@webiny/api-headless-cms-ddb 6.3.0 → 6.4.0-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.
Files changed (100) hide show
  1. package/definitions/entry.js +7 -9
  2. package/definitions/entry.js.map +1 -1
  3. package/definitions/group.js +7 -9
  4. package/definitions/group.js.map +1 -1
  5. package/definitions/model.js +7 -9
  6. package/definitions/model.js.map +1 -1
  7. package/definitions/table.js +6 -7
  8. package/definitions/table.js.map +1 -1
  9. package/definitions/types.d.ts +1 -0
  10. package/definitions/types.js +0 -3
  11. package/dynamoDb/index.js +6 -1
  12. package/dynamoDb/index.js.map +1 -1
  13. package/dynamoDb/path/locationFolderId.js +16 -29
  14. package/dynamoDb/path/locationFolderId.js.map +1 -1
  15. package/dynamoDb/path/plainObject.js +11 -21
  16. package/dynamoDb/path/plainObject.js.map +1 -1
  17. package/dynamoDb/transformValue/datetime.js +21 -32
  18. package/dynamoDb/transformValue/datetime.js.map +1 -1
  19. package/index.js +67 -77
  20. package/index.js.map +1 -1
  21. package/operations/entry/dataLoader/DataLoaderCache.js +22 -26
  22. package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -1
  23. package/operations/entry/dataLoader/constants.js +2 -1
  24. package/operations/entry/dataLoader/constants.js.map +1 -1
  25. package/operations/entry/dataLoader/createBatchScheduleFn.js +6 -15
  26. package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -1
  27. package/operations/entry/dataLoader/getAllEntryRevisions.js +18 -29
  28. package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -1
  29. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +31 -41
  30. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -1
  31. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +31 -41
  32. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -1
  33. package/operations/entry/dataLoader/getRevisionById.js +33 -47
  34. package/operations/entry/dataLoader/getRevisionById.js.map +1 -1
  35. package/operations/entry/dataLoader/index.js +8 -9
  36. package/operations/entry/dataLoader/index.js.map +1 -1
  37. package/operations/entry/dataLoader/types.js +0 -3
  38. package/operations/entry/dataLoaders.js +81 -99
  39. package/operations/entry/dataLoaders.js.map +1 -1
  40. package/operations/entry/filtering/createExpressions.js +109 -157
  41. package/operations/entry/filtering/createExpressions.js.map +1 -1
  42. package/operations/entry/filtering/createFields.js +83 -96
  43. package/operations/entry/filtering/createFields.js.map +1 -1
  44. package/operations/entry/filtering/extractSort.js +50 -74
  45. package/operations/entry/filtering/extractSort.js.map +1 -1
  46. package/operations/entry/filtering/filter.js +72 -140
  47. package/operations/entry/filtering/filter.js.map +1 -1
  48. package/operations/entry/filtering/fullTextSearch.js +21 -38
  49. package/operations/entry/filtering/fullTextSearch.js.map +1 -1
  50. package/operations/entry/filtering/getValue.js +31 -53
  51. package/operations/entry/filtering/getValue.js.map +1 -1
  52. package/operations/entry/filtering/index.js +0 -2
  53. package/operations/entry/filtering/mapPlugins.js +15 -22
  54. package/operations/entry/filtering/mapPlugins.js.map +1 -1
  55. package/operations/entry/filtering/plugins/defaultFilterCreate.js +29 -33
  56. package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -1
  57. package/operations/entry/filtering/plugins/index.js +7 -3
  58. package/operations/entry/filtering/plugins/index.js.map +1 -1
  59. package/operations/entry/filtering/plugins/objectFilterCreate.js +60 -76
  60. package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -1
  61. package/operations/entry/filtering/plugins/refFilterCreate.js +55 -66
  62. package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -1
  63. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js +43 -56
  64. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js.map +1 -1
  65. package/operations/entry/filtering/sort.js +34 -60
  66. package/operations/entry/filtering/sort.js.map +1 -1
  67. package/operations/entry/filtering/systemFields.js +144 -126
  68. package/operations/entry/filtering/systemFields.js.map +1 -1
  69. package/operations/entry/filtering/transform.js +4 -8
  70. package/operations/entry/filtering/transform.js.map +1 -1
  71. package/operations/entry/filtering/types.js +0 -3
  72. package/operations/entry/filtering/values.js +11 -12
  73. package/operations/entry/filtering/values.js.map +1 -1
  74. package/operations/entry/filtering/where.js +17 -23
  75. package/operations/entry/filtering/where.js.map +1 -1
  76. package/operations/entry/index.js +894 -1148
  77. package/operations/entry/index.js.map +1 -1
  78. package/operations/entry/keys.js +54 -77
  79. package/operations/entry/keys.js.map +1 -1
  80. package/operations/group/index.js +113 -134
  81. package/operations/group/index.js.map +1 -1
  82. package/operations/model/index.js +100 -121
  83. package/operations/model/index.js.map +1 -1
  84. package/package.json +15 -15
  85. package/plugins/CmsEntryFieldFilterPathPlugin.js +23 -33
  86. package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -1
  87. package/plugins/CmsEntryFieldFilterPlugin.js +16 -17
  88. package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -1
  89. package/plugins/CmsEntryFieldSortingPlugin.js +16 -15
  90. package/plugins/CmsEntryFieldSortingPlugin.js.map +1 -1
  91. package/plugins/CmsFieldFilterValueTransformPlugin.js +15 -12
  92. package/plugins/CmsFieldFilterValueTransformPlugin.js.map +1 -1
  93. package/plugins/index.js +0 -2
  94. package/types.js +6 -5
  95. package/types.js.map +1 -1
  96. package/definitions/types.js.map +0 -1
  97. package/operations/entry/dataLoader/types.js.map +0 -1
  98. package/operations/entry/filtering/index.js.map +0 -1
  99. package/operations/entry/filtering/types.js.map +0 -1
  100. package/plugins/index.js.map +0 -1
