@webiny/api-file-manager-ddb 0.0.0-unstable.d65ec29d44 → 0.0.0-unstable.e3f4727c56
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.
- package/definitions/filesEntity.js +7 -45
- package/definitions/filesEntity.js.map +1 -1
- package/definitions/settingsEntity.js +9 -23
- package/definitions/settingsEntity.js.map +1 -1
- package/definitions/systemEntity.js +0 -6
- package/definitions/systemEntity.js.map +1 -1
- package/definitions/table.js +7 -5
- package/definitions/table.js.map +1 -1
- package/index.js +0 -5
- package/index.js.map +1 -1
- package/operations/files/FilesStorageOperations.d.ts +1 -1
- package/operations/files/FilesStorageOperations.js +43 -91
- package/operations/files/FilesStorageOperations.js.map +1 -1
- package/operations/files/fields.js +0 -3
- package/operations/files/fields.js.map +1 -1
- package/operations/files/index.js +0 -9
- package/operations/files/index.js.map +1 -1
- package/operations/settings/SettingsStorageOperations.js +19 -39
- package/operations/settings/SettingsStorageOperations.js.map +1 -1
- package/operations/settings/index.js +0 -8
- package/operations/settings/index.js.map +1 -1
- package/operations/system/SystemStorageOperations.js +0 -22
- package/operations/system/SystemStorageOperations.js.map +1 -1
- package/operations/system/index.js +0 -8
- package/operations/system/index.js.map +1 -1
- package/operations/utils.js +0 -10
- package/operations/utils.js.map +1 -1
- package/package.json +7 -7
- package/plugins/FileAttributePlugin.js +1 -7
- package/plugins/FileAttributePlugin.js.map +1 -1
- package/plugins/FileDynamoDbFieldPlugin.js +0 -5
- package/plugins/FileDynamoDbFieldPlugin.js.map +1 -1
- package/plugins/SettingsAttributePlugin.js +1 -7
- package/plugins/SettingsAttributePlugin.js.map +1 -1
- package/plugins/SystemAttributePlugin.js +0 -6
- package/plugins/SystemAttributePlugin.js.map +1 -1
|
@@ -1,76 +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 = "
|
|
22
|
-
const attributes = (0, _attributes.getExtraAttributes)(context, entityName);
|
|
12
|
+
const entityName = "FM.File";
|
|
23
13
|
return new _dynamodbToolbox.Entity({
|
|
24
14
|
name: entityName,
|
|
25
15
|
table,
|
|
26
|
-
attributes:
|
|
16
|
+
attributes: {
|
|
27
17
|
PK: {
|
|
28
18
|
partitionKey: true
|
|
29
19
|
},
|
|
30
20
|
SK: {
|
|
31
21
|
sortKey: true
|
|
32
22
|
},
|
|
33
|
-
|
|
34
|
-
type: "string"
|
|
35
|
-
},
|
|
36
|
-
id: {
|
|
37
|
-
type: "string"
|
|
38
|
-
},
|
|
39
|
-
key: {
|
|
40
|
-
type: "string"
|
|
41
|
-
},
|
|
42
|
-
size: {
|
|
43
|
-
type: "number"
|
|
44
|
-
},
|
|
45
|
-
type: {
|
|
23
|
+
GSI1_PK: {
|
|
46
24
|
type: "string"
|
|
47
25
|
},
|
|
48
|
-
|
|
26
|
+
GSI1_SK: {
|
|
49
27
|
type: "string"
|
|
50
28
|
},
|
|
51
|
-
|
|
52
|
-
type: "map"
|
|
53
|
-
},
|
|
54
|
-
tags: {
|
|
55
|
-
type: "list"
|
|
56
|
-
},
|
|
57
|
-
createdOn: {
|
|
29
|
+
TYPE: {
|
|
58
30
|
type: "string"
|
|
59
31
|
},
|
|
60
|
-
|
|
32
|
+
data: {
|
|
61
33
|
type: "map"
|
|
62
|
-
},
|
|
63
|
-
tenant: {
|
|
64
|
-
type: "string"
|
|
65
|
-
},
|
|
66
|
-
locale: {
|
|
67
|
-
type: "string"
|
|
68
|
-
},
|
|
69
|
-
webinyVersion: {
|
|
70
|
-
type: "string"
|
|
71
34
|
}
|
|
72
|
-
}
|
|
35
|
+
}
|
|
73
36
|
});
|
|
74
37
|
};
|
|
75
|
-
|
|
76
38
|
exports.default = _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["params","
|
|
1
|
+
{"version":3,"names":["params","table","entityName","Entity","name","attributes","PK","partitionKey","SK","sortKey","GSI1_PK","type","GSI1_SK","TYPE","data"],"sources":["filesEntity.ts"],"sourcesContent":["import { Entity, Table } from \"dynamodb-toolbox\";\nimport { FileManagerContext } from \"@webiny/api-file-manager/types\";\n\nexport interface FilesEntityParams {\n context: FileManagerContext;\n table: Table;\n}\nexport default (params: FilesEntityParams): Entity<any> => {\n const { table } = params;\n const entityName = \"FM.File\";\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,MAAyB,IAAkB;EACvD,MAAM;IAAEC;EAAM,CAAC,GAAGD,MAAM;EACxB,MAAME,UAAU,GAAG,SAAS;EAC5B,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,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:
|
|
16
|
+
attributes: {
|
|
27
17
|
PK: {
|
|
28
18
|
partitionKey: true
|
|
29
19
|
},
|
|
30
20
|
SK: {
|
|
31
21
|
sortKey: true
|
|
32
22
|
},
|
|
33
|
-
|
|
23
|
+
GSI1_PK: {
|
|
34
24
|
type: "string"
|
|
35
25
|
},
|
|
36
|
-
|
|
26
|
+
GSI1_SK: {
|
|
37
27
|
type: "string"
|
|
38
28
|
},
|
|
39
|
-
|
|
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
|
-
}
|
|
35
|
+
}
|
|
49
36
|
});
|
|
50
37
|
};
|
|
51
|
-
|
|
52
38
|
exports.default = _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["params","
|
|
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":"
|
|
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"}
|
package/definitions/table.js
CHANGED
|
@@ -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;
|
package/definitions/table.js.map
CHANGED
|
@@ -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":"
|
|
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":"
|
|
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"}
|
|
@@ -17,6 +17,6 @@ export declare class FilesStorageOperations implements FileManagerFilesStorageOp
|
|
|
17
17
|
tags(params: FileManagerFilesStorageOperationsTagsParams): Promise<FileManagerFilesStorageOperationsTagsResponse>;
|
|
18
18
|
private createQueryAllOptions;
|
|
19
19
|
private createPartitionKey;
|
|
20
|
-
private
|
|
20
|
+
private createGSI1PartitionKey;
|
|
21
21
|
}
|
|
22
22
|
export {};
|
|
@@ -1,43 +1,26 @@
|
|
|
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
12
|
var _filesEntity = _interopRequireDefault(require("../../definitions/filesEntity"));
|
|
19
|
-
|
|
20
13
|
var _query = require("@webiny/db-dynamodb/utils/query");
|
|
21
|
-
|
|
22
14
|
var _cursor = require("@webiny/db-dynamodb/utils/cursor");
|
|
23
|
-
|
|
24
15
|
var _filter = require("@webiny/db-dynamodb/utils/filter");
|
|
25
|
-
|
|
26
16
|
var _sort = require("@webiny/db-dynamodb/utils/sort");
|
|
27
|
-
|
|
28
17
|
var _FileDynamoDbFieldPlugin = require("../../plugins/FileDynamoDbFieldPlugin");
|
|
29
|
-
|
|
30
18
|
var _batchWrite = require("@webiny/db-dynamodb/utils/batchWrite");
|
|
31
|
-
|
|
32
19
|
var _get = require("@webiny/db-dynamodb/utils/get");
|
|
33
|
-
|
|
34
|
-
var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
35
|
-
|
|
36
20
|
class FilesStorageOperations {
|
|
37
21
|
get context() {
|
|
38
22
|
return this._context;
|
|
39
23
|
}
|
|
40
|
-
|
|
41
24
|
constructor({
|
|
42
25
|
context
|
|
43
26
|
}) {
|
|
@@ -53,22 +36,20 @@ class FilesStorageOperations {
|
|
|
53
36
|
table: this.table
|
|
54
37
|
});
|
|
55
38
|
}
|
|
56
|
-
|
|
57
39
|
async get(params) {
|
|
58
40
|
const {
|
|
59
41
|
where
|
|
60
42
|
} = params;
|
|
61
43
|
const keys = {
|
|
62
44
|
PK: this.createPartitionKey(where),
|
|
63
|
-
SK:
|
|
45
|
+
SK: "A"
|
|
64
46
|
};
|
|
65
|
-
|
|
66
47
|
try {
|
|
67
48
|
const file = await (0, _get.get)({
|
|
68
49
|
entity: this.entity,
|
|
69
50
|
keys
|
|
70
51
|
});
|
|
71
|
-
return
|
|
52
|
+
return file ? file.data : null;
|
|
72
53
|
} catch (ex) {
|
|
73
54
|
throw new _error.default(ex.message || "Could not fetch requested file.", ex.code || "GET_FILE_ERROR", {
|
|
74
55
|
error: ex,
|
|
@@ -76,19 +57,18 @@ class FilesStorageOperations {
|
|
|
76
57
|
});
|
|
77
58
|
}
|
|
78
59
|
}
|
|
79
|
-
|
|
80
60
|
async create(params) {
|
|
81
61
|
const {
|
|
82
62
|
file
|
|
83
63
|
} = params;
|
|
84
|
-
const
|
|
64
|
+
const item = {
|
|
85
65
|
PK: this.createPartitionKey(file),
|
|
86
|
-
SK:
|
|
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"
|
|
90
|
-
});
|
|
91
|
-
|
|
92
72
|
try {
|
|
93
73
|
await this.entity.put(item);
|
|
94
74
|
} catch (ex) {
|
|
@@ -97,43 +77,27 @@ class FilesStorageOperations {
|
|
|
97
77
|
item
|
|
98
78
|
});
|
|
99
79
|
}
|
|
100
|
-
|
|
101
80
|
return file;
|
|
102
81
|
}
|
|
103
|
-
|
|
104
82
|
async update(params) {
|
|
105
|
-
const {
|
|
106
|
-
file
|
|
107
|
-
} = params;
|
|
108
|
-
const keys = {
|
|
109
|
-
PK: this.createPartitionKey(file),
|
|
110
|
-
SK: this.createSortKey(file)
|
|
111
|
-
};
|
|
112
|
-
const item = (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, file), keys), {}, {
|
|
113
|
-
TYPE: "fm.file"
|
|
114
|
-
});
|
|
115
|
-
|
|
116
83
|
try {
|
|
117
|
-
await this.
|
|
84
|
+
await this.create(params);
|
|
118
85
|
} catch (ex) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
86
|
+
if (ex.code === "CREATE_FILE_ERROR") {
|
|
87
|
+
throw new _error.default("Could not update a file in the DynamoDB.", "UPDATE_FILE_ERROR", ex.data);
|
|
88
|
+
}
|
|
89
|
+
throw ex;
|
|
123
90
|
}
|
|
124
|
-
|
|
125
|
-
return file;
|
|
91
|
+
return params.file;
|
|
126
92
|
}
|
|
127
|
-
|
|
128
93
|
async delete(params) {
|
|
129
94
|
const {
|
|
130
95
|
file
|
|
131
96
|
} = params;
|
|
132
97
|
const keys = {
|
|
133
98
|
PK: this.createPartitionKey(file),
|
|
134
|
-
SK:
|
|
99
|
+
SK: "A"
|
|
135
100
|
};
|
|
136
|
-
|
|
137
101
|
try {
|
|
138
102
|
await this.entity.delete(keys);
|
|
139
103
|
} catch (ex) {
|
|
@@ -144,19 +108,20 @@ class FilesStorageOperations {
|
|
|
144
108
|
});
|
|
145
109
|
}
|
|
146
110
|
}
|
|
147
|
-
|
|
148
111
|
async createBatch(params) {
|
|
149
112
|
const {
|
|
150
113
|
files
|
|
151
114
|
} = params;
|
|
152
115
|
const items = files.map(file => {
|
|
153
|
-
return this.entity.putBatch(
|
|
116
|
+
return this.entity.putBatch({
|
|
154
117
|
PK: this.createPartitionKey(file),
|
|
155
|
-
SK:
|
|
156
|
-
|
|
157
|
-
|
|
118
|
+
SK: "A",
|
|
119
|
+
GSI1_PK: this.createGSI1PartitionKey(file),
|
|
120
|
+
GSI1_SK: file.id,
|
|
121
|
+
TYPE: "fm.file",
|
|
122
|
+
data: file
|
|
123
|
+
});
|
|
158
124
|
});
|
|
159
|
-
|
|
160
125
|
try {
|
|
161
126
|
await (0, _batchWrite.batchWriteAll)({
|
|
162
127
|
table: this.entity.table,
|
|
@@ -168,10 +133,8 @@ class FilesStorageOperations {
|
|
|
168
133
|
files
|
|
169
134
|
});
|
|
170
135
|
}
|
|
171
|
-
|
|
172
136
|
return files;
|
|
173
137
|
}
|
|
174
|
-
|
|
175
138
|
async list(params) {
|
|
176
139
|
const {
|
|
177
140
|
where: initialWhere,
|
|
@@ -184,13 +147,13 @@ class FilesStorageOperations {
|
|
|
184
147
|
});
|
|
185
148
|
const queryAllParams = {
|
|
186
149
|
entity: this.entity,
|
|
187
|
-
partitionKey: this.
|
|
150
|
+
partitionKey: this.createGSI1PartitionKey(initialWhere),
|
|
188
151
|
options
|
|
189
152
|
};
|
|
190
153
|
let items = [];
|
|
191
|
-
|
|
192
154
|
try {
|
|
193
|
-
|
|
155
|
+
const dbItems = await (0, _query.queryAll)(queryAllParams);
|
|
156
|
+
items = dbItems.map(item => item.data);
|
|
194
157
|
} catch (ex) {
|
|
195
158
|
throw new _error.default(ex.message || "Could not query for the files.", ex.code || "FILE_LIST_ERROR", {
|
|
196
159
|
error: ex,
|
|
@@ -206,16 +169,13 @@ class FilesStorageOperations {
|
|
|
206
169
|
}
|
|
207
170
|
});
|
|
208
171
|
}
|
|
209
|
-
|
|
210
172
|
const where = (0, _objectSpread2.default)({}, initialWhere);
|
|
211
|
-
|
|
212
173
|
if (where.search) {
|
|
213
174
|
where.contains = {
|
|
214
175
|
fields: ["name", "tags"],
|
|
215
176
|
value: where.search
|
|
216
177
|
};
|
|
217
178
|
}
|
|
218
|
-
|
|
219
179
|
delete where["tenant"];
|
|
220
180
|
delete where["locale"];
|
|
221
181
|
delete where["search"];
|
|
@@ -224,7 +184,6 @@ class FilesStorageOperations {
|
|
|
224
184
|
* Filter the read items via the code.
|
|
225
185
|
* It will build the filters out of the where input and transform the values it is using.
|
|
226
186
|
*/
|
|
227
|
-
|
|
228
187
|
const filteredFiles = (0, _filter.filterItems)({
|
|
229
188
|
plugins: this.context.plugins,
|
|
230
189
|
items,
|
|
@@ -236,7 +195,6 @@ class FilesStorageOperations {
|
|
|
236
195
|
* Sorting is also done via the code.
|
|
237
196
|
* It takes the sort input and sorts by it via the lodash sortBy method.
|
|
238
197
|
*/
|
|
239
|
-
|
|
240
198
|
const sortedFiles = (0, _sort.sortItems)({
|
|
241
199
|
items: filteredFiles,
|
|
242
200
|
sort,
|
|
@@ -250,7 +208,6 @@ class FilesStorageOperations {
|
|
|
250
208
|
* Although we do not need a cursor here, we will use it as such to keep it standardized.
|
|
251
209
|
* Number is simply encoded.
|
|
252
210
|
*/
|
|
253
|
-
|
|
254
211
|
const cursor = files.length > 0 ? (0, _cursor.encodeCursor)(start + limit) : null;
|
|
255
212
|
const meta = {
|
|
256
213
|
hasMoreItems,
|
|
@@ -259,60 +216,56 @@ class FilesStorageOperations {
|
|
|
259
216
|
};
|
|
260
217
|
return [files, meta];
|
|
261
218
|
}
|
|
262
|
-
|
|
263
219
|
async tags(params) {
|
|
264
220
|
const {
|
|
265
221
|
where: initialWhere
|
|
266
222
|
} = params;
|
|
267
223
|
const queryAllParams = {
|
|
268
224
|
entity: this.entity,
|
|
269
|
-
partitionKey: this.
|
|
225
|
+
partitionKey: this.createGSI1PartitionKey(initialWhere),
|
|
270
226
|
options: {
|
|
227
|
+
index: "GSI1",
|
|
271
228
|
gte: " ",
|
|
272
229
|
reverse: false
|
|
273
230
|
}
|
|
274
231
|
};
|
|
275
232
|
let results = [];
|
|
276
|
-
|
|
277
233
|
try {
|
|
278
|
-
|
|
234
|
+
const dbItems = await (0, _query.queryAll)(queryAllParams);
|
|
235
|
+
results = dbItems.map(item => item.data);
|
|
279
236
|
} catch (ex) {
|
|
280
237
|
throw new _error.default(ex.message || "Error in the DynamoDB query.", ex.code || "DYNAMODB_ERROR", {
|
|
281
238
|
error: ex,
|
|
282
239
|
query: queryAllParams
|
|
283
240
|
});
|
|
284
241
|
}
|
|
285
|
-
|
|
286
242
|
const fields = this.context.plugins.byType(_FileDynamoDbFieldPlugin.FileDynamoDbFieldPlugin.type);
|
|
287
243
|
const where = (0, _objectSpread2.default)({}, initialWhere);
|
|
288
244
|
delete where["tenant"];
|
|
289
245
|
delete where["locale"];
|
|
246
|
+
|
|
290
247
|
/**
|
|
291
248
|
* Filter the read items via the code.
|
|
292
249
|
* It will build the filters out of the where input and transform the values it is using.
|
|
293
250
|
*/
|
|
294
|
-
|
|
295
251
|
const filteredItems = (0, _filter.filterItems)({
|
|
296
252
|
plugins: this.context.plugins,
|
|
297
253
|
items: results,
|
|
298
254
|
where,
|
|
299
255
|
fields
|
|
300
256
|
});
|
|
257
|
+
|
|
301
258
|
/**
|
|
302
259
|
* Aggregate all the tags from all the filtered items.
|
|
303
260
|
*/
|
|
304
|
-
|
|
305
261
|
const tagsObject = filteredItems.reduce((collection, item) => {
|
|
306
262
|
const tags = Array.isArray(item.tags) ? item.tags : [];
|
|
307
|
-
|
|
308
263
|
for (const tag of tags) {
|
|
309
264
|
if (!collection[tag]) {
|
|
310
265
|
collection[tag] = [];
|
|
311
266
|
}
|
|
312
|
-
|
|
313
267
|
collection[tag].push(item.id);
|
|
314
268
|
}
|
|
315
|
-
|
|
316
269
|
return collection;
|
|
317
270
|
}, {});
|
|
318
271
|
const tags = Object.keys(tagsObject);
|
|
@@ -325,34 +278,33 @@ class FilesStorageOperations {
|
|
|
325
278
|
};
|
|
326
279
|
return [tags, meta];
|
|
327
280
|
}
|
|
328
|
-
|
|
329
281
|
createQueryAllOptions({
|
|
330
282
|
where
|
|
331
283
|
}) {
|
|
332
|
-
const options = {
|
|
333
|
-
|
|
284
|
+
const options = {
|
|
285
|
+
index: "GSI1"
|
|
286
|
+
};
|
|
334
287
|
if (where.id) {
|
|
335
288
|
options.eq = where.id;
|
|
289
|
+
} else {
|
|
290
|
+
options.gt = " ";
|
|
336
291
|
}
|
|
337
|
-
|
|
338
292
|
return options;
|
|
339
293
|
}
|
|
340
|
-
|
|
341
294
|
createPartitionKey(params) {
|
|
342
295
|
const {
|
|
343
296
|
tenant,
|
|
344
|
-
locale
|
|
297
|
+
locale,
|
|
298
|
+
id
|
|
345
299
|
} = params;
|
|
346
|
-
return `T#${tenant}#L#${locale}#FM#
|
|
300
|
+
return `T#${tenant}#L#${locale}#FM#FILE#${id}`;
|
|
347
301
|
}
|
|
348
|
-
|
|
349
|
-
createSortKey(params) {
|
|
302
|
+
createGSI1PartitionKey(params) {
|
|
350
303
|
const {
|
|
351
|
-
|
|
304
|
+
tenant,
|
|
305
|
+
locale
|
|
352
306
|
} = params;
|
|
353
|
-
return
|
|
307
|
+
return `T#${tenant}#L#${locale}#FM#FILES`;
|
|
354
308
|
}
|
|
355
|
-
|
|
356
309
|
}
|
|
357
|
-
|
|
358
310
|
exports.FilesStorageOperations = FilesStorageOperations;
|