@webiny/api-page-builder-so-ddb-es 0.0.0-mt-1

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 (97) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +30 -0
  3. package/definitions/categoryEntity.d.ts +6 -0
  4. package/definitions/categoryEntity.js +68 -0
  5. package/definitions/menuEntity.d.ts +6 -0
  6. package/definitions/menuEntity.js +68 -0
  7. package/definitions/pageElasticsearchEntity.d.ts +6 -0
  8. package/definitions/pageElasticsearchEntity.js +47 -0
  9. package/definitions/pageElementEntity.d.ts +6 -0
  10. package/definitions/pageElementEntity.js +74 -0
  11. package/definitions/pageEntity.d.ts +6 -0
  12. package/definitions/pageEntity.js +113 -0
  13. package/definitions/settingsEntity.d.ts +6 -0
  14. package/definitions/settingsEntity.js +77 -0
  15. package/definitions/systemEntity.d.ts +6 -0
  16. package/definitions/systemEntity.js +44 -0
  17. package/definitions/table.d.ts +6 -0
  18. package/definitions/table.js +30 -0
  19. package/definitions/tableElasticsearch.d.ts +5 -0
  20. package/definitions/tableElasticsearch.js +37 -0
  21. package/index.d.ts +8 -0
  22. package/index.js +26 -0
  23. package/operations/category/CategoryDataLoader.d.ts +20 -0
  24. package/operations/category/CategoryDataLoader.js +77 -0
  25. package/operations/category/CategoryStorageOperations.d.ts +29 -0
  26. package/operations/category/CategoryStorageOperations.js +243 -0
  27. package/operations/category/fields.d.ts +3 -0
  28. package/operations/category/fields.js +28 -0
  29. package/operations/category/index.d.ts +5 -0
  30. package/operations/category/index.js +28 -0
  31. package/operations/configurations.d.ts +36 -0
  32. package/operations/configurations.js +71 -0
  33. package/operations/menu/MenuStorageOperations.d.ts +23 -0
  34. package/operations/menu/MenuStorageOperations.js +235 -0
  35. package/operations/menu/fields.d.ts +3 -0
  36. package/operations/menu/fields.js +25 -0
  37. package/operations/menu/index.d.ts +5 -0
  38. package/operations/menu/index.js +28 -0
  39. package/operations/pageElement/PageElementStorageOperations.d.ts +23 -0
  40. package/operations/pageElement/PageElementStorageOperations.js +234 -0
  41. package/operations/pageElement/fields.d.ts +3 -0
  42. package/operations/pageElement/fields.js +19 -0
  43. package/operations/pageElement/index.d.ts +7 -0
  44. package/operations/pageElement/index.js +28 -0
  45. package/operations/pages/PageStorageOperations.d.ts +79 -0
  46. package/operations/pages/PageStorageOperations.js +1117 -0
  47. package/operations/pages/elasticsearchQueryBody.d.ts +18 -0
  48. package/operations/pages/elasticsearchQueryBody.js +271 -0
  49. package/operations/pages/fields.d.ts +3 -0
  50. package/operations/pages/fields.js +42 -0
  51. package/operations/pages/helpers.d.ts +42 -0
  52. package/operations/pages/helpers.js +89 -0
  53. package/operations/pages/index.d.ts +5 -0
  54. package/operations/pages/index.js +33 -0
  55. package/operations/settings/SettingsStorageOperations.d.ts +35 -0
  56. package/operations/settings/SettingsStorageOperations.js +191 -0
  57. package/operations/settings/index.d.ts +7 -0
  58. package/operations/settings/index.js +23 -0
  59. package/operations/system/InstallationDdbEsPlugin.d.ts +2 -0
  60. package/operations/system/InstallationDdbEsPlugin.js +73 -0
  61. package/operations/system/SystemStorageOperations.d.ts +16 -0
  62. package/operations/system/SystemStorageOperations.js +114 -0
  63. package/operations/system/index.d.ts +5 -0
  64. package/operations/system/index.js +29 -0
  65. package/package.json +65 -0
  66. package/plugins/definitions/CategoryDynamoDbElasticFieldPlugin.d.ts +4 -0
  67. package/plugins/definitions/CategoryDynamoDbElasticFieldPlugin.js +17 -0
  68. package/plugins/definitions/IndexPageDataPlugin.d.ts +18 -0
  69. package/plugins/definitions/IndexPageDataPlugin.js +32 -0
  70. package/plugins/definitions/MenuDynamoDbElasticFieldPlugin.d.ts +4 -0
  71. package/plugins/definitions/MenuDynamoDbElasticFieldPlugin.js +17 -0
  72. package/plugins/definitions/PageElasticsearchBodyModifierPlugin.d.ts +4 -0
  73. package/plugins/definitions/PageElasticsearchBodyModifierPlugin.js +17 -0
  74. package/plugins/definitions/PageElasticsearchFieldPlugin.d.ts +5 -0
  75. package/plugins/definitions/PageElasticsearchFieldPlugin.js +22 -0
  76. package/plugins/definitions/PageElasticsearchQueryModifierPlugin.d.ts +4 -0
  77. package/plugins/definitions/PageElasticsearchQueryModifierPlugin.js +17 -0
  78. package/plugins/definitions/PageElasticsearchSortModifierPlugin.d.ts +4 -0
  79. package/plugins/definitions/PageElasticsearchSortModifierPlugin.js +17 -0
  80. package/plugins/definitions/PageElementDynamoDbElasticFieldPlugin.d.ts +4 -0
  81. package/plugins/definitions/PageElementDynamoDbElasticFieldPlugin.js +17 -0
  82. package/plugins/definitions/SearchLatestPagesPlugin.d.ts +4 -0
  83. package/plugins/definitions/SearchLatestPagesPlugin.js +17 -0
  84. package/plugins/definitions/SearchPagesPlugin.d.ts +24 -0
  85. package/plugins/definitions/SearchPagesPlugin.js +39 -0
  86. package/plugins/definitions/SearchPublishedPagesPlugin.d.ts +4 -0
  87. package/plugins/definitions/SearchPublishedPagesPlugin.js +17 -0
  88. package/upgrades/index.d.ts +2 -0
  89. package/upgrades/index.js +14 -0
  90. package/upgrades/v5.15.0/category.d.ts +2 -0
  91. package/upgrades/v5.15.0/category.js +75 -0
  92. package/upgrades/v5.15.0/index.d.ts +4 -0
  93. package/upgrades/v5.15.0/index.js +52 -0
  94. package/upgrades/v5.15.0/menu.d.ts +2 -0
  95. package/upgrades/v5.15.0/menu.js +75 -0
  96. package/upgrades/v5.15.0/pageElement.d.ts +2 -0
  97. package/upgrades/v5.15.0/pageElement.js +75 -0
