@webiny/api-headless-cms-storage 6.6.0-alpha.0 → 6.6.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{dist/cms → cms}/storageHelpers.js +3 -3
- package/cms/storageHelpers.js.map +1 -0
- package/features/FilterRegistriesFeature.d.ts +9 -0
- package/features/FilterRegistriesFeature.js +17 -0
- package/features/FilterRegistriesFeature.js.map +1 -0
- package/features/fieldFilterCreate/DefaultFieldFilterCreateRegistry.d.ts +9 -0
- package/features/fieldFilterCreate/DefaultFieldFilterCreateRegistry.js +26 -0
- package/features/fieldFilterCreate/DefaultFieldFilterCreateRegistry.js.map +1 -0
- package/features/fieldFilterPath/DefaultFieldFilterPathRegistry.d.ts +9 -0
- package/features/fieldFilterPath/DefaultFieldFilterPathRegistry.js +20 -0
- package/features/fieldFilterPath/DefaultFieldFilterPathRegistry.js.map +1 -0
- package/features/fieldFilterValueTransform/DefaultFieldFilterValueTransformRegistry.d.ts +9 -0
- package/features/fieldFilterValueTransform/DefaultFieldFilterValueTransformRegistry.js +17 -0
- package/features/fieldFilterValueTransform/DefaultFieldFilterValueTransformRegistry.js.map +1 -0
- package/features/fieldSorting/DefaultFieldSortingRegistry.d.ts +8 -0
- package/features/fieldSorting/DefaultFieldSortingRegistry.js +11 -0
- package/features/fieldSorting/DefaultFieldSortingRegistry.js.map +1 -0
- package/{dist/filtering → filtering}/fields/createFields.d.ts +2 -0
- package/{dist/filtering → filtering}/fields/createFields.js +2 -2
- package/filtering/fields/createFields.js.map +1 -0
- package/{dist/filtering → filtering}/fields/extractSort.js +1 -1
- package/{dist/filtering → filtering}/fields/extractSort.js.map +1 -1
- package/filtering/fields/systemFields.d.ts +5 -0
- package/{dist/filtering → filtering}/fields/systemFields.js +17 -1
- package/filtering/fields/systemFields.js.map +1 -0
- package/{dist/filtering → filtering}/filter.js +1 -1
- package/{dist/filtering → filtering}/filter.js.map +1 -1
- package/{dist/filtering → filtering}/getValue.js +2 -2
- package/{dist/filtering → filtering}/getValue.js.map +1 -1
- package/{dist/filtering → filtering}/sort.js +1 -1
- package/{dist/filtering → filtering}/sort.js.map +1 -1
- package/{dist/handlers → handlers}/datetimeTransformHandler.js +3 -3
- package/{dist/handlers → handlers}/datetimeTransformHandler.js.map +1 -1
- package/{dist/handlers → handlers}/locationFolderIdPathHandler.js +1 -1
- package/{dist/handlers → handlers}/locationFolderIdPathHandler.js.map +1 -1
- package/package.json +20 -15
- package/{dist/path → path}/locationFolderId.js +1 -1
- package/{dist/path → path}/locationFolderId.js.map +1 -1
- package/{dist/plugins → plugins}/CmsEntryFieldFilterPathPlugin.js +2 -2
- package/{dist/plugins → plugins}/CmsEntryFieldFilterPathPlugin.js.map +1 -1
- package/{dist/transforms → transforms}/datetime.js +3 -3
- package/{dist/transforms → transforms}/datetime.js.map +1 -1
- package/__tests__/filtering/getValue.test.ts +0 -58
- package/__tests__/filtering/mocks/entry.noModel.ts +0 -110
- package/__tests__/path/plainObject.test.ts +0 -32
- package/__tests__/transforms/datetime.test.ts +0 -71
- package/dist/cms/storageHelpers.js.map +0 -1
- package/dist/features/FilterRegistriesFeature.d.ts +0 -4
- package/dist/features/FilterRegistriesFeature.js +0 -39
- package/dist/features/FilterRegistriesFeature.js.map +0 -1
- package/dist/filtering/fields/createFields.js.map +0 -1
- package/dist/filtering/fields/systemFields.d.ts +0 -2
- package/dist/filtering/fields/systemFields.js.map +0 -1
- package/dist/package.json +0 -30
- package/src/cms/storageHelpers.ts +0 -92
- package/src/features/FilterRegistriesFeature.ts +0 -40
- package/src/features/fieldFilterCreate/FieldFilterCreateRegistry.ts +0 -25
- package/src/features/fieldFilterCreate/abstractions.ts +0 -51
- package/src/features/fieldFilterPath/FieldFilterPathRegistry.ts +0 -13
- package/src/features/fieldFilterPath/abstractions.ts +0 -22
- package/src/features/fieldFilterValueTransform/FieldFilterValueTransformRegistry.ts +0 -15
- package/src/features/fieldFilterValueTransform/abstractions.ts +0 -21
- package/src/features/fieldSorting/FieldSortingRegistry.ts +0 -20
- package/src/features/fieldSorting/abstractions.ts +0 -49
- package/src/filtering/expressions/createExpressions.ts +0 -170
- package/src/filtering/fields/createFields.ts +0 -124
- package/src/filtering/fields/extractSort.ts +0 -97
- package/src/filtering/fields/systemFields.ts +0 -165
- package/src/filtering/fields/types.ts +0 -46
- package/src/filtering/filter.ts +0 -166
- package/src/filtering/fullTextSearch.ts +0 -40
- package/src/filtering/getValue.ts +0 -64
- package/src/filtering/mapPlugins.ts +0 -30
- package/src/filtering/plugins/defaultFilterCreate.ts +0 -36
- package/src/filtering/plugins/index.ts +0 -13
- package/src/filtering/plugins/objectFilterCreate.ts +0 -100
- package/src/filtering/plugins/refFilterCreate.ts +0 -83
- package/src/filtering/plugins/searchableJsonFilterCreate.ts +0 -78
- package/src/filtering/sort.ts +0 -79
- package/src/filtering/transform.ts +0 -11
- package/src/filtering/values.ts +0 -24
- package/src/filtering/where.ts +0 -24
- package/src/handlers/datetimeTransformHandler.ts +0 -52
- package/src/handlers/defaultFilterCreateHandler.ts +0 -31
- package/src/handlers/locationFolderIdPathHandler.ts +0 -24
- package/src/handlers/objectFilterCreateHandler.ts +0 -86
- package/src/handlers/plainObjectPathHandler.ts +0 -17
- package/src/handlers/refFilterCreateHandler.ts +0 -65
- package/src/handlers/searchableJsonFilterCreateHandler.ts +0 -61
- package/src/index.ts +0 -63
- package/src/path/locationFolderId.ts +0 -29
- package/src/path/plainObject.ts +0 -21
- package/src/plugins/CmsEntryFieldFilterPathPlugin.ts +0 -58
- package/src/plugins/CmsEntryFieldFilterPlugin.ts +0 -59
- package/src/plugins/CmsEntryFieldSortingPlugin.ts +0 -63
- package/src/plugins/CmsFieldFilterValueTransformPlugin.ts +0 -43
- package/src/plugins/index.ts +0 -10
- package/src/transforms/datetime.ts +0 -62
- package/tsconfig.build.json +0 -33
- package/tsconfig.json +0 -33
- package/vitest.config.ts +0 -5
- package/webiny.config.js +0 -8
- /package/{dist/LICENSE → LICENSE} +0 -0
- /package/{dist/README.md → README.md} +0 -0
- /package/{dist/cms → cms}/storageHelpers.d.ts +0 -0
- /package/{dist/features → features}/fieldFilterCreate/FieldFilterCreateRegistry.d.ts +0 -0
- /package/{dist/features → features}/fieldFilterCreate/FieldFilterCreateRegistry.js +0 -0
- /package/{dist/features → features}/fieldFilterCreate/FieldFilterCreateRegistry.js.map +0 -0
- /package/{dist/features → features}/fieldFilterCreate/abstractions.d.ts +0 -0
- /package/{dist/features → features}/fieldFilterCreate/abstractions.js +0 -0
- /package/{dist/features → features}/fieldFilterCreate/abstractions.js.map +0 -0
- /package/{dist/features → features}/fieldFilterPath/FieldFilterPathRegistry.d.ts +0 -0
- /package/{dist/features → features}/fieldFilterPath/FieldFilterPathRegistry.js +0 -0
- /package/{dist/features → features}/fieldFilterPath/FieldFilterPathRegistry.js.map +0 -0
- /package/{dist/features → features}/fieldFilterPath/abstractions.d.ts +0 -0
- /package/{dist/features → features}/fieldFilterPath/abstractions.js +0 -0
- /package/{dist/features → features}/fieldFilterPath/abstractions.js.map +0 -0
- /package/{dist/features → features}/fieldFilterValueTransform/FieldFilterValueTransformRegistry.d.ts +0 -0
- /package/{dist/features → features}/fieldFilterValueTransform/FieldFilterValueTransformRegistry.js +0 -0
- /package/{dist/features → features}/fieldFilterValueTransform/FieldFilterValueTransformRegistry.js.map +0 -0
- /package/{dist/features → features}/fieldFilterValueTransform/abstractions.d.ts +0 -0
- /package/{dist/features → features}/fieldFilterValueTransform/abstractions.js +0 -0
- /package/{dist/features → features}/fieldFilterValueTransform/abstractions.js.map +0 -0
- /package/{dist/features → features}/fieldSorting/FieldSortingRegistry.d.ts +0 -0
- /package/{dist/features → features}/fieldSorting/FieldSortingRegistry.js +0 -0
- /package/{dist/features → features}/fieldSorting/FieldSortingRegistry.js.map +0 -0
- /package/{dist/features → features}/fieldSorting/abstractions.d.ts +0 -0
- /package/{dist/features → features}/fieldSorting/abstractions.js +0 -0
- /package/{dist/features → features}/fieldSorting/abstractions.js.map +0 -0
- /package/{dist/filtering → filtering}/expressions/createExpressions.d.ts +0 -0
- /package/{dist/filtering → filtering}/expressions/createExpressions.js +0 -0
- /package/{dist/filtering → filtering}/expressions/createExpressions.js.map +0 -0
- /package/{dist/filtering → filtering}/fields/extractSort.d.ts +0 -0
- /package/{dist/filtering → filtering}/fields/types.d.ts +0 -0
- /package/{dist/filtering → filtering}/fields/types.js +0 -0
- /package/{dist/filtering → filtering}/filter.d.ts +0 -0
- /package/{dist/filtering → filtering}/fullTextSearch.d.ts +0 -0
- /package/{dist/filtering → filtering}/fullTextSearch.js +0 -0
- /package/{dist/filtering → filtering}/fullTextSearch.js.map +0 -0
- /package/{dist/filtering → filtering}/getValue.d.ts +0 -0
- /package/{dist/filtering → filtering}/mapPlugins.d.ts +0 -0
- /package/{dist/filtering → filtering}/mapPlugins.js +0 -0
- /package/{dist/filtering → filtering}/mapPlugins.js.map +0 -0
- /package/{dist/filtering → filtering}/plugins/defaultFilterCreate.d.ts +0 -0
- /package/{dist/filtering → filtering}/plugins/defaultFilterCreate.js +0 -0
- /package/{dist/filtering → filtering}/plugins/defaultFilterCreate.js.map +0 -0
- /package/{dist/filtering → filtering}/plugins/index.d.ts +0 -0
- /package/{dist/filtering → filtering}/plugins/index.js +0 -0
- /package/{dist/filtering → filtering}/plugins/index.js.map +0 -0
- /package/{dist/filtering → filtering}/plugins/objectFilterCreate.d.ts +0 -0
- /package/{dist/filtering → filtering}/plugins/objectFilterCreate.js +0 -0
- /package/{dist/filtering → filtering}/plugins/objectFilterCreate.js.map +0 -0
- /package/{dist/filtering → filtering}/plugins/refFilterCreate.d.ts +0 -0
- /package/{dist/filtering → filtering}/plugins/refFilterCreate.js +0 -0
- /package/{dist/filtering → filtering}/plugins/refFilterCreate.js.map +0 -0
- /package/{dist/filtering → filtering}/plugins/searchableJsonFilterCreate.d.ts +0 -0
- /package/{dist/filtering → filtering}/plugins/searchableJsonFilterCreate.js +0 -0
- /package/{dist/filtering → filtering}/plugins/searchableJsonFilterCreate.js.map +0 -0
- /package/{dist/filtering → filtering}/sort.d.ts +0 -0
- /package/{dist/filtering → filtering}/transform.d.ts +0 -0
- /package/{dist/filtering → filtering}/transform.js +0 -0
- /package/{dist/filtering → filtering}/transform.js.map +0 -0
- /package/{dist/filtering → filtering}/values.d.ts +0 -0
- /package/{dist/filtering → filtering}/values.js +0 -0
- /package/{dist/filtering → filtering}/values.js.map +0 -0
- /package/{dist/filtering → filtering}/where.d.ts +0 -0
- /package/{dist/filtering → filtering}/where.js +0 -0
- /package/{dist/filtering → filtering}/where.js.map +0 -0
- /package/{dist/handlers → handlers}/datetimeTransformHandler.d.ts +0 -0
- /package/{dist/handlers → handlers}/defaultFilterCreateHandler.d.ts +0 -0
- /package/{dist/handlers → handlers}/defaultFilterCreateHandler.js +0 -0
- /package/{dist/handlers → handlers}/defaultFilterCreateHandler.js.map +0 -0
- /package/{dist/handlers → handlers}/locationFolderIdPathHandler.d.ts +0 -0
- /package/{dist/handlers → handlers}/objectFilterCreateHandler.d.ts +0 -0
- /package/{dist/handlers → handlers}/objectFilterCreateHandler.js +0 -0
- /package/{dist/handlers → handlers}/objectFilterCreateHandler.js.map +0 -0
- /package/{dist/handlers → handlers}/plainObjectPathHandler.d.ts +0 -0
- /package/{dist/handlers → handlers}/plainObjectPathHandler.js +0 -0
- /package/{dist/handlers → handlers}/plainObjectPathHandler.js.map +0 -0
- /package/{dist/handlers → handlers}/refFilterCreateHandler.d.ts +0 -0
- /package/{dist/handlers → handlers}/refFilterCreateHandler.js +0 -0
- /package/{dist/handlers → handlers}/refFilterCreateHandler.js.map +0 -0
- /package/{dist/handlers → handlers}/searchableJsonFilterCreateHandler.d.ts +0 -0
- /package/{dist/handlers → handlers}/searchableJsonFilterCreateHandler.js +0 -0
- /package/{dist/handlers → handlers}/searchableJsonFilterCreateHandler.js.map +0 -0
- /package/{dist/index.d.ts → index.d.ts} +0 -0
- /package/{dist/index.js → index.js} +0 -0
- /package/{dist/path → path}/locationFolderId.d.ts +0 -0
- /package/{dist/path → path}/plainObject.d.ts +0 -0
- /package/{dist/path → path}/plainObject.js +0 -0
- /package/{dist/path → path}/plainObject.js.map +0 -0
- /package/{dist/plugins → plugins}/CmsEntryFieldFilterPathPlugin.d.ts +0 -0
- /package/{dist/plugins → plugins}/CmsEntryFieldFilterPlugin.d.ts +0 -0
- /package/{dist/plugins → plugins}/CmsEntryFieldFilterPlugin.js +0 -0
- /package/{dist/plugins → plugins}/CmsEntryFieldFilterPlugin.js.map +0 -0
- /package/{dist/plugins → plugins}/CmsEntryFieldSortingPlugin.d.ts +0 -0
- /package/{dist/plugins → plugins}/CmsEntryFieldSortingPlugin.js +0 -0
- /package/{dist/plugins → plugins}/CmsEntryFieldSortingPlugin.js.map +0 -0
- /package/{dist/plugins → plugins}/CmsFieldFilterValueTransformPlugin.d.ts +0 -0
- /package/{dist/plugins → plugins}/CmsFieldFilterValueTransformPlugin.js +0 -0
- /package/{dist/plugins → plugins}/CmsFieldFilterValueTransformPlugin.js.map +0 -0
- /package/{dist/plugins → plugins}/index.d.ts +0 -0
- /package/{dist/plugins → plugins}/index.js +0 -0
- /package/{dist/transforms → transforms}/datetime.d.ts +0 -0
|
@@ -1 +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;
|
|
1
|
+
{"version":3,"file":"path/locationFolderId.js","sources":["../../src/path/locationFolderId.ts"],"sourcesContent":["/* File is @internal. */\nimport WebinyError from \"@webiny/error\";\nimport type { CreatePathCallable } from \"../plugins/CmsEntryFieldFilterPathPlugin.js\";\nimport { CmsEntryFieldFilterPathPlugin } from \"../plugins/CmsEntryFieldFilterPathPlugin.js\";\n\nconst createPath: CreatePathCallable = ({ field }) => {\n const { path } = field.settings || {};\n if (!path) {\n throw new WebinyError(\"Missing path settings value.\", \"FIELD_SETTINGS_ERROR\", {\n field\n });\n }\n return path;\n};\n\nexport const createLocationFolderIdPathPlugin = (): CmsEntryFieldFilterPathPlugin => {\n return new CmsEntryFieldFilterPathPlugin({\n fieldType: \"text\",\n path: createPath,\n canUse: (field, parents) => {\n if (field.fieldId !== \"folderId\") {\n return false;\n } else if (!parents?.length) {\n return false;\n }\n return parents[0] === \"wbyAco_location\";\n }\n });\n};\n"],"names":["createPath","field","path","WebinyError","createLocationFolderIdPathPlugin","CmsEntryFieldFilterPathPlugin","parents"],"mappings":";;AAKA,MAAMA,aAAiC,CAAC,EAAEC,KAAK,EAAE;IAC7C,MAAM,EAAEC,IAAI,EAAE,GAAGD,MAAM,QAAQ,IAAI,CAAC;IACpC,IAAI,CAACC,MACD,MAAM,IAAIC,MAAY,gCAAgC,wBAAwB;QAC1EF;IACJ;IAEJ,OAAOC;AACX;AAEO,MAAME,mCAAmC,IACrC,IAAIC,8BAA8B;QACrC,WAAW;QACX,MAAML;QACN,QAAQ,CAACC,OAAOK;YACZ,IAAIL,AAAkB,eAAlBA,MAAM,OAAO,EACb,OAAO;iBACJ,IAAI,CAACK,SAAS,QACjB,OAAO;YAEX,OAAOA,AAAe,sBAAfA,OAAO,CAAC,EAAE;QACrB;IACJ"}
|
|
@@ -14,14 +14,14 @@ class CmsEntryFieldFilterPathPlugin extends Plugin {
|
|
|
14
14
|
}
|
|
15
15
|
canUse(field, parents) {
|
|
16
16
|
if (field.type !== this.config.fieldType) return false;
|
|
17
|
-
if (this.config.canUse) return this.config.canUse(field, parents);
|
|
17
|
+
else if (this.config.canUse) return this.config.canUse(field, parents);
|
|
18
18
|
const fieldId = this.config.fieldId;
|
|
19
19
|
if (!fieldId || false === Array.isArray(fieldId) || 0 === fieldId.length) return true;
|
|
20
20
|
return fieldId.includes(field.fieldId);
|
|
21
21
|
}
|
|
22
22
|
createPath(params) {
|
|
23
23
|
if ("function" == typeof this.config.path) return this.config.path(params);
|
|
24
|
-
if ("string" == typeof this.config.path) return this.config.path;
|
|
24
|
+
else if ("string" == typeof this.config.path) return this.config.path;
|
|
25
25
|
throw new error(`Missing path in "${this.name}" plugin.`);
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -1 +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;
|
|
1
|
+
{"version":3,"file":"plugins/CmsEntryFieldFilterPathPlugin.js","sources":["../../src/plugins/CmsEntryFieldFilterPathPlugin.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { Plugin } from \"@webiny/plugins/Plugin.js\";\nimport type { CmsModelField } from \"@webiny/api-headless-cms/types/index.js\";\n\nexport interface CreatePathCallableParams {\n field: Partial<CmsModelField> & Pick<CmsModelField, \"fieldId\" | \"storageId\" | \"id\">;\n index?: number;\n}\nexport interface CreatePathCallable {\n (params: CreatePathCallableParams): string;\n}\nexport interface CmsEntryFieldFilterPathPluginParams {\n fieldType: string;\n fieldId?: string[];\n path: string | CreatePathCallable;\n canUse?: (field: Pick<CmsModelField, \"fieldId\" | \"type\">, parents?: string[]) => boolean;\n}\nexport class CmsEntryFieldFilterPathPlugin extends Plugin {\n public static override readonly type: string = \"cms-field-filter-path\";\n\n private readonly config: CmsEntryFieldFilterPathPluginParams;\n\n public get fieldType(): string {\n return this.config.fieldType;\n }\n\n public constructor(config: CmsEntryFieldFilterPathPluginParams) {\n super();\n\n this.config = config;\n\n /* We expect error here because we know that `this.constructor.type` is defined, but TS does not. */\n // @ts-expect-error\n this.name = `${this.constructor.type}-${this.config.fieldType}`;\n }\n\n public canUse(field: Pick<CmsModelField, \"fieldId\" | \"type\">, parents: string[]): boolean {\n if (field.type !== this.config.fieldType) {\n return false;\n } else if (this.config.canUse) {\n return this.config.canUse(field, parents);\n }\n const fieldId = this.config.fieldId;\n if (!fieldId || Array.isArray(fieldId) === false || fieldId.length === 0) {\n return true;\n }\n return fieldId.includes(field.fieldId);\n }\n\n public createPath(params: CreatePathCallableParams): string {\n if (typeof this.config.path === \"function\") {\n return this.config.path(params);\n } else if (typeof this.config.path === \"string\") {\n return this.config.path;\n }\n throw new WebinyError(`Missing path in \"${this.name}\" plugin.`);\n }\n}\n"],"names":["CmsEntryFieldFilterPathPlugin","Plugin","config","field","parents","fieldId","Array","params","WebinyError"],"mappings":";;AAiBO,MAAMA,sCAAsCC;;aACf,IAAI,GAAW;;IAI/C,IAAW,YAAoB;QAC3B,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS;IAChC;IAEA,YAAmBC,MAA2C,CAAE;QAC5D,KAAK;QAEL,IAAI,CAAC,MAAM,GAAGA;QAId,IAAI,CAAC,IAAI,GAAG,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE;IACnE;IAEO,OAAOC,KAA8C,EAAEC,OAAiB,EAAW;QACtF,IAAID,MAAM,IAAI,KAAK,IAAI,CAAC,MAAM,CAAC,SAAS,EACpC,OAAO;aACJ,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,EACzB,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAACA,OAAOC;QAErC,MAAMC,UAAU,IAAI,CAAC,MAAM,CAAC,OAAO;QACnC,IAAI,CAACA,WAAWC,AAA2B,UAA3BA,MAAM,OAAO,CAACD,YAAsBA,AAAmB,MAAnBA,QAAQ,MAAM,EAC9D,OAAO;QAEX,OAAOA,QAAQ,QAAQ,CAACF,MAAM,OAAO;IACzC;IAEO,WAAWI,MAAgC,EAAU;QACxD,IAAI,AAA4B,cAA5B,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,EACvB,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAACA;aACrB,IAAI,AAA4B,YAA5B,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,EAC9B,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI;QAE3B,MAAM,IAAIC,MAAY,CAAC,iBAAiB,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC;IAClE;AACJ"}
|
|
@@ -2,10 +2,10 @@ import { parseISO } from "date-fns";
|
|
|
2
2
|
import { CmsFieldFilterValueTransformPlugin } from "../plugins/CmsFieldFilterValueTransformPlugin.js";
|
|
3
3
|
const transformTime = (value)=>{
|
|
4
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.");
|
|
5
|
+
else if ("boolean" == typeof value || "" === value || Array.isArray(value)) throw new Error("Field value must be a string because field is defined as time.");
|
|
6
6
|
const converted = Number(`${value}`);
|
|
7
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.");
|
|
8
|
+
else if ("string" != typeof value) throw new Error("Field value must be a string because field is defined as time.");
|
|
9
9
|
const [time, milliseconds = 0] = value.split(".");
|
|
10
10
|
const values = time.split(":").map(Number);
|
|
11
11
|
if (values.length < 2) throw new Error("Time must contain at least hours and minutes.");
|
|
@@ -14,7 +14,7 @@ const transformTime = (value)=>{
|
|
|
14
14
|
};
|
|
15
15
|
const transformDateTime = (value)=>{
|
|
16
16
|
if (null == value) return null;
|
|
17
|
-
if ("string" == typeof value) {
|
|
17
|
+
else if ("string" == typeof value) {
|
|
18
18
|
const parsedDateTime = parseISO(value).getTime();
|
|
19
19
|
if (false === isNaN(parsedDateTime)) return parsedDateTime;
|
|
20
20
|
} else if (value instanceof Date || "function" == typeof value?.getTime) return value.getTime();
|
|
@@ -1 +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;
|
|
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;SACb,IAAI,AAAiB,aAAjB,OAAOD,SAAuBA,AAAU,OAAVA,SAAgBE,MAAM,OAAO,CAACF,QACnE,MAAM,IAAIC,MAAM;IAEpB,MAAME,YAAYC,OAAO,GAAGJ,OAAO;IACnC,IAAI,AAAiB,YAAjB,OAAOA,SAAsBK,AAAqB,UAArBA,MAAMF,YACnC,OAAOC,OAAOJ;SACX,IAAI,AAAiB,YAAjB,OAAOA,OACd,MAAM,IAAIC,MAAM;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;SACJ,IAAI,AAAiB,YAAjB,OAAOA,OAAoB;QAClC,MAAMa,iBAAiBC,SAASd,OAAO,OAAO;QAC9C,IAAIK,AAA0B,UAA1BA,MAAMQ,iBACN,OAAOA;IAEf,OAAO,IAAIb,iBAAiBe,QAAQ,AAA+C,cAA/C,OAAQf,OAA2B,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"}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { getValue } from "~/filtering/getValue";
|
|
3
|
-
import { createEntry } from "./mocks/entry.noModel";
|
|
4
|
-
|
|
5
|
-
describe("value via object-path", () => {
|
|
6
|
-
it("should find values complex object / array structure", async () => {
|
|
7
|
-
const title = getValue(createEntry(), "values.title");
|
|
8
|
-
expect(title).toEqual(createEntry().values.title);
|
|
9
|
-
|
|
10
|
-
const options = getValue(createEntry(), "values.options");
|
|
11
|
-
expect(options).toEqual(createEntry().values.options);
|
|
12
|
-
|
|
13
|
-
const variantTitle = getValue(createEntry(), "values.variant.title");
|
|
14
|
-
expect(variantTitle).toEqual(createEntry().values.variant.title);
|
|
15
|
-
|
|
16
|
-
const variantSpecificationsKey = getValue(
|
|
17
|
-
createEntry(),
|
|
18
|
-
"values.variant.specifications.key"
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
expect(variantSpecificationsKey).toEqual([
|
|
22
|
-
"Specification #1",
|
|
23
|
-
"Specification #2",
|
|
24
|
-
"Specification #3"
|
|
25
|
-
]);
|
|
26
|
-
|
|
27
|
-
const variantSpecificationsInfoImages = getValue(
|
|
28
|
-
createEntry(),
|
|
29
|
-
"values.variant.specifications.info.images"
|
|
30
|
-
);
|
|
31
|
-
expect(variantSpecificationsInfoImages).toEqual([
|
|
32
|
-
{ files: ["image1.jpg", "image2.jpg", "image3.jpg", "image4.jpg"] },
|
|
33
|
-
{ files: ["image31.jpg", "image32.jpg", "image33.jpg", "image34.jpg"] }
|
|
34
|
-
]);
|
|
35
|
-
|
|
36
|
-
const variantSpecificationsInfoImagesFiles = getValue(
|
|
37
|
-
createEntry(),
|
|
38
|
-
"values.variant.specifications.info.images.files"
|
|
39
|
-
);
|
|
40
|
-
expect(variantSpecificationsInfoImagesFiles).toEqual([
|
|
41
|
-
"image1.jpg",
|
|
42
|
-
"image2.jpg",
|
|
43
|
-
"image3.jpg",
|
|
44
|
-
"image4.jpg",
|
|
45
|
-
"image31.jpg",
|
|
46
|
-
"image32.jpg",
|
|
47
|
-
"image33.jpg",
|
|
48
|
-
"image34.jpg"
|
|
49
|
-
]);
|
|
50
|
-
|
|
51
|
-
const variantSpecificationsInfoTagsKey = getValue(
|
|
52
|
-
createEntry(),
|
|
53
|
-
"values.variant.specifications.info.tags.key"
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
expect(variantSpecificationsInfoTagsKey).toEqual(["size", "weight", "price"]);
|
|
57
|
-
});
|
|
58
|
-
});
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import type { CmsEntry } from "@webiny/api-headless-cms/types";
|
|
2
|
-
|
|
3
|
-
interface ValuesOption {
|
|
4
|
-
title: string;
|
|
5
|
-
value: number;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
interface ValuesVariantSpecification {
|
|
9
|
-
key: string;
|
|
10
|
-
value: string | number;
|
|
11
|
-
info?: {
|
|
12
|
-
[key: string]: any;
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
interface ValuesVariant {
|
|
16
|
-
title: string;
|
|
17
|
-
specifications: ValuesVariantSpecification[];
|
|
18
|
-
}
|
|
19
|
-
interface Values {
|
|
20
|
-
title: string;
|
|
21
|
-
options: ValuesOption[];
|
|
22
|
-
variant: ValuesVariant;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
type Result = Pick<CmsEntry<Values>, "id" | "createdBy" | "createdOn" | "values">;
|
|
26
|
-
|
|
27
|
-
const createCreatedOn = (index: number) => {
|
|
28
|
-
const d = new Date();
|
|
29
|
-
d.setTime(d.getTime() + index * 1000 * 86400);
|
|
30
|
-
|
|
31
|
-
return d.toISOString();
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export const createEntry = (index = 0): Result => {
|
|
35
|
-
return {
|
|
36
|
-
id: `${index + 100000}#0001`,
|
|
37
|
-
createdOn: createCreatedOn(index),
|
|
38
|
-
createdBy: {
|
|
39
|
-
id: "userId",
|
|
40
|
-
type: "admin",
|
|
41
|
-
displayName: "Admin"
|
|
42
|
-
},
|
|
43
|
-
values: {
|
|
44
|
-
title: `Title #${String(index).padStart(5, "t")}`,
|
|
45
|
-
options: Array.from({ length: 100 }).map((_, optionIndex) => {
|
|
46
|
-
return {
|
|
47
|
-
title: `Option #${index + optionIndex + 1}`,
|
|
48
|
-
value: index + optionIndex + 1
|
|
49
|
-
};
|
|
50
|
-
}),
|
|
51
|
-
variant: {
|
|
52
|
-
title: `Variant title ${String(index).padStart(5, "a")}`,
|
|
53
|
-
specifications: [
|
|
54
|
-
{
|
|
55
|
-
key: `Specification #${index === 0 ? 1 : index}`,
|
|
56
|
-
value: `${index + 100}`,
|
|
57
|
-
info: {
|
|
58
|
-
images: {
|
|
59
|
-
files: ["image1.jpg", "image2.jpg", "image3.jpg", "image4.jpg"]
|
|
60
|
-
},
|
|
61
|
-
tags: [
|
|
62
|
-
{
|
|
63
|
-
key: "size",
|
|
64
|
-
value: 55
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
key: "weight",
|
|
68
|
-
value: 105
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
key: "price",
|
|
72
|
-
value: 999
|
|
73
|
-
}
|
|
74
|
-
]
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
key: "Specification #2",
|
|
79
|
-
value: "2"
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
key: "Specification #3",
|
|
83
|
-
value: "3",
|
|
84
|
-
info: {
|
|
85
|
-
images: {
|
|
86
|
-
files: ["image31.jpg", "image32.jpg", "image33.jpg", "image34.jpg"]
|
|
87
|
-
},
|
|
88
|
-
tags: [
|
|
89
|
-
{
|
|
90
|
-
key: "size",
|
|
91
|
-
value: 355
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
key: "price",
|
|
95
|
-
value: 3999
|
|
96
|
-
}
|
|
97
|
-
]
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
]
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
export const createEntries = (amount: number) => {
|
|
107
|
-
return [...Array(amount)].map((_, index) => {
|
|
108
|
-
return createEntry(index);
|
|
109
|
-
});
|
|
110
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { CmsModelField } from "@webiny/api-headless-cms/types";
|
|
3
|
-
import { createPlainObjectPathPlugin } from "~/path/plainObject";
|
|
4
|
-
|
|
5
|
-
describe("dynamodb path plain object", () => {
|
|
6
|
-
it("should get the plain object path", () => {
|
|
7
|
-
const plugin = createPlainObjectPathPlugin();
|
|
8
|
-
|
|
9
|
-
const result = plugin.createPath({
|
|
10
|
-
field: {
|
|
11
|
-
storageId: "authors",
|
|
12
|
-
settings: {
|
|
13
|
-
path: "createdBy.id"
|
|
14
|
-
}
|
|
15
|
-
} as unknown as CmsModelField
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
expect(result).toEqual("createdBy.id");
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it("should throw an error when no path in the settings", () => {
|
|
22
|
-
const plugin = createPlainObjectPathPlugin();
|
|
23
|
-
|
|
24
|
-
expect(() => {
|
|
25
|
-
plugin.createPath({
|
|
26
|
-
field: {
|
|
27
|
-
settings: {}
|
|
28
|
-
} as unknown as CmsModelField
|
|
29
|
-
});
|
|
30
|
-
}).toThrow("Missing path settings value.");
|
|
31
|
-
});
|
|
32
|
-
});
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { createDatetimeTransformValuePlugin } from "~/transforms/datetime";
|
|
3
|
-
import { CmsModelField } from "@webiny/api-headless-cms/types";
|
|
4
|
-
|
|
5
|
-
const createField = (fieldType: string): CmsModelField => {
|
|
6
|
-
return {
|
|
7
|
-
id: "storageId",
|
|
8
|
-
storageId: "storageId",
|
|
9
|
-
type: "datetime",
|
|
10
|
-
settings: {
|
|
11
|
-
type: fieldType
|
|
12
|
-
}
|
|
13
|
-
} as unknown as CmsModelField;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
describe("dynamodb transform datetime", () => {
|
|
17
|
-
const correctValues: [string | Date, string, number][] = [
|
|
18
|
-
[new Date("Thu, 13 May 2021 12:32:33.892 GMT"), "date", 1620909153892],
|
|
19
|
-
[new Date("2021-05-13T12:32:33.892Z"), "date", 1620909153892],
|
|
20
|
-
["2021-05-13T12:32:33.892Z", "date", 1620909153892],
|
|
21
|
-
["13:57:22", "time", 50242000],
|
|
22
|
-
["13:57", "time", 50220000],
|
|
23
|
-
["13:57.481", "time", 50220481],
|
|
24
|
-
["13:57:22.581", "time", 50242581]
|
|
25
|
-
];
|
|
26
|
-
it.each(correctValues)(
|
|
27
|
-
"should transform date or time into the milliseconds - %s",
|
|
28
|
-
(value: Date | string, fieldType: string, expected: number) => {
|
|
29
|
-
const plugin = createDatetimeTransformValuePlugin();
|
|
30
|
-
|
|
31
|
-
const result = plugin.transform({
|
|
32
|
-
field: createField(fieldType),
|
|
33
|
-
value
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
expect(result).toEqual(expected);
|
|
37
|
-
}
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
const incorrectTimeValues: [any][] = [
|
|
41
|
-
[{}],
|
|
42
|
-
[[]],
|
|
43
|
-
[""],
|
|
44
|
-
[
|
|
45
|
-
function () {
|
|
46
|
-
return 1;
|
|
47
|
-
}
|
|
48
|
-
],
|
|
49
|
-
[true]
|
|
50
|
-
];
|
|
51
|
-
|
|
52
|
-
it.each(incorrectTimeValues)(
|
|
53
|
-
"should throw an error when trying to transform time field but value is not a string or a number",
|
|
54
|
-
value => {
|
|
55
|
-
expect.assertions(1);
|
|
56
|
-
const plugin = createDatetimeTransformValuePlugin();
|
|
57
|
-
|
|
58
|
-
try {
|
|
59
|
-
const result = plugin.transform({
|
|
60
|
-
field: createField("time"),
|
|
61
|
-
value
|
|
62
|
-
});
|
|
63
|
-
expect(result).toEqual("SHOULD NOT HAPPEN");
|
|
64
|
-
} catch (ex) {
|
|
65
|
-
expect(ex.message).toEqual(
|
|
66
|
-
"Field value must be a string because field is defined as time."
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
);
|
|
71
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cms/storageHelpers.js","sources":["../../src/cms/storageHelpers.ts"],"sourcesContent":["import type {\n CmsEntry,\n CmsEntryUniqueValue,\n CmsEntryValues,\n CmsModel,\n CmsModelField,\n StorageOperationsCmsModel\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport type { Container } from \"@webiny/di\";\nimport { CmsStorageModelProvider } from \"@webiny/api-headless-cms/features/shared/abstractions.js\";\nimport { getBaseFieldType } from \"@webiny/api-headless-cms/utils/getBaseFieldType.js\";\nimport type { StorageTransformRegistry } from \"@webiny/api-headless-cms/exports/api/cms/storage.js\";\nimport type { FilterItemFromStorage } from \"../filtering/fields/types.js\";\n\n/* Creates a lazy-cached getter for the storage representation of a CMS model. */\nexport const createStorageModelAccessor = (container: Container) => {\n let cached: CmsStorageModelProvider.Interface | undefined;\n\n const getProvider = () => {\n if (!cached) {\n cached = container.resolve(CmsStorageModelProvider);\n }\n return cached;\n };\n\n const getModel = <T extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel\n ): StorageOperationsCmsModel<T> => {\n return getProvider().getModel<T>(model);\n };\n\n return { getModel };\n};\n\n/* Creates a fromStorage transform callable for a given model. */\nexport const createStorageTransformCallable = (\n storageTransformRegistry: StorageTransformRegistry.Interface,\n model: StorageOperationsCmsModel\n): FilterItemFromStorage => {\n return async (field: CmsModelField, value: unknown) => {\n const fieldType = getBaseFieldType(field);\n const storageTransform = storageTransformRegistry.get(fieldType);\n\n if (!storageTransform) {\n return value;\n }\n\n const result = await storageTransform.fromStorage({\n model,\n field,\n value,\n getStorageTransform(ft: string) {\n return storageTransformRegistry.get(ft) || storageTransformRegistry.get(\"*\")!;\n }\n });\n\n return result;\n };\n};\n\n/* Aggregates unique values for a given field across a list of CMS entries. */\nexport const aggregateUniqueFieldValues = <T extends CmsEntryValues = CmsEntryValues>(\n items: CmsEntry<T>[],\n fieldId: string\n): CmsEntryUniqueValue[] => {\n const result: Record<string, CmsEntryUniqueValue> = {};\n\n for (const item of items) {\n const fieldValue = item.values[fieldId] as string[] | string | undefined;\n\n if (fieldValue == null) {\n continue;\n }\n\n const values = Array.isArray(fieldValue) ? fieldValue : [fieldValue];\n\n if (values.length === 0) {\n continue;\n }\n\n for (const value of values) {\n result[value] = {\n value,\n count: (result[value]?.count || 0) + 1\n };\n }\n }\n\n return Object.values(result)\n .sort((a, b) => (a.value > b.value ? 1 : b.value > a.value ? -1 : 0))\n .sort((a, b) => b.count - a.count);\n};\n"],"names":["createStorageModelAccessor","container","cached","getProvider","CmsStorageModelProvider","getModel","model","createStorageTransformCallable","storageTransformRegistry","field","value","fieldType","getBaseFieldType","storageTransform","result","ft","aggregateUniqueFieldValues","items","fieldId","item","fieldValue","values","Array","Object","a","b"],"mappings":";;AAeO,MAAMA,6BAA6B,CAACC;IACvC,IAAIC;IAEJ,MAAMC,cAAc;QAChB,IAAI,CAACD,QACDA,SAASD,UAAU,OAAO,CAACG;QAE/B,OAAOF;IACX;IAEA,MAAMG,WAAW,CACbC,QAEOH,cAAc,QAAQ,CAAIG;IAGrC,OAAO;QAAED;IAAS;AACtB;AAGO,MAAME,iCAAiC,CAC1CC,0BACAF,QAEO,OAAOG,OAAsBC;QAChC,MAAMC,YAAYC,iBAAiBH;QACnC,MAAMI,mBAAmBL,yBAAyB,GAAG,CAACG;QAEtD,IAAI,CAACE,kBACD,OAAOH;QAGX,MAAMI,SAAS,MAAMD,iBAAiB,WAAW,CAAC;YAC9CP;YACAG;YACAC;YACA,qBAAoBK,EAAU;gBAC1B,OAAOP,yBAAyB,GAAG,CAACO,OAAOP,yBAAyB,GAAG,CAAC;YAC5E;QACJ;QAEA,OAAOM;IACX;AAIG,MAAME,6BAA6B,CACtCC,OACAC;IAEA,MAAMJ,SAA8C,CAAC;IAErD,KAAK,MAAMK,QAAQF,MAAO;QACtB,MAAMG,aAAaD,KAAK,MAAM,CAACD,QAAQ;QAEvC,IAAIE,AAAc,QAAdA,YACA;QAGJ,MAAMC,SAASC,MAAM,OAAO,CAACF,cAAcA,aAAa;YAACA;SAAW;QAEpE,IAAIC,AAAkB,MAAlBA,OAAO,MAAM,EAIjB,KAAK,MAAMX,SAASW,OAChBP,MAAM,CAACJ,MAAM,GAAG;YACZA;YACA,OAAQI,AAAAA,CAAAA,MAAM,CAACJ,MAAM,EAAE,SAAS,KAAK;QACzC;IAER;IAEA,OAAOa,OAAO,MAAM,CAACT,QAChB,IAAI,CAAC,CAACU,GAAGC,IAAOD,EAAE,KAAK,GAAGC,EAAE,KAAK,GAAG,IAAIA,EAAE,KAAK,GAAGD,EAAE,KAAK,GAAG,KAAK,GACjE,IAAI,CAAC,CAACA,GAAGC,IAAMA,EAAE,KAAK,GAAGD,EAAE,KAAK;AACzC"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { createFeature } from "@webiny/feature/api/index.js";
|
|
2
|
-
import { FieldFilterPathRegistry } from "./fieldFilterPath/abstractions.js";
|
|
3
|
-
import { FieldFilterValueTransformRegistry } from "./fieldFilterValueTransform/abstractions.js";
|
|
4
|
-
import { FieldFilterCreateRegistry } from "./fieldFilterCreate/abstractions.js";
|
|
5
|
-
import { FieldSortingRegistry } from "./fieldSorting/abstractions.js";
|
|
6
|
-
import { FieldFilterPathRegistryImpl } from "./fieldFilterPath/FieldFilterPathRegistry.js";
|
|
7
|
-
import { FieldFilterValueTransformRegistryImpl } from "./fieldFilterValueTransform/FieldFilterValueTransformRegistry.js";
|
|
8
|
-
import { FieldFilterCreateRegistryImpl } from "./fieldFilterCreate/FieldFilterCreateRegistry.js";
|
|
9
|
-
import { FieldSortingRegistryImpl } from "./fieldSorting/FieldSortingRegistry.js";
|
|
10
|
-
import { createPlainObjectPathHandler } from "../handlers/plainObjectPathHandler.js";
|
|
11
|
-
import { createLocationFolderIdPathHandler } from "../handlers/locationFolderIdPathHandler.js";
|
|
12
|
-
import { createDatetimeTransformHandler } from "../handlers/datetimeTransformHandler.js";
|
|
13
|
-
import { createDefaultFilterCreateHandler } from "../handlers/defaultFilterCreateHandler.js";
|
|
14
|
-
import { createRefFilterCreateHandler } from "../handlers/refFilterCreateHandler.js";
|
|
15
|
-
import { createObjectFilterCreateHandler } from "../handlers/objectFilterCreateHandler.js";
|
|
16
|
-
import { createSearchableJsonFilterCreateHandler } from "../handlers/searchableJsonFilterCreateHandler.js";
|
|
17
|
-
const FilterRegistriesFeature = createFeature({
|
|
18
|
-
name: "cms.storage.filterRegistries",
|
|
19
|
-
register: (container)=>{
|
|
20
|
-
const pathRegistry = new FieldFilterPathRegistryImpl();
|
|
21
|
-
pathRegistry.register("plainObject", createPlainObjectPathHandler());
|
|
22
|
-
pathRegistry.register("text", createLocationFolderIdPathHandler());
|
|
23
|
-
container.registerInstance(FieldFilterPathRegistry, pathRegistry);
|
|
24
|
-
const transformRegistry = new FieldFilterValueTransformRegistryImpl();
|
|
25
|
-
transformRegistry.register("datetime", createDatetimeTransformHandler());
|
|
26
|
-
container.registerInstance(FieldFilterValueTransformRegistry, transformRegistry);
|
|
27
|
-
const filterCreateRegistry = new FieldFilterCreateRegistryImpl();
|
|
28
|
-
filterCreateRegistry.register("*", createDefaultFilterCreateHandler());
|
|
29
|
-
filterCreateRegistry.register("ref", createRefFilterCreateHandler());
|
|
30
|
-
filterCreateRegistry.register("object", createObjectFilterCreateHandler());
|
|
31
|
-
filterCreateRegistry.register("searchable-json", createSearchableJsonFilterCreateHandler());
|
|
32
|
-
container.registerInstance(FieldFilterCreateRegistry, filterCreateRegistry);
|
|
33
|
-
const sortingRegistry = new FieldSortingRegistryImpl();
|
|
34
|
-
container.registerInstance(FieldSortingRegistry, sortingRegistry);
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
export { FilterRegistriesFeature };
|
|
38
|
-
|
|
39
|
-
//# sourceMappingURL=FilterRegistriesFeature.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"features/FilterRegistriesFeature.js","sources":["../../src/features/FilterRegistriesFeature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api/index.js\";\nimport { FieldFilterPathRegistry } from \"./fieldFilterPath/abstractions.js\";\nimport { FieldFilterValueTransformRegistry } from \"./fieldFilterValueTransform/abstractions.js\";\nimport { FieldFilterCreateRegistry } from \"./fieldFilterCreate/abstractions.js\";\nimport { FieldSortingRegistry } from \"./fieldSorting/abstractions.js\";\nimport { FieldFilterPathRegistryImpl } from \"./fieldFilterPath/FieldFilterPathRegistry.js\";\nimport { FieldFilterValueTransformRegistryImpl } from \"./fieldFilterValueTransform/FieldFilterValueTransformRegistry.js\";\nimport { FieldFilterCreateRegistryImpl } from \"./fieldFilterCreate/FieldFilterCreateRegistry.js\";\nimport { FieldSortingRegistryImpl } from \"./fieldSorting/FieldSortingRegistry.js\";\nimport { createPlainObjectPathHandler } from \"../handlers/plainObjectPathHandler.js\";\nimport { createLocationFolderIdPathHandler } from \"../handlers/locationFolderIdPathHandler.js\";\nimport { createDatetimeTransformHandler } from \"../handlers/datetimeTransformHandler.js\";\nimport { createDefaultFilterCreateHandler } from \"../handlers/defaultFilterCreateHandler.js\";\nimport { createRefFilterCreateHandler } from \"../handlers/refFilterCreateHandler.js\";\nimport { createObjectFilterCreateHandler } from \"../handlers/objectFilterCreateHandler.js\";\nimport { createSearchableJsonFilterCreateHandler } from \"../handlers/searchableJsonFilterCreateHandler.js\";\n\nexport const FilterRegistriesFeature = createFeature({\n name: \"cms.storage.filterRegistries\",\n register: container => {\n const pathRegistry = new FieldFilterPathRegistryImpl();\n pathRegistry.register(\"plainObject\", createPlainObjectPathHandler());\n pathRegistry.register(\"text\", createLocationFolderIdPathHandler());\n container.registerInstance(FieldFilterPathRegistry, pathRegistry);\n\n const transformRegistry = new FieldFilterValueTransformRegistryImpl();\n transformRegistry.register(\"datetime\", createDatetimeTransformHandler());\n container.registerInstance(FieldFilterValueTransformRegistry, transformRegistry);\n\n const filterCreateRegistry = new FieldFilterCreateRegistryImpl();\n filterCreateRegistry.register(\"*\", createDefaultFilterCreateHandler());\n filterCreateRegistry.register(\"ref\", createRefFilterCreateHandler());\n filterCreateRegistry.register(\"object\", createObjectFilterCreateHandler());\n filterCreateRegistry.register(\"searchable-json\", createSearchableJsonFilterCreateHandler());\n container.registerInstance(FieldFilterCreateRegistry, filterCreateRegistry);\n\n const sortingRegistry = new FieldSortingRegistryImpl();\n container.registerInstance(FieldSortingRegistry, sortingRegistry);\n }\n});\n"],"names":["FilterRegistriesFeature","createFeature","container","pathRegistry","FieldFilterPathRegistryImpl","createPlainObjectPathHandler","createLocationFolderIdPathHandler","FieldFilterPathRegistry","transformRegistry","FieldFilterValueTransformRegistryImpl","createDatetimeTransformHandler","FieldFilterValueTransformRegistry","filterCreateRegistry","FieldFilterCreateRegistryImpl","createDefaultFilterCreateHandler","createRefFilterCreateHandler","createObjectFilterCreateHandler","createSearchableJsonFilterCreateHandler","FieldFilterCreateRegistry","sortingRegistry","FieldSortingRegistryImpl","FieldSortingRegistry"],"mappings":";;;;;;;;;;;;;;;;AAiBO,MAAMA,0BAA0BC,cAAc;IACjD,MAAM;IACN,UAAUC,CAAAA;QACN,MAAMC,eAAe,IAAIC;QACzBD,aAAa,QAAQ,CAAC,eAAeE;QACrCF,aAAa,QAAQ,CAAC,QAAQG;QAC9BJ,UAAU,gBAAgB,CAACK,yBAAyBJ;QAEpD,MAAMK,oBAAoB,IAAIC;QAC9BD,kBAAkB,QAAQ,CAAC,YAAYE;QACvCR,UAAU,gBAAgB,CAACS,mCAAmCH;QAE9D,MAAMI,uBAAuB,IAAIC;QACjCD,qBAAqB,QAAQ,CAAC,KAAKE;QACnCF,qBAAqB,QAAQ,CAAC,OAAOG;QACrCH,qBAAqB,QAAQ,CAAC,UAAUI;QACxCJ,qBAAqB,QAAQ,CAAC,mBAAmBK;QACjDf,UAAU,gBAAgB,CAACgB,2BAA2BN;QAEtD,MAAMO,kBAAkB,IAAIC;QAC5BlB,UAAU,gBAAgB,CAACmB,sBAAsBF;IACrD;AACJ"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"filtering/fields/createFields.js","sources":["../../../src/filtering/fields/createFields.ts"],"sourcesContent":["import type { CmsModelField } from \"@webiny/api-headless-cms/types/index.js\";\nimport { createSystemFields } from \"./systemFields.js\";\nimport type { Field, FieldParent } from \"./types.js\";\nimport type { FieldFilterPathRegistry } from \"../../features/fieldFilterPath/abstractions.js\";\nimport type { FieldFilterValueTransformRegistry } from \"../../features/fieldFilterValueTransform/abstractions.js\";\nimport { getBaseFieldType } from \"@webiny/api-headless-cms/utils/getBaseFieldType.js\";\n\ninterface Params {\n fields: CmsModelField[];\n pathRegistry: FieldFilterPathRegistry.Interface;\n transformRegistry: FieldFilterValueTransformRegistry.Interface;\n}\n\ninterface FieldCollection {\n [key: string]: Field;\n}\n\ninterface AddFieldsToCollectionParams {\n fields: CmsModelField[];\n parents: FieldParent[];\n pathRegistry: FieldFilterPathRegistry.Interface;\n transformRegistry: FieldFilterValueTransformRegistry.Interface;\n system: boolean;\n}\n\nconst createFieldCollection = (params: AddFieldsToCollectionParams): FieldCollection => {\n const { fields, parents, pathRegistry, transformRegistry, system } = params;\n return fields.reduce<FieldCollection>((collection, field) => {\n const fieldType = getBaseFieldType(field);\n const transformHandler = transformRegistry.get(fieldType);\n const pathHandler = pathRegistry.get(fieldType);\n\n const fieldId = [\n ...parents,\n {\n fieldId: field.fieldId,\n list: field.list\n }\n ]\n .map(f => f.fieldId)\n .join(\".\");\n\n collection[fieldId] = {\n ...field,\n parents,\n system,\n createPath: pathParams => {\n if (\n pathHandler &&\n pathHandler.canUse(\n field,\n parents.map(p => p.fieldId)\n )\n ) {\n return pathHandler.createPath(pathParams);\n }\n\n return parents\n .map(parent => parent.fieldId)\n .concat([pathParams.field.fieldId])\n .join(\".\");\n },\n transform: value => {\n if (!transformHandler) {\n return value;\n }\n return transformHandler.transform({\n field,\n value\n });\n }\n };\n const childFields = field.settings?.fields;\n if (!childFields?.length) {\n return collection;\n }\n\n const result = createFieldCollection({\n fields: childFields,\n parents: [\n ...parents,\n {\n fieldId: field.fieldId,\n list: field.list\n }\n ],\n pathRegistry,\n transformRegistry,\n system\n });\n Object.assign(collection, result);\n return collection;\n }, {});\n};\n\nexport const createFields = (params: Params) => {\n const { fields, pathRegistry, transformRegistry } = params;\n\n const collection = createFieldCollection({\n fields: createSystemFields(),\n pathRegistry,\n transformRegistry,\n parents: [],\n system: true\n });\n\n const result = createFieldCollection({\n fields,\n pathRegistry,\n transformRegistry,\n parents: [\n {\n fieldId: \"values\",\n list: false\n }\n ],\n system: false\n });\n\n return {\n ...collection,\n ...result\n };\n};\n"],"names":["createFieldCollection","params","fields","parents","pathRegistry","transformRegistry","system","collection","field","fieldType","getBaseFieldType","transformHandler","pathHandler","fieldId","f","pathParams","p","parent","value","childFields","result","Object","createFields","createSystemFields"],"mappings":";;AAyBA,MAAMA,wBAAwB,CAACC;IAC3B,MAAM,EAAEC,MAAM,EAAEC,OAAO,EAAEC,YAAY,EAAEC,iBAAiB,EAAEC,MAAM,EAAE,GAAGL;IACrE,OAAOC,OAAO,MAAM,CAAkB,CAACK,YAAYC;QAC/C,MAAMC,YAAYC,iBAAiBF;QACnC,MAAMG,mBAAmBN,kBAAkB,GAAG,CAACI;QAC/C,MAAMG,cAAcR,aAAa,GAAG,CAACK;QAErC,MAAMI,UAAU;eACTV;YACH;gBACI,SAASK,MAAM,OAAO;gBACtB,MAAMA,MAAM,IAAI;YACpB;SACH,CACI,GAAG,CAACM,CAAAA,IAAKA,EAAE,OAAO,EAClB,IAAI,CAAC;QAEVP,UAAU,CAACM,QAAQ,GAAG;YAClB,GAAGL,KAAK;YACRL;YACAG;YACA,YAAYS,CAAAA;gBACR,IACIH,eACAA,YAAY,MAAM,CACdJ,OACAL,QAAQ,GAAG,CAACa,CAAAA,IAAKA,EAAE,OAAO,IAG9B,OAAOJ,YAAY,UAAU,CAACG;gBAGlC,OAAOZ,QACF,GAAG,CAACc,CAAAA,SAAUA,OAAO,OAAO,EAC5B,MAAM,CAAC;oBAACF,WAAW,KAAK,CAAC,OAAO;iBAAC,EACjC,IAAI,CAAC;YACd;YACA,WAAWG,CAAAA;gBACP,IAAI,CAACP,kBACD,OAAOO;gBAEX,OAAOP,iBAAiB,SAAS,CAAC;oBAC9BH;oBACAU;gBACJ;YACJ;QACJ;QACA,MAAMC,cAAcX,MAAM,QAAQ,EAAE;QACpC,IAAI,CAACW,aAAa,QACd,OAAOZ;QAGX,MAAMa,SAASpB,sBAAsB;YACjC,QAAQmB;YACR,SAAS;mBACFhB;gBACH;oBACI,SAASK,MAAM,OAAO;oBACtB,MAAMA,MAAM,IAAI;gBACpB;aACH;YACDJ;YACAC;YACAC;QACJ;QACAe,OAAO,MAAM,CAACd,YAAYa;QAC1B,OAAOb;IACX,GAAG,CAAC;AACR;AAEO,MAAMe,eAAe,CAACrB;IACzB,MAAM,EAAEC,MAAM,EAAEE,YAAY,EAAEC,iBAAiB,EAAE,GAAGJ;IAEpD,MAAMM,aAAaP,sBAAsB;QACrC,QAAQuB;QACRnB;QACAC;QACA,SAAS,EAAE;QACX,QAAQ;IACZ;IAEA,MAAMe,SAASpB,sBAAsB;QACjCE;QACAE;QACAC;QACA,SAAS;YACL;gBACI,SAAS;gBACT,MAAM;YACV;SACH;QACD,QAAQ;IACZ;IAEA,OAAO;QACH,GAAGE,UAAU;QACb,GAAGa,MAAM;IACb;AACJ"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"filtering/fields/systemFields.js","sources":["../../../src/filtering/fields/systemFields.ts"],"sourcesContent":["import type { CmsModelField } from \"@webiny/api-headless-cms/types/index.js\";\nimport {\n ENTRY_META_FIELDS,\n isDateTimeEntryMetaField,\n isIdentityEntryMetaField\n} from \"@webiny/api-headless-cms/constants.js\";\nimport lodashStartCase from \"lodash/startCase.js\";\nimport { createModelField } from \"@webiny/api-headless-cms\";\n\nexport const createSystemFields = (): CmsModelField[] => {\n const onMetaFields = ENTRY_META_FIELDS.filter(isDateTimeEntryMetaField).map<CmsModelField>(\n fieldName => {\n return createModelField({\n id: fieldName,\n type: \"datetime\",\n storageId: fieldName,\n fieldId: fieldName,\n label: lodashStartCase(fieldName)\n });\n }\n );\n\n const byMetaFields = ENTRY_META_FIELDS.filter(isIdentityEntryMetaField).map<CmsModelField>(\n fieldName => {\n return createModelField({\n id: fieldName,\n type: \"plainObject\",\n storageId: fieldName,\n fieldId: fieldName,\n label: lodashStartCase(fieldName),\n settings: {\n path: `${fieldName}.id`\n }\n });\n }\n );\n\n return [\n createModelField({\n id: \"id\",\n type: \"text\",\n storageId: \"id\",\n fieldId: \"id\",\n label: \"ID\"\n }),\n createModelField({\n id: \"entryId\",\n type: \"text\",\n storageId: \"entryId\",\n fieldId: \"entryId\",\n label: \"Entry ID\"\n }),\n\n ...onMetaFields,\n ...byMetaFields,\n\n createModelField({\n id: \"meta\",\n type: \"plainObject\",\n storageId: \"meta\",\n fieldId: \"meta\",\n label: \"Meta\"\n }),\n createModelField({\n id: \"wbyAco_location\",\n type: \"object\",\n storageId: \"location\",\n label: \"Location\",\n fieldId: \"wbyAco_location\",\n settings: {\n fields: [\n createModelField({\n id: \"folderId\",\n type: \"text\",\n fieldId: \"folderId\",\n label: \"Folder ID\",\n storageId: \"folderId\",\n settings: {\n path: \"location.folderId\"\n }\n })\n ]\n }\n }),\n\n createModelField({\n id: \"version\",\n type: \"number\",\n storageId: \"version\",\n fieldId: \"version\",\n label: \"Version\"\n }),\n createModelField({\n id: \"status\",\n type: \"text\",\n storageId: \"status\",\n fieldId: \"status\",\n label: \"Status\"\n }),\n createModelField({\n id: \"wbyDeleted\",\n type: \"boolean\",\n storageId: \"wbyDeleted\",\n fieldId: \"wbyDeleted\",\n label: \"Deleted\"\n }),\n createModelField({\n id: \"state\",\n type: \"object\",\n storageId: \"object@state\",\n fieldId: \"state\",\n label: \"State\",\n settings: {\n fields: [\n createModelField({\n id: \"stepId\",\n type: \"text\",\n fieldId: \"stepId\",\n label: \"Step ID\",\n storageId: \"stepId\"\n }),\n createModelField({\n id: \"stepName\",\n type: \"text\",\n fieldId: \"stepName\",\n label: \"Step Name\",\n storageId: \"stepName\"\n }),\n createModelField({\n id: \"state\",\n type: \"text\",\n fieldId: \"state\",\n label: \"State\",\n storageId: \"state\"\n })\n ]\n }\n }),\n createModelField({\n id: \"values\",\n type: \"object\",\n storageId: \"values\",\n fieldId: \"values\",\n label: \"Values\"\n }),\n createModelField({\n id: \"live\",\n type: \"object\",\n storageId: \"live\",\n fieldId: \"live\",\n label: \"Live\",\n settings: {\n fields: [\n createModelField({\n id: \"version\",\n type: \"number\",\n fieldId: \"version\",\n label: \"Version\",\n storageId: \"version\"\n })\n ]\n }\n })\n ];\n};\n"],"names":["createSystemFields","onMetaFields","ENTRY_META_FIELDS","isDateTimeEntryMetaField","fieldName","createModelField","lodashStartCase","byMetaFields","isIdentityEntryMetaField"],"mappings":";;;AASO,MAAMA,qBAAqB;IAC9B,MAAMC,eAAeC,kBAAkB,MAAM,CAACC,0BAA0B,GAAG,CACvEC,CAAAA,YACWC,iBAAiB;YACpB,IAAID;YACJ,MAAM;YACN,WAAWA;YACX,SAASA;YACT,OAAOE,UAAgBF;QAC3B;IAIR,MAAMG,eAAeL,kBAAkB,MAAM,CAACM,0BAA0B,GAAG,CACvEJ,CAAAA,YACWC,iBAAiB;YACpB,IAAID;YACJ,MAAM;YACN,WAAWA;YACX,SAASA;YACT,OAAOE,UAAgBF;YACvB,UAAU;gBACN,MAAM,GAAGA,UAAU,GAAG,CAAC;YAC3B;QACJ;IAIR,OAAO;QACHC,iBAAiB;YACb,IAAI;YACJ,MAAM;YACN,WAAW;YACX,SAAS;YACT,OAAO;QACX;QACAA,iBAAiB;YACb,IAAI;YACJ,MAAM;YACN,WAAW;YACX,SAAS;YACT,OAAO;QACX;WAEGJ;WACAM;QAEHF,iBAAiB;YACb,IAAI;YACJ,MAAM;YACN,WAAW;YACX,SAAS;YACT,OAAO;QACX;QACAA,iBAAiB;YACb,IAAI;YACJ,MAAM;YACN,WAAW;YACX,OAAO;YACP,SAAS;YACT,UAAU;gBACN,QAAQ;oBACJA,iBAAiB;wBACb,IAAI;wBACJ,MAAM;wBACN,SAAS;wBACT,OAAO;wBACP,WAAW;wBACX,UAAU;4BACN,MAAM;wBACV;oBACJ;iBACH;YACL;QACJ;QAEAA,iBAAiB;YACb,IAAI;YACJ,MAAM;YACN,WAAW;YACX,SAAS;YACT,OAAO;QACX;QACAA,iBAAiB;YACb,IAAI;YACJ,MAAM;YACN,WAAW;YACX,SAAS;YACT,OAAO;QACX;QACAA,iBAAiB;YACb,IAAI;YACJ,MAAM;YACN,WAAW;YACX,SAAS;YACT,OAAO;QACX;QACAA,iBAAiB;YACb,IAAI;YACJ,MAAM;YACN,WAAW;YACX,SAAS;YACT,OAAO;YACP,UAAU;gBACN,QAAQ;oBACJA,iBAAiB;wBACb,IAAI;wBACJ,MAAM;wBACN,SAAS;wBACT,OAAO;wBACP,WAAW;oBACf;oBACAA,iBAAiB;wBACb,IAAI;wBACJ,MAAM;wBACN,SAAS;wBACT,OAAO;wBACP,WAAW;oBACf;oBACAA,iBAAiB;wBACb,IAAI;wBACJ,MAAM;wBACN,SAAS;wBACT,OAAO;wBACP,WAAW;oBACf;iBACH;YACL;QACJ;QACAA,iBAAiB;YACb,IAAI;YACJ,MAAM;YACN,WAAW;YACX,SAAS;YACT,OAAO;QACX;QACAA,iBAAiB;YACb,IAAI;YACJ,MAAM;YACN,WAAW;YACX,SAAS;YACT,OAAO;YACP,UAAU;gBACN,QAAQ;oBACJA,iBAAiB;wBACb,IAAI;wBACJ,MAAM;wBACN,SAAS;wBACT,OAAO;wBACP,WAAW;oBACf;iBACH;YACL;QACJ;KACH;AACL"}
|
package/dist/package.json
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@webiny/api-headless-cms-storage",
|
|
3
|
-
"version": "0.0.0",
|
|
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",
|
|
14
|
-
"@webiny/api-headless-cms": "0.0.0",
|
|
15
|
-
"@webiny/db-utils": "0.0.0",
|
|
16
|
-
"@webiny/di": "1.0.2",
|
|
17
|
-
"@webiny/error": "0.0.0",
|
|
18
|
-
"@webiny/feature": "0.0.0",
|
|
19
|
-
"@webiny/plugins": "0.0.0",
|
|
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",
|
|
26
|
-
"@webiny/project-utils": "0.0.0",
|
|
27
|
-
"typescript": "7.0.2",
|
|
28
|
-
"vitest": "4.1.10"
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
CmsEntry,
|
|
3
|
-
CmsEntryUniqueValue,
|
|
4
|
-
CmsEntryValues,
|
|
5
|
-
CmsModel,
|
|
6
|
-
CmsModelField,
|
|
7
|
-
StorageOperationsCmsModel
|
|
8
|
-
} from "@webiny/api-headless-cms/types/index.js";
|
|
9
|
-
import type { Container } from "@webiny/di";
|
|
10
|
-
import { CmsStorageModelProvider } from "@webiny/api-headless-cms/features/shared/abstractions.js";
|
|
11
|
-
import { getBaseFieldType } from "@webiny/api-headless-cms/utils/getBaseFieldType.js";
|
|
12
|
-
import type { StorageTransformRegistry } from "@webiny/api-headless-cms/exports/api/cms/storage.js";
|
|
13
|
-
import type { FilterItemFromStorage } from "../filtering/fields/types.js";
|
|
14
|
-
|
|
15
|
-
/* Creates a lazy-cached getter for the storage representation of a CMS model. */
|
|
16
|
-
export const createStorageModelAccessor = (container: Container) => {
|
|
17
|
-
let cached: CmsStorageModelProvider.Interface | undefined;
|
|
18
|
-
|
|
19
|
-
const getProvider = () => {
|
|
20
|
-
if (!cached) {
|
|
21
|
-
cached = container.resolve(CmsStorageModelProvider);
|
|
22
|
-
}
|
|
23
|
-
return cached;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const getModel = <T extends CmsEntryValues = CmsEntryValues>(
|
|
27
|
-
model: CmsModel
|
|
28
|
-
): StorageOperationsCmsModel<T> => {
|
|
29
|
-
return getProvider().getModel<T>(model);
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
return { getModel };
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
/* Creates a fromStorage transform callable for a given model. */
|
|
36
|
-
export const createStorageTransformCallable = (
|
|
37
|
-
storageTransformRegistry: StorageTransformRegistry.Interface,
|
|
38
|
-
model: StorageOperationsCmsModel
|
|
39
|
-
): FilterItemFromStorage => {
|
|
40
|
-
return async (field: CmsModelField, value: unknown) => {
|
|
41
|
-
const fieldType = getBaseFieldType(field);
|
|
42
|
-
const storageTransform = storageTransformRegistry.get(fieldType);
|
|
43
|
-
|
|
44
|
-
if (!storageTransform) {
|
|
45
|
-
return value;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const result = await storageTransform.fromStorage({
|
|
49
|
-
model,
|
|
50
|
-
field,
|
|
51
|
-
value,
|
|
52
|
-
getStorageTransform(ft: string) {
|
|
53
|
-
return storageTransformRegistry.get(ft) || storageTransformRegistry.get("*")!;
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
return result;
|
|
58
|
-
};
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
/* Aggregates unique values for a given field across a list of CMS entries. */
|
|
62
|
-
export const aggregateUniqueFieldValues = <T extends CmsEntryValues = CmsEntryValues>(
|
|
63
|
-
items: CmsEntry<T>[],
|
|
64
|
-
fieldId: string
|
|
65
|
-
): CmsEntryUniqueValue[] => {
|
|
66
|
-
const result: Record<string, CmsEntryUniqueValue> = {};
|
|
67
|
-
|
|
68
|
-
for (const item of items) {
|
|
69
|
-
const fieldValue = item.values[fieldId] as string[] | string | undefined;
|
|
70
|
-
|
|
71
|
-
if (fieldValue == null) {
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const values = Array.isArray(fieldValue) ? fieldValue : [fieldValue];
|
|
76
|
-
|
|
77
|
-
if (values.length === 0) {
|
|
78
|
-
continue;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
for (const value of values) {
|
|
82
|
-
result[value] = {
|
|
83
|
-
value,
|
|
84
|
-
count: (result[value]?.count || 0) + 1
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return Object.values(result)
|
|
90
|
-
.sort((a, b) => (a.value > b.value ? 1 : b.value > a.value ? -1 : 0))
|
|
91
|
-
.sort((a, b) => b.count - a.count);
|
|
92
|
-
};
|