@webiny/api-file-manager-ddb 0.0.0-unstable.97a151f74d → 0.0.0-unstable.99666aeb00

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 (67) hide show
  1. package/index.d.ts +9 -5
  2. package/index.js +50 -11
  3. package/index.js.map +1 -1
  4. package/operations/AliasesStorageOperations.d.ts +16 -0
  5. package/operations/AliasesStorageOperations.js +107 -0
  6. package/operations/AliasesStorageOperations.js.map +1 -0
  7. package/operations/FilesStorageOperations.d.ts +15 -0
  8. package/operations/FilesStorageOperations.js +35 -0
  9. package/operations/FilesStorageOperations.js.map +1 -0
  10. package/operations/SettingsStorageOperations.d.ts +14 -0
  11. package/operations/SettingsStorageOperations.js +92 -0
  12. package/operations/SettingsStorageOperations.js.map +1 -0
  13. package/operations/SystemStorageOperations.d.ts +13 -0
  14. package/operations/{system/SystemStorageOperations.js → SystemStorageOperations.js} +21 -44
  15. package/operations/SystemStorageOperations.js.map +1 -0
  16. package/package.json +22 -22
  17. package/plugins/SettingsAttributePlugin.js +1 -7
  18. package/plugins/SettingsAttributePlugin.js.map +1 -1
  19. package/plugins/SystemAttributePlugin.js +0 -6
  20. package/plugins/SystemAttributePlugin.js.map +1 -1
  21. package/plugins/index.d.ts +2 -0
  22. package/plugins/index.js +27 -0
  23. package/plugins/index.js.map +1 -0
  24. package/definitions/filesEntity.d.ts +0 -8
  25. package/definitions/filesEntity.js +0 -76
  26. package/definitions/filesEntity.js.map +0 -1
  27. package/definitions/settingsEntity.d.ts +0 -8
  28. package/definitions/settingsEntity.js +0 -52
  29. package/definitions/settingsEntity.js.map +0 -1
  30. package/definitions/systemEntity.d.ts +0 -8
  31. package/definitions/systemEntity.js +0 -43
  32. package/definitions/systemEntity.js.map +0 -1
  33. package/definitions/table.d.ts +0 -7
  34. package/definitions/table.js +0 -24
  35. package/definitions/table.js.map +0 -1
  36. package/operations/files/FilesStorageOperations.d.ts +0 -22
  37. package/operations/files/FilesStorageOperations.js +0 -358
  38. package/operations/files/FilesStorageOperations.js.map +0 -1
  39. package/operations/files/fields.d.ts +0 -3
  40. package/operations/files/fields.js +0 -42
  41. package/operations/files/fields.js.map +0 -1
  42. package/operations/files/index.d.ts +0 -6
  43. package/operations/files/index.js +0 -35
  44. package/operations/files/index.js.map +0 -1
  45. package/operations/settings/SettingsStorageOperations.d.ts +0 -15
  46. package/operations/settings/SettingsStorageOperations.js +0 -118
  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.d.ts +0 -14
  52. package/operations/system/SystemStorageOperations.js.map +0 -1
  53. package/operations/system/index.d.ts +0 -6
  54. package/operations/system/index.js +0 -32
  55. package/operations/system/index.js.map +0 -1
  56. package/operations/utils.d.ts +0 -4
  57. package/operations/utils.js +0 -36
  58. package/operations/utils.js.map +0 -1
  59. package/plugins/FileAttributePlugin.d.ts +0 -4
  60. package/plugins/FileAttributePlugin.js +0 -23
  61. package/plugins/FileAttributePlugin.js.map +0 -1
  62. package/plugins/FileDynamoDbFieldPlugin.d.ts +0 -4
  63. package/plugins/FileDynamoDbFieldPlugin.js +0 -17
  64. package/plugins/FileDynamoDbFieldPlugin.js.map +0 -1
  65. package/types.d.ts +0 -0
  66. package/types.js +0 -1
  67. package/types.js.map +0 -1
