Skip to main content

@webda/coreReadme | API


Class: OwnerModel

Webda Model

Extends

Constructors

new OwnerModel()

new OwnerModel(): OwnerModel

Returns

OwnerModel

Inherited from

UuidModel.constructor

Source

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

Properties

__class

__class: CoreModelDefinition<OwnerModel>

Class reference to the object

Inherited from

UuidModel.__class

Source

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


__ctx

__ctx: OperationContext<any, any>

Object context

@TJS-ignore

Inherited from

UuidModel.__ctx

Source

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


__dirty

__dirty: Set<string | symbol>

Inherited from

UuidModel.__dirty

Source

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


__store

__store: Store<OwnerModel, StoreParameters, StoreEvents>

If object is attached to its store

@TJS-ignore

Inherited from

UuidModel.__store

Source

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


__type

__type: string

Type name

Inherited from

UuidModel.__type

Source

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


__types

__types: string[]

Types name

Inherited from

UuidModel.__types

Source

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


_creationDate

_creationDate: Date

Creation date

Inherited from

UuidModel._creationDate

Source

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


_lastUpdate

_lastUpdate: Date

Last update date

Inherited from

UuidModel._lastUpdate

Source

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


_user

_user: ModelLink<User>

Default owner of the object

Source

packages/core/src/models/ownermodel.ts:13


public?

public?: boolean

Define if the object is publicly readable

Default

false

Source

packages/core/src/models/ownermodel.ts:18


uuid

readonly uuid: string

UUID of the object

Overrides

UuidModel.uuid

Source

packages/core/src/models/ownermodel.ts:23

Methods

_onDelete()

_onDelete(): Promise<void>

Called when object is about to be deleted

Returns

Promise<void>

Inherited from

UuidModel._onDelete

Source

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


_onDeleted()

_onDeleted(): Promise<void>

Called when object has been deleted

Returns

Promise<void>

Inherited from

UuidModel._onDeleted

Source

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


_onGet()

_onGet(): Promise<void>

Called when object is retrieved

Returns

Promise<void>

Inherited from

UuidModel._onGet

Source

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


_onSave()

_onSave(): Promise<void>

Called when object is about to be saved

Returns

Promise<void>

Inherited from

UuidModel._onSave

Source

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


_onSaved()

_onSaved(): Promise<void>

Called when object is saved

Returns

Promise<void>

Inherited from

UuidModel._onSaved

Source

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


_onUpdate()

_onUpdate(_updates): Promise<void>

Called when object is about to be updates

Parameters

_updates: any

Returns

Promise<void>

Inherited from

UuidModel._onUpdate

Source

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


_onUpdated()

_onUpdated(): Promise<void>

Called when object is updated

Returns

Promise<void>

Inherited from

UuidModel._onUpdated

Source

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


_toJSON()

_toJSON(secure): any

Remove the specific attributes if not secure

Parameters

secure: any

serialize server fields also

Returns

any

filtered object to be serialized

Inherited from

UuidModel._toJSON

Source

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


attributePermission()

attributePermission(key, value, mode, context?): any

Allow to define custom permission per attribute

This method allows you to do permission based attribute But also a mask destructive attribute

Parameters

key: string

value: any

mode: "READ" | "WRITE"

context?: OperationContext<any, any>

Returns

any

updated value

Inherited from

UuidModel.attributePermission

Source

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


canAct()

canAct(ctx, action): Promise<string | boolean>

By default nothing is permitted on a CoreModel

Parameters

ctx: OperationContext<any, any>

action: string

Returns

Promise<string | boolean>

Overrides

UuidModel.canAct

Source

packages/core/src/models/ownermodel.ts:53


checkAct()

checkAct(context, action): Promise<void>

Parameters

context: OperationContext<any, any>

action: string

Returns

Promise<void>

Inherited from

UuidModel.checkAct

Source

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


delete()

delete(): Promise<void>

Delete this object

Returns

Promise<void>

Inherited from

UuidModel.delete

Throws

Error if the object is not coming from a store

Source

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


generateUid()

generateUid(_object): string

Generate uuid for the object

Parameters

_object: any= undefined

Returns

string

Inherited from

UuidModel.generateUid

Source

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


get()

get(): Promise<OwnerModel>

Get the object

Returns

Promise<OwnerModel>

Inherited from

UuidModel.get

Source

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


getContext()

getContext<T>(): T

Get object context

