@vite-hub/runtime 0.4.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/core-BfUEli_0.d.ts +304 -0
  2. package/dist/core-DpLK9dQt.js +1105 -0
  3. package/dist/durability.d.ts +2 -2
  4. package/dist/durability.js +4 -1
  5. package/dist/hosted-console-ZfMo5MW4.d.ts +30 -0
  6. package/dist/index-DsisbCNa.d.ts +364 -0
  7. package/dist/index.d.ts +7 -5
  8. package/dist/index.js +5 -4
  9. package/dist/internal/console.d.ts +7 -0
  10. package/dist/internal/console.js +2 -0
  11. package/dist/internal/context.d.ts +2 -0
  12. package/dist/internal/context.js +2 -0
  13. package/dist/internal/error-diagnostics.d.ts +2 -0
  14. package/dist/internal/error-diagnostics.js +2 -0
  15. package/dist/internal/execution-budget.d.ts +3 -2
  16. package/dist/internal/execution-budget.js +226 -1
  17. package/dist/internal/grant.js +1 -1
  18. package/dist/internal/h3.d.ts +2 -2
  19. package/dist/internal/h3.js +1 -7
  20. package/dist/internal/node.d.ts +1 -1
  21. package/dist/internal/public-url.d.ts +2 -2
  22. package/dist/internal/public-url.js +2 -2
  23. package/dist/internal/response.d.ts +2 -0
  24. package/dist/internal/response.js +2 -0
  25. package/dist/internal/run-failed.js +0 -1
  26. package/dist/internal/runtime-type.js +1 -1
  27. package/dist/internal/shutdown.js +17 -19
  28. package/dist/internal/test-mode-setup.js +0 -4
  29. package/dist/internal/trace.d.ts +6 -0
  30. package/dist/internal/trace.js +2 -0
  31. package/dist/operations.d.ts +8 -2
  32. package/dist/operations.js +6 -2
  33. package/dist/{public-url-1WeOw54Z.d.ts → public-url-BCFhTiTM.d.ts} +6 -1
  34. package/dist/{public-url-ByAmAjbP.js → public-url-DizC8CFs.js} +25 -17
  35. package/dist/request-context-Dmsliqan.js +687 -0
  36. package/dist/response-Be5M4WIn.js +432 -0
  37. package/dist/response-iONbTI0E.d.ts +33 -0
  38. package/dist/{runtime-type-BftydMAf.js → runtime-type-CHYQYwDx.js} +0 -7
  39. package/package.json +26 -1
  40. package/dist/index-C1DoYfCf.d.ts +0 -733
  41. package/dist/request-context-uRQpodgl.js +0 -2433