@@ -0,0 +1,235 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.MenuStorageOperationsDdbEs = void 0;
9
+
10
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
11
+
12
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
+
14
+ var _error = _interopRequireDefault(require("@webiny/error"));
15
+
16
+ var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
17
+
18
+ var _query = require("@webiny/db-dynamodb/utils/query");
19
+
20
+ var _filter = require("@webiny/db-dynamodb/utils/filter");
21
+
22
+ var _sort = require("@webiny/db-dynamodb/utils/sort");
23
+
24
+ var _listResponse = require("@webiny/db-dynamodb/utils/listResponse");
25
+
26
+ var _table = require("../../definitions/table");
27
+
28
+ var _menuEntity = require("../../definitions/menuEntity");
29
+
30
+ var _MenuDynamoDbElasticFieldPlugin = require("../../plugins/definitions/MenuDynamoDbElasticFieldPlugin");
31
+
32
+ const _excluded = ["tenant", "locale"];
33
+
34
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
35
+
36
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
37
+
38
+ class MenuStorageOperationsDdbEs {
39
+ constructor({
40
+ context
41
+ }) {
42
+ (0, _defineProperty2.default)(this, "context", void 0);
43
+ (0, _defineProperty2.default)(this, "table", void 0);
44
+ (0, _defineProperty2.default)(this, "entity", void 0);
45
+ this.context = context;
46
+ this.table = (0, _table.defineTable)({
47
+ context
48
+ });
49
+ this.entity = (0, _menuEntity.defineMenuEntity)({
50
+ context,
51
+ table: this.table
52
+ });
53
+ }
54
+
55
+ async get(params) {
56
+ const {
57
+ where
58
+ } = params;
59
+ const keys = {
60
+ PK: this.createPartitionKey(where),
61
+ SK: this.createSortKey(where)
62
+ };
63
+
64
+ try {
65
+ const result = await this.entity.get(keys);
66
+
67
+ if (!result || !result.Item) {
68
+ return null;
69
+ }
70
+
71
+ return (0, _cleanup.cleanupItem)(this.entity, result.Item);
72
+ } catch (ex) {
73
+ throw new _error.default(ex.message || "Could not load menu by given parameters.", ex.code || "MENU_GET_ERROR", {
74
+ where
75
+ });
76
+ }
77
+ }
78
+
79
+ async list(params) {
80
+ const {
81
+ where,
82
+ sort,
83
+ limit
84
+ } = params;
85
+ const {
86
+ tenant,
87
+ locale
88
+ } = where,
89
+ restWhere = (0, _objectWithoutProperties2.default)(where, _excluded);
90
+ const queryAllParams = {
91
+ entity: this.entity,
92
+ partitionKey: this.createPartitionKey({
93
+ tenant,
94
+ locale
95
+ }),
96
+ options: {
97
+ limit: limit || undefined,
98
+ gt: " "
99
+ }
100
+ };
101
+ let items = [];
102
+
103
+ try {
104
+ items = await (0, _query.queryAll)(queryAllParams);
105
+ } catch (ex) {
106
+ throw new _error.default(ex.message || "Could not list menus by given parameters.", ex.code || "MENUS_LIST_ERROR", {
107
+ partitionKey: queryAllParams.partitionKey,
108
+ options: queryAllParams.options
109
+ });
110
+ }
111
+
112
+ const fields = this.context.plugins.byType(_MenuDynamoDbElasticFieldPlugin.MenuDynamoDbElasticFieldPlugin.type);
113
+ const filteredItems = (0, _filter.filterItems)({
114
+ plugins: this.context.plugins,
115
+ where: restWhere,
116
+ items,
117
+ fields
118
+ }).map(item => {
119
+ return (0, _cleanup.cleanupItem)(this.entity, item);
120
+ });
121
+ const sortedItems = (0, _sort.sortItems)({
122
+ items: filteredItems,
123
+ sort,
124
+ fields ///: ["createdOn", "id", "title", "slug"]
125
+
126
+ });
127
+ return (0, _listResponse.createListResponse)({
128
+ items: sortedItems,
129
+ limit,
130
+ totalCount: filteredItems.length,
131
+ after: null
132
+ });
133
+ }
134
+
135
+ async create(params) {
136
+ const {
137
+ menu
138
+ } = params;
139
+ const keys = {
140
+ PK: this.createPartitionKey({
141
+ tenant: menu.tenant,
142
+ locale: menu.locale
143
+ }),
144
+ SK: this.createSortKey(menu)
145
+ };
146
+
147
+ try {
148
+ await this.entity.put(_objectSpread(_objectSpread({}, menu), {}, {
149
+ TYPE: this.createType()
150
+ }, keys));
151
+ return menu;
152
+ } catch (ex) {
153
+ throw new _error.default(ex.message || "Could not create menu.", ex.code || "MENU_CREATE_ERROR", {
154
+ keys,
155
+ menu
156
+ });
157
+ }
158
+ }
159
+
160
+ async update(params) {
161
+ const {
162
+ menu,
163
+ original
164
+ } = params;
165
+ const keys = {
166
+ PK: this.createPartitionKey({
167
+ tenant: menu.tenant,
168
+ locale: menu.locale
169
+ }),
170
+ SK: this.createSortKey(menu)
171
+ };
172
+
173
+ try {
174
+ await this.entity.put(_objectSpread(_objectSpread({}, menu), {}, {
175
+ TYPE: this.createType()
176
+ }, keys));
177
+ return menu;
178
+ } catch (ex) {
179
+ throw new _error.default(ex.message || "Could not update menu.", ex.code || "MENU_UPDATE_ERROR", {
180
+ keys,
181
+ original,
182
+ menu
183
+ });
184
+ }
185
+ }
186
+
187
+ async delete(params) {
188
+ const {
189
+ menu
190
+ } = params;
191
+ const keys = {
192
+ PK: this.createPartitionKey({
193
+ tenant: menu.tenant,
194
+ locale: menu.locale
195
+ }),
196
+ SK: this.createSortKey(menu)
197
+ };
198
+
199
+ try {
200
+ await this.entity.delete(_objectSpread(_objectSpread({}, menu), keys));
201
+ return menu;
202
+ } catch (ex) {
203
+ throw new _error.default(ex.message || "Could not delete menu.", ex.code || "MENU_DELETE_ERROR", {
204
+ keys,
205
+ menu
206
+ });
207
+ }
208
+ }
209
+
210
+ createPartitionKey({
211
+ tenant,
212
+ locale
213
+ }) {
214
+ return `T#${tenant}#L#${locale}#PB#M`;
215
+ }
216
+
217
+ createSortKey(input) {
218
+ if (typeof input === "string") {
219
+ return input;
220
+ } else if (input.slug) {
221
+ return input.slug;
222
+ }
223
+
224
+ throw new _error.default("Could not determine the menu sort key from the input.", "MALFORMED_SORT_KEY", {
225
+ input
226
+ });
227
+ }
228
+
229
+ createType() {
230
+ return "pb.menu";
231
+ }
232
+
233
+ }
234
+
235
+ exports.MenuStorageOperationsDdbEs = MenuStorageOperationsDdbEs;
@@ -0,0 +1,3 @@
1
+ import { MenuDynamoDbElasticFieldPlugin } from "../../plugins/definitions/MenuDynamoDbElasticFieldPlugin";
2
+ declare const _default: () => MenuDynamoDbElasticFieldPlugin[];
3
+ export default _default;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _MenuDynamoDbElasticFieldPlugin = require("../../plugins/definitions/MenuDynamoDbElasticFieldPlugin");
9
+
10
+ var _default = () => [new _MenuDynamoDbElasticFieldPlugin.MenuDynamoDbElasticFieldPlugin({
11
+ field: "id"
12
+ }), new _MenuDynamoDbElasticFieldPlugin.MenuDynamoDbElasticFieldPlugin({
13
+ field: "title"
14
+ }), new _MenuDynamoDbElasticFieldPlugin.MenuDynamoDbElasticFieldPlugin({
15
+ field: "slug"
16
+ }), new _MenuDynamoDbElasticFieldPlugin.MenuDynamoDbElasticFieldPlugin({
17
+ field: "createdOn",
18
+ type: "date"
19
+ }), new _MenuDynamoDbElasticFieldPlugin.MenuDynamoDbElasticFieldPlugin({
20
+ field: "createdBy",
21
+ path: "createdBy.id",
22
+ sortable: false
23
+ })];
24
+
25
+ exports.default = _default;
@@ -0,0 +1,5 @@
1
+ import { MenuStorageOperationsProviderPlugin, Params } from "@webiny/api-page-builder/plugins/MenuStorageOperationsProviderPlugin";
2
+ import { MenuStorageOperations } from "@webiny/api-page-builder/types";
3
+ export declare class MenuStorageOperationsDdbEsProviderPlugin extends MenuStorageOperationsProviderPlugin {
4
+ provide({ context }: Params): Promise<MenuStorageOperations>;
5
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.MenuStorageOperationsDdbEsProviderPlugin = void 0;
9
+
10
+ var _MenuStorageOperationsProviderPlugin = require("@webiny/api-page-builder/plugins/MenuStorageOperationsProviderPlugin");
11
+
12
+ var _MenuStorageOperations = require("./MenuStorageOperations");
13
+
14
+ var _fields = _interopRequireDefault(require("./fields"));
15
+
16
+ class MenuStorageOperationsDdbEsProviderPlugin extends _MenuStorageOperationsProviderPlugin.MenuStorageOperationsProviderPlugin {
17
+ async provide({
18
+ context
19
+ }) {
20
+ context.plugins.register((0, _fields.default)());
21
+ return new _MenuStorageOperations.MenuStorageOperationsDdbEs({
22
+ context
23
+ });
24
+ }
25
+
26
+ }
27
+
28
+ exports.MenuStorageOperationsDdbEsProviderPlugin = MenuStorageOperationsDdbEsProviderPlugin;
@@ -0,0 +1,23 @@
1
+ import { PageElement, PageElementStorageOperations, PageElementStorageOperationsCreateParams, PageElementStorageOperationsDeleteParams, PageElementStorageOperationsGetParams, PageElementStorageOperationsListParams, PageElementStorageOperationsListResponse, PageElementStorageOperationsUpdateParams, PbContext } from "@webiny/api-page-builder/types";
2
+ import { Entity, Table } from "dynamodb-toolbox";
3
+ export interface Params {
4
+ context: PbContext;
5
+ }
6
+ export interface PartitionKeyOptions {
7
+ tenant: string;
8
+ locale: string;
9
+ }
10
+ export declare class PageElementStorageOperationsDdbEs implements PageElementStorageOperations {
11
+ protected readonly context: PbContext;
12
+ readonly table: Table;
13
+ readonly entity: Entity<any>;
14
+ constructor({ context }: Params);
15
+ get(params: PageElementStorageOperationsGetParams): Promise<PageElement | null>;
16
+ list(params: PageElementStorageOperationsListParams): Promise<PageElementStorageOperationsListResponse>;
17
+ create(params: PageElementStorageOperationsCreateParams): Promise<PageElement>;
18
+ update(params: PageElementStorageOperationsUpdateParams): Promise<PageElement>;
19
+ delete(params: PageElementStorageOperationsDeleteParams): Promise<PageElement>;
20
+ createPartitionKey({ tenant, locale }: PartitionKeyOptions): string;
21
+ createSortKey(input: Pick<PageElement, "id"> | string): string;
22
+ createType(): string;
23
+ }
@@ -0,0 +1,234 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.PageElementStorageOperationsDdbEs = void 0;
9
+
10
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
11
+
12
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
+
14
+ var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
15
+
16
+ var _error = _interopRequireDefault(require("@webiny/error"));
17
+
18
+ var _query = require("@webiny/db-dynamodb/utils/query");
19
+
20
+ var _filter = require("@webiny/db-dynamodb/utils/filter");
21
+
22
+ var _sort = require("@webiny/db-dynamodb/utils/sort");
23
+
24
+ var _listResponse = require("@webiny/db-dynamodb/utils/listResponse");
25
+
26
+ var _table = require("../../definitions/table");
27
+
28
+ var _pageElementEntity = require("../../definitions/pageElementEntity");
29
+
30
+ var _PageElementDynamoDbElasticFieldPlugin = require("../../plugins/definitions/PageElementDynamoDbElasticFieldPlugin");
31
+
32
+ const _excluded = ["tenant", "locale"];
33
+
34
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
35
+
36
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
37
+
38
+ class PageElementStorageOperationsDdbEs {
39
+ constructor({
40
+ context
41
+ }) {
42
+ (0, _defineProperty2.default)(this, "context", void 0);
43
+ (0, _defineProperty2.default)(this, "table", void 0);
44
+ (0, _defineProperty2.default)(this, "entity", void 0);
45
+ this.context = context;
46
+ this.table = (0, _table.defineTable)({
47
+ context
48
+ });
49
+ this.entity = (0, _pageElementEntity.definePageElementEntity)({
50
+ context,
51
+ table: this.table
52
+ });
53
+ }
54
+
55
+ async get(params) {
56
+ const {
57
+ where
58
+ } = params;
59
+ const keys = {
60
+ PK: this.createPartitionKey(where),
61
+ SK: this.createSortKey(where)
62
+ };
63
+
64
+ try {
65
+ const result = await this.entity.get(keys);
66
+
67
+ if (!result || !result.Item) {
68
+ return null;
69
+ }
70
+
71
+ return (0, _cleanup.cleanupItem)(this.entity, result.Item);
72
+ } catch (ex) {
73
+ throw new _error.default(ex.message || "Could not load page element by given parameters.", ex.code || "PAGE_ELEMENT_GET_ERROR", {
74
+ where
75
+ });
76
+ }
77
+ }
78
+
79
+ async list(params) {
80
+ const {
81
+ where,
82
+ sort,
83
+ limit
84
+ } = params;
85
+ const {
86
+ tenant,
87
+ locale
88
+ } = where,
89
+ restWhere = (0, _objectWithoutProperties2.default)(where, _excluded);
90
+ const queryAllParams = {
91
+ entity: this.entity,
92
+ partitionKey: this.createPartitionKey({
93
+ tenant,
94
+ locale
95
+ }),
96
+ options: {
97
+ limit: limit || undefined,
98
+ gt: " "
99
+ }
100
+ };
101
+ let results = [];
102
+
103
+ try {
104
+ results = await (0, _query.queryAll)(queryAllParams);
105
+ } catch (ex) {
106
+ throw new _error.default(ex.message || "Could not list page elements by given parameters.", ex.code || "PAGE_ELEMENTS_LIST_ERROR", {
107
+ partitionKey: queryAllParams.partitionKey,
108
+ options: queryAllParams.options
109
+ });
110
+ }
111
+
112
+ const fields = this.context.plugins.byType(_PageElementDynamoDbElasticFieldPlugin.PageElementDynamoDbElasticFieldPlugin.type);
113
+ const filteredItems = (0, _filter.filterItems)({
114
+ plugins: this.context.plugins,
115
+ where: restWhere,
116
+ items: results,
117
+ fields
118
+ }).map(item => {
119
+ return (0, _cleanup.cleanupItem)(this.entity, item);
120
+ });
121
+ const sortedItems = (0, _sort.sortItems)({
122
+ items: filteredItems,
123
+ sort,
124
+ fields
125
+ });
126
+ return (0, _listResponse.createListResponse)({
127
+ items: sortedItems,
128
+ limit,
129
+ totalCount: filteredItems.length,
130
+ after: null
131
+ });
132
+ }
133
+
134
+ async create(params) {
135
+ const {
136
+ pageElement
137
+ } = params;
138
+ const keys = {
139
+ PK: this.createPartitionKey({
140
+ tenant: pageElement.tenant,
141
+ locale: pageElement.locale
142
+ }),
143
+ SK: this.createSortKey(pageElement)
144
+ };
145
+
146
+ try {
147
+ await this.entity.put(_objectSpread(_objectSpread({}, pageElement), {}, {
148
+ TYPE: this.createType()
149
+ }, keys));
150
+ return pageElement;
151
+ } catch (ex) {
152
+ throw new _error.default(ex.message || "Could not create pageElement.", ex.code || "PAGE_ELEMENT_CREATE_ERROR", {
153
+ keys,
154
+ pageElement
155
+ });
156
+ }
157
+ }
158
+
159
+ async update(params) {
160
+ const {
161
+ pageElement,
162
+ original
163
+ } = params;
164
+ const keys = {
165
+ PK: this.createPartitionKey({
166
+ tenant: pageElement.tenant,
167
+ locale: pageElement.locale
168
+ }),
169
+ SK: this.createSortKey(pageElement)
170
+ };
171
+
172
+ try {
173
+ await this.entity.put(_objectSpread(_objectSpread({}, pageElement), {}, {
174
+ TYPE: this.createType()
175
+ }, keys));
176
+ return pageElement;
177
+ } catch (ex) {
178
+ throw new _error.default(ex.message || "Could not update pageElement.", ex.code || "PAGE_ELEMENT_UPDATE_ERROR", {
179
+ keys,
180
+ original,
181
+ pageElement
182
+ });
183
+ }
184
+ }
185
+
186
+ async delete(params) {
187
+ const {
188
+ pageElement
189
+ } = params;
190
+ const keys = {
191
+ PK: this.createPartitionKey({
192
+ tenant: pageElement.tenant,
193
+ locale: pageElement.locale
194
+ }),
195
+ SK: this.createSortKey(pageElement)
196
+ };
197
+
198
+ try {
199
+ await this.entity.delete(keys);
200
+ return pageElement;
201
+ } catch (ex) {
202
+ throw new _error.default(ex.message || "Could not delete pageElement.", ex.code || "PAGE_ELEMENT_DELETE_ERROR", {
203
+ keys,
204
+ pageElement
205
+ });
206
+ }
207
+ }
208
+
209
+ createPartitionKey({
210
+ tenant,
211
+ locale
212
+ }) {
213
+ return `T#${tenant}#L#${locale}#PB#PE`;
214
+ }
215
+
216
+ createSortKey(input) {
217
+ if (typeof input === "string") {
218
+ return input;
219
+ } else if (input.id) {
220
+ return input.id;
221
+ }
222
+
223
+ throw new _error.default("Could not determine the category sort key from the input.", "MALFORMED_SORT_KEY", {
224
+ input
225
+ });
226
+ }
227
+
228
+ createType() {
229
+ return "pb.pageElement";
230
+ }
231
+
232
+ }
233
+
234
+ exports.PageElementStorageOperationsDdbEs = PageElementStorageOperationsDdbEs;
@@ -0,0 +1,3 @@
1
+ import { PageElementDynamoDbElasticFieldPlugin } from "../../plugins/definitions/PageElementDynamoDbElasticFieldPlugin";
2
+ declare const _default: () => PageElementDynamoDbElasticFieldPlugin[];
3
+ export default _default;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _PageElementDynamoDbElasticFieldPlugin = require("../../plugins/definitions/PageElementDynamoDbElasticFieldPlugin");
9
+
10
+ var _default = () => [new _PageElementDynamoDbElasticFieldPlugin.PageElementDynamoDbElasticFieldPlugin({
11
+ field: "createdOn",
12
+ type: "date"
13
+ }), new _PageElementDynamoDbElasticFieldPlugin.PageElementDynamoDbElasticFieldPlugin({
14
+ field: "createdBy",
15
+ path: "createdBy.id",
16
+ sortable: false
17
+ })];
18
+
19
+ exports.default = _default;
@@ -0,0 +1,7 @@
1
+ import { PageElementStorageOperationsProviderPlugin } from "@webiny/api-page-builder/plugins/PageElementStorageOperationsProviderPlugin";
2
+ import { PageElementStorageOperations } from "@webiny/api-page-builder/types";
3
+ export declare class PageElementStorageOperationsDdbEsProviderPlugin extends PageElementStorageOperationsProviderPlugin {
4
+ provide({ context }: {
5
+ context: any;
6
+ }): Promise<PageElementStorageOperations>;
7
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.PageElementStorageOperationsDdbEsProviderPlugin = void 0;
9
+
10
+ var _PageElementStorageOperationsProviderPlugin = require("@webiny/api-page-builder/plugins/PageElementStorageOperationsProviderPlugin");
11
+
12
+ var _PageElementStorageOperations = require("./PageElementStorageOperations");
13
+
14
+ var _fields = _interopRequireDefault(require("./fields"));
15
+
16
+ class PageElementStorageOperationsDdbEsProviderPlugin extends _PageElementStorageOperationsProviderPlugin.PageElementStorageOperationsProviderPlugin {
17
+ async provide({
18
+ context
19
+ }) {
20
+ context.plugins.register((0, _fields.default)());
21
+ return new _PageElementStorageOperations.PageElementStorageOperationsDdbEs({
22
+ context
23
+ });
24
+ }
25
+
26
+ }
27
+
28
+ exports.PageElementStorageOperationsDdbEsProviderPlugin = PageElementStorageOperationsDdbEsProviderPlugin;