@ms-cloudpack/remote-cache 0.1.3 → 0.1.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.
Files changed (95) hide show
  1. package/README.md +2 -7
  2. package/lib/{RemoteCacheClient.d.ts → AzureRemoteCacheClient.d.ts} +5 -4
  3. package/lib/AzureRemoteCacheClient.d.ts.map +1 -0
  4. package/lib/{RemoteCacheClient.js → AzureRemoteCacheClient.js} +18 -6
  5. package/lib/AzureRemoteCacheClient.js.map +1 -0
  6. package/lib/authentication/acquireSasToken.d.ts +1 -1
  7. package/lib/authentication/acquireSasToken.d.ts.map +1 -1
  8. package/lib/authentication/acquireSasToken.js +3 -5
  9. package/lib/authentication/acquireSasToken.js.map +1 -1
  10. package/lib/authentication/getAuthenticatedConnectionString.d.ts.map +1 -1
  11. package/lib/authentication/getAuthenticatedConnectionString.js +8 -2
  12. package/lib/authentication/getAuthenticatedConnectionString.js.map +1 -1
  13. package/lib/authentication/getCredential.d.ts +3 -0
  14. package/lib/authentication/getCredential.d.ts.map +1 -0
  15. package/lib/authentication/getCredential.js +10 -0
  16. package/lib/authentication/getCredential.js.map +1 -0
  17. package/lib/authentication/getSasToken.d.ts +1 -1
  18. package/lib/authentication/getSasToken.d.ts.map +1 -1
  19. package/lib/authentication/getSasToken.js +2 -2
  20. package/lib/authentication/getSasToken.js.map +1 -1
  21. package/lib/createRemoteCacheClient.d.ts +7 -10
  22. package/lib/createRemoteCacheClient.d.ts.map +1 -1
  23. package/lib/createRemoteCacheClient.js +20 -10
  24. package/lib/createRemoteCacheClient.js.map +1 -1
  25. package/lib/decorators/InMemoryDecorator.d.ts +15 -0
  26. package/lib/decorators/InMemoryDecorator.d.ts.map +1 -0
  27. package/lib/decorators/InMemoryDecorator.js +29 -0
  28. package/lib/decorators/InMemoryDecorator.js.map +1 -0
  29. package/lib/decorators/ReporterDecorator.d.ts +10 -0
  30. package/lib/decorators/ReporterDecorator.d.ts.map +1 -0
  31. package/lib/decorators/ReporterDecorator.js +64 -0
  32. package/lib/decorators/ReporterDecorator.js.map +1 -0
  33. package/lib/decorators/RetryDecorator.d.ts +17 -0
  34. package/lib/decorators/RetryDecorator.d.ts.map +1 -0
  35. package/lib/decorators/RetryDecorator.js +27 -0
  36. package/lib/decorators/RetryDecorator.js.map +1 -0
  37. package/lib/getListOfBlobs.d.ts +6 -0
  38. package/lib/getListOfBlobs.d.ts.map +1 -0
  39. package/lib/getListOfBlobs.js +14 -0
  40. package/lib/getListOfBlobs.js.map +1 -0
  41. package/lib/index.d.ts +4 -4
  42. package/lib/index.d.ts.map +1 -1
  43. package/lib/index.js +1 -2
  44. package/lib/index.js.map +1 -1
  45. package/lib/retry/RetryManager.d.ts +20 -0
  46. package/lib/retry/RetryManager.d.ts.map +1 -0
  47. package/lib/retry/RetryManager.js +47 -0
  48. package/lib/retry/RetryManager.js.map +1 -0
  49. package/lib/retry/blockListIsInvalidRetryPolicy.d.ts +3 -0
  50. package/lib/retry/blockListIsInvalidRetryPolicy.d.ts.map +1 -0
  51. package/lib/retry/blockListIsInvalidRetryPolicy.js +8 -0
  52. package/lib/retry/blockListIsInvalidRetryPolicy.js.map +1 -0
  53. package/lib/tsdoc-metadata.json +1 -1
  54. package/lib/types/ConnectionStringOptions.d.ts +2 -0
  55. package/lib/types/ConnectionStringOptions.d.ts.map +1 -1
  56. package/lib/types/ConnectionStringOptions.js.map +1 -1
  57. package/lib/types/RemoteCacheClient.d.ts +11 -0
  58. package/lib/types/RemoteCacheClient.d.ts.map +1 -0
  59. package/lib/types/RemoteCacheClient.js +2 -0
  60. package/lib/types/RemoteCacheClient.js.map +1 -0
  61. package/lib/types/RetryPolicy.d.ts +15 -0
  62. package/lib/types/RetryPolicy.d.ts.map +1 -0
  63. package/lib/types/RetryPolicy.js +2 -0
  64. package/lib/types/RetryPolicy.js.map +1 -0
  65. package/package.json +1 -3
  66. package/lib/RemoteCacheClient.d.ts.map +0 -1
  67. package/lib/RemoteCacheClient.js.map +0 -1
  68. package/lib/createDownloadTask.d.ts +0 -5
  69. package/lib/createDownloadTask.d.ts.map +0 -1
  70. package/lib/createDownloadTask.js +0 -21
  71. package/lib/createDownloadTask.js.map +0 -1
  72. package/lib/createUploadTask.d.ts +0 -5
  73. package/lib/createUploadTask.d.ts.map +0 -1
  74. package/lib/createUploadTask.js +0 -18
  75. package/lib/createUploadTask.js.map +0 -1
  76. package/lib/getPackagesToSync.d.ts +0 -4
  77. package/lib/getPackagesToSync.d.ts.map +0 -1
  78. package/lib/getPackagesToSync.js +0 -18
  79. package/lib/getPackagesToSync.js.map +0 -1
  80. package/lib/performance/markers.d.ts +0 -13
  81. package/lib/performance/markers.d.ts.map +0 -1
  82. package/lib/performance/markers.js +0 -15
  83. package/lib/performance/markers.js.map +0 -1
  84. package/lib/syncToLocal.d.ts +0 -3
  85. package/lib/syncToLocal.d.ts.map +0 -1
  86. package/lib/syncToLocal.js +0 -21
  87. package/lib/syncToLocal.js.map +0 -1
  88. package/lib/syncToRemote.d.ts +0 -15
  89. package/lib/syncToRemote.d.ts.map +0 -1
  90. package/lib/syncToRemote.js +0 -25
  91. package/lib/syncToRemote.js.map +0 -1
  92. package/lib/types/SyncContext.d.ts +0 -24
  93. package/lib/types/SyncContext.d.ts.map +0 -1
  94. package/lib/types/SyncContext.js +0 -2
  95. package/lib/types/SyncContext.js.map +0 -1
package/README.md CHANGED
@@ -5,18 +5,13 @@ This package is a wrapper around the Azure Storage SDK that provides a simple in
5
5
  ## Usage
6
6
 
7
7
  ```ts
8
- import { getAuthenticatedConnectionString, RemoteCacheClient } from '@ms-cloudpack/remote-cache';
8
+ import { createRemoteCacheClient } from '@ms-cloudpack/remote-cache';
9
9
 
10
- const connectionString = await getAuthenticatedConnectionString({
10
+ const client = await createRemoteCacheClient({
11
11
  storageAccount: 'my-storage-account',
12
12
  container: 'my-container',
13
13
  permissions: { read: true, write: false },
14
14
  });
15
15
 
16
- const client = new RemoteCacheClient({
17
- container: 'my-container',
18
- connectionString,
19
- });
20
-
21
16
  await client.downloadFolder('my-folder', 'download-it-to-this-path');
22
17
  ```
@@ -1,5 +1,6 @@
1
1
  import type { RemoteCacheClientOptions } from './types/RemoteCacheClientOptions.js';
