@webiny/api-file-manager-ddb 0.0.0-unstable.df6d94b531 → 0.0.0-unstable.e53eceafb5

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 (66) hide show
  1. package/index.d.ts +4 -4
  2. package/index.js +11 -10
  3. package/index.js.map +1 -1
  4. package/operations/AliasesStorageOperations.d.ts +16 -0
  5. package/operations/AliasesStorageOperations.js +103 -0
  6. package/operations/AliasesStorageOperations.js.map +1 -0
  7. package/operations/FilesStorageOperations.d.ts +15 -0
  8. package/operations/FilesStorageOperations.js +37 -0
  9. package/operations/FilesStorageOperations.js.map +1 -0
  10. package/operations/{settings/SettingsStorageOperations.d.ts → SettingsStorageOperations.d.ts} +3 -3
  11. package/operations/{settings/SettingsStorageOperations.js → SettingsStorageOperations.js} +33 -25
  12. package/operations/SettingsStorageOperations.js.map +1 -0
  13. package/operations/{system/SystemStorageOperations.d.ts → SystemStorageOperations.d.ts} +3 -3
  14. package/operations/{system/SystemStorageOperations.js → SystemStorageOperations.js} +43 -25
  15. package/operations/SystemStorageOperations.js.map +1 -0
  16. package/package.json +17 -28
  17. package/plugins/SettingsAttributePlugin.d.ts +2 -1
  18. package/plugins/SettingsAttributePlugin.js +6 -5
  19. package/plugins/SettingsAttributePlugin.js.map +1 -1
  20. package/plugins/SystemAttributePlugin.d.ts +2 -1
  21. package/plugins/SystemAttributePlugin.js +6 -5
  22. package/plugins/SystemAttributePlugin.js.map +1 -1
  23. package/plugins/index.d.ts +0 -2
  24. package/plugins/index.js +3 -23
  25. package/plugins/index.js.map +1 -1
  26. package/definitions/filesEntity.d.ts +0 -8
  27. package/definitions/filesEntity.js +0 -76
  28. package/definitions/filesEntity.js.map +0 -1
  29. package/definitions/settingsEntity.d.ts +0 -6
  30. package/definitions/settingsEntity.js +0 -38
  31. package/definitions/settingsEntity.js.map +0 -1
  32. package/definitions/systemEntity.d.ts +0 -6
  33. package/definitions/systemEntity.js +0 -32
  34. package/definitions/systemEntity.js.map +0 -1
  35. package/definitions/table.d.ts +0 -7
  36. package/definitions/table.js +0 -25
  37. package/definitions/table.js.map +0 -1
  38. package/operations/files/FilesStorageOperations.d.ts +0 -26
  39. package/operations/files/FilesStorageOperations.js +0 -407
  40. package/operations/files/FilesStorageOperations.js.map +0 -1
  41. package/operations/files/fields.d.ts +0 -2
  42. package/operations/files/fields.js +0 -39
  43. package/operations/files/fields.js.map +0 -1
  44. package/operations/files/index.d.ts +0 -6
  45. package/operations/files/index.js +0 -35
  46. package/operations/files/index.js.map +0 -1
  47. package/operations/settings/SettingsStorageOperations.js.map +0 -1
  48. package/operations/settings/index.d.ts +0 -6
  49. package/operations/settings/index.js +0 -32
  50. package/operations/settings/index.js.map +0 -1
  51. package/operations/system/SystemStorageOperations.js.map +0 -1
  52. package/operations/system/index.d.ts +0 -6
  53. package/operations/system/index.js +0 -32
  54. package/operations/system/index.js.map +0 -1
  55. package/operations/utils.d.ts +0 -4
  56. package/operations/utils.js +0 -26
  57. package/operations/utils.js.map +0 -1
  58. package/plugins/FileAttributePlugin.d.ts +0 -4
  59. package/plugins/FileAttributePlugin.js +0 -17
  60. package/plugins/FileAttributePlugin.js.map +0 -1
  61. package/plugins/FileDynamoDbFieldPlugin.d.ts +0 -4
  62. package/plugins/FileDynamoDbFieldPlugin.js +0 -12
  63. package/plugins/FileDynamoDbFieldPlugin.js.map +0 -1
  64. package/types.d.ts +0 -0
  65. package/types.js +0 -1
  66. package/types.js.map +0 -1
package/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { DocumentClient } from "aws-sdk/clients/dynamodb";
2
- import { PluginCollection } from "@webiny/plugins/types";
3
- import { FileManagerStorageOperations } from "@webiny/api-file-manager/types";
1
+ import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb";
2
+ import type { PluginCollection } from "@webiny/plugins/types";
3
+ import type { FileManagerStorageOperations } from "@webiny/api-file-manager/types";
4
4
  export interface StorageOperationsConfig {
5
- documentClient: DocumentClient;
5
+ documentClient: DynamoDBDocument;
6
6
  plugins?: PluginCollection;
7
7
  }
8
8
  export * from "./plugins";
package/index.js CHANGED
@@ -10,10 +10,9 @@ var _exportNames = {
10
10
  exports.createFileManagerStorageOperations = void 0;
11
11
  var _plugins = _interopRequireDefault(require("@webiny/db-dynamodb/plugins"));
12
12
  var _plugins2 = require("@webiny/plugins");
13
- var _FilesStorageOperations = require("./operations/files/FilesStorageOperations");
14
- var _SettingsStorageOperations = require("./operations/settings/SettingsStorageOperations");
15
- var _SystemStorageOperations = require("./operations/system/SystemStorageOperations");
16
- var _fields = require("./operations/files/fields");
13
+ var _FilesStorageOperations = require("./operations/FilesStorageOperations");
14
+ var _SettingsStorageOperations = require("./operations/SettingsStorageOperations");
15
+ var _SystemStorageOperations = require("./operations/SystemStorageOperations");
17
16
  var _plugins3 = require("./plugins");
18
17
  Object.keys(_plugins3).forEach(function (key) {
19
18
  if (key === "default" || key === "__esModule") return;
@@ -26,24 +25,24 @@ Object.keys(_plugins3).forEach(function (key) {
26
25
  }
27
26
  });
28
27
  });
