@vite-hub/runtime 0.3.1 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -7
- package/dist/durability.js +1 -1
- package/dist/{error-diagnostics-BsJr9VdW.d.ts → error-diagnostics-0sYgKTT8.d.ts} +11 -7
- package/dist/{error-diagnostics-BKICpwZp.js → error-diagnostics-BM9W4pBg.js} +9 -1
- package/dist/{errors-BEomN3fX.js → errors-BQ0ofIL4.js} +1 -1
- package/dist/{index-Bcl-Hr-a.d.ts → index-C1DoYfCf.d.ts} +70 -15
- package/dist/index.d.ts +3 -3
- package/dist/index.js +5 -5
- package/dist/internal/drain.js +1 -1
- package/dist/internal/grant.js +1 -1
- package/dist/internal/h3.d.ts +1 -1
- package/dist/internal/h3.js +2 -2
- package/dist/internal/node.d.ts +1 -1
- package/dist/internal/node.js +1 -1
- package/dist/internal/public-url.js +1 -1
- package/dist/internal/run-failed.d.ts +40 -0
- package/dist/internal/run-failed.js +56 -0
- package/dist/internal/runtime-type.d.ts +1 -1
- package/dist/internal/runtime-type.js +1 -1
- package/dist/operations.d.ts +6 -1
- package/dist/operations.js +6 -2
- package/dist/{public-url-B6x0HMgY.js → public-url-ByAmAjbP.js} +1 -1
- package/dist/{request-context-CP9NhgLL.js → request-context-uRQpodgl.js} +172 -13
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
# @vite-hub/runtime
|
|
2
2
|
|
|
3
3
|
<p>
|
|
4
|
-
<a href="https://vitehub.dev"><img alt="ViteHub" src="https://
|
|
5
|
-
<img alt="TypeScript" src="https://
|
|
6
|
-
<img alt="Runtime" src="https://
|
|
4
|
+
<a href="https://vitehub.dev"><img alt="ViteHub" src="https://img.shields.io/static/v1?label=ViteHub&message=vitehub.dev&color=blue"></a>
|
|
5
|
+
<img alt="TypeScript" src="https://img.shields.io/static/v1?label=TypeScript&message=ready&color=blue">
|
|
6
|
+
<img alt="Runtime" src="https://img.shields.io/static/v1?label=Runtime&message=context+%7C+policy+%7C+trace&color=blue">
|
|
7
7
|
</p>
|
|
8
8
|
|
|
9
9
|
`@vite-hub/runtime` provides the shared Runtime Host Context, Runtime Capability,
|
|
10
10
|
policy, approval, trace, error, lease, and execution-authority contracts used by
|
|
11
|
-
ViteHub packages and custom host integrations.
|
|
11
|
+
ViteHub packages and custom host integrations. User docs: [Runtime](https://vitehub.dev/docs/runtime).
|
|
12
12
|
|
|
13
13
|
## Choose an import
|
|
14
14
|
|
|
@@ -29,7 +29,7 @@ or Agent Definitions.
|
|
|
29
29
|
pnpm add @vite-hub/runtime
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
The package declares Node.js
|
|
32
|
+
The package declares Node.js 24.15 or newer. Import the root entry for portable
|
|
33
33
|
Runtime contracts. The `/operations` entry exports `defineOperation()`, its types,
|
|
34
34
|
and the `vitehub: { operations }` contribution types of a Vite plugin.
|
|
35
35
|
|
|
@@ -391,9 +391,10 @@ Do not import from `src`, `dist`, or ViteHub's `_internal` paths.
|
|
|
391
391
|
|
|
392
392
|
## Go deeper
|
|
393
393
|
|
|
394
|
-
- [Runtime Context](https://vitehub.dev/docs/
|
|
394
|
+
- [Runtime Context](https://vitehub.dev/docs/runtime/context)
|
|
395
395
|
- [Runtime policy, approvals, and traces](https://vitehub.dev/docs/agents/runtime-policy)
|
|
396
|
-
- [Runtime events](https://vitehub.dev/docs/
|
|
396
|
+
- [Runtime events](https://vitehub.dev/docs/runtime/events)
|
|
397
|
+
- [Runtime error contract](https://vitehub.dev/docs/runtime/errors)
|
|
397
398
|
- [Stable import paths](https://vitehub.dev/docs/reference/import-paths)
|
|
398
399
|
- [Node Runtime diagnostics](https://vitehub.dev/docs/agents/capabilities/diagnostics)
|
|
399
400
|
- [Report a Runtime issue](https://github.com/vite-hub/vitehub/issues/new)
|
package/dist/durability.js
CHANGED
|
@@ -62,7 +62,7 @@ function resolveDurabilityValue(value, env) {
|
|
|
62
62
|
}
|
|
63
63
|
const instancesEnvName = "VITEHUB_INSTANCES";
|
|
64
64
|
const durabilityDiagnostics = defineDiagnostics({
|
|
65
|
-
docsBase: "https://vitehub.dev/docs/
|
|
65
|
+
docsBase: "https://vitehub.dev/docs/runtime/diagnostics",
|
|
66
66
|
codes: {
|
|
67
67
|
RUNTIME_R0017: {
|
|
68
68
|
why: ({ instances, lines }) => [`[vitehub] ${instancesEnvName} is ${instances}, but these primitives keep their state in one process or on one host. Each instance would see different data:`, ...lines].join("\n"),
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { Diagnostics } from "nostics";
|
|
2
2
|
//#region src/error-diagnostics.d.ts
|
|
3
|
+
interface RuntimeCodeParams {
|
|
4
|
+
counter?: string;
|
|
5
|
+
message?: unknown;
|
|
6
|
+
option?: string;
|
|
7
|
+
suggestion?: string;
|
|
8
|
+
unit?: string;
|
|
9
|
+
value?: string;
|
|
10
|
+
}
|
|
3
11
|
interface RuntimeCodeDefinition {
|
|
4
|
-
why: (params:
|
|
5
|
-
|
|
6
|
-
message?: unknown;
|
|
7
|
-
value?: string;
|
|
8
|
-
}) => string;
|
|
9
|
-
fix?: string;
|
|
12
|
+
why: (params: RuntimeCodeParams) => string;
|
|
13
|
+
fix?: string | ((params: RuntimeCodeParams) => string);
|
|
10
14
|
}
|
|
11
|
-
type RuntimeErrorCode = "RUNTIME_R0001" | "RUNTIME_R0002" | "RUNTIME_R0003" | "RUNTIME_R0004" | "RUNTIME_R0005" | "RUNTIME_R0006" | "RUNTIME_R0007" | "RUNTIME_R0009" | "RUNTIME_R0010" | "RUNTIME_R0011" | "RUNTIME_R0015" | "RUNTIME_R0016" | "RUNTIME_R0017" | "RUNTIME_R0018" | "RUNTIME_CONSOLE_PATH_INVALID" | "RUNTIME_CONSOLE_PROJECT_URL_INVALID" | "RUNTIME_EXECUTION_BUDGET_AMOUNT_INVALID" | "RUNTIME_EXECUTION_BUDGET_EXCEEDED" | "RUNTIME_EXECUTION_BUDGET_LIMIT_INVALID" | "RUNTIME_SERIALIZED_RESPONSE_INVALID";
|
|
15
|
+
type RuntimeErrorCode = "RUNTIME_R0001" | "RUNTIME_R0002" | "RUNTIME_R0003" | "RUNTIME_R0004" | "RUNTIME_R0005" | "RUNTIME_R0006" | "RUNTIME_R0007" | "RUNTIME_R0009" | "RUNTIME_R0010" | "RUNTIME_R0011" | "RUNTIME_R0015" | "RUNTIME_R0016" | "RUNTIME_R0017" | "RUNTIME_R0018" | "RUNTIME_CONSOLE_PATH_INVALID" | "RUNTIME_CONSOLE_PROJECT_URL_INVALID" | "RUNTIME_DURATION_INVALID" | "RUNTIME_EXECUTION_BUDGET_AMOUNT_INVALID" | "RUNTIME_EXECUTION_BUDGET_EXCEEDED" | "RUNTIME_EXECUTION_BUDGET_LIMIT_INVALID" | "RUNTIME_HIDDEN_ERROR" | "RUNTIME_SERIALIZED_RESPONSE_INVALID";
|
|
12
16
|
declare const codes: Record<RuntimeErrorCode, RuntimeCodeDefinition>;
|
|
13
17
|
declare const runtimeErrorDiagnostics: Diagnostics<typeof codes, []>;
|
|
14
18
|
//#endregion
|
|
@@ -60,6 +60,10 @@ const codes = {
|
|
|
60
60
|
why: ({ value }) => `${value} is not a project URL. Use the https:// origin of the app, with its base path if it has one.`,
|
|
61
61
|
fix: "Pass `hostedConsoleUrl()` the `https://` origin of the app, or `http://localhost` in development, with its base path and without a user name or password."
|
|
62
62
|
},
|
|
63
|
+
RUNTIME_DURATION_INVALID: {
|
|
64
|
+
why: ({ option, value }) => `${option ? `\`${option}\`` : "The value"} is ${value}, which is not a duration. A duration is a string with a number of 0 or more and a unit, such as "30s", "5m", or "1 day".`,
|
|
65
|
+
fix: ({ suggestion, unit = "milliseconds", value }) => suggestion ? `Write the time as a string with a unit: ${value} ${unit} is ${suggestion}.` : "Write a number of 0 or more and one unit: `ms`, `s`, `m`, `h`, `d`, or `w`, or a long name such as `minutes` or `days`. For example `\"30s\"`, `\"5m\"`, or `\"1 day\"`."
|
|
66
|
+
},
|
|
63
67
|
RUNTIME_EXECUTION_BUDGET_AMOUNT_INVALID: {
|
|
64
68
|
why: ({ counter }) => `[vitehub] Execution budget ${counter} amount must be a finite non-negative number.`,
|
|
65
69
|
fix: "Pass `consume()` and the `record*()` methods of the execution budget a finite number of 0 or more."
|
|
@@ -72,13 +76,17 @@ const codes = {
|
|
|
72
76
|
why: () => "[vitehub] Execution budget limits must be finite non-negative numbers.",
|
|
73
77
|
fix: "Set each limit of `executionBudget`, such as `maxToolCalls` or `maxOutputBytes`, to a finite number of 0 or more, or remove it."
|
|
74
78
|
},
|
|
79
|
+
RUNTIME_HIDDEN_ERROR: {
|
|
80
|
+
why: () => "The server failed. The error is not a ViteHub error, so its message and stack stay on the server.",
|
|
81
|
+
fix: "Read the server logs for the error. To send a code, a why, and a fix to the client, return a `ResultError` from `defineErrors()` and pass it to `toResponse()`."
|
|
82
|
+
},
|
|
75
83
|
RUNTIME_SERIALIZED_RESPONSE_INVALID: {
|
|
76
84
|
why: () => "Invalid serialized Response",
|
|
77
85
|
fix: "Pass `deserializeResponse()` the record that `serializeResponse()` returned, unchanged. Check it first with `isSerializedResponse()`."
|
|
78
86
|
}
|
|
79
87
|
};
|
|
80
88
|
const runtimeErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
81
|
-
docsBase: "https://vitehub.dev/docs/
|
|
89
|
+
docsBase: "https://vitehub.dev/docs/runtime/diagnostics",
|
|
82
90
|
codes
|
|
83
91
|
});
|
|
84
92
|
//#endregion
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./error-diagnostics-
|
|
1
|
+
import "./error-diagnostics-0sYgKTT8.js";
|
|
2
2
|
import "./execution-budget-BPXbISEt.js";
|
|
3
3
|
import { Diagnostic, DiagnosticDefinition, DiagnosticJSON, Diagnostics } from "nostics";
|
|
4
4
|
import { StandardContext } from "standard-context";
|
|
@@ -40,8 +40,11 @@ declare function isTraceContentAttributeKey(key: string): boolean;
|
|
|
40
40
|
* - `docs` links to the code on vitehub.dev.
|
|
41
41
|
* - `cause` keeps the lower-level error, for example the provider error.
|
|
42
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.
|
|
43
44
|
*/
|
|
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;
|
|
45
48
|
/** Retains the Nostics serializer type for compatibility; runtime JSON is redacted. */
|
|
46
49
|
toJSON(): DiagnosticJSON<TData> & {
|
|
47
50
|
code: TCode;
|
|
@@ -56,8 +59,13 @@ interface ResultError<TCode extends string = string, TData = unknown> extends Di
|
|
|
56
59
|
* Check `error` first. When `error` is `undefined`, `data` has the value.
|
|
57
60
|
*/
|
|
58
61
|
type Result<TData, TCode extends string = string> = [error: ResultError<TCode>, data: undefined] | [error: undefined, data: TData];
|
|
59
|
-
/**
|
|
60
|
-
|
|
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
|
+
}> & {
|
|
61
69
|
is?: never;
|
|
62
70
|
};
|
|
63
71
|
type CatalogCode<TCodes> = Exclude<keyof TCodes, "is"> & string;
|
|
@@ -86,7 +94,7 @@ type ErrorCatalog<TCodes extends Record<string, DiagnosticDefinition>> = {
|
|
|
86
94
|
is: (error: unknown) => error is { [TCode in CatalogCode<TCodes>]: ResultError<TCode, CatalogData<TCodes, TCode>>; }[CatalogCode<TCodes>];
|
|
87
95
|
} & { [TCode in CatalogCode<TCodes>]: ErrorHandle<Parameters<CatalogHandles<TCodes>[TCode]>, TCode, CatalogData<TCodes, TCode>>; };
|
|
88
96
|
interface DefineErrorsOptions<TCodes extends Record<string, DiagnosticDefinition>> {
|
|
89
|
-
/** Each code with a `why` and a `fix`. */
|
|
97
|
+
/** Each code with a `why` and a `fix`, and an optional HTTP `status`. */
|
|
90
98
|
codes: TCodes;
|
|
91
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>`. */
|
|
92
100
|
docs: string;
|
|
@@ -180,6 +188,25 @@ declare const leaseTable = "vitehub_leases";
|
|
|
180
188
|
*/
|
|
181
189
|
declare function createSqlLeaseStore(client: LeaseSqlClient): LeaseStore;
|
|
182
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
|
|
183
210
|
//#region src/route-segment.d.ts
|
|
184
211
|
declare function encodeRouteSegment(value: string): string;
|
|
185
212
|
declare function decodeRouteSegment(segment: string): string | undefined;
|
|
@@ -356,7 +383,13 @@ interface SerializedResponse {
|
|
|
356
383
|
readonly url?: string;
|
|
357
384
|
readonly type?: "error" | "opaque" | "opaqueredirect";
|
|
358
385
|
}
|
|
359
|
-
/**
|
|
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
|
+
*/
|
|
360
393
|
declare function toResponse(value: unknown): Response;
|
|
361
394
|
/** Recognize Responses created by another realm from their standard tag and surface. */
|
|
362
395
|
declare function isResponse(value: unknown): value is Response;
|
|
@@ -417,21 +450,43 @@ declare function getHostBinding<T = unknown>(name: string, event?: object): Resu
|
|
|
417
450
|
//#endregion
|
|
418
451
|
//#region src/index.d.ts
|
|
419
452
|
type MaybePromise<T> = T | Promise<T>;
|
|
420
|
-
|
|
421
|
-
|
|
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> {
|
|
422
476
|
/** The input of the guard: the H3 event in a Nitro route, so `event.context` and helpers that take the event work. */
|
|
423
477
|
event: TEvent;
|
|
424
478
|
request: Pick<Request, "body" | "headers" | "method" | "signal" | "url">;
|
|
425
|
-
session:
|
|
426
|
-
user:
|
|
427
|
-
id: string;
|
|
428
|
-
};
|
|
479
|
+
session: TSession;
|
|
480
|
+
user: TUser;
|
|
429
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>>;
|
|
430
484
|
type AccessAuthorizeResult = boolean | Response;
|
|
485
|
+
type Authorize<TContext> = (context: TContext) => MaybePromise<AccessAuthorizeResult>;
|
|
431
486
|
/** Decides whether a signed-in user can access one request. Return `false` for `403` or a custom `Response`. */
|
|
432
|
-
type AccessAuthorize<TEvent = ViteHubContext> =
|
|
487
|
+
type AccessAuthorize<TEvent = ViteHubContext, TRegistered extends boolean = true> = TRegistered extends true ? Authorize<AccessAuthorizationContext<TEvent>> : Authorize<AccessAuthorizationContext<TEvent, false>>;
|
|
433
488
|
/** `true` requires a signed-in session. A callback also decides each request after sign-in. */
|
|
434
|
-
type AccessAuthorizeOption<TEvent = ViteHubContext> = true | AccessAuthorize<TEvent>;
|
|
489
|
+
type AccessAuthorizeOption<TEvent = ViteHubContext, TRegistered extends boolean = true> = true | AccessAuthorize<TEvent, TRegistered>;
|
|
435
490
|
/** A signed-out caller. `session` and `user` are `null`. */
|
|
436
491
|
interface AnonymousAccessAuthorizationContext<TEvent = ViteHubContext> {
|
|
437
492
|
event: TEvent;
|
|
@@ -443,7 +498,7 @@ interface AnonymousAccessAuthorizationContext<TEvent = ViteHubContext> {
|
|
|
443
498
|
* Decides whether a signed-in or signed-out caller can access one request.
|
|
444
499
|
* Check `user` before you read it. Return `false` for `403` (`401` when signed out) or a custom `Response`.
|
|
445
500
|
*/
|
|
446
|
-
type AnonymousAccessAuthorize<TEvent = ViteHubContext> =
|
|
501
|
+
type AnonymousAccessAuthorize<TEvent = ViteHubContext, TRegistered extends boolean = true> = TRegistered extends true ? Authorize<AccessAuthorizationContext<TEvent> | AnonymousAccessAuthorizationContext<TEvent>> : Authorize<AccessAuthorizationContext<TEvent, false> | AnonymousAccessAuthorizationContext<TEvent>>;
|
|
447
502
|
interface ExecutionAuthority {
|
|
448
503
|
readonly credentials: "ambient" | "none" | "provisioned" | "unknown";
|
|
449
504
|
readonly environment: "ambient" | "none" | "selected" | "unknown";
|
|
@@ -675,4 +730,4 @@ declare function isResolvable<T, TContext extends RuntimeHostContext<any>>(value
|
|
|
675
730
|
declare function resolveRuntimeValue<T, TContext extends RuntimeHostContext<any>>(value: MaybeResolvable<T, TContext>, context: TContext): Promise<T>;
|
|
676
731
|
declare function resolveCapabilityPolicy(policy: CapabilityPolicy | undefined, context: PolicyContext): Promise<PolicyDecision>;
|
|
677
732
|
//#endregion
|
|
678
|
-
export { emitTraceEvent as $, decodeRouteSegment as $t, RuntimeWaitUntil as A, ViteHubErrorDetails as At, TraceEventLogOptions as B, RuntimeResourceInspector as Bt, PolicyDecision as C,
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as runtimeErrorDiagnostics } from "./error-diagnostics-
|
|
2
|
-
import { $ as emitTraceEvent, $t as decodeRouteSegment, A as RuntimeWaitUntil, At as ViteHubErrorDetails, B as TraceEventLogOptions, Bt as RuntimeResourceInspector, C as PolicyDecision, Cn as
|
|
1
|
+
import { t as runtimeErrorDiagnostics } from "./error-diagnostics-0sYgKTT8.js";
|
|
2
|
+
import { $ as emitTraceEvent, $t as decodeRouteSegment, A as RuntimeWaitUntil, At as ViteHubErrorDetails, B as TraceEventLogOptions, Bt as RuntimeResourceInspector, C as PolicyDecision, Cn as isTraceContentAttributeKey, Ct as RuntimeName, D as RuntimeCapabilityHandle, E as RuntimeCapabilities, En as ViteHubStandardProps, F as TraceContext, Ft as RuntimeDiagnosticError, G as TraceStepStatus, Gt as RuntimeResourceUnit, H as TracePayloadVisibility, Ht as RuntimeResourceScope, I as TraceEvent, It as RuntimeDiagnosticErrorOptions, J as createRuntimeContext, Jt as normalizeRuntimeDiagnosticError, K as TraceStepView, Kt as formatRuntimeDiagnosticError, L as TraceEventContentPolicy, Lt as RuntimeDiagnosticEvent, M as TraceActivityContext, Mt as ViteHubErrorShape, N as TraceActivityOwner, Nt as getViteHubErrorShape, O as RuntimeContextInput, Ot as ViteHubError, P as TraceActivityPhase, Pt as isViteHubError, Q as deriveTraceRuns, Qt as normalizeConsoleProjectUrl, R as TraceEventLog, Rt as RuntimeDiagnosticLevel, S as PolicyContext, Sn as toResultError, St as RuntimeContextOptions, T as RunLifecycleHooks, Tn as ViteHubRuntime, Tt as getStandardContext, U as TraceRunStatus, Ut as RuntimeResourceSnapshot, V as TraceEventPayload, Vt as RuntimeResourceObservation, W as TraceRunView, Wt as RuntimeResourceSupport, X as createTraceEventLog, Xt as hostedConsoleUrl, Y as createRuntimeWaitUntilController, Yt as hostedConsoleOrigin, Z as defineCapability, Zt as normalizeConsolePath, _ as MaybeResolvable, _n as ErrorCodes, _t as isResponse, a as AnonymousAccessAuthorizationContext, an as LeaseAcquireOptions, at as normalizeExecutionAuthority, b as OpenTelemetrySpanView, bn as ResultError, bt as toResponse, c as ApprovalRequest, cn as LeaseRecord, ct as traceEventsToOpenTelemetryLogRecords, d as CapabilityHandle, dn as LeaseStore, dt as HostBindingErrorCode, en as encodeRouteSegment, et as getCapability, f as CapabilityPolicy, fn as createMemoryLeaseStore, ft as detectHost, g as MaybePromise, gn as ErrorCatalog, gt as deserializeResponse, h as ExecutionContext, hn as DefineErrorsOptions, ht as SerializedResponse, i as AccessAuthorizeResult, in as Lease, it as noExecutionAuthority, j as RuntimeWaitUntilController, jt as ViteHubErrorOptions, k as RuntimeHostContext, kt as ViteHubErrorDetail, l as ApprovalState, ln as LeaseSqlClient, lt as traceEventsToOpenTelemetrySpans, m as ExecutionAuthority, mn as leaseTable, mt as ViteHubHost, n as AccessAuthorize, nn as DurationUnit, nt as isExecutionAuthority, o as AnonymousAccessAuthorize, on as LeaseErrorCode, ot as resolveCapabilityPolicy, p as CreatedRuntimeContext, pn as createSqlLeaseStore, pt as getHostBinding, q as createExecutionContext, qt as isRuntimeDiagnostic, r as AccessAuthorizeOption, rn as parseDuration, rt as isResolvable, s as ApprovalDecision, sn as LeaseOperation, st as resolveRuntimeValue, t as AccessAuthorizationContext, tn as Duration, tt as hasCapability, u as CapabilityDefinition, un as LeaseSqlParam, ut as unknownExecutionAuthority, v as OpenTelemetryLogRecordView, vn as ErrorHandle, vt as isSerializedResponse, w as Resolvable, wn as ViteHubContext, wt as getRuntimeContext, x as OpenTelemetrySpanViewOptions, xn as defineErrors, xt as RequestRuntimeContext, y as OpenTelemetrySpanEventView, yn as Result, yt as serializeResponse, z as TraceEventLogEntry, zt as RuntimeDiagnosticReporter } from "./index-C1DoYfCf.js";
|
|
3
3
|
import { a as ExecutionBudgetOptions, c as createExecutionBudget, i as ExecutionBudgetLimits, l as isExecutionBudgetExceededError, n as ExecutionBudgetCounter, o as ExecutionBudgetSnapshot, r as ExecutionBudgetExceededError, s as ExecutionBudgetUsage, t as ExecutionBudget } from "./execution-budget-BPXbISEt.js";
|
|
4
4
|
import { a as resolvePublicUrl, n as consoleInvocationUrl, t as PublicUrlConfig } from "./public-url-1WeOw54Z.js";
|
|
5
|
-
export { AccessAuthorizationContext, AccessAuthorize, AccessAuthorizeOption, AccessAuthorizeResult, AnonymousAccessAuthorizationContext, AnonymousAccessAuthorize, ApprovalDecision, ApprovalRequest, ApprovalState, CapabilityDefinition, CapabilityHandle, CapabilityPolicy, CreatedRuntimeContext, type DefineErrorsOptions, type ErrorCatalog, type ErrorCodes, type ErrorHandle, ExecutionAuthority, type ExecutionBudget, type ExecutionBudgetCounter, type ExecutionBudgetExceededError, type ExecutionBudgetLimits, type ExecutionBudgetOptions, type ExecutionBudgetSnapshot, type ExecutionBudgetUsage, ExecutionContext, type HostBindingErrorCode, type Lease, type LeaseAcquireOptions, type LeaseErrorCode, type LeaseOperation, type LeaseRecord, type LeaseSqlClient, type LeaseSqlParam, type LeaseStore, MaybePromise, MaybeResolvable, OpenTelemetryLogRecordView, OpenTelemetrySpanEventView, OpenTelemetrySpanView, OpenTelemetrySpanViewOptions, PolicyContext, PolicyDecision, type PublicUrlConfig, type RequestRuntimeContext, Resolvable, type Result, type ResultError, RunLifecycleHooks, RuntimeCapabilities, RuntimeCapabilityHandle, RuntimeContextInput, type RuntimeContextOptions, type RuntimeDiagnosticError, type RuntimeDiagnosticErrorOptions, type RuntimeDiagnosticEvent, type RuntimeDiagnosticLevel, type RuntimeDiagnosticReporter, RuntimeHostContext, type RuntimeName, type RuntimeResourceInspector, type RuntimeResourceObservation, type RuntimeResourceScope, type RuntimeResourceSnapshot, type RuntimeResourceSupport, type RuntimeResourceUnit, RuntimeWaitUntil, RuntimeWaitUntilController, type SerializedResponse, TraceActivityContext, TraceActivityOwner, TraceActivityPhase, TraceContext, TraceEvent, TraceEventContentPolicy, TraceEventLog, TraceEventLogEntry, TraceEventLogOptions, TraceEventPayload, TracePayloadVisibility, TraceRunStatus, TraceRunView, TraceStepStatus, TraceStepView, type ViteHubContext, ViteHubError, type ViteHubErrorDetail, type ViteHubErrorDetails, type ViteHubErrorOptions, type ViteHubErrorShape, type ViteHubHost, type ViteHubRuntime, type ViteHubStandardProps, consoleInvocationUrl, createExecutionBudget, createExecutionContext, createMemoryLeaseStore, createRuntimeContext, createRuntimeWaitUntilController, createSqlLeaseStore, createTraceEventLog, decodeRouteSegment, defineCapability, defineErrors, deriveTraceRuns, deserializeResponse, detectHost, emitTraceEvent, encodeRouteSegment, formatRuntimeDiagnosticError, getCapability, getHostBinding, getRuntimeContext, getStandardContext, getViteHubErrorShape, hasCapability, hostedConsoleOrigin, hostedConsoleUrl, isExecutionAuthority, isExecutionBudgetExceededError, isResolvable, isResponse, isRuntimeDiagnostic, isSerializedResponse, isTraceContentAttributeKey, isViteHubError, leaseTable, noExecutionAuthority, normalizeConsolePath, normalizeConsoleProjectUrl, normalizeExecutionAuthority, normalizeRuntimeDiagnosticError, resolveCapabilityPolicy, resolvePublicUrl, resolveRuntimeValue, runtimeErrorDiagnostics, serializeResponse, toResponse, toResultError, traceEventsToOpenTelemetryLogRecords, traceEventsToOpenTelemetrySpans, unknownExecutionAuthority };
|
|
5
|
+
export { AccessAuthorizationContext, AccessAuthorize, AccessAuthorizeOption, AccessAuthorizeResult, AnonymousAccessAuthorizationContext, AnonymousAccessAuthorize, ApprovalDecision, ApprovalRequest, ApprovalState, CapabilityDefinition, CapabilityHandle, CapabilityPolicy, CreatedRuntimeContext, type DefineErrorsOptions, type Duration, type DurationUnit, type ErrorCatalog, type ErrorCodes, type ErrorHandle, ExecutionAuthority, type ExecutionBudget, type ExecutionBudgetCounter, type ExecutionBudgetExceededError, type ExecutionBudgetLimits, type ExecutionBudgetOptions, type ExecutionBudgetSnapshot, type ExecutionBudgetUsage, ExecutionContext, type HostBindingErrorCode, type Lease, type LeaseAcquireOptions, type LeaseErrorCode, type LeaseOperation, type LeaseRecord, type LeaseSqlClient, type LeaseSqlParam, type LeaseStore, MaybePromise, MaybeResolvable, OpenTelemetryLogRecordView, OpenTelemetrySpanEventView, OpenTelemetrySpanView, OpenTelemetrySpanViewOptions, PolicyContext, PolicyDecision, type PublicUrlConfig, type RequestRuntimeContext, Resolvable, type Result, type ResultError, RunLifecycleHooks, RuntimeCapabilities, RuntimeCapabilityHandle, RuntimeContextInput, type RuntimeContextOptions, type RuntimeDiagnosticError, type RuntimeDiagnosticErrorOptions, type RuntimeDiagnosticEvent, type RuntimeDiagnosticLevel, type RuntimeDiagnosticReporter, RuntimeHostContext, type RuntimeName, type RuntimeResourceInspector, type RuntimeResourceObservation, type RuntimeResourceScope, type RuntimeResourceSnapshot, type RuntimeResourceSupport, type RuntimeResourceUnit, RuntimeWaitUntil, RuntimeWaitUntilController, type SerializedResponse, TraceActivityContext, TraceActivityOwner, TraceActivityPhase, TraceContext, TraceEvent, TraceEventContentPolicy, TraceEventLog, TraceEventLogEntry, TraceEventLogOptions, TraceEventPayload, TracePayloadVisibility, TraceRunStatus, TraceRunView, TraceStepStatus, TraceStepView, type ViteHubContext, ViteHubError, type ViteHubErrorDetail, type ViteHubErrorDetails, type ViteHubErrorOptions, type ViteHubErrorShape, type ViteHubHost, type ViteHubRuntime, type ViteHubStandardProps, consoleInvocationUrl, createExecutionBudget, createExecutionContext, createMemoryLeaseStore, createRuntimeContext, createRuntimeWaitUntilController, createSqlLeaseStore, createTraceEventLog, decodeRouteSegment, defineCapability, defineErrors, deriveTraceRuns, deserializeResponse, detectHost, emitTraceEvent, encodeRouteSegment, formatRuntimeDiagnosticError, getCapability, getHostBinding, getRuntimeContext, getStandardContext, getViteHubErrorShape, hasCapability, hostedConsoleOrigin, hostedConsoleUrl, isExecutionAuthority, isExecutionBudgetExceededError, isResolvable, isResponse, isRuntimeDiagnostic, isSerializedResponse, isTraceContentAttributeKey, isViteHubError, leaseTable, noExecutionAuthority, normalizeConsolePath, normalizeConsoleProjectUrl, normalizeExecutionAuthority, normalizeRuntimeDiagnosticError, parseDuration, resolveCapabilityPolicy, resolvePublicUrl, resolveRuntimeValue, runtimeErrorDiagnostics, serializeResponse, toResponse, toResultError, traceEventsToOpenTelemetryLogRecords, traceEventsToOpenTelemetrySpans, unknownExecutionAuthority };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { A as isResponse, B as
|
|
2
|
-
import { t as runtimeErrorDiagnostics } from "./error-diagnostics-
|
|
3
|
-
import { n as getViteHubErrorShape, r as isViteHubError, t as ViteHubError } from "./errors-
|
|
4
|
-
import { a as hostedConsoleOrigin, c as normalizeConsoleProjectUrl, i as resolvePublicUrl, l as decodeRouteSegment, o as hostedConsoleUrl, s as normalizeConsolePath, t as consoleInvocationUrl, u as encodeRouteSegment } from "./public-url-
|
|
5
|
-
export { ViteHubError, consoleInvocationUrl, createExecutionBudget, createExecutionContext, createMemoryLeaseStore, createRuntimeContext, createRuntimeWaitUntilController, createSqlLeaseStore, createTraceEventLog, decodeRouteSegment, defineCapability, defineErrors, deriveTraceRuns, deserializeResponse, detectHost, emitTraceEvent, encodeRouteSegment, formatRuntimeDiagnosticError, getCapability, getHostBinding, getRuntimeContext, getStandardContext, getViteHubErrorShape, hasCapability, hostedConsoleOrigin, hostedConsoleUrl, isExecutionAuthority, isExecutionBudgetExceededError, isResolvable, isResponse, isRuntimeDiagnostic, isSerializedResponse, isTraceContentAttributeKey, isViteHubError, leaseTable, noExecutionAuthority, normalizeConsolePath, normalizeConsoleProjectUrl, normalizeExecutionAuthority, normalizeRuntimeDiagnosticError, resolveCapabilityPolicy, resolvePublicUrl, resolveRuntimeValue, runtimeErrorDiagnostics, serializeResponse, toResponse, toResultError, traceEventsToOpenTelemetryLogRecords, traceEventsToOpenTelemetrySpans, unknownExecutionAuthority };
|
|
1
|
+
import { A as isResponse, B as formatRuntimeDiagnosticError, C as resolveRuntimeValue, D as detectHost, E as unknownExecutionAuthority, F as createMemoryLeaseStore, G as isTraceContentAttributeKey, H as normalizeRuntimeDiagnosticError, I as createSqlLeaseStore, L as leaseTable, M as serializeResponse, N as toResponse, O as getHostBinding, P as parseDuration, R as defineErrors, S as resolveCapabilityPolicy, T as traceEventsToOpenTelemetrySpans, U as createExecutionBudget, V as isRuntimeDiagnostic, W as isExecutionBudgetExceededError, _ as hasCapability, b as noExecutionAuthority, d as createRuntimeWaitUntilController, f as createTraceEventLog, g as getCapability, h as emitTraceEvent, i as getStandardContext, j as isSerializedResponse, k as deserializeResponse, l as createExecutionContext, m as deriveTraceRuns, p as defineCapability, r as getRuntimeContext, u as createRuntimeContext, v as isExecutionAuthority, w as traceEventsToOpenTelemetryLogRecords, x as normalizeExecutionAuthority, y as isResolvable, z as toResultError } from "./request-context-uRQpodgl.js";
|
|
2
|
+
import { t as runtimeErrorDiagnostics } from "./error-diagnostics-BM9W4pBg.js";
|
|
3
|
+
import { n as getViteHubErrorShape, r as isViteHubError, t as ViteHubError } from "./errors-BQ0ofIL4.js";
|
|
4
|
+
import { a as hostedConsoleOrigin, c as normalizeConsoleProjectUrl, i as resolvePublicUrl, l as decodeRouteSegment, o as hostedConsoleUrl, s as normalizeConsolePath, t as consoleInvocationUrl, u as encodeRouteSegment } from "./public-url-ByAmAjbP.js";
|
|
5
|
+
export { ViteHubError, consoleInvocationUrl, createExecutionBudget, createExecutionContext, createMemoryLeaseStore, createRuntimeContext, createRuntimeWaitUntilController, createSqlLeaseStore, createTraceEventLog, decodeRouteSegment, defineCapability, defineErrors, deriveTraceRuns, deserializeResponse, detectHost, emitTraceEvent, encodeRouteSegment, formatRuntimeDiagnosticError, getCapability, getHostBinding, getRuntimeContext, getStandardContext, getViteHubErrorShape, hasCapability, hostedConsoleOrigin, hostedConsoleUrl, isExecutionAuthority, isExecutionBudgetExceededError, isResolvable, isResponse, isRuntimeDiagnostic, isSerializedResponse, isTraceContentAttributeKey, isViteHubError, leaseTable, noExecutionAuthority, normalizeConsolePath, normalizeConsoleProjectUrl, normalizeExecutionAuthority, normalizeRuntimeDiagnosticError, parseDuration, resolveCapabilityPolicy, resolvePublicUrl, resolveRuntimeValue, runtimeErrorDiagnostics, serializeResponse, toResponse, toResultError, traceEventsToOpenTelemetryLogRecords, traceEventsToOpenTelemetrySpans, unknownExecutionAuthority };
|
package/dist/internal/drain.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as runtimeErrorDiagnostics } from "../error-diagnostics-
|
|
1
|
+
import { t as runtimeErrorDiagnostics } from "../error-diagnostics-BM9W4pBg.js";
|
|
2
2
|
//#region src/internal/drain-process.ts
|
|
3
3
|
/** Check whether a process still exists without confusing access denial for exit. */
|
|
4
4
|
function isProcessRunning(pid) {
|
package/dist/internal/grant.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { r as isRuntimeObject } from "../runtime-type-BftydMAf.js";
|
|
2
|
-
import { t as ViteHubError } from "../errors-
|
|
2
|
+
import { t as ViteHubError } from "../errors-BQ0ofIL4.js";
|
|
3
3
|
//#region src/internal/grant.ts
|
|
4
4
|
/**
|
|
5
5
|
* Define one kind of grant. Keep the definition module-private: the module that owns the check issues grants,
|
package/dist/internal/h3.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Dt as sendPreparedResponse, En as ViteHubStandardProps, Et as installRequestStandardContext, St as RuntimeContextOptions, Tn as ViteHubRuntime, wn as ViteHubContext, xt as RequestRuntimeContext } from "../index-C1DoYfCf.js";
|
|
2
2
|
import { EventHandlerRequest } from "h3";
|
|
3
3
|
//#region src/internal/h3.d.ts
|
|
4
4
|
declare module "h3" {
|
package/dist/internal/h3.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as runtimeErrorDiagnostics } from "../error-diagnostics-
|
|
1
|
+
import { J as getCloudflareEnv, K as activeEnvStorageKey, X as ownValue, Y as ownObject, a as installRequestStandardContext, c as sendPreparedResponse, i as getStandardContext$1, n as firstAddress, o as isHostRequest, q as cloudflareOwners, s as requestAddressPaths, t as createStandardRuntimeContext } from "../request-context-uRQpodgl.js";
|
|
2
|
+
import { t as runtimeErrorDiagnostics } from "../error-diagnostics-BM9W4pBg.js";
|
|
3
3
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
4
4
|
//#region ../internal/dist/runtime/cloudflare-env.js
|
|
5
5
|
const runtimeGlobal = globalThis;
|
package/dist/internal/node.d.ts
CHANGED
package/dist/internal/node.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as runtimeErrorDiagnostics } from "../error-diagnostics-
|
|
1
|
+
import { t as runtimeErrorDiagnostics } from "../error-diagnostics-BM9W4pBg.js";
|
|
2
2
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
3
3
|
import { readFile } from "node:fs/promises";
|
|
4
4
|
import { join } from "node:path";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as registerPublicUrlAgentName, r as resetPublicUrlAgentNames } from "../public-url-
|
|
1
|
+
import { n as registerPublicUrlAgentName, r as resetPublicUrlAgentNames } from "../public-url-ByAmAjbP.js";
|
|
2
2
|
export { registerPublicUrlAgentName, resetPublicUrlAgentNames };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
//#region src/internal/run-failed.d.ts
|
|
2
|
+
/** The error of a failed run: its message and, for a ViteHub error, its code. */
|
|
3
|
+
export interface RunFailedError {
|
|
4
|
+
message: string;
|
|
5
|
+
code?: string;
|
|
6
|
+
}
|
|
7
|
+
/** A run that ended in failure: no retry is left. Agent, Workflow, and Schedule emit it, and Webhooks sends it. */
|
|
8
|
+
export type RunFailedEvent = {
|
|
9
|
+
event: "invocation.failed";
|
|
10
|
+
agent: string | null;
|
|
11
|
+
invocationId: string;
|
|
12
|
+
error: RunFailedError;
|
|
13
|
+
failedAt: string;
|
|
14
|
+
} | {
|
|
15
|
+
event: "workflow.failed";
|
|
16
|
+
workflow: string;
|
|
17
|
+
runId: string;
|
|
18
|
+
error: RunFailedError;
|
|
19
|
+
failedAt: string;
|
|
20
|
+
} | {
|
|
21
|
+
event: "schedule.failed";
|
|
22
|
+
schedule: string;
|
|
23
|
+
runId: string;
|
|
24
|
+
error: RunFailedError;
|
|
25
|
+
failedAt: string;
|
|
26
|
+
};
|
|
27
|
+
export type RunFailedEventName = RunFailedEvent["event"];
|
|
28
|
+
export declare const runFailedEventNames: readonly RunFailedEventName[];
|
|
29
|
+
export type RunFailedListener = (event: RunFailedEvent) => unknown;
|
|
30
|
+
/** Calls `listener` for each run that ends in failure in this process. Returns a function that removes it. */
|
|
31
|
+
export declare function onRunFailed(listener: RunFailedListener): () => void;
|
|
32
|
+
/** The message and code of a thrown value. */
|
|
33
|
+
export declare function toRunFailedError(error: unknown): RunFailedError;
|
|
34
|
+
/**
|
|
35
|
+
* Tells the listeners that a run ended in failure. Call it once, when no retry is left. It waits for the listeners, so a
|
|
36
|
+
* serverless host keeps the work alive, and it never throws: an alert that fails must not change the run.
|
|
37
|
+
*/
|
|
38
|
+
export declare function emitRunFailed(event: RunFailedEvent): Promise<void>;
|
|
39
|
+
export declare function hasRunFailedListeners(): boolean;
|
|
40
|
+
//#endregion
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
//#region src/internal/run-failed.ts
|
|
2
|
+
const runFailedEventNames = [
|
|
3
|
+
"invocation.failed",
|
|
4
|
+
"schedule.failed",
|
|
5
|
+
"workflow.failed"
|
|
6
|
+
];
|
|
7
|
+
const listenersKey = Symbol.for("vitehub.runtime.runFailedListeners");
|
|
8
|
+
function listeners() {
|
|
9
|
+
const runtimeGlobal = globalThis;
|
|
10
|
+
return runtimeGlobal[listenersKey] ??= /* @__PURE__ */ new Set();
|
|
11
|
+
}
|
|
12
|
+
/** Calls `listener` for each run that ends in failure in this process. Returns a function that removes it. */
|
|
13
|
+
function onRunFailed(listener) {
|
|
14
|
+
listeners().add(listener);
|
|
15
|
+
return () => {
|
|
16
|
+
listeners().delete(listener);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** Long messages, such as a stack in a message, are cut to this many characters. */
|
|
20
|
+
const maxMessageLength = 2e3;
|
|
21
|
+
/** The message and code of a thrown value. */
|
|
22
|
+
function toRunFailedError(error) {
|
|
23
|
+
const record = typeof error === "object" && error !== null ? error : void 0;
|
|
24
|
+
let message;
|
|
25
|
+
let code;
|
|
26
|
+
try {
|
|
27
|
+
const value = record && "message" in record ? Reflect.get(record, "message") : error;
|
|
28
|
+
message = typeof value === "string" ? value : String(value);
|
|
29
|
+
} catch {
|
|
30
|
+
message = "[unprintable thrown value]";
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
code = record ? Reflect.get(record, "code") : void 0;
|
|
34
|
+
} catch {
|
|
35
|
+
code = void 0;
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
message: message.length > maxMessageLength ? `${message.slice(0, maxMessageLength)}…` : message,
|
|
39
|
+
...typeof code === "string" && code ? { code } : {}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Tells the listeners that a run ended in failure. Call it once, when no retry is left. It waits for the listeners, so a
|
|
44
|
+
* serverless host keeps the work alive, and it never throws: an alert that fails must not change the run.
|
|
45
|
+
*/
|
|
46
|
+
async function emitRunFailed(event) {
|
|
47
|
+
const current = [...listeners()];
|
|
48
|
+
if (!current.length) return;
|
|
49
|
+
const results = await Promise.allSettled(current.map(async (listener) => await listener(event)));
|
|
50
|
+
for (const result of results) if (result.status === "rejected") console.error(`[vitehub] A listener of ${event.event} failed.`, result.reason);
|
|
51
|
+
}
|
|
52
|
+
function hasRunFailedListeners() {
|
|
53
|
+
return listeners().size > 0;
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
export { emitRunFailed, hasRunFailedListeners, onRunFailed, runFailedEventNames, toRunFailedError };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { t as runtimeErrorDiagnostics } from "../error-diagnostics-
|
|
1
|
+
import { t as runtimeErrorDiagnostics } from "../error-diagnostics-BM9W4pBg.js";
|
|
2
2
|
import { i as isRuntimeResponse, n as hasRuntimeType, r as isRuntimeObject, t as asUnknownBoundary } from "../runtime-type-BftydMAf.js";
|
|
3
3
|
export { asUnknownBoundary, hasRuntimeType, isRuntimeObject, isRuntimeResponse, runtimeErrorDiagnostics };
|
package/dist/operations.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
-
//#region ../internal/dist/operation-definition-
|
|
2
|
+
//#region ../internal/dist/operation-definition-BQGzmZRs.d.ts
|
|
3
3
|
//#region src/operation-definition.d.ts
|
|
4
4
|
/** `read` never changes state. `write` changes state. `destructive` deletes or publishes. */
|
|
5
5
|
type OperationKind = "read" | "write" | "destructive";
|
|
@@ -40,6 +40,11 @@ interface OperationContext {
|
|
|
40
40
|
surface: "console" | "cli" | "mcp" | "agent";
|
|
41
41
|
/** Set by the host from generated build identity, never from request input or runtime NODE_ENV. */
|
|
42
42
|
development?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* The project root of a development server, for operations that read build files, such as `bundle.report`. Hosts set
|
|
45
|
+
* it only with `development`, so a deployed server never reads project files through it.
|
|
46
|
+
*/
|
|
47
|
+
projectRoot?: string;
|
|
43
48
|
env?: Record<string, unknown>;
|
|
44
49
|
waitUntil?: (task: Promise<unknown>) => void;
|
|
45
50
|
request?: Request;
|
package/dist/operations.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineDiagnostics } from "nostics";
|
|
2
2
|
import { toJsonSchema } from "@valibot/to-json-schema";
|
|
3
|
-
//#region ../internal/dist/error-diagnostics-
|
|
3
|
+
//#region ../internal/dist/error-diagnostics-D7txO3cV.js
|
|
4
4
|
const dynamicError = { why: ({ message }) => message === void 0 ? "" : String(message) };
|
|
5
5
|
const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
6
6
|
docsBase: "https://vitehub.dev/docs/development/diagnostics",
|
|
@@ -171,7 +171,7 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
171
171
|
},
|
|
172
172
|
INTERNAL_R0004: {
|
|
173
173
|
...dynamicError,
|
|
174
|
-
fix: "Set a larger `maxResponseBytes` on the HTTP request, such as the `
|
|
174
|
+
fix: "Set a larger `maxResponseBytes` on the HTTP request, such as the `url()` Source options, or ask the server for a smaller response."
|
|
175
175
|
},
|
|
176
176
|
INTERNAL_R0005: {
|
|
177
177
|
...dynamicError,
|
|
@@ -217,6 +217,10 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
217
217
|
why: ({ variable }) => `[vitehub] ${variable} must be the 43-character private key that \`vitehub secret console-key\` prints, and its name 1 to 64 of A-Z, 0-9, and _.`,
|
|
218
218
|
fix: "Set the variable that the message names to the private key that `vitehub secret console-key` prints, and name it `VITEHUB_CONSOLE_PRIVATE_KEY_<NAME>` with A-Z, 0-9, and _ in `<NAME>`."
|
|
219
219
|
},
|
|
220
|
+
INTERNAL_DEV_SERVER_NOT_FOUND: {
|
|
221
|
+
why: ({ command }) => `[vitehub] No dev server of this project is running, and --url is not set, so \`vitehub ${command}\` has no app to call.`,
|
|
222
|
+
fix: "Start the dev server of this project, such as with `pnpm dev`, or pass --url with the app URL, such as --url http://localhost:3000."
|
|
223
|
+
},
|
|
220
224
|
INTERNAL_FORGE_NOT_INSTALLED: {
|
|
221
225
|
why: ({ feature }) => `${feature} needs @vite-hub/forge, and the app did not install it.`,
|
|
222
226
|
fix: "Install Forge in your app with `pnpm add @vite-hub/forge`, then build again."
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as runtimeErrorDiagnostics } from "./error-diagnostics-
|
|
1
|
+
import { t as runtimeErrorDiagnostics } from "./error-diagnostics-BM9W4pBg.js";
|
|
2
2
|
//#region src/route-segment.ts
|
|
3
3
|
const plainSegment = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
4
4
|
function encodeRouteSegment(value) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as runtimeErrorDiagnostics } from "./error-diagnostics-
|
|
1
|
+
import { t as runtimeErrorDiagnostics } from "./error-diagnostics-BM9W4pBg.js";
|
|
2
2
|
import { r as isRuntimeObject } from "./runtime-type-BftydMAf.js";
|
|
3
|
-
import { n as getViteHubErrorShape, t as ViteHubError } from "./errors-
|
|
3
|
+
import { n as getViteHubErrorShape, t as ViteHubError } from "./errors-BQ0ofIL4.js";
|
|
4
4
|
import { Diagnostic, defineDiagnostics, formatDiagnostic } from "nostics";
|
|
5
5
|
//#region ../internal/dist/runtime/cloudflare-env-lookup.js
|
|
6
6
|
/** The key of the AsyncLocalStorage store on `globalThis`. Every bundled copy of this module shares the store. */
|
|
@@ -373,15 +373,23 @@ function normalizeLimits(options) {
|
|
|
373
373
|
}
|
|
374
374
|
//#endregion
|
|
375
375
|
//#region src/diagnostics.ts
|
|
376
|
+
/** Recognizes an `Error` from any realm, without reading its properties. */
|
|
377
|
+
function isNativeError(value) {
|
|
378
|
+
if (!isRuntimeObject(value)) return false;
|
|
379
|
+
try {
|
|
380
|
+
const nativeIsError = Reflect.get(Error, "isError");
|
|
381
|
+
return typeof nativeIsError === "function" ? nativeIsError(value) === true : value instanceof Error || !(Symbol.toStringTag in value) && Object.prototype.toString.call(value) === "[object Error]";
|
|
382
|
+
} catch {
|
|
383
|
+
return false;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
376
386
|
/**
|
|
377
387
|
* Recognizes a live Nostics error across bundled copies. This does not make its fields safe for public responses.
|
|
378
388
|
* nostics' own check matches only its own copy (https://github.com/vercel-labs/nostics/pull/40).
|
|
379
389
|
*/
|
|
380
390
|
function isRuntimeDiagnostic(error) {
|
|
381
|
-
if (!
|
|
391
|
+
if (!isNativeError(error)) return false;
|
|
382
392
|
try {
|
|
383
|
-
const nativeIsError = Reflect.get(Error, "isError");
|
|
384
|
-
if (!(typeof nativeIsError === "function" ? nativeIsError(error) === true : error instanceof Error || !(Symbol.toStringTag in error) && Object.prototype.toString.call(error) === "[object Error]")) return false;
|
|
385
393
|
const message = Reflect.get(error, "message");
|
|
386
394
|
const code = Reflect.get(error, "code");
|
|
387
395
|
const name = Reflect.get(error, "name");
|
|
@@ -550,6 +558,7 @@ function normalizeRuntimeDiagnosticError(error, options = {}) {
|
|
|
550
558
|
}
|
|
551
559
|
//#endregion
|
|
552
560
|
//#region src/result.ts
|
|
561
|
+
const resultErrorBrand = Symbol.for("vitehub.runtime.resultError");
|
|
553
562
|
/**
|
|
554
563
|
* Prepares a recognized diagnostic for a result, keeping its metadata in memory.
|
|
555
564
|
* Reuses mutable diagnostics; copies diagnostics whose name or serializer cannot be replaced.
|
|
@@ -561,7 +570,7 @@ function toResultError(error) {
|
|
|
561
570
|
const descriptor = Object.getOwnPropertyDescriptor(error, key);
|
|
562
571
|
return descriptor ? descriptor.configurable === true : Object.isExtensible(error);
|
|
563
572
|
};
|
|
564
|
-
const result = canReplace("name") && canReplace("toJSON") ? error : new Diagnostic({
|
|
573
|
+
const result = canReplace("name") && canReplace("toJSON") && (Object.hasOwn(error, resultErrorBrand) || Object.isExtensible(error)) ? error : new Diagnostic({
|
|
565
574
|
code: error.code,
|
|
566
575
|
why: error.why,
|
|
567
576
|
fix: error.fix,
|
|
@@ -570,12 +579,20 @@ function toResultError(error) {
|
|
|
570
579
|
data: error.data,
|
|
571
580
|
sources: error.sources
|
|
572
581
|
});
|
|
573
|
-
if (result !== error)
|
|
582
|
+
if (result !== error) {
|
|
583
|
+
result.stack = error.stack;
|
|
584
|
+
const status = Reflect.get(error, "status");
|
|
585
|
+
if (typeof status === "number") Object.defineProperty(result, "status", {
|
|
586
|
+
configurable: true,
|
|
587
|
+
value: status
|
|
588
|
+
});
|
|
589
|
+
}
|
|
574
590
|
Object.defineProperty(result, "name", {
|
|
575
591
|
configurable: true,
|
|
576
592
|
value: result.code,
|
|
577
593
|
writable: true
|
|
578
594
|
});
|
|
595
|
+
Object.defineProperty(result, resultErrorBrand, { value: true });
|
|
579
596
|
Object.defineProperty(result, "toJSON", {
|
|
580
597
|
configurable: true,
|
|
581
598
|
value: () => ({
|
|
@@ -597,14 +614,23 @@ function defineErrors(options) {
|
|
|
597
614
|
const catalog = Object.defineProperty({}, "is", { value: (error) => isRuntimeDiagnostic(error) && codes.has(error.code) });
|
|
598
615
|
for (const code of codes) {
|
|
599
616
|
const create = diagnostics[code];
|
|
600
|
-
|
|
617
|
+
const status = options.codes[code]?.status;
|
|
618
|
+
catalog[code] = Object.assign((params) => {
|
|
619
|
+
const error = toResultError(create(params));
|
|
620
|
+
if (status !== void 0) Object.defineProperty(error, "status", {
|
|
621
|
+
configurable: true,
|
|
622
|
+
enumerable: false,
|
|
623
|
+
value: status
|
|
624
|
+
});
|
|
625
|
+
return error;
|
|
626
|
+
}, { is: (error) => isRuntimeDiagnostic(error) && error.code === code });
|
|
601
627
|
}
|
|
602
628
|
return catalog;
|
|
603
629
|
}
|
|
604
630
|
//#endregion
|
|
605
631
|
//#region src/lease.ts
|
|
606
632
|
const leaseErrorDiagnostics = /*#__PURE__*/ defineErrors({
|
|
607
|
-
docs: "https://vitehub.dev/docs/
|
|
633
|
+
docs: "https://vitehub.dev/docs/runtime/diagnostics",
|
|
608
634
|
codes: {
|
|
609
635
|
RUNTIME_LEASE_INVALID_TTL: {
|
|
610
636
|
why: "`ttl` must be a positive number of seconds.",
|
|
@@ -844,6 +870,96 @@ function createSqlLeaseStore(client) {
|
|
|
844
870
|
});
|
|
845
871
|
}
|
|
846
872
|
//#endregion
|
|
873
|
+
//#region src/duration.ts
|
|
874
|
+
const second = 1e3;
|
|
875
|
+
const minute = 60 * second;
|
|
876
|
+
const hour = 60 * minute;
|
|
877
|
+
const day = 24 * hour;
|
|
878
|
+
const week = 7 * day;
|
|
879
|
+
const units = {
|
|
880
|
+
ms: 1,
|
|
881
|
+
millisecond: 1,
|
|
882
|
+
milliseconds: 1,
|
|
883
|
+
s: second,
|
|
884
|
+
sec: second,
|
|
885
|
+
secs: second,
|
|
886
|
+
second,
|
|
887
|
+
seconds: second,
|
|
888
|
+
m: minute,
|
|
889
|
+
min: minute,
|
|
890
|
+
mins: minute,
|
|
891
|
+
minute,
|
|
892
|
+
minutes: minute,
|
|
893
|
+
h: hour,
|
|
894
|
+
hr: hour,
|
|
895
|
+
hrs: hour,
|
|
896
|
+
hour,
|
|
897
|
+
hours: hour,
|
|
898
|
+
d: day,
|
|
899
|
+
day,
|
|
900
|
+
days: day,
|
|
901
|
+
w: week,
|
|
902
|
+
week,
|
|
903
|
+
weeks: week
|
|
904
|
+
};
|
|
905
|
+
const pattern = /^(\d+(?:\.\d+)?)\s*([a-z]+)$/i;
|
|
906
|
+
/** The shortest whole string form of `milliseconds`, such as `"5m"` for `300000`. */
|
|
907
|
+
function suggest(milliseconds) {
|
|
908
|
+
for (const [unit, size] of [
|
|
909
|
+
["w", week],
|
|
910
|
+
["d", day],
|
|
911
|
+
["h", hour],
|
|
912
|
+
["m", minute],
|
|
913
|
+
["s", second]
|
|
914
|
+
]) if (milliseconds >= size && milliseconds % size === 0) return `"${milliseconds / size}${unit}"`;
|
|
915
|
+
return `"${milliseconds}ms"`;
|
|
916
|
+
}
|
|
917
|
+
/** Names a value for an error without converting an object, which could run its code. */
|
|
918
|
+
function describe(value) {
|
|
919
|
+
if (typeof value === "string") return JSON.stringify(value);
|
|
920
|
+
if (typeof value === "object" && value !== null) return "an object";
|
|
921
|
+
return typeof value === "function" || typeof value === "symbol" ? `a ${typeof value}` : String(value);
|
|
922
|
+
}
|
|
923
|
+
function toMilliseconds(amount, size, round) {
|
|
924
|
+
const [whole, fraction = ""] = amount.split(".");
|
|
925
|
+
const scaled = BigInt(`${whole}${fraction}`) * BigInt(size);
|
|
926
|
+
if (fraction.length === 0) return Number(scaled);
|
|
927
|
+
if (round === "ceil") {
|
|
928
|
+
const divisor = 10n ** BigInt(fraction.length);
|
|
929
|
+
return Number((scaled + divisor - 1n) / divisor);
|
|
930
|
+
}
|
|
931
|
+
return Number(`${scaled}e-${fraction.length}`);
|
|
932
|
+
}
|
|
933
|
+
/**
|
|
934
|
+
* Reads a {@link Duration} such as `"30s"`, `"5m"`, or `"1 day"` and returns its milliseconds. A number, a negative
|
|
935
|
+
* value, an unknown unit, or a value too large for a number throws `RUNTIME_DURATION_INVALID`. Pass `option`, such as
|
|
936
|
+
* `"debounce"`, so the error names the option. Pass `"ceil"` to round up to whole milliseconds before converting
|
|
937
|
+
* to a number. For a number, the fix shows the same time as a string. Pass `"s"` as `legacyUnit` when the option took a
|
|
938
|
+
* number of seconds before, so `60` gets the fix `"1m"` and not `"60ms"`. It changes only the fix text.
|
|
939
|
+
*
|
|
940
|
+
* ```ts
|
|
941
|
+
* parseDuration("90s") // 90000
|
|
942
|
+
* parseDuration("1 day") // 86400000
|
|
943
|
+
* ```
|
|
944
|
+
*/
|
|
945
|
+
function parseDuration(value, option, round, legacyUnit = "ms") {
|
|
946
|
+
const [, amount, suffix] = (typeof value === "string" ? pattern.exec(value.trim()) : null) ?? [];
|
|
947
|
+
const unit = suffix?.toLowerCase();
|
|
948
|
+
const size = unit !== void 0 && Object.hasOwn(units, unit) ? units[unit] : void 0;
|
|
949
|
+
const milliseconds = amount === void 0 || size === void 0 ? NaN : toMilliseconds(amount, size, round);
|
|
950
|
+
if (Number.isFinite(milliseconds)) return milliseconds;
|
|
951
|
+
const received = value;
|
|
952
|
+
const legacy = typeof received === "number" && received >= 0 ? received * (legacyUnit === "s" ? second : 1) : NaN;
|
|
953
|
+
const suggestion = Number.isFinite(legacy) ? suggest(legacy) : void 0;
|
|
954
|
+
const legacyUnitName = legacyUnit === "s" ? "seconds" : "milliseconds";
|
|
955
|
+
throw runtimeErrorDiagnostics.RUNTIME_DURATION_INVALID({
|
|
956
|
+
option,
|
|
957
|
+
value: describe(received),
|
|
958
|
+
suggestion,
|
|
959
|
+
unit: legacyUnitName
|
|
960
|
+
});
|
|
961
|
+
}
|
|
962
|
+
//#endregion
|
|
847
963
|
//#region src/response.ts
|
|
848
964
|
function prototypeGetter(constructor, key) {
|
|
849
965
|
return Object.getOwnPropertyDescriptor(constructor.prototype, key)?.get;
|
|
@@ -910,14 +1026,57 @@ function isArrayBufferValue(value) {
|
|
|
910
1026
|
return false;
|
|
911
1027
|
}
|
|
912
1028
|
}
|
|
913
|
-
|
|
1029
|
+
const jsonHeaders = { "content-type": "application/json; charset=utf-8" };
|
|
1030
|
+
/**
|
|
1031
|
+
* Normalize a primitive value into the native Web Response contract.
|
|
1032
|
+
* An error answers with `{ code, why, fix }` and never with its `stack`, `cause`, or `data`:
|
|
1033
|
+
* - A ResultError or other Nostics diagnostic answers its `status`, or 500, so a route can `return toResponse(error)`.
|
|
1034
|
+
* - A `ViteHubError` answers 500 with its `code` and its message as `why`.
|
|
1035
|
+
* - Any other `Error` answers 500 with `RUNTIME_HIDDEN_ERROR`, because its message can hold server details.
|
|
1036
|
+
*/
|
|
914
1037
|
function toResponse(value) {
|
|
915
1038
|
if (isResponse(value)) return value;
|
|
1039
|
+
if (isNativeError(value)) return errorResponse(value);
|
|
916
1040
|
if (value === void 0) return new Response(null, { status: 204 });
|
|
917
1041
|
if (typeof value === "string" || value instanceof Blob || isArrayBufferValue(value) || ArrayBuffer.isView(value)) return new Response(value);
|
|
918
1042
|
const blobMethods = getBlobMethods(value);
|
|
919
1043
|
if (blobMethods) return new Response(blobMethods.body(), blobMethods.type ? { headers: { "content-type": blobMethods.type } } : void 0);
|
|
920
|
-
return new Response(JSON.stringify(value), { headers:
|
|
1044
|
+
return new Response(JSON.stringify(value), { headers: jsonHeaders });
|
|
1045
|
+
}
|
|
1046
|
+
function errorResponse(error) {
|
|
1047
|
+
let body;
|
|
1048
|
+
let status;
|
|
1049
|
+
if (isRuntimeDiagnostic(error)) try {
|
|
1050
|
+
body = {
|
|
1051
|
+
code: error.code,
|
|
1052
|
+
why: error.why,
|
|
1053
|
+
fix: error.fix
|
|
1054
|
+
};
|
|
1055
|
+
status = Reflect.get(error, "status");
|
|
1056
|
+
} catch {
|
|
1057
|
+
body = void 0;
|
|
1058
|
+
}
|
|
1059
|
+
else {
|
|
1060
|
+
const shape = getViteHubErrorShape(error);
|
|
1061
|
+
if (shape) body = {
|
|
1062
|
+
code: shape.code,
|
|
1063
|
+
why: shape.message,
|
|
1064
|
+
fix: void 0
|
|
1065
|
+
};
|
|
1066
|
+
}
|
|
1067
|
+
if (!body || typeof body.code !== "string" || typeof body.why !== "string" || body.fix !== void 0 && typeof body.fix !== "string") {
|
|
1068
|
+
const hidden = runtimeErrorDiagnostics.RUNTIME_HIDDEN_ERROR();
|
|
1069
|
+
body = {
|
|
1070
|
+
code: hidden.code,
|
|
1071
|
+
why: hidden.why,
|
|
1072
|
+
fix: hidden.fix
|
|
1073
|
+
};
|
|
1074
|
+
status = 500;
|
|
1075
|
+
}
|
|
1076
|
+
return new Response(JSON.stringify(body), {
|
|
1077
|
+
headers: jsonHeaders,
|
|
1078
|
+
status: typeof status === "number" && Number.isInteger(status) && status >= 400 && status <= 599 ? status : 500
|
|
1079
|
+
});
|
|
921
1080
|
}
|
|
922
1081
|
/** Recognize Responses created by another realm from their standard tag and surface. */
|
|
923
1082
|
function isResponse(value) {
|
|
@@ -1081,7 +1240,7 @@ function detectHost$1(env = process.env) {
|
|
|
1081
1240
|
//#endregion
|
|
1082
1241
|
//#region src/host.ts
|
|
1083
1242
|
const hostBindingErrors = /*#__PURE__*/ defineErrors({
|
|
1084
|
-
docs: "https://vitehub.dev/docs/
|
|
1243
|
+
docs: "https://vitehub.dev/docs/runtime/diagnostics",
|
|
1085
1244
|
codes: {
|
|
1086
1245
|
RUNTIME_HOST_BINDINGS_UNAVAILABLE: {
|
|
1087
1246
|
why: ({ name }) => `This code runs without host bindings, so the binding "${name}" is not available. Only Cloudflare Workers give bindings.`,
|
|
@@ -2271,4 +2430,4 @@ function getRuntimeContext(value, options = {}) {
|
|
|
2271
2430
|
return createStandardRuntimeContext(value, getStandardContext(value), options);
|
|
2272
2431
|
}
|
|
2273
2432
|
//#endregion
|
|
2274
|
-
export { isResponse as A,
|
|
2433
|
+
export { isResponse as A, formatRuntimeDiagnosticError as B, resolveRuntimeValue as C, detectHost as D, unknownExecutionAuthority as E, createMemoryLeaseStore as F, isTraceContentAttributeKey as G, normalizeRuntimeDiagnosticError as H, createSqlLeaseStore as I, getCloudflareEnv as J, activeEnvStorageKey as K, leaseTable as L, serializeResponse as M, toResponse as N, getHostBinding as O, parseDuration as P, defineErrors as R, resolveCapabilityPolicy as S, traceEventsToOpenTelemetrySpans as T, createExecutionBudget as U, isRuntimeDiagnostic as V, isExecutionBudgetExceededError as W, ownValue as X, ownObject as Y, hasCapability as _, installRequestStandardContext as a, noExecutionAuthority as b, sendPreparedResponse as c, createRuntimeWaitUntilController as d, createTraceEventLog as f, getCapability as g, emitTraceEvent as h, getStandardContext as i, isSerializedResponse as j, deserializeResponse as k, createExecutionContext as l, deriveTraceRuns as m, firstAddress as n, isHostRequest as o, defineCapability as p, cloudflareOwners as q, getRuntimeContext as r, requestAddressPaths as s, createStandardRuntimeContext as t, createRuntimeContext as u, isExecutionAuthority as v, traceEventsToOpenTelemetryLogRecords as w, normalizeExecutionAuthority as x, isResolvable as y, toResultError as z };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vite-hub/runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Shared runtime context, capability, policy, approval, and tracing primitives for ViteHub.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"approvals",
|
|
@@ -67,6 +67,11 @@
|
|
|
67
67
|
"import": "./dist/internal/public-url.js",
|
|
68
68
|
"default": "./dist/internal/public-url.js"
|
|
69
69
|
},
|
|
70
|
+
"./internal/run-failed": {
|
|
71
|
+
"types": "./dist/internal/run-failed.d.ts",
|
|
72
|
+
"import": "./dist/internal/run-failed.js",
|
|
73
|
+
"default": "./dist/internal/run-failed.js"
|
|
74
|
+
},
|
|
70
75
|
"./internal/run-scope": {
|
|
71
76
|
"types": "./dist/internal/run-scope.d.ts",
|
|
72
77
|
"import": "./dist/internal/run-scope.js",
|
|
@@ -118,7 +123,7 @@
|
|
|
118
123
|
"vitest": "^4.1.11"
|
|
119
124
|
},
|
|
120
125
|
"engines": {
|
|
121
|
-
"node": ">=
|
|
126
|
+
"node": ">=24.15.0"
|
|
122
127
|
},
|
|
123
128
|
"scripts": {
|
|
124
129
|
"build": "vp pack",
|