@webiny/api-headless-cms-ddb 0.0.0-unstable.615a930a68 → 0.0.0-unstable.61c048f412

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 (177) hide show
  1. package/README.md +6 -20
  2. package/definitions/entry.d.ts +4 -5
  3. package/definitions/entry.js +6 -89
  4. package/definitions/entry.js.map +1 -1
  5. package/definitions/group.d.ts +4 -5
  6. package/definitions/group.js +6 -63
  7. package/definitions/group.js.map +1 -1
  8. package/definitions/model.d.ts +4 -5
  9. package/definitions/model.js +6 -85
  10. package/definitions/model.js.map +1 -1
  11. package/definitions/table.d.ts +4 -6
  12. package/definitions/table.js +7 -28
  13. package/definitions/table.js.map +1 -1
  14. package/definitions/types.d.ts +59 -0
  15. package/definitions/types.js +3 -0
  16. package/definitions/types.js.map +1 -0
  17. package/dynamoDb/index.d.ts +1 -1
  18. package/dynamoDb/index.js +8 -20
  19. package/dynamoDb/index.js.map +1 -1
  20. package/dynamoDb/path/locationFolderId.d.ts +2 -0
  21. package/dynamoDb/path/locationFolderId.js +34 -0
  22. package/dynamoDb/path/locationFolderId.js.map +1 -0
  23. package/dynamoDb/path/plainObject.d.ts +1 -1
  24. package/dynamoDb/path/plainObject.js +6 -20
  25. package/dynamoDb/path/plainObject.js.map +1 -1
  26. package/dynamoDb/storage/longText.d.ts +1 -1
  27. package/dynamoDb/storage/longText.js +19 -34
  28. package/dynamoDb/storage/longText.js.map +1 -1
  29. package/dynamoDb/storage/richText.d.ts +1 -1
  30. package/dynamoDb/storage/richText.js +27 -88
  31. package/dynamoDb/storage/richText.js.map +1 -1
  32. package/dynamoDb/transformValue/datetime.d.ts +1 -1
  33. package/dynamoDb/transformValue/datetime.js +7 -19
  34. package/dynamoDb/transformValue/datetime.js.map +1 -1
  35. package/index.d.ts +2 -2
  36. package/index.js +47 -105
  37. package/index.js.map +1 -1
  38. package/operations/entry/dataLoader/DataLoaderCache.d.ts +15 -0
  39. package/operations/entry/dataLoader/DataLoaderCache.js +34 -0
  40. package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -0
  41. package/operations/entry/dataLoader/constants.d.ts +1 -0
  42. package/operations/entry/dataLoader/constants.js +4 -0
  43. package/operations/entry/dataLoader/constants.js.map +1 -0
  44. package/operations/entry/dataLoader/createBatchScheduleFn.d.ts +8 -0
  45. package/operations/entry/dataLoader/createBatchScheduleFn.js +19 -0
  46. package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -0
  47. package/operations/entry/dataLoader/getAllEntryRevisions.d.ts +4 -0
  48. package/operations/entry/dataLoader/getAllEntryRevisions.js +32 -0
  49. package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -0
  50. package/operations/entry/dataLoader/getLatestRevisionByEntryId.d.ts +4 -0
  51. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +46 -0
  52. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -0
  53. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.d.ts +4 -0
  54. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +46 -0
  55. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -0
  56. package/operations/entry/dataLoader/getRevisionById.d.ts +4 -0
  57. package/operations/entry/dataLoader/getRevisionById.js +52 -0
  58. package/operations/entry/dataLoader/getRevisionById.js.map +1 -0
  59. package/operations/entry/dataLoader/index.d.ts +8 -0
  60. package/operations/entry/dataLoader/index.js +19 -0
  61. package/operations/entry/dataLoader/index.js.map +1 -0
  62. package/operations/entry/dataLoader/types.d.ts +5 -0
  63. package/operations/entry/dataLoader/types.js +3 -0
  64. package/operations/entry/dataLoader/types.js.map +1 -0
  65. package/operations/entry/dataLoaders.d.ts +14 -30
  66. package/operations/entry/dataLoaders.js +56 -271
  67. package/operations/entry/dataLoaders.js.map +1 -1
  68. package/operations/entry/filtering/createExpressions.d.ts +26 -0
  69. package/operations/entry/filtering/createExpressions.js +175 -0
  70. package/operations/entry/filtering/createExpressions.js.map +1 -0
  71. package/operations/entry/filtering/createFields.d.ts +7 -9
  72. package/operations/entry/filtering/createFields.js +87 -105
  73. package/operations/entry/filtering/createFields.js.map +1 -1
  74. package/operations/entry/filtering/extractSort.d.ts +8 -4
  75. package/operations/entry/filtering/extractSort.js +60 -31
  76. package/operations/entry/filtering/extractSort.js.map +1 -1
  77. package/operations/entry/filtering/filter.d.ts +6 -7
  78. package/operations/entry/filtering/filter.js +102 -89
  79. package/operations/entry/filtering/filter.js.map +1 -1
  80. package/operations/entry/filtering/fullTextSearch.d.ts +4 -8
  81. package/operations/entry/filtering/fullTextSearch.js +8 -30
  82. package/operations/entry/filtering/fullTextSearch.js.map +1 -1
  83. package/operations/entry/filtering/getValue.js +5 -27
  84. package/operations/entry/filtering/getValue.js.map +1 -1
  85. package/operations/entry/filtering/index.d.ts +2 -2
  86. package/operations/entry/filtering/index.js +3 -20
  87. package/operations/entry/filtering/index.js.map +1 -1
  88. package/operations/entry/filtering/mapPlugins.d.ts +2 -2
  89. package/operations/entry/filtering/mapPlugins.js +4 -18
  90. package/operations/entry/filtering/mapPlugins.js.map +1 -1
  91. package/operations/entry/filtering/plugins/defaultFilterCreate.d.ts +2 -2
  92. package/operations/entry/filtering/plugins/defaultFilterCreate.js +9 -20
  93. package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -1
  94. package/operations/entry/filtering/plugins/index.d.ts +1 -1
  95. package/operations/entry/filtering/plugins/index.js +7 -16
  96. package/operations/entry/filtering/plugins/index.js.map +1 -1
  97. package/operations/entry/filtering/plugins/objectFilterCreate.d.ts +2 -2
  98. package/operations/entry/filtering/plugins/objectFilterCreate.js +16 -39
  99. package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -1
  100. package/operations/entry/filtering/plugins/refFilterCreate.d.ts +3 -2
  101. package/operations/entry/filtering/plugins/refFilterCreate.js +21 -36
  102. package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -1
  103. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.d.ts +2 -0
  104. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js +57 -0
  105. package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js.map +1 -0
  106. package/operations/entry/filtering/sort.d.ts +8 -5
  107. package/operations/entry/filtering/sort.js +23 -36
  108. package/operations/entry/filtering/sort.js.map +1 -1
  109. package/operations/entry/filtering/systemFields.d.ts +2 -4
  110. package/operations/entry/filtering/systemFields.js +87 -43
  111. package/operations/entry/filtering/systemFields.js.map +1 -1
  112. package/operations/entry/filtering/transform.d.ts +1 -1
  113. package/operations/entry/filtering/transform.js +2 -10
  114. package/operations/entry/filtering/transform.js.map +1 -1
  115. package/operations/entry/filtering/types.d.ts +2 -2
  116. package/operations/entry/filtering/types.js +2 -4
  117. package/operations/entry/filtering/types.js.map +1 -1
  118. package/operations/entry/filtering/values.d.ts +2 -0
  119. package/operations/entry/filtering/values.js +16 -0
  120. package/operations/entry/filtering/values.js.map +1 -0
  121. package/operations/entry/filtering/where.js +5 -15
  122. package/operations/entry/filtering/where.js.map +1 -1
  123. package/operations/entry/index.d.ts +3 -4
  124. package/operations/entry/index.js +751 -414
  125. package/operations/entry/index.js.map +1 -1
  126. package/operations/entry/keys.d.ts +40 -2
  127. package/operations/entry/keys.js +54 -47
  128. package/operations/entry/keys.js.map +1 -1
  129. package/operations/group/index.d.ts +4 -4
  130. package/operations/group/index.js +44 -91
  131. package/operations/group/index.js.map +1 -1
  132. package/operations/model/index.d.ts +3 -3
  133. package/operations/model/index.js +36 -70
  134. package/operations/model/index.js.map +1 -1
  135. package/package.json +22 -29
  136. package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +4 -3
  137. package/plugins/CmsEntryFieldFilterPathPlugin.js +14 -29
  138. package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -1
  139. package/plugins/CmsEntryFieldFilterPlugin.d.ts +10 -10
  140. package/plugins/CmsEntryFieldFilterPlugin.js +9 -19
  141. package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -1
  142. package/plugins/CmsEntryFieldSortingPlugin.d.ts +42 -0
  143. package/plugins/CmsEntryFieldSortingPlugin.js +19 -0
  144. package/plugins/CmsEntryFieldSortingPlugin.js.map +1 -0
  145. package/plugins/CmsFieldFilterValueTransformPlugin.d.ts +11 -0
  146. package/plugins/CmsFieldFilterValueTransformPlugin.js +16 -0
  147. package/plugins/CmsFieldFilterValueTransformPlugin.js.map +1 -0
  148. package/plugins/index.d.ts +4 -1
  149. package/plugins/index.js +5 -17
  150. package/plugins/index.js.map +1 -1
  151. package/types.d.ts +24 -19
  152. package/types.js +5 -13
  153. package/types.js.map +1 -1
  154. package/definitions/settings.d.ts +0 -9
  155. package/definitions/settings.js +0 -58
  156. package/definitions/settings.js.map +0 -1
  157. package/definitions/system.d.ts +0 -9
  158. package/definitions/system.js +0 -46
  159. package/definitions/system.js.map +0 -1
  160. package/dynamoDb/storage/date.d.ts +0 -2
  161. package/dynamoDb/storage/date.js +0 -109
  162. package/dynamoDb/storage/date.js.map +0 -1
  163. package/operations/entry/filtering/createFilters.d.ts +0 -20
  164. package/operations/entry/filtering/createFilters.js +0 -155
  165. package/operations/entry/filtering/createFilters.js.map +0 -1
  166. package/operations/entry/systemFields.d.ts +0 -2
  167. package/operations/entry/systemFields.js +0 -74
  168. package/operations/entry/systemFields.js.map +0 -1
  169. package/operations/entry/utils.d.ts +0 -36
  170. package/operations/entry/utils.js +0 -684
  171. package/operations/entry/utils.js.map +0 -1
  172. package/operations/settings/index.d.ts +0 -7
  173. package/operations/settings/index.js +0 -135
  174. package/operations/settings/index.js.map +0 -1
  175. package/operations/system/index.d.ts +0 -7
  176. package/operations/system/index.js +0 -99
  177. package/operations/system/index.js.map +0 -1