Global object does not belong to a request

Type parameters

T extends OperationContext<any, any>

Returns

T

Inherited from

UuidModel.getContext

Source

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


getFullUuid()

getFullUuid(): string

Return a unique reference within the application to the object

It contains the Store containing it

Returns

string

Inherited from

UuidModel.getFullUuid

Source

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


getOwner()

getOwner(): ModelLink<User>

Return the owner of the object

Only the owner can do update to the object

Returns

ModelLink<User>

Source

packages/core/src/models/ownermodel.ts:49


getProxy()

getProxy(): this

Return a proxy to the object to detect if dirty

Returns

this

Inherited from

UuidModel.getProxy

Source

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


getRef()

getRef<T>(): ModelRef<T>

Return a model ref

Type parameters

T extends OwnerModel

Returns

ModelRef<T>

Inherited from

UuidModel.getRef

Source

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


getService()

getService<T>(service): T

Get a pre typed service

Type parameters

T extends Service<ServiceParameters, Events>

Parameters

service: any

to retrieve WARNING: Only object attached to a store can retrieve service

Returns

T

Inherited from

UuidModel.getService

Source

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


getStore()

getStore(): Store<OwnerModel, StoreParameters, StoreEvents>

Return the object registered store

Returns

Store<OwnerModel, StoreParameters, StoreEvents>

Inherited from

UuidModel.getStore

Source

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


getUuid()

getUuid(): string

Returns

string

the uuid of the object

Inherited from

UuidModel.getUuid

Source

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


handleRelations()

protected handleRelations(): void

Patch every attribute that is based on a relation to add all the helpers

Returns

void

Inherited from

UuidModel.handleRelations

Source

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


incrementAttribute()

incrementAttribute(property, value): Promise<void>

Increment an attribute both in store and object

Parameters

property: never

value: number

Returns

Promise<void>

Inherited from

UuidModel.incrementAttribute

Source

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


incrementAttributes()

incrementAttributes(info): Promise<void>

Increment a attributes both in store and object

Parameters

info: Object[]

Returns

Promise<void>

Inherited from

UuidModel.incrementAttributes

Source

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


isDirty()

isDirty(): boolean

Return true if needs a save

Returns

boolean

Inherited from

UuidModel.isDirty

Source

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


load()

load(raw, secure, relations): this

Load an object from RAW

Parameters

raw: RawModel<OwnerModel>

data

secure: boolean= false

if false will ignore any _ variable

relations: boolean= true

Returns

this

Inherited from

UuidModel.load

Source

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


patch()

patch(obj, conditionField?, conditionValue?): Promise<void>

Patch current object with this update

Parameters

obj: Partial<OwnerModel>

conditionField?: keyof OwnerModel

if null no condition used otherwise fallback to lastUpdate

conditionValue?: any

Returns

Promise<void>

Inherited from

UuidModel.patch

Source

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


refresh()

refresh(): Promise<OwnerModel>

Get the object again

Returns

Promise<OwnerModel>

Inherited from

UuidModel.refresh

Throws

Error if the object is not coming from a store

Source

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


removeAttribute()

removeAttribute(property): Promise<void>

Remove attribute from both the object and db

Parameters

property: keyof OwnerModel

Returns

Promise<void>

Inherited from

UuidModel.removeAttribute

Source

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


save()

save(full?, ...args?): Promise<OwnerModel>

Save this object

Parameters

full?: boolean | keyof OwnerModel

• ...args?: keyof OwnerModel[]

Returns

Promise<OwnerModel>

Inherited from

UuidModel.save

Throws

Error if the object is not coming from a store

Source

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


setAttribute()

setAttribute(property, value): Promise<void>

Set attribute on the object and database

Parameters

property: keyof OwnerModel

value: any

Returns

Promise<void>

Inherited from

UuidModel.setAttribute

Source

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


setContext()

setContext(ctx): this

Context of the request

Parameters

ctx: OperationContext<any, any>

Returns

this

Inherited from

UuidModel.setContext

Source

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


setOwner()

setOwner(uuid): void

Set object owner

Parameters

uuid: string

Returns

void

Source

packages/core/src/models/ownermodel.ts:29


setUuid()

setUuid(uuid, target): this

Parameters

uuid: string

target: OwnerModel= undefined

Returns

this

Inherited from

UuidModel.setUuid

Source

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


toJSON()

toJSON(): any

Return the object without sensitive attributes

