@webiny/db-dynamodb 0.0.0-unstable.6f45466a1d → 0.0.0-unstable.7be00a75a9

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 (215) hide show
  1. package/DynamoDbDriver.js +204 -209
  2. package/DynamoDbDriver.js.map +1 -1
  3. package/exports/api/db.d.ts +2 -0
  4. package/exports/api/db.js +2 -0
  5. package/feature/FilterUtil/FilterUtil.d.ts +11 -0
  6. package/feature/FilterUtil/FilterUtil.js +26 -0
  7. package/feature/FilterUtil/FilterUtil.js.map +1 -0
  8. package/feature/FilterUtil/abstractions/FilterUtil.d.ts +17 -0
  9. package/feature/FilterUtil/abstractions/FilterUtil.js +5 -0
  10. package/feature/FilterUtil/abstractions/FilterUtil.js.map +1 -0
  11. package/feature/FilterUtil/createFilters.d.ts +22 -0
  12. package/feature/FilterUtil/createFilters.js +92 -0
  13. package/feature/FilterUtil/createFilters.js.map +1 -0
  14. package/feature/FilterUtil/extractWhereArgs.d.ts +7 -0
  15. package/feature/FilterUtil/extractWhereArgs.js +20 -0
  16. package/feature/FilterUtil/extractWhereArgs.js.map +1 -0
  17. package/feature/FilterUtil/feature.d.ts +4 -0
  18. package/feature/FilterUtil/feature.js +11 -0
  19. package/feature/FilterUtil/feature.js.map +1 -0
  20. package/feature/FilterUtil/index.d.ts +2 -0
  21. package/feature/FilterUtil/index.js +2 -0
  22. package/feature/ValueFilter/ValueFilterRegistry.d.ts +12 -0
  23. package/feature/ValueFilter/ValueFilterRegistry.js +27 -0
  24. package/feature/ValueFilter/ValueFilterRegistry.js.map +1 -0
  25. package/feature/ValueFilter/abstractions/ValueFilter.d.ts +22 -0
  26. package/feature/ValueFilter/abstractions/ValueFilter.js +5 -0
  27. package/feature/ValueFilter/abstractions/ValueFilter.js.map +1 -0
  28. package/feature/ValueFilter/abstractions/ValueFilterRegistry.d.ts +10 -0
  29. package/feature/ValueFilter/abstractions/ValueFilterRegistry.js +5 -0
  30. package/feature/ValueFilter/abstractions/ValueFilterRegistry.js.map +1 -0
  31. package/feature/ValueFilter/feature.d.ts +4 -0
  32. package/feature/ValueFilter/feature.js +33 -0
  33. package/feature/ValueFilter/feature.js.map +1 -0
  34. package/feature/ValueFilter/filters/AndInFilter.d.ts +11 -0
  35. package/feature/ValueFilter/filters/AndInFilter.js +28 -0
  36. package/feature/ValueFilter/filters/AndInFilter.js.map +1 -0
  37. package/feature/ValueFilter/filters/BetweenFilter.d.ts +11 -0
  38. package/feature/ValueFilter/filters/BetweenFilter.js +31 -0
  39. package/feature/ValueFilter/filters/BetweenFilter.js.map +1 -0
  40. package/feature/ValueFilter/filters/ContainsFilter.d.ts +11 -0
  41. package/feature/ValueFilter/filters/ContainsFilter.js +42 -0
  42. package/feature/ValueFilter/filters/ContainsFilter.js.map +1 -0
  43. package/feature/ValueFilter/filters/EqFilter.d.ts +11 -0
  44. package/feature/ValueFilter/filters/EqFilter.js +24 -0
  45. package/feature/ValueFilter/filters/EqFilter.js.map +1 -0
  46. package/feature/ValueFilter/filters/FuzzyFilter.d.ts +11 -0
  47. package/feature/ValueFilter/filters/FuzzyFilter.js +37 -0
  48. package/feature/ValueFilter/filters/FuzzyFilter.js.map +1 -0
  49. package/feature/ValueFilter/filters/GtFilter.d.ts +11 -0
  50. package/feature/ValueFilter/filters/GtFilter.js +22 -0
  51. package/feature/ValueFilter/filters/GtFilter.js.map +1 -0
  52. package/feature/ValueFilter/filters/GteFilter.d.ts +11 -0
  53. package/feature/ValueFilter/filters/GteFilter.js +22 -0
  54. package/feature/ValueFilter/filters/GteFilter.js.map +1 -0
  55. package/feature/ValueFilter/filters/InFilter.d.ts +11 -0
  56. package/feature/ValueFilter/filters/InFilter.js +28 -0
  57. package/feature/ValueFilter/filters/InFilter.js.map +1 -0
  58. package/feature/ValueFilter/filters/LtFilter.d.ts +11 -0
  59. package/feature/ValueFilter/filters/LtFilter.js +22 -0
  60. package/feature/ValueFilter/filters/LtFilter.js.map +1 -0
  61. package/feature/ValueFilter/filters/LteFilter.d.ts +11 -0
  62. package/feature/ValueFilter/filters/LteFilter.js +22 -0
  63. package/feature/ValueFilter/filters/LteFilter.js.map +1 -0
  64. package/feature/ValueFilter/filters/StartsWithFilter.d.ts +11 -0
  65. package/feature/ValueFilter/filters/StartsWithFilter.js +29 -0
  66. package/feature/ValueFilter/filters/StartsWithFilter.js.map +1 -0
  67. package/feature/ValueFilter/index.d.ts +3 -0
  68. package/feature/ValueFilter/index.js +3 -0
  69. package/index.d.ts +1 -0
  70. package/index.js +9 -2
  71. package/index.js.map +1 -1
  72. package/package.json +28 -20
  73. package/plugins/definitions/DateTimeTransformPlugin.js +18 -27
  74. package/plugins/definitions/DateTimeTransformPlugin.js.map +1 -1
  75. package/plugins/definitions/FieldPlugin.js +34 -37
  76. package/plugins/definitions/FieldPlugin.js.map +1 -1
  77. package/plugins/definitions/TimeTransformPlugin.js +25 -37
  78. package/plugins/definitions/TimeTransformPlugin.js.map +1 -1
  79. package/plugins/definitions/ValueTransformPlugin.d.ts +1 -6
  80. package/plugins/definitions/ValueTransformPlugin.js +17 -22
  81. package/plugins/definitions/ValueTransformPlugin.js.map +1 -1
  82. package/plugins/definitions/assignFields.js +14 -18
  83. package/plugins/definitions/assignFields.js.map +1 -1
  84. package/plugins/index.d.ts +0 -5
  85. package/plugins/index.js +0 -12
  86. package/store/entity.js +6 -9
  87. package/store/entity.js.map +1 -1
  88. package/store/keys.js +6 -13
  89. package/store/keys.js.map +1 -1
  90. package/store/types.js +0 -3
  91. package/toolbox.d.ts +53 -1
  92. package/toolbox.js +0 -4
  93. package/types.js +0 -3
  94. package/utils/batch/batchRead.js +37 -56
  95. package/utils/batch/batchRead.js.map +1 -1
  96. package/utils/batch/batchWrite.js +33 -51
  97. package/utils/batch/batchWrite.js.map +1 -1
  98. package/utils/batch/index.js +0 -2
  99. package/utils/batch/types.js +0 -3
  100. package/utils/cleanup.js +35 -25
  101. package/utils/cleanup.js.map +1 -1
  102. package/utils/count.js +8 -13
  103. package/utils/count.js.map +1 -1
  104. package/utils/createEntity.d.ts +1 -1
  105. package/utils/createEntity.js +75 -78
  106. package/utils/createEntity.js.map +1 -1
  107. package/utils/createTable.js +25 -35
  108. package/utils/createTable.js.map +1 -1
  109. package/utils/cursor.js +7 -10
  110. package/utils/cursor.js.map +1 -1
  111. package/utils/delete.js +6 -8
  112. package/utils/delete.js.map +1 -1
  113. package/utils/entity/Entity.d.ts +1 -1
  114. package/utils/entity/Entity.js +85 -89
  115. package/utils/entity/Entity.js.map +1 -1
  116. package/utils/entity/EntityReadBatch.js +23 -31
  117. package/utils/entity/EntityReadBatch.js.map +1 -1
  118. package/utils/entity/EntityReadBatchBuilder.js +12 -15
  119. package/utils/entity/EntityReadBatchBuilder.js.map +1 -1
  120. package/utils/entity/EntityWriteBatch.js +34 -41
  121. package/utils/entity/EntityWriteBatch.js.map +1 -1
  122. package/utils/entity/EntityWriteBatchBuilder.js +15 -16
  123. package/utils/entity/EntityWriteBatchBuilder.js.map +1 -1
  124. package/utils/entity/getEntity.js +8 -9
  125. package/utils/entity/getEntity.js.map +1 -1
  126. package/utils/entity/index.js +0 -2
  127. package/utils/entity/types.js +0 -4
  128. package/utils/get.js +12 -26
  129. package/utils/get.js.map +1 -1
  130. package/utils/index.d.ts +1 -5
  131. package/utils/index.js +1 -7
  132. package/utils/put.js +7 -9
  133. package/utils/put.js.map +1 -1
  134. package/utils/query.js +77 -128
  135. package/utils/query.js.map +1 -1
  136. package/utils/scan.js +47 -73
  137. package/utils/scan.js.map +1 -1
  138. package/utils/sort.js +37 -61
  139. package/utils/sort.js.map +1 -1
  140. package/utils/table/Table.js +22 -21
  141. package/utils/table/Table.js.map +1 -1
  142. package/utils/table/TableReadBatch.js +37 -45
  143. package/utils/table/TableReadBatch.js.map +1 -1
  144. package/utils/table/TableWriteBatch.js +47 -56
  145. package/utils/table/TableWriteBatch.js.map +1 -1
  146. package/utils/table/index.js +0 -2
  147. package/utils/table/types.js +0 -3
  148. package/plugins/definitions/AttributePlugin.d.ts +0 -18
  149. package/plugins/definitions/AttributePlugin.js +0 -38
  150. package/plugins/definitions/AttributePlugin.js.map +0 -1
  151. package/plugins/definitions/FieldPathPlugin.d.ts +0 -22
  152. package/plugins/definitions/FieldPathPlugin.js +0 -26
  153. package/plugins/definitions/FieldPathPlugin.js.map +0 -1
  154. package/plugins/definitions/ValueFilterPlugin.d.ts +0 -22
  155. package/plugins/definitions/ValueFilterPlugin.js +0 -35
  156. package/plugins/definitions/ValueFilterPlugin.js.map +0 -1
  157. package/plugins/filters/andIn.d.ts +0 -3
  158. package/plugins/filters/andIn.js +0 -24
  159. package/plugins/filters/andIn.js.map +0 -1
  160. package/plugins/filters/between.d.ts +0 -3
  161. package/plugins/filters/between.js +0 -25
  162. package/plugins/filters/between.js.map +0 -1
  163. package/plugins/filters/contains.d.ts +0 -3
  164. package/plugins/filters/contains.js +0 -53
  165. package/plugins/filters/contains.js.map +0 -1
  166. package/plugins/filters/eq.d.ts +0 -3
  167. package/plugins/filters/eq.js +0 -26
  168. package/plugins/filters/eq.js.map +0 -1
  169. package/plugins/filters/fuzzy.d.ts +0 -3
  170. package/plugins/filters/fuzzy.js +0 -29
  171. package/plugins/filters/fuzzy.js.map +0 -1
  172. package/plugins/filters/gt.d.ts +0 -3
  173. package/plugins/filters/gt.js +0 -14
  174. package/plugins/filters/gt.js.map +0 -1
  175. package/plugins/filters/gte.d.ts +0 -3
  176. package/plugins/filters/gte.js +0 -14
  177. package/plugins/filters/gte.js.map +0 -1
  178. package/plugins/filters/in.d.ts +0 -3
  179. package/plugins/filters/in.js +0 -24
  180. package/plugins/filters/in.js.map +0 -1
  181. package/plugins/filters/index.d.ts +0 -2
  182. package/plugins/filters/index.js +0 -14
  183. package/plugins/filters/index.js.map +0 -1
  184. package/plugins/filters/lt.d.ts +0 -3
  185. package/plugins/filters/lt.js +0 -14
  186. package/plugins/filters/lt.js.map +0 -1
  187. package/plugins/filters/lte.d.ts +0 -3
  188. package/plugins/filters/lte.js +0 -14
  189. package/plugins/filters/lte.js.map +0 -1
  190. package/plugins/filters/startsWith.d.ts +0 -3
  191. package/plugins/filters/startsWith.js +0 -34
  192. package/plugins/filters/startsWith.js.map +0 -1
  193. package/plugins/index.js.map +0 -1
  194. package/store/types.js.map +0 -1
  195. package/toolbox.js.map +0 -1
  196. package/types.js.map +0 -1
  197. package/utils/attributes.d.ts +0 -10
  198. package/utils/attributes.js +0 -19
  199. package/utils/attributes.js.map +0 -1
  200. package/utils/batch/index.js.map +0 -1
  201. package/utils/batch/types.js.map +0 -1
  202. package/utils/entity/index.js.map +0 -1
  203. package/utils/entity/types.js.map +0 -1
  204. package/utils/filter.d.ts +0 -12
  205. package/utils/filter.js +0 -174
  206. package/utils/filter.js.map +0 -1
  207. package/utils/index.js.map +0 -1
  208. package/utils/listResponse.d.ts +0 -13
  209. package/utils/listResponse.js +0 -25
  210. package/utils/listResponse.js.map +0 -1
  211. package/utils/table/index.js.map +0 -1
  212. package/utils/table/types.js.map +0 -1
  213. package/utils/update.d.ts +0 -12
  214. package/utils/update.js +0 -12
  215. package/utils/update.js.map +0 -1
