@webiny/api-headless-cms-storage 6.6.0-alpha.0 → 6.6.0-alpha.10

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 (204) hide show
  1. package/{dist/cms → cms}/storageHelpers.js +3 -3
  2. package/cms/storageHelpers.js.map +1 -0
  3. package/features/FilterRegistriesFeature.d.ts +9 -0
  4. package/features/FilterRegistriesFeature.js +17 -0
  5. package/features/FilterRegistriesFeature.js.map +1 -0
  6. package/features/fieldFilterCreate/DefaultFieldFilterCreateRegistry.d.ts +9 -0
  7. package/features/fieldFilterCreate/DefaultFieldFilterCreateRegistry.js +26 -0
  8. package/features/fieldFilterCreate/DefaultFieldFilterCreateRegistry.js.map +1 -0
  9. package/features/fieldFilterPath/DefaultFieldFilterPathRegistry.d.ts +9 -0
  10. package/features/fieldFilterPath/DefaultFieldFilterPathRegistry.js +20 -0
  11. package/features/fieldFilterPath/DefaultFieldFilterPathRegistry.js.map +1 -0
  12. package/features/fieldFilterValueTransform/DefaultFieldFilterValueTransformRegistry.d.ts +9 -0
  13. package/features/fieldFilterValueTransform/DefaultFieldFilterValueTransformRegistry.js +17 -0
  14. package/features/fieldFilterValueTransform/DefaultFieldFilterValueTransformRegistry.js.map +1 -0
  15. package/features/fieldSorting/DefaultFieldSortingRegistry.d.ts +8 -0
  16. package/features/fieldSorting/DefaultFieldSortingRegistry.js +11 -0
  17. package/features/fieldSorting/DefaultFieldSortingRegistry.js.map +1 -0
  18. package/{dist/filtering → filtering}/fields/createFields.d.ts +2 -0
  19. package/{dist/filtering → filtering}/fields/createFields.js +2 -2
  20. package/filtering/fields/createFields.js.map +1 -0
  21. package/{dist/filtering → filtering}/fields/extractSort.js +1 -1
  22. package/{dist/filtering → filtering}/fields/extractSort.js.map +1 -1
  23. package/filtering/fields/systemFields.d.ts +5 -0
  24. package/{dist/filtering → filtering}/fields/systemFields.js +17 -1
  25. package/filtering/fields/systemFields.js.map +1 -0
  26. package/{dist/filtering → filtering}/filter.js +1 -1
  27. package/{dist/filtering → filtering}/filter.js.map +1 -1
  28. package/{dist/filtering → filtering}/getValue.js +2 -2
  29. package/{dist/filtering → filtering}/getValue.js.map +1 -1
  30. package/{dist/filtering → filtering}/sort.js +1 -1
  31. package/{dist/filtering → filtering}/sort.js.map +1 -1
  32. package/{dist/handlers → handlers}/datetimeTransformHandler.js +3 -3
  33. package/{dist/handlers → handlers}/datetimeTransformHandler.js.map +1 -1
  34. package/{dist/handlers → handlers}/locationFolderIdPathHandler.js +1 -1
  35. package/{dist/handlers → handlers}/locationFolderIdPathHandler.js.map +1 -1
  36. package/package.json +20 -15
  37. package/{dist/path → path}/locationFolderId.js +1 -1
  38. package/{dist/path → path}/locationFolderId.js.map +1 -1
  39. package/{dist/plugins → plugins}/CmsEntryFieldFilterPathPlugin.js +2 -2
  40. package/{dist/plugins → plugins}/CmsEntryFieldFilterPathPlugin.js.map +1 -1
  41. package/{dist/transforms → transforms}/datetime.js +3 -3
  42. package/{dist/transforms → transforms}/datetime.js.map +1 -1
  43. package/__tests__/filtering/getValue.test.ts +0 -58
  44. package/__tests__/filtering/mocks/entry.noModel.ts +0 -110
  45. package/__tests__/path/plainObject.test.ts +0 -32
  46. package/__tests__/transforms/datetime.test.ts +0 -71
  47. package/dist/cms/storageHelpers.js.map +0 -1
  48. package/dist/features/FilterRegistriesFeature.d.ts +0 -4
  49. package/dist/features/FilterRegistriesFeature.js +0 -39
  50. package/dist/features/FilterRegistriesFeature.js.map +0 -1
  51. package/dist/filtering/fields/createFields.js.map +0 -1
  52. package/dist/filtering/fields/systemFields.d.ts +0 -2
  53. package/dist/filtering/fields/systemFields.js.map +0 -1
  54. package/dist/package.json +0 -30
  55. package/src/cms/storageHelpers.ts +0 -92
  56. package/src/features/FilterRegistriesFeature.ts +0 -40
  57. package/src/features/fieldFilterCreate/FieldFilterCreateRegistry.ts +0 -25
  58. package/src/features/fieldFilterCreate/abstractions.ts +0 -51
  59. package/src/features/fieldFilterPath/FieldFilterPathRegistry.ts +0 -13
  60. package/src/features/fieldFilterPath/abstractions.ts +0 -22
  61. package/src/features/fieldFilterValueTransform/FieldFilterValueTransformRegistry.ts +0 -15
  62. package/src/features/fieldFilterValueTransform/abstractions.ts +0 -21
  63. package/src/features/fieldSorting/FieldSortingRegistry.ts +0 -20
  64. package/src/features/fieldSorting/abstractions.ts +0 -49
  65. package/src/filtering/expressions/createExpressions.ts +0 -170
  66. package/src/filtering/fields/createFields.ts +0 -124
  67. package/src/filtering/fields/extractSort.ts +0 -97
  68. package/src/filtering/fields/systemFields.ts +0 -165
  69. package/src/filtering/fields/types.ts +0 -46
  70. package/src/filtering/filter.ts +0 -166
  71. package/src/filtering/fullTextSearch.ts +0 -40
  72. package/src/filtering/getValue.ts +0 -64
  73. package/src/filtering/mapPlugins.ts +0 -30
  74. package/src/filtering/plugins/defaultFilterCreate.ts +0 -36
  75. package/src/filtering/plugins/index.ts +0 -13
  76. package/src/filtering/plugins/objectFilterCreate.ts +0 -100
  77. package/src/filtering/plugins/refFilterCreate.ts +0 -83
  78. package/src/filtering/plugins/searchableJsonFilterCreate.ts +0 -78
  79. package/src/filtering/sort.ts +0 -79
  80. package/src/filtering/transform.ts +0 -11
  81. package/src/filtering/values.ts +0 -24
  82. package/src/filtering/where.ts +0 -24
  83. package/src/handlers/datetimeTransformHandler.ts +0 -52
  84. package/src/handlers/defaultFilterCreateHandler.ts +0 -31
  85. package/src/handlers/locationFolderIdPathHandler.ts +0 -24
  86. package/src/handlers/objectFilterCreateHandler.ts +0 -86
  87. package/src/handlers/plainObjectPathHandler.ts +0 -17
  88. package/src/handlers/refFilterCreateHandler.ts +0 -65
  89. package/src/handlers/searchableJsonFilterCreateHandler.ts +0 -61
  90. package/src/index.ts +0 -63
  91. package/src/path/locationFolderId.ts +0 -29
  92. package/src/path/plainObject.ts +0 -21
  93. package/src/plugins/CmsEntryFieldFilterPathPlugin.ts +0 -58
  94. package/src/plugins/CmsEntryFieldFilterPlugin.ts +0 -59
  95. package/src/plugins/CmsEntryFieldSortingPlugin.ts +0 -63
  96. package/src/plugins/CmsFieldFilterValueTransformPlugin.ts +0 -43
  97. package/src/plugins/index.ts +0 -10
  98. package/src/transforms/datetime.ts +0 -62
  99. package/tsconfig.build.json +0 -33
  100. package/tsconfig.json +0 -33
  101. package/vitest.config.ts +0 -5
  102. package/webiny.config.js +0 -8
  103. /package/{dist/LICENSE → LICENSE} +0 -0
  104. /package/{dist/README.md → README.md} +0 -0
  105. /package/{dist/cms → cms}/storageHelpers.d.ts +0 -0
  106. /package/{dist/features → features}/fieldFilterCreate/FieldFilterCreateRegistry.d.ts +0 -0
  107. /package/{dist/features → features}/fieldFilterCreate/FieldFilterCreateRegistry.js +0 -0
  108. /package/{dist/features → features}/fieldFilterCreate/FieldFilterCreateRegistry.js.map +0 -0
  109. /package/{dist/features → features}/fieldFilterCreate/abstractions.d.ts +0 -0
  110. /package/{dist/features → features}/fieldFilterCreate/abstractions.js +0 -0
  111. /package/{dist/features → features}/fieldFilterCreate/abstractions.js.map +0 -0
  112. /package/{dist/features → features}/fieldFilterPath/FieldFilterPathRegistry.d.ts +0 -0
  113. /package/{dist/features → features}/fieldFilterPath/FieldFilterPathRegistry.js +0 -0
  114. /package/{dist/features → features}/fieldFilterPath/FieldFilterPathRegistry.js.map +0 -0
  115. /package/{dist/features → features}/fieldFilterPath/abstractions.d.ts +0 -0
  116. /package/{dist/features → features}/fieldFilterPath/abstractions.js +0 -0
  117. /package/{dist/features → features}/fieldFilterPath/abstractions.js.map +0 -0
  118. /package/{dist/features → features}/fieldFilterValueTransform/FieldFilterValueTransformRegistry.d.ts +0 -0
  119. /package/{dist/features → features}/fieldFilterValueTransform/FieldFilterValueTransformRegistry.js +0 -0
  120. /package/{dist/features → features}/fieldFilterValueTransform/FieldFilterValueTransformRegistry.js.map +0 -0
  121. /package/{dist/features → features}/fieldFilterValueTransform/abstractions.d.ts +0 -0
  122. /package/{dist/features → features}/fieldFilterValueTransform/abstractions.js +0 -0
  123. /package/{dist/features → features}/fieldFilterValueTransform/abstractions.js.map +0 -0
  124. /package/{dist/features → features}/fieldSorting/FieldSortingRegistry.d.ts +0 -0
  125. /package/{dist/features → features}/fieldSorting/FieldSortingRegistry.js +0 -0
  126. /package/{dist/features → features}/fieldSorting/FieldSortingRegistry.js.map +0 -0
  127. /package/{dist/features → features}/fieldSorting/abstractions.d.ts +0 -0
  128. /package/{dist/features → features}/fieldSorting/abstractions.js +0 -0
  129. /package/{dist/features → features}/fieldSorting/abstractions.js.map +0 -0
  130. /package/{dist/filtering → filtering}/expressions/createExpressions.d.ts +0 -0
  131. /package/{dist/filtering → filtering}/expressions/createExpressions.js +0 -0
  132. /package/{dist/filtering → filtering}/expressions/createExpressions.js.map +0 -0
  133. /package/{dist/filtering → filtering}/fields/extractSort.d.ts +0 -0
  134. /package/{dist/filtering → filtering}/fields/types.d.ts +0 -0
  135. /package/{dist/filtering → filtering}/fields/types.js +0 -0
  136. /package/{dist/filtering → filtering}/filter.d.ts +0 -0
  137. /package/{dist/filtering → filtering}/fullTextSearch.d.ts +0 -0
  138. /package/{dist/filtering → filtering}/fullTextSearch.js +0 -0
  139. /package/{dist/filtering → filtering}/fullTextSearch.js.map +0 -0
  140. /package/{dist/filtering → filtering}/getValue.d.ts +0 -0
  141. /package/{dist/filtering → filtering}/mapPlugins.d.ts +0 -0
  142. /package/{dist/filtering → filtering}/mapPlugins.js +0 -0
  143. /package/{dist/filtering → filtering}/mapPlugins.js.map +0 -0
  144. /package/{dist/filtering → filtering}/plugins/defaultFilterCreate.d.ts +0 -0
  145. /package/{dist/filtering → filtering}/plugins/defaultFilterCreate.js +0 -0
  146. /package/{dist/filtering → filtering}/plugins/defaultFilterCreate.js.map +0 -0
  147. /package/{dist/filtering → filtering}/plugins/index.d.ts +0 -0
  148. /package/{dist/filtering → filtering}/plugins/index.js +0 -0
  149. /package/{dist/filtering → filtering}/plugins/index.js.map +0 -0
  150. /package/{dist/filtering → filtering}/plugins/objectFilterCreate.d.ts +0 -0
  151. /package/{dist/filtering → filtering}/plugins/objectFilterCreate.js +0 -0
  152. /package/{dist/filtering → filtering}/plugins/objectFilterCreate.js.map +0 -0
  153. /package/{dist/filtering → filtering}/plugins/refFilterCreate.d.ts +0 -0
  154. /package/{dist/filtering → filtering}/plugins/refFilterCreate.js +0 -0
  155. /package/{dist/filtering → filtering}/plugins/refFilterCreate.js.map +0 -0
  156. /package/{dist/filtering → filtering}/plugins/searchableJsonFilterCreate.d.ts +0 -0
  157. /package/{dist/filtering → filtering}/plugins/searchableJsonFilterCreate.js +0 -0
  158. /package/{dist/filtering → filtering}/plugins/searchableJsonFilterCreate.js.map +0 -0
  159. /package/{dist/filtering → filtering}/sort.d.ts +0 -0
  160. /package/{dist/filtering → filtering}/transform.d.ts +0 -0
  161. /package/{dist/filtering → filtering}/transform.js +0 -0
  162. /package/{dist/filtering → filtering}/transform.js.map +0 -0
  163. /package/{dist/filtering → filtering}/values.d.ts +0 -0
  164. /package/{dist/filtering → filtering}/values.js +0 -0
  165. /package/{dist/filtering → filtering}/values.js.map +0 -0
  166. /package/{dist/filtering → filtering}/where.d.ts +0 -0
  167. /package/{dist/filtering → filtering}/where.js +0 -0
  168. /package/{dist/filtering → filtering}/where.js.map +0 -0
  169. /package/{dist/handlers → handlers}/datetimeTransformHandler.d.ts +0 -0
  170. /package/{dist/handlers → handlers}/defaultFilterCreateHandler.d.ts +0 -0
  171. /package/{dist/handlers → handlers}/defaultFilterCreateHandler.js +0 -0
  172. /package/{dist/handlers → handlers}/defaultFilterCreateHandler.js.map +0 -0
  173. /package/{dist/handlers → handlers}/locationFolderIdPathHandler.d.ts +0 -0
  174. /package/{dist/handlers → handlers}/objectFilterCreateHandler.d.ts +0 -0
  175. /package/{dist/handlers → handlers}/objectFilterCreateHandler.js +0 -0
  176. /package/{dist/handlers → handlers}/objectFilterCreateHandler.js.map +0 -0
  177. /package/{dist/handlers → handlers}/plainObjectPathHandler.d.ts +0 -0
  178. /package/{dist/handlers → handlers}/plainObjectPathHandler.js +0 -0
  179. /package/{dist/handlers → handlers}/plainObjectPathHandler.js.map +0 -0
  180. /package/{dist/handlers → handlers}/refFilterCreateHandler.d.ts +0 -0
  181. /package/{dist/handlers → handlers}/refFilterCreateHandler.js +0 -0
  182. /package/{dist/handlers → handlers}/refFilterCreateHandler.js.map +0 -0
  183. /package/{dist/handlers → handlers}/searchableJsonFilterCreateHandler.d.ts +0 -0
  184. /package/{dist/handlers → handlers}/searchableJsonFilterCreateHandler.js +0 -0
  185. /package/{dist/handlers → handlers}/searchableJsonFilterCreateHandler.js.map +0 -0
  186. /package/{dist/index.d.ts → index.d.ts} +0 -0
  187. /package/{dist/index.js → index.js} +0 -0
  188. /package/{dist/path → path}/locationFolderId.d.ts +0 -0
  189. /package/{dist/path → path}/plainObject.d.ts +0 -0
  190. /package/{dist/path → path}/plainObject.js +0 -0
  191. /package/{dist/path → path}/plainObject.js.map +0 -0
  192. /package/{dist/plugins → plugins}/CmsEntryFieldFilterPathPlugin.d.ts +0 -0
  193. /package/{dist/plugins → plugins}/CmsEntryFieldFilterPlugin.d.ts +0 -0
  194. /package/{dist/plugins → plugins}/CmsEntryFieldFilterPlugin.js +0 -0
  195. /package/{dist/plugins → plugins}/CmsEntryFieldFilterPlugin.js.map +0 -0
  196. /package/{dist/plugins → plugins}/CmsEntryFieldSortingPlugin.d.ts +0 -0
  197. /package/{dist/plugins → plugins}/CmsEntryFieldSortingPlugin.js +0 -0
  198. /package/{dist/plugins → plugins}/CmsEntryFieldSortingPlugin.js.map +0 -0
  199. /package/{dist/plugins → plugins}/CmsFieldFilterValueTransformPlugin.d.ts +0 -0
  200. /package/{dist/plugins → plugins}/CmsFieldFilterValueTransformPlugin.js +0 -0
  201. /package/{dist/plugins → plugins}/CmsFieldFilterValueTransformPlugin.js.map +0 -0
  202. /package/{dist/plugins → plugins}/index.d.ts +0 -0
  203. /package/{dist/plugins → plugins}/index.js +0 -0
  204. /package/{dist/transforms → transforms}/datetime.d.ts +0 -0
