@ms-cloudpack/remote-cache 0.1.5 → 0.1.7
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,10 +1,11 @@
|
|
|
1
1
|
import { type TaskReporter } from '@ms-cloudpack/task-reporter';
|
|
2
|
-
import type { RemoteCacheClient, RemoteCacheClientOperationOptions } from '../types/RemoteCacheClient.js';
|
|
2
|
+
import type { RemoteCacheClient, RemoteCacheClientOperationOptions, RemoteCacheClientOperationResult } from '../types/RemoteCacheClient.js';
|
|
3
3
|
export declare class ReporterDecorator implements RemoteCacheClient {
|
|
4
4
|
private readonly client;
|
|
5
5
|
private readonly reporter;
|
|
6
6
|
constructor(client: RemoteCacheClient, reporter: TaskReporter);
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
private buildFailureMessage;
|
|
8
|
+
uploadFolder(options: RemoteCacheClientOperationOptions): Promise<RemoteCacheClientOperationResult>;
|
|
9
|
+
downloadFolder(options: RemoteCacheClientOperationOptions): Promise<RemoteCacheClientOperationResult>;
|
|
9
10
|
}
|
|
10
11
|
//# sourceMappingURL=ReporterDecorator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReporterDecorator.d.ts","sourceRoot":"","sources":["../../src/decorators/ReporterDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC9E,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"ReporterDecorator.d.ts","sourceRoot":"","sources":["../../src/decorators/ReporterDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC9E,OAAO,KAAK,EACV,iBAAiB,EACjB,iCAAiC,EACjC,gCAAgC,EACjC,MAAM,+BAA+B,CAAC;AAEvC,qBAAa,iBAAkB,YAAW,iBAAiB;IAEvD,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBADR,MAAM,EAAE,iBAAiB,EACzB,QAAQ,EAAE,YAAY;IAGzC,OAAO,CAAC,mBAAmB;IAWrB,YAAY,CAAC,OAAO,EAAE,iCAAiC;IA0CvD,cAAc,CAAC,OAAO,EAAE,iCAAiC;CAyChE"}
|
|
@@ -4,10 +4,29 @@ export class ReporterDecorator {
|
|
|
4
4
|
this.client = client;
|
|
5
5
|
this.reporter = reporter;
|
|
6
6
|
}
|
|
7
|
+
buildFailureMessage({ folderName, friendlyName, path }, error) {
|
|
8
|
+
const list = bulletedList([
|
|
9
|
+
`FolderName: ${folderName}`,
|
|
10
|
+
`Path: ${path}`,
|
|
11
|
+
`Name: ${friendlyName}`,
|
|
12
|
+
`Error: ${error instanceof Error ? error.message : '<Unknown>'}`,
|
|
13
|
+
]);
|
|
14
|
+
return `\n${list}`;
|
|
15
|
+
}
|
|
7
16
|
async uploadFolder(options) {
|
|
8
17
|
const { folderName, path, friendlyName } = options;
|
|
9
18
|
const task = this.reporter.addTask(`Uploading to remote cache: ${friendlyName}`);
|
|
10
|
-
|
|
19
|
+
let uploadResult;
|
|
20
|
+
try {
|
|
21
|
+
uploadResult = await this.client.uploadFolder(options);
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
task.complete({
|
|
25
|
+
status: 'fail',
|
|
26
|
+
message: this.buildFailureMessage(options, e),
|
|
27
|
+
});
|
|
28
|
+
throw e;
|
|
29
|
+
}
|
|
11
30
|
switch (uploadResult) {
|
|
12
31
|
case 'success':
|
|
13
32
|
task.complete({
|
|
@@ -35,7 +54,17 @@ export class ReporterDecorator {
|
|
|
35
54
|
async downloadFolder(options) {
|
|
36
55
|
const { folderName, path, friendlyName } = options;
|
|
37
56
|
const task = this.reporter.addTask(`Downloading from remote cache: ${friendlyName}`);
|
|
38
|
-
|
|
57
|
+
let downloadResult;
|
|
58
|
+
try {
|
|
59
|
+
downloadResult = await this.client.downloadFolder(options);
|
|
60
|
+
}
|
|
61
|
+
catch (e) {
|
|
62
|
+
task.complete({
|
|
63
|
+
status: 'fail',
|
|
64
|
+
message: this.buildFailureMessage(options, e),
|
|
65
|
+
});
|
|
66
|
+
throw e;
|
|
67
|
+
}
|
|
39
68
|
switch (downloadResult) {
|
|
40
69
|
case 'success':
|
|
41
70
|
task.complete({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReporterDecorator.js","sourceRoot":"","sources":["../../src/decorators/ReporterDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAqB,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"ReporterDecorator.js","sourceRoot":"","sources":["../../src/decorators/ReporterDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAqB,MAAM,6BAA6B,CAAC;AAO9E,MAAM,OAAO,iBAAiB;IAC5B,YACmB,MAAyB,EACzB,QAAsB;QADtB,WAAM,GAAN,MAAM,CAAmB;QACzB,aAAQ,GAAR,QAAQ,CAAc;IACtC,CAAC;IAEI,mBAAmB,CAAC,EAAE,UAAU,EAAE,YAAY,EAAE,IAAI,EAAqC,EAAE,KAAc;QAC/G,MAAM,IAAI,GAAG,YAAY,CAAC;YACxB,eAAe,UAAU,EAAE;YAC3B,SAAS,IAAI,EAAE;YACf,SAAS,YAAY,EAAE;YACvB,UAAU,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,EAAE;SACjE,CAAC,CAAC;QAEH,OAAO,KAAK,IAAI,EAAE,CAAC;IACrB,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,OAA0C;QAC3D,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;QACnD,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,8BAA8B,YAAY,EAAE,CAAC,CAAC;QAEjF,IAAI,YAA8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CAAC;SAC5D;QAAC,OAAO,CAAC,EAAE;YACV,IAAI,CAAC,QAAQ,CAAC;gBACZ,MAAM,EAAE,MAAM;gBACd,OAAO,EAAE,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,CAAC,CAAC;aAC9C,CAAC,CAAC;YACH,MAAM,CAAC,CAAC;SACT;QAED,QAAQ,cAAc,EAAE;YACtB,KAAK,SAAS;gBACZ,IAAI,CAAC,QAAQ,CAAC;oBACZ,MAAM,EAAE,UAAU;oBAClB,OAAO,EAAE,YAAY,CAAC,CAAC,eAAe,UAAU,EAAE,EAAE,SAAS,IAAI,EAAE,EAAE,SAAS,YAAY,EAAE,CAAC,CAAC;iBAC/F,CAAC,CAAC;gBACH,MAAM;YACR,KAAK,WAAW;gBACd,IAAI,CAAC,QAAQ,CAAC;oBACZ,MAAM,EAAE,MAAM;oBACd,OAAO,EAAE,gCAAgC;iBAC1C,CAAC,CAAC;gBACH,MAAM;YACR,KAAK,eAAe;gBAClB,IAAI,CAAC,QAAQ,CAAC;oBACZ,MAAM,EAAE,MAAM;oBACd,OAAO,EAAE,8CAA8C;iBACxD,CAAC,CAAC;gBACH,MAAM;YACR;gBACE,MAAM,IAAI,KAAK,CAAC,4BAA4B,cAAc,EAAE,CAAC,CAAC;SACjE;QAED,OAAO,cAAc,CAAC;IACxB,CAAC;CACF","sourcesContent":["import { bulletedList, type TaskReporter } from '@ms-cloudpack/task-reporter';\nimport type {\n RemoteCacheClient,\n RemoteCacheClientOperationOptions,\n RemoteCacheClientOperationResult,\n} from '../types/RemoteCacheClient.js';\n\nexport class ReporterDecorator implements RemoteCacheClient {\n constructor(\n private readonly client: RemoteCacheClient,\n private readonly reporter: TaskReporter,\n ) {}\n\n private buildFailureMessage({ folderName, friendlyName, path }: RemoteCacheClientOperationOptions, error: unknown) {\n const list = bulletedList([\n `FolderName: ${folderName}`,\n `Path: ${path}`,\n `Name: ${friendlyName}`,\n `Error: ${error instanceof Error ? error.message : '<Unknown>'}`,\n ]);\n\n return `\\n${list}`;\n }\n\n async uploadFolder(options: RemoteCacheClientOperationOptions) {\n const { folderName, path, friendlyName } = options;\n const task = this.reporter.addTask(`Uploading to remote cache: ${friendlyName}`);\n\n let uploadResult: RemoteCacheClientOperationResult;\n\n try {\n uploadResult = await this.client.uploadFolder(options);\n } catch (e) {\n task.complete({\n status: 'fail',\n message: this.buildFailureMessage(options, e),\n });\n throw e;\n }\n\n switch (uploadResult) {\n case 'success':\n task.complete({\n status: 'complete',\n details: bulletedList([`FolderName: ${folderName}`, `Path: ${path}`, `Name: ${friendlyName}`]),\n });\n break;\n case 'not-found':\n task.complete({\n status: 'skip',\n message: `Not found in the local cache.`,\n });\n break;\n case 'already-exist':\n task.complete({\n status: 'skip',\n message: `Package is already exist in the remote cache.`,\n });\n break;\n default:\n throw new Error(`Unknown upload result: ${uploadResult}`);\n }\n\n return uploadResult;\n }\n\n async downloadFolder(options: RemoteCacheClientOperationOptions) {\n const { folderName, path, friendlyName } = options;\n const task = this.reporter.addTask(`Downloading from remote cache: ${friendlyName}`);\n\n let downloadResult: RemoteCacheClientOperationResult;\n\n try {\n downloadResult = await this.client.downloadFolder(options);\n } catch (e) {\n task.complete({\n status: 'fail',\n message: this.buildFailureMessage(options, e),\n });\n throw e;\n }\n\n switch (downloadResult) {\n case 'success':\n task.complete({\n status: 'complete',\n details: bulletedList([`FolderName: ${folderName}`, `Path: ${path}`, `Name: ${friendlyName}`]),\n });\n break;\n case 'not-found':\n task.complete({\n status: 'skip',\n message: `Not found in the remote cache.`,\n });\n break;\n case 'already-exist':\n task.complete({\n status: 'skip',\n message: `Package is already exist in the local cache.`,\n });\n break;\n default:\n throw new Error(`Unknown download result: ${downloadResult}`);\n }\n\n return downloadResult;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/remote-cache",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "Manages syncing the local Cloudpack cached assets to/from a remote storage service.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"lib/**/!(*.test.*)"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@ms-cloudpack/task-reporter": "^0.
|
|
32
|
+
"@ms-cloudpack/task-reporter": "^0.8.0",
|
|
33
33
|
"@azure/identity": "^3.2.3",
|
|
34
34
|
"@azure/storage-blob": "^12.15.0",
|
|
35
35
|
"@napi-rs/keyring": "^1.1.3",
|