@ms-cloudpack/remote-cache 0.5.1-beta.2 → 0.5.2
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/lib/AzureRemoteCacheClient.d.ts.map +1 -0
- package/lib/AzureRemoteCacheClient.js +51 -0
- package/lib/AzureRemoteCacheClient.js.map +1 -0
- package/lib/Task.d.ts.map +1 -0
- package/lib/Task.js +2 -0
- package/lib/Task.js.map +1 -0
- package/lib/authentication/getAuthenticationRecord.d.ts.map +1 -0
- package/lib/authentication/getAuthenticationRecord.js +17 -0
- package/lib/authentication/getAuthenticationRecord.js.map +1 -0
- package/lib/authentication/getAuthenticationRecordPath.d.ts.map +1 -0
- package/lib/authentication/getAuthenticationRecordPath.js +10 -0
- package/lib/authentication/getAuthenticationRecordPath.js.map +1 -0
- package/lib/authentication/getCredential.d.ts.map +1 -0
- package/lib/authentication/getCredential.js +61 -0
- package/lib/authentication/getCredential.js.map +1 -0
- package/lib/authentication/saveAuthenticationRecord.d.ts.map +1 -0
- package/lib/authentication/saveAuthenticationRecord.js +17 -0
- package/lib/authentication/saveAuthenticationRecord.js.map +1 -0
- package/lib/cache-persistance/cachePersistencePlugin.d.ts.map +1 -0
- package/lib/cache-persistance/cachePersistencePlugin.js +35 -0
- package/lib/cache-persistance/cachePersistencePlugin.js.map +1 -0
- package/lib/cache-persistance/platforms.d.ts.map +1 -0
- package/lib/cache-persistance/platforms.js +109 -0
- package/lib/cache-persistance/platforms.js.map +1 -0
- package/lib/cache-persistance/provider.d.ts.map +1 -0
- package/lib/cache-persistance/provider.js +26 -0
- package/lib/cache-persistance/provider.js.map +1 -0
- package/lib/createBlobStorageUrl.d.ts.map +1 -0
- package/lib/createBlobStorageUrl.js +4 -0
- package/lib/createBlobStorageUrl.js.map +1 -0
- package/lib/createRemoteCacheClient.d.ts.map +1 -0
- package/lib/createRemoteCacheClient.js +27 -0
- package/lib/createRemoteCacheClient.js.map +1 -0
- package/lib/decorators/InMemoryDecorator.d.ts.map +1 -0
- package/lib/decorators/InMemoryDecorator.js +29 -0
- package/lib/decorators/InMemoryDecorator.js.map +1 -0
- package/lib/decorators/ReporterDecorator.d.ts +1 -1
- package/lib/decorators/ReporterDecorator.d.ts.map +1 -0
- package/lib/decorators/ReporterDecorator.js +126 -0
- package/lib/decorators/ReporterDecorator.js.map +1 -0
- package/lib/decorators/RetryDecorator.d.ts.map +1 -0
- package/lib/decorators/RetryDecorator.js +27 -0
- package/lib/decorators/RetryDecorator.js.map +1 -0
- package/lib/getListOfBlobs.d.ts.map +1 -0
- package/lib/getListOfBlobs.js +15 -0
- package/lib/getListOfBlobs.js.map +1 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -0
- package/lib/retry/blockListIsInvalidRetryPolicy.d.ts.map +1 -0
- package/lib/retry/blockListIsInvalidRetryPolicy.js +8 -0
- package/lib/retry/blockListIsInvalidRetryPolicy.js.map +1 -0
- package/lib/tsdoc-metadata.json +11 -0
- package/lib/types/LoginMethod.d.ts.map +1 -0
- package/lib/types/LoginMethod.js +2 -0
- package/lib/types/LoginMethod.js.map +1 -0
- package/lib/types/RemoteCacheClient.d.ts.map +1 -0
- package/lib/types/RemoteCacheClient.js +2 -0
- package/lib/types/RemoteCacheClient.js.map +1 -0
- package/lib/types/RemoteCacheClientOptions.d.ts.map +1 -0
- package/lib/types/RemoteCacheClientOptions.js +2 -0
- package/lib/types/RemoteCacheClientOptions.js.map +1 -0
- package/lib/types/RetryPolicy.d.ts.map +1 -0
- package/lib/types/RetryPolicy.js +2 -0
- package/lib/types/RetryPolicy.js.map +1 -0
- package/package.json +13 -14
- package/dist/AzureRemoteCacheClient-AE2VSZ7M.js +0 -52517
- package/dist/ReporterDecorator-IPB43LAC.js +0 -127
- package/dist/chunk-7DWZ2KJB.js +0 -49702
- package/dist/chunk-IG2LEA6S.js +0 -185
- package/dist/chunk-N2VHZU53.js +0 -63
- package/dist/chunk-X5NZ4TUB.js +0 -1075
- package/dist/chunk-YE3TMZ3A.js +0 -13
- package/dist/getCredential-63JEO57N.js +0 -24180
- package/dist/getListOfBlobs-BZCK6WJA.js +0 -27
- package/dist/index.js +0 -103
- package/lib/decorators/InMemoryDecorator.test.d.ts +0 -2
- package/lib/decorators/RetryDecorator.test.d.ts +0 -2
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { bulletedList } from '@ms-cloudpack/task-reporter';
|
|
2
|
+
import { RestError } from '@azure/storage-blob';
|
|
3
|
+
let isAuthErrorReported = false;
|
|
4
|
+
/**
|
|
5
|
+
* Reports an error to the telemetry client. If the error is an auth error, it will be reported only once.
|
|
6
|
+
* @param telemetryClient - The telemetry client to report the error to.
|
|
7
|
+
* @param error - The error to report.
|
|
8
|
+
*/
|
|
9
|
+
function reportError(telemetryClient, error) {
|
|
10
|
+
const isAuthError = error instanceof RestError && error.statusCode === 403;
|
|
11
|
+
if (isAuthError && isAuthErrorReported) {
|
|
12
|
+
return; // No need to proceed if auth error is already reported
|
|
13
|
+
}
|
|
14
|
+
telemetryClient.rootSpan.recordException(error);
|
|
15
|
+
// Set isAuthErrorReported only if it's an auth error
|
|
16
|
+
isAuthErrorReported = isAuthError;
|
|
17
|
+
}
|
|
18
|
+
export class ReporterDecorator {
|
|
19
|
+
constructor(client, context) {
|
|
20
|
+
this.client = client;
|
|
21
|
+
this.context = context;
|
|
22
|
+
}
|
|
23
|
+
buildFailureResult({ id, friendlyName, path }, error) {
|
|
24
|
+
const list = bulletedList([
|
|
25
|
+
`Id: ${id}`,
|
|
26
|
+
`Path: ${path}`,
|
|
27
|
+
`Name: ${friendlyName}`,
|
|
28
|
+
`Error: ${error instanceof Error ? error.message : String(error)}`,
|
|
29
|
+
]);
|
|
30
|
+
const result = {
|
|
31
|
+
status: 'fail',
|
|
32
|
+
message: `\n${list}`,
|
|
33
|
+
};
|
|
34
|
+
if (error instanceof Error && error.stack) {
|
|
35
|
+
result.details = error.stack.includes(error.message) ? error.stack.split(error.message)[1] : error.stack;
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
async uploadFolder(options) {
|
|
40
|
+
const { id, path, friendlyName } = options;
|
|
41
|
+
const task = this.context.reporter.addTask(`Uploading to remote cache: ${friendlyName}`);
|
|
42
|
+
let uploadResult;
|
|
43
|
+
try {
|
|
44
|
+
uploadResult = await this.client.uploadFolder(options);
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
task.complete(this.buildFailureResult(options, e));
|
|
48
|
+
if (e instanceof Error) {
|
|
49
|
+
reportError(this.context.telemetryClient, e);
|
|
50
|
+
// Clear the stack since it was already included in the task details
|
|
51
|
+
e.stack = undefined;
|
|
52
|
+
}
|
|
53
|
+
throw e;
|
|
54
|
+
}
|
|
55
|
+
const details = bulletedList([`Id: ${id}`, `Path: ${path}`, `Name: ${friendlyName}`]);
|
|
56
|
+
switch (uploadResult) {
|
|
57
|
+
case 'success':
|
|
58
|
+
task.complete({
|
|
59
|
+
status: 'complete',
|
|
60
|
+
details,
|
|
61
|
+
});
|
|
62
|
+
break;
|
|
63
|
+
case 'not-found':
|
|
64
|
+
task.complete({
|
|
65
|
+
status: 'skip',
|
|
66
|
+
message: `Not found in the local cache.`,
|
|
67
|
+
details,
|
|
68
|
+
});
|
|
69
|
+
break;
|
|
70
|
+
case 'already-exist':
|
|
71
|
+
task.complete({
|
|
72
|
+
status: 'skip',
|
|
73
|
+
message: `Package is already exist in the remote cache.`,
|
|
74
|
+
details,
|
|
75
|
+
});
|
|
76
|
+
break;
|
|
77
|
+
default:
|
|
78
|
+
throw new Error(`Unknown upload result: ${uploadResult}`);
|
|
79
|
+
}
|
|
80
|
+
return uploadResult;
|
|
81
|
+
}
|
|
82
|
+
async downloadFolder(options) {
|
|
83
|
+
const { id, path, friendlyName } = options;
|
|
84
|
+
const task = this.context.reporter.addTask(`Downloading from remote cache: ${friendlyName}`);
|
|
85
|
+
let downloadResult;
|
|
86
|
+
try {
|
|
87
|
+
downloadResult = await this.client.downloadFolder(options);
|
|
88
|
+
}
|
|
89
|
+
catch (e) {
|
|
90
|
+
task.complete(this.buildFailureResult(options, e));
|
|
91
|
+
if (e instanceof Error) {
|
|
92
|
+
reportError(this.context.telemetryClient, e);
|
|
93
|
+
// Clear the stack since it was already included in the task details
|
|
94
|
+
e.stack = undefined;
|
|
95
|
+
}
|
|
96
|
+
throw e;
|
|
97
|
+
}
|
|
98
|
+
const details = bulletedList([`Id: ${id}`, `Path: ${path}`, `Name: ${friendlyName}`]);
|
|
99
|
+
switch (downloadResult) {
|
|
100
|
+
case 'success':
|
|
101
|
+
task.complete({
|
|
102
|
+
status: 'complete',
|
|
103
|
+
details,
|
|
104
|
+
});
|
|
105
|
+
break;
|
|
106
|
+
case 'not-found':
|
|
107
|
+
task.complete({
|
|
108
|
+
status: 'skip',
|
|
109
|
+
message: `Not found in the remote cache.`,
|
|
110
|
+
details,
|
|
111
|
+
});
|
|
112
|
+
break;
|
|
113
|
+
case 'already-exist':
|
|
114
|
+
task.complete({
|
|
115
|
+
status: 'skip',
|
|
116
|
+
message: `Package is already exist in the local cache.`,
|
|
117
|
+
details,
|
|
118
|
+
});
|
|
119
|
+
break;
|
|
120
|
+
default:
|
|
121
|
+
throw new Error(`Unknown download result: ${downloadResult}`);
|
|
122
|
+
}
|
|
123
|
+
return downloadResult;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=ReporterDecorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReporterDecorator.js","sourceRoot":"","sources":["../../src/decorators/ReporterDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAkD,MAAM,6BAA6B,CAAC;AAQ3G,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,IAAI,mBAAmB,GAAY,KAAK,CAAC;AAEzC;;;;GAIG;AACH,SAAS,WAAW,CAAC,eAAgC,EAAE,KAAY;IACj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AAC,QAAQ,CAAC;oBACZ,MAAM,EAAE,MAAM;oBACd,OAAO,EAAE,8CAA8C;oBACvD,OAAO;iBACR,CAAC,CAAC;gBACH,MAAM;YACR;gBACE,MAAM,IAAI,KAAK,CAAC,4BAA4B,cAAc,EAAE,CAAC,CAAC;QAClE,CAAC;QAED,OAAO,cAAc,CAAC;IACxB,CAAC;CACF","sourcesContent":["import { bulletedList, type TaskReporter, type TaskReporterTaskResult } from '@ms-cloudpack/task-reporter';\nimport type {\n RemoteCacheClient,\n RemoteCacheClientUploadOperationOptions,\n RemoteCacheClientOperationOptions,\n RemoteCacheClientOperationResult,\n} from '../types/RemoteCacheClient.js';\nimport type { TelemetryClient } from '@ms-cloudpack/telemetry';\nimport { RestError } from '@azure/storage-blob';\n\nlet isAuthErrorReported: boolean = false;\n\n/**\n * Reports an error to the telemetry client. If the error is an auth error, it will be reported only once.\n * @param telemetryClient - The telemetry client to report the error to.\n * @param error - The error to report.\n */\nfunction reportError(telemetryClient: TelemetryClient, error: Error) {\n const isAuthError = error instanceof RestError && error.statusCode === 403;\n\n if (isAuthError && isAuthErrorReported) {\n return; // No need to proceed if auth error is already reported\n }\n\n telemetryClient.rootSpan.recordException(error);\n\n // Set isAuthErrorReported only if it's an auth error\n isAuthErrorReported = isAuthError;\n}\n\nexport class ReporterDecorator implements RemoteCacheClient {\n constructor(\n private readonly client: RemoteCacheClient,\n private readonly context: {\n reporter: TaskReporter;\n telemetryClient: TelemetryClient;\n },\n ) {}\n\n private buildFailureResult(\n { id, friendlyName, path }: RemoteCacheClientOperationOptions,\n error: unknown,\n ): TaskReporterTaskResult {\n const list = bulletedList([\n `Id: ${id}`,\n `Path: ${path}`,\n `Name: ${friendlyName}`,\n `Error: ${error instanceof Error ? error.message : String(error)}`,\n ]);\n\n const result: TaskReporterTaskResult = {\n status: 'fail',\n message: `\\n${list}`,\n };\n\n if (error instanceof Error && error.stack) {\n result.details = error.stack.includes(error.message) ? error.stack.split(error.message)[1] : error.stack;\n }\n\n return result;\n }\n\n async uploadFolder(options: RemoteCacheClientUploadOperationOptions) {\n const { id, path, friendlyName } = options;\n const task = this.context.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(this.buildFailureResult(options, e));\n if (e instanceof Error) {\n reportError(this.context.telemetryClient, e);\n // Clear the stack since it was already included in the task details\n e.stack = undefined;\n }\n throw e;\n }\n\n const details = bulletedList([`Id: ${id}`, `Path: ${path}`, `Name: ${friendlyName}`]);\n\n switch (uploadResult) {\n case 'success':\n task.complete({\n status: 'complete',\n details,\n });\n break;\n case 'not-found':\n task.complete({\n status: 'skip',\n message: `Not found in the local cache.`,\n details,\n });\n break;\n case 'already-exist':\n task.complete({\n status: 'skip',\n message: `Package is already exist in the remote cache.`,\n details,\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 { id, path, friendlyName } = options;\n const task = this.context.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(this.buildFailureResult(options, e));\n if (e instanceof Error) {\n reportError(this.context.telemetryClient, e);\n // Clear the stack since it was already included in the task details\n e.stack = undefined;\n }\n throw e;\n }\n\n const details = bulletedList([`Id: ${id}`, `Path: ${path}`, `Name: ${friendlyName}`]);\n\n switch (downloadResult) {\n case 'success':\n task.complete({\n status: 'complete',\n details,\n });\n break;\n case 'not-found':\n task.complete({\n status: 'skip',\n message: `Not found in the remote cache.`,\n details,\n });\n break;\n case 'already-exist':\n task.complete({\n status: 'skip',\n message: `Package is already exist in the local cache.`,\n details,\n });\n break;\n default:\n throw new Error(`Unknown download result: ${downloadResult}`);\n }\n\n return downloadResult;\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RetryDecorator.d.ts","sourceRoot":"","sources":["../../src/decorators/RetryDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,uCAAuC,EACvC,iCAAiC,EACjC,gCAAgC,EACjC,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD;;GAEG;AACH,qBAAa,cAAe,YAAW,iBAAiB;IACtD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAoB;IAChD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAe;gBAEhC,OAAO,EAAE;QAAE,WAAW,EAAE,iBAAiB,CAAC;QAAC,YAAY,EAAE,YAAY,CAAA;KAAE;IAKnF,OAAO,CAAC,iBAAiB;IAYnB,YAAY,CAAC,OAAO,EAAE,uCAAuC,GAAG,OAAO,CAAC,gCAAgC,CAAC;IAOzG,cAAc,CAAC,OAAO,EAAE,iCAAiC,GAAG,OAAO,CAAC,gCAAgC,CAAC;CAM5G"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A decorator that retries the upload/download operation if it fails.
|
|
3
|
+
*/
|
|
4
|
+
export class RetryDecorator {
|
|
5
|
+
constructor(options) {
|
|
6
|
+
this.cacheClient = options.cacheClient;
|
|
7
|
+
this.retryManager = options.retryManager;
|
|
8
|
+
}
|
|
9
|
+
printRetryContext(operationName, options, retryContext) {
|
|
10
|
+
if (retryContext) {
|
|
11
|
+
console.warn(`Retrying ${operationName} ${options.friendlyName} ... [${retryContext.retryAttempt}/${retryContext.maxRetries}]`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
async uploadFolder(options) {
|
|
15
|
+
return this.retryManager.retry((retryContext) => {
|
|
16
|
+
this.printRetryContext('upload', options, retryContext);
|
|
17
|
+
return this.cacheClient.uploadFolder(options);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
async downloadFolder(options) {
|
|
21
|
+
return this.retryManager.retry((retryContext) => {
|
|
22
|
+
this.printRetryContext('download', options, retryContext);
|
|
23
|
+
return this.cacheClient.downloadFolder(options);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=RetryDecorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RetryDecorator.js","sourceRoot":"","sources":["../../src/decorators/RetryDecorator.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,MAAM,OAAO,cAAc;IAIzB,YAAY,OAAuE;QACjF,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;QACvC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAC3C,CAAC;IAEO,iBAAiB,CACvB,aAAqB,EACrB,OAA0C,EAC1C,YAA2D;QAE3D,IAAI,YAAY,EAAE,CAAC;YACjB,OAAO,CAAC,IAAI,CACV,YAAY,aAAa,IAAI,OAAO,CAAC,YAAY,SAAS,YAAY,CAAC,YAAY,IAAI,YAAY,CAAC,UAAU,GAAG,CAClH,CAAC;QACJ,CAAC;IACH,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,OAAgD;QACjE,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,YAAY,EAAE,EAAE;YAC9C,IAAI,CAAC,iBAAiB,CAAC,QAAQ,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;YACxD,OAAO,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QAChD,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,OAA0C;QAC7D,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,YAAY,EAAE,EAAE;YAC9C,IAAI,CAAC,iBAAiB,CAAC,UAAU,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;YAC1D,OAAO,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QAClD,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import type {\n RemoteCacheClient,\n RemoteCacheClientUploadOperationOptions,\n RemoteCacheClientOperationOptions,\n RemoteCacheClientOperationResult,\n} from '../types/RemoteCacheClient.js';\nimport type { RetryManager } from '@ms-cloudpack/retry';\n\n/**\n * A decorator that retries the upload/download operation if it fails.\n */\nexport class RetryDecorator implements RemoteCacheClient {\n private readonly cacheClient: RemoteCacheClient;\n private readonly retryManager: RetryManager;\n\n constructor(options: { cacheClient: RemoteCacheClient; retryManager: RetryManager }) {\n this.cacheClient = options.cacheClient;\n this.retryManager = options.retryManager;\n }\n\n private printRetryContext(\n operationName: string,\n options: RemoteCacheClientOperationOptions,\n retryContext?: { retryAttempt: number; maxRetries: number },\n ) {\n if (retryContext) {\n console.warn(\n `Retrying ${operationName} ${options.friendlyName} ... [${retryContext.retryAttempt}/${retryContext.maxRetries}]`,\n );\n }\n }\n\n async uploadFolder(options: RemoteCacheClientUploadOperationOptions): Promise<RemoteCacheClientOperationResult> {\n return this.retryManager.retry((retryContext) => {\n this.printRetryContext('upload', options, retryContext);\n return this.cacheClient.uploadFolder(options);\n });\n }\n\n async downloadFolder(options: RemoteCacheClientOperationOptions): Promise<RemoteCacheClientOperationResult> {\n return this.retryManager.retry((retryContext) => {\n this.printRetryContext('download', options, retryContext);\n return this.cacheClient.downloadFolder(options);\n });\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getListOfBlobs.d.ts","sourceRoot":"","sources":["../src/getListOfBlobs.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAGpF;;GAEG;AACH,wBAAsB,cAAc,CAAC,EAAE,SAAS,EAAE,cAAc,EAAE,UAAU,EAAE,EAAE,wBAAwB,wBAQvG"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createBlobStorageUrl } from './createBlobStorageUrl.js';
|
|
2
|
+
import { BlobServiceClient } from '@azure/storage-blob';
|
|
3
|
+
/**
|
|
4
|
+
* Gets all the blobs in the remote cache.
|
|
5
|
+
*/
|
|
6
|
+
export async function getListOfBlobs({ container, storageAccount, credential }) {
|
|
7
|
+
const blobStorageClient = new BlobServiceClient(createBlobStorageUrl(storageAccount), credential);
|
|
8
|
+
const containerClient = blobStorageClient.getContainerClient(container);
|
|
9
|
+
const blobs = new Set();
|
|
10
|
+
for await (const blob of containerClient.listBlobsFlat()) {
|
|
11
|
+
blobs.add(blob.name);
|
|
12
|
+
}
|
|
13
|
+
return blobs;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=getListOfBlobs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getListOfBlobs.js","sourceRoot":"","sources":["../src/getListOfBlobs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,EAAE,SAAS,EAAE,cAAc,EAAE,UAAU,EAA4B;IACtG,MAAM,iBAAiB,GAAG,IAAI,iBAAiB,CAAC,oBAAoB,CAAC,cAAc,CAAC,EAAE,UAAU,CAAC,CAAC;IAClG,MAAM,eAAe,GAAG,iBAAiB,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;IACxE,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;IAChC,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,eAAe,CAAC,aAAa,EAAE,EAAE,CAAC;QACzD,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACvB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { createBlobStorageUrl } from './createBlobStorageUrl.js';\nimport type { RemoteCacheClientOptions } from './types/RemoteCacheClientOptions.js';\nimport { BlobServiceClient } from '@azure/storage-blob';\n\n/**\n * Gets all the blobs in the remote cache.\n */\nexport async function getListOfBlobs({ container, storageAccount, credential }: RemoteCacheClientOptions) {\n const blobStorageClient = new BlobServiceClient(createBlobStorageUrl(storageAccount), credential);\n const containerClient = blobStorageClient.getContainerClient(container);\n const blobs = new Set<string>();\n for await (const blob of containerClient.listBlobsFlat()) {\n blobs.add(blob.name);\n }\n return blobs;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,KAAK,6BAA6B,EAAE,MAAM,8BAA8B,CAAC;AAE3G,YAAY,EACV,iBAAiB,EACjB,uCAAuC,IAAI,yCAAyC,EACpF,iCAAiC,EACjC,gCAAgC,GACjC,MAAM,8BAA8B,CAAC;AACtC,YAAY,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,YAAY,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC"}
|
package/lib/index.js
ADDED
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAsC,MAAM,8BAA8B,CAAC","sourcesContent":["export { createRemoteCacheClient, type CreateRemoteCacheClientParams } from './createRemoteCacheClient.js';\n\nexport type {\n RemoteCacheClient,\n RemoteCacheClientUploadOperationOptions as RemoteCacheClientDownloadOperationOptions,\n RemoteCacheClientOperationOptions,\n RemoteCacheClientOperationResult,\n} from './types/RemoteCacheClient.js';\nexport type { LoginMethod } from './types/LoginMethod.js';\nexport type { RemoteCacheClientOptions } from './types/RemoteCacheClientOptions.js';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blockListIsInvalidRetryPolicy.d.ts","sourceRoot":"","sources":["../../src/retry/blockListIsInvalidRetryPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE3D,eAAO,MAAM,6BAA6B,EAAE,WAM3C,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const blockListIsInvalidRetryPolicy = {
|
|
2
|
+
maxRetries: 1,
|
|
3
|
+
handle: (error) => {
|
|
4
|
+
return error instanceof Error && error.message.indexOf('The specified block list is invalid.') > -1;
|
|
5
|
+
},
|
|
6
|
+
wait: () => 0,
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=blockListIsInvalidRetryPolicy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blockListIsInvalidRetryPolicy.js","sourceRoot":"","sources":["../../src/retry/blockListIsInvalidRetryPolicy.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,6BAA6B,GAAgB;IACxD,UAAU,EAAE,CAAC;IACb,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE;QAChB,OAAO,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,sCAAsC,CAAC,GAAG,CAAC,CAAC,CAAC;IACtG,CAAC;IACD,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC;CACd,CAAC","sourcesContent":["import type { RetryPolicy } from '../types/RetryPolicy.js';\n\nexport const blockListIsInvalidRetryPolicy: RetryPolicy = {\n maxRetries: 1,\n handle: (error) => {\n return error instanceof Error && error.message.indexOf('The specified block list is invalid.') > -1;\n },\n wait: () => 0,\n};\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
|
2
|
+
// It should be published with your NPM package. It should not be tracked by Git.
|
|
3
|
+
{
|
|
4
|
+
"tsdocVersion": "0.12",
|
|
5
|
+
"toolPackages": [
|
|
6
|
+
{
|
|
7
|
+
"packageName": "@microsoft/api-extractor",
|
|
8
|
+
"packageVersion": "7.39.4"
|
|
9
|
+
}
|
|
10
|
+
]
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LoginMethod.d.ts","sourceRoot":"","sources":["../../src/types/LoginMethod.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,aAAa,GAAG,WAAW,GAAG,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LoginMethod.js","sourceRoot":"","sources":["../../src/types/LoginMethod.ts"],"names":[],"mappings":"","sourcesContent":["export type LoginMethod = 'interactive' | 'azure-cli' | 'device-code';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RemoteCacheClient.d.ts","sourceRoot":"","sources":["../../src/types/RemoteCacheClient.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gCAAgC,GAAG,SAAS,GAAG,WAAW,GAAG,eAAe,CAAC;AAEzF,MAAM,WAAW,iCAAiC;IAChD;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,uCAAwC,SAAQ,iCAAiC;IAChG,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB;AAED,MAAM,WAAW,iBAAiB;IAChC,YAAY,CAAC,OAAO,EAAE,uCAAuC,GAAG,OAAO,CAAC,gCAAgC,CAAC,CAAC;IAC1G,cAAc,CAAC,OAAO,EAAE,iCAAiC,GAAG,OAAO,CAAC,gCAAgC,CAAC,CAAC;CACvG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RemoteCacheClient.js","sourceRoot":"","sources":["../../src/types/RemoteCacheClient.ts"],"names":[],"mappings":"","sourcesContent":["export type RemoteCacheClientOperationResult = 'success' | 'not-found' | 'already-exist';\n\nexport interface RemoteCacheClientOperationOptions {\n /**\n * The unique identifier of the asset\n */\n id: string;\n\n /**\n * Local path to the asset\n */\n path: string;\n\n /**\n * The friendly name of the asset to be used in logs\n */\n friendlyName: string;\n}\n\nexport interface RemoteCacheClientUploadOperationOptions extends RemoteCacheClientOperationOptions {\n globMatches: string[];\n}\n\nexport interface RemoteCacheClient {\n uploadFolder(options: RemoteCacheClientUploadOperationOptions): Promise<RemoteCacheClientOperationResult>;\n downloadFolder(options: RemoteCacheClientOperationOptions): Promise<RemoteCacheClientOperationResult>;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RemoteCacheClientOptions.d.ts","sourceRoot":"","sources":["../../src/types/RemoteCacheClientOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEvD,MAAM,WAAW,wBAAwB;IACvC,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,eAAe,CAAC;CAC7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RemoteCacheClientOptions.js","sourceRoot":"","sources":["../../src/types/RemoteCacheClientOptions.ts"],"names":[],"mappings":"","sourcesContent":["import type { TokenCredential } from '@azure/identity';\n\nexport interface RemoteCacheClientOptions {\n storageAccount: string;\n container: string;\n credential: TokenCredential;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RetryPolicy.d.ts","sourceRoot":"","sources":["../../src/types/RetryPolicy.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG;IACxB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;IAEpC;;OAEG;IACH,IAAI,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,MAAM,CAAC;CACxC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RetryPolicy.js","sourceRoot":"","sources":["../../src/types/RetryPolicy.ts"],"names":[],"mappings":"","sourcesContent":["export type RetryPolicy = {\n /**\n * The maximum number of retries.\n */\n maxRetries: number;\n\n /**\n * Given the error, return true if the operation should be handled by this policy.\n */\n handle: (error: unknown) => boolean;\n\n /**\n * Given the retry attempt, return the number of milliseconds to wait before retrying.\n */\n wait: (retryAttempt: number) => number;\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/remote-cache",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "Manages syncing the local Cloudpack cached assets to/from a remote storage service.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -10,34 +10,33 @@
|
|
|
10
10
|
".": {
|
|
11
11
|
"source": "./src/index.ts",
|
|
12
12
|
"types": "./lib/index.d.ts",
|
|
13
|
-
"import": "./
|
|
13
|
+
"import": "./lib/index.js"
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@ms-cloudpack/eslint-plugin-internal": "*",
|
|
18
|
+
"@ms-cloudpack/scripts": "*"
|
|
19
|
+
},
|
|
16
20
|
"scripts": {
|
|
17
21
|
"api": "cloudpack-scripts api",
|
|
18
22
|
"build:watch": "cloudpack-scripts build-watch",
|
|
19
|
-
"build": "cloudpack-scripts build
|
|
23
|
+
"build": "cloudpack-scripts build",
|
|
20
24
|
"lint:update": "cloudpack-scripts lint-update",
|
|
21
25
|
"lint": "cloudpack-scripts lint",
|
|
22
26
|
"test:watch": "cloudpack-scripts test-watch",
|
|
23
27
|
"test": "cloudpack-scripts test"
|
|
24
28
|
},
|
|
25
29
|
"files": [
|
|
26
|
-
"
|
|
27
|
-
"lib/**/*.d.ts"
|
|
30
|
+
"lib/**/!(*.test.*)"
|
|
28
31
|
],
|
|
29
32
|
"dependencies": {
|
|
33
|
+
"@azure/identity": "^3.4.0",
|
|
34
|
+
"@azure/msal-node": "^2.6.0",
|
|
30
35
|
"@azure/msal-node-extensions": "^1.0.10",
|
|
31
|
-
"@ms-cloudpack/task-reporter": "^0.11.1",
|
|
32
|
-
"@ms-cloudpack/telemetry": "^0.4.7-beta.2",
|
|
33
|
-
"@ms-cloudpack/retry": "^0.1.1"
|
|
34
|
-
},
|
|
35
|
-
"devDependencies": {
|
|
36
|
-
"@azure/identity": "^3.3.0",
|
|
37
36
|
"@azure/storage-blob": "^12.17.0",
|
|
38
|
-
"@
|
|
39
|
-
"@ms-cloudpack/
|
|
40
|
-
"@ms-cloudpack/
|
|
37
|
+
"@ms-cloudpack/retry": "^0.1.1",
|
|
38
|
+
"@ms-cloudpack/task-reporter": "^0.11.2",
|
|
39
|
+
"@ms-cloudpack/telemetry": "^0.4.7",
|
|
41
40
|
"backfill": "^6.2.1",
|
|
42
41
|
"backfill-config": "^6.4.1"
|
|
43
42
|
}
|