@adea-ai/app-framework 0.39.3 → 0.39.4
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 +158 -52
- package/dist/app/application.d.ts +0 -1
- package/dist/app/application.js +8 -6
- package/dist/app/create-application.js +3 -11
- package/dist/app/service-registry.d.ts +0 -1
- package/dist/app/service-registry.js +3 -3
- package/dist/app/value-guards.d.ts +2 -0
- package/dist/app/value-guards.js +6 -1
- package/dist/appearance/appearance-host.d.ts +1 -1
- package/dist/appearance/appearance-host.js +11 -2
- package/dist/appearance/appearance-preferences.d.ts +0 -1
- package/dist/appearance/custom-theme-import.d.ts +8 -2
- package/dist/appearance/custom-theme-import.js +58 -23
- package/dist/appearance/custom-theme-library.d.ts +3 -3
- package/dist/appearance/custom-theme-library.js +3 -3
- package/dist/appearance/theme-file-importer.d.ts +1 -1
- package/dist/appearance/theme-file-importer.js +2 -1
- package/dist/appearance/theme-library-mutation.d.ts +7 -0
- package/dist/appearance/theme-library-mutation.js +10 -2
- package/dist/appearance/theme-library-store.d.ts +17 -13
- package/dist/appearance/theme-library-store.js +35 -22
- package/dist/appearance/theme-record-adapter.js +1 -2
- package/dist/appearance/theme-registry.js +0 -1
- package/dist/cli/cli-runner.d.ts +3 -2
- package/dist/cli/cli-runner.js +5 -10
- package/dist/cli/release-assets-plan-cli.js +2 -2
- package/dist/cli/release-cut-cli.js +2 -3
- package/dist/cli/release-descriptor-staging-cli.js +2 -2
- package/dist/cli/release-finalize-cli.js +3 -3
- package/dist/cli/release-promote-cli.js +2 -2
- package/dist/cli/release-publish-cli.js +2 -2
- package/dist/cli/release-sign-cli.js +2 -1
- package/dist/cli/release-step-cli.js +2 -2
- package/dist/desktop/channel-proof.js +27 -11
- package/dist/desktop/client-assets.d.ts +6 -1
- package/dist/desktop/client-assets.js +16 -3
- package/dist/desktop/client-dev-proxy.d.ts +0 -2
- package/dist/desktop/client-dev-proxy.js +2 -2
- package/dist/desktop/desktop-client.js +2 -1
- package/dist/desktop/desktop-gateway.js +24 -82
- package/dist/desktop/desktop-host-websocket.d.ts +5 -1
- package/dist/desktop/desktop-host-websocket.js +9 -7
- package/dist/desktop/desktop-host.d.ts +5 -0
- package/dist/desktop/desktop-host.js +3 -0
- package/dist/desktop/desktop-stream.js +5 -10
- package/dist/desktop/typed-array-intrinsics.d.ts +6 -0
- package/dist/desktop/typed-array-intrinsics.js +13 -1
- package/dist/developer-app/developer-app.d.ts +1 -1
- package/dist/developer-app/developer-app.js +26 -13
- package/dist/framework-source.json +1 -1
- package/dist/installer/command-artifact.d.ts +1 -0
- package/dist/installer/command-artifact.js +47 -27
- package/dist/installer/installed-payload.js +3 -1
- package/dist/installer/installer-ci-bootstrap.js +5 -6
- package/dist/installer/installer-ci-preflight.js +3 -3
- package/dist/installer/installer-identity.d.ts +0 -22
- package/dist/installer/installer-identity.js +3 -53
- package/dist/installer/installer-image-mount.d.ts +0 -1
- package/dist/installer/installer-image-mount.js +1 -1
- package/dist/installer/installer-observation.d.ts +5 -5
- package/dist/installer/installer-observation.js +32 -47
- package/dist/installer/installer-process-cleanup.js +2 -2
- package/dist/installer/installer-renderer-evidence.js +7 -28
- package/dist/installer/installer-upgrade-command.js +8 -20
- package/dist/installer/installer-worker-guard.js +3 -3
- package/dist/native/cef-helper.js +4 -4
- package/dist/native/desktop-build.d.ts +0 -3
- package/dist/native/desktop-build.js +2 -2
- package/dist/native/electrobun-source-patch.d.ts +4 -0
- package/dist/native/electrobun-source-patch.js +5 -1
- package/dist/native/native-utilities.js +4 -3
- package/dist/native/pinned-download.d.ts +16 -0
- package/dist/native/pinned-download.js +42 -0
- package/dist/native/posix-launcher-build.js +15 -35
- package/dist/native/posix-tree-removal.js +21 -33
- package/dist/native/sidecar-services.d.ts +0 -2
- package/dist/native/sidecar-services.js +1 -1
- package/dist/native/sidecar.d.ts +3 -0
- package/dist/native/sidecar.js +15 -2
- package/dist/native/window-surface-store.js +3 -3
- package/dist/native/windows-extractor-build.d.ts +6 -16
- package/dist/native/windows-extractor-build.js +11 -14
- package/dist/release/feed-release-cut.d.ts +2 -6
- package/dist/release/feed-release-cut.js +5 -93
- package/dist/release/feed-state.js +1 -5
- package/dist/release/github-release-cut.js +5 -66
- package/dist/release/github-release-provenance.d.ts +2 -0
- package/dist/release/github-release-provenance.js +4 -7
- package/dist/release/github-release-publisher.js +2 -2
- package/dist/release/github-release-qualification.js +3 -3
- package/dist/release/local-release.d.ts +3 -3
- package/dist/release/local-release.js +12 -23
- package/dist/release/qualification-run.js +1 -1
- package/dist/release/release-assets-plan.js +1 -1
- package/dist/release/release-config.d.ts +7 -15
- package/dist/release/release-config.js +25 -29
- package/dist/release/release-cut-command.d.ts +1 -1
- package/dist/release/release-cut-command.js +1 -1
- package/dist/release/release-cut.d.ts +5 -32
- package/dist/release/release-cut.js +9 -55
- package/dist/release/release-descriptor-staging.js +3 -8
- package/dist/release/release-promotion.js +2 -1
- package/dist/release/release-publish-command.js +5 -15
- package/dist/release/release-qualification.js +1 -1
- package/dist/shared/bounded-body.d.ts +33 -0
- package/dist/shared/bounded-body.js +102 -0
- package/dist/shared/file-system.d.ts +12 -0
- package/dist/shared/file-system.js +40 -0
- package/dist/shell/app-shell.js +29 -14
- package/dist/shell/app-utilities.d.ts +2 -1
- package/dist/shell/app-utilities.js +2 -1
- package/dist/shell/application-menu.d.ts +1 -1
- package/dist/shell/application-menu.js +7 -3
- package/dist/shell/poll.d.ts +27 -0
- package/dist/shell/poll.js +88 -0
- package/dist/update-helper.bundle.js +268 -144
- package/dist/updates/channel-update-manager.js +0 -1
- package/dist/updates/desktop-updater.d.ts +9 -0
- package/dist/updates/desktop-updater.js +103 -50
- package/dist/updates/feed/release-feed.d.ts +7 -4
- package/dist/updates/feed/release-feed.js +3 -7
- package/dist/updates/feed/release-location.js +6 -26
- package/dist/updates/feed/release-version.d.ts +7 -2
- package/dist/updates/feed/release-version.js +9 -2
- package/dist/updates/feed/signed-release.d.ts +1 -1
- package/dist/updates/feed/signed-release.js +2 -2
- package/dist/updates/feed/update-discovery.js +2 -6
- package/dist/updates/helper/launch-gate-recovery.js +28 -78
- package/dist/updates/helper/resume-staging.d.ts +14 -3
- package/dist/updates/helper/resume-staging.js +23 -37
- package/dist/updates/helper/update-helper.d.ts +6 -2
- package/dist/updates/helper/update-helper.js +38 -33
- package/dist/updates/helper/update-resume.js +9 -6
- package/dist/updates/install/update-extraction.js +28 -8
- package/dist/updates/install/update-handoff-plan.d.ts +0 -1
- package/dist/updates/install/update-handoff-plan.js +3 -4
- package/dist/updates/install/update-swap-stage.js +1 -6
- package/dist/updates/install/update-swap.d.ts +5 -2
- package/dist/updates/install/update-swap.js +193 -72
- package/dist/updates/launch/helper-exit-wait.d.ts +6 -0
- package/dist/updates/launch/helper-exit-wait.js +18 -0
- package/dist/updates/launch/packaged-update-startup.js +8 -6
- package/dist/updates/launch/update-launch-gate.js +7 -14
- package/dist/updates/locks/stable-file.js +4 -1
- package/dist/updates/locks/update-helper-presence.d.ts +12 -0
- package/dist/updates/locks/update-helper-presence.js +27 -0
- package/dist/updates/retention/retention-cleanup.js +10 -9
- package/dist/updates/retention/retention-maintenance.d.ts +40 -0
- package/dist/updates/retention/retention-maintenance.js +95 -0
- package/dist/updates/retention/retention-prune-progress.js +4 -5
- package/dist/updates/retention/retirement-inventory.d.ts +13 -0
- package/dist/updates/retention/retirement-inventory.js +39 -31
- package/dist/updates/retention/retirement-records.d.ts +1 -4
- package/dist/updates/retention/retirement-records.js +18 -32
- package/dist/updates/retention/update-retention-marker.d.ts +4 -0
- package/dist/updates/retention/update-retention-marker.js +9 -14
- package/dist/updates/retention/update-retirement.d.ts +12 -0
- package/dist/updates/retention/update-retirement.js +59 -31
- package/dist/updates/update-adapter.d.ts +1 -23
- package/dist/updates/update-adapter.js +31 -24
- package/dist/updates/update-channel-store.d.ts +2 -1
- package/dist/updates/update-channel-store.js +6 -4
- package/dist/updates/update-manager.js +2 -2
- package/dist/updates/update-services.d.ts +1 -1
- package/dist/updates/update-services.js +9 -4
- package/dist/updates/update-state-store.d.ts +0 -2
- package/dist/updates/update-state-store.js +5 -12
- package/dist/updates/update-state.d.ts +6 -10
- package/dist/updates/update-state.js +1 -1
- package/dist/views/app-help.d.ts +1 -1
- package/dist/views/app-help.js +1 -3
- package/dist/views/appearance-surface.js +15 -8
- package/dist/views/update-surface.d.ts +1 -3
- package/dist/views/update-surface.js +2 -2
- package/package.json +18 -16
- package/src/app/application.tsx +13 -6
- package/src/appearance/appearance-host.tsx +17 -7
- package/src/appearance/appearance-preferences.ts +0 -1
- package/src/appearance/custom-theme-import.ts +99 -26
- package/src/appearance/custom-theme-library.ts +3 -2
- package/src/appearance/theme-file-importer.ts +3 -2
- package/src/appearance/theme-library-mutation.ts +20 -8
- package/src/appearance/theme-library-schema.ts +7 -0
- package/src/appearance/theme-library-store.ts +41 -26
- package/src/desktop/client-assets.ts +27 -12
- package/src/shell/app-shell.tsx +33 -13
- package/src/shell/app-utilities.tsx +7 -1
- package/src/shell/poll.ts +125 -0
- package/src/updates/feed/release-version.ts +11 -3
- package/src/updates/update-adapter.ts +27 -44
- package/src/updates/update-state.ts +7 -13
- package/src/views/app-help.tsx +1 -1
- package/src/views/appearance-surface.tsx +36 -8
- package/src/views/update-surface.tsx +0 -4
- package/templates/application/.github/workflows/release-assets.yml +2 -2
- package/templates/application/README.md +3 -3
- package/dist/native/cef-helper-download.d.ts +0 -1
- package/dist/native/cef-helper-download.js +0 -35
- package/src/desktop/client-response-lifecycle.ts +0 -305
|
@@ -24,8 +24,8 @@ masked `DESKTOP_UPDATE_SIGNING_KEY_B64` (base64 of the private key PEM) and
|
|
|
24
24
|
bucket credentials listed in that file. A GitLab-only app may remove the
|
|
25
25
|
`.github` workflows and `releaseWorkflows` from `release-config.json`.
|
|
26
26
|
|
|
27
|
-
The generated release control workflow uses `release-config.json` for daily
|
|
28
|
-
|
|
27
|
+
The generated release control workflow uses `release-config.json` for the daily
|
|
28
|
+
and stable channels. Run `bun install` and commit `bun.lock` before
|
|
29
29
|
pushing. The root `package.json` version is the default for both web and
|
|
30
30
|
desktop builds; release workflows can select their validated version through
|
|
31
31
|
`ADEA_APP_RELEASE_VERSION`. The generated `appConfig.version` is the initial
|
|
@@ -56,7 +56,7 @@ the descriptors. `create-adea-app` fills it from a canonical GitHub
|
|
|
56
56
|
`--source-url`; for another source host, pass `--repository OWNER/NAME`. The
|
|
57
57
|
Electrobun package copies this file beside the app worker. Managed startup
|
|
58
58
|
checks its app identity, repository, feed, and public keys against the generated
|
|
59
|
-
app configuration; the saved channel only selects `stable
|
|
59
|
+
app configuration; the saved channel only selects `stable` or `pre-release` (daily)
|
|
60
60
|
within that packaged trust. A missing key or malformed channel or staged update
|
|
61
61
|
stops managed startup and preserves update state.
|
|
62
62
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function downloadCefHelperInput(url: string, path: string, maxBytes: number): Promise<string>;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { open } from "node:fs/promises";
|
|
2
|
-
import { createHash } from "node:crypto";
|
|
3
|
-
// src/native/cef-helper-download.ts
|
|
4
|
-
async function downloadCefHelperInput(url, path, maxBytes) {
|
|
5
|
-
const hash = createHash("sha256");
|
|
6
|
-
const file = await open(path, "wx");
|
|
7
|
-
let size = 0;
|
|
8
|
-
let closeFailed = false;
|
|
9
|
-
let closeError;
|
|
10
|
-
try {
|
|
11
|
-
const response = await fetch(url, { signal: AbortSignal.timeout(9e5) });
|
|
12
|
-
if (!response.ok || !response.body) {
|
|
13
|
-
try {
|
|
14
|
-
response.body?.cancel().catch(() => {});
|
|
15
|
-
} catch {}
|
|
16
|
-
throw new Error("CEF helper download failed");
|
|
17
|
-
}
|
|
18
|
-
for await (const chunk of response.body) {
|
|
19
|
-
size += chunk.byteLength;
|
|
20
|
-
if (size > maxBytes) throw new Error("CEF helper download exceeded its size");
|
|
21
|
-
hash.update(chunk);
|
|
22
|
-
await file.writeFile(chunk);
|
|
23
|
-
}
|
|
24
|
-
} finally {
|
|
25
|
-
try {
|
|
26
|
-
await file.close();
|
|
27
|
-
} catch (error) {
|
|
28
|
-
closeFailed = true;
|
|
29
|
-
closeError = error;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
if (closeFailed) throw closeError;
|
|
33
|
-
return hash.digest("hex");
|
|
34
|
-
}
|
|
35
|
-
export { downloadCefHelperInput };
|
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
/** A request was admitted after the response lifecycle had started draining. */
|
|
2
|
-
export class ClientResponseLifecycleClosedError extends Error {
|
|
3
|
-
constructor() {
|
|
4
|
-
super('Client response lifecycle is closed')
|
|
5
|
-
this.name = 'ClientResponseLifecycleClosedError'
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export type ClientResponseLifecycleTracker = Readonly<{
|
|
10
|
-
/** Run an asset handler while registering it synchronously for shutdown drain. */
|
|
11
|
-
handle(factory: () => Response | PromiseLike<Response>): Promise<Response>
|
|
12
|
-
/** Pause admission and wait for current handlers and response bodies to finish naturally. */
|
|
13
|
-
quiesce(): Promise<void>
|
|
14
|
-
/** Resume admission after an aborted shutdown that has not started stopping the host. */
|
|
15
|
-
resume(): void
|
|
16
|
-
/** Stop admission, cancel outstanding response bodies, and await all cleanup. */
|
|
17
|
-
stopAndDrain(reason?: unknown): Promise<void>
|
|
18
|
-
readonly accepting: boolean
|
|
19
|
-
}>
|
|
20
|
-
|
|
21
|
-
type TrackedBody = Readonly<{
|
|
22
|
-
cancel(reason: unknown): Promise<void>
|
|
23
|
-
settled: Promise<void>
|
|
24
|
-
}>
|
|
25
|
-
|
|
26
|
-
type TrackedResponseBody = TrackedBody & Readonly<{ stream: ReadableStream<Uint8Array> }>
|
|
27
|
-
|
|
28
|
-
async function cancelClientResponse(response: Response, reason: unknown) {
|
|
29
|
-
const body = response.body
|
|
30
|
-
if (!body) return
|
|
31
|
-
if (body.locked || response.bodyUsed) {
|
|
32
|
-
throw new Error('Cannot safely cancel an untracked client response body')
|
|
33
|
-
}
|
|
34
|
-
await body.cancel(reason)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Tracks async asset handlers and the response bodies they create. The response
|
|
39
|
-
* body returned from `handle` remains owned by its caller for normal reads; this
|
|
40
|
-
* tracker keeps a reader so shutdown can cancel it even while the body is locked
|
|
41
|
-
* by the host's response writer.
|
|
42
|
-
*/
|
|
43
|
-
export function createClientResponseLifecycleTracker(): ClientResponseLifecycleTracker {
|
|
44
|
-
let accepting = true
|
|
45
|
-
let drain: Promise<void> | undefined
|
|
46
|
-
const handlers = new Set<Promise<void>>()
|
|
47
|
-
const bodies = new Set<TrackedBody>()
|
|
48
|
-
const cleanupFailures: unknown[] = []
|
|
49
|
-
let stopped = false
|
|
50
|
-
|
|
51
|
-
const rememberFailure = (error: unknown) => {
|
|
52
|
-
cleanupFailures.push(error)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const trackBody = (source: ReadableStream<Uint8Array>): TrackedResponseBody => {
|
|
56
|
-
const reader = source.getReader()
|
|
57
|
-
const pendingReads = new Set<ReturnType<typeof reader.read>>()
|
|
58
|
-
const pendingPulls = new Set<Promise<void>>()
|
|
59
|
-
let controller: ReadableStreamDefaultController<Uint8Array> | undefined
|
|
60
|
-
let terminal = false
|
|
61
|
-
let sourceClosed = false
|
|
62
|
-
let sourceFailureRecorded = false
|
|
63
|
-
let cancelRequested = false
|
|
64
|
-
let cancelTask: Promise<void> | undefined
|
|
65
|
-
let cancelSettled = false
|
|
66
|
-
let settleBody!: () => void
|
|
67
|
-
const settled = new Promise<void>((resolve) => {
|
|
68
|
-
settleBody = resolve
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
const settleIfReady = () => {
|
|
72
|
-
if (
|
|
73
|
-
terminal &&
|
|
74
|
-
pendingReads.size === 0 &&
|
|
75
|
-
pendingPulls.size === 0 &&
|
|
76
|
-
(!cancelRequested || cancelSettled)
|
|
77
|
-
) {
|
|
78
|
-
bodies.delete(body)
|
|
79
|
-
settleBody()
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const closeAfterPendingPulls = () => {
|
|
84
|
-
if (sourceClosed && pendingReads.size === 0 && pendingPulls.size === 0) closeOutput()
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const closeOutput = () => {
|
|
88
|
-
if (terminal) return
|
|
89
|
-
terminal = true
|
|
90
|
-
try {
|
|
91
|
-
controller?.close()
|
|
92
|
-
} catch {
|
|
93
|
-
// A concurrent source error or consumer cancellation already closed it.
|
|
94
|
-
}
|
|
95
|
-
settleIfReady()
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const errorOutput = (error: unknown) => {
|
|
99
|
-
if (terminal) return
|
|
100
|
-
if (!sourceFailureRecorded) {
|
|
101
|
-
sourceFailureRecorded = true
|
|
102
|
-
rememberFailure(error)
|
|
103
|
-
}
|
|
104
|
-
terminal = true
|
|
105
|
-
try {
|
|
106
|
-
controller?.error(error)
|
|
107
|
-
} catch {
|
|
108
|
-
// The response writer already canceled or closed the output stream.
|
|
109
|
-
}
|
|
110
|
-
settleIfReady()
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const cancel = (reason: unknown): Promise<void> => {
|
|
114
|
-
if (cancelTask) return cancelTask
|
|
115
|
-
if (terminal) return settled
|
|
116
|
-
|
|
117
|
-
cancelRequested = true
|
|
118
|
-
try {
|
|
119
|
-
controller?.close()
|
|
120
|
-
} catch {
|
|
121
|
-
// The output stream may already be closed or errored.
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
let operation: Promise<void>
|
|
125
|
-
try {
|
|
126
|
-
operation = reader.cancel(reason)
|
|
127
|
-
} catch (error) {
|
|
128
|
-
operation = Promise.reject(error)
|
|
129
|
-
}
|
|
130
|
-
cancelTask = operation
|
|
131
|
-
.then(
|
|
132
|
-
() => {},
|
|
133
|
-
(error: unknown) => {
|
|
134
|
-
rememberFailure(error)
|
|
135
|
-
throw error
|
|
136
|
-
}
|
|
137
|
-
)
|
|
138
|
-
.finally(() => {
|
|
139
|
-
cancelSettled = true
|
|
140
|
-
terminal = true
|
|
141
|
-
settleIfReady()
|
|
142
|
-
})
|
|
143
|
-
return cancelTask
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const body: TrackedBody = { cancel, settled }
|
|
147
|
-
bodies.add(body)
|
|
148
|
-
|
|
149
|
-
const output = new ReadableStream<Uint8Array>(
|
|
150
|
-
{
|
|
151
|
-
start(value) {
|
|
152
|
-
controller = value
|
|
153
|
-
},
|
|
154
|
-
pull(value) {
|
|
155
|
-
if (terminal || cancelRequested) return
|
|
156
|
-
let operation!: Promise<void>
|
|
157
|
-
operation = Promise.resolve().then(async () => {
|
|
158
|
-
let read: ReturnType<typeof reader.read> | undefined
|
|
159
|
-
try {
|
|
160
|
-
read = reader.read()
|
|
161
|
-
pendingReads.add(read)
|
|
162
|
-
const result = await read
|
|
163
|
-
if (cancelRequested || terminal) return
|
|
164
|
-
if (result.done) {
|
|
165
|
-
sourceClosed = true
|
|
166
|
-
closeOutput()
|
|
167
|
-
return
|
|
168
|
-
}
|
|
169
|
-
value.enqueue(result.value)
|
|
170
|
-
} catch (error) {
|
|
171
|
-
if (!cancelRequested) errorOutput(error)
|
|
172
|
-
} finally {
|
|
173
|
-
if (read) pendingReads.delete(read)
|
|
174
|
-
pendingPulls.delete(operation)
|
|
175
|
-
closeAfterPendingPulls()
|
|
176
|
-
settleIfReady()
|
|
177
|
-
}
|
|
178
|
-
})
|
|
179
|
-
pendingPulls.add(operation)
|
|
180
|
-
return operation
|
|
181
|
-
},
|
|
182
|
-
cancel(reason) {
|
|
183
|
-
return cancel(reason)
|
|
184
|
-
},
|
|
185
|
-
},
|
|
186
|
-
// A zero-sized queue prevents the wrapper from reading ahead of its consumer.
|
|
187
|
-
{ highWaterMark: 0 }
|
|
188
|
-
)
|
|
189
|
-
|
|
190
|
-
// `closed` observes source errors and empty completion even before the host
|
|
191
|
-
// asks to read the wrapped response body.
|
|
192
|
-
void reader.closed.then(
|
|
193
|
-
() => {
|
|
194
|
-
if (!cancelRequested) {
|
|
195
|
-
sourceClosed = true
|
|
196
|
-
closeAfterPendingPulls()
|
|
197
|
-
}
|
|
198
|
-
},
|
|
199
|
-
(error: unknown) => {
|
|
200
|
-
if (!cancelRequested) errorOutput(error)
|
|
201
|
-
}
|
|
202
|
-
)
|
|
203
|
-
|
|
204
|
-
return { ...body, stream: output }
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
const handle = (factory: () => Response | PromiseLike<Response>): Promise<Response> => {
|
|
208
|
-
if (!accepting) return Promise.reject(new ClientResponseLifecycleClosedError())
|
|
209
|
-
|
|
210
|
-
let releaseHandler!: () => void
|
|
211
|
-
const handler = new Promise<void>((resolve) => {
|
|
212
|
-
releaseHandler = resolve
|
|
213
|
-
})
|
|
214
|
-
handlers.add(handler)
|
|
215
|
-
|
|
216
|
-
return (async () => {
|
|
217
|
-
try {
|
|
218
|
-
const response = await factory()
|
|
219
|
-
if (!(response instanceof Response))
|
|
220
|
-
throw new TypeError('Asset handler did not return a Response')
|
|
221
|
-
|
|
222
|
-
if (!accepting) {
|
|
223
|
-
try {
|
|
224
|
-
await cancelClientResponse(response, new ClientResponseLifecycleClosedError())
|
|
225
|
-
} catch (error) {
|
|
226
|
-
rememberFailure(error)
|
|
227
|
-
throw error
|
|
228
|
-
}
|
|
229
|
-
throw new ClientResponseLifecycleClosedError()
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
if (!response.body) return response
|
|
233
|
-
if (response.body.locked || response.bodyUsed) {
|
|
234
|
-
const error = new Error('Cannot track a locked or consumed client response body')
|
|
235
|
-
rememberFailure(error)
|
|
236
|
-
throw error
|
|
237
|
-
}
|
|
238
|
-
const tracked = trackBody(response.body)
|
|
239
|
-
try {
|
|
240
|
-
return new Response(tracked.stream, {
|
|
241
|
-
status: response.status,
|
|
242
|
-
statusText: response.statusText,
|
|
243
|
-
headers: response.headers,
|
|
244
|
-
})
|
|
245
|
-
} catch (error) {
|
|
246
|
-
// The tracked source remains registered so drain can still cancel it.
|
|
247
|
-
rememberFailure(error)
|
|
248
|
-
throw error
|
|
249
|
-
}
|
|
250
|
-
} finally {
|
|
251
|
-
handlers.delete(handler)
|
|
252
|
-
releaseHandler()
|
|
253
|
-
}
|
|
254
|
-
})()
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
const quiesce = () => {
|
|
258
|
-
if (stopped) return Promise.reject(new ClientResponseLifecycleClosedError())
|
|
259
|
-
accepting = false
|
|
260
|
-
// With admission paused, active handlers can only settle or cancel their
|
|
261
|
-
// late response. No handler can add a new tracked body after this snapshot.
|
|
262
|
-
return Promise.all([...handlers, ...[...bodies].map((body) => body.settled)]).then(() => {})
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
const resume = () => {
|
|
266
|
-
if (stopped) throw new ClientResponseLifecycleClosedError()
|
|
267
|
-
accepting = true
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
const stopAndDrain = (reason: unknown = new ClientResponseLifecycleClosedError()) => {
|
|
271
|
-
accepting = false
|
|
272
|
-
if (drain) return drain
|
|
273
|
-
stopped = true
|
|
274
|
-
|
|
275
|
-
const pendingHandlers = [...handlers]
|
|
276
|
-
const pendingBodies = [...bodies]
|
|
277
|
-
const cancellations = pendingBodies.map((body) => body.cancel(reason))
|
|
278
|
-
drain = (async () => {
|
|
279
|
-
const results = await Promise.allSettled([
|
|
280
|
-
...pendingHandlers,
|
|
281
|
-
...pendingBodies.map((body) => body.settled),
|
|
282
|
-
...cancellations,
|
|
283
|
-
])
|
|
284
|
-
const failures = results.flatMap((result) =>
|
|
285
|
-
result.status === 'rejected' ? [result.reason] : []
|
|
286
|
-
)
|
|
287
|
-
failures.push(...cleanupFailures)
|
|
288
|
-
const uniqueFailures = [...new Set(failures)]
|
|
289
|
-
if (uniqueFailures.length > 0) {
|
|
290
|
-
throw new AggregateError(uniqueFailures, 'Client response cleanup failed')
|
|
291
|
-
}
|
|
292
|
-
})()
|
|
293
|
-
return drain
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
return {
|
|
297
|
-
handle,
|
|
298
|
-
quiesce,
|
|
299
|
-
resume,
|
|
300
|
-
stopAndDrain,
|
|
301
|
-
get accepting() {
|
|
302
|
-
return accepting
|
|
303
|
-
},
|
|
304
|
-
}
|
|
305
|
-
}
|