@twin.org/entity-storage-service 0.0.1-next.5 → 0.0.1-next.7
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/cjs/index.cjs +39 -20
- package/dist/esm/index.mjs +40 -21
- package/dist/types/entityStorageService.d.ts +1 -4
- package/docs/changelog.md +1 -1
- package/docs/open-api/spec.json +81 -0
- package/docs/reference/classes/EntityStorageService.md +1 -1
- package/locales/en.json +5 -1
- package/package.json +2 -2
package/dist/cjs/index.cjs
CHANGED
@@ -96,6 +96,9 @@ function generateRestRoutesEntityStorage(baseRouteName, componentName, options)
|
|
96
96
|
}
|
97
97
|
}
|
98
98
|
]
|
99
|
+
},
|
100
|
+
{
|
101
|
+
type: "INotFoundResponse"
|
99
102
|
}
|
100
103
|
]
|
101
104
|
};
|
@@ -122,6 +125,9 @@ function generateRestRoutesEntityStorage(baseRouteName, componentName, options)
|
|
122
125
|
responseType: [
|
123
126
|
{
|
124
127
|
type: "INoContentResponse"
|
128
|
+
},
|
129
|
+
{
|
130
|
+
type: "INotFoundResponse"
|
125
131
|
}
|
126
132
|
]
|
127
133
|
};
|
@@ -273,12 +279,12 @@ class EntityStorageService {
|
|
273
279
|
core.Guards.object(this.CLASS_NAME, "entity", entity);
|
274
280
|
if (this._includeUserIdentity) {
|
275
281
|
core.Guards.stringValue(this.CLASS_NAME, "userIdentity", userIdentity);
|
282
|
+
core.ObjectHelper.propertySet(entity, "userIdentity", userIdentity);
|
276
283
|
}
|
277
284
|
if (this._includeNodeIdentity) {
|
278
285
|
core.Guards.stringValue(this.CLASS_NAME, "nodeIdentity", nodeIdentity);
|
286
|
+
core.ObjectHelper.propertySet(entity, "nodeIdentity", nodeIdentity);
|
279
287
|
}
|
280
|
-
entity.nodeIdentity = nodeIdentity;
|
281
|
-
entity.userIdentity = userIdentity;
|
282
288
|
return this._entityStorage.set(entity);
|
283
289
|
}
|
284
290
|
/**
|
@@ -317,10 +323,11 @@ class EntityStorageService {
|
|
317
323
|
}
|
318
324
|
if (conditions.length === 0) {
|
319
325
|
const entity = await this._entityStorage.get(id, secondaryIndex);
|
320
|
-
if (
|
321
|
-
|
322
|
-
delete entity.userIdentity;
|
326
|
+
if (core.Is.empty(entity)) {
|
327
|
+
throw new core.NotFoundError(this.CLASS_NAME, "entityNotFound", id);
|
323
328
|
}
|
329
|
+
core.ObjectHelper.propertyDelete(entity, "nodeIdentity");
|
330
|
+
core.ObjectHelper.propertyDelete(entity, "userIdentity");
|
324
331
|
return entity;
|
325
332
|
}
|
326
333
|
const results = await this._entityStorage.query({
|
@@ -328,8 +335,11 @@ class EntityStorageService {
|
|
328
335
|
logicalOperator: entity.LogicalOperator.And
|
329
336
|
}, undefined, undefined, undefined, 1);
|
330
337
|
const entity$1 = results.entities[0];
|
331
|
-
|
332
|
-
|
338
|
+
if (core.Is.empty(entity$1)) {
|
339
|
+
throw new core.NotFoundError(this.CLASS_NAME, "entityNotFound", id);
|
340
|
+
}
|
341
|
+
core.ObjectHelper.propertyDelete(entity$1, "nodeIdentity");
|
342
|
+
core.ObjectHelper.propertyDelete(entity$1, "userIdentity");
|
333
343
|
return entity$1;
|
334
344
|
}
|
335
345
|
/**
|
@@ -359,17 +369,26 @@ class EntityStorageService {
|
|
359
369
|
});
|
360
370
|
}
|
361
371
|
if (conditions.length === 0) {
|
362
|
-
|
372
|
+
const entity = await this._entityStorage.get(id);
|
373
|
+
if (core.Is.empty(entity)) {
|
374
|
+
throw new core.NotFoundError(this.CLASS_NAME, "entityNotFound", id);
|
375
|
+
}
|
376
|
+
await this._entityStorage.remove(id);
|
363
377
|
}
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
378
|
+
else {
|
379
|
+
const results = await this._entityStorage.query({
|
380
|
+
conditions,
|
381
|
+
logicalOperator: entity.LogicalOperator.And
|
382
|
+
}, undefined, undefined, undefined, 1);
|
383
|
+
if (results.entities.length > 0) {
|
384
|
+
const firstEntity = results.entities[0];
|
385
|
+
const schema = this._entityStorage.getSchema();
|
386
|
+
const primaryKey = entity.EntitySchemaHelper.getPrimaryKey(schema);
|
387
|
+
await this._entityStorage.remove(firstEntity[primaryKey.property]);
|
388
|
+
}
|
389
|
+
else {
|
390
|
+
throw new core.NotFoundError(this.CLASS_NAME, "entityNotFound", id);
|
391
|
+
}
|
373
392
|
}
|
374
393
|
}
|
375
394
|
/**
|
@@ -409,10 +428,10 @@ class EntityStorageService {
|
|
409
428
|
if (!core.Is.empty(conditions)) {
|
410
429
|
finalConditions.conditions.push(conditions);
|
411
430
|
}
|
412
|
-
const result = await this._entityStorage.query(finalConditions, sortProperties, properties, cursor, pageSize);
|
431
|
+
const result = await this._entityStorage.query(finalConditions.conditions.length > 0 ? finalConditions : undefined, sortProperties, properties, cursor, pageSize);
|
413
432
|
for (const entity of result.entities) {
|
414
|
-
|
415
|
-
|
433
|
+
core.ObjectHelper.propertyDelete(entity, "nodeIdentity");
|
434
|
+
core.ObjectHelper.propertyDelete(entity, "userIdentity");
|
416
435
|
}
|
417
436
|
return result;
|
418
437
|
}
|
package/dist/esm/index.mjs
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { HttpParameterHelper } from '@twin.org/api-models';
|
2
|
-
import { StringHelper, Guards, ComponentFactory, Coerce, Is } from '@twin.org/core';
|
2
|
+
import { StringHelper, Guards, ComponentFactory, Coerce, ObjectHelper, Is, NotFoundError } from '@twin.org/core';
|
3
3
|
import { HttpStatusCode } from '@twin.org/web';
|
4
4
|
import { ComparisonOperator, LogicalOperator, EntitySchemaHelper } from '@twin.org/entity';
|
5
5
|
import { EntityStorageConnectorFactory } from '@twin.org/entity-storage-models';
|
@@ -94,6 +94,9 @@ function generateRestRoutesEntityStorage(baseRouteName, componentName, options)
|
|
94
94
|
}
|
95
95
|
}
|
96
96
|
]
|
97
|
+
},
|
98
|
+
{
|
99
|
+
type: "INotFoundResponse"
|
97
100
|
}
|
98
101
|
]
|
99
102
|
};
|
@@ -120,6 +123,9 @@ function generateRestRoutesEntityStorage(baseRouteName, componentName, options)
|
|
120
123
|
responseType: [
|
121
124
|
{
|
122
125
|
type: "INoContentResponse"
|
126
|
+
},
|
127
|
+
{
|
128
|
+
type: "INotFoundResponse"
|
123
129
|
}
|
124
130
|
]
|
125
131
|
};
|
@@ -271,12 +277,12 @@ class EntityStorageService {
|
|
271
277
|
Guards.object(this.CLASS_NAME, "entity", entity);
|
272
278
|
if (this._includeUserIdentity) {
|
273
279
|
Guards.stringValue(this.CLASS_NAME, "userIdentity", userIdentity);
|
280
|
+
ObjectHelper.propertySet(entity, "userIdentity", userIdentity);
|
274
281
|
}
|
275
282
|
if (this._includeNodeIdentity) {
|
276
283
|
Guards.stringValue(this.CLASS_NAME, "nodeIdentity", nodeIdentity);
|
284
|
+
ObjectHelper.propertySet(entity, "nodeIdentity", nodeIdentity);
|
277
285
|
}
|
278
|
-
entity.nodeIdentity = nodeIdentity;
|
279
|
-
entity.userIdentity = userIdentity;
|
280
286
|
return this._entityStorage.set(entity);
|
281
287
|
}
|
282
288
|
/**
|
@@ -315,10 +321,11 @@ class EntityStorageService {
|
|
315
321
|
}
|
316
322
|
if (conditions.length === 0) {
|
317
323
|
const entity = await this._entityStorage.get(id, secondaryIndex);
|
318
|
-
if (
|
319
|
-
|
320
|
-
delete entity.userIdentity;
|
324
|
+
if (Is.empty(entity)) {
|
325
|
+
throw new NotFoundError(this.CLASS_NAME, "entityNotFound", id);
|
321
326
|
}
|
327
|
+
ObjectHelper.propertyDelete(entity, "nodeIdentity");
|
328
|
+
ObjectHelper.propertyDelete(entity, "userIdentity");
|
322
329
|
return entity;
|
323
330
|
}
|
324
331
|
const results = await this._entityStorage.query({
|
@@ -326,8 +333,11 @@ class EntityStorageService {
|
|
326
333
|
logicalOperator: LogicalOperator.And
|
327
334
|
}, undefined, undefined, undefined, 1);
|
328
335
|
const entity = results.entities[0];
|
329
|
-
|
330
|
-
|
336
|
+
if (Is.empty(entity)) {
|
337
|
+
throw new NotFoundError(this.CLASS_NAME, "entityNotFound", id);
|
338
|
+
}
|
339
|
+
ObjectHelper.propertyDelete(entity, "nodeIdentity");
|
340
|
+
ObjectHelper.propertyDelete(entity, "userIdentity");
|
331
341
|
return entity;
|
332
342
|
}
|
333
343
|
/**
|
@@ -357,17 +367,26 @@ class EntityStorageService {
|
|
357
367
|
});
|
358
368
|
}
|
359
369
|
if (conditions.length === 0) {
|
360
|
-
|
370
|
+
const entity = await this._entityStorage.get(id);
|
371
|
+
if (Is.empty(entity)) {
|
372
|
+
throw new NotFoundError(this.CLASS_NAME, "entityNotFound", id);
|
373
|
+
}
|
374
|
+
await this._entityStorage.remove(id);
|
361
375
|
}
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
376
|
+
else {
|
377
|
+
const results = await this._entityStorage.query({
|
378
|
+
conditions,
|
379
|
+
logicalOperator: LogicalOperator.And
|
380
|
+
}, undefined, undefined, undefined, 1);
|
381
|
+
if (results.entities.length > 0) {
|
382
|
+
const firstEntity = results.entities[0];
|
383
|
+
const schema = this._entityStorage.getSchema();
|
384
|
+
const primaryKey = EntitySchemaHelper.getPrimaryKey(schema);
|
385
|
+
await this._entityStorage.remove(firstEntity[primaryKey.property]);
|
386
|
+
}
|
387
|
+
else {
|
388
|
+
throw new NotFoundError(this.CLASS_NAME, "entityNotFound", id);
|
389
|
+
}
|
371
390
|
}
|
372
391
|
}
|
373
392
|
/**
|
@@ -407,10 +426,10 @@ class EntityStorageService {
|
|
407
426
|
if (!Is.empty(conditions)) {
|
408
427
|
finalConditions.conditions.push(conditions);
|
409
428
|
}
|
410
|
-
const result = await this._entityStorage.query(finalConditions, sortProperties, properties, cursor, pageSize);
|
429
|
+
const result = await this._entityStorage.query(finalConditions.conditions.length > 0 ? finalConditions : undefined, sortProperties, properties, cursor, pageSize);
|
411
430
|
for (const entity of result.entities) {
|
412
|
-
|
413
|
-
|
431
|
+
ObjectHelper.propertyDelete(entity, "nodeIdentity");
|
432
|
+
ObjectHelper.propertyDelete(entity, "userIdentity");
|
414
433
|
}
|
415
434
|
return result;
|
416
435
|
}
|
@@ -4,10 +4,7 @@ import type { IEntityStorageConfig } from "./models/IEntityStorageConfig";
|
|
4
4
|
/**
|
5
5
|
* Class for performing entity service operations.
|
6
6
|
*/
|
7
|
-
export declare class EntityStorageService<T
|
8
|
-
nodeIdentity?: string;
|
9
|
-
userIdentity?: string;
|
10
|
-
} = any> implements IEntityStorageComponent<T> {
|
7
|
+
export declare class EntityStorageService<T = any> implements IEntityStorageComponent<T> {
|
11
8
|
/**
|
12
9
|
* Runtime name for the class.
|
13
10
|
*/
|
package/docs/changelog.md
CHANGED
package/docs/open-api/spec.json
CHANGED
@@ -348,6 +348,27 @@
|
|
348
348
|
}
|
349
349
|
}
|
350
350
|
},
|
351
|
+
"404": {
|
352
|
+
"description": "The resource you tried to access does not exist, see the content for more details.",
|
353
|
+
"content": {
|
354
|
+
"application/json": {
|
355
|
+
"schema": {
|
356
|
+
"$ref": "#/components/schemas/NotFoundResponse"
|
357
|
+
},
|
358
|
+
"examples": {
|
359
|
+
"exampleResponse": {
|
360
|
+
"value": {
|
361
|
+
"name": "NotFoundError",
|
362
|
+
"message": "component.error",
|
363
|
+
"properties": {
|
364
|
+
"notFoundId": "1"
|
365
|
+
}
|
366
|
+
}
|
367
|
+
}
|
368
|
+
}
|
369
|
+
}
|
370
|
+
}
|
371
|
+
},
|
351
372
|
"500": {
|
352
373
|
"description": "The server has encountered a situation it does not know how to handle, see the content for more details.",
|
353
374
|
"content": {
|
@@ -435,6 +456,27 @@
|
|
435
456
|
}
|
436
457
|
}
|
437
458
|
},
|
459
|
+
"404": {
|
460
|
+
"description": "The resource you tried to access does not exist, see the content for more details.",
|
461
|
+
"content": {
|
462
|
+
"application/json": {
|
463
|
+
"schema": {
|
464
|
+
"$ref": "#/components/schemas/NotFoundResponse"
|
465
|
+
},
|
466
|
+
"examples": {
|
467
|
+
"exampleResponse": {
|
468
|
+
"value": {
|
469
|
+
"name": "NotFoundError",
|
470
|
+
"message": "component.error",
|
471
|
+
"properties": {
|
472
|
+
"notFoundId": "1"
|
473
|
+
}
|
474
|
+
}
|
475
|
+
}
|
476
|
+
}
|
477
|
+
}
|
478
|
+
}
|
479
|
+
},
|
438
480
|
"500": {
|
439
481
|
"description": "The server has encountered a situation it does not know how to handle, see the content for more details.",
|
440
482
|
"content": {
|
@@ -515,6 +557,45 @@
|
|
515
557
|
],
|
516
558
|
"additionalProperties": false,
|
517
559
|
"description": "Model to describe serialized error."
|
560
|
+
},
|
561
|
+
"NotFoundResponse": {
|
562
|
+
"type": "object",
|
563
|
+
"additionalProperties": false,
|
564
|
+
"properties": {
|
565
|
+
"notFoundId": {
|
566
|
+
"type": "string",
|
567
|
+
"description": "The id if the item that was not found."
|
568
|
+
},
|
569
|
+
"name": {
|
570
|
+
"type": "string",
|
571
|
+
"description": "The name for the error."
|
572
|
+
},
|
573
|
+
"message": {
|
574
|
+
"type": "string",
|
575
|
+
"description": "The message for the error."
|
576
|
+
},
|
577
|
+
"source": {
|
578
|
+
"type": "string",
|
579
|
+
"description": "The source of the error."
|
580
|
+
},
|
581
|
+
"properties": {
|
582
|
+
"type": "object",
|
583
|
+
"additionalProperties": {},
|
584
|
+
"description": "Any additional information for the error."
|
585
|
+
},
|
586
|
+
"stack": {
|
587
|
+
"type": "string",
|
588
|
+
"description": "The stack trace for the error."
|
589
|
+
},
|
590
|
+
"inner": {
|
591
|
+
"$ref": "#/components/schemas/Error"
|
592
|
+
}
|
593
|
+
},
|
594
|
+
"required": [
|
595
|
+
"message",
|
596
|
+
"name"
|
597
|
+
],
|
598
|
+
"description": "The body which contains the error."
|
518
599
|
}
|
519
600
|
},
|
520
601
|
"securitySchemes": {
|
package/locales/en.json
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@twin.org/entity-storage-service",
|
3
|
-
"version": "0.0.1-next.
|
3
|
+
"version": "0.0.1-next.7",
|
4
4
|
"description": "Entity Storage contract implementation 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.1-next.
|
20
|
+
"@twin.org/entity-storage-models": "0.0.1-next.7",
|
21
21
|
"@twin.org/nameof": "next",
|
22
22
|
"@twin.org/web": "next"
|
23
23
|
},
|