@webiny/api-headless-cms-ddb 0.0.0-unstable.e6f0dc8ca7 → 0.0.0-unstable.e9333b3f0b

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 (267) hide show
  1. package/abstractions/CmsDdbDataLoaders.d.ts +5 -0
  2. package/abstractions/CmsDdbDataLoaders.js +5 -0
  3. package/abstractions/CmsDdbDataLoaders.js.map +1 -0
  4. package/abstractions/CmsDdbEntryEntity.d.ts +5 -0
  5. package/abstractions/CmsDdbEntryEntity.js +5 -0
  6. package/abstractions/CmsDdbEntryEntity.js.map +1 -0
  7. package/abstractions/CmsDdbGroupEntity.d.ts +5 -0
  8. package/abstractions/CmsDdbGroupEntity.js +5 -0
  9. package/abstractions/CmsDdbGroupEntity.js.map +1 -0
  10. package/abstractions/CmsDdbModelEntity.d.ts +5 -0
  11. package/abstractions/CmsDdbModelEntity.js +5 -0
  12. package/abstractions/CmsDdbModelEntity.js.map +1 -0
  13. package/abstractions/CmsDdbTable.d.ts +5 -0
  14. package/abstractions/CmsDdbTable.js +5 -0
  15. package/abstractions/CmsDdbTable.js.map +1 -0
  16. package/definitions/entry.js +7 -9
  17. package/definitions/entry.js.map +1 -1
  18. package/definitions/group.js +7 -9
  19. package/definitions/group.js.map +1 -1
  20. package/definitions/model.js +7 -9
  21. package/definitions/model.js.map +1 -1
  22. package/definitions/table.js +6 -7
  23. package/definitions/table.js.map +1 -1
  24. package/definitions/types.d.ts +4 -0
  25. package/definitions/types.js +0 -3
  26. package/index.d.ts +17 -2
  27. package/index.js +31 -88
  28. package/index.js.map +1 -1
  29. package/operations/entry/DdbCreateEntry.d.ts +16 -0
  30. package/operations/entry/DdbCreateEntry.js +77 -0
  31. package/operations/entry/DdbCreateEntry.js.map +1 -0
  32. package/operations/entry/DdbCreateEntryRevisionFrom.d.ts +16 -0
  33. package/operations/entry/DdbCreateEntryRevisionFrom.js +85 -0
  34. package/operations/entry/DdbCreateEntryRevisionFrom.js.map +1 -0
  35. package/operations/entry/DdbDeleteEntry.d.ts +16 -0
  36. package/operations/entry/DdbDeleteEntry.js +65 -0
  37. package/operations/entry/DdbDeleteEntry.js.map +1 -0
  38. package/operations/entry/DdbDeleteEntryRevision.d.ts +17 -0
  39. package/operations/entry/DdbDeleteEntryRevision.js +91 -0
  40. package/operations/entry/DdbDeleteEntryRevision.js.map +1 -0
  41. package/operations/entry/DdbDeleteMultipleEntries.d.ts +16 -0
  42. package/operations/entry/DdbDeleteMultipleEntries.js +59 -0
  43. package/operations/entry/DdbDeleteMultipleEntries.js.map +1 -0
  44. package/operations/entry/DdbGetEntriesByIds.d.ts +14 -0
  45. package/operations/entry/DdbGetEntriesByIds.js +31 -0
  46. package/operations/entry/DdbGetEntriesByIds.js.map +1 -0
  47. package/operations/entry/DdbGetEntry.d.ts +14 -0
  48. package/operations/entry/DdbGetEntry.js +27 -0
  49. package/operations/entry/DdbGetEntry.js.map +1 -0
  50. package/operations/entry/DdbGetLatestEntriesByIds.d.ts +14 -0
  51. package/operations/entry/DdbGetLatestEntriesByIds.js +31 -0
  52. package/operations/entry/DdbGetLatestEntriesByIds.js.map +1 -0
  53. package/operations/entry/DdbGetLatestRevisionByEntryId.d.ts +14 -0
  54. package/operations/entry/DdbGetLatestRevisionByEntryId.js +35 -0
  55. package/operations/entry/DdbGetLatestRevisionByEntryId.js.map +1 -0
  56. package/operations/entry/DdbGetPreviousRevision.d.ts +14 -0
  57. package/operations/entry/DdbGetPreviousRevision.js +53 -0
  58. package/operations/entry/DdbGetPreviousRevision.js.map +1 -0
  59. package/operations/entry/DdbGetPublishedEntriesByIds.d.ts +14 -0
  60. package/operations/entry/DdbGetPublishedEntriesByIds.js +31 -0
  61. package/operations/entry/DdbGetPublishedEntriesByIds.js.map +1 -0
  62. package/operations/entry/DdbGetPublishedRevisionByEntryId.d.ts +14 -0
  63. package/operations/entry/DdbGetPublishedRevisionByEntryId.js +35 -0
  64. package/operations/entry/DdbGetPublishedRevisionByEntryId.js.map +1 -0
  65. package/operations/entry/DdbGetRevisionById.d.ts +14 -0
  66. package/operations/entry/DdbGetRevisionById.js +34 -0
  67. package/operations/entry/DdbGetRevisionById.js.map +1 -0
  68. package/operations/entry/DdbGetRevisions.d.ts +14 -0
  69. package/operations/entry/DdbGetRevisions.js +33 -0
  70. package/operations/entry/DdbGetRevisions.js.map +1 -0
  71. package/operations/entry/DdbGetUniqueFieldValues.d.ts +12 -0
  72. package/operations/entry/DdbGetUniqueFieldValues.js +31 -0
  73. package/operations/entry/DdbGetUniqueFieldValues.js.map +1 -0
  74. package/operations/entry/DdbListEntries.d.ts +28 -0
  75. package/operations/entry/DdbListEntries.js +124 -0
  76. package/operations/entry/DdbListEntries.js.map +1 -0
  77. package/operations/entry/DdbMoveEntry.d.ts +14 -0
  78. package/operations/entry/DdbMoveEntry.js +57 -0
  79. package/operations/entry/DdbMoveEntry.js.map +1 -0
  80. package/operations/entry/DdbMoveToBin.d.ts +16 -0
  81. package/operations/entry/DdbMoveToBin.js +77 -0
  82. package/operations/entry/DdbMoveToBin.js.map +1 -0
  83. package/operations/entry/DdbPublishEntry.d.ts +18 -0
  84. package/operations/entry/DdbPublishEntry.js +162 -0
  85. package/operations/entry/DdbPublishEntry.js.map +1 -0
  86. package/operations/entry/DdbRestoreFromBin.d.ts +16 -0
  87. package/operations/entry/DdbRestoreFromBin.js +78 -0
  88. package/operations/entry/DdbRestoreFromBin.js.map +1 -0
  89. package/operations/entry/DdbUnpublishEntry.d.ts +17 -0
  90. package/operations/entry/DdbUnpublishEntry.js +112 -0
  91. package/operations/entry/DdbUnpublishEntry.js.map +1 -0
  92. package/operations/entry/DdbUpdateEntry.d.ts +17 -0
  93. package/operations/entry/DdbUpdateEntry.js +105 -0
  94. package/operations/entry/DdbUpdateEntry.js.map +1 -0
  95. package/operations/entry/dataLoader/DataLoaderCache.js +22 -26
  96. package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -1
  97. package/operations/entry/dataLoader/constants.js +2 -1
  98. package/operations/entry/dataLoader/constants.js.map +1 -1
  99. package/operations/entry/dataLoader/createBatchScheduleFn.js +6 -15
  100. package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -1
  101. package/operations/entry/dataLoader/getAllEntryRevisions.js +18 -29
  102. package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -1
  103. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +31 -41
  104. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -1
  105. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +31 -41
  106. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -1
  107. package/operations/entry/dataLoader/getRevisionById.js +33 -47
  108. package/operations/entry/dataLoader/getRevisionById.js.map +1 -1
  109. package/operations/entry/dataLoader/index.js +8 -9
  110. package/operations/entry/dataLoader/index.js.map +1 -1
  111. package/operations/entry/dataLoader/types.js +0 -3
  112. package/operations/entry/dataLoaders.d.ts +7 -6
  113. package/operations/entry/dataLoaders.js +89 -99
  114. package/operations/entry/dataLoaders.js.map +1 -1
  115. package/operations/entry/feature.d.ts +4 -0
  116. package/operations/entry/feature.js +53 -0
  117. package/operations/entry/feature.js.map +1 -0
  118. package/operations/entry/keys.d.ts +6 -0
  119. package/operations/entry/keys.js +57 -77
  120. package/operations/entry/keys.js.map +1 -1
  121. package/operations/entry/storageEntryUtils.d.ts +8 -0
  122. package/operations/entry/storageEntryUtils.js +25 -0
  123. package/operations/entry/storageEntryUtils.js.map +1 -0
  124. package/operations/group/DdbCreateGroup.d.ts +12 -0
  125. package/operations/group/DdbCreateGroup.js +35 -0
  126. package/operations/group/DdbCreateGroup.js.map +1 -0
  127. package/operations/group/DdbDeleteGroup.d.ts +12 -0
  128. package/operations/group/DdbDeleteGroup.js +31 -0
  129. package/operations/group/DdbDeleteGroup.js.map +1 -0
  130. package/operations/group/DdbGetGroup.d.ts +12 -0
  131. package/operations/group/DdbGetGroup.js +31 -0
  132. package/operations/group/DdbGetGroup.js.map +1 -0
  133. package/operations/group/DdbListGroups.d.ts +14 -0
  134. package/operations/group/DdbListGroups.js +52 -0
  135. package/operations/group/DdbListGroups.js.map +1 -0
  136. package/operations/group/DdbUpdateGroup.d.ts +12 -0
  137. package/operations/group/DdbUpdateGroup.js +35 -0
  138. package/operations/group/DdbUpdateGroup.js.map +1 -0
  139. package/operations/group/feature.d.ts +4 -0
  140. package/operations/group/feature.js +19 -0
  141. package/operations/group/feature.js.map +1 -0
  142. package/operations/group/keys.d.ts +15 -0
  143. package/operations/group/keys.js +17 -0
  144. package/operations/group/keys.js.map +1 -0
  145. package/operations/model/DdbCreateModel.d.ts +12 -0
  146. package/operations/model/DdbCreateModel.js +37 -0
  147. package/operations/model/DdbCreateModel.js.map +1 -0
  148. package/operations/model/DdbDeleteModel.d.ts +12 -0
  149. package/operations/model/DdbDeleteModel.js +31 -0
  150. package/operations/model/DdbDeleteModel.js.map +1 -0
  151. package/operations/model/DdbGetModel.d.ts +12 -0
  152. package/operations/model/DdbGetModel.js +30 -0
  153. package/operations/model/DdbGetModel.js.map +1 -0
  154. package/operations/model/DdbListModels.d.ts +12 -0
  155. package/operations/model/DdbListModels.js +36 -0
  156. package/operations/model/DdbListModels.js.map +1 -0
  157. package/operations/model/DdbUpdateModel.d.ts +12 -0
  158. package/operations/model/DdbUpdateModel.js +36 -0
  159. package/operations/model/DdbUpdateModel.js.map +1 -0
  160. package/operations/model/feature.d.ts +4 -0
  161. package/operations/model/feature.js +19 -0
  162. package/operations/model/feature.js.map +1 -0
  163. package/operations/model/keys.d.ts +15 -0
  164. package/operations/model/keys.js +16 -0
  165. package/operations/model/keys.js.map +1 -0
  166. package/package.json +22 -24
  167. package/requestFeature.d.ts +17 -0
  168. package/requestFeature.js +19 -0
  169. package/requestFeature.js.map +1 -0
  170. package/types.d.ts +10 -50
  171. package/types.js +6 -5
  172. package/types.js.map +1 -1
  173. package/definitions/types.js.map +0 -1
  174. package/dynamoDb/index.d.ts +0 -2
  175. package/dynamoDb/index.js +0 -6
  176. package/dynamoDb/index.js.map +0 -1
  177. package/dynamoDb/path/locationFolderId.d.ts +0 -2
  178. package/dynamoDb/path/locationFolderId.js +0 -34
  179. package/dynamoDb/path/locationFolderId.js.map +0 -1
  180. package/dynamoDb/path/plainObject.d.ts +0 -2
  181. package/dynamoDb/path/plainObject.js +0 -26
  182. package/dynamoDb/path/plainObject.js.map +0 -1
  183. package/dynamoDb/transformValue/datetime.d.ts +0 -5
  184. package/dynamoDb/transformValue/datetime.js +0 -40
  185. package/dynamoDb/transformValue/datetime.js.map +0 -1
  186. package/operations/entry/dataLoader/types.js.map +0 -1
  187. package/operations/entry/filtering/createExpressions.d.ts +0 -27
  188. package/operations/entry/filtering/createExpressions.js +0 -172
  189. package/operations/entry/filtering/createExpressions.js.map +0 -1
  190. package/operations/entry/filtering/createFields.d.ts +0 -16
  191. package/operations/entry/filtering/createFields.js +0 -106
  192. package/operations/entry/filtering/createFields.js.map +0 -1
  193. package/operations/entry/filtering/extractSort.d.ts +0 -17
  194. package/operations/entry/filtering/extractSort.js +0 -84
  195. package/operations/entry/filtering/extractSort.js.map +0 -1
  196. package/operations/entry/filtering/filter.d.ts +0 -16
  197. package/operations/entry/filtering/filter.js +0 -153
  198. package/operations/entry/filtering/filter.js.map +0 -1
  199. package/operations/entry/filtering/fullTextSearch.d.ts +0 -14
  200. package/operations/entry/filtering/fullTextSearch.js +0 -42
  201. package/operations/entry/filtering/fullTextSearch.js.map +0 -1
  202. package/operations/entry/filtering/getValue.d.ts +0 -5
  203. package/operations/entry/filtering/getValue.js +0 -59
  204. package/operations/entry/filtering/getValue.js.map +0 -1
  205. package/operations/entry/filtering/index.d.ts +0 -2
  206. package/operations/entry/filtering/index.js +0 -4
  207. package/operations/entry/filtering/index.js.map +0 -1
  208. package/operations/entry/filtering/mapPlugins.d.ts +0 -8
  209. package/operations/entry/filtering/mapPlugins.js +0 -25
  210. package/operations/entry/filtering/mapPlugins.js.map +0 -1
  211. package/operations/entry/filtering/plugins/defaultFilterCreate.d.ts +0 -2
  212. package/operations/entry/filtering/plugins/defaultFilterCreate.js +0 -37
  213. package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +0 -1
  214. package/operations/entry/filtering/plugins/index.d.ts +0 -1
  215. package/operations/entry/filtering/plugins/index.js +0 -9
  216. package/operations/entry/filtering/plugins/index.js.map +0 -1
  217. package/operations/entry/filtering/plugins/objectFilterCreate.d.ts +0 -2
  218. package/operations/entry/filtering/plugins/objectFilterCreate.js +0 -84
  219. package/operations/entry/filtering/plugins/objectFilterCreate.js.map +0 -1
  220. package/operations/entry/filtering/plugins/refFilterCreate.d.ts +0 -3
  221. package/operations/entry/filtering/plugins/refFilterCreate.js +0 -74
  222. package/operations/entry/filtering/plugins/refFilterCreate.js.map +0 -1
  223. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.d.ts +0 -2
  224. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js +0 -62
  225. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js.map +0 -1
  226. package/operations/entry/filtering/sort.d.ts +0 -12
  227. package/operations/entry/filtering/sort.js +0 -67
  228. package/operations/entry/filtering/sort.js.map +0 -1
  229. package/operations/entry/filtering/systemFields.d.ts +0 -2
  230. package/operations/entry/filtering/systemFields.js +0 -131
  231. package/operations/entry/filtering/systemFields.js.map +0 -1
  232. package/operations/entry/filtering/transform.d.ts +0 -6
  233. package/operations/entry/filtering/transform.js +0 -11
  234. package/operations/entry/filtering/transform.js.map +0 -1
  235. package/operations/entry/filtering/types.d.ts +0 -40
  236. package/operations/entry/filtering/types.js +0 -3
  237. package/operations/entry/filtering/types.js.map +0 -1
  238. package/operations/entry/filtering/values.d.ts +0 -2
  239. package/operations/entry/filtering/values.js +0 -16
  240. package/operations/entry/filtering/values.js.map +0 -1
  241. package/operations/entry/filtering/where.d.ts +0 -5
  242. package/operations/entry/filtering/where.js +0 -28
  243. package/operations/entry/filtering/where.js.map +0 -1
  244. package/operations/entry/index.d.ts +0 -9
  245. package/operations/entry/index.js +0 -1197
  246. package/operations/entry/index.js.map +0 -1
  247. package/operations/group/index.d.ts +0 -8
  248. package/operations/group/index.js +0 -142
  249. package/operations/group/index.js.map +0 -1
  250. package/operations/model/index.d.ts +0 -7
  251. package/operations/model/index.js +0 -127
  252. package/operations/model/index.js.map +0 -1
  253. package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +0 -23
  254. package/plugins/CmsEntryFieldFilterPathPlugin.js +0 -40
  255. package/plugins/CmsEntryFieldFilterPathPlugin.js.map +0 -1
  256. package/plugins/CmsEntryFieldFilterPlugin.d.ts +0 -43
  257. package/plugins/CmsEntryFieldFilterPlugin.js +0 -21
  258. package/plugins/CmsEntryFieldFilterPlugin.js.map +0 -1
  259. package/plugins/CmsEntryFieldSortingPlugin.d.ts +0 -42
  260. package/plugins/CmsEntryFieldSortingPlugin.js +0 -19
  261. package/plugins/CmsEntryFieldSortingPlugin.js.map +0 -1
  262. package/plugins/CmsFieldFilterValueTransformPlugin.d.ts +0 -11
  263. package/plugins/CmsFieldFilterValueTransformPlugin.js +0 -16
  264. package/plugins/CmsFieldFilterValueTransformPlugin.js.map +0 -1
  265. package/plugins/index.d.ts +0 -4
  266. package/plugins/index.js +0 -6
  267. package/plugins/index.js.map +0 -1
