@webiny/api-headless-cms-storage 0.0.0-unstable.0156a4c312

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 (144) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +11 -0
  3. package/cms/storageHelpers.d.ts +9 -0
  4. package/cms/storageHelpers.js +45 -0
  5. package/cms/storageHelpers.js.map +1 -0
  6. package/features/FilterRegistriesFeature.d.ts +9 -0
  7. package/features/FilterRegistriesFeature.js +17 -0
  8. package/features/FilterRegistriesFeature.js.map +1 -0
  9. package/features/fieldFilterCreate/DefaultFieldFilterCreateRegistry.d.ts +9 -0
  10. package/features/fieldFilterCreate/DefaultFieldFilterCreateRegistry.js +26 -0
  11. package/features/fieldFilterCreate/DefaultFieldFilterCreateRegistry.js.map +1 -0
  12. package/features/fieldFilterCreate/FieldFilterCreateRegistry.d.ts +7 -0
  13. package/features/fieldFilterCreate/FieldFilterCreateRegistry.js +20 -0
  14. package/features/fieldFilterCreate/FieldFilterCreateRegistry.js.map +1 -0
  15. package/features/fieldFilterCreate/abstractions.d.ts +41 -0
  16. package/features/fieldFilterCreate/abstractions.js +5 -0
  17. package/features/fieldFilterCreate/abstractions.js.map +1 -0
  18. package/features/fieldFilterPath/DefaultFieldFilterPathRegistry.d.ts +9 -0
  19. package/features/fieldFilterPath/DefaultFieldFilterPathRegistry.js +20 -0
  20. package/features/fieldFilterPath/DefaultFieldFilterPathRegistry.js.map +1 -0
  21. package/features/fieldFilterPath/FieldFilterPathRegistry.d.ts +6 -0
  22. package/features/fieldFilterPath/FieldFilterPathRegistry.js +14 -0
  23. package/features/fieldFilterPath/FieldFilterPathRegistry.js.map +1 -0
  24. package/features/fieldFilterPath/abstractions.d.ts +16 -0
  25. package/features/fieldFilterPath/abstractions.js +5 -0
  26. package/features/fieldFilterPath/abstractions.js.map +1 -0
  27. package/features/fieldFilterValueTransform/DefaultFieldFilterValueTransformRegistry.d.ts +9 -0
  28. package/features/fieldFilterValueTransform/DefaultFieldFilterValueTransformRegistry.js +17 -0
  29. package/features/fieldFilterValueTransform/DefaultFieldFilterValueTransformRegistry.js.map +1 -0
  30. package/features/fieldFilterValueTransform/FieldFilterValueTransformRegistry.d.ts +6 -0
  31. package/features/fieldFilterValueTransform/FieldFilterValueTransformRegistry.js +14 -0
  32. package/features/fieldFilterValueTransform/FieldFilterValueTransformRegistry.js.map +1 -0
  33. package/features/fieldFilterValueTransform/abstractions.d.ts +14 -0
  34. package/features/fieldFilterValueTransform/abstractions.js +5 -0
  35. package/features/fieldFilterValueTransform/abstractions.js.map +1 -0
  36. package/features/fieldSorting/DefaultFieldSortingRegistry.d.ts +8 -0
  37. package/features/fieldSorting/DefaultFieldSortingRegistry.js +11 -0
  38. package/features/fieldSorting/DefaultFieldSortingRegistry.js.map +1 -0
  39. package/features/fieldSorting/FieldSortingRegistry.d.ts +6 -0
  40. package/features/fieldSorting/FieldSortingRegistry.js +14 -0
  41. package/features/fieldSorting/FieldSortingRegistry.js.map +1 -0
  42. package/features/fieldSorting/abstractions.d.ts +40 -0
  43. package/features/fieldSorting/abstractions.js +5 -0
  44. package/features/fieldSorting/abstractions.js.map +1 -0
  45. package/filtering/expressions/createExpressions.d.ts +29 -0
  46. package/filtering/expressions/createExpressions.js +109 -0
  47. package/filtering/expressions/createExpressions.js.map +1 -0
  48. package/filtering/fields/createFields.d.ts +15 -0
  49. package/filtering/fields/createFields.js +81 -0
  50. package/filtering/fields/createFields.js.map +1 -0
  51. package/filtering/fields/extractSort.d.ts +17 -0
  52. package/filtering/fields/extractSort.js +59 -0
  53. package/filtering/fields/extractSort.js.map +1 -0
  54. package/filtering/fields/systemFields.d.ts +5 -0
  55. package/filtering/fields/systemFields.js +165 -0
  56. package/filtering/fields/systemFields.js.map +1 -0
  57. package/filtering/fields/types.d.ts +19 -0
  58. package/filtering/fields/types.js +0 -0
  59. package/filtering/filter.d.ts +19 -0
  60. package/filtering/filter.js +84 -0
  61. package/filtering/filter.js.map +1 -0
  62. package/filtering/fullTextSearch.d.ts +11 -0
  63. package/filtering/fullTextSearch.js +25 -0
  64. package/filtering/fullTextSearch.js.map +1 -0
  65. package/filtering/getValue.d.ts +1 -0
  66. package/filtering/getValue.js +37 -0
  67. package/filtering/getValue.js.map +1 -0
  68. package/filtering/mapPlugins.d.ts +8 -0
  69. package/filtering/mapPlugins.js +18 -0
  70. package/filtering/mapPlugins.js.map +1 -0
  71. package/filtering/plugins/defaultFilterCreate.d.ts +2 -0
  72. package/filtering/plugins/defaultFilterCreate.js +33 -0
  73. package/filtering/plugins/defaultFilterCreate.js.map +1 -0
  74. package/filtering/plugins/index.d.ts +1 -0
  75. package/filtering/plugins/index.js +13 -0
  76. package/filtering/plugins/index.js.map +1 -0
  77. package/filtering/plugins/objectFilterCreate.d.ts +2 -0
  78. package/filtering/plugins/objectFilterCreate.js +68 -0
  79. package/filtering/plugins/objectFilterCreate.js.map +1 -0
  80. package/filtering/plugins/refFilterCreate.d.ts +3 -0
  81. package/filtering/plugins/refFilterCreate.js +63 -0
  82. package/filtering/plugins/refFilterCreate.js.map +1 -0
  83. package/filtering/plugins/searchableJsonFilterCreate.d.ts +2 -0
  84. package/filtering/plugins/searchableJsonFilterCreate.js +56 -0
  85. package/filtering/plugins/searchableJsonFilterCreate.js.map +1 -0
  86. package/filtering/sort.d.ts +12 -0
  87. package/filtering/sort.js +41 -0
  88. package/filtering/sort.js.map +1 -0
  89. package/filtering/transform.d.ts +6 -0
  90. package/filtering/transform.js +7 -0
  91. package/filtering/transform.js.map +1 -0
  92. package/filtering/values.d.ts +2 -0
  93. package/filtering/values.js +15 -0
  94. package/filtering/values.js.map +1 -0
  95. package/filtering/where.d.ts +5 -0
  96. package/filtering/where.js +22 -0
  97. package/filtering/where.js.map +1 -0
  98. package/handlers/datetimeTransformHandler.d.ts +2 -0
  99. package/handlers/datetimeTransformHandler.js +34 -0
  100. package/handlers/datetimeTransformHandler.js.map +1 -0
  101. package/handlers/defaultFilterCreateHandler.d.ts +2 -0
  102. package/handlers/defaultFilterCreateHandler.js +27 -0
  103. package/handlers/defaultFilterCreateHandler.js.map +1 -0
  104. package/handlers/locationFolderIdPathHandler.d.ts +2 -0
  105. package/handlers/locationFolderIdPathHandler.js +18 -0
  106. package/handlers/locationFolderIdPathHandler.js.map +1 -0
  107. package/handlers/objectFilterCreateHandler.d.ts +2 -0
  108. package/handlers/objectFilterCreateHandler.js +62 -0
  109. package/handlers/objectFilterCreateHandler.js.map +1 -0
  110. package/handlers/plainObjectPathHandler.d.ts +2 -0
  111. package/handlers/plainObjectPathHandler.js +14 -0
  112. package/handlers/plainObjectPathHandler.js.map +1 -0
  113. package/handlers/refFilterCreateHandler.d.ts +2 -0
  114. package/handlers/refFilterCreateHandler.js +57 -0
  115. package/handlers/refFilterCreateHandler.js.map +1 -0
  116. package/handlers/searchableJsonFilterCreateHandler.d.ts +2 -0
  117. package/handlers/searchableJsonFilterCreateHandler.js +43 -0
  118. package/handlers/searchableJsonFilterCreateHandler.js.map +1 -0
  119. package/index.d.ts +24 -0
  120. package/index.js +19 -0
  121. package/package.json +35 -0
  122. package/path/locationFolderId.d.ts +2 -0
  123. package/path/locationFolderId.js +21 -0
  124. package/path/locationFolderId.js.map +1 -0
  125. package/path/plainObject.d.ts +2 -0
  126. package/path/plainObject.js +16 -0
  127. package/path/plainObject.js.map +1 -0
  128. package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +23 -0
  129. package/plugins/CmsEntryFieldFilterPathPlugin.js +30 -0
  130. package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -0
  131. package/plugins/CmsEntryFieldFilterPlugin.d.ts +39 -0
  132. package/plugins/CmsEntryFieldFilterPlugin.js +20 -0
  133. package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -0
  134. package/plugins/CmsEntryFieldSortingPlugin.d.ts +37 -0
  135. package/plugins/CmsEntryFieldSortingPlugin.js +20 -0
  136. package/plugins/CmsEntryFieldSortingPlugin.js.map +1 -0
  137. package/plugins/CmsFieldFilterValueTransformPlugin.d.ts +21 -0
  138. package/plugins/CmsFieldFilterValueTransformPlugin.js +19 -0
  139. package/plugins/CmsFieldFilterValueTransformPlugin.js.map +1 -0
  140. package/plugins/index.d.ts +7 -0
  141. package/plugins/index.js +4 -0
  142. package/transforms/datetime.d.ts +2 -0
  143. package/transforms/datetime.js +37 -0
  144. package/transforms/datetime.js.map +1 -0
