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,30 @@
|
|
|
1
|
+
import type DynaRecord from "../DynaRecord";
|
|
2
|
+
import { type EntityAttributes } from "../operations/types";
|
|
3
|
+
import type { NullableForeignKey, ForeignKey, Optional } from "../types";
|
|
4
|
+
/**
|
|
5
|
+
* Returns attributes on the provided model which are EntityAttributes of type ForeignKey
|
|
6
|
+
*/
|
|
7
|
+
export type ForeignEntityAttribute<T extends DynaRecord> = {
|
|
8
|
+
[K in keyof T]: T[K] extends ForeignKey ? K : T[K] extends NullableForeignKey ? Optional<K> : never;
|
|
9
|
+
}[keyof EntityAttributes<T>];
|
|
10
|
+
/**
|
|
11
|
+
* Represents the properties of an attribute that are configurable via the {@link Attribute} decorator.
|
|
12
|
+
*/
|
|
13
|
+
export interface AttributeOptions {
|
|
14
|
+
/**
|
|
15
|
+
* An optional alias for the attribute as represented in the database table.
|
|
16
|
+
*
|
|
17
|
+
* This alias is used as the column name in the database table corresponding to
|
|
18
|
+
* the entity. If omitted, the ORM defaults to using the attribute's key as defined
|
|
19
|
+
* within the entity model. Specifying an alias allows for mapping between the
|
|
20
|
+
* entity's attribute names in the code and their respective column names in
|
|
21
|
+
* the database, providing flexibility in naming conventions and supporting
|
|
22
|
+
* scenarios where column names in the database differ from attribute names in the code.
|
|
23
|
+
*/
|
|
24
|
+
alias?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Do not allow ForeignKey or NullableForeignKey types when using the Attribute decorator
|
|
28
|
+
*/
|
|
29
|
+
export type NotForeignKey<T> = T extends ForeignKey | NullableForeignKey ? never : T;
|
|
30
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/decorators/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,KAAK,EAAE,kBAAkB,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzE;;GAEG;AACH,MAAM,MAAM,sBAAsB,CAAC,CAAC,SAAS,UAAU,IAAI;KACxD,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,UAAU,GACnC,CAAC,GACD,CAAC,CAAC,CAAC,CAAC,SAAS,kBAAkB,GAC7B,QAAQ,CAAC,CAAC,CAAC,GACX,KAAK;CACZ,CAAC,MAAM,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC;AAE7B;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;;;;;;OASG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,SAAS,UAAU,GAAG,kBAAkB,GACpE,KAAK,GACL,CAAC,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type QueryCommandInput, type GetCommandInput, type GetCommandOutput, type TransactWriteCommandInput, type TransactWriteCommandOutput, type TransactGetCommandInput } from "@aws-sdk/lib-dynamodb";
|
|
2
|
+
import type { QueryItems, TransactGetItemResponses } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* A utility class for interacting with DynamoDB, providing static methods
|
|
5
|
+
* for common operations such as retrieving, querying, and transacting items.
|
|
6
|
+
*/
|
|
7
|
+
declare class DynamoClient {
|
|
8
|
+
/**
|
|
9
|
+
* Retrieves a single item from DynamoDB based on the provided parameters.
|
|
10
|
+
* @param params The parameters for the GetCommand to DynamoDB.
|
|
11
|
+
* @returns A Promise resolving to the retrieved item.
|
|
12
|
+
*/
|
|
13
|
+
static getItem(params: GetCommandInput): Promise<GetCommandOutput["Item"]>;
|
|
14
|
+
/**
|
|
15
|
+
* Queries DynamoDB based on the provided parameters and returns the matching items.
|
|
16
|
+
* @param params The parameters for the QueryCommand to DynamoDB.
|
|
17
|
+
* @returns A Promise resolving to an array of the queried items.
|
|
18
|
+
*/
|
|
19
|
+
static query(params: QueryCommandInput): Promise<QueryItems>;
|
|
20
|
+
/**
|
|
21
|
+
* Executes a transactional read operation in DynamoDB to get multiple items atomically.
|
|
22
|
+
* @param params The parameters for the TransactGetCommand to DynamoDB.
|
|
23
|
+
* @returns A Promise resolving to the responses of the transactional get operation.
|
|
24
|
+
*/
|
|
25
|
+
static transactGetItems(params: TransactGetCommandInput): Promise<TransactGetItemResponses>;
|
|
26
|
+
/**
|
|
27
|
+
* Executes a transactional write operation in DynamoDB to write multiple items atomically.
|
|
28
|
+
* @param params The parameters for the TransactWriteCommand to DynamoDB.
|
|
29
|
+
* @returns A Promise resolving to the output of the transactional write operation.
|
|
30
|
+
*/
|
|
31
|
+
static transactWriteItems(params: TransactWriteCommandInput): Promise<TransactWriteCommandOutput>;
|
|
32
|
+
}
|
|
33
|
+
export default DynamoClient;
|
|
34
|
+
//# sourceMappingURL=DynamoClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DynamoClient.d.ts","sourceRoot":"","sources":["../../../src/dynamo-utils/DynamoClient.ts"],"names":[],"mappings":"AACA,OAAO,EAML,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,yBAAyB,EAC9B,KAAK,0BAA0B,EAC/B,KAAK,uBAAuB,EAC7B,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,UAAU,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAOpE;;;GAGG;AAEH,cAAM,YAAY;IAChB;;;;OAIG;WACiB,OAAO,CACzB,MAAM,EAAE,eAAe,GACtB,OAAO,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAMpC;;;;OAIG;WACiB,KAAK,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,UAAU,CAAC;IAMzE;;;;OAIG;WACiB,gBAAgB,CAClC,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC,wBAAwB,CAAC;IAMpC;;;;OAIG;WACiB,kBAAkB,CACpC,MAAM,EAAE,yBAAyB,GAChC,OAAO,CAAC,0BAA0B,CAAC;CAIvC;AAED,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
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 client_dynamodb_1 = require("@aws-sdk/client-dynamodb");
|
|
7
|
+
const lib_dynamodb_1 = require("@aws-sdk/lib-dynamodb");
|
|
8
|
+
const Logger_1 = __importDefault(require("../Logger"));
|
|
9
|
+
// Initialize the DynamoDB Document Client with a specific AWS region.
|
|
10
|
+
const dynamo = lib_dynamodb_1.DynamoDBDocumentClient.from(new client_dynamodb_1.DynamoDBClient({ region: "us-west-2" }));
|
|
11
|
+
/**
|
|
12
|
+
* A utility class for interacting with DynamoDB, providing static methods
|
|
13
|
+
* for common operations such as retrieving, querying, and transacting items.
|
|
14
|
+
*/
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
16
|
+
class DynamoClient {
|
|
17
|
+
/**
|
|
18
|
+
* Retrieves a single item from DynamoDB based on the provided parameters.
|
|
19
|
+
* @param params The parameters for the GetCommand to DynamoDB.
|
|
20
|
+
* @returns A Promise resolving to the retrieved item.
|
|
21
|
+
*/
|
|
22
|
+
static async getItem(params) {
|
|
23
|
+
Logger_1.default.log("getItem", { params });
|
|
24
|
+
const response = await dynamo.send(new lib_dynamodb_1.GetCommand(params));
|
|
25
|
+
return response.Item;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Queries DynamoDB based on the provided parameters and returns the matching items.
|
|
29
|
+
* @param params The parameters for the QueryCommand to DynamoDB.
|
|
30
|
+
* @returns A Promise resolving to an array of the queried items.
|
|
31
|
+
*/
|
|
32
|
+
static async query(params) {
|
|
33
|
+
Logger_1.default.log("query", { params });
|
|
34
|
+
const response = await dynamo.send(new lib_dynamodb_1.QueryCommand(params));
|
|
35
|
+
return response.Items ?? [];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Executes a transactional read operation in DynamoDB to get multiple items atomically.
|
|
39
|
+
* @param params The parameters for the TransactGetCommand to DynamoDB.
|
|
40
|
+
* @returns A Promise resolving to the responses of the transactional get operation.
|
|
41
|
+
*/
|
|
42
|
+
static async transactGetItems(params) {
|
|
43
|
+
Logger_1.default.log("transactGetItems", { params });
|
|
44
|
+
const response = await dynamo.send(new lib_dynamodb_1.TransactGetCommand(params));
|
|
45
|
+
return response.Responses ?? [];
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Executes a transactional write operation in DynamoDB to write multiple items atomically.
|
|
49
|
+
* @param params The parameters for the TransactWriteCommand to DynamoDB.
|
|
50
|
+
* @returns A Promise resolving to the output of the transactional write operation.
|
|
51
|
+
*/
|
|
52
|
+
static async transactWriteItems(params) {
|
|
53
|
+
Logger_1.default.log("transactWriteItems", { params });
|
|
54
|
+
return await dynamo.send(new lib_dynamodb_1.TransactWriteCommand(params));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.default = DynamoClient;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Get, TransactGetItemResponses } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Build and executes a [TransactGetItems](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_TransactGetItems.html) request
|
|
4
|
+
*/
|
|
5
|
+
declare class TransactGetBuilder {
|
|
6
|
+
#private;
|
|
7
|
+
/**
|
|
8
|
+
* Execute the transaction
|
|
9
|
+
*/
|
|
10
|
+
executeTransaction(): Promise<TransactGetItemResponses>;
|
|
11
|
+
/**
|
|
12
|
+
* Add a get operation to the transaction
|
|
13
|
+
* @param item
|
|
14
|
+
*/
|
|
15
|
+
addGet(item: Get): void;
|
|
16
|
+
}
|
|
17
|
+
export default TransactGetBuilder;
|
|
18
|
+
//# sourceMappingURL=TransactGetBuilder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TransactGetBuilder.d.ts","sourceRoot":"","sources":["../../../src/dynamo-utils/TransactGetBuilder.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB,EAAoB,MAAM,SAAS,CAAC;AAK/E;;GAEG;AACH,cAAM,kBAAkB;;IAGtB;;OAEG;IACG,kBAAkB,IAAI,OAAO,CAAC,wBAAwB,CAAC;IAiB7D;;;OAGG;IACI,MAAM,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI;CAG/B;AAED,eAAe,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
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 DynamoClient_1 = __importDefault(require("./DynamoClient"));
|
|
7
|
+
const utils_1 = require("../utils");
|
|
8
|
+
// https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_TransactGetItems.html
|
|
9
|
+
const MAX_TRANSACTION_ITEMS = 100;
|
|
10
|
+
/**
|
|
11
|
+
* Build and executes a [TransactGetItems](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_TransactGetItems.html) request
|
|
12
|
+
*/
|
|
13
|
+
class TransactGetBuilder {
|
|
14
|
+
#transactionItems = [];
|
|
15
|
+
/**
|
|
16
|
+
* Execute the transaction
|
|
17
|
+
*/
|
|
18
|
+
async executeTransaction() {
|
|
19
|
+
const transactionChunks = (0, utils_1.chunkArray)(this.#transactionItems, MAX_TRANSACTION_ITEMS);
|
|
20
|
+
// Break transaction into chunks of 100 due to Dynamo limit
|
|
21
|
+
const res = await Promise.all(transactionChunks.map(async (chunk) => await DynamoClient_1.default.transactGetItems({ TransactItems: chunk })));
|
|
22
|
+
return res.flat();
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Add a get operation to the transaction
|
|
26
|
+
* @param item
|
|
27
|
+
*/
|
|
28
|
+
addGet(item) {
|
|
29
|
+
this.#transactionItems.push({ Get: item });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.default = TransactGetBuilder;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { ConditionCheck, Put, Update, Delete } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Build and executes a [TransactWriteItems](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_TransactWriteItems.html) request
|
|
4
|
+
*/
|
|
5
|
+
declare class TransactionBuilder {
|
|
6
|
+
#private;
|
|
7
|
+
/**
|
|
8
|
+
* Execute the transaction
|
|
9
|
+
*/
|
|
10
|
+
executeTransaction(): Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* Add a conditional check to the transaction
|
|
13
|
+
* @param item
|
|
14
|
+
*/
|
|
15
|
+
addConditionCheck(item: ConditionCheck, conditionFailedMsg: string): void;
|
|
16
|
+
/**
|
|
17
|
+
* Add a put operation to the transaction
|
|
18
|
+
* @param item
|
|
19
|
+
*/
|
|
20
|
+
addPut(item: Put, conditionFailedMsg?: string): void;
|
|
21
|
+
/**
|
|
22
|
+
* Add an update operation to the transaction
|
|
23
|
+
* @param item
|
|
24
|
+
*/
|
|
25
|
+
addUpdate(item: Update, conditionFailedMsg?: string): void;
|
|
26
|
+
/**
|
|
27
|
+
* Add a delete operation to the transaction
|
|
28
|
+
* @param item
|
|
29
|
+
*/
|
|
30
|
+
addDelete(item: Delete, conditionFailedMsg?: string): void;
|
|
31
|
+
/**
|
|
32
|
+
* Track error messages to return if there is a ConditionalCheckFailed exception
|
|
33
|
+
*
|
|
34
|
+
* IMPORTANT - Call this before adding the transaction to this.#transactionItems
|
|
35
|
+
* @param errMsg The custom error message to return if there is a ConditionalCheckFailed exception
|
|
36
|
+
*/
|
|
37
|
+
private trackErrorMessage;
|
|
38
|
+
/**
|
|
39
|
+
* Handle TransactionCanceledException, aggregating errors and applying friendly errors if provided.
|
|
40
|
+
* @param error
|
|
41
|
+
* @returns
|
|
42
|
+
*/
|
|
43
|
+
private buildTransactionCanceledException;
|
|
44
|
+
}
|
|
45
|
+
export default TransactionBuilder;
|
|
46
|
+
//# sourceMappingURL=TransactWriteBuilder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TransactWriteBuilder.d.ts","sourceRoot":"","sources":["../../../src/dynamo-utils/TransactWriteBuilder.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAEV,cAAc,EACd,GAAG,EACH,MAAM,EACN,MAAM,EACP,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,cAAM,kBAAkB;;IAItB;;OAEG;IACU,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC;IAehD;;;OAGG;IACI,iBAAiB,CACtB,IAAI,EAAE,cAAc,EACpB,kBAAkB,EAAE,MAAM,GACzB,IAAI;IAKP;;;OAGG;IACI,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,kBAAkB,CAAC,EAAE,MAAM,GAAG,IAAI;IAK3D;;;OAGG;IACI,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,kBAAkB,CAAC,EAAE,MAAM,GAAG,IAAI;IAKjE;;;OAGG;IACI,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,kBAAkB,CAAC,EAAE,MAAM,GAAG,IAAI;IAKjE;;;;;OAKG;IACH,OAAO,CAAC,iBAAiB;IAMzB;;;;OAIG;IACH,OAAO,CAAC,iCAAiC;CA6B1C;AAED,eAAe,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
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 DynamoClient_1 = __importDefault(require("./DynamoClient"));
|
|
7
|
+
const client_dynamodb_1 = require("@aws-sdk/client-dynamodb");
|
|
8
|
+
const errors_1 = require("./errors");
|
|
9
|
+
const Logger_1 = __importDefault(require("../Logger"));
|
|
10
|
+
/**
|
|
11
|
+
* Build and executes a [TransactWriteItems](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_TransactWriteItems.html) request
|
|
12
|
+
*/
|
|
13
|
+
class TransactionBuilder {
|
|
14
|
+
#transactionItems = [];
|
|
15
|
+
#errorMessages = {};
|
|
16
|
+
/**
|
|
17
|
+
* Execute the transaction
|
|
18
|
+
*/
|
|
19
|
+
async executeTransaction() {
|
|
20
|
+
try {
|
|
21
|
+
const response = await DynamoClient_1.default.transactWriteItems({
|
|
22
|
+
TransactItems: this.#transactionItems
|
|
23
|
+
});
|
|
24
|
+
Logger_1.default.log("Transaction successful:", response);
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
if (error instanceof client_dynamodb_1.TransactionCanceledException) {
|
|
28
|
+
throw this.buildTransactionCanceledException(error);
|
|
29
|
+
}
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Add a conditional check to the transaction
|
|
35
|
+
* @param item
|
|
36
|
+
*/
|
|
37
|
+
addConditionCheck(item, conditionFailedMsg) {
|
|
38
|
+
this.trackErrorMessage(conditionFailedMsg);
|
|
39
|
+
this.#transactionItems.push({ ConditionCheck: item });
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Add a put operation to the transaction
|
|
43
|
+
* @param item
|
|
44
|
+
*/
|
|
45
|
+
addPut(item, conditionFailedMsg) {
|
|
46
|
+
this.trackErrorMessage(conditionFailedMsg);
|
|
47
|
+
this.#transactionItems.push({ Put: item });
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Add an update operation to the transaction
|
|
51
|
+
* @param item
|
|
52
|
+
*/
|
|
53
|
+
addUpdate(item, conditionFailedMsg) {
|
|
54
|
+
this.trackErrorMessage(conditionFailedMsg);
|
|
55
|
+
this.#transactionItems.push({ Update: item });
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Add a delete operation to the transaction
|
|
59
|
+
* @param item
|
|
60
|
+
*/
|
|
61
|
+
addDelete(item, conditionFailedMsg) {
|
|
62
|
+
this.trackErrorMessage(conditionFailedMsg);
|
|
63
|
+
this.#transactionItems.push({ Delete: item });
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Track error messages to return if there is a ConditionalCheckFailed exception
|
|
67
|
+
*
|
|
68
|
+
* IMPORTANT - Call this before adding the transaction to this.#transactionItems
|
|
69
|
+
* @param errMsg The custom error message to return if there is a ConditionalCheckFailed exception
|
|
70
|
+
*/
|
|
71
|
+
trackErrorMessage(errMsg) {
|
|
72
|
+
if (errMsg !== undefined) {
|
|
73
|
+
this.#errorMessages[this.#transactionItems.length] = errMsg;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Handle TransactionCanceledException, aggregating errors and applying friendly errors if provided.
|
|
78
|
+
* @param error
|
|
79
|
+
* @returns
|
|
80
|
+
*/
|
|
81
|
+
buildTransactionCanceledException(error) {
|
|
82
|
+
if (error.CancellationReasons !== undefined) {
|
|
83
|
+
const reasons = error.CancellationReasons;
|
|
84
|
+
const conditionFailedErrs = reasons.reduce((errors, reason, idx) => {
|
|
85
|
+
if (reason.Code === "ConditionalCheckFailed") {
|
|
86
|
+
const failure = this.#errorMessages[idx] ?? reason.Message;
|
|
87
|
+
const msg = `${reason.Code}: ${failure}`;
|
|
88
|
+
errors.push(new errors_1.ConditionalCheckFailedError(msg));
|
|
89
|
+
}
|
|
90
|
+
return errors;
|
|
91
|
+
}, []);
|
|
92
|
+
if (conditionFailedErrs.length > 0) {
|
|
93
|
+
Logger_1.default.error(conditionFailedErrs.map(err => err.message));
|
|
94
|
+
return new errors_1.TransactionWriteFailedError(conditionFailedErrs, "Failed Conditional Checks", { cause: error });
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return error;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.default = TransactionBuilder;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error thrown if a condition within a dynamo operation fails
|
|
3
|
+
*/
|
|
4
|
+
export declare class ConditionalCheckFailedError extends Error {
|
|
5
|
+
readonly code = "ConditionalCheckFailedError";
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* AggregateError thrown if a transaction fails. Check errors for reasons
|
|
9
|
+
*/
|
|
10
|
+
export declare class TransactionWriteFailedError extends AggregateError {
|
|
11
|
+
readonly code = "TransactionWriteFailedError";
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/dynamo-utils/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,2BAA4B,SAAQ,KAAK;IACpD,SAAgB,IAAI,iCAAiC;CACtD;AAED;;GAEG;AACH,qBAAa,2BAA4B,SAAQ,cAAc;IAC7D,SAAgB,IAAI,iCAAiC;CACtD"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TransactionWriteFailedError = exports.ConditionalCheckFailedError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Error thrown if a condition within a dynamo operation fails
|
|
6
|
+
*/
|
|
7
|
+
class ConditionalCheckFailedError extends Error {
|
|
8
|
+
code = "ConditionalCheckFailedError";
|
|
9
|
+
}
|
|
10
|
+
exports.ConditionalCheckFailedError = ConditionalCheckFailedError;
|
|
11
|
+
/**
|
|
12
|
+
* AggregateError thrown if a transaction fails. Check errors for reasons
|
|
13
|
+
*/
|
|
14
|
+
class TransactionWriteFailedError extends AggregateError {
|
|
15
|
+
code = "TransactionWriteFailedError";
|
|
16
|
+
}
|
|
17
|
+
exports.TransactionWriteFailedError = TransactionWriteFailedError;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { default as TransactWriteBuilder } from "./TransactWriteBuilder";
|
|
2
|
+
export { default as TransactGetBuilder } from "./TransactGetBuilder";
|
|
3
|
+
export { default as DynamoClient } from "./DynamoClient";
|
|
4
|
+
export * from "./TransactWriteBuilder";
|
|
5
|
+
export * from "./TransactGetBuilder";
|
|
6
|
+
export * from "./errors";
|
|
7
|
+
export * from "./types";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/dynamo-utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEzD,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
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.DynamoClient = exports.TransactGetBuilder = exports.TransactWriteBuilder = void 0;
|
|
21
|
+
var TransactWriteBuilder_1 = require("./TransactWriteBuilder");
|
|
22
|
+
Object.defineProperty(exports, "TransactWriteBuilder", { enumerable: true, get: function () { return __importDefault(TransactWriteBuilder_1).default; } });
|
|
23
|
+
var TransactGetBuilder_1 = require("./TransactGetBuilder");
|
|
24
|
+
Object.defineProperty(exports, "TransactGetBuilder", { enumerable: true, get: function () { return __importDefault(TransactGetBuilder_1).default; } });
|
|
25
|
+
var DynamoClient_1 = require("./DynamoClient");
|
|
26
|
+
Object.defineProperty(exports, "DynamoClient", { enumerable: true, get: function () { return __importDefault(DynamoClient_1).default; } });
|
|
27
|
+
__exportStar(require("./TransactWriteBuilder"), exports);
|
|
28
|
+
__exportStar(require("./TransactGetBuilder"), exports);
|
|
29
|
+
__exportStar(require("./errors"), exports);
|
|
30
|
+
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { QueryCommandOutput, TransactGetCommandOutput, TransactGetCommandInput, TransactWriteCommandInput } from "@aws-sdk/lib-dynamodb";
|
|
2
|
+
/**
|
|
3
|
+
* Represents the responses from a `TransactGetItems` operation in DynamoDB.
|
|
4
|
+
*/
|
|
5
|
+
export type TransactGetItemResponses = NonNullable<TransactGetCommandOutput["Responses"]>;
|
|
6
|
+
/**
|
|
7
|
+
* Represents the items returned from a `Query` operation in DynamoDB.
|
|
8
|
+
*/
|
|
9
|
+
export type QueryItems = NonNullable<QueryCommandOutput["Items"]>;
|
|
10
|
+
/**
|
|
11
|
+
* Represents a non-nullable version of the `TransactItems` array from the `TransactGetCommandInput` interface. This type ensures that the `TransactItems` array cannot be null, enhancing type safety by enforcing the presence of transaction items in operations that require them. It is commonly used in contexts where a transaction involves multiple actions, and each item in the transaction must be explicitly defined without allowing for null values.
|
|
12
|
+
*
|
|
13
|
+
* @type {TransactItems} A type derived from `TransactGetCommandInput["TransactItems"]`, guaranteed to be non-nullable, representing an array of transaction items in a DynamoDB transaction.
|
|
14
|
+
*/
|
|
15
|
+
export type TransactGetItems = NonNullable<TransactGetCommandInput["TransactItems"]>;
|
|
16
|
+
/**
|
|
17
|
+
* Represents a non-nullable version of the `Get` operation within a `TransactItems` array item. This type is used to enforce the presence and correct structure of a `Get` operation within a transaction item, providing stronger type guarantees and facilitating the use of IntelliSense and compile-time checks in development environments.
|
|
18
|
+
*
|
|
19
|
+
* @type {Get} A derived type from `TransactItems[number]["Get"]`, guaranteed to be non-nullable, representing the structure of a `Get` operation in a DynamoDB transaction item.
|
|
20
|
+
*/
|
|
21
|
+
export type Get = NonNullable<TransactGetItems[number]["Get"]>;
|
|
22
|
+
/**
|
|
23
|
+
* Represents a non-nullable version of the `TransactItems` array from the `TransactWriteCommandInput` interface. This type is crucial for operations that involve multiple write actions within a single transaction in DynamoDB, ensuring that the array of transaction items is always defined and non-null.
|
|
24
|
+
*
|
|
25
|
+
* @type {TransactWriteItems} A type derived from `TransactWriteCommandInput["TransactItems"]`, guaranteed to be non-nullable, indicating an array of transaction items for write operations in DynamoDB.
|
|
26
|
+
*/
|
|
27
|
+
export type TransactWriteItems = NonNullable<TransactWriteCommandInput["TransactItems"]>;
|
|
28
|
+
/**
|
|
29
|
+
* Represents the non-nullable structure of a `ConditionCheck` operation within a transaction item in DynamoDB. This type is essential for transactions that include condition checks to ensure specific prerequisites are met before executing the transaction. It enforces the presence and proper structure of condition check operations within transaction items.
|
|
30
|
+
*
|
|
31
|
+
* @type {ConditionCheck} A derived type from `TransactWriteItems[number]["ConditionCheck"]`, guaranteed to be non-nullable, specifying the structure of a `ConditionCheck` operation in a DynamoDB transaction item.
|
|
32
|
+
*/
|
|
33
|
+
export type ConditionCheck = NonNullable<TransactWriteItems[number]["ConditionCheck"]>;
|
|
34
|
+
/**
|
|
35
|
+
* Represents the non-nullable structure of a `Put` operation within a transaction item in DynamoDB. This type ensures that `Put` operations, which create or overwrite items in a table, are always present and correctly structured within transaction items, enhancing type safety and clarity in DynamoDB transactions.
|
|
36
|
+
*
|
|
37
|
+
* @type {Put} A derived type from `TransactWriteItems[number]["Put"]`, guaranteed to be non-nullable, detailing the structure of a `Put` operation in a DynamoDB transaction item.
|
|
38
|
+
*/
|
|
39
|
+
export type Put = NonNullable<TransactWriteItems[number]["Put"]>;
|
|
40
|
+
/**
|
|
41
|
+
* Represents the non-nullable structure of an `Update` operation within a transaction item in DynamoDB. This type is used to enforce the presence and correct structure of `Update` operations, which modify existing items in a table, within transaction items. It contributes to clearer and safer transaction definitions in DynamoDB operations.
|
|
42
|
+
*
|
|
43
|
+
* @type {Update} A derived type from `TransactWriteItems[number]["Update"]`, guaranteed to be non-nullable, outlining the structure of an `Update` operation in a DynamoDB transaction item.
|
|
44
|
+
*/
|
|
45
|
+
export type Update = NonNullable<TransactWriteItems[number]["Update"]>;
|
|
46
|
+
/**
|
|
47
|
+
* Represents the non-nullable structure of a `Delete` operation within a transaction item in DynamoDB. This type ensures that `Delete` operations, which remove items from a table, are always present and correctly structured within transaction items, providing stronger guarantees about transaction item configurations.
|
|
48
|
+
*
|
|
49
|
+
* @type {Delete} A derived type from `TransactWriteItems[number]["Delete"]`, guaranteed to be non-nullable, specifying the structure of a `Delete` operation in a DynamoDB transaction item.
|
|
50
|
+
*/
|
|
51
|
+
export type Delete = NonNullable<TransactWriteItems[number]["Delete"]>;
|
|
52
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/dynamo-utils/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,wBAAwB,EACxB,uBAAuB,EACvB,yBAAyB,EAC1B,MAAM,uBAAuB,CAAC;AAE/B;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG,WAAW,CAChD,wBAAwB,CAAC,WAAW,CAAC,CACtC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,WAAW,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC;AAElE;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,WAAW,CACxC,uBAAuB,CAAC,eAAe,CAAC,CACzC,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,GAAG,GAAG,WAAW,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;AAE/D;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG,WAAW,CAC1C,yBAAyB,CAAC,eAAe,CAAC,CAC3C,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG,WAAW,CACtC,kBAAkB,CAAC,MAAM,CAAC,CAAC,gBAAgB,CAAC,CAC7C,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,GAAG,GAAG,WAAW,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;AAEjE;;;;GAIG;AACH,MAAM,MAAM,MAAM,GAAG,WAAW,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;AAEvE;;;;GAIG;AACH,MAAM,MAAM,MAAM,GAAG,WAAW,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents an error indicating a violation of a null constraint within the ORM system. This error is typically thrown when an operation attempts to set a non-nullable attribute to `null`, which would violate the data integrity rules of the database schema.
|
|
3
|
+
*/
|
|
4
|
+
export declare class NullConstraintViolationError extends Error {
|
|
5
|
+
readonly code = "NullConstraintViolationError";
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Represents an error indicating that a requested entity or item could not be found within the database. This error is thrown during operations that expect to find and return a specific item, but the item does not exist in the database.
|
|
9
|
+
*/
|
|
10
|
+
export declare class NotFoundError extends Error {
|
|
11
|
+
readonly code = "NotFoundError";
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,4BAA6B,SAAQ,KAAK;IACrD,SAAgB,IAAI,kCAAkC;CACvD;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACtC,SAAgB,IAAI,mBAAmB;CACxC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NotFoundError = exports.NullConstraintViolationError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Represents an error indicating a violation of a null constraint within the ORM system. This error is typically thrown when an operation attempts to set a non-nullable attribute to `null`, which would violate the data integrity rules of the database schema.
|
|
6
|
+
*/
|
|
7
|
+
class NullConstraintViolationError extends Error {
|
|
8
|
+
code = "NullConstraintViolationError";
|
|
9
|
+
}
|
|
10
|
+
exports.NullConstraintViolationError = NullConstraintViolationError;
|
|
11
|
+
/**
|
|
12
|
+
* Represents an error indicating that a requested entity or item could not be found within the database. This error is thrown during operations that expect to find and return a specific item, but the item does not exist in the database.
|
|
13
|
+
*/
|
|
14
|
+
class NotFoundError extends Error {
|
|
15
|
+
code = "NotFoundError";
|
|
16
|
+
}
|
|
17
|
+
exports.NotFoundError = NotFoundError;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,cAAc,CAAC;AAEtC,eAAe,UAAU,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
const DynaRecord_1 = __importDefault(require("./DynaRecord"));
|
|
21
|
+
exports.default = DynaRecord_1.default;
|
|
22
|
+
__exportStar(require("./types"), exports);
|
|
23
|
+
__exportStar(require("./decorators"), exports);
|
|
24
|
+
__exportStar(require("./errors"), exports);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { AttributeMetadataOptions, Serializers } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Represents the metadata for an attribute of an entity, including its name, alias (if any), nullability, and serialization strategies.
|
|
4
|
+
*
|
|
5
|
+
* Serialization strategies are essential for attributes whose types do not natively exist in DynamoDB, such as `Date` objects, enabling custom conversion between the entity representation and the database representation. These strategies ensure that the ORM can seamlessly handle a wide range of attribute types beyond those natively supported by DynamoDB.
|
|
6
|
+
*
|
|
7
|
+
* @property {string} name - The name of the attribute as defined on the entity. This serves as the primary identifier for the attribute within the ORM.
|
|
8
|
+
* @property {string} alias - The name of the attribute as defined in the database table. If not provided, it defaults to the name of the attribute. This alias is used for database operations to map the attribute to its corresponding database column.
|
|
9
|
+
* @property {boolean} nullable - Indicates whether the attribute can be `null`, defining the attribute's nullability constraint within the database.
|
|
10
|
+
* @property {Serializers | undefined} serializers - Optional serialization strategies for converting the attribute between its database representation and its entity representation. This is particularly useful for custom data types not natively supported by DynamoDB.
|
|
11
|
+
*
|
|
12
|
+
* @param {AttributeMetadataOptions} options - Configuration options for the attribute metadata, including the attribute's name, optional alias, nullability, and serialization strategies.
|
|
13
|
+
*/
|
|
14
|
+
declare class AttributeMetadata {
|
|
15
|
+
readonly name: string;
|
|
16
|
+
readonly alias: string;
|
|
17
|
+
readonly nullable: boolean;
|
|
18
|
+
readonly serializers?: Serializers;
|
|
19
|
+
constructor(options: AttributeMetadataOptions);
|
|
20
|
+
}
|
|
21
|
+
export default AttributeMetadata;
|
|
22
|
+
//# sourceMappingURL=AttributeMetadata.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AttributeMetadata.d.ts","sourceRoot":"","sources":["../../../src/metadata/AttributeMetadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAErE;;;;;;;;;;;GAWG;AACH,cAAM,iBAAiB;IACrB,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,SAAgB,KAAK,EAAE,MAAM,CAAC;IAC9B,SAAgB,QAAQ,EAAE,OAAO,CAAC;IAClC,SAAgB,WAAW,CAAC,EAAE,WAAW,CAAC;gBAE9B,OAAO,EAAE,wBAAwB;CAM9C;AAED,eAAe,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Represents the metadata for an attribute of an entity, including its name, alias (if any), nullability, and serialization strategies.
|
|
5
|
+
*
|
|
6
|
+
* Serialization strategies are essential for attributes whose types do not natively exist in DynamoDB, such as `Date` objects, enabling custom conversion between the entity representation and the database representation. These strategies ensure that the ORM can seamlessly handle a wide range of attribute types beyond those natively supported by DynamoDB.
|
|
7
|
+
*
|
|
8
|
+
* @property {string} name - The name of the attribute as defined on the entity. This serves as the primary identifier for the attribute within the ORM.
|
|
9
|
+
* @property {string} alias - The name of the attribute as defined in the database table. If not provided, it defaults to the name of the attribute. This alias is used for database operations to map the attribute to its corresponding database column.
|
|
10
|
+
* @property {boolean} nullable - Indicates whether the attribute can be `null`, defining the attribute's nullability constraint within the database.
|
|
11
|
+
* @property {Serializers | undefined} serializers - Optional serialization strategies for converting the attribute between its database representation and its entity representation. This is particularly useful for custom data types not natively supported by DynamoDB.
|
|
12
|
+
*
|
|
13
|
+
* @param {AttributeMetadataOptions} options - Configuration options for the attribute metadata, including the attribute's name, optional alias, nullability, and serialization strategies.
|
|
14
|
+
*/
|
|
15
|
+
class AttributeMetadata {
|
|
16
|
+
name;
|
|
17
|
+
alias;
|
|
18
|
+
nullable;
|
|
19
|
+
serializers;
|
|
20
|
+
constructor(options) {
|
|
21
|
+
this.name = options.attributeName;
|
|
22
|
+
this.alias = options.alias ?? options.attributeName;
|
|
23
|
+
this.nullable = options.nullable;
|
|
24
|
+
this.serializers = options.serializers;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.default = AttributeMetadata;
|