@@ -1,153 +0,0 @@
1
- import WebinyError from "@webiny/error";
2
- import { createFullTextSearch } from "./fullTextSearch.js";
3
- import { createExpressions } from "./createExpressions.js";
4
- import { transformValue } from "./transform.js";
5
- import { getValue } from "./getValue.js";
6
- import { ValueFilterRegistry } from "@webiny/db-dynamodb/exports/api/db.js";
7
- const executeFilter = params => {
8
- const {
9
- value,
10
- filter
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.filter.canUse({
18
- value,
19
- compareValue: filter.compareValue
20
- });
21
- if (!canUse) {
22
- return true;
23
- }
24
- const matched = filter.filter.matches({
25
- value,
26
- compareValue: filter.compareValue
27
- });
28
- if (filter.negate) {
29
- return matched === false;
30
- }
31
- return matched;
32
- };
33
- const executeExpressions = params => {
34
- const {
35
- expressions,
36
- getCachedValue,
37
- filters,
38
- condition
39
- } = params;
40
- if (expressions.length === 0 && filters.length === 0) {
41
- return true;
42
- }
43
- /**
44
- * Always run filters first as they might trigger an early return.
45
- */
46
- for (const filter of filters) {
47
- const value = getCachedValue(filter);
48
- const result = executeFilter({
49
- value,
50
- filter
51
- });
52
- /**
53
- * Filters are ALWAYS executed as an AND.
54
- * So if even one is false, everything false.
55
- */
56
- if (!result) {
57
- return false;
58
- }
59
- }
60
- /**
61
- * Then we move onto expressions, which are basically nested upon nested filters with different conditions.
62
- */
63
- for (const expression of expressions) {
64
- const result = executeExpressions({
65
- ...expression,
66
- getCachedValue
67
- });
68
- if (result && condition === "OR") {
69
- return true;
70
- } else if (!result && condition == "AND") {
71
- return false;
72
- }
73
- }
74
- /**
75
- * If condition is an OR, we can fail the expressions check because the code would return a lot earlier than this line.
76
- *
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.
78
- */
79
- return condition === "OR" ? false : true;
80
- };
81
- export const filter = params => {
82
- const {
83
- items: records,
84
- where,
85
- plugins,
86
- fields,
87
- fullTextSearch,
88
- container
89
- } = params;
90
- const valueFilterRegistry = container.resolve(ValueFilterRegistry);
91
- const keys = Object.keys(where);
92
- if (keys.length === 0 && !fullTextSearch) {
93
- return records;
94
- }
95
- const expression = createExpressions({
96
- plugins,
97
- where,
98
- fields,
99
- container
100
- });
101
-
102
- /**
103
- * No point in going further if there are no expressions to be applied and no full text search to be executed.
104
- */
105
- if (expression.filters.length === 0 && expression.expressions.length === 0 && !fullTextSearch?.term) {
106
- return records;
107
- }
108
- /**
109
- * We need the contains plugin to run the full text search.
110
- */
111
- const fullTextSearchFilter = valueFilterRegistry.get("contains");
112
- if (!fullTextSearchFilter) {
113
- throw new WebinyError(`Missing "contains" plugin to run the full-text search.`, "MISSING_PLUGIN");
114
- }
115
- const search = createFullTextSearch({
116
- term: fullTextSearch?.term,
117
- targetFields: fullTextSearch?.fields,
118
- fields,
119
- filter: fullTextSearchFilter
120
- });
121
- return records.filter(record => {
122
- const cachedValues = {};
123
- const getCachedValue = filter => {
124
- const {
125
- path
126
- } = filter;
127
- if (cachedValues[path] !== undefined) {
128
- return cachedValues[path];
129
- }
130
- const plainValue = getValue(record, path);
131
- const rawValue = transformValue({
132
- value: plainValue,
133
- transform: filter.transformValue
134
- });
135
- cachedValues[path] = rawValue;
136
- return rawValue;
137
- };
138
- const exprResult = executeExpressions({
139
- ...expression,
140
- getCachedValue
141
- });
142
- /**
143
- * If expression result is false we do not need to continue further.
144
- * Also, if there is no full text search defined, just return the expression result.
145
- */
146
- if (!exprResult || !search) {
147
- return exprResult;
148
- }
149
- return search(record);
150
- });
151
- };
152
-
153
- //# sourceMappingURL=filter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["WebinyError","createFullTextSearch","createExpressions","transformValue","getValue","ValueFilterRegistry","executeFilter","params","value","filter","canUse","compareValue","matched","matches","negate","executeExpressions","expressions","getCachedValue","filters","condition","length","result","expression","items","records","where","plugins","fields","fullTextSearch","container","valueFilterRegistry","resolve","keys","Object","term","fullTextSearchFilter","get","search","targetFields","record","cachedValues","path","undefined","plainValue","rawValue","transform","exprResult"],"sources":["filter.ts"],"sourcesContent":["import type {\n CmsContext,\n CmsEntry,\n CmsEntryListWhere,\n CmsEntryValues\n} from \"@webiny/api-headless-cms/types/index.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\";\nimport { ValueFilterRegistry } from \"@webiny/db-dynamodb/exports/api/db.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.filter.canUse({\n value,\n compareValue: filter.compareValue\n });\n if (!canUse) {\n return true;\n }\n\n const matched = filter.filter.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 IFilterParams<T extends CmsEntryValues = CmsEntryValues> {\n plugins: PluginsContainer;\n container: CmsContext[\"container\"];\n items: CmsEntry<T>[];\n where: Partial<CmsEntryListWhere>;\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: IFilterParams<T>\n): CmsEntry<T>[] => {\n const { items: records, where, plugins, fields, fullTextSearch, container } = params;\n\n const valueFilterRegistry = container.resolve(ValueFilterRegistry);\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 container\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 fullTextSearchFilter = valueFilterRegistry.get(\"contains\");\n if (!fullTextSearchFilter) {\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 filter: fullTextSearchFilter\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":"AAMA,OAAOA,WAAW,MAAM,eAAe;AAGvC,SAASC,oBAAoB;AAE7B,SAASC,iBAAiB;AAC1B,SAASC,cAAc;AACvB,SAASC,QAAQ;AACjB,SAASC,mBAAmB,QAAQ,uCAAuC;AAO3E,MAAMC,aAAa,GAAIC,MAA2B,IAAK;EACnD,MAAM;IAAEC,KAAK;IAAEC;EAAO,CAAC,GAAGF,MAAM;;EAEhC;AACJ;AACA;AACA;EACI,MAAMG,MAAM,GAAGD,MAAM,CAACA,MAAM,CAACC,MAAM,CAAC;IAChCF,KAAK;IACLG,YAAY,EAAEF,MAAM,CAACE;EACzB,CAAC,CAAC;EACF,IAAI,CAACD,MAAM,EAAE;IACT,OAAO,IAAI;EACf;EAEA,MAAME,OAAO,GAAGH,MAAM,CAACA,MAAM,CAACI,OAAO,CAAC;IAClCL,KAAK;IACLG,YAAY,EAAEF,MAAM,CAACE;EACzB,CAAC,CAAC;EACF,IAAIF,MAAM,CAACK,MAAM,EAAE;IACf,OAAOF,OAAO,KAAK,KAAK;EAC5B;EACA,OAAOA,OAAO;AAClB,CAAC;AASD,MAAMG,kBAAkB,GAAIR,MAAgC,IAAc;EACtE,MAAM;IAAES,WAAW;IAAEC,cAAc;IAAEC,OAAO;IAAEC;EAAU,CAAC,GAAGZ,MAAM;EAClE,IAAIS,WAAW,CAACI,MAAM,KAAK,CAAC,IAAIF,OAAO,CAACE,MAAM,KAAK,CAAC,EAAE;IAClD,OAAO,IAAI;EACf;EACA;AACJ;AACA;EACI,KAAK,MAAMX,MAAM,IAAIS,OAAO,EAAE;IAC1B,MAAMV,KAAK,GAAGS,cAAc,CAACR,MAAM,CAAC;IAEpC,MAAMY,MAAM,GAAGf,aAAa,CAAC;MACzBE,KAAK;MACLC;IACJ,CAAC,CAAC;IACF;AACR;AACA;AACA;IACQ,IAAI,CAACY,MAAM,EAAE;MACT,OAAO,KAAK;IAChB;EACJ;EACA;AACJ;AACA;EACI,KAAK,MAAMC,UAAU,IAAIN,WAAW,EAAE;IAClC,MAAMK,MAAM,GAAGN,kBAAkB,CAAC;MAC9B,GAAGO,UAAU;MACbL;IACJ,CAAC,CAAC;IACF,IAAII,MAAM,IAAIF,SAAS,KAAK,IAAI,EAAE;MAC9B,OAAO,IAAI;IACf,CAAC,MAAM,IAAI,CAACE,MAAM,IAAIF,SAAS,IAAI,KAAK,EAAE;MACtC,OAAO,KAAK;IAChB;EACJ;EACA;AACJ;AACA;AACA;AACA;EACI,OAAOA,SAAS,KAAK,IAAI,GAAG,KAAK,GAAG,IAAI;AAC5C,CAAC;AAcD,OAAO,MAAMV,MAAM,GACfF,MAAwB,IACR;EAChB,MAAM;IAAEgB,KAAK,EAAEC,OAAO;IAAEC,KAAK;IAAEC,OAAO;IAAEC,MAAM;IAAEC,cAAc;IAAEC;EAAU,CAAC,GAAGtB,MAAM;EAEpF,MAAMuB,mBAAmB,GAAGD,SAAS,CAACE,OAAO,CAAC1B,mBAAmB,CAAC;EAElE,MAAM2B,IAAI,GAAGC,MAAM,CAACD,IAAI,CAACP,KAAK,CAAC;EAC/B,IAAIO,IAAI,CAACZ,MAAM,KAAK,CAAC,IAAI,CAACQ,cAAc,EAAE;IACtC,OAAOJ,OAAO;EAClB;EACA,MAAMF,UAAU,GAAGpB,iBAAiB,CAAC;IACjCwB,OAAO;IACPD,KAAK;IACLE,MAAM;IACNE;EACJ,CAAC,CAAC;;EAEF;AACJ;AACA;EACI,IACIP,UAAU,CAACJ,OAAO,CAACE,MAAM,KAAK,CAAC,IAC/BE,UAAU,CAACN,WAAW,CAACI,MAAM,KAAK,CAAC,IACnC,CAACQ,cAAc,EAAEM,IAAI,EACvB;IACE,OAAOV,OAAO;EAClB;EACA;AACJ;AACA;EACI,MAAMW,oBAAoB,GAAGL,mBAAmB,CAACM,GAAG,CAAC,UAAU,CAAC;EAChE,IAAI,CAACD,oBAAoB,EAAE;IACvB,MAAM,IAAInC,WAAW,CACjB,wDAAwD,EACxD,gBACJ,CAAC;EACL;EAEA,MAAMqC,MAAM,GAAGpC,oBAAoB,CAAC;IAChCiC,IAAI,EAAEN,cAAc,EAAEM,IAAI;IAC1BI,YAAY,EAAEV,cAAc,EAAED,MAAM;IACpCA,MAAM;IACNlB,MAAM,EAAE0B;EACZ,CAAC,CAAC;EAEF,OAAOX,OAAO,CAACf,MAAM,CAAC8B,MAAM,IAAI;IAC5B,MAAMC,YAAiC,GAAG,CAAC,CAAC;IAE5C,MAAMvB,cAAc,GAAIR,MAAc,IAAK;MACvC,MAAM;QAAEgC;MAAK,CAAC,GAAGhC,MAAM;MACvB,IAAI+B,YAAY,CAACC,IAAI,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;QAC5BK,KAAK,EAAEmC,UAAU;QACjBE,SAAS,EAAEpC,MAAM,CAACN;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,14 +0,0 @@
1
- import type { CmsEntry } from "@webiny/api-headless-cms/types/index.js";
2
- import type { Field } from "./types.js";
3
- import { ValueFilter } from "@webiny/db-dynamodb/exports/api/db.js";
4
- interface Params {
5
- term?: string;
6
- targetFields?: string[];
7
- fields: Record<string, Field>;
8
- filter: ValueFilter.Interface;
9
- }
10
- /**
11
- * Unfortunately we must use the contains plugin directly as plugins do not support multi field searching.
12
- */
13
- export declare const createFullTextSearch: (params: Params) => ((item: CmsEntry) => boolean) | null;
14
- export {};
@@ -1,42 +0,0 @@
1
- import WebinyError from "@webiny/error";
2
- import { getValue } from "./getValue.js";
3
- /**
4
- * Unfortunately we must use the contains plugin directly as plugins do not support multi field searching.
5
- */
6
- export const createFullTextSearch = params => {
7
- const {
8
- term,
9
- targetFields,
10
- fields: fieldDefinitions,
11
- filter
12
- } = params;
13
- if (!term || term.trim().length === 0 || !targetFields || targetFields.length === 0) {
14
- return null;
15
- }
16
- return item => {
17
- for (const target of targetFields) {
18
- /**
19
- * As fields is a mapped Field objects where key is a path to the value, we can directly find the related field.
20
- */
21
- const field = fieldDefinitions[target];
22
- if (!field) {
23
- throw new WebinyError(`Unknown field "${target}" in the model.`, "UNKNOWN_FIELD", {
24
- target
25
- });
26
- }
27
- const value = getValue(item, target);
28
- if (!value) {
29
- continue;
30
- }
31
- if (filter.matches({
32
- value,
33
- compareValue: term
34
- }) === true) {
35
- return true;
36
- }
37
- }
38
- return false;
39
- };
40
- };
41
-
42
- //# sourceMappingURL=fullTextSearch.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["WebinyError","getValue","createFullTextSearch","params","term","targetFields","fields","fieldDefinitions","filter","trim","length","item","target","field","value","matches","compareValue"],"sources":["fullTextSearch.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsEntry } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { Field } from \"./types.js\";\nimport { getValue } from \"./getValue.js\";\nimport { ValueFilter } from \"@webiny/db-dynamodb/exports/api/db.js\";\n\ninterface Params {\n term?: string;\n targetFields?: string[];\n fields: Record<string, Field>;\n filter: ValueFilter.Interface;\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, filter } = 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 (filter.matches({ value, compareValue: term }) === true) {\n return true;\n }\n }\n return false;\n };\n};\n"],"mappings":"AAAA,OAAOA,WAAW,MAAM,eAAe;AAGvC,SAASC,QAAQ;AAUjB;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,5 +0,0 @@
1
- /**
2
- * A wrapper function for the find function.
3
- * Basically it transforms input paths to an array (and runs various checks).
4
- */
5
- export declare const getValue: (target: Record<string, any>, input: string | string[]) => any;
@@ -1,59 +0,0 @@
1
- const addArrayResult = (target, result) => {
2
- for (const r of result) {
3
- if (target.some(t => r === t)) {
4
- continue;
5
- }
6
- target.push(r);
7
- }
8
- };
9
- /**
10
- * A recursive function which goes through given input paths and returns the value in it.
11
- * In case a path is an array, it goes through the array of those values to get values further down the path line.
12
- */
13
- const find = (target, input) => {
14
- const paths = [...input];
15
- const path = paths.shift();
16
- if (!path) {
17
- return undefined;
18
- }
19
- const value = target?.[path];
20
- if (value === undefined) {
21
- return undefined;
22
- }
23
- if (paths.length === 0) {
24
- return value;
25
- } else if (Array.isArray(value)) {
26
- if (value.length === 0) {
27
- return undefined;
28
- }
29
- return value.reduce((collection, v) => {
30
- const result = find(v, paths);
31
- if (result === undefined) {
32
- return collection;
33
- } else if (Array.isArray(result)) {
34
- addArrayResult(collection, result);
35
- return collection;
36
- }
37
- collection.push(result);
38
- return collection;
39
- }, []);
40
- }
41
- return find(value, paths);
42
- };
43
- /**
44
- * A wrapper function for the find function.
45
- * Basically it transforms input paths to an array (and runs various checks).
46
- */
47
- export const getValue = (target, input) => {
48
- const paths = Array.isArray(input) ? input : input.split(".");
49
- if (paths.length === 0) {
50
- throw new Error(`Path is empty!`);
51
- }
52
- const filtered = paths.filter(Boolean);
53
- if (paths.length !== filtered.length) {
54
- throw new Error(`Input path is different than the filtered empty path string. (${paths.join(".")} to ${filtered.join(".")})`);
55
- }
56
- return find(target, paths);
57
- };
58
-
59
- //# sourceMappingURL=getValue.js.map
@@ -1 +0,0 @@
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;AACD;AACA;AACA;AACA;AACA,MAAMI,IAAI,GAAGA,CAACN,MAAuC,EAAEO,KAAe,KAAwB;EAC1F,MAAMC,KAAK,GAAG,CAAC,GAAGD,KAAK,CAAC;EACxB,MAAME,IAAI,GAAGD,KAAK,CAACE,KAAK,CAAC,CAAC;EAE1B,IAAI,CAACD,IAAI,EAAE;IACP,OAAOE,SAAS;EACpB;EAEA,MAAMC,KAAK,GAAGZ,MAAM,GAAGS,IAAI,CAAC;EAC5B,IAAIG,KAAK,KAAKD,SAAS,EAAE;IACrB,OAAOA,SAAS;EACpB;EACA,IAAIH,KAAK,CAACK,MAAM,KAAK,CAAC,EAAE;IACpB,OAAOD,KAAK;EAChB,CAAC,MAAM,IAAIE,KAAK,CAACC,OAAO,CAACH,KAAK,CAAC,EAAE;IAC7B,IAAIA,KAAK,CAACC,MAAM,KAAK,CAAC,EAAE;MACpB,OAAOF,SAAS;IACpB;IACA,OAAOC,KAAK,CAACI,MAAM,CAAQ,CAACC,UAAU,EAAEC,CAAC,KAAK;MAC1C,MAAMjB,MAAM,GAAGK,IAAI,CAACY,CAAC,EAAEV,KAAK,CAAC;MAC7B,IAAIP,MAAM,KAAKU,SAAS,EAAE;QACtB,OAAOM,UAAU;MACrB,CAAC,MAAM,IAAIH,KAAK,CAACC,OAAO,CAACd,MAAM,CAAC,EAAE;QAC9BF,cAAc,CAACkB,UAAU,EAAEhB,MAAM,CAAC;QAClC,OAAOgB,UAAU;MACrB;MACAA,UAAU,CAACZ,IAAI,CAACJ,MAAM,CAAC;MACvB,OAAOgB,UAAU;IACrB,CAAC,EAAE,EAAE,CAAC;EACV;EACA,OAAOX,IAAI,CAACM,KAAK,EAAEJ,KAAK,CAAC;AAC7B,CAAC;AACD;AACA;AACA;AACA;AACA,OAAO,MAAMW,QAAQ,GAAGA,CAACnB,MAA2B,EAAEO,KAAwB,KAAU;EACpF,MAAMC,KAAK,GAAGM,KAAK,CAACC,OAAO,CAACR,KAAK,CAAC,GAAGA,KAAK,GAAGA,KAAK,CAACa,KAAK,CAAC,GAAG,CAAC;EAC7D,IAAIZ,KAAK,CAACK,MAAM,KAAK,CAAC,EAAE;IACpB,MAAM,IAAIQ,KAAK,CAAC,gBAAgB,CAAC;EACrC;EACA,MAAMC,QAAQ,GAAGd,KAAK,CAACe,MAAM,CAACC,OAAO,CAAC;EACtC,IAAIhB,KAAK,CAACK,MAAM,KAAKS,QAAQ,CAACT,MAAM,EAAE;IAClC,MAAM,IAAIQ,KAAK,CACX,iEAAiEb,KAAK,CAACiB,IAAI,CACvE,GACJ,CAAC,OAAOH,QAAQ,CAACG,IAAI,CAAC,GAAG,CAAC,GAC9B,CAAC;EACL;EAEA,OAAOnB,IAAI,CAACN,MAAM,EAAEQ,KAAK,CAAC;AAC9B,CAAC","ignoreList":[]}
@@ -1,2 +0,0 @@
1
- export { filter } from "./filter.js";
2
- export { sort } from "./sort.js";
@@ -1,4 +0,0 @@
1
- export { filter } from "./filter.js";
2
- export { sort } from "./sort.js";
3
-
4
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["filter","sort"],"sources":["index.ts"],"sourcesContent":["export { filter } from \"./filter.js\";\nexport { sort } from \"./sort.js\";\n"],"mappings":"AAAA,SAASA,MAAM;AACf,SAASC,IAAI","ignoreList":[]}
@@ -1,8 +0,0 @@
1
- import type { Plugin, PluginsContainer } from "@webiny/plugins/types.js";
2
- interface Params {
3
- plugins: PluginsContainer;
4
- type: string;
5
- property: string;
6
- }
7
- export declare const getMappedPlugins: <T extends Plugin>(params: Params) => Record<string, T>;
8
- export {};
@@ -1,25 +0,0 @@
1
- import WebinyError from "@webiny/error";
2
- export const getMappedPlugins = params => {
3
- const {
4
- plugins: pluginsContainer,
5
- type,
6
- property
7
- } = params;
8
- const plugins = pluginsContainer.byType(type);
9
- if (plugins.length === 0) {
10
- return {};
11
- }
12
- return plugins.reduce((collection, plugin) => {
13
- const key = plugin[property];
14
- if (typeof key !== "string") {
15
- throw new WebinyError("Property to map the plugins on must be a string.", "PLUGIN_PROPERTY_ERROR", {
16
- type,
17
- property
18
- });
19
- }
20
- collection[key] = plugin;
21
- return collection;
22
- }, {});
23
- };
24
-
25
- //# sourceMappingURL=mapPlugins.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["WebinyError","getMappedPlugins","params","plugins","pluginsContainer","type","property","byType","length","reduce","collection","plugin","key"],"sources":["mapPlugins.ts"],"sourcesContent":["import type { Plugin, PluginsContainer } from \"@webiny/plugins/types.js\";\nimport WebinyError from \"@webiny/error\";\n\ninterface Params {\n plugins: PluginsContainer;\n type: string;\n property: string;\n}\nexport const getMappedPlugins = <T extends Plugin>(params: Params) => {\n const { plugins: pluginsContainer, type, property } = params;\n const plugins = pluginsContainer.byType<T>(type);\n if (plugins.length === 0) {\n return {};\n }\n return plugins.reduce<Record<string, T>>((collection, plugin) => {\n const key: keyof typeof plugin = plugin[property];\n if (typeof key !== \"string\") {\n throw new WebinyError(\n \"Property to map the plugins on must be a string.\",\n \"PLUGIN_PROPERTY_ERROR\",\n {\n type,\n property\n }\n );\n }\n collection[key] = plugin;\n return collection;\n }, {});\n};\n"],"mappings":"AACA,OAAOA,WAAW,MAAM,eAAe;AAOvC,OAAO,MAAMC,gBAAgB,GAAsBC,MAAc,IAAK;EAClE,MAAM;IAAEC,OAAO,EAAEC,gBAAgB;IAAEC,IAAI;IAAEC;EAAS,CAAC,GAAGJ,MAAM;EAC5D,MAAMC,OAAO,GAAGC,gBAAgB,CAACG,MAAM,CAAIF,IAAI,CAAC;EAChD,IAAIF,OAAO,CAACK,MAAM,KAAK,CAAC,EAAE;IACtB,OAAO,CAAC,CAAC;EACb;EACA,OAAOL,OAAO,CAACM,MAAM,CAAoB,CAACC,UAAU,EAAEC,MAAM,KAAK;IAC7D,MAAMC,GAAwB,GAAGD,MAAM,CAACL,QAAQ,CAAC;IACjD,IAAI,OAAOM,GAAG,KAAK,QAAQ,EAAE;MACzB,MAAM,IAAIZ,WAAW,CACjB,kDAAkD,EAClD,uBAAuB,EACvB;QACIK,IAAI;QACJC;MACJ,CACJ,CAAC;IACL;IACAI,UAAU,CAACE,GAAG,CAAC,GAAGD,MAAM;IACxB,OAAOD,UAAU;EACrB,CAAC,EAAE,CAAC,CAAC,CAAC;AACV,CAAC","ignoreList":[]}
@@ -1,2 +0,0 @@
1
- import { CmsEntryFieldFilterPlugin } from "../../../../plugins/CmsEntryFieldFilterPlugin.js";
2
- export declare const createDefaultFilterCreate: () => CmsEntryFieldFilterPlugin<any>;
@@ -1,37 +0,0 @@
1
- import WebinyError from "@webiny/error";
2
- import { CmsEntryFieldFilterPlugin } from "../../../../plugins/CmsEntryFieldFilterPlugin.js";
3
- export const createDefaultFilterCreate = () => {
4
- const plugin = new CmsEntryFieldFilterPlugin({
5
- fieldType: CmsEntryFieldFilterPlugin.ALL,
6
- create: params => {
7
- const {
8
- negate,
9
- transformValue,
10
- field,
11
- compareValue,
12
- valueFilterRegistry
13
- } = params;
14
- const filter = valueFilterRegistry.get(params.operation);
15
- if (!filter) {
16
- throw new WebinyError(`Missing ValueFilterPlugin for operation "${params.operation}".`, "MISSING_OPERATION_PLUGIN", {
17
- operation: params.operation
18
- });
19
- }
20
- return {
21
- negate,
22
- transformValue,
23
- field,
24
- compareValue,
25
- fieldPathId: [...field.parents.map(f => f.fieldId), field.fieldId].join("."),
26
- path: field.createPath({
27
- field
28
- }),
29
- filter
30
- };
31
- }
32
- });
33
- plugin.name = `headless-cms.ddb.filter.default`;
34
- return plugin;
35
- };
36
-
37
- //# sourceMappingURL=defaultFilterCreate.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["WebinyError","CmsEntryFieldFilterPlugin","createDefaultFilterCreate","plugin","fieldType","ALL","create","params","negate","transformValue","field","compareValue","valueFilterRegistry","filter","get","operation","fieldPathId","parents","map","f","fieldId","join","path","createPath","name"],"sources":["defaultFilterCreate.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsEntryFieldFilterPlugin } from \"~/plugins/CmsEntryFieldFilterPlugin.js\";\n\nexport const createDefaultFilterCreate = () => {\n const plugin = new CmsEntryFieldFilterPlugin({\n fieldType: CmsEntryFieldFilterPlugin.ALL,\n create: params => {\n const { negate, transformValue, field, compareValue, valueFilterRegistry } = params;\n const filter = valueFilterRegistry.get(params.operation);\n if (!filter) {\n throw new WebinyError(\n `Missing ValueFilterPlugin for operation \"${params.operation}\".`,\n \"MISSING_OPERATION_PLUGIN\",\n {\n operation: params.operation\n }\n );\n }\n return {\n negate,\n transformValue,\n field,\n compareValue,\n fieldPathId: [...field.parents.map(f => f.fieldId), field.fieldId].join(\".\"),\n path: field.createPath({\n field\n }),\n filter\n };\n }\n });\n\n plugin.name = `headless-cms.ddb.filter.default`;\n\n return plugin;\n};\n"],"mappings":"AAAA,OAAOA,WAAW,MAAM,eAAe;AACvC,SAASC,yBAAyB;AAElC,OAAO,MAAMC,yBAAyB,GAAGA,CAAA,KAAM;EAC3C,MAAMC,MAAM,GAAG,IAAIF,yBAAyB,CAAC;IACzCG,SAAS,EAAEH,yBAAyB,CAACI,GAAG;IACxCC,MAAM,EAAEC,MAAM,IAAI;MACd,MAAM;QAAEC,MAAM;QAAEC,cAAc;QAAEC,KAAK;QAAEC,YAAY;QAAEC;MAAoB,CAAC,GAAGL,MAAM;MACnF,MAAMM,MAAM,GAAGD,mBAAmB,CAACE,GAAG,CAACP,MAAM,CAACQ,SAAS,CAAC;MACxD,IAAI,CAACF,MAAM,EAAE;QACT,MAAM,IAAIb,WAAW,CACjB,4CAA4CO,MAAM,CAACQ,SAAS,IAAI,EAChE,0BAA0B,EAC1B;UACIA,SAAS,EAAER,MAAM,CAACQ;QACtB,CACJ,CAAC;MACL;MACA,OAAO;QACHP,MAAM;QACNC,cAAc;QACdC,KAAK;QACLC,YAAY;QACZK,WAAW,EAAE,CAAC,GAAGN,KAAK,CAACO,OAAO,CAACC,GAAG,CAACC,CAAC,IAAIA,CAAC,CAACC,OAAO,CAAC,EAAEV,KAAK,CAACU,OAAO,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC;QAC5EC,IAAI,EAAEZ,KAAK,CAACa,UAAU,CAAC;UACnBb;QACJ,CAAC,CAAC;QACFG;MACJ,CAAC;IACL;EACJ,CAAC,CAAC;EAEFV,MAAM,CAACqB,IAAI,GAAG,iCAAiC;EAE/C,OAAOrB,MAAM;AACjB,CAAC","ignoreList":[]}
@@ -1 +0,0 @@
1
- export declare const createFilterCreatePlugins: () => import("../../../../index.js").CmsEntryFieldFilterPlugin<import("@webiny/api/types.js").GenericRecord | null | undefined>[];
@@ -1,9 +0,0 @@
1
- import { createDefaultFilterCreate } from "./defaultFilterCreate.js";
2
- import { createRefFilterCreate } from "./refFilterCreate.js";
3
- import { objectFilterCreate } from "./objectFilterCreate.js";
4
- import { searchableJsonFilterCreate } from "./searchableJsonFilterCreate.js";
5
- export const createFilterCreatePlugins = () => {
6
- return [createDefaultFilterCreate(), createRefFilterCreate(), objectFilterCreate(), searchableJsonFilterCreate()];
7
- };
8
-
9
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["createDefaultFilterCreate","createRefFilterCreate","objectFilterCreate","searchableJsonFilterCreate","createFilterCreatePlugins"],"sources":["index.ts"],"sourcesContent":["import { createDefaultFilterCreate } from \"./defaultFilterCreate.js\";\nimport { createRefFilterCreate } from \"./refFilterCreate.js\";\nimport { objectFilterCreate } from \"./objectFilterCreate.js\";\nimport { searchableJsonFilterCreate } from \"./searchableJsonFilterCreate.js\";\n\nexport const createFilterCreatePlugins = () => {\n return [\n createDefaultFilterCreate(),\n createRefFilterCreate(),\n objectFilterCreate(),\n searchableJsonFilterCreate()\n ];\n};\n"],"mappings":"AAAA,SAASA,yBAAyB;AAClC,SAASC,qBAAqB;AAC9B,SAASC,kBAAkB;AAC3B,SAASC,0BAA0B;AAEnC,OAAO,MAAMC,yBAAyB,GAAGA,CAAA,KAAM;EAC3C,OAAO,CACHJ,yBAAyB,CAAC,CAAC,EAC3BC,qBAAqB,CAAC,CAAC,EACvBC,kBAAkB,CAAC,CAAC,EACpBC,0BAA0B,CAAC,CAAC,CAC/B;AACL,CAAC","ignoreList":[]}
@@ -1,2 +0,0 @@
1
- import { CmsEntryFieldFilterPlugin } from "../../../../plugins/CmsEntryFieldFilterPlugin.js";
2
- export declare const objectFilterCreate: () => CmsEntryFieldFilterPlugin<any>;
@@ -1,84 +0,0 @@
1
- import { CmsEntryFieldFilterPlugin } from "../../../../plugins/CmsEntryFieldFilterPlugin.js";
2
- import { extractWhereParams } from "../where.js";
3
- import WebinyError from "@webiny/error";
4
- import { transformValue } from "../transform.js";
5
- import { getBaseFieldType } from "@webiny/api-headless-cms/utils/getBaseFieldType.js";
6
- export const objectFilterCreate = () => {
7
- const plugin = new CmsEntryFieldFilterPlugin({
8
- fieldType: "object",
9
- create: params => {
10
- const {
11
- value: objectValue,
12
- valueFilterRegistry,
13
- transformValuePlugins,
14
- getFilterCreatePlugin,
15
- field: parentField,
16
- fields
17
- } = params;
18
- const filters = [];
19
- for (const key in objectValue) {
20
- const value = objectValue[key];
21
- if (value === undefined) {
22
- continue;
23
- }
24
- const whereParams = extractWhereParams(key);
25
- if (!whereParams) {
26
- continue;
27
- }
28
- const {
29
- negate,
30
- fieldId,
31
- operation
32
- } = whereParams;
33
- const fieldPath = parentField.parents.map(p => p.fieldId).concat([parentField.fieldId, fieldId]).join(".");
34
- const field = fields[fieldPath];
35
- if (!field) {
36
- throw new WebinyError(`There is no field with the field path "${fieldPath}".`, "FIELD_ERROR", {
37
- fieldId
38
- });
39
- }
40
- const fieldType = getBaseFieldType(field);
41
- const filterCreatePlugin = getFilterCreatePlugin(fieldType);
42
- const transformValuePlugin = transformValuePlugins[fieldType];
43
- const transformValueCallable = value => {
44
- if (!transformValuePlugin) {
45
- return value;
46
- }
47
- return transformValuePlugin.transform({
48
- field,
49
- value
50
- });
51
- };
52
- const result = filterCreatePlugin.create({
53
- key,
54
- value,
55
- valueFilterRegistry,
56
- transformValuePlugins,
57
- getFilterCreatePlugin,
58
- operation,
59
- negate,
60
- field,
61
- fields,
62
- compareValue: transformValue({
63
- value,
64
- transform: transformValueCallable
65
- }),
66
- transformValue: transformValueCallable
67
- });
68
- if (!result) {
69
- continue;
70
- }
71
- if (Array.isArray(result)) {
72
- filters.push(...result);
73
- continue;
74
- }
75
- filters.push(result);
76
- }
77
- return filters;
78
- }
79
- });
80
- plugin.name = `headless-cms.ddb.filter.object`;
81
- return plugin;
82
- };
83
-
84
- //# sourceMappingURL=objectFilterCreate.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["CmsEntryFieldFilterPlugin","extractWhereParams","WebinyError","transformValue","getBaseFieldType","objectFilterCreate","plugin","fieldType","create","params","value","objectValue","valueFilterRegistry","transformValuePlugins","getFilterCreatePlugin","field","parentField","fields","filters","key","undefined","whereParams","negate","fieldId","operation","fieldPath","parents","map","p","concat","join","filterCreatePlugin","transformValuePlugin","transformValueCallable","transform","result","compareValue","Array","isArray","push","name"],"sources":["objectFilterCreate.ts"],"sourcesContent":["import { CmsEntryFieldFilterPlugin } from \"~/plugins/CmsEntryFieldFilterPlugin.js\";\nimport { extractWhereParams } from \"~/operations/entry/filtering/where.js\";\nimport WebinyError from \"@webiny/error\";\nimport type { CmsFieldFilterValueTransformPlugin } from \"~/types.js\";\nimport { transformValue } from \"~/operations/entry/filtering/transform.js\";\nimport { getBaseFieldType } from \"@webiny/api-headless-cms/utils/getBaseFieldType.js\";\n\nexport const objectFilterCreate = () => {\n const plugin = new CmsEntryFieldFilterPlugin({\n fieldType: \"object\",\n create: params => {\n const {\n value: objectValue,\n valueFilterRegistry,\n transformValuePlugins,\n getFilterCreatePlugin,\n field: parentField,\n fields\n } = params;\n\n const filters = [];\n\n for (const key in objectValue) {\n const value = objectValue[key];\n if (value === undefined) {\n continue;\n }\n const whereParams = extractWhereParams(key);\n if (!whereParams) {\n continue;\n }\n const { negate, fieldId, operation } = whereParams;\n\n const fieldPath = parentField.parents\n .map(p => p.fieldId)\n .concat([parentField.fieldId, fieldId])\n .join(\".\");\n\n const field = fields[fieldPath];\n if (!field) {\n throw new WebinyError(\n `There is no field with the field path \"${fieldPath}\".`,\n \"FIELD_ERROR\",\n {\n fieldId\n }\n );\n }\n\n const fieldType = getBaseFieldType(field);\n\n const filterCreatePlugin = getFilterCreatePlugin(fieldType);\n\n const transformValuePlugin: CmsFieldFilterValueTransformPlugin =\n transformValuePlugins[fieldType];\n\n const transformValueCallable = (value: any) => {\n if (!transformValuePlugin) {\n return value;\n }\n return transformValuePlugin.transform({\n field,\n value\n });\n };\n\n const result = filterCreatePlugin.create({\n key,\n value,\n valueFilterRegistry,\n transformValuePlugins,\n getFilterCreatePlugin,\n operation,\n negate,\n field,\n fields,\n compareValue: transformValue({\n value,\n transform: transformValueCallable\n }),\n transformValue: transformValueCallable\n });\n if (!result) {\n continue;\n }\n if (Array.isArray(result)) {\n filters.push(...result);\n continue;\n }\n\n filters.push(result);\n }\n return filters;\n }\n });\n\n plugin.name = `headless-cms.ddb.filter.object`;\n\n return plugin;\n};\n"],"mappings":"AAAA,SAASA,yBAAyB;AAClC,SAASC,kBAAkB;AAC3B,OAAOC,WAAW,MAAM,eAAe;AAEvC,SAASC,cAAc;AACvB,SAASC,gBAAgB,QAAQ,oDAAoD;AAErF,OAAO,MAAMC,kBAAkB,GAAGA,CAAA,KAAM;EACpC,MAAMC,MAAM,GAAG,IAAIN,yBAAyB,CAAC;IACzCO,SAAS,EAAE,QAAQ;IACnBC,MAAM,EAAEC,MAAM,IAAI;MACd,MAAM;QACFC,KAAK,EAAEC,WAAW;QAClBC,mBAAmB;QACnBC,qBAAqB;QACrBC,qBAAqB;QACrBC,KAAK,EAAEC,WAAW;QAClBC;MACJ,CAAC,GAAGR,MAAM;MAEV,MAAMS,OAAO,GAAG,EAAE;MAElB,KAAK,MAAMC,GAAG,IAAIR,WAAW,EAAE;QAC3B,MAAMD,KAAK,GAAGC,WAAW,CAACQ,GAAG,CAAC;QAC9B,IAAIT,KAAK,KAAKU,SAAS,EAAE;UACrB;QACJ;QACA,MAAMC,WAAW,GAAGpB,kBAAkB,CAACkB,GAAG,CAAC;QAC3C,IAAI,CAACE,WAAW,EAAE;UACd;QACJ;QACA,MAAM;UAAEC,MAAM;UAAEC,OAAO;UAAEC;QAAU,CAAC,GAAGH,WAAW;QAElD,MAAMI,SAAS,GAAGT,WAAW,CAACU,OAAO,CAChCC,GAAG,CAACC,CAAC,IAAIA,CAAC,CAACL,OAAO,CAAC,CACnBM,MAAM,CAAC,CAACb,WAAW,CAACO,OAAO,EAAEA,OAAO,CAAC,CAAC,CACtCO,IAAI,CAAC,GAAG,CAAC;QAEd,MAAMf,KAAK,GAAGE,MAAM,CAACQ,SAAS,CAAC;QAC/B,IAAI,CAACV,KAAK,EAAE;UACR,MAAM,IAAIb,WAAW,CACjB,0CAA0CuB,SAAS,IAAI,EACvD,aAAa,EACb;YACIF;UACJ,CACJ,CAAC;QACL;QAEA,MAAMhB,SAAS,GAAGH,gBAAgB,CAACW,KAAK,CAAC;QAEzC,MAAMgB,kBAAkB,GAAGjB,qBAAqB,CAACP,SAAS,CAAC;QAE3D,MAAMyB,oBAAwD,GAC1DnB,qBAAqB,CAACN,SAAS,CAAC;QAEpC,MAAM0B,sBAAsB,GAAIvB,KAAU,IAAK;UAC3C,IAAI,CAACsB,oBAAoB,EAAE;YACvB,OAAOtB,KAAK;UAChB;UACA,OAAOsB,oBAAoB,CAACE,SAAS,CAAC;YAClCnB,KAAK;YACLL;UACJ,CAAC,CAAC;QACN,CAAC;QAED,MAAMyB,MAAM,GAAGJ,kBAAkB,CAACvB,MAAM,CAAC;UACrCW,GAAG;UACHT,KAAK;UACLE,mBAAmB;UACnBC,qBAAqB;UACrBC,qBAAqB;UACrBU,SAAS;UACTF,MAAM;UACNP,KAAK;UACLE,MAAM;UACNmB,YAAY,EAAEjC,cAAc,CAAC;YACzBO,KAAK;YACLwB,SAAS,EAAED;UACf,CAAC,CAAC;UACF9B,cAAc,EAAE8B;QACpB,CAAC,CAAC;QACF,IAAI,CAACE,MAAM,EAAE;UACT;QACJ;QACA,IAAIE,KAAK,CAACC,OAAO,CAACH,MAAM,CAAC,EAAE;UACvBjB,OAAO,CAACqB,IAAI,CAAC,GAAGJ,MAAM,CAAC;UACvB;QACJ;QAEAjB,OAAO,CAACqB,IAAI,CAACJ,MAAM,CAAC;MACxB;MACA,OAAOjB,OAAO;IAClB;EACJ,CAAC,CAAC;EAEFZ,MAAM,CAACkC,IAAI,GAAG,gCAAgC;EAE9C,OAAOlC,MAAM;AACjB,CAAC","ignoreList":[]}
@@ -1,3 +0,0 @@
1
- import { CmsEntryFieldFilterPlugin } from "../../../../plugins/CmsEntryFieldFilterPlugin.js";
2
- import type { GenericRecord } from "@webiny/api/types.js";
3
- export declare const createRefFilterCreate: () => CmsEntryFieldFilterPlugin<GenericRecord | null | undefined>;
@@ -1,74 +0,0 @@
1
- import WebinyError from "@webiny/error";
2
- import { CmsEntryFieldFilterPlugin } from "../../../../plugins/CmsEntryFieldFilterPlugin.js";
3
- import { extractWhereParams } from "../where.js";
4
- import { transformValue } from "../transform.js";
5
- import { getBaseFieldType } from "@webiny/api-headless-cms/utils/getBaseFieldType.js";
6
- export const createRefFilterCreate = () => {
7
- const plugin = new CmsEntryFieldFilterPlugin({
8
- fieldType: "ref",
9
- create: params => {
10
- const {
11
- valueFilterRegistry,
12
- transformValuePlugins,
13
- field
14
- } = params;
15
- let value = params.value;
16
- if (!value) {
17
- value = {
18
- entryId: null
19
- };
20
- }
21
- const propertyFilters = Object.keys(value);
22
- if (propertyFilters.length === 0) {
23
- return null;
24
- }
25
- const filters = [];
26
- for (const propertyFilter of propertyFilters) {
27
- const whereParams = extractWhereParams(propertyFilter);
28
- if (!whereParams) {
29
- continue;
30
- }
31
- const {
32
- fieldId: propertyId,
33
- operation: propertyOperation,
34
- negate
35
- } = whereParams;
36
- const fieldType = getBaseFieldType(field);
37
- const transformValuePlugin = transformValuePlugins[fieldType];
38
- const transformValueCallable = value => {
39
- if (!transformValuePlugin) {
40
- return value;
41
- }
42
- return transformValuePlugin.transform({
43
- field,
44
- value
45
- });
46
- };
47
- const filter = valueFilterRegistry.get(propertyOperation);
48
- if (!filter) {
49
- throw new WebinyError(`Missing operation filter for "${propertyOperation}".`, "MISSING_OPERATION_FILTER");
50
- }
51
- const paths = [field.createPath({
52
- field
53
- }), propertyId];
54
- filters.push({
55
- field,
56
- path: paths.join("."),
57
- fieldPathId: [...field.parents.map(f => f.fieldId), field.fieldId].join("."),
58
- filter,
59
- negate,
60
- compareValue: transformValue({
61
- value: value[propertyFilter],
62
- transform: transformValueCallable
63
- }),
64
- transformValue: transformValueCallable
65
- });
66
- }
67
- return filters;
68
- }
69
- });
70
- plugin.name = `headless-cms.ddb.filter.ref`;
71
- return plugin;
72
- };
73
-
74
- //# sourceMappingURL=refFilterCreate.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["WebinyError","CmsEntryFieldFilterPlugin","extractWhereParams","transformValue","getBaseFieldType","createRefFilterCreate","plugin","fieldType","create","params","valueFilterRegistry","transformValuePlugins","field","value","entryId","propertyFilters","Object","keys","length","filters","propertyFilter","whereParams","fieldId","propertyId","operation","propertyOperation","negate","transformValuePlugin","transformValueCallable","transform","filter","get","paths","createPath","push","path","join","fieldPathId","parents","map","f","compareValue","name"],"sources":["refFilterCreate.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsEntryFieldFilterPluginCreateResponse } from \"~/plugins/CmsEntryFieldFilterPlugin.js\";\nimport { CmsEntryFieldFilterPlugin } from \"~/plugins/CmsEntryFieldFilterPlugin.js\";\nimport { extractWhereParams } from \"~/operations/entry/filtering/where.js\";\nimport { transformValue } from \"~/operations/entry/filtering/transform.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport { getBaseFieldType } from \"@webiny/api-headless-cms/utils/getBaseFieldType.js\";\n\nexport const createRefFilterCreate = () => {\n const plugin = new CmsEntryFieldFilterPlugin<GenericRecord | null | undefined>({\n fieldType: \"ref\",\n create: params => {\n const { valueFilterRegistry, transformValuePlugins, field } = params;\n let value = params.value;\n if (!value) {\n value = {\n entryId: null\n };\n }\n const propertyFilters = Object.keys(value);\n if (propertyFilters.length === 0) {\n return null;\n }\n const filters: CmsEntryFieldFilterPluginCreateResponse[] = [];\n\n for (const propertyFilter of propertyFilters) {\n const whereParams = extractWhereParams(propertyFilter);\n if (!whereParams) {\n continue;\n }\n const { fieldId: propertyId, operation: propertyOperation, negate } = whereParams;\n\n const fieldType = getBaseFieldType(field);\n\n const transformValuePlugin = transformValuePlugins[fieldType];\n\n const transformValueCallable = (value: any) => {\n if (!transformValuePlugin) {\n return value;\n }\n return transformValuePlugin.transform({\n field,\n value\n });\n };\n\n const filter = valueFilterRegistry.get(propertyOperation);\n if (!filter) {\n throw new WebinyError(\n `Missing operation filter for \"${propertyOperation}\".`,\n \"MISSING_OPERATION_FILTER\"\n );\n }\n\n const paths = [\n field.createPath({\n field\n }),\n propertyId\n ];\n\n filters.push({\n field,\n path: paths.join(\".\"),\n fieldPathId: [...field.parents.map(f => f.fieldId), field.fieldId].join(\".\"),\n filter,\n negate,\n compareValue: transformValue({\n value: value[propertyFilter],\n transform: transformValueCallable\n }),\n transformValue: transformValueCallable\n });\n }\n\n return filters;\n }\n });\n\n plugin.name = `headless-cms.ddb.filter.ref`;\n\n return plugin;\n};\n"],"mappings":"AAAA,OAAOA,WAAW,MAAM,eAAe;AAEvC,SAASC,yBAAyB;AAClC,SAASC,kBAAkB;AAC3B,SAASC,cAAc;AAEvB,SAASC,gBAAgB,QAAQ,oDAAoD;AAErF,OAAO,MAAMC,qBAAqB,GAAGA,CAAA,KAAM;EACvC,MAAMC,MAAM,GAAG,IAAIL,yBAAyB,CAAmC;IAC3EM,SAAS,EAAE,KAAK;IAChBC,MAAM,EAAEC,MAAM,IAAI;MACd,MAAM;QAAEC,mBAAmB;QAAEC,qBAAqB;QAAEC;MAAM,CAAC,GAAGH,MAAM;MACpE,IAAII,KAAK,GAAGJ,MAAM,CAACI,KAAK;MACxB,IAAI,CAACA,KAAK,EAAE;QACRA,KAAK,GAAG;UACJC,OAAO,EAAE;QACb,CAAC;MACL;MACA,MAAMC,eAAe,GAAGC,MAAM,CAACC,IAAI,CAACJ,KAAK,CAAC;MAC1C,IAAIE,eAAe,CAACG,MAAM,KAAK,CAAC,EAAE;QAC9B,OAAO,IAAI;MACf;MACA,MAAMC,OAAkD,GAAG,EAAE;MAE7D,KAAK,MAAMC,cAAc,IAAIL,eAAe,EAAE;QAC1C,MAAMM,WAAW,GAAGnB,kBAAkB,CAACkB,cAAc,CAAC;QACtD,IAAI,CAACC,WAAW,EAAE;UACd;QACJ;QACA,MAAM;UAAEC,OAAO,EAAEC,UAAU;UAAEC,SAAS,EAAEC,iBAAiB;UAAEC;QAAO,CAAC,GAAGL,WAAW;QAEjF,MAAMd,SAAS,GAAGH,gBAAgB,CAACQ,KAAK,CAAC;QAEzC,MAAMe,oBAAoB,GAAGhB,qBAAqB,CAACJ,SAAS,CAAC;QAE7D,MAAMqB,sBAAsB,GAAIf,KAAU,IAAK;UAC3C,IAAI,CAACc,oBAAoB,EAAE;YACvB,OAAOd,KAAK;UAChB;UACA,OAAOc,oBAAoB,CAACE,SAAS,CAAC;YAClCjB,KAAK;YACLC;UACJ,CAAC,CAAC;QACN,CAAC;QAED,MAAMiB,MAAM,GAAGpB,mBAAmB,CAACqB,GAAG,CAACN,iBAAiB,CAAC;QACzD,IAAI,CAACK,MAAM,EAAE;UACT,MAAM,IAAI9B,WAAW,CACjB,iCAAiCyB,iBAAiB,IAAI,EACtD,0BACJ,CAAC;QACL;QAEA,MAAMO,KAAK,GAAG,CACVpB,KAAK,CAACqB,UAAU,CAAC;UACbrB;QACJ,CAAC,CAAC,EACFW,UAAU,CACb;QAEDJ,OAAO,CAACe,IAAI,CAAC;UACTtB,KAAK;UACLuB,IAAI,EAAEH,KAAK,CAACI,IAAI,CAAC,GAAG,CAAC;UACrBC,WAAW,EAAE,CAAC,GAAGzB,KAAK,CAAC0B,OAAO,CAACC,GAAG,CAACC,CAAC,IAAIA,CAAC,CAAClB,OAAO,CAAC,EAAEV,KAAK,CAACU,OAAO,CAAC,CAACc,IAAI,CAAC,GAAG,CAAC;UAC5EN,MAAM;UACNJ,MAAM;UACNe,YAAY,EAAEtC,cAAc,CAAC;YACzBU,KAAK,EAAEA,KAAK,CAACO,cAAc,CAAC;YAC5BS,SAAS,EAAED;UACf,CAAC,CAAC;UACFzB,cAAc,EAAEyB;QACpB,CAAC,CAAC;MACN;MAEA,OAAOT,OAAO;IAClB;EACJ,CAAC,CAAC;EAEFb,MAAM,CAACoC,IAAI,GAAG,6BAA6B;EAE3C,OAAOpC,MAAM;AACjB,CAAC","ignoreList":[]}
@@ -1,2 +0,0 @@
1
- import { CmsEntryFieldFilterPlugin } from "../../../../plugins/CmsEntryFieldFilterPlugin.js";
2
- export declare const searchableJsonFilterCreate: () => CmsEntryFieldFilterPlugin<any>;