@vite-hub/runtime 0.1.0 → 0.3.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 +151 -117
- package/dist/durability.d.ts +107 -0
- package/dist/durability.js +168 -0
- package/dist/error-diagnostics-BKICpwZp.js +85 -0
- package/dist/error-diagnostics-BsJr9VdW.d.ts +15 -0
- package/dist/{errors-CbqHQTvn.js → errors-BEomN3fX.js} +1 -1
- package/dist/{execution-budget-D8SwJE8_.d.ts → execution-budget-BPXbISEt.d.ts} +9 -6
- package/dist/index-Bcl-Hr-a.d.ts +678 -0
- package/dist/index.d.ts +5 -4
- package/dist/index.js +5 -4
- package/dist/internal/drain.d.ts +17 -0
- package/dist/internal/drain.js +75 -0
- package/dist/internal/execution-budget.d.ts +1 -1
- package/dist/internal/grant.js +2 -2
- package/dist/internal/h3.d.ts +42 -0
- package/dist/internal/h3.js +181 -0
- package/dist/{node.d.ts → internal/node.d.ts} +2 -2
- package/dist/{node.js → internal/node.js} +4 -4
- package/dist/internal/public-url.d.ts +2 -0
- package/dist/internal/public-url.js +2 -0
- package/dist/internal/run-scope.d.ts +11 -0
- package/dist/internal/run-scope.js +30 -0
- package/dist/internal/runtime-type.d.ts +9 -2
- package/dist/internal/runtime-type.js +3 -2
- package/dist/{shutdown.d.ts → internal/shutdown.d.ts} +1 -1
- package/dist/{shutdown.js → internal/shutdown.js} +1 -1
- package/dist/internal/test-mode-setup.d.ts +7 -0
- package/dist/internal/test-mode-setup.js +114 -0
- package/dist/internal/test-mode.d.ts +32 -0
- package/dist/internal/test-mode.js +9 -0
- package/dist/operations.d.ts +167 -0
- package/dist/operations.js +406 -0
- package/dist/public-url-1WeOw54Z.d.ts +34 -0
- package/dist/public-url-B6x0HMgY.js +140 -0
- package/dist/{src-jy-gyPPu.js → request-context-CP9NhgLL.js} +635 -551
- package/dist/runtime-type-BftydMAf.js +88 -0
- package/package.json +61 -26
- package/dist/drain.d.ts +0 -1
- package/dist/drain.js +0 -69
- package/dist/error-diagnostics-Bkym4e6y.d.ts +0 -12
- package/dist/h3.d.ts +0 -49
- package/dist/h3.js +0 -404
- package/dist/index-Rl4DbP8B.d.ts +0 -574
- package/dist/runtime-type-CgfU6SWl.js +0 -52
|
@@ -0,0 +1,678 @@
|
|
|
1
|
+
import "./error-diagnostics-BsJr9VdW.js";
|
|
2
|
+
import "./execution-budget-BPXbISEt.js";
|
|
3
|
+
import { Diagnostic, DiagnosticDefinition, DiagnosticJSON, Diagnostics } from "nostics";
|
|
4
|
+
import { StandardContext } from "standard-context";
|
|
5
|
+
//#region ../internal/dist/runtime/cloudflare-env.d.ts
|
|
6
|
+
//#region src/runtime/cloudflare-env.d.ts
|
|
7
|
+
interface CloudflareWorkerExecutionContext {
|
|
8
|
+
waitUntil?: (promise: Promise<unknown>) => void;
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/standard-context.d.ts
|
|
12
|
+
/** The host data that ViteHub puts in `runtime` of a Standard Context. */
|
|
13
|
+
interface ViteHubRuntime {
|
|
14
|
+
/** The Cloudflare bindings and execution context of the request. A host can pass either one without the other. */
|
|
15
|
+
cloudflare?: {
|
|
16
|
+
context?: CloudflareWorkerExecutionContext;
|
|
17
|
+
env?: Record<string, unknown>;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* The client IP address that the host reports. ViteHub does not read it from forwarding headers.
|
|
21
|
+
* Standard Context has no client address field yet (https://github.com/standard-servers/proposals/issues/4).
|
|
22
|
+
*/
|
|
23
|
+
clientAddress?: string;
|
|
24
|
+
}
|
|
25
|
+
/** The `~standard` properties of a request event in a ViteHub app. */
|
|
26
|
+
type ViteHubStandardProps = StandardContext.Props<ViteHubRuntime, void>;
|
|
27
|
+
/** A request event in a ViteHub app: any server context with Standard Context properties. */
|
|
28
|
+
type ViteHubContext<C = {}> = StandardContext<C, ViteHubRuntime, void>;
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/internal/trace-attributes.d.ts
|
|
31
|
+
declare function isTraceContentAttributeKey(key: string): boolean;
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/result.d.ts
|
|
34
|
+
/**
|
|
35
|
+
* Error of a ViteHub operation. It is a Nostics diagnostic with a typed `code`.
|
|
36
|
+
*
|
|
37
|
+
* - `code` names the failure, for example `KV_INVALID_CURSOR`. `name` has the same code.
|
|
38
|
+
* - `why` tells what went wrong. `message` has the same text.
|
|
39
|
+
* - `fix` tells what to do next.
|
|
40
|
+
* - `docs` links to the code on vitehub.dev.
|
|
41
|
+
* - `cause` keeps the lower-level error, for example the provider error.
|
|
42
|
+
* - `data` keeps catalog metadata in memory. Its type is inferred by `defineErrors()`.
|
|
43
|
+
*/
|
|
44
|
+
interface ResultError<TCode extends string = string, TData = unknown> extends Diagnostic<TData, TCode> {
|
|
45
|
+
/** Retains the Nostics serializer type for compatibility; runtime JSON is redacted. */
|
|
46
|
+
toJSON(): DiagnosticJSON<TData> & {
|
|
47
|
+
code: TCode;
|
|
48
|
+
name: TCode;
|
|
49
|
+
why: string;
|
|
50
|
+
fix: string | undefined;
|
|
51
|
+
docs: string | undefined;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* `[error, data]` tuple that each ViteHub runtime operation returns.
|
|
56
|
+
* Check `error` first. When `error` is `undefined`, `data` has the value.
|
|
57
|
+
*/
|
|
58
|
+
type Result<TData, TCode extends string = string> = [error: ResultError<TCode>, data: undefined] | [error: undefined, data: TData];
|
|
59
|
+
/** Code map that `defineErrors()` accepts. `is` is reserved for `ErrorCatalog.is`. */
|
|
60
|
+
type ErrorCodes = Record<string, DiagnosticDefinition> & {
|
|
61
|
+
is?: never;
|
|
62
|
+
};
|
|
63
|
+
type CatalogCode<TCodes> = Exclude<keyof TCodes, "is"> & string;
|
|
64
|
+
type CatalogHandles<TCodes extends Record<string, DiagnosticDefinition>> = Diagnostics<TCodes, []>;
|
|
65
|
+
type CatalogData<TCodes extends Record<string, DiagnosticDefinition>, TCode extends CatalogCode<TCodes>> = ReturnType<CatalogHandles<TCodes>[TCode]>["data"];
|
|
66
|
+
/** One code of an error catalog. Call it to create the error, or use `is` to check an error. */
|
|
67
|
+
interface ErrorHandle<TArgs extends unknown[], TCode extends string, TData> {
|
|
68
|
+
(...args: TArgs): ResultError<TCode, TData>;
|
|
69
|
+
/**
|
|
70
|
+
* Checks if `error` is a live Nostics error with this code, and narrows its `data`.
|
|
71
|
+
* It reads `code`, so it also accepts an error from another copy of the package or another realm.
|
|
72
|
+
* Safe to pass unbound, for example `errors.filter(catalog.CODE.is)`.
|
|
73
|
+
*/
|
|
74
|
+
is: (error: unknown) => error is ResultError<TCode, TData>;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Error catalog of one package. Each code creates a `ResultError` with that code.
|
|
78
|
+
* `is` checks if an error has a code of this catalog. `is` is not enumerable, so `Object.keys()` gives only the codes.
|
|
79
|
+
* Use `InferDiagnosticCodes<typeof catalog>` from `nostics` for the union of the codes.
|
|
80
|
+
*/
|
|
81
|
+
type ErrorCatalog<TCodes extends Record<string, DiagnosticDefinition>> = {
|
|
82
|
+
/**
|
|
83
|
+
* Checks if `error` is a live Nostics error with a code of this catalog, and narrows its `code` and `data`.
|
|
84
|
+
* It reads `code`, so it also accepts an error from another copy of the package or another realm.
|
|
85
|
+
*/
|
|
86
|
+
is: (error: unknown) => error is { [TCode in CatalogCode<TCodes>]: ResultError<TCode, CatalogData<TCodes, TCode>>; }[CatalogCode<TCodes>];
|
|
87
|
+
} & { [TCode in CatalogCode<TCodes>]: ErrorHandle<Parameters<CatalogHandles<TCodes>[TCode]>, TCode, CatalogData<TCodes, TCode>>; };
|
|
88
|
+
interface DefineErrorsOptions<TCodes extends Record<string, DiagnosticDefinition>> {
|
|
89
|
+
/** Each code with a `why` and a `fix`. */
|
|
90
|
+
codes: TCodes;
|
|
91
|
+
/** Base URL of the diagnostics pages, which have one page for each code. The `docs` URL of an error is `<docs>/<code in lowercase>`. */
|
|
92
|
+
docs: string;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Prepares a recognized diagnostic for a result, keeping its metadata in memory.
|
|
96
|
+
* Reuses mutable diagnostics; copies diagnostics whose name or serializer cannot be replaced.
|
|
97
|
+
* Sets name to code to match the result contract, including diagnostics renamed by their owner.
|
|
98
|
+
* The caller owns code allowlisting and the public text. JSON includes only the public fields.
|
|
99
|
+
*/
|
|
100
|
+
declare function toResultError<TCode extends string, TData>(error: (Diagnostic<TData> | ResultError<string, TData>) & {
|
|
101
|
+
readonly code: TCode;
|
|
102
|
+
}): ResultError<TCode, TData>;
|
|
103
|
+
/**
|
|
104
|
+
* Defines the error catalog of a package with Nostics.
|
|
105
|
+
* Return runtime errors as `[error, undefined]`. Throw definition and config errors.
|
|
106
|
+
*/
|
|
107
|
+
declare function defineErrors<const TCodes extends ErrorCodes>(options: DefineErrorsOptions<TCodes>): ErrorCatalog<TCodes>;
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/lease.d.ts
|
|
110
|
+
type LeaseOperation = "acquire" | "get" | "release" | "renew";
|
|
111
|
+
/** The codes that lease operations return. */
|
|
112
|
+
type LeaseErrorCode = "RUNTIME_LEASE_FAILED" | "RUNTIME_LEASE_INVALID_TTL";
|
|
113
|
+
/** One live lease as the store keeps it. */
|
|
114
|
+
interface LeaseRecord {
|
|
115
|
+
/** The value that the caller locks, such as `schedule:daily:2026-11-09`. */
|
|
116
|
+
key: string;
|
|
117
|
+
/** A new random ID for each acquire. Release and renew act only when the stored ID is still this one. */
|
|
118
|
+
id: string;
|
|
119
|
+
/** The label from `acquire()`, such as an instance name. It is for inspection only. */
|
|
120
|
+
owner?: string;
|
|
121
|
+
/** When the lease ends, from the clock of the store. */
|
|
122
|
+
expiresAt: Date;
|
|
123
|
+
}
|
|
124
|
+
/** A lease that this caller holds. */
|
|
125
|
+
interface Lease extends LeaseRecord {
|
|
126
|
+
/**
|
|
127
|
+
* Moves the end of the lease to `ttl` seconds from now. The default is the TTL of `acquire()`. Resolves `false` when
|
|
128
|
+
* the lease is no longer this caller's, because another caller acquired it after it expired. On `true`, `expiresAt`
|
|
129
|
+
* has the new end.
|
|
130
|
+
*/
|
|
131
|
+
renew(options?: {
|
|
132
|
+
ttl?: number;
|
|
133
|
+
}): Promise<Result<boolean, LeaseErrorCode>>;
|
|
134
|
+
/** Frees the lease. Resolves `false` and changes nothing when another caller holds the key now. */
|
|
135
|
+
release(): Promise<Result<boolean, "RUNTIME_LEASE_FAILED">>;
|
|
136
|
+
}
|
|
137
|
+
interface LeaseAcquireOptions {
|
|
138
|
+
/** Seconds until the lease ends when the holder does not renew or release it. Fractions are allowed. */
|
|
139
|
+
ttl: number;
|
|
140
|
+
/** A label for the holder, such as an instance name. Acquire does not compare it. */
|
|
141
|
+
owner?: string;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Gives one caller at a time a lease on a key. A lease ends at `release()` or when its TTL passes, so a holder that
|
|
145
|
+
* crashes blocks the key only until then. Leases are not reentrant: a held key refuses every other acquire, also from
|
|
146
|
+
* the same owner.
|
|
147
|
+
*/
|
|
148
|
+
interface LeaseStore {
|
|
149
|
+
/** Takes the lease when the key is free or its lease expired. Resolves `null` when another caller holds it. */
|
|
150
|
+
acquire(key: string, options: LeaseAcquireOptions): Promise<Result<Lease | null, LeaseErrorCode>>;
|
|
151
|
+
/** The live lease on the key, or `null`. */
|
|
152
|
+
get(key: string): Promise<Result<LeaseRecord | null, "RUNTIME_LEASE_FAILED">>;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Leases in the memory of this process. Use it for one instance and for tests. Several instances need a shared store,
|
|
156
|
+
* such as `createSqlLeaseStore()`.
|
|
157
|
+
*/
|
|
158
|
+
declare function createMemoryLeaseStore(): LeaseStore;
|
|
159
|
+
/**
|
|
160
|
+
* The SQL connection that `createSqlLeaseStore()` uses. `query()` runs one statement with positional parameters and
|
|
161
|
+
* resolves its rows as objects keyed by column name.
|
|
162
|
+
*
|
|
163
|
+
* - `postgresql`: the SQL text uses `$1`, `$2`, and so on, like postgres.js `sql.unsafe(text, params)`.
|
|
164
|
+
* - `sqlite`: the SQL text uses `?`, like libSQL `client.execute({ sql, args })`. The store runs a statement that fails
|
|
165
|
+
* with `SQLITE_BUSY` again. Across several processes, use Postgres, remote libSQL, or `node:sqlite`. A local libSQL
|
|
166
|
+
* `file:` client is for one process only: after `SQLITE_BUSY` it can lose writes that it reported as done.
|
|
167
|
+
*/
|
|
168
|
+
interface LeaseSqlClient {
|
|
169
|
+
dialect: "postgresql" | "sqlite";
|
|
170
|
+
query(sql: string, params: LeaseSqlParam[]): Promise<readonly Record<string, unknown>[]>;
|
|
171
|
+
}
|
|
172
|
+
/** The parameter values that the lease statements pass. */
|
|
173
|
+
type LeaseSqlParam = string | number | null;
|
|
174
|
+
/** The table of `createSqlLeaseStore()`. The store creates it when it is missing. */
|
|
175
|
+
declare const leaseTable = "vitehub_leases";
|
|
176
|
+
/**
|
|
177
|
+
* Leases in a SQL table, shared by every process that uses the same Database. Each operation is one statement, so
|
|
178
|
+
* two processes that acquire a key at the same time get one winner. Expiry uses the clock of the Database, not the
|
|
179
|
+
* clocks of the hosts. Works on Postgres and on SQLite 3.35 or later, such as libSQL.
|
|
180
|
+
*/
|
|
181
|
+
declare function createSqlLeaseStore(client: LeaseSqlClient): LeaseStore;
|
|
182
|
+
//#endregion
|
|
183
|
+
//#region src/route-segment.d.ts
|
|
184
|
+
declare function encodeRouteSegment(value: string): string;
|
|
185
|
+
declare function decodeRouteSegment(segment: string): string | undefined;
|
|
186
|
+
//#endregion
|
|
187
|
+
//#region src/hosted-console.d.ts
|
|
188
|
+
/** The origin of the hosted Console. */
|
|
189
|
+
declare const hostedConsoleOrigin = "https://console.vitehub.dev";
|
|
190
|
+
/**
|
|
191
|
+
* The Console path of a link, such as `/agents/bot/invocations/abc?tab=trace`, or `undefined` when the value is not a
|
|
192
|
+
* Console path. A Console path starts with one `/`. Absolute URLs, protocol-relative URLs, and backslashes are not
|
|
193
|
+
* Console paths, so a link cannot send the browser to another site. A path that starts with `/_vitehub`, as on a
|
|
194
|
+
* Console that the app serves, loses that prefix.
|
|
195
|
+
*/
|
|
196
|
+
declare function normalizeConsolePath(path: string): string | undefined;
|
|
197
|
+
/**
|
|
198
|
+
* The project URL of a link: the app origin and its application mount, such as `https://app.example.com/portal`, or
|
|
199
|
+
* `undefined` when the URL cannot be a project. A project URL is `https:`, or `http:` on a loopback host, and has no
|
|
200
|
+
* user name or password.
|
|
201
|
+
*/
|
|
202
|
+
declare function normalizeConsoleProjectUrl(projectUrl: string): string | undefined;
|
|
203
|
+
/**
|
|
204
|
+
* The hosted Console URL that opens one page of a project, such as
|
|
205
|
+
* `https://console.vitehub.dev/open?project=https%3A%2F%2Fapp.example.com&path=%2Fkv`.
|
|
206
|
+
*
|
|
207
|
+
* `projectUrl` is the app origin with its application mount, such as `https://app.example.com/portal`. `path` is the
|
|
208
|
+
* Console path, such as `/agents/bot/invocations/abc`. The hosted Console switches to the project when this browser
|
|
209
|
+
* linked it, or asks the person to link it first. The URL holds no secret.
|
|
210
|
+
*
|
|
211
|
+
* Throws `RUNTIME_CONSOLE_PROJECT_URL_INVALID` when `projectUrl` is not `https:` (or `http:` on a loopback host), and
|
|
212
|
+
* `RUNTIME_CONSOLE_PATH_INVALID` when `path` is not a Console path.
|
|
213
|
+
*/
|
|
214
|
+
declare function hostedConsoleUrl(projectUrl: string, path: string, consoleOrigin?: string): string;
|
|
215
|
+
//#endregion
|
|
216
|
+
//#region src/diagnostics.d.ts
|
|
217
|
+
type RuntimeDiagnosticLevel = "debug" | "error" | "info" | "warn";
|
|
218
|
+
type RuntimeResourceScope = "container" | "host" | "process" | "service" | "workload";
|
|
219
|
+
type RuntimeResourceUnit = "bytes" | "count" | "microseconds" | "ratio";
|
|
220
|
+
interface RuntimeDiagnosticError {
|
|
221
|
+
cause?: RuntimeDiagnosticError;
|
|
222
|
+
code?: number | string;
|
|
223
|
+
details?: Readonly<Record<string, unknown>>;
|
|
224
|
+
docs?: string;
|
|
225
|
+
errors?: readonly RuntimeDiagnosticError[];
|
|
226
|
+
fix?: string;
|
|
227
|
+
message: string;
|
|
228
|
+
name?: string;
|
|
229
|
+
requestId?: string;
|
|
230
|
+
sources?: readonly string[];
|
|
231
|
+
stack?: string;
|
|
232
|
+
status?: number | string;
|
|
233
|
+
statusCode?: number | string;
|
|
234
|
+
}
|
|
235
|
+
interface RuntimeDiagnosticEvent {
|
|
236
|
+
attributes?: Readonly<Record<string, unknown>>;
|
|
237
|
+
component: string;
|
|
238
|
+
error?: RuntimeDiagnosticError;
|
|
239
|
+
level: RuntimeDiagnosticLevel;
|
|
240
|
+
name: string;
|
|
241
|
+
timestamp: string;
|
|
242
|
+
}
|
|
243
|
+
type RuntimeDiagnosticReporter = (event: RuntimeDiagnosticEvent) => MaybePromise<void>;
|
|
244
|
+
interface RuntimeResourceObservation {
|
|
245
|
+
name: string;
|
|
246
|
+
scope: RuntimeResourceScope;
|
|
247
|
+
source: string;
|
|
248
|
+
unit: RuntimeResourceUnit;
|
|
249
|
+
value: number;
|
|
250
|
+
}
|
|
251
|
+
interface RuntimeResourceSupport {
|
|
252
|
+
reason?: "collection-failed" | "not-isolated" | "permission-denied" | "unsupported-runtime" | (string & {});
|
|
253
|
+
scope: RuntimeResourceScope;
|
|
254
|
+
source: string;
|
|
255
|
+
supported: boolean;
|
|
256
|
+
}
|
|
257
|
+
interface RuntimeResourceSnapshot {
|
|
258
|
+
observedAt: string;
|
|
259
|
+
observations: readonly RuntimeResourceObservation[];
|
|
260
|
+
support?: readonly RuntimeResourceSupport[];
|
|
261
|
+
}
|
|
262
|
+
interface RuntimeResourceInspector {
|
|
263
|
+
inspect(options?: {
|
|
264
|
+
signal?: AbortSignal;
|
|
265
|
+
}): MaybePromise<RuntimeResourceSnapshot>;
|
|
266
|
+
}
|
|
267
|
+
interface RuntimeDiagnosticErrorOptions {
|
|
268
|
+
includeStack?: boolean;
|
|
269
|
+
maxDepth?: number;
|
|
270
|
+
maxErrors?: number;
|
|
271
|
+
maxStringLength?: number;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Recognizes a live Nostics error across bundled copies. This does not make its fields safe for public responses.
|
|
275
|
+
* nostics' own check matches only its own copy (https://github.com/vercel-labs/nostics/pull/40).
|
|
276
|
+
*/
|
|
277
|
+
declare function isRuntimeDiagnostic(error: unknown): error is Diagnostic<unknown> | ResultError;
|
|
278
|
+
/** Formats bounded developer diagnostics without exposing causes or stacks. */
|
|
279
|
+
declare function formatRuntimeDiagnosticError(error: unknown): string;
|
|
280
|
+
declare function normalizeRuntimeDiagnosticError(error: unknown, options?: RuntimeDiagnosticErrorOptions): RuntimeDiagnosticError;
|
|
281
|
+
//#endregion
|
|
282
|
+
//#region src/errors.d.ts
|
|
283
|
+
type ViteHubErrorDetail = boolean | null | number | string | readonly ViteHubErrorDetail[] | {
|
|
284
|
+
readonly [key: string]: ViteHubErrorDetail | undefined;
|
|
285
|
+
};
|
|
286
|
+
type ViteHubErrorDetails = Readonly<Record<string, ViteHubErrorDetail | undefined>>;
|
|
287
|
+
interface ViteHubErrorShape<TCode extends string = string, TDetails extends ViteHubErrorDetails = ViteHubErrorDetails> {
|
|
288
|
+
code: TCode;
|
|
289
|
+
details?: TDetails;
|
|
290
|
+
message: string;
|
|
291
|
+
name: "ViteHubError";
|
|
292
|
+
requestId?: string;
|
|
293
|
+
}
|
|
294
|
+
interface ViteHubErrorOptions<TDetails extends ViteHubErrorDetails = ViteHubErrorDetails> extends ErrorOptions {
|
|
295
|
+
details?: TDetails;
|
|
296
|
+
requestId?: string;
|
|
297
|
+
}
|
|
298
|
+
declare class ViteHubError<TCode extends string = string, TDetails extends ViteHubErrorDetails = ViteHubErrorDetails> extends Error {
|
|
299
|
+
readonly code: TCode;
|
|
300
|
+
readonly details?: TDetails;
|
|
301
|
+
readonly requestId?: string;
|
|
302
|
+
constructor(code: TCode, message: string, options?: ViteHubErrorOptions<TDetails>);
|
|
303
|
+
toJSON(): ViteHubErrorShape<TCode, TDetails>;
|
|
304
|
+
}
|
|
305
|
+
declare function getViteHubErrorShape(value: unknown): ViteHubErrorShape | undefined;
|
|
306
|
+
declare function isViteHubError(value: unknown): value is ViteHubErrorShape;
|
|
307
|
+
//#endregion
|
|
308
|
+
//#region src/request-context.d.ts
|
|
309
|
+
type RuntimeName = "cloudflare-agents" | "deno" | "unknown" | "vercel" | "vite";
|
|
310
|
+
type RuntimeContextOptions = Omit<RuntimeContextInput, "event" | "runtime"> & {
|
|
311
|
+
runtime?: RuntimeName;
|
|
312
|
+
};
|
|
313
|
+
type RequestRuntimeContext<TOptions extends RuntimeContextOptions = {}> = CreatedRuntimeContext<TOptions & {
|
|
314
|
+
cloudflare?: RuntimeHostContext["cloudflare"];
|
|
315
|
+
event: ViteHubContext;
|
|
316
|
+
request: Request;
|
|
317
|
+
runtime: RuntimeName;
|
|
318
|
+
vercel?: RuntimeHostContext["vercel"];
|
|
319
|
+
}>;
|
|
320
|
+
/** Keep one Standard Context per Request, even when it cannot be extended. A value set by the host stays. */
|
|
321
|
+
declare function installRequestStandardContext(request: Request, standard?: ViteHubStandardProps): ViteHubStandardProps;
|
|
322
|
+
/**
|
|
323
|
+
* Return the Standard Context of a web Request or of a request event. In a Fetchable server entry, pass the
|
|
324
|
+
* Request: `getStandardContext(request)`. In a ViteHub app, Nitro sets `~standard` on each event and on its
|
|
325
|
+
* Request, so ViteHub keeps the response headers that primitives set. Throws `RUNTIME_R0015` for an event without
|
|
326
|
+
* Standard Context.
|
|
327
|
+
*/
|
|
328
|
+
declare function getStandardContext(value: Request | ViteHubContext): ViteHubStandardProps;
|
|
329
|
+
/**
|
|
330
|
+
* Adds the prepared response of a plain Fetch host to the Response that a ViteHub route returns, as H3 adds it in a
|
|
331
|
+
* ViteHub app: `set-cookie` values join the ones of the Response, and other headers replace them. The headers move,
|
|
332
|
+
* so a host that also copies `res.headers` does not send them twice. With another vendor, such as H3, the host adds
|
|
333
|
+
* the prepared response, and `response` comes back as it is.
|
|
334
|
+
*/
|
|
335
|
+
declare function sendPreparedResponse(request: Request, response: Response): Response;
|
|
336
|
+
/**
|
|
337
|
+
* Adapt one request. Pass the Request of a Fetchable handler or the event of a ViteHub app.
|
|
338
|
+
* Await `flushWaitUntil()` when the host has no lifetime API.
|
|
339
|
+
*/
|
|
340
|
+
declare function getRuntimeContext(value: Request | ViteHubContext): RequestRuntimeContext;
|
|
341
|
+
declare function getRuntimeContext<const TOptions extends RuntimeContextOptions>(value: Request | ViteHubContext, options: TOptions): RequestRuntimeContext<TOptions>;
|
|
342
|
+
//#endregion
|
|
343
|
+
//#region src/response.d.ts
|
|
344
|
+
/** A JSON-safe representation of a web Response for durable boundaries. */
|
|
345
|
+
interface SerializedResponse {
|
|
346
|
+
readonly body: {
|
|
347
|
+
readonly data: string;
|
|
348
|
+
readonly encoding: "base64";
|
|
349
|
+
readonly mediaType: string;
|
|
350
|
+
readonly isNull?: boolean;
|
|
351
|
+
};
|
|
352
|
+
/** Header entries are kept as pairs so repeated headers are preserved. */
|
|
353
|
+
readonly headers: readonly (readonly [string, string])[];
|
|
354
|
+
readonly status: number;
|
|
355
|
+
readonly statusText: string;
|
|
356
|
+
readonly url?: string;
|
|
357
|
+
readonly type?: "error" | "opaque" | "opaqueredirect";
|
|
358
|
+
}
|
|
359
|
+
/** Normalize a primitive value into the native Web Response contract. */
|
|
360
|
+
declare function toResponse(value: unknown): Response;
|
|
361
|
+
/** Recognize Responses created by another realm from their standard tag and surface. */
|
|
362
|
+
declare function isResponse(value: unknown): value is Response;
|
|
363
|
+
/** Convert a native Response into a JSON-safe record. The body is fully buffered. */
|
|
364
|
+
declare function serializeResponse(response: Response): Promise<SerializedResponse>;
|
|
365
|
+
/** Reconstruct a native Response from a durable response record. */
|
|
366
|
+
declare function deserializeResponse(value: SerializedResponse): Response;
|
|
367
|
+
declare function isSerializedResponse(value: unknown): value is SerializedResponse;
|
|
368
|
+
//#endregion
|
|
369
|
+
//#region ../internal/dist/deployment.d.ts
|
|
370
|
+
//#region src/deployment.d.ts
|
|
371
|
+
/** The host that ViteHub builds for: the `host` option of `vitehub()` and the value of `VITEHUB_HOST`. */
|
|
372
|
+
type ViteHubHost = "cloudflare" | "deno" | "netlify" | "node" | "vercel";
|
|
373
|
+
//#endregion
|
|
374
|
+
//#region src/host.d.ts
|
|
375
|
+
declare global {
|
|
376
|
+
/** `wrangler types` adds the app's bindings to `Cloudflare.Env`. ViteHub reads it to type `getHostBinding()`. */
|
|
377
|
+
namespace Cloudflare {
|
|
378
|
+
interface Env {}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
/** The codes that `getHostBinding()` returns. */
|
|
382
|
+
type HostBindingErrorCode = "RUNTIME_HOST_BINDING_NOT_FOUND" | "RUNTIME_HOST_BINDINGS_UNAVAILABLE";
|
|
383
|
+
/**
|
|
384
|
+
* Returns the host that this code builds or runs on, or `undefined` when nothing names one.
|
|
385
|
+
* It reads `VITEHUB_HOST`, `NITRO_PRESET`, `SERVER_PRESET`, then the build variables of Cloudflare Workers Builds
|
|
386
|
+
* (`WORKERS_CI`), Netlify, Vercel, and Deno Deploy. Inside a Cloudflare Worker, it returns `"cloudflare"`.
|
|
387
|
+
* `vitehub()` uses the same detection when `host` is omitted.
|
|
388
|
+
*
|
|
389
|
+
* @example
|
|
390
|
+
* ```ts
|
|
391
|
+
* import { detectHost } from "vite-hub/runtime"
|
|
392
|
+
*
|
|
393
|
+
* const host = detectHost() ?? "node"
|
|
394
|
+
* ```
|
|
395
|
+
*/
|
|
396
|
+
declare function detectHost(env?: Record<string, string | undefined>): ViteHubHost | undefined;
|
|
397
|
+
/**
|
|
398
|
+
* Reads one raw binding of the host, such as an R2 bucket, a Durable Object namespace, or a variable of a Cloudflare
|
|
399
|
+
* Worker. Use it for host features that no ViteHub primitive covers. It works in request handlers, Schedules, Queues,
|
|
400
|
+
* and Workflows. Pass the request `event` when you have one: an H3 event, a Standard Context, or a host context with `env`.
|
|
401
|
+
*
|
|
402
|
+
* Run `wrangler types` to type the result from the app's bindings.
|
|
403
|
+
* Returns `RUNTIME_HOST_BINDINGS_UNAVAILABLE` when the code runs without host bindings, such as on Node, and
|
|
404
|
+
* `RUNTIME_HOST_BINDING_NOT_FOUND` when the Worker has no binding with that name.
|
|
405
|
+
*
|
|
406
|
+
* @example
|
|
407
|
+
* ```ts
|
|
408
|
+
* import { getHostBinding } from "vite-hub/runtime"
|
|
409
|
+
*
|
|
410
|
+
* const [error, bucket] = getHostBinding("VIDEOS", event)
|
|
411
|
+
* if (error) return new Response(null, { status: 404 })
|
|
412
|
+
* const object = await bucket.get("intro.mp4")
|
|
413
|
+
* ```
|
|
414
|
+
*/
|
|
415
|
+
declare function getHostBinding<TName extends keyof Cloudflare.Env & string>(name: TName, event?: object): Result<Cloudflare.Env[TName], HostBindingErrorCode>;
|
|
416
|
+
declare function getHostBinding<T = unknown>(name: string, event?: object): Result<T, HostBindingErrorCode>;
|
|
417
|
+
//#endregion
|
|
418
|
+
//#region src/index.d.ts
|
|
419
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
420
|
+
/** `TEvent` is the input of the guard, such as the H3 event of a Nitro route. */
|
|
421
|
+
interface AccessAuthorizationContext<TEvent = ViteHubContext> {
|
|
422
|
+
/** The input of the guard: the H3 event in a Nitro route, so `event.context` and helpers that take the event work. */
|
|
423
|
+
event: TEvent;
|
|
424
|
+
request: Pick<Request, "body" | "headers" | "method" | "signal" | "url">;
|
|
425
|
+
session: Record<string, unknown>;
|
|
426
|
+
user: Record<string, unknown> & {
|
|
427
|
+
id: string;
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
type AccessAuthorizeResult = boolean | Response;
|
|
431
|
+
/** Decides whether a signed-in user can access one request. Return `false` for `403` or a custom `Response`. */
|
|
432
|
+
type AccessAuthorize<TEvent = ViteHubContext> = (context: AccessAuthorizationContext<TEvent>) => MaybePromise<AccessAuthorizeResult>;
|
|
433
|
+
/** `true` requires a signed-in session. A callback also decides each request after sign-in. */
|
|
434
|
+
type AccessAuthorizeOption<TEvent = ViteHubContext> = true | AccessAuthorize<TEvent>;
|
|
435
|
+
/** A signed-out caller. `session` and `user` are `null`. */
|
|
436
|
+
interface AnonymousAccessAuthorizationContext<TEvent = ViteHubContext> {
|
|
437
|
+
event: TEvent;
|
|
438
|
+
request: AccessAuthorizationContext["request"];
|
|
439
|
+
session: null;
|
|
440
|
+
user: null;
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Decides whether a signed-in or signed-out caller can access one request.
|
|
444
|
+
* Check `user` before you read it. Return `false` for `403` (`401` when signed out) or a custom `Response`.
|
|
445
|
+
*/
|
|
446
|
+
type AnonymousAccessAuthorize<TEvent = ViteHubContext> = (context: AccessAuthorizationContext<TEvent> | AnonymousAccessAuthorizationContext<TEvent>) => MaybePromise<AccessAuthorizeResult>;
|
|
447
|
+
interface ExecutionAuthority {
|
|
448
|
+
readonly credentials: "ambient" | "none" | "provisioned" | "unknown";
|
|
449
|
+
readonly environment: "ambient" | "none" | "selected" | "unknown";
|
|
450
|
+
readonly filesystem: {
|
|
451
|
+
readonly access: "none" | "read-only" | "read-write" | "unknown";
|
|
452
|
+
readonly scope: "host" | "none" | "sandbox" | "unknown" | "workspace";
|
|
453
|
+
};
|
|
454
|
+
readonly isolation: "container" | "microvm" | "none" | "process" | "unknown";
|
|
455
|
+
readonly network: "none" | "restricted" | "unrestricted" | "unknown";
|
|
456
|
+
readonly processes: "arbitrary" | "none" | "restricted" | "unknown";
|
|
457
|
+
}
|
|
458
|
+
declare const noExecutionAuthority: ExecutionAuthority;
|
|
459
|
+
declare const unknownExecutionAuthority: ExecutionAuthority;
|
|
460
|
+
declare function isExecutionAuthority(value: unknown): value is ExecutionAuthority;
|
|
461
|
+
declare function normalizeExecutionAuthority(value: unknown): ExecutionAuthority;
|
|
462
|
+
type RuntimeWaitUntil = (task: Promise<unknown>) => void;
|
|
463
|
+
interface RuntimeWaitUntilController {
|
|
464
|
+
/**
|
|
465
|
+
* Drain registered work, including tasks added during the flush.
|
|
466
|
+
* Call from the operation owner. A registered task must not await its own
|
|
467
|
+
* controller's flush, because the flush waits for that task to finish.
|
|
468
|
+
*/
|
|
469
|
+
flushWaitUntil(): Promise<void>;
|
|
470
|
+
waitUntil: RuntimeWaitUntil;
|
|
471
|
+
}
|
|
472
|
+
interface TraceContext {
|
|
473
|
+
id: string;
|
|
474
|
+
parentId?: string;
|
|
475
|
+
sampled?: boolean;
|
|
476
|
+
}
|
|
477
|
+
type TraceActivityOwner = "agent" | "vitehub";
|
|
478
|
+
type TraceActivityPhase = "delivery" | "execution" | "setup" | "teardown";
|
|
479
|
+
interface TraceActivityContext {
|
|
480
|
+
owner: TraceActivityOwner;
|
|
481
|
+
phase: TraceActivityPhase;
|
|
482
|
+
}
|
|
483
|
+
type TracePayloadVisibility = "private" | "public" | "redacted" | "summary";
|
|
484
|
+
type TraceEventPayload = {
|
|
485
|
+
value: unknown;
|
|
486
|
+
visibility: "public";
|
|
487
|
+
} | {
|
|
488
|
+
summary: string;
|
|
489
|
+
visibility: "summary";
|
|
490
|
+
} | {
|
|
491
|
+
visibility: "redacted";
|
|
492
|
+
} | {
|
|
493
|
+
visibility: "private";
|
|
494
|
+
};
|
|
495
|
+
type TraceEventContentPolicy = "content" | "metadata";
|
|
496
|
+
type TraceRunStatus = "cancelled" | "completed" | "failed" | "running";
|
|
497
|
+
type TraceStepStatus = "completed" | "failed" | "running";
|
|
498
|
+
interface TraceEvent {
|
|
499
|
+
activity?: TraceActivityContext;
|
|
500
|
+
attributes?: Record<string, unknown>;
|
|
501
|
+
name: string;
|
|
502
|
+
payload?: TraceEventPayload;
|
|
503
|
+
timestamp?: Date | string;
|
|
504
|
+
trace?: TraceContext;
|
|
505
|
+
type: "approval" | "capability" | "error" | "lifecycle" | "policy" | "run";
|
|
506
|
+
}
|
|
507
|
+
interface TraceEventLogEntry extends TraceEvent {
|
|
508
|
+
sequence: number;
|
|
509
|
+
timestamp: string;
|
|
510
|
+
}
|
|
511
|
+
interface TraceEventLog {
|
|
512
|
+
append(event: TraceEvent): MaybePromise<TraceEventLogEntry>;
|
|
513
|
+
entries(): readonly TraceEventLogEntry[];
|
|
514
|
+
}
|
|
515
|
+
interface TraceEventLogOptions {
|
|
516
|
+
content?: TraceEventContentPolicy;
|
|
517
|
+
onEntry?: (entry: TraceEventLogEntry) => MaybePromise<void>;
|
|
518
|
+
}
|
|
519
|
+
interface TraceStepView {
|
|
520
|
+
attributes?: Record<string, unknown>;
|
|
521
|
+
durationMs?: number;
|
|
522
|
+
endTime?: string;
|
|
523
|
+
events: TraceEventLogEntry[];
|
|
524
|
+
id: string;
|
|
525
|
+
name: string;
|
|
526
|
+
startTime: string;
|
|
527
|
+
status: TraceStepStatus;
|
|
528
|
+
type: TraceEvent["type"];
|
|
529
|
+
}
|
|
530
|
+
interface TraceRunView {
|
|
531
|
+
durationMs?: number;
|
|
532
|
+
endTime?: string;
|
|
533
|
+
events: TraceEventLogEntry[];
|
|
534
|
+
id: string;
|
|
535
|
+
startTime: string;
|
|
536
|
+
status: TraceRunStatus;
|
|
537
|
+
steps: TraceStepView[];
|
|
538
|
+
}
|
|
539
|
+
interface OpenTelemetrySpanView {
|
|
540
|
+
attributes?: Record<string, unknown>;
|
|
541
|
+
endTime?: string;
|
|
542
|
+
events?: OpenTelemetrySpanEventView[];
|
|
543
|
+
name: string;
|
|
544
|
+
parentSpanId?: string;
|
|
545
|
+
spanId: string;
|
|
546
|
+
startTime: string;
|
|
547
|
+
status: {
|
|
548
|
+
code: "ERROR" | "OK" | "UNSET";
|
|
549
|
+
message?: string;
|
|
550
|
+
};
|
|
551
|
+
traceId: string;
|
|
552
|
+
}
|
|
553
|
+
interface OpenTelemetrySpanEventView {
|
|
554
|
+
attributes?: Record<string, unknown>;
|
|
555
|
+
name: string;
|
|
556
|
+
time: string;
|
|
557
|
+
}
|
|
558
|
+
interface OpenTelemetryLogRecordView {
|
|
559
|
+
attributes?: Record<string, unknown>;
|
|
560
|
+
eventName: string;
|
|
561
|
+
severityNumber?: number;
|
|
562
|
+
severityText?: string;
|
|
563
|
+
spanId: string;
|
|
564
|
+
time: string;
|
|
565
|
+
traceId: string;
|
|
566
|
+
}
|
|
567
|
+
interface OpenTelemetrySpanViewOptions {
|
|
568
|
+
content?: TraceEventContentPolicy;
|
|
569
|
+
}
|
|
570
|
+
interface RuntimeHostContext<TRuntimeConfig = Record<string, unknown>> {
|
|
571
|
+
capabilities?: RuntimeCapabilities;
|
|
572
|
+
cloudflare?: {
|
|
573
|
+
context?: unknown;
|
|
574
|
+
durableObjectStateName?: string;
|
|
575
|
+
env?: Record<string, unknown>;
|
|
576
|
+
};
|
|
577
|
+
event?: unknown;
|
|
578
|
+
memo<T>(key: string, create: () => T): T;
|
|
579
|
+
platform?: string;
|
|
580
|
+
request?: Request;
|
|
581
|
+
runtime: string;
|
|
582
|
+
runtimeConfig?: TRuntimeConfig;
|
|
583
|
+
trace?: TraceContext;
|
|
584
|
+
traceLog?: TraceEventLog;
|
|
585
|
+
vercel?: {
|
|
586
|
+
waitUntil?: RuntimeWaitUntil;
|
|
587
|
+
};
|
|
588
|
+
/** Drain from the operation owner, never from work registered with this context. */
|
|
589
|
+
flushWaitUntil?: () => Promise<void>;
|
|
590
|
+
waitUntil: RuntimeWaitUntil;
|
|
591
|
+
}
|
|
592
|
+
type ExecutionContext<TRuntimeConfig = Record<string, unknown>> = RuntimeHostContext<TRuntimeConfig> & {
|
|
593
|
+
capabilities: RuntimeCapabilities;
|
|
594
|
+
runtimeConfig: TRuntimeConfig;
|
|
595
|
+
};
|
|
596
|
+
interface CapabilityHandle<TKind extends string = string, TValue = unknown> {
|
|
597
|
+
kind: TKind;
|
|
598
|
+
name?: string;
|
|
599
|
+
value: TValue;
|
|
600
|
+
}
|
|
601
|
+
type RuntimeCapabilityHandle<TKind extends string = string, TValue = unknown> = CapabilityHandle<TKind, TValue>;
|
|
602
|
+
type RuntimeCapabilities = Record<string, CapabilityHandle | unknown>;
|
|
603
|
+
interface CapabilityDefinition<TKind extends string = string, TValue = unknown> {
|
|
604
|
+
handle: CapabilityHandle<TKind, TValue>;
|
|
605
|
+
resolve(context: ExecutionContext): MaybePromise<CapabilityHandle<TKind, TValue>>;
|
|
606
|
+
}
|
|
607
|
+
interface Resolvable<T, TContext extends RuntimeHostContext<any> = RuntimeHostContext> {
|
|
608
|
+
resolve(context: TContext): MaybePromise<T>;
|
|
609
|
+
}
|
|
610
|
+
type MaybeResolvable<T, TContext extends RuntimeHostContext<any> = RuntimeHostContext> = T | Resolvable<T, TContext> | ((context: TContext) => MaybePromise<T>);
|
|
611
|
+
interface PolicyContext {
|
|
612
|
+
capability?: string;
|
|
613
|
+
input?: unknown;
|
|
614
|
+
operation?: string;
|
|
615
|
+
runtime?: string;
|
|
616
|
+
subject?: unknown;
|
|
617
|
+
trace?: TraceContext;
|
|
618
|
+
}
|
|
619
|
+
type PolicyDecision = "allow" | "deny" | "require-approval" | "retryable-failure";
|
|
620
|
+
type CapabilityPolicy = PolicyDecision | ((context: PolicyContext) => MaybePromise<PolicyDecision>);
|
|
621
|
+
type ApprovalState = "proposed" | "awaiting-approval" | "approved" | "denied" | "executing" | "completed" | "failed";
|
|
622
|
+
interface ApprovalRequest<TInput = unknown> {
|
|
623
|
+
id: string;
|
|
624
|
+
capability?: string;
|
|
625
|
+
input?: TInput;
|
|
626
|
+
reason?: string;
|
|
627
|
+
state: Extract<ApprovalState, "awaiting-approval" | "proposed">;
|
|
628
|
+
trace?: TraceContext;
|
|
629
|
+
}
|
|
630
|
+
interface ApprovalDecision {
|
|
631
|
+
approved: boolean;
|
|
632
|
+
decidedAt?: Date | string;
|
|
633
|
+
reason?: string;
|
|
634
|
+
requestId: string;
|
|
635
|
+
state: Extract<ApprovalState, "approved" | "denied">;
|
|
636
|
+
}
|
|
637
|
+
interface RunLifecycleHooks<TContext extends RuntimeHostContext<any> = RuntimeHostContext> {
|
|
638
|
+
approval?: (request: ApprovalRequest, context: TContext) => MaybePromise<void>;
|
|
639
|
+
error?: (error: unknown, context: TContext) => MaybePromise<void>;
|
|
640
|
+
finish?: (context: TContext) => MaybePromise<void>;
|
|
641
|
+
request?: (context: TContext) => MaybePromise<void>;
|
|
642
|
+
trace?: (event: TraceEvent, context: TContext) => MaybePromise<void>;
|
|
643
|
+
}
|
|
644
|
+
declare function emitTraceEvent<TContext extends RuntimeHostContext<any>>(context: TContext, event: TraceEvent): Promise<TraceEventLogEntry | undefined>;
|
|
645
|
+
declare function createTraceEventLog(options?: TraceEventLogOptions): TraceEventLog;
|
|
646
|
+
declare function deriveTraceRuns(events: Iterable<TraceEventLogEntry>): TraceRunView[];
|
|
647
|
+
declare function traceEventsToOpenTelemetryLogRecords(events: Iterable<TraceEventLogEntry>, options?: OpenTelemetrySpanViewOptions): OpenTelemetryLogRecordView[];
|
|
648
|
+
declare function traceEventsToOpenTelemetrySpans(events: Iterable<TraceEventLogEntry>, options?: OpenTelemetrySpanViewOptions): OpenTelemetrySpanView[];
|
|
649
|
+
type NormalizedRuntimeConfig<TConfig> = Exclude<TConfig, null | undefined> extends Record<string, unknown> ? Record<string, unknown> : Exclude<TConfig, null | undefined> | Record<string, unknown>;
|
|
650
|
+
type RuntimeConfigOf<TContext extends RuntimeHostContext<any>> = "runtimeConfig" extends keyof TContext ? undefined extends TContext["runtimeConfig"] ? NormalizedRuntimeConfig<TContext["runtimeConfig"]> : null extends TContext["runtimeConfig"] ? NormalizedRuntimeConfig<TContext["runtimeConfig"]> : TContext["runtimeConfig"] : Record<string, unknown>;
|
|
651
|
+
type RuntimeCapabilitiesOf<TContext extends RuntimeHostContext<any>> = "capabilities" extends keyof TContext ? undefined extends TContext["capabilities"] ? RuntimeCapabilities : TContext["capabilities"] : RuntimeCapabilities;
|
|
652
|
+
type CreatedExecutionContext<TContext extends RuntimeHostContext<any>> = TContext extends unknown ? Omit<TContext, "capabilities" | "runtimeConfig"> & {
|
|
653
|
+
capabilities: RuntimeCapabilitiesOf<TContext>;
|
|
654
|
+
runtimeConfig: RuntimeConfigOf<TContext>;
|
|
655
|
+
} : never;
|
|
656
|
+
declare function createExecutionContext<TContext extends RuntimeHostContext<any>>(context: TContext): CreatedExecutionContext<TContext>;
|
|
657
|
+
type RuntimeContextInput = Omit<RuntimeHostContext<unknown>, "flushWaitUntil" | "memo" | "waitUntil"> & {
|
|
658
|
+
memo?: RuntimeHostContext["memo"];
|
|
659
|
+
waitUntil?: RuntimeWaitUntil;
|
|
660
|
+
};
|
|
661
|
+
type CreatedRuntimeContext<TContext extends RuntimeContextInput> = CreatedExecutionContext<TContext & RuntimeWaitUntilController & {
|
|
662
|
+
memo: RuntimeHostContext["memo"];
|
|
663
|
+
}>;
|
|
664
|
+
/** Create one operation's context. Without a host waitUntil, drain work before returning. */
|
|
665
|
+
declare function createRuntimeContext<const TContext extends RuntimeContextInput>(input: TContext): CreatedRuntimeContext<TContext>;
|
|
666
|
+
declare function defineCapability<TKind extends string, TValue>(kind: TKind, value: TValue, options?: {
|
|
667
|
+
name?: string;
|
|
668
|
+
}): CapabilityHandle<TKind, TValue>;
|
|
669
|
+
declare function createRuntimeWaitUntilController(options?: {
|
|
670
|
+
forward?: RuntimeWaitUntil;
|
|
671
|
+
}): RuntimeWaitUntilController;
|
|
672
|
+
declare function hasCapability(context: RuntimeHostContext, name: string): boolean;
|
|
673
|
+
declare function getCapability(context: RuntimeHostContext<any>, name: string): CapabilityHandle;
|
|
674
|
+
declare function isResolvable<T, TContext extends RuntimeHostContext<any>>(value: MaybeResolvable<T, TContext>): value is Resolvable<T, TContext>;
|
|
675
|
+
declare function resolveRuntimeValue<T, TContext extends RuntimeHostContext<any>>(value: MaybeResolvable<T, TContext>, context: TContext): Promise<T>;
|
|
676
|
+
declare function resolveCapabilityPolicy(policy: CapabilityPolicy | undefined, context: PolicyContext): Promise<PolicyDecision>;
|
|
677
|
+
//#endregion
|
|
678
|
+
export { emitTraceEvent as $, decodeRouteSegment as $t, RuntimeWaitUntil as A, ViteHubErrorDetails as At, TraceEventLogOptions as B, RuntimeResourceInspector as Bt, PolicyDecision as C, ViteHubStandardProps as Cn, RuntimeName as Ct, RuntimeCapabilityHandle as D, sendPreparedResponse as Dt, RuntimeCapabilities as E, installRequestStandardContext as Et, TraceContext as F, RuntimeDiagnosticError as Ft, TraceStepStatus as G, RuntimeResourceUnit as Gt, TracePayloadVisibility as H, RuntimeResourceScope as Ht, TraceEvent as I, RuntimeDiagnosticErrorOptions as It, createRuntimeContext as J, normalizeRuntimeDiagnosticError as Jt, TraceStepView as K, formatRuntimeDiagnosticError as Kt, TraceEventContentPolicy as L, RuntimeDiagnosticEvent as Lt, TraceActivityContext as M, ViteHubErrorShape as Mt, TraceActivityOwner as N, getViteHubErrorShape as Nt, RuntimeContextInput as O, ViteHubError as Ot, TraceActivityPhase as P, isViteHubError as Pt, deriveTraceRuns as Q, normalizeConsoleProjectUrl as Qt, TraceEventLog as R, RuntimeDiagnosticLevel as Rt, PolicyContext as S, ViteHubRuntime as Sn, RuntimeContextOptions as St, RunLifecycleHooks as T, getStandardContext as Tt, TraceRunStatus as U, RuntimeResourceSnapshot as Ut, TraceEventPayload as V, RuntimeResourceObservation as Vt, TraceRunView as W, RuntimeResourceSupport as Wt, createTraceEventLog as X, hostedConsoleUrl as Xt, createRuntimeWaitUntilController as Y, hostedConsoleOrigin as Yt, defineCapability as Z, normalizeConsolePath as Zt, MaybeResolvable as _, ResultError as _n, isResponse as _t, AnonymousAccessAuthorizationContext as a, LeaseRecord as an, normalizeExecutionAuthority as at, OpenTelemetrySpanView as b, isTraceContentAttributeKey as bn, toResponse as bt, ApprovalRequest as c, LeaseStore as cn, traceEventsToOpenTelemetryLogRecords as ct, CapabilityHandle as d, leaseTable as dn, HostBindingErrorCode as dt, encodeRouteSegment as en, getCapability as et, CapabilityPolicy as f, DefineErrorsOptions as fn, detectHost as ft, MaybePromise as g, Result as gn, deserializeResponse as gt, ExecutionContext as h, ErrorHandle as hn, SerializedResponse as ht, AccessAuthorizeResult as i, LeaseOperation as in, noExecutionAuthority as it, RuntimeWaitUntilController as j, ViteHubErrorOptions as jt, RuntimeHostContext as k, ViteHubErrorDetail as kt, ApprovalState as l, createMemoryLeaseStore as ln, traceEventsToOpenTelemetrySpans as lt, ExecutionAuthority as m, ErrorCodes as mn, ViteHubHost as mt, AccessAuthorize as n, LeaseAcquireOptions as nn, isExecutionAuthority as nt, AnonymousAccessAuthorize as o, LeaseSqlClient as on, resolveCapabilityPolicy as ot, CreatedRuntimeContext as p, ErrorCatalog as pn, getHostBinding as pt, createExecutionContext as q, isRuntimeDiagnostic as qt, AccessAuthorizeOption as r, LeaseErrorCode as rn, isResolvable as rt, ApprovalDecision as s, LeaseSqlParam as sn, resolveRuntimeValue as st, AccessAuthorizationContext as t, Lease as tn, hasCapability as tt, CapabilityDefinition as u, createSqlLeaseStore as un, unknownExecutionAuthority as ut, OpenTelemetryLogRecordView as v, defineErrors as vn, isSerializedResponse as vt, Resolvable as w, getRuntimeContext as wt, OpenTelemetrySpanViewOptions as x, ViteHubContext as xn, RequestRuntimeContext as xt, OpenTelemetrySpanEventView as y, toResultError as yn, serializeResponse as yt, TraceEventLogEntry as z, RuntimeDiagnosticReporter as zt };
|