@vite-hub/runtime 0.0.4 → 0.3.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.
Files changed (44) hide show
  1. package/README.md +278 -41
  2. package/dist/durability.d.ts +107 -0
  3. package/dist/durability.js +168 -0
  4. package/dist/error-diagnostics-BKICpwZp.js +85 -0
  5. package/dist/error-diagnostics-BsJr9VdW.d.ts +15 -0
  6. package/dist/errors-BEomN3fX.js +190 -0
  7. package/dist/execution-budget-BPXbISEt.d.ts +56 -0
  8. package/dist/index-Bcl-Hr-a.d.ts +678 -0
  9. package/dist/index.d.ts +5 -2
  10. package/dist/index.js +5 -1159
  11. package/dist/internal/drain.d.ts +17 -0
  12. package/dist/internal/drain.js +75 -0
  13. package/dist/internal/execution-budget.d.ts +10 -0
  14. package/dist/internal/execution-budget.js +17 -0
  15. package/dist/internal/grant.d.ts +36 -0
  16. package/dist/internal/grant.js +44 -0
  17. package/dist/internal/h3.d.ts +42 -0
  18. package/dist/internal/h3.js +181 -0
  19. package/dist/internal/node.d.ts +33 -0
  20. package/dist/{node.js → internal/node.js} +12 -9
  21. package/dist/internal/public-url.d.ts +2 -0
  22. package/dist/internal/public-url.js +2 -0
  23. package/dist/internal/run-scope.d.ts +11 -0
  24. package/dist/internal/run-scope.js +30 -0
  25. package/dist/internal/runtime-type.d.ts +26 -0
  26. package/dist/internal/runtime-type.js +3 -0
  27. package/dist/internal/shutdown.d.ts +84 -0
  28. package/dist/internal/shutdown.js +202 -0
  29. package/dist/internal/test-mode-setup.d.ts +7 -0
  30. package/dist/internal/test-mode-setup.js +114 -0
  31. package/dist/internal/test-mode.d.ts +32 -0
  32. package/dist/internal/test-mode.js +9 -0
  33. package/dist/operations.d.ts +167 -0
  34. package/dist/operations.js +406 -0
  35. package/dist/public-url-1WeOw54Z.d.ts +34 -0
  36. package/dist/public-url-B6x0HMgY.js +140 -0
  37. package/dist/request-context-CP9NhgLL.js +2274 -0
  38. package/dist/runtime-type-BftydMAf.js +88 -0
  39. package/package.json +92 -17
  40. package/dist/drain.d.ts +0 -1
  41. package/dist/drain.js +0 -52
  42. package/dist/index-tBKyUP1T.d.ts +0 -314
  43. package/dist/node.d.ts +0 -35
  44. package/dist/runtime-type-ovvOd6m5.js +0 -37
