@webiny/api-file-manager-ddb 0.0.0-ee-vpcs.549378cf03

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +30 -0
  3. package/definitions/filesEntity.d.ts +8 -0
  4. package/definitions/filesEntity.js +76 -0
  5. package/definitions/filesEntity.js.map +1 -0
  6. package/definitions/settingsEntity.d.ts +8 -0
  7. package/definitions/settingsEntity.js +52 -0
  8. package/definitions/settingsEntity.js.map +1 -0
  9. package/definitions/systemEntity.d.ts +8 -0
  10. package/definitions/systemEntity.js +43 -0
  11. package/definitions/systemEntity.js.map +1 -0
  12. package/definitions/table.d.ts +7 -0
  13. package/definitions/table.js +24 -0
  14. package/definitions/table.js.map +1 -0
  15. package/index.d.ts +5 -0
  16. package/index.js +16 -0
  17. package/index.js.map +1 -0
  18. package/operations/files/FilesStorageOperations.d.ts +22 -0
  19. package/operations/files/FilesStorageOperations.js +358 -0
  20. package/operations/files/FilesStorageOperations.js.map +1 -0
  21. package/operations/files/fields.d.ts +3 -0
  22. package/operations/files/fields.js +42 -0
  23. package/operations/files/fields.js.map +1 -0
  24. package/operations/files/index.d.ts +6 -0
  25. package/operations/files/index.js +35 -0
  26. package/operations/files/index.js.map +1 -0
  27. package/operations/settings/SettingsStorageOperations.d.ts +15 -0
  28. package/operations/settings/SettingsStorageOperations.js +118 -0
  29. package/operations/settings/SettingsStorageOperations.js.map +1 -0
  30. package/operations/settings/index.d.ts +6 -0
  31. package/operations/settings/index.js +32 -0
  32. package/operations/settings/index.js.map +1 -0
  33. package/operations/system/SystemStorageOperations.d.ts +14 -0
  34. package/operations/system/SystemStorageOperations.js +106 -0
  35. package/operations/system/SystemStorageOperations.js.map +1 -0
  36. package/operations/system/index.d.ts +6 -0
  37. package/operations/system/index.js +32 -0
  38. package/operations/system/index.js.map +1 -0
  39. package/operations/utils.d.ts +4 -0
  40. package/operations/utils.js +36 -0
  41. package/operations/utils.js.map +1 -0
  42. package/package.json +67 -0
  43. package/plugins/FileAttributePlugin.d.ts +4 -0
  44. package/plugins/FileAttributePlugin.js +23 -0
  45. package/plugins/FileAttributePlugin.js.map +1 -0
  46. package/plugins/FileDynamoDbFieldPlugin.d.ts +4 -0
  47. package/plugins/FileDynamoDbFieldPlugin.js +17 -0
  48. package/plugins/FileDynamoDbFieldPlugin.js.map +1 -0
  49. package/plugins/SettingsAttributePlugin.d.ts +4 -0
  50. package/plugins/SettingsAttributePlugin.js +23 -0
  51. package/plugins/SettingsAttributePlugin.js.map +1 -0
  52. package/plugins/SystemAttributePlugin.d.ts +4 -0
  53. package/plugins/SystemAttributePlugin.js +23 -0
  54. package/plugins/SystemAttributePlugin.js.map +1 -0
  55. package/types.d.ts +0 -0
  56. package/types.js +1 -0
  57. package/types.js.map +1 -0