@@ -0,0 +1,175 @@
1
+ import WebinyError from "@webiny/error";
2
+ import { ValueFilterPlugin } from "@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin.js";
3
+ import { getMappedPlugins } from "./mapPlugins.js";
4
+ import { extractWhereParams } from "./where.js";
5
+ import { transformValue } from "./transform.js";
6
+ import { CmsEntryFieldFilterPlugin } from "../../../plugins/CmsEntryFieldFilterPlugin.js";
7
+ import { getWhereValues } from "./values.js";
8
+ import { getBaseFieldType } from "@webiny/api-headless-cms/utils/getBaseFieldType.js";
9
+ export const createExpressions = params => {
10
+ const {
11
+ where,
12
+ plugins,
13
+ fields
14
+ } = params;
15
+ const filterPlugins = getMappedPlugins({
16
+ plugins,
17
+ type: ValueFilterPlugin.type,
18
+ property: "operation"
19
+ });
20
+ const transformValuePlugins = getMappedPlugins({
21
+ plugins,
22
+ type: "cms-field-filter-value-transform",
23
+ property: "fieldType"
24
+ });
25
+ const fieldFilterCreatePlugins = getMappedPlugins({
26
+ plugins,
27
+ type: CmsEntryFieldFilterPlugin.type,
28
+ property: "fieldType"
29
+ });
30
+ const defaultFilterCreatePlugin = fieldFilterCreatePlugins["*"];
31
+ const getFilterCreatePlugin = type => {
32
+ const fieldType = getBaseFieldType({
33
+ type
34
+ });
35
+ const filterCreatePlugin = fieldFilterCreatePlugins[fieldType] || defaultFilterCreatePlugin;
36
+ if (filterCreatePlugin) {
37
+ return filterCreatePlugin;
38
+ }
39
+ throw new WebinyError(`There is no filter create plugin for the field type "${fieldType}".`, "MISSING_FILTER_CREATE_PLUGIN", {
40
+ fieldType
41
+ });
42
+ };
43
+ const createExpression = ({
44
+ where,
45
+ condition
46
+ }) => {
47
+ const expression = {
48
+ filters: [],
49
+ expressions: [],
50
+ condition
51
+ };
52
+ for (const key in where) {
53
+ const value = where[key];
54
+ if (value === undefined) {
55
+ continue;
56
+ }
57
+
58
+ /**
59
+ * If there are "AND" or "OR" keys, let's sort them out first.
60
+ *
61
+ *
62
+ * AND conditional
63
+ */
64
+ if (key === "AND") {
65
+ const childWhereList = getWhereValues(value, key);
66
+ const childExpression = {
67
+ condition: "AND",
68
+ filters: [],
69
+ expressions: []
70
+ };
71
+ for (const childWhere of childWhereList) {
72
+ const result = createExpression({
73
+ where: childWhere,
74
+ condition: "AND"
75
+ });
76
+ childExpression.expressions.push(result);
77
+ }
78
+ expression.expressions.push(childExpression);
79
+ continue;
80
+ }
81
+ /**
82
+ * OR conditional
83
+ */
84
+ if (key === "OR") {
85
+ const childWhereList = getWhereValues(value, key);
86
+ const childExpression = {
87
+ condition: "OR",
88
+ filters: [],
89
+ expressions: []
90
+ };
91
+ for (const childWhere of childWhereList) {
92
+ const result = createExpression({
93
+ where: childWhere,
94
+ condition: "AND"
95
+ });
96
+ childExpression.expressions.push(result);
97
+ }
98
+ expression.expressions.push(childExpression);
99
+ continue;
100
+ }
101
+ const whereParams = extractWhereParams(key);
102
+ if (!whereParams) {
103
+ continue;
104
+ }
105
+ const {
106
+ fieldId,
107
+ operation,
108
+ negate
109
+ } = whereParams;
110
+ const field = fields[fieldId];
111
+ if (!field) {
112
+ throw new WebinyError(`There is no field with the fieldId "${fieldId}".`, "FIELD_ERROR", {
113
+ fieldId
114
+ });
115
+ }
116
+
117
+ /**
118
+ * We need a filter create plugin for this type.
119
+ */
120
+ const filterCreatePlugin = getFilterCreatePlugin(field.type);
121
+ const fieldType = getBaseFieldType(field);
122
+ const transformValuePlugin = transformValuePlugins[fieldType];
123
+ const transformValueCallable = value => {
124
+ if (!transformValuePlugin) {
125
+ return value;
126
+ }
127
+ return transformValuePlugin.transform({
128
+ field,
129
+ value
130
+ });
131
+ };
132
+ const result = filterCreatePlugin.create({
133
+ key,
134
+ value,
135
+ valueFilterPlugins: filterPlugins,
136
+ transformValuePlugins,
137
+ getFilterCreatePlugin,
138
+ operation,
139
+ negate,
140
+ field,
141
+ fields,
142
+ compareValue: transformValue({
143
+ value,
144
+ transform: transformValueCallable
145
+ }),
146
+ transformValue: transformValueCallable
147
+ });
148
+ /**
149
+ * There is a possibility of
150
+ * - no result
151
+ * - result being an array
152
+ * - result being an object
153
+ */
154
+ if (!result || Array.isArray(result) && result.length === 0) {
155
+ continue;
156
+ }
157
+ expression.filters.push(...(Array.isArray(result) ? result : [result]));
158
+ }
159
+ return expression;
160
+ };
161
+ const expression = createExpression({
162
+ where,
163
+ condition: "AND"
164
+ });
165
+ /**
166
+ * If the first expression has no filters and has only one expression, put that expression as main one.
167
+ * This will mostly be used when having an OR condition as the single expression in the root level of the where
168
+ */
169
+ if (expression.filters.length > 0 || expression.expressions.length !== 1) {
170
+ return expression;
171
+ }
172
+ return expression.expressions[0];
173
+ };
174
+
175
+ //# sourceMappingURL=createExpressions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["WebinyError","ValueFilterPlugin","getMappedPlugins","extractWhereParams","transformValue","CmsEntryFieldFilterPlugin","getWhereValues","getBaseFieldType","createExpressions","params","where","plugins","fields","filterPlugins","type","property","transformValuePlugins","fieldFilterCreatePlugins","defaultFilterCreatePlugin","getFilterCreatePlugin","fieldType","filterCreatePlugin","createExpression","condition","expression","filters","expressions","key","value","undefined","childWhereList","childExpression","childWhere","result","push","whereParams","fieldId","operation","negate","field","transformValuePlugin","transformValueCallable","transform","create","valueFilterPlugins","compareValue","Array","isArray","length"],"sources":["createExpressions.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsEntryListWhere } from \"@webiny/api-headless-cms/types/index.js\";\nimport { ValueFilterPlugin } from \"@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin.js\";\nimport type { CmsFieldFilterValueTransformPlugin } from \"~/types.js\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport type { Field } from \"./types.js\";\nimport { getMappedPlugins } from \"./mapPlugins.js\";\nimport { extractWhereParams } from \"./where.js\";\nimport { transformValue } from \"./transform.js\";\nimport { CmsEntryFieldFilterPlugin } from \"~/plugins/CmsEntryFieldFilterPlugin.js\";\nimport { getWhereValues } from \"~/operations/entry/filtering/values.js\";\nimport { getBaseFieldType } from \"@webiny/api-headless-cms/utils/getBaseFieldType.js\";\n\ninterface CreateExpressionParams {\n where: Partial<CmsEntryListWhere>;\n condition: ExpressionCondition;\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 fieldType = getBaseFieldType({\n type\n });\n const filterCreatePlugin = fieldFilterCreatePlugins[fieldType] || defaultFilterCreatePlugin;\n if (filterCreatePlugin) {\n return filterCreatePlugin;\n }\n throw new WebinyError(\n `There is no filter create plugin for the field type \"${fieldType}\".`,\n \"MISSING_FILTER_CREATE_PLUGIN\",\n {\n fieldType\n }\n );\n };\n\n const createExpression = ({ where, condition }: CreateExpressionParams): Expression => {\n const expression: Expression = {\n filters: [],\n expressions: [],\n condition\n };\n\n for (const key in where) {\n const value = where[key as keyof typeof where];\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 fieldType = getBaseFieldType(field);\n\n const transformValuePlugin: CmsFieldFilterValueTransformPlugin =\n transformValuePlugins[fieldType];\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,OAAOA,WAAW,MAAM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AAC,IAAIY,KAAK,CAACC,OAAO,CAACd,MAAM,CAAC,GAAGA,MAAM,GAAG,CAACA,MAAM,CAAC,CAAC,CAAC;IAC3E;IAEA,OAAOT,UAAU;EACrB,CAAC;EAED,MAAMA,UAAU,GAAGF,gBAAgB,CAAC;IAChCZ,KAAK;IACLa,SAAS,EAAE;EACf,CAAC,CAAC;EACF;AACJ;AACA;AACA;EACI,IAAIC,UAAU,CAACC,OAAO,CAACuB,MAAM,GAAG,CAAC,IAAIxB,UAAU,CAACE,WAAW,CAACsB,MAAM,KAAK,CAAC,EAAE;IACtE,OAAOxB,UAAU;EACrB;EACA,OAAOA,UAAU,CAACE,WAAW,CAAC,CAAC,CAAC;AACpC,CAAC","ignoreList":[]}
@@ -1,18 +1,16 @@
1
- import { CmsModel } 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/index.js";
2
+ import type { Field } from "./types.js";
3
+ import type { PluginsContainer } from "@webiny/plugins";
4
4
  interface Params {
5
- model: CmsModel;
5
+ fields: CmsModelField[];
6
6
  plugins: PluginsContainer;
7
7
  }
