@webiny/api-file-manager-ddb 0.0.0-unstable.40876133bb → 0.0.0-unstable.496cf268ac
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/definitions/settingsEntity.d.ts +0 -2
- package/definitions/settingsEntity.js +9 -23
- package/definitions/settingsEntity.js.map +1 -1
- package/definitions/systemEntity.d.ts +0 -2
- package/definitions/systemEntity.js +2 -13
- package/definitions/systemEntity.js.map +1 -1
- package/definitions/table.d.ts +5 -5
- package/definitions/table.js +14 -13
- package/definitions/table.js.map +1 -1
- package/index.d.ts +9 -5
- package/index.js +52 -11
- package/index.js.map +1 -1
- package/operations/files/FilesStorageOperations.d.ts +11 -7
- package/operations/files/FilesStorageOperations.js +155 -106
- package/operations/files/FilesStorageOperations.js.map +1 -1
- package/operations/files/fields.d.ts +1 -2
- package/operations/files/fields.js +3 -6
- package/operations/files/fields.js.map +1 -1
- package/operations/settings/SettingsStorageOperations.d.ts +7 -8
- package/operations/settings/SettingsStorageOperations.js +36 -61
- package/operations/settings/SettingsStorageOperations.js.map +1 -1
- package/operations/system/SystemStorageOperations.d.ts +5 -6
- package/operations/system/SystemStorageOperations.js +11 -42
- package/operations/system/SystemStorageOperations.js.map +1 -1
- package/operations/utils.js +0 -10
- package/operations/utils.js.map +1 -1
- package/package.json +10 -9
- package/plugins/FileAttributePlugin.js +1 -7
- package/plugins/FileAttributePlugin.js.map +1 -1
- package/plugins/FileDynamoDbFieldPlugin.js +0 -5
- package/plugins/FileDynamoDbFieldPlugin.js.map +1 -1
- package/plugins/SettingsAttributePlugin.js +1 -7
- package/plugins/SettingsAttributePlugin.js.map +1 -1
- package/plugins/SystemAttributePlugin.js +0 -6
- package/plugins/SystemAttributePlugin.js.map +1 -1
- package/plugins/index.d.ts +4 -0
- package/plugins/index.js +49 -0
- package/plugins/index.js.map +1 -0
|
@@ -1,74 +1,52 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.FilesStorageOperations = void 0;
|
|
9
|
-
|
|
10
8
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
-
|
|
12
9
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
|
-
|
|
14
10
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
15
|
-
|
|
16
|
-
var _table = _interopRequireDefault(require("../../definitions/table"));
|
|
17
|
-
|
|
18
|
-
var _filesEntity = _interopRequireDefault(require("../../definitions/filesEntity"));
|
|
19
|
-
|
|
11
|
+
var _table = require("../../definitions/table");
|
|
20
12
|
var _query = require("@webiny/db-dynamodb/utils/query");
|
|
21
|
-
|
|
22
13
|
var _cursor = require("@webiny/db-dynamodb/utils/cursor");
|
|
23
|
-
|
|
24
14
|
var _filter = require("@webiny/db-dynamodb/utils/filter");
|
|
25
|
-
|
|
26
15
|
var _sort = require("@webiny/db-dynamodb/utils/sort");
|
|
27
|
-
|
|
28
16
|
var _FileDynamoDbFieldPlugin = require("../../plugins/FileDynamoDbFieldPlugin");
|
|
29
|
-
|
|
30
17
|
var _batchWrite = require("@webiny/db-dynamodb/utils/batchWrite");
|
|
31
|
-
|
|
32
18
|
var _get = require("@webiny/db-dynamodb/utils/get");
|
|
33
|
-
|
|
34
|
-
var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
35
|
-
|
|
19
|
+
var _dbDynamodb = require("@webiny/db-dynamodb");
|
|
36
20
|
class FilesStorageOperations {
|
|
37
|
-
get context() {
|
|
38
|
-
return this._context;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
21
|
constructor({
|
|
42
|
-
|
|
22
|
+
documentClient,
|
|
23
|
+
plugins
|
|
43
24
|
}) {
|
|
44
|
-
(0, _defineProperty2.default)(this, "
|
|
25
|
+
(0, _defineProperty2.default)(this, "plugins", void 0);
|
|
45
26
|
(0, _defineProperty2.default)(this, "table", void 0);
|
|
46
|
-
(0, _defineProperty2.default)(this, "
|
|
47
|
-
this
|
|
48
|
-
this.
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
this.entity = (0, _filesEntity.default)({
|
|
52
|
-
context,
|
|
53
|
-
table: this.table
|
|
27
|
+
(0, _defineProperty2.default)(this, "fileEntity", void 0);
|
|
28
|
+
(0, _defineProperty2.default)(this, "aliasEntity", void 0);
|
|
29
|
+
this.plugins = plugins;
|
|
30
|
+
this.table = (0, _table.createTable)({
|
|
31
|
+
documentClient
|
|
54
32
|
});
|
|
33
|
+
this.fileEntity = (0, _dbDynamodb.createStandardEntity)(this.table, "FM.File");
|
|
34
|
+
this.aliasEntity = (0, _dbDynamodb.createStandardEntity)(this.table, "FM.FileAlias");
|
|
55
35
|
}
|
|
56
|
-
|
|
57
36
|
async get(params) {
|
|
58
37
|
const {
|
|
59
38
|
where
|
|
60
39
|
} = params;
|
|
61
40
|
const keys = {
|
|
62
41
|
PK: this.createPartitionKey(where),
|
|
63
|
-
SK:
|
|
42
|
+
SK: "A"
|
|
64
43
|
};
|
|
65
|
-
|
|
66
44
|
try {
|
|
67
45
|
const file = await (0, _get.get)({
|
|
68
|
-
entity: this.
|
|
46
|
+
entity: this.fileEntity,
|
|
69
47
|
keys
|
|
70
48
|
});
|
|
71
|
-
return
|
|
49
|
+
return file ? file.data : null;
|
|
72
50
|
} catch (ex) {
|
|
73
51
|
throw new _error.default(ex.message || "Could not fetch requested file.", ex.code || "GET_FILE_ERROR", {
|
|
74
52
|
error: ex,
|
|
@@ -76,90 +54,150 @@ class FilesStorageOperations {
|
|
|
76
54
|
});
|
|
77
55
|
}
|
|
78
56
|
}
|
|
79
|
-
|
|
80
57
|
async create(params) {
|
|
81
58
|
const {
|
|
82
59
|
file
|
|
83
60
|
} = params;
|
|
84
|
-
const
|
|
61
|
+
const items = [];
|
|
62
|
+
const item = {
|
|
85
63
|
PK: this.createPartitionKey(file),
|
|
86
|
-
SK:
|
|
64
|
+
SK: "A",
|
|
65
|
+
GSI1_PK: this.createGSI1PartitionKey(file),
|
|
66
|
+
GSI1_SK: file.id,
|
|
67
|
+
TYPE: "fm.file",
|
|
68
|
+
data: file
|
|
87
69
|
};
|
|
88
|
-
|
|
89
|
-
|
|
70
|
+
items.push(this.fileEntity.putBatch(item));
|
|
71
|
+
this.createNewAliasesRecords(file).forEach(alias => {
|
|
72
|
+
items.push(this.aliasEntity.putBatch(alias));
|
|
90
73
|
});
|
|
91
|
-
|
|
92
74
|
try {
|
|
93
|
-
await
|
|
75
|
+
await (0, _batchWrite.batchWriteAll)({
|
|
76
|
+
table: this.table,
|
|
77
|
+
items
|
|
78
|
+
});
|
|
94
79
|
} catch (ex) {
|
|
95
80
|
throw new _error.default(ex.message || "Could not create a new file in the DynamoDB.", ex.code || "CREATE_FILE_ERROR", {
|
|
96
81
|
error: ex,
|
|
97
|
-
|
|
82
|
+
items
|
|
98
83
|
});
|
|
99
84
|
}
|
|
100
|
-
|
|
101
85
|
return file;
|
|
102
86
|
}
|
|
103
|
-
|
|
104
87
|
async update(params) {
|
|
105
88
|
const {
|
|
106
89
|
file
|
|
107
90
|
} = params;
|
|
108
|
-
const
|
|
91
|
+
const items = [];
|
|
92
|
+
const item = {
|
|
109
93
|
PK: this.createPartitionKey(file),
|
|
110
|
-
SK:
|
|
94
|
+
SK: "A",
|
|
95
|
+
GSI1_PK: this.createGSI1PartitionKey(file),
|
|
96
|
+
GSI1_SK: file.id,
|
|
97
|
+
TYPE: "fm.file",
|
|
98
|
+
data: file
|
|
111
99
|
};
|
|
112
|
-
|
|
113
|
-
|
|
100
|
+
items.push(this.fileEntity.putBatch(item));
|
|
101
|
+
const existingAliases = await (0, _query.queryAll)({
|
|
102
|
+
entity: this.aliasEntity,
|
|
103
|
+
partitionKey: `T#${file.tenant}#L#${file.locale}#FM#FILE#${file.id}`,
|
|
104
|
+
options: {
|
|
105
|
+
beginsWith: `ALIAS#`
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
const newAliases = this.createNewAliasesRecords(file, existingAliases.map(alias => alias.data));
|
|
109
|
+
newAliases.forEach(alias => {
|
|
110
|
+
items.push(this.aliasEntity.putBatch(alias));
|
|
114
111
|
});
|
|
115
112
|
|
|
113
|
+
// Delete aliases that are in the DB but are NOT in the file.
|
|
114
|
+
for (const {
|
|
115
|
+
data
|
|
116
|
+
} of existingAliases) {
|
|
117
|
+
if (!file.aliases.some(alias => data.alias === alias)) {
|
|
118
|
+
items.push(this.aliasEntity.deleteBatch({
|
|
119
|
+
PK: this.createPartitionKey(file),
|
|
120
|
+
SK: `ALIAS#${data.alias}`
|
|
121
|
+
}));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
116
124
|
try {
|
|
117
|
-
await
|
|
125
|
+
await (0, _batchWrite.batchWriteAll)({
|
|
126
|
+
table: this.table,
|
|
127
|
+
items
|
|
128
|
+
});
|
|
118
129
|
} catch (ex) {
|
|
119
130
|
throw new _error.default(ex.message || "Could not update a file in the DynamoDB.", ex.code || "UPDATE_FILE_ERROR", {
|
|
120
|
-
|
|
121
|
-
item
|
|
131
|
+
items
|
|
122
132
|
});
|
|
123
133
|
}
|
|
124
|
-
|
|
125
|
-
return file;
|
|
134
|
+
return params.file;
|
|
126
135
|
}
|
|
127
|
-
|
|
128
136
|
async delete(params) {
|
|
129
137
|
const {
|
|
130
138
|
file
|
|
131
139
|
} = params;
|
|
132
140
|
const keys = {
|
|
133
141
|
PK: this.createPartitionKey(file),
|
|
134
|
-
SK:
|
|
142
|
+
SK: "A"
|
|
135
143
|
};
|
|
144
|
+
const aliasItems = await (0, _query.queryAll)({
|
|
145
|
+
entity: this.aliasEntity,
|
|
146
|
+
partitionKey: keys.PK,
|
|
147
|
+
options: {
|
|
148
|
+
beginsWith: "ALIAS#"
|
|
149
|
+
}
|
|
150
|
+
});
|
|
136
151
|
|
|
152
|
+
// All items to delete in batch
|
|
153
|
+
const items = [];
|
|
137
154
|
try {
|
|
138
|
-
|
|
155
|
+
// Delete the main file item
|
|
156
|
+
items.push(this.fileEntity.deleteBatch(keys));
|
|
157
|
+
|
|
158
|
+
// Delete file alias items
|
|
159
|
+
aliasItems.forEach(item => {
|
|
160
|
+
items.push(this.aliasEntity.deleteBatch({
|
|
161
|
+
PK: item.PK,
|
|
162
|
+
SK: item.SK
|
|
163
|
+
}));
|
|
164
|
+
});
|
|
165
|
+
await (0, _batchWrite.batchWriteAll)({
|
|
166
|
+
table: this.table,
|
|
167
|
+
items
|
|
168
|
+
});
|
|
139
169
|
} catch (ex) {
|
|
140
170
|
throw new _error.default(ex.message || "Could not delete file from the DynamoDB.", ex.code || "DELETE_FILE_ERROR", {
|
|
141
171
|
error: ex,
|
|
142
172
|
file,
|
|
143
|
-
keys
|
|
173
|
+
keys,
|
|
174
|
+
aliasItems
|
|
144
175
|
});
|
|
145
176
|
}
|
|
146
177
|
}
|
|
147
|
-
|
|
148
178
|
async createBatch(params) {
|
|
149
179
|
const {
|
|
150
180
|
files
|
|
151
181
|
} = params;
|
|
152
|
-
|
|
153
|
-
|
|
182
|
+
|
|
183
|
+
// Items to be written in batch
|
|
184
|
+
const items = [];
|
|
185
|
+
files.forEach(file => {
|
|
186
|
+
items.push(this.fileEntity.putBatch({
|
|
154
187
|
PK: this.createPartitionKey(file),
|
|
155
|
-
SK:
|
|
156
|
-
|
|
188
|
+
SK: "A",
|
|
189
|
+
GSI1_PK: this.createGSI1PartitionKey(file),
|
|
190
|
+
GSI1_SK: file.id,
|
|
191
|
+
TYPE: "fm.file",
|
|
192
|
+
data: file
|
|
157
193
|
}));
|
|
194
|
+
this.createNewAliasesRecords(file).forEach(alias => {
|
|
195
|
+
items.push(this.aliasEntity.putBatch(alias));
|
|
196
|
+
});
|
|
158
197
|
});
|
|
159
|
-
|
|
160
198
|
try {
|
|
161
199
|
await (0, _batchWrite.batchWriteAll)({
|
|
162
|
-
table: this.
|
|
200
|
+
table: this.table,
|
|
163
201
|
items
|
|
164
202
|
});
|
|
165
203
|
} catch (ex) {
|
|
@@ -168,10 +206,8 @@ class FilesStorageOperations {
|
|
|
168
206
|
files
|
|
169
207
|
});
|
|
170
208
|
}
|
|
171
|
-
|
|
172
209
|
return files;
|
|
173
210
|
}
|
|
174
|
-
|
|
175
211
|
async list(params) {
|
|
176
212
|
const {
|
|
177
213
|
where: initialWhere,
|
|
@@ -183,14 +219,14 @@ class FilesStorageOperations {
|
|
|
183
219
|
where: initialWhere
|
|
184
220
|
});
|
|
185
221
|
const queryAllParams = {
|
|
186
|
-
entity: this.
|
|
187
|
-
partitionKey: this.
|
|
222
|
+
entity: this.fileEntity,
|
|
223
|
+
partitionKey: this.createGSI1PartitionKey(initialWhere),
|
|
188
224
|
options
|
|
189
225
|
};
|
|
190
226
|
let items = [];
|
|
191
|
-
|
|
192
227
|
try {
|
|
193
|
-
|
|
228
|
+
const dbItems = await (0, _query.queryAll)(queryAllParams);
|
|
229
|
+
items = dbItems.map(item => item.data);
|
|
194
230
|
} catch (ex) {
|
|
195
231
|
throw new _error.default(ex.message || "Could not query for the files.", ex.code || "FILE_LIST_ERROR", {
|
|
196
232
|
error: ex,
|
|
@@ -206,27 +242,23 @@ class FilesStorageOperations {
|
|
|
206
242
|
}
|
|
207
243
|
});
|
|
208
244
|
}
|
|
209
|
-
|
|
210
245
|
const where = (0, _objectSpread2.default)({}, initialWhere);
|
|
211
|
-
|
|
212
246
|
if (where.search) {
|
|
213
247
|
where.contains = {
|
|
214
248
|
fields: ["name", "tags"],
|
|
215
249
|
value: where.search
|
|
216
250
|
};
|
|
217
251
|
}
|
|
218
|
-
|
|
219
252
|
delete where["tenant"];
|
|
220
253
|
delete where["locale"];
|
|
221
254
|
delete where["search"];
|
|
222
|
-
const fields = this.
|
|
255
|
+
const fields = this.plugins.byType(_FileDynamoDbFieldPlugin.FileDynamoDbFieldPlugin.type);
|
|
223
256
|
/**
|
|
224
257
|
* Filter the read items via the code.
|
|
225
258
|
* It will build the filters out of the where input and transform the values it is using.
|
|
226
259
|
*/
|
|
227
|
-
|
|
228
260
|
const filteredFiles = (0, _filter.filterItems)({
|
|
229
|
-
plugins: this.
|
|
261
|
+
plugins: this.plugins,
|
|
230
262
|
items,
|
|
231
263
|
where,
|
|
232
264
|
fields
|
|
@@ -236,7 +268,6 @@ class FilesStorageOperations {
|
|
|
236
268
|
* Sorting is also done via the code.
|
|
237
269
|
* It takes the sort input and sorts by it via the lodash sortBy method.
|
|
238
270
|
*/
|
|
239
|
-
|
|
240
271
|
const sortedFiles = (0, _sort.sortItems)({
|
|
241
272
|
items: filteredFiles,
|
|
242
273
|
sort,
|
|
@@ -250,7 +281,6 @@ class FilesStorageOperations {
|
|
|
250
281
|
* Although we do not need a cursor here, we will use it as such to keep it standardized.
|
|
251
282
|
* Number is simply encoded.
|
|
252
283
|
*/
|
|
253
|
-
|
|
254
284
|
const cursor = files.length > 0 ? (0, _cursor.encodeCursor)(start + limit) : null;
|
|
255
285
|
const meta = {
|
|
256
286
|
hasMoreItems,
|
|
@@ -259,60 +289,56 @@ class FilesStorageOperations {
|
|
|
259
289
|
};
|
|
260
290
|
return [files, meta];
|
|
261
291
|
}
|
|
262
|
-
|
|
263
292
|
async tags(params) {
|
|
264
293
|
const {
|
|
265
294
|
where: initialWhere
|
|
266
295
|
} = params;
|
|
267
296
|
const queryAllParams = {
|
|
268
|
-
entity: this.
|
|
269
|
-
partitionKey: this.
|
|
297
|
+
entity: this.fileEntity,
|
|
298
|
+
partitionKey: this.createGSI1PartitionKey(initialWhere),
|
|
270
299
|
options: {
|
|
300
|
+
index: "GSI1",
|
|
271
301
|
gte: " ",
|
|
272
302
|
reverse: false
|
|
273
303
|
}
|
|
274
304
|
};
|
|
275
305
|
let results = [];
|
|
276
|
-
|
|
277
306
|
try {
|
|
278
|
-
|
|
307
|
+
const dbItems = await (0, _query.queryAll)(queryAllParams);
|
|
308
|
+
results = dbItems.map(item => item.data);
|
|
279
309
|
} catch (ex) {
|
|
280
310
|
throw new _error.default(ex.message || "Error in the DynamoDB query.", ex.code || "DYNAMODB_ERROR", {
|
|
281
311
|
error: ex,
|
|
282
312
|
query: queryAllParams
|
|
283
313
|
});
|
|
284
314
|
}
|
|
285
|
-
|
|
286
|
-
const fields = this.context.plugins.byType(_FileDynamoDbFieldPlugin.FileDynamoDbFieldPlugin.type);
|
|
315
|
+
const fields = this.plugins.byType(_FileDynamoDbFieldPlugin.FileDynamoDbFieldPlugin.type);
|
|
287
316
|
const where = (0, _objectSpread2.default)({}, initialWhere);
|
|
288
317
|
delete where["tenant"];
|
|
289
318
|
delete where["locale"];
|
|
319
|
+
|
|
290
320
|
/**
|
|
291
321
|
* Filter the read items via the code.
|
|
292
322
|
* It will build the filters out of the where input and transform the values it is using.
|
|
293
323
|
*/
|
|
294
|
-
|
|
295
324
|
const filteredItems = (0, _filter.filterItems)({
|
|
296
|
-
plugins: this.
|
|
325
|
+
plugins: this.plugins,
|
|
297
326
|
items: results,
|
|
298
327
|
where,
|
|
299
328
|
fields
|
|
300
329
|
});
|
|
330
|
+
|
|
301
331
|
/**
|
|
302
332
|
* Aggregate all the tags from all the filtered items.
|
|
303
333
|
*/
|
|
304
|
-
|
|
305
334
|
const tagsObject = filteredItems.reduce((collection, item) => {
|
|
306
335
|
const tags = Array.isArray(item.tags) ? item.tags : [];
|
|
307
|
-
|
|
308
336
|
for (const tag of tags) {
|
|
309
337
|
if (!collection[tag]) {
|
|
310
338
|
collection[tag] = [];
|
|
311
339
|
}
|
|
312
|
-
|
|
313
340
|
collection[tag].push(item.id);
|
|
314
341
|
}
|
|
315
|
-
|
|
316
342
|
return collection;
|
|
317
343
|
}, {});
|
|
318
344
|
const tags = Object.keys(tagsObject);
|
|
@@ -325,34 +351,57 @@ class FilesStorageOperations {
|
|
|
325
351
|
};
|
|
326
352
|
return [tags, meta];
|
|
327
353
|
}
|
|
328
|
-
|
|
329
354
|
createQueryAllOptions({
|
|
330
355
|
where
|
|
331
356
|
}) {
|
|
332
|
-
const options = {
|
|
333
|
-
|
|
357
|
+
const options = {
|
|
358
|
+
index: "GSI1"
|
|
359
|
+
};
|
|
334
360
|
if (where.id) {
|
|
335
361
|
options.eq = where.id;
|
|
362
|
+
} else {
|
|
363
|
+
options.gt = " ";
|
|
336
364
|
}
|
|
337
|
-
|
|
338
365
|
return options;
|
|
339
366
|
}
|
|
340
|
-
|
|
341
367
|
createPartitionKey(params) {
|
|
342
368
|
const {
|
|
343
369
|
tenant,
|
|
344
|
-
locale
|
|
370
|
+
locale,
|
|
371
|
+
id
|
|
345
372
|
} = params;
|
|
346
|
-
return `T#${tenant}#L#${locale}#FM#
|
|
373
|
+
return `T#${tenant}#L#${locale}#FM#FILE#${id}`;
|
|
347
374
|
}
|
|
348
|
-
|
|
349
|
-
createSortKey(params) {
|
|
375
|
+
createGSI1PartitionKey(params) {
|
|
350
376
|
const {
|
|
351
|
-
|
|
377
|
+
tenant,
|
|
378
|
+
locale
|
|
352
379
|
} = params;
|
|
353
|
-
return
|
|
380
|
+
return `T#${tenant}#L#${locale}#FM#FILES`;
|
|
354
381
|
}
|
|
382
|
+
createNewAliasesRecords(file, existingAliases = []) {
|
|
383
|
+
return (file.aliases || []).map(alias => {
|
|
384
|
+
// If alias is already in the DB, skip it.
|
|
385
|
+
if (existingAliases.find(item => item.alias === alias)) {
|
|
386
|
+
return null;
|
|
387
|
+
}
|
|
355
388
|
|
|
389
|
+
// Add a new alias.
|
|
390
|
+
return {
|
|
391
|
+
PK: this.createPartitionKey(file),
|
|
392
|
+
SK: `ALIAS#${alias}`,
|
|
393
|
+
GSI1_PK: `T#${file.tenant}#FM#FILE_ALIASES`,
|
|
394
|
+
GSI1_SK: alias,
|
|
395
|
+
TYPE: "fm.fileAlias",
|
|
396
|
+
data: {
|
|
397
|
+
alias,
|
|
398
|
+
tenant: file.tenant,
|
|
399
|
+
locale: file.locale,
|
|
400
|
+
fileId: file.id,
|
|
401
|
+
key: file.key
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
}).filter(Boolean);
|
|
405
|
+
}
|
|
356
406
|
}
|
|
357
|
-
|
|
358
407
|
exports.FilesStorageOperations = FilesStorageOperations;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["FilesStorageOperations","context","_context","constructor","table","defineTable","entity","defineFilesEntity","get","params","where","keys","PK","createPartitionKey","SK","createSortKey","file","getEntityItem","cleanupItem","ex","WebinyError","message","code","error","create","item","TYPE","put","update","delete","createBatch","files","items","map","putBatch","batchWriteAll","list","initialWhere","limit","after","sort","options","createQueryAllOptions","queryAllParams","partitionKey","queryAll","queryParams","name","search","contains","fields","value","plugins","byType","FileDynamoDbFieldPlugin","type","filteredFiles","filterItems","totalCount","length","sortedFiles","sortItems","start","parseInt","decodeCursor","hasMoreItems","end","undefined","slice","cursor","encodeCursor","meta","tags","gte","reverse","results","query","filteredItems","tagsObject","reduce","collection","Array","isArray","tag","push","id","Object","eq","tenant","locale"],"sources":["FilesStorageOperations.ts"],"sourcesContent":["import {\n File,\n FileManagerContext,\n FileManagerFilesStorageOperations,\n FileManagerFilesStorageOperationsCreateBatchParams,\n FileManagerFilesStorageOperationsCreateParams,\n FileManagerFilesStorageOperationsDeleteParams,\n FileManagerFilesStorageOperationsGetParams,\n FileManagerFilesStorageOperationsListParams,\n FileManagerFilesStorageOperationsListParamsWhere,\n FileManagerFilesStorageOperationsListResponse,\n FileManagerFilesStorageOperationsListResponseMeta,\n FileManagerFilesStorageOperationsTagsParams,\n FileManagerFilesStorageOperationsTagsParamsWhere,\n FileManagerFilesStorageOperationsTagsResponse,\n FileManagerFilesStorageOperationsUpdateParams\n} from \"@webiny/api-file-manager/types\";\nimport { Entity, Table } from \"dynamodb-toolbox\";\nimport WebinyError from \"@webiny/error\";\nimport defineTable from \"~/definitions/table\";\nimport defineFilesEntity from \"~/definitions/filesEntity\";\nimport { queryOptions as DynamoDBToolboxQueryOptions } from \"dynamodb-toolbox/dist/classes/Table\";\nimport { queryAll } from \"@webiny/db-dynamodb/utils/query\";\nimport { decodeCursor, encodeCursor } from \"@webiny/db-dynamodb/utils/cursor\";\nimport { filterItems } from \"@webiny/db-dynamodb/utils/filter\";\nimport { sortItems } from \"@webiny/db-dynamodb/utils/sort\";\nimport { FileDynamoDbFieldPlugin } from \"~/plugins/FileDynamoDbFieldPlugin\";\nimport { batchWriteAll } from \"@webiny/db-dynamodb/utils/batchWrite\";\nimport { get as getEntityItem } from \"@webiny/db-dynamodb/utils/get\";\nimport { cleanupItem } from \"@webiny/db-dynamodb/utils/cleanup\";\n\ninterface FileItem extends File {\n PK: string;\n SK: string;\n TYPE: string;\n}\n\ninterface ConstructorParams {\n context: FileManagerContext;\n}\n\ninterface QueryAllOptionsParams {\n where: FileManagerFilesStorageOperationsListParamsWhere;\n}\n\ninterface CreatePartitionKeyParams {\n locale: string;\n tenant: string;\n}\n\ninterface CreateSortKeyParams {\n id: string;\n}\n\nexport class FilesStorageOperations implements FileManagerFilesStorageOperations {\n private readonly _context: FileManagerContext;\n private readonly table: Table;\n private readonly entity: Entity<any>;\n\n private get context(): FileManagerContext {\n return this._context;\n }\n\n public constructor({ context }: ConstructorParams) {\n this._context = context;\n this.table = defineTable({\n context\n });\n\n this.entity = defineFilesEntity({\n context,\n table: this.table\n });\n }\n\n public async get(params: FileManagerFilesStorageOperationsGetParams): Promise<File | null> {\n const { where } = params;\n const keys = {\n PK: this.createPartitionKey(where),\n SK: this.createSortKey(where)\n };\n try {\n const file = await getEntityItem<File>({\n entity: this.entity,\n keys\n });\n return cleanupItem<File>(this.entity, file);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not fetch requested file.\",\n ex.code || \"GET_FILE_ERROR\",\n {\n error: ex,\n where\n }\n );\n }\n }\n\n public async create(params: FileManagerFilesStorageOperationsCreateParams): Promise<File> {\n const { file } = params;\n\n const keys = {\n PK: this.createPartitionKey(file),\n SK: this.createSortKey(file)\n };\n const item: FileItem = {\n ...file,\n ...keys,\n TYPE: \"fm.file\"\n };\n try {\n await this.entity.put(item);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create a new file in the DynamoDB.\",\n ex.code || \"CREATE_FILE_ERROR\",\n {\n error: ex,\n item\n }\n );\n }\n\n return file;\n }\n\n public async update(params: FileManagerFilesStorageOperationsUpdateParams): Promise<File> {\n const { file } = params;\n const keys = {\n PK: this.createPartitionKey(file),\n SK: this.createSortKey(file)\n };\n\n const item: FileItem = {\n ...file,\n ...keys,\n TYPE: \"fm.file\"\n };\n try {\n await this.entity.put(item);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update a file in the DynamoDB.\",\n ex.code || \"UPDATE_FILE_ERROR\",\n {\n error: ex,\n item\n }\n );\n }\n return file;\n }\n\n public async delete(params: FileManagerFilesStorageOperationsDeleteParams): Promise<void> {\n const { file } = params;\n const keys = {\n PK: this.createPartitionKey(file),\n SK: this.createSortKey(file)\n };\n\n try {\n await this.entity.delete(keys);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete file from the DynamoDB.\",\n ex.code || \"DELETE_FILE_ERROR\",\n {\n error: ex,\n file,\n keys\n }\n );\n }\n }\n\n public async createBatch(\n params: FileManagerFilesStorageOperationsCreateBatchParams\n ): Promise<File[]> {\n const { files } = params;\n\n const items = files.map(file => {\n return this.entity.putBatch({\n ...file,\n PK: this.createPartitionKey(file),\n SK: this.createSortKey(file),\n TYPE: \"fm.file\"\n });\n });\n\n try {\n await batchWriteAll({\n table: this.entity.table,\n items\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not batch insert a list of files.\",\n ex.code || \"BATCH_CREATE_FILES_ERROR\",\n {\n error: ex,\n files\n }\n );\n }\n return files;\n }\n\n public async list(\n params: FileManagerFilesStorageOperationsListParams\n ): Promise<FileManagerFilesStorageOperationsListResponse> {\n const { where: initialWhere, limit, after, sort } = params;\n\n const options = this.createQueryAllOptions({\n where: initialWhere\n });\n const queryAllParams = {\n entity: this.entity,\n partitionKey: this.createPartitionKey(initialWhere),\n options\n };\n let items = [];\n try {\n items = await queryAll<File>(queryAllParams);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not query for the files.\",\n ex.code || \"FILE_LIST_ERROR\",\n {\n error: ex,\n where: initialWhere,\n limit,\n after,\n sort,\n queryParams: {\n options,\n partitionKey: queryAllParams.partitionKey,\n entity: queryAllParams.entity.name,\n table: queryAllParams.entity.table.name\n }\n }\n );\n }\n\n const where: Partial<FileManagerFilesStorageOperationsListParamsWhere> & {\n contains?: { fields: string[]; value: string };\n } = {\n ...initialWhere\n };\n if (where.search) {\n where.contains = {\n fields: [\"name\", \"tags\"],\n value: where.search\n };\n }\n delete where[\"tenant\"];\n delete where[\"locale\"];\n delete where[\"search\"];\n\n const fields = this.context.plugins.byType<FileDynamoDbFieldPlugin>(\n FileDynamoDbFieldPlugin.type\n );\n /**\n * Filter the read items via the code.\n * It will build the filters out of the where input and transform the values it is using.\n */\n const filteredFiles = filterItems({\n plugins: this.context.plugins,\n items,\n where,\n fields\n });\n\n const totalCount = filteredFiles.length;\n /**\n * Sorting is also done via the code.\n * It takes the sort input and sorts by it via the lodash sortBy method.\n */\n const sortedFiles = sortItems({\n items: filteredFiles,\n sort,\n fields\n });\n\n const start = parseInt(decodeCursor(after) || \"0\") || 0;\n const hasMoreItems = totalCount > start + limit;\n const end = limit > totalCount + start + limit ? undefined : start + limit;\n const files = sortedFiles.slice(start, end);\n /**\n * Although we do not need a cursor here, we will use it as such to keep it standardized.\n * Number is simply encoded.\n */\n const cursor = files.length > 0 ? encodeCursor(start + limit) : null;\n\n const meta = {\n hasMoreItems,\n totalCount: totalCount,\n cursor\n };\n\n return [files, meta];\n }\n\n public async tags(\n params: FileManagerFilesStorageOperationsTagsParams\n ): Promise<FileManagerFilesStorageOperationsTagsResponse> {\n const { where: initialWhere } = params;\n\n const queryAllParams = {\n entity: this.entity,\n partitionKey: this.createPartitionKey(initialWhere),\n options: {\n gte: \" \",\n reverse: false\n }\n };\n let results = [];\n try {\n results = await queryAll<File>(queryAllParams);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Error in the DynamoDB query.\",\n ex.code || \"DYNAMODB_ERROR\",\n {\n error: ex,\n query: queryAllParams\n }\n );\n }\n\n const fields = this.context.plugins.byType<FileDynamoDbFieldPlugin>(\n FileDynamoDbFieldPlugin.type\n );\n\n const where: Partial<FileManagerFilesStorageOperationsTagsParamsWhere> = {\n ...initialWhere\n };\n\n delete where[\"tenant\"];\n delete where[\"locale\"];\n\n /**\n * Filter the read items via the code.\n * It will build the filters out of the where input and transform the values it is using.\n */\n const filteredItems = filterItems({\n plugins: this.context.plugins,\n items: results,\n where,\n fields\n });\n\n /**\n * Aggregate all the tags from all the filtered items.\n */\n const tagsObject = filteredItems.reduce((collection, item) => {\n const tags = Array.isArray(item.tags) ? item.tags : [];\n for (const tag of tags) {\n if (!collection[tag]) {\n collection[tag] = [];\n }\n collection[tag].push(item.id);\n }\n return collection;\n }, {} as Record<string, string[]>);\n\n const tags: string[] = Object.keys(tagsObject);\n\n const hasMoreItems = false;\n const totalCount = tags.length;\n\n const meta: FileManagerFilesStorageOperationsListResponseMeta = {\n hasMoreItems,\n totalCount,\n cursor: null\n };\n\n return [tags, meta];\n }\n\n private createQueryAllOptions({ where }: QueryAllOptionsParams): DynamoDBToolboxQueryOptions {\n const options: DynamoDBToolboxQueryOptions = {};\n if (where.id) {\n options.eq = where.id;\n }\n return options;\n }\n\n private createPartitionKey(params: CreatePartitionKeyParams): string {\n const { tenant, locale } = params;\n return `T#${tenant}#L#${locale}#FM#F`;\n }\n\n private createSortKey(params: CreateSortKeyParams) {\n const { id } = params;\n\n return id;\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAkBA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAyBO,MAAMA,sBAAN,CAA0E;EAK1D,IAAPC,OAAO,GAAuB;IACtC,OAAO,KAAKC,QAAZ;EACH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;IAEA,MAAMY,IAAuD,GAAG;MAC5DN,YAD4D;MAE5DP,UAF4D;MAG5DW,MAAM,EAAE;IAHoD,CAAhE;IAMA,OAAO,CAACG,IAAD,EAAOD,IAAP,CAAP;EACH;;EAEO7B,qBAAqB,CAAC;IAAEhC;EAAF,CAAD,EAAgE;IACzF,MAAM+B,OAAoC,GAAG,EAA7C;;IACA,IAAI/B,KAAK,CAAC2E,EAAV,EAAc;MACV5C,OAAO,CAAC8C,EAAR,GAAa7E,KAAK,CAAC2E,EAAnB;IACH;;IACD,OAAO5C,OAAP;EACH;;EAEO5B,kBAAkB,CAACJ,MAAD,EAA2C;IACjE,MAAM;MAAE+E,MAAF;MAAUC;IAAV,IAAqBhF,MAA3B;IACA,OAAQ,KAAI+E,MAAO,MAAKC,MAAO,OAA/B;EACH;;EAEO1E,aAAa,CAACN,MAAD,EAA8B;IAC/C,MAAM;MAAE4E;IAAF,IAAS5E,MAAf;IAEA,OAAO4E,EAAP;EACH;;AAvV4E"}
|
|
1
|
+
{"version":3,"names":["FilesStorageOperations","constructor","documentClient","plugins","table","createTable","fileEntity","createStandardEntity","aliasEntity","get","params","where","keys","PK","createPartitionKey","SK","file","getEntityItem","entity","data","ex","WebinyError","message","code","error","create","items","item","GSI1_PK","createGSI1PartitionKey","GSI1_SK","id","TYPE","push","putBatch","createNewAliasesRecords","forEach","alias","batchWriteAll","update","existingAliases","queryAll","partitionKey","tenant","locale","options","beginsWith","newAliases","map","aliases","some","deleteBatch","delete","aliasItems","createBatch","files","list","initialWhere","limit","after","sort","createQueryAllOptions","queryAllParams","dbItems","queryParams","name","search","contains","fields","value","byType","FileDynamoDbFieldPlugin","type","filteredFiles","filterItems","totalCount","length","sortedFiles","sortItems","start","parseInt","decodeCursor","hasMoreItems","end","undefined","slice","cursor","encodeCursor","meta","tags","index","gte","reverse","results","query","filteredItems","tagsObject","reduce","collection","Array","isArray","tag","Object","eq","gt","find","fileId","key","filter","Boolean"],"sources":["FilesStorageOperations.ts"],"sourcesContent":["import {\n File,\n FileAlias,\n FileManagerFilesStorageOperations,\n FileManagerFilesStorageOperationsCreateBatchParams,\n FileManagerFilesStorageOperationsCreateParams,\n FileManagerFilesStorageOperationsDeleteParams,\n FileManagerFilesStorageOperationsGetParams,\n FileManagerFilesStorageOperationsListParams,\n FileManagerFilesStorageOperationsListParamsWhere,\n FileManagerFilesStorageOperationsListResponse,\n FileManagerFilesStorageOperationsListResponseMeta,\n FileManagerFilesStorageOperationsTagsParams,\n FileManagerFilesStorageOperationsTagsParamsWhere,\n FileManagerFilesStorageOperationsTagsResponse,\n FileManagerFilesStorageOperationsUpdateParams\n} from \"@webiny/api-file-manager/types\";\nimport { Entity, Table } from \"dynamodb-toolbox\";\nimport WebinyError from \"@webiny/error\";\nimport { createTable } from \"~/definitions/table\";\nimport { queryOptions as DynamoDBToolboxQueryOptions } from \"dynamodb-toolbox/dist/classes/Table\";\nimport { queryAll } from \"@webiny/db-dynamodb/utils/query\";\nimport { decodeCursor, encodeCursor } from \"@webiny/db-dynamodb/utils/cursor\";\nimport { filterItems } from \"@webiny/db-dynamodb/utils/filter\";\nimport { sortItems } from \"@webiny/db-dynamodb/utils/sort\";\nimport { FileDynamoDbFieldPlugin } from \"~/plugins/FileDynamoDbFieldPlugin\";\nimport { batchWriteAll } from \"@webiny/db-dynamodb/utils/batchWrite\";\nimport { get as getEntityItem } from \"@webiny/db-dynamodb/utils/get\";\nimport { createStandardEntity, DbItem } from \"@webiny/db-dynamodb\";\nimport { DocumentClient } from \"aws-sdk/clients/dynamodb\";\nimport { PluginsContainer } from \"@webiny/plugins\";\n\ntype FileItem = DbItem<File>;\ntype FileAliasItem = DbItem<FileAlias>;\n\ninterface ConstructorParams {\n documentClient: DocumentClient;\n plugins: PluginsContainer;\n}\n\ninterface QueryAllOptionsParams {\n where: FileManagerFilesStorageOperationsListParamsWhere;\n}\n\ninterface CreatePartitionKeyParams {\n locale: string;\n tenant: string;\n id: string;\n}\n\ntype CreateGSI1PartitionKeyParams = Pick<CreatePartitionKeyParams, \"tenant\" | \"locale\">;\n\nexport class FilesStorageOperations implements FileManagerFilesStorageOperations {\n private readonly plugins: PluginsContainer;\n private readonly table: Table;\n private readonly fileEntity: Entity<any>;\n private readonly aliasEntity: Entity<any>;\n\n public constructor({ documentClient, plugins }: ConstructorParams) {\n this.plugins = plugins;\n this.table = createTable({ documentClient });\n this.fileEntity = createStandardEntity(this.table, \"FM.File\");\n this.aliasEntity = createStandardEntity(this.table, \"FM.FileAlias\");\n }\n\n public async get(params: FileManagerFilesStorageOperationsGetParams): Promise<File | null> {\n const { where } = params;\n const keys = {\n PK: this.createPartitionKey(where),\n SK: \"A\"\n };\n try {\n const file = await getEntityItem<{ data: File }>({\n entity: this.fileEntity,\n keys\n });\n\n return file ? file.data : null;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not fetch requested file.\",\n ex.code || \"GET_FILE_ERROR\",\n {\n error: ex,\n where\n }\n );\n }\n }\n\n public async create(params: FileManagerFilesStorageOperationsCreateParams): Promise<File> {\n const { file } = params;\n\n const items: any[] = [];\n\n const item: FileItem = {\n PK: this.createPartitionKey(file),\n SK: \"A\",\n GSI1_PK: this.createGSI1PartitionKey(file),\n GSI1_SK: file.id,\n TYPE: \"fm.file\",\n data: file\n };\n\n items.push(this.fileEntity.putBatch(item));\n\n this.createNewAliasesRecords(file).forEach(alias => {\n items.push(this.aliasEntity.putBatch(alias));\n });\n\n try {\n await batchWriteAll({\n table: this.table,\n items\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create a new file in the DynamoDB.\",\n ex.code || \"CREATE_FILE_ERROR\",\n {\n error: ex,\n items\n }\n );\n }\n\n return file;\n }\n\n public async update(params: FileManagerFilesStorageOperationsUpdateParams): Promise<File> {\n const { file } = params;\n\n const items: any[] = [];\n\n const item: FileItem = {\n PK: this.createPartitionKey(file),\n SK: \"A\",\n GSI1_PK: this.createGSI1PartitionKey(file),\n GSI1_SK: file.id,\n TYPE: \"fm.file\",\n data: file\n };\n\n items.push(this.fileEntity.putBatch(item));\n\n const existingAliases = await queryAll<FileAliasItem>({\n entity: this.aliasEntity,\n partitionKey: `T#${file.tenant}#L#${file.locale}#FM#FILE#${file.id}`,\n options: {\n beginsWith: `ALIAS#`\n }\n });\n\n const newAliases = this.createNewAliasesRecords(\n file,\n existingAliases.map(alias => alias.data)\n );\n\n newAliases.forEach(alias => {\n items.push(this.aliasEntity.putBatch(alias));\n });\n\n // Delete aliases that are in the DB but are NOT in the file.\n for (const { data } of existingAliases) {\n if (!file.aliases.some(alias => data.alias === alias)) {\n items.push(\n this.aliasEntity.deleteBatch({\n PK: this.createPartitionKey(file),\n SK: `ALIAS#${data.alias}`\n })\n );\n }\n }\n\n try {\n await batchWriteAll({\n table: this.table,\n items\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update a file in the DynamoDB.\",\n ex.code || \"UPDATE_FILE_ERROR\",\n {\n items\n }\n );\n }\n return params.file;\n }\n\n public async delete(params: FileManagerFilesStorageOperationsDeleteParams): Promise<void> {\n const { file } = params;\n const keys = {\n PK: this.createPartitionKey(file),\n SK: \"A\"\n };\n\n const aliasItems = await queryAll({\n entity: this.aliasEntity,\n partitionKey: keys.PK,\n options: {\n beginsWith: \"ALIAS#\"\n }\n });\n\n // All items to delete in batch\n const items: any[] = [];\n\n try {\n // Delete the main file item\n items.push(this.fileEntity.deleteBatch(keys));\n\n // Delete file alias items\n aliasItems.forEach(item => {\n items.push(\n this.aliasEntity.deleteBatch({\n PK: item.PK,\n SK: item.SK\n })\n );\n });\n\n await batchWriteAll({ table: this.table, items });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete file from the DynamoDB.\",\n ex.code || \"DELETE_FILE_ERROR\",\n {\n error: ex,\n file,\n keys,\n aliasItems\n }\n );\n }\n }\n\n public async createBatch(\n params: FileManagerFilesStorageOperationsCreateBatchParams\n ): Promise<File[]> {\n const { files } = params;\n\n // Items to be written in batch\n const items: any[] = [];\n\n files.forEach(file => {\n items.push(\n this.fileEntity.putBatch({\n PK: this.createPartitionKey(file),\n SK: \"A\",\n GSI1_PK: this.createGSI1PartitionKey(file),\n GSI1_SK: file.id,\n TYPE: \"fm.file\",\n data: file\n })\n );\n\n this.createNewAliasesRecords(file).forEach(alias => {\n items.push(this.aliasEntity.putBatch(alias));\n });\n });\n\n try {\n await batchWriteAll({\n table: this.table,\n items\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not batch insert a list of files.\",\n ex.code || \"BATCH_CREATE_FILES_ERROR\",\n {\n error: ex,\n files\n }\n );\n }\n return files;\n }\n\n public async list(\n params: FileManagerFilesStorageOperationsListParams\n ): Promise<FileManagerFilesStorageOperationsListResponse> {\n const { where: initialWhere, limit, after, sort } = params;\n\n const options = this.createQueryAllOptions({\n where: initialWhere\n });\n const queryAllParams = {\n entity: this.fileEntity,\n partitionKey: this.createGSI1PartitionKey(initialWhere),\n options\n };\n let items = [];\n try {\n const dbItems = await queryAll<{ data: File }>(queryAllParams);\n items = dbItems.map(item => item.data);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not query for the files.\",\n ex.code || \"FILE_LIST_ERROR\",\n {\n error: ex,\n where: initialWhere,\n limit,\n after,\n sort,\n queryParams: {\n options,\n partitionKey: queryAllParams.partitionKey,\n entity: queryAllParams.entity.name,\n table: queryAllParams.entity.table.name\n }\n }\n );\n }\n\n const where: Partial<FileManagerFilesStorageOperationsListParamsWhere> & {\n contains?: { fields: string[]; value: string };\n } = {\n ...initialWhere\n };\n if (where.search) {\n where.contains = {\n fields: [\"name\", \"tags\"],\n value: where.search\n };\n }\n delete where[\"tenant\"];\n delete where[\"locale\"];\n delete where[\"search\"];\n\n const fields = this.plugins.byType<FileDynamoDbFieldPlugin>(FileDynamoDbFieldPlugin.type);\n /**\n * Filter the read items via the code.\n * It will build the filters out of the where input and transform the values it is using.\n */\n const filteredFiles = filterItems({\n plugins: this.plugins,\n items,\n where,\n fields\n });\n\n const totalCount = filteredFiles.length;\n /**\n * Sorting is also done via the code.\n * It takes the sort input and sorts by it via the lodash sortBy method.\n */\n const sortedFiles = sortItems({\n items: filteredFiles,\n sort,\n fields\n });\n\n const start = parseInt(decodeCursor(after) || \"0\") || 0;\n const hasMoreItems = totalCount > start + limit;\n const end = limit > totalCount + start + limit ? undefined : start + limit;\n const files = sortedFiles.slice(start, end);\n /**\n * Although we do not need a cursor here, we will use it as such to keep it standardized.\n * Number is simply encoded.\n */\n const cursor = files.length > 0 ? encodeCursor(start + limit) : null;\n\n const meta = {\n hasMoreItems,\n totalCount: totalCount,\n cursor\n };\n\n return [files, meta];\n }\n\n public async tags(\n params: FileManagerFilesStorageOperationsTagsParams\n ): Promise<FileManagerFilesStorageOperationsTagsResponse> {\n const { where: initialWhere } = params;\n\n const queryAllParams = {\n entity: this.fileEntity,\n partitionKey: this.createGSI1PartitionKey(initialWhere),\n options: {\n index: \"GSI1\",\n gte: \" \",\n reverse: false\n }\n };\n let results = [];\n try {\n const dbItems = await queryAll<{ data: File }>(queryAllParams);\n results = dbItems.map(item => item.data);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Error in the DynamoDB query.\",\n ex.code || \"DYNAMODB_ERROR\",\n {\n error: ex,\n query: queryAllParams\n }\n );\n }\n\n const fields = this.plugins.byType<FileDynamoDbFieldPlugin>(FileDynamoDbFieldPlugin.type);\n\n const where: Partial<FileManagerFilesStorageOperationsTagsParamsWhere> = {\n ...initialWhere\n };\n\n delete where[\"tenant\"];\n delete where[\"locale\"];\n\n /**\n * Filter the read items via the code.\n * It will build the filters out of the where input and transform the values it is using.\n */\n const filteredItems = filterItems({\n plugins: this.plugins,\n items: results,\n where,\n fields\n });\n\n /**\n * Aggregate all the tags from all the filtered items.\n */\n const tagsObject = filteredItems.reduce((collection, item) => {\n const tags = Array.isArray(item.tags) ? item.tags : [];\n for (const tag of tags) {\n if (!collection[tag]) {\n collection[tag] = [];\n }\n collection[tag].push(item.id);\n }\n return collection;\n }, {} as Record<string, string[]>);\n\n const tags: string[] = Object.keys(tagsObject);\n\n const hasMoreItems = false;\n const totalCount = tags.length;\n\n const meta: FileManagerFilesStorageOperationsListResponseMeta = {\n hasMoreItems,\n totalCount,\n cursor: null\n };\n\n return [tags, meta];\n }\n\n private createQueryAllOptions({ where }: QueryAllOptionsParams): DynamoDBToolboxQueryOptions {\n const options: DynamoDBToolboxQueryOptions = { index: \"GSI1\" };\n if (where.id) {\n options.eq = where.id;\n } else {\n options.gt = \" \";\n }\n return options;\n }\n\n private createPartitionKey(params: CreatePartitionKeyParams): string {\n const { tenant, locale, id } = params;\n return `T#${tenant}#L#${locale}#FM#FILE#${id}`;\n }\n private createGSI1PartitionKey(params: CreateGSI1PartitionKeyParams): string {\n const { tenant, locale } = params;\n return `T#${tenant}#L#${locale}#FM#FILES`;\n }\n\n private createNewAliasesRecords(\n file: File,\n existingAliases: FileAlias[] = []\n ): FileAliasItem[] {\n return (file.aliases || [])\n .map(alias => {\n // If alias is already in the DB, skip it.\n if (existingAliases.find(item => item.alias === alias)) {\n return null;\n }\n\n // Add a new alias.\n return {\n PK: this.createPartitionKey(file),\n SK: `ALIAS#${alias}`,\n GSI1_PK: `T#${file.tenant}#FM#FILE_ALIASES`,\n GSI1_SK: alias,\n TYPE: \"fm.fileAlias\",\n data: {\n alias,\n tenant: file.tenant,\n locale: file.locale,\n fileId: file.id,\n key: file.key\n }\n };\n })\n .filter(Boolean) as FileAliasItem[];\n }\n}\n"],"mappings":";;;;;;;;;AAkBA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAwBO,MAAMA,sBAAsB,CAA8C;EAMtEC,WAAW,CAAC;IAAEC,cAAc;IAAEC;EAA2B,CAAC,EAAE;IAAA;IAAA;IAAA;IAAA;IAC/D,IAAI,CAACA,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACC,KAAK,GAAG,IAAAC,kBAAW,EAAC;MAAEH;IAAe,CAAC,CAAC;IAC5C,IAAI,CAACI,UAAU,GAAG,IAAAC,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AAI,EAAE;UACFkB,KAAK;UACLM,MAAM,EAAE3B,IAAI,CAAC2B,MAAM;UACnBC,MAAM,EAAE5B,IAAI,CAAC4B,MAAM;UACnB8D,MAAM,EAAE1F,IAAI,CAACe,EAAE;UACf4E,GAAG,EAAE3F,IAAI,CAAC2F;QACd;MACJ,CAAC;IACL,CAAC,CAAC,CACDC,MAAM,CAACC,OAAO,CAAC;EACxB;AACJ;AAAC"}
|
|
@@ -3,11 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
|
|
6
|
+
exports.createFileFieldsPlugins = void 0;
|
|
8
7
|
var _FileDynamoDbFieldPlugin = require("../../plugins/FileDynamoDbFieldPlugin");
|
|
9
|
-
|
|
10
|
-
var _default = () => [new _FileDynamoDbFieldPlugin.FileDynamoDbFieldPlugin({
|
|
8
|
+
const createFileFieldsPlugins = () => [new _FileDynamoDbFieldPlugin.FileDynamoDbFieldPlugin({
|
|
11
9
|
field: "id"
|
|
12
10
|
}),
|
|
13
11
|
/**
|
|
@@ -38,5 +36,4 @@ new _FileDynamoDbFieldPlugin.FileDynamoDbFieldPlugin({
|
|
|
38
36
|
field: "createdOn",
|
|
39
37
|
type: "date"
|
|
40
38
|
})];
|
|
41
|
-
|
|
42
|
-
exports.default = _default;
|
|
39
|
+
exports.createFileFieldsPlugins = createFileFieldsPlugins;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["FileDynamoDbFieldPlugin","field","path","type"],"sources":["fields.ts"],"sourcesContent":["import { FileDynamoDbFieldPlugin } from \"~/plugins/FileDynamoDbFieldPlugin\";\n\nexport
|
|
1
|
+
{"version":3,"names":["createFileFieldsPlugins","FileDynamoDbFieldPlugin","field","path","type"],"sources":["fields.ts"],"sourcesContent":["import { FileDynamoDbFieldPlugin } from \"~/plugins/FileDynamoDbFieldPlugin\";\n\nexport const createFileFieldsPlugins = () => [\n new FileDynamoDbFieldPlugin({\n field: \"id\"\n }),\n /**\n * Path plugin for the field that are ddb map type and the value filtered by is the id property in the object.\n */\n new FileDynamoDbFieldPlugin({\n field: \"createdBy\",\n path: \"createdBy.id\"\n }),\n /**\n * Path plugin for meta field properties.\n */\n new FileDynamoDbFieldPlugin({\n field: \"private\",\n path: \"meta.private\"\n }),\n /**\n * Path plugin for tag field.\n */\n new FileDynamoDbFieldPlugin({\n field: \"tag\",\n path: \"tags\"\n }),\n /**\n * Value transformation for the dateTime field.\n */\n new FileDynamoDbFieldPlugin({\n field: \"createdOn\",\n type: \"date\"\n })\n];\n"],"mappings":";;;;;;AAAA;AAEO,MAAMA,uBAAuB,GAAG,MAAM,CACzC,IAAIC,gDAAuB,CAAC;EACxBC,KAAK,EAAE;AACX,CAAC,CAAC;AACF;AACJ;AACA;AACI,IAAID,gDAAuB,CAAC;EACxBC,KAAK,EAAE,WAAW;EAClBC,IAAI,EAAE;AACV,CAAC,CAAC;AACF;AACJ;AACA;AACI,IAAIF,gDAAuB,CAAC;EACxBC,KAAK,EAAE,SAAS;EAChBC,IAAI,EAAE;AACV,CAAC,CAAC;AACF;AACJ;AACA;AACI,IAAIF,gDAAuB,CAAC;EACxBC,KAAK,EAAE,KAAK;EACZC,IAAI,EAAE;AACV,CAAC,CAAC;AACF;AACJ;AACA;AACI,IAAIF,gDAAuB,CAAC;EACxBC,KAAK,EAAE,WAAW;EAClBE,IAAI,EAAE;AACV,CAAC,CAAC,CACL;AAAC"}
|