@webiny/api-headless-cms-ddb 0.0.0-ee-vpcs.549378cf03

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 (132) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +25 -0
  3. package/definitions/entry.d.ts +9 -0
  4. package/definitions/entry.js +96 -0
  5. package/definitions/entry.js.map +1 -0
  6. package/definitions/group.d.ts +9 -0
  7. package/definitions/group.js +70 -0
  8. package/definitions/group.js.map +1 -0
  9. package/definitions/model.d.ts +9 -0
  10. package/definitions/model.js +97 -0
  11. package/definitions/model.js.map +1 -0
  12. package/definitions/settings.d.ts +9 -0
  13. package/definitions/settings.js +58 -0
  14. package/definitions/settings.js.map +1 -0
  15. package/definitions/system.d.ts +9 -0
  16. package/definitions/system.js +46 -0
  17. package/definitions/system.js.map +1 -0
  18. package/definitions/table.d.ts +9 -0
  19. package/definitions/table.js +30 -0
  20. package/definitions/table.js.map +1 -0
  21. package/dynamoDb/index.d.ts +2 -0
  22. package/dynamoDb/index.js +20 -0
  23. package/dynamoDb/index.js.map +1 -0
  24. package/dynamoDb/path/plainObject.d.ts +2 -0
  25. package/dynamoDb/path/plainObject.js +40 -0
  26. package/dynamoDb/path/plainObject.js.map +1 -0
  27. package/dynamoDb/storage/date.d.ts +3 -0
  28. package/dynamoDb/storage/date.js +109 -0
  29. package/dynamoDb/storage/date.js.map +1 -0
  30. package/dynamoDb/storage/longText.d.ts +10 -0
  31. package/dynamoDb/storage/longText.js +108 -0
  32. package/dynamoDb/storage/longText.js.map +1 -0
  33. package/dynamoDb/storage/richText.d.ts +2 -0
  34. package/dynamoDb/storage/richText.js +113 -0
  35. package/dynamoDb/storage/richText.js.map +1 -0
  36. package/dynamoDb/transformValue/datetime.d.ts +5 -0
  37. package/dynamoDb/transformValue/datetime.js +52 -0
  38. package/dynamoDb/transformValue/datetime.js.map +1 -0
  39. package/index.d.ts +3 -0
  40. package/index.js +150 -0
  41. package/index.js.map +1 -0
  42. package/operations/entry/dataLoaders.d.ts +42 -0
  43. package/operations/entry/dataLoaders.js +321 -0
  44. package/operations/entry/dataLoaders.js.map +1 -0
  45. package/operations/entry/filtering/createExpressions.d.ts +26 -0
  46. package/operations/entry/filtering/createExpressions.js +217 -0
  47. package/operations/entry/filtering/createExpressions.js.map +1 -0
  48. package/operations/entry/filtering/createFields.d.ts +14 -0
  49. package/operations/entry/filtering/createFields.js +123 -0
  50. package/operations/entry/filtering/createFields.js.map +1 -0
  51. package/operations/entry/filtering/extractSort.d.ts +13 -0
  52. package/operations/entry/filtering/extractSort.js +55 -0
  53. package/operations/entry/filtering/extractSort.js.map +1 -0
  54. package/operations/entry/filtering/filter.d.ts +15 -0
  55. package/operations/entry/filtering/filter.js +178 -0
  56. package/operations/entry/filtering/filter.js.map +1 -0
  57. package/operations/entry/filtering/fullTextSearch.d.ts +14 -0
  58. package/operations/entry/filtering/fullTextSearch.js +60 -0
  59. package/operations/entry/filtering/fullTextSearch.js.map +1 -0
  60. package/operations/entry/filtering/getValue.d.ts +5 -0
  61. package/operations/entry/filtering/getValue.js +81 -0
  62. package/operations/entry/filtering/getValue.js.map +1 -0
  63. package/operations/entry/filtering/index.d.ts +2 -0
  64. package/operations/entry/filtering/index.js +21 -0
  65. package/operations/entry/filtering/index.js.map +1 -0
  66. package/operations/entry/filtering/mapPlugins.d.ts +8 -0
  67. package/operations/entry/filtering/mapPlugins.js +39 -0
  68. package/operations/entry/filtering/mapPlugins.js.map +1 -0
  69. package/operations/entry/filtering/plugins/defaultFilterCreate.d.ts +2 -0
  70. package/operations/entry/filtering/plugins/defaultFilterCreate.js +48 -0
  71. package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -0
  72. package/operations/entry/filtering/plugins/index.d.ts +1 -0
  73. package/operations/entry/filtering/plugins/index.js +18 -0
  74. package/operations/entry/filtering/plugins/index.js.map +1 -0
  75. package/operations/entry/filtering/plugins/objectFilterCreate.d.ts +2 -0
  76. package/operations/entry/filtering/plugins/objectFilterCreate.js +107 -0
  77. package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -0
  78. package/operations/entry/filtering/plugins/refFilterCreate.d.ts +2 -0
  79. package/operations/entry/filtering/plugins/refFilterCreate.js +89 -0
  80. package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -0
  81. package/operations/entry/filtering/sort.d.ts +9 -0
  82. package/operations/entry/filtering/sort.js +80 -0
  83. package/operations/entry/filtering/sort.js.map +1 -0
  84. package/operations/entry/filtering/systemFields.d.ts +4 -0
  85. package/operations/entry/filtering/systemFields.js +72 -0
  86. package/operations/entry/filtering/systemFields.js.map +1 -0
  87. package/operations/entry/filtering/transform.d.ts +6 -0
  88. package/operations/entry/filtering/transform.js +19 -0
  89. package/operations/entry/filtering/transform.js.map +1 -0
  90. package/operations/entry/filtering/types.d.ts +40 -0
  91. package/operations/entry/filtering/types.js +5 -0
  92. package/operations/entry/filtering/types.js.map +1 -0
  93. package/operations/entry/filtering/values.d.ts +2 -0
  94. package/operations/entry/filtering/values.js +28 -0
  95. package/operations/entry/filtering/values.js.map +1 -0
  96. package/operations/entry/filtering/where.d.ts +5 -0
  97. package/operations/entry/filtering/where.js +38 -0
  98. package/operations/entry/filtering/where.js.map +1 -0
  99. package/operations/entry/index.d.ts +8 -0
  100. package/operations/entry/index.js +872 -0
  101. package/operations/entry/index.js.map +1 -0
  102. package/operations/entry/keys.d.ts +25 -0
  103. package/operations/entry/keys.js +73 -0
  104. package/operations/entry/keys.js.map +1 -0
  105. package/operations/entry/systemFields.d.ts +2 -0
  106. package/operations/entry/systemFields.js +74 -0
  107. package/operations/entry/systemFields.js.map +1 -0
  108. package/operations/group/index.d.ts +9 -0
  109. package/operations/group/index.js +192 -0
  110. package/operations/group/index.js.map +1 -0
  111. package/operations/model/index.d.ts +7 -0
  112. package/operations/model/index.js +162 -0
  113. package/operations/model/index.js.map +1 -0
  114. package/operations/settings/index.d.ts +7 -0
  115. package/operations/settings/index.js +135 -0
  116. package/operations/settings/index.js.map +1 -0
  117. package/operations/system/index.d.ts +7 -0
  118. package/operations/system/index.js +99 -0
  119. package/operations/system/index.js.map +1 -0
  120. package/package.json +60 -0
  121. package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +22 -0
  122. package/plugins/CmsEntryFieldFilterPathPlugin.js +55 -0
  123. package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -0
  124. package/plugins/CmsEntryFieldFilterPlugin.d.ts +43 -0
  125. package/plugins/CmsEntryFieldFilterPlugin.js +31 -0
  126. package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -0
  127. package/plugins/index.d.ts +1 -0
  128. package/plugins/index.js +18 -0
  129. package/plugins/index.js.map +1 -0
  130. package/types.d.ts +53 -0
  131. package/types.js +16 -0
  132. package/types.js.map +1 -0
