@webiny/api-page-builder-so-ddb-es 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.
- package/LICENSE +21 -0
- package/README.md +30 -0
- package/configurations.d.ts +9 -0
- package/configurations.js +49 -0
- package/configurations.js.map +1 -0
- package/definitions/blockCategoryEntity.d.ts +9 -0
- package/definitions/blockCategoryEntity.js +61 -0
- package/definitions/blockCategoryEntity.js.map +1 -0
- package/definitions/categoryEntity.d.ts +9 -0
- package/definitions/categoryEntity.js +61 -0
- package/definitions/categoryEntity.js.map +1 -0
- package/definitions/menuEntity.d.ts +9 -0
- package/definitions/menuEntity.js +61 -0
- package/definitions/menuEntity.js.map +1 -0
- package/definitions/pageBlockEntity.d.ts +9 -0
- package/definitions/pageBlockEntity.js +64 -0
- package/definitions/pageBlockEntity.js.map +1 -0
- package/definitions/pageElasticsearchEntity.d.ts +9 -0
- package/definitions/pageElasticsearchEntity.js +40 -0
- package/definitions/pageElasticsearchEntity.js.map +1 -0
- package/definitions/pageElementEntity.d.ts +9 -0
- package/definitions/pageElementEntity.js +67 -0
- package/definitions/pageElementEntity.js.map +1 -0
- package/definitions/pageEntity.d.ts +9 -0
- package/definitions/pageEntity.js +97 -0
- package/definitions/pageEntity.js.map +1 -0
- package/definitions/settingsEntity.d.ts +9 -0
- package/definitions/settingsEntity.js +77 -0
- package/definitions/settingsEntity.js.map +1 -0
- package/definitions/systemEntity.d.ts +9 -0
- package/definitions/systemEntity.js +40 -0
- package/definitions/systemEntity.js.map +1 -0
- package/definitions/table.d.ts +9 -0
- package/definitions/table.js +24 -0
- package/definitions/table.js.map +1 -0
- package/definitions/tableElasticsearch.d.ts +9 -0
- package/definitions/tableElasticsearch.js +24 -0
- package/definitions/tableElasticsearch.js.map +1 -0
- package/elasticsearch/createElasticsearchIndex.d.ts +9 -0
- package/elasticsearch/createElasticsearchIndex.js +60 -0
- package/elasticsearch/createElasticsearchIndex.js.map +1 -0
- package/elasticsearch/indices/base.d.ts +2 -0
- package/elasticsearch/indices/base.js +15 -0
- package/elasticsearch/indices/base.js.map +1 -0
- package/elasticsearch/indices/index.d.ts +1 -0
- package/elasticsearch/indices/index.js +16 -0
- package/elasticsearch/indices/index.js.map +1 -0
- package/elasticsearch/indices/japanese.d.ts +2 -0
- package/elasticsearch/indices/japanese.js +16 -0
- package/elasticsearch/indices/japanese.js.map +1 -0
- package/index.d.ts +2 -0
- package/index.js +233 -0
- package/index.js.map +1 -0
- package/operations/blockCategory/dataLoader.d.ts +16 -0
- package/operations/blockCategory/dataLoader.js +79 -0
- package/operations/blockCategory/dataLoader.js.map +1 -0
- package/operations/blockCategory/fields.d.ts +2 -0
- package/operations/blockCategory/fields.js +28 -0
- package/operations/blockCategory/fields.js.map +1 -0
- package/operations/blockCategory/index.d.ts +8 -0
- package/operations/blockCategory/index.js +208 -0
- package/operations/blockCategory/index.js.map +1 -0
- package/operations/blockCategory/keys.d.ts +9 -0
- package/operations/blockCategory/keys.js +25 -0
- package/operations/blockCategory/keys.js.map +1 -0
- package/operations/category/dataLoader.d.ts +16 -0
- package/operations/category/dataLoader.js +79 -0
- package/operations/category/dataLoader.js.map +1 -0
- package/operations/category/fields.d.ts +2 -0
- package/operations/category/fields.js +28 -0
- package/operations/category/fields.js.map +1 -0
- package/operations/category/index.d.ts +8 -0
- package/operations/category/index.js +208 -0
- package/operations/category/index.js.map +1 -0
- package/operations/category/keys.d.ts +9 -0
- package/operations/category/keys.js +25 -0
- package/operations/category/keys.js.map +1 -0
- package/operations/menu/fields.d.ts +2 -0
- package/operations/menu/fields.js +27 -0
- package/operations/menu/fields.js.map +1 -0
- package/operations/menu/index.d.ts +8 -0
- package/operations/menu/index.js +217 -0
- package/operations/menu/index.js.map +1 -0
- package/operations/pageBlock/dataLoader.d.ts +16 -0
- package/operations/pageBlock/dataLoader.js +79 -0
- package/operations/pageBlock/dataLoader.js.map +1 -0
- package/operations/pageBlock/fields.d.ts +2 -0
- package/operations/pageBlock/fields.js +25 -0
- package/operations/pageBlock/fields.js.map +1 -0
- package/operations/pageBlock/index.d.ts +8 -0
- package/operations/pageBlock/index.js +208 -0
- package/operations/pageBlock/index.js.map +1 -0
- package/operations/pageBlock/keys.d.ts +9 -0
- package/operations/pageBlock/keys.js +25 -0
- package/operations/pageBlock/keys.js.map +1 -0
- package/operations/pageElement/fields.d.ts +2 -0
- package/operations/pageElement/fields.js +19 -0
- package/operations/pageElement/fields.js.map +1 -0
- package/operations/pageElement/index.d.ts +8 -0
- package/operations/pageElement/index.js +207 -0
- package/operations/pageElement/index.js.map +1 -0
- package/operations/pages/elasticsearchQueryBody.d.ts +12 -0
- package/operations/pages/elasticsearchQueryBody.js +237 -0
- package/operations/pages/elasticsearchQueryBody.js.map +1 -0
- package/operations/pages/fields.d.ts +4 -0
- package/operations/pages/fields.js +54 -0
- package/operations/pages/fields.js.map +1 -0
- package/operations/pages/helpers.d.ts +35 -0
- package/operations/pages/helpers.js +83 -0
- package/operations/pages/helpers.js.map +1 -0
- package/operations/pages/index.d.ts +11 -0
- package/operations/pages/index.js +829 -0
- package/operations/pages/index.js.map +1 -0
- package/operations/pages/keys.d.ts +24 -0
- package/operations/pages/keys.js +79 -0
- package/operations/pages/keys.js.map +1 -0
- package/operations/settings/index.d.ts +6 -0
- package/operations/settings/index.js +178 -0
- package/operations/settings/index.js.map +1 -0
- package/operations/system/index.d.ts +6 -0
- package/operations/system/index.js +104 -0
- package/operations/system/index.js.map +1 -0
- package/package.json +65 -0
- package/plugins/definitions/BlockCategoryDynamoDbElasticFieldPlugin.d.ts +4 -0
- package/plugins/definitions/BlockCategoryDynamoDbElasticFieldPlugin.js +17 -0
- package/plugins/definitions/BlockCategoryDynamoDbElasticFieldPlugin.js.map +1 -0
- package/plugins/definitions/CategoryDynamoDbElasticFieldPlugin.d.ts +4 -0
- package/plugins/definitions/CategoryDynamoDbElasticFieldPlugin.js +17 -0
- package/plugins/definitions/CategoryDynamoDbElasticFieldPlugin.js.map +1 -0
- package/plugins/definitions/IndexPageDataPlugin.d.ts +17 -0
- package/plugins/definitions/IndexPageDataPlugin.js +32 -0
- package/plugins/definitions/IndexPageDataPlugin.js.map +1 -0
- package/plugins/definitions/MenuDynamoDbElasticFieldPlugin.d.ts +4 -0
- package/plugins/definitions/MenuDynamoDbElasticFieldPlugin.js +17 -0
- package/plugins/definitions/MenuDynamoDbElasticFieldPlugin.js.map +1 -0
- package/plugins/definitions/PageBlockDynamoDbFieldPlugin.d.ts +4 -0
- package/plugins/definitions/PageBlockDynamoDbFieldPlugin.js +17 -0
- package/plugins/definitions/PageBlockDynamoDbFieldPlugin.js.map +1 -0
- package/plugins/definitions/PageDynamoDbElasticsearchFieldPlugin.d.ts +4 -0
- package/plugins/definitions/PageDynamoDbElasticsearchFieldPlugin.js +17 -0
- package/plugins/definitions/PageDynamoDbElasticsearchFieldPlugin.js.map +1 -0
- package/plugins/definitions/PageElasticsearchBodyModifierPlugin.d.ts +4 -0
- package/plugins/definitions/PageElasticsearchBodyModifierPlugin.js +17 -0
- package/plugins/definitions/PageElasticsearchBodyModifierPlugin.js.map +1 -0
- package/plugins/definitions/PageElasticsearchFieldPlugin.d.ts +4 -0
- package/plugins/definitions/PageElasticsearchFieldPlugin.js +17 -0
- package/plugins/definitions/PageElasticsearchFieldPlugin.js.map +1 -0
- package/plugins/definitions/PageElasticsearchIndexPlugin.d.ts +4 -0
- package/plugins/definitions/PageElasticsearchIndexPlugin.js +17 -0
- package/plugins/definitions/PageElasticsearchIndexPlugin.js.map +1 -0
- package/plugins/definitions/PageElasticsearchQueryModifierPlugin.d.ts +4 -0
- package/plugins/definitions/PageElasticsearchQueryModifierPlugin.js +17 -0
- package/plugins/definitions/PageElasticsearchQueryModifierPlugin.js.map +1 -0
- package/plugins/definitions/PageElasticsearchSortModifierPlugin.d.ts +4 -0
- package/plugins/definitions/PageElasticsearchSortModifierPlugin.js +17 -0
- package/plugins/definitions/PageElasticsearchSortModifierPlugin.js.map +1 -0
- package/plugins/definitions/PageElementDynamoDbElasticFieldPlugin.d.ts +4 -0
- package/plugins/definitions/PageElementDynamoDbElasticFieldPlugin.js +17 -0
- package/plugins/definitions/PageElementDynamoDbElasticFieldPlugin.js.map +1 -0
- package/plugins/definitions/SearchLatestPagesPlugin.d.ts +4 -0
- package/plugins/definitions/SearchLatestPagesPlugin.js +17 -0
- package/plugins/definitions/SearchLatestPagesPlugin.js.map +1 -0
- package/plugins/definitions/SearchPagesPlugin.d.ts +23 -0
- package/plugins/definitions/SearchPagesPlugin.js +39 -0
- package/plugins/definitions/SearchPagesPlugin.js.map +1 -0
- package/plugins/definitions/SearchPublishedPagesPlugin.d.ts +4 -0
- package/plugins/definitions/SearchPublishedPagesPlugin.js +17 -0
- package/plugins/definitions/SearchPublishedPagesPlugin.js.map +1 -0
- package/types.d.ts +39 -0
- package/types.js +20 -0
- package/types.js.map +1 -0
- package/upgrades/index.d.ts +2 -0
- package/upgrades/index.js +14 -0
- package/upgrades/index.js.map +1 -0
- package/upgrades/v5.15.0/category.d.ts +2 -0
- package/upgrades/v5.15.0/category.js +73 -0
- package/upgrades/v5.15.0/category.js.map +1 -0
- package/upgrades/v5.15.0/index.d.ts +4 -0
- package/upgrades/v5.15.0/index.js +52 -0
- package/upgrades/v5.15.0/index.js.map +1 -0
- package/upgrades/v5.15.0/menu.d.ts +2 -0
- package/upgrades/v5.15.0/menu.js +73 -0
- package/upgrades/v5.15.0/menu.js.map +1 -0
- package/upgrades/v5.15.0/pageElement.d.ts +2 -0
- package/upgrades/v5.15.0/pageElement.js +73 -0
- package/upgrades/v5.15.0/pageElement.js.map +1 -0
|
@@ -0,0 +1,217 @@
|
|
|
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.createMenuStorageOperations = void 0;
|
|
9
|
+
|
|
10
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
11
|
+
|
|
12
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
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 _MenuDynamoDbElasticFieldPlugin = require("../../plugins/definitions/MenuDynamoDbElasticFieldPlugin");
|
|
27
|
+
|
|
28
|
+
const _excluded = ["tenant", "locale"];
|
|
29
|
+
|
|
30
|
+
const createPartitionKey = params => {
|
|
31
|
+
const {
|
|
32
|
+
tenant,
|
|
33
|
+
locale
|
|
34
|
+
} = params;
|
|
35
|
+
return `T#${tenant}#L#${locale}#PB#M`;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const createSortKey = params => {
|
|
39
|
+
const {
|
|
40
|
+
slug
|
|
41
|
+
} = params;
|
|
42
|
+
return slug;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const createType = () => {
|
|
46
|
+
return "pb.menu";
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const createMenuStorageOperations = ({
|
|
50
|
+
entity,
|
|
51
|
+
plugins
|
|
52
|
+
}) => {
|
|
53
|
+
const get = async params => {
|
|
54
|
+
const {
|
|
55
|
+
where
|
|
56
|
+
} = params;
|
|
57
|
+
const keys = {
|
|
58
|
+
PK: createPartitionKey(where),
|
|
59
|
+
SK: createSortKey(where)
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
const result = await entity.get(keys);
|
|
64
|
+
|
|
65
|
+
if (!result || !result.Item) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return (0, _cleanup.cleanupItem)(entity, result.Item);
|
|
70
|
+
} catch (ex) {
|
|
71
|
+
throw new _error.default(ex.message || "Could not load menu by given parameters.", ex.code || "MENU_GET_ERROR", {
|
|
72
|
+
where
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const create = async params => {
|
|
78
|
+
const {
|
|
79
|
+
menu
|
|
80
|
+
} = params;
|
|
81
|
+
const keys = {
|
|
82
|
+
PK: createPartitionKey({
|
|
83
|
+
tenant: menu.tenant,
|
|
84
|
+
locale: menu.locale
|
|
85
|
+
}),
|
|
86
|
+
SK: createSortKey(menu)
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, menu), {}, {
|
|
91
|
+
TYPE: createType()
|
|
92
|
+
}, keys));
|
|
93
|
+
return menu;
|
|
94
|
+
} catch (ex) {
|
|
95
|
+
throw new _error.default(ex.message || "Could not create menu.", ex.code || "MENU_CREATE_ERROR", {
|
|
96
|
+
keys,
|
|
97
|
+
menu
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const update = async params => {
|
|
103
|
+
const {
|
|
104
|
+
menu,
|
|
105
|
+
original
|
|
106
|
+
} = params;
|
|
107
|
+
const keys = {
|
|
108
|
+
PK: createPartitionKey({
|
|
109
|
+
tenant: menu.tenant,
|
|
110
|
+
locale: menu.locale
|
|
111
|
+
}),
|
|
112
|
+
SK: createSortKey(menu)
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
try {
|
|
116
|
+
await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, menu), {}, {
|
|
117
|
+
TYPE: createType()
|
|
118
|
+
}, keys));
|
|
119
|
+
return menu;
|
|
120
|
+
} catch (ex) {
|
|
121
|
+
throw new _error.default(ex.message || "Could not update menu.", ex.code || "MENU_UPDATE_ERROR", {
|
|
122
|
+
keys,
|
|
123
|
+
original,
|
|
124
|
+
menu
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const list = async params => {
|
|
130
|
+
const {
|
|
131
|
+
where,
|
|
132
|
+
sort,
|
|
133
|
+
limit = 10
|
|
134
|
+
} = params;
|
|
135
|
+
const {
|
|
136
|
+
tenant,
|
|
137
|
+
locale
|
|
138
|
+
} = where,
|
|
139
|
+
restWhere = (0, _objectWithoutProperties2.default)(where, _excluded);
|
|
140
|
+
const queryAllParams = {
|
|
141
|
+
entity,
|
|
142
|
+
partitionKey: createPartitionKey({
|
|
143
|
+
tenant,
|
|
144
|
+
locale
|
|
145
|
+
}),
|
|
146
|
+
options: {
|
|
147
|
+
limit: limit || undefined,
|
|
148
|
+
gt: " "
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
let items = [];
|
|
152
|
+
|
|
153
|
+
try {
|
|
154
|
+
items = await (0, _query.queryAll)(queryAllParams);
|
|
155
|
+
} catch (ex) {
|
|
156
|
+
throw new _error.default(ex.message || "Could not list menus by given parameters.", ex.code || "MENUS_LIST_ERROR", {
|
|
157
|
+
partitionKey: queryAllParams.partitionKey,
|
|
158
|
+
options: queryAllParams.options
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const fields = plugins.byType(_MenuDynamoDbElasticFieldPlugin.MenuDynamoDbElasticFieldPlugin.type);
|
|
163
|
+
const filteredItems = (0, _filter.filterItems)({
|
|
164
|
+
plugins,
|
|
165
|
+
where: restWhere,
|
|
166
|
+
items,
|
|
167
|
+
fields
|
|
168
|
+
}).map(item => {
|
|
169
|
+
return (0, _cleanup.cleanupItem)(entity, item);
|
|
170
|
+
});
|
|
171
|
+
const sortedItems = (0, _sort.sortItems)({
|
|
172
|
+
items: filteredItems,
|
|
173
|
+
sort,
|
|
174
|
+
fields ///: ["createdOn", "id", "title", "slug"]
|
|
175
|
+
|
|
176
|
+
});
|
|
177
|
+
return (0, _listResponse.createListResponse)({
|
|
178
|
+
items: sortedItems,
|
|
179
|
+
limit,
|
|
180
|
+
totalCount: filteredItems.length,
|
|
181
|
+
after: null
|
|
182
|
+
});
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
const deleteMenu = async params => {
|
|
186
|
+
const {
|
|
187
|
+
menu
|
|
188
|
+
} = params;
|
|
189
|
+
const keys = {
|
|
190
|
+
PK: createPartitionKey({
|
|
191
|
+
tenant: menu.tenant,
|
|
192
|
+
locale: menu.locale
|
|
193
|
+
}),
|
|
194
|
+
SK: createSortKey(menu)
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
try {
|
|
198
|
+
await entity.delete((0, _objectSpread2.default)((0, _objectSpread2.default)({}, menu), keys));
|
|
199
|
+
return menu;
|
|
200
|
+
} catch (ex) {
|
|
201
|
+
throw new _error.default(ex.message || "Could not delete menu.", ex.code || "MENU_DELETE_ERROR", {
|
|
202
|
+
keys,
|
|
203
|
+
menu
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
return {
|
|
209
|
+
get,
|
|
210
|
+
create,
|
|
211
|
+
update,
|
|
212
|
+
list,
|
|
213
|
+
delete: deleteMenu
|
|
214
|
+
};
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
exports.createMenuStorageOperations = createMenuStorageOperations;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createPartitionKey","params","tenant","locale","createSortKey","slug","createType","createMenuStorageOperations","entity","plugins","get","where","keys","PK","SK","result","Item","cleanupItem","ex","WebinyError","message","code","create","menu","put","TYPE","update","original","list","sort","limit","restWhere","queryAllParams","partitionKey","options","undefined","gt","items","queryAll","fields","byType","MenuDynamoDbElasticFieldPlugin","type","filteredItems","filterItems","map","item","sortedItems","sortItems","createListResponse","totalCount","length","after","deleteMenu","delete"],"sources":["index.ts"],"sourcesContent":["import {\n Menu,\n MenuStorageOperations,\n MenuStorageOperationsCreateParams,\n MenuStorageOperationsDeleteParams,\n MenuStorageOperationsGetParams,\n MenuStorageOperationsListParams,\n MenuStorageOperationsUpdateParams\n} from \"@webiny/api-page-builder/types\";\nimport { Entity } from \"dynamodb-toolbox\";\nimport WebinyError from \"@webiny/error\";\nimport { cleanupItem } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { queryAll, QueryAllParams } from \"@webiny/db-dynamodb/utils/query\";\nimport { filterItems } from \"@webiny/db-dynamodb/utils/filter\";\nimport { sortItems } from \"@webiny/db-dynamodb/utils/sort\";\nimport { createListResponse } from \"@webiny/db-dynamodb/utils/listResponse\";\nimport { MenuDynamoDbElasticFieldPlugin } from \"~/plugins/definitions/MenuDynamoDbElasticFieldPlugin\";\nimport { PluginsContainer } from \"@webiny/plugins\";\n\ninterface PartitionKeyParams {\n tenant: string;\n locale: string;\n}\nconst createPartitionKey = (params: PartitionKeyParams): string => {\n const { tenant, locale } = params;\n return `T#${tenant}#L#${locale}#PB#M`;\n};\n\ninterface SortKeyParams {\n slug: string;\n}\nconst createSortKey = (params: SortKeyParams): string => {\n const { slug } = params;\n return slug;\n};\n\nconst createType = (): string => {\n return \"pb.menu\";\n};\n\nexport interface CreateMenuStorageOperationsParams {\n entity: Entity<any>;\n plugins: PluginsContainer;\n}\nexport const createMenuStorageOperations = ({\n entity,\n plugins\n}: CreateMenuStorageOperationsParams): MenuStorageOperations => {\n const get = async (params: MenuStorageOperationsGetParams) => {\n const { where } = params;\n const keys = {\n PK: createPartitionKey(where),\n SK: createSortKey(where)\n };\n\n try {\n const result = await entity.get(keys);\n if (!result || !result.Item) {\n return null;\n }\n return cleanupItem(entity, result.Item);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not load menu by given parameters.\",\n ex.code || \"MENU_GET_ERROR\",\n {\n where\n }\n );\n }\n };\n\n const create = async (params: MenuStorageOperationsCreateParams) => {\n const { menu } = params;\n const keys = {\n PK: createPartitionKey({\n tenant: menu.tenant,\n locale: menu.locale\n }),\n SK: createSortKey(menu)\n };\n\n try {\n await entity.put({\n ...menu,\n TYPE: createType(),\n ...keys\n });\n return menu;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create menu.\",\n ex.code || \"MENU_CREATE_ERROR\",\n {\n keys,\n menu\n }\n );\n }\n };\n\n const update = async (params: MenuStorageOperationsUpdateParams) => {\n const { menu, original } = params;\n const keys = {\n PK: createPartitionKey({\n tenant: menu.tenant,\n locale: menu.locale\n }),\n SK: createSortKey(menu)\n };\n\n try {\n await entity.put({\n ...menu,\n TYPE: createType(),\n ...keys\n });\n return menu;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update menu.\",\n ex.code || \"MENU_UPDATE_ERROR\",\n {\n keys,\n original,\n menu\n }\n );\n }\n };\n\n const list = async (params: MenuStorageOperationsListParams) => {\n const { where, sort, limit = 10 } = params;\n\n const { tenant, locale, ...restWhere } = where;\n const queryAllParams: QueryAllParams = {\n entity,\n partitionKey: createPartitionKey({\n tenant,\n locale\n }),\n options: {\n limit: limit || undefined,\n gt: \" \"\n }\n };\n\n let items: Menu[] = [];\n\n try {\n items = await queryAll<Menu>(queryAllParams);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not list menus by given parameters.\",\n ex.code || \"MENUS_LIST_ERROR\",\n {\n partitionKey: queryAllParams.partitionKey,\n options: queryAllParams.options\n }\n );\n }\n\n const fields = plugins.byType<MenuDynamoDbElasticFieldPlugin>(\n MenuDynamoDbElasticFieldPlugin.type\n );\n\n const filteredItems = filterItems<Menu>({\n plugins,\n where: restWhere,\n items,\n fields\n }).map(item => {\n return cleanupItem<Menu>(entity, item);\n }) as Menu[];\n\n const sortedItems = sortItems<Menu>({\n items: filteredItems,\n sort,\n fields\n ///: [\"createdOn\", \"id\", \"title\", \"slug\"]\n });\n\n return createListResponse({\n items: sortedItems,\n limit,\n totalCount: filteredItems.length,\n after: null\n });\n };\n\n const deleteMenu = async (params: MenuStorageOperationsDeleteParams) => {\n const { menu } = params;\n const keys = {\n PK: createPartitionKey({\n tenant: menu.tenant,\n locale: menu.locale\n }),\n SK: createSortKey(menu)\n };\n\n try {\n await entity.delete({\n ...menu,\n ...keys\n });\n return menu;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete menu.\",\n ex.code || \"MENU_DELETE_ERROR\",\n {\n keys,\n menu\n }\n );\n }\n };\n\n return {\n get,\n create,\n update,\n list,\n delete: deleteMenu\n };\n};\n"],"mappings":";;;;;;;;;;;;;AAUA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;AAOA,MAAMA,kBAAkB,GAAIC,MAAD,IAAwC;EAC/D,MAAM;IAAEC,MAAF;IAAUC;EAAV,IAAqBF,MAA3B;EACA,OAAQ,KAAIC,MAAO,MAAKC,MAAO,OAA/B;AACH,CAHD;;AAQA,MAAMC,aAAa,GAAIH,MAAD,IAAmC;EACrD,MAAM;IAAEI;EAAF,IAAWJ,MAAjB;EACA,OAAOI,IAAP;AACH,CAHD;;AAKA,MAAMC,UAAU,GAAG,MAAc;EAC7B,OAAO,SAAP;AACH,CAFD;;AAQO,MAAMC,2BAA2B,GAAG,CAAC;EACxCC,MADwC;EAExCC;AAFwC,CAAD,KAGqB;EAC5D,MAAMC,GAAG,GAAG,MAAOT,MAAP,IAAkD;IAC1D,MAAM;MAAEU;IAAF,IAAYV,MAAlB;IACA,MAAMW,IAAI,GAAG;MACTC,EAAE,EAAEb,kBAAkB,CAACW,KAAD,CADb;MAETG,EAAE,EAAEV,aAAa,CAACO,KAAD;IAFR,CAAb;;IAKA,IAAI;MACA,MAAMI,MAAM,GAAG,MAAMP,MAAM,CAACE,GAAP,CAAWE,IAAX,CAArB;;MACA,IAAI,CAACG,MAAD,IAAW,CAAC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M"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { PageBlock } from "@webiny/api-page-builder/types";
|
|
2
|
+
import { Entity } from "dynamodb-toolbox";
|
|
3
|
+
interface Params {
|
|
4
|
+
entity: Entity<any>;
|
|
5
|
+
}
|
|
6
|
+
declare type DataLoaderGetItem = Pick<PageBlock, "id" | "tenant" | "locale">;
|
|
7
|
+
export declare class PageBlockDataLoader {
|
|
8
|
+
private _getDataLoader;
|
|
9
|
+
private readonly entity;
|
|
10
|
+
constructor(params: Params);
|
|
11
|
+
getOne(item: DataLoaderGetItem): Promise<PageBlock>;
|
|
12
|
+
getAll(items: DataLoaderGetItem[]): Promise<PageBlock[]>;
|
|
13
|
+
clear(): void;
|
|
14
|
+
private getDataLoader;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,79 @@
|
|
|
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.PageBlockDataLoader = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _dataloader = _interopRequireDefault(require("dataloader"));
|
|
13
|
+
|
|
14
|
+
var _batchRead = require("@webiny/db-dynamodb/utils/batchRead");
|
|
15
|
+
|
|
16
|
+
var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
17
|
+
|
|
18
|
+
var _keys = require("./keys");
|
|
19
|
+
|
|
20
|
+
class PageBlockDataLoader {
|
|
21
|
+
constructor(params) {
|
|
22
|
+
(0, _defineProperty2.default)(this, "_getDataLoader", undefined);
|
|
23
|
+
(0, _defineProperty2.default)(this, "entity", void 0);
|
|
24
|
+
this.entity = params.entity;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async getOne(item) {
|
|
28
|
+
return await this.getDataLoader().load(item);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async getAll(items) {
|
|
32
|
+
return await this.getDataLoader().loadMany(items);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
clear() {
|
|
36
|
+
this.getDataLoader().clearAll();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
getDataLoader() {
|
|
40
|
+
if (!this._getDataLoader) {
|
|
41
|
+
const cacheKeyFn = key => {
|
|
42
|
+
return `T#${key.tenant}#L#${key.locale}#${key.id}`;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
this._getDataLoader = new _dataloader.default(async items => {
|
|
46
|
+
const batched = items.map(item => {
|
|
47
|
+
return this.entity.getBatch({
|
|
48
|
+
PK: (0, _keys.createPartitionKey)(item),
|
|
49
|
+
SK: (0, _keys.createSortKey)(item)
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
const records = await (0, _batchRead.batchReadAll)({
|
|
53
|
+
table: this.entity.table,
|
|
54
|
+
items: batched
|
|
55
|
+
});
|
|
56
|
+
const results = records.reduce((collection, result) => {
|
|
57
|
+
if (!result) {
|
|
58
|
+
return collection;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const key = cacheKeyFn(result);
|
|
62
|
+
collection[key] = (0, _cleanup.cleanupItem)(this.entity, result);
|
|
63
|
+
return collection;
|
|
64
|
+
}, {});
|
|
65
|
+
return items.map(item => {
|
|
66
|
+
const key = cacheKeyFn(item);
|
|
67
|
+
return results[key] || null;
|
|
68
|
+
});
|
|
69
|
+
}, {
|
|
70
|
+
cacheKeyFn
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return this._getDataLoader;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
exports.PageBlockDataLoader = PageBlockDataLoader;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["PageBlockDataLoader","constructor","params","undefined","entity","getOne","item","getDataLoader","load","getAll","items","loadMany","clear","clearAll","_getDataLoader","cacheKeyFn","key","tenant","locale","id","DataLoader","batched","map","getBatch","PK","createPartitionKey","SK","createSortKey","records","batchReadAll","table","results","reduce","collection","result","cleanupItem"],"sources":["dataLoader.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport { batchReadAll } from \"@webiny/db-dynamodb/utils/batchRead\";\nimport { PageBlock } from \"@webiny/api-page-builder/types\";\nimport { cleanupItem } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { Entity } from \"dynamodb-toolbox\";\nimport { createPartitionKey, createSortKey } from \"./keys\";\n\ninterface Params {\n entity: Entity<any>;\n}\n\ntype DataLoaderGetItem = Pick<PageBlock, \"id\" | \"tenant\" | \"locale\">;\n\nexport class PageBlockDataLoader {\n private _getDataLoader: DataLoader<any, any> | undefined = undefined;\n\n private readonly entity: Entity<any>;\n\n constructor(params: Params) {\n this.entity = params.entity;\n }\n\n public async getOne(item: DataLoaderGetItem): Promise<PageBlock> {\n return await this.getDataLoader().load(item);\n }\n\n public async getAll(items: DataLoaderGetItem[]): Promise<PageBlock[]> {\n return await this.getDataLoader().loadMany(items);\n }\n\n public clear(): void {\n this.getDataLoader().clearAll();\n }\n\n private getDataLoader() {\n if (!this._getDataLoader) {\n const cacheKeyFn = (key: DataLoaderGetItem) => {\n return `T#${key.tenant}#L#${key.locale}#${key.id}`;\n };\n this._getDataLoader = new DataLoader(\n async items => {\n const batched = items.map(item => {\n return this.entity.getBatch({\n PK: createPartitionKey(item),\n SK: createSortKey(item)\n });\n });\n\n const records = await batchReadAll<PageBlock>({\n table: this.entity.table,\n items: batched\n });\n\n const results = records.reduce((collection, result) => {\n if (!result) {\n return collection;\n }\n const key = cacheKeyFn(result);\n collection[key] = cleanupItem(this.entity, result) as PageBlock;\n return collection;\n }, {} as Record<string, PageBlock>);\n return items.map(item => {\n const key = cacheKeyFn(item);\n return results[key] || null;\n });\n },\n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CAACI,MAAR,CAAe,CAACC,UAAD,EAAaC,MAAb,KAAwB;UACnD,IAAI,CAACA,MAAL,EAAa;YACT,OAAOD,UAAP;UACH;;UACD,MAAMjB,GAAG,GAAGD,UAAU,CAACmB,MAAD,CAAtB;UACAD,UAAU,CAACjB,GAAD,CAAV,GAAkB,IAAAmB,oBAAA,EAAY,KAAK/B,MAAjB,EAAyB8B,MAAzB,CAAlB;UACA,OAAOD,UAAP;QACH,CAPe,EAOb,EAPa,CAAhB;QAQA,OAAOvB,KAAK,CAACY,GAAN,CAAUhB,IAAI,IAAI;UACrB,MAAMU,GAAG,GAAGD,UAAU,CAACT,IAAD,CAAtB;UACA,OAAOyB,OAAO,CAACf,GAAD,CAAP,IAAgB,IAAvB;QACH,CAHM,CAAP;MAIH,CA1BiB,EA2BlB;QACID;MADJ,CA3BkB,CAAtB;IA+BH;;IACD,OAAO,KAAKD,cAAZ;EACH;;AA3D4B"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createPageBlockDynamoDbFields = void 0;
|
|
7
|
+
|
|
8
|
+
var _PageBlockDynamoDbFieldPlugin = require("../../plugins/definitions/PageBlockDynamoDbFieldPlugin");
|
|
9
|
+
|
|
10
|
+
const createPageBlockDynamoDbFields = () => {
|
|
11
|
+
return [new _PageBlockDynamoDbFieldPlugin.PageBlockDynamoDbFieldPlugin({
|
|
12
|
+
field: "id"
|
|
13
|
+
}), new _PageBlockDynamoDbFieldPlugin.PageBlockDynamoDbFieldPlugin({
|
|
14
|
+
field: "createdOn",
|
|
15
|
+
type: "date"
|
|
16
|
+
}), new _PageBlockDynamoDbFieldPlugin.PageBlockDynamoDbFieldPlugin({
|
|
17
|
+
field: "savedOn",
|
|
18
|
+
type: "date"
|
|
19
|
+
}), new _PageBlockDynamoDbFieldPlugin.PageBlockDynamoDbFieldPlugin({
|
|
20
|
+
field: "createdBy",
|
|
21
|
+
path: "createdBy.id"
|
|
22
|
+
})];
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
exports.createPageBlockDynamoDbFields = createPageBlockDynamoDbFields;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createPageBlockDynamoDbFields","PageBlockDynamoDbFieldPlugin","field","type","path"],"sources":["fields.ts"],"sourcesContent":["import { PageBlockDynamoDbFieldPlugin } from \"~/plugins/definitions/PageBlockDynamoDbFieldPlugin\";\n\nexport const createPageBlockDynamoDbFields = (): PageBlockDynamoDbFieldPlugin[] => {\n return [\n new PageBlockDynamoDbFieldPlugin({\n field: \"id\"\n }),\n new PageBlockDynamoDbFieldPlugin({\n field: \"createdOn\",\n type: \"date\"\n }),\n new PageBlockDynamoDbFieldPlugin({\n field: \"savedOn\",\n type: \"date\"\n }),\n new PageBlockDynamoDbFieldPlugin({\n field: \"createdBy\",\n path: \"createdBy.id\"\n })\n ];\n};\n"],"mappings":";;;;;;;AAAA;;AAEO,MAAMA,6BAA6B,GAAG,MAAsC;EAC/E,OAAO,CACH,IAAIC,0DAAJ,CAAiC;IAC7BC,KAAK,EAAE;EADsB,CAAjC,CADG,EAIH,IAAID,0DAAJ,CAAiC;IAC7BC,KAAK,EAAE,WADsB;IAE7BC,IAAI,EAAE;EAFuB,CAAjC,CAJG,EAQH,IAAIF,0DAAJ,CAAiC;IAC7BC,KAAK,EAAE,SADsB;IAE7BC,IAAI,EAAE;EAFuB,CAAjC,CARG,EAYH,IAAIF,0DAAJ,CAAiC;IAC7BC,KAAK,EAAE,WADsB;IAE7BE,IAAI,EAAE;EAFuB,CAAjC,CAZG,CAAP;AAiBH,CAlBM"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PageBlockStorageOperations } from "@webiny/api-page-builder/types";
|
|
2
|
+
import { Entity } from "dynamodb-toolbox";
|
|
3
|
+
import { PluginsContainer } from "@webiny/plugins";
|
|
4
|
+
export interface CreatePageBlockStorageOperationsParams {
|
|
5
|
+
entity: Entity<any>;
|
|
6
|
+
plugins: PluginsContainer;
|
|
7
|
+
}
|
|
8
|
+
export declare const createPageBlockStorageOperations: ({ entity, plugins }: CreatePageBlockStorageOperationsParams) => PageBlockStorageOperations;
|
|
@@ -0,0 +1,208 @@
|
|
|
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.createPageBlockStorageOperations = void 0;
|
|
9
|
+
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
+
|
|
12
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
13
|
+
|
|
14
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
15
|
+
|
|
16
|
+
var _query = require("@webiny/db-dynamodb/utils/query");
|
|
17
|
+
|
|
18
|
+
var _sort = require("@webiny/db-dynamodb/utils/sort");
|
|
19
|
+
|
|
20
|
+
var _filter = require("@webiny/db-dynamodb/utils/filter");
|
|
21
|
+
|
|
22
|
+
var _dataLoader = require("./dataLoader");
|
|
23
|
+
|
|
24
|
+
var _listResponse = require("@webiny/db-dynamodb/utils/listResponse");
|
|
25
|
+
|
|
26
|
+
var _PageBlockDynamoDbFieldPlugin = require("../../plugins/definitions/PageBlockDynamoDbFieldPlugin");
|
|
27
|
+
|
|
28
|
+
var _keys = require("./keys");
|
|
29
|
+
|
|
30
|
+
const _excluded = ["tenant", "locale"];
|
|
31
|
+
|
|
32
|
+
const createType = () => {
|
|
33
|
+
return "pb.pageBlock";
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const createPageBlockStorageOperations = ({
|
|
37
|
+
entity,
|
|
38
|
+
plugins
|
|
39
|
+
}) => {
|
|
40
|
+
const dataLoader = new _dataLoader.PageBlockDataLoader({
|
|
41
|
+
entity
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const get = async params => {
|
|
45
|
+
const {
|
|
46
|
+
where
|
|
47
|
+
} = params;
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
return await dataLoader.getOne(where);
|
|
51
|
+
} catch (ex) {
|
|
52
|
+
throw new _error.default(ex.message || "Could not load page block by given parameters.", ex.code || "PAGE_BLOCK_GET_ERROR", {
|
|
53
|
+
where
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const list = async params => {
|
|
59
|
+
const {
|
|
60
|
+
where,
|
|
61
|
+
sort,
|
|
62
|
+
limit
|
|
63
|
+
} = params;
|
|
64
|
+
const {
|
|
65
|
+
tenant,
|
|
66
|
+
locale
|
|
67
|
+
} = where,
|
|
68
|
+
restWhere = (0, _objectWithoutProperties2.default)(where, _excluded);
|
|
69
|
+
const queryAllParams = {
|
|
70
|
+
entity,
|
|
71
|
+
partitionKey: (0, _keys.createPartitionKey)({
|
|
72
|
+
tenant,
|
|
73
|
+
locale
|
|
74
|
+
}),
|
|
75
|
+
options: {
|
|
76
|
+
gt: " "
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
let items = [];
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
items = await (0, _query.queryAll)(queryAllParams);
|
|
83
|
+
} catch (ex) {
|
|
84
|
+
throw new _error.default(ex.message || "Could not list page blocks by given parameters.", ex.code || "PAGE_BLOCK_LIST_ERROR", {
|
|
85
|
+
partitionKey: queryAllParams.partitionKey,
|
|
86
|
+
options: queryAllParams.options
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const fields = plugins.byType(_PageBlockDynamoDbFieldPlugin.PageBlockDynamoDbFieldPlugin.type);
|
|
91
|
+
const filteredItems = (0, _filter.filterItems)({
|
|
92
|
+
plugins,
|
|
93
|
+
where: restWhere,
|
|
94
|
+
items,
|
|
95
|
+
fields
|
|
96
|
+
});
|
|
97
|
+
const sortedItems = (0, _sort.sortItems)({
|
|
98
|
+
items: filteredItems,
|
|
99
|
+
sort,
|
|
100
|
+
fields
|
|
101
|
+
});
|
|
102
|
+
return (0, _listResponse.createListResponse)({
|
|
103
|
+
items: sortedItems,
|
|
104
|
+
limit: limit || 100000,
|
|
105
|
+
totalCount: filteredItems.length,
|
|
106
|
+
after: null
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const create = async params => {
|
|
111
|
+
const {
|
|
112
|
+
pageBlock
|
|
113
|
+
} = params;
|
|
114
|
+
const keys = {
|
|
115
|
+
PK: (0, _keys.createPartitionKey)({
|
|
116
|
+
tenant: pageBlock.tenant,
|
|
117
|
+
locale: pageBlock.locale
|
|
118
|
+
}),
|
|
119
|
+
SK: (0, _keys.createSortKey)(pageBlock)
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
try {
|
|
123
|
+
await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, pageBlock), {}, {
|
|
124
|
+
TYPE: createType()
|
|
125
|
+
}, keys));
|
|
126
|
+
/**
|
|
127
|
+
* Always clear data loader cache when modifying the records.
|
|
128
|
+
*/
|
|
129
|
+
|
|
130
|
+
dataLoader.clear();
|
|
131
|
+
return pageBlock;
|
|
132
|
+
} catch (ex) {
|
|
133
|
+
throw new _error.default(ex.message || "Could not create page block.", ex.code || "PAGE_BLOCK_CREATE_ERROR", {
|
|
134
|
+
keys
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const update = async params => {
|
|
140
|
+
const {
|
|
141
|
+
original,
|
|
142
|
+
pageBlock
|
|
143
|
+
} = params;
|
|
144
|
+
const keys = {
|
|
145
|
+
PK: (0, _keys.createPartitionKey)({
|
|
146
|
+
tenant: original.tenant,
|
|
147
|
+
locale: original.locale
|
|
148
|
+
}),
|
|
149
|
+
SK: (0, _keys.createSortKey)(pageBlock)
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
try {
|
|
153
|
+
await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, pageBlock), {}, {
|
|
154
|
+
TYPE: createType()
|
|
155
|
+
}, keys));
|
|
156
|
+
/**
|
|
157
|
+
* Always clear data loader cache when modifying the records.
|
|
158
|
+
*/
|
|
159
|
+
|
|
160
|
+
dataLoader.clear();
|
|
161
|
+
return pageBlock;
|
|
162
|
+
} catch (ex) {
|
|
163
|
+
throw new _error.default(ex.message || "Could not update page block.", ex.code || "PAGE_BLOCK_UPDATE_ERROR", {
|
|
164
|
+
keys,
|
|
165
|
+
original,
|
|
166
|
+
pageBlock
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const deletePageBlock = async params => {
|
|
172
|
+
const {
|
|
173
|
+
pageBlock
|
|
174
|
+
} = params;
|
|
175
|
+
const keys = {
|
|
176
|
+
PK: (0, _keys.createPartitionKey)({
|
|
177
|
+
tenant: pageBlock.tenant,
|
|
178
|
+
locale: pageBlock.locale
|
|
179
|
+
}),
|
|
180
|
+
SK: (0, _keys.createSortKey)(pageBlock)
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
try {
|
|
184
|
+
await entity.delete((0, _objectSpread2.default)((0, _objectSpread2.default)({}, pageBlock), keys));
|
|
185
|
+
/**
|
|
186
|
+
* Always clear data loader cache when modifying the records.
|
|
187
|
+
*/
|
|
188
|
+
|
|
189
|
+
dataLoader.clear();
|
|
190
|
+
return pageBlock;
|
|
191
|
+
} catch (ex) {
|
|
192
|
+
throw new _error.default(ex.message || "Could not delete page block.", ex.code || "PAGE_BLOCK_DELETE_ERROR", {
|
|
193
|
+
keys,
|
|
194
|
+
pageBlock
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
return {
|
|
200
|
+
get,
|
|
201
|
+
list,
|
|
202
|
+
create,
|
|
203
|
+
update,
|
|
204
|
+
delete: deletePageBlock
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
exports.createPageBlockStorageOperations = createPageBlockStorageOperations;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createType","createPageBlockStorageOperations","entity","plugins","dataLoader","PageBlockDataLoader","get","params","where","getOne","ex","WebinyError","message","code","list","sort","limit","tenant","locale","restWhere","queryAllParams","partitionKey","createPartitionKey","options","gt","items","queryAll","fields","byType","PageBlockDynamoDbFieldPlugin","type","filteredItems","filterItems","sortedItems","sortItems","createListResponse","totalCount","length","after","create","pageBlock","keys","PK","SK","createSortKey","put","TYPE","clear","update","original","deletePageBlock","delete"],"sources":["index.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport {\n PageBlock,\n PageBlockStorageOperations,\n PageBlockStorageOperationsCreateParams,\n PageBlockStorageOperationsDeleteParams,\n PageBlockStorageOperationsGetParams,\n PageBlockStorageOperationsListParams,\n PageBlockStorageOperationsUpdateParams\n} from \"@webiny/api-page-builder/types\";\nimport { Entity } from \"dynamodb-toolbox\";\nimport { queryAll, QueryAllParams } from \"@webiny/db-dynamodb/utils/query\";\nimport { sortItems } from \"@webiny/db-dynamodb/utils/sort\";\nimport { filterItems } from \"@webiny/db-dynamodb/utils/filter\";\nimport { PageBlockDataLoader } from \"./dataLoader\";\nimport { createListResponse } from \"@webiny/db-dynamodb/utils/listResponse\";\nimport { PageBlockDynamoDbFieldPlugin } from \"~/plugins/definitions/PageBlockDynamoDbFieldPlugin\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { createPartitionKey, createSortKey } from \"./keys\";\n\nconst createType = (): string => {\n return \"pb.pageBlock\";\n};\n\nexport interface CreatePageBlockStorageOperationsParams {\n entity: Entity<any>;\n plugins: PluginsContainer;\n}\nexport const createPageBlockStorageOperations = ({\n entity,\n plugins\n}: CreatePageBlockStorageOperationsParams): PageBlockStorageOperations => {\n const dataLoader = new PageBlockDataLoader({\n entity\n });\n\n const get = async (params: PageBlockStorageOperationsGetParams) => {\n const { where } = params;\n\n try {\n return await dataLoader.getOne(where);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not load page block by given parameters.\",\n ex.code || \"PAGE_BLOCK_GET_ERROR\",\n {\n where\n }\n );\n }\n };\n\n const list = async (params: PageBlockStorageOperationsListParams) => {\n const { where, sort, limit } = params;\n\n const { tenant, locale, ...restWhere } = where;\n const queryAllParams: QueryAllParams = {\n entity,\n partitionKey: createPartitionKey({ tenant, locale }),\n options: {\n gt: \" \"\n }\n };\n\n let items: PageBlock[] = [];\n\n try {\n items = await queryAll<PageBlock>(queryAllParams);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not list page blocks by given parameters.\",\n ex.code || \"PAGE_BLOCK_LIST_ERROR\",\n {\n partitionKey: queryAllParams.partitionKey,\n options: queryAllParams.options\n }\n );\n }\n\n const fields = plugins.byType<PageBlockDynamoDbFieldPlugin>(\n PageBlockDynamoDbFieldPlugin.type\n );\n\n const filteredItems = filterItems<PageBlock>({\n plugins,\n where: restWhere,\n items,\n fields\n });\n\n const sortedItems = sortItems<PageBlock>({\n items: filteredItems,\n sort,\n fields\n });\n\n return createListResponse({\n items: sortedItems,\n limit: limit || 100000,\n totalCount: filteredItems.length,\n after: null\n });\n };\n\n const create = async (params: PageBlockStorageOperationsCreateParams) => {\n const { pageBlock } = params;\n\n const keys = {\n PK: createPartitionKey({\n tenant: pageBlock.tenant,\n locale: pageBlock.locale\n }),\n SK: createSortKey(pageBlock)\n };\n\n try {\n await entity.put({\n ...pageBlock,\n TYPE: createType(),\n ...keys\n });\n /**\n * Always clear data loader cache when modifying the records.\n */\n dataLoader.clear();\n\n return pageBlock;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create page block.\",\n ex.code || \"PAGE_BLOCK_CREATE_ERROR\",\n {\n keys\n }\n );\n }\n };\n\n const update = async (params: PageBlockStorageOperationsUpdateParams) => {\n const { original, pageBlock } = params;\n const keys = {\n PK: createPartitionKey({\n tenant: original.tenant,\n locale: original.locale\n }),\n SK: createSortKey(pageBlock)\n };\n\n try {\n await entity.put({\n ...pageBlock,\n TYPE: createType(),\n ...keys\n });\n /**\n * Always clear data loader cache when modifying the records.\n */\n dataLoader.clear();\n\n return pageBlock;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update page block.\",\n ex.code || \"PAGE_BLOCK_UPDATE_ERROR\",\n {\n keys,\n original,\n pageBlock\n }\n );\n }\n };\n\n const deletePageBlock = async (params: PageBlockStorageOperationsDeleteParams) => {\n const { pageBlock } = params;\n const keys = {\n PK: createPartitionKey({\n tenant: pageBlock.tenant,\n locale: pageBlock.locale\n }),\n SK: createSortKey(pageBlock)\n };\n\n try {\n await entity.delete({\n ...pageBlock,\n ...keys\n });\n /**\n * Always clear data loader cache when modifying the records.\n */\n dataLoader.clear();\n\n return pageBlock;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete page block.\",\n ex.code || \"PAGE_BLOCK_DELETE_ERROR\",\n {\n keys,\n pageBlock\n }\n );\n }\n };\n\n return {\n get,\n list,\n create,\n update,\n delete: deletePageBlock\n };\n};\n"],"mappings":";;;;;;;;;;;;;AAAA;;AAWA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;AAEA,MAAMA,UAAU,GAAG,MAAc;EAC7B,OAAO,cAAP;AACH,CAFD;;AAQO,MAAMC,gCAAgC,GAAG,CAAC;EAC7CC,MAD6C;EAE7CC;AAF6C,CAAD,KAG0B;EACtE,MAAMC,UAAU,GAAG,IAAIC,+BAAJ,CAAwB;IACvCH;EADuC,CAAxB,CAAnB;;EAIA,MAAMI,GAAG,GAAG,MAAOC,MAAP,IAAuD;IAC/D,MAAM;MAAEC;IAAF,IAAYD,MAAlB;;IAEA,IAAI;MACA,OAAO,MAAMH,UAAU,CAACK,MAAX,CAAkBD,KAAlB,CAAb;IACH,CAFD,CAE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string;
|
|
4
|
+
}
|
|
5
|
+
export declare const createPartitionKey: (params: PartitionKeyParams) => string;
|
|
6
|
+
export interface SortKeyParams {
|
|
7
|
+
id: string;
|
|
8
|
+
}
|
|
9
|
+
export declare const createSortKey: (params: SortKeyParams) => string;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createSortKey = exports.createPartitionKey = void 0;
|
|
7
|
+
|
|
8
|
+
const createPartitionKey = params => {
|
|
9
|
+
const {
|
|
10
|
+
tenant,
|
|
11
|
+
locale
|
|
12
|
+
} = params;
|
|
13
|
+
return `T#${tenant}#L#${locale}#PB#B`;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
exports.createPartitionKey = createPartitionKey;
|
|
17
|
+
|
|
18
|
+
const createSortKey = params => {
|
|
19
|
+
const {
|
|
20
|
+
id
|
|
21
|
+
} = params;
|
|
22
|
+
return id;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
exports.createSortKey = createSortKey;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createPartitionKey","params","tenant","locale","createSortKey","id"],"sources":["keys.ts"],"sourcesContent":["export interface PartitionKeyParams {\n tenant: string;\n locale: string;\n}\nexport const createPartitionKey = (params: PartitionKeyParams): string => {\n const { tenant, locale } = params;\n return `T#${tenant}#L#${locale}#PB#B`;\n};\n\nexport interface SortKeyParams {\n id: string;\n}\nexport const createSortKey = (params: SortKeyParams): string => {\n const { id } = params;\n return id;\n};\n"],"mappings":";;;;;;;AAIO,MAAMA,kBAAkB,GAAIC,MAAD,IAAwC;EACtE,MAAM;IAAEC,MAAF;IAAUC;EAAV,IAAqBF,MAA3B;EACA,OAAQ,KAAIC,MAAO,MAAKC,MAAO,OAA/B;AACH,CAHM;;;;AAQA,MAAMC,aAAa,GAAIH,MAAD,IAAmC;EAC5D,MAAM;IAAEI;EAAF,IAASJ,MAAf;EACA,OAAOI,EAAP;AACH,CAHM"}
|