@webiny/api-headless-cms-ddb 6.4.11-beta.1 → 6.4.12-beta.0

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.
@@ -12,7 +12,7 @@ const createLocationFolderIdPathPlugin = ()=>new CmsEntryFieldFilterPathPlugin({
12
12
  path: createPath,
13
13
  canUse: (field, parents)=>{
14
14
  if ("folderId" !== field.fieldId) return false;
15
- if (!parents?.length) return false;
15
+ else if (!parents?.length) return false;
16
16
  return "wbyAco_location" === parents[0];
17
17
  }
18
18
  });
@@ -1 +1 @@
1
- {"version":3,"file":"dynamoDb/path/locationFolderId.js","sources":["../../../src/dynamoDb/path/locationFolderId.ts"],"sourcesContent":["/**\n * File is @internal\n */\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":";;AAOA,MAAMA,aAAiC,CAAC,EAAEC,KAAK,EAAE;IAC7C,MAAM,EAAEC,IAAI,EAAE,GAAGD,MAAM,QAAQ,IAAI,CAAC;IACpC,IAAI,CAACC,MACD,MAAM,IAAIC,MAAY,gCAAgC,wBAAwB;QAC1EF;IACJ;IAEJ,OAAOC;AACX;AAEO,MAAME,mCAAmC,IACrC,IAAIC,8BAA8B;QACrC,WAAW;QACX,MAAML;QACN,QAAQ,CAACC,OAAOK;YACZ,IAAIL,AAAkB,eAAlBA,MAAM,OAAO,EACb,OAAO;YACJ,IAAI,CAACK,SAAS,QACjB,OAAO;YAEX,OAAOA,AAAe,sBAAfA,OAAO,CAAC,EAAE;QACrB;IACJ"}
1
+ {"version":3,"file":"dynamoDb/path/locationFolderId.js","sources":["../../../src/dynamoDb/path/locationFolderId.ts"],"sourcesContent":["/**\n * File is @internal\n */\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":";;AAOA,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"}
@@ -41,7 +41,7 @@ const extractSort = (params)=>{
41
41
  field,
42
42
  fields
43
43
  });
44
- if (!field) throw new error("Sorting field does not exist in the content model.", "SORTING_FIELD_ERROR", {
44
+ else if (!field) throw new error("Sorting field does not exist in the content model.", "SORTING_FIELD_ERROR", {
45
45
  fieldId,
46
46
  fields
47
47
  });
@@ -1 +1 @@
1
- {"version":3,"file":"operations/entry/filtering/extractSort.js","sources":["../../../../src/operations/entry/filtering/extractSort.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { Field } from \"./types.js\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport { CmsEntryFieldSortingPlugin } from \"~/plugins/index.js\";\nimport type { CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\n\nconst extractSortInfo = (sortBy: string) => {\n const rootSorting = sortBy.match(/^([a-zA-Z]+)_(ASC|DESC)$/);\n if (rootSorting) {\n return {\n fieldId: rootSorting[1],\n isValues: false,\n order: rootSorting[2] as \"ASC\" | \"DESC\"\n };\n }\n const valuesSorting = sortBy.match(/^values_([a-zA-Z0-9]+)_(ASC|DESC)$/);\n if (valuesSorting) {\n return {\n fieldId: valuesSorting[1],\n isValues: true,\n order: valuesSorting[2] as \"ASC\" | \"DESC\"\n };\n }\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\ninterface IResponse {\n valuePath: string;\n reverse: boolean;\n fieldId: string;\n field: Field;\n}\n\ninterface IParams {\n model: CmsModel;\n sortBy: string;\n fields: Record<string, Field>;\n plugins: PluginsContainer;\n}\n\nexport const extractSort = (params: IParams): IResponse => {\n const { model, sortBy, fields, plugins } = params;\n const { fieldId, isValues: isValuesSorting, order } = extractSortInfo(sortBy);\n\n const field = Object.values(fields).find(f => {\n /**\n * We do not support sorting by nested fields.\n */\n const isValues = f.parents[0]?.fieldId === \"values\";\n if (isValues && isValuesSorting) {\n return f.fieldId === fieldId;\n }\n if (f.parents.length > 0) {\n return false;\n }\n return f.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"],"names":["extractSortInfo","sortBy","rootSorting","valuesSorting","WebinyError","extractSort","params","model","fields","plugins","fieldId","isValuesSorting","order","field","Object","f","isValues","plugin","CmsEntryFieldSortingPlugin","valuePath"],"mappings":";;AAMA,MAAMA,kBAAkB,CAACC;IACrB,MAAMC,cAAcD,OAAO,KAAK,CAAC;IACjC,IAAIC,aACA,OAAO;QACH,SAASA,WAAW,CAAC,EAAE;QACvB,UAAU;QACV,OAAOA,WAAW,CAAC,EAAE;IACzB;IAEJ,MAAMC,gBAAgBF,OAAO,KAAK,CAAC;IACnC,IAAIE,eACA,OAAO;QACH,SAASA,aAAa,CAAC,EAAE;QACzB,UAAU;QACV,OAAOA,aAAa,CAAC,EAAE;IAC3B;IAEJ,MAAM,IAAIC,MACN,2DACA,sBACA;QACIH;IACJ;AAER;AAgBO,MAAMI,cAAc,CAACC;IACxB,MAAM,EAAEC,KAAK,EAAEN,MAAM,EAAEO,MAAM,EAAEC,OAAO,EAAE,GAAGH;IAC3C,MAAM,EAAEI,OAAO,EAAE,UAAUC,eAAe,EAAEC,KAAK,EAAE,GAAGZ,gBAAgBC;IAEtE,MAAMY,QAAQC,OAAO,MAAM,CAACN,QAAQ,IAAI,CAACO,CAAAA;QAIrC,MAAMC,WAAWD,EAAE,OAAO,CAAC,EAAE,EAAE,YAAY;QAC3C,IAAIC,YAAYL,iBACZ,OAAOI,EAAE,OAAO,KAAKL;QAEzB,IAAIK,EAAE,OAAO,CAAC,MAAM,GAAG,GACnB,OAAO;QAEX,OAAOA,EAAE,OAAO,KAAKL;IACzB;IAEA,MAAMO,SAASR,QACV,MAAM,CAA6BS,2BAA2B,IAAI,EAClE,OAAO,GACP,IAAI,CAACD,CAAAA,SACKA,OAAO,MAAM,CAAC;YACjBV;YACAM;YACAH;YACAE;YACAX;QACJ;IAGR,IAAIgB,QACA,OAAOA,OAAO,UAAU,CAAC;QACrBV;QACAG;QACAE;QACAX;QACAY;QACAL;IACJ;IACG,IAAI,CAACK,OACR,MAAM,IAAIT,MACN,sDACA,uBACA;QACIM;QACAF;IACJ;IAGR,MAAMW,YAAYN,MAAM,UAAU,CAAC;QAC/BA;IACJ;IACA,OAAO;QACHA;QACAH;QACAS;QACA,SAASP,AAAU,WAAVA;IACb;AACJ"}
1
+ {"version":3,"file":"operations/entry/filtering/extractSort.js","sources":["../../../../src/operations/entry/filtering/extractSort.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { Field } from \"./types.js\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport { CmsEntryFieldSortingPlugin } from \"~/plugins/index.js\";\nimport type { CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\n\nconst extractSortInfo = (sortBy: string) => {\n const rootSorting = sortBy.match(/^([a-zA-Z]+)_(ASC|DESC)$/);\n if (rootSorting) {\n return {\n fieldId: rootSorting[1],\n isValues: false,\n order: rootSorting[2] as \"ASC\" | \"DESC\"\n };\n }\n const valuesSorting = sortBy.match(/^values_([a-zA-Z0-9]+)_(ASC|DESC)$/);\n if (valuesSorting) {\n return {\n fieldId: valuesSorting[1],\n isValues: true,\n order: valuesSorting[2] as \"ASC\" | \"DESC\"\n };\n }\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\ninterface IResponse {\n valuePath: string;\n reverse: boolean;\n fieldId: string;\n field: Field;\n}\n\ninterface IParams {\n model: CmsModel;\n sortBy: string;\n fields: Record<string, Field>;\n plugins: PluginsContainer;\n}\n\nexport const extractSort = (params: IParams): IResponse => {\n const { model, sortBy, fields, plugins } = params;\n const { fieldId, isValues: isValuesSorting, order } = extractSortInfo(sortBy);\n\n const field = Object.values(fields).find(f => {\n /**\n * We do not support sorting by nested fields.\n */\n const isValues = f.parents[0]?.fieldId === \"values\";\n if (isValues && isValuesSorting) {\n return f.fieldId === fieldId;\n }\n if (f.parents.length > 0) {\n return false;\n }\n return f.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"],"names":["extractSortInfo","sortBy","rootSorting","valuesSorting","WebinyError","extractSort","params","model","fields","plugins","fieldId","isValuesSorting","order","field","Object","f","isValues","plugin","CmsEntryFieldSortingPlugin","valuePath"],"mappings":";;AAMA,MAAMA,kBAAkB,CAACC;IACrB,MAAMC,cAAcD,OAAO,KAAK,CAAC;IACjC,IAAIC,aACA,OAAO;QACH,SAASA,WAAW,CAAC,EAAE;QACvB,UAAU;QACV,OAAOA,WAAW,CAAC,EAAE;IACzB;IAEJ,MAAMC,gBAAgBF,OAAO,KAAK,CAAC;IACnC,IAAIE,eACA,OAAO;QACH,SAASA,aAAa,CAAC,EAAE;QACzB,UAAU;QACV,OAAOA,aAAa,CAAC,EAAE;IAC3B;IAEJ,MAAM,IAAIC,MACN,2DACA,sBACA;QACIH;IACJ;AAER;AAgBO,MAAMI,cAAc,CAACC;IACxB,MAAM,EAAEC,KAAK,EAAEN,MAAM,EAAEO,MAAM,EAAEC,OAAO,EAAE,GAAGH;IAC3C,MAAM,EAAEI,OAAO,EAAE,UAAUC,eAAe,EAAEC,KAAK,EAAE,GAAGZ,gBAAgBC;IAEtE,MAAMY,QAAQC,OAAO,MAAM,CAACN,QAAQ,IAAI,CAACO,CAAAA;QAIrC,MAAMC,WAAWD,EAAE,OAAO,CAAC,EAAE,EAAE,YAAY;QAC3C,IAAIC,YAAYL,iBACZ,OAAOI,EAAE,OAAO,KAAKL;QAEzB,IAAIK,EAAE,OAAO,CAAC,MAAM,GAAG,GACnB,OAAO;QAEX,OAAOA,EAAE,OAAO,KAAKL;IACzB;IAEA,MAAMO,SAASR,QACV,MAAM,CAA6BS,2BAA2B,IAAI,EAClE,OAAO,GACP,IAAI,CAACD,CAAAA,SACKA,OAAO,MAAM,CAAC;YACjBV;YACAM;YACAH;YACAE;YACAX;QACJ;IAGR,IAAIgB,QACA,OAAOA,OAAO,UAAU,CAAC;QACrBV;QACAG;QACAE;QACAX;QACAY;QACAL;IACJ;SACG,IAAI,CAACK,OACR,MAAM,IAAIT,MACN,sDACA,uBACA;QACIM;QACAF;IACJ;IAGR,MAAMW,YAAYN,MAAM,UAAU,CAAC;QAC/BA;IACJ;IACA,OAAO;QACHA;QACAH;QACAS;QACA,SAASP,AAAU,WAAVA;IACb;AACJ"}
@@ -35,7 +35,7 @@ const executeExpressions = (params)=>{
35
35
  getCachedValue
36
36
  });
37
37
  if (result && "OR" === condition) return true;
38
- if (!result && "AND" == condition) return false;
38
+ else if (!result && "AND" == condition) return false;
39
39
  }
40
40
  return "OR" !== condition;
41
41
  };
