@webiny/api-page-builder-import-export-so-ddb 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.
- package/LICENSE +21 -0
- package/README.md +30 -0
- package/definitions/pageImportExportTaskEntity.d.ts +9 -0
- package/definitions/pageImportExportTaskEntity.js +79 -0
- package/definitions/table.d.ts +7 -0
- package/definitions/table.js +28 -0
- package/index.d.ts +2 -0
- package/index.js +400 -0
- package/package.json +54 -0
- package/types.d.ts +18 -0
- package/types.js +5 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Webiny
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# @webiny/api-page-builder-import-export-so-ddb
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@webiny/api-page-builder-so-ddb)
|
|
4
|
+
[](https://www.npmjs.com/package/@webiny/api-page-builder-so-ddb)
|
|
5
|
+
[](https://github.com/prettier/prettier)
|
|
6
|
+
[](http://makeapullrequest.com)
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
npm install --save @webiny/api-page-builder-import-export-so-ddb
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Or if you prefer yarn:
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
yarn add @webiny/api-page-builder-import-export-so-ddb
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## Testing
|
|
22
|
+
To run the tests only for this package you must filter it with keywords.
|
|
23
|
+
|
|
24
|
+
### Env variables
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### Command
|
|
28
|
+
````
|
|
29
|
+
yarn test packages/api-page-builder-import-export --keyword=pbie:ddb --keyword=pbie:base
|
|
30
|
+
````
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Entity, Table } from "dynamodb-toolbox";
|
|
2
|
+
import { Attributes } from "../types";
|
|
3
|
+
interface Params {
|
|
4
|
+
entityName: string;
|
|
5
|
+
table: Table;
|
|
6
|
+
attributes?: Attributes;
|
|
7
|
+
}
|
|
8
|
+
export declare const createPageImportExportTaskEntity: ({ entityName, table, attributes }: Params) => Entity<{}>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.createPageImportExportTaskEntity = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _dynamodbToolbox = require("dynamodb-toolbox");
|
|
13
|
+
|
|
14
|
+
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; }
|
|
15
|
+
|
|
16
|
+
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; }
|
|
17
|
+
|
|
18
|
+
const createPageImportExportTaskEntity = ({
|
|
19
|
+
entityName,
|
|
20
|
+
table,
|
|
21
|
+
attributes
|
|
22
|
+
}) => {
|
|
23
|
+
return new _dynamodbToolbox.Entity({
|
|
24
|
+
name: entityName,
|
|
25
|
+
table,
|
|
26
|
+
attributes: _objectSpread({
|
|
27
|
+
PK: {
|
|
28
|
+
partitionKey: true
|
|
29
|
+
},
|
|
30
|
+
SK: {
|
|
31
|
+
sortKey: true
|
|
32
|
+
},
|
|
33
|
+
GSI1_PK: {
|
|
34
|
+
type: "string"
|
|
35
|
+
},
|
|
36
|
+
GSI1_SK: {
|
|
37
|
+
type: "string"
|
|
38
|
+
},
|
|
39
|
+
TYPE: {
|
|
40
|
+
type: "string"
|
|
41
|
+
},
|
|
42
|
+
id: {
|
|
43
|
+
type: "string"
|
|
44
|
+
},
|
|
45
|
+
parent: {
|
|
46
|
+
type: "string"
|
|
47
|
+
},
|
|
48
|
+
status: {
|
|
49
|
+
type: "string"
|
|
50
|
+
},
|
|
51
|
+
data: {
|
|
52
|
+
type: "map"
|
|
53
|
+
},
|
|
54
|
+
input: {
|
|
55
|
+
type: "map"
|
|
56
|
+
},
|
|
57
|
+
stats: {
|
|
58
|
+
type: "map"
|
|
59
|
+
},
|
|
60
|
+
error: {
|
|
61
|
+
type: "map"
|
|
62
|
+
},
|
|
63
|
+
createdOn: {
|
|
64
|
+
type: "string"
|
|
65
|
+
},
|
|
66
|
+
createdBy: {
|
|
67
|
+
type: "map"
|
|
68
|
+
},
|
|
69
|
+
tenant: {
|
|
70
|
+
type: "string"
|
|
71
|
+
},
|
|
72
|
+
locale: {
|
|
73
|
+
type: "string"
|
|
74
|
+
}
|
|
75
|
+
}, attributes)
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
exports.createPageImportExportTaskEntity = createPageImportExportTaskEntity;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createTable = void 0;
|
|
7
|
+
|
|
8
|
+
var _dynamodbToolbox = require("dynamodb-toolbox");
|
|
9
|
+
|
|
10
|
+
const createTable = ({
|
|
11
|
+
table,
|
|
12
|
+
documentClient
|
|
13
|
+
}) => {
|
|
14
|
+
return new _dynamodbToolbox.Table({
|
|
15
|
+
name: table || process.env.DB_TABLE_PAGE_BUILDER || process.env.DB_TABLE,
|
|
16
|
+
partitionKey: "PK",
|
|
17
|
+
sortKey: "SK",
|
|
18
|
+
DocumentClient: documentClient,
|
|
19
|
+
indexes: {
|
|
20
|
+
GSI1: {
|
|
21
|
+
partitionKey: "GSI1_PK",
|
|
22
|
+
sortKey: "GSI1_SK"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
exports.createTable = createTable;
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.createStorageOperations = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
13
|
+
|
|
14
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
15
|
+
|
|
16
|
+
var _query = require("@webiny/db-dynamodb/utils/query");
|
|
17
|
+
|
|
18
|
+
var _listResponse = require("@webiny/db-dynamodb/utils/listResponse");
|
|
19
|
+
|
|
20
|
+
var _table = require("./definitions/table");
|
|
21
|
+
|
|
22
|
+
var _pageImportExportTaskEntity = require("./definitions/pageImportExportTaskEntity");
|
|
23
|
+
|
|
24
|
+
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; }
|
|
25
|
+
|
|
26
|
+
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; }
|
|
27
|
+
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
const createStorageOperations = params => {
|
|
30
|
+
const {
|
|
31
|
+
table: tableName,
|
|
32
|
+
documentClient,
|
|
33
|
+
attributes = {}
|
|
34
|
+
} = params;
|
|
35
|
+
const table = (0, _table.createTable)({
|
|
36
|
+
table: tableName,
|
|
37
|
+
documentClient
|
|
38
|
+
});
|
|
39
|
+
const entity = (0, _pageImportExportTaskEntity.createPageImportExportTaskEntity)({
|
|
40
|
+
entityName: "PageImportExportTask",
|
|
41
|
+
table,
|
|
42
|
+
attributes
|
|
43
|
+
});
|
|
44
|
+
const PARENT_TASK_GSI1_PK = "PB#IE_TASKS";
|
|
45
|
+
return {
|
|
46
|
+
getTable() {
|
|
47
|
+
return table;
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
getEntity() {
|
|
51
|
+
return entity;
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
createPartitionKey({
|
|
55
|
+
tenant,
|
|
56
|
+
locale,
|
|
57
|
+
id
|
|
58
|
+
}) {
|
|
59
|
+
return `T#${tenant}#L#${locale}#PB#IE_TASK#${id}`;
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
createSortKey(input) {
|
|
63
|
+
return `SUB#${input}`;
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
createGsiPartitionKey({
|
|
67
|
+
tenant,
|
|
68
|
+
locale,
|
|
69
|
+
id
|
|
70
|
+
}) {
|
|
71
|
+
return `T#${tenant}#L#${locale}#PB#IE_TASK#${id}`;
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
createGsiSortKey(status, id) {
|
|
75
|
+
return `S#${status}#${id}`;
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
createType() {
|
|
79
|
+
return "pb.pageImportExportTask";
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
async getTask(params) {
|
|
83
|
+
const {
|
|
84
|
+
where
|
|
85
|
+
} = params;
|
|
86
|
+
const keys = {
|
|
87
|
+
PK: this.createPartitionKey(where),
|
|
88
|
+
SK: "A"
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
const result = await entity.get(keys);
|
|
93
|
+
|
|
94
|
+
if (!result || !result.Item) {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return (0, _cleanup.cleanupItem)(entity, result.Item);
|
|
99
|
+
} catch (ex) {
|
|
100
|
+
throw new _error.default(ex.message || "Could not load page element by given parameters.", ex.code || "PAGE_IMPORT_EXPORT_TASK_GET_ERROR", {
|
|
101
|
+
where
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
async listTasks(params) {
|
|
107
|
+
const {
|
|
108
|
+
limit
|
|
109
|
+
} = params;
|
|
110
|
+
const queryAllParams = {
|
|
111
|
+
entity: entity,
|
|
112
|
+
partitionKey: PARENT_TASK_GSI1_PK,
|
|
113
|
+
options: {
|
|
114
|
+
beginsWith: "",
|
|
115
|
+
index: "GSI1",
|
|
116
|
+
limit: limit || undefined
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
let results = [];
|
|
120
|
+
|
|
121
|
+
try {
|
|
122
|
+
results = await (0, _query.queryAll)(queryAllParams);
|
|
123
|
+
} catch (ex) {
|
|
124
|
+
throw new _error.default(ex.message || "Could not list page import export tasks by given parameters.", ex.code || "PAGE_IMPORT_EXPORT_TASKS_LIST_ERROR", {
|
|
125
|
+
partitionKey: queryAllParams.partitionKey,
|
|
126
|
+
options: queryAllParams.options
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const items = results.map(item => (0, _cleanup.cleanupItem)(entity, item)); // TODO: Implement sort and filter
|
|
131
|
+
|
|
132
|
+
return (0, _listResponse.createListResponse)({
|
|
133
|
+
items: items,
|
|
134
|
+
limit,
|
|
135
|
+
totalCount: items.length,
|
|
136
|
+
after: null
|
|
137
|
+
});
|
|
138
|
+
},
|
|
139
|
+
|
|
140
|
+
async createTask(params) {
|
|
141
|
+
const {
|
|
142
|
+
task
|
|
143
|
+
} = params;
|
|
144
|
+
const keys = {
|
|
145
|
+
PK: this.createPartitionKey({
|
|
146
|
+
tenant: task.tenant,
|
|
147
|
+
locale: task.locale,
|
|
148
|
+
id: task.id
|
|
149
|
+
}),
|
|
150
|
+
SK: "A",
|
|
151
|
+
GSI1_PK: PARENT_TASK_GSI1_PK,
|
|
152
|
+
GSI1_SK: task.createdOn
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
try {
|
|
156
|
+
await entity.put(_objectSpread(_objectSpread({}, task), {}, {
|
|
157
|
+
TYPE: this.createType()
|
|
158
|
+
}, keys));
|
|
159
|
+
return task;
|
|
160
|
+
} catch (ex) {
|
|
161
|
+
throw new _error.default(ex.message || "Could not create pageImportExportTask.", ex.code || "PAGE_IMPORT_EXPORT_TASK_CREATE_ERROR", {
|
|
162
|
+
keys,
|
|
163
|
+
pageImportExportTask: task
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
|
|
168
|
+
async updateTask(params) {
|
|
169
|
+
const {
|
|
170
|
+
task,
|
|
171
|
+
original
|
|
172
|
+
} = params;
|
|
173
|
+
const keys = {
|
|
174
|
+
PK: this.createPartitionKey({
|
|
175
|
+
tenant: task.tenant,
|
|
176
|
+
locale: task.locale,
|
|
177
|
+
id: task.id
|
|
178
|
+
}),
|
|
179
|
+
SK: "A",
|
|
180
|
+
GSI1_PK: PARENT_TASK_GSI1_PK,
|
|
181
|
+
GSI1_SK: task.createdOn
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
try {
|
|
185
|
+
await entity.put(_objectSpread(_objectSpread({}, task), {}, {
|
|
186
|
+
TYPE: this.createType()
|
|
187
|
+
}, keys));
|
|
188
|
+
return task;
|
|
189
|
+
} catch (ex) {
|
|
190
|
+
throw new _error.default(ex.message || "Could not update pageImportExportTask.", ex.code || "PAGE_IMPORT_EXPORT_TASK_UPDATE_ERROR", {
|
|
191
|
+
keys,
|
|
192
|
+
original,
|
|
193
|
+
task: task
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
|
|
198
|
+
async deleteTask(params) {
|
|
199
|
+
const {
|
|
200
|
+
task
|
|
201
|
+
} = params;
|
|
202
|
+
const keys = {
|
|
203
|
+
PK: this.createPartitionKey({
|
|
204
|
+
tenant: task.tenant,
|
|
205
|
+
locale: task.locale,
|
|
206
|
+
id: task.id
|
|
207
|
+
}),
|
|
208
|
+
SK: "A"
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
try {
|
|
212
|
+
await entity.delete(keys);
|
|
213
|
+
return task;
|
|
214
|
+
} catch (ex) {
|
|
215
|
+
throw new _error.default(ex.message || "Could not delete pageImportExportTask.", ex.code || "PAGE_IMPORT_EXPORT_TASK_DELETE_ERROR", {
|
|
216
|
+
keys,
|
|
217
|
+
task: task
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
|
|
222
|
+
async updateTaskStats(params) {
|
|
223
|
+
const {
|
|
224
|
+
original,
|
|
225
|
+
input: {
|
|
226
|
+
prevStatus,
|
|
227
|
+
nextStatus
|
|
228
|
+
}
|
|
229
|
+
} = params;
|
|
230
|
+
const keys = {
|
|
231
|
+
PK: this.createPartitionKey({
|
|
232
|
+
tenant: original.tenant,
|
|
233
|
+
locale: original.locale,
|
|
234
|
+
id: original.id
|
|
235
|
+
}),
|
|
236
|
+
SK: "A",
|
|
237
|
+
GSI1_PK: PARENT_TASK_GSI1_PK,
|
|
238
|
+
GSI1_SK: original.createdOn
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
try {
|
|
242
|
+
await entity.update(_objectSpread(_objectSpread({
|
|
243
|
+
TYPE: this.createType()
|
|
244
|
+
}, keys), {}, {
|
|
245
|
+
stats: {
|
|
246
|
+
$set: {
|
|
247
|
+
[prevStatus]: {
|
|
248
|
+
$add: -1
|
|
249
|
+
},
|
|
250
|
+
[nextStatus]: {
|
|
251
|
+
$add: 1
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}));
|
|
256
|
+
return original;
|
|
257
|
+
} catch (ex) {
|
|
258
|
+
throw new _error.default(ex.message || "Could not update pageImportExportTask.", ex.code || "PAGE_IMPORT_EXPORT_TASK_UPDATE_ERROR", {
|
|
259
|
+
keys,
|
|
260
|
+
original
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
|
|
265
|
+
async createSubTask(params) {
|
|
266
|
+
const {
|
|
267
|
+
subTask
|
|
268
|
+
} = params;
|
|
269
|
+
const pkParams = {
|
|
270
|
+
tenant: subTask.tenant,
|
|
271
|
+
locale: subTask.locale,
|
|
272
|
+
id: subTask.parent
|
|
273
|
+
};
|
|
274
|
+
const keys = {
|
|
275
|
+
PK: this.createPartitionKey(pkParams),
|
|
276
|
+
SK: this.createSortKey(subTask.id),
|
|
277
|
+
GSI1_PK: this.createGsiPartitionKey(pkParams),
|
|
278
|
+
GSI1_SK: this.createGsiSortKey(subTask.status, subTask.id)
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
try {
|
|
282
|
+
await entity.put(_objectSpread(_objectSpread({}, subTask), {}, {
|
|
283
|
+
TYPE: this.createType()
|
|
284
|
+
}, keys));
|
|
285
|
+
return subTask;
|
|
286
|
+
} catch (ex) {
|
|
287
|
+
throw new _error.default(ex.message || "Could not create pageImportExportSubTask.", ex.code || "CREATE_PAGE_IMPORT_EXPORT_SUB_TASK_ERROR", {
|
|
288
|
+
keys,
|
|
289
|
+
subTask: subTask
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
},
|
|
293
|
+
|
|
294
|
+
async updateSubTask(params) {
|
|
295
|
+
const {
|
|
296
|
+
subTask,
|
|
297
|
+
original
|
|
298
|
+
} = params;
|
|
299
|
+
const pkParams = {
|
|
300
|
+
tenant: subTask.tenant,
|
|
301
|
+
locale: subTask.locale,
|
|
302
|
+
id: subTask.parent
|
|
303
|
+
};
|
|
304
|
+
const keys = {
|
|
305
|
+
PK: this.createPartitionKey(pkParams),
|
|
306
|
+
SK: this.createSortKey(subTask.id),
|
|
307
|
+
GSI1_PK: this.createGsiPartitionKey(pkParams),
|
|
308
|
+
GSI1_SK: this.createGsiSortKey(subTask.status, subTask.id)
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
try {
|
|
312
|
+
await entity.put(_objectSpread(_objectSpread({}, subTask), {}, {
|
|
313
|
+
TYPE: this.createType()
|
|
314
|
+
}, keys));
|
|
315
|
+
return subTask;
|
|
316
|
+
} catch (ex) {
|
|
317
|
+
throw new _error.default(ex.message || "Could not update pageImportExportSubTask.", ex.code || "UPDATE_PAGE_IMPORT_EXPORT_SUB_TASK_ERROR", {
|
|
318
|
+
keys,
|
|
319
|
+
original,
|
|
320
|
+
subTask: subTask
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
},
|
|
324
|
+
|
|
325
|
+
async getSubTask(params) {
|
|
326
|
+
const {
|
|
327
|
+
where
|
|
328
|
+
} = params;
|
|
329
|
+
const keys = {
|
|
330
|
+
PK: this.createPartitionKey({
|
|
331
|
+
tenant: where.tenant,
|
|
332
|
+
locale: where.locale,
|
|
333
|
+
id: where.parent
|
|
334
|
+
}),
|
|
335
|
+
SK: this.createSortKey(where.id)
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
try {
|
|
339
|
+
const result = await entity.get(keys);
|
|
340
|
+
|
|
341
|
+
if (!result || !result.Item) {
|
|
342
|
+
return null;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
return (0, _cleanup.cleanupItem)(entity, result.Item);
|
|
346
|
+
} catch (ex) {
|
|
347
|
+
throw new _error.default(ex.message || "Could not load page import export subTask by given parameters.", ex.code || "PAGE_IMPORT_EXPORT_TASK_GET_ERROR", {
|
|
348
|
+
where
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
},
|
|
352
|
+
|
|
353
|
+
async listSubTasks(params) {
|
|
354
|
+
const {
|
|
355
|
+
where,
|
|
356
|
+
limit
|
|
357
|
+
} = params;
|
|
358
|
+
const {
|
|
359
|
+
tenant,
|
|
360
|
+
locale,
|
|
361
|
+
parent,
|
|
362
|
+
status
|
|
363
|
+
} = where;
|
|
364
|
+
const queryAllParams = {
|
|
365
|
+
entity: entity,
|
|
366
|
+
partitionKey: this.createGsiPartitionKey({
|
|
367
|
+
tenant,
|
|
368
|
+
locale,
|
|
369
|
+
id: parent
|
|
370
|
+
}),
|
|
371
|
+
options: {
|
|
372
|
+
beginsWith: `S#${status}`,
|
|
373
|
+
limit: limit || undefined,
|
|
374
|
+
index: "GSI1"
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
let results = [];
|
|
378
|
+
|
|
379
|
+
try {
|
|
380
|
+
results = await (0, _query.queryAll)(queryAllParams);
|
|
381
|
+
} catch (ex) {
|
|
382
|
+
throw new _error.default(ex.message || "Could not list page import export tasks by given parameters.", ex.code || "LIST_PAGE_IMPORT_EXPORT_SUB_TASKS_ERROR", {
|
|
383
|
+
partitionKey: queryAllParams.partitionKey,
|
|
384
|
+
options: queryAllParams.options
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
const items = results.map(item => (0, _cleanup.cleanupItem)(entity, item));
|
|
389
|
+
return (0, _listResponse.createListResponse)({
|
|
390
|
+
items: items,
|
|
391
|
+
limit,
|
|
392
|
+
totalCount: items.length,
|
|
393
|
+
after: null
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
};
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
exports.createStorageOperations = createStorageOperations;
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@webiny/api-page-builder-import-export-so-ddb",
|
|
3
|
+
"version": "0.0.0-mt-1",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"@webiny/api-page-builder-import-export",
|
|
7
|
+
"storage-operations",
|
|
8
|
+
"dynamodb",
|
|
9
|
+
"pbie:ddb"
|
|
10
|
+
],
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/webiny/webiny-js.git",
|
|
14
|
+
"directory": "packages/api-page-builder-import-export-so-ddb"
|
|
15
|
+
},
|
|
16
|
+
"author": "Webiny Ltd",
|
|
17
|
+
"description": "The DynamoDB storage operations for import export feature in the Webiny Page Builder API.",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@babel/runtime": "7.15.4",
|
|
21
|
+
"@webiny/api-page-builder-import-export": "0.0.0-mt-1",
|
|
22
|
+
"@webiny/db-dynamodb": "0.0.0-mt-1",
|
|
23
|
+
"@webiny/error": "0.0.0-mt-1",
|
|
24
|
+
"dynamodb-toolbox": "0.3.4"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@babel/cli": "^7.5.5",
|
|
28
|
+
"@babel/core": "^7.5.5",
|
|
29
|
+
"@babel/preset-env": "^7.5.5",
|
|
30
|
+
"@babel/preset-typescript": "^7.8.3",
|
|
31
|
+
"@webiny/api-security": "^0.0.0-mt-1",
|
|
32
|
+
"@webiny/api-tenancy": "^0.0.0-mt-1",
|
|
33
|
+
"@webiny/cli": "^0.0.0-mt-1",
|
|
34
|
+
"@webiny/handler": "^0.0.0-mt-1",
|
|
35
|
+
"@webiny/handler-aws": "^0.0.0-mt-1",
|
|
36
|
+
"@webiny/handler-graphql": "^0.0.0-mt-1",
|
|
37
|
+
"@webiny/project-utils": "^0.0.0-mt-1",
|
|
38
|
+
"jest": "^26.6.3",
|
|
39
|
+
"jest-dynalite": "^3.2.0",
|
|
40
|
+
"jest-environment-node": "^27.0.6",
|
|
41
|
+
"rimraf": "^3.0.2",
|
|
42
|
+
"ttypescript": "^1.5.12",
|
|
43
|
+
"typescript": "^4.1.3"
|
|
44
|
+
},
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public",
|
|
47
|
+
"directory": "dist"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "yarn webiny run build",
|
|
51
|
+
"watch": "yarn webiny run watch"
|
|
52
|
+
},
|
|
53
|
+
"gitHead": "37736d8456a6ecb342a6c3645060bd9a3f2d4bb0"
|
|
54
|
+
}
|
package/types.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { DynamoDBTypes } from "dynamodb-toolbox/dist/classes/Table";
|
|
2
|
+
import { EntityAttributeConfig, EntityCompositeAttributes } from "dynamodb-toolbox/dist/classes/Entity";
|
|
3
|
+
import { DocumentClient } from "aws-sdk/clients/dynamodb";
|
|
4
|
+
import { PageImportExportTaskStorageOperations } from "@webiny/api-page-builder-import-export/types";
|
|
5
|
+
export declare type AttributeDefinition = DynamoDBTypes | EntityAttributeConfig | EntityCompositeAttributes;
|
|
6
|
+
export declare type Attributes = Record<string, AttributeDefinition>;
|
|
7
|
+
export interface PartitionKeyOptions {
|
|
8
|
+
tenant: string;
|
|
9
|
+
locale: string;
|
|
10
|
+
id?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface CreateStorageOperations {
|
|
13
|
+
(params: {
|
|
14
|
+
documentClient: DocumentClient;
|
|
15
|
+
table?: string;
|
|
16
|
+
attributes?: Attributes;
|
|
17
|
+
}): PageImportExportTaskStorageOperations;
|
|
18
|
+
}
|