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

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 (185) hide show
  1. package/package.json +20 -15
  2. package/__tests__/filtering/getValue.test.ts +0 -58
  3. package/__tests__/filtering/mocks/entry.noModel.ts +0 -110
  4. package/__tests__/path/plainObject.test.ts +0 -32
  5. package/__tests__/transforms/datetime.test.ts +0 -71
  6. package/dist/package.json +0 -30
  7. package/src/cms/storageHelpers.ts +0 -92
  8. package/src/features/FilterRegistriesFeature.ts +0 -40
  9. package/src/features/fieldFilterCreate/FieldFilterCreateRegistry.ts +0 -25
  10. package/src/features/fieldFilterCreate/abstractions.ts +0 -51
  11. package/src/features/fieldFilterPath/FieldFilterPathRegistry.ts +0 -13
  12. package/src/features/fieldFilterPath/abstractions.ts +0 -22
  13. package/src/features/fieldFilterValueTransform/FieldFilterValueTransformRegistry.ts +0 -15
  14. package/src/features/fieldFilterValueTransform/abstractions.ts +0 -21
  15. package/src/features/fieldSorting/FieldSortingRegistry.ts +0 -20
  16. package/src/features/fieldSorting/abstractions.ts +0 -49
  17. package/src/filtering/expressions/createExpressions.ts +0 -170
  18. package/src/filtering/fields/createFields.ts +0 -124
  19. package/src/filtering/fields/extractSort.ts +0 -97
  20. package/src/filtering/fields/systemFields.ts +0 -165
  21. package/src/filtering/fields/types.ts +0 -46
  22. package/src/filtering/filter.ts +0 -166
  23. package/src/filtering/fullTextSearch.ts +0 -40
  24. package/src/filtering/getValue.ts +0 -64
  25. package/src/filtering/mapPlugins.ts +0 -30
  26. package/src/filtering/plugins/defaultFilterCreate.ts +0 -36
  27. package/src/filtering/plugins/index.ts +0 -13
  28. package/src/filtering/plugins/objectFilterCreate.ts +0 -100
  29. package/src/filtering/plugins/refFilterCreate.ts +0 -83
  30. package/src/filtering/plugins/searchableJsonFilterCreate.ts +0 -78
  31. package/src/filtering/sort.ts +0 -79
  32. package/src/filtering/transform.ts +0 -11
  33. package/src/filtering/values.ts +0 -24
  34. package/src/filtering/where.ts +0 -24
  35. package/src/handlers/datetimeTransformHandler.ts +0 -52
  36. package/src/handlers/defaultFilterCreateHandler.ts +0 -31
  37. package/src/handlers/locationFolderIdPathHandler.ts +0 -24
  38. package/src/handlers/objectFilterCreateHandler.ts +0 -86
  39. package/src/handlers/plainObjectPathHandler.ts +0 -17
  40. package/src/handlers/refFilterCreateHandler.ts +0 -65
  41. package/src/handlers/searchableJsonFilterCreateHandler.ts +0 -61
  42. package/src/index.ts +0 -63
  43. package/src/path/locationFolderId.ts +0 -29
  44. package/src/path/plainObject.ts +0 -21
  45. package/src/plugins/CmsEntryFieldFilterPathPlugin.ts +0 -58
  46. package/src/plugins/CmsEntryFieldFilterPlugin.ts +0 -59
  47. package/src/plugins/CmsEntryFieldSortingPlugin.ts +0 -63
  48. package/src/plugins/CmsFieldFilterValueTransformPlugin.ts +0 -43
  49. package/src/plugins/index.ts +0 -10
  50. package/src/transforms/datetime.ts +0 -62
  51. package/tsconfig.build.json +0 -33
  52. package/tsconfig.json +0 -33
  53. package/vitest.config.ts +0 -5
  54. package/webiny.config.js +0 -8
  55. /package/{dist/LICENSE → LICENSE} +0 -0
  56. /package/{dist/README.md → README.md} +0 -0
  57. /package/{dist/cms → cms}/storageHelpers.d.ts +0 -0
  58. /package/{dist/cms → cms}/storageHelpers.js +0 -0
  59. /package/{dist/cms → cms}/storageHelpers.js.map +0 -0
  60. /package/{dist/features → features}/FilterRegistriesFeature.d.ts +0 -0
  61. /package/{dist/features → features}/FilterRegistriesFeature.js +0 -0
  62. /package/{dist/features → features}/FilterRegistriesFeature.js.map +0 -0
  63. /package/{dist/features → features}/fieldFilterCreate/FieldFilterCreateRegistry.d.ts +0 -0
  64. /package/{dist/features → features}/fieldFilterCreate/FieldFilterCreateRegistry.js +0 -0
  65. /package/{dist/features → features}/fieldFilterCreate/FieldFilterCreateRegistry.js.map +0 -0
  66. /package/{dist/features → features}/fieldFilterCreate/abstractions.d.ts +0 -0
  67. /package/{dist/features → features}/fieldFilterCreate/abstractions.js +0 -0
  68. /package/{dist/features → features}/fieldFilterCreate/abstractions.js.map +0 -0
  69. /package/{dist/features → features}/fieldFilterPath/FieldFilterPathRegistry.d.ts +0 -0
  70. /package/{dist/features → features}/fieldFilterPath/FieldFilterPathRegistry.js +0 -0
  71. /package/{dist/features → features}/fieldFilterPath/FieldFilterPathRegistry.js.map +0 -0
  72. /package/{dist/features → features}/fieldFilterPath/abstractions.d.ts +0 -0
  73. /package/{dist/features → features}/fieldFilterPath/abstractions.js +0 -0
  74. /package/{dist/features → features}/fieldFilterPath/abstractions.js.map +0 -0
  75. /package/{dist/features → features}/fieldFilterValueTransform/FieldFilterValueTransformRegistry.d.ts +0 -0
  76. /package/{dist/features → features}/fieldFilterValueTransform/FieldFilterValueTransformRegistry.js +0 -0
  77. /package/{dist/features → features}/fieldFilterValueTransform/FieldFilterValueTransformRegistry.js.map +0 -0
  78. /package/{dist/features → features}/fieldFilterValueTransform/abstractions.d.ts +0 -0
  79. /package/{dist/features → features}/fieldFilterValueTransform/abstractions.js +0 -0
  80. /package/{dist/features → features}/fieldFilterValueTransform/abstractions.js.map +0 -0
  81. /package/{dist/features → features}/fieldSorting/FieldSortingRegistry.d.ts +0 -0
  82. /package/{dist/features → features}/fieldSorting/FieldSortingRegistry.js +0 -0
  83. /package/{dist/features → features}/fieldSorting/FieldSortingRegistry.js.map +0 -0
  84. /package/{dist/features → features}/fieldSorting/abstractions.d.ts +0 -0
  85. /package/{dist/features → features}/fieldSorting/abstractions.js +0 -0
  86. /package/{dist/features → features}/fieldSorting/abstractions.js.map +0 -0
  87. /package/{dist/filtering → filtering}/expressions/createExpressions.d.ts +0 -0
  88. /package/{dist/filtering → filtering}/expressions/createExpressions.js +0 -0
  89. /package/{dist/filtering → filtering}/expressions/createExpressions.js.map +0 -0
  90. /package/{dist/filtering → filtering}/fields/createFields.d.ts +0 -0
  91. /package/{dist/filtering → filtering}/fields/createFields.js +0 -0
  92. /package/{dist/filtering → filtering}/fields/createFields.js.map +0 -0
  93. /package/{dist/filtering → filtering}/fields/extractSort.d.ts +0 -0
  94. /package/{dist/filtering → filtering}/fields/extractSort.js +0 -0
  95. /package/{dist/filtering → filtering}/fields/extractSort.js.map +0 -0
  96. /package/{dist/filtering → filtering}/fields/systemFields.d.ts +0 -0
  97. /package/{dist/filtering → filtering}/fields/systemFields.js +0 -0
  98. /package/{dist/filtering → filtering}/fields/systemFields.js.map +0 -0
  99. /package/{dist/filtering → filtering}/fields/types.d.ts +0 -0
  100. /package/{dist/filtering → filtering}/fields/types.js +0 -0
  101. /package/{dist/filtering → filtering}/filter.d.ts +0 -0
  102. /package/{dist/filtering → filtering}/filter.js +0 -0
  103. /package/{dist/filtering → filtering}/filter.js.map +0 -0
  104. /package/{dist/filtering → filtering}/fullTextSearch.d.ts +0 -0
  105. /package/{dist/filtering → filtering}/fullTextSearch.js +0 -0
  106. /package/{dist/filtering → filtering}/fullTextSearch.js.map +0 -0
  107. /package/{dist/filtering → filtering}/getValue.d.ts +0 -0
  108. /package/{dist/filtering → filtering}/getValue.js +0 -0
  109. /package/{dist/filtering → filtering}/getValue.js.map +0 -0
  110. /package/{dist/filtering → filtering}/mapPlugins.d.ts +0 -0
  111. /package/{dist/filtering → filtering}/mapPlugins.js +0 -0
  112. /package/{dist/filtering → filtering}/mapPlugins.js.map +0 -0
  113. /package/{dist/filtering → filtering}/plugins/defaultFilterCreate.d.ts +0 -0
  114. /package/{dist/filtering → filtering}/plugins/defaultFilterCreate.js +0 -0
  115. /package/{dist/filtering → filtering}/plugins/defaultFilterCreate.js.map +0 -0
  116. /package/{dist/filtering → filtering}/plugins/index.d.ts +0 -0
  117. /package/{dist/filtering → filtering}/plugins/index.js +0 -0
  118. /package/{dist/filtering → filtering}/plugins/index.js.map +0 -0
  119. /package/{dist/filtering → filtering}/plugins/objectFilterCreate.d.ts +0 -0
  120. /package/{dist/filtering → filtering}/plugins/objectFilterCreate.js +0 -0
  121. /package/{dist/filtering → filtering}/plugins/objectFilterCreate.js.map +0 -0
  122. /package/{dist/filtering → filtering}/plugins/refFilterCreate.d.ts +0 -0
  123. /package/{dist/filtering → filtering}/plugins/refFilterCreate.js +0 -0
  124. /package/{dist/filtering → filtering}/plugins/refFilterCreate.js.map +0 -0
  125. /package/{dist/filtering → filtering}/plugins/searchableJsonFilterCreate.d.ts +0 -0
  126. /package/{dist/filtering → filtering}/plugins/searchableJsonFilterCreate.js +0 -0
  127. /package/{dist/filtering → filtering}/plugins/searchableJsonFilterCreate.js.map +0 -0
  128. /package/{dist/filtering → filtering}/sort.d.ts +0 -0
  129. /package/{dist/filtering → filtering}/sort.js +0 -0
  130. /package/{dist/filtering → filtering}/sort.js.map +0 -0
  131. /package/{dist/filtering → filtering}/transform.d.ts +0 -0
  132. /package/{dist/filtering → filtering}/transform.js +0 -0
  133. /package/{dist/filtering → filtering}/transform.js.map +0 -0
  134. /package/{dist/filtering → filtering}/values.d.ts +0 -0
  135. /package/{dist/filtering → filtering}/values.js +0 -0
  136. /package/{dist/filtering → filtering}/values.js.map +0 -0
  137. /package/{dist/filtering → filtering}/where.d.ts +0 -0
  138. /package/{dist/filtering → filtering}/where.js +0 -0
  139. /package/{dist/filtering → filtering}/where.js.map +0 -0
  140. /package/{dist/handlers → handlers}/datetimeTransformHandler.d.ts +0 -0
  141. /package/{dist/handlers → handlers}/datetimeTransformHandler.js +0 -0
  142. /package/{dist/handlers → handlers}/datetimeTransformHandler.js.map +0 -0
  143. /package/{dist/handlers → handlers}/defaultFilterCreateHandler.d.ts +0 -0
  144. /package/{dist/handlers → handlers}/defaultFilterCreateHandler.js +0 -0
  145. /package/{dist/handlers → handlers}/defaultFilterCreateHandler.js.map +0 -0
  146. /package/{dist/handlers → handlers}/locationFolderIdPathHandler.d.ts +0 -0
  147. /package/{dist/handlers → handlers}/locationFolderIdPathHandler.js +0 -0
  148. /package/{dist/handlers → handlers}/locationFolderIdPathHandler.js.map +0 -0
  149. /package/{dist/handlers → handlers}/objectFilterCreateHandler.d.ts +0 -0
  150. /package/{dist/handlers → handlers}/objectFilterCreateHandler.js +0 -0
  151. /package/{dist/handlers → handlers}/objectFilterCreateHandler.js.map +0 -0
  152. /package/{dist/handlers → handlers}/plainObjectPathHandler.d.ts +0 -0
  153. /package/{dist/handlers → handlers}/plainObjectPathHandler.js +0 -0
  154. /package/{dist/handlers → handlers}/plainObjectPathHandler.js.map +0 -0
  155. /package/{dist/handlers → handlers}/refFilterCreateHandler.d.ts +0 -0
  156. /package/{dist/handlers → handlers}/refFilterCreateHandler.js +0 -0
  157. /package/{dist/handlers → handlers}/refFilterCreateHandler.js.map +0 -0
  158. /package/{dist/handlers → handlers}/searchableJsonFilterCreateHandler.d.ts +0 -0
  159. /package/{dist/handlers → handlers}/searchableJsonFilterCreateHandler.js +0 -0
  160. /package/{dist/handlers → handlers}/searchableJsonFilterCreateHandler.js.map +0 -0
  161. /package/{dist/index.d.ts → index.d.ts} +0 -0
  162. /package/{dist/index.js → index.js} +0 -0
  163. /package/{dist/path → path}/locationFolderId.d.ts +0 -0
  164. /package/{dist/path → path}/locationFolderId.js +0 -0
  165. /package/{dist/path → path}/locationFolderId.js.map +0 -0
  166. /package/{dist/path → path}/plainObject.d.ts +0 -0
  167. /package/{dist/path → path}/plainObject.js +0 -0
  168. /package/{dist/path → path}/plainObject.js.map +0 -0
  169. /package/{dist/plugins → plugins}/CmsEntryFieldFilterPathPlugin.d.ts +0 -0
  170. /package/{dist/plugins → plugins}/CmsEntryFieldFilterPathPlugin.js +0 -0
  171. /package/{dist/plugins → plugins}/CmsEntryFieldFilterPathPlugin.js.map +0 -0
  172. /package/{dist/plugins → plugins}/CmsEntryFieldFilterPlugin.d.ts +0 -0
  173. /package/{dist/plugins → plugins}/CmsEntryFieldFilterPlugin.js +0 -0
  174. /package/{dist/plugins → plugins}/CmsEntryFieldFilterPlugin.js.map +0 -0
  175. /package/{dist/plugins → plugins}/CmsEntryFieldSortingPlugin.d.ts +0 -0
  176. /package/{dist/plugins → plugins}/CmsEntryFieldSortingPlugin.js +0 -0
  177. /package/{dist/plugins → plugins}/CmsEntryFieldSortingPlugin.js.map +0 -0
  178. /package/{dist/plugins → plugins}/CmsFieldFilterValueTransformPlugin.d.ts +0 -0
  179. /package/{dist/plugins → plugins}/CmsFieldFilterValueTransformPlugin.js +0 -0
  180. /package/{dist/plugins → plugins}/CmsFieldFilterValueTransformPlugin.js.map +0 -0
  181. /package/{dist/plugins → plugins}/index.d.ts +0 -0
  182. /package/{dist/plugins → plugins}/index.js +0 -0
  183. /package/{dist/transforms → transforms}/datetime.d.ts +0 -0
  184. /package/{dist/transforms → transforms}/datetime.js +0 -0
  185. /package/{dist/transforms → transforms}/datetime.js.map +0 -0