2
- export declare class RemoteCacheClient {
2
+ import type { RemoteCacheClient, RemoteCacheClientOperationOptions } from './types/RemoteCacheClient.js';
3
+ export declare class AzureRemoteCacheClient implements RemoteCacheClient {
3
4
  private readonly logger;
4
5
  private readonly config;
5
6
  constructor({ container, connectionString }: RemoteCacheClientOptions);
@@ -9,13 +10,13 @@ export declare class RemoteCacheClient {
9
10
  * @param path - The path to the folder to upload.
10
11
  * @returns - A promise that resolves when the folder has been uploaded.
11
12
  */
12
- uploadFolder(folderName: string, path: string): Promise<void>;
13
+ uploadFolder({ folderName, path }: RemoteCacheClientOperationOptions): Promise<"success" | "not-found">;
13
14
  /**
14
15
  * Downloads the folder from the remote cache.
15
16
  * @param folderName - The name of the folder to download.
16
17
  * @param path - The path to download the folder to.
17
18
  * @returns - A promise that resolves when the folder has been downloaded.
18
19
  */
19
- downloadFolder(folderName: string, path: string): Promise<boolean>;
20
+ downloadFolder({ folderName, path }: RemoteCacheClientOperationOptions): Promise<"success" | "not-found" | "already-exist">;
20
21
  }
21
- //# sourceMappingURL=RemoteCacheClient.d.ts.map
22
+ //# sourceMappingURL=AzureRemoteCacheClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AzureRemoteCacheClient.d.ts","sourceRoot":"","sources":["../src/AzureRemoteCacheClient.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAGpF,OAAO,KAAK,EAAE,iBAAiB,EAAE,iCAAiC,EAAE,MAAM,8BAA8B,CAAC;AAEzG,qBAAa,sBAAuB,YAAW,iBAAiB;IAC9D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsD;IAC7E,OAAO,CAAC,QAAQ,CAAC,MAAM,CAKrB;gBAEU,EAAE,SAAS,EAAE,gBAAgB,EAAE,EAAE,wBAAwB;IAerE;;;;;OAKG;IACG,YAAY,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,iCAAiC;IAS1E;;;;;OAKG;IACG,cAAc,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,iCAAiC;CAY7E"}
@@ -1,5 +1,6 @@
1
1
  import { makeLogger, put, fetch } from 'backfill/lib/api.js';
2
- export class RemoteCacheClient {
2
+ import { existsSync } from 'fs';
3
+ export class AzureRemoteCacheClient {
3
4
  constructor({ container, connectionString }) {
4
5
  this.logger = makeLogger('mute', process.stdout, process.stderr);
5
6
  this.config = {
@@ -21,8 +22,12 @@ export class RemoteCacheClient {
21
22
  * @param path - The path to the folder to upload.
22
23
  * @returns - A promise that resolves when the folder has been uploaded.
23
24
  */
24
- uploadFolder(folderName, path) {
25
- return put(path, folderName, this.logger, this.config);
25
+ async uploadFolder({ folderName, path }) {
26
+ if (!existsSync(path)) {
27
+ return 'not-found';
28
+ }
29
+ await put(path, folderName, this.logger, this.config);
30
+ return 'success';
26
31
  }
27
32
  /**
28
33
  * Downloads the folder from the remote cache.
@@ -30,8 +35,15 @@ export class RemoteCacheClient {
30
35
  * @param path - The path to download the folder to.
31
36
  * @returns - A promise that resolves when the folder has been downloaded.
32
37
  */
33
- downloadFolder(folderName, path) {
34
- return fetch(path, folderName, this.logger, this.config);
38
+ async downloadFolder({ folderName, path }) {
39
+ if (existsSync(path)) {
40
+ return 'already-exist';
41
+ }
42
+ const result = await fetch(path, folderName, this.logger, this.config);
43
+ if (!result) {
44
+ return 'not-found';
45
+ }
46
+ return 'success';
35
47
  }
36
48
  }
37
- //# sourceMappingURL=RemoteCacheClient.js.map
49
+ //# sourceMappingURL=AzureRemoteCacheClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AzureRemoteCacheClient.js","sourceRoot":"","sources":["../src/AzureRemoteCacheClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAG7D,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAGhC,MAAM,OAAO,sBAAsB;IASjC,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAA4B;QARpD,WAAM,GAAG,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;QAS3E,IAAI,CAAC,MAAM,GAAG;YACZ,kBAAkB,EAAE,IAAI;YACxB,mBAAmB,EAAE,EAAE;YACvB,UAAU,EAAE,CAAC,MAAM,CAAC;YACpB,kBAAkB,EAAE;gBAClB,QAAQ,EAAE,YAAY;gBACtB,OAAO,EAAE;oBACP,gBAAgB;oBAChB,SAAS;iBACV;aACF;SACF,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,YAAY,CAAC,EAAE,UAAU,EAAE,IAAI,EAAqC;QACxE,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;YACrB,OAAO,WAAW,CAAC;SACpB;QAED,MAAM,GAAG,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QACtD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,cAAc,CAAC,EAAE,UAAU,EAAE,IAAI,EAAqC;QAC1E,IAAI,UAAU,CAAC,IAAI,CAAC,EAAE;YACpB,OAAO,eAAe,CAAC;SACxB;QAED,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QACvE,IAAI,CAAC,MAAM,EAAE;YACX,OAAO,WAAW,CAAC;SACpB;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;CACF","sourcesContent":["import { makeLogger, put, fetch } from 'backfill/lib/api.js';\nimport type { RemoteCacheClientOptions } from './types/RemoteCacheClientOptions.js';\nimport type { AzureBlobCacheStorageConfig } from 'backfill-config';\nimport { existsSync } from 'fs';\nimport type { RemoteCacheClient, RemoteCacheClientOperationOptions } from './types/RemoteCacheClient.js';\n\nexport class AzureRemoteCacheClient implements RemoteCacheClient {\n private readonly logger = makeLogger('mute', process.stdout, process.stderr);\n private readonly config: {\n cacheStorageConfig: AzureBlobCacheStorageConfig;\n incrementalCaching: boolean;\n internalCacheFolder: string;\n outputGlob: string[];\n };\n\n constructor({ container, connectionString }: RemoteCacheClientOptions) {\n this.config = {\n incrementalCaching: true,\n internalCacheFolder: '', // not used by azure-blob\n outputGlob: ['**/*'],\n cacheStorageConfig: {\n provider: 'azure-blob',\n options: {\n connectionString,\n container,\n },\n },\n };\n }\n\n /**\n * Uploads the folder to the remote cache.\n * @param folderName - The name of the folder to upload.\n * @param path - The path to the folder to upload.\n * @returns - A promise that resolves when the folder has been uploaded.\n */\n async uploadFolder({ folderName, path }: RemoteCacheClientOperationOptions) {\n if (!existsSync(path)) {\n return 'not-found';\n }\n\n await put(path, folderName, this.logger, this.config);\n return 'success';\n }\n\n /**\n * Downloads the folder from the remote cache.\n * @param folderName - The name of the folder to download.\n * @param path - The path to download the folder to.\n * @returns - A promise that resolves when the folder has been downloaded.\n */\n async downloadFolder({ folderName, path }: RemoteCacheClientOperationOptions) {\n if (existsSync(path)) {\n return 'already-exist';\n }\n\n const result = await fetch(path, folderName, this.logger, this.config);\n if (!result) {\n return 'not-found';\n }\n\n return 'success';\n }\n}\n"]}
@@ -1,3 +1,3 @@
1
1
  import type { ConnectionStringOptions } from '../types/ConnectionStringOptions.js';
2
- export declare function acquireSasToken({ storageAccount: account, container, permissions }: ConnectionStringOptions): Promise<string>;
2
+ export declare function acquireSasToken({ storageAccount: account, container, permissions, isInteractiveLogin, }: ConnectionStringOptions): Promise<string>;
3
3
  //# sourceMappingURL=acquireSasToken.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"acquireSasToken.d.ts","sourceRoot":"","sources":["../../src/authentication/acquireSasToken.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAGnF,wBAAsB,eAAe,CAAC,EAAE,cAAc,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,EAAE,uBAAuB,mBA2BjH"}
1
+ {"version":3,"file":"acquireSasToken.d.ts","sourceRoot":"","sources":["../../src/authentication/acquireSasToken.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAInF,wBAAsB,eAAe,CAAC,EACpC,cAAc,EAAE,OAAO,EACvB,SAAS,EACT,WAAW,EACX,kBAAkB,GACnB,EAAE,uBAAuB,mBAyBzB"}
@@ -1,10 +1,8 @@
1
1
  import { BlobServiceClient, ContainerSASPermissions, SASProtocol, generateBlobSASQueryParameters, } from '@azure/storage-blob';
2
- import { InteractiveBrowserCredential } from '@azure/identity';
3
2
  import { createBlobStorageUrl } from './createBlobStorageUrl.js';
4
- export async function acquireSasToken({ storageAccount: account, container, permissions }) {
5
- const credential = new InteractiveBrowserCredential({
6
- redirectUri: 'http://localhost:1337',
7
- });
3
+ import { getCredential } from './getCredential.js';
4
+ export async function acquireSasToken({ storageAccount: account, container, permissions, isInteractiveLogin, }) {
5
+ const credential = getCredential(isInteractiveLogin);
8
6
  const blobStorage = new BlobServiceClient(createBlobStorageUrl(account), credential);
9
7
  const containerClient = blobStorage.getContainerClient(container);
10
8
  const startsOn = new Date(); // now
@@ -1 +1 @@
1
- {"version":3,"file":"acquireSasToken.js","sourceRoot":"","sources":["../../src/authentication/acquireSasToken.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,uBAAuB,EACvB,WAAW,EACX,8BAA8B,GAC/B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAE/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,EAAE,cAAc,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAA2B;IAChH,MAAM,UAAU,GAAG,IAAI,4BAA4B,CAAC;QAClD,WAAW,EAAE,uBAAuB;KACrC,CAAC,CAAC;IACH,MAAM,WAAW,GAAG,IAAI,iBAAiB,CAAC,oBAAoB,CAAC,OAAO,CAAC,EAAE,UAAU,CAAC,CAAC;IACrF,MAAM,eAAe,GAAG,WAAW,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;IAElE,MAAM,QAAQ,GAAG,IAAI,IAAI,EAAE,CAAC,CAAC,MAAM;IACnC,MAAM,mBAAmB,GAAG,QAAQ,CAAC;IACrC,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,mBAAmB,CAAC,CAAC,CAAC,cAAc;IAEpF,MAAM,iBAAiB,GAAG,MAAM,WAAW,CAAC,oBAAoB,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IAEtF,MAAM,cAAc,GAAG,8BAA8B,CACnD;QACE,aAAa,EAAE,eAAe,CAAC,aAAa;QAC5C,WAAW,EAAE,uBAAuB,CAAC,IAAI,CAAC,WAAW,CAAC;QACtD,SAAS;QACT,QAAQ;QACR,OAAO,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,iBAAiB,EAAE;QACrD,QAAQ,EAAE,WAAW,CAAC,KAAK;KAC5B,EACD,iBAAiB,EACjB,OAAO,CACR,CAAC;IAEF,OAAO,cAAc,CAAC,QAAQ,EAAE,CAAC;AACnC,CAAC","sourcesContent":["import {\n BlobServiceClient,\n ContainerSASPermissions,\n SASProtocol,\n generateBlobSASQueryParameters,\n} from '@azure/storage-blob';\nimport { InteractiveBrowserCredential } from '@azure/identity';\nimport type { ConnectionStringOptions } from '../types/ConnectionStringOptions.js';\nimport { createBlobStorageUrl } from './createBlobStorageUrl.js';\n\nexport async function acquireSasToken({ storageAccount: account, container, permissions }: ConnectionStringOptions) {\n const credential = new InteractiveBrowserCredential({\n redirectUri: 'http://localhost:1337',\n });\n const blobStorage = new BlobServiceClient(createBlobStorageUrl(account), credential);\n const containerClient = blobStorage.getContainerClient(container);\n\n const startsOn = new Date(); // now\n const twentyFourHoursInMs = 86400000;\n const expiresOn = new Date(startsOn.valueOf() + twentyFourHoursInMs); // in 24 hours\n\n const userDelegationKey = await blobStorage.getUserDelegationKey(startsOn, expiresOn);\n\n const sasQueryParams = generateBlobSASQueryParameters(\n {\n containerName: containerClient.containerName,\n permissions: ContainerSASPermissions.from(permissions),\n expiresOn,\n startsOn,\n ipRange: { start: '0.0.0.0', end: '255.255.255.255' },\n protocol: SASProtocol.Https,\n },\n userDelegationKey,\n account,\n );\n\n return sasQueryParams.toString();\n}\n"]}
1
+ {"version":3,"file":"acquireSasToken.js","sourceRoot":"","sources":["../../src/authentication/acquireSasToken.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,uBAAuB,EACvB,WAAW,EACX,8BAA8B,GAC/B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,EACpC,cAAc,EAAE,OAAO,EACvB,SAAS,EACT,WAAW,EACX,kBAAkB,GACM;IACxB,MAAM,UAAU,GAAG,aAAa,CAAC,kBAAkB,CAAC,CAAC;IACrD,MAAM,WAAW,GAAG,IAAI,iBAAiB,CAAC,oBAAoB,CAAC,OAAO,CAAC,EAAE,UAAU,CAAC,CAAC;IACrF,MAAM,eAAe,GAAG,WAAW,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;IAElE,MAAM,QAAQ,GAAG,IAAI,IAAI,EAAE,CAAC,CAAC,MAAM;IACnC,MAAM,mBAAmB,GAAG,QAAQ,CAAC;IACrC,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,mBAAmB,CAAC,CAAC,CAAC,cAAc;IAEpF,MAAM,iBAAiB,GAAG,MAAM,WAAW,CAAC,oBAAoB,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IAEtF,MAAM,cAAc,GAAG,8BAA8B,CACnD;QACE,aAAa,EAAE,eAAe,CAAC,aAAa;QAC5C,WAAW,EAAE,uBAAuB,CAAC,IAAI,CAAC,WAAW,CAAC;QACtD,SAAS;QACT,QAAQ;QACR,OAAO,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,iBAAiB,EAAE;QACrD,QAAQ,EAAE,WAAW,CAAC,KAAK;KAC5B,EACD,iBAAiB,EACjB,OAAO,CACR,CAAC;IAEF,OAAO,cAAc,CAAC,QAAQ,EAAE,CAAC;AACnC,CAAC","sourcesContent":["import {\n BlobServiceClient,\n ContainerSASPermissions,\n SASProtocol,\n generateBlobSASQueryParameters,\n} from '@azure/storage-blob';\nimport type { ConnectionStringOptions } from '../types/ConnectionStringOptions.js';\nimport { createBlobStorageUrl } from './createBlobStorageUrl.js';\nimport { getCredential } from './getCredential.js';\n\nexport async function acquireSasToken({\n storageAccount: account,\n container,\n permissions,\n isInteractiveLogin,\n}: ConnectionStringOptions) {\n const credential = getCredential(isInteractiveLogin);\n const blobStorage = new BlobServiceClient(createBlobStorageUrl(account), credential);\n const containerClient = blobStorage.getContainerClient(container);\n\n const startsOn = new Date(); // now\n const twentyFourHoursInMs = 86400000;\n const expiresOn = new Date(startsOn.valueOf() + twentyFourHoursInMs); // in 24 hours\n\n const userDelegationKey = await blobStorage.getUserDelegationKey(startsOn, expiresOn);\n\n const sasQueryParams = generateBlobSASQueryParameters(\n {\n containerName: containerClient.containerName,\n permissions: ContainerSASPermissions.from(permissions),\n expiresOn,\n startsOn,\n ipRange: { start: '0.0.0.0', end: '255.255.255.255' },\n protocol: SASProtocol.Https,\n },\n userDelegationKey,\n account,\n );\n\n return sasQueryParams.toString();\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"getAuthenticatedConnectionString.d.ts","sourceRoot":"","sources":["../../src/authentication/getAuthenticatedConnectionString.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAMnF,wBAAsB,gCAAgC,CAAC,uBAAuB,EAAE,uBAAuB,mBAMtG"}
1
+ {"version":3,"file":"getAuthenticatedConnectionString.d.ts","sourceRoot":"","sources":["../../src/authentication/getAuthenticatedConnectionString.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAUnF,wBAAsB,gCAAgC,CAAC,uBAAuB,EAAE,uBAAuB,mBAUtG"}
@@ -1,10 +1,16 @@
1
1
  import { createBlobStorageUrl } from './createBlobStorageUrl.js';
2
2
  import { getSasToken } from './getSasToken.js';
3
- import { KeyRingLocalTokenCache } from './KeyRingLocalTokenCache.js';
4
3
  import { acquireSasToken } from './acquireSasToken.js';
5
4
  import { isExpired } from './isExpired.js';
5
+ async function createLocalTokenCacheLazy(connectionStringOptions) {
6
+ const { KeyRingLocalTokenCache } = await import('./KeyRingLocalTokenCache.js');
7
+ return new KeyRingLocalTokenCache(connectionStringOptions);
8
+ }
6
9
  export async function getAuthenticatedConnectionString(connectionStringOptions) {
7
- const tokenCache = new KeyRingLocalTokenCache(connectionStringOptions);
10
+ // No need to cache tokens if the user is NOT running in interactive mode.
11
+ const tokenCache = connectionStringOptions.isInteractiveLogin
12
+ ? await createLocalTokenCacheLazy(connectionStringOptions)
13
+ : undefined;
8
14
  const sasToken = await getSasToken({ connectionStringOptions }, { tokenCache, acquireSasToken, isExpired });
9
15
  const { storageAccount } = connectionStringOptions;
10
16
  return `BlobEndpoint=${createBlobStorageUrl(storageAccount)};SharedAccessSignature=${sasToken}`;
@@ -1 +1 @@
1
- {"version":3,"file":"getAuthenticatedConnectionString.js","sourceRoot":"","sources":["../../src/authentication/getAuthenticatedConnectionString.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,MAAM,CAAC,KAAK,UAAU,gCAAgC,CAAC,uBAAgD;IACrG,MAAM,UAAU,GAAG,IAAI,sBAAsB,CAAC,uBAAuB,CAAC,CAAC;IACvE,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,EAAE,uBAAuB,EAAE,EAAE,EAAE,UAAU,EAAE,eAAe,EAAE,SAAS,EAAE,CAAC,CAAC;IAE5G,MAAM,EAAE,cAAc,EAAE,GAAG,uBAAuB,CAAC;IACnD,OAAO,gBAAgB,oBAAoB,CAAC,cAAc,CAAC,0BAA0B,QAAQ,EAAE,CAAC;AAClG,CAAC","sourcesContent":["import { createBlobStorageUrl } from './createBlobStorageUrl.js';\nimport type { ConnectionStringOptions } from '../types/ConnectionStringOptions.js';\nimport { getSasToken } from './getSasToken.js';\nimport { KeyRingLocalTokenCache } from './KeyRingLocalTokenCache.js';\nimport { acquireSasToken } from './acquireSasToken.js';\nimport { isExpired } from './isExpired.js';\n\nexport async function getAuthenticatedConnectionString(connectionStringOptions: ConnectionStringOptions) {\n const tokenCache = new KeyRingLocalTokenCache(connectionStringOptions);\n const sasToken = await getSasToken({ connectionStringOptions }, { tokenCache, acquireSasToken, isExpired });\n\n const { storageAccount } = connectionStringOptions;\n return `BlobEndpoint=${createBlobStorageUrl(storageAccount)};SharedAccessSignature=${sasToken}`;\n}\n"]}
1
+ {"version":3,"file":"getAuthenticatedConnectionString.js","sourceRoot":"","sources":["../../src/authentication/getAuthenticatedConnectionString.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,KAAK,UAAU,yBAAyB,CAAC,uBAAgD;IACvF,MAAM,EAAE,sBAAsB,EAAE,GAAG,MAAM,MAAM,CAAC,6BAA6B,CAAC,CAAC;IAC/E,OAAO,IAAI,sBAAsB,CAAC,uBAAuB,CAAC,CAAC;AAC7D,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gCAAgC,CAAC,uBAAgD;IACrG,0EAA0E;IAC1E,MAAM,UAAU,GAAG,uBAAuB,CAAC,kBAAkB;QAC3D,CAAC,CAAC,MAAM,yBAAyB,CAAC,uBAAuB,CAAC;QAC1D,CAAC,CAAC,SAAS,CAAC;IAEd,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,EAAE,uBAAuB,EAAE,EAAE,EAAE,UAAU,EAAE,eAAe,EAAE,SAAS,EAAE,CAAC,CAAC;IAE5G,MAAM,EAAE,cAAc,EAAE,GAAG,uBAAuB,CAAC;IACnD,OAAO,gBAAgB,oBAAoB,CAAC,cAAc,CAAC,0BAA0B,QAAQ,EAAE,CAAC;AAClG,CAAC","sourcesContent":["import { createBlobStorageUrl } from './createBlobStorageUrl.js';\nimport type { ConnectionStringOptions } from '../types/ConnectionStringOptions.js';\nimport { getSasToken } from './getSasToken.js';\nimport { acquireSasToken } from './acquireSasToken.js';\nimport { isExpired } from './isExpired.js';\n\nasync function createLocalTokenCacheLazy(connectionStringOptions: ConnectionStringOptions) {\n const { KeyRingLocalTokenCache } = await import('./KeyRingLocalTokenCache.js');\n return new KeyRingLocalTokenCache(connectionStringOptions);\n}\n\nexport async function getAuthenticatedConnectionString(connectionStringOptions: ConnectionStringOptions) {\n // No need to cache tokens if the user is NOT running in interactive mode.\n const tokenCache = connectionStringOptions.isInteractiveLogin\n ? await createLocalTokenCacheLazy(connectionStringOptions)\n : undefined;\n\n const sasToken = await getSasToken({ connectionStringOptions }, { tokenCache, acquireSasToken, isExpired });\n\n const { storageAccount } = connectionStringOptions;\n return `BlobEndpoint=${createBlobStorageUrl(storageAccount)};SharedAccessSignature=${sasToken}`;\n}\n"]}
@@ -0,0 +1,3 @@
1
+ import { DefaultAzureCredential, InteractiveBrowserCredential } from '@azure/identity';
2
+ export declare function getCredential(isInteractiveLogin: boolean): InteractiveBrowserCredential | DefaultAzureCredential;
3
+ //# sourceMappingURL=getCredential.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getCredential.d.ts","sourceRoot":"","sources":["../../src/authentication/getCredential.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAEvF,wBAAgB,aAAa,CAAC,kBAAkB,EAAE,OAAO,yDAOxD"}
@@ -0,0 +1,10 @@
1
+ import { DefaultAzureCredential, InteractiveBrowserCredential } from '@azure/identity';
2
+ export function getCredential(isInteractiveLogin) {
3
+ if (isInteractiveLogin) {
4
+ return new InteractiveBrowserCredential({
5
+ redirectUri: 'http://localhost:1337',
6
+ });
7
+ }
8
+ return new DefaultAzureCredential();
9
+ }
10
+ //# sourceMappingURL=getCredential.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getCredential.js","sourceRoot":"","sources":["../../src/authentication/getCredential.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAEvF,MAAM,UAAU,aAAa,CAAC,kBAA2B;IACvD,IAAI,kBAAkB,EAAE;QACtB,OAAO,IAAI,4BAA4B,CAAC;YACtC,WAAW,EAAE,uBAAuB;SACrC,CAAC,CAAC;KACJ;IACD,OAAO,IAAI,sBAAsB,EAAE,CAAC;AACtC,CAAC","sourcesContent":["import { DefaultAzureCredential, InteractiveBrowserCredential } from '@azure/identity';\n\nexport function getCredential(isInteractiveLogin: boolean) {\n if (isInteractiveLogin) {\n return new InteractiveBrowserCredential({\n redirectUri: 'http://localhost:1337',\n });\n }\n return new DefaultAzureCredential();\n}\n"]}
@@ -4,7 +4,7 @@ export interface GetSasTokenOptions {
4
4
  connectionStringOptions: ConnectionStringOptions;
5
5
  }
6
6
  export interface GetSasTokenDependencies {
7
- tokenCache: LocalTokenCacheProvider;
7
+ tokenCache?: LocalTokenCacheProvider;
8
8
  acquireSasToken: (options: ConnectionStringOptions) => Promise<string>;
9
9
  isExpired: (token: string) => boolean;
10
10
  }
@@ -1 +1 @@
1
- {"version":3,"file":"getSasToken.d.ts","sourceRoot":"","sources":["../../src/authentication/getSasToken.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AACnF,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAEnF,MAAM,WAAW,kBAAkB;IACjC,uBAAuB,EAAE,uBAAuB,CAAC;CAClD;AAED,MAAM,WAAW,uBAAuB;IACtC,UAAU,EAAE,uBAAuB,CAAC;IACpC,eAAe,EAAE,CAAC,OAAO,EAAE,uBAAuB,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACvE,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;CACvC;AAED,wBAAsB,WAAW,CAC/B,EAAE,uBAAuB,EAAE,EAAE,kBAAkB,EAC/C,EAAE,UAAU,EAAE,eAAe,EAAE,SAAS,EAAE,EAAE,uBAAuB,+BAcpE"}
1
+ {"version":3,"file":"getSasToken.d.ts","sourceRoot":"","sources":["../../src/authentication/getSasToken.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AACnF,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAEnF,MAAM,WAAW,kBAAkB;IACjC,uBAAuB,EAAE,uBAAuB,CAAC;CAClD;AAED,MAAM,WAAW,uBAAuB;IACtC,UAAU,CAAC,EAAE,uBAAuB,CAAC;IACrC,eAAe,EAAE,CAAC,OAAO,EAAE,uBAAuB,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACvE,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;CACvC;AAED,wBAAsB,WAAW,CAC/B,EAAE,uBAAuB,EAAE,EAAE,kBAAkB,EAC/C,EAAE,UAAU,EAAE,eAAe,EAAE,SAAS,EAAE,EAAE,uBAAuB,+BAcpE"}
@@ -1,11 +1,11 @@
1
1
  export async function getSasToken({ connectionStringOptions }, { tokenCache, acquireSasToken, isExpired }) {
2
2
  try {
3
- const localToken = tokenCache.get();
3
+ const localToken = tokenCache?.get();
4
4
  if (localToken && !isExpired(localToken)) {
5
5
  return localToken;
6
6
  }
7
7
  const token = await acquireSasToken(connectionStringOptions);
8
- tokenCache.set(token);
8
+ tokenCache?.set(token);
9
9
  return token;
10
10
  }
11
11
  catch (error) {
@@ -1 +1 @@
1
- {"version":3,"file":"getSasToken.js","sourceRoot":"","sources":["../../src/authentication/getSasToken.ts"],"names":[],"mappings":"AAaA,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,EAAE,uBAAuB,EAAsB,EAC/C,EAAE,UAAU,EAAE,eAAe,EAAE,SAAS,EAA2B;IAEnE,IAAI;QACF,MAAM,UAAU,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC;QACpC,IAAI,UAAU,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE;YACxC,OAAO,UAAU,CAAC;SACnB;QAED,MAAM,KAAK,GAAG,MAAM,eAAe,CAAC,uBAAuB,CAAC,CAAC;QAC7D,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACtB,OAAO,KAAK,CAAC;KACd;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,CAAC,KAAK,CAAC,8CAA8C,CAAC,CAAC;KAC/D;AACH,CAAC","sourcesContent":["import type { LocalTokenCacheProvider } from '../types/LocalTokenCacheProvider.js';\nimport type { ConnectionStringOptions } from '../types/ConnectionStringOptions.js';\n\nexport interface GetSasTokenOptions {\n connectionStringOptions: ConnectionStringOptions;\n}\n\nexport interface GetSasTokenDependencies {\n tokenCache: LocalTokenCacheProvider;\n acquireSasToken: (options: ConnectionStringOptions) => Promise<string>;\n isExpired: (token: string) => boolean;\n}\n\nexport async function getSasToken(\n { connectionStringOptions }: GetSasTokenOptions,\n { tokenCache, acquireSasToken, isExpired }: GetSasTokenDependencies,\n) {\n try {\n const localToken = tokenCache.get();\n if (localToken && !isExpired(localToken)) {\n return localToken;\n }\n\n const token = await acquireSasToken(connectionStringOptions);\n tokenCache.set(token);\n return token;\n } catch (error) {\n console.error(`Failed to get SAS token for storage account.`);\n }\n}\n"]}
1
+ {"version":3,"file":"getSasToken.js","sourceRoot":"","sources":["../../src/authentication/getSasToken.ts"],"names":[],"mappings":"AAaA,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,EAAE,uBAAuB,EAAsB,EAC/C,EAAE,UAAU,EAAE,eAAe,EAAE,SAAS,EAA2B;IAEnE,IAAI;QACF,MAAM,UAAU,GAAG,UAAU,EAAE,GAAG,EAAE,CAAC;QACrC,IAAI,UAAU,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE;YACxC,OAAO,UAAU,CAAC;SACnB;QAED,MAAM,KAAK,GAAG,MAAM,eAAe,CAAC,uBAAuB,CAAC,CAAC;QAC7D,UAAU,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC;QACvB,OAAO,KAAK,CAAC;KACd;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,CAAC,KAAK,CAAC,8CAA8C,CAAC,CAAC;KAC/D;AACH,CAAC","sourcesContent":["import type { LocalTokenCacheProvider } from '../types/LocalTokenCacheProvider.js';\nimport type { ConnectionStringOptions } from '../types/ConnectionStringOptions.js';\n\nexport interface GetSasTokenOptions {\n connectionStringOptions: ConnectionStringOptions;\n}\n\nexport interface GetSasTokenDependencies {\n tokenCache?: LocalTokenCacheProvider;\n acquireSasToken: (options: ConnectionStringOptions) => Promise<string>;\n isExpired: (token: string) => boolean;\n}\n\nexport async function getSasToken(\n { connectionStringOptions }: GetSasTokenOptions,\n { tokenCache, acquireSasToken, isExpired }: GetSasTokenDependencies,\n) {\n try {\n const localToken = tokenCache?.get();\n if (localToken && !isExpired(localToken)) {\n return localToken;\n }\n\n const token = await acquireSasToken(connectionStringOptions);\n tokenCache?.set(token);\n return token;\n } catch (error) {\n console.error(`Failed to get SAS token for storage account.`);\n }\n}\n"]}
@@ -1,11 +1,8 @@
1
- import { RemoteCacheClient } from './RemoteCacheClient.js';
2
- import type { SyncContext } from './types/SyncContext.js';
3
- export interface ClientOptions {
4
- permissions: {
5
- read: boolean;
6
- write: boolean;
7
- };
8
- config: SyncContext['config'];
9
- }
10
- export declare function createRemoteCacheClient({ config, permissions }: ClientOptions): Promise<RemoteCacheClient>;
1
+ import type { TaskReporter } from '@ms-cloudpack/task-reporter';
2
+ import type { ConnectionStringOptions } from './types/ConnectionStringOptions.js';
3
+ import type { RemoteCacheClient } from './types/RemoteCacheClient.js';
4
+ export declare function createRemoteCacheClient(options: {
5
+ connectionStringOptions: ConnectionStringOptions;
6
+ reporter: TaskReporter;
7
+ }): Promise<RemoteCacheClient>;
11
8
  //# sourceMappingURL=createRemoteCacheClient.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createRemoteCacheClient.d.ts","sourceRoot":"","sources":["../src/createRemoteCacheClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAE1D,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE;QACX,IAAI,EAAE,OAAO,CAAC;QACd,KAAK,EAAE,OAAO,CAAC;KAChB,CAAC;IACF,MAAM,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;CAC/B;AAED,wBAAsB,uBAAuB,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,aAAa,8BAenF"}
1
+ {"version":3,"file":"createRemoteCacheClient.d.ts","sourceRoot":"","sources":["../src/createRemoteCacheClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAMhE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAClF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAKtE,wBAAsB,uBAAuB,CAAC,OAAO,EAAE;IACrD,uBAAuB,EAAE,uBAAuB,CAAC;IACjD,QAAQ,EAAE,YAAY,CAAC;CACxB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAuB7B"}
@@ -1,16 +1,26 @@
1
- import { RemoteCacheClient } from './RemoteCacheClient.js';
1
+ import { AzureRemoteCacheClient } from './AzureRemoteCacheClient.js';
2
2
  import { getAuthenticatedConnectionString } from './authentication/getAuthenticatedConnectionString.js';
3
- export async function createRemoteCacheClient({ config, permissions }) {
4
- const { container, storageAccount } = config;
5
- const connectionString = await getAuthenticatedConnectionString({
6
- storageAccount,
7
- container,
8
- permissions,
9
- });
10
- const client = new RemoteCacheClient({
3
+ import { InMemoryDecorator } from './decorators/InMemoryDecorator.js';
4
+ import { ReporterDecorator } from './decorators/ReporterDecorator.js';
5
+ import { getListOfBlobs } from './getListOfBlobs.js';
6
+ import { RetryDecorator } from './decorators/RetryDecorator.js';
7
+ import { blockListIsInvalidRetryPolicy } from './retry/blockListIsInvalidRetryPolicy.js';
8
+ import { RetryManager } from './retry/RetryManager.js';
9
+ export async function createRemoteCacheClient(options) {
10
+ const { connectionStringOptions, reporter } = options;
11
+ const { container } = connectionStringOptions;
12
+ const connectionString = await getAuthenticatedConnectionString(connectionStringOptions);
13
+ const cacheClientOptions = {
11
14
  container,
12
15
  connectionString,
13
- });
16
+ };
17
+ const client = new ReporterDecorator(new RetryDecorator({
18
+ retryManager: new RetryManager([blockListIsInvalidRetryPolicy]),
19
+ cacheClient: new InMemoryDecorator({
20
+ cacheClient: new AzureRemoteCacheClient(cacheClientOptions),
21
+ getList: () => getListOfBlobs(cacheClientOptions),
22
+ }),
23
+ }), reporter);
14
24
  return client;
15
25
  }
16
26
  //# sourceMappingURL=createRemoteCacheClient.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"createRemoteCacheClient.js","sourceRoot":"","sources":["../src/createRemoteCacheClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,gCAAgC,EAAE,MAAM,sDAAsD,CAAC;AAWxG,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,EAAE,MAAM,EAAE,WAAW,EAAiB;IAClF,MAAM,EAAE,SAAS,EAAE,cAAc,EAAE,GAAG,MAAM,CAAC;IAE7C,MAAM,gBAAgB,GAAG,MAAM,gCAAgC,CAAC;QAC9D,cAAc;QACd,SAAS;QACT,WAAW;KACZ,CAAC,CAAC;IAEH,MAAM,MAAM,GAAG,IAAI,iBAAiB,CAAC;QACnC,SAAS;QACT,gBAAgB;KACjB,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { RemoteCacheClient } from './RemoteCacheClient.js';\nimport { getAuthenticatedConnectionString } from './authentication/getAuthenticatedConnectionString.js';\nimport type { SyncContext } from './types/SyncContext.js';\n\nexport interface ClientOptions {\n permissions: {\n read: boolean;\n write: boolean;\n };\n config: SyncContext['config'];\n}\n\nexport async function createRemoteCacheClient({ config, permissions }: ClientOptions) {\n const { container, storageAccount } = config;\n\n const connectionString = await getAuthenticatedConnectionString({\n storageAccount,\n container,\n permissions,\n });\n\n const client = new RemoteCacheClient({\n container,\n connectionString,\n });\n\n return client;\n}\n"]}
1
+ {"version":3,"file":"createRemoteCacheClient.js","sourceRoot":"","sources":["../src/createRemoteCacheClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,gCAAgC,EAAE,MAAM,sDAAsD,CAAC;AACxG,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGrD,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,6BAA6B,EAAE,MAAM,0CAA0C,CAAC;AACzF,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,OAG7C;IACC,MAAM,EAAE,uBAAuB,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IACtD,MAAM,EAAE,SAAS,EAAE,GAAG,uBAAuB,CAAC;IAE9C,MAAM,gBAAgB,GAAG,MAAM,gCAAgC,CAAC,uBAAuB,CAAC,CAAC;IAEzF,MAAM,kBAAkB,GAAG;QACzB,SAAS;QACT,gBAAgB;KACjB,CAAC;IAEF,MAAM,MAAM,GAAG,IAAI,iBAAiB,CAClC,IAAI,cAAc,CAAC;QACjB,YAAY,EAAE,IAAI,YAAY,CAAC,CAAC,6BAA6B,CAAC,CAAC;QAC/D,WAAW,EAAE,IAAI,iBAAiB,CAAC;YACjC,WAAW,EAAE,IAAI,sBAAsB,CAAC,kBAAkB,CAAC;YAC3D,OAAO,EAAE,GAAG,EAAE,CAAC,cAAc,CAAC,kBAAkB,CAAC;SAClD,CAAC;KACH,CAAC,EACF,QAAQ,CACT,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type { TaskReporter } from '@ms-cloudpack/task-reporter';\nimport { AzureRemoteCacheClient } from './AzureRemoteCacheClient.js';\nimport { getAuthenticatedConnectionString } from './authentication/getAuthenticatedConnectionString.js';\nimport { InMemoryDecorator } from './decorators/InMemoryDecorator.js';\nimport { ReporterDecorator } from './decorators/ReporterDecorator.js';\nimport { getListOfBlobs } from './getListOfBlobs.js';\nimport type { ConnectionStringOptions } from './types/ConnectionStringOptions.js';\nimport type { RemoteCacheClient } from './types/RemoteCacheClient.js';\nimport { RetryDecorator } from './decorators/RetryDecorator.js';\nimport { blockListIsInvalidRetryPolicy } from './retry/blockListIsInvalidRetryPolicy.js';\nimport { RetryManager } from './retry/RetryManager.js';\n\nexport async function createRemoteCacheClient(options: {\n connectionStringOptions: ConnectionStringOptions;\n reporter: TaskReporter;\n}): Promise<RemoteCacheClient> {\n const { connectionStringOptions, reporter } = options;\n const { container } = connectionStringOptions;\n\n const connectionString = await getAuthenticatedConnectionString(connectionStringOptions);\n\n const cacheClientOptions = {\n container,\n connectionString,\n };\n\n const client = new ReporterDecorator(\n new RetryDecorator({\n retryManager: new RetryManager([blockListIsInvalidRetryPolicy]),\n cacheClient: new InMemoryDecorator({\n cacheClient: new AzureRemoteCacheClient(cacheClientOptions),\n getList: () => getListOfBlobs(cacheClientOptions),\n }),\n }),\n reporter,\n );\n\n return client;\n}\n"]}
@@ -0,0 +1,15 @@
1
+ import type { RemoteCacheClient, RemoteCacheClientOperationOptions, RemoteCacheClientOperationResult } from '../types/RemoteCacheClient.js';
2
+ /**
3
+ * A decorator for a RemoteCacheClient that keeps a list of remote resources locally.
4
+ */
5
+ export declare class InMemoryDecorator implements RemoteCacheClient {
6
+ private readonly cacheClient;
7
+ private readonly list;
8
+ constructor(options: {
9
+ cacheClient: RemoteCacheClient;
10
+ getList: () => Promise<Set<string>>;
11
+ });
12
+ uploadFolder(options: RemoteCacheClientOperationOptions): Promise<RemoteCacheClientOperationResult>;
13
+ downloadFolder(options: RemoteCacheClientOperationOptions): Promise<RemoteCacheClientOperationResult>;
14
+ }
15
+ //# sourceMappingURL=InMemoryDecorator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InMemoryDecorator.d.ts","sourceRoot":"","sources":["../../src/decorators/InMemoryDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,iCAAiC,EACjC,gCAAgC,EACjC,MAAM,+BAA+B,CAAC;AAEvC;;GAEG;AACH,qBAAa,iBAAkB,YAAW,iBAAiB;IACzD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAoB;IAChD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAuB;gBAEhC,OAAO,EAAE;QAAE,WAAW,EAAE,iBAAiB,CAAC;QAAC,OAAO,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAA;KAAE;IAKtF,YAAY,CAAC,OAAO,EAAE,iCAAiC,GAAG,OAAO,CAAC,gCAAgC,CAAC;IAgBnG,cAAc,CAAC,OAAO,EAAE,iCAAiC,GAAG,OAAO,CAAC,gCAAgC,CAAC;CAQ5G"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * A decorator for a RemoteCacheClient that keeps a list of remote resources locally.
3
+ */
4
+ export class InMemoryDecorator {
5
+ constructor(options) {
6
+ this.cacheClient = options.cacheClient;
7
+ this.list = options.getList();
8
+ }
9
+ async uploadFolder(options) {
10
+ if ((await this.list).has(options.folderName)) {
11
+ // This resource already exists in the remote cache, no need to upload it again.
12
+ return 'already-exist';
13
+ }
14
+ const result = await this.cacheClient.uploadFolder(options);
15
+ if (result === 'success') {
16
+ // The upload is successful, add the resource to the list.
17
+ (await this.list).add(options.folderName);
18
+ }
19
+ return result;
20
+ }
21
+ async downloadFolder(options) {
22
+ if (!(await this.list).has(options.folderName)) {
23
+ // This resource doesn't exist in the remote cache, can't download it.
24
+ return 'not-found';
25
+ }
26
+ return this.cacheClient.downloadFolder(options);
27
+ }
28
+ }
29
+ //# sourceMappingURL=InMemoryDecorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InMemoryDecorator.js","sourceRoot":"","sources":["../../src/decorators/InMemoryDecorator.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,MAAM,OAAO,iBAAiB;IAI5B,YAAY,OAAgF;QAC1F,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;QACvC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAChC,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,OAA0C;QAC3D,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;YAC7C,gFAAgF;YAChF,OAAO,eAAe,CAAC;SACxB;QAED,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QAE5D,IAAI,MAAM,KAAK,SAAS,EAAE;YACxB,0DAA0D;YAC1D,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;SAC3C;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,OAA0C;QAC7D,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;YAC9C,sEAAsE;YACtE,OAAO,WAAW,CAAC;SACpB;QAED,OAAO,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IAClD,CAAC;CACF","sourcesContent":["import type {\n RemoteCacheClient,\n RemoteCacheClientOperationOptions,\n RemoteCacheClientOperationResult,\n} from '../types/RemoteCacheClient.js';\n\n/**\n * A decorator for a RemoteCacheClient that keeps a list of remote resources locally.\n */\nexport class InMemoryDecorator implements RemoteCacheClient {\n private readonly cacheClient: RemoteCacheClient;\n private readonly list: Promise<Set<string>>;\n\n constructor(options: { cacheClient: RemoteCacheClient; getList: () => Promise<Set<string>> }) {\n this.cacheClient = options.cacheClient;\n this.list = options.getList();\n }\n\n async uploadFolder(options: RemoteCacheClientOperationOptions): Promise<RemoteCacheClientOperationResult> {\n if ((await this.list).has(options.folderName)) {\n // This resource already exists in the remote cache, no need to upload it again.\n return 'already-exist';\n }\n\n const result = await this.cacheClient.uploadFolder(options);\n\n if (result === 'success') {\n // The upload is successful, add the resource to the list.\n (await this.list).add(options.folderName);\n }\n\n return result;\n }\n\n async downloadFolder(options: RemoteCacheClientOperationOptions): Promise<RemoteCacheClientOperationResult> {\n if (!(await this.list).has(options.folderName)) {\n // This resource doesn't exist in the remote cache, can't download it.\n return 'not-found';\n }\n\n return this.cacheClient.downloadFolder(options);\n }\n}\n"]}
@@ -0,0 +1,10 @@
1
+ import { type TaskReporter } from '@ms-cloudpack/task-reporter';
2
+ import type { RemoteCacheClient, RemoteCacheClientOperationOptions } from '../types/RemoteCacheClient.js';
3
+ export declare class ReporterDecorator implements RemoteCacheClient {
4
+ private readonly client;
5
+ private readonly reporter;
6
+ constructor(client: RemoteCacheClient, reporter: TaskReporter);
7
+ uploadFolder(options: RemoteCacheClientOperationOptions): Promise<import("../types/RemoteCacheClient.js").RemoteCacheClientOperationResult>;
8
+ downloadFolder(options: RemoteCacheClientOperationOptions): Promise<import("../types/RemoteCacheClient.js").RemoteCacheClientOperationResult>;
9
+ }
10
+ //# sourceMappingURL=ReporterDecorator.d.ts.map
@@ -0,0 +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,EAAE,iBAAiB,EAAE,iCAAiC,EAAE,MAAM,+BAA+B,CAAC;AAE1G,qBAAa,iBAAkB,YAAW,iBAAiB;IAEvD,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBADR,MAAM,EAAE,iBAAiB,EACzB,QAAQ,EAAE,YAAY;IAGnC,YAAY,CAAC,OAAO,EAAE,iCAAiC;IAgCvD,cAAc,CAAC,OAAO,EAAE,iCAAiC;CA+BhE"}
@@ -0,0 +1,64 @@
1
+ import { bulletedList } from '@ms-cloudpack/task-reporter';
2
+ export class ReporterDecorator {
3
+ constructor(client, reporter) {
4
+ this.client = client;
5
+ this.reporter = reporter;
6
+ }
7
+ async uploadFolder(options) {
8
+ const { folderName, path, friendlyName } = options;
9
+ const task = this.reporter.addTask(`Uploading to remote cache: ${friendlyName}`);
10
+ const uploadResult = await this.client.uploadFolder(options);
11
+ switch (uploadResult) {
12
+ case 'success':
13
+ task.complete({
14
+ status: 'complete',
15
+ details: bulletedList([`FolderName: ${folderName}`, `Path: ${path}`, `Name: ${friendlyName}`]),
16
+ });
17
+ break;
18
+ case 'not-found':
19
+ task.complete({
20
+ status: 'skip',
21
+ message: `Not found in the local cache.`,
22
+ });
23
+ break;
24
+ case 'already-exist':
25
+ task.complete({
26
+ status: 'skip',
27
+ message: `Package is already exist in the remote cache.`,
28
+ });
29
+ break;
30
+ default:
31
+ throw new Error(`Unknown upload result: ${uploadResult}`);
32
+ }
33
+ return uploadResult;
34
+ }
35
+ async downloadFolder(options) {
36
+ const { folderName, path, friendlyName } = options;
37
+ const task = this.reporter.addTask(`Downloading from remote cache: ${friendlyName}`);
38
+ const downloadResult = await this.client.downloadFolder(options);
39
+ switch (downloadResult) {
40
+ case 'success':
41
+ task.complete({
42
+ status: 'complete',
43
+ details: bulletedList([`FolderName: ${folderName}`, `Path: ${path}`, `Name: ${friendlyName}`]),
44
+ });
45
+ break;
46
+ case 'not-found':
47
+ task.complete({
48
+ status: 'skip',
49
+ message: `Not found in the remote cache.`,
50
+ });
51
+ break;
52
+ case 'already-exist':
53
+ task.complete({
54
+ status: 'skip',
55
+ message: `Package is already exist in the local cache.`,
56
+ });
57
+ break;
58
+ default:
59
+ throw new Error(`Unknown download result: ${downloadResult}`);
60
+ }
61
+ return downloadResult;
62
+ }
63
+ }
64
+ //# 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,EAAqB,MAAM,6BAA6B,CAAC;AAG9E,MAAM,OAAO,iBAAiB;IAC5B,YACmB,MAAyB,EACzB,QAAsB;QADtB,WAAM,GAAN,MAAM,CAAmB;QACzB,aAAQ,GAAR,QAAQ,CAAc;IACtC,CAAC;IAEJ,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,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QAE7D,QAAQ,YAAY,EAAE;YACpB,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,+BAA+B;iBACzC,CAAC,CAAC;gBACH,MAAM;YACR,KAAK,eAAe;gBAClB,IAAI,CAAC,QAAQ,CAAC;oBACZ,MAAM,EAAE,MAAM;oBACd,OAAO,EAAE,+CAA+C;iBACzD,CAAC,CAAC;gBACH,MAAM;YACR;gBACE,MAAM,IAAI,KAAK,CAAC,0BAA0B,YAAY,EAAE,CAAC,CAAC;SAC7D;QAED,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,OAA0C;QAC7D,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;QACnD,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,kCAAkC,YAAY,EAAE,CAAC,CAAC;QAErF,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QAEjE,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 { RemoteCacheClient, RemoteCacheClientOperationOptions } 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 async uploadFolder(options: RemoteCacheClientOperationOptions) {\n const { folderName, path, friendlyName } = options;\n const task = this.reporter.addTask(`Uploading to remote cache: ${friendlyName}`);\n\n const uploadResult = await this.client.uploadFolder(options);\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 const downloadResult = await this.client.downloadFolder(options);\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"]}
@@ -0,0 +1,17 @@
1
+ import type { RemoteCacheClient, RemoteCacheClientOperationOptions, RemoteCacheClientOperationResult } from '../types/RemoteCacheClient.js';
2
+ import type { RetryManager } from '../retry/RetryManager.js';
3
+ /**
4
+ * A decorator that retries the upload/download operation if it fails.
5
+ */
6
+ export declare class RetryDecorator implements RemoteCacheClient {
7
+ private readonly cacheClient;
8
+ private readonly retryManager;
9
+ constructor(options: {
10
+ cacheClient: RemoteCacheClient;
11
+ retryManager: RetryManager;
12
+ });
13
+ private printRetryContext;
14
+ uploadFolder(options: RemoteCacheClientOperationOptions): Promise<RemoteCacheClientOperationResult>;
15
+ downloadFolder(options: RemoteCacheClientOperationOptions): Promise<RemoteCacheClientOperationResult>;
16
+ }
17
+ //# sourceMappingURL=RetryDecorator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RetryDecorator.d.ts","sourceRoot":"","sources":["../../src/decorators/RetryDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,iCAAiC,EACjC,gCAAgC,EACjC,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAE7D;;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,iCAAiC,GAAG,OAAO,CAAC,gCAAgC,CAAC;IAOnG,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":"AAOA;;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;YAChB,OAAO,CAAC,IAAI,CACV,YAAY,aAAa,IAAI,OAAO,CAAC,YAAY,SAAS,YAAY,CAAC,YAAY,IAAI,YAAY,CAAC,UAAU,GAAG,CAClH,CAAC;SACH;IACH,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,OAA0C;QAC3D,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 RemoteCacheClientOperationOptions,\n RemoteCacheClientOperationResult,\n} from '../types/RemoteCacheClient.js';\nimport type { RetryManager } from '../retry/RetryManager.js';\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: RemoteCacheClientOperationOptions): 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,6 @@
1
+ import type { RemoteCacheClientOptions } from './types/RemoteCacheClientOptions.js';
2
+ /**
3
+ * Gets all the blobs in the remote cache.
4
+ */
5
+ export declare function getListOfBlobs({ container, connectionString }: RemoteCacheClientOptions): Promise<Set<string>>;
6
+ //# sourceMappingURL=getListOfBlobs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getListOfBlobs.d.ts","sourceRoot":"","sources":["../src/getListOfBlobs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAGpF;;GAEG;AACH,wBAAsB,cAAc,CAAC,EAAE,SAAS,EAAE,gBAAgB,EAAE,EAAE,wBAAwB,wBAQ7F"}
@@ -0,0 +1,14 @@
1
+ import { BlobServiceClient } from '@azure/storage-blob';
2
+ /**
3
+ * Gets all the blobs in the remote cache.
4
+ */
5
+ export async function getListOfBlobs({ container, connectionString }) {
6
+ const blobStorageClient = BlobServiceClient.fromConnectionString(connectionString);
7
+ const containerClient = blobStorageClient.getContainerClient(container);
8
+ const blobs = new Set();
9
+ for await (const blob of containerClient.listBlobsFlat()) {
10
+ blobs.add(blob.name);
11
+ }
12
+ return blobs;
13
+ }
14
+ //# sourceMappingURL=getListOfBlobs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getListOfBlobs.js","sourceRoot":"","sources":["../src/getListOfBlobs.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,EAAE,SAAS,EAAE,gBAAgB,EAA4B;IAC5F,MAAM,iBAAiB,GAAG,iBAAiB,CAAC,oBAAoB,CAAC,gBAAgB,CAAC,CAAC;IACnF,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;QACxD,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;KACtB;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import 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, connectionString }: RemoteCacheClientOptions) {\n const blobStorageClient = BlobServiceClient.fromConnectionString(connectionString);\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"]}
package/lib/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export { syncToLocal } from './syncToLocal.js';
2
- export { syncToRemote } from './syncToRemote.js';
3
- export type { SyncContext } from './types/SyncContext.js';
4
- export type { PackageToSync } from './types/PackageToSync.js';
1
+ export { createRemoteCacheClient } from './createRemoteCacheClient.js';
2
+ export type { RemoteCacheClient, RemoteCacheClientOperationOptions, RemoteCacheClientOperationResult, } from './types/RemoteCacheClient.js';
3
+ export type { ConnectionStringOptions } from './types/ConnectionStringOptions.js';
4
+ export type { RemoteCacheClientOptions } from './types/RemoteCacheClientOptions.js';
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,YAAY,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAEvE,YAAY,EACV,iBAAiB,EACjB,iCAAiC,EACjC,gCAAgC,GACjC,MAAM,8BAA8B,CAAC;AACtC,YAAY,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAClF,YAAY,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC"}