@webiny/api-headless-cms-ddb 0.0.0-unstable.bca7b3e350 → 0.0.0-unstable.c27f4d8a31

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 (169) hide show
  1. package/README.md +6 -20
  2. package/definitions/entry.d.ts +4 -5
  3. package/definitions/entry.js +6 -89
  4. package/definitions/entry.js.map +1 -1
  5. package/definitions/group.d.ts +4 -5
  6. package/definitions/group.js +6 -63
  7. package/definitions/group.js.map +1 -1
  8. package/definitions/model.d.ts +4 -5
  9. package/definitions/model.js +6 -90
  10. package/definitions/model.js.map +1 -1
  11. package/definitions/table.d.ts +4 -6
  12. package/definitions/table.js +7 -28
  13. package/definitions/table.js.map +1 -1
  14. package/definitions/types.d.ts +60 -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 +8 -20
  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 +6 -20
  25. package/dynamoDb/path/plainObject.js.map +1 -1
  26. package/dynamoDb/storage/longText.js +13 -35
  27. package/dynamoDb/storage/longText.js.map +1 -1
  28. package/dynamoDb/storage/richText.js +27 -88
  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 -19
  32. package/dynamoDb/transformValue/datetime.js.map +1 -1
  33. package/index.d.ts +2 -2
  34. package/index.js +47 -111
  35. package/index.js.map +1 -1
  36. package/operations/entry/dataLoader/DataLoaderCache.d.ts +16 -0
  37. package/operations/entry/dataLoader/DataLoaderCache.js +31 -0
  38. package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -0
  39. package/operations/entry/dataLoader/constants.d.ts +1 -0
  40. package/operations/entry/dataLoader/constants.js +4 -0
  41. package/operations/entry/dataLoader/constants.js.map +1 -0
  42. package/operations/entry/dataLoader/createBatchScheduleFn.d.ts +8 -0
  43. package/operations/entry/dataLoader/createBatchScheduleFn.js +19 -0
  44. package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -0
  45. package/operations/entry/dataLoader/getAllEntryRevisions.d.ts +4 -0
  46. package/operations/entry/dataLoader/getAllEntryRevisions.js +35 -0
  47. package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -0
  48. package/operations/entry/dataLoader/getLatestRevisionByEntryId.d.ts +4 -0
  49. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +50 -0
  50. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -0
  51. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.d.ts +4 -0
  52. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +50 -0
  53. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -0
  54. package/operations/entry/dataLoader/getRevisionById.d.ts +4 -0
  55. package/operations/entry/dataLoader/getRevisionById.js +56 -0
  56. package/operations/entry/dataLoader/getRevisionById.js.map +1 -0
  57. package/operations/entry/dataLoader/index.d.ts +8 -0
  58. package/operations/entry/dataLoader/index.js +19 -0
  59. package/operations/entry/dataLoader/index.js.map +1 -0
  60. package/operations/entry/dataLoader/types.d.ts +6 -0
  61. package/operations/entry/dataLoader/types.js +3 -0
  62. package/operations/entry/dataLoader/types.js.map +1 -0
  63. package/operations/entry/dataLoaders.d.ts +14 -30
  64. package/operations/entry/dataLoaders.js +58 -271
  65. package/operations/entry/dataLoaders.js.map +1 -1
  66. package/operations/entry/filtering/createExpressions.d.ts +5 -5
  67. package/operations/entry/filtering/createExpressions.js +30 -68
  68. package/operations/entry/filtering/createExpressions.js.map +1 -1
  69. package/operations/entry/filtering/createFields.d.ts +6 -4
  70. package/operations/entry/filtering/createFields.js +86 -103
  71. package/operations/entry/filtering/createFields.js.map +1 -1
  72. package/operations/entry/filtering/extractSort.d.ts +6 -6
  73. package/operations/entry/filtering/extractSort.js +39 -32
  74. package/operations/entry/filtering/extractSort.js.map +1 -1
  75. package/operations/entry/filtering/filter.d.ts +6 -6
  76. package/operations/entry/filtering/filter.js +36 -64
  77. package/operations/entry/filtering/filter.js.map +1 -1
  78. package/operations/entry/filtering/fullTextSearch.d.ts +3 -3
  79. package/operations/entry/filtering/fullTextSearch.js +6 -24
  80. package/operations/entry/filtering/fullTextSearch.js.map +1 -1
  81. package/operations/entry/filtering/getValue.js +5 -27
  82. package/operations/entry/filtering/getValue.js.map +1 -1
  83. package/operations/entry/filtering/index.d.ts +2 -2
  84. package/operations/entry/filtering/index.js +3 -20
  85. package/operations/entry/filtering/index.js.map +1 -1
  86. package/operations/entry/filtering/mapPlugins.d.ts +2 -2
  87. package/operations/entry/filtering/mapPlugins.js +4 -18
  88. package/operations/entry/filtering/mapPlugins.js.map +1 -1
  89. package/operations/entry/filtering/plugins/defaultFilterCreate.d.ts +2 -2
  90. package/operations/entry/filtering/plugins/defaultFilterCreate.js +9 -20
  91. package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -1
  92. package/operations/entry/filtering/plugins/index.d.ts +1 -1
  93. package/operations/entry/filtering/plugins/index.js +7 -16
  94. package/operations/entry/filtering/plugins/index.js.map +1 -1
  95. package/operations/entry/filtering/plugins/objectFilterCreate.d.ts +2 -2
  96. package/operations/entry/filtering/plugins/objectFilterCreate.js +16 -39
  97. package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -1
  98. package/operations/entry/filtering/plugins/refFilterCreate.d.ts +3 -2
  99. package/operations/entry/filtering/plugins/refFilterCreate.js +21 -36
  100. package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -1
  101. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.d.ts +2 -0
  102. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js +57 -0
  103. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js.map +1 -0
  104. package/operations/entry/filtering/sort.d.ts +6 -6
  105. package/operations/entry/filtering/sort.js +17 -34
  106. package/operations/entry/filtering/sort.js.map +1 -1
  107. package/operations/entry/filtering/systemFields.d.ts +2 -4
  108. package/operations/entry/filtering/systemFields.js +102 -43
  109. package/operations/entry/filtering/systemFields.js.map +1 -1
  110. package/operations/entry/filtering/transform.d.ts +1 -1
  111. package/operations/entry/filtering/transform.js +2 -10
  112. package/operations/entry/filtering/transform.js.map +1 -1
  113. package/operations/entry/filtering/types.d.ts +3 -3
  114. package/operations/entry/filtering/types.js +2 -4
  115. package/operations/entry/filtering/types.js.map +1 -1
  116. package/operations/entry/filtering/values.d.ts +1 -1
  117. package/operations/entry/filtering/values.js +5 -17
  118. package/operations/entry/filtering/values.js.map +1 -1
  119. package/operations/entry/filtering/where.js +5 -15
  120. package/operations/entry/filtering/where.js.map +1 -1
  121. package/operations/entry/index.d.ts +3 -4
  122. package/operations/entry/index.js +732 -410
  123. package/operations/entry/index.js.map +1 -1
  124. package/operations/entry/keys.d.ts +40 -2
  125. package/operations/entry/keys.js +54 -47
  126. package/operations/entry/keys.js.map +1 -1
  127. package/operations/group/index.d.ts +4 -4
  128. package/operations/group/index.js +44 -91
  129. package/operations/group/index.js.map +1 -1
  130. package/operations/model/index.d.ts +3 -3
  131. package/operations/model/index.js +36 -70
  132. package/operations/model/index.js.map +1 -1
  133. package/package.json +22 -29
  134. package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +4 -3
  135. package/plugins/CmsEntryFieldFilterPathPlugin.js +14 -29
  136. package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -1
  137. package/plugins/CmsEntryFieldFilterPlugin.d.ts +10 -10
  138. package/plugins/CmsEntryFieldFilterPlugin.js +9 -19
  139. package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -1
  140. package/plugins/CmsEntryFieldSortingPlugin.d.ts +2 -2
  141. package/plugins/CmsEntryFieldSortingPlugin.js +5 -24
  142. package/plugins/CmsEntryFieldSortingPlugin.js.map +1 -1
  143. package/plugins/CmsFieldFilterValueTransformPlugin.d.ts +11 -0
  144. package/plugins/CmsFieldFilterValueTransformPlugin.js +16 -0
  145. package/plugins/CmsFieldFilterValueTransformPlugin.js.map +1 -0
  146. package/plugins/index.d.ts +4 -3
  147. package/plugins/index.js +5 -43
  148. package/plugins/index.js.map +1 -1
  149. package/types.d.ts +24 -19
  150. package/types.js +5 -13
  151. package/types.js.map +1 -1
  152. package/definitions/settings.d.ts +0 -9
  153. package/definitions/settings.js +0 -58
  154. package/definitions/settings.js.map +0 -1
  155. package/definitions/system.d.ts +0 -9
  156. package/definitions/system.js +0 -46
  157. package/definitions/system.js.map +0 -1
  158. package/dynamoDb/storage/date.d.ts +0 -3
  159. package/dynamoDb/storage/date.js +0 -109
  160. package/dynamoDb/storage/date.js.map +0 -1
  161. package/operations/entry/systemFields.d.ts +0 -2
  162. package/operations/entry/systemFields.js +0 -74
  163. package/operations/entry/systemFields.js.map +0 -1
  164. package/operations/settings/index.d.ts +0 -7
  165. package/operations/settings/index.js +0 -135
  166. package/operations/settings/index.js.map +0 -1
  167. package/operations/system/index.d.ts +0 -7
  168. package/operations/system/index.js +0 -99
  169. package/operations/system/index.js.map +0 -1
