@webiny/db-dynamodb 0.0.0-ee-vpcs.549378cf03

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 (153) hide show
  1. package/BatchProcess.d.ts +47 -0
  2. package/BatchProcess.js +198 -0
  3. package/BatchProcess.js.map +1 -0
  4. package/DynamoDbDriver.d.ts +35 -0
  5. package/DynamoDbDriver.js +274 -0
  6. package/DynamoDbDriver.js.map +1 -0
  7. package/LICENSE +21 -0
  8. package/QueryGenerator.d.ts +21 -0
  9. package/QueryGenerator.js +78 -0
  10. package/QueryGenerator.js.map +1 -0
  11. package/README.md +67 -0
  12. package/index.d.ts +2 -0
  13. package/index.js +15 -0
  14. package/index.js.map +1 -0
  15. package/operators/comparison/beginsWith.d.ts +3 -0
  16. package/operators/comparison/beginsWith.js +24 -0
  17. package/operators/comparison/beginsWith.js.map +1 -0
  18. package/operators/comparison/between.d.ts +3 -0
  19. package/operators/comparison/between.js +30 -0
  20. package/operators/comparison/between.js.map +1 -0
  21. package/operators/comparison/eq.d.ts +3 -0
  22. package/operators/comparison/eq.js +34 -0
  23. package/operators/comparison/eq.js.map +1 -0
  24. package/operators/comparison/gt.d.ts +3 -0
  25. package/operators/comparison/gt.js +24 -0
  26. package/operators/comparison/gt.js.map +1 -0
  27. package/operators/comparison/gte.d.ts +3 -0
  28. package/operators/comparison/gte.js +24 -0
  29. package/operators/comparison/gte.js.map +1 -0
  30. package/operators/comparison/lt.d.ts +3 -0
  31. package/operators/comparison/lt.js +24 -0
  32. package/operators/comparison/lt.js.map +1 -0
  33. package/operators/comparison/lte.d.ts +3 -0
  34. package/operators/comparison/lte.js +24 -0
  35. package/operators/comparison/lte.js.map +1 -0
  36. package/operators/index.d.ts +12 -0
  37. package/operators/index.js +39 -0
  38. package/operators/index.js.map +1 -0
  39. package/operators/logical/and.d.ts +3 -0
  40. package/operators/logical/and.js +63 -0
  41. package/operators/logical/and.js.map +1 -0
  42. package/operators/logical/or.d.ts +3 -0
  43. package/operators/logical/or.js +63 -0
  44. package/operators/logical/or.js.map +1 -0
  45. package/package.json +46 -0
  46. package/plugins/definitions/AttributePlugin.d.ts +20 -0
  47. package/plugins/definitions/AttributePlugin.js +61 -0
  48. package/plugins/definitions/AttributePlugin.js.map +1 -0
  49. package/plugins/definitions/DateTimeTransformPlugin.d.ts +4 -0
  50. package/plugins/definitions/DateTimeTransformPlugin.js +54 -0
  51. package/plugins/definitions/DateTimeTransformPlugin.js.map +1 -0
  52. package/plugins/definitions/FieldPathPlugin.d.ts +22 -0
  53. package/plugins/definitions/FieldPathPlugin.js +46 -0
  54. package/plugins/definitions/FieldPathPlugin.js.map +1 -0
  55. package/plugins/definitions/FieldPlugin.d.ts +34 -0
  56. package/plugins/definitions/FieldPlugin.js +73 -0
  57. package/plugins/definitions/FieldPlugin.js.map +1 -0
  58. package/plugins/definitions/NumberTransformPlugin.d.ts +4 -0
  59. package/plugins/definitions/NumberTransformPlugin.js +45 -0
  60. package/plugins/definitions/NumberTransformPlugin.js.map +1 -0
  61. package/plugins/definitions/TimeTransformPlugin.d.ts +4 -0
  62. package/plugins/definitions/TimeTransformPlugin.js +61 -0
  63. package/plugins/definitions/TimeTransformPlugin.js.map +1 -0
  64. package/plugins/definitions/ValueFilterPlugin.d.ts +20 -0
  65. package/plugins/definitions/ValueFilterPlugin.js +49 -0
  66. package/plugins/definitions/ValueFilterPlugin.js.map +1 -0
  67. package/plugins/definitions/ValueTransformPlugin.d.ts +22 -0
  68. package/plugins/definitions/ValueTransformPlugin.js +50 -0
  69. package/plugins/definitions/ValueTransformPlugin.js.map +1 -0
  70. package/plugins/definitions/assignFields.d.ts +1 -0
  71. package/plugins/definitions/assignFields.js +37 -0
  72. package/plugins/definitions/assignFields.js.map +1 -0
  73. package/plugins/filters/andIn.d.ts +3 -0
  74. package/plugins/filters/andIn.js +36 -0
  75. package/plugins/filters/andIn.js.map +1 -0
  76. package/plugins/filters/between.d.ts +3 -0
  77. package/plugins/filters/between.js +37 -0
  78. package/plugins/filters/between.js.map +1 -0
  79. package/plugins/filters/contains.d.ts +3 -0
  80. package/plugins/filters/contains.js +33 -0
  81. package/plugins/filters/contains.js.map +1 -0
  82. package/plugins/filters/eq.d.ts +3 -0
  83. package/plugins/filters/eq.js +34 -0
  84. package/plugins/filters/eq.js.map +1 -0
  85. package/plugins/filters/fuzzy.d.ts +3 -0
  86. package/plugins/filters/fuzzy.js +31 -0
  87. package/plugins/filters/fuzzy.js.map +1 -0
  88. package/plugins/filters/gt.d.ts +3 -0
  89. package/plugins/filters/gt.js +21 -0
  90. package/plugins/filters/gt.js.map +1 -0
  91. package/plugins/filters/gte.d.ts +3 -0
  92. package/plugins/filters/gte.js +21 -0
  93. package/plugins/filters/gte.js.map +1 -0
  94. package/plugins/filters/in.d.ts +3 -0
  95. package/plugins/filters/in.js +36 -0
  96. package/plugins/filters/in.js.map +1 -0
  97. package/plugins/filters/index.d.ts +2 -0
  98. package/plugins/filters/index.js +34 -0
  99. package/plugins/filters/index.js.map +1 -0
  100. package/plugins/filters/lt.d.ts +3 -0
  101. package/plugins/filters/lt.js +21 -0
  102. package/plugins/filters/lt.js.map +1 -0
  103. package/plugins/filters/lte.d.ts +3 -0
  104. package/plugins/filters/lte.js +21 -0
  105. package/plugins/filters/lte.js.map +1 -0
  106. package/plugins/filters/startsWith.d.ts +3 -0
  107. package/plugins/filters/startsWith.js +34 -0
  108. package/plugins/filters/startsWith.js.map +1 -0
  109. package/plugins/index.d.ts +2 -0
  110. package/plugins/index.js +19 -0
  111. package/plugins/index.js.map +1 -0
  112. package/statements/createKeyConditionExpressionArgs.d.ts +15 -0
  113. package/statements/createKeyConditionExpressionArgs.js +52 -0
  114. package/statements/createKeyConditionExpressionArgs.js.map +1 -0
  115. package/statements/processStatement.d.ts +3 -0
  116. package/statements/processStatement.js +42 -0
  117. package/statements/processStatement.js.map +1 -0
  118. package/types.d.ts +58 -0
  119. package/types.js +5 -0
  120. package/types.js.map +1 -0
  121. package/utils/attributes.d.ts +10 -0
  122. package/utils/attributes.js +31 -0
  123. package/utils/attributes.js.map +1 -0
  124. package/utils/batchRead.d.ts +15 -0
  125. package/utils/batchRead.js +89 -0
  126. package/utils/batchRead.js.map +1 -0
  127. package/utils/batchWrite.d.ts +17 -0
  128. package/utils/batchWrite.js +30 -0
  129. package/utils/batchWrite.js.map +1 -0
  130. package/utils/cleanup.d.ts +3 -0
  131. package/utils/cleanup.js +45 -0
  132. package/utils/cleanup.js.map +1 -0
  133. package/utils/cursor.d.ts +2 -0
  134. package/utils/cursor.js +26 -0
  135. package/utils/cursor.js.map +1 -0
  136. package/utils/filter.d.ts +12 -0
  137. package/utils/filter.js +213 -0
  138. package/utils/filter.js.map +1 -0
  139. package/utils/get.d.ts +17 -0
  140. package/utils/get.js +30 -0
  141. package/utils/get.js.map +1 -0
  142. package/utils/listResponse.d.ts +13 -0
  143. package/utils/listResponse.js +33 -0
  144. package/utils/listResponse.js.map +1 -0
  145. package/utils/query.d.ts +32 -0
  146. package/utils/query.js +119 -0
  147. package/utils/query.js.map +1 -0
  148. package/utils/sort.d.ts +17 -0
  149. package/utils/sort.js +91 -0
  150. package/utils/sort.js.map +1 -0
  151. package/utils/table.d.ts +7 -0
  152. package/utils/table.js +27 -0
  153. package/utils/table.js.map +1 -0