@@ -0,0 +1,88 @@
1
+ import { defineDiagnostics } from "nostics";
2
+ //#region ../internal/dist/invariant.js
3
+ const invariantDiagnostics = /*#__PURE__*/ defineDiagnostics({
4
+ docsBase: "https://vitehub.dev/docs/development/diagnostics",
5
+ codes: { INTERNAL_INVARIANT_FAILED: {
6
+ why: ({ what }) => `ViteHub reached a state that it does not expect: ${what}`,
7
+ fix: "This is a ViteHub bug. Open an issue at https://github.com/vite-hub/vitehub/issues with this error message and its stack trace."
8
+ } }
9
+ });
10
+ /**
11
+ * The error for a state that only a ViteHub bug can reach, such as an impossible branch. `what` says which rule broke.
12
+ * Use a code from the package catalog when a developer can cause the error or fix it.
13
+ */
14
+ function invariantError(what) {
15
+ return invariantDiagnostics.INTERNAL_INVARIANT_FAILED({ what });
16
+ }
17
+ //#endregion
18
+ //#region src/internal/runtime-type.ts
19
+ /** Narrows opaque inputs without reading their properties. Kept for `@vite-hub/presets`; other packages use `typeof`. */
20
+ function hasRuntimeType(value, expected) {
21
+ switch (expected) {
22
+ case "bigint":
23
+ case "boolean":
24
+ case "function":
25
+ case "number":
26
+ case "object":
27
+ case "string":
28
+ case "symbol":
29
+ case "undefined": {
30
+ const representation = typeof value;
31
+ return (representation === "undefined" && value !== void 0 ? "function" : representation) === expected;
32
+ }
33
+ }
34
+ throw invariantError(`hasRuntimeType() receives only a key of RuntimeTypeMap, not ${String(expected)}`);
35
+ }
36
+ /** Marks an intentional structural boundary that TypeScript cannot express. */
37
+ function asUnknownBoundary(value) {
38
+ return value;
39
+ }
40
+ function isRuntimeObject(value) {
41
+ return value !== null && Object(value) === value;
42
+ }
43
+ /** Whether a value is an object literal or a null-prototype record. A built-in object whose prototype code replaced reads as one. */
44
+ function isPlainRecord(value) {
45
+ const prototype = Object.getPrototypeOf(value);
46
+ return prototype === Object.prototype || prototype === null;
47
+ }
48
+ /** The native Response class and its `status` getter, and the proxy check of Node.js. Read once, at import. */
49
+ function captureResponseChecks() {
50
+ const response = globalThis.Response;
51
+ return {
52
+ response,
53
+ status: typeof response === "function" ? Object.getOwnPropertyDescriptor(Response.prototype, "status")?.get : void 0,
54
+ isProxy: globalThis.process?.getBuiltinModule?.("node:util")?.types.isProxy
55
+ };
56
+ }
57
+ const nativeResponseChecks = /* @__PURE__ */ captureResponseChecks();
58
+ /**
59
+ * The `status` getter of the global `Response` when a server replaced the native class. srvx, which Nitro uses on Node.js,
60
+ * installs its own `Response` class, so `Response.json()` in app code and in ViteHub returns an instance of that class.
61
+ * Its getters read private fields, so they check the brand like the native getter does.
62
+ */
63
+ function replacedResponseStatus() {
64
+ const current = globalThis.Response;
65
+ if (typeof current !== "function" || current === nativeResponseChecks.response) return void 0;
66
+ const prototype = Reflect.get(current, "prototype");
67
+ return isRuntimeObject(prototype) ? Object.getOwnPropertyDescriptor(prototype, "status")?.get : void 0;
68
+ }
69
+ /**
70
+ * Return whether `value` is a Response of this runtime: of the native class, or of the class that the server installed
71
+ * as the global `Response`.
72
+ * The `status` getter checks the internal Response slot, so a copied prototype, an object tagged `Response`,
73
+ * and a Response from another Fetch implementation all fail. A proxy fails too. The check reads no property of `value`.
74
+ */
75
+ function isRuntimeResponse(value) {
76
+ if (value === null || typeof value !== "object" || nativeResponseChecks.isProxy?.(value)) return false;
77
+ if (nativeResponseChecks.isProxy !== void 0 && (Array.isArray(value) || isPlainRecord(value))) return false;
78
+ for (const status of [nativeResponseChecks.status, replacedResponseStatus()]) {
79
+ if (!status) continue;
80
+ try {
81
+ Reflect.apply(status, value, []);
82
+ return true;
83
+ } catch {}
84
+ }
85
+ return false;
86
+ }
87
+ //#endregion
88
+ export { isRuntimeResponse as i, hasRuntimeType as n, isRuntimeObject as r, asUnknownBoundary as t };
package/package.json CHANGED
@@ -1,15 +1,16 @@
1
1
  {
2
2
  "name": "@vite-hub/runtime",
3
- "version": "0.0.4",
3
+ "version": "0.3.0",
4
4
  "description": "Shared runtime context, capability, policy, approval, and tracing primitives for ViteHub.",
5
5
  "keywords": [
6
6
  "approvals",
7
7
  "capabilities",
8
8
  "policy",
9
9
  "runtime",
10
+ "typescript",
10
11
  "vitehub"
11
12
  ],
12
- "homepage": "https://github.com/vite-hub/vitehub#readme",
13
+ "homepage": "https://vitehub.dev",
13
14
  "bugs": "https://github.com/vite-hub/vitehub/issues",
14
15
  "license": "Apache-2.0",
15
16
  "author": "onmax <maximogarciamtnez@gmail.com>",
@@ -23,32 +24,106 @@
23
24
  "package.json"
24
25
  ],
25
26
  "type": "module",
26
- "sideEffects": [
27
- "./dist/drain.js"
28
- ],
29
- "bin": {
30
- "vitehub-drain": "./dist/drain.js"
31
- },
27
+ "sideEffects": false,
32
28
  "types": "./dist/index.d.ts",