8
- interface Fields {
9
- [key: string]: Field;
10
- }
11
8
  /**
12
9
  * This method will map the fieldId (fieldId -> field) to the actual field.
13
10
  *
14
11
  * In case of nested fields, fieldId is all the parent fieldIds + current one, joined by the dot (.).
15
- * @param params
16
12
  */
17
- export declare const createFields: (params: Params) => Fields;
13
+ export declare const createFields: (params: Params) => {
14
+ [x: string]: Field;
15
+ };
18
16
  export {};
@@ -1,124 +1,106 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.createFields = void 0;
9
-
10
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
- var _systemFields = require("./systemFields");
13
-
14
- var _plugins = require("../../../plugins");
15
-
16
- var _mapPlugins = require("./mapPlugins");
17
-
18
- /**
19
- * This method will map the fieldId (fieldId -> field) to the actual field.
20
- *
21
- * In case of nested fields, fieldId is all the parent fieldIds + current one, joined by the dot (.).
22
- * @param params
23
- */
24
- const createFields = params => {
1
+ import { createSystemFields } from "./systemFields.js";
2
+ import { CmsEntryFieldFilterPathPlugin } from "../../../plugins/index.js";
3
+ import { getMappedPlugins } from "./mapPlugins.js";
4
+ import { getBaseFieldType } from "@webiny/api-headless-cms/utils/getBaseFieldType.js";
5
+ const createFieldCollection = params => {
25
6
  const {
26
- model,
27
- plugins
7
+ fields,
8
+ parents,
9
+ transformValuePlugins,
10
+ valuePathPlugins,
11
+ system
28
12
  } = params;
29
- const transformValuePlugins = (0, _mapPlugins.getMappedPlugins)({
30
- plugins,
31
- type: "cms-field-filter-value-transform",
32
- property: "fieldType"
33
- });
34
- const valuePathPlugins = (0, _mapPlugins.getMappedPlugins)({
35
- plugins,
36
- type: _plugins.CmsEntryFieldFilterPathPlugin.type,
37
- property: "fieldType"
38
- });
39
- const collection = (0, _systemFields.createSystemFields)().reduce((fields, field) => {
40
- const transformPlugin = transformValuePlugins[field.type];
41
- fields[field.fieldId] = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, field), {}, {
42
- parents: [],
43
- system: true,
44
- createPath: ({
45
- field
46
- }) => {
47
- var _field$settings;
13
+ return fields.reduce((collection, field) => {
14
+ const fieldType = getBaseFieldType(field);
15
+ const transformPlugin = transformValuePlugins[fieldType];
16
+ const valuePathPlugin = valuePathPlugins[fieldType];
48
17
 
49
- return ((_field$settings = field.settings) === null || _field$settings === void 0 ? void 0 : _field$settings.path) || field.fieldId;
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
+ multipleValues: field.multipleValues
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(".");
50
34
  },
51
35
  transform: value => {
52
36
  if (!transformPlugin) {
53
37
  return value;
54
38
  }
55
-
56
39
  return transformPlugin.transform({
57
40
  field,
58
41
  value
59
42
  });
60
43
  }
61
- });
62
- return fields;
63
- }, {});
64
-
65
- const addFieldsToCollection = (fields, parents = []) => {
66
- /**
67
- * Exit early if no fields are sent.
68
- */
69
- if (fields.length === 0) {
70
- return;
44
+ };
45
+ const childFields = field.settings?.fields;
46
+ if (!childFields?.length) {
47
+ return collection;
71
48
  }
72
-
73
- for (const field of fields) {
74
- var _field$settings2;
75
-
76
- const transformPlugin = transformValuePlugins[field.type];
77
- const valuePathPlugin = valuePathPlugins[field.type];
78
- /**
79
- * The required fieldId is a product of all of its parents and its own fieldId.
80
- */
81
-
82
- const fieldId = [...parents, {
83
- fieldId: field.fieldId,
84
- multipleValues: field.multipleValues
85
- }].map(f => f.fieldId).join(".");
86
- collection[fieldId] = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, field), {}, {
87
- parents,
88
- system: false,
89
- createPath: params => {
90
- if (valuePathPlugin) {
91
- return valuePathPlugin.createPath(params);
92
- }
93
-
94
- return ["values"].concat(parents.map(parent => parent.fieldId)).concat([params.field.fieldId]).join(".");
95
- },
96
- transform: value => {
97
- if (!transformPlugin) {
98
- return value;
99
- }
100
-
101
- return transformPlugin.transform({
102
- field,
103
- value
104
- });
105
- }
106
- });
107
- const childFields = (_field$settings2 = field.settings) === null || _field$settings2 === void 0 ? void 0 : _field$settings2.fields;
108
-
109
- if (!childFields || childFields.length === 0) {
110
- continue;
111
- }
112
-
113
- addFieldsToCollection(childFields, [...parents, {
49
+ const result = createFieldCollection({
50
+ fields: childFields,
51
+ parents: [...parents, {
114
52
  fieldId: field.fieldId,
115
53
  multipleValues: field.multipleValues
116
- }]);
117
- }
54
+ }],
55
+ transformValuePlugins,
56
+ valuePathPlugins,
57
+ system
58
+ });
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
+ multipleValues: false
97
+ }],
98
+ system: false
99
+ });
100
+ return {
101
+ ...collection,
102
+ ...result
118
103
  };
