@veryfront/ext-content-mdx 0.1.1186 → 0.1.1189

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 (163) hide show
  1. package/esm/_dnt.polyfills.d.ts +6 -6
  2. package/esm/_dnt.polyfills.d.ts.map +1 -1
  3. package/esm/deno.d.ts +18 -0
  4. package/esm/deno.js +30 -9
  5. package/esm/src/config/defaults.d.ts +31 -24
  6. package/esm/src/config/defaults.d.ts.map +1 -1
  7. package/esm/src/config/defaults.js +25 -18
  8. package/esm/src/errors/diagnostic-policy.d.ts +35 -0
  9. package/esm/src/errors/diagnostic-policy.d.ts.map +1 -0
  10. package/esm/src/errors/diagnostic-policy.js +100 -0
  11. package/esm/src/errors/error-registry/boundary.d.ts +2 -0
  12. package/esm/src/errors/error-registry/boundary.d.ts.map +1 -1
  13. package/esm/src/errors/error-registry/boundary.js +8 -0
  14. package/esm/src/errors/error-registry/config.d.ts.map +1 -1
  15. package/esm/src/errors/error-registry/config.js +3 -3
  16. package/esm/src/errors/error-registry/deploy.js +1 -1
  17. package/esm/src/errors/error-registry/server.d.ts +2 -0
  18. package/esm/src/errors/error-registry/server.d.ts.map +1 -1
  19. package/esm/src/errors/error-registry/server.js +8 -0
  20. package/esm/src/errors/error-registry-helpers.d.ts +11 -2
  21. package/esm/src/errors/error-registry-helpers.d.ts.map +1 -1
  22. package/esm/src/errors/error-registry-helpers.js +70 -1
  23. package/esm/src/errors/error-registry.d.ts +85 -73
  24. package/esm/src/errors/error-registry.d.ts.map +1 -1
  25. package/esm/src/errors/error-registry.js +2 -14
  26. package/esm/src/errors/types.d.ts +44 -5
  27. package/esm/src/errors/types.d.ts.map +1 -1
  28. package/esm/src/errors/types.js +148 -24
  29. package/esm/src/errors/veryfront-error.d.ts +25 -2
  30. package/esm/src/errors/veryfront-error.d.ts.map +1 -1
  31. package/esm/src/errors/veryfront-error.js +638 -28
  32. package/esm/src/observability/limits.d.ts +20 -0
  33. package/esm/src/observability/limits.d.ts.map +1 -0
  34. package/esm/src/observability/limits.js +19 -0
  35. package/esm/src/observability/telemetry-error.d.ts +22 -0
  36. package/esm/src/observability/telemetry-error.d.ts.map +1 -0
  37. package/esm/src/observability/telemetry-error.js +377 -0
  38. package/esm/src/observability/tracing/api-shim.d.ts +39 -0
  39. package/esm/src/observability/tracing/api-shim.d.ts.map +1 -1
  40. package/esm/src/observability/tracing/api-shim.js +196 -69
  41. package/esm/src/observability/tracing/context-callback.d.ts +14 -0
  42. package/esm/src/observability/tracing/context-callback.d.ts.map +1 -0
  43. package/esm/src/observability/tracing/context-callback.js +111 -0
  44. package/esm/src/observability/tracing/otlp-setup.d.ts.map +1 -1
  45. package/esm/src/observability/tracing/otlp-setup.js +190 -46
  46. package/esm/src/platform/adapters/base.d.ts +51 -7
  47. package/esm/src/platform/adapters/base.d.ts.map +1 -1
  48. package/esm/src/platform/adapters/base.js +4 -2
  49. package/esm/src/platform/adapters/bounded-file-read.d.ts +9 -0
  50. package/esm/src/platform/adapters/bounded-file-read.d.ts.map +1 -1
  51. package/esm/src/platform/adapters/bounded-file-read.js +11 -5
  52. package/esm/src/platform/adapters/file-snapshot-error.d.ts +2 -0
  53. package/esm/src/platform/adapters/file-snapshot-error.d.ts.map +1 -1
  54. package/esm/src/platform/adapters/file-snapshot-error.js +2 -0
  55. package/esm/src/platform/adapters/file-system-capabilities.d.ts +74 -0
  56. package/esm/src/platform/adapters/file-system-capabilities.d.ts.map +1 -0
  57. package/esm/src/platform/adapters/file-system-capabilities.js +508 -0
  58. package/esm/src/platform/adapters/native-file-system-provenance.d.ts +6 -0
  59. package/esm/src/platform/adapters/native-file-system-provenance.d.ts.map +1 -0
  60. package/esm/src/platform/adapters/native-file-system-provenance.js +15 -0
  61. package/esm/src/platform/adapters/runtime/deno/filesystem-adapter.d.ts +45 -0
  62. package/esm/src/platform/adapters/runtime/deno/filesystem-adapter.d.ts.map +1 -0
  63. package/esm/src/platform/adapters/runtime/deno/filesystem-adapter.js +291 -0
  64. package/esm/src/platform/adapters/runtime/shared/node-filesystem-adapter.d.ts +71 -0
  65. package/esm/src/platform/adapters/runtime/shared/node-filesystem-adapter.d.ts.map +1 -0
  66. package/esm/src/platform/adapters/runtime/shared/node-filesystem-adapter.js +471 -0
  67. package/esm/src/platform/adapters/runtime/shared/shared-watcher.d.ts +16 -0
  68. package/esm/src/platform/adapters/runtime/shared/shared-watcher.d.ts.map +1 -0
  69. package/esm/src/platform/adapters/runtime/shared/shared-watcher.js +140 -0
  70. package/esm/src/platform/adapters/runtime/shared/temp-dir.d.ts +2 -0
  71. package/esm/src/platform/adapters/runtime/shared/temp-dir.d.ts.map +1 -0
  72. package/esm/src/platform/adapters/runtime/shared/temp-dir.js +10 -0
  73. package/esm/src/platform/adapters/runtime/shared/watcher-queue.d.ts +5 -0
  74. package/esm/src/platform/adapters/runtime/shared/watcher-queue.d.ts.map +1 -0
  75. package/esm/src/platform/adapters/runtime/shared/watcher-queue.js +75 -0
  76. package/esm/src/platform/compat/abort-signal.d.ts +20 -0
  77. package/esm/src/platform/compat/abort-signal.d.ts.map +1 -0
  78. package/esm/src/platform/compat/abort-signal.js +64 -0
  79. package/esm/src/platform/compat/constants.d.ts +2 -2
  80. package/esm/src/platform/compat/constants.d.ts.map +1 -1
  81. package/esm/src/platform/compat/constants.js +2 -2
  82. package/esm/src/platform/compat/error-introspection.d.ts +37 -0
  83. package/esm/src/platform/compat/error-introspection.d.ts.map +1 -0
  84. package/esm/src/platform/compat/error-introspection.js +258 -0
  85. package/esm/src/platform/compat/fs.d.ts +29 -8
  86. package/esm/src/platform/compat/fs.d.ts.map +1 -1
  87. package/esm/src/platform/compat/fs.js +123 -57
  88. package/esm/src/platform/compat/native-brand-checks.d.ts +14 -0
  89. package/esm/src/platform/compat/native-brand-checks.d.ts.map +1 -0
  90. package/esm/src/platform/compat/native-brand-checks.js +68 -0
  91. package/esm/src/platform/compat/not-found-error.d.ts +8 -3
  92. package/esm/src/platform/compat/not-found-error.d.ts.map +1 -1
  93. package/esm/src/platform/compat/not-found-error.js +164 -31
  94. package/esm/src/platform/compat/path/security.d.ts.map +1 -1
  95. package/esm/src/platform/compat/path/security.js +3 -5
  96. package/esm/src/platform/compat/process/command.d.ts +24 -1
  97. package/esm/src/platform/compat/process/command.d.ts.map +1 -1
  98. package/esm/src/platform/compat/process/command.js +393 -78
  99. package/esm/src/platform/compat/process/env.d.ts +11 -0
  100. package/esm/src/platform/compat/process/env.d.ts.map +1 -1
  101. package/esm/src/platform/compat/process/env.js +28 -38
  102. package/esm/src/platform/compat/process/global-error.d.ts +19 -0
  103. package/esm/src/platform/compat/process/global-error.d.ts.map +1 -0
  104. package/esm/src/platform/compat/process/global-error.js +57 -0
  105. package/esm/src/platform/compat/process/lifecycle.d.ts +10 -3
  106. package/esm/src/platform/compat/process/lifecycle.d.ts.map +1 -1
  107. package/esm/src/platform/compat/process/lifecycle.js +74 -23
  108. package/esm/src/platform/compat/process/project-env-contract.d.ts +19 -0
  109. package/esm/src/platform/compat/process/project-env-contract.d.ts.map +1 -0
  110. package/esm/src/platform/compat/process/project-env-contract.js +19 -0
  111. package/esm/src/platform/compat/runtime.d.ts +14 -5
  112. package/esm/src/platform/compat/runtime.d.ts.map +1 -1
  113. package/esm/src/platform/compat/runtime.js +34 -9
  114. package/esm/src/platform/compat/std/front-matter-yaml.d.ts +12 -0
  115. package/esm/src/platform/compat/std/front-matter-yaml.d.ts.map +1 -1
  116. package/esm/src/platform/compat/std/front-matter-yaml.js +35 -3
  117. package/esm/src/platform/compat/temp-directory-prefix.d.ts +8 -0
  118. package/esm/src/platform/compat/temp-directory-prefix.d.ts.map +1 -0
  119. package/esm/src/platform/compat/temp-directory-prefix.js +15 -0
  120. package/esm/src/utils/abort.d.ts +10 -0
  121. package/esm/src/utils/abort.d.ts.map +1 -0
  122. package/esm/src/utils/abort.js +35 -0
  123. package/esm/src/utils/constants/build.d.ts +3 -0
  124. package/esm/src/utils/constants/build.d.ts.map +1 -1
  125. package/esm/src/utils/constants/build.js +5 -1
  126. package/esm/src/utils/constants/cache.d.ts +21 -0
  127. package/esm/src/utils/constants/cache.d.ts.map +1 -1
  128. package/esm/src/utils/constants/cache.js +101 -39
  129. package/esm/src/utils/constants/css.d.ts +20 -0
  130. package/esm/src/utils/constants/css.d.ts.map +1 -0
  131. package/esm/src/utils/constants/css.js +19 -0
  132. package/esm/src/utils/constants/limits.d.ts +4 -0
  133. package/esm/src/utils/constants/limits.d.ts.map +1 -1
  134. package/esm/src/utils/constants/limits.js +4 -0
  135. package/esm/src/utils/constants/project-identity.d.ts +5 -0
  136. package/esm/src/utils/constants/project-identity.d.ts.map +1 -0
  137. package/esm/src/utils/constants/project-identity.js +4 -0
  138. package/esm/src/utils/constants/retry.d.ts +18 -0
  139. package/esm/src/utils/constants/retry.d.ts.map +1 -1
  140. package/esm/src/utils/constants/retry.js +18 -0
  141. package/esm/src/utils/constants/security.d.ts +4 -0
  142. package/esm/src/utils/constants/security.d.ts.map +1 -1
  143. package/esm/src/utils/constants/security.js +4 -0
  144. package/esm/src/utils/index.d.ts +3 -1
  145. package/esm/src/utils/index.d.ts.map +1 -1
  146. package/esm/src/utils/index.js +3 -1
  147. package/esm/src/utils/logger/core.d.ts +5 -0
  148. package/esm/src/utils/logger/core.d.ts.map +1 -1
  149. package/esm/src/utils/logger/core.js +67 -2
  150. package/esm/src/utils/logger/redact.d.ts +36 -13
  151. package/esm/src/utils/logger/redact.d.ts.map +1 -1
  152. package/esm/src/utils/logger/redact.js +573 -83
  153. package/esm/src/utils/parallel.d.ts.map +1 -1
  154. package/esm/src/utils/parallel.js +11 -1
  155. package/esm/src/utils/project-identity.d.ts +11 -0
  156. package/esm/src/utils/project-identity.d.ts.map +1 -0
  157. package/esm/src/utils/project-identity.js +69 -0
  158. package/esm/src/utils/version-constant.d.ts +1 -1
  159. package/esm/src/utils/version-constant.js +1 -1
  160. package/package.json +3 -3
  161. package/esm/src/platform/adapters/runtime/shared/native-file-capabilities.d.ts +0 -33
  162. package/esm/src/platform/adapters/runtime/shared/native-file-capabilities.d.ts.map +0 -1
  163. package/esm/src/platform/adapters/runtime/shared/native-file-capabilities.js +0 -205
