| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- /* eslint no-unused-vars: 0 */
- import {Service} from '../service/index.js';
- import {NotImplementedError} from '../errors/index.js';
- import {InclusionDecorator} from './decorator/index.js';
- import {DefaultValuesDecorator} from './decorator/index.js';
- import {DataValidationDecorator} from './decorator/index.js';
- import {DataSanitizingDecorator} from './decorator/index.js';
- import {FieldsFilteringDecorator} from './decorator/index.js';
- /**
- * Adapter.
- */
- export class Adapter extends Service {
- /**
- * Settings.
- */
- _settings;
- /**
- * Settings.
- *
- * @return {*}
- */
- get settings() {
- return this._settings;
- }
- /**
- * Constructor.
- *
- * @param services
- * @param settings
- */
- constructor(services = undefined, settings = undefined) {
- super(services);
- this._settings = settings;
- // decorate only extended classes
- if (this.constructor !== Adapter) {
- this.get(DataValidationDecorator).decorate(this);
- this.get(DataSanitizingDecorator).decorate(this);
- this.get(DefaultValuesDecorator).decorate(this);
- this.get(FieldsFilteringDecorator).decorate(this);
- this.get(InclusionDecorator).decorate(this);
- }
- }
- /**
- * Create.
- *
- * @param {string} modelName
- * @param {Record<string, unknown>} modelData
- * @param {Record<string, unknown>|undefined} filter
- * @return {Promise<object>}
- */
- create(modelName, modelData, filter = undefined) {
- throw new NotImplementedError(
- '%s.create is not implemented.',
- new String(this.constructor.name),
- );
- }
- /**
- * Replace by id.
- *
- * @param {string} modelName
- * @param {string|number} id
- * @param {Record<string, unknown>} modelData
- * @param {Record<string, unknown>|undefined} filter
- * @return {Promise<object>}
- */
- replaceById(modelName, id, modelData, filter = undefined) {
- throw new NotImplementedError(
- '%s.replaceById is not implemented.',
- new String(this.constructor.name),
- );
- }
- /**
- * Patch by id.
- *
- * @param {string} modelName
- * @param {string|number} id
- * @param {Record<string, unknown>} modelData
- * @param {Record<string, unknown>|undefined} filter
- * @return {Promise<object>}
- */
- patchById(modelName, id, modelData, filter = undefined) {
- throw new NotImplementedError(
- '%s.patchById is not implemented.',
- new String(this.constructor.name),
- );
- }
- /**
- * Find.
- *
- * @param {string} modelName
- * @param {Record<string, unknown>|undefined} filter
- * @return {Promise<object[]>}
- */
- find(modelName, filter = undefined) {
- throw new NotImplementedError(
- '%s.find is not implemented.',
- new String(this.constructor.name),
- );
- }
- /**
- * Find by id.
- *
- * @param {string} modelName
- * @param {string|number} id
- * @param {Record<string, unknown>|undefined} filter
- * @return {Promise<object>}
- */
- findById(modelName, id, filter = undefined) {
- throw new NotImplementedError(
- '%s.findById is not implemented.',
- new String(this.constructor.name),
- );
- }
- /**
- * Delete.
- *
- * @param {string} modelName
- * @param {Record<string, unknown>|undefined} where
- * @return {Promise<number>}
- */
- delete(modelName, where = undefined) {
- throw new NotImplementedError(
- '%s.delete is not implemented.',
- new String(this.constructor.name),
- );
- }
- /**
- * Delete by id.
- *
- * @param {string} modelName
- * @param {string|number} id
- * @return {Promise<boolean>}
- */
- deleteById(modelName, id) {
- throw new NotImplementedError(
- '%s.deleteById is not implemented.',
- new String(this.constructor.name),
- );
- }
- /**
- * Exists.
- *
- * @param {string} modelName
- * @param {string|number} id
- * @return {Promise<boolean>}
- */
- exists(modelName, id) {
- throw new NotImplementedError(
- '%s.exists is not implemented.',
- new String(this.constructor.name),
- );
- }
- /**
- * Count.
- *
- * @param {string} modelName
- * @param {Record<string, unknown>|undefined} where
- * @return {Promise<number>}
- */
- count(modelName, where = undefined) {
- throw new NotImplementedError(
- '%s.count is not implemented.',
- new String(this.constructor.name),
- );
- }
- }
|