33
29
  "exports": {
34
- ".": "./dist/index.js",
35
- "./node": "./dist/node.js",
30
+ ".": {
31
+ "types": "./dist/index.d.ts",
32
+ "import": "./dist/index.js",
33
+ "default": "./dist/index.js"
34
+ },
35
+ "./durability": {
36
+ "types": "./dist/durability.d.ts",
37
+ "import": "./dist/durability.js",
38
+ "default": "./dist/durability.js"
39
+ },
40
+ "./internal/drain": {
41
+ "types": "./dist/internal/drain.d.ts",
42
+ "import": "./dist/internal/drain.js",
43
+ "default": "./dist/internal/drain.js"
44
+ },
45
+ "./internal/execution-budget": {
46
+ "types": "./dist/internal/execution-budget.d.ts",
47
+ "import": "./dist/internal/execution-budget.js",
48
+ "default": "./dist/internal/execution-budget.js"
49
+ },
50
+ "./internal/grant": {
51
+ "types": "./dist/internal/grant.d.ts",
52
+ "import": "./dist/internal/grant.js",
53
+ "default": "./dist/internal/grant.js"
54
+ },
55
+ "./internal/h3": {
56
+ "types": "./dist/internal/h3.d.ts",
57
+ "import": "./dist/internal/h3.js",
58
+ "default": "./dist/internal/h3.js"
59
+ },
60
+ "./internal/node": {
61
+ "types": "./dist/internal/node.d.ts",
62
+ "import": "./dist/internal/node.js",
63
+ "default": "./dist/internal/node.js"
64
+ },
65
+ "./internal/public-url": {
66
+ "types": "./dist/internal/public-url.d.ts",
67
+ "import": "./dist/internal/public-url.js",
68
+ "default": "./dist/internal/public-url.js"
69
+ },
70
+ "./internal/run-scope": {
71
+ "types": "./dist/internal/run-scope.d.ts",
72
+ "import": "./dist/internal/run-scope.js",
73
+ "default": "./dist/internal/run-scope.js"
74
+ },
75
+ "./internal/runtime-type": {
76
+ "types": "./dist/internal/runtime-type.d.ts",
77
+ "import": "./dist/internal/runtime-type.js",
78
+ "default": "./dist/internal/runtime-type.js"
79
+ },
80
+ "./internal/shutdown": {
81
+ "types": "./dist/internal/shutdown.d.ts",
82
+ "import": "./dist/internal/shutdown.js",
83
+ "default": "./dist/internal/shutdown.js"
84
+ },
85
+ "./internal/test-mode": {
86
+ "types": "./dist/internal/test-mode.d.ts",
87
+ "import": "./dist/internal/test-mode.js",
88
+ "default": "./dist/internal/test-mode.js"
89
+ },
90
+ "./internal/test-mode-setup": {
91
+ "types": "./dist/internal/test-mode-setup.d.ts",
92
+ "import": "./dist/internal/test-mode-setup.js",
93
+ "default": "./dist/internal/test-mode-setup.js"
94
+ },
95
+ "./operations": {
96
+ "types": "./dist/operations.d.ts",
97
+ "import": "./dist/operations.js",
98
+ "default": "./dist/operations.js"
99
+ },
36
100
  "./package.json": "./package.json"
37
101
  },
102
+ "dependencies": {
103
+ "@standard-schema/spec": "^1.1.0",
104
+ "@valibot/to-json-schema": "^1.8.0",
105
+ "h3": "^2.0.8",
106
+ "nostics": "1.4.0",
107
+ "standard-context": "0.0.4",
108
+ "valibot": "^1.5.0"
109
+ },
38
110
  "devDependencies": {
39
- "@types/node": "^24.13.3",
40
- "publint": "^0.3.21",
111
+ "@libsql/client": "^0.18.0",
112
+ "@types/node": "^24.19.1",
113
+ "@vite-hub/internal": "0.0.1",
114
+ "postgres": "^3.4.9",
115
+ "publint": "^0.3.25",
41
116
  "typescript": "^6.0.3",
42
- "vite-plus": "^0.1.24",
43
- "vitest": "^4.1.4"
117
+ "vite-plus": "^0.3.3",
118
+ "vitest": "^4.1.11"
44
119
  },
45
120
  "engines": {
46
- "node": ">=24.0.0"
121
+ "node": ">=22.18.0"
47
122
  },
48
123
  "scripts": {
49
124
  "build": "vp pack",
50
125
  "dev": "vp pack --watch",
51
- "typecheck": "tsc --noEmit -p ./tsconfig.json",
52
- "test": "vp run -t @vite-hub/runtime#build && vp test"
126
+ "typecheck": "vp run --cache -t @vite-hub/runtime#build && node ../../test/package-typecheck.mjs --noEmit -p ./tsconfig.json",
127
+ "test": "vp run --cache -t @vite-hub/runtime#build && vp test"
53
128
  }
54
129
  }
