Skip to main content

@webda/coreReadme | API


Interface: CoreModelDefinition<T>

Extends

  • EventEmitter

Type parameters

T extends CoreModel = CoreModel

Constructors

new CoreModelDefinition()

new CoreModelDefinition(): T

Returns

T

Inherited from

EventEmitter.constructor

Source

packages/core/src/models/coremodel.ts:226

Properties

Expose?

Expose?: ExposeParameters

If the model have some Expose annotation

Source

packages/core/src/models/coremodel.ts:230


ref

ref: <T>(this, uid) => ModelRefWithCreate<T>

Reference to an object without doing a DB request yet

Type parameters

T extends CoreModel

Parameters

this: Constructor<T, []>

uid: string

Returns

ModelRefWithCreate<T>

Source

packages/core/src/models/coremodel.ts:284

Methods

addListener()

addListener(event, listener): this

EventEmitter interface

Parameters

event: string | symbol

listener: (...args) => void

Returns

this

Overrides

EventEmitter.addListener

Source

packages/core/src/models/coremodel.ts:358


authorizeClientEvent()

authorizeClientEvent(_event, _context, _model?): boolean

Authorize a public event subscription

Parameters

_event: string

_context: OperationContext<any, any>

_model?: T

Returns

boolean

Source

packages/core/src/models/coremodel.ts:351


completeUid()

completeUid(uid): string

Complete uuid useful to implement uuid prefix or suffix

Parameters

uid: string

Returns

string

Source

packages/core/src/models/coremodel.ts:271


create()

create<T>(this, data): Promise<T>

Create a new model

Type parameters

T extends CoreModel

Parameters

this: Constructor<T, []>

data: RawModel<T>

Returns

Promise<T>

Source

packages/core/src/models/coremodel.ts:290


emit()

emit<T, Key>(this, event, evt): any

Emit an event for this class

Type parameters

T extends CoreModel

Key extends keyof StoreEvents

Parameters

this: Constructor<T, []>

event: Key

evt: StoreEvents[Key]

Returns

any

Overrides

EventEmitter.emit

Source

packages/core/src/models/coremodel.ts:328


emitSync()

emitSync<T, Key>(this, event, evt): Promise<void>

Emit an event for this class and wait for all listeners to finish

Type parameters

T extends CoreModel

Key extends keyof StoreEvents

Parameters

this: Constructor<T, []>

event: Key

evt: StoreEvents[Key]

Returns

Promise<void>

Source

packages/core/src/models/coremodel.ts:335


eventNames()

eventNames(): (string | symbol)[]

Returns an array listing the events for which the emitter has registered listeners. The values in the array are strings or Symbols.

const EventEmitter = require('events');
const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});

const sym = Symbol('symbol');
myEE.on(sym, () => {});

console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]

Returns

(string | symbol)[]

Inherited from

EventEmitter.eventNames

Since

v6.0.0

Source

packages/core/node_modules/@types/node/events.d.ts:669


factory()

factory<T>(this, object, context?): T

Create a CoreModel object loaded with the content of object

It allows polymorphism from Store

Type parameters

T extends CoreModel

Parameters

this: Constructor<T, []>

object: Partial<T>

to load data from

context?: OperationContext<any, any>

if the data is unsafe from http

Returns

T

Source

packages/core/src/models/coremodel.ts:240


getActions()

getActions(): Object

Get the model actions

Returns

Object

Source

packages/core/src/models/coremodel.ts:244


getClientEvents()

getClientEvents(): (string | Object)[]

Return the event on the model that can be listened to by an external authorized source

Returns

(string | Object)[]

See

authorizeClientEvent

Source

packages/core/src/models/coremodel.ts:345


getHierarchy()

getHierarchy(): Object

Get the model hierarchy

Returns

Object

ancestors

ancestors: string[]

children

children: ModelsTree

Source

packages/core/src/models/coremodel.ts:257


getIdentifier()

getIdentifier(short?): string

Get Model identifier

Parameters

short?: boolean

Returns

string

Source

packages/core/src/models/coremodel.ts:265


getMaxListeners()

getMaxListeners(): number

Returns the current max listener value for the EventEmitter which is either set by emitter.setMaxListeners(n) or defaults to defaultMaxListeners.

Returns

number

Inherited from

EventEmitter.getMaxListeners

Since

v1.0.0

Source

packages/core/node_modules/@types/node/events.d.ts:526


getPermissionQuery()

getPermissionQuery(context?): Object

Permission query for the model

Parameters

context?: OperationContext<any, any>

Returns

Object

partial

partial: boolean

query

query: string

Source

packages/core/src/models/coremodel.ts:280


getRelations()

getRelations(): ModelGraph

Get the model relations

Returns

ModelGraph

Source

packages/core/src/models/coremodel.ts:261


getSchema()

getSchema(): JSONSchema7

Get the model schema

Returns

JSONSchema7

Source

packages/core/src/models/coremodel.ts:252


getUuidField()

getUuidField(): string

Get the model uuid field if you do not want to use the uuid field

Returns

string

Source

packages/core/src/models/coremodel.ts:275


listenerCount()

listenerCount(eventName): number

Returns the number of listeners listening to the event named eventName.

Parameters

eventName: string | symbol

The name of the event being listened for

Returns

number

Inherited from

EventEmitter.listenerCount

Since

v3.2.0

Source

