@ms-cloudpack/remote-cache 0.5.2 → 0.5.4-beta.0

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 (79) hide show
  1. package/dist/AzureRemoteCacheClient-R5HCIW6L.js +65 -0
  2. package/dist/ReporterDecorator-SNBYNGOT.js +134 -0
  3. package/dist/chunk-4P62L7ZZ.js +1530 -0
  4. package/dist/chunk-KFSFZYG6.js +49961 -0
  5. package/dist/chunk-R2VDVRDZ.js +15 -0
  6. package/dist/chunk-TQLTL4XO.js +65 -0
  7. package/dist/getCredential-QMMPE77Q.js +24525 -0
  8. package/dist/getListOfBlobs-E5OFG2MF.js +29 -0
  9. package/dist/index.js +109 -0
  10. package/lib/decorators/InMemoryDecorator.test.d.ts +2 -0
  11. package/lib/decorators/RetryDecorator.test.d.ts +2 -0
  12. package/package.json +13 -12
  13. package/lib/AzureRemoteCacheClient.d.ts.map +0 -1
  14. package/lib/AzureRemoteCacheClient.js +0 -51
  15. package/lib/AzureRemoteCacheClient.js.map +0 -1
  16. package/lib/Task.d.ts.map +0 -1
  17. package/lib/Task.js +0 -2
  18. package/lib/Task.js.map +0 -1
  19. package/lib/authentication/getAuthenticationRecord.d.ts.map +0 -1
  20. package/lib/authentication/getAuthenticationRecord.js +0 -17
  21. package/lib/authentication/getAuthenticationRecord.js.map +0 -1
  22. package/lib/authentication/getAuthenticationRecordPath.d.ts.map +0 -1
  23. package/lib/authentication/getAuthenticationRecordPath.js +0 -10
  24. package/lib/authentication/getAuthenticationRecordPath.js.map +0 -1
  25. package/lib/authentication/getCredential.d.ts.map +0 -1
  26. package/lib/authentication/getCredential.js +0 -61
  27. package/lib/authentication/getCredential.js.map +0 -1
  28. package/lib/authentication/saveAuthenticationRecord.d.ts.map +0 -1
  29. package/lib/authentication/saveAuthenticationRecord.js +0 -17
  30. package/lib/authentication/saveAuthenticationRecord.js.map +0 -1
  31. package/lib/cache-persistance/cachePersistencePlugin.d.ts +0 -32
  32. package/lib/cache-persistance/cachePersistencePlugin.d.ts.map +0 -1
  33. package/lib/cache-persistance/cachePersistencePlugin.js +0 -35
  34. package/lib/cache-persistance/cachePersistencePlugin.js.map +0 -1
  35. package/lib/cache-persistance/platforms.d.ts +0 -55
  36. package/lib/cache-persistance/platforms.d.ts.map +0 -1
  37. package/lib/cache-persistance/platforms.js +0 -109
  38. package/lib/cache-persistance/platforms.js.map +0 -1
  39. package/lib/cache-persistance/provider.d.ts +0 -15
  40. package/lib/cache-persistance/provider.d.ts.map +0 -1
  41. package/lib/cache-persistance/provider.js +0 -26
  42. package/lib/cache-persistance/provider.js.map +0 -1
  43. package/lib/createBlobStorageUrl.d.ts.map +0 -1
  44. package/lib/createBlobStorageUrl.js +0 -4
  45. package/lib/createBlobStorageUrl.js.map +0 -1
  46. package/lib/createRemoteCacheClient.d.ts.map +0 -1
  47. package/lib/createRemoteCacheClient.js +0 -27
  48. package/lib/createRemoteCacheClient.js.map +0 -1
  49. package/lib/decorators/InMemoryDecorator.d.ts.map +0 -1
  50. package/lib/decorators/InMemoryDecorator.js +0 -29
  51. package/lib/decorators/InMemoryDecorator.js.map +0 -1
  52. package/lib/decorators/ReporterDecorator.d.ts.map +0 -1
  53. package/lib/decorators/ReporterDecorator.js +0 -126
  54. package/lib/decorators/ReporterDecorator.js.map +0 -1
  55. package/lib/decorators/RetryDecorator.d.ts.map +0 -1
  56. package/lib/decorators/RetryDecorator.js +0 -27
  57. package/lib/decorators/RetryDecorator.js.map +0 -1
  58. package/lib/getListOfBlobs.d.ts.map +0 -1
  59. package/lib/getListOfBlobs.js +0 -15
  60. package/lib/getListOfBlobs.js.map +0 -1
  61. package/lib/index.d.ts.map +0 -1
  62. package/lib/index.js +0 -2
  63. package/lib/index.js.map +0 -1
  64. package/lib/retry/blockListIsInvalidRetryPolicy.d.ts.map +0 -1
  65. package/lib/retry/blockListIsInvalidRetryPolicy.js +0 -8
  66. package/lib/retry/blockListIsInvalidRetryPolicy.js.map +0 -1
  67. package/lib/tsdoc-metadata.json +0 -11
  68. package/lib/types/LoginMethod.d.ts.map +0 -1
  69. package/lib/types/LoginMethod.js +0 -2
  70. package/lib/types/LoginMethod.js.map +0 -1
  71. package/lib/types/RemoteCacheClient.d.ts.map +0 -1
  72. package/lib/types/RemoteCacheClient.js +0 -2
  73. package/lib/types/RemoteCacheClient.js.map +0 -1
  74. package/lib/types/RemoteCacheClientOptions.d.ts.map +0 -1
  75. package/lib/types/RemoteCacheClientOptions.js +0 -2
  76. package/lib/types/RemoteCacheClientOptions.js.map +0 -1
  77. package/lib/types/RetryPolicy.d.ts.map +0 -1
  78. package/lib/types/RetryPolicy.js +0 -2
  79. package/lib/types/RetryPolicy.js.map +0 -1