@@ -0,0 +1,358 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.FilesStorageOperations = void 0;
9
+
10
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
+
12
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
+
14
+ var _error = _interopRequireDefault(require("@webiny/error"));
15
+
16
+ var _table = _interopRequireDefault(require("../../definitions/table"));
17
+
18
+ var _filesEntity = _interopRequireDefault(require("../../definitions/filesEntity"));
19
+
20
+ var _query = require("@webiny/db-dynamodb/utils/query");
21
+
22
+ var _cursor = require("@webiny/db-dynamodb/utils/cursor");
23
+
24
+ var _filter = require("@webiny/db-dynamodb/utils/filter");
25
+
26
+ var _sort = require("@webiny/db-dynamodb/utils/sort");
27
+
28
+ var _FileDynamoDbFieldPlugin = require("../../plugins/FileDynamoDbFieldPlugin");
29
+
30
+ var _batchWrite = require("@webiny/db-dynamodb/utils/batchWrite");
31
+
32
+ var _get = require("@webiny/db-dynamodb/utils/get");
33
+
34
+ var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
35
+
36
+ class FilesStorageOperations {
37
+ get context() {
38
+ return this._context;
39
+ }
40
+
41
+ constructor({
42
+ context
43
+ }) {
44
+ (0, _defineProperty2.default)(this, "_context", void 0);
45
+ (0, _defineProperty2.default)(this, "table", void 0);
46
+ (0, _defineProperty2.default)(this, "entity", void 0);
47
+ this._context = context;
48
+ this.table = (0, _table.default)({
49
+ context
50
+ });
51
+ this.entity = (0, _filesEntity.default)({
52
+ context,
53
+ table: this.table
54
+ });
55
+ }
56
+
57
+ async get(params) {
58
+ const {
59
+ where
60
+ } = params;
61
+ const keys = {
62
+ PK: this.createPartitionKey(where),
63
+ SK: this.createSortKey(where)
64
+ };
65
+
66
+ try {
67
+ const file = await (0, _get.get)({
68
+ entity: this.entity,
69
+ keys
70
+ });
71
+ return (0, _cleanup.cleanupItem)(this.entity, file);
72
+ } catch (ex) {
73
+ throw new _error.default(ex.message || "Could not fetch requested file.", ex.code || "GET_FILE_ERROR", {
74
+ error: ex,
75
+ where
76
+ });
77
+ }
78
+ }
79
+
80
+ async create(params) {
81
+ const {
82
+ file
83
+ } = params;
84
+ const keys = {
85
+ PK: this.createPartitionKey(file),
86
+ SK: this.createSortKey(file)
87
+ };
88
+ const item = (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, file), keys), {}, {
89
+ TYPE: "fm.file"
90
+ });
91
+
92
+ try {
93
+ await this.entity.put(item);
94
+ } catch (ex) {
95
+ throw new _error.default(ex.message || "Could not create a new file in the DynamoDB.", ex.code || "CREATE_FILE_ERROR", {
96
+ error: ex,
97
+ item
98
+ });
99
+ }
100
+
101
+ return file;
102
+ }
103
+
104
+ async update(params) {
105
+ const {
106
+ file
107
+ } = params;
108
+ const keys = {
109
+ PK: this.createPartitionKey(file),
110
+ SK: this.createSortKey(file)
111
+ };
112
+ const item = (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, file), keys), {}, {
113
+ TYPE: "fm.file"
114
+ });
115
+
116
+ try {
117
+ await this.entity.put(item);
118
+ } catch (ex) {
119
+ throw new _error.default(ex.message || "Could not update a file in the DynamoDB.", ex.code || "UPDATE_FILE_ERROR", {
120
+ error: ex,
121
+ item
122
+ });
123
+ }
124
+
125
+ return file;
126
+ }
127
+
128
+ async delete(params) {
129
+ const {
130
+ file
131
+ } = params;
132
+ const keys = {
133
+ PK: this.createPartitionKey(file),
134
+ SK: this.createSortKey(file)
135
+ };
136
+
137
+ try {
138
+ await this.entity.delete(keys);
139
+ } catch (ex) {
140
+ throw new _error.default(ex.message || "Could not delete file from the DynamoDB.", ex.code || "DELETE_FILE_ERROR", {
141
+ error: ex,
142
+ file,
143
+ keys
144
+ });
145
+ }
146
+ }
147
+
148
+ async createBatch(params) {
149
+ const {
150
+ files
151
+ } = params;
152
+ const items = files.map(file => {
153
+ return this.entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, file), {}, {
154
+ PK: this.createPartitionKey(file),
155
+ SK: this.createSortKey(file),
156
+ TYPE: "fm.file"
157
+ }));
158
+ });
159
+
160
+ try {
161
+ await (0, _batchWrite.batchWriteAll)({
162
+ table: this.entity.table,
163
+ items
164
+ });
165
+ } catch (ex) {
166
+ throw new _error.default(ex.message || "Could not batch insert a list of files.", ex.code || "BATCH_CREATE_FILES_ERROR", {
167
+ error: ex,
168
+ files
169
+ });
170
+ }
171
+
172
+ return files;
173
+ }
174
+
175
+ async list(params) {
176
+ const {
177
+ where: initialWhere,
178
+ limit,
179
+ after,
180
+ sort
181
+ } = params;
182
+ const options = this.createQueryAllOptions({
183
+ where: initialWhere
184
+ });
185
+ const queryAllParams = {
186
+ entity: this.entity,
187
+ partitionKey: this.createPartitionKey(initialWhere),
188
+ options
189
+ };
190
+ let items = [];
191
+
192
+ try {
193
+ items = await (0, _query.queryAll)(queryAllParams);
194
+ } catch (ex) {
195
+ throw new _error.default(ex.message || "Could not query for the files.", ex.code || "FILE_LIST_ERROR", {
196
+ error: ex,
197
+ where: initialWhere,
198
+ limit,
199
+ after,
200
+ sort,
201
+ queryParams: {
202
+ options,
203
+ partitionKey: queryAllParams.partitionKey,
204
+ entity: queryAllParams.entity.name,
205
+ table: queryAllParams.entity.table.name
206
+ }
207
+ });
208
+ }
209
+
210
+ const where = (0, _objectSpread2.default)({}, initialWhere);
211
+
212
+ if (where.search) {
213
+ where.contains = {
214
+ fields: ["name", "tags"],
215
+ value: where.search
216
+ };
217
+ }
218
+
219
+ delete where["tenant"];
220
+ delete where["locale"];
221
+ delete where["search"];
222
+ const fields = this.context.plugins.byType(_FileDynamoDbFieldPlugin.FileDynamoDbFieldPlugin.type);
223
+ /**
224
+ * Filter the read items via the code.
225
+ * It will build the filters out of the where input and transform the values it is using.
226
+ */
227
+
228
+ const filteredFiles = (0, _filter.filterItems)({
229
+ plugins: this.context.plugins,
230
+ items,
231
+ where,
232
+ fields
233
+ });
234
+ const totalCount = filteredFiles.length;
235
+ /**
236
+ * Sorting is also done via the code.
237
+ * It takes the sort input and sorts by it via the lodash sortBy method.
238
+ */
239
+
240
+ const sortedFiles = (0, _sort.sortItems)({
241
+ items: filteredFiles,
242
+ sort,
243
+ fields
244
+ });
245
+ const start = parseInt((0, _cursor.decodeCursor)(after) || "0") || 0;
246
+ const hasMoreItems = totalCount > start + limit;
247
+ const end = limit > totalCount + start + limit ? undefined : start + limit;
248
+ const files = sortedFiles.slice(start, end);
249
+ /**
250
+ * Although we do not need a cursor here, we will use it as such to keep it standardized.
251
+ * Number is simply encoded.
252
+ */
253
+
254
+ const cursor = files.length > 0 ? (0, _cursor.encodeCursor)(start + limit) : null;
255
+ const meta = {
256
+ hasMoreItems,
257
+ totalCount: totalCount,
258
+ cursor
259
+ };
260
+ return [files, meta];
261
+ }
262
+
263
+ async tags(params) {
264
+ const {
265
+ where: initialWhere
266
+ } = params;
267
+ const queryAllParams = {
268
+ entity: this.entity,
269
+ partitionKey: this.createPartitionKey(initialWhere),
270
+ options: {
271
+ gte: " ",
272
+ reverse: false
273
+ }
274
+ };
275
+ let results = [];
276
+
277
+ try {
278
+ results = await (0, _query.queryAll)(queryAllParams);
279
+ } catch (ex) {
280
+ throw new _error.default(ex.message || "Error in the DynamoDB query.", ex.code || "DYNAMODB_ERROR", {
281
+ error: ex,
282
+ query: queryAllParams
283
+ });
284
+ }
285
+
286
+ const fields = this.context.plugins.byType(_FileDynamoDbFieldPlugin.FileDynamoDbFieldPlugin.type);
287
+ const where = (0, _objectSpread2.default)({}, initialWhere);
288
+ delete where["tenant"];
289
+ delete where["locale"];
290
+ /**
291
+ * Filter the read items via the code.
292
+ * It will build the filters out of the where input and transform the values it is using.
293
+ */
294
+
295
+ const filteredItems = (0, _filter.filterItems)({
296
+ plugins: this.context.plugins,
297
+ items: results,
298
+ where,
299
+ fields
300
+ });
301
+ /**
302
+ * Aggregate all the tags from all the filtered items.
303
+ */
304
+
305
+ const tagsObject = filteredItems.reduce((collection, item) => {
306
+ const tags = Array.isArray(item.tags) ? item.tags : [];
307
+
308
+ for (const tag of tags) {
309
+ if (!collection[tag]) {
310
+ collection[tag] = [];
311
+ }
312
+
313
+ collection[tag].push(item.id);
314
+ }
315
+
316
+ return collection;
317
+ }, {});
318
+ const tags = Object.keys(tagsObject);
319
+ const hasMoreItems = false;
320
+ const totalCount = tags.length;
321
+ const meta = {
322
+ hasMoreItems,
323
+ totalCount,
324
+ cursor: null
325
+ };
326
+ return [tags, meta];
327
+ }
328
+
329
+ createQueryAllOptions({
330
+ where
331
+ }) {
332
+ const options = {};
333
+
334
+ if (where.id) {
335
+ options.eq = where.id;
336
+ }
337
+
338
+ return options;
339
+ }
340
+
341
+ createPartitionKey(params) {
342
+ const {
343
+ tenant,
344
+ locale
345
+ } = params;
346
+ return `T#${tenant}#L#${locale}#FM#F`;
347
+ }
348
+
349
+ createSortKey(params) {
350
+ const {
351
+ id
352
+ } = params;
353
+ return id;
354
+ }
355
+
356
+ }
357
+
358
+ exports.FilesStorageOperations = FilesStorageOperations;
@@ -0,0 +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;;EAEMC,WAAW,CAAC;IAAEF;EAAF,CAAD,EAAiC;IAAA;IAAA;IAAA;IAC/C,KAAKC,QAAL,GAAgBD,OAAhB;IACA,KAAKG,KAAL,GA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D,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"}
@@ -0,0 +1,3 @@
1
+ import { FileDynamoDbFieldPlugin } from "../../plugins/FileDynamoDbFieldPlugin";
2
+ declare const _default: () => FileDynamoDbFieldPlugin[];
3
+ export default _default;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _FileDynamoDbFieldPlugin = require("../../plugins/FileDynamoDbFieldPlugin");
9
+
10
+ var _default = () => [new _FileDynamoDbFieldPlugin.FileDynamoDbFieldPlugin({
11
+ field: "id"
12
+ }),
13
+ /**
14
+ * Path plugin for the field that are ddb map type and the value filtered by is the id property in the object.
15
+ */
16
+ new _FileDynamoDbFieldPlugin.FileDynamoDbFieldPlugin({
17
+ field: "createdBy",
18
+ path: "createdBy.id"
19
+ }),
20
+ /**
21
+ * Path plugin for meta field properties.
22
+ */
23
+ new _FileDynamoDbFieldPlugin.FileDynamoDbFieldPlugin({
24
+ field: "private",
25
+ path: "meta.private"
26
+ }),
27
+ /**
28
+ * Path plugin for tag field.
29
+ */
30
+ new _FileDynamoDbFieldPlugin.FileDynamoDbFieldPlugin({
31
+ field: "tag",
32
+ path: "tags"
33
+ }),
34
+ /**
35
+ * Value transformation for the dateTime field.
36
+ */
37
+ new _FileDynamoDbFieldPlugin.FileDynamoDbFieldPlugin({
38
+ field: "createdOn",
39
+ type: "date"
40
+ })];
41
+
42
+ exports.default = _default;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["FileDynamoDbFieldPlugin","field","path","type"],"sources":["fields.ts"],"sourcesContent":["import { FileDynamoDbFieldPlugin } from \"~/plugins/FileDynamoDbFieldPlugin\";\n\nexport default () => [\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;;eAEe,MAAM,CACjB,IAAIA,gDAAJ,CAA4B;EACxBC,KAAK,EAAE;AADiB,CAA5B,CADiB;AAIjB;AACJ;AACA;AACI,IAAID,gDAAJ,CAA4B;EACxBC,KAAK,EAAE,WADiB;EAExBC,IAAI,EAAE;AAFkB,CAA5B,CAPiB;AAWjB;AACJ;AACA;AACI,IAAIF,gDAAJ,CAA4B;EACxBC,KAAK,EAAE,SADiB;EAExBC,IAAI,EAAE;AAFkB,CAA5B,CAdiB;AAkBjB;AACJ;AACA;AACI,IAAIF,gDAAJ,CAA4B;EACxBC,KAAK,EAAE,KADiB;EAExBC,IAAI,EAAE;AAFkB,CAA5B,CArBiB;AAyBjB;AACJ;AACA;AACI,IAAIF,gDAAJ,CAA4B;EACxBC,KAAK,EAAE,WADiB;EAExBE,IAAI,EAAE;AAFkB,CAA5B,CA5BiB,C"}
@@ -0,0 +1,6 @@
1
+ import { FilesStorageOperationsProviderPlugin, FilesStorageOperationsProviderPluginParams } from "@webiny/api-file-manager/plugins/definitions/FilesStorageOperationsProviderPlugin";
2
+ import { FilesStorageOperations } from "./FilesStorageOperations";
3
+ export declare class FilesStorageOperationsProviderDdb extends FilesStorageOperationsProviderPlugin {
4
+ name: string;
5
+ provide({ context }: FilesStorageOperationsProviderPluginParams): Promise<FilesStorageOperations>;
6
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.FilesStorageOperationsProviderDdb = void 0;
9
+
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
12
+ var _FilesStorageOperationsProviderPlugin = require("@webiny/api-file-manager/plugins/definitions/FilesStorageOperationsProviderPlugin");
13
+
14
+ var _FilesStorageOperations = require("./FilesStorageOperations");
15
+
16
+ var _fields = _interopRequireDefault(require("./fields"));
17
+
18
+ class FilesStorageOperationsProviderDdb extends _FilesStorageOperationsProviderPlugin.FilesStorageOperationsProviderPlugin {
19
+ constructor(...args) {
20
+ super(...args);
21
+ (0, _defineProperty2.default)(this, "name", "fm.storageOperationsProvider.files.ddb");
22
+ }
23
+
24
+ async provide({
25
+ context
26
+ }) {
27
+ context.plugins.register((0, _fields.default)());
28
+ return new _FilesStorageOperations.FilesStorageOperations({
29
+ context
30
+ });
31
+ }
32
+
33
+ }
34
+
35
+ exports.FilesStorageOperationsProviderDdb = FilesStorageOperationsProviderDdb;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["FilesStorageOperationsProviderDdb","FilesStorageOperationsProviderPlugin","provide","context","plugins","register","fields","FilesStorageOperations"],"sources":["index.ts"],"sourcesContent":["import {\n FilesStorageOperationsProviderPlugin,\n FilesStorageOperationsProviderPluginParams\n} from \"@webiny/api-file-manager/plugins/definitions/FilesStorageOperationsProviderPlugin\";\nimport { FilesStorageOperations } from \"./FilesStorageOperations\";\nimport fields from \"./fields\";\n\nexport class FilesStorageOperationsProviderDdb extends FilesStorageOperationsProviderPlugin {\n public override name = \"fm.storageOperationsProvider.files.ddb\";\n async provide({ context }: FilesStorageOperationsProviderPluginParams) {\n context.plugins.register(fields());\n return new FilesStorageOperations({\n context\n });\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAIA;;AACA;;AAEO,MAAMA,iCAAN,SAAgDC,0EAAhD,CAAqF;EAAA;IAAA;IAAA,4CACjE,wCADiE;EAAA;;EAE3E,MAAPC,OAAO,CAAC;IAAEC;EAAF,CAAD,EAA0D;IACnEA,OAAO,CAACC,OAAR,CAAgBC,QAAhB,CAAyB,IAAAC,eAAA,GAAzB;IACA,OAAO,IAAIC,8CAAJ,CAA2B;MAC9BJ;IAD8B,CAA3B,CAAP;EAGH;;AAPuF"}
@@ -0,0 +1,15 @@
1
+ import { FileManagerContext, FileManagerSettings, FileManagerSettingsStorageOperations, FileManagerSettingsStorageOperationsCreateParams, FileManagerSettingsStorageOperationsUpdateParams } from "@webiny/api-file-manager/types";
2
+ interface SettingsStorageOperationsConstructorParams {
3
+ context: FileManagerContext;
4
+ }
5
+ export declare class SettingsStorageOperations implements FileManagerSettingsStorageOperations {
6
+ private readonly _context;
7
+ private readonly _entity;
8
+ private get partitionKey();
9
+ constructor({ context }: SettingsStorageOperationsConstructorParams);
10
+ get(): Promise<FileManagerSettings | null>;
11
+ create({ data }: FileManagerSettingsStorageOperationsCreateParams): Promise<FileManagerSettings>;
12
+ update({ data }: FileManagerSettingsStorageOperationsUpdateParams): Promise<FileManagerSettings>;
13
+ delete(): Promise<void>;
14
+ }
15
+ export {};
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.SettingsStorageOperations = void 0;
9
+
10
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
+
12
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
+
14
+ var _error = _interopRequireDefault(require("@webiny/error"));
15
+
16
+ var _table = _interopRequireDefault(require("../../definitions/table"));
17
+
18
+ var _settingsEntity = _interopRequireDefault(require("../../definitions/settingsEntity"));
19
+
20
+ const SORT_KEY = "default";
21
+
22
+ class SettingsStorageOperations {
23
+ get partitionKey() {
24
+ const tenant = this._context.tenancy.getCurrentTenant();
25
+
26
+ if (!tenant) {
27
+ throw new _error.default("Tenant missing.", "TENANT_NOT_FOUND");
28
+ }
29
+
30
+ return `T#${tenant.id}#FM#SETTINGS`;
31
+ }
32
+
33
+ constructor({
34
+ context
35
+ }) {
36
+ (0, _defineProperty2.default)(this, "_context", void 0);
37
+ (0, _defineProperty2.default)(this, "_entity", void 0);
38
+ this._context = context;
39
+ const table = (0, _table.default)({
40
+ context
41
+ });
42
+ this._entity = (0, _settingsEntity.default)({
43
+ context,
44
+ table
45
+ });
46
+ }
47
+
48
+ async get() {
49
+ try {
50
+ const settings = await this._entity.get({
51
+ PK: this.partitionKey,
52
+ SK: SORT_KEY
53
+ });
54
+
55
+ if (!settings || !settings.Item) {
56
+ return null;
57
+ }
58
+
59
+ return settings.Item;
60
+ } catch (ex) {
61
+ throw new _error.default(ex.message || "Could not fetch the FileManager settings.", ex.code || "GET_SETTINGS_ERROR");
62
+ }
63
+ }
64
+
65
+ async create({
66
+ data
67
+ }) {
68
+ const original = await this.get();
69
+ /**
70
+ * TODO: check if need to throw an error on existing settings
71
+ */
72
+
73
+ if (original) {
74
+ return await this.update({
75
+ original,
76
+ data
77
+ });
78
+ }
79
+
80
+ try {
81
+ await this._entity.put((0, _objectSpread2.default)({
82
+ PK: this.partitionKey,
83
+ SK: SORT_KEY
84
+ }, data));
85
+ return data;
86
+ } catch (ex) {
87
+ throw new _error.default(ex.message || "Cannot create FileManager settings.", ex.code || "CREATE_FM_SETTINGS_ERROR", {
88
+ data
89
+ });
90
+ }
91
+ }
92
+
93
+ async update({
94
+ data
95
+ }) {
96
+ try {
97
+ await this._entity.update((0, _objectSpread2.default)({
98
+ PK: this.partitionKey,
99
+ SK: SORT_KEY
100
+ }, data));
101
+ return data;
102
+ } catch (ex) {
103
+ throw new _error.default(ex.message || "Cannot update FileManager settings.", ex.code || "UPDATE_FM_SETTINGS_ERROR", {
104
+ data
105
+ });
106
+ }
107
+ }
108
+
109
+ async delete() {
110
+ return this._entity.delete({
111
+ PK: this.partitionKey,
112
+ SK: SORT_KEY
113
+ });
114
+ }
115
+
116
+ }
117
+
118
+ exports.SettingsStorageOperations = SettingsStorageOperations;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["SORT_KEY","SettingsStorageOperations","partitionKey","tenant","_context","tenancy","getCurrentTenant","WebinyError","id","constructor","context","table","defineTable","_entity","defineSettingsEntity","get","settings","PK","SK","Item","ex","message","code","create","data","original","update","put","delete"],"sources":["SettingsStorageOperations.ts"],"sourcesContent":["import {\n FileManagerContext,\n FileManagerSettings,\n FileManagerSettingsStorageOperations,\n FileManagerSettingsStorageOperationsCreateParams,\n FileManagerSettingsStorageOperationsUpdateParams\n} from \"@webiny/api-file-manager/types\";\nimport { Entity } from \"dynamodb-toolbox\";\nimport WebinyError from \"@webiny/error\";\nimport defineTable from \"~/definitions/table\";\nimport defineSettingsEntity from \"~/definitions/settingsEntity\";\n\ninterface SettingsStorageOperationsConstructorParams {\n context: FileManagerContext;\n}\n\nconst SORT_KEY = \"default\";\n\nexport class SettingsStorageOperations implements FileManagerSettingsStorageOperations {\n private readonly _context: FileManagerContext;\n private readonly _entity: Entity<any>;\n\n private get partitionKey(): string {\n const tenant = this._context.tenancy.getCurrentTenant();\n if (!tenant) {\n throw new WebinyError(\"Tenant missing.\", \"TENANT_NOT_FOUND\");\n }\n return `T#${tenant.id}#FM#SETTINGS`;\n }\n\n public constructor({ context }: SettingsStorageOperationsConstructorParams) {\n this._context = context;\n const table = defineTable({\n context\n });\n\n this._entity = defineSettingsEntity({\n context,\n table\n });\n }\n\n public async get(): Promise<FileManagerSettings | null> {\n try {\n const settings = await this._entity.get({\n PK: this.partitionKey,\n SK: SORT_KEY\n });\n if (!settings || !settings.Item) {\n return null;\n }\n return settings.Item;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not fetch the FileManager settings.\",\n ex.code || \"GET_SETTINGS_ERROR\"\n );\n }\n }\n\n public async create({\n data\n }: FileManagerSettingsStorageOperationsCreateParams): Promise<FileManagerSettings> {\n const original = await this.get();\n /**\n * TODO: check if need to throw an error on existing settings\n */\n if (original) {\n return await this.update({ original, data });\n }\n\n try {\n await this._entity.put({\n PK: this.partitionKey,\n SK: SORT_KEY,\n ...data\n });\n return data;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Cannot create FileManager settings.\",\n ex.code || \"CREATE_FM_SETTINGS_ERROR\",\n {\n data\n }\n );\n }\n }\n\n public async update({\n data\n }: FileManagerSettingsStorageOperationsUpdateParams): Promise<FileManagerSettings> {\n try {\n await this._entity.update({\n PK: this.partitionKey,\n SK: SORT_KEY,\n ...data\n });\n return data;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Cannot update FileManager settings.\",\n ex.code || \"UPDATE_FM_SETTINGS_ERROR\",\n {\n data\n }\n );\n }\n }\n\n public async delete(): Promise<void> {\n return this._entity.delete({\n PK: this.partitionKey,\n SK: SORT_KEY\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAQA;;AACA;;AACA;;AAMA,MAAMA,QAAQ,GAAG,SAAjB;;AAEO,MAAMC,yBAAN,CAAgF;EAI3D,IAAZC,YAAY,GAAW;IAC/B,MAAMC,MAAM,GAAG,KAAKC,QAAL,CAAcC,OAAd,CAAsBC,gBAAtB,EAAf;;IACA,IAAI,CAACH,MAAL,EAAa;MACT,MAAM,IAAII,cAAJ,CAAgB,iBAAh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AJ,CACFa,EAAE,CAACC,OAAH,IAAc,qCADZ,EAEFD,EAAE,CAACE,IAAH,IAAW,0BAFT,EAGF;QACIE;MADJ,CAHE,CAAN;IAOH;EACJ;;EAEkB,MAANE,MAAM,CAAC;IAChBF;EADgB,CAAD,EAEgE;IAC/E,IAAI;MACA,MAAM,KAAKX,OAAL,CAAaa,MAAb;QACFT,EAAE,EAAE,KAAKf,YADP;QAEFgB,EAAE,EAAElB;MAFF,GAGCwB,IAHD,EAAN;MAKA,OAAOA,IAAP;IACH,CAPD,CAOE,OAAOJ,EAAP,EAAW;MACT,MAAM,IAAIb,cAAJ,CACFa,EAAE,CAACC,OAAH,IAAc,qCADZ,EAEFD,EAAE,CAACE,IAAH,IAAW,0BAFT,EAGF;QACIE;MADJ,CAHE,CAAN;IAOH;EACJ;;EAEkB,MAANI,MAAM,GAAkB;IACjC,OAAO,KAAKf,OAAL,CAAae,MAAb,CAAoB;MACvBX,EAAE,EAAE,KAAKf,YADc;MAEvBgB,EAAE,EAAElB;IAFmB,CAApB,CAAP;EAIH;;AAjGkF"}
@@ -0,0 +1,6 @@
1
+ import { SettingsStorageOperations } from "./SettingsStorageOperations";
2
+ import { SettingsStorageOperationsProviderPlugin, SettingsStorageOperationsProviderPluginParams } from "@webiny/api-file-manager/plugins/definitions/SettingsStorageOperationsProviderPlugin";
3
+ export declare class SettingsStorageOperationsProviderDdbPlugin extends SettingsStorageOperationsProviderPlugin {
4
+ name: string;
5
+ provide({ context }: SettingsStorageOperationsProviderPluginParams): Promise<SettingsStorageOperations>;
6
+ }