@webiny/api-headless-cms-ddb 0.0.0-mt-2 → 0.0.0-unstable.085ff6572f

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 +2 -1
  2. package/definitions/entry.js +12 -12
  3. package/definitions/entry.js.map +1 -0
  4. package/definitions/group.d.ts +2 -1
  5. package/definitions/group.js +3 -12
  6. package/definitions/group.js.map +1 -0
  7. package/definitions/model.d.ts +2 -1
  8. package/definitions/model.js +25 -12
  9. package/definitions/model.js.map +1 -0
  10. package/definitions/settings.d.ts +2 -1
  11. package/definitions/settings.js +3 -12
  12. package/definitions/settings.js.map +1 -0
  13. package/definitions/system.d.ts +2 -1
  14. package/definitions/system.js +3 -12
  15. package/definitions/system.js.map +1 -0
  16. package/definitions/table.d.ts +2 -1
  17. package/definitions/table.js +0 -3
  18. package/definitions/table.js.map +1 -0
  19. package/dynamoDb/index.d.ts +1 -1
  20. package/dynamoDb/index.js +7 -17
  21. package/dynamoDb/index.js.map +1 -0
  22. package/dynamoDb/path/locationFolderId.d.ts +2 -0
  23. package/dynamoDb/path/locationFolderId.js +41 -0
  24. package/dynamoDb/path/locationFolderId.js.map +1 -0
  25. package/dynamoDb/path/plainObject.d.ts +2 -3
  26. package/dynamoDb/path/plainObject.js +25 -25
  27. package/dynamoDb/path/plainObject.js.map +1 -0
  28. package/dynamoDb/storage/date.d.ts +3 -3
  29. package/dynamoDb/storage/date.js +71 -54
  30. package/dynamoDb/storage/date.js.map +1 -0
  31. package/dynamoDb/storage/longText.d.ts +7 -4
  32. package/dynamoDb/storage/longText.js +72 -64
  33. package/dynamoDb/storage/longText.js.map +1 -0
  34. package/dynamoDb/storage/richText.d.ts +2 -8
  35. package/dynamoDb/storage/richText.js +62 -77
  36. package/dynamoDb/storage/richText.js.map +1 -0
  37. package/dynamoDb/transformValue/datetime.d.ts +4 -2
  38. package/dynamoDb/transformValue/datetime.js +28 -30
  39. package/dynamoDb/transformValue/datetime.js.map +1 -0
  40. package/index.d.ts +1 -0
  41. package/index.js +54 -45
  42. package/index.js.map +1 -0
  43. package/operations/entry/dataLoader/DataLoaderCache.d.ts +17 -0
  44. package/operations/entry/dataLoader/DataLoaderCache.js +43 -0
  45. package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -0
  46. package/operations/entry/dataLoader/constants.d.ts +1 -0
  47. package/operations/entry/dataLoader/constants.js +9 -0
  48. package/operations/entry/dataLoader/constants.js.map +1 -0
  49. package/operations/entry/dataLoader/createBatchScheduleFn.d.ts +8 -0
  50. package/operations/entry/dataLoader/createBatchScheduleFn.js +23 -0
  51. package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -0
  52. package/operations/entry/dataLoader/getAllEntryRevisions.d.ts +4 -0
  53. package/operations/entry/dataLoader/getAllEntryRevisions.js +43 -0
  54. package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -0
  55. package/operations/entry/dataLoader/getLatestRevisionByEntryId.d.ts +4 -0
  56. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +57 -0
  57. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -0
  58. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.d.ts +4 -0
  59. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +57 -0
  60. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -0
  61. package/operations/entry/dataLoader/getRevisionById.d.ts +4 -0
  62. package/operations/entry/dataLoader/getRevisionById.js +63 -0
  63. package/operations/entry/dataLoader/getRevisionById.js.map +1 -0
  64. package/operations/entry/dataLoader/index.d.ts +8 -0
  65. package/operations/entry/dataLoader/index.js +38 -0
  66. package/operations/entry/dataLoader/index.js.map +1 -0
  67. package/operations/entry/dataLoader/types.d.ts +6 -0
  68. package/operations/entry/dataLoader/types.js +5 -0
  69. package/operations/entry/dataLoader/types.js.map +1 -0
  70. package/operations/entry/dataLoaders.d.ts +17 -28
  71. package/operations/entry/dataLoaders.js +51 -239
  72. package/operations/entry/dataLoaders.js.map +1 -0
  73. package/operations/entry/filtering/createExpressions.d.ts +26 -0
  74. package/operations/entry/filtering/createExpressions.js +176 -0
  75. package/operations/entry/filtering/createExpressions.js.map +1 -0
  76. package/operations/entry/filtering/createFields.d.ts +16 -0
  77. package/operations/entry/filtering/createFields.js +105 -0
  78. package/operations/entry/filtering/createFields.js.map +1 -0
  79. package/operations/entry/filtering/extractSort.d.ts +17 -0
  80. package/operations/entry/filtering/extractSort.js +67 -0
  81. package/operations/entry/filtering/extractSort.js.map +1 -0
  82. package/operations/entry/filtering/filter.d.ts +15 -0
  83. package/operations/entry/filtering/filter.js +143 -0
  84. package/operations/entry/filtering/filter.js.map +1 -0
  85. package/operations/entry/filtering/fullTextSearch.d.ts +14 -0
  86. package/operations/entry/filtering/fullTextSearch.js +48 -0
  87. package/operations/entry/filtering/fullTextSearch.js.map +1 -0
  88. package/operations/entry/filtering/getValue.d.ts +5 -0
  89. package/operations/entry/filtering/getValue.js +63 -0
  90. package/operations/entry/filtering/getValue.js.map +1 -0
  91. package/operations/entry/filtering/index.d.ts +2 -0
  92. package/operations/entry/filtering/index.js +19 -0
  93. package/operations/entry/filtering/index.js.map +1 -0
  94. package/operations/entry/filtering/mapPlugins.d.ts +8 -0
  95. package/operations/entry/filtering/mapPlugins.js +31 -0
  96. package/operations/entry/filtering/mapPlugins.js.map +1 -0
  97. package/operations/entry/filtering/plugins/defaultFilterCreate.d.ts +2 -0
  98. package/operations/entry/filtering/plugins/defaultFilterCreate.js +43 -0
  99. package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -0
  100. package/operations/entry/filtering/plugins/index.d.ts +1 -0
  101. package/operations/entry/filtering/plugins/index.js +13 -0
  102. package/operations/entry/filtering/plugins/index.js.map +1 -0
  103. package/operations/entry/filtering/plugins/objectFilterCreate.d.ts +2 -0
  104. package/operations/entry/filtering/plugins/objectFilterCreate.js +88 -0
  105. package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -0
  106. package/operations/entry/filtering/plugins/refFilterCreate.d.ts +2 -0
  107. package/operations/entry/filtering/plugins/refFilterCreate.js +73 -0
  108. package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -0
  109. package/operations/entry/filtering/sort.d.ts +12 -0
  110. package/operations/entry/filtering/sort.js +69 -0
  111. package/operations/entry/filtering/sort.js.map +1 -0
  112. package/operations/entry/filtering/systemFields.d.ts +4 -0
  113. package/operations/entry/filtering/systemFields.js +88 -0
  114. package/operations/entry/filtering/systemFields.js.map +1 -0
  115. package/operations/entry/filtering/transform.d.ts +6 -0
  116. package/operations/entry/filtering/transform.js +16 -0
  117. package/operations/entry/filtering/transform.js.map +1 -0
  118. package/operations/entry/filtering/types.d.ts +40 -0
  119. package/operations/entry/filtering/types.js +5 -0
  120. package/operations/entry/filtering/types.js.map +1 -0
  121. package/operations/entry/filtering/values.d.ts +2 -0
  122. package/operations/entry/filtering/values.js +22 -0
  123. package/operations/entry/filtering/values.js.map +1 -0
  124. package/operations/entry/filtering/where.d.ts +5 -0
  125. package/operations/entry/filtering/where.js +33 -0
  126. package/operations/entry/filtering/where.js.map +1 -0
  127. package/operations/entry/index.d.ts +3 -3
  128. package/operations/entry/index.js +425 -330
  129. package/operations/entry/index.js.map +1 -0
  130. package/operations/entry/keys.js +7 -14
  131. package/operations/entry/keys.js.map +1 -0
  132. package/operations/group/index.d.ts +3 -2
  133. package/operations/group/index.js +9 -45
  134. package/operations/group/index.js.map +1 -0
  135. package/operations/model/index.d.ts +3 -2
  136. package/operations/model/index.js +13 -37
  137. package/operations/model/index.js.map +1 -0
  138. package/operations/settings/index.d.ts +3 -2
  139. package/operations/settings/index.js +7 -37
  140. package/operations/settings/index.js.map +1 -0
  141. package/operations/system/index.d.ts +3 -2
  142. package/operations/system/index.js +5 -28
  143. package/operations/system/index.js.map +1 -0
  144. package/package.json +25 -26
  145. package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +23 -0
  146. package/plugins/CmsEntryFieldFilterPathPlugin.js +43 -0
  147. package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -0
  148. package/plugins/CmsEntryFieldFilterPlugin.d.ts +43 -0
  149. package/plugins/CmsEntryFieldFilterPlugin.js +24 -0
  150. package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -0
  151. package/plugins/CmsEntryFieldSortingPlugin.d.ts +42 -0
  152. package/plugins/CmsEntryFieldSortingPlugin.js +28 -0
  153. package/plugins/CmsEntryFieldSortingPlugin.js.map +1 -0
  154. package/plugins/CmsFieldFilterValueTransformPlugin.d.ts +11 -0
  155. package/plugins/CmsFieldFilterValueTransformPlugin.js +24 -0
  156. package/plugins/CmsFieldFilterValueTransformPlugin.js.map +1 -0
  157. package/plugins/index.d.ts +4 -0
  158. package/plugins/index.js +49 -0
  159. package/plugins/index.js.map +1 -0
  160. package/types.d.ts +11 -33
  161. package/types.js +0 -1
  162. package/types.js.map +1 -0
  163. package/dynamoDb/path/ref.d.ts +0 -3
  164. package/dynamoDb/path/ref.js +0 -27
  165. package/operations/entry/systemFields.d.ts +0 -2
  166. package/operations/entry/systemFields.js +0 -50
  167. package/operations/entry/utils.d.ts +0 -31
  168. package/operations/entry/utils.js +0 -406
