@webiny/db-dynamodb 0.0.0-mt-3 → 0.0.0-unstable.2af142b57e

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 (130) hide show
  1. package/BatchProcess.d.ts +27 -11
  2. package/BatchProcess.js +10 -42
  3. package/BatchProcess.js.map +1 -0
  4. package/DynamoDbDriver.d.ts +19 -11
  5. package/DynamoDbDriver.js +11 -44
  6. package/DynamoDbDriver.js.map +1 -0
  7. package/QueryGenerator.d.ts +15 -13
  8. package/QueryGenerator.js +16 -31
  9. package/QueryGenerator.js.map +1 -0
  10. package/index.js +1 -3
  11. package/index.js.map +1 -0
  12. package/operators/comparison/beginsWith.js.map +1 -0
  13. package/operators/comparison/between.js.map +1 -0
  14. package/operators/comparison/eq.js +0 -2
  15. package/operators/comparison/eq.js.map +1 -0
  16. package/operators/comparison/gt.js.map +1 -0
  17. package/operators/comparison/gte.js.map +1 -0
  18. package/operators/comparison/lt.js.map +1 -0
  19. package/operators/comparison/lte.js.map +1 -0
  20. package/operators/index.js +1 -12
  21. package/operators/index.js.map +1 -0
  22. package/operators/logical/and.js +0 -5
  23. package/operators/logical/and.js.map +1 -0
  24. package/operators/logical/or.js +0 -5
  25. package/operators/logical/or.js.map +1 -0
  26. package/package.json +17 -16
  27. package/plugins/definitions/AttributePlugin.d.ts +3 -3
  28. package/plugins/definitions/AttributePlugin.js +1 -14
  29. package/plugins/definitions/AttributePlugin.js.map +1 -0
  30. package/plugins/definitions/DateTimeTransformPlugin.d.ts +2 -2
  31. package/plugins/definitions/DateTimeTransformPlugin.js +6 -20
  32. package/plugins/definitions/DateTimeTransformPlugin.js.map +1 -0
  33. package/plugins/definitions/FieldPathPlugin.d.ts +3 -3
  34. package/plugins/definitions/FieldPathPlugin.js +3 -17
  35. package/plugins/definitions/FieldPathPlugin.js.map +1 -0
  36. package/plugins/definitions/FieldPlugin.d.ts +3 -3
  37. package/plugins/definitions/FieldPlugin.js +1 -17
  38. package/plugins/definitions/FieldPlugin.js.map +1 -0
  39. package/plugins/definitions/NumberTransformPlugin.d.ts +2 -2
  40. package/plugins/definitions/NumberTransformPlugin.js +3 -18
  41. package/plugins/definitions/NumberTransformPlugin.js.map +1 -0
  42. package/plugins/definitions/TimeTransformPlugin.d.ts +2 -2
  43. package/plugins/definitions/TimeTransformPlugin.js +3 -21
  44. package/plugins/definitions/TimeTransformPlugin.js.map +1 -0
  45. package/plugins/definitions/ValueFilterPlugin.d.ts +10 -10
  46. package/plugins/definitions/ValueFilterPlugin.js +1 -13
  47. package/plugins/definitions/ValueFilterPlugin.js.map +1 -0
  48. package/plugins/definitions/ValueTransformPlugin.d.ts +8 -8
  49. package/plugins/definitions/ValueTransformPlugin.js +3 -18
  50. package/plugins/definitions/ValueTransformPlugin.js.map +1 -0
  51. package/plugins/definitions/assignFields.js +1 -10
  52. package/plugins/definitions/assignFields.js.map +1 -0
  53. package/plugins/filters/andIn.d.ts +2 -2
  54. package/plugins/filters/andIn.js +4 -9
  55. package/plugins/filters/andIn.js.map +1 -0
  56. package/plugins/filters/between.d.ts +2 -2
  57. package/plugins/filters/between.js +4 -9
  58. package/plugins/filters/between.js.map +1 -0
  59. package/plugins/filters/contains.d.ts +2 -2
  60. package/plugins/filters/contains.js +3 -6
  61. package/plugins/filters/contains.js.map +1 -0
  62. package/plugins/filters/eq.d.ts +2 -2
  63. package/plugins/filters/eq.js +15 -4
  64. package/plugins/filters/eq.js.map +1 -0
  65. package/plugins/filters/fuzzy.d.ts +2 -2
  66. package/plugins/filters/fuzzy.js +4 -8
  67. package/plugins/filters/fuzzy.js.map +1 -0
  68. package/plugins/filters/gt.d.ts +2 -2
  69. package/plugins/filters/gt.js +3 -4
  70. package/plugins/filters/gt.js.map +1 -0
  71. package/plugins/filters/gte.d.ts +2 -2
  72. package/plugins/filters/gte.js +3 -4
  73. package/plugins/filters/gte.js.map +1 -0
  74. package/plugins/filters/in.d.ts +2 -2
  75. package/plugins/filters/in.js +4 -9
  76. package/plugins/filters/in.js.map +1 -0
  77. package/plugins/filters/index.js +3 -15
  78. package/plugins/filters/index.js.map +1 -0
  79. package/plugins/filters/lt.d.ts +2 -2
  80. package/plugins/filters/lt.js +3 -4
  81. package/plugins/filters/lt.js.map +1 -0
  82. package/plugins/filters/lte.d.ts +2 -2
  83. package/plugins/filters/lte.js +3 -4
  84. package/plugins/filters/lte.js.map +1 -0
  85. package/plugins/filters/startsWith.d.ts +3 -0
  86. package/plugins/filters/startsWith.js +29 -0
  87. package/plugins/filters/startsWith.js.map +1 -0
  88. package/plugins/index.js +1 -5
  89. package/plugins/index.js.map +1 -0
  90. package/statements/createKeyConditionExpressionArgs.d.ts +12 -9
  91. package/statements/createKeyConditionExpressionArgs.js +5 -8
  92. package/statements/createKeyConditionExpressionArgs.js.map +1 -0
  93. package/statements/processStatement.d.ts +3 -4
  94. package/statements/processStatement.js +7 -11
  95. package/statements/processStatement.js.map +1 -0
  96. package/types.d.ts +37 -8
  97. package/types.js.map +1 -0
  98. package/utils/attributes.d.ts +2 -2
  99. package/utils/attributes.js +3 -14
  100. package/utils/attributes.js.map +1 -0
  101. package/utils/batchRead.d.ts +1 -1
  102. package/utils/batchRead.js +43 -34
  103. package/utils/batchRead.js.map +1 -0
  104. package/utils/batchWrite.js +1 -7
  105. package/utils/batchWrite.js.map +1 -0
  106. package/utils/cleanup.d.ts +2 -2
  107. package/utils/cleanup.js +9 -27
  108. package/utils/cleanup.js.map +1 -0
  109. package/utils/cursor.d.ts +2 -2
  110. package/utils/cursor.js +0 -6
  111. package/utils/cursor.js.map +1 -0
  112. package/utils/filter.d.ts +2 -2
  113. package/utils/filter.js +7 -43
  114. package/utils/filter.js.map +1 -0
  115. package/utils/get.d.ts +2 -2
  116. package/utils/get.js +0 -4
  117. package/utils/get.js.map +1 -0
  118. package/utils/listResponse.d.ts +1 -1
  119. package/utils/listResponse.js +7 -8
  120. package/utils/listResponse.js.map +1 -0
  121. package/utils/query.d.ts +2 -3
  122. package/utils/query.js +7 -34
  123. package/utils/query.js.map +1 -0
  124. package/utils/sort.d.ts +2 -2
  125. package/utils/sort.js +4 -23
  126. package/utils/sort.js.map +1 -0
  127. package/utils/table.js +1 -6
  128. package/utils/table.js.map +1 -0
  129. package/utils/documentClient.d.ts +0 -8
  130. package/utils/documentClient.js +0 -33