package/utils/sort.js CHANGED
@@ -1,69 +1,45 @@
1
- import lodashOrderBy from "lodash/orderBy.js";
2
- import WebinyError from "@webiny/error";
3
- const extractSort = (sortBy, fields) => {
4
- const result = sortBy.split("_");
5
- if (result.length !== 2) {
6
- throw new WebinyError("Problem in determining the sorting for the entry items.", "SORT_ERROR", {
7
- sortBy
1
+ import orderBy from "lodash/orderBy.js";
2
+ import error from "@webiny/error";
3
+ const extractSort = (sortBy, fields)=>{
4
+ const result = sortBy.split("_");
5
+ if (2 !== result.length) throw new error("Problem in determining the sorting for the entry items.", "SORT_ERROR", {
6
+ sortBy
8
7
  });
9
- }
10
- const [field, order] = result;
11
- if (!field) {
12
- throw new WebinyError("Sorting field does not exist.", "SORTING_FIELD_ERROR", {
13
- field,
14
- order,
15
- fields
8
+ const [field, order] = result;
9
+ if (!field) throw new error("Sorting field does not exist.", "SORTING_FIELD_ERROR", {
10
+ field,
11
+ order,
12
+ fields
16
13
  });
17
- }
18
- const fieldPlugin = fields.find(f => f.getField() === field);
19
- const isSortable = fieldPlugin ? fieldPlugin.isSortable() : true;
20
- if (isSortable === false) {
21
- throw new WebinyError(`Cannot sort by given field: "${field}".`, "UNSUPPORTED_SORT_ERROR", {
22
- fields,
23
- field
14
+ const fieldPlugin = fields.find((f)=>f.getField() === field);
15
+ const isSortable = fieldPlugin ? fieldPlugin.isSortable() : true;
16
+ if (false === isSortable) throw new error(`Cannot sort by given field: "${field}".`, "UNSUPPORTED_SORT_ERROR", {
17
+ fields,
18
+ field
24
19
  });
25
- }
26
- return {
27
- field,
28
- reverse: order.toUpperCase() === "DESC"
29
- };
20
+ return {
21
+ field,
22
+ reverse: "DESC" === order.toUpperCase()
23
+ };
30
24
  };
31
- export function sortItems(params) {
32
- const {
33
- items,
34
- sort: initialSort = [],
35
- fields = []
36
- } = params;
37
- /**
38
- * Skip sorting if nothing was passed to sort by or nothing to sort.
39
- */
40
- if (items.length <= 1 || Array.isArray(initialSort) === false || initialSort.length === 0) {
41
- return items;
42
- }
43
- const info = {
44
- sorters: [],
45
- orders: []
46
- };
47
- for (const sort of initialSort) {
48
- /**
49
- * Possibly empty array item was passed.
50
- */
51
- if (!sort) {
52
- continue;
25
+ function sortItems(params) {
26
+ const { items, sort: initialSort = [], fields = [] } = params;
27
+ if (items.length <= 1 || false === Array.isArray(initialSort) || 0 === initialSort.length) return items;
28
+ const info = {
29
+ sorters: [],
30
+ orders: []
31
+ };
32
+ for (const sort of initialSort){
33
+ if (!sort) continue;
34
+ const { field, reverse } = extractSort(sort, fields);
35
+ const fieldPlugin = fields.find((f)=>f.getField() === field);
36
+ const path = fieldPlugin ? fieldPlugin.getPath() : field;
37
+ info.sorters.push(path);
38
+ info.orders.push(true === reverse ? "desc" : "asc");
53
39
  }
54
- const {
55
- field,
56
- reverse
57
- } = extractSort(sort, fields);
58
- const fieldPlugin = fields.find(f => f.getField() === field);
59
- const path = fieldPlugin ? fieldPlugin.getPath() : field;
60
- info.sorters.push(path);
61
- info.orders.push(reverse === true ? "desc" : "asc");
62
- }
63
- if (info.sorters.length === 0) {
64
- return items;
65
- }
66
- return lodashOrderBy(items, info.sorters, info.orders);
40
+ if (0 === info.sorters.length) return items;
41
+ return orderBy(items, info.sorters, info.orders);
67
42
  }
43
+ export { sortItems };
68
44
 
69
45
  //# sourceMappingURL=sort.js.map
package/utils/sort.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["lodashOrderBy","WebinyError","extractSort","sortBy","fields","result","split","length","field","order","fieldPlugin","find","f","getField","isSortable","reverse","toUpperCase","sortItems","params","items","sort","initialSort","Array","isArray","info","sorters","orders","path","getPath","push"],"sources":["sort.ts"],"sourcesContent":["import lodashOrderBy from \"lodash/orderBy.js\";\nimport WebinyError from \"@webiny/error\";\nimport type { FieldPlugin } from \"~/plugins/definitions/FieldPlugin.js\";\n\ninterface Info {\n sorters: string[];\n orders: (boolean | \"asc\" | \"desc\")[];\n}\n\ninterface Response {\n reverse: boolean;\n field: string;\n}\n\nconst extractSort = (sortBy: string, fields: FieldPlugin[]): Response => {\n const result = sortBy.split(\"_\");\n if (result.length !== 2) {\n throw new WebinyError(\n \"Problem in determining the sorting for the entry items.\",\n \"SORT_ERROR\",\n {\n sortBy\n }\n );\n }\n const [field, order] = result;\n\n if (!field) {\n throw new WebinyError(\"Sorting field does not exist.\", \"SORTING_FIELD_ERROR\", {\n field,\n order,\n fields\n });\n }\n const fieldPlugin = fields.find(f => f.getField() === field);\n const isSortable = fieldPlugin ? fieldPlugin.isSortable() : true;\n if (isSortable === false) {\n throw new WebinyError(`Cannot sort by given field: \"${field}\".`, \"UNSUPPORTED_SORT_ERROR\", {\n fields,\n field\n });\n }\n\n return {\n field,\n reverse: order.toUpperCase() === \"DESC\"\n };\n};\n\ninterface Params<T> {\n /**\n * The items we are sorting.\n */\n items: T[];\n /**\n * Sort options. For example: [\"id_ASC\"]\n */\n sort?: string[];\n /**\n * Fields we can sort by.\n */\n fields?: FieldPlugin[];\n}\n\nexport function sortItems<T = any>(params: Params<T>): T[] {\n const { items, sort: initialSort = [], fields = [] } = params;\n /**\n * Skip sorting if nothing was passed to sort by or nothing to sort.\n */\n if (items.length <= 1 || Array.isArray(initialSort) === false || initialSort.length === 0) {\n return items;\n }\n\n const info: Info = {\n sorters: [],\n orders: []\n };\n\n for (const sort of initialSort) {\n /**\n * Possibly empty array item was passed.\n */\n if (!sort) {\n continue;\n }\n const { field, reverse } = extractSort(sort, fields);\n const fieldPlugin = fields.find(f => f.getField() === field);\n const path = fieldPlugin ? fieldPlugin.getPath() : field;\n\n info.sorters.push(path);\n info.orders.push(reverse === true ? \"desc\" : \"asc\");\n }\n\n if (info.sorters.length === 0) {\n return items;\n }\n\n return lodashOrderBy(items, info.sorters, info.orders);\n}\n"],"mappings":"AAAA,OAAOA,aAAa,MAAM,mBAAmB;AAC7C,OAAOC,WAAW,MAAM,eAAe;AAavC,MAAMC,WAAW,GAAGA,CAACC,MAAc,EAAEC,MAAqB,KAAe;EACrE,MAAMC,MAAM,GAAGF,MAAM,CAACG,KAAK,CAAC,GAAG,CAAC;EAChC,IAAID,MAAM,CAACE,MAAM,KAAK,CAAC,EAAE;IACrB,MAAM,IAAIN,WAAW,CACjB,yDAAyD,EACzD,YAAY,EACZ;MACIE;IACJ,CACJ,CAAC;EACL;EACA,MAAM,CAACK,KAAK,EAAEC,KAAK,CAAC,GAAGJ,MAAM;EAE7B,IAAI,CAACG,KAAK,EAAE;IACR,MAAM,IAAIP,WAAW,CAAC,+BAA+B,EAAE,qBAAqB,EAAE;MAC1EO,KAAK;MACLC,KAAK;MACLL;IACJ,CAAC,CAAC;EACN;EACA,MAAMM,WAAW,GAAGN,MAAM,CAACO,IAAI,CAACC,CAAC,IAAIA,CAAC,CAACC,QAAQ,CAAC,CAAC,KAAKL,KAAK,CAAC;EAC5D,MAAMM,UAAU,GAAGJ,WAAW,GAAGA,WAAW,CAACI,UAAU,CAAC,CAAC,GAAG,IAAI;EAChE,IAAIA,UAAU,KAAK,KAAK,EAAE;IACtB,MAAM,IAAIb,WAAW,CAAC,gCAAgCO,KAAK,IAAI,EAAE,wBAAwB,EAAE;MACvFJ,MAAM;MACNI;IACJ,CAAC,CAAC;EACN;EAEA,OAAO;IACHA,KAAK;IACLO,OAAO,EAAEN,KAAK,CAACO,WAAW,CAAC,CAAC,KAAK;EACrC,CAAC;AACL,CAAC;AAiBD,OAAO,SAASC,SAASA,CAAUC,MAAiB,EAAO;EACvD,MAAM;IAAEC,KAAK;IAAEC,IAAI,EAAEC,WAAW,GAAG,EAAE;IAAEjB,MAAM,GAAG;EAAG,CAAC,GAAGc,MAAM;EAC7D;AACJ;AACA;EACI,IAAIC,KAAK,CAACZ,MAAM,IAAI,CAAC,IAAIe,KAAK,CAACC,OAAO,CAACF,WAAW,CAAC,KAAK,KAAK,IAAIA,WAAW,CAACd,MAAM,KAAK,CAAC,EAAE;IACvF,OAAOY,KAAK;EAChB;EAEA,MAAMK,IAAU,GAAG;IACfC,OAAO,EAAE,EAAE;IACXC,MAAM,EAAE;EACZ,CAAC;EAED,KAAK,MAAMN,IAAI,IAAIC,WAAW,EAAE;IAC5B;AACR;AACA;IACQ,IAAI,CAACD,IAAI,EAAE;MACP;IACJ;IACA,MAAM;MAAEZ,KAAK;MAAEO;IAAQ,CAAC,GAAGb,WAAW,CAACkB,IAAI,EAAEhB,MAAM,CAAC;IACpD,MAAMM,WAAW,GAAGN,MAAM,CAACO,IAAI,CAACC,CAAC,IAAIA,CAAC,CAACC,QAAQ,CAAC,CAAC,KAAKL,KAAK,CAAC;IAC5D,MAAMmB,IAAI,GAAGjB,WAAW,GAAGA,WAAW,CAACkB,OAAO,CAAC,CAAC,GAAGpB,KAAK;IAExDgB,IAAI,CAACC,OAAO,CAACI,IAAI,CAACF,IAAI,CAAC;IACvBH,IAAI,CAACE,MAAM,CAACG,IAAI,CAACd,OAAO,KAAK,IAAI,GAAG,MAAM,GAAG,KAAK,CAAC;EACvD;EAEA,IAAIS,IAAI,CAACC,OAAO,CAAClB,MAAM,KAAK,CAAC,EAAE;IAC3B,OAAOY,KAAK;EAChB;EAEA,OAAOnB,aAAa,CAACmB,KAAK,EAAEK,IAAI,CAACC,OAAO,EAAED,IAAI,CAACE,MAAM,CAAC;AAC1D","ignoreList":[]}
1
+ {"version":3,"file":"utils/sort.js","sources":["../../src/utils/sort.ts"],"sourcesContent":["import lodashOrderBy from \"lodash/orderBy.js\";\nimport WebinyError from \"@webiny/error\";\nimport type { FieldPlugin } from \"~/plugins/definitions/FieldPlugin.js\";\n\ninterface Info {\n sorters: string[];\n orders: (boolean | \"asc\" | \"desc\")[];\n}\n\ninterface Response {\n reverse: boolean;\n field: string;\n}\n\nconst extractSort = (sortBy: string, fields: FieldPlugin[]): Response => {\n const result = sortBy.split(\"_\");\n if (result.length !== 2) {\n throw new WebinyError(\n \"Problem in determining the sorting for the entry items.\",\n \"SORT_ERROR\",\n {\n sortBy\n }\n );\n }\n const [field, order] = result;\n\n if (!field) {\n throw new WebinyError(\"Sorting field does not exist.\", \"SORTING_FIELD_ERROR\", {\n field,\n order,\n fields\n });\n }\n const fieldPlugin = fields.find(f => f.getField() === field);\n const isSortable = fieldPlugin ? fieldPlugin.isSortable() : true;\n if (isSortable === false) {\n throw new WebinyError(`Cannot sort by given field: \"${field}\".`, \"UNSUPPORTED_SORT_ERROR\", {\n fields,\n field\n });\n }\n\n return {\n field,\n reverse: order.toUpperCase() === \"DESC\"\n };\n};\n\ninterface Params<T> {\n /**\n * The items we are sorting.\n */\n items: T[];\n /**\n * Sort options. For example: [\"id_ASC\"]\n */\n sort?: string[];\n /**\n * Fields we can sort by.\n */\n fields?: FieldPlugin[];\n}\n\nexport function sortItems<T = any>(params: Params<T>): T[] {\n const { items, sort: initialSort = [], fields = [] } = params;\n /**\n * Skip sorting if nothing was passed to sort by or nothing to sort.\n */\n if (items.length <= 1 || Array.isArray(initialSort) === false || initialSort.length === 0) {\n return items;\n }\n\n const info: Info = {\n sorters: [],\n orders: []\n };\n\n for (const sort of initialSort) {\n /**\n * Possibly empty array item was passed.\n */\n if (!sort) {\n continue;\n }\n const { field, reverse } = extractSort(sort, fields);\n const fieldPlugin = fields.find(f => f.getField() === field);\n const path = fieldPlugin ? fieldPlugin.getPath() : field;\n\n info.sorters.push(path);\n info.orders.push(reverse === true ? \"desc\" : \"asc\");\n }\n\n if (info.sorters.length === 0) {\n return items;\n }\n\n return lodashOrderBy(items, info.sorters, info.orders);\n}\n"],"names":["extractSort","sortBy","fields","result","WebinyError","field","order","fieldPlugin","f","isSortable","sortItems","params","items","initialSort","Array","info","sort","reverse","path","lodashOrderBy"],"mappings":";;AAcA,MAAMA,cAAc,CAACC,QAAgBC;IACjC,MAAMC,SAASF,OAAO,KAAK,CAAC;IAC5B,IAAIE,AAAkB,MAAlBA,OAAO,MAAM,EACb,MAAM,IAAIC,MACN,2DACA,cACA;QACIH;IACJ;IAGR,MAAM,CAACI,OAAOC,MAAM,GAAGH;IAEvB,IAAI,CAACE,OACD,MAAM,IAAID,MAAY,iCAAiC,uBAAuB;QAC1EC;QACAC;QACAJ;IACJ;IAEJ,MAAMK,cAAcL,OAAO,IAAI,CAACM,CAAAA,IAAKA,EAAE,QAAQ,OAAOH;IACtD,MAAMI,aAAaF,cAAcA,YAAY,UAAU,KAAK;IAC5D,IAAIE,AAAe,UAAfA,YACA,MAAM,IAAIL,MAAY,CAAC,6BAA6B,EAAEC,MAAM,EAAE,CAAC,EAAE,0BAA0B;QACvFH;QACAG;IACJ;IAGJ,OAAO;QACHA;QACA,SAASC,AAAwB,WAAxBA,MAAM,WAAW;IAC9B;AACJ;AAiBO,SAASI,UAAmBC,MAAiB;IAChD,MAAM,EAAEC,KAAK,EAAE,MAAMC,cAAc,EAAE,EAAEX,SAAS,EAAE,EAAE,GAAGS;IAIvD,IAAIC,MAAM,MAAM,IAAI,KAAKE,AAA+B,UAA/BA,MAAM,OAAO,CAACD,gBAA0BA,AAAuB,MAAvBA,YAAY,MAAM,EAC/E,OAAOD;IAGX,MAAMG,OAAa;QACf,SAAS,EAAE;QACX,QAAQ,EAAE;IACd;IAEA,KAAK,MAAMC,QAAQH,YAAa;QAI5B,IAAI,CAACG,MACD;QAEJ,MAAM,EAAEX,KAAK,EAAEY,OAAO,EAAE,GAAGjB,YAAYgB,MAAMd;QAC7C,MAAMK,cAAcL,OAAO,IAAI,CAACM,CAAAA,IAAKA,EAAE,QAAQ,OAAOH;QACtD,MAAMa,OAAOX,cAAcA,YAAY,OAAO,KAAKF;QAEnDU,KAAK,OAAO,CAAC,IAAI,CAACG;QAClBH,KAAK,MAAM,CAAC,IAAI,CAACE,AAAY,SAAZA,UAAmB,SAAS;IACjD;IAEA,IAAIF,AAAwB,MAAxBA,KAAK,OAAO,CAAC,MAAM,EACnB,OAAOH;IAGX,OAAOO,QAAcP,OAAOG,KAAK,OAAO,EAAEA,KAAK,MAAM;AACzD"}
@@ -1,27 +1,28 @@
1
- import { Table as BaseTable } from "../../toolbox.js";
1
+ import { Table } from "../../toolbox.js";
2
2
  import { createTableWriteBatch } from "./TableWriteBatch.js";
3
3
  import { createTableReadBatch } from "./TableReadBatch.js";
4
4
  import { scan } from "../scan.js";
5
- export class Table {
6
- constructor(params) {
7
- this.table = new BaseTable(params);
8
- }
9
- createWriter() {
10
- return createTableWriteBatch({
11
- table: this.table
12
- });
13
- }
14
- createReader() {
15
- return createTableReadBatch({
16
- table: this.table
17
- });
18
- }
19
- async scan(params) {
20
- return scan({
21
- ...params,
22
- table: this.table
23
- });
24
- }
5
+ class Table_Table {
6
+ constructor(params){
7
+ this.table = new Table(params);
8
+ }
9
+ createWriter() {
10
+ return createTableWriteBatch({
11
+ table: this.table
12
+ });
13
+ }
14
+ createReader() {
15
+ return createTableReadBatch({
16
+ table: this.table
17
+ });
18
+ }
19
+ async scan(params) {
20
+ return scan({
21
+ ...params,
22
+ table: this.table
23
+ });
24
+ }
25
25
  }
26
+ export { Table_Table as Table };
26
27
 
27
28
  //# sourceMappingURL=Table.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["Table","BaseTable","createTableWriteBatch","createTableReadBatch","scan","constructor","params","table","createWriter","createReader"],"sources":["Table.ts"],"sourcesContent":["import type { TableConstructor } from \"~/toolbox.js\";\nimport { Table as BaseTable } from \"~/toolbox.js\";\nimport type {\n ITable,\n ITableReadBatch,\n ITableScanParams,\n ITableScanResponse,\n ITableWriteBatch\n} from \"./types.js\";\nimport { createTableWriteBatch } from \"./TableWriteBatch.js\";\nimport { createTableReadBatch } from \"./TableReadBatch.js\";\nimport { scan } from \"../scan.js\";\n\nexport class Table<\n Name extends string = string,\n PartitionKey extends string = string,\n SortKey extends string = string\n> implements ITable<Name, PartitionKey, SortKey>\n{\n public readonly table: BaseTable<Name, PartitionKey, SortKey>;\n\n public constructor(params: TableConstructor<Name, PartitionKey, SortKey>) {\n this.table = new BaseTable(params);\n }\n\n public createWriter(): ITableWriteBatch {\n return createTableWriteBatch({\n table: this.table\n });\n }\n\n public createReader(): ITableReadBatch {\n return createTableReadBatch({\n table: this.table\n });\n }\n\n public async scan<T>(params: ITableScanParams): Promise<ITableScanResponse<T>> {\n return scan<T>({\n ...params,\n table: this.table\n });\n }\n}\n"],"mappings":"AACA,SAASA,KAAK,IAAIC,SAAS;AAQ3B,SAASC,qBAAqB;AAC9B,SAASC,oBAAoB;AAC7B,SAASC,IAAI;AAEb,OAAO,MAAMJ,KAAK,CAKlB;EAGWK,WAAWA,CAACC,MAAqD,EAAE;IACtE,IAAI,CAACC,KAAK,GAAG,IAAIN,SAAS,CAACK,MAAM,CAAC;EACtC;EAEOE,YAAYA,CAAA,EAAqB;IACpC,OAAON,qBAAqB,CAAC;MACzBK,KAAK,EAAE,IAAI,CAACA;IAChB,CAAC,CAAC;EACN;EAEOE,YAAYA,CAAA,EAAoB;IACnC,OAAON,oBAAoB,CAAC;MACxBI,KAAK,EAAE,IAAI,CAACA;IAChB,CAAC,CAAC;EACN;EAEA,MAAaH,IAAIA,CAAIE,MAAwB,EAAkC;IAC3E,OAAOF,IAAI,CAAI;MACX,GAAGE,MAAM;MACTC,KAAK,EAAE,IAAI,CAACA;IAChB,CAAC,CAAC;EACN;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"utils/table/Table.js","sources":["../../../src/utils/table/Table.ts"],"sourcesContent":["import type { TableConstructor } from \"~/toolbox.js\";\nimport { Table as BaseTable } from \"~/toolbox.js\";\nimport type {\n ITable,\n ITableReadBatch,\n ITableScanParams,\n ITableScanResponse,\n ITableWriteBatch\n} from \"./types.js\";\nimport { createTableWriteBatch } from \"./TableWriteBatch.js\";\nimport { createTableReadBatch } from \"./TableReadBatch.js\";\nimport { scan } from \"../scan.js\";\n\nexport class Table<\n Name extends string = string,\n PartitionKey extends string = string,\n SortKey extends string = string\n> implements ITable<Name, PartitionKey, SortKey> {\n public readonly table: BaseTable<Name, PartitionKey, SortKey>;\n\n public constructor(params: TableConstructor<Name, PartitionKey, SortKey>) {\n this.table = new BaseTable(params);\n }\n\n public createWriter(): ITableWriteBatch {\n return createTableWriteBatch({\n table: this.table\n });\n }\n\n public createReader(): ITableReadBatch {\n return createTableReadBatch({\n table: this.table\n });\n }\n\n public async scan<T>(params: ITableScanParams): Promise<ITableScanResponse<T>> {\n return scan<T>({\n ...params,\n table: this.table\n });\n }\n}\n"],"names":["Table","params","BaseTable","createTableWriteBatch","createTableReadBatch","scan"],"mappings":";;;;AAaO,MAAMA;IAOT,YAAmBC,MAAqD,CAAE;QACtE,IAAI,CAAC,KAAK,GAAG,IAAIC,MAAUD;IAC/B;IAEO,eAAiC;QACpC,OAAOE,sBAAsB;YACzB,OAAO,IAAI,CAAC,KAAK;QACrB;IACJ;IAEO,eAAgC;QACnC,OAAOC,qBAAqB;YACxB,OAAO,IAAI,CAAC,KAAK;QACrB;IACJ;IAEA,MAAa,KAAQH,MAAwB,EAAkC;QAC3E,OAAOI,KAAQ;YACX,GAAGJ,MAAM;YACT,OAAO,IAAI,CAAC,KAAK;QACrB;IACJ;AACJ"}
@@ -1,54 +1,46 @@
1
1
  import { batchReadAll } from "../batch/batchRead.js";
2
2
  import { createEntityReadBatchBuilder } from "../entity/EntityReadBatchBuilder.js";
3
3
  import { WebinyError } from "@webiny/error";
4
- export class TableReadBatch {
5
- _items = [];
6
- builders = new Map();
7
- constructor(params) {
8
- this.table = params.table;
9
- }
10
- get total() {
11
- return this._items.length;
12
- }
13
- get items() {
14
- return Array.from(this._items);
15
- }
16
- get(entity, input) {
17
- const builder = this.getBuilder(entity);
18
- const items = Array.isArray(input) ? input : [input];
19
- for (const item of items) {
20
- /**
21
- * We cannot read from two tables at the same time, so check for that.
22
- */
23
- if (this.table.name !== entity.table.name) {
24
- throw new WebinyError(`Cannot read from two different tables at the same time.`);
25
- }
26
- this._items.push(builder.get(item));
4
+ class TableReadBatch {
5
+ constructor(params){
6
+ this._items = [];
7
+ this.builders = new Map();
8
+ this.table = params.table;
27
9
  }
28
- }
29
- async execute() {
30
- if (this._items.length === 0) {
31
- return [];
10
+ get total() {
11
+ return this._items.length;
32
12
  }
33
- const items = Array.from(this._items);
34
- this._items.length = 0;
35
- return await batchReadAll({
36
- items,
37
- table: this.table
38
- });
39
- }
40
- getBuilder(entity) {
41
- const builder = this.builders.get(entity.name);
42
- if (builder) {
43
- return builder;
13
+ get items() {
14
+ return Array.from(this._items);
15
+ }
16
+ get(entity, input) {
17
+ const builder = this.getBuilder(entity);
18
+ const items = Array.isArray(input) ? input : [
19
+ input
20
+ ];
21
+ for (const item of items){
22
+ if (this.table.name !== entity.table.name) throw new WebinyError("Cannot read from two different tables at the same time.");
23
+ this._items.push(builder.get(item));
24
+ }
25
+ }
26
+ async execute() {
27
+ if (0 === this._items.length) return [];
28
+ const items = Array.from(this._items);
29
+ this._items.length = 0;
30
+ return await batchReadAll({
31
+ items,
32
+ table: this.table
33
+ });
34
+ }
35
+ getBuilder(entity) {
36
+ const builder = this.builders.get(entity.name);
37
+ if (builder) return builder;
38
+ const newBuilder = createEntityReadBatchBuilder(entity);
39
+ this.builders.set(entity.name, newBuilder);
40
+ return newBuilder;
44
41
  }
45
- const newBuilder = createEntityReadBatchBuilder(entity);
46
- this.builders.set(entity.name, newBuilder);
47
- return newBuilder;
48
- }
49
42
  }
50
- export const createTableReadBatch = params => {
51
- return new TableReadBatch(params);
52
- };
43
+ const createTableReadBatch = (params)=>new TableReadBatch(params);
44
+ export { TableReadBatch, createTableReadBatch };
53
45
 
54
46
  //# sourceMappingURL=TableReadBatch.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["batchReadAll","createEntityReadBatchBuilder","WebinyError","TableReadBatch","_items","builders","Map","constructor","params","table","total","length","items","Array","from","get","entity","input","builder","getBuilder","isArray","item","name","push","execute","newBuilder","set","createTableReadBatch"],"sources":["TableReadBatch.ts"],"sourcesContent":["import type { Entity, TableDef } from \"~/toolbox.js\";\nimport type {\n IEntityReadBatchBuilder,\n IEntityReadBatchBuilderGetResponse\n} from \"~/utils/entity/types.js\";\nimport { batchReadAll } from \"~/utils/batch/batchRead.js\";\nimport { createEntityReadBatchBuilder } from \"~/utils/entity/EntityReadBatchBuilder.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport { WebinyError } from \"@webiny/error\";\nimport type { ITableReadBatch, ITableReadBatchKey } from \"./types.js\";\n\nexport interface ITableReadBatchParams {\n table: TableDef;\n}\n\nexport class TableReadBatch implements ITableReadBatch {\n private readonly table: TableDef;\n\n private readonly _items: IEntityReadBatchBuilderGetResponse[] = [];\n private readonly builders: Map<string, IEntityReadBatchBuilder> = new Map();\n\n public constructor(params: ITableReadBatchParams) {\n this.table = params.table;\n }\n\n public get total(): number {\n return this._items.length;\n }\n\n public get items(): IEntityReadBatchBuilderGetResponse[] {\n return Array.from(this._items);\n }\n\n public get(entity: Entity, input: ITableReadBatchKey): void {\n const builder = this.getBuilder(entity);\n\n const items = Array.isArray(input) ? input : [input];\n for (const item of items) {\n /**\n * We cannot read from two tables at the same time, so check for that.\n */\n if (this.table.name !== entity.table!.name) {\n throw new WebinyError(`Cannot read from two different tables at the same time.`);\n }\n\n this._items.push(builder.get(item));\n }\n }\n\n public async execute<T = GenericRecord>(): Promise<T[]> {\n if (this._items.length === 0) {\n return [];\n }\n const items = Array.from(this._items);\n this._items.length = 0;\n return await batchReadAll<T>({\n items,\n table: this.table\n });\n }\n\n private getBuilder(entity: Entity): IEntityReadBatchBuilder {\n const builder = this.builders.get(entity.name);\n if (builder) {\n return builder;\n }\n const newBuilder = createEntityReadBatchBuilder(entity);\n this.builders.set(entity.name, newBuilder);\n return newBuilder;\n }\n}\n\nexport const createTableReadBatch = (params: ITableReadBatchParams): ITableReadBatch => {\n return new TableReadBatch(params);\n};\n"],"mappings":"AAKA,SAASA,YAAY;AACrB,SAASC,4BAA4B;AAErC,SAASC,WAAW,QAAQ,eAAe;AAO3C,OAAO,MAAMC,cAAc,CAA4B;EAGlCC,MAAM,GAAyC,EAAE;EACjDC,QAAQ,GAAyC,IAAIC,GAAG,CAAC,CAAC;EAEpEC,WAAWA,CAACC,MAA6B,EAAE;IAC9C,IAAI,CAACC,KAAK,GAAGD,MAAM,CAACC,KAAK;EAC7B;EAEA,IAAWC,KAAKA,CAAA,EAAW;IACvB,OAAO,IAAI,CAACN,MAAM,CAACO,MAAM;EAC7B;EAEA,IAAWC,KAAKA,CAAA,EAAyC;IACrD,OAAOC,KAAK,CAACC,IAAI,CAAC,IAAI,CAACV,MAAM,CAAC;EAClC;EAEOW,GAAGA,CAACC,MAAc,EAAEC,KAAyB,EAAQ;IACxD,MAAMC,OAAO,GAAG,IAAI,CAACC,UAAU,CAACH,MAAM,CAAC;IAEvC,MAAMJ,KAAK,GAAGC,KAAK,CAACO,OAAO,CAACH,KAAK,CAAC,GAAGA,KAAK,GAAG,CAACA,KAAK,CAAC;IACpD,KAAK,MAAMI,IAAI,IAAIT,KAAK,EAAE;MACtB;AACZ;AACA;MACY,IAAI,IAAI,CAACH,KAAK,CAACa,IAAI,KAAKN,MAAM,CAACP,KAAK,CAAEa,IAAI,EAAE;QACxC,MAAM,IAAIpB,WAAW,CAAC,yDAAyD,CAAC;MACpF;MAEA,IAAI,CAACE,MAAM,CAACmB,IAAI,CAACL,OAAO,CAACH,GAAG,CAACM,IAAI,CAAC,CAAC;IACvC;EACJ;EAEA,MAAaG,OAAOA,CAAA,EAAoC;IACpD,IAAI,IAAI,CAACpB,MAAM,CAACO,MAAM,KAAK,CAAC,EAAE;MAC1B,OAAO,EAAE;IACb;IACA,MAAMC,KAAK,GAAGC,KAAK,CAACC,IAAI,CAAC,IAAI,CAACV,MAAM,CAAC;IACrC,IAAI,CAACA,MAAM,CAACO,MAAM,GAAG,CAAC;IACtB,OAAO,MAAMX,YAAY,CAAI;MACzBY,KAAK;MACLH,KAAK,EAAE,IAAI,CAACA;IAChB,CAAC,CAAC;EACN;EAEQU,UAAUA,CAACH,MAAc,EAA2B;IACxD,MAAME,OAAO,GAAG,IAAI,CAACb,QAAQ,CAACU,GAAG,CAACC,MAAM,CAACM,IAAI,CAAC;IAC9C,IAAIJ,OAAO,EAAE;MACT,OAAOA,OAAO;IAClB;IACA,MAAMO,UAAU,GAAGxB,4BAA4B,CAACe,MAAM,CAAC;IACvD,IAAI,CAACX,QAAQ,CAACqB,GAAG,CAACV,MAAM,CAACM,IAAI,EAAEG,UAAU,CAAC;IAC1C,OAAOA,UAAU;EACrB;AACJ;AAEA,OAAO,MAAME,oBAAoB,GAAInB,MAA6B,IAAsB;EACpF,OAAO,IAAIL,cAAc,CAACK,MAAM,CAAC;AACrC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"utils/table/TableReadBatch.js","sources":["../../../src/utils/table/TableReadBatch.ts"],"sourcesContent":["import type { Entity, TableDef } from \"~/toolbox.js\";\nimport type {\n IEntityReadBatchBuilder,\n IEntityReadBatchBuilderGetResponse\n} from \"~/utils/entity/types.js\";\nimport { batchReadAll } from \"~/utils/batch/batchRead.js\";\nimport { createEntityReadBatchBuilder } from \"~/utils/entity/EntityReadBatchBuilder.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport { WebinyError } from \"@webiny/error\";\nimport type { ITableReadBatch, ITableReadBatchKey } from \"./types.js\";\n\nexport interface ITableReadBatchParams {\n table: TableDef;\n}\n\nexport class TableReadBatch implements ITableReadBatch {\n private readonly table: TableDef;\n\n private readonly _items: IEntityReadBatchBuilderGetResponse[] = [];\n private readonly builders: Map<string, IEntityReadBatchBuilder> = new Map();\n\n public constructor(params: ITableReadBatchParams) {\n this.table = params.table;\n }\n\n public get total(): number {\n return this._items.length;\n }\n\n public get items(): IEntityReadBatchBuilderGetResponse[] {\n return Array.from(this._items);\n }\n\n public get(entity: Entity, input: ITableReadBatchKey): void {\n const builder = this.getBuilder(entity);\n\n const items = Array.isArray(input) ? input : [input];\n for (const item of items) {\n /**\n * We cannot read from two tables at the same time, so check for that.\n */\n if (this.table.name !== entity.table!.name) {\n throw new WebinyError(`Cannot read from two different tables at the same time.`);\n }\n\n this._items.push(builder.get(item));\n }\n }\n\n public async execute<T = GenericRecord>(): Promise<T[]> {\n if (this._items.length === 0) {\n return [];\n }\n const items = Array.from(this._items);\n this._items.length = 0;\n return await batchReadAll<T>({\n items,\n table: this.table\n });\n }\n\n private getBuilder(entity: Entity): IEntityReadBatchBuilder {\n const builder = this.builders.get(entity.name);\n if (builder) {\n return builder;\n }\n const newBuilder = createEntityReadBatchBuilder(entity);\n this.builders.set(entity.name, newBuilder);\n return newBuilder;\n }\n}\n\nexport const createTableReadBatch = (params: ITableReadBatchParams): ITableReadBatch => {\n return new TableReadBatch(params);\n};\n"],"names":["TableReadBatch","params","Map","Array","entity","input","builder","items","item","WebinyError","batchReadAll","newBuilder","createEntityReadBatchBuilder","createTableReadBatch"],"mappings":";;;AAeO,MAAMA;IAMT,YAAmBC,MAA6B,CAAE;aAHjC,MAAM,GAAyC,EAAE;aACjD,QAAQ,GAAyC,IAAIC;QAGlE,IAAI,CAAC,KAAK,GAAGD,OAAO,KAAK;IAC7B;IAEA,IAAW,QAAgB;QACvB,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM;IAC7B;IAEA,IAAW,QAA8C;QACrD,OAAOE,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM;IACjC;IAEO,IAAIC,MAAc,EAAEC,KAAyB,EAAQ;QACxD,MAAMC,UAAU,IAAI,CAAC,UAAU,CAACF;QAEhC,MAAMG,QAAQJ,MAAM,OAAO,CAACE,SAASA,QAAQ;YAACA;SAAM;QACpD,KAAK,MAAMG,QAAQD,MAAO;YAItB,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,KAAKH,OAAO,KAAK,CAAE,IAAI,EACtC,MAAM,IAAIK,YAAY;YAG1B,IAAI,CAAC,MAAM,CAAC,IAAI,CAACH,QAAQ,GAAG,CAACE;QACjC;IACJ;IAEA,MAAa,UAA2C;QACpD,IAAI,AAAuB,MAAvB,IAAI,CAAC,MAAM,CAAC,MAAM,EAClB,OAAO,EAAE;QAEb,MAAMD,QAAQJ,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM;QACpC,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG;QACrB,OAAO,MAAMO,aAAgB;YACzBH;YACA,OAAO,IAAI,CAAC,KAAK;QACrB;IACJ;IAEQ,WAAWH,MAAc,EAA2B;QACxD,MAAME,UAAU,IAAI,CAAC,QAAQ,CAAC,GAAG,CAACF,OAAO,IAAI;QAC7C,IAAIE,SACA,OAAOA;QAEX,MAAMK,aAAaC,6BAA6BR;QAChD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAACA,OAAO,IAAI,EAAEO;QAC/B,OAAOA;IACX;AACJ;AAEO,MAAME,uBAAuB,CAACZ,SAC1B,IAAID,eAAeC"}
@@ -1,61 +1,52 @@
1
1
  import { batchWriteAll } from "../batch/batchWrite.js";
2
2
  import { createEntityWriteBatchBuilder } from "../entity/EntityWriteBatchBuilder.js";
3
- export class TableWriteBatch {
4
- _items = [];
5
- builders = new Map();
6
- get total() {
7
- return this._items.length;
8
- }
9
- get items() {
10
- return Array.from(this._items);
11
- }
12
- constructor(params) {
13
- this.table = params.table;
14
- if (!params.items?.length) {
15
- return;
16
- }
17
- this._items.push(...params.items);
18
- }
19
- put(entity, item) {
20
- const builder = this.getBuilder(entity);
21
- this._items.push(builder.put(item));
22
- }
23
- delete(entity, item) {
24
- const builder = this.getBuilder(entity);
25
- this._items.push(builder.delete(item));
26
- }
27
- combine(items) {
28
- return createTableWriteBatch({
29
- table: this.table,
30
- items: this._items.concat(items)
31
- });
32
- }
33
- async execute() {
34
- if (this._items.length === 0) {
35
- return [];
36
- }
37
- const items = Array.from(this._items);
38
- this._items.length = 0;
39
- return await batchWriteAll({
40
- items,
41
- table: this.table
42
- });
43
- }
44
- getBuilder(entity) {
45
- if (!entity.name) {
46
- throw new Error("Entity must have a name.");
47
- }
48
- const builder = this.builders.get(entity.name);
49
- if (builder) {
50
- return builder;
51
- }
52
- const newBuilder = createEntityWriteBatchBuilder(entity);
53
- this.builders.set(entity.name, newBuilder);
54
- return newBuilder;
55
- }
3
+ class TableWriteBatch {
4
+ get total() {
5
+ return this._items.length;
6
+ }
7
+ get items() {
8
+ return Array.from(this._items);
9
+ }
10
+ constructor(params){
11
+ this._items = [];
12
+ this.builders = new Map();
13
+ this.table = params.table;
14
+ if (!params.items?.length) return;
15
+ this._items.push(...params.items);
16
+ }
17
+ put(entity, item) {
18
+ const builder = this.getBuilder(entity);
19
+ this._items.push(builder.put(item));
20
+ }
21
+ delete(entity, item) {
22
+ const builder = this.getBuilder(entity);
23
+ this._items.push(builder.delete(item));
24
+ }
25
+ combine(items) {
26
+ return createTableWriteBatch({
27
+ table: this.table,
28
+ items: this._items.concat(items)
29
+ });
30
+ }
31
+ async execute() {
32
+ if (0 === this._items.length) return [];
33
+ const items = Array.from(this._items);
34
+ this._items.length = 0;
35
+ return await batchWriteAll({
36
+ items,
37
+ table: this.table
38
+ });
39
+ }
40
+ getBuilder(entity) {
41
+ if (!entity.name) throw new Error("Entity must have a name.");
42
+ const builder = this.builders.get(entity.name);
43
+ if (builder) return builder;
44
+ const newBuilder = createEntityWriteBatchBuilder(entity);
45
+ this.builders.set(entity.name, newBuilder);
46
+ return newBuilder;
47
+ }
56
48
  }
57
- export const createTableWriteBatch = params => {
58
- return new TableWriteBatch(params);
59
- };
49
+ const createTableWriteBatch = (params)=>new TableWriteBatch(params);
50
+ export { TableWriteBatch, createTableWriteBatch };
60
51
 
61
52
  //# sourceMappingURL=TableWriteBatch.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["batchWriteAll","createEntityWriteBatchBuilder","TableWriteBatch","_items","builders","Map","total","length","items","Array","from","constructor","params","table","push","put","entity","item","builder","getBuilder","delete","combine","createTableWriteBatch","concat","execute","name","Error","get","newBuilder","set"],"sources":["TableWriteBatch.ts"],"sourcesContent":["import type { Entity, TableDef } from \"~/toolbox.js\";\nimport type {\n BatchWriteItem,\n BatchWriteResult,\n IDeleteBatchItem,\n IPutBatchItem\n} from \"~/utils/batch/types.js\";\nimport type { IEntityWriteBatchBuilder } from \"~/utils/entity/types.js\";\nimport { batchWriteAll } from \"~/utils/batch/batchWrite.js\";\nimport { createEntityWriteBatchBuilder } from \"~/utils/entity/EntityWriteBatchBuilder.js\";\nimport type { ITableWriteBatch } from \"./types.js\";\n\nexport interface ITableWriteBatchParams {\n table: TableDef;\n items?: BatchWriteItem[];\n}\n\nexport class TableWriteBatch implements ITableWriteBatch {\n private readonly table: TableDef;\n private readonly _items: BatchWriteItem[] = [];\n private readonly builders: Map<string, IEntityWriteBatchBuilder> = new Map();\n\n public get total(): number {\n return this._items.length;\n }\n\n public get items(): BatchWriteItem[] {\n return Array.from(this._items);\n }\n\n public constructor(params: ITableWriteBatchParams) {\n this.table = params.table;\n if (!params.items?.length) {\n return;\n }\n this._items.push(...params.items);\n }\n\n public put(entity: Entity, item: IPutBatchItem): void {\n const builder = this.getBuilder(entity);\n this._items.push(builder.put(item));\n }\n\n public delete(entity: Entity, item: IDeleteBatchItem): void {\n const builder = this.getBuilder(entity);\n this._items.push(builder.delete(item));\n }\n\n public combine(items: BatchWriteItem[]): ITableWriteBatch {\n return createTableWriteBatch({\n table: this.table,\n items: this._items.concat(items)\n });\n }\n\n public async execute(): Promise<BatchWriteResult> {\n if (this._items.length === 0) {\n return [];\n }\n const items = Array.from(this._items);\n this._items.length = 0;\n return await batchWriteAll({\n items,\n table: this.table\n });\n }\n\n private getBuilder(entity: Entity): IEntityWriteBatchBuilder {\n if (!entity.name) {\n throw new Error(\"Entity must have a name.\");\n }\n const builder = this.builders.get(entity.name);\n if (builder) {\n return builder;\n }\n const newBuilder = createEntityWriteBatchBuilder(entity);\n this.builders.set(entity.name, newBuilder);\n return newBuilder;\n }\n}\n\nexport const createTableWriteBatch = (params: ITableWriteBatchParams): ITableWriteBatch => {\n return new TableWriteBatch(params);\n};\n"],"mappings":"AAQA,SAASA,aAAa;AACtB,SAASC,6BAA6B;AAQtC,OAAO,MAAMC,eAAe,CAA6B;EAEpCC,MAAM,GAAqB,EAAE;EAC7BC,QAAQ,GAA0C,IAAIC,GAAG,CAAC,CAAC;EAE5E,IAAWC,KAAKA,CAAA,EAAW;IACvB,OAAO,IAAI,CAACH,MAAM,CAACI,MAAM;EAC7B;EAEA,IAAWC,KAAKA,CAAA,EAAqB;IACjC,OAAOC,KAAK,CAACC,IAAI,CAAC,IAAI,CAACP,MAAM,CAAC;EAClC;EAEOQ,WAAWA,CAACC,MAA8B,EAAE;IAC/C,IAAI,CAACC,KAAK,GAAGD,MAAM,CAACC,KAAK;IACzB,IAAI,CAACD,MAAM,CAACJ,KAAK,EAAED,MAAM,EAAE;MACvB;IACJ;IACA,IAAI,CAACJ,MAAM,CAACW,IAAI,CAAC,GAAGF,MAAM,CAACJ,KAAK,CAAC;EACrC;EAEOO,GAAGA,CAACC,MAAc,EAAEC,IAAmB,EAAQ;IAClD,MAAMC,OAAO,GAAG,IAAI,CAACC,UAAU,CAACH,MAAM,CAAC;IACvC,IAAI,CAACb,MAAM,CAACW,IAAI,CAACI,OAAO,CAACH,GAAG,CAACE,IAAI,CAAC,CAAC;EACvC;EAEOG,MAAMA,CAACJ,MAAc,EAAEC,IAAsB,EAAQ;IACxD,MAAMC,OAAO,GAAG,IAAI,CAACC,UAAU,CAACH,MAAM,CAAC;IACvC,IAAI,CAACb,MAAM,CAACW,IAAI,CAACI,OAAO,CAACE,MAAM,CAACH,IAAI,CAAC,CAAC;EAC1C;EAEOI,OAAOA,CAACb,KAAuB,EAAoB;IACtD,OAAOc,qBAAqB,CAAC;MACzBT,KAAK,EAAE,IAAI,CAACA,KAAK;MACjBL,KAAK,EAAE,IAAI,CAACL,MAAM,CAACoB,MAAM,CAACf,KAAK;IACnC,CAAC,CAAC;EACN;EAEA,MAAagB,OAAOA,CAAA,EAA8B;IAC9C,IAAI,IAAI,CAACrB,MAAM,CAACI,MAAM,KAAK,CAAC,EAAE;MAC1B,OAAO,EAAE;IACb;IACA,MAAMC,KAAK,GAAGC,KAAK,CAACC,IAAI,CAAC,IAAI,CAACP,MAAM,CAAC;IACrC,IAAI,CAACA,MAAM,CAACI,MAAM,GAAG,CAAC;IACtB,OAAO,MAAMP,aAAa,CAAC;MACvBQ,KAAK;MACLK,KAAK,EAAE,IAAI,CAACA;IAChB,CAAC,CAAC;EACN;EAEQM,UAAUA,CAACH,MAAc,EAA4B;IACzD,IAAI,CAACA,MAAM,CAACS,IAAI,EAAE;MACd,MAAM,IAAIC,KAAK,CAAC,0BAA0B,CAAC;IAC/C;IACA,MAAMR,OAAO,GAAG,IAAI,CAACd,QAAQ,CAACuB,GAAG,CAACX,MAAM,CAACS,IAAI,CAAC;IAC9C,IAAIP,OAAO,EAAE;MACT,OAAOA,OAAO;IAClB;IACA,MAAMU,UAAU,GAAG3B,6BAA6B,CAACe,MAAM,CAAC;IACxD,IAAI,CAACZ,QAAQ,CAACyB,GAAG,CAACb,MAAM,CAACS,IAAI,EAAEG,UAAU,CAAC;IAC1C,OAAOA,UAAU;EACrB;AACJ;AAEA,OAAO,MAAMN,qBAAqB,GAAIV,MAA8B,IAAuB;EACvF,OAAO,IAAIV,eAAe,CAACU,MAAM,CAAC;AACtC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"utils/table/TableWriteBatch.js","sources":["../../../src/utils/table/TableWriteBatch.ts"],"sourcesContent":["import type { Entity, TableDef } from \"~/toolbox.js\";\nimport type {\n BatchWriteItem,\n BatchWriteResult,\n IDeleteBatchItem,\n IPutBatchItem\n} from \"~/utils/batch/types.js\";\nimport type { IEntityWriteBatchBuilder } from \"~/utils/entity/types.js\";\nimport { batchWriteAll } from \"~/utils/batch/batchWrite.js\";\nimport { createEntityWriteBatchBuilder } from \"~/utils/entity/EntityWriteBatchBuilder.js\";\nimport type { ITableWriteBatch } from \"./types.js\";\n\nexport interface ITableWriteBatchParams {\n table: TableDef;\n items?: BatchWriteItem[];\n}\n\nexport class TableWriteBatch implements ITableWriteBatch {\n private readonly table: TableDef;\n private readonly _items: BatchWriteItem[] = [];\n private readonly builders: Map<string, IEntityWriteBatchBuilder> = new Map();\n\n public get total(): number {\n return this._items.length;\n }\n\n public get items(): BatchWriteItem[] {\n return Array.from(this._items);\n }\n\n public constructor(params: ITableWriteBatchParams) {\n this.table = params.table;\n if (!params.items?.length) {\n return;\n }\n this._items.push(...params.items);\n }\n\n public put(entity: Entity, item: IPutBatchItem): void {\n const builder = this.getBuilder(entity);\n this._items.push(builder.put(item));\n }\n\n public delete(entity: Entity, item: IDeleteBatchItem): void {\n const builder = this.getBuilder(entity);\n this._items.push(builder.delete(item));\n }\n\n public combine(items: BatchWriteItem[]): ITableWriteBatch {\n return createTableWriteBatch({\n table: this.table,\n items: this._items.concat(items)\n });\n }\n\n public async execute(): Promise<BatchWriteResult> {\n if (this._items.length === 0) {\n return [];\n }\n const items = Array.from(this._items);\n this._items.length = 0;\n return await batchWriteAll({\n items,\n table: this.table\n });\n }\n\n private getBuilder(entity: Entity): IEntityWriteBatchBuilder {\n if (!entity.name) {\n throw new Error(\"Entity must have a name.\");\n }\n const builder = this.builders.get(entity.name);\n if (builder) {\n return builder;\n }\n const newBuilder = createEntityWriteBatchBuilder(entity);\n this.builders.set(entity.name, newBuilder);\n return newBuilder;\n }\n}\n\nexport const createTableWriteBatch = (params: ITableWriteBatchParams): ITableWriteBatch => {\n return new TableWriteBatch(params);\n};\n"],"names":["TableWriteBatch","Array","params","Map","entity","item","builder","items","createTableWriteBatch","batchWriteAll","Error","newBuilder","createEntityWriteBatchBuilder"],"mappings":";;AAiBO,MAAMA;IAKT,IAAW,QAAgB;QACvB,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM;IAC7B;IAEA,IAAW,QAA0B;QACjC,OAAOC,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM;IACjC;IAEA,YAAmBC,MAA8B,CAAE;aAXlC,MAAM,GAAqB,EAAE;aAC7B,QAAQ,GAA0C,IAAIC;QAWnE,IAAI,CAAC,KAAK,GAAGD,OAAO,KAAK;QACzB,IAAI,CAACA,OAAO,KAAK,EAAE,QACf;QAEJ,IAAI,CAAC,MAAM,CAAC,IAAI,IAAIA,OAAO,KAAK;IACpC;IAEO,IAAIE,MAAc,EAAEC,IAAmB,EAAQ;QAClD,MAAMC,UAAU,IAAI,CAAC,UAAU,CAACF;QAChC,IAAI,CAAC,MAAM,CAAC,IAAI,CAACE,QAAQ,GAAG,CAACD;IACjC;IAEO,OAAOD,MAAc,EAAEC,IAAsB,EAAQ;QACxD,MAAMC,UAAU,IAAI,CAAC,UAAU,CAACF;QAChC,IAAI,CAAC,MAAM,CAAC,IAAI,CAACE,QAAQ,MAAM,CAACD;IACpC;IAEO,QAAQE,KAAuB,EAAoB;QACtD,OAAOC,sBAAsB;YACzB,OAAO,IAAI,CAAC,KAAK;YACjB,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAACD;QAC9B;IACJ;IAEA,MAAa,UAAqC;QAC9C,IAAI,AAAuB,MAAvB,IAAI,CAAC,MAAM,CAAC,MAAM,EAClB,OAAO,EAAE;QAEb,MAAMA,QAAQN,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM;QACpC,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG;QACrB,OAAO,MAAMQ,cAAc;YACvBF;YACA,OAAO,IAAI,CAAC,KAAK;QACrB;IACJ;IAEQ,WAAWH,MAAc,EAA4B;QACzD,IAAI,CAACA,OAAO,IAAI,EACZ,MAAM,IAAIM,MAAM;QAEpB,MAAMJ,UAAU,IAAI,CAAC,QAAQ,CAAC,GAAG,CAACF,OAAO,IAAI;QAC7C,IAAIE,SACA,OAAOA;QAEX,MAAMK,aAAaC,8BAA8BR;QACjD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAACA,OAAO,IAAI,EAAEO;QAC/B,OAAOA;IACX;AACJ;AAEO,MAAMH,wBAAwB,CAACN,SAC3B,IAAIF,gBAAgBE"}
@@ -2,5 +2,3 @@ export * from "./Table.js";
2
2
  export * from "./TableReadBatch.js";
3
3
  export * from "./TableWriteBatch.js";
4
4
  export * from "./types.js";
5
-
6
- //# sourceMappingURL=index.js.map
@@ -1,3 +0,0 @@
1
- export {};
2
-
3
- //# sourceMappingURL=types.js.map
@@ -1,18 +0,0 @@
1
- import { Plugin } from "@webiny/plugins";
2
- import type { AttributeDefinition } from "../../toolbox.js";
3
- export interface AttributePluginParams {
4
- entity: string;
5
- attribute: string;
6
- params: AttributeDefinition;
7
- }
8
- export declare abstract class AttributePlugin extends Plugin {
9
- static readonly type: string;
10
- private readonly _entity;
11
- private readonly _attribute;
12
- private readonly _params;
13
- get entity(): string;
14
- get attribute(): string;
15
- constructor({ entity, attribute, params }: AttributePluginParams);
16
- getDefinition(): Record<string, AttributeDefinition>;
17
- private validateReserved;
18
- }
@@ -1,38 +0,0 @@
1
- import WebinyError from "@webiny/error";
2
- import { Plugin } from "@webiny/plugins";
3
- const reservedFields = ["PK", "SK", "index", "data"];
4
- export class AttributePlugin extends Plugin {
5
- static type = "db.dynamodb.attribute";
6
- get entity() {
7
- return this._entity;
8
- }
9
- get attribute() {
10
- return this._attribute;
11
- }
12
- constructor({
13
- entity,
14
- attribute,
15
- params
16
- }) {
17
- super();
18
- this.validateReserved(attribute);
19
- this._entity = entity;
20
- this._attribute = attribute;
21
- this._params = params;
22
- }
23
- getDefinition() {
24
- return {
25
- [this.attribute]: this._params
26
- };
27
- }
28
- validateReserved(attribute) {
29
- if (reservedFields.includes(attribute) === false) {
30
- return;
31
- }
32
- throw new WebinyError(`Attribute name "${attribute}" is not allowed.`, "ATTRIBUTE_NOT_ALLOWED", {
33
- attribute
34
- });
35
- }
36
- }
37
-
38
- //# sourceMappingURL=AttributePlugin.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["WebinyError","Plugin","reservedFields","AttributePlugin","type","entity","_entity","attribute","_attribute","constructor","params","validateReserved","_params","getDefinition","includes"],"sources":["AttributePlugin.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { Plugin } from \"@webiny/plugins\";\nimport type { AttributeDefinition } from \"~/toolbox.js\";\n\nconst reservedFields = [\"PK\", \"SK\", \"index\", \"data\"];\n\nexport interface AttributePluginParams {\n entity: string;\n attribute: string;\n params: AttributeDefinition;\n}\n\nexport abstract class AttributePlugin extends Plugin {\n public static override readonly type: string = \"db.dynamodb.attribute\";\n private readonly _entity: string;\n private readonly _attribute: string;\n private readonly _params: AttributeDefinition;\n\n public get entity(): string {\n return this._entity;\n }\n\n public get attribute(): string {\n return this._attribute;\n }\n\n public constructor({ entity, attribute, params }: AttributePluginParams) {\n super();\n\n this.validateReserved(attribute);\n\n this._entity = entity;\n this._attribute = attribute;\n this._params = params;\n }\n\n public getDefinition(): Record<string, AttributeDefinition> {\n return {\n [this.attribute]: this._params\n };\n }\n\n private validateReserved(attribute: string): void {\n if (reservedFields.includes(attribute) === false) {\n return;\n }\n throw new WebinyError(\n `Attribute name \"${attribute}\" is not allowed.`,\n \"ATTRIBUTE_NOT_ALLOWED\",\n {\n attribute\n }\n );\n }\n}\n"],"mappings":"AAAA,OAAOA,WAAW,MAAM,eAAe;AACvC,SAASC,MAAM,QAAQ,iBAAiB;AAGxC,MAAMC,cAAc,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC;AAQpD,OAAO,MAAeC,eAAe,SAASF,MAAM,CAAC;EACjD,OAAgCG,IAAI,GAAW,uBAAuB;EAKtE,IAAWC,MAAMA,CAAA,EAAW;IACxB,OAAO,IAAI,CAACC,OAAO;EACvB;EAEA,IAAWC,SAASA,CAAA,EAAW;IAC3B,OAAO,IAAI,CAACC,UAAU;EAC1B;EAEOC,WAAWA,CAAC;IAAEJ,MAAM;IAAEE,SAAS;IAAEG;EAA8B,CAAC,EAAE;IACrE,KAAK,CAAC,CAAC;IAEP,IAAI,CAACC,gBAAgB,CAACJ,SAAS,CAAC;IAEhC,IAAI,CAACD,OAAO,GAAGD,MAAM;IACrB,IAAI,CAACG,UAAU,GAAGD,SAAS;IAC3B,IAAI,CAACK,OAAO,GAAGF,MAAM;EACzB;EAEOG,aAAaA,CAAA,EAAwC;IACxD,OAAO;MACH,CAAC,IAAI,CAACN,SAAS,GAAG,IAAI,CAACK;IAC3B,CAAC;EACL;EAEQD,gBAAgBA,CAACJ,SAAiB,EAAQ;IAC9C,IAAIL,cAAc,CAACY,QAAQ,CAACP,SAAS,CAAC,KAAK,KAAK,EAAE;MAC9C;IACJ;IACA,MAAM,IAAIP,WAAW,CACjB,mBAAmBO,SAAS,mBAAmB,EAC/C,uBAAuB,EACvB;MACIA;IACJ,CACJ,CAAC;EACL;AACJ","ignoreList":[]}
@@ -1,22 +0,0 @@
1
- import { Plugin } from "@webiny/plugins";
2
- export interface CreatePath {
3
- (field: string): string;
4
- }
5
- export interface FieldPathPluginParams {
6
- /**
7
- * Which field(s) is this plugin for.
8
- */
9
- fields: string | string[];
10
- /**
11
- * Create a path for given field.
12
- * Field is passed because it can be a multi-field plugin.
13
- */
14
- createPath: CreatePath;
15
- }
16
- export declare class FieldPathPlugin extends Plugin {
17
- static readonly type: string;
18
- private readonly _params;
19
- constructor(params: FieldPathPluginParams);
20
- canCreate(field: string): boolean;
21
- createPath(field: string): string;
22
- }
@@ -1,26 +0,0 @@
1
- import { Plugin } from "@webiny/plugins";
2
- import WebinyError from "@webiny/error";
3
- import { assignFields } from "./assignFields.js";
4
- export class FieldPathPlugin extends Plugin {
5
- static type = "dynamodb.value.path";
6
- constructor(params) {
7
- super();
8
- this._params = {
9
- ...params,
10
- fields: assignFields(params.fields)
11
- };
12
- }
13
- canCreate(field) {
14
- return this._params.fields.includes(field);
15
- }
16
- createPath(field) {
17
- if (!this._params.createPath) {
18
- throw new WebinyError(`Missing "createPath" in the plugin.`, "TRANSFORM_ERROR", {
19
- fields: this._params.fields
20
- });
21
- }
22
- return this._params.createPath(field);
23
- }
24
- }
25
-
26
- //# sourceMappingURL=FieldPathPlugin.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["Plugin","WebinyError","assignFields","FieldPathPlugin","type","constructor","params","_params","fields","canCreate","field","includes","createPath"],"sources":["FieldPathPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport WebinyError from \"@webiny/error\";\nimport { assignFields } from \"./assignFields.js\";\n\nexport interface CreatePath {\n (field: string): string;\n}\nexport interface FieldPathPluginParams {\n /**\n * Which field(s) is this plugin for.\n */\n fields: string | string[];\n /**\n * Create a path for given field.\n * Field is passed because it can be a multi-field plugin.\n */\n createPath: CreatePath;\n}\n\nexport class FieldPathPlugin extends Plugin {\n public static override readonly type: string = \"dynamodb.value.path\";\n private readonly _params: Omit<FieldPathPluginParams, \"fields\"> & { fields: string[] };\n\n public constructor(params: FieldPathPluginParams) {\n super();\n this._params = {\n ...params,\n fields: assignFields(params.fields)\n };\n }\n\n public canCreate(field: string): boolean {\n return this._params.fields.includes(field);\n }\n\n public createPath(field: string): string {\n if (!this._params.createPath) {\n throw new WebinyError(`Missing \"createPath\" in the plugin.`, \"TRANSFORM_ERROR\", {\n fields: this._params.fields\n });\n }\n return this._params.createPath(field);\n }\n}\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,iBAAiB;AACxC,OAAOC,WAAW,MAAM,eAAe;AACvC,SAASC,YAAY;AAiBrB,OAAO,MAAMC,eAAe,SAASH,MAAM,CAAC;EACxC,OAAgCI,IAAI,GAAW,qBAAqB;EAG7DC,WAAWA,CAACC,MAA6B,EAAE;IAC9C,KAAK,CAAC,CAAC;IACP,IAAI,CAACC,OAAO,GAAG;MACX,GAAGD,MAAM;MACTE,MAAM,EAAEN,YAAY,CAACI,MAAM,CAACE,MAAM;IACtC,CAAC;EACL;EAEOC,SAASA,CAACC,KAAa,EAAW;IACrC,OAAO,IAAI,CAACH,OAAO,CAACC,MAAM,CAACG,QAAQ,CAACD,KAAK,CAAC;EAC9C;EAEOE,UAAUA,CAACF,KAAa,EAAU;IACrC,IAAI,CAAC,IAAI,CAACH,OAAO,CAACK,UAAU,EAAE;MAC1B,MAAM,IAAIX,WAAW,CAAC,qCAAqC,EAAE,iBAAiB,EAAE;QAC5EO,MAAM,EAAE,IAAI,CAACD,OAAO,CAACC;MACzB,CAAC,CAAC;IACN;IACA,OAAO,IAAI,CAACD,OAAO,CAACK,UAAU,CAACF,KAAK,CAAC;EACzC;AACJ","ignoreList":[]}
@@ -1,22 +0,0 @@
1
- import { Plugin } from "@webiny/plugins";
2
- export interface ValueFilterPluginParamsMatchesParams<V = any, C = any> {
3
- value: V;
4
- compareValue: C;
5
- }
6
- export interface ValueFilterPluginParamsMatches {
7
- (params: ValueFilterPluginParamsMatchesParams): boolean;
8
- }
9
- export interface ValueFilterPluginParams {
10
- operation: string;
11
- canUse?: (params: ValueFilterPluginParamsMatchesParams) => boolean;
12
- matches: ValueFilterPluginParamsMatches;
13
- }
14
- export declare class ValueFilterPlugin<V = any, C = any> extends Plugin {
15
- static readonly type: string;
16
- private readonly _params;
17
- get operation(): string;
18
- constructor(params: ValueFilterPluginParams);
19
- canUse(params: ValueFilterPluginParamsMatchesParams<V, C>): boolean;
20
- matches(params: ValueFilterPluginParamsMatchesParams): boolean;
21
- getOperation(): string;
22
- }