Returns

any

Object to serialize

Inherited from

UuidModel.toJSON

Source

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


toStoredJSON()

toStoredJSON(stringify): any

Return the object to be serialized without the __store

Parameters

stringify: boolean= false

Returns

any

Inherited from

UuidModel.toStoredJSON

Source

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


unflat()

unflat<T>(split): T

Create subobject for a model

Useful for counters

Type parameters

T

Parameters

split: string= "#"

Returns

T

Inherited from

UuidModel.unflat

Source

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


validate()

validate(ctx, updates, ignoreRequired?): Promise<boolean>

Parameters

ctx: OperationContext<any, any>

updates: any

ignoreRequired?: boolean

Returns

Promise<boolean>

Overrides

UuidModel.validate

Source

packages/core/src/models/ownermodel.ts:37


addListener()

static addListener<Key>(event, listener): any

Type parameters

Key extends keyof StoreEvents

Parameters

event: Key

listener: (...args) => void

Returns

any

Inherited from

UuidModel.addListener

Source

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


authorizeClientEvent()

static authorizeClientEvent(_event, _context, _model?): boolean

Does not allow any event by default

Parameters

_event: string

_context: OperationContext<any, any>

_model?: CoreModel

Returns

boolean

Inherited from

UuidModel.authorizeClientEvent

Source

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


completeQuery()

static protected completeQuery(query, includeSubclass): string

Complete the query with __type/__types

Parameters

query: string

includeSubclass: boolean= true

Returns

string

Inherited from

UuidModel.completeQuery

Source

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


completeUid()

static completeUid(uid): string

Complete the uid with prefix if any

Useful when object are stored with a prefix for full uuid

Parameters

uid: string

Returns

string

Inherited from

UuidModel.completeUid

Source

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


create()

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

Get a reference to a model

Type parameters

T extends CoreModel

Parameters

this: Constructor<T, []>

data: RawModel<T>

Returns

Promise<T>

Inherited from

UuidModel.create

Source

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


emit()

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

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

void

Inherited from

UuidModel.emit

Source

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


emitSync()

static 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>

Inherited from

UuidModel.emitSync

Source

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


emitter()

static emitter(method, ...args): any

Parameters

method: any

• ...args: any[]

Returns

any

Inherited from

UuidModel.emitter

Source

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


eventNames()

static eventNames(...args): any

Parameters

• ...args: any[]

Returns

any

Inherited from

UuidModel.eventNames

Source

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


factory()

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

Create an object

Type parameters

T extends CoreModel

Parameters

this: Constructor<T, []>

object: Partial<T>

context?: OperationContext<any, any>

Returns

T

Inherited from

UuidModel.factory

Source

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


flat()

static flat(target, data, split, prefix): any

Flat an object into another

{ a: { b: 1 }, c: 1 }

become

{ "a#b": 1 "c": 1 }

Parameters

target: any

data: any

split: string= "#"

prefix: string= ""

Returns

any

Inherited from

UuidModel.flat

Source

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


fromFullUuid()

static fromFullUuid<T>(fullUuid, core, partials?): Promise<T>

Get an object from the full uuid

Type parameters

T extends CoreModel = CoreModel

Parameters

fullUuid: string

core: Core<CoreEvents>= undefined

partials?: any

Returns

Promise<T>

Inherited from

UuidModel.fromFullUuid

Source

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


getActions()

static getActions<T>(this): ModelActions

Get actions callable on an object

This will expose them by the Store with /storeUrl/{uuid}/{action}

Type parameters

T

Parameters

this: Constructor<T, []>

Returns

ModelActions

Inherited from

UuidModel.getActions

Source

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


getClientEvents()

static getClientEvents(): any[]

Do not declare any public events by default

Returns

any[]

Inherited from

UuidModel.getClientEvents

Source

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


getHierarchy()

static getHierarchy(): Object

Get the model hierarchy

Ancestors will contain every model it inherits from Children will contain every model that inherits from this model in a tree structure

Returns

Object

ancestors

ancestors: string[]

children

children: ModelsTree

Inherited from

UuidModel.getHierarchy

Source

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


getIdentifier()

static getIdentifier(short): string

Get identifier for this model

Parameters

short: boolean= true

Returns

string

Inherited from

UuidModel.getIdentifier

Source

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


getMaxListeners()

static getMaxListeners(...args): any

Parameters

• ...args: any[]

