@itzworking/single-table 0.0.162 → 0.0.196
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-cjs/dynamodb/dynamodb.js +17 -0
- package/{dist → dist-cjs}/errors/decorators-error.js +1 -1
- package/{dist → dist-cjs}/errors/generate-update-expression-error.js +1 -1
- package/{dist → dist-cjs}/errors/index-decorator-error.js +1 -1
- package/{dist → dist-cjs}/errors/key-composition-error.js +1 -1
- package/{dist → dist-cjs}/errors/single-table-error.js +1 -1
- package/{dist → dist-cjs}/errors/single-table-item-format-error.js +1 -1
- package/dist-cjs/single-table-item/single-table-item.js +261 -0
- package/dist-cjs/single-table-item/utils/validate-entity-annotations.js +20 -0
- package/{dist → dist-cjs}/single-table-repository/single-table-repository.js +0 -22
- package/dist-es/decorators/editable/editable.js +4 -0
- package/dist-es/decorators/editable/index.js +2 -0
- package/dist-es/decorators/editable/is-editable.js +4 -0
- package/dist-es/decorators/editable/symbol.js +1 -0
- package/dist-es/decorators/entity/entity.js +6 -0
- package/dist-es/decorators/entity/get-entity-name.js +4 -0
- package/dist-es/decorators/entity/index.js +2 -0
- package/dist-es/decorators/entity/symbol.js +1 -0
- package/dist-es/decorators/gsis/get-pk-composition.js +4 -0
- package/dist-es/decorators/gsis/get-sk-composition.js +4 -0
- package/dist-es/decorators/gsis/gsis.js +15 -0
- package/dist-es/decorators/gsis/index.js +3 -0
- package/dist-es/decorators/gsis/symbols.js +8 -0
- package/dist-es/decorators/gsis/types.js +1 -0
- package/dist-es/decorators/index.js +4 -0
- package/dist-es/dynamodb/delete-dynamodb-item.js +24 -0
- package/dist-es/dynamodb/dynamodb.js +14 -0
- package/dist-es/dynamodb/get-dynamodb-item.js +24 -0
- package/dist-es/dynamodb/index.js +7 -0
- package/dist-es/dynamodb/put-dynamodb-item.js +28 -0
- package/dist-es/dynamodb/query-all-dynamodb.js +19 -0
- package/dist-es/dynamodb/query-dynamodb.js +28 -0
- package/dist-es/dynamodb/update-dynamodb-item.js +24 -0
- package/dist-es/errors/decorators-error.js +10 -0
- package/dist-es/errors/generate-update-expression-error.js +10 -0
- package/dist-es/errors/index-decorator-error.js +10 -0
- package/dist-es/errors/index.js +5 -0
- package/dist-es/errors/key-composition-error.js +10 -0
- package/dist-es/errors/single-table-error.js +10 -0
- package/dist-es/errors/single-table-item-format-error.js +10 -0
- package/dist-es/index.js +6 -0
- package/dist-es/single-table-item/index.js +1 -0
- package/dist-es/single-table-item/single-table-item.js +257 -0
- package/dist-es/single-table-item/utils/capitalize-first-letter.js +3 -0
- package/dist-es/single-table-item/utils/handle-composite-primary-key.js +33 -0
- package/dist-es/single-table-item/utils/index.js +3 -0
- package/dist-es/single-table-item/utils/validate-entity-annotations.js +16 -0
- package/dist-es/single-table-repository/index.js +2 -0
- package/dist-es/single-table-repository/single-table-repository.js +189 -0
- package/dist-es/single-table-repository/types.js +1 -0
- package/dist-es/types.js +1 -0
- package/{dist → dist-types}/decorators/editable/editable.d.ts +0 -1
- package/{dist → dist-types}/decorators/editable/index.d.ts +0 -1
- package/{dist → dist-types}/decorators/editable/is-editable.d.ts +0 -1
- package/{dist → dist-types}/decorators/editable/symbol.d.ts +0 -1
- package/{dist → dist-types}/decorators/entity/entity.d.ts +0 -1
- package/{dist → dist-types}/decorators/entity/get-entity-name.d.ts +0 -1
- package/{dist → dist-types}/decorators/entity/index.d.ts +0 -1
- package/{dist → dist-types}/decorators/entity/symbol.d.ts +0 -1
- package/{dist → dist-types}/decorators/gsis/get-pk-composition.d.ts +0 -1
- package/{dist → dist-types}/decorators/gsis/get-sk-composition.d.ts +0 -1
- package/{dist → dist-types}/decorators/gsis/gsis.d.ts +0 -1
- package/{dist → dist-types}/decorators/gsis/index.d.ts +0 -1
- package/{dist → dist-types}/decorators/gsis/symbols.d.ts +0 -1
- package/{dist → dist-types}/decorators/gsis/types.d.ts +0 -1
- package/{dist → dist-types}/decorators/index.d.ts +0 -1
- package/{dist → dist-types}/dynamodb/delete-dynamodb-item.d.ts +0 -1
- package/{dist → dist-types}/dynamodb/dynamodb.d.ts +0 -1
- package/{dist → dist-types}/dynamodb/get-dynamodb-item.d.ts +0 -1
- package/{dist → dist-types}/dynamodb/index.d.ts +0 -1
- package/{dist → dist-types}/dynamodb/put-dynamodb-item.d.ts +0 -1
- package/{dist → dist-types}/dynamodb/query-all-dynamodb.d.ts +0 -1
- package/{dist → dist-types}/dynamodb/query-dynamodb.d.ts +0 -1
- package/{dist → dist-types}/dynamodb/update-dynamodb-item.d.ts +0 -1
- package/{dist → dist-types}/errors/decorators-error.d.ts +0 -1
- package/{dist → dist-types}/errors/generate-update-expression-error.d.ts +0 -1
- package/{dist → dist-types}/errors/index-decorator-error.d.ts +0 -1
- package/{dist → dist-types}/errors/index.d.ts +0 -1
- package/{dist → dist-types}/errors/key-composition-error.d.ts +0 -1
- package/{dist → dist-types}/errors/single-table-error.d.ts +0 -1
- package/{dist → dist-types}/errors/single-table-item-format-error.d.ts +0 -1
- package/{dist → dist-types}/index.d.ts +0 -1
- package/{dist → dist-types}/single-table-item/index.d.ts +0 -1
- package/{dist → dist-types}/single-table-item/single-table-item.d.ts +0 -1
- package/{dist → dist-types}/single-table-item/utils/capitalize-first-letter.d.ts +0 -1
- package/{dist → dist-types}/single-table-item/utils/handle-composite-primary-key.d.ts +0 -1
- package/{dist → dist-types}/single-table-item/utils/index.d.ts +0 -1
- package/{dist → dist-types}/single-table-item/utils/validate-entity-annotations.d.ts +0 -1
- package/{dist → dist-types}/single-table-repository/index.d.ts +0 -1
- package/{dist → dist-types}/single-table-repository/single-table-repository.d.ts +0 -1
- package/{dist → dist-types}/single-table-repository/types.d.ts +0 -1
- package/{dist → dist-types}/types.d.ts +0 -1
- package/package.json +26 -26
- package/dist/decorators/editable/editable.d.ts.map +0 -1
- package/dist/decorators/editable/index.d.ts.map +0 -1
- package/dist/decorators/editable/is-editable.d.ts.map +0 -1
- package/dist/decorators/editable/symbol.d.ts.map +0 -1
- package/dist/decorators/entity/entity.d.ts.map +0 -1
- package/dist/decorators/entity/get-entity-name.d.ts.map +0 -1
- package/dist/decorators/entity/index.d.ts.map +0 -1
- package/dist/decorators/entity/symbol.d.ts.map +0 -1
- package/dist/decorators/gsis/get-pk-composition.d.ts.map +0 -1
- package/dist/decorators/gsis/get-sk-composition.d.ts.map +0 -1
- package/dist/decorators/gsis/gsis.d.ts.map +0 -1
- package/dist/decorators/gsis/index.d.ts.map +0 -1
- package/dist/decorators/gsis/symbols.d.ts.map +0 -1
- package/dist/decorators/gsis/types.d.ts.map +0 -1
- package/dist/decorators/index.d.ts.map +0 -1
- package/dist/dynamodb/delete-dynamodb-item.d.ts.map +0 -1
- package/dist/dynamodb/dynamodb.d.ts.map +0 -1
- package/dist/dynamodb/dynamodb.js +0 -24
- package/dist/dynamodb/get-dynamodb-item.d.ts.map +0 -1
- package/dist/dynamodb/index.d.ts.map +0 -1
- package/dist/dynamodb/put-dynamodb-item.d.ts.map +0 -1
- package/dist/dynamodb/query-all-dynamodb.d.ts.map +0 -1
- package/dist/dynamodb/query-dynamodb.d.ts.map +0 -1
- package/dist/dynamodb/update-dynamodb-item.d.ts.map +0 -1
- package/dist/errors/decorators-error.d.ts.map +0 -1
- package/dist/errors/generate-update-expression-error.d.ts.map +0 -1
- package/dist/errors/index-decorator-error.d.ts.map +0 -1
- package/dist/errors/index.d.ts.map +0 -1
- package/dist/errors/key-composition-error.d.ts.map +0 -1
- package/dist/errors/single-table-error.d.ts.map +0 -1
- package/dist/errors/single-table-item-format-error.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/single-table-item/index.d.ts.map +0 -1
- package/dist/single-table-item/single-table-item.d.ts.map +0 -1
- package/dist/single-table-item/single-table-item.js +0 -281
- package/dist/single-table-item/utils/capitalize-first-letter.d.ts.map +0 -1
- package/dist/single-table-item/utils/handle-composite-primary-key.d.ts.map +0 -1
- package/dist/single-table-item/utils/index.d.ts.map +0 -1
- package/dist/single-table-item/utils/validate-entity-annotations.d.ts.map +0 -1
- package/dist/single-table-item/utils/validate-entity-annotations.js +0 -38
- package/dist/single-table-repository/index.d.ts.map +0 -1
- package/dist/single-table-repository/single-table-repository.d.ts.map +0 -1
- package/dist/single-table-repository/types.d.ts.map +0 -1
- package/dist/types.d.ts.map +0 -1
- /package/{dist → dist-cjs}/decorators/editable/editable.js +0 -0
- /package/{dist → dist-cjs}/decorators/editable/index.js +0 -0
- /package/{dist → dist-cjs}/decorators/editable/is-editable.js +0 -0
- /package/{dist → dist-cjs}/decorators/editable/symbol.js +0 -0
- /package/{dist → dist-cjs}/decorators/entity/entity.js +0 -0
- /package/{dist → dist-cjs}/decorators/entity/get-entity-name.js +0 -0
- /package/{dist → dist-cjs}/decorators/entity/index.js +0 -0
- /package/{dist → dist-cjs}/decorators/entity/symbol.js +0 -0
- /package/{dist → dist-cjs}/decorators/gsis/get-pk-composition.js +0 -0
- /package/{dist → dist-cjs}/decorators/gsis/get-sk-composition.js +0 -0
- /package/{dist → dist-cjs}/decorators/gsis/gsis.js +0 -0
- /package/{dist → dist-cjs}/decorators/gsis/index.js +0 -0
- /package/{dist → dist-cjs}/decorators/gsis/symbols.js +0 -0
- /package/{dist → dist-cjs}/decorators/gsis/types.js +0 -0
- /package/{dist → dist-cjs}/decorators/index.js +0 -0
- /package/{dist → dist-cjs}/dynamodb/delete-dynamodb-item.js +0 -0
- /package/{dist → dist-cjs}/dynamodb/get-dynamodb-item.js +0 -0
- /package/{dist → dist-cjs}/dynamodb/index.js +0 -0
- /package/{dist → dist-cjs}/dynamodb/put-dynamodb-item.js +0 -0
- /package/{dist → dist-cjs}/dynamodb/query-all-dynamodb.js +0 -0
- /package/{dist → dist-cjs}/dynamodb/query-dynamodb.js +0 -0
- /package/{dist → dist-cjs}/dynamodb/update-dynamodb-item.js +0 -0
- /package/{dist → dist-cjs}/errors/index.js +0 -0
- /package/{dist → dist-cjs}/index.js +0 -0
- /package/{dist → dist-cjs}/single-table-item/index.js +0 -0
- /package/{dist → dist-cjs}/single-table-item/utils/capitalize-first-letter.js +0 -0
- /package/{dist → dist-cjs}/single-table-item/utils/handle-composite-primary-key.js +0 -0
- /package/{dist → dist-cjs}/single-table-item/utils/index.js +0 -0
- /package/{dist → dist-cjs}/single-table-repository/index.js +0 -0
- /package/{dist → dist-cjs}/single-table-repository/types.js +0 -0
- /package/{dist → dist-cjs}/types.js +0 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dynamodb = void 0;
|
|
4
|
+
const client_dynamodb_1 = require("@aws-sdk/client-dynamodb");
|
|
5
|
+
const lib_dynamodb_1 = require("@aws-sdk/lib-dynamodb");
|
|
6
|
+
const marshallOptions = {
|
|
7
|
+
convertEmptyValues: false,
|
|
8
|
+
removeUndefinedValues: true,
|
|
9
|
+
convertClassInstanceToMap: true,
|
|
10
|
+
};
|
|
11
|
+
const unmarshallOptions = {
|
|
12
|
+
wrapNumbers: false,
|
|
13
|
+
};
|
|
14
|
+
exports.dynamodb = lib_dynamodb_1.DynamoDBDocumentClient.from(new client_dynamodb_1.DynamoDBClient({}), {
|
|
15
|
+
marshallOptions,
|
|
16
|
+
unmarshallOptions,
|
|
17
|
+
});
|
|
@@ -8,7 +8,7 @@ class DecoratorsError extends single_table_error_1.SingleTableError {
|
|
|
8
8
|
message,
|
|
9
9
|
});
|
|
10
10
|
this.name = "DecoratorsError";
|
|
11
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
11
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
exports.DecoratorsError = DecoratorsError;
|
|
@@ -8,7 +8,7 @@ class GenerateUpdateExpressionError extends single_table_error_1.SingleTableErro
|
|
|
8
8
|
message,
|
|
9
9
|
});
|
|
10
10
|
this.name = "GenerateUpdateExpressionError";
|
|
11
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
11
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
exports.GenerateUpdateExpressionError = GenerateUpdateExpressionError;
|
|
@@ -8,7 +8,7 @@ class IndexDecoratorError extends single_table_error_1.SingleTableError {
|
|
|
8
8
|
message,
|
|
9
9
|
});
|
|
10
10
|
this.name = "IndexDecoratorError";
|
|
11
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
11
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
exports.IndexDecoratorError = IndexDecoratorError;
|
|
@@ -8,7 +8,7 @@ class KeyCompositionError extends single_table_error_1.SingleTableError {
|
|
|
8
8
|
message,
|
|
9
9
|
});
|
|
10
10
|
this.name = "KeyCompositionError";
|
|
11
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
11
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
exports.KeyCompositionError = KeyCompositionError;
|
|
@@ -8,7 +8,7 @@ class SingleTableError extends Error {
|
|
|
8
8
|
const { statusCode = 500 } = props;
|
|
9
9
|
this.name = "SingleTableError";
|
|
10
10
|
this.statusCode = statusCode;
|
|
11
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
11
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
exports.SingleTableError = SingleTableError;
|
|
@@ -8,7 +8,7 @@ class SingleTableItemFormatError extends single_table_error_1.SingleTableError {
|
|
|
8
8
|
message,
|
|
9
9
|
});
|
|
10
10
|
this.name = "SingleTableItemFormatError";
|
|
11
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
11
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
exports.SingleTableItemFormatError = SingleTableItemFormatError;
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SingleTableItem = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const uuid_1 = require("uuid");
|
|
6
|
+
const decorators_1 = require("../decorators");
|
|
7
|
+
const utils_1 = require("./utils");
|
|
8
|
+
const errors_1 = require("../errors");
|
|
9
|
+
const decorated_class_1 = require("@itzworking/decorated-class");
|
|
10
|
+
class SingleTableItem extends decorated_class_1.DecoratedClass {
|
|
11
|
+
id;
|
|
12
|
+
createdAt;
|
|
13
|
+
updatedAt;
|
|
14
|
+
createdBy;
|
|
15
|
+
updatedBy;
|
|
16
|
+
deletedBy;
|
|
17
|
+
deletedAt;
|
|
18
|
+
constructor(props = {}) {
|
|
19
|
+
super(props);
|
|
20
|
+
(0, utils_1.validateEntityAnnotations)(this);
|
|
21
|
+
if (!props?.id) {
|
|
22
|
+
this.generateId();
|
|
23
|
+
}
|
|
24
|
+
if (!props?.createdAt) {
|
|
25
|
+
this.createdAt = new Date();
|
|
26
|
+
}
|
|
27
|
+
if (!props?.updatedAt) {
|
|
28
|
+
this.updatedAt = new Date();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
generateId() {
|
|
32
|
+
this.id = (0, uuid_1.v4)();
|
|
33
|
+
return this.id;
|
|
34
|
+
}
|
|
35
|
+
type() {
|
|
36
|
+
return (0, decorators_1.getEntityName)(this);
|
|
37
|
+
}
|
|
38
|
+
pk() {
|
|
39
|
+
const keys = (0, decorators_1.getPKComposition)(this);
|
|
40
|
+
if (!keys?.length) {
|
|
41
|
+
throw new errors_1.IndexDecoratorError(`@Entity("${this.type()}") @Index: PK is not defined`);
|
|
42
|
+
}
|
|
43
|
+
return (0, utils_1.handleCompositePrimaryKey)(this, keys);
|
|
44
|
+
}
|
|
45
|
+
sk() {
|
|
46
|
+
const keys = (0, decorators_1.getSKComposition)(this);
|
|
47
|
+
if (!keys?.length) {
|
|
48
|
+
throw new errors_1.IndexDecoratorError(`@Entity("${this.type()}") @Index: SK is not defined`);
|
|
49
|
+
}
|
|
50
|
+
return (0, utils_1.handleCompositePrimaryKey)(this, keys);
|
|
51
|
+
}
|
|
52
|
+
key() {
|
|
53
|
+
return {
|
|
54
|
+
PK: this.pk(),
|
|
55
|
+
SK: this.sk(),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
gsi1pk() {
|
|
59
|
+
return (0, utils_1.handleCompositePrimaryKey)(this, (0, decorators_1.getPKComposition)(this, "GSI1"));
|
|
60
|
+
}
|
|
61
|
+
gsi1sk() {
|
|
62
|
+
return (0, utils_1.handleCompositePrimaryKey)(this, (0, decorators_1.getSKComposition)(this, "GSI1"));
|
|
63
|
+
}
|
|
64
|
+
gsi2pk() {
|
|
65
|
+
return (0, utils_1.handleCompositePrimaryKey)(this, (0, decorators_1.getPKComposition)(this, "GSI2"));
|
|
66
|
+
}
|
|
67
|
+
gsi2sk() {
|
|
68
|
+
return (0, utils_1.handleCompositePrimaryKey)(this, (0, decorators_1.getSKComposition)(this, "GSI2"));
|
|
69
|
+
}
|
|
70
|
+
gsi3pk() {
|
|
71
|
+
return (0, utils_1.handleCompositePrimaryKey)(this, (0, decorators_1.getPKComposition)(this, "GSI3"));
|
|
72
|
+
}
|
|
73
|
+
gsi3sk() {
|
|
74
|
+
return (0, utils_1.handleCompositePrimaryKey)(this, (0, decorators_1.getSKComposition)(this, "GSI3"));
|
|
75
|
+
}
|
|
76
|
+
gsi4pk() {
|
|
77
|
+
return (0, utils_1.handleCompositePrimaryKey)(this, (0, decorators_1.getPKComposition)(this, "GSI4"));
|
|
78
|
+
}
|
|
79
|
+
gsi4sk() {
|
|
80
|
+
return (0, utils_1.handleCompositePrimaryKey)(this, (0, decorators_1.getSKComposition)(this, "GSI4"));
|
|
81
|
+
}
|
|
82
|
+
gsi5pk() {
|
|
83
|
+
return (0, utils_1.handleCompositePrimaryKey)(this, (0, decorators_1.getPKComposition)(this, "GSI5"));
|
|
84
|
+
}
|
|
85
|
+
gsi5sk() {
|
|
86
|
+
return (0, utils_1.handleCompositePrimaryKey)(this, (0, decorators_1.getSKComposition)(this, "GSI5"));
|
|
87
|
+
}
|
|
88
|
+
generateUpdateExpression(attributes = []) {
|
|
89
|
+
const attributesToUpdate = [];
|
|
90
|
+
const entityAttributes = (0, decorated_class_1.listAttributes)(this);
|
|
91
|
+
if (attributes?.length) {
|
|
92
|
+
for (const attribute of attributes) {
|
|
93
|
+
if (entityAttributes.find((ef) => ef.attributeName === attribute)) {
|
|
94
|
+
attributesToUpdate.push(attribute);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
throw new errors_1.GenerateUpdateExpressionError(`@Entity("${this.type()}"): ${attribute} is not an @Attribute`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
for (const attribute of entityAttributes) {
|
|
103
|
+
if (!(0, decorators_1.isEditable)(this, attribute.attributeName)) {
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
attributesToUpdate.push(attribute.attributeName);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (attributesToUpdate.length === 0) {
|
|
110
|
+
throw new errors_1.GenerateUpdateExpressionError(`@Entity("${this.type()}"): attributesToUpdate is empty; attributes = ${attributes}`);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
const indexComposition = {
|
|
114
|
+
PK: (0, decorators_1.getPKComposition)(this),
|
|
115
|
+
SK: (0, decorators_1.getSKComposition)(this),
|
|
116
|
+
};
|
|
117
|
+
const indexPkSkAttributes = [
|
|
118
|
+
...(indexComposition.PK || []),
|
|
119
|
+
...(indexComposition.SK || []),
|
|
120
|
+
];
|
|
121
|
+
const notAllowedAttributes = indexPkSkAttributes.filter((attribute) => attributesToUpdate.includes(attribute));
|
|
122
|
+
if (notAllowedAttributes.length > 0) {
|
|
123
|
+
throw new errors_1.GenerateUpdateExpressionError(`@Entity("${this.type()}"): cannot update @Index notAllowedAttributes = ${notAllowedAttributes}`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
const attributeValues = {};
|
|
127
|
+
const attributeNames = {};
|
|
128
|
+
const namesAndValues = [];
|
|
129
|
+
const attributesToRemove = [];
|
|
130
|
+
const gsis = {
|
|
131
|
+
GSI1: {
|
|
132
|
+
PK: (0, decorators_1.getPKComposition)(this, "GSI1"),
|
|
133
|
+
SK: (0, decorators_1.getSKComposition)(this, "GSI1"),
|
|
134
|
+
},
|
|
135
|
+
GSI2: {
|
|
136
|
+
PK: (0, decorators_1.getPKComposition)(this, "GSI2"),
|
|
137
|
+
SK: (0, decorators_1.getSKComposition)(this, "GSI2"),
|
|
138
|
+
},
|
|
139
|
+
GSI3: {
|
|
140
|
+
PK: (0, decorators_1.getPKComposition)(this, "GSI3"),
|
|
141
|
+
SK: (0, decorators_1.getSKComposition)(this, "GSI3"),
|
|
142
|
+
},
|
|
143
|
+
GSI4: {
|
|
144
|
+
PK: (0, decorators_1.getPKComposition)(this, "GSI4"),
|
|
145
|
+
SK: (0, decorators_1.getSKComposition)(this, "GSI4"),
|
|
146
|
+
},
|
|
147
|
+
GSI5: {
|
|
148
|
+
PK: (0, decorators_1.getPKComposition)(this, "GSI5"),
|
|
149
|
+
SK: (0, decorators_1.getSKComposition)(this, "GSI5"),
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
for (const [gsiKey, gsiComposition] of Object.entries(gsis)) {
|
|
153
|
+
for (const [gsiAttributeKey, gsiAttributeComposition] of Object.entries(gsiComposition)) {
|
|
154
|
+
if (gsiAttributeComposition?.some((key) => attributesToUpdate.includes(key))) {
|
|
155
|
+
attributeNames[`#key${gsiKey}${gsiAttributeKey}`] = `${gsiKey}${gsiAttributeKey}`;
|
|
156
|
+
attributeValues[`:value${gsiKey}${gsiAttributeKey}`] = this[`${gsiKey}${gsiAttributeKey}`.toLowerCase()]();
|
|
157
|
+
namesAndValues.push(`#key${gsiKey}${gsiAttributeKey} = :value${gsiKey}${gsiAttributeKey}`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
for (const key of attributesToUpdate) {
|
|
162
|
+
const keyToUse = (0, utils_1.capitalizeFirstLetter)(key);
|
|
163
|
+
const value = this[key];
|
|
164
|
+
attributeNames[`#key${keyToUse}`] = key;
|
|
165
|
+
if (value === undefined) {
|
|
166
|
+
attributesToRemove.push(`#key${keyToUse}`);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
attributeValues[`:value${keyToUse}`] =
|
|
170
|
+
value instanceof Date ? value.toISOString() : value;
|
|
171
|
+
namesAndValues.push(`#key${keyToUse} = :value${keyToUse}`);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return {
|
|
175
|
+
UpdateExpression: ((namesAndValues.length ? `SET ${namesAndValues.join(", ")} ` : "") +
|
|
176
|
+
(attributesToRemove.length
|
|
177
|
+
? `REMOVE ${attributesToRemove.join(", ")}`
|
|
178
|
+
: "")).trim(),
|
|
179
|
+
ExpressionAttributeNames: attributeNames,
|
|
180
|
+
ExpressionAttributeValues: attributeValues,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
toSingleTableItem() {
|
|
184
|
+
const result = {
|
|
185
|
+
type: this.type(),
|
|
186
|
+
...this.key(),
|
|
187
|
+
};
|
|
188
|
+
if (this.gsi1pk() && this.gsi1sk()) {
|
|
189
|
+
result.GSI1PK = this.gsi1pk();
|
|
190
|
+
result.GSI1SK = this.gsi1sk();
|
|
191
|
+
}
|
|
192
|
+
if (this.gsi2pk() && this.gsi2sk()) {
|
|
193
|
+
result.GSI2PK = this.gsi2pk();
|
|
194
|
+
result.GSI2SK = this.gsi2sk();
|
|
195
|
+
}
|
|
196
|
+
if (this.gsi3pk() && this.gsi3sk()) {
|
|
197
|
+
result.GSI3PK = this.gsi3pk();
|
|
198
|
+
result.GSI3SK = this.gsi3sk();
|
|
199
|
+
}
|
|
200
|
+
if (this.gsi4pk() && this.gsi4sk()) {
|
|
201
|
+
result.GSI4PK = this.gsi4pk();
|
|
202
|
+
result.GSI4SK = this.gsi4sk();
|
|
203
|
+
}
|
|
204
|
+
if (this.gsi5pk() && this.gsi5sk()) {
|
|
205
|
+
result.GSI5PK = this.gsi5pk();
|
|
206
|
+
result.GSI5SK = this.gsi5sk();
|
|
207
|
+
}
|
|
208
|
+
const attributes = (0, decorated_class_1.listAttributes)(this);
|
|
209
|
+
const reservedKeys = [
|
|
210
|
+
"type",
|
|
211
|
+
"PK",
|
|
212
|
+
"SK",
|
|
213
|
+
"GSI1PK",
|
|
214
|
+
"GSI1SK",
|
|
215
|
+
"GSI2PK",
|
|
216
|
+
"GSI2SK",
|
|
217
|
+
"GSI3PK",
|
|
218
|
+
"GSI3SK",
|
|
219
|
+
"GSI4PK",
|
|
220
|
+
"GSI4SK",
|
|
221
|
+
"GSI5PK",
|
|
222
|
+
"GSI5SK",
|
|
223
|
+
];
|
|
224
|
+
const reservedKeysInUse = reservedKeys.filter((reservedKey) => attributes.find((f) => f.attributeName === reservedKey));
|
|
225
|
+
if (reservedKeysInUse.length > 0) {
|
|
226
|
+
throw new errors_1.SingleTableItemFormatError(`@Entity("${this.type()}"): cannot use reserved keys in attributes = ${reservedKeysInUse}`);
|
|
227
|
+
}
|
|
228
|
+
for (const attribute of attributes) {
|
|
229
|
+
const value = this[attribute.attributeName];
|
|
230
|
+
if (value !== undefined) {
|
|
231
|
+
result[attribute.attributeName] =
|
|
232
|
+
value instanceof Date ? value.toISOString() : value;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return result;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
exports.SingleTableItem = SingleTableItem;
|
|
239
|
+
tslib_1.__decorate([
|
|
240
|
+
(0, decorated_class_1.Attribute)(decorated_class_1.AttributeType.String)
|
|
241
|
+
], SingleTableItem.prototype, "id", void 0);
|
|
242
|
+
tslib_1.__decorate([
|
|
243
|
+
(0, decorated_class_1.Attribute)(decorated_class_1.AttributeType.Date)
|
|
244
|
+
], SingleTableItem.prototype, "createdAt", void 0);
|
|
245
|
+
tslib_1.__decorate([
|
|
246
|
+
decorators_1.Editable,
|
|
247
|
+
(0, decorated_class_1.Attribute)(decorated_class_1.AttributeType.Date)
|
|
248
|
+
], SingleTableItem.prototype, "updatedAt", void 0);
|
|
249
|
+
tslib_1.__decorate([
|
|
250
|
+
(0, decorated_class_1.Attribute)(decorated_class_1.AttributeType.String)
|
|
251
|
+
], SingleTableItem.prototype, "createdBy", void 0);
|
|
252
|
+
tslib_1.__decorate([
|
|
253
|
+
decorators_1.Editable,
|
|
254
|
+
(0, decorated_class_1.Attribute)(decorated_class_1.AttributeType.String)
|
|
255
|
+
], SingleTableItem.prototype, "updatedBy", void 0);
|
|
256
|
+
tslib_1.__decorate([
|
|
257
|
+
(0, decorated_class_1.Attribute)(decorated_class_1.AttributeType.String)
|
|
258
|
+
], SingleTableItem.prototype, "deletedBy", void 0);
|
|
259
|
+
tslib_1.__decorate([
|
|
260
|
+
(0, decorated_class_1.Attribute)(decorated_class_1.AttributeType.Date)
|
|
261
|
+
], SingleTableItem.prototype, "deletedAt", void 0);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateEntityAnnotations = void 0;
|
|
4
|
+
const errors_1 = require("../../errors");
|
|
5
|
+
const validateEntityAnnotations = (entity) => {
|
|
6
|
+
const errors = [];
|
|
7
|
+
if (!entity.type()) {
|
|
8
|
+
errors.push("missing @Entity annotation on SingleTableItem class");
|
|
9
|
+
}
|
|
10
|
+
try {
|
|
11
|
+
entity.key();
|
|
12
|
+
}
|
|
13
|
+
catch (e) {
|
|
14
|
+
errors.push("missing @Index annotation on SingleTableItem class");
|
|
15
|
+
}
|
|
16
|
+
if (errors.length) {
|
|
17
|
+
throw new errors_1.DecoratorsError(errors.join(","));
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
exports.validateEntityAnnotations = validateEntityAnnotations;
|
|
@@ -187,28 +187,6 @@ class SingleTableRepository {
|
|
|
187
187
|
}
|
|
188
188
|
response.items.push(new entityClass(dynamodbItem));
|
|
189
189
|
}
|
|
190
|
-
// if (response.items.length > 0) {
|
|
191
|
-
// const classPriority: Map<EntityConstructor<U>, number> = new Map();
|
|
192
|
-
// let index = 0;
|
|
193
|
-
// for (const entityClass of options.entityClasses) {
|
|
194
|
-
// classPriority.set(entityClass, index);
|
|
195
|
-
// index++;
|
|
196
|
-
// }
|
|
197
|
-
// const classPriorityArray = Array.from(classPriority.keys());
|
|
198
|
-
// response.items.sort((a, b) => {
|
|
199
|
-
// const aPriority = classPriorityArray.findIndex(
|
|
200
|
-
// (constructorFn) => a instanceof constructorFn
|
|
201
|
-
// );
|
|
202
|
-
// const bPriority = classPriorityArray.findIndex(
|
|
203
|
-
// (constructorFn) => b instanceof constructorFn
|
|
204
|
-
// );
|
|
205
|
-
//
|
|
206
|
-
// const classCompare = aPriority - bPriority;
|
|
207
|
-
// if (classCompare !== 0) return classCompare;
|
|
208
|
-
//
|
|
209
|
-
// return a.createdAt.getTime() - b.createdAt.getTime();
|
|
210
|
-
// });
|
|
211
|
-
// }
|
|
212
190
|
return response;
|
|
213
191
|
}
|
|
214
192
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const symbol = Symbol("Editable");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const symbol = Symbol("EntityName");
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { symbols } from "./symbols";
|
|
2
|
+
const buildIndex = (name = "Index") => {
|
|
3
|
+
return (keyComposition) => {
|
|
4
|
+
return (constructor, context) => {
|
|
5
|
+
Reflect.defineMetadata(constructor.name + "#" + symbols[name].PK.toString(), keyComposition.PK, constructor);
|
|
6
|
+
Reflect.defineMetadata(constructor.name + "#" + symbols[name].SK.toString(), keyComposition.SK, constructor);
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export const Index = buildIndex();
|
|
11
|
+
export const GSI1 = buildIndex("GSI1");
|
|
12
|
+
export const GSI2 = buildIndex("GSI2");
|
|
13
|
+
export const GSI3 = buildIndex("GSI3");
|
|
14
|
+
export const GSI4 = buildIndex("GSI4");
|
|
15
|
+
export const GSI5 = buildIndex("GSI5");
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const symbols = {
|
|
2
|
+
Index: { PK: Symbol("IndexPK"), SK: Symbol("IndexSK") },
|
|
3
|
+
GSI1: { PK: Symbol("GSI1PK"), SK: Symbol("GSI1SK") },
|
|
4
|
+
GSI2: { PK: Symbol("GSI2PK"), SK: Symbol("GSI2SK") },
|
|
5
|
+
GSI3: { PK: Symbol("GSI3PK"), SK: Symbol("GSI3SK") },
|
|
6
|
+
GSI4: { PK: Symbol("GSI4PK"), SK: Symbol("GSI4SK") },
|
|
7
|
+
GSI5: { PK: Symbol("GSI5PK"), SK: Symbol("GSI5SK") },
|
|
8
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { DeleteCommand } from "@aws-sdk/lib-dynamodb";
|
|
2
|
+
import { logger } from "@itzworking/powertools";
|
|
3
|
+
import { dynamodb } from "./dynamodb";
|
|
4
|
+
export const deleteDynamodbItem = async (input) => {
|
|
5
|
+
logger.debug({
|
|
6
|
+
message: "send dynamodb DeleteCommand",
|
|
7
|
+
awsService: "dynamodb",
|
|
8
|
+
action: "DeleteCommand",
|
|
9
|
+
input,
|
|
10
|
+
});
|
|
11
|
+
try {
|
|
12
|
+
return dynamodb.send(new DeleteCommand(input));
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
logger.error({
|
|
16
|
+
message: "send dynamodb DeleteCommand",
|
|
17
|
+
awsService: "dynamodb",
|
|
18
|
+
action: "DeleteCommand",
|
|
19
|
+
input,
|
|
20
|
+
error,
|
|
21
|
+
});
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
|
|
2
|
+
import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb";
|
|
3
|
+
const marshallOptions = {
|
|
4
|
+
convertEmptyValues: false,
|
|
5
|
+
removeUndefinedValues: true,
|
|
6
|
+
convertClassInstanceToMap: true,
|
|
7
|
+
};
|
|
8
|
+
const unmarshallOptions = {
|
|
9
|
+
wrapNumbers: false,
|
|
10
|
+
};
|
|
11
|
+
export const dynamodb = DynamoDBDocumentClient.from(new DynamoDBClient({}), {
|
|
12
|
+
marshallOptions,
|
|
13
|
+
unmarshallOptions,
|
|
14
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { GetCommand } from "@aws-sdk/lib-dynamodb";
|
|
2
|
+
import { logger } from "@itzworking/powertools";
|
|
3
|
+
import { dynamodb } from "./dynamodb";
|
|
4
|
+
export const getDynamodbItem = async (input) => {
|
|
5
|
+
logger.debug({
|
|
6
|
+
message: "send dynamodb GetCommand",
|
|
7
|
+
awsService: "dynamodb",
|
|
8
|
+
action: "GetCommand",
|
|
9
|
+
input,
|
|
10
|
+
});
|
|
11
|
+
try {
|
|
12
|
+
return dynamodb.send(new GetCommand(input));
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
logger.error({
|
|
16
|
+
message: "send dynamodb GetCommand",
|
|
17
|
+
awsService: "dynamodb",
|
|
18
|
+
action: "GetCommand",
|
|
19
|
+
input,
|
|
20
|
+
error,
|
|
21
|
+
});
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { PutCommand } from "@aws-sdk/lib-dynamodb";
|
|
2
|
+
import { logger } from "@itzworking/powertools";
|
|
3
|
+
import { dynamodb } from "./dynamodb";
|
|
4
|
+
export const putDynamodbItem = async (input) => {
|
|
5
|
+
const updatedParams = {
|
|
6
|
+
ReturnValues: "NONE",
|
|
7
|
+
...input,
|
|
8
|
+
};
|
|
9
|
+
logger.debug({
|
|
10
|
+
message: "send dynamodb PutCommand",
|
|
11
|
+
awsService: "dynamodb",
|
|
12
|
+
action: "PutCommand",
|
|
13
|
+
input: updatedParams,
|
|
14
|
+
});
|
|
15
|
+
try {
|
|
16
|
+
return dynamodb.send(new PutCommand(updatedParams));
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
logger.error({
|
|
20
|
+
message: "send dynamodb PutCommand",
|
|
21
|
+
awsService: "dynamodb",
|
|
22
|
+
action: "PutCommand",
|
|
23
|
+
input: updatedParams,
|
|
24
|
+
error,
|
|
25
|
+
});
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { logger } from "@itzworking/powertools";
|
|
2
|
+
import { queryDynamodb } from "./query-dynamodb";
|
|
3
|
+
export const queryAllDynamodb = async (input) => {
|
|
4
|
+
logger.debug({
|
|
5
|
+
message: "send multiple dynamodb QueryCommand",
|
|
6
|
+
input,
|
|
7
|
+
});
|
|
8
|
+
const items = [];
|
|
9
|
+
let lastEvaluatedKey;
|
|
10
|
+
do {
|
|
11
|
+
const dynamodbResponse = await queryDynamodb({
|
|
12
|
+
...input,
|
|
13
|
+
ExclusiveStartKey: lastEvaluatedKey,
|
|
14
|
+
});
|
|
15
|
+
lastEvaluatedKey = dynamodbResponse.LastEvaluatedKey;
|
|
16
|
+
items.push(...(dynamodbResponse.Items || []));
|
|
17
|
+
} while (lastEvaluatedKey);
|
|
18
|
+
return items;
|
|
19
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { QueryCommand } from "@aws-sdk/lib-dynamodb";
|
|
2
|
+
import { logger } from "@itzworking/powertools";
|
|
3
|
+
import { dynamodb } from "./dynamodb";
|
|
4
|
+
export const queryDynamodb = async (input) => {
|
|
5
|
+
const updatedParams = {
|
|
6
|
+
ScanIndexForward: false,
|
|
7
|
+
...input,
|
|
8
|
+
};
|
|
9
|
+
logger.debug({
|
|
10
|
+
message: "send dynamodb QueryCommand",
|
|
11
|
+
awsService: "dynamodb",
|
|
12
|
+
action: "QueryCommand",
|
|
13
|
+
input: updatedParams,
|
|
14
|
+
});
|
|
15
|
+
try {
|
|
16
|
+
return dynamodb.send(new QueryCommand(updatedParams));
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
logger.error({
|
|
20
|
+
message: "send dynamodb QueryCommand",
|
|
21
|
+
awsService: "dynamodb",
|
|
22
|
+
action: "QueryCommand",
|
|
23
|
+
input: updatedParams,
|
|
24
|
+
error,
|
|
25
|
+
});
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { UpdateCommand } from "@aws-sdk/lib-dynamodb";
|
|
2
|
+
import { logger } from "@itzworking/powertools";
|
|
3
|
+
import { dynamodb } from "./dynamodb";
|
|
4
|
+
export const updateDynamodbItem = async (input) => {
|
|
5
|
+
logger.debug({
|
|
6
|
+
message: "send dynamodb UpdateCommand",
|
|
7
|
+
awsService: "dynamodb",
|
|
8
|
+
action: "UpdateCommand",
|
|
9
|
+
input,
|
|
10
|
+
});
|
|
11
|
+
try {
|
|
12
|
+
return dynamodb.send(new UpdateCommand(input));
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
logger.error({
|
|
16
|
+
message: "send dynamodb UpdateCommand",
|
|
17
|
+
awsService: "dynamodb",
|
|
18
|
+
action: "UpdateCommand",
|
|
19
|
+
input,
|
|
20
|
+
error,
|
|
21
|
+
});
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
};
|