@webiny/api-headless-cms-ddb 0.0.0-unstable.aa00eecd97 → 0.0.0-unstable.ac6ebf63c6

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 (167) hide show
  1. package/README.md +6 -20
  2. package/definitions/entry.d.ts +4 -5
  3. package/definitions/entry.js +7 -88
  4. package/definitions/entry.js.map +1 -1
  5. package/definitions/group.d.ts +4 -5
  6. package/definitions/group.js +7 -59
  7. package/definitions/group.js.map +1 -1
  8. package/definitions/model.d.ts +4 -5
  9. package/definitions/model.js +7 -103
  10. package/definitions/model.js.map +1 -1
  11. package/definitions/table.d.ts +4 -6
  12. package/definitions/table.js +8 -26
  13. package/definitions/table.js.map +1 -1
  14. package/definitions/types.d.ts +59 -0
  15. package/definitions/types.js +3 -0
  16. package/definitions/types.js.map +1 -0
  17. package/dynamoDb/index.d.ts +1 -1
  18. package/dynamoDb/index.js +7 -12
  19. package/dynamoDb/index.js.map +1 -1
  20. package/dynamoDb/path/locationFolderId.d.ts +2 -0
  21. package/dynamoDb/path/locationFolderId.js +34 -0
  22. package/dynamoDb/path/locationFolderId.js.map +1 -0
  23. package/dynamoDb/path/plainObject.d.ts +1 -1
  24. package/dynamoDb/path/plainObject.js +7 -14
  25. package/dynamoDb/path/plainObject.js.map +1 -1
  26. package/dynamoDb/storage/longText.js +13 -18
  27. package/dynamoDb/storage/longText.js.map +1 -1
  28. package/dynamoDb/storage/richText.js +28 -71
  29. package/dynamoDb/storage/richText.js.map +1 -1
  30. package/dynamoDb/transformValue/datetime.d.ts +1 -1
  31. package/dynamoDb/transformValue/datetime.js +7 -12
  32. package/dynamoDb/transformValue/datetime.js.map +1 -1
  33. package/index.d.ts +2 -2
  34. package/index.js +40 -82
  35. package/index.js.map +1 -1
  36. package/operations/entry/dataLoader/DataLoaderCache.d.ts +1 -3
  37. package/operations/entry/dataLoader/DataLoaderCache.js +8 -17
  38. package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -1
  39. package/operations/entry/dataLoader/constants.js +3 -8
  40. package/operations/entry/dataLoader/constants.js.map +1 -1
  41. package/operations/entry/dataLoader/createBatchScheduleFn.js +6 -10
  42. package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -1
  43. package/operations/entry/dataLoader/getAllEntryRevisions.d.ts +3 -3
  44. package/operations/entry/dataLoader/getAllEntryRevisions.js +13 -24
  45. package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -1
  46. package/operations/entry/dataLoader/getLatestRevisionByEntryId.d.ts +3 -3
  47. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +24 -35
  48. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -1
  49. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.d.ts +3 -3
  50. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +24 -35
  51. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -1
  52. package/operations/entry/dataLoader/getRevisionById.d.ts +3 -3
  53. package/operations/entry/dataLoader/getRevisionById.js +26 -37
  54. package/operations/entry/dataLoader/getRevisionById.js.map +1 -1
  55. package/operations/entry/dataLoader/index.d.ts +5 -5
  56. package/operations/entry/dataLoader/index.js +12 -31
  57. package/operations/entry/dataLoader/index.js.map +1 -1
  58. package/operations/entry/dataLoader/types.d.ts +3 -4
  59. package/operations/entry/dataLoader/types.js +2 -4
  60. package/operations/entry/dataLoader/types.js.map +1 -1
  61. package/operations/entry/dataLoaders.d.ts +11 -12
  62. package/operations/entry/dataLoaders.js +25 -34
  63. package/operations/entry/dataLoaders.js.map +1 -1
  64. package/operations/entry/filtering/createExpressions.d.ts +5 -5
  65. package/operations/entry/filtering/createExpressions.js +29 -30
  66. package/operations/entry/filtering/createExpressions.js.map +1 -1
  67. package/operations/entry/filtering/createFields.d.ts +6 -4
  68. package/operations/entry/filtering/createFields.js +87 -86
  69. package/operations/entry/filtering/createFields.js.map +1 -1
  70. package/operations/entry/filtering/extractSort.d.ts +6 -6
  71. package/operations/entry/filtering/extractSort.js +40 -23
  72. package/operations/entry/filtering/extractSort.js.map +1 -1
  73. package/operations/entry/filtering/filter.d.ts +6 -6
  74. package/operations/entry/filtering/filter.js +36 -29
  75. package/operations/entry/filtering/filter.js.map +1 -1
  76. package/operations/entry/filtering/fullTextSearch.d.ts +3 -3
  77. package/operations/entry/filtering/fullTextSearch.js +8 -14
  78. package/operations/entry/filtering/fullTextSearch.js.map +1 -1
  79. package/operations/entry/filtering/getValue.js +6 -10
  80. package/operations/entry/filtering/getValue.js.map +1 -1
  81. package/operations/entry/filtering/index.d.ts +2 -2
  82. package/operations/entry/filtering/index.js +3 -18
  83. package/operations/entry/filtering/index.js.map +1 -1
  84. package/operations/entry/filtering/mapPlugins.d.ts +2 -2
  85. package/operations/entry/filtering/mapPlugins.js +5 -11
  86. package/operations/entry/filtering/mapPlugins.js.map +1 -1
  87. package/operations/entry/filtering/plugins/defaultFilterCreate.d.ts +2 -2
  88. package/operations/entry/filtering/plugins/defaultFilterCreate.js +10 -14
  89. package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -1
  90. package/operations/entry/filtering/plugins/index.d.ts +1 -1
  91. package/operations/entry/filtering/plugins/index.js +8 -12
  92. package/operations/entry/filtering/plugins/index.js.map +1 -1
  93. package/operations/entry/filtering/plugins/objectFilterCreate.d.ts +2 -2
  94. package/operations/entry/filtering/plugins/objectFilterCreate.js +17 -19
  95. package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -1
  96. package/operations/entry/filtering/plugins/refFilterCreate.d.ts +3 -2
  97. package/operations/entry/filtering/plugins/refFilterCreate.js +22 -19
  98. package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -1
  99. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.d.ts +2 -0
  100. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js +57 -0
  101. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js.map +1 -0
  102. package/operations/entry/filtering/sort.d.ts +6 -6
  103. package/operations/entry/filtering/sort.js +18 -20
  104. package/operations/entry/filtering/sort.js.map +1 -1
  105. package/operations/entry/filtering/systemFields.d.ts +2 -4
  106. package/operations/entry/filtering/systemFields.js +88 -42
  107. package/operations/entry/filtering/systemFields.js.map +1 -1
  108. package/operations/entry/filtering/transform.d.ts +1 -1
  109. package/operations/entry/filtering/transform.js +3 -8
  110. package/operations/entry/filtering/transform.js.map +1 -1
  111. package/operations/entry/filtering/types.d.ts +3 -3
  112. package/operations/entry/filtering/types.js +2 -4
  113. package/operations/entry/filtering/types.js.map +1 -1
  114. package/operations/entry/filtering/values.d.ts +1 -1
  115. package/operations/entry/filtering/values.js +6 -12
  116. package/operations/entry/filtering/values.js.map +1 -1
  117. package/operations/entry/filtering/where.js +6 -10
  118. package/operations/entry/filtering/where.js.map +1 -1
  119. package/operations/entry/index.d.ts +3 -4
  120. package/operations/entry/index.js +635 -339
  121. package/operations/entry/index.js.map +1 -1
  122. package/operations/entry/keys.d.ts +40 -2
  123. package/operations/entry/keys.js +55 -30
  124. package/operations/entry/keys.js.map +1 -1
  125. package/operations/group/index.d.ts +4 -4
  126. package/operations/group/index.js +44 -61
  127. package/operations/group/index.js.map +1 -1
  128. package/operations/model/index.d.ts +3 -3
  129. package/operations/model/index.js +37 -46
  130. package/operations/model/index.js.map +1 -1
  131. package/package.json +21 -28
  132. package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +4 -3
  133. package/plugins/CmsEntryFieldFilterPathPlugin.js +15 -16
  134. package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -1
  135. package/plugins/CmsEntryFieldFilterPlugin.d.ts +10 -10
  136. package/plugins/CmsEntryFieldFilterPlugin.js +11 -14
  137. package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -1
  138. package/plugins/CmsEntryFieldSortingPlugin.d.ts +2 -2
  139. package/plugins/CmsEntryFieldSortingPlugin.js +6 -15
  140. package/plugins/CmsEntryFieldSortingPlugin.js.map +1 -1
  141. package/plugins/CmsFieldFilterValueTransformPlugin.d.ts +2 -2
  142. package/plugins/CmsFieldFilterValueTransformPlugin.js +5 -13
  143. package/plugins/CmsFieldFilterValueTransformPlugin.js.map +1 -1
  144. package/plugins/index.d.ts +4 -4
  145. package/plugins/index.js +5 -48
  146. package/plugins/index.js.map +1 -1
  147. package/types.d.ts +18 -22
  148. package/types.js +5 -12
  149. package/types.js.map +1 -1
  150. package/definitions/settings.d.ts +0 -9
  151. package/definitions/settings.js +0 -53
  152. package/definitions/settings.js.map +0 -1
  153. package/definitions/system.d.ts +0 -9
  154. package/definitions/system.js +0 -41
  155. package/definitions/system.js.map +0 -1
  156. package/dynamoDb/storage/date.d.ts +0 -3
  157. package/dynamoDb/storage/date.js +0 -91
  158. package/dynamoDb/storage/date.js.map +0 -1
  159. package/operations/entry/systemFields.d.ts +0 -2
  160. package/operations/entry/systemFields.js +0 -72
  161. package/operations/entry/systemFields.js.map +0 -1
  162. package/operations/settings/index.d.ts +0 -7
  163. package/operations/settings/index.js +0 -111
  164. package/operations/settings/index.js.map +0 -1
  165. package/operations/system/index.d.ts +0 -7
  166. package/operations/system/index.js +0 -82
  167. package/operations/system/index.js.map +0 -1
