dyna-record 0.0.1
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 +3 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/src/DynaRecord.d.ts +216 -0
- package/dist/src/DynaRecord.d.ts.map +1 -0
- package/dist/src/DynaRecord.js +217 -0
- package/dist/src/Logger.d.ts +42 -0
- package/dist/src/Logger.d.ts.map +1 -0
- package/dist/src/Logger.js +57 -0
- package/dist/src/decorators/Entity.d.ts +23 -0
- package/dist/src/decorators/Entity.d.ts.map +1 -0
- package/dist/src/decorators/Entity.js +32 -0
- package/dist/src/decorators/Table.d.ts +22 -0
- package/dist/src/decorators/Table.d.ts.map +1 -0
- package/dist/src/decorators/Table.js +31 -0
- package/dist/src/decorators/attributes/Attribute.d.ts +26 -0
- package/dist/src/decorators/attributes/Attribute.d.ts.map +1 -0
- package/dist/src/decorators/attributes/Attribute.js +41 -0
- package/dist/src/decorators/attributes/DateAttribute.d.ts +25 -0
- package/dist/src/decorators/attributes/DateAttribute.d.ts.map +1 -0
- package/dist/src/decorators/attributes/DateAttribute.js +43 -0
- package/dist/src/decorators/attributes/DateNullableAttribute.d.ts +26 -0
- package/dist/src/decorators/attributes/DateNullableAttribute.d.ts.map +1 -0
- package/dist/src/decorators/attributes/DateNullableAttribute.js +43 -0
- package/dist/src/decorators/attributes/ForeignKeyAttribute.d.ts +25 -0
- package/dist/src/decorators/attributes/ForeignKeyAttribute.d.ts.map +1 -0
- package/dist/src/decorators/attributes/ForeignKeyAttribute.js +40 -0
- package/dist/src/decorators/attributes/NullableAttribute.d.ts +27 -0
- package/dist/src/decorators/attributes/NullableAttribute.d.ts.map +1 -0
- package/dist/src/decorators/attributes/NullableAttribute.js +41 -0
- package/dist/src/decorators/attributes/NullableForeignKeyAttribute.d.ts +25 -0
- package/dist/src/decorators/attributes/NullableForeignKeyAttribute.d.ts.map +1 -0
- package/dist/src/decorators/attributes/NullableForeignKeyAttribute.js +40 -0
- package/dist/src/decorators/attributes/PartitionKeyAttribute.d.ts +24 -0
- package/dist/src/decorators/attributes/PartitionKeyAttribute.d.ts.map +1 -0
- package/dist/src/decorators/attributes/PartitionKeyAttribute.js +38 -0
- package/dist/src/decorators/attributes/SortKeyAttribute.d.ts +24 -0
- package/dist/src/decorators/attributes/SortKeyAttribute.d.ts.map +1 -0
- package/dist/src/decorators/attributes/SortKeyAttribute.js +38 -0
- package/dist/src/decorators/attributes/index.d.ts +10 -0
- package/dist/src/decorators/attributes/index.d.ts.map +1 -0
- package/dist/src/decorators/attributes/index.js +37 -0
- package/dist/src/decorators/attributes/serializers.d.ts +13 -0
- package/dist/src/decorators/attributes/serializers.d.ts.map +1 -0
- package/dist/src/decorators/attributes/serializers.js +19 -0
- package/dist/src/decorators/index.d.ts +6 -0
- package/dist/src/decorators/index.d.ts.map +1 -0
- package/dist/src/decorators/index.js +27 -0
- package/dist/src/decorators/relationships/BelongsTo.d.ts +34 -0
- package/dist/src/decorators/relationships/BelongsTo.d.ts.map +1 -0
- package/dist/src/decorators/relationships/BelongsTo.js +50 -0
- package/dist/src/decorators/relationships/HasAndBelongsToMany.d.ts +80 -0
- package/dist/src/decorators/relationships/HasAndBelongsToMany.d.ts.map +1 -0
- package/dist/src/decorators/relationships/HasAndBelongsToMany.js +70 -0
- package/dist/src/decorators/relationships/HasMany.d.ts +35 -0
- package/dist/src/decorators/relationships/HasMany.d.ts.map +1 -0
- package/dist/src/decorators/relationships/HasMany.js +48 -0
- package/dist/src/decorators/relationships/HasOne.d.ts +35 -0
- package/dist/src/decorators/relationships/HasOne.d.ts.map +1 -0
- package/dist/src/decorators/relationships/HasOne.js +48 -0
- package/dist/src/decorators/relationships/index.d.ts +6 -0
- package/dist/src/decorators/relationships/index.d.ts.map +1 -0
- package/dist/src/decorators/relationships/index.js +29 -0
- package/dist/src/decorators/relationships/types.d.ts +11 -0
- package/dist/src/decorators/relationships/types.d.ts.map +1 -0
- package/dist/src/decorators/relationships/types.js +2 -0
- package/dist/src/decorators/types.d.ts +30 -0
- package/dist/src/decorators/types.d.ts.map +1 -0
- package/dist/src/decorators/types.js +2 -0
- package/dist/src/dynamo-utils/DynamoClient.d.ts +34 -0
- package/dist/src/dynamo-utils/DynamoClient.d.ts.map +1 -0
- package/dist/src/dynamo-utils/DynamoClient.js +57 -0
- package/dist/src/dynamo-utils/TransactGetBuilder.d.ts +18 -0
- package/dist/src/dynamo-utils/TransactGetBuilder.d.ts.map +1 -0
- package/dist/src/dynamo-utils/TransactGetBuilder.js +32 -0
- package/dist/src/dynamo-utils/TransactWriteBuilder.d.ts +46 -0
- package/dist/src/dynamo-utils/TransactWriteBuilder.d.ts.map +1 -0
- package/dist/src/dynamo-utils/TransactWriteBuilder.js +100 -0
- package/dist/src/dynamo-utils/errors.d.ts +13 -0
- package/dist/src/dynamo-utils/errors.d.ts.map +1 -0
- package/dist/src/dynamo-utils/errors.js +17 -0
- package/dist/src/dynamo-utils/index.d.ts +8 -0
- package/dist/src/dynamo-utils/index.d.ts.map +1 -0
- package/dist/src/dynamo-utils/index.js +30 -0
- package/dist/src/dynamo-utils/types.d.ts +52 -0
- package/dist/src/dynamo-utils/types.d.ts.map +1 -0
- package/dist/src/dynamo-utils/types.js +2 -0
- package/dist/src/errors.d.ts +13 -0
- package/dist/src/errors.d.ts.map +1 -0
- package/dist/src/errors.js +17 -0
- package/dist/src/index.d.ts +6 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +24 -0
- package/dist/src/metadata/AttributeMetadata.d.ts +22 -0
- package/dist/src/metadata/AttributeMetadata.d.ts.map +1 -0
- package/dist/src/metadata/AttributeMetadata.js +27 -0
- package/dist/src/metadata/EntityMetadata.d.ts +42 -0
- package/dist/src/metadata/EntityMetadata.d.ts.map +1 -0
- package/dist/src/metadata/EntityMetadata.js +49 -0
- package/dist/src/metadata/JoinTableMetadata.d.ts +23 -0
- package/dist/src/metadata/JoinTableMetadata.d.ts.map +1 -0
- package/dist/src/metadata/JoinTableMetadata.js +22 -0
- package/dist/src/metadata/MetadataStorage.d.ts +104 -0
- package/dist/src/metadata/MetadataStorage.d.ts.map +1 -0
- package/dist/src/metadata/MetadataStorage.js +194 -0
- package/dist/src/metadata/TableMetadata.d.ts +53 -0
- package/dist/src/metadata/TableMetadata.d.ts.map +1 -0
- package/dist/src/metadata/TableMetadata.js +100 -0
- package/dist/src/metadata/index.d.ts +13 -0
- package/dist/src/metadata/index.d.ts.map +1 -0
- package/dist/src/metadata/index.js +34 -0
- package/dist/src/metadata/relationship-metadata/BelongsToRelationship.d.ts +18 -0
- package/dist/src/metadata/relationship-metadata/BelongsToRelationship.d.ts.map +1 -0
- package/dist/src/metadata/relationship-metadata/BelongsToRelationship.js +26 -0
- package/dist/src/metadata/relationship-metadata/HasAndBelongsToManyRelationship.d.ts +16 -0
- package/dist/src/metadata/relationship-metadata/HasAndBelongsToManyRelationship.d.ts.map +1 -0
- package/dist/src/metadata/relationship-metadata/HasAndBelongsToManyRelationship.js +25 -0
- package/dist/src/metadata/relationship-metadata/HasManyRelationship.d.ts +18 -0
- package/dist/src/metadata/relationship-metadata/HasManyRelationship.d.ts.map +1 -0
- package/dist/src/metadata/relationship-metadata/HasManyRelationship.js +26 -0
- package/dist/src/metadata/relationship-metadata/HasOneRelationship.d.ts +17 -0
- package/dist/src/metadata/relationship-metadata/HasOneRelationship.d.ts.map +1 -0
- package/dist/src/metadata/relationship-metadata/HasOneRelationship.js +25 -0
- package/dist/src/metadata/relationship-metadata/RelationshipMetadata.d.ts +21 -0
- package/dist/src/metadata/relationship-metadata/RelationshipMetadata.d.ts.map +1 -0
- package/dist/src/metadata/relationship-metadata/RelationshipMetadata.js +18 -0
- package/dist/src/metadata/relationship-metadata/index.d.ts +7 -0
- package/dist/src/metadata/relationship-metadata/index.d.ts.map +1 -0
- package/dist/src/metadata/relationship-metadata/index.js +29 -0
- package/dist/src/metadata/relationship-metadata/types.d.ts +16 -0
- package/dist/src/metadata/relationship-metadata/types.d.ts.map +1 -0
- package/dist/src/metadata/relationship-metadata/types.js +2 -0
- package/dist/src/metadata/relationship-metadata/utils.d.ts +3 -0
- package/dist/src/metadata/relationship-metadata/utils.d.ts.map +1 -0
- package/dist/src/metadata/relationship-metadata/utils.js +25 -0
- package/dist/src/metadata/types.d.ts +90 -0
- package/dist/src/metadata/types.d.ts.map +1 -0
- package/dist/src/metadata/types.js +2 -0
- package/dist/src/metadata/utils.d.ts +42 -0
- package/dist/src/metadata/utils.d.ts.map +1 -0
- package/dist/src/metadata/utils.js +67 -0
- package/dist/src/operations/Create/Create.d.ts +39 -0
- package/dist/src/operations/Create/Create.d.ts.map +1 -0
- package/dist/src/operations/Create/Create.js +84 -0
- package/dist/src/operations/Create/index.d.ts +3 -0
- package/dist/src/operations/Create/index.d.ts.map +1 -0
- package/dist/src/operations/Create/index.js +23 -0
- package/dist/src/operations/Create/types.d.ts +7 -0
- package/dist/src/operations/Create/types.d.ts.map +1 -0
- package/dist/src/operations/Create/types.js +2 -0
- package/dist/src/operations/Delete/Delete.d.ts +74 -0
- package/dist/src/operations/Delete/Delete.d.ts.map +1 -0
- package/dist/src/operations/Delete/Delete.js +207 -0
- package/dist/src/operations/Delete/index.d.ts +2 -0
- package/dist/src/operations/Delete/index.d.ts.map +1 -0
- package/dist/src/operations/Delete/index.js +8 -0
- package/dist/src/operations/Delete/types.d.ts +7 -0
- package/dist/src/operations/Delete/types.d.ts.map +1 -0
- package/dist/src/operations/Delete/types.js +2 -0
- package/dist/src/operations/FindById/FindById.d.ts +91 -0
- package/dist/src/operations/FindById/FindById.d.ts.map +1 -0
- package/dist/src/operations/FindById/FindById.js +244 -0
- package/dist/src/operations/FindById/index.d.ts +3 -0
- package/dist/src/operations/FindById/index.d.ts.map +1 -0
- package/dist/src/operations/FindById/index.js +23 -0
- package/dist/src/operations/FindById/types.d.ts +57 -0
- package/dist/src/operations/FindById/types.d.ts.map +1 -0
- package/dist/src/operations/FindById/types.js +2 -0
- package/dist/src/operations/OperationBase.d.ts +37 -0
- package/dist/src/operations/OperationBase.d.ts.map +1 -0
- package/dist/src/operations/OperationBase.js +44 -0
- package/dist/src/operations/Query/Query.d.ts +45 -0
- package/dist/src/operations/Query/Query.d.ts.map +1 -0
- package/dist/src/operations/Query/Query.js +84 -0
- package/dist/src/operations/Query/index.d.ts +3 -0
- package/dist/src/operations/Query/index.d.ts.map +1 -0
- package/dist/src/operations/Query/index.js +23 -0
- package/dist/src/operations/Query/types.d.ts +38 -0
- package/dist/src/operations/Query/types.d.ts.map +1 -0
- package/dist/src/operations/Query/types.js +2 -0
- package/dist/src/operations/Update/Update.d.ts +48 -0
- package/dist/src/operations/Update/Update.d.ts.map +1 -0
- package/dist/src/operations/Update/Update.js +118 -0
- package/dist/src/operations/Update/index.d.ts +3 -0
- package/dist/src/operations/Update/index.d.ts.map +1 -0
- package/dist/src/operations/Update/index.js +23 -0
- package/dist/src/operations/Update/types.d.ts +32 -0
- package/dist/src/operations/Update/types.d.ts.map +1 -0
- package/dist/src/operations/Update/types.js +2 -0
- package/dist/src/operations/index.d.ts +7 -0
- package/dist/src/operations/index.d.ts.map +1 -0
- package/dist/src/operations/index.js +22 -0
- package/dist/src/operations/types.d.ts +59 -0
- package/dist/src/operations/types.d.ts.map +1 -0
- package/dist/src/operations/types.js +2 -0
- package/dist/src/operations/utils/RelationshipTransactions.d.ts +64 -0
- package/dist/src/operations/utils/RelationshipTransactions.d.ts.map +1 -0
- package/dist/src/operations/utils/RelationshipTransactions.js +125 -0
- package/dist/src/operations/utils/expressionBuilder.d.ts +9 -0
- package/dist/src/operations/utils/expressionBuilder.d.ts.map +1 -0
- package/dist/src/operations/utils/expressionBuilder.js +106 -0
- package/dist/src/operations/utils/index.d.ts +5 -0
- package/dist/src/operations/utils/index.d.ts.map +1 -0
- package/dist/src/operations/utils/index.js +25 -0
- package/dist/src/operations/utils/types.d.ts +21 -0
- package/dist/src/operations/utils/types.d.ts.map +1 -0
- package/dist/src/operations/utils/types.js +2 -0
- package/dist/src/operations/utils/utils.d.ts +19 -0
- package/dist/src/operations/utils/utils.d.ts.map +1 -0
- package/dist/src/operations/utils/utils.js +36 -0
- package/dist/src/query-utils/Filters.d.ts +10 -0
- package/dist/src/query-utils/Filters.d.ts.map +1 -0
- package/dist/src/query-utils/Filters.js +25 -0
- package/dist/src/query-utils/QueryBuilder.d.ts +90 -0
- package/dist/src/query-utils/QueryBuilder.d.ts.map +1 -0
- package/dist/src/query-utils/QueryBuilder.js +213 -0
- package/dist/src/query-utils/index.d.ts +3 -0
- package/dist/src/query-utils/index.d.ts.map +1 -0
- package/dist/src/query-utils/index.js +23 -0
- package/dist/src/query-utils/types.d.ts +89 -0
- package/dist/src/query-utils/types.d.ts.map +1 -0
- package/dist/src/query-utils/types.js +2 -0
- package/dist/src/relationships/BelongsToLink.d.ts +50 -0
- package/dist/src/relationships/BelongsToLink.d.ts.map +1 -0
- package/dist/src/relationships/BelongsToLink.js +57 -0
- package/dist/src/relationships/JoinTable.d.ts +68 -0
- package/dist/src/relationships/JoinTable.d.ts.map +1 -0
- package/dist/src/relationships/JoinTable.js +133 -0
- package/dist/src/relationships/index.d.ts +3 -0
- package/dist/src/relationships/index.d.ts.map +1 -0
- package/dist/src/relationships/index.js +10 -0
- package/dist/src/types.d.ts +73 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +2 -0
- package/dist/src/utils.d.ts +89 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +168 -0
- package/package.json +61 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
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 uuid_1 = require("uuid");
|
|
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
|
+
/**
|
|
12
|
+
* Represents the operation for creating a new entity in the database, including handling its attributes and any related entities' associations. It will handle de-normalizing data to support relationships
|
|
13
|
+
*
|
|
14
|
+
* It encapsulates the logic required to translate entity attributes to a format suitable for DynamoDB, execute the creation transaction, and manage any relationships defined by the entity, such as "BelongsTo" or "HasMany" links.
|
|
15
|
+
*
|
|
16
|
+
* @template T - The type of the entity being created, extending `DynaRecord`.
|
|
17
|
+
*/
|
|
18
|
+
class Create extends OperationBase_1.default {
|
|
19
|
+
#transactionBuilder;
|
|
20
|
+
constructor(Entity) {
|
|
21
|
+
super(Entity);
|
|
22
|
+
this.#transactionBuilder = new dynamo_utils_1.TransactWriteBuilder();
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Create an entity transaction, including relationship transactions (EX: Creating BelongsToLinks for HasMany, checking existence of relationships, etc)
|
|
26
|
+
* @param attributes
|
|
27
|
+
* @returns
|
|
28
|
+
*/
|
|
29
|
+
async run(attributes) {
|
|
30
|
+
const entityData = this.buildEntityData(attributes);
|
|
31
|
+
const tableItem = (0, utils_1.entityToTableItem)(this.EntityClass, entityData);
|
|
32
|
+
this.buildPutItemTransaction(tableItem);
|
|
33
|
+
await this.buildRelationshipTransactions(entityData);
|
|
34
|
+
await this.#transactionBuilder.executeTransaction();
|
|
35
|
+
return (0, utils_1.tableItemToEntity)(this.EntityClass, tableItem);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Builds the entity attributes
|
|
39
|
+
* @param attributes
|
|
40
|
+
* @returns
|
|
41
|
+
*/
|
|
42
|
+
buildEntityData(attributes) {
|
|
43
|
+
const id = (0, uuid_1.v4)();
|
|
44
|
+
const createdAt = new Date();
|
|
45
|
+
const pk = this.tableMetadata.partitionKeyAttribute.name;
|
|
46
|
+
const sk = this.tableMetadata.sortKeyAttribute.name;
|
|
47
|
+
const keys = {
|
|
48
|
+
[pk]: this.EntityClass.partitionKeyValue(id),
|
|
49
|
+
[sk]: this.EntityClass.name
|
|
50
|
+
};
|
|
51
|
+
const defaultAttrs = {
|
|
52
|
+
id,
|
|
53
|
+
type: this.EntityClass.name,
|
|
54
|
+
createdAt,
|
|
55
|
+
updatedAt: createdAt
|
|
56
|
+
};
|
|
57
|
+
return { ...keys, ...attributes, ...defaultAttrs };
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Build the transaction for the parent entity Create item request
|
|
61
|
+
* @param tableItem
|
|
62
|
+
*/
|
|
63
|
+
buildPutItemTransaction(tableItem) {
|
|
64
|
+
const { name: tableName } = this.tableMetadata;
|
|
65
|
+
const putExpression = {
|
|
66
|
+
TableName: tableName,
|
|
67
|
+
Item: tableItem,
|
|
68
|
+
ConditionExpression: `attribute_not_exists(${this.partitionKeyAlias})` // Ensure item doesn't already exist
|
|
69
|
+
};
|
|
70
|
+
this.#transactionBuilder.addPut(putExpression);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Build transaction items for associations
|
|
74
|
+
* @param entityData
|
|
75
|
+
*/
|
|
76
|
+
async buildRelationshipTransactions(entityData) {
|
|
77
|
+
const relationshipTransactions = new utils_2.RelationshipTransactions({
|
|
78
|
+
Entity: this.EntityClass,
|
|
79
|
+
transactionBuilder: this.#transactionBuilder
|
|
80
|
+
});
|
|
81
|
+
await relationshipTransactions.build(entityData);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.default = Create;
|
|
@@ -0,0 +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,UAAU,CAAC;AAC7C,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
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);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type DynaRecord from "../../DynaRecord";
|
|
2
|
+
import type { EntityDefinedAttributes } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* Entity attribute fields that can be set on create. Excludes that are managed by dyna-record
|
|
5
|
+
*/
|
|
6
|
+
export type CreateOptions<T extends DynaRecord> = EntityDefinedAttributes<T>;
|
|
7
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/operations/Create/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAExD;;GAEG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,UAAU,IAAI,uBAAuB,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import DynaRecord from "../../DynaRecord";
|
|
2
|
+
import type { EntityClass } from "../../types";
|
|
3
|
+
import OperationBase from "../OperationBase";
|
|
4
|
+
/**
|
|
5
|
+
* Implements the operation for deleting an entity and its related data from the database within the ORM framework.
|
|
6
|
+
*
|
|
7
|
+
* Delete an entity, everything in its partition, BelongsToLinks and nullifies ForeignKeys on attributes that BelongTo it
|
|
8
|
+
* If the foreign key is non nullable than it will throw a NullConstraintViolationError
|
|
9
|
+
*
|
|
10
|
+
* The `Delete` operation supports complex scenarios, such as deleting related entities in "BelongsTo" relationships, nullifying or removing foreign keys to maintain data integrity, and handling many-to-many relationships through join tables.
|
|
11
|
+
*
|
|
12
|
+
* @template T - The type of the entity being deleted, extending `DynaRecord`.
|
|
13
|
+
*/
|
|
14
|
+
declare class Delete<T extends DynaRecord> extends OperationBase<T> {
|
|
15
|
+
#private;
|
|
16
|
+
constructor(Entity: EntityClass<T>);
|
|
17
|
+
/**
|
|
18
|
+
* Delete an item by id
|
|
19
|
+
* - Deletes the given entity
|
|
20
|
+
* - Deletes each item in the entity's partition
|
|
21
|
+
* - For each item in the entity's partition which is of type 'BelongsToLink' it:
|
|
22
|
+
* - Will nullify the associated relationship's ForeignKey attribute if the attribute is nullable
|
|
23
|
+
* @param id
|
|
24
|
+
*/
|
|
25
|
+
run(id: string): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Deletes an item
|
|
28
|
+
* @param item
|
|
29
|
+
*/
|
|
30
|
+
private buildDeleteItemTransaction;
|
|
31
|
+
/**
|
|
32
|
+
* If the item has a JoinTable entry (is part of HasAndBelongsToMany relationship) then delete both JoinTable entries
|
|
33
|
+
* @param item - BelongsToLink from HasAndBelongsToMany relationship
|
|
34
|
+
*/
|
|
35
|
+
private buildDeleteJoinTableLinkTransaction;
|
|
36
|
+
/**
|
|
37
|
+
* If the item being deleted has a foreign key reference, nullify the associated relationship's ForeignKey attribute
|
|
38
|
+
* If the ForeignKey is non nullable than it throws a NullConstraintViolationError
|
|
39
|
+
* @param item
|
|
40
|
+
*/
|
|
41
|
+
private buildNullifyForeignKeyTransaction;
|
|
42
|
+
/**
|
|
43
|
+
* Deletes associated BelongsTo relationships for each ForeignKey of the item being deleted
|
|
44
|
+
* @param entityId
|
|
45
|
+
* @param item
|
|
46
|
+
*/
|
|
47
|
+
private buildDeleteAssociatedBelongsTransaction;
|
|
48
|
+
/**
|
|
49
|
+
* Deletes associated BelongsToLink for a BelongsTo HasMany relationship
|
|
50
|
+
* @param relMeta
|
|
51
|
+
* @param entityId
|
|
52
|
+
* @param foreignKeyValue
|
|
53
|
+
*/
|
|
54
|
+
private buildDeleteBelongsToHasManyTransaction;
|
|
55
|
+
/**
|
|
56
|
+
* Deletes associated BelongsToLink for a BelongsTo HasOne relationship
|
|
57
|
+
* @param relMeta
|
|
58
|
+
* @param foreignKeyValue
|
|
59
|
+
*/
|
|
60
|
+
private buildDeleteBelongsToHasOneTransaction;
|
|
61
|
+
/**
|
|
62
|
+
* Type guard to check if the item being evaluated is the currentClass
|
|
63
|
+
* @param item
|
|
64
|
+
* @returns
|
|
65
|
+
*/
|
|
66
|
+
private isEntityClass;
|
|
67
|
+
/**
|
|
68
|
+
* Track validation errors and throw AggregateError after all validations have been run
|
|
69
|
+
* @param err
|
|
70
|
+
*/
|
|
71
|
+
private trackValidationError;
|
|
72
|
+
}
|
|
73
|
+
export default Delete;
|
|
74
|
+
//# sourceMappingURL=Delete.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Delete.d.ts","sourceRoot":"","sources":["../../../../src/operations/Delete/Delete.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,kBAAkB,CAAC;AAc1C,OAAO,KAAK,EAAE,WAAW,EAAsB,MAAM,aAAa,CAAC;AAEnE,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAI7C;;;;;;;;;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;IAyC3C;;;OAGG;IACH,OAAO,CAAC,0BAA0B;IAmBlC;;;OAGG;IACH,OAAO,CAAC,mCAAmC;IAoB3C;;;;OAIG;IACH,OAAO,CAAC,iCAAiC;IA0CzC;;;;OAIG;IACH,OAAO,CAAC,uCAAuC;IA0B/C;;;;;OAKG;IACH,OAAO,CAAC,sCAAsC;IAkB9C;;;;OAIG;IACH,OAAO,CAAC,qCAAqC;IAiB7C;;;;OAIG;IACH,OAAO,CAAC,aAAa;IAIrB;;;OAGG;IACH,OAAO,CAAC,oBAAoB;CAG7B;AAED,eAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"use strict";
|
|
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 DynaRecord_1 = __importDefault(require("../../DynaRecord"));
|
|
7
|
+
const dynamo_utils_1 = require("../../dynamo-utils");
|
|
8
|
+
const errors_1 = require("../../errors");
|
|
9
|
+
const metadata_1 = __importDefault(require("../../metadata"));
|
|
10
|
+
const utils_1 = require("../../metadata/utils");
|
|
11
|
+
const relationships_1 = require("../../relationships");
|
|
12
|
+
const utils_2 = require("../../utils");
|
|
13
|
+
const OperationBase_1 = __importDefault(require("../OperationBase"));
|
|
14
|
+
const utils_3 = require("../utils");
|
|
15
|
+
/**
|
|
16
|
+
* Implements the operation for deleting an entity and its related data from the database within the ORM framework.
|
|
17
|
+
*
|
|
18
|
+
* Delete an entity, everything in its partition, BelongsToLinks and nullifies ForeignKeys on attributes that BelongTo it
|
|
19
|
+
* If the foreign key is non nullable than it will throw a NullConstraintViolationError
|
|
20
|
+
*
|
|
21
|
+
* The `Delete` operation supports complex scenarios, such as deleting related entities in "BelongsTo" relationships, nullifying or removing foreign keys to maintain data integrity, and handling many-to-many relationships through join tables.
|
|
22
|
+
*
|
|
23
|
+
* @template T - The type of the entity being deleted, extending `DynaRecord`.
|
|
24
|
+
*/
|
|
25
|
+
class Delete extends OperationBase_1.default {
|
|
26
|
+
#transactionBuilder;
|
|
27
|
+
#tableName;
|
|
28
|
+
#partitionKeyField;
|
|
29
|
+
#sortKeyField;
|
|
30
|
+
#relationsLookup;
|
|
31
|
+
#belongsToRelationships;
|
|
32
|
+
#validationErrors = [];
|
|
33
|
+
constructor(Entity) {
|
|
34
|
+
super(Entity);
|
|
35
|
+
this.#transactionBuilder = new dynamo_utils_1.TransactWriteBuilder();
|
|
36
|
+
const { name: tableName } = this.tableMetadata;
|
|
37
|
+
this.#tableName = tableName;
|
|
38
|
+
this.#partitionKeyField = this.tableMetadata.partitionKeyAttribute.name;
|
|
39
|
+
this.#sortKeyField = this.tableMetadata.sortKeyAttribute.name;
|
|
40
|
+
const relationsObj = (0, utils_3.buildEntityRelationshipMetaObj)(Object.values(this.entityMetadata.relationships));
|
|
41
|
+
this.#relationsLookup = relationsObj.relationsLookup;
|
|
42
|
+
this.#belongsToRelationships = relationsObj.belongsToRelationships;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Delete an item by id
|
|
46
|
+
* - Deletes the given entity
|
|
47
|
+
* - Deletes each item in the entity's partition
|
|
48
|
+
* - For each item in the entity's partition which is of type 'BelongsToLink' it:
|
|
49
|
+
* - Will nullify the associated relationship's ForeignKey attribute if the attribute is nullable
|
|
50
|
+
* @param id
|
|
51
|
+
*/
|
|
52
|
+
async run(id) {
|
|
53
|
+
const items = await this.EntityClass.query(id);
|
|
54
|
+
if (items.length === 0) {
|
|
55
|
+
throw new errors_1.NotFoundError(`Item does not exist: ${id}`);
|
|
56
|
+
}
|
|
57
|
+
for (const item of items) {
|
|
58
|
+
if (item.id === id && this.isEntityClass(item)) {
|
|
59
|
+
this.buildDeleteItemTransaction(item, {
|
|
60
|
+
errorMessage: `Failed to delete ${this.EntityClass.name} with Id: ${id}`
|
|
61
|
+
});
|
|
62
|
+
this.buildDeleteAssociatedBelongsTransaction(id, item);
|
|
63
|
+
}
|
|
64
|
+
if (item instanceof relationships_1.BelongsToLink) {
|
|
65
|
+
this.buildDeleteItemTransaction(item, {
|
|
66
|
+
errorMessage: `Failed to delete BelongsToLink with keys: ${JSON.stringify({
|
|
67
|
+
[this.#partitionKeyField]: item[this.#partitionKeyField],
|
|
68
|
+
[this.#sortKeyField]: item[this.#sortKeyField]
|
|
69
|
+
})}`
|
|
70
|
+
});
|
|
71
|
+
this.buildNullifyForeignKeyTransaction(item);
|
|
72
|
+
this.buildDeleteJoinTableLinkTransaction(item);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (this.#validationErrors.length === 0) {
|
|
76
|
+
await this.#transactionBuilder.executeTransaction();
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
throw new dynamo_utils_1.TransactionWriteFailedError(this.#validationErrors, "Failed Validations");
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Deletes an item
|
|
84
|
+
* @param item
|
|
85
|
+
*/
|
|
86
|
+
buildDeleteItemTransaction(item, options) {
|
|
87
|
+
const pkField = this.#partitionKeyField;
|
|
88
|
+
const skField = this.#sortKeyField;
|
|
89
|
+
this.#transactionBuilder.addDelete({
|
|
90
|
+
TableName: this.#tableName,
|
|
91
|
+
Key: {
|
|
92
|
+
[this.partitionKeyAlias]: item[pkField],
|
|
93
|
+
[this.sortKeyAlias]: item[skField]
|
|
94
|
+
}
|
|
95
|
+
}, options.errorMessage);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* If the item has a JoinTable entry (is part of HasAndBelongsToMany relationship) then delete both JoinTable entries
|
|
99
|
+
* @param item - BelongsToLink from HasAndBelongsToMany relationship
|
|
100
|
+
*/
|
|
101
|
+
buildDeleteJoinTableLinkTransaction(item) {
|
|
102
|
+
const relMeta = this.#relationsLookup[item.foreignEntityType];
|
|
103
|
+
if ((0, utils_1.isHasAndBelongsToManyRelationship)(relMeta)) {
|
|
104
|
+
// Inverse the keys to delete the other JoinTable entry
|
|
105
|
+
const belongsToLinksKeys = {
|
|
106
|
+
[this.#partitionKeyField]: item[this.#sortKeyField],
|
|
107
|
+
[this.#sortKeyField]: item[this.#partitionKeyField]
|
|
108
|
+
};
|
|
109
|
+
this.buildDeleteItemTransaction(belongsToLinksKeys, {
|
|
110
|
+
errorMessage: `Failed to delete BelongsToLink with keys: ${JSON.stringify(belongsToLinksKeys)}`
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* If the item being deleted has a foreign key reference, nullify the associated relationship's ForeignKey attribute
|
|
116
|
+
* If the ForeignKey is non nullable than it throws a NullConstraintViolationError
|
|
117
|
+
* @param item
|
|
118
|
+
*/
|
|
119
|
+
buildNullifyForeignKeyTransaction(item) {
|
|
120
|
+
const relMeta = this.#relationsLookup[item.foreignEntityType];
|
|
121
|
+
if ((0, utils_1.isRelationshipMetadataWithForeignKey)(relMeta)) {
|
|
122
|
+
const entityAttrs = metadata_1.default.getEntityAttributes(relMeta.target.name);
|
|
123
|
+
const attrMeta = Object.values(entityAttrs).find(attr => attr.name === relMeta.foreignKey);
|
|
124
|
+
if (attrMeta?.nullable === false) {
|
|
125
|
+
this.trackValidationError(new errors_1.NullConstraintViolationError(`Cannot set ${relMeta.target.name} with id: '${item.id}' attribute '${relMeta.foreignKey}' to null`));
|
|
126
|
+
}
|
|
127
|
+
const tableKeys = (0, utils_2.entityToTableItem)(this.EntityClass, {
|
|
128
|
+
[this.#partitionKeyField]: relMeta.target.partitionKeyValue(item.foreignKey),
|
|
129
|
+
[this.#sortKeyField]: relMeta.target.name
|
|
130
|
+
});
|
|
131
|
+
const tableAttrs = (0, utils_2.entityToTableItem)(relMeta.target, {
|
|
132
|
+
[relMeta.foreignKey]: null
|
|
133
|
+
});
|
|
134
|
+
const expression = (0, utils_3.expressionBuilder)(tableAttrs);
|
|
135
|
+
this.#transactionBuilder.addUpdate({
|
|
136
|
+
TableName: this.#tableName,
|
|
137
|
+
Key: tableKeys,
|
|
138
|
+
UpdateExpression: expression.UpdateExpression,
|
|
139
|
+
ExpressionAttributeNames: expression.ExpressionAttributeNames
|
|
140
|
+
}, `Failed to remove foreign key attribute from ${relMeta.target.name} with Id: ${item.foreignKey}`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Deletes associated BelongsTo relationships for each ForeignKey of the item being deleted
|
|
145
|
+
* @param entityId
|
|
146
|
+
* @param item
|
|
147
|
+
*/
|
|
148
|
+
buildDeleteAssociatedBelongsTransaction(entityId, item) {
|
|
149
|
+
this.#belongsToRelationships.forEach(relMeta => {
|
|
150
|
+
if ((0, utils_2.isKeyOfObject)(item, relMeta.foreignKey) &&
|
|
151
|
+
item[relMeta.foreignKey] !== undefined) {
|
|
152
|
+
const foreignKeyValue = item[relMeta.foreignKey];
|
|
153
|
+
if ((0, utils_1.doesEntityBelongToRelAsHasMany)(this.EntityClass, relMeta)) {
|
|
154
|
+
this.buildDeleteBelongsToHasManyTransaction(relMeta, entityId, foreignKeyValue);
|
|
155
|
+
}
|
|
156
|
+
if ((0, utils_1.doesEntityBelongToRelAsHasOne)(this.EntityClass, relMeta)) {
|
|
157
|
+
this.buildDeleteBelongsToHasOneTransaction(relMeta, foreignKeyValue);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Deletes associated BelongsToLink for a BelongsTo HasMany relationship
|
|
164
|
+
* @param relMeta
|
|
165
|
+
* @param entityId
|
|
166
|
+
* @param foreignKeyValue
|
|
167
|
+
*/
|
|
168
|
+
buildDeleteBelongsToHasManyTransaction(relMeta, entityId, foreignKeyValue) {
|
|
169
|
+
const belongsToLinksKeys = {
|
|
170
|
+
[this.#partitionKeyField]: relMeta.target.partitionKeyValue(foreignKeyValue),
|
|
171
|
+
[this.#sortKeyField]: this.EntityClass.partitionKeyValue(entityId)
|
|
172
|
+
};
|
|
173
|
+
this.buildDeleteItemTransaction(belongsToLinksKeys, {
|
|
174
|
+
errorMessage: `Failed to delete BelongsToLink with keys: ${JSON.stringify(belongsToLinksKeys)}`
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Deletes associated BelongsToLink for a BelongsTo HasOne relationship
|
|
179
|
+
* @param relMeta
|
|
180
|
+
* @param foreignKeyValue
|
|
181
|
+
*/
|
|
182
|
+
buildDeleteBelongsToHasOneTransaction(relMeta, foreignKeyValue) {
|
|
183
|
+
const belongsToLinksKeys = {
|
|
184
|
+
[this.#partitionKeyField]: relMeta.target.partitionKeyValue(foreignKeyValue),
|
|
185
|
+
[this.#sortKeyField]: this.EntityClass.name
|
|
186
|
+
};
|
|
187
|
+
this.buildDeleteItemTransaction(belongsToLinksKeys, {
|
|
188
|
+
errorMessage: `Failed to delete BelongsToLink with keys: ${JSON.stringify(belongsToLinksKeys)}`
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Type guard to check if the item being evaluated is the currentClass
|
|
193
|
+
* @param item
|
|
194
|
+
* @returns
|
|
195
|
+
*/
|
|
196
|
+
isEntityClass(item) {
|
|
197
|
+
return item instanceof DynaRecord_1.default;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Track validation errors and throw AggregateError after all validations have been run
|
|
201
|
+
* @param err
|
|
202
|
+
*/
|
|
203
|
+
trackValidationError(err) {
|
|
204
|
+
this.#validationErrors.push(err);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
exports.default = Delete;
|
|
@@ -0,0 +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,UAAU,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
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; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/operations/Delete/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C,MAAM,WAAW,aAAa;IAC5B,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,UAAU,IAAI,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type DynaRecord from "../../DynaRecord";
|
|
2
|
+
import type { EntityClass, Optional } from "../../types";
|
|
3
|
+
import OperationBase from "../OperationBase";
|
|
4
|
+
import type { FindByIdOptions, FindByIdIncludesRes } from "./types";
|
|
5
|
+
/**
|
|
6
|
+
* Facilitates the retrieval of an entity by its identifier (ID) from the database, potentially including its associated entities based on specified relationships.
|
|
7
|
+
*
|
|
8
|
+
* It supports fetching an entity solely by its ID or along with its related entities through specified associations, allowing for flexible retrieval of complex entity graphs in a single operation.
|
|
9
|
+
*
|
|
10
|
+
* @template T - The type of the entity being retrieved, extending `DynaRecord`.
|
|
11
|
+
*/
|
|
12
|
+
declare class FindById<T extends DynaRecord> extends OperationBase<T> {
|
|
13
|
+
#private;
|
|
14
|
+
constructor(Entity: EntityClass<T>);
|
|
15
|
+
/**
|
|
16
|
+
* Find an entity by Id and optionally include associations
|
|
17
|
+
* @param {string} id - Entity Id
|
|
18
|
+
* @param {Object} options - FindById options
|
|
19
|
+
* @param {Object[]=} options.include - The associations to include in the query
|
|
20
|
+
* @param {string} options.include[].association - The name of the association to include. Must be defined on the model
|
|
21
|
+
* @returns An entity with optional included associations serialized
|
|
22
|
+
*/
|
|
23
|
+
run(id: string, options?: FindByIdOptions<T>): Promise<Optional<T | FindByIdIncludesRes<T, FindByIdOptions<T>>>>;
|
|
24
|
+
/**
|
|
25
|
+
* Find an Entity by id without associations
|
|
26
|
+
* @param {string} id - Entity Id
|
|
27
|
+
* @returns An entity object or undefined
|
|
28
|
+
*/
|
|
29
|
+
private findByIdOnly;
|
|
30
|
+
/**
|
|
31
|
+
* Find an entity with included associations
|
|
32
|
+
* @param {string} id - Entity Id
|
|
33
|
+
* @param {Object[]=} includedAssociations - The associations to include in the query
|
|
34
|
+
* @param {string} includedAssociations[].association - The name of the association to include. Must be defined on the model
|
|
35
|
+
* @returns An entity with included associations serialized
|
|
36
|
+
*/
|
|
37
|
+
private findByIdWithIncludes;
|
|
38
|
+
/**
|
|
39
|
+
* Build the query to find the entity, and any of the BelongsToLinks for the included models
|
|
40
|
+
* @param id
|
|
41
|
+
* @param includedRelationships
|
|
42
|
+
* @returns
|
|
43
|
+
*/
|
|
44
|
+
private buildFindByIdIncludesQuery;
|
|
45
|
+
/**
|
|
46
|
+
* Sort query results into an object containing:
|
|
47
|
+
* - item: The FindById DynamoItem
|
|
48
|
+
* - belongsToLinks: BelongsToLinkDynamoItem records for each of the included relationships
|
|
49
|
+
* @param queryResults
|
|
50
|
+
* @returns
|
|
51
|
+
*/
|
|
52
|
+
private filterQueryResults;
|
|
53
|
+
private buildGetIncludedRelationshipsTransaction;
|
|
54
|
+
/**
|
|
55
|
+
* Builds transactions to get an associated entity via a BelongsToLink (HasOne or HasMany)
|
|
56
|
+
* @param belongsToLinks
|
|
57
|
+
* @param relationsLookup
|
|
58
|
+
*/
|
|
59
|
+
private buildGetRelationshipsThroughLinksTransaction;
|
|
60
|
+
/**
|
|
61
|
+
* Builds transactions to get an associated entity using a foreign key on the parent model (BelongsTo)
|
|
62
|
+
* @param belongsToLinks
|
|
63
|
+
* @param relationsLookup
|
|
64
|
+
*/
|
|
65
|
+
private buildGetRelationshipsThroughForeignKeyTransaction;
|
|
66
|
+
/**
|
|
67
|
+
* Get relationship metadata for the associations included in the query
|
|
68
|
+
* @param includedAssociations
|
|
69
|
+
* @returns
|
|
70
|
+
*/
|
|
71
|
+
private getIncludedRelationships;
|
|
72
|
+
/**
|
|
73
|
+
* Serialize the FindById item to its class, serialize results from included relationships query onto the entity
|
|
74
|
+
* @param entityTableItem
|
|
75
|
+
* @param transactionResults
|
|
76
|
+
* @param relationsLookup
|
|
77
|
+
* @returns
|
|
78
|
+
*/
|
|
79
|
+
private resolveFindByIdIncludesResults;
|
|
80
|
+
/**
|
|
81
|
+
* Initializes default values for included relationships on a parent entity. It assigns
|
|
82
|
+
* an empty array to each relationship property for HasMany and HasAndBelongsToMany specified in `relationsLookup` if the property exists on `parentEntity`.
|
|
83
|
+
*
|
|
84
|
+
* @param parentEntity - The parent entity to initialize relationship properties on.
|
|
85
|
+
* @param relationsLookup - A mapping of relationship identifiers to their descriptions, including the relationship
|
|
86
|
+
* type and the property name on the parent entity.
|
|
87
|
+
*/
|
|
88
|
+
private setIncludedRelationshipDefaults;
|
|
89
|
+
}
|
|
90
|
+
export default FindById;
|
|
91
|
+
//# sourceMappingURL=FindById.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FindById.d.ts","sourceRoot":"","sources":["../../../../src/operations/FindById/FindById.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAW/C,OAAO,KAAK,EAIV,WAAW,EACX,QAAQ,EACT,MAAM,aAAa,CAAC;AASrB,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,EACV,eAAe,EACf,mBAAmB,EAGpB,MAAM,SAAS,CAAC;AAQjB;;;;;;GAMG;AACH,cAAM,QAAQ,CAAC,CAAC,SAAS,UAAU,CAAE,SAAQ,aAAa,CAAC,CAAC,CAAC;;gBAG/C,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IAKlC;;;;;;;OAOG;IACU,GAAG,CACd,EAAE,EAAE,MAAM,EACV,OAAO,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,GAC3B,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,mBAAmB,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAQpE;;;;OAIG;YACW,YAAY;IAmB1B;;;;;;OAMG;YACW,oBAAoB;IAiClC;;;;;OAKG;IACH,OAAO,CAAC,0BAA0B;IAkBlC;;;;;;OAMG;IACH,OAAO,CAAC,kBAAkB;IAa1B,OAAO,CAAC,wCAAwC;IAehD;;;;OAIG;IACH,OAAO,CAAC,4CAA4C;IA6BpD;;;;OAIG;IACH,OAAO,CAAC,iDAAiD;IA0BzD;;;;OAIG;IACH,OAAO,CAAC,wBAAwB;IAchC;;;;;;OAMG;IACH,OAAO,CAAC,8BAA8B;IAyCtC;;;;;;;OAOG;IACH,OAAO,CAAC,+BAA+B;CAexC;AAED,eAAe,QAAQ,CAAC"}
|