@@ -1,165 +0,0 @@
1
- import type { CmsModelField } from "@webiny/api-headless-cms/types/index.js";
2
- import {
3
- ENTRY_META_FIELDS,
4
- isDateTimeEntryMetaField,
5
- isIdentityEntryMetaField
6
- } from "@webiny/api-headless-cms/constants.js";
7
- import lodashStartCase from "lodash/startCase.js";
8
- import { createModelField } from "@webiny/api-headless-cms";
9
-
10
- export const createSystemFields = (): CmsModelField[] => {
11
- const onMetaFields = ENTRY_META_FIELDS.filter(isDateTimeEntryMetaField).map<CmsModelField>(
12
- fieldName => {
13
- return createModelField({
14
- id: fieldName,
15
- type: "datetime",
16
- storageId: fieldName,
17
- fieldId: fieldName,
18
- label: lodashStartCase(fieldName)
19
- });
20
- }
21
- );
22
-
23
- const byMetaFields = ENTRY_META_FIELDS.filter(isIdentityEntryMetaField).map<CmsModelField>(
24
- fieldName => {
25
- return createModelField({
26
- id: fieldName,
27
- type: "plainObject",
28
- storageId: fieldName,
29
- fieldId: fieldName,
30
- label: lodashStartCase(fieldName),
31
- settings: {
32
- path: `${fieldName}.id`
33
- }
34
- });
35
- }
36
- );
37
-
38
- return [
39
- createModelField({
40
- id: "id",
41
- type: "text",
42
- storageId: "id",
43
- fieldId: "id",
44
- label: "ID"
45
- }),
46
- createModelField({
47
- id: "entryId",
48
- type: "text",
49
- storageId: "entryId",
50
- fieldId: "entryId",
51
- label: "Entry ID"
52
- }),
53
-
54
- ...onMetaFields,
55
- ...byMetaFields,
56
-
57
- createModelField({
58
- id: "meta",
59
- type: "plainObject",
60
- storageId: "meta",
61
- fieldId: "meta",
62
- label: "Meta"
63
- }),
64
- createModelField({
65
- id: "wbyAco_location",
66
- type: "object",
67
- storageId: "location",
68
- label: "Location",
69
- fieldId: "wbyAco_location",
70
- settings: {
71
- fields: [
72
- createModelField({
73
- id: "folderId",
74
- type: "text",
75
- fieldId: "folderId",
76
- label: "Folder ID",
77
- storageId: "folderId",
78
- settings: {
79
- path: "location.folderId"
80
- }
81
- })
82
- ]
83
- }
84
- }),
85
-
86
- createModelField({
87
- id: "version",
88
- type: "number",
89
- storageId: "version",
90
- fieldId: "version",
91
- label: "Version"
92
- }),
93
- createModelField({
94
- id: "status",
95
- type: "text",
96
- storageId: "status",
97
- fieldId: "status",
98
- label: "Status"
99
- }),
100
- createModelField({
101
- id: "wbyDeleted",
102
- type: "boolean",
103
- storageId: "wbyDeleted",
104
- fieldId: "wbyDeleted",
105
- label: "Deleted"
106
- }),
107
- createModelField({
108
- id: "state",
109
- type: "object",
110
- storageId: "object@state",
111
- fieldId: "state",
112
- label: "State",
113
- settings: {
114
- fields: [
115
- createModelField({
116
- id: "stepId",
117
- type: "text",
118
- fieldId: "stepId",
119
- label: "Step ID",
120
- storageId: "stepId"
121
- }),
122
- createModelField({
123
- id: "stepName",
124
- type: "text",
125
- fieldId: "stepName",
126
- label: "Step Name",
127
- storageId: "stepName"
128
- }),
129
- createModelField({
130
- id: "state",
131
- type: "text",
132
- fieldId: "state",
133
- label: "State",
134
- storageId: "state"
135
- })
136
- ]
137
- }
138
- }),
139
- createModelField({
140
- id: "values",
141
- type: "object",
142
- storageId: "values",
143
- fieldId: "values",
144
- label: "Values"
145
- }),
146
- createModelField({
147
- id: "live",
148
- type: "object",
149
- storageId: "live",
150
- fieldId: "live",
151
- label: "Live",
152
- settings: {
153
- fields: [
154
- createModelField({
155
- id: "version",
156
- type: "number",
157
- fieldId: "version",
158
- label: "Version",
159
- storageId: "version"
160
- })
161
- ]
162
- }
163
- })
164
- ];
165
- };
@@ -1,46 +0,0 @@
1
- import type { CmsModelField } from "@webiny/api-headless-cms/types/index.js";
2
- import type { CreatePathCallable } from "../../plugins/CmsEntryFieldFilterPathPlugin.js";
3
-
4
- interface FieldValueTransform {
5
- (value: any): any;
6
- }
7
-
8
- export interface FieldParent {
9
- fieldId: string;
10
- list?: boolean;
11
- }
12
-
13
- export interface Field
14
- extends
15
- Partial<Omit<CmsModelField, "id" | "type" | "storageId" | "fieldId">>,
16
- Pick<CmsModelField, "id" | "type" | "storageId" | "fieldId"> {
17
- /*
18
- * A list of fieldId of all parents of the current field.
19
- *
20
- * This is used to check if we need to iterate through an array of parent values.
21
- */
22
- parents: FieldParent[];
23
- /*
24
- * The method which creates a path for the filtering.
25
- *
26
- * Always exists. In most cases it will return some fixed value.
27
- * When having a CmsEntryFieldFilterPathPlugin then it is executed to create a path.
28
- */
29
- createPath: CreatePathCallable;
30
- /*
31
- * In most cases, return value of this method is what ever is the input.
32
- *
33
- * In some cases there might be a CmsFieldFilterValueTransformPlugin, which transforms value to a comparable one.
34
- * For example, time in format 15:45:58 is not comparable, so we transform it into the seconds and then compare.
35
- */
36
- transform: FieldValueTransform;
37
- /*
38
- * Is the field a system field?
39
- * System fields are built into the code and cannot be changed.
40
- */
41
- system: boolean;
42
- }
43
-
44
- export interface FilterItemFromStorage {
45
- <T = any>(field: CmsModelField, value: any): Promise<T>;
46
- }
@@ -1,166 +0,0 @@
1
- import type {
2
- CmsEntry,
3
- CmsEntryListWhere,
4
- CmsEntryValues
5
- } from "@webiny/api-headless-cms/types/index.js";
6
- import WebinyError from "@webiny/error";
7
- import type { Field } from "./fields/types.js";
8
- import { createFullTextSearch } from "./fullTextSearch.js";
9
- import type { Expression, ExpressionCondition, Filter } from "./expressions/createExpressions.js";
10
- import { createExpressions } from "./expressions/createExpressions.js";
11
- import { transformValue } from "./transform.js";
12
- import { getValue } from "./getValue.js";
13
- import { ValueFilterRegistry } from "@webiny/db-utils";
14
- import type { FieldFilterCreateRegistry } from "../features/fieldFilterCreate/abstractions.js";
15
- import type { FieldFilterValueTransformRegistry } from "../features/fieldFilterValueTransform/abstractions.js";
16
-
17
- interface ExecuteFilterParams {
18
- value: any;
19
- filter: Filter;
20
- }
21
-
22
- const executeFilter = (params: ExecuteFilterParams) => {
23
- const { value, filter } = params;
24
-
25
- const canUse = filter.filter.canUse({
26
- value,
27
- compareValue: filter.compareValue
28
- });
29
- if (!canUse) {
30
- return true;
31
- }
32
-
33
- const matched = filter.filter.matches({
34
- value,
35
- compareValue: filter.compareValue
36
- });
37
- if (filter.negate) {
38
- return matched === false;
39
- }
40
- return matched;
41
- };
42
-
43
- interface ExecuteExpressionsParams {
44
- getCachedValue: (filter: Filter) => Promise<any>;
45
- expressions: Expression[];
46
- filters: Filter[];
47
- condition: ExpressionCondition;
48
- }
49
-
50
- const executeExpressions = (params: ExecuteExpressionsParams): boolean => {
51
- const { expressions, getCachedValue, filters, condition } = params;
52
- if (expressions.length === 0 && filters.length === 0) {
53
- return true;
54
- }
55
- for (const filter of filters) {
56
- const value = getCachedValue(filter);
57
-
58
- const result = executeFilter({
59
- value,
60
- filter
61
- });
62
- if (!result) {
63
- return false;
64
- }
65
- }
66
- for (const expression of expressions) {
67
- const result = executeExpressions({
68
- ...expression,
69
- getCachedValue
70
- });
71
- if (result && condition === "OR") {
72
- return true;
73
- } else if (!result && condition == "AND") {
74
- return false;
75
- }
76
- }
77
- return condition === "OR" ? false : true;
78
- };
79
-
80
- interface IFilterParams<T extends CmsEntryValues = CmsEntryValues> {
81
- filterCreateRegistry: FieldFilterCreateRegistry.Interface;
82
- transformRegistry: FieldFilterValueTransformRegistry.Interface;
83
- valueFilterRegistry: ValueFilterRegistry.Interface;
84
- items: CmsEntry<T>[];
85
- where: Partial<CmsEntryListWhere>;
86
- fields: Record<string, Field>;
87
- fullTextSearch?: {
88
- term?: string;
89
- fields?: string[];
90
- };
91
- }
92
-
93
- export const filter = <T extends CmsEntryValues = CmsEntryValues>(
94
- params: IFilterParams<T>
95
- ): CmsEntry<T>[] => {
96
- const {
97
- items: records,
98
- where,
99
- filterCreateRegistry,
100
- transformRegistry,
101
- fields,
102
- fullTextSearch,
103
- valueFilterRegistry
104
- } = params;
105
-
106
- const keys = Object.keys(where);
107
- if (keys.length === 0 && !fullTextSearch) {
108
- return records;
109
- }
110
- const expression = createExpressions({
111
- filterCreateRegistry,
112
- transformRegistry,
113
- where,
114
- fields,
115
- valueFilterRegistry
116
- });
117
-
118
- if (
119
- expression.filters.length === 0 &&
120
- expression.expressions.length === 0 &&
121
- !fullTextSearch?.term
122
- ) {
123
- return records;
124
- }
125
- const fullTextSearchFilter = valueFilterRegistry.get("contains");
126
- if (!fullTextSearchFilter) {
127
- throw new WebinyError(
128
- `Missing "contains" plugin to run the full-text search.`,
129
- "MISSING_PLUGIN"
130
- );
131
- }
132
-
133
- const search = createFullTextSearch({
134
- term: fullTextSearch?.term,
135
- targetFields: fullTextSearch?.fields,
136
- fields,
137
- filter: fullTextSearchFilter
138
- });
139
-
140
- return records.filter(record => {
141
- const cachedValues: Record<string, any> = {};
142
-
143
- const getCachedValue = (filter: Filter) => {
144
- const { path } = filter;
145
- if (cachedValues[path] !== undefined) {
146
- return cachedValues[path];
147
- }
148
- const plainValue = getValue(record, path);
149
-
150
- const rawValue = transformValue({
151
- value: plainValue,
152
- transform: filter.transformValue
153
- });
154
-
155
- cachedValues[path] = rawValue;
156
- return rawValue;
157
- };
158
-
159
- const exprResult = executeExpressions({ ...expression, getCachedValue });
160
- if (!exprResult || !search) {
161
- return exprResult;
162
- }
163
-
164
- return search(record);
165
- });
166
- };
@@ -1,40 +0,0 @@
1
- import WebinyError from "@webiny/error";
2
- import type { CmsEntry } from "@webiny/api-headless-cms/types/index.js";
3
- import type { Field } from "./fields/types.js";
4
- import { getValue } from "./getValue.js";
5
- import { ValueFilter } from "@webiny/db-utils";
6
-
7
- interface Params {
8
- term?: string;
9
- targetFields?: string[];
10
- fields: Record<string, Field>;
11
- filter: ValueFilter.Interface;
12
- }
13
-
14
- /* Unfortunately we must use the contains plugin directly as plugins do not support multi field searching. */
15
- export const createFullTextSearch = (params: Params) => {
16
- const { term, targetFields, fields: fieldDefinitions, filter } = params;
17
- if (!term || term.trim().length === 0 || !targetFields || targetFields.length === 0) {
18
- return null;
19
- }
20
- return (item: CmsEntry) => {
21
- for (const target of targetFields) {
22
- /* As fields is a mapped Field objects where key is a path to the value, we can directly find the related field. */
23
- const field = fieldDefinitions[target];
24
-
25
- if (!field) {
26
- throw new WebinyError(`Unknown field "${target}" in the model.`, "UNKNOWN_FIELD", {
27
- target
28
- });
29
- }
30
- const value = getValue(item, target);
31
- if (!value) {
32
- continue;
33
- }
34
- if (filter.matches({ value, compareValue: term }) === true) {
35
- return true;
36
- }
37
- }
38
- return false;
39
- };
40
- };
@@ -1,64 +0,0 @@
1
- const addArrayResult = (target: any[], result: any[]): void => {
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: Record<string, any> | undefined, input: string[]): any[] | undefined => {
14
- const paths = [...input];
15
- const path = paths.shift();
16
-
17
- if (!path) {
18
- return undefined;
19
- }
20
-
21
- const value = target?.[path];
22
- if (value === undefined) {
23
- return undefined;
24
- }
25
- if (paths.length === 0) {
26
- return value;
27
- } else if (Array.isArray(value)) {
28
- if (value.length === 0) {
29
- return undefined;
30
- }
31
- return value.reduce<any[]>((collection, v) => {
32
- const result = find(v, paths);
33
- if (result === undefined) {
34
- return collection;
35
- } else if (Array.isArray(result)) {
36
- addArrayResult(collection, result);
37
- return collection;
38
- }
39
- collection.push(result);
40
- return collection;
41
- }, []);
42
- }
43
- return find(value, paths);
44
- };
45
- /*
46
- * A wrapper function for the find function.
47
- * Basically it transforms input paths to an array (and runs various checks).
48
- */
49
- export const getValue = (target: Record<string, any>, input: string | string[]): any => {
50
- const paths = Array.isArray(input) ? input : input.split(".");
51
- if (paths.length === 0) {
52
- throw new Error(`Path is empty!`);
53
- }
54
- const filtered = paths.filter(Boolean);
55
- if (paths.length !== filtered.length) {
56
- throw new Error(
57
- `Input path is different than the filtered empty path string. (${paths.join(
58
- "."
59
- )} to ${filtered.join(".")})`
60
- );
61
- }
62
-
63
- return find(target, paths);
64
- };
@@ -1,30 +0,0 @@
1
- import type { Plugin, PluginsContainer } from "@webiny/plugins/types.js";
2
- import WebinyError from "@webiny/error";
3
-
4
- interface Params {
5
- plugins: PluginsContainer;
6
- type: string;
7
- property: string;
8
- }
9
- export const getMappedPlugins = <T extends Plugin>(params: Params) => {
10
- const { plugins: pluginsContainer, type, property } = params;
11
- const plugins = pluginsContainer.byType<T>(type);
12
- if (plugins.length === 0) {
13
- return {};
14
- }
15
- return plugins.reduce<Record<string, T>>((collection, plugin) => {
16
- const key: keyof typeof plugin = plugin[property];
17
- if (typeof key !== "string") {
18
- throw new WebinyError(
19
- "Property to map the plugins on must be a string.",
20
- "PLUGIN_PROPERTY_ERROR",
21
- {
22
- type,
23
- property
24
- }
25
- );
26
- }
27
- collection[key] = plugin;
28
- return collection;
29
- }, {});
30
- };
@@ -1,36 +0,0 @@
1
- import WebinyError from "@webiny/error";
2
- import { CmsEntryFieldFilterPlugin } from "../../plugins/CmsEntryFieldFilterPlugin.js";
3
-
4
- export const createDefaultFilterCreate = () => {
5
- const plugin = new CmsEntryFieldFilterPlugin({
6
- fieldType: CmsEntryFieldFilterPlugin.ALL,
7
- create: params => {
8
- const { negate, transformValue, field, compareValue, valueFilterRegistry } = params;
9
- const filter = valueFilterRegistry.get(params.operation);
10
- if (!filter) {
11
- throw new WebinyError(
12
- `Missing ValueFilterPlugin for operation "${params.operation}".`,
13
- "MISSING_OPERATION_PLUGIN",
14
- {
15
- operation: params.operation
16
- }
17
- );
18
- }
19
- return {
20
- negate,
21
- transformValue,
22
- field,
23
- compareValue,
24
- fieldPathId: [...field.parents.map(f => f.fieldId), field.fieldId].join("."),
25
- path: field.createPath({
26
- field
27
- }),
28
- filter
29
- };
30
- }
31
- });
32
-
33
- plugin.name = `headless-cms.ddb.filter.default`;
34
-
35
- return plugin;
36
- };
@@ -1,13 +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
-
6
- export const createFilterCreatePlugins = () => {
7
- return [
8
- createDefaultFilterCreate(),
9
- createRefFilterCreate(),
10
- objectFilterCreate(),
11
- searchableJsonFilterCreate()
12
- ];
13
- };
@@ -1,100 +0,0 @@
1
- import { CmsEntryFieldFilterPlugin } from "../../plugins/CmsEntryFieldFilterPlugin.js";
2
- import { extractWhereParams } from "../where.js";
3
- import WebinyError from "@webiny/error";
4
- import type { ICmsFieldFilterValueTransformPlugin } from "../../plugins/CmsFieldFilterValueTransformPlugin.js";
5
- import { transformValue } from "../transform.js";
6
- import { getBaseFieldType } from "@webiny/api-headless-cms/utils/getBaseFieldType.js";
7
-
8
- export const objectFilterCreate = () => {
9
- const plugin = new CmsEntryFieldFilterPlugin({
10
- fieldType: "object",
11
- create: params => {
12
- const {
13
- value: objectValue,
14
- valueFilterRegistry,
15
- transformValuePlugins,
16
- getFilterCreatePlugin,
17
- field: parentField,
18
- fields
19
- } = params;
20
-
21
- const filters = [];
22
-
23
- for (const key in objectValue) {
24
- const value = objectValue[key];
25
- if (value === undefined) {
26
- continue;
27
- }
28
- const whereParams = extractWhereParams(key);
29
- if (!whereParams) {
30
- continue;
31
- }
32
- const { negate, fieldId, operation } = whereParams;
33
-
34
- const fieldPath = parentField.parents
35
- .map(p => p.fieldId)
36
- .concat([parentField.fieldId, fieldId])
37
- .join(".");
38
-
39
- const field = fields[fieldPath];
40
- if (!field) {
41
- throw new WebinyError(
42
- `There is no field with the field path "${fieldPath}".`,
43
- "FIELD_ERROR",
44
- {
45
- fieldId
46
- }
47
- );
48
- }
49
-
50
- const fieldType = getBaseFieldType(field);
51
-
52
- const filterCreatePlugin = getFilterCreatePlugin(fieldType);
53
-
54
- const transformValuePlugin: ICmsFieldFilterValueTransformPlugin =
55
- transformValuePlugins[fieldType];
56
-
57
- const transformValueCallable = (value: any) => {
58
- if (!transformValuePlugin) {
59
- return value;
60
- }
61
- return transformValuePlugin.transform({
62
- field,
63
- value
64
- });
65
- };
66
-
67
- const result = filterCreatePlugin.create({
68
- key,
69
- value,
70
- valueFilterRegistry,
71
- transformValuePlugins,
72
- getFilterCreatePlugin,
73
- operation,
74
- negate,
75
- field,
76
- fields,
77
- compareValue: transformValue({
78
- value,
79
- transform: transformValueCallable
80
- }),
81
- transformValue: transformValueCallable
82
- });
83
- if (!result) {
84
- continue;
85
- }
86
- if (Array.isArray(result)) {
87
- filters.push(...result);
88
- continue;
89
- }
90
-
91
- filters.push(result);
92
- }
93
- return filters;
94
- }
95
- });
96
-
97
- plugin.name = `headless-cms.ddb.filter.object`;
98
-
99
- return plugin;
100
- };