@@ -2,105 +2,92 @@ import { createSystemFields } from "./systemFields.js";
2
2
  import { CmsEntryFieldFilterPathPlugin } from "../../../plugins/index.js";
3
3
  import { getMappedPlugins } from "./mapPlugins.js";
4
4
  import { getBaseFieldType } from "@webiny/api-headless-cms/utils/getBaseFieldType.js";
5
- const createFieldCollection = params => {
6
- const {
7
- fields,
8
- parents,
9
- transformValuePlugins,
10
- valuePathPlugins,
11
- system
12
- } = params;
13
- return fields.reduce((collection, field) => {
14
- const fieldType = getBaseFieldType(field);
15
- const transformPlugin = transformValuePlugins[fieldType];
16
- const valuePathPlugin = valuePathPlugins[fieldType];
17
-
18
- /**
19
- * The required fieldId is a product of all of its parents and its own fieldId.
20
- */
21
- const fieldId = [...parents, {
22
- fieldId: field.fieldId,
23
- list: field.list
24
- }].map(f => f.fieldId).join(".");
25
- collection[fieldId] = {
26
- ...field,
27
- parents,
28
- system,
29
- createPath: params => {
30
- if (valuePathPlugin && valuePathPlugin.canUse(field, parents.map(p => p.fieldId))) {
31
- return valuePathPlugin.createPath(params);
32
- }
33
- return parents.map(parent => parent.fieldId).concat([params.field.fieldId]).join(".");
34
- },
35
- transform: value => {
36
- if (!transformPlugin) {
37
- return value;
38
- }
39
- return transformPlugin.transform({
40
- field,
41
- value
5
+ const createFieldCollection = (params)=>{
6
+ const { fields, parents, transformValuePlugins, valuePathPlugins, system } = params;
7
+ return fields.reduce((collection, field)=>{
8
+ const fieldType = getBaseFieldType(field);
9
+ const transformPlugin = transformValuePlugins[fieldType];
10
+ const valuePathPlugin = valuePathPlugins[fieldType];
11
+ const fieldId = [
12
+ ...parents,
13
+ {
14
+ fieldId: field.fieldId,
15
+ list: field.list
16
+ }
17
+ ].map((f)=>f.fieldId).join(".");
18
+ collection[fieldId] = {
19
+ ...field,
20
+ parents,
21
+ system,
22
+ createPath: (params)=>{
23
+ if (valuePathPlugin && valuePathPlugin.canUse(field, parents.map((p)=>p.fieldId))) return valuePathPlugin.createPath(params);
24
+ return parents.map((parent)=>parent.fieldId).concat([
25
+ params.field.fieldId
26
+ ]).join(".");
27
+ },
28
+ transform: (value)=>{
29
+ if (!transformPlugin) return value;
30
+ return transformPlugin.transform({
31
+ field,
32
+ value
33
+ });
34
+ }
35
+ };
36
+ const childFields = field.settings?.fields;
37
+ if (!childFields?.length) return collection;
38
+ const result = createFieldCollection({
39
+ fields: childFields,
40
+ parents: [
41
+ ...parents,
42
+ {
43
+ fieldId: field.fieldId,
44
+ list: field.list
45
+ }
46
+ ],
47
+ transformValuePlugins,
48
+ valuePathPlugins,
49
+ system
42
50
  });
43
- }
44
- };
45
- const childFields = field.settings?.fields;
46
- if (!childFields?.length) {
47
- return collection;
48
- }
51
+ Object.assign(collection, result);
52
+ return collection;
53
+ }, {});
54
+ };
55
+ const createFields = (params)=>{
56
+ const { fields, plugins } = params;
57
+ const transformValuePlugins = getMappedPlugins({
58
+ plugins,
59
+ type: "cms-field-filter-value-transform",
60
+ property: "fieldType"
61
+ });
62
+ const valuePathPlugins = getMappedPlugins({
63
+ plugins,
64
+ type: CmsEntryFieldFilterPathPlugin.type,
65
+ property: "fieldType"
66
+ });
67
+ const collection = createFieldCollection({
68
+ fields: createSystemFields(),
69
+ transformValuePlugins,
70
+ valuePathPlugins,
71
+ parents: [],
72
+ system: true
73
+ });
49
74
  const result = createFieldCollection({
50
- fields: childFields,
51
- parents: [...parents, {
52
- fieldId: field.fieldId,
53
- list: field.list
54
- }],
55
- transformValuePlugins,
56
- valuePathPlugins,
57
- system
75
+ fields,
76
+ transformValuePlugins,
77
+ valuePathPlugins,
78
+ parents: [
79
+ {
80
+ fieldId: "values",
81
+ list: false
82
+ }
83
+ ],
84
+ system: false
58
85
  });
59
- Object.assign(collection, result);
60
- return collection;
61
- }, {});
62
- };
63
- /**
64
- * This method will map the fieldId (fieldId -> field) to the actual field.
65
- *
66
- * In case of nested fields, fieldId is all the parent fieldIds + current one, joined by the dot (.).
67
- */
68
- export const createFields = params => {
69
- const {
70
- fields,
71
- plugins
72
- } = params;
73
- const transformValuePlugins = getMappedPlugins({
74
- plugins,
75
- type: "cms-field-filter-value-transform",
76
- property: "fieldType"
77
- });
78
- const valuePathPlugins = getMappedPlugins({
79
- plugins,
80
- type: CmsEntryFieldFilterPathPlugin.type,
81
- property: "fieldType"
82
- });
83
- const collection = createFieldCollection({
84
- fields: createSystemFields(),
85
- transformValuePlugins,
86
- valuePathPlugins,
87
- parents: [],
88
- system: true
89
- });
90
- const result = createFieldCollection({
91
- fields,
92
- transformValuePlugins,
93
- valuePathPlugins,
94
- parents: [{
95
- fieldId: "values",
96
- list: false
97
- }],
98
- system: false
99
- });
100
- return {
101
- ...collection,
102
- ...result
103
- };
86
+ return {
87
+ ...collection,
88
+ ...result
89
+ };
104
90
  };
91
+ export { createFields };
105
92
 
106
93
  //# sourceMappingURL=createFields.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createSystemFields","CmsEntryFieldFilterPathPlugin","getMappedPlugins","getBaseFieldType","createFieldCollection","params","fields","parents","transformValuePlugins","valuePathPlugins","system","reduce","collection","field","fieldType","transformPlugin","valuePathPlugin","fieldId","list","map","f","join","createPath","canUse","p","parent","concat","transform","value","childFields","settings","length","result","Object","assign","createFields","plugins","type","property"],"sources":["createFields.ts"],"sourcesContent":["import type { CmsModelField } from \"@webiny/api-headless-cms/types/index.js\";\nimport { createSystemFields } from \"./systemFields.js\";\nimport type { Field, FieldParent } from \"./types.js\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport type { CmsFieldFilterValueTransformPlugin } from \"~/types.js\";\nimport { CmsEntryFieldFilterPathPlugin } from \"~/plugins/index.js\";\nimport { getMappedPlugins } from \"./mapPlugins.js\";\nimport { getBaseFieldType } from \"@webiny/api-headless-cms/utils/getBaseFieldType.js\";\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 fieldType = getBaseFieldType(field);\n const transformPlugin = transformValuePlugins[fieldType];\n const valuePathPlugin = valuePathPlugins[fieldType];\n\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 list: field.list\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 parents\n .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 list: field.list\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 {\n fieldId: \"values\",\n list: false\n }\n ],\n system: false\n });\n\n return {\n ...collection,\n ...result\n };\n};\n"],"mappings":"AACA,SAASA,kBAAkB;AAI3B,SAASC,6BAA6B;AACtC,SAASC,gBA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C;IACjCE,MAAM;IACNE,qBAAqB;IACrBC,gBAAgB;IAChBF,OAAO,EAAE,CACL;MACIU,OAAO,EAAE,QAAQ;MACjBC,IAAI,EAAE;IACV,CAAC,CACJ;IACDR,MAAM,EAAE;EACZ,CAAC,CAAC;EAEF,OAAO;IACH,GAAGE,UAAU;IACb,GAAGoB;EACP,CAAC;AACL,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"operations/entry/filtering/createFields.js","sources":["../../../../src/operations/entry/filtering/createFields.ts"],"sourcesContent":["import type { CmsModelField } from \"@webiny/api-headless-cms/types/index.js\";\nimport { createSystemFields } from \"./systemFields.js\";\nimport type { Field, FieldParent } from \"./types.js\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport type { CmsFieldFilterValueTransformPlugin } from \"~/types.js\";\nimport { CmsEntryFieldFilterPathPlugin } from \"~/plugins/index.js\";\nimport { getMappedPlugins } from \"./mapPlugins.js\";\nimport { getBaseFieldType } from \"@webiny/api-headless-cms/utils/getBaseFieldType.js\";\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 fieldType = getBaseFieldType(field);\n const transformPlugin = transformValuePlugins[fieldType];\n const valuePathPlugin = valuePathPlugins[fieldType];\n\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 list: field.list\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 parents\n .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 list: field.list\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 {\n fieldId: \"values\",\n list: false\n }\n ],\n system: false\n });\n\n return {\n ...collection,\n ...result\n };\n};\n"],"names":["createFieldCollection","params","fields","parents","transformValuePlugins","valuePathPlugins","system","collection","field","fieldType","getBaseFieldType","transformPlugin","valuePathPlugin","fieldId","f","p","parent","value","childFields","result","Object","createFields","plugins","getMappedPlugins","CmsEntryFieldFilterPathPlugin","createSystemFields"],"mappings":";;;;AA0BA,MAAMA,wBAAwB,CAACC;IAC3B,MAAM,EAAEC,MAAM,EAAEC,OAAO,EAAEC,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AMG,wBAAwBmB,iBAAqD;QAC/ED;QACA,MAAM;QACN,UAAU;IACd;IACA,MAAMjB,mBAAmBkB,iBAAgD;QACrED;QACA,MAAME,8BAA8B,IAAI;QACxC,UAAU;IACd;IAEA,MAAMjB,aAAaP,sBAAsB;QACrC,QAAQyB;QACRrB;QACAC;QACA,SAAS,EAAE;QACX,QAAQ;IACZ;IAEA,MAAMc,SAASnB,sBAAsB;QACjCE;QACAE;QACAC;QACA,SAAS;YACL;gBACI,SAAS;gBACT,MAAM;YACV;SACH;QACD,QAAQ;IACZ;IAEA,OAAO;QACH,GAAGE,UAAU;QACb,GAAGY,MAAM;IACb;AACJ"}
@@ -1,84 +1,60 @@
1
- import WebinyError from "@webiny/error";
1
+ import error from "@webiny/error";
2
2
  import { CmsEntryFieldSortingPlugin } from "../../../plugins/index.js";
3
- const extractSortInfo = sortBy => {
4
- const rootSorting = sortBy.match(/^([a-zA-Z]+)_(ASC|DESC)$/);
5
- if (rootSorting) {
6
- return {
7
- fieldId: rootSorting[1],
8
- isValues: false,
9
- order: rootSorting[2]
3
+ const extractSortInfo = (sortBy)=>{
4
+ const rootSorting = sortBy.match(/^([a-zA-Z]+)_(ASC|DESC)$/);
5
+ if (rootSorting) return {
6
+ fieldId: rootSorting[1],
7
+ isValues: false,
8
+ order: rootSorting[2]
10
9
  };
11
- }
12
- const valuesSorting = sortBy.match(/^values_([a-zA-Z0-9]+)_(ASC|DESC)$/);
13
- if (valuesSorting) {
14
- return {
15
- fieldId: valuesSorting[1],
16
- isValues: true,
17
- order: valuesSorting[2]
10
+ const valuesSorting = sortBy.match(/^values_([a-zA-Z0-9]+)_(ASC|DESC)$/);
11
+ if (valuesSorting) return {
12
+ fieldId: valuesSorting[1],
13
+ isValues: true,
14
+ order: valuesSorting[2]
18
15
  };
19
- }
20
- throw new WebinyError("Problem in determining the sorting for the entry items.", "SORT_EXTRACT_ERROR", {
21
- sortBy
22
- });
16
+ throw new error("Problem in determining the sorting for the entry items.", "SORT_EXTRACT_ERROR", {
17
+ sortBy
18
+ });
23
19
  };
24
- export const extractSort = params => {
25
- const {
26
- model,
27
- sortBy,
28
- fields,
29
- plugins
30
- } = params;
31
- const {
32
- fieldId,
33
- isValues: isValuesSorting,
34
- order
35
- } = extractSortInfo(sortBy);
36
- const field = Object.values(fields).find(f => {
37
- /**
38
- * We do not support sorting by nested fields.
39
- */
40
- const isValues = f.parents[0]?.fieldId === "values";
41
- if (isValues && isValuesSorting) {
42
- return f.fieldId === fieldId;
43
- }
44
- if (f.parents.length > 0) {
45
- return false;
46
- }
47
- return f.fieldId === fieldId;
48
- });
49
- const plugin = plugins.byType(CmsEntryFieldSortingPlugin.type).reverse().find(plugin => {
50
- return plugin.canUse({
51
- model,
52
- field,
53
- fieldId,
54
- order,
55
- sortBy
20
+ const extractSort = (params)=>{
21
+ const { model, sortBy, fields, plugins } = params;
22
+ const { fieldId, isValues: isValuesSorting, order } = extractSortInfo(sortBy);
23
+ const field = Object.values(fields).find((f)=>{
24
+ const isValues = f.parents[0]?.fieldId === "values";
25
+ if (isValues && isValuesSorting) return f.fieldId === fieldId;
26
+ if (f.parents.length > 0) return false;
27
+ return f.fieldId === fieldId;
56
28
  });
57
- });
58
- if (plugin) {
59
- return plugin.createSort({
60
- model,
61
- fieldId,
62
- order,
63
- sortBy,
64
- field,
65
- fields
29
+ const plugin = plugins.byType(CmsEntryFieldSortingPlugin.type).reverse().find((plugin)=>plugin.canUse({
30
+ model,
31
+ field,
32
+ fieldId,
33
+ order,
34
+ sortBy
35
+ }));
36
+ if (plugin) return plugin.createSort({
37
+ model,
38
+ fieldId,
39
+ order,
40
+ sortBy,
41
+ field,
42
+ fields
66
43
  });
67
- } else if (!field) {
68
- throw new WebinyError("Sorting field does not exist in the content model.", "SORTING_FIELD_ERROR", {
69
- fieldId,
70
- fields
44
+ if (!field) throw new error("Sorting field does not exist in the content model.", "SORTING_FIELD_ERROR", {
45
+ fieldId,
46
+ fields
71
47
  });
72
- }
73
- const valuePath = field.createPath({
74
- field
75
- });
76
- return {
77
- field,
78
- fieldId,
79
- valuePath,
80
- reverse: order === "DESC"
81
- };
48
+ const valuePath = field.createPath({
49
+ field
50
+ });
51
+ return {
52
+ field,
53
+ fieldId,
54
+ valuePath,
55
+ reverse: "DESC" === order
56
+ };
82
57
  };
58
+ export { extractSort };
83
59
 
84
60
  //# sourceMappingURL=extractSort.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["WebinyError","CmsEntryFieldSortingPlugin","extractSortInfo","sortBy","rootSorting","match","fieldId","isValues","order","valuesSorting","extractSort","params","model","fields","plugins","isValuesSorting","field","Object","values","find","f","parents","length","plugin","byType","type","reverse","canUse","createSort","valuePath","createPath"],"sources":["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"],"mappings":"AAAA,OAAOA,WAAW,MAAM,eAAe;AAGvC,SAASC,0BAA0B;AAGnC,MAAMC,eAAe,GAAIC,MAAc,IAAK;EACxC,MAAMC,WAAW,GAAGD,MAAM,CAACE,KAAK,CAAC,0BAA0B,CAAC;EAC5D,IAAID,WAAW,EAAE;IACb,OAAO;MACHE,OAAO,EAAEF,WAAW,CAAC,CAAC,CAAC;MACvBG,QAAQ,EAAE,KAAK;MACfC,KAAK,EAAEJ,WAAW,CAAC,CAAC;IACxB,CAAC;EACL;EACA,MAAMK,aAAa,GAAGN,MAAM,CAACE,KAAK,CAAC,oCAAoC,CAAC;EACxE,IAAII,aAAa,EAAE;IACf,OAAO;MACHH,OAAO,EAAEG,aAAa,CAAC,CAAC,CAAC;MACzBF,QAAQ,EAAE,IAAI;MACdC,KAAK,EAAEC,aAAa,CAAC,CAAC;IAC1B,CAAC;EACL;EACA,MAAM,IAAIT,WAAW,CACjB,yDAAyD,EACzD,oBAAoB,EACpB;IACIG;EACJ,CACJ,CAAC;AACL,CAAC;AAgBD,OAA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gB,SAAS,GAAGb,KAAK,CAACc,UAAU,CAAC;IAC/Bd;EACJ,CAAC,CAAC;EACF,OAAO;IACHA,KAAK;IACLV,OAAO;IACPuB,SAAS;IACTH,OAAO,EAAElB,KAAK,KAAK;EACvB,CAAC;AACL,CAAC","ignoreList":[]}
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,153 +1,85 @@
1
- import WebinyError from "@webiny/error";
1
+ import error from "@webiny/error";
2
2
  import { createFullTextSearch } from "./fullTextSearch.js";
3
3
  import { createExpressions } from "./createExpressions.js";
4
4
  import { transformValue } from "./transform.js";
5
5
  import { getValue } from "./getValue.js";
6
6
  import { ValueFilterRegistry } from "@webiny/db-dynamodb/exports/api/db.js";
7
- const executeFilter = params => {
8
- const {
9
- value,
10
- filter
11
- } = params;
12
-
13
- /**
14
- * We need to check if the filter can be used.
15
- * If it cannot, we will just return true.
16
- */
17
- const canUse = filter.filter.canUse({
18
- value,
19
- compareValue: filter.compareValue
20
- });
21
- if (!canUse) {
22
- return true;
23
- }
24
- const matched = filter.filter.matches({
25
- value,
26
- compareValue: filter.compareValue
27
- });
28
- if (filter.negate) {
29
- return matched === false;
30
- }
31
- return matched;
32
- };
33
- const executeExpressions = params => {
34
- const {
35
- expressions,
36
- getCachedValue,
37
- filters,
38
- condition
39
- } = params;
40
- if (expressions.length === 0 && filters.length === 0) {
41
- return true;
42
- }
43
- /**
44
- * Always run filters first as they might trigger an early return.
45
- */
46
- for (const filter of filters) {
47
- const value = getCachedValue(filter);
48
- const result = executeFilter({
49
- value,
50
- filter
7
+ const executeFilter = (params)=>{
8
+ const { value, filter } = params;
9
+ const canUse = filter.filter.canUse({
10
+ value,
11
+ compareValue: filter.compareValue
51
12
  });
52
- /**
53
- * Filters are ALWAYS executed as an AND.
54
- * So if even one is false, everything false.
55
- */
56
- if (!result) {
57
- return false;
58
- }
59
- }
60
- /**
61
- * Then we move onto expressions, which are basically nested upon nested filters with different conditions.
62
- */
63
- for (const expression of expressions) {
64
- const result = executeExpressions({
65
- ...expression,
66
- getCachedValue
13
+ if (!canUse) return true;
14
+ const matched = filter.filter.matches({
15
+ value,
16
+ compareValue: filter.compareValue
67
17
  });
68
- if (result && condition === "OR") {
69
- return true;
70
- } else if (!result && condition == "AND") {
71
- return false;
18
+ if (filter.negate) return false === matched;
19
+ return matched;
20
+ };
21
+ const executeExpressions = (params)=>{
22
+ const { expressions, getCachedValue, filters, condition } = params;
23
+ if (0 === expressions.length && 0 === filters.length) return true;
24
+ for (const filter of filters){
25
+ const value = getCachedValue(filter);
26
+ const result = executeFilter({
27
+ value,
28
+ filter
29
+ });
30
+ if (!result) return false;
31
+ }
32
+ for (const expression of expressions){
33
+ const result = executeExpressions({
34
+ ...expression,
35
+ getCachedValue
36
+ });
37
+ if (result && "OR" === condition) return true;
38
+ if (!result && "AND" == condition) return false;
72
39
  }
73
- }
74
- /**
75
- * If condition is an OR, we can fail the expressions check because the code would return a lot earlier than this line.
76
- *
77
- * 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.
78
- */
79
- return condition === "OR" ? false : true;
40
+ return "OR" !== condition;
80
41
  };
81
- export const filter = params => {
82
- const {
83
- items: records,
84
- where,
85
- plugins,
86
- fields,
87
- fullTextSearch,
88
- container
89
- } = params;
90
- const valueFilterRegistry = container.resolve(ValueFilterRegistry);
91
- const keys = Object.keys(where);
92
- if (keys.length === 0 && !fullTextSearch) {
93
- return records;
94
- }
95
- const expression = createExpressions({
96
- plugins,
97
- where,
98
- fields,
99
- container
100
- });
101
-
102
- /**
103
- * No point in going further if there are no expressions to be applied and no full text search to be executed.
104
- */
105
- if (expression.filters.length === 0 && expression.expressions.length === 0 && !fullTextSearch?.term) {
106
- return records;
107
- }
108
- /**
109
- * We need the contains plugin to run the full text search.
110
- */
111
- const fullTextSearchFilter = valueFilterRegistry.get("contains");
112
- if (!fullTextSearchFilter) {
113
- throw new WebinyError(`Missing "contains" plugin to run the full-text search.`, "MISSING_PLUGIN");
114
- }
115
- const search = createFullTextSearch({
116
- term: fullTextSearch?.term,
117
- targetFields: fullTextSearch?.fields,
118
- fields,
119
- filter: fullTextSearchFilter
120
- });
121
- return records.filter(record => {
122
- const cachedValues = {};
123
- const getCachedValue = filter => {
124
- const {
125
- path
126
- } = filter;
127
- if (cachedValues[path] !== undefined) {
128
- return cachedValues[path];
129
- }
130
- const plainValue = getValue(record, path);
131
- const rawValue = transformValue({
132
- value: plainValue,
133
- transform: filter.transformValue
134
- });
135
- cachedValues[path] = rawValue;
136
- return rawValue;
137
- };
138
- const exprResult = executeExpressions({
139
- ...expression,
140
- getCachedValue
42
+ const filter_filter = (params)=>{
43
+ const { items: records, where, plugins, fields, fullTextSearch, container } = params;
44
+ const valueFilterRegistry = container.resolve(ValueFilterRegistry);
45
+ const keys = Object.keys(where);
46
+ if (0 === keys.length && !fullTextSearch) return records;
47
+ const expression = createExpressions({
48
+ plugins,
49
+ where,
50
+ fields,
51
+ container
52
+ });
53
+ if (0 === expression.filters.length && 0 === expression.expressions.length && !fullTextSearch?.term) return records;
54
+ const fullTextSearchFilter = valueFilterRegistry.get("contains");
55
+ if (!fullTextSearchFilter) throw new error('Missing "contains" plugin to run the full-text search.', "MISSING_PLUGIN");
56
+ const search = createFullTextSearch({
57
+ term: fullTextSearch?.term,
58
+ targetFields: fullTextSearch?.fields,
59
+ fields,
60
+ filter: fullTextSearchFilter
61
+ });
62
+ return records.filter((record)=>{
63
+ const cachedValues = {};
64
+ const getCachedValue = (filter)=>{
65
+ const { path } = filter;
66
+ if (void 0 !== cachedValues[path]) return cachedValues[path];
67
+ const plainValue = getValue(record, path);
68
+ const rawValue = transformValue({
69
+ value: plainValue,
70
+ transform: filter.transformValue
71
+ });
72
+ cachedValues[path] = rawValue;
73
+ return rawValue;
74
+ };
75
+ const exprResult = executeExpressions({
76
+ ...expression,
77
+ getCachedValue
78
+ });
79
+ if (!exprResult || !search) return exprResult;
80
+ return search(record);
141
81
  });
142
- /**
143
- * If expression result is false we do not need to continue further.
144
- * Also, if there is no full text search defined, just return the expression result.
145
- */
146
- if (!exprResult || !search) {
147
- return exprResult;
148
- }
149
- return search(record);
150
- });
151
82
  };
83
+ export { filter_filter as filter };
152
84
 
153
85
  //# sourceMappingURL=filter.js.map