@webiny/db-dynamodb 0.0.0-mt-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/BatchProcess.d.ts +31 -0
  2. package/BatchProcess.js +196 -0
  3. package/DynamoDbDriver.d.ts +27 -0
  4. package/DynamoDbDriver.js +272 -0
  5. package/LICENSE +21 -0
  6. package/QueryGenerator.d.ts +19 -0
  7. package/QueryGenerator.js +79 -0
  8. package/README.md +67 -0
  9. package/index.d.ts +2 -0
  10. package/index.js +15 -0
  11. package/operators/comparison/beginsWith.d.ts +3 -0
  12. package/operators/comparison/beginsWith.js +24 -0
  13. package/operators/comparison/between.d.ts +3 -0
  14. package/operators/comparison/between.js +30 -0
  15. package/operators/comparison/eq.d.ts +3 -0
  16. package/operators/comparison/eq.js +34 -0
  17. package/operators/comparison/gt.d.ts +3 -0
  18. package/operators/comparison/gt.js +24 -0
  19. package/operators/comparison/gte.d.ts +3 -0
  20. package/operators/comparison/gte.js +24 -0
  21. package/operators/comparison/lt.d.ts +3 -0
  22. package/operators/comparison/lt.js +24 -0
  23. package/operators/comparison/lte.d.ts +3 -0
  24. package/operators/comparison/lte.js +24 -0
  25. package/operators/index.d.ts +12 -0
  26. package/operators/index.js +39 -0
  27. package/operators/logical/and.d.ts +3 -0
  28. package/operators/logical/and.js +63 -0
  29. package/operators/logical/or.d.ts +3 -0
  30. package/operators/logical/or.js +63 -0
  31. package/package.json +45 -0
  32. package/plugins/definitions/AttributePlugin.d.ts +20 -0
  33. package/plugins/definitions/AttributePlugin.js +61 -0
  34. package/plugins/definitions/DateTimeTransformPlugin.d.ts +4 -0
  35. package/plugins/definitions/DateTimeTransformPlugin.js +54 -0
  36. package/plugins/definitions/FieldPathPlugin.d.ts +22 -0
  37. package/plugins/definitions/FieldPathPlugin.js +48 -0
  38. package/plugins/definitions/FieldPlugin.d.ts +34 -0
  39. package/plugins/definitions/FieldPlugin.js +73 -0
  40. package/plugins/definitions/NumberTransformPlugin.d.ts +4 -0
  41. package/plugins/definitions/NumberTransformPlugin.js +49 -0
  42. package/plugins/definitions/TimeTransformPlugin.d.ts +4 -0
  43. package/plugins/definitions/TimeTransformPlugin.js +65 -0
  44. package/plugins/definitions/ValueFilterPlugin.d.ts +20 -0
  45. package/plugins/definitions/ValueFilterPlugin.js +49 -0
  46. package/plugins/definitions/ValueTransformPlugin.d.ts +22 -0
  47. package/plugins/definitions/ValueTransformPlugin.js +52 -0
  48. package/plugins/definitions/assignFields.d.ts +1 -0
  49. package/plugins/definitions/assignFields.js +37 -0
  50. package/plugins/filters/andIn.d.ts +3 -0
  51. package/plugins/filters/andIn.js +35 -0
  52. package/plugins/filters/between.d.ts +3 -0
  53. package/plugins/filters/between.js +36 -0
  54. package/plugins/filters/contains.d.ts +3 -0
  55. package/plugins/filters/contains.js +32 -0
  56. package/plugins/filters/eq.d.ts +3 -0
  57. package/plugins/filters/eq.js +20 -0
  58. package/plugins/filters/fuzzy.d.ts +3 -0
  59. package/plugins/filters/fuzzy.js +30 -0
  60. package/plugins/filters/gt.d.ts +3 -0
  61. package/plugins/filters/gt.js +20 -0
  62. package/plugins/filters/gte.d.ts +3 -0
  63. package/plugins/filters/gte.js +20 -0
  64. package/plugins/filters/in.d.ts +3 -0
  65. package/plugins/filters/in.js +35 -0
  66. package/plugins/filters/index.d.ts +2 -0
  67. package/plugins/filters/index.js +32 -0
  68. package/plugins/filters/lt.d.ts +3 -0
  69. package/plugins/filters/lt.js +20 -0
  70. package/plugins/filters/lte.d.ts +3 -0
  71. package/plugins/filters/lte.js +20 -0
  72. package/plugins/index.d.ts +2 -0
  73. package/plugins/index.js +19 -0
  74. package/statements/createKeyConditionExpressionArgs.d.ts +12 -0
  75. package/statements/createKeyConditionExpressionArgs.js +48 -0
  76. package/statements/processStatement.d.ts +4 -0
  77. package/statements/processStatement.js +39 -0
  78. package/types.d.ts +29 -0
  79. package/types.js +5 -0
  80. package/utils/attributes.d.ts +10 -0
  81. package/utils/attributes.js +35 -0
  82. package/utils/batchRead.d.ts +15 -0
  83. package/utils/batchRead.js +58 -0
  84. package/utils/batchWrite.d.ts +17 -0
  85. package/utils/batchWrite.js +30 -0
  86. package/utils/cleanup.d.ts +3 -0
  87. package/utils/cleanup.js +53 -0
  88. package/utils/cursor.d.ts +2 -0
  89. package/utils/cursor.js +26 -0
  90. package/utils/documentClient.d.ts +8 -0
  91. package/utils/documentClient.js +33 -0
  92. package/utils/filter.d.ts +12 -0
  93. package/utils/filter.js +212 -0
  94. package/utils/get.d.ts +17 -0
  95. package/utils/get.js +30 -0
  96. package/utils/listResponse.d.ts +13 -0
  97. package/utils/listResponse.js +30 -0
  98. package/utils/query.d.ts +33 -0
  99. package/utils/query.js +127 -0
  100. package/utils/sort.d.ts +17 -0
  101. package/utils/sort.js +93 -0
  102. package/utils/table.d.ts +7 -0
  103. package/utils/table.js +27 -0
