@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,105 +1,106 @@
1
- "use strict";
1
+ import { createSystemFields } from "./systemFields.js";
2
+ import { CmsEntryFieldFilterPathPlugin } from "../../../plugins/index.js";
3
+ import { getMappedPlugins } from "./mapPlugins.js";
4
+ import { getBaseFieldType } from "@webiny/api-headless-cms/utils/getBaseFieldType.js";
5
+ const createFieldCollection = params => {
6
+ const {
7
+ fields,
8
+ parents,
9
+ transformValuePlugins,
10
+ valuePathPlugins,
11
+ system
12
+ } = params;
13
+ return fields.reduce((collection, field) => {
14
+ const fieldType = getBaseFieldType(field);
15
+ const transformPlugin = transformValuePlugins[fieldType];
16
+ const valuePathPlugin = valuePathPlugins[fieldType];
2
17
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.createFields = void 0;
8
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
- var _systemFields = require("./systemFields");
10
- var _plugins = require("../../../plugins");
11
- var _mapPlugins = require("./mapPlugins");
18
+ /**
19
+ * The required fieldId is a product of all of its parents and its own fieldId.
20
+ */
21
+ const fieldId = [...parents, {
22
+ fieldId: field.fieldId,
23
+ list: field.list
24
+ }].map(f => f.fieldId).join(".");
25
+ collection[fieldId] = {
26
+ ...field,
27
+ parents,
28
+ system,
29
+ createPath: params => {
30
+ if (valuePathPlugin && valuePathPlugin.canUse(field, parents.map(p => p.fieldId))) {
31
+ return valuePathPlugin.createPath(params);
32
+ }
33
+ return parents.map(parent => parent.fieldId).concat([params.field.fieldId]).join(".");
34
+ },
35
+ transform: value => {
36
+ if (!transformPlugin) {
37
+ return value;
38
+ }
39
+ return transformPlugin.transform({
40
+ field,
41
+ value
42
+ });
43
+ }
44
+ };
45
+ const childFields = field.settings?.fields;
46
+ if (!childFields?.length) {
47
+ return collection;
48
+ }
49
+ const result = createFieldCollection({
50
+ fields: childFields,
51
+ parents: [...parents, {
52
+ fieldId: field.fieldId,
53
+ list: field.list
54
+ }],
55
+ transformValuePlugins,
56
+ valuePathPlugins,
57
+ system
58
+ });
59
+ Object.assign(collection, result);
60
+ return collection;
61
+ }, {});
62
+ };
12
63
  /**
13
64
  * This method will map the fieldId (fieldId -> field) to the actual field.
14
65
  *
15
66
  * In case of nested fields, fieldId is all the parent fieldIds + current one, joined by the dot (.).
16
67
  */