@@ -0,0 +1,15 @@
1
+ import { Query, QueryKey, QuerySort } from "../types";
2
+ interface Output {
3
+ KeyConditionExpression: string;
4
+ ExpressionAttributeNames: Record<string, any>;
5
+ ExpressionAttributeValues: Record<string, any>;
6
+ ScanIndexForward: boolean;
7
+ IndexName: string;
8
+ }
9
+ interface Params {
10
+ query: Query;
11
+ sort: QuerySort;
12
+ key: QueryKey;
13
+ }
14
+ declare const _default: ({ query, sort, key }: Params) => Output;
15
+ export default _default;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _processStatement = _interopRequireDefault(require("./processStatement"));
11
+
12
+ /**
13
+ * Remove this when no apps are using our internal db drivers anymore
14
+ */
15
+ // @ts-nocheck
16
+ var _default = ({
17
+ query,
18
+ sort,
19
+ key
20
+ }) => {
21
+ const args = {
22
+ expression: "",
23
+ attributeNames: {},
24
+ attributeValues: {}
25
+ };
26
+ (0, _processStatement.default)({
27
+ args,
28
+ query: {
29
+ $and: query
30
+ }
31
+ });
32
+ const output = {
33
+ KeyConditionExpression: args.expression,
34
+ ExpressionAttributeNames: args.attributeNames,
35
+ ExpressionAttributeValues: args.attributeValues,
36
+ ScanIndexForward: true,
37
+ IndexName: null
38
+ };
39
+ const sortKey = key.fields && key.fields[1];
40
+
41
+ if (sort && sort[sortKey.name] === -1) {
42
+ output.ScanIndexForward = false;
43
+ }
44
+
45
+ if (!key.primary) {
46
+ output.IndexName = key.name;
47
+ }
48
+
49
+ return output;
50
+ };
51
+
52
+ exports.default = _default;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["query","sort","key","args","expression","attributeNames","attributeValues","processStatement","$and","output","KeyConditionExpression","ExpressionAttributeNames","ExpressionAttributeValues","ScanIndexForward","IndexName","sortKey","fields","name","primary"],"sources":["createKeyConditionExpressionArgs.ts"],"sourcesContent":["/**\n * Remove this when no apps are using our internal db drivers anymore\n */\n// @ts-nocheck\nimport processStatement from \"./processStatement\";\nimport { ProcessStatementArgsParam, Query, QueryKey, QuerySort } from \"~/types\";\n\ninterface Output {\n KeyConditionExpression: string;\n ExpressionAttributeNames: Record<string, any>;\n ExpressionAttributeValues: Record<string, any>;\n ScanIndexForward: boolean;\n IndexName: string;\n}\ninterface Params {\n query: Query;\n sort: QuerySort;\n key: QueryKey;\n}\nexport default ({ query, sort, key }: Params): Output => {\n const args: ProcessStatementArgsParam = {\n expression: \"\",\n attributeNames: {},\n attributeValues: {}\n };\n\n processStatement({ args, query: { $and: query } });\n\n const output: Output = {\n KeyConditionExpression: args.expression,\n ExpressionAttributeNames: args.attributeNames,\n ExpressionAttributeValues: args.attributeValues,\n ScanIndexForward: true,\n IndexName: null\n };\n\n const sortKey = key.fields && key.fields[1];\n if (sort && sort[sortKey.name] === -1) {\n output.ScanIndexForward = false;\n }\n\n if (!key.primary) {\n output.IndexName = key.name;\n }\n\n return output;\n};\n"],"mappings":";;;;;;;;;AAIA;;AAJA;AACA;AACA;AACA;eAgBe,CAAC;EAAEA,KAAF;EAASC,IAAT;EAAeC;AAAf,CAAD,KAA0C;EACrD,MAAMC,IAA+B,GAAG;IACpCC,UAAU,EAAE,EADwB;IAEpCC,cAAc,EAAE,EAFoB;IAGpCC,eAAe,EAAE;EAHmB,CAAxC;EAMA,IAAAC,yBAAA,EAAiB;IAAEJ,IAAF;IAAQH,KAAK,EAAE;MAAEQ,IAAI,EAAER;IAAR;EAAf,CAAjB;EAEA,MAAMS,MAAc,GAAG;IACnBC,sBAAsB,EAAEP,IAAI,CAACC,UADV;IAEnBO,wBAAwB,EAAER,IAAI,CAACE,cAFZ;IAGnBO,yBAAyB,EAAET,IAAI,CAACG,eAHb;IAInBO,gBAAgB,EAAE,IAJC;IAKnBC,SAAS,EAAE;EALQ,CAAvB;EAQA,MAAMC,OAAO,GAAGb,GAAG,CAACc,MAAJ,IAAcd,GAAG,CAACc,MAAJ,CAAW,CAAX,CAA9B;;EACA,IAAIf,IAAI,IAAIA,IAAI,CAACc,OAAO,CAACE,IAAT,CAAJ,KAAuB,CAAC,CAApC,EAAuC;IACnCR,MAAM,CAACI,gBAAP,GAA0B,KAA1B;EACH;;EAED,IAAI,CAACX,GAAG,CAACgB,OAAT,EAAkB;IACdT,MAAM,CAACK,SAAP,GAAmBZ,GAAG,CAACe,IAAvB;EACH;;EAED,OAAOR,MAAP;AACH,C"}
@@ -0,0 +1,3 @@
1
+ import { ProcessStatementCallable } from "../types";
2
+ declare const processStatement: ProcessStatementCallable;
3
+ export default processStatement;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _operators = _interopRequireDefault(require("./../operators"));
11
+
12
+ const processStatement = ({
13
+ args,
14
+ query
15
+ }) => {
16
+ outerLoop: for (const [key, value] of Object.entries(query)) {
17
+ const operators = Object.values(_operators.default);
18
+
19
+ for (let i = 0; i < operators.length; i++) {
20
+ const operator = operators[i];
21
+
22
+ if (operator.canProcess({
23
+ key,
24
+ value,
25
+ args
26
+ })) {
27
+ operator.process({
28
+ key,
29
+ value,
30
+ args,
31
+ processStatement
32
+ });
33
+ continue outerLoop;
34
+ }
35
+ }
36
+
37
+ throw new Error(`Invalid operator {${key} : ${value}}.`);
38
+ }
39
+ };
40
+
41
+ var _default = processStatement;
42
+ exports.default = _default;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["processStatement","args","query","outerLoop","key","value","Object","entries","operators","values","allOperators","i","length","operator","canProcess","process","Error"],"sources":["processStatement.ts"],"sourcesContent":["import allOperators from \"./../operators\";\nimport { ProcessStatementCallable } from \"~/types\";\n\nconst processStatement: ProcessStatementCallable = ({ args, query }) => {\n outerLoop: for (const [key, value] of Object.entries(query)) {\n const operators = Object.values(allOperators);\n for (let i = 0; i < operators.length; i++) {\n const operator = operators[i];\n if (operator.canProcess({ key, value, args })) {\n operator.process({ key, value, args, processStatement });\n continue outerLoop;\n }\n }\n throw new Error(`Invalid operator {${key} : ${value}}.`);\n }\n};\nexport default processStatement;\n"],"mappings":";;;;;;;;;AAAA;;AAGA,MAAMA,gBAA0C,GAAG,CAAC;EAAEC,IAAF;EAAQC;AAAR,CAAD,KAAqB;EACpEC,SAAS,EAAE,KAAK,MAAM,CAACC,GAAD,EAAMC,KAAN,CAAX,IAA2BC,MAAM,CAACC,OAAP,CAAeL,KAAf,CAA3B,EAAkD;IACzD,MAAMM,SAAS,GAAGF,MAAM,CAACG,MAAP,CAAcC,kBAAd,CAAlB;;IACA,KAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGH,SAAS,CAACI,MAA9B,EAAsCD,CAAC,EAAvC,EAA2C;MACvC,MAAME,QAAQ,GAAGL,SAAS,CAACG,CAAD,CAA1B;;MACA,IAAIE,QAAQ,CAACC,UAAT,CAAoB;QAAEV,GAAF;QAAOC,KAAP;QAAcJ;MAAd,CAApB,CAAJ,EAA+C;QAC3CY,QAAQ,CAACE,OAAT,CAAiB;UAAEX,GAAF;UAAOC,KAAP;UAAcJ,IAAd;UAAoBD;QAApB,CAAjB;QACA,SAASG,SAAT;MACH;IACJ;;IACD,MAAM,IAAIa,KAAJ,CAAW,qBAAoBZ,GAAI,MAAKC,KAAM,IAA9C,CAAN;EACH;AACJ,CAZD;;eAaeL,gB"}
package/types.d.ts ADDED
@@ -0,0 +1,58 @@
1
+ export interface OperatorArgs {
2
+ expression: string;
3
+ attributeNames: Record<string, any>;
4
+ attributeValues: Record<string, any>;
5
+ }
6
+ interface CanProcessArgs {
7
+ key: string;
8
+ value: any;
9
+ args: OperatorArgs;
10
+ }
11
+ interface ProcessArgs {
12
+ key: string;
13
+ value: any;
14
+ args: OperatorArgs;
15
+ processStatement: any;
16
+ }
17
+ export interface Operator {
18
+ canProcess: ({ key }: CanProcessArgs) => boolean;
19
+ process: ({ key, value, args }: ProcessArgs) => void;
20
+ }
21
+ /**
22
+ * We use this definition to search for a value in any given field that was passed.
23
+ * It works as an "OR" condition.
24
+ */
25
+ export interface DynamoDbContainsFilter {
26
+ fields: string[];
27
+ value: string;
28
+ }
29
+ export interface ProcessStatementArgsParam {
30
+ expression: string;
31
+ attributeNames: Record<string, any>;
32
+ attributeValues: Record<string, any>;
33
+ }
34
+ export interface ProcessStatementQueryParam {
35
+ [key: string]: any;
36
+ }
37
+ export interface ProcessStatementParams {
38
+ args: ProcessStatementArgsParam;
39
+ query: ProcessStatementQueryParam;
40
+ }
41
+ export interface ProcessStatementCallable {
42
+ (params: ProcessStatementParams): void;
43
+ }
44
+ export interface Query {
45
+ [key: string]: string;
46
+ }
47
+ export interface QueryKeyField {
48
+ name: string;
49
+ }
50
+ export interface QueryKey {
51
+ fields: QueryKeyField[];
52
+ primary?: boolean;
53
+ unique?: boolean;
54
+ name: string;
55
+ }
56
+ export declare type QueryKeys = QueryKey[];
57
+ export declare type QuerySort = Record<string, -1 | 1>;
58
+ export {};
package/types.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
package/types.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["export interface OperatorArgs {\n expression: string;\n attributeNames: Record<string, any>;\n attributeValues: Record<string, any>;\n}\n\ninterface CanProcessArgs {\n key: string;\n value: any;\n args: OperatorArgs;\n}\n\ninterface ProcessArgs {\n key: string;\n value: any;\n args: OperatorArgs;\n processStatement: any;\n}\n\nexport interface Operator {\n canProcess: ({ key }: CanProcessArgs) => boolean;\n process: ({ key, value, args }: ProcessArgs) => void;\n}\n\n/**\n * We use this definition to search for a value in any given field that was passed.\n * It works as an \"OR\" condition.\n */\nexport interface DynamoDbContainsFilter {\n fields: string[];\n value: string;\n}\n\nexport interface ProcessStatementArgsParam {\n expression: string;\n attributeNames: Record<string, any>;\n attributeValues: Record<string, any>;\n}\nexport interface ProcessStatementQueryParam {\n [key: string]: any;\n}\nexport interface ProcessStatementParams {\n args: ProcessStatementArgsParam;\n query: ProcessStatementQueryParam;\n}\n\nexport interface ProcessStatementCallable {\n (params: ProcessStatementParams): void;\n}\n\nexport interface Query {\n [key: string]: string;\n}\nexport interface QueryKeyField {\n name: string;\n}\nexport interface QueryKey {\n fields: QueryKeyField[];\n primary?: boolean;\n unique?: boolean;\n name: string;\n}\nexport type QueryKeys = QueryKey[];\n\nexport type QuerySort = Record<string, -1 | 1>;\n"],"mappings":""}
@@ -0,0 +1,10 @@
1
+ import { Context } from "@webiny/api/types";
2
+ import { DefinitionParams } from "../plugins/definitions/AttributePlugin";
3
+ import { PluginsContainer } from "@webiny/plugins";
4
+ /**
5
+ * Will be removed in favor of directly assigning attributes to a certain entity when creating the storage operations.
6
+ *
7
+ * @deprecated
8
+ */
9
+ export declare const getExtraAttributes: (context: Context, entity: string) => Record<string, DefinitionParams>;
10
+ export declare const getExtraAttributesFromPlugins: (plugins: PluginsContainer, entity: string) => Record<string, DefinitionParams>;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.getExtraAttributesFromPlugins = exports.getExtraAttributes = void 0;
9
+
10
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
+
12
+ var _AttributePlugin = require("../plugins/definitions/AttributePlugin");
13
+
14
+ /**
15
+ * Will be removed in favor of directly assigning attributes to a certain entity when creating the storage operations.
16
+ *
17
+ * @deprecated
18
+ */
19
+ const getExtraAttributes = (context, entity) => {
20
+ return getExtraAttributesFromPlugins(context.plugins, entity);
21
+ };
22
+
23
+ exports.getExtraAttributes = getExtraAttributes;
24
+
25
+ const getExtraAttributesFromPlugins = (plugins, entity) => {
26
+ return plugins.byType(_AttributePlugin.AttributePlugin.type).filter(plugin => plugin.entity === entity).reduce((attributes, plugin) => {
27
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, attributes), plugin.getDefinition());
28
+ }, {});
29
+ };
30
+
31
+ exports.getExtraAttributesFromPlugins = getExtraAttributesFromPlugins;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["getExtraAttributes","context","entity","getExtraAttributesFromPlugins","plugins","byType","AttributePlugin","type","filter","plugin","reduce","attributes","getDefinition"],"sources":["attributes.ts"],"sourcesContent":["import { Context } from \"@webiny/api/types\";\nimport { AttributePlugin, DefinitionParams } from \"~/plugins/definitions/AttributePlugin\";\nimport { PluginsContainer } from \"@webiny/plugins\";\n\n/**\n * Will be removed in favor of directly assigning attributes to a certain entity when creating the storage operations.\n *\n * @deprecated\n */\nexport const getExtraAttributes = (\n context: Context,\n entity: string\n): Record<string, DefinitionParams> => {\n return getExtraAttributesFromPlugins(context.plugins, entity);\n};\n\nexport const getExtraAttributesFromPlugins = (\n plugins: PluginsContainer,\n entity: string\n): Record<string, DefinitionParams> => {\n return plugins\n .byType<AttributePlugin>(AttributePlugin.type)\n .filter(plugin => plugin.entity === entity)\n .reduce((attributes, plugin) => {\n return {\n ...attributes,\n ...plugin.getDefinition()\n };\n }, {});\n};\n"],"mappings":";;;;;;;;;;;AACA;;AAGA;AACA;AACA;AACA;AACA;AACO,MAAMA,kBAAkB,GAAG,CAC9BC,OAD8B,EAE9BC,MAF8B,KAGK;EACnC,OAAOC,6BAA6B,CAACF,OAAO,CAACG,OAAT,EAAkBF,MAAlB,CAApC;AACH,CALM;;;;AAOA,MAAMC,6BAA6B,GAAG,CACzCC,OADyC,EAEzCF,MAFyC,KAGN;EACnC,OAAOE,OAAO,CACTC,MADE,CACsBC,gCAAA,CAAgBC,IADtC,EAEFC,MAFE,CAEKC,MAAM,IAAIA,MAAM,CAACP,MAAP,KAAkBA,MAFjC,EAGFQ,MAHE,CAGK,CAACC,UAAD,EAAaF,MAAb,KAAwB;IAC5B,mEACOE,UADP,GAEOF,MAAM,CAACG,aAAP,EAFP;EAIH,CARE,EAQA,EARA,CAAP;AASH,CAbM"}
@@ -0,0 +1,15 @@
1
+ import { Table } from "dynamodb-toolbox";
2
+ interface Item {
3
+ Table: Table;
4
+ Key: any;
5
+ }
6
+ interface Params {
7
+ table: Table;
8
+ items: Item[];
9
+ }
10
+ /**
11
+ * This helper function is meant to be used to batch read from one table.
12
+ * It will fetch all results, as there is a next() method call built in.
13
+ */
14
+ export declare const batchReadAll: <T = any>(params: Params, maxChunk?: number) => Promise<T[]>;
15
+ export {};
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.batchReadAll = void 0;
9
+
10
+ var _chunk = _interopRequireDefault(require("lodash/chunk"));
11
+
12
+ var _error = _interopRequireDefault(require("@webiny/error"));
13
+
14
+ const MAX_BATCH_ITEMS = 100;
15
+
16
+ const flatten = responses => {
17
+ const entries = [];
18
+ const values = Object.values(responses);
19
+
20
+ for (const items of values) {
21
+ entries.push(...items);
22
+ }
23
+
24
+ return entries;
25
+ };
26
+
27
+ const batchReadAllChunk = async params => {
28
+ const {
29
+ table,
30
+ items
31
+ } = params;
32
+ const records = [];
33
+ const result = await table.batchGet(items);
34
+
35
+ if (!result || !result.Responses) {
36
+ return records;
37
+ }
38
+
39
+ records.push(...flatten(result.Responses));
40
+
41
+ if (!result.next || typeof result.next !== "function") {
42
+ return records;
43
+ }
44
+
45
+ let previous = result;
46
+
47
+ while (typeof previous.next === "function") {
48
+ const nextResult = await previous.next();
49
+
50
+ if (!nextResult) {
51
+ return records;
52
+ }
53
+
54
+ records.push(...flatten(nextResult.Responses));
55
+ previous = nextResult;
56
+ }
57
+
58
+ return records;
59
+ };
60
+ /**
61
+ * This helper function is meant to be used to batch read from one table.
62
+ * It will fetch all results, as there is a next() method call built in.
63
+ */
64
+
65
+
66
+ const batchReadAll = async (params, maxChunk = MAX_BATCH_ITEMS) => {
67
+ if (params.items.length === 0) {
68
+ return [];
69
+ } else if (maxChunk > MAX_BATCH_ITEMS) {
70
+ throw new _error.default(`Cannot set to load more than ${MAX_BATCH_ITEMS} items from the DynamoDB at once.`, "DYNAMODB_MAX_BATCH_GET_LIMIT_ERROR", {
71
+ maxChunk
72
+ });
73
+ }
74
+
75
+ const records = [];
76
+ const chunkItemsList = (0, _chunk.default)(params.items, maxChunk);
77
+
78
+ for (const chunkItems of chunkItemsList) {
79
+ const results = await batchReadAllChunk({
80
+ table: params.table,
81
+ items: chunkItems
82
+ });
83
+ records.push(...results);
84
+ }
85
+
86
+ return records;
87
+ };
88
+
89
+ exports.batchReadAll = batchReadAll;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["MAX_BATCH_ITEMS","flatten","responses","entries","values","Object","items","push","batchReadAllChunk","params","table","records","result","batchGet","Responses","next","previous","nextResult","batchReadAll","maxChunk","length","WebinyError","chunkItemsList","lodashChunk","chunkItems","results"],"sources":["batchRead.ts"],"sourcesContent":["import { Table } from \"dynamodb-toolbox\";\nimport lodashChunk from \"lodash/chunk\";\nimport WebinyError from \"@webiny/error\";\n\ninterface Item {\n Table: Table;\n Key: any;\n}\ninterface Params {\n table: Table;\n items: Item[];\n}\n\nconst MAX_BATCH_ITEMS = 100;\n\nconst flatten = (responses: Record<string, any[]>): any[] => {\n const entries = [];\n const values = Object.values(responses);\n for (const items of values) {\n entries.push(...items);\n }\n return entries;\n};\n\ninterface BatchReadAllChunkParams {\n table: Table;\n items: Item[];\n}\nconst batchReadAllChunk = async <T = any>(params: BatchReadAllChunkParams): Promise<T[]> => {\n const { table, items } = params;\n const records: T[] = [];\n\n const result = await table.batchGet(items);\n if (!result || !result.Responses) {\n return records;\n }\n records.push(...flatten(result.Responses));\n if (!result.next || typeof result.next !== \"function\") {\n return records;\n }\n let previous = result;\n while (typeof previous.next === \"function\") {\n const nextResult = await previous.next();\n if (!nextResult) {\n return records;\n }\n records.push(...flatten(nextResult.Responses));\n previous = nextResult;\n }\n return records;\n};\n/**\n * This helper function is meant to be used to batch read from one table.\n * It will fetch all results, as there is a next() method call built in.\n */\nexport const batchReadAll = async <T = any>(\n params: Params,\n maxChunk = MAX_BATCH_ITEMS\n): Promise<T[]> => {\n if (params.items.length === 0) {\n return [];\n } else if (maxChunk > MAX_BATCH_ITEMS) {\n throw new WebinyError(\n `Cannot set to load more than ${MAX_BATCH_ITEMS} items from the DynamoDB at once.`,\n \"DYNAMODB_MAX_BATCH_GET_LIMIT_ERROR\",\n {\n maxChunk\n }\n );\n }\n\n const records: T[] = [];\n\n const chunkItemsList: Item[][] = lodashChunk(params.items, maxChunk);\n\n for (const chunkItems of chunkItemsList) {\n const results = await batchReadAllChunk<T>({\n table: params.table,\n items: chunkItems\n });\n\n records.push(...results);\n }\n\n return records;\n};\n"],"mappings":";;;;;;;;;AACA;;AACA;;AAWA,MAAMA,eAAe,GAAG,GAAxB;;AAEA,MAAMC,OAAO,GAAIC,SAAD,IAA6C;EACzD,MAAMC,OAAO,GAAG,EAAhB;EACA,MAAMC,MAAM,GAAGC,MAAM,CAACD,MAAP,CAAcF,SAAd,CAAf;;EACA,KAAK,MAAMI,KAAX,IAAoBF,MAApB,EAA4B;IACxBD,OAAO,CAACI,IAAR,CAAa,GAAGD,KAAhB;EACH;;EACD,OAAOH,OAAP;AACH,CAPD;;AAaA,MAAMK,iBAAiB,GAAG,MAAgBC,MAAhB,IAAkE;EACxF,MAAM;IAAEC,KAAF;IAASJ;EAAT,IAAmBG,MAAzB;EACA,MAAME,OAAY,GAAG,EAArB;EAEA,MAAMC,MAAM,GAAG,MAAMF,KAAK,CAACG,QAAN,CAAeP,KAAf,CAArB;;EACA,IAAI,CAACM,MAAD,IAAW,CAACA,MAAM,CAACE,SAAvB,EAAkC;IAC9B,OAAOH,OAAP;EACH;;EACDA,OAAO,CAACJ,IAAR,CAAa,GAAGN,OAAO,CAACW,MAAM,CAACE,SAAR,CAAvB;;EACA,IAAI,CAACF,MAAM,CAACG,IAAR,IAAgB,OAAOH,MAAM,CAACG,IAAd,KAAuB,UAA3C,EAAuD;IACnD,OAAOJ,OAAP;EACH;;EACD,IAAIK,QAAQ,GAAGJ,MAAf;;EACA,OAAO,OAAOI,QAAQ,CAACD,IAAhB,KAAyB,UAAhC,EAA4C;IACxC,MAAME,UAAU,GAAG,MAAMD,QAAQ,CAACD,IAAT,EAAzB;;IACA,IAAI,CAACE,UAAL,EAAiB;MACb,OAAON,OAAP;IACH;;IACDA,OAAO,CAACJ,IAAR,CAAa,GAAGN,OAAO,CAACgB,UAAU,CAACH,SAAZ,CAAvB;IACAE,QAAQ,GAAGC,UAAX;EACH;;EACD,OAAON,OAAP;AACH,CAtBD;AAuBA;AACA;AACA;AACA;;;AACO,MAAMO,YAAY,GAAG,OACxBT,MADwB,EAExBU,QAAQ,GAAGnB,eAFa,KAGT;EACf,IAAIS,MAAM,CAACH,KAAP,CAAac,MAAb,KAAwB,CAA5B,EAA+B;IAC3B,OAAO,EAAP;EACH,CAFD,MAEO,IAAID,QAAQ,GAAGnB,eAAf,EAAgC;IACnC,MAAM,IAAIqB,cAAJ,CACD,gCAA+BrB,eAAgB,mCAD9C,EAEF,oCAFE,EAGF;MACImB;IADJ,CAHE,CAAN;EAOH;;EAED,MAAMR,OAAY,GAAG,EAArB;EAEA,MAAMW,cAAwB,GAAG,IAAAC,cAAA,EAAYd,MAAM,CAACH,KAAnB,EAA0Ba,QAA1B,CAAjC;;EAEA,KAAK,MAAMK,UAAX,IAAyBF,cAAzB,EAAyC;IACrC,MAAMG,OAAO,GAAG,MAAMjB,iBAAiB,CAAI;MACvCE,KAAK,EAAED,MAAM,CAACC,KADyB;MAEvCJ,KAAK,EAAEkB;IAFgC,CAAJ,CAAvC;IAKAb,OAAO,CAACJ,IAAR,CAAa,GAAGkB,OAAhB;EACH;;EAED,OAAOd,OAAP;AACH,CA9BM"}
@@ -0,0 +1,17 @@
1
+ import { Table } from "dynamodb-toolbox";
2
+ import { DocumentClient } from "aws-sdk/clients/dynamodb";
3
+ interface Item {
4
+ [key: string]: DocumentClient.WriteRequest;
5
+ }
6
+ interface Params {
7
+ table: Table;
8
+ items: Item[];
9
+ }
10
+ /**
11
+ * Method is meant for batch writing to a single table.
12
+ * It expects already prepared items for the write.
13
+ * It can either delete or put items
14
+ * The method does not check items before actually sending them into the underlying library.
15
+ */
16
+ export declare const batchWriteAll: (params: Params, maxChunk?: number) => Promise<void>;
17
+ export {};
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.batchWriteAll = void 0;
9
+
10
+ var _chunk = _interopRequireDefault(require("lodash/chunk"));
11
+
12
+ /**
13
+ * Method is meant for batch writing to a single table.
14
+ * It expects already prepared items for the write.
15
+ * It can either delete or put items
16
+ * The method does not check items before actually sending them into the underlying library.
17
+ */
18
+ const batchWriteAll = async (params, maxChunk = 25) => {
19
+ if (params.items.length === 0) {
20
+ return;
21
+ }
22
+
23
+ const chunkedItems = (0, _chunk.default)(params.items, maxChunk);
24
+
25
+ for (const items of chunkedItems) {
26
+ await params.table.batchWrite(items);
27
+ }
28
+ };
29
+
30
+ exports.batchWriteAll = batchWriteAll;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["batchWriteAll","params","maxChunk","items","length","chunkedItems","lodashChunk","table","batchWrite"],"sources":["batchWrite.ts"],"sourcesContent":["import { Table } from \"dynamodb-toolbox\";\nimport lodashChunk from \"lodash/chunk\";\nimport { DocumentClient } from \"aws-sdk/clients/dynamodb\";\n\ninterface Item {\n [key: string]: DocumentClient.WriteRequest;\n}\ninterface Params {\n table: Table;\n items: Item[];\n}\n\n/**\n * Method is meant for batch writing to a single table.\n * It expects already prepared items for the write.\n * It can either delete or put items\n * The method does not check items before actually sending them into the underlying library.\n */\nexport const batchWriteAll = async (params: Params, maxChunk = 25): Promise<void> => {\n if (params.items.length === 0) {\n return;\n }\n const chunkedItems: Item[][] = lodashChunk(params.items, maxChunk);\n for (const items of chunkedItems) {\n await params.table.batchWrite(items);\n }\n};\n"],"mappings":";;;;;;;;;AACA;;AAWA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,aAAa,GAAG,OAAOC,MAAP,EAAuBC,QAAQ,GAAG,EAAlC,KAAwD;EACjF,IAAID,MAAM,CAACE,KAAP,CAAaC,MAAb,KAAwB,CAA5B,EAA+B;IAC3B;EACH;;EACD,MAAMC,YAAsB,GAAG,IAAAC,cAAA,EAAYL,MAAM,CAACE,KAAnB,EAA0BD,QAA1B,CAA/B;;EACA,KAAK,MAAMC,KAAX,IAAoBE,YAApB,EAAkC;IAC9B,MAAMJ,MAAM,CAACM,KAAP,CAAaC,UAAb,CAAwBL,KAAxB,CAAN;EACH;AACJ,CARM"}
@@ -0,0 +1,3 @@
1
+ import { Entity } from "dynamodb-toolbox";
2
+ export declare function cleanupItem<T>(entity: Entity<any>, item?: (T & Record<string, any>) | null, removeAttributes?: string[]): T | null;
3
+ export declare function cleanupItems<T>(entity: Entity<any>, items: (T & Record<string, any>)[], removeAttributes?: string[]): T[];
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.cleanupItem = cleanupItem;
9
+ exports.cleanupItems = cleanupItems;
10
+
11
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
12
+
13
+ /**
14
+ * The attributes defined by us or the dynamodb-toolbox library.
15
+ * Add more attributes if necessary.
16
+ */
17
+ const attributesToRemove = ["PK", "SK", "created", "_ct", "modified", "_mt", "entity", "_et", "GSI1_PK", "GSI1_SK", "TYPE"];
18
+
19
+ function cleanupItem(entity, item, removeAttributes = []) {
20
+ if (!item) {
21
+ return null;
22
+ }
23
+
24
+ const newItem = (0, _objectSpread2.default)({}, item);
25
+ const targets = attributesToRemove.concat(removeAttributes);
26
+ const attributes = entity.schema.attributes;
27
+
28
+ for (const key in item) {
29
+ if (item.hasOwnProperty(key) === false) {
30
+ continue;
31
+ }
32
+
33
+ if (attributes[key] && targets.includes(key) === false) {
34
+ continue;
35
+ }
36
+
37
+ delete newItem[key];
38
+ }
39
+
40
+ return newItem;
41
+ }
42
+
43
+ function cleanupItems(entity, items, removeAttributes = []) {
44
+ return items.map(item => cleanupItem(entity, item, removeAttributes));
45
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"names":["attributesToRemove","cleanupItem","entity","item","removeAttributes","newItem","targets","concat","attributes","schema","key","hasOwnProperty","includes","cleanupItems","items","map"],"sources":["cleanup.ts"],"sourcesContent":["import { Entity } from \"dynamodb-toolbox\";\n\n/**\n * The attributes defined by us or the dynamodb-toolbox library.\n * Add more attributes if necessary.\n */\nconst attributesToRemove = [\n \"PK\",\n \"SK\",\n \"created\",\n \"_ct\",\n \"modified\",\n \"_mt\",\n \"entity\",\n \"_et\",\n \"GSI1_PK\",\n \"GSI1_SK\",\n \"TYPE\"\n];\n\nexport function cleanupItem<T>(\n entity: Entity<any>,\n item?: (T & Record<string, any>) | null,\n removeAttributes: string[] = []\n): T | null {\n if (!item) {\n return null;\n }\n const newItem = {\n ...item\n };\n const targets = attributesToRemove.concat(removeAttributes);\n const attributes = entity.schema.attributes;\n for (const key in item) {\n if (item.hasOwnProperty(key) === false) {\n continue;\n }\n if (attributes[key] && targets.includes(key) === false) {\n continue;\n }\n delete newItem[key];\n }\n return newItem;\n}\n\nexport function cleanupItems<T>(\n entity: Entity<any>,\n items: (T & Record<string, any>)[],\n removeAttributes: string[] = []\n): T[] {\n return items.map(item => cleanupItem<T>(entity, item, removeAttributes) as T);\n}\n"],"mappings":";;;;;;;;;;;;AAEA;AACA;AACA;AACA;AACA,MAAMA,kBAAkB,GAAG,CACvB,IADuB,EAEvB,IAFuB,EAGvB,SAHuB,EAIvB,KAJuB,EAKvB,UALuB,EAMvB,KANuB,EAOvB,QAPuB,EAQvB,KARuB,EASvB,SATuB,EAUvB,SAVuB,EAWvB,MAXuB,CAA3B;;AAcO,SAASC,WAAT,CACHC,MADG,EAEHC,IAFG,EAGHC,gBAA0B,GAAG,EAH1B,EAIK;EACR,IAAI,CAACD,IAAL,EAAW;IACP,OAAO,IAAP;EACH;;EACD,MAAME,OAAO,mCACNF,IADM,CAAb;EAGA,MAAMG,OAAO,GAAGN,kBAAkB,CAACO,MAAnB,CAA0BH,gBAA1B,CAAhB;EACA,MAAMI,UAAU,GAAGN,MAAM,CAACO,MAAP,CAAcD,UAAjC;;EACA,KAAK,MAAME,GAAX,IAAkBP,IAAlB,EAAwB;IACpB,IAAIA,IAAI,CAACQ,cAAL,CAAoBD,GAApB,MAA6B,KAAjC,EAAwC;MACpC;IACH;;IACD,IAAIF,UAAU,CAACE,GAAD,CAAV,IAAmBJ,OAAO,CAACM,QAAR,CAAiBF,GAAjB,MAA0B,KAAjD,EAAwD;MACpD;IACH;;IACD,OAAOL,OAAO,CAACK,GAAD,CAAd;EACH;;EACD,OAAOL,OAAP;AACH;;AAEM,SAASQ,YAAT,CACHX,MADG,EAEHY,KAFG,EAGHV,gBAA0B,GAAG,EAH1B,EAIA;EACH,OAAOU,KAAK,CAACC,GAAN,CAAUZ,IAAI,IAAIF,WAAW,CAAIC,MAAJ,EAAYC,IAAZ,EAAkBC,gBAAlB,CAA7B,CAAP;AACH"}
@@ -0,0 +1,2 @@
1
+ export declare const encodeCursor: (cursor?: any) => string | null;
2
+ export declare const decodeCursor: (cursor?: string | null) => string | null;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.encodeCursor = exports.decodeCursor = void 0;
7
+
8
+ const encodeCursor = cursor => {
9
+ if (!cursor) {
10
+ return null;
11
+ }
12
+
13
+ return Buffer.from(JSON.stringify(cursor)).toString("base64");
14
+ };
15
+
16
+ exports.encodeCursor = encodeCursor;
17
+
18
+ const decodeCursor = cursor => {
19
+ if (!cursor) {
20
+ return null;
21
+ }
22
+
23
+ return JSON.parse(Buffer.from(cursor, "base64").toString("ascii"));
24
+ };
25
+
26
+ exports.decodeCursor = decodeCursor;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["encodeCursor","cursor","Buffer","from","JSON","stringify","toString","decodeCursor","parse"],"sources":["cursor.ts"],"sourcesContent":["export const encodeCursor = (cursor?: any): string | null => {\n if (!cursor) {\n return null;\n }\n\n return Buffer.from(JSON.stringify(cursor)).toString(\"base64\");\n};\n\nexport const decodeCursor = (cursor?: string | null): string | null => {\n if (!cursor) {\n return null;\n }\n\n return JSON.parse(Buffer.from(cursor, \"base64\").toString(\"ascii\"));\n};\n"],"mappings":";;;;;;;AAAO,MAAMA,YAAY,GAAIC,MAAD,IAAiC;EACzD,IAAI,CAACA,MAAL,EAAa;IACT,OAAO,IAAP;EACH;;EAED,OAAOC,MAAM,CAACC,IAAP,CAAYC,IAAI,CAACC,SAAL,CAAeJ,MAAf,CAAZ,EAAoCK,QAApC,CAA6C,QAA7C,CAAP;AACH,CANM;;;;AAQA,MAAMC,YAAY,GAAIN,MAAD,IAA2C;EACnE,IAAI,CAACA,MAAL,EAAa;IACT,OAAO,IAAP;EACH;;EAED,OAAOG,IAAI,CAACI,KAAL,CAAWN,MAAM,CAACC,IAAP,CAAYF,MAAZ,EAAoB,QAApB,EAA8BK,QAA9B,CAAuC,OAAvC,CAAX,CAAP;AACH,CANM"}
@@ -0,0 +1,12 @@
1
+ import { PluginsContainer } from "@webiny/plugins";
2
+ import { FieldPlugin } from "../plugins/definitions/FieldPlugin";
3
+ export interface Params<T = any> {
4
+ plugins: PluginsContainer;
5
+ items: T[];
6
+ where: Record<string, any>;
7
+ /**
8
+ * An array of fields that require some special operation.
9
+ */
10
+ fields: FieldPlugin[];
11
+ }
12
+ export declare function filterItems<T = any>(params: Params<T>): T[];