UNPKG

@webda/core

Version:

Expose API with Lambda

168 lines 5.75 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; import { Inject } from "../services/service.js"; import { Store, StoreParameters } from "./store.js"; import { WebdaQL } from "./webdaql/query.js"; export class AbstractAliasStoreParameters extends StoreParameters { constructor(params, store) { super(params, store); this.strict = true; } } /** * AliasStore allow to expose a Store as another route with another model * This is useful to store small collection in the registry * * The RegistryStore will default to a model, then specific models from the * target collection can be exposed via an endpoint like users * */ export class AbstractAliasStore extends Store { /** * @override */ find(query) { let expr = new WebdaQL.AndExpression([new WebdaQL.ComparisonExpression("=", "__type", this._modelType)]); // Will need to check for uuid query if (query.filter) { expr.children.push(query.filter); } query.filter = expr; return this._targetStore.find(query); } /** * @override */ _exists(uid) { return this._targetStore._exists(this.generateUuidFromPublicId(uid)); } /** * @override */ async getAll(list) { if (list) { return this._targetStore.getAll(list.map(id => this.generateUuidFromPublicId(id))); } else { let res = []; for await (const item of this._targetStore.iterate(`__type = '${this._modelType}'`)) { res.push(item); } // Get all from find return res; } } /** * @override */ _removeAttribute(uuid, attribute, itemWriteCondition, itemWriteConditionField) { // @ts-ignore return this._targetStore._removeAttribute(this.generateUuidFromPublicId(uuid), attribute, itemWriteCondition, itemWriteConditionField); } /** * @override */ _save(object) { // @ts-ignore return this._targetStore._save(object); } /** * @override */ _upsertItemToCollection(uid, prop, item, index, itemWriteCondition, itemWriteConditionField, updateDate) { // @ts-ignore return this._targetStore._upsertItemToCollection(this.generateUuidFromPublicId(uid), prop, item, index, itemWriteCondition, itemWriteConditionField, updateDate); } /** * @override */ async _get(uid, raiseIfNotFound) { // @ts-ignore return this._targetStore._get(this.generateUuidFromPublicId(uid), raiseIfNotFound); } /** * @override */ async _delete(uid, writeCondition, itemWriteConditionField) { // @ts-ignore return this._targetStore._delete(this.generateUuidFromPublicId(uid), writeCondition, itemWriteConditionField); } /** * @override */ async _deleteItemFromCollection(uid, prop, index, itemWriteCondition, itemWriteConditionField, updateDate) { // @ts-ignore return this._targetStore._deleteItemFromCollection(this.generateUuidFromPublicId(uid), prop, index, itemWriteCondition, itemWriteConditionField, updateDate); } /** * @override */ async _incrementAttributes(uid, ...args) { // @ts-ignore return this._targetStore._incrementAttributes(this.generateUuidFromPublicId(uid), // @ts-ignore ...args); } /** * @override */ async _patch(object, uid, itemWriteCondition, itemWriteConditionField) { // @ts-ignore return this._targetStore._patch(object, this.generateUuidFromPublicId(uid), itemWriteCondition, itemWriteConditionField); } /** * @override */ async _update(object, uid, itemWriteCondition, itemWriteConditionField) { // @ts-ignore return this._targetStore._update(object, this.generateUuidFromPublicId(uid), itemWriteCondition, itemWriteConditionField); } /** * @override */ httpGet(ctx) { ctx.getParameters().id = this.generateUuidFromPublicId(ctx.getParameters().id); return super.httpGet(ctx); } /** * @override */ httpAction(ctx) { ctx.getParameters().id = this.generateUuidFromPublicId(ctx.getParameters().id); return super.httpAction(ctx); } } __decorate([ Inject("params:targetStore") ], AbstractAliasStore.prototype, "_targetStore", void 0); export class AliasStoreParameters extends AbstractAliasStoreParameters { } /** * AliasStore allow to expose a Store as another route with another model * This is useful to store small collection in the registry * * The RegistryStore will default to a model, then specific models from the * target collection can be exposed via an endpoint like users * * @WebdaModda */ export class AliasStore extends AbstractAliasStore { /** * @override */ loadParameters(params) { return new AliasStoreParameters(params, this); } /** * Use the idTemplate parameter to generate uuid * @override */ generateUuidFromPublicId(id) { return this.parameters.idTemplate.replace(/\{id\}/g, id); } } //# sourceMappingURL=aliasstore.js.map