@webiny/api-headless-cms-storage 0.0.0-unstable.0d717d18dd
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.
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/cms/storageHelpers.d.ts +9 -0
- package/cms/storageHelpers.js +45 -0
- package/cms/storageHelpers.js.map +1 -0
- package/features/FilterRegistriesFeature.d.ts +4 -0
- package/features/FilterRegistriesFeature.js +39 -0
- package/features/FilterRegistriesFeature.js.map +1 -0
- package/features/fieldFilterCreate/FieldFilterCreateRegistry.d.ts +7 -0
- package/features/fieldFilterCreate/FieldFilterCreateRegistry.js +20 -0
- package/features/fieldFilterCreate/FieldFilterCreateRegistry.js.map +1 -0
- package/features/fieldFilterCreate/abstractions.d.ts +41 -0
- package/features/fieldFilterCreate/abstractions.js +5 -0
- package/features/fieldFilterCreate/abstractions.js.map +1 -0
- package/features/fieldFilterPath/FieldFilterPathRegistry.d.ts +6 -0
- package/features/fieldFilterPath/FieldFilterPathRegistry.js +14 -0
- package/features/fieldFilterPath/FieldFilterPathRegistry.js.map +1 -0
- package/features/fieldFilterPath/abstractions.d.ts +16 -0
- package/features/fieldFilterPath/abstractions.js +5 -0
- package/features/fieldFilterPath/abstractions.js.map +1 -0
- package/features/fieldFilterValueTransform/FieldFilterValueTransformRegistry.d.ts +6 -0
- package/features/fieldFilterValueTransform/FieldFilterValueTransformRegistry.js +14 -0
- package/features/fieldFilterValueTransform/FieldFilterValueTransformRegistry.js.map +1 -0
- package/features/fieldFilterValueTransform/abstractions.d.ts +14 -0
- package/features/fieldFilterValueTransform/abstractions.js +5 -0
- package/features/fieldFilterValueTransform/abstractions.js.map +1 -0
- package/features/fieldSorting/FieldSortingRegistry.d.ts +6 -0
- package/features/fieldSorting/FieldSortingRegistry.js +14 -0
- package/features/fieldSorting/FieldSortingRegistry.js.map +1 -0
- package/features/fieldSorting/abstractions.d.ts +40 -0
- package/features/fieldSorting/abstractions.js +5 -0
- package/features/fieldSorting/abstractions.js.map +1 -0
- package/filtering/expressions/createExpressions.d.ts +29 -0
- package/filtering/expressions/createExpressions.js +109 -0
- package/filtering/expressions/createExpressions.js.map +1 -0
- package/filtering/fields/createFields.d.ts +13 -0
- package/filtering/fields/createFields.js +81 -0
- package/filtering/fields/createFields.js.map +1 -0
- package/filtering/fields/extractSort.d.ts +17 -0
- package/filtering/fields/extractSort.js +59 -0
- package/filtering/fields/extractSort.js.map +1 -0
- package/filtering/fields/systemFields.d.ts +2 -0
- package/filtering/fields/systemFields.js +149 -0
- package/filtering/fields/systemFields.js.map +1 -0
- package/filtering/fields/types.d.ts +19 -0
- package/filtering/fields/types.js +0 -0
- package/filtering/filter.d.ts +19 -0
- package/filtering/filter.js +84 -0
- package/filtering/filter.js.map +1 -0
- package/filtering/fullTextSearch.d.ts +11 -0
- package/filtering/fullTextSearch.js +25 -0
- package/filtering/fullTextSearch.js.map +1 -0
- package/filtering/getValue.d.ts +1 -0
- package/filtering/getValue.js +37 -0
- package/filtering/getValue.js.map +1 -0
- package/filtering/mapPlugins.d.ts +8 -0
- package/filtering/mapPlugins.js +18 -0
- package/filtering/mapPlugins.js.map +1 -0
- package/filtering/plugins/defaultFilterCreate.d.ts +2 -0
- package/filtering/plugins/defaultFilterCreate.js +33 -0
- package/filtering/plugins/defaultFilterCreate.js.map +1 -0
- package/filtering/plugins/index.d.ts +1 -0
- package/filtering/plugins/index.js +13 -0
- package/filtering/plugins/index.js.map +1 -0
- package/filtering/plugins/objectFilterCreate.d.ts +2 -0
- package/filtering/plugins/objectFilterCreate.js +68 -0
- package/filtering/plugins/objectFilterCreate.js.map +1 -0
- package/filtering/plugins/refFilterCreate.d.ts +3 -0
- package/filtering/plugins/refFilterCreate.js +63 -0
- package/filtering/plugins/refFilterCreate.js.map +1 -0
- package/filtering/plugins/searchableJsonFilterCreate.d.ts +2 -0
- package/filtering/plugins/searchableJsonFilterCreate.js +56 -0
- package/filtering/plugins/searchableJsonFilterCreate.js.map +1 -0
- package/filtering/sort.d.ts +12 -0
- package/filtering/sort.js +41 -0
- package/filtering/sort.js.map +1 -0
- package/filtering/transform.d.ts +6 -0
- package/filtering/transform.js +7 -0
- package/filtering/transform.js.map +1 -0
- package/filtering/values.d.ts +2 -0
- package/filtering/values.js +15 -0
- package/filtering/values.js.map +1 -0
- package/filtering/where.d.ts +5 -0
- package/filtering/where.js +22 -0
- package/filtering/where.js.map +1 -0
- package/handlers/datetimeTransformHandler.d.ts +2 -0
- package/handlers/datetimeTransformHandler.js +34 -0
- package/handlers/datetimeTransformHandler.js.map +1 -0
- package/handlers/defaultFilterCreateHandler.d.ts +2 -0
- package/handlers/defaultFilterCreateHandler.js +27 -0
- package/handlers/defaultFilterCreateHandler.js.map +1 -0
- package/handlers/locationFolderIdPathHandler.d.ts +2 -0
- package/handlers/locationFolderIdPathHandler.js +18 -0
- package/handlers/locationFolderIdPathHandler.js.map +1 -0
- package/handlers/objectFilterCreateHandler.d.ts +2 -0
- package/handlers/objectFilterCreateHandler.js +62 -0
- package/handlers/objectFilterCreateHandler.js.map +1 -0
- package/handlers/plainObjectPathHandler.d.ts +2 -0
- package/handlers/plainObjectPathHandler.js +14 -0
- package/handlers/plainObjectPathHandler.js.map +1 -0
- package/handlers/refFilterCreateHandler.d.ts +2 -0
- package/handlers/refFilterCreateHandler.js +57 -0
- package/handlers/refFilterCreateHandler.js.map +1 -0
- package/handlers/searchableJsonFilterCreateHandler.d.ts +2 -0
- package/handlers/searchableJsonFilterCreateHandler.js +43 -0
- package/handlers/searchableJsonFilterCreateHandler.js.map +1 -0
- package/index.d.ts +24 -0
- package/index.js +19 -0
- package/package.json +36 -0
- package/path/locationFolderId.d.ts +2 -0
- package/path/locationFolderId.js +21 -0
- package/path/locationFolderId.js.map +1 -0
- package/path/plainObject.d.ts +2 -0
- package/path/plainObject.js +16 -0
- package/path/plainObject.js.map +1 -0
- package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +23 -0
- package/plugins/CmsEntryFieldFilterPathPlugin.js +30 -0
- package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -0
- package/plugins/CmsEntryFieldFilterPlugin.d.ts +39 -0
- package/plugins/CmsEntryFieldFilterPlugin.js +20 -0
- package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -0
- package/plugins/CmsEntryFieldSortingPlugin.d.ts +37 -0
- package/plugins/CmsEntryFieldSortingPlugin.js +20 -0
- package/plugins/CmsEntryFieldSortingPlugin.js.map +1 -0
- package/plugins/CmsFieldFilterValueTransformPlugin.d.ts +21 -0
- package/plugins/CmsFieldFilterValueTransformPlugin.js +19 -0
- package/plugins/CmsFieldFilterValueTransformPlugin.js.map +1 -0
- package/plugins/index.d.ts +7 -0
- package/plugins/index.js +4 -0
- package/transforms/datetime.d.ts +2 -0
- package/transforms/datetime.js +37 -0
- package/transforms/datetime.js.map +1 -0
|
@@ -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;gBAC3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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,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,M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;YAEA,OAAOV;QACX;IACJ"}
|
|
@@ -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,GAA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"}
|
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,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@webiny/api-headless-cms-storage",
|
|
3
|
+
"version": "0.0.0-unstable.0d717d18dd",
|
|
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.0d717d18dd",
|
|
14
|
+
"@webiny/api-headless-cms": "0.0.0-unstable.0d717d18dd",
|
|
15
|
+
"@webiny/db-utils": "0.0.0-unstable.0d717d18dd",
|
|
16
|
+
"@webiny/di": "1.0.2",
|
|
17
|
+
"@webiny/error": "0.0.0-unstable.0d717d18dd",
|
|
18
|
+
"@webiny/feature": "0.0.0-unstable.0d717d18dd",
|
|
19
|
+
"@webiny/plugins": "0.0.0-unstable.0d717d18dd",
|
|
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.0d717d18dd",
|
|
26
|
+
"@webiny/project-utils": "0.0.0-unstable.0d717d18dd",
|
|
27
|
+
"typescript": "7.0.2",
|
|
28
|
+
"vitest": "4.1.10"
|
|
29
|
+
},
|
|
30
|
+
"webiny": {
|
|
31
|
+
"publishFrom": "dist"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -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
|
+
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;YACJ,IAAI,CAACK,SAAS,QACjB,OAAO;YAEX,OAAOA,AAAe,sBAAfA,OAAO,CAAC,EAAE;QACrB;IACJ"}
|
|
@@ -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
|
+
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
|
+
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;QACJ,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;QACrB,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 {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Plugin } from "@webiny/plugins";
|
|
2
|
+
class CmsEntryFieldFilterPlugin extends Plugin {
|
|
3
|
+
static{
|
|
4
|
+
this.type = "cms.dynamodb.entry.field.filter";
|
|
5
|
+
}
|
|
6
|
+
static{
|
|
7
|
+
this.ALL = "*";
|
|
8
|
+
}
|
|
9
|
+
constructor(config){
|
|
10
|
+
super();
|
|
11
|
+
this.config = config;
|
|
12
|
+
this.fieldType = this.config.fieldType;
|
|
13
|
+
}
|
|
14
|
+
create(params) {
|
|
15
|
+
return this.config.create(params);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export { CmsEntryFieldFilterPlugin };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=CmsEntryFieldFilterPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugins/CmsEntryFieldFilterPlugin.js","sources":["../../src/plugins/CmsEntryFieldFilterPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport type { Field } from \"~/filtering/fields/types.js\";\nimport type { ICmsFieldFilterValueTransformPlugin } from \"./CmsFieldFilterValueTransformPlugin.js\";\nimport { ValueFilterRegistry } from \"@webiny/db-utils\";\n\n/*\n * This plugin is used to create the filter.\n * Internally we have default one + the one for the reference field - because it is actually an object when filtering.\n */\n\ninterface CmsEntryFieldFilterPluginParams<T = any> {\n fieldType: string;\n create: (\n params: CmsEntryFieldFilterPluginCreateParams<T>\n ) => null | CmsEntryFieldFilterPluginCreateResponse | CmsEntryFieldFilterPluginCreateResponse[];\n}\n\ninterface CmsEntryFieldFilterPluginCreateParams<T = any> {\n key: string;\n value: T;\n field: Field;\n fields: Record<string, Field>;\n operation: string;\n valueFilterRegistry: ValueFilterRegistry.Interface;\n transformValuePlugins: Record<string, ICmsFieldFilterValueTransformPlugin>;\n getFilterCreatePlugin: (type: string) => CmsEntryFieldFilterPlugin;\n negate: boolean;\n compareValue: any;\n transformValue: <I = any, O = any>(value: I) => O;\n}\n\nexport interface CmsEntryFieldFilterPluginCreateResponse {\n field: Field;\n path: string;\n fieldPathId: string;\n filter: ValueFilterRegistry.Filter;\n negate: boolean;\n compareValue: any;\n transformValue: <I = any, O = any>(value: I) => O;\n}\n\nexport class CmsEntryFieldFilterPlugin<T = any> extends Plugin {\n public static override readonly type: string = \"cms.dynamodb.entry.field.filter\";\n public static readonly ALL: string = \"*\";\n\n private readonly config: CmsEntryFieldFilterPluginParams<T>;\n\n public readonly fieldType: string;\n\n public constructor(config: CmsEntryFieldFilterPluginParams<T>) {\n super();\n this.config = config;\n this.fieldType = this.config.fieldType;\n }\n\n public create(params: CmsEntryFieldFilterPluginCreateParams<T>) {\n return this.config.create(params);\n }\n}\n"],"names":["CmsEntryFieldFilterPlugin","Plugin","config","params"],"mappings":";AAyCO,MAAMA,kCAA2CC;;aACpB,IAAI,GAAW;;;aACxB,GAAG,GAAW;;IAMrC,YAAmBC,MAA0C,CAAE;QAC3D,KAAK;QACL,IAAI,CAAC,MAAM,GAAGA;QACd,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS;IAC1C;IAEO,OAAOC,MAAgD,EAAE;QAC5D,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAACA;IAC9B;AACJ"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Plugin } from "@webiny/plugins";
|
|
2
|
+
import type { Field } from "../filtering/fields/types.js";
|
|
3
|
+
import type { CmsModel } from "@webiny/api-headless-cms/types/index.js";
|
|
4
|
+
interface CmsEntryFieldSortingPluginCanUseParams {
|
|
5
|
+
model: CmsModel;
|
|
6
|
+
field?: Field;
|
|
7
|
+
fieldId: string;
|
|
8
|
+
order: "ASC" | "DESC";
|
|
9
|
+
sortBy: string;
|
|
10
|
+
}
|
|
11
|
+
interface CmsEntryFieldSortingPluginCreateSortParams {
|
|
12
|
+
model: CmsModel;
|
|
13
|
+
fieldId: string;
|
|
14
|
+
order: "ASC" | "DESC";
|
|
15
|
+
sortBy: string;
|
|
16
|
+
fields: Record<string, Field>;
|
|
17
|
+
field?: Field;
|
|
18
|
+
}
|
|
19
|
+
interface CmsEntryFieldSortingPluginCreateSortResult {
|
|
20
|
+
valuePath: string;
|
|
21
|
+
reverse: boolean;
|
|
22
|
+
fieldId: string;
|
|
23
|
+
field: Field;
|
|
24
|
+
}
|
|
25
|
+
interface CmsEntryFieldSortingPluginConfig {
|
|
26
|
+
createSort: (params: CmsEntryFieldSortingPluginCreateSortParams) => CmsEntryFieldSortingPluginCreateSortResult;
|
|
27
|
+
canUse: (params: CmsEntryFieldSortingPluginCanUseParams) => boolean;
|
|
28
|
+
}
|
|
29
|
+
export declare class CmsEntryFieldSortingPlugin extends Plugin {
|
|
30
|
+
static readonly type: string;
|
|
31
|
+
private readonly config;
|
|
32
|
+
constructor(config: CmsEntryFieldSortingPluginConfig);
|
|
33
|
+
canUse(params: CmsEntryFieldSortingPluginCanUseParams): boolean;
|
|
34
|
+
createSort(params: CmsEntryFieldSortingPluginCreateSortParams): CmsEntryFieldSortingPluginCreateSortResult;
|
|
35
|
+
}
|
|
36
|
+
export declare const createCmsEntryFieldSortingPlugin: (config: CmsEntryFieldSortingPluginConfig) => CmsEntryFieldSortingPlugin;
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Plugin } from "@webiny/plugins";
|
|
2
|
+
class CmsEntryFieldSortingPlugin extends Plugin {
|
|
3
|
+
static{
|
|
4
|
+
this.type = "cms.entry.field.sorting";
|
|
5
|
+
}
|
|
6
|
+
constructor(config){
|
|
7
|
+
super();
|
|
8
|
+
this.config = config;
|
|
9
|
+
}
|
|
10
|
+
canUse(params) {
|
|
11
|
+
return this.config.canUse(params);
|
|
12
|
+
}
|
|
13
|
+
createSort(params) {
|
|
14
|
+
return this.config.createSort(params);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
const createCmsEntryFieldSortingPlugin = (config)=>new CmsEntryFieldSortingPlugin(config);
|
|
18
|
+
export { CmsEntryFieldSortingPlugin, createCmsEntryFieldSortingPlugin };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=CmsEntryFieldSortingPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugins/CmsEntryFieldSortingPlugin.js","sources":["../../src/plugins/CmsEntryFieldSortingPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport type { Field } from \"~/filtering/fields/types.js\";\nimport type { CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\n\ninterface CmsEntryFieldSortingPluginCanUseParams {\n model: CmsModel;\n field?: Field;\n fieldId: string;\n order: \"ASC\" | \"DESC\";\n /*\n * Combination of fieldId and sortBy.\n *\n * example: id_ASC or createdBy_DESC\n */\n sortBy: string;\n}\n\ninterface CmsEntryFieldSortingPluginCreateSortParams {\n model: CmsModel;\n fieldId: string;\n order: \"ASC\" | \"DESC\";\n sortBy: string;\n fields: Record<string, Field>;\n field?: Field;\n}\n\ninterface CmsEntryFieldSortingPluginCreateSortResult {\n valuePath: string;\n reverse: boolean;\n fieldId: string;\n field: Field;\n}\n\ninterface CmsEntryFieldSortingPluginConfig {\n createSort: (\n params: CmsEntryFieldSortingPluginCreateSortParams\n ) => CmsEntryFieldSortingPluginCreateSortResult;\n canUse: (params: CmsEntryFieldSortingPluginCanUseParams) => boolean;\n}\n\nexport class CmsEntryFieldSortingPlugin extends Plugin {\n public static override readonly type: string = \"cms.entry.field.sorting\";\n private readonly config: CmsEntryFieldSortingPluginConfig;\n\n public constructor(config: CmsEntryFieldSortingPluginConfig) {\n super();\n this.config = config;\n }\n\n public canUse(params: CmsEntryFieldSortingPluginCanUseParams): boolean {\n return this.config.canUse(params);\n }\n\n public createSort(\n params: CmsEntryFieldSortingPluginCreateSortParams\n ): CmsEntryFieldSortingPluginCreateSortResult {\n return this.config.createSort(params);\n }\n}\n\nexport const createCmsEntryFieldSortingPlugin = (config: CmsEntryFieldSortingPluginConfig) => {\n return new CmsEntryFieldSortingPlugin(config);\n};\n"],"names":["CmsEntryFieldSortingPlugin","Plugin","config","params","createCmsEntryFieldSortingPlugin"],"mappings":";AAwCO,MAAMA,mCAAmCC;;aACZ,IAAI,GAAW;;IAG/C,YAAmBC,MAAwC,CAAE;QACzD,KAAK;QACL,IAAI,CAAC,MAAM,GAAGA;IAClB;IAEO,OAAOC,MAA8C,EAAW;QACnE,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAACA;IAC9B;IAEO,WACHA,MAAkD,EACR;QAC1C,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,CAACA;IAClC;AACJ;AAEO,MAAMC,mCAAmC,CAACF,SACtC,IAAIF,2BAA2BE"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Plugin } from "@webiny/plugins";
|
|
2
|
+
import type { CmsModelField } from "@webiny/api-headless-cms/types/index.js";
|
|
3
|
+
import type { Plugin as IPlugin } from "@webiny/plugins/types.js";
|
|
4
|
+
export interface CmsFieldFilterValueTransformParams {
|
|
5
|
+
field: Partial<CmsModelField> & Pick<CmsModelField, "id" | "storageId" | "fieldId" | "settings">;
|
|
6
|
+
value: any;
|
|
7
|
+
}
|
|
8
|
+
export interface ICmsFieldFilterValueTransformPlugin extends IPlugin {
|
|
9
|
+
type: "cms-field-filter-value-transform";
|
|
10
|
+
fieldType: string;
|
|
11
|
+
transform: (params: CmsFieldFilterValueTransformParams) => any;
|
|
12
|
+
}
|
|
13
|
+
type CmsFieldFilterValueTransformPluginParams = Omit<ICmsFieldFilterValueTransformPlugin, "type">;
|
|
14
|
+
export declare class CmsFieldFilterValueTransformPlugin extends Plugin implements Omit<ICmsFieldFilterValueTransformPlugin, "type"> {
|
|
15
|
+
static type: string;
|
|
16
|
+
private readonly config;
|
|
17
|
+
get fieldType(): string;
|
|
18
|
+
get transform(): CmsFieldFilterValueTransformPluginParams["transform"];
|
|
19
|
+
constructor(config: CmsFieldFilterValueTransformPluginParams);
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Plugin } from "@webiny/plugins";
|
|
2
|
+
class CmsFieldFilterValueTransformPlugin extends Plugin {
|
|
3
|
+
static{
|
|
4
|
+
this.type = "cms-field-filter-value-transform";
|
|
5
|
+
}
|
|
6
|
+
get fieldType() {
|
|
7
|
+
return this.config.fieldType;
|
|
8
|
+
}
|
|
9
|
+
get transform() {
|
|
10
|
+
return this.config.transform;
|
|
11
|
+
}
|
|
12
|
+
constructor(config){
|
|
13
|
+
super();
|
|
14
|
+
this.config = config;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export { CmsFieldFilterValueTransformPlugin };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=CmsFieldFilterValueTransformPlugin.js.map
|