package/index.d.ts CHANGED
@@ -1,5 +1,9 @@
1
- import { FilesStorageOperationsProviderDdb } from "./operations/files";
2
- import { SettingsStorageOperationsProviderDdbPlugin } from "./operations/settings";
3
- import { SystemStorageOperationsProviderDdbPlugin } from "./operations/system";
4
- declare const _default: () => (FilesStorageOperationsProviderDdb | SettingsStorageOperationsProviderDdbPlugin | SystemStorageOperationsProviderDdbPlugin)[];
5
- export default _default;
1
+ import { DocumentClient } from "aws-sdk/clients/dynamodb";
2
+ import { PluginCollection } from "@webiny/plugins/types";
3
+ import { FileManagerStorageOperations } from "@webiny/api-file-manager/types";
4
+ export interface StorageOperationsConfig {
5
+ documentClient: DocumentClient;
6
+ plugins?: PluginCollection;
7
+ }
8
+ export * from "./plugins";
9
+ export declare const createFileManagerStorageOperations: ({ documentClient, plugins: userPlugins }: StorageOperationsConfig) => FileManagerStorageOperations;
package/index.js CHANGED
@@ -1,16 +1,55 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
- exports.default = void 0;
7
-
8
- var _files = require("./operations/files");
9
-
10
- var _settings = require("./operations/settings");
11
-
12
- var _system = require("./operations/system");
13
-
14
- var _default = () => [new _files.FilesStorageOperationsProviderDdb(), new _settings.SettingsStorageOperationsProviderDdbPlugin(), new _system.SystemStorageOperationsProviderDdbPlugin()];
15
-
16
- exports.default = _default;
7
+ var _exportNames = {
8
+ createFileManagerStorageOperations: true
9
+ };
10
+ exports.createFileManagerStorageOperations = void 0;
11
+ var _plugins = _interopRequireDefault(require("@webiny/db-dynamodb/plugins"));
12
+ var _plugins2 = require("@webiny/plugins");
13
+ var _FilesStorageOperations = require("./operations/FilesStorageOperations");
14
+ var _SettingsStorageOperations = require("./operations/SettingsStorageOperations");
15
+ var _SystemStorageOperations = require("./operations/SystemStorageOperations");
16
+ var _plugins3 = require("./plugins");
17
+ Object.keys(_plugins3).forEach(function (key) {
18
+ if (key === "default" || key === "__esModule") return;
19
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
20
+ if (key in exports && exports[key] === _plugins3[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _plugins3[key];
25
+ }
26
+ });
27
+ });
28
+ var _AliasesStorageOperations = require("./operations/AliasesStorageOperations");
29
+ const createFileManagerStorageOperations = ({
30
+ documentClient,
31
+ plugins: userPlugins
32
+ }) => {
33
+ const plugins = new _plugins2.PluginsContainer([(0, _plugins.default)(),
34
+ // User plugins
35
+ ...(userPlugins || [])]);
36
+ return {
37
+ beforeInit: async context => {
38
+ const types = [_plugins3.SettingsAttributePlugin.type, _plugins3.SystemAttributePlugin.type];
39
+ for (const type of types) {
40
+ plugins.mergeByType(context.plugins, type);
41
+ }
42
+ },
43
+ files: new _FilesStorageOperations.FilesStorageOperations(),
44
+ aliases: new _AliasesStorageOperations.AliasesStorageOperations({
45
+ documentClient
46
+ }),
47
+ settings: new _SettingsStorageOperations.SettingsStorageOperations({
48
+ documentClient
49
+ }),
50
+ system: new _SystemStorageOperations.SystemStorageOperations({
51
+ documentClient
52
+ })
53
+ };
54
+ };
55
+ exports.createFileManagerStorageOperations = createFileManagerStorageOperations;
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["FilesStorageOperationsProviderDdb","SettingsStorageOperationsProviderDdbPlugin","SystemStorageOperationsProviderDdbPlugin"],"sources":["index.ts"],"sourcesContent":["import { FilesStorageOperationsProviderDdb } from \"./operations/files\";\nimport { SettingsStorageOperationsProviderDdbPlugin } from \"./operations/settings\";\nimport { SystemStorageOperationsProviderDdbPlugin } from \"./operations/system\";\n\nexport default () => [\n new FilesStorageOperationsProviderDdb(),\n new SettingsStorageOperationsProviderDdbPlugin(),\n new SystemStorageOperationsProviderDdbPlugin()\n];\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;eAEe,MAAM,CACjB,IAAIA,wCAAJ,EADiB,EAEjB,IAAIC,oDAAJ,EAFiB,EAGjB,IAAIC,gDAAJ,EAHiB,C"}
1
+ {"version":3,"names":["createFileManagerStorageOperations","documentClient","plugins","userPlugins","PluginsContainer","ddbPlugins","beforeInit","context","types","SettingsAttributePlugin","type","SystemAttributePlugin","mergeByType","files","FilesStorageOperations","aliases","AliasesStorageOperations","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/FilesStorageOperations\";\nimport { SettingsStorageOperations } from \"~/operations/SettingsStorageOperations\";\nimport { SystemStorageOperations } from \"~/operations/SystemStorageOperations\";\nimport { SettingsAttributePlugin, SystemAttributePlugin } from \"./plugins\";\nimport { AliasesStorageOperations } from \"~/operations/AliasesStorageOperations\";\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 // User plugins\n ...(userPlugins || [])\n ]);\n\n return {\n beforeInit: async context => {\n const types: string[] = [SettingsAttributePlugin.type, SystemAttributePlugin.type];\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;AACA;AAGA;AACA;AACA;AACA;AAQA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AAPA;AASO,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,IAAIF,WAAW,IAAI,EAAE,CAAC,CACzB,CAAC;EAEF,OAAO;IACHG,UAAU,EAAE,MAAMC,OAAO,IAAI;MACzB,MAAMC,KAAe,GAAG,CAACC,iCAAuB,CAACC,IAAI,EAAEC,+BAAqB,CAACD,IAAI,CAAC;MAClF,KAAK,MAAMA,IAAI,IAAIF,KAAK,EAAE;QACtBN,OAAO,CAACU,WAAW,CAACL,OAAO,CAACL,OAAO,EAAEQ,IAAI,CAAC;MAC9C;IACJ,CAAC;IACDG,KAAK,EAAE,IAAIC,8CAAsB,EAAE;IACnCC,OAAO,EAAE,IAAIC,kDAAwB,CAAC;MAAEf;IAAe,CAAC,CAAC;IACzDgB,QAAQ,EAAE,IAAIC,oDAAyB,CAAC;MAAEjB;IAAe,CAAC,CAAC;IAC3DkB,MAAM,EAAE,IAAIC,gDAAuB,CAAC;MAAEnB;IAAe,CAAC;EAC1D,CAAC;AACL,CAAC;AAAC"}
@@ -0,0 +1,16 @@
1
+ import { DocumentClient } from "aws-sdk/clients/dynamodb";
2
+ import { FileManagerAliasesStorageOperations, File } from "@webiny/api-file-manager/types";
3
+ interface AliasesStorageOperationsConfig {
4
+ documentClient: DocumentClient;
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,107 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.AliasesStorageOperations = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _dbDynamodb = require("@webiny/db-dynamodb");
10
+ class AliasesStorageOperations {
11
+ constructor({
12
+ documentClient
13
+ }) {
14
+ (0, _defineProperty2.default)(this, "aliasEntity", void 0);
15
+ (0, _defineProperty2.default)(this, "table", void 0);
16
+ this.table = (0, _dbDynamodb.createTable)({
17
+ documentClient
18
+ });
19
+ this.aliasEntity = (0, _dbDynamodb.createStandardEntity)({
20
+ table: this.table,
21
+ name: "FM.FileAlias"
22
+ });
23
+ }
24
+ async deleteAliases(file) {
25
+ const aliasItems = await this.getExistingAliases(file);
26
+ const items = [];
27
+ aliasItems.forEach(item => {
28
+ items.push(this.aliasEntity.deleteBatch({
29
+ PK: this.createPartitionKey({
30
+ id: item.fileId,
31
+ tenant: item.tenant,
32
+ locale: item.locale
33
+ }),
34
+ SK: `ALIAS#${item.alias}`
35
+ }));
36
+ });
37
+ await (0, _dbDynamodb.batchWriteAll)({
38
+ table: this.table,
39
+ items
40
+ });
41
+ }
42
+ async storeAliases(file) {
43
+ const items = [];
44
+ const existingAliases = await this.getExistingAliases(file);
45
+ const newAliases = this.createNewAliasesRecords(file, existingAliases);
46
+ newAliases.forEach(alias => {
47
+ items.push(this.aliasEntity.putBatch(alias));
48
+ });
49
+
50
+ // Delete aliases that are in the DB but are NOT in the file.
51
+ for (const data of existingAliases) {
52
+ if (!file.aliases.some(alias => data.alias === alias)) {
53
+ items.push(this.aliasEntity.deleteBatch({
54
+ PK: this.createPartitionKey(file),
55
+ SK: `ALIAS#${data.alias}`
56
+ }));
57
+ }
58
+ }
59
+ await (0, _dbDynamodb.batchWriteAll)({
60
+ table: this.table,
61
+ items
62
+ });
63
+ }
64
+ async getExistingAliases(file) {
65
+ const aliases = await (0, _dbDynamodb.queryAll)({
66
+ entity: this.aliasEntity,
67
+ partitionKey: this.createPartitionKey(file),
68
+ options: {
69
+ beginsWith: "ALIAS#"
70
+ }
71
+ });
72
+ return aliases.map(alias => alias.data);
73
+ }
74
+ createPartitionKey(params) {
75
+ const {
76
+ tenant,
77
+ locale,
78
+ id
79
+ } = params;
80
+ return `T#${tenant}#L#${locale}#FM#F${id}`;
81
+ }
82
+ createNewAliasesRecords(file, existingAliases = []) {
83
+ return (file.aliases || []).map(alias => {
84
+ // If alias is already in the DB, skip it.
85
+ if (existingAliases.find(item => item.alias === alias)) {
86
+ return null;
87
+ }
88
+
89
+ // Add a new alias.
90
+ return {
91
+ PK: this.createPartitionKey(file),
92
+ SK: `ALIAS#${alias}`,
93
+ GSI1_PK: `T#${file.tenant}#FM#FILE_ALIASES`,
94
+ GSI1_SK: alias,
95
+ TYPE: "fm.fileAlias",
96
+ data: {
97
+ alias,
98
+ tenant: file.tenant,
99
+ locale: file.locale,
100
+ fileId: file.id,
101
+ key: file.key
102
+ }
103
+ };
104
+ }).filter(Boolean);
105
+ }
106
+ }
107
+ exports.AliasesStorageOperations = AliasesStorageOperations;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["AliasesStorageOperations","constructor","documentClient","table","createTable","aliasEntity","createStandardEntity","name","deleteAliases","file","aliasItems","getExistingAliases","items","forEach","item","push","deleteBatch","PK","createPartitionKey","id","fileId","tenant","locale","SK","alias","batchWriteAll","storeAliases","existingAliases","newAliases","createNewAliasesRecords","putBatch","data","aliases","some","queryAll","entity","partitionKey","options","beginsWith","map","params","find","GSI1_PK","GSI1_SK","TYPE","key","filter","Boolean"],"sources":["AliasesStorageOperations.ts"],"sourcesContent":["import { DocumentClient } from \"aws-sdk/clients/dynamodb\";\nimport { Entity, Table } from \"dynamodb-toolbox\";\nimport {\n FileManagerAliasesStorageOperations,\n File,\n FileAlias\n} from \"@webiny/api-file-manager/types\";\nimport {\n BatchWriteItem,\n batchWriteAll,\n createStandardEntity,\n createTable,\n DbItem,\n queryAll\n} from \"@webiny/db-dynamodb\";\n\ninterface AliasesStorageOperationsConfig {\n documentClient: DocumentClient;\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;\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 const items: BatchWriteItem[] = [];\n\n aliasItems.forEach(item => {\n items.push(\n this.aliasEntity.deleteBatch({\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 batchWriteAll({ table: this.table, items });\n }\n\n async storeAliases(file: File): Promise<void> {\n const items: BatchWriteItem[] = [];\n const existingAliases = await this.getExistingAliases(file);\n const newAliases = this.createNewAliasesRecords(file, existingAliases);\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 await batchWriteAll({\n table: this.table,\n items\n });\n }\n\n private async getExistingAliases(file: File) {\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 }\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e,CAACc,IAAI,CAAC3B,IAAI,IAAIA,IAAI,CAACU,KAAK,KAAKA,KAAK,CAAC,EAAE;QACpD,OAAO,IAAI;MACf;;MAEA;MACA,OAAO;QACHP,EAAE,EAAE,IAAI,CAACC,kBAAkB,CAACT,IAAI,CAAC;QACjCc,EAAE,EAAG,SAAQC,KAAM,EAAC;QACpBkB,OAAO,EAAG,KAAIjC,IAAI,CAACY,MAAO,kBAAiB;QAC3CsB,OAAO,EAAEnB,KAAK;QACdoB,IAAI,EAAE,cAAc;QACpBb,IAAI,EAAE;UACFP,KAAK;UACLH,MAAM,EAAEZ,IAAI,CAACY,MAAM;UACnBC,MAAM,EAAEb,IAAI,CAACa,MAAM;UACnBF,MAAM,EAAEX,IAAI,CAACU,EAAE;UACf0B,GAAG,EAAEpC,IAAI,CAACoC;QACd;MACJ,CAAC;IACL,CAAC,CAAC,CACDC,MAAM,CAACC,OAAO,CAAC;EACxB;AACJ;AAAC"}
@@ -0,0 +1,15 @@
1
+ import { 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,35 @@
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;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["FilesStorageOperations","create","Error","createBatch","delete","get","list","tags","update"],"sources":["FilesStorageOperations.ts"],"sourcesContent":["import {\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,MAAM,GAAkB;IACpB,MAAM,IAAIC,KAAK,CAAC,uEAAuE,CAAC;EAC5F;EAEAC,WAAW,GAAoB;IAC3B,MAAM,IAAID,KAAK,CAAC,uEAAuE,CAAC;EAC5F;EAEAE,MAAM,GAAkB;IACpB,MAAM,IAAIF,KAAK,CAAC,uEAAuE,CAAC;EAC5F;EAEAG,GAAG,GAAyB;IACxB,MAAM,IAAIH,KAAK,CAAC,uEAAuE,CAAC;EAC5F;EAEAI,IAAI,GAA2D;IAC3D,MAAM,IAAIJ,KAAK,CAAC,uEAAuE,CAAC;EAC5F;EAEAK,IAAI,GAA6D;IAC7D,MAAM,IAAIL,KAAK,CAAC,uEAAuE,CAAC;EAC5F;EAEAM,MAAM,GAAkB;IACpB,MAAM,IAAIN,KAAK,CAAC,uEAAuE,CAAC;EAC5F;AACJ;AAAC"}
@@ -0,0 +1,14 @@
1
+ import { DocumentClient } from "aws-sdk/clients/dynamodb";
2
+ import { FileManagerSettings, FileManagerSettingsStorageOperations, FileManagerSettingsStorageOperationsCreateParams, FileManagerSettingsStorageOperationsUpdateParams, FileManagerStorageOperationsDeleteSettings, FileManagerStorageOperationsGetSettingsParams } from "@webiny/api-file-manager/types";
3
+ interface SettingsStorageOperationsConfig {
4
+ documentClient: DocumentClient;
5
+ }
6
+ export declare class SettingsStorageOperations implements FileManagerSettingsStorageOperations {
7
+ private readonly _entity;
8
+ constructor({ documentClient }: SettingsStorageOperationsConfig);
9
+ get({ tenant }: FileManagerStorageOperationsGetSettingsParams): Promise<FileManagerSettings | null>;
10
+ create({ data }: FileManagerSettingsStorageOperationsCreateParams): Promise<FileManagerSettings>;
11
+ update({ data }: FileManagerSettingsStorageOperationsUpdateParams): Promise<FileManagerSettings>;
12
+ delete({ tenant }: FileManagerStorageOperationsDeleteSettings): Promise<void>;
13
+ }
14
+ export {};
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.SettingsStorageOperations = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _error = _interopRequireDefault(require("@webiny/error"));
10
+ var _dbDynamodb = require("@webiny/db-dynamodb");
11
+ const SORT_KEY = "A";
12
+ class SettingsStorageOperations {
13
+ constructor({
14
+ documentClient
15
+ }) {
16
+ (0, _defineProperty2.default)(this, "_entity", void 0);
17
+ this._entity = (0, _dbDynamodb.createStandardEntity)({
18
+ table: (0, _dbDynamodb.createTable)({
19
+ documentClient
20
+ }),
21
+ name: "FM.Settings"
22
+ });
23
+ }
24
+ async get({
25
+ tenant
26
+ }) {
27
+ try {
28
+ const settings = await (0, _dbDynamodb.get)({
29
+ entity: this._entity,
30
+ keys: {
31
+ PK: `T#${tenant}#FM#SETTINGS`,
32
+ SK: SORT_KEY
33
+ }
34
+ });
35
+ return settings ? settings.data : null;
36
+ } catch (ex) {
37
+ throw new _error.default(ex.message || "Could not fetch the FileManager settings.", ex.code || "GET_SETTINGS_ERROR");
38
+ }
39
+ }
40
+ async create({
41
+ data
42
+ }) {
43
+ const original = await this.get({
44
+ tenant: data.tenant
45
+ });
46
+ if (original) {
47
+ return await this.update({
48
+ original,
49
+ data
50
+ });
51
+ }
52
+ try {
53
+ await this._entity.put({
54
+ PK: `T#${data.tenant}#FM#SETTINGS`,
55
+ SK: SORT_KEY,
56
+ TYPE: "fm.settings",
57
+ data
58
+ });
59
+ return data;
60
+ } catch (ex) {
61
+ throw new _error.default(ex.message || "Cannot create FileManager settings.", ex.code || "CREATE_FM_SETTINGS_ERROR", {
62
+ data
63
+ });
64
+ }
65
+ }
66
+ async update({
67
+ data
68
+ }) {
69
+ try {
70
+ await this._entity.update({
71
+ PK: `T#${data.tenant}#FM#SETTINGS`,
72
+ SK: SORT_KEY,
73
+ TYPE: "fm.settings",
74
+ data
75
+ });
76
+ return data;
77
+ } catch (ex) {
78
+ throw new _error.default(ex.message || "Cannot update FileManager settings.", ex.code || "UPDATE_FM_SETTINGS_ERROR", {
79
+ data
80
+ });
81
+ }
82
+ }
83
+ async delete({
84
+ tenant
85
+ }) {
86
+ return this._entity.delete({
87
+ PK: `T#${tenant}#FM#SETTINGS`,
88
+ SK: SORT_KEY
89
+ });
90
+ }
91
+ }
92
+ exports.SettingsStorageOperations = SettingsStorageOperations;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["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","TYPE","delete"],"sources":["SettingsStorageOperations.ts"],"sourcesContent":["import { Entity } from \"dynamodb-toolbox\";\nimport { DocumentClient } from \"aws-sdk/clients/dynamodb\";\nimport {\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 { get, createStandardEntity, createTable } from \"@webiny/db-dynamodb\";\n\ninterface SettingsStorageOperationsConfig {\n documentClient: DocumentClient;\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 ? 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 this._entity.put({\n PK: `T#${data.tenant}#FM#SETTINGS`,\n SK: SORT_KEY,\n TYPE: \"fm.settings\",\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: `T#${data.tenant}#FM#SETTINGS`,\n SK: SORT_KEY,\n TYPE: \"fm.settings\",\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({ tenant }: FileManagerStorageOperationsDeleteSettings): Promise<void> {\n return this._entity.delete({\n PK: `T#${tenant}#FM#SETTINGS`,\n SK: SORT_KEY\n });\n }\n}\n"],"mappings":";;;;;;;;AAUA;AACA;AAMA,MAAMA,QAAQ,GAAG,GAAG;AAEb,MAAMC,yBAAyB,CAAiD;EAG5EC,WAAW,CAAC;IAAEC;EAAgD,CAAC,EAAE;IAAA;IACpE,IAAI,CAACC,OAAO,GAAG,IAAAC,gCAAoB,EAAC;MAChCC,KAAK,EAAE,IAAAC,uBAAW,E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;IAChBP;EAC8C,CAAC,EAAgC;IAC/E,IAAI;MACA,MAAM,IAAI,CAACZ,OAAO,CAACmB,MAAM,CAAC;QACtBT,EAAE,EAAG,KAAIE,IAAI,CAACN,MAAO,cAAa;QAClCK,EAAE,EAAEf,QAAQ;QACZyB,IAAI,EAAE,aAAa;QACnBT;MACJ,CAAC,CAAC;MACF,OAAOA,IAAI;IACf,CAAC,CAAC,OAAOC,EAAE,EAAE;MACT,MAAM,IAAIC,cAAW,CACjBD,EAAE,CAACE,OAAO,IAAI,qCAAqC,EACnDF,EAAE,CAACG,IAAI,IAAI,0BAA0B,EACrC;QACIJ;MACJ,CAAC,CACJ;IACL;EACJ;EAEA,MAAaU,MAAM,CAAC;IAAEhB;EAAmD,CAAC,EAAiB;IACvF,OAAO,IAAI,CAACN,OAAO,CAACsB,MAAM,CAAC;MACvBZ,EAAE,EAAG,KAAIJ,MAAO,cAAa;MAC7BK,EAAE,EAAEf;IACR,CAAC,CAAC;EACN;AACJ;AAAC"}
@@ -0,0 +1,13 @@
1
+ import { DocumentClient } from "aws-sdk/clients/dynamodb";
2
+ import { FileManagerSystem, FileManagerSystemStorageOperations, FileManagerSystemStorageOperationsCreateParams, FileManagerSystemStorageOperationsGetParams, FileManagerSystemStorageOperationsUpdateParams } from "@webiny/api-file-manager/types";
3
+ interface SystemStorageOperationsConstructorParams {
4
+ documentClient: DocumentClient;
5
+ }
6
+ export declare class SystemStorageOperations implements FileManagerSystemStorageOperations {
7
+ private readonly _entity;
8
+ constructor({ documentClient }: SystemStorageOperationsConstructorParams);
9
+ get({ tenant }: FileManagerSystemStorageOperationsGetParams): Promise<FileManagerSystem | null>;
10
+ create(params: FileManagerSystemStorageOperationsCreateParams): Promise<FileManagerSystem>;
11
+ update(params: FileManagerSystemStorageOperationsUpdateParams): Promise<FileManagerSystem>;
12
+ }
13
+ export {};
@@ -1,75 +1,58 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.SystemStorageOperations = void 0;
9
-
10
8
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
-
14
10
  var _error = _interopRequireDefault(require("@webiny/error"));
15
-
16
- var _systemEntity = _interopRequireDefault(require("../../definitions/systemEntity"));
17
-
18
- var _table = _interopRequireDefault(require("../../definitions/table"));
19
-
11
+ var _dbDynamodb = require("@webiny/db-dynamodb");
20
12
  const SORT_KEY = "FM";
21
-
22
13
  class SystemStorageOperations {
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}#SYSTEM`;
31
- }
32
-
33
14
  constructor({
34
- context
15
+ documentClient
35
16
  }) {
36
- (0, _defineProperty2.default)(this, "_context", void 0);
37
17
  (0, _defineProperty2.default)(this, "_entity", void 0);
38
- this._context = context;
39
- const table = (0, _table.default)({
40
- context
41
- });
42
- this._entity = (0, _systemEntity.default)({
43
- context,
44
- table
18
+ this._entity = (0, _dbDynamodb.createLegacyEntity)({
19
+ table: (0, _dbDynamodb.createTable)({
20
+ documentClient
21
+ }),
22
+ name: "System",
23
+ attributes: {
24
+ version: {
25
+ type: "string"
26
+ },
27
+ tenant: {
28
+ type: "string"
29
+ }
30
+ }
45
31
  });
46
32
  }
47
-
48
- async get() {
33
+ async get({
34
+ tenant
35
+ }) {
49
36
  try {
50
37
  const system = await this._entity.get({
51
- PK: this.partitionKey,
38
+ PK: `T#${tenant}#SYSTEM`,
52
39
  SK: SORT_KEY
53
40
  });
54
-
55
41
  if (!system || !system.Item) {
56
42
  return null;
57
43
  }
58
-
59
44
  return system.Item;
60
45
  } catch (ex) {
61
46
  throw new _error.default(ex.message || "Could not fetch the FileManager system.", ex.code || "GET_SYSTEM_ERROR");
62
47
  }
63
48
  }
64
-
65
49
  async create(params) {
66
50
  const {
67
51
  data
68
52
  } = params;
69
-
70
53
  try {
71
54
  await this._entity.put((0, _objectSpread2.default)({
72
- PK: this.partitionKey,
55
+ PK: `T#${data.tenant}#SYSTEM`,
73
56
  SK: SORT_KEY
74
57
  }, data));
75
58
  } catch (ex) {
@@ -77,19 +60,16 @@ class SystemStorageOperations {
77
60
  data
78
61
  });
79
62
  }
80
-
81
63
  return data;
82
64
  }
83
-
84
65
  async update(params) {
85
66
  const {
86
67
  original,
87
68
  data
88
69
  } = params;
89
-
90
70
  try {
91
71
  await this._entity.update((0, _objectSpread2.default)({
92
- PK: this.partitionKey,
72
+ PK: `T#${data.tenant}#SYSTEM`,
93
73
  SK: SORT_KEY
94
74
  }, data));
95
75
  } catch (ex) {
@@ -97,10 +77,7 @@ class SystemStorageOperations {
97
77
  data
98
78
  });
99
79
  }
100
-
101
80
  return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, original), data);
102
81
  }