@@ -0,0 +1,65 @@
1
+ import {
2
+ createBlobStorageUrl
3
+ } from "./chunk-R2VDVRDZ.js";
4
+ import {
5
+ __name,
6
+ init_esbuildCjsShims
7
+ } from "./chunk-TQLTL4XO.js";
8
+
9
+ // src/AzureRemoteCacheClient.ts
10
+ init_esbuildCjsShims();
11
+ import { makeLogger, put, fetch } from "backfill/lib/api.js";
12
+ import { existsSync } from "fs";
13
+ var _AzureRemoteCacheClient = class _AzureRemoteCacheClient {
14
+ constructor({ container, storageAccount, credential }) {
15
+ this.logger = makeLogger("mute", process.stdout, process.stderr);
16
+ this.config = {
17
+ incrementalCaching: true,
18
+ internalCacheFolder: "",
19
+ // not used by azure-blob
20
+ cacheStorageConfig: {
21
+ provider: "azure-blob",
22
+ options: {
23
+ connectionString: createBlobStorageUrl(storageAccount),
24
+ credential,
25
+ container
26
+ }
27
+ }
28
+ };
29
+ }
30
+ /**
31
+ * Uploads the folder to the remote cache.
32
+ * @param id - The unique identifier of the asset to upload.
33
+ * @param path - The path to the folder to upload.
34
+ * @param globMatches - The glob pattern to use when uploading the folder.
35
+ * @returns - A promise that resolves when the folder has been uploaded.
36
+ */
37
+ async uploadFolder({ id, path, globMatches }) {
38
+ if (!existsSync(path)) {
39
+ return "not-found";
40
+ }
41
+ await put(path, id, this.logger, { ...this.config, outputGlob: globMatches });
42
+ return "success";
43
+ }
44
+ /**
45
+ * Downloads the folder from the remote cache.
46
+ * @param id - The unique identifier of the asset to download.
47
+ * @param path - The path to download the folder to.
48
+ * @returns - A promise that resolves when the folder has been downloaded.
49
+ */
50
+ async downloadFolder({ id, path }) {
51
+ if (existsSync(path)) {
52
+ return "already-exist";
53
+ }
54
+ const result = await fetch(path, id, this.logger, this.config);
55
+ if (!result) {
56
+ return "not-found";
57
+ }
58
+ return "success";
59
+ }
60
+ };
61
+ __name(_AzureRemoteCacheClient, "AzureRemoteCacheClient");
62
+ var AzureRemoteCacheClient = _AzureRemoteCacheClient;
63
+ export {
64
+ AzureRemoteCacheClient
65
+ };
@@ -0,0 +1,134 @@
1
+ import {
2
+ require_dist
3
+ } from "./chunk-KFSFZYG6.js";
4
+ import "./chunk-4P62L7ZZ.js";
5
+ import {
6
+ __name,
7
+ __toESM,
8
+ init_esbuildCjsShims
9
+ } from "./chunk-TQLTL4XO.js";
10
+
11
+ // src/decorators/ReporterDecorator.ts
12
+ init_esbuildCjsShims();
13
+ var import_storage_blob = __toESM(require_dist(), 1);
14
+ import { bulletedList } from "@ms-cloudpack/task-reporter";
15
+ var isAuthErrorReported = false;
16
+ function reportError(telemetryClient, error) {
17
+ const isAuthError = error instanceof import_storage_blob.RestError && error.statusCode === 403;
18
+ if (isAuthError && isAuthErrorReported) {
19
+ return;
20
+ }
21
+ telemetryClient.rootSpan.recordException(error);
22
+ isAuthErrorReported = isAuthError;
23
+ }
24
+ __name(reportError, "reportError");
25
+ var _ReporterDecorator = class _ReporterDecorator {
26
+ constructor(client, context) {
27
+ this.client = client;
28
+ this.context = context;
29
+ }
30
+ buildFailureResult({ id, friendlyName, path }, error) {
31
+ const list = bulletedList([
32
+ `Id: ${id}`,
33
+ `Path: ${path}`,
34
+ `Name: ${friendlyName}`,
35
+ `Error: ${error instanceof Error ? error.message : String(error)}`
36
+ ]);
37
+ const result = {
38
+ status: "fail",
39
+ message: `
40
+ ${list}`
41
+ };
42
+ if (error instanceof Error && error.stack) {
43
+ result.details = error.stack.includes(error.message) ? error.stack.split(error.message)[1] : error.stack;
44
+ }
45
+ return result;
46
+ }
47
+ async uploadFolder(options) {
48
+ const { id, path, friendlyName } = options;
49
+ const task = this.context.reporter.addTask(`Uploading to remote cache: ${friendlyName}`);
50
+ let uploadResult;
51
+ try {
52
+ uploadResult = await this.client.uploadFolder(options);
53
+ } catch (e) {
54
+ task.complete(this.buildFailureResult(options, e));
55
+ if (e instanceof Error) {
56
+ reportError(this.context.telemetryClient, e);
57
+ e.stack = void 0;
58
+ }
59
+ throw e;
60
+ }
61
+ const details = bulletedList([`Id: ${id}`, `Path: ${path}`, `Name: ${friendlyName}`]);
62
+ switch (uploadResult) {
63
+ case "success":
64
+ task.complete({
65
+ status: "complete",
66
+ details
67
+ });
68
+ break;
69
+ case "not-found":
70
+ task.complete({
71
+ status: "skip",
72
+ message: `Not found in the local cache.`,
73
+ details
74
+ });
75
+ break;
76
+ case "already-exist":
77
+ task.complete({
78
+ status: "skip",
79
+ message: `Package is already exist in the remote cache.`,
80
+ details
81
+ });
82
+ break;
83
+ default:
84
+ throw new Error(`Unknown upload result: ${uploadResult}`);
85
+ }
86
+ return uploadResult;
87
+ }
88
+ async downloadFolder(options) {
89
+ const { id, path, friendlyName } = options;
90
+ const task = this.context.reporter.addTask(`Downloading from remote cache: ${friendlyName}`);
91
+ let downloadResult;
92
+ try {
93
+ downloadResult = await this.client.downloadFolder(options);
94
+ } catch (e) {
95
+ task.complete(this.buildFailureResult(options, e));
96
+ if (e instanceof Error) {
97
+ reportError(this.context.telemetryClient, e);
98
+ e.stack = void 0;
99
+ }
100
+ throw e;
101
+ }
102
+ const details = bulletedList([`Id: ${id}`, `Path: ${path}`, `Name: ${friendlyName}`]);
103
+ switch (downloadResult) {
104
+ case "success":
105
+ task.complete({
106
+ status: "complete",
107
+ details
108
+ });
109
+ break;
110
+ case "not-found":
111
+ task.complete({
112
+ status: "skip",
113
+ message: `Not found in the remote cache.`,
114
+ details
115
+ });
116
+ break;
117
+ case "already-exist":
118
+ task.complete({
119
+ status: "skip",
120
+ message: `Package is already exist in the local cache.`,
121
+ details
122
+ });
123
+ break;
124
+ default:
125
+ throw new Error(`Unknown download result: ${downloadResult}`);
126
+ }
127
+ return downloadResult;
128
+ }
129
+ };
130
+ __name(_ReporterDecorator, "ReporterDecorator");
131
+ var ReporterDecorator = _ReporterDecorator;
132
+ export {
133
+ ReporterDecorator
134
+ };