@twin.org/blob-storage-service 0.0.1-next.13 → 0.0.1-next.15

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.
@@ -371,7 +371,7 @@ async function blobStorageCreate(httpRequestContext, componentName, request) {
371
371
  core.Guards.object(ROUTES_SOURCE, "request.body", request.body);
372
372
  core.Guards.stringBase64(ROUTES_SOURCE, "request.body.blob", request.body.blob);
373
373
  const component = core.ComponentFactory.get(componentName);
374
- const id = await component.create(request.body.blob, request.body.encodingFormat, request.body.fileExtension, request.body.metadata, request.body.namespace, httpRequestContext.nodeIdentity);
374
+ const id = await component.create(request.body.blob, request.body.encodingFormat, request.body.fileExtension, request.body.metadata, request.body.namespace, httpRequestContext.userIdentity, httpRequestContext.nodeIdentity);
375
375
  return {
376
376
  statusCode: web.HttpStatusCode.created,
377
377
  headers: {
@@ -472,7 +472,7 @@ async function blobStorageList(httpRequestContext, componentName, request) {
472
472
  core.Guards.object(ROUTES_SOURCE, "request", request);
473
473
  const mimeType = request.headers?.[web.HeaderTypes.Accept] === web.MimeTypes.JsonLd ? "jsonld" : "json";
474
474
  const component = core.ComponentFactory.get(componentName);
475
- const result = await component.query(apiModels.HttpParameterHelper.objectFromString(request.query?.conditions), apiModels.HttpParameterHelper.objectFromString(request.query?.sortProperties), request.query?.cursor, core.Coerce.number(request.query?.pageSize), httpRequestContext.userIdentity, httpRequestContext.nodeIdentity);
475
+ const result = await component.query(apiModels.HttpParameterHelper.objectFromString(request.query?.conditions), request.query?.orderBy, request.query?.orderByDirection, request.query?.cursor, core.Coerce.number(request.query?.pageSize), httpRequestContext.userIdentity, httpRequestContext.nodeIdentity);
476
476
  return {
477
477
  headers: {
478
478
  [web.HeaderTypes.ContentType]: mimeType === "json" ? web.MimeTypes.Json : web.MimeTypes.JsonLd
@@ -759,7 +759,8 @@ class BlobStorageService {
759
759
  /**
760
760
  * Query all the blob storage entries which match the conditions.
761
761
  * @param conditions The conditions to match for the entries.
762
- * @param sortProperties The optional sort order.
762
+ * @param orderBy The order for the results, defaults to created.
763
+ * @param orderByDirection The direction for the order, defaults to descending.
763
764
  * @param cursor The cursor to request the next page of entries.
764
765
  * @param pageSize The suggested number of entries to return in each chunk, in some scenarios can return a different amount.
765
766
  * @param userIdentity The user identity to use with storage operations.
@@ -767,7 +768,7 @@ class BlobStorageService {
767
768
  * @returns All the entries for the storage matching the conditions,
768
769
  * and a cursor which can be used to request more entities.
769
770
  */
770
- async query(conditions, sortProperties, cursor, pageSize, userIdentity, nodeIdentity) {
771
+ async query(conditions, orderBy, orderByDirection, cursor, pageSize, userIdentity, nodeIdentity) {
771
772
  const finalConditions = {
772
773
  conditions: [],
773
774
  logicalOperator: entity.LogicalOperator.And
@@ -791,7 +792,14 @@ class BlobStorageService {
791
792
  if (!core.Is.empty(conditions)) {
792
793
  finalConditions.conditions.push(conditions);
793
794
  }
794
- const result = await this._entryEntityStorage.query(finalConditions.conditions.length > 0 ? finalConditions : undefined, sortProperties, undefined, cursor, pageSize);
795
+ const orderProperty = orderBy ?? "dateCreated";
796
+ const orderDirection = orderByDirection ?? entity.SortDirection.Descending;
797
+ const result = await this._entryEntityStorage.query(finalConditions.conditions.length > 0 ? finalConditions : undefined, [
798
+ {
799
+ property: orderProperty,
800
+ sortDirection: orderDirection
801
+ }
802
+ ], undefined, cursor, pageSize);
795
803
  for (const entity of result.entities) {
796
804
  core.ObjectHelper.propertyDelete(entity, "nodeIdentity");
797
805
  core.ObjectHelper.propertyDelete(entity, "userIdentity");
@@ -943,11 +951,11 @@ __decorate([
943
951
  __metadata("design:type", String)
944
952
  ], exports.BlobStorageEntry.prototype, "id", void 0);
945
953
  __decorate([
946
- entity.property({ type: "string", format: "date-time", sortDirection: "desc" }),
954
+ entity.property({ type: "string", format: "date-time", sortDirection: entity.SortDirection.Descending }),
947
955
  __metadata("design:type", String)
948
956
  ], exports.BlobStorageEntry.prototype, "dateCreated", void 0);
949
957
  __decorate([
950
- entity.property({ type: "string", format: "date-time", sortDirection: "desc" }),
958
+ entity.property({ type: "string", format: "date-time", sortDirection: entity.SortDirection.Descending }),
951
959
  __metadata("design:type", String)
952
960
  ], exports.BlobStorageEntry.prototype, "dateModified", void 0);
953
961
  __decorate([
@@ -4,7 +4,7 @@ import { StringHelper, Guards, ComponentFactory, Is, Converter, Coerce, GeneralE
4
4
  import { SchemaOrgTypes, SchemaOrgDataTypes } from '@twin.org/data-schema-org';
5
5
  import { HttpStatusCode, HeaderTypes, MimeTypes, MimeTypeHelper } from '@twin.org/web';
6
6
  import { JsonLdHelper, JsonLdProcessor } from '@twin.org/data-json-ld';
7
- import { ComparisonOperator, LogicalOperator, EntitySchemaHelper, property, entity, EntitySchemaFactory } from '@twin.org/entity';
7
+ import { ComparisonOperator, LogicalOperator, SortDirection, EntitySchemaHelper, property, entity, EntitySchemaFactory } from '@twin.org/entity';
8
8
  import { EntityStorageConnectorFactory } from '@twin.org/entity-storage-models';
9
9
  import { VaultConnectorFactory, VaultEncryptionType } from '@twin.org/vault-models';
10
10
 
@@ -369,7 +369,7 @@ async function blobStorageCreate(httpRequestContext, componentName, request) {
369
369
  Guards.object(ROUTES_SOURCE, "request.body", request.body);
370
370
  Guards.stringBase64(ROUTES_SOURCE, "request.body.blob", request.body.blob);
371
371
  const component = ComponentFactory.get(componentName);
372
- const id = await component.create(request.body.blob, request.body.encodingFormat, request.body.fileExtension, request.body.metadata, request.body.namespace, httpRequestContext.nodeIdentity);
372
+ const id = await component.create(request.body.blob, request.body.encodingFormat, request.body.fileExtension, request.body.metadata, request.body.namespace, httpRequestContext.userIdentity, httpRequestContext.nodeIdentity);
373
373
  return {
374
374
  statusCode: HttpStatusCode.created,
375
375
  headers: {
@@ -470,7 +470,7 @@ async function blobStorageList(httpRequestContext, componentName, request) {
470
470
  Guards.object(ROUTES_SOURCE, "request", request);
471
471
  const mimeType = request.headers?.[HeaderTypes.Accept] === MimeTypes.JsonLd ? "jsonld" : "json";
472
472
  const component = ComponentFactory.get(componentName);
473
- const result = await component.query(HttpParameterHelper.objectFromString(request.query?.conditions), HttpParameterHelper.objectFromString(request.query?.sortProperties), request.query?.cursor, Coerce.number(request.query?.pageSize), httpRequestContext.userIdentity, httpRequestContext.nodeIdentity);
473
+ const result = await component.query(HttpParameterHelper.objectFromString(request.query?.conditions), request.query?.orderBy, request.query?.orderByDirection, request.query?.cursor, Coerce.number(request.query?.pageSize), httpRequestContext.userIdentity, httpRequestContext.nodeIdentity);
474
474
  return {
475
475
  headers: {
476
476
  [HeaderTypes.ContentType]: mimeType === "json" ? MimeTypes.Json : MimeTypes.JsonLd
@@ -757,7 +757,8 @@ class BlobStorageService {
757
757
  /**
758
758
  * Query all the blob storage entries which match the conditions.
759
759
  * @param conditions The conditions to match for the entries.
760
- * @param sortProperties The optional sort order.
760
+ * @param orderBy The order for the results, defaults to created.
761
+ * @param orderByDirection The direction for the order, defaults to descending.
761
762
  * @param cursor The cursor to request the next page of entries.
762
763
  * @param pageSize The suggested number of entries to return in each chunk, in some scenarios can return a different amount.
763
764
  * @param userIdentity The user identity to use with storage operations.
@@ -765,7 +766,7 @@ class BlobStorageService {
765
766
  * @returns All the entries for the storage matching the conditions,
766
767
  * and a cursor which can be used to request more entities.
767
768
  */
768
- async query(conditions, sortProperties, cursor, pageSize, userIdentity, nodeIdentity) {
769
+ async query(conditions, orderBy, orderByDirection, cursor, pageSize, userIdentity, nodeIdentity) {
769
770
  const finalConditions = {
770
771
  conditions: [],
771
772
  logicalOperator: LogicalOperator.And
@@ -789,7 +790,14 @@ class BlobStorageService {
789
790
  if (!Is.empty(conditions)) {
790
791
  finalConditions.conditions.push(conditions);
791
792
  }
792
- const result = await this._entryEntityStorage.query(finalConditions.conditions.length > 0 ? finalConditions : undefined, sortProperties, undefined, cursor, pageSize);
793
+ const orderProperty = orderBy ?? "dateCreated";
794
+ const orderDirection = orderByDirection ?? SortDirection.Descending;
795
+ const result = await this._entryEntityStorage.query(finalConditions.conditions.length > 0 ? finalConditions : undefined, [
796
+ {
797
+ property: orderProperty,
798
+ sortDirection: orderDirection
799
+ }
800
+ ], undefined, cursor, pageSize);
793
801
  for (const entity of result.entities) {
794
802
  ObjectHelper.propertyDelete(entity, "nodeIdentity");
795
803
  ObjectHelper.propertyDelete(entity, "userIdentity");
@@ -941,11 +949,11 @@ __decorate([
941
949
  __metadata("design:type", String)
942
950
  ], BlobStorageEntry.prototype, "id", void 0);
943
951
  __decorate([
944
- property({ type: "string", format: "date-time", sortDirection: "desc" }),
952
+ property({ type: "string", format: "date-time", sortDirection: SortDirection.Descending }),
945
953
  __metadata("design:type", String)
946
954
  ], BlobStorageEntry.prototype, "dateCreated", void 0);
947
955
  __decorate([
948
- property({ type: "string", format: "date-time", sortDirection: "desc" }),
956
+ property({ type: "string", format: "date-time", sortDirection: SortDirection.Descending }),
949
957
  __metadata("design:type", String)
950
958
  ], BlobStorageEntry.prototype, "dateModified", void 0);
951
959
  __decorate([
@@ -1,6 +1,6 @@
1
1
  import { type IBlobStorageEntry, type IBlobStorageComponent, type IBlobStorageEntryList } from "@twin.org/blob-storage-models";
2
2
  import { type IJsonLdNodeObject } from "@twin.org/data-json-ld";
3
- import { type EntityCondition, type SortDirection } from "@twin.org/entity";
3
+ import { type EntityCondition, SortDirection } from "@twin.org/entity";
4
4
  import type { IBlobStorageServiceConfig } from "./models/IBlobStorageServiceConfig";
5
5
  /**
6
6
  * Service for performing blob storage operations to a connector.
@@ -71,7 +71,8 @@ export declare class BlobStorageService implements IBlobStorageComponent {
71
71
  /**
72
72
  * Query all the blob storage entries which match the conditions.
73
73
  * @param conditions The conditions to match for the entries.
74
- * @param sortProperties The optional sort order.
74
+ * @param orderBy The order for the results, defaults to created.
75
+ * @param orderByDirection The direction for the order, defaults to descending.
75
76
  * @param cursor The cursor to request the next page of entries.
76
77
  * @param pageSize The suggested number of entries to return in each chunk, in some scenarios can return a different amount.
77
78
  * @param userIdentity The user identity to use with storage operations.
@@ -79,8 +80,5 @@ export declare class BlobStorageService implements IBlobStorageComponent {
79
80
  * @returns All the entries for the storage matching the conditions,
80
81
  * and a cursor which can be used to request more entities.
81
82
  */
82
- query(conditions?: EntityCondition<IBlobStorageEntry>, sortProperties?: {
83
- property: keyof Pick<IBlobStorageEntry, "dateCreated" | "dateModified">;
84
- sortDirection: SortDirection;
85
- }[], cursor?: string, pageSize?: number, userIdentity?: string, nodeIdentity?: string): Promise<IBlobStorageEntryList>;
83
+ query(conditions?: EntityCondition<IBlobStorageEntry>, orderBy?: keyof Pick<IBlobStorageEntry, "dateCreated" | "dateModified">, orderByDirection?: SortDirection, cursor?: string, pageSize?: number, userIdentity?: string, nodeIdentity?: string): Promise<IBlobStorageEntryList>;
86
84
  }
package/docs/changelog.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # @twin.org/blob-storage-service - Changelog
2
2
 
3
- ## v0.0.1-next.13
3
+ ## v0.0.1-next.15
4
4
 
5
5
  - Initial Release
@@ -144,12 +144,25 @@
144
144
  }
145
145
  },
146
146
  {
147
- "name": "sortProperties",
148
- "description": "The sort property array as JSON serialization of property,direction.",
147
+ "name": "orderBy",
148
+ "description": "The order for the results, default to created.",
149
149
  "in": "query",
150
150
  "required": false,
151
151
  "schema": {
152
- "type": "string"
152
+ "type": "string",
153
+ "enum": [
154
+ "dateCreated",
155
+ "dateModified"
156
+ ]
157
+ }
158
+ },
159
+ {
160
+ "name": "orderByDirection",
161
+ "description": "The direction for the order, defaults to desc.",
162
+ "in": "query",
163
+ "required": false,
164
+ "schema": {
165
+ "$ref": "#/components/schemas/SortDirection"
153
166
  }
154
167
  },
155
168
  {
@@ -2172,6 +2185,21 @@
2172
2185
  ],
2173
2186
  "description": "The body which contains the error."
2174
2187
  },
2188
+ "SortDirection": {
2189
+ "anyOf": [
2190
+ {
2191
+ "type": "string",
2192
+ "const": "asc",
2193
+ "description": "Ascending."
2194
+ },
2195
+ {
2196
+ "type": "string",
2197
+ "const": "desc",
2198
+ "description": "Descending."
2199
+ }
2200
+ ],
2201
+ "description": "The sort directions."
2202
+ },
2175
2203
  "Uint8Array": {
2176
2204
  "type": "object",
2177
2205
  "properties": {
@@ -228,7 +228,7 @@ Nothing.
228
228
 
229
229
  ### query()
230
230
 
231
- > **query**(`conditions`?, `sortProperties`?, `cursor`?, `pageSize`?, `userIdentity`?, `nodeIdentity`?): `Promise`\<`IBlobStorageEntryList`\>
231
+ > **query**(`conditions`?, `orderBy`?, `orderByDirection`?, `cursor`?, `pageSize`?, `userIdentity`?, `nodeIdentity`?): `Promise`\<`IBlobStorageEntryList`\>
232
232
 
233
233
  Query all the blob storage entries which match the conditions.
234
234
 
@@ -238,9 +238,13 @@ Query all the blob storage entries which match the conditions.
238
238
 
239
239
  The conditions to match for the entries.
240
240
 
241
- • **sortProperties?**: `object`[]
241
+ • **orderBy?**: `"dateCreated"` \| `"dateModified"`
242
242
 
243
- The optional sort order.
243
+ The order for the results, defaults to created.
244
+
245
+ • **orderByDirection?**: `SortDirection`
246
+
247
+ The direction for the order, defaults to descending.
244
248
 
245
249
  • **cursor?**: `string`
246
250
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/blob-storage-service",
3
- "version": "0.0.1-next.13",
3
+ "version": "0.0.1-next.15",
4
4
  "description": "Blob storage contract implementation and REST endpoint definitions",
5
5
  "repository": {
6
6
  "type": "git",
@@ -15,7 +15,7 @@
15
15
  },
16
16
  "dependencies": {
17
17
  "@twin.org/api-models": "next",
18
- "@twin.org/blob-storage-models": "0.0.1-next.13",
18
+ "@twin.org/blob-storage-models": "0.0.1-next.15",
19
19
  "@twin.org/core": "next",
20
20
  "@twin.org/data-json-ld": "next",
21
21
  "@twin.org/data-schema-org": "next",