@webiny/api-headless-cms-ddb 0.0.0-unstable.40876133bb → 0.0.0-unstable.496cf268ac

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 (122) hide show
  1. package/definitions/entry.js +3 -5
  2. package/definitions/entry.js.map +1 -1
  3. package/definitions/group.js +0 -5
  4. package/definitions/group.js.map +1 -1
  5. package/definitions/model.js +22 -5
  6. package/definitions/model.js.map +1 -1
  7. package/definitions/settings.js +0 -5
  8. package/definitions/settings.js.map +1 -1
  9. package/definitions/system.js +0 -5
  10. package/definitions/system.js.map +1 -1
  11. package/definitions/table.js +0 -3
  12. package/definitions/table.js.map +1 -1
  13. package/dynamoDb/index.d.ts +1 -1
  14. package/dynamoDb/index.js +0 -7
  15. package/dynamoDb/index.js.map +1 -1
  16. package/dynamoDb/path/plainObject.js +1 -8
  17. package/dynamoDb/path/plainObject.js.map +1 -1
  18. package/dynamoDb/storage/date.d.ts +2 -1
  19. package/dynamoDb/storage/date.js +11 -19
  20. package/dynamoDb/storage/date.js.map +1 -1
  21. package/dynamoDb/storage/longText.d.ts +1 -1
  22. package/dynamoDb/storage/longText.js +7 -17
  23. package/dynamoDb/storage/longText.js.map +1 -1
  24. package/dynamoDb/storage/richText.d.ts +1 -1
  25. package/dynamoDb/storage/richText.js +0 -18
  26. package/dynamoDb/storage/richText.js.map +1 -1
  27. package/dynamoDb/transformValue/datetime.js +1 -8
  28. package/dynamoDb/transformValue/datetime.js.map +1 -1
  29. package/index.js +15 -27
  30. package/index.js.map +1 -1
  31. package/operations/entry/dataLoaders.js +1 -44
  32. package/operations/entry/dataLoaders.js.map +1 -1
  33. package/operations/entry/filtering/createExpressions.d.ts +26 -0
  34. package/operations/entry/filtering/createExpressions.js +176 -0
  35. package/operations/entry/filtering/createExpressions.js.map +1 -0
  36. package/operations/entry/filtering/createFields.d.ts +14 -0
  37. package/operations/entry/filtering/createFields.js +105 -0
  38. package/operations/entry/filtering/createFields.js.map +1 -0
  39. package/operations/entry/filtering/extractSort.d.ts +17 -0
  40. package/operations/entry/filtering/extractSort.js +67 -0
  41. package/operations/entry/filtering/extractSort.js.map +1 -0
  42. package/operations/entry/filtering/filter.d.ts +15 -0
  43. package/operations/entry/filtering/filter.js +143 -0
  44. package/operations/entry/filtering/filter.js.map +1 -0
  45. package/operations/entry/filtering/fullTextSearch.d.ts +14 -0
  46. package/operations/entry/filtering/fullTextSearch.js +48 -0
  47. package/operations/entry/filtering/fullTextSearch.js.map +1 -0
  48. package/operations/entry/filtering/getValue.d.ts +5 -0
  49. package/operations/entry/filtering/getValue.js +63 -0
  50. package/operations/entry/filtering/getValue.js.map +1 -0
  51. package/operations/entry/filtering/index.d.ts +2 -0
  52. package/operations/entry/filtering/index.js +19 -0
  53. package/operations/entry/filtering/index.js.map +1 -0
  54. package/operations/entry/filtering/mapPlugins.d.ts +8 -0
  55. package/operations/entry/filtering/mapPlugins.js +31 -0
  56. package/operations/entry/filtering/mapPlugins.js.map +1 -0
  57. package/operations/entry/filtering/plugins/defaultFilterCreate.d.ts +2 -0
  58. package/operations/entry/filtering/plugins/defaultFilterCreate.js +41 -0
  59. package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -0
  60. package/operations/entry/filtering/plugins/index.d.ts +1 -0
  61. package/operations/entry/filtering/plugins/index.js +13 -0
  62. package/operations/entry/filtering/plugins/index.js.map +1 -0
  63. package/operations/entry/filtering/plugins/objectFilterCreate.d.ts +2 -0
  64. package/operations/entry/filtering/plugins/objectFilterCreate.js +86 -0
  65. package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -0
  66. package/operations/entry/filtering/plugins/refFilterCreate.d.ts +2 -0
  67. package/operations/entry/filtering/plugins/refFilterCreate.js +71 -0
  68. package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -0
  69. package/operations/entry/filtering/sort.d.ts +12 -0
  70. package/operations/entry/filtering/sort.js +69 -0
  71. package/operations/entry/filtering/sort.js.map +1 -0
  72. package/operations/entry/filtering/systemFields.d.ts +4 -0
  73. package/operations/entry/filtering/systemFields.js +70 -0
  74. package/operations/entry/filtering/systemFields.js.map +1 -0
  75. package/operations/entry/filtering/transform.d.ts +6 -0
  76. package/operations/entry/filtering/transform.js +16 -0
  77. package/operations/entry/filtering/transform.js.map +1 -0
  78. package/operations/entry/filtering/types.d.ts +40 -0
  79. package/operations/entry/filtering/types.js +5 -0
  80. package/operations/entry/filtering/types.js.map +1 -0
  81. package/operations/entry/filtering/values.d.ts +2 -0
  82. package/operations/entry/filtering/values.js +22 -0
  83. package/operations/entry/filtering/values.js.map +1 -0
  84. package/operations/entry/filtering/where.d.ts +5 -0
  85. package/operations/entry/filtering/where.js +32 -0
  86. package/operations/entry/filtering/where.js.map +1 -0
  87. package/operations/entry/index.js +37 -107
  88. package/operations/entry/index.js.map +1 -1
  89. package/operations/entry/keys.js +0 -18
  90. package/operations/entry/keys.js.map +1 -1
  91. package/operations/entry/systemFields.js +0 -2
  92. package/operations/entry/systemFields.js.map +1 -1
  93. package/operations/group/index.js +2 -32
  94. package/operations/group/index.js.map +1 -1
  95. package/operations/model/index.js +0 -25
  96. package/operations/model/index.js.map +1 -1
  97. package/operations/settings/index.js +0 -24
  98. package/operations/settings/index.js.map +1 -1
  99. package/operations/system/index.js +0 -17
  100. package/operations/system/index.js.map +1 -1
  101. package/package.json +13 -13
  102. package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +2 -2
  103. package/plugins/CmsEntryFieldFilterPathPlugin.js +0 -14
  104. package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -1
  105. package/plugins/CmsEntryFieldFilterPlugin.d.ts +43 -0
  106. package/plugins/CmsEntryFieldFilterPlugin.js +24 -0
  107. package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -0
  108. package/plugins/CmsEntryFieldSortingPlugin.d.ts +42 -0
  109. package/plugins/CmsEntryFieldSortingPlugin.js +28 -0
  110. package/plugins/CmsEntryFieldSortingPlugin.js.map +1 -0
  111. package/plugins/CmsFieldFilterValueTransformPlugin.d.ts +11 -0
  112. package/plugins/CmsFieldFilterValueTransformPlugin.js +24 -0
  113. package/plugins/CmsFieldFilterValueTransformPlugin.js.map +1 -0
  114. package/plugins/index.d.ts +3 -0
  115. package/plugins/index.js +33 -2
  116. package/plugins/index.js.map +1 -1
  117. package/types.d.ts +1 -1
  118. package/types.js +0 -1
  119. package/types.js.map +1 -1
  120. package/operations/entry/utils.d.ts +0 -36
  121. package/operations/entry/utils.js +0 -680
  122. package/operations/entry/utils.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createFields","params","fields","plugins","transformValuePlugins","getMappedPlugins","type","property","valuePathPlugins","CmsEntryFieldFilterPathPlugin","collection","createSystemFields","reduce","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 { 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 fields: CmsModelField[];\n plugins: PluginsContainer;\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 = createSystemFields().reduce<Record<string, Field>>((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(fields);\n\n return collection;\n};\n"],"mappings":";;;;;;;;AACA;AAIA;AACA;AAMA;AACA;AACA;AACA;AACA;AACO,MAAMA,YAAY,GAAIC,MAAc,IAAK;EAC5C,MAAM;IAAEC,MAAM;IAAEC;EAAQ,CAAC,GAAGF,MAAM;EAElC,MAAMG,qBAAqB,GAAG,IAAAC,4BAAgB,EAAqC;IAC/EF,OAAO;IACPG,IAAI,EAAE,kCAAkC;IACxCC,QAAQ,EAAE;EACd,CAAC,CAAC;EACF,MAAMC,gBAAgB,GAAG,IAA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CAACa;MAC1B,CAAC,CACJ,CACIC,GAAG,CAACC,CAAC,IAAIA,CAAC,CAACb,OAAO,CAAC,CACnBc,IAAI,CAAC,GAAG,CAAC;MAEdnB,UAAU,CAACK,OAAO,CAAC,+DACZF,KAAK;QACRG,OAAO;QACPC,MAAM,EAAE,KAAK;QACbC,UAAU,EAAEjB,MAAM,IAAI;UAClB,IAAIwB,eAAe,EAAE;YACjB,OAAOA,eAAe,CAACP,UAAU,CAACjB,MAAM,CAAC;UAC7C;UAEA,OAAO,CAAC,QAAQ,CAAC,CACZ6B,MAAM,CAACd,OAAO,CAACW,GAAG,CAACI,MAAM,IAAIA,MAAM,CAAChB,OAAO,CAAC,CAAC,CAC7Ce,MAAM,CAAC,CAAC7B,MAAM,CAACY,KAAK,CAACE,OAAO,CAAC,CAAC,CAC9Bc,IAAI,CAAC,GAAG,CAAC;QAClB,CAAC;QACDR,SAAS,EAAEC,KAAK,IAAI;UAChB,IAAI,CAACR,eAAe,EAAE;YAClB,OAAOQ,KAAK;UAChB;UACA,OAAOR,eAAe,CAACO,SAAS,CAAC;YAC7BR,KAAK;YACLS;UACJ,CAAC,CAAC;QACN;MAAC,EACJ;MACD,MAAMU,WAAW,uBAAGnB,KAAK,CAACM,QAAQ,qDAAd,iBAAgBjB,MAAM;MAC1C,IAAI,CAAC8B,WAAW,IAAIA,WAAW,CAACR,MAAM,KAAK,CAAC,EAAE;QAC1C;MACJ;MACAD,qBAAqB,CAACS,WAAW,EAAE,CAC/B,GAAGhB,OAAO,EACV;QACID,OAAO,EAAEF,KAAK,CAACE,OAAO;QACtBW,cAAc,EAAEb,KAAK,CAACa;MAC1B,CAAC,CACJ,CAAC;IACN;EACJ,CAAC;EAEDH,qBAAqB,CAACrB,MAAM,CAAC;EAE7B,OAAOQ,UAAU;AACrB,CAAC;AAAC"}
@@ -0,0 +1,17 @@
1
+ import { Field } from "./types";
2
+ import { PluginsContainer } from "@webiny/plugins";
3
+ import { CmsModel } from "@webiny/api-headless-cms/types";
4
+ interface Result {
5
+ valuePath: string;
6
+ reverse: boolean;
7
+ fieldId: string;
8
+ field: Field;
9
+ }
10
+ interface Params {
11
+ model: CmsModel;
12
+ sortBy: string;
13
+ fields: Record<string, Field>;
14
+ plugins: PluginsContainer;
15
+ }
16
+ export declare const extractSort: (params: Params) => Result;
17
+ export {};
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.extractSort = void 0;
8
+ var _error = _interopRequireDefault(require("@webiny/error"));
9
+ var _plugins = require("../../../plugins");
10
+ const extractSort = params => {
11
+ const {
12
+ model,
13
+ sortBy,
14
+ fields,
15
+ plugins
16
+ } = params;
17
+ const result = sortBy.split("_");
18
+ if (result.length !== 2) {
19
+ throw new _error.default("Problem in determining the sorting for the entry items.", "SORT_EXTRACT_ERROR", {
20
+ sortBy
21
+ });
22
+ }
23
+ const [fieldId, order] = result;
24
+ const field = Object.values(fields).find(field => {
25
+ /**
26
+ * We do not support sorting by nested fields.
27
+ */
28
+ if (field.parents.length > 0) {
29
+ return false;
30
+ }
31
+ return field.fieldId === fieldId;
32
+ });
33
+ const plugin = plugins.byType(_plugins.CmsEntryFieldSortingPlugin.type).reverse().find(plugin => {
34
+ return plugin.canUse({
35
+ model,
36
+ field,
37
+ fieldId,
38
+ order,
39
+ sortBy
40
+ });
41
+ });
42
+ if (plugin) {
43
+ return plugin.createSort({
44
+ model,
45
+ fieldId,
46
+ order,
47
+ sortBy,
48
+ field,
49
+ fields
50
+ });
51
+ } else if (!field) {
52
+ throw new _error.default("Sorting field does not exist in the content model.", "SORTING_FIELD_ERROR", {
53
+ fieldId,
54
+ fields
55
+ });
56
+ }
57
+ const valuePath = field.createPath({
58
+ field
59
+ });
60
+ return {
61
+ field,
62
+ fieldId,
63
+ valuePath,
64
+ reverse: order === "DESC"
65
+ };
66
+ };
67
+ exports.extractSort = extractSort;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["extractSort","params","model","sortBy","fields","plugins","result","split","length","WebinyError","fieldId","order","field","Object","values","find","parents","plugin","byType","CmsEntryFieldSortingPlugin","type","reverse","canUse","createSort","valuePath","createPath"],"sources":["extractSort.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { Field } from \"./types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { CmsEntryFieldSortingPlugin } from \"~/plugins\";\nimport { CmsModel } from \"@webiny/api-headless-cms/types\";\n\ninterface Result {\n valuePath: string;\n reverse: boolean;\n fieldId: string;\n field: Field;\n}\n\ninterface Params {\n model: CmsModel;\n sortBy: string;\n fields: Record<string, Field>;\n plugins: PluginsContainer;\n}\n\nexport const extractSort = (params: Params): Result => {\n const { model, sortBy, fields, plugins } = params;\n const result = sortBy.split(\"_\");\n if (result.length !== 2) {\n throw new WebinyError(\n \"Problem in determining the sorting for the entry items.\",\n \"SORT_EXTRACT_ERROR\",\n {\n sortBy\n }\n );\n }\n const [fieldId, order] = result as [string, \"ASC\" | \"DESC\"];\n\n const field = Object.values(fields).find(field => {\n /**\n * We do not support sorting by nested fields.\n */\n if (field.parents.length > 0) {\n return false;\n }\n return field.fieldId === fieldId;\n });\n\n const plugin = plugins\n .byType<CmsEntryFieldSortingPlugin>(CmsEntryFieldSortingPlugin.type)\n .reverse()\n .find(plugin => {\n return plugin.canUse({\n model,\n field,\n fieldId,\n order,\n sortBy\n });\n });\n\n if (plugin) {\n return plugin.createSort({\n model,\n fieldId,\n order,\n sortBy,\n field,\n fields\n });\n } else if (!field) {\n throw new WebinyError(\n \"Sorting field does not exist in the content model.\",\n \"SORTING_FIELD_ERROR\",\n {\n fieldId,\n fields\n }\n );\n }\n const valuePath = field.createPath({\n field\n });\n return {\n field,\n fieldId,\n valuePath,\n reverse: order === \"DESC\"\n };\n};\n"],"mappings":";;;;;;;AAAA;AAGA;AAiBO,MAAMA,WAAW,GAAIC,MAAc,IAAa;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EACF,OAAO;IACHA,KAAK;IACLF,OAAO;IACPc,SAAS;IACTH,OAAO,EAAEV,KAAK,KAAK;EACvB,CAAC;AACL,CAAC;AAAC"}
@@ -0,0 +1,15 @@
1
+ import { CmsEntry, CmsEntryListWhere } from "@webiny/api-headless-cms/types";
2
+ import { PluginsContainer } from "@webiny/plugins";
3
+ import { Field } from "./types";
4
+ interface Params {
5
+ items: CmsEntry[];
6
+ where: Partial<CmsEntryListWhere>;
7
+ plugins: PluginsContainer;
8
+ fields: Record<string, Field>;
9
+ fullTextSearch?: {
10
+ term?: string;
11
+ fields?: string[];
12
+ };
13
+ }
14
+ export declare const filter: (params: Params) => CmsEntry[];
15
+ export {};
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.filter = void 0;
8
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
+ var _ValueFilterPlugin = require("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin");
10
+ var _error = _interopRequireDefault(require("@webiny/error"));
11
+ var _fullTextSearch = require("./fullTextSearch");
12
+ var _createExpressions = require("./createExpressions");
13
+ var _transform = require("./transform");
14
+ var _getValue = require("./getValue");
15
+ const executeFilter = params => {
16
+ const {
17
+ value,
18
+ filter
19
+ } = params;
20
+ const matched = filter.plugin.matches({
21
+ value,
22
+ compareValue: filter.compareValue
23
+ });
24
+ if (filter.negate) {
25
+ return matched === false;
26
+ }
27
+ return matched;
28
+ };
29
+ const executeExpressions = params => {
30
+ const {
31
+ expressions,
32
+ getCachedValue,
33
+ filters,
34
+ condition
35
+ } = params;
36
+ if (expressions.length === 0 && filters.length === 0) {
37
+ return true;
38
+ }
39
+ /**
40
+ * Always run filters first as they might trigger an early return.
41
+ */
42
+ for (const filter of filters) {
43
+ const value = getCachedValue(filter);
44
+ const result = executeFilter({
45
+ value,
46
+ filter
47
+ });
48
+ /**
49
+ * Filters are ALWAYS executed as an AND.
50
+ * So if even one is false, everything false.
51
+ */
52
+ if (!result) {
53
+ return false;
54
+ }
55
+ }
56
+ /**
57
+ * Then we move onto expressions, which are basically nested upon nested filters with different conditions.
58
+ */
59
+ for (const expression of expressions) {
60
+ const result = executeExpressions((0, _objectSpread2.default)((0, _objectSpread2.default)({}, expression), {}, {
61
+ getCachedValue
62
+ }));
63
+ if (result && condition === "OR") {
64
+ return true;
65
+ } else if (!result && condition == "AND") {
66
+ return false;
67
+ }
68
+ }
69
+ /**
70
+ * If condition is an OR, we can fail the expressions check because the code would return a lot earlier than this line.
71
+ *
72
+ * 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.
73
+ */
74
+ return condition === "OR" ? false : true;
75
+ };
76
+ const filter = params => {
77
+ const {
78
+ items: records,
79
+ where,
80
+ plugins,
81
+ fields,
82
+ fullTextSearch
83
+ } = params;
84
+ const keys = Object.keys(where);
85
+ if (keys.length === 0 && !fullTextSearch) {
86
+ return records;
87
+ }
88
+ const expression = (0, _createExpressions.createExpressions)({
89
+ plugins,
90
+ where,
91
+ fields
92
+ });
93
+
94
+ /**
95
+ * No point in going further if there are no expressions to be applied and no full text search to be executed.
96
+ */
97
+ if (expression.filters.length === 0 && expression.expressions.length === 0 && !(fullTextSearch !== null && fullTextSearch !== void 0 && fullTextSearch.term)) {
98
+ return records;
99
+ }
100
+ /**
101
+ * We need the contains plugin to run the full text search.
102
+ */
103
+ const fullTextSearchPlugin = plugins.byType(_ValueFilterPlugin.ValueFilterPlugin.type).find(plugin => plugin.getOperation() === "contains");
104
+ if (!fullTextSearchPlugin) {
105
+ throw new _error.default(`Missing "contains" plugin to run the full-text search.`, "MISSING_PLUGIN");
106
+ }
107
+ const search = (0, _fullTextSearch.createFullTextSearch)({
108
+ term: fullTextSearch === null || fullTextSearch === void 0 ? void 0 : fullTextSearch.term,
109
+ targetFields: fullTextSearch === null || fullTextSearch === void 0 ? void 0 : fullTextSearch.fields,
110
+ fields,
111
+ plugin: fullTextSearchPlugin
112
+ });
113
+ return records.filter(record => {
114
+ const cachedValues = {};
115
+ const getCachedValue = filter => {
116
+ const {
117
+ path
118
+ } = filter;
119
+ if (cachedValues[path] !== undefined) {
120
+ return cachedValues[path];
121
+ }
122
+ const plainValue = (0, _getValue.getValue)(record, path);
123
+ const rawValue = (0, _transform.transformValue)({
124
+ value: plainValue,
125
+ transform: filter.transformValue
126
+ });
127
+ cachedValues[path] = rawValue;
128
+ return rawValue;
129
+ };
130
+ const exprResult = executeExpressions((0, _objectSpread2.default)((0, _objectSpread2.default)({}, expression), {}, {
131
+ getCachedValue
132
+ }));
133
+ /**
134
+ * If expression result is false we do not need to continue further.
135
+ * Also, if there is no full text search defined, just return the expression result.
136
+ */
137
+ if (!exprResult || !search) {
138
+ return exprResult;
139
+ }
140
+ return search(record);
141
+ });
142
+ };
143
+ exports.filter = filter;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["executeFilter","params","value","filter","matched","plugin","matches","compareValue","negate","executeExpressions","expressions","getCachedValue","filters","condition","length","result","expression","items","records","where","plugins","fields","fullTextSearch","keys","Object","createExpressions","term","fullTextSearchPlugin","byType","ValueFilterPlugin","type","find","getOperation","WebinyError","search","createFullTextSearch","targetFields","record","cachedValues","path","undefined","plainValue","getValue","rawValue","transformValue","transform","exprResult"],"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 } from \"./types\";\nimport { createFullTextSearch } from \"./fullTextSearch\";\nimport { createExpressions, Expression, ExpressionCondition, Filter } from \"./createExpressions\";\nimport { transformValue } from \"./transform\";\nimport { getValue } from \"~/operations/entry/filtering/getValue\";\n\ninterface ExecuteFilterParams {\n value: any;\n filter: Filter;\n}\n\nconst executeFilter = (params: ExecuteFilterParams) => {\n const { value, filter } = params;\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 ExecuteExpressionsParams {\n getCachedValue: (filter: Filter) => Promise<any>;\n expressions: Expression[];\n filters: Filter[];\n condition: ExpressionCondition;\n}\n\nconst executeExpressions = (params: ExecuteExpressionsParams): boolean => {\n const { expressions, getCachedValue, filters, condition } = params;\n if (expressions.length === 0 && filters.length === 0) {\n return true;\n }\n /**\n * Always run filters first as they might trigger an early return.\n */\n for (const filter of filters) {\n const value = getCachedValue(filter);\n\n const result = executeFilter({\n value,\n filter\n });\n /**\n * Filters are ALWAYS executed as an AND.\n * So if even one is false, everything false.\n */\n if (!result) {\n return false;\n }\n }\n /**\n * Then we move onto expressions, which are basically nested upon nested filters with different conditions.\n */\n for (const expression of expressions) {\n const result = executeExpressions({\n ...expression,\n getCachedValue\n });\n if (result && condition === \"OR\") {\n return true;\n } else if (!result && condition == \"AND\") {\n return false;\n }\n }\n /**\n * If condition is an OR, we can fail the expressions check because the code would return a lot earlier than this line.\n *\n * Also, if condition is not an OR, we can say that the expressions check is ok, because it would fail a lot earlier than this line.\n */\n return condition === \"OR\" ? false : true;\n};\n\ninterface Params {\n items: CmsEntry[];\n where: Partial<CmsEntryListWhere>;\n plugins: PluginsContainer;\n fields: Record<string, Field>;\n fullTextSearch?: {\n term?: string;\n fields?: string[];\n };\n}\n\nexport const filter = (params: Params): CmsEntry[] => {\n const { items: records, where, plugins, fields, fullTextSearch } = params;\n\n const keys = Object.keys(where);\n if (keys.length === 0 && !fullTextSearch) {\n return records;\n }\n const expression = createExpressions({\n plugins,\n where,\n fields\n });\n\n /**\n * No point in going further if there are no expressions to be applied and no full text search to be executed.\n */\n if (\n expression.filters.length === 0 &&\n expression.expressions.length === 0 &&\n !fullTextSearch?.term\n ) {\n return records;\n }\n /**\n * We need the contains plugin to run the full text search.\n */\n const 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 plugin: fullTextSearchPlugin\n });\n\n return records.filter(record => {\n const cachedValues: Record<string, any> = {};\n\n const getCachedValue = (filter: Filter) => {\n const { path } = filter;\n if (cachedValues[path] !== undefined) {\n return cachedValues[path];\n }\n const plainValue = getValue(record, path);\n\n const rawValue = transformValue({\n value: plainValue,\n transform: filter.transformValue\n });\n\n cachedValues[path] = rawValue;\n return rawValue;\n };\n\n const exprResult = executeExpressions({ ...expression, getCachedValue });\n /**\n * If expression result is false we do not need to continue further.\n * Also, if there is no full text search defined, just return the expression result.\n */\n if (!exprResult || !search) {\n return exprResult;\n }\n\n return search(record);\n });\n};\n"],"mappings":";;;;;;;;AACA;AACA;AAGA;AACA;AACA;AACA;AAOA,MAAMA,aAAa,GAAIC,MAA2B,IAAK;EACnD,MAAM;IAAEC,KAAK;IAAEC;EAAO,CAAC,GAAGF,MAAM;EAEhC,MAAMG,OAAO,GAAGD,MAAM,CAACE,MAAM,CAACC,OAAO,CAAC;IAClCJ,KAAK;IACLK,YAAY,EAAEJ,MAAM,CAACI;EACzB,CAAC,CAAC;EACF,IAAIJ,MAAM,CAACK,MAAM,EAAE;IACf,OAAOJ,OAAO,KAAK,KAAK;EAC5B;EACA,OAAOA,OAAO;AAClB,CAAC;AASD,MAAMK,kBAAkB,GAAIR,MAAgC,IAAc;EACtE,MAAM;IAAES,WAAW;IAAEC,cAAc;IAAEC,OAAO;IAAEC;EAAU,CAAC,GAAGZ,MAAM;EAClE,IAAIS,WAAW,CAACI,MAAM,KAAK,CAAC,IAAIF,OAAO,CAACE,MAAM,KAAK,CAAC,EAAE;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I,CAACmC,UAAU,IAAI,CAACZ,MAAM,EAAE;MACxB,OAAOY,UAAU;IACrB;IAEA,OAAOZ,MAAM,CAACG,MAAM,CAAC;EACzB,CAAC,CAAC;AACN,CAAC;AAAC"}
@@ -0,0 +1,14 @@
1
+ import { ValueFilterPlugin } from "@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin";
2
+ import { CmsEntry } from "@webiny/api-headless-cms/types";
3
+ import { Field } from "./types";
4
+ interface Params {
5
+ term?: string;
6
+ targetFields?: string[];
7
+ fields: Record<string, Field>;
8
+ plugin: ValueFilterPlugin;
9
+ }
10
+ /**
11
+ * Unfortunately we must use the contains plugin directly as plugins do not support multi field searching.
12
+ */
13
+ export declare const createFullTextSearch: (params: Params) => ((item: CmsEntry) => boolean) | null;
14
+ export {};
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.createFullTextSearch = void 0;
8
+ var _error = _interopRequireDefault(require("@webiny/error"));
9
+ var _getValue = require("./getValue");
10
+ /**
11
+ * Unfortunately we must use the contains plugin directly as plugins do not support multi field searching.
12
+ */
13
+ const createFullTextSearch = params => {
14
+ const {
15
+ term,
16
+ targetFields,
17
+ fields: fieldDefinitions,
18
+ plugin
19
+ } = params;
20
+ if (!term || term.trim().length === 0 || !targetFields || targetFields.length === 0) {
21
+ return null;
22
+ }
23
+ return item => {
24
+ for (const target of targetFields) {
25
+ /**
26
+ * As fields is a mapped Field objects where key is a path to the value, we can directly find the related field.
27
+ */
28
+ const field = fieldDefinitions[target];
29
+ if (!field) {
30
+ throw new _error.default(`Unknown field "${target}" in the model.`, "UNKNOWN_FIELD", {
31
+ target
32
+ });
33
+ }
34
+ const value = (0, _getValue.getValue)(item.values, target);
35
+ if (!value) {
36
+ continue;
37
+ }
38
+ if (plugin.matches({
39
+ value,
40
+ compareValue: term
41
+ }) === true) {
42
+ return true;
43
+ }
44
+ }
45
+ return false;
46
+ };
47
+ };
48
+ exports.createFullTextSearch = createFullTextSearch;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createFullTextSearch","params","term","targetFields","fields","fieldDefinitions","plugin","trim","length","item","target","field","WebinyError","value","getValue","values","matches","compareValue"],"sources":["fullTextSearch.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { ValueFilterPlugin } from \"@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin\";\nimport { CmsEntry } from \"@webiny/api-headless-cms/types\";\nimport { Field } from \"./types\";\nimport { getValue } from \"./getValue\";\n\ninterface Params {\n term?: string;\n targetFields?: string[];\n fields: Record<string, Field>;\n plugin: ValueFilterPlugin;\n}\n\n/**\n * Unfortunately we must use the contains plugin directly as plugins do not support multi field searching.\n */\nexport const createFullTextSearch = (params: Params) => {\n const { term, targetFields, fields: fieldDefinitions, plugin } = params;\n if (!term || term.trim().length === 0 || !targetFields || targetFields.length === 0) {\n return null;\n }\n return (item: CmsEntry) => {\n for (const target of targetFields) {\n /**\n * As fields is a mapped Field objects where key is a path to the value, we can directly find the related field.\n */\n const field = fieldDefinitions[target];\n\n if (!field) {\n throw new WebinyError(`Unknown field \"${target}\" in the model.`, \"UNKNOWN_FIELD\", {\n target\n });\n }\n const value = getValue(item.values, target);\n if (!value) {\n continue;\n }\n if (plugin.matches({ value, compareValue: term }) === true) {\n return true;\n }\n }\n return false;\n };\n};\n"],"mappings":";;;;;;;AAAA;AAIA;AASA;AACA;AACA;AACO,MAAMA,oBAAoB,GAAIC,MAAc,IAAK;EACpD,MAAM;IAAEC,IAAI;IAAEC,YAAY;IAAEC,MAAM,EAAEC,gBAAgB;IAAEC;EAAO,CAAC,GAAGL,MAAM;EACvE,IAAI,CAACC,IAAI,IAAIA,IAAI,CAACK,IAAI,EAAE,CAACC,MAAM,KAAK,CAAC,IAAI,CAACL,YAAY,IAAIA,YAAY,CAACK,MAAM,KAAK,CAAC,EAAE;IACjF,OAAO,IAAI;EACf;EACA,OAAQC,IAAc,IAAK;IACvB,KAAK,MAAMC,MAAM,IAAIP,YAAY,EAAE;MAC/B;AACZ;AACA;MACY,MAAMQ,KAAK,GAAGN,gBAAgB,CAACK,MAAM,CAAC;MAEtC,IAAI,CAACC,KAAK,EAAE;QACR,MAAM,IAAIC,cAAW,CAAE,kBAAiBF,MAAO,iBAAgB,EAAE,eAAe,EAAE;UAC9EA;QACJ,CAAC,CAAC;MACN;MACA,MAAMG,KAAK,GAAG,IAAAC,kBAAQ,EAACL,IAAI,CAACM,MAAM,EAAEL,MAAM,CAAC;MAC3C,IAAI,CAACG,KAAK,EAAE;QACR;MACJ;MACA,IAAIP,MAAM,CAACU,OAAO,CAAC;QAAEH,KAAK;QAAEI,YAAY,EAAEf;MAAK,CAAC,CAAC,KAAK,IAAI,EAAE;QACxD,OAAO,IAAI;MACf;IACJ;IACA,OAAO,KAAK;EAChB,CAAC;AACL,CAAC;AAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * A wrapper function for the find function.
3
+ * Basically it transforms input paths to an array (and runs various checks).
4
+ */
5
+ export declare const getValue: (target: Record<string, any>, input: string | string[]) => any;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getValue = void 0;
7
+ const addArrayResult = (target, result) => {
8
+ for (const r of result) {
9
+ if (target.some(t => r === t)) {
10
+ continue;
11
+ }
12
+ target.push(r);
13
+ }
14
+ };
15
+ /**
16
+ * A recursive function which goes through given input paths and returns the value in it.
17
+ * In case a path is an array, it goes through the array of those values to get values further down the path line.
18
+ */
19
+ const find = (target, input) => {
20
+ const paths = [...input];
21
+ const path = paths.shift();
22
+ if (!path) {
23
+ return undefined;
24
+ } else if (target[path] === undefined) {
25
+ return undefined;
26
+ }
27
+ const value = target[path];
28
+ if (paths.length === 0) {
29
+ return value;
30
+ } else if (Array.isArray(value)) {
31
+ if (value.length === 0) {
32
+ return undefined;
33
+ }
34
+ return value.reduce((collection, v) => {
35
+ const result = find(v, paths);
36
+ if (result === undefined) {
37
+ return collection;
38
+ } else if (Array.isArray(result)) {
39
+ addArrayResult(collection, result);
40
+ return collection;
41
+ }
42
+ collection.push(result);
43
+ return collection;
44
+ }, []);
45
+ }
46
+ return find(value, paths);
47
+ };
48
+ /**
49
+ * A wrapper function for the find function.
50
+ * Basically it transforms input paths to an array (and runs various checks).
51
+ */
52
+ const getValue = (target, input) => {
53
+ const paths = Array.isArray(input) ? input : input.split(".");
54
+ if (paths.length === 0) {
55
+ throw new Error(`Path is empty!`);
56
+ }
57
+ const filtered = paths.filter(Boolean);
58
+ if (paths.length !== filtered.length) {
59
+ throw new Error(`Input path is different than the filtered empty path string. (${paths.join(".")} to ${filtered.join(".")})`);
60
+ }
61
+ return find(target, paths);
62
+ };
63
+ exports.getValue = getValue;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["addArrayResult","target","result","r","some","t","push","find","input","paths","path","shift","undefined","value","length","Array","isArray","reduce","collection","v","getValue","split","Error","filtered","filter","Boolean","join"],"sources":["getValue.ts"],"sourcesContent":["const addArrayResult = (target: any[], result: any[]): void => {\n for (const r of result) {\n if (target.some(t => r === t)) {\n continue;\n }\n target.push(r);\n }\n};\n/**\n * A recursive function which goes through given input paths and returns the value in it.\n * In case a path is an array, it goes through the array of those values to get values further down the path line.\n */\nconst find = (target: Record<string, any>, input: string[]): any[] | undefined => {\n const paths = [...input];\n const path = paths.shift();\n\n if (!path) {\n return undefined;\n } else if (target[path] === undefined) {\n return undefined;\n }\n const value = target[path];\n if (paths.length === 0) {\n return value;\n } else if (Array.isArray(value)) {\n if (value.length === 0) {\n return undefined;\n }\n return value.reduce<any[]>((collection, v) => {\n const result = find(v, paths);\n if (result === undefined) {\n return collection;\n } else if (Array.isArray(result)) {\n addArrayResult(collection, result);\n return collection;\n }\n collection.push(result);\n return collection;\n }, []);\n }\n return find(value, paths);\n};\n/**\n * A wrapper function for the find function.\n * Basically it transforms input paths to an array (and runs various checks).\n */\nexport const getValue = (target: Record<string, any>, input: string | string[]): any => {\n const paths = Array.isArray(input) ? input : input.split(\".\");\n if (paths.length === 0) {\n throw new Error(`Path is empty!`);\n }\n const filtered = paths.filter(Boolean);\n if (paths.length !== filtered.length) {\n throw new Error(\n `Input path is different than the filtered empty path string. (${paths.join(\n \".\"\n )} to ${filtered.join(\".\")})`\n );\n }\n\n return find(target, paths);\n};\n"],"mappings":";;;;;;AAAA,MAAMA,cAAc,GAAG,CAACC,MAAa,EAAEC,MAAa,KAAW;EAC3D,KAAK,MAAMC,CAAC,IAAID,MAAM,EAAE;IACpB,IAAID,MAAM,CAACG,IAAI,CAACC,CAAC,IAAIF,CAAC,KAAKE,CAAC,CAAC,EAAE;MAC3B;IACJ;IACAJ,MAAM,CAACK,IAAI,CAACH,CAAC,CAAC;EAClB;AACJ,CAAC;AACD;AACA;AACA;AACA;AACA,MAAMI,IAAI,GAAG,CAACN,MAA2B,EAAEO,KAAe,KAAwB;EAC9E,MAAMC,KAAK,GAAG,CAAC,GAAGD,KAAK,CAAC;EACxB,MAAME,IAAI,GAAGD,KAAK,CAACE,KAAK,EAAE;EAE1B,IAAI,CAACD,IAAI,EAAE;IACP,OAAOE,SAAS;EACpB,CAAC,MAAM,IAAIX,MAAM,CAACS,IAAI,CAAC,KAAKE,SAAS,EAAE;IACnC,OAAOA,SAAS;EACpB;EACA,MAAMC,KAAK,GAAGZ,MAAM,CAACS,IAAI,CAAC;EAC1B,IAAID,KAAK,CAACK,MAAM,KAAK,CAAC,EAAE;IACpB,OAAOD,KAAK;EAChB,CAAC,MAAM,IAAIE,KAAK,CAACC,OAAO,CAACH,KAAK,CAAC,EAAE;IAC7B,IAAIA,KAAK,CAACC,MAAM,KAAK,CAAC,EAAE;MACpB,OAAOF,SAAS;IACpB;IACA,OAAOC,KAAK,CAACI,MAAM,CAAQ,CAACC,UAAU,EAAEC,CAAC,KAAK;MAC1C,MAAMjB,MAAM,GAAGK,IAAI,CAACY,CAAC,EAAEV,KAAK,CAAC;MAC7B,IAAIP,MAAM,KAAKU,SAAS,EAAE;QACtB,OAAOM,UAAU;MACrB,CAAC,MAAM,IAAIH,KAAK,CAACC,OAAO,CAACd,MAAM,CAAC,EAAE;QAC9BF,cAAc,CAACkB,UAAU,EAAEhB,MAAM,CAAC;QAClC,OAAOgB,UAAU;MACrB;MACAA,UAAU,CAACZ,IAAI,CAACJ,MAAM,CAAC;MACvB,OAAOgB,UAAU;IACrB,CAAC,EAAE,EAAE,CAAC;EACV;EACA,OAAOX,IAAI,CAACM,KAAK,EAAEJ,KAAK,CAAC;AAC7B,CAAC;AACD;AACA;AACA;AACA;AACO,MAAMW,QAAQ,GAAG,CAACnB,MAA2B,EAAEO,KAAwB,KAAU;EACpF,MAAMC,KAAK,GAAGM,KAAK,CAACC,OAAO,CAACR,KAAK,CAAC,GAAGA,KAAK,GAAGA,KAAK,CAACa,KAAK,CAAC,GAAG,CAAC;EAC7D,IAAIZ,KAAK,CAACK,MAAM,KAAK,CAAC,EAAE;IACpB,MAAM,IAAIQ,KAAK,CAAE,gBAAe,CAAC;EACrC;EACA,MAAMC,QAAQ,GAAGd,KAAK,CAACe,MAAM,CAACC,OAAO,CAAC;EACtC,IAAIhB,KAAK,CAACK,MAAM,KAAKS,QAAQ,CAACT,MAAM,EAAE;IAClC,MAAM,IAAIQ,KAAK,CACV,iEAAgEb,KAAK,CAACiB,IAAI,CACvE,GAAG,CACL,OAAMH,QAAQ,CAACG,IAAI,CAAC,GAAG,CAAE,GAAE,CAChC;EACL;EAEA,OAAOnB,IAAI,CAACN,MAAM,EAAEQ,KAAK,CAAC;AAC9B,CAAC;AAAC"}
@@ -0,0 +1,2 @@
1
+ export { filter } from "./filter";
2
+ export { sort } from "./sort";
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "filter", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _filter.filter;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "sort", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _sort.sort;
16
+ }
17
+ });
18
+ var _filter = require("./filter");
19
+ var _sort = require("./sort");
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { filter } from \"./filter\";\nexport { sort } from \"./sort\";\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA;AACA"}
@@ -0,0 +1,8 @@
1
+ import { Plugin, PluginsContainer } from "@webiny/plugins/types";
2
+ interface Params {
3
+ plugins: PluginsContainer;
4
+ type: string;
5
+ property: string;
6
+ }
7
+ export declare const getMappedPlugins: <T extends Plugin<Record<string, any>>>(params: Params) => Record<string, T>;
8
+ export {};
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.getMappedPlugins = void 0;
8
+ var _error = _interopRequireDefault(require("@webiny/error"));
9
+ const getMappedPlugins = params => {
10
+ const {
11
+ plugins: pluginsContainer,
12
+ type,
13
+ property
14
+ } = params;
15
+ const plugins = pluginsContainer.byType(type);
16
+ if (plugins.length === 0) {
17
+ return {};
18
+ }
19
+ return plugins.reduce((collection, plugin) => {
20
+ const key = plugin[property];
21
+ if (typeof key !== "string") {
22
+ throw new _error.default("Property to map the plugins on must be a string.", "PLUGIN_PROPERTY_ERROR", {
23
+ type,
24
+ property
25
+ });
26
+ }
27
+ collection[key] = plugin;
28
+ return collection;
29
+ }, {});
30
+ };
31
+ exports.getMappedPlugins = getMappedPlugins;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["getMappedPlugins","params","plugins","pluginsContainer","type","property","byType","length","reduce","collection","plugin","key","WebinyError"],"sources":["mapPlugins.ts"],"sourcesContent":["import { Plugin, PluginsContainer } from \"@webiny/plugins/types\";\nimport WebinyError from \"@webiny/error\";\n\ninterface Params {\n plugins: PluginsContainer;\n type: string;\n property: string;\n}\nexport const getMappedPlugins = <T extends Plugin>(params: Params) => {\n const { plugins: pluginsContainer, type, property } = params;\n const plugins = pluginsContainer.byType<T>(type);\n if (plugins.length === 0) {\n return {};\n }\n return plugins.reduce<Record<string, T>>((collection, plugin) => {\n const key: keyof typeof plugin = plugin[property];\n if (typeof key !== \"string\") {\n throw new WebinyError(\n \"Property to map the plugins on must be a string.\",\n \"PLUGIN_PROPERTY_ERROR\",\n {\n type,\n property\n }\n );\n }\n collection[key] = plugin;\n return collection;\n }, {});\n};\n"],"mappings":";;;;;;;AACA;AAOO,MAAMA,gBAAgB,GAAsBC,MAAc,IAAK;EAClE,MAAM;IAAEC,OAAO,EAAEC,gBAAgB;IAAEC,IAAI;IAAEC;EAAS,CAAC,GAAGJ,MAAM;EAC5D,MAAMC,OAAO,GAAGC,gBAAgB,CAACG,MAAM,CAAIF,IAAI,CAAC;EAChD,IAAIF,OAAO,CAACK,MAAM,KAAK,CAAC,EAAE;IACtB,OAAO,CAAC,CAAC;EACb;EACA,OAAOL,OAAO,CAACM,MAAM,CAAoB,CAACC,UAAU,EAAEC,MAAM,KAAK;IAC7D,MAAMC,GAAwB,GAAGD,MAAM,CAACL,QAAQ,CAAC;IACjD,IAAI,OAAOM,GAAG,KAAK,QAAQ,EAAE;MACzB,MAAM,IAAIC,cAAW,CACjB,kDAAkD,EAClD,uBAAuB,EACvB;QACIR,IAAI;QACJC;MACJ,CAAC,CACJ;IACL;IACAI,UAAU,CAACE,GAAG,CAAC,GAAGD,MAAM;IACxB,OAAOD,UAAU;EACrB,CAAC,EAAE,CAAC,CAAC,CAAC;AACV,CAAC;AAAC"}
@@ -0,0 +1,2 @@
1
+ import { CmsEntryFieldFilterPlugin } from "../../../../plugins/CmsEntryFieldFilterPlugin";
2
+ export declare const createDefaultFilterCreate: () => CmsEntryFieldFilterPlugin;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.createDefaultFilterCreate = void 0;
8
+ var _error = _interopRequireDefault(require("@webiny/error"));
9
+ var _CmsEntryFieldFilterPlugin = require("../../../../plugins/CmsEntryFieldFilterPlugin");
10
+ const createDefaultFilterCreate = () => {
11
+ return new _CmsEntryFieldFilterPlugin.CmsEntryFieldFilterPlugin({
12
+ fieldType: _CmsEntryFieldFilterPlugin.CmsEntryFieldFilterPlugin.ALL,
13
+ create: params => {
14
+ const {
15
+ negate,
16
+ transformValue,
17
+ field,
18
+ compareValue,
19
+ valueFilterPlugins
20
+ } = params;
21
+ const plugin = valueFilterPlugins[params.operation];
22
+ if (!plugin) {
23
+ throw new _error.default(`Missing ValueFilterPlugin for operation "${params.operation}".`, "MISSING_OPERATION_PLUGIN", {
24
+ operation: params.operation
25
+ });
26
+ }
27
+ return {
28
+ negate,
29
+ transformValue,
30
+ field,
31
+ compareValue,
32
+ fieldPathId: [...field.parents.map(f => f.fieldId), field.fieldId].join("."),
33
+ path: field.createPath({
34
+ field
35
+ }),
36
+ plugin
37
+ };
38
+ }
39
+ });
40
+ };
41
+ exports.createDefaultFilterCreate = createDefaultFilterCreate;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createDefaultFilterCreate","CmsEntryFieldFilterPlugin","fieldType","ALL","create","params","negate","transformValue","field","compareValue","valueFilterPlugins","plugin","operation","WebinyError","fieldPathId","parents","map","f","fieldId","join","path","createPath"],"sources":["defaultFilterCreate.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsEntryFieldFilterPlugin } from \"~/plugins/CmsEntryFieldFilterPlugin\";\n\nexport const createDefaultFilterCreate = () => {\n return new CmsEntryFieldFilterPlugin({\n fieldType: CmsEntryFieldFilterPlugin.ALL,\n create: params => {\n const { negate, transformValue, field, compareValue, valueFilterPlugins } = params;\n const plugin = valueFilterPlugins[params.operation];\n if (!plugin) {\n throw new WebinyError(\n `Missing ValueFilterPlugin for operation \"${params.operation}\".`,\n \"MISSING_OPERATION_PLUGIN\",\n {\n operation: params.operation\n }\n );\n }\n return {\n negate,\n transformValue,\n field,\n compareValue,\n fieldPathId: [...field.parents.map(f => f.fieldId), field.fieldId].join(\".\"),\n path: field.createPath({\n field\n }),\n plugin\n };\n }\n });\n};\n"],"mappings":";;;;;;;AAAA;AACA;AAEO,MAAMA,yBAAyB,GAAG,MAAM;EAC3C,OAAO,IAAIC,oDAAyB,CAAC;IACjCC,SAAS,EAAED,oDAAyB,CAACE,GAAG;IACxCC,MAAM,EAAEC,MAAM,IAAI;MACd,MAAM;QAAEC,MAAM;QAAEC,cAAc;QAAEC,KAAK;QAAEC,YAAY;QAAEC;MAAmB,CAAC,GAAGL,MAAM;MAClF,MAAMM,MAAM,GAAGD,kBAAkB,CAACL,MAAM,CAACO,SAAS,CAAC;MACnD,IAAI,CAACD,MAAM,EAAE;QACT,MAAM,IAAIE,cAAW,CAChB,4CAA2CR,MAAM,CAACO,SAAU,IAAG,EAChE,0BAA0B,EAC1B;UACIA,SAAS,EAAEP,MAAM,CAACO;QACtB,CAAC,CACJ;MACL;MACA,OAAO;QACHN,MAAM;QACNC,cAAc;QACdC,KAAK;QACLC,YAAY;QACZK,WAAW,EAAE,CAAC,GAAGN,KAAK,CAACO,OAAO,CAACC,GAAG,CAACC,CAAC,IAAIA,CAAC,CAACC,OAAO,CAAC,EAAEV,KAAK,CAACU,OAAO,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC;QAC5EC,IAAI,EAAEZ,KAAK,CAACa,UAAU,CAAC;UACnBb;QACJ,CAAC,CAAC;QACFG;MACJ,CAAC;IACL;EACJ,CAAC,CAAC;AACN,CAAC;AAAC"}
@@ -0,0 +1 @@
1
+ export declare const createFilterCreatePlugins: () => import("../../../..").CmsEntryFieldFilterPlugin[];
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createFilterCreatePlugins = void 0;
7
+ var _defaultFilterCreate = require("./defaultFilterCreate");
8
+ var _refFilterCreate = require("./refFilterCreate");
9
+ var _objectFilterCreate = require("./objectFilterCreate");
10
+ const createFilterCreatePlugins = () => {
11
+ return [(0, _defaultFilterCreate.createDefaultFilterCreate)(), (0, _refFilterCreate.createRefFilterCreate)(), (0, _objectFilterCreate.objectFilterCreate)()];
12
+ };
13
+ exports.createFilterCreatePlugins = createFilterCreatePlugins;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createFilterCreatePlugins","createDefaultFilterCreate","createRefFilterCreate","objectFilterCreate"],"sources":["index.ts"],"sourcesContent":["import { createDefaultFilterCreate } from \"./defaultFilterCreate\";\nimport { createRefFilterCreate } from \"./refFilterCreate\";\nimport { objectFilterCreate } from \"./objectFilterCreate\";\n\nexport const createFilterCreatePlugins = () => {\n return [createDefaultFilterCreate(), createRefFilterCreate(), objectFilterCreate()];\n};\n"],"mappings":";;;;;;AAAA;AACA;AACA;AAEO,MAAMA,yBAAyB,GAAG,MAAM;EAC3C,OAAO,CAAC,IAAAC,8CAAyB,GAAE,EAAE,IAAAC,sCAAqB,GAAE,EAAE,IAAAC,sCAAkB,GAAE,CAAC;AACvF,CAAC;AAAC"}
@@ -0,0 +1,2 @@
1
+ import { CmsEntryFieldFilterPlugin } from "../../../../plugins/CmsEntryFieldFilterPlugin";
2
+ export declare const objectFilterCreate: () => CmsEntryFieldFilterPlugin;