28
+ var _AliasesStorageOperations = require("./operations/AliasesStorageOperations");
29
+ var _api = require("@webiny/api");
29
30
  const createFileManagerStorageOperations = ({
30
31
  documentClient,
31
32
  plugins: userPlugins
32
33
  }) => {
33
34
  const plugins = new _plugins2.PluginsContainer([(0, _plugins.default)(),
34
- // Built-in plugins
35
- ...(0, _fields.createFileFieldsPlugins)(),
36
35
  // User plugins
37
36
  ...(userPlugins || [])]);
38
37
  return {
39
38
  beforeInit: async context => {
40
- const types = [_plugins3.FileAttributePlugin.type, _plugins3.FileDynamoDbFieldPlugin.type, _plugins3.SettingsAttributePlugin.type, _plugins3.SystemAttributePlugin.type];
39
+ const types = [_plugins3.SettingsAttributePlugin.type, _plugins3.SystemAttributePlugin.type, _api.CompressorPlugin.type];
41
40
  for (const type of types) {
42
41
  plugins.mergeByType(context.plugins, type);
43
42
  }
44
43
  },
45
- files: new _FilesStorageOperations.FilesStorageOperations({
46
- plugins,
44
+ files: new _FilesStorageOperations.FilesStorageOperations(),
45
+ aliases: new _AliasesStorageOperations.AliasesStorageOperations({
47
46
  documentClient
48
47
  }),
49
48
  settings: new _SettingsStorageOperations.SettingsStorageOperations({
@@ -54,4 +53,6 @@ const createFileManagerStorageOperations = ({
54
53
  })
55
54
  };
56
55
  };
57
- exports.createFileManagerStorageOperations = createFileManagerStorageOperations;
56
+ exports.createFileManagerStorageOperations = createFileManagerStorageOperations;
57
+
58
+ //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["createFileManagerStorageOperations","documentClient","plugins","userPlugins","PluginsContainer","ddbPlugins","createFileFieldsPlugins","beforeInit","context","types","FileAttributePlugin","type","FileDynamoDbFieldPlugin","SettingsAttributePlugin","SystemAttributePlugin","mergeByType","files","FilesStorageOperations","settings","SettingsStorageOperations","system","SystemStorageOperations"],"sources":["index.ts"],"sourcesContent":["import { DocumentClient } from \"aws-sdk/clients/dynamodb\";\nimport ddbPlugins from \"@webiny/db-dynamodb/plugins\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { PluginCollection } from \"@webiny/plugins/types\";\nimport { FileManagerStorageOperations } from \"@webiny/api-file-manager/types\";\nimport { FilesStorageOperations } from \"~/operations/files/FilesStorageOperations\";\nimport { SettingsStorageOperations } from \"~/operations/settings/SettingsStorageOperations\";\nimport { SystemStorageOperations } from \"~/operations/system/SystemStorageOperations\";\nimport { createFileFieldsPlugins } from \"~/operations/files/fields\";\nimport {\n FileAttributePlugin,\n FileDynamoDbFieldPlugin,\n SettingsAttributePlugin,\n SystemAttributePlugin\n} from \"./plugins\";\n\nexport interface StorageOperationsConfig {\n documentClient: DocumentClient;\n plugins?: PluginCollection;\n}\n\nexport * from \"./plugins\";\n\nexport const createFileManagerStorageOperations = ({\n documentClient,\n plugins: userPlugins\n}: StorageOperationsConfig): FileManagerStorageOperations => {\n const plugins = new PluginsContainer([\n ddbPlugins(),\n // Built-in plugins\n ...createFileFieldsPlugins(),\n // User plugins\n ...(userPlugins || [])\n ]);\n\n return {\n beforeInit: async context => {\n const types: string[] = [\n FileAttributePlugin.type,\n FileDynamoDbFieldPlugin.type,\n SettingsAttributePlugin.type,\n SystemAttributePlugin.type\n ];\n for (const type of types) {\n plugins.mergeByType(context.plugins, type);\n }\n },\n files: new FilesStorageOperations({ plugins, documentClient }),\n settings: new SettingsStorageOperations({ documentClient }),\n system: new SystemStorageOperations({ documentClient })\n };\n};\n"],"mappings":";;;;;;;;;;AACA;AACA;AAGA;AACA;AACA;AACA;AACA;AAYA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AAEO,MAAMA,kCAAkC,GAAG,CAAC;EAC/CC,cAAc;EACdC,OAAO,EAAEC;AACY,CAAC,KAAmC;EACzD,MAAMD,OAAO,GAAG,IAAIE,0BAAgB,CAAC,CACjC,IAAAC,gBAAU,GAAE;EACZ;EACA,GAAG,IAAAC,+BAAuB,GAAE;EAC5B;EACA,IAAIH,WAAW,IAAI,EAAE,CAAC,CACzB,CAAC;EAEF,OAAO;IACHI,UAAU,EAAE,MAAMC,OAAO,IAAI;MACzB,MAAMC,KAAe,GAAG,CACpBC,6BAAmB,CAACC,IAAI,EACxBC,iCAAuB,CAACD,IAAI,EAC5BE,iCAAuB,CAACF,IAAI,EAC5BG,+BAAqB,CAACH,IAAI,CAC7B;MACD,KAAK,MAAMA,IAAI,IAAIF,KAAK,EAAE;QACtBP,OAAO,CAACa,WAAW,CAACP,OAAO,CAACN,OAAO,EAAES,IAAI,CAAC;MAC9C;IACJ,CAAC;IACDK,KAAK,EAAE,IAAIC,8CAAsB,CAAC;MAAEf,OAAO;MAAED;IAAe,CAAC,CAAC;IAC9DiB,QAAQ,EAAE,IAAIC,oDAAyB,CAAC;MAAElB;IAAe,CAAC,CAAC;IAC3DmB,MAAM,EAAE,IAAIC,gDAAuB,CAAC;MAAEpB;IAAe,CAAC;EAC1D,CAAC;AACL,CAAC;AAAC"}
1
+ {"version":3,"names":["_plugins","_interopRequireDefault","require","_plugins2","_FilesStorageOperations","_SettingsStorageOperations","_SystemStorageOperations","_plugins3","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_AliasesStorageOperations","_api","createFileManagerStorageOperations","documentClient","plugins","userPlugins","PluginsContainer","ddbPlugins","beforeInit","context","types","SettingsAttributePlugin","type","SystemAttributePlugin","CompressorPlugin","mergeByType","files","FilesStorageOperations","aliases","AliasesStorageOperations","settings","SettingsStorageOperations","system","SystemStorageOperations"],"sources":["index.ts"],"sourcesContent":["import type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb\";\nimport ddbPlugins from \"@webiny/db-dynamodb/plugins\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport type { PluginCollection } from \"@webiny/plugins/types\";\nimport type { FileManagerStorageOperations } from \"@webiny/api-file-manager/types\";\nimport { FilesStorageOperations } from \"~/operations/FilesStorageOperations\";\nimport { SettingsStorageOperations } from \"~/operations/SettingsStorageOperations\";\nimport { SystemStorageOperations } from \"~/operations/SystemStorageOperations\";\nimport { SettingsAttributePlugin, SystemAttributePlugin } from \"./plugins\";\nimport { AliasesStorageOperations } from \"~/operations/AliasesStorageOperations\";\nimport { CompressorPlugin } from \"@webiny/api\";\n\nexport interface StorageOperationsConfig {\n documentClient: DynamoDBDocument;\n plugins?: PluginCollection;\n}\n\nexport * from \"./plugins\";\n\nexport const createFileManagerStorageOperations = ({\n documentClient,\n plugins: userPlugins\n}: StorageOperationsConfig): FileManagerStorageOperations => {\n const plugins = new PluginsContainer([\n ddbPlugins(),\n // User plugins\n ...(userPlugins || [])\n ]);\n\n return {\n beforeInit: async context => {\n const types: string[] = [\n SettingsAttributePlugin.type,\n SystemAttributePlugin.type,\n CompressorPlugin.type\n ];\n for (const type of types) {\n plugins.mergeByType(context.plugins, type);\n }\n },\n files: new FilesStorageOperations(),\n aliases: new AliasesStorageOperations({ documentClient }),\n settings: new SettingsStorageOperations({ documentClient }),\n system: new SystemStorageOperations({ documentClient })\n };\n};\n"],"mappings":";;;;;;;;;;AACA,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AAGA,IAAAE,uBAAA,GAAAF,OAAA;AACA,IAAAG,0BAAA,GAAAH,OAAA;AACA,IAAAI,wBAAA,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAL,OAAA;AASAM,MAAA,CAAAC,IAAA,CAAAF,SAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,SAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,SAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AARA,IAAAS,yBAAA,GAAAlB,OAAA;AACA,IAAAmB,IAAA,GAAAnB,OAAA;AASO,MAAMoB,kCAAkC,GAAGA,CAAC;EAC/CC,cAAc;EACdC,OAAO,EAAEC;AACY,CAAC,KAAmC;EACzD,MAAMD,OAAO,GAAG,IAAIE,0BAAgB,CAAC,CACjC,IAAAC,gBAAU,EAAC,CAAC;EACZ;EACA,IAAIF,WAAW,IAAI,EAAE,CAAC,CACzB,CAAC;EAEF,OAAO;IACHG,UAAU,EAAE,MAAMC,OAAO,IAAI;MACzB,MAAMC,KAAe,GAAG,CACpBC,iCAAuB,CAACC,IAAI,EAC5BC,+BAAqB,CAACD,IAAI,EAC1BE,qBAAgB,CAACF,IAAI,CACxB;MACD,KAAK,MAAMA,IAAI,IAAIF,KAAK,EAAE;QACtBN,OAAO,CAACW,WAAW,CAACN,OAAO,CAACL,OAAO,EAAEQ,IAAI,CAAC;MAC9C;IACJ,CAAC;IACDI,KAAK,EAAE,IAAIC,8CAAsB,CAAC,CAAC;IACnCC,OAAO,EAAE,IAAIC,kDAAwB,CAAC;MAAEhB;IAAe,CAAC,CAAC;IACzDiB,QAAQ,EAAE,IAAIC,oDAAyB,CAAC;MAAElB;IAAe,CAAC,CAAC;IAC3DmB,MAAM,EAAE,IAAIC,gDAAuB,CAAC;MAAEpB;IAAe,CAAC;EAC1D,CAAC;AACL,CAAC;AAACP,OAAA,CAAAM,kCAAA,GAAAA,kCAAA","ignoreList":[]}
@@ -0,0 +1,16 @@
1
+ import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb";
2
+ import type { File, FileManagerAliasesStorageOperations } from "@webiny/api-file-manager/types";
3
+ interface AliasesStorageOperationsConfig {
4
+ documentClient: DynamoDBDocument;
5
+ }
6
+ export declare class AliasesStorageOperations implements FileManagerAliasesStorageOperations {
7
+ private readonly aliasEntity;
8
+ private readonly table;
9
+ constructor({ documentClient }: AliasesStorageOperationsConfig);
10
+ deleteAliases(file: File): Promise<void>;
11
+ storeAliases(file: File): Promise<void>;
12
+ private getExistingAliases;
13
+ private createPartitionKey;
14
+ private createNewAliasesRecords;
15
+ }
16
+ export {};
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.AliasesStorageOperations = void 0;
7
+ var _dbDynamodb = require("@webiny/db-dynamodb");
8
+ class AliasesStorageOperations {
9
+ constructor({
10
+ documentClient
11
+ }) {
12
+ this.table = (0, _dbDynamodb.createTable)({
13
+ documentClient
14
+ });
15
+ this.aliasEntity = (0, _dbDynamodb.createStandardEntity)({
16
+ table: this.table,
17
+ name: "FM.FileAlias"
18
+ });
19
+ }
20
+ async deleteAliases(file) {
21
+ const aliasItems = await this.getExistingAliases(file);
22
+ const batchWrite = (0, _dbDynamodb.createEntityWriteBatch)({
23
+ entity: this.aliasEntity,
24
+ delete: aliasItems.map(item => {
25
+ return {
26
+ PK: this.createPartitionKey({
27
+ id: item.fileId,
28
+ tenant: item.tenant,
29
+ locale: item.locale
30
+ }),
31
+ SK: `ALIAS#${item.alias}`
32
+ };
33
+ })
34
+ });
35
+ await batchWrite.execute();
36
+ }
37
+ async storeAliases(file) {
38
+ const existingAliases = await this.getExistingAliases(file);
39
+ const newAliases = this.createNewAliasesRecords(file, existingAliases);
40
+ const batchWrite = (0, _dbDynamodb.createEntityWriteBatch)({
41
+ entity: this.aliasEntity
42
+ });
43
+ for (const alias of newAliases) {
44
+ batchWrite.put(alias);
45
+ }
46
+
47
+ // Delete aliases that are in the DB but are NOT in the file.
48
+ for (const data of existingAliases) {
49
+ if (!file.aliases.some(alias => data.alias === alias)) {
50
+ batchWrite.delete({
51
+ PK: this.createPartitionKey(file),
52
+ SK: `ALIAS#${data.alias}`
53
+ });
54
+ }
55
+ }
56
+ await batchWrite.execute();
57
+ }
58
+ async getExistingAliases(file) {
59
+ const aliases = await (0, _dbDynamodb.queryAll)({
60
+ entity: this.aliasEntity,
61
+ partitionKey: this.createPartitionKey(file),
62
+ options: {
63
+ beginsWith: "ALIAS#"
64
+ }
65
+ });
66
+ return aliases.map(alias => alias.data);
67
+ }
68
+ createPartitionKey(params) {
69
+ const {
70
+ tenant,
71
+ locale,
72
+ id
73
+ } = params;
74
+ return `T#${tenant}#L#${locale}#FM#F${id}`;
75
+ }
76
+ createNewAliasesRecords(file, existingAliases = []) {
77
+ return (file.aliases || []).map(alias => {
78
+ // If alias is already in the DB, skip it.
79
+ if (existingAliases.find(item => item.alias === alias)) {
80
+ return null;
81
+ }
82
+
83
+ // Add a new alias.
84
+ return {
85
+ PK: this.createPartitionKey(file),
86
+ SK: `ALIAS#${alias}`,
87
+ GSI1_PK: `T#${file.tenant}#FM#FILE_ALIASES`,
88
+ GSI1_SK: alias,
89
+ TYPE: "fm.fileAlias",
90
+ data: {
91
+ alias,
92
+ tenant: file.tenant,
93
+ locale: file.locale,
94
+ fileId: file.id,
95
+ key: file.key
96
+ }
97
+ };
98
+ }).filter(Boolean);
99
+ }
100
+ }
101
+ exports.AliasesStorageOperations = AliasesStorageOperations;
102
+
103
+ //# sourceMappingURL=AliasesStorageOperations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_dbDynamodb","require","AliasesStorageOperations","constructor","documentClient","table","createTable","aliasEntity","createStandardEntity","name","deleteAliases","file","aliasItems","getExistingAliases","batchWrite","createEntityWriteBatch","entity","delete","map","item","PK","createPartitionKey","id","fileId","tenant","locale","SK","alias","execute","storeAliases","existingAliases","newAliases","createNewAliasesRecords","put","data","aliases","some","queryAll","partitionKey","options","beginsWith","params","find","GSI1_PK","GSI1_SK","TYPE","key","filter","Boolean","exports"],"sources":["AliasesStorageOperations.ts"],"sourcesContent":["import type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb\";\nimport type { Entity, Table } from \"@webiny/db-dynamodb/toolbox\";\nimport type {\n File,\n FileAlias,\n FileManagerAliasesStorageOperations\n} from \"@webiny/api-file-manager/types\";\nimport type { DbItem } from \"@webiny/db-dynamodb\";\nimport {\n createEntityWriteBatch,\n createStandardEntity,\n createTable,\n queryAll\n} from \"@webiny/db-dynamodb\";\n\ninterface AliasesStorageOperationsConfig {\n documentClient: DynamoDBDocument;\n}\n\ninterface CreatePartitionKeyParams {\n locale: string;\n tenant: string;\n id: string;\n}\n\nexport class AliasesStorageOperations implements FileManagerAliasesStorageOperations {\n private readonly aliasEntity: Entity<any>;\n private readonly table: Table<string, string, string>;\n\n constructor({ documentClient }: AliasesStorageOperationsConfig) {\n this.table = createTable({ documentClient });\n\n this.aliasEntity = createStandardEntity({\n table: this.table,\n name: \"FM.FileAlias\"\n });\n }\n\n async deleteAliases(file: File): Promise<void> {\n const aliasItems = await this.getExistingAliases(file);\n\n const batchWrite = createEntityWriteBatch({\n entity: this.aliasEntity,\n delete: aliasItems.map(item => {\n return {\n PK: this.createPartitionKey({\n id: item.fileId,\n tenant: item.tenant,\n locale: item.locale\n }),\n SK: `ALIAS#${item.alias}`\n };\n })\n });\n\n await batchWrite.execute();\n }\n\n async storeAliases(file: File): Promise<void> {\n const existingAliases = await this.getExistingAliases(file);\n const newAliases = this.createNewAliasesRecords(file, existingAliases);\n\n const batchWrite = createEntityWriteBatch({\n entity: this.aliasEntity\n });\n for (const alias of newAliases) {\n batchWrite.put(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 batchWrite.delete({\n PK: this.createPartitionKey(file),\n SK: `ALIAS#${data.alias}`\n });\n }\n }\n\n await batchWrite.execute();\n }\n\n private async getExistingAliases(file: File): Promise<FileAlias[]> {\n const aliases = await queryAll<{ data: FileAlias }>({\n entity: this.aliasEntity,\n partitionKey: this.createPartitionKey(file),\n options: {\n beginsWith: \"ALIAS#\"\n }\n });\n\n return aliases.map(alias => alias.data);\n }\n\n private createPartitionKey(params: CreatePartitionKeyParams): string {\n const { tenant, locale, id } = params;\n return `T#${tenant}#L#${locale}#FM#F${id}`;\n }\n\n private createNewAliasesRecords(\n file: File,\n existingAliases: FileAlias[] = []\n ): DbItem<FileAlias>[] {\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 DbItem<FileAlias>[];\n }\n}\n"],"mappings":";;;;;;AAQA,IAAAA,WAAA,GAAAC,OAAA;AAiBO,MAAMC,wBAAwB,CAAgD;EAIjFC,WAAWA,CAAC;IAAEC;EAA+C,CAAC,EAAE;IAC5D,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KAAKhC,IAAI,CAACa,MAAM,kBAAkB;QAC3CoB,OAAO,EAAEjB,KAAK;QACdkB,IAAI,EAAE,cAAc;QACpBX,IAAI,EAAE;UACFP,KAAK;UACLH,MAAM,EAAEb,IAAI,CAACa,MAAM;UACnBC,MAAM,EAAEd,IAAI,CAACc,MAAM;UACnBF,MAAM,EAAEZ,IAAI,CAACW,EAAE;UACfwB,GAAG,EAAEnC,IAAI,CAACmC;QACd;MACJ,CAAC;IACL,CAAC,CAAC,CACDC,MAAM,CAACC,OAAO,CAAC;EACxB;AACJ;AAACC,OAAA,CAAA/C,wBAAA,GAAAA,wBAAA","ignoreList":[]}
@@ -0,0 +1,15 @@
1
+ import type { File, FileManagerFilesStorageOperations, FileManagerFilesStorageOperationsListResponse, FileManagerFilesStorageOperationsTagsResponse } from "@webiny/api-file-manager/types";
2
+ /**
3
+ * This class is here to satisfy TS interface, but it will always be overridden by CMS storage operations
4
+ * within the `api-file-manager` package itself. This will remain here until we find a better approach to organizing
5
+ * storage operations, and connecting app logic to CMS.
6
+ */
7
+ export declare class FilesStorageOperations implements FileManagerFilesStorageOperations {
8
+ create(): Promise<File>;
9
+ createBatch(): Promise<File[]>;
10
+ delete(): Promise<void>;
11
+ get(): Promise<File | null>;
12
+ list(): Promise<FileManagerFilesStorageOperationsListResponse>;
13
+ tags(): Promise<FileManagerFilesStorageOperationsTagsResponse[]>;
14
+ update(): Promise<File>;
15
+ }
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.FilesStorageOperations = void 0;
7
+ /**
8
+ * This class is here to satisfy TS interface, but it will always be overridden by CMS storage operations
9
+ * within the `api-file-manager` package itself. This will remain here until we find a better approach to organizing
10
+ * storage operations, and connecting app logic to CMS.
11
+ */
12
+ class FilesStorageOperations {
13
+ create() {
14
+ throw new Error("api-file-manager-ddb does not implement the Files storage operations.");
15
+ }
16
+ createBatch() {
17
+ throw new Error("api-file-manager-ddb does not implement the Files storage operations.");
18
+ }
19
+ delete() {
20
+ throw new Error("api-file-manager-ddb does not implement the Files storage operations.");
21
+ }
22
+ get() {
23
+ throw new Error("api-file-manager-ddb does not implement the Files storage operations.");
24
+ }
25
+ list() {
26
+ throw new Error("api-file-manager-ddb does not implement the Files storage operations.");
27
+ }
28
+ tags() {
29
+ throw new Error("api-file-manager-ddb does not implement the Files storage operations.");
30
+ }
31
+ update() {
32
+ throw new Error("api-file-manager-ddb does not implement the Files storage operations.");
33
+ }
34
+ }
35
+ exports.FilesStorageOperations = FilesStorageOperations;
36
+
37
+ //# sourceMappingURL=FilesStorageOperations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["FilesStorageOperations","create","Error","createBatch","delete","get","list","tags","update","exports"],"sources":["FilesStorageOperations.ts"],"sourcesContent":["import type {\n File,\n FileManagerFilesStorageOperations,\n FileManagerFilesStorageOperationsListResponse,\n FileManagerFilesStorageOperationsTagsResponse\n} from \"@webiny/api-file-manager/types\";\n\n/**\n * This class is here to satisfy TS interface, but it will always be overridden by CMS storage operations\n * within the `api-file-manager` package itself. This will remain here until we find a better approach to organizing\n * storage operations, and connecting app logic to CMS.\n */\nexport class FilesStorageOperations implements FileManagerFilesStorageOperations {\n create(): Promise<File> {\n throw new Error(\"api-file-manager-ddb does not implement the Files storage operations.\");\n }\n\n createBatch(): Promise<File[]> {\n throw new Error(\"api-file-manager-ddb does not implement the Files storage operations.\");\n }\n\n delete(): Promise<void> {\n throw new Error(\"api-file-manager-ddb does not implement the Files storage operations.\");\n }\n\n get(): Promise<File | null> {\n throw new Error(\"api-file-manager-ddb does not implement the Files storage operations.\");\n }\n\n list(): Promise<FileManagerFilesStorageOperationsListResponse> {\n throw new Error(\"api-file-manager-ddb does not implement the Files storage operations.\");\n }\n\n tags(): Promise<FileManagerFilesStorageOperationsTagsResponse[]> {\n throw new Error(\"api-file-manager-ddb does not implement the Files storage operations.\");\n }\n\n update(): Promise<File> {\n throw new Error(\"api-file-manager-ddb does not implement the Files storage operations.\");\n }\n}\n"],"mappings":";;;;;;AAOA;AACA;AACA;AACA;AACA;AACO,MAAMA,sBAAsB,CAA8C;EAC7EC,MAAMA,CAAA,EAAkB;IACpB,MAAM,IAAIC,KAAK,CAAC,uEAAuE,CAAC;EAC5F;EAEAC,WAAWA,CAAA,EAAoB;IAC3B,MAAM,IAAID,KAAK,CAAC,uEAAuE,CAAC;EAC5F;EAEAE,MAAMA,CAAA,EAAkB;IACpB,MAAM,IAAIF,KAAK,CAAC,uEAAuE,CAAC;EAC5F;EAEAG,GAAGA,CAAA,EAAyB;IACxB,MAAM,IAAIH,KAAK,CAAC,uEAAuE,CAAC;EAC5F;EAEAI,IAAIA,CAAA,EAA2D;IAC3D,MAAM,IAAIJ,KAAK,CAAC,uEAAuE,CAAC;EAC5F;EAEAK,IAAIA,CAAA,EAA6D;IAC7D,MAAM,IAAIL,KAAK,CAAC,uEAAuE,CAAC;EAC5F;EAEAM,MAAMA,CAAA,EAAkB;IACpB,MAAM,IAAIN,KAAK,CAAC,uEAAuE,CAAC;EAC5F;AACJ;AAACO,OAAA,CAAAT,sBAAA,GAAAA,sBAAA","ignoreList":[]}
@@ -1,7 +1,7 @@
1
- import { FileManagerSettings, FileManagerSettingsStorageOperations, FileManagerSettingsStorageOperationsCreateParams, FileManagerSettingsStorageOperationsUpdateParams, FileManagerStorageOperationsDeleteSettings, FileManagerStorageOperationsGetSettingsParams } from "@webiny/api-file-manager/types";
2
- import { DocumentClient } from "aws-sdk/clients/dynamodb";
1
+ import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb";
2
+ import type { FileManagerSettings, FileManagerSettingsStorageOperations, FileManagerSettingsStorageOperationsCreateParams, FileManagerSettingsStorageOperationsUpdateParams, FileManagerStorageOperationsDeleteSettings, FileManagerStorageOperationsGetSettingsParams } from "@webiny/api-file-manager/types";
3
3
  interface SettingsStorageOperationsConfig {
4
- documentClient: DocumentClient;
4
+ documentClient: DynamoDBDocument;
5
5
  }
6
6
  export declare class SettingsStorageOperations implements FileManagerSettingsStorageOperations {
7
7
  private readonly _entity;
@@ -5,35 +5,32 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.SettingsStorageOperations = void 0;
8
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
8
  var _error = _interopRequireDefault(require("@webiny/error"));
10
- var _settingsEntity = _interopRequireDefault(require("../../definitions/settingsEntity"));
11
- var _get = require("@webiny/db-dynamodb/utils/get");
12
- var _table = require("../../definitions/table");
9
+ var _dbDynamodb = require("@webiny/db-dynamodb");
13
10
  const SORT_KEY = "A";
14
11
  class SettingsStorageOperations {
15
12
  constructor({
16
13
  documentClient
17
14
  }) {
18
- (0, _defineProperty2.default)(this, "_entity", void 0);
19
- this._entity = (0, _settingsEntity.default)({
20
- table: (0, _table.createTable)({
15
+ this._entity = (0, _dbDynamodb.createStandardEntity)({
16
+ table: (0, _dbDynamodb.createTable)({
21
17
  documentClient
22
- })
18
+ }),
19
+ name: "FM.Settings"
23
20
  });
24
21
  }
25
22
  async get({
26
23
  tenant
27
24
  }) {
28
25
  try {
29
- const settings = await (0, _get.get)({
26
+ const settings = await (0, _dbDynamodb.get)({
30
27
  entity: this._entity,
31
28
  keys: {
32
29
  PK: `T#${tenant}#FM#SETTINGS`,
33
- SK: "A"
30
+ SK: SORT_KEY
34
31
  }
35
32
  });
36
- return settings ? settings.data : null;
33
+ return settings?.data || null;
37
34
  } catch (ex) {
38
35
  throw new _error.default(ex.message || "Could not fetch the FileManager settings.", ex.code || "GET_SETTINGS_ERROR");
39
36
  }
@@ -51,11 +48,14 @@ class SettingsStorageOperations {
51
48
  });
52
49
  }
53
50
  try {
54
- await this._entity.put({
55
- PK: `T#${data.tenant}#FM#SETTINGS`,
56
- SK: SORT_KEY,
57
- TYPE: "fm.settings",
58
- data
51
+ await (0, _dbDynamodb.put)({
52
+ entity: this._entity,
53
+ item: {
54
+ PK: `T#${data.tenant}#FM#SETTINGS`,
55
+ SK: SORT_KEY,
56
+ TYPE: "fm.settings",
57
+ data
58
+ }
59
59
  });
60
60
  return data;
61
61
  } catch (ex) {
@@ -68,11 +68,14 @@ class SettingsStorageOperations {
68
68
  data
69
69
  }) {
70
70
  try {
71
- await this._entity.update({
72
- PK: `T#${data.tenant}#FM#SETTINGS`,
73
- SK: SORT_KEY,
74
- TYPE: "fm.settings",
75
- data
71
+ await (0, _dbDynamodb.put)({
72
+ entity: this._entity,
73
+ item: {
74
+ PK: `T#${data.tenant}#FM#SETTINGS`,
75
+ SK: SORT_KEY,
76
+ TYPE: "fm.settings",
77
+ data
78
+ }
76
79
  });
77
80
  return data;
78
81
  } catch (ex) {
@@ -84,10 +87,15 @@ class SettingsStorageOperations {
84
87
  async delete({
85
88
  tenant
86
89
  }) {
87
- return this._entity.delete({
88
- PK: `T#${tenant}#FM#SETTINGS`,
89
- SK: SORT_KEY
90
+ await (0, _dbDynamodb.deleteItem)({
91
+ entity: this._entity,
92
+ keys: {
93
+ PK: `T#${tenant}#FM#SETTINGS`,
94
+ SK: SORT_KEY
95
+ }
90
96
  });
91
97
  }
92
98
  }
93
- exports.SettingsStorageOperations = SettingsStorageOperations;
99
+ exports.SettingsStorageOperations = SettingsStorageOperations;
100
+
101
+ //# sourceMappingURL=SettingsStorageOperations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_error","_interopRequireDefault","require","_dbDynamodb","SORT_KEY","SettingsStorageOperations","constructor","documentClient","_entity","createStandardEntity","table","createTable","name","get","tenant","settings","entity","keys","PK","SK","data","ex","WebinyError","message","code","create","original","update","put","item","TYPE","delete","deleteItem","exports"],"sources":["SettingsStorageOperations.ts"],"sourcesContent":["import type { Entity } from \"@webiny/db-dynamodb/toolbox\";\nimport type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb\";\nimport type {\n FileManagerSettings,\n FileManagerSettingsStorageOperations,\n FileManagerSettingsStorageOperationsCreateParams,\n FileManagerSettingsStorageOperationsUpdateParams,\n FileManagerStorageOperationsDeleteSettings,\n FileManagerStorageOperationsGetSettingsParams\n} from \"@webiny/api-file-manager/types\";\nimport WebinyError from \"@webiny/error\";\nimport { createStandardEntity, createTable, deleteItem, get, put } from \"@webiny/db-dynamodb\";\n\ninterface SettingsStorageOperationsConfig {\n documentClient: DynamoDBDocument;\n}\n\nconst SORT_KEY = \"A\";\n\nexport class SettingsStorageOperations implements FileManagerSettingsStorageOperations {\n private readonly _entity: Entity<any>;\n\n public constructor({ documentClient }: SettingsStorageOperationsConfig) {\n this._entity = createStandardEntity({\n table: createTable({ documentClient }),\n name: \"FM.Settings\"\n });\n }\n\n public async get({\n tenant\n }: FileManagerStorageOperationsGetSettingsParams): Promise<FileManagerSettings | null> {\n try {\n const settings = await get<{ data: FileManagerSettings }>({\n entity: this._entity,\n keys: {\n PK: `T#${tenant}#FM#SETTINGS`,\n SK: SORT_KEY\n }\n });\n\n return settings?.data || null;\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({ tenant: data.tenant });\n\n if (original) {\n return await this.update({ original, data });\n }\n\n try {\n await put({\n entity: this._entity,\n item: {\n PK: `T#${data.tenant}#FM#SETTINGS`,\n SK: SORT_KEY,\n TYPE: \"fm.settings\",\n data\n }\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 put({\n entity: this._entity,\n item: {\n PK: `T#${data.tenant}#FM#SETTINGS`,\n SK: SORT_KEY,\n TYPE: \"fm.settings\",\n data\n }\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({ tenant }: FileManagerStorageOperationsDeleteSettings): Promise<void> {\n await deleteItem({\n entity: this._entity,\n keys: {\n PK: `T#${tenant}#FM#SETTINGS`,\n SK: SORT_KEY\n }\n });\n }\n}\n"],"mappings":";;;;;;;AAUA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AAMA,MAAME,QAAQ,GAAG,GAAG;AAEb,MAAMC,yBAAyB,CAAiD;EAG5EC,WAAWA,CAAC;IAAEC;EAAgD,CAAC,EAAE;IACpE,IAAI,CAACC,OAAO,GAAG,IAAAC,gCAAoB,EAAC;MAChCC,KAAK,EAAE,IAAAC,uBAAW,EAAC;QAAEJ;MAAe,CAAC,CAAC;MACtCK,IAAI,EAAE;IACV,CAAC,CAAC;EACN;EAEA,MAAaC,GAAGA,CAAC;IACbC;EAC2C,CAAC,EAAuC;IACnF,IAAI;MACA,MAAMC,QAAQ,GAAG,MAAM,IAAAF,eAAG,EAAgC;QACtDG,MAAM,EAAE,IAAI,CAACR,OAAO;QACpBS,IAAI,EAAE;UACFC,EAAE,EAAE,KAAKJ,MAAM,cAAc;UAC7BK,EAAE,EAAEf;QACR;MACJ,CAAC,CAAC;MAEF,OAAOW,QAAQ,EAAEK,IAAI,IAAI,IAAI;IACjC,CAAC,CAAC,OAAOC,EAAE,EAAE;MACT,MAAM,IAAIC,cAAW,CACjBD,EAAE,CAACE,OAAO,IAAI,2CAA2C,EACzDF,EAAE,CAACG,IAAI,IAAI,oBACf,CAAC;IACL;EACJ;EAEA,MAAaC,MAAMA,CAAC;IAChBL;EAC8C,CAAC,EAAgC;IAC/E,MAAMM,QAAQ,GAAG,MAAM,IAAI,CAACb,GAAG,CAAC;MAAEC,MAAM,EAAEM,IAAI,CAACN;IAAO,CAAC,CAAC;IAExD,IAAIY,QAAQ,EAAE;M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,CAAC;EACN;AACJ;AAAC6B,OAAA,CAAA5B,yBAAA,GAAAA,yBAAA","ignoreList":[]}
@@ -1,7 +1,7 @@
1
- import { DocumentClient } from "aws-sdk/clients/dynamodb";
2
- import { FileManagerSystem, FileManagerSystemStorageOperations, FileManagerSystemStorageOperationsCreateParams, FileManagerSystemStorageOperationsGetParams, FileManagerSystemStorageOperationsUpdateParams } from "@webiny/api-file-manager/types";
1
+ import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb";
2
+ import type { FileManagerSystem, FileManagerSystemStorageOperations, FileManagerSystemStorageOperationsCreateParams, FileManagerSystemStorageOperationsGetParams, FileManagerSystemStorageOperationsUpdateParams } from "@webiny/api-file-manager/types";
3
3
  interface SystemStorageOperationsConstructorParams {
4
- documentClient: DocumentClient;
4
+ documentClient: DynamoDBDocument;
5
5
  }
6
6
  export declare class SystemStorageOperations implements FileManagerSystemStorageOperations {
7
7
  private readonly _entity;
@@ -5,35 +5,40 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.SystemStorageOperations = void 0;
8
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
8
  var _error = _interopRequireDefault(require("@webiny/error"));
11
- var _systemEntity = _interopRequireDefault(require("../../definitions/systemEntity"));
12
- var _table = require("../../definitions/table");
9
+ var _dbDynamodb = require("@webiny/db-dynamodb");
13
10
  const SORT_KEY = "FM";
14
11
  class SystemStorageOperations {
15
12
  constructor({
16
13
  documentClient
17
14
  }) {
18
- (0, _defineProperty2.default)(this, "_entity", void 0);
19
- this._entity = (0, _systemEntity.default)({
20
- table: (0, _table.createTable)({
15
+ this._entity = (0, _dbDynamodb.createLegacyEntity)({
16
+ table: (0, _dbDynamodb.createTable)({
21
17
  documentClient
22
- })
18
+ }),
19
+ name: "System",
20
+ attributes: {
21
+ version: {
22
+ type: "string"
23
+ },
24
+ tenant: {
25
+ type: "string"
26
+ }
27
+ }
23
28
  });
24
29
  }
25
30
  async get({
26
31
  tenant
27
32
  }) {
28
33
  try {
29
- const system = await this._entity.get({
30
- PK: `T#${tenant}#SYSTEM`,
31
- SK: SORT_KEY
34
+ const system = await (0, _dbDynamodb.get)({
35
+ entity: this._entity,
36
+ keys: {
37
+ PK: `T#${tenant}#SYSTEM`,
38
+ SK: SORT_KEY
39
+ }
32
40
  });
33
- if (!system || !system.Item) {
34
- return null;
35
- }
36
- return system.Item;
41
+ return system || null;
37
42
  } catch (ex) {
38
43
  throw new _error.default(ex.message || "Could not fetch the FileManager system.", ex.code || "GET_SYSTEM_ERROR");
39
44
  }
@@ -43,10 +48,14 @@ class SystemStorageOperations {
43
48
  data
44
49
  } = params;
45
50
  try {
46
- await this._entity.put((0, _objectSpread2.default)({
47
- PK: `T#${data.tenant}#SYSTEM`,
48
- SK: SORT_KEY
49
- }, data));
51
+ await (0, _dbDynamodb.put)({
52
+ entity: this._entity,
53
+ item: {
54
+ ...data,
55
+ PK: `T#${data.tenant}#SYSTEM`,
56
+ SK: SORT_KEY
57
+ }
58
+ });
50
59
  } catch (ex) {
51
60
  throw new _error.default("Could not insert new system data into DynamoDB", "CREATE_SYSTEM_ERROR", {
52
61
  data
@@ -60,16 +69,25 @@ class SystemStorageOperations {
60
69
  data
61
70
  } = params;
62
71
  try {
63
- await this._entity.update((0, _objectSpread2.default)({
64
- PK: `T#${data.tenant}#SYSTEM`,
65
- SK: SORT_KEY
66
- }, data));
72
+ await (0, _dbDynamodb.put)({
73
+ entity: this._entity,
74
+ item: {
75
+ ...data,
76
+ PK: `T#${data.tenant}#SYSTEM`,
77
+ SK: SORT_KEY
78
+ }
79
+ });
67
80
  } catch (ex) {
68
81
  throw new _error.default("Could not update system data in the DynamoDB.", "UPDATE_SYSTEM_ERROR", {
69
82
  data
70
83
  });
71
84
  }
72
- return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, original), data);
85
+ return {
86
+ ...original,
87
+ ...data
88
+ };
73
89
  }
74
90
  }
75
- exports.SystemStorageOperations = SystemStorageOperations;
91
+ exports.SystemStorageOperations = SystemStorageOperations;
92
+
93
+ //# sourceMappingURL=SystemStorageOperations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_error","_interopRequireDefault","require","_dbDynamodb","SORT_KEY","SystemStorageOperations","constructor","documentClient","_entity","createLegacyEntity","table","createTable","name","attributes","version","type","tenant","get","system","entity","keys","PK","SK","ex","WebinyError","message","code","create","params","data","put","item","update","original","exports"],"sources":["SystemStorageOperations.ts"],"sourcesContent":["import type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb\";\nimport type { Entity } from \"@webiny/db-dynamodb/toolbox\";\nimport type {\n FileManagerSystem,\n FileManagerSystemStorageOperations,\n FileManagerSystemStorageOperationsCreateParams,\n FileManagerSystemStorageOperationsGetParams,\n FileManagerSystemStorageOperationsUpdateParams\n} from \"@webiny/api-file-manager/types\";\nimport WebinyError from \"@webiny/error\";\nimport { createLegacyEntity, createTable, get, put } from \"@webiny/db-dynamodb\";\n\ninterface SystemStorageOperationsConstructorParams {\n documentClient: DynamoDBDocument;\n}\n\nconst SORT_KEY = \"FM\";\n\nexport class SystemStorageOperations implements FileManagerSystemStorageOperations {\n private readonly _entity: Entity<any>;\n\n public constructor({ documentClient }: SystemStorageOperationsConstructorParams) {\n this._entity = createLegacyEntity({\n table: createTable({ documentClient }),\n name: \"System\",\n attributes: {\n version: {\n type: \"string\"\n },\n tenant: {\n type: \"string\"\n }\n }\n });\n }\n\n public async get({\n tenant\n }: FileManagerSystemStorageOperationsGetParams): Promise<FileManagerSystem | null> {\n try {\n const system = await get<FileManagerSystem>({\n entity: this._entity,\n keys: {\n PK: `T#${tenant}#SYSTEM`,\n SK: SORT_KEY\n }\n });\n return system || null;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not fetch the FileManager system.\",\n ex.code || \"GET_SYSTEM_ERROR\"\n );\n }\n }\n\n public async create(\n params: FileManagerSystemStorageOperationsCreateParams\n ): Promise<FileManagerSystem> {\n const { data } = params;\n try {\n await put({\n entity: this._entity,\n item: {\n ...data,\n PK: `T#${data.tenant}#SYSTEM`,\n SK: SORT_KEY\n }\n });\n } catch (ex) {\n throw new WebinyError(\n \"Could not insert new system data into DynamoDB\",\n \"CREATE_SYSTEM_ERROR\",\n {\n data\n }\n );\n }\n return data;\n }\n\n public async update(\n params: FileManagerSystemStorageOperationsUpdateParams\n ): Promise<FileManagerSystem> {\n const { original, data } = params;\n\n try {\n await put({\n entity: this._entity,\n item: {\n ...data,\n PK: `T#${data.tenant}#SYSTEM`,\n SK: SORT_KEY\n }\n });\n } catch (ex) {\n throw new WebinyError(\n \"Could not update system data in the DynamoDB.\",\n \"UPDATE_SYSTEM_ERROR\",\n {\n data\n }\n );\n }\n return {\n ...original,\n ...data\n };\n }\n}\n"],"mappings":";;;;;;;AASA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AAMA,MAAME,QAAQ,GAAG,IAAI;AAEd,MAAMC,uBAAuB,CAA+C;EAGxEC,WAAWA,CAAC;IAAEC;EAAyD,CAAC,EAAE;IAC7E,IAAI,CAACC,OAAO,GAAG,IAAAC,8BAAkB,EAAC;MAC9BC,KAAK,EAAE,IAAAC,uBAAW,EAAC;QAAEJ;MAAe,CAAC,CAAC;MACtCK,IAAI,EAAE,QAAQ;MACdC,UAAU,EAAE;QACRC,OAAO,EAAE;UACLC,IAAI,EAAE;QACV,CAAC;QACDC,MAAM,EAAE;UACJD,IAAI,EAAE;QACV;MACJ;IACJ,CAAC,CAAC;EACN;EAEA,MAAaE,GAAGA,CAAC;IACbD;EACyC,CAAC,EAAqC;IAC/E,IAAI;MACA,MAAME,MAAM,GAAG,MAAM,IAAAD,eAAG,EAAoB;QACxCE,MAAM,EAAE,IAAI,CAACX,OAAO;QACpBY,IAAI,EAAE;UACFC,EAAE,EAAE,KAAKL,MAAM,SAAS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":[]}
package/package.json CHANGED
@@ -1,12 +1,11 @@
1
1
  {
2
2
  "name": "@webiny/api-file-manager-ddb",
3
- "version": "0.0.0-unstable.df6d94b531",
3
+ "version": "0.0.0-unstable.e53eceafb5",
4
4
  "main": "index.js",
5
5
  "keywords": [
6
6
  "@webiny/api-file-manager",
7
7
  "storage-operations",
8
- "dynamodb",
9
- "fm:ddb"
8
+ "ddb"
10
9
  ],
11
10
  "repository": {
12
11
  "type": "git",
@@ -21,37 +20,28 @@
21
20
  ],
22
21
  "license": "MIT",
23
22
  "dependencies": {
24
- "@babel/runtime": "7.20.13",
25
- "@webiny/api-file-manager": "0.0.0-unstable.df6d94b531",
26
- "@webiny/db-dynamodb": "0.0.0-unstable.df6d94b531",
27
- "@webiny/error": "0.0.0-unstable.df6d94b531",
28
- "@webiny/plugins": "0.0.0-unstable.df6d94b531",
29
- "@webiny/project-utils": "0.0.0-unstable.df6d94b531",
30
- "aws-sdk": "2.1310.0",
31
- "dynamodb-toolbox": "0.3.5"
23
+ "@webiny/api": "0.0.0-unstable.e53eceafb5",
24
+ "@webiny/api-file-manager": "0.0.0-unstable.e53eceafb5",
25
+ "@webiny/aws-sdk": "0.0.0-unstable.e53eceafb5",
26
+ "@webiny/db-dynamodb": "0.0.0-unstable.e53eceafb5",
27
+ "@webiny/error": "0.0.0-unstable.e53eceafb5",
28
+ "@webiny/plugins": "0.0.0-unstable.e53eceafb5",
29
+ "@webiny/project-utils": "0.0.0-unstable.e53eceafb5"
32
30
  },
33
31
  "devDependencies": {
34
- "@babel/cli": "^7.19.3",
35
- "@babel/core": "^7.19.3",
36
- "@babel/plugin-proposal-object-rest-spread": "^7.16.0",
37
- "@babel/plugin-transform-runtime": "^7.16.4",
38
- "@babel/preset-env": "^7.19.4",
39
- "@babel/preset-typescript": "^7.18.6",
40
- "@webiny/cli": "^0.0.0-unstable.df6d94b531",
41
- "jest": "^28.1.0",
42
- "jest-dynalite": "^3.2.0",
43
- "jsonpack": "^1.1.5",
44
- "rimraf": "^3.0.2",
45
- "ttypescript": "^1.5.12",
46
- "typescript": "4.7.4"
32
+ "jest": "29.7.0",
33
+ "jest-dynalite": "3.6.1",
34
+ "jsonpack": "1.1.5",
35
+ "rimraf": "6.0.1",
36
+ "typescript": "5.3.3"
47
37
  },
48
38
  "publishConfig": {
49
39
  "access": "public",
50
40
  "directory": "dist"
51
41
  },
52
42
  "scripts": {
53
- "watch": "yarn webiny run watch",
54
- "build": "yarn webiny run build"
43
+ "watch": "node ../cli/bin.js run watch",
44
+ "build": "node ../cli/bin.js run build"
55
45
  },
56
46
  "adio": {
57
47
  "ignoreDirs": [
@@ -59,10 +49,9 @@
59
49
  ],
60
50
  "ignore": {
61
51
  "src": [
62
- "aws-sdk",
63
52
  "sharp"
64
53
  ]
65
54
  }
66
55
  },
67
- "gitHead": "df6d94b531ed0453caef22c785d42be580c9df96"
56
+ "gitHead": "e53eceafb5ce1a3872c9b4548939bb2eae5b1aef"
68
57
  }