Skip to main content

EventRepository

@webda/core


Class: EventRepository<T>

Defined in: packages/models/lib/repositories/event.d.ts:18

Repository decorator that wraps another repository with event emission.

Emits "before" events (Create, Update, Patch, Delete, PartialUpdate, Query) before delegating to the underlying repository, then emits "after" events (Created, Updated, Patched, Deleted, PartialUpdated, Queried) on success.

Extends​

  • AbstractRepository<T>

Type Parameters​

T​

T extends ModelClass = any

The ModelClass this repository manages

Constructors​

Constructor​

new EventRepository<T>(model, pks, repository, separator?): EventRepository<T>

Defined in: packages/models/lib/repositories/event.d.ts:26

Parameters​

model​

T

The model class constructor

pks​

string[]

Array of primary key field names

repository​

AbstractRepository<T>

The underlying repository to delegate storage operations to

separator?​

string

Separator used when joining composite key fields (default: "_")

Returns​

EventRepository<T>

Overrides​

AbstractRepository<T>.constructor

Properties​

[WEBDA_TEST]​

[WEBDA_TEST]: object

Defined in: packages/models/lib/repositories/event.d.ts:154

Test utilities - clears events and delegates to underlying repository

clear​

clear: (excludeListeners?) => Promise<void>

Parameters​
excludeListeners?​

boolean

Returns​

Promise<void>


aggregationOptions​

protected aggregationOptions: AggregationOptions

Defined in: packages/models/lib/repositories/abstract.d.ts:27

Aggregation fallback policy, set by the owning store through configureAggregation

Inherited from​

AbstractRepository.aggregationOptions


events​

protected events: Map<keyof InstanceType<T>[typeof WEBDA_EVENTS], Set<(data) => void>>

Defined in: packages/models/lib/repositories/abstract.d.ts:25

Registered event listeners keyed by event name

Inherited from​

AbstractRepository.events


maxListeners​

protected maxListeners: number

Defined in: packages/models/lib/repositories/abstract.d.ts:321

Max-listeners hint kept for Node EventEmitter API compatibility. Not enforced — repositories use an unbounded Set per event.

Inherited from​

AbstractRepository.maxListeners


model​

protected model: T

Defined in: packages/models/lib/repositories/abstract.d.ts:21

Inherited from​

AbstractRepository.model


monitorOptions​

protected monitorOptions: QueryMonitorOptions

Defined in: packages/models/lib/repositories/abstract.d.ts:29

Query monitoring options, set by the owning store through configureMonitoring

Inherited from​

AbstractRepository.monitorOptions


pks​

protected pks: string[]

Defined in: packages/models/lib/repositories/abstract.d.ts:22

Inherited from​

AbstractRepository.pks


repository​

protected repository: AbstractRepository<T>

Defined in: packages/models/lib/repositories/event.d.ts:19


separator​

protected separator: string

Defined in: packages/models/lib/repositories/abstract.d.ts:23

Inherited from​

AbstractRepository.separator


tableRoot?​

protected optional tableRoot?: ModelClass

Defined in: packages/models/lib/repositories/abstract.d.ts:35

Model owning the untyped rows of the storage (the first model of the store), undefined when not known

Inherited from​

AbstractRepository.tableRoot


warnedAggregations​

protected warnedAggregations: Set<string>

Defined in: packages/models/lib/repositories/abstract.d.ts:31

Fallback shapes already warned about

Inherited from​

AbstractRepository.warnedAggregations

Methods​

acceptedTypes()​

acceptedTypes(): string[]

Defined in: packages/models/lib/repositories/abstract.d.ts:69

Every stored __type value of this model and its transitive subclasses, for stores filtering in their query language

Returns​

string[]

the values, empty when the model carries no Metadata

Inherited from​

AbstractRepository.acceptedTypes


aggregate()​

aggregate<G, M>(spec, params?): Promise<AggregationResult<AggregatedRow<InstanceType<T>, G, M>>>

Defined in: packages/models/lib/repositories/event.d.ts:70

Aggregate with event emission

Parameters are bound here, so the events carry the bound filter and the underlying repository receives a plain spec and keeps its native implementation.

Type Parameters​

G​

G extends readonly _NonFunctionPropertyPaths<InstanceType<T>>[] = []

M​