@@ -0,0 +1,432 @@
1
+ import { t as runtimeErrorDiagnostics } from "./error-diagnostics-BM9W4pBg.js";
2
+ import { r as isRuntimeObject } from "./runtime-type-CHYQYwDx.js";
3
+ import { n as getViteHubErrorShape } from "./errors-BQ0ofIL4.js";
4
+ import { Diagnostic, formatDiagnostic } from "nostics";
5
+ //#region src/diagnostics.ts
6
+ /** Recognizes an `Error` from any realm, without reading its properties. */
7
+ function isNativeError(value) {
8
+ if (!isRuntimeObject(value)) return false;
9
+ try {
10
+ const nativeIsError = Reflect.get(Error, "isError");
11
+ return typeof nativeIsError === "function" ? nativeIsError(value) === true : value instanceof Error || !(Symbol.toStringTag in value) && Object.prototype.toString.call(value) === "[object Error]";
12
+ } catch {
13
+ return false;
14
+ }
15
+ }
16
+ /**
17
+ * Recognizes a live Nostics error across bundled copies. This does not make its fields safe for public responses.
18
+ * nostics' own check matches only its own copy (https://github.com/vercel-labs/nostics/pull/40).
19
+ */
20
+ function isRuntimeDiagnostic(error) {
21
+ if (!isNativeError(error)) return false;
22
+ try {
23
+ const message = Reflect.get(error, "message");
24
+ const code = Reflect.get(error, "code");
25
+ const name = Reflect.get(error, "name");
26
+ const why = Reflect.get(error, "why");
27
+ const fix = Reflect.get(error, "fix");
28
+ const docs = Reflect.get(error, "docs");
29
+ const sources = Reflect.get(error, "sources");
30
+ return typeof code === "string" && code.length > 0 && typeof name === "string" && typeof message === "string" && why === message && (fix === void 0 || typeof fix === "string") && (docs === void 0 || typeof docs === "string") && (sources === void 0 || Array.isArray(sources) && sources.every((source) => typeof source === "string")) && typeof Reflect.get(error, "toJSON") === "function";
31
+ } catch {
32
+ return false;
33
+ }
34
+ }
35
+ function boundedString(value, state) {
36
+ if (typeof value !== "string") return;
37
+ const maximum = Math.min(state.maxStringLength, state.remainingStringLength);
38
+ if (maximum <= 0) return;
39
+ if (value.length <= maximum) {
40
+ state.remainingStringLength -= value.length;
41
+ return value;
42
+ }
43
+ const suffix = `… [${value.length - maximum} chars omitted]`;
44
+ const bounded = maximum > suffix.length ? `${value.slice(0, maximum - suffix.length)}${suffix}` : value.slice(0, maximum);
45
+ state.remainingStringLength -= bounded.length;
46
+ return bounded;
47
+ }
48
+ function safeString(value) {
49
+ try {
50
+ return String(value);
51
+ } catch {
52
+ return "Unknown error";
53
+ }
54
+ }
55
+ function readProperty(value, key) {
56
+ if (!isRuntimeObject(value)) return void 0;
57
+ try {
58
+ return value[key];
59
+ } catch {
60
+ return;
61
+ }
62
+ }
63
+ function scalarProperty(value, key, state) {
64
+ const property = readProperty(value, key);
65
+ if (typeof property === "string") return boundedString(property, state);
66
+ return typeof property === "number" && Number.isFinite(property) ? property : void 0;
67
+ }
68
+ function errorChildren(value, maximum) {
69
+ try {
70
+ if (!Array.isArray(value)) return;
71
+ const length = Math.min(value.length, maximum);
72
+ return Array.from({ length }, (_item, index) => readProperty(value, index));
73
+ } catch {
74
+ return [];
75
+ }
76
+ }
77
+ function normalizeDetailValue(value, state, depth) {
78
+ if (state.remainingNodes <= 0) return;
79
+ state.remainingNodes -= 1;
80
+ if (value === null || typeof value === "boolean") return value;
81
+ if (typeof value === "number") return Number.isFinite(value) ? value : void 0;
82
+ if (typeof value === "string") return boundedString(value, state);
83
+ if (depth > state.maxDepth) return boundedString("[Detail depth exceeded]", state);
84
+ if (Array.isArray(value)) return value.flatMap((item) => {
85
+ const normalized = normalizeDetailValue(item, state, depth + 1);
86
+ return normalized === void 0 ? [] : [normalized];
87
+ });
88
+ if (!isRuntimeObject(value)) return;
89
+ const normalized = {};
90
+ let keys;
91
+ try {
92
+ keys = Object.keys(value);
93
+ } catch {
94
+ return normalized;
95
+ }
96
+ for (const key of keys) {
97
+ const normalizedKey = boundedString(key, state);
98
+ if (!normalizedKey) break;
99
+ const child = normalizeDetailValue(readProperty(value, key), state, depth + 1);
100
+ if (child !== void 0) normalized[normalizedKey] = child;
101
+ }
102
+ return normalized;
103
+ }
104
+ function normalizeDetails(details, state, depth) {
105
+ const normalized = normalizeDetailValue(details, state, depth);
106
+ if (!isRuntimeObject(normalized) || Array.isArray(normalized)) return;
107
+ return normalized;
108
+ }
109
+ function normalizeError(value, state, depth) {
110
+ if (state.remainingNodes <= 0) return;
111
+ state.remainingNodes -= 1;
112
+ if (typeof value === "string") return { message: boundedString(value, state) || "Error" };
113
+ if (!value || typeof value !== "object") return { message: boundedString(safeString(value), state) || "Error" };
114
+ if (state.ancestors.has(value)) return { message: boundedString("[Circular error cause]", state) || "Error" };
115
+ if (depth > state.maxDepth) return { message: boundedString("[Error cause depth exceeded]", state) || "Error" };
116
+ state.ancestors.add(value);
117
+ try {
118
+ const publicError = getViteHubErrorShape(value);
119
+ const why = readProperty(value, "why");
120
+ const message = boundedString(readProperty(value, "message"), state) || boundedString(why, state) || boundedString(safeString(value), state) || "Error";
121
+ const name = boundedString(readProperty(value, "name"), state) || boundedString(readProperty(readProperty(value, "constructor") || {}, "name"), state);
122
+ const result = {
123
+ message,
124
+ ...name ? { name } : {}
125
+ };
126
+ const code = publicError?.code ? boundedString(publicError.code, state) : scalarProperty(value, "code", state) ?? (typeof why === "string" ? boundedString(name, state) : void 0);
127
+ const fix = boundedString(readProperty(value, "fix"), state);
128
+ const docs = boundedString(readProperty(value, "docs"), state);
129
+ const requestId = publicError?.requestId ? boundedString(publicError.requestId, state) : boundedString(readProperty(value, "requestId"), state);
130
+ const status = scalarProperty(value, "status", state);
131
+ const statusCode = scalarProperty(value, "statusCode", state);
132
+ const stack = state.includeStack ? boundedString(readProperty(value, "stack"), state) : void 0;
133
+ if (code !== void 0) result.code = code;
134
+ if (fix) result.fix = fix;
135
+ if (docs) result.docs = docs;
136
+ if (requestId) result.requestId = requestId;
137
+ if (stack) result.stack = stack;
138
+ if (status !== void 0) result.status = status;
139
+ if (statusCode !== void 0) result.statusCode = statusCode;
140
+ const cause = readProperty(value, "cause");
141
+ const normalizedCause = cause === void 0 ? void 0 : normalizeError(cause, state, depth + 1);
142
+ if (normalizedCause) result.cause = normalizedCause;
143
+ const normalizedErrors = errorChildren(readProperty(value, "errors"), state.remainingNodes)?.flatMap((error) => {
144
+ const normalized = normalizeError(error, state, depth + 1);
145
+ return normalized ? [normalized] : [];
146
+ });
147
+ if (normalizedErrors?.length) result.errors = normalizedErrors;
148
+ const details = publicError?.details ? normalizeDetails(publicError.details, state, depth + 1) : void 0;
149
+ if (details) result.details = details;
150
+ const sources = errorChildren(readProperty(value, "sources"), state.remainingNodes)?.flatMap((source) => {
151
+ state.remainingNodes -= 1;
152
+ const normalized = boundedString(source, state);
153
+ return normalized ? [normalized] : [];
154
+ });
155
+ if (sources?.length) result.sources = sources;
156
+ return result;
157
+ } finally {
158
+ state.ancestors.delete(value);
159
+ }
160
+ }
161
+ /** Formats bounded developer diagnostics without exposing causes or stacks. */
162
+ function formatRuntimeDiagnosticError(error) {
163
+ const normalized = normalizeRuntimeDiagnosticError(error);
164
+ if (normalized.code === void 0 && !normalized.fix && !normalized.docs && !normalized.sources?.length) return normalized.message;
165
+ return formatDiagnostic(new Diagnostic({
166
+ code: normalized.code === void 0 ? normalized.name || "Error" : String(normalized.code),
167
+ docs: normalized.docs,
168
+ fix: normalized.fix,
169
+ sources: normalized.sources ? [...normalized.sources] : void 0,
170
+ why: normalized.message
171
+ }));
172
+ }
173
+ function normalizeRuntimeDiagnosticError(error, options = {}) {
174
+ const maxDepth = options.maxDepth ?? 4;
175
+ const maxErrors = options.maxErrors ?? 8;
176
+ const maxStringLength = options.maxStringLength ?? 4096;
177
+ if (!Number.isInteger(maxDepth) || maxDepth < 0) throw runtimeErrorDiagnostics.RUNTIME_R0001({ message: "[vitehub:runtime] Diagnostic error maxDepth must be a non-negative integer." });
178
+ if (!Number.isInteger(maxErrors) || maxErrors < 1) throw runtimeErrorDiagnostics.RUNTIME_R0002({ message: "[vitehub:runtime] Diagnostic error maxErrors must be a positive integer." });
179
+ if (!Number.isInteger(maxStringLength) || maxStringLength < 64) throw runtimeErrorDiagnostics.RUNTIME_R0003({ message: "[vitehub:runtime] Diagnostic error maxStringLength must be an integer of at least 64." });
180
+ return normalizeError(error, {
181
+ ancestors: /* @__PURE__ */ new Set(),
182
+ includeStack: options.includeStack === true,
183
+ maxDepth,
184
+ maxStringLength,
185
+ remainingNodes: maxErrors + 1,
186
+ remainingStringLength: maxStringLength * (maxErrors + 1)
187
+ }, 0);
188
+ }
189
+ //#endregion
190
+ //#region src/response.ts
191
+ function prototypeGetter(constructor, key) {
192
+ return Object.getOwnPropertyDescriptor(constructor.prototype, key)?.get;
193
+ }
194
+ function prototypeMethod(constructor, key) {
195
+ const value = Object.getOwnPropertyDescriptor(constructor.prototype, key)?.value;
196
+ return typeof value === "function" ? value : void 0;
197
+ }
198
+ const blobTypeGetter = /* @__PURE__ */ prototypeGetter(Blob, "type");
199
+ const blobStreamMethod = /* @__PURE__ */ prototypeMethod(Blob, "stream");
200
+ function streamBody(read) {
201
+ let reader;
202
+ const cleanup = async (reason, cancel = false) => {
203
+ const current = reader;
204
+ reader = void 0;
205
+ if (!current) return;
206
+ try {
207
+ if (cancel) await current.cancel(reason);
208
+ } finally {
209
+ current.releaseLock();
210
+ }
211
+ };
212
+ return new ReadableStream({
213
+ async pull(controller) {
214
+ reader ??= read().getReader();
215
+ try {
216
+ const chunk = await reader.read();
217
+ if (chunk.done) {
218
+ await cleanup();
219
+ controller.close();
220
+ } else controller.enqueue(chunk.value);
221
+ } catch (error) {
222
+ await cleanup(error, true);
223
+ throw error;
224
+ }
225
+ },
226
+ async cancel(reason) {
227
+ await cleanup(reason, true);
228
+ }
229
+ });
230
+ }
231
+ function getBlobMethods(value) {
232
+ if (value === null || typeof value !== "object" && typeof value !== "function") return void 0;
233
+ try {
234
+ if (typeof blobTypeGetter !== "function" || typeof blobStreamMethod !== "function") return void 0;
235
+ const type = String(Reflect.apply(blobTypeGetter, value, []));
236
+ const body = () => streamBody(() => Reflect.apply(blobStreamMethod, value, []));
237
+ return {
238
+ type,
239
+ body
240
+ };
241
+ } catch {
242
+ return;
243
+ }
244
+ }
245
+ const arrayBufferByteLengthGetter = /* @__PURE__ */ prototypeGetter(ArrayBuffer, "byteLength");
246
+ function isArrayBufferValue(value) {
247
+ if (!isRuntimeObject(value)) return false;
248
+ try {
249
+ if (typeof arrayBufferByteLengthGetter !== "function") return false;
250
+ arrayBufferByteLengthGetter.call(value);
251
+ return true;
252
+ } catch {
253
+ return false;
254
+ }
255
+ }
256
+ const jsonHeaders = { "content-type": "application/json; charset=utf-8" };
257
+ /**
258
+ * Normalize a primitive value into the native Web Response contract.
259
+ * An error answers with `{ code, why, fix }` and never with its `stack`, `cause`, or `data`:
260
+ * - A ResultError or other Nostics diagnostic answers its `status`, or 500, so a route can `return toResponse(error)`.
261
+ * - A `ViteHubError` answers 500 with its `code` and its message as `why`.
262
+ * - Any other `Error` answers 500 with `RUNTIME_HIDDEN_ERROR`, because its message can hold server details.
263
+ */
264
+ function toResponse(value) {
265
+ if (isResponse(value)) return value;
266
+ if (isNativeError(value)) return errorResponse(value);
267
+ if (value === void 0) return new Response(null, { status: 204 });
268
+ if (typeof value === "string" || value instanceof Blob || isArrayBufferValue(value) || ArrayBuffer.isView(value)) return new Response(value);
269
+ const blobMethods = getBlobMethods(value);
270
+ if (blobMethods) return new Response(blobMethods.body(), blobMethods.type ? { headers: { "content-type": blobMethods.type } } : void 0);
271
+ return new Response(JSON.stringify(value), { headers: jsonHeaders });
272
+ }
273
+ function errorResponse(error) {
274
+ let body;
275
+ let status;
276
+ if (isRuntimeDiagnostic(error)) try {
277
+ body = {
278
+ code: error.code,
279
+ why: error.why,
280
+ fix: error.fix
281
+ };
282
+ status = Reflect.get(error, "status");
283
+ } catch {
284
+ body = void 0;
285
+ }
286
+ else {
287
+ const shape = getViteHubErrorShape(error);
288
+ if (shape) body = {
289
+ code: shape.code,
290
+ why: shape.message,
291
+ fix: void 0
292
+ };
293
+ }
294
+ if (!body || typeof body.code !== "string" || typeof body.why !== "string" || body.fix !== void 0 && typeof body.fix !== "string") {
295
+ const hidden = runtimeErrorDiagnostics.RUNTIME_HIDDEN_ERROR();
296
+ body = {
297
+ code: hidden.code,
298
+ why: hidden.why,
299
+ fix: hidden.fix
300
+ };
301
+ status = 500;
302
+ }
303
+ return new Response(JSON.stringify(body), {
304
+ headers: jsonHeaders,
305
+ status: typeof status === "number" && Number.isInteger(status) && status >= 400 && status <= 599 ? status : 500
306
+ });
307
+ }
308
+ /** Recognize Responses created by another realm from their standard tag and surface. */
309
+ function isResponse(value) {
310
+ if (value instanceof Response) return true;
311
+ if (!isRuntimeObject(value)) return false;
312
+ try {
313
+ if (Object.prototype.toString.call(value) !== "[object Response]") return false;
314
+ const headers = Object.getOwnPropertyDescriptor(Response.prototype, "headers")?.get?.call(value);
315
+ if (!headers) return false;
316
+ Array.from(Headers.prototype.entries.call(headers));
317
+ return true;
318
+ } catch {
319
+ return false;
320
+ }
321
+ }
322
+ /** Convert a native Response into a JSON-safe record. The body is fully buffered. */
323
+ async function serializeResponse(response) {
324
+ const isNull = response.body === null;
325
+ return {
326
+ body: {
327
+ data: bytesToBase64(new Uint8Array(await response.arrayBuffer())),
328
+ isNull,
329
+ encoding: "base64",
330
+ mediaType: response.headers.get("content-type") || "application/octet-stream"
331
+ },
332
+ headers: Array.from(response.headers, ([name, value]) => [name, value]),
333
+ status: response.status,
334
+ statusText: response.statusText,
335
+ ...response.type === "opaqueredirect" ? { url: response.url } : {},
336
+ ...response.type === "error" || response.type === "opaque" || response.type === "opaqueredirect" ? { type: response.type } : {}
337
+ };
338
+ }
339
+ /** Reconstruct a native Response from a durable response record. */
340
+ function deserializeResponse(value) {
341
+ if (!isSerializedResponse(value)) throw runtimeErrorDiagnostics.RUNTIME_SERIALIZED_RESPONSE_INVALID();
342
+ if (value.type !== void 0) return createStatusZeroResponse(value.type, value.url);
343
+ const bytes = base64ToBytes(value.body.data);
344
+ const body = value.body.isNull === true || [
345
+ 204,
346
+ 205,
347
+ 304
348
+ ].includes(value.status) && bytes.length === 0 ? null : bytes;
349
+ return new Response(body, {
350
+ headers: value.headers.map(([name, headerValue]) => [name, headerValue]),
351
+ status: value.status,
352
+ statusText: value.statusText
353
+ });
354
+ }
355
+ function isSerializedResponse(value) {
356
+ if (!isRuntimeObject(value)) return false;
357
+ const record = value;
358
+ if (!isRuntimeObject(record.body)) return false;
359
+ const body = record.body;
360
+ if (typeof body.data !== "string" || body.encoding !== "base64" || typeof body.mediaType !== "string") return false;
361
+ if (body.isNull !== void 0 && typeof body.isNull !== "boolean") return false;
362
+ if (body.isNull === true && body.data !== "") return false;
363
+ if (record.url !== void 0 && typeof record.url !== "string") return false;
364
+ if (record.type !== void 0 && record.type !== "error" && record.type !== "opaque" && record.type !== "opaqueredirect") return false;
365
+ if (record.type !== void 0) {
366
+ if (record.type !== "opaqueredirect" && record.url !== void 0) return false;
367
+ return record.status === 0 && record.statusText === "" && Array.isArray(record.headers) && record.headers.length === 0 && body.isNull === true && body.data === "";
368
+ }
369
+ if (record.url !== void 0) return false;
370
+ if (typeof record.status !== "number" || !Number.isInteger(record.status) || record.status < 200 || record.status > 599) return false;
371
+ if (typeof record.statusText !== "string" || !isSerializedHeaderEntries(record.headers)) return false;
372
+ if ([
373
+ 204,
374
+ 205,
375
+ 304
376
+ ].includes(record.status) && (/[^\t\n\f\r ]/.test(body.data) || body.isNull === false)) return false;
377
+ const headers = record.headers;
378
+ if (!isBase64(body.data)) return false;
379
+ try {
380
+ new Response(null, {
381
+ headers: headers.map(([name, headerValue]) => [name, headerValue]),
382
+ status: record.status,
383
+ statusText: record.statusText
384
+ });
385
+ } catch {
386
+ return false;
387
+ }
388
+ return true;
389
+ }
390
+ function isSerializedHeaderEntry(value) {
391
+ return Array.isArray(value) && value.length === 2 && typeof value[0] === "string" && typeof value[1] === "string";
392
+ }
393
+ function isSerializedHeaderEntries(value) {
394
+ if (!Array.isArray(value)) return false;
395
+ for (let index = 0; index < value.length; index++) if (!isSerializedHeaderEntry(value[index])) return false;
396
+ return true;
397
+ }
398
+ function isBase64(value) {
399
+ const compact = value.replace(/[\t\n\f\r ]/g, "");
400
+ const unpadded = compact.length % 4 === 0 ? compact.replace(/={1,2}$/, "") : compact;
401
+ return unpadded.length % 4 !== 1 && !/[^A-Za-z0-9+/]/.test(unpadded);
402
+ }
403
+ function bytesToBase64(bytes) {
404
+ if (typeof Buffer !== "undefined") return Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString("base64");
405
+ let binary = "";
406
+ for (let offset = 0; offset < bytes.length; offset += 32768) binary += String.fromCharCode(...bytes.subarray(offset, offset + 32768));
407
+ return btoa(binary);
408
+ }
409
+ function base64ToBytes(value) {
410
+ if (typeof Buffer !== "undefined") return Buffer.from(value, "base64");
411
+ const binary = atob(value);
412
+ const bytes = new Uint8Array(binary.length);
413
+ for (let index = 0; index < binary.length; index += 1) bytes[index] = binary.charCodeAt(index);
414
+ return bytes;
415
+ }
416
+ function createStatusZeroResponse(type, url = "") {
417
+ const response = Response.error();
418
+ if (type !== "error") Object.defineProperties(response, {
419
+ type: {
420
+ value: type,
421
+ enumerable: true
422
+ },
423
+ url: {
424
+ value: type === "opaqueredirect" ? url : "",
425
+ enumerable: true
426
+ },
427
+ clone: { value: () => createStatusZeroResponse(type, url) }
428
+ });
429
+ return response;
430
+ }
431
+ //#endregion
432
+ export { toResponse as a, normalizeRuntimeDiagnosticError as c, serializeResponse as i, isResponse as n, formatRuntimeDiagnosticError as o, isSerializedResponse as r, isRuntimeDiagnostic as s, deserializeResponse as t };
@@ -0,0 +1,33 @@
1
+ //#region src/response.d.ts
2
+ /** A JSON-safe representation of a web Response for durable boundaries. */
3
+ interface SerializedResponse {
4
+ readonly body: {
5
+ readonly data: string;
6
+ readonly encoding: "base64";
7
+ readonly mediaType: string;
8
+ readonly isNull?: boolean;
9
+ };
10
+ /** Header entries are kept as pairs so repeated headers are preserved. */
11
+ readonly headers: readonly (readonly [string, string])[];
12
+ readonly status: number;
13
+ readonly statusText: string;
14
+ readonly url?: string;
15
+ readonly type?: "error" | "opaque" | "opaqueredirect";
16
+ }
17
+ /**
18
+ * Normalize a primitive value into the native Web Response contract.
19
+ * An error answers with `{ code, why, fix }` and never with its `stack`, `cause`, or `data`:
20
+ * - A ResultError or other Nostics diagnostic answers its `status`, or 500, so a route can `return toResponse(error)`.
21
+ * - A `ViteHubError` answers 500 with its `code` and its message as `why`.
22
+ * - Any other `Error` answers 500 with `RUNTIME_HIDDEN_ERROR`, because its message can hold server details.
23
+ */
24
+ declare function toResponse(value: unknown): Response;
25
+ /** Recognize Responses created by another realm from their standard tag and surface. */
26
+ declare function isResponse(value: unknown): value is Response;
27
+ /** Convert a native Response into a JSON-safe record. The body is fully buffered. */
28
+ declare function serializeResponse(response: Response): Promise<SerializedResponse>;
29
+ /** Reconstruct a native Response from a durable response record. */
30
+ declare function deserializeResponse(value: SerializedResponse): Response;
31
+ declare function isSerializedResponse(value: unknown): value is SerializedResponse;
32
+ //#endregion
33
+ export { serializeResponse as a, isSerializedResponse as i, deserializeResponse as n, toResponse as o, isResponse as r, SerializedResponse as t };
@@ -40,12 +40,10 @@ function asUnknownBoundary(value) {
40
40
  function isRuntimeObject(value) {
41
41
  return value !== null && Object(value) === value;
42
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
43
  function isPlainRecord(value) {
45
44
  const prototype = Object.getPrototypeOf(value);
46
45
  return prototype === Object.prototype || prototype === null;
47
46
  }
48
- /** The native Response class and its `status` getter, and the proxy check of Node.js. Read once, at import. */
49
47
  function captureResponseChecks() {
50
48
  const response = globalThis.Response;
51
49
  return {
@@ -55,11 +53,6 @@ function captureResponseChecks() {
55
53
  };
56
54
  }
57
55
  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
56
  function replacedResponseStatus() {
64
57
  const current = globalThis.Response;
65
58
  if (typeof current !== "function" || current === nativeResponseChecks.response) return void 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vite-hub/runtime",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
4
4
  "description": "Shared runtime context, capability, policy, approval, and tracing primitives for ViteHub.",
5
5
  "keywords": [
6
6
  "approvals",
@@ -37,11 +37,26 @@
37
37
  "import": "./dist/durability.js",
38
38
  "default": "./dist/durability.js"
39
39
  },
40
+ "./internal/console": {
41
+ "types": "./dist/internal/console.d.ts",
42
+ "import": "./dist/internal/console.js",
43
+ "default": "./dist/internal/console.js"
44
+ },
45
+ "./internal/context": {
46
+ "types": "./dist/internal/context.d.ts",
47
+ "import": "./dist/internal/context.js",
48
+ "default": "./dist/internal/context.js"
49
+ },
40
50
  "./internal/drain": {
41
51
  "types": "./dist/internal/drain.d.ts",
42
52
  "import": "./dist/internal/drain.js",
43
53
  "default": "./dist/internal/drain.js"
44
54
  },
55
+ "./internal/error-diagnostics": {
56
+ "types": "./dist/internal/error-diagnostics.d.ts",
57
+ "import": "./dist/internal/error-diagnostics.js",
58
+ "default": "./dist/internal/error-diagnostics.js"
59
+ },
45
60
  "./internal/execution-budget": {
46
61
  "types": "./dist/internal/execution-budget.d.ts",
47
62
  "import": "./dist/internal/execution-budget.js",
@@ -67,6 +82,11 @@
67
82
  "import": "./dist/internal/public-url.js",
68
83
  "default": "./dist/internal/public-url.js"
69
84
  },
85
+ "./internal/response": {
86
+ "types": "./dist/internal/response.d.ts",
87
+ "import": "./dist/internal/response.js",
88
+ "default": "./dist/internal/response.js"
89
+ },
70
90
  "./internal/run-failed": {
71
91
  "types": "./dist/internal/run-failed.d.ts",
72
92
  "import": "./dist/internal/run-failed.js",
@@ -97,6 +117,11 @@
97
117
  "import": "./dist/internal/test-mode-setup.js",
98
118
  "default": "./dist/internal/test-mode-setup.js"
99
119
  },
120
+ "./internal/trace": {
121
+ "types": "./dist/internal/trace.d.ts",
122
+ "import": "./dist/internal/trace.js",
123
+ "default": "./dist/internal/trace.js"
124
+ },
100
125
  "./operations": {
101
126
  "types": "./dist/operations.d.ts",
102
127
  "import": "./dist/operations.js",