MemoryRepository
Class: MemoryRepository<T, K>
Defined in: packages/models/src/repositories/memory.ts:58
This is a simple in-memory repository implementation It is used for testing purposes only
Extends
Type Parameters
T
T extends ModelClass
K
K extends Map<string, string> = Map<string, string>
Constructors
Constructor
new MemoryRepository<
T,K>(model,pks,separator?,map?):MemoryRepository<T,K>
Defined in: packages/models/src/repositories/memory.ts:71
Parameters
model
T
The model class constructor
pks
string[]
Primary key field names
separator?
string
Composite key separator (default: "_")
map?
K
Optional pre-existing Map to use as storage backend; a TypeIndexedMap lets queries skip the entries of other models without parsing them
Returns
MemoryRepository<T, K>
Overrides
AbstractRepository.constructor
Properties
[WEBDA_TEST]
[WEBDA_TEST]:
object
Defined in: packages/models/src/repositories/memory.ts:857
Test utilities - clears all stored data
clear
clear: () =>
Promise<void>
Returns
Promise<void>
aggregationOptions
protectedaggregationOptions:AggregationOptions
Defined in: packages/models/src/repositories/abstract.ts:42
Aggregation fallback policy, set by the owning store through configureAggregation
Inherited from
AbstractRepository.aggregationOptions
events
protectedevents:Map<keyofInstanceType<T>[typeofWEBDA_EVENTS],Set<(data) =>void>>
Defined in: packages/models/src/repositories/abstract.ts:39
Registered event listeners keyed by event name
Inherited from
maxListeners
protectedmaxListeners:number=100
Defined in: packages/models/src/repositories/abstract.ts:891
Max-listeners hint kept for Node EventEmitter API compatibility. Not
enforced — repositories use an unbounded Set per event.
Inherited from
AbstractRepository.maxListeners
model
protectedmodel:T
Defined in: packages/models/src/repositories/abstract.ts:62
The model class constructor
Inherited from
monitorOptions
protectedmonitorOptions:QueryMonitorOptions={}
Defined in: packages/models/src/repositories/abstract.ts:44
Query monitoring options, set by the owning store through configureMonitoring
Inherited from
AbstractRepository.monitorOptions
pks
protectedpks:string[]
Defined in: packages/models/src/repositories/abstract.ts:63
Array of primary key field names
Inherited from
separator
protectedseparator:string="_"
Defined in: packages/models/src/repositories/abstract.ts:64
Separator used when joining composite key fields into a string (default: "_")
Inherited from
storage
protectedstorage:K
Defined in: packages/models/src/repositories/memory.ts:62
tableRoot?
protectedoptionaltableRoot?:ModelClass<Storable<any,any>>
Defined in: packages/models/src/repositories/abstract.ts:50
Model owning the untyped rows of the storage (the first model of the store), undefined when not known
Inherited from
warnedAggregations
protectedwarnedAggregations:Set<string>
Defined in: packages/models/src/repositories/abstract.ts:46
Fallback shapes already warned about
Inherited from
AbstractRepository.warnedAggregations
Methods
acceptedTypes()
acceptedTypes():
string[]
Defined in: packages/models/src/repositories/abstract.ts:109
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/src/repositories/abstract.ts:700
Keep the full generic signature here (not spec: any): concrete repositories are used
directly in code and tests, and must expose the typed rows.
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>
params?
QueryParameters
Returns
Promise<AggregationResult<AggregatedRow<InstanceType<T>, G, M>>>
Inherited from
aggregateInMemory()
protectedaggregateInMemory(query):Promise<Record<string,unknown>[]>
Defined in: packages/models/src/repositories/abstract.ts:799
Aggregate by streaming the filtered items
Parameters
query
AggregationQuery
the aggregation
Returns
Promise<Record<string, unknown>[]>
the rows
Inherited from
AbstractRepository.aggregateInMemory
applyAssignments()
protectedapplyAssignments<O>(target,assignments):O
Defined in: packages/models/src/repositories/abstract.ts:466
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/src/repositories/abstract.ts:121
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
buildClassFilter()
protectedbuildClassFilter():string|undefined
Defined in: packages/models/src/repositories/memory.ts:392
Build the WebdaQL class-filter clause __type IN ['A', 'B', ...] covering
this.model's identifier and every transitive descendant.
Returns undefined when the model carries no Metadata.
Returns
string | undefined
the class-filter WebdaQL clause, or undefined when no Metadata
buildClassFilterIdentifiers()
protectedbuildClassFilterIdentifiers():string[] |undefined
Defined in: packages/models/src/repositories/memory.ts:377
Collect the WebdaQL class-filter identifier list — this.model's
identifier and every transitive descendant.
Returns undefined when the model carries no Metadata (plain unit-test
classes that didn't go through Application.setModelMetadata). In that
case query() skips the prepend and returns everything in storage,
preserving the pre-fix behavior for those bare classes.
Returns
string[] | undefined
the list of identifiers to match, or undefined when no Metadata
buildItem()
protectedbuildItem(data):InstanceType<T>
Defined in: packages/models/src/repositories/abstract.ts:138
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
checkAggregationFallback()
protectedcheckAggregationFallback(query,reason):Promise<void>
Defined in: packages/models/src/repositories/abstract.ts:730
Apply the fallback policy before aggregating or counting in memory
Parameters
query
AggregationQuery | undefined
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
checkCondition()
protectedcheckCondition<K>(item,conditionField?,condition?):void
Defined in: packages/models/src/repositories/memory.ts:135
Verify an optimistic locking condition on an item
Type Parameters
K
K extends string
Parameters
item
InstanceType<T>
The item to check
conditionField?
K | null
Field to validate
condition?
any
Expected value
Returns
void
Throws
Error if the condition does not match
checkItemWriteCondition()
protectedcheckItemWriteCondition(item,index,itemWriteConditionField,itemWriteCondition):void
Defined in: packages/models/src/repositories/memory.ts:775
Verify a write condition on a collection item
Parameters
item
any[]
The array to check
index
number
Index of the item in the array
itemWriteConditionField
string
Field name to check on the item
itemWriteCondition
any
Expected value for the field
Returns
void
Throws
Error if the condition does not match
collectStatementKeys()
protectedcollectStatementKeys(statement):Promise<PrimaryKeyType<InstanceType<T>>[]>
Defined in: packages/models/src/repositories/abstract.ts:488
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/src/repositories/abstract.ts:611
Copy the known options (fallback, maxGroups, warn); undefined values keep the current ones
Parameters
options
Partial<AggregationOptions>
Returns
void
Throws
Error when maxGroups is not a positive integer or fallback is unknown
Inherited from
AbstractRepository.configureAggregation
configureMonitoring()
configureMonitoring(
options):void
Defined in: packages/models/src/repositories/abstract.ts:628
Configure the query monitoring policy, called by the owning store
Parameters
options
Partial<QueryMonitorOptions>
options to override
Returns
void
Inherited from
AbstractRepository.configureMonitoring
count()
count(
filter?,params?,options?):Promise<CountResult>
Defined in: packages/models/src/repositories/abstract.ts:752
Parse the filter, refuse statements, drop ORDER BY / LIMIT / OFFSET and run executeCount
Parameters
filter?
string
params?
QueryParameters
options?
Returns
Promise<CountResult>
Throws
Error when max is not a positive integer
Inherited from
countInMemory()
protectedcountInMemory(filter,max?):Promise<Omit<CountResult,"native">>
Defined in: packages/models/src/repositories/abstract.ts:785
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/src/repositories/memory.ts:100
Parameters
data
Helpers<InstanceType<T>>
save?
boolean = true
Returns
Promise<InstanceType<T>>
Overrides
currentTypeOf()
protectedcurrentTypeOf(instance,stored?):string|undefined
Defined in: packages/models/src/repositories/memory.ts:294
The __type to attach to a loaded instance: the current identifier of its class, the stored value when it is
unknown or ambiguous (never rewritten to a guess), the repository model identifier for an untyped row
Parameters
instance
any
the loaded instance
stored?
string
the stored __type
Returns
string | undefined
the value to attach
delete()
delete<
K>(primaryKey,conditionField?,condition?):Promise<void>
Defined in: packages/models/src/repositories/memory.ts:685
Type Parameters
K
K extends string
Parameters
primaryKey
PK<InstanceType<T>, InstanceType<T>[typeof WEBDA_PRIMARY_KEY][number]>
conditionField?
K | null
condition?
any
Returns
Promise<void>
Overrides
deleteItemFromCollection()
deleteItemFromCollection<
K,L>(primaryKey,collection,index,itemWriteConditionField?,itemWriteCondition?):Promise<void>
Defined in: packages/models/src/repositories/memory.ts:820
Type Parameters
K
K extends string
L
L extends string | number | symbol
Parameters
primaryKey
PK<InstanceType<T>, InstanceType<T>[typeof WEBDA_PRIMARY_KEY][number]>
collection
K
index
number
itemWriteConditionField?
any
itemWriteCondition?
any
Returns
Promise<void>
Overrides
AbstractRepository.deleteItemFromCollection
deleteMany()
deleteMany(
statement,params?):Promise<number>
Defined in: packages/models/src/repositories/memory.ts:659
Delete in bulk, directly in the storage map: no event (see Repository.deleteMany)
Parameters
statement
string | Query
params?
QueryParameters
Returns
Promise<number>
Overrides
deleteManyByKey()
protecteddeleteManyByKey(statement,params?):Promise<number>
Defined in: packages/models/src/repositories/abstract.ts:530
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
deserialize()
deserialize(
item):InstanceType<T>
Defined in: packages/models/src/repositories/memory.ts:234
Unserialize the object from a string
Beyond restoring the concrete type via @webda/serialize's
$serializer.type typeKey, this also surfaces the storage envelope's
__type stamp on the in-memory instance as a NON-ENUMERABLE property. The
non-enumerable bit keeps __type invisible to JSON.stringify and
Object.keys (so API responses and re-serialize cycles are byte-identical
for the model's own fields), while still being readable via direct
property access — which is exactly how WebdaQL's filter eval reads it
(ComparisonExpression.getAttributeValue walks obj[name]).
Backward-compat: legacy rows written before the envelope-stamping was
introduced won't carry __type. In that case we backfill from the
repository's own model.Metadata.Identifier so they look like records of
the parent class — which is exactly what query()'s prepended class
filter expects (parent + descendants). Plain unit-test classes without
Metadata get no stamp at all; their repos opt out of class filtering on
the query side too (see query).
Parameters
item
string
the serialized string
Returns
InstanceType<T>
the deserialized model instance
deserializeEnvelope()
protecteddeserializeEnvelope(item,raw,stored?):any
Defined in: packages/models/src/repositories/memory.ts:273
Deserialize a serializer envelope
A row written under a model's former identifier (renamed, see @WebdaAlias) names a serializer that no longer
exists: it is deserialized with the serializer of the class its __type resolves to.
Parameters
item
string
the stored string
raw
any
the parsed envelope
stored?
string
the stored __type
Returns
any
the instance
emit()
emit<
K>(event,data):Promise<void>
Defined in: packages/models/src/repositories/abstract.ts:930
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
excludePrimaryKey()
excludePrimaryKey(
object):any
Defined in: packages/models/src/repositories/abstract.ts:222
Parameters
object
any
Returns
any
Inherited from
AbstractRepository.excludePrimaryKey
executeAggregation()
protectedexecuteAggregation(query):Promise<AggregationResult<any>>
Defined in: packages/models/src/repositories/memory.ts:584
A plain MemoryRepository (MemoryStore, FileStore) aggregates its own local data: that is native. Subclasses backed by a remote database (Firestore, Dynamo, ...) inherit the fallback instead.
Parameters
query
AggregationQuery
Returns
Promise<AggregationResult<any>>
Overrides
AbstractRepository.executeAggregation
executeCount()
protectedexecuteCount(filter,max?):Promise<CountResult>
Defined in: packages/models/src/repositories/memory.ts:596
A plain MemoryRepository (MemoryStore, FileStore) counts its own local data: that is native. Subclasses backed by a remote database (Firestore, Dynamo, ...) inherit the fallback instead.
Parameters
filter
Expression
max?
number
Returns
Promise<CountResult>
Overrides
AbstractRepository.executeCount
exists()
exists(
primaryKey):Promise<boolean>
Defined in: packages/models/src/repositories/memory.ts:698
Parameters
primaryKey
string | PK<InstanceType<T>, InstanceType<T>[typeof WEBDA_PRIMARY_KEY][number]>
Returns
Promise<boolean>
Overrides
findModelClass()
protectedfindModelClass(identifier):any
Defined in: packages/models/src/repositories/memory.ts:328
Find the class to hydrate a row typed identifier (a Webda 3 legacy form included): the resolved model when it
is the repository model or one of its transitive subclasses, the repository model for an ancestor type or an
unknown or ambiguous type
Parameters
identifier
string
stored __type
Returns
any
the class, this.model when it carries no Metadata, or undefined for an unrelated model
fromUID()
fromUID(
uid):ModelRefWithCreate<InstanceType<T>>
Defined in: packages/models/src/repositories/abstract.ts:171
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
get()
get(
primaryKey):Promise<HelperProperties<InstanceType<T>>>
Defined in: packages/models/src/repositories/memory.ts:76
Parameters
primaryKey
string | PK<InstanceType<T>, InstanceType<T>[typeof WEBDA_PRIMARY_KEY][number]>
Returns
Promise<HelperProperties<InstanceType<T>>>
Overrides
getAllowedFields()
getAllowedFields():
string[] |undefined
Defined in: packages/models/src/repositories/abstract.ts:365
Field paths of the model, from its metadata (Reflection and the stored, input and output schemas)
Used to validate UPDATE SET targets.
Returns
string[] | undefined
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/src/repositories/abstract.ts:382
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/src/repositories/abstract.ts:911
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/src/repositories/abstract.ts:232
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/src/repositories/abstract.ts:234
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/src/repositories/abstract.ts:67
Returns
T
Inherited from
AbstractRepository.getRootModel
getSync()
protectedgetSync(primaryKey):InstanceType<T>
Defined in: packages/models/src/repositories/memory.ts:90
Synchronous read used by conditional writes to keep check-and-set atomic
Parameters
primaryKey
string | PK<InstanceType<T>, InstanceType<T>[typeof WEBDA_PRIMARY_KEY][number]>
key of the item
Returns
InstanceType<T>
the deserialized item
getTableRoot()
getTableRoot():
ModelClass<Storable<any,any>> |undefined
Defined in: packages/models/src/repositories/abstract.ts:84
Returns
ModelClass<Storable<any, any>> | undefined
the model owning the untyped rows of the storage
Inherited from
AbstractRepository.getTableRoot
getUID()
getUID(
object):string
Defined in: packages/models/src/repositories/abstract.ts:307
Parameters
object
any
Returns
string
Inherited from
hydratePlainRow()
protectedhydratePlainRow(raw):InstanceType<T>
Defined in: packages/models/src/repositories/memory.ts:351
Hydrate a plain JSON row as an instance of the repository model (or of the transitive subclass named by its
__type; an ancestor type hydrates as the repository model), the same way document stores hydrate their rows;
a row typed as an unrelated model is refused
Parameters
raw
any
the parsed row
Returns
InstanceType<T>
the model instance
incrementAttribute()
incrementAttribute<
K,L>(primaryKey,info,_conditionField?,_condition?):Promise<void>
Defined in: packages/models/src/repositories/abstract.ts:340
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 | null
_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/src/repositories/memory.ts:734
Increment attributes atomically: the read-modify-write never yields, so concurrent calls all count
Type Parameters
K
K extends string
L
L extends string
Parameters
primaryKey
string | PK<InstanceType<T>, InstanceType<T>[typeof WEBDA_PRIMARY_KEY][number]>
info
(L | { property: L; value?: number; })[] | Record<L, number>
_conditionField?
K | null
_condition?
any
Returns
Promise<void | Record<string, number>>
the new value of each incremented attribute, by path
Overrides
AbstractRepository.incrementAttributes
isPlainRow()
protectedisPlainRow(raw):boolean
Defined in: packages/models/src/repositories/memory.ts:311
Whether a stored row is a plain JSON object without a serializer envelope
Rows written by earlier versions (e.g. a v3 FileStore folder or MemoryStore persistence file) store the
object itself, its type in a top-level __type.
Parameters
raw
any
the parsed row
Returns
boolean
true for a plain object row
iterate()
iterate(
query,params?):AsyncGenerator<InstanceType<T>,any,any>
Defined in: packages/models/src/repositories/memory.ts:608
Add iterator support
Parameters
query
string
the query string
params?
QueryParameters
values for the ? or :name placeholders
Returns
AsyncGenerator<InstanceType<T>, any, any>
Overrides
listKeysOfModel()
protectedlistKeysOfModel(ids?):string[]
Defined in: packages/models/src/repositories/memory.ts:485
List the storage keys that may belong to this model
A storage shared by several models holds foreign entries whose key shape can be invalid for this
repository: they are skipped from the stored __type before any parsing. Entries are kept when their stored
__type belongs to the model (legacy forms included). Untyped entries, and entries typed as a strict ancestor
of the table root, belong to the table root and its ancestors. Unreadable entries are kept so their error
surfaces.
A TypeIndexedMap storage answers from its type index: only the keys of the model are visited. Any other Map-like storage is scanned, parsing every entry.
Parameters
ids?
string[]
class identifiers (model and subclasses), undefined to keep everything
Returns
string[]
the keys to evaluate
matchStorage()
protectedmatchStorage(statement):object[]
Defined in: packages/models/src/repositories/memory.ts:636
Keys of the stored objects of this model matching a statement's WHERE, at most LIMIT
Synchronous: the statement then runs without yielding, so no other write interleaves and an object is never met twice.
Parameters
statement
Query
the parsed statement
Returns
object[]
the storage keys and their objects
monitor()
protectedmonitor<R>(operation,query,fn,details):Promise<R>
Defined in: packages/models/src/repositories/abstract.ts:652
Helper that times a query operation, catches and rethrows errors, and calls onQuery safely
Type Parameters
R
R
Parameters
operation
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
off()
off<
K>(event,listener):void
Defined in: packages/models/src/repositories/abstract.ts:880
Type Parameters
K
K extends string | number | symbol
Parameters
event
K
listener
(data) => void
Returns
void
Inherited from
on()
on<
K>(event,listener):void
Defined in: packages/models/src/repositories/abstract.ts:857
Type Parameters
K
K extends string | number | symbol
Parameters
event
K
listener
(data) => void
Returns
void
Inherited from
once()
once<
K>(event,listener):void
Defined in: packages/models/src/repositories/abstract.ts:868
Type Parameters
K
K extends string | number | symbol
Parameters
event
K
listener
(data) => void
Returns
void
Inherited from
parseLegacyUID()
protectedparseLegacyUID(uid):PrimaryKey<InstanceType<T>> |undefined
Defined in: packages/models/src/repositories/abstract.ts:210
Parse a uid through the model's parseLegacyUID hook
Parameters
uid
string
the raw storage key
Returns
PrimaryKey<InstanceType<T>> | undefined
a key whose string form is the raw uid, or undefined when the model does not recognise it
Inherited from
AbstractRepository.parseLegacyUID
parseStatement()
protectedparseStatement(type,statement,params?):Promise<Query>
Defined in: packages/models/src/repositories/abstract.ts:403
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/src/repositories/abstract.ts:184
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
patch()
patch<
K>(primaryKey,data,conditionField?,condition?):Promise<void>
Defined in: packages/models/src/repositories/memory.ts:147
Type Parameters
K
K extends string
Parameters
primaryKey
string | PK<InstanceType<T>, InstanceType<T>[typeof WEBDA_PRIMARY_KEY][number]>
data
Partial<InstanceType<T>>
conditionField?
K | null
condition?
any
Returns
Promise<void>
Overrides
query()
query(
query,params?):Promise<{continuationToken?:string;results:InstanceType<T>[]; }>
Defined in: packages/models/src/repositories/memory.ts:425
Add query support
Class filtering: when several model classes share the same underlying
storage Map (e.g. a model and its subclasses each registering their own
repository pointing at the same Map via MemoryStore.getRepository),
results are restricted to instances of this.model and its transitive
descendants. The filter is applied as a real WebdaQL clause —
__type IN ['Webda/Post', 'Webda/BlogPost', ...] — prepended to the
caller's query via WebdaQL.PrependCondition (string path) or merged
directly into the AST (parsed-Query path used by iterate). Each stored
item carries its __type as a non-enumerable property courtesy of
deserialize, so the WebdaQL filter eval reads it directly without
leaking it to JSON serialization. There is no post-filter step.
Models without Metadata (plain unit-test classes) opt out of the
prepend — buildClassFilterIdentifiers returns undefined and the query
runs as given. External storage backends that adopt the same __type
stamping convention can use buildClassFilter to produce the equivalent
server-side WHERE clause.
Parameters
query
string | Query
the query string or parsed query
params?
QueryParameters
values for the ? or :name placeholders of a query string
Returns
Promise<{ continuationToken?: string; results: InstanceType<T>[]; }>
the query results with optional continuation token
Overrides
ref()
ref(
key):ModelRefWithCreate<InstanceType<T>>
Defined in: packages/models/src/repositories/abstract.ts:333
Parameters
key
PK<InstanceType<T>, InstanceType<T>[typeof WEBDA_PRIMARY_KEY][number]>
Returns
ModelRefWithCreate<InstanceType<T>>
Inherited from
removeAttribute()
removeAttribute<
L,K>(primaryKey,attribute,_conditionField?,_condition?):Promise<void>
Defined in: packages/models/src/repositories/memory.ts:845
Type Parameters
L
L extends string
K
K extends string
Parameters
primaryKey
PK<InstanceType<T>, InstanceType<T>[typeof WEBDA_PRIMARY_KEY][number]>
attribute
K
_conditionField?
L | null
_condition?
any
Returns
Promise<void>
Overrides
AbstractRepository.removeAttribute
removeListener()
removeListener<
K>(event,listener):void
Defined in: packages/models/src/repositories/abstract.ts:900
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
resolvePath()
protectedresolvePath(item,path):object
Defined in: packages/models/src/repositories/memory.ts:710
Resolve the parent object and last key of a dotted path, creating intermediate objects
Parameters
item
any
root object
path
string
dotted path
Returns
object
the holder and the last key
holder
holder:
any
key
key:
string
safeOnQuery()
protectedsafeOnQuery(info):void
Defined in: packages/models/src/repositories/abstract.ts:636
Safely invoke the onQuery callback without throwing into the caller
Parameters
info
query execution info
Returns
void
Inherited from
AbstractRepository.safeOnQuery
serialize()
serialize(
item):string
Defined in: packages/models/src/repositories/memory.ts:187
Serialize the object to a string
This method is used to allow switching between different serialization methods
The serialized payload is also stamped with a top-level __type field
carrying the concrete model identifier when available
(item.constructor.Metadata?.Identifier). This lets query() and external
storage backends filter results by class without re-instantiating every
item — important when a single underlying storage map is shared across a
model and its subclasses (the common case in production where each
registered model owns its own MemoryRepository pointing at the same Map).
The stamp lives on the serializer envelope (sibling of value /
$serializer), not inside value. deserialize() re-surfaces it on the
reconstructed instance as a non-enumerable __type property so WebdaQL's
filter eval can read it without it ever leaking into JSON.stringify or
Object.keys output — keeping API responses and re-serialize cycles
byte-identical for the model's own fields.
Models that don't carry Metadata (plain unit-test classes that don't go through Application.setModelMetadata) simply skip the stamp; the resulting payload is byte-identical to the previous implementation.
Parameters
item
InstanceType<T>
to serialize
Returns
string
serialized object
setAttribute()
setAttribute<
K,L>(primaryKey,attribute,value,conditionField?,condition?):Promise<void>
Defined in: packages/models/src/repositories/abstract.ts:322
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 | null
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/src/repositories/abstract.ts:920
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/src/repositories/abstract.ts:76
Set the model owning the untyped rows of the storage
Parameters
root?
ModelClass<Storable<any, any>>
the first model of the store, undefined when not known
Returns
this
this
Inherited from
AbstractRepository.setTableRoot
typeResolver()
protectedtypeResolver():ModelTypeResolver
Defined in: packages/models/src/repositories/abstract.ts:93
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
the resolver
Inherited from
AbstractRepository.typeResolver
update()
update<
K>(data,conditionField?,condition?):Promise<void>
Defined in: packages/models/src/repositories/memory.ts:115
Type Parameters
K
K extends string
Parameters
data
Helpers<InstanceType<T>>
conditionField?
K | null
condition?
any
Returns
Promise<void>
Overrides
updateMany()
updateMany(
statement,params?):Promise<number>
Defined in: packages/models/src/repositories/memory.ts:675
Update in bulk, directly in the storage map: no event (see Repository.updateMany)
Matches are collected first, then rewritten without yielding: an object whose WHERE field changes is updated once.
Parameters
statement
string | Query
params?
QueryParameters
Returns
Promise<number>
Overrides
updateManyByKey()
protectedupdateManyByKey(statement,params?):Promise<number>
Defined in: packages/models/src/repositories/abstract.ts:549
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/src/repositories/abstract.ts:312
Parameters
data
Helpers<InstanceType<T>>
Returns
Promise<InstanceType<T>>
Inherited from
upsertItemToCollection()
upsertItemToCollection<
K,L>(primaryKey,collection,item,index?,itemWriteConditionField?,itemWriteCondition?):Promise<void>
Defined in: packages/models/src/repositories/memory.ts:791
Type Parameters
K
K extends string
L
L extends string | number | symbol
Parameters
primaryKey
PK<InstanceType<T>, InstanceType<T>[typeof WEBDA_PRIMARY_KEY][number]>
collection
K
item
ArrayElement<InstanceType<T>[K]> | JSONed<ArrayElement<InstanceType<T>[K]>>
index?
number
itemWriteConditionField?
any
itemWriteCondition?
any
Returns
Promise<void>
Overrides
AbstractRepository.upsertItemToCollection
writeIfPresent()
protectedwriteIfPresent(key,write):Promise<boolean>
Defined in: packages/models/src/repositories/abstract.ts:509
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
simulateFind()
staticsimulateFind<T>(query,uuids,repository):Promise<{continuationToken?:string;results:InstanceType<T>[]; }>
Defined in: packages/models/src/repositories/memory.ts:514
Allow to simulate a find on a list of uuids It is static to be reusable by other repository like FileRepository
Type Parameters
T
T extends ModelClass<Storable<any, any>>
Parameters
query
the parsed query
uuids
any[]
the list of UIDs to search
repository
Repository<T>
the repository to fetch objects from
Returns
Promise<{ continuationToken?: string; results: InstanceType<T>[]; }>
the query results with optional continuation token