@pristine-ts/common 2.0.3 → 2.0.5
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/dist/lib/cjs/contexts/event-context.js +5 -5
- package/dist/lib/cjs/contexts/event-context.js.map +1 -1
- package/dist/lib/cjs/decorators/decorators.js +1 -0
- package/dist/lib/cjs/decorators/decorators.js.map +1 -1
- package/dist/lib/cjs/decorators/traced.decorator.js +101 -0
- package/dist/lib/cjs/decorators/traced.decorator.js.map +1 -0
- package/dist/lib/cjs/enums/enums.js +1 -0
- package/dist/lib/cjs/enums/enums.js.map +1 -1
- package/dist/lib/cjs/enums/span-keyname.enum.js +34 -0
- package/dist/lib/cjs/enums/span-keyname.enum.js.map +1 -0
- package/dist/lib/cjs/errors/bad-request.error.js +15 -0
- package/dist/lib/cjs/errors/bad-request.error.js.map +1 -0
- package/dist/lib/cjs/errors/config.error.js +20 -0
- package/dist/lib/cjs/errors/config.error.js.map +1 -0
- package/dist/lib/cjs/errors/conflict.error.js +15 -0
- package/dist/lib/cjs/errors/conflict.error.js.map +1 -0
- package/dist/lib/cjs/errors/errors.js +14 -1
- package/dist/lib/cjs/errors/errors.js.map +1 -1
- package/dist/lib/cjs/errors/exit-code.enum.js +50 -0
- package/dist/lib/cjs/errors/exit-code.enum.js.map +1 -0
- package/dist/lib/cjs/errors/forbidden.error.js +15 -0
- package/dist/lib/cjs/errors/forbidden.error.js.map +1 -0
- package/dist/lib/cjs/errors/internal.error.js +19 -0
- package/dist/lib/cjs/errors/internal.error.js.map +1 -0
- package/dist/lib/cjs/errors/not-found.error.js +15 -0
- package/dist/lib/cjs/errors/not-found.error.js.map +1 -0
- package/dist/lib/cjs/errors/pristine-error-code.enum.js +37 -0
- package/dist/lib/cjs/errors/pristine-error-code.enum.js.map +1 -0
- package/dist/lib/cjs/errors/pristine-error-kind.enum.js +29 -0
- package/dist/lib/cjs/errors/pristine-error-kind.enum.js.map +1 -0
- package/dist/lib/cjs/errors/pristine-error-options.interface.js +3 -0
- package/dist/lib/cjs/errors/pristine-error-options.interface.js.map +1 -0
- package/dist/lib/cjs/errors/pristine.error.js +109 -0
- package/dist/lib/cjs/errors/pristine.error.js.map +1 -0
- package/dist/lib/cjs/errors/unauthorized.error.js +15 -0
- package/dist/lib/cjs/errors/unauthorized.error.js.map +1 -0
- package/dist/lib/cjs/errors/usage.error.js +18 -0
- package/dist/lib/cjs/errors/usage.error.js.map +1 -0
- package/dist/lib/cjs/errors/validation.error.js +15 -0
- package/dist/lib/cjs/errors/validation.error.js.map +1 -0
- package/dist/lib/cjs/interfaces/interfaces.js +1 -0
- package/dist/lib/cjs/interfaces/interfaces.js.map +1 -1
- package/dist/lib/cjs/interfaces/tracing-manager.interface.js +3 -0
- package/dist/lib/cjs/interfaces/tracing-manager.interface.js.map +1 -0
- package/dist/lib/cjs/managers/event-context.manager.js +9 -0
- package/dist/lib/cjs/managers/event-context.manager.js.map +1 -1
- package/dist/lib/cjs/models/models.js +4 -0
- package/dist/lib/cjs/models/models.js.map +1 -1
- package/dist/lib/cjs/models/span-event.model.js +28 -0
- package/dist/lib/cjs/models/span-event.model.js.map +1 -0
- package/dist/lib/cjs/models/span-lifecycle-owner.interface.js +3 -0
- package/dist/lib/cjs/models/span-lifecycle-owner.interface.js.map +1 -0
- package/dist/lib/cjs/models/span.model.js +79 -0
- package/dist/lib/cjs/models/span.model.js.map +1 -0
- package/dist/lib/cjs/models/trace.model.js +46 -0
- package/dist/lib/cjs/models/trace.model.js.map +1 -0
- package/dist/lib/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/lib/esm/contexts/event-context.js +5 -5
- package/dist/lib/esm/contexts/event-context.js.map +1 -1
- package/dist/lib/esm/decorators/decorators.js +1 -0
- package/dist/lib/esm/decorators/decorators.js.map +1 -1
- package/dist/lib/esm/decorators/traced.decorator.js +98 -0
- package/dist/lib/esm/decorators/traced.decorator.js.map +1 -0
- package/dist/lib/esm/enums/enums.js +1 -0
- package/dist/lib/esm/enums/enums.js.map +1 -1
- package/dist/lib/esm/enums/span-keyname.enum.js +31 -0
- package/dist/lib/esm/enums/span-keyname.enum.js.map +1 -0
- package/dist/lib/esm/errors/bad-request.error.js +11 -0
- package/dist/lib/esm/errors/bad-request.error.js.map +1 -0
- package/dist/lib/esm/errors/config.error.js +16 -0
- package/dist/lib/esm/errors/config.error.js.map +1 -0
- package/dist/lib/esm/errors/conflict.error.js +11 -0
- package/dist/lib/esm/errors/conflict.error.js.map +1 -0
- package/dist/lib/esm/errors/errors.js +14 -1
- package/dist/lib/esm/errors/errors.js.map +1 -1
- package/dist/lib/esm/errors/exit-code.enum.js +47 -0
- package/dist/lib/esm/errors/exit-code.enum.js.map +1 -0
- package/dist/lib/esm/errors/forbidden.error.js +11 -0
- package/dist/lib/esm/errors/forbidden.error.js.map +1 -0
- package/dist/lib/esm/errors/internal.error.js +15 -0
- package/dist/lib/esm/errors/internal.error.js.map +1 -0
- package/dist/lib/esm/errors/not-found.error.js +11 -0
- package/dist/lib/esm/errors/not-found.error.js.map +1 -0
- package/dist/lib/esm/errors/pristine-error-code.enum.js +34 -0
- package/dist/lib/esm/errors/pristine-error-code.enum.js.map +1 -0
- package/dist/lib/esm/errors/pristine-error-kind.enum.js +26 -0
- package/dist/lib/esm/errors/pristine-error-kind.enum.js.map +1 -0
- package/dist/lib/esm/errors/pristine-error-options.interface.js +2 -0
- package/dist/lib/esm/errors/pristine-error-options.interface.js.map +1 -0
- package/dist/lib/esm/errors/pristine.error.js +105 -0
- package/dist/lib/esm/errors/pristine.error.js.map +1 -0
- package/dist/lib/esm/errors/unauthorized.error.js +11 -0
- package/dist/lib/esm/errors/unauthorized.error.js.map +1 -0
- package/dist/lib/esm/errors/usage.error.js +14 -0
- package/dist/lib/esm/errors/usage.error.js.map +1 -0
- package/dist/lib/esm/errors/validation.error.js +11 -0
- package/dist/lib/esm/errors/validation.error.js.map +1 -0
- package/dist/lib/esm/interfaces/interfaces.js +1 -0
- package/dist/lib/esm/interfaces/interfaces.js.map +1 -1
- package/dist/lib/esm/interfaces/tracing-manager.interface.js +2 -0
- package/dist/lib/esm/interfaces/tracing-manager.interface.js.map +1 -0
- package/dist/lib/esm/managers/event-context.manager.js +9 -0
- package/dist/lib/esm/managers/event-context.manager.js.map +1 -1
- package/dist/lib/esm/models/models.js +4 -0
- package/dist/lib/esm/models/models.js.map +1 -1
- package/dist/lib/esm/models/span-event.model.js +24 -0
- package/dist/lib/esm/models/span-event.model.js.map +1 -0
- package/dist/lib/esm/models/span-lifecycle-owner.interface.js +2 -0
- package/dist/lib/esm/models/span-lifecycle-owner.interface.js.map +1 -0
- package/dist/lib/esm/models/span.model.js +75 -0
- package/dist/lib/esm/models/span.model.js.map +1 -0
- package/dist/lib/esm/models/trace.model.js +42 -0
- package/dist/lib/esm/models/trace.model.js.map +1 -0
- package/dist/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/types/contexts/event-context.d.ts +24 -9
- package/dist/types/decorators/decorators.d.ts +1 -0
- package/dist/types/decorators/traced.decorator.d.ts +40 -0
- package/dist/types/enums/enums.d.ts +1 -0
- package/dist/types/enums/span-keyname.enum.d.ts +29 -0
- package/dist/types/errors/bad-request.error.d.ts +8 -0
- package/dist/types/errors/config.error.d.ts +13 -0
- package/dist/types/errors/conflict.error.d.ts +8 -0
- package/dist/types/errors/errors.d.ts +14 -1
- package/dist/types/errors/exit-code.enum.d.ts +45 -0
- package/dist/types/errors/forbidden.error.d.ts +8 -0
- package/dist/types/errors/internal.error.d.ts +12 -0
- package/dist/types/errors/not-found.error.d.ts +8 -0
- package/dist/types/errors/pristine-error-code.enum.d.ts +32 -0
- package/dist/types/errors/pristine-error-kind.enum.d.ts +24 -0
- package/dist/types/errors/pristine-error-options.interface.d.ts +59 -0
- package/dist/types/errors/pristine.error.d.ts +78 -0
- package/dist/types/errors/unauthorized.error.d.ts +8 -0
- package/dist/types/errors/usage.error.d.ts +11 -0
- package/dist/types/errors/validation.error.d.ts +8 -0
- package/dist/types/interfaces/interfaces.d.ts +1 -0
- package/dist/types/interfaces/module.interface.d.ts +26 -0
- package/dist/types/interfaces/tracing-manager.interface.d.ts +78 -0
- package/dist/types/managers/event-context.manager.d.ts +4 -0
- package/dist/types/models/models.d.ts +4 -0
- package/dist/types/models/span-event.model.d.ts +30 -0
- package/dist/types/models/span-lifecycle-owner.interface.d.ts +11 -0
- package/dist/types/models/span.model.d.ts +82 -0
- package/dist/types/models/trace.model.d.ts +53 -0
- package/package.json +2 -2
- package/dist/lib/cjs/errors/loggable.error.js +0 -19
- package/dist/lib/cjs/errors/loggable.error.js.map +0 -1
- package/dist/lib/esm/errors/loggable.error.js +0 -15
- package/dist/lib/esm/errors/loggable.error.js.map +0 -1
- package/dist/types/errors/loggable.error.d.ts +0 -8
|
@@ -1,28 +1,43 @@
|
|
|
1
1
|
import { DependencyContainer } from "tsyringe";
|
|
2
|
+
import { TracingManagerInterface } from "../interfaces/tracing-manager.interface";
|
|
3
|
+
import { Trace } from "../models/trace.model";
|
|
2
4
|
/**
|
|
3
5
|
* Per-event runtime state — the framework's correlation primitives plus a handle to
|
|
4
|
-
* the per-event DI child container. Propagated implicitly via
|
|
5
|
-
* (managed by `EventContextManager`) so downstream code doesn't
|
|
6
|
-
* fields through every method signature.
|
|
6
|
+
* the per-event DI child container and the active trace. Propagated implicitly via
|
|
7
|
+
* `AsyncLocalStorage` (managed by `EventContextManager`) so downstream code doesn't
|
|
8
|
+
* have to thread these fields through every method signature.
|
|
7
9
|
*
|
|
8
10
|
* **Not to be confused with `ExecutionContextInterface` (in `@pristine-ts/core`):**
|
|
9
11
|
* - `ExecutionContext` describes *where* the framework is running (AWS Lambda, CLI,
|
|
10
12
|
* Express, etc.) — set once per `kernel.handle()` call, immutable, host-shaped.
|
|
11
13
|
* - `EventContext` describes *which specific event* is being handled — set per event
|
|
12
|
-
* in the pipeline, mutable (`traceId`
|
|
13
|
-
* shaped.
|
|
14
|
+
* in the pipeline, mutable (`traceId` / `trace` fill in once tracing starts),
|
|
15
|
+
* correlation-shaped.
|
|
14
16
|
*
|
|
15
17
|
* One `kernel.handle()` call can produce multiple events (each event mapper can return
|
|
16
18
|
* a list); each event gets its own `EventContext` instance.
|
|
17
19
|
*/
|
|
18
20
|
export declare class EventContext {
|
|
19
21
|
/** Unique id for this specific event. Same value the framework uses everywhere
|
|
20
|
-
* else as the correlation/eventId (logging,
|
|
22
|
+
* else as the correlation/eventId (logging, file tracer filenames). */
|
|
21
23
|
eventId: string;
|
|
22
24
|
/** Trace id once tracing has started. Filled in by `TracingManager.startTracing`. */
|
|
23
25
|
traceId?: string;
|
|
24
|
-
/** The
|
|
25
|
-
*
|
|
26
|
-
*
|
|
26
|
+
/** The active `Trace` for this event. Single source of truth: every `TracingManager`
|
|
27
|
+
* instance — whether resolved from the root container, a per-event child container,
|
|
28
|
+
* or anywhere else — reads and writes spans through this reference. This is what
|
|
29
|
+
* lets `addEventToCurrentSpan` from a controller find the same trace started in the
|
|
30
|
+
* kernel, even though the TracingManager instances differ across containers. */
|
|
31
|
+
trace?: Trace;
|
|
32
|
+
/** The per-event DI child container. Helpers like the LogHandler eventId fallback
|
|
33
|
+
* reach through this to resolve event-scoped services without callers having to
|
|
34
|
+
* inject them explicitly. */
|
|
27
35
|
container?: DependencyContainer;
|
|
36
|
+
/** The `TracingManager` that owns this event's trace. Set by the event pipeline
|
|
37
|
+
* alongside `trace`, read by `@traced` so spans go through the manager that started
|
|
38
|
+
* the trace rather than a fresh ContainerScoped instance from the child container.
|
|
39
|
+
* Resolving `TracingManager` via the child container would create a new instance
|
|
40
|
+
* (its lifecycle is ContainerScoped) whose `span.tracingManager = this` back-reference
|
|
41
|
+
* points at the throwaway, not the manager that owns the trace. */
|
|
42
|
+
tracingManager?: TracingManagerInterface;
|
|
28
43
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Method decorator that wraps the decorated method in a span. The span is automatically
|
|
3
|
+
* ended when the method returns or throws, and the `TracingManager` is auto-resolved
|
|
4
|
+
* from the active `EventContext` — no need to inject it manually.
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* class PaymentService {
|
|
8
|
+
* @traced() // span name = "PaymentService.charge"
|
|
9
|
+
* async charge(amount: number) { ... }
|
|
10
|
+
*
|
|
11
|
+
* @traced("payment.refund.action") // explicit name
|
|
12
|
+
* async refund(chargeId: string) { ... }
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* **Behavior outside an event context.** When the decorated method runs without an
|
|
17
|
+
* active `EventContext` (e.g. a unit test calling the method directly, or background
|
|
18
|
+
* work that escaped the event lifecycle), the decorator is a no-op — the original
|
|
19
|
+
* method runs unchanged. Tracing must never throw or alter semantics.
|
|
20
|
+
*
|
|
21
|
+
* **Sync methods become async.** The decorator awaits the wrapped method internally,
|
|
22
|
+
* so any decorated method returns a `Promise`. Decorating a sync method changes its
|
|
23
|
+
* signature visible to callers — apply `@traced` to methods you'd already be awaiting
|
|
24
|
+
* (DB calls, HTTP, expensive computations), not to tight sync helpers.
|
|
25
|
+
*
|
|
26
|
+
* **Type-level caveat.** TypeScript's parameter and method decorator types don't carry
|
|
27
|
+
* enough information for the compiler to verify that the wrapped method's return type
|
|
28
|
+
* is compatible with `Promise<T>`. The wrapper is type-safe at runtime; the call site's
|
|
29
|
+
* static types are unchanged. Pair with explicit `: Promise<T>` annotations on the
|
|
30
|
+
* method when you want the static type to match what's actually returned.
|
|
31
|
+
*
|
|
32
|
+
* **Lives in `@pristine-ts/common`** so any package can use it without taking a direct
|
|
33
|
+
* dep on `@pristine-ts/telemetry`. The actual `TracingManager` implementation still
|
|
34
|
+
* lives in telemetry; this decorator only reads the active manager from the
|
|
35
|
+
* EventContext when one is present.
|
|
36
|
+
*
|
|
37
|
+
* @param spanName Optional explicit name for the span. Defaults to
|
|
38
|
+
* `${ClassName}.${methodName}`.
|
|
39
|
+
*/
|
|
40
|
+
export declare function traced(spanName?: string): MethodDecorator;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This enum is for the different span names that are integrated in Pristine.
|
|
3
|
+
*/
|
|
4
|
+
export declare enum SpanKeynameEnum {
|
|
5
|
+
ChildContainerCreation = "child.container.creation",
|
|
6
|
+
ChildContainerRegistration = "child.container.registration",
|
|
7
|
+
ConfigurationInitialization = "configuration.initialization",
|
|
8
|
+
ErrorResponseInterceptors = "error.response.interceptors",
|
|
9
|
+
EventDispatcherResolver = "event.dispatcher.resolver",
|
|
10
|
+
EventExecution = "event.execution",
|
|
11
|
+
EventInitialization = "event.initialization",
|
|
12
|
+
EventPreMappingInterception = "event.pre-mapping.interception",
|
|
13
|
+
EventPostMappingInterception = "event.post-mapping.interception",
|
|
14
|
+
EventPreResponseMappingInterception = "event.pre-response-mapping.interception",
|
|
15
|
+
EventPostResponseMappingInterception = "event.post-response-mapping.interception",
|
|
16
|
+
EventMapping = "event.mapping",
|
|
17
|
+
KernelInitialization = "kernel.initialization",
|
|
18
|
+
ModuleInitialization = "module.initialization",
|
|
19
|
+
ModuleInitializationImportModules = "module.initialization.import.modules",
|
|
20
|
+
RequestExecution = "request.execution",
|
|
21
|
+
RequestInterceptors = "request.interceptors",
|
|
22
|
+
ResponseInterceptors = "response.interceptors",
|
|
23
|
+
RootExecution = "root.execution",
|
|
24
|
+
RouterControllerResolver = "router.controller.resolver",
|
|
25
|
+
RouterFindMethodRouterNode = "router.find.method.router.node",
|
|
26
|
+
RouterRequestAuthentication = "router.request.authentication",
|
|
27
|
+
RouterRequestExecution = "router.request.execution",
|
|
28
|
+
RouterSetup = "router.setup"
|
|
29
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PristineError } from "./pristine.error";
|
|
2
|
+
import { PristineErrorOptions } from "./pristine-error-options.interface";
|
|
3
|
+
type StandardOptions = Omit<PristineErrorOptions, "httpStatus" | "exitCode" | "kind">;
|
|
4
|
+
/** 400. Caller sent malformed/invalid input. CLI exit `ExitCode.DataError` (65). */
|
|
5
|
+
export declare class BadRequestError extends PristineError {
|
|
6
|
+
constructor(message: string, options?: StandardOptions);
|
|
7
|
+
}
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PristineError } from "./pristine.error";
|
|
2
|
+
import { PristineErrorOptions } from "./pristine-error-options.interface";
|
|
3
|
+
type StandardOptions = Omit<PristineErrorOptions, "httpStatus" | "exitCode" | "kind">;
|
|
4
|
+
/**
|
|
5
|
+
* Configuration loading / parsing / validation failure. No `httpStatus` — config errors
|
|
6
|
+
* shouldn't be exposed to HTTP callers, so the responder will treat them as 500 with
|
|
7
|
+
* sanitized message. CLI exit `ExitCode.Configuration` (78). Marked `SystemError` so the
|
|
8
|
+
* message isn't surfaced verbatim in production HTTP responses.
|
|
9
|
+
*/
|
|
10
|
+
export declare class ConfigError extends PristineError {
|
|
11
|
+
constructor(message: string, options?: StandardOptions);
|
|
12
|
+
}
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PristineError } from "./pristine.error";
|
|
2
|
+
import { PristineErrorOptions } from "./pristine-error-options.interface";
|
|
3
|
+
type StandardOptions = Omit<PristineErrorOptions, "httpStatus" | "exitCode" | "kind">;
|
|
4
|
+
/** 409. Operation conflicts with existing state (duplicate, version mismatch, etc.). */
|
|
5
|
+
export declare class ConflictError extends PristineError {
|
|
6
|
+
constructor(message: string, options?: StandardOptions);
|
|
7
|
+
}
|
|
8
|
+
export {};
|
|
@@ -1 +1,14 @@
|
|
|
1
|
-
export * from "./
|
|
1
|
+
export * from "./bad-request.error";
|
|
2
|
+
export * from "./config.error";
|
|
3
|
+
export * from "./conflict.error";
|
|
4
|
+
export * from "./exit-code.enum";
|
|
5
|
+
export * from "./forbidden.error";
|
|
6
|
+
export * from "./internal.error";
|
|
7
|
+
export * from "./not-found.error";
|
|
8
|
+
export * from "./pristine-error-code.enum";
|
|
9
|
+
export * from "./pristine-error-kind.enum";
|
|
10
|
+
export * from "./pristine-error-options.interface";
|
|
11
|
+
export * from "./pristine.error";
|
|
12
|
+
export * from "./unauthorized.error";
|
|
13
|
+
export * from "./usage.error";
|
|
14
|
+
export * from "./validation.error";
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standard process exit codes, drawn from BSD's `sysexits.h` conventions. Surfaced by
|
|
3
|
+
* `CliErrorReporter` and `PristineError.options.exitCode` so shell pipelines can branch on
|
|
4
|
+
* meaningful failure categories rather than the binary "0 or non-zero" distinction.
|
|
5
|
+
*
|
|
6
|
+
* **Use the enum for framework-standard codes.** Consumers can pass raw numbers for any
|
|
7
|
+
* custom exit code — `PristineErrorOptions.exitCode` is typed `ExitCode | number`.
|
|
8
|
+
*
|
|
9
|
+
* Note that exit codes ≥ 64 (`Usage` and above) follow the `sysexits.h` registered
|
|
10
|
+
* meanings; lower codes (1, etc.) are conventional but not standardized.
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* throw new ConfigError("Missing DATABASE_URL", {
|
|
14
|
+
* exitCode: ExitCode.Configuration, // 78 — picked up by shells aware of sysexits.h
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* throw new UsageError("Unknown flag --foo", {
|
|
18
|
+
* exitCode: ExitCode.Usage, // 64
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare enum ExitCode {
|
|
23
|
+
/** Successful termination. */
|
|
24
|
+
Success = 0,
|
|
25
|
+
/** Generic error. Default fallback for user-facing errors that don't specify a code. */
|
|
26
|
+
Error = 1,
|
|
27
|
+
/** Command-line usage error (`EX_USAGE`). Bad flags, missing required args, unknown commands. */
|
|
28
|
+
Usage = 64,
|
|
29
|
+
/** Input data malformed (`EX_DATAERR`). Validation failed, body unparseable. */
|
|
30
|
+
DataError = 65,
|
|
31
|
+
/** Internal software error (`EX_SOFTWARE`). Default fallback for system errors. */
|
|
32
|
+
Software = 70,
|
|
33
|
+
/** Can't create user output file (`EX_CANTCREAT`). */
|
|
34
|
+
Cantcreat = 73,
|
|
35
|
+
/** Input/output error (`EX_IOERR`). */
|
|
36
|
+
IoError = 74,
|
|
37
|
+
/** Temporary failure, retry might succeed (`EX_TEMPFAIL`). */
|
|
38
|
+
Temporary = 75,
|
|
39
|
+
/** Remote error in protocol (`EX_PROTOCOL`). */
|
|
40
|
+
Protocol = 76,
|
|
41
|
+
/** Permission denied (`EX_NOPERM`). Authentication / authorization failures. */
|
|
42
|
+
NoPermission = 77,
|
|
43
|
+
/** Configuration error (`EX_CONFIG`). Missing or invalid config. */
|
|
44
|
+
Configuration = 78
|
|
45
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PristineError } from "./pristine.error";
|
|
2
|
+
import { PristineErrorOptions } from "./pristine-error-options.interface";
|
|
3
|
+
type StandardOptions = Omit<PristineErrorOptions, "httpStatus" | "exitCode" | "kind">;
|
|
4
|
+
/** 403. Caller is authenticated but lacks permission. CLI exit `ExitCode.NoPermission` (77). */
|
|
5
|
+
export declare class ForbiddenError extends PristineError {
|
|
6
|
+
constructor(message?: string, options?: StandardOptions);
|
|
7
|
+
}
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PristineError } from "./pristine.error";
|
|
2
|
+
import { PristineErrorOptions } from "./pristine-error-options.interface";
|
|
3
|
+
type StandardOptions = Omit<PristineErrorOptions, "httpStatus" | "exitCode" | "kind">;
|
|
4
|
+
/**
|
|
5
|
+
* Catch-all for framework/system bugs that shouldn't be exposed verbatim. 500.
|
|
6
|
+
* CLI exit `ExitCode.Software` (70). `SystemError` triggers message sanitization in
|
|
7
|
+
* production mode.
|
|
8
|
+
*/
|
|
9
|
+
export declare class InternalError extends PristineError {
|
|
10
|
+
constructor(message?: string, options?: StandardOptions);
|
|
11
|
+
}
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PristineError } from "./pristine.error";
|
|
2
|
+
import { PristineErrorOptions } from "./pristine-error-options.interface";
|
|
3
|
+
type StandardOptions = Omit<PristineErrorOptions, "httpStatus" | "exitCode" | "kind">;
|
|
4
|
+
/** 404. Resource doesn't exist. CLI exit `ExitCode.Error` (1). */
|
|
5
|
+
export declare class NotFoundError extends PristineError {
|
|
6
|
+
constructor(message: string, options?: StandardOptions);
|
|
7
|
+
}
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standard error-code catalog used across the framework. Each value is a `SCREAMING_SNAKE_CASE`
|
|
3
|
+
* slug surfaced in the HTTP response body (`{"code": ...}`) and on CLI stderr (`✗ CODE: ...`).
|
|
4
|
+
*
|
|
5
|
+
* **Use the enum members for framework-standard cases.** Consumers can add their own
|
|
6
|
+
* domain-specific codes by passing a plain string — `PristineErrorOptions.code` is typed
|
|
7
|
+
* `PristineErrorCode | string` so both the enum and free-form strings get autocomplete-
|
|
8
|
+
* friendly type checking.
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* throw new PristineError("Token expired", {
|
|
12
|
+
* code: "TOKEN_EXPIRED", // consumer-defined code
|
|
13
|
+
* httpStatus: 401,
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* throw new PristineError("Item missing", {
|
|
17
|
+
* code: PristineErrorCode.NotFound, // framework-standard code
|
|
18
|
+
* httpStatus: 404,
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare enum PristineErrorCode {
|
|
23
|
+
BadRequest = "BAD_REQUEST",
|
|
24
|
+
Unauthorized = "UNAUTHORIZED",
|
|
25
|
+
Forbidden = "FORBIDDEN",
|
|
26
|
+
NotFound = "NOT_FOUND",
|
|
27
|
+
Conflict = "CONFLICT",
|
|
28
|
+
ValidationFailed = "VALIDATION_FAILED",
|
|
29
|
+
ConfigError = "CONFIG_ERROR",
|
|
30
|
+
UsageError = "USAGE_ERROR",
|
|
31
|
+
InternalError = "INTERNAL_ERROR"
|
|
32
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Categorizes a `PristineError` by who caused it. Replaces the older `expected: boolean`
|
|
3
|
+
* field, whose meaning ("expected by whom?") wasn't self-explanatory.
|
|
4
|
+
*
|
|
5
|
+
* The kind drives how the channel reporters render the error in production mode:
|
|
6
|
+
*
|
|
7
|
+
* - `UserError`: caller did something wrong. Message is safe to expose verbatim;
|
|
8
|
+
* structured details surface as-is. HTTP responses use the carried `httpStatus`
|
|
9
|
+
* (typically 4xx). CLI stderr shows the message and details.
|
|
10
|
+
*
|
|
11
|
+
* - `SystemError`: framework or downstream bug — not the caller's fault. In production
|
|
12
|
+
* mode the message is replaced with a generic "Internal Server Error" / "Internal Error"
|
|
13
|
+
* so internal details never leak to clients. Stack and cause chain are still logged
|
|
14
|
+
* internally via the LogHandler for operators. In development mode (`PRISTINE_ENV=dev`)
|
|
15
|
+
* the full message surfaces.
|
|
16
|
+
*
|
|
17
|
+
* Default is `UserError` — most thrown errors in framework and application code are caller-
|
|
18
|
+
* induced. `PristineError.from(unknown)` marks raw `Error` and non-Error throws as
|
|
19
|
+
* `SystemError` since they didn't opt into the typed contract.
|
|
20
|
+
*/
|
|
21
|
+
export declare enum PristineErrorKind {
|
|
22
|
+
UserError = "user-error",
|
|
23
|
+
SystemError = "system-error"
|
|
24
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { ExitCode } from "./exit-code.enum";
|
|
2
|
+
import { PristineErrorCode } from "./pristine-error-code.enum";
|
|
3
|
+
import { PristineErrorKind } from "./pristine-error-kind.enum";
|
|
4
|
+
/**
|
|
5
|
+
* Options carried by every `PristineError`. All fields optional — defaults give a sensible
|
|
6
|
+
* "user error with 500 / exit 1" shape when none are set.
|
|
7
|
+
*/
|
|
8
|
+
export interface PristineErrorOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Stable slug for the error category. Surfaces in HTTP response bodies and CLI stderr;
|
|
11
|
+
* safe to use as the join key for i18n, log queries, and alerting rules.
|
|
12
|
+
*
|
|
13
|
+
* Accepts the framework's `PristineErrorCode` enum for standard categories, or any
|
|
14
|
+
* `SCREAMING_SNAKE_CASE` string for domain-specific codes (`"TOKEN_EXPIRED"`,
|
|
15
|
+
* `"STRIPE_CARD_DECLINED"`). The enum is the catalog of well-known codes; strings are
|
|
16
|
+
* the extensibility hatch.
|
|
17
|
+
*
|
|
18
|
+
* Defaults to `PristineErrorCode.InternalError` at render time when absent.
|
|
19
|
+
*/
|
|
20
|
+
code?: PristineErrorCode | string;
|
|
21
|
+
/**
|
|
22
|
+
* HTTP status when this error reaches the HTTP boundary. Omit when the error has no
|
|
23
|
+
* natural HTTP semantics (e.g. a CLI-only `ConfigError`) — the responder will fall back
|
|
24
|
+
* to 500.
|
|
25
|
+
*/
|
|
26
|
+
httpStatus?: number;
|
|
27
|
+
/**
|
|
28
|
+
* Process exit code when this error reaches the CLI boundary. Accepts the framework's
|
|
29
|
+
* `ExitCode` enum (sysexits.h-aligned) or any raw number for custom codes. Omit to fall
|
|
30
|
+
* back to `ExitCode.Error` (1) for user errors and `ExitCode.Software` (70) for system
|
|
31
|
+
* errors.
|
|
32
|
+
*/
|
|
33
|
+
exitCode?: ExitCode | number;
|
|
34
|
+
/**
|
|
35
|
+
* Underlying error this one wraps. Uses the standard `Error.cause` slot (Node 16.9+),
|
|
36
|
+
* so any tooling that knows the standard cause chain works automatically. Walked by
|
|
37
|
+
* `PristineError.from` to preserve the original error type when normalizing.
|
|
38
|
+
*/
|
|
39
|
+
cause?: Error;
|
|
40
|
+
/**
|
|
41
|
+
* Structured fields safe to surface in the response body / stderr. Per-error-class
|
|
42
|
+
* schema — e.g. a `NotFoundError` may carry `{ resource, id }`. Surfaced to users
|
|
43
|
+
* only when `kind === UserError` (the default) or `mode === development`.
|
|
44
|
+
*/
|
|
45
|
+
details?: Record<string, unknown>;
|
|
46
|
+
/**
|
|
47
|
+
* Categorizes the error by who caused it. Drives how the message is rendered in
|
|
48
|
+
* production mode:
|
|
49
|
+
*
|
|
50
|
+
* - `UserError` (default): caller did something wrong. Message surfaced verbatim;
|
|
51
|
+
* details exposed; production responses include both.
|
|
52
|
+
*
|
|
53
|
+
* - `SystemError`: framework/system bug, not the caller's fault. Production responses
|
|
54
|
+
* replace the message with a generic "Internal Server Error" / "Internal Error" and
|
|
55
|
+
* omit details + stack. The raw error is still logged via the LogHandler for
|
|
56
|
+
* operators. `PristineError.from` marks unknown throws as `SystemError`.
|
|
57
|
+
*/
|
|
58
|
+
kind?: PristineErrorKind;
|
|
59
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { PristineErrorOptions } from "./pristine-error-options.interface";
|
|
2
|
+
/**
|
|
3
|
+
* Single error base for the entire framework. Replaces the old `LoggableError` +
|
|
4
|
+
* `HttpError` + ad-hoc subclass hierarchy.
|
|
5
|
+
*
|
|
6
|
+
* **What it gives you**:
|
|
7
|
+
* - A structured `options` bag (`code`, `httpStatus`, `exitCode`, `details`, `cause`,
|
|
8
|
+
* `kind`) read by both the HTTP and CLI channel reporters.
|
|
9
|
+
* - Automatic `error.name = ClassName` for subclasses.
|
|
10
|
+
* - Automatic prototype-chain fix via `new.target.prototype` — subclasses never need to
|
|
11
|
+
* repeat the `Object.setPrototypeOf(this, FooError.prototype)` incantation, AND
|
|
12
|
+
* `instanceof` works correctly for direct/standard-library/custom subclasses at any
|
|
13
|
+
* depth (verified by spec).
|
|
14
|
+
* - Standard `Error.cause` propagation (Node 16.9+ native).
|
|
15
|
+
*
|
|
16
|
+
* **Subclass form** when a named class makes `instanceof` checks read better:
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* export class TokenExpiredError extends UnauthorizedError {
|
|
20
|
+
* constructor(tokenId: string) {
|
|
21
|
+
* super("The token has expired", {
|
|
22
|
+
* code: "TOKEN_EXPIRED",
|
|
23
|
+
* details: { tokenId },
|
|
24
|
+
* });
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
* // ...
|
|
28
|
+
* try { ... }
|
|
29
|
+
* catch (e) { if (e instanceof TokenExpiredError) ... } // works.
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* **Direct form** when the call site self-documents:
|
|
33
|
+
*
|
|
34
|
+
* ```ts
|
|
35
|
+
* throw new PristineError(`User '${id}' not found`, {
|
|
36
|
+
* code: PristineErrorCode.NotFound,
|
|
37
|
+
* httpStatus: 404,
|
|
38
|
+
* details: { resource: "User", id },
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* **Re-throw with enrichment** when catching, adding context, and re-throwing. Use the
|
|
43
|
+
* standard `cause` chain rather than mutating the original — this preserves the original
|
|
44
|
+
* error's identity for tooling that walks `error.cause`:
|
|
45
|
+
*
|
|
46
|
+
* ```ts
|
|
47
|
+
* try { await dispatcher.dispatch(event); }
|
|
48
|
+
* catch (cause) {
|
|
49
|
+
* throw new PristineError("Event dispatch failed", {
|
|
50
|
+
* code: "EVENT_DISPATCH_FAILED",
|
|
51
|
+
* kind: PristineErrorKind.SystemError,
|
|
52
|
+
* cause,
|
|
53
|
+
* details: { eventId: event.id },
|
|
54
|
+
* });
|
|
55
|
+
* }
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare class PristineError extends Error {
|
|
59
|
+
readonly options: PristineErrorOptions;
|
|
60
|
+
constructor(message: string, options?: PristineErrorOptions);
|
|
61
|
+
/**
|
|
62
|
+
* Normalizes any thrown value into a `PristineError`. The chokepoint that every channel
|
|
63
|
+
* reporter funnels through before rendering, so the reporters never need to handle
|
|
64
|
+
* unknown shapes.
|
|
65
|
+
*
|
|
66
|
+
* - `PristineError` instances pass through unchanged.
|
|
67
|
+
* - `Error` instances are wrapped with `kind: SystemError` and propagated as `cause` —
|
|
68
|
+
* the wrapper preserves the original message and stack for `mode === Development`
|
|
69
|
+
* rendering.
|
|
70
|
+
* - Anything else (strings, numbers, `throw {someObject}`) is coerced via `String(...)`
|
|
71
|
+
* into a message with `kind: SystemError`.
|
|
72
|
+
*
|
|
73
|
+
* The standard `Error.cause` chain is preserved: if the input has a `cause`, it stays
|
|
74
|
+
* on the wrapper (which itself has the input as its cause), so a debugger walking
|
|
75
|
+
* `error.cause.cause.cause` sees the full history.
|
|
76
|
+
*/
|
|
77
|
+
static from(error: unknown): PristineError;
|
|
78
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PristineError } from "./pristine.error";
|
|
2
|
+
import { PristineErrorOptions } from "./pristine-error-options.interface";
|
|
3
|
+
type StandardOptions = Omit<PristineErrorOptions, "httpStatus" | "exitCode" | "kind">;
|
|
4
|
+
/** 401. Caller is not authenticated. CLI exit `ExitCode.NoPermission` (77). */
|
|
5
|
+
export declare class UnauthorizedError extends PristineError {
|
|
6
|
+
constructor(message?: string, options?: StandardOptions);
|
|
7
|
+
}
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PristineError } from "./pristine.error";
|
|
2
|
+
import { PristineErrorOptions } from "./pristine-error-options.interface";
|
|
3
|
+
type StandardOptions = Omit<PristineErrorOptions, "httpStatus" | "exitCode" | "kind">;
|
|
4
|
+
/**
|
|
5
|
+
* CLI-only — bad command-line usage (wrong flag, missing required arg, unknown command).
|
|
6
|
+
* No `httpStatus`. CLI exit `ExitCode.Usage` (64).
|
|
7
|
+
*/
|
|
8
|
+
export declare class UsageError extends PristineError {
|
|
9
|
+
constructor(message: string, options?: StandardOptions);
|
|
10
|
+
}
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PristineError } from "./pristine.error";
|
|
2
|
+
import { PristineErrorOptions } from "./pristine-error-options.interface";
|
|
3
|
+
type StandardOptions = Omit<PristineErrorOptions, "httpStatus" | "exitCode" | "kind">;
|
|
4
|
+
/** 422. Input parsed but failed semantic validation. CLI exit `ExitCode.DataError` (65). */
|
|
5
|
+
export declare class ValidationError extends PristineError {
|
|
6
|
+
constructor(message: string, options?: StandardOptions);
|
|
7
|
+
}
|
|
8
|
+
export {};
|
|
@@ -9,4 +9,5 @@ export * from "./module-scoped-registration.interface";
|
|
|
9
9
|
export * from "./resolver.interface";
|
|
10
10
|
export * from "./tagged-registration.interface";
|
|
11
11
|
export * from "./token-provider-registration.interface";
|
|
12
|
+
export * from "./tracing-manager.interface";
|
|
12
13
|
export * from "./value-provider-registration.interface";
|
|
@@ -25,6 +25,32 @@ export interface ModuleInterface {
|
|
|
25
25
|
* for the module.
|
|
26
26
|
*/
|
|
27
27
|
configurationDefinitions?: ConfigurationDefinition[];
|
|
28
|
+
/**
|
|
29
|
+
* Default values this module wants applied to configuration keys — typically keys owned
|
|
30
|
+
* by **other** modules. Use it when a context-providing module (e.g. `CliModule`) has an
|
|
31
|
+
* opinion about how a dependency-module's keys should be configured by default.
|
|
32
|
+
*
|
|
33
|
+
* Precedence in the resolution chain:
|
|
34
|
+
* 1. Explicit overrides passed to `kernel.start()` — beats this.
|
|
35
|
+
* 2. `pristine.config.ts:config` block — beats this.
|
|
36
|
+
* 3. **`configDefaults`** (this field).
|
|
37
|
+
* 4. The owning `configurationDefinition.defaultResolvers` chain — loses to this.
|
|
38
|
+
* 5. The owning `configurationDefinition.defaultValue` — loses to this.
|
|
39
|
+
*
|
|
40
|
+
* Not to be confused with `configurationDefinition.defaultValue`: that's the
|
|
41
|
+
* owning-module's hard fallback when nothing else fires; `configDefaults` is a
|
|
42
|
+
* different module expressing a preferred value above the resolver chain.
|
|
43
|
+
*
|
|
44
|
+
* Validation:
|
|
45
|
+
* - **Unknown key** (not declared by any module's `configurationDefinitions` in the
|
|
46
|
+
* graph) → kernel throws at boot, naming the source module + key.
|
|
47
|
+
* - **Two modules disagree** on the same key's `configDefaults` → kernel throws at
|
|
48
|
+
* registration time, naming both module keynames.
|
|
49
|
+
*
|
|
50
|
+
* Keys are configuration parameter names (e.g. `"pristine.logging.consoleLoggerOutputMode"`),
|
|
51
|
+
* not arbitrary strings.
|
|
52
|
+
*/
|
|
53
|
+
configDefaults?: Record<string, unknown>;
|
|
28
54
|
/**
|
|
29
55
|
* This function lets you run code on the module initialization. Be careful the tags and the router are not created yet.
|
|
30
56
|
* @param container
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Span } from "../models/span.model";
|
|
2
|
+
import { Trace } from "../models/trace.model";
|
|
3
|
+
/**
|
|
4
|
+
* This interface specifies what a tracing manager should implement.
|
|
5
|
+
*
|
|
6
|
+
* Lives in `@pristine-ts/common` so any package can declare a `TracingManagerInterface`
|
|
7
|
+
* dependency or use the `@traced` decorator without taking a direct dep on
|
|
8
|
+
* `@pristine-ts/telemetry`. The concrete implementation (`TracingManager`, plus the
|
|
9
|
+
* tracers that consume traces) still lives in telemetry.
|
|
10
|
+
*/
|
|
11
|
+
export interface TracingManagerInterface {
|
|
12
|
+
/**
|
|
13
|
+
* This property contains a reference to the active trace.
|
|
14
|
+
*/
|
|
15
|
+
trace?: Trace;
|
|
16
|
+
/**
|
|
17
|
+
* This methods starts the Tracing. This should be the first method called before doing anything else.
|
|
18
|
+
* @param spanRootKeyname The keyname of the span at the root.
|
|
19
|
+
* @param traceId The trace id if there is one.
|
|
20
|
+
* @param context The context if there is one.
|
|
21
|
+
*/
|
|
22
|
+
startTracing(spanRootKeyname?: string, traceId?: string, context?: {
|
|
23
|
+
[key: string]: string;
|
|
24
|
+
}): Span;
|
|
25
|
+
/**
|
|
26
|
+
* This method ends the trace entirely.
|
|
27
|
+
*/
|
|
28
|
+
endTrace(): void;
|
|
29
|
+
/**
|
|
30
|
+
* This method starts a new span.
|
|
31
|
+
* @param keyname The keyname for this new span.
|
|
32
|
+
* @param parentKeyname The keyname of the parent span.
|
|
33
|
+
* @param parentId The id of the parent span.
|
|
34
|
+
* @param context The context if there is one.
|
|
35
|
+
*/
|
|
36
|
+
startSpan(keyname: string, parentKeyname?: string, parentId?: string, context?: {
|
|
37
|
+
[key: string]: string;
|
|
38
|
+
}): Span;
|
|
39
|
+
/**
|
|
40
|
+
* This methods adds an already created Span to the trace. It assumes that it its hierarchy is correct.
|
|
41
|
+
* @param span The span to add.
|
|
42
|
+
*/
|
|
43
|
+
addSpan(span: Span): Span;
|
|
44
|
+
/**
|
|
45
|
+
* This methods ends the span by setting the end date and by calling the tracers.
|
|
46
|
+
* It will also end the trace if the rootspan is being ended.
|
|
47
|
+
* @param span The span to end.
|
|
48
|
+
*/
|
|
49
|
+
endSpan(span: Span): void;
|
|
50
|
+
/**
|
|
51
|
+
* This method ends the span using a keyname.
|
|
52
|
+
* @param keyname The keyname of the span to end.
|
|
53
|
+
*/
|
|
54
|
+
endSpanKeyname(keyname: string): void;
|
|
55
|
+
/**
|
|
56
|
+
* Attaches a named, timestamped event to the most-recently-started in-progress span.
|
|
57
|
+
* Use for noteworthy moments inside a span's lifetime that don't warrant their own
|
|
58
|
+
* child span — "validation passed", "found 50 rows", etc. Logs a warning and drops
|
|
59
|
+
* the marker if no span is currently active.
|
|
60
|
+
*/
|
|
61
|
+
addEventToCurrentSpan(message: string, attributes?: {
|
|
62
|
+
[key: string]: string;
|
|
63
|
+
}): void;
|
|
64
|
+
/**
|
|
65
|
+
* Returns the active trace's spans + their events as a flat, timestamp-sorted list.
|
|
66
|
+
* Public utility for custom tracers, debug endpoints, test helpers, or any consumer
|
|
67
|
+
* who wants "the active trace as a flat list" without walking the span tree manually.
|
|
68
|
+
* Returns an empty array when no active trace exists.
|
|
69
|
+
*/
|
|
70
|
+
getCurrentTrail(): Array<{
|
|
71
|
+
kind: "span" | "event";
|
|
72
|
+
name: string;
|
|
73
|
+
date: Date;
|
|
74
|
+
attributes: {
|
|
75
|
+
[key: string]: string;
|
|
76
|
+
};
|
|
77
|
+
}>;
|
|
78
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DependencyContainer } from "tsyringe";
|
|
2
2
|
import { EventContext } from "../contexts/event-context";
|
|
3
|
+
import { TracingManagerInterface } from "../interfaces/tracing-manager.interface";
|
|
3
4
|
/**
|
|
4
5
|
* Owns the `AsyncLocalStorage` instance that propagates the active `EventContext`
|
|
5
6
|
* across `await` boundaries, `Promise.all`, `setImmediate`, and the rest of Node's
|
|
@@ -40,6 +41,8 @@ export declare class EventContextManager {
|
|
|
40
41
|
traceId(): string | undefined;
|
|
41
42
|
/** Convenience: the per-event DI child container, or `undefined`. */
|
|
42
43
|
container(): DependencyContainer | undefined;
|
|
44
|
+
/** Convenience: the `TracingManager` that owns this event's trace, or `undefined`. */
|
|
45
|
+
tracingManager(): TracingManagerInterface | undefined;
|
|
43
46
|
/**
|
|
44
47
|
* Returns a wrapped version of `fn` that restores the current context on call. Use
|
|
45
48
|
* when you need to spawn work that escapes the natural async chain (e.g. a callback
|
|
@@ -54,5 +57,6 @@ export declare class EventContextManager {
|
|
|
54
57
|
static eventId(): string | undefined;
|
|
55
58
|
static traceId(): string | undefined;
|
|
56
59
|
static container(): DependencyContainer | undefined;
|
|
60
|
+
static tracingManager(): TracingManagerInterface | undefined;
|
|
57
61
|
static bind<F extends (...args: any[]) => any>(fn: F): F;
|
|
58
62
|
}
|