Class

BaseRepository

BaseRepository(clazz)

Constructor

# new BaseRepository(clazz)

The BaseRepository class serves as a foundation for repository implementations, providing abstract and concrete methods for creating, reading, updating, and deleting model instances. It handles operation lifecycles including prefix and suffix operations, and enforces decorators.

Base repository implementation providing CRUD operations for models.

sequenceDiagram participant C as Client participant R as Repository participant P as Prefix Methods participant D as Database participant S as Suffix Methods participant V as Validators/Decorators Note over C,V: Create Operation C->>R: create(model) R->>P: createPrefix(model) P->>V: enforceDBDecorators(ON) P->>D: Database operation D->>S: createSuffix(model) S->>V: enforceDBDecorators(AFTER) S->>C: Return model Note over C,V: Read Operation C->>R: read(key) R->>P: readPrefix(key) P->>V: enforceDBDecorators(ON) P->>D: Database operation D->>S: readSuffix(model) S->>V: enforceDBDecorators(AFTER) S->>C: Return model Note over C,V: Update Operation C->>R: update(model) R->>P: updatePrefix(model) P->>V: enforceDBDecorators(ON) P->>D: Database operation D->>S: updateSuffix(model) S->>V: enforceDBDecorators(AFTER) S->>C: Return model Note over C,V: Delete Operation C->>R: delete(key) R->>P: deletePrefix(key) P->>V: enforceDBDecorators(ON) P->>D: Database operation D->>S: deleteSuffix(model) S->>V: enforceDBDecorators(AFTER) S->>C: Return model
Parameters:
Name Type Description
clazz Constructor.<M>

The constructor for the model class

View Source repository/BaseRepository.ts, line 8