@@ -0,0 +1,2 @@
1
+ import type { FieldFilterValueTransformRegistry } from "../features/fieldFilterValueTransform/abstractions.js";
2
+ export declare const createDatetimeTransformHandler: () => FieldFilterValueTransformRegistry.Handler;
@@ -0,0 +1,34 @@
1
+ import { parseISO } from "date-fns";
2
+ const transformTime = (value)=>{
3
+ if (null == value) throw new Error("Time value is null or undefined.");
4
+ else if ("boolean" == typeof value || "" === value || Array.isArray(value)) throw new Error("Field value must be a string because field is defined as time.");
5
+ const converted = Number(`${value}`);
6
+ if ("number" == typeof value || false === isNaN(converted)) return Number(value);
7
+ else if ("string" != typeof value) throw new Error("Field value must be a string because field is defined as time.");
8
+ const [time, milliseconds = 0] = value.split(".");
9
+ const values = time.split(":").map(Number);
10
+ if (values.length < 2) throw new Error("Time must contain at least hours and minutes.");
11
+ const [hours, minutes, seconds = 0] = values;
12
+ return (60 * hours * 60 + 60 * minutes + seconds) * 1000 + Number(milliseconds);
13
+ };
14
+ const transformDateTime = (value)=>{
15
+ if (null == value) return null;
16
+ else if ("string" == typeof value) {
17
+ const parsedDateTime = parseISO(value).getTime();
18
+ if (false === isNaN(parsedDateTime)) return parsedDateTime;
19
+ } else if (value instanceof Date || "function" == typeof value?.getTime) return value.getTime();
20
+ console.warn("Could not parse given dateTime value.", "PARSE_DATE_ERROR", {
21
+ value
22
+ });
23
+ return null;
24
+ };
25
+ const createDatetimeTransformHandler = ()=>({
26
+ transform: ({ field, value })=>{
27
+ const { type } = field.settings || {};
28
+ if ("time" === type) return transformTime(value);
29
+ return transformDateTime(value);
30
+ }
31
+ });
32
+ export { createDatetimeTransformHandler };
33
+
34
+ //# sourceMappingURL=datetimeTransformHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlers/datetimeTransformHandler.js","sources":["../../src/handlers/datetimeTransformHandler.ts"],"sourcesContent":["import { parseISO } from \"date-fns\";\nimport type { FieldFilterValueTransformRegistry } from \"../features/fieldFilterValueTransform/abstractions.js\";\n\nconst transformTime = (value: any): number => {\n if (value === undefined || value === null) {\n throw new Error(`Time value is null or undefined.`);\n } else if (typeof value === \"boolean\" || value === \"\" || Array.isArray(value)) {\n throw new Error(\"Field value must be a string because field is defined as time.\");\n }\n const converted = Number(`${value}`);\n if (typeof value === \"number\" || isNaN(converted) === false) {\n return Number(value);\n } else if (typeof value !== \"string\") {\n throw new Error(\"Field value must be a string because field is defined as time.\");\n }\n const [time, milliseconds = 0] = value.split(\".\");\n const values = time.split(\":\").map(Number);\n if (values.length < 2) {\n throw new Error(\"Time must contain at least hours and minutes.\");\n }\n const [hours, minutes, seconds = 0] = values;\n return (hours * 60 * 60 + minutes * 60 + seconds) * 1000 + Number(milliseconds);\n};\n\nconst transformDateTime = (value: any): number | null => {\n if (value === null || value === undefined) {\n return null;\n } else if (typeof value === \"string\") {\n const parsedDateTime = parseISO(value).getTime();\n if (isNaN(parsedDateTime) === false) {\n return parsedDateTime;\n }\n } else if (value instanceof Date || typeof (value as unknown as Date)?.getTime === \"function\") {\n return value.getTime();\n }\n console.warn(\"Could not parse given dateTime value.\", \"PARSE_DATE_ERROR\", {\n value\n });\n return null;\n};\n\nexport const createDatetimeTransformHandler = (): FieldFilterValueTransformRegistry.Handler => {\n return {\n transform: ({ field, value }) => {\n const { type } = field.settings || {};\n if (type === \"time\") {\n return transformTime(value);\n }\n return transformDateTime(value);\n }\n };\n};\n"],"names":["transformTime","value","Error","Array","converted","Number","isNaN","time","milliseconds","values","hours","minutes","seconds","transformDateTime","parsedDateTime","parseISO","Date","console","createDatetimeTransformHandler","field","type"],"mappings":";AAGA,MAAMA,gBAAgB,CAACC;IACnB,IAAIA,QAAAA,OACA,MAAM,IAAIC,MAAM;SACb,IAAI,AAAiB,aAAjB,OAAOD,SAAuBA,AAAU,OAAVA,SAAgBE,MAAM,OAAO,CAACF,QACnE,MAAM,IAAIC,MAAM;IAEpB,MAAME,YAAYC,OAAO,GAAGJ,OAAO;IACnC,IAAI,AAAiB,YAAjB,OAAOA,SAAsBK,AAAqB,UAArBA,MAAMF,YACnC,OAAOC,OAAOJ;SACX,IAAI,AAAiB,YAAjB,OAAOA,OACd,MAAM,IAAIC,MAAM;IAEpB,MAAM,CAACK,MAAMC,eAAe,CAAC,CAAC,GAAGP,MAAM,KAAK,CAAC;IAC7C,MAAMQ,SAASF,KAAK,KAAK,CAAC,KAAK,GAAG,CAACF;IACnC,IAAII,OAAO,MAAM,GAAG,GAChB,MAAM,IAAIP,MAAM;IAEpB,MAAM,CAACQ,OAAOC,SAASC,UAAU,CAAC,CAAC,GAAGH;IACtC,OAAQC,AAAAA,CAAAA,AAAQ,KAARA,QAAa,KAAKC,AAAU,KAAVA,UAAeC,OAAM,IAAK,OAAOP,OAAOG;AACtE;AAEA,MAAMK,oBAAoB,CAACZ;IACvB,IAAIA,QAAAA,OACA,OAAO;SACJ,IAAI,AAAiB,YAAjB,OAAOA,OAAoB;QAClC,MAAMa,iBAAiBC,SAASd,OAAO,OAAO;QAC9C,IAAIK,AAA0B,UAA1BA,MAAMQ,iBACN,OAAOA;IAEf,OAAO,IAAIb,iBAAiBe,QAAQ,AAA+C,cAA/C,OAAQf,OAA2B,SACnE,OAAOA,MAAM,OAAO;IAExBgB,QAAQ,IAAI,CAAC,yCAAyC,oBAAoB;QACtEhB;IACJ;IACA,OAAO;AACX;AAEO,MAAMiB,iCAAiC,IACnC;QACH,WAAW,CAAC,EAAEC,KAAK,EAAElB,KAAK,EAAE;YACxB,MAAM,EAAEmB,IAAI,EAAE,GAAGD,MAAM,QAAQ,IAAI,CAAC;YACpC,IAAIC,AAAS,WAATA,MACA,OAAOpB,cAAcC;YAEzB,OAAOY,kBAAkBZ;QAC7B;IACJ"}
@@ -0,0 +1,2 @@
1
+ import type { FieldFilterCreateRegistry } from "../features/fieldFilterCreate/abstractions.js";
2
+ export declare const createDefaultFilterCreateHandler: () => FieldFilterCreateRegistry.Handler;
@@ -0,0 +1,27 @@
1
+ import error from "@webiny/error";
2
+ const createDefaultFilterCreateHandler = ()=>({
3
+ create: (params)=>{
4
+ const { negate, transformValue, field, compareValue, valueFilterRegistry } = params;
5
+ const filter = valueFilterRegistry.get(params.operation);
6
+ if (!filter) throw new error(`Missing ValueFilterPlugin for operation "${params.operation}".`, "MISSING_OPERATION_PLUGIN", {
7
+ operation: params.operation
8
+ });
9
+ return {
10
+ negate,
11
+ transformValue,
12
+ field,
13
+ compareValue,
14
+ fieldPathId: [
15
+ ...field.parents.map((f)=>f.fieldId),
16
+ field.fieldId
17
+ ].join("."),
18
+ path: field.createPath({
19
+ field
20
+ }),
21
+ filter
22
+ };
23
+ }
24
+ });
25
+ export { createDefaultFilterCreateHandler };
26
+
27
+ //# sourceMappingURL=defaultFilterCreateHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlers/defaultFilterCreateHandler.js","sources":["../../src/handlers/defaultFilterCreateHandler.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { FieldFilterCreateRegistry } from \"../features/fieldFilterCreate/abstractions.js\";\n\nexport const createDefaultFilterCreateHandler = (): FieldFilterCreateRegistry.Handler => {\n return {\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"],"names":["createDefaultFilterCreateHandler","params","negate","transformValue","field","compareValue","valueFilterRegistry","filter","WebinyError","f"],"mappings":";AAGO,MAAMA,mCAAmC,IACrC;QACH,QAAQC,CAAAA;YACJ,MAAM,EAAEC,MAAM,EAAEC,cAAc,EAAEC,KAAK,EAAEC,YAAY,EAAEC,mBAAmB,EAAE,GAAGL;YAC7E,MAAMM,SAASD,oBAAoB,GAAG,CAACL,OAAO,SAAS;YACvD,IAAI,CAACM,QACD,MAAM,IAAIC,MACN,CAAC,yCAAyC,EAAEP,OAAO,SAAS,CAAC,EAAE,CAAC,EAChE,4BACA;gBACI,WAAWA,OAAO,SAAS;YAC/B;YAGR,OAAO;gBACHC;gBACAC;gBACAC;gBACAC;gBACA,aAAa;uBAAID,MAAM,OAAO,CAAC,GAAG,CAACK,CAAAA,IAAKA,EAAE,OAAO;oBAAGL,MAAM,OAAO;iBAAC,CAAC,IAAI,CAAC;gBACxE,MAAMA,MAAM,UAAU,CAAC;oBACnBA;gBACJ;gBACAG;YACJ;QACJ;IACJ"}
@@ -0,0 +1,2 @@
1
+ import type { FieldFilterPathRegistry } from "../features/fieldFilterPath/abstractions.js";
2
+ export declare const createLocationFolderIdPathHandler: () => FieldFilterPathRegistry.Handler;
@@ -0,0 +1,18 @@
1
+ import error from "@webiny/error";
2
+ const createLocationFolderIdPathHandler = ()=>({
3
+ canUse: (field, parents)=>{
4
+ if ("folderId" !== field.fieldId) return false;
5
+ else if (!parents?.length) return false;
6
+ return "wbyAco_location" === parents[0];
7
+ },
8
+ createPath: ({ field })=>{
9
+ const { path } = field.settings || {};
10
+ if (!path) throw new error("Missing path settings value.", "FIELD_SETTINGS_ERROR", {
11
+ field
12
+ });
13
+ return path;
14
+ }
15
+ });
16
+ export { createLocationFolderIdPathHandler };
17
+
18
+ //# sourceMappingURL=locationFolderIdPathHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlers/locationFolderIdPathHandler.js","sources":["../../src/handlers/locationFolderIdPathHandler.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { FieldFilterPathRegistry } from \"../features/fieldFilterPath/abstractions.js\";\n\nexport const createLocationFolderIdPathHandler = (): FieldFilterPathRegistry.Handler => {\n return {\n canUse: (field, parents) => {\n if (field.fieldId !== \"folderId\") {\n return false;\n } else if (!parents?.length) {\n return false;\n }\n return parents[0] === \"wbyAco_location\";\n },\n createPath: ({ field }) => {\n const { path } = field.settings || {};\n if (!path) {\n throw new WebinyError(\"Missing path settings value.\", \"FIELD_SETTINGS_ERROR\", {\n field\n });\n }\n return path;\n }\n };\n};\n"],"names":["createLocationFolderIdPathHandler","field","parents","path","WebinyError"],"mappings":";AAGO,MAAMA,oCAAoC,IACtC;QACH,QAAQ,CAACC,OAAOC;YACZ,IAAID,AAAkB,eAAlBA,MAAM,OAAO,EACb,OAAO;iBACJ,IAAI,CAACC,SAAS,QACjB,OAAO;YAEX,OAAOA,AAAe,sBAAfA,OAAO,CAAC,EAAE;QACrB;QACA,YAAY,CAAC,EAAED,KAAK,EAAE;YAClB,MAAM,EAAEE,IAAI,EAAE,GAAGF,MAAM,QAAQ,IAAI,CAAC;YACpC,IAAI,CAACE,MACD,MAAM,IAAIC,MAAY,gCAAgC,wBAAwB;gBAC1EH;YACJ;YAEJ,OAAOE;QACX;IACJ"}
@@ -0,0 +1,2 @@
1
+ import type { FieldFilterCreateRegistry } from "../features/fieldFilterCreate/abstractions.js";
2
+ export declare const createObjectFilterCreateHandler: () => FieldFilterCreateRegistry.Handler;
@@ -0,0 +1,62 @@
1
+ import error from "@webiny/error";
2
+ import { extractWhereParams } from "../filtering/where.js";
3
+ import { transformValue } from "../filtering/transform.js";
4
+ import { getBaseFieldType } from "@webiny/api-headless-cms/utils/getBaseFieldType.js";
5
+ const createObjectFilterCreateHandler = ()=>({
6
+ create: (params)=>{
7
+ const { value: objectValue, valueFilterRegistry, transformRegistry, getHandler, field: parentField, fields } = params;
8
+ const filters = [];
9
+ for(const key in objectValue){
10
+ const value = objectValue[key];
11
+ if (void 0 === value) continue;
12
+ const whereParams = extractWhereParams(key);
13
+ if (!whereParams) continue;
14
+ const { negate, fieldId, operation } = whereParams;
15
+ const fieldPath = parentField.parents.map((p)=>p.fieldId).concat([
16
+ parentField.fieldId,
17
+ fieldId
18
+ ]).join(".");
19
+ const field = fields[fieldPath];
20
+ if (!field) throw new error(`There is no field with the field path "${fieldPath}".`, "FIELD_ERROR", {
21
+ fieldId
22
+ });
23
+ const fieldType = getBaseFieldType(field);
24
+ const handler = getHandler(fieldType);
25
+ const transformHandler = transformRegistry.get(fieldType);
26
+ const transformValueCallable = (value)=>{
27
+ if (!transformHandler) return value;
28
+ return transformHandler.transform({
29
+ field,
30
+ value
31
+ });
32
+ };
33
+ const result = handler.create({
34
+ key,
35
+ value,
36
+ valueFilterRegistry,
37
+ transformRegistry,
38
+ getHandler,
39
+ operation,
40
+ negate,
41
+ field,
42
+ fields,
43
+ compareValue: transformValue({
44
+ value,
45
+ transform: transformValueCallable
46
+ }),
47
+ transformValue: transformValueCallable
48
+ });
49
+ if (result) {
50
+ if (Array.isArray(result)) {
51
+ filters.push(...result);
52
+ continue;
53
+ }
54
+ filters.push(result);
55
+ }
56
+ }
57
+ return filters;
58
+ }
59
+ });
60
+ export { createObjectFilterCreateHandler };
61
+
62
+ //# sourceMappingURL=objectFilterCreateHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlers/objectFilterCreateHandler.js","sources":["../../src/handlers/objectFilterCreateHandler.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { FieldFilterCreateRegistry } from \"../features/fieldFilterCreate/abstractions.js\";\nimport { extractWhereParams } from \"../filtering/where.js\";\nimport { transformValue } from \"../filtering/transform.js\";\nimport { getBaseFieldType } from \"@webiny/api-headless-cms/utils/getBaseFieldType.js\";\n\nexport const createObjectFilterCreateHandler = (): FieldFilterCreateRegistry.Handler => {\n return {\n create: params => {\n const {\n value: objectValue,\n valueFilterRegistry,\n transformRegistry,\n getHandler,\n field: parentField,\n fields\n } = params;\n\n const filters: FieldFilterCreateRegistry.Result[] = [];\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 { fieldId }\n );\n }\n\n const fieldType = getBaseFieldType(field);\n const handler = getHandler(fieldType);\n const transformHandler = transformRegistry.get(fieldType);\n\n const transformValueCallable = (value: any) => {\n if (!transformHandler) {\n return value;\n }\n return transformHandler.transform({ field, value });\n };\n\n const result = handler.create({\n key,\n value,\n valueFilterRegistry,\n transformRegistry,\n getHandler,\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"],"names":["createObjectFilterCreateHandler","params","objectValue","valueFilterRegistry","transformRegistry","getHandler","parentField","fields","filters","key","value","undefined","whereParams","extractWhereParams","negate","fieldId","operation","fieldPath","p","field","WebinyError","fieldType","getBaseFieldType","handler","transformHandler","transformValueCallable","result","transformValue","Array"],"mappings":";;;;AAMO,MAAMA,kCAAkC,IACpC;QACH,QAAQC,CAAAA;YACJ,MAAM,EACF,OAAOC,WAAW,EAClBC,mBAAmB,EACnBC,iBAAiB,EACjBC,UAAU,EACV,OAAOC,WAAW,EAClBC,MAAM,EACT,GAAGN;YAEJ,MAAMO,UAA8C,EAAE;YAEtD,IAAK,MAAMC,OAAOP,YAAa;gBAC3B,MAAMQ,QAAQR,WAAW,CAACO,IAAI;gBAC9B,IAAIC,AAAUC,WAAVD,OACA;gBAEJ,MAAME,cAAcC,mBAAmBJ;gBACvC,IAAI,CAACG,aACD;gBAEJ,MAAM,EAAEE,MAAM,EAAEC,OAAO,EAAEC,SAAS,EAAE,GAAGJ;gBAEvC,MAAMK,YAAYX,YAAY,OAAO,CAChC,GAAG,CAACY,CAAAA,IAAKA,EAAE,OAAO,EAClB,MAAM,CAAC;oBAACZ,YAAY,OAAO;oBAAES;iBAAQ,EACrC,IAAI,CAAC;gBAEV,MAAMI,QAAQZ,MAAM,CAACU,UAAU;gBAC/B,IAAI,CAACE,OACD,MAAM,IAAIC,MACN,CAAC,uCAAuC,EAAEH,UAAU,EAAE,CAAC,EACvD,eACA;oBAAEF;gBAAQ;gBAIlB,MAAMM,YAAYC,iBAAiBH;gBACnC,MAAMI,UAAUlB,WAAWgB;gBAC3B,MAAMG,mBAAmBpB,kBAAkB,GAAG,CAACiB;gBAE/C,MAAMI,yBAAyB,CAACf;oBAC5B,IAAI,CAACc,kBACD,OAAOd;oBAEX,OAAOc,iBAAiB,SAAS,CAAC;wBAAEL;wBAAOT;oBAAM;gBACrD;gBAEA,MAAMgB,SAASH,QAAQ,MAAM,CAAC;oBAC1Bd;oBACAC;oBACAP;oBACAC;oBACAC;oBACAW;oBACAF;oBACAK;oBACAZ;oBACA,cAAcoB,eAAe;wBACzBjB;wBACA,WAAWe;oBACf;oBACA,gBAAgBA;gBACpB;gBACA,IAAKC;oBAGL,IAAIE,MAAM,OAAO,CAACF,SAAS;wBACvBlB,QAAQ,IAAI,IAAIkB;wBAChB;oBACJ;oBAEAlB,QAAQ,IAAI,CAACkB;;YACjB;YACA,OAAOlB;QACX;IACJ"}
@@ -0,0 +1,2 @@
1
+ import type { FieldFilterPathRegistry } from "../features/fieldFilterPath/abstractions.js";
2
+ export declare const createPlainObjectPathHandler: () => FieldFilterPathRegistry.Handler;
@@ -0,0 +1,14 @@
1
+ import error from "@webiny/error";
2
+ const createPlainObjectPathHandler = ()=>({
3
+ canUse: ()=>true,
4
+ createPath: ({ field })=>{
5
+ const { path } = field.settings || {};
6
+ if (!path) throw new error("Missing path settings value.", "FIELD_SETTINGS_ERROR", {
7
+ field
8
+ });
9
+ return path;
10
+ }
11
+ });
12
+ export { createPlainObjectPathHandler };
13
+
14
+ //# sourceMappingURL=plainObjectPathHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlers/plainObjectPathHandler.js","sources":["../../src/handlers/plainObjectPathHandler.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { FieldFilterPathRegistry } from \"../features/fieldFilterPath/abstractions.js\";\n\nexport const createPlainObjectPathHandler = (): FieldFilterPathRegistry.Handler => {\n return {\n canUse: () => true,\n createPath: ({ field }) => {\n const { path } = field.settings || {};\n if (!path) {\n throw new WebinyError(\"Missing path settings value.\", \"FIELD_SETTINGS_ERROR\", {\n field\n });\n }\n return path;\n }\n };\n};\n"],"names":["createPlainObjectPathHandler","field","path","WebinyError"],"mappings":";AAGO,MAAMA,+BAA+B,IACjC;QACH,QAAQ,IAAM;QACd,YAAY,CAAC,EAAEC,KAAK,EAAE;YAClB,MAAM,EAAEC,IAAI,EAAE,GAAGD,MAAM,QAAQ,IAAI,CAAC;YACpC,IAAI,CAACC,MACD,MAAM,IAAIC,MAAY,gCAAgC,wBAAwB;gBAC1EF;YACJ;YAEJ,OAAOC;QACX;IACJ"}
@@ -0,0 +1,2 @@
1
+ import type { FieldFilterCreateRegistry } from "../features/fieldFilterCreate/abstractions.js";
2
+ export declare const createRefFilterCreateHandler: () => FieldFilterCreateRegistry.Handler;
@@ -0,0 +1,57 @@
1
+ import error from "@webiny/error";
2
+ import { extractWhereParams } from "../filtering/where.js";
3
+ import { transformValue } from "../filtering/transform.js";
4
+ import { getBaseFieldType } from "@webiny/api-headless-cms/utils/getBaseFieldType.js";
5
+ const createRefFilterCreateHandler = ()=>({
6
+ create: (params)=>{
7
+ const { valueFilterRegistry, transformRegistry, field } = params;
8
+ let value = params.value;
9
+ if (!value) value = {
10
+ entryId: null
11
+ };
12
+ const propertyFilters = Object.keys(value);
13
+ if (0 === propertyFilters.length) return null;
14
+ const filters = [];
15
+ for (const propertyFilter of propertyFilters){
16
+ const whereParams = extractWhereParams(propertyFilter);
17
+ if (!whereParams) continue;
18
+ const { fieldId: propertyId, operation: propertyOperation, negate } = whereParams;
19
+ const fieldType = getBaseFieldType(field);
20
+ const transformHandler = transformRegistry.get(fieldType);
21
+ const transformValueCallable = (value)=>{
22
+ if (!transformHandler) return value;
23
+ return transformHandler.transform({
24
+ field,
25
+ value
26
+ });
27
+ };
28
+ const filter = valueFilterRegistry.get(propertyOperation);
29
+ if (!filter) throw new error(`Missing operation filter for "${propertyOperation}".`, "MISSING_OPERATION_FILTER");
30
+ const paths = [
31
+ field.createPath({
32
+ field
33
+ }),
34
+ propertyId
35
+ ];
36
+ filters.push({
37
+ field,
38
+ path: paths.join("."),
39
+ fieldPathId: [
40
+ ...field.parents.map((f)=>f.fieldId),
41
+ field.fieldId
42
+ ].join("."),
43
+ filter,
44
+ negate,
45
+ compareValue: transformValue({
46
+ value: value[propertyFilter],
47
+ transform: transformValueCallable
48
+ }),
49
+ transformValue: transformValueCallable
50
+ });
51
+ }
52
+ return filters;
53
+ }
54
+ });
55
+ export { createRefFilterCreateHandler };
56
+
57
+ //# sourceMappingURL=refFilterCreateHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlers/refFilterCreateHandler.js","sources":["../../src/handlers/refFilterCreateHandler.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { FieldFilterCreateRegistry } from \"../features/fieldFilterCreate/abstractions.js\";\nimport { extractWhereParams } from \"../filtering/where.js\";\nimport { transformValue } from \"../filtering/transform.js\";\nimport { getBaseFieldType } from \"@webiny/api-headless-cms/utils/getBaseFieldType.js\";\n\nexport const createRefFilterCreateHandler = (): FieldFilterCreateRegistry.Handler => {\n return {\n create: params => {\n const { valueFilterRegistry, transformRegistry, field } = params;\n let value = params.value;\n if (!value) {\n value = { entryId: null };\n }\n const propertyFilters = Object.keys(value);\n if (propertyFilters.length === 0) {\n return null;\n }\n const filters: FieldFilterCreateRegistry.Result[] = [];\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 const transformHandler = transformRegistry.get(fieldType);\n\n const transformValueCallable = (value: any) => {\n if (!transformHandler) {\n return value;\n }\n return transformHandler.transform({ field, value });\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 = [field.createPath({ field }), propertyId];\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"],"names":["createRefFilterCreateHandler","params","valueFilterRegistry","transformRegistry","field","value","propertyFilters","Object","filters","propertyFilter","whereParams","extractWhereParams","propertyId","propertyOperation","negate","fieldType","getBaseFieldType","transformHandler","transformValueCallable","filter","WebinyError","paths","f","transformValue"],"mappings":";;;;AAMO,MAAMA,+BAA+B,IACjC;QACH,QAAQC,CAAAA;YACJ,MAAM,EAAEC,mBAAmB,EAAEC,iBAAiB,EAAEC,KAAK,EAAE,GAAGH;YAC1D,IAAII,QAAQJ,OAAO,KAAK;YACxB,IAAI,CAACI,OACDA,QAAQ;gBAAE,SAAS;YAAK;YAE5B,MAAMC,kBAAkBC,OAAO,IAAI,CAACF;YACpC,IAAIC,AAA2B,MAA3BA,gBAAgB,MAAM,EACtB,OAAO;YAEX,MAAME,UAA8C,EAAE;YAEtD,KAAK,MAAMC,kBAAkBH,gBAAiB;gBAC1C,MAAMI,cAAcC,mBAAmBF;gBACvC,IAAI,CAACC,aACD;gBAEJ,MAAM,EAAE,SAASE,UAAU,EAAE,WAAWC,iBAAiB,EAAEC,MAAM,EAAE,GAAGJ;gBAEtE,MAAMK,YAAYC,iBAAiBZ;gBACnC,MAAMa,mBAAmBd,kBAAkB,GAAG,CAACY;gBAE/C,MAAMG,yBAAyB,CAACb;oBAC5B,IAAI,CAACY,kBACD,OAAOZ;oBAEX,OAAOY,iBAAiB,SAAS,CAAC;wBAAEb;wBAAOC;oBAAM;gBACrD;gBAEA,MAAMc,SAASjB,oBAAoB,GAAG,CAACW;gBACvC,IAAI,CAACM,QACD,MAAM,IAAIC,MACN,CAAC,8BAA8B,EAAEP,kBAAkB,EAAE,CAAC,EACtD;gBAIR,MAAMQ,QAAQ;oBAACjB,MAAM,UAAU,CAAC;wBAAEA;oBAAM;oBAAIQ;iBAAW;gBAEvDJ,QAAQ,IAAI,CAAC;oBACTJ;oBACA,MAAMiB,MAAM,IAAI,CAAC;oBACjB,aAAa;2BAAIjB,MAAM,OAAO,CAAC,GAAG,CAACkB,CAAAA,IAAKA,EAAE,OAAO;wBAAGlB,MAAM,OAAO;qBAAC,CAAC,IAAI,CAAC;oBACxEe;oBACAL;oBACA,cAAcS,eAAe;wBACzB,OAAOlB,KAAK,CAACI,eAAe;wBAC5B,WAAWS;oBACf;oBACA,gBAAgBA;gBACpB;YACJ;YAEA,OAAOV;QACX;IACJ"}
@@ -0,0 +1,2 @@
1
+ import type { FieldFilterCreateRegistry } from "../features/fieldFilterCreate/abstractions.js";
2
+ export declare const createSearchableJsonFilterCreateHandler: () => FieldFilterCreateRegistry.Handler;
@@ -0,0 +1,43 @@
1
+ import { extractWhereParams } from "../filtering/where.js";
2
+ function dotFlatten(obj, prefix = "") {
3
+ return Object.entries(obj).reduce((acc, [key, val])=>{
4
+ const path = prefix ? `${prefix}.${key}` : key;
5
+ if (val && "object" == typeof val && !Array.isArray(val)) Object.assign(acc, dotFlatten(val, path));
6
+ else acc[path] = val;
7
+ return acc;
8
+ }, {});
9
+ }
10
+ const createSearchableJsonFilterCreateHandler = ()=>({
11
+ create: (params)=>{
12
+ const { value: objectValue, valueFilterRegistry, field: parentField } = params;
13
+ const filters = [];
14
+ const accessPatterns = dotFlatten(objectValue);
15
+ for(const key in accessPatterns){
16
+ const value = accessPatterns[key];
17
+ if (void 0 === value) continue;
18
+ const whereParams = extractWhereParams(key);
19
+ if (!whereParams) continue;
20
+ const { negate, operation } = whereParams;
21
+ const transformValueCallable = (value)=>value;
22
+ const fieldId = `${parentField.fieldId}.${whereParams.fieldId ?? key}`;
23
+ const filter = valueFilterRegistry.get(operation);
24
+ if (!filter) {
25
+ console.error(`Missing operation filter for "${operation}".`);
26
+ continue;
27
+ }
28
+ filters.push({
29
+ field: parentField,
30
+ path: `values.${fieldId}`,
31
+ fieldPathId: `values.${fieldId}`,
32
+ negate,
33
+ filter,
34
+ compareValue: value,
35
+ transformValue: transformValueCallable
36
+ });
37
+ }
38
+ return filters;
39
+ }
40
+ });
41
+ export { createSearchableJsonFilterCreateHandler };
42
+
43
+ //# sourceMappingURL=searchableJsonFilterCreateHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlers/searchableJsonFilterCreateHandler.js","sources":["../../src/handlers/searchableJsonFilterCreateHandler.ts"],"sourcesContent":["import type { FieldFilterCreateRegistry } from \"../features/fieldFilterCreate/abstractions.js\";\nimport { extractWhereParams } from \"../filtering/where.js\";\n\nfunction dotFlatten(obj: Record<string, any>, prefix = \"\"): Record<string, any> {\n return Object.entries(obj).reduce<Record<string, any>>((acc, [key, val]) => {\n const path = prefix ? `${prefix}.${key}` : key;\n if (val && typeof val === \"object\" && !Array.isArray(val)) {\n Object.assign(acc, dotFlatten(val, path));\n } else {\n acc[path] = val;\n }\n return acc;\n }, {});\n}\n\nexport const createSearchableJsonFilterCreateHandler = (): FieldFilterCreateRegistry.Handler => {\n return {\n create: params => {\n const { value: objectValue, valueFilterRegistry, field: parentField } = params;\n\n const filters: FieldFilterCreateRegistry.Result[] = [];\n const accessPatterns = dotFlatten(objectValue);\n\n for (const key in accessPatterns) {\n const value = accessPatterns[key];\n if (value === undefined) {\n continue;\n }\n\n const whereParams = extractWhereParams(key);\n if (!whereParams) {\n continue;\n }\n const { negate, operation } = whereParams;\n\n const transformValueCallable = (value: any) => {\n return value;\n };\n\n const fieldId = `${parentField.fieldId}.${whereParams.fieldId ?? key}`;\n\n const filter = valueFilterRegistry.get(operation);\n if (!filter) {\n console.error(`Missing operation filter for \"${operation}\".`);\n continue;\n }\n\n filters.push({\n field: parentField,\n path: `values.${fieldId}`,\n fieldPathId: `values.${fieldId}`,\n negate,\n filter,\n compareValue: value,\n transformValue: transformValueCallable\n });\n }\n return filters;\n }\n };\n};\n"],"names":["dotFlatten","obj","prefix","Object","acc","key","val","path","Array","createSearchableJsonFilterCreateHandler","params","objectValue","valueFilterRegistry","parentField","filters","accessPatterns","value","undefined","whereParams","extractWhereParams","negate","operation","transformValueCallable","fieldId","filter","console"],"mappings":";AAGA,SAASA,WAAWC,GAAwB,EAAEC,SAAS,EAAE;IACrD,OAAOC,OAAO,OAAO,CAACF,KAAK,MAAM,CAAsB,CAACG,KAAK,CAACC,KAAKC,IAAI;QACnE,MAAMC,OAAOL,SAAS,GAAGA,OAAO,CAAC,EAAEG,KAAK,GAAGA;QAC3C,IAAIC,OAAO,AAAe,YAAf,OAAOA,OAAoB,CAACE,MAAM,OAAO,CAACF,MACjDH,OAAO,MAAM,CAACC,KAAKJ,WAAWM,KAAKC;aAEnCH,GAAG,CAACG,KAAK,GAAGD;QAEhB,OAAOF;IACX,GAAG,CAAC;AACR;AAEO,MAAMK,0CAA0C,IAC5C;QACH,QAAQC,CAAAA;YACJ,MAAM,EAAE,OAAOC,WAAW,EAAEC,mBAAmB,EAAE,OAAOC,WAAW,EAAE,GAAGH;YAExE,MAAMI,UAA8C,EAAE;YACtD,MAAMC,iBAAiBf,WAAWW;YAElC,IAAK,MAAMN,OAAOU,eAAgB;gBAC9B,MAAMC,QAAQD,cAAc,CAACV,IAAI;gBACjC,IAAIW,AAAUC,WAAVD,OACA;gBAGJ,MAAME,cAAcC,mBAAmBd;gBACvC,IAAI,CAACa,aACD;gBAEJ,MAAM,EAAEE,MAAM,EAAEC,SAAS,EAAE,GAAGH;gBAE9B,MAAMI,yBAAyB,CAACN,QACrBA;gBAGX,MAAMO,UAAU,GAAGV,YAAY,OAAO,CAAC,CAAC,EAAEK,YAAY,OAAO,IAAIb,KAAK;gBAEtE,MAAMmB,SAASZ,oBAAoB,GAAG,CAACS;gBACvC,IAAI,CAACG,QAAQ;oBACTC,QAAQ,KAAK,CAAC,CAAC,8BAA8B,EAAEJ,UAAU,EAAE,CAAC;oBAC5D;gBACJ;gBAEAP,QAAQ,IAAI,CAAC;oBACT,OAAOD;oBACP,MAAM,CAAC,OAAO,EAAEU,SAAS;oBACzB,aAAa,CAAC,OAAO,EAAEA,SAAS;oBAChCH;oBACAI;oBACA,cAAcR;oBACd,gBAAgBM;gBACpB;YACJ;YACA,OAAOR;QACX;IACJ"}
package/index.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ export { filter } from "./filtering/filter.js";
2
+ export { sort } from "./filtering/sort.js";
3
+ export { createFields } from "./filtering/fields/createFields.js";
4
+ export { createFilterCreatePlugins } from "./filtering/plugins/index.js";
5
+ export { createExpressions } from "./filtering/expressions/createExpressions.js";
6
+ export type { Expression, ExpressionCondition } from "./filtering/expressions/createExpressions.js";
7
+ export { getValue } from "./filtering/getValue.js";
8
+ export { CmsEntryFieldFilterPlugin } from "./plugins/CmsEntryFieldFilterPlugin.js";
9
+ export type { CmsEntryFieldFilterPluginCreateResponse } from "./plugins/CmsEntryFieldFilterPlugin.js";
10
+ export { CmsEntryFieldSortingPlugin, createCmsEntryFieldSortingPlugin } from "./plugins/CmsEntryFieldSortingPlugin.js";
11
+ export { CmsEntryFieldFilterPathPlugin } from "./plugins/CmsEntryFieldFilterPathPlugin.js";
12
+ export type { CreatePathCallable } from "./plugins/CmsEntryFieldFilterPathPlugin.js";
13
+ export { CmsFieldFilterValueTransformPlugin } from "./plugins/CmsFieldFilterValueTransformPlugin.js";
14
+ export { createPlainObjectPathPlugin } from "./path/plainObject.js";
15
+ export { createLocationFolderIdPathPlugin } from "./path/locationFolderId.js";
16
+ export { createDatetimeTransformValuePlugin } from "./transforms/datetime.js";
17
+ export { createStorageModelAccessor, createStorageTransformCallable, aggregateUniqueFieldValues } from "./cms/storageHelpers.js";
18
+ export type { Field } from "./filtering/fields/types.js";
19
+ export type { FilterItemFromStorage } from "./filtering/fields/types.js";
20
+ export { FieldFilterPathRegistry, type IFieldFilterPathHandler, type IFieldFilterPathRegistry } from "./features/fieldFilterPath/abstractions.js";
21
+ export { FieldFilterValueTransformRegistry, type IFieldFilterValueTransformHandler, type IFieldFilterValueTransformRegistry } from "./features/fieldFilterValueTransform/abstractions.js";
22
+ export { FieldFilterCreateRegistry, type IFieldFilterCreateHandler, type IFieldFilterCreateParams, type IFieldFilterCreateRegistry, type IFieldFilterCreateResult } from "./features/fieldFilterCreate/abstractions.js";
23
+ export { FieldSortingRegistry, type IFieldSortingCanUseParams, type IFieldSortingCreateParams, type IFieldSortingHandler, type IFieldSortingRegistry, type IFieldSortingResult } from "./features/fieldSorting/abstractions.js";
24
+ export { FilterRegistriesFeature } from "./features/FilterRegistriesFeature.js";
package/index.js ADDED
@@ -0,0 +1,19 @@
1
+ export { filter } from "./filtering/filter.js";
2
+ export { sort } from "./filtering/sort.js";
3
+ export { createFields } from "./filtering/fields/createFields.js";
4
+ export { createFilterCreatePlugins } from "./filtering/plugins/index.js";
5
+ export { createExpressions } from "./filtering/expressions/createExpressions.js";
6
+ export { getValue } from "./filtering/getValue.js";
7
+ export { CmsEntryFieldFilterPlugin } from "./plugins/CmsEntryFieldFilterPlugin.js";
8
+ export { CmsEntryFieldSortingPlugin, createCmsEntryFieldSortingPlugin } from "./plugins/CmsEntryFieldSortingPlugin.js";
9
+ export { CmsEntryFieldFilterPathPlugin } from "./plugins/CmsEntryFieldFilterPathPlugin.js";
10
+ export { CmsFieldFilterValueTransformPlugin } from "./plugins/CmsFieldFilterValueTransformPlugin.js";
11
+ export { createPlainObjectPathPlugin } from "./path/plainObject.js";
12
+ export { createLocationFolderIdPathPlugin } from "./path/locationFolderId.js";
13
+ export { createDatetimeTransformValuePlugin } from "./transforms/datetime.js";
14
+ export { aggregateUniqueFieldValues, createStorageModelAccessor, createStorageTransformCallable } from "./cms/storageHelpers.js";
15
+ export { FieldFilterPathRegistry } from "./features/fieldFilterPath/abstractions.js";
16
+ export { FieldFilterValueTransformRegistry } from "./features/fieldFilterValueTransform/abstractions.js";
17
+ export { FieldFilterCreateRegistry } from "./features/fieldFilterCreate/abstractions.js";
18
+ export { FieldSortingRegistry } from "./features/fieldSorting/abstractions.js";
19
+ export { FilterRegistriesFeature } from "./features/FilterRegistriesFeature.js";
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@webiny/api-headless-cms-storage",
3
+ "version": "0.0.0-unstable.0156a4c312",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "type": "module",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/webiny/webiny-js.git",
10
+ "directory": "packages/api-headless-cms-storage"
11
+ },
12
+ "dependencies": {
13
+ "@webiny/api": "0.0.0-unstable.0156a4c312",
14
+ "@webiny/api-headless-cms": "0.0.0-unstable.0156a4c312",
15
+ "@webiny/db-utils": "0.0.0-unstable.0156a4c312",
16
+ "@webiny/di": "2.0.0",
17
+ "@webiny/error": "0.0.0-unstable.0156a4c312",
18
+ "@webiny/feature": "0.0.0-unstable.0156a4c312",
19
+ "@webiny/plugins": "0.0.0-unstable.0156a4c312",
20
+ "date-fns": "4.4.0",
21
+ "dot-prop": "10.2.0",
22
+ "lodash": "4.18.1"
23
+ },
24
+ "devDependencies": {
25
+ "@webiny/build-tools": "0.0.0-unstable.0156a4c312",
26
+ "typescript": "7.0.2",
27
+ "vitest": "5.0.5"
28
+ },
29
+ "webiny": {
30
+ "publishFrom": "dist"
31
+ },
32
+ "publishConfig": {
33
+ "access": "public"
34
+ }
35
+ }
@@ -0,0 +1,2 @@
1
+ import { CmsEntryFieldFilterPathPlugin } from "../plugins/CmsEntryFieldFilterPathPlugin.js";
2
+ export declare const createLocationFolderIdPathPlugin: () => CmsEntryFieldFilterPathPlugin;
@@ -0,0 +1,21 @@
1
+ import error from "@webiny/error";
2
+ import { CmsEntryFieldFilterPathPlugin } from "../plugins/CmsEntryFieldFilterPathPlugin.js";
3
+ const createPath = ({ field })=>{
4
+ const { path } = field.settings || {};
5
+ if (!path) throw new error("Missing path settings value.", "FIELD_SETTINGS_ERROR", {
6
+ field
7
+ });
8
+ return path;
9
+ };
10
+ const createLocationFolderIdPathPlugin = ()=>new CmsEntryFieldFilterPathPlugin({
11
+ fieldType: "text",
12
+ path: createPath,
13
+ canUse: (field, parents)=>{
14
+ if ("folderId" !== field.fieldId) return false;
15
+ else if (!parents?.length) return false;
16
+ return "wbyAco_location" === parents[0];
17
+ }
18
+ });
19
+ export { createLocationFolderIdPathPlugin };
20
+
21
+ //# sourceMappingURL=locationFolderId.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path/locationFolderId.js","sources":["../../src/path/locationFolderId.ts"],"sourcesContent":["/* File is @internal. */\nimport WebinyError from \"@webiny/error\";\nimport type { CreatePathCallable } from \"../plugins/CmsEntryFieldFilterPathPlugin.js\";\nimport { CmsEntryFieldFilterPathPlugin } from \"../plugins/CmsEntryFieldFilterPathPlugin.js\";\n\nconst createPath: CreatePathCallable = ({ field }) => {\n const { path } = field.settings || {};\n if (!path) {\n throw new WebinyError(\"Missing path settings value.\", \"FIELD_SETTINGS_ERROR\", {\n field\n });\n }\n return path;\n};\n\nexport const createLocationFolderIdPathPlugin = (): CmsEntryFieldFilterPathPlugin => {\n return new CmsEntryFieldFilterPathPlugin({\n fieldType: \"text\",\n path: createPath,\n canUse: (field, parents) => {\n if (field.fieldId !== \"folderId\") {\n return false;\n } else if (!parents?.length) {\n return false;\n }\n return parents[0] === \"wbyAco_location\";\n }\n });\n};\n"],"names":["createPath","field","path","WebinyError","createLocationFolderIdPathPlugin","CmsEntryFieldFilterPathPlugin","parents"],"mappings":";;AAKA,MAAMA,aAAiC,CAAC,EAAEC,KAAK,EAAE;IAC7C,MAAM,EAAEC,IAAI,EAAE,GAAGD,MAAM,QAAQ,IAAI,CAAC;IACpC,IAAI,CAACC,MACD,MAAM,IAAIC,MAAY,gCAAgC,wBAAwB;QAC1EF;IACJ;IAEJ,OAAOC;AACX;AAEO,MAAME,mCAAmC,IACrC,IAAIC,8BAA8B;QACrC,WAAW;QACX,MAAML;QACN,QAAQ,CAACC,OAAOK;YACZ,IAAIL,AAAkB,eAAlBA,MAAM,OAAO,EACb,OAAO;iBACJ,IAAI,CAACK,SAAS,QACjB,OAAO;YAEX,OAAOA,AAAe,sBAAfA,OAAO,CAAC,EAAE;QACrB;IACJ"}
@@ -0,0 +1,2 @@
1
+ import { CmsEntryFieldFilterPathPlugin } from "../plugins/CmsEntryFieldFilterPathPlugin.js";
2
+ export declare const createPlainObjectPathPlugin: () => CmsEntryFieldFilterPathPlugin;
@@ -0,0 +1,16 @@
1
+ import error from "@webiny/error";
2
+ import { CmsEntryFieldFilterPathPlugin } from "../plugins/CmsEntryFieldFilterPathPlugin.js";
3
+ const createPath = ({ field })=>{
4
+ const { path } = field.settings || {};
5
+ if (!path) throw new error("Missing path settings value.", "FIELD_SETTINGS_ERROR", {
6
+ field
7
+ });
8
+ return path;
9
+ };
10
+ const createPlainObjectPathPlugin = ()=>new CmsEntryFieldFilterPathPlugin({
11
+ fieldType: "plainObject",
12
+ path: createPath
13
+ });
14
+ export { createPlainObjectPathPlugin };
15
+
16
+ //# sourceMappingURL=plainObject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path/plainObject.js","sources":["../../src/path/plainObject.ts"],"sourcesContent":["/* File is @internal. */\nimport WebinyError from \"@webiny/error\";\nimport type { CreatePathCallable } from \"../plugins/CmsEntryFieldFilterPathPlugin.js\";\nimport { CmsEntryFieldFilterPathPlugin } from \"../plugins/CmsEntryFieldFilterPathPlugin.js\";\n\nconst createPath: CreatePathCallable = ({ field }) => {\n const { path } = field.settings || {};\n if (!path) {\n throw new WebinyError(\"Missing path settings value.\", \"FIELD_SETTINGS_ERROR\", {\n field\n });\n }\n return path;\n};\n\nexport const createPlainObjectPathPlugin = (): CmsEntryFieldFilterPathPlugin => {\n return new CmsEntryFieldFilterPathPlugin({\n fieldType: \"plainObject\",\n path: createPath\n });\n};\n"],"names":["createPath","field","path","WebinyError","createPlainObjectPathPlugin","CmsEntryFieldFilterPathPlugin"],"mappings":";;AAKA,MAAMA,aAAiC,CAAC,EAAEC,KAAK,EAAE;IAC7C,MAAM,EAAEC,IAAI,EAAE,GAAGD,MAAM,QAAQ,IAAI,CAAC;IACpC,IAAI,CAACC,MACD,MAAM,IAAIC,MAAY,gCAAgC,wBAAwB;QAC1EF;IACJ;IAEJ,OAAOC;AACX;AAEO,MAAME,8BAA8B,IAChC,IAAIC,8BAA8B;QACrC,WAAW;QACX,MAAML;IACV"}
@@ -0,0 +1,23 @@
1
+ import { Plugin } from "@webiny/plugins/Plugin.js";
2
+ import type { CmsModelField } from "@webiny/api-headless-cms/types/index.js";
3
+ export interface CreatePathCallableParams {
4
+ field: Partial<CmsModelField> & Pick<CmsModelField, "fieldId" | "storageId" | "id">;
5
+ index?: number;
6
+ }
7
+ export interface CreatePathCallable {
8
+ (params: CreatePathCallableParams): string;
9
+ }
10
+ export interface CmsEntryFieldFilterPathPluginParams {
11
+ fieldType: string;
12
+ fieldId?: string[];
13
+ path: string | CreatePathCallable;
14
+ canUse?: (field: Pick<CmsModelField, "fieldId" | "type">, parents?: string[]) => boolean;
15
+ }
16
+ export declare class CmsEntryFieldFilterPathPlugin extends Plugin {
17
+ static readonly type: string;
18
+ private readonly config;
19
+ get fieldType(): string;
20
+ constructor(config: CmsEntryFieldFilterPathPluginParams);
21
+ canUse(field: Pick<CmsModelField, "fieldId" | "type">, parents: string[]): boolean;
22
+ createPath(params: CreatePathCallableParams): string;
23
+ }
@@ -0,0 +1,30 @@
1
+ import error from "@webiny/error";
2
+ import { Plugin } from "@webiny/plugins/Plugin.js";
3
+ class CmsEntryFieldFilterPathPlugin extends Plugin {
4
+ static{
5
+ this.type = "cms-field-filter-path";
6
+ }
7
+ get fieldType() {
8
+ return this.config.fieldType;
9
+ }
10
+ constructor(config){
11
+ super();
12
+ this.config = config;
13
+ this.name = `${this.constructor.type}-${this.config.fieldType}`;
14
+ }
15
+ canUse(field, parents) {
16
+ if (field.type !== this.config.fieldType) return false;
17
+ else if (this.config.canUse) return this.config.canUse(field, parents);
18
+ const fieldId = this.config.fieldId;
19
+ if (!fieldId || false === Array.isArray(fieldId) || 0 === fieldId.length) return true;
20
+ return fieldId.includes(field.fieldId);
21
+ }
22
+ createPath(params) {
23
+ if ("function" == typeof this.config.path) return this.config.path(params);
24
+ else if ("string" == typeof this.config.path) return this.config.path;
25
+ throw new error(`Missing path in "${this.name}" plugin.`);
26
+ }
27
+ }
28
+ export { CmsEntryFieldFilterPathPlugin };
29
+
30
+ //# sourceMappingURL=CmsEntryFieldFilterPathPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugins/CmsEntryFieldFilterPathPlugin.js","sources":["../../src/plugins/CmsEntryFieldFilterPathPlugin.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { Plugin } from \"@webiny/plugins/Plugin.js\";\nimport type { CmsModelField } from \"@webiny/api-headless-cms/types/index.js\";\n\nexport interface CreatePathCallableParams {\n field: Partial<CmsModelField> & Pick<CmsModelField, \"fieldId\" | \"storageId\" | \"id\">;\n index?: number;\n}\nexport interface CreatePathCallable {\n (params: CreatePathCallableParams): string;\n}\nexport interface CmsEntryFieldFilterPathPluginParams {\n fieldType: string;\n fieldId?: string[];\n path: string | CreatePathCallable;\n canUse?: (field: Pick<CmsModelField, \"fieldId\" | \"type\">, parents?: string[]) => boolean;\n}\nexport class CmsEntryFieldFilterPathPlugin extends Plugin {\n public static override readonly type: string = \"cms-field-filter-path\";\n\n private readonly config: CmsEntryFieldFilterPathPluginParams;\n\n public get fieldType(): string {\n return this.config.fieldType;\n }\n\n public constructor(config: CmsEntryFieldFilterPathPluginParams) {\n super();\n\n this.config = config;\n\n /* We expect error here because we know that `this.constructor.type` is defined, but TS does not. */\n // @ts-expect-error\n this.name = `${this.constructor.type}-${this.config.fieldType}`;\n }\n\n public canUse(field: Pick<CmsModelField, \"fieldId\" | \"type\">, parents: string[]): boolean {\n if (field.type !== this.config.fieldType) {\n return false;\n } else if (this.config.canUse) {\n return this.config.canUse(field, parents);\n }\n const fieldId = this.config.fieldId;\n if (!fieldId || Array.isArray(fieldId) === false || fieldId.length === 0) {\n return true;\n }\n return fieldId.includes(field.fieldId);\n }\n\n public createPath(params: CreatePathCallableParams): string {\n if (typeof this.config.path === \"function\") {\n return this.config.path(params);\n } else if (typeof this.config.path === \"string\") {\n return this.config.path;\n }\n throw new WebinyError(`Missing path in \"${this.name}\" plugin.`);\n }\n}\n"],"names":["CmsEntryFieldFilterPathPlugin","Plugin","config","field","parents","fieldId","Array","params","WebinyError"],"mappings":";;AAiBO,MAAMA,sCAAsCC;;aACf,IAAI,GAAW;;IAI/C,IAAW,YAAoB;QAC3B,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS;IAChC;IAEA,YAAmBC,MAA2C,CAAE;QAC5D,KAAK;QAEL,IAAI,CAAC,MAAM,GAAGA;QAId,IAAI,CAAC,IAAI,GAAG,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE;IACnE;IAEO,OAAOC,KAA8C,EAAEC,OAAiB,EAAW;QACtF,IAAID,MAAM,IAAI,KAAK,IAAI,CAAC,MAAM,CAAC,SAAS,EACpC,OAAO;aACJ,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,EACzB,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAACA,OAAOC;QAErC,MAAMC,UAAU,IAAI,CAAC,MAAM,CAAC,OAAO;QACnC,IAAI,CAACA,WAAWC,AAA2B,UAA3BA,MAAM,OAAO,CAACD,YAAsBA,AAAmB,MAAnBA,QAAQ,MAAM,EAC9D,OAAO;QAEX,OAAOA,QAAQ,QAAQ,CAACF,MAAM,OAAO;IACzC;IAEO,WAAWI,MAAgC,EAAU;QACxD,IAAI,AAA4B,cAA5B,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,EACvB,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAACA;aACrB,IAAI,AAA4B,YAA5B,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,EAC9B,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI;QAE3B,MAAM,IAAIC,MAAY,CAAC,iBAAiB,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC;IAClE;AACJ"}
@@ -0,0 +1,39 @@
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
+ interface CmsEntryFieldFilterPluginParams<T = any> {
6
+ fieldType: string;
7
+ create: (params: CmsEntryFieldFilterPluginCreateParams<T>) => null | CmsEntryFieldFilterPluginCreateResponse | CmsEntryFieldFilterPluginCreateResponse[];
8
+ }
9
+ interface CmsEntryFieldFilterPluginCreateParams<T = any> {
10
+ key: string;
11
+ value: T;
12
+ field: Field;
13
+ fields: Record<string, Field>;
14
+ operation: string;
15
+ valueFilterRegistry: ValueFilterRegistry.Interface;
16
+ transformValuePlugins: Record<string, ICmsFieldFilterValueTransformPlugin>;
17
+ getFilterCreatePlugin: (type: string) => CmsEntryFieldFilterPlugin;
18
+ negate: boolean;
19
+ compareValue: any;
20
+ transformValue: <I = any, O = any>(value: I) => O;
21
+ }
22
+ export interface CmsEntryFieldFilterPluginCreateResponse {
23
+ field: Field;
24
+ path: string;
25
+ fieldPathId: string;
26
+ filter: ValueFilterRegistry.Filter;
27
+ negate: boolean;
28
+ compareValue: any;
29
+ transformValue: <I = any, O = any>(value: I) => O;
30
+ }
31
+ export declare class CmsEntryFieldFilterPlugin<T = any> extends Plugin {
32
+ static readonly type: string;
33
+ static readonly ALL: string;
34
+ private readonly config;
35
+ readonly fieldType: string;
36
+ constructor(config: CmsEntryFieldFilterPluginParams<T>);
37
+ create(params: CmsEntryFieldFilterPluginCreateParams<T>): CmsEntryFieldFilterPluginCreateResponse[] | CmsEntryFieldFilterPluginCreateResponse | null;
38
+ }
39
+ export {};