M extends Record<string, MetricSpec<InstanceType<T>>> = Record<string, MetricSpec<InstanceType<T>>>

Parameters​

spec​

AggregationSpec<InstanceType<T>, G, M>

the aggregation spec

params?​

QueryParameters

values for the placeholders of spec.filter

Returns​

Promise<AggregationResult<AggregatedRow<InstanceType<T>, G, M>>>

the aggregated rows

Overrides​

AbstractRepository.aggregate


aggregateInMemory()​

protected aggregateInMemory(query): Promise<Record<string, unknown>[]>

Defined in: packages/models/lib/repositories/abstract.d.ts:301

Aggregate by streaming the filtered items

Parameters​

query​

AggregationQuery

the aggregation

Returns​

Promise<Record<string, unknown>[]>

the rows

Inherited from​

AbstractRepository.aggregateInMemory


applyAssignments()​

protected applyAssignments<O>(target, assignments): O

Defined in: packages/models/lib/repositories/abstract.d.ts:166

Set the assignments of an UPDATE on an object, creating the intermediate objects of dotted paths

Targets were checked by parseStatement: letters, digits and _ only, no __ segment, no Object.prototype member name.

Type Parameters​

O​

O

Parameters​

target​

O

the object to change in place

assignments​

Assignment[]

the SET assignments

Returns​

O

the target

Inherited from​

AbstractRepository.applyAssignments


belongsToModel()​

belongsToModel(stored?): boolean

Defined in: packages/models/lib/repositories/abstract.d.ts:75

Whether a stored row belongs to this model, for stores filtering in memory

Parameters​

stored?​

string

the stored __type, undefined for an untyped row

Returns​

boolean

true when the row belongs to this model (always without Metadata)

Inherited from​

AbstractRepository.belongsToModel


buildItem()​

protected buildItem(data): InstanceType<T>

Defined in: packages/models/lib/repositories/abstract.d.ts:86

Build the model instance to create from the incoming data

Primary key fields that are undefined or null are dropped from the data so a key generated by the model constructor (e.g. UuidModel) is not overwritten. Repositories must read the storage key from the returned instance.

Parameters​

data​

Helpers<InstanceType<T>>

the incoming data

Returns​

InstanceType<T>

the model instance

Inherited from​

AbstractRepository.buildItem


checkAggregationFallback()​

protected checkAggregationFallback(query, reason): Promise<void>

Defined in: packages/models/lib/repositories/abstract.d.ts:272

Apply the fallback policy before aggregating or counting in memory

Parameters​

query​

AggregationQuery

the aggregation, undefined for a count

reason​

string

why it cannot run natively

Returns​

Promise<void>

Throws​

AggregationError AGGREGATION_NOT_NATIVE when the policy is deny

Inherited from​

AbstractRepository.checkAggregationFallback


collectStatementKeys()​

protected collectStatementKeys(statement): Promise<PrimaryKeyType<InstanceType<T>>[]>

Defined in: packages/models/lib/repositories/abstract.d.ts:173

Keys of the objects matching the WHERE of a statement, collected before any change so an update changing a WHERE field cannot meet the same object twice; at most LIMIT keys

Parameters​

statement​

Query

the parsed statement

Returns​

Promise<PrimaryKeyType<InstanceType<T>>[]>

the primary keys

Inherited from​

AbstractRepository.collectStatementKeys


configureAggregation()​

configureAggregation(options): void

Defined in: packages/models/lib/repositories/event.d.ts:86

Configure both this wrapper and the underlying repository

Parameters​

options​

Partial<AggregationOptions>

Returns​

void

Overrides​

AbstractRepository.configureAggregation


configureMonitoring()​

configureMonitoring(options): void

Defined in: packages/models/lib/repositories/event.d.ts:91

Configure monitoring on the event wrapper only (not on the inner repository)

Parameters​

options​

Partial<QueryMonitorOptions>

Returns​

void

Overrides​

AbstractRepository.configureMonitoring


count()​

count(filter?, params?, options?): Promise<CountResult>

Defined in: packages/models/lib/repositories/event.d.ts:81

Count through the underlying repository, monitored as a "count" operation

Parameters are bound here, so the monitor sees the bound filter and the underlying repository keeps its native implementation. A count emits no repository event.

Parameters​

filter?​

string

the WebdaQL filter

params?​

QueryParameters

