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