@webiny/api-file-manager-ddb 0.0.0-unstable.d7f521b032 → 0.0.0-unstable.ecd8734205

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/definitions/settingsEntity.js +9 -23
  2. package/definitions/settingsEntity.js.map +1 -1
  3. package/definitions/systemEntity.js +0 -6
  4. package/definitions/systemEntity.js.map +1 -1
  5. package/definitions/table.js +7 -5
  6. package/definitions/table.js.map +1 -1
  7. package/index.js +0 -5
  8. package/index.js.map +1 -1
  9. package/operations/files/FilesStorageOperations.d.ts +4 -2
  10. package/operations/files/FilesStorageOperations.js +144 -93
  11. package/operations/files/FilesStorageOperations.js.map +1 -1
  12. package/operations/files/fields.js +0 -3
  13. package/operations/files/fields.js.map +1 -1
  14. package/operations/files/index.js +0 -9
  15. package/operations/files/index.js.map +1 -1
  16. package/operations/settings/SettingsStorageOperations.js +19 -39
  17. package/operations/settings/SettingsStorageOperations.js.map +1 -1
  18. package/operations/settings/index.js +0 -8
  19. package/operations/settings/index.js.map +1 -1
  20. package/operations/system/SystemStorageOperations.js +0 -22
  21. package/operations/system/SystemStorageOperations.js.map +1 -1
  22. package/operations/system/index.js +0 -8
  23. package/operations/system/index.js.map +1 -1
  24. package/operations/utils.js +0 -10
  25. package/operations/utils.js.map +1 -1
  26. package/package.json +7 -7
  27. package/plugins/FileAttributePlugin.js +1 -7
  28. package/plugins/FileAttributePlugin.js.map +1 -1
  29. package/plugins/FileDynamoDbFieldPlugin.js +0 -5
  30. package/plugins/FileDynamoDbFieldPlugin.js.map +1 -1
  31. package/plugins/SettingsAttributePlugin.js +1 -7
  32. package/plugins/SettingsAttributePlugin.js.map +1 -1
  33. package/plugins/SystemAttributePlugin.js +0 -6
  34. package/plugins/SystemAttributePlugin.js.map +1 -1
@@ -1,52 +1,38 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
8
6
  exports.default = void 0;
9
-
10
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
7
  var _dynamodbToolbox = require("dynamodb-toolbox");