17
- const createFields = params => {
68
+ export const createFields = params => {
18
69
  const {
19
70
  fields,
20
71
  plugins
21
72
  } = params;
22
- const transformValuePlugins = (0, _mapPlugins.getMappedPlugins)({
73
+ const transformValuePlugins = getMappedPlugins({
23
74
  plugins,
24
75
  type: "cms-field-filter-value-transform",
25
76
  property: "fieldType"
26
77
  });
27
- const valuePathPlugins = (0, _mapPlugins.getMappedPlugins)({
78
+ const valuePathPlugins = getMappedPlugins({
28
79
  plugins,
29
- type: _plugins.CmsEntryFieldFilterPathPlugin.type,
80
+ type: CmsEntryFieldFilterPathPlugin.type,
30
81
  property: "fieldType"
31
82
  });
32
- const collection = (0, _systemFields.createSystemFields)().reduce((fields, field) => {
33
- const transformPlugin = transformValuePlugins[field.type];
34
- fields[field.fieldId] = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, field), {}, {
35
- parents: [],
36
- system: true,
37
- createPath: ({
38
- field
39
- }) => {
40
- var _field$settings;
41
- return ((_field$settings = field.settings) === null || _field$settings === void 0 ? void 0 : _field$settings.path) || field.fieldId;
42
- },
43
- transform: value => {
44
- if (!transformPlugin) {
45
- return value;
46
- }
47
- return transformPlugin.transform({
48
- field,
49
- value
50
- });
51
- }
52
- });
53
- return fields;
54
- }, {});
55
- const addFieldsToCollection = (fields, parents = []) => {
56
- /**
57
- * Exit early if no fields are sent.
58
- */
59
- if (fields.length === 0) {
60
- return;
61
- }
62
- for (const field of fields) {
63
- var _field$settings2;
64
- const transformPlugin = transformValuePlugins[field.type];
65
- const valuePathPlugin = valuePathPlugins[field.type];
66
- /**
67
- * The required fieldId is a product of all of its parents and its own fieldId.
68
- */
69
- const fieldId = [...parents, {
70
- fieldId: field.fieldId,
71
- multipleValues: field.multipleValues
72
- }].map(f => f.fieldId).join(".");
73
- collection[fieldId] = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, field), {}, {
74
- parents,
75
- system: false,
76
- createPath: params => {
77
- if (valuePathPlugin) {
78
- return valuePathPlugin.createPath(params);
79
- }
80
- return ["values"].concat(parents.map(parent => parent.fieldId)).concat([params.field.fieldId]).join(".");
81
- },
82
- transform: value => {
83
- if (!transformPlugin) {
84
- return value;
85
- }
86
- return transformPlugin.transform({
87
- field,
88
- value
89
- });
90
- }
91
- });
92
- const childFields = (_field$settings2 = field.settings) === null || _field$settings2 === void 0 ? void 0 : _field$settings2.fields;
93
- if (!childFields || childFields.length === 0) {
94
- continue;
95
- }
96
- addFieldsToCollection(childFields, [...parents, {
97
- fieldId: field.fieldId,
98
- multipleValues: field.multipleValues
99
- }]);
100
- }
83
+ const collection = createFieldCollection({
84
+ fields: createSystemFields(),
85
+ transformValuePlugins,
86
+ valuePathPlugins,
87
+ parents: [],
88
+ system: true
89
+ });
90
+ const result = createFieldCollection({
91
+ fields,
92
+ transformValuePlugins,
93
+ valuePathPlugins,
94
+ parents: [{
95
+ fieldId: "values",
96
+ list: false
97
+ }],
98
+ system: false
99
+ });
100
+ return {
101
+ ...collection,
102
+ ...result
101
103
  };
102
- addFieldsToCollection(fields);
103
- return collection;
104
104
  };
105
- exports.createFields = createFields;
105
+
106
+ //# sourceMappingURL=createFields.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createFields","params","fields","plugins","transformValuePlugins","getMappedPlugins","type","property","valuePathPlugins","CmsEntryFieldFilterPathPlugin","collection","createSystemFields","reduce","field","transformPlugin","fieldId","parents","system","createPath","settings","path","transform","value","addFieldsToCollection","length","valuePathPlugin","multipleValues","map","f","join","concat","parent","childFields"],"sources":["createFields.ts"],"sourcesContent":["import { CmsModelField } from \"@webiny/api-headless-cms/types\";\nimport { createSystemFields } from \"./systemFields\";\nimport { Field, FieldParent } from \"./types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { CmsFieldFilterValueTransformPlugin } from \"~/types\";\nimport { CmsEntryFieldFilterPathPlugin } from \"~/plugins\";\nimport { getMappedPlugins } from \"./mapPlugins\";\n\ninterface Params {\n fields: CmsModelField[];\n plugins: PluginsContainer;\n}\n/**\n * This method will map the fieldId (fieldId -> field) to the actual field.\n *\n * In case of nested fields, fieldId is all the parent fieldIds + current one, joined by the dot (.).\n */\nexport const createFields = (params: Params) => {\n const { fields, plugins } = params;\n\n const transformValuePlugins = getMappedPlugins<CmsFieldFilterValueTransformPlugin>({\n plugins,\n type: \"cms-field-filter-value-transform\",\n property: \"fieldType\"\n });\n const valuePathPlugins = getMappedPlugins<CmsEntryFieldFilterPathPlugin>({\n plugins,\n type: CmsEntryFieldFilterPathPlugin.type,\n property: \"fieldType\"\n });\n\n const collection = createSystemFields().reduce<Record<string, Field>>((fields, field) => {\n const transformPlugin = transformValuePlugins[field.type];\n\n fields[field.fieldId] = {\n ...field,\n parents: [],\n system: true,\n createPath: ({ field }) => {\n return field.settings?.path || field.fieldId;\n },\n transform: value => {\n if (!transformPlugin) {\n return value;\n }\n return transformPlugin.transform({\n field,\n value\n });\n }\n };\n\n return fields;\n }, {});\n\n const addFieldsToCollection = (fields: CmsModelField[], parents: FieldParent[] = []): void => {\n /**\n * Exit early if no fields are sent.\n */\n if (fields.length === 0) {\n return;\n }\n for (const field of fields) {\n const transformPlugin = transformValuePlugins[field.type];\n const valuePathPlugin = valuePathPlugins[field.type];\n /**\n * The required fieldId is a product of all of its parents and its own fieldId.\n */\n const fieldId = [\n ...parents,\n {\n fieldId: field.fieldId,\n multipleValues: field.multipleValues\n }\n ]\n .map(f => f.fieldId)\n .join(\".\");\n\n collection[fieldId] = {\n ...field,\n parents,\n system: false,\n createPath: params => {\n if (valuePathPlugin) {\n return valuePathPlugin.createPath(params);\n }\n\n return [\"values\"]\n .concat(parents.map(parent => parent.fieldId))\n .concat([params.field.fieldId])\n .join(\".\");\n },\n transform: value => {\n if (!transformPlugin) {\n return value;\n }\n return transformPlugin.transform({\n field,\n value\n });\n }\n };\n const childFields = field.settings?.fields;\n if (!childFields || childFields.length === 0) {\n continue;\n }\n addFieldsToCollection(childFields, [\n ...parents,\n {\n fieldId: field.fieldId,\n multipleValues: field.multipleValues\n }\n ]);\n }\n };\n\n addFieldsToCollection(fields);\n\n return collection;\n};\n"],"mappings":";;;;;;;;AACA;AAIA;AACA;AAMA;AACA;AACA;AACA;AACA;AACO,MAAMA,YAAY,GAAIC,MAAc,IAAK;EAC5C,MAAM;IAAEC,MAAM;IAAEC;EAAQ,CAAC,GAAGF,MAAM;EAElC,MAAMG,qBAAqB,GAAG,IAAAC,4BAAgB,EAAqC;IAC/EF,OAAO;IACPG,IAAI,E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Fields","CmsEntryFieldFilterPathPlugin","getMappedPlugins","getBaseFieldType","createFieldCollection","params","fields","parents","transformValuePlugins","valuePathPlugins","system","reduce","collection","field","fieldType","transformPlugin","valuePathPlugin","fieldId","list","map","f","join","createPath","canUse","p","parent","concat","transform","value","childFields","settings","length","result","Object","assign","createFields","plugins","type","property"],"sources":["createFields.ts"],"sourcesContent":["import type { CmsModelField } from \"@webiny/api-headless-cms/types/index.js\";\nimport { createSystemFields } from \"./systemFields.js\";\nimport type { Field, FieldParent } from \"./types.js\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport type { CmsFieldFilterValueTransformPlugin } from \"~/types.js\";\nimport { CmsEntryFieldFilterPathPlugin } from \"~/plugins/index.js\";\nimport { getMappedPlugins } from \"./mapPlugins.js\";\nimport { getBaseFieldType } from \"@webiny/api-headless-cms/utils/getBaseFieldType.js\";\n\ninterface Params {\n fields: CmsModelField[];\n plugins: PluginsContainer;\n}\n\ninterface FieldCollection {\n [key: string]: Field;\n}\n\ninterface AddFieldsToCollectionParams {\n fields: CmsModelField[];\n parents: FieldParent[];\n transformValuePlugins: Record<string, CmsFieldFilterValueTransformPlugin>;\n valuePathPlugins: Record<string, CmsEntryFieldFilterPathPlugin>;\n system: boolean;\n}\n\nconst createFieldCollection = (params: AddFieldsToCollectionParams): FieldCollection => {\n const { fields, parents, transformValuePlugins, valuePathPlugins, system } = params;\n return fields.reduce<FieldCollection>((collection, field) => {\n const fieldType = getBaseFieldType(field);\n const transformPlugin = transformValuePlugins[fieldType];\n const valuePathPlugin = valuePathPlugins[fieldType];\n\n /**\n * The required fieldId is a product of all of its parents and its own fieldId.\n */\n const fieldId = [\n ...parents,\n {\n fieldId: field.fieldId,\n list: field.list\n }\n ]\n .map(f => f.fieldId)\n .join(\".\");\n\n collection[fieldId] = {\n ...field,\n parents,\n system,\n createPath: params => {\n if (\n valuePathPlugin &&\n valuePathPlugin.canUse(\n field,\n parents.map(p => p.fieldId)\n )\n ) {\n return valuePathPlugin.createPath(params);\n }\n\n return parents\n .map(parent => parent.fieldId)\n .concat([params.field.fieldId])\n .join(\".\");\n },\n transform: value => {\n if (!transformPlugin) {\n return value;\n }\n return transformPlugin.transform({\n field,\n value\n });\n }\n };\n const childFields = field.settings?.fields;\n if (!childFields?.length) {\n return collection;\n }\n\n const result = createFieldCollection({\n fields: childFields,\n parents: [\n ...parents,\n {\n fieldId: field.fieldId,\n list: field.list\n }\n ],\n transformValuePlugins,\n valuePathPlugins,\n system\n });\n Object.assign(collection, result);\n return collection;\n }, {});\n};\n/**\n * This method will map the fieldId (fieldId -> field) to the actual field.\n *\n * In case of nested fields, fieldId is all the parent fieldIds + current one, joined by the dot (.).\n */\nexport const createFields = (params: Params) => {\n const { fields, plugins } = params;\n\n const transformValuePlugins = getMappedPlugins<CmsFieldFilterValueTransformPlugin>({\n plugins,\n type: \"cms-field-filter-value-transform\",\n property: \"fieldType\"\n });\n const valuePathPlugins = getMappedPlugins<CmsEntryFieldFilterPathPlugin>({\n plugins,\n type: CmsEntryFieldFilterPathPlugin.type,\n property: \"fieldType\"\n });\n\n const collection = createFieldCollection({\n fields: createSystemFields(),\n transformValuePlugins,\n valuePathPlugins,\n parents: [],\n system: true\n });\n\n const result = createFieldCollection({\n fields,\n transformValuePlugins,\n valuePathPlugins,\n parents: [\n {\n fieldId: \"values\",\n list: false\n }\n ],\n system: false\n });\n\n return {\n ...collection,\n ...result\n };\n};\n"],"mappings":"AACA,SAASA,kBAAkB;AAI3B,SAASC,6BAA6B;AACtC,SAASC,gBAAgB;AACzB,SAASC,gBAAgB,QAAQ,oDAAoD;AAmBrF,MAAMC,qBAAqB,GAAIC,MAAmC,IAAsB;EACpF,MAAM;IAAEC,MAAM;IAAEC,OAAO;IAAEC,qBAAqB;IAAEC,gBAAgB;IAAEC;EAAO,CAAC,GAAGL,MAAM;EACnF,OAAOC,MAAM,CAACK,MAAM,CAAkB,CAACC,UAAU,EAAEC,KAAK,KAAK;IACzD,MAAMC,SAAS,GAAGX,gB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luginsContainer } from "@webiny/plugins";
3
- import { CmsModel } from "@webiny/api-headless-cms/types";
4
- interface Result {
1
+ import type { Field } from "./types.js";
2
+ import type { PluginsContainer } from "@webiny/plugins";
3
+ import type { CmsModel } from "@webiny/api-headless-cms/types/index.js";
4
+ interface IResponse {
5
5
  valuePath: string;
6
6
  reverse: boolean;
7
7
  fieldId: string;
8
8
  field: Field;
9
9
  }
10
- interface Params {
10
+ interface IParams {
11
11
  model: CmsModel;
12
12
  sortBy: string;
13
13
  fields: Record<string, Field>;
14
14
  plugins: PluginsContainer;
15
15
  }
16
- export declare const extractSort: (params: Params) => Result;
16
+ export declare const extractSort: (params: IParams) => IResponse;
17
17
  export {};
@@ -1,36 +1,52 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.extractSort = void 0;
8
- var _error = _interopRequireDefault(require("@webiny/error"));
9
- var _plugins = require("../../../plugins");
10
- const extractSort = params => {
1
+ import WebinyError from "@webiny/error";
2
+ import { CmsEntryFieldSortingPlugin } from "../../../plugins/index.js";
3
+ const extractSortInfo = sortBy => {
4
+ const rootSorting = sortBy.match(/^([a-zA-Z]+)_(ASC|DESC)$/);
5
+ if (rootSorting) {
6
+ return {
7
+ fieldId: rootSorting[1],
8
+ isValues: false,
9
+ order: rootSorting[2]
10
+ };
11
+ }
12
+ const valuesSorting = sortBy.match(/^values_([a-zA-Z0-9]+)_(ASC|DESC)$/);
13
+ if (valuesSorting) {
14
+ return {
15
+ fieldId: valuesSorting[1],
16
+ isValues: true,
17
+ order: valuesSorting[2]
18
+ };
19
+ }
20
+ throw new WebinyError("Problem in determining the sorting for the entry items.", "SORT_EXTRACT_ERROR", {
21
+ sortBy
22
+ });
23
+ };
24
+ export const extractSort = params => {
11
25
  const {
12
26
  model,
13
27
  sortBy,
14
28
  fields,
15
29
  plugins
16
30
  } = params;
17
- const result = sortBy.split("_");
18
- if (result.length !== 2) {
19
- throw new _error.default("Problem in determining the sorting for the entry items.", "SORT_EXTRACT_ERROR", {
20
- sortBy
21
- });
22
- }
23
- const [fieldId, order] = result;
24
- const field = Object.values(fields).find(field => {
31
+ const {
32
+ fieldId,
33
+ isValues: isValuesSorting,
34
+ order
35
+ } = extractSortInfo(sortBy);
36
+ const field = Object.values(fields).find(f => {
25
37
  /**
26
38
  * We do not support sorting by nested fields.
27
39
  */
28
- if (field.parents.length > 0) {
40
+ const isValues = f.parents[0]?.fieldId === "values";
41
+ if (isValues && isValuesSorting) {
42
+ return f.fieldId === fieldId;
43
+ }
44
+ if (f.parents.length > 0) {
29
45
  return false;
30
46
  }
31
- return field.fieldId === fieldId;
47
+ return f.fieldId === fieldId;
32
48
  });
33
- const plugin = plugins.byType(_plugins.CmsEntryFieldSortingPlugin.type).reverse().find(plugin => {
49
+ const plugin = plugins.byType(CmsEntryFieldSortingPlugin.type).reverse().find(plugin => {
34
50
  return plugin.canUse({
35
51
  model,
36
52
  field,
@@ -49,7 +65,7 @@ const extractSort = params => {
49
65
  fields
50
66
  });
51
67
  } else if (!field) {
52
- throw new _error.default("Sorting field does not exist in the content model.", "SORTING_FIELD_ERROR", {
68
+ throw new WebinyError("Sorting field does not exist in the content model.", "SORTING_FIELD_ERROR", {
53
69
  fieldId,
54
70
  fields
55
71
  });
@@ -64,4 +80,5 @@ const extractSort = params => {
64
80
  reverse: order === "DESC"
65
81
  };
66
82
  };
67
- exports.extractSort = extractSort;
83
+
84
+ //# sourceMappingURL=extractSort.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["extractSort","params","model","sortBy","fields","plugins","result","split","length","WebinyError","fieldId","order","field","Object","values","find","parents","plugin","byType","CmsEntryFieldSortingPlugin","type","reverse","canUse","createSort","valuePath","createPath"],"sources":["extractSort.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { Field } from \"./types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { CmsEntryFieldSortingPlugin } from \"~/plugins\";\nimport { CmsModel } from \"@webiny/api-headless-cms/types\";\n\ninterface Result {\n valuePath: string;\n reverse: boolean;\n fieldId: string;\n field: Field;\n}\n\ninterface Params {\n model: CmsModel;\n sortBy: string;\n fields: Record<string, Field>;\n plugins: PluginsContainer;\n}\n\nexport const extractSort = (params: Params): Result => {\n const { model, sortBy, fields, plugins } = params;\n const result = sortBy.split(\"_\");\n if (result.length !== 2) {\n throw new WebinyError(\n \"Problem in determining the sorting for the entry items.\",\n \"SORT_EXTRACT_ERROR\",\n {\n sortBy\n }\n );\n }\n const [fieldId, order] = result as [string, \"ASC\" | \"DESC\"];\n\n const field = Object.values(fields).find(field => {\n /**\n * We do not support sorting by nested fields.\n */\n if (field.parents.length > 0) {\n return false;\n }\n return field.fieldId === fieldId;\n });\n\n const plugin = plugins\n .byType<CmsEntryFieldSortingPlugin>(CmsEntryFieldSortingPlugin.type)\n .reverse()\n .find(plugin => {\n return plugin.canUse({\n model,\n field,\n fieldId,\n order,\n sortBy\n });\n });\n\n if (plugin) {\n return plugin.createSort({\n model,\n fieldId,\n order,\n sortBy,\n field,\n fields\n });\n } else if (!field) {\n throw new WebinyError(\n \"Sorting field does not exist in the content model.\",\n \"SORTING_FIELD_ERROR\",\n {\n fieldId,\n fields\n }\n );\n }\n const valuePath = field.createPath({\n field\n });\n return {\n field,\n fieldId,\n valuePath,\n reverse: order === \"DESC\"\n };\n};\n"],"mappings":";;;;;;;AAAA;AAGA;AAiBO,MAAMA,WAAW,GAAIC,MAAc,IAAa;EACnD,MAAM;IAAEC,KAAK;IAAEC,MAAM;IAAEC,MAAM;IAAEC;EAAQ,CAAC,GAAGJ,MAAM;EACjD,MAAMK,MAAM,GAAGH,MAAM,CAACI,KAAK,CAAC,GAAG,CAAC;EAChC,IAAID,MAAM,CAACE,MAAM,KAAK,CAAC,EAAE;IACrB,MAAM,IAAIC,cAAW,CACjB,yDAAyD,EACzD,oBAAoB,EACpB;MACIN;IACJ,CAAC,CACJ;EACL;EACA,MAAM,CAACO,OAAO,EAAEC,KAAK,CAAC,GAAGL,MAAkC;EAE3D,MAAMM,KAAK,GAAGC,MAAM,CAACC,MAAM,CAACV,MAAM,CAAC,CAACW,IAAI,CAACH,KAAK,IAAI;IAC9C;AACR;AACA;IACQ,IAAIA,KAAK,CAACI,OAAO,CAACR,MAAM,GAAG,CAAC,EAAE;MAC1B,OAAO,KAAK;IAChB;IACA,OAAOI,KAAK,CAACF,OAAO,KAAKA,OAAO;EACpC,CAAC,CAAC;EAEF,MAAMO,MAAM,GAAGZ,OAAO,CACjBa,MAAM,CAA6BC,mCAA0B,CAACC,IAAI,CAAC,CACnEC,OAAO,EAAE,CACTN,IAAI,CAACE,MAAM,IAAI;IACZ,OAAOA,MAAM,CAACK,MAAM,CAAC;MACjBpB,KAAK;MACLU,KAAK;MACLF,OAAO;MACPC,KAAK;MACLR;IACJ,CAAC,CAAC;EACN,CAAC,CAAC;EAEN,IAAIc,MAAM,EAAE;IACR,OAAOA,MAAM,CAACM,UAAU,CAAC;MACrBrB,KAAK;MACLQ,OAAO;MACPC,KAAK;MACLR,MAAM;MACNS,KAAK;MACLR;IACJ,CAAC,CAAC;EACN,CAAC,MAAM,IAAI,CAACQ,KAAK,EAAE;IACf,MAAM,IAAIH,cAAW,CACjB,oDAAoD,EACpD,qBAAqB,EACrB;MACIC,OAAO;MACPN;IACJ,CAAC,CACJ;EACL;EACA,MAAMoB,SAAS,GAAGZ,KAAK,CAACa,UAAU,CAAC;IAC/Bb;EACJ,CAAC,CAAC;EACF,OAAO;IACHA,KAAK;IACLF,OAAO;IACPc,SAAS;IACTH,OAAO,EAAEV,KAAK,KAAK;EACvB,CAAC;AACL,CAAC;AAAC"}
1
+ {"version":3,"names":["WebinyError","CmsEntryFieldSortingPlugin","extractSortInfo","sortBy","rootSorting","match","fieldId","isValues","order","valuesSorting","extractSort","params","model","fields","plugins","isValuesSorting","field","Object","values","find","f","parents","length","plugin","byType","type","reverse","canUse","createSort","valuePath","createPath"],"sources":["extractSort.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { Field } from \"./types.js\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport { CmsEntryFieldSortingPlugin } from \"~/plugins/index.js\";\nimport type { CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\n\nconst extractSortInfo = (sortBy: string) => {\n const rootSorting = sortBy.match(/^([a-zA-Z]+)_(ASC|DESC)$/);\n if (rootSorting) {\n return {\n fieldId: rootSorting[1],\n isValues: false,\n order: rootSorting[2] as \"ASC\" | \"DESC\"\n };\n }\n const valuesSorting = sortBy.match(/^values_([a-zA-Z0-9]+)_(ASC|DESC)$/);\n if (valuesSorting) {\n return {\n fieldId: valuesSorting[1],\n isValues: true,\n order: valuesSorting[2] as \"ASC\" | \"DESC\"\n };\n }\n throw new WebinyError(\n \"Problem in determining the sorting for the entry items.\",\n \"SORT_EXTRACT_ERROR\",\n {\n sortBy\n }\n );\n};\n\ninterface IResponse {\n valuePath: string;\n reverse: boolean;\n fieldId: string;\n field: Field;\n}\n\ninterface IParams {\n model: CmsModel;\n sortBy: string;\n fields: Record<string, Field>;\n plugins: PluginsContainer;\n}\n\nexport const extractSort = (params: IParams): IResponse => {\n const { model, sortBy, fields, plugins } = params;\n const { fieldId, isValues: isValuesSorting, order } = extractSortInfo(sortBy);\n\n const field = Object.values(fields).find(f => {\n /**\n * We do not support sorting by nested fields.\n */\n const isValues = f.parents[0]?.fieldId === \"values\";\n if (isValues && isValuesSorting) {\n return f.fieldId === fieldId;\n }\n if (f.parents.length > 0) {\n return false;\n }\n return f.fieldId === fieldId;\n });\n\n const plugin = plugins\n .byType<CmsEntryFieldSortingPlugin>(CmsEntryFieldSortingPlugin.type)\n .reverse()\n .find(plugin => {\n return plugin.canUse({\n model,\n field,\n fieldId,\n order,\n sortBy\n });\n });\n\n if (plugin) {\n return plugin.createSort({\n model,\n fieldId,\n order,\n sortBy,\n field,\n fields\n });\n } else if (!field) {\n throw new WebinyError(\n \"Sorting field does not exist in the content model.\",\n \"SORTING_FIELD_ERROR\",\n {\n fieldId,\n fields\n }\n );\n }\n const valuePath = field.createPath({\n field\n });\n return {\n field,\n fieldId,\n valuePath,\n reverse: order === \"DESC\"\n };\n};\n"],"mappings":"AAAA,OAAOA,WAAW,MAAM,eAAe;AAGvC,SAASC,0BAA0B;AAGnC,MAAMC,eAAe,GAAIC,MAAc,IAAK;EACxC,MAAMC,WAAW,GAAGD,MAAM,CAACE,KAAK,CAAC,0BAA0B,CAAC;EAC5D,IAAID,WAAW,EAAE;IACb,OAAO;MACHE,OAAO,EAAEF,WAAW,CAAC,CAAC,CAAC;MACvBG,QAAQ,EAAE,KAAK;MACfC,KAAK,EAAEJ,WAAW,CAAC,CAAC;IACxB,CAAC;EACL;EACA,MAAMK,aAAa,GAAGN,MAAM,CAACE,KAAK,CAAC,oCAAoC,CAAC;EACxE,IAAII,aAAa,EAAE;IACf,OAAO;MACHH,OAAO,EAAEG,aAAa,CAAC,CAAC,CAAC;MACzBF,QAAQ,EAAE,IAAI;MACdC,KAAK,EAAEC,aAAa,CAAC,CAAC;IAC1B,CAAC;EACL;EACA,MAAM,IAAIT,WAAW,CACjB,yDAAyD,EACzD,oBAAoB,EACpB;IACIG;EACJ,CACJ,CAAC;AACL,CAAC;AAgBD,OAAO,MAAMO,WAAW,GAAIC,MAAe,IAAgB;EACvD,MAAM;IAAEC,KAAK;IAAET,MAAM;IAAEU,MAAM;IAAEC;EAAQ,CAAC,GAAGH,MAAM;EACjD,MAAM;IAAEL,OAAO;IAAEC,QAAQ,EAAEQ,eAAe;IAAEP;EAAM,CAAC,GAAGN,eAAe,CAACC,MAAM,CAAC;EAE7E,MAAMa,KAAK,GAAGC,MAAM,CAACC,MAAM,CAACL,MAAM,CAAC,CAACM,IAAI,CAACC,CAAC,IAAI;IAC1C;AACR;AACA;IACQ,MAAMb,QAAQ,GAAGa,CAAC,CAACC,OAAO,CAAC,CAAC,CAAC,EAAEf,OAAO,KAAK,QAAQ;IACnD,IAAIC,QAAQ,IAAIQ,eAAe,EAAE;MAC7B,OAAOK,CAAC,CAACd,OAAO,KAAKA,OAAO;IAChC;IACA,IAAIc,CAAC,CAACC,OAAO,CAACC,MAAM,GAAG,CAAC,EAAE;MACtB,OAAO,KAAK;IAChB;IACA,OAAOF,CAAC,CAACd,OAAO,KAAKA,OAAO;EAChC,CAAC,CAAC;EAEF,MAAMiB,MAAM,GAAGT,OAAO,CACjBU,MAAM,CAA6BvB,0BAA0B,CAACwB,IAAI,CAAC,CACnEC,OAAO,CAAC,CAAC,CACTP,IAAI,CAACI,MAAM,IAAI;IACZ,OAAOA,MAAM,CAACI,MAAM,CAAC;MACjBf,KAAK;MACLI,KAAK;MACLV,OAAO;MACPE,KAAK;MACLL;IACJ,CAAC,CAAC;EACN,CAAC,CAAC;EAEN,IAAIoB,MAAM,EAAE;IACR,OAAOA,MAAM,CAACK,UAAU,CAAC;MACrBhB,KAAK;MACLN,OAAO;MACPE,KAAK;MACLL,MAAM;MACNa,KAAK;MACLH;IACJ,CAAC,CAAC;EACN,CAAC,MAAM,IAAI,CAACG,KAAK,EAAE;IACf,MAAM,IAAIhB,WAAW,CACjB,oDAAoD,EACpD,qBAAqB,EACrB;MACIM,OAAO;MACPO;IACJ,CACJ,CAAC;EACL;EACA,MAAMgB,SAAS,GAAGb,KAAK,CAACc,UAAU,CAAC;IAC/Bd;EACJ,CAAC,CAAC;EACF,OAAO;IACHA,KAAK;IACLV,OAAO;IACPuB,SAAS;IACTH,OAAO,EAAElB,KAAK,KAAK;EACvB,CAAC;AACL,CAAC","ignoreList":[]}
@@ -1,8 +1,8 @@
1
- import { CmsEntry, CmsEntryListWhere } from "@webiny/api-headless-cms/types";
2
- import { PluginsContainer } from "@webiny/plugins";
3
- import { Field } from "./types";
4
- interface Params {
5
- items: CmsEntry[];
1
+ import type { CmsEntry, CmsEntryListWhere, CmsEntryValues } from "@webiny/api-headless-cms/types/index.js";
2
+ import type { PluginsContainer } from "@webiny/plugins";
3
+ import type { Field } from "./types.js";
4
+ interface Params<T extends CmsEntryValues = CmsEntryValues> {
5
+ items: CmsEntry<T>[];
6
6
  where: Partial<CmsEntryListWhere>;
7
7
  plugins: PluginsContainer;
8
8
  fields: Record<string, Field>;
@@ -11,5 +11,5 @@ interface Params {
11
11
  fields?: string[];
12
12
  };
13
13
  }
14
- export declare const filter: (params: Params) => CmsEntry[];
14
+ export declare const filter: <T extends CmsEntryValues = CmsEntryValues>(params: Params<T>) => CmsEntry<T>[];
15
15
  export {};
@@ -1,22 +1,26 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.filter = void 0;
8
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
- var _ValueFilterPlugin = require("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin");
10
- var _error = _interopRequireDefault(require("@webiny/error"));
11
- var _fullTextSearch = require("./fullTextSearch");
12
- var _createExpressions = require("./createExpressions");
13
- var _transform = require("./transform");
14
- var _getValue = require("./getValue");
1
+ import { ValueFilterPlugin } from "@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin.js";
2
+ import WebinyError from "@webiny/error";
3
+ import { createFullTextSearch } from "./fullTextSearch.js";
4
+ import { createExpressions } from "./createExpressions.js";
5
+ import { transformValue } from "./transform.js";
6
+ import { getValue } from "./getValue.js";
15
7
  const executeFilter = params => {
16
8
  const {
17
9
  value,
18
10
  filter
19
11
  } = params;
12
+
13
+ /**
14
+ * We need to check if the filter can be used.
15
+ * If it cannot, we will just return true.
16
+ */
17
+ const canUse = filter.plugin.canUse({
18
+ value,
19
+ compareValue: filter.compareValue
20
+ });
21
+ if (!canUse) {
22
+ return true;
23
+ }
20
24
  const matched = filter.plugin.matches({
21
25
  value,
22
26
  compareValue: filter.compareValue
@@ -57,9 +61,10 @@ const executeExpressions = params => {
57
61
  * Then we move onto expressions, which are basically nested upon nested filters with different conditions.
58
62
  */
59
63
  for (const expression of expressions) {
60
- const result = executeExpressions((0, _objectSpread2.default)((0, _objectSpread2.default)({}, expression), {}, {
64
+ const result = executeExpressions({
65
+ ...expression,
61
66
  getCachedValue
62
- }));
67
+ });
63
68
  if (result && condition === "OR") {
64
69
  return true;
65
70
  } else if (!result && condition == "AND") {
@@ -73,7 +78,7 @@ const executeExpressions = params => {
73
78
  */
74
79
  return condition === "OR" ? false : true;
75
80
  };
76
- const filter = params => {
81
+ export const filter = params => {
77
82
  const {
78
83
  items: records,
79
84
  where,
@@ -85,7 +90,7 @@ const filter = params => {
85
90
  if (keys.length === 0 && !fullTextSearch) {
86
91
  return records;
87
92
  }
88
- const expression = (0, _createExpressions.createExpressions)({
93
+ const expression = createExpressions({
89
94
  plugins,
90
95
  where,
91
96
  fields
@@ -94,19 +99,19 @@ const filter = params => {
94
99
  /**
95
100
  * No point in going further if there are no expressions to be applied and no full text search to be executed.
96
101
  */
97
- if (expression.filters.length === 0 && expression.expressions.length === 0 && !(fullTextSearch !== null && fullTextSearch !== void 0 && fullTextSearch.term)) {
102
+ if (expression.filters.length === 0 && expression.expressions.length === 0 && !fullTextSearch?.term) {
98
103
  return records;
99
104
  }
100
105
  /**
101
106
  * We need the contains plugin to run the full text search.
102
107
  */
103
- const fullTextSearchPlugin = plugins.byType(_ValueFilterPlugin.ValueFilterPlugin.type).find(plugin => plugin.getOperation() === "contains");
108
+ const fullTextSearchPlugin = plugins.byType(ValueFilterPlugin.type).find(plugin => plugin.getOperation() === "contains");
104
109
  if (!fullTextSearchPlugin) {
105
- throw new _error.default(`Missing "contains" plugin to run the full-text search.`, "MISSING_PLUGIN");
110
+ throw new WebinyError(`Missing "contains" plugin to run the full-text search.`, "MISSING_PLUGIN");
106
111
  }
107
- const search = (0, _fullTextSearch.createFullTextSearch)({
108
- term: fullTextSearch === null || fullTextSearch === void 0 ? void 0 : fullTextSearch.term,
109
- targetFields: fullTextSearch === null || fullTextSearch === void 0 ? void 0 : fullTextSearch.fields,
112
+ const search = createFullTextSearch({
113
+ term: fullTextSearch?.term,
114
+ targetFields: fullTextSearch?.fields,
110
115
  fields,
111
116
  plugin: fullTextSearchPlugin
112
117
  });
@@ -119,17 +124,18 @@ const filter = params => {
119
124
  if (cachedValues[path] !== undefined) {
120
125
  return cachedValues[path];
121
126
  }
122
- const plainValue = (0, _getValue.getValue)(record, path);
123
- const rawValue = (0, _transform.transformValue)({
127
+ const plainValue = getValue(record, path);
128
+ const rawValue = transformValue({
124
129
  value: plainValue,
125
130
  transform: filter.transformValue
126
131
  });
127
132
  cachedValues[path] = rawValue;
128
133
  return rawValue;
129
134
  };
130
- const exprResult = executeExpressions((0, _objectSpread2.default)((0, _objectSpread2.default)({}, expression), {}, {
135
+ const exprResult = executeExpressions({
136
+ ...expression,
131
137
  getCachedValue
132
- }));
138
+ });
133
139
  /**
134
140
  * If expression result is false we do not need to continue further.
135
141
  * Also, if there is no full text search defined, just return the expression result.
@@ -140,4 +146,5 @@ const filter = params => {
140
146
  return search(record);
141
147
  });
142
148
  };
143
- exports.filter = filter;
149
+
150
+ //# sourceMappingURL=filter.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["executeFilter","params","value","filter","matched","plugin","matches","compareValue","negate","executeExpressions","expressions","getCachedValue","filters","condition","length","result","expression","items","records","where","plugins","fields","fullTextSearch","keys","Object","createExpressions","term","fullTextSearchPlugin","byType","ValueFilterPlugin","type","find","getOperation","WebinyError","search","createFullTextSearch","targetFields","record","cachedValues","path","undefined","plainValue","getValue","rawValue","transformValue","transform","exprResult"],"sources":["filter.ts"],"sourcesContent":["import { CmsEntry, CmsEntryListWhere } from \"@webiny/api-headless-cms/types\";\nimport { ValueFilterPlugin } from \"@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin\";\nimport WebinyError from \"@webiny/error\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { Field } from \"./types\";\nimport { createFullTextSearch } from \"./fullTextSearch\";\nimport { createExpressions, Expression, ExpressionCondition, Filter } from \"./createExpressions\";\nimport { transformValue } from \"./transform\";\nimport { getValue } from \"~/operations/entry/filtering/getValue\";\n\ninterface ExecuteFilterParams {\n value: any;\n filter: Filter;\n}\n\nconst executeFilter = (params: ExecuteFilterParams) => {\n const { value, filter } = params;\n\n const matched = filter.plugin.matches({\n value,\n compareValue: filter.compareValue\n });\n if (filter.negate) {\n return matched === false;\n }\n return matched;\n};\n\ninterface ExecuteExpressionsParams {\n getCachedValue: (filter: Filter) => Promise<any>;\n expressions: Expression[];\n filters: Filter[];\n condition: ExpressionCondition;\n}\n\nconst executeExpressions = (params: ExecuteExpressionsParams): boolean => {\n const { expressions, getCachedValue, filters, condition } = params;\n if (expressions.length === 0 && filters.length === 0) {\n return true;\n }\n /**\n * Always run filters first as they might trigger an early return.\n */\n for (const filter of filters) {\n const value = getCachedValue(filter);\n\n const result = executeFilter({\n value,\n filter\n });\n /**\n * Filters are ALWAYS executed as an AND.\n * So if even one is false, everything false.\n */\n if (!result) {\n return false;\n }\n }\n /**\n * Then we move onto expressions, which are basically nested upon nested filters with different conditions.\n */\n for (const expression of expressions) {\n const result = executeExpressions({\n ...expression,\n getCachedValue\n });\n if (result && condition === \"OR\") {\n return true;\n } else if (!result && condition == \"AND\") {\n return false;\n }\n }\n /**\n * If condition is an OR, we can fail the expressions check because the code would return a lot earlier than this line.\n *\n * Also, if condition is not an OR, we can say that the expressions check is ok, because it would fail a lot earlier than this line.\n */\n return condition === \"OR\" ? false : true;\n};\n\ninterface Params {\n items: CmsEntry[];\n where: Partial<CmsEntryListWhere>;\n plugins: PluginsContainer;\n fields: Record<string, Field>;\n fullTextSearch?: {\n term?: string;\n fields?: string[];\n };\n}\n\nexport const filter = (params: Params): CmsEntry[] => {\n const { items: records, where, plugins, fields, fullTextSearch } = params;\n\n const keys = Object.keys(where);\n if (keys.length === 0 && !fullTextSearch) {\n return records;\n }\n const expression = createExpressions({\n plugins,\n where,\n fields\n });\n\n /**\n * No point in going further if there are no expressions to be applied and no full text search to be executed.\n */\n if (\n expression.filters.length === 0 &&\n expression.expressions.length === 0 &&\n !fullTextSearch?.term\n ) {\n return records;\n }\n /**\n * We need the contains plugin to run the full text search.\n */\n const fullTextSearchPlugin = plugins\n .byType<ValueFilterPlugin>(ValueFilterPlugin.type)\n .find(plugin => plugin.getOperation() === \"contains\");\n if (!fullTextSearchPlugin) {\n throw new WebinyError(\n `Missing \"contains\" plugin to run the full-text search.`,\n \"MISSING_PLUGIN\"\n );\n }\n\n const search = createFullTextSearch({\n term: fullTextSearch?.term,\n targetFields: fullTextSearch?.fields,\n fields,\n plugin: fullTextSearchPlugin\n });\n\n return records.filter(record => {\n const cachedValues: Record<string, any> = {};\n\n const getCachedValue = (filter: Filter) => {\n const { path } = filter;\n if (cachedValues[path] !== undefined) {\n return cachedValues[path];\n }\n const plainValue = getValue(record, path);\n\n const rawValue = transformValue({\n value: plainValue,\n transform: filter.transformValue\n });\n\n cachedValues[path] = rawValue;\n return rawValue;\n };\n\n const exprResult = executeExpressions({ ...expression, getCachedValue });\n /**\n * If expression result is false we do not need to continue further.\n * Also, if there is no full text search defined, just return the expression result.\n */\n if (!exprResult || !search) {\n return exprResult;\n }\n\n return search(record);\n });\n};\n"],"mappings":";;;;;;;;AACA;AACA;AAGA;AACA;AACA;AACA;AAOA,MAAMA,aAAa,GAAIC,MAA2B,IAAK;EACnD,MAAM;IAAEC,KAAK;IAAEC;EAAO,CAAC,GAAGF,MAAM;EAEhC,MAAMG,OAAO,GAAGD,MAAM,CAACE,MAAM,CAACC,OAAO,CAAC;IAClCJ,KAAK;IACLK,YAAY,EAAEJ,MAAM,CAACI;EACzB,CAAC,CAAC;EACF,IAAIJ,MAAM,CAACK,MAAM,EAAE;IACf,OAAOJ,OAAO,KAAK,KAAK;EAC5B;EACA,OAAOA,OAAO;AAClB,CAAC;AASD,MAAMK,kBAAkB,GAAIR,MAAgC,IAAc;EACtE,MAAM;IAAES,WAAW;IAAEC,cAAc;IAAEC,OAA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AOA,QAAQ;IACnB,CAAC;IAED,MAAMG,UAAU,GAAGrC,kBAAkB,6DAAMO,UAAU;MAAEL;IAAc,GAAG;IACxE;AACR;AACA;AACA;IACQ,IAAI,CAACmC,UAAU,IAAI,CAACZ,MAAM,EAAE;MACxB,OAAOY,UAAU;IACrB;IAEA,OAAOZ,MAAM,CAACG,MAAM,CAAC;EACzB,CAAC,CAAC;AACN,CAAC;AAAC"}
1
+ {"version":3,"names":["ValueFilterPlugin","WebinyError","createFullTextSearch","createExpressions","transformValue","getValue","executeFilter","params","value","filter","canUse","plugin","compareValue","matched","matches","negate","executeExpressions","expressions","getCachedValue","filters","condition","length","result","expression","items","records","where","plugins","fields","fullTextSearch","keys","Object","term","fullTextSearchPlugin","byType","type","find","getOperation","search","targetFields","record","cachedValues","path","undefined","plainValue","rawValue","transform","exprResult"],"sources":["filter.ts"],"sourcesContent":["import type {\n CmsEntry,\n CmsEntryListWhere,\n CmsEntryValues\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { ValueFilterPlugin } from \"@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin.js\";\nimport WebinyError from \"@webiny/error\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport type { Field } from \"./types.js\";\nimport { createFullTextSearch } from \"./fullTextSearch.js\";\nimport type { Expression, ExpressionCondition, Filter } from \"./createExpressions.js\";\nimport { createExpressions } from \"./createExpressions.js\";\nimport { transformValue } from \"./transform.js\";\nimport { getValue } from \"~/operations/entry/filtering/getValue.js\";\n\ninterface ExecuteFilterParams {\n value: any;\n filter: Filter;\n}\n\nconst executeFilter = (params: ExecuteFilterParams) => {\n const { value, filter } = params;\n\n /**\n * We need to check if the filter can be used.\n * If it cannot, we will just return true.\n */\n const canUse = filter.plugin.canUse({\n value,\n compareValue: filter.compareValue\n });\n if (!canUse) {\n return true;\n }\n\n const matched = filter.plugin.matches({\n value,\n compareValue: filter.compareValue\n });\n if (filter.negate) {\n return matched === false;\n }\n return matched;\n};\n\ninterface ExecuteExpressionsParams {\n getCachedValue: (filter: Filter) => Promise<any>;\n expressions: Expression[];\n filters: Filter[];\n condition: ExpressionCondition;\n}\n\nconst executeExpressions = (params: ExecuteExpressionsParams): boolean => {\n const { expressions, getCachedValue, filters, condition } = params;\n if (expressions.length === 0 && filters.length === 0) {\n return true;\n }\n /**\n * Always run filters first as they might trigger an early return.\n */\n for (const filter of filters) {\n const value = getCachedValue(filter);\n\n const result = executeFilter({\n value,\n filter\n });\n /**\n * Filters are ALWAYS executed as an AND.\n * So if even one is false, everything false.\n */\n if (!result) {\n return false;\n }\n }\n /**\n * Then we move onto expressions, which are basically nested upon nested filters with different conditions.\n */\n for (const expression of expressions) {\n const result = executeExpressions({\n ...expression,\n getCachedValue\n });\n if (result && condition === \"OR\") {\n return true;\n } else if (!result && condition == \"AND\") {\n return false;\n }\n }\n /**\n * If condition is an OR, we can fail the expressions check because the code would return a lot earlier than this line.\n *\n * Also, if condition is not an OR, we can say that the expressions check is ok, because it would fail a lot earlier than this line.\n */\n return condition === \"OR\" ? false : true;\n};\n\ninterface Params<T extends CmsEntryValues = CmsEntryValues> {\n items: CmsEntry<T>[];\n where: Partial<CmsEntryListWhere>;\n plugins: PluginsContainer;\n fields: Record<string, Field>;\n fullTextSearch?: {\n term?: string;\n fields?: string[];\n };\n}\n\nexport const filter = <T extends CmsEntryValues = CmsEntryValues>(\n params: Params<T>\n): CmsEntry<T>[] => {\n const { items: records, where, plugins, fields, fullTextSearch } = params;\n\n const keys = Object.keys(where);\n if (keys.length === 0 && !fullTextSearch) {\n return records;\n }\n const expression = createExpressions({\n plugins,\n where,\n fields\n });\n\n /**\n * No point in going further if there are no expressions to be applied and no full text search to be executed.\n */\n if (\n expression.filters.length === 0 &&\n expression.expressions.length === 0 &&\n !fullTextSearch?.term\n ) {\n return records;\n }\n /**\n * We need the contains plugin to run the full text search.\n */\n const fullTextSearchPlugin = plugins\n .byType<ValueFilterPlugin>(ValueFilterPlugin.type)\n .find(plugin => plugin.getOperation() === \"contains\");\n if (!fullTextSearchPlugin) {\n throw new WebinyError(\n `Missing \"contains\" plugin to run the full-text search.`,\n \"MISSING_PLUGIN\"\n );\n }\n\n const search = createFullTextSearch({\n term: fullTextSearch?.term,\n targetFields: fullTextSearch?.fields,\n fields,\n plugin: fullTextSearchPlugin\n });\n\n return records.filter(record => {\n const cachedValues: Record<string, any> = {};\n\n const getCachedValue = (filter: Filter) => {\n const { path } = filter;\n if (cachedValues[path] !== undefined) {\n return cachedValues[path];\n }\n const plainValue = getValue(record, path);\n\n const rawValue = transformValue({\n value: plainValue,\n transform: filter.transformValue\n });\n\n cachedValues[path] = rawValue;\n return rawValue;\n };\n\n const exprResult = executeExpressions({ ...expression, getCachedValue });\n /**\n * If expression result is false we do not need to continue further.\n * Also, if there is no full text search defined, just return the expression result.\n */\n if (!exprResult || !search) {\n return exprResult;\n }\n\n return search(record);\n });\n};\n"],"mappings":"AAKA,SAASA,iBAAiB,QAAQ,8DAA8D;AAChG,OAAOC,WAAW,MAAM,eAAe;AAGvC,SAASC,oBAAoB;AAE7B,SAASC,iBAAiB;AAC1B,SAASC,cAAc;AACvB,SAASC,QAAQ;AAOjB,MAAMC,aAAa,GAAIC,MAA2B,IAAK;EACnD,MAAM;IAAEC,KAAK;IAAEC;EAAO,CAAC,GAAGF,MAAM;;EAEhC;AACJ;AACA;AACA;EACI,MAAMG,MAAM,GAAGD,MAAM,CAACE,MAAM,CAACD,MAAM,CAAC;IAChCF,KAAK;IACLI,YAAY,EAAEH,MAAM,CAACG;EACzB,CAAC,CAAC;EACF,IAAI,CAACF,MAAM,EAAE;IACT,OAAO,IAAI;EACf;EAEA,MAAMG,OAAO,GAAGJ,MAAM,CAACE,MAAM,CAACG,OAAO,CAAC;IAClCN,KAAK;IACLI,YAAY,EAAEH,MAAM,CAACG;EACzB,CAAC,CAAC;EACF,IAAIH,MAAM,CAACM,MAAM,EAAE;IACf,OAAOF,OAAO,KAAK,KAAK;EAC5B;EACA,OAAOA,OAAO;AACl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CAAC,GAAGG,QAAQ;MAC7B,OAAOA,QAAQ;IACnB,CAAC;IAED,MAAME,UAAU,GAAG/B,kBAAkB,CAAC;MAAE,GAAGO,UAAU;MAAEL;IAAe,CAAC,CAAC;IACxE;AACR;AACA;AACA;IACQ,IAAI,CAAC6B,UAAU,IAAI,CAACT,MAAM,EAAE;MACxB,OAAOS,UAAU;IACrB;IAEA,OAAOT,MAAM,CAACE,MAAM,CAAC;EACzB,CAAC,CAAC;AACN,CAAC","ignoreList":[]}
@@ -1,6 +1,6 @@
1
- import { ValueFilterPlugin } from "@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin";
2
- import { CmsEntry } from "@webiny/api-headless-cms/types";
3
- import { Field } from "./types";
1
+ import type { ValueFilterPlugin } from "@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin.js";
2
+ import type { CmsEntry } from "@webiny/api-headless-cms/types/index.js";
3
+ import type { Field } from "./types.js";
4
4
  interface Params {
5
5
  term?: string;
6
6
  targetFields?: string[];