103
-
104
82
  }
105
-
106
83
  exports.SystemStorageOperations = SystemStorageOperations;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["SORT_KEY","SystemStorageOperations","constructor","documentClient","_entity","createLegacyEntity","table","createTable","name","attributes","version","type","tenant","get","system","PK","SK","Item","ex","WebinyError","message","code","create","params","data","put","update","original"],"sources":["SystemStorageOperations.ts"],"sourcesContent":["import { DocumentClient } from \"aws-sdk/clients/dynamodb\";\nimport { Entity } from \"dynamodb-toolbox\";\nimport {\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 } from \"@webiny/db-dynamodb\";\n\ninterface SystemStorageOperationsConstructorParams {\n documentClient: DocumentClient;\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 this._entity.get({\n PK: `T#${tenant}#SYSTEM`,\n SK: SORT_KEY\n });\n if (!system || !system.Item) {\n return null;\n }\n return system.Item;\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 this._entity.put({\n PK: `T#${data.tenant}#SYSTEM`,\n SK: SORT_KEY,\n ...data\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 this._entity.update({\n PK: `T#${data.tenant}#SYSTEM`,\n SK: SORT_KEY,\n ...data\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;AACA;AAMA,MAAMA,QAAQ,GAAG,IAAI;AAEd,MAAMC,uBAAuB,CAA+C;EAGxEC,WAAW,CAAC;IAAEC;EAAyD,CAAC,EAAE;IAAA;IAC7E,IAAI,CAACC,OAAO,GAAG,IAAAC,8BAAkB,EAAC;MAC9BC,KAAK,EAAE,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BX,EAAE,EAAG,KAAIS,IAAI,CAACZ,MAAO,SAAQ;QAC7BI,EAAE,EAAEhB;MAAQ,GACTwB,IAAI,EACT;IACN,CAAC,CAAC,OAAON,EAAE,EAAE;MACT,MAAM,IAAIC,cAAW,CACjB,+CAA+C,EAC/C,qBAAqB,EACrB;QACIK;MACJ,CAAC,CACJ;IACL;IACA,mEACOG,QAAQ,GACRH,IAAI;EAEf;AACJ;AAAC"}