values for the placeholders of the filter

options?​

CountOptions

max stops counting after max objects

Returns​

Promise<CountResult>

the count

Overrides​

AbstractRepository.count


countInMemory()​

protected countInMemory(filter, max?): Promise<Omit<CountResult, "native">>

Defined in: packages/models/lib/repositories/abstract.d.ts:295

Count by streaming the filtered items, stopping at max + 1

Parameters​

filter​

Expression

the filter

max?​

number

stop after max objects, undefined for an exact count

Returns​

Promise<Omit<CountResult, "native">>

the value and its relation

Inherited from​

AbstractRepository.countInMemory


create()​

create(data, save?): Promise<InstanceType<T>>

Defined in: packages/models/lib/repositories/event.d.ts:135

Create with event emission (emits Create before and Created after)

Parameters​

data​

Helpers<InstanceType<T>>

save?​

boolean

Returns​

Promise<InstanceType<T>>

Overrides​

AbstractRepository.create


delete()​

delete<K>(uuid, conditionField?, condition?): Promise<void>

Defined in: packages/models/lib/repositories/event.d.ts:150

Delete with event emission (emits Delete before and Deleted after)

Type Parameters​

K​

K extends string

Parameters​

uuid​

PrimaryKeyType<InstanceType<T>>

conditionField?​

K

condition?​

PropertyPathType<InstanceType<T>, K> | JSONed<PropertyPathType<InstanceType<T>, K>>

Returns​

Promise<void>

Overrides​

AbstractRepository.delete


deleteItemFromCollection()​

deleteItemFromCollection<K, L>(uuid, collection, index, itemWriteConditionField?, itemWriteCondition?): Promise<void>

Defined in: packages/models/lib/repositories/event.d.ts:118

Delete an item from a collection

Type Parameters​

K​

K extends string

L​

L extends string | number | symbol

Parameters​

uuid​

PrimaryKeyType<InstanceType<T>>

The UUID of the item

collection​

K

The collection to delete from

index​

number

The index of the item to delete

itemWriteConditionField?​

L

The field to use for the write condition

itemWriteCondition?​

ArrayElement<InstanceType<T>[K]>[L]

The value to use for the write condition

Returns​

Promise<void>

Overrides​

AbstractRepository.deleteItemFromCollection


deleteMany()​

deleteMany(statement, params?): Promise<number>

Defined in: packages/models/lib/repositories/event.d.ts:100

Delete in bulk through the underlying repository

Bulk operations emit no per-object event: see Repository.deleteMany.

Parameters​

statement​

string | Query

the DELETE statement or its parsed form

params?​

QueryParameters

values for the placeholders

Returns​

Promise<number>

the number of objects deleted

Overrides​

AbstractRepository.deleteMany


deleteManyByKey()​

protected deleteManyByKey(statement, params?): Promise<number>

Defined in: packages/models/lib/repositories/abstract.d.ts:191

Generic deleteMany: collect the matching keys (up to LIMIT), then delete them one by one with this repository's delete primitive

Used by stores without a native bulk delete. On a store repository the primitive emits no event.

Parameters​

statement​

string | Query

the DELETE statement or its parsed form

params?​

QueryParameters

values for the placeholders

Returns​

Promise<number>

the number of objects deleted

Inherited from​

AbstractRepository.deleteManyByKey


emit()​

emit<K>(event, data): Promise<void>

Defined in: packages/models/lib/repositories/abstract.d.ts:346

Emit an event to all registered listeners and await their completion.

Type Parameters​

K​

K extends string | number | symbol

Parameters​

event​

K

The event name to emit

data​

InstanceType<T>[typeof WEBDA_EVENTS][K]

The event payload

Returns​

Promise<void>

Inherited from​

AbstractRepository.emit


excludePrimaryKey()​

excludePrimaryKey(object): any

Defined in: packages/models/lib/repositories/abstract.d.ts:110

Parameters​

object​

any

Returns​

any

Inherited from​

AbstractRepository.excludePrimaryKey


executeAggregation()​

protected executeAggregation(query): Promise<AggregationResult<any>>

Defined in: packages/models/lib/repositories/abstract.d.ts:265

Run a validated aggregation

Backends override it to aggregate natively, and call super for the shapes they cannot translate. The default streams iterate() into the in-memory Aggregator, under the fallback policy.

