@webiny/api-file-manager-ddb 0.0.0-unstable.e3f4727c56 → 0.0.0-unstable.ecd8734205
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.
|
@@ -1,38 +1,76 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
6
8
|
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
+
|
|
7
12
|
var _dynamodbToolbox = require("dynamodb-toolbox");
|
|
13
|
+
|
|
14
|
+
var _attributes = require("@webiny/db-dynamodb/utils/attributes");
|
|
15
|
+
|
|
8
16
|
var _default = params => {
|
|
9
17
|
const {
|
|
18
|
+
context,
|
|
10
19
|
table
|
|
11
20
|
} = params;
|
|
12
|
-
const entityName = "
|
|
21
|
+
const entityName = "Files";
|
|
22
|
+
const attributes = (0, _attributes.getExtraAttributes)(context, entityName);
|
|
13
23
|
return new _dynamodbToolbox.Entity({
|
|
14
24
|
name: entityName,
|
|
15
25
|
table,
|
|
16
|
-
attributes: {
|
|
26
|
+
attributes: (0, _objectSpread2.default)({
|
|
17
27
|
PK: {
|
|
18
28
|
partitionKey: true
|
|
19
29
|
},
|
|
20
30
|
SK: {
|
|
21
31
|
sortKey: true
|
|
22
32
|
},
|
|
23
|
-
|
|
33
|
+
TYPE: {
|
|
34
|
+
type: "string"
|
|
35
|
+
},
|
|
36
|
+
id: {
|
|
24
37
|
type: "string"
|
|
25
38
|
},
|
|
26
|
-
|
|
39
|
+
key: {
|
|
27
40
|
type: "string"
|
|
28
41
|
},
|
|
29
|
-
|
|
42
|
+
size: {
|
|
43
|
+
type: "number"
|
|
44
|
+
},
|
|
45
|
+
type: {
|
|
46
|
+
type: "string"
|
|
47
|
+
},
|
|
48
|
+
name: {
|
|
30
49
|
type: "string"
|
|
31
50
|
},
|
|
32
|
-
|
|
51
|
+
meta: {
|
|
33
52
|
type: "map"
|
|
53
|
+
},
|
|
54
|
+
tags: {
|
|
55
|
+
type: "list"
|
|
56
|
+
},
|
|
57
|
+
createdOn: {
|
|
58
|
+
type: "string"
|
|
59
|
+
},
|
|
60
|
+
createdBy: {
|
|
61
|
+
type: "map"
|
|
62
|
+
},
|
|
63
|
+
tenant: {
|
|
64
|
+
type: "string"
|
|
65
|
+
},
|
|
66
|
+
locale: {
|
|
67
|
+
type: "string"
|
|
68
|
+
},
|
|
69
|
+
webinyVersion: {
|
|
70
|
+
type: "string"
|
|
34
71
|
}
|
|
35
|
-
}
|
|
72
|
+
}, attributes)
|
|
36
73
|
});
|
|
37
74
|
};
|
|
75
|
+
|
|
38
76
|
exports.default = _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["params","table","entityName","
|
|
1
|
+
{"version":3,"names":["params","context","table","entityName","attributes","getExtraAttributes","Entity","name","PK","partitionKey","SK","sortKey","TYPE","type","id","key","size","meta","tags","createdOn","createdBy","tenant","locale","webinyVersion"],"sources":["filesEntity.ts"],"sourcesContent":["import { Entity, Table } from \"dynamodb-toolbox\";\nimport { FileManagerContext } from \"@webiny/api-file-manager/types\";\nimport { getExtraAttributes } from \"@webiny/db-dynamodb/utils/attributes\";\n\nexport interface FilesEntityParams {\n context: FileManagerContext;\n table: Table;\n}\nexport default (params: FilesEntityParams): Entity<any> => {\n const { context, table } = params;\n const entityName = \"Files\";\n const attributes = getExtraAttributes(context, entityName);\n return new Entity({\n name: entityName,\n table,\n attributes: {\n PK: {\n partitionKey: true\n },\n SK: {\n sortKey: true\n },\n TYPE: {\n type: \"string\"\n },\n id: {\n type: \"string\"\n },\n key: {\n type: \"string\"\n },\n size: {\n type: \"number\"\n },\n type: {\n type: \"string\"\n },\n name: {\n type: \"string\"\n },\n meta: {\n type: \"map\"\n },\n tags: {\n type: \"list\"\n },\n createdOn: {\n type: \"string\"\n },\n createdBy: {\n type: \"map\"\n },\n tenant: {\n type: \"string\"\n },\n locale: {\n type: \"string\"\n },\n webinyVersion: {\n type: \"string\"\n },\n ...attributes\n }\n });\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAEA;;eAMgBA,MAAD,IAA4C;EACvD,MAAM;IAAEC,OAAF;IAAWC;EAAX,IAAqBF,MAA3B;EACA,MAAMG,UAAU,GAAG,OAAnB;EACA,MAAMC,UAAU,GAAG,IAAAC,8BAAA,EAAmBJ,OAAnB,EAA4BE,UAA5B,CAAnB;EACA,OAAO,IAAIG,uBAAJ,CAAW;IACdC,IAAI,EAAEJ,UADQ;IAEdD,KAFc;IAGdE,UAAU;MACNI,EAAE,EAAE;QACAC,YAAY,EAAE;MADd,CADE;MAINC,EAAE,EAAE;QACAC,OAAO,EAAE;MADT,CAJE;MAONC,IAAI,EAAE;QACFC,IAAI,EAAE;MADJ,CAPA;MAUNC,EAAE,EAAE;QACAD,IAAI,EAAE;MADN,CAVE;MAaNE,GAAG,EAAE;QACDF,IAAI,EAAE;MADL,CAbC;MAgBNG,IAAI,EAAE;QACFH,IAAI,EAAE;MADJ,CAhBA;MAmBNA,IAAI,EAAE;QACFA,IAAI,EAAE;MADJ,CAnBA;MAsBNN,IAAI,EAAE;QACFM,IAAI,EAAE;MADJ,CAtBA;MAyBNI,IAAI,EAAE;QACFJ,IAAI,EAAE;MADJ,CAzBA;MA4BNK,IAAI,EAAE;QACFL,IAAI,EAAE;MADJ,CA5BA;MA+BNM,SAAS,EAAE;QACPN,IAAI,EAAE;MADC,CA/BL;MAkCNO,SAAS,EAAE;QACPP,IAAI,EAAE;MADC,CAlCL;MAqCNQ,MAAM,EAAE;QACJR,IAAI,EAAE;MADF,CArCF;MAwCNS,MAAM,EAAE;QACJT,IAAI,EAAE;MADF,CAxCF;MA2CNU,aAAa,EAAE;QACXV,IAAI,EAAE;MADK;IA3CT,GA8CHT,UA9CG;EAHI,CAAX,CAAP;AAoDH,C"}
|
|
@@ -5,7 +5,8 @@ interface ConstructorParams {
|
|
|
5
5
|
export declare class FilesStorageOperations implements FileManagerFilesStorageOperations {
|
|
6
6
|
private readonly _context;
|
|
7
7
|
private readonly table;
|
|
8
|
-
private readonly
|
|
8
|
+
private readonly fileEntity;
|
|
9
|
+
private readonly aliasEntity;
|
|
9
10
|
private get context();
|
|
10
11
|
constructor({ context }: ConstructorParams);
|
|
11
12
|
get(params: FileManagerFilesStorageOperationsGetParams): Promise<File | null>;
|
|
@@ -18,5 +19,6 @@ export declare class FilesStorageOperations implements FileManagerFilesStorageOp
|
|
|
18
19
|
private createQueryAllOptions;
|
|
19
20
|
private createPartitionKey;
|
|
20
21
|
private createGSI1PartitionKey;
|
|
22
|
+
private createNewAliasesRecords;
|
|
21
23
|
}
|
|
22
24
|
export {};
|
|
@@ -9,7 +9,6 @@ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/obje
|
|
|
9
9
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
10
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
11
|
var _table = _interopRequireDefault(require("../../definitions/table"));
|
|
12
|
-
var _filesEntity = _interopRequireDefault(require("../../definitions/filesEntity"));
|
|
13
12
|
var _query = require("@webiny/db-dynamodb/utils/query");
|
|
14
13
|
var _cursor = require("@webiny/db-dynamodb/utils/cursor");
|
|
15
14
|
var _filter = require("@webiny/db-dynamodb/utils/filter");
|
|
@@ -17,6 +16,7 @@ var _sort = require("@webiny/db-dynamodb/utils/sort");
|
|
|
17
16
|
var _FileDynamoDbFieldPlugin = require("../../plugins/FileDynamoDbFieldPlugin");
|
|
18
17
|
var _batchWrite = require("@webiny/db-dynamodb/utils/batchWrite");
|
|
19
18
|
var _get = require("@webiny/db-dynamodb/utils/get");
|
|
19
|
+
var _dbDynamodb = require("@webiny/db-dynamodb");
|
|
20
20
|
class FilesStorageOperations {
|
|
21
21
|
get context() {
|
|
22
22
|
return this._context;
|
|
@@ -26,15 +26,14 @@ class FilesStorageOperations {
|
|
|
26
26
|
}) {
|
|
27
27
|
(0, _defineProperty2.default)(this, "_context", void 0);
|
|
28
28
|
(0, _defineProperty2.default)(this, "table", void 0);
|
|
29
|
-
(0, _defineProperty2.default)(this, "
|
|
29
|
+
(0, _defineProperty2.default)(this, "fileEntity", void 0);
|
|
30
|
+
(0, _defineProperty2.default)(this, "aliasEntity", void 0);
|
|
30
31
|
this._context = context;
|
|
31
32
|
this.table = (0, _table.default)({
|
|
32
33
|
context
|
|
33
34
|
});
|
|
34
|
-
this.
|
|
35
|
-
|
|
36
|
-
table: this.table
|
|
37
|
-
});
|
|
35
|
+
this.fileEntity = (0, _dbDynamodb.createStandardEntity)(this.table, "FM.File");
|
|
36
|
+
this.aliasEntity = (0, _dbDynamodb.createStandardEntity)(this.table, "FM.FileAlias");
|
|
38
37
|
}
|
|
39
38
|
async get(params) {
|
|
40
39
|
const {
|
|
@@ -46,7 +45,7 @@ class FilesStorageOperations {
|
|
|
46
45
|
};
|
|
47
46
|
try {
|
|
48
47
|
const file = await (0, _get.get)({
|
|
49
|
-
entity: this.
|
|
48
|
+
entity: this.fileEntity,
|
|
50
49
|
keys
|
|
51
50
|
});
|
|
52
51
|
return file ? file.data : null;
|
|
@@ -61,6 +60,7 @@ class FilesStorageOperations {
|
|
|
61
60
|
const {
|
|
62
61
|
file
|
|
63
62
|
} = params;
|
|
63
|
+
const items = [];
|
|
64
64
|
const item = {
|
|
65
65
|
PK: this.createPartitionKey(file),
|
|
66
66
|
SK: "A",
|
|
@@ -69,24 +69,69 @@ class FilesStorageOperations {
|
|
|
69
69
|
TYPE: "fm.file",
|
|
70
70
|
data: file
|
|
71
71
|
};
|
|
72
|
+
items.push(this.fileEntity.putBatch(item));
|
|
73
|
+
this.createNewAliasesRecords(file).forEach(alias => {
|
|
74
|
+
items.push(this.aliasEntity.putBatch(alias));
|
|
75
|
+
});
|
|
72
76
|
try {
|
|
73
|
-
await
|
|
77
|
+
await (0, _batchWrite.batchWriteAll)({
|
|
78
|
+
table: this.table,
|
|
79
|
+
items
|
|
80
|
+
});
|
|
74
81
|
} catch (ex) {
|
|
75
82
|
throw new _error.default(ex.message || "Could not create a new file in the DynamoDB.", ex.code || "CREATE_FILE_ERROR", {
|
|
76
83
|
error: ex,
|
|
77
|
-
|
|
84
|
+
items
|
|
78
85
|
});
|
|
79
86
|
}
|
|
80
87
|
return file;
|
|
81
88
|
}
|
|
82
89
|
async update(params) {
|
|
90
|
+
const {
|
|
91
|
+
file
|
|
92
|
+
} = params;
|
|
93
|
+
const items = [];
|
|
94
|
+
const item = {
|
|
95
|
+
PK: this.createPartitionKey(file),
|
|
96
|
+
SK: "A",
|
|
97
|
+
GSI1_PK: this.createGSI1PartitionKey(file),
|
|
98
|
+
GSI1_SK: file.id,
|
|
99
|
+
TYPE: "fm.file",
|
|
100
|
+
data: file
|
|
101
|
+
};
|
|
102
|
+
items.push(this.fileEntity.putBatch(item));
|
|
103
|
+
const existingAliases = await (0, _query.queryAll)({
|
|
104
|
+
entity: this.aliasEntity,
|
|
105
|
+
partitionKey: `T#${file.tenant}#L#${file.locale}#FM#FILE#${file.id}`,
|
|
106
|
+
options: {
|
|
107
|
+
beginsWith: `ALIAS#`
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
const newAliases = this.createNewAliasesRecords(file, existingAliases.map(alias => alias.data));
|
|
111
|
+
newAliases.forEach(alias => {
|
|
112
|
+
items.push(this.aliasEntity.putBatch(alias));
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// Delete aliases that are in the DB but are NOT in the file.
|
|
116
|
+
for (const {
|
|
117
|
+
data
|
|
118
|
+
} of existingAliases) {
|
|
119
|
+
if (!file.aliases.some(alias => data.alias === alias)) {
|
|
120
|
+
items.push(this.aliasEntity.deleteBatch({
|
|
121
|
+
PK: this.createPartitionKey(file),
|
|
122
|
+
SK: `ALIAS#${data.alias}`
|
|
123
|
+
}));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
83
126
|
try {
|
|
84
|
-
await
|
|
127
|
+
await (0, _batchWrite.batchWriteAll)({
|
|
128
|
+
table: this.table,
|
|
129
|
+
items
|
|
130
|
+
});
|
|
85
131
|
} catch (ex) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
throw ex;
|
|
132
|
+
throw new _error.default(ex.message || "Could not update a file in the DynamoDB.", ex.code || "UPDATE_FILE_ERROR", {
|
|
133
|
+
items
|
|
134
|
+
});
|
|
90
135
|
}
|
|
91
136
|
return params.file;
|
|
92
137
|
}
|
|
@@ -98,13 +143,37 @@ class FilesStorageOperations {
|
|
|
98
143
|
PK: this.createPartitionKey(file),
|
|
99
144
|
SK: "A"
|
|
100
145
|
};
|
|
146
|
+
const aliasItems = await (0, _query.queryAll)({
|
|
147
|
+
entity: this.aliasEntity,
|
|
148
|
+
partitionKey: keys.PK,
|
|
149
|
+
options: {
|
|
150
|
+
beginsWith: "ALIAS#"
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
// All items to delete in batch
|
|
155
|
+
const items = [];
|
|
101
156
|
try {
|
|
102
|
-
|
|
157
|
+
// Delete the main file item
|
|
158
|
+
items.push(this.fileEntity.deleteBatch(keys));
|
|
159
|
+
|
|
160
|
+
// Delete file alias items
|
|
161
|
+
aliasItems.forEach(item => {
|
|
162
|
+
items.push(this.aliasEntity.deleteBatch({
|
|
163
|
+
PK: item.PK,
|
|
164
|
+
SK: item.SK
|
|
165
|
+
}));
|
|
166
|
+
});
|
|
167
|
+
await (0, _batchWrite.batchWriteAll)({
|
|
168
|
+
table: this.table,
|
|
169
|
+
items
|
|
170
|
+
});
|
|
103
171
|
} catch (ex) {
|
|
104
172
|
throw new _error.default(ex.message || "Could not delete file from the DynamoDB.", ex.code || "DELETE_FILE_ERROR", {
|
|
105
173
|
error: ex,
|
|
106
174
|
file,
|
|
107
|
-
keys
|
|
175
|
+
keys,
|
|
176
|
+
aliasItems
|
|
108
177
|
});
|
|
109
178
|
}
|
|
110
179
|
}
|
|
@@ -112,19 +181,25 @@ class FilesStorageOperations {
|
|
|
112
181
|
const {
|
|
113
182
|
files
|
|
114
183
|
} = params;
|
|
115
|
-
|
|
116
|
-
|
|
184
|
+
|
|
185
|
+
// Items to be written in batch
|
|
186
|
+
const items = [];
|
|
187
|
+
files.forEach(file => {
|
|
188
|
+
items.push(this.fileEntity.putBatch({
|
|
117
189
|
PK: this.createPartitionKey(file),
|
|
118
190
|
SK: "A",
|
|
119
191
|
GSI1_PK: this.createGSI1PartitionKey(file),
|
|
120
192
|
GSI1_SK: file.id,
|
|
121
193
|
TYPE: "fm.file",
|
|
122
194
|
data: file
|
|
195
|
+
}));
|
|
196
|
+
this.createNewAliasesRecords(file).forEach(alias => {
|
|
197
|
+
items.push(this.aliasEntity.putBatch(alias));
|
|
123
198
|
});
|
|
124
199
|
});
|
|
125
200
|
try {
|
|
126
201
|
await (0, _batchWrite.batchWriteAll)({
|
|
127
|
-
table: this.
|
|
202
|
+
table: this.table,
|
|
128
203
|
items
|
|
129
204
|
});
|
|
130
205
|
} catch (ex) {
|
|
@@ -146,7 +221,7 @@ class FilesStorageOperations {
|
|
|
146
221
|
where: initialWhere
|
|
147
222
|
});
|
|
148
223
|
const queryAllParams = {
|
|
149
|
-
entity: this.
|
|
224
|
+
entity: this.fileEntity,
|
|
150
225
|
partitionKey: this.createGSI1PartitionKey(initialWhere),
|
|
151
226
|
options
|
|
152
227
|
};
|
|
@@ -221,7 +296,7 @@ class FilesStorageOperations {
|
|
|
221
296
|
where: initialWhere
|
|
222
297
|
} = params;
|
|
223
298
|
const queryAllParams = {
|
|
224
|
-
entity: this.
|
|
299
|
+
entity: this.fileEntity,
|
|
225
300
|
partitionKey: this.createGSI1PartitionKey(initialWhere),
|
|
226
301
|
options: {
|
|
227
302
|
index: "GSI1",
|
|
@@ -306,5 +381,29 @@ class FilesStorageOperations {
|
|
|
306
381
|
} = params;
|
|
307
382
|
return `T#${tenant}#L#${locale}#FM#FILES`;
|
|
308
383
|
}
|
|
384
|
+
createNewAliasesRecords(file, existingAliases = []) {
|
|
385
|
+
return (file.aliases || []).map(alias => {
|
|
386
|
+
// If alias is already in the DB, skip it.
|
|
387
|
+
if (existingAliases.find(item => item.alias === alias)) {
|
|
388
|
+
return null;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// Add a new alias.
|
|
392
|
+
return {
|
|
393
|
+
PK: this.createPartitionKey(file),
|
|
394
|
+
SK: `ALIAS#${alias}`,
|
|
395
|
+
GSI1_PK: `T#${file.tenant}#FM#FILE_ALIASES`,
|
|
396
|
+
GSI1_SK: alias,
|
|
397
|
+
TYPE: "fm.fileAlias",
|
|
398
|
+
data: {
|
|
399
|
+
alias,
|
|
400
|
+
tenant: file.tenant,
|
|
401
|
+
locale: file.locale,
|
|
402
|
+
fileId: file.id,
|
|
403
|
+
key: file.key
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
}).filter(Boolean);
|
|
407
|
+
}
|
|
309
408
|
}
|
|
310
409
|
exports.FilesStorageOperations = FilesStorageOperations;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["FilesStorageOperations","context","_context","constructor","table","defineTable","entity","defineFilesEntity","get","params","where","keys","PK","createPartitionKey","SK","file","getEntityItem","data","ex","WebinyError","message","code","error","create","item","GSI1_PK","createGSI1PartitionKey","GSI1_SK","id","TYPE","put","update","delete","createBatch","files","items","map","putBatch","batchWriteAll","list","initialWhere","limit","after","sort","options","createQueryAllOptions","queryAllParams","partitionKey","dbItems","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","index","gte","reverse","results","query","filteredItems","tagsObject","reduce","collection","Array","isArray","tag","push","Object","eq","gt","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\";\n\ninterface FileItem {\n PK: string;\n SK: string;\n GSI1_PK: string;\n GSI1_SK: string;\n TYPE: string;\n data: File;\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 id: string;\n}\n\ntype CreateGSI1PartitionKeyParams = Pick<CreatePartitionKeyParams, \"tenant\" | \"locale\">;\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: \"A\"\n };\n try {\n const file = await getEntityItem<{ data: File }>({\n entity: this.entity,\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 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 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 try {\n await this.create(params);\n } catch (ex) {\n if (ex.code === \"CREATE_FILE_ERROR\") {\n throw new WebinyError(\n \"Could not update a file in the DynamoDB.\",\n \"UPDATE_FILE_ERROR\",\n ex.data\n );\n }\n throw ex;\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 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 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 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.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.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.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.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 = { 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"],"mappings":";;;;;;;;;AAkBA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AA2BO,MAAMA,sBAAsB,CAA8C;EAK7E,IAAYC,OAAO,GAAuB;IACtC,OAAO,IAAI,CAACC,QAAQ;EACxB;EAEOC,WAAW,CAAC;IAAEF;EAA2B,CAAC,EAAE;IAAA;IAAA;IAAA;IAC/C,IAAI,CAACC,QAAQ,GAAGD,OAAO;IACvB,IAAI,CAACG,KAAK,GAAG,IAAAC,cAAW,EAAC;MACrBJ;IACJ,CAAC,CAAC;IAEF,IAAI,CAACK,MAAM,GAAG,IAAAC,oBAAiB,EAAC;MAC5BN,OAAO;MACPG,KAAK,EAAE,IAAI,CAACA;IAChB,CAAC,CAAC;EACN;EAEA,MAAaI,GAAG,CAACC,MAAkD,EAAwB;IACvF,MAAM;MAAEC;IAAM,CAAC,GAAGD,MAAM;IACxB,MAAME,IAAI,GAAG;MACTC,EAAE,EAAE,IAAI,CAACC,kBAAkB,CAACH,KAAK,CAAC;MAClCI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AAO;EAClB;EAEQ/B,kBAAkB,CAACJ,MAAgC,EAAU;IACjE,MAAM;MAAEoF,MAAM;MAAEC,MAAM;MAAElE;IAAG,CAAC,GAAGnB,MAAM;IACrC,OAAQ,KAAIoF,MAAO,MAAKC,MAAO,YAAWlE,EAAG,EAAC;EAClD;EACQF,sBAAsB,CAACjB,MAAoC,EAAU;IACzE,MAAM;MAAEoF,MAAM;MAAEC;IAAO,CAAC,GAAGrF,MAAM;IACjC,OAAQ,KAAIoF,MAAO,MAAKC,MAAO,WAAU;EAC7C;AACJ;AAAC"}
|
|
1
|
+
{"version":3,"names":["FilesStorageOperations","context","_context","constructor","table","defineTable","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","plugins","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 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 { 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\";\n\ntype FileItem = DbItem<File>;\ntype FileAliasItem = DbItem<FileAlias>;\n\ninterface ConstructorParams {\n context: FileManagerContext;\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 _context: FileManagerContext;\n private readonly table: Table;\n private readonly fileEntity: Entity<any>;\n private readonly aliasEntity: 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.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.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.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.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 = { 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":";;;;;;;;;AAmBA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAqBO,MAAMA,sBAAsB,CAA8C;EAM7E,IAAYC,OAAO,GAAuB;IACtC,OAAO,IAAI,CAACC,QAAQ;EACxB;EAEOC,WAAW,CAAC;IAAEF;EAA2B,CAAC,EAAE;IAAA;IAAA;IAAA;IAAA;IAC/C,IAAI,CAACC,QAAQ,GAAGD,OAAO;IACvB,IAAI,CAACG,KAAK,GAAG,IAAAC,cAAW,EAAC;MACrBJ;IACJ,CAAC,CAAC;IAEF,IAAI,CAACK,UAAU,GAAG,IAAAC,gCAAoB,EAAC,IAAI,CAACH,KAAK,EAAE,SAAS,CAAC;IAC7D,IAAI,CAACI,WAAW,GAAG,IAAAD,gCAAoB,EAAC,IAAI,CAACH,KAAK,EAAE,cAAc,CAAC;EACvE;EAEA,MAAaK,GAAG,CAACC,MAAkD,EAAwB;IACvF,MAAM;MAAEC;IAAM,CAAC,GAAGD,MAAM;IACxB,MAAME,IAAI,GA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IACL,CAAC,CAAC,CACDC,MAAM,CAACC,OAAO,CAAC;EACxB;AACJ;AAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-file-manager-ddb",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
3
|
+
"version": "0.0.0-unstable.ecd8734205",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"@webiny/api-file-manager",
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@babel/runtime": "7.20.13",
|
|
25
|
-
"@webiny/api-file-manager": "0.0.0-unstable.
|
|
26
|
-
"@webiny/db-dynamodb": "0.0.0-unstable.
|
|
27
|
-
"@webiny/error": "0.0.0-unstable.
|
|
28
|
-
"@webiny/project-utils": "0.0.0-unstable.
|
|
25
|
+
"@webiny/api-file-manager": "0.0.0-unstable.ecd8734205",
|
|
26
|
+
"@webiny/db-dynamodb": "0.0.0-unstable.ecd8734205",
|
|
27
|
+
"@webiny/error": "0.0.0-unstable.ecd8734205",
|
|
28
|
+
"@webiny/project-utils": "0.0.0-unstable.ecd8734205",
|
|
29
29
|
"aws-sdk": "2.1310.0",
|
|
30
30
|
"dynamodb-toolbox": "0.3.5"
|
|
31
31
|
},
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"@babel/plugin-transform-runtime": "^7.16.4",
|
|
37
37
|
"@babel/preset-env": "^7.19.4",
|
|
38
38
|
"@babel/preset-typescript": "^7.18.6",
|
|
39
|
-
"@webiny/cli": "^0.0.0-unstable.
|
|
39
|
+
"@webiny/cli": "^0.0.0-unstable.ecd8734205",
|
|
40
40
|
"jest": "^28.1.0",
|
|
41
41
|
"jest-dynalite": "^3.2.0",
|
|
42
42
|
"jsonpack": "^1.1.5",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
]
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "ecd8734205e0e21ae04076c28ff9806dad07a730"
|
|
67
67
|
}
|