package/package.json CHANGED
@@ -1,12 +1,11 @@
1
1
  {
2
2
  "name": "@webiny/api-file-manager-ddb",
3
- "version": "0.0.0-unstable.97a151f74d",
3
+ "version": "0.0.0-unstable.99666aeb00",
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,27 +20,28 @@
21
20
  ],
22
21
  "license": "MIT",
23
22
  "dependencies": {
24
- "@babel/runtime": "7.19.0",
25
- "@webiny/api-file-manager": "0.0.0-unstable.97a151f74d",
26
- "@webiny/db-dynamodb": "0.0.0-unstable.97a151f74d",
27
- "@webiny/error": "0.0.0-unstable.97a151f74d",
28
- "@webiny/project-utils": "0.0.0-unstable.97a151f74d",
29
- "aws-sdk": "2.1230.0",
23
+ "@babel/runtime": "7.20.13",
24
+ "@webiny/api-file-manager": "0.0.0-unstable.99666aeb00",
25
+ "@webiny/db-dynamodb": "0.0.0-unstable.99666aeb00",
26
+ "@webiny/error": "0.0.0-unstable.99666aeb00",
27
+ "@webiny/plugins": "0.0.0-unstable.99666aeb00",
28
+ "@webiny/project-utils": "0.0.0-unstable.99666aeb00",
29
+ "aws-sdk": "2.1310.0",
30
30
  "dynamodb-toolbox": "0.3.5"
31
31
  },