Example
class UserModel extends Model {
  

Members

# class

Retrieves the constructor for the model class associated with this repository. Throws an error if no class definition is found.

Gets the model class constructor.

View Source repository/BaseRepository.ts, line 109

# pk

Retrieves the name of the property that serves as the primary key for the model. If not already determined, it finds the primary key using the model's decorators.

Gets the primary key property name of the model.

View Source repository/BaseRepository.ts, line 120

# pkProps

Retrieves the properties associated with the primary key of the model. If not already determined, it triggers the pk getter to find the primary key properties.

Gets the primary key properties.

View Source repository/BaseRepository.ts, line 134

Methods

# class() → {Constructor.<M>}

Retrieves the constructor for the model class associated with this repository. Throws an error if no class definition is found.

Gets the model class constructor.

View Source repository/BaseRepository.ts, line 469

The constructor for the model class

Constructor.<M>

# abstract create(model, args) → {Promise.<M>}

Persists a new model instance to the underlying data store. This method must be implemented by concrete repository classes.

Creates a new model instance in the repository.

Parameters:
Name Type Description
model M

The model instance to create

args Array.<any>

Additional arguments for the create operation

View Source repository/BaseRepository.ts, line 497

A promise that resolves to the created model instance

Promise.<M>

# async createAll(models, args) → {Promise.<Array.<M>>}

Persists multiple model instances to the underlying data store by calling the create method for each model in the array.

Creates multiple model instances in the repository.

Parameters:
Name Type Description
models Array.<M>

The array of model instances to create

args Array.<any>

Additional arguments for the create operation

View Source repository/BaseRepository.ts, line 508

A promise that resolves to an array of created model instances

Promise.<Array.<M>>

# async protected createAllPrefix(models, args)

Processes multiple models before they are created in the data store. This includes creating a context, instantiating new model instances, and enforcing any decorators that should be applied before creation for each model.

Prepares multiple models for creation and executes pre-creation operations.

Parameters:
Name Type Description
models Array.<M>

The array of model instances to prepare for creation

args Array.<any>

Additional arguments for the create operation

View Source repository/BaseRepository.ts, line 546

A promise that resolves to an array containing the prepared models and context arguments

# async protected createAllSuffix(models, context) → {Promise.<Array.<M>>}

Finalizes multiple models after they have been created in the data store. This includes enforcing any decorators that should be applied after creation for each model.

Processes multiple models after creation and executes post-creation operations.

Parameters:
Name Type Description
models Array.<M>

The array of model instances that were created

context C

The context for the operation

View Source repository/BaseRepository.ts, line 558

A promise that resolves to the array of processed model instances

Promise.<Array.<M>>

# async protected createPrefix(model, args)

Processes a model before it is created in the data store. This includes creating a context, instantiating a new model instance, and enforcing any decorators that should be applied before creation.

Prepares a model for creation and executes pre-creation operations.

Parameters:
Name Type Description
model M

The model instance to prepare for creation

args Array.<any>

Additional arguments for the create operation

View Source repository/BaseRepository.ts, line 521

A promise that resolves to an array containing the prepared model and context arguments

# async protected createSuffix(model, context) → {Promise.<M>}

Finalizes a model after it has been created in the data store. This includes enforcing any decorators that should be applied after creation.

Processes a model after creation and executes post-creation operations.

Parameters:
Name Type Description
model M

The model instance that was created

context C

The context for the operation

View Source repository/BaseRepository.ts, line 533

A promise that resolves to the processed model instance

Promise.<M>

# abstract delete(key, args) → {Promise.<M>}

Removes a model instance from the underlying data store using its primary key. This method must be implemented by concrete repository classes.

Deletes a model instance from the repository by its primary key.

Parameters:
Name Type Description
key string | number

The primary key of the model to delete

args Array.<any>

Additional arguments for the delete operation

View Source repository/BaseRepository.ts, line 713

A promise that resolves to the deleted model instance

Promise.<M>

# async deleteAll(keys, args) → {Promise.<Array.<M>>}

Removes multiple model instances from the underlying data store using their primary keys by calling the delete method for each key in the array.

Deletes multiple model instances from the repository by their primary keys.

Parameters:
Name Type Description
keys Array.<string> | Array.<number>

The array of primary keys of the models to delete

args Array.<any>

Additional arguments for the delete operation

View Source repository/BaseRepository.ts, line 724

A promise that resolves to an array of deleted model instances

Promise.<Array.<M>>

# async protected deleteAllPrefix(keys, args)

Processes multiple keys before models are deleted from the data store. This includes creating a context, retrieving the models to be deleted, and enforcing any decorators that should be applied before deletion for each model.

Prepares for deleting multiple models and executes pre-delete operations.

Parameters:
Name Type Description
keys Array.<string> | Array.<number>

The array of primary keys of the models to delete

args Array.<any>

Additional arguments for the delete operation

View Source repository/BaseRepository.ts, line 762

A promise that resolves to an array containing the keys and context arguments

# async protected deleteAllSuffix(models, context) → {Promise.<Array.<M>>}

Finalizes multiple models after they have been deleted from the data store. This includes enforcing any decorators that should be applied after deletion for each model.

Processes multiple models after deletion and executes post-delete operations.

Parameters:
Name Type Description
models Array.<M>

The array of model instances that were deleted

context C

The context for the operation

View Source repository/BaseRepository.ts, line 774

A promise that resolves to the array of processed model instances

Promise.<Array.<M>>

# async protected deletePrefix(key, args)

Processes a key before a model is deleted from the data store. This includes creating a context, retrieving the model to be deleted, and enforcing any decorators that should be applied before deletion.

Prepares for deleting a model and executes pre-delete operations.

Parameters:
Name Type Description
key any

The primary key of the model to delete

args Array.<any>

Additional arguments for the delete operation

View Source repository/BaseRepository.ts, line 749

A promise that resolves to an array containing the key and context arguments

# async protected deleteSuffix(model, context) → {Promise.<M>}

Finalizes a model after it has been deleted from the data store. This includes enforcing any decorators that should be applied after deletion.

Processes a model after deletion and executes post-delete operations.

Parameters:
Name Type Description
model M

The model instance that was deleted

context C

The context for the operation

View Source repository/BaseRepository.ts, line 736

A promise that resolves to the processed model instance

Promise.<M>

# protected merge(oldModel, model) → {M}

Creates a new model instance by combining properties from an old model and a new model. Properties from the new model override properties from the old model if they are defined.

Merges two model instances into a new instance.

Parameters:
Name Type Description
oldModel M

The original model instance

model M

The new model instance with updated properties

View Source repository/BaseRepository.ts, line 785

A new model instance with merged properties

M

# pk()

Retrieves the name of the property that serves as the primary key for the model. If not already determined, it finds the primary key using the model's decorators.

Gets the primary key property name of the model.

View Source repository/BaseRepository.ts, line 477

The name of the primary key property

# protected pkProps() → {any}

Retrieves the properties associated with the primary key of the model. If not already determined, it triggers the pk getter to find the primary key properties.

Gets the primary key properties.

View Source repository/BaseRepository.ts, line 486

The properties of the primary key

any

# abstract read(key, args) → {Promise.<M>}

Fetches a model instance from the underlying data store using its primary key. This method must be implemented by concrete repository classes.

Retrieves a model instance from the repository by its primary key.

Parameters:
Name Type Description
key string | number

The primary key of the model to retrieve

args Array.<any>

Additional arguments for the read operation

View Source repository/BaseRepository.ts, line 569

A promise that resolves to the retrieved model instance

Promise.<M>

# async readAll(keys, args) → {Promise.<Array.<M>>}

Fetches multiple model instances from the underlying data store using their primary keys by calling the read method for each key in the array.

Retrieves multiple model instances from the repository by their primary keys.

Parameters:
Name Type Description
keys Array.<string> | Array.<number>

The array of primary keys of the models to retrieve

args Array.<any>

Additional arguments for the read operation

View Source repository/BaseRepository.ts, line 580

A promise that resolves to an array of retrieved model instances

Promise.<Array.<M>>

# async protected readAllPrefix(keys, args)

Processes multiple keys before models are read from the data store. This includes creating a context, instantiating new model instances with the keys, and enforcing any decorators that should be applied before reading for each key.

Prepares for reading multiple models and executes pre-read operations.

Parameters:
Name Type Description
keys Array.<string> | Array.<number>

The array of primary keys of the models to read

args Array.<any>

Additional arguments for the read operation

View Source repository/BaseRepository.ts, line 618

A promise that resolves to an array containing the keys and context arguments

# async protected readAllSuffix(models, context) → {Promise.<Array.<M>>}

Finalizes multiple models after they have been retrieved from the data store. This includes enforcing any decorators that should be applied after reading for each model.

Processes multiple models after retrieval and executes post-read operations.

Parameters:
Name Type Description
models Array.<M>

The array of model instances that were retrieved

context C

The context for the operation

View Source repository/BaseRepository.ts, line 630

A promise that resolves to the array of processed model instances

Promise.<Array.<M>>

# async protected readPrefix(key, args)

Processes a key before a model is read from the data store. This includes creating a context, instantiating a new model instance with the key, and enforcing any decorators that should be applied before reading.

Prepares for reading a model and executes pre-read operations.

Parameters:
Name Type Description
key string

The primary key of the model to read

args Array.<any>

Additional arguments for the read operation

View Source repository/BaseRepository.ts, line 605

A promise that resolves to an array containing the key and context arguments

# async protected readSuffix(model, context) → {Promise.<M>}

Finalizes a model after it has been retrieved from the data store. This includes enforcing any decorators that should be applied after reading.

Processes a model after retrieval and executes post-read operations.

Parameters:
Name Type Description
model M

The model instance that was retrieved

context C

The context for the operation

View Source repository/BaseRepository.ts, line 592

A promise that resolves to the processed model instance

Promise.<M>

# toString() → {string}

Creates a string that identifies this repository by the name of its model class.

Returns a string representation of the repository.

View Source repository/BaseRepository.ts, line 792

A string representation of the repository

string

# abstract update(model, args) → {Promise.<M>}

Updates an existing model instance in the underlying data store. This method must be implemented by concrete repository classes.

Updates an existing model instance in the repository.

Parameters:
Name Type Description
model M

The model instance to update

args Array.<any>

Additional arguments for the update operation

View Source repository/BaseRepository.ts, line 641

A promise that resolves to the updated model instance

Promise.<M>

# async updateAll(models, args) → {Promise.<Array.<M>>}

Updates multiple model instances in the underlying data store by calling the update method for each model in the array.

Updates multiple model instances in the repository.

Parameters:
Name Type Description
models Array.<M>

The array of model instances to update

args Array.<any>

Additional arguments for the update operation

View Source repository/BaseRepository.ts, line 652

A promise that resolves to an array of updated model instances

Promise.<Array.<M>>

# async protected updateAllPrefix(models, args)

Processes multiple models before they are updated in the data store. This includes creating a context, instantiating new model instances, and enforcing any decorators that should be applied before updating for each model.

Prepares multiple models for update and executes pre-update operations.

Parameters:
Name Type Description
models Array.<M>

The array of model instances to prepare for update

args Array.<any>

Additional arguments for the update operation

View Source repository/BaseRepository.ts, line 690

A promise that resolves to an array containing the prepared models and context arguments

# async protected updateAllSuffix(models, context) → {Promise.<Array.<M>>}

Finalizes multiple models after they have been updated in the data store. This includes enforcing any decorators that should be applied after updating for each model.

Processes multiple models after update and executes post-update operations.

Parameters:
Name Type Description
models Array.<M>

The array of model instances that were updated

context C

The context for the operation

View Source repository/BaseRepository.ts, line 702

A promise that resolves to the array of processed model instances

Promise.<Array.<M>>

# async protected updatePrefix(model, args)

Processes a model before it is updated in the data store. This includes creating a context, validating the primary key, retrieving the existing model, and enforcing any decorators that should be applied before updating.

Prepares a model for update and executes pre-update operations.

Parameters:
Name Type Description
model M

The model instance to prepare for update

args Array.<any>

Additional arguments for the update operation

View Source repository/BaseRepository.ts, line 677

A promise that resolves to an array containing the prepared model and context arguments

# async protected updateSuffix(model, context) → {Promise.<M>}

Finalizes a model after it has been updated in the data store. This includes enforcing any decorators that should be applied after updating.

Processes a model after update and executes post-update operations.

Parameters:
Name Type Description
model M

The model instance that was updated

context C

The context for the operation

View Source repository/BaseRepository.ts, line 664

A promise that resolves to the processed model instance

Promise.<M>