package/utils/query.js CHANGED
@@ -1,20 +1,12 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.queryOne = exports.queryAll = void 0;
9
-
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
8
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
12
9
  var _error = _interopRequireDefault(require("@webiny/error"));
13
-
14
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
15
-
16
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
17
-
18
10
  /**
19
11
  * Will run query only once. Pass the previous to run the query again to fetch new data.
20
12
  * It returns the result and the items it found.
@@ -32,7 +24,6 @@ const query = async params => {
32
24
  * In case there is no previous result we must make a new query.
33
25
  * This is the first query on the given partition key.
34
26
  */
35
-
36
27
  if (!previous) {
37
28
  result = await entity.query(partitionKey, options);
38
29
  } else if (typeof previous.next === "function") {
@@ -42,7 +33,6 @@ const query = async params => {
42
33
  * and we return a null to keep the query from repeating.
43
34
  */
44
35
  result = await previous.next();
45
-
46
36
  if (result === false) {
47
37
  return {
48
38
  result: null,
@@ -63,15 +53,12 @@ const query = async params => {
63
53
  /**
64
54
  * We expect the result to contain an Items array and if not, something went wrong, very wrong.
65
55
  */
66
-
67
-
68
56
  if (!result || !result.Items || !Array.isArray(result.Items)) {
69
57
  throw new _error.default("Error when querying for content entries - no result.", "QUERY_ERROR", {
70
58
  partitionKey,
71
59
  options
72
60
  });
73
61
  }
74
-
75
62
  return {
76
63
  result,
77
64
  items: result.Items
@@ -80,48 +67,34 @@ const query = async params => {
80
67
  /**
81
68
  * Will run the query to fetch the first possible item from the database.
82
69
  */
83
-
84
-
85
70
  const queryOne = async params => {
86
71
  const {
87
72
  items
88
- } = await query(_objectSpread(_objectSpread({}, params), {}, {
89
- options: _objectSpread(_objectSpread({}, params.options || {}), {}, {
73
+ } = await query((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
74
+ options: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params.options || {}), {}, {
90
75
  limit: 1
91
76
  })
92
77
  }));
93
-
94
- if (items.length === 0) {
95
- return null;
96
- }
97
-
98
- return items.shift();
78
+ const item = items.shift();
79
+ return item ? item : null;
99
80
  };
100
81
  /**
101
82
  * Will run the query to fetch the results no matter how much iterations it needs to go through.
102
83
  */
103
-
104
-
105
84
  exports.queryOne = queryOne;
106
-
107
85
  const queryAll = async params => {
108
86
  const items = [];
109
87
  let results;
110
88
  let previousResult = undefined;
111
-
112
- while (results = await query(_objectSpread(_objectSpread({}, params), {}, {
89
+ while (results = await query((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
113
90
  previous: previousResult
114
91
  }))) {
115
92
  items.push(...results.items);
116
-
117
93
  if (!results.result) {
118
94
  return items;
119
95
  }
120
-
121
96
  previousResult = results.result;
122
97
  }
123
-
124
98
  return items;
125
99
  };
126
-
127
100
  exports.queryAll = queryAll;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["query","params","entity","previous","partitionKey","options","result","next","items","Items","Array","isArray","WebinyError","queryOne","limit","item","shift","queryAll","results","previousResult","undefined","push"],"sources":["query.ts"],"sourcesContent":["import { queryOptions as DynamoDBToolboxQueryOptions } from \"dynamodb-toolbox/dist/classes/Table\";\nimport WebinyError from \"@webiny/error\";\nimport { Entity } from \"dynamodb-toolbox\";\n\nexport interface QueryAllParams {\n entity: Entity<any>;\n partitionKey: string;\n options?: DynamoDBToolboxQueryOptions;\n}\n\nexport interface QueryOneParams extends QueryAllParams {\n options?: Omit<DynamoDBToolboxQueryOptions, \"limit\">;\n}\n\nexport interface QueryParams extends QueryAllParams {\n previous?: any;\n}\n\nexport interface QueryResult<T> {\n result: any | null;\n items: T[];\n}\n\nexport type DbItem<T> = T & {\n PK: string;\n SK: string;\n TYPE: string;\n GSI1_PK?: string;\n GSI1_SK?: string;\n};\n\n/**\n * Will run query only once. Pass the previous to run the query again to fetch new data.\n * It returns the result and the items it found.\n * Result is required to fetch the items that were not fetched in the previous run.\n */\nconst query = async <T>(params: QueryParams): Promise<QueryResult<T>> => {\n const { entity, previous, partitionKey, options } = params;\n let result;\n /**\n * In case there is no previous result we must make a new query.\n * This is the first query on the given partition key.\n */\n if (!previous) {\n result = await entity.query(partitionKey, options);\n } else if (typeof previous.next === \"function\") {\n /**\n * In case we have a previous result and it has a next method, we run it.\n * In case result of the next method is false, it means it has nothing else to read\n * and we return a null to keep the query from repeating.\n */\n result = await previous.next();\n if (result === false) {\n return {\n result: null,\n items: []\n };\n }\n } else {\n /**\n * This could probably never happen but keep it here just in case to break the query loop.\n * Basically, either previous does not exist or it exists and it does not have the next method\n * and at that point a result returned will be null and loop should not start again.\n */\n return {\n result: null,\n items: []\n };\n }\n /**\n * We expect the result to contain an Items array and if not, something went wrong, very wrong.\n */\n if (!result || !result.Items || !Array.isArray(result.Items)) {\n throw new WebinyError(\n \"Error when querying for content entries - no result.\",\n \"QUERY_ERROR\",\n {\n partitionKey,\n options\n }\n );\n }\n return {\n result,\n items: result.Items\n };\n};\n/**\n * Will run the query to fetch the first possible item from the database.\n */\nexport const queryOne = async <T>(params: QueryOneParams): Promise<DbItem<T> | null> => {\n const { items } = await query<DbItem<T>>({\n ...params,\n options: {\n ...(params.options || {}),\n limit: 1\n }\n });\n const item = items.shift();\n return item ? item : null;\n};\n/**\n * Will run the query to fetch the results no matter how much iterations it needs to go through.\n */\nexport const queryAll = async <T>(params: QueryAllParams): Promise<DbItem<T>[]> => {\n const items: DbItem<T>[] = [];\n let results: QueryResult<DbItem<T>>;\n let previousResult: any = undefined;\n while ((results = await query({ ...params, previous: previousResult }))) {\n items.push(...results.items);\n if (!results.result) {\n return items;\n }\n previousResult = results.result;\n }\n return items;\n};\n"],"mappings":";;;;;;;;AACA;AA8BA;AACA;AACA;AACA;AACA;AACA,MAAMA,KAAK,GAAG,MAAUC,MAAmB,IAA8B;EACrE,MAAM;IAAEC,MAAM;IAAEC,QAAQ;IAAEC,YAAY;IAAEC;EAAQ,CAAC,GAAGJ,MAAM;EAC1D,IAAIK,MAAM;EACV;AACJ;AACA;AACA;EACI,IAAI,CAACH,QAAQ,EAAE;IACXG,MAAM,GAAG,MAAMJ,MAAM,CAACF,KAAK,CAACI,YAAY,EAAEC,OAAO,CAAC;EACtD,CAAC,MAAM,IAAI,OAAOF,QAAQ,CAACI,IAAI,KAAK,UAAU,EAAE;IAC5C;AACR;AACA;AACA;AACA;IACQD,MAAM,GAAG,MAAMH,QAAQ,CAACI,IAAI,EAAE;IAC9B,IAAID,MAAM,KAAK,KAAK,EAAE;MAClB,OAAO;QACHA,MAAM,EAAE,IAAI;QACZE,KAAK,EAAE;MACX,CAAC;IACL;EACJ,CAAC,MAAM;IACH;AACR;AACA;AACA;AACA;IACQ,OAAO;MACHF,MAAM,EAAE,IAAI;MACZE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*/
10
- sort: string[];
10
+ sort?: string[];
11
11
  /**
12
12
  * Fields we can sort by.
13
13
  */
14
14
  fields?: FieldPlugin[];
15
15
  }
16
- export declare const sortItems: <T extends unknown = any>(params: Params<T>) => T[];
16
+ export declare function sortItems<T = any>(params: Params<T>): T[];
17
17
  export {};
package/utils/sort.js CHANGED
@@ -1,27 +1,20 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
- exports.sortItems = void 0;
9
-
7
+ exports.sortItems = sortItems;
10
8
  var _orderBy = _interopRequireDefault(require("lodash/orderBy"));
11
-
12
9
  var _error = _interopRequireDefault(require("@webiny/error"));
13
-
14
10
  const extractSort = (sortBy, fields) => {
15
11
  const result = sortBy.split("_");
16
-
17
12
  if (result.length !== 2) {
18
13
  throw new _error.default("Problem in determining the sorting for the entry items.", "SORT_ERROR", {
19
14
  sortBy
20
15
  });
21
16
  }
22
-
23
17
  const [field, order] = result;
24
-
25
18
  if (!field) {
26
19
  throw new _error.default("Sorting field does not exist.", "SORTING_FIELD_ERROR", {
27
20
  field,
@@ -29,24 +22,20 @@ const extractSort = (sortBy, fields) => {
29
22
  fields
30
23
  });
31
24
  }
32
-
33
25
  const fieldPlugin = fields.find(f => f.getField() === field);
34
26
  const isSortable = fieldPlugin ? fieldPlugin.isSortable() : true;
35
-
36
27
  if (isSortable === false) {
37
28
  throw new _error.default(`Cannot sort by given field: "${field}".`, "UNSUPPORTED_SORT_ERROR", {
38
29
  fields,
39
30
  field
40
31
  });
41
32
  }
42
-
43
33
  return {
44
34
  field,
45
35
  reverse: order.toUpperCase() === "DESC"
46
36
  };
47
37
  };
48
-
49
- const sortItems = params => {
38
+ function sortItems(params) {
50
39
  const {
51
40
  items,
52
41
  sort: initialSort = [],
@@ -55,16 +44,13 @@ const sortItems = params => {
55
44
  /**
56
45
  * Skip sorting if nothing was passed to sort by or nothing to sort.
57
46
  */
58
-
59
47
  if (items.length <= 1 || Array.isArray(initialSort) === false || initialSort.length === 0) {
60
48
  return items;
61
49
  }
62
-
63
50
  const info = {
64
51
  sorters: [],
65
52
  orders: []
66
53
  };
67
-
68
54
  for (const sort of initialSort) {
69
55
  /**
70
56
  * Possibly empty array item was passed.
@@ -72,7 +58,6 @@ const sortItems = params => {
72
58
  if (!sort) {
73
59
  continue;
74
60
  }
75
-
76
61
  const {
77
62
  field,
78
63
  reverse
@@ -82,12 +67,8 @@ const sortItems = params => {
82
67
  info.sorters.push(path);
83
68
  info.orders.push(reverse === true ? "desc" : "asc");
84
69
  }
85
-
86
70
  if (info.sorters.length === 0) {
87
71
  return items;
88
72
  }
89
-
90
73
  return (0, _orderBy.default)(items, info.sorters, info.orders);
91
- };
92
-
93
- exports.sortItems = sortItems;
74
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"names":["extractSort","sortBy","fields","result","split","length","WebinyError","field","order","fieldPlugin","find","f","getField","isSortable","reverse","toUpperCase","sortItems","params","items","sort","initialSort","Array","isArray","info","sorters","orders","path","getPath","push","lodashOrderBy"],"sources":["sort.ts"],"sourcesContent":["import lodashOrderBy from \"lodash/orderBy\";\nimport WebinyError from \"@webiny/error\";\nimport { FieldPlugin } from \"~/plugins/definitions/FieldPlugin\";\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;AACA;AAaA,MAAMA,WAAW,GAAG,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,IAAIC,cAAW,CACjB,yDAAyD,EACzD,YAAY,EACZ;MACIL;IACJ,CAAC,CACJ;EACL;EACA,MAAM,CAACM,KAAK,EAAEC,KAAK,CAAC,GAAGL,MAAM;EAE7B,IAAI,CAACI,KAAK,EAAE;IACR,MAAM,IAAID,cAAW,CAAC,+BAA+B,EAAE,qBAAqB,EA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GAAGjB,WAAW,GAAGA,WAAW,CAACkB,OAAO,EAAE,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,CAACnB,MAAM,KAAK,CAAC,EAAE;IAC3B,OAAOa,KAAK;EAChB;EAEA,OAAO,IAAAW,gBAAa,EAACX,KAAK,EAAEK,IAAI,CAACC,OAAO,EAAED,IAAI,CAACE,MAAM,CAAC;AAC1D"}
package/utils/table.js CHANGED
@@ -1,14 +1,11 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.getTable = void 0;
9
-
10
8
  var _error = _interopRequireDefault(require("@webiny/error"));
11
-
12
9
  /**
13
10
  * Will be removed in favor of passing the table name directly to the storage operations.
14
11
  *
@@ -20,8 +17,6 @@ const getTable = context => {
20
17
  } else if (!context.db.table) {
21
18
  throw new _error.default("Missing table on context.db.", "TABLE_ERROR");
22
19
  }
23
-
24
20
  return context.db.table;
25
21
  };
26
-
27
22
  exports.getTable = getTable;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["getTable","context","db","WebinyError","table"],"sources":["table.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { DbContext } from \"@webiny/handler-db/types\";\n\n/**\n * Will be removed in favor of passing the table name directly to the storage operations.\n *\n * @deprecated\n */\nexport const getTable = <T extends DbContext>(context: T): string => {\n if (!context.db) {\n throw new WebinyError(\"Missing db on context.\", \"DB_ERROR\");\n } else if (!context.db.table) {\n throw new WebinyError(\"Missing table on context.db.\", \"TABLE_ERROR\");\n }\n return context.db.table;\n};\n"],"mappings":";;;;;;;AAAA;AAGA;AACA;AACA;AACA;AACA;AACO,MAAMA,QAAQ,GAAyBC,OAAU,IAAa;EACjE,IAAI,CAACA,OAAO,CAACC,EAAE,EAAE;IACb,MAAM,IAAIC,cAAW,CAAC,wBAAwB,EAAE,UAAU,CAAC;EAC/D,CAAC,MAAM,IAAI,CAACF,OAAO,CAACC,EAAE,CAACE,KAAK,EAAE;IAC1B,MAAM,IAAID,cAAW,CAAC,8BAA8B,EAAE,aAAa,CAAC;EACxE;EACA,OAAOF,OAAO,CAACC,EAAE,CAACE,KAAK;AAC3B,CAAC;AAAC"}
@@ -1,8 +0,0 @@
1
- import { DocumentClient } from "aws-sdk/clients/dynamodb";
2
- import { DbContext } from "@webiny/handler-db/types";
3
- /**
4
- * Will be removed in favor of directly passing the documentClient to the storage operations.
5
- *
6
- * @deprecated
7
- */
8
- export declare const getDocumentClient: <T extends DbContext>(context: T) => DocumentClient;
@@ -1,33 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.getDocumentClient = void 0;
9
-
10
- var _error = _interopRequireDefault(require("@webiny/error"));
11
-
12
- /**
13
- * Will be removed in favor of directly passing the documentClient to the storage operations.
14
- *
15
- * @deprecated
16
- */
17
- const getDocumentClient = context => {
18
- if (!context.db) {
19
- throw new _error.default("Missing db on context.", "DB_ERROR");
20
- } else if (!context.db.driver) {
21
- throw new _error.default(`Missing driver on the context.db property.`, "DRIVER_ERROR");
22
- }
23
-
24
- const driver = context.db.driver;
25
-
26
- if (!driver.documentClient) {
27
- throw new _error.default(`Missing documentClient on the context.db.driver property.`, "DOCUMENT_CLIENT_ERROR");
28
- }
29
-
30
- return driver.documentClient;
31
- };
32
-
33
- exports.getDocumentClient = getDocumentClient;