32
32
  "devDependencies": {
33
- "@babel/cli": "^7.19.3",
34
- "@babel/core": "^7.19.3",
35
- "@babel/plugin-proposal-object-rest-spread": "^7.16.0",
36
- "@babel/plugin-transform-runtime": "^7.16.4",
37
- "@babel/preset-env": "^7.19.4",
38
- "@babel/preset-typescript": "^7.18.6",
39
- "@webiny/cli": "^0.0.0-unstable.97a151f74d",
40
- "jest": "^28.1.0",
41
- "jest-dynalite": "^3.2.0",
42
- "jsonpack": "^1.1.5",
43
- "rimraf": "^3.0.2",
44
- "ttypescript": "^1.5.12",
33
+ "@babel/cli": "7.20.7",
34
+ "@babel/core": "7.20.12",
35
+ "@babel/plugin-proposal-object-rest-spread": "7.20.7",
36
+ "@babel/plugin-transform-runtime": "7.19.6",
37
+ "@babel/preset-env": "7.20.2",
38
+ "@babel/preset-typescript": "7.18.6",
39
+ "@webiny/cli": "0.0.0-unstable.99666aeb00",
40
+ "jest": "29.5.0",
41
+ "jest-dynalite": "3.6.1",
42
+ "jsonpack": "1.1.5",
43
+ "rimraf": "3.0.2",
44
+ "ttypescript": "1.5.15",
45
45
  "typescript": "4.7.4"
46
46
  },
47
47
  "publishConfig": {
@@ -63,5 +63,5 @@
63
63
  ]
64
64
  }
65
65
  },
66
- "gitHead": "97a151f74d8c5679323989fcc8cc7036be0f150e"
66
+ "gitHead": "99666aeb00056c56292eeb5dbb6aba7fda2439e2"
67
67
  }