@webiny/api-headless-cms-ddb 0.0.0-unstable.611c5af35e → 0.0.0-unstable.615a930a68

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 (107) hide show
  1. package/definitions/entry.js +5 -0
  2. package/definitions/entry.js.map +1 -1
  3. package/definitions/group.js +5 -0
  4. package/definitions/group.js.map +1 -1
  5. package/definitions/model.js +5 -0
  6. package/definitions/model.js.map +1 -1
  7. package/definitions/settings.js +5 -0
  8. package/definitions/settings.js.map +1 -1
  9. package/definitions/system.js +5 -0
  10. package/definitions/system.js.map +1 -1
  11. package/definitions/table.js +3 -0
  12. package/definitions/table.js.map +1 -1
  13. package/dynamoDb/index.js +7 -0
  14. package/dynamoDb/index.js.map +1 -1
  15. package/dynamoDb/path/plainObject.js +8 -1
  16. package/dynamoDb/path/plainObject.js.map +1 -1
  17. package/dynamoDb/storage/date.js +29 -4
  18. package/dynamoDb/storage/date.js.map +1 -1
  19. package/dynamoDb/storage/longText.js +17 -1
  20. package/dynamoDb/storage/longText.js.map +1 -1
  21. package/dynamoDb/storage/richText.js +18 -0
  22. package/dynamoDb/storage/richText.js.map +1 -1
  23. package/dynamoDb/transformValue/datetime.js +8 -1
  24. package/dynamoDb/transformValue/datetime.js.map +1 -1
  25. package/index.js +32 -5
  26. package/index.js.map +1 -1
  27. package/operations/entry/dataLoaders.js +44 -1
  28. package/operations/entry/dataLoaders.js.map +1 -1
  29. package/operations/entry/filtering/createFields.d.ts +18 -0
  30. package/operations/entry/filtering/createFields.js +124 -0
  31. package/operations/entry/filtering/createFields.js.map +1 -0
  32. package/operations/entry/filtering/createFilters.d.ts +20 -0
  33. package/operations/entry/filtering/createFilters.js +155 -0
  34. package/operations/entry/filtering/createFilters.js.map +1 -0
  35. package/operations/entry/filtering/extractSort.d.ts +13 -0
  36. package/operations/entry/filtering/extractSort.js +55 -0
  37. package/operations/entry/filtering/extractSort.js.map +1 -0
  38. package/operations/entry/filtering/filter.d.ts +16 -0
  39. package/operations/entry/filtering/filter.js +137 -0
  40. package/operations/entry/filtering/filter.js.map +1 -0
  41. package/operations/entry/filtering/fullTextSearch.d.ts +18 -0
  42. package/operations/entry/filtering/fullTextSearch.js +64 -0
  43. package/operations/entry/filtering/fullTextSearch.js.map +1 -0
  44. package/operations/entry/filtering/getValue.d.ts +5 -0
  45. package/operations/entry/filtering/getValue.js +81 -0
  46. package/operations/entry/filtering/getValue.js.map +1 -0
  47. package/operations/entry/filtering/index.d.ts +2 -0
  48. package/operations/entry/filtering/index.js +21 -0
  49. package/operations/entry/filtering/index.js.map +1 -0
  50. package/operations/entry/filtering/mapPlugins.d.ts +8 -0
  51. package/operations/entry/filtering/mapPlugins.js +39 -0
  52. package/operations/entry/filtering/mapPlugins.js.map +1 -0
  53. package/operations/entry/filtering/plugins/defaultFilterCreate.d.ts +2 -0
  54. package/operations/entry/filtering/plugins/defaultFilterCreate.js +48 -0
  55. package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -0
  56. package/operations/entry/filtering/plugins/index.d.ts +1 -0
  57. package/operations/entry/filtering/plugins/index.js +18 -0
  58. package/operations/entry/filtering/plugins/index.js.map +1 -0
  59. package/operations/entry/filtering/plugins/objectFilterCreate.d.ts +2 -0
  60. package/operations/entry/filtering/plugins/objectFilterCreate.js +107 -0
  61. package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -0
  62. package/operations/entry/filtering/plugins/refFilterCreate.d.ts +2 -0
  63. package/operations/entry/filtering/plugins/refFilterCreate.js +89 -0
  64. package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -0
  65. package/operations/entry/filtering/sort.d.ts +9 -0
  66. package/operations/entry/filtering/sort.js +80 -0
  67. package/operations/entry/filtering/sort.js.map +1 -0
  68. package/operations/entry/filtering/systemFields.d.ts +4 -0
  69. package/operations/entry/filtering/systemFields.js +72 -0
  70. package/operations/entry/filtering/systemFields.js.map +1 -0
  71. package/operations/entry/filtering/transform.d.ts +6 -0
  72. package/operations/entry/filtering/transform.js +19 -0
  73. package/operations/entry/filtering/transform.js.map +1 -0
  74. package/operations/entry/filtering/types.d.ts +40 -0
  75. package/operations/entry/filtering/types.js +5 -0
  76. package/operations/entry/filtering/types.js.map +1 -0
  77. package/operations/entry/filtering/where.d.ts +5 -0
  78. package/operations/entry/filtering/where.js +38 -0
  79. package/operations/entry/filtering/where.js.map +1 -0
  80. package/operations/entry/index.js +98 -13
  81. package/operations/entry/index.js.map +1 -1
  82. package/operations/entry/keys.js +18 -0
  83. package/operations/entry/keys.js.map +1 -1
  84. package/operations/entry/systemFields.js +2 -0
  85. package/operations/entry/systemFields.js.map +1 -1
  86. package/operations/entry/utils.js +121 -3
  87. package/operations/entry/utils.js.map +1 -1
  88. package/operations/group/index.js +32 -2
  89. package/operations/group/index.js.map +1 -1
  90. package/operations/model/index.js +25 -0
  91. package/operations/model/index.js.map +1 -1
  92. package/operations/settings/index.js +24 -0
  93. package/operations/settings/index.js.map +1 -1
  94. package/operations/system/index.js +17 -0
  95. package/operations/system/index.js.map +1 -1
  96. package/package.json +12 -12
  97. package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +2 -2
  98. package/plugins/CmsEntryFieldFilterPathPlugin.js +14 -0
  99. package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -1
  100. package/plugins/CmsEntryFieldFilterPlugin.d.ts +43 -0
  101. package/plugins/CmsEntryFieldFilterPlugin.js +31 -0
  102. package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -0
  103. package/plugins/index.js +2 -0
  104. package/plugins/index.js.map +1 -1
  105. package/types.d.ts +1 -1
  106. package/types.js +1 -0
  107. package/types.js.map +1 -1
