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,89 @@
|
|
|
1
|
+
import { type QueryCommandInput } from "@aws-sdk/lib-dynamodb";
|
|
2
|
+
import { type NativeScalarAttributeValue } from "@aws-sdk/util-dynamodb";
|
|
3
|
+
/**
|
|
4
|
+
* Represents conditions used to specify the partition key and sort key (if applicable) for querying items in DynamoDB.
|
|
5
|
+
*
|
|
6
|
+
* @type {KeyConditions} - Derived from the `KeyConditions` part of the `QueryCommandInput` from AWS SDK, excluding the "undefined" type to ensure type safety.
|
|
7
|
+
*/
|
|
8
|
+
export type KeyConditions = Omit<QueryCommandInput["KeyConditions"], "undefined">;
|
|
9
|
+
/**
|
|
10
|
+
* Defines the structure for a filter expression used in querying items, including the expression string and a record of values associated with the expression placeholders.
|
|
11
|
+
*
|
|
12
|
+
* @property {Record<string, NativeScalarAttributeValue>} values - A mapping of placeholder tokens in the filter expression to their actual values.
|
|
13
|
+
* @property {string} expression - The filter expression string, using DynamoDB's expression syntax.
|
|
14
|
+
*/
|
|
15
|
+
export interface FilterExpression {
|
|
16
|
+
values: Record<string, NativeScalarAttributeValue>;
|
|
17
|
+
expression: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Represents a filter condition specifying that a value must begin with a certain prefix.
|
|
21
|
+
*
|
|
22
|
+
* @type {BeginsWithFilter} - A record with "$beginsWith" key pointing to the prefix value.
|
|
23
|
+
*/
|
|
24
|
+
export type BeginsWithFilter = Record<"$beginsWith", NativeScalarAttributeValue>;
|
|
25
|
+
/**
|
|
26
|
+
* Defines possible types of values that can be used in a filter condition, including begins with, exact value, or an array for "IN" conditions.
|
|
27
|
+
*
|
|
28
|
+
* @type {FilterTypes} - A union of `BeginsWithFilter`, a single scalar value, or an array of scalar values.
|
|
29
|
+
*/
|
|
30
|
+
export type FilterTypes = BeginsWithFilter | NativeScalarAttributeValue | NativeScalarAttributeValue[];
|
|
31
|
+
/**
|
|
32
|
+
* Represents a filter condition using an AND logical operator. All items in this record will be queried with "AND"
|
|
33
|
+
*
|
|
34
|
+
* @type {AndFilter} - A record mapping attribute names to their filter conditions, implying all conditions must be met (AND logic).
|
|
35
|
+
*/
|
|
36
|
+
export type AndFilter = Record<string, FilterTypes>;
|
|
37
|
+
/**
|
|
38
|
+
* Represents a filter condition using an OR logical operator, allowing for grouping of multiple `AndFilter` conditions under a single '$or' key.
|
|
39
|
+
*
|
|
40
|
+
* @type {OrFilter} - A record with an "$or" key containing an array of `AndFilter` objects, indicating any of the conditions can be met (OR logic).
|
|
41
|
+
*/
|
|
42
|
+
export type OrFilter = Record<"$or", AndFilter[]>;
|
|
43
|
+
/**
|
|
44
|
+
* Makes the '$or' key optional in an `OrFilter`, allowing for filters that primarily use AND logic but optionally include OR conditions.
|
|
45
|
+
*
|
|
46
|
+
* @type {OrOptional} - An `OrFilter` type with the '$or' key made optional.
|
|
47
|
+
*/
|
|
48
|
+
export type OrOptional = Omit<OrFilter, "$or"> & Partial<Pick<OrFilter, "$or">>;
|
|
49
|
+
/**
|
|
50
|
+
* Combines `AndFilter` and `OrFilter` types, supporting complex filters that use both AND and OR logic within the same filter structure.
|
|
51
|
+
*
|
|
52
|
+
* @type {FilterParams} - A combination of `AndFilter` or `OrFilter` with optional OR conditions.
|
|
53
|
+
*/
|
|
54
|
+
export type FilterParams = (AndFilter | OrFilter) & OrOptional;
|
|
55
|
+
/**
|
|
56
|
+
* Represents complex filters combining AND and OR logic, specifically allowing for an 'OrFilter' at the top level.
|
|
57
|
+
*
|
|
58
|
+
* @type {AndOrFilter} - A `FilterParams` type further combined with an `OrFilter` for additional flexibility.
|
|
59
|
+
*/
|
|
60
|
+
export type AndOrFilter = FilterParams & OrFilter;
|
|
61
|
+
/**
|
|
62
|
+
* Defines the condition for a sort key in a query, allowing for exact matches or "begins with" conditions.
|
|
63
|
+
*
|
|
64
|
+
* @type {SortKeyCondition} - A `BeginsWithFilter` or a single scalar value, used for sort key conditions in queries.
|
|
65
|
+
*/
|
|
66
|
+
export type SortKeyCondition = BeginsWithFilter | NativeScalarAttributeValue;
|
|
67
|
+
/**
|
|
68
|
+
* Specifies additional options for querying items, including optional index name and filter conditions.
|
|
69
|
+
*
|
|
70
|
+
* @property {string?} indexName - Optional name of the secondary index to use in the query.
|
|
71
|
+
* @property {FilterParams?} filter - Optional filter conditions to apply to the query.
|
|
72
|
+
*/
|
|
73
|
+
export interface QueryOptions {
|
|
74
|
+
indexName?: string;
|
|
75
|
+
filter?: FilterParams;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Combines key conditions and query options to define the properties for a query command.
|
|
79
|
+
*
|
|
80
|
+
* @property {string} entityClassName - The name of the entity class being queried.
|
|
81
|
+
* @property {KeyConditions} key - The partition key conditions for the query.
|
|
82
|
+
* @property {QueryOptions?} options - Optional additional query options.
|
|
83
|
+
*/
|
|
84
|
+
export interface QueryCommandProps {
|
|
85
|
+
entityClassName: string;
|
|
86
|
+
key: KeyConditions;
|
|
87
|
+
options?: QueryOptions;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/query-utils/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,KAAK,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AAEzE;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,IAAI,CAC9B,iBAAiB,CAAC,eAAe,CAAC,EAClC,WAAW,CACZ,CAAC;AAEF;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,0BAA0B,CAAC,CAAC;IACnD,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,CACnC,aAAa,EACb,0BAA0B,CAC3B,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,WAAW,GACnB,gBAAgB,GAChB,0BAA0B,GAC1B,0BAA0B,EAAE,CAAC;AAEjC;;;;GAIG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;AAEpD;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;AAElD;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC;AAEhF;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,SAAS,GAAG,QAAQ,CAAC,GAAG,UAAU,CAAC;AAE/D;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,YAAY,GAAG,QAAQ,CAAC;AAElD;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,gBAAgB,GAAG,0BAA0B,CAAC;AAE7E;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,iBAAiB;IAChC,eAAe,EAAE,MAAM,CAAC;IACxB,GAAG,EAAE,aAAa,CAAC;IACnB,OAAO,CAAC,EAAE,YAAY,CAAC;CACxB"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type DynaRecord from "../DynaRecord";
|
|
2
|
+
import type { ForeignKey } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* Extends `DynaRecord` with properties specific to "BelongsTo" relationships, such as `foreignEntityType` and `foreignKey`.
|
|
5
|
+
*/
|
|
6
|
+
interface BelongsToLinkProps extends DynaRecord {
|
|
7
|
+
foreignEntityType: string;
|
|
8
|
+
foreignKey: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Represents a "BelongsTo" relationship link between entities within the ORM system. Instances of this class are used to track and manage associations where one entity belongs to another, encapsulating the connection details including the type of the foreign entity and its foreign key.
|
|
12
|
+
*
|
|
13
|
+
* This class implements the `BelongsToLinkProps` interface, ensuring consistency in the properties used to describe the "BelongsTo" relationship.
|
|
14
|
+
*/
|
|
15
|
+
declare class BelongsToLink implements BelongsToLinkProps {
|
|
16
|
+
/**
|
|
17
|
+
* A unique identifier for the link itself, automatically generated upon creation.
|
|
18
|
+
*/
|
|
19
|
+
readonly id: string;
|
|
20
|
+
/**
|
|
21
|
+
* The type of the link, statically set to "BelongsToLink".
|
|
22
|
+
*/
|
|
23
|
+
readonly type: string;
|
|
24
|
+
/**
|
|
25
|
+
* The name of the entity type to which the link points (the "parent" entity in the relationship).
|
|
26
|
+
*/
|
|
27
|
+
readonly foreignEntityType: string;
|
|
28
|
+
/**
|
|
29
|
+
* The foreign key value identifying the specific instance of the foreign entity to which the link belongs. While it is a string, it represents the value of a `ForeignKey` attribute in the related entity.
|
|
30
|
+
*/
|
|
31
|
+
readonly foreignKey: ForeignKey;
|
|
32
|
+
/**
|
|
33
|
+
* The timestamp marking when the link was created
|
|
34
|
+
*/
|
|
35
|
+
readonly createdAt: Date;
|
|
36
|
+
/**
|
|
37
|
+
* The timestamp marking the last update to the link. Initially set to the same value as `createdAt`.
|
|
38
|
+
*/
|
|
39
|
+
readonly updatedAt: Date;
|
|
40
|
+
constructor(item?: BelongsToLink);
|
|
41
|
+
/**
|
|
42
|
+
* A static method to construct a `BelongsToLinkProps` object with specified properties, including auto-generated `id` and timestamp fields. This method facilitates the creation of new link instances without directly instantiating the class.
|
|
43
|
+
* @param {string} foreignEntityType - The name of the entity type to which the new link will belong.
|
|
44
|
+
* @param {string} foreignKey - The foreign key value identifying the specific instance of the foreign entity.
|
|
45
|
+
* @returns {BelongsToLinkProps} - A new `BelongsToLinkProps` object ready for use in creating or managing a "BelongsTo" relationship.
|
|
46
|
+
*/
|
|
47
|
+
static build(foreignEntityType: string, foreignKey: string): BelongsToLinkProps;
|
|
48
|
+
}
|
|
49
|
+
export default BelongsToLink;
|
|
50
|
+
//# sourceMappingURL=BelongsToLink.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BelongsToLink.d.ts","sourceRoot":"","sources":["../../../src/relationships/BelongsToLink.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C;;GAEG;AACH,UAAU,kBAAmB,SAAQ,UAAU;IAC7C,iBAAiB,EAAE,MAAM,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;GAIG;AACH,cAAM,aAAc,YAAW,kBAAkB;IAC/C;;OAEG;IACH,SAAgB,EAAE,EAAE,MAAM,CAAC;IAC3B;;OAEG;IACH,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B;;OAEG;IACH,SAAgB,iBAAiB,EAAE,MAAM,CAAC;IAC1C;;OAEG;IACH,SAAgB,UAAU,EAAE,UAAU,CAAC;IACvC;;OAEG;IACH,SAAgB,SAAS,EAAE,IAAI,CAAC;IAChC;;OAEG;IACH,SAAgB,SAAS,EAAE,IAAI,CAAC;gBAEpB,IAAI,CAAC,EAAE,aAAa;IAMhC;;;;;OAKG;WACW,KAAK,CACjB,iBAAiB,EAAE,MAAM,EACzB,UAAU,EAAE,MAAM,GACjB,kBAAkB;CAYtB;AAED,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const uuid_1 = require("uuid");
|
|
4
|
+
/**
|
|
5
|
+
* Represents a "BelongsTo" relationship link between entities within the ORM system. Instances of this class are used to track and manage associations where one entity belongs to another, encapsulating the connection details including the type of the foreign entity and its foreign key.
|
|
6
|
+
*
|
|
7
|
+
* This class implements the `BelongsToLinkProps` interface, ensuring consistency in the properties used to describe the "BelongsTo" relationship.
|
|
8
|
+
*/
|
|
9
|
+
class BelongsToLink {
|
|
10
|
+
/**
|
|
11
|
+
* A unique identifier for the link itself, automatically generated upon creation.
|
|
12
|
+
*/
|
|
13
|
+
id;
|
|
14
|
+
/**
|
|
15
|
+
* The type of the link, statically set to "BelongsToLink".
|
|
16
|
+
*/
|
|
17
|
+
type;
|
|
18
|
+
/**
|
|
19
|
+
* The name of the entity type to which the link points (the "parent" entity in the relationship).
|
|
20
|
+
*/
|
|
21
|
+
foreignEntityType;
|
|
22
|
+
/**
|
|
23
|
+
* The foreign key value identifying the specific instance of the foreign entity to which the link belongs. While it is a string, it represents the value of a `ForeignKey` attribute in the related entity.
|
|
24
|
+
*/
|
|
25
|
+
foreignKey;
|
|
26
|
+
/**
|
|
27
|
+
* The timestamp marking when the link was created
|
|
28
|
+
*/
|
|
29
|
+
createdAt;
|
|
30
|
+
/**
|
|
31
|
+
* The timestamp marking the last update to the link. Initially set to the same value as `createdAt`.
|
|
32
|
+
*/
|
|
33
|
+
updatedAt;
|
|
34
|
+
constructor(item) {
|
|
35
|
+
if (item !== undefined) {
|
|
36
|
+
Object.assign(this, item);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A static method to construct a `BelongsToLinkProps` object with specified properties, including auto-generated `id` and timestamp fields. This method facilitates the creation of new link instances without directly instantiating the class.
|
|
41
|
+
* @param {string} foreignEntityType - The name of the entity type to which the new link will belong.
|
|
42
|
+
* @param {string} foreignKey - The foreign key value identifying the specific instance of the foreign entity.
|
|
43
|
+
* @returns {BelongsToLinkProps} - A new `BelongsToLinkProps` object ready for use in creating or managing a "BelongsTo" relationship.
|
|
44
|
+
*/
|
|
45
|
+
static build(foreignEntityType, foreignKey) {
|
|
46
|
+
const createdAt = new Date();
|
|
47
|
+
return {
|
|
48
|
+
id: (0, uuid_1.v4)(),
|
|
49
|
+
type: BelongsToLink.name,
|
|
50
|
+
foreignKey,
|
|
51
|
+
foreignEntityType,
|
|
52
|
+
createdAt,
|
|
53
|
+
updatedAt: createdAt
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.default = BelongsToLink;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type DynaRecord from "../DynaRecord";
|
|
2
|
+
import type { ForeignKey, EntityClass } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* Exclude the type1 type2 instance keys
|
|
5
|
+
*/
|
|
6
|
+
type ExcludeKeys = "type1" | "type2";
|
|
7
|
+
/**
|
|
8
|
+
* ForeignKey properties of the join table
|
|
9
|
+
*/
|
|
10
|
+
type ForeignKeyProperties<T> = {
|
|
11
|
+
[P in Exclude<keyof T, ExcludeKeys>]: T[P] extends ForeignKey ? string : never;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Abstract class representing a join table for HasAndBelongsToMany relationships.
|
|
15
|
+
* This class should be extended for specific join table implementations.
|
|
16
|
+
* It is virtual and not persisted to the database but manages the BelongsToLinks
|
|
17
|
+
* in each related entity's partition.
|
|
18
|
+
*
|
|
19
|
+
* Example:
|
|
20
|
+
* ```
|
|
21
|
+
* class ExampleJoinTable extends JoinTable {
|
|
22
|
+
* public exampleId1: ForeignKey;
|
|
23
|
+
* public exampleId2: ForeignKey;
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
declare abstract class JoinTable<T extends DynaRecord, K extends DynaRecord> {
|
|
28
|
+
private readonly type1;
|
|
29
|
+
private readonly type2;
|
|
30
|
+
constructor(type1: EntityClass<T>, type2: EntityClass<K>);
|
|
31
|
+
/**
|
|
32
|
+
* Create a JoinTable entry
|
|
33
|
+
* Adds BelongsToLink to each associated Entity's partition
|
|
34
|
+
* @param this
|
|
35
|
+
* @param keys
|
|
36
|
+
*/
|
|
37
|
+
static create<ThisClass extends JoinTable<T, K>, T extends DynaRecord, K extends DynaRecord>(this: new (type1: EntityClass<T>, type2: EntityClass<K>) => ThisClass, keys: ForeignKeyProperties<ThisClass>): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Delete a JoinTable entry
|
|
40
|
+
* Deletes BelongsToLink from each associated Entity's partition
|
|
41
|
+
* @param this
|
|
42
|
+
* @param keys
|
|
43
|
+
*/
|
|
44
|
+
static delete<ThisClass extends JoinTable<T, K>, T extends DynaRecord, K extends DynaRecord>(this: new (type1: EntityClass<T>, type2: EntityClass<K>) => ThisClass, keys: ForeignKeyProperties<ThisClass>): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Creates transactions:
|
|
47
|
+
* 1. Create a BelongsToLink in parents partition if its not already linked
|
|
48
|
+
* 2. Ensures that the parent EntityExists
|
|
49
|
+
* @param transactionBuilder
|
|
50
|
+
* @param keys
|
|
51
|
+
* @param parentEntityMeta
|
|
52
|
+
* @param linkedEntityMeta
|
|
53
|
+
*/
|
|
54
|
+
private static createBelongsToLink;
|
|
55
|
+
/**
|
|
56
|
+
* Deletes transactions:
|
|
57
|
+
* 1. Delete a BelongsToLink in parents partition if its linked
|
|
58
|
+
* @param transactionBuilder
|
|
59
|
+
* @param keys
|
|
60
|
+
* @param parentEntityMeta
|
|
61
|
+
* @param linkedEntityMeta
|
|
62
|
+
*/
|
|
63
|
+
private static deleteBelongsToLink;
|
|
64
|
+
private static joinTableKey;
|
|
65
|
+
private static transactionProps;
|
|
66
|
+
}
|
|
67
|
+
export default JoinTable;
|
|
68
|
+
//# sourceMappingURL=JoinTable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JoinTable.d.ts","sourceRoot":"","sources":["../../../src/relationships/JoinTable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;AAM5C,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAIxD;;GAEG;AACH,KAAK,WAAW,GAAG,OAAO,GAAG,OAAO,CAAC;AAErC;;GAEG;AACH,KAAK,oBAAoB,CAAC,CAAC,IAAI;KAC5B,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,UAAU,GACzD,MAAM,GACN,KAAK;CACV,CAAC;AAcF;;;;;;;;;;;;;GAaG;AACH,uBAAe,SAAS,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,UAAU;IAE/D,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,KAAK;gBADL,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,EACrB,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC;IAGxC;;;;;OAKG;WACiB,MAAM,CACxB,SAAS,SAAS,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EACjC,CAAC,SAAS,UAAU,EACpB,CAAC,SAAS,UAAU,EAEpB,IAAI,EAAE,KAAK,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,SAAS,EACrE,IAAI,EAAE,oBAAoB,CAAC,SAAS,CAAC,GACpC,OAAO,CAAC,IAAI,CAAC;IAWhB;;;;;OAKG;WACiB,MAAM,CACxB,SAAS,SAAS,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EACjC,CAAC,SAAS,UAAU,EACpB,CAAC,SAAS,UAAU,EAEpB,IAAI,EAAE,KAAK,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,SAAS,EACrE,IAAI,EAAE,oBAAoB,CAAC,SAAS,CAAC,GACpC,OAAO,CAAC,IAAI,CAAC;IAWhB;;;;;;;;OAQG;IACH,OAAO,CAAC,MAAM,CAAC,mBAAmB;IA6ClC;;;;;;;OAOG;IACH,OAAO,CAAC,MAAM,CAAC,mBAAmB;IA0BlC,OAAO,CAAC,MAAM,CAAC,YAAY;IAoB3B,OAAO,CAAC,MAAM,CAAC,gBAAgB;CAmBhC;AAED,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,133 @@
|
|
|
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 TransactWriteBuilder_1 = __importDefault(require("../dynamo-utils/TransactWriteBuilder"));
|
|
7
|
+
const metadata_1 = __importDefault(require("../metadata"));
|
|
8
|
+
const utils_1 = require("../utils");
|
|
9
|
+
const BelongsToLink_1 = __importDefault(require("./BelongsToLink"));
|
|
10
|
+
/**
|
|
11
|
+
* Abstract class representing a join table for HasAndBelongsToMany relationships.
|
|
12
|
+
* This class should be extended for specific join table implementations.
|
|
13
|
+
* It is virtual and not persisted to the database but manages the BelongsToLinks
|
|
14
|
+
* in each related entity's partition.
|
|
15
|
+
*
|
|
16
|
+
* Example:
|
|
17
|
+
* ```
|
|
18
|
+
* class ExampleJoinTable extends JoinTable {
|
|
19
|
+
* public exampleId1: ForeignKey;
|
|
20
|
+
* public exampleId2: ForeignKey;
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
class JoinTable {
|
|
25
|
+
type1;
|
|
26
|
+
type2;
|
|
27
|
+
constructor(type1, type2) {
|
|
28
|
+
this.type1 = type1;
|
|
29
|
+
this.type2 = type2;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Create a JoinTable entry
|
|
33
|
+
* Adds BelongsToLink to each associated Entity's partition
|
|
34
|
+
* @param this
|
|
35
|
+
* @param keys
|
|
36
|
+
*/
|
|
37
|
+
static async create(keys) {
|
|
38
|
+
const transactionBuilder = new TransactWriteBuilder_1.default();
|
|
39
|
+
const [rel1, rel2] = metadata_1.default.getJoinTable(this.name);
|
|
40
|
+
JoinTable.createBelongsToLink(transactionBuilder, keys, rel1, rel2);
|
|
41
|
+
JoinTable.createBelongsToLink(transactionBuilder, keys, rel2, rel1);
|
|
42
|
+
await transactionBuilder.executeTransaction();
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Delete a JoinTable entry
|
|
46
|
+
* Deletes BelongsToLink from each associated Entity's partition
|
|
47
|
+
* @param this
|
|
48
|
+
* @param keys
|
|
49
|
+
*/
|
|
50
|
+
static async delete(keys) {
|
|
51
|
+
const transactionBuilder = new TransactWriteBuilder_1.default();
|
|
52
|
+
const [rel1, rel2] = metadata_1.default.getJoinTable(this.name);
|
|
53
|
+
JoinTable.deleteBelongsToLink(transactionBuilder, keys, rel1, rel2);
|
|
54
|
+
JoinTable.deleteBelongsToLink(transactionBuilder, keys, rel2, rel1);
|
|
55
|
+
await transactionBuilder.executeTransaction();
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Creates transactions:
|
|
59
|
+
* 1. Create a BelongsToLink in parents partition if its not already linked
|
|
60
|
+
* 2. Ensures that the parent EntityExists
|
|
61
|
+
* @param transactionBuilder
|
|
62
|
+
* @param keys
|
|
63
|
+
* @param parentEntityMeta
|
|
64
|
+
* @param linkedEntityMeta
|
|
65
|
+
*/
|
|
66
|
+
static createBelongsToLink(transactionBuilder, keys, parentEntityMeta, linkedEntityMeta) {
|
|
67
|
+
const { tableProps, entities, ids } = this.transactionProps(keys, parentEntityMeta, linkedEntityMeta);
|
|
68
|
+
const { name: tableName } = tableProps;
|
|
69
|
+
const { alias: partitionKeyAlias } = tableProps.partitionKeyAttribute;
|
|
70
|
+
const { alias: sortKeyAlias } = tableProps.sortKeyAttribute;
|
|
71
|
+
const { parentEntity, linkedEntity } = entities;
|
|
72
|
+
const { parentId, linkedEntityId } = ids;
|
|
73
|
+
transactionBuilder.addPut({
|
|
74
|
+
TableName: tableName,
|
|
75
|
+
Item: {
|
|
76
|
+
...this.joinTableKey(keys, parentEntityMeta, linkedEntityMeta),
|
|
77
|
+
...(0, utils_1.entityToTableItem)(linkedEntity, BelongsToLink_1.default.build(linkedEntity.name, parentId))
|
|
78
|
+
},
|
|
79
|
+
ConditionExpression: `attribute_not_exists(${partitionKeyAlias})` // Ensure item doesn't already exist
|
|
80
|
+
}, `${parentEntity.name} with ID ${linkedEntityId} is already linked to ${linkedEntity.name} with ID ${parentId}`);
|
|
81
|
+
transactionBuilder.addConditionCheck({
|
|
82
|
+
TableName: tableName,
|
|
83
|
+
Key: {
|
|
84
|
+
[partitionKeyAlias]: parentEntity.partitionKeyValue(linkedEntityId),
|
|
85
|
+
[sortKeyAlias]: parentEntity.name
|
|
86
|
+
},
|
|
87
|
+
ConditionExpression: `attribute_exists(${partitionKeyAlias})`
|
|
88
|
+
}, `${parentEntity.name} with ID ${linkedEntityId} does not exist`);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Deletes transactions:
|
|
92
|
+
* 1. Delete a BelongsToLink in parents partition if its linked
|
|
93
|
+
* @param transactionBuilder
|
|
94
|
+
* @param keys
|
|
95
|
+
* @param parentEntityMeta
|
|
96
|
+
* @param linkedEntityMeta
|
|
97
|
+
*/
|
|
98
|
+
static deleteBelongsToLink(transactionBuilder, keys, parentEntityMeta, linkedEntityMeta) {
|
|
99
|
+
const { entity: parentEntity, foreignKey: parentKey } = parentEntityMeta;
|
|
100
|
+
const { entity: linkedEntity, foreignKey: linkedKey } = linkedEntityMeta;
|
|
101
|
+
const parentId = keys[parentKey];
|
|
102
|
+
const linkedEntityId = keys[linkedKey];
|
|
103
|
+
const { name: tableName, partitionKeyAttribute } = metadata_1.default.getEntityTable(parentEntity.name);
|
|
104
|
+
transactionBuilder.addDelete({
|
|
105
|
+
TableName: tableName,
|
|
106
|
+
Key: this.joinTableKey(keys, parentEntityMeta, linkedEntityMeta),
|
|
107
|
+
ConditionExpression: `attribute_exists(${partitionKeyAttribute.alias})`
|
|
108
|
+
}, `${parentEntity.name} with ID ${linkedEntityId} is not linked to ${linkedEntity.name} with ID ${parentId}`);
|
|
109
|
+
}
|
|
110
|
+
static joinTableKey(keys, parentEntityMeta, linkedEntityMeta) {
|
|
111
|
+
const { tableProps, entities, ids } = this.transactionProps(keys, parentEntityMeta, linkedEntityMeta);
|
|
112
|
+
const { parentEntity, linkedEntity } = entities;
|
|
113
|
+
const { alias: partitionKeyAlias } = tableProps.partitionKeyAttribute;
|
|
114
|
+
const { alias: sortKeyAlias } = tableProps.sortKeyAttribute;
|
|
115
|
+
return {
|
|
116
|
+
[partitionKeyAlias]: parentEntity.partitionKeyValue(ids.linkedEntityId),
|
|
117
|
+
[sortKeyAlias]: linkedEntity.partitionKeyValue(ids.parentId)
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
static transactionProps(keys, parentEntityMeta, linkedEntityMeta) {
|
|
121
|
+
const { entity: parentEntity, foreignKey: parentFK } = parentEntityMeta;
|
|
122
|
+
const { entity: linkedEntity, foreignKey: linkedFK } = linkedEntityMeta;
|
|
123
|
+
const tableMetadata = metadata_1.default.getEntityTable(parentEntity.name);
|
|
124
|
+
const parentId = keys[parentFK];
|
|
125
|
+
const linkedEntityId = keys[linkedFK];
|
|
126
|
+
return {
|
|
127
|
+
tableProps: tableMetadata,
|
|
128
|
+
entities: { parentEntity, linkedEntity },
|
|
129
|
+
ids: { parentId, linkedEntityId }
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
exports.default = JoinTable;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/relationships/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
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.JoinTable = exports.BelongsToLink = void 0;
|
|
7
|
+
var BelongsToLink_1 = require("./BelongsToLink");
|
|
8
|
+
Object.defineProperty(exports, "BelongsToLink", { enumerable: true, get: function () { return __importDefault(BelongsToLink_1).default; } });
|
|
9
|
+
var JoinTable_1 = require("./JoinTable");
|
|
10
|
+
Object.defineProperty(exports, "JoinTable", { enumerable: true, get: function () { return __importDefault(JoinTable_1).default; } });
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { type NativeScalarAttributeValue } from "@aws-sdk/util-dynamodb";
|
|
2
|
+
import { type BelongsToLink } from "./relationships";
|
|
3
|
+
import type { BelongsToRelationship, RelationshipMetadata } from "./metadata";
|
|
4
|
+
import type DynaRecord from "./DynaRecord";
|
|
5
|
+
/**
|
|
6
|
+
* A utility type for branding primitives to ensure type safety with unique identifiers.
|
|
7
|
+
*/
|
|
8
|
+
export type Brand<K, T> = K & {
|
|
9
|
+
__brand: T;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* A branded string type to represent sort keys in DynamoDB tables
|
|
13
|
+
*/
|
|
14
|
+
export type SortKey = Brand<string, "SortKey">;
|
|
15
|
+
/**
|
|
16
|
+
* A branded string type to represent partition keys in DynamoDB tables
|
|
17
|
+
*/
|
|
18
|
+
export type PartitionKey = Brand<string, "PartitionKey">;
|
|
19
|
+
/**
|
|
20
|
+
* A branded string type to represent foreign keys in DynamoDB tables
|
|
21
|
+
*/
|
|
22
|
+
export type ForeignKey = Brand<string, "ForeignKey">;
|
|
23
|
+
/**
|
|
24
|
+
* A branded string type to represent nullable foreign keys in DynamoDB tables, which can also be undefined.
|
|
25
|
+
*/
|
|
26
|
+
export type NullableForeignKey = Optional<Brand<string, "NullableForeignKey">>;
|
|
27
|
+
/**
|
|
28
|
+
* Represents a foreign key property on an entity within a DynaRecord model
|
|
29
|
+
*/
|
|
30
|
+
export type ForeignKeyProperty = keyof DynaRecord & ForeignKey;
|
|
31
|
+
/**
|
|
32
|
+
* Defines a general type for items stored in a DynamoDB table, using string keys and native scalar attribute values.
|
|
33
|
+
*/
|
|
34
|
+
export type DynamoTableItem = Record<string, NativeScalarAttributeValue>;
|
|
35
|
+
/**
|
|
36
|
+
* A utility type for objects with string keys and string values.
|
|
37
|
+
*/
|
|
38
|
+
export type StringObj = Record<string, string>;
|
|
39
|
+
/**
|
|
40
|
+
* Describes the shape of a DynamoDB item representing a `BelongsToLink`, enforcing type consistency.
|
|
41
|
+
*/
|
|
42
|
+
export interface BelongsToLinkDynamoItem {
|
|
43
|
+
Type: typeof BelongsToLink.name;
|
|
44
|
+
[key: string]: NativeScalarAttributeValue;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* A utility type for making a type optional, allowing it to be undefined.
|
|
48
|
+
*/
|
|
49
|
+
export type Optional<T> = T | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* A utility type for making a type nullable, allowing it to be null.
|
|
52
|
+
*/
|
|
53
|
+
export type Nullable<T> = T | null;
|
|
54
|
+
/**
|
|
55
|
+
* Represents a lookup object to access relationship metadata by related entity name for DynaRecord models.
|
|
56
|
+
*/
|
|
57
|
+
export type RelationshipLookup = Record<string, RelationshipMetadata>;
|
|
58
|
+
/**
|
|
59
|
+
* An object structure for holding relationship metadata, aimed at optimizing lookup operations and iterations.
|
|
60
|
+
*/
|
|
61
|
+
export interface RelationshipMetaObj {
|
|
62
|
+
relationsLookup: RelationshipLookup;
|
|
63
|
+
belongsToRelationships: BelongsToRelationship[];
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* A utility type for modifying certain keys of an object type to be optional.
|
|
67
|
+
*/
|
|
68
|
+
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
69
|
+
/**
|
|
70
|
+
* Represents an instance of a class decorated with the `Entity` decorator in DynaRecord, encapsulating entity logic.
|
|
71
|
+
*/
|
|
72
|
+
export type EntityClass<T> = (new () => T) & typeof DynaRecord;
|
|
73
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAC9E,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAE3C;;GAEG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAAE,OAAO,EAAE,CAAC,CAAA;CAAE,CAAC;AAE7C;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAE/C;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,KAAK,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;AAEzD;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;AAErD;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CAAC,KAAK,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC,CAAC;AAE/E;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,UAAU,GAAG,UAAU,CAAC;AAE/D;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,0BAA0B,CAAC,CAAC;AAEzE;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAE/C;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,OAAO,aAAa,CAAC,IAAI,CAAC;IAChC,CAAC,GAAG,EAAE,MAAM,GAAG,0BAA0B,CAAC;CAC3C;AAED;;GAEG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC;AAExC;;GAEG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AAEnC;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;AAEtE;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,eAAe,EAAE,kBAAkB,CAAC;IACpC,sBAAsB,EAAE,qBAAqB,EAAE,CAAC;CACjD;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GACzD,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAEtB;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,GAAG,OAAO,UAAU,CAAC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type DynaRecord from "./DynaRecord";
|
|
2
|
+
import type { DynamoTableItem, BelongsToLinkDynamoItem } from "./types";
|
|
3
|
+
import { type TableMetadata } from "./metadata";
|
|
4
|
+
import { BelongsToLink } from "./relationships";
|
|
5
|
+
/**
|
|
6
|
+
* Convert an entity to its aliased table item fields to for dynamo interactions
|
|
7
|
+
* @param entityClassName
|
|
8
|
+
* @param entityData
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
export declare const entityToTableItem: <T extends DynaRecord>(EntityClass: new () => T, entityData: Partial<DynaRecord>) => DynamoTableItem;
|
|
12
|
+
/**
|
|
13
|
+
* Serialize a table item to its associated Entity class, using the class attribute property names
|
|
14
|
+
* @param EntityClass
|
|
15
|
+
* @param tableItem
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
export declare const tableItemToEntity: <T extends DynaRecord>(EntityClass: new () => T, tableItem: DynamoTableItem) => T;
|
|
19
|
+
/**
|
|
20
|
+
* Serialize a dynamo table item response to a BelongsToLink
|
|
21
|
+
* @param tableMeta - Table metadata
|
|
22
|
+
* @param tableItem - Table item from dynamo response
|
|
23
|
+
* @returns - { @link BelongsToLink }
|
|
24
|
+
*/
|
|
25
|
+
export declare const tableItemToBelongsToLink: (tableMeta: TableMetadata, tableItem: BelongsToLinkDynamoItem) => BelongsToLink;
|
|
26
|
+
/**
|
|
27
|
+
* Type guard to check if the key is defined on the entity
|
|
28
|
+
*/
|
|
29
|
+
export declare const isKeyOfEntity: (entity: DynaRecord, key: string) => key is keyof DynaRecord;
|
|
30
|
+
/**
|
|
31
|
+
* Type guard to check if the key is a defined property on the entity
|
|
32
|
+
* @param entity
|
|
33
|
+
* @param key
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
export declare const isKeyOfObject: <T>(entity: Partial<DynaRecord>, key: any) => key is keyof T;
|
|
37
|
+
/**
|
|
38
|
+
* Type guard to check if the DynamoTableItem is a BelongsToLink
|
|
39
|
+
* @param res DynamoTableItem
|
|
40
|
+
* @returns boolean
|
|
41
|
+
*/
|
|
42
|
+
export declare const isBelongsToLinkDynamoItem: (res: DynamoTableItem, tableMeta: TableMetadata) => res is BelongsToLinkDynamoItem;
|
|
43
|
+
/**
|
|
44
|
+
* Break an array into chunks
|
|
45
|
+
* @param array
|
|
46
|
+
* @param size
|
|
47
|
+
* @returns Array split into chunks of given size
|
|
48
|
+
*/
|
|
49
|
+
export declare const chunkArray: <T>(array: T[], size: number) => T[][];
|
|
50
|
+
/**
|
|
51
|
+
* Checks if a value is a valid property key (string, number, or symbol).
|
|
52
|
+
*
|
|
53
|
+
* @param value The value to be checked. This can be of any type.
|
|
54
|
+
* @returns `true` if the value is a `string`, `number`, or `symbol` (i.e., a valid property key); otherwise, `false`.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* Logger.log(isPropertyKey('test')); // true
|
|
58
|
+
* Logger.log(isPropertyKey(123)); // true
|
|
59
|
+
* Logger.log(isPropertyKey(Symbol('sym'))); // true
|
|
60
|
+
* Logger.log(isPropertyKey({})); // false
|
|
61
|
+
*/
|
|
62
|
+
export declare const isPropertyKey: (value: any) => value is PropertyKey;
|
|
63
|
+
/**
|
|
64
|
+
* Checks if the given value is a string.
|
|
65
|
+
*
|
|
66
|
+
* @param value - The value to check. This can be any type as the function is meant to validate if it's a string.
|
|
67
|
+
* @returns `true` if `value` is a string; otherwise, `false`.
|
|
68
|
+
*/
|
|
69
|
+
export declare const isString: (value: any) => value is string;
|
|
70
|
+
/**
|
|
71
|
+
* Safely assigns a value to a property of an object.
|
|
72
|
+
* It's useful for dynamically assigning properties to objects where the property names might be known but the types could vary.
|
|
73
|
+
*
|
|
74
|
+
* @template TObject - The object type to which the property belongs.
|
|
75
|
+
* @template TKey - The type of the keys of `TObject`
|
|
76
|
+
* @template TValue - The value to be assigned.
|
|
77
|
+
*
|
|
78
|
+
* @param {TObject} object - The target object to which the property will be assigned.
|
|
79
|
+
* @param {TKey} key - The property name under which the value should be assigned. Must be a key of `TObject`.
|
|
80
|
+
* @param {TValue} value - The value to assign to the property on the object.
|
|
81
|
+
*
|
|
82
|
+
* @returns {void} - This function does not return a value; it performs the assignment operation directly on the passed object.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* let entity = { id: "123" };
|
|
86
|
+
* safeAssign(entity, "name", "Jane Doe");
|
|
87
|
+
*/
|
|
88
|
+
export declare const safeAssign: <TObject extends DynaRecord, TKey extends keyof TObject, TValue>(object: TObject, key: TKey, value: TValue) => void;
|
|
89
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AACxE,OAAiB,EAEf,KAAK,aAAa,EACnB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGhD;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,+DAEhB,QAAQ,UAAU,CAAC,KAC9B,eAmBF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,8DAEjB,eAAe,MAwB3B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,cACxB,aAAa,aACb,uBAAuB,KACjC,aA2BF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa,WAChB,UAAU,OACb,MAAM,4BAGZ,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,aAAa,cAChB,QAAQ,UAAU,CAAC,OACtB,GAAG,mBAGT,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,QAC/B,eAAe,aACT,aAAa,mCAGzB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,wBAAyB,MAAM,UAIrD,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,aAAa,UAAW,GAAG,yBAMvC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,UAAW,GAAG,oBAElC,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,UAAU,iHAQpB,IAEF,CAAC"}
|