@trebired/result 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/README.md +261 -20
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/instrument_result_exports.d.ts +6 -0
- package/dist/instrument_result_exports.d.ts.map +1 -0
- package/dist/instrument_result_exports.js +62 -0
- package/dist/instrument_result_exports.js.map +1 -0
- package/dist/logging.d.ts +4 -0
- package/dist/logging.d.ts.map +1 -0
- package/dist/logging.js +14 -0
- package/dist/logging.js.map +1 -0
- package/dist/module_hooks.d.ts +6 -0
- package/dist/module_hooks.d.ts.map +1 -0
- package/dist/module_hooks.js +90 -0
- package/dist/module_hooks.js.map +1 -0
- package/dist/process_hooks.d.ts +6 -0
- package/dist/process_hooks.d.ts.map +1 -0
- package/dist/process_hooks.js +69 -0
- package/dist/process_hooks.js.map +1 -0
- package/dist/responder.d.ts.map +1 -1
- package/dist/responder.js +6 -4
- package/dist/responder.js.map +1 -1
- package/dist/responder_support.d.ts +2 -2
- package/dist/responder_support.d.ts.map +1 -1
- package/dist/responder_support.js +2 -2
- package/dist/responder_support.js.map +1 -1
- package/dist/src/index.d.ts +7 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +7 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/instrument_result_exports.d.ts +6 -0
- package/dist/src/instrument_result_exports.d.ts.map +1 -0
- package/dist/src/instrument_result_exports.js +62 -0
- package/dist/src/instrument_result_exports.js.map +1 -0
- package/dist/src/logging.d.ts +4 -0
- package/dist/src/logging.d.ts.map +1 -0
- package/dist/src/logging.js +14 -0
- package/dist/src/logging.js.map +1 -0
- package/dist/src/module_hooks.d.ts +6 -0
- package/dist/src/module_hooks.d.ts.map +1 -0
- package/dist/src/module_hooks.js +90 -0
- package/dist/src/module_hooks.js.map +1 -0
- package/dist/src/process_hooks.d.ts +6 -0
- package/dist/src/process_hooks.d.ts.map +1 -0
- package/dist/src/process_hooks.js +69 -0
- package/dist/src/process_hooks.js.map +1 -0
- package/dist/src/responder.d.ts.map +1 -1
- package/dist/src/responder.js +6 -4
- package/dist/src/responder.js.map +1 -1
- package/dist/src/responder_support.d.ts +2 -2
- package/dist/src/responder_support.d.ts.map +1 -1
- package/dist/src/responder_support.js +2 -2
- package/dist/src/responder_support.js.map +1 -1
- package/dist/src/trace/capture.d.ts +8 -0
- package/dist/src/trace/capture.d.ts.map +1 -0
- package/dist/src/trace/capture.js +47 -0
- package/dist/src/trace/capture.js.map +1 -0
- package/dist/src/trace/runtime.d.ts +51 -0
- package/dist/src/trace/runtime.d.ts.map +1 -0
- package/dist/src/trace/runtime.js +151 -0
- package/dist/src/trace/runtime.js.map +1 -0
- package/dist/src/trace/types.d.ts +121 -0
- package/dist/src/trace/types.d.ts.map +1 -0
- package/dist/src/trace/types.js +2 -0
- package/dist/src/trace/types.js.map +1 -0
- package/dist/src/trace/utils.d.ts +14 -0
- package/dist/src/trace/utils.d.ts.map +1 -0
- package/dist/src/trace/utils.js +150 -0
- package/dist/src/trace/utils.js.map +1 -0
- package/dist/src/tracer.d.ts +5 -0
- package/dist/src/tracer.d.ts.map +1 -0
- package/dist/src/tracer.js +76 -0
- package/dist/src/tracer.js.map +1 -0
- package/dist/src/types.d.ts +10 -4
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/wrap/result/function.d.ts +6 -0
- package/dist/src/wrap/result/function.d.ts.map +1 -0
- package/dist/src/wrap/result/function.js +61 -0
- package/dist/src/wrap/result/function.js.map +1 -0
- package/dist/src/wrap/result/promise.d.ts +6 -0
- package/dist/src/wrap/result/promise.d.ts.map +1 -0
- package/dist/src/wrap/result/promise.js +45 -0
- package/dist/src/wrap/result/promise.js.map +1 -0
- package/dist/trace/capture.d.ts +8 -0
- package/dist/trace/capture.d.ts.map +1 -0
- package/dist/trace/capture.js +47 -0
- package/dist/trace/capture.js.map +1 -0
- package/dist/trace/runtime.d.ts +51 -0
- package/dist/trace/runtime.d.ts.map +1 -0
- package/dist/trace/runtime.js +151 -0
- package/dist/trace/runtime.js.map +1 -0
- package/dist/trace/types.d.ts +121 -0
- package/dist/trace/types.d.ts.map +1 -0
- package/dist/trace/types.js +2 -0
- package/dist/trace/types.js.map +1 -0
- package/dist/trace/utils.d.ts +14 -0
- package/dist/trace/utils.d.ts.map +1 -0
- package/dist/trace/utils.js +150 -0
- package/dist/trace/utils.js.map +1 -0
- package/dist/tracer.d.ts +5 -0
- package/dist/tracer.d.ts.map +1 -0
- package/dist/tracer.js +76 -0
- package/dist/tracer.js.map +1 -0
- package/dist/types.d.ts +10 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/wrap/result/function.d.ts +6 -0
- package/dist/wrap/result/function.d.ts.map +1 -0
- package/dist/wrap/result/function.js +61 -0
- package/dist/wrap/result/function.js.map +1 -0
- package/dist/wrap/result/promise.d.ts +6 -0
- package/dist/wrap/result/promise.d.ts.map +1 -0
- package/dist/wrap/result/promise.js +45 -0
- package/dist/wrap/result/promise.js.map +1 -0
- package/package.json +19 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.1
|
|
4
|
+
|
|
5
|
+
- Moved package-owned result tracing and responder diagnostics under the `trebired.result` group root while leaving caller-supplied trace labels intact.
|
|
6
|
+
|
|
7
|
+
## 0.2.0
|
|
8
|
+
|
|
9
|
+
- Expanded `@trebired/result` into a fuller failure-handling toolkit with opt-in tracing, sync and async wrappers, promise tracing, export/object instrumentation, process hooks, module hooks, shared trace utilities, and AsyncLocalStorage-backed trace-stack propagation.
|
|
10
|
+
- Kept the responder and preset system reusable while adding explicit tracing APIs, stronger types, pack verification coverage for the new surface, and updated publishing-ready docs.
|
|
11
|
+
|
|
3
12
|
## 0.1.0
|
|
4
13
|
|
|
5
14
|
- Added the initial `@trebired/result` release with typed result builders, a transport-agnostic responder factory, preset resolution with parent type fallback, and pack verification coverage.
|
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# @trebired/result
|
|
2
2
|
|
|
3
|
-
Shared result builders and
|
|
3
|
+
Shared result builders, response orchestration, and failure tracing for Bun and Node.js products.
|
|
4
4
|
|
|
5
|
-
`@trebired/result`
|
|
5
|
+
`@trebired/result` gives Trebired packages a shared result envelope, a transport-facing responder layer, and an opt-in tracing toolkit for failed flows.
|
|
6
6
|
|
|
7
|
-
It does not know about Express, React,
|
|
7
|
+
It does not know about Express, React, route names, page names, logger group wording, or a fixed runtime layout. Hosts bring their own adapters and decide which advanced tracing surfaces to enable.
|
|
8
8
|
|
|
9
9
|
## Install
|
|
10
10
|
|
|
@@ -16,7 +16,7 @@ npm install @trebired/result
|
|
|
16
16
|
|
|
17
17
|
## Quick Start
|
|
18
18
|
|
|
19
|
-
Build shared
|
|
19
|
+
Build shared result payloads in normal application code:
|
|
20
20
|
|
|
21
21
|
```ts
|
|
22
22
|
import { result } from "@trebired/result";
|
|
@@ -34,7 +34,7 @@ const missing = result.notFound("project-not-found", "Project not found.", {
|
|
|
34
34
|
});
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
Wire a responder with transport adapters:
|
|
38
38
|
|
|
39
39
|
```ts
|
|
40
40
|
import { createResultResponder, result } from "@trebired/result";
|
|
@@ -63,9 +63,33 @@ return responder.respond({
|
|
|
63
63
|
});
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
+
Add tracing only where it helps:
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
import { createResultTracer, result } from "@trebired/result";
|
|
70
|
+
|
|
71
|
+
const tracer = createResultTracer({
|
|
72
|
+
failedResultSeverity: "warn",
|
|
73
|
+
logger: console,
|
|
74
|
+
onTrace(record) {
|
|
75
|
+
console.error(record.label, record.message, record.traceStack);
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const loadProject = tracer.wrapFunction(async (id: string) => {
|
|
80
|
+
if (id === "missing") {
|
|
81
|
+
return result.notFound("project-not-found", "Project not found.");
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
throw new Error("Database offline");
|
|
85
|
+
}, {
|
|
86
|
+
label: "project.load",
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
66
90
|
## Result Builder
|
|
67
91
|
|
|
68
|
-
The shared result envelope
|
|
92
|
+
The shared result envelope stays consistent across success, noop, and error outcomes:
|
|
69
93
|
|
|
70
94
|
```ts
|
|
71
95
|
type ResultLike = {
|
|
@@ -94,7 +118,7 @@ Builder helpers:
|
|
|
94
118
|
- `result.conflict(...)`
|
|
95
119
|
- `result.internal(...)`
|
|
96
120
|
|
|
97
|
-
The `meta` argument
|
|
121
|
+
The `meta` argument accepts optional `data`, `details`, `redirect`, `meta`, and `error` fields.
|
|
98
122
|
|
|
99
123
|
## Responder Model
|
|
100
124
|
|
|
@@ -105,7 +129,7 @@ The responder factory keeps transport concerns outside the package:
|
|
|
105
129
|
- `text` receives a fallback payload when render is unavailable or throws.
|
|
106
130
|
- `getRenderModePath` is optional and lets a host derive mode-aware render variants such as `app.process.error`.
|
|
107
131
|
|
|
108
|
-
|
|
132
|
+
Preset resolution walks in this order:
|
|
109
133
|
|
|
110
134
|
1. result level
|
|
111
135
|
2. exact status for that level
|
|
@@ -147,7 +171,217 @@ const preset = resolveResultPreset({
|
|
|
147
171
|
});
|
|
148
172
|
```
|
|
149
173
|
|
|
150
|
-
Defaults
|
|
174
|
+
Defaults stay reusable. No app-specific views, routes, or page names are built in.
|
|
175
|
+
|
|
176
|
+
## Tracing Toolkit
|
|
177
|
+
|
|
178
|
+
Tracing is fully opt-in. Nothing patches the runtime unless you call a tracing API.
|
|
179
|
+
|
|
180
|
+
Logger delivery uses `@trebired/logger-adapter`, so package code can keep Trebired-style `group/message/metadata` logging while still accepting `console`, pino-style loggers, sink functions, or a custom `loggerAdapter` writer.
|
|
181
|
+
|
|
182
|
+
`createResultTracer()` gives you one runtime with:
|
|
183
|
+
|
|
184
|
+
- failed-result tracing
|
|
185
|
+
- thrown-error tracing
|
|
186
|
+
- rejected-promise tracing
|
|
187
|
+
- nested trace-stack propagation
|
|
188
|
+
- wrapper and proxy caches
|
|
189
|
+
- optional process and module hooks
|
|
190
|
+
|
|
191
|
+
```ts
|
|
192
|
+
import { createResultTracer, result } from "@trebired/result";
|
|
193
|
+
|
|
194
|
+
const records: unknown[] = [];
|
|
195
|
+
const tracer = createResultTracer({
|
|
196
|
+
stackDepth: 10,
|
|
197
|
+
failedResultSeverity: "warn",
|
|
198
|
+
logger: console,
|
|
199
|
+
onTrace(record) {
|
|
200
|
+
records.push(record);
|
|
201
|
+
},
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
tracer.traceFailure(result.notFound("project-not-found", "Missing."), {
|
|
205
|
+
label: "project.read",
|
|
206
|
+
});
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Each trace record includes:
|
|
210
|
+
|
|
211
|
+
- `kind`
|
|
212
|
+
- `severity`
|
|
213
|
+
- `label`
|
|
214
|
+
- `errorCode`
|
|
215
|
+
- `status`
|
|
216
|
+
- `message`
|
|
217
|
+
- `compactStack`
|
|
218
|
+
- `failureSite`
|
|
219
|
+
- `argumentPreview`
|
|
220
|
+
- `metadataSummary`
|
|
221
|
+
- `dataSummary`
|
|
222
|
+
- `detailsSummary`
|
|
223
|
+
- `source`
|
|
224
|
+
- `traceStack`
|
|
225
|
+
|
|
226
|
+
## Wrapping Functions And Promises
|
|
227
|
+
|
|
228
|
+
Use wrappers when you want tracing without rewriting the function body:
|
|
229
|
+
|
|
230
|
+
```ts
|
|
231
|
+
import { createResultTracer, result } from "@trebired/result";
|
|
232
|
+
|
|
233
|
+
const tracer = createResultTracer();
|
|
234
|
+
|
|
235
|
+
const saveProject = tracer.wrapFunction(async (input: { id: string }) => {
|
|
236
|
+
if (!input.id) {
|
|
237
|
+
return result.badRequest("missing-id", "Project id is required.");
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return result.ok("Saved.");
|
|
241
|
+
}, {
|
|
242
|
+
label: "project.save",
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
const remoteSync = tracer.wrapPromise(fetch("https://example.test").then((res) => {
|
|
246
|
+
if (!res.ok) {
|
|
247
|
+
throw new Error(`Remote sync failed: ${res.status}`);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return res;
|
|
251
|
+
}), {
|
|
252
|
+
label: "project.sync",
|
|
253
|
+
});
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
Wrappers preserve original behavior:
|
|
257
|
+
|
|
258
|
+
- sync return values still return normally
|
|
259
|
+
- async return values still resolve or reject normally
|
|
260
|
+
- failed result payloads are traced
|
|
261
|
+
- thrown and rejected failures are traced
|
|
262
|
+
- the same function or promise is not wrapped twice inside the same tracer runtime
|
|
263
|
+
|
|
264
|
+
## Export And Object Instrumentation
|
|
265
|
+
|
|
266
|
+
If a module exports a plain object tree, you can instrument it without hand-wrapping every method:
|
|
267
|
+
|
|
268
|
+
```ts
|
|
269
|
+
import { createResultTracer } from "@trebired/result";
|
|
270
|
+
import * as handlers from "./handlers.js";
|
|
271
|
+
|
|
272
|
+
const tracer = createResultTracer({
|
|
273
|
+
objectDepth: 3,
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
const instrumented = tracer.instrumentExports(handlers, {
|
|
277
|
+
label: "handlers",
|
|
278
|
+
include: "invoice",
|
|
279
|
+
});
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
Instrumentation:
|
|
283
|
+
|
|
284
|
+
- wraps callable exports
|
|
285
|
+
- descends into plain object trees up to the configured depth
|
|
286
|
+
- leaves symbol-based access alone
|
|
287
|
+
- caches proxies and wrappers so the same target is reused
|
|
288
|
+
|
|
289
|
+
## Process And Module Hooks
|
|
290
|
+
|
|
291
|
+
Advanced runtime hooks are available when you explicitly opt in.
|
|
292
|
+
|
|
293
|
+
Process hooks:
|
|
294
|
+
|
|
295
|
+
```ts
|
|
296
|
+
import { installResultProcessHooks } from "@trebired/result";
|
|
297
|
+
|
|
298
|
+
const hooks = installResultProcessHooks({
|
|
299
|
+
logger: console,
|
|
300
|
+
exitOnUncaughtException: false,
|
|
301
|
+
exitOnUnhandledRejection: false,
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
hooks.uninstall();
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
Module hooks:
|
|
308
|
+
|
|
309
|
+
```ts
|
|
310
|
+
import { installResultModuleHooks } from "@trebired/result";
|
|
311
|
+
|
|
312
|
+
const hooks = installResultModuleHooks({
|
|
313
|
+
include: [/services/, /workers/],
|
|
314
|
+
labelPrefix: "module",
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
hooks.uninstall();
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
Module instrumentation only works in runtimes that expose a CommonJS-style loader with `_load` support. It is meant for targeted observability, not for blanket patching in every environment.
|
|
321
|
+
|
|
322
|
+
## Boot Helper
|
|
323
|
+
|
|
324
|
+
If you want one entrypoint that creates a tracer and installs selected hooks, use `bootResultTracing()`:
|
|
325
|
+
|
|
326
|
+
```ts
|
|
327
|
+
import { bootResultTracing } from "@trebired/result";
|
|
328
|
+
|
|
329
|
+
const boot = bootResultTracing({
|
|
330
|
+
logger: console,
|
|
331
|
+
processHooks: {
|
|
332
|
+
exitOnUncaughtException: false,
|
|
333
|
+
},
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
boot.tracer.wrapFunction(() => {
|
|
337
|
+
throw new Error("boom");
|
|
338
|
+
}, {
|
|
339
|
+
label: "demo.run",
|
|
340
|
+
});
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
## Configuration
|
|
344
|
+
|
|
345
|
+
Tracing configuration lets hosts control:
|
|
346
|
+
|
|
347
|
+
- `enabled`
|
|
348
|
+
- `logger`
|
|
349
|
+
- `loggerAdapter`
|
|
350
|
+
- `onTrace`
|
|
351
|
+
- `include`
|
|
352
|
+
- `exclude`
|
|
353
|
+
- `objectDepth`
|
|
354
|
+
- `stackDepth`
|
|
355
|
+
- `argumentPreview`
|
|
356
|
+
- `summaryPreview`
|
|
357
|
+
- `failedResultSeverity`
|
|
358
|
+
|
|
359
|
+
Wrapper and hook helpers also accept:
|
|
360
|
+
|
|
361
|
+
- `label`
|
|
362
|
+
- `source`
|
|
363
|
+
- `tracer`
|
|
364
|
+
- per-call `include` and `exclude`
|
|
365
|
+
- process exit policies
|
|
366
|
+
- module label prefixes and traversal depth
|
|
367
|
+
|
|
368
|
+
## Safe Defaults
|
|
369
|
+
|
|
370
|
+
Safe by default:
|
|
371
|
+
|
|
372
|
+
- result builders
|
|
373
|
+
- responder factory
|
|
374
|
+
- preset resolution
|
|
375
|
+
- manual tracing with `traceFailure`, `traceResult`, or `traceError`
|
|
376
|
+
- function and promise wrapping
|
|
377
|
+
|
|
378
|
+
More invasive surfaces:
|
|
379
|
+
|
|
380
|
+
- export/object instrumentation
|
|
381
|
+
- process hooks
|
|
382
|
+
- module hooks
|
|
383
|
+
|
|
384
|
+
Those advanced surfaces are still opt-in and can be turned off per host.
|
|
151
385
|
|
|
152
386
|
## Public API
|
|
153
387
|
|
|
@@ -164,6 +398,13 @@ Runtime exports:
|
|
|
164
398
|
- `conflict`
|
|
165
399
|
- `internal`
|
|
166
400
|
- `createResultResponder`
|
|
401
|
+
- `createResultTracer`
|
|
402
|
+
- `bootResultTracing`
|
|
403
|
+
- `wrapResultFunction`
|
|
404
|
+
- `wrapResultPromise`
|
|
405
|
+
- `instrumentResultExports`
|
|
406
|
+
- `installResultProcessHooks`
|
|
407
|
+
- `installResultModuleHooks`
|
|
167
408
|
- `DEFAULT_RESULT_PRESETS`
|
|
168
409
|
- `mergeResultPresets`
|
|
169
410
|
- `resolveResultPreset`
|
|
@@ -171,14 +412,14 @@ Runtime exports:
|
|
|
171
412
|
- `getResultLevel`
|
|
172
413
|
- `normalizeResultErrorCode`
|
|
173
414
|
- `toResultStatus`
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
- `
|
|
178
|
-
- `
|
|
179
|
-
- `
|
|
180
|
-
- `
|
|
181
|
-
- `
|
|
182
|
-
- `
|
|
183
|
-
|
|
184
|
-
|
|
415
|
+
- `captureCallSite`
|
|
416
|
+
- `compactStack`
|
|
417
|
+
- `isFailedResultLike`
|
|
418
|
+
- `matchTraceTarget`
|
|
419
|
+
- `normalizeThrownValue`
|
|
420
|
+
- `normalizeTraceLabel`
|
|
421
|
+
- `previewCallArguments`
|
|
422
|
+
- `previewValue`
|
|
423
|
+
- `summarizeFailedResult`
|
|
424
|
+
|
|
425
|
+
Type exports include the result, responder, preset, and tracing types used by those APIs.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
export { badRequest, conflict, error, forbidden, internal, noop, notFound, ok, result, unauthorized, } from "./result.js";
|
|
2
2
|
export { createResultResponder } from "./responder.js";
|
|
3
|
+
export { bootResultTracing, createResultTracer, } from "./tracer.js";
|
|
4
|
+
export { instrumentResultExports, } from "./instrument_result_exports.js";
|
|
5
|
+
export { installResultModuleHooks, } from "./module_hooks.js";
|
|
6
|
+
export { installResultProcessHooks, } from "./process_hooks.js";
|
|
3
7
|
export { DEFAULT_RESULT_PRESETS, mergeResultPresets, resolveResultPreset, } from "./presets.js";
|
|
4
8
|
export { buildResultRenderModePath, getResultLevel, normalizeResultErrorCode, toResultStatus, } from "./shared.js";
|
|
9
|
+
export { captureCallSite, compactStack, isFailedResultLike, matchTraceTarget, normalizeThrownValue, normalizeTraceLabel, previewCallArguments, previewValue, summarizeFailedResult, } from "./trace/utils.js";
|
|
10
|
+
export { wrapResultFunction, } from "./wrap/result/function.js";
|
|
11
|
+
export { wrapResultPromise, } from "./wrap/result/promise.js";
|
|
5
12
|
export type * from "./types.js";
|
|
6
13
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,QAAQ,EACR,KAAK,EACL,SAAS,EACT,QAAQ,EACR,IAAI,EACJ,QAAQ,EACR,EAAE,EACF,MAAM,EACN,YAAY,GACb,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EACL,sBAAsB,EACtB,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,yBAAyB,EACzB,cAAc,EACd,wBAAwB,EACxB,cAAc,GACf,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,QAAQ,EACR,KAAK,EACL,SAAS,EACT,QAAQ,EACR,IAAI,EACJ,QAAQ,EACR,EAAE,EACF,MAAM,EACN,YAAY,GACb,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EACL,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,uBAAuB,GACxB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,wBAAwB,GACzB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,yBAAyB,GAC1B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,sBAAsB,EACtB,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,yBAAyB,EACzB,cAAc,EACd,wBAAwB,EACxB,cAAc,GACf,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,eAAe,EACf,YAAY,EACZ,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,YAAY,EACZ,qBAAqB,GACtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,kBAAkB,GACnB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,iBAAiB,GAClB,MAAM,0BAA0B,CAAC;AAElC,mBAAmB,QAAQ,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
export { badRequest, conflict, error, forbidden, internal, noop, notFound, ok, result, unauthorized, } from "./result.js";
|
|
2
2
|
export { createResultResponder } from "./responder.js";
|
|
3
|
+
export { bootResultTracing, createResultTracer, } from "./tracer.js";
|
|
4
|
+
export { instrumentResultExports, } from "./instrument_result_exports.js";
|
|
5
|
+
export { installResultModuleHooks, } from "./module_hooks.js";
|
|
6
|
+
export { installResultProcessHooks, } from "./process_hooks.js";
|
|
3
7
|
export { DEFAULT_RESULT_PRESETS, mergeResultPresets, resolveResultPreset, } from "./presets.js";
|
|
4
8
|
export { buildResultRenderModePath, getResultLevel, normalizeResultErrorCode, toResultStatus, } from "./shared.js";
|
|
9
|
+
export { captureCallSite, compactStack, isFailedResultLike, matchTraceTarget, normalizeThrownValue, normalizeTraceLabel, previewCallArguments, previewValue, summarizeFailedResult, } from "./trace/utils.js";
|
|
10
|
+
export { wrapResultFunction, } from "./wrap/result/function.js";
|
|
11
|
+
export { wrapResultPromise, } from "./wrap/result/promise.js";
|
|
5
12
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,QAAQ,EACR,KAAK,EACL,SAAS,EACT,QAAQ,EACR,IAAI,EACJ,QAAQ,EACR,EAAE,EACF,MAAM,EACN,YAAY,GACb,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EACL,sBAAsB,EACtB,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,yBAAyB,EACzB,cAAc,EACd,wBAAwB,EACxB,cAAc,GACf,MAAM,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,QAAQ,EACR,KAAK,EACL,SAAS,EACT,QAAQ,EACR,IAAI,EACJ,QAAQ,EACR,EAAE,EACF,MAAM,EACN,YAAY,GACb,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EACL,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,uBAAuB,GACxB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,wBAAwB,GACzB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,yBAAyB,GAC1B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,sBAAsB,EACtB,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,yBAAyB,EACzB,cAAc,EACd,wBAAwB,EACxB,cAAc,GACf,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,eAAe,EACf,YAAY,EACZ,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,YAAY,EACZ,qBAAqB,GACtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,kBAAkB,GACnB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,iBAAiB,GAClB,MAAM,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { createResultTraceRuntime } from "./trace/runtime.js";
|
|
2
|
+
import type { InstrumentResultExportsOptions } from "./trace/types.js";
|
|
3
|
+
declare function instrumentResultExports<T>(target: T, options?: InstrumentResultExportsOptions): T;
|
|
4
|
+
declare function instrumentResultExportsWithRuntime<T>(runtime: ReturnType<typeof createResultTraceRuntime>, target: T, options?: InstrumentResultExportsOptions): T;
|
|
5
|
+
export { instrumentResultExports, instrumentResultExportsWithRuntime, };
|
|
6
|
+
//# sourceMappingURL=instrument_result_exports.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instrument_result_exports.d.ts","sourceRoot":"","sources":["../../src/instrument_result_exports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAqD,MAAM,oBAAoB,CAAC;AAGjH,OAAO,KAAK,EACV,8BAA8B,EAC/B,MAAM,kBAAkB,CAAC;AAE1B,iBAAS,uBAAuB,CAAC,CAAC,EAChC,MAAM,EAAE,CAAC,EACT,OAAO,GAAE,8BAAmC,GAC3C,CAAC,CAGH;AAED,iBAAS,kCAAkC,CAAC,CAAC,EAC3C,OAAO,EAAE,UAAU,CAAC,OAAO,wBAAwB,CAAC,EACpD,MAAM,EAAE,CAAC,EACT,OAAO,GAAE,8BAAmC,GAC3C,CAAC,CAIH;AA6ED,OAAO,EACL,uBAAuB,EACvB,kCAAkC,GACnC,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { createResultTraceRuntime, getCachedEntry, readTracerRuntime, setCachedEntry } from "./trace/runtime.js";
|
|
2
|
+
import { isPlainObject, matchTraceTarget, normalizeTraceLabel } from "./trace/utils.js";
|
|
3
|
+
import { wrapResultFunctionWithRuntime } from "./wrap/result/function.js";
|
|
4
|
+
function instrumentResultExports(target, options = {}) {
|
|
5
|
+
const runtime = resolveRuntime(options.tracer, options);
|
|
6
|
+
return instrumentResultExportsWithRuntime(runtime, target, options);
|
|
7
|
+
}
|
|
8
|
+
function instrumentResultExportsWithRuntime(runtime, target, options = {}) {
|
|
9
|
+
const label = normalizeTraceLabel(options.label, "trebired.result.exports");
|
|
10
|
+
const depth = resolveDepth(runtime, options.depth);
|
|
11
|
+
return instrumentValue(runtime, target, label, depth, options);
|
|
12
|
+
}
|
|
13
|
+
function instrumentValue(runtime, value, label, depth, options) {
|
|
14
|
+
if (typeof value === "function") {
|
|
15
|
+
if (!matchTraceTarget(label, options.include || runtime.config.include, options.exclude || runtime.config.exclude)) {
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
return wrapResultFunctionWithRuntime(runtime, value, {
|
|
19
|
+
...options,
|
|
20
|
+
label,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
if (!isPlainObject(value) || depth <= 0) {
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
if (!matchTraceTarget(label, undefined, options.exclude || runtime.config.exclude)) {
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
const cacheKey = `${label}:${depth}`;
|
|
30
|
+
const cached = getCachedEntry(runtime.objectCache, value, cacheKey);
|
|
31
|
+
if (cached) {
|
|
32
|
+
return cached;
|
|
33
|
+
}
|
|
34
|
+
const proxy = new Proxy(value, createProxyHandler(runtime, label, depth, options));
|
|
35
|
+
return setCachedEntry(runtime.objectCache, value, cacheKey, proxy);
|
|
36
|
+
}
|
|
37
|
+
function createProxyHandler(runtime, label, depth, options) {
|
|
38
|
+
return {
|
|
39
|
+
get(target, property, receiver) {
|
|
40
|
+
if (typeof property === "symbol" || property === "inspect") {
|
|
41
|
+
return Reflect.get(target, property, receiver);
|
|
42
|
+
}
|
|
43
|
+
const nextLabel = `${label}.${String(property)}`;
|
|
44
|
+
const current = Reflect.get(target, property, receiver);
|
|
45
|
+
return instrumentValue(runtime, current, nextLabel, depth - 1, options);
|
|
46
|
+
},
|
|
47
|
+
getOwnPropertyDescriptor(target, property) {
|
|
48
|
+
return Reflect.getOwnPropertyDescriptor(target, property);
|
|
49
|
+
},
|
|
50
|
+
ownKeys(target) {
|
|
51
|
+
return Reflect.ownKeys(target);
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function resolveDepth(runtime, depth) {
|
|
56
|
+
return typeof depth === "number" ? depth : runtime.config.objectDepth;
|
|
57
|
+
}
|
|
58
|
+
function resolveRuntime(tracer, options) {
|
|
59
|
+
return readTracerRuntime(tracer) || createResultTraceRuntime(options);
|
|
60
|
+
}
|
|
61
|
+
export { instrumentResultExports, instrumentResultExportsWithRuntime, };
|
|
62
|
+
//# sourceMappingURL=instrument_result_exports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instrument_result_exports.js","sourceRoot":"","sources":["../../src/instrument_result_exports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,cAAc,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACjH,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACxF,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAK1E,SAAS,uBAAuB,CAC9B,MAAS,EACT,UAA0C,EAAE;IAE5C,MAAM,OAAO,GAAG,cAAc,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxD,OAAO,kCAAkC,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AACtE,CAAC;AAED,SAAS,kCAAkC,CACzC,OAAoD,EACpD,MAAS,EACT,UAA0C,EAAE;IAE5C,MAAM,KAAK,GAAG,mBAAmB,CAAC,OAAO,CAAC,KAAK,EAAE,yBAAyB,CAAC,CAAC;IAC5E,MAAM,KAAK,GAAG,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IACnD,OAAO,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,CAAM,CAAC;AACtE,CAAC;AAED,SAAS,eAAe,CACtB,OAAoD,EACpD,KAAc,EACd,KAAa,EACb,KAAa,EACb,OAAuC;IAEvC,IAAI,OAAO,KAAK,KAAK,UAAU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AAQ,KAAK,SAAS,EAAE,CAAC;gBAC3D,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;YACjD,CAAC;YAED,MAAM,SAAS,GAAG,GAAG,KAAK,IAAI,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;YACjD,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;YACxD,OAAO,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC;QAC1E,CAAC;QACD,wBAAwB,CAAC,MAAM,EAAE,QAAQ;YACvC,OAAO,OAAO,CAAC,wBAAwB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QAC5D,CAAC;QACD,OAAO,CAAC,MAAM;YACZ,OAAO,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACjC,CAAC;KACF,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CACnB,OAAoD,EACpD,KAAyB;IAEzB,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC;AACxE,CAAC;AAED,SAAS,cAAc,CACrB,MAAgD,EAChD,OAAuC;IAEvC,OAAO,iBAAiB,CAAC,MAAM,CAAC,IAAI,wBAAwB,CAAC,OAAO,CAAC,CAAC;AACxE,CAAC;AAED,OAAO,EACL,uBAAuB,EACvB,kCAAkC,GACnC,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { NormalizedResultLogger, ResultLogger, ResultLoggerAdapter } from "./types.js";
|
|
2
|
+
declare function resolveLogger(logger?: ResultLogger, adapter?: ResultLoggerAdapter): NormalizedResultLogger | null;
|
|
3
|
+
export { resolveLogger, };
|
|
4
|
+
//# sourceMappingURL=logging.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logging.d.ts","sourceRoot":"","sources":["../../src/logging.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,sBAAsB,EACtB,YAAY,EACZ,mBAAmB,EACpB,MAAM,QAAQ,CAAC;AAEhB,iBAAS,aAAa,CACpB,MAAM,CAAC,EAAE,YAAY,EACrB,OAAO,CAAC,EAAE,mBAAmB,GAC5B,sBAAsB,GAAG,IAAI,CAW/B;AAED,OAAO,EACL,aAAa,GACd,CAAC"}
|
package/dist/logging.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { resolveLogger as resolveSharedLogger, } from "@trebired/logger-adapter";
|
|
2
|
+
function resolveLogger(logger, adapter) {
|
|
3
|
+
if (!logger && !adapter) {
|
|
4
|
+
return null;
|
|
5
|
+
}
|
|
6
|
+
return resolveSharedLogger({
|
|
7
|
+
adapter,
|
|
8
|
+
fallback: "console",
|
|
9
|
+
logger,
|
|
10
|
+
source: "@trebired/result",
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
export { resolveLogger, };
|
|
14
|
+
//# sourceMappingURL=logging.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logging.js","sourceRoot":"","sources":["../../src/logging.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,IAAI,mBAAmB,GACrC,MAAM,0BAA0B,CAAC;AAQlC,SAAS,aAAa,CACpB,MAAqB,EACrB,OAA6B;IAE7B,IAAI,CAAC,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;QACxB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,mBAAmB,CAAC;QACzB,OAAO;QACP,QAAQ,EAAE,SAAS;QACnB,MAAM;QACN,MAAM,EAAE,kBAAkB;KAC3B,CAA2B,CAAC;AAC/B,CAAC;AAED,OAAO,EACL,aAAa,GACd,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { createResultTraceRuntime } from "./trace/runtime.js";
|
|
2
|
+
import type { ResultHookInstallation, ResultModuleHookOptions } from "./trace/types.js";
|
|
3
|
+
declare function installResultModuleHooks(options?: ResultModuleHookOptions): ResultHookInstallation;
|
|
4
|
+
declare function installResultModuleHooksWithRuntime(runtime: ReturnType<typeof createResultTraceRuntime>, options?: ResultModuleHookOptions): ResultHookInstallation;
|
|
5
|
+
export { installResultModuleHooks, installResultModuleHooksWithRuntime, };
|
|
6
|
+
//# sourceMappingURL=module_hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module_hooks.d.ts","sourceRoot":"","sources":["../../src/module_hooks.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,wBAAwB,EAAqB,MAAM,oBAAoB,CAAC;AAEjF,OAAO,KAAK,EACV,sBAAsB,EACtB,uBAAuB,EAExB,MAAM,kBAAkB,CAAC;AAI1B,iBAAS,wBAAwB,CAC/B,OAAO,GAAE,uBAA4B,GACpC,sBAAsB,CAGxB;AAED,iBAAS,mCAAmC,CAC1C,OAAO,EAAE,UAAU,CAAC,OAAO,wBAAwB,CAAC,EACpD,OAAO,GAAE,uBAA4B,GACpC,sBAAsB,CA6CxB;AAkED,OAAO,EACL,wBAAwB,EACxB,mCAAmC,GACpC,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { instrumentResultExportsWithRuntime } from "./instrument_result_exports.js";
|
|
3
|
+
import { traceErrorWithRuntime } from "./trace/capture.js";
|
|
4
|
+
import { createResultTraceRuntime, readTracerRuntime } from "./trace/runtime.js";
|
|
5
|
+
import { matchTraceTarget, normalizeTraceLabel } from "./trace/utils.js";
|
|
6
|
+
const NodeModule = createRequire(import.meta.url)("node:module");
|
|
7
|
+
function installResultModuleHooks(options = {}) {
|
|
8
|
+
const runtime = resolveRuntime(options.tracer, options);
|
|
9
|
+
return installResultModuleHooksWithRuntime(runtime, options);
|
|
10
|
+
}
|
|
11
|
+
function installResultModuleHooksWithRuntime(runtime, options = {}) {
|
|
12
|
+
const target = options.module || NodeModule;
|
|
13
|
+
const current = runtime.moduleHooks.get(target);
|
|
14
|
+
if (current) {
|
|
15
|
+
return {
|
|
16
|
+
installed: false,
|
|
17
|
+
uninstall: current.uninstall,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
const originalLoad = target._load;
|
|
21
|
+
const patchedLoad = function patchedResultModuleLoad(request, parent, isMain) {
|
|
22
|
+
const resolved = resolveModuleTarget(target, request, parent, isMain);
|
|
23
|
+
try {
|
|
24
|
+
const loaded = originalLoad.call(this, request, parent, isMain);
|
|
25
|
+
if (!shouldInstrumentTarget(runtime, options, request, resolved)) {
|
|
26
|
+
return loaded;
|
|
27
|
+
}
|
|
28
|
+
return instrumentResultExportsWithRuntime(runtime, loaded, {
|
|
29
|
+
...options,
|
|
30
|
+
label: buildModuleLabel(options, resolved || request),
|
|
31
|
+
depth: options.depth,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
traceModuleLoadFailure(runtime, options, request, resolved, parent, error);
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
target._load = patchedLoad;
|
|
40
|
+
const uninstall = () => {
|
|
41
|
+
target._load = originalLoad;
|
|
42
|
+
runtime.moduleHooks.delete(target);
|
|
43
|
+
};
|
|
44
|
+
const installation = {
|
|
45
|
+
installed: true,
|
|
46
|
+
uninstall,
|
|
47
|
+
};
|
|
48
|
+
runtime.moduleHooks.set(target, installation);
|
|
49
|
+
return installation;
|
|
50
|
+
}
|
|
51
|
+
function shouldInstrumentTarget(runtime, options, request, resolved) {
|
|
52
|
+
const current = resolved || request;
|
|
53
|
+
return matchTraceTarget(current, options.include || runtime.config.include, options.exclude || runtime.config.exclude);
|
|
54
|
+
}
|
|
55
|
+
function traceModuleLoadFailure(runtime, options, request, resolved, parent, error) {
|
|
56
|
+
const parentId = typeof parent?.filename === "string"
|
|
57
|
+
? String(parent.filename)
|
|
58
|
+
: "";
|
|
59
|
+
const dedupeKey = `${request}:${parentId}`;
|
|
60
|
+
if (runtime.moduleFailureKeys.has(dedupeKey)) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
runtime.moduleFailureKeys.add(dedupeKey);
|
|
64
|
+
traceErrorWithRuntime(runtime, error, {
|
|
65
|
+
...options,
|
|
66
|
+
kind: "module-load",
|
|
67
|
+
label: buildModuleLabel(options, request),
|
|
68
|
+
source: resolved || request,
|
|
69
|
+
args: parentId ? [parentId] : [],
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
function buildModuleLabel(options, input) {
|
|
73
|
+
const prefix = normalizeTraceLabel(options.labelPrefix, "module");
|
|
74
|
+
return `${prefix}.${normalizeTraceLabel(input, "load")}`;
|
|
75
|
+
}
|
|
76
|
+
function resolveModuleTarget(target, request, parent, isMain) {
|
|
77
|
+
try {
|
|
78
|
+
return typeof target._resolveFilename === "function"
|
|
79
|
+
? String(target._resolveFilename(request, parent, isMain))
|
|
80
|
+
: null;
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function resolveRuntime(tracer, options) {
|
|
87
|
+
return readTracerRuntime(tracer) || createResultTraceRuntime(options);
|
|
88
|
+
}
|
|
89
|
+
export { installResultModuleHooks, installResultModuleHooksWithRuntime, };
|
|
90
|
+
//# sourceMappingURL=module_hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module_hooks.js","sourceRoot":"","sources":["../../src/module_hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAE,kCAAkC,EAAE,MAAM,gCAAgC,CAAC;AACpF,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,wBAAwB,EAAE,iBAAiB,EAA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C;AAED,OAAO,EACL,wBAAwB,EACxB,mCAAmC,GACpC,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { createResultTraceRuntime } from "./trace/runtime.js";
|
|
2
|
+
import type { ResultHookInstallation, ResultProcessHookOptions } from "./trace/types.js";
|
|
3
|
+
declare function installResultProcessHooks(options?: ResultProcessHookOptions): ResultHookInstallation;
|
|
4
|
+
declare function installResultProcessHooksWithRuntime(runtime: ReturnType<typeof createResultTraceRuntime>, options?: ResultProcessHookOptions): ResultHookInstallation;
|
|
5
|
+
export { installResultProcessHooks, installResultProcessHooksWithRuntime, };
|
|
6
|
+
//# sourceMappingURL=process_hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process_hooks.d.ts","sourceRoot":"","sources":["../../src/process_hooks.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAqB,MAAM,oBAAoB,CAAC;AACjF,OAAO,KAAK,EACV,sBAAsB,EACtB,wBAAwB,EAEzB,MAAM,kBAAkB,CAAC;AAE1B,iBAAS,yBAAyB,CAChC,OAAO,GAAE,wBAA6B,GACrC,sBAAsB,CAGxB;AAED,iBAAS,oCAAoC,CAC3C,OAAO,EAAE,UAAU,CAAC,OAAO,wBAAwB,CAAC,EACpD,OAAO,GAAE,wBAA6B,GACrC,sBAAsB,CA6CxB;AAuCD,OAAO,EACL,yBAAyB,EACzB,oCAAoC,GACrC,CAAC"}
|