@@ -0,0 +1,38 @@
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;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["dataLoaders","getAllEntryRevisions","createGetAllEntryRevisions","getLatestRevisionByEntryId","createGetLatestRevisionByEntryId","getPublishedRevisionByEntryId","createGetPublishedRevisionByEntryId","getRevisionById","createGetRevisionById","getDataLoaderFactory","name","Error"],"sources":["index.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport { 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;AACA;AACA;AACA;AAEA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AAMA,MAAMA,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,CAAE,wBAAuBD,IAAK,IAAG,CAAC;EACrD;EACA,OAAOV,WAAW,CAACU,IAAI,CAAC;AAC5B,CAAC;AAAC"}
@@ -0,0 +1,6 @@
1
+ import { Entity } from "dynamodb-toolbox";
2
+ export interface DataLoaderParams {
3
+ entity: Entity<any>;
4
+ tenant: string;
5
+ locale: string;
6
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import { Entity } from \"dynamodb-toolbox\";\n\nexport interface DataLoaderParams {\n entity: Entity<any>;\n tenant: string;\n locale: string;\n}\n"],"mappings":""}
@@ -1,38 +1,27 @@
1
- import { CmsEntry, CmsModel } from "@webiny/api-headless-cms/types";
1
+ import { CmsModel, CmsStorageEntry } from "@webiny/api-headless-cms/types";
2
2
  import { Entity } from "dynamodb-toolbox";
