monguito
Version:
MongoDB Abstract Repository implementation for Node.js
59 lines (58 loc) • 3.1 kB
TypeScript
import { Connection, HydratedDocument, Model, UpdateQuery } from 'mongoose';
import { Optional } from 'typescript-optional';
import { PartialEntityWithId, Repository } from './repository';
import { DomainModel } from './util/domain-model';
import { Entity } from './util/entity';
import { DeleteByIdOptions, FindAllOptions, FindByIdOptions, FindOneOptions, SaveOptions } from './util/operation-options';
/**
* Abstract Mongoose-based implementation of the {@link Repository} interface.
*/
export declare abstract class MongooseRepository<T extends Entity & UpdateQuery<T>> implements Repository<T> {
protected readonly connection?: Connection | undefined;
private readonly domainTree;
protected readonly entityModel: Model<T>;
/**
* Sets up the underlying configuration to enable database operation execution.
* @param {DomainModel<T>} domainModel the domain model supported by this repository.
* @param {Connection} connection (optional) a MongoDB instance connection.
*/
protected constructor(domainModel: DomainModel<T>, connection?: Connection | undefined);
private createEntityModel;
/** @inheritdoc */
findById<S extends T>(id: string, options?: FindByIdOptions): Promise<Optional<S>>;
/** @inheritdoc */
findOne<S extends T>(options?: FindOneOptions<S>): Promise<Optional<S>>;
/** @inheritdoc */
findAll<S extends T>(options?: FindAllOptions<S>): Promise<S[]>;
/** @inheritdoc */
save<S extends T>(entity: S | PartialEntityWithId<S>, options?: SaveOptions): Promise<S>;
/**
* Inserts an entity.
* @param {S} entity the entity to insert.
* @param {SaveOptions} options (optional) insert operation options.
* @returns {Promise<S>} the inserted entity.
* @throws {IllegalArgumentException} if the given entity is `undefined` or `null`.
*/
protected insert<S extends T>(entity: S, options?: SaveOptions): Promise<S>;
private createDocumentForInsertion;
private setDiscriminatorKeyOnEntity;
private setAuditableDataOnDocumentToInsert;
/**
* Updates an entity.
* @param {S} entity the entity to update.
* @param {SaveOptions} options (optional) update operation options.
* @returns {Promise<S>} the updated entity.
* @throws {IllegalArgumentException} if the given entity is `undefined` or `null` or specifies an `id` not matching any existing entity.
*/
protected update<S extends T>(entity: PartialEntityWithId<S>, options?: SaveOptions): Promise<S>;
private setAuditableDataOnDocumentToUpdate;
/** @inheritdoc */
deleteById(id: string, options?: DeleteByIdOptions): Promise<boolean>;
/**
* Instantiates a persistable domain object from the given Mongoose Document.
* @param {HydratedDocument<S> | null} document the given Mongoose Document.
* @returns {S | null} the resulting persistable domain object instance.
* @throws {UndefinedConstructorException} if there is no constructor available.
*/
protected instantiateFrom<S extends T>(document: HydratedDocument<S> | null): S | null;
}