Parameters​

query​

AggregationQuery

the validated aggregation

Returns​

Promise<AggregationResult<any>>

the rows

Inherited from​

AbstractRepository.executeAggregation


executeCount()​

protected executeCount(filter, max?): Promise<CountResult>

Defined in: packages/models/lib/repositories/abstract.d.ts:288

Count the objects matching a validated filter

Backends override it to count natively. The default scans iterate() in memory, under the fallback policy. It does not go through executeAggregation: an aggregation has no cap.

Parameters​

filter​

Expression

the filter, without ORDER BY, LIMIT or OFFSET

max?​

number

stop after max objects, undefined for an exact count

Returns​

Promise<CountResult>

the count

Inherited from​

AbstractRepository.executeCount


exists()​

exists(uuid): Promise<boolean>

Defined in: packages/models/lib/repositories/event.d.ts:152

Parameters​

uuid​

PrimaryKeyType<InstanceType<T>>

Returns​

Promise<boolean>

Overrides​

AbstractRepository.exists


fromUID()​

fromUID(uid): ModelRefWithCreate<InstanceType<T>>

Defined in: packages/models/lib/repositories/abstract.d.ts:92

Return a ref from the uuid

Parameters​

uid​

string

the serialized primary key

Returns​

ModelRefWithCreate<InstanceType<T>>

a model reference with create capability

Inherited from​

AbstractRepository.fromUID


get()​

get(primaryKey): Promise<HelperProperties<InstanceType<T>>>

Defined in: packages/models/lib/repositories/event.d.ts:130

Parameters​

primaryKey​

PrimaryKeyType<InstanceType<T>>

Returns​

Promise<HelperProperties<InstanceType<T>>>

Overrides​

AbstractRepository.get


getAllowedFields()​

getAllowedFields(): string[]

Defined in: packages/models/lib/repositories/abstract.d.ts:138

Field paths of the model, from its metadata (Reflection and the stored, input and output schemas)

Used to validate UPDATE SET targets.

Returns​

string[]

the field names, undefined when the model carries no field metadata (no validation then)

Inherited from​

AbstractRepository.getAllowedFields


getCompletionFields()​

getCompletionFields(): CompletionField[]

Defined in: packages/models/lib/repositories/abstract.d.ts:143

Completion fields of the model, flattened from its schemas

Returns​

CompletionField[]

array of completion fields

Inherited from​

AbstractRepository.getCompletionFields


getMaxListeners()​

getMaxListeners(): number

Defined in: packages/models/lib/repositories/abstract.d.ts:334

EventEmitter-compatibility shim. Returns the max-listeners hint.

Returns​

number

the current max-listeners hint

Inherited from​

AbstractRepository.getMaxListeners


getPrimaryKey()​

Call Signature​

getPrimaryKey(object, forceObject?): PrimaryKeyType<InstanceType<T>>

Defined in: packages/models/lib/repositories/abstract.d.ts:112

Get the primary key value for an object as a scalar or string.

Parameters​
object​

any

forceObject?​

false

Returns​

PrimaryKeyType<InstanceType<T>>

Inherited from​

AbstractRepository.getPrimaryKey

Call Signature​

getPrimaryKey(object, forceObject): PrimaryKey<InstanceType<T>>

Defined in: packages/models/lib/repositories/abstract.d.ts:114

Get the primary key value for an object as a structured key object.

Parameters​
object​

any

forceObject​

true

Returns​

PrimaryKey<InstanceType<T>>

Inherited from​

AbstractRepository.getPrimaryKey


getRootModel()​

getRootModel(): T

Defined in: packages/models/lib/repositories/abstract.d.ts:47

Returns​

T

Inherited from​

AbstractRepository.getRootModel


getTableRoot()​

getTableRoot(): ModelClass<Storable<any, any>>

Defined in: packages/models/lib/repositories/abstract.d.ts:57

Returns​

ModelClass<Storable<any, any>>

the model owning the untyped rows of the storage

Inherited from​

AbstractRepository.getTableRoot


getUID()​

getUID(object): string

Defined in: packages/models/lib/repositories/abstract.d.ts:116

Parameters​

object​

any

Returns​

string

Inherited from​

AbstractRepository.getUID


incrementAttribute()​

incrementAttribute<K, L>(primaryKey, info, _conditionField?, _condition?): Promise<void>