@@ -1 +1 @@
1
- {"version":3,"file":"operations/entry/filtering/filter.js","sources":["../../../../src/operations/entry/filtering/filter.ts"],"sourcesContent":["import type {\n CmsContext,\n CmsEntry,\n CmsEntryListWhere,\n CmsEntryValues\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport WebinyError from \"@webiny/error\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport type { Field } from \"./types.js\";\nimport { createFullTextSearch } from \"./fullTextSearch.js\";\nimport type { Expression, ExpressionCondition, Filter } from \"./createExpressions.js\";\nimport { createExpressions } from \"./createExpressions.js\";\nimport { transformValue } from \"./transform.js\";\nimport { getValue } from \"~/operations/entry/filtering/getValue.js\";\nimport { ValueFilterRegistry } from \"@webiny/db-dynamodb/exports/api/db.js\";\n\ninterface ExecuteFilterParams {\n value: any;\n filter: Filter;\n}\n\nconst executeFilter = (params: ExecuteFilterParams) => {\n const { value, filter } = params;\n\n /**\n * We need to check if the filter can be used.\n * If it cannot, we will just return true.\n */\n const canUse = filter.filter.canUse({\n value,\n compareValue: filter.compareValue\n });\n if (!canUse) {\n return true;\n }\n\n const matched = filter.filter.matches({\n value,\n compareValue: filter.compareValue\n });\n if (filter.negate) {\n return matched === false;\n }\n return matched;\n};\n\ninterface ExecuteExpressionsParams {\n getCachedValue: (filter: Filter) => Promise<any>;\n expressions: Expression[];\n filters: Filter[];\n condition: ExpressionCondition;\n}\n\nconst executeExpressions = (params: ExecuteExpressionsParams): boolean => {\n const { expressions, getCachedValue, filters, condition } = params;\n if (expressions.length === 0 && filters.length === 0) {\n return true;\n }\n /**\n * Always run filters first as they might trigger an early return.\n */\n for (const filter of filters) {\n const value = getCachedValue(filter);\n\n const result = executeFilter({\n value,\n filter\n });\n /**\n * Filters are ALWAYS executed as an AND.\n * So if even one is false, everything false.\n */\n if (!result) {\n return false;\n }\n }\n /**\n * Then we move onto expressions, which are basically nested upon nested filters with different conditions.\n */\n for (const expression of expressions) {\n const result = executeExpressions({\n ...expression,\n getCachedValue\n });\n if (result && condition === \"OR\") {\n return true;\n } else if (!result && condition == \"AND\") {\n return false;\n }\n }\n /**\n * If condition is an OR, we can fail the expressions check because the code would return a lot earlier than this line.\n *\n * 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.\n */\n return condition === \"OR\" ? false : true;\n};\n\ninterface IFilterParams<T extends CmsEntryValues = CmsEntryValues> {\n plugins: PluginsContainer;\n container: CmsContext[\"container\"];\n items: CmsEntry<T>[];\n where: Partial<CmsEntryListWhere>;\n fields: Record<string, Field>;\n fullTextSearch?: {\n term?: string;\n fields?: string[];\n };\n}\n\nexport const filter = <T extends CmsEntryValues = CmsEntryValues>(\n params: IFilterParams<T>\n): CmsEntry<T>[] => {\n const { items: records, where, plugins, fields, fullTextSearch, container } = params;\n\n const valueFilterRegistry = container.resolve(ValueFilterRegistry);\n\n const keys = Object.keys(where);\n if (keys.length === 0 && !fullTextSearch) {\n return records;\n }\n const expression = createExpressions({\n plugins,\n where,\n fields,\n container\n });\n\n /**\n * No point in going further if there are no expressions to be applied and no full text search to be executed.\n */\n if (\n expression.filters.length === 0 &&\n expression.expressions.length === 0 &&\n !fullTextSearch?.term\n ) {\n return records;\n }\n /**\n * We need the contains plugin to run the full text search.\n */\n const fullTextSearchFilter = valueFilterRegistry.get(\"contains\");\n if (!fullTextSearchFilter) {\n throw new WebinyError(\n `Missing \"contains\" plugin to run the full-text search.`,\n \"MISSING_PLUGIN\"\n );\n }\n\n const search = createFullTextSearch({\n term: fullTextSearch?.term,\n targetFields: fullTextSearch?.fields,\n fields,\n filter: fullTextSearchFilter\n });\n\n return records.filter(record => {\n const cachedValues: Record<string, any> = {};\n\n const getCachedValue = (filter: Filter) => {\n const { path } = filter;\n if (cachedValues[path] !== undefined) {\n return cachedValues[path];\n }\n const plainValue = getValue(record, path);\n\n const rawValue = transformValue({\n value: plainValue,\n transform: filter.transformValue\n });\n\n cachedValues[path] = rawValue;\n return rawValue;\n };\n\n const exprResult = executeExpressions({ ...expression, getCachedValue });\n /**\n * If expression result is false we do not need to continue further.\n * Also, if there is no full text search defined, just return the expression result.\n */\n if (!exprResult || !search) {\n return exprResult;\n }\n\n return search(record);\n });\n};\n"],"names":["executeFilter","params","value","filter","canUse","matched","executeExpressions","expressions","getCachedValue","filters","condition","result","expression","records","where","plugins","fields","fullTextSearch","container","valueFilterRegistry","ValueFilterRegistry","keys","Object","createExpressions","fullTextSearchFilter","WebinyError","search","createFullTextSearch","record","cachedValues","path","undefined","plainValue","getValue","rawValue","transformValue","exprResult"],"mappings":";;;;;;AAqBA,MAAMA,gBAAgB,CAACC;IACnB,MAAM,EAAEC,KAAK,EAAEC,MAAM,EAAE,GAAGF;IAM1B,MAAMG,SAASD,OAAO,MAAM,CAAC,MAAM,CAAC;QAChCD;QACA,cAAcC,OAAO,YAAY;IACrC;IACA,IAAI,CAACC,QACD,OAAO;IAGX,MAAMC,UAAUF,OAAO,MAAM,CAAC,OAAO,CAAC;QAClCD;QACA,cAAcC,OAAO,YAAY;IACrC;IACA,IAAIA,OAAO,MAAM,EACb,OAAOE,AAAY,UAAZA;IAEX,OAAOA;AACX;AASA,MAAMC,qBAAqB,CAACL;IACxB,MAAM,EAAEM,WAAW,EAAEC,cAAc,EAAEC,OAAO,EAAEC,SAAS,EAAE,GAAGT;IAC5D,IAAIM,AAAuB,MAAvBA,YAAY,MAAM,IAAUE,AAAmB,MAAnBA,QAAQ,MAAM,EAC1C,OAAO;IAKX,KAAK,MAAMN,UAAUM,QAAS;QAC1B,MAAMP,QAAQM,eAAeL;QAE7B,MAAMQ,SAASX,cAAc;YACzBE;YACAC;QACJ;QAKA,IAAI,CAACQ,QACD,OAAO;IAEf;IAIA,KAAK,MAAMC,cAAcL,YAAa;QAClC,MAAMI,SAASL,mBAAmB;YAC9B,GAAGM,UAAU;YACbJ;QACJ;QACA,IAAIG,UAAUD,AAAc,SAAdA,WACV,OAAO;QACJ,IAAI,CAACC,UAAUD,AAAa,SAAbA,WAClB,OAAO;IAEf;IAMA,OAAOA,AAAc,SAAdA;AACX;AAcO,MAAMP,gBAAS,CAClBF;IAEA,MAAM,EAAE,OAAOY,OAAO,EAAEC,KAAK,EAAEC,OAAO,EAAEC,MAAM,EAAEC,cAAc,EAAEC,SAAS,EAAE,GAAGjB;IAE9E,MAAMkB,sBAAsBD,UAAU,OAAO,CAACE;IAE9C,MAAMC,OAAOC,OAAO,IAAI,CAACR;IACzB,IAAIO,AAAgB,MAAhBA,KAAK,MAAM,IAAU,CAACJ,gBACtB,OAAOJ;IAEX,MAAMD,aAAaW,kBAAkB;QACjCR;QACAD;QACAE;QACAE;IACJ;IAKA,IACIN,AAA8B,MAA9BA,WAAW,OAAO,CAAC,MAAM,IACzBA,AAAkC,MAAlCA,WAAW,WAAW,CAAC,MAAM,IAC7B,CAACK,gBAAgB,MAEjB,OAAOJ;IAKX,MAAMW,uBAAuBL,oBAAoB,GAAG,CAAC;IACrD,IAAI,CAACK,sBACD,MAAM,IAAIC,MACN,0DACA;IAIR,MAAMC,SAASC,qBAAqB;QAChC,MAAMV,gBAAgB;QACtB,cAAcA,gBAAgB;QAC9BD;QACA,QAAQQ;IACZ;IAEA,OAAOX,QAAQ,MAAM,CAACe,CAAAA;QAClB,MAAMC,eAAoC,CAAC;QAE3C,MAAMrB,iBAAiB,CAACL;YACpB,MAAM,EAAE2B,IAAI,EAAE,GAAG3B;YACjB,IAAI0B,AAAuBE,WAAvBF,YAAY,CAACC,KAAK,EAClB,OAAOD,YAAY,CAACC,KAAK;YAE7B,MAAME,aAAaC,SAASL,QAAQE;YAEpC,MAAMI,WAAWC,eAAe;gBAC5B,OAAOH;gBACP,WAAW7B,OAAO,cAAc;YACpC;YAEA0B,YAAY,CAACC,KAAK,GAAGI;YACrB,OAAOA;QACX;QAEA,MAAME,aAAa9B,mBAAmB;YAAE,GAAGM,UAAU;YAAEJ;QAAe;QAKtE,IAAI,CAAC4B,cAAc,CAACV,QAChB,OAAOU;QAGX,OAAOV,OAAOE;IAClB;AACJ"}
1
+ {"version":3,"file":"operations/entry/filtering/filter.js","sources":["../../../../src/operations/entry/filtering/filter.ts"],"sourcesContent":["import type {\n CmsContext,\n CmsEntry,\n CmsEntryListWhere,\n CmsEntryValues\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport WebinyError from \"@webiny/error\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport type { Field } from \"./types.js\";\nimport { createFullTextSearch } from \"./fullTextSearch.js\";\nimport type { Expression, ExpressionCondition, Filter } from \"./createExpressions.js\";\nimport { createExpressions } from \"./createExpressions.js\";\nimport { transformValue } from \"./transform.js\";\nimport { getValue } from \"~/operations/entry/filtering/getValue.js\";\nimport { ValueFilterRegistry } from \"@webiny/db-dynamodb/exports/api/db.js\";\n\ninterface ExecuteFilterParams {\n value: any;\n filter: Filter;\n}\n\nconst executeFilter = (params: ExecuteFilterParams) => {\n const { value, filter } = params;\n\n /**\n * We need to check if the filter can be used.\n * If it cannot, we will just return true.\n */\n const canUse = filter.filter.canUse({\n value,\n compareValue: filter.compareValue\n });\n if (!canUse) {\n return true;\n }\n\n const matched = filter.filter.matches({\n value,\n compareValue: filter.compareValue\n });\n if (filter.negate) {\n return matched === false;\n }\n return matched;\n};\n\ninterface ExecuteExpressionsParams {\n getCachedValue: (filter: Filter) => Promise<any>;\n expressions: Expression[];\n filters: Filter[];\n condition: ExpressionCondition;\n}\n\nconst executeExpressions = (params: ExecuteExpressionsParams): boolean => {\n const { expressions, getCachedValue, filters, condition } = params;\n if (expressions.length === 0 && filters.length === 0) {\n return true;\n }\n /**\n * Always run filters first as they might trigger an early return.\n */\n for (const filter of filters) {\n const value = getCachedValue(filter);\n\n const result = executeFilter({\n value,\n filter\n });\n /**\n * Filters are ALWAYS executed as an AND.\n * So if even one is false, everything false.\n */\n if (!result) {\n return false;\n }\n }\n /**\n * Then we move onto expressions, which are basically nested upon nested filters with different conditions.\n */\n for (const expression of expressions) {\n const result = executeExpressions({\n ...expression,\n getCachedValue\n });\n if (result && condition === \"OR\") {\n return true;\n } else if (!result && condition == \"AND\") {\n return false;\n }\n }\n /**\n * If condition is an OR, we can fail the expressions check because the code would return a lot earlier than this line.\n *\n * 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.\n */\n return condition === \"OR\" ? false : true;\n};\n\ninterface IFilterParams<T extends CmsEntryValues = CmsEntryValues> {\n plugins: PluginsContainer;\n container: CmsContext[\"container\"];\n items: CmsEntry<T>[];\n where: Partial<CmsEntryListWhere>;\n fields: Record<string, Field>;\n fullTextSearch?: {\n term?: string;\n fields?: string[];\n };\n}\n\nexport const filter = <T extends CmsEntryValues = CmsEntryValues>(\n params: IFilterParams<T>\n): CmsEntry<T>[] => {\n const { items: records, where, plugins, fields, fullTextSearch, container } = params;\n\n const valueFilterRegistry = container.resolve(ValueFilterRegistry);\n\n const keys = Object.keys(where);\n if (keys.length === 0 && !fullTextSearch) {\n return records;\n }\n const expression = createExpressions({\n plugins,\n where,\n fields,\n container\n });\n\n /**\n * No point in going further if there are no expressions to be applied and no full text search to be executed.\n */\n if (\n expression.filters.length === 0 &&\n expression.expressions.length === 0 &&\n !fullTextSearch?.term\n ) {\n return records;\n }\n /**\n * We need the contains plugin to run the full text search.\n */\n const fullTextSearchFilter = valueFilterRegistry.get(\"contains\");\n if (!fullTextSearchFilter) {\n throw new WebinyError(\n `Missing \"contains\" plugin to run the full-text search.`,\n \"MISSING_PLUGIN\"\n );\n }\n\n const search = createFullTextSearch({\n term: fullTextSearch?.term,\n targetFields: fullTextSearch?.fields,\n fields,\n filter: fullTextSearchFilter\n });\n\n return records.filter(record => {\n const cachedValues: Record<string, any> = {};\n\n const getCachedValue = (filter: Filter) => {\n const { path } = filter;\n if (cachedValues[path] !== undefined) {\n return cachedValues[path];\n }\n const plainValue = getValue(record, path);\n\n const rawValue = transformValue({\n value: plainValue,\n transform: filter.transformValue\n });\n\n cachedValues[path] = rawValue;\n return rawValue;\n };\n\n const exprResult = executeExpressions({ ...expression, getCachedValue });\n /**\n * If expression result is false we do not need to continue further.\n * Also, if there is no full text search defined, just return the expression result.\n */\n if (!exprResult || !search) {\n return exprResult;\n }\n\n return search(record);\n });\n};\n"],"names":["executeFilter","params","value","filter","canUse","matched","executeExpressions","expressions","getCachedValue","filters","condition","result","expression","records","where","plugins","fields","fullTextSearch","container","valueFilterRegistry","ValueFilterRegistry","keys","Object","createExpressions","fullTextSearchFilter","WebinyError","search","createFullTextSearch","record","cachedValues","path","undefined","plainValue","getValue","rawValue","transformValue","exprResult"],"mappings":";;;;;;AAqBA,MAAMA,gBAAgB,CAACC;IACnB,MAAM,EAAEC,KAAK,EAAEC,MAAM,EAAE,GAAGF;IAM1B,MAAMG,SAASD,OAAO,MAAM,CAAC,MAAM,CAAC;QAChCD;QACA,cAAcC,OAAO,YAAY;IACrC;IACA,IAAI,CAACC,QACD,OAAO;IAGX,MAAMC,UAAUF,OAAO,MAAM,CAAC,OAAO,CAAC;QAClCD;QACA,cAAcC,OAAO,YAAY;IACrC;IACA,IAAIA,OAAO,MAAM,EACb,OAAOE,AAAY,UAAZA;IAEX,OAAOA;AACX;AASA,MAAMC,qBAAqB,CAACL;IACxB,MAAM,EAAEM,WAAW,EAAEC,cAAc,EAAEC,OAAO,EAAEC,SAAS,EAAE,GAAGT;IAC5D,IAAIM,AAAuB,MAAvBA,YAAY,MAAM,IAAUE,AAAmB,MAAnBA,QAAQ,MAAM,EAC1C,OAAO;IAKX,KAAK,MAAMN,UAAUM,QAAS;QAC1B,MAAMP,QAAQM,eAAeL;QAE7B,MAAMQ,SAASX,cAAc;YACzBE;YACAC;QACJ;QAKA,IAAI,CAACQ,QACD,OAAO;IAEf;IAIA,KAAK,MAAMC,cAAcL,YAAa;QAClC,MAAMI,SAASL,mBAAmB;YAC9B,GAAGM,UAAU;YACbJ;QACJ;QACA,IAAIG,UAAUD,AAAc,SAAdA,WACV,OAAO;aACJ,IAAI,CAACC,UAAUD,AAAa,SAAbA,WAClB,OAAO;IAEf;IAMA,OAAOA,AAAc,SAAdA;AACX;AAcO,MAAMP,gBAAS,CAClBF;IAEA,MAAM,EAAE,OAAOY,OAAO,EAAEC,KAAK,EAAEC,OAAO,EAAEC,MAAM,EAAEC,cAAc,EAAEC,SAAS,EAAE,GAAGjB;IAE9E,MAAMkB,sBAAsBD,UAAU,OAAO,CAACE;IAE9C,MAAMC,OAAOC,OAAO,IAAI,CAACR;IACzB,IAAIO,AAAgB,MAAhBA,KAAK,MAAM,IAAU,CAACJ,gBACtB,OAAOJ;IAEX,MAAMD,aAAaW,kBAAkB;QACjCR;QACAD;QACAE;QACAE;IACJ;IAKA,IACIN,AAA8B,MAA9BA,WAAW,OAAO,CAAC,MAAM,IACzBA,AAAkC,MAAlCA,WAAW,WAAW,CAAC,MAAM,IAC7B,CAACK,gBAAgB,MAEjB,OAAOJ;IAKX,MAAMW,uBAAuBL,oBAAoB,GAAG,CAAC;IACrD,IAAI,CAACK,sBACD,MAAM,IAAIC,MACN,0DACA;IAIR,MAAMC,SAASC,qBAAqB;QAChC,MAAMV,gBAAgB;QACtB,cAAcA,gBAAgB;QAC9BD;QACA,QAAQQ;IACZ;IAEA,OAAOX,QAAQ,MAAM,CAACe,CAAAA;QAClB,MAAMC,eAAoC,CAAC;QAE3C,MAAMrB,iBAAiB,CAACL;YACpB,MAAM,EAAE2B,IAAI,EAAE,GAAG3B;YACjB,IAAI0B,AAAuBE,WAAvBF,YAAY,CAACC,KAAK,EAClB,OAAOD,YAAY,CAACC,KAAK;YAE7B,MAAME,aAAaC,SAASL,QAAQE;YAEpC,MAAMI,WAAWC,eAAe;gBAC5B,OAAOH;gBACP,WAAW7B,OAAO,cAAc;YACpC;YAEA0B,YAAY,CAACC,KAAK,GAAGI;YACrB,OAAOA;QACX;QAEA,MAAME,aAAa9B,mBAAmB;YAAE,GAAGM,UAAU;YAAEJ;QAAe;QAKtE,IAAI,CAAC4B,cAAc,CAACV,QAChB,OAAOU;QAGX,OAAOV,OAAOE;IAClB;AACJ"}
@@ -10,12 +10,12 @@ const find = (target, input)=>{
10
10
  const value = target?.[path];
11
11
  if (void 0 === value) return;
12
12
  if (0 === paths.length) return value;
13
- if (Array.isArray(value)) {
13
+ else if (Array.isArray(value)) {
14
14
  if (0 === value.length) return;
15
15
  return value.reduce((collection, v)=>{
16
16
  const result = find(v, paths);
17
17
  if (void 0 === result) return collection;
18
- if (Array.isArray(result)) {
18
+ else if (Array.isArray(result)) {
19
19
  addArrayResult(collection, result);
20
20
  return collection;
21
21
  }
@@ -1 +1 @@
1
- {"version":3,"file":"operations/entry/filtering/getValue.js","sources":["../../../../src/operations/entry/filtering/getValue.ts"],"sourcesContent":["const addArrayResult = (target: any[], result: any[]): void => {\n for (const r of result) {\n if (target.some(t => r === t)) {\n continue;\n }\n target.push(r);\n }\n};\n/**\n * A recursive function which goes through given input paths and returns the value in it.\n * In case a path is an array, it goes through the array of those values to get values further down the path line.\n */\nconst find = (target: Record<string, any> | undefined, input: string[]): any[] | undefined => {\n const paths = [...input];\n const path = paths.shift();\n\n if (!path) {\n return undefined;\n }\n\n const value = target?.[path];\n if (value === undefined) {\n return undefined;\n }\n if (paths.length === 0) {\n return value;\n } else if (Array.isArray(value)) {\n if (value.length === 0) {\n return undefined;\n }\n return value.reduce<any[]>((collection, v) => {\n const result = find(v, paths);\n if (result === undefined) {\n return collection;\n } else if (Array.isArray(result)) {\n addArrayResult(collection, result);\n return collection;\n }\n collection.push(result);\n return collection;\n }, []);\n }\n return find(value, paths);\n};\n/**\n * A wrapper function for the find function.\n * Basically it transforms input paths to an array (and runs various checks).\n */\nexport const getValue = (target: Record<string, any>, input: string | string[]): any => {\n const paths = Array.isArray(input) ? input : input.split(\".\");\n if (paths.length === 0) {\n throw new Error(`Path is empty!`);\n }\n const filtered = paths.filter(Boolean);\n if (paths.length !== filtered.length) {\n throw new Error(\n `Input path is different than the filtered empty path string. (${paths.join(\n \".\"\n )} to ${filtered.join(\".\")})`\n );\n }\n\n return find(target, paths);\n};\n"],"names":["addArrayResult","target","result","r","t","find","input","paths","path","value","undefined","Array","collection","v","getValue","Error","filtered","Boolean"],"mappings":"AAAA,MAAMA,iBAAiB,CAACC,QAAeC;IACnC,KAAK,MAAMC,KAAKD,OACZ,KAAID,OAAO,IAAI,CAACG,CAAAA,IAAKD,MAAMC,IAG3BH,OAAO,IAAI,CAACE;AAEpB;AAKA,MAAME,OAAO,CAACJ,QAAyCK;IACnD,MAAMC,QAAQ;WAAID;KAAM;IACxB,MAAME,OAAOD,MAAM,KAAK;IAExB,IAAI,CAACC,MACD;IAGJ,MAAMC,QAAQR,QAAQ,CAACO,KAAK;IAC5B,IAAIC,AAAUC,WAAVD,OACA;IAEJ,IAAIF,AAAiB,MAAjBA,MAAM,MAAM,EACZ,OAAOE;IACJ,IAAIE,MAAM,OAAO,CAACF,QAAQ;QAC7B,IAAIA,AAAiB,MAAjBA,MAAM,MAAM,EACZ;QAEJ,OAAOA,MAAM,MAAM,CAAQ,CAACG,YAAYC;YACpC,MAAMX,SAASG,KAAKQ,GAAGN;YACvB,IAAIL,AAAWQ,WAAXR,QACA,OAAOU;YACJ,IAAID,MAAM,OAAO,CAACT,SAAS;gBAC9BF,eAAeY,YAAYV;gBAC3B,OAAOU;YACX;YACAA,WAAW,IAAI,CAACV;YAChB,OAAOU;QACX,GAAG,EAAE;IACT;IACA,OAAOP,KAAKI,OAAOF;AACvB;AAKO,MAAMO,WAAW,CAACb,QAA6BK;IAClD,MAAMC,QAAQI,MAAM,OAAO,CAACL,SAASA,QAAQA,MAAM,KAAK,CAAC;IACzD,IAAIC,AAAiB,MAAjBA,MAAM,MAAM,EACZ,MAAM,IAAIQ,MAAM;IAEpB,MAAMC,WAAWT,MAAM,MAAM,CAACU;IAC9B,IAAIV,MAAM,MAAM,KAAKS,SAAS,MAAM,EAChC,MAAM,IAAID,MACN,CAAC,8DAA8D,EAAER,MAAM,IAAI,CACvE,KACF,IAAI,EAAES,SAAS,IAAI,CAAC,KAAK,CAAC,CAAC;IAIrC,OAAOX,KAAKJ,QAAQM;AACxB"}
1
+ {"version":3,"file":"operations/entry/filtering/getValue.js","sources":["../../../../src/operations/entry/filtering/getValue.ts"],"sourcesContent":["const addArrayResult = (target: any[], result: any[]): void => {\n for (const r of result) {\n if (target.some(t => r === t)) {\n continue;\n }\n target.push(r);\n }\n};\n/**\n * A recursive function which goes through given input paths and returns the value in it.\n * In case a path is an array, it goes through the array of those values to get values further down the path line.\n */\nconst find = (target: Record<string, any> | undefined, input: string[]): any[] | undefined => {\n const paths = [...input];\n const path = paths.shift();\n\n if (!path) {\n return undefined;\n }\n\n const value = target?.[path];\n if (value === undefined) {\n return undefined;\n }\n if (paths.length === 0) {\n return value;\n } else if (Array.isArray(value)) {\n if (value.length === 0) {\n return undefined;\n }\n return value.reduce<any[]>((collection, v) => {\n const result = find(v, paths);\n if (result === undefined) {\n return collection;\n } else if (Array.isArray(result)) {\n addArrayResult(collection, result);\n return collection;\n }\n collection.push(result);\n return collection;\n }, []);\n }\n return find(value, paths);\n};\n/**\n * A wrapper function for the find function.\n * Basically it transforms input paths to an array (and runs various checks).\n */\nexport const getValue = (target: Record<string, any>, input: string | string[]): any => {\n const paths = Array.isArray(input) ? input : input.split(\".\");\n if (paths.length === 0) {\n throw new Error(`Path is empty!`);\n }\n const filtered = paths.filter(Boolean);\n if (paths.length !== filtered.length) {\n throw new Error(\n `Input path is different than the filtered empty path string. (${paths.join(\n \".\"\n )} to ${filtered.join(\".\")})`\n );\n }\n\n return find(target, paths);\n};\n"],"names":["addArrayResult","target","result","r","t","find","input","paths","path","value","undefined","Array","collection","v","getValue","Error","filtered","Boolean"],"mappings":"AAAA,MAAMA,iBAAiB,CAACC,QAAeC;IACnC,KAAK,MAAMC,KAAKD,OACZ,KAAID,OAAO,IAAI,CAACG,CAAAA,IAAKD,MAAMC,IAG3BH,OAAO,IAAI,CAACE;AAEpB;AAKA,MAAME,OAAO,CAACJ,QAAyCK;IACnD,MAAMC,QAAQ;WAAID;KAAM;IACxB,MAAME,OAAOD,MAAM,KAAK;IAExB,IAAI,CAACC,MACD;IAGJ,MAAMC,QAAQR,QAAQ,CAACO,KAAK;IAC5B,IAAIC,AAAUC,WAAVD,OACA;IAEJ,IAAIF,AAAiB,MAAjBA,MAAM,MAAM,EACZ,OAAOE;SACJ,IAAIE,MAAM,OAAO,CAACF,QAAQ;QAC7B,IAAIA,AAAiB,MAAjBA,MAAM,MAAM,EACZ;QAEJ,OAAOA,MAAM,MAAM,CAAQ,CAACG,YAAYC;YACpC,MAAMX,SAASG,KAAKQ,GAAGN;YACvB,IAAIL,AAAWQ,WAAXR,QACA,OAAOU;iBACJ,IAAID,MAAM,OAAO,CAACT,SAAS;gBAC9BF,eAAeY,YAAYV;gBAC3B,OAAOU;YACX;YACAA,WAAW,IAAI,CAACV;YAChB,OAAOU;QACX,GAAG,EAAE;IACT;IACA,OAAOP,KAAKI,OAAOF;AACvB;AAKO,MAAMO,WAAW,CAACb,QAA6BK;IAClD,MAAMC,QAAQI,MAAM,OAAO,CAACL,SAASA,QAAQA,MAAM,KAAK,CAAC;IACzD,IAAIC,AAAiB,MAAjBA,MAAM,MAAM,EACZ,MAAM,IAAIQ,MAAM;IAEpB,MAAMC,WAAWT,MAAM,MAAM,CAACU;IAC9B,IAAIV,MAAM,MAAM,KAAKS,SAAS,MAAM,EAChC,MAAM,IAAID,MACN,CAAC,8DAA8D,EAAER,MAAM,IAAI,CACvE,KACF,IAAI,EAAES,SAAS,IAAI,CAAC,KAAK,CAAC,CAAC;IAIrC,OAAOX,KAAKJ,QAAQM;AACxB"}
@@ -5,7 +5,7 @@ import * as __rspack_external_dot_prop_0ebbd169 from "dot-prop";
5
5
  const sort_sort = (params)=>{
6
6
  const { model, items, sort = [], fields, plugins } = params;
7
7
  if (items.length <= 1) return items;
8
- if (0 === sort.length) sort.push("savedOn_DESC");
8
+ else if (0 === sort.length) sort.push("savedOn_DESC");
9
9
  else if (sort.length > 1) throw new error("Sorting is limited to a single field on DynamoDB only system.", "SORT_MULTIPLE_FIELDS_ERROR", {
10
10
  sort
11
11
  });
@@ -1 +1 @@
1
- {"version":3,"file":"operations/entry/filtering/sort.js","sources":["../../../../src/operations/entry/filtering/sort.ts"],"sourcesContent":["import type { CmsEntry, CmsEntryValues, CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport WebinyError from \"@webiny/error\";\nimport * as dotProp from \"dot-prop\";\nimport lodashSortBy from \"lodash/sortBy.js\";\nimport { extractSort } from \"./extractSort.js\";\nimport type { Field } from \"./types.js\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\n\ninterface Params<T extends CmsEntryValues = CmsEntryValues> {\n model: CmsModel;\n items: CmsEntry<T>[];\n sort?: string[];\n fields: Record<string, Field>;\n plugins: PluginsContainer;\n}\n\ninterface SortedItem {\n id: string;\n value: any;\n}\n\nexport const sort = <T extends CmsEntryValues = CmsEntryValues>(\n params: Params<T>\n): CmsEntry<T>[] => {\n const { model, items, sort = [], fields, plugins } = params;\n if (items.length <= 1) {\n return items;\n } else if (sort.length === 0) {\n sort.push(\"savedOn_DESC\");\n } else if (sort.length > 1) {\n throw new WebinyError(\n \"Sorting is limited to a single field on DynamoDB only system.\",\n \"SORT_MULTIPLE_FIELDS_ERROR\",\n {\n sort\n }\n );\n }\n const [firstSort] = sort;\n if (!firstSort) {\n throw new WebinyError(\"Empty sort array item.\", \"SORT_EMPTY_ERROR\", {\n sort\n });\n }\n\n const { fieldId, field, valuePath, reverse } = extractSort({\n model,\n sortBy: firstSort,\n fields,\n plugins\n });\n\n const itemsToSort = items.map(item => {\n return {\n id: item.id,\n value: field.transform(dotProp.getProperty(item, valuePath))\n };\n });\n const sortedItems: SortedItem[] = lodashSortBy(itemsToSort, \"value\");\n const newItems = sortedItems.map(s => {\n const item = items.find(i => i.id === s.id);\n if (item) {\n return item;\n }\n /**\n * This is impossible to happen because sorting items does not remove the items.\n * BUT, we need to have this check just in case for development purposes.\n */\n throw new WebinyError(\n \"Could not find item by given id after the sorting.\",\n \"SORTING_ITEMS_ERROR\",\n {\n id: s.id,\n sortingBy: fieldId,\n reverse\n }\n );\n });\n if (!reverse) {\n return newItems;\n }\n return newItems.reverse();\n};\n"],"names":["sort","params","model","items","fields","plugins","WebinyError","firstSort","fieldId","field","valuePath","reverse","extractSort","itemsToSort","item","dotProp","sortedItems","lodashSortBy","newItems","s","i"],"mappings":";;;;AAqBO,MAAMA,YAAO,CAChBC;IAEA,MAAM,EAAEC,KAAK,EAAEC,KAAK,EAAEH,OAAO,EAAE,EAAEI,MAAM,EAAEC,OAAO,EAAE,GAAGJ;IACrD,IAAIE,MAAM,MAAM,IAAI,GAChB,OAAOA;IACJ,IAAIH,AAAgB,MAAhBA,KAAK,MAAM,EAClBA,KAAK,IAAI,CAAC;SACP,IAAIA,KAAK,MAAM,GAAG,GACrB,MAAM,IAAIM,MACN,iEACA,8BACA;QACIN;IACJ;IAGR,MAAM,CAACO,UAAU,GAAGP;IACpB,IAAI,CAACO,WACD,MAAM,IAAID,MAAY,0BAA0B,oBAAoB;QAChEN;IACJ;IAGJ,MAAM,EAAEQ,OAAO,EAAEC,KAAK,EAAEC,SAAS,EAAEC,OAAO,EAAE,GAAGC,YAAY;QACvDV;QACA,QAAQK;QACRH;QACAC;IACJ;IAEA,MAAMQ,cAAcV,MAAM,GAAG,CAACW,CAAAA,OACnB;YACH,IAAIA,KAAK,EAAE;YACX,OAAOL,MAAM,SAAS,CAACM,oCAAAA,WAAmB,CAACD,MAAMJ;QACrD;IAEJ,MAAMM,cAA4BC,OAAaJ,aAAa;IAC5D,MAAMK,WAAWF,YAAY,GAAG,CAACG,CAAAA;QAC7B,MAAML,OAAOX,MAAM,IAAI,CAACiB,CAAAA,IAAKA,EAAE,EAAE,KAAKD,EAAE,EAAE;QAC1C,IAAIL,MACA,OAAOA;QAMX,MAAM,IAAIR,MACN,sDACA,uBACA;YACI,IAAIa,EAAE,EAAE;YACR,WAAWX;YACXG;QACJ;IAER;IACA,IAAI,CAACA,SACD,OAAOO;IAEX,OAAOA,SAAS,OAAO;AAC3B"}
1
+ {"version":3,"file":"operations/entry/filtering/sort.js","sources":["../../../../src/operations/entry/filtering/sort.ts"],"sourcesContent":["import type { CmsEntry, CmsEntryValues, CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport WebinyError from \"@webiny/error\";\nimport * as dotProp from \"dot-prop\";\nimport lodashSortBy from \"lodash/sortBy.js\";\nimport { extractSort } from \"./extractSort.js\";\nimport type { Field } from \"./types.js\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\n\ninterface Params<T extends CmsEntryValues = CmsEntryValues> {\n model: CmsModel;\n items: CmsEntry<T>[];\n sort?: string[];\n fields: Record<string, Field>;\n plugins: PluginsContainer;\n}\n\ninterface SortedItem {\n id: string;\n value: any;\n}\n\nexport const sort = <T extends CmsEntryValues = CmsEntryValues>(\n params: Params<T>\n): CmsEntry<T>[] => {\n const { model, items, sort = [], fields, plugins } = params;\n if (items.length <= 1) {\n return items;\n } else if (sort.length === 0) {\n sort.push(\"savedOn_DESC\");\n } else if (sort.length > 1) {\n throw new WebinyError(\n \"Sorting is limited to a single field on DynamoDB only system.\",\n \"SORT_MULTIPLE_FIELDS_ERROR\",\n {\n sort\n }\n );\n }\n const [firstSort] = sort;\n if (!firstSort) {\n throw new WebinyError(\"Empty sort array item.\", \"SORT_EMPTY_ERROR\", {\n sort\n });\n }\n\n const { fieldId, field, valuePath, reverse } = extractSort({\n model,\n sortBy: firstSort,\n fields,\n plugins\n });\n\n const itemsToSort = items.map(item => {\n return {\n id: item.id,\n value: field.transform(dotProp.getProperty(item, valuePath))\n };\n });\n const sortedItems: SortedItem[] = lodashSortBy(itemsToSort, \"value\");\n const newItems = sortedItems.map(s => {\n const item = items.find(i => i.id === s.id);\n if (item) {\n return item;\n }\n /**\n * This is impossible to happen because sorting items does not remove the items.\n * BUT, we need to have this check just in case for development purposes.\n */\n throw new WebinyError(\n \"Could not find item by given id after the sorting.\",\n \"SORTING_ITEMS_ERROR\",\n {\n id: s.id,\n sortingBy: fieldId,\n reverse\n }\n );\n });\n if (!reverse) {\n return newItems;\n }\n return newItems.reverse();\n};\n"],"names":["sort","params","model","items","fields","plugins","WebinyError","firstSort","fieldId","field","valuePath","reverse","extractSort","itemsToSort","item","dotProp","sortedItems","lodashSortBy","newItems","s","i"],"mappings":";;;;AAqBO,MAAMA,YAAO,CAChBC;IAEA,MAAM,EAAEC,KAAK,EAAEC,KAAK,EAAEH,OAAO,EAAE,EAAEI,MAAM,EAAEC,OAAO,EAAE,GAAGJ;IACrD,IAAIE,MAAM,MAAM,IAAI,GAChB,OAAOA;SACJ,IAAIH,AAAgB,MAAhBA,KAAK,MAAM,EAClBA,KAAK,IAAI,CAAC;SACP,IAAIA,KAAK,MAAM,GAAG,GACrB,MAAM,IAAIM,MACN,iEACA,8BACA;QACIN;IACJ;IAGR,MAAM,CAACO,UAAU,GAAGP;IACpB,IAAI,CAACO,WACD,MAAM,IAAID,MAAY,0BAA0B,oBAAoB;QAChEN;IACJ;IAGJ,MAAM,EAAEQ,OAAO,EAAEC,KAAK,EAAEC,SAAS,EAAEC,OAAO,EAAE,GAAGC,YAAY;QACvDV;QACA,QAAQK;QACRH;QACAC;IACJ;IAEA,MAAMQ,cAAcV,MAAM,GAAG,CAACW,CAAAA,OACnB;YACH,IAAIA,KAAK,EAAE;YACX,OAAOL,MAAM,SAAS,CAACM,oCAAAA,WAAmB,CAACD,MAAMJ;QACrD;IAEJ,MAAMM,cAA4BC,OAAaJ,aAAa;IAC5D,MAAMK,WAAWF,YAAY,GAAG,CAACG,CAAAA;QAC7B,MAAML,OAAOX,MAAM,IAAI,CAACiB,CAAAA,IAAKA,EAAE,EAAE,KAAKD,EAAE,EAAE;QAC1C,IAAIL,MACA,OAAOA;QAMX,MAAM,IAAIR,MACN,sDACA,uBACA;YACI,IAAIa,EAAE,EAAE;YACR,WAAWX;YACXG;QACJ;IAER;IACA,IAAI,CAACA,SACD,OAAOO;IAEX,OAAOA,SAAS,OAAO;AAC3B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-headless-cms-ddb",
3
- "version": "6.4.11-beta.1",
3
+ "version": "6.4.12-beta.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./index.js",
@@ -26,28 +26,28 @@
26
26
  ],
27
27
  "license": "MIT",
28
28
  "dependencies": {
29
- "@webiny/api": "6.4.11-beta.1",
30
- "@webiny/api-headless-cms": "6.4.11-beta.1",
31
- "@webiny/aws-sdk": "6.4.11-beta.1",
32
- "@webiny/db-dynamodb": "6.4.11-beta.1",
33
- "@webiny/error": "6.4.11-beta.1",
34
- "@webiny/feature": "6.4.11-beta.1",
35
- "@webiny/handler": "6.4.11-beta.1",
36
- "@webiny/handler-db": "6.4.11-beta.1",
37
- "@webiny/utils": "6.4.11-beta.1",
29
+ "@webiny/api": "6.4.12-beta.0",
30
+ "@webiny/api-headless-cms": "6.4.12-beta.0",
31
+ "@webiny/aws-sdk": "6.4.12-beta.0",
32
+ "@webiny/db-dynamodb": "6.4.12-beta.0",
33
+ "@webiny/error": "6.4.12-beta.0",
34
+ "@webiny/feature": "6.4.12-beta.0",
35
+ "@webiny/handler": "6.4.12-beta.0",
36
+ "@webiny/handler-db": "6.4.12-beta.0",
37
+ "@webiny/utils": "6.4.12-beta.0",
38
38
  "dataloader": "2.2.3",
39
- "dot-prop": "10.1.0",
39
+ "dot-prop": "10.2.0",
40
40
  "lodash": "4.18.1"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@types/jsonpack": "1.1.6",
44
- "@webiny/build-tools": "6.4.11-beta.1",
45
- "@webiny/di": "1.0.2",
46
- "@webiny/plugins": "6.4.11-beta.1",
47
- "@webiny/project-utils": "6.4.11-beta.1",
44
+ "@webiny/build-tools": "6.4.12-beta.0",
45
+ "@webiny/di": "1.1.0",
46
+ "@webiny/plugins": "6.4.12-beta.0",
47
+ "@webiny/project-utils": "6.4.12-beta.0",
48
48
  "jest-dynalite": "3.6.1",
49
49
  "typescript": "6.0.3",
50
- "vitest": "4.1.10"
50
+ "vitest": "5.0.1"
51
51
  },
52
52
  "publishConfig": {
53
53
  "access": "public"
@@ -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 /**\n * We expect error here because we know that `this.constructor.type` is defined, but TS does not.\n */\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;QAMd,IAAI,CAAC,IAAI,GAAG,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE;IACnE;IAEO,OAAOC,KAA8C,EAAEC,OAAiB,EAAW;QACtF,IAAID,MAAM,IAAI,KAAK,IAAI,CAAC,MAAM,CAAC,SAAS,EACpC,OAAO;QACJ,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,EACzB,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAACA,OAAOC;QAErC,MAAMC,UAAU,IAAI,CAAC,MAAM,CAAC,OAAO;QACnC,IAAI,CAACA,WAAWC,AAA2B,UAA3BA,MAAM,OAAO,CAACD,YAAsBA,AAAmB,MAAnBA,QAAQ,MAAM,EAC9D,OAAO;QAEX,OAAOA,QAAQ,QAAQ,CAACF,MAAM,OAAO;IACzC;IAEO,WAAWI,MAAgC,EAAU;QACxD,IAAI,AAA4B,cAA5B,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,EACvB,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAACA;QACrB,IAAI,AAA4B,YAA5B,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,EAC9B,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI;QAE3B,MAAM,IAAIC,MAAY,CAAC,iBAAiB,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC;IAClE;AACJ"}
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 /**\n * We expect error here because we know that `this.constructor.type` is defined, but TS does not.\n */\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;QAMd,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"}