@twin.org/entity-storage-service 0.0.3-next.13 → 0.0.3-next.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/entityStorageRoutes.js +4 -4
- package/dist/es/entityStorageRoutes.js.map +1 -1
- package/dist/es/entityStorageService.js +12 -8
- package/dist/es/entityStorageService.js.map +1 -1
- package/dist/types/entityStorageService.d.ts +17 -4
- package/docs/changelog.md +16 -0
- package/docs/open-api/spec.json +40 -15
- package/docs/reference/classes/EntityStorageService.md +30 -4
- package/package.json +2 -2
|
@@ -284,7 +284,7 @@ export function generateRestRoutesEntityStorage(baseRouteName, componentName, op
|
|
|
284
284
|
export async function entityStorageSet(httpRequestContext, componentName, request) {
|
|
285
285
|
Guards.object(ROUTES_SOURCE, "request", request);
|
|
286
286
|
const component = ComponentFactory.get(componentName);
|
|
287
|
-
await component.set(request.body);
|
|
287
|
+
await component.set(request.body, HttpParameterHelper.objectFromString(request.query?.conditions));
|
|
288
288
|
return {
|
|
289
289
|
statusCode: HttpStatusCode.noContent
|
|
290
290
|
};
|
|
@@ -329,7 +329,7 @@ export async function entityStorageGet(httpRequestContext, componentName, reques
|
|
|
329
329
|
Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
|
|
330
330
|
Guards.stringValue(ROUTES_SOURCE, "request.pathParams.id", request.pathParams.id);
|
|
331
331
|
const component = ComponentFactory.get(componentName);
|
|
332
|
-
const item = await component.get(request.pathParams.id, request.query?.secondaryIndex);
|
|
332
|
+
const item = await component.get(request.pathParams.id, request.query?.secondaryIndex, HttpParameterHelper.objectFromString(request.query?.conditions));
|
|
333
333
|
return {
|
|
334
334
|
body: item
|
|
335
335
|
};
|
|
@@ -346,7 +346,7 @@ export async function entityStorageRemove(httpRequestContext, componentName, req
|
|
|
346
346
|
Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
|
|
347
347
|
Guards.stringValue(ROUTES_SOURCE, "request.pathParams.id", request.pathParams.id);
|
|
348
348
|
const component = ComponentFactory.get(componentName);
|
|
349
|
-
await component.remove(request.pathParams.id);
|
|
349
|
+
await component.remove(request.pathParams.id, HttpParameterHelper.objectFromString(request.query?.conditions));
|
|
350
350
|
return {
|
|
351
351
|
statusCode: HttpStatusCode.noContent
|
|
352
352
|
};
|
|
@@ -375,7 +375,7 @@ export async function entityStorageList(httpRequestContext, componentName, reque
|
|
|
375
375
|
*/
|
|
376
376
|
export async function entityStorageCount(httpRequestContext, componentName, request) {
|
|
377
377
|
const component = ComponentFactory.get(componentName);
|
|
378
|
-
const count = await component.count();
|
|
378
|
+
const count = await component.count(HttpParameterHelper.objectFromString(request.query?.conditions));
|
|
379
379
|
return {
|
|
380
380
|
body: { count }
|
|
381
381
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entityStorageRoutes.js","sourceRoot":"","sources":["../../src/entityStorageRoutes.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EACN,mBAAmB,EAMnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAgBhF,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAG/C;;GAEG;AACH,MAAM,aAAa,GAAG,qBAAqB,CAAC;AAE5C;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAW;IACxC;QACC,IAAI,EAAE,eAAe;QACrB,WAAW,EAAE,oEAAoE;KACjF;CACD,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,UAAU,+BAA+B,CAC9C,aAAqB,EACrB,aAAqB,EACrB,OAIC;IAED,MAAM,QAAQ,GAAG,OAAO,EAAE,QAAQ,IAAI,gBAAgB,CAAC;IACvD,MAAM,SAAS,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;IACzC,MAAM,aAAa,GAAG,YAAY,CAAC,SAAS,CA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IHttpRequestContext,\n\ttype INoContentResponse,\n\ttype IRestRoute,\n\ttype ITag\n} from \"@twin.org/api-models\";\nimport { Coerce, ComponentFactory, Guards, StringHelper } from \"@twin.org/core\";\nimport type {\n\tIEntityStorageComponent,\n\tIEntityStorageCountRequest,\n\tIEntityStorageCountResponse,\n\tIEntityStorageEmptyRequest,\n\tIEntityStorageGetRequest,\n\tIEntityStorageGetResponse,\n\tIEntityStorageListRequest,\n\tIEntityStorageListResponse,\n\tIEntityStorageRemoveBatchRequest,\n\tIEntityStorageRemoveRequest,\n\tIEntityStorageSetBatchRequest,\n\tIEntityStorageSetRequest\n} from \"@twin.org/entity-storage-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { HttpStatusCode } from \"@twin.org/web\";\nimport type { IEntityStorageRoutesExamples } from \"./models/IEntityStorageRoutesExamples.js\";\n\n/**\n * The source used when communicating about these routes.\n */\nconst ROUTES_SOURCE = \"entityStorageRoutes\";\n\n/**\n * The tag to associate with the routes.\n */\nexport const tagsEntityStorage: ITag[] = [\n\t{\n\t\tname: \"EntityStorage\",\n\t\tdescription: \"Endpoints which are modelled to access an entity storage contract.\"\n\t}\n];\n\n/**\n * The REST routes for entity storage.\n * @param baseRouteName Prefix to prepend to the paths.\n * @param componentName The name of the component to use in the routes stored in the ComponentFactory.\n * @param options Additional options for the routes.\n * @param options.typeName Optional type name to use in the routes, defaults to Entity Storage.\n * @param options.tagName Optional name to use in OpenAPI spec for tag.\n * @param options.examples Optional examples to use in the routes.\n * @returns The generated routes.\n */\nexport function generateRestRoutesEntityStorage(\n\tbaseRouteName: string,\n\tcomponentName: string,\n\toptions?: {\n\t\ttypeName?: string;\n\t\ttagName?: string;\n\t\texamples?: IEntityStorageRoutesExamples;\n\t}\n): IRestRoute[] {\n\tconst typeName = options?.typeName ?? \"Entity Storage\";\n\tconst lowerName = typeName.toLowerCase();\n\tconst camelTypeName = StringHelper.camelCase(typeName);\n\n\tconst setRoute: IRestRoute<IEntityStorageSetRequest, INoContentResponse> = {\n\t\toperationId: `${camelTypeName}Set`,\n\t\tsummary: `Set an entry in ${lowerName}.`,\n\t\ttag: options?.tagName ?? tagsEntityStorage[0].name,\n\t\tmethod: \"POST\",\n\t\tpath: `${baseRouteName}/`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tentityStorageSet(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IEntityStorageSetRequest>(),\n\t\t\texamples: options?.examples?.set?.requestExamples ?? [\n\t\t\t\t{\n\t\t\t\t\tid: `${camelTypeName}SetRequestExample`,\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\tid: \"12345\",\n\t\t\t\t\t\t\tname: \"My Item\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\tconst setBatchRoute: IRestRoute<IEntityStorageSetBatchRequest, INoContentResponse> = {\n\t\toperationId: `${camelTypeName}SetBatch`,\n\t\tsummary: `Set multiple entries in ${lowerName}.`,\n\t\ttag: options?.tagName ?? tagsEntityStorage[0].name,\n\t\tmethod: \"POST\",\n\t\tpath: `${baseRouteName}/batch`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tentityStorageSetBatch(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IEntityStorageSetBatchRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: `${camelTypeName}SetBatchRequestExample`,\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tbody: [\n\t\t\t\t\t\t\t{ id: \"12345\", name: \"My Item\" },\n\t\t\t\t\t\t\t{ id: \"67890\", name: \"My Other Item\" }\n\t\t\t\t\t\t]\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\tconst getRoute: IRestRoute<IEntityStorageGetRequest, IEntityStorageGetResponse> = {\n\t\toperationId: `${camelTypeName}Get`,\n\t\tsummary: `Get an entry from ${lowerName}.`,\n\t\ttag: options?.tagName ?? tagsEntityStorage[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/:id`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tentityStorageGet(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IEntityStorageGetRequest>(),\n\t\t\texamples: options?.examples?.get?.requestExamples ?? [\n\t\t\t\t{\n\t\t\t\t\tid: `${camelTypeName}GetRequestExample`,\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"12345\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<IEntityStorageGetResponse>(),\n\t\t\t\texamples: options?.examples?.get?.responseExamples ?? [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: `${camelTypeName}GetResponseExample`,\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\tid: \"12345\",\n\t\t\t\t\t\t\t\tname: \"My Item\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: nameof<INotFoundResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\tconst removeRoute: IRestRoute<IEntityStorageRemoveRequest, INoContentResponse> = {\n\t\toperationId: `${camelTypeName}Remove`,\n\t\tsummary: `Remove an entry from ${lowerName}.`,\n\t\ttag: options?.tagName ?? tagsEntityStorage[0].name,\n\t\tmethod: \"DELETE\",\n\t\tpath: `${baseRouteName}/:id`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tentityStorageRemove(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IEntityStorageRemoveRequest>(),\n\t\t\texamples: options?.examples?.remove?.requestExamples ?? [\n\t\t\t\t{\n\t\t\t\t\tid: `${camelTypeName}RemoveRequestExample`,\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"12345\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: nameof<INotFoundResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\tconst listRoute: IRestRoute<IEntityStorageListRequest, IEntityStorageListResponse> = {\n\t\toperationId: `${camelTypeName}List`,\n\t\tsummary: `Query entries from ${lowerName}.`,\n\t\ttag: options?.tagName ?? tagsEntityStorage[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tentityStorageList(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IEntityStorageListRequest>(),\n\t\t\texamples: options?.examples?.list?.requestExamples ?? [\n\t\t\t\t{\n\t\t\t\t\tid: `${camelTypeName}ListRequestExample`,\n\t\t\t\t\trequest: {}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<IEntityStorageListResponse>(),\n\t\t\t\texamples: options?.examples?.list?.responseExamples ?? [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: `${camelTypeName}ListResponseExample`,\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\tentities: [{ id: \"12345\", name: \"My Item\" }]\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\tconst countRoute: IRestRoute<IEntityStorageCountRequest, IEntityStorageCountResponse> = {\n\t\toperationId: `${camelTypeName}Count`,\n\t\tsummary: `Count entries in ${lowerName}.`,\n\t\ttag: options?.tagName ?? tagsEntityStorage[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/count`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tentityStorageCount(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IEntityStorageCountRequest>(),\n\t\t\texamples: options?.examples?.count?.requestExamples ?? [\n\t\t\t\t{\n\t\t\t\t\tid: `${camelTypeName}CountRequestExample`,\n\t\t\t\t\trequest: {}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<IEntityStorageCountResponse>(),\n\t\t\t\texamples: options?.examples?.count?.responseExamples ?? [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: `${camelTypeName}CountResponseExample`,\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\tcount: 1\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\tconst emptyRoute: IRestRoute<IEntityStorageEmptyRequest, INoContentResponse> = {\n\t\toperationId: `${camelTypeName}Empty`,\n\t\tsummary: `Remove all entries from ${lowerName}.`,\n\t\ttag: options?.tagName ?? tagsEntityStorage[0].name,\n\t\tmethod: \"DELETE\",\n\t\tpath: `${baseRouteName}/`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tentityStorageEmpty(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IEntityStorageEmptyRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: `${camelTypeName}EmptyRequestExample`,\n\t\t\t\t\trequest: {}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\tconst removeBatchRoute: IRestRoute<IEntityStorageRemoveBatchRequest, INoContentResponse> = {\n\t\toperationId: `${camelTypeName}RemoveBatch`,\n\t\tsummary: `Remove multiple entries from ${lowerName} by id.`,\n\t\ttag: options?.tagName ?? tagsEntityStorage[0].name,\n\t\tmethod: \"DELETE\",\n\t\tpath: `${baseRouteName}/batch`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tentityStorageRemoveBatch(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IEntityStorageRemoveBatchRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: `${camelTypeName}RemoveBatchRequestExample`,\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tbody: [\"12345\", \"67890\"]\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\treturn [\n\t\tsetRoute,\n\t\tsetBatchRoute,\n\t\tgetRoute,\n\t\tremoveRoute,\n\t\tremoveBatchRoute,\n\t\temptyRoute,\n\t\tlistRoute,\n\t\tcountRoute\n\t];\n}\n\n/**\n * Set the entry in entity storage.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function entityStorageSet(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IEntityStorageSetRequest\n): Promise<INoContentResponse> {\n\tGuards.object<IEntityStorageSetRequest>(ROUTES_SOURCE, nameof(request), request);\n\n\tconst component = ComponentFactory.get<IEntityStorageComponent>(componentName);\n\tawait component.set(request.body);\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n\n/**\n * Set multiple entries in entity storage.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function entityStorageSetBatch(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IEntityStorageSetBatchRequest\n): Promise<INoContentResponse> {\n\tGuards.object<IEntityStorageSetBatchRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.arrayValue(ROUTES_SOURCE, nameof(request.body), request.body);\n\n\tconst component = ComponentFactory.get<IEntityStorageComponent>(componentName);\n\tawait component.setBatch(request.body);\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n\n/**\n * Remove all entries from entity storage.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function entityStorageEmpty(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IEntityStorageEmptyRequest\n): Promise<INoContentResponse> {\n\tconst component = ComponentFactory.get<IEntityStorageComponent>(componentName);\n\tawait component.empty();\n\treturn { statusCode: HttpStatusCode.noContent };\n}\n\n/**\n * Get the entry from entity storage.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function entityStorageGet(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IEntityStorageGetRequest\n): Promise<IEntityStorageGetResponse> {\n\tGuards.object<IEntityStorageGetRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IEntityStorageGetRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\n\tconst component = ComponentFactory.get<IEntityStorageComponent>(componentName);\n\tconst item = await component.get(\n\t\trequest.pathParams.id,\n\t\trequest.query?.secondaryIndex as keyof unknown\n\t);\n\treturn {\n\t\tbody: item\n\t};\n}\n\n/**\n * Remove the entry from entity storage.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function entityStorageRemove(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IEntityStorageRemoveRequest\n): Promise<INoContentResponse> {\n\tGuards.object<IEntityStorageRemoveRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IEntityStorageRemoveRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\n\tconst component = ComponentFactory.get<IEntityStorageComponent>(componentName);\n\tawait component.remove(request.pathParams.id);\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n\n/**\n * Query the entries from entity storage.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function entityStorageList(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IEntityStorageListRequest\n): Promise<IEntityStorageListResponse> {\n\tGuards.object<IEntityStorageListRequest>(ROUTES_SOURCE, nameof(request), request);\n\n\tconst component = ComponentFactory.get<IEntityStorageComponent>(componentName);\n\tconst result = await component.query(\n\t\tHttpParameterHelper.objectFromString(request.query?.conditions),\n\t\trequest.query?.orderBy as keyof unknown,\n\t\trequest.query?.orderByDirection,\n\t\tHttpParameterHelper.objectFromString(request.query?.properties),\n\t\trequest.query?.cursor,\n\t\tCoerce.number(request.query?.limit)\n\t);\n\treturn {\n\t\tbody: result\n\t};\n}\n\n/**\n * Count the entries in entity storage.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function entityStorageCount(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IEntityStorageCountRequest\n): Promise<IEntityStorageCountResponse> {\n\tconst component = ComponentFactory.get<IEntityStorageComponent>(componentName);\n\tconst count = await component.count();\n\treturn {\n\t\tbody: { count }\n\t};\n}\n\n/**\n * Remove multiple entries from entity storage by id.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function entityStorageRemoveBatch(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IEntityStorageRemoveBatchRequest\n): Promise<INoContentResponse> {\n\tGuards.object<IEntityStorageRemoveBatchRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.arrayValue(ROUTES_SOURCE, nameof(request.body), request.body);\n\n\tconst component = ComponentFactory.get<IEntityStorageComponent>(componentName);\n\tawait component.removeBatch(request.body);\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"entityStorageRoutes.js","sourceRoot":"","sources":["../../src/entityStorageRoutes.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EACN,mBAAmB,EAMnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAgBhF,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAG/C;;GAEG;AACH,MAAM,aAAa,GAAG,qBAAqB,CAAC;AAE5C;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAW;IACxC;QACC,IAAI,EAAE,eAAe;QACrB,WAAW,EAAE,oEAAoE;KACjF;CACD,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,UAAU,+BAA+B,CAC9C,aAAqB,EACrB,aAAqB,EACrB,OAIC;IAED,MAAM,QAAQ,GAAG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C,aAAa,aAAmB,OAAO,CAAC,CAAC;IACzF,MAAM,CAAC,UAAU,CAAC,aAAa,kBAAwB,OAAO,CAAC,IAAI,CAAC,CAAC;IAErE,MAAM,SAAS,GAAG,gBAAgB,CAAC,GAAG,CAA0B,aAAa,CAAC,CAAC;IAC/E,MAAM,SAAS,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1C,OAAO;QACN,UAAU,EAAE,cAAc,CAAC,SAAS;KACpC,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport {\n\tHttpParameterHelper,\n\ttype INotFoundResponse,\n\ttype IHttpRequestContext,\n\ttype INoContentResponse,\n\ttype IRestRoute,\n\ttype ITag\n} from \"@twin.org/api-models\";\nimport { Coerce, ComponentFactory, Guards, StringHelper } from \"@twin.org/core\";\nimport type {\n\tIEntityStorageComponent,\n\tIEntityStorageCountRequest,\n\tIEntityStorageCountResponse,\n\tIEntityStorageEmptyRequest,\n\tIEntityStorageGetRequest,\n\tIEntityStorageGetResponse,\n\tIEntityStorageListRequest,\n\tIEntityStorageListResponse,\n\tIEntityStorageRemoveBatchRequest,\n\tIEntityStorageRemoveRequest,\n\tIEntityStorageSetBatchRequest,\n\tIEntityStorageSetRequest\n} from \"@twin.org/entity-storage-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { HttpStatusCode } from \"@twin.org/web\";\nimport type { IEntityStorageRoutesExamples } from \"./models/IEntityStorageRoutesExamples.js\";\n\n/**\n * The source used when communicating about these routes.\n */\nconst ROUTES_SOURCE = \"entityStorageRoutes\";\n\n/**\n * The tag to associate with the routes.\n */\nexport const tagsEntityStorage: ITag[] = [\n\t{\n\t\tname: \"EntityStorage\",\n\t\tdescription: \"Endpoints which are modelled to access an entity storage contract.\"\n\t}\n];\n\n/**\n * The REST routes for entity storage.\n * @param baseRouteName Prefix to prepend to the paths.\n * @param componentName The name of the component to use in the routes stored in the ComponentFactory.\n * @param options Additional options for the routes.\n * @param options.typeName Optional type name to use in the routes, defaults to Entity Storage.\n * @param options.tagName Optional name to use in OpenAPI spec for tag.\n * @param options.examples Optional examples to use in the routes.\n * @returns The generated routes.\n */\nexport function generateRestRoutesEntityStorage(\n\tbaseRouteName: string,\n\tcomponentName: string,\n\toptions?: {\n\t\ttypeName?: string;\n\t\ttagName?: string;\n\t\texamples?: IEntityStorageRoutesExamples;\n\t}\n): IRestRoute[] {\n\tconst typeName = options?.typeName ?? \"Entity Storage\";\n\tconst lowerName = typeName.toLowerCase();\n\tconst camelTypeName = StringHelper.camelCase(typeName);\n\n\tconst setRoute: IRestRoute<IEntityStorageSetRequest, INoContentResponse> = {\n\t\toperationId: `${camelTypeName}Set`,\n\t\tsummary: `Set an entry in ${lowerName}.`,\n\t\ttag: options?.tagName ?? tagsEntityStorage[0].name,\n\t\tmethod: \"POST\",\n\t\tpath: `${baseRouteName}/`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tentityStorageSet(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IEntityStorageSetRequest>(),\n\t\t\texamples: options?.examples?.set?.requestExamples ?? [\n\t\t\t\t{\n\t\t\t\t\tid: `${camelTypeName}SetRequestExample`,\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\tid: \"12345\",\n\t\t\t\t\t\t\tname: \"My Item\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\tconst setBatchRoute: IRestRoute<IEntityStorageSetBatchRequest, INoContentResponse> = {\n\t\toperationId: `${camelTypeName}SetBatch`,\n\t\tsummary: `Set multiple entries in ${lowerName}.`,\n\t\ttag: options?.tagName ?? tagsEntityStorage[0].name,\n\t\tmethod: \"POST\",\n\t\tpath: `${baseRouteName}/batch`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tentityStorageSetBatch(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IEntityStorageSetBatchRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: `${camelTypeName}SetBatchRequestExample`,\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tbody: [\n\t\t\t\t\t\t\t{ id: \"12345\", name: \"My Item\" },\n\t\t\t\t\t\t\t{ id: \"67890\", name: \"My Other Item\" }\n\t\t\t\t\t\t]\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\tconst getRoute: IRestRoute<IEntityStorageGetRequest, IEntityStorageGetResponse> = {\n\t\toperationId: `${camelTypeName}Get`,\n\t\tsummary: `Get an entry from ${lowerName}.`,\n\t\ttag: options?.tagName ?? tagsEntityStorage[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/:id`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tentityStorageGet(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IEntityStorageGetRequest>(),\n\t\t\texamples: options?.examples?.get?.requestExamples ?? [\n\t\t\t\t{\n\t\t\t\t\tid: `${camelTypeName}GetRequestExample`,\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"12345\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<IEntityStorageGetResponse>(),\n\t\t\t\texamples: options?.examples?.get?.responseExamples ?? [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: `${camelTypeName}GetResponseExample`,\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\tid: \"12345\",\n\t\t\t\t\t\t\t\tname: \"My Item\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: nameof<INotFoundResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\tconst removeRoute: IRestRoute<IEntityStorageRemoveRequest, INoContentResponse> = {\n\t\toperationId: `${camelTypeName}Remove`,\n\t\tsummary: `Remove an entry from ${lowerName}.`,\n\t\ttag: options?.tagName ?? tagsEntityStorage[0].name,\n\t\tmethod: \"DELETE\",\n\t\tpath: `${baseRouteName}/:id`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tentityStorageRemove(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IEntityStorageRemoveRequest>(),\n\t\t\texamples: options?.examples?.remove?.requestExamples ?? [\n\t\t\t\t{\n\t\t\t\t\tid: `${camelTypeName}RemoveRequestExample`,\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"12345\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: nameof<INotFoundResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\tconst listRoute: IRestRoute<IEntityStorageListRequest, IEntityStorageListResponse> = {\n\t\toperationId: `${camelTypeName}List`,\n\t\tsummary: `Query entries from ${lowerName}.`,\n\t\ttag: options?.tagName ?? tagsEntityStorage[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tentityStorageList(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IEntityStorageListRequest>(),\n\t\t\texamples: options?.examples?.list?.requestExamples ?? [\n\t\t\t\t{\n\t\t\t\t\tid: `${camelTypeName}ListRequestExample`,\n\t\t\t\t\trequest: {}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<IEntityStorageListResponse>(),\n\t\t\t\texamples: options?.examples?.list?.responseExamples ?? [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: `${camelTypeName}ListResponseExample`,\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\tentities: [{ id: \"12345\", name: \"My Item\" }]\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\tconst countRoute: IRestRoute<IEntityStorageCountRequest, IEntityStorageCountResponse> = {\n\t\toperationId: `${camelTypeName}Count`,\n\t\tsummary: `Count entries in ${lowerName}.`,\n\t\ttag: options?.tagName ?? tagsEntityStorage[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/count`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tentityStorageCount(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IEntityStorageCountRequest>(),\n\t\t\texamples: options?.examples?.count?.requestExamples ?? [\n\t\t\t\t{\n\t\t\t\t\tid: `${camelTypeName}CountRequestExample`,\n\t\t\t\t\trequest: {}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<IEntityStorageCountResponse>(),\n\t\t\t\texamples: options?.examples?.count?.responseExamples ?? [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: `${camelTypeName}CountResponseExample`,\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\tcount: 1\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\tconst emptyRoute: IRestRoute<IEntityStorageEmptyRequest, INoContentResponse> = {\n\t\toperationId: `${camelTypeName}Empty`,\n\t\tsummary: `Remove all entries from ${lowerName}.`,\n\t\ttag: options?.tagName ?? tagsEntityStorage[0].name,\n\t\tmethod: \"DELETE\",\n\t\tpath: `${baseRouteName}/`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tentityStorageEmpty(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IEntityStorageEmptyRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: `${camelTypeName}EmptyRequestExample`,\n\t\t\t\t\trequest: {}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\tconst removeBatchRoute: IRestRoute<IEntityStorageRemoveBatchRequest, INoContentResponse> = {\n\t\toperationId: `${camelTypeName}RemoveBatch`,\n\t\tsummary: `Remove multiple entries from ${lowerName} by id.`,\n\t\ttag: options?.tagName ?? tagsEntityStorage[0].name,\n\t\tmethod: \"DELETE\",\n\t\tpath: `${baseRouteName}/batch`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tentityStorageRemoveBatch(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IEntityStorageRemoveBatchRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: `${camelTypeName}RemoveBatchRequestExample`,\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tbody: [\"12345\", \"67890\"]\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\treturn [\n\t\tsetRoute,\n\t\tsetBatchRoute,\n\t\tgetRoute,\n\t\tremoveRoute,\n\t\tremoveBatchRoute,\n\t\temptyRoute,\n\t\tlistRoute,\n\t\tcountRoute\n\t];\n}\n\n/**\n * Set the entry in entity storage.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function entityStorageSet(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IEntityStorageSetRequest\n): Promise<INoContentResponse> {\n\tGuards.object<IEntityStorageSetRequest>(ROUTES_SOURCE, nameof(request), request);\n\n\tconst component = ComponentFactory.get<IEntityStorageComponent>(componentName);\n\tawait component.set(\n\t\trequest.body,\n\t\tHttpParameterHelper.objectFromString(request.query?.conditions)\n\t);\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n\n/**\n * Set multiple entries in entity storage.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function entityStorageSetBatch(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IEntityStorageSetBatchRequest\n): Promise<INoContentResponse> {\n\tGuards.object<IEntityStorageSetBatchRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.arrayValue(ROUTES_SOURCE, nameof(request.body), request.body);\n\n\tconst component = ComponentFactory.get<IEntityStorageComponent>(componentName);\n\tawait component.setBatch(request.body);\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n\n/**\n * Remove all entries from entity storage.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function entityStorageEmpty(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IEntityStorageEmptyRequest\n): Promise<INoContentResponse> {\n\tconst component = ComponentFactory.get<IEntityStorageComponent>(componentName);\n\tawait component.empty();\n\treturn { statusCode: HttpStatusCode.noContent };\n}\n\n/**\n * Get the entry from entity storage.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function entityStorageGet(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IEntityStorageGetRequest\n): Promise<IEntityStorageGetResponse> {\n\tGuards.object<IEntityStorageGetRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IEntityStorageGetRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\n\tconst component = ComponentFactory.get<IEntityStorageComponent>(componentName);\n\tconst item = await component.get(\n\t\trequest.pathParams.id,\n\t\trequest.query?.secondaryIndex as keyof unknown,\n\t\tHttpParameterHelper.objectFromString(request.query?.conditions)\n\t);\n\treturn {\n\t\tbody: item\n\t};\n}\n\n/**\n * Remove the entry from entity storage.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function entityStorageRemove(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IEntityStorageRemoveRequest\n): Promise<INoContentResponse> {\n\tGuards.object<IEntityStorageRemoveRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IEntityStorageRemoveRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\n\tconst component = ComponentFactory.get<IEntityStorageComponent>(componentName);\n\tawait component.remove(\n\t\trequest.pathParams.id,\n\t\tHttpParameterHelper.objectFromString(request.query?.conditions)\n\t);\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n\n/**\n * Query the entries from entity storage.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function entityStorageList(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IEntityStorageListRequest\n): Promise<IEntityStorageListResponse> {\n\tGuards.object<IEntityStorageListRequest>(ROUTES_SOURCE, nameof(request), request);\n\n\tconst component = ComponentFactory.get<IEntityStorageComponent>(componentName);\n\tconst result = await component.query(\n\t\tHttpParameterHelper.objectFromString(request.query?.conditions),\n\t\trequest.query?.orderBy as keyof unknown,\n\t\trequest.query?.orderByDirection,\n\t\tHttpParameterHelper.objectFromString(request.query?.properties),\n\t\trequest.query?.cursor,\n\t\tCoerce.number(request.query?.limit)\n\t);\n\treturn {\n\t\tbody: result\n\t};\n}\n\n/**\n * Count the entries in entity storage.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function entityStorageCount(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IEntityStorageCountRequest\n): Promise<IEntityStorageCountResponse> {\n\tconst component = ComponentFactory.get<IEntityStorageComponent>(componentName);\n\tconst count = await component.count(\n\t\tHttpParameterHelper.objectFromString(request.query?.conditions)\n\t);\n\treturn {\n\t\tbody: { count }\n\t};\n}\n\n/**\n * Remove multiple entries from entity storage by id.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function entityStorageRemoveBatch(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IEntityStorageRemoveBatchRequest\n): Promise<INoContentResponse> {\n\tGuards.object<IEntityStorageRemoveBatchRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.arrayValue(ROUTES_SOURCE, nameof(request.body), request.body);\n\n\tconst component = ComponentFactory.get<IEntityStorageComponent>(componentName);\n\tawait component.removeBatch(request.body);\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n"]}
|
|
@@ -35,11 +35,12 @@ export class EntityStorageService {
|
|
|
35
35
|
/**
|
|
36
36
|
* Set an entity.
|
|
37
37
|
* @param entity The entity to set.
|
|
38
|
+
* @param conditions The optional conditions to match for the entities.
|
|
38
39
|
* @returns The id of the entity.
|
|
39
40
|
*/
|
|
40
|
-
async set(entity) {
|
|
41
|
+
async set(entity, conditions) {
|
|
41
42
|
Guards.object(EntityStorageService.CLASS_NAME, "entity", entity);
|
|
42
|
-
return this._entityStorage.set(entity,
|
|
43
|
+
return this._entityStorage.set(entity, conditions);
|
|
43
44
|
}
|
|
44
45
|
/**
|
|
45
46
|
* Set multiple entities in a batch.
|
|
@@ -54,20 +55,22 @@ export class EntityStorageService {
|
|
|
54
55
|
* Get an entity.
|
|
55
56
|
* @param id The id of the entity to get, or the index value if secondaryIndex is set.
|
|
56
57
|
* @param secondaryIndex Get the item using a secondary index.
|
|
58
|
+
* @param conditions The optional conditions to match for the entities.
|
|
57
59
|
* @returns The object if it can be found or undefined.
|
|
58
60
|
*/
|
|
59
|
-
async get(id, secondaryIndex) {
|
|
61
|
+
async get(id, secondaryIndex, conditions) {
|
|
60
62
|
Guards.stringValue(EntityStorageService.CLASS_NAME, "id", id);
|
|
61
|
-
return this._entityStorage.get(id, secondaryIndex);
|
|
63
|
+
return this._entityStorage.get(id, secondaryIndex, conditions);
|
|
62
64
|
}
|
|
63
65
|
/**
|
|
64
66
|
* Remove the entity.
|
|
65
67
|
* @param id The id of the entity to remove.
|
|
68
|
+
* @param conditions The optional conditions to match for the entities.
|
|
66
69
|
* @returns Nothing.
|
|
67
70
|
*/
|
|
68
|
-
async remove(id) {
|
|
71
|
+
async remove(id, conditions) {
|
|
69
72
|
Guards.stringValue(EntityStorageService.CLASS_NAME, "id", id);
|
|
70
|
-
await this._entityStorage.remove(id);
|
|
73
|
+
await this._entityStorage.remove(id, conditions);
|
|
71
74
|
}
|
|
72
75
|
/**
|
|
73
76
|
* Remove multiple entities by id.
|
|
@@ -87,10 +90,11 @@ export class EntityStorageService {
|
|
|
87
90
|
}
|
|
88
91
|
/**
|
|
89
92
|
* Count all the entities which match the conditions.
|
|
93
|
+
* @param conditions The optional conditions to match for the entities.
|
|
90
94
|
* @returns The total count of entities in the storage.
|
|
91
95
|
*/
|
|
92
|
-
async count() {
|
|
93
|
-
return this._entityStorage.count();
|
|
96
|
+
async count(conditions) {
|
|
97
|
+
return this._entityStorage.count(conditions);
|
|
94
98
|
}
|
|
95
99
|
/**
|
|
96
100
|
* Query all the entities which match the conditions.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entityStorageService.js","sourceRoot":"","sources":["../../src/entityStorageService.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAwB,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EACN,6BAA6B,EAG7B,MAAM,iCAAiC,CAAC;AAIzC;;GAEG;AACH,8DAA8D;AAC9D,MAAM,OAAO,oBAAoB;IAChC;;OAEG;IACI,MAAM,CAAU,UAAU,0BAA0C;IAE3E;;;OAGG;IACc,cAAc,CAA6B;IAE5D;;;OAGG;IACH,YAAY,OAAgD;QAC3D,MAAM,CAAC,MAAM,CACZ,oBAAoB,CAAC,UAAU,+BAE/B,OAAO,CAAC,iBAAiB,CACzB,CAAC;QACF,IAAI,CAAC,cAAc,GAAG,6BAA6B,CAAC,GAAG,CACtD,OAAO,CAAC,iBAAiB,CACzB,CAAC;IACH,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,oBAAoB,CAAC,UAAU,CAAC;IACxC,CAAC;IAED
|
|
1
|
+
{"version":3,"file":"entityStorageService.js","sourceRoot":"","sources":["../../src/entityStorageService.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,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CAAC;IAChE,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,MAAM,CAClB,EAAU,EACV,UAAoD;QAEpD,MAAM,CAAC,WAAW,CAAC,oBAAoB,CAAC,UAAU,QAAc,EAAE,CAAC,CAAC;QAEpE,MAAM,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,EAAE,UAAU,CAAC,CAAC;IAClD,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,WAAW,CAAC,GAAa;QACrC,MAAM,CAAC,UAAU,CAAC,oBAAoB,CAAC,UAAU,SAAe,GAAG,CAAC,CAAC;QAErE,OAAO,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IAC7C,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,KAAK;QACjB,OAAO,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;IACpC,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,KAAK,CAAC,UAA+B;QACjD,OAAO,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAC9C,CAAC;IAED;;;;;;;;;;OAUG;IACI,KAAK,CAAC,KAAK,CACjB,UAA+B,EAC/B,OAAiB,EACjB,gBAAgC,EAChC,UAAwB,EACxB,MAAe,EACf,KAAc;QAWd,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,KAAK,CAC7C,UAAU,EACV,EAAE,CAAC,WAAW,CAAC,OAAO,CAAC;YACtB,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,aAAa,EAAE,gBAAgB,IAAI,aAAa,CAAC,SAAS,EAAE,CAAC;YACrF,CAAC,CAAC,SAAS,EACZ,UAAU,EACV,MAAM,EACN,KAAK,CACL,CAAC;QAEF,OAAO,MAAM,CAAC;IACf,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Guards, Is } from \"@twin.org/core\";\nimport { type EntityCondition, SortDirection } from \"@twin.org/entity\";\nimport {\n\tEntityStorageConnectorFactory,\n\ttype IEntityStorageComponent,\n\ttype IEntityStorageConnector\n} from \"@twin.org/entity-storage-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type { IEntityStorageServiceConstructorOptions } from \"./models/IEntityStorageServiceConstructorOptions.js\";\n\n/**\n * Class for performing entity service operations.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class EntityStorageService<T = any> implements IEntityStorageComponent<T> {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<EntityStorageService>();\n\n\t/**\n\t * The entity storage for items.\n\t * @internal\n\t */\n\tprivate readonly _entityStorage: IEntityStorageConnector<T>;\n\n\t/**\n\t * Create a new instance of EntityStorageService.\n\t * @param options The dependencies for the entity storage service.\n\t */\n\tconstructor(options: IEntityStorageServiceConstructorOptions) {\n\t\tGuards.string(\n\t\t\tEntityStorageService.CLASS_NAME,\n\t\t\tnameof(options.entityStorageType),\n\t\t\toptions.entityStorageType\n\t\t);\n\t\tthis._entityStorage = EntityStorageConnectorFactory.get<IEntityStorageConnector<T>>(\n\t\t\toptions.entityStorageType\n\t\t);\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn EntityStorageService.CLASS_NAME;\n\t}\n\n\t/**\n\t * Set an entity.\n\t * @param entity The entity to set.\n\t * @param conditions The optional conditions to match for the entities.\n\t * @returns The id of the entity.\n\t */\n\tpublic async set(entity: T, conditions?: { property: keyof T; value: unknown }[]): Promise<void> {\n\t\tGuards.object(EntityStorageService.CLASS_NAME, nameof(entity), entity);\n\n\t\treturn this._entityStorage.set(entity, conditions);\n\t}\n\n\t/**\n\t * Set multiple entities in a batch.\n\t * @param entities The entities to set.\n\t * @returns Nothing.\n\t */\n\tpublic async setBatch(entities: T[]): Promise<void> {\n\t\tGuards.arrayValue(EntityStorageService.CLASS_NAME, nameof(entities), entities);\n\n\t\treturn this._entityStorage.setBatch(entities);\n\t}\n\n\t/**\n\t * Get an entity.\n\t * @param id The id of the entity to get, or the index value if secondaryIndex is set.\n\t * @param secondaryIndex Get the item using a secondary index.\n\t * @param conditions The optional conditions to match for the entities.\n\t * @returns The object if it can be found or undefined.\n\t */\n\tpublic async get(\n\t\tid: string,\n\t\tsecondaryIndex?: keyof T,\n\t\tconditions?: { property: keyof T; value: unknown }[]\n\t): Promise<T | undefined> {\n\t\tGuards.stringValue(EntityStorageService.CLASS_NAME, nameof(id), id);\n\n\t\treturn this._entityStorage.get(id, secondaryIndex, conditions);\n\t}\n\n\t/**\n\t * Remove the entity.\n\t * @param id The id of the entity to remove.\n\t * @param conditions The optional conditions to match for the entities.\n\t * @returns Nothing.\n\t */\n\tpublic async remove(\n\t\tid: string,\n\t\tconditions?: { property: keyof T; value: unknown }[]\n\t): Promise<void> {\n\t\tGuards.stringValue(EntityStorageService.CLASS_NAME, nameof(id), id);\n\n\t\tawait this._entityStorage.remove(id, conditions);\n\t}\n\n\t/**\n\t * Remove multiple entities by id.\n\t * @param ids The ids of the entities to remove.\n\t * @returns Nothing.\n\t */\n\tpublic async removeBatch(ids: string[]): Promise<void> {\n\t\tGuards.arrayValue(EntityStorageService.CLASS_NAME, nameof(ids), ids);\n\n\t\treturn this._entityStorage.removeBatch(ids);\n\t}\n\n\t/**\n\t * Remove all entities from the storage.\n\t * @returns Nothing.\n\t */\n\tpublic async empty(): Promise<void> {\n\t\treturn this._entityStorage.empty();\n\t}\n\n\t/**\n\t * Count all the entities which match the conditions.\n\t * @param conditions The optional conditions to match for the entities.\n\t * @returns The total count of entities in the storage.\n\t */\n\tpublic async count(conditions?: EntityCondition<T>): Promise<number> {\n\t\treturn this._entityStorage.count(conditions);\n\t}\n\n\t/**\n\t * Query all the entities which match the conditions.\n\t * @param conditions The conditions to match for the entities.\n\t * @param orderBy The order for the results.\n\t * @param orderByDirection The direction for the order, defaults to ascending.\n\t * @param properties The optional properties to return, defaults to all.\n\t * @param cursor The cursor to request the next chunk of entities.\n\t * @param limit The suggested number of entities to return in each chunk, in some scenarios can return a different amount.\n\t * @returns All the entities for the storage matching the conditions,\n\t * and a cursor which can be used to request more entities.\n\t */\n\tpublic async query(\n\t\tconditions?: EntityCondition<T>,\n\t\torderBy?: keyof T,\n\t\torderByDirection?: SortDirection,\n\t\tproperties?: (keyof T)[],\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<{\n\t\t/**\n\t\t * The entities, which can be partial if a limited keys list was provided.\n\t\t */\n\t\tentities: Partial<T>[];\n\t\t/**\n\t\t * An optional cursor, when defined can be used to call find to get more entities.\n\t\t */\n\t\tcursor?: string;\n\t}> {\n\t\tconst result = await this._entityStorage.query(\n\t\t\tconditions,\n\t\t\tIs.stringValue(orderBy)\n\t\t\t\t? [{ property: orderBy, sortDirection: orderByDirection ?? SortDirection.Ascending }]\n\t\t\t\t: undefined,\n\t\t\tproperties,\n\t\t\tcursor,\n\t\t\tlimit\n\t\t);\n\n\t\treturn result;\n\t}\n}\n"]}
|
|
@@ -22,9 +22,13 @@ export declare class EntityStorageService<T = any> implements IEntityStorageComp
|
|
|
22
22
|
/**
|
|
23
23
|
* Set an entity.
|
|
24
24
|
* @param entity The entity to set.
|
|
25
|
+
* @param conditions The optional conditions to match for the entities.
|
|
25
26
|
* @returns The id of the entity.
|
|
26
27
|
*/
|
|
27
|
-
set(entity: T
|
|
28
|
+
set(entity: T, conditions?: {
|
|
29
|
+
property: keyof T;
|
|
30
|
+
value: unknown;
|
|
31
|
+
}[]): Promise<void>;
|
|
28
32
|
/**
|
|
29
33
|
* Set multiple entities in a batch.
|
|
30
34
|
* @param entities The entities to set.
|
|
@@ -35,15 +39,23 @@ export declare class EntityStorageService<T = any> implements IEntityStorageComp
|
|
|
35
39
|
* Get an entity.
|
|
36
40
|
* @param id The id of the entity to get, or the index value if secondaryIndex is set.
|
|
37
41
|
* @param secondaryIndex Get the item using a secondary index.
|
|
42
|
+
* @param conditions The optional conditions to match for the entities.
|
|
38
43
|
* @returns The object if it can be found or undefined.
|
|
39
44
|
*/
|
|
40
|
-
get(id: string, secondaryIndex?: keyof T
|
|
45
|
+
get(id: string, secondaryIndex?: keyof T, conditions?: {
|
|
46
|
+
property: keyof T;
|
|
47
|
+
value: unknown;
|
|
48
|
+
}[]): Promise<T | undefined>;
|
|
41
49
|
/**
|
|
42
50
|
* Remove the entity.
|
|
43
51
|
* @param id The id of the entity to remove.
|
|
52
|
+
* @param conditions The optional conditions to match for the entities.
|
|
44
53
|
* @returns Nothing.
|
|
45
54
|
*/
|
|
46
|
-
remove(id: string
|
|
55
|
+
remove(id: string, conditions?: {
|
|
56
|
+
property: keyof T;
|
|
57
|
+
value: unknown;
|
|
58
|
+
}[]): Promise<void>;
|
|
47
59
|
/**
|
|
48
60
|
* Remove multiple entities by id.
|
|
49
61
|
* @param ids The ids of the entities to remove.
|
|
@@ -57,9 +69,10 @@ export declare class EntityStorageService<T = any> implements IEntityStorageComp
|
|
|
57
69
|
empty(): Promise<void>;
|
|
58
70
|
/**
|
|
59
71
|
* Count all the entities which match the conditions.
|
|
72
|
+
* @param conditions The optional conditions to match for the entities.
|
|
60
73
|
* @returns The total count of entities in the storage.
|
|
61
74
|
*/
|
|
62
|
-
count(): Promise<number>;
|
|
75
|
+
count(conditions?: EntityCondition<T>): Promise<number>;
|
|
63
76
|
/**
|
|
64
77
|
* Query all the entities which match the conditions.
|
|
65
78
|
* @param conditions The conditions to match for the entities.
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.3-next.14](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-service-v0.0.3-next.13...entity-storage-service-v0.0.3-next.14) (2026-05-19)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* adding schema migration functionality to all the connectors ([#85](https://github.com/iotaledger/twin-entity-storage/issues/85)) ([fd1555a](https://github.com/iotaledger/twin-entity-storage/commit/fd1555a34380158214a577586dafae821e72a578))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* dependencies
|
|
15
|
+
* @twin.org/entity-storage-models bumped from 0.0.3-next.13 to 0.0.3-next.14
|
|
16
|
+
* devDependencies
|
|
17
|
+
* @twin.org/entity-storage-connector-memory bumped from 0.0.3-next.13 to 0.0.3-next.14
|
|
18
|
+
|
|
3
19
|
## [0.0.3-next.13](https://github.com/iotaledger/twin-entity-storage/compare/entity-storage-service-v0.0.3-next.12...entity-storage-service-v0.0.3-next.13) (2026-05-13)
|
|
4
20
|
|
|
5
21
|
|
package/docs/open-api/spec.json
CHANGED
|
@@ -28,6 +28,17 @@
|
|
|
28
28
|
"tags": [
|
|
29
29
|
"EntityStorage"
|
|
30
30
|
],
|
|
31
|
+
"parameters": [
|
|
32
|
+
{
|
|
33
|
+
"name": "conditions",
|
|
34
|
+
"description": "The optional conditions to match for the entity, JSON encoded array of property/value pairs.",
|
|
35
|
+
"in": "query",
|
|
36
|
+
"required": false,
|
|
37
|
+
"schema": {
|
|
38
|
+
"type": "string"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
],
|
|
31
42
|
"security": [
|
|
32
43
|
{
|
|
33
44
|
"jwtBearerAuthScheme": []
|
|
@@ -571,6 +582,15 @@
|
|
|
571
582
|
"schema": {
|
|
572
583
|
"type": "string"
|
|
573
584
|
}
|
|
585
|
+
},
|
|
586
|
+
{
|
|
587
|
+
"name": "conditions",
|
|
588
|
+
"description": "The optional conditions to match for the entity, JSON encoded array of property/value pairs.",
|
|
589
|
+
"in": "query",
|
|
590
|
+
"required": false,
|
|
591
|
+
"schema": {
|
|
592
|
+
"type": "string"
|
|
593
|
+
}
|
|
574
594
|
}
|
|
575
595
|
],
|
|
576
596
|
"security": [
|
|
@@ -694,6 +714,15 @@
|
|
|
694
714
|
},
|
|
695
715
|
"style": "simple",
|
|
696
716
|
"example": "12345"
|
|
717
|
+
},
|
|
718
|
+
{
|
|
719
|
+
"name": "conditions",
|
|
720
|
+
"description": "The optional conditions to match for the entity, JSON encoded array of property/value pairs.",
|
|
721
|
+
"in": "query",
|
|
722
|
+
"required": false,
|
|
723
|
+
"schema": {
|
|
724
|
+
"type": "string"
|
|
725
|
+
}
|
|
697
726
|
}
|
|
698
727
|
],
|
|
699
728
|
"security": [
|
|
@@ -793,22 +822,22 @@
|
|
|
793
822
|
"tags": [
|
|
794
823
|
"EntityStorage"
|
|
795
824
|
],
|
|
825
|
+
"parameters": [
|
|
826
|
+
{
|
|
827
|
+
"name": "conditions",
|
|
828
|
+
"description": "The optional conditions to filter the count, JSON encoded EntityCondition.",
|
|
829
|
+
"in": "query",
|
|
830
|
+
"required": false,
|
|
831
|
+
"schema": {
|
|
832
|
+
"type": "string"
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
],
|
|
796
836
|
"security": [
|
|
797
837
|
{
|
|
798
838
|
"jwtBearerAuthScheme": []
|
|
799
839
|
}
|
|
800
840
|
],
|
|
801
|
-
"requestBody": {
|
|
802
|
-
"description": "Count the entries in entity storage.",
|
|
803
|
-
"required": true,
|
|
804
|
-
"content": {
|
|
805
|
-
"text/plain": {
|
|
806
|
-
"schema": {
|
|
807
|
-
"$ref": "#/components/schemas/EntityStorageCountRequest"
|
|
808
|
-
}
|
|
809
|
-
}
|
|
810
|
-
}
|
|
811
|
-
},
|
|
812
841
|
"responses": {
|
|
813
842
|
"200": {
|
|
814
843
|
"description": "The response for counting entries in entity storage.",
|
|
@@ -890,10 +919,6 @@
|
|
|
890
919
|
},
|
|
891
920
|
"components": {
|
|
892
921
|
"schemas": {
|
|
893
|
-
"EntityStorageCountRequest": {
|
|
894
|
-
"description": "Count the entries in entity storage.",
|
|
895
|
-
"type": "object"
|
|
896
|
-
},
|
|
897
922
|
"EntityStorageCountResponse": {
|
|
898
923
|
"type": "object",
|
|
899
924
|
"properties": {
|
|
@@ -62,7 +62,7 @@ The class name of the component.
|
|
|
62
62
|
|
|
63
63
|
### set() {#set}
|
|
64
64
|
|
|
65
|
-
> **set**(`entity`): `Promise`\<`void`\>
|
|
65
|
+
> **set**(`entity`, `conditions?`): `Promise`\<`void`\>
|
|
66
66
|
|
|
67
67
|
Set an entity.
|
|
68
68
|
|
|
@@ -74,6 +74,12 @@ Set an entity.
|
|
|
74
74
|
|
|
75
75
|
The entity to set.
|
|
76
76
|
|
|
77
|
+
##### conditions?
|
|
78
|
+
|
|
79
|
+
`object`[]
|
|
80
|
+
|
|
81
|
+
The optional conditions to match for the entities.
|
|
82
|
+
|
|
77
83
|
#### Returns
|
|
78
84
|
|
|
79
85
|
`Promise`\<`void`\>
|
|
@@ -114,7 +120,7 @@ Nothing.
|
|
|
114
120
|
|
|
115
121
|
### get() {#get}
|
|
116
122
|
|
|
117
|
-
> **get**(`id`, `secondaryIndex?`): `Promise`\<`T` \| `undefined`\>
|
|
123
|
+
> **get**(`id`, `secondaryIndex?`, `conditions?`): `Promise`\<`T` \| `undefined`\>
|
|
118
124
|
|
|
119
125
|
Get an entity.
|
|
120
126
|
|
|
@@ -132,6 +138,12 @@ keyof `T`
|
|
|
132
138
|
|
|
133
139
|
Get the item using a secondary index.
|
|
134
140
|
|
|
141
|
+
##### conditions?
|
|
142
|
+
|
|
143
|
+
`object`[]
|
|
144
|
+
|
|
145
|
+
The optional conditions to match for the entities.
|
|
146
|
+
|
|
135
147
|
#### Returns
|
|
136
148
|
|
|
137
149
|
`Promise`\<`T` \| `undefined`\>
|
|
@@ -146,7 +158,7 @@ The object if it can be found or undefined.
|
|
|
146
158
|
|
|
147
159
|
### remove() {#remove}
|
|
148
160
|
|
|
149
|
-
> **remove**(`id`): `Promise`\<`void`\>
|
|
161
|
+
> **remove**(`id`, `conditions?`): `Promise`\<`void`\>
|
|
150
162
|
|
|
151
163
|
Remove the entity.
|
|
152
164
|
|
|
@@ -158,6 +170,12 @@ Remove the entity.
|
|
|
158
170
|
|
|
159
171
|
The id of the entity to remove.
|
|
160
172
|
|
|
173
|
+
##### conditions?
|
|
174
|
+
|
|
175
|
+
`object`[]
|
|
176
|
+
|
|
177
|
+
The optional conditions to match for the entities.
|
|
178
|
+
|
|
161
179
|
#### Returns
|
|
162
180
|
|
|
163
181
|
`Promise`\<`void`\>
|
|
@@ -216,10 +234,18 @@ Nothing.
|
|
|
216
234
|
|
|
217
235
|
### count() {#count}
|
|
218
236
|
|
|
219
|
-
> **count**(): `Promise`\<`number`\>
|
|
237
|
+
> **count**(`conditions?`): `Promise`\<`number`\>
|
|
220
238
|
|
|
221
239
|
Count all the entities which match the conditions.
|
|
222
240
|
|
|
241
|
+
#### Parameters
|
|
242
|
+
|
|
243
|
+
##### conditions?
|
|
244
|
+
|
|
245
|
+
`EntityCondition`\<`T`\>
|
|
246
|
+
|
|
247
|
+
The optional conditions to match for the entities.
|
|
248
|
+
|
|
223
249
|
#### Returns
|
|
224
250
|
|
|
225
251
|
`Promise`\<`number`\>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/entity-storage-service",
|
|
3
|
-
"version": "0.0.3-next.
|
|
3
|
+
"version": "0.0.3-next.14",
|
|
4
4
|
"description": "Service layer exposing storage contracts and REST endpoint definitions.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"@twin.org/api-models": "next",
|
|
18
18
|
"@twin.org/core": "next",
|
|
19
19
|
"@twin.org/entity": "next",
|
|
20
|
-
"@twin.org/entity-storage-models": "0.0.3-next.
|
|
20
|
+
"@twin.org/entity-storage-models": "0.0.3-next.14",
|
|
21
21
|
"@twin.org/nameof": "next",
|
|
22
22
|
"@twin.org/web": "next"
|
|
23
23
|
},
|