Defined in: packages/models/lib/repositories/abstract.d.ts:124

Type Parameters​

K​

K extends string

L​

L extends string

Parameters​

primaryKey​

PK<InstanceType<T>, InstanceType<T>[typeof WEBDA_PRIMARY_KEY][number]>

info​

L | { property: L; value?: number; }

_conditionField?​

K

_condition?​

any

Returns​

Promise<void>

Inherited from​

AbstractRepository.incrementAttribute


incrementAttributes()​

incrementAttributes<K, L>(primaryKey, info, _conditionField?, _condition?): Promise<void | Record<string, number>>

Defined in: packages/models/lib/repositories/event.d.ts:37

Increment numeric attributes with event emission

Type Parameters​

K​

K extends string

L​

L extends string

Parameters​

primaryKey​

PK<InstanceType<T>, InstanceType<T>[typeof WEBDA_PRIMARY_KEY][number]>

info​

(L | { property: L; value?: number; })[] | Record<L, number>

_conditionField?​

K

_condition?​

any

Returns​

Promise<void | Record<string, number>>

Overrides​

AbstractRepository.incrementAttributes


iterate()​

iterate(query, params?): AsyncGenerator<InstanceType<T>, any, any>

Defined in: packages/models/lib/repositories/event.d.ts:60

Iterate through all objects

Parameters​

query​

string

the query filter

params?​

QueryParameters

values for the ? or :name placeholders, bound before reaching the underlying repository

Returns​

AsyncGenerator<InstanceType<T>, any, any>

an async generator of objects

Overrides​

AbstractRepository.iterate


monitor()​

protected monitor<R>(operation, query, fn, details): Promise<R>

Defined in: packages/models/lib/repositories/abstract.d.ts:247

Helper that times a query operation, catches and rethrows errors, and calls onQuery safely

Type Parameters​

R​

R

Parameters​

operation​

QueryOperation

the query operation

query​

string

the query string

fn​

() => Promise<R>

the async function to execute and time

details​

((r) => object) | ((r) => number)

optional callback to extract result count or pagination details

Returns​

Promise<R>

the result of fn

Inherited from​

AbstractRepository.monitor


off()​

off<K>(event, listener): void

Defined in: packages/models/lib/repositories/abstract.d.ts:316

Type Parameters​

K​

K extends string | number | symbol

Parameters​

event​

K

listener​

(data) => void

Returns​

void

Inherited from​

AbstractRepository.off


on()​

on<K>(event, listener): void

Defined in: packages/models/lib/repositories/abstract.d.ts:312

Type Parameters​

K​

K extends string | number | symbol

Parameters​

event​

K

listener​

(data) => void

Returns​

void

Inherited from​

AbstractRepository.on


once()​

once<K>(event, listener): void

Defined in: packages/models/lib/repositories/abstract.d.ts:314

Type Parameters​

K​

K extends string | number | symbol

Parameters​

event​

K

listener​

(data) => void

Returns​

void

Inherited from​

AbstractRepository.once


parseLegacyUID()​

protected parseLegacyUID(uid): PrimaryKey<InstanceType<T>>

Defined in: packages/models/lib/repositories/abstract.d.ts:108

Parse a uid through the model's parseLegacyUID hook

Parameters​

uid​

string

the raw storage key

Returns​

PrimaryKey<InstanceType<T>>

a key whose string form is the raw uid, or undefined when the model does not recognise it

Inherited from​

AbstractRepository.parseLegacyUID


parseStatement()​

protected parseStatement(type, statement, params?): Promise<Query>

Defined in: packages/models/lib/repositories/abstract.d.ts:156

Parse a bulk statement and check it is of the expected type

For an UPDATE, every SET target is checked: no primary key field, no private (__) segment, no constructor/prototype segment, and a field of the model when its metadata lists them.

Parameters​

type​

"DELETE" | "UPDATE"

the expected statement type

statement​

string | Query

the statement string or its parsed form

params?​

QueryParameters

values for the placeholders of a statement string

Returns​

Promise<Query>

the parsed statement

Throws​

WebdaQLError when the statement has another type or a SET target is refused

Throws​

SyntaxError when the statement does not parse, or a SET target is not a field of the model

Inherited from​

AbstractRepository.parseStatement


parseUID()​

