Skip to main content

Repository

@webda/core


Interface: Repository<T>

Defined in: packages/models/lib/repositories/repository.d.ts:236

Full-featured repository combining all capabilities (backward compatible)

This is the main interface that most code will interact with. It extends all specialized interfaces for backward compatibility.

Note: All methods are inherited from:

  • CoreRepository: Basic CRUD, query, and key management
  • Updatable: Update, patch, and upsert operations
  • AtomicOperations: Atomic increment, setAttribute, removeAttribute
  • CollectionOperations: Array/collection manipulation

Extends​

  • CoreRepository<T>.Updatable<T>.AtomicOperations<T>.CollectionOperations<T>

Type Parameters​

T​

T extends ModelClass = ModelClass

Properties​

[WEBDA_TEST]?​

optional [WEBDA_TEST]?: object

Defined in: packages/models/lib/repositories/repository.d.ts:106

clear()​

clear(): Promise<void>

Returns​

Promise<void>

Inherited from​

CoreRepository.[WEBDA_TEST]

Methods​

create()​

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

Defined in: packages/models/lib/repositories/repository.d.ts:67

Create data in the store

Parameters​

data​

Helpers<InstanceType<T>>

save?​

boolean

if false, create in-memory object without saving

Returns​

Promise<InstanceType<T>>

Inherited from​

CoreRepository.create


delete()​

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

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

Delete data from the store

Type Parameters​

K​

K extends string

Parameters​

uid​

string | PrimaryKeyType<InstanceType<T>>

Primary key or UID string

conditionField?​

K

Field to check for condition (optional)

condition?​

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

Value to check for condition (optional)

Returns​

Promise<void>

Inherited from​

CoreRepository.delete


deleteItemFromCollection()​

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

Defined in: packages/models/lib/repositories/repository.d.ts:210

Remove item from a collection by index

Type Parameters​

K​

K extends string

L​

L extends string | number | symbol

Parameters​

primaryKeyOrUid​

string | PrimaryKeyType<InstanceType<T>>

Primary key of object containing the collection

collection​

K

Name of the array field

index​

number

Position of item to remove

itemWriteConditionField?​

L

Field to check for condition on item

itemWriteCondition?​

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

Expected value for condition field on item

Returns​

Promise<void>

Inherited from​

CollectionOperations.deleteItemFromCollection


emit()​

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

Defined in: packages/models/lib/repositories/repository.d.ts:105

Type Parameters​

K​

K extends string | number | symbol

Parameters​

event​

K

payload​

InstanceType<T>[typeof WEBDA_EVENTS][K]

Returns​

Promise<void>

Inherited from​

CoreRepository.emit


excludePrimaryKey()​

excludePrimaryKey(object): any

Defined in: packages/models/lib/repositories/repository.d.ts:49

Remove the primary key from the object

Parameters​

object​

any

Returns​

any

Inherited from​

CoreRepository.excludePrimaryKey


exists()​

exists(uid): Promise<boolean>

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

Verify if the object exists

Parameters​

uid​

string | PrimaryKeyType<InstanceType<T>>

Returns​

Promise<boolean>

Inherited from​

CoreRepository.exists


fromUID()​

fromUID(uid, forceObject?): ModelRefWithCreate<InstanceType<T>>

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

In REST API, composite keys are represented as a string with the format "key1#key2#key3" We need a way to convert this string to the object

Parameters​

uid​

string

serialized primary key

forceObject?​

boolean

if true, the result will be an object with the primary key fields

Returns​

ModelRefWithCreate<InstanceType<T>>

Inherited from​

CoreRepository.fromUID


get()​

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

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

Get data from the store

Parameters​

primaryKey​

PrimaryKeyType<InstanceType<T>>

Returns​

Promise<HelperProperties<InstanceType<T>>>

Inherited from​

CoreRepository.get


getPrimaryKey()​

getPrimaryKey<K>(object, forceObject?): K extends false ? PrimaryKeyType<InstanceType<T>> : PrimaryKey<InstanceType<T>>

Defined in: packages/models/lib/repositories/repository.d.ts:39

Extract the primary key from the object

Type Parameters​

K​

K

Parameters​

object​

any

to extract the primary key from

forceObject?​

boolean

if true, the result will be an object with the primary key fields

Returns​

K extends false ? PrimaryKeyType<InstanceType<T>> : PrimaryKey<InstanceType<T>>

Inherited from​

CoreRepository.getPrimaryKey


getRootModel()​

getRootModel(): T

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

Get the root model class for this repository

Returns​

T

Inherited from​

CoreRepository.getRootModel


getUID()​

getUID(object): string

Defined in: packages/models/lib/repositories/repository.d.ts:44

Get the UID of the object

Parameters​

object​

any

to extract the primary key from

Returns​

string

Inherited from​

CoreRepository.getUID


incrementAttribute()​

incrementAttribute<K, L>(primaryKeyOrUid, info, conditionField?, condition?): Promise<void>

Defined in: packages/models/lib/repositories/repository.d.ts:163

Atomically increment a single numeric field

Type Parameters​

K​

K extends string

L​

L extends string

Parameters​

primaryKeyOrUid​

string | PrimaryKeyType<InstanceType<T>>

Primary key of object to update

info​

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

Field to increment with optional value (default: 1)

conditionField?​

K

Field to check for condition

condition?​

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

Expected value for condition field

Returns​

Promise<void>

Inherited from​

AtomicOperations.incrementAttribute


incrementAttributes()​