Returns

any

Inherited from

UuidModel.getMaxListeners

Source

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


getPermissionQuery()

static getPermissionQuery(context?): Object

Return a query to filter OwnerModel

Parameters

context?: OperationContext<any, any>

Returns

Object

partial

partial: boolean

query

query: string

Overrides

UuidModel.getPermissionQuery

Source

packages/core/src/models/ownermodel.ts:86


getRelations()

static getRelations(): ModelGraph

Returns

ModelGraph

Inherited from

UuidModel.getRelations

Source

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


getSchema()

static getSchema(): JSONSchema7

Return the known schema

Returns

JSONSchema7

Inherited from

UuidModel.getSchema

Source

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


getUuidField()

static getUuidField(): string

Get the UUID property

Returns

string

Inherited from

UuidModel.getUuidField

Source

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


instanceOf()

static instanceOf(object): boolean

Detect what looks like a CoreModel but can be from different version

Parameters

object: any

Returns

boolean

Inherited from

UuidModel.instanceOf

Source

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


iterate()

static iterate<T>(this, query, includeSubclass, context?): AsyncGenerator<T, any, unknown>

Iterate through the model

How to use a iterator is:

for await (const model of CoreModel.iterate()) {
// Do something with my model
}

Type parameters

T extends CoreModel

Parameters

this: Constructor<T, []>

query: string= ""

includeSubclass: boolean= true

context?: OperationContext<any, any>

Returns

AsyncGenerator<T, any, unknown>

Inherited from

UuidModel.iterate

Source

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


listenerCount()

static listenerCount(...args): any

Parameters

• ...args: any[]

Returns

any

Inherited from

UuidModel.listenerCount

Source

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


listeners()

static listeners(...args): any

Parameters

• ...args: any[]

Returns

any

Inherited from

UuidModel.listeners

Source

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


off()

static off(...args): any

Parameters

• ...args: any[]

Returns

any

Inherited from

UuidModel.off

Source

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


on()

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

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= false

Returns

any

Inherited from

UuidModel.on

Source

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


onAsync()

static onAsync<Key>(event, listener, queue?): any

Listen to events on the model asynchronously

Type parameters

Key extends keyof StoreEvents

Parameters

event: Key

listener: (evt) => any

queue?: string

Returns

any

Inherited from

UuidModel.onAsync

Source

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


once()

static once(...args): any

Parameters

• ...args: any[]

Returns

any

Inherited from

UuidModel.once

Source

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


prependListener()

static prependListener(...args): any

Parameters

• ...args: any[]

Returns

any

Inherited from

UuidModel.prependListener

Source

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


prependOnceListener()

static prependOnceListener(...args): any

Parameters

• ...args: any[]

Returns

any

Inherited from

UuidModel.prependOnceListener

Source

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


query()

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

Query for models

Type parameters

T extends CoreModel

Parameters

this: Constructor<T, []>

query: string= ""

includeSubclass: boolean= true

context?: OperationContext<any, any>

Returns

Promise<Object>

continuationToken?

continuationToken?: string

results

results: T[]

Inherited from

UuidModel.query

Source

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


rawListeners()

static rawListeners(...args): any

Parameters

• ...args: any[]

Returns

any

Inherited from

UuidModel.rawListeners

Source

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


ref()

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

Get a reference to a model

Type parameters

T extends CoreModel

Parameters

this: Constructor<T, []>

uid: string

Returns

ModelRefWithCreate<T>

Inherited from

UuidModel.ref

Source

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


removeAllListeners()

static removeAllListeners(...args): any

Parameters

• ...args: any[]

Returns

any

Inherited from

UuidModel.removeAllListeners

Source

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


removeListener()

static removeListener(...args): any

Parameters

• ...args: any[]

Returns

any

Inherited from

UuidModel.removeListener

Source

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


setMaxListeners()

static setMaxListeners(...args): any

Parameters

• ...args: any[]

Returns

any

Inherited from

UuidModel.setMaxListeners

Source

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


store()

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

Get Store for this model

Type parameters

T extends CoreModel

Parameters

this: Constructor<T, []>

Returns

Store<T, StoreParameters, StoreEvents>

Inherited from

UuidModel.store

Source

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


unflat()

static unflat<T>(data, split): T

Unflat an object

Type parameters

T = any

Parameters

data: any

split: string= "#"

Returns

T

Inherited from

UuidModel.unflat

Source

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