parseUID(uid, forceObject?): PrimaryKeyType<InstanceType<T>> | PrimaryKey<InstanceType<T>>

Defined in: packages/models/lib/repositories/abstract.d.ts:102

Parse a serialized primary key

A composite key that does not split into the primary key fields is offered to the model's optional static parseLegacyUID(uid) hook (see WEBDA_LEGACY_UID): the returned key keeps the raw uid as its string form so it addresses the legacy storage entry. Without a hook, or when the hook declines, the uid is rejected.

Parameters​

uid​

string

forceObject?​

boolean

Returns​

PrimaryKeyType<InstanceType<T>> | PrimaryKey<InstanceType<T>>

Inherited from​

AbstractRepository.parseUID


patch()​

patch<K>(primaryKey, data, _conditionField?, _condition?): Promise<void>

Defined in: packages/models/lib/repositories/event.d.ts:140

Patch with event emission (emits Patch before and Patched after)

Type Parameters​

K​

K extends string

Parameters​

primaryKey​

PK<InstanceType<T>, InstanceType<T>[typeof WEBDA_PRIMARY_KEY][number]>

data​

Partial<InstanceType<T>>

_conditionField?​

K

_condition?​

any

Returns​

Promise<void>

Overrides​

AbstractRepository.patch


query()​

query(query, params?): Promise<{ continuationToken?: string; results: InstanceType<T>[]; }>

Defined in: packages/models/lib/repositories/event.d.ts:50

Query with event emission

Parameters are bound here, so the events carry the bound query and the underlying repository (often a store one) only ever receives a plain query.

Parameters​

query​

string

the query to execute

params?​

QueryParameters

values for the ? or :name placeholders

Returns​

Promise<{ continuationToken?: string; results: InstanceType<T>[]; }>

the query results with optional continuation token

Overrides​

AbstractRepository.query


ref()​

ref(key): ModelRefWithCreate<InstanceType<T>>

Defined in: packages/models/lib/repositories/abstract.d.ts:122

Parameters​

key​

PK<InstanceType<T>, InstanceType<T>[typeof WEBDA_PRIMARY_KEY][number]>

Returns​

ModelRefWithCreate<InstanceType<T>>

Inherited from​

AbstractRepository.ref


removeAttribute()​

removeAttribute<L, K>(uuid, attribute, conditionField?, condition?): Promise<void>

Defined in: packages/models/lib/repositories/event.d.ts:128

Remove attribute with event emission

Type Parameters​

L​

L extends string

K​

K extends string

Parameters​

uuid​

PrimaryKeyType<InstanceType<T>>

attribute​

K

conditionField?​

L

condition?​

PropertyPathType<InstanceType<T>, L> | JSONed<PropertyPathType<InstanceType<T>, L>>

Returns​

Promise<void>

Overrides​

AbstractRepository.removeAttribute


removeListener()​

removeListener<K>(event, listener): void

Defined in: packages/models/lib/repositories/abstract.d.ts:329

EventEmitter-compatibility alias for off. Consumers that treat a repository as a Node EventEmitter (e.g. @webda/runtime EventIterator) call removeListener.

Type Parameters​

K​

K extends string | number | symbol

Parameters​

event​

K

the event name

listener​

(data) => void

the listener to remove

Returns​

void

Inherited from​

AbstractRepository.removeListener


safeOnQuery()​

protected safeOnQuery(info): void

Defined in: packages/models/lib/repositories/abstract.d.ts:238

Safely invoke the onQuery callback without throwing into the caller

Parameters​

info​

QueryExecutionInfo

query execution info

Returns​

void

Inherited from​

AbstractRepository.safeOnQuery


setAttribute()​

setAttribute<K, L>(primaryKey, attribute, value, conditionField?, condition?): Promise<void>

Defined in: packages/models/lib/repositories/abstract.d.ts:120

Type Parameters​

K​

K extends string

L​

L extends string

Parameters​

primaryKey​

string | PK<InstanceType<T>, InstanceType<T>[typeof WEBDA_PRIMARY_KEY][number]>

attribute​

K

value​

_PropertyPathType<InstanceType<T>, K>

conditionField?​

L

condition?​

_PropertyPathType<InstanceType<T>, L> | JSONed<_PropertyPathType<InstanceType<T>, L>>

Returns​

Promise<void>

Inherited from​