package/dist/drain.d.ts DELETED
@@ -1 +0,0 @@
1
- export { };
package/dist/drain.js DELETED
@@ -1,52 +0,0 @@
1
- #!/usr/bin/env node
2
- import { t as hasRuntimeType } from "./runtime-type-ovvOd6m5.js";
3
- //#region src/drain.ts
4
- const pidInput = process.argv[2];
5
- const statusUrl = process.argv[3] || "http://127.0.0.1:3000/api/drain";
6
- const pid = Number(pidInput);
7
- if (pidInput === "-h" || pidInput === "--help") {
8
- console.log("Usage: vitehub-drain MAINPID [STATUS_URL]");
9
- process.exit(0);
10
- }
11
- if (!Number.isSafeInteger(pid) || pid <= 0) {
12
- console.error("usage: vitehub-drain MAINPID [STATUS_URL]");
13
- process.exit(2);
14
- }
15
- function running() {
16
- try {
17
- process.kill(pid, 0);
18
- return true;
19
- } catch {
20
- return false;
21
- }
22
- }
23
- async function readStatus() {
24
- try {
25
- const response = await fetch(statusUrl, { signal: AbortSignal.timeout(5e3) });
26
- if (!response.ok) return "unavailable";
27
- const body = await response.json();
28
- const status = body && hasRuntimeType(body, "object") ? body.status : void 0;
29
- return status === "accepting" || status === "drained" || status === "draining" || status === "failed" ? status : "invalid";
30
- } catch {
31
- return "unavailable";
32
- }
33
- }
34
- try {
35
- let signaled = false;
36
- while (running()) {
37
- const status = await readStatus();
38
- if (status === "failed" || status === "invalid") throw new Error(`Process drain reported ${status}.`);
39
- if (status === "drained") process.exit(0);
40
- if (status === "accepting" && !signaled) {
41
- process.kill(pid, "SIGUSR2");
42
- signaled = true;
43
- }
44
- await new Promise((resolve) => setTimeout(resolve, 1e3));
45
- }
46
- throw new Error(`Process ${pid} exited before drain completed.`);
47
- } catch (error) {
48
- console.error(error instanceof Error ? error.message : error);
49
- process.exit(1);
50
- }
51
- //#endregion
52
- export {};
@@ -1,314 +0,0 @@
1
- //#region src/diagnostics.d.ts
2
- type RuntimeDiagnosticLevel = "debug" | "error" | "info" | "warn";
3
- type RuntimeResourceScope = "container" | "host" | "process" | "service" | "workload";
4
- type RuntimeResourceUnit = "bytes" | "count" | "microseconds" | "ratio";
5
- interface RuntimeDiagnosticError {
6
- cause?: RuntimeDiagnosticError;
7
- code?: number | string;
8
- details?: Readonly<Record<string, unknown>>;
9
- errors?: readonly RuntimeDiagnosticError[];
10
- message: string;
11
- name?: string;
12
- requestId?: string;
13
- stack?: string;
14
- status?: number | string;
15
- statusCode?: number | string;
16
- }
17
- interface RuntimeDiagnosticEvent {
18
- attributes?: Readonly<Record<string, unknown>>;
19
- component: string;
20
- error?: RuntimeDiagnosticError;
21
- level: RuntimeDiagnosticLevel;
22
- name: string;
23
- timestamp: string;
24
- }
25
- type RuntimeDiagnosticReporter = (event: RuntimeDiagnosticEvent) => MaybePromise<void>;
26
- interface RuntimeResourceObservation {
27
- name: string;
28
- scope: RuntimeResourceScope;
29
- source: string;
30
- unit: RuntimeResourceUnit;
31
- value: number;
32
- }
33
- interface RuntimeResourceSupport {
34
- reason?: "collection-failed" | "not-isolated" | "permission-denied" | "unsupported-runtime" | (string & {});
35
- scope: RuntimeResourceScope;
36
- source: string;
37
- supported: boolean;
38
- }
39
- interface RuntimeResourceSnapshot {
40
- observedAt: string;
41
- observations: readonly RuntimeResourceObservation[];
42
- support?: readonly RuntimeResourceSupport[];
43
- }
44
- interface RuntimeResourceInspector {
45
- inspect(options?: {
46
- signal?: AbortSignal;
47
- }): MaybePromise<RuntimeResourceSnapshot>;
48
- }
49
- interface RuntimeDiagnosticErrorOptions {
50
- includeStack?: boolean;
51
- maxDepth?: number;
52
- maxErrors?: number;
53
- maxStringLength?: number;
54
- }
55
- declare function normalizeRuntimeDiagnosticError(error: unknown, options?: RuntimeDiagnosticErrorOptions): RuntimeDiagnosticError;
56
- //#endregion
57
- //#region src/errors.d.ts
58
- type ViteHubErrorDetail = boolean | null | number | string | readonly ViteHubErrorDetail[] | {
59
- readonly [key: string]: ViteHubErrorDetail | undefined;
60
- };
61
- type ViteHubErrorDetails = Readonly<Record<string, ViteHubErrorDetail | undefined>>;
62
- interface ViteHubErrorShape<TCode extends string = string, TDetails extends ViteHubErrorDetails = ViteHubErrorDetails> {
63
- code: TCode;
64
- details?: TDetails;
65
- message: string;
66
- name: "ViteHubError";
67
- requestId?: string;
68
- }
69
- interface ViteHubErrorOptions<TDetails extends ViteHubErrorDetails = ViteHubErrorDetails> extends ErrorOptions {
70
- details?: TDetails;
71
- requestId?: string;
72
- }
73
- declare class ViteHubError<TCode extends string = string, TDetails extends ViteHubErrorDetails = ViteHubErrorDetails> extends Error {
74
- readonly code: TCode;
75
- readonly details?: TDetails;
76
- readonly requestId?: string;
77
- constructor(code: TCode, message: string, options?: ViteHubErrorOptions<TDetails>);
78
- toJSON(): ViteHubErrorShape<TCode, TDetails>;
79
- }
80
- declare function getViteHubErrorShape(value: unknown): ViteHubErrorShape | undefined;
81
- declare function isViteHubError(value: unknown): value is ViteHubErrorShape;
82
- //#endregion
83
- //#region src/index.d.ts
84
- type MaybePromise<T> = T | Promise<T>;
85
- interface ExecutionAuthority {
86
- readonly credentials: "ambient" | "none" | "provisioned" | "unknown";
87
- readonly environment: "ambient" | "none" | "selected" | "unknown";
88
- readonly filesystem: {
89
- readonly access: "none" | "read-only" | "read-write" | "unknown";
90
- readonly scope: "host" | "none" | "sandbox" | "unknown" | "workspace";
91
- };
92
- readonly isolation: "container" | "microvm" | "none" | "process" | "unknown";
93
- readonly network: "none" | "restricted" | "unrestricted" | "unknown";
94
- readonly processes: "arbitrary" | "none" | "restricted" | "unknown";
95
- }
96
- declare const noExecutionAuthority: ExecutionAuthority;
97
- declare const unknownExecutionAuthority: ExecutionAuthority;
98
- declare function isExecutionAuthority(value: unknown): value is ExecutionAuthority;
99
- declare function normalizeExecutionAuthority(value: unknown): ExecutionAuthority;
100
- type RuntimeWaitUntil = (task: Promise<unknown>) => void;
101
- interface RuntimeWaitUntilController {
102
- flushWaitUntil(): Promise<void>;
103
- waitUntil: RuntimeWaitUntil;
104
- }
105
- interface TraceContext {
106
- id: string;
107
- parentId?: string;
108
- sampled?: boolean;
109
- }
110
- type TraceActivityOwner = "agent" | "vitehub";
111
- type TraceActivityPhase = "delivery" | "execution" | "setup" | "teardown";
112
- interface TraceActivityContext {
113
- owner: TraceActivityOwner;
114
- phase: TraceActivityPhase;
115
- }
116
- type TracePayloadVisibility = "private" | "public" | "redacted" | "summary";
117
- type TraceEventPayload = {
118
- value: unknown;
119
- visibility: "public";
120
- } | {
121
- summary: string;
122
- visibility: "summary";
123
- } | {
124
- visibility: "redacted";
125
- } | {
126
- visibility: "private";
127
- };
128
- type TraceEventContentPolicy = "content" | "metadata";
129
- type TraceRunStatus = "cancelled" | "completed" | "failed" | "running";
130
- type TraceStepStatus = "completed" | "failed" | "running";
131
- interface TraceEvent {
132
- activity?: TraceActivityContext;
133
- attributes?: Record<string, unknown>;
134
- name: string;
135
- payload?: TraceEventPayload;
136
- timestamp?: Date | string;
137
- trace?: TraceContext;
138
- type: "approval" | "capability" | "error" | "lifecycle" | "policy" | "run";
139
- }
140
- interface TraceEventLogEntry extends TraceEvent {
141
- sequence: number;
142
- timestamp: string;
143
- }
144
- interface TraceEventLog {
145
- append(event: TraceEvent): MaybePromise<TraceEventLogEntry>;
146
- entries(): readonly TraceEventLogEntry[];
147
- }
148
- interface TraceEventLogOptions {
149
- content?: TraceEventContentPolicy;
150
- onEntry?: (entry: TraceEventLogEntry) => MaybePromise<void>;
151
- }
152
- interface TraceStepView {
153
- attributes?: Record<string, unknown>;
154
- durationMs?: number;
155
- endTime?: string;
156
- events: TraceEventLogEntry[];
157
- id: string;
158
- name: string;
159
- startTime: string;
160
- status: TraceStepStatus;
161
- type: TraceEvent["type"];
162
- }
163
- interface TraceRunView {
164
- durationMs?: number;
165
- endTime?: string;
166
- events: TraceEventLogEntry[];
167
- id: string;
168
- startTime: string;
169
- status: TraceRunStatus;
170
- steps: TraceStepView[];
171
- }
172
- interface OpenTelemetrySpanView {
173
- attributes?: Record<string, unknown>;
174
- endTime?: string;
175
- events?: OpenTelemetrySpanEventView[];
176
- name: string;
177
- parentSpanId?: string;
178
- spanId: string;
179
- startTime: string;
180
- status: {
181
- code: "ERROR" | "OK" | "UNSET";
182
- message?: string;
183
- };
184
- traceId: string;
185
- }
186
- interface OpenTelemetrySpanEventView {
187
- attributes?: Record<string, unknown>;
188
- name: string;
189
- time: string;
190
- }
191
- interface OpenTelemetryLogRecordView {
192
- attributes?: Record<string, unknown>;
193
- eventName: string;
194
- severityNumber?: number;
195
- severityText?: string;
196
- spanId: string;
197
- time: string;
198
- traceId: string;
199
- }
200
- interface OpenTelemetrySpanViewOptions {
201
- content?: TraceEventContentPolicy;
202
- }
203
- interface RuntimeHostContext<TRuntimeConfig = Record<string, unknown>> {
204
- capabilities?: RuntimeCapabilities;
205
- cloudflare?: {
206
- context?: unknown;
207
- durableObjectStateName?: string;
208
- env?: Record<string, unknown>;
209
- };
210
- event?: unknown;
211
- memo<T>(key: string, create: () => T): T;
212
- platform?: string;
213
- request?: Request;
214
- runtime: string;
215
- runtimeConfig?: TRuntimeConfig;
216
- trace?: TraceContext;
217
- traceLog?: TraceEventLog;
218
- vercel?: {
219
- waitUntil?: RuntimeWaitUntil;
220
- };
221
- flushWaitUntil?: () => Promise<void>;
222
- waitUntil: RuntimeWaitUntil;
223
- }
224
- type ExecutionContext<TRuntimeConfig = Record<string, unknown>> = RuntimeHostContext<TRuntimeConfig> & {
225
- capabilities: RuntimeCapabilities;
226
- runtimeConfig: TRuntimeConfig;
227
- };
228
- interface CapabilityHandle<TKind extends string = string, TValue = unknown> {
229
- kind: TKind;
230
- name?: string;
231
- value: TValue;
232
- }
233
- type RuntimeCapabilityHandle<TKind extends string = string, TValue = unknown> = CapabilityHandle<TKind, TValue>;
234
- type RuntimeCapabilities = Record<string, CapabilityHandle | unknown>;
235
- interface CapabilityDefinition<TKind extends string = string, TValue = unknown> {
236
- handle: CapabilityHandle<TKind, TValue>;
237
- resolve(context: ExecutionContext): MaybePromise<CapabilityHandle<TKind, TValue>>;
238
- }
239
- interface Resolvable<T, TContext extends RuntimeHostContext<any> = RuntimeHostContext> {
240
- resolve(context: TContext): MaybePromise<T>;
241
- }
242
- type MaybeResolvable<T, TContext extends RuntimeHostContext<any> = RuntimeHostContext> = T | Resolvable<T, TContext> | ((context: TContext) => MaybePromise<T>);
243
- interface PolicyContext {
244
- capability?: string;
245
- input?: unknown;
246
- operation?: string;
247
- runtime?: string;
248
- subject?: unknown;
249
- trace?: TraceContext;
250
- }
251
- type PolicyDecision = "allow" | "deny" | "require-approval" | "retryable-failure";
252
- type CapabilityPolicy = PolicyDecision | ((context: PolicyContext) => MaybePromise<PolicyDecision>);
253
- type ApprovalState = "proposed" | "awaiting-approval" | "approved" | "denied" | "executing" | "completed" | "failed";
254
- interface ApprovalRequest<TInput = unknown> {
255
- id: string;
256
- capability?: string;
257
- input?: TInput;
258
- reason?: string;
259
- state: Extract<ApprovalState, "awaiting-approval" | "proposed">;
260
- trace?: TraceContext;
261
- }
262
- interface ApprovalDecision {
263
- approved: boolean;
264
- decidedAt?: Date | string;
265
- reason?: string;
266
- requestId: string;
267
- state: Extract<ApprovalState, "approved" | "denied">;
268
- }
269
- interface RunLifecycleHooks<TContext extends RuntimeHostContext<any> = RuntimeHostContext> {
270
- approval?: (request: ApprovalRequest, context: TContext) => MaybePromise<void>;
271
- error?: (error: unknown, context: TContext) => MaybePromise<void>;
272
- finish?: (context: TContext) => MaybePromise<void>;
273
- request?: (context: TContext) => MaybePromise<void>;
274
- trace?: (event: TraceEvent, context: TContext) => MaybePromise<void>;
275
- }
276
- declare function isTraceContentAttributeKey(key: string): boolean;
277
- declare function emitTraceEvent<TContext extends RuntimeHostContext<any>>(context: TContext, event: TraceEvent): Promise<TraceEventLogEntry | undefined>;
278
- declare function createTraceEventLog(options?: TraceEventLogOptions): TraceEventLog;
279
- declare function deriveTraceRuns(events: Iterable<TraceEventLogEntry>): TraceRunView[];
280
- declare function traceEventsToOpenTelemetryLogRecords(events: Iterable<TraceEventLogEntry>, options?: OpenTelemetrySpanViewOptions): OpenTelemetryLogRecordView[];
281
- declare function traceEventsToOpenTelemetrySpans(events: Iterable<TraceEventLogEntry>, options?: OpenTelemetrySpanViewOptions): OpenTelemetrySpanView[];
282
- interface Lease {
283
- expiresAt?: Date | string;
284
- id: string;
285
- key: string;
286
- release(): MaybePromise<void>;
287
- }
288
- interface LeaseStore {
289
- acquire(key: string, options?: {
290
- owner?: string;
291
- ttl?: number;
292
- }): MaybePromise<Lease>;
293
- }
294
- type NormalizedRuntimeConfig<TConfig> = Exclude<TConfig, null | undefined> extends Record<string, unknown> ? Record<string, unknown> : Exclude<TConfig, null | undefined> | Record<string, unknown>;
295
- 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>;
296
- type RuntimeCapabilitiesOf<TContext extends RuntimeHostContext<any>> = "capabilities" extends keyof TContext ? undefined extends TContext["capabilities"] ? RuntimeCapabilities : TContext["capabilities"] : RuntimeCapabilities;
297
- type CreatedExecutionContext<TContext extends RuntimeHostContext<any>> = TContext extends unknown ? Omit<TContext, "capabilities" | "runtimeConfig"> & {
298
- capabilities: RuntimeCapabilitiesOf<TContext>;
299
- runtimeConfig: RuntimeConfigOf<TContext>;
300
- } : never;
301
- declare function createExecutionContext<TContext extends RuntimeHostContext<any>>(context: TContext): CreatedExecutionContext<TContext>;
302
- declare function defineCapability<TKind extends string, TValue>(kind: TKind, value: TValue, options?: {
303
- name?: string;
304
- }): CapabilityHandle<TKind, TValue>;
305
- declare function createRuntimeWaitUntilController(options?: {
306
- forward?: RuntimeWaitUntil;
307
- }): RuntimeWaitUntilController;
308
- declare function hasCapability(context: RuntimeHostContext, name: string): boolean;
309
- declare function getCapability(context: RuntimeHostContext<any>, name: string): CapabilityHandle;
310
- declare function isResolvable<T, TContext extends RuntimeHostContext<any>>(value: MaybeResolvable<T, TContext>): value is Resolvable<T, TContext>;
311
- declare function resolveRuntimeValue<T, TContext extends RuntimeHostContext<any>>(value: MaybeResolvable<T, TContext>, context: TContext): Promise<T>;
312
- declare function resolveCapabilityPolicy(policy: CapabilityPolicy | undefined, context: PolicyContext): Promise<PolicyDecision>;
313
- //#endregion
314
- export { normalizeExecutionAuthority as $, TraceEvent as A, TraceStepView as B, RuntimeHostContext as C, normalizeRuntimeDiagnosticError as Ct, TraceActivityOwner as D, TraceActivityContext as E, TraceEventPayload as F, deriveTraceRuns as G, createRuntimeWaitUntilController as H, TracePayloadVisibility as I, hasCapability as J, emitTraceEvent as K, TraceRunStatus as L, TraceEventLog as M, TraceEventLogEntry as N, TraceActivityPhase as O, TraceEventLogOptions as P, noExecutionAuthority as Q, TraceRunView as R, RuntimeCapabilityHandle as S, RuntimeResourceUnit as St, RuntimeWaitUntilController as T, createTraceEventLog as U, createExecutionContext as V, defineCapability as W, isResolvable as X, isExecutionAuthority as Y, isTraceContentAttributeKey as Z, PolicyContext as _, RuntimeResourceInspector as _t, CapabilityHandle as a, ViteHubError as at, RunLifecycleHooks as b, RuntimeResourceSnapshot as bt, ExecutionContext as c, ViteHubErrorOptions as ct, MaybePromise as d, isViteHubError as dt, resolveCapabilityPolicy as et, MaybeResolvable as f, RuntimeDiagnosticError as ft, OpenTelemetrySpanViewOptions as g, RuntimeDiagnosticReporter as gt, OpenTelemetrySpanView as h, RuntimeDiagnosticLevel as ht, CapabilityDefinition as i, unknownExecutionAuthority as it, TraceEventContentPolicy as j, TraceContext as k, Lease as l, ViteHubErrorShape as lt, OpenTelemetrySpanEventView as m, RuntimeDiagnosticEvent as mt, ApprovalRequest as n, traceEventsToOpenTelemetryLogRecords as nt, CapabilityPolicy as o, ViteHubErrorDetail as ot, OpenTelemetryLogRecordView as p, RuntimeDiagnosticErrorOptions as pt, getCapability as q, ApprovalState as r, traceEventsToOpenTelemetrySpans as rt, ExecutionAuthority as s, ViteHubErrorDetails as st, ApprovalDecision as t, resolveRuntimeValue as tt, LeaseStore as u, getViteHubErrorShape as ut, PolicyDecision as v, RuntimeResourceObservation as vt, RuntimeWaitUntil as w, RuntimeCapabilities as x, RuntimeResourceSupport as xt, Resolvable as y, RuntimeResourceScope as yt, TraceStepStatus as z };
package/dist/node.d.ts DELETED
@@ -1,35 +0,0 @@
1
- import { _t as RuntimeResourceInspector } from "./index-tBKyUP1T.js";
2
-
3
- //#region src/node.d.ts
4
- type ReadText = (path: string, options?: {
5
- signal?: AbortSignal;
6
- }) => Promise<string>;
7
- interface NodeRuntimeResourceInspectorOptions {
8
- now?: () => Date;
9
- readText?: ReadText;
10
- }
11
- declare function resolveLinuxCgroupV2Path(mountinfo: string, membership: string): string | undefined;
12
- declare function nodeRuntimeResources(options?: NodeRuntimeResourceInspectorOptions): RuntimeResourceInspector;
13
- type ProcessReconcilerStatus = "accepting" | "drained" | "draining" | "failed";
14
- type ProcessReconcilerSignal = Exclude<NodeJS.Signals, "SIGKILL" | "SIGSTOP">;
15
- interface ProcessReconcilerRunContext {
16
- track<T>(work: Promise<T>): Promise<T>;
17
- }
18
- interface ProcessReconcilerOptions {
19
- intervalMs: number;
20
- onDrained?: () => Promise<void> | void;
21
- onError?: (error: unknown, reason: string) => Promise<void> | void;
22
- onQuiesce?: () => Promise<void> | void;
23
- repairReason?: string;
24
- run: (reason: string, context: ProcessReconcilerRunContext) => Promise<void> | void;
25
- signal?: false | ProcessReconcilerSignal;
26
- }
27
- interface ProcessReconciler extends ProcessReconcilerRunContext {
28
- close: () => Promise<void>;
29
- drain: () => Promise<void>;
30
- status: () => ProcessReconcilerStatus;
31
- wake: (reason: string) => void;
32
- }
33
- declare function createProcessReconciler(options: ProcessReconcilerOptions): ProcessReconciler;
34
- //#endregion
35
- export { NodeRuntimeResourceInspectorOptions, ProcessReconciler, ProcessReconcilerOptions, ProcessReconcilerRunContext, ProcessReconcilerSignal, ProcessReconcilerStatus, createProcessReconciler, nodeRuntimeResources, resolveLinuxCgroupV2Path };
@@ -1,37 +0,0 @@
1
- //#region src/internal/runtime-type.ts
2
- function isCallableRepresentation(value) {
3
- if (value === null || value === void 0 || Object(value) !== value) return false;
4
- try {
5
- Function.prototype.toString.call(value);
6
- return true;
7
- } catch {
8
- return false;
9
- }
10
- }
11
- /** Parses JavaScript runtime representation categories at Runtime boundaries. */
12
- function hasRuntimeType(value, expected) {
13
- if (expected === "undefined") return value === void 0;
14
- if (expected === "object" && value === null) return true;
15
- if (value === null || value === void 0) return false;
16
- const isPrimitive = Object(value) !== value;
17
- if (!isPrimitive) {
18
- if (expected === "function") return isCallableRepresentation(value);
19
- return expected === "object" && !isCallableRepresentation(value);
20
- }
21
- const tag = Object.prototype.toString.call(value);
22
- switch (expected) {
23
- case "bigint": return isPrimitive && tag === "[object BigInt]";
24
- case "boolean": return isPrimitive && tag === "[object Boolean]";
25
- case "function": return false;
26
- case "number": return isPrimitive && tag === "[object Number]";
27
- case "object": return false;
28
- case "string": return isPrimitive && tag === "[object String]";
29
- case "symbol": return isPrimitive && tag === "[object Symbol]";
30
- }
31
- throw new TypeError(`Unsupported runtime type: ${expected}`);
32
- }
33
- function isRuntimeObject(value) {
34
- return value !== null && Object(value) === value;
35
- }
36
- //#endregion
37
- export { isRuntimeObject as n, hasRuntimeType as t };