@webiny/api-page-builder-so-ddb-es 0.0.0-mt-2 → 0.0.0-unstable.06b2ede40f
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/configurations.d.ts +18 -0
- package/configurations.js +53 -0
- package/configurations.js.map +1 -0
- package/definitions/blockCategoryEntity.d.ts +10 -0
- package/definitions/blockCategoryEntity.js +57 -0
- package/definitions/blockCategoryEntity.js.map +1 -0
- package/definitions/categoryEntity.d.ts +10 -6
- package/definitions/categoryEntity.js +12 -23
- package/definitions/categoryEntity.js.map +1 -0
- package/definitions/menuEntity.d.ts +10 -6
- package/definitions/menuEntity.js +12 -23
- package/definitions/menuEntity.js.map +1 -0
- package/definitions/pageBlockEntity.d.ts +10 -0
- package/definitions/pageBlockEntity.js +74 -0
- package/definitions/pageBlockEntity.js.map +1 -0
- package/definitions/pageElasticsearchEntity.d.ts +10 -6
- package/definitions/pageElasticsearchEntity.js +15 -23
- package/definitions/pageElasticsearchEntity.js.map +1 -0
- package/definitions/pageElementEntity.d.ts +10 -6
- package/definitions/pageElementEntity.js +12 -23
- package/definitions/pageElementEntity.js.map +1 -0
- package/definitions/pageEntity.d.ts +10 -6
- package/definitions/pageEntity.js +20 -32
- package/definitions/pageEntity.js.map +1 -0
- package/definitions/pageTemplateEntity.d.ts +10 -0
- package/definitions/pageTemplateEntity.js +42 -0
- package/definitions/pageTemplateEntity.js.map +1 -0
- package/definitions/settingsEntity.d.ts +8 -6
- package/definitions/settingsEntity.js +11 -54
- package/definitions/settingsEntity.js.map +1 -0
- package/definitions/systemEntity.d.ts +10 -6
- package/definitions/systemEntity.js +15 -23
- package/definitions/systemEntity.js.map +1 -0
- package/definitions/table.d.ts +8 -5
- package/definitions/table.js +22 -21
- package/definitions/table.js.map +1 -0
- package/definitions/tableElasticsearch.d.ts +9 -5
- package/definitions/tableElasticsearch.js +16 -28
- package/definitions/tableElasticsearch.js.map +1 -0
- package/elasticsearch/createElasticsearchIndex.d.ts +9 -0
- package/elasticsearch/createElasticsearchIndex.js +41 -0
- package/elasticsearch/createElasticsearchIndex.js.map +1 -0
- package/elasticsearch/indices/base.d.ts +2 -0
- package/elasticsearch/indices/base.js +14 -0
- package/elasticsearch/indices/base.js.map +1 -0
- package/elasticsearch/indices/index.d.ts +1 -0
- package/elasticsearch/indices/index.js +14 -0
- package/elasticsearch/indices/index.js.map +1 -0
- package/elasticsearch/indices/japanese.d.ts +2 -0
- package/elasticsearch/indices/japanese.js +15 -0
- package/elasticsearch/indices/japanese.js.map +1 -0
- package/index.d.ts +3 -8
- package/index.js +246 -16
- package/index.js.map +1 -0
- package/operations/blockCategory/dataLoader.d.ts +17 -0
- package/operations/blockCategory/dataLoader.js +63 -0
- package/operations/blockCategory/dataLoader.js.map +1 -0
- package/operations/blockCategory/fields.d.ts +2 -0
- package/operations/blockCategory/fields.js +27 -0
- package/operations/blockCategory/fields.js.map +1 -0
- package/operations/blockCategory/index.d.ts +8 -0
- package/operations/blockCategory/index.js +192 -0
- package/operations/blockCategory/index.js.map +1 -0
- package/operations/blockCategory/keys.d.ts +9 -0
- package/operations/blockCategory/keys.js +23 -0
- package/operations/blockCategory/keys.js.map +1 -0
- package/operations/category/dataLoader.d.ts +17 -0
- package/operations/category/{CategoryDataLoader.js → dataLoader.js} +13 -27
- package/operations/category/dataLoader.js.map +1 -0
- package/operations/category/fields.d.ts +1 -2
- package/operations/category/fields.js +4 -5
- package/operations/category/fields.js.map +1 -0
- package/operations/category/index.d.ts +7 -4
- package/operations/category/index.js +185 -21
- package/operations/category/index.js.map +1 -0
- package/operations/category/keys.d.ts +9 -0
- package/operations/category/keys.js +23 -0
- package/operations/category/keys.js.map +1 -0
- package/operations/menu/fields.d.ts +1 -2
- package/operations/menu/fields.js +19 -18
- package/operations/menu/fields.js.map +1 -0
- package/operations/menu/index.d.ts +7 -4
- package/operations/menu/index.js +193 -21
- package/operations/menu/index.js.map +1 -0
- package/operations/pageBlock/compression.d.ts +18 -0
- package/operations/pageBlock/compression.js +42 -0
- package/operations/pageBlock/compression.js.map +1 -0
- package/operations/pageBlock/dataLoader.d.ts +17 -0
- package/operations/pageBlock/dataLoader.js +63 -0
- package/operations/pageBlock/dataLoader.js.map +1 -0
- package/operations/pageBlock/fields.d.ts +2 -0
- package/operations/pageBlock/fields.js +24 -0
- package/operations/pageBlock/fields.js.map +1 -0
- package/operations/pageBlock/index.d.ts +8 -0
- package/operations/pageBlock/index.js +219 -0
- package/operations/pageBlock/index.js.map +1 -0
- package/operations/pageBlock/keys.d.ts +20 -0
- package/operations/pageBlock/keys.js +37 -0
- package/operations/pageBlock/keys.js.map +1 -0
- package/operations/pageElement/fields.d.ts +1 -2
- package/operations/pageElement/fields.js +4 -5
- package/operations/pageElement/fields.js.map +1 -0
- package/operations/pageElement/index.d.ts +7 -6
- package/operations/pageElement/index.js +182 -21
- package/operations/pageElement/index.js.map +1 -0
- package/operations/pageTemplate/dataLoader.d.ts +17 -0
- package/operations/pageTemplate/dataLoader.js +62 -0
- package/operations/pageTemplate/dataLoader.js.map +1 -0
- package/operations/pageTemplate/fields.d.ts +2 -0
- package/operations/pageTemplate/fields.js +24 -0
- package/operations/pageTemplate/fields.js.map +1 -0
- package/operations/pageTemplate/index.d.ts +8 -0
- package/operations/pageTemplate/index.js +204 -0
- package/operations/pageTemplate/index.js.map +1 -0
- package/operations/pageTemplate/keys.d.ts +5 -0
- package/operations/pageTemplate/keys.js +23 -0
- package/operations/pageTemplate/keys.js.map +1 -0
- package/operations/pages/elasticsearchQueryBody.d.ts +8 -12
- package/operations/pages/elasticsearchQueryBody.js +43 -101
- package/operations/pages/elasticsearchQueryBody.js.map +1 -0
- package/operations/pages/fields.d.ts +3 -2
- package/operations/pages/fields.js +18 -5
- package/operations/pages/fields.js.map +1 -0
- package/operations/pages/helpers.d.ts +10 -18
- package/operations/pages/helpers.js +34 -33
- package/operations/pages/helpers.js.map +1 -0
- package/operations/pages/index.d.ts +10 -4
- package/operations/pages/index.js +785 -18
- package/operations/pages/index.js.map +1 -0
- package/operations/pages/keys.d.ts +24 -0
- package/operations/pages/keys.js +59 -0
- package/operations/pages/keys.js.map +1 -0
- package/operations/pages/logIgnoredEsResponseError.d.ts +7 -0
- package/operations/pages/logIgnoredEsResponseError.js +28 -0
- package/operations/pages/logIgnoredEsResponseError.js.map +1 -0
- package/operations/pages/shouldIgnoreEsResponseError.d.ts +2 -0
- package/operations/pages/shouldIgnoreEsResponseError.js +13 -0
- package/operations/pages/shouldIgnoreEsResponseError.js.map +1 -0
- package/operations/settings/index.d.ts +11 -6
- package/operations/settings/index.js +140 -15
- package/operations/settings/index.js.map +1 -0
- package/operations/system/index.d.ts +5 -4
- package/operations/system/index.js +94 -23
- package/operations/system/index.js.map +1 -0
- package/package.json +44 -36
- package/plugins/definitions/BlockCategoryDynamoDbElasticFieldPlugin.d.ts +4 -0
- package/plugins/definitions/BlockCategoryDynamoDbElasticFieldPlugin.js +13 -0
- package/plugins/definitions/BlockCategoryDynamoDbElasticFieldPlugin.js.map +1 -0
- package/plugins/definitions/CategoryDynamoDbElasticFieldPlugin.js +5 -9
- package/plugins/definitions/CategoryDynamoDbElasticFieldPlugin.js.map +1 -0
- package/plugins/definitions/IndexPageDataPlugin.d.ts +12 -11
- package/plugins/definitions/IndexPageDataPlugin.js +3 -12
- package/plugins/definitions/IndexPageDataPlugin.js.map +1 -0
- package/plugins/definitions/MenuDynamoDbElasticFieldPlugin.js +5 -9
- package/plugins/definitions/MenuDynamoDbElasticFieldPlugin.js.map +1 -0
- package/plugins/definitions/PageBlockDynamoDbFieldPlugin.d.ts +4 -0
- package/plugins/definitions/PageBlockDynamoDbFieldPlugin.js +13 -0
- package/plugins/definitions/PageBlockDynamoDbFieldPlugin.js.map +1 -0
- package/plugins/definitions/PageDynamoDbElasticsearchFieldPlugin.d.ts +4 -0
- package/plugins/definitions/PageDynamoDbElasticsearchFieldPlugin.js +13 -0
- package/plugins/definitions/PageDynamoDbElasticsearchFieldPlugin.js.map +1 -0
- package/plugins/definitions/PageElasticsearchBodyModifierPlugin.d.ts +6 -2
- package/plugins/definitions/PageElasticsearchBodyModifierPlugin.js +6 -10
- package/plugins/definitions/PageElasticsearchBodyModifierPlugin.js.map +1 -0
- package/plugins/definitions/PageElasticsearchFieldPlugin.d.ts +1 -2
- package/plugins/definitions/PageElasticsearchFieldPlugin.js +5 -14
- package/plugins/definitions/PageElasticsearchFieldPlugin.js.map +1 -0
- package/plugins/definitions/PageElasticsearchIndexPlugin.d.ts +4 -0
- package/plugins/definitions/PageElasticsearchIndexPlugin.js +13 -0
- package/plugins/definitions/PageElasticsearchIndexPlugin.js.map +1 -0
- package/plugins/definitions/PageElasticsearchQueryModifierPlugin.d.ts +8 -2
- package/plugins/definitions/PageElasticsearchQueryModifierPlugin.js +6 -10
- package/plugins/definitions/PageElasticsearchQueryModifierPlugin.js.map +1 -0
- package/plugins/definitions/PageElasticsearchSortModifierPlugin.d.ts +6 -2
- package/plugins/definitions/PageElasticsearchSortModifierPlugin.js +6 -10
- package/plugins/definitions/PageElasticsearchSortModifierPlugin.js.map +1 -0
- package/plugins/definitions/PageElementDynamoDbElasticFieldPlugin.js +5 -9
- package/plugins/definitions/PageElementDynamoDbElasticFieldPlugin.js.map +1 -0
- package/plugins/definitions/PageTemplateDynamoDbElasticFieldPlugin.d.ts +4 -0
- package/plugins/definitions/PageTemplateDynamoDbElasticFieldPlugin.js +13 -0
- package/plugins/definitions/PageTemplateDynamoDbElasticFieldPlugin.js.map +1 -0
- package/plugins/definitions/SearchLatestPagesPlugin.d.ts +1 -1
- package/plugins/definitions/SearchLatestPagesPlugin.js +5 -9
- package/plugins/definitions/SearchLatestPagesPlugin.js.map +1 -0
- package/plugins/definitions/SearchPagesPlugin.d.ts +4 -4
- package/plugins/definitions/SearchPagesPlugin.js +2 -13
- package/plugins/definitions/SearchPagesPlugin.js.map +1 -0
- package/plugins/definitions/SearchPublishedPagesPlugin.d.ts +1 -1
- package/plugins/definitions/SearchPublishedPagesPlugin.js +5 -9
- package/plugins/definitions/SearchPublishedPagesPlugin.js.map +1 -0
- package/plugins/definitions/index.d.ts +15 -0
- package/plugins/definitions/index.js +172 -0
- package/plugins/definitions/index.js.map +1 -0
- package/plugins/index.d.ts +1 -0
- package/plugins/index.js +18 -0
- package/plugins/index.js.map +1 -0
- package/tasks/createIndexTaskPlugin.d.ts +2 -0
- package/tasks/createIndexTaskPlugin.js +36 -0
- package/tasks/createIndexTaskPlugin.js.map +1 -0
- package/types.d.ts +63 -0
- package/types.js +21 -0
- package/types.js.map +1 -0
- package/operations/category/CategoryDataLoader.d.ts +0 -20
- package/operations/category/CategoryStorageOperations.d.ts +0 -29
- package/operations/category/CategoryStorageOperations.js +0 -243
- package/operations/configurations.d.ts +0 -36
- package/operations/configurations.js +0 -71
- package/operations/menu/MenuStorageOperations.d.ts +0 -23
- package/operations/menu/MenuStorageOperations.js +0 -235
- package/operations/pageElement/PageElementStorageOperations.d.ts +0 -23
- package/operations/pageElement/PageElementStorageOperations.js +0 -234
- package/operations/pages/PageStorageOperations.d.ts +0 -79
- package/operations/pages/PageStorageOperations.js +0 -1117
- package/operations/settings/SettingsStorageOperations.d.ts +0 -35
- package/operations/settings/SettingsStorageOperations.js +0 -191
- package/operations/system/InstallationDdbEsPlugin.d.ts +0 -2
- package/operations/system/InstallationDdbEsPlugin.js +0 -73
- package/operations/system/SystemStorageOperations.d.ts +0 -16
- package/operations/system/SystemStorageOperations.js +0 -114
- package/upgrades/index.d.ts +0 -2
- package/upgrades/index.js +0 -14
- package/upgrades/v5.15.0/category.d.ts +0 -2
- package/upgrades/v5.15.0/category.js +0 -75
- package/upgrades/v5.15.0/index.d.ts +0 -4
- package/upgrades/v5.15.0/index.js +0 -52
- package/upgrades/v5.15.0/menu.d.ts +0 -2
- package/upgrades/v5.15.0/menu.js +0 -75
- package/upgrades/v5.15.0/pageElement.d.ts +0 -2
- package/upgrades/v5.15.0/pageElement.js +0 -75
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.createBlockCategoryStorageOperations = void 0;
|
|
8
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
9
|
+
var _query = require("@webiny/db-dynamodb/utils/query");
|
|
10
|
+
var _sort = require("@webiny/db-dynamodb/utils/sort");
|
|
11
|
+
var _filter = require("@webiny/db-dynamodb/utils/filter");
|
|
12
|
+
var _dataLoader = require("./dataLoader");
|
|
13
|
+
var _listResponse = require("@webiny/db-dynamodb/utils/listResponse");
|
|
14
|
+
var _BlockCategoryDynamoDbElasticFieldPlugin = require("../../plugins/definitions/BlockCategoryDynamoDbElasticFieldPlugin");
|
|
15
|
+
var _keys = require("./keys");
|
|
16
|
+
var _dbDynamodb = require("@webiny/db-dynamodb");
|
|
17
|
+
const createType = () => {
|
|
18
|
+
return "pb.blockCategory";
|
|
19
|
+
};
|
|
20
|
+
const createBlockCategoryStorageOperations = ({
|
|
21
|
+
entity,
|
|
22
|
+
plugins
|
|
23
|
+
}) => {
|
|
24
|
+
const dataLoader = new _dataLoader.BlockCategoryDataLoader({
|
|
25
|
+
entity
|
|
26
|
+
});
|
|
27
|
+
const get = async params => {
|
|
28
|
+
const {
|
|
29
|
+
where
|
|
30
|
+
} = params;
|
|
31
|
+
try {
|
|
32
|
+
return await dataLoader.getOne(where);
|
|
33
|
+
} catch (ex) {
|
|
34
|
+
throw new _error.default(ex.message || "Could not load block category by given parameters.", ex.code || "BLOCK_CATEGORY_GET_ERROR", {
|
|
35
|
+
where
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const create = async params => {
|
|
40
|
+
const {
|
|
41
|
+
blockCategory
|
|
42
|
+
} = params;
|
|
43
|
+
const keys = {
|
|
44
|
+
PK: (0, _keys.createPartitionKey)({
|
|
45
|
+
tenant: blockCategory.tenant,
|
|
46
|
+
locale: blockCategory.locale
|
|
47
|
+
}),
|
|
48
|
+
SK: (0, _keys.createSortKey)(blockCategory)
|
|
49
|
+
};
|
|
50
|
+
try {
|
|
51
|
+
await (0, _dbDynamodb.put)({
|
|
52
|
+
entity,
|
|
53
|
+
item: {
|
|
54
|
+
...blockCategory,
|
|
55
|
+
TYPE: createType(),
|
|
56
|
+
...keys
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
/**
|
|
60
|
+
* Always clear data loader cache when modifying the records.
|
|
61
|
+
*/
|
|
62
|
+
dataLoader.clear();
|
|
63
|
+
return blockCategory;
|
|
64
|
+
} catch (ex) {
|
|
65
|
+
throw new _error.default(ex.message || "Could not create block category.", ex.code || "BLOCK_CATEGORY_CREATE_ERROR", {
|
|
66
|
+
keys
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const update = async params => {
|
|
71
|
+
const {
|
|
72
|
+
original,
|
|
73
|
+
blockCategory
|
|
74
|
+
} = params;
|
|
75
|
+
const keys = {
|
|
76
|
+
PK: (0, _keys.createPartitionKey)({
|
|
77
|
+
tenant: original.tenant,
|
|
78
|
+
locale: original.locale
|
|
79
|
+
}),
|
|
80
|
+
SK: (0, _keys.createSortKey)(blockCategory)
|
|
81
|
+
};
|
|
82
|
+
try {
|
|
83
|
+
await (0, _dbDynamodb.put)({
|
|
84
|
+
entity,
|
|
85
|
+
item: {
|
|
86
|
+
...blockCategory,
|
|
87
|
+
TYPE: createType(),
|
|
88
|
+
...keys
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
/**
|
|
92
|
+
* Always clear data loader cache when modifying the records.
|
|
93
|
+
*/
|
|
94
|
+
dataLoader.clear();
|
|
95
|
+
return blockCategory;
|
|
96
|
+
} catch (ex) {
|
|
97
|
+
throw new _error.default(ex.message || "Could not update block category.", ex.code || "BLOCK_CATEGORY_UPDATE_ERROR", {
|
|
98
|
+
keys,
|
|
99
|
+
original,
|
|
100
|
+
category: blockCategory
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
const deleteBlockCategory = async params => {
|
|
105
|
+
const {
|
|
106
|
+
blockCategory
|
|
107
|
+
} = params;
|
|
108
|
+
const keys = {
|
|
109
|
+
PK: (0, _keys.createPartitionKey)({
|
|
110
|
+
tenant: blockCategory.tenant,
|
|
111
|
+
locale: blockCategory.locale
|
|
112
|
+
}),
|
|
113
|
+
SK: (0, _keys.createSortKey)(blockCategory)
|
|
114
|
+
};
|
|
115
|
+
try {
|
|
116
|
+
await (0, _dbDynamodb.deleteItem)({
|
|
117
|
+
entity,
|
|
118
|
+
keys
|
|
119
|
+
});
|
|
120
|
+
/**
|
|
121
|
+
* Always clear data loader cache when modifying the records.
|
|
122
|
+
*/
|
|
123
|
+
dataLoader.clear();
|
|
124
|
+
return blockCategory;
|
|
125
|
+
} catch (ex) {
|
|
126
|
+
throw new _error.default(ex.message || "Could not delete block category.", ex.code || "BLOCK_CATEGORY_DELETE_ERROR", {
|
|
127
|
+
keys,
|
|
128
|
+
blockCategory
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
const list = async params => {
|
|
133
|
+
const {
|
|
134
|
+
where,
|
|
135
|
+
sort,
|
|
136
|
+
limit
|
|
137
|
+
} = params;
|
|
138
|
+
const {
|
|
139
|
+
tenant,
|
|
140
|
+
locale,
|
|
141
|
+
...restWhere
|
|
142
|
+
} = where;
|
|
143
|
+
const queryAllParams = {
|
|
144
|
+
entity,
|
|
145
|
+
partitionKey: (0, _keys.createPartitionKey)({
|
|
146
|
+
tenant,
|
|
147
|
+
locale
|
|
148
|
+
}),
|
|
149
|
+
options: {
|
|
150
|
+
gt: " "
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
let items = [];
|
|
154
|
+
try {
|
|
155
|
+
items = await (0, _query.queryAll)(queryAllParams);
|
|
156
|
+
} catch (ex) {
|
|
157
|
+
throw new _error.default(ex.message || "Could not list block categories by given parameters.", ex.code || "BLOCK_CATEGORIES_LIST_ERROR", {
|
|
158
|
+
partitionKey: queryAllParams.partitionKey,
|
|
159
|
+
options: queryAllParams.options
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
const fields = plugins.byType(_BlockCategoryDynamoDbElasticFieldPlugin.BlockCategoryDynamoDbElasticFieldPlugin.type);
|
|
163
|
+
const filteredItems = (0, _filter.filterItems)({
|
|
164
|
+
plugins,
|
|
165
|
+
where: restWhere,
|
|
166
|
+
items,
|
|
167
|
+
fields
|
|
168
|
+
});
|
|
169
|
+
const sortedItems = (0, _sort.sortItems)({
|
|
170
|
+
items: filteredItems,
|
|
171
|
+
sort,
|
|
172
|
+
fields
|
|
173
|
+
});
|
|
174
|
+
return (0, _listResponse.createListResponse)({
|
|
175
|
+
items: sortedItems,
|
|
176
|
+
limit: limit || 100000,
|
|
177
|
+
totalCount: filteredItems.length,
|
|
178
|
+
after: null
|
|
179
|
+
});
|
|
180
|
+
};
|
|
181
|
+
return {
|
|
182
|
+
dataLoader,
|
|
183
|
+
get,
|
|
184
|
+
create,
|
|
185
|
+
update,
|
|
186
|
+
delete: deleteBlockCategory,
|
|
187
|
+
list
|
|
188
|
+
};
|
|
189
|
+
};
|
|
190
|
+
exports.createBlockCategoryStorageOperations = createBlockCategoryStorageOperations;
|
|
191
|
+
|
|
192
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_error","_interopRequireDefault","require","_query","_sort","_filter","_dataLoader","_listResponse","_BlockCategoryDynamoDbElasticFieldPlugin","_keys","_dbDynamodb","createType","createBlockCategoryStorageOperations","entity","plugins","dataLoader","BlockCategoryDataLoader","get","params","where","getOne","ex","WebinyError","message","code","create","blockCategory","keys","PK","createPartitionKey","tenant","locale","SK","createSortKey","put","item","TYPE","clear","update","original","category","deleteBlockCategory","deleteItem","list","sort","limit","restWhere","queryAllParams","partitionKey","options","gt","items","queryAll","fields","byType","BlockCategoryDynamoDbElasticFieldPlugin","type","filteredItems","filterItems","sortedItems","sortItems","createListResponse","totalCount","length","after","delete","exports"],"sources":["index.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n BlockCategory,\n BlockCategoryStorageOperationsCreateParams,\n BlockCategoryStorageOperationsDeleteParams,\n BlockCategoryStorageOperationsGetParams,\n BlockCategoryStorageOperationsListParams,\n BlockCategoryStorageOperationsUpdateParams\n} from \"@webiny/api-page-builder/types\";\nimport type { Entity } from \"@webiny/db-dynamodb/toolbox\";\nimport type { QueryAllParams } from \"@webiny/db-dynamodb/utils/query\";\nimport { queryAll } from \"@webiny/db-dynamodb/utils/query\";\nimport { sortItems } from \"@webiny/db-dynamodb/utils/sort\";\nimport { filterItems } from \"@webiny/db-dynamodb/utils/filter\";\nimport { BlockCategoryDataLoader } from \"./dataLoader\";\nimport { createListResponse } from \"@webiny/db-dynamodb/utils/listResponse\";\nimport { BlockCategoryDynamoDbElasticFieldPlugin } from \"~/plugins/definitions/BlockCategoryDynamoDbElasticFieldPlugin\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport { createPartitionKey, createSortKey } from \"~/operations/blockCategory/keys\";\nimport type { BlockCategoryStorageOperations } from \"~/types\";\nimport { deleteItem, put } from \"@webiny/db-dynamodb\";\n\nconst createType = (): string => {\n return \"pb.blockCategory\";\n};\n\nexport interface CreateBlockCategoryStorageOperationsParams {\n entity: Entity<any>;\n plugins: PluginsContainer;\n}\nexport const createBlockCategoryStorageOperations = ({\n entity,\n plugins\n}: CreateBlockCategoryStorageOperationsParams): BlockCategoryStorageOperations => {\n const dataLoader = new BlockCategoryDataLoader({\n entity\n });\n\n const get = async (params: BlockCategoryStorageOperationsGetParams) => {\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 block category by given parameters.\",\n ex.code || \"BLOCK_CATEGORY_GET_ERROR\",\n {\n where\n }\n );\n }\n };\n\n const create = async (params: BlockCategoryStorageOperationsCreateParams) => {\n const { blockCategory } = params;\n\n const keys = {\n PK: createPartitionKey({\n tenant: blockCategory.tenant,\n locale: blockCategory.locale\n }),\n SK: createSortKey(blockCategory)\n };\n\n try {\n await put({\n entity,\n item: {\n ...blockCategory,\n TYPE: createType(),\n ...keys\n }\n });\n /**\n * Always clear data loader cache when modifying the records.\n */\n dataLoader.clear();\n\n return blockCategory;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create block category.\",\n ex.code || \"BLOCK_CATEGORY_CREATE_ERROR\",\n {\n keys\n }\n );\n }\n };\n\n const update = async (params: BlockCategoryStorageOperationsUpdateParams) => {\n const { original, blockCategory } = params;\n const keys = {\n PK: createPartitionKey({\n tenant: original.tenant,\n locale: original.locale\n }),\n SK: createSortKey(blockCategory)\n };\n\n try {\n await put({\n entity,\n item: {\n ...blockCategory,\n TYPE: createType(),\n ...keys\n }\n });\n /**\n * Always clear data loader cache when modifying the records.\n */\n dataLoader.clear();\n\n return blockCategory;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update block category.\",\n ex.code || \"BLOCK_CATEGORY_UPDATE_ERROR\",\n {\n keys,\n original,\n category: blockCategory\n }\n );\n }\n };\n\n const deleteBlockCategory = async (params: BlockCategoryStorageOperationsDeleteParams) => {\n const { blockCategory } = params;\n const keys = {\n PK: createPartitionKey({\n tenant: blockCategory.tenant,\n locale: blockCategory.locale\n }),\n SK: createSortKey(blockCategory)\n };\n\n try {\n await deleteItem({\n entity,\n keys\n });\n /**\n * Always clear data loader cache when modifying the records.\n */\n dataLoader.clear();\n\n return blockCategory;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete block category.\",\n ex.code || \"BLOCK_CATEGORY_DELETE_ERROR\",\n {\n keys,\n blockCategory\n }\n );\n }\n };\n\n const list = async (params: BlockCategoryStorageOperationsListParams) => {\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: BlockCategory[] = [];\n\n try {\n items = await queryAll<BlockCategory>(queryAllParams);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not list block categories by given parameters.\",\n ex.code || \"BLOCK_CATEGORIES_LIST_ERROR\",\n {\n partitionKey: queryAllParams.partitionKey,\n options: queryAllParams.options\n }\n );\n }\n\n const fields = plugins.byType<BlockCategoryDynamoDbElasticFieldPlugin>(\n BlockCategoryDynamoDbElasticFieldPlugin.type\n );\n\n const filteredItems = filterItems<BlockCategory>({\n plugins,\n where: restWhere,\n items,\n fields\n });\n\n const sortedItems = sortItems<BlockCategory>({\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 return {\n dataLoader,\n get,\n create,\n update,\n delete: deleteBlockCategory,\n list\n };\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAWA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,WAAA,GAAAJ,OAAA;AACA,IAAAK,aAAA,GAAAL,OAAA;AACA,IAAAM,wCAAA,GAAAN,OAAA;AAEA,IAAAO,KAAA,GAAAP,OAAA;AAEA,IAAAQ,WAAA,GAAAR,OAAA;AAEA,MAAMS,UAAU,GAAGA,CAAA,KAAc;EAC7B,OAAO,kBAAkB;AAC7B,CAAC;AAMM,MAAMC,oCAAoC,GAAGA,CAAC;EACjDC,MAAM;EACNC;AACwC,CAAC,KAAqC;EAC9E,MAAMC,UAAU,GAAG,IAAIC,mCAAuB,CAAC;IAC3CH;EACJ,CAAC,CAAC;EAEF,MAAMI,GAAG,GAAG,MAAOC,MAA+C,IAAK;IACnE,MAAM;MAAEC;IAAM,CAAC,G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,UAAU;IACVE,GAAG;IACHQ,MAAM;IACNa,MAAM;IACN2B,MAAM,EAAExB,mBAAmB;IAC3BE;EACJ,CAAC;AACL,CAAC;AAACuB,OAAA,CAAAtD,oCAAA,GAAAA,oCAAA","ignoreList":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface PartitionKeyParams {
|
|
2
|
+
tenant: string;
|
|
3
|
+
locale: string;
|
|
4
|
+
}
|
|
5
|
+
export declare const createPartitionKey: (params: PartitionKeyParams) => string;
|
|
6
|
+
export interface SortKeyParams {
|
|
7
|
+
slug: string;
|
|
8
|
+
}
|
|
9
|
+
export declare const createSortKey: (params: SortKeyParams) => string;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createSortKey = exports.createPartitionKey = void 0;
|
|
7
|
+
const createPartitionKey = params => {
|
|
8
|
+
const {
|
|
9
|
+
tenant,
|
|
10
|
+
locale
|
|
11
|
+
} = params;
|
|
12
|
+
return `T#${tenant}#L#${locale}#PB#BC`;
|
|
13
|
+
};
|
|
14
|
+
exports.createPartitionKey = createPartitionKey;
|
|
15
|
+
const createSortKey = params => {
|
|
16
|
+
const {
|
|
17
|
+
slug
|
|
18
|
+
} = params;
|
|
19
|
+
return slug;
|
|
20
|
+
};
|
|
21
|
+
exports.createSortKey = createSortKey;
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=keys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createPartitionKey","params","tenant","locale","exports","createSortKey","slug"],"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#BC`;\n};\n\nexport interface SortKeyParams {\n slug: string;\n}\nexport const createSortKey = (params: SortKeyParams): string => {\n const { slug } = params;\n return slug;\n};\n"],"mappings":";;;;;;AAIO,MAAMA,kBAAkB,GAAIC,MAA0B,IAAa;EACtE,MAAM;IAAEC,MAAM;IAAEC;EAAO,CAAC,GAAGF,MAAM;EACjC,OAAO,KAAKC,MAAM,MAAMC,MAAM,QAAQ;AAC1C,CAAC;AAACC,OAAA,CAAAJ,kBAAA,GAAAA,kBAAA;AAKK,MAAMK,aAAa,GAAIJ,MAAqB,IAAa;EAC5D,MAAM;IAAEK;EAAK,CAAC,GAAGL,MAAM;EACvB,OAAOK,IAAI;AACf,CAAC;AAACF,OAAA,CAAAC,aAAA,GAAAA,aAAA","ignoreList":[]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Category } from "@webiny/api-page-builder/types";
|
|
2
|
+
import type { Entity } from "@webiny/db-dynamodb/toolbox";
|
|
3
|
+
import type { DataLoaderInterface } from "../../types";
|
|
4
|
+
interface Params {
|
|
5
|
+
entity: Entity<any>;
|
|
6
|
+
}
|
|
7
|
+
type DataLoaderGetItem = Pick<Category, "slug" | "tenant" | "locale">;
|
|
8
|
+
export declare class CategoryDataLoader implements DataLoaderInterface {
|
|
9
|
+
private _getDataLoader;
|
|
10
|
+
private readonly entity;
|
|
11
|
+
constructor(params: Params);
|
|
12
|
+
getOne(item: DataLoaderGetItem): Promise<Category>;
|
|
13
|
+
getAll(items: DataLoaderGetItem[]): Promise<Category[]>;
|
|
14
|
+
clear(): void;
|
|
15
|
+
private getDataLoader;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -1,63 +1,50 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.CategoryDataLoader = void 0;
|
|
9
|
-
|
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
12
8
|
var _dataloader = _interopRequireDefault(require("dataloader"));
|
|
13
|
-
|
|
14
|
-
var _batchRead = require("@webiny/db-dynamodb/utils/batchRead");
|
|
15
|
-
|
|
9
|
+
var _dbDynamodb = require("@webiny/db-dynamodb");
|
|
16
10
|
var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
17
|
-
|
|
11
|
+
var _keys = require("./keys");
|
|
18
12
|
class CategoryDataLoader {
|
|
13
|
+
_getDataLoader = undefined;
|
|
19
14
|
constructor(params) {
|
|
20
|
-
|
|
21
|
-
(0, _defineProperty2.default)(this, "_getDataLoader", void 0);
|
|
22
|
-
this.storageOperations = params.storageOperations;
|
|
15
|
+
this.entity = params.entity;
|
|
23
16
|
}
|
|
24
|
-
|
|
25
17
|
async getOne(item) {
|
|
26
18
|
return await this.getDataLoader().load(item);
|
|
27
19
|
}
|
|
28
|
-
|
|
29
20
|
async getAll(items) {
|
|
30
21
|
return await this.getDataLoader().loadMany(items);
|
|
31
22
|
}
|
|
32
|
-
|
|
33
23
|
clear() {
|
|
34
24
|
this.getDataLoader().clearAll();
|
|
35
25
|
}
|
|
36
|
-
|
|
37
26
|
getDataLoader() {
|
|
38
27
|
if (!this._getDataLoader) {
|
|
39
28
|
const cacheKeyFn = key => {
|
|
40
29
|
return `T#${key.tenant}#L#${key.locale}#${key.slug}`;
|
|
41
30
|
};
|
|
42
|
-
|
|
43
31
|
this._getDataLoader = new _dataloader.default(async items => {
|
|
44
32
|
const batched = items.map(item => {
|
|
45
|
-
return this.
|
|
46
|
-
PK:
|
|
47
|
-
SK:
|
|
33
|
+
return this.entity.getBatch({
|
|
34
|
+
PK: (0, _keys.createPartitionKey)(item),
|
|
35
|
+
SK: (0, _keys.createSortKey)(item)
|
|
48
36
|
});
|
|
49
37
|
});
|
|
50
|
-
const records = await (0,
|
|
51
|
-
table: this.
|
|
38
|
+
const records = await (0, _dbDynamodb.batchReadAll)({
|
|
39
|
+
table: this.entity.table,
|
|
52
40
|
items: batched
|
|
53
41
|
});
|
|
54
42
|
const results = records.reduce((collection, result) => {
|
|
55
43
|
if (!result) {
|
|
56
44
|
return collection;
|
|
57
45
|
}
|
|
58
|
-
|
|
59
46
|
const key = cacheKeyFn(result);
|
|
60
|
-
collection[key] = (0, _cleanup.cleanupItem)(this.
|
|
47
|
+
collection[key] = (0, _cleanup.cleanupItem)(this.entity, result);
|
|
61
48
|
return collection;
|
|
62
49
|
}, {});
|
|
63
50
|
return items.map(item => {
|
|
@@ -68,10 +55,9 @@ class CategoryDataLoader {
|
|
|
68
55
|
cacheKeyFn
|
|
69
56
|
});
|
|
70
57
|
}
|
|
71
|
-
|
|
72
58
|
return this._getDataLoader;
|
|
73
59
|
}
|
|
74
|
-
|
|
75
60
|
}
|
|
61
|
+
exports.CategoryDataLoader = CategoryDataLoader;
|
|
76
62
|
|
|
77
|
-
|
|
63
|
+
//# sourceMappingURL=dataLoader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_dataloader","_interopRequireDefault","require","_dbDynamodb","_cleanup","_keys","CategoryDataLoader","_getDataLoader","undefined","constructor","params","entity","getOne","item","getDataLoader","load","getAll","items","loadMany","clear","clearAll","cacheKeyFn","key","tenant","locale","slug","DataLoader","batched","map","getBatch","PK","createPartitionKey","SK","createSortKey","records","batchReadAll","table","results","reduce","collection","result","cleanupItem","exports"],"sources":["dataLoader.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport { batchReadAll } from \"@webiny/db-dynamodb\";\nimport type { Category } from \"@webiny/api-page-builder/types\";\nimport { cleanupItem } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport type { Entity } from \"@webiny/db-dynamodb/toolbox\";\nimport { createPartitionKey, createSortKey } from \"./keys\";\nimport type { DataLoaderInterface } from \"~/types\";\n\ninterface Params {\n entity: Entity<any>;\n}\n\ntype DataLoaderGetItem = Pick<Category, \"slug\" | \"tenant\" | \"locale\">;\n\nexport class CategoryDataLoader implements DataLoaderInterface {\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<Category> {\n return await this.getDataLoader().load(item);\n }\n\n public async getAll(items: DataLoaderGetItem[]): Promise<Category[]> {\n return await this.getDataLoader().loadMany(items);\n }\n\n public clear(): void {\n this.getDataLoader().clearAll();\n }\n\n private getDataLoader(): DataLoader<any, any> {\n if (!this._getDataLoader) {\n const cacheKeyFn = (key: DataLoaderGetItem) => {\n return `T#${key.tenant}#L#${key.locale}#${key.slug}`;\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<Category>({\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 Category;\n return collection;\n }, {} as Record<string, Category>);\n return items.map(item => {\n const key = cacheKeyFn(item);\n return results[key] || null;\n });\n },\n {\n cacheKeyFn\n }\n );\n }\n return this._getDataLoader;\n }\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AAEA,IAAAE,QAAA,GAAAF,OAAA;AAEA,IAAAG,KAAA,GAAAH,OAAA;AASO,MAAMI,kBAAkB,CAAgC;EACnDC,cAAc,GAAqCC,SAAS;EAIpEC,WAAWA,CAACC,MAAc,EAAE;IACxB,IAAI,CAACC,MAAM,GAAGD,MAAM,CAACC,MAAM;EAC/B;EAEA,MAAaC,MAAMA,CAACC,IAAuB,EAAqB;IAC5D,OAAO,MAAM,IAAI,CAACC,aA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,MAAM,CAAa;UAC9D,OAAOD,UAAU;QACrB,CAAC,EAAE,CAAC,CAA6B,CAAC;QAClC,OAAOtB,KAAK,CAACW,GAAG,CAACf,IAAI,IAAI;UACrB,MAAMS,GAAG,GAAGD,UAAU,CAACR,IAAI,CAAC;UAC5B,OAAOwB,OAAO,CAACf,GAAG,CAAC,IAAI,IAAI;QAC/B,CAAC,CAAC;MACN,CAAC,EACD;QACID;MACJ,CACJ,CAAC;IACL;IACA,OAAO,IAAI,CAACd,cAAc;EAC9B;AACJ;AAACmC,OAAA,CAAApC,kBAAA,GAAAA,kBAAA","ignoreList":[]}
|
|
@@ -1,3 +1,2 @@
|
|
|
1
1
|
import { CategoryDynamoDbElasticFieldPlugin } from "../../plugins/definitions/CategoryDynamoDbElasticFieldPlugin";
|
|
2
|
-
declare const
|
|
3
|
-
export default _default;
|
|
2
|
+
export declare const createCategoryDynamoDbFields: () => CategoryDynamoDbElasticFieldPlugin[];
|
|
@@ -3,11 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
|
|
6
|
+
exports.createCategoryDynamoDbFields = void 0;
|
|
8
7
|
var _CategoryDynamoDbElasticFieldPlugin = require("../../plugins/definitions/CategoryDynamoDbElasticFieldPlugin");
|
|
9
|
-
|
|
10
|
-
var _default = () => {
|
|
8
|
+
const createCategoryDynamoDbFields = () => {
|
|
11
9
|
return [new _CategoryDynamoDbElasticFieldPlugin.CategoryDynamoDbElasticFieldPlugin({
|
|
12
10
|
field: "id"
|
|
13
11
|
}), new _CategoryDynamoDbElasticFieldPlugin.CategoryDynamoDbElasticFieldPlugin({
|
|
@@ -24,5 +22,6 @@ var _default = () => {
|
|
|
24
22
|
path: "createdBy.id"
|
|
25
23
|
})];
|
|
26
24
|
};
|
|
25
|
+
exports.createCategoryDynamoDbFields = createCategoryDynamoDbFields;
|
|
27
26
|
|
|
28
|
-
|
|
27
|
+
//# sourceMappingURL=fields.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_CategoryDynamoDbElasticFieldPlugin","require","createCategoryDynamoDbFields","CategoryDynamoDbElasticFieldPlugin","field","type","path","exports"],"sources":["fields.ts"],"sourcesContent":["import { CategoryDynamoDbElasticFieldPlugin } from \"~/plugins/definitions/CategoryDynamoDbElasticFieldPlugin\";\n\nexport const createCategoryDynamoDbFields = (): CategoryDynamoDbElasticFieldPlugin[] => {\n return [\n new CategoryDynamoDbElasticFieldPlugin({\n field: \"id\"\n }),\n new CategoryDynamoDbElasticFieldPlugin({\n field: \"createdOn\",\n type: \"date\"\n }),\n new CategoryDynamoDbElasticFieldPlugin({\n field: \"savedOn\",\n type: \"date\"\n }),\n new CategoryDynamoDbElasticFieldPlugin({\n field: \"publishedOn\",\n type: \"date\"\n }),\n new CategoryDynamoDbElasticFieldPlugin({\n field: \"createdBy\",\n path: \"createdBy.id\"\n })\n ];\n};\n"],"mappings":";;;;;;AAAA,IAAAA,mCAAA,GAAAC,OAAA;AAEO,MAAMC,4BAA4B,GAAGA,CAAA,KAA4C;EACpF,OAAO,CACH,IAAIC,sEAAkC,CAAC;IACnCC,KAAK,EAAE;EACX,CAAC,CAAC,EACF,IAAID,sEAAkC,CAAC;IACnCC,KAAK,EAAE,WAAW;IAClBC,IAAI,EAAE;EACV,CAAC,CAAC,EACF,IAAIF,sEAAkC,CAAC;IACnCC,KAAK,EAAE,SAAS;IAChBC,IAAI,EAAE;EACV,CAAC,CAAC,EACF,IAAIF,sEAAkC,CAAC;IACnCC,KAAK,EAAE,aAAa;IACpBC,IAAI,EAAE;EACV,CAAC,CAAC,EACF,IAAIF,sEAAkC,CAAC;IACnCC,KAAK,EAAE,WAAW;IAClBE,IAAI,EAAE;EACV,CAAC,CAAC,CACL;AACL,CAAC;AAACC,OAAA,CAAAL,4BAAA,GAAAA,4BAAA","ignoreList":[]}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import type { Entity } from "@webiny/db-dynamodb/toolbox";
|
|
2
|
+
import type { PluginsContainer } from "@webiny/plugins";
|
|
3
|
+
import type { CategoryStorageOperations } from "../../types";
|
|
4
|
+
export interface CreateCategoryStorageOperationsParams {
|
|
5
|
+
entity: Entity<any>;
|
|
6
|
+
plugins: PluginsContainer;
|
|
5
7
|
}
|
|
8
|
+
export declare const createCategoryStorageOperations: ({ entity, plugins }: CreateCategoryStorageOperationsParams) => CategoryStorageOperations;
|
|
@@ -1,28 +1,192 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
|
-
exports.
|
|
9
|
-
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
7
|
+
exports.createCategoryStorageOperations = void 0;
|
|
8
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
9
|
+
var _query = require("@webiny/db-dynamodb/utils/query");
|
|
10
|
+
var _sort = require("@webiny/db-dynamodb/utils/sort");
|
|
11
|
+
var _filter = require("@webiny/db-dynamodb/utils/filter");
|
|
12
|
+
var _dataLoader = require("./dataLoader");
|
|
13
|
+
var _listResponse = require("@webiny/db-dynamodb/utils/listResponse");
|
|
14
|
+
var _CategoryDynamoDbElasticFieldPlugin = require("../../plugins/definitions/CategoryDynamoDbElasticFieldPlugin");
|
|
15
|
+
var _keys = require("./keys");
|
|
16
|
+
var _dbDynamodb = require("@webiny/db-dynamodb");
|
|
17
|
+
const createType = () => {
|
|
18
|
+
return "pb.category";
|
|
19
|
+
};
|
|
20
|
+
const createCategoryStorageOperations = ({
|
|
21
|
+
entity,
|
|
22
|
+
plugins
|
|
23
|
+
}) => {
|
|
24
|
+
const dataLoader = new _dataLoader.CategoryDataLoader({
|
|
25
|
+
entity
|
|
26
|
+
});
|
|
27
|
+
const get = async params => {
|
|
28
|
+
const {
|
|
29
|
+
where
|
|
30
|
+
} = params;
|
|
31
|
+
try {
|
|
32
|
+
return await dataLoader.getOne(where);
|
|
33
|
+
} catch (ex) {
|
|
34
|
+
throw new _error.default(ex.message || "Could not load category by given parameters.", ex.code || "CATEGORY_GET_ERROR", {
|
|
35
|
+
where
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const create = async params => {
|
|
40
|
+
const {
|
|
41
|
+
category
|
|
42
|
+
} = params;
|
|
43
|
+
const keys = {
|
|
44
|
+
PK: (0, _keys.createPartitionKey)({
|
|
45
|
+
tenant: category.tenant,
|
|
46
|
+
locale: category.locale
|
|
47
|
+
}),
|
|
48
|
+
SK: (0, _keys.createSortKey)(category)
|
|
49
|
+
};
|
|
50
|
+
try {
|
|
51
|
+
await (0, _dbDynamodb.put)({
|
|
52
|
+
entity,
|
|
53
|
+
item: {
|
|
54
|
+
...category,
|
|
55
|
+
TYPE: createType(),
|
|
56
|
+
...keys
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
/**
|
|
60
|
+
* Always clear data loader cache when modifying the records.
|
|
61
|
+
*/
|
|
62
|
+
dataLoader.clear();
|
|
63
|
+
return category;
|
|
64
|
+
} catch (ex) {
|
|
65
|
+
throw new _error.default(ex.message || "Could not create category.", ex.code || "CATEGORY_CREATE_ERROR", {
|
|
66
|
+
keys
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const update = async params => {
|
|
71
|
+
const {
|
|
72
|
+
original,
|
|
73
|
+
category
|
|
74
|
+
} = params;
|
|
75
|
+
const keys = {
|
|
76
|
+
PK: (0, _keys.createPartitionKey)({
|
|
77
|
+
tenant: original.tenant,
|
|
78
|
+
locale: original.locale
|
|
79
|
+
}),
|
|
80
|
+
SK: (0, _keys.createSortKey)(category)
|
|
81
|
+
};
|
|
82
|
+
try {
|
|
83
|
+
await (0, _dbDynamodb.put)({
|
|
84
|
+
entity,
|
|
85
|
+
item: {
|
|
86
|
+
...category,
|
|
87
|
+
TYPE: createType(),
|
|
88
|
+
...keys
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
/**
|
|
92
|
+
* Always clear data loader cache when modifying the records.
|
|
93
|
+
*/
|
|
94
|
+
dataLoader.clear();
|
|
95
|
+
return category;
|
|
96
|
+
} catch (ex) {
|
|
97
|
+
throw new _error.default(ex.message || "Could not update category.", ex.code || "CATEGORY_UPDATE_ERROR", {
|
|
98
|
+
keys,
|
|
99
|
+
original,
|
|
100
|
+
category
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
const deleteCategory = async params => {
|
|
105
|
+
const {
|
|
106
|
+
category
|
|
107
|
+
} = params;
|
|
108
|
+
const keys = {
|
|
109
|
+
PK: (0, _keys.createPartitionKey)({
|
|
110
|
+
tenant: category.tenant,
|
|
111
|
+
locale: category.locale
|
|
112
|
+
}),
|
|
113
|
+
SK: (0, _keys.createSortKey)(category)
|
|
114
|
+
};
|
|
115
|
+
try {
|
|
116
|
+
await (0, _dbDynamodb.deleteItem)({
|
|
117
|
+
entity,
|
|
118
|
+
keys
|
|
119
|
+
});
|
|
120
|
+
/**
|
|
121
|
+
* Always clear data loader cache when modifying the records.
|
|
122
|
+
*/
|
|
123
|
+
dataLoader.clear();
|
|
124
|
+
return category;
|
|
125
|
+
} catch (ex) {
|
|
126
|
+
throw new _error.default(ex.message || "Could not delete category.", ex.code || "CATEGORY_DELETE_ERROR", {
|
|
127
|
+
keys,
|
|
128
|
+
category
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
const list = async params => {
|
|
133
|
+
const {
|
|
134
|
+
where,
|
|
135
|
+
sort,
|
|
136
|
+
limit
|
|
137
|
+
} = params;
|
|
138
|
+
const {
|
|
139
|
+
tenant,
|
|
140
|
+
locale,
|
|
141
|
+
...restWhere
|
|
142
|
+
} = where;
|
|
143
|
+
const queryAllParams = {
|
|
144
|
+
entity,
|
|
145
|
+
partitionKey: (0, _keys.createPartitionKey)({
|
|
146
|
+
tenant,
|
|
147
|
+
locale
|
|
148
|
+
}),
|
|
149
|
+
options: {
|
|
150
|
+
gt: " "
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
let items = [];
|
|
154
|
+
try {
|
|
155
|
+
items = await (0, _query.queryAll)(queryAllParams);
|
|
156
|
+
} catch (ex) {
|
|
157
|
+
throw new _error.default(ex.message || "Could not list categories by given parameters.", ex.code || "CATEGORIES_LIST_ERROR", {
|
|
158
|
+
partitionKey: queryAllParams.partitionKey,
|
|
159
|
+
options: queryAllParams.options
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
const fields = plugins.byType(_CategoryDynamoDbElasticFieldPlugin.CategoryDynamoDbElasticFieldPlugin.type);
|
|
163
|
+
const filteredItems = (0, _filter.filterItems)({
|
|
164
|
+
plugins,
|
|
165
|
+
where: restWhere,
|
|
166
|
+
items,
|
|
167
|
+
fields
|
|
23
168
|
});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
169
|
+
const sortedItems = (0, _sort.sortItems)({
|
|
170
|
+
items: filteredItems,
|
|
171
|
+
sort,
|
|
172
|
+
fields
|
|
173
|
+
});
|
|
174
|
+
return (0, _listResponse.createListResponse)({
|
|
175
|
+
items: sortedItems,
|
|
176
|
+
limit: limit || 100000,
|
|
177
|
+
totalCount: filteredItems.length,
|
|
178
|
+
after: null
|
|
179
|
+
});
|
|
180
|
+
};
|
|
181
|
+
return {
|
|
182
|
+
dataLoader,
|
|
183
|
+
get,
|
|
184
|
+
create,
|
|
185
|
+
update,
|
|
186
|
+
delete: deleteCategory,
|
|
187
|
+
list
|
|
188
|
+
};
|
|
189
|
+
};
|
|
190
|
+
exports.createCategoryStorageOperations = createCategoryStorageOperations;
|
|
27
191
|
|
|
28
|
-
|
|
192
|
+
//# sourceMappingURL=index.js.map
|