@@ -1,38 +1,19 @@
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
- });
1
+ import { createGetAllEntryRevisions } from "./getAllEntryRevisions.js";
2
+ import { createGetLatestRevisionByEntryId } from "./getLatestRevisionByEntryId.js";
3
+ import { createGetPublishedRevisionByEntryId } from "./getPublishedRevisionByEntryId.js";
4
+ import { createGetRevisionById } from "./getRevisionById.js";
5
+ export * from "./DataLoaderCache.js";
26
6
  const dataLoaders = {
27
- getAllEntryRevisions: _getAllEntryRevisions.createGetAllEntryRevisions,
28
- getLatestRevisionByEntryId: _getLatestRevisionByEntryId.createGetLatestRevisionByEntryId,
29
- getPublishedRevisionByEntryId: _getPublishedRevisionByEntryId.createGetPublishedRevisionByEntryId,
30
- getRevisionById: _getRevisionById.createGetRevisionById
7
+ getAllEntryRevisions: createGetAllEntryRevisions,
8
+ getLatestRevisionByEntryId: createGetLatestRevisionByEntryId,
9
+ getPublishedRevisionByEntryId: createGetPublishedRevisionByEntryId,
10
+ getRevisionById: createGetRevisionById
31
11
  };
32
- const getDataLoaderFactory = name => {
12
+ export const getDataLoaderFactory = name => {
33
13
  if (!dataLoaders[name]) {
34
14
  throw new Error(`Missing data loader "${name}".`);
35
15
  }
36
16
  return dataLoaders[name];
37
17
  };
38
- exports.getDataLoaderFactory = getDataLoaderFactory;
18
+
19
+ //# sourceMappingURL=index.js.map
@@ -1 +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"}
1
+ {"version":3,"names":["createGetAllEntryRevisions","createGetLatestRevisionByEntryId","createGetPublishedRevisionByEntryId","createGetRevisionById","dataLoaders","getAllEntryRevisions","getLatestRevisionByEntryId","getPublishedRevisionByEntryId","getRevisionById","getDataLoaderFactory","name","Error"],"sources":["index.ts"],"sourcesContent":["import type DataLoader from \"dataloader\";\nimport type { IDataLoaderParams } from \"./types.js\";\nimport { createGetAllEntryRevisions } from \"./getAllEntryRevisions.js\";\nimport { createGetLatestRevisionByEntryId } from \"./getLatestRevisionByEntryId.js\";\nimport { createGetPublishedRevisionByEntryId } from \"./getPublishedRevisionByEntryId.js\";\nimport { createGetRevisionById } from \"./getRevisionById.js\";\n\nexport * from \"./DataLoaderCache.js\";\n\ninterface Callable {\n (params: IDataLoaderParams): 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,SAASA,0BAA0B;AACnC,SAASC,gCAAgC;AACzC,SAASC,mCAAmC;AAC5C,SAASC,qBAAqB;AAE9B;AAMA,MAAMC,WAAqC,GAAG;EAC1CC,oBAAoB,EAAEL,0BAA0B;EAChDM,0BAA0B,EAAEL,gCAAgC;EAC5DM,6BAA6B,EAAEL,mCAAmC;EAClEM,eAAe,EAAEL;AACrB,CAAC;AAQD,OAAO,MAAMM,oBAAoB,GAAIC,IAAY,IAAK;EAClD,IAAI,CAACN,WAAW,CAACM,IAAI,CAAC,EAAE;IACpB,MAAM,IAAIC,KAAK,CAAC,wBAAwBD,IAAI,IAAI,CAAC;EACrD;EACA,OAAON,WAAW,CAACM,IAAI,CAAC;AAC5B,CAAC","ignoreList":[]}
@@ -1,6 +1,5 @@
1
- import { Entity } from "dynamodb-toolbox";
2
- export interface DataLoaderParams {
3
- entity: Entity<any>;
1
+ import type { IEntryEntity } from "../../../definitions/types.js";
2
+ export interface IDataLoaderParams {
3
+ entity: IEntryEntity;
4
4
  tenant: string;
5
- locale: string;
6
5
  }
@@ -1,5 +1,3 @@
1
- "use strict";
1
+ export {};
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
3
+ //# sourceMappingURL=types.js.map
@@ -1 +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
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { IEntryEntity } from \"~/definitions/types.js\";\n\nexport interface IDataLoaderParams {\n entity: IEntryEntity;\n tenant: string;\n}\n"],"mappings":"","ignoreList":[]}
@@ -1,21 +1,20 @@
1
- import { CmsModel, CmsStorageEntry } from "@webiny/api-headless-cms/types";
2
- import { Entity } from "dynamodb-toolbox";
3
- import { DataLoadersHandlerInterface, DataLoadersHandlerInterfaceClearAllParams } from "../../types";
1
+ import type { CmsEntryValues, CmsModel, CmsStorageEntry } from "@webiny/api-headless-cms/types/index.js";
2
+ import type { DataLoadersHandlerInterfaceClearAllParams, IDataLoadersHandler, IEntryEntity } from "../../types.js";
4
3
  interface DataLoaderParams {
5
- model: Pick<CmsModel, "tenant" | "locale" | "modelId">;
4
+ model: Pick<CmsModel, "tenant" | "modelId">;
6
5
  ids: readonly string[];
7
6
  }
8
- interface DataLoadersHandlerParams {
9
- entity: Entity<any>;
7
+ interface IDataLoadersHandlerParams {
8
+ entity: IEntryEntity;
10
9
  }
11
- export declare class DataLoadersHandler implements DataLoadersHandlerInterface {
10
+ export declare class DataLoadersHandler implements IDataLoadersHandler {
12
11
  private readonly entity;
13
12
  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[]>;
13
+ constructor(params: IDataLoadersHandlerParams);
14
+ getAllEntryRevisions<T extends CmsEntryValues = CmsEntryValues>(params: DataLoaderParams): Promise<CmsStorageEntry<T>[]>;
15
+ getRevisionById<T extends CmsEntryValues = CmsEntryValues>(params: DataLoaderParams): Promise<CmsStorageEntry<T>[]>;
16
+ getPublishedRevisionByEntryId<T extends CmsEntryValues = CmsEntryValues>(params: DataLoaderParams): Promise<CmsStorageEntry<T>[]>;
17
+ getLatestRevisionByEntryId<T extends CmsEntryValues = CmsEntryValues>(params: DataLoaderParams): Promise<CmsStorageEntry<T>[]>;
19
18
  /**
20
19
  * TODO @ts-refactor
21
20
  * Maybe pass on the generics to DataLoader definition?
@@ -1,27 +1,17 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.DataLoadersHandler = void 0;
8
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
- var _error = _interopRequireDefault(require("@webiny/error"));
11
- var _DataLoaderCache = require("./dataLoader/DataLoaderCache");
12
- var _dataLoader = require("./dataLoader");
13
- var _utils = require("@webiny/utils");
14
- class DataLoadersHandler {
1
+ import WebinyError from "@webiny/error";
2
+ import { DataLoaderCache } from "./dataLoader/DataLoaderCache.js";
3
+ import { getDataLoaderFactory } from "./dataLoader/index.js";
4
+ import { parseIdentifier } from "@webiny/utils";
5
+ export class DataLoadersHandler {
6
+ cache = new DataLoaderCache();
15
7
  constructor(params) {
16
- (0, _defineProperty2.default)(this, "entity", void 0);
17
- (0, _defineProperty2.default)(this, "cache", new _DataLoaderCache.DataLoaderCache());
18
8
  this.entity = params.entity;
19
9
  }
20
10
  async getAllEntryRevisions(params) {
21
11
  const ids = params.ids.map(id => {
22
12
  const {
23
13
  id: entryId
24
- } = (0, _utils.parseIdentifier)(id);
14
+ } = parseIdentifier(id);
25
15
  return entryId;
26
16
  });
27
17
  return await this.loadMany("getAllEntryRevisions", params, ids);
@@ -33,7 +23,7 @@ class DataLoadersHandler {
33
23
  const ids = params.ids.map(id => {
34
24
  const {
35
25
  id: entryId
36
- } = (0, _utils.parseIdentifier)(id);
26
+ } = parseIdentifier(id);
37
27
  return entryId;
38
28
  });
39
29
  return await this.loadMany("getPublishedRevisionByEntryId", params, ids);
@@ -42,7 +32,7 @@ class DataLoadersHandler {
42
32
  const ids = params.ids.map(id => {
43
33
  const {
44
34
  id: entryId
45
- } = (0, _utils.parseIdentifier)(id);
35
+ } = parseIdentifier(id);
46
36
  return entryId;
47
37
  });
48
38
  return await this.loadMany("getLatestRevisionByEntryId", params, ids);
@@ -58,18 +48,16 @@ class DataLoadersHandler {
58
48
  } = params;
59
49
  const cacheParams = {
60
50
  tenant: model.tenant,
61
- locale: model.locale,
62
51
  name
63
52
  };
64
53
  let loader = this.cache.getDataLoader(cacheParams);
65
54
  if (loader) {
66
55
  return loader;
67
56
  }
68
- const factory = (0, _dataLoader.getDataLoaderFactory)(name);
57
+ const factory = getDataLoaderFactory(name);
69
58
  loader = factory({
70
59
  entity: this.entity,
71
- tenant: model.tenant,
72
- locale: model.locale
60
+ tenant: model.tenant
73
61
  });
74
62
  this.cache.setDataLoader(cacheParams, loader);
75
63
  return loader;
@@ -82,34 +70,37 @@ class DataLoadersHandler {
82
70
  return results.reduce((acc, res) => {
83
71
  if (Array.isArray(res) === false) {
84
72
  if (res && res.message) {
85
- throw new _error.default(res.message, res.code, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, res), {}, {
73
+ throw new WebinyError(res.message, res.code, {
74
+ ...res,
86
75
  data: JSON.stringify(res.data || {})
87
- }));
76
+ });
88
77
  }
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), {}, {
78
+ throw new WebinyError("Result from the data loader must be an array of arrays which contain requested items.", "DATA_LOADER_RESULTS_ERROR", {
79
+ ...params,
90
80
  loader
91
- }));
81
+ });
92
82
  }
93
83
  acc.push(...res);
94
84
  return acc;
95
85
  }, []);
96
86
  }
97
87
  } catch (ex) {
98
- throw new _error.default(ex.message || "Data loader error.", ex.code || "DATA_LOADER_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({
99
- error: ex
100
- }, params), {}, {
88
+ throw new WebinyError(ex.message || "Data loader error.", ex.code || "DATA_LOADER_ERROR", {
89
+ error: ex,
90
+ ...params,
101
91
  loader,
102
92
  ids
103
- }));
93
+ });
104
94
  }
105
- throw new _error.default(`Data loader did not return array of items or empty array.`, "INVALID_DATA_LOADER_RESULT", {
95
+ throw new WebinyError(`Data loader did not return array of items or empty array.`, "INVALID_DATA_LOADER_RESULT", {
106
96
  loader,
107
97
  ids,
108
98
  results
109
99
  });
110
100
  }
111
101
  clearAll(params) {
112
- this.cache.clearAll(params === null || params === void 0 ? void 0 : params.model);
102
+ this.cache.clearAll(params?.model);
113
103
  }
114
104
  }
115
- exports.DataLoadersHandler = DataLoadersHandler;
105
+
106
+ //# sourceMappingURL=dataLoaders.js.map
@@ -1 +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":";;;;;;;;;AACA;AAEA;AAEA;AACA;AAgBO,MAAMA,kBAAkB,CAAwC;EAI5DC,WAAW,CAACC,MAAgC,EAAE;IAAA;IAAA,6CAFX,IAAIC,gCAAe,EAAE;IAG3D,IAAI,CAACC,MAAM,GAAGF,MAAM,CAACE,MAAM;EAC/B;EAEA,MAAaC,oBAAoB,CAACH,MAAwB,EAA8B;IACpF,MAAMI,GAAG,GAAGJ,MAAM,CAACI,GAAG,CAACC,GAAG,CAACC,EAAE,IAAI;MAC7B,MAAM;QAAEA,EAAE,EAAEC;MAAQ,CAAC,GAAG,IAAAC,sB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AC,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;QAE1BM,KAAK,EAAED;MAAE,GACNtC,MAAM;QACTmB,MAAM;QACNf;MAAG,GAEV;IACL;IACA,MAAM,IAAI4B,cAAW,CAChB,2DAA0D,EAC3D,4BAA4B,EAC5B;MACIb,MAAM;MACNf,GAAG;MACHqB;IACJ,CAAC,CACJ;EACL;EAEOe,QAAQ,CAACxC,MAAkD,EAAQ;IACtE,IAAI,CAACoB,KAAK,CAACoB,QAAQ,CAACxC,MAAM,aAANA,MAAM,uBAANA,MAAM,CAAEe,KAAK,CAAC;EACtC;AACJ;AAAC"}
1
+ {"version":3,"names":["WebinyError","DataLoaderCache","getDataLoaderFactory","parseIdentifier","DataLoadersHandler","cache","constructor","params","entity","getAllEntryRevisions","ids","map","id","entryId","loadMany","getRevisionById","getPublishedRevisionByEntryId","getLatestRevisionByEntryId","getLoader","name","model","cacheParams","tenant","loader","getDataLoader","factory","setDataLoader","results","Array","isArray","reduce","acc","res","message","code","data","JSON","stringify","push","ex","error","clearAll"],"sources":["dataLoaders.ts"],"sourcesContent":["import type DataLoader from \"dataloader\";\nimport WebinyError from \"@webiny/error\";\nimport type {\n CmsEntryValues,\n CmsModel,\n CmsStorageEntry\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport type { CacheKeyParams } from \"~/operations/entry/dataLoader/DataLoaderCache.js\";\nimport { DataLoaderCache } from \"~/operations/entry/dataLoader/DataLoaderCache.js\";\nimport type { DataLoaders } from \"~/operations/entry/dataLoader/index.js\";\nimport { getDataLoaderFactory } from \"~/operations/entry/dataLoader/index.js\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport type {\n DataLoadersHandlerInterfaceClearAllParams,\n IDataLoadersHandler,\n IEntryEntity\n} from \"~/types.js\";\n\ninterface DataLoaderParams {\n model: Pick<CmsModel, \"tenant\" | \"modelId\">;\n ids: readonly string[];\n}\n\ninterface GetLoaderParams {\n model: Pick<CmsModel, \"tenant\" | \"modelId\">;\n}\n\ninterface IDataLoadersHandlerParams {\n entity: IEntryEntity;\n}\n\nexport class DataLoadersHandler implements IDataLoadersHandler {\n private readonly entity;\n private readonly cache = new DataLoaderCache();\n\n public constructor(params: IDataLoadersHandlerParams) {\n this.entity = params.entity;\n }\n\n public async getAllEntryRevisions<T extends CmsEntryValues = CmsEntryValues>(\n params: DataLoaderParams\n ): Promise<CmsStorageEntry<T>[]> {\n const ids = params.ids.map(id => {\n const { id: entryId } = parseIdentifier(id);\n return entryId;\n });\n return await this.loadMany<T>(\"getAllEntryRevisions\", params, ids);\n }\n\n public async getRevisionById<T extends CmsEntryValues = CmsEntryValues>(\n params: DataLoaderParams\n ): Promise<CmsStorageEntry<T>[]> {\n return await this.loadMany<T>(\"getRevisionById\", params, params.ids);\n }\n\n public async getPublishedRevisionByEntryId<T extends CmsEntryValues = CmsEntryValues>(\n params: DataLoaderParams\n ): Promise<CmsStorageEntry<T>[]> {\n const ids = params.ids.map(id => {\n const { id: entryId } = parseIdentifier(id);\n return entryId;\n });\n return await this.loadMany<T>(\"getPublishedRevisionByEntryId\", params, ids);\n }\n\n public async getLatestRevisionByEntryId<T extends CmsEntryValues = CmsEntryValues>(\n params: DataLoaderParams\n ): Promise<CmsStorageEntry<T>[]> {\n const ids = params.ids.map(id => {\n const { id: entryId } = parseIdentifier(id);\n return entryId;\n });\n return await this.loadMany<T>(\"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 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 });\n this.cache.setDataLoader(cacheParams, loader);\n return loader;\n }\n\n private async loadMany<T extends CmsEntryValues = CmsEntryValues>(\n loader: DataLoaders,\n params: GetLoaderParams,\n ids: readonly string[]\n ): Promise<CmsStorageEntry<T>[]> {\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,OAAOA,WAAW,MAAM,eAAe;AAOvC,SAASC,eAAe;AAExB,SAASC,oBAAoB;AAC7B,SAASC,eAAe,QAAQ,eAAe;AAoB/C,OAAO,MAAMC,kBAAkB,CAAgC;EAE1CC,KAAK,GAAG,IAAIJ,eAAe,CAAC,CAAC;EAEvCK,WAAWA,CAACC,MAAiC,EAAE;IAClD,IAAI,CAACC,MAAM,GAAGD,MAAM,CAACC,MAAM;EAC/B;EAEA,MAAaC,oBAAoBA,CAC7BF,MAAwB,EACK;IAC7B,MAAMG,GAAG,GAAGH,MAAM,CAACG,GAAG,CAACC,GAAG,CAACC,EAAE,IAAI;MAC7B,MAAM;QAAEA,EAAE,EAAEC;MAAQ,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AC,OAAOQ,EAAE,EAAE;MACT,MAAM,IAAIvC,WAAW,CACjBuC,EAAE,CAACN,OAAO,IAAI,oBAAoB,EAClCM,EAAE,CAACL,IAAI,IAAI,mBAAmB,EAC9B;QACIM,KAAK,EAAED,EAAE;QACT,GAAGhC,MAAM;QACTgB,MAAM;QACNb;MACJ,CACJ,CAAC;IACL;IACA,MAAM,IAAIV,WAAW,CACjB,2DAA2D,EAC3D,4BAA4B,EAC5B;MACIuB,MAAM;MACNb,GAAG;MACHiB;IACJ,CACJ,CAAC;EACL;EAEOc,QAAQA,CAAClC,MAAkD,EAAQ;IACtE,IAAI,CAACF,KAAK,CAACoC,QAAQ,CAAClC,MAAM,EAAEa,KAAK,CAAC;EACtC;AACJ","ignoreList":[]}
@@ -1,13 +1,13 @@
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";
1
+ import type { CmsEntryListWhere } from "@webiny/api-headless-cms/types/index.js";
2
+ import { ValueFilterPlugin } from "@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin.js";
3
+ import type { PluginsContainer } from "@webiny/plugins";
4
+ import type { Field } from "./types.js";
5
5
  interface Params {
6
6
  plugins: PluginsContainer;
7
7
  where: Partial<CmsEntryListWhere>;
8
8
  fields: Record<string, Field>;
9
9
  }
10
- export declare type ExpressionCondition = "AND" | "OR";
10
+ export type ExpressionCondition = "AND" | "OR";
11
11
  export interface Expression {
12
12
  expressions: Expression[];
13
13
  filters: Filter[];
@@ -1,46 +1,43 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.createExpressions = void 0;
8
- var _error = _interopRequireDefault(require("@webiny/error"));
9
- var _ValueFilterPlugin = require("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin");
10
- var _mapPlugins = require("./mapPlugins");
11
- var _where = require("./where");
12
- var _transform = require("./transform");
13
- var _CmsEntryFieldFilterPlugin = require("../../../plugins/CmsEntryFieldFilterPlugin");
14
- var _values = require("./values");
15
- const createExpressions = params => {
1
+ import WebinyError from "@webiny/error";
2
+ import { ValueFilterPlugin } from "@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin.js";
3
+ import { getMappedPlugins } from "./mapPlugins.js";
4
+ import { extractWhereParams } from "./where.js";
5
+ import { transformValue } from "./transform.js";
6
+ import { CmsEntryFieldFilterPlugin } from "../../../plugins/CmsEntryFieldFilterPlugin.js";
7
+ import { getWhereValues } from "./values.js";
8
+ import { getBaseFieldType } from "@webiny/api-headless-cms/utils/getBaseFieldType.js";
9
+ export const createExpressions = params => {
16
10
  const {
17
11
  where,
18
12
  plugins,
19
13
  fields
20
14
  } = params;
21
- const filterPlugins = (0, _mapPlugins.getMappedPlugins)({
15
+ const filterPlugins = getMappedPlugins({
22
16
  plugins,
23
- type: _ValueFilterPlugin.ValueFilterPlugin.type,
17
+ type: ValueFilterPlugin.type,
24
18
  property: "operation"
25
19
  });
26
- const transformValuePlugins = (0, _mapPlugins.getMappedPlugins)({
20
+ const transformValuePlugins = getMappedPlugins({
27
21
  plugins,
28
22
  type: "cms-field-filter-value-transform",
29
23
  property: "fieldType"
30
24
  });
31
- const fieldFilterCreatePlugins = (0, _mapPlugins.getMappedPlugins)({
25
+ const fieldFilterCreatePlugins = getMappedPlugins({
32
26
  plugins,
33
- type: _CmsEntryFieldFilterPlugin.CmsEntryFieldFilterPlugin.type,
27
+ type: CmsEntryFieldFilterPlugin.type,
34
28
  property: "fieldType"
35
29
  });
36
30
  const defaultFilterCreatePlugin = fieldFilterCreatePlugins["*"];
37
31
  const getFilterCreatePlugin = type => {
38
- const filterCreatePlugin = fieldFilterCreatePlugins[type] || defaultFilterCreatePlugin;
32
+ const fieldType = getBaseFieldType({
33
+ type
34
+ });
35
+ const filterCreatePlugin = fieldFilterCreatePlugins[fieldType] || defaultFilterCreatePlugin;
39
36
  if (filterCreatePlugin) {
40
37
  return filterCreatePlugin;
41
38
  }
42
- throw new _error.default(`There is no filter create plugin for the field type "${type}".`, "MISSING_FILTER_CREATE_PLUGIN", {
43
- type
39
+ throw new WebinyError(`There is no filter create plugin for the field type "${fieldType}".`, "MISSING_FILTER_CREATE_PLUGIN", {
40
+ fieldType
44
41
  });
45
42
  };
46
43
  const createExpression = ({
@@ -65,7 +62,7 @@ const createExpressions = params => {
65
62
  * AND conditional
66
63
  */
67
64
  if (key === "AND") {
68
- const childWhereList = (0, _values.getWhereValues)(value, key);
65
+ const childWhereList = getWhereValues(value, key);
69
66
  const childExpression = {
70
67
  condition: "AND",
71
68
  filters: [],
@@ -85,7 +82,7 @@ const createExpressions = params => {
85
82
  * OR conditional
86
83
  */
87
84
  if (key === "OR") {
88
- const childWhereList = (0, _values.getWhereValues)(value, key);
85
+ const childWhereList = getWhereValues(value, key);
89
86
  const childExpression = {
90
87
  condition: "OR",
91
88
  filters: [],
@@ -101,7 +98,7 @@ const createExpressions = params => {
101
98
  expression.expressions.push(childExpression);
102
99
  continue;
103
100
  }
104
- const whereParams = (0, _where.extractWhereParams)(key);
101
+ const whereParams = extractWhereParams(key);
105
102
  if (!whereParams) {
106
103
  continue;
107
104
  }
@@ -112,7 +109,7 @@ const createExpressions = params => {
112
109
  } = whereParams;
113
110
  const field = fields[fieldId];
114
111
  if (!field) {
115
- throw new _error.default(`There is no field with the fieldId "${fieldId}".`, "FIELD_ERROR", {
112
+ throw new WebinyError(`There is no field with the fieldId "${fieldId}".`, "FIELD_ERROR", {
116
113
  fieldId
117
114
  });
118
115
  }
@@ -121,7 +118,8 @@ const createExpressions = params => {
121
118
  * We need a filter create plugin for this type.
122
119
  */
123
120
  const filterCreatePlugin = getFilterCreatePlugin(field.type);
124
- const transformValuePlugin = transformValuePlugins[field.type];
121
+ const fieldType = getBaseFieldType(field);
122
+ const transformValuePlugin = transformValuePlugins[fieldType];
125
123
  const transformValueCallable = value => {
126
124
  if (!transformValuePlugin) {
127
125
  return value;
@@ -141,7 +139,7 @@ const createExpressions = params => {
141
139
  negate,
142
140
  field,
143
141
  fields,
144
- compareValue: (0, _transform.transformValue)({
142
+ compareValue: transformValue({
145
143
  value,
146
144
  transform: transformValueCallable
147
145
  }),
@@ -173,4 +171,5 @@ const createExpressions = params => {
173
171
  }
174
172
  return expression.expressions[0];
175
173
  };
176
- exports.createExpressions = createExpressions;
174
+
175
+ //# sourceMappingURL=createExpressions.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createExpressions","params","where","plugins","fields","filterPlugins","getMappedPlugins","type","ValueFilterPlugin","property","transformValuePlugins","fieldFilterCreatePlugins","CmsEntryFieldFilterPlugin","defaultFilterCreatePlugin","getFilterCreatePlugin","filterCreatePlugin","WebinyError","createExpression","condition","expression","filters","expressions","key","value","undefined","childWhereList","getWhereValues","childExpression","childWhere","result","push","whereParams","extractWhereParams","fieldId","operation","negate","field","transformValuePlugin","transformValueCallable","transform","create","valueFilterPlugins","compareValue","transformValue","Array","isArray","length"],"sources":["createExpressions.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsEntryListWhere } from \"@webiny/api-headless-cms/types\";\nimport { ValueFilterPlugin } from \"@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin\";\nimport { CmsFieldFilterValueTransformPlugin } from \"~/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { Field } from \"./types\";\nimport { getMappedPlugins } from \"./mapPlugins\";\nimport { extractWhereParams } from \"./where\";\nimport { transformValue } from \"./transform\";\nimport { CmsEntryFieldFilterPlugin } from \"~/plugins/CmsEntryFieldFilterPlugin\";\nimport { getWhereValues } from \"~/operations/entry/filtering/values\";\n\ninterface CreateExpressionParams {\n where: Partial<CmsEntryListWhere>;\n condition: ExpressionCondition;\n}\n\ninterface CreateExpressionCb {\n (params: CreateExpressionParams): Expression;\n}\n\ninterface Params {\n plugins: PluginsContainer;\n where: Partial<CmsEntryListWhere>;\n fields: Record<string, Field>;\n}\n\nexport type ExpressionCondition = \"AND\" | \"OR\";\n\nexport interface Expression {\n expressions: Expression[];\n filters: Filter[];\n condition: ExpressionCondition;\n}\n\nexport interface Filter {\n field: Field;\n path: string;\n fieldPathId: string;\n plugin: ValueFilterPlugin;\n negate: boolean;\n compareValue: any;\n transformValue: <I = any, O = any>(value: I) => O;\n}\n\nexport const createExpressions = (params: Params): Expression => {\n const { where, plugins, fields } = params;\n const filterPlugins = getMappedPlugins<ValueFilterPlugin>({\n plugins,\n type: ValueFilterPlugin.type,\n property: \"operation\"\n });\n const transformValuePlugins = getMappedPlugins<CmsFieldFilterValueTransformPlugin>({\n plugins,\n type: \"cms-field-filter-value-transform\",\n property: \"fieldType\"\n });\n const fieldFilterCreatePlugins = getMappedPlugins<CmsEntryFieldFilterPlugin>({\n plugins,\n type: CmsEntryFieldFilterPlugin.type,\n property: \"fieldType\"\n });\n\n const defaultFilterCreatePlugin = fieldFilterCreatePlugins[\"*\"] as CmsEntryFieldFilterPlugin;\n\n const getFilterCreatePlugin = (type: string) => {\n const filterCreatePlugin = fieldFilterCreatePlugins[type] || defaultFilterCreatePlugin;\n if (filterCreatePlugin) {\n return filterCreatePlugin;\n }\n throw new WebinyError(\n `There is no filter create plugin for the field type \"${type}\".`,\n \"MISSING_FILTER_CREATE_PLUGIN\",\n {\n type\n }\n );\n };\n\n const createExpression: CreateExpressionCb = ({ where, condition }) => {\n const expression: Expression = {\n filters: [],\n expressions: [],\n condition\n };\n\n for (const key in where) {\n const value = (where as any)[key];\n if (value === undefined) {\n continue;\n }\n\n /**\n * If there are \"AND\" or \"OR\" keys, let's sort them out first.\n *\n *\n * AND conditional\n */\n if (key === \"AND\") {\n const childWhereList = getWhereValues(value, key);\n const childExpression: Expression = {\n condition: \"AND\",\n filters: [],\n expressions: []\n };\n for (const childWhere of childWhereList) {\n const result = createExpression({\n where: childWhere,\n condition: \"AND\"\n });\n childExpression.expressions.push(result);\n }\n expression.expressions.push(childExpression);\n continue;\n }\n /**\n * OR conditional\n */\n if (key === \"OR\") {\n const childWhereList = getWhereValues(value, key);\n\n const childExpression: Expression = {\n condition: \"OR\",\n filters: [],\n expressions: []\n };\n for (const childWhere of childWhereList) {\n const result = createExpression({\n where: childWhere,\n condition: \"AND\"\n });\n childExpression.expressions.push(result);\n }\n expression.expressions.push(childExpression);\n continue;\n }\n\n const whereParams = extractWhereParams(key);\n if (!whereParams) {\n continue;\n }\n\n const { fieldId, operation, negate } = whereParams;\n\n const field = fields[fieldId];\n if (!field) {\n throw new WebinyError(\n `There is no field with the fieldId \"${fieldId}\".`,\n \"FIELD_ERROR\",\n {\n fieldId\n }\n );\n }\n\n /**\n * We need a filter create plugin for this type.\n */\n const filterCreatePlugin = getFilterCreatePlugin(field.type);\n\n const transformValuePlugin: CmsFieldFilterValueTransformPlugin =\n transformValuePlugins[field.type];\n\n const transformValueCallable = (value: any) => {\n if (!transformValuePlugin) {\n return value;\n }\n return transformValuePlugin.transform({\n field,\n value\n });\n };\n\n const result = filterCreatePlugin.create({\n key,\n value,\n valueFilterPlugins: filterPlugins,\n transformValuePlugins,\n getFilterCreatePlugin,\n operation,\n negate,\n field,\n fields,\n compareValue: transformValue({\n value,\n transform: transformValueCallable\n }),\n transformValue: transformValueCallable\n });\n /**\n * There is a possibility of\n * - no result\n * - result being an array\n * - result being an object\n */\n if (!result || (Array.isArray(result) && result.length === 0)) {\n continue;\n }\n\n expression.filters.push(...(Array.isArray(result) ? result : [result]));\n }\n\n return expression;\n };\n\n const expression = createExpression({\n where,\n condition: \"AND\"\n });\n /**\n * If the first expression has no filters and has only one expression, put that expression as main one.\n * This will mostly be used when having an OR condition as the single expression in the root level of the where\n */\n if (expression.filters.length > 0 || expression.expressions.length !== 1) {\n return expression;\n }\n return expression.expressions[0];\n};\n"],"mappings":";;;;;;;AAAA;AAEA;AAIA;AACA;AACA;AACA;AACA;AAmCO,MAAMA,iBAAiB,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0B,MAAM,GAAG,CAAC,IAAI3B,UAAU,CAACE,WAAW,CAACyB,MAAM,KAAK,CAAC,EAAE;IACtE,OAAO3B,UAAU;EACrB;EACA,OAAOA,UAAU,CAACE,WAAW,CAAC,CAAC,CAAC;AACpC,CAAC;AAAC"}
1
+ {"version":3,"names":["WebinyError","ValueFilterPlugin","getMappedPlugins","extractWhereParams","transformValue","CmsEntryFieldFilterPlugin","getWhereValues","getBaseFieldType","createExpressions","params","where","plugins","fields","filterPlugins","type","property","transformValuePlugins","fieldFilterCreatePlugins","defaultFilterCreatePlugin","getFilterCreatePlugin","fieldType","filterCreatePlugin","createExpression","condition","expression","filters","expressions","key","value","undefined","childWhereList","childExpression","childWhere","result","push","whereParams","fieldId","operation","negate","field","transformValuePlugin","transformValueCallable","transform","create","valueFilterPlugins","compareValue","Array","isArray","length"],"sources":["createExpressions.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsEntryListWhere } from \"@webiny/api-headless-cms/types/index.js\";\nimport { ValueFilterPlugin } from \"@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin.js\";\nimport type { CmsFieldFilterValueTransformPlugin } from \"~/types.js\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport type { Field } from \"./types.js\";\nimport { getMappedPlugins } from \"./mapPlugins.js\";\nimport { extractWhereParams } from \"./where.js\";\nimport { transformValue } from \"./transform.js\";\nimport { CmsEntryFieldFilterPlugin } from \"~/plugins/CmsEntryFieldFilterPlugin.js\";\nimport { getWhereValues } from \"~/operations/entry/filtering/values.js\";\nimport { getBaseFieldType } from \"@webiny/api-headless-cms/utils/getBaseFieldType.js\";\n\ninterface CreateExpressionParams {\n where: Partial<CmsEntryListWhere>;\n condition: ExpressionCondition;\n}\n\ninterface Params {\n plugins: PluginsContainer;\n where: Partial<CmsEntryListWhere>;\n fields: Record<string, Field>;\n}\n\nexport type ExpressionCondition = \"AND\" | \"OR\";\n\nexport interface Expression {\n expressions: Expression[];\n filters: Filter[];\n condition: ExpressionCondition;\n}\n\nexport interface Filter {\n field: Field;\n path: string;\n fieldPathId: string;\n plugin: ValueFilterPlugin;\n negate: boolean;\n compareValue: any;\n transformValue: <I = any, O = any>(value: I) => O;\n}\n\nexport const createExpressions = (params: Params): Expression => {\n const { where, plugins, fields } = params;\n const filterPlugins = getMappedPlugins<ValueFilterPlugin>({\n plugins,\n type: ValueFilterPlugin.type,\n property: \"operation\"\n });\n const transformValuePlugins = getMappedPlugins<CmsFieldFilterValueTransformPlugin>({\n plugins,\n type: \"cms-field-filter-value-transform\",\n property: \"fieldType\"\n });\n const fieldFilterCreatePlugins = getMappedPlugins<CmsEntryFieldFilterPlugin>({\n plugins,\n type: CmsEntryFieldFilterPlugin.type,\n property: \"fieldType\"\n });\n\n const defaultFilterCreatePlugin = fieldFilterCreatePlugins[\"*\"] as CmsEntryFieldFilterPlugin;\n\n const getFilterCreatePlugin = (type: string) => {\n const fieldType = getBaseFieldType({\n type\n });\n const filterCreatePlugin = fieldFilterCreatePlugins[fieldType] || defaultFilterCreatePlugin;\n if (filterCreatePlugin) {\n return filterCreatePlugin;\n }\n throw new WebinyError(\n `There is no filter create plugin for the field type \"${fieldType}\".`,\n \"MISSING_FILTER_CREATE_PLUGIN\",\n {\n fieldType\n }\n );\n };\n\n const createExpression = ({ where, condition }: CreateExpressionParams): Expression => {\n const expression: Expression = {\n filters: [],\n expressions: [],\n condition\n };\n\n for (const key in where) {\n const value = where[key as keyof typeof where];\n if (value === undefined) {\n continue;\n }\n\n /**\n * If there are \"AND\" or \"OR\" keys, let's sort them out first.\n *\n *\n * AND conditional\n */\n if (key === \"AND\") {\n const childWhereList = getWhereValues(value, key);\n const childExpression: Expression = {\n condition: \"AND\",\n filters: [],\n expressions: []\n };\n for (const childWhere of childWhereList) {\n const result = createExpression({\n where: childWhere,\n condition: \"AND\"\n });\n childExpression.expressions.push(result);\n }\n expression.expressions.push(childExpression);\n continue;\n }\n /**\n * OR conditional\n */\n if (key === \"OR\") {\n const childWhereList = getWhereValues(value, key);\n\n const childExpression: Expression = {\n condition: \"OR\",\n filters: [],\n expressions: []\n };\n for (const childWhere of childWhereList) {\n const result = createExpression({\n where: childWhere,\n condition: \"AND\"\n });\n childExpression.expressions.push(result);\n }\n expression.expressions.push(childExpression);\n continue;\n }\n\n const whereParams = extractWhereParams(key);\n if (!whereParams) {\n continue;\n }\n\n const { fieldId, operation, negate } = whereParams;\n\n const field = fields[fieldId];\n if (!field) {\n throw new WebinyError(\n `There is no field with the fieldId \"${fieldId}\".`,\n \"FIELD_ERROR\",\n {\n fieldId\n }\n );\n }\n\n /**\n * We need a filter create plugin for this type.\n */\n const filterCreatePlugin = getFilterCreatePlugin(field.type);\n\n const fieldType = getBaseFieldType(field);\n\n const transformValuePlugin: CmsFieldFilterValueTransformPlugin =\n transformValuePlugins[fieldType];\n\n const transformValueCallable = (value: any) => {\n if (!transformValuePlugin) {\n return value;\n }\n return transformValuePlugin.transform({\n field,\n value\n });\n };\n\n const result = filterCreatePlugin.create({\n key,\n value,\n valueFilterPlugins: filterPlugins,\n transformValuePlugins,\n getFilterCreatePlugin,\n operation,\n negate,\n field,\n fields,\n compareValue: transformValue({\n value,\n transform: transformValueCallable\n }),\n transformValue: transformValueCallable\n });\n /**\n * There is a possibility of\n * - no result\n * - result being an array\n * - result being an object\n */\n if (!result || (Array.isArray(result) && result.length === 0)) {\n continue;\n }\n\n expression.filters.push(...(Array.isArray(result) ? result : [result]));\n }\n\n return expression;\n };\n\n const expression = createExpression({\n where,\n condition: \"AND\"\n });\n /**\n * If the first expression has no filters and has only one expression, put that expression as main one.\n * This will mostly be used when having an OR condition as the single expression in the root level of the where\n */\n if (expression.filters.length > 0 || expression.expressions.length !== 1) {\n return expression;\n }\n return expression.expressions[0];\n};\n"],"mappings":"AAAA,OAAOA,WAAW,MAAM,eAAe;AAEvC,SAASC,iBAAiB,QAAQ,8DAA8D;AAIhG,SAASC,gBAAgB;AACzB,SAASC,kBAAkB;AAC3B,SAASC,cAAc;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AEA,OAAOT,UAAU;EACrB,CAAC;EAED,MAAMA,UAAU,GAAGF,gBAAgB,CAAC;IAChCZ,KAAK;IACLa,SAAS,EAAE;EACf,CAAC,CAAC;EACF;AACJ;AACA;AACA;EACI,IAAIC,UAAU,CAACC,OAAO,CAACuB,MAAM,GAAG,CAAC,IAAIxB,UAAU,CAACE,WAAW,CAACsB,MAAM,KAAK,CAAC,EAAE;IACtE,OAAOxB,UAAU;EACrB;EACA,OAAOA,UAAU,CAACE,WAAW,CAAC,CAAC,CAAC;AACpC,CAAC","ignoreList":[]}
@@ -1,6 +1,6 @@
1
- import { CmsModelField } from "@webiny/api-headless-cms/types";
2
- import { Field } from "./types";
3
- import { PluginsContainer } from "@webiny/plugins";
1
+ import type { CmsModelField } from "@webiny/api-headless-cms/types/index.js";
2
+ import type { Field } from "./types.js";
3
+ import type { PluginsContainer } from "@webiny/plugins";
4
4
  interface Params {
5
5
  fields: CmsModelField[];
6
6
  plugins: PluginsContainer;
@@ -10,5 +10,7 @@ interface Params {
10
10
  *
11
11
  * In case of nested fields, fieldId is all the parent fieldIds + current one, joined by the dot (.).
12
12
  */
13
- export declare const createFields: (params: Params) => Record<string, Field>;
13
+ export declare const createFields: (params: Params) => {
14
+ [x: string]: Field;
15
+ };
14
16
  export {};