13
-
14
- var _attributes = require("@webiny/db-dynamodb/utils/attributes");
15
-
16
8
  var _default = params => {
17
9
  const {
18
- context,
19
10
  table
20
11
  } = params;
21
- const entityName = "Settings";
22
- const attributes = (0, _attributes.getExtraAttributes)(context, entityName);
12
+ const entityName = "FM.Settings";
23
13
  return new _dynamodbToolbox.Entity({
24
14
  name: entityName,
25
15
  table,
26
- attributes: (0, _objectSpread2.default)({
16
+ attributes: {
27
17
  PK: {
28
18
  partitionKey: true
29
19
  },
30
20
  SK: {
31
21
  sortKey: true
32
22
  },
33
- TYPE: {
23
+ GSI1_PK: {
34
24
  type: "string"
35
25
  },
36
- key: {
26
+ GSI1_SK: {
37
27
  type: "string"
38
28
  },
39
- uploadMinFileSize: {
40
- type: "number"
41
- },
42
- uploadMaxFileSize: {
43
- type: "number"
44
- },
45
- srcPrefix: {
29
+ TYPE: {
46
30
  type: "string"
31
+ },
32
+ data: {
33
+ type: "map"
47
34
  }
48
- }, attributes)
35
+ }
49
36
  });
50
37
  };
51
-
52
38
  exports.default = _default;
@@ -1 +1 @@
1
- {"version":3,"names":["params","context","table","entityName","attributes","getExtraAttributes","Entity","name","PK","partitionKey","SK","sortKey","TYPE","type","key","uploadMinFileSize","uploadMaxFileSize","srcPrefix"],"sources":["settingsEntity.ts"],"sourcesContent":["import { Entity, Table } from \"dynamodb-toolbox\";\nimport { FileManagerContext } from \"@webiny/api-file-manager/types\";\nimport { getExtraAttributes } from \"@webiny/db-dynamodb/utils/attributes\";\n\nexport interface SettingsEntityParams {\n context: FileManagerContext;\n table: Table;\n}\nexport default (params: SettingsEntityParams): Entity<any> => {\n const { context, table } = params;\n const entityName = \"Settings\";\n const attributes = getExtraAttributes(context, entityName);\n return new Entity({\n name: entityName,\n table,\n attributes: {\n PK: {\n partitionKey: true\n },\n SK: {\n sortKey: true\n },\n TYPE: {\n type: \"string\"\n },\n key: {\n type: \"string\"\n },\n uploadMinFileSize: {\n type: \"number\"\n },\n uploadMaxFileSize: {\n type: \"number\"\n },\n srcPrefix: {\n type: \"string\"\n },\n ...attributes\n }\n });\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAEA;;eAMgBA,MAAD,IAA+C;EAC1D,MAAM;IAAEC,OAAF;IAAWC;EAAX,IAAqBF,MAA3B;EACA,MAAMG,UAAU,GAAG,UAAnB;EACA,MAAMC,UAAU,GAAG,IAAAC,8BAAA,EAAmBJ,OAAnB,EAA4BE,UAA5B,CAAnB;EACA,OAAO,IAAIG,uBAAJ,CAAW;IACdC,IAAI,EAAEJ,UADQ;IAEdD,KAFc;IAGdE,UAAU;MACNI,EAAE,EAAE;QACAC,YAAY,EAAE;MADd,CADE;MAINC,EAAE,EAAE;QACAC,OAAO,EAAE;MADT,CAJE;MAONC,IAAI,EAAE;QACFC,IAAI,EAAE;MADJ,CAPA;MAUNC,GAAG,EAAE;QACDD,IAAI,EAAE;MADL,CAVC;MAaNE,iBAAiB,EAAE;QACfF,IAAI,EAAE;MADS,CAbb;MAgBNG,iBAAiB,EAAE;QACfH,IAAI,EAAE;MADS,CAhBb;MAmBNI,SAAS,EAAE;QACPJ,IAAI,EAAE;MADC;IAnBL,GAsBHT,UAtBG;EAHI,CAAX,CAAP;AA4BH,C"}
1
+ {"version":3,"names":["params","table","entityName","Entity","name","attributes","PK","partitionKey","SK","sortKey","GSI1_PK","type","GSI1_SK","TYPE","data"],"sources":["settingsEntity.ts"],"sourcesContent":["import { Entity, Table } from \"dynamodb-toolbox\";\nimport { FileManagerContext } from \"@webiny/api-file-manager/types\";\n\nexport interface SettingsEntityParams {\n context: FileManagerContext;\n table: Table;\n}\nexport default (params: SettingsEntityParams): Entity<any> => {\n const { table } = params;\n const entityName = \"FM.Settings\";\n return new Entity({\n name: entityName,\n table,\n attributes: {\n PK: {\n partitionKey: true\n },\n SK: {\n sortKey: true\n },\n GSI1_PK: {\n type: \"string\"\n },\n GSI1_SK: {\n type: \"string\"\n },\n TYPE: {\n type: \"string\"\n },\n data: {\n type: \"map\"\n }\n }\n });\n};\n"],"mappings":";;;;;;AAAA;AAAiD,eAOjCA,MAA4B,IAAkB;EAC1D,MAAM;IAAEC;EAAM,CAAC,GAAGD,MAAM;EACxB,MAAME,UAAU,GAAG,aAAa;EAChC,OAAO,IAAIC,uBAAM,CAAC;IACdC,IAAI,EAAEF,UAAU;IAChBD,KAAK;IACLI,UAAU,EAAE;MACRC,EAAE,EAAE;QACAC,YAAY,EAAE;MAClB,CAAC;MACDC,EAAE,EAAE;QACAC,OAAO,EAAE;MACb,CAAC;MACDC,OAAO,EAAE;QACLC,IAAI,EAAE;MACV,CAAC;MACDC,OAAO,EAAE;QACLD,IAAI,EAAE;MACV,CAAC;MACDE,IAAI,EAAE;QACFF,IAAI,EAAE;MACV,CAAC;MACDG,IAAI,EAAE;QACFH,IAAI,EAAE;MACV;IACJ;EACJ,CAAC,CAAC;AACN,CAAC;AAAA"}
@@ -1,18 +1,13 @@
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.default = void 0;
9
-
10
8
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
9
  var _dynamodbToolbox = require("dynamodb-toolbox");
13
-
14
10
  var _attributes = require("@webiny/db-dynamodb/utils/attributes");
15
-
16
11
  var _default = params => {
17
12
  const {
18
13
  context,
@@ -39,5 +34,4 @@ var _default = params => {
39
34
  }, attributes)
40
35
  });
41
36
  };
42
-
43
37
  exports.default = _default;
@@ -1 +1 @@
1
- {"version":3,"names":["params","context","table","entityName","attributes","getExtraAttributes","Entity","name","PK","partitionKey","SK","sortKey","version","type","tenant"],"sources":["systemEntity.ts"],"sourcesContent":["import { Entity, Table } from \"dynamodb-toolbox\";\nimport { FileManagerContext } from \"@webiny/api-file-manager/types\";\nimport { getExtraAttributes } from \"@webiny/db-dynamodb/utils/attributes\";\n\nexport interface SystemEntityParams {\n context: FileManagerContext;\n table: Table;\n}\nexport default (params: SystemEntityParams): Entity<any> => {\n const { context, table } = params;\n const entityName = \"System\";\n const attributes = getExtraAttributes(context, entityName);\n return new Entity({\n name: entityName,\n table,\n attributes: {\n PK: {\n partitionKey: true\n },\n SK: {\n sortKey: true\n },\n version: {\n type: \"string\"\n },\n tenant: {\n type: \"string\"\n },\n ...attributes\n }\n });\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAEA;;eAMgBA,MAAD,IAA6C;EACxD,MAAM;IAAEC,OAAF;IAAWC;EAAX,IAAqBF,MAA3B;EACA,MAAMG,UAAU,GAAG,QAAnB;EACA,MAAMC,UAAU,GAAG,IAAAC,8BAAA,EAAmBJ,OAAnB,EAA4BE,UAA5B,CAAnB;EACA,OAAO,IAAIG,uBAAJ,CAAW;IACdC,IAAI,EAAEJ,UADQ;IAEdD,KAFc;IAGdE,UAAU;MACNI,EAAE,EAAE;QACAC,YAAY,EAAE;MADd,CADE;MAINC,EAAE,EAAE;QACAC,OAAO,EAAE;MADT,CAJE;MAONC,OAAO,EAAE;QACLC,IAAI,EAAE;MADD,CAPH;MAUNC,MAAM,EAAE;QACJD,IAAI,EAAE;MADF;IAVF,GAaHT,UAbG;EAHI,CAAX,CAAP;AAmBH,C"}
1
+ {"version":3,"names":["params","context","table","entityName","attributes","getExtraAttributes","Entity","name","PK","partitionKey","SK","sortKey","version","type","tenant"],"sources":["systemEntity.ts"],"sourcesContent":["import { Entity, Table } from \"dynamodb-toolbox\";\nimport { FileManagerContext } from \"@webiny/api-file-manager/types\";\nimport { getExtraAttributes } from \"@webiny/db-dynamodb/utils/attributes\";\n\nexport interface SystemEntityParams {\n context: FileManagerContext;\n table: Table;\n}\nexport default (params: SystemEntityParams): Entity<any> => {\n const { context, table } = params;\n const entityName = \"System\";\n const attributes = getExtraAttributes(context, entityName);\n return new Entity({\n name: entityName,\n table,\n attributes: {\n PK: {\n partitionKey: true\n },\n SK: {\n sortKey: true\n },\n version: {\n type: \"string\"\n },\n tenant: {\n type: \"string\"\n },\n ...attributes\n }\n });\n};\n"],"mappings":";;;;;;;;AAAA;AAEA;AAA0E,eAM1DA,MAA0B,IAAkB;EACxD,MAAM;IAAEC,OAAO;IAAEC;EAAM,CAAC,GAAGF,MAAM;EACjC,MAAMG,UAAU,GAAG,QAAQ;EAC3B,MAAMC,UAAU,GAAG,IAAAC,8BAAkB,EAACJ,OAAO,EAAEE,UAAU,CAAC;EAC1D,OAAO,IAAIG,uBAAM,CAAC;IACdC,IAAI,EAAEJ,UAAU;IAChBD,KAAK;IACLE,UAAU;MACNI,EAAE,EAAE;QACAC,YAAY,EAAE;MAClB,CAAC;MACDC,EAAE,EAAE;QACAC,OAAO,EAAE;MACb,CAAC;MACDC,OAAO,EAAE;QACLC,IAAI,EAAE;MACV,CAAC;MACDC,MAAM,EAAE;QACJD,IAAI,EAAE;MACV;IAAC,GACET,UAAU;EAErB,CAAC,CAAC;AACN,CAAC;AAAA"}
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _dynamodbToolbox = require("dynamodb-toolbox");
9
-
10
8
  var _utils = require("../operations/utils");
11
-
12
9
  var _default = params => {
13
10
  const {
14
11
  context
@@ -17,8 +14,13 @@ var _default = params => {
17
14
  name: process.env.DB_TABLE_FILE_MANGER || process.env.DB_TABLE || (0, _utils.getTable)(context),
18
15
  partitionKey: "PK",
19
16
  sortKey: "SK",
20
- DocumentClient: (0, _utils.getDocumentClient)(context)
17
+ DocumentClient: (0, _utils.getDocumentClient)(context),
18
+ indexes: {
19
+ GSI1: {
20
+ partitionKey: "GSI1_PK",
21
+ sortKey: "GSI1_SK"
22
+ }
23
+ }
21
24
  });
22
25
  };
23
-
24
26
  exports.default = _default;
@@ -1 +1 @@
1
- {"version":3,"names":["params","context","Table","name","process","env","DB_TABLE_FILE_MANGER","DB_TABLE","getTable","partitionKey","sortKey","DocumentClient","getDocumentClient"],"sources":["table.ts"],"sourcesContent":["import { Table } from \"dynamodb-toolbox\";\nimport { getDocumentClient, getTable } from \"~/operations/utils\";\nimport { FileManagerContext } from \"@webiny/api-file-manager/types\";\n\nexport interface TableParams {\n context: FileManagerContext;\n}\nexport default (params: TableParams): Table => {\n const { context } = params;\n return new Table({\n name: process.env.DB_TABLE_FILE_MANGER || process.env.DB_TABLE || getTable(context),\n partitionKey: \"PK\",\n sortKey: \"SK\",\n DocumentClient: getDocumentClient(context)\n });\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;eAMgBA,MAAD,IAAgC;EAC3C,MAAM;IAAEC;EAAF,IAAcD,MAApB;EACA,OAAO,IAAIE,sBAAJ,CAAU;IACbC,IAAI,EAAEC,OAAO,CAACC,GAAR,CAAYC,oBAAZ,IAAoCF,OAAO,CAACC,GAAR,CAAYE,QAAhD,IAA4D,IAAAC,eAAA,EAASP,OAAT,CADrD;IAEbQ,YAAY,EAAE,IAFD;IAGbC,OAAO,EAAE,IAHI;IAIbC,cAAc,EAAE,IAAAC,wBAAA,EAAkBX,OAAlB;EAJH,CAAV,CAAP;AAMH,C"}
1
+ {"version":3,"names":["params","context","Table","name","process","env","DB_TABLE_FILE_MANGER","DB_TABLE","getTable","partitionKey","sortKey","DocumentClient","getDocumentClient","indexes","GSI1"],"sources":["table.ts"],"sourcesContent":["import { Table } from \"dynamodb-toolbox\";\nimport { getDocumentClient, getTable } from \"~/operations/utils\";\nimport { FileManagerContext } from \"@webiny/api-file-manager/types\";\n\nexport interface TableParams {\n context: FileManagerContext;\n}\nexport default (params: TableParams): Table => {\n const { context } = params;\n return new Table({\n name: process.env.DB_TABLE_FILE_MANGER || process.env.DB_TABLE || getTable(context),\n partitionKey: \"PK\",\n sortKey: \"SK\",\n DocumentClient: getDocumentClient(context),\n indexes: {\n GSI1: {\n partitionKey: \"GSI1_PK\",\n sortKey: \"GSI1_SK\"\n }\n }\n });\n};\n"],"mappings":";;;;;;AAAA;AACA;AAAiE,eAMjDA,MAAmB,IAAY;EAC3C,MAAM;IAAEC;EAAQ,CAAC,GAAGD,MAAM;EAC1B,OAAO,IAAIE,sBAAK,CAAC;IACbC,IAAI,EAAEC,OAAO,CAACC,GAAG,CAACC,oBAAoB,IAAIF,OAAO,CAACC,GAAG,CAACE,QAAQ,IAAI,IAAAC,eAAQ,EAACP,OAAO,CAAC;IACnFQ,YAAY,EAAE,IAAI;IAClBC,OAAO,EAAE,IAAI;IACbC,cAAc,EAAE,IAAAC,wBAAiB,EAACX,OAAO,CAAC;IAC1CY,OAAO,EAAE;MACLC,IAAI,EAAE;QACFL,YAAY,EAAE,SAAS;QACvBC,OAAO,EAAE;MACb;IACJ;EACJ,CAAC,CAAC;AACN,CAAC;AAAA"}
package/index.js CHANGED
@@ -4,13 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _files = require("./operations/files");
9
-
10
8
  var _settings = require("./operations/settings");
11
-
12
9
  var _system = require("./operations/system");
13
-
14
10
  var _default = () => [new _files.FilesStorageOperationsProviderDdb(), new _settings.SettingsStorageOperationsProviderDdbPlugin(), new _system.SystemStorageOperationsProviderDdbPlugin()];
15
-
16
11
  exports.default = _default;
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":["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;AAA+E,eAEhE,MAAM,CACjB,IAAIA,wCAAiC,EAAE,EACvC,IAAIC,oDAA0C,EAAE,EAChD,IAAIC,gDAAwC,EAAE,CACjD;AAAA"}
@@ -5,7 +5,8 @@ interface ConstructorParams {
5
5
  export declare class FilesStorageOperations implements FileManagerFilesStorageOperations {
6
6
  private readonly _context;
7
7
  private readonly table;
8
- private readonly entity;
8
+ private readonly fileEntity;
9
+ private readonly aliasEntity;
9
10
  private get context();
10
11
  constructor({ context }: ConstructorParams);
11
12
  get(params: FileManagerFilesStorageOperationsGetParams): Promise<File | null>;
@@ -17,6 +18,7 @@ export declare class FilesStorageOperations implements FileManagerFilesStorageOp
17
18
  tags(params: FileManagerFilesStorageOperationsTagsParams): Promise<FileManagerFilesStorageOperationsTagsResponse>;
18
19
  private createQueryAllOptions;
19
20
  private createPartitionKey;
20
- private createSortKey;
21
+ private createGSI1PartitionKey;
22
+ private createNewAliasesRecords;
21
23
  }
22
24
  export {};
@@ -1,74 +1,54 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.FilesStorageOperations = void 0;
9
-
10
8
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
-
14
10
  var _error = _interopRequireDefault(require("@webiny/error"));
15
-
16
11
  var _table = _interopRequireDefault(require("../../definitions/table"));
17
-
18
- var _filesEntity = _interopRequireDefault(require("../../definitions/filesEntity"));
19
-
20
12
  var _query = require("@webiny/db-dynamodb/utils/query");
21
-
22
13
  var _cursor = require("@webiny/db-dynamodb/utils/cursor");
23
-
24
14
  var _filter = require("@webiny/db-dynamodb/utils/filter");
25
-
26
15
  var _sort = require("@webiny/db-dynamodb/utils/sort");
27
-
28
16
  var _FileDynamoDbFieldPlugin = require("../../plugins/FileDynamoDbFieldPlugin");
29
-
30
17
  var _batchWrite = require("@webiny/db-dynamodb/utils/batchWrite");
31
-
32
18
  var _get = require("@webiny/db-dynamodb/utils/get");
33
-
34
- var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
35
-
19
+ var _dbDynamodb = require("@webiny/db-dynamodb");
36
20
  class FilesStorageOperations {
37
21
  get context() {
38
22
  return this._context;
39
23
  }
40
-
41
24
  constructor({
42
25
  context
43
26
  }) {
44
27
  (0, _defineProperty2.default)(this, "_context", void 0);
45
28
  (0, _defineProperty2.default)(this, "table", void 0);
46
- (0, _defineProperty2.default)(this, "entity", void 0);
29
+ (0, _defineProperty2.default)(this, "fileEntity", void 0);
30
+ (0, _defineProperty2.default)(this, "aliasEntity", void 0);
47
31
  this._context = context;
48
32
  this.table = (0, _table.default)({
49
33
  context
50
34
  });
51
- this.entity = (0, _filesEntity.default)({
52
- context,
53
- table: this.table
54
- });
35
+ this.fileEntity = (0, _dbDynamodb.createStandardEntity)(this.table, "FM.File");
36
+ this.aliasEntity = (0, _dbDynamodb.createStandardEntity)(this.table, "FM.FileAlias");
55
37
  }
56
-
57
38
  async get(params) {
58
39
  const {
59
40
  where
60
41
  } = params;
61
42
  const keys = {
62
43
  PK: this.createPartitionKey(where),
63
- SK: this.createSortKey(where)
44
+ SK: "A"
64
45
  };
65
-
66
46
  try {
67
47
  const file = await (0, _get.get)({
68
- entity: this.entity,
48
+ entity: this.fileEntity,
69
49
  keys
70
50
  });
71
- return (0, _cleanup.cleanupItem)(this.entity, file);
51
+ return file ? file.data : null;
72
52
  } catch (ex) {
73
53
  throw new _error.default(ex.message || "Could not fetch requested file.", ex.code || "GET_FILE_ERROR", {
74
54
  error: ex,
@@ -76,90 +56,150 @@ class FilesStorageOperations {
76
56
  });
77
57
  }
78
58
  }
79
-
80
59
  async create(params) {
81
60
  const {
82
61
  file
83
62
  } = params;
84
- const keys = {
63
+ const items = [];
64
+ const item = {
85
65
  PK: this.createPartitionKey(file),
86
- SK: this.createSortKey(file)
66
+ SK: "A",
67
+ GSI1_PK: this.createGSI1PartitionKey(file),
68
+ GSI1_SK: file.id,
69
+ TYPE: "fm.file",
70
+ data: file
87
71
  };
88
- const item = (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, file), keys), {}, {
89
- TYPE: "fm.file"
72
+ items.push(this.fileEntity.putBatch(item));
73
+ this.createNewAliasesRecords(file).forEach(alias => {
74
+ items.push(this.aliasEntity.putBatch(alias));
90
75
  });
91
-
92
76
  try {
93
- await this.entity.put(item);
77
+ await (0, _batchWrite.batchWriteAll)({
78
+ table: this.table,
79
+ items
80
+ });
94
81
  } catch (ex) {
95
82
  throw new _error.default(ex.message || "Could not create a new file in the DynamoDB.", ex.code || "CREATE_FILE_ERROR", {
96
83
  error: ex,
97
- item
84
+ items
98
85
  });
99
86
  }
100
-
101
87
  return file;
102
88
  }
103
-
104
89
  async update(params) {
105
90
  const {
106
91
  file
107
92
  } = params;
108
- const keys = {
93
+ const items = [];
94
+ const item = {
109
95
  PK: this.createPartitionKey(file),
110
- SK: this.createSortKey(file)
96
+ SK: "A",
97
+ GSI1_PK: this.createGSI1PartitionKey(file),
98
+ GSI1_SK: file.id,
99
+ TYPE: "fm.file",
100
+ data: file
111
101
  };
112
- const item = (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, file), keys), {}, {
113
- TYPE: "fm.file"
102
+ items.push(this.fileEntity.putBatch(item));
103
+ const existingAliases = await (0, _query.queryAll)({
104
+ entity: this.aliasEntity,
105
+ partitionKey: `T#${file.tenant}#L#${file.locale}#FM#FILE#${file.id}`,
106
+ options: {
107
+ beginsWith: `ALIAS#`
108
+ }
109
+ });
110
+ const newAliases = this.createNewAliasesRecords(file, existingAliases.map(alias => alias.data));
111
+ newAliases.forEach(alias => {
112
+ items.push(this.aliasEntity.putBatch(alias));
114
113
  });
115
114
 
115
+ // Delete aliases that are in the DB but are NOT in the file.
116
+ for (const {
117
+ data
118
+ } of existingAliases) {
119
+ if (!file.aliases.some(alias => data.alias === alias)) {
120
+ items.push(this.aliasEntity.deleteBatch({
121
+ PK: this.createPartitionKey(file),
122
+ SK: `ALIAS#${data.alias}`
123
+ }));
124
+ }
125
+ }
116
126
  try {
117
- await this.entity.put(item);
127
+ await (0, _batchWrite.batchWriteAll)({
128
+ table: this.table,
129
+ items
130
+ });
118
131
  } catch (ex) {
119
132
  throw new _error.default(ex.message || "Could not update a file in the DynamoDB.", ex.code || "UPDATE_FILE_ERROR", {
120
- error: ex,
121
- item
133
+ items
122
134
  });
123
135
  }
124
-
125
- return file;
136
+ return params.file;
126
137
  }
127
-
128
138
  async delete(params) {
129
139
  const {
130
140
  file
131
141
  } = params;
132
142
  const keys = {
133
143
  PK: this.createPartitionKey(file),
134
- SK: this.createSortKey(file)
144
+ SK: "A"
135
145
  };
146
+ const aliasItems = await (0, _query.queryAll)({
147
+ entity: this.aliasEntity,
148
+ partitionKey: keys.PK,
149
+ options: {
150
+ beginsWith: "ALIAS#"
151
+ }
152
+ });
136
153
 
154
+ // All items to delete in batch
155
+ const items = [];
137
156
  try {
138
- await this.entity.delete(keys);
157
+ // Delete the main file item
158
+ items.push(this.fileEntity.deleteBatch(keys));
159
+
160
+ // Delete file alias items
161
+ aliasItems.forEach(item => {
162
+ items.push(this.aliasEntity.deleteBatch({
163
+ PK: item.PK,
164
+ SK: item.SK
165
+ }));
166
+ });
167
+ await (0, _batchWrite.batchWriteAll)({
168
+ table: this.table,
169
+ items
170
+ });
139
171
  } catch (ex) {
140
172
  throw new _error.default(ex.message || "Could not delete file from the DynamoDB.", ex.code || "DELETE_FILE_ERROR", {
141
173
  error: ex,
142
174
  file,
143
- keys
175
+ keys,
176
+ aliasItems
144
177
  });
145
178
  }
146
179
  }
147
-
148
180
  async createBatch(params) {
149
181
  const {
150
182
  files
151
183
  } = params;
152
- const items = files.map(file => {
153
- return this.entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, file), {}, {
184
+
185
+ // Items to be written in batch
186
+ const items = [];
187
+ files.forEach(file => {
188
+ items.push(this.fileEntity.putBatch({
154
189
  PK: this.createPartitionKey(file),
155
- SK: this.createSortKey(file),
156
- TYPE: "fm.file"
190
+ SK: "A",
191
+ GSI1_PK: this.createGSI1PartitionKey(file),
192
+ GSI1_SK: file.id,
193
+ TYPE: "fm.file",
194
+ data: file
157
195
  }));
196
+ this.createNewAliasesRecords(file).forEach(alias => {
197
+ items.push(this.aliasEntity.putBatch(alias));
198
+ });
158
199
  });
159
-
160
200
  try {
161
201
  await (0, _batchWrite.batchWriteAll)({
162
- table: this.entity.table,
202
+ table: this.table,
163
203
  items
164
204
  });
165
205
  } catch (ex) {
@@ -168,10 +208,8 @@ class FilesStorageOperations {
168
208
  files
169
209
  });
170
210
  }
171
-
172
211
  return files;
173
212
  }
174
-
175
213
  async list(params) {
176
214
  const {
177
215
  where: initialWhere,
@@ -183,14 +221,14 @@ class FilesStorageOperations {
183
221
  where: initialWhere
184
222
  });
185
223
  const queryAllParams = {
186
- entity: this.entity,
187
- partitionKey: this.createPartitionKey(initialWhere),
224
+ entity: this.fileEntity,
225
+ partitionKey: this.createGSI1PartitionKey(initialWhere),
188
226
  options
189
227
  };
190
228
  let items = [];
191
-
192
229
  try {
193
- items = await (0, _query.queryAll)(queryAllParams);
230
+ const dbItems = await (0, _query.queryAll)(queryAllParams);
231
+ items = dbItems.map(item => item.data);
194
232
  } catch (ex) {
195
233
  throw new _error.default(ex.message || "Could not query for the files.", ex.code || "FILE_LIST_ERROR", {
196
234
  error: ex,
@@ -206,16 +244,13 @@ class FilesStorageOperations {
206
244
  }
207
245
  });
208
246
  }
209
-
210
247
  const where = (0, _objectSpread2.default)({}, initialWhere);
211
-
212
248
  if (where.search) {
213
249
  where.contains = {
214
250
  fields: ["name", "tags"],
215
251
  value: where.search
216
252
  };
217
253
  }
218
-
219
254
  delete where["tenant"];
220
255
  delete where["locale"];
221
256
  delete where["search"];
@@ -224,7 +259,6 @@ class FilesStorageOperations {
224
259
  * Filter the read items via the code.
225
260
  * It will build the filters out of the where input and transform the values it is using.
226
261
  */
227
-
228
262
  const filteredFiles = (0, _filter.filterItems)({
229
263
  plugins: this.context.plugins,
230
264
  items,
@@ -236,7 +270,6 @@ class FilesStorageOperations {
236
270
  * Sorting is also done via the code.
237
271
  * It takes the sort input and sorts by it via the lodash sortBy method.
238
272
  */
239
-
240
273
  const sortedFiles = (0, _sort.sortItems)({
241
274
  items: filteredFiles,
242
275
  sort,
@@ -250,7 +283,6 @@ class FilesStorageOperations {
250
283
  * Although we do not need a cursor here, we will use it as such to keep it standardized.
251
284
  * Number is simply encoded.
252
285
  */
253
-
254
286
  const cursor = files.length > 0 ? (0, _cursor.encodeCursor)(start + limit) : null;
255
287
  const meta = {
256
288
  hasMoreItems,
@@ -259,60 +291,56 @@ class FilesStorageOperations {
259
291
  };
260
292
  return [files, meta];
261
293
  }
262
-
263
294
  async tags(params) {
264
295
  const {
265
296
  where: initialWhere
266
297
  } = params;
267
298
  const queryAllParams = {
268
- entity: this.entity,
269
- partitionKey: this.createPartitionKey(initialWhere),
299
+ entity: this.fileEntity,
300
+ partitionKey: this.createGSI1PartitionKey(initialWhere),
270
301
  options: {
302
+ index: "GSI1",
271
303
  gte: " ",
272
304
  reverse: false
273
305
  }
274
306
  };
275
307
  let results = [];
276
-
277
308
  try {
278
- results = await (0, _query.queryAll)(queryAllParams);
309
+ const dbItems = await (0, _query.queryAll)(queryAllParams);
310
+ results = dbItems.map(item => item.data);
279
311
  } catch (ex) {
280
312
  throw new _error.default(ex.message || "Error in the DynamoDB query.", ex.code || "DYNAMODB_ERROR", {
281
313
  error: ex,
282
314
  query: queryAllParams
283
315
  });
284
316
  }
285
-
286
317
  const fields = this.context.plugins.byType(_FileDynamoDbFieldPlugin.FileDynamoDbFieldPlugin.type);
287
318
  const where = (0, _objectSpread2.default)({}, initialWhere);
288
319
  delete where["tenant"];
289
320
  delete where["locale"];
321
+
290
322
  /**
291
323
  * Filter the read items via the code.
292
324
  * It will build the filters out of the where input and transform the values it is using.
293
325
  */
294
-
295
326
  const filteredItems = (0, _filter.filterItems)({
296
327
  plugins: this.context.plugins,
297
328
  items: results,
298
329
  where,
299
330
  fields
300
331
  });
332
+
301
333
  /**
302
334
  * Aggregate all the tags from all the filtered items.
303
335
  */
304
-
305
336
  const tagsObject = filteredItems.reduce((collection, item) => {
306
337
  const tags = Array.isArray(item.tags) ? item.tags : [];
307
-
308
338
  for (const tag of tags) {
309
339
  if (!collection[tag]) {
310
340
  collection[tag] = [];
311
341
  }
312
-
313
342
  collection[tag].push(item.id);
314
343
  }
315
-
316
344
  return collection;
317
345
  }, {});
318
346
  const tags = Object.keys(tagsObject);
@@ -325,34 +353,57 @@ class FilesStorageOperations {
325
353
  };
326
354
  return [tags, meta];
327
355
  }
328
-
329
356
  createQueryAllOptions({
330
357
  where
331
358
  }) {
332
- const options = {};
333
-
359
+ const options = {
360
+ index: "GSI1"
361
+ };
334
362
  if (where.id) {
335
363
  options.eq = where.id;
364
+ } else {
365
+ options.gt = " ";
336
366
  }
337
-
338
367
  return options;
339
368
  }
340
-
341
369
  createPartitionKey(params) {
342
370
  const {
343
371
  tenant,
344
- locale
372
+ locale,
373
+ id
345
374
  } = params;
346
- return `T#${tenant}#L#${locale}#FM#F`;
375
+ return `T#${tenant}#L#${locale}#FM#FILE#${id}`;
347
376
  }
348
-
349
- createSortKey(params) {
377
+ createGSI1PartitionKey(params) {
350
378
  const {
351
- id
379
+ tenant,
380
+ locale
352
381
  } = params;
353
- return id;
382
+ return `T#${tenant}#L#${locale}#FM#FILES`;
354
383
  }
384
+ createNewAliasesRecords(file, existingAliases = []) {
385
+ return (file.aliases || []).map(alias => {
386
+ // If alias is already in the DB, skip it.
387
+ if (existingAliases.find(item => item.alias === alias)) {
388
+ return null;
389
+ }
355
390
 
391
+ // Add a new alias.
392
+ return {
393
+ PK: this.createPartitionKey(file),
394
+ SK: `ALIAS#${alias}`,
395
+ GSI1_PK: `T#${file.tenant}#FM#FILE_ALIASES`,
396
+ GSI1_SK: alias,
397
+ TYPE: "fm.fileAlias",
398
+ data: {
399
+ alias,
400
+ tenant: file.tenant,
401
+ locale: file.locale,
402
+ fileId: file.id,
403
+ key: file.key
404
+ }
405
+ };
406
+ }).filter(Boolean);
407
+ }
356
408
  }
357
-
358
409
  exports.FilesStorageOperations = FilesStorageOperations;