@kravc/dos-dynamodb 1.0.0-alpha.0
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 +30 -0
- package/bin/table.js +88 -0
- package/config/default.yaml +36 -0
- package/config/test.yaml +0 -0
- package/dist/example/Activity.d.ts +34 -0
- package/dist/example/Activity.d.ts.map +1 -0
- package/dist/example/Activity.js +66 -0
- package/dist/example/Activity.js.map +1 -0
- package/dist/example/ActivityAttributes.d.ts +23 -0
- package/dist/example/ActivityAttributes.d.ts.map +1 -0
- package/dist/example/ActivityAttributes.js +54 -0
- package/dist/example/ActivityAttributes.js.map +1 -0
- package/dist/example/Asset.d.ts +36 -0
- package/dist/example/Asset.d.ts.map +1 -0
- package/dist/example/Asset.js +56 -0
- package/dist/example/Asset.js.map +1 -0
- package/dist/example/AssetAttributes.d.ts +28 -0
- package/dist/example/AssetAttributes.d.ts.map +1 -0
- package/dist/example/AssetAttributes.js +72 -0
- package/dist/example/AssetAttributes.js.map +1 -0
- package/dist/example/Organization.d.ts +19 -0
- package/dist/example/Organization.d.ts.map +1 -0
- package/dist/example/Organization.js +42 -0
- package/dist/example/Organization.js.map +1 -0
- package/dist/example/OrganizationAttributes.d.ts +13 -0
- package/dist/example/OrganizationAttributes.d.ts.map +1 -0
- package/dist/example/OrganizationAttributes.js +24 -0
- package/dist/example/OrganizationAttributes.js.map +1 -0
- package/dist/example/index.d.ts +5 -0
- package/dist/example/index.d.ts.map +1 -0
- package/dist/example/index.js +13 -0
- package/dist/example/index.js.map +1 -0
- package/dist/src/Document/Document.d.ts +67 -0
- package/dist/src/Document/Document.d.ts.map +1 -0
- package/dist/src/Document/Document.js +216 -0
- package/dist/src/Document/Document.js.map +1 -0
- package/dist/src/Document/DocumentWithHashId.d.ts +22 -0
- package/dist/src/Document/DocumentWithHashId.d.ts.map +1 -0
- package/dist/src/Document/DocumentWithHashId.js +73 -0
- package/dist/src/Document/DocumentWithHashId.js.map +1 -0
- package/dist/src/Document/__tests__/__helpers.d.ts +21 -0
- package/dist/src/Document/__tests__/__helpers.d.ts.map +1 -0
- package/dist/src/Document/__tests__/__helpers.js +92 -0
- package/dist/src/Document/__tests__/__helpers.js.map +1 -0
- package/dist/src/Document/helpers/composeIndexKeys.d.ts +11 -0
- package/dist/src/Document/helpers/composeIndexKeys.d.ts.map +1 -0
- package/dist/src/Document/helpers/composeIndexKeys.js +81 -0
- package/dist/src/Document/helpers/composeIndexKeys.js.map +1 -0
- package/dist/src/Document/helpers/index.d.ts +3 -0
- package/dist/src/Document/helpers/index.d.ts.map +1 -0
- package/dist/src/Document/helpers/index.js +9 -0
- package/dist/src/Document/helpers/index.js.map +1 -0
- package/dist/src/Table/Table.d.ts +56 -0
- package/dist/src/Table/Table.d.ts.map +1 -0
- package/dist/src/Table/Table.js +228 -0
- package/dist/src/Table/Table.js.map +1 -0
- package/dist/src/Table/helpers/buildConditionExpression.d.ts +22 -0
- package/dist/src/Table/helpers/buildConditionExpression.d.ts.map +1 -0
- package/dist/src/Table/helpers/buildConditionExpression.js +128 -0
- package/dist/src/Table/helpers/buildConditionExpression.js.map +1 -0
- package/dist/src/Table/helpers/buildQueryCommandInput.d.ts +12 -0
- package/dist/src/Table/helpers/buildQueryCommandInput.d.ts.map +1 -0
- package/dist/src/Table/helpers/buildQueryCommandInput.js +60 -0
- package/dist/src/Table/helpers/buildQueryCommandInput.js.map +1 -0
- package/dist/src/Table/helpers/buildQueryConditionExpression.d.ts +17 -0
- package/dist/src/Table/helpers/buildQueryConditionExpression.d.ts.map +1 -0
- package/dist/src/Table/helpers/buildQueryConditionExpression.js +77 -0
- package/dist/src/Table/helpers/buildQueryConditionExpression.js.map +1 -0
- package/dist/src/Table/helpers/buildTableSchema.d.ts +6 -0
- package/dist/src/Table/helpers/buildTableSchema.d.ts.map +1 -0
- package/dist/src/Table/helpers/buildTableSchema.js +100 -0
- package/dist/src/Table/helpers/buildTableSchema.js.map +1 -0
- package/dist/src/Table/helpers/buildUpdateExpression.d.ts +10 -0
- package/dist/src/Table/helpers/buildUpdateExpression.d.ts.map +1 -0
- package/dist/src/Table/helpers/buildUpdateExpression.js +69 -0
- package/dist/src/Table/helpers/buildUpdateExpression.js.map +1 -0
- package/dist/src/Table/helpers/filterConditionExpression.d.ts +5 -0
- package/dist/src/Table/helpers/filterConditionExpression.d.ts.map +1 -0
- package/dist/src/Table/helpers/filterConditionExpression.js +68 -0
- package/dist/src/Table/helpers/filterConditionExpression.js.map +1 -0
- package/dist/src/Table/helpers/getRawClientConfig.d.ts +5 -0
- package/dist/src/Table/helpers/getRawClientConfig.d.ts.map +1 -0
- package/dist/src/Table/helpers/getRawClientConfig.js +29 -0
- package/dist/src/Table/helpers/getRawClientConfig.js.map +1 -0
- package/dist/src/Table/helpers/getTableOptions.d.ts +51 -0
- package/dist/src/Table/helpers/getTableOptions.d.ts.map +1 -0
- package/dist/src/Table/helpers/getTableOptions.js +144 -0
- package/dist/src/Table/helpers/getTableOptions.js.map +1 -0
- package/dist/src/Table/helpers/index.d.ts +10 -0
- package/dist/src/Table/helpers/index.d.ts.map +1 -0
- package/dist/src/Table/helpers/index.js +21 -0
- package/dist/src/Table/helpers/index.js.map +1 -0
- package/dist/src/Table/index.d.ts +8 -0
- package/dist/src/Table/index.d.ts.map +1 -0
- package/dist/src/Table/index.js +13 -0
- package/dist/src/Table/index.js.map +1 -0
- package/dist/src/index.d.ts +7 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +14 -0
- package/dist/src/index.js.map +1 -0
- package/docker-compose.yaml +10 -0
- package/eslint.config.mjs +35 -0
- package/example/Activity.ts +123 -0
- package/example/ActivityAttributes.ts +72 -0
- package/example/Asset.ts +78 -0
- package/example/AssetAttributes.ts +87 -0
- package/example/Organization.ts +61 -0
- package/example/OrganizationAttributes.ts +28 -0
- package/example/index.ts +9 -0
- package/jest.config.mjs +10 -0
- package/package.json +50 -0
- package/src/Document/DefaultAttributes.d.ts +16 -0
- package/src/Document/Document.ts +257 -0
- package/src/Document/DocumentWithHashId.ts +85 -0
- package/src/Document/__tests__/Document.test.ts +596 -0
- package/src/Document/__tests__/DocumentWithHashId.test.ts +81 -0
- package/src/Document/__tests__/__helpers.ts +115 -0
- package/src/Document/helpers/__tests__/composeIndexKeys.test.ts +40 -0
- package/src/Document/helpers/composeIndexKeys.ts +137 -0
- package/src/Document/helpers/index.ts +5 -0
- package/src/Table/Table.ts +354 -0
- package/src/Table/__tests__/Table.test.ts +64 -0
- package/src/Table/helpers/__tests__/buildQueryCommandInput.test.ts +14 -0
- package/src/Table/helpers/__tests__/buildTableSchema.test.ts +19 -0
- package/src/Table/helpers/buildConditionExpression.ts +151 -0
- package/src/Table/helpers/buildQueryCommandInput.ts +113 -0
- package/src/Table/helpers/buildQueryConditionExpression.ts +109 -0
- package/src/Table/helpers/buildTableSchema.ts +151 -0
- package/src/Table/helpers/buildUpdateExpression.ts +95 -0
- package/src/Table/helpers/filterConditionExpression.ts +87 -0
- package/src/Table/helpers/getRawClientConfig.ts +35 -0
- package/src/Table/helpers/getTableOptions.ts +228 -0
- package/src/Table/helpers/index.ts +21 -0
- package/src/Table/index.ts +18 -0
- package/src/index.ts +15 -0
- package/tsconfig.json +26 -0
|
@@ -0,0 +1,60 @@
|
|
|
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 dos_1 = require("@kravc/dos");
|
|
7
|
+
const buildQueryConditionExpression_1 = __importDefault(require("./buildQueryConditionExpression"));
|
|
8
|
+
const QUERY_ERROR_TEMPLATE = 'Query parameter "$PATH" is required';
|
|
9
|
+
const SORT_ASC = 'asc';
|
|
10
|
+
/** Returns partitionKey and sortKey for a query. */
|
|
11
|
+
const getKeys = (tableOptions, indexName) => {
|
|
12
|
+
const { primaryKey, localSecondaryIndexes, globalSecondaryIndexes } = tableOptions;
|
|
13
|
+
if (!indexName) {
|
|
14
|
+
return { ...primaryKey, isGlobalSecondaryIndex: false };
|
|
15
|
+
}
|
|
16
|
+
const lsi = localSecondaryIndexes.find(({ name }) => name === indexName);
|
|
17
|
+
if (lsi) {
|
|
18
|
+
const { sortKey } = lsi;
|
|
19
|
+
return { ...primaryKey, sortKey, isGlobalSecondaryIndex: false };
|
|
20
|
+
}
|
|
21
|
+
const gsi = globalSecondaryIndexes.find(({ name }) => name === indexName);
|
|
22
|
+
if (gsi) {
|
|
23
|
+
const { partitionKey, sortKey } = gsi;
|
|
24
|
+
return { partitionKey, sortKey, isGlobalSecondaryIndex: true };
|
|
25
|
+
}
|
|
26
|
+
const indexesJson = JSON.stringify({ localSecondaryIndexes, globalSecondaryIndexes }, null, 2);
|
|
27
|
+
throw new Error(`Index "${indexName}" is not defined, indexes: ${indexesJson}`);
|
|
28
|
+
};
|
|
29
|
+
/** Builds query command input. */
|
|
30
|
+
const buildQueryCommandInput = (tableOptions, query, options) => {
|
|
31
|
+
const { name: TableName } = tableOptions;
|
|
32
|
+
const { sort, limit, indexName, exclusiveStartKey } = options;
|
|
33
|
+
const { sortKey, partitionKey, isGlobalSecondaryIndex } = getKeys(tableOptions, indexName);
|
|
34
|
+
(0, dos_1.got)(query, partitionKey, QUERY_ERROR_TEMPLATE);
|
|
35
|
+
const { ConditionExpression, KeyConditionExpression, ExpressionAttributeNames, ExpressionAttributeValues } = (0, buildQueryConditionExpression_1.default)(query, partitionKey, sortKey);
|
|
36
|
+
const Limit = limit;
|
|
37
|
+
const ConsistentRead = !isGlobalSecondaryIndex;
|
|
38
|
+
const ScanIndexForward = sort === SORT_ASC;
|
|
39
|
+
const input = {
|
|
40
|
+
TableName,
|
|
41
|
+
Limit,
|
|
42
|
+
ConsistentRead,
|
|
43
|
+
ScanIndexForward,
|
|
44
|
+
KeyConditionExpression,
|
|
45
|
+
ExpressionAttributeNames,
|
|
46
|
+
ExpressionAttributeValues
|
|
47
|
+
};
|
|
48
|
+
if (indexName) {
|
|
49
|
+
input.IndexName = indexName;
|
|
50
|
+
}
|
|
51
|
+
if (ConditionExpression) {
|
|
52
|
+
input.FilterExpression = ConditionExpression;
|
|
53
|
+
}
|
|
54
|
+
if (exclusiveStartKey) {
|
|
55
|
+
input.ExclusiveStartKey = JSON.parse(decodeURIComponent(exclusiveStartKey));
|
|
56
|
+
}
|
|
57
|
+
return input;
|
|
58
|
+
};
|
|
59
|
+
exports.default = buildQueryCommandInput;
|
|
60
|
+
//# sourceMappingURL=buildQueryCommandInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildQueryCommandInput.js","sourceRoot":"","sources":["../../../../src/Table/helpers/buildQueryCommandInput.ts"],"names":[],"mappings":";;;;;AACA,oCAAgD;AAEhD,oGAA4E;AAE5E,MAAM,oBAAoB,GAAG,qCAAqC,CAAC;AAEnE,MAAM,QAAQ,GAAG,KAAK,CAAC;AAEvB,oDAAoD;AACpD,MAAM,OAAO,GAAG,CACd,YAA0B,EAC1B,SAAkB,EAKlB,EAAE;IACF,MAAM,EACJ,UAAU,EACV,qBAAqB,EACrB,sBAAsB,EACvB,GAAG,YAAY,CAAC;IAEjB,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,EAAE,GAAG,UAAU,EAAE,sBAAsB,EAAE,KAAK,EAAE,CAAC;IAC1D,CAAC;IAED,MAAM,GAAG,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;IAEzE,IAAI,GAAG,EAAE,CAAC;QACR,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,CAAC;QAExB,OAAO,EAAE,GAAG,UAAU,EAAE,OAAO,EAAE,sBAAsB,EAAE,KAAK,EAAE,CAAC;IACnE,CAAC;IAED,MAAM,GAAG,GAAG,sBAAsB,CAAC,IAAI,CAAC,CAAC,EAAE,IAA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AwB;QACxB,yBAAyB;KACL,CAAC;IAEvB,IAAI,SAAS,EAAE,CAAC;QACd,KAAK,CAAC,SAAS,GAAG,SAAS,CAAC;IAC9B,CAAC;IAED,IAAI,mBAAmB,EAAE,CAAC;QACxB,KAAK,CAAC,gBAAgB,GAAG,mBAAmB,CAAC;IAC/C,CAAC;IAED,IAAI,iBAAiB,EAAE,CAAC;QACtB,KAAK,CAAC,iBAAiB,GAAG,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAC9E,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,kBAAe,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { QueryMap } from '@kravc/dos';
|
|
2
|
+
export declare enum SortExpressionKey {
|
|
3
|
+
BW = "bw",
|
|
4
|
+
LT = "lt",
|
|
5
|
+
LE = "le",
|
|
6
|
+
GT = "gt",
|
|
7
|
+
GE = "ge"
|
|
8
|
+
}
|
|
9
|
+
/** Builds condition expression for a table query. */
|
|
10
|
+
declare const buildQueryConditionExpression: (query: QueryMap, partitionKey: string, sortKey: string) => {
|
|
11
|
+
ConditionExpression: string | undefined;
|
|
12
|
+
KeyConditionExpression: string;
|
|
13
|
+
ExpressionAttributeNames: Record<string, string>;
|
|
14
|
+
ExpressionAttributeValues: Record<string, unknown>;
|
|
15
|
+
};
|
|
16
|
+
export default buildQueryConditionExpression;
|
|
17
|
+
//# sourceMappingURL=buildQueryConditionExpression.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildQueryConditionExpression.d.ts","sourceRoot":"","sources":["../../../../src/Table/helpers/buildQueryConditionExpression.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAG3C,oBAAY,iBAAiB;IAC3B,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;IACT,EAAE,OAAO;CACV;AAED,qDAAqD;AACrD,QAAA,MAAM,6BAA6B,GACjC,OAAO,QAAQ,EACf,cAAc,MAAM,EACpB,SAAS,MAAM;;;;;CA2FhB,CAAC;AAEF,eAAe,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SortExpressionKey = void 0;
|
|
7
|
+
const buildConditionExpression_1 = __importDefault(require("./buildConditionExpression"));
|
|
8
|
+
var SortExpressionKey;
|
|
9
|
+
(function (SortExpressionKey) {
|
|
10
|
+
SortExpressionKey["BW"] = "bw";
|
|
11
|
+
SortExpressionKey["LT"] = "lt";
|
|
12
|
+
SortExpressionKey["LE"] = "le";
|
|
13
|
+
SortExpressionKey["GT"] = "gt";
|
|
14
|
+
SortExpressionKey["GE"] = "ge";
|
|
15
|
+
})(SortExpressionKey || (exports.SortExpressionKey = SortExpressionKey = {}));
|
|
16
|
+
;
|
|
17
|
+
/** Builds condition expression for a table query. */
|
|
18
|
+
const buildQueryConditionExpression = (query, partitionKey, sortKey) => {
|
|
19
|
+
const { [partitionKey]: partitionKeyValue, [sortKey]: sortKeyValue, [`${sortKey}:${SortExpressionKey.BW}`]: sortKeyBeginsWithValue, [`${sortKey}:${SortExpressionKey.LT}`]: sortKeyLowerThanValue, [`${sortKey}:${SortExpressionKey.LE}`]: sortKeyLowerThanOrEqualValue, [`${sortKey}:${SortExpressionKey.GT}`]: sortKeyGreaterThanValue, [`${sortKey}:${SortExpressionKey.GE}`]: sortKeyGreaterThanOrEqualValue, ...conditionQuery } = query;
|
|
20
|
+
const { ConditionExpression, ExpressionAttributeNames, ExpressionAttributeValues, } = (0, buildConditionExpression_1.default)(conditionQuery);
|
|
21
|
+
ExpressionAttributeNames[`#${partitionKey}`] = partitionKey;
|
|
22
|
+
ExpressionAttributeValues[`:${partitionKey}`] = partitionKeyValue;
|
|
23
|
+
const KeyConditionExpression = `#${partitionKey} = :${partitionKey}`;
|
|
24
|
+
const result = {
|
|
25
|
+
ConditionExpression,
|
|
26
|
+
KeyConditionExpression,
|
|
27
|
+
ExpressionAttributeNames,
|
|
28
|
+
ExpressionAttributeValues
|
|
29
|
+
};
|
|
30
|
+
const isBetweenValues = !!sortKeyLowerThanValue && !!sortKeyGreaterThanValue;
|
|
31
|
+
if (isBetweenValues) {
|
|
32
|
+
result.KeyConditionExpression += ` AND #${sortKey} BETWEEN :${sortKey}_gt AND :${sortKey}_lt`;
|
|
33
|
+
result.ExpressionAttributeNames[`#${sortKey}`] = sortKey;
|
|
34
|
+
result.ExpressionAttributeValues[`:${sortKey}_lt`] = sortKeyLowerThanValue;
|
|
35
|
+
result.ExpressionAttributeValues[`:${sortKey}_gt`] = sortKeyGreaterThanValue;
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
if (sortKeyLowerThanValue) {
|
|
39
|
+
result.KeyConditionExpression += ` AND #${sortKey} < :${sortKey}_lt`;
|
|
40
|
+
result.ExpressionAttributeNames[`#${sortKey}`] = sortKey;
|
|
41
|
+
result.ExpressionAttributeValues[`:${sortKey}_lt`] = sortKeyLowerThanValue;
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
if (sortKeyLowerThanOrEqualValue) {
|
|
45
|
+
result.KeyConditionExpression += ` AND #${sortKey} <= :${sortKey}_le`;
|
|
46
|
+
result.ExpressionAttributeNames[`#${sortKey}`] = sortKey;
|
|
47
|
+
result.ExpressionAttributeValues[`:${sortKey}_le`] = sortKeyLowerThanOrEqualValue;
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
if (sortKeyGreaterThanValue) {
|
|
51
|
+
result.KeyConditionExpression += ` AND #${sortKey} > :${sortKey}_gt`;
|
|
52
|
+
result.ExpressionAttributeNames[`#${sortKey}`] = sortKey;
|
|
53
|
+
result.ExpressionAttributeValues[`:${sortKey}_gt`] = sortKeyGreaterThanValue;
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
if (sortKeyGreaterThanOrEqualValue) {
|
|
57
|
+
result.KeyConditionExpression += ` AND #${sortKey} >= :${sortKey}_ge`;
|
|
58
|
+
result.ExpressionAttributeNames[`#${sortKey}`] = sortKey;
|
|
59
|
+
result.ExpressionAttributeValues[`:${sortKey}_ge`] = sortKeyGreaterThanOrEqualValue;
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
if (sortKeyBeginsWithValue) {
|
|
63
|
+
result.KeyConditionExpression += ` AND begins_with(#${sortKey}, :${sortKey})`;
|
|
64
|
+
result.ExpressionAttributeNames[`#${sortKey}`] = sortKey;
|
|
65
|
+
result.ExpressionAttributeValues[`:${sortKey}`] = sortKeyBeginsWithValue;
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
if (sortKeyValue) {
|
|
69
|
+
result.KeyConditionExpression += ` AND #${sortKey} = :${sortKey}`;
|
|
70
|
+
result.ExpressionAttributeNames[`#${sortKey}`] = sortKey;
|
|
71
|
+
result.ExpressionAttributeValues[`:${sortKey}`] = sortKeyValue;
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
75
|
+
};
|
|
76
|
+
exports.default = buildQueryConditionExpression;
|
|
77
|
+
//# sourceMappingURL=buildQueryConditionExpression.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildQueryConditionExpression.js","sourceRoot":"","sources":["../../../../src/Table/helpers/buildQueryConditionExpression.ts"],"names":[],"mappings":";;;;;;AACA,0FAAkE;AAElE,IAAY,iBAMX;AAND,WAAY,iBAAiB;IAC3B,8BAAS,CAAA;IACT,8BAAS,CAAA;IACT,8BAAS,CAAA;IACT,8BAAS,CAAA;IACT,8BAAS,CAAA;AACX,CAAC,EANW,iBAAiB,iCAAj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M,CAAC,wBAAwB,CAAC,IAAI,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC;QACzD,MAAM,CAAC,yBAAyB,CAAC,IAAI,OAAO,KAAK,CAAC,GAAG,8BAA8B,CAAC;QAEpF,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,IAAI,sBAAsB,EAAE,CAAC;QAC3B,MAAM,CAAC,sBAAsB,IAAI,qBAAqB,OAAO,MAAM,OAAO,GAAG,CAAC;QAC9E,MAAM,CAAC,wBAAwB,CAAC,IAAI,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC;QACzD,MAAM,CAAC,yBAAyB,CAAC,IAAI,OAAO,EAAE,CAAC,GAAG,sBAAsB,CAAC;QAEzE,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,IAAI,YAAY,EAAE,CAAC;QACjB,MAAM,CAAC,sBAAsB,IAAI,SAAS,OAAO,OAAO,OAAO,EAAE,CAAC;QAClE,MAAM,CAAC,wBAAwB,CAAC,IAAI,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC;QACzD,MAAM,CAAC,yBAAyB,CAAC,IAAI,OAAO,EAAE,CAAC,GAAG,YAAY,CAAC;QAE/D,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF,kBAAe,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { TableOptions } from './getTableOptions';
|
|
2
|
+
import { type CreateTableInput } from '@aws-sdk/client-dynamodb';
|
|
3
|
+
/** Returns schema for a table from table options. */
|
|
4
|
+
declare const buildTableSchema: ({ name: TableName, primaryKey, isLocalhost, localSecondaryIndexes, globalSecondaryIndexes, }: TableOptions) => CreateTableInput;
|
|
5
|
+
export default buildTableSchema;
|
|
6
|
+
//# sourceMappingURL=buildTableSchema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildTableSchema.d.ts","sourceRoot":"","sources":["../../../../src/Table/helpers/buildTableSchema.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAwB,MAAM,mBAAmB,CAAC;AAC5E,OAAO,EACL,KAAK,gBAAgB,EAGtB,MAAM,0BAA0B,CAAC;AAyGlC,qDAAqD;AACrD,QAAA,MAAM,gBAAgB,GAAI,8FAMvB,YAAY,KAAG,gBA8BjB,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const lodash_1 = require("lodash");
|
|
4
|
+
const ProvisionedThroughput = {
|
|
5
|
+
ReadCapacityUnits: 1,
|
|
6
|
+
WriteCapacityUnits: 1,
|
|
7
|
+
};
|
|
8
|
+
const Projection = {
|
|
9
|
+
ProjectionType: 'ALL'
|
|
10
|
+
};
|
|
11
|
+
/** Returns attribute definitions for table schema. */
|
|
12
|
+
const getAttributeDefinitions = (primaryKey, localSecondaryIndexes, globalSecondaryIndexes) => {
|
|
13
|
+
const { partitionKey, sortKey } = primaryKey;
|
|
14
|
+
let attributes = [partitionKey, sortKey];
|
|
15
|
+
for (const localIndexKey in localSecondaryIndexes) {
|
|
16
|
+
const { sortKey } = localSecondaryIndexes[localIndexKey];
|
|
17
|
+
attributes.push(sortKey);
|
|
18
|
+
}
|
|
19
|
+
for (const globalIndexKey in globalSecondaryIndexes) {
|
|
20
|
+
const { partitionKey, sortKey } = globalSecondaryIndexes[globalIndexKey];
|
|
21
|
+
attributes.push(partitionKey);
|
|
22
|
+
if (sortKey) {
|
|
23
|
+
attributes.push(sortKey);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
attributes = (0, lodash_1.uniq)(attributes);
|
|
27
|
+
const AttributeDefinitions = attributes
|
|
28
|
+
.map(AttributeName => ({
|
|
29
|
+
// NOTE: Only composite keys are supported, no numbers.
|
|
30
|
+
AttributeType: 'S',
|
|
31
|
+
AttributeName,
|
|
32
|
+
}));
|
|
33
|
+
return AttributeDefinitions;
|
|
34
|
+
};
|
|
35
|
+
/** Returns secondary index. */
|
|
36
|
+
const getSecondaryIndex = (IndexName, partitionKey, sortKey) => {
|
|
37
|
+
const KeySchema = [
|
|
38
|
+
{
|
|
39
|
+
KeyType: 'HASH',
|
|
40
|
+
AttributeName: partitionKey
|
|
41
|
+
},
|
|
42
|
+
];
|
|
43
|
+
if (sortKey) {
|
|
44
|
+
KeySchema.push({
|
|
45
|
+
KeyType: 'RANGE',
|
|
46
|
+
AttributeName: sortKey
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
const index = {
|
|
50
|
+
IndexName,
|
|
51
|
+
KeySchema,
|
|
52
|
+
Projection,
|
|
53
|
+
};
|
|
54
|
+
return index;
|
|
55
|
+
};
|
|
56
|
+
/** Returns schemas for local secondary indexes. */
|
|
57
|
+
const getLocalSecondaryIndexes = (partitionKey, localSecondaryIndexes) => {
|
|
58
|
+
const indexes = localSecondaryIndexes
|
|
59
|
+
.map(({ name, sortKey }) => getSecondaryIndex(name, partitionKey, sortKey));
|
|
60
|
+
return indexes;
|
|
61
|
+
};
|
|
62
|
+
/** Returns schemas for global secondary indexes. */
|
|
63
|
+
const getGlobalSecondaryIndexes = (globalSecondaryIndexes, isLocalhost) => {
|
|
64
|
+
const indexes = globalSecondaryIndexes
|
|
65
|
+
.map(({ name, partitionKey, sortKey }) => getSecondaryIndex(name, partitionKey, sortKey));
|
|
66
|
+
/* istanbul ignore next */
|
|
67
|
+
if (!isLocalhost) {
|
|
68
|
+
return indexes;
|
|
69
|
+
}
|
|
70
|
+
indexes.forEach(index => index.ProvisionedThroughput = ProvisionedThroughput);
|
|
71
|
+
return indexes;
|
|
72
|
+
};
|
|
73
|
+
/** Returns schema for a table from table options. */
|
|
74
|
+
const buildTableSchema = ({ name: TableName, primaryKey, isLocalhost, localSecondaryIndexes, globalSecondaryIndexes, }) => {
|
|
75
|
+
const { partitionKey, sortKey } = primaryKey;
|
|
76
|
+
const AttributeDefinitions = getAttributeDefinitions(primaryKey, localSecondaryIndexes, globalSecondaryIndexes);
|
|
77
|
+
const LocalSecondaryIndexes = getLocalSecondaryIndexes(partitionKey, localSecondaryIndexes);
|
|
78
|
+
const GlobalSecondaryIndexes = getGlobalSecondaryIndexes(globalSecondaryIndexes, isLocalhost);
|
|
79
|
+
const KeySchema = [
|
|
80
|
+
{ KeyType: 'HASH', AttributeName: partitionKey },
|
|
81
|
+
{ KeyType: 'RANGE', AttributeName: sortKey }
|
|
82
|
+
];
|
|
83
|
+
const schema = {
|
|
84
|
+
TableName,
|
|
85
|
+
KeySchema,
|
|
86
|
+
AttributeDefinitions,
|
|
87
|
+
LocalSecondaryIndexes,
|
|
88
|
+
GlobalSecondaryIndexes,
|
|
89
|
+
};
|
|
90
|
+
/* istanbul ignore else */
|
|
91
|
+
if (isLocalhost) {
|
|
92
|
+
schema.ProvisionedThroughput = ProvisionedThroughput;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
schema.BillingMode = 'PAY_PER_REQUEST';
|
|
96
|
+
}
|
|
97
|
+
return schema;
|
|
98
|
+
};
|
|
99
|
+
exports.default = buildTableSchema;
|
|
100
|
+
//# sourceMappingURL=buildTableSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildTableSchema.js","sourceRoot":"","sources":["../../../../src/Table/helpers/buildTableSchema.ts"],"names":[],"mappings":";;AAAA,mCAA8B;AAQ9B,MAAM,qBAAqB,GAAG;IAC5B,iBAAiB,EAAE,CAAC;IACpB,kBAAkB,EAAE,CAAC;CACtB,CAAC;AAEF,MAAM,UAAU,GAAG;IACjB,cAAc,EAAE,KAAK;CACtB,CAAC;AAEF,sDAAsD;AACtD,MAAM,uBAAuB,GAAG,CAC9B,UAAsB,EACtB,qBAA4B,EAC5B,sBAA6B,EAC7B,EAAE;IACF,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,GAAG,UAAU,CAAC;IAE7C,IAAI,UAAU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MAAM,EAAE,aAAa,EAAE,YAAY,EAAE;QAChD,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE;KAC7C,CAAC;IAEF,MAAM,MAAM,GAAG;QACb,SAAS;QACT,SAAS;QACT,oBAAoB;QACpB,qBAAqB;QACrB,sBAAsB;KACH,CAAC;IAEtB,0BAA0B;IAC1B,IAAI,WAAW,EAAE,CAAC;QAChB,MAAM,CAAC,qBAAqB,GAAG,qBAAqB,CAAC;IAEvD,CAAC;SAAM,CAAC;QACN,MAAM,CAAC,WAAW,GAAG,iBAAiB,CAAC;IAEzC,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF,kBAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { QueryMap, MutationMap } from '@kravc/dos';
|
|
2
|
+
/** Builds update expression from a query for a table item update method. */
|
|
3
|
+
declare const buildUpdateExpression: (query: QueryMap, mutation: MutationMap) => {
|
|
4
|
+
UpdateExpression: string;
|
|
5
|
+
ConditionExpression: string | undefined;
|
|
6
|
+
ExpressionAttributeNames: Record<string, string>;
|
|
7
|
+
ExpressionAttributeValues: Record<string, unknown>;
|
|
8
|
+
};
|
|
9
|
+
export default buildUpdateExpression;
|
|
10
|
+
//# sourceMappingURL=buildUpdateExpression.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildUpdateExpression.d.ts","sourceRoot":"","sources":["../../../../src/Table/helpers/buildUpdateExpression.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAGxD,4EAA4E;AAC5E,QAAA,MAAM,qBAAqB,GAAI,OAAO,QAAQ,EAAE,UAAU,WAAW;;;;;CAwFpE,CAAC;AAEF,eAAe,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
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 buildConditionExpression_1 = __importDefault(require("./buildConditionExpression"));
|
|
7
|
+
/** Builds update expression from a query for a table item update method. */
|
|
8
|
+
const buildUpdateExpression = (query, mutation) => {
|
|
9
|
+
const UpdateExpressions = [];
|
|
10
|
+
const RemoveExpressions = [];
|
|
11
|
+
const { ConditionExpression: _ConditionExpression, ExpressionAttributeNames, ExpressionAttributeValues, } = (0, buildConditionExpression_1.default)(query);
|
|
12
|
+
let ConditionExpression = _ConditionExpression;
|
|
13
|
+
for (let name in mutation) {
|
|
14
|
+
const expressionValue = mutation[name];
|
|
15
|
+
const arrayItemIndex = name.match(/\[\d+\]/g);
|
|
16
|
+
name = name.replace(/\[\d+\]/g, '');
|
|
17
|
+
let path = '#' + name.replace(/\./g, '.#');
|
|
18
|
+
const valueKey = name.replace(/\.|:/g, '_');
|
|
19
|
+
const isAppend = name.endsWith(':append');
|
|
20
|
+
const isPrepend = name.endsWith(':prepend');
|
|
21
|
+
name = name.replace(/:append/, '');
|
|
22
|
+
name = name.replace(/:prepend/, '');
|
|
23
|
+
const pathKeys = name.split('.');
|
|
24
|
+
for (const pathKey of pathKeys) {
|
|
25
|
+
ExpressionAttributeNames[`#${pathKey}`] = pathKey;
|
|
26
|
+
}
|
|
27
|
+
const shouldRemoveAttribute = expressionValue === null;
|
|
28
|
+
if (shouldRemoveAttribute) {
|
|
29
|
+
RemoveExpressions.push(`${path}`);
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (isAppend || isPrepend) {
|
|
33
|
+
path = path.replace(/:append/, '');
|
|
34
|
+
path = path.replace(/:prepend/, '');
|
|
35
|
+
ExpressionAttributeValues[`:${valueKey}`] = [expressionValue];
|
|
36
|
+
ExpressionAttributeValues[`:${valueKey}_item`] = expressionValue;
|
|
37
|
+
ConditionExpression += ` AND not contains (${path}, :${valueKey}_item)`;
|
|
38
|
+
if (isAppend) {
|
|
39
|
+
UpdateExpressions.push(`${path} = list_append(#${name}, :${valueKey})`);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
UpdateExpressions.push(`${path} = list_append(:${valueKey}, #${name})`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
ExpressionAttributeValues[`:${valueKey}`] = expressionValue;
|
|
47
|
+
path = `${path}${arrayItemIndex ? arrayItemIndex : ''}`;
|
|
48
|
+
UpdateExpressions.push(`${path} = :${valueKey}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const UpdatedExpressions = [];
|
|
52
|
+
const hasUpdateExpressions = UpdateExpressions.length > 0;
|
|
53
|
+
if (hasUpdateExpressions) {
|
|
54
|
+
UpdatedExpressions.push(`SET ${UpdateExpressions.join(', ')}`);
|
|
55
|
+
}
|
|
56
|
+
const hasRemoveAttributes = RemoveExpressions.length > 0;
|
|
57
|
+
if (hasRemoveAttributes) {
|
|
58
|
+
UpdatedExpressions.push(`REMOVE ${RemoveExpressions.join(', ')}`);
|
|
59
|
+
}
|
|
60
|
+
const UpdateExpression = UpdatedExpressions.join(' ');
|
|
61
|
+
return {
|
|
62
|
+
UpdateExpression,
|
|
63
|
+
ConditionExpression,
|
|
64
|
+
ExpressionAttributeNames,
|
|
65
|
+
ExpressionAttributeValues,
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
exports.default = buildUpdateExpression;
|
|
69
|
+
//# sourceMappingURL=buildUpdateExpression.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildUpdateExpression.js","sourceRoot":"","sources":["../../../../src/Table/helpers/buildUpdateExpression.ts"],"names":[],"mappings":";;;;;AACA,0FAAkE;AAElE,4EAA4E;AAC5E,MAAM,qBAAqB,GAAG,CAAC,KAAe,EAAE,QAAqB,EAAE,EAAE;IACvE,MAAM,iBAAiB,G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IAED,MAAM,mBAAmB,GAAG,iBAAiB,CAAC,MAAM,GAAG,CAAC,CAAC;IAEzD,IAAI,mBAAmB,EAAE,CAAC;QACxB,kBAAkB,CAAC,IAAI,CAAC,UAAU,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACpE,CAAC;IAED,MAAM,gBAAgB,GAAG,kBAAkB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAEtD,OAAO;QACL,gBAAgB;QAChB,mBAAmB;QACnB,wBAAwB;QACxB,yBAAyB;KAC1B,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { QueryMap } from '@kravc/dos';
|
|
2
|
+
/** Ensures item matches condition expression built from a query. */
|
|
3
|
+
declare function filterConditionExpression<T>(item: T, query: QueryMap): T | undefined;
|
|
4
|
+
export default filterConditionExpression;
|
|
5
|
+
//# sourceMappingURL=filterConditionExpression.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filterConditionExpression.d.ts","sourceRoot":"","sources":["../../../../src/Table/helpers/filterConditionExpression.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAG3C,oEAAoE;AACpE,iBAAS,yBAAyB,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,QAAQ,GAAG,CAAC,GAAG,SAAS,CA+E7E;AAED,eAAe,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const lodash_1 = require("lodash");
|
|
4
|
+
const buildConditionExpression_1 = require("./buildConditionExpression");
|
|
5
|
+
/** Ensures item matches condition expression built from a query. */
|
|
6
|
+
function filterConditionExpression(item, query) {
|
|
7
|
+
if (!item) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const conditionEntries = Object.entries(query);
|
|
11
|
+
for (const [key, value] of conditionEntries) {
|
|
12
|
+
const isNot = key.endsWith(`:${buildConditionExpression_1.ExpressionKey.NOT}`);
|
|
13
|
+
const isContains = key.endsWith(`:${buildConditionExpression_1.ExpressionKey.CONTAIN}`);
|
|
14
|
+
// const isLessThan = key.endsWith(':lt')
|
|
15
|
+
// const isGreaterThan = key.endsWith(':gt')
|
|
16
|
+
const isNotContains = key.endsWith(`:${buildConditionExpression_1.ExpressionKey.EXCLUDE}`);
|
|
17
|
+
const isFilterValueArray = Array.isArray(value);
|
|
18
|
+
const isFilterValueNull = value === null;
|
|
19
|
+
let path = key;
|
|
20
|
+
/** Checks items are equal. */
|
|
21
|
+
let match = (a, b) => a === b;
|
|
22
|
+
if (isNot) {
|
|
23
|
+
path = key.replace(/:not/g, '');
|
|
24
|
+
/** Checks items are not equal. */
|
|
25
|
+
match = (a, b) => a !== b;
|
|
26
|
+
}
|
|
27
|
+
if (isFilterValueNull) {
|
|
28
|
+
if (isNot) {
|
|
29
|
+
/** Checks item is not undefined. */
|
|
30
|
+
match = (a) => a !== undefined;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
/** Checks item is undefined. */
|
|
34
|
+
match = (a) => a === undefined;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (isContains) {
|
|
38
|
+
path = key.replace(/:contains/g, '');
|
|
39
|
+
/** Checks item includes value. */
|
|
40
|
+
match = (a, b) => a.includes(b);
|
|
41
|
+
}
|
|
42
|
+
if (isNotContains) {
|
|
43
|
+
path = key.replace(/:not_contains/g, '');
|
|
44
|
+
/** Checks item does not include value. */
|
|
45
|
+
match = (a, b) => !a.includes(b);
|
|
46
|
+
}
|
|
47
|
+
if (isFilterValueArray) {
|
|
48
|
+
/** Checks item is included in the array. */
|
|
49
|
+
match = (a, b) => b.includes(a);
|
|
50
|
+
}
|
|
51
|
+
// if (isLessThan) {
|
|
52
|
+
// path = key.replace(/:lt/g, '')
|
|
53
|
+
// }
|
|
54
|
+
// if (isGreaterThan) {
|
|
55
|
+
// path = key.replace(/:gt/g, '')
|
|
56
|
+
// }
|
|
57
|
+
const itemValue = (0, lodash_1.get)(item, path);
|
|
58
|
+
const isMatched = match(itemValue, value);
|
|
59
|
+
if (isMatched) {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
return item;
|
|
65
|
+
}
|
|
66
|
+
;
|
|
67
|
+
exports.default = filterConditionExpression;
|
|
68
|
+
//# sourceMappingURL=filterConditionExpression.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filterConditionExpression.js","sourceRoot":"","sources":["../../../../src/Table/helpers/filterConditionExpression.ts"],"names":[],"mappings":";;AAAA,mCAA6B;AAE7B,yEAA2D;AAE3D,oEAAoE;AACpE,SAAS,yBAAyB,CAAI,IAAO,EAAE,KAAe;IAC5D,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO;IACT,CAAC;IAED,MAAM,gBAAgB,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAE/C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,gBAAgB,EAAE,CAAC;QAC5C,MAAM,KAAK,GAAG,GAAG,CAAC,QAAQ,CAAC,IAAI,wCAAa,CAAC,GAAG,EAAE,CAAC,CAAC;QACpD,MAAM,UAAU,GAAG,GAAG,CAAC,QAAQ,CAAC,IAAI,wCAAa,CAAC,OAAO,EAAE,CAAC,CAAC;QAC7D,4CAA4C;QAC5C,4CAA4C;QAC5C,MAAM,aAAa,GAAG,GAAG,CAAC,QAAQ,CAAC,IAAI,wCAAa,CAAC,OAAO,EAAE,CAAC,CAAC;QAEhE,MAAM,kBAAkB,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAEhD,MAAM,iBAAiB,GAAG,KAAK,KAAK,IAAI,CA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,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QACnE,CAAC;QAED,oBAAoB;QACpB,mCAAmC;QACnC,IAAI;QAEJ,uBAAuB;QACvB,mCAAmC;QACnC,IAAI;QAEJ,MAAM,SAAS,GAAG,IAAA,YAAG,EAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAClC,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QAE1C,IAAI,SAAS,EAAE,CAAC;YACd,SAAS;QACX,CAAC;QAED,OAAO;IACT,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAAA,CAAC;AAEF,kBAAe,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type DynamoDBClientConfig } from '@aws-sdk/client-dynamodb';
|
|
2
|
+
/** Returns config for DynamoDB raw client. */
|
|
3
|
+
declare const getRawClientConfig: (region: string, profile: string) => DynamoDBClientConfig;
|
|
4
|
+
export default getRawClientConfig;
|
|
5
|
+
//# sourceMappingURL=getRawClientConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getRawClientConfig.d.ts","sourceRoot":"","sources":["../../../../src/Table/helpers/getRawClientConfig.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAQrE,8CAA8C;AAC9C,QAAA,MAAM,kBAAkB,GAAI,QAAQ,MAAM,EAAE,SAAS,MAAM,KAAG,oBAmB7D,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const os_1 = require("os");
|
|
4
|
+
const credential_providers_1 = require("@aws-sdk/credential-providers");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const getTableOptions_1 = require("./getTableOptions");
|
|
7
|
+
const HOME = (0, os_1.homedir)();
|
|
8
|
+
const hasAwsCredentials = (0, fs_1.existsSync)(`${HOME}/.aws/credentials`);
|
|
9
|
+
const LOCAL_ENDPOINT = 'http://0.0.0.0:8000';
|
|
10
|
+
const DEFAULT_MAX_ATTEMPTS = 10;
|
|
11
|
+
/** Returns config for DynamoDB raw client. */
|
|
12
|
+
const getRawClientConfig = (region, profile) => {
|
|
13
|
+
const config = {
|
|
14
|
+
maxAttempts: DEFAULT_MAX_ATTEMPTS,
|
|
15
|
+
region,
|
|
16
|
+
};
|
|
17
|
+
const isLocal = region === getTableOptions_1.LOCAL_REGION;
|
|
18
|
+
/* istanbul ignore else */
|
|
19
|
+
if (isLocal) {
|
|
20
|
+
config.endpoint = LOCAL_ENDPOINT;
|
|
21
|
+
}
|
|
22
|
+
/* istanbul ignore else */
|
|
23
|
+
if (hasAwsCredentials) {
|
|
24
|
+
config.credentials = (0, credential_providers_1.fromIni)({ profile });
|
|
25
|
+
}
|
|
26
|
+
return config;
|
|
27
|
+
};
|
|
28
|
+
exports.default = getRawClientConfig;
|
|
29
|
+
//# sourceMappingURL=getRawClientConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getRawClientConfig.js","sourceRoot":"","sources":["../../../../src/Table/helpers/getRawClientConfig.ts"],"names":[],"mappings":";;AAAA,2BAA6B;AAC7B,wEAAwD;AACxD,2BAAgC;AAChC,uDAAiD;AAGjD,MAAM,IAAI,GAAG,IAAA,YAAO,GAAE,CAAC;AACvB,MAAM,iBAAiB,GAAG,IAAA,eAAU,EAAC,GAAG,IAAI,mBAAmB,CAAC,CAAC;AAEjE,MAAM,cAAc,GAAG,qBAAqB,CAAC;AAC7C,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAEhC,8CAA8C;AAC9C,MAAM,kBAAkB,GAAG,CAAC,MAAc,EAAE,OAAe,EAAwB,EAAE;IACnF,MAAM,MAAM,GAAG;QACb,WAAW,EAAE,oBAAoB;QACjC,MAAM;KACiB,CAAC;IAE1B,MAAM,OAAO,GAAG,MAAM,KAAK,8BAAY,CAAC;IAExC,0BAA0B;IAC1B,IAAI,OAAO,EAAE,CAAC;QACZ,MAAM,CAAC,QAAQ,GAAG,cAAc,CAAC;IACnC,CAAC;IAED,0BAA0B;IAC1B,IAAI,iBAAiB,EAAE,CAAC;QACtB,MAAM,CAAC,WAAW,GAAG,IAAA,8BAAO,EAAC,EAAE,OAAO,EAAE,CAAC,CAAC;IAC5C,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF,kBAAe,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export declare const LOCAL_REGION = "local";
|
|
2
|
+
export type LSI = {
|
|
3
|
+
name: string;
|
|
4
|
+
sortKey: string;
|
|
5
|
+
};
|
|
6
|
+
export type GSI = {
|
|
7
|
+
name: string;
|
|
8
|
+
partitionKey: string;
|
|
9
|
+
sortKey: string;
|
|
10
|
+
};
|
|
11
|
+
export type PrimaryKey = {
|
|
12
|
+
sortKey: string;
|
|
13
|
+
partitionKey: string;
|
|
14
|
+
};
|
|
15
|
+
export type LocalIndexKeyComposer = {
|
|
16
|
+
documentName: string;
|
|
17
|
+
sk: string;
|
|
18
|
+
};
|
|
19
|
+
export type GlobalIndexKeyComposer = {
|
|
20
|
+
pk: string;
|
|
21
|
+
sk?: string;
|
|
22
|
+
};
|
|
23
|
+
type LocalIndexProps = {
|
|
24
|
+
indexName: string;
|
|
25
|
+
sortKeyName: string;
|
|
26
|
+
};
|
|
27
|
+
type GlobalIndexProps = {
|
|
28
|
+
indexName: string;
|
|
29
|
+
sortKeyName: string;
|
|
30
|
+
partitionKeyName: string;
|
|
31
|
+
};
|
|
32
|
+
export type TableOptions = {
|
|
33
|
+
name: string;
|
|
34
|
+
region: string;
|
|
35
|
+
profile: string;
|
|
36
|
+
indexKeys: Record<string, LocalIndexKeyComposer | Record<string, GlobalIndexKeyComposer>>;
|
|
37
|
+
primaryKey: PrimaryKey;
|
|
38
|
+
isLocalhost: boolean;
|
|
39
|
+
localSecondaryIndexes: LSI[];
|
|
40
|
+
globalSecondaryIndexes: GSI[];
|
|
41
|
+
getLocalIndexSortKeyName: (indexName: string) => string;
|
|
42
|
+
getGlobalIndexPartitionKeyName: (indexName: string) => string;
|
|
43
|
+
getGlobalIndexSortKeyName: (indexName: string) => string;
|
|
44
|
+
isLocalSecondaryIndex: (indexName: string) => boolean;
|
|
45
|
+
getLocalIndexProps: (indexName: string) => LocalIndexProps;
|
|
46
|
+
getGlobalIndexProps: (indexName: string) => GlobalIndexProps;
|
|
47
|
+
};
|
|
48
|
+
/** Returns options for DynamoDB table creation. */
|
|
49
|
+
declare const getTableOptions: (partitionKey: string, sortKey: string) => TableOptions;
|
|
50
|
+
export default getTableOptions;
|
|
51
|
+
//# sourceMappingURL=getTableOptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getTableOptions.d.ts","sourceRoot":"","sources":["../../../../src/Table/helpers/getTableOptions.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,YAAY,UAAU,CAAC;AAGpC,MAAM,MAAM,GAAG,GAAG;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,GAAG,GAAG;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC;AACzE,MAAM,MAAM,sBAAsB,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,EAAE,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;A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