@webiny/api-headless-cms-ddb 0.0.0-unstable.e3f4727c56 → 0.0.0-unstable.eb196ccd2f
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/definitions/entry.d.ts +4 -3
- package/definitions/entry.js +108 -16
- package/definitions/entry.js.map +1 -1
- package/definitions/group.d.ts +4 -3
- package/definitions/group.js +8 -12
- package/definitions/group.js.map +1 -1
- package/definitions/model.d.ts +4 -3
- package/definitions/model.js +25 -12
- package/definitions/model.js.map +1 -1
- package/definitions/system.d.ts +4 -3
- package/definitions/system.js +8 -12
- package/definitions/system.js.map +1 -1
- package/definitions/table.d.ts +5 -5
- package/definitions/table.js +7 -6
- package/definitions/table.js.map +1 -1
- package/dynamoDb/index.js +4 -9
- package/dynamoDb/index.js.map +1 -1
- package/dynamoDb/path/locationFolderId.d.ts +2 -0
- package/dynamoDb/path/locationFolderId.js +43 -0
- package/dynamoDb/path/locationFolderId.js.map +1 -0
- package/dynamoDb/path/plainObject.js +3 -8
- package/dynamoDb/path/plainObject.js.map +1 -1
- package/dynamoDb/storage/longText.js +4 -18
- package/dynamoDb/storage/longText.js.map +1 -1
- package/dynamoDb/storage/richText.js +23 -75
- package/dynamoDb/storage/richText.js.map +1 -1
- package/dynamoDb/transformValue/datetime.d.ts +1 -1
- package/dynamoDb/transformValue/datetime.js +3 -8
- package/dynamoDb/transformValue/datetime.js.map +1 -1
- package/index.d.ts +1 -1
- package/index.js +15 -44
- package/index.js.map +1 -1
- package/operations/entry/dataLoader/DataLoaderCache.d.ts +17 -0
- package/operations/entry/dataLoader/DataLoaderCache.js +41 -0
- package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -0
- package/operations/entry/dataLoader/constants.d.ts +1 -0
- package/operations/entry/dataLoader/constants.js +10 -0
- package/operations/entry/dataLoader/constants.js.map +1 -0
- package/operations/entry/dataLoader/createBatchScheduleFn.d.ts +8 -0
- package/operations/entry/dataLoader/createBatchScheduleFn.js +25 -0
- package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -0
- package/operations/entry/dataLoader/getAllEntryRevisions.d.ts +4 -0
- package/operations/entry/dataLoader/getAllEntryRevisions.js +45 -0
- package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -0
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.d.ts +4 -0
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +56 -0
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -0
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.d.ts +4 -0
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +56 -0
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -0
- package/operations/entry/dataLoader/getRevisionById.d.ts +4 -0
- package/operations/entry/dataLoader/getRevisionById.js +62 -0
- package/operations/entry/dataLoader/getRevisionById.js.map +1 -0
- package/operations/entry/dataLoader/index.d.ts +8 -0
- package/operations/entry/dataLoader/index.js +40 -0
- package/operations/entry/dataLoader/index.js.map +1 -0
- package/operations/entry/dataLoader/types.d.ts +6 -0
- package/operations/entry/dataLoader/types.js +7 -0
- package/operations/entry/dataLoader/types.js.map +1 -0
- package/operations/entry/dataLoaders.d.ts +12 -27
- package/operations/entry/dataLoaders.js +55 -260
- package/operations/entry/dataLoaders.js.map +1 -1
- package/operations/entry/filtering/createExpressions.d.ts +4 -4
- package/operations/entry/filtering/createExpressions.js +4 -39
- package/operations/entry/filtering/createExpressions.js.map +1 -1
- package/operations/entry/filtering/createFields.d.ts +6 -4
- package/operations/entry/filtering/createFields.js +76 -91
- package/operations/entry/filtering/createFields.js.map +1 -1
- package/operations/entry/filtering/extractSort.d.ts +3 -3
- package/operations/entry/filtering/extractSort.js +2 -10
- package/operations/entry/filtering/extractSort.js.map +1 -1
- package/operations/entry/filtering/filter.d.ts +3 -3
- package/operations/entry/filtering/filter.js +24 -44
- package/operations/entry/filtering/filter.js.map +1 -1
- package/operations/entry/filtering/fullTextSearch.d.ts +3 -3
- package/operations/entry/filtering/fullTextSearch.js +2 -12
- package/operations/entry/filtering/fullTextSearch.js.map +1 -1
- package/operations/entry/filtering/getValue.js +5 -20
- package/operations/entry/filtering/getValue.js.map +1 -1
- package/operations/entry/filtering/index.js +2 -2
- package/operations/entry/filtering/index.js.map +1 -1
- package/operations/entry/filtering/mapPlugins.d.ts +2 -2
- package/operations/entry/filtering/mapPlugins.js +2 -8
- package/operations/entry/filtering/mapPlugins.js.map +1 -1
- package/operations/entry/filtering/plugins/defaultFilterCreate.d.ts +1 -1
- package/operations/entry/filtering/plugins/defaultFilterCreate.js +5 -8
- package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -1
- package/operations/entry/filtering/plugins/index.d.ts +1 -1
- package/operations/entry/filtering/plugins/index.js +4 -6
- package/operations/entry/filtering/plugins/index.js.map +1 -1
- package/operations/entry/filtering/plugins/objectFilterCreate.d.ts +1 -1
- package/operations/entry/filtering/plugins/objectFilterCreate.js +5 -22
- package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -1
- package/operations/entry/filtering/plugins/refFilterCreate.d.ts +2 -1
- package/operations/entry/filtering/plugins/refFilterCreate.js +11 -20
- package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -1
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.d.ts +2 -0
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js +65 -0
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js.map +1 -0
- package/operations/entry/filtering/sort.d.ts +3 -3
- package/operations/entry/filtering/sort.js +4 -17
- package/operations/entry/filtering/sort.js.map +1 -1
- package/operations/entry/filtering/systemFields.d.ts +2 -2
- package/operations/entry/filtering/systemFields.js +48 -30
- package/operations/entry/filtering/systemFields.js.map +1 -1
- package/operations/entry/filtering/transform.d.ts +1 -1
- package/operations/entry/filtering/transform.js +2 -3
- package/operations/entry/filtering/transform.js.map +1 -1
- package/operations/entry/filtering/types.d.ts +2 -2
- package/operations/entry/filtering/types.js +3 -1
- package/operations/entry/filtering/types.js.map +1 -1
- package/operations/entry/filtering/values.d.ts +1 -1
- package/operations/entry/filtering/values.js +2 -6
- package/operations/entry/filtering/values.js.map +1 -1
- package/operations/entry/filtering/where.js +5 -8
- package/operations/entry/filtering/where.js.map +1 -1
- package/operations/entry/index.d.ts +3 -3
- package/operations/entry/index.js +705 -273
- package/operations/entry/index.js.map +1 -1
- package/operations/entry/keys.js +2 -18
- package/operations/entry/keys.js.map +1 -1
- package/operations/group/index.d.ts +3 -3
- package/operations/group/index.js +33 -51
- package/operations/group/index.js.map +1 -1
- package/operations/model/index.d.ts +2 -2
- package/operations/model/index.js +25 -37
- package/operations/model/index.js.map +1 -1
- package/operations/system/index.d.ts +2 -2
- package/operations/system/index.js +18 -23
- package/operations/system/index.js.map +1 -1
- package/package.json +21 -26
- package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +3 -2
- package/plugins/CmsEntryFieldFilterPathPlugin.js +11 -18
- package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -1
- package/plugins/CmsEntryFieldFilterPlugin.d.ts +10 -10
- package/plugins/CmsEntryFieldFilterPlugin.js +8 -12
- package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -1
- package/plugins/CmsEntryFieldSortingPlugin.d.ts +2 -2
- package/plugins/CmsEntryFieldSortingPlugin.js +3 -14
- package/plugins/CmsEntryFieldSortingPlugin.js.map +1 -1
- package/plugins/CmsFieldFilterValueTransformPlugin.d.ts +11 -0
- package/plugins/CmsFieldFilterValueTransformPlugin.js +23 -0
- package/plugins/CmsFieldFilterValueTransformPlugin.js.map +1 -0
- package/plugins/index.d.ts +1 -0
- package/plugins/index.js +14 -7
- package/plugins/index.js.map +1 -1
- package/types.d.ts +20 -13
- package/types.js +5 -6
- package/types.js.map +1 -1
- package/definitions/settings.d.ts +0 -9
- package/definitions/settings.js +0 -58
- package/definitions/settings.js.map +0 -1
- package/dynamoDb/storage/date.d.ts +0 -3
- package/dynamoDb/storage/date.js +0 -109
- package/dynamoDb/storage/date.js.map +0 -1
- package/operations/entry/systemFields.d.ts +0 -2
- package/operations/entry/systemFields.js +0 -74
- package/operations/entry/systemFields.js.map +0 -1
- package/operations/settings/index.d.ts +0 -7
- package/operations/settings/index.js +0 -135
- package/operations/settings/index.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createExpressions","params","where","plugins","fields","filterPlugins","getMappedPlugins","type","ValueFilterPlugin","property","transformValuePlugins","fieldFilterCreatePlugins","CmsEntryFieldFilterPlugin","defaultFilterCreatePlugin","getFilterCreatePlugin","filterCreatePlugin","WebinyError","createExpression","condition","expression","filters","expressions","key","value","undefined","childWhereList","getWhereValues","childExpression","childWhere","result","push","whereParams","extractWhereParams","fieldId","operation","negate","field","transformValuePlugin","transformValueCallable","transform","create","valueFilterPlugins","compareValue","transformValue","Array","isArray","length"],"sources":["createExpressions.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsEntryListWhere } from \"@webiny/api-headless-cms/types\";\nimport { ValueFilterPlugin } from \"@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin\";\nimport { CmsFieldFilterValueTransformPlugin } from \"~/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { Field } from \"./types\";\nimport { getMappedPlugins } from \"./mapPlugins\";\nimport { extractWhereParams } from \"./where\";\nimport { transformValue } from \"./transform\";\nimport { CmsEntryFieldFilterPlugin } from \"~/plugins/CmsEntryFieldFilterPlugin\";\nimport { getWhereValues } from \"~/operations/entry/filtering/values\";\n\ninterface CreateExpressionParams {\n where: Partial<CmsEntryListWhere>;\n condition: ExpressionCondition;\n}\n\ninterface CreateExpressionCb {\n (params: CreateExpressionParams): Expression;\n}\n\ninterface Params {\n plugins: PluginsContainer;\n where: Partial<CmsEntryListWhere>;\n fields: Record<string, Field>;\n}\n\nexport type ExpressionCondition = \"AND\" | \"OR\";\n\nexport interface Expression {\n expressions: Expression[];\n filters: Filter[];\n condition: ExpressionCondition;\n}\n\nexport interface Filter {\n field: Field;\n path: string;\n fieldPathId: string;\n plugin: ValueFilterPlugin;\n negate: boolean;\n compareValue: any;\n transformValue: <I = any, O = any>(value: I) => O;\n}\n\nexport const createExpressions = (params: Params): Expression => {\n const { where, plugins, fields } = params;\n const filterPlugins = getMappedPlugins<ValueFilterPlugin>({\n plugins,\n type: ValueFilterPlugin.type,\n property: \"operation\"\n });\n const transformValuePlugins = getMappedPlugins<CmsFieldFilterValueTransformPlugin>({\n plugins,\n type: \"cms-field-filter-value-transform\",\n property: \"fieldType\"\n });\n const fieldFilterCreatePlugins = getMappedPlugins<CmsEntryFieldFilterPlugin>({\n plugins,\n type: CmsEntryFieldFilterPlugin.type,\n property: \"fieldType\"\n });\n\n const defaultFilterCreatePlugin = fieldFilterCreatePlugins[\"*\"] as CmsEntryFieldFilterPlugin;\n\n const getFilterCreatePlugin = (type: string) => {\n const filterCreatePlugin = fieldFilterCreatePlugins[type] || defaultFilterCreatePlugin;\n if (filterCreatePlugin) {\n return filterCreatePlugin;\n }\n throw new WebinyError(\n `There is no filter create plugin for the field type \"${type}\".`,\n \"MISSING_FILTER_CREATE_PLUGIN\",\n {\n type\n }\n );\n };\n\n const createExpression: CreateExpressionCb = ({ where, condition }) => {\n const expression: Expression = {\n filters: [],\n expressions: [],\n condition\n };\n\n for (const key in where) {\n const value = (where as any)[key];\n if (value === undefined) {\n continue;\n }\n\n /**\n * If there are \"AND\" or \"OR\" keys, let's sort them out first.\n *\n *\n * AND conditional\n */\n if (key === \"AND\") {\n const childWhereList = getWhereValues(value, key);\n const childExpression: Expression = {\n condition: \"AND\",\n filters: [],\n expressions: []\n };\n for (const childWhere of childWhereList) {\n const result = createExpression({\n where: childWhere,\n condition: \"AND\"\n });\n childExpression.expressions.push(result);\n }\n expression.expressions.push(childExpression);\n continue;\n }\n /**\n * OR conditional\n */\n if (key === \"OR\") {\n const childWhereList = getWhereValues(value, key);\n\n const childExpression: Expression = {\n condition: \"OR\",\n filters: [],\n expressions: []\n };\n for (const childWhere of childWhereList) {\n const result = createExpression({\n where: childWhere,\n condition: \"AND\"\n });\n childExpression.expressions.push(result);\n }\n expression.expressions.push(childExpression);\n continue;\n }\n\n const whereParams = extractWhereParams(key);\n if (!whereParams) {\n continue;\n }\n\n const { fieldId, operation, negate } = whereParams;\n\n const field = fields[fieldId];\n if (!field) {\n throw new WebinyError(\n `There is no field with the fieldId \"${fieldId}\".`,\n \"FIELD_ERROR\",\n {\n fieldId\n }\n );\n }\n\n /**\n * We need a filter create plugin for this type.\n */\n const filterCreatePlugin = getFilterCreatePlugin(field.type);\n\n const transformValuePlugin: CmsFieldFilterValueTransformPlugin =\n transformValuePlugins[field.type];\n\n const transformValueCallable = (value: any) => {\n if (!transformValuePlugin) {\n return value;\n }\n return transformValuePlugin.transform({\n field,\n value\n });\n };\n\n const result = filterCreatePlugin.create({\n key,\n value,\n valueFilterPlugins: filterPlugins,\n transformValuePlugins,\n getFilterCreatePlugin,\n operation,\n negate,\n field,\n fields,\n compareValue: transformValue({\n value,\n transform: transformValueCallable\n }),\n transformValue: transformValueCallable\n });\n /**\n * There is a possibility of\n * - no result\n * - result being an array\n * - result being an object\n */\n if (!result || (Array.isArray(result) && result.length === 0)) {\n continue;\n }\n\n expression.filters.push(...(Array.isArray(result) ? result : [result]));\n }\n\n return expression;\n };\n\n const expression = createExpression({\n where,\n condition: \"AND\"\n });\n /**\n * If the first expression has no filters and has only one expression, put that expression as main one.\n * This will mostly be used when having an OR condition as the single expression in the root level of the where\n */\n if (expression.filters.length > 0 || expression.expressions.length !== 1) {\n return expression;\n }\n return expression.expressions[0];\n};\n"],"mappings":";;;;;;;;;AAAA;;AAEA;;AAIA;;AACA;;AACA;;AACA;;AACA;;AAmCO,MAAMA,iBAAiB,GAAIC,MAAD,IAAgC;EAC7D,MAAM;IAAEC,KAAF;IAASC,OAAT;IAAkBC;EAAlB,IAA6BH,MAAnC;EACA,MAAMI,aAAa,GAAG,IAAAC,4B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U,CAACC,OAAX,CAAmB0B,MAAnB,GAA4B,CAA5B,IAAiC3B,UAAU,CAACE,WAAX,CAAuByB,MAAvB,KAAkC,CAAvE,EAA0E;IACtE,OAAO3B,UAAP;EACH;;EACD,OAAOA,UAAU,CAACE,WAAX,CAAuB,CAAvB,CAAP;AACH,CA5KM"}
|
|
1
|
+
{"version":3,"names":["_error","_interopRequireDefault","require","_ValueFilterPlugin","_mapPlugins","_where","_transform","_CmsEntryFieldFilterPlugin","_values","createExpressions","params","where","plugins","fields","filterPlugins","getMappedPlugins","type","ValueFilterPlugin","property","transformValuePlugins","fieldFilterCreatePlugins","CmsEntryFieldFilterPlugin","defaultFilterCreatePlugin","getFilterCreatePlugin","filterCreatePlugin","WebinyError","createExpression","condition","expression","filters","expressions","key","value","undefined","childWhereList","getWhereValues","childExpression","childWhere","result","push","whereParams","extractWhereParams","fieldId","operation","negate","field","transformValuePlugin","transformValueCallable","transform","create","valueFilterPlugins","compareValue","transformValue","Array","isArray","length","exports"],"sources":["createExpressions.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsEntryListWhere } from \"@webiny/api-headless-cms/types\";\nimport { ValueFilterPlugin } from \"@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin\";\nimport type { CmsFieldFilterValueTransformPlugin } from \"~/types\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport type { Field } from \"./types\";\nimport { getMappedPlugins } from \"./mapPlugins\";\nimport { extractWhereParams } from \"./where\";\nimport { transformValue } from \"./transform\";\nimport { CmsEntryFieldFilterPlugin } from \"~/plugins/CmsEntryFieldFilterPlugin\";\nimport { getWhereValues } from \"~/operations/entry/filtering/values\";\n\ninterface CreateExpressionParams {\n where: Partial<CmsEntryListWhere>;\n condition: ExpressionCondition;\n}\n\ninterface CreateExpressionCb {\n (params: CreateExpressionParams): Expression;\n}\n\ninterface Params {\n plugins: PluginsContainer;\n where: Partial<CmsEntryListWhere>;\n fields: Record<string, Field>;\n}\n\nexport type ExpressionCondition = \"AND\" | \"OR\";\n\nexport interface Expression {\n expressions: Expression[];\n filters: Filter[];\n condition: ExpressionCondition;\n}\n\nexport interface Filter {\n field: Field;\n path: string;\n fieldPathId: string;\n plugin: ValueFilterPlugin;\n negate: boolean;\n compareValue: any;\n transformValue: <I = any, O = any>(value: I) => O;\n}\n\nexport const createExpressions = (params: Params): Expression => {\n const { where, plugins, fields } = params;\n const filterPlugins = getMappedPlugins<ValueFilterPlugin>({\n plugins,\n type: ValueFilterPlugin.type,\n property: \"operation\"\n });\n const transformValuePlugins = getMappedPlugins<CmsFieldFilterValueTransformPlugin>({\n plugins,\n type: \"cms-field-filter-value-transform\",\n property: \"fieldType\"\n });\n const fieldFilterCreatePlugins = getMappedPlugins<CmsEntryFieldFilterPlugin>({\n plugins,\n type: CmsEntryFieldFilterPlugin.type,\n property: \"fieldType\"\n });\n\n const defaultFilterCreatePlugin = fieldFilterCreatePlugins[\"*\"] as CmsEntryFieldFilterPlugin;\n\n const getFilterCreatePlugin = (type: string) => {\n const filterCreatePlugin = fieldFilterCreatePlugins[type] || defaultFilterCreatePlugin;\n if (filterCreatePlugin) {\n return filterCreatePlugin;\n }\n throw new WebinyError(\n `There is no filter create plugin for the field type \"${type}\".`,\n \"MISSING_FILTER_CREATE_PLUGIN\",\n {\n type\n }\n );\n };\n\n const createExpression: CreateExpressionCb = ({ where, condition }) => {\n const expression: Expression = {\n filters: [],\n expressions: [],\n condition\n };\n\n for (const key in where) {\n const value = where[key];\n if (value === undefined) {\n continue;\n }\n\n /**\n * If there are \"AND\" or \"OR\" keys, let's sort them out first.\n *\n *\n * AND conditional\n */\n if (key === \"AND\") {\n const childWhereList = getWhereValues(value, key);\n const childExpression: Expression = {\n condition: \"AND\",\n filters: [],\n expressions: []\n };\n for (const childWhere of childWhereList) {\n const result = createExpression({\n where: childWhere,\n condition: \"AND\"\n });\n childExpression.expressions.push(result);\n }\n expression.expressions.push(childExpression);\n continue;\n }\n /**\n * OR conditional\n */\n if (key === \"OR\") {\n const childWhereList = getWhereValues(value, key);\n\n const childExpression: Expression = {\n condition: \"OR\",\n filters: [],\n expressions: []\n };\n for (const childWhere of childWhereList) {\n const result = createExpression({\n where: childWhere,\n condition: \"AND\"\n });\n childExpression.expressions.push(result);\n }\n expression.expressions.push(childExpression);\n continue;\n }\n\n const whereParams = extractWhereParams(key);\n if (!whereParams) {\n continue;\n }\n\n const { fieldId, operation, negate } = whereParams;\n\n const field = fields[fieldId];\n if (!field) {\n throw new WebinyError(\n `There is no field with the fieldId \"${fieldId}\".`,\n \"FIELD_ERROR\",\n {\n fieldId\n }\n );\n }\n\n /**\n * We need a filter create plugin for this type.\n */\n const filterCreatePlugin = getFilterCreatePlugin(field.type);\n\n const transformValuePlugin: CmsFieldFilterValueTransformPlugin =\n transformValuePlugins[field.type];\n\n const transformValueCallable = (value: any) => {\n if (!transformValuePlugin) {\n return value;\n }\n return transformValuePlugin.transform({\n field,\n value\n });\n };\n\n const result = filterCreatePlugin.create({\n key,\n value,\n valueFilterPlugins: filterPlugins,\n transformValuePlugins,\n getFilterCreatePlugin,\n operation,\n negate,\n field,\n fields,\n compareValue: transformValue({\n value,\n transform: transformValueCallable\n }),\n transformValue: transformValueCallable\n });\n /**\n * There is a possibility of\n * - no result\n * - result being an array\n * - result being an object\n */\n if (!result || (Array.isArray(result) && result.length === 0)) {\n continue;\n }\n\n expression.filters.push(...(Array.isArray(result) ? result : [result]));\n }\n\n return expression;\n };\n\n const expression = createExpression({\n where,\n condition: \"AND\"\n });\n /**\n * If the first expression has no filters and has only one expression, put that expression as main one.\n * This will mostly be used when having an OR condition as the single expression in the root level of the where\n */\n if (expression.filters.length > 0 || expression.expressions.length !== 1) {\n return expression;\n }\n return expression.expressions[0];\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,kBAAA,GAAAD,OAAA;AAIA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAA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U,GAAGF,gBAAgB,CAAC;IAChCf,KAAK;IACLgB,SAAS,EAAE;EACf,CAAC,CAAC;EACF;AACJ;AACA;AACA;EACI,IAAIC,UAAU,CAACC,OAAO,CAAC0B,MAAM,GAAG,CAAC,IAAI3B,UAAU,CAACE,WAAW,CAACyB,MAAM,KAAK,CAAC,EAAE;IACtE,OAAO3B,UAAU;EACrB;EACA,OAAOA,UAAU,CAACE,WAAW,CAAC,CAAC,CAAC;AACpC,CAAC;AAAC0B,OAAA,CAAA/C,iBAAA,GAAAA,iBAAA","ignoreList":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { CmsModelField } from "@webiny/api-headless-cms/types";
|
|
2
|
-
import { Field } from "./types";
|
|
3
|
-
import { PluginsContainer } from "@webiny/plugins";
|
|
1
|
+
import type { CmsModelField } from "@webiny/api-headless-cms/types";
|
|
2
|
+
import type { Field } from "./types";
|
|
3
|
+
import type { PluginsContainer } from "@webiny/plugins";
|
|
4
4
|
interface Params {
|
|
5
5
|
fields: CmsModelField[];
|
|
6
6
|
plugins: PluginsContainer;
|
|
@@ -10,5 +10,7 @@ interface Params {
|
|
|
10
10
|
*
|
|
11
11
|
* In case of nested fields, fieldId is all the parent fieldIds + current one, joined by the dot (.).
|
|
12
12
|
*/
|
|
13
|
-
export declare const createFields: (params: Params) =>
|
|
13
|
+
export declare const createFields: (params: Params) => {
|
|
14
|
+
[x: string]: Field;
|
|
15
|
+
};
|
|
14
16
|
export {};
|
|
@@ -1,20 +1,69 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
8
6
|
exports.createFields = void 0;
|
|
9
|
-
|
|
10
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
-
|
|
12
7
|
var _systemFields = require("./systemFields");
|
|
13
|
-
|
|
14
8
|
var _plugins = require("../../../plugins");
|
|
15
|
-
|
|
16
9
|
var _mapPlugins = require("./mapPlugins");
|
|
17
|
-
|
|
10
|
+
const createFieldCollection = params => {
|
|
11
|
+
const {
|
|
12
|
+
fields,
|
|
13
|
+
parents,
|
|
14
|
+
transformValuePlugins,
|
|
15
|
+
valuePathPlugins,
|
|
16
|
+
system
|
|
17
|
+
} = params;
|
|
18
|
+
return fields.reduce((collection, field) => {
|
|
19
|
+
const transformPlugin = transformValuePlugins[field.type];
|
|
20
|
+
const valuePathPlugin = valuePathPlugins[field.type];
|
|
21
|
+
const basePath = system ? [] : ["values"];
|
|
22
|
+
/**
|
|
23
|
+
* The required fieldId is a product of all of its parents and its own fieldId.
|
|
24
|
+
*/
|
|
25
|
+
const fieldId = [...parents, {
|
|
26
|
+
fieldId: field.fieldId,
|
|
27
|
+
multipleValues: field.multipleValues
|
|
28
|
+
}].map(f => f.fieldId).join(".");
|
|
29
|
+
collection[fieldId] = {
|
|
30
|
+
...field,
|
|
31
|
+
parents,
|
|
32
|
+
system,
|
|
33
|
+
createPath: params => {
|
|
34
|
+
if (valuePathPlugin && valuePathPlugin.canUse(field, parents.map(p => p.fieldId))) {
|
|
35
|
+
return valuePathPlugin.createPath(params);
|
|
36
|
+
}
|
|
37
|
+
return basePath.concat(parents.map(parent => parent.fieldId)).concat([params.field.fieldId]).join(".");
|
|
38
|
+
},
|
|
39
|
+
transform: value => {
|
|
40
|
+
if (!transformPlugin) {
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
return transformPlugin.transform({
|
|
44
|
+
field,
|
|
45
|
+
value
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const childFields = field.settings?.fields;
|
|
50
|
+
if (!childFields?.length) {
|
|
51
|
+
return collection;
|
|
52
|
+
}
|
|
53
|
+
const result = createFieldCollection({
|
|
54
|
+
fields: childFields,
|
|
55
|
+
parents: [...parents, {
|
|
56
|
+
fieldId: field.fieldId,
|
|
57
|
+
multipleValues: field.multipleValues
|
|
58
|
+
}],
|
|
59
|
+
transformValuePlugins,
|
|
60
|
+
valuePathPlugins,
|
|
61
|
+
system
|
|
62
|
+
});
|
|
63
|
+
Object.assign(collection, result);
|
|
64
|
+
return collection;
|
|
65
|
+
}, {});
|
|
66
|
+
};
|
|
18
67
|
/**
|
|
19
68
|
* This method will map the fieldId (fieldId -> field) to the actual field.
|
|
20
69
|
*
|
|
@@ -35,89 +84,25 @@ const createFields = params => {
|
|
|
35
84
|
type: _plugins.CmsEntryFieldFilterPathPlugin.type,
|
|
36
85
|
property: "fieldType"
|
|
37
86
|
});
|
|
38
|
-
const collection = (
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return transformPlugin.transform({
|
|
56
|
-
field,
|
|
57
|
-
value
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
return fields;
|
|
62
|
-
}, {});
|
|
63
|
-
|
|
64
|
-
const addFieldsToCollection = (fields, parents = []) => {
|
|
65
|
-
/**
|
|
66
|
-
* Exit early if no fields are sent.
|
|
67
|
-
*/
|
|
68
|
-
if (fields.length === 0) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
for (const field of fields) {
|
|
73
|
-
var _field$settings2;
|
|
74
|
-
|
|
75
|
-
const transformPlugin = transformValuePlugins[field.type];
|
|
76
|
-
const valuePathPlugin = valuePathPlugins[field.type];
|
|
77
|
-
/**
|
|
78
|
-
* The required fieldId is a product of all of its parents and its own fieldId.
|
|
79
|
-
*/
|
|
80
|
-
|
|
81
|
-
const fieldId = [...parents, {
|
|
82
|
-
fieldId: field.fieldId,
|
|
83
|
-
multipleValues: field.multipleValues
|
|
84
|
-
}].map(f => f.fieldId).join(".");
|
|
85
|
-
collection[fieldId] = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, field), {}, {
|
|
86
|
-
parents,
|
|
87
|
-
system: false,
|
|
88
|
-
createPath: params => {
|
|
89
|
-
if (valuePathPlugin) {
|
|
90
|
-
return valuePathPlugin.createPath(params);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return ["values"].concat(parents.map(parent => parent.fieldId)).concat([params.field.fieldId]).join(".");
|
|
94
|
-
},
|
|
95
|
-
transform: value => {
|
|
96
|
-
if (!transformPlugin) {
|
|
97
|
-
return value;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return transformPlugin.transform({
|
|
101
|
-
field,
|
|
102
|
-
value
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
const childFields = (_field$settings2 = field.settings) === null || _field$settings2 === void 0 ? void 0 : _field$settings2.fields;
|
|
107
|
-
|
|
108
|
-
if (!childFields || childFields.length === 0) {
|
|
109
|
-
continue;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
addFieldsToCollection(childFields, [...parents, {
|
|
113
|
-
fieldId: field.fieldId,
|
|
114
|
-
multipleValues: field.multipleValues
|
|
115
|
-
}]);
|
|
116
|
-
}
|
|
87
|
+
const collection = createFieldCollection({
|
|
88
|
+
fields: (0, _systemFields.createSystemFields)(),
|
|
89
|
+
transformValuePlugins,
|
|
90
|
+
valuePathPlugins,
|
|
91
|
+
parents: [],
|
|
92
|
+
system: true
|
|
93
|
+
});
|
|
94
|
+
const result = createFieldCollection({
|
|
95
|
+
fields,
|
|
96
|
+
transformValuePlugins,
|
|
97
|
+
valuePathPlugins,
|
|
98
|
+
parents: [],
|
|
99
|
+
system: false
|
|
100
|
+
});
|
|
101
|
+
return {
|
|
102
|
+
...collection,
|
|
103
|
+
...result
|
|
117
104
|
};
|
|
118
|
-
|
|
119
|
-
addFieldsToCollection(fields);
|
|
120
|
-
return collection;
|
|
121
105
|
};
|
|
106
|
+
exports.createFields = createFields;
|
|
122
107
|
|
|
123
|
-
|
|
108
|
+
//# sourceMappingURL=createFields.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["_systemFields","require","_plugins","_mapPlugins","createFieldCollection","params","fields","parents","transformValuePlugins","valuePathPlugins","system","reduce","collection","field","transformPlugin","type","valuePathPlugin","basePath","fieldId","multipleValues","map","f","join","createPath","canUse","p","concat","parent","transform","value","childFields","settings","length","result","Object","assign","createFields","plugins","getMappedPlugins","property","CmsEntryFieldFilterPathPlugin","createSystemFields","exports"],"sources":["createFields.ts"],"sourcesContent":["import type { CmsModelField } from \"@webiny/api-headless-cms/types\";\nimport { createSystemFields } from \"./systemFields\";\nimport type { Field, FieldParent } from \"./types\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport type { CmsFieldFilterValueTransformPlugin } from \"~/types\";\nimport { CmsEntryFieldFilterPathPlugin } from \"~/plugins\";\nimport { getMappedPlugins } from \"./mapPlugins\";\n\ninterface Params {\n fields: CmsModelField[];\n plugins: PluginsContainer;\n}\n\ninterface FieldCollection {\n [key: string]: Field;\n}\n\ninterface AddFieldsToCollectionParams {\n fields: CmsModelField[];\n parents: FieldParent[];\n transformValuePlugins: Record<string, CmsFieldFilterValueTransformPlugin>;\n valuePathPlugins: Record<string, CmsEntryFieldFilterPathPlugin>;\n system: boolean;\n}\n\nconst createFieldCollection = (params: AddFieldsToCollectionParams): FieldCollection => {\n const { fields, parents, transformValuePlugins, valuePathPlugins, system } = params;\n return fields.reduce<FieldCollection>((collection, field) => {\n const transformPlugin = transformValuePlugins[field.type];\n const valuePathPlugin = valuePathPlugins[field.type];\n\n const basePath = system ? [] : [\"values\"];\n /**\n * The required fieldId is a product of all of its parents and its own fieldId.\n */\n const fieldId = [\n ...parents,\n {\n fieldId: field.fieldId,\n multipleValues: field.multipleValues\n }\n ]\n .map(f => f.fieldId)\n .join(\".\");\n\n collection[fieldId] = {\n ...field,\n parents,\n system,\n createPath: params => {\n if (\n valuePathPlugin &&\n valuePathPlugin.canUse(\n field,\n parents.map(p => p.fieldId)\n )\n ) {\n return valuePathPlugin.createPath(params);\n }\n\n return basePath\n .concat(parents.map(parent => parent.fieldId))\n .concat([params.field.fieldId])\n .join(\".\");\n },\n transform: value => {\n if (!transformPlugin) {\n return value;\n }\n return transformPlugin.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 multipleValues: field.multipleValues\n }\n ],\n transformValuePlugins,\n valuePathPlugins,\n system\n });\n Object.assign(collection, result);\n return collection;\n }, {});\n};\n/**\n * This method will map the fieldId (fieldId -> field) to the actual field.\n *\n * In case of nested fields, fieldId is all the parent fieldIds + current one, joined by the dot (.).\n */\nexport const createFields = (params: Params) => {\n const { fields, plugins } = params;\n\n const transformValuePlugins = getMappedPlugins<CmsFieldFilterValueTransformPlugin>({\n plugins,\n type: \"cms-field-filter-value-transform\",\n property: \"fieldType\"\n });\n const valuePathPlugins = getMappedPlugins<CmsEntryFieldFilterPathPlugin>({\n plugins,\n type: CmsEntryFieldFilterPathPlugin.type,\n property: \"fieldType\"\n });\n\n const collection = createFieldCollection({\n fields: createSystemFields(),\n transformValuePlugins,\n valuePathPlugins,\n parents: [],\n system: true\n });\n\n const result = createFieldCollection({\n fields,\n transformValuePlugins,\n valuePathPlugins,\n parents: [],\n system: false\n });\n\n return {\n ...collection,\n ...result\n };\n};\n"],"mappings":";;;;;;AACA,IAAAA,aAAA,GAAAC,OAAA;AAIA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AAmBA,MAAMG,qBAAqB,GAAIC,MAAmC,IAAsB;EACpF,MAAM;IAAEC,MAAM;IAAEC,OAAO;IAAEC,qB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AAgB;IAChBF,OAAO,EAAE,EAAE;IACXG,MAAM,EAAE;EACZ,CAAC,CAAC;EAEF,OAAO;IACH,GAAGE,UAAU;IACb,GAAGqB;EACP,CAAC;AACL,CAAC;AAACS,OAAA,CAAAN,YAAA,GAAAA,YAAA","ignoreList":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Field } from "./types";
|
|
2
|
-
import { PluginsContainer } from "@webiny/plugins";
|
|
3
|
-
import { CmsModel } from "@webiny/api-headless-cms/types";
|
|
1
|
+
import type { Field } from "./types";
|
|
2
|
+
import type { PluginsContainer } from "@webiny/plugins";
|
|
3
|
+
import type { CmsModel } from "@webiny/api-headless-cms/types";
|
|
4
4
|
interface Result {
|
|
5
5
|
valuePath: string;
|
|
6
6
|
reverse: boolean;
|
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.extractSort = void 0;
|
|
9
|
-
|
|
10
8
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
|
-
|
|
12
9
|
var _plugins = require("../../../plugins");
|
|
13
|
-
|
|
14
10
|
const extractSort = params => {
|
|
15
11
|
const {
|
|
16
12
|
model,
|
|
@@ -19,13 +15,11 @@ const extractSort = params => {
|
|
|
19
15
|
plugins
|
|
20
16
|
} = params;
|
|
21
17
|
const result = sortBy.split("_");
|
|
22
|
-
|
|
23
18
|
if (result.length !== 2) {
|
|
24
19
|
throw new _error.default("Problem in determining the sorting for the entry items.", "SORT_EXTRACT_ERROR", {
|
|
25
20
|
sortBy
|
|
26
21
|
});
|
|
27
22
|
}
|
|
28
|
-
|
|
29
23
|
const [fieldId, order] = result;
|
|
30
24
|
const field = Object.values(fields).find(field => {
|
|
31
25
|
/**
|
|
@@ -34,7 +28,6 @@ const extractSort = params => {
|
|
|
34
28
|
if (field.parents.length > 0) {
|
|
35
29
|
return false;
|
|
36
30
|
}
|
|
37
|
-
|
|
38
31
|
return field.fieldId === fieldId;
|
|
39
32
|
});
|
|
40
33
|
const plugin = plugins.byType(_plugins.CmsEntryFieldSortingPlugin.type).reverse().find(plugin => {
|
|
@@ -46,7 +39,6 @@ const extractSort = params => {
|
|
|
46
39
|
sortBy
|
|
47
40
|
});
|
|
48
41
|
});
|
|
49
|
-
|
|
50
42
|
if (plugin) {
|
|
51
43
|
return plugin.createSort({
|
|
52
44
|
model,
|
|
@@ -62,7 +54,6 @@ const extractSort = params => {
|
|
|
62
54
|
fields
|
|
63
55
|
});
|
|
64
56
|
}
|
|
65
|
-
|
|
66
57
|
const valuePath = field.createPath({
|
|
67
58
|
field
|
|
68
59
|
});
|
|
@@ -73,5 +64,6 @@ const extractSort = params => {
|
|
|
73
64
|
reverse: order === "DESC"
|
|
74
65
|
};
|
|
75
66
|
};
|
|
67
|
+
exports.extractSort = extractSort;
|
|
76
68
|
|
|
77
|
-
|
|
69
|
+
//# sourceMappingURL=extractSort.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["extractSort","params","model","sortBy","fields","plugins","result","split","length","WebinyError","fieldId","order","field","Object","values","find","parents","plugin","byType","CmsEntryFieldSortingPlugin","type","reverse","canUse","createSort","valuePath","createPath"],"sources":["extractSort.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { Field } from \"./types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { CmsEntryFieldSortingPlugin } from \"~/plugins\";\nimport { CmsModel } from \"@webiny/api-headless-cms/types\";\n\ninterface Result {\n valuePath: string;\n reverse: boolean;\n fieldId: string;\n field: Field;\n}\n\ninterface Params {\n model: CmsModel;\n sortBy: string;\n fields: Record<string, Field>;\n plugins: PluginsContainer;\n}\n\nexport const extractSort = (params: Params): Result => {\n const { model, sortBy, fields, plugins } = params;\n const result = sortBy.split(\"_\");\n if (result.length !== 2) {\n throw new WebinyError(\n \"Problem in determining the sorting for the entry items.\",\n \"SORT_EXTRACT_ERROR\",\n {\n sortBy\n }\n );\n }\n const [fieldId, order] = result as [string, \"ASC\" | \"DESC\"];\n\n const field = Object.values(fields).find(field => {\n /**\n * We do not support sorting by nested fields.\n */\n if (field.parents.length > 0) {\n return false;\n }\n return field.fieldId === fieldId;\n });\n\n const plugin = plugins\n .byType<CmsEntryFieldSortingPlugin>(CmsEntryFieldSortingPlugin.type)\n .reverse()\n .find(plugin => {\n return plugin.canUse({\n model,\n field,\n fieldId,\n order,\n sortBy\n });\n });\n\n if (plugin) {\n return plugin.createSort({\n model,\n fieldId,\n order,\n sortBy,\n field,\n fields\n });\n } else if (!field) {\n throw new WebinyError(\n \"Sorting field does not exist in the content model.\",\n \"SORTING_FIELD_ERROR\",\n {\n fieldId,\n fields\n }\n );\n }\n const valuePath = field.createPath({\n field\n });\n return {\n field,\n fieldId,\n valuePath,\n reverse: order === \"DESC\"\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["_error","_interopRequireDefault","require","_plugins","extractSort","params","model","sortBy","fields","plugins","result","split","length","WebinyError","fieldId","order","field","Object","values","find","parents","plugin","byType","CmsEntryFieldSortingPlugin","type","reverse","canUse","createSort","valuePath","createPath","exports"],"sources":["extractSort.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { Field } from \"./types\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport { CmsEntryFieldSortingPlugin } from \"~/plugins\";\nimport type { CmsModel } from \"@webiny/api-headless-cms/types\";\n\ninterface Result {\n valuePath: string;\n reverse: boolean;\n fieldId: string;\n field: Field;\n}\n\ninterface Params {\n model: CmsModel;\n sortBy: string;\n fields: Record<string, Field>;\n plugins: PluginsContainer;\n}\n\nexport const extractSort = (params: Params): Result => {\n const { model, sortBy, fields, plugins } = params;\n const result = sortBy.split(\"_\");\n if (result.length !== 2) {\n throw new WebinyError(\n \"Problem in determining the sorting for the entry items.\",\n \"SORT_EXTRACT_ERROR\",\n {\n sortBy\n }\n );\n }\n const [fieldId, order] = result as [string, \"ASC\" | \"DESC\"];\n\n const field = Object.values(fields).find(field => {\n /**\n * We do not support sorting by nested fields.\n */\n if (field.parents.length > 0) {\n return false;\n }\n return field.fieldId === fieldId;\n });\n\n const plugin = plugins\n .byType<CmsEntryFieldSortingPlugin>(CmsEntryFieldSortingPlugin.type)\n .reverse()\n .find(plugin => {\n return plugin.canUse({\n model,\n field,\n fieldId,\n order,\n sortBy\n });\n });\n\n if (plugin) {\n return plugin.createSort({\n model,\n fieldId,\n order,\n sortBy,\n field,\n fields\n });\n } else if (!field) {\n throw new WebinyError(\n \"Sorting field does not exist in the content model.\",\n \"SORTING_FIELD_ERROR\",\n {\n fieldId,\n fields\n }\n );\n }\n const valuePath = field.createPath({\n field\n });\n return {\n field,\n fieldId,\n valuePath,\n reverse: order === \"DESC\"\n };\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAGA,IAAAC,QAAA,GAAAD,OAAA;AAiBO,MAAME,WAAW,GAAIC,MAAc,IAAa;EACnD,MAAM;IAAEC,KAAK;IAAEC,MAAM;IAAEC,MAAM;IAAEC;EAAQ,CAAC,GAAGJ,MAAM;EACjD,MAAMK,MAAM,GAAGH,MAAM,CAACI,KAAK,CAAC,GAAG,CAAC;EAChC,IAAID,MAAM,CAACE,MAAM,KAAK,CAAC,EAAE;IACrB,MAAM,IAAIC,cAAW,CACjB,yDAAyD,EACzD,oBAAoB,EACpB;MACIN;IACJ,CACJ,CAAC;EACL;EACA,MAAM,CAACO,OAAO,EAAEC,KAAK,CAAC,GAAGL,MAAkC;EAE3D,MAAMM,KAAK,GAAGC,MAAM,CAACC,MAAM,CAACV,MAAM,CAAC,CAACW,IAAI,CAACH,KAAK,IAAI;IAC9C;AACR;AACA;IACQ,IAAIA,KAAK,CAACI,OAAO,CAACR,MAAM,GAAG,CAAC,EAAE;MAC1B,OAAO,KAAK;IAChB;IACA,OAAOI,KAAK,CAACF,OAAO,KAAKA,OAAO;EACpC,CAAC,CAAC;EAEF,MAAMO,MAAM,GAAGZ,OAAO,CACjBa,MAAM,CAA6BC,mCAA0B,CAACC,IAAI,CAAC,CACnEC,OAAO,CAAC,CAAC,CACTN,IAAI,CAACE,MAAM,IAAI;IACZ,OAAOA,MAAM,CAACK,MAAM,CAAC;MACjBpB,KAAK;MACLU,KAAK;MACLF,OAAO;MACPC,KAAK;MACLR;IACJ,CAAC,CAAC;EACN,CAAC,CAAC;EAEN,IAAIc,MAAM,EAAE;IACR,OAAOA,MAAM,CAACM,UAAU,CAAC;MACrBrB,KAAK;MACLQ,OAAO;MACPC,KAAK;MACLR,MAAM;MACNS,KAAK;MACLR;IACJ,CAAC,CAAC;EACN,CAAC,MAAM,IAAI,CAACQ,KAAK,EAAE;IACf,MAAM,IAAIH,cAAW,CACjB,oDAAoD,EACpD,qBAAqB,EACrB;MACIC,OAAO;MACPN;IACJ,CACJ,CAAC;EACL;EACA,MAAMoB,SAAS,GAAGZ,KAAK,CAACa,UAAU,CAAC;IAC/Bb;EACJ,CAAC,CAAC;EACF,OAAO;IACHA,KAAK;IACLF,OAAO;IACPc,SAAS;IACTH,OAAO,EAAEV,KAAK,KAAK;EACvB,CAAC;AACL,CAAC;AAACe,OAAA,CAAA1B,WAAA,GAAAA,WAAA","ignoreList":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { CmsEntry, CmsEntryListWhere } from "@webiny/api-headless-cms/types";
|
|
2
|
-
import { PluginsContainer } from "@webiny/plugins";
|
|
3
|
-
import { Field } from "./types";
|
|
1
|
+
import type { CmsEntry, CmsEntryListWhere } from "@webiny/api-headless-cms/types";
|
|
2
|
+
import type { PluginsContainer } from "@webiny/plugins";
|
|
3
|
+
import type { Field } from "./types";
|
|
4
4
|
interface Params {
|
|
5
5
|
items: CmsEntry[];
|
|
6
6
|
where: Partial<CmsEntryListWhere>;
|
|
@@ -1,43 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.filter = void 0;
|
|
9
|
-
|
|
10
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
-
|
|
12
8
|
var _ValueFilterPlugin = require("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin");
|
|
13
|
-
|
|
14
9
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
15
|
-
|
|
16
10
|
var _fullTextSearch = require("./fullTextSearch");
|
|
17
|
-
|
|
18
11
|
var _createExpressions = require("./createExpressions");
|
|
19
|
-
|
|
20
12
|
var _transform = require("./transform");
|
|
21
|
-
|
|
22
13
|
var _getValue = require("./getValue");
|
|
23
|
-
|
|
24
14
|
const executeFilter = params => {
|
|
25
15
|
const {
|
|
26
16
|
value,
|
|
27
17
|
filter
|
|
28
18
|
} = params;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* We need to check if the filter can be used.
|
|
22
|
+
* If it cannot, we will just return true.
|
|
23
|
+
*/
|
|
24
|
+
const canUse = filter.plugin.canUse({
|
|
25
|
+
value,
|
|
26
|
+
compareValue: filter.compareValue
|
|
27
|
+
});
|
|
28
|
+
if (!canUse) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
29
31
|
const matched = filter.plugin.matches({
|
|
30
32
|
value,
|
|
31
33
|
compareValue: filter.compareValue
|
|
32
34
|
});
|
|
33
|
-
|
|
34
35
|
if (filter.negate) {
|
|
35
36
|
return matched === false;
|
|
36
37
|
}
|
|
37
|
-
|
|
38
38
|
return matched;
|
|
39
39
|
};
|
|
40
|
-
|
|
41
40
|
const executeExpressions = params => {
|
|
42
41
|
const {
|
|
43
42
|
expressions,
|
|
@@ -45,15 +44,12 @@ const executeExpressions = params => {
|
|
|
45
44
|
filters,
|
|
46
45
|
condition
|
|
47
46
|
} = params;
|
|
48
|
-
|
|
49
47
|
if (expressions.length === 0 && filters.length === 0) {
|
|
50
48
|
return true;
|
|
51
49
|
}
|
|
52
50
|
/**
|
|
53
51
|
* Always run filters first as they might trigger an early return.
|
|
54
52
|
*/
|
|
55
|
-
|
|
56
|
-
|
|
57
53
|
for (const filter of filters) {
|
|
58
54
|
const value = getCachedValue(filter);
|
|
59
55
|
const result = executeFilter({
|
|
@@ -64,7 +60,6 @@ const executeExpressions = params => {
|
|
|
64
60
|
* Filters are ALWAYS executed as an AND.
|
|
65
61
|
* So if even one is false, everything false.
|
|
66
62
|
*/
|
|
67
|
-
|
|
68
63
|
if (!result) {
|
|
69
64
|
return false;
|
|
70
65
|
}
|
|
@@ -72,13 +67,11 @@ const executeExpressions = params => {
|
|
|
72
67
|
/**
|
|
73
68
|
* Then we move onto expressions, which are basically nested upon nested filters with different conditions.
|
|
74
69
|
*/
|
|
75
|
-
|
|
76
|
-
|
|
77
70
|
for (const expression of expressions) {
|
|
78
|
-
const result = executeExpressions(
|
|
71
|
+
const result = executeExpressions({
|
|
72
|
+
...expression,
|
|
79
73
|
getCachedValue
|
|
80
|
-
})
|
|
81
|
-
|
|
74
|
+
});
|
|
82
75
|
if (result && condition === "OR") {
|
|
83
76
|
return true;
|
|
84
77
|
} else if (!result && condition == "AND") {
|
|
@@ -90,11 +83,8 @@ const executeExpressions = params => {
|
|
|
90
83
|
*
|
|
91
84
|
* Also, if condition is not an OR, we can say that the expressions check is ok, because it would fail a lot earlier than this line.
|
|
92
85
|
*/
|
|
93
|
-
|
|
94
|
-
|
|
95
86
|
return condition === "OR" ? false : true;
|
|
96
87
|
};
|
|
97
|
-
|
|
98
88
|
const filter = params => {
|
|
99
89
|
const {
|
|
100
90
|
items: records,
|
|
@@ -104,52 +94,43 @@ const filter = params => {
|
|
|
104
94
|
fullTextSearch
|
|
105
95
|
} = params;
|
|
106
96
|
const keys = Object.keys(where);
|
|
107
|
-
|
|
108
97
|
if (keys.length === 0 && !fullTextSearch) {
|
|
109
98
|
return records;
|
|
110
99
|
}
|
|
111
|
-
|
|
112
100
|
const expression = (0, _createExpressions.createExpressions)({
|
|
113
101
|
plugins,
|
|
114
102
|
where,
|
|
115
103
|
fields
|
|
116
104
|
});
|
|
105
|
+
|
|
117
106
|
/**
|
|
118
107
|
* No point in going further if there are no expressions to be applied and no full text search to be executed.
|
|
119
108
|
*/
|
|
120
|
-
|
|
121
|
-
if (expression.filters.length === 0 && expression.expressions.length === 0 && !(fullTextSearch !== null && fullTextSearch !== void 0 && fullTextSearch.term)) {
|
|
109
|
+
if (expression.filters.length === 0 && expression.expressions.length === 0 && !fullTextSearch?.term) {
|
|
122
110
|
return records;
|
|
123
111
|
}
|
|
124
112
|
/**
|
|
125
113
|
* We need the contains plugin to run the full text search.
|
|
126
114
|
*/
|
|
127
|
-
|
|
128
|
-
|
|
129
115
|
const fullTextSearchPlugin = plugins.byType(_ValueFilterPlugin.ValueFilterPlugin.type).find(plugin => plugin.getOperation() === "contains");
|
|
130
|
-
|
|
131
116
|
if (!fullTextSearchPlugin) {
|
|
132
117
|
throw new _error.default(`Missing "contains" plugin to run the full-text search.`, "MISSING_PLUGIN");
|
|
133
118
|
}
|
|
134
|
-
|
|
135
119
|
const search = (0, _fullTextSearch.createFullTextSearch)({
|
|
136
|
-
term: fullTextSearch
|
|
137
|
-
targetFields: fullTextSearch
|
|
120
|
+
term: fullTextSearch?.term,
|
|
121
|
+
targetFields: fullTextSearch?.fields,
|
|
138
122
|
fields,
|
|
139
123
|
plugin: fullTextSearchPlugin
|
|
140
124
|
});
|
|
141
125
|
return records.filter(record => {
|
|
142
126
|
const cachedValues = {};
|
|
143
|
-
|
|
144
127
|
const getCachedValue = filter => {
|
|
145
128
|
const {
|
|
146
129
|
path
|
|
147
130
|
} = filter;
|
|
148
|
-
|
|
149
131
|
if (cachedValues[path] !== undefined) {
|
|
150
132
|
return cachedValues[path];
|
|
151
133
|
}
|
|
152
|
-
|
|
153
134
|
const plainValue = (0, _getValue.getValue)(record, path);
|
|
154
135
|
const rawValue = (0, _transform.transformValue)({
|
|
155
136
|
value: plainValue,
|
|
@@ -158,21 +139,20 @@ const filter = params => {
|
|
|
158
139
|
cachedValues[path] = rawValue;
|
|
159
140
|
return rawValue;
|
|
160
141
|
};
|
|
161
|
-
|
|
162
|
-
|
|
142
|
+
const exprResult = executeExpressions({
|
|
143
|
+
...expression,
|
|
163
144
|
getCachedValue
|
|
164
|
-
})
|
|
145
|
+
});
|
|
165
146
|
/**
|
|
166
147
|
* If expression result is false we do not need to continue further.
|
|
167
148
|
* Also, if there is no full text search defined, just return the expression result.
|
|
168
149
|
*/
|
|
169
|
-
|
|
170
150
|
if (!exprResult || !search) {
|
|
171
151
|
return exprResult;
|
|
172
152
|
}
|
|
173
|
-
|
|
174
153
|
return search(record);
|
|
175
154
|
});
|
|
176
155
|
};
|
|
156
|
+
exports.filter = filter;
|
|
177
157
|
|
|
178
|
-
|
|
158
|
+
//# sourceMappingURL=filter.js.map
|