@webiny/api-file-manager-ddb 5.41.4-beta.3 → 5.41.4-beta.5
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb";
|
|
2
|
-
import {
|
|
1
|
+
import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb";
|
|
2
|
+
import type { File, FileManagerAliasesStorageOperations } from "@webiny/api-file-manager/types";
|
|
3
3
|
interface AliasesStorageOperationsConfig {
|
|
4
4
|
documentClient: DynamoDBDocument;
|
|
5
5
|
}
|
|
@@ -19,43 +19,41 @@ class AliasesStorageOperations {
|
|
|
19
19
|
}
|
|
20
20
|
async deleteAliases(file) {
|
|
21
21
|
const aliasItems = await this.getExistingAliases(file);
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
table: this.table,
|
|
35
|
-
items
|
|
22
|
+
const batchWrite = (0, _dbDynamodb.createEntityWriteBatch)({
|
|
23
|
+
entity: this.aliasEntity,
|
|
24
|
+
delete: aliasItems.map(item => {
|
|
25
|
+
return {
|
|
26
|
+
PK: this.createPartitionKey({
|
|
27
|
+
id: item.fileId,
|
|
28
|
+
tenant: item.tenant,
|
|
29
|
+
locale: item.locale
|
|
30
|
+
}),
|
|
31
|
+
SK: `ALIAS#${item.alias}`
|
|
32
|
+
};
|
|
33
|
+
})
|
|
36
34
|
});
|
|
35
|
+
await batchWrite.execute();
|
|
37
36
|
}
|
|
38
37
|
async storeAliases(file) {
|
|
39
|
-
const items = [];
|
|
40
38
|
const existingAliases = await this.getExistingAliases(file);
|
|
41
39
|
const newAliases = this.createNewAliasesRecords(file, existingAliases);
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
const batchWrite = (0, _dbDynamodb.createEntityWriteBatch)({
|
|
41
|
+
entity: this.aliasEntity
|
|
44
42
|
});
|
|
43
|
+
for (const alias of newAliases) {
|
|
44
|
+
batchWrite.put(alias);
|
|
45
|
+
}
|
|
45
46
|
|
|
46
47
|
// Delete aliases that are in the DB but are NOT in the file.
|
|
47
48
|
for (const data of existingAliases) {
|
|
48
49
|
if (!file.aliases.some(alias => data.alias === alias)) {
|
|
49
|
-
|
|
50
|
+
batchWrite.delete({
|
|
50
51
|
PK: this.createPartitionKey(file),
|
|
51
52
|
SK: `ALIAS#${data.alias}`
|
|
52
|
-
})
|
|
53
|
+
});
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
|
-
await (
|
|
56
|
-
table: this.table,
|
|
57
|
-
items
|
|
58
|
-
});
|
|
56
|
+
await batchWrite.execute();
|
|
59
57
|
}
|
|
60
58
|
async getExistingAliases(file) {
|
|
61
59
|
const aliases = await (0, _dbDynamodb.queryAll)({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_dbDynamodb","require","AliasesStorageOperations","constructor","documentClient","table","createTable","aliasEntity","createStandardEntity","name","deleteAliases","file","aliasItems","getExistingAliases","
|
|
1
|
+
{"version":3,"names":["_dbDynamodb","require","AliasesStorageOperations","constructor","documentClient","table","createTable","aliasEntity","createStandardEntity","name","deleteAliases","file","aliasItems","getExistingAliases","batchWrite","createEntityWriteBatch","entity","delete","map","item","PK","createPartitionKey","id","fileId","tenant","locale","SK","alias","execute","storeAliases","existingAliases","newAliases","createNewAliasesRecords","put","data","aliases","some","queryAll","partitionKey","options","beginsWith","params","find","GSI1_PK","GSI1_SK","TYPE","key","filter","Boolean","exports"],"sources":["AliasesStorageOperations.ts"],"sourcesContent":["import type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb\";\nimport type { Entity, Table } from \"@webiny/db-dynamodb/toolbox\";\nimport type {\n File,\n FileAlias,\n FileManagerAliasesStorageOperations\n} from \"@webiny/api-file-manager/types\";\nimport {\n createEntityWriteBatch,\n createStandardEntity,\n createTable,\n DbItem,\n queryAll\n} from \"@webiny/db-dynamodb\";\n\ninterface AliasesStorageOperationsConfig {\n documentClient: DynamoDBDocument;\n}\n\ninterface CreatePartitionKeyParams {\n locale: string;\n tenant: string;\n id: string;\n}\n\nexport class AliasesStorageOperations implements FileManagerAliasesStorageOperations {\n private readonly aliasEntity: Entity<any>;\n private readonly table: Table<string, string, string>;\n\n constructor({ documentClient }: AliasesStorageOperationsConfig) {\n this.table = createTable({ documentClient });\n\n this.aliasEntity = createStandardEntity({\n table: this.table,\n name: \"FM.FileAlias\"\n });\n }\n\n async deleteAliases(file: File): Promise<void> {\n const aliasItems = await this.getExistingAliases(file);\n\n const batchWrite = createEntityWriteBatch({\n entity: this.aliasEntity,\n delete: aliasItems.map(item => {\n return {\n PK: this.createPartitionKey({\n id: item.fileId,\n tenant: item.tenant,\n locale: item.locale\n }),\n SK: `ALIAS#${item.alias}`\n };\n })\n });\n\n await batchWrite.execute();\n }\n\n async storeAliases(file: File): Promise<void> {\n const existingAliases = await this.getExistingAliases(file);\n const newAliases = this.createNewAliasesRecords(file, existingAliases);\n\n const batchWrite = createEntityWriteBatch({\n entity: this.aliasEntity\n });\n for (const alias of newAliases) {\n batchWrite.put(alias);\n }\n\n // Delete aliases that are in the DB but are NOT in the file.\n for (const data of existingAliases) {\n if (!file.aliases.some(alias => data.alias === alias)) {\n batchWrite.delete({\n PK: this.createPartitionKey(file),\n SK: `ALIAS#${data.alias}`\n });\n }\n }\n\n await batchWrite.execute();\n }\n\n private async getExistingAliases(file: File): Promise<FileAlias[]> {\n const aliases = await queryAll<{ data: FileAlias }>({\n entity: this.aliasEntity,\n partitionKey: this.createPartitionKey(file),\n options: {\n beginsWith: \"ALIAS#\"\n }\n });\n\n return aliases.map(alias => alias.data);\n }\n\n private createPartitionKey(params: CreatePartitionKeyParams): string {\n const { tenant, locale, id } = params;\n return `T#${tenant}#L#${locale}#FM#F${id}`;\n }\n\n private createNewAliasesRecords(\n file: File,\n existingAliases: FileAlias[] = []\n ): DbItem<FileAlias>[] {\n return (file.aliases || [])\n .map(alias => {\n // If alias is already in the DB, skip it.\n if (existingAliases.find(item => item.alias === alias)) {\n return null;\n }\n\n // Add a new alias.\n return {\n PK: this.createPartitionKey(file),\n SK: `ALIAS#${alias}`,\n GSI1_PK: `T#${file.tenant}#FM#FILE_ALIASES`,\n GSI1_SK: alias,\n TYPE: \"fm.fileAlias\",\n data: {\n alias,\n tenant: file.tenant,\n locale: file.locale,\n fileId: file.id,\n key: file.key\n }\n };\n })\n .filter(Boolean) as DbItem<FileAlias>[];\n }\n}\n"],"mappings":";;;;;;AAOA,IAAAA,WAAA,GAAAC,OAAA;AAkBO,MAAMC,wBAAwB,CAAgD;EAIjFC,WAAWA,CAAC;IAAEC;EAA+C,CAAC,EAAE;IAC5D,IAAI,CAACC,KAAK,GAAG,IAAAC,uBAAW,EAAC;MAAEF;IAAe,CAAC,CAAC;IAE5C,IAAI,CAACG,WAAW,GAAG,IAAAC,gCAAoB,EAAC;MACpCH,KAAK,EAAE,IAAI,CAACA,KAAK;MACjBI,IAAI,EAAE;IACV,CAAC,CAAC;EACN;EAEA,MAAMC,aAAaA,CAACC,IAAU,EAAiB;IAC3C,MAAMC,UAAU,GAAG,MAAM,IAAI,CAACC,kBAAkB,CAACF,IAAI,CAAC;IAEtD,MAAMG,UAAU,GAAG,IAAAC,kCAAsB,EAAC;MACtCC,MAAM,EAAE,IAAI,CAACT,WAAW;MACxBU,MAAM,EAAEL,UAAU,CAACM,GAAG,CAACC,IAAI,IAAI;QAC3B,OAAO;UACHC,EAAE,EAAE,IAAI,CAACC,kBAAkB,CAAC;YACxBC,EAAE,EAAEH,IAAI,CAACI,MAAM;YACfC,MAAM,EAAEL,IAAI,CAACK,MAAM;YACnBC,MAAM,EAAEN,IAAI,CAACM;UACjB,CAAC,CAAC;UACFC,EAAE,EAAG,SAAQP,IAAI,CAACQ,KAAM;QAC5B,CA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;IACjE,MAAM;MAAEjB,MAAM;MAAEC,MAAM;MAAEH;IAAG,CAAC,GAAGmB,MAAM;IACrC,OAAQ,KAAIjB,MAAO,MAAKC,MAAO,QAAOH,EAAG,EAAC;EAC9C;EAEQU,uBAAuBA,CAC3BrB,IAAU,EACVmB,eAA4B,GAAG,EAAE,EACd;IACnB,OAAO,CAACnB,IAAI,CAACwB,OAAO,IAAI,EAAE,EACrBjB,GAAG,CAACS,KAAK,IAAI;MACV;MACA,IAAIG,eAAe,CAACY,IAAI,CAACvB,IAAI,IAAIA,IAAI,CAACQ,KAAK,KAAKA,KAAK,CAAC,EAAE;QACpD,OAAO,IAAI;MACf;;MAEA;MACA,OAAO;QACHP,EAAE,EAAE,IAAI,CAACC,kBAAkB,CAACV,IAAI,CAAC;QACjCe,EAAE,EAAG,SAAQC,KAAM,EAAC;QACpBgB,OAAO,EAAG,KAAIhC,IAAI,CAACa,MAAO,kBAAiB;QAC3CoB,OAAO,EAAEjB,KAAK;QACdkB,IAAI,EAAE,cAAc;QACpBX,IAAI,EAAE;UACFP,KAAK;UACLH,MAAM,EAAEb,IAAI,CAACa,MAAM;UACnBC,MAAM,EAAEd,IAAI,CAACc,MAAM;UACnBF,MAAM,EAAEZ,IAAI,CAACW,EAAE;UACfwB,GAAG,EAAEnC,IAAI,CAACmC;QACd;MACJ,CAAC;IACL,CAAC,CAAC,CACDC,MAAM,CAACC,OAAO,CAAC;EACxB;AACJ;AAACC,OAAA,CAAA/C,wBAAA,GAAAA,wBAAA","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-file-manager-ddb",
|
|
3
|
-
"version": "5.41.4-beta.
|
|
3
|
+
"version": "5.41.4-beta.5",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"@webiny/api-file-manager",
|
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@babel/runtime": "7.24.1",
|
|
24
|
-
"@webiny/api-file-manager": "5.41.4-beta.
|
|
25
|
-
"@webiny/aws-sdk": "5.41.4-beta.
|
|
26
|
-
"@webiny/db-dynamodb": "5.41.4-beta.
|
|
27
|
-
"@webiny/error": "5.41.4-beta.
|
|
28
|
-
"@webiny/plugins": "5.41.4-beta.
|
|
29
|
-
"@webiny/project-utils": "5.41.4-beta.
|
|
24
|
+
"@webiny/api-file-manager": "5.41.4-beta.5",
|
|
25
|
+
"@webiny/aws-sdk": "5.41.4-beta.5",
|
|
26
|
+
"@webiny/db-dynamodb": "5.41.4-beta.5",
|
|
27
|
+
"@webiny/error": "5.41.4-beta.5",
|
|
28
|
+
"@webiny/plugins": "5.41.4-beta.5",
|
|
29
|
+
"@webiny/project-utils": "5.41.4-beta.5"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@babel/cli": "7.24.1",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"@babel/plugin-transform-runtime": "7.24.3",
|
|
36
36
|
"@babel/preset-env": "7.24.3",
|
|
37
37
|
"@babel/preset-typescript": "7.24.1",
|
|
38
|
-
"@webiny/cli": "5.41.4-beta.
|
|
38
|
+
"@webiny/cli": "5.41.4-beta.5",
|
|
39
39
|
"jest": "29.7.0",
|
|
40
40
|
"jest-dynalite": "3.6.1",
|
|
41
41
|
"jsonpack": "1.1.5",
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
]
|
|
62
62
|
}
|
|
63
63
|
},
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "e3f273ea63f0c426c2ddde0794d303bc8ffaa6c4"
|
|
65
65
|
}
|