3
- export interface GetAllEntryRevisionsParams {
3
+ import { 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,115 @@
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
-
8
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
10
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
- var _dataloader = _interopRequireDefault(require("dataloader"));
13
-
14
10
  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
-
11
+ var _DataLoaderCache = require("./dataLoader/DataLoaderCache");
12
+ var _dataLoader = require("./dataLoader");
22
13
  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
14
  class DataLoadersHandler {
207
15
  constructor(params) {
208
- (0, _defineProperty2.default)(this, "loaders", new Map());
209
16
  (0, _defineProperty2.default)(this, "entity", void 0);
17
+ (0, _defineProperty2.default)(this, "cache", new _DataLoaderCache.DataLoaderCache());
210
18
  this.entity = params.entity;
211
19
  }
212
-
213
20
  async getAllEntryRevisions(params) {
214
- return await this.loadMany("getAllEntryRevisions", params, params.ids);
21
+ const ids = params.ids.map(id => {
22
+ const {
23
+ id: entryId
24
+ } = (0, _utils.parseIdentifier)(id);
25
+ return entryId;
26
+ });
27
+ return await this.loadMany("getAllEntryRevisions", params, ids);
215
28
  }
216
-
217
29
  async getRevisionById(params) {
218
30
  return await this.loadMany("getRevisionById", params, params.ids);
219
31
  }
220
-
221
32
  async getPublishedRevisionByEntryId(params) {
222
- return await this.loadMany("getPublishedRevisionByEntryId", params, params.ids);
33
+ const ids = params.ids.map(id => {
34
+ const {
35
+ id: entryId
36
+ } = (0, _utils.parseIdentifier)(id);
37
+ return entryId;
38
+ });
39
+ return await this.loadMany("getPublishedRevisionByEntryId", params, ids);
223
40
  }
224
-
225
41
  async getLatestRevisionByEntryId(params) {
226
- return await this.loadMany("getLatestRevisionByEntryId", params, params.ids);
42
+ const ids = params.ids.map(id => {
43
+ const {
44
+ id: entryId
45
+ } = (0, _utils.parseIdentifier)(id);
46
+ return entryId;
47
+ });
48
+ return await this.loadMany("getLatestRevisionByEntryId", params, ids);
227
49
  }
228
50
 
51
+ /**
52
+ * TODO @ts-refactor
53
+ * Maybe pass on the generics to DataLoader definition?
54
+ */
229
55
  getLoader(name, params) {
230
- if (!dataLoaders[name]) {
231
- throw new _error.default("Unknown data loader.", "UNKNOWN_DATA_LOADER", {
232
- name
233
- });
234
- }
235
-
236
56
  const {
237
57
  model
238
58
  } = 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
- })));
59
+ const cacheParams = {
60
+ tenant: model.tenant,
61
+ locale: model.locale,
62
+ name
63
+ };
64
+ let loader = this.cache.getDataLoader(cacheParams);
65
+ if (loader) {
66
+ return loader;
249
67
  }