@@ -1,11 +0,0 @@
1
- import type { Field } from "./fields/types.js";
2
-
3
- interface Params extends Pick<Field, "transform"> {
4
- value: any;
5
- }
6
- export const transformValue = ({ value, transform }: Params): any => {
7
- if (Array.isArray(value)) {
8
- return value.map(v => transform(v));
9
- }
10
- return transform(value);
11
- };
@@ -1,24 +0,0 @@
1
- import type { CmsEntryListWhere } from "@webiny/api-headless-cms/types/index.js";
2
- import WebinyError from "@webiny/error";
3
-
4
- export const getWhereValues = (value: unknown, condition: "AND" | "OR") => {
5
- const values = value as CmsEntryListWhere[] | undefined;
6
- if (!Array.isArray(values)) {
7
- throw new WebinyError(
8
- `Trying to run filtering with "${condition}", but the value sent is not an array.`,
9
- `MALFORMED_${condition}_CONDITION`,
10
- {
11
- value
12
- }
13
- );
14
- } else if (values.length === 0) {
15
- throw new WebinyError(
16
- `Trying to run filtering with "${condition}", but the value sent is empty array.`,
17
- `MALFORMED_${condition}_CONDITION`,
18
- {
19
- value
20
- }
21
- );
22
- }
23
- return values;
24
- };
@@ -1,24 +0,0 @@
1
- export const extractWhereParams = (key: string) => {
2
- const isWbyAco = key.match("wbyAco_") !== null;
3
- const result = key.replace("wbyAco_", "").split("_");
4
- const fieldId = result.shift();
5
- if (!fieldId) {
6
- return null;
7
- }
8
- const rawOp = result.length === 0 ? "eq" : result.join("_");
9
- /* When rawOp is not, it means it is equal negated so just return that. */
10
- if (rawOp === "not") {
11
- return {
12
- fieldId,
13
- operation: "eq",
14
- negate: true
15
- };
16
- }
17
- const negate = rawOp.match("not_") !== null;
18
- const operation = rawOp.replace("not_", "");
19
- return {
20
- fieldId: isWbyAco ? `wbyAco_${fieldId}` : fieldId,
21
- operation,
22
- negate
23
- };
24
- };
@@ -1,52 +0,0 @@
1
- import { parseISO } from "date-fns";
2
- import type { FieldFilterValueTransformRegistry } from "../features/fieldFilterValueTransform/abstractions.js";
3
-
4
- const transformTime = (value: any): number => {
5
- if (value === undefined || value === null) {
6
- throw new Error(`Time value is null or undefined.`);
7
- } else if (typeof value === "boolean" || value === "" || Array.isArray(value)) {
8
- throw new Error("Field value must be a string because field is defined as time.");
9
- }
10
- const converted = Number(`${value}`);
11
- if (typeof value === "number" || isNaN(converted) === false) {
12
- return Number(value);
13
- } else if (typeof value !== "string") {
14
- throw new Error("Field value must be a string because field is defined as time.");
15
- }
16
- const [time, milliseconds = 0] = value.split(".");
17
- const values = time.split(":").map(Number);
18
- if (values.length < 2) {
19
- throw new Error("Time must contain at least hours and minutes.");
20
- }
21
- const [hours, minutes, seconds = 0] = values;
22
- return (hours * 60 * 60 + minutes * 60 + seconds) * 1000 + Number(milliseconds);
23
- };
24
-
25
- const transformDateTime = (value: any): number | null => {
26
- if (value === null || value === undefined) {
27
- return null;
28
- } else if (typeof value === "string") {
29
- const parsedDateTime = parseISO(value).getTime();
30
- if (isNaN(parsedDateTime) === false) {
31
- return parsedDateTime;
32
- }
33
- } else if (value instanceof Date || typeof (value as unknown as Date)?.getTime === "function") {
34
- return value.getTime();
35
- }
36
- console.warn("Could not parse given dateTime value.", "PARSE_DATE_ERROR", {
37
- value
38
- });
39
- return null;
40
- };
41
-
42
- export const createDatetimeTransformHandler = (): FieldFilterValueTransformRegistry.Handler => {
43
- return {
44
- transform: ({ field, value }) => {
45
- const { type } = field.settings || {};
46
- if (type === "time") {
47
- return transformTime(value);
48
- }
49
- return transformDateTime(value);
50
- }
51
- };
52
- };
@@ -1,31 +0,0 @@
1
- import WebinyError from "@webiny/error";
2
- import type { FieldFilterCreateRegistry } from "../features/fieldFilterCreate/abstractions.js";
3
-
4
- export const createDefaultFilterCreateHandler = (): FieldFilterCreateRegistry.Handler => {
5
- return {
6
- create: params => {
7
- const { negate, transformValue, field, compareValue, valueFilterRegistry } = params;
8
- const filter = valueFilterRegistry.get(params.operation);
9
- if (!filter) {
10
- throw new WebinyError(
11
- `Missing ValueFilterPlugin for operation "${params.operation}".`,
12
- "MISSING_OPERATION_PLUGIN",
13
- {
14
- operation: params.operation
15
- }
16
- );
17
- }
18
- return {
19
- negate,
20
- transformValue,
21
- field,
22
- compareValue,
23
- fieldPathId: [...field.parents.map(f => f.fieldId), field.fieldId].join("."),
24
- path: field.createPath({
25
- field
26
- }),
27
- filter
28
- };
29
- }
30
- };
31
- };
@@ -1,24 +0,0 @@
1
- import WebinyError from "@webiny/error";
2
- import type { FieldFilterPathRegistry } from "../features/fieldFilterPath/abstractions.js";
3
-
4
- export const createLocationFolderIdPathHandler = (): FieldFilterPathRegistry.Handler => {
5
- return {
6
- canUse: (field, parents) => {
7
- if (field.fieldId !== "folderId") {
8
- return false;
9
- } else if (!parents?.length) {
10
- return false;
11
- }
12
- return parents[0] === "wbyAco_location";
13
- },
14
- createPath: ({ field }) => {
15
- const { path } = field.settings || {};
16
- if (!path) {
17
- throw new WebinyError("Missing path settings value.", "FIELD_SETTINGS_ERROR", {
18
- field
19
- });
20
- }
21
- return path;
22
- }
23
- };
24
- };
@@ -1,86 +0,0 @@
1
- import WebinyError from "@webiny/error";
2
- import type { FieldFilterCreateRegistry } from "../features/fieldFilterCreate/abstractions.js";
3
- import { extractWhereParams } from "../filtering/where.js";
4
- import { transformValue } from "../filtering/transform.js";
5
- import { getBaseFieldType } from "@webiny/api-headless-cms/utils/getBaseFieldType.js";
6
-
7
- export const createObjectFilterCreateHandler = (): FieldFilterCreateRegistry.Handler => {
8
- return {
9
- create: params => {
10
- const {
11
- value: objectValue,
12
- valueFilterRegistry,
13
- transformRegistry,
14
- getHandler,
15
- field: parentField,
16
- fields
17
- } = params;
18
-
19
- const filters: FieldFilterCreateRegistry.Result[] = [];
20
-
21
- for (const key in objectValue) {
22
- const value = objectValue[key];
23
- if (value === undefined) {
24
- continue;
25
- }
26
- const whereParams = extractWhereParams(key);
27
- if (!whereParams) {
28
- continue;
29
- }
30
- const { negate, fieldId, operation } = whereParams;
31
-
32
- const fieldPath = parentField.parents
33
- .map(p => p.fieldId)
34
- .concat([parentField.fieldId, fieldId])
35
- .join(".");
36
-
37
- const field = fields[fieldPath];
38
- if (!field) {
39
- throw new WebinyError(
40
- `There is no field with the field path "${fieldPath}".`,
41
- "FIELD_ERROR",
42
- { fieldId }
43
- );
44
- }
45
-
46
- const fieldType = getBaseFieldType(field);
47
- const handler = getHandler(fieldType);
48
- const transformHandler = transformRegistry.get(fieldType);
49
-
50
- const transformValueCallable = (value: any) => {
51
- if (!transformHandler) {
52
- return value;
53
- }
54
- return transformHandler.transform({ field, value });
55
- };
56
-
57
- const result = handler.create({
58
- key,
59
- value,
60
- valueFilterRegistry,
61
- transformRegistry,
62
- getHandler,
63
- operation,
64
- negate,
65
- field,
66
- fields,
67
- compareValue: transformValue({
68
- value,
69
- transform: transformValueCallable
70
- }),
71
- transformValue: transformValueCallable
72
- });
73
- if (!result) {
74
- continue;
75
- }
76
- if (Array.isArray(result)) {
77
- filters.push(...result);
78
- continue;
79
- }
80
-
81
- filters.push(result);
82
- }
83
- return filters;
84
- }
85
- };
86
- };
@@ -1,17 +0,0 @@
1
- import WebinyError from "@webiny/error";
2
- import type { FieldFilterPathRegistry } from "../features/fieldFilterPath/abstractions.js";
3
-
4
- export const createPlainObjectPathHandler = (): FieldFilterPathRegistry.Handler => {
5
- return {
6
- canUse: () => true,
7
- createPath: ({ field }) => {
8
- const { path } = field.settings || {};
9
- if (!path) {
10
- throw new WebinyError("Missing path settings value.", "FIELD_SETTINGS_ERROR", {
11
- field
12
- });
13
- }
14
- return path;
15
- }
16
- };
17
- };
@@ -1,65 +0,0 @@
1
- import WebinyError from "@webiny/error";
2
- import type { FieldFilterCreateRegistry } from "../features/fieldFilterCreate/abstractions.js";
3
- import { extractWhereParams } from "../filtering/where.js";
4
- import { transformValue } from "../filtering/transform.js";
5
- import { getBaseFieldType } from "@webiny/api-headless-cms/utils/getBaseFieldType.js";
6
-
7
- export const createRefFilterCreateHandler = (): FieldFilterCreateRegistry.Handler => {
8
- return {
9
- create: params => {
10
- const { valueFilterRegistry, transformRegistry, field } = params;
11
- let value = params.value;
12
- if (!value) {
13
- value = { entryId: null };
14
- }
15
- const propertyFilters = Object.keys(value);
16
- if (propertyFilters.length === 0) {
17
- return null;
18
- }
19
- const filters: FieldFilterCreateRegistry.Result[] = [];
20
-
21
- for (const propertyFilter of propertyFilters) {
22
- const whereParams = extractWhereParams(propertyFilter);
23
- if (!whereParams) {
24
- continue;
25
- }
26
- const { fieldId: propertyId, operation: propertyOperation, negate } = whereParams;
27
-
28
- const fieldType = getBaseFieldType(field);
29
- const transformHandler = transformRegistry.get(fieldType);
30
-
31
- const transformValueCallable = (value: any) => {
32
- if (!transformHandler) {
33
- return value;
34
- }
35
- return transformHandler.transform({ field, value });
36
- };
37
-
38
- const filter = valueFilterRegistry.get(propertyOperation);
39
- if (!filter) {
40
- throw new WebinyError(
41
- `Missing operation filter for "${propertyOperation}".`,
42
- "MISSING_OPERATION_FILTER"
43
- );
44
- }
45
-
46
- const paths = [field.createPath({ field }), propertyId];
47
-
48
- filters.push({
49
- field,
50
- path: paths.join("."),
51
- fieldPathId: [...field.parents.map(f => f.fieldId), field.fieldId].join("."),
52
- filter,
53
- negate,
54
- compareValue: transformValue({
55
- value: value[propertyFilter],
56
- transform: transformValueCallable
57
- }),
58
- transformValue: transformValueCallable
59
- });
60
- }
61
-
62
- return filters;
63
- }
64
- };
65
- };
@@ -1,61 +0,0 @@
1
- import type { FieldFilterCreateRegistry } from "../features/fieldFilterCreate/abstractions.js";
2
- import { extractWhereParams } from "../filtering/where.js";
3
-
4
- function dotFlatten(obj: Record<string, any>, prefix = ""): Record<string, any> {
5
- return Object.entries(obj).reduce<Record<string, any>>((acc, [key, val]) => {
6
- const path = prefix ? `${prefix}.${key}` : key;
7
- if (val && typeof val === "object" && !Array.isArray(val)) {
8
- Object.assign(acc, dotFlatten(val, path));
9
- } else {
10
- acc[path] = val;
11
- }
12
- return acc;
13
- }, {});
14
- }
15
-
16
- export const createSearchableJsonFilterCreateHandler = (): FieldFilterCreateRegistry.Handler => {
17
- return {
18
- create: params => {
19
- const { value: objectValue, valueFilterRegistry, field: parentField } = params;
20
-
21
- const filters: FieldFilterCreateRegistry.Result[] = [];
22
- const accessPatterns = dotFlatten(objectValue);
23
-
24
- for (const key in accessPatterns) {
25
- const value = accessPatterns[key];
26
- if (value === undefined) {
27
- continue;
28
- }
29
-
30
- const whereParams = extractWhereParams(key);
31
- if (!whereParams) {
32
- continue;
33
- }
34
- const { negate, operation } = whereParams;
35
-
36
- const transformValueCallable = (value: any) => {
37
- return value;
38
- };
39
-
40
- const fieldId = `${parentField.fieldId}.${whereParams.fieldId ?? key}`;
41
-
42
- const filter = valueFilterRegistry.get(operation);
43
- if (!filter) {
44
- console.error(`Missing operation filter for "${operation}".`);
45
- continue;
46
- }
47
-
48
- filters.push({
49
- field: parentField,
50
- path: `values.${fieldId}`,
51
- fieldPathId: `values.${fieldId}`,
52
- negate,
53
- filter,
54
- compareValue: value,
55
- transformValue: transformValueCallable
56
- });
57
- }
58
- return filters;
59
- }
60
- };
61
- };
package/src/index.ts DELETED
@@ -1,63 +0,0 @@
1
- /* Filtering. */
2
- export { filter } from "./filtering/filter.js";
3
- export { sort } from "./filtering/sort.js";
4
- export { createFields } from "./filtering/fields/createFields.js";
5
- export { createFilterCreatePlugins } from "./filtering/plugins/index.js";
6
- export { createExpressions } from "./filtering/expressions/createExpressions.js";
7
- export type { Expression, ExpressionCondition } from "./filtering/expressions/createExpressions.js";
8
- export { getValue } from "./filtering/getValue.js";
9
-
10
- /* Plugin base classes. */
11
- export { CmsEntryFieldFilterPlugin } from "./plugins/CmsEntryFieldFilterPlugin.js";
12
- export type { CmsEntryFieldFilterPluginCreateResponse } from "./plugins/CmsEntryFieldFilterPlugin.js";
13
- export {
14
- CmsEntryFieldSortingPlugin,
15
- createCmsEntryFieldSortingPlugin
16
- } from "./plugins/CmsEntryFieldSortingPlugin.js";
17
- export { CmsEntryFieldFilterPathPlugin } from "./plugins/CmsEntryFieldFilterPathPlugin.js";
18
- export type { CreatePathCallable } from "./plugins/CmsEntryFieldFilterPathPlugin.js";
19
- export { CmsFieldFilterValueTransformPlugin } from "./plugins/CmsFieldFilterValueTransformPlugin.js";
20
-
21
- /* Path + transform plugins. */
22
- export { createPlainObjectPathPlugin } from "./path/plainObject.js";
23
- export { createLocationFolderIdPathPlugin } from "./path/locationFolderId.js";
24
- export { createDatetimeTransformValuePlugin } from "./transforms/datetime.js";
25
-
26
- /* CMS storage helpers. */
27
- export {
28
- createStorageModelAccessor,
29
- createStorageTransformCallable,
30
- aggregateUniqueFieldValues
31
- } from "./cms/storageHelpers.js";
32
-
33
- /* Types. */
34
- export type { Field } from "./filtering/fields/types.js";
35
- export type { FilterItemFromStorage } from "./filtering/fields/types.js";
36
-
37
- /* DI registries. */
38
- export {
39
- FieldFilterPathRegistry,
40
- type IFieldFilterPathHandler,
41
- type IFieldFilterPathRegistry
42
- } from "./features/fieldFilterPath/abstractions.js";
43
- export {
44
- FieldFilterValueTransformRegistry,
45
- type IFieldFilterValueTransformHandler,
46
- type IFieldFilterValueTransformRegistry
47
- } from "./features/fieldFilterValueTransform/abstractions.js";
48
- export {
49
- FieldFilterCreateRegistry,
50
- type IFieldFilterCreateHandler,
51
- type IFieldFilterCreateParams,
52
- type IFieldFilterCreateRegistry,
53
- type IFieldFilterCreateResult
54
- } from "./features/fieldFilterCreate/abstractions.js";
55
- export {
56
- FieldSortingRegistry,
57
- type IFieldSortingCanUseParams,
58
- type IFieldSortingCreateParams,
59
- type IFieldSortingHandler,
60
- type IFieldSortingRegistry,
61
- type IFieldSortingResult
62
- } from "./features/fieldSorting/abstractions.js";
63
- export { FilterRegistriesFeature } from "./features/FilterRegistriesFeature.js";
@@ -1,29 +0,0 @@
1
- /* File is @internal. */
2
- import WebinyError from "@webiny/error";
3
- import type { CreatePathCallable } from "../plugins/CmsEntryFieldFilterPathPlugin.js";
4
- import { CmsEntryFieldFilterPathPlugin } from "../plugins/CmsEntryFieldFilterPathPlugin.js";
5
-
6
- const createPath: CreatePathCallable = ({ field }) => {
7
- const { path } = field.settings || {};
8
- if (!path) {
9
- throw new WebinyError("Missing path settings value.", "FIELD_SETTINGS_ERROR", {
10
- field
11
- });
12
- }
13
- return path;
14
- };
15
-
16
- export const createLocationFolderIdPathPlugin = (): CmsEntryFieldFilterPathPlugin => {
17
- return new CmsEntryFieldFilterPathPlugin({
18
- fieldType: "text",
19
- path: createPath,
20
- canUse: (field, parents) => {
21
- if (field.fieldId !== "folderId") {
22
- return false;
23
- } else if (!parents?.length) {
24
- return false;
25
- }
26
- return parents[0] === "wbyAco_location";
27
- }
28
- });
29
- };
@@ -1,21 +0,0 @@
1
- /* File is @internal. */
2
- import WebinyError from "@webiny/error";
3
- import type { CreatePathCallable } from "../plugins/CmsEntryFieldFilterPathPlugin.js";
4
- import { CmsEntryFieldFilterPathPlugin } from "../plugins/CmsEntryFieldFilterPathPlugin.js";
5
-
6
- const createPath: CreatePathCallable = ({ field }) => {
7
- const { path } = field.settings || {};
8
- if (!path) {
9
- throw new WebinyError("Missing path settings value.", "FIELD_SETTINGS_ERROR", {
10
- field
11
- });
12
- }
13
- return path;
14
- };
15
-
16
- export const createPlainObjectPathPlugin = (): CmsEntryFieldFilterPathPlugin => {
17
- return new CmsEntryFieldFilterPathPlugin({
18
- fieldType: "plainObject",
19
- path: createPath
20
- });
21
- };
@@ -1,58 +0,0 @@
1
- import WebinyError from "@webiny/error";
2
- import { Plugin } from "@webiny/plugins/Plugin.js";
3
- import type { CmsModelField } from "@webiny/api-headless-cms/types/index.js";
4
-
5
- export interface CreatePathCallableParams {
6
- field: Partial<CmsModelField> & Pick<CmsModelField, "fieldId" | "storageId" | "id">;
7
- index?: number;
8
- }
9
- export interface CreatePathCallable {
10
- (params: CreatePathCallableParams): string;
11
- }
12
- export interface CmsEntryFieldFilterPathPluginParams {
13
- fieldType: string;
14
- fieldId?: string[];
15
- path: string | CreatePathCallable;
16
- canUse?: (field: Pick<CmsModelField, "fieldId" | "type">, parents?: string[]) => boolean;
17
- }
18
- export class CmsEntryFieldFilterPathPlugin extends Plugin {
19
- public static override readonly type: string = "cms-field-filter-path";
20
-
21
- private readonly config: CmsEntryFieldFilterPathPluginParams;
22
-
23
- public get fieldType(): string {
24
- return this.config.fieldType;
25
- }
26
-
27
- public constructor(config: CmsEntryFieldFilterPathPluginParams) {
28
- super();
29
-
30
- this.config = config;
31
-
32
- /* We expect error here because we know that `this.constructor.type` is defined, but TS does not. */
33
- // @ts-expect-error
34
- this.name = `${this.constructor.type}-${this.config.fieldType}`;
35
- }
36
-
37
- public canUse(field: Pick<CmsModelField, "fieldId" | "type">, parents: string[]): boolean {
38
- if (field.type !== this.config.fieldType) {
39
- return false;
40
- } else if (this.config.canUse) {
41
- return this.config.canUse(field, parents);
42
- }
43
- const fieldId = this.config.fieldId;
44
- if (!fieldId || Array.isArray(fieldId) === false || fieldId.length === 0) {
45
- return true;
46
- }
47
- return fieldId.includes(field.fieldId);
48
- }
49
-
50
- public createPath(params: CreatePathCallableParams): string {
51
- if (typeof this.config.path === "function") {
52
- return this.config.path(params);
53
- } else if (typeof this.config.path === "string") {
54
- return this.config.path;
55
- }
56
- throw new WebinyError(`Missing path in "${this.name}" plugin.`);
57
- }
58
- }
@@ -1,59 +0,0 @@
1
- import { Plugin } from "@webiny/plugins";
2
- import type { Field } from "~/filtering/fields/types.js";
3
- import type { ICmsFieldFilterValueTransformPlugin } from "./CmsFieldFilterValueTransformPlugin.js";
4
- import { ValueFilterRegistry } from "@webiny/db-utils";
5
-
6
- /*
7
- * This plugin is used to create the filter.
8
- * Internally we have default one + the one for the reference field - because it is actually an object when filtering.
9
- */
10
-
11
- interface CmsEntryFieldFilterPluginParams<T = any> {
12
- fieldType: string;
13
- create: (
14
- params: CmsEntryFieldFilterPluginCreateParams<T>
15
- ) => null | CmsEntryFieldFilterPluginCreateResponse | CmsEntryFieldFilterPluginCreateResponse[];
16
- }
17
-
18
- interface CmsEntryFieldFilterPluginCreateParams<T = any> {
19
- key: string;
20
- value: T;
21
- field: Field;
22
- fields: Record<string, Field>;
23
- operation: string;
24
- valueFilterRegistry: ValueFilterRegistry.Interface;
25
- transformValuePlugins: Record<string, ICmsFieldFilterValueTransformPlugin>;
26
- getFilterCreatePlugin: (type: string) => CmsEntryFieldFilterPlugin;
27
- negate: boolean;
28
- compareValue: any;
29
- transformValue: <I = any, O = any>(value: I) => O;
30
- }
31
-
32
- export interface CmsEntryFieldFilterPluginCreateResponse {
33
- field: Field;
34
- path: string;
35
- fieldPathId: string;
36
- filter: ValueFilterRegistry.Filter;
37
- negate: boolean;
38
- compareValue: any;
39
- transformValue: <I = any, O = any>(value: I) => O;
40
- }
41
-
42
- export class CmsEntryFieldFilterPlugin<T = any> extends Plugin {
43
- public static override readonly type: string = "cms.dynamodb.entry.field.filter";
44
- public static readonly ALL: string = "*";
45
-
46
- private readonly config: CmsEntryFieldFilterPluginParams<T>;
47
-
48
- public readonly fieldType: string;
49
-
50
- public constructor(config: CmsEntryFieldFilterPluginParams<T>) {
51
- super();
52
- this.config = config;
53
- this.fieldType = this.config.fieldType;
54
- }
55
-
56
- public create(params: CmsEntryFieldFilterPluginCreateParams<T>) {
57
- return this.config.create(params);
58
- }
59
- }