incrementAttributes<K, L>(primaryKeyOrUid, info, conditionField?, condition?): Promise<void | Record<string, number>>

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

Atomically increment numeric field(s)

Type Parameters​

K​

K extends string

L​

L extends string

Parameters​

primaryKeyOrUid​

string | PrimaryKeyType<InstanceType<T>>

Primary key of object to update

info​

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

Fields to increment with optional values (default: 1)

conditionField?​

K

Field to check for condition

condition?​

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

Expected value for condition field

Returns​

Promise<void | Record<string, number>>

Inherited from​

AtomicOperations.incrementAttributes


iterate()​

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

Defined in: packages/models/lib/repositories/repository.d.ts:98

Iterate over the store

Parameters​

query​

WebdaQLString<InstanceType<T>>

the WebdaQL query, optionally with ? or :name placeholders

params?​

QueryParameters

values for the placeholders: an array for ?, an object for :name

Returns​

AsyncGenerator<InstanceType<T>>

Inherited from​

CoreRepository.iterate


off()​

off<K>(event, listener): void

Defined in: packages/models/lib/repositories/repository.d.ts:104

Type Parameters​

K​

K extends string | number | symbol

Parameters​

event​

K

listener​

(data) => void

Returns​

void

Inherited from​

CoreRepository.off


on()​

on<K>(event, listener): void

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

Event listeners

Type Parameters​

K​

K extends string | number | symbol

Parameters​

event​

K

listener​

(data) => void

Returns​

void

Inherited from​

CoreRepository.on


once()​

once<K>(event, listener): void

Defined in: packages/models/lib/repositories/repository.d.ts:103

Type Parameters​

K​

K extends string | number | symbol

Parameters​

event​

K

listener​

(data) => void

Returns​

void

Inherited from​

CoreRepository.once


parseUID()​

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

Defined in: packages/models/lib/repositories/repository.d.ts:33

Parse the UID into the primary key

Parameters​

uid​

string

forceObject?​

boolean

Returns​

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

Inherited from​

CoreRepository.parseUID


patch()​

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

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

Partially update object (only specified fields)

Type Parameters​

K​

K extends string

Parameters​

uid​

string | PrimaryKeyType<InstanceType<T>>

Primary key of object to update

data​

Partial<Omit<InstanceType<T>, PrimaryKeyAttributes<InstanceType<T>>>>

Partial object data (only fields to update)

conditionField?​

K

Field to check for optimistic locking (null = no check)

condition?​

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

Expected value for condition field

Returns​

Promise<void>

Inherited from​

Updatable.patch


query()​

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

Defined in: packages/models/lib/repositories/repository.d.ts:88

Query the store

Parameters​

query​

WebdaQLString<InstanceType<T>>

the WebdaQL query, optionally with ? or :name placeholders

params?​

QueryParameters

values for the placeholders: an array for ?, an object for :name

Returns​

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

Inherited from​

CoreRepository.query


ref()​

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

Defined in: packages/models/lib/repositories/repository.d.ts:54

Refers to the object in the store

Parameters​

pk​

SettablePrimaryKey<InstanceType<T>>

primary key

Returns​

ModelRefWithCreate<InstanceType<T>>

Inherited from​

CoreRepository.ref


removeAttribute()​

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

Defined in: packages/models/lib/repositories/repository.d.ts:183

Atomically remove an attribute

Type Parameters​

L​

L extends string

K​

K extends string

Parameters​

primaryKeyOrUid​

string | PrimaryKeyType<InstanceType<T>>

Primary key of object to update

attribute​

K

Attribute name to remove

conditionField?​

L

Field to check for condition

condition?​

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

Expected value for condition field

Returns​

Promise<void>

Inherited from​

AtomicOperations.removeAttribute


setAttribute()​

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

Defined in: packages/models/lib/repositories/repository.d.ts:175

Atomically set a single attribute value

Type Parameters​

K​

K extends string

L​

L extends string

Parameters​

primaryKeyOrUid​

string | PrimaryKeyType<InstanceType<T>>

Primary key of object to update

attribute​

K

Attribute name to set

value​

_PropertyPathType<InstanceType<T>, K>

New value for attribute

conditionField?​

L

Field to check for condition

condition?​

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

Expected value for condition field

Returns​

Promise<void>

Inherited from​

AtomicOperations.setAttribute


update()​

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

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

Replace entire object (full update)

Type Parameters​

K​

K extends string

Parameters​

data​

Helpers<InstanceType<T>>

Complete object data including primary key

conditionField?​

K

Field to check for optimistic locking (null = no check)

condition?​

_PropertyPathType<InstanceType<T>, K>

Expected value for condition field

Returns​

Promise<void>

Inherited from​

Updatable.update


upsert()​

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

Defined in: packages/models/lib/repositories/repository.d.ts:134

Create or update object (insert if not exists, update if exists)

Parameters​

data​

Helpers<InstanceType<T>>

Returns​

Promise<InstanceType<T>>

Inherited from​

Updatable.upsert


upsertItemToCollection()​

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

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

Add or update item in a collection (array field)

Type Parameters​

K​

K extends string

L​

L extends string | number | symbol

Parameters​

primaryKeyOrUid​

string | PrimaryKeyType<InstanceType<T>>

Primary key of object containing the collection

collection​

K

Name of the array field

item​

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

Item to add/update

index?​

number

Position to insert (undefined = append to end)

itemWriteConditionField?​

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

Field to check for condition on item

itemWriteCondition?​

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

Expected value for condition field on item

Returns​

Promise<void>

Inherited from​

CollectionOperations.upsertItemToCollection