@@ -1,43 +1,52 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.extractSort = void 0;
9
-
10
- var _error = _interopRequireDefault(require("@webiny/error"));
11
-
12
- var _plugins = require("../../../plugins");
13
-
14
- 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 => {
15
25
  const {
16
26
  model,
17
27
  sortBy,
18
28
  fields,
19
29
  plugins
20
30
  } = params;
21
- const result = sortBy.split("_");
22
-
23
- if (result.length !== 2) {
24
- throw new _error.default("Problem in determining the sorting for the entry items.", "SORT_EXTRACT_ERROR", {
25
- sortBy
26
- });
27
- }
28
-
29
- const [fieldId, order] = result;
30
- 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 => {
31
37
  /**
32
38
  * We do not support sorting by nested fields.
33
39
  */
34
- 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) {
35
45
  return false;
36
46
  }
37
-
38
- return field.fieldId === fieldId;
47
+ return f.fieldId === fieldId;
39
48
  });
40
- const plugin = plugins.byType(_plugins.CmsEntryFieldSortingPlugin.type).reverse().find(plugin => {
49
+ const plugin = plugins.byType(CmsEntryFieldSortingPlugin.type).reverse().find(plugin => {
41
50
  return plugin.canUse({
42
51
  model,
43
52
  field,
@@ -46,7 +55,6 @@ const extractSort = params => {
46
55
  sortBy
47
56
  });
48
57
  });
49
-
50
58
  if (plugin) {
51
59
  return plugin.createSort({
52
60
  model,
@@ -57,12 +65,11 @@ const extractSort = params => {
57
65
  fields
58
66
  });
59
67
  } else if (!field) {
60
- 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", {
61
69
  fieldId,
62
70
  fields
63
71
  });
64
72
  }
65
-
66
73
  const valuePath = field.createPath({
67
74
  field
68
75
  });
@@ -74,4 +81,4 @@ const extractSort = params => {
74
81
  };
75
82
  };
76
83
 
77
- exports.extractSort = extractSort;
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,MAAD,IAA4B;EACnD,MAAM;IAAEC,KAAF;IAASC,MAAT;IAAiBC,MAAjB;IAAyBC;EAAzB,IAAqCJ,MAA3C;EACA,MAAMK,MAAM,GAAGH,MAAM,CAACI,KAAP,CAAa,GAAb,CAAf;;EACA,IAAID,MAAM,CAACE,MAAP,KAAkB,CAAtB,EAAyB;IACrB,MAAM,IAAIC,cAAJ,CACF,yDADE,EAEF,oBAFE,EAGF;MACIN;IADJ,CAHE,CAAN;EAOH;;EACD,MAAM,CAACO,OAAD,EAAUC,KAAV,IAAmBL,MAAzB;EAEA,MAAMM,KAAK,GAAGC,MAAM,CAACC,MAAP,CAAcV,MAAd,EAAsBW,IAAtB,CAA2BH,KAAK,IAAI;IAC9C;AACR;AACA;IACQ,IAAIA,KAAK,CAACI,OAAN,CAAcR,MAAd,GAAuB,CAA3B,EAA8B;MAC1B,OAAO,KAAP;IACH;;IACD,OAAOI,KAAK,CAACF,OAAN,KAAkBA,OAAzB;EACH,CARa,CAAd;EAUA,MAAMO,MAAM,GAAGZ,OAAO,CACjBa,MADU,CACyBC,mCAAA,CAA2BC,IADpD,EAEVC,OAFU,GAGVN,IAHU,CAGLE,MAAM,IAAI;IACZ,OAAOA,MAAM,CAACK,MAAP,CAAc;MACjBpB,KADiB;MAEjBU,KAFiB;MAGjBF,OAHiB;MAIjBC,KAJiB;MAKjBR;IALiB,CAAd,CAAP;EAOH,CAXU,CAAf;;EAaA,IAAIc,MAAJ,EAAY;IACR,OAAOA,MAAM,CAACM,UAAP,CAAkB;MACrBrB,KADqB;MAErBQ,OAFqB;MAGrBC,KAHqB;MAIrBR,MAJqB;MAKrBS,KALqB;MAMrBR;IANqB,CAAlB,CAAP;EAQH,CATD,MASO,IAAI,CAACQ,KAAL,EAAY;IACf,MAAM,IAAIH,cAAJ,CACF,oDADE,EAEF,qBAFE,EAGF;MACIC,OADJ;MAEIN;IAFJ,CAHE,CAAN;EAQH;;EACD,MAAMoB,SAAS,GAAGZ,KAAK,CAACa,UAAN,CAAiB;IAC/Bb;EAD+B,CAAjB,CAAlB;EAGA,OAAO;IACHA,KADG;IAEHF,OAFG;IAGHc,SAHG;IAIHH,OAAO,EAAEV,KAAK,KAAK;EAJhB,CAAP;AAMH,CAjEM"}
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,EAA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ACJ,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,43 +1,35 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.filter = void 0;
9
-
10
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
- var _ValueFilterPlugin = require("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin");
13
-
14
- var _error = _interopRequireDefault(require("@webiny/error"));
15
-
16
- var _fullTextSearch = require("./fullTextSearch");
17
-
18
- var _createExpressions = require("./createExpressions");
19
-
20
- var _transform = require("./transform");
21
-
22
- var _getValue = require("./getValue");
23
-
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";
24
7
  const executeFilter = params => {
25
8
  const {
26
9
  value,
27
10
  filter
28
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
+ }
29
24
  const matched = filter.plugin.matches({
30
25
  value,
31
26
  compareValue: filter.compareValue
32
27
  });
33
-
34
28
  if (filter.negate) {
35
29
  return matched === false;
36
30
  }
37
-
38
31
  return matched;
39
32
  };
40
-
41
33
  const executeExpressions = params => {
42
34
  const {
43
35
  expressions,
@@ -45,15 +37,12 @@ const executeExpressions = params => {
45
37
  filters,
46
38
  condition
47
39
  } = params;
48
-
49
40
  if (expressions.length === 0 && filters.length === 0) {
50
41
  return true;
51
42
  }
52
43
  /**
53
44
  * Always run filters first as they might trigger an early return.
54
45
  */
55
-
56
-
57
46
  for (const filter of filters) {
58
47
  const value = getCachedValue(filter);
59
48
  const result = executeFilter({
@@ -64,7 +53,6 @@ const executeExpressions = params => {
64
53
  * Filters are ALWAYS executed as an AND.
65
54
  * So if even one is false, everything false.
66
55
  */
67
-
68
56
  if (!result) {
69
57
  return false;
70
58
  }
@@ -72,13 +60,11 @@ const executeExpressions = params => {
72
60
  /**
73
61
  * Then we move onto expressions, which are basically nested upon nested filters with different conditions.
74
62
  */
75
-
76
-
77
63
  for (const expression of expressions) {
78
- const result = executeExpressions((0, _objectSpread2.default)((0, _objectSpread2.default)({}, expression), {}, {
64
+ const result = executeExpressions({
65
+ ...expression,
79
66
  getCachedValue
80
- }));
81
-
67
+ });
82
68
  if (result && condition === "OR") {
83
69
  return true;
84
70
  } else if (!result && condition == "AND") {
@@ -90,12 +76,9 @@ const executeExpressions = params => {
90
76
  *
91
77
  * 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.
92
78
  */
93
-
94
-
95
79
  return condition === "OR" ? false : true;
96
80
  };
97
-
98
- const filter = params => {
81
+ export const filter = params => {
99
82
  const {
100
83
  items: records,
101
84
  where,
@@ -104,75 +87,64 @@ const filter = params => {
104
87
  fullTextSearch
105
88
  } = params;
106
89
  const keys = Object.keys(where);
107
-
108
90
  if (keys.length === 0 && !fullTextSearch) {
109
91
  return records;
110
92
  }
111
-
112
- const expression = (0, _createExpressions.createExpressions)({
93
+ const expression = createExpressions({
113
94
  plugins,
114
95
  where,
115
96
  fields
116
97
  });
98
+
117
99
  /**
118
100
  * No point in going further if there are no expressions to be applied and no full text search to be executed.
119
101
  */
120
-
121
- 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) {
122
103
  return records;
123
104
  }
124
105
  /**
125
106
  * We need the contains plugin to run the full text search.
126
107
  */
127
-
128
-
129
- const fullTextSearchPlugin = plugins.byType(_ValueFilterPlugin.ValueFilterPlugin.type).find(plugin => plugin.getOperation() === "contains");
130
-
108
+ const fullTextSearchPlugin = plugins.byType(ValueFilterPlugin.type).find(plugin => plugin.getOperation() === "contains");
131
109
  if (!fullTextSearchPlugin) {
132
- 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");
133
111
  }
134
-
135
- const search = (0, _fullTextSearch.createFullTextSearch)({
136
- term: fullTextSearch === null || fullTextSearch === void 0 ? void 0 : fullTextSearch.term,
137
- targetFields: fullTextSearch === null || fullTextSearch === void 0 ? void 0 : fullTextSearch.fields,
112
+ const search = createFullTextSearch({
113
+ term: fullTextSearch?.term,
114
+ targetFields: fullTextSearch?.fields,
138
115
  fields,
139
116
  plugin: fullTextSearchPlugin
140
117
  });
141
118
  return records.filter(record => {
142
119
  const cachedValues = {};
143
-
144
120
  const getCachedValue = filter => {
145
121
  const {
146
122
  path
147
123
  } = filter;
148
-
149
124
  if (cachedValues[path] !== undefined) {
150
125
  return cachedValues[path];
151
126
  }
152
-
153
- const plainValue = (0, _getValue.getValue)(record, path);
154
- const rawValue = (0, _transform.transformValue)({
127
+ const plainValue = getValue(record, path);
128
+ const rawValue = transformValue({
155
129
  value: plainValue,
156
130
  transform: filter.transformValue
157
131
  });
158
132
  cachedValues[path] = rawValue;
159
133
  return rawValue;
160
134
  };
161
-
162
- const exprResult = executeExpressions((0, _objectSpread2.default)((0, _objectSpread2.default)({}, expression), {}, {
135
+ const exprResult = executeExpressions({
136
+ ...expression,
163
137
  getCachedValue
164
- }));
138
+ });
165
139
  /**
166
140
  * If expression result is false we do not need to continue further.
167
141
  * Also, if there is no full text search defined, just return the expression result.
168
142
  */
169
-
170
143
  if (!exprResult || !search) {
171
144
  return exprResult;
172
145
  }
173
-
174
146
  return search(record);
175
147
  });
176
148
  };
177
149
 
178
- exports.filter = filter;
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,MAAD,IAAiC;EACnD,MAAM;IAAEC,KAAF;IAASC;EAAT,IAAoBF,MAA1B;EAEA,MAAMG,OAAO,GAAGD,MAAM,CAACE,MAAP,CAAcC,OAAd,CAAsB;IAClCJ,KADkC;IAElCK,YAAY,EAAEJ,MAAM,CAACI;EAFa,CAAtB,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CAACC,IAAD,CAAnB;MACH;;MACD,MAAME,UAAU,GAAG,IAAAC,kBAAA,EAASL,MAAT,EAAiBE,IAAjB,CAAnB;MAEA,MAAMI,QAAQ,GAAG,IAAAC,yBAAA,EAAe;QAC5B1C,KAAK,EAAEuC,UADqB;QAE5BI,SAAS,EAAE1C,MAAM,CAACyC;MAFU,CAAf,CAAjB;MAKAN,YAAY,CAACC,IAAD,CAAZ,GAAqBI,QAArB;MACA,OAAOA,QAAP;IACH,CAdD;;IAgBA,MAAMG,UAAU,GAAGrC,kBAAkB,6DAAMO,UAAN;MAAkBL;IAAlB,GAArC;IACA;AACR;AACA;AACA;;IACQ,IAAI,CAACmC,UAAD,IAAe,CAACZ,MAApB,EAA4B;MACxB,OAAOY,UAAP;IACH;;IAED,OAAOZ,MAAM,CAACG,MAAD,CAAb;EACH,CA7BM,CAAP;AA8BH,CAzEM"}
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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I,CAAC,KAAKC,SAAS,EAAE;QAClC,OAAOF,YAAY,CAACC,IAAI,CAAC;MAC7B;MACA,MAAME,UAAU,GAAGvC,QAAQ,CAACmC,MAAM,EAAEE,IAAI,CAAC;MAEzC,MAAMG,QAAQ,GAAGzC,cAAc,CAAC;QAC5BI,KAAK,EAAEoC,UAAU;QACjBE,SAAS,EAAErC,MAAM,CAACL;MACtB,CAAC,CAAC;MAEFqC,YAAY,CAACC,IAAI,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[];
@@ -1,50 +1,33 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.createFullTextSearch = void 0;
9
-
10
- var _error = _interopRequireDefault(require("@webiny/error"));
11
-
12
- var _getValue = require("./getValue");
13
-
1
+ import WebinyError from "@webiny/error";
2
+ import { getValue } from "./getValue.js";
14
3
  /**
15
4
  * Unfortunately we must use the contains plugin directly as plugins do not support multi field searching.
16
5
  */
17
- const createFullTextSearch = params => {
6
+ export const createFullTextSearch = params => {
18
7
  const {
19
8
  term,
20
9
  targetFields,
21
10
  fields: fieldDefinitions,
22
11
  plugin
23
12
  } = params;
24
-
25
13
  if (!term || term.trim().length === 0 || !targetFields || targetFields.length === 0) {
26
14
  return null;
27
15
  }
28
-
29
16
  return item => {
30
17
  for (const target of targetFields) {
31
18
  /**
32
19
  * As fields is a mapped Field objects where key is a path to the value, we can directly find the related field.
33
20
  */
34
21
  const field = fieldDefinitions[target];
35
-
36
22
  if (!field) {
37
- throw new _error.default(`Unknown field "${target}" in the model.`, "UNKNOWN_FIELD", {
23
+ throw new WebinyError(`Unknown field "${target}" in the model.`, "UNKNOWN_FIELD", {
38
24
  target
39
25
  });
40
26
  }
41
-
42
- const value = (0, _getValue.getValue)(item.values, target);
43
-
27
+ const value = getValue(item, target);
44
28
  if (!value) {
45
29
  continue;
46
30
  }
47
-
48
31
  if (plugin.matches({
49
32
  value,
50
33
  compareValue: term
@@ -52,9 +35,8 @@ const createFullTextSearch = params => {
52
35
  return true;
53
36
  }
54
37
  }
55
-
56
38
  return false;
57
39
  };
58
40
  };
59
41
 
60
- exports.createFullTextSearch = createFullTextSearch;
42
+ //# sourceMappingURL=fullTextSearch.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createFullTextSearch","params","term","targetFields","fields","fieldDefinitions","plugin","trim","length","item","target","field","WebinyError","value","getValue","values","matches","compareValue"],"sources":["fullTextSearch.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { ValueFilterPlugin } from \"@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin\";\nimport { CmsEntry } from \"@webiny/api-headless-cms/types\";\nimport { Field } from \"./types\";\nimport { getValue } from \"./getValue\";\n\ninterface Params {\n term?: string;\n targetFields?: string[];\n fields: Record<string, Field>;\n plugin: ValueFilterPlugin;\n}\n\n/**\n * Unfortunately we must use the contains plugin directly as plugins do not support multi field searching.\n */\nexport const createFullTextSearch = (params: Params) => {\n const { term, targetFields, fields: fieldDefinitions, plugin } = params;\n if (!term || term.trim().length === 0 || !targetFields || targetFields.length === 0) {\n return null;\n }\n return (item: CmsEntry) => {\n for (const target of targetFields) {\n /**\n * As fields is a mapped Field objects where key is a path to the value, we can directly find the related field.\n */\n const field = fieldDefinitions[target];\n\n if (!field) {\n throw new WebinyError(`Unknown field \"${target}\" in the model.`, \"UNKNOWN_FIELD\", {\n target\n });\n }\n const value = getValue(item.values, target);\n if (!value) {\n continue;\n }\n if (plugin.matches({ value, compareValue: term }) === true) {\n return true;\n }\n }\n return false;\n };\n};\n"],"mappings":";;;;;;;;;AAAA;;AAIA;;AASA;AACA;AACA;AACO,MAAMA,oBAAoB,GAAIC,MAAD,IAAoB;EACpD,MAAM;IAAEC,IAAF;IAAQC,YAAR;IAAsBC,MAAM,EAAEC,gBAA9B;IAAgDC;EAAhD,IAA2DL,MAAjE;;EACA,IAAI,CAACC,IAAD,IAASA,IAAI,CAACK,IAAL,GAAYC,MAAZ,KAAuB,CAAhC,IAAqC,CAACL,YAAtC,IAAsDA,YAAY,CAACK,MAAb,KAAwB,CAAlF,EAAqF;IACjF,OAAO,IAAP;EACH;;EACD,OAAQC,IAAD,IAAoB;IACvB,KAAK,MAAMC,MAAX,IAAqBP,YAArB,EAAmC;MAC/B;AACZ;AACA;MACY,MAAMQ,KAAK,GAAGN,gBAAgB,CAACK,MAAD,CAA9B;;MAEA,IAAI,CAACC,KAAL,EAAY;QACR,MAAM,IAAIC,cAAJ,CAAiB,kBAAiBF,MAAO,iBAAzC,EAA2D,eAA3D,EAA4E;UAC9EA;QAD8E,CAA5E,CAAN;MAGH;;MACD,MAAMG,KAAK,GAAG,IAAAC,kBAAA,EAASL,IAAI,CAACM,MAAd,EAAsBL,MAAtB,CAAd;;MACA,IAAI,CAACG,KAAL,EAAY;QACR;MACH;;MACD,IAAIP,MAAM,CAACU,OAAP,CAAe;QAAEH,KAAF;QAASI,YAAY,EAAEf;MAAvB,CAAf,MAAkD,IAAtD,EAA4D;QACxD,OAAO,IAAP;MACH;IACJ;;IACD,OAAO,KAAP;EACH,CArBD;AAsBH,CA3BM"}
1
+ {"version":3,"names":["WebinyError","getValue","createFullTextSearch","params","term","targetFields","fields","fieldDefinitions","plugin","trim","length","item","target","field","value","matches","compareValue"],"sources":["fullTextSearch.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { ValueFilterPlugin } from \"@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin.js\";\nimport type { CmsEntry } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { Field } from \"./types.js\";\nimport { getValue } from \"./getValue.js\";\n\ninterface Params {\n term?: string;\n targetFields?: string[];\n fields: Record<string, Field>;\n plugin: ValueFilterPlugin;\n}\n\n/**\n * Unfortunately we must use the contains plugin directly as plugins do not support multi field searching.\n */\nexport const createFullTextSearch = (params: Params) => {\n const { term, targetFields, fields: fieldDefinitions, plugin } = params;\n if (!term || term.trim().length === 0 || !targetFields || targetFields.length === 0) {\n return null;\n }\n return (item: CmsEntry) => {\n for (const target of targetFields) {\n /**\n * As fields is a mapped Field objects where key is a path to the value, we can directly find the related field.\n */\n const field = fieldDefinitions[target];\n\n if (!field) {\n throw new WebinyError(`Unknown field \"${target}\" in the model.`, \"UNKNOWN_FIELD\", {\n target\n });\n }\n const value = getValue(item, target);\n if (!value) {\n continue;\n }\n if (plugin.matches({ value, compareValue: term }) === true) {\n return true;\n }\n }\n return false;\n };\n};\n"],"mappings":"AAAA,OAAOA,WAAW,MAAM,eAAe;AAIvC,SAASC,QAAQ;AASjB;AACA;AACA;AACA,OAAO,MAAMC,oBAAoB,GAAIC,MAAc,IAAK;EACpD,MAAM;IAAEC,IAAI;IAAEC,YAAY;IAAEC,MAAM,EAAEC,gBAAgB;IAAEC;EAAO,CAAC,GAAGL,MAAM;EACvE,IAAI,CAACC,IAAI,IAAIA,IAAI,CAACK,IAAI,CAAC,CAAC,CAACC,MAAM,KAAK,CAAC,IAAI,CAACL,YAAY,IAAIA,YAAY,CAACK,MAAM,KAAK,CAAC,EAAE;IACjF,OAAO,IAAI;EACf;EACA,OAAQC,IAAc,IAAK;IACvB,KAAK,MAAMC,MAAM,IAAIP,YAAY,EAAE;MAC/B;AACZ;AACA;MACY,MAAMQ,KAAK,GAAGN,gBAAgB,CAACK,MAAM,CAAC;MAEtC,IAAI,CAACC,KAAK,EAAE;QACR,MAAM,IAAIb,WAAW,CAAC,kBAAkBY,MAAM,iBAAiB,EAAE,eAAe,EAAE;UAC9EA;QACJ,CAAC,CAAC;MACN;MACA,MAAME,KAAK,GAAGb,QAAQ,CAACU,IAAI,EAAEC,MAAM,CAAC;MACpC,IAAI,CAACE,KAAK,EAAE;QACR;MACJ;MACA,IAAIN,MAAM,CAACO,OAAO,CAAC;QAAED,KAAK;QAAEE,YAAY,EAAEZ;MAAK,CAAC,CAAC,KAAK,IAAI,EAAE;QACxD,OAAO,IAAI;MACf;IACJ;IACA,OAAO,KAAK;EAChB,CAAC;AACL,CAAC","ignoreList":[]}
@@ -1,16 +1,8 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getValue = void 0;
7
-
8
1
  const addArrayResult = (target, result) => {
9
2
  for (const r of result) {
10
3
  if (target.some(t => r === t)) {
11
4
  continue;
12
5
  }
13
-
14
6
  target.push(r);
15
7
  }
16
8
  };
@@ -18,64 +10,50 @@ const addArrayResult = (target, result) => {
18
10
  * A recursive function which goes through given input paths and returns the value in it.
19
11
  * In case a path is an array, it goes through the array of those values to get values further down the path line.
20
12
  */
21
-
22
-
23
13
  const find = (target, input) => {
24
14
  const paths = [...input];
25
15
  const path = paths.shift();
26
-
27
16
  if (!path) {
28
17
  return undefined;
29
- } else if (target[path] === undefined) {
18
+ }
19
+ const value = target?.[path];
20
+ if (value === undefined) {
30
21
  return undefined;
31
22
  }
32
-
33
- const value = target[path];
34
-
35
23
  if (paths.length === 0) {
36
24
  return value;
37
25
  } else if (Array.isArray(value)) {
38
26
  if (value.length === 0) {
39
27
  return undefined;
40
28
  }
41
-
42
29
  return value.reduce((collection, v) => {
43
30
  const result = find(v, paths);
44
-
45
31
  if (result === undefined) {
46
32
  return collection;
47
33
  } else if (Array.isArray(result)) {
48
34
  addArrayResult(collection, result);
49
35
  return collection;
50
36
  }
51
-
52
37
  collection.push(result);
53
38
  return collection;
54
39
  }, []);
55
40
  }
56
-
57
41
  return find(value, paths);
58
42
  };
59
43
  /**
60
44
  * A wrapper function for the find function.
61
45
  * Basically it transforms input paths to an array (and runs various checks).
62
46
  */
63
-
64
-
65
- const getValue = (target, input) => {
47
+ export const getValue = (target, input) => {
66
48
  const paths = Array.isArray(input) ? input : input.split(".");
67
-
68
49
  if (paths.length === 0) {
69
50
  throw new Error(`Path is empty!`);
70
51
  }
71
-
72
52
  const filtered = paths.filter(Boolean);
73
-
74
53
  if (paths.length !== filtered.length) {
75
54
  throw new Error(`Input path is different than the filtered empty path string. (${paths.join(".")} to ${filtered.join(".")})`);
76
55
  }
77
-
78
56
  return find(target, paths);
79
57
  };
80
58
 
81
- exports.getValue = getValue;
59
+ //# sourceMappingURL=getValue.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["addArrayResult","target","result","r","some","t","push","find","input","paths","path","shift","undefined","value","length","Array","isArray","reduce","collection","v","getValue","split","Error","filtered","filter","Boolean","join"],"sources":["getValue.ts"],"sourcesContent":["const addArrayResult = (target: any[], result: any[]): void => {\n for (const r of result) {\n if (target.some(t => r === t)) {\n continue;\n }\n target.push(r);\n }\n};\n/**\n * A recursive function which goes through given input paths and returns the value in it.\n * In case a path is an array, it goes through the array of those values to get values further down the path line.\n */\nconst find = (target: Record<string, any>, input: string[]): any[] | undefined => {\n const paths = [...input];\n const path = paths.shift();\n\n if (!path) {\n return undefined;\n } else if (target[path] === undefined) {\n return undefined;\n }\n const value = target[path];\n if (paths.length === 0) {\n return value;\n } else if (Array.isArray(value)) {\n if (value.length === 0) {\n return undefined;\n }\n return value.reduce<any[]>((collection, v) => {\n const result = find(v, paths);\n if (result === undefined) {\n return collection;\n } else if (Array.isArray(result)) {\n addArrayResult(collection, result);\n return collection;\n }\n collection.push(result);\n return collection;\n }, []);\n }\n return find(value, paths);\n};\n/**\n * A wrapper function for the find function.\n * Basically it transforms input paths to an array (and runs various checks).\n */\nexport const getValue = (target: Record<string, any>, input: string | string[]): any => {\n const paths = Array.isArray(input) ? input : input.split(\".\");\n if (paths.length === 0) {\n throw new Error(`Path is empty!`);\n }\n const filtered = paths.filter(Boolean);\n if (paths.length !== filtered.length) {\n throw new Error(\n `Input path is different than the filtered empty path string. (${paths.join(\n \".\"\n )} to ${filtered.join(\".\")})`\n );\n }\n\n return find(target, paths);\n};\n"],"mappings":";;;;;;;AAAA,MAAMA,cAAc,GAAG,CAACC,MAAD,EAAgBC,MAAhB,KAAwC;EAC3D,KAAK,MAAMC,CAAX,IAAgBD,MAAhB,EAAwB;IACpB,IAAID,MAAM,CAACG,IAAP,CAAYC,CAAC,IAAIF,CAAC,KAAKE,CAAvB,CAAJ,EAA+B;MAC3B;IACH;;IACDJ,MAAM,CAACK,IAAP,CAAYH,CAAZ;EACH;AACJ,CAPD;AAQA;AACA;AACA;AACA;;;AACA,MAAMI,IAAI,GAAG,CAACN,MAAD,EAA8BO,KAA9B,KAAqE;EAC9E,MAAMC,KAAK,GAAG,CAAC,GAAGD,KAAJ,CAAd;EACA,MAAME,IAAI,GAAGD,KAAK,CAACE,KAAN,EAAb;;EAEA,IAAI,CAACD,IAAL,EAAW;IACP,OAAOE,SAAP;EACH,CAFD,MAEO,IAAIX,MAAM,CAACS,IAAD,CAAN,KAAiBE,SAArB,EAAgC;IACnC,OAAOA,SAAP;EACH;;EACD,MAAMC,KAAK,GAAGZ,MAAM,CAACS,IAAD,CAApB;;EACA,IAAID,KAAK,CAACK,MAAN,KAAiB,CAArB,EAAwB;IACpB,OAAOD,KAAP;EACH,CAFD,MAEO,IAAIE,KAAK,CAACC,OAAN,CAAcH,KAAd,CAAJ,E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H,CAfM"}
1
+ {"version":3,"names":["addArrayResult","target","result","r","some","t","push","find","input","paths","path","shift","undefined","value","length","Array","isArray","reduce","collection","v","getValue","split","Error","filtered","filter","Boolean","join"],"sources":["getValue.ts"],"sourcesContent":["const addArrayResult = (target: any[], result: any[]): void => {\n for (const r of result) {\n if (target.some(t => r === t)) {\n continue;\n }\n target.push(r);\n }\n};\n/**\n * A recursive function which goes through given input paths and returns the value in it.\n * In case a path is an array, it goes through the array of those values to get values further down the path line.\n */\nconst find = (target: Record<string, any> | undefined, input: string[]): any[] | undefined => {\n const paths = [...input];\n const path = paths.shift();\n\n if (!path) {\n return undefined;\n }\n\n const value = target?.[path];\n if (value === undefined) {\n return undefined;\n }\n if (paths.length === 0) {\n return value;\n } else if (Array.isArray(value)) {\n if (value.length === 0) {\n return undefined;\n }\n return value.reduce<any[]>((collection, v) => {\n const result = find(v, paths);\n if (result === undefined) {\n return collection;\n } else if (Array.isArray(result)) {\n addArrayResult(collection, result);\n return collection;\n }\n collection.push(result);\n return collection;\n }, []);\n }\n return find(value, paths);\n};\n/**\n * A wrapper function for the find function.\n * Basically it transforms input paths to an array (and runs various checks).\n */\nexport const getValue = (target: Record<string, any>, input: string | string[]): any => {\n const paths = Array.isArray(input) ? input : input.split(\".\");\n if (paths.length === 0) {\n throw new Error(`Path is empty!`);\n }\n const filtered = paths.filter(Boolean);\n if (paths.length !== filtered.length) {\n throw new Error(\n `Input path is different than the filtered empty path string. (${paths.join(\n \".\"\n )} to ${filtered.join(\".\")})`\n );\n }\n\n return find(target, paths);\n};\n"],"mappings":"AAAA,MAAMA,cAAc,GAAGA,CAACC,MAAa,EAAEC,MAAa,KAAW;EAC3D,KAAK,MAAMC,CAAC,IAAID,MAAM,EAAE;IACpB,IAAID,MAAM,CAACG,IAAI,CAACC,CAAC,IAAIF,CAAC,KAAKE,CAAC,CAAC,EAAE;MAC3B;IACJ;IACAJ,MAAM,CAACK,IAAI,CAACH,CAAC,CAAC;EAClB;AACJ,CAAC;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