@itzworking/single-table 0.0.157 → 0.0.159
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/decorators/editable/editable.js +7 -3
- package/dist/decorators/editable/index.js +5 -2
- package/dist/decorators/editable/is-editable.js +7 -3
- package/dist/decorators/editable/symbol.js +4 -1
- package/dist/decorators/entity/entity.js +7 -3
- package/dist/decorators/entity/get-entity-name.js +7 -3
- package/dist/decorators/entity/index.js +5 -2
- package/dist/decorators/entity/symbol.js +4 -1
- package/dist/decorators/gsis/get-pk-composition.js +7 -3
- package/dist/decorators/gsis/get-sk-composition.js +7 -3
- package/dist/decorators/gsis/gsis.js +12 -9
- package/dist/decorators/gsis/index.js +6 -3
- package/dist/decorators/gsis/symbols.js +4 -1
- package/dist/decorators/gsis/types.js +2 -1
- package/dist/decorators/index.js +7 -4
- package/dist/dynamodb/delete-dynamodb-item.js +11 -7
- package/dist/dynamodb/dynamodb.js +6 -3
- package/dist/dynamodb/get-dynamodb-item.js +11 -7
- package/dist/dynamodb/index.js +10 -7
- package/dist/dynamodb/put-dynamodb-item.js +11 -7
- package/dist/dynamodb/query-all-dynamodb.js +9 -5
- package/dist/dynamodb/query-dynamodb.js +11 -7
- package/dist/dynamodb/update-dynamodb-item.js +11 -7
- package/dist/errors/decorators-error.js +6 -2
- package/dist/errors/generate-update-expression-error.js +6 -2
- package/dist/errors/index-decorator-error.js +6 -2
- package/dist/errors/index.js +8 -5
- package/dist/errors/key-composition-error.js +6 -2
- package/dist/errors/single-table-error.js +5 -1
- package/dist/errors/single-table-item-format-error.js +6 -2
- package/dist/index.js +9 -6
- package/dist/single-table-item/index.js +4 -1
- package/dist/single-table-item/single-table-item.js +72 -69
- package/dist/single-table-item/utils/capitalize-first-letter.js +5 -1
- package/dist/single-table-item/utils/handle-composite-primary-key.js +11 -7
- package/dist/single-table-item/utils/index.js +6 -3
- package/dist/single-table-item/utils/validate-entity-annotations.js +7 -3
- package/dist/single-table-repository/index.js +5 -2
- package/dist/single-table-repository/single-table-repository.js +16 -12
- package/dist/single-table-repository/types.js +2 -1
- package/dist/types.js +2 -1
- package/package.json +4 -4
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Editable = void 0;
|
|
4
|
+
const symbol_1 = require("./symbol");
|
|
5
|
+
const Editable = (target, context) => {
|
|
6
|
+
Reflect.defineMetadata(symbol_1.symbol, true, target, typeof context === "string" ? context : context.name);
|
|
4
7
|
};
|
|
8
|
+
exports.Editable = Editable;
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./editable"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./is-editable"), exports);
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isEditable = void 0;
|
|
4
|
+
const symbol_1 = require("./symbol");
|
|
5
|
+
const isEditable = (target, propertyKey) => {
|
|
6
|
+
return !!Reflect.getMetadata(symbol_1.symbol, target, propertyKey);
|
|
4
7
|
};
|
|
8
|
+
exports.isEditable = isEditable;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Entity = void 0;
|
|
4
|
+
const symbol_1 = require("./symbol");
|
|
5
|
+
const Entity = (name) => {
|
|
3
6
|
return (constructor, ctx) => {
|
|
4
|
-
Reflect.defineMetadata(constructor.name + "#" + symbol.toString(), name, constructor);
|
|
7
|
+
Reflect.defineMetadata(constructor.name + "#" + symbol_1.symbol.toString(), name, constructor);
|
|
5
8
|
};
|
|
6
9
|
};
|
|
10
|
+
exports.Entity = Entity;
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getEntityName = void 0;
|
|
4
|
+
const symbol_1 = require("./symbol");
|
|
5
|
+
const getEntityName = (target) => {
|
|
6
|
+
return Reflect.getMetadata(target.constructor.name + "#" + symbol_1.symbol.toString(), target.constructor);
|
|
4
7
|
};
|
|
8
|
+
exports.getEntityName = getEntityName;
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./entity"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./get-entity-name"), exports);
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPKComposition = void 0;
|
|
4
|
+
const symbols_1 = require("./symbols");
|
|
5
|
+
const getPKComposition = (target, name = "Index") => {
|
|
6
|
+
return Reflect.getMetadata(target.constructor.name + "#" + symbols_1.symbols[name].PK.toString(), target.constructor);
|
|
4
7
|
};
|
|
8
|
+
exports.getPKComposition = getPKComposition;
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSKComposition = void 0;
|
|
4
|
+
const symbols_1 = require("./symbols");
|
|
5
|
+
const getSKComposition = (target, name = "Index") => {
|
|
6
|
+
return Reflect.getMetadata(target.constructor.name + "#" + symbols_1.symbols[name].SK.toString(), target.constructor);
|
|
4
7
|
};
|
|
8
|
+
exports.getSKComposition = getSKComposition;
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GSI5 = exports.GSI4 = exports.GSI3 = exports.GSI2 = exports.GSI1 = exports.Index = void 0;
|
|
4
|
+
const symbols_1 = require("./symbols");
|
|
2
5
|
const buildIndex = (name = "Index") => {
|
|
3
6
|
return (keyComposition) => {
|
|
4
7
|
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);
|
|
8
|
+
Reflect.defineMetadata(constructor.name + "#" + symbols_1.symbols[name].PK.toString(), keyComposition.PK, constructor);
|
|
9
|
+
Reflect.defineMetadata(constructor.name + "#" + symbols_1.symbols[name].SK.toString(), keyComposition.SK, constructor);
|
|
7
10
|
};
|
|
8
11
|
};
|
|
9
12
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
exports.Index = buildIndex();
|
|
14
|
+
exports.GSI1 = buildIndex("GSI1");
|
|
15
|
+
exports.GSI2 = buildIndex("GSI2");
|
|
16
|
+
exports.GSI3 = buildIndex("GSI3");
|
|
17
|
+
exports.GSI4 = buildIndex("GSI4");
|
|
18
|
+
exports.GSI5 = buildIndex("GSI5");
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./gsis"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./get-pk-composition"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./get-sk-composition"), exports);
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.symbols = void 0;
|
|
4
|
+
exports.symbols = {
|
|
2
5
|
Index: { PK: Symbol("IndexPK"), SK: Symbol("IndexSK") },
|
|
3
6
|
GSI1: { PK: Symbol("GSI1PK"), SK: Symbol("GSI1SK") },
|
|
4
7
|
GSI2: { PK: Symbol("GSI2PK"), SK: Symbol("GSI2SK") },
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/dist/decorators/index.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
tslib_1.__exportStar(require("./editable"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./entity"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./gsis"), exports);
|
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deleteDynamodbItem = void 0;
|
|
4
|
+
const lib_dynamodb_1 = require("@aws-sdk/lib-dynamodb");
|
|
5
|
+
const powertools_1 = require("@itzworking/powertools");
|
|
6
|
+
const dynamodb_1 = require("./dynamodb");
|
|
7
|
+
const deleteDynamodbItem = async (input) => {
|
|
8
|
+
powertools_1.logger.debug({
|
|
6
9
|
message: "send dynamodb DeleteCommand",
|
|
7
10
|
awsService: "dynamodb",
|
|
8
11
|
action: "DeleteCommand",
|
|
9
12
|
input,
|
|
10
13
|
});
|
|
11
14
|
try {
|
|
12
|
-
return dynamodb.send(new DeleteCommand(input));
|
|
15
|
+
return dynamodb_1.dynamodb.send(new lib_dynamodb_1.DeleteCommand(input));
|
|
13
16
|
}
|
|
14
17
|
catch (error) {
|
|
15
|
-
logger.error({
|
|
18
|
+
powertools_1.logger.error({
|
|
16
19
|
message: "send dynamodb DeleteCommand",
|
|
17
20
|
awsService: "dynamodb",
|
|
18
21
|
action: "DeleteCommand",
|
|
@@ -22,3 +25,4 @@ export const deleteDynamodbItem = async (input) => {
|
|
|
22
25
|
throw error;
|
|
23
26
|
}
|
|
24
27
|
};
|
|
28
|
+
exports.deleteDynamodbItem = deleteDynamodbItem;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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");
|
|
3
6
|
/**
|
|
4
7
|
* Define the DynamoDB Document Client
|
|
5
8
|
*/
|
|
@@ -15,7 +18,7 @@ const unmarshallOptions = {
|
|
|
15
18
|
// Whether to return numbers as a string instead of converting them to native JavaScript numbers.
|
|
16
19
|
wrapNumbers: false, // false, by default.
|
|
17
20
|
};
|
|
18
|
-
|
|
21
|
+
exports.dynamodb = lib_dynamodb_1.DynamoDBDocumentClient.from(new client_dynamodb_1.DynamoDBClient({}), {
|
|
19
22
|
marshallOptions,
|
|
20
23
|
unmarshallOptions,
|
|
21
24
|
});
|
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDynamodbItem = void 0;
|
|
4
|
+
const lib_dynamodb_1 = require("@aws-sdk/lib-dynamodb");
|
|
5
|
+
const powertools_1 = require("@itzworking/powertools");
|
|
6
|
+
const dynamodb_1 = require("./dynamodb");
|
|
7
|
+
const getDynamodbItem = async (input) => {
|
|
8
|
+
powertools_1.logger.debug({
|
|
6
9
|
message: "send dynamodb GetCommand",
|
|
7
10
|
awsService: "dynamodb",
|
|
8
11
|
action: "GetCommand",
|
|
9
12
|
input,
|
|
10
13
|
});
|
|
11
14
|
try {
|
|
12
|
-
return dynamodb.send(new GetCommand(input));
|
|
15
|
+
return dynamodb_1.dynamodb.send(new lib_dynamodb_1.GetCommand(input));
|
|
13
16
|
}
|
|
14
17
|
catch (error) {
|
|
15
|
-
logger.error({
|
|
18
|
+
powertools_1.logger.error({
|
|
16
19
|
message: "send dynamodb GetCommand",
|
|
17
20
|
awsService: "dynamodb",
|
|
18
21
|
action: "GetCommand",
|
|
@@ -22,3 +25,4 @@ export const getDynamodbItem = async (input) => {
|
|
|
22
25
|
throw error;
|
|
23
26
|
}
|
|
24
27
|
};
|
|
28
|
+
exports.getDynamodbItem = getDynamodbItem;
|
package/dist/dynamodb/index.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./dynamodb"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./delete-dynamodb-item"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./get-dynamodb-item"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./put-dynamodb-item"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./query-all-dynamodb"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./query-dynamodb"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./update-dynamodb-item"), exports);
|
|
@@ -1,22 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.putDynamodbItem = void 0;
|
|
4
|
+
const lib_dynamodb_1 = require("@aws-sdk/lib-dynamodb");
|
|
5
|
+
const powertools_1 = require("@itzworking/powertools");
|
|
6
|
+
const dynamodb_1 = require("./dynamodb");
|
|
7
|
+
const putDynamodbItem = async (input) => {
|
|
5
8
|
const updatedParams = {
|
|
6
9
|
ReturnValues: "NONE",
|
|
7
10
|
...input,
|
|
8
11
|
};
|
|
9
|
-
logger.debug({
|
|
12
|
+
powertools_1.logger.debug({
|
|
10
13
|
message: "send dynamodb PutCommand",
|
|
11
14
|
awsService: "dynamodb",
|
|
12
15
|
action: "PutCommand",
|
|
13
16
|
input: updatedParams,
|
|
14
17
|
});
|
|
15
18
|
try {
|
|
16
|
-
return dynamodb.send(new PutCommand(updatedParams));
|
|
19
|
+
return dynamodb_1.dynamodb.send(new lib_dynamodb_1.PutCommand(updatedParams));
|
|
17
20
|
}
|
|
18
21
|
catch (error) {
|
|
19
|
-
logger.error({
|
|
22
|
+
powertools_1.logger.error({
|
|
20
23
|
message: "send dynamodb PutCommand",
|
|
21
24
|
awsService: "dynamodb",
|
|
22
25
|
action: "PutCommand",
|
|
@@ -26,3 +29,4 @@ export const putDynamodbItem = async (input) => {
|
|
|
26
29
|
throw error;
|
|
27
30
|
}
|
|
28
31
|
};
|
|
32
|
+
exports.putDynamodbItem = putDynamodbItem;
|
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.queryAllDynamodb = void 0;
|
|
4
|
+
const powertools_1 = require("@itzworking/powertools");
|
|
5
|
+
const query_dynamodb_1 = require("./query-dynamodb");
|
|
6
|
+
const queryAllDynamodb = async (input) => {
|
|
7
|
+
powertools_1.logger.debug({
|
|
5
8
|
message: "send multiple dynamodb QueryCommand",
|
|
6
9
|
input,
|
|
7
10
|
});
|
|
8
11
|
const items = [];
|
|
9
12
|
let lastEvaluatedKey;
|
|
10
13
|
do {
|
|
11
|
-
const dynamodbResponse = await queryDynamodb({
|
|
14
|
+
const dynamodbResponse = await (0, query_dynamodb_1.queryDynamodb)({
|
|
12
15
|
...input,
|
|
13
16
|
ExclusiveStartKey: lastEvaluatedKey,
|
|
14
17
|
});
|
|
@@ -17,3 +20,4 @@ export const queryAllDynamodb = async (input) => {
|
|
|
17
20
|
} while (lastEvaluatedKey);
|
|
18
21
|
return items;
|
|
19
22
|
};
|
|
23
|
+
exports.queryAllDynamodb = queryAllDynamodb;
|
|
@@ -1,22 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.queryDynamodb = void 0;
|
|
4
|
+
const lib_dynamodb_1 = require("@aws-sdk/lib-dynamodb");
|
|
5
|
+
const powertools_1 = require("@itzworking/powertools");
|
|
6
|
+
const dynamodb_1 = require("./dynamodb");
|
|
7
|
+
const queryDynamodb = async (input) => {
|
|
5
8
|
const updatedParams = {
|
|
6
9
|
ScanIndexForward: false,
|
|
7
10
|
...input,
|
|
8
11
|
};
|
|
9
|
-
logger.debug({
|
|
12
|
+
powertools_1.logger.debug({
|
|
10
13
|
message: "send dynamodb QueryCommand",
|
|
11
14
|
awsService: "dynamodb",
|
|
12
15
|
action: "QueryCommand",
|
|
13
16
|
input: updatedParams,
|
|
14
17
|
});
|
|
15
18
|
try {
|
|
16
|
-
return dynamodb.send(new QueryCommand(updatedParams));
|
|
19
|
+
return dynamodb_1.dynamodb.send(new lib_dynamodb_1.QueryCommand(updatedParams));
|
|
17
20
|
}
|
|
18
21
|
catch (error) {
|
|
19
|
-
logger.error({
|
|
22
|
+
powertools_1.logger.error({
|
|
20
23
|
message: "send dynamodb QueryCommand",
|
|
21
24
|
awsService: "dynamodb",
|
|
22
25
|
action: "QueryCommand",
|
|
@@ -26,3 +29,4 @@ export const queryDynamodb = async (input) => {
|
|
|
26
29
|
throw error;
|
|
27
30
|
}
|
|
28
31
|
};
|
|
32
|
+
exports.queryDynamodb = queryDynamodb;
|
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateDynamodbItem = void 0;
|
|
4
|
+
const lib_dynamodb_1 = require("@aws-sdk/lib-dynamodb");
|
|
5
|
+
const powertools_1 = require("@itzworking/powertools");
|
|
6
|
+
const dynamodb_1 = require("./dynamodb");
|
|
7
|
+
const updateDynamodbItem = async (input) => {
|
|
8
|
+
powertools_1.logger.debug({
|
|
6
9
|
message: "send dynamodb UpdateCommand",
|
|
7
10
|
awsService: "dynamodb",
|
|
8
11
|
action: "UpdateCommand",
|
|
9
12
|
input,
|
|
10
13
|
});
|
|
11
14
|
try {
|
|
12
|
-
return dynamodb.send(new UpdateCommand(input));
|
|
15
|
+
return dynamodb_1.dynamodb.send(new lib_dynamodb_1.UpdateCommand(input));
|
|
13
16
|
}
|
|
14
17
|
catch (error) {
|
|
15
|
-
logger.error({
|
|
18
|
+
powertools_1.logger.error({
|
|
16
19
|
message: "send dynamodb UpdateCommand",
|
|
17
20
|
awsService: "dynamodb",
|
|
18
21
|
action: "UpdateCommand",
|
|
@@ -22,3 +25,4 @@ export const updateDynamodbItem = async (input) => {
|
|
|
22
25
|
throw error;
|
|
23
26
|
}
|
|
24
27
|
};
|
|
28
|
+
exports.updateDynamodbItem = updateDynamodbItem;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DecoratorsError = void 0;
|
|
4
|
+
const single_table_error_1 = require("./single-table-error");
|
|
5
|
+
class DecoratorsError extends single_table_error_1.SingleTableError {
|
|
3
6
|
constructor(message) {
|
|
4
7
|
super({
|
|
5
8
|
message,
|
|
@@ -8,3 +11,4 @@ export class DecoratorsError extends SingleTableError {
|
|
|
8
11
|
Object.setPrototypeOf(this, new.target.prototype); // maintain prototype chain
|
|
9
12
|
}
|
|
10
13
|
}
|
|
14
|
+
exports.DecoratorsError = DecoratorsError;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GenerateUpdateExpressionError = void 0;
|
|
4
|
+
const single_table_error_1 = require("./single-table-error");
|
|
5
|
+
class GenerateUpdateExpressionError extends single_table_error_1.SingleTableError {
|
|
3
6
|
constructor(message) {
|
|
4
7
|
super({
|
|
5
8
|
message,
|
|
@@ -8,3 +11,4 @@ export class GenerateUpdateExpressionError extends SingleTableError {
|
|
|
8
11
|
Object.setPrototypeOf(this, new.target.prototype); // maintain prototype chain
|
|
9
12
|
}
|
|
10
13
|
}
|
|
14
|
+
exports.GenerateUpdateExpressionError = GenerateUpdateExpressionError;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IndexDecoratorError = void 0;
|
|
4
|
+
const single_table_error_1 = require("./single-table-error");
|
|
5
|
+
class IndexDecoratorError extends single_table_error_1.SingleTableError {
|
|
3
6
|
constructor(message) {
|
|
4
7
|
super({
|
|
5
8
|
message,
|
|
@@ -8,3 +11,4 @@ export class IndexDecoratorError extends SingleTableError {
|
|
|
8
11
|
Object.setPrototypeOf(this, new.target.prototype); // maintain prototype chain
|
|
9
12
|
}
|
|
10
13
|
}
|
|
14
|
+
exports.IndexDecoratorError = IndexDecoratorError;
|
package/dist/errors/index.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./decorators-error"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./generate-update-expression-error"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./index-decorator-error"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./single-table-error"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./single-table-item-format-error"), exports);
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KeyCompositionError = void 0;
|
|
4
|
+
const single_table_error_1 = require("./single-table-error");
|
|
5
|
+
class KeyCompositionError extends single_table_error_1.SingleTableError {
|
|
3
6
|
constructor(message) {
|
|
4
7
|
super({
|
|
5
8
|
message,
|
|
@@ -8,3 +11,4 @@ export class KeyCompositionError extends SingleTableError {
|
|
|
8
11
|
Object.setPrototypeOf(this, new.target.prototype); // maintain prototype chain
|
|
9
12
|
}
|
|
10
13
|
}
|
|
14
|
+
exports.KeyCompositionError = KeyCompositionError;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SingleTableError = void 0;
|
|
4
|
+
class SingleTableError extends Error {
|
|
2
5
|
statusCode;
|
|
3
6
|
constructor(props) {
|
|
4
7
|
super(JSON.stringify({ props }));
|
|
@@ -8,3 +11,4 @@ export class SingleTableError extends Error {
|
|
|
8
11
|
Object.setPrototypeOf(this, new.target.prototype); // maintain prototype chain
|
|
9
12
|
}
|
|
10
13
|
}
|
|
14
|
+
exports.SingleTableError = SingleTableError;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SingleTableItemFormatError = void 0;
|
|
4
|
+
const single_table_error_1 = require("./single-table-error");
|
|
5
|
+
class SingleTableItemFormatError extends single_table_error_1.SingleTableError {
|
|
3
6
|
constructor(message) {
|
|
4
7
|
super({
|
|
5
8
|
message,
|
|
@@ -8,3 +11,4 @@ export class SingleTableItemFormatError extends SingleTableError {
|
|
|
8
11
|
Object.setPrototypeOf(this, new.target.prototype); // maintain prototype chain
|
|
9
12
|
}
|
|
10
13
|
}
|
|
14
|
+
exports.SingleTableItemFormatError = SingleTableItemFormatError;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./types"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./decorators"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./dynamodb"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./errors"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./single-table-item"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./single-table-repository"), exports);
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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");
|
|
7
10
|
let SingleTableItem = (() => {
|
|
8
|
-
let _classSuper = DecoratedClass;
|
|
11
|
+
let _classSuper = decorated_class_1.DecoratedClass;
|
|
9
12
|
let _id_decorators;
|
|
10
13
|
let _id_initializers = [];
|
|
11
14
|
let _id_extraInitializers = [];
|
|
@@ -30,33 +33,33 @@ let SingleTableItem = (() => {
|
|
|
30
33
|
return class SingleTableItem extends _classSuper {
|
|
31
34
|
static {
|
|
32
35
|
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
33
|
-
_id_decorators = [Attribute(AttributeType.String)];
|
|
34
|
-
_createdAt_decorators = [Attribute(AttributeType.Date)];
|
|
35
|
-
_updatedAt_decorators = [Editable, Attribute(AttributeType.Date)];
|
|
36
|
-
_createdBy_decorators = [Attribute(AttributeType.String)];
|
|
37
|
-
_updatedBy_decorators = [Editable, Attribute(AttributeType.String)];
|
|
38
|
-
_deletedBy_decorators = [Attribute(AttributeType.String)];
|
|
39
|
-
_deletedAt_decorators = [Attribute(AttributeType.Date)];
|
|
40
|
-
__esDecorate(null, null, _id_decorators, { kind: "field", name: "id", static: false, private: false, access: { has: obj => "id" in obj, get: obj => obj.id, set: (obj, value) => { obj.id = value; } }, metadata: _metadata }, _id_initializers, _id_extraInitializers);
|
|
41
|
-
__esDecorate(null, null, _createdAt_decorators, { kind: "field", name: "createdAt", static: false, private: false, access: { has: obj => "createdAt" in obj, get: obj => obj.createdAt, set: (obj, value) => { obj.createdAt = value; } }, metadata: _metadata }, _createdAt_initializers, _createdAt_extraInitializers);
|
|
42
|
-
__esDecorate(null, null, _updatedAt_decorators, { kind: "field", name: "updatedAt", static: false, private: false, access: { has: obj => "updatedAt" in obj, get: obj => obj.updatedAt, set: (obj, value) => { obj.updatedAt = value; } }, metadata: _metadata }, _updatedAt_initializers, _updatedAt_extraInitializers);
|
|
43
|
-
__esDecorate(null, null, _createdBy_decorators, { kind: "field", name: "createdBy", static: false, private: false, access: { has: obj => "createdBy" in obj, get: obj => obj.createdBy, set: (obj, value) => { obj.createdBy = value; } }, metadata: _metadata }, _createdBy_initializers, _createdBy_extraInitializers);
|
|
44
|
-
__esDecorate(null, null, _updatedBy_decorators, { kind: "field", name: "updatedBy", static: false, private: false, access: { has: obj => "updatedBy" in obj, get: obj => obj.updatedBy, set: (obj, value) => { obj.updatedBy = value; } }, metadata: _metadata }, _updatedBy_initializers, _updatedBy_extraInitializers);
|
|
45
|
-
__esDecorate(null, null, _deletedBy_decorators, { kind: "field", name: "deletedBy", static: false, private: false, access: { has: obj => "deletedBy" in obj, get: obj => obj.deletedBy, set: (obj, value) => { obj.deletedBy = value; } }, metadata: _metadata }, _deletedBy_initializers, _deletedBy_extraInitializers);
|
|
46
|
-
__esDecorate(null, null, _deletedAt_decorators, { kind: "field", name: "deletedAt", static: false, private: false, access: { has: obj => "deletedAt" in obj, get: obj => obj.deletedAt, set: (obj, value) => { obj.deletedAt = value; } }, metadata: _metadata }, _deletedAt_initializers, _deletedAt_extraInitializers);
|
|
36
|
+
_id_decorators = [(0, decorated_class_1.Attribute)(decorated_class_1.AttributeType.String)];
|
|
37
|
+
_createdAt_decorators = [(0, decorated_class_1.Attribute)(decorated_class_1.AttributeType.Date)];
|
|
38
|
+
_updatedAt_decorators = [decorators_1.Editable, (0, decorated_class_1.Attribute)(decorated_class_1.AttributeType.Date)];
|
|
39
|
+
_createdBy_decorators = [(0, decorated_class_1.Attribute)(decorated_class_1.AttributeType.String)];
|
|
40
|
+
_updatedBy_decorators = [decorators_1.Editable, (0, decorated_class_1.Attribute)(decorated_class_1.AttributeType.String)];
|
|
41
|
+
_deletedBy_decorators = [(0, decorated_class_1.Attribute)(decorated_class_1.AttributeType.String)];
|
|
42
|
+
_deletedAt_decorators = [(0, decorated_class_1.Attribute)(decorated_class_1.AttributeType.Date)];
|
|
43
|
+
tslib_1.__esDecorate(null, null, _id_decorators, { kind: "field", name: "id", static: false, private: false, access: { has: obj => "id" in obj, get: obj => obj.id, set: (obj, value) => { obj.id = value; } }, metadata: _metadata }, _id_initializers, _id_extraInitializers);
|
|
44
|
+
tslib_1.__esDecorate(null, null, _createdAt_decorators, { kind: "field", name: "createdAt", static: false, private: false, access: { has: obj => "createdAt" in obj, get: obj => obj.createdAt, set: (obj, value) => { obj.createdAt = value; } }, metadata: _metadata }, _createdAt_initializers, _createdAt_extraInitializers);
|
|
45
|
+
tslib_1.__esDecorate(null, null, _updatedAt_decorators, { kind: "field", name: "updatedAt", static: false, private: false, access: { has: obj => "updatedAt" in obj, get: obj => obj.updatedAt, set: (obj, value) => { obj.updatedAt = value; } }, metadata: _metadata }, _updatedAt_initializers, _updatedAt_extraInitializers);
|
|
46
|
+
tslib_1.__esDecorate(null, null, _createdBy_decorators, { kind: "field", name: "createdBy", static: false, private: false, access: { has: obj => "createdBy" in obj, get: obj => obj.createdBy, set: (obj, value) => { obj.createdBy = value; } }, metadata: _metadata }, _createdBy_initializers, _createdBy_extraInitializers);
|
|
47
|
+
tslib_1.__esDecorate(null, null, _updatedBy_decorators, { kind: "field", name: "updatedBy", static: false, private: false, access: { has: obj => "updatedBy" in obj, get: obj => obj.updatedBy, set: (obj, value) => { obj.updatedBy = value; } }, metadata: _metadata }, _updatedBy_initializers, _updatedBy_extraInitializers);
|
|
48
|
+
tslib_1.__esDecorate(null, null, _deletedBy_decorators, { kind: "field", name: "deletedBy", static: false, private: false, access: { has: obj => "deletedBy" in obj, get: obj => obj.deletedBy, set: (obj, value) => { obj.deletedBy = value; } }, metadata: _metadata }, _deletedBy_initializers, _deletedBy_extraInitializers);
|
|
49
|
+
tslib_1.__esDecorate(null, null, _deletedAt_decorators, { kind: "field", name: "deletedAt", static: false, private: false, access: { has: obj => "deletedAt" in obj, get: obj => obj.deletedAt, set: (obj, value) => { obj.deletedAt = value; } }, metadata: _metadata }, _deletedAt_initializers, _deletedAt_extraInitializers);
|
|
47
50
|
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
48
51
|
}
|
|
49
|
-
id = __runInitializers(this, _id_initializers, void 0);
|
|
50
|
-
createdAt = (__runInitializers(this, _id_extraInitializers), __runInitializers(this, _createdAt_initializers, void 0));
|
|
51
|
-
updatedAt = (__runInitializers(this, _createdAt_extraInitializers), __runInitializers(this, _updatedAt_initializers, void 0));
|
|
52
|
-
createdBy = (__runInitializers(this, _updatedAt_extraInitializers), __runInitializers(this, _createdBy_initializers, void 0));
|
|
53
|
-
updatedBy = (__runInitializers(this, _createdBy_extraInitializers), __runInitializers(this, _updatedBy_initializers, void 0));
|
|
54
|
-
deletedBy = (__runInitializers(this, _updatedBy_extraInitializers), __runInitializers(this, _deletedBy_initializers, void 0));
|
|
55
|
-
deletedAt = (__runInitializers(this, _deletedBy_extraInitializers), __runInitializers(this, _deletedAt_initializers, void 0));
|
|
52
|
+
id = tslib_1.__runInitializers(this, _id_initializers, void 0);
|
|
53
|
+
createdAt = (tslib_1.__runInitializers(this, _id_extraInitializers), tslib_1.__runInitializers(this, _createdAt_initializers, void 0));
|
|
54
|
+
updatedAt = (tslib_1.__runInitializers(this, _createdAt_extraInitializers), tslib_1.__runInitializers(this, _updatedAt_initializers, void 0));
|
|
55
|
+
createdBy = (tslib_1.__runInitializers(this, _updatedAt_extraInitializers), tslib_1.__runInitializers(this, _createdBy_initializers, void 0));
|
|
56
|
+
updatedBy = (tslib_1.__runInitializers(this, _createdBy_extraInitializers), tslib_1.__runInitializers(this, _updatedBy_initializers, void 0));
|
|
57
|
+
deletedBy = (tslib_1.__runInitializers(this, _updatedBy_extraInitializers), tslib_1.__runInitializers(this, _deletedBy_initializers, void 0));
|
|
58
|
+
deletedAt = (tslib_1.__runInitializers(this, _deletedBy_extraInitializers), tslib_1.__runInitializers(this, _deletedAt_initializers, void 0));
|
|
56
59
|
constructor(props = {}) {
|
|
57
60
|
super(props);
|
|
58
|
-
__runInitializers(this, _deletedAt_extraInitializers);
|
|
59
|
-
validateEntityAnnotations(this);
|
|
61
|
+
tslib_1.__runInitializers(this, _deletedAt_extraInitializers);
|
|
62
|
+
(0, utils_1.validateEntityAnnotations)(this);
|
|
60
63
|
if (!props?.id) {
|
|
61
64
|
this.generateId();
|
|
62
65
|
}
|
|
@@ -68,25 +71,25 @@ let SingleTableItem = (() => {
|
|
|
68
71
|
}
|
|
69
72
|
}
|
|
70
73
|
generateId() {
|
|
71
|
-
this.id =
|
|
74
|
+
this.id = (0, uuid_1.v4)();
|
|
72
75
|
return this.id;
|
|
73
76
|
}
|
|
74
77
|
type() {
|
|
75
|
-
return getEntityName(this);
|
|
78
|
+
return (0, decorators_1.getEntityName)(this);
|
|
76
79
|
}
|
|
77
80
|
pk() {
|
|
78
|
-
const keys = getPKComposition(this);
|
|
81
|
+
const keys = (0, decorators_1.getPKComposition)(this);
|
|
79
82
|
if (!keys?.length) {
|
|
80
|
-
throw new IndexDecoratorError(`@Entity("${this.type()}") @Index: PK is not defined`);
|
|
83
|
+
throw new errors_1.IndexDecoratorError(`@Entity("${this.type()}") @Index: PK is not defined`);
|
|
81
84
|
}
|
|
82
|
-
return handleCompositePrimaryKey(this, keys);
|
|
85
|
+
return (0, utils_1.handleCompositePrimaryKey)(this, keys);
|
|
83
86
|
}
|
|
84
87
|
sk() {
|
|
85
|
-
const keys = getSKComposition(this);
|
|
88
|
+
const keys = (0, decorators_1.getSKComposition)(this);
|
|
86
89
|
if (!keys?.length) {
|
|
87
|
-
throw new IndexDecoratorError(`@Entity("${this.type()}") @Index: SK is not defined`);
|
|
90
|
+
throw new errors_1.IndexDecoratorError(`@Entity("${this.type()}") @Index: SK is not defined`);
|
|
88
91
|
}
|
|
89
|
-
return handleCompositePrimaryKey(this, keys);
|
|
92
|
+
return (0, utils_1.handleCompositePrimaryKey)(this, keys);
|
|
90
93
|
}
|
|
91
94
|
key() {
|
|
92
95
|
return {
|
|
@@ -95,63 +98,63 @@ let SingleTableItem = (() => {
|
|
|
95
98
|
};
|
|
96
99
|
}
|
|
97
100
|
gsi1pk() {
|
|
98
|
-
return handleCompositePrimaryKey(this, getPKComposition(this, "GSI1"));
|
|
101
|
+
return (0, utils_1.handleCompositePrimaryKey)(this, (0, decorators_1.getPKComposition)(this, "GSI1"));
|
|
99
102
|
}
|
|
100
103
|
gsi1sk() {
|
|
101
|
-
return handleCompositePrimaryKey(this, getSKComposition(this, "GSI1"));
|
|
104
|
+
return (0, utils_1.handleCompositePrimaryKey)(this, (0, decorators_1.getSKComposition)(this, "GSI1"));
|
|
102
105
|
}
|
|
103
106
|
gsi2pk() {
|
|
104
|
-
return handleCompositePrimaryKey(this, getPKComposition(this, "GSI2"));
|
|
107
|
+
return (0, utils_1.handleCompositePrimaryKey)(this, (0, decorators_1.getPKComposition)(this, "GSI2"));
|
|
105
108
|
}
|
|
106
109
|
gsi2sk() {
|
|
107
|
-
return handleCompositePrimaryKey(this, getSKComposition(this, "GSI2"));
|
|
110
|
+
return (0, utils_1.handleCompositePrimaryKey)(this, (0, decorators_1.getSKComposition)(this, "GSI2"));
|
|
108
111
|
}
|
|
109
112
|
gsi3pk() {
|
|
110
|
-
return handleCompositePrimaryKey(this, getPKComposition(this, "GSI3"));
|
|
113
|
+
return (0, utils_1.handleCompositePrimaryKey)(this, (0, decorators_1.getPKComposition)(this, "GSI3"));
|
|
111
114
|
}
|
|
112
115
|
gsi3sk() {
|
|
113
|
-
return handleCompositePrimaryKey(this, getSKComposition(this, "GSI3"));
|
|
116
|
+
return (0, utils_1.handleCompositePrimaryKey)(this, (0, decorators_1.getSKComposition)(this, "GSI3"));
|
|
114
117
|
}
|
|
115
118
|
gsi4pk() {
|
|
116
|
-
return handleCompositePrimaryKey(this, getPKComposition(this, "GSI4"));
|
|
119
|
+
return (0, utils_1.handleCompositePrimaryKey)(this, (0, decorators_1.getPKComposition)(this, "GSI4"));
|
|
117
120
|
}
|
|
118
121
|
gsi4sk() {
|
|
119
|
-
return handleCompositePrimaryKey(this, getSKComposition(this, "GSI4"));
|
|
122
|
+
return (0, utils_1.handleCompositePrimaryKey)(this, (0, decorators_1.getSKComposition)(this, "GSI4"));
|
|
120
123
|
}
|
|
121
124
|
gsi5pk() {
|
|
122
|
-
return handleCompositePrimaryKey(this, getPKComposition(this, "GSI5"));
|
|
125
|
+
return (0, utils_1.handleCompositePrimaryKey)(this, (0, decorators_1.getPKComposition)(this, "GSI5"));
|
|
123
126
|
}
|
|
124
127
|
gsi5sk() {
|
|
125
|
-
return handleCompositePrimaryKey(this, getSKComposition(this, "GSI5"));
|
|
128
|
+
return (0, utils_1.handleCompositePrimaryKey)(this, (0, decorators_1.getSKComposition)(this, "GSI5"));
|
|
126
129
|
}
|
|
127
130
|
generateUpdateExpression(attributes = []) {
|
|
128
131
|
const attributesToUpdate = [];
|
|
129
|
-
const entityAttributes = listAttributes(this);
|
|
132
|
+
const entityAttributes = (0, decorated_class_1.listAttributes)(this);
|
|
130
133
|
if (attributes?.length) {
|
|
131
134
|
for (const attribute of attributes) {
|
|
132
135
|
if (entityAttributes.find((ef) => ef.attributeName === attribute)) {
|
|
133
136
|
attributesToUpdate.push(attribute);
|
|
134
137
|
}
|
|
135
138
|
else {
|
|
136
|
-
throw new GenerateUpdateExpressionError(`@Entity("${this.type()}"): ${attribute} is not an @Attribute`);
|
|
139
|
+
throw new errors_1.GenerateUpdateExpressionError(`@Entity("${this.type()}"): ${attribute} is not an @Attribute`);
|
|
137
140
|
}
|
|
138
141
|
}
|
|
139
142
|
}
|
|
140
143
|
else {
|
|
141
144
|
for (const attribute of entityAttributes) {
|
|
142
|
-
if (!isEditable(this, attribute.attributeName)) {
|
|
145
|
+
if (!(0, decorators_1.isEditable)(this, attribute.attributeName)) {
|
|
143
146
|
continue;
|
|
144
147
|
}
|
|
145
148
|
attributesToUpdate.push(attribute.attributeName);
|
|
146
149
|
}
|
|
147
150
|
}
|
|
148
151
|
if (attributesToUpdate.length === 0) {
|
|
149
|
-
throw new GenerateUpdateExpressionError(`@Entity("${this.type()}"): attributesToUpdate is empty; attributes = ${attributes}`);
|
|
152
|
+
throw new errors_1.GenerateUpdateExpressionError(`@Entity("${this.type()}"): attributesToUpdate is empty; attributes = ${attributes}`);
|
|
150
153
|
}
|
|
151
154
|
else {
|
|
152
155
|
const indexComposition = {
|
|
153
|
-
PK: getPKComposition(this),
|
|
154
|
-
SK: getSKComposition(this),
|
|
156
|
+
PK: (0, decorators_1.getPKComposition)(this),
|
|
157
|
+
SK: (0, decorators_1.getSKComposition)(this),
|
|
155
158
|
};
|
|
156
159
|
const indexPkSkAttributes = [
|
|
157
160
|
...(indexComposition.PK || []),
|
|
@@ -159,7 +162,7 @@ let SingleTableItem = (() => {
|
|
|
159
162
|
];
|
|
160
163
|
const notAllowedAttributes = indexPkSkAttributes.filter((attribute) => attributesToUpdate.includes(attribute));
|
|
161
164
|
if (notAllowedAttributes.length > 0) {
|
|
162
|
-
throw new GenerateUpdateExpressionError(`@Entity("${this.type()}"): cannot update @Index notAllowedAttributes = ${notAllowedAttributes}`);
|
|
165
|
+
throw new errors_1.GenerateUpdateExpressionError(`@Entity("${this.type()}"): cannot update @Index notAllowedAttributes = ${notAllowedAttributes}`);
|
|
163
166
|
}
|
|
164
167
|
}
|
|
165
168
|
const attributeValues = {};
|
|
@@ -168,24 +171,24 @@ let SingleTableItem = (() => {
|
|
|
168
171
|
const attributesToRemove = [];
|
|
169
172
|
const gsis = {
|
|
170
173
|
GSI1: {
|
|
171
|
-
PK: getPKComposition(this, "GSI1"),
|
|
172
|
-
SK: getSKComposition(this, "GSI1"),
|
|
174
|
+
PK: (0, decorators_1.getPKComposition)(this, "GSI1"),
|
|
175
|
+
SK: (0, decorators_1.getSKComposition)(this, "GSI1"),
|
|
173
176
|
},
|
|
174
177
|
GSI2: {
|
|
175
|
-
PK: getPKComposition(this, "GSI2"),
|
|
176
|
-
SK: getSKComposition(this, "GSI2"),
|
|
178
|
+
PK: (0, decorators_1.getPKComposition)(this, "GSI2"),
|
|
179
|
+
SK: (0, decorators_1.getSKComposition)(this, "GSI2"),
|
|
177
180
|
},
|
|
178
181
|
GSI3: {
|
|
179
|
-
PK: getPKComposition(this, "GSI3"),
|
|
180
|
-
SK: getSKComposition(this, "GSI3"),
|
|
182
|
+
PK: (0, decorators_1.getPKComposition)(this, "GSI3"),
|
|
183
|
+
SK: (0, decorators_1.getSKComposition)(this, "GSI3"),
|
|
181
184
|
},
|
|
182
185
|
GSI4: {
|
|
183
|
-
PK: getPKComposition(this, "GSI4"),
|
|
184
|
-
SK: getSKComposition(this, "GSI4"),
|
|
186
|
+
PK: (0, decorators_1.getPKComposition)(this, "GSI4"),
|
|
187
|
+
SK: (0, decorators_1.getSKComposition)(this, "GSI4"),
|
|
185
188
|
},
|
|
186
189
|
GSI5: {
|
|
187
|
-
PK: getPKComposition(this, "GSI5"),
|
|
188
|
-
SK: getSKComposition(this, "GSI5"),
|
|
190
|
+
PK: (0, decorators_1.getPKComposition)(this, "GSI5"),
|
|
191
|
+
SK: (0, decorators_1.getSKComposition)(this, "GSI5"),
|
|
189
192
|
},
|
|
190
193
|
};
|
|
191
194
|
for (const [gsiKey, gsiComposition] of Object.entries(gsis)) {
|
|
@@ -198,7 +201,7 @@ let SingleTableItem = (() => {
|
|
|
198
201
|
}
|
|
199
202
|
}
|
|
200
203
|
for (const key of attributesToUpdate) {
|
|
201
|
-
const keyToUse = capitalizeFirstLetter(key);
|
|
204
|
+
const keyToUse = (0, utils_1.capitalizeFirstLetter)(key);
|
|
202
205
|
const value = this[key];
|
|
203
206
|
attributeNames[`#key${keyToUse}`] = key;
|
|
204
207
|
if (value === undefined) {
|
|
@@ -244,7 +247,7 @@ let SingleTableItem = (() => {
|
|
|
244
247
|
result.GSI5PK = this.gsi5pk();
|
|
245
248
|
result.GSI5SK = this.gsi5sk();
|
|
246
249
|
}
|
|
247
|
-
const attributes = listAttributes(this);
|
|
250
|
+
const attributes = (0, decorated_class_1.listAttributes)(this);
|
|
248
251
|
const reservedKeys = [
|
|
249
252
|
"type",
|
|
250
253
|
"PK",
|
|
@@ -262,7 +265,7 @@ let SingleTableItem = (() => {
|
|
|
262
265
|
];
|
|
263
266
|
const reservedKeysInUse = reservedKeys.filter((reservedKey) => attributes.find((f) => f.attributeName === reservedKey));
|
|
264
267
|
if (reservedKeysInUse.length > 0) {
|
|
265
|
-
throw new SingleTableItemFormatError(`@Entity("${this.type()}"): cannot use reserved keys in attributes = ${reservedKeysInUse}`);
|
|
268
|
+
throw new errors_1.SingleTableItemFormatError(`@Entity("${this.type()}"): cannot use reserved keys in attributes = ${reservedKeysInUse}`);
|
|
266
269
|
}
|
|
267
270
|
for (const attribute of attributes) {
|
|
268
271
|
const value = this[attribute.attributeName];
|
|
@@ -275,4 +278,4 @@ let SingleTableItem = (() => {
|
|
|
275
278
|
}
|
|
276
279
|
};
|
|
277
280
|
})();
|
|
278
|
-
|
|
281
|
+
exports.SingleTableItem = SingleTableItem;
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.capitalizeFirstLetter = void 0;
|
|
4
|
+
const capitalizeFirstLetter = (s) => {
|
|
2
5
|
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
3
6
|
};
|
|
7
|
+
exports.capitalizeFirstLetter = capitalizeFirstLetter;
|
|
@@ -1,24 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handleCompositePrimaryKey = void 0;
|
|
4
|
+
const decorated_class_1 = require("@itzworking/decorated-class");
|
|
5
|
+
const key_composition_error_1 = require("../../errors/key-composition-error");
|
|
3
6
|
const isPrimitiveType = (type) => {
|
|
4
|
-
return Object.values(PrimitiveType).includes(type);
|
|
7
|
+
return Object.values(decorated_class_1.PrimitiveType).includes(type);
|
|
5
8
|
};
|
|
6
|
-
|
|
9
|
+
const handleCompositePrimaryKey = (target, keys) => {
|
|
7
10
|
if (!keys?.length) {
|
|
8
11
|
return "";
|
|
9
12
|
}
|
|
10
|
-
const entityAttributes = listAttributes(target);
|
|
13
|
+
const entityAttributes = (0, decorated_class_1.listAttributes)(target);
|
|
11
14
|
const result = [];
|
|
12
15
|
for (const key of keys) {
|
|
13
16
|
const entityAttribute = entityAttributes.find((attDef) => attDef.attributeName === key);
|
|
14
17
|
if (entityAttribute) {
|
|
15
18
|
if (!isPrimitiveType(entityAttribute?.attributeType)) {
|
|
16
|
-
throw new KeyCompositionError(`Composite primary key must all be primitive type - @Entity("${target.type()}"): ${key}`);
|
|
19
|
+
throw new key_composition_error_1.KeyCompositionError(`Composite primary key must all be primitive type - @Entity("${target.type()}"): ${key}`);
|
|
17
20
|
}
|
|
18
21
|
if (target[key] === undefined) {
|
|
19
22
|
result.push("null");
|
|
20
23
|
}
|
|
21
|
-
else if (entityAttribute.attributeType === AttributeType.Date) {
|
|
24
|
+
else if (entityAttribute.attributeType === decorated_class_1.AttributeType.Date) {
|
|
22
25
|
result.push(target[key].toISOString());
|
|
23
26
|
}
|
|
24
27
|
else {
|
|
@@ -31,3 +34,4 @@ export const handleCompositePrimaryKey = (target, keys) => {
|
|
|
31
34
|
}
|
|
32
35
|
return result.join("#");
|
|
33
36
|
};
|
|
37
|
+
exports.handleCompositePrimaryKey = handleCompositePrimaryKey;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./capitalize-first-letter"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./handle-composite-primary-key"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./validate-entity-annotations"), exports);
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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) => {
|
|
3
6
|
const errors = [];
|
|
4
7
|
if (!entity.type()) {
|
|
5
8
|
errors.push("missing @Entity annotation on SingleTableItem class");
|
|
@@ -29,6 +32,7 @@ export const validateEntityAnnotations = (entity) => {
|
|
|
29
32
|
// }
|
|
30
33
|
// }
|
|
31
34
|
if (errors.length) {
|
|
32
|
-
throw new DecoratorsError(errors.join(","));
|
|
35
|
+
throw new errors_1.DecoratorsError(errors.join(","));
|
|
33
36
|
}
|
|
34
37
|
};
|
|
38
|
+
exports.validateEntityAnnotations = validateEntityAnnotations;
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./single-table-repository"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./types"), exports);
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SingleTableRepository = void 0;
|
|
4
|
+
const dynamodb_1 = require("../dynamodb");
|
|
5
|
+
const powertools_1 = require("@itzworking/powertools");
|
|
6
|
+
class SingleTableRepository {
|
|
4
7
|
tableName = process.env.MAIN_TABLE_NAME || process.env.MAIN_TABLE_TABLE_NAME || "";
|
|
5
8
|
getUserId() {
|
|
6
9
|
try {
|
|
7
|
-
return getContext().user?.id || "unknown";
|
|
10
|
+
return (0, powertools_1.getContext)().user?.id || "unknown";
|
|
8
11
|
}
|
|
9
12
|
catch (e) {
|
|
10
13
|
return "unknown";
|
|
@@ -20,7 +23,7 @@ export class SingleTableRepository {
|
|
|
20
23
|
let retryLimit = options?.override ? 1 : 3;
|
|
21
24
|
while (retryLimit > 0) {
|
|
22
25
|
try {
|
|
23
|
-
await putDynamodbItem({
|
|
26
|
+
await (0, dynamodb_1.putDynamodbItem)({
|
|
24
27
|
TableName: this.tableName || "",
|
|
25
28
|
Item: entity.toSingleTableItem(),
|
|
26
29
|
ConditionExpression: options?.override
|
|
@@ -44,13 +47,13 @@ export class SingleTableRepository {
|
|
|
44
47
|
return entity;
|
|
45
48
|
}
|
|
46
49
|
async get(entity, options) {
|
|
47
|
-
const { Item: item } = await getDynamodbItem({
|
|
50
|
+
const { Item: item } = await (0, dynamodb_1.getDynamodbItem)({
|
|
48
51
|
TableName: this.tableName || "",
|
|
49
52
|
Key: entity.key(),
|
|
50
53
|
...options?.input,
|
|
51
54
|
});
|
|
52
55
|
if (!item) {
|
|
53
|
-
throw new NotFoundError(`Item not found: ${JSON.stringify(entity.key())}`);
|
|
56
|
+
throw new powertools_1.NotFoundError(`Item not found: ${JSON.stringify(entity.key())}`);
|
|
54
57
|
}
|
|
55
58
|
const EntityClass = Object.getPrototypeOf(entity).constructor;
|
|
56
59
|
return new EntityClass(item);
|
|
@@ -66,7 +69,7 @@ export class SingleTableRepository {
|
|
|
66
69
|
}
|
|
67
70
|
entity.updatedAt = new Date();
|
|
68
71
|
entity.updatedBy = this.getUserId();
|
|
69
|
-
const dynamodbResponse = await updateDynamodbItem({
|
|
72
|
+
const dynamodbResponse = await (0, dynamodb_1.updateDynamodbItem)({
|
|
70
73
|
TableName: this.tableName || "",
|
|
71
74
|
Key: entity.key(),
|
|
72
75
|
ReturnValues: "ALL_NEW",
|
|
@@ -79,13 +82,13 @@ export class SingleTableRepository {
|
|
|
79
82
|
async delete(entity, options) {
|
|
80
83
|
entity.deletedAt = new Date();
|
|
81
84
|
entity.deletedBy = this.getUserId();
|
|
82
|
-
await updateDynamodbItem({
|
|
85
|
+
await (0, dynamodb_1.updateDynamodbItem)({
|
|
83
86
|
TableName: options?.input?.TableName || this.tableName || "",
|
|
84
87
|
Key: options?.input?.Key || entity.key(),
|
|
85
88
|
ReturnValues: "NONE",
|
|
86
89
|
...entity.generateUpdateExpression(["deletedAt", "deletedBy"]),
|
|
87
90
|
});
|
|
88
|
-
await deleteDynamodbItem({
|
|
91
|
+
await (0, dynamodb_1.deleteDynamodbItem)({
|
|
89
92
|
TableName: this.tableName || "",
|
|
90
93
|
Key: entity.key(),
|
|
91
94
|
...options?.input,
|
|
@@ -154,7 +157,7 @@ export class SingleTableRepository {
|
|
|
154
157
|
};
|
|
155
158
|
let dynamodbItems;
|
|
156
159
|
if (options?.queryAll) {
|
|
157
|
-
dynamodbItems = await queryAllDynamodb({
|
|
160
|
+
dynamodbItems = await (0, dynamodb_1.queryAllDynamodb)({
|
|
158
161
|
TableName: this.tableName || "",
|
|
159
162
|
IndexName: options.index,
|
|
160
163
|
KeyConditionExpression,
|
|
@@ -164,7 +167,7 @@ export class SingleTableRepository {
|
|
|
164
167
|
});
|
|
165
168
|
}
|
|
166
169
|
else {
|
|
167
|
-
const { Items, LastEvaluatedKey } = await queryDynamodb({
|
|
170
|
+
const { Items, LastEvaluatedKey } = await (0, dynamodb_1.queryDynamodb)({
|
|
168
171
|
TableName: this.tableName || "",
|
|
169
172
|
IndexName: options.index,
|
|
170
173
|
KeyConditionExpression,
|
|
@@ -209,3 +212,4 @@ export class SingleTableRepository {
|
|
|
209
212
|
return response;
|
|
210
213
|
}
|
|
211
214
|
}
|
|
215
|
+
exports.SingleTableRepository = SingleTableRepository;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/dist/types.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itzworking/single-table",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"type": "
|
|
3
|
+
"version": "0.0.159",
|
|
4
|
+
"type": "commonjs",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"@aws-sdk/client-dynamodb": "3.x",
|
|
42
42
|
"@aws-sdk/lib-dynamodb": "3.x",
|
|
43
|
-
"@itzworking/decorated-class": "0.0.
|
|
44
|
-
"@itzworking/powertools": "0.0.
|
|
43
|
+
"@itzworking/decorated-class": "0.0.159",
|
|
44
|
+
"@itzworking/powertools": "0.0.159",
|
|
45
45
|
"reflect-metadata": "0.2.x",
|
|
46
46
|
"uuid": "10.x"
|
|
47
47
|
}
|