dcl-catalyst-client 22.0.0 → 22.0.1-38482794215.commit-a4a4e71

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 (34) hide show
  1. package/README.md +47 -0
  2. package/dist/client/CatalystClient.d.ts.map +1 -1
  3. package/dist/client/CatalystClient.js +2 -1
  4. package/dist/client/CatalystClient.js.map +1 -1
  5. package/dist/client/ContentClient.d.ts +10 -2
  6. package/dist/client/ContentClient.d.ts.map +1 -1
  7. package/dist/client/ContentClient.js +500 -10
  8. package/dist/client/ContentClient.js.map +1 -1
  9. package/dist/client/index.d.ts +1 -0
  10. package/dist/client/index.d.ts.map +1 -1
  11. package/dist/client/index.js +6 -0
  12. package/dist/client/index.js.map +1 -1
  13. package/dist/client/types.d.ts +75 -0
  14. package/dist/client/types.d.ts.map +1 -1
  15. package/dist/client/utils/batching.d.ts +20 -0
  16. package/dist/client/utils/batching.d.ts.map +1 -0
  17. package/dist/client/utils/batching.js +39 -0
  18. package/dist/client/utils/batching.js.map +1 -0
  19. package/dist/client/utils/errors.d.ts +43 -0
  20. package/dist/client/utils/errors.d.ts.map +1 -0
  21. package/dist/client/utils/errors.js +66 -0
  22. package/dist/client/utils/errors.js.map +1 -0
  23. package/dist/client/utils/upload-progress.d.ts +57 -0
  24. package/dist/client/utils/upload-progress.d.ts.map +1 -0
  25. package/dist/client/utils/upload-progress.js +246 -0
  26. package/dist/client/utils/upload-progress.js.map +1 -0
  27. package/dist/contracts-snapshots/data.d.ts.map +1 -1
  28. package/dist/contracts-snapshots/data.js +7 -1
  29. package/dist/contracts-snapshots/data.js.map +1 -1
  30. package/dist/index.d.ts +4 -1
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +9 -0
  33. package/dist/index.js.map +1 -1
  34. package/package.json +2 -2
@@ -14,7 +14,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.PartialDeploymentValidationError = exports.PartialDeploymentRetryLaterError = exports.PartialDeploymentNotSupportedError = exports.DeploymentError = void 0;
17
18
  __exportStar(require("./utils/DeploymentBuilder"), exports);
19
+ var errors_1 = require("./utils/errors");
20
+ Object.defineProperty(exports, "DeploymentError", { enumerable: true, get: function () { return errors_1.DeploymentError; } });
21
+ Object.defineProperty(exports, "PartialDeploymentNotSupportedError", { enumerable: true, get: function () { return errors_1.PartialDeploymentNotSupportedError; } });
22
+ Object.defineProperty(exports, "PartialDeploymentRetryLaterError", { enumerable: true, get: function () { return errors_1.PartialDeploymentRetryLaterError; } });
23
+ Object.defineProperty(exports, "PartialDeploymentValidationError", { enumerable: true, get: function () { return errors_1.PartialDeploymentValidationError; } });
18
24
  __exportStar(require("./CatalystClient"), exports);
19
25
  __exportStar(require("./ContentClient"), exports);