package/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # @webiny/db-dynamodb
2
+ [![](https://img.shields.io/npm/dw/webiny-data-dynamodb.svg)](https://www.npmjs.com/package/webiny-data-dynamodb)
3
+ [![](https://img.shields.io/npm/v/webiny-data-dynamodb.svg)](https://www.npmjs.com/package/webiny-data-dynamodb)
4
+ [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
5
+ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
6
+
7
+ A set of frequently used data-dynamodb higher order functions.
8
+
9
+ For more information, please visit
10
+ [the official docs](https://github.com/doitadrian/data-dynamodb).
11
+
12
+ ## Install
13
+ ```
14
+ yarn add @webiny/db-dynamodb
15
+ ```
16
+
17
+
18
+ ### Helper functions
19
+ We have a number [helper](./src/utils) functions that ease the use of either dynamodb-toolbox, filtering, sorting or just creating proper response.
20
+
21
+ #### [batchRead](./src/utils/batchRead.ts)
22
+ Read a batch of records from the DynamoDB table.
23
+
24
+ This function accepts [table](https://github.com/jeremydaly/dynamodb-toolbox/blob/main/src/classes/Table.ts) and items, an array of objects created by [Entity.getBatch()](https://github.com/jeremydaly/dynamodb-toolbox/blob/main/src/classes/Entity.ts#L313).
25
+
26
+ Internally it reads records until there are no more to read and returns a list of read records.
27
+
28
+ #### [batchWrite](./src/utils/batchWrite.ts)
29
+ Write a batch of records to the DynamoDB table.
30
+
31
+ This function accepts [table](https://github.com/jeremydaly/dynamodb-toolbox/blob/main/src/classes/Table.ts) and items, an array of objects created by [Entity.putBatch()](https://github.com/jeremydaly/dynamodb-toolbox/blob/main/src/classes/Entity.ts#L989).
32
+ It also accepts a number which defines a number of items to be written in one request. DO NOT put that number over the official DynamoDB maximum.
33
+
34
+ Internally it loops through the items received (in chunks of `maxChunks` parameter) and does not return anything.
35
+
36
+
37
+ #### [cleanupItem and cleanupItems](./src/utils/cleanup.ts)
38
+ Clean up records received from the DynamoDB table.
39
+
40
+ This function accepts [entity](https://github.com/jeremydaly/dynamodb-toolbox/blob/main/src/classes/Entity.ts) and item to be cleaned up, in case of the cleanupItem.
41
+ In case of `cleanupItems` it accepts an array of items to clean up.
42
+
43
+ We use this to remove the properties that dynamodb-toolbox puts on the record automatically.
44
+
45
+ #### [get](./src/utils/get.ts)
46
+ Get a single record from the DynamoDB table with given keys.
47
+
48
+ This function accepts [entity](https://github.com/jeremydaly/dynamodb-toolbox/blob/main/src/classes/Entity.ts) and keys to fetch the record by.
49
+
50
+ It returns either record or null. By default, [entity.get()](https://github.com/jeremydaly/dynamodb-toolbox/blob/main/src/classes/Entity.ts#L281) returns a object with some meta data and `Item` property, which contains the record (or null if no record).
51
+
52
+ #### [queryOne and queryAll](./src/utils/query.ts)
53
+ Query the DynamoDB table for record(s) by given partition key and query options.
54
+
55
+ This function accepts [entity](https://github.com/jeremydaly/dynamodb-toolbox/blob/main/src/classes/Entity.ts) to perform the query on, `partitionKey` to query by and [options](https://github.com/jeremydaly/dynamodb-toolbox/blob/main/src/classes/Table.ts#L65) to define the query parameters with.
56
+
57
+ The `queryAll` method accepts `limit`, a number with which you can load only a certain amount of records. The `queryOne` method does not have that property.
58
+
59
+ #### [filter](./src/utils/filter.ts)
60
+ Filter the DynamoDB records by given where condition.
61
+
62
+ This function accepts items (records) to be filtered, a definition of fields to filter by (not required by default if no field modification is required), where conditions (eg. `{published: true, date_gte: "2021-01-01"}`) and filtering plugins.
63
+
64
+ #### [sort](./src/utils/sort.ts)
65
+ Sort the DynamoDB records by given sort condition.
66
+
67
+ This function accepts items (records) to be sorted, sort options (eg. createdBy_ASC, id_DESC, etc.) and a definitions of fields to sort by (not required by default if no field modification is required).
package/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { default as DynamoDbDriver } from "./DynamoDbDriver";
2
+ export { DynamoDbDriver };
package/index.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ Object.defineProperty(exports, "DynamoDbDriver", {
9
+ enumerable: true,
10
+ get: function () {
11
+ return _DynamoDbDriver.default;
12
+ }
13
+ });
14
+
15
+ var _DynamoDbDriver = _interopRequireDefault(require("./DynamoDbDriver"));
@@ -0,0 +1,3 @@
1
+ import { Operator } from "../../types";
2
+ declare const beginsWith: Operator;
3
+ export default beginsWith;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ const beginsWith = {
8
+ canProcess: ({
9
+ value
10
+ }) => {
11
+ return value && typeof value["$beginsWith"] !== "undefined";
12
+ },
13
+ process: ({
14
+ key,
15
+ value,
16
+ args
17
+ }) => {
18
+ args.expression += `begins_with (#${key}, :${key})`;
19
+ args.attributeNames[`#${key}`] = key;
20
+ args.attributeValues[`:${key}`] = value["$beginsWith"];
21
+ }
22
+ };
23
+ var _default = beginsWith;
24
+ exports.default = _default;
@@ -0,0 +1,3 @@
1
+ import { Operator } from "../../types";
2
+ declare const between: Operator;
3
+ export default between;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ const between = {
8
+ canProcess: ({
9
+ value
10
+ }) => {
11
+ return value && typeof value["$between"] !== "undefined";
12
+ },
13
+ process: ({
14
+ key,
15
+ value
16
+ }) => {
17
+ return {
18
+ statement: `#${key} BETWEEN :${key}Gte AND :${key}Lte`,
19
+ attributeNames: {
20
+ [`#${key}`]: key
21
+ },
22
+ attributeValues: {
23
+ [`:${key}Gte`]: value[0],
24
+ [`:${key}Lte`]: value[1]
25
+ }
26
+ };
27
+ }
28
+ };
29
+ var _default = between;
30
+ exports.default = _default;
@@ -0,0 +1,3 @@
1
+ import { Operator } from "../../types";
2
+ declare const eq: Operator;
3
+ export default eq;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ const validTypes = ["string", "boolean", "number"];
8
+ const eq = {
9
+ canProcess: ({
10
+ key,
11
+ value
12
+ }) => {
13
+ if (key && key.charAt(0) === "$") {
14
+ return false;
15
+ }
16
+
17
+ if (value && typeof value["$eq"] !== "undefined") {
18
+ return true;
19
+ }
20
+
21
+ return validTypes.includes(typeof value);
22
+ },
23
+ process: ({
24
+ key,
25
+ value,
26
+ args
27
+ }) => {
28
+ args.expression += `#${key} = :${key}`;
29
+ args.attributeNames[`#${key}`] = key;
30
+ args.attributeValues[`:${key}`] = value;
31
+ }
32
+ };
33
+ var _default = eq;
34
+ exports.default = _default;
@@ -0,0 +1,3 @@
1
+ import { Operator } from "../../types";
2
+ declare const gt: Operator;
3
+ export default gt;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ const gt = {
8
+ canProcess: ({
9
+ value
10
+ }) => {
11
+ return value && typeof value["$gt"] !== "undefined";
12
+ },
13
+ process: ({
14
+ key,
15
+ value,
16
+ args
17
+ }) => {
18
+ args.expression += `#${key} > :${key}`;
19
+ args.attributeNames[`#${key}`] = key;
20
+ args.attributeValues[`:${key}`] = value["$gt"];
21
+ }
22
+ };
23
+ var _default = gt;
24
+ exports.default = _default;
@@ -0,0 +1,3 @@
1
+ import { Operator } from "../../types";
2
+ declare const gte: Operator;
3
+ export default gte;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ const gte = {
8
+ canProcess: ({
9
+ value
10
+ }) => {
11
+ return value && typeof value["$gte"] !== "undefined";
12
+ },
13
+ process: ({
14
+ key,
15
+ value,
16
+ args
17
+ }) => {
18
+ args.expression += `#${key} >= :${key}`;
19
+ args.attributeNames[`#${key}`] = key;
20
+ args.attributeValues[`:${key}`] = value["$gte"];
21
+ }
22
+ };
23
+ var _default = gte;
24
+ exports.default = _default;
@@ -0,0 +1,3 @@
1
+ import { Operator } from "../../types";
2
+ declare const lt: Operator;
3
+ export default lt;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ const lt = {
8
+ canProcess: ({
9
+ value
10
+ }) => {
11
+ return value && typeof value["$lt"] !== "undefined";
12
+ },
13
+ process: ({
14
+ key,
15
+ value,
16
+ args
17
+ }) => {
18
+ args.expression += `#${key} < :${key}`;
19
+ args.attributeNames[`#${key}`] = key;
20
+ args.attributeValues[`:${key}`] = value["$lt"];
21
+ }
22
+ };
23
+ var _default = lt;
24
+ exports.default = _default;
@@ -0,0 +1,3 @@
1
+ import { Operator } from "../../types";
2
+ declare const lte: Operator;
3
+ export default lte;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ const lte = {
8
+ canProcess: ({
9
+ value
10
+ }) => {
11
+ return value && typeof value["$lte"] !== "undefined";
12
+ },
13
+ process: ({
14
+ key,
15
+ value,
16
+ args
17
+ }) => {
18
+ args.expression += `#${key} <= :${key}`;
19
+ args.attributeNames[`#${key}`] = key;
20
+ args.attributeValues[`:${key}`] = value["$lte"];
21
+ }
22
+ };
23
+ var _default = lte;
24
+ exports.default = _default;
@@ -0,0 +1,12 @@
1
+ declare const _default: {
2
+ $and: import("../types").Operator;
3
+ $or: import("../types").Operator;
4
+ $beginsWith: import("../types").Operator;
5
+ $between: import("../types").Operator;
6
+ $eq: import("../types").Operator;
7
+ $gt: import("../types").Operator;
8
+ $gte: import("../types").Operator;
9
+ $lt: import("../types").Operator;
10
+ $lte: import("../types").Operator;
11
+ };
12
+ export default _default;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _and = _interopRequireDefault(require("./logical/and"));
11
+
12
+ var _or = _interopRequireDefault(require("./logical/or"));
13
+
14
+ var _beginsWith = _interopRequireDefault(require("./comparison/beginsWith"));
15
+
16
+ var _between = _interopRequireDefault(require("./comparison/between"));
17
+
18
+ var _gt = _interopRequireDefault(require("./comparison/gt"));
19
+
20
+ var _gte = _interopRequireDefault(require("./comparison/gte"));
21
+
22
+ var _lt = _interopRequireDefault(require("./comparison/lt"));
23
+
24
+ var _lte = _interopRequireDefault(require("./comparison/lte"));
25
+
26
+ var _eq = _interopRequireDefault(require("./comparison/eq"));
27
+
28
+ var _default = {
29
+ $and: _and.default,
30
+ $or: _or.default,
31
+ $beginsWith: _beginsWith.default,
32
+ $between: _between.default,
33
+ $eq: _eq.default,
34
+ $gt: _gt.default,
35
+ $gte: _gte.default,
36
+ $lt: _lt.default,
37
+ $lte: _lte.default
38
+ };
39
+ exports.default = _default;
@@ -0,0 +1,3 @@
1
+ import { Operator } from "../../types";
2
+ declare const and: Operator;
3
+ export default and;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ const processQuery = (query, andArgs, processStatement) => {
9
+ const args = {
10
+ expression: "",
11
+ attributeNames: {},
12
+ attributeValues: {}
13
+ };
14
+ processStatement({
15
+ args,
16
+ query
17
+ });
18
+ Object.assign(andArgs.attributeNames, args.attributeNames);
19
+ Object.assign(andArgs.attributeValues, args.attributeValues);
20
+
21
+ if (andArgs.expression === "") {
22
+ andArgs.expression = args.expression;
23
+ } else {
24
+ andArgs.expression += " and " + args.expression;
25
+ }
26
+ };
27
+
28
+ const and = {
29
+ canProcess: ({
30
+ key
31
+ }) => {
32
+ return key === "$and";
33
+ },
34
+ process: ({
35
+ value,
36
+ args,
37
+ processStatement
38
+ }) => {
39
+ const andArgs = {
40
+ expression: "",
41
+ attributeNames: {},
42
+ attributeValues: {}
43
+ };
44
+
45
+ if (Array.isArray(value)) {
46
+ for (let i = 0; i < value.length; i++) {
47
+ processQuery(value[i], andArgs, processStatement);
48
+ }
49
+ } else {
50
+ for (const [andKey, andValue] of Object.entries(value)) {
51
+ processQuery({
52
+ [andKey]: andValue
53
+ }, andArgs, processStatement);
54
+ }
55
+ }
56
+
57
+ args.expression += "(" + andArgs.expression + ")";
58
+ Object.assign(args.attributeNames, andArgs.attributeNames);
59
+ Object.assign(args.attributeValues, andArgs.attributeValues);
60
+ }
61
+ };
62
+ var _default = and;
63
+ exports.default = _default;
@@ -0,0 +1,3 @@
1
+ import { Operator } from "../../types";
2
+ declare const or: Operator;
3
+ export default or;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ const processQuery = (query, orArgs, processStatement) => {
9
+ const args = {
10
+ expression: "",
11
+ attributeNames: {},
12
+ attributeValues: {}
13
+ };
14
+ processStatement({
15
+ args,
16
+ query
17
+ });
18
+ Object.assign(orArgs.attributeNames, args.attributeNames);
19
+ Object.assign(orArgs.attributeValues, args.attributeValues);
20
+
21
+ if (orArgs.expression === "") {
22
+ orArgs.expression = args.expression;
23
+ } else {
24
+ orArgs.expression += " or " + args.expression;
25
+ }
26
+ };
27
+
28
+ const or = {
29
+ canProcess: ({
30
+ key
31
+ }) => {
32
+ return key === "$or";
33
+ },
34
+ process: ({
35
+ value,
36
+ args,
37
+ processStatement
38
+ }) => {
39
+ const orArgs = {
40
+ expression: "",
41
+ attributeNames: {},
42
+ attributeValues: {}
43
+ };
44
+
45
+ if (Array.isArray(value)) {
46
+ for (let i = 0; i < value.length; i++) {
47
+ processQuery(value[i], orArgs, processStatement);
48
+ }
49
+ } else {
50
+ for (const [orKey, orValue] of Object.entries(value)) {
51
+ processQuery({
52
+ [orKey]: orValue
53
+ }, orArgs, processStatement);
54
+ }
55
+ }
56
+
57
+ args.expression += "(" + orArgs.expression + ")";
58
+ Object.assign(args.attributeNames, orArgs.attributeNames);
59
+ Object.assign(args.attributeValues, orArgs.attributeValues);
60
+ }
61
+ };
62
+ var _default = or;
63
+ exports.default = _default;
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@webiny/db-dynamodb",
3
+ "version": "0.0.0-mt-1",
4
+ "main": "index.js",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/webiny/webiny-js.git"
8
+ },
9
+ "description": "A DynamoDB driver for the @webiny/db database client.",
10
+ "author": "Webiny Ltd",
11
+ "license": "MIT",
12
+ "dependencies": {
13
+ "@webiny/db": "0.0.0-mt-1",
14
+ "@webiny/error": "0.0.0-mt-1",
15
+ "@webiny/handler": "0.0.0-mt-1",
16
+ "@webiny/handler-db": "0.0.0-mt-1",
17
+ "@webiny/plugins": "0.0.0-mt-1",
18
+ "date-fns": "2.25.0",
19
+ "dot-prop": "6.0.1",
20
+ "fuse.js": "6.4.6",
21
+ "is-number": "7.0.0",
22
+ "lodash": "4.17.21"
23
+ },
24
+ "devDependencies": {
25
+ "@babel/cli": "^7.5.5",
26
+ "@babel/core": "^7.5.5",
27
+ "@webiny/cli": "^0.0.0-mt-1",
28
+ "@webiny/project-utils": "^0.0.0-mt-1",
29
+ "dynamodb-toolbox": "^0.3.4",
30
+ "jest": "^26.6.3",
31
+ "jest-dynalite": "^3.2.0",
32
+ "rimraf": "^3.0.2",
33
+ "ttypescript": "^1.5.12",
34
+ "typescript": "^4.1.3"
35
+ },
36
+ "publishConfig": {
37
+ "access": "public",
38
+ "directory": "dist"
39
+ },
40
+ "scripts": {
41
+ "build": "yarn webiny run build",
42
+ "watch": "yarn webiny run watch"
43
+ },
44
+ "gitHead": "37736d8456a6ecb342a6c3645060bd9a3f2d4bb0"
45
+ }
@@ -0,0 +1,20 @@
1
+ import { Plugin } from "@webiny/plugins";
2
+ import { DynamoDBTypes } from "dynamodb-toolbox/dist/classes/Table";
3
+ import { EntityAttributeConfig, EntityCompositeAttributes } from "dynamodb-toolbox/dist/classes/Entity";
4
+ export declare type DefinitionParams = DynamoDBTypes | EntityAttributeConfig | EntityCompositeAttributes;
5
+ export interface Params {
6
+ entity: string;
7
+ attribute: string;
8
+ params: DefinitionParams;
9
+ }
10
+ export declare abstract class AttributePlugin extends Plugin {
11
+ static readonly type = "db.dynamodb.attribute";
12
+ private readonly _entity;
13
+ private readonly _attribute;
14
+ private readonly _params;
15
+ get entity(): string;
16
+ get attribute(): string;
17
+ constructor({ entity, attribute, params }: Params);
18
+ getDefinition(): Record<string, DefinitionParams>;
19
+ private validateReserved;
20
+ }
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.AttributePlugin = void 0;
9
+
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
12
+ var _plugins = require("@webiny/plugins");
13
+
14
+ var _error = _interopRequireDefault(require("@webiny/error"));
15
+
16
+ const reservedFields = ["PK", "SK", "index", "data"];
17
+
18
+ class AttributePlugin extends _plugins.Plugin {
19
+ get entity() {
20
+ return this._entity;
21
+ }
22
+
23
+ get attribute() {
24
+ return this._attribute;
25
+ }
26
+
27
+ constructor({
28
+ entity,
29
+ attribute,
30
+ params
31
+ }) {
32
+ super();
33
+ (0, _defineProperty2.default)(this, "_entity", void 0);
34
+ (0, _defineProperty2.default)(this, "_attribute", void 0);
35
+ (0, _defineProperty2.default)(this, "_params", void 0);
36
+ this.validateReserved(attribute);
37
+ this._entity = entity;
38
+ this._attribute = attribute;
39
+ this._params = params;
40
+ }
41
+
42
+ getDefinition() {
43
+ return {
44
+ [this.attribute]: this._params
45
+ };
46
+ }
47
+
48
+ validateReserved(attribute) {
49
+ if (reservedFields.includes(attribute) === false) {
50
+ return;
51
+ }
52
+
53
+ throw new _error.default(`Attribute name "${attribute}" is not allowed.`, "ATTRIBUTE_NOT_ALLOWED", {
54
+ attribute
55
+ });
56
+ }
57
+
58
+ }
59
+
60
+ exports.AttributePlugin = AttributePlugin;
61
+ (0, _defineProperty2.default)(AttributePlugin, "type", "db.dynamodb.attribute");
@@ -0,0 +1,4 @@
1
+ import { ValueTransformPlugin, Params } from "./ValueTransformPlugin";
2
+ export declare class DateTimeTransformPlugin extends ValueTransformPlugin {
3
+ constructor(params: Omit<Params, "transform">);
4
+ }