AbstractRepository.setAttribute


setMaxListeners()​

setMaxListeners(n): this

Defined in: packages/models/lib/repositories/abstract.d.ts:340

EventEmitter-compatibility shim. Records the max-listeners hint (no enforcement).

Parameters​

n​

number

the new hint value

Returns​

this

this for chaining

Inherited from​

AbstractRepository.setMaxListeners


setTableRoot()​

setTableRoot(root?): this

Defined in: packages/models/lib/repositories/event.d.ts:32

Set the table root on the wrapped repository too: it filters the untyped rows

Parameters​

root?​

ModelClass

the model owning the untyped rows of the storage

Returns​

this

this

Overrides​

AbstractRepository.setTableRoot


typeResolver()​

protected typeResolver(): ModelTypeResolver

Defined in: packages/models/lib/repositories/abstract.d.ts:63

Resolver of the stored __type: the installed application one when it knows the model, else the model's own hierarchy with exact identifiers only

Returns​

ModelTypeResolver

the resolver

Inherited from​

AbstractRepository.typeResolver


update()​

update<K>(data, conditionField?, condition?): Promise<void>

Defined in: packages/models/lib/repositories/event.d.ts:145

Update with event emission (emits Update before and Updated after)

Type Parameters​

K​

K extends string

Parameters​

data​

Helpers<InstanceType<T>>

conditionField?​

K

condition?​

PropertyPathType<InstanceType<T>, K>

Returns​

Promise<void>

Overrides​

AbstractRepository.update


updateMany()​

updateMany(statement, params?): Promise<number>

Defined in: packages/models/lib/repositories/event.d.ts:109

Update in bulk through the underlying repository

Bulk operations emit no per-object event: see Repository.updateMany.

Parameters​

statement​

string | Query

the UPDATE statement or its parsed form

params?​

QueryParameters

values for the placeholders

Returns​

Promise<number>

the number of objects updated

Overrides​

AbstractRepository.updateMany


updateManyByKey()​

protected updateManyByKey(statement, params?): Promise<number>

Defined in: packages/models/lib/repositories/abstract.d.ts:201

Generic updateMany: collect the matching keys (up to LIMIT), then patch them one by one with this repository's patch primitive. A dotted target reads the object to rewrite its top-level field.

Used by stores without a native bulk update. On a store repository the primitive emits no event.

Parameters​

statement​

string | Query

the UPDATE statement or its parsed form

params?​

QueryParameters

values for the placeholders

Returns​

Promise<number>

the number of objects updated

Inherited from​

AbstractRepository.updateManyByKey


upsert()​

upsert(data): Promise<InstanceType<T>>

Defined in: packages/models/lib/repositories/abstract.d.ts:118

Parameters​

data​

Helpers<InstanceType<T>>

Returns​

Promise<InstanceType<T>>

Inherited from​

AbstractRepository.upsert


upsertItemToCollection()​

upsertItemToCollection<K, L>(uuid, collection, item, index?, itemWriteConditionField?, itemWriteCondition?): Promise<void>

Defined in: packages/models/lib/repositories/event.d.ts:123

Upsert item to collection with event emission

Type Parameters​

K​

K extends string

L​

L extends string | number | symbol

Parameters​

uuid​

PrimaryKeyType<InstanceType<T>>

collection​

K

item​

ArrayElement<InstanceType<T>[K]> | JSONed<ArrayElement<InstanceType<T>[K]>>

index?​

number

itemWriteConditionField?​

ArrayElement<InstanceType<T>[K]> extends object ? L : never

itemWriteCondition?​

ArrayElement<InstanceType<T>[K]> extends object ? object & ArrayElement[L] : ArrayElement<InstanceType<T>[K]>

Returns​

Promise<void>

Overrides​

AbstractRepository.upsertItemToCollection


writeIfPresent()​

protected writeIfPresent(key, write): Promise<boolean>

Defined in: packages/models/lib/repositories/abstract.d.ts:181

Run one write of the generic fallback; an object deleted since the keys were collected is skipped

Parameters​

key​

PrimaryKeyType<InstanceType<T>>

the primary key

write​

() => Promise<void>

the write

Returns​

Promise<boolean>

true when written, false when the object is gone

Throws​

the write error when the object still exists

Inherited from​

AbstractRepository.writeIfPresent