20
26
  __exportStar(require("./LambdasClient"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAAyC;AACzC,mDAAgC;AAChC,kDAA+B;AAC/B,kDAA+B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,4DAAyC;AACzC,yCAKuB;AAJrB,yGAAA,eAAe,OAAA;AACf,4HAAA,kCAAkC,OAAA;AAClC,0HAAA,gCAAgC,OAAA;AAChC,0HAAA,gCAAgC,OAAA;AAElC,mDAAgC;AAChC,kDAA+B;AAC/B,kDAA+B"}
@@ -28,6 +28,9 @@ export type FetchResponse = {
28
28
  json(): Promise<any>;
29
29
  text(): Promise<string>;
30
30
  arrayBuffer(): Promise<ArrayBuffer>;
31
+ headers?: {
32
+ get(name: string): string | null;
33
+ };
31
34
  };
32
35
  /**
33
36
  * The fetch component the client depends on.
@@ -69,6 +72,68 @@ export type ServerMetadata = {
69
72
  export type ParallelConfig = {
70
73
  urls: string[];
71
74
  };
75
+ export type PartialDeploymentProgress = {
76
+ /** Bytes of content confirmed on the server so far (includes content already present before the upload). */
77
+ uploadedBytes: number;
78
+ /** Total bytes of the entity's content files. */
79
+ totalBytes: number;
80
+ /** Number of batches confirmed staged so far. */
81
+ completedBatches: number;
82
+ /** Total number of batches known so far; grows if the server reports more content missing. */
83
+ totalBatches: number;
84
+ };
85
+ /**
86
+ * Stage of an upload reported by `onUploadProgress`:
87
+ * - `checking`: asking the server which files it already stores.
88
+ * - `uploading`: file bytes are going out.
89
+ * - `processing`: every scheduled byte was sent; waiting for the server's answer.
90
+ */
91
+ export type UploadPhase = 'checking' | 'uploading' | 'processing';
92
+ /** Byte-level progress of a deployment upload. */
93
+ export type UploadProgress = {
94
+ phase: UploadPhase;
95
+ /**
96
+ * File bytes handed to the HTTP client so far, summed across requests (multipart overhead excluded).
97
+ * Never decreases and never exceeds `totalBytes`.
98
+ */
99
+ sentBytes: number;
100
+ /**
101
+ * File bytes the deployment must send: files the server already stores are excluded, and the entity
102
+ * file is included when sent. Grows when content is re-sent (retries, the server's `missing` list).
103
+ * While `checking`, it is every candidate file.
104
+ */
105
+ totalBytes: number;
106
+ };
107
+ export type UploadProgressOptions = {
108
+ /**
109
+ * Invoked with byte-level upload progress, at most every 200 ms plus on every phase change. With
110
+ * {@link ClientOptions.streamingUploads} on Node, the request body is streamed and counted as it is
111
+ * handed to the HTTP client; otherwise a request's bytes count as sent when its response arrives.
112
+ */
113
+ onUploadProgress?: (progress: UploadProgress) => void;
114
+ };
115
+ export type PartialDeploymentOptions = UploadProgressOptions & {
116
+ /**
117
+ * Max summed file bytes per request. Default {@link DEFAULT_MAX_BATCH_SIZE_BYTES} (100 MiB — safely
118
+ * under the ~200MB request ceiling of the infrastructure in front of the content servers).
119
+ */
120
+ maxBatchSizeBytes?: number;
121
+ /** Concurrent batch uploads after the first (entity-carrying) request. Default 2. */
122
+ concurrency?: number;
123
+ /**
124
+ * Retries after retryable failures (408, 409, 429, 5xx, network), and rounds allowed without progress
125
+ * when the server keeps reporting content missing. Both budgets reset whenever the server's missing
126
+ * list shrinks below its lowest count so far. Default 3.
127
+ */
128
+ maxResumeAttempts?: number;
129
+ /** Base retry delay in ms, doubled on each retry (exponential backoff), never below `Retry-After`. Default 1000. */
130
+ resumeDelay?: number;
131
+ /** Invoked after each staged batch with cumulative progress. */
132
+ onProgress?: (progress: PartialDeploymentProgress) => void;
133
+ };
134
+ export type PartialDeploymentResult = {
135
+ creationTimestamp: number;
136
+ };
72
137
  export type ClientOptions = {
73
138
  url: string;
74
139
  fetcher: IFetchComponent;
@@ -79,5 +144,15 @@ export type ClientOptions = {
79
144
  * @type {ParallelConfig}
80
145
  */
81
146
  parallelConfig?: ParallelConfig;
147
+ /**
148
+ * Declares that `fetcher` can send a streamed deployment body, so `onUploadProgress` counts bytes as
149
+ * they go out instead of per request. Default false. Only enable it when the fetcher:
150
+ * - passes `body` to the global (undici) `fetch` of Node >= 18, which accepts a web `ReadableStream`;
151
+ * - forwards the `duplex: 'half'` option and the `content-length` header unchanged;
152
+ * - never retries a POST with the same options, since the stream can only be read once.
153
+ * `@dcl/fetch-component` meets this. node-fetch does not (it would send the stream as a string).
154
+ * Each request in flight then also holds an encoded copy of its body, about the batch size.
155
+ */
156
+ streamingUploads?: boolean;
82
157
  };
83
158
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAA;AAEpE;;;;;;;GAOG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,E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AO,EAAE,eAAe,CAAA;IACxB,MAAM,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAA;IACjC;;;;OAIG;IACH,cAAc,CAAC,EAAE,cAAc,CAAA;IAC/B;;;;;;;;OAQG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B,CAAA"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Default cap on the summed file bytes per partial-deployment request. The infrastructure in front of
3
+ * the content servers times out requests larger than ~200MB, so 100MB keeps a comfortable safety
4
+ * margin (the cap counts file bytes, not exact wire size — the margin also absorbs multipart overhead
5
+ * and the entity JSON riding along in the first request) while keeping the request count low for large
6
+ * scenes. Also under the servers' own request caps (worlds-content-server 350MB, catalyst 2GiB).
7
+ */
8
+ export declare const DEFAULT_MAX_BATCH_SIZE_BYTES: number;
9
+ export type FileBatch = {
10
+ hashes: string[];
11
+ sizeBytes: number;
12
+ };
13
+ /**
14
+ * Splits files into batches whose summed byte size stays at or below `maxBatchSizeBytes`, using
15
+ * first-fit-decreasing bin packing. Files are never split, so a file larger than the cap still lands
16
+ * alone in an over-cap batch; deployPartial rejects such files before uploading. Deterministic given the
17
+ * same input.
18
+ */
19
+ export declare function splitIntoBatches(files: Map<string, Uint8Array>, maxBatchSizeBytes: number): FileBatch[];
20
+ //# sourceMappingURL=batching.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"batching.d.ts","sourceRoot":"","sources":["../../../src/client/utils/batching.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,4BAA4B,QAAoB,CAAA;AAE7D,MAAM,MAAM,SAAS,GAAG;IACtB,MAAM,EAAE,MAAM,EAAE,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,EAAE,iBAAiB,EAAE,MAAM,GAAG,SAAS,EAAE,CAqBvG"}
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.splitIntoBatches = exports.DEFAULT_MAX_BATCH_SIZE_BYTES = void 0;
4
+ /**
5
+ * Default cap on the summed file bytes per partial-deployment request. The infrastructure in front of
6
+ * the content servers times out requests larger than ~200MB, so 100MB keeps a comfortable safety
7
+ * margin (the cap counts file bytes, not exact wire size — the margin also absorbs multipart overhead
8
+ * and the entity JSON riding along in the first request) while keeping the request count low for large
9
+ * scenes. Also under the servers' own request caps (worlds-content-server 350MB, catalyst 2GiB).
10
+ */
11
+ exports.DEFAULT_MAX_BATCH_SIZE_BYTES = 100 * 1024 * 1024; // 100 MiB
12
+ /**
13
+ * Splits files into batches whose summed byte size stays at or below `maxBatchSizeBytes`, using
14
+ * first-fit-decreasing bin packing. Files are never split, so a file larger than the cap still lands
15
+ * alone in an over-cap batch; deployPartial rejects such files before uploading. Deterministic given the
16
+ * same input.
17
+ */
18
+ function splitIntoBatches(files, maxBatchSizeBytes) {
19
+ const entries = Array.from(files.entries()).sort((a, b) => b[1].byteLength - a[1].byteLength);
20
+ const batches = [];
21
+ for (const [hash, content] of entries) {
22
+ const size = content.byteLength;
23
+ let placed = false;
24
+ for (const batch of batches) {
25
+ if (batch.sizeBytes + size <= maxBatchSizeBytes) {
26
+ batch.hashes.push(hash);
27
+ batch.sizeBytes += size;
28
+ placed = true;
29
+ break;
30
+ }
31
+ }
32
+ if (!placed) {
33
+ batches.push({ hashes: [hash], sizeBytes: size });
34
+ }
35
+ }
36
+ return batches;
37
+ }
38
+ exports.splitIntoBatches = splitIntoBatches;
39
+ //# sourceMappingURL=batching.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"batching.js","sourceRoot":"","sources":["../../../src/client/utils/batching.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACU,QAAA,4BAA4B,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,CAAA,CAAC,UAAU;AAOxE;;;;;GAKG;AACH,SAAgB,gBAAgB,CAAC,KAA8B,EAAE,iBAAyB;IACxF,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAA;IAC7F,MAAM,OAAO,GAAgB,EAAE,CAAA;IAE/B,KAAK,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,OAAO,EAAE;QACrC,MAAM,IAAI,GAAG,OAAO,CAAC,UAAU,CAAA;QAC/B,IAAI,MAAM,GAAG,KAAK,CAAA;QAClB,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE;YAC3B,IAAI,KAAK,CAAC,SAAS,GAAG,IAAI,IAAI,iBAAiB,EAAE;gBAC/C,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;gBACvB,KAAK,CAAC,SAAS,IAAI,IAAI,CAAA;gBACvB,MAAM,GAAG,IAAI,CAAA;gBACb,MAAK;aACN;SACF;QACD,IAAI,CAAC,MAAM,EAAE;YACX,OAAO,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;SAClD;KACF;IAED,OAAO,OAAO,CAAA;AAChB,CAAC;AArBD,4CAqBC"}
@@ -0,0 +1,43 @@
1
+ /** Base error for a failed deployment. Carries the HTTP status and raw response body when available. */
2
+ export declare class DeploymentError extends Error {
3
+ readonly status?: number | undefined;
4
+ readonly responseBody?: string | undefined;
5
+ constructor(message: string, status?: number | undefined, responseBody?: string | undefined);
6
+ }
7
+ /**
8
+ * The server rejected the deployment with a validation error (HTTP 400) — e.g. the deployment exceeds
9
+ * the size budget, or a signature/permission check failed. Terminal: retrying will not help.
10
+ */
11
+ export declare class PartialDeploymentValidationError extends DeploymentError {
12
+ constructor(message: string, status?: number, responseBody?: string);
13
+ }
14
+ /**
15
+ * The target server does not support partial deployments: it ran the full deployment pipeline on a
16
+ * staging request and rejected it because referenced content was not uploaded or stored. Fall back to
17
+ * `deploy()` (a single request) against such a server. Best-effort detection via the server's error text.
18
+ */
19
+ export declare class PartialDeploymentNotSupportedError extends DeploymentError {
20
+ constructor(message: string, status?: number, responseBody?: string);
21
+ }
22
+ /**
23
+ * A transient failure the resume loop should retry (408, 409, 429, 5xx). Deliberately NOT a
24
+ * {@link DeploymentError} (those are terminal). `retryAfterMs`, when set from a server `Retry-After`
25
+ * header, is used as the backoff floor so the client waits out the server's window instead of exhausting
26
+ * its attempts inside it.
27
+ */
28
+ export declare class RetryablePartialDeploymentError extends Error {
29
+ readonly retryAfterMs?: number | undefined;
30
+ readonly status?: number | undefined;
31
+ readonly responseBody?: string | undefined;
32
+ constructor(message: string, retryAfterMs?: number | undefined, status?: number | undefined, responseBody?: string | undefined);
33
+ }
34
+ /**
35
+ * The server asked to retry later than the client is willing to wait (e.g. a partial-upload quota that
36
+ * frees up only when older uploads expire). Terminal for this call; `retryAfterMs` says when a new
37
+ * attempt may succeed, and the message carries the server's explanation.
38
+ */
39
+ export declare class PartialDeploymentRetryLaterError extends DeploymentError {
40
+ readonly retryAfterMs: number;
41
+ constructor(message: string, retryAfterMs: number, status?: number, responseBody?: string);
42
+ }
43
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/client/utils/errors.ts"],"names":[],"mappings":"AAAA,wGAAwG;AACxG,qBAAa,eAAgB,SAAQ,KAAK;aACK,MAAM,CAAC;aAA0B,YAAY,CAAC;gBAA/E,OAAO,EAAE,MAAM,EAAkB,MAAM,CAAC,oBAAQ,EAAkB,YAAY,CAAC,oBAAQ;CAIpG;AAED;;;GAGG;AACH,qBAAa,gCAAiC,SAAQ,eAAe;gBACvD,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM;CAIpE;AAED;;;;GAIG;AACH,qBAAa,kCAAmC,SAAQ,eAAe;gBACzD,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM;CAIpE;AAED;;;;;GAKG;AACH,qBAAa,+BAAgC,SAAQ,KAAK;aAGtC,YAAY,CAAC;aACb,MAAM,CAAC;aACP,YAAY,CAAC;gBAH7B,OAAO,EAAE,MAAM,EACC,YAAY,CAAC,oBAAQ,EACrB,MAAM,CAAC,oBAAQ,EACf,YAAY,CAAC,oBAAQ;CAKxC;AAED;;;;GAIG;AACH,qBAAa,gCAAiC,SAAQ,eAAe;aACtB,YAAY,EAAE,MAAM;gBAArD,OAAO,EAAE,MAAM,EAAkB,YAAY,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM;CAI1G"}
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PartialDeploymentRetryLaterError = exports.RetryablePartialDeploymentError = exports.PartialDeploymentNotSupportedError = exports.PartialDeploymentValidationError = exports.DeploymentError = void 0;
4
+ /** Base error for a failed deployment. Carries the HTTP status and raw response body when available. */
5
+ class DeploymentError extends Error {
6
+ constructor(message, status, responseBody) {
7
+ super(message);
8
+ this.status = status;
9
+ this.responseBody = responseBody;
10
+ this.name = 'DeploymentError';
11
+ }
12
+ }
13
+ exports.DeploymentError = DeploymentError;
14
+ /**
15
+ * The server rejected the deployment with a validation error (HTTP 400) — e.g. the deployment exceeds
16
+ * the size budget, or a signature/permission check failed. Terminal: retrying will not help.
17
+ */
18
+ class PartialDeploymentValidationError extends DeploymentError {
19
+ constructor(message, status, responseBody) {
20
+ super(message, status, responseBody);
21
+ this.name = 'PartialDeploymentValidationError';
22
+ }
23
+ }
24
+ exports.PartialDeploymentValidationError = PartialDeploymentValidationError;
25
+ /**
26
+ * The target server does not support partial deployments: it ran the full deployment pipeline on a
27
+ * staging request and rejected it because referenced content was not uploaded or stored. Fall back to
28
+ * `deploy()` (a single request) against such a server. Best-effort detection via the server's error text.
29
+ */
30
+ class PartialDeploymentNotSupportedError extends DeploymentError {
31
+ constructor(message, status, responseBody) {
32
+ super(message, status, responseBody);
33
+ this.name = 'PartialDeploymentNotSupportedError';
34
+ }
35
+ }
36
+ exports.PartialDeploymentNotSupportedError = PartialDeploymentNotSupportedError;
37
+ /**
38
+ * A transient failure the resume loop should retry (408, 409, 429, 5xx). Deliberately NOT a
39
+ * {@link DeploymentError} (those are terminal). `retryAfterMs`, when set from a server `Retry-After`
40
+ * header, is used as the backoff floor so the client waits out the server's window instead of exhausting
41
+ * its attempts inside it.
42
+ */
43
+ class RetryablePartialDeploymentError extends Error {
44
+ constructor(message, retryAfterMs, status, responseBody) {
45
+ super(message);
46
+ this.retryAfterMs = retryAfterMs;
47
+ this.status = status;
48
+ this.responseBody = responseBody;
49
+ this.name = 'RetryablePartialDeploymentError';
50
+ }
51
+ }
52
+ exports.RetryablePartialDeploymentError = RetryablePartialDeploymentError;
53
+ /**
54
+ * The server asked to retry later than the client is willing to wait (e.g. a partial-upload quota that
55
+ * frees up only when older uploads expire). Terminal for this call; `retryAfterMs` says when a new
56
+ * attempt may succeed, and the message carries the server's explanation.
57
+ */
58
+ class PartialDeploymentRetryLaterError extends DeploymentError {
59
+ constructor(message, retryAfterMs, status, responseBody) {
60
+ super(message, status, responseBody);
61
+ this.retryAfterMs = retryAfterMs;
62
+ this.name = 'PartialDeploymentRetryLaterError';
63
+ }
64
+ }
65
+ exports.PartialDeploymentRetryLaterError = PartialDeploymentRetryLaterError;
66
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/client/utils/errors.ts"],"names":[],"mappings":";;;AAAA,wGAAwG;AACxG,MAAa,eAAgB,S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IAChD,CAAC;CACF;AALD,4EAKC"}
@@ -0,0 +1,57 @@
1
+ import { UploadProgress } from '../types';
2
+ export declare const UPLOAD_PROGRESS_INTERVAL_MS = 200;
3
+ export declare const UPLOAD_SLICE_BYTES: number;
4
+ /** Whether request bodies can be streamed (and so counted as they go out): only on Node. */
5
+ export declare function supportsStreamingUpload(): boolean;
6
+ /**
7
+ * Whether `error` is the rejection of a fetcher that dropped the `duplex` option of a streamed body.
8
+ * Targets undici's "TypeError: RequestInit: duplex option is required when sending a body."
9
+ */
10
+ export declare function isDuplexUnsupportedError(error: unknown): boolean;
11
+ export type CountingBody = {
12
+ body: ReadableStream<Uint8Array>;
13
+ headers: {
14
+ 'content-type': string;
15
+ 'content-length': string;
16
+ };
17
+ /** Releases the encoded body and stops the stream if it is still open. */
18
+ dispose: () => void;
19
+ };
20
+ /**
21
+ * Encodes `form` once and returns a stream of it that calls `onStreamed` with the cumulative
22
+ * number of body bytes handed to the HTTP client, one slice at a time.
23
+ */
24
+ export declare function createCountingBody(url: string, form: FormData, onStreamed: (streamedBytes: number, bodyBytes: number) => void, signal?: AbortSignal): Promise<CountingBody>;
25
+ /** Returns `headers` plus `extra`, dropping any caller header that `extra` replaces (case-insensitive). */
26
+ export declare function withBodyHeaders(headers: Record<string, string> | undefined, extra: Record<string, string>): Record<string, string>;
27
+ /** Progress of one request, in file bytes. */
28
+ export type UploadRequestProgress = {
29
+ /** Body bytes streamed so far; converted to file bytes proportionally. */
30
+ streamed(streamedBytes: number, bodyBytes: number): void;
31
+ /** The body won't be streamed after all: its bytes count when the response arrives. */
32
+ unstreamed(): void;
33
+ /** A response arrived for an unstreamed body: all its file bytes count as sent. */
34
+ delivered(): void;
35
+ /** The request ended. Bytes it never sent leave the total only once a retry or success follows. */
36
+ end(): void;
37
+ };
38
+ export type UploadProgressTracker = {
39
+ /** Reports the `/available-content` check, with every candidate file as the provisional total. */
40
+ checking(candidateBytes: number): void;
41
+ /** Adds the file bytes a round of requests is about to send, dropping what earlier rounds never sent. */
42
+ plan(fileBytes: number): void;
43
+ /** Starts a request carrying `fileBytes` of the planned bytes; `streaming` when its body is counted. */
44
+ request(fileBytes: number, streaming: boolean): UploadRequestProgress;
45
+ /** The deployment succeeded: emits `processing` with every byte sent, then stops. */
46
+ complete(): void;
47
+ /** The deployment failed: stops without emitting. */
48
+ close(): void;
49
+ };
50
+ /**
51
+ * Runs `upload`, completing the tracker when it succeeds and closing it silently when it rejects or
52
+ * `succeeded` rejects its result (e.g. an error response the caller still receives).
53
+ */
54
+ export declare function trackUpload<T>(tracker: UploadProgressTracker | undefined, upload: () => Promise<T>, succeeded?: (result: T) => boolean): Promise<T>;
55
+ /** Tracks byte-level upload progress across requests, throttling events to `onUploadProgress`. */
56
+ export declare function createUploadProgressTracker(onUploadProgress: (progress: UploadProgress) => void, now?: () => number, intervalMs?: number): UploadProgressTracker;
57
+ //# sourceMappingURL=upload-progress.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upload-progress.d.ts","sourceRoot":"","sources":["../../../src/client/utils/upload-progress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,cAAc,EAAE,MAAM,UAAU,CAAA;AAGtD,eAAO,MAAM,2BAA2B,MAAM,CAAA;AAG9C,eAAO,MAAM,kBAAkB,QAAa,CAAA;AAE5C,4FAA4F;AAC5F,wBAAgB,uBAAuB,IAAI,OAAO,CAEjD;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAEhE;AAED,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,CAAA;IAChC,OAAO,EAAE;QAAE,cAAc,EAAE,MAAM,CAAC;QAAC,gBAAgB,EAAE,MAAM,CAAA;KAAE,CAAA;IAC7D,0EAA0E;IAC1E,OAAO,EAAE,MAAM,IAAI,CAAA;CACpB,CAAA;AAED;;;GAGG;AACH,wBAAsB,kBAAkB,CACtC,GAAG,EAAE,MAAM,E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,CAAC,CAAC,CAAC,CAUZ;AAED,kGAAkG;AAClG,wBAAgB,2BAA2B,CACzC,gBAAgB,EAAE,CAAC,QAAQ,EAAE,cAAc,KAAK,IAAI,EACpD,GAAG,GAAE,MAAM,MAAiB,EAC5B,UAAU,GAAE,MAAoC,GAC/C,qBAAqB,CAoIvB"}
@@ -0,0 +1,246 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createUploadProgressTracker = exports.trackUpload = exports.withBodyHeaders = exports.createCountingBody = exports.isDuplexUnsupportedError = exports.supportsStreamingUpload = exports.UPLOAD_SLICE_BYTES = exports.UPLOAD_PROGRESS_INTERVAL_MS = void 0;
4
+ // Minimum time between two progress events of the same phase.
5
+ exports.UPLOAD_PROGRESS_INTERVAL_MS = 200;
6
+ // Size of each body slice handed to the HTTP client, and so the granularity of the progress.
7
+ exports.UPLOAD_SLICE_BYTES = 256 * 1024;
8
+ /** Whether request bodies can be streamed (and so counted as they go out): only on Node. */
9
+ function supportsStreamingUpload() {
10
+ var _a;
11
+ return typeof process !== 'undefined' && !!((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node);
12
+ }
13
+ exports.supportsStreamingUpload = supportsStreamingUpload;
14
+ /**
15
+ * Whether `error` is the rejection of a fetcher that dropped the `duplex` option of a streamed body.
16
+ * Targets undici's "TypeError: RequestInit: duplex option is required when sending a body."
17
+ */
18
+ function isDuplexUnsupportedError(error) {
19
+ return error instanceof TypeError && /duplex/i.test(error.message);
20
+ }
21
+ exports.isDuplexUnsupportedError = isDuplexUnsupportedError;
22
+ /**
23
+ * Encodes `form` once and returns a stream of it that calls `onStreamed` with the cumulative
24
+ * number of body bytes handed to the HTTP client, one slice at a time.
25
+ */
26
+ async function createCountingBody(url, form, onStreamed, signal) {
27
+ var _a;
28
+ const encoded = new Request(url, { method: 'POST', body: form });
29
+ const contentType = (_a = encoded.headers.get('content-type')) !== null && _a !== void 0 ? _a : 'multipart/form-data';
30
+ let bytes = new Uint8Array(await encoded.arrayBuffer());
31
+ const bodyBytes = bytes.byteLength;
32
+ let offset = 0;
33
+ let stream;
34
+ // Releases the encoded body and, if the stream is still open, errors it so the HTTP client stops reading.
35
+ const stop = (reason) => {
36
+ signal === null || signal === void 0 ? void 0 : signal.removeEventListener('abort', onAbort);
37
+ const controller = stream;
38
+ bytes = undefined;
39
+ stream = undefined;
40
+ controller === null || controller === void 0 ? void 0 : controller.error(reason !== null && reason !== void 0 ? reason : new Error('The upload stopped.'));
41
+ };
42
+ function onAbort() {
43
+ var _a;
44
+ stop((_a = signal === null || signal === void 0 ? void 0 : signal.reason) !== null && _a !== void 0 ? _a : new Error('The upload was aborted.'));
45
+ }
46
+ const body = new ReadableStream({
47
+ start(controller) {
48
+ stream = controller;
49
+ if (signal === null || signal === void 0 ? void 0 : signal.aborted)
50
+ onAbort();
51
+ else
52
+ signal === null || signal === void 0 ? void 0 : signal.addEventListener('abort', onAbort, { once: true });
53
+ },
54
+ pull(controller) {
55
+ if (!bytes)
56
+ return;
57
+ const slice = bytes.subarray(offset, offset + exports.UPLOAD_SLICE_BYTES);
58
+ offset += slice.byteLength;
59
+ controller.enqueue(slice);
60
+ if (offset >= bodyBytes) {
61
+ signal === null || signal === void 0 ? void 0 : signal.removeEventListener('abort', onAbort);
62
+ bytes = undefined;
63
+ stream = undefined;
64
+ controller.close();
65
+ }
66
+ onStreamed(offset, bodyBytes);
67
+ },
68
+ cancel() {
69
+ stream = undefined;
70
+ stop();
71
+ }
72
+ },
73
+ // Pull only when the HTTP client reads, so a slice is counted when it is handed over.
74
+ { highWaterMark: 0 });
75
+ return {
76
+ body,
77
+ headers: { 'content-type': contentType, 'content-length': String(bodyBytes) },
78
+ dispose: () => stop()
79
+ };
80
+ }
81
+ exports.createCountingBody = createCountingBody;
82
+ /** Returns `headers` plus `extra`, dropping any caller header that `extra` replaces (case-insensitive). */
83
+ function withBodyHeaders(headers, extra) {
84
+ const replaced = new Set(Object.keys(extra).map((name) => name.toLowerCase()));
85
+ const kept = Object.entries(headers !== null && headers !== void 0 ? headers : {}).filter(([name]) => !replaced.has(name.toLowerCase()));
86
+ return { ...Object.fromEntries(kept), ...extra };
87
+ }
88
+ exports.withBodyHeaders = withBodyHeaders;
89
+ /**
90
+ * Runs `upload`, completing the tracker when it succeeds and closing it silently when it rejects or
91
+ * `succeeded` rejects its result (e.g. an error response the caller still receives).
92
+ */
93
+ async function trackUpload(tracker, upload, succeeded = () => true) {
94
+ try {
95
+ const result = await upload();
96
+ if (succeeded(result))
97
+ tracker === null || tracker === void 0 ? void 0 : tracker.complete();
98
+ else
99
+ tracker === null || tracker === void 0 ? void 0 : tracker.close();
100
+ return result;
101
+ }
102
+ catch (error) {
103
+ tracker === null || tracker === void 0 ? void 0 : tracker.close();
104
+ throw error;
105
+ }
106
+ }
107
+ exports.trackUpload = trackUpload;
108
+ /** Tracks byte-level upload progress across requests, throttling events to `onUploadProgress`. */
109
+ function createUploadProgressTracker(onUploadProgress, now = Date.now, intervalMs = exports.UPLOAD_PROGRESS_INTERVAL_MS) {
110
+ let phase;
111
+ let sentBytes = 0;
112
+ let totalBytes = 0;
113
+ // Planned bytes no request has taken yet, and bytes of ended requests that were never sent.
114
+ let unstartedBytes = 0;
115
+ let unsentBytes = 0;
116
+ let inFlight = 0;
117
+ let lastEmitAt = -Infinity;
118
+ let pending = false;
119
+ let closed = false;
120
+ let trailing;
121
+ let last;
122
+ const clearTrailing = () => {
123
+ if (trailing !== undefined)
124
+ clearTimeout(trailing);
125
+ trailing = undefined;
126
+ };
127
+ const emit = () => {
128
+ clearTrailing();
129
+ pending = false;
130
+ if (!phase || closed)
131
+ return;
132
+ lastEmitAt = now();
133
+ const progress = { phase, sentBytes: Math.min(sentBytes, totalBytes), totalBytes };
134
+ if (last &&
135
+ last.phase === progress.phase &&
136
+ last.sentBytes === progress.sentBytes &&
137
+ last.totalBytes === progress.totalBytes) {
138
+ return;
139
+ }
140
+ last = progress;
141
+ onUploadProgress(progress);
142
+ };
143
+ const update = () => {
144
+ var _a, _b;
145
+ const elapsed = now() - lastEmitAt;
146
+ if (elapsed >= intervalMs)
147
+ return emit();
148
+ pending = true;
149
+ // Trailing edge, so a stalled upload still reports its latest count.
150
+ if (trailing === undefined && !closed) {
151
+ trailing = setTimeout(emit, intervalMs - elapsed);
152
+ (_b = (_a = trailing).unref) === null || _b === void 0 ? void 0 : _b.call(_a);
153
+ }
154
+ };
155
+ const setPhase = (next) => {
156
+ if (next === phase)
157
+ return update();
158
+ // The last count of the previous phase goes out before the phase changes.
159
+ if (pending)
160
+ emit();
161
+ phase = next;
162
+ emit();
163
+ };
164
+ // `processing` only once every scheduled byte is sent and responses are pending.
165
+ const refreshPhase = () => {
166
+ if (inFlight === 0)
167
+ return;
168
+ const next = sentBytes >= totalBytes ? 'processing' : 'uploading';
169
+ if (next !== phase)
170
+ setPhase(next);
171
+ };
172
+ const dropUnsent = () => {
173
+ totalBytes -= unstartedBytes + unsentBytes;
174
+ unstartedBytes = 0;
175
+ unsentBytes = 0;
176
+ };
177
+ return {
178
+ checking(candidateBytes) {
179
+ totalBytes = candidateBytes;
180
+ setPhase('checking');
181
+ },
182
+ plan(fileBytes) {
183
+ if (phase === 'checking')
184
+ totalBytes = 0;
185
+ dropUnsent();
186
+ totalBytes += fileBytes;
187
+ unstartedBytes += fileBytes;
188
+ },
189
+ request(fileBytes, streamingBody) {
190
+ let counted = 0;
191
+ let isStreaming = streamingBody;
192
+ let ended = false;
193
+ unstartedBytes = Math.max(0, unstartedBytes - fileBytes);
194
+ inFlight++;
195
+ refreshPhase();
196
+ const count = (bytes) => {
197
+ sentBytes += bytes - counted;
198
+ counted = bytes;
199
+ };
200
+ return {
201
+ streamed(streamedBytes, bodyBytes) {
202
+ if (ended || !isStreaming)
203
+ return;
204
+ const done = streamedBytes >= bodyBytes;
205
+ count(done ? fileBytes : Math.floor((fileBytes * streamedBytes) / bodyBytes));
206
+ update();
207
+ refreshPhase();
208
+ },
209
+ unstreamed() {
210
+ if (ended)
211
+ return;
212
+ isStreaming = false;
213
+ refreshPhase();
214
+ },
215
+ delivered() {
216
+ if (ended || isStreaming)
217
+ return;
218
+ count(fileBytes);
219
+ update();
220
+ refreshPhase();
221
+ },
222
+ end() {
223
+ if (ended)
224
+ return;
225
+ ended = true;
226
+ inFlight--;
227
+ unsentBytes += fileBytes - counted;
228
+ }
229
+ };
230
+ },
231
+ complete() {
232
+ dropUnsent();
233
+ if (pending)
234
+ emit();
235
+ phase = 'processing';
236
+ emit();
237
+ closed = true;
238
+ },
239
+ close() {
240
+ clearTrailing();
241
+ closed = true;
242
+ }
243
+ };
244
+ }
245
+ exports.createUploadProgressTracker = createUploadProgressTracker;
246
+ //# sourceMappingURL=upload-progress.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upload-progress.js","sourceRoot":"","sources":["../../../src/client/utils/upload-progress.ts"],"names":[],"mappings":";;;AAEA,8DAA8D;AACjD,QAAA,2BAA2B,GAAG,GAAG,CAAA;AAE9C,6FAA6F;AAChF,QAAA,kBAAkB,GAAG,GAAG,GAAG,IAAI,CAAA;AAE5C,4FAA4F;AAC5F,SAAgB,uBAAuB;;IACrC,OAAO,OAAO,OAAO,KAAK,WAAW,IAAI,CAAC,CAAC,CAAA,MAAA,OAAO,CAAC,QAAQ,0CAAE,IAAI,CAAA,CAAA;AACnE,CAAC;AAFD,0DAEC;AAED;;;GAGG;AACH,SAAgB,wBAAwB,CAAC,KAAc;IACrD,OAAO,KAAK,YAAY,SAAS,IAAI,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;AACpE,CAAC;AAFD,4DAEC;AASD;;;GAGG;AACI,KAAK,UAAU,kBAAkB,CACtC,GAAW,EACX,IAAc,EACd,UAA8D,EAC9D,MAAoB;;IAEpB,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAA;IAChE,MAAM,WAAW,GAAG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IAAI,KAAK,IAAI,CAAC,WAAW;wBAAE,OAAM;oBACjC,MAAM,IAAI,GAAG,aAAa,IAAI,SAAS,CAAA;oBACvC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,SAAS,GAAG,aAAa,CAAC,GAAG,SAAS,CAAC,CAAC,CAAA;oBAC7E,MAAM,EAAE,CAAA;oBACR,YAAY,EAAE,CAAA;gBAChB,CAAC;gBACD,UAAU;oBACR,IAAI,KAAK;wBAAE,OAAM;oBACjB,WAAW,GAAG,KAAK,CAAA;oBACnB,YAAY,EAAE,CAAA;gBAChB,CAAC;gBACD,SAAS;oBACP,IAAI,KAAK,IAAI,WAAW;wBAAE,OAAM;oBAChC,KAAK,CAAC,SAAS,CAAC,CAAA;oBAChB,MAAM,EAAE,CAAA;oBACR,YAAY,EAAE,CAAA;gBAChB,CAAC;gBACD,GAAG;oBACD,IAAI,KAAK;wBAAE,OAAM;oBACjB,KAAK,GAAG,IAAI,CAAA;oBACZ,QAAQ,EAAE,CAAA;oBACV,WAAW,IAAI,SAAS,GAAG,OAAO,CAAA;gBACpC,CAAC;aACF,CAAA;QACH,CAAC;QACD,QAAQ;YACN,UAAU,EAAE,CAAA;YACZ,IAAI,OAAO;gBAAE,IAAI,EAAE,CAAA;YACnB,KAAK,GAAG,YAAY,CAAA;YACpB,IAAI,EAAE,CAAA;YACN,MAAM,GAAG,IAAI,CAAA;QACf,CAAC;QACD,KAAK;YACH,aAAa,EAAE,CAAA;YACf,MAAM,GAAG,IAAI,CAAA;QACf,CAAC;KACF,CAAA;AACH,CAAC;AAxID,kEAwIC"}
@@ -1 +1 @@
1
- {"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../src/contracts-snapshots/data.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;CAwIjB,CAAA"}
1
+ {"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../src/contracts-snapshots/data.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;CA8IjB,CAAA"}