dyna-record 0.6.7 → 0.7.0
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/README.md +23 -7
- package/dist/index.d.ts +12 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -22
- package/dist/src/DynaRecord.d.ts +3 -3
- package/dist/src/DynaRecord.d.ts.map +1 -1
- package/dist/src/DynaRecord.js +24 -59
- package/dist/src/Logger.js +1 -3
- package/dist/src/decorators/Entity.d.ts +1 -1
- package/dist/src/decorators/Entity.d.ts.map +1 -1
- package/dist/src/decorators/Entity.js +3 -8
- package/dist/src/decorators/Table.d.ts +2 -2
- package/dist/src/decorators/Table.d.ts.map +1 -1
- package/dist/src/decorators/Table.js +3 -8
- package/dist/src/decorators/attributes/BooleanAttribute.d.ts +2 -2
- package/dist/src/decorators/attributes/BooleanAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/BooleanAttribute.js +5 -10
- package/dist/src/decorators/attributes/DateAttribute.d.ts +2 -2
- package/dist/src/decorators/attributes/DateAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/DateAttribute.js +7 -12
- package/dist/src/decorators/attributes/EnumAttribute.d.ts +2 -2
- package/dist/src/decorators/attributes/EnumAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/EnumAttribute.js +5 -10
- package/dist/src/decorators/attributes/ForeignKeyAttribute.d.ts +3 -3
- package/dist/src/decorators/attributes/ForeignKeyAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/ForeignKeyAttribute.js +5 -10
- package/dist/src/decorators/attributes/IdAttribute.d.ts +1 -1
- package/dist/src/decorators/attributes/IdAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/IdAttribute.js +3 -8
- package/dist/src/decorators/attributes/NumberAttribute.d.ts +2 -2
- package/dist/src/decorators/attributes/NumberAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/NumberAttribute.js +5 -10
- package/dist/src/decorators/attributes/ObjectAttribute.d.ts +3 -3
- package/dist/src/decorators/attributes/ObjectAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/ObjectAttribute.js +16 -21
- package/dist/src/decorators/attributes/PartitionKeyAttribute.d.ts +3 -3
- package/dist/src/decorators/attributes/PartitionKeyAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/PartitionKeyAttribute.js +5 -10
- package/dist/src/decorators/attributes/SortKeyAttribute.d.ts +3 -3
- package/dist/src/decorators/attributes/SortKeyAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/SortKeyAttribute.js +5 -10
- package/dist/src/decorators/attributes/StringAttribute.d.ts +2 -2
- package/dist/src/decorators/attributes/StringAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/StringAttribute.js +5 -10
- package/dist/src/decorators/attributes/index.d.ts +13 -13
- package/dist/src/decorators/attributes/index.d.ts.map +1 -1
- package/dist/src/decorators/attributes/index.js +11 -41
- package/dist/src/decorators/attributes/serializers.d.ts +2 -2
- package/dist/src/decorators/attributes/serializers.d.ts.map +1 -1
- package/dist/src/decorators/attributes/serializers.js +5 -12
- package/dist/src/decorators/attributes/types.js +1 -2
- package/dist/src/decorators/index.d.ts +5 -5
- package/dist/src/decorators/index.d.ts.map +1 -1
- package/dist/src/decorators/index.js +5 -27
- package/dist/src/decorators/relationships/BelongsTo.d.ts +4 -4
- package/dist/src/decorators/relationships/BelongsTo.d.ts.map +1 -1
- package/dist/src/decorators/relationships/BelongsTo.js +3 -8
- package/dist/src/decorators/relationships/HasAndBelongsToMany.d.ts +3 -3
- package/dist/src/decorators/relationships/HasAndBelongsToMany.d.ts.map +1 -1
- package/dist/src/decorators/relationships/HasAndBelongsToMany.js +4 -9
- package/dist/src/decorators/relationships/HasMany.d.ts +3 -3
- package/dist/src/decorators/relationships/HasMany.d.ts.map +1 -1
- package/dist/src/decorators/relationships/HasMany.js +4 -9
- package/dist/src/decorators/relationships/HasOne.d.ts +3 -3
- package/dist/src/decorators/relationships/HasOne.d.ts.map +1 -1
- package/dist/src/decorators/relationships/HasOne.js +3 -8
- package/dist/src/decorators/relationships/index.d.ts +5 -5
- package/dist/src/decorators/relationships/index.d.ts.map +1 -1
- package/dist/src/decorators/relationships/index.js +5 -29
- package/dist/src/decorators/relationships/types.d.ts +3 -3
- package/dist/src/decorators/relationships/types.d.ts.map +1 -1
- package/dist/src/decorators/relationships/types.js +1 -2
- package/dist/src/decorators/types.d.ts +3 -3
- package/dist/src/decorators/types.d.ts.map +1 -1
- package/dist/src/decorators/types.js +1 -2
- package/dist/src/dynamo-utils/DynamoClient.d.ts +1 -1
- package/dist/src/dynamo-utils/DynamoClient.d.ts.map +1 -1
- package/dist/src/dynamo-utils/DynamoClient.js +13 -18
- package/dist/src/dynamo-utils/TransactGetBuilder.d.ts +1 -1
- package/dist/src/dynamo-utils/TransactGetBuilder.d.ts.map +1 -1
- package/dist/src/dynamo-utils/TransactGetBuilder.js +5 -10
- package/dist/src/dynamo-utils/TransactWriteBuilder.d.ts +1 -1
- package/dist/src/dynamo-utils/TransactWriteBuilder.d.ts.map +1 -1
- package/dist/src/dynamo-utils/TransactWriteBuilder.js +11 -16
- package/dist/src/dynamo-utils/errors.js +2 -7
- package/dist/src/dynamo-utils/index.d.ts +7 -7
- package/dist/src/dynamo-utils/index.d.ts.map +1 -1
- package/dist/src/dynamo-utils/index.js +7 -30
- package/dist/src/dynamo-utils/types.js +1 -2
- package/dist/src/errors.js +3 -9
- package/dist/src/id.d.ts +12 -0
- package/dist/src/id.d.ts.map +1 -0
- package/dist/src/id.js +11 -0
- package/dist/src/index.d.ts +8 -8
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -20
- package/dist/src/metadata/AttributeMetadata.d.ts +4 -4
- package/dist/src/metadata/AttributeMetadata.d.ts.map +1 -1
- package/dist/src/metadata/AttributeMetadata.js +1 -3
- package/dist/src/metadata/EntityMetadata.d.ts +3 -3
- package/dist/src/metadata/EntityMetadata.d.ts.map +1 -1
- package/dist/src/metadata/EntityMetadata.js +18 -23
- package/dist/src/metadata/JoinTableMetadata.d.ts +3 -3
- package/dist/src/metadata/JoinTableMetadata.d.ts.map +1 -1
- package/dist/src/metadata/JoinTableMetadata.js +1 -3
- package/dist/src/metadata/MetadataStorage.d.ts +7 -7
- package/dist/src/metadata/MetadataStorage.d.ts.map +1 -1
- package/dist/src/metadata/MetadataStorage.js +12 -17
- package/dist/src/metadata/TableMetadata.d.ts +3 -3
- package/dist/src/metadata/TableMetadata.d.ts.map +1 -1
- package/dist/src/metadata/TableMetadata.js +17 -20
- package/dist/src/metadata/index.d.ts +9 -9
- package/dist/src/metadata/index.d.ts.map +1 -1
- package/dist/src/metadata/index.js +11 -34
- package/dist/src/metadata/relationship-metadata/BelongsToRelationship.d.ts +2 -2
- package/dist/src/metadata/relationship-metadata/BelongsToRelationship.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/BelongsToRelationship.js +3 -8
- package/dist/src/metadata/relationship-metadata/HasAndBelongsToManyRelationship.d.ts +1 -1
- package/dist/src/metadata/relationship-metadata/HasAndBelongsToManyRelationship.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/HasAndBelongsToManyRelationship.js +3 -8
- package/dist/src/metadata/relationship-metadata/HasManyRelationship.d.ts +2 -2
- package/dist/src/metadata/relationship-metadata/HasManyRelationship.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/HasManyRelationship.js +3 -8
- package/dist/src/metadata/relationship-metadata/HasOneRelationship.d.ts +2 -2
- package/dist/src/metadata/relationship-metadata/HasOneRelationship.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/HasOneRelationship.js +3 -8
- package/dist/src/metadata/relationship-metadata/OwnedByRelationship.d.ts +2 -2
- package/dist/src/metadata/relationship-metadata/OwnedByRelationship.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/OwnedByRelationship.js +3 -8
- package/dist/src/metadata/relationship-metadata/RelationshipMetadata.d.ts +2 -2
- package/dist/src/metadata/relationship-metadata/RelationshipMetadata.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/RelationshipMetadata.js +1 -3
- package/dist/src/metadata/relationship-metadata/index.d.ts +6 -6
- package/dist/src/metadata/relationship-metadata/index.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/index.js +7 -31
- package/dist/src/metadata/relationship-metadata/types.d.ts +5 -5
- package/dist/src/metadata/relationship-metadata/types.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/types.js +1 -2
- package/dist/src/metadata/relationship-metadata/utils.d.ts +1 -1
- package/dist/src/metadata/relationship-metadata/utils.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/utils.js +11 -18
- package/dist/src/metadata/schemas.d.ts +3 -3
- package/dist/src/metadata/schemas.d.ts.map +1 -1
- package/dist/src/metadata/schemas.js +34 -37
- package/dist/src/metadata/types.d.ts +4 -4
- package/dist/src/metadata/types.d.ts.map +1 -1
- package/dist/src/metadata/types.js +1 -2
- package/dist/src/metadata/utils.d.ts +5 -5
- package/dist/src/metadata/utils.d.ts.map +1 -1
- package/dist/src/metadata/utils.js +14 -29
- package/dist/src/operations/Create/Create.d.ts +5 -5
- package/dist/src/operations/Create/Create.d.ts.map +1 -1
- package/dist/src/operations/Create/Create.js +18 -23
- package/dist/src/operations/Create/index.d.ts +2 -2
- package/dist/src/operations/Create/index.d.ts.map +1 -1
- package/dist/src/operations/Create/index.js +2 -23
- package/dist/src/operations/Create/types.d.ts +2 -2
- package/dist/src/operations/Create/types.d.ts.map +1 -1
- package/dist/src/operations/Create/types.js +1 -2
- package/dist/src/operations/Delete/Delete.d.ts +3 -3
- package/dist/src/operations/Delete/Delete.d.ts.map +1 -1
- package/dist/src/operations/Delete/Delete.js +28 -33
- package/dist/src/operations/Delete/index.d.ts +1 -1
- package/dist/src/operations/Delete/index.d.ts.map +1 -1
- package/dist/src/operations/Delete/index.js +1 -8
- package/dist/src/operations/Delete/types.js +1 -2
- package/dist/src/operations/FindById/FindById.d.ts +4 -4
- package/dist/src/operations/FindById/FindById.d.ts.map +1 -1
- package/dist/src/operations/FindById/FindById.js +17 -22
- package/dist/src/operations/FindById/index.d.ts +2 -2
- package/dist/src/operations/FindById/index.d.ts.map +1 -1
- package/dist/src/operations/FindById/index.js +2 -23
- package/dist/src/operations/FindById/types.d.ts +3 -3
- package/dist/src/operations/FindById/types.d.ts.map +1 -1
- package/dist/src/operations/FindById/types.js +1 -2
- package/dist/src/operations/OperationBase.d.ts +3 -3
- package/dist/src/operations/OperationBase.d.ts.map +1 -1
- package/dist/src/operations/OperationBase.js +4 -9
- package/dist/src/operations/Query/Query.d.ts +4 -4
- package/dist/src/operations/Query/Query.d.ts.map +1 -1
- package/dist/src/operations/Query/Query.js +15 -20
- package/dist/src/operations/Query/index.d.ts +2 -2
- package/dist/src/operations/Query/index.d.ts.map +1 -1
- package/dist/src/operations/Query/index.js +2 -23
- package/dist/src/operations/Query/types.d.ts +4 -4
- package/dist/src/operations/Query/types.d.ts.map +1 -1
- package/dist/src/operations/Query/types.js +1 -2
- package/dist/src/operations/Update/Update.d.ts +5 -5
- package/dist/src/operations/Update/Update.d.ts.map +1 -1
- package/dist/src/operations/Update/Update.js +37 -42
- package/dist/src/operations/Update/UpdateDryRun.d.ts +2 -2
- package/dist/src/operations/Update/UpdateDryRun.d.ts.map +1 -1
- package/dist/src/operations/Update/UpdateDryRun.js +3 -8
- package/dist/src/operations/Update/index.d.ts +3 -3
- package/dist/src/operations/Update/index.d.ts.map +1 -1
- package/dist/src/operations/Update/index.js +3 -25
- package/dist/src/operations/Update/types.d.ts +2 -2
- package/dist/src/operations/Update/types.d.ts.map +1 -1
- package/dist/src/operations/Update/types.js +1 -2
- package/dist/src/operations/index.d.ts +6 -6
- package/dist/src/operations/index.d.ts.map +1 -1
- package/dist/src/operations/index.js +6 -22
- package/dist/src/operations/types.d.ts +3 -3
- package/dist/src/operations/types.d.ts.map +1 -1
- package/dist/src/operations/types.js +1 -2
- package/dist/src/operations/utils/expressionBuilder.d.ts +2 -2
- package/dist/src/operations/utils/expressionBuilder.d.ts.map +1 -1
- package/dist/src/operations/utils/expressionBuilder.js +1 -5
- package/dist/src/operations/utils/flattenObjectForUpdate.d.ts +2 -2
- package/dist/src/operations/utils/flattenObjectForUpdate.d.ts.map +1 -1
- package/dist/src/operations/utils/flattenObjectForUpdate.js +3 -6
- package/dist/src/operations/utils/index.d.ts +5 -5
- package/dist/src/operations/utils/index.d.ts.map +1 -1
- package/dist/src/operations/utils/index.js +5 -21
- package/dist/src/operations/utils/mergePartialObjectAttributes.d.ts +1 -1
- package/dist/src/operations/utils/mergePartialObjectAttributes.d.ts.map +1 -1
- package/dist/src/operations/utils/mergePartialObjectAttributes.js +1 -4
- package/dist/src/operations/utils/types.js +1 -2
- package/dist/src/operations/utils/utils.d.ts +4 -4
- package/dist/src/operations/utils/utils.d.ts.map +1 -1
- package/dist/src/operations/utils/utils.js +13 -23
- package/dist/src/query-utils/Filters.d.ts +2 -2
- package/dist/src/query-utils/Filters.d.ts.map +1 -1
- package/dist/src/query-utils/Filters.js +1 -4
- package/dist/src/query-utils/QueryBuilder.d.ts +1 -1
- package/dist/src/query-utils/QueryBuilder.d.ts.map +1 -1
- package/dist/src/query-utils/QueryBuilder.js +8 -13
- package/dist/src/query-utils/index.d.ts +2 -2
- package/dist/src/query-utils/index.d.ts.map +1 -1
- package/dist/src/query-utils/index.js +2 -23
- package/dist/src/query-utils/types.js +1 -2
- package/dist/src/relationships/JoinTable.d.ts +2 -2
- package/dist/src/relationships/JoinTable.d.ts.map +1 -1
- package/dist/src/relationships/JoinTable.js +14 -19
- package/dist/src/relationships/index.d.ts +1 -1
- package/dist/src/relationships/index.d.ts.map +1 -1
- package/dist/src/relationships/index.js +1 -8
- package/dist/src/types.d.ts +2 -2
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js +1 -2
- package/dist/src/utils.d.ts +3 -3
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +16 -31
- package/package.json +28 -24
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type DynaRecord from "../../DynaRecord";
|
|
2
|
-
import type { EntityClass } from "../../types";
|
|
3
|
-
import OperationBase from "../OperationBase";
|
|
4
|
-
import type { CreateOptions, CreateOperationOptions } from "./types";
|
|
5
|
-
import { type EntityAttributesOnly } from "../types";
|
|
1
|
+
import type DynaRecord from "../../DynaRecord.js";
|
|
2
|
+
import type { EntityClass } from "../../types.js";
|
|
3
|
+
import OperationBase from "../OperationBase.js";
|
|
4
|
+
import type { CreateOptions, CreateOperationOptions } from "./types.js";
|
|
5
|
+
import { type EntityAttributesOnly } from "../types.js";
|
|
6
6
|
/**
|
|
7
7
|
* Represents an operation to create a new entity record in DynamoDB, including all necessary
|
|
8
8
|
* denormalized relationship records. This ensures that "BelongsTo" and "HasMany" relationships
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Create.d.ts","sourceRoot":"","sources":["../../../../src/operations/Create/Create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,
|
|
1
|
+
{"version":3,"file":"Create.d.ts","sourceRoot":"","sources":["../../../../src/operations/Create/Create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,qBAAqB,CAAC;AAElD,OAAO,KAAK,EAAmB,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAOnE,OAAO,aAAa,MAAM,qBAAqB,CAAC;AAKhD,OAAO,KAAK,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACxE,OAAO,EAGL,KAAK,oBAAoB,EAC1B,MAAM,aAAa,CAAC;AAIrB;;;;;;;;;;;;;;;;;GAiBG;AACH,cAAM,MAAM,CAAC,CAAC,SAAS,UAAU,CAAE,SAAQ,aAAa,CAAC,CAAC,CAAC;;gBAG7C,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IAKlC;;;;;;;;;;;;;;;;;OAiBG;IACU,GAAG,CACd,UAAU,EAAE,aAAa,CAAC,CAAC,CAAC,EAC5B,OAAO,CAAC,EAAE,sBAAsB,GAC/B,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC;IAuCnC;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,uBAAuB;IA8B/B;;;;;;;;;OASG;IACH,OAAO,CAAC,uBAAuB;IAiB/B;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,0BAA0B;IAqClC;;;;;;;OAOG;IACH,OAAO,CAAC,wCAAwC;IAkChD;;;;;;;;;;;OAWG;YACW,sBAAsB;IAmCpC;;;;;;;;;;OAUG;IACH,OAAO,CAAC,2CAA2C;IAmBnD;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,uCAAuC;CA0BhD;AAED,eAAe,MAAM,CAAC"}
|
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const dynamo_utils_1 = require("../../dynamo-utils");
|
|
8
|
-
const utils_1 = require("../../utils");
|
|
9
|
-
const OperationBase_1 = __importDefault(require("../OperationBase"));
|
|
10
|
-
const utils_2 = require("../utils");
|
|
11
|
-
const utils_3 = require("../../metadata/utils");
|
|
1
|
+
import { generateId } from "../../id.js";
|
|
2
|
+
import { TransactGetBuilder, TransactWriteBuilder } from "../../dynamo-utils/index.js";
|
|
3
|
+
import { entityToTableItem, isString, tableItemToEntity } from "../../utils.js";
|
|
4
|
+
import OperationBase from "../OperationBase.js";
|
|
5
|
+
import { extractForeignKeyFromEntity, buildBelongsToLinkKey } from "../utils/index.js";
|
|
6
|
+
import { isBelongsToRelationship } from "../../metadata/utils.js";
|
|
12
7
|
/**
|
|
13
8
|
* Represents an operation to create a new entity record in DynamoDB, including all necessary
|
|
14
9
|
* denormalized relationship records. This ensures that "BelongsTo" and "HasMany" relationships
|
|
@@ -27,11 +22,11 @@ const utils_3 = require("../../metadata/utils");
|
|
|
27
22
|
*
|
|
28
23
|
* @template T - The type of the entity being created, extending `DynaRecord`.
|
|
29
24
|
*/
|
|
30
|
-
class Create extends
|
|
25
|
+
class Create extends OperationBase {
|
|
31
26
|
#transactionBuilder;
|
|
32
27
|
constructor(Entity) {
|
|
33
28
|
super(Entity);
|
|
34
|
-
this.#transactionBuilder = new
|
|
29
|
+
this.#transactionBuilder = new TransactWriteBuilder();
|
|
35
30
|
}
|
|
36
31
|
/**
|
|
37
32
|
* Executes the create operation.
|
|
@@ -56,7 +51,7 @@ class Create extends OperationBase_1.default {
|
|
|
56
51
|
const entityAttrs = this.entityMetadata.parseRawEntityDefinedAttributes(attributes);
|
|
57
52
|
const reservedAttrs = this.buildReservedAttributes(entityAttrs);
|
|
58
53
|
const entityData = { ...reservedAttrs, ...entityAttrs };
|
|
59
|
-
const tableItem =
|
|
54
|
+
const tableItem = entityToTableItem(this.EntityClass, entityData);
|
|
60
55
|
this.buildPutItemTransaction(tableItem, entityData.id);
|
|
61
56
|
this.buildBelongsToTransactions(entityData, tableItem, referentialIntegrityCheck);
|
|
62
57
|
this.buildStandaloneForeignKeyConditionChecks(entityData, referentialIntegrityCheck);
|
|
@@ -67,7 +62,7 @@ class Create extends OperationBase_1.default {
|
|
|
67
62
|
this.buildAddBelongsToLinkToSelfTransactions(reservedAttrs.id, belongsToTableItems);
|
|
68
63
|
}
|
|
69
64
|
await this.#transactionBuilder.executeTransaction();
|
|
70
|
-
return
|
|
65
|
+
return tableItemToEntity(this.EntityClass, tableItem);
|
|
71
66
|
}
|
|
72
67
|
/**
|
|
73
68
|
* Builds and returns entity attributes that must be reserved for system usage.
|
|
@@ -84,7 +79,7 @@ class Create extends OperationBase_1.default {
|
|
|
84
79
|
buildReservedAttributes(entityAttrs) {
|
|
85
80
|
const { idField } = this.entityMetadata;
|
|
86
81
|
const id = idField === undefined
|
|
87
|
-
? (
|
|
82
|
+
? generateId()
|
|
88
83
|
: entityAttrs[idField];
|
|
89
84
|
const createdAt = new Date();
|
|
90
85
|
const pk = this.tableMetadata.partitionKeyAttribute.name;
|
|
@@ -136,13 +131,13 @@ class Create extends OperationBase_1.default {
|
|
|
136
131
|
const tableName = this.tableMetadata.name;
|
|
137
132
|
const relMetadata = this.entityMetadata.belongsToOrOwnedByRelationships;
|
|
138
133
|
for (const relMeta of relMetadata) {
|
|
139
|
-
const foreignKey =
|
|
134
|
+
const foreignKey = extractForeignKeyFromEntity(relMeta, entityData);
|
|
140
135
|
if (foreignKey != null) {
|
|
141
136
|
// Ensure referenced entity exists before linking
|
|
142
137
|
if (referentialIntegrityCheck) {
|
|
143
138
|
this.buildRelationshipExistsConditionTransaction(relMeta, foreignKey);
|
|
144
139
|
}
|
|
145
|
-
const key =
|
|
140
|
+
const key = buildBelongsToLinkKey(this.EntityClass, entityData.id, relMeta, foreignKey);
|
|
146
141
|
this.#transactionBuilder.addPut({
|
|
147
142
|
TableName: tableName,
|
|
148
143
|
Item: { ...tableItem, ...key },
|
|
@@ -167,7 +162,7 @@ class Create extends OperationBase_1.default {
|
|
|
167
162
|
for (const attrMeta of standaloneForeignKeys) {
|
|
168
163
|
const target = attrMeta.foreignKeyTarget;
|
|
169
164
|
const foreignKeyValue = entityData[attrMeta.name];
|
|
170
|
-
if (!
|
|
165
|
+
if (!isString(foreignKeyValue))
|
|
171
166
|
continue;
|
|
172
167
|
const foreignKey = foreignKeyValue;
|
|
173
168
|
const errMsg = `${target.name} with ID '${foreignKey}' does not exist`;
|
|
@@ -196,11 +191,11 @@ class Create extends OperationBase_1.default {
|
|
|
196
191
|
*/
|
|
197
192
|
async getBelongsToTableItems(entityData) {
|
|
198
193
|
const { name: tableName } = this.tableMetadata;
|
|
199
|
-
const transactionBuilder = new
|
|
194
|
+
const transactionBuilder = new TransactGetBuilder();
|
|
200
195
|
const relMetas = this.entityMetadata.relationships;
|
|
201
|
-
const belongsToRelMetas = Object.values(relMetas).filter(relMeta =>
|
|
196
|
+
const belongsToRelMetas = Object.values(relMetas).filter(relMeta => isBelongsToRelationship(relMeta));
|
|
202
197
|
belongsToRelMetas.forEach(relMeta => {
|
|
203
|
-
const fk =
|
|
198
|
+
const fk = extractForeignKeyFromEntity(relMeta, entityData);
|
|
204
199
|
if (fk != null) {
|
|
205
200
|
transactionBuilder.addGet({
|
|
206
201
|
TableName: tableName,
|
|
@@ -274,4 +269,4 @@ class Create extends OperationBase_1.default {
|
|
|
274
269
|
});
|
|
275
270
|
}
|
|
276
271
|
}
|
|
277
|
-
|
|
272
|
+
export default Create;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { default as Create } from "./Create";
|
|
2
|
-
export * from "./types";
|
|
1
|
+
export { default as Create } from "./Create.js";
|
|
2
|
+
export * from "./types.js";
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/operations/Create/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/operations/Create/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAC;AAChD,cAAc,YAAY,CAAC"}
|
|
@@ -1,23 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
-
};
|
|
19
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.Create = void 0;
|
|
21
|
-
var Create_1 = require("./Create");
|
|
22
|
-
Object.defineProperty(exports, "Create", { enumerable: true, get: function () { return __importDefault(Create_1).default; } });
|
|
23
|
-
__exportStar(require("./types"), exports);
|
|
1
|
+
export { default as Create } from "./Create.js";
|
|
2
|
+
export * from "./types.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/operations/Create/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/operations/Create/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAE3D;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;;;OAKG;IACH,yBAAyB,CAAC,EAAE,OAAO,CAAC;CACrC;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,UAAU,IAAI,uBAAuB,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type DynaRecord from "../../DynaRecord";
|
|
2
|
-
import type { EntityClass } from "../../types";
|
|
3
|
-
import OperationBase from "../OperationBase";
|
|
1
|
+
import type DynaRecord from "../../DynaRecord.js";
|
|
2
|
+
import type { EntityClass } from "../../types.js";
|
|
3
|
+
import OperationBase from "../OperationBase.js";
|
|
4
4
|
/**
|
|
5
5
|
* Implements the operation for deleting an entity and its related data from the database within the ORM framework.
|
|
6
6
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Delete.d.ts","sourceRoot":"","sources":["../../../../src/operations/Delete/Delete.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,
|
|
1
|
+
{"version":3,"file":"Delete.d.ts","sourceRoot":"","sources":["../../../../src/operations/Delete/Delete.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,qBAAqB,CAAC;AAYlD,OAAO,KAAK,EAEV,WAAW,EAEZ,MAAM,gBAAgB,CAAC;AAExB,OAAO,aAAa,MAAM,qBAAqB,CAAC;AA2BhD;;;;;;;;;GASG;AACH,cAAM,MAAM,CAAC,CAAC,SAAS,UAAU,CAAE,SAAQ,aAAa,CAAC,CAAC,CAAC;;gBAS7C,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IAiBlC;;;;;;;OAOG;IACU,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAgC3C;;;;OAIG;YACW,QAAQ;IAiCtB;;;;OAIG;IACH,OAAO,CAAC,iCAAiC;IASzC;;;OAGG;IACH,OAAO,CAAC,2BAA2B;IAOnC;;;OAGG;IACH,OAAO,CAAC,0BAA0B;IAalC;;;OAGG;IACH,OAAO,CAAC,4BAA4B;IAkBpC;;;;OAIG;YACW,iCAAiC;IA2B/C;;;;OAIG;IACH,OAAO,CAAC,uCAAuC;IAyB/C;;;OAGG;IACH,OAAO,CAAC,mCAAmC;IAiB3C;;;OAGG;IACH,OAAO,CAAC,+BAA+B;IAqBvC;;;OAGG;IACH,OAAO,CAAC,oBAAoB;IAI5B,OAAO,CAAC,cAAc;CAcvB;AAED,eAAe,MAAM,CAAC"}
|
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const utils_1 = require("../../metadata/utils");
|
|
10
|
-
const utils_2 = require("../../utils");
|
|
11
|
-
const OperationBase_1 = __importDefault(require("../OperationBase"));
|
|
12
|
-
const Update_1 = require("../Update");
|
|
13
|
-
const utils_3 = require("../utils");
|
|
1
|
+
import { TransactWriteBuilder, TransactionWriteFailedError } from "../../dynamo-utils/index.js";
|
|
2
|
+
import { NotFoundError, NullConstraintViolationError } from "../../errors.js";
|
|
3
|
+
import Metadata from "../../metadata/index.js";
|
|
4
|
+
import { isRelationshipMetadataWithForeignKey, isBelongsToRelationship, isHasAndBelongsToManyRelationship } from "../../metadata/utils.js";
|
|
5
|
+
import { isKeyOfObject } from "../../utils.js";
|
|
6
|
+
import OperationBase from "../OperationBase.js";
|
|
7
|
+
import { UpdateDryRun } from "../Update/index.js";
|
|
8
|
+
import { buildBelongsToLinkKey, buildEntityRelationshipMetaObj } from "../utils/index.js";
|
|
14
9
|
/**
|
|
15
10
|
* Implements the operation for deleting an entity and its related data from the database within the ORM framework.
|
|
16
11
|
*
|
|
@@ -21,7 +16,7 @@ const utils_3 = require("../utils");
|
|
|
21
16
|
*
|
|
22
17
|
* @template T - The type of the entity being deleted, extending `DynaRecord`.
|
|
23
18
|
*/
|
|
24
|
-
class Delete extends
|
|
19
|
+
class Delete extends OperationBase {
|
|
25
20
|
#transactionBuilder;
|
|
26
21
|
#tableName;
|
|
27
22
|
#partitionKeyField;
|
|
@@ -31,12 +26,12 @@ class Delete extends OperationBase_1.default {
|
|
|
31
26
|
#validationErrors = [];
|
|
32
27
|
constructor(Entity) {
|
|
33
28
|
super(Entity);
|
|
34
|
-
this.#transactionBuilder = new
|
|
29
|
+
this.#transactionBuilder = new TransactWriteBuilder();
|
|
35
30
|
const { name: tableName } = this.tableMetadata;
|
|
36
31
|
this.#tableName = tableName;
|
|
37
32
|
this.#partitionKeyField = this.tableMetadata.partitionKeyAttribute.name;
|
|
38
33
|
this.#sortKeyField = this.tableMetadata.sortKeyAttribute.name;
|
|
39
|
-
const relationsObj =
|
|
34
|
+
const relationsObj = buildEntityRelationshipMetaObj(Object.values(this.entityMetadata.relationships));
|
|
40
35
|
this.#relationsLookup = relationsObj.relationsLookup;
|
|
41
36
|
this.#belongsToRelationships = relationsObj.belongsToRelationships;
|
|
42
37
|
}
|
|
@@ -65,7 +60,7 @@ class Delete extends OperationBase_1.default {
|
|
|
65
60
|
await this.#transactionBuilder.executeTransaction();
|
|
66
61
|
}
|
|
67
62
|
else {
|
|
68
|
-
throw new
|
|
63
|
+
throw new TransactionWriteFailedError(this.#validationErrors, "Failed Validations");
|
|
69
64
|
}
|
|
70
65
|
}
|
|
71
66
|
/**
|
|
@@ -91,7 +86,7 @@ class Delete extends OperationBase_1.default {
|
|
|
91
86
|
return acc;
|
|
92
87
|
}, { linkedEntities: [], linkedEntitiesWithFkRef: [] });
|
|
93
88
|
if (prefetchResult.self === undefined) {
|
|
94
|
-
throw new
|
|
89
|
+
throw new NotFoundError(`Item does not exist: ${id}`);
|
|
95
90
|
}
|
|
96
91
|
return {
|
|
97
92
|
self: prefetchResult.self,
|
|
@@ -106,8 +101,8 @@ class Delete extends OperationBase_1.default {
|
|
|
106
101
|
*/
|
|
107
102
|
doesEntityNeedForeignKeyNullified(linkedEntity) {
|
|
108
103
|
const relMeta = this.#relationsLookup[linkedEntity.type];
|
|
109
|
-
return (!
|
|
110
|
-
|
|
104
|
+
return (!isBelongsToRelationship(relMeta) &&
|
|
105
|
+
isRelationshipMetadataWithForeignKey(relMeta));
|
|
111
106
|
}
|
|
112
107
|
/**
|
|
113
108
|
* Delete the entity and denormalized links from BelongsTo relationships
|
|
@@ -134,8 +129,8 @@ class Delete extends OperationBase_1.default {
|
|
|
134
129
|
* @param keys - The key to delete representing the entity keys, as opposed to the table keys
|
|
135
130
|
*/
|
|
136
131
|
buildDeleteEntityTransaction(keys, options) {
|
|
137
|
-
if (
|
|
138
|
-
|
|
132
|
+
if (isKeyOfObject(keys, this.#partitionKeyField) &&
|
|
133
|
+
isKeyOfObject(keys, this.#sortKeyField)) {
|
|
139
134
|
this.buildDeleteItemTransaction({
|
|
140
135
|
[this.partitionKeyAlias]: keys[this.#partitionKeyField],
|
|
141
136
|
[this.sortKeyAlias]: keys[this.#sortKeyField]
|
|
@@ -149,14 +144,14 @@ class Delete extends OperationBase_1.default {
|
|
|
149
144
|
*/
|
|
150
145
|
async buildNullifyForeignKeyTransaction(item) {
|
|
151
146
|
const relMeta = this.#relationsLookup[item.type];
|
|
152
|
-
if (
|
|
153
|
-
const entityAttrs =
|
|
147
|
+
if (isRelationshipMetadataWithForeignKey(relMeta)) {
|
|
148
|
+
const entityAttrs = Metadata.getEntityAttributes(relMeta.target.name);
|
|
154
149
|
const attrMeta = Object.values(entityAttrs).find(attr => attr.name === relMeta.foreignKey);
|
|
155
150
|
if (attrMeta?.nullable === false) {
|
|
156
|
-
this.trackValidationError(new
|
|
151
|
+
this.trackValidationError(new NullConstraintViolationError(`Cannot set ${relMeta.target.name} with id: '${item.id}' attribute '${relMeta.foreignKey}' to null`));
|
|
157
152
|
}
|
|
158
153
|
else {
|
|
159
|
-
const op = new
|
|
154
|
+
const op = new UpdateDryRun(relMeta.target, this.#transactionBuilder);
|
|
160
155
|
await op.run(item.id, { [relMeta.foreignKey]: null });
|
|
161
156
|
}
|
|
162
157
|
}
|
|
@@ -168,11 +163,11 @@ class Delete extends OperationBase_1.default {
|
|
|
168
163
|
*/
|
|
169
164
|
buildDeleteAssociatedBelongsTransaction(entityId, item) {
|
|
170
165
|
this.#belongsToRelationships.forEach(relMeta => {
|
|
171
|
-
if (
|
|
166
|
+
if (isKeyOfObject(item, relMeta.foreignKey)) {
|
|
172
167
|
const foreignKeyValue = item[relMeta.foreignKey];
|
|
173
168
|
if (foreignKeyValue === undefined)
|
|
174
169
|
return;
|
|
175
|
-
const belongsToLinksKeys =
|
|
170
|
+
const belongsToLinksKeys = buildBelongsToLinkKey(this.EntityClass, entityId, relMeta, foreignKeyValue);
|
|
176
171
|
this.buildDeleteItemTransaction(belongsToLinksKeys, {
|
|
177
172
|
errorMessage: `Failed to delete denormalized record with keys: ${JSON.stringify(belongsToLinksKeys)}`
|
|
178
173
|
});
|
|
@@ -185,7 +180,7 @@ class Delete extends OperationBase_1.default {
|
|
|
185
180
|
*/
|
|
186
181
|
buildDeleteJoinTableLinkTransaction(item) {
|
|
187
182
|
const relMeta = this.#relationsLookup[item.type];
|
|
188
|
-
if (
|
|
183
|
+
if (isHasAndBelongsToManyRelationship(relMeta)) {
|
|
189
184
|
const belongsToLinksKeys = this.buildKeyObject(item, this.#sortKeyField, this.#partitionKeyField);
|
|
190
185
|
this.buildDeleteEntityTransaction(belongsToLinksKeys, {
|
|
191
186
|
errorMessage: `Failed to delete denormalized record with keys: ${JSON.stringify(belongsToLinksKeys)}`
|
|
@@ -198,9 +193,9 @@ class Delete extends OperationBase_1.default {
|
|
|
198
193
|
*/
|
|
199
194
|
buildDeleteOwnedByRelationships(self) {
|
|
200
195
|
this.entityMetadata.ownedByRelationships.forEach(ownedByRelMeta => {
|
|
201
|
-
if (
|
|
196
|
+
if (isKeyOfObject(self, ownedByRelMeta.foreignKey)) {
|
|
202
197
|
const fkValue = self[ownedByRelMeta.foreignKey];
|
|
203
|
-
const keys =
|
|
198
|
+
const keys = buildBelongsToLinkKey(this.EntityClass, self.id, ownedByRelMeta, fkValue);
|
|
204
199
|
this.buildDeleteItemTransaction(keys, {
|
|
205
200
|
errorMessage: `Failed to delete denormalized record with keys: ${JSON.stringify(keys)}`
|
|
206
201
|
});
|
|
@@ -215,7 +210,7 @@ class Delete extends OperationBase_1.default {
|
|
|
215
210
|
this.#validationErrors.push(err);
|
|
216
211
|
}
|
|
217
212
|
buildKeyObject(item, pkField, skField) {
|
|
218
|
-
if (
|
|
213
|
+
if (isKeyOfObject(item, pkField) && isKeyOfObject(item, skField)) {
|
|
219
214
|
return {
|
|
220
215
|
[this.#partitionKeyField]: item[pkField],
|
|
221
216
|
[this.#sortKeyField]: item[skField]
|
|
@@ -224,4 +219,4 @@ class Delete extends OperationBase_1.default {
|
|
|
224
219
|
throw new Error("Invalid keys");
|
|
225
220
|
}
|
|
226
221
|
}
|
|
227
|
-
|
|
222
|
+
export default Delete;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default as Delete } from "./Delete";
|
|
1
|
+
export { default as Delete } from "./Delete.js";
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/operations/Delete/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/operations/Delete/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -1,8 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Delete = void 0;
|
|
7
|
-
var Delete_1 = require("./Delete");
|
|
8
|
-
Object.defineProperty(exports, "Delete", { enumerable: true, get: function () { return __importDefault(Delete_1).default; } });
|
|
1
|
+
export { default as Delete } from "./Delete.js";
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type DynaRecord from "../../DynaRecord";
|
|
2
|
-
import type { Optional } from "../../types";
|
|
3
|
-
import OperationBase from "../OperationBase";
|
|
4
|
-
import type { FindByIdOptions, FindByIdIncludesRes, IncludedAssociations } from "./types";
|
|
1
|
+
import type DynaRecord from "../../DynaRecord.js";
|
|
2
|
+
import type { Optional } from "../../types.js";
|
|
3
|
+
import OperationBase from "../OperationBase.js";
|
|
4
|
+
import type { FindByIdOptions, FindByIdIncludesRes, IncludedAssociations } from "./types.js";
|
|
5
5
|
/**
|
|
6
6
|
* Facilitates the retrieval of an entity by its identifier (ID) from the database, potentially including its associated entities based on specified relationships.
|
|
7
7
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FindById.d.ts","sourceRoot":"","sources":["../../../../src/operations/FindById/FindById.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,
|
|
1
|
+
{"version":3,"file":"FindById.d.ts","sourceRoot":"","sources":["../../../../src/operations/FindById/FindById.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,qBAAqB,CAAC;AAIlD,OAAO,KAAK,EAAE,QAAQ,EAAsB,MAAM,gBAAgB,CAAC;AAEnE,OAAO,aAAa,MAAM,qBAAqB,CAAC;AAChD,OAAO,KAAK,EACV,eAAe,EACf,mBAAmB,EACnB,oBAAoB,EAErB,MAAM,YAAY,CAAC;AAWpB;;;;;;GAMG;AACH,cAAM,QAAQ,CAAC,CAAC,SAAS,UAAU,CAAE,SAAQ,aAAa,CAAC,CAAC,CAAC;IAC3D;;;;;;;OAOG;IACU,GAAG,CAAC,GAAG,SAAS,oBAAoB,CAAC,CAAC,CAAC,GAAG,EAAE,EACvD,EAAE,EAAE,MAAM,EACV,OAAO,CAAC,EAAE,eAAe,CAAC,CAAC,EAAE,GAAG,CAAC,GAChC,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,mBAAmB,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;IAarD;;;;OAIG;YACW,YAAY;IAsB1B;;;;;;OAMG;YACW,oBAAoB;IAiClC;;;;;OAKG;IACH,OAAO,CAAC,kBAAkB;IAkB1B;;;;OAIG;IACH,OAAO,CAAC,wBAAwB;IAehC;;;;;;OAMG;IACH,OAAO,CAAC,8BAA8B;IA4BtC;;;;;;;OAOG;IACH,OAAO,CAAC,+BAA+B;CAaxC;AAED,eAAe,QAAQ,CAAC"}
|
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const dynamo_utils_1 = require("../../dynamo-utils");
|
|
8
|
-
const utils_1 = require("../../utils");
|
|
9
|
-
const OperationBase_1 = __importDefault(require("../OperationBase"));
|
|
10
|
-
const utils_2 = require("../utils");
|
|
11
|
-
const utils_3 = require("../../metadata/utils");
|
|
1
|
+
import { includedRelationshipsFilter } from "../../query-utils/Filters.js";
|
|
2
|
+
import { DynamoClient } from "../../dynamo-utils/index.js";
|
|
3
|
+
import { safeAssign, tableItemToEntity } from "../../utils.js";
|
|
4
|
+
import OperationBase from "../OperationBase.js";
|
|
5
|
+
import { buildEntityRelationshipMetaObj, consistentReadVal } from "../utils/index.js";
|
|
6
|
+
import { isHasAndBelongsToManyRelationship, isHasManyRelationship } from "../../metadata/utils.js";
|
|
12
7
|
/**
|
|
13
8
|
* Facilitates the retrieval of an entity by its identifier (ID) from the database, potentially including its associated entities based on specified relationships.
|
|
14
9
|
*
|
|
@@ -16,7 +11,7 @@ const utils_3 = require("../../metadata/utils");
|
|
|
16
11
|
*
|
|
17
12
|
* @template T - The type of the entity being retrieved, extending `DynaRecord`.
|
|
18
13
|
*/
|
|
19
|
-
class FindById extends
|
|
14
|
+
class FindById extends OperationBase {
|
|
20
15
|
/**
|
|
21
16
|
* Find an entity by Id and optionally include associations
|
|
22
17
|
* @param {string} id - Entity Id
|
|
@@ -45,19 +40,19 @@ class FindById extends OperationBase_1.default {
|
|
|
45
40
|
*/
|
|
46
41
|
async findByIdOnly(id, options) {
|
|
47
42
|
const { name: tableName } = this.tableMetadata;
|
|
48
|
-
const res = await
|
|
43
|
+
const res = await DynamoClient.getItem({
|
|
49
44
|
TableName: tableName,
|
|
50
45
|
Key: {
|
|
51
46
|
[this.partitionKeyAlias]: this.EntityClass.partitionKeyValue(id),
|
|
52
47
|
[this.sortKeyAlias]: this.EntityClass.name
|
|
53
48
|
},
|
|
54
|
-
ConsistentRead:
|
|
49
|
+
ConsistentRead: consistentReadVal(options.consistentRead)
|
|
55
50
|
});
|
|
56
51
|
if (res === undefined) {
|
|
57
52
|
return undefined;
|
|
58
53
|
}
|
|
59
54
|
else {
|
|
60
|
-
return
|
|
55
|
+
return tableItemToEntity(this.EntityClass, res);
|
|
61
56
|
}
|
|
62
57
|
}
|
|
63
58
|
/**
|
|
@@ -69,10 +64,10 @@ class FindById extends OperationBase_1.default {
|
|
|
69
64
|
*/
|
|
70
65
|
async findByIdWithIncludes(id, options) {
|
|
71
66
|
const includedRelMeta = this.getIncludedRelationships(options.includedAssociations);
|
|
72
|
-
const includedTypesFilter =
|
|
67
|
+
const includedTypesFilter = includedRelationshipsFilter(this.EntityClass.name, includedRelMeta);
|
|
73
68
|
const queryResults = await this.EntityClass.query(id, {
|
|
74
69
|
filter: includedTypesFilter,
|
|
75
|
-
consistentRead:
|
|
70
|
+
consistentRead: consistentReadVal(options.consistentRead)
|
|
76
71
|
});
|
|
77
72
|
if (queryResults.length === 0)
|
|
78
73
|
return undefined;
|
|
@@ -120,7 +115,7 @@ class FindById extends OperationBase_1.default {
|
|
|
120
115
|
* @returns
|
|
121
116
|
*/
|
|
122
117
|
resolveFindByIdIncludesResults(parentEntity, relatedEntities, includedRelMeta) {
|
|
123
|
-
const { relationsLookup } =
|
|
118
|
+
const { relationsLookup } = buildEntityRelationshipMetaObj(includedRelMeta);
|
|
124
119
|
this.setIncludedRelationshipDefaults(parentEntity, relationsLookup);
|
|
125
120
|
relatedEntities.forEach(entity => {
|
|
126
121
|
const rel = relationsLookup[entity.type];
|
|
@@ -146,11 +141,11 @@ class FindById extends OperationBase_1.default {
|
|
|
146
141
|
*/
|
|
147
142
|
setIncludedRelationshipDefaults(parentEntity, relationsLookup) {
|
|
148
143
|
Object.values(relationsLookup).forEach(rel => {
|
|
149
|
-
if (
|
|
150
|
-
|
|
151
|
-
|
|
144
|
+
if (isHasManyRelationship(rel) ||
|
|
145
|
+
isHasAndBelongsToManyRelationship(rel)) {
|
|
146
|
+
safeAssign(parentEntity, rel.propertyName, []);
|
|
152
147
|
}
|
|
153
148
|
});
|
|
154
149
|
}
|
|
155
150
|
}
|
|
156
|
-
|
|
151
|
+
export default FindById;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { default as FindById } from "./FindById";
|
|
2
|
-
export * from "./types";
|
|
1
|
+
export { default as FindById } from "./FindById.js";
|
|
2
|
+
export * from "./types.js";
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/operations/FindById/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/operations/FindById/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,eAAe,CAAC;AACpD,cAAc,YAAY,CAAC"}
|
|
@@ -1,23 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
-
};
|
|
19
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.FindById = void 0;
|
|
21
|
-
var FindById_1 = require("./FindById");
|
|
22
|
-
Object.defineProperty(exports, "FindById", { enumerable: true, get: function () { return __importDefault(FindById_1).default; } });
|
|
23
|
-
__exportStar(require("./types"), exports);
|
|
1
|
+
export { default as FindById } from "./FindById.js";
|
|
2
|
+
export * from "./types.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type DynaRecord from "../../DynaRecord";
|
|
2
|
-
import type { EntityAttributesInstance, EntityAttributesOnly, FunctionFields, RelationshipAttributeNames } from "../types";
|
|
3
|
-
import { type QueryResult, type QueryResults } from "../Query";
|
|
1
|
+
import type DynaRecord from "../../DynaRecord.js";
|
|
2
|
+
import type { EntityAttributesInstance, EntityAttributesOnly, FunctionFields, RelationshipAttributeNames } from "../types.js";
|
|
3
|
+
import { type QueryResult, type QueryResults } from "../Query/index.js";
|
|
4
4
|
/**
|
|
5
5
|
* An array of objects each describing an entity relationship association to include.
|
|
6
6
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/operations/FindById/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/operations/FindById/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EACV,wBAAwB,EACxB,oBAAoB,EACpB,cAAc,EACd,0BAA0B,EAC3B,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAExE;;GAEG;AACH,MAAM,MAAM,oBAAoB,CAAC,CAAC,SAAS,UAAU,IAAI,KAAK,CAAC;IAC7D,WAAW,EAAE,0BAA0B,CAAC,CAAC,CAAC,CAAC;CAC5C,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,WAAW,eAAe,CAC9B,CAAC,SAAS,UAAU,EACpB,GAAG,SAAS,oBAAoB,CAAC,CAAC,CAAC,GAAG,EAAE;IAExC,OAAO,CAAC,EAAE,GAAG,CAAC;IACd;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,EAAE,WAAW,CAAC,UAAU,CAAC,CAAC;IACjC,eAAe,EAAE,YAAY,CAAC,UAAU,CAAC,CAAC;CAC3C;AAED;;GAEG;AACH,KAAK,YAAY,CACf,CAAC,SAAS,UAAU,EACpB,GAAG,SAAS,oBAAoB,CAAC,CAAC,CAAC,GAAG,EAAE,IACtC,GAAG,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC,CAAC;AAE/B;;;GAGG;AACH,KAAK,kCAAkC,CACrC,CAAC,SAAS,UAAU,EACpB,CAAC,SAAS,MAAM,CAAC,IACf;KACD,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,UAAU,GAC7B,wBAAwB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAC9B,CAAC,CAAC,CAAC,CAAC,SAAS,UAAU,EAAE,GACvB,KAAK,CAAC,wBAAwB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAC7C,CAAC,CAAC,CAAC,CAAC,SAAS,UAAU,GAAG,SAAS,GACjC,wBAAwB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,GAAG,SAAS,GAC9D,CAAC,CAAC,CAAC,CAAC;CACb,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,CAC7B,CAAC,SAAS,UAAU,EACpB,GAAG,SAAS,oBAAoB,CAAC,CAAC,CAAC,GAAG,EAAE,IACtC,kCAAkC,CACpC,CAAC,EACD,MAAM,oBAAoB,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CACzE,CAAC"}
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type DynaRecord from "../DynaRecord";
|
|
2
|
-
import { type EntityMetadata, type TableMetadata } from "../metadata";
|
|
3
|
-
import type { EntityClass } from "../types";
|
|
1
|
+
import type DynaRecord from "../DynaRecord.js";
|
|
2
|
+
import { type EntityMetadata, type TableMetadata } from "../metadata/index.js";
|
|
3
|
+
import type { EntityClass } from "../types.js";
|
|
4
4
|
/**
|
|
5
5
|
* Serves as an abstract base class for various operation classes within the ORM system that perform actions on entities, such as creating, updating, querying, or deleting. This class provides shared properties and functionality that are common across different types of operations, centralizing the handling of entity and table metadata.
|
|
6
6
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OperationBase.d.ts","sourceRoot":"","sources":["../../../src/operations/OperationBase.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,
|
|
1
|
+
{"version":3,"file":"OperationBase.d.ts","sourceRoot":"","sources":["../../../src/operations/OperationBase.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAiB,EACf,KAAK,cAAc,EACnB,KAAK,aAAa,EACnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C;;;;;;;GAOG;AACH,uBAAe,aAAa,CAAC,CAAC,SAAS,UAAU;IAC/C;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IAE/C;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,cAAc,EAAE,cAAc,CAAC;IAElD;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IAEhD;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IAE7C;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;gBAE5B,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;aAQlB,GAAG,CAAC,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO;CACnD;AAED,eAAe,aAAa,CAAC"}
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const metadata_1 = __importDefault(require("../metadata"));
|
|
1
|
+
import Metadata from "../metadata/index.js";
|
|
7
2
|
/**
|
|
8
3
|
* Serves as an abstract base class for various operation classes within the ORM system that perform actions on entities, such as creating, updating, querying, or deleting. This class provides shared properties and functionality that are common across different types of operations, centralizing the handling of entity and table metadata.
|
|
9
4
|
*
|
|
@@ -35,10 +30,10 @@ class OperationBase {
|
|
|
35
30
|
sortKeyAlias;
|
|
36
31
|
constructor(Entity) {
|
|
37
32
|
this.EntityClass = Entity;
|
|
38
|
-
this.entityMetadata =
|
|
39
|
-
this.tableMetadata =
|
|
33
|
+
this.entityMetadata = Metadata.getEntity(Entity.name);
|
|
34
|
+
this.tableMetadata = Metadata.getTable(this.entityMetadata.tableClassName);
|
|
40
35
|
this.partitionKeyAlias = this.tableMetadata.partitionKeyAttribute.alias;
|
|
41
36
|
this.sortKeyAlias = this.tableMetadata.sortKeyAttribute.alias;
|
|
42
37
|
}
|
|
43
38
|
}
|
|
44
|
-
|
|
39
|
+
export default OperationBase;
|