@vercel/sandbox 1.9.0 → 1.9.1
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/README.md +8 -0
- package/dist/_virtual/rolldown_runtime.cjs +29 -0
- package/dist/api-client/api-client.cjs +375 -0
- package/dist/api-client/api-client.cjs.map +1 -0
- package/dist/api-client/api-client.d.cts +403 -0
- package/dist/api-client/api-client.d.ts +397 -392
- package/dist/api-client/api-client.js +365 -405
- package/dist/api-client/api-client.js.map +1 -1
- package/dist/api-client/api-error.cjs +31 -0
- package/dist/api-client/api-error.cjs.map +1 -0
- package/dist/api-client/api-error.d.cts +27 -0
- package/dist/api-client/api-error.d.ts +19 -16
- package/dist/api-client/api-error.js +27 -32
- package/dist/api-client/api-error.js.map +1 -1
- package/dist/api-client/base-client.cjs +113 -0
- package/dist/api-client/base-client.cjs.map +1 -0
- package/dist/api-client/base-client.d.cts +38 -0
- package/dist/api-client/base-client.d.ts +31 -36
- package/dist/api-client/base-client.js +101 -118
- package/dist/api-client/base-client.js.map +1 -1
- package/dist/api-client/file-writer.cjs +62 -0
- package/dist/api-client/file-writer.cjs.map +1 -0
- package/dist/api-client/file-writer.d.cts +66 -0
- package/dist/api-client/file-writer.d.ts +56 -52
- package/dist/api-client/file-writer.js +57 -61
- package/dist/api-client/file-writer.js.map +1 -1
- package/dist/api-client/index.cjs +2 -0
- package/dist/api-client/index.d.ts +2 -2
- package/dist/api-client/index.js +4 -21
- package/dist/api-client/validators.cjs +149 -0
- package/dist/api-client/validators.cjs.map +1 -0
- package/dist/api-client/validators.d.cts +1677 -0
- package/dist/api-client/validators.d.ts +1501 -2412
- package/dist/api-client/validators.js +124 -154
- package/dist/api-client/validators.js.map +1 -1
- package/dist/api-client/with-retry.cjs +89 -0
- package/dist/api-client/with-retry.cjs.map +1 -0
- package/dist/api-client/with-retry.d.cts +10 -0
- package/dist/api-client/with-retry.d.ts +9 -13
- package/dist/api-client/with-retry.js +81 -102
- package/dist/api-client/with-retry.js.map +1 -1
- package/dist/auth/api.cjs +29 -0
- package/dist/auth/api.cjs.map +1 -0
- package/dist/auth/api.js +26 -25
- package/dist/auth/api.js.map +1 -1
- package/dist/auth/error.cjs +13 -0
- package/dist/auth/error.cjs.map +1 -0
- package/dist/auth/error.js +11 -11
- package/dist/auth/error.js.map +1 -1
- package/dist/auth/file.cjs +64 -0
- package/dist/auth/file.cjs.map +1 -0
- package/dist/auth/file.d.cts +26 -0
- package/dist/auth/file.d.ts +19 -15
- package/dist/auth/file.js +49 -64
- package/dist/auth/file.js.map +1 -1
- package/dist/auth/index.cjs +12 -0
- package/dist/auth/index.d.cts +5 -0
- package/dist/auth/index.d.ts +5 -6
- package/dist/auth/index.js +6 -27
- package/dist/auth/linked-project.cjs +38 -0
- package/dist/auth/linked-project.cjs.map +1 -0
- package/dist/auth/linked-project.js +30 -64
- package/dist/auth/linked-project.js.map +1 -1
- package/dist/auth/oauth.cjs +205 -0
- package/dist/auth/oauth.cjs.map +1 -0
- package/dist/auth/oauth.d.cts +135 -0
- package/dist/auth/oauth.d.ts +113 -109
- package/dist/auth/oauth.js +185 -252
- package/dist/auth/oauth.js.map +1 -1
- package/dist/auth/poll-for-token.cjs +82 -0
- package/dist/auth/poll-for-token.cjs.map +1 -0
- package/dist/auth/poll-for-token.d.cts +28 -0
- package/dist/auth/poll-for-token.d.ts +23 -15
- package/dist/auth/poll-for-token.js +79 -64
- package/dist/auth/poll-for-token.js.map +1 -1
- package/dist/auth/project.cjs +80 -0
- package/dist/auth/project.cjs.map +1 -0
- package/dist/auth/project.d.cts +44 -0
- package/dist/auth/project.d.ts +12 -8
- package/dist/auth/project.js +70 -72
- package/dist/auth/project.js.map +1 -1
- package/dist/auth/zod.cjs +22 -0
- package/dist/auth/zod.cjs.map +1 -0
- package/dist/auth/zod.js +18 -17
- package/dist/auth/zod.js.map +1 -1
- package/dist/command.cjs +326 -0
- package/dist/command.cjs.map +1 -0
- package/dist/command.d.cts +289 -0
- package/dist/command.d.ts +265 -171
- package/dist/command.js +321 -226
- package/dist/command.js.map +1 -1
- package/dist/constants.d.cts +5 -0
- package/dist/constants.d.ts +5 -1
- package/dist/index.cjs +11 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -5
- package/dist/index.js +6 -15
- package/dist/network-policy.d.cts +100 -0
- package/dist/network-policy.d.ts +32 -28
- package/dist/sandbox.cjs +543 -0
- package/dist/sandbox.cjs.map +1 -0
- package/dist/sandbox.d.cts +538 -0
- package/dist/sandbox.d.ts +521 -479
- package/dist/sandbox.js +539 -512
- package/dist/sandbox.js.map +1 -1
- package/dist/snapshot.cjs +116 -0
- package/dist/snapshot.cjs.map +1 -0
- package/dist/snapshot.d.cts +109 -0
- package/dist/snapshot.d.ts +100 -92
- package/dist/snapshot.js +114 -114
- package/dist/snapshot.js.map +1 -1
- package/dist/utils/array.cjs +17 -0
- package/dist/utils/array.cjs.map +1 -0
- package/dist/utils/array.js +12 -15
- package/dist/utils/array.js.map +1 -1
- package/dist/utils/consume-readable.cjs +18 -0
- package/dist/utils/consume-readable.cjs.map +1 -0
- package/dist/utils/consume-readable.js +13 -12
- package/dist/utils/consume-readable.js.map +1 -1
- package/dist/utils/decode-base64-url.cjs +15 -0
- package/dist/utils/decode-base64-url.cjs.map +1 -0
- package/dist/utils/decode-base64-url.js +10 -9
- package/dist/utils/decode-base64-url.js.map +1 -1
- package/dist/utils/dev-credentials.cjs +142 -0
- package/dist/utils/dev-credentials.cjs.map +1 -0
- package/dist/utils/dev-credentials.js +126 -184
- package/dist/utils/dev-credentials.js.map +1 -1
- package/dist/utils/get-credentials.cjs +123 -0
- package/dist/utils/get-credentials.cjs.map +1 -0
- package/dist/utils/get-credentials.d.cts +21 -0
- package/dist/utils/get-credentials.d.ts +19 -61
- package/dist/utils/get-credentials.js +106 -140
- package/dist/utils/get-credentials.js.map +1 -1
- package/dist/utils/log.cjs +25 -0
- package/dist/utils/log.cjs.map +1 -0
- package/dist/utils/log.js +15 -17
- package/dist/utils/log.js.map +1 -1
- package/dist/utils/network-policy.cjs +65 -0
- package/dist/utils/network-policy.cjs.map +1 -0
- package/dist/utils/network-policy.js +58 -77
- package/dist/utils/network-policy.js.map +1 -1
- package/dist/utils/normalizePath.cjs +27 -0
- package/dist/utils/normalizePath.cjs.map +1 -0
- package/dist/utils/normalizePath.js +21 -28
- package/dist/utils/normalizePath.js.map +1 -1
- package/dist/utils/resolveSignal.cjs +20 -0
- package/dist/utils/resolveSignal.cjs.map +1 -0
- package/dist/utils/resolveSignal.d.cts +15 -0
- package/dist/utils/resolveSignal.d.ts +12 -10
- package/dist/utils/resolveSignal.js +14 -17
- package/dist/utils/resolveSignal.js.map +1 -1
- package/dist/utils/sandbox-snapshot.cjs +14 -0
- package/dist/utils/sandbox-snapshot.cjs.map +1 -0
- package/dist/utils/sandbox-snapshot.d.cts +10 -0
- package/dist/utils/sandbox-snapshot.d.ts +11 -0
- package/dist/utils/sandbox-snapshot.js +14 -0
- package/dist/utils/sandbox-snapshot.js.map +1 -0
- package/dist/utils/types.cjs +13 -0
- package/dist/utils/types.cjs.map +1 -0
- package/dist/utils/types.d.cts +11 -0
- package/dist/utils/types.d.ts +5 -7
- package/dist/utils/types.js +8 -8
- package/dist/utils/types.js.map +1 -1
- package/dist/version.cjs +7 -0
- package/dist/version.cjs.map +1 -0
- package/dist/version.js +5 -5
- package/dist/version.js.map +1 -1
- package/package.json +23 -3
- package/dist/api-client/index.js.map +0 -1
- package/dist/auth/api.d.ts +0 -6
- package/dist/auth/error.d.ts +0 -11
- package/dist/auth/index.js.map +0 -1
- package/dist/auth/linked-project.d.ts +0 -10
- package/dist/auth/zod.d.ts +0 -5
- package/dist/constants.js +0 -3
- package/dist/constants.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/network-policy.js +0 -3
- package/dist/network-policy.js.map +0 -1
- package/dist/utils/array.d.ts +0 -9
- package/dist/utils/consume-readable.d.ts +0 -5
- package/dist/utils/convert-sandbox.d.ts +0 -6
- package/dist/utils/convert-sandbox.js +0 -14
- package/dist/utils/convert-sandbox.js.map +0 -1
- package/dist/utils/decode-base64-url.d.ts +0 -7
- package/dist/utils/dev-credentials.d.ts +0 -37
- package/dist/utils/log.d.ts +0 -2
- package/dist/utils/network-policy.d.ts +0 -7
- package/dist/utils/normalizePath.d.ts +0 -17
- package/dist/version.d.ts +0 -1
|
@@ -1,128 +1,111 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const array_1 = require("../utils/array");
|
|
8
|
-
const with_retry_1 = require("./with-retry");
|
|
9
|
-
const undici_1 = require("undici");
|
|
1
|
+
import { APIError } from "./api-error.js";
|
|
2
|
+
import { array } from "../utils/array.js";
|
|
3
|
+
import { withRetry } from "./with-retry.js";
|
|
4
|
+
import { Agent } from "undici";
|
|
5
|
+
|
|
6
|
+
//#region src/api-client/base-client.ts
|
|
10
7
|
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
console.warn(`[API] ${url} Rate Limited, Retry After ${hours}h ${minutes}m ${seconds}s`);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return response;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
exports.BaseClient = BaseClient;
|
|
8
|
+
* A base API client that provides a convenience wrapper for fetching where
|
|
9
|
+
* we can pass query parameters as an object, support retries, debugging
|
|
10
|
+
* and automatic authorization.
|
|
11
|
+
*/
|
|
12
|
+
var BaseClient = class {
|
|
13
|
+
constructor(params) {
|
|
14
|
+
this.fetch = withRetry(params.fetch ?? globalThis.fetch);
|
|
15
|
+
this.baseUrl = params.baseUrl;
|
|
16
|
+
this.debug = params.debug ?? process.env.DEBUG_FETCH === "true";
|
|
17
|
+
this.token = params.token;
|
|
18
|
+
this.agent = new Agent({ bodyTimeout: 0 });
|
|
19
|
+
}
|
|
20
|
+
async request(path, opts) {
|
|
21
|
+
const url = new URL(`${this.baseUrl}${path}`);
|
|
22
|
+
if (opts?.query) for (const [key, value] of Object.entries(opts.query)) array(value).forEach((value$1) => {
|
|
23
|
+
url.searchParams.append(key, value$1.toString());
|
|
24
|
+
});
|
|
25
|
+
const start = Date.now();
|
|
26
|
+
const response = await this.fetch(url.toString(), {
|
|
27
|
+
...opts,
|
|
28
|
+
body: opts?.body,
|
|
29
|
+
method: opts?.method || "GET",
|
|
30
|
+
headers: this.token ? {
|
|
31
|
+
Authorization: `Bearer ${this.token}`,
|
|
32
|
+
...opts?.headers
|
|
33
|
+
} : opts?.headers,
|
|
34
|
+
dispatcher: this.agent,
|
|
35
|
+
signal: opts?.signal
|
|
36
|
+
});
|
|
37
|
+
if (this.debug) {
|
|
38
|
+
const duration = Date.now() - start;
|
|
39
|
+
console.log(`[API] ${url} (${response.status}) ${duration}ms`);
|
|
40
|
+
if (response.status === 429) {
|
|
41
|
+
const retry = parseInt(response.headers.get("Retry-After") ?? "", 10);
|
|
42
|
+
const hours = Math.floor(retry / 60 / 60);
|
|
43
|
+
const minutes = Math.floor(retry / 60) % 60;
|
|
44
|
+
const seconds = retry % 60;
|
|
45
|
+
console.warn(`[API] ${url} Rate Limited, Retry After ${hours}h ${minutes}m ${seconds}s`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return response;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
61
51
|
/**
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
52
|
+
* Extract sandboxId from a sandbox API URL.
|
|
53
|
+
* URLs follow the pattern: /v1/sandboxes/{sandboxId}/...
|
|
54
|
+
*/
|
|
65
55
|
function extractSandboxId(url) {
|
|
66
|
-
|
|
67
|
-
return match?.[1];
|
|
56
|
+
return url.match(/\/v1\/sandboxes\/([^/?]+)/)?.[1];
|
|
68
57
|
}
|
|
69
58
|
/**
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
59
|
+
* Allows to read the response text and parse it as JSON casting to the given
|
|
60
|
+
* type. If the response is not ok or cannot be parsed it will return error.
|
|
61
|
+
*
|
|
62
|
+
* @param response Response to parse.
|
|
63
|
+
* @returns Parsed response or error.
|
|
64
|
+
*/
|
|
76
65
|
async function parse(validator, response) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
return {
|
|
116
|
-
json: validated.data,
|
|
117
|
-
response,
|
|
118
|
-
text,
|
|
119
|
-
};
|
|
66
|
+
const sandboxId = extractSandboxId(response.url);
|
|
67
|
+
const text = await response.text().catch((err) => {
|
|
68
|
+
return new APIError(response, {
|
|
69
|
+
message: `Can't read response text: ${String(err)}`,
|
|
70
|
+
sandboxId
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
if (typeof text !== "string") return text;
|
|
74
|
+
let json;
|
|
75
|
+
try {
|
|
76
|
+
json = JSON.parse(text || "{}");
|
|
77
|
+
} catch (error) {
|
|
78
|
+
return new APIError(response, {
|
|
79
|
+
message: `Can't parse JSON: ${String(error)}`,
|
|
80
|
+
text,
|
|
81
|
+
sandboxId
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
if (!response.ok) return new APIError(response, {
|
|
85
|
+
message: `Status code ${response.status} is not ok`,
|
|
86
|
+
json,
|
|
87
|
+
text,
|
|
88
|
+
sandboxId
|
|
89
|
+
});
|
|
90
|
+
const validated = validator.safeParse(json);
|
|
91
|
+
if (!validated.success) return new APIError(response, {
|
|
92
|
+
message: `Response JSON is not valid: ${validated.error}`,
|
|
93
|
+
json,
|
|
94
|
+
text,
|
|
95
|
+
sandboxId
|
|
96
|
+
});
|
|
97
|
+
return {
|
|
98
|
+
json: validated.data,
|
|
99
|
+
response,
|
|
100
|
+
text
|
|
101
|
+
};
|
|
120
102
|
}
|
|
121
103
|
async function parseOrThrow(validator, response) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
return result;
|
|
104
|
+
const result = await parse(validator, response);
|
|
105
|
+
if (result instanceof APIError) throw result;
|
|
106
|
+
return result;
|
|
127
107
|
}
|
|
108
|
+
|
|
109
|
+
//#endregion
|
|
110
|
+
export { BaseClient, parseOrThrow };
|
|
128
111
|
//# sourceMappingURL=base-client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-client.js","
|
|
1
|
+
{"version":3,"file":"base-client.js","names":["value","json: Data | ErrorData"],"sources":["../../src/api-client/base-client.ts"],"sourcesContent":["import type { Options as RetryOptions } from \"async-retry\";\nimport { APIError } from \"./api-error.js\";\nimport { ZodType } from \"zod\";\nimport { array } from \"../utils/array.js\";\nimport { withRetry, type RequestOptions } from \"./with-retry.js\";\nimport { Agent } from \"undici\";\n\nexport interface RequestParams extends RequestInit {\n headers?: Record<string, string>;\n method?: string;\n onRetry?(error: any, options: RequestOptions): void;\n query?: Record<string, number | string | null | undefined | string[]>;\n retry?: Partial<RetryOptions>;\n}\n\n/**\n * A base API client that provides a convenience wrapper for fetching where\n * we can pass query parameters as an object, support retries, debugging\n * and automatic authorization.\n */\nexport class BaseClient {\n protected token?: string;\n private fetch: ReturnType<typeof withRetry<RequestInit>>;\n private debug: boolean;\n private baseUrl: string;\n private agent: Agent;\n\n constructor(params: {\n debug?: boolean;\n baseUrl: string;\n token?: string;\n fetch?: typeof globalThis.fetch;\n }) {\n this.fetch = withRetry(params.fetch ?? globalThis.fetch);\n this.baseUrl = params.baseUrl;\n this.debug = params.debug ?? process.env.DEBUG_FETCH === \"true\";\n this.token = params.token;\n this.agent = new Agent({\n bodyTimeout: 0, // disable body timeout to allow long logs streaming\n });\n }\n\n protected async request(path: string, opts?: RequestParams) {\n const url = new URL(`${this.baseUrl}${path}`);\n if (opts?.query) {\n for (const [key, value] of Object.entries(opts.query)) {\n array(value).forEach((value) => {\n url.searchParams.append(key, value.toString());\n });\n }\n }\n\n const start = Date.now();\n const response = await this.fetch(url.toString(), {\n ...opts,\n body: opts?.body,\n method: opts?.method || \"GET\",\n headers: this.token\n ? { Authorization: `Bearer ${this.token}`, ...opts?.headers }\n : opts?.headers,\n // @ts-expect-error Node.js' and undici's Agent have different types\n dispatcher: this.agent,\n signal: opts?.signal,\n });\n\n if (this.debug) {\n const duration = Date.now() - start;\n console.log(`[API] ${url} (${response.status}) ${duration}ms`);\n if (response.status === 429) {\n const retry = parseInt(response.headers.get(\"Retry-After\") ?? \"\", 10);\n const hours = Math.floor(retry / 60 / 60);\n const minutes = Math.floor(retry / 60) % 60;\n const seconds = retry % 60;\n console.warn(\n `[API] ${url} Rate Limited, Retry After ${hours}h ${minutes}m ${seconds}s`,\n );\n }\n }\n\n return response;\n }\n}\n\nexport interface Parsed<Data> {\n response: Response;\n text: string;\n json: Data;\n}\n\n/**\n * Extract sandboxId from a sandbox API URL.\n * URLs follow the pattern: /v1/sandboxes/{sandboxId}/...\n */\nfunction extractSandboxId(url: string): string | undefined {\n const match = url.match(/\\/v1\\/sandboxes\\/([^/?]+)/);\n return match?.[1];\n}\n\n/**\n * Allows to read the response text and parse it as JSON casting to the given\n * type. If the response is not ok or cannot be parsed it will return error.\n *\n * @param response Response to parse.\n * @returns Parsed response or error.\n */\nexport async function parse<Data, ErrorData>(\n validator: ZodType<Data>,\n response: Response,\n): Promise<Parsed<Data> | APIError<ErrorData>> {\n const sandboxId = extractSandboxId(response.url);\n\n const text = await response.text().catch((err) => {\n return new APIError<ErrorData>(response, {\n message: `Can't read response text: ${String(err)}`,\n sandboxId,\n });\n });\n\n if (typeof text !== \"string\") {\n return text;\n }\n\n let json: Data | ErrorData;\n\n try {\n json = JSON.parse(text || \"{}\");\n } catch (error) {\n return new APIError<ErrorData>(response, {\n message: `Can't parse JSON: ${String(error)}`,\n text,\n sandboxId,\n });\n }\n\n if (!response.ok) {\n return new APIError<ErrorData>(response, {\n message: `Status code ${response.status} is not ok`,\n json: json as ErrorData,\n text,\n sandboxId,\n });\n }\n\n const validated = validator.safeParse(json);\n if (!validated.success) {\n return new APIError<ErrorData>(response, {\n message: `Response JSON is not valid: ${validated.error}`,\n json: json as ErrorData,\n text,\n sandboxId,\n });\n }\n\n return {\n json: validated.data,\n response,\n text,\n };\n}\n\nexport async function parseOrThrow<Data, ErrorData>(\n validator: ZodType<Data>,\n response: Response,\n): Promise<Parsed<Data>> {\n const result = await parse<Data, ErrorData>(validator, response);\n if (result instanceof APIError) {\n throw result;\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;AAoBA,IAAa,aAAb,MAAwB;CAOtB,YAAY,QAKT;AACD,OAAK,QAAQ,UAAU,OAAO,SAAS,WAAW,MAAM;AACxD,OAAK,UAAU,OAAO;AACtB,OAAK,QAAQ,OAAO,SAAS,QAAQ,IAAI,gBAAgB;AACzD,OAAK,QAAQ,OAAO;AACpB,OAAK,QAAQ,IAAI,MAAM,EACrB,aAAa,GACd,CAAC;;CAGJ,MAAgB,QAAQ,MAAc,MAAsB;EAC1D,MAAM,MAAM,IAAI,IAAI,GAAG,KAAK,UAAU,OAAO;AAC7C,MAAI,MAAM,MACR,MAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,KAAK,MAAM,CACnD,OAAM,MAAM,CAAC,SAAS,YAAU;AAC9B,OAAI,aAAa,OAAO,KAAKA,QAAM,UAAU,CAAC;IAC9C;EAIN,MAAM,QAAQ,KAAK,KAAK;EACxB,MAAM,WAAW,MAAM,KAAK,MAAM,IAAI,UAAU,EAAE;GAChD,GAAG;GACH,MAAM,MAAM;GACZ,QAAQ,MAAM,UAAU;GACxB,SAAS,KAAK,QACV;IAAE,eAAe,UAAU,KAAK;IAAS,GAAG,MAAM;IAAS,GAC3D,MAAM;GAEV,YAAY,KAAK;GACjB,QAAQ,MAAM;GACf,CAAC;AAEF,MAAI,KAAK,OAAO;GACd,MAAM,WAAW,KAAK,KAAK,GAAG;AAC9B,WAAQ,IAAI,SAAS,IAAI,IAAI,SAAS,OAAO,IAAI,SAAS,IAAI;AAC9D,OAAI,SAAS,WAAW,KAAK;IAC3B,MAAM,QAAQ,SAAS,SAAS,QAAQ,IAAI,cAAc,IAAI,IAAI,GAAG;IACrE,MAAM,QAAQ,KAAK,MAAM,QAAQ,KAAK,GAAG;IACzC,MAAM,UAAU,KAAK,MAAM,QAAQ,GAAG,GAAG;IACzC,MAAM,UAAU,QAAQ;AACxB,YAAQ,KACN,SAAS,IAAI,6BAA6B,MAAM,IAAI,QAAQ,IAAI,QAAQ,GACzE;;;AAIL,SAAO;;;;;;;AAcX,SAAS,iBAAiB,KAAiC;AAEzD,QADc,IAAI,MAAM,4BAA4B,GACrC;;;;;;;;;AAUjB,eAAsB,MACpB,WACA,UAC6C;CAC7C,MAAM,YAAY,iBAAiB,SAAS,IAAI;CAEhD,MAAM,OAAO,MAAM,SAAS,MAAM,CAAC,OAAO,QAAQ;AAChD,SAAO,IAAI,SAAoB,UAAU;GACvC,SAAS,6BAA6B,OAAO,IAAI;GACjD;GACD,CAAC;GACF;AAEF,KAAI,OAAO,SAAS,SAClB,QAAO;CAGT,IAAIC;AAEJ,KAAI;AACF,SAAO,KAAK,MAAM,QAAQ,KAAK;UACxB,OAAO;AACd,SAAO,IAAI,SAAoB,UAAU;GACvC,SAAS,qBAAqB,OAAO,MAAM;GAC3C;GACA;GACD,CAAC;;AAGJ,KAAI,CAAC,SAAS,GACZ,QAAO,IAAI,SAAoB,UAAU;EACvC,SAAS,eAAe,SAAS,OAAO;EAClC;EACN;EACA;EACD,CAAC;CAGJ,MAAM,YAAY,UAAU,UAAU,KAAK;AAC3C,KAAI,CAAC,UAAU,QACb,QAAO,IAAI,SAAoB,UAAU;EACvC,SAAS,+BAA+B,UAAU;EAC5C;EACN;EACA;EACD,CAAC;AAGJ,QAAO;EACL,MAAM,UAAU;EAChB;EACA;EACD;;AAGH,eAAsB,aACpB,WACA,UACuB;CACvB,MAAM,SAAS,MAAM,MAAuB,WAAW,SAAS;AAChE,KAAI,kBAAkB,SACpB,OAAM;AAGR,QAAO"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let zlib = require("zlib");
|
|
3
|
+
zlib = require_rolldown_runtime.__toESM(zlib);
|
|
4
|
+
let tar_stream = require("tar-stream");
|
|
5
|
+
tar_stream = require_rolldown_runtime.__toESM(tar_stream);
|
|
6
|
+
let stream = require("stream");
|
|
7
|
+
|
|
8
|
+
//#region src/api-client/file-writer.ts
|
|
9
|
+
/**
|
|
10
|
+
* Allows to create a Readable stream with methods to write files
|
|
11
|
+
* to it and to finish it. Files written are compressed together
|
|
12
|
+
* and gzipped in the stream.
|
|
13
|
+
*/
|
|
14
|
+
var FileWriter = class {
|
|
15
|
+
constructor() {
|
|
16
|
+
const gzip = zlib.default.createGzip();
|
|
17
|
+
this.pack = tar_stream.default.pack();
|
|
18
|
+
this.readable = this.pack.pipe(gzip);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Allows to add a file to the stream. Size is required to write
|
|
22
|
+
* the tarball header so when content is a stream it must be
|
|
23
|
+
* provided.
|
|
24
|
+
*
|
|
25
|
+
* Returns a Promise resolved once the file is written in the
|
|
26
|
+
* stream.
|
|
27
|
+
*/
|
|
28
|
+
async addFile(file) {
|
|
29
|
+
return new Promise((resolve, reject) => {
|
|
30
|
+
const entry = this.pack.entry("size" in file ? {
|
|
31
|
+
name: file.name,
|
|
32
|
+
size: file.size,
|
|
33
|
+
mode: file.mode
|
|
34
|
+
} : {
|
|
35
|
+
name: file.name,
|
|
36
|
+
size: Buffer.byteLength(file.content),
|
|
37
|
+
mode: file.mode
|
|
38
|
+
}, (error) => {
|
|
39
|
+
if (error) return reject(error);
|
|
40
|
+
else resolve();
|
|
41
|
+
});
|
|
42
|
+
if (file.content instanceof stream.Readable) file.content.pipe(entry);
|
|
43
|
+
else entry.end(file.content);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Allows to finish the stream returning a Promise that will
|
|
48
|
+
* resolve once the readable is effectively closed or
|
|
49
|
+
* errored.
|
|
50
|
+
*/
|
|
51
|
+
async end() {
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
this.readable.on("error", reject);
|
|
54
|
+
this.readable.on("end", resolve);
|
|
55
|
+
this.pack.finalize();
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
//#endregion
|
|
61
|
+
exports.FileWriter = FileWriter;
|
|
62
|
+
//# sourceMappingURL=file-writer.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-writer.cjs","names":["tar","Readable"],"sources":["../../src/api-client/file-writer.ts"],"sourcesContent":["import zlib from \"zlib\";\nimport tar, { type Pack } from \"tar-stream\";\nimport { Readable } from \"stream\";\n\ninterface FileData {\n /**\n * The name (path) of the file to write.\n */\n name: string;\n /**\n * The content of the file.\n */\n content: string | Uint8Array;\n /**\n * The file mode (permissions) to set on the file.\n * For example, 0o755 for executable files.\n */\n mode?: number;\n}\n\ninterface FileStream {\n /**\n * The name (path) of the file to write.\n */\n name: string;\n /**\n * A Readable stream to consume the content of the file.\n */\n content: Readable;\n /**\n * The expected size of the file. This is required to write\n * the header of the compressed file.\n */\n size: number;\n /**\n * The file mode (permissions) to set on the file.\n * For example, 0o755 for executable files.\n */\n mode?: number;\n}\n\n/**\n * Allows to create a Readable stream with methods to write files\n * to it and to finish it. Files written are compressed together\n * and gzipped in the stream.\n */\nexport class FileWriter {\n public readable: Readable;\n private pack: Pack;\n\n constructor() {\n const gzip = zlib.createGzip();\n this.pack = tar.pack();\n this.readable = this.pack.pipe(gzip);\n }\n\n /**\n * Allows to add a file to the stream. Size is required to write\n * the tarball header so when content is a stream it must be\n * provided.\n *\n * Returns a Promise resolved once the file is written in the\n * stream.\n */\n async addFile(file: FileData | FileStream) {\n return new Promise<void>((resolve, reject) => {\n const entry = this.pack.entry(\n \"size\" in file\n ? { name: file.name, size: file.size, mode: file.mode }\n : {\n name: file.name,\n size: Buffer.byteLength(file.content),\n mode: file.mode,\n },\n (error) => {\n if (error) {\n return reject(error);\n } else {\n resolve();\n }\n },\n );\n\n if (file.content instanceof Readable) {\n file.content.pipe(entry);\n } else {\n entry.end(file.content);\n }\n });\n }\n\n /**\n * Allows to finish the stream returning a Promise that will\n * resolve once the readable is effectively closed or\n * errored.\n */\n async end() {\n return new Promise<void>((resolve, reject) => {\n this.readable.on(\"error\", reject);\n this.readable.on(\"end\", resolve);\n this.pack.finalize();\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;AA8CA,IAAa,aAAb,MAAwB;CAItB,cAAc;EACZ,MAAM,OAAO,aAAK,YAAY;AAC9B,OAAK,OAAOA,mBAAI,MAAM;AACtB,OAAK,WAAW,KAAK,KAAK,KAAK,KAAK;;;;;;;;;;CAWtC,MAAM,QAAQ,MAA6B;AACzC,SAAO,IAAI,SAAe,SAAS,WAAW;GAC5C,MAAM,QAAQ,KAAK,KAAK,MACtB,UAAU,OACN;IAAE,MAAM,KAAK;IAAM,MAAM,KAAK;IAAM,MAAM,KAAK;IAAM,GACrD;IACE,MAAM,KAAK;IACX,MAAM,OAAO,WAAW,KAAK,QAAQ;IACrC,MAAM,KAAK;IACZ,GACJ,UAAU;AACT,QAAI,MACF,QAAO,OAAO,MAAM;QAEpB,UAAS;KAGd;AAED,OAAI,KAAK,mBAAmBC,gBAC1B,MAAK,QAAQ,KAAK,MAAM;OAExB,OAAM,IAAI,KAAK,QAAQ;IAEzB;;;;;;;CAQJ,MAAM,MAAM;AACV,SAAO,IAAI,SAAe,SAAS,WAAW;AAC5C,QAAK,SAAS,GAAG,SAAS,OAAO;AACjC,QAAK,SAAS,GAAG,OAAO,QAAQ;AAChC,QAAK,KAAK,UAAU;IACpB"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Readable } from "stream";
|
|
2
|
+
|
|
3
|
+
//#region src/api-client/file-writer.d.ts
|
|
4
|
+
interface FileData {
|
|
5
|
+
/**
|
|
6
|
+
* The name (path) of the file to write.
|
|
7
|
+
*/
|
|
8
|
+
name: string;
|
|
9
|
+
/**
|
|
10
|
+
* The content of the file.
|
|
11
|
+
*/
|
|
12
|
+
content: string | Uint8Array;
|
|
13
|
+
/**
|
|
14
|
+
* The file mode (permissions) to set on the file.
|
|
15
|
+
* For example, 0o755 for executable files.
|
|
16
|
+
*/
|
|
17
|
+
mode?: number;
|
|
18
|
+
}
|
|
19
|
+
interface FileStream {
|
|
20
|
+
/**
|
|
21
|
+
* The name (path) of the file to write.
|
|
22
|
+
*/
|
|
23
|
+
name: string;
|
|
24
|
+
/**
|
|
25
|
+
* A Readable stream to consume the content of the file.
|
|
26
|
+
*/
|
|
27
|
+
content: Readable;
|
|
28
|
+
/**
|
|
29
|
+
* The expected size of the file. This is required to write
|
|
30
|
+
* the header of the compressed file.
|
|
31
|
+
*/
|
|
32
|
+
size: number;
|
|
33
|
+
/**
|
|
34
|
+
* The file mode (permissions) to set on the file.
|
|
35
|
+
* For example, 0o755 for executable files.
|
|
36
|
+
*/
|
|
37
|
+
mode?: number;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Allows to create a Readable stream with methods to write files
|
|
41
|
+
* to it and to finish it. Files written are compressed together
|
|
42
|
+
* and gzipped in the stream.
|
|
43
|
+
*/
|
|
44
|
+
declare class FileWriter {
|
|
45
|
+
readable: Readable;
|
|
46
|
+
private pack;
|
|
47
|
+
constructor();
|
|
48
|
+
/**
|
|
49
|
+
* Allows to add a file to the stream. Size is required to write
|
|
50
|
+
* the tarball header so when content is a stream it must be
|
|
51
|
+
* provided.
|
|
52
|
+
*
|
|
53
|
+
* Returns a Promise resolved once the file is written in the
|
|
54
|
+
* stream.
|
|
55
|
+
*/
|
|
56
|
+
addFile(file: FileData | FileStream): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Allows to finish the stream returning a Promise that will
|
|
59
|
+
* resolve once the readable is effectively closed or
|
|
60
|
+
* errored.
|
|
61
|
+
*/
|
|
62
|
+
end(): Promise<void>;
|
|
63
|
+
}
|
|
64
|
+
//#endregion
|
|
65
|
+
export { FileWriter };
|
|
66
|
+
//# sourceMappingURL=file-writer.d.cts.map
|
|
@@ -1,62 +1,66 @@
|
|
|
1
1
|
import { Readable } from "stream";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
|
|
3
|
+
//#region src/api-client/file-writer.d.ts
|
|
4
|
+
interface FileData {
|
|
5
|
+
/**
|
|
6
|
+
* The name (path) of the file to write.
|
|
7
|
+
*/
|
|
8
|
+
name: string;
|
|
9
|
+
/**
|
|
10
|
+
* The content of the file.
|
|
11
|
+
*/
|
|
12
|
+
content: string | Uint8Array;
|
|
13
|
+
/**
|
|
14
|
+
* The file mode (permissions) to set on the file.
|
|
15
|
+
* For example, 0o755 for executable files.
|
|
16
|
+
*/
|
|
17
|
+
mode?: number;
|
|
16
18
|
}
|
|
17
19
|
interface FileStream {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
20
|
+
/**
|
|
21
|
+
* The name (path) of the file to write.
|
|
22
|
+
*/
|
|
23
|
+
name: string;
|
|
24
|
+
/**
|
|
25
|
+
* A Readable stream to consume the content of the file.
|
|
26
|
+
*/
|
|
27
|
+
content: Readable;
|
|
28
|
+
/**
|
|
29
|
+
* The expected size of the file. This is required to write
|
|
30
|
+
* the header of the compressed file.
|
|
31
|
+
*/
|
|
32
|
+
size: number;
|
|
33
|
+
/**
|
|
34
|
+
* The file mode (permissions) to set on the file.
|
|
35
|
+
* For example, 0o755 for executable files.
|
|
36
|
+
*/
|
|
37
|
+
mode?: number;
|
|
36
38
|
}
|
|
37
39
|
/**
|
|
38
40
|
* Allows to create a Readable stream with methods to write files
|
|
39
41
|
* to it and to finish it. Files written are compressed together
|
|
40
42
|
* and gzipped in the stream.
|
|
41
43
|
*/
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
44
|
+
declare class FileWriter {
|
|
45
|
+
readable: Readable;
|
|
46
|
+
private pack;
|
|
47
|
+
constructor();
|
|
48
|
+
/**
|
|
49
|
+
* Allows to add a file to the stream. Size is required to write
|
|
50
|
+
* the tarball header so when content is a stream it must be
|
|
51
|
+
* provided.
|
|
52
|
+
*
|
|
53
|
+
* Returns a Promise resolved once the file is written in the
|
|
54
|
+
* stream.
|
|
55
|
+
*/
|
|
56
|
+
addFile(file: FileData | FileStream): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Allows to finish the stream returning a Promise that will
|
|
59
|
+
* resolve once the readable is effectively closed or
|
|
60
|
+
* errored.
|
|
61
|
+
*/
|
|
62
|
+
end(): Promise<void>;
|
|
61
63
|
}
|
|
62
|
-
|
|
64
|
+
//#endregion
|
|
65
|
+
export { FileWriter };
|
|
66
|
+
//# sourceMappingURL=file-writer.d.ts.map
|
|
@@ -1,63 +1,59 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.FileWriter = void 0;
|
|
7
|
-
const zlib_1 = __importDefault(require("zlib"));
|
|
8
|
-
const tar_stream_1 = __importDefault(require("tar-stream"));
|
|
9
|
-
const stream_1 = require("stream");
|
|
1
|
+
import zlib from "zlib";
|
|
2
|
+
import tar from "tar-stream";
|
|
3
|
+
import { Readable } from "stream";
|
|
4
|
+
|
|
5
|
+
//#region src/api-client/file-writer.ts
|
|
10
6
|
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
7
|
+
* Allows to create a Readable stream with methods to write files
|
|
8
|
+
* to it and to finish it. Files written are compressed together
|
|
9
|
+
* and gzipped in the stream.
|
|
10
|
+
*/
|
|
11
|
+
var FileWriter = class {
|
|
12
|
+
constructor() {
|
|
13
|
+
const gzip = zlib.createGzip();
|
|
14
|
+
this.pack = tar.pack();
|
|
15
|
+
this.readable = this.pack.pipe(gzip);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Allows to add a file to the stream. Size is required to write
|
|
19
|
+
* the tarball header so when content is a stream it must be
|
|
20
|
+
* provided.
|
|
21
|
+
*
|
|
22
|
+
* Returns a Promise resolved once the file is written in the
|
|
23
|
+
* stream.
|
|
24
|
+
*/
|
|
25
|
+
async addFile(file) {
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
const entry = this.pack.entry("size" in file ? {
|
|
28
|
+
name: file.name,
|
|
29
|
+
size: file.size,
|
|
30
|
+
mode: file.mode
|
|
31
|
+
} : {
|
|
32
|
+
name: file.name,
|
|
33
|
+
size: Buffer.byteLength(file.content),
|
|
34
|
+
mode: file.mode
|
|
35
|
+
}, (error) => {
|
|
36
|
+
if (error) return reject(error);
|
|
37
|
+
else resolve();
|
|
38
|
+
});
|
|
39
|
+
if (file.content instanceof Readable) file.content.pipe(entry);
|
|
40
|
+
else entry.end(file.content);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Allows to finish the stream returning a Promise that will
|
|
45
|
+
* resolve once the readable is effectively closed or
|
|
46
|
+
* errored.
|
|
47
|
+
*/
|
|
48
|
+
async end() {
|
|
49
|
+
return new Promise((resolve, reject) => {
|
|
50
|
+
this.readable.on("error", reject);
|
|
51
|
+
this.readable.on("end", resolve);
|
|
52
|
+
this.pack.finalize();
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
58
|
+
export { FileWriter };
|
|
63
59
|
//# sourceMappingURL=file-writer.js.map
|