packages/core/node_modules/@types/node/events.d.ts:616


listeners()

listeners(eventName): Function[]

Returns a copy of the array of listeners for the event named eventName.

server.on('connection', (stream) => {
console.log('someone connected!');
});
console.log(util.inspect(server.listeners('connection')));
// Prints: [ [Function] ]

Parameters

eventName: string | symbol

Returns

Function[]

Inherited from

EventEmitter.listeners

Since

v0.1.26

Source

packages/core/node_modules/@types/node/events.d.ts:539


off()

off(eventName, listener): this

EventEmitter interface

Parameters

eventName: string | symbol

listener: (...args) => void

Returns

this

Overrides

EventEmitter.off

Source

packages/core/src/models/coremodel.ts:376


on()

on<T, Key>(this, event, listener, async?): this

Listen to events on the model

Type parameters

T extends CoreModel

Key extends keyof StoreEvents

Parameters

this: Constructor<T, []>

event: Key

listener: (evt) => any

async?: boolean

Returns

this

Overrides

EventEmitter.on

Source

packages/core/src/models/coremodel.ts:306


onAsync()

onAsync<T, Key>(this, event, listener): this

Listen to events on the model asynchronously

Type parameters

T extends CoreModel

Key extends keyof StoreEvents

Parameters

this: Constructor<T, []>

event: Key

listener: (evt) => any

Returns

this

Source

packages/core/src/models/coremodel.ts:317


once()

once(event, listener): this

EventEmitter interface

Parameters

event: string | symbol

listener: (...args) => void

Returns

this

Overrides

EventEmitter.once

Source

packages/core/src/models/coremodel.ts:364


prependListener()

prependListener(eventName, listener): this

Adds the listener function to the beginning of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventNameand listener will result in the listener being added, and called, multiple times.

server.prependListener('connection', (stream) => {
console.log('someone connected!');
});

Returns a reference to the EventEmitter, so that calls can be chained.

Parameters

eventName: string | symbol

The name of the event.

listener: (...args) => void

The callback function

Returns

this

Inherited from

EventEmitter.prependListener

Since

v6.0.0

Source

packages/core/node_modules/@types/node/events.d.ts:634


prependOnceListener()

prependOnceListener(eventName, listener): this

Adds a one-timelistener function for the event named eventName to the beginning of the listeners array. The next time eventName is triggered, this listener is removed, and then invoked.

server.prependOnceListener('connection', (stream) => {
console.log('Ah, we have our first user!');
});

Returns a reference to the EventEmitter, so that calls can be chained.

Parameters

eventName: string | symbol

The name of the event.

listener: (...args) => void

The callback function

Returns

this

Inherited from

EventEmitter.prependOnceListener

Since

v6.0.0

Source

packages/core/node_modules/@types/node/events.d.ts:650


query()

query(query?, includeSubclass?, context?): Promise<Object>

Query the model

Parameters

query?: string

includeSubclass?: boolean

context?: OperationContext<any, any>

Returns

Promise<Object>

continuationToken?

continuationToken?: string

results

results: T[]

Source

packages/core/src/models/coremodel.ts:295


rawListeners()

rawListeners(eventName): Function[]

Returns a copy of the array of listeners for the event named eventName, including any wrappers (such as those created by .once()).

const emitter = new EventEmitter();
emitter.once('log', () => console.log('log once'));

// Returns a new Array with a function `onceWrapper` which has a property
// `listener` which contains the original listener bound above
const listeners = emitter.rawListeners('log');
const logFnWrapper = listeners[0];

// Logs "log once" to the console and does not unbind the `once` event
logFnWrapper.listener();

// Logs "log once" to the console and removes the listener
logFnWrapper();

emitter.on('log', () => console.log('log persistently'));
// Will return a new Array with a single function bound by `.on()` above
const newListeners = emitter.rawListeners('log');

// Logs "log persistently" twice
newListeners[0]();
emitter.emit('log');

Parameters

eventName: string | symbol

Returns

Function[]

Inherited from

EventEmitter.rawListeners

Since

v9.4.0

Source

packages/core/node_modules/@types/node/events.d.ts:569


removeAllListeners()

removeAllListeners(eventName?): this

EventEmitter interface

Parameters

eventName?: any

Returns

this

Overrides

EventEmitter.removeAllListeners

Source

packages/core/src/models/coremodel.ts:382


removeListener()

removeListener(event, listener): this

EventEmitter interface

Parameters

event: string | symbol

listener: (...args) => void

Returns

this

Overrides

EventEmitter.removeListener

Source

packages/core/src/models/coremodel.ts:370


setMaxListeners()

setMaxListeners(n): this

By default EventEmitters will print a warning if more than 10 listeners are added for a particular event. This is a useful default that helps finding memory leaks. The emitter.setMaxListeners() method allows the limit to be modified for this specific EventEmitter instance. The value can be set toInfinity (or 0) to indicate an unlimited number of listeners.

Returns a reference to the EventEmitter, so that calls can be chained.

Parameters

n: number

Returns

this

Inherited from

EventEmitter.setMaxListeners

Since

v0.3.5

Source

packages/core/node_modules/@types/node/events.d.ts:520


store()

store(): Store<T, StoreParameters, StoreEvents>

Get the model store

Returns

Store<T, StoreParameters, StoreEvents>

Source

packages/core/src/models/coremodel.ts:248