250
-
251
- return this.loaders.get(loaderKey);
68
+ const factory = (0, _dataLoader.getDataLoaderFactory)(name);
69
+ loader = factory({
70
+ entity: this.entity,
71
+ tenant: model.tenant,
72
+ locale: model.locale
73
+ });
74
+ this.cache.setDataLoader(cacheParams, loader);
75
+ return loader;
252
76
  }
253
-
254
77
  async loadMany(loader, params, ids) {
255
- let results;
256
-
78
+ let results = [];
257
79
  try {
258
80
  results = await this.getLoader(loader, params).loadMany(ids);
259
-
260
81
  if (Array.isArray(results) === true) {
261
82
  return results.reduce((acc, res) => {
262
83
  if (Array.isArray(res) === false) {
263
84
  if (res && res.message) {
264
- throw new _error.default(res.message, res.code, _objectSpread(_objectSpread({}, res), {}, {
85
+ throw new _error.default(res.message, res.code, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, res), {}, {
265
86
  data: JSON.stringify(res.data || {})
266
87
  }));
267
88
  }
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), {}, {
89
+ throw new _error.default("Result from the data loader must be an array of arrays which contain requested items.", "DATA_LOADER_RESULTS_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
270
90
  loader
271
91
  }));
272
92
  }
273
-
274
93
  acc.push(...res);
275
94
  return acc;
276
95
  }, []);
277
96
  }
278
97
  } catch (ex) {
279
- throw new _error.default(ex.message || "Data loader error.", ex.code || "DATA_LOADER_ERROR", _objectSpread(_objectSpread({
98
+ throw new _error.default(ex.message || "Data loader error.", ex.code || "DATA_LOADER_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({
280
99
  error: ex
281
100
  }, params), {}, {
282
101
  loader,
283
102
  ids
284
103
  }));
285
104
  }
286
-
287
105
  throw new _error.default(`Data loader did not return array of items or empty array.`, "INVALID_DATA_LOADER_RESULT", {
288
106
  loader,
289
107
  ids,
290
108
  results
291
109
  });
292
110
  }
293
-
294
111
  clearAll(params) {
295
- for (const name of loaderNames) {
296
- const loader = this.getLoader(name, params);
297
- loader.clearAll();
298
- }
112
+ this.cache.clearAll(params === null || params === void 0 ? void 0 : params.model);
299
113
  }
300
-
301
114
  }
302
-
303
115
  exports.DataLoadersHandler = DataLoadersHandler;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["DataLoadersHandler","constructor","params","DataLoaderCache","entity","getAllEntryRevisions","ids","map","id","entryId","parseIdentifier","loadMany","getRevisionById","getPublishedRevisionByEntryId","getLatestRevisionByEntryId","getLoader","name","model","cacheParams","tenant","locale","loader","cache","getDataLoader","factory","getDataLoaderFactory","setDataLoader","results","Array","isArray","reduce","acc","res","message","WebinyError","code","data","JSON","stringify","push","ex","error","clearAll"],"sources":["dataLoaders.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport WebinyError from \"@webiny/error\";\nimport { CmsModel, CmsStorageEntry } from \"@webiny/api-headless-cms/types\";\nimport { CacheKeyParams, DataLoaderCache } from \"~/operations/entry/dataLoader/DataLoaderCache\";\nimport { Entity } from \"dynamodb-toolbox\";\nimport { DataLoaders, getDataLoaderFactory } from \"~/operations/entry/dataLoader\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { DataLoadersHandlerInterface, DataLoadersHandlerInterfaceClearAllParams } 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":"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"}
@@ -0,0 +1,26 @@
1
+ import { CmsEntryListWhere } from "@webiny/api-headless-cms/types";
2
+ import { ValueFilterPlugin } from "@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin";
3
+ import { PluginsContainer } from "@webiny/plugins";
4
+ import { Field } from "./types";
5
+ interface Params {
6
+ plugins: PluginsContainer;
7
+ where: Partial<CmsEntryListWhere>;
8
+ fields: Record<string, Field>;
9
+ }
10
+ export declare 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 {};