@@ -1,3 +1,20 @@
1
+ import { isVeryfrontErrorInstance, snapshotKnownVeryfrontError, VeryfrontError, } from "./types.js";
2
+ const apply = Reflect.apply;
3
+ const arrayIsArray = Array.isArray;
4
+ const createObject = Object.create;
5
+ const defineProperty = Object.defineProperty;
6
+ const getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
7
+ const getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors;
8
+ const getPrototypeOf = Object.getPrototypeOf;
9
+ const hasOwn = Object.hasOwn;
10
+ const objectEntries = Object.entries;
11
+ const objectPrototype = Object.prototype;
12
+ const numberIsFinite = Number.isFinite;
13
+ const NativeArray = Array;
14
+ const NativeError = Error;
15
+ const NativeSet = Set;
16
+ const NativeString = String;
17
+ const captureStackTrace = Error.captureStackTrace;
1
18
  export function createError(error) {
2
19
  return error;
3
20
  }
@@ -11,51 +28,644 @@ export const isRenderError = isErrorType("render");
11
28
  export const isConfigError = isErrorType("config");
12
29
  export const isFileError = isErrorType("file");
13
30
  export const isNetworkError = isErrorType("network");
14
- /**
15
- * Convert a VeryfrontErrorData (plain object) to a throwable Error instance.
16
- *
17
- * Uses Error.captureStackTrace when available (V8 engines) to exclude toError()
18
- * from the stack trace, making the stack point to the actual call site.
19
- *
20
- * @see plans/architecture-audit/010.3-dual-veryfront-error-definitions.md
21
- */
22
- export function toError(veryfrontError) {
23
- const error = new Error(veryfrontError.message);
31
+ const SNAPSHOT_FAILED = Symbol("snapshot-failed");
32
+ const INVALID_ERROR_DATA = Symbol("invalid-error-data");
33
+ const MAX_SNAPSHOT_DEPTH = 16;
34
+ const MAX_SNAPSHOT_ENTRIES = 10_000;
35
+ const standardIsError = getOwnPropertyDescriptor(NativeError, "isError")?.value;
36
+ function hasNativeErrorBrand(error) {
37
+ if (typeof standardIsError === "function") {
38
+ try {
39
+ return apply(standardIsError, NativeError, [error]);
40
+ }
41
+ catch {
42
+ return false;
43
+ }
44
+ }
45
+ // Compatibility path for engines predating Error.isError. Modern runtimes
46
+ // use the hook-free brand check above.
47
+ try {
48
+ return error instanceof NativeError;
49
+ }
50
+ catch {
51
+ return false;
52
+ }
53
+ }
54
+ function snapshotPlainValue(value, depth, state) {
55
+ if (value === null ||
56
+ value === undefined ||
57
+ typeof value === "string" ||
58
+ typeof value === "number" ||
59
+ typeof value === "boolean" ||
60
+ typeof value === "bigint") {
61
+ return value;
62
+ }
63
+ if (typeof value !== "object" ||
64
+ depth >= MAX_SNAPSHOT_DEPTH ||
65
+ state.seen.has(value) ||
66
+ state.isProxy(value)) {
67
+ return SNAPSHOT_FAILED;
68
+ }
69
+ state.seen.add(value);
70
+ try {
71
+ if (arrayIsArray(value)) {
72
+ const descriptors = getOwnPropertyDescriptors(value);
73
+ const lengthDescriptor = descriptors["length"];
74
+ if (!lengthDescriptor ||
75
+ !("value" in lengthDescriptor) ||
76
+ typeof lengthDescriptor.value !== "number" ||
77
+ lengthDescriptor.value > state.remainingEntries) {
78
+ return SNAPSHOT_FAILED;
79
+ }
80
+ state.remainingEntries -= lengthDescriptor.value;
81
+ const result = new NativeArray(lengthDescriptor.value);
82
+ for (let index = 0; index < lengthDescriptor.value; index++) {
83
+ const descriptor = descriptors[String(index)];
84
+ if (!descriptor)
85
+ continue;
86
+ if (!("value" in descriptor))
87
+ return SNAPSHOT_FAILED;
88
+ const child = snapshotPlainValue(descriptor.value, depth + 1, state);
89
+ if (child === SNAPSHOT_FAILED)
90
+ return SNAPSHOT_FAILED;
91
+ result[index] = child;
92
+ }
93
+ return result;
94
+ }
95
+ const prototype = getPrototypeOf(value);
96
+ if (prototype !== objectPrototype && prototype !== null)
97
+ return SNAPSHOT_FAILED;
98
+ const descriptors = getOwnPropertyDescriptors(value);
99
+ const entries = objectEntries(descriptors).filter(([, descriptor]) => descriptor.enumerable);
100
+ if (entries.length > state.remainingEntries)
101
+ return SNAPSHOT_FAILED;
102
+ state.remainingEntries -= entries.length;
103
+ const result = {};
104
+ for (const [key, descriptor] of entries) {
105
+ if (!("value" in descriptor))
106
+ return SNAPSHOT_FAILED;
107
+ const child = snapshotPlainValue(descriptor.value, depth + 1, state);
108
+ if (child === SNAPSHOT_FAILED)
109
+ return SNAPSHOT_FAILED;
110
+ defineProperty(result, key, {
111
+ configurable: true,
112
+ enumerable: true,
113
+ value: child,
114
+ writable: true,
115
+ });
116
+ }
117
+ return result;
118
+ }
119
+ catch {
120
+ return SNAPSHOT_FAILED;
121
+ }
122
+ finally {
123
+ state.seen.delete(value);
124
+ }
125
+ }
126
+ function isRecord(value) {
127
+ return typeof value === "object" && value !== null && !arrayIsArray(value);
128
+ }
129
+ function isString(value) {
130
+ return typeof value === "string";
131
+ }
132
+ function isFiniteNumber(value) {
133
+ return typeof value === "number" && numberIsFinite(value);
134
+ }
135
+ function optionalField(source, key, predicate) {
136
+ if (!hasOwn(source, key) || source[key] === undefined)
137
+ return undefined;
138
+ return predicate(source[key]) ? source[key] : INVALID_ERROR_DATA;
139
+ }
140
+ function optionalContext(source, normalize) {
141
+ if (!hasOwn(source, "context") || source.context === undefined) {
142
+ return undefined;
143
+ }
144
+ return normalize(source.context);
145
+ }
146
+ function normalizeStringArray(value) {
147
+ if (!arrayIsArray(value))
148
+ return INVALID_ERROR_DATA;
149
+ const normalized = [];
150
+ for (const entry of value) {
151
+ if (!isString(entry))
152
+ return INVALID_ERROR_DATA;
153
+ normalized.push(entry);
154
+ }
155
+ return normalized;
156
+ }
157
+ function normalizeMissingDependencies(value) {
158
+ if (!arrayIsArray(value))
159
+ return INVALID_ERROR_DATA;
160
+ const normalized = [];
161
+ for (const entry of value) {
162
+ if (!isRecord(entry) ||
163
+ typeof entry.specifier !== "string" ||
164
+ typeof entry.fromFile !== "string" ||
165
+ typeof entry.reason !== "string") {
166
+ return INVALID_ERROR_DATA;
167
+ }
168
+ normalized.push({
169
+ specifier: entry.specifier,
170
+ fromFile: entry.fromFile,
171
+ reason: entry.reason,
172
+ });
173
+ }
174
+ return normalized;
175
+ }
176
+ const BUILD_PHASES = new NativeSet([
177
+ "parse",
178
+ "transform",
179
+ "bundle",
180
+ "optimize",
181
+ "dependency-resolution",
182
+ "circuit-breaker",
183
+ "http-bundle-validation",
184
+ ]);
185
+ function isBuildPhase(value) {
186
+ return typeof value === "string" &&
187
+ BUILD_PHASES.has(value);
188
+ }
189
+ function normalizeBuildContext(value) {
190
+ if (!isRecord(value))
191
+ return INVALID_ERROR_DATA;
192
+ const file = optionalField(value, "file", isString);
193
+ const line = optionalField(value, "line", isFiniteNumber);
194
+ const column = optionalField(value, "column", isFiniteNumber);
195
+ const moduleId = optionalField(value, "moduleId", isString);
196
+ const phase = optionalField(value, "phase", isBuildPhase);
197
+ const failures = optionalField(value, "failures", isFiniteNumber);
198
+ const missing = optionalField(value, "missing", arrayIsArray);
199
+ const failed = optionalField(value, "failed", arrayIsArray);
200
+ const cacheDir = optionalField(value, "cacheDir", isString);
201
+ if (file === INVALID_ERROR_DATA ||
202
+ line === INVALID_ERROR_DATA ||
203
+ column === INVALID_ERROR_DATA ||
204
+ moduleId === INVALID_ERROR_DATA ||
205
+ phase === INVALID_ERROR_DATA ||
206
+ failures === INVALID_ERROR_DATA ||
207
+ missing === INVALID_ERROR_DATA ||
208
+ failed === INVALID_ERROR_DATA ||
209
+ cacheDir === INVALID_ERROR_DATA) {
210
+ return INVALID_ERROR_DATA;
211
+ }
212
+ const normalizedMissing = missing === undefined
213
+ ? undefined
214
+ : normalizeMissingDependencies(missing);
215
+ const normalizedFailed = failed === undefined ? undefined : normalizeStringArray(failed);
216
+ if (normalizedMissing === INVALID_ERROR_DATA ||
217
+ normalizedFailed === INVALID_ERROR_DATA) {
218
+ return INVALID_ERROR_DATA;
219
+ }
220
+ const normalized = {};
221
+ if (file !== undefined)
222
+ normalized.file = file;
223
+ if (line !== undefined)
224
+ normalized.line = line;
225
+ if (column !== undefined)
226
+ normalized.column = column;
227
+ if (moduleId !== undefined)
228
+ normalized.moduleId = moduleId;
229
+ if (phase !== undefined)
230
+ normalized.phase = phase;
231
+ if (failures !== undefined)
232
+ normalized.failures = failures;
233
+ if (normalizedMissing !== undefined)
234
+ normalized.missing = normalizedMissing;
235
+ if (normalizedFailed !== undefined)
236
+ normalized.failed = normalizedFailed;
237
+ if (cacheDir !== undefined)
238
+ normalized.cacheDir = cacheDir;
239
+ return normalized;
240
+ }
241
+ function normalizeHeaders(value) {
242
+ if (!isRecord(value))
243
+ return INVALID_ERROR_DATA;
244
+ const headers = createObject(null);
245
+ for (const [name, headerValue] of objectEntries(value)) {
246
+ if (typeof headerValue !== "string")
247
+ return INVALID_ERROR_DATA;
248
+ headers[name] = headerValue;
249
+ }
250
+ return headers;
251
+ }
252
+ function normalizeAPIContext(value) {
253
+ if (!isRecord(value))
254
+ return INVALID_ERROR_DATA;
255
+ const endpoint = optionalField(value, "endpoint", isString);
256
+ const method = optionalField(value, "method", isString);
257
+ const statusCode = optionalField(value, "statusCode", isFiniteNumber);
258
+ const headersValue = optionalField(value, "headers", isRecord);
259
+ if (endpoint === INVALID_ERROR_DATA ||
260
+ method === INVALID_ERROR_DATA ||
261
+ statusCode === INVALID_ERROR_DATA ||
262
+ headersValue === INVALID_ERROR_DATA) {
263
+ return INVALID_ERROR_DATA;
264
+ }
265
+ const headers = headersValue === undefined ? undefined : normalizeHeaders(headersValue);
266
+ if (headers === INVALID_ERROR_DATA)
267
+ return INVALID_ERROR_DATA;
268
+ const normalized = {};
269
+ if (endpoint !== undefined)
270
+ normalized.endpoint = endpoint;
271
+ if (method !== undefined)
272
+ normalized.method = method;
273
+ if (statusCode !== undefined)
274
+ normalized.statusCode = statusCode;
275
+ if (headers !== undefined)
276
+ normalized.headers = headers;
277
+ return normalized;
278
+ }
279
+ const RENDER_PHASES = new NativeSet([
280
+ "server",
281
+ "client",
282
+ "hydration",
283
+ ]);
284
+ function isRenderPhase(value) {
285
+ return typeof value === "string" &&
286
+ RENDER_PHASES.has(value);
287
+ }
288
+ function normalizeRenderContext(value) {
289
+ if (!isRecord(value))
290
+ return INVALID_ERROR_DATA;
291
+ const component = optionalField(value, "component", isString);
292
+ const route = optionalField(value, "route", isString);
293
+ const phase = optionalField(value, "phase", isRenderPhase);
294
+ if (component === INVALID_ERROR_DATA ||
295
+ route === INVALID_ERROR_DATA ||
296
+ phase === INVALID_ERROR_DATA) {
297
+ return INVALID_ERROR_DATA;
298
+ }
299
+ const normalized = {};
300
+ if (component !== undefined)
301
+ normalized.component = component;
302
+ if (route !== undefined)
303
+ normalized.route = route;
304
+ if (phase !== undefined)
305
+ normalized.phase = phase;
306
+ if (hasOwn(value, "props") && value.props !== undefined) {
307
+ normalized.props = value.props;
308
+ }
309
+ return normalized;
310
+ }
311
+ function normalizeConfigContext(value) {
312
+ if (!isRecord(value))
313
+ return INVALID_ERROR_DATA;
314
+ const configFile = optionalField(value, "configFile", isString);
315
+ const field = optionalField(value, "field", isString);
316
+ const expected = optionalField(value, "expected", isString);
317
+ if (configFile === INVALID_ERROR_DATA ||
318
+ field === INVALID_ERROR_DATA ||
319
+ expected === INVALID_ERROR_DATA) {
320
+ return INVALID_ERROR_DATA;
321
+ }
322
+ const normalized = {};
323
+ if (configFile !== undefined)
324
+ normalized.configFile = configFile;
325
+ if (field !== undefined)
326
+ normalized.field = field;
327
+ if (hasOwn(value, "value") && value.value !== undefined) {
328
+ normalized.value = value.value;
329
+ }
330
+ if (expected !== undefined)
331
+ normalized.expected = expected;
332
+ return normalized;
333
+ }
334
+ function normalizeAgentContext(value) {
335
+ if (!isRecord(value))
336
+ return INVALID_ERROR_DATA;
337
+ const agentId = optionalField(value, "agentId", isString);
338
+ const intent = optionalField(value, "intent", isString);
339
+ const timeout = optionalField(value, "timeout", isFiniteNumber);
340
+ if (agentId === INVALID_ERROR_DATA ||
341
+ intent === INVALID_ERROR_DATA ||
342
+ timeout === INVALID_ERROR_DATA) {
343
+ return INVALID_ERROR_DATA;
344
+ }
345
+ const normalized = {};
346
+ if (agentId !== undefined)
347
+ normalized.agentId = agentId;
348
+ if (intent !== undefined)
349
+ normalized.intent = intent;
350
+ if (timeout !== undefined)
351
+ normalized.timeout = timeout;
352
+ return normalized;
353
+ }
354
+ const FILE_OPERATIONS = new NativeSet([
355
+ "read",
356
+ "write",
357
+ "delete",
358
+ "mkdir",
359
+ ]);
360
+ function isFileOperation(value) {
361
+ return typeof value === "string" &&
362
+ FILE_OPERATIONS.has(value);
363
+ }
364
+ function normalizeFileContext(value) {
365
+ if (!isRecord(value))
366
+ return INVALID_ERROR_DATA;
367
+ const path = optionalField(value, "path", isString);
368
+ const operation = optionalField(value, "operation", isFileOperation);
369
+ const permissions = optionalField(value, "permissions", isString);
370
+ if (path === INVALID_ERROR_DATA ||
371
+ operation === INVALID_ERROR_DATA ||
372
+ permissions === INVALID_ERROR_DATA) {
373
+ return INVALID_ERROR_DATA;
374
+ }
375
+ const normalized = {};
376
+ if (path !== undefined)
377
+ normalized.path = path;
378
+ if (operation !== undefined)
379
+ normalized.operation = operation;
380
+ if (permissions !== undefined)
381
+ normalized.permissions = permissions;
382
+ return normalized;
383
+ }
384
+ function normalizeNetworkContext(value) {
385
+ if (!isRecord(value))
386
+ return INVALID_ERROR_DATA;
387
+ const url = optionalField(value, "url", isString);
388
+ const timeout = optionalField(value, "timeout", isFiniteNumber);
389
+ const retryCount = optionalField(value, "retryCount", isFiniteNumber);
390
+ if (url === INVALID_ERROR_DATA ||
391
+ timeout === INVALID_ERROR_DATA ||
392
+ retryCount === INVALID_ERROR_DATA) {
393
+ return INVALID_ERROR_DATA;
394
+ }
395
+ const normalized = {};
396
+ if (url !== undefined)
397
+ normalized.url = url;
398
+ if (timeout !== undefined)
399
+ normalized.timeout = timeout;
400
+ if (retryCount !== undefined)
401
+ normalized.retryCount = retryCount;
402
+ return normalized;
403
+ }
404
+ function normalizeErrorData(source) {
405
+ if (typeof source.message !== "string")
406
+ return null;
407
+ const message = source.message;
408
+ switch (source.type) {
409
+ case "build": {
410
+ const context = optionalContext(source, normalizeBuildContext);
411
+ if (context === INVALID_ERROR_DATA)
412
+ return null;
413
+ return context === undefined
414
+ ? { type: "build", message }
415
+ : { type: "build", message, context };
416
+ }
417
+ case "api": {
418
+ const context = optionalContext(source, normalizeAPIContext);
419
+ if (context === INVALID_ERROR_DATA)
420
+ return null;
421
+ return context === undefined ? { type: "api", message } : { type: "api", message, context };
422
+ }
423
+ case "render": {
424
+ const context = optionalContext(source, normalizeRenderContext);
425
+ if (context === INVALID_ERROR_DATA)
426
+ return null;
427
+ return context === undefined
428
+ ? { type: "render", message }
429
+ : { type: "render", message, context };
430
+ }
431
+ case "config": {
432
+ const context = optionalContext(source, normalizeConfigContext);
433
+ if (context === INVALID_ERROR_DATA)
434
+ return null;
435
+ return context === undefined
436
+ ? { type: "config", message }
437
+ : { type: "config", message, context };
438
+ }
439
+ case "agent": {
440
+ const context = optionalContext(source, normalizeAgentContext);
441
+ if (context === INVALID_ERROR_DATA)
442
+ return null;
443
+ return context === undefined
444
+ ? { type: "agent", message }
445
+ : { type: "agent", message, context };
446
+ }
447
+ case "file": {
448
+ const context = optionalContext(source, normalizeFileContext);
449
+ if (context === INVALID_ERROR_DATA)
450
+ return null;
451
+ return context === undefined ? { type: "file", message } : { type: "file", message, context };
452
+ }
453
+ case "network": {
454
+ const context = optionalContext(source, normalizeNetworkContext);
455
+ if (context === INVALID_ERROR_DATA)
456
+ return null;
457
+ return context === undefined
458
+ ? { type: "network", message }
459
+ : { type: "network", message, context };
460
+ }
461
+ case "permission": {
462
+ const context = optionalContext(source, normalizeFileContext);
463
+ if (context === INVALID_ERROR_DATA)
464
+ return null;
465
+ return context === undefined
466
+ ? { type: "permission", message }
467
+ : { type: "permission", message, context };
468
+ }
469
+ case "not_supported": {
470
+ const feature = optionalField(source, "feature", isString);
471
+ if (feature === INVALID_ERROR_DATA)
472
+ return null;
473
+ return feature === undefined
474
+ ? { type: "not_supported", message }
475
+ : { type: "not_supported", message, feature };
476
+ }
477
+ case "no_ai_available":
478
+ return { type: "no_ai_available", message };
479
+ default:
480
+ return null;
481
+ }
482
+ }
483
+ export function toError(veryfrontError, ErrorType = NativeError) {
484
+ const error = new ErrorType(veryfrontError.message);
24
485
  error.name = `VeryfrontError[${veryfrontError.type}]`;
25
486
  // Capture stack at call site, excluding toError from the trace
26
487
  // This makes debugging easier by showing where createError+toError was called
27
- if (Error.captureStackTrace)
28
- Error.captureStackTrace(error, toError);
29
- Object.defineProperty(error, "context", {
488
+ if (captureStackTrace) {
489
+ apply(captureStackTrace, NativeError, [error, toError]);
490
+ }
491
+ defineProperty(error, "context", {
30
492
  value: veryfrontError,
31
493
  enumerable: false,
32
494
  configurable: true,
33
495
  });
34
496
  return error;
35
497
  }
36
- export function fromError(error) {
37
- if (!error || typeof error !== "object" || !("context" in error))
498
+ /** @internal Decode one already-extracted legacy context value. */
499
+ export function decodeVeryfrontErrorData(contextValue, isProxy) {
500
+ try {
501
+ const context = snapshotPlainValue(contextValue, 0, {
502
+ isProxy,
503
+ seen: new NativeSet(),
504
+ remainingEntries: MAX_SNAPSHOT_ENTRIES,
505
+ });
506
+ if (context === SNAPSHOT_FAILED ||
507
+ !context ||
508
+ typeof context !== "object" ||
509
+ arrayIsArray(context)) {
510
+ return null;
511
+ }
512
+ return normalizeErrorData(context);
513
+ }
514
+ catch {
38
515
  return null;
39
- const context = error.context;
40
- if (!context || typeof context !== "object")
41
- return null;
42
- if (!("type" in context) || !("message" in context))
43
- return null;
44
- return context;
516
+ }
45
517
  }
46
518
  /**
47
519
  * Extract error message from any error type
48
520
  */
49
521
  export function getErrorMessage(error) {
50
- if (error instanceof Error)
51
- return error.message;
52
- return String(error);
522
+ try {
523
+ if (isErrorInstance(error)) {
524
+ const message = error.message;
525
+ return typeof message === "string" ? message : "Unknown error";
526
+ }
527
+ return NativeString(error);
528
+ }
529
+ catch {
530
+ return "Unknown error";
531
+ }
532
+ }
533
+ /** Runtime-safe native Error guard for values caught from untrusted code. */
534
+ export function isErrorInstance(error) {
535
+ return hasNativeErrorBrand(error);
536
+ }
537
+ /** Snapshot a native Error without retaining a proxy or invoking it again later. */
538
+ export function snapshotError(error) {
539
+ if (!isErrorInstance(error))
540
+ return null;
541
+ return snapshotKnownError(error);
542
+ }
543
+ export function snapshotKnownError(error) {
544
+ try {
545
+ const descriptors = getOwnPropertyDescriptors(error);
546
+ const ownDataValue = (key) => {
547
+ const descriptor = descriptors[key];
548
+ return descriptor && "value" in descriptor ? descriptor.value : undefined;
549
+ };
550
+ const ownName = ownDataValue("name");
551
+ const ownMessage = ownDataValue("message");
552
+ const ownStack = ownDataValue("stack");
553
+ const prototype = getPrototypeOf(error);
554
+ const prototypeName = prototype !== null
555
+ ? getOwnPropertyDescriptor(prototype, "name")
556
+ : undefined;
557
+ const name = ownName === undefined &&
558
+ prototypeName &&
559
+ "value" in prototypeName &&
560
+ typeof prototypeName.value === "string"
561
+ ? prototypeName.value
562
+ : ownName ?? "Error";
563
+ const message = ownMessage === undefined ? "" : ownMessage;
564
+ const stack = ownStack === undefined ? undefined : ownStack;
565
+ if (typeof name !== "string" ||
566
+ typeof message !== "string" ||
567
+ (stack !== undefined && typeof stack !== "string")) {
568
+ return null;
569
+ }
570
+ return { name, message, stack };
571
+ }
572
+ catch {
573
+ return null;
574
+ }
575
+ }
576
+ function applySnapshotStack(error, stack) {
577
+ if (stack === undefined)
578
+ return;
579
+ defineProperty(error, "stack", {
580
+ configurable: true,
581
+ value: stack,
582
+ writable: true,
583
+ });
584
+ }
585
+ function detachVeryfrontError(snapshot) {
586
+ const detached = new VeryfrontError(snapshot.message, {
587
+ slug: snapshot.slug,
588
+ category: snapshot.category,
589
+ status: snapshot.status,
590
+ title: snapshot.title,
591
+ suggestion: snapshot.suggestion,
592
+ exitCode: snapshot.exitCode,
593
+ detail: snapshot.detail,
594
+ cause: snapshot.cause,
595
+ instance: snapshot.instance,
596
+ context: snapshot.context,
597
+ });
598
+ applySnapshotStack(detached, snapshot.stack);
599
+ return detached;
600
+ }
601
+ function copyOwnDataProperties(source, target) {
602
+ try {
603
+ const descriptors = getOwnPropertyDescriptors(source);
604
+ for (const [key, descriptor] of objectEntries(descriptors)) {
605
+ if (key === "name" || key === "message" || key === "stack")
606
+ continue;
607
+ if (!("value" in descriptor))
608
+ continue;
609
+ defineProperty(target, key, {
610
+ configurable: true,
611
+ enumerable: descriptor.enumerable,
612
+ value: descriptor.value,
613
+ writable: true,
614
+ });
615
+ }
616
+ }
617
+ catch {
618
+ // Core fields were already detached. Unreadable optional metadata is omitted.
619
+ }
620
+ }
621
+ function detachNativeError(source, snapshot) {
622
+ const detached = new NativeError(snapshot.message);
623
+ detached.name = snapshot.name;
624
+ applySnapshotStack(detached, snapshot.stack);
625
+ copyOwnDataProperties(source, detached);
626
+ return detached;
627
+ }
628
+ /**
629
+ * Normalize a thrown value into a detached Error snapshot.
630
+ *
631
+ * Use this at boundaries that retain or repeatedly inspect the result. A
632
+ * transparent Proxy can pass `instanceof Error` while throwing or changing
633
+ * values on a later property read.
634
+ */
635
+ export function snapshotErrorAsError(error) {
636
+ if (isVeryfrontErrorInstance(error)) {
637
+ const veryfrontSnapshot = snapshotKnownVeryfrontError(error);
638
+ return veryfrontSnapshot
639
+ ? detachVeryfrontError(veryfrontSnapshot)
640
+ : new NativeError("Unknown error");
641
+ }
642
+ if (isErrorInstance(error)) {
643
+ const nativeSnapshot = snapshotKnownError(error);
644
+ return nativeSnapshot
645
+ ? detachNativeError(error, nativeSnapshot)
646
+ : new NativeError("Unknown error");
647
+ }
648
+ return new NativeError(safePrimitiveErrorMessage(error));
649
+ }
650
+ function safePrimitiveErrorMessage(error) {
651
+ if ((typeof error === "object" && error !== null) ||
652
+ typeof error === "function") {
653
+ return "Unknown error";
654
+ }
655
+ try {
656
+ return NativeString(error);
657
+ }
658
+ catch {
659
+ return "Unknown error";
660
+ }
53
661
  }
54
662
  /**
55
- * Ensure error is an Error instance
663
+ * Ensure a value is an Error while preserving the established identity
664
+ * contract for ordinary Error instances.
56
665
  */
57
666
  export function ensureError(error) {
58
- if (error instanceof Error)
59
- return error;
60
- return new Error(String(error));
667
+ if (isErrorInstance(error)) {
668
+ return snapshotError(error) ? error : new NativeError("Unknown error");
669
+ }
670
+ return new NativeError(safePrimitiveErrorMessage(error));
61
671
  }