@webiny/api-headless-cms-storage 0.0.0-unstable.9f53ea597d
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 +11 -0
- package/cms/storageHelpers.js +50 -0
- package/cms/storageHelpers.js.map +1 -0
- package/filtering/expressions/createExpressions.d.ts +27 -0
- package/filtering/expressions/createExpressions.js +122 -0
- package/filtering/expressions/createExpressions.js.map +1 -0
- package/filtering/fields/createFields.d.ts +11 -0
- package/filtering/fields/createFields.js +93 -0
- package/filtering/fields/createFields.js.map +1 -0
- package/filtering/fields/extractSort.d.ts +17 -0
- package/filtering/fields/extractSort.js +60 -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 +17 -0
- package/filtering/filter.js +83 -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/index.d.ts +19 -0
- package/index.js +14 -0
- package/package.json +34 -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,41 @@
|
|
|
1
|
+
import error from "@webiny/error";
|
|
2
|
+
import sortBy from "lodash/sortBy.js";
|
|
3
|
+
import { extractSort } from "./fields/extractSort.js";
|
|
4
|
+
import * as __rspack_external_dot_prop_0ebbd169 from "dot-prop";
|
|
5
|
+
const sort_sort = (params)=>{
|
|
6
|
+
const { model, items, sort = [], fields, plugins } = params;
|
|
7
|
+
if (items.length <= 1) return items;
|
|
8
|
+
if (0 === sort.length) sort.push("savedOn_DESC");
|
|
9
|
+
else if (sort.length > 1) throw new error("Sorting is limited to a single field.", "SORT_MULTIPLE_FIELDS_ERROR", {
|
|
10
|
+
sort
|
|
11
|
+
});
|
|
12
|
+
const [firstSort] = sort;
|
|
13
|
+
if (!firstSort) throw new error("Empty sort array item.", "SORT_EMPTY_ERROR", {
|
|
14
|
+
sort
|
|
15
|
+
});
|
|
16
|
+
const { fieldId, field, valuePath, reverse } = extractSort({
|
|
17
|
+
model,
|
|
18
|
+
sortBy: firstSort,
|
|
19
|
+
fields,
|
|
20
|
+
plugins
|
|
21
|
+
});
|
|
22
|
+
const itemsToSort = items.map((item)=>({
|
|
23
|
+
id: item.id,
|
|
24
|
+
value: field.transform(__rspack_external_dot_prop_0ebbd169.getProperty(item, valuePath))
|
|
25
|
+
}));
|
|
26
|
+
const sortedItems = sortBy(itemsToSort, "value");
|
|
27
|
+
const newItems = sortedItems.map((s)=>{
|
|
28
|
+
const item = items.find((i)=>i.id === s.id);
|
|
29
|
+
if (item) return item;
|
|
30
|
+
throw new error("Could not find item by given id after the sorting.", "SORTING_ITEMS_ERROR", {
|
|
31
|
+
id: s.id,
|
|
32
|
+
sortingBy: fieldId,
|
|
33
|
+
reverse
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
if (!reverse) return newItems;
|
|
37
|
+
return newItems.reverse();
|
|
38
|
+
};
|
|
39
|
+
export { sort_sort as sort };
|
|
40
|
+
|
|
41
|
+
//# sourceMappingURL=sort.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filtering/sort.js","sources":["../../src/filtering/sort.ts"],"sourcesContent":["import type { CmsEntry, CmsEntryValues, CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport WebinyError from \"@webiny/error\";\nimport * as dotProp from \"dot-prop\";\nimport lodashSortBy from \"lodash/sortBy.js\";\nimport { extractSort } from \"./fields/extractSort.js\";\nimport type { Field } from \"./fields/types.js\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\n\ninterface Params<T extends CmsEntryValues = CmsEntryValues> {\n model: CmsModel;\n items: CmsEntry<T>[];\n sort?: string[];\n fields: Record<string, Field>;\n plugins: PluginsContainer;\n}\n\ninterface SortedItem {\n id: string;\n value: any;\n}\n\nexport const sort = <T extends CmsEntryValues = CmsEntryValues>(\n params: Params<T>\n): CmsEntry<T>[] => {\n const { model, items, sort = [], fields, plugins } = params;\n if (items.length <= 1) {\n return items;\n } else if (sort.length === 0) {\n sort.push(\"savedOn_DESC\");\n } else if (sort.length > 1) {\n throw new WebinyError(\n \"Sorting is limited to a single field.\",\n \"SORT_MULTIPLE_FIELDS_ERROR\",\n {\n sort\n }\n );\n }\n const [firstSort] = sort;\n if (!firstSort) {\n throw new WebinyError(\"Empty sort array item.\", \"SORT_EMPTY_ERROR\", {\n sort\n });\n }\n\n const { fieldId, field, valuePath, reverse } = extractSort({\n model,\n sortBy: firstSort,\n fields,\n plugins\n });\n\n const itemsToSort = items.map(item => {\n return {\n id: item.id,\n value: field.transform(dotProp.getProperty(item, valuePath))\n };\n });\n const sortedItems: SortedItem[] = lodashSortBy(itemsToSort, \"value\");\n const newItems = sortedItems.map(s => {\n const item = items.find(i => i.id === s.id);\n if (item) {\n return item;\n }\n /* This is impossible to happen because sorting items does not remove the items. BUT, we need to have this check just in case for development purposes. */\n throw new WebinyError(\n \"Could not find item by given id after the sorting.\",\n \"SORTING_ITEMS_ERROR\",\n {\n id: s.id,\n sortingBy: fieldId,\n reverse\n }\n );\n });\n if (!reverse) {\n return newItems;\n }\n return newItems.reverse();\n};\n"],"names":["sort","params","model","items","fields","plugins","WebinyError","firstSort","fieldId","field","valuePath","reverse","extractSort","itemsToSort","item","dotProp","sortedItems","lodashSortBy","newItems","s","i"],"mappings":";;;;AAqBO,MAAMA,YAAO,CAChBC;IAEA,MAAM,EAAEC,KAAK,EAAEC,KAAK,EAAEH,OAAO,EAAE,EAAEI,MAAM,EAAEC,OAAO,EAAE,GAAGJ;IACrD,IAAIE,MAAM,MAAM,IAAI,GAChB,OAAOA;IACJ,IAAIH,AAAgB,MAAhBA,KAAK,MAAM,EAClBA,KAAK,IAAI,CAAC;SACP,IAAIA,KAAK,MAAM,GAAG,GACrB,MAAM,IAAIM,MACN,yCACA,8BACA;QACIN;IACJ;IAGR,MAAM,CAACO,UAAU,GAAGP;IACpB,IAAI,CAACO,WACD,MAAM,IAAID,MAAY,0BAA0B,oBAAoB;QAChEN;IACJ;IAGJ,MAAM,EAAEQ,OAAO,EAAEC,KAAK,EAAEC,SAAS,EAAEC,OAAO,EAAE,GAAGC,YAAY;QACvDV;QACA,QAAQK;QACRH;QACAC;IACJ;IAEA,MAAMQ,cAAcV,MAAM,GAAG,CAACW,CAAAA,OACnB;YACH,IAAIA,KAAK,EAAE;YACX,OAAOL,MAAM,SAAS,CAACM,oCAAAA,WAAmB,CAACD,MAAMJ;QACrD;IAEJ,MAAMM,cAA4BC,OAAaJ,aAAa;IAC5D,MAAMK,WAAWF,YAAY,GAAG,CAACG,CAAAA;QAC7B,MAAML,OAAOX,MAAM,IAAI,CAACiB,CAAAA,IAAKA,EAAE,EAAE,KAAKD,EAAE,EAAE;QAC1C,IAAIL,MACA,OAAOA;QAGX,MAAM,IAAIR,MACN,sDACA,uBACA;YACI,IAAIa,EAAE,EAAE;YACR,WAAWX;YACXG;QACJ;IAER;IACA,IAAI,CAACA,SACD,OAAOO;IAEX,OAAOA,SAAS,OAAO;AAC3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filtering/transform.js","sources":["../../src/filtering/transform.ts"],"sourcesContent":["import type { Field } from \"./fields/types.js\";\n\ninterface Params extends Pick<Field, \"transform\"> {\n value: any;\n}\nexport const transformValue = ({ value, transform }: Params): any => {\n if (Array.isArray(value)) {\n return value.map(v => transform(v));\n }\n return transform(value);\n};\n"],"names":["transformValue","value","transform","Array","v"],"mappings":"AAKO,MAAMA,iBAAiB,CAAC,EAAEC,KAAK,EAAEC,SAAS,EAAU;IACvD,IAAIC,MAAM,OAAO,CAACF,QACd,OAAOA,MAAM,GAAG,CAACG,CAAAA,IAAKF,UAAUE;IAEpC,OAAOF,UAAUD;AACrB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import error from "@webiny/error";
|
|
2
|
+
const getWhereValues = (value, condition)=>{
|
|
3
|
+
const values = value;
|
|
4
|
+
if (Array.isArray(values)) {
|
|
5
|
+
if (0 === values.length) throw new error(`Trying to run filtering with "${condition}", but the value sent is empty array.`, `MALFORMED_${condition}_CONDITION`, {
|
|
6
|
+
value
|
|
7
|
+
});
|
|
8
|
+
} else throw new error(`Trying to run filtering with "${condition}", but the value sent is not an array.`, `MALFORMED_${condition}_CONDITION`, {
|
|
9
|
+
value
|
|
10
|
+
});
|
|
11
|
+
return values;
|
|
12
|
+
};
|
|
13
|
+
export { getWhereValues };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=values.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filtering/values.js","sources":["../../src/filtering/values.ts"],"sourcesContent":["import type { CmsEntryListWhere } from \"@webiny/api-headless-cms/types/index.js\";\nimport WebinyError from \"@webiny/error\";\n\nexport const getWhereValues = (value: unknown, condition: \"AND\" | \"OR\") => {\n const values = value as CmsEntryListWhere[] | undefined;\n if (!Array.isArray(values)) {\n throw new WebinyError(\n `Trying to run filtering with \"${condition}\", but the value sent is not an array.`,\n `MALFORMED_${condition}_CONDITION`,\n {\n value\n }\n );\n } else if (values.length === 0) {\n throw new WebinyError(\n `Trying to run filtering with \"${condition}\", but the value sent is empty array.`,\n `MALFORMED_${condition}_CONDITION`,\n {\n value\n }\n );\n }\n return values;\n};\n"],"names":["getWhereValues","value","condition","values","Array","WebinyError"],"mappings":";AAGO,MAAMA,iBAAiB,CAACC,OAAgBC;IAC3C,MAAMC,SAASF;IACf,IAAKG,MAAM,OAAO,CAACD,SAQZ;QAAA,IAAIA,AAAkB,MAAlBA,OAAO,MAAM,EACpB,MAAM,IAAIE,MACN,CAAC,8BAA8B,EAAEH,UAAU,qCAAqC,CAAC,EACjF,CAAC,UAAU,EAAEA,UAAU,UAAU,CAAC,EAClC;YACID;QACJ;IAER,OAfI,MAAM,IAAII,MACN,CAAC,8BAA8B,EAAEH,UAAU,sCAAsC,CAAC,EAClF,CAAC,UAAU,EAAEA,UAAU,UAAU,CAAC,EAClC;QACID;IACJ;IAWR,OAAOE;AACX"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const extractWhereParams = (key)=>{
|
|
2
|
+
const isWbyAco = null !== key.match("wbyAco_");
|
|
3
|
+
const result = key.replace("wbyAco_", "").split("_");
|
|
4
|
+
const fieldId = result.shift();
|
|
5
|
+
if (!fieldId) return null;
|
|
6
|
+
const rawOp = 0 === result.length ? "eq" : result.join("_");
|
|
7
|
+
if ("not" === rawOp) return {
|
|
8
|
+
fieldId,
|
|
9
|
+
operation: "eq",
|
|
10
|
+
negate: true
|
|
11
|
+
};
|
|
12
|
+
const negate = null !== rawOp.match("not_");
|
|
13
|
+
const operation = rawOp.replace("not_", "");
|
|
14
|
+
return {
|
|
15
|
+
fieldId: isWbyAco ? `wbyAco_${fieldId}` : fieldId,
|
|
16
|
+
operation,
|
|
17
|
+
negate
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export { extractWhereParams };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=where.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filtering/where.js","sources":["../../src/filtering/where.ts"],"sourcesContent":["export const extractWhereParams = (key: string) => {\n const isWbyAco = key.match(\"wbyAco_\") !== null;\n const result = key.replace(\"wbyAco_\", \"\").split(\"_\");\n const fieldId = result.shift();\n if (!fieldId) {\n return null;\n }\n const rawOp = result.length === 0 ? \"eq\" : result.join(\"_\");\n /* When rawOp is not, it means it is equal negated so just return that. */\n if (rawOp === \"not\") {\n return {\n fieldId,\n operation: \"eq\",\n negate: true\n };\n }\n const negate = rawOp.match(\"not_\") !== null;\n const operation = rawOp.replace(\"not_\", \"\");\n return {\n fieldId: isWbyAco ? `wbyAco_${fieldId}` : fieldId,\n operation,\n negate\n };\n};\n"],"names":["extractWhereParams","key","isWbyAco","result","fieldId","rawOp","negate","operation"],"mappings":"AAAO,MAAMA,qBAAqB,CAACC;IAC/B,MAAMC,WAAWD,AAAyB,SAAzBA,IAAI,KAAK,CAAC;IAC3B,MAAME,SAASF,IAAI,OAAO,CAAC,WAAW,IAAI,KAAK,CAAC;IAChD,MAAMG,UAAUD,OAAO,KAAK;IAC5B,IAAI,CAACC,SACD,OAAO;IAEX,MAAMC,QAAQF,AAAkB,MAAlBA,OAAO,MAAM,GAAS,OAAOA,OAAO,IAAI,CAAC;IAEvD,IAAIE,AAAU,UAAVA,OACA,OAAO;QACHD;QACA,WAAW;QACX,QAAQ;IACZ;IAEJ,MAAME,SAASD,AAAwB,SAAxBA,MAAM,KAAK,CAAC;IAC3B,MAAME,YAAYF,MAAM,OAAO,CAAC,QAAQ;IACxC,OAAO;QACH,SAASH,WAAW,CAAC,OAAO,EAAEE,SAAS,GAAGA;QAC1CG;QACAD;IACJ;AACJ"}
|
package/index.d.ts
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 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";
|
package/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
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";
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@webiny/api-headless-cms-storage",
|
|
3
|
+
"version": "0.0.0-unstable.9f53ea597d",
|
|
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.9f53ea597d",
|
|
14
|
+
"@webiny/api-headless-cms": "0.0.0-unstable.9f53ea597d",
|
|
15
|
+
"@webiny/db-utils": "0.0.0-unstable.9f53ea597d",
|
|
16
|
+
"@webiny/error": "0.0.0-unstable.9f53ea597d",
|
|
17
|
+
"@webiny/plugins": "0.0.0-unstable.9f53ea597d",
|
|
18
|
+
"date-fns": "4.4.0",
|
|
19
|
+
"dot-prop": "10.2.0",
|
|
20
|
+
"lodash": "4.18.1"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@webiny/build-tools": "0.0.0-unstable.9f53ea597d",
|
|
24
|
+
"@webiny/project-utils": "0.0.0-unstable.9f53ea597d",
|
|
25
|
+
"typescript": "7.0.2",
|
|
26
|
+
"vitest": "4.1.10"
|
|
27
|
+
},
|
|
28
|
+
"webiny": {
|
|
29
|
+
"publishFrom": "dist"
|
|
30
|
+
},
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugins/CmsFieldFilterValueTransformPlugin.js","sources":["../../src/plugins/CmsFieldFilterValueTransformPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport type { CmsModelField } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { Plugin as IPlugin } from \"@webiny/plugins/types.js\";\n\nexport interface CmsFieldFilterValueTransformParams {\n /* A field which value we are transforming. */\n field: Partial<CmsModelField> &\n Pick<CmsModelField, \"id\" | \"storageId\" | \"fieldId\" | \"settings\">;\n value: any;\n}\n\nexport interface ICmsFieldFilterValueTransformPlugin extends IPlugin {\n /* A plugin type. */\n type: \"cms-field-filter-value-transform\";\n /* A field type this plugin is for. */\n fieldType: string;\n /* Transform method which expect field definition and value to transform. */\n transform: (params: CmsFieldFilterValueTransformParams) => any;\n}\n\ntype CmsFieldFilterValueTransformPluginParams = Omit<ICmsFieldFilterValueTransformPlugin, \"type\">;\n\nexport class CmsFieldFilterValueTransformPlugin\n extends Plugin\n implements Omit<ICmsFieldFilterValueTransformPlugin, \"type\">\n{\n public static override type = \"cms-field-filter-value-transform\";\n\n private readonly config: CmsFieldFilterValueTransformPluginParams;\n\n public get fieldType(): string {\n return this.config.fieldType;\n }\n\n public get transform(): CmsFieldFilterValueTransformPluginParams[\"transform\"] {\n return this.config.transform;\n }\n\n public constructor(config: CmsFieldFilterValueTransformPluginParams) {\n super();\n this.config = config;\n }\n}\n"],"names":["CmsFieldFilterValueTransformPlugin","Plugin","config"],"mappings":";AAsBO,MAAMA,2CACDC;;aAGe,IAAI,GAAG;;IAI9B,IAAW,YAAoB;QAC3B,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS;IAChC;IAEA,IAAW,YAAmE;QAC1E,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS;IAChC;IAEA,YAAmBC,MAAgD,CAAE;QACjE,KAAK;QACL,IAAI,CAAC,MAAM,GAAGA;IAClB;AACJ"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { CmsEntryFieldFilterPathPlugin } from "./CmsEntryFieldFilterPathPlugin.js";
|
|
2
|
+
export type { CreatePathCallable } from "./CmsEntryFieldFilterPathPlugin.js";
|
|
3
|
+
export { CmsEntryFieldSortingPlugin, createCmsEntryFieldSortingPlugin } from "./CmsEntryFieldSortingPlugin.js";
|
|
4
|
+
export { CmsEntryFieldFilterPlugin } from "./CmsEntryFieldFilterPlugin.js";
|
|
5
|
+
export type { CmsEntryFieldFilterPluginCreateResponse } from "./CmsEntryFieldFilterPlugin.js";
|
|
6
|
+
export { CmsFieldFilterValueTransformPlugin } from "./CmsFieldFilterValueTransformPlugin.js";
|
|
7
|
+
export type { ICmsFieldFilterValueTransformPlugin } from "./CmsFieldFilterValueTransformPlugin.js";
|
package/plugins/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { CmsEntryFieldFilterPathPlugin } from "./CmsEntryFieldFilterPathPlugin.js";
|
|
2
|
+
export { CmsEntryFieldSortingPlugin, createCmsEntryFieldSortingPlugin } from "./CmsEntryFieldSortingPlugin.js";
|
|
3
|
+
export { CmsEntryFieldFilterPlugin } from "./CmsEntryFieldFilterPlugin.js";
|
|
4
|
+
export { CmsFieldFilterValueTransformPlugin } from "./CmsFieldFilterValueTransformPlugin.js";
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { parseISO } from "date-fns";
|
|
2
|
+
import { CmsFieldFilterValueTransformPlugin } from "../plugins/CmsFieldFilterValueTransformPlugin.js";
|
|
3
|
+
const transformTime = (value)=>{
|
|
4
|
+
if (null == value) throw new Error("Time value is null or undefined.");
|
|
5
|
+
if ("boolean" == typeof value || "" === value || Array.isArray(value)) throw new Error("Field value must be a string because field is defined as time.");
|
|
6
|
+
const converted = Number(`${value}`);
|
|
7
|
+
if ("number" == typeof value || false === isNaN(converted)) return Number(value);
|
|
8
|
+
if ("string" != typeof value) throw new Error("Field value must be a string because field is defined as time.");
|
|
9
|
+
const [time, milliseconds = 0] = value.split(".");
|
|
10
|
+
const values = time.split(":").map(Number);
|
|
11
|
+
if (values.length < 2) throw new Error("Time must contain at least hours and minutes.");
|
|
12
|
+
const [hours, minutes, seconds = 0] = values;
|
|
13
|
+
return (60 * hours * 60 + 60 * minutes + seconds) * 1000 + Number(milliseconds);
|
|
14
|
+
};
|
|
15
|
+
const transformDateTime = (value)=>{
|
|
16
|
+
if (null == value) return null;
|
|
17
|
+
if ("string" == typeof value) {
|
|
18
|
+
const parsedDateTime = parseISO(value).getTime();
|
|
19
|
+
if (false === isNaN(parsedDateTime)) return parsedDateTime;
|
|
20
|
+
} else if (value instanceof Date || "function" == typeof value?.getTime) return value.getTime();
|
|
21
|
+
console.warn("Could not parse given dateTime value.", "PARSE_DATE_ERROR", {
|
|
22
|
+
value
|
|
23
|
+
});
|
|
24
|
+
return null;
|
|
25
|
+
};
|
|
26
|
+
const createDatetimeTransformValuePlugin = ()=>new CmsFieldFilterValueTransformPlugin({
|
|
27
|
+
name: "cms-field-value-filter-transform-datetime",
|
|
28
|
+
fieldType: "datetime",
|
|
29
|
+
transform: ({ field, value })=>{
|
|
30
|
+
const { type } = field.settings || {};
|
|
31
|
+
if ("time" === type) return transformTime(value);
|
|
32
|
+
return transformDateTime(value);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
export { createDatetimeTransformValuePlugin };
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=datetime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transforms/datetime.js","sources":["../../src/transforms/datetime.ts"],"sourcesContent":["/* File is @internal. */\nimport { parseISO } from \"date-fns\";\nimport {\n CmsFieldFilterValueTransformPlugin,\n CmsFieldFilterValueTransformParams\n} from \"../plugins/CmsFieldFilterValueTransformPlugin.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 /* This is for the time format, eg. 12:36:25 or 12:36:25.881. */\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 /* In this case we assume this is a date object, and we just get the time. */\n return value.getTime();\n }\n /* No point in throwing an error here, as this would cause the entire transformation to fail. Instead, we just log a warning and return null. */\n console.warn(\"Could not parse given dateTime value.\", \"PARSE_DATE_ERROR\", {\n value\n });\n return null;\n};\n\nexport const createDatetimeTransformValuePlugin = (): CmsFieldFilterValueTransformPlugin => {\n return new CmsFieldFilterValueTransformPlugin({\n name: \"cms-field-value-filter-transform-datetime\",\n fieldType: \"datetime\",\n /* Always transform into the milliseconds. */\n transform: ({ field, value }: CmsFieldFilterValueTransformParams) => {\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","createDatetimeTransformValuePlugin","CmsFieldFilterValueTransformPlugin","field","type"],"mappings":";;AAOA,MAAMA,gBAAgB,CAACC;IACnB,IAAIA,QAAAA,OACA,MAAM,IAAIC,MAAM;IACb,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;IACX,IAAI,AAAiB,YAAjB,OAAOA,OACd,MAAM,IAAIC,MAAM;IAGpB,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;IACJ,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,SAEnE,OAAOA,MAAM,OAAO;IAGxBgB,QAAQ,IAAI,CAAC,yCAAyC,oBAAoB;QACtEhB;IACJ;IACA,OAAO;AACX;AAEO,MAAMiB,qCAAqC,IACvC,IAAIC,mCAAmC;QAC1C,MAAM;QACN,WAAW;QAEX,WAAW,CAAC,EAAEC,KAAK,EAAEnB,KAAK,EAAsC;YAC5D,MAAM,EAAEoB,IAAI,EAAE,GAAGD,MAAM,QAAQ,IAAI,CAAC;YACpC,IAAIC,AAAS,WAATA,MACA,OAAOrB,cAAcC;YAEzB,OAAOY,kBAAkBZ;QAC7B;IACJ"}
|