@@ -0,0 +1,18 @@
1
+ import { CmsModel } from "@webiny/api-headless-cms/types";
2
+ import { Field } from "./types";
3
+ import { PluginsContainer } from "@webiny/plugins";
4
+ interface Params {
5
+ model: CmsModel;
6
+ plugins: PluginsContainer;
7
+ }
8
+ interface Fields {
9
+ [key: string]: Field;
10
+ }
11
+ /**
12
+ * This method will map the fieldId (fieldId -> field) to the actual field.
13
+ *
14
+ * In case of nested fields, fieldId is all the parent fieldIds + current one, joined by the dot (.).
15
+ * @param params
16
+ */
17
+ export declare const createFields: (params: Params) => Fields;
18
+ export {};
@@ -0,0 +1,124 @@
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 => {
25
+ const {
26
+ model,
27
+ plugins
28
+ } = 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;
48
+
49
+ return ((_field$settings = field.settings) === null || _field$settings === void 0 ? void 0 : _field$settings.path) || field.fieldId;
50
+ },
51
+ transform: value => {
52
+ if (!transformPlugin) {
53
+ return value;
54
+ }
55
+
56
+ return transformPlugin.transform({
57
+ field,
58
+ value
59
+ });
60
+ }
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;
71
+ }
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, {
114
+ fieldId: field.fieldId,
115
+ multipleValues: field.multipleValues
116
+ }]);
117
+ }
118
+ };
119
+
120
+ addFieldsToCollection(model.fields);
121
+ return collection;
122
+ };
123
+
124
+ exports.createFields = createFields;
@@ -0,0 +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,IAA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FL,EAGFc,IAHE,CAGG,GAHH,CAAP;QAIH,CAbL;QAcIR,SAAS,EAAEC,KAAK,IAAI;UAChB,IAAI,CAACR,eAAL,EAAsB;YAClB,OAAOQ,KAAP;UACH;;UACD,OAAOR,eAAe,CAACO,SAAhB,CAA0B;YAC7BR,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"}
@@ -0,0 +1,20 @@
1
+ import { CmsEntryListWhere } from "@webiny/api-headless-cms/types";
2
+ import { ValueFilterPlugin } from "@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin";
3
+ import { PluginsContainer } from "@webiny/plugins";
4
+ import { Field } from "./types";
5
+ interface CreateFiltersParams {
6
+ plugins: PluginsContainer;
7
+ where: Partial<CmsEntryListWhere>;
8
+ fields: Record<string, Field>;
9
+ }
10
+ export interface ItemFilter {
11
+ field: Field;
12
+ path: string;
13
+ fieldPathId: string;
14
+ plugin: ValueFilterPlugin;
15
+ negate: boolean;
16
+ compareValue: any;
17
+ transformValue: <I = any, O = any>(value: I) => O;
18
+ }
19
+ export declare const createFilters: (params: CreateFiltersParams) => ItemFilter[];
20
+ export {};
@@ -0,0 +1,155 @@
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.createFilters = void 0;
9
+
10
+ var _ValueFilterPlugin = require("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin");
11
+
12
+ var _error = _interopRequireDefault(require("@webiny/error"));
13
+
14
+ var _mapPlugins = require("./mapPlugins");
15
+
16
+ var _where = require("./where");
17
+
18
+ var _transform = require("./transform");
19
+
20
+ var _CmsEntryFieldFilterPlugin = require("../../../plugins/CmsEntryFieldFilterPlugin");
21
+
22
+ const createFilters = params => {
23
+ const {
24
+ where,
25
+ plugins,
26
+ fields
27
+ } = params;
28
+ const filterPlugins = (0, _mapPlugins.getMappedPlugins)({
29
+ plugins,
30
+ type: _ValueFilterPlugin.ValueFilterPlugin.type,
31
+ property: "operation"
32
+ });
33
+ const transformValuePlugins = (0, _mapPlugins.getMappedPlugins)({
34
+ plugins,
35
+ type: "cms-field-filter-value-transform",
36
+ property: "fieldType"
37
+ });
38
+ const fieldFilterCreatePlugins = (0, _mapPlugins.getMappedPlugins)({
39
+ plugins,
40
+ type: _CmsEntryFieldFilterPlugin.CmsEntryFieldFilterPlugin.type,
41
+ property: "fieldType"
42
+ });
43
+ const defaultFilterCreatePlugin = fieldFilterCreatePlugins["*"];
44
+
45
+ const getFilterCreatePlugin = type => {
46
+ const filterCreatePlugin = fieldFilterCreatePlugins[type] || defaultFilterCreatePlugin;
47
+
48
+ if (filterCreatePlugin) {
49
+ return filterCreatePlugin;
50
+ }
51
+
52
+ throw new _error.default(`There is no filter create plugin for the field type "${type}".`, "MISSING_FILTER_CREATE_PLUGIN", {
53
+ type
54
+ });
55
+ };
56
+
57
+ const filters = [];
58
+
59
+ for (const key in where) {
60
+ if (where.hasOwnProperty(key) === false) {
61
+ continue;
62
+ }
63
+ /**
64
+ * At the moment we do not allow "OR" and "AND" conditional filtering, so throw an error on it.
65
+ */
66
+
67
+
68
+ if (key === "AND") {
69
+ throw new _error.default(`Conditional "AND" is currently disabled in the DynamoDB only deployment.`, "DISABLED_AND_CONDITIONAL");
70
+ } else if (key === "OR") {
71
+ throw new _error.default(`Conditional "OR" is currently disabled in the DynamoDB only deployment.`, "DISABLED_OR_CONDITIONAL");
72
+ }
73
+
74
+ const value = where[key];
75
+
76
+ if (value === undefined) {
77
+ continue;
78
+ }
79
+
80
+ const whereParams = (0, _where.extractWhereParams)(key);
81
+
82
+ if (!whereParams) {
83
+ continue;
84
+ }
85
+
86
+ const {
87
+ fieldId,
88
+ operation,
89
+ negate
90
+ } = whereParams;
91
+ const field = fields[fieldId];
92
+
93
+ if (!field) {
94
+ throw new _error.default(`There is no field with the fieldId "${fieldId}".`, "FIELD_ERROR", {
95
+ fieldId
96
+ });
97
+ }
98
+ /**
99
+ * We need a filter create plugin for this type.
100
+ */
101
+
102
+
103
+ const filterCreatePlugin = getFilterCreatePlugin(field.type);
104
+ const transformValuePlugin = transformValuePlugins[field.type];
105
+
106
+ const transformValueCallable = value => {
107
+ if (!transformValuePlugin) {
108
+ return value;
109
+ }
110
+
111
+ return transformValuePlugin.transform({
112
+ field,
113
+ value
114
+ });
115
+ };
116
+
117
+ const result = filterCreatePlugin.create({
118
+ key,
119
+ value,
120
+ valueFilterPlugins: filterPlugins,
121
+ transformValuePlugins,
122
+ getFilterCreatePlugin,
123
+ operation,
124
+ negate,
125
+ field,
126
+ fields,
127
+ compareValue: (0, _transform.transformValue)({
128
+ value,
129
+ transform: transformValueCallable
130
+ }),
131
+ transformValue: transformValueCallable
132
+ });
133
+ /**
134
+ * There is a possibility of
135
+ * - no result
136
+ * - result being an array
137
+ * - result being an object
138
+ */
139
+
140
+ if (!result) {
141
+ continue;
142
+ }
143
+
144
+ if (Array.isArray(result)) {
145
+ filters.push(...result);
146
+ continue;
147
+ }
148
+
149
+ filters.push(result);
150
+ }
151
+
152
+ return filters;
153
+ };
154
+
155
+ exports.createFilters = createFilters;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createFilters","params","where","plugins","fields","filterPlugins","getMappedPlugins","type","ValueFilterPlugin","property","transformValuePlugins","fieldFilterCreatePlugins","CmsEntryFieldFilterPlugin","defaultFilterCreatePlugin","getFilterCreatePlugin","filterCreatePlugin","WebinyError","filters","key","hasOwnProperty","value","undefined","whereParams","extractWhereParams","fieldId","operation","negate","field","transformValuePlugin","transformValueCallable","transform","result","create","valueFilterPlugins","compareValue","transformValue","Array","isArray","push"],"sources":["createFilters.ts"],"sourcesContent":["import { CmsEntryListWhere } from \"@webiny/api-headless-cms/types\";\nimport { ValueFilterPlugin } from \"@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin\";\nimport { CmsFieldFilterValueTransformPlugin } from \"~/types\";\nimport WebinyError from \"@webiny/error\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { Field } from \"./types\";\nimport { getMappedPlugins } from \"./mapPlugins\";\nimport { extractWhereParams } from \"./where\";\nimport { transformValue } from \"./transform\";\nimport { CmsEntryFieldFilterPlugin } from \"~/plugins/CmsEntryFieldFilterPlugin\";\n\ninterface CreateFiltersParams {\n plugins: PluginsContainer;\n where: Partial<CmsEntryListWhere>;\n fields: Record<string, Field>;\n}\n\nexport interface ItemFilter {\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 createFilters = (params: CreateFiltersParams): ItemFilter[] => {\n const { where, plugins, fields } = params;\n const filterPlugins = getMappedPlugins<ValueFilterPlugin>({\n plugins,\n type: ValueFilterPlugin.type,\n property: \"operation\"\n });\n const transformValuePlugins = getMappedPlugins<CmsFieldFilterValueTransformPlugin>({\n plugins,\n type: \"cms-field-filter-value-transform\",\n property: \"fieldType\"\n });\n const fieldFilterCreatePlugins = getMappedPlugins<CmsEntryFieldFilterPlugin>({\n plugins,\n type: CmsEntryFieldFilterPlugin.type,\n property: \"fieldType\"\n });\n\n const defaultFilterCreatePlugin = fieldFilterCreatePlugins[\"*\"] as CmsEntryFieldFilterPlugin;\n\n const getFilterCreatePlugin = (type: string) => {\n const filterCreatePlugin = fieldFilterCreatePlugins[type] || defaultFilterCreatePlugin;\n if (filterCreatePlugin) {\n return filterCreatePlugin;\n }\n throw new WebinyError(\n `There is no filter create plugin for the field type \"${type}\".`,\n \"MISSING_FILTER_CREATE_PLUGIN\",\n {\n type\n }\n );\n };\n\n const filters: ItemFilter[] = [];\n\n for (const key in where) {\n if (where.hasOwnProperty(key) === false) {\n continue;\n }\n /**\n * At the moment we do not allow \"OR\" and \"AND\" conditional filtering, so throw an error on it.\n */\n if (key === \"AND\") {\n throw new WebinyError(\n `Conditional \"AND\" is currently disabled in the DynamoDB only deployment.`,\n \"DISABLED_AND_CONDITIONAL\"\n );\n } else if (key === \"OR\") {\n throw new WebinyError(\n `Conditional \"OR\" is currently disabled in the DynamoDB only deployment.`,\n \"DISABLED_OR_CONDITIONAL\"\n );\n }\n\n const value = (where as any)[key];\n if (value === undefined) {\n continue;\n }\n\n const whereParams = extractWhereParams(key);\n if (!whereParams) {\n continue;\n }\n\n const { fieldId, operation, negate } = whereParams;\n\n const field = fields[fieldId];\n if (!field) {\n throw new WebinyError(\n `There is no field with the fieldId \"${fieldId}\".`,\n \"FIELD_ERROR\",\n {\n fieldId\n }\n );\n }\n\n /**\n * We need a filter create plugin for this type.\n */\n const filterCreatePlugin = getFilterCreatePlugin(field.type);\n\n const transformValuePlugin: CmsFieldFilterValueTransformPlugin =\n transformValuePlugins[field.type];\n\n const transformValueCallable = (value: any) => {\n if (!transformValuePlugin) {\n return value;\n }\n return transformValuePlugin.transform({\n field,\n value\n });\n };\n\n const result = filterCreatePlugin.create({\n key,\n value,\n valueFilterPlugins: filterPlugins,\n transformValuePlugins,\n getFilterCreatePlugin,\n operation,\n negate,\n field,\n fields,\n compareValue: transformValue({\n value,\n transform: transformValueCallable\n }),\n transformValue: transformValueCallable\n });\n /**\n * There is a possibility of\n * - no result\n * - result being an array\n * - result being an object\n */\n if (!result) {\n continue;\n }\n if (Array.isArray(result)) {\n filters.push(...result);\n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AAS,EAAED;MAFc,CAAf,CAVuB;MAcrCM,cAAc,EAAEN;IAdqB,CAA1B,CAAf;IAgBA;AACR;AACA;AACA;AACA;AACA;;IACQ,IAAI,CAACE,MAAL,EAAa;MACT;IACH;;IACD,IAAIK,KAAK,CAACC,OAAN,CAAcN,MAAd,CAAJ,EAA2B;MACvBd,OAAO,CAACqB,IAAR,CAAa,GAAGP,MAAhB;MACA;IACH;;IACDd,OAAO,CAACqB,IAAR,CAAaP,MAAb;EACH;;EAED,OAAOd,OAAP;AACH,CAjIM"}
@@ -0,0 +1,13 @@
1
+ import { Field } from "./types";
2
+ interface Result {
3
+ valuePath: string;
4
+ reverse: boolean;
5
+ fieldId: string;
6
+ field: Field;
7
+ }
8
+ interface Params {
9
+ sortBy: string;
10
+ fields: Record<string, Field>;
11
+ }
12
+ export declare const extractSort: (params: Params) => Result;
13
+ export {};
@@ -0,0 +1,55 @@
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 => {
13
+ const {
14
+ sortBy,
15
+ fields
16
+ } = 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 => {
27
+ /**
28
+ * We do not support sorting by nested fields.
29
+ */
30
+ if (field.parents.length > 0) {
31
+ return false;
32
+ }
33
+
34
+ return field.fieldId === fieldId;
35
+ });
36
+
37
+ if (!field) {
38
+ throw new _error.default("Sorting field does not exist in the content model.", "SORTING_FIELD_ERROR", {
39
+ fieldId,
40
+ fields
41
+ });
42
+ }
43
+
44
+ const valuePath = field.createPath({
45
+ field
46
+ });
47
+ return {
48
+ field,
49
+ fieldId,
50
+ valuePath,
51
+ reverse: order === "DESC"
52
+ };
53
+ };
54
+
55
+ exports.extractSort = extractSort;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["extractSort","params","sortBy","fields","result","split","length","WebinyError","fieldId","order","field","Object","values","find","parents","valuePath","createPath","reverse"],"sources":["extractSort.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { Field } from \"./types\";\n\ninterface Result {\n valuePath: string;\n reverse: boolean;\n fieldId: string;\n field: Field;\n}\n\ninterface Params {\n sortBy: string;\n fields: Record<string, Field>;\n}\n\nexport const extractSort = (params: Params): Result => {\n const { sortBy, fields } = params;\n const result = sortBy.split(\"_\");\n if (result.length !== 2) {\n throw new WebinyError(\n \"Problem in determining the sorting for the entry items.\",\n \"SORT_EXTRACT_ERROR\",\n {\n sortBy\n }\n );\n }\n const [fieldId, order] = result;\n\n const field = Object.values(fields).find(field => {\n /**\n * We do not support sorting by nested fields.\n */\n if (field.parents.length > 0) {\n return false;\n }\n return field.fieldId === fieldId;\n });\n\n 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;;AAeO,MAAMA,WAAW,GAAIC,MAAD,IAA4B;EACnD,MAAM;IAAEC,MAAF;IAAUC;EAAV,IAAqBF,MAA3B;EACA,MAAMG,MAAM,GAAGF,MAAM,CAACG,KAAP,CAAa,GAAb,CAAf;;EACA,IAAID,MAAM,CAACE,MAAP,KAAkB,CAAtB,EAAyB;IACrB,MAAM,IAAIC,cAAJ,CACF,yDADE,EAEF,oBAFE,EAGF;MACIL;IADJ,CAHE,CAAN;EAOH;;EACD,MAAM,CAACM,OAAD,EAAUC,KAAV,IAAmBL,MAAzB;EAEA,MAAMM,KAAK,GAAGC,MAAM,CAACC,MAAP,CAAcT,MAAd,EAAsBU,IAAtB,CAA2BH,KAAK,IAAI;IAC9C;AACR;AACA;IACQ,IAAIA,KAAK,CAACI,OAAN,CAAcR,MAAd,GAAuB,CAA3B,EAA8B;MAC1B,OAAO,KAAP;IACH;;IACD,OAAOI,KAAK,CAACF,OAAN,KAAkBA,OAAzB;EACH,CARa,CAAd;;EAUA,IAAI,CAACE,KAAL,EAAY;IACR,MAAM,IAAIH,cAAJ,CACF,oDADE,EAEF,qBAFE,EAGF;MACIC,OADJ;MAEIL;IAFJ,CAHE,CAAN;EAQH;;EACD,MAAMY,SAAS,GAAGL,KAAK,CAACM,UAAN,CAAiB;IAC/BN;EAD+B,CAAjB,CAAlB;EAGA,OAAO;IACHA,KADG;IAEHF,OAFG;IAGHO,SAHG;IAIHE,OAAO,EAAER,KAAK,KAAK;EAJhB,CAAP;AAMH,CA3CM"}
@@ -0,0 +1,16 @@
1
+ import { CmsEntry, CmsEntryListWhere } from "@webiny/api-headless-cms/types";
2
+ import { PluginsContainer } from "@webiny/plugins";
3
+ import { Field, FilterItemFromStorage } from "./types";
4
+ interface Params {
5
+ items: CmsEntry[];
6
+ where: Partial<CmsEntryListWhere>;
7
+ plugins: PluginsContainer;
8
+ fields: Record<string, Field>;
9
+ fromStorage: FilterItemFromStorage;
10
+ fullTextSearch?: {
11
+ term?: string;
12
+ fields?: string[];
13
+ };
14
+ }
15
+ export declare const filter: (params: Params) => Promise<CmsEntry[]>;
16
+ export {};
@@ -0,0 +1,137 @@
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.filter = void 0;
9
+
10
+ var _ValueFilterPlugin = require("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin");
11
+
12
+ var _error = _interopRequireDefault(require("@webiny/error"));
13
+
14
+ var _fullTextSearch = require("./fullTextSearch");
15
+
16
+ var _createFilters = require("./createFilters");
17
+
18
+ var _transform = require("./transform");
19
+
20
+ var _getValue = require("./getValue");
21
+
22
+ const execFilter = params => {
23
+ const {
24
+ value: plainValue,
25
+ filter
26
+ } = params;
27
+ const value = (0, _transform.transformValue)({
28
+ value: plainValue,
29
+ transform: filter.transformValue
30
+ });
31
+ const matched = filter.plugin.matches({
32
+ value,
33
+ compareValue: filter.compareValue
34
+ });
35
+
36
+ if (filter.negate) {
37
+ return matched === false;
38
+ }
39
+
40
+ return matched;
41
+ };
42
+
43
+ const filter = async params => {
44
+ const {
45
+ items: records,
46
+ where,
47
+ plugins,
48
+ fields,
49
+ fromStorage,
50
+ fullTextSearch
51
+ } = params;
52
+ const keys = Object.keys(where);
53
+
54
+ if (keys.length === 0 && !fullTextSearch) {
55
+ return records;
56
+ }
57
+
58
+ const filters = (0, _createFilters.createFilters)({
59
+ plugins,
60
+ where,
61
+ fields
62
+ });
63
+ /**
64
+ * No point in going further if there are no filters to be applied and no full text search to be executed.
65
+ */
66
+
67
+ if (filters.length === 0 && !fullTextSearch) {
68
+ return records;
69
+ }
70
+ /**
71
+ * We need the contains plugin to run the full text search.
72
+ * TODO check out to maybe implement fuzzy search.
73
+ */
74
+
75
+
76
+ const fullTextSearchPlugin = plugins.byType(_ValueFilterPlugin.ValueFilterPlugin.type).find(plugin => plugin.getOperation() === "contains");
77
+
78
+ if (!fullTextSearchPlugin) {
79
+ throw new _error.default(`Missing "contains" plugin to run the full-text search.`, "MISSING_PLUGIN");
80
+ }
81
+
82
+ const search = (0, _fullTextSearch.createFullTextSearch)({
83
+ term: fullTextSearch === null || fullTextSearch === void 0 ? void 0 : fullTextSearch.term,
84
+ targetFields: fullTextSearch === null || fullTextSearch === void 0 ? void 0 : fullTextSearch.fields,
85
+ fields,
86
+ fromStorage,
87
+ plugin: fullTextSearchPlugin
88
+ });
89
+ const promises = records.map(async record => {
90
+ /**
91
+ * We need to go through all the filters and apply them to the given record.
92
+ */
93
+ for (const filter of filters) {
94
+ const rawValue = (0, _getValue.getValue)(record, filter.path);
95
+ const field = fields[filter.fieldPathId];
96
+ const plainValue = await fromStorage(field, rawValue);
97
+ const result = execFilter({
98
+ value: plainValue,
99
+ filter
100
+ });
101
+
102
+ if (result === false) {
103
+ return null;
104
+ }
105
+ }
106
+ /**
107
+ * If we have full text search defined, run it. Just return the given record if not full text search.
108
+ */
109
+
110
+
111
+ if (!search) {
112
+ return record;
113
+ }
114
+
115
+ const result = await search({
116
+ item: record
117
+ });
118
+
119
+ if (!result) {
120
+ return null;
121
+ }
122
+
123
+ return record;
124
+ });
125
+ /**
126
+ * We run filtering as promises, so it is a bit faster than in for ... of loop.
127
+ */
128
+
129
+ const results = await Promise.all(promises);
130
+ /**
131
+ * And filter out the null values which are returned when filter is not satisfied.
132
+ */
133
+
134
+ return results.filter(Boolean);
135
+ };
136
+
137
+ exports.filter = filter;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["execFilter","params","value","plainValue","filter","transformValue","transform","matched","plugin","matches","compareValue","negate","items","records","where","plugins","fields","fromStorage","fullTextSearch","keys","Object","length","filters","createFilters","fullTextSearchPlugin","byType","ValueFilterPlugin","type","find","getOperation","WebinyError","search","createFullTextSearch","term","targetFields","promises","map","record","rawValue","getValue","path","field","fieldPathId","result","item","results","Promise","all","Boolean"],"sources":["filter.ts"],"sourcesContent":["import { CmsEntry, CmsEntryListWhere } from \"@webiny/api-headless-cms/types\";\nimport { ValueFilterPlugin } from \"@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin\";\nimport WebinyError from \"@webiny/error\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { Field, FilterItemFromStorage } from \"./types\";\nimport { createFullTextSearch } from \"./fullTextSearch\";\nimport { createFilters, ItemFilter } from \"./createFilters\";\nimport { transformValue } from \"./transform\";\nimport { getValue } from \"~/operations/entry/filtering/getValue\";\n\ninterface ExecFilterParams {\n value: any;\n filter: ItemFilter;\n}\nconst execFilter = (params: ExecFilterParams) => {\n const { value: plainValue, filter } = params;\n\n const value = transformValue({\n value: plainValue,\n transform: filter.transformValue\n });\n const matched = filter.plugin.matches({\n value,\n compareValue: filter.compareValue\n });\n if (filter.negate) {\n return matched === false;\n }\n return matched;\n};\n\ninterface Params {\n items: CmsEntry[];\n where: Partial<CmsEntryListWhere>;\n plugins: PluginsContainer;\n fields: Record<string, Field>;\n fromStorage: FilterItemFromStorage;\n fullTextSearch?: {\n term?: string;\n fields?: string[];\n };\n}\n\nexport const filter = async (params: Params): Promise<CmsEntry[]> => {\n const { items: records, where, plugins, fields, fromStorage, fullTextSearch } = params;\n\n const keys = Object.keys(where);\n if (keys.length === 0 && !fullTextSearch) {\n return records;\n }\n const filters = createFilters({\n plugins,\n where,\n fields\n });\n\n /**\n * No point in going further if there are no filters to be applied and no full text search to be executed.\n */\n if (filters.length === 0 && !fullTextSearch) {\n return records;\n }\n /**\n * We need the contains plugin to run the full text search.\n * TODO check out to maybe implement fuzzy search.\n */\n const fullTextSearchPlugin = plugins\n .byType<ValueFilterPlugin>(ValueFilterPlugin.type)\n .find(plugin => plugin.getOperation() === \"contains\");\n if (!fullTextSearchPlugin) {\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 fromStorage,\n plugin: fullTextSearchPlugin\n });\n\n const promises: Promise<CmsEntry | null>[] = records.map(async record => {\n /**\n * We need to go through all the filters and apply them to the given record.\n */\n for (const filter of filters) {\n const rawValue = getValue(record, filter.path);\n\n const field = fields[filter.fieldPathId];\n const plainValue = await fromStorage(field, rawValue);\n\n const result = execFilter({\n value: plainValue,\n filter\n });\n if (result === false) {\n return null;\n }\n }\n /**\n * If we have full text search defined, run it. Just return the given record if not full text search.\n */\n if (!search) {\n return record;\n }\n const result = await search({\n item: record\n });\n if (!result) {\n return null;\n }\n\n return record;\n });\n\n /**\n * We run filtering as promises, so it is a bit faster than in for ... of loop.\n */\n const results: (CmsEntry | null)[] = await Promise.all(promises);\n\n /**\n * And filter out the null values which are returned when filter is not satisfied.\n */\n return results.filter(Boolean) as CmsEntry[];\n};\n"],"mappings":";;;;;;;;;AACA;;AACA;;AAGA;;AACA;;AACA;;AACA;;AAMA,MAAMA,UAAU,GAAIC,MAAD,IAA8B;EAC7C,MAAM;IAAEC,KAAK,EAAEC,UAAT;IAAqBC;EAArB,IAAgCH,MAAtC;EAEA,MAAMC,KAAK,GAAG,IAAAG,yBAAA,EAAe;IACzBH,KAAK,EAAEC,UADkB;IAEzBG,SAAS,EAAEF,MAAM,CAACC;EAFO,CAAf,CAAd;EAIA,MAAME,OAAO,GAAGH,MAAM,CAACI,MAAP,CAAcC,OAAd,CAAsB;IAClCP,KADkC;IAElCQ,YAAY,EAAEN,MAAM,CAACM;EAFa,CAAtB,CAAhB;;EAIA,IAAIN,MAAM,CAACO,MAAX,EAAmB;IACf,OAAOJ,OAAO,KAAK,KAAnB;EACH;;EACD,OAAOA,OAAP;AACH,CAfD;;AA6BO,MAAMH,MAAM,GAAG,MAAOH,MAAP,IAA+C;EACjE,MAAM;IAAEW,KAAK,EAAEC,OAAT;IAAkBC,KAAlB;IAAyBC,OAAzB;IAAkCC,MAAlC;IAA0CC,WAA1C;IAAuDC;EAAvD,IAA0EjB,MAAhF;EAEA,MAAMkB,IAAI,GAAGC,MAAM,CAACD,IAAP,CAAYL,KAAZ,CAAb;;EACA,IAAIK,IAAI,CAACE,MAAL,KAAgB,CAAhB,IAAqB,CAACH,cAA1B,EAA0C;IACtC,OAAOL,OAAP;EACH;;EACD,MAAMS,OAAO,GAAG,IAAAC,4BAAA,EAAc;IAC1BR,OAD0B;IAE1BD,KAF0B;IAG1BE;EAH0B,CAAd,CAAhB;EAMA;AACJ;AACA;;EACI,IAAIM,OAAO,CAACD,MAAR,KAAmB,CAAnB,IAAwB,CAACH,cAA7B,EAA6C;IACzC,OAAOL,OAAP;EACH;EACD;AACJ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,EAAa;MACT,OAAO,IAAP;IACH;;IAED,OAAON,MAAP;EACH,CAhC4C,CAA7C;EAkCA;AACJ;AACA;;EACI,MAAMQ,OAA4B,GAAG,MAAMC,OAAO,CAACC,GAAR,CAAYZ,QAAZ,CAA3C;EAEA;AACJ;AACA;;EACI,OAAOU,OAAO,CAACzC,MAAR,CAAe4C,OAAf,CAAP;AACH,CApFM"}
@@ -0,0 +1,18 @@
1
+ import { ValueFilterPlugin } from "@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin";
2
+ import { CmsEntry } from "@webiny/api-headless-cms/types";
3
+ import { Field, FilterItemFromStorage } from "./types";
4
+ interface Params {
5
+ term?: string;
6
+ targetFields?: string[];
7
+ fromStorage: FilterItemFromStorage;
8
+ fields: Record<string, Field>;
9
+ plugin: ValueFilterPlugin;
10
+ }
11
+ interface FtParams {
12
+ item: CmsEntry;
13
+ }
14
+ /**
15
+ * Unfortunately we must use the contains plugin directly as plugins do not support multi field searching.
16
+ */
17
+ export declare const createFullTextSearch: (params: Params) => (({ item }: FtParams) => Promise<boolean>) | null;
18
+ export {};