@webiny/api-headless-cms-ddb 0.0.0-mt-2 → 0.0.0-unstable.06b2ede40f

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 (168) hide show
  1. package/definitions/entry.d.ts +6 -4
  2. package/definitions/entry.js +111 -20
  3. package/definitions/entry.js.map +1 -0
  4. package/definitions/group.d.ts +6 -4
  5. package/definitions/group.js +8 -16
  6. package/definitions/group.js.map +1 -0
  7. package/definitions/model.d.ts +6 -4
  8. package/definitions/model.js +30 -16
  9. package/definitions/model.js.map +1 -0
  10. package/definitions/system.d.ts +6 -4
  11. package/definitions/system.js +8 -16
  12. package/definitions/system.js.map +1 -0
  13. package/definitions/table.d.ts +7 -6
  14. package/definitions/table.js +7 -6
  15. package/definitions/table.js.map +1 -0
  16. package/dynamoDb/index.d.ts +1 -1
  17. package/dynamoDb/index.js +9 -18
  18. package/dynamoDb/index.js.map +1 -0
  19. package/dynamoDb/path/locationFolderId.d.ts +2 -0
  20. package/dynamoDb/path/locationFolderId.js +43 -0
  21. package/dynamoDb/path/locationFolderId.js.map +1 -0
  22. package/dynamoDb/path/plainObject.d.ts +2 -3
  23. package/dynamoDb/path/plainObject.js +26 -24
  24. package/dynamoDb/path/plainObject.js.map +1 -0
  25. package/dynamoDb/storage/longText.d.ts +7 -4
  26. package/dynamoDb/storage/longText.js +74 -63
  27. package/dynamoDb/storage/longText.js.map +1 -0
  28. package/dynamoDb/storage/richText.d.ts +2 -8
  29. package/dynamoDb/storage/richText.js +49 -98
  30. package/dynamoDb/storage/richText.js.map +1 -0
  31. package/dynamoDb/transformValue/datetime.d.ts +5 -3
  32. package/dynamoDb/transformValue/datetime.js +29 -29
  33. package/dynamoDb/transformValue/datetime.js.map +1 -0
  34. package/index.d.ts +2 -1
  35. package/index.js +56 -54
  36. package/index.js.map +1 -0
  37. package/operations/entry/dataLoader/DataLoaderCache.d.ts +17 -0
  38. package/operations/entry/dataLoader/DataLoaderCache.js +41 -0
  39. package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -0
  40. package/operations/entry/dataLoader/constants.d.ts +1 -0
  41. package/operations/entry/dataLoader/constants.js +10 -0
  42. package/operations/entry/dataLoader/constants.js.map +1 -0
  43. package/operations/entry/dataLoader/createBatchScheduleFn.d.ts +8 -0
  44. package/operations/entry/dataLoader/createBatchScheduleFn.js +25 -0
  45. package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -0
  46. package/operations/entry/dataLoader/getAllEntryRevisions.d.ts +4 -0
  47. package/operations/entry/dataLoader/getAllEntryRevisions.js +45 -0
  48. package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -0
  49. package/operations/entry/dataLoader/getLatestRevisionByEntryId.d.ts +4 -0
  50. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +56 -0
  51. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -0
  52. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.d.ts +4 -0
  53. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +56 -0
  54. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -0
  55. package/operations/entry/dataLoader/getRevisionById.d.ts +4 -0
  56. package/operations/entry/dataLoader/getRevisionById.js +62 -0
  57. package/operations/entry/dataLoader/getRevisionById.js.map +1 -0
  58. package/operations/entry/dataLoader/index.d.ts +8 -0
  59. package/operations/entry/dataLoader/index.js +40 -0
  60. package/operations/entry/dataLoader/index.js.map +1 -0
  61. package/operations/entry/dataLoader/types.d.ts +6 -0
  62. package/operations/entry/dataLoader/types.js +7 -0
  63. package/operations/entry/dataLoader/types.js.map +1 -0
  64. package/operations/entry/dataLoaders.d.ts +18 -29
  65. package/operations/entry/dataLoaders.js +59 -246
  66. package/operations/entry/dataLoaders.js.map +1 -0
  67. package/operations/entry/filtering/createExpressions.d.ts +26 -0
  68. package/operations/entry/filtering/createExpressions.js +178 -0
  69. package/operations/entry/filtering/createExpressions.js.map +1 -0
  70. package/operations/entry/filtering/createFields.d.ts +16 -0
  71. package/operations/entry/filtering/createFields.js +108 -0
  72. package/operations/entry/filtering/createFields.js.map +1 -0
  73. package/operations/entry/filtering/extractSort.d.ts +17 -0
  74. package/operations/entry/filtering/extractSort.js +69 -0
  75. package/operations/entry/filtering/extractSort.js.map +1 -0
  76. package/operations/entry/filtering/filter.d.ts +15 -0
  77. package/operations/entry/filtering/filter.js +158 -0
  78. package/operations/entry/filtering/filter.js.map +1 -0
  79. package/operations/entry/filtering/fullTextSearch.d.ts +14 -0
  80. package/operations/entry/filtering/fullTextSearch.js +50 -0
  81. package/operations/entry/filtering/fullTextSearch.js.map +1 -0
  82. package/operations/entry/filtering/getValue.d.ts +5 -0
  83. package/operations/entry/filtering/getValue.js +66 -0
  84. package/operations/entry/filtering/getValue.js.map +1 -0
  85. package/operations/entry/filtering/index.d.ts +2 -0
  86. package/operations/entry/filtering/index.js +21 -0
  87. package/operations/entry/filtering/index.js.map +1 -0
  88. package/operations/entry/filtering/mapPlugins.d.ts +8 -0
  89. package/operations/entry/filtering/mapPlugins.js +33 -0
  90. package/operations/entry/filtering/mapPlugins.js.map +1 -0
  91. package/operations/entry/filtering/plugins/defaultFilterCreate.d.ts +2 -0
  92. package/operations/entry/filtering/plugins/defaultFilterCreate.js +45 -0
  93. package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -0
  94. package/operations/entry/filtering/plugins/index.d.ts +1 -0
  95. package/operations/entry/filtering/plugins/index.js +16 -0
  96. package/operations/entry/filtering/plugins/index.js.map +1 -0
  97. package/operations/entry/filtering/plugins/objectFilterCreate.d.ts +2 -0
  98. package/operations/entry/filtering/plugins/objectFilterCreate.js +90 -0
  99. package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -0
  100. package/operations/entry/filtering/plugins/refFilterCreate.d.ts +3 -0
  101. package/operations/entry/filtering/plugins/refFilterCreate.js +80 -0
  102. package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -0
  103. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.d.ts +2 -0
  104. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js +65 -0
  105. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js.map +1 -0
  106. package/operations/entry/filtering/sort.d.ts +12 -0
  107. package/operations/entry/filtering/sort.js +71 -0
  108. package/operations/entry/filtering/sort.js.map +1 -0
  109. package/operations/entry/filtering/systemFields.d.ts +4 -0
  110. package/operations/entry/filtering/systemFields.js +90 -0
  111. package/operations/entry/filtering/systemFields.js.map +1 -0
  112. package/operations/entry/filtering/transform.d.ts +6 -0
  113. package/operations/entry/filtering/transform.js +18 -0
  114. package/operations/entry/filtering/transform.js.map +1 -0
  115. package/operations/entry/filtering/types.d.ts +40 -0
  116. package/operations/entry/filtering/types.js +7 -0
  117. package/operations/entry/filtering/types.js.map +1 -0
  118. package/operations/entry/filtering/values.d.ts +2 -0
  119. package/operations/entry/filtering/values.js +24 -0
  120. package/operations/entry/filtering/values.js.map +1 -0
  121. package/operations/entry/filtering/where.d.ts +5 -0
  122. package/operations/entry/filtering/where.js +35 -0
  123. package/operations/entry/filtering/where.js.map +1 -0
  124. package/operations/entry/index.d.ts +5 -5
  125. package/operations/entry/index.js +920 -437
  126. package/operations/entry/index.js.map +1 -0
  127. package/operations/entry/keys.js +9 -14
  128. package/operations/entry/keys.js.map +1 -0
  129. package/operations/group/index.d.ts +6 -5
  130. package/operations/group/index.js +35 -59
  131. package/operations/group/index.js.map +1 -0
  132. package/operations/model/index.d.ts +5 -4
  133. package/operations/model/index.js +35 -46
  134. package/operations/model/index.js.map +1 -0
  135. package/operations/system/index.d.ts +5 -4
  136. package/operations/system/index.js +20 -31
  137. package/operations/system/index.js.map +1 -0
  138. package/package.json +23 -29
  139. package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +23 -0
  140. package/plugins/CmsEntryFieldFilterPathPlugin.js +48 -0
  141. package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -0
  142. package/plugins/CmsEntryFieldFilterPlugin.d.ts +43 -0
  143. package/plugins/CmsEntryFieldFilterPlugin.js +27 -0
  144. package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -0
  145. package/plugins/CmsEntryFieldSortingPlugin.d.ts +42 -0
  146. package/plugins/CmsEntryFieldSortingPlugin.js +27 -0
  147. package/plugins/CmsEntryFieldSortingPlugin.js.map +1 -0
  148. package/plugins/CmsFieldFilterValueTransformPlugin.d.ts +11 -0
  149. package/plugins/CmsFieldFilterValueTransformPlugin.js +23 -0
  150. package/plugins/CmsFieldFilterValueTransformPlugin.js.map +1 -0
  151. package/plugins/index.d.ts +4 -0
  152. package/plugins/index.js +51 -0
  153. package/plugins/index.js.map +1 -0
  154. package/types.d.ts +21 -45
  155. package/types.js +5 -6
  156. package/types.js.map +1 -0
  157. package/definitions/settings.d.ts +0 -8
  158. package/definitions/settings.js +0 -62
  159. package/dynamoDb/path/ref.d.ts +0 -3
  160. package/dynamoDb/path/ref.js +0 -27
  161. package/dynamoDb/storage/date.d.ts +0 -3
  162. package/dynamoDb/storage/date.js +0 -65
  163. package/operations/entry/systemFields.d.ts +0 -2
  164. package/operations/entry/systemFields.js +0 -50
  165. package/operations/entry/utils.d.ts +0 -31
  166. package/operations/entry/utils.js +0 -406
  167. package/operations/settings/index.d.ts +0 -6
  168. package/operations/settings/index.js +0 -141
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _exportNames = {
7
+ getDataLoaderFactory: true
8
+ };
9
+ exports.getDataLoaderFactory = void 0;
10
+ var _getAllEntryRevisions = require("./getAllEntryRevisions");
11
+ var _getLatestRevisionByEntryId = require("./getLatestRevisionByEntryId");
12
+ var _getPublishedRevisionByEntryId = require("./getPublishedRevisionByEntryId");
13
+ var _getRevisionById = require("./getRevisionById");
14
+ var _DataLoaderCache = require("./DataLoaderCache");
15
+ Object.keys(_DataLoaderCache).forEach(function (key) {
16
+ if (key === "default" || key === "__esModule") return;
17
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
18
+ if (key in exports && exports[key] === _DataLoaderCache[key]) return;
19
+ Object.defineProperty(exports, key, {
20
+ enumerable: true,
21
+ get: function () {
22
+ return _DataLoaderCache[key];
23
+ }
24
+ });
25
+ });
26
+ const dataLoaders = {
27
+ getAllEntryRevisions: _getAllEntryRevisions.createGetAllEntryRevisions,
28
+ getLatestRevisionByEntryId: _getLatestRevisionByEntryId.createGetLatestRevisionByEntryId,
29
+ getPublishedRevisionByEntryId: _getPublishedRevisionByEntryId.createGetPublishedRevisionByEntryId,
30
+ getRevisionById: _getRevisionById.createGetRevisionById
31
+ };
32
+ const getDataLoaderFactory = name => {
33
+ if (!dataLoaders[name]) {
34
+ throw new Error(`Missing data loader "${name}".`);
35
+ }
36
+ return dataLoaders[name];
37
+ };
38
+ exports.getDataLoaderFactory = getDataLoaderFactory;
39
+
40
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_getAllEntryRevisions","require","_getLatestRevisionByEntryId","_getPublishedRevisionByEntryId","_getRevisionById","_DataLoaderCache","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","dataLoaders","getAllEntryRevisions","createGetAllEntryRevisions","getLatestRevisionByEntryId","createGetLatestRevisionByEntryId","getPublishedRevisionByEntryId","createGetPublishedRevisionByEntryId","getRevisionById","createGetRevisionById","getDataLoaderFactory","name","Error"],"sources":["index.ts"],"sourcesContent":["import type DataLoader from \"dataloader\";\nimport type { DataLoaderParams } from \"./types\";\nimport { createGetAllEntryRevisions } from \"./getAllEntryRevisions\";\nimport { createGetLatestRevisionByEntryId } from \"./getLatestRevisionByEntryId\";\nimport { createGetPublishedRevisionByEntryId } from \"./getPublishedRevisionByEntryId\";\nimport { createGetRevisionById } from \"./getRevisionById\";\n\nexport * from \"./DataLoaderCache\";\n\ninterface Callable {\n (params: DataLoaderParams): DataLoader<any, any>;\n}\n\nconst dataLoaders: Record<string, Callable> = {\n getAllEntryRevisions: createGetAllEntryRevisions,\n getLatestRevisionByEntryId: createGetLatestRevisionByEntryId,\n getPublishedRevisionByEntryId: createGetPublishedRevisionByEntryId,\n getRevisionById: createGetRevisionById\n};\n\nexport type DataLoaders =\n | \"getAllEntryRevisions\"\n | \"getRevisionById\"\n | \"getPublishedRevisionByEntryId\"\n | \"getLatestRevisionByEntryId\";\n\nexport const getDataLoaderFactory = (name: string) => {\n if (!dataLoaders[name]) {\n throw new Error(`Missing data loader \"${name}\".`);\n }\n return dataLoaders[name];\n};\n"],"mappings":";;;;;;;;;AAEA,IAAAA,qBAAA,GAAAC,OAAA;AACA,IAAAC,2BAAA,GAAAD,OAAA;AACA,IAAAE,8BAAA,GAAAF,OAAA;AACA,IAAAG,gBAAA,GAAAH,OAAA;AAEA,IAAAI,gBAAA,GAAAJ,OAAA;AAAAK,MAAA,CAAAC,IAAA,CAAAF,gBAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,gBAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,gBAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AAMA,MAAMS,WAAqC,GAAG;EAC1CC,oBAAoB,EAAEC,gDAA0B;EAChDC,0BAA0B,EAAEC,4DAAgC;EAC5DC,6BAA6B,EAAEC,kEAAmC;EAClEC,eAAe,EAAEC;AACrB,CAAC;AAQM,MAAMC,oBAAoB,GAAIC,IAAY,IAAK;EAClD,IAAI,CAACV,WAAW,CAACU,IAAI,CAAC,EAAE;IACpB,MAAM,IAAIC,KAAK,CAAC,wBAAwBD,IAAI,IAAI,CAAC;EACrD;EACA,OAAOV,WAAW,CAACU,IAAI,CAAC;AAC5B,CAAC;AAACd,OAAA,CAAAa,oBAAA,GAAAA,oBAAA","ignoreList":[]}
@@ -0,0 +1,6 @@
1
+ import type { Entity } from "@webiny/db-dynamodb/toolbox";
2
+ export interface DataLoaderParams {
3
+ entity: Entity<any>;
4
+ tenant: string;
5
+ locale: string;
6
+ }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { Entity } from \"@webiny/db-dynamodb/toolbox\";\n\nexport interface DataLoaderParams {\n entity: Entity<any>;\n tenant: string;\n locale: string;\n}\n"],"mappings":"","ignoreList":[]}
@@ -1,38 +1,27 @@
1
- import { CmsEntry, CmsModel } from "@webiny/api-headless-cms/types";
2
- import { Entity } from "dynamodb-toolbox";
3
- export interface GetAllEntryRevisionsParams {
1
+ import type { CmsModel, CmsStorageEntry } from "@webiny/api-headless-cms/types";
2
+ import type { Entity } from "@webiny/db-dynamodb/toolbox";
3
+ import type { DataLoadersHandlerInterface, DataLoadersHandlerInterfaceClearAllParams } from "../../types";
4
+ interface DataLoaderParams {
5
+ model: Pick<CmsModel, "tenant" | "locale" | "modelId">;
4
6
  ids: readonly string[];
5
- model: CmsModel;
6
7
  }
7
- export interface GetRevisionByIdParams {
8
- ids: readonly string[];
9
- model: CmsModel;
10
- }
11
- export interface GetPublishedRevisionByEntryIdParams {
12
- ids: readonly string[];
13
- model: CmsModel;
14
- }
15
- export interface GetLatestRevisionByEntryIdParams {
16
- ids: readonly string[];
17
- model: CmsModel;
18
- }
19
- interface ClearLoaderParams {
20
- model: CmsModel;
21
- entry?: CmsEntry;
22
- }
23
- export interface Params {
8
+ interface DataLoadersHandlerParams {
24
9
  entity: Entity<any>;
25
10
  }
26
- export declare class DataLoadersHandler {
27
- private readonly loaders;
11
+ export declare class DataLoadersHandler implements DataLoadersHandlerInterface {
28
12
  private readonly entity;
29
- constructor(params: any);
30
- getAllEntryRevisions(params: GetAllEntryRevisionsParams): Promise<CmsEntry[]>;
31
- getRevisionById(params: GetRevisionByIdParams): Promise<CmsEntry[]>;
32
- getPublishedRevisionByEntryId(params: GetPublishedRevisionByEntryIdParams): Promise<CmsEntry[]>;
33
- getLatestRevisionByEntryId(params: GetLatestRevisionByEntryIdParams): Promise<CmsEntry[]>;
13
+ private readonly cache;
14
+ constructor(params: DataLoadersHandlerParams);
15
+ getAllEntryRevisions(params: DataLoaderParams): Promise<CmsStorageEntry[]>;
16
+ getRevisionById(params: DataLoaderParams): Promise<CmsStorageEntry[]>;
17
+ getPublishedRevisionByEntryId(params: DataLoaderParams): Promise<CmsStorageEntry[]>;
18
+ getLatestRevisionByEntryId(params: DataLoaderParams): Promise<CmsStorageEntry[]>;
19
+ /**
20
+ * TODO @ts-refactor
21
+ * Maybe pass on the generics to DataLoader definition?
22
+ */
34
23
  private getLoader;
35
24
  private loadMany;
36
- clearAll(params: Omit<ClearLoaderParams, "entry">): void;
25
+ clearAll(params?: DataLoadersHandlerInterfaceClearAllParams): void;
37
26
  }
38
27
  export {};
@@ -1,303 +1,116 @@
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.DataLoadersHandler = void 0;
9
-
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
- var _dataloader = _interopRequireDefault(require("dataloader"));
13
-
14
8
  var _error = _interopRequireDefault(require("@webiny/error"));
15
-
16
- var _query = require("@webiny/db-dynamodb/utils/query");
17
-
18
- var _keys = require("./keys");
19
-
20
- var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
21
-
9
+ var _DataLoaderCache = require("./dataLoader/DataLoaderCache");
10
+ var _dataLoader = require("./dataLoader");
22
11
  var _utils = require("@webiny/utils");
23
-
24
- var _batchRead = require("@webiny/db-dynamodb/utils/batchRead");
25
-
26
- 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; }
27
-
28
- 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; }
29
-
30
- const getAllEntryRevisions = params => {
31
- const {
32
- entity,
33
- model
34
- } = params;
35
- const {
36
- tenant,
37
- locale
38
- } = model;
39
- return new _dataloader.default(async ids => {
40
- const results = [];
41
-
42
- for (const id of ids) {
43
- const queryAllParams = {
44
- entity,
45
- partitionKey: (0, _keys.createPartitionKey)({
46
- tenant,
47
- locale,
48
- id
49
- }),
50
- options: {
51
- beginsWith: "REV#"
52
- }
53
- };
54
- const items = await (0, _query.queryAll)(queryAllParams);
55
- const entries = (0, _cleanup.cleanupItems)(entity, items);
56
- results.push(entries);
57
- }
58
-
59
- return results;
60
- });
61
- };
62
-
63
- const getRevisionById = params => {
64
- const {
65
- entity,
66
- model
67
- } = params;
68
- const {
69
- locale,
70
- tenant
71
- } = model;
72
- return new _dataloader.default(async ids => {
73
- const queries = ids.reduce((collection, id) => {
74
- const partitionKey = (0, _keys.createPartitionKey)({
75
- tenant,
76
- locale,
77
- id
78
- });
79
- const {
80
- version
81
- } = (0, _utils.parseIdentifier)(id);
82
- const sortKey = (0, _keys.createRevisionSortKey)({
83
- version
84
- });
85
- const keys = `${partitionKey}__${sortKey}`;
86
-
87
- if (collection[keys]) {
88
- return collection;
89
- }
90
-
91
- collection[keys] = entity.getBatch({
92
- PK: partitionKey,
93
- SK: sortKey
94
- });
95
- return collection;
96
- }, {});
97
- const records = await (0, _batchRead.batchReadAll)({
98
- table: entity.table,
99
- items: Object.values(queries)
100
- });
101
- const items = (0, _cleanup.cleanupItems)(entity, records);
102
- return ids.map(id => {
103
- return items.filter(item => {
104
- return id === item.id;
105
- });
106
- });
107
- });
108
- };
109
-
110
- const getPublishedRevisionByEntryId = params => {
111
- const {
112
- entity,
113
- model
114
- } = params;
115
- const {
116
- locale,
117
- tenant
118
- } = model;
119
- const publishedKey = (0, _keys.createPublishedSortKey)();
120
- return new _dataloader.default(async ids => {
121
- const queries = ids.reduce((collection, id) => {
122
- const partitionKey = (0, _keys.createPartitionKey)({
123
- tenant,
124
- locale,
125
- id
126
- });
127
-
128
- if (collection[partitionKey]) {
129
- return collection;
130
- }
131
-
132
- collection[partitionKey] = entity.getBatch({
133
- PK: partitionKey,
134
- SK: publishedKey
135
- });
136
- return collection;
137
- }, {});
138
- const records = await (0, _batchRead.batchReadAll)({
139
- table: entity.table,
140
- items: Object.values(queries)
141
- });
142
- const items = (0, _cleanup.cleanupItems)(entity, records);
143
- return ids.map(id => {
144
- const {
145
- id: entryId
146
- } = (0, _utils.parseIdentifier)(id);
147
- return items.filter(item => {
148
- return entryId === item.entryId;
149
- });
150
- });
151
- });
152
- };
153
-
154
- const getLatestRevisionByEntryId = params => {
155
- const {
156
- entity,
157
- model
158
- } = params;
159
- const {
160
- locale,
161
- tenant
162
- } = model;
163
- const latestKey = (0, _keys.createLatestSortKey)();
164
- return new _dataloader.default(async ids => {
165
- const queries = ids.reduce((collection, id) => {
166
- const partitionKey = (0, _keys.createPartitionKey)({
167
- tenant,
168
- locale,
169
- id
170
- });
171
-
172
- if (collection[partitionKey]) {
173
- return collection;
174
- }
175
-
176
- collection[partitionKey] = entity.getBatch({
177
- PK: partitionKey,
178
- SK: latestKey
179
- });
180
- return collection;
181
- }, {});
182
- const records = await (0, _batchRead.batchReadAll)({
183
- table: entity.table,
184
- items: Object.values(queries)
185
- });
186
- const items = (0, _cleanup.cleanupItems)(entity, records);
187
- return ids.map(id => {
188
- const {
189
- id: entryId
190
- } = (0, _utils.parseIdentifier)(id);
191
- return items.filter(item => {
192
- return entryId === item.entryId;
193
- });
194
- });
195
- });
196
- };
197
-
198
- const dataLoaders = {
199
- getAllEntryRevisions,
200
- getRevisionById,
201
- getPublishedRevisionByEntryId,
202
- getLatestRevisionByEntryId
203
- };
204
- const loaderNames = Object.keys(dataLoaders);
205
-
206
12
  class DataLoadersHandler {
13
+ cache = new _DataLoaderCache.DataLoaderCache();
207
14
  constructor(params) {
208
- (0, _defineProperty2.default)(this, "loaders", new Map());
209
- (0, _defineProperty2.default)(this, "entity", void 0);
210
15
  this.entity = params.entity;
211
16
  }
212
-
213
17
  async getAllEntryRevisions(params) {
214
- return await this.loadMany("getAllEntryRevisions", params, params.ids);
18
+ const ids = params.ids.map(id => {
19
+ const {
20
+ id: entryId
21
+ } = (0, _utils.parseIdentifier)(id);
22
+ return entryId;
23
+ });
24
+ return await this.loadMany("getAllEntryRevisions", params, ids);
215
25
  }
216
-
217
26
  async getRevisionById(params) {
218
27
  return await this.loadMany("getRevisionById", params, params.ids);
219
28
  }
220
-
221
29
  async getPublishedRevisionByEntryId(params) {
222
- return await this.loadMany("getPublishedRevisionByEntryId", params, params.ids);
30
+ const ids = params.ids.map(id => {
31
+ const {
32
+ id: entryId
33
+ } = (0, _utils.parseIdentifier)(id);
34
+ return entryId;
35
+ });
36
+ return await this.loadMany("getPublishedRevisionByEntryId", params, ids);
223
37
  }
224
-
225
38
  async getLatestRevisionByEntryId(params) {
226
- return await this.loadMany("getLatestRevisionByEntryId", params, params.ids);
39
+ const ids = params.ids.map(id => {
40
+ const {
41
+ id: entryId
42
+ } = (0, _utils.parseIdentifier)(id);
43
+ return entryId;
44
+ });
45
+ return await this.loadMany("getLatestRevisionByEntryId", params, ids);
227
46
  }
228
47
 
48
+ /**
49
+ * TODO @ts-refactor
50
+ * Maybe pass on the generics to DataLoader definition?
51
+ */
229
52
  getLoader(name, params) {
230
- if (!dataLoaders[name]) {
231
- throw new _error.default("Unknown data loader.", "UNKNOWN_DATA_LOADER", {
232
- name
233
- });
234
- }
235
-
236
53
  const {
237
54
  model
238
55
  } = params;
239
- const {
240
- tenant,
241
- locale
242
- } = model;
243
- const loaderKey = `${name}-${tenant}-${locale}-${model.modelId}`;
244
-
245
- if (!this.loaders.has(loaderKey)) {
246
- this.loaders.set(loaderKey, dataLoaders[name](_objectSpread(_objectSpread({}, params), {}, {
247
- entity: this.entity
248
- })));
56
+ const cacheParams = {
57
+ tenant: model.tenant,
58
+ locale: model.locale,
59
+ name
60
+ };
61
+ let loader = this.cache.getDataLoader(cacheParams);
62
+ if (loader) {
63
+ return loader;
249
64
  }
250
-
251
- return this.loaders.get(loaderKey);
65
+ const factory = (0, _dataLoader.getDataLoaderFactory)(name);
66
+ loader = factory({
67
+ entity: this.entity,
68
+ tenant: model.tenant,
69
+ locale: model.locale
70
+ });
71
+ this.cache.setDataLoader(cacheParams, loader);
72
+ return loader;
252
73
  }
253
-
254
74
  async loadMany(loader, params, ids) {
255
- let results;
256
-
75
+ let results = [];
257
76
  try {
258
77
  results = await this.getLoader(loader, params).loadMany(ids);
259
-
260
78
  if (Array.isArray(results) === true) {
261
79
  return results.reduce((acc, res) => {
262
80
  if (Array.isArray(res) === false) {
263
81
  if (res && res.message) {
264
- throw new _error.default(res.message, res.code, _objectSpread(_objectSpread({}, res), {}, {
82
+ throw new _error.default(res.message, res.code, {
83
+ ...res,
265
84
  data: JSON.stringify(res.data || {})
266
- }));
85
+ });
267
86
  }
268
-
269
- throw new _error.default("Result from the data loader must be an array of arrays which contain requested items.", "DATA_LOADER_RESULTS_ERROR", _objectSpread(_objectSpread({}, params), {}, {
87
+ throw new _error.default("Result from the data loader must be an array of arrays which contain requested items.", "DATA_LOADER_RESULTS_ERROR", {
88
+ ...params,
270
89
  loader
271
- }));
90
+ });
272
91
  }
273
-
274
92
  acc.push(...res);
275
93
  return acc;
276
94
  }, []);
277
95
  }
278
96
  } catch (ex) {
279
- throw new _error.default(ex.message || "Data loader error.", ex.code || "DATA_LOADER_ERROR", _objectSpread(_objectSpread({
280
- error: ex
281
- }, params), {}, {
97
+ throw new _error.default(ex.message || "Data loader error.", ex.code || "DATA_LOADER_ERROR", {
98
+ error: ex,
99
+ ...params,
282
100
  loader,
283
101
  ids
284
- }));
102
+ });
285
103
  }
286
-
287
104
  throw new _error.default(`Data loader did not return array of items or empty array.`, "INVALID_DATA_LOADER_RESULT", {
288
105
  loader,
289
106
  ids,
290
107
  results
291
108
  });
292
109
  }
293
-
294
110
  clearAll(params) {
295
- for (const name of loaderNames) {
296
- const loader = this.getLoader(name, params);
297
- loader.clearAll();
298
- }
111
+ this.cache.clearAll(params?.model);
299
112
  }
300
-
301
113
  }
114
+ exports.DataLoadersHandler = DataLoadersHandler;
302
115
 
303
- exports.DataLoadersHandler = DataLoadersHandler;
116
+ //# sourceMappingURL=dataLoaders.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_error","_interopRequireDefault","require","_DataLoaderCache","_dataLoader","_utils","DataLoadersHandler","cache","DataLoaderCache","constructor","params","entity","getAllEntryRevisions","ids","map","id","entryId","parseIdentifier","loadMany","getRevisionById","getPublishedRevisionByEntryId","getLatestRevisionByEntryId","getLoader","name","model","cacheParams","tenant","locale","loader","getDataLoader","factory","getDataLoaderFactory","setDataLoader","results","Array","isArray","reduce","acc","res","message","WebinyError","code","data","JSON","stringify","push","ex","error","clearAll","exports"],"sources":["dataLoaders.ts"],"sourcesContent":["import type DataLoader from \"dataloader\";\nimport WebinyError from \"@webiny/error\";\nimport type { CmsModel, CmsStorageEntry } from \"@webiny/api-headless-cms/types\";\nimport type { CacheKeyParams } from \"~/operations/entry/dataLoader/DataLoaderCache\";\nimport { DataLoaderCache } from \"~/operations/entry/dataLoader/DataLoaderCache\";\nimport type { Entity } from \"@webiny/db-dynamodb/toolbox\";\nimport type { DataLoaders } from \"~/operations/entry/dataLoader\";\nimport { getDataLoaderFactory } from \"~/operations/entry/dataLoader\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport type {\n DataLoadersHandlerInterface,\n DataLoadersHandlerInterfaceClearAllParams\n} from \"~/types\";\n\ninterface DataLoaderParams {\n model: Pick<CmsModel, \"tenant\" | \"locale\" | \"modelId\">;\n ids: readonly string[];\n}\n\ninterface GetLoaderParams {\n model: Pick<CmsModel, \"tenant\" | \"locale\" | \"modelId\">;\n}\n\ninterface DataLoadersHandlerParams {\n entity: Entity<any>;\n}\n\nexport class DataLoadersHandler implements DataLoadersHandlerInterface {\n private readonly entity: Entity<any>;\n private readonly cache: DataLoaderCache = new DataLoaderCache();\n\n public constructor(params: DataLoadersHandlerParams) {\n this.entity = params.entity;\n }\n\n public async getAllEntryRevisions(params: DataLoaderParams): Promise<CmsStorageEntry[]> {\n const ids = params.ids.map(id => {\n const { id: entryId } = parseIdentifier(id);\n return entryId;\n });\n return await this.loadMany(\"getAllEntryRevisions\", params, ids);\n }\n\n public async getRevisionById(params: DataLoaderParams): Promise<CmsStorageEntry[]> {\n return await this.loadMany(\"getRevisionById\", params, params.ids);\n }\n\n public async getPublishedRevisionByEntryId(\n params: DataLoaderParams\n ): Promise<CmsStorageEntry[]> {\n const ids = params.ids.map(id => {\n const { id: entryId } = parseIdentifier(id);\n return entryId;\n });\n return await this.loadMany(\"getPublishedRevisionByEntryId\", params, ids);\n }\n\n public async getLatestRevisionByEntryId(params: DataLoaderParams): Promise<CmsStorageEntry[]> {\n const ids = params.ids.map(id => {\n const { id: entryId } = parseIdentifier(id);\n return entryId;\n });\n return await this.loadMany(\"getLatestRevisionByEntryId\", params, ids);\n }\n\n /**\n * TODO @ts-refactor\n * Maybe pass on the generics to DataLoader definition?\n */\n private getLoader(name: DataLoaders, params: GetLoaderParams): DataLoader<any, any> {\n const { model } = params;\n const cacheParams: CacheKeyParams = {\n tenant: model.tenant,\n locale: model.locale,\n name\n };\n let loader = this.cache.getDataLoader(cacheParams);\n if (loader) {\n return loader;\n }\n const factory = getDataLoaderFactory(name);\n loader = factory({\n entity: this.entity,\n tenant: model.tenant,\n locale: model.locale\n });\n this.cache.setDataLoader(cacheParams, loader);\n return loader;\n }\n\n private async loadMany(\n loader: DataLoaders,\n params: GetLoaderParams,\n ids: readonly string[]\n ): Promise<CmsStorageEntry[]> {\n let results: any[] = [];\n try {\n results = await this.getLoader(loader, params).loadMany(ids);\n if (Array.isArray(results) === true) {\n return results.reduce((acc, res) => {\n if (Array.isArray(res) === false) {\n if (res && res.message) {\n throw new WebinyError(res.message, res.code, {\n ...res,\n data: JSON.stringify(res.data || {})\n });\n }\n throw new WebinyError(\n \"Result from the data loader must be an array of arrays which contain requested items.\",\n \"DATA_LOADER_RESULTS_ERROR\",\n {\n ...params,\n loader\n }\n );\n }\n acc.push(...res);\n return acc;\n }, []);\n }\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Data loader error.\",\n ex.code || \"DATA_LOADER_ERROR\",\n {\n error: ex,\n ...params,\n loader,\n ids\n }\n );\n }\n throw new WebinyError(\n `Data loader did not return array of items or empty array.`,\n \"INVALID_DATA_LOADER_RESULT\",\n {\n loader,\n ids,\n results\n }\n );\n }\n\n public clearAll(params?: DataLoadersHandlerInterfaceClearAllParams): void {\n this.cache.clearAll(params?.model);\n }\n}\n"],"mappings":";;;;;;;AACA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAGA,IAAAC,gBAAA,GAAAD,OAAA;AAGA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAmBO,MAAMI,kBAAkB,CAAwC;EAElDC,KAAK,GAAoB,IAAIC,gCAA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IAAI,EAAE;gBACzC,GAAGH,GAAG;gBACNI,IAAI,EAAEC,IAAI,CAACC,SAAS,CAACN,GAAG,CAACI,IAAI,IAAI,CAAC,CAAC;cACvC,CAAC,CAAC;YACN;YACA,MAAM,IAAIF,cAAW,CACjB,uFAAuF,EACvF,2BAA2B,EAC3B;cACI,GAAG9B,MAAM;cACTkB;YACJ,CACJ,CAAC;UACL;UACAS,GAAG,CAACQ,IAAI,CAAC,GAAGP,GAAG,CAAC;UAChB,OAAOD,GAAG;QACd,CAAC,EAAE,EAAE,CAAC;MACV;IACJ,CAAC,CAAC,OAAOS,EAAE,EAAE;MACT,MAAM,IAAIN,cAAW,CACjBM,EAAE,CAACP,OAAO,IAAI,oBAAoB,EAClCO,EAAE,CAACL,IAAI,IAAI,mBAAmB,EAC9B;QACIM,KAAK,EAAED,EAAE;QACT,GAAGpC,MAAM;QACTkB,MAAM;QACNf;MACJ,CACJ,CAAC;IACL;IACA,MAAM,IAAI2B,cAAW,CACjB,2DAA2D,EAC3D,4BAA4B,EAC5B;MACIZ,MAAM;MACNf,GAAG;MACHoB;IACJ,CACJ,CAAC;EACL;EAEOe,QAAQA,CAACtC,MAAkD,EAAQ;IACtE,IAAI,CAACH,KAAK,CAACyC,QAAQ,CAACtC,MAAM,EAAEc,KAAK,CAAC;EACtC;AACJ;AAACyB,OAAA,CAAA3C,kBAAA,GAAAA,kBAAA","ignoreList":[]}
@@ -0,0 +1,26 @@
1
+ import type { CmsEntryListWhere } from "@webiny/api-headless-cms/types";
2
+ import { ValueFilterPlugin } from "@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin";
3
+ import type { PluginsContainer } from "@webiny/plugins";
4
+ import type { Field } from "./types";
5
+ interface Params {
6
+ plugins: PluginsContainer;
7
+ where: Partial<CmsEntryListWhere>;
8
+ fields: Record<string, Field>;
9
+ }
10
+ export type ExpressionCondition = "AND" | "OR";
11
+ export interface Expression {
12
+ expressions: Expression[];
13
+ filters: Filter[];
14
+ condition: ExpressionCondition;
15
+ }
16
+ export interface Filter {
17
+ field: Field;
18
+ path: string;
19
+ fieldPathId: string;
20
+ plugin: ValueFilterPlugin;
21
+ negate: boolean;
22
+ compareValue: any;
23
+ transformValue: <I = any, O = any>(value: I) => O;
24
+ }
25
+ export declare const createExpressions: (params: Params) => Expression;
26
+ export {};