@@ -0,0 +1,162 @@
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.createModelsStorageOperations = void 0;
9
+
10
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
+
12
+ var _error = _interopRequireDefault(require("@webiny/error"));
13
+
14
+ var _get = require("@webiny/db-dynamodb/utils/get");
15
+
16
+ var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
17
+
18
+ var _query = require("@webiny/db-dynamodb/utils/query");
19
+
20
+ const createPartitionKey = params => {
21
+ const {
22
+ tenant,
23
+ locale
24
+ } = params;
25
+
26
+ if (!tenant) {
27
+ throw new _error.default(`Missing tenant variable when creating model partitionKey.`);
28
+ } else if (!locale) {
29
+ throw new _error.default(`Missing locale variable when creating model partitionKey.`);
30
+ }
31
+
32
+ return `T#${tenant}#L#${locale}#CMS#CM`;
33
+ };
34
+
35
+ const createSortKey = params => {
36
+ return params.modelId;
37
+ };
38
+
39
+ const createKeys = params => {
40
+ return {
41
+ PK: createPartitionKey(params),
42
+ SK: createSortKey(params)
43
+ };
44
+ };
45
+
46
+ const createType = () => {
47
+ return "cms.model";
48
+ };
49
+
50
+ const createModelsStorageOperations = params => {
51
+ const {
52
+ entity
53
+ } = params;
54
+
55
+ const create = async params => {
56
+ const {
57
+ model
58
+ } = params;
59
+ const keys = createKeys(model);
60
+
61
+ try {
62
+ await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, (0, _cleanup.cleanupItem)(entity, model)), keys), {}, {
63
+ TYPE: createType()
64
+ }));
65
+ return model;
66
+ } catch (ex) {
67
+ throw new _error.default(`Could not create CMS Content Model.`, "CREATE_MODEL_ERROR", {
68
+ error: ex,
69
+ model,
70
+ keys
71
+ });
72
+ }
73
+ };
74
+
75
+ const update = async params => {
76
+ const {
77
+ model
78
+ } = params;
79
+ const keys = createKeys(model);
80
+
81
+ try {
82
+ await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, (0, _cleanup.cleanupItem)(entity, model)), keys), {}, {
83
+ TYPE: createType()
84
+ }));
85
+ return model;
86
+ } catch (ex) {
87
+ throw new _error.default(ex.message || "Could not update model.", ex.code || "MODEL_UPDATE_ERROR", {
88
+ error: ex,
89
+ model,
90
+ keys
91
+ });
92
+ }
93
+ };
94
+
95
+ const deleteModel = async params => {
96
+ const {
97
+ model
98
+ } = params;
99
+ const keys = createKeys(model);
100
+
101
+ try {
102
+ await entity.delete(keys);
103
+ return model;
104
+ } catch (ex) {
105
+ throw new _error.default(ex.message || "Could not delete model.", ex.code || "MODEL_DELETE_ERROR", {
106
+ error: ex,
107
+ model,
108
+ keys
109
+ });
110
+ }
111
+ };
112
+
113
+ const get = async params => {
114
+ const keys = createKeys(params);
115
+
116
+ try {
117
+ const item = await (0, _get.get)({
118
+ entity,
119
+ keys
120
+ });
121
+ return (0, _cleanup.cleanupItem)(entity, item);
122
+ } catch (ex) {
123
+ throw new _error.default(ex.message || "Could not get model.", ex.code || "MODEL_GET_ERROR", {
124
+ error: ex,
125
+ keys
126
+ });
127
+ }
128
+ };
129
+
130
+ const list = async params => {
131
+ const {
132
+ where
133
+ } = params;
134
+ const queryAllParams = {
135
+ entity,
136
+ partitionKey: createPartitionKey(where),
137
+ options: {
138
+ gte: " "
139
+ }
140
+ };
141
+
142
+ try {
143
+ const items = await (0, _query.queryAll)(queryAllParams);
144
+ return (0, _cleanup.cleanupItems)(entity, items);
145
+ } catch (ex) {
146
+ throw new _error.default(ex.message || "Could not list models.", ex.code || "MODEL_LIST_ERROR", {
147
+ error: ex,
148
+ partitionKey: queryAllParams.partitionKey
149
+ });
150
+ }
151
+ };
152
+
153
+ return {
154
+ create,
155
+ update,
156
+ delete: deleteModel,
157
+ get,
158
+ list
159
+ };
160
+ };
161
+
162
+ exports.createModelsStorageOperations = createModelsStorageOperations;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createPartitionKey","params","tenant","locale","WebinyError","createSortKey","modelId","createKeys","PK","SK","createType","createModelsStorageOperations","entity","create","model","keys","put","cleanupItem","TYPE","ex","error","update","message","code","deleteModel","delete","get","item","getRecord","list","where","queryAllParams","partitionKey","options","gte","items","queryAll","cleanupItems"],"sources":["index.ts"],"sourcesContent":["import {\n CmsModel,\n CmsModelStorageOperations,\n CmsModelStorageOperationsCreateParams,\n CmsModelStorageOperationsDeleteParams,\n CmsModelStorageOperationsGetParams,\n CmsModelStorageOperationsListParams,\n CmsModelStorageOperationsUpdateParams\n} from \"@webiny/api-headless-cms/types\";\nimport { Entity } from \"dynamodb-toolbox\";\nimport WebinyError from \"@webiny/error\";\nimport { get as getRecord } from \"@webiny/db-dynamodb/utils/get\";\nimport { cleanupItem, cleanupItems } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { queryAll, QueryAllParams } from \"@webiny/db-dynamodb/utils/query\";\n\ninterface PartitionKeysParams {\n tenant: string;\n locale: string;\n}\nconst createPartitionKey = (params: PartitionKeysParams): string => {\n const { tenant, locale } = params;\n if (!tenant) {\n throw new WebinyError(`Missing tenant variable when creating model partitionKey.`);\n } else if (!locale) {\n throw new WebinyError(`Missing locale variable when creating model partitionKey.`);\n }\n return `T#${tenant}#L#${locale}#CMS#CM`;\n};\n\ninterface SortKeyParams {\n modelId: string;\n}\nconst createSortKey = (params: SortKeyParams): string => {\n return params.modelId;\n};\n\ninterface Keys {\n PK: string;\n SK: string;\n}\nconst createKeys = (params: PartitionKeysParams & SortKeyParams): Keys => {\n return {\n PK: createPartitionKey(params),\n SK: createSortKey(params)\n };\n};\n\nconst createType = (): string => {\n return \"cms.model\";\n};\n\ninterface CreateModelsStorageOperationsParams {\n entity: Entity<any>;\n}\nexport const createModelsStorageOperations = (\n params: CreateModelsStorageOperationsParams\n): CmsModelStorageOperations => {\n const { entity } = params;\n\n const create = async (params: CmsModelStorageOperationsCreateParams) => {\n const { model } = params;\n\n const keys = createKeys(model);\n\n try {\n await entity.put({\n ...cleanupItem(entity, model),\n ...keys,\n TYPE: createType()\n });\n return model;\n } catch (ex) {\n throw new WebinyError(`Could not create CMS Content Model.`, \"CREATE_MODEL_ERROR\", {\n error: ex,\n model,\n keys\n });\n }\n };\n\n const update = async (params: CmsModelStorageOperationsUpdateParams) => {\n const { model } = params;\n\n const keys = createKeys(model);\n\n try {\n await entity.put({\n ...cleanupItem(entity, model),\n ...keys,\n TYPE: createType()\n });\n return model;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update model.\",\n ex.code || \"MODEL_UPDATE_ERROR\",\n {\n error: ex,\n model,\n keys\n }\n );\n }\n };\n\n const deleteModel = async (params: CmsModelStorageOperationsDeleteParams) => {\n const { model } = params;\n const keys = createKeys(model);\n\n try {\n await entity.delete(keys);\n return model;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete model.\",\n ex.code || \"MODEL_DELETE_ERROR\",\n {\n error: ex,\n model,\n keys\n }\n );\n }\n };\n\n const get = async (params: CmsModelStorageOperationsGetParams) => {\n const keys = createKeys(params);\n\n try {\n const item = await getRecord<CmsModel>({\n entity,\n keys\n });\n return cleanupItem(entity, item);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not get model.\",\n ex.code || \"MODEL_GET_ERROR\",\n {\n error: ex,\n keys\n }\n );\n }\n };\n\n const list = async (params: CmsModelStorageOperationsListParams) => {\n const { where } = params;\n const queryAllParams: QueryAllParams = {\n entity,\n partitionKey: createPartitionKey(where),\n options: {\n gte: \" \"\n }\n };\n try {\n const items = await queryAll<CmsModel>(queryAllParams);\n\n return cleanupItems(entity, items);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not list models.\",\n ex.code || \"MODEL_LIST_ERROR\",\n {\n error: ex,\n partitionKey: queryAllParams.partitionKey\n }\n );\n }\n };\n\n return {\n create,\n update,\n delete: deleteModel,\n get,\n list\n };\n};\n"],"mappings":";;;;;;;;;;;AAUA;;AACA;;AACA;;AACA;;AAMA,MAAMA,kBAAkB,GAAIC,MAAD,IAAyC;EAChE,MAAM;IAAEC,MAAF;IAAUC;EAAV,IAAqBF,MAA3B;;EACA,IAAI,CAACC,MAAL,EAAa;IACT,MAAM,IAAIE,cAAJ,CAAiB,2DAAjB,CAAN;EACH,CAFD,MAEO,IAAI,CAACD,MAAL,EAAa;IAChB,MAAM,IAAIC,cAAJ,CAAiB,2DAAjB,CAAN;EACH;;EACD,OAAQ,KAAIF,MAAO,MAAKC,MAAO,SAA/B;AACH,CARD;;AAaA,MAAME,aAAa,GAAIJ,MAAD,IAAmC;EACrD,OAAOA,MAAM,CAACK,OAAd;AACH,CAFD;;AAQA,MAAMC,UAAU,GAAIN,MAAD,IAAuD;EACtE,OAAO;IACHO,EAAE,EAAER,kBAAkB,CAACC,MAAD,CADnB;IAEHQ,EAAE,EAAEJ,aAAa,CAACJ,MAAD;EAFd,CAAP;AAIH,CALD;;AAOA,MAAMS,UAAU,GAAG,MAAc;EAC7B,OAAO,WAAP;AACH,CAFD;;AAOO,MAAMC,6BAA6B,GACtCV,MADyC,IAEb;EAC5B,MAAM;IAAEW;EAAF,IAAaX,MA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AH,IAAW,kBAFT,EAGF;QACIH,KAAK,EAAED,EADX;QAEIa,YAAY,EAAED,cAAc,CAACC;MAFjC,CAHE,CAAN;IAQH;EACJ,CAvBD;;EAyBA,OAAO;IACHnB,MADG;IAEHQ,MAFG;IAGHI,MAAM,EAAED,WAHL;IAIHE,GAJG;IAKHG;EALG,CAAP;AAOH,CA5HM"}
@@ -0,0 +1,7 @@
1
+ import { CmsSettingsStorageOperations } from "@webiny/api-headless-cms/types";
2
+ import { Entity } from "dynamodb-toolbox";
3
+ interface CreateSettingsStorageOperationsParams {
4
+ entity: Entity<any>;
5
+ }
6
+ export declare const createSettingsStorageOperations: (params: CreateSettingsStorageOperationsParams) => CmsSettingsStorageOperations;
7
+ export {};
@@ -0,0 +1,135 @@
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.createSettingsStorageOperations = void 0;
9
+
10
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
+
12
+ var _get = require("@webiny/db-dynamodb/utils/get");
13
+
14
+ var _error = _interopRequireDefault(require("@webiny/error"));
15
+
16
+ var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
17
+
18
+ const convertToDbData = settings => {
19
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, settings), {}, {
20
+ contentModelLastChange: settings.contentModelLastChange.toISOString()
21
+ });
22
+ };
23
+
24
+ const convertFromDbData = settings => {
25
+ if (!settings) {
26
+ return null;
27
+ }
28
+
29
+ let contentModelLastChange;
30
+
31
+ try {
32
+ contentModelLastChange = new Date(settings.contentModelLastChange);
33
+ } catch {
34
+ contentModelLastChange = new Date();
35
+ }
36
+
37
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, settings), {}, {
38
+ contentModelLastChange
39
+ });
40
+ };
41
+
42
+ const createPartitionKey = ({
43
+ tenant,
44
+ locale
45
+ }) => {
46
+ return `T#${tenant}#L#${locale}#CMS#SETTINGS`;
47
+ };
48
+
49
+ const createSortKey = () => {
50
+ return "settings";
51
+ };
52
+
53
+ const createKeys = params => {
54
+ return {
55
+ PK: createPartitionKey(params),
56
+ SK: createSortKey()
57
+ };
58
+ };
59
+
60
+ const createSettingsStorageOperations = params => {
61
+ const {
62
+ entity
63
+ } = params;
64
+
65
+ const create = async params => {
66
+ const {
67
+ settings
68
+ } = params;
69
+ const keys = createKeys(settings);
70
+ const dbSettings = convertToDbData(settings);
71
+
72
+ try {
73
+ await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, dbSettings), keys));
74
+ return settings;
75
+ } catch (ex) {
76
+ throw new _error.default(ex.message || "Could not create settings.", ex.code || "CREATE_SETTINGS_ERROR", {
77
+ error: ex,
78
+ settings,
79
+ dbSettings,
80
+ keys
81
+ });
82
+ }
83
+ };
84
+
85
+ const update = async params => {
86
+ const {
87
+ settings
88
+ } = params;
89
+ const keys = createKeys(settings);
90
+ const dbSettings = convertToDbData(settings);
91
+
92
+ try {
93
+ await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, dbSettings), keys));
94
+ return settings;
95
+ } catch (ex) {
96
+ throw new _error.default(ex.message || "Could not update settings.", ex.code || "UPDATE_SETTINGS_ERROR", {
97
+ error: ex,
98
+ settings,
99
+ dbSettings,
100
+ keys
101
+ });
102
+ }
103
+ };
104
+
105
+ const get = async params => {
106
+ const keys = createKeys(params);
107
+
108
+ try {
109
+ const record = await (0, _get.get)({
110
+ entity,
111
+ keys
112
+ });
113
+
114
+ if (!record) {
115
+ return null;
116
+ }
117
+
118
+ const settings = (0, _cleanup.cleanupItem)(entity, record);
119
+ return convertFromDbData(settings);
120
+ } catch (ex) {
121
+ throw new _error.default(ex.message || "Could not get settings.", ex.code || "GET_SETTINGS_ERROR", {
122
+ error: ex,
123
+ keys
124
+ });
125
+ }
126
+ };
127
+
128
+ return {
129
+ create,
130
+ get,
131
+ update
132
+ };
133
+ };
134
+
135
+ exports.createSettingsStorageOperations = createSettingsStorageOperations;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["convertToDbData","settings","contentModelLastChange","toISOString","convertFromDbData","Date","createPartitionKey","tenant","locale","createSortKey","createKeys","params","PK","SK","createSettingsStorageOperations","entity","create","keys","dbSettings","put","ex","WebinyError","message","code","error","update","get","record","getRecord","cleanupItem"],"sources":["index.ts"],"sourcesContent":["import {\n CmsSettings,\n CmsSettingsStorageOperations,\n CmsSettingsStorageOperationsCreateParams,\n CmsSettingsStorageOperationsGetParams,\n CmsSettingsStorageOperationsUpdateParams\n} from \"@webiny/api-headless-cms/types\";\nimport { Entity } from \"dynamodb-toolbox\";\nimport { get as getRecord } from \"@webiny/db-dynamodb/utils/get\";\nimport WebinyError from \"@webiny/error\";\nimport { cleanupItem } from \"@webiny/db-dynamodb/utils/cleanup\";\n\ninterface CmsSettingsDb extends Omit<CmsSettings, \"contentModelLastChange\"> {\n contentModelLastChange: string;\n}\n\nconst convertToDbData = (settings: CmsSettings): CmsSettingsDb => {\n return {\n ...settings,\n contentModelLastChange: settings.contentModelLastChange.toISOString()\n };\n};\n\nconst convertFromDbData = (settings?: CmsSettingsDb): CmsSettings | null => {\n if (!settings) {\n return null;\n }\n let contentModelLastChange;\n try {\n contentModelLastChange = new Date(settings.contentModelLastChange);\n } catch {\n contentModelLastChange = new Date();\n }\n return {\n ...settings,\n contentModelLastChange\n };\n};\n\ninterface PartitionKeyParams {\n tenant: string;\n locale: string;\n}\n\nconst createPartitionKey = ({ tenant, locale }: PartitionKeyParams): string => {\n return `T#${tenant}#L#${locale}#CMS#SETTINGS`;\n};\n\nconst createSortKey = (): string => {\n return \"settings\";\n};\n\ninterface Keys {\n PK: string;\n SK: string;\n}\nconst createKeys = (params: PartitionKeyParams): Keys => {\n return {\n PK: createPartitionKey(params),\n SK: createSortKey()\n };\n};\n\ninterface CreateSettingsStorageOperationsParams {\n entity: Entity<any>;\n}\n\nexport const createSettingsStorageOperations = (\n params: CreateSettingsStorageOperationsParams\n): CmsSettingsStorageOperations => {\n const { entity } = params;\n\n const create = async (params: CmsSettingsStorageOperationsCreateParams) => {\n const { settings } = params;\n const keys = createKeys(settings);\n\n const dbSettings: CmsSettingsDb = convertToDbData(settings);\n\n try {\n await entity.put({\n ...dbSettings,\n ...keys\n });\n return settings;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create settings.\",\n ex.code || \"CREATE_SETTINGS_ERROR\",\n {\n error: ex,\n settings,\n dbSettings,\n keys\n }\n );\n }\n };\n\n const update = async (params: CmsSettingsStorageOperationsUpdateParams) => {\n const { settings } = params;\n\n const keys = createKeys(settings);\n\n const dbSettings: CmsSettingsDb = convertToDbData(settings);\n\n try {\n await entity.put({\n ...dbSettings,\n ...keys\n });\n return settings;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update settings.\",\n ex.code || \"UPDATE_SETTINGS_ERROR\",\n {\n error: ex,\n settings,\n dbSettings,\n keys\n }\n );\n }\n };\n\n const get = async (params: CmsSettingsStorageOperationsGetParams) => {\n const keys = createKeys(params);\n try {\n const record = await getRecord<CmsSettingsDb>({\n entity,\n keys\n });\n if (!record) {\n return null;\n }\n const settings = cleanupItem(entity, record) as CmsSettingsDb;\n return convertFromDbData(settings);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not get settings.\",\n ex.code || \"GET_SETTINGS_ERROR\",\n {\n error: ex,\n keys\n }\n );\n }\n };\n\n return {\n create,\n get,\n update\n };\n};\n"],"mappings":";;;;;;;;;;;AAQA;;AACA;;AACA;;AAMA,MAAMA,eAAe,GAAIC,QAAD,IAA0C;EAC9D,mEACOA,QADP;IAEIC,sBAAsB,EAAED,QAAQ,CAACC,sBAAT,CAAgCC,WAAhC;EAF5B;AAIH,CALD;;AAOA,MAAMC,iBAAiB,GAAIH,QAAD,IAAkD;EACxE,IAAI,CAACA,QAAL,EAAe;IACX,OAAO,IAAP;EACH;;EACD,IAAIC,sBAAJ;;EACA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,MAArB;IAEA,MAAMM,IAAI,GAAGP,UAAU,CAACT,QAAD,CAAvB;IAEA,MAAMiB,UAAyB,GAAGlB,eAAe,CAACC,QAAD,CAAjD;;IAEA,IAAI;MACA,MAAMc,MAAM,CAACI,GAAP,6DACCD,UADD,GAECD,IAFD,EAAN;MAIA,OAAOhB,QAAP;IACH,CAND,CAME,OAAOmB,EAAP,EAAW;MACT,MAAM,IAAIC,cAAJ,CACFD,EAAE,CAACE,OAAH,IAAc,4BADZ,EAEFF,EAAE,CAACG,IAAH,IAAW,uBAFT,EAGF;QACIC,KAAK,EAAEJ,EADX;QAEInB,QAFJ;QAGIiB,UAHJ;QAIID;MAJJ,CAHE,CAAN;IAUH;EACJ,CAzBD;;EA2BA,MAAMS,GAAG,GAAG,MAAOf,MAAP,IAAyD;IACjE,MAAMM,IAAI,GAAGP,UAAU,CAACC,MAAD,CAAvB;;IACA,IAAI;MACA,MAAMgB,MAAM,GAAG,MAAM,IAAAC,QAAA,EAAyB;QAC1Cb,MAD0C;QAE1CE;MAF0C,CAAzB,CAArB;;MAIA,IAAI,CAACU,MAAL,EAAa;QACT,OAAO,IAAP;MACH;;MACD,MAAM1B,QAAQ,GAAG,IAAA4B,oBAAA,EAAYd,MAAZ,EAAoBY,MAApB,CAAjB;MACA,OAAOvB,iBAAiB,CAACH,QAAD,CAAxB;IACH,CAVD,CAUE,OAAOmB,EAAP,EAAW;MACT,MAAM,IAAIC,cAAJ,CACFD,EAAE,CAACE,OAAH,IAAc,yBADZ,EAEFF,EAAE,CAACG,IAAH,IAAW,oBAFT,EAGF;QACIC,KAAK,EAAEJ,EADX;QAEIH;MAFJ,CAHE,CAAN;IAQH;EACJ,CAtBD;;EAwBA,OAAO;IACHD,MADG;IAEHU,GAFG;IAGHD;EAHG,CAAP;AAKH,CAvFM"}
@@ -0,0 +1,7 @@
1
+ import { CmsSystemStorageOperations } from "@webiny/api-headless-cms/types";
2
+ import { Entity } from "dynamodb-toolbox";
3
+ interface CreateSystemStorageOperationsParams {
4
+ entity: Entity<any>;
5
+ }
6
+ export declare const createSystemStorageOperations: (params: CreateSystemStorageOperationsParams) => CmsSystemStorageOperations;
7
+ export {};
@@ -0,0 +1,99 @@
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.createSystemStorageOperations = void 0;
9
+
10
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
+
12
+ var _error = _interopRequireDefault(require("@webiny/error"));
13
+
14
+ var _get = require("@webiny/db-dynamodb/utils/get");
15
+
16
+ var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
17
+
18
+ const createPartitionKey = ({
19
+ tenant
20
+ }) => {
21
+ return `T#${tenant.toLowerCase()}#SYSTEM`;
22
+ };
23
+
24
+ const createSortKey = () => {
25
+ return "CMS";
26
+ };
27
+
28
+ const createKeys = params => {
29
+ return {
30
+ PK: createPartitionKey(params),
31
+ SK: createSortKey()
32
+ };
33
+ };
34
+
35
+ const createSystemStorageOperations = params => {
36
+ const {
37
+ entity
38
+ } = params;
39
+
40
+ const create = async ({
41
+ system
42
+ }) => {
43
+ const keys = createKeys(system);
44
+
45
+ try {
46
+ await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, system), keys));
47
+ return system;
48
+ } catch (ex) {
49
+ throw new _error.default(ex.message || "Could not create system.", ex.code || "CREATE_SYSTEM_ERROR", {
50
+ error: ex,
51
+ system,
52
+ keys
53
+ });
54
+ }
55
+ };
56
+
57
+ const update = async params => {
58
+ const {
59
+ system
60
+ } = params;
61
+ const keys = createKeys(system);
62
+
63
+ try {
64
+ await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, system), keys));
65
+ return system;
66
+ } catch (ex) {
67
+ throw new _error.default(ex.message || "Could not update system.", ex.code || "UPDATE_SYSTEM_ERROR", {
68
+ error: ex,
69
+ system,
70
+ keys
71
+ });
72
+ }
73
+ };
74
+
75
+ const get = async params => {
76
+ const keys = createKeys(params);
77
+
78
+ try {
79
+ const system = await (0, _get.get)({
80
+ entity,
81
+ keys
82
+ });
83
+ return (0, _cleanup.cleanupItem)(entity, system);
84
+ } catch (ex) {
85
+ throw new _error.default(ex.message || "Could not get system.", ex.code || "GET_SYSTEM_ERROR", {
86
+ error: ex,
87
+ keys
88
+ });
89
+ }
90
+ };
91
+
92
+ return {
93
+ create,
94
+ update,
95
+ get
96
+ };
97
+ };
98
+
99
+ exports.createSystemStorageOperations = createSystemStorageOperations;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createPartitionKey","tenant","toLowerCase","createSortKey","createKeys","params","PK","SK","createSystemStorageOperations","entity","create","system","keys","put","ex","WebinyError","message","code","error","update","get","getRecord","cleanupItem"],"sources":["index.ts"],"sourcesContent":["import {\n CmsSystem,\n CmsSystemStorageOperations,\n CmsSystemStorageOperationsCreateParams,\n CmsSystemStorageOperationsGetParams,\n CmsSystemStorageOperationsUpdateParams\n} from \"@webiny/api-headless-cms/types\";\nimport { Entity } from \"dynamodb-toolbox\";\nimport WebinyError from \"@webiny/error\";\nimport { get as getRecord } from \"@webiny/db-dynamodb/utils/get\";\nimport { cleanupItem } from \"@webiny/db-dynamodb/utils/cleanup\";\n\ninterface CreateSystemStorageOperationsParams {\n entity: Entity<any>;\n}\n\ninterface PartitionKeyParams {\n tenant: string;\n}\nconst createPartitionKey = ({ tenant }: PartitionKeyParams): string => {\n return `T#${tenant.toLowerCase()}#SYSTEM`;\n};\nconst createSortKey = (): string => {\n return \"CMS\";\n};\n\ninterface Keys {\n PK: string;\n SK: string;\n}\nconst createKeys = (params: PartitionKeyParams): Keys => {\n return {\n PK: createPartitionKey(params),\n SK: createSortKey()\n };\n};\n\nexport const createSystemStorageOperations = (\n params: CreateSystemStorageOperationsParams\n): CmsSystemStorageOperations => {\n const { entity } = params;\n\n const create = async ({ system }: CmsSystemStorageOperationsCreateParams) => {\n const keys = createKeys(system);\n try {\n await entity.put({\n ...system,\n ...keys\n });\n return system;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create system.\",\n ex.code || \"CREATE_SYSTEM_ERROR\",\n {\n error: ex,\n system,\n keys\n }\n );\n }\n };\n\n const update = async (params: CmsSystemStorageOperationsUpdateParams) => {\n const { system } = params;\n\n const keys = createKeys(system);\n\n try {\n await entity.put({\n ...system,\n ...keys\n });\n return system;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update system.\",\n ex.code || \"UPDATE_SYSTEM_ERROR\",\n {\n error: ex,\n system,\n keys\n }\n );\n }\n };\n\n const get = async (params: CmsSystemStorageOperationsGetParams) => {\n const keys = createKeys(params);\n\n try {\n const system = await getRecord<CmsSystem>({\n entity,\n keys\n });\n return cleanupItem(entity, system);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not get system.\",\n ex.code || \"GET_SYSTEM_ERROR\",\n {\n error: ex,\n keys\n }\n );\n }\n };\n\n return {\n create,\n update,\n get\n };\n};\n"],"mappings":";;;;;;;;;;;AAQA;;AACA;;AACA;;AASA,MAAMA,kBAAkB,GAAG,CAAC;EAAEC;AAAF,CAAD,KAA4C;EACnE,OAAQ,KAAIA,MAAM,CAACC,WAAP,EAAqB,SAAjC;AACH,CAFD;;AAGA,MAAMC,aAAa,GAAG,MAAc;EAChC,OAAO,KAAP;AACH,CAFD;;AAQA,MAAMC,UAAU,GAAIC,MAAD,IAAsC;EACrD,OAAO;IACHC,EAAE,EAAEN,kBAAkB,CAACK,MAAD,CADnB;IAEHE,EAAE,EAAEJ,aAAa;EAFd,CAAP;AAIH,CALD;;AAOO,MAAMK,6BAA6B,GACtCH,MADyC,IAEZ;EAC7B,MAAM;IAAEI;EAAF,IAAaJ,MAAnB;;EAEA,MAAMK,MAAM,GAAG,OAAO;IAAEC;EAAF,CAAP,KAA8D;IACzE,MAAMC,IAAI,GAAGR,UAAU,CAACO,MAAD,CAAvB;;IACA,IAAI;MACA,MAAM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;;EAqBA,OAAO;IACHF,MADG;IAEHS,MAFG;IAGHC;EAHG,CAAP;AAKH,CA5EM"}
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@webiny/api-headless-cms-ddb",
3
+ "version": "0.0.0-ee-vpcs.549378cf03",
4
+ "main": "index.js",
5
+ "keywords": [
6
+ "@webiny/api-headless-cms",
7
+ "storage-operations",
8
+ "dynamodb",
9
+ "cms:ddb"
10
+ ],
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/webiny/webiny-js.git",
14
+ "directory": "packages/api-headless-cms-ddb"
15
+ },
16
+ "description": "DynamoDB storage operations plugin for Headless CMS API.",
17
+ "contributors": [
18
+ "Pavel Denisjuk <pavel@webiny.com>",
19
+ "Sven Al Hamad <sven@webiny.com>",
20
+ "Adrian Smijulj <adrian@webiny.com>"
21
+ ],
22
+ "license": "MIT",
23
+ "dependencies": {
24
+ "@babel/runtime": "7.19.0",
25
+ "@webiny/api-headless-cms": "0.0.0-ee-vpcs.549378cf03",
26
+ "@webiny/db-dynamodb": "0.0.0-ee-vpcs.549378cf03",
27
+ "@webiny/error": "0.0.0-ee-vpcs.549378cf03",
28
+ "@webiny/handler-db": "0.0.0-ee-vpcs.549378cf03",
29
+ "@webiny/utils": "0.0.0-ee-vpcs.549378cf03",
30
+ "aws-sdk": "2.1230.0",
31
+ "dataloader": "2.1.0",
32
+ "dot-prop": "6.0.1",
33
+ "dynamodb-toolbox": "0.3.5",
34
+ "jsonpack": "1.1.5",
35
+ "lodash": "4.17.21"
36
+ },
37
+ "devDependencies": {
38
+ "@babel/cli": "^7.19.3",
39
+ "@babel/core": "^7.19.3",
40
+ "@babel/preset-env": "^7.19.4",
41
+ "@types/jsonpack": "^1.1.0",
42
+ "@webiny/cli": "^0.0.0-ee-vpcs.549378cf03",
43
+ "@webiny/plugins": "^0.0.0-ee-vpcs.549378cf03",
44
+ "@webiny/project-utils": "^0.0.0-ee-vpcs.549378cf03",
45
+ "jest": "^28.1.0",
46
+ "jest-dynalite": "^3.2.0",
47
+ "jest-environment-node": "^27.2.4",
48
+ "ttypescript": "^1.5.12",
49
+ "typescript": "4.7.4"
50
+ },
51
+ "publishConfig": {
52
+ "access": "public",
53
+ "directory": "dist"
54
+ },
55
+ "scripts": {
56
+ "build": "yarn webiny run build",
57
+ "watch": "yarn webiny run watch"
58
+ },
59
+ "gitHead": "549378cf03fcd27845fc3fa23d1dc6b32896f630"
60
+ }
@@ -0,0 +1,22 @@
1
+ import { Plugin } from "@webiny/plugins/Plugin";
2
+ import { CmsModelField } from "@webiny/api-headless-cms/types";
3
+ export interface CreatePathCallableParams {
4
+ field: Partial<CmsModelField> & Pick<CmsModelField, "fieldId" | "storageId" | "id">;
5
+ index?: number;
6
+ }
7
+ export interface CreatePathCallable {
8
+ (params: CreatePathCallableParams): string;
9
+ }
10
+ export interface CmsEntryFieldFilterPathPluginParams {
11
+ fieldType: string;
12
+ fieldId?: string[];
13
+ path: string | CreatePathCallable;
14
+ }
15
+ export declare class CmsEntryFieldFilterPathPlugin extends Plugin {
16
+ static readonly type: string;
17
+ private readonly config;
18
+ get fieldType(): string;
19
+ constructor(config: CmsEntryFieldFilterPathPluginParams);
20
+ canUse(field: Pick<CmsModelField, "fieldId" | "type">): boolean;
21
+ createPath(params: CreatePathCallableParams): string;
22
+ }
@@ -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.CmsEntryFieldFilterPathPlugin = void 0;
9
+
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
12
+ var _error = _interopRequireDefault(require("@webiny/error"));
13
+
14
+ var _Plugin = require("@webiny/plugins/Plugin");
15
+
16
+ class CmsEntryFieldFilterPathPlugin extends _Plugin.Plugin {
17
+ get fieldType() {
18
+ return this.config.fieldType;
19
+ }
20
+
21
+ constructor(config) {
22
+ super();
23
+ (0, _defineProperty2.default)(this, "config", void 0);
24
+ this.config = config;
25
+ this.name = `${this.constructor.type}-${this.config.fieldType}`;
26
+ }
27
+
28
+ canUse(field) {
29
+ if (field.type !== this.config.fieldType) {
30
+ return false;
31
+ }
32
+
33
+ const fieldId = this.config.fieldId;
34
+
35
+ if (!fieldId || Array.isArray(fieldId) === false || fieldId.length === 0) {
36
+ return true;
37
+ }
38
+
39
+ return fieldId.includes(field.fieldId);
40
+ }
41
+
42
+ createPath(params) {
43
+ if (typeof this.config.path === "function") {
44
+ return this.config.path(params);
45
+ } else if (typeof this.config.path === "string") {
46
+ return this.config.path;
47
+ }
48
+
49
+ throw new _error.default(`Missing path in "${this.name}" plugin.`);
50
+ }
51
+
52
+ }
53
+
54
+ exports.CmsEntryFieldFilterPathPlugin = CmsEntryFieldFilterPathPlugin;
55
+ (0, _defineProperty2.default)(CmsEntryFieldFilterPathPlugin, "type", "cms-field-filter-path");
@@ -0,0 +1 @@
1
+ {"version":3,"names":["CmsEntryFieldFilterPathPlugin","Plugin","fieldType","config","constructor","name","type","canUse","field","fieldId","Array","isArray","length","includes","createPath","params","path","WebinyError"],"sources":["CmsEntryFieldFilterPathPlugin.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { Plugin } from \"@webiny/plugins/Plugin\";\nimport { CmsModelField } from \"@webiny/api-headless-cms/types\";\n\nexport interface CreatePathCallableParams {\n field: Partial<CmsModelField> & Pick<CmsModelField, \"fieldId\" | \"storageId\" | \"id\">;\n index?: number;\n}\nexport interface CreatePathCallable {\n (params: CreatePathCallableParams): string;\n}\nexport interface CmsEntryFieldFilterPathPluginParams {\n fieldType: string;\n fieldId?: string[];\n path: string | CreatePathCallable;\n}\nexport class CmsEntryFieldFilterPathPlugin extends Plugin {\n public static override readonly type: string = \"cms-field-filter-path\";\n\n private readonly config: CmsEntryFieldFilterPathPluginParams;\n\n public get fieldType(): string {\n return this.config.fieldType;\n }\n\n public constructor(config: CmsEntryFieldFilterPathPluginParams) {\n super();\n\n this.config = config;\n\n this.name = `${(this.constructor as any).type}-${this.config.fieldType}`;\n }\n\n public canUse(field: Pick<CmsModelField, \"fieldId\" | \"type\">): boolean {\n if (field.type !== this.config.fieldType) {\n return false;\n }\n const fieldId = this.config.fieldId;\n if (!fieldId || Array.isArray(fieldId) === false || fieldId.length === 0) {\n return true;\n }\n return fieldId.includes(field.fieldId);\n }\n\n public createPath(params: CreatePathCallableParams): string {\n if (typeof this.config.path === \"function\") {\n return this.config.path(params);\n } else if (typeof this.config.path === \"string\") {\n return this.config.path;\n }\n throw new WebinyError(`Missing path in \"${this.name}\" plugin.`);\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAeO,MAAMA,6BAAN,SAA4CC,cAA5C,CAAmD;EAKlC,IAATC,SAAS,GAAW;IAC3B,OAAO,KAAKC,MAAL,CAAYD,SAAnB;EACH;;EAEME,WAAW,CAACD,MAAD,EAA8C;IAC5D;IAD4D;IAG5D,KAAKA,MAAL,GAAcA,MAAd;IAEA,KAAKE,IAAL,GAAa,GAAG,KAAKD,WAAN,CAA0BE,IAAK,IAAG,KAAKH,MAAL,CAAYD,SAAU,EAAvE;EACH;;EAEMK,MAAM,CAACC,KAAD,EAA0D;IACnE,IAAIA,KAAK,CAACF,IAAN,KAAe,KAAKH,MAAL,CAAYD,SAA/B,EAA0C;MACtC,OAAO,KAAP;IACH;;IACD,MAAMO,OAAO,GAAG,KAAKN,MAAL,CAAYM,OAA5B;;IACA,IAAI,CAACA,OAAD,IAAYC,KAAK,CAACC,OAAN,CAAcF,OAAd,MAA2B,KAAvC,IAAgDA,OAAO,CAACG,MAAR,KAAmB,CAAvE,EAA0E;MACtE,OAAO,IAAP;IACH;;IACD,OAAOH,OAAO,CAACI,QAAR,CAAiBL,KAAK,CAACC,OAAvB,CAAP;EACH;;EAEMK,UAAU,CAACC,MAAD,EAA2C;IACxD,IAAI,OAAO,KAAKZ,MAAL,CAAYa,IAAnB,KAA4B,UAAhC,EAA4C;MACxC,OAAO,KAAKb,MAAL,CAAYa,IAAZ,CAAiBD,MAAjB,CAAP;IACH,CAFD,MAEO,IAAI,OAAO,KAAKZ,MAAL,CAAYa,IAAnB,KAA4B,QAAhC,EAA0C;MAC7C,OAAO,KAAKb,MAAL,CAAYa,IAAnB;IACH;;IACD,MAAM,IAAIC,cAAJ,CAAiB,oBAAmB,KAAKZ,IAAK,WAA9C,CAAN;EACH;;AAnCqD;;;8BAA7CL,6B,UACsC,uB"}
@@ -0,0 +1,43 @@
1
+ import { Plugin } from "@webiny/plugins";
2
+ import { ValueFilterPlugin } from "@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin";
3
+ import { Field } from "../operations/entry/filtering/types";
4
+ import { CmsFieldFilterValueTransformPlugin } from "../types";
5
+ /**
6
+ * This plugin is used to create the filter.
7
+ * Internally we have default one + the one for the reference field - because it is actually an object when filtering.
8
+ */
9
+ interface CmsEntryFieldFilterPluginParams {
10
+ fieldType: string;
11
+ create: (params: CmsEntryFieldFilterPluginCreateParams) => null | CmsEntryFieldFilterPluginCreateResponse | CmsEntryFieldFilterPluginCreateResponse[];
12
+ }
13
+ interface CmsEntryFieldFilterPluginCreateParams {
14
+ key: string;
15
+ value: any;
16
+ field: Field;
17
+ fields: Record<string, Field>;
18
+ operation: string;
19
+ valueFilterPlugins: Record<string, ValueFilterPlugin>;
20
+ transformValuePlugins: Record<string, CmsFieldFilterValueTransformPlugin>;
21
+ getFilterCreatePlugin: (type: string) => CmsEntryFieldFilterPlugin;
22
+ negate: boolean;
23
+ compareValue: any;
24
+ transformValue: <I = any, O = any>(value: I) => O;
25
+ }
26
+ export interface CmsEntryFieldFilterPluginCreateResponse {
27
+ field: Field;
28
+ path: string;
29
+ fieldPathId: string;
30
+ plugin: ValueFilterPlugin;
31
+ negate: boolean;
32
+ compareValue: any;
33
+ transformValue: <I = any, O = any>(value: I) => O;
34
+ }
35
+ export declare class CmsEntryFieldFilterPlugin extends Plugin {
36
+ static readonly type: string;
37
+ static readonly ALL: string;
38
+ private readonly config;
39
+ readonly fieldType: string;
40
+ constructor(config: CmsEntryFieldFilterPluginParams);
41
+ create(params: CmsEntryFieldFilterPluginCreateParams): CmsEntryFieldFilterPluginCreateResponse | CmsEntryFieldFilterPluginCreateResponse[] | null;
42
+ }
43
+ export {};