119
-
120
- addFieldsToCollection(model.fields);
121
- return collection;
122
104
  };
123
105
 
124
- exports.createFields = createFields;
106
+ //# sourceMappingURL=createFields.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createFields","params","model","plugins","transformValuePlugins","getMappedPlugins","type","property","valuePathPlugins","CmsEntryFieldFilterPathPlugin","collection","createSystemFields","reduce","fields","field","transformPlugin","fieldId","parents","system","createPath","settings","path","transform","value","addFieldsToCollection","length","valuePathPlugin","multipleValues","map","f","join","concat","parent","childFields"],"sources":["createFields.ts"],"sourcesContent":["import { CmsModel, CmsModelField } from \"@webiny/api-headless-cms/types\";\nimport { createSystemFields } from \"./systemFields\";\nimport { Field, FieldParent } from \"./types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { CmsFieldFilterValueTransformPlugin } from \"~/types\";\nimport { CmsEntryFieldFilterPathPlugin } from \"~/plugins\";\nimport { getMappedPlugins } from \"./mapPlugins\";\n\ninterface Params {\n model: CmsModel;\n plugins: PluginsContainer;\n}\n\ninterface Fields {\n [key: string]: Field;\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 * @param params\n */\nexport const createFields = (params: Params) => {\n const { model, 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 = createSystemFields().reduce<Fields>((fields, field) => {\n const transformPlugin = transformValuePlugins[field.type];\n\n fields[field.fieldId] = {\n ...field,\n parents: [],\n system: true,\n createPath: ({ field }) => {\n return field.settings?.path || field.fieldId;\n },\n transform: value => {\n if (!transformPlugin) {\n return value;\n }\n return transformPlugin.transform({\n field,\n value\n });\n }\n };\n\n return fields;\n }, {});\n\n const addFieldsToCollection = (fields: CmsModelField[], parents: FieldParent[] = []): void => {\n /**\n * Exit early if no fields are sent.\n */\n if (fields.length === 0) {\n return;\n }\n for (const field of fields) {\n const transformPlugin = transformValuePlugins[field.type];\n const valuePathPlugin = valuePathPlugins[field.type];\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: false,\n createPath: params => {\n if (valuePathPlugin) {\n return valuePathPlugin.createPath(params);\n }\n\n return [\"values\"]\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 || childFields.length === 0) {\n continue;\n }\n addFieldsToCollection(childFields, [\n ...parents,\n {\n fieldId: field.fieldId,\n multipleValues: field.multipleValues\n }\n ]);\n }\n };\n\n addFieldsToCollection(model.fields);\n\n return collection;\n};\n"],"mappings":";;;;;;;;;;;AACA;;AAIA;;AACA;;AAWA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,YAAY,GAAIC,MAAD,IAAoB;EAC5C,MAAM;IAAEC,KAAF;IAASC;EAAT,IAAqBF,MAA3B;EAEA,MAAMG,qBAAqB,GAAG,IAAAC,4BAAA,EAAqD;IAC/EF,OAD+E;IAE/EG,IAAI,EAAE,kCAFyE;IAG/EC,QAAQ,EAAE;EAHqE,CAArD,CAA9B;EAKA,MAAMC,gBAAgB,GAAG,IAAAH,4BAAA,EAAgD;IACrEF,OADqE;IAErEG,IAAI,EAAEG,sCAAA,CAA8BH,IAFiC;IAGrEC,QAAQ,EAAE;EAH2D,CAAhD,CAAzB;EAMA,MAAMG,UAAU,GAAG,IAAAC,gCAAA,IAAqBC,MAArB,CAAoC,CAACC,MAAD,EAASC,KAAT,KAAmB;IACtE,MAAMC,eAAe,GAAGX,qBAAqB,CAACU,KAAK,CAACR,IAAP,CAA7C;IAEAO,MAAM,CAACC,KAAK,CAACE,OAAP,CAAN,+DACOF,KADP;MAEIG,OAAO,EAAE,EAFb;MAGIC,MAAM,EAAE,IAHZ;MAIIC,UAAU,EAAE,CAAC;QAAEL;MAAF,CAAD,KAAe;QAAA;;QACvB,OAAO,oBAAAA,KAAK,CAACM,QAAN,oEAAgBC,IAAhB,KAAwBP,KAAK,CAACE,OAArC;MACH,CANL;MAOIM,SAAS,EAAEC,KAAK,IAAI;QAChB,IAAI,CAACR,eAAL,EAAsB;UAClB,OAAOQ,KAAP;QACH;;QACD,OAAOR,eAAe,CAACO,SAAhB,CAA0B;UAC7BR,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AC7BR,KAD6B;YAE7BS;UAF6B,CAA1B,CAAP;QAIH;MAtBL;MAwBA,MAAMU,WAAW,uBAAGnB,KAAK,CAACM,QAAT,qDAAG,iBAAgBP,MAApC;;MACA,IAAI,CAACoB,WAAD,IAAgBA,WAAW,CAACR,MAAZ,KAAuB,CAA3C,EAA8C;QAC1C;MACH;;MACDD,qBAAqB,CAACS,WAAD,EAAc,CAC/B,GAAGhB,OAD4B,EAE/B;QACID,OAAO,EAAEF,KAAK,CAACE,OADnB;QAEIW,cAAc,EAAEb,KAAK,CAACa;MAF1B,CAF+B,CAAd,CAArB;IAOH;EACJ,CA3DD;;EA6DAH,qBAAqB,CAACtB,KAAK,CAACW,MAAP,CAArB;EAEA,OAAOH,UAAP;AACH,CAtGM"}
1
+ {"version":3,"names":["createSystemFields","CmsEntryFieldFilterPathPlugin","getMappedPlugins","getBaseFieldType","createFieldCollection","params","fields","parents","transformValuePlugins","valuePathPlugins","system","reduce","collection","field","fieldType","transformPlugin","valuePathPlugin","fieldId","multipleValues","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 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 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 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 {\n fieldId: \"values\",\n multipleValues: 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,gBAAgB;AACzB,SAASC,gBAAgB,QAAQ,oDAAoD;AAmBrF,MAAMC,qBAAqB,GAAIC,MAAmC,IAAsB;EACpF,MAAM;IAAEC,MAAM;IAAEC,OAAO;IAAEC,qBAAqB;IAAEC,gBAAgB;IAAEC;EAAO,CAAC,GAAGL,MAAM;EACnF,OAAOC,MAAM,CAACK,MAAM,CAAkB,CAACC,UAAU,EAAEC,KAAK,KAAK;IACzD,MAAMC,SAAS,GAAGX,gBAAgB,CAACU,KAAK,CAAC;IACzC,MAAME,eAAe,GAAGP,qBAAqB,CAACM,SAAS,CAAC;IACxD,MAAME,eAAe,GAAGP,gBAAgB,CAACK,SAAS,CAAC;;IAEnD;AACR;AACA;IACQ,MAAMG,OAAO,GAAG,CACZ,GAAGV,OAAO,EACV;MACIU,OAAO,EAAEJ,KAAK,CAACI,OAAO;MACtBC,cAAc,EAAEL,KAAK,CAACK;IAC1B,CAAC,CACJ,CACIC,GAAG,CAACC,CAAC,IAAIA,CAAC,CAACH,OAAO,CAAC,CACnBI,IAAI,CAAC,GAAG,CAAC;IAEdT,UAAU,CAACK,OAAO,CAAC,GAAG;MAClB,GAAGJ,KAAK;MACRN,OAAO;MACPG,MAAM;MACNY,UAAU,EAAEjB,MAAM,IAAI;QAClB,IACIW,eAAe,IACfA,eAAe,CAACO,MAAM,CAClBV,KAAK,EACLN,OAAO,CAACY,GAAG,CAACK,CAAC,IAAIA,CAAC,CAACP,OAAO,CAC9B,CAAC,EACH;UACE,OAAOD,eAAe,CAACM,UAAU,CAACjB,MAAM,CAAC;QAC7C;QAEA,OAAOE,OAAO,CACTY,GAA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AAE;EACd,CAAC,CAAC;EAEF,MAAM1B,UAAU,GAAGR,qBAAqB,CAAC;IACrCE,MAAM,EAAEN,kBAAkB,CAAC,CAAC;IAC5BQ,qBAAqB;IACrBC,gBAAgB;IAChBF,OAAO,EAAE,EAAE;IACXG,MAAM,EAAE;EACZ,CAAC,CAAC;EAEF,MAAMsB,MAAM,GAAG5B,qBAAqB,CAAC;IACjCE,MAAM;IACNE,qBAAqB;IACrBC,gBAAgB;IAChBF,OAAO,EAAE,CACL;MACIU,OAAO,EAAE,QAAQ;MACjBC,cAAc,EAAE;IACpB,CAAC,CACJ;IACDR,MAAM,EAAE;EACZ,CAAC,CAAC;EAEF,OAAO;IACH,GAAGE,UAAU;IACb,GAAGoB;EACP,CAAC;AACL,CAAC","ignoreList":[]}
@@ -1,13 +1,17 @@
1
- import { Field } from "./types";
2
- interface Result {
1
+ import type { Field } from "./types.js";
2
+ import type { PluginsContainer } from "@webiny/plugins";
3
+ import type { CmsModel } from "@webiny/api-headless-cms/types/index.js";
4
+ interface IResponse {
3
5
  valuePath: string;
4
6
  reverse: boolean;
5
7
  fieldId: string;
6
8
  field: Field;
7
9
  }
8
- interface Params {
10
+ interface IParams {
11
+ model: CmsModel;
9
12
  sortBy: string;
10
13
  fields: Record<string, Field>;
14
+ plugins: PluginsContainer;
11
15
  }
12
- export declare const extractSort: (params: Params) => Result;
16
+ export declare const extractSort: (params: IParams) => IResponse;
13
17
  export {};
@@ -1,46 +1,75 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.extractSort = void 0;
9
-
10
- var _error = _interopRequireDefault(require("@webiny/error"));
11
-
12
- const extractSort = params => {
1
+ import WebinyError from "@webiny/error";
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]
10
+ };
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]
18
+ };
19
+ }
20
+ throw new WebinyError("Problem in determining the sorting for the entry items.", "SORT_EXTRACT_ERROR", {
21
+ sortBy
22
+ });
23
+ };
24
+ export const extractSort = params => {
13
25
  const {
26
+ model,
14
27
  sortBy,
15
- fields
28
+ fields,
29
+ plugins
16
30
  } = params;
17
- const result = sortBy.split("_");
18
-
19
- if (result.length !== 2) {
20
- throw new _error.default("Problem in determining the sorting for the entry items.", "SORT_EXTRACT_ERROR", {
21
- sortBy
22
- });
23
- }
24
-
25
- const [fieldId, order] = result;
26
- const field = Object.values(fields).find(field => {
31
+ const {
32
+ fieldId,
33
+ isValues: isValuesSorting,
34
+ order
35
+ } = extractSortInfo(sortBy);
36
+ const field = Object.values(fields).find(f => {
27
37
  /**
28
38
  * We do not support sorting by nested fields.
29
39
  */
30
- if (field.parents.length > 0) {
40
+ const isValues = f.parents[0]?.fieldId === "values";
41
+ if (isValues && isValuesSorting) {
42
+ return f.fieldId === fieldId;
43
+ }
44
+ if (f.parents.length > 0) {
31
45
  return false;
32
46
  }
33
-
34
- return field.fieldId === fieldId;
47
+ return f.fieldId === fieldId;
35
48
  });
36
-
37
- if (!field) {
38
- throw new _error.default("Sorting field does not exist in the content model.", "SORTING_FIELD_ERROR", {
49
+ const plugin = plugins.byType(CmsEntryFieldSortingPlugin.type).reverse().find(plugin => {
50
+ return plugin.canUse({
51
+ model,
52
+ field,
53
+ fieldId,
54
+ order,
55
+ sortBy
56
+ });
57
+ });
58
+ if (plugin) {
59
+ return plugin.createSort({
60
+ model,
61
+ fieldId,
62
+ order,
63
+ sortBy,
64
+ field,
65
+ fields
66
+ });
67
+ } else if (!field) {
68
+ throw new WebinyError("Sorting field does not exist in the content model.", "SORTING_FIELD_ERROR", {
39
69
  fieldId,
40
70
  fields
41
71
  });
42
72
  }
43
-
44
73
  const valuePath = field.createPath({
45
74
  field
46
75
  });
@@ -52,4 +81,4 @@ const extractSort = params => {
52
81
  };
53
82
  };
54
83
 
55
- exports.extractSort = extractSort;
84
+ //# sourceMappingURL=extractSort.js.map