better-effect 0.11.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +544 -10
- package/dist/adapters/iti.d.mts +3 -2
- package/dist/adapters/iti.d.mts.map +1 -1
- package/dist/adapters/iti.mjs +11 -10
- package/dist/adapters/iti.mjs.map +1 -1
- package/dist/bun.d.mts +43 -0
- package/dist/bun.d.mts.map +1 -0
- package/dist/bun.mjs +40 -0
- package/dist/bun.mjs.map +1 -0
- package/dist/{context-BUEf1qjL.mjs → context-BphfFUMO.mjs} +4 -2
- package/dist/context-BphfFUMO.mjs.map +1 -0
- package/dist/current-request-CIU7AHhF.d.mts +22 -0
- package/dist/current-request-CIU7AHhF.d.mts.map +1 -0
- package/dist/current-request-DDKNyymv.mjs +20 -0
- package/dist/current-request-DDKNyymv.mjs.map +1 -0
- package/dist/disposable-CP-Q2H3l.mjs +57 -0
- package/dist/disposable-CP-Q2H3l.mjs.map +1 -0
- package/dist/{effect-2ZcGZI8A.mjs → effect-CPdV7Yv8.mjs} +56 -10
- package/dist/effect-CPdV7Yv8.mjs.map +1 -0
- package/dist/hono.d.mts +7 -5
- package/dist/hono.d.mts.map +1 -1
- package/dist/hono.mjs +88 -30
- package/dist/hono.mjs.map +1 -1
- package/dist/{index-heuaRmXR.d.mts → index-AiKM71-u.d.mts} +3 -1
- package/dist/{index-heuaRmXR.d.mts.map → index-AiKM71-u.d.mts.map} +1 -1
- package/dist/index-BodMy6rO.d.mts +180 -0
- package/dist/index-BodMy6rO.d.mts.map +1 -0
- package/dist/{index-C7Qild0_.d.mts → index-CCi07kUw.d.mts} +15 -151
- package/dist/index-CCi07kUw.d.mts.map +1 -0
- package/dist/index-DAKn0qHk.d.mts +19 -0
- package/dist/index-DAKn0qHk.d.mts.map +1 -0
- package/dist/{index-DStz0JMN.d.mts → index-cXgyMa0v.d.mts} +75 -22
- package/dist/index-cXgyMa0v.d.mts.map +1 -0
- package/dist/index.d.mts +7 -4
- package/dist/index.mjs +8 -6
- package/dist/index.mjs.map +1 -1
- package/dist/{internal-identity-DmUpBeeL.mjs → internal-identity-CbXoZIfw.mjs} +3 -3
- package/dist/internal-identity-CbXoZIfw.mjs.map +1 -0
- package/dist/{signal-B97cs85Z.mjs → layer-D16GKxuX.mjs} +31 -112
- package/dist/layer-D16GKxuX.mjs.map +1 -0
- package/dist/next.d.mts +116 -0
- package/dist/next.d.mts.map +1 -0
- package/dist/next.mjs +68 -0
- package/dist/next.mjs.map +1 -0
- package/dist/node-context-Ca18oNSg.mjs +25 -0
- package/dist/node-context-Ca18oNSg.mjs.map +1 -0
- package/dist/node-context-DczjAcrX.d.mts +12 -0
- package/dist/node-context-DczjAcrX.d.mts.map +1 -0
- package/dist/node.d.mts +51 -0
- package/dist/node.d.mts.map +1 -0
- package/dist/node.mjs +233 -0
- package/dist/node.mjs.map +1 -0
- package/dist/observer-9nhbL7Pr.d.mts +68 -0
- package/dist/observer-9nhbL7Pr.d.mts.map +1 -0
- package/dist/opentelemetry.d.mts +94 -0
- package/dist/opentelemetry.d.mts.map +1 -0
- package/dist/opentelemetry.mjs +453 -0
- package/dist/opentelemetry.mjs.map +1 -0
- package/dist/{index-rQhZk3Nt.d.mts → outcome-DI8LPIQ4.d.mts} +27 -72
- package/dist/outcome-DI8LPIQ4.d.mts.map +1 -0
- package/dist/{scope-GGnmTQck.mjs → program-metadata-BxjGkT17.mjs} +19 -4
- package/dist/program-metadata-BxjGkT17.mjs.map +1 -0
- package/dist/registration-drnZk0SY.mjs +182 -0
- package/dist/registration-drnZk0SY.mjs.map +1 -0
- package/dist/runtime/explicit.d.mts +1 -1
- package/dist/runtime/explicit.mjs +1 -1
- package/dist/runtime/node.d.mts +3 -12
- package/dist/runtime/node.mjs +2 -24
- package/dist/{runtime-DnMn0X0X.mjs → runtime-C_55ofnL.mjs} +245 -67
- package/dist/runtime-C_55ofnL.mjs.map +1 -0
- package/dist/signal-nfgFyNCk.mjs +52 -0
- package/dist/signal-nfgFyNCk.mjs.map +1 -0
- package/dist/{standard-services-BFBq-4lo.mjs → standard-services-vnGIafkS.mjs} +200 -30
- package/dist/standard-services-vnGIafkS.mjs.map +1 -0
- package/dist/standard-services.d.mts +4 -3
- package/dist/standard-services.mjs +4 -3
- package/dist/testing.d.mts +67 -7
- package/dist/testing.d.mts.map +1 -1
- package/dist/testing.mjs +192 -9
- package/dist/testing.mjs.map +1 -1
- package/dist/types-oihI-ESv.d.mts +54 -0
- package/dist/types-oihI-ESv.d.mts.map +1 -0
- package/dist/web-Bq3MfMrj.mjs +147 -0
- package/dist/web-Bq3MfMrj.mjs.map +1 -0
- package/dist/web.d.mts +47 -0
- package/dist/web.d.mts.map +1 -0
- package/dist/web.mjs +2 -0
- package/package.json +39 -3
- package/dist/context-BUEf1qjL.mjs.map +0 -1
- package/dist/effect-2ZcGZI8A.mjs.map +0 -1
- package/dist/errors-Dnjhzbt0.mjs +0 -99
- package/dist/errors-Dnjhzbt0.mjs.map +0 -1
- package/dist/index-C7Qild0_.d.mts.map +0 -1
- package/dist/index-DStz0JMN.d.mts.map +0 -1
- package/dist/index-rQhZk3Nt.d.mts.map +0 -1
- package/dist/internal-identity-DmUpBeeL.mjs.map +0 -1
- package/dist/runtime/node.d.mts.map +0 -1
- package/dist/runtime/node.mjs.map +0 -1
- package/dist/runtime-DnMn0X0X.mjs.map +0 -1
- package/dist/scope-GGnmTQck.mjs.map +0 -1
- package/dist/signal-B97cs85Z.mjs.map +0 -1
- package/dist/standard-services-BFBq-4lo.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next.mjs","names":[],"sources":["../src/next/next-effect.ts"],"sourcesContent":["/* oxlint-disable anti-slop/no-object-parameters -- the private boundary erases arbitrary framework context types after public overload validation. */\n/* oxlint-disable anti-slop/no-unknown-parameters -- response policy values are opaque until WebEffect validates them. */\n/* oxlint-disable anti-slop/no-unsafe-dictionary-type -- the private WebEffect options object is populated only by checked policies. */\n\nimport { Result } from 'better-result'\n\nimport { Effect } from '../effect'\nimport type { EffectSuccess, EffectYield, ProgramFromGenerator } from '../effect/types'\nimport type { LayerInput } from '../layer/inference'\nimport type { Runtime } from '../runtime'\nimport type { AnyService } from '../service'\nimport { WebEffect } from '../web'\nimport type {\n AnyProgram,\n AnyResult,\n DefaultRequestLayer,\n GeneratorBody,\n NextEffectContext,\n NextEffectOptions,\n NextEffectParams,\n NextEffectRouteOptions,\n NextGeneratorChecks,\n CompleteNextProgram,\n NextHandlerFactory,\n NextRequestLayerChecks,\n NextRouteHandler\n} from './types'\n\nconst routeSuccessPolicyNames = ['respond', 'serialize', 'onSuccess'] as const\n\nconst assertExclusiveRouteSuccessPolicy = (\n options: NextEffectRouteOptions<unknown, object>\n): void => {\n const configuredPolicies = routeSuccessPolicyNames.filter((name) => options[name] !== undefined)\n\n if (configuredPolicies.length > 1) {\n throw new TypeError(\n `NextEffect route options must configure at most one success policy; received ${configuredPolicies.join(', ')}`\n )\n }\n}\n\n/** Run Result-valued Programs inside one Runtime boundary per Next request. */\nexport class NextEffect<\n Provided extends AnyService = AnyService,\n Failure = unknown,\n RequestLayer extends LayerInput = DefaultRequestLayer,\n Context extends object = NextEffectContext\n> {\n readonly runtime: Runtime<Provided>\n\n private readonly onSuccess: NextEffectOptions<Failure, RequestLayer, Context>['onSuccess']\n\n private readonly onFailure: NextEffectOptions<Failure, RequestLayer, Context>['onFailure']\n\n private readonly requestLayer: NextEffectOptions<Failure, RequestLayer, Context>['requestLayer']\n\n private constructor(\n runtime: Runtime<Provided>,\n options: NextEffectOptions<Failure, RequestLayer, Context>\n ) {\n this.runtime = runtime\n this.onSuccess = options.onSuccess\n this.onFailure = options.onFailure\n this.requestLayer = options.requestLayer\n }\n\n /** Bind an application-owned Runtime to App Router Route Handler factories. */\n static make<\n Provided extends AnyService,\n Failure = unknown,\n RequestLayer extends LayerInput = DefaultRequestLayer,\n Context extends object = NextEffectContext\n >(\n runtime: Runtime<Provided>,\n options?: NextEffectOptions<Failure, RequestLayer, Context> &\n NextRequestLayerChecks<Provided, RequestLayer>\n ): NextEffect<Provided, Failure, RequestLayer, Context> {\n return new NextEffect(runtime, options ?? {})\n }\n\n /** Create a native Route Handler from an explicit Request/context Program factory. */\n handler<Program extends AnyProgram>(\n makeProgram: (\n request: Request,\n context: Context\n ) => CompleteNextProgram<Provided, RequestLayer, Program, Failure>,\n options?: NextEffectRouteOptions<EffectSuccess<Program>, Context>\n ): NextRouteHandler<Context>\n handler<\n const HandlerContext extends object,\n const ProgramFactory extends (request: Request, context: HandlerContext) => AnyProgram\n >(\n makeProgram: NextHandlerFactory<\n HandlerContext,\n Provided,\n RequestLayer,\n Failure,\n ProgramFactory\n >,\n options?: NextEffectRouteOptions<EffectSuccess<ReturnType<ProgramFactory>>, HandlerContext>\n ): NextRouteHandler<HandlerContext>\n handler(...args: unknown[]): NextRouteHandler<object> {\n // SAFETY: The public overloads restrict the first argument to a checked Program factory.\n const makeProgram = args[0] as (request: Request, context: object) => AnyProgram\n // SAFETY: The public overloads restrict the optional second argument to route options.\n const options = (args[1] ?? {}) as NextEffectRouteOptions<unknown, object>\n\n return this.makeHandler(makeProgram, options)\n }\n\n /** Create a native Route Handler from a Request/context generator body. */\n gen<\n const HandlerContext extends object = Context,\n const Yield extends EffectYield = EffectYield,\n const Returned extends AnyResult = AnyResult\n >(\n body: GeneratorBody<HandlerContext, Yield, Returned> &\n NextGeneratorChecks<Provided, RequestLayer, Yield, Returned, Failure>,\n options?: NextEffectRouteOptions<\n EffectSuccess<ProgramFromGenerator<Yield, Returned>>,\n HandlerContext\n >\n ): NextRouteHandler<HandlerContext>\n gen<\n const CustomContext extends object,\n const CustomYield extends EffectYield,\n const CustomReturned extends AnyResult\n >(\n body: GeneratorBody<CustomContext, CustomYield, CustomReturned> &\n NextGeneratorChecks<Provided, RequestLayer, CustomYield, CustomReturned, Failure>,\n options?: NextEffectRouteOptions<\n EffectSuccess<ProgramFromGenerator<CustomYield, CustomReturned>>,\n CustomContext\n >\n ): NextRouteHandler<CustomContext>\n gen(...args: unknown[]): NextRouteHandler<object> {\n // SAFETY: The public overloads restrict the first argument to a checked generator body.\n const body = args[0] as GeneratorBody<object, EffectYield, AnyResult>\n // SAFETY: The public overloads restrict the optional second argument to route options.\n const options = (args[1] ?? {}) as NextEffectRouteOptions<unknown, object>\n\n return this.makeHandler((request, context) => {\n // SAFETY: Effect.fn accepts the sync or async generator supplied by the public overload.\n const program = Effect.fn(\n // SAFETY: The public overloads accept both sync and async generator bodies; the runtime invokes the resulting Program asynchronously.\n () => body(request, context) as AsyncGenerator<EffectYield, AnyResult, unknown>\n )\n\n // SAFETY: The public overloads validate the generator's Result, failure, and Service channels.\n return program as AnyProgram\n }, options)\n }\n\n private makeHandler(\n makeProgram: (request: Request, context: object) => AnyProgram,\n routeOptions: NextEffectRouteOptions<unknown, object>\n ): NextRouteHandler<object> {\n assertExclusiveRouteSuccessPolicy(routeOptions)\n\n return async (request, context) => {\n const program = makeProgram(request, context)\n const shouldSerialize = routeOptions.serialize !== undefined\n const effectiveProgram = shouldSerialize\n ? async () => {\n const result = await program()\n\n if (Result.isError(result)) {\n return result\n }\n\n return Result.ok(routeOptions.serialize!(result.value, request, context))\n }\n : program\n const webOptions: Record<string, unknown> = {}\n\n if (this.requestLayer !== undefined) {\n // SAFETY: The public handler overloads pair this runtime context with the configured Context type.\n webOptions.requestLayer = () => this.requestLayer!(request, context as Context)\n }\n\n if (routeOptions.respond !== undefined) {\n webOptions.onSuccess = ({ value }: { readonly value: unknown }) =>\n routeOptions.respond!(value, request, context)\n } else if (routeOptions.onSuccess !== undefined) {\n webOptions.onSuccess = (result: { readonly value: unknown }) =>\n routeOptions.onSuccess!(result, request, context)\n } else if (this.onSuccess !== undefined) {\n webOptions.onSuccess = (result: { readonly value: unknown }) => {\n // SAFETY: The public handler overloads pair this runtime context with the configured Context type.\n return this.onSuccess!(result, request, context as Context)\n }\n }\n\n if (this.onFailure !== undefined) {\n webOptions.onFailure = (error: unknown) => {\n // SAFETY: Runtime WebEffect failures are the checked Failure channel of the route Program.\n return this.onFailure!(error as Failure, request, context as Context)\n }\n }\n\n // SAFETY: Public overloads validate the Program, request Layer, Failure, and Response policy before this erased WebEffect call.\n return await WebEffect.handle(\n // SAFETY: The Runtime's concrete Service union is intentionally erased for WebEffect's internal heterogeneous boundary.\n // oxlint-disable-next-line anti-slop/no-chained-type-assertions -- this is the adapter's single generic erasure.\n this.runtime as unknown as Runtime<AnyService>,\n request,\n // SAFETY: The effective Program is either the checked Program or a private serializer wrapper that preserves its Result error channel.\n effectiveProgram as AnyProgram,\n // SAFETY: The erased WebEffect options are built exclusively from the validated route policies above.\n webOptions as never\n )\n }\n }\n}\n\nexport declare namespace NextEffect {\n /** Options shared by all handlers created from a bound Runtime. */\n export type Options<\n Failure = unknown,\n RequestLayer extends LayerInput = DefaultRequestLayer,\n Context extends object = NextEffectContext\n > = NextEffectOptions<Failure, RequestLayer, Context>\n\n /** A typed per-route success policy. */\n export type RouteOptions<A, Context extends object = NextEffectContext> = NextEffectRouteOptions<\n A,\n Context\n >\n\n /** The explicit App Router context passed to route factories. */\n export type Context<Params extends object = NextEffectParams> = NextEffectContext<Params>\n\n /** The native handler returned by `handler` and `gen`. */\n export type Handler<Context extends object = NextEffectContext> = NextRouteHandler<Context>\n}\n"],"mappings":";;;;AA4BA,MAAM,0BAA0B;CAAC;CAAW;CAAa;AAAW;AAEpE,MAAM,qCACJ,YACS;CACT,MAAM,qBAAqB,wBAAwB,QAAQ,SAAS,QAAQ,UAAU,KAAA,CAAS;CAE/F,IAAI,mBAAmB,SAAS,GAC9B,MAAM,IAAI,UACR,gFAAgF,mBAAmB,KAAK,IAAI,GAC9G;AAEJ;;AAGA,IAAa,aAAb,MAAa,WAKX;CACA;CAEA;CAEA;CAEA;CAEA,YACE,SACA,SACA;EACA,KAAK,UAAU;EACf,KAAK,YAAY,QAAQ;EACzB,KAAK,YAAY,QAAQ;EACzB,KAAK,eAAe,QAAQ;CAC9B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;GACtE;GAIF,OAAO,MAAM,UAAU,OAGrB,KAAK,SACL,SAEA,kBAEA,UACF;EACF;CACF;AACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { f as setRuntimeContextFrameCarrier, h as RuntimeContextNotConfiguredError, m as withActiveRuntimeContextStorage, r as currentRuntimeContextFrame } from "./context-BphfFUMO.mjs";
|
|
2
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
3
|
+
//#region src/runtime/node-context.ts
|
|
4
|
+
const asyncLocalStorage = new AsyncLocalStorage();
|
|
5
|
+
setRuntimeContextFrameCarrier({
|
|
6
|
+
run: (frame, program) => asyncLocalStorage.run(frame, program),
|
|
7
|
+
current: () => asyncLocalStorage.getStore()
|
|
8
|
+
});
|
|
9
|
+
/** RuntimeContextStorage backed by Node/Bun async context propagation. */
|
|
10
|
+
var NodeRuntimeContextStorage = class {
|
|
11
|
+
run(context, program) {
|
|
12
|
+
return withActiveRuntimeContextStorage(this, context, program);
|
|
13
|
+
}
|
|
14
|
+
current() {
|
|
15
|
+
const frame = currentRuntimeContextFrame();
|
|
16
|
+
if (!frame || frame.storage !== this) throw new RuntimeContextNotConfiguredError();
|
|
17
|
+
return frame.context;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
/** Shared Node/Bun storage used by the compatibility APIs and default Runtime. */
|
|
21
|
+
const nodeRuntimeContextStorage = new NodeRuntimeContextStorage();
|
|
22
|
+
//#endregion
|
|
23
|
+
export { nodeRuntimeContextStorage as n, NodeRuntimeContextStorage as t };
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=node-context-Ca18oNSg.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-context-Ca18oNSg.mjs","names":[],"sources":["../src/runtime/node-context.ts"],"sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks'\n\nimport { RuntimeContextNotConfiguredError } from './errors'\n\nimport {\n currentRuntimeContextFrame,\n setRuntimeContextFrameCarrier,\n withActiveRuntimeContextStorage\n} from './context'\n\nimport type {\n ActiveRuntimeContextFrame,\n RuntimeContext,\n RuntimeContextFrameCarrier,\n RuntimeContextStorage\n} from './context'\n\nconst asyncLocalStorage = new AsyncLocalStorage<ActiveRuntimeContextFrame>()\n\nconst frameCarrier: RuntimeContextFrameCarrier = {\n run: (frame, program) => asyncLocalStorage.run(frame, program),\n current: () => asyncLocalStorage.getStore()\n}\n\nsetRuntimeContextFrameCarrier(frameCarrier)\n\n/** RuntimeContextStorage backed by Node/Bun async context propagation. */\nexport class NodeRuntimeContextStorage implements RuntimeContextStorage {\n run<A>(context: RuntimeContext, program: () => A): A {\n return withActiveRuntimeContextStorage(this, context, program)\n }\n\n current(): RuntimeContext {\n const frame = currentRuntimeContextFrame()\n\n if (!frame || frame.storage !== this) {\n throw new RuntimeContextNotConfiguredError()\n }\n\n return frame.context\n }\n}\n\n/** Shared Node/Bun storage used by the compatibility APIs and default Runtime. */\nexport const nodeRuntimeContextStorage = new NodeRuntimeContextStorage()\n\nexport { RuntimeContextNotConfiguredError } from './errors'\n\nexport type { RuntimeContext, RuntimeContextStorage } from './context'\n"],"mappings":";;;AAiBA,MAAM,oBAAoB,IAAI,kBAA6C;AAO3E,8BAA8B;CAJ5B,MAAM,OAAO,YAAY,kBAAkB,IAAI,OAAO,OAAO;CAC7D,eAAe,kBAAkB,SAAS;AAGH,CAAC;;AAG1C,IAAa,4BAAb,MAAwE;CACtE,IAAO,SAAyB,SAAqB;EACnD,OAAO,gCAAgC,MAAM,SAAS,OAAO;CAC/D;CAEA,UAA0B;EACxB,MAAM,QAAQ,2BAA2B;EAEzC,IAAI,CAAC,SAAS,MAAM,YAAY,MAC9B,MAAM,IAAI,iCAAiC;EAG7C,OAAO,MAAM;CACf;AACF;;AAGA,MAAa,4BAA4B,IAAI,0BAA0B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { c as RuntimeContextStorage, s as RuntimeContext } from "./index-AiKM71-u.mjs";
|
|
2
|
+
//#region src/runtime/node-context.d.ts
|
|
3
|
+
/** RuntimeContextStorage backed by Node/Bun async context propagation. */
|
|
4
|
+
declare class NodeRuntimeContextStorage implements RuntimeContextStorage {
|
|
5
|
+
run<A>(context: RuntimeContext, program: () => A): A;
|
|
6
|
+
current(): RuntimeContext;
|
|
7
|
+
}
|
|
8
|
+
/** Shared Node/Bun storage used by the compatibility APIs and default Runtime. */
|
|
9
|
+
declare const nodeRuntimeContextStorage: NodeRuntimeContextStorage;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { nodeRuntimeContextStorage as n, NodeRuntimeContextStorage as t };
|
|
12
|
+
//# sourceMappingURL=node-context-DczjAcrX.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-context-DczjAcrX.d.mts","names":[],"sources":["../src/runtime/node-context.ts"],"mappings":";;;cA2Ba,qCAAqC;EAChD,IAAI,GAAG,SAAS,gBAAgB,eAAe,IAAI;EAInD,WAAW;;;cAYA,2BAAyB"}
|
package/dist/node.d.mts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { C as EffectError, E as EffectSuccess, c as RuntimeContextStorage, s as RuntimeContext } from "./index-AiKM71-u.mjs";
|
|
2
|
+
import { _ as CompleteInput, d as LayerBackend, h as CompleteExecution, r as RuntimeOptions, w as ProvidedEnvironment, y as LayerInput } from "./outcome-DI8LPIQ4.mjs";
|
|
3
|
+
import { t as RuntimeContextNotConfiguredError } from "./errors-BKcsQ0ip.mjs";
|
|
4
|
+
import "./index-CCi07kUw.mjs";
|
|
5
|
+
import { n as nodeRuntimeContextStorage, t as NodeRuntimeContextStorage } from "./node-context-DczjAcrX.mjs";
|
|
6
|
+
import { Result } from "better-result";
|
|
7
|
+
//#region src/runtime/node-runtime.d.ts
|
|
8
|
+
/** Process signals supported by the Node.js/Bun process boundary. */
|
|
9
|
+
type NodeRuntimeSignal = 'SIGINT' | 'SIGTERM';
|
|
10
|
+
/** Translate a successful main result to a process exit code. */
|
|
11
|
+
type NodeRuntimeSuccessHandler<Success> = (value: Success) => number;
|
|
12
|
+
/** Translate a typed main failure to a process exit code. */
|
|
13
|
+
type NodeRuntimeFailureHandler<Failure> = (error: Failure) => number;
|
|
14
|
+
/** Observe a thrown or rejected main defect while it remains a rejected Promise. */
|
|
15
|
+
type NodeRuntimeDefectHandler = (cause: unknown) => number | void;
|
|
16
|
+
/** Options for the Node.js/Bun process boundary. */
|
|
17
|
+
type NodeRuntimeOptions<Success = unknown, Failure = unknown> = RuntimeOptions & {
|
|
18
|
+
/** Process signals that request cooperative shutdown. Defaults to SIGINT and SIGTERM. */
|
|
19
|
+
readonly signals?: readonly NodeRuntimeSignal[];
|
|
20
|
+
/** Map a nominal Result.ok value, or a plain successful value, to an exit code. */
|
|
21
|
+
readonly onSuccess?: NodeRuntimeSuccessHandler<Success>;
|
|
22
|
+
/** Map a nominal Result.err error to an exit code. */
|
|
23
|
+
readonly onFailure?: NodeRuntimeFailureHandler<Failure>;
|
|
24
|
+
/** Observe a defect. Defects are rethrown after the handler runs. */
|
|
25
|
+
readonly onDefect?: NodeRuntimeDefectHandler;
|
|
26
|
+
};
|
|
27
|
+
type NonResultMainSuccess<Value> = Value extends Result<any, any> ? never : Value;
|
|
28
|
+
type PlainMainSuccess<Value> = NonResultMainSuccess<Awaited<Value>>;
|
|
29
|
+
type MainSuccess<Value> = EffectSuccess<Value> | PlainMainSuccess<Value>;
|
|
30
|
+
type MainFailure<Value> = EffectError<Value>;
|
|
31
|
+
type MainOptions<Value> = NodeRuntimeOptions<MainSuccess<Value>, MainFailure<Value>>;
|
|
32
|
+
/** Node.js/Bun process lifecycle helpers. */
|
|
33
|
+
declare class NodeRuntime {
|
|
34
|
+
/**
|
|
35
|
+
* Run a typed main Program, translate its final result to `process.exitCode`,
|
|
36
|
+
* and dispose the Runtime when the program or a configured process signal settles.
|
|
37
|
+
*/
|
|
38
|
+
static runMain<A, L extends LayerInput>(layer: L & CompleteInput<L>, backend: LayerBackend, program: CompleteExecution<ProvidedEnvironment<L>, A>, options?: MainOptions<A>): Promise<Awaited<A>>;
|
|
39
|
+
static runMain<A, L extends LayerInput>(layer: L & CompleteInput<L>, program: CompleteExecution<ProvidedEnvironment<L>, A>, options?: MainOptions<A>): Promise<Awaited<A>>;
|
|
40
|
+
static runMain<A, L extends LayerInput>(layer: L & CompleteInput<L>, options: MainOptions<A>, program: CompleteExecution<ProvidedEnvironment<L>, A>): Promise<Awaited<A>>;
|
|
41
|
+
}
|
|
42
|
+
/** Type-level aliases for the Node.js/Bun process boundary. */
|
|
43
|
+
declare namespace NodeRuntime {
|
|
44
|
+
/** Options for `NodeRuntime.runMain`. */
|
|
45
|
+
type Options<Success = unknown, Failure = unknown> = NodeRuntimeOptions<Success, Failure>;
|
|
46
|
+
/** A process signal accepted by `NodeRuntime.runMain`. */
|
|
47
|
+
type Signal = NodeRuntimeSignal;
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
export { NodeRuntime, NodeRuntimeContextStorage, type NodeRuntimeDefectHandler, type NodeRuntimeFailureHandler, type NodeRuntimeOptions, type NodeRuntimeSignal, type NodeRuntimeSuccessHandler, type RuntimeContext, RuntimeContextNotConfiguredError, type RuntimeContextStorage, nodeRuntimeContextStorage };
|
|
51
|
+
//# sourceMappingURL=node.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.d.mts","names":[],"sources":["../src/runtime/node-runtime.ts"],"mappings":";;;;;;;;KAoBY;;KAGA,0BAA0B,YAAY,OAAO;;KAG7C,0BAA0B,YAAY,OAAO;;KAG7C,4BAA4B;;KAG5B,mBAAmB,mBAAmB,qBAAqB;;WAE5D,mBAAmB;;WAEnB,YAAY,0BAA0B;;WAEtC,YAAY,0BAA0B;;WAEtC,WAAW;;KAGjB,qBAAqB,SAAS,cAAc,2BAA+B;KAE3E,iBAAiB,SAAS,qBAAqB,QAAQ;KAEvD,YAAY,SAAS,cAAc,SAAS,iBAAiB;KAE7D,YAAY,SAAS,YAAY;KAEjC,YAAY,SAAS,mBAAmB,YAAY,QAAQ,YAAY;;cAqMhE;;;;;SAKJ,QAAQ,GAAG,UAAU,YAC1B,OAAO,IAAI,cAAc,IACzB,SAAS,cACT,SAAS,kBAAkB,oBAAoB,IAAI,IACnD,UAAU,YAAY,KACrB,QAAQ,QAAQ;SAEZ,QAAQ,GAAG,UAAU,YAC1B,OAAO,IAAI,cAAc,IACzB,SAAS,kBAAkB,oBAAoB,IAAI,IACnD,UAAU,YAAY,KACrB,QAAQ,QAAQ;SAEZ,QAAQ,GAAG,UAAU,YAC1B,OAAO,IAAI,cAAc,IACzB,SAAS,YAAY,IACrB,SAAS,kBAAkB,oBAAoB,IAAI,KAClD,QAAQ,QAAQ;;;kBA8NI;;OAEX,QAAQ,mBAAmB,qBAAqB,mBAAmB,SAAS;;OAG5E,SAAS"}
|
package/dist/node.mjs
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { h as RuntimeContextNotConfiguredError } from "./context-BphfFUMO.mjs";
|
|
2
|
+
import { n as nodeRuntimeContextStorage, t as NodeRuntimeContextStorage } from "./node-context-Ca18oNSg.mjs";
|
|
3
|
+
import { t as Runtime } from "./runtime-C_55ofnL.mjs";
|
|
4
|
+
import { n as linkAbortSignals } from "./signal-nfgFyNCk.mjs";
|
|
5
|
+
import { Err, Ok } from "better-result";
|
|
6
|
+
//#region src/runtime/node-runtime.ts
|
|
7
|
+
const DEFAULT_SIGNALS = ["SIGINT", "SIGTERM"];
|
|
8
|
+
const isLayerBackend = (value) => {
|
|
9
|
+
if (value === null || typeof value !== "object") return false;
|
|
10
|
+
return "register" in value && "resolve" in value && "disposeAll" in value && typeof value.register === "function" && typeof value.resolve === "function" && typeof value.disposeAll === "function";
|
|
11
|
+
};
|
|
12
|
+
const isAbortSignal = (value) => {
|
|
13
|
+
if (value === null || typeof value !== "object") return false;
|
|
14
|
+
return typeof value.aborted === "boolean" && typeof value.addEventListener === "function" && typeof value.removeEventListener === "function";
|
|
15
|
+
};
|
|
16
|
+
const isOptionsObject = (value) => {
|
|
17
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
18
|
+
};
|
|
19
|
+
const validateExitCode = (code) => {
|
|
20
|
+
if (!Number.isSafeInteger(code) || code < 0) throw new RangeError("NodeRuntime exit codes must be non-negative safe integers");
|
|
21
|
+
return code;
|
|
22
|
+
};
|
|
23
|
+
const ensureFailureExitCode = (code) => code === 0 ? 1 : code;
|
|
24
|
+
const validateSignals = (signals) => {
|
|
25
|
+
if (signals !== void 0 && !Array.isArray(signals)) throw new TypeError("NodeRuntime signals must be an array of supported signal names");
|
|
26
|
+
for (const signal of signals ?? DEFAULT_SIGNALS) if (typeof signal !== "string" || signal !== "SIGINT" && signal !== "SIGTERM") throw new RangeError(`NodeRuntime signal "${String(signal)}" is not supported`);
|
|
27
|
+
};
|
|
28
|
+
const validateRuntimeOptions = (options) => {
|
|
29
|
+
if (options.signal !== void 0 && !isAbortSignal(options.signal)) throw new TypeError("NodeRuntime signal must be an AbortSignal");
|
|
30
|
+
};
|
|
31
|
+
const validateCallbacks = (options) => {
|
|
32
|
+
if (options.onSuccess !== void 0 && typeof options.onSuccess !== "function") throw new TypeError("NodeRuntime onSuccess must be a function");
|
|
33
|
+
if (options.onFailure !== void 0 && typeof options.onFailure !== "function") throw new TypeError("NodeRuntime onFailure must be a function");
|
|
34
|
+
if (options.onDefect !== void 0 && typeof options.onDefect !== "function") throw new TypeError("NodeRuntime onDefect must be a function");
|
|
35
|
+
if (options.onCleanupFailure !== void 0 && typeof options.onCleanupFailure !== "function") throw new TypeError("NodeRuntime onCleanupFailure must be a function");
|
|
36
|
+
};
|
|
37
|
+
const validateOptions = (options) => {
|
|
38
|
+
validateSignals(options.signals);
|
|
39
|
+
validateRuntimeOptions(options);
|
|
40
|
+
validateCallbacks(options);
|
|
41
|
+
if (options.observers !== void 0 && !Array.isArray(options.observers)) throw new TypeError("NodeRuntime observers must be an array");
|
|
42
|
+
};
|
|
43
|
+
const normalizeSignals = (signals) => {
|
|
44
|
+
const unique = /* @__PURE__ */ new Set();
|
|
45
|
+
for (const signal of signals ?? DEFAULT_SIGNALS) unique.add(signal);
|
|
46
|
+
return [...unique];
|
|
47
|
+
};
|
|
48
|
+
const removeSignalListeners = (listeners) => {
|
|
49
|
+
const failures = [];
|
|
50
|
+
for (const { signal, listener } of listeners) try {
|
|
51
|
+
process.removeListener(signal, listener);
|
|
52
|
+
} catch (cause) {
|
|
53
|
+
failures.push(cause);
|
|
54
|
+
}
|
|
55
|
+
listeners.length = 0;
|
|
56
|
+
return failures;
|
|
57
|
+
};
|
|
58
|
+
const combineFailures = (failures) => {
|
|
59
|
+
if (failures.length === 0) return [];
|
|
60
|
+
if (failures.length === 1) return [failures[0]];
|
|
61
|
+
return [new AggregateError(failures, "NodeRuntime cleanup failed")];
|
|
62
|
+
};
|
|
63
|
+
const setExitCode = (code) => {
|
|
64
|
+
process.exitCode = validateExitCode(code);
|
|
65
|
+
};
|
|
66
|
+
const reportDefect = (cause, handler) => {
|
|
67
|
+
let exitCode = 1;
|
|
68
|
+
if (handler) try {
|
|
69
|
+
const requestedExitCode = handler(cause);
|
|
70
|
+
if (requestedExitCode !== void 0) exitCode = validateExitCode(requestedExitCode);
|
|
71
|
+
} catch {
|
|
72
|
+
exitCode = 1;
|
|
73
|
+
}
|
|
74
|
+
setExitCode(ensureFailureExitCode(exitCode));
|
|
75
|
+
};
|
|
76
|
+
const installSignalListeners = (signals, listeners, onSignal) => {
|
|
77
|
+
for (const signal of signals) {
|
|
78
|
+
const listener = () => onSignal(signal);
|
|
79
|
+
process.on(signal, listener);
|
|
80
|
+
listeners.push({
|
|
81
|
+
signal,
|
|
82
|
+
listener
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
/** Node.js/Bun process lifecycle helpers. */
|
|
87
|
+
var NodeRuntime = class {
|
|
88
|
+
static async runMain(layer, backendOrProgramOrOptions, programOrOptions, legacyOptions) {
|
|
89
|
+
let backend;
|
|
90
|
+
let program;
|
|
91
|
+
let options;
|
|
92
|
+
if (typeof backendOrProgramOrOptions === "function") {
|
|
93
|
+
program = backendOrProgramOrOptions;
|
|
94
|
+
options = programOrOptions;
|
|
95
|
+
} else if (isLayerBackend(backendOrProgramOrOptions)) {
|
|
96
|
+
backend = backendOrProgramOrOptions;
|
|
97
|
+
program = programOrOptions;
|
|
98
|
+
options = legacyOptions;
|
|
99
|
+
} else {
|
|
100
|
+
options = backendOrProgramOrOptions;
|
|
101
|
+
program = programOrOptions;
|
|
102
|
+
}
|
|
103
|
+
if (options !== void 0 && !isOptionsObject(options)) throw new TypeError("NodeRuntime options must be a non-array object");
|
|
104
|
+
const normalizedOptions = options ?? {};
|
|
105
|
+
validateOptions(normalizedOptions);
|
|
106
|
+
const shutdownController = new AbortController();
|
|
107
|
+
const configuredSignals = normalizeSignals(normalizedOptions.signals);
|
|
108
|
+
const { onSuccess, onFailure, onDefect, signal: callerSignal, ...runtimeOptions } = normalizedOptions;
|
|
109
|
+
const signalLink = linkAbortSignals(callerSignal, shutdownController.signal);
|
|
110
|
+
const listeners = [];
|
|
111
|
+
const cleanupFailures = [];
|
|
112
|
+
let runtime;
|
|
113
|
+
let disposalPromise;
|
|
114
|
+
let disposalObserved = false;
|
|
115
|
+
let firstSignal;
|
|
116
|
+
let setupFailed = false;
|
|
117
|
+
let setupFailure;
|
|
118
|
+
let programFailed = false;
|
|
119
|
+
let programFailure;
|
|
120
|
+
let executionCleanupFailed = false;
|
|
121
|
+
let executionOutcome;
|
|
122
|
+
let programSettled = false;
|
|
123
|
+
let programValue;
|
|
124
|
+
const requestDispose = () => {
|
|
125
|
+
if (disposalPromise) return disposalPromise;
|
|
126
|
+
try {
|
|
127
|
+
disposalPromise = runtime.dispose();
|
|
128
|
+
} catch (cause) {
|
|
129
|
+
disposalPromise = Promise.reject(cause);
|
|
130
|
+
}
|
|
131
|
+
return disposalPromise;
|
|
132
|
+
};
|
|
133
|
+
const observeDisposal = async () => {
|
|
134
|
+
if (!runtime || disposalObserved) return;
|
|
135
|
+
disposalObserved = true;
|
|
136
|
+
try {
|
|
137
|
+
await requestDispose();
|
|
138
|
+
} catch (cause) {
|
|
139
|
+
cleanupFailures.push(cause);
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
const onSignal = (signal) => {
|
|
143
|
+
if (firstSignal !== void 0) return;
|
|
144
|
+
firstSignal = signal;
|
|
145
|
+
try {
|
|
146
|
+
shutdownController.abort(signal);
|
|
147
|
+
} finally {
|
|
148
|
+
requestDispose().catch(() => {});
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
try {
|
|
152
|
+
const executionObserver = { onExecutionEnd: ({ outcome }) => {
|
|
153
|
+
executionOutcome = outcome;
|
|
154
|
+
} };
|
|
155
|
+
const runtimeOptionsWithSignal = {
|
|
156
|
+
...runtimeOptions,
|
|
157
|
+
observers: [executionObserver, ...runtimeOptions.observers ?? []],
|
|
158
|
+
signal: signalLink.signal
|
|
159
|
+
};
|
|
160
|
+
runtime = backend ? await Runtime.make(layer, backend, runtimeOptionsWithSignal) : await Runtime.make(layer, runtimeOptionsWithSignal);
|
|
161
|
+
installSignalListeners(configuredSignals, listeners, onSignal);
|
|
162
|
+
try {
|
|
163
|
+
programValue = await runtime.run(program);
|
|
164
|
+
programSettled = true;
|
|
165
|
+
} catch (cause) {
|
|
166
|
+
if (executionOutcome?.status === "success") executionCleanupFailed = true;
|
|
167
|
+
else programFailed = true;
|
|
168
|
+
programFailure = cause;
|
|
169
|
+
}
|
|
170
|
+
await observeDisposal();
|
|
171
|
+
} catch (cause) {
|
|
172
|
+
setupFailed = true;
|
|
173
|
+
setupFailure = cause;
|
|
174
|
+
} finally {
|
|
175
|
+
await observeDisposal();
|
|
176
|
+
cleanupFailures.push(...removeSignalListeners(listeners));
|
|
177
|
+
try {
|
|
178
|
+
signalLink.dispose();
|
|
179
|
+
} catch (cause) {
|
|
180
|
+
cleanupFailures.push(cause);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
const cleanupFailureValues = combineFailures(cleanupFailures);
|
|
184
|
+
const hasCleanupFailure = cleanupFailureValues.length > 0;
|
|
185
|
+
const cleanupFailure = cleanupFailureValues[0];
|
|
186
|
+
if (setupFailed) {
|
|
187
|
+
reportDefect(setupFailure, onDefect);
|
|
188
|
+
throw setupFailure;
|
|
189
|
+
}
|
|
190
|
+
if (programFailed) {
|
|
191
|
+
reportDefect(programFailure, onDefect);
|
|
192
|
+
throw programFailure;
|
|
193
|
+
}
|
|
194
|
+
if (executionCleanupFailed) {
|
|
195
|
+
setExitCode(1);
|
|
196
|
+
throw programFailure;
|
|
197
|
+
}
|
|
198
|
+
if (!programSettled) {
|
|
199
|
+
const failure = /* @__PURE__ */ new Error("NodeRuntime main program did not settle");
|
|
200
|
+
reportDefect(failure, onDefect);
|
|
201
|
+
throw failure;
|
|
202
|
+
}
|
|
203
|
+
if (programValue instanceof Err) {
|
|
204
|
+
let exitCode = 1;
|
|
205
|
+
try {
|
|
206
|
+
if (onFailure) exitCode = validateExitCode(onFailure(programValue.error));
|
|
207
|
+
} catch (cause) {
|
|
208
|
+
reportDefect(cause, onDefect);
|
|
209
|
+
throw cause;
|
|
210
|
+
}
|
|
211
|
+
setExitCode(exitCode);
|
|
212
|
+
return programValue;
|
|
213
|
+
}
|
|
214
|
+
let exitCode = 0;
|
|
215
|
+
try {
|
|
216
|
+
if (onSuccess) {
|
|
217
|
+
const successValue = programValue instanceof Ok ? programValue.value : programValue;
|
|
218
|
+
exitCode = validateExitCode(onSuccess(successValue));
|
|
219
|
+
}
|
|
220
|
+
} catch (cause) {
|
|
221
|
+
reportDefect(cause, onDefect);
|
|
222
|
+
throw cause;
|
|
223
|
+
}
|
|
224
|
+
if (hasCleanupFailure) exitCode = ensureFailureExitCode(exitCode);
|
|
225
|
+
setExitCode(exitCode);
|
|
226
|
+
if (hasCleanupFailure) throw cleanupFailure;
|
|
227
|
+
return programValue;
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
//#endregion
|
|
231
|
+
export { NodeRuntime, NodeRuntimeContextStorage, RuntimeContextNotConfiguredError, nodeRuntimeContextStorage };
|
|
232
|
+
|
|
233
|
+
//# sourceMappingURL=node.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.mjs","names":[],"sources":["../src/runtime/node-runtime.ts"],"sourcesContent":["import { Err, Ok } from 'better-result'\n\nimport type { Result as ResultType } from 'better-result'\n\nimport type { EffectError, EffectSuccess } from '../effect'\nimport type { LayerBackend } from '../layer/backend'\nimport type {\n CompleteExecution,\n CompleteInput,\n LayerInput,\n ProvidedEnvironment\n} from '../layer/inference'\nimport { Runtime } from './runtime'\nimport { linkAbortSignals } from './signal'\n\nimport type { RuntimeOptions } from './outcome'\nimport type { RuntimeExecutionEndEvent, RuntimeObserver } from './observer'\nimport type { ScopeOutcome } from '../scope'\n\n/** Process signals supported by the Node.js/Bun process boundary. */\nexport type NodeRuntimeSignal = 'SIGINT' | 'SIGTERM'\n\n/** Translate a successful main result to a process exit code. */\nexport type NodeRuntimeSuccessHandler<Success> = (value: Success) => number\n\n/** Translate a typed main failure to a process exit code. */\nexport type NodeRuntimeFailureHandler<Failure> = (error: Failure) => number\n\n/** Observe a thrown or rejected main defect while it remains a rejected Promise. */\nexport type NodeRuntimeDefectHandler = (cause: unknown) => number | void\n\n/** Options for the Node.js/Bun process boundary. */\nexport type NodeRuntimeOptions<Success = unknown, Failure = unknown> = RuntimeOptions & {\n /** Process signals that request cooperative shutdown. Defaults to SIGINT and SIGTERM. */\n readonly signals?: readonly NodeRuntimeSignal[]\n /** Map a nominal Result.ok value, or a plain successful value, to an exit code. */\n readonly onSuccess?: NodeRuntimeSuccessHandler<Success>\n /** Map a nominal Result.err error to an exit code. */\n readonly onFailure?: NodeRuntimeFailureHandler<Failure>\n /** Observe a defect. Defects are rethrown after the handler runs. */\n readonly onDefect?: NodeRuntimeDefectHandler\n}\n\ntype NonResultMainSuccess<Value> = Value extends ResultType<any, any> ? never : Value\n\ntype PlainMainSuccess<Value> = NonResultMainSuccess<Awaited<Value>>\n\ntype MainSuccess<Value> = EffectSuccess<Value> | PlainMainSuccess<Value>\n\ntype MainFailure<Value> = EffectError<Value>\n\ntype MainOptions<Value> = NodeRuntimeOptions<MainSuccess<Value>, MainFailure<Value>>\n\nconst DEFAULT_SIGNALS = ['SIGINT', 'SIGTERM'] as const satisfies readonly NodeRuntimeSignal[]\n\ntype InstalledSignalListener = {\n readonly signal: NodeRuntimeSignal\n readonly listener: () => void\n}\n\n// oxlint-disable-next-line anti-slop/no-unknown-parameters -- backend overload dispatch validates an opaque runtime value.\nconst isLayerBackend = (value: unknown): value is LayerBackend => {\n // oxlint-disable-next-line anti-slop/no-runtime-typeof -- runtime overload dispatch must inspect the backend shape.\n if (value === null || typeof value !== 'object') {\n return false\n }\n\n return (\n 'register' in value &&\n 'resolve' in value &&\n 'disposeAll' in value &&\n // oxlint-disable-next-line anti-slop/no-runtime-typeof -- the backend contract is validated at this runtime boundary.\n typeof value.register === 'function' &&\n // oxlint-disable-next-line anti-slop/no-runtime-typeof -- the backend contract is validated at this runtime boundary.\n typeof value.resolve === 'function' &&\n // oxlint-disable-next-line anti-slop/no-runtime-typeof -- the backend contract is validated at this runtime boundary.\n typeof value.disposeAll === 'function'\n )\n}\n\n// oxlint-disable-next-line anti-slop/no-unknown-parameters -- AbortSignal validation receives an opaque public option.\nconst isAbortSignal = (value: unknown): value is AbortSignal => {\n // oxlint-disable-next-line anti-slop/no-runtime-typeof -- validate the structural host signal contract.\n if (value === null || typeof value !== 'object') {\n return false\n }\n\n return (\n // SAFETY: the preceding guard establishes that the opaque value is an object; these are the required AbortSignal members.\n // oxlint-disable-next-line anti-slop/no-runtime-typeof -- validate the structural host signal contract.\n typeof (value as AbortSignal).aborted === 'boolean' &&\n // SAFETY: the preceding guard establishes that the opaque value is an object; these are the required AbortSignal members.\n // oxlint-disable-next-line anti-slop/no-runtime-typeof -- validate the structural host signal contract.\n typeof (value as AbortSignal).addEventListener === 'function' &&\n // SAFETY: the preceding guard establishes that the opaque value is an object; these are the required AbortSignal members.\n // oxlint-disable-next-line anti-slop/no-runtime-typeof -- validate the structural host signal contract.\n typeof (value as AbortSignal).removeEventListener === 'function'\n )\n}\n\n// oxlint-disable-next-line anti-slop/no-unknown-parameters -- options are validated at the public boundary.\nconst isOptionsObject = (value: unknown): value is object => {\n // oxlint-disable-next-line anti-slop/no-runtime-typeof -- validate the public options boundary before installing listeners.\n return value !== null && typeof value === 'object' && !Array.isArray(value)\n}\n\nconst validateExitCode = (code: number): number => {\n if (!Number.isSafeInteger(code) || code < 0) {\n throw new RangeError('NodeRuntime exit codes must be non-negative safe integers')\n }\n\n return code\n}\n\nconst ensureFailureExitCode = (code: number): number => (code === 0 ? 1 : code)\n\nconst validateSignals = <Success, Failure>(\n signals: NodeRuntimeOptions<Success, Failure>['signals']\n): void => {\n if (signals !== undefined && !Array.isArray(signals)) {\n throw new TypeError('NodeRuntime signals must be an array of supported signal names')\n }\n\n for (const signal of signals ?? DEFAULT_SIGNALS) {\n // oxlint-disable-next-line anti-slop/no-runtime-typeof -- validate untyped options before process.on receives them.\n if (typeof signal !== 'string' || (signal !== 'SIGINT' && signal !== 'SIGTERM')) {\n throw new RangeError(`NodeRuntime signal \"${String(signal)}\" is not supported`)\n }\n }\n}\n\nconst validateRuntimeOptions = <Success, Failure>(\n options: NodeRuntimeOptions<Success, Failure>\n): void => {\n if (options.signal !== undefined && !isAbortSignal(options.signal)) {\n throw new TypeError('NodeRuntime signal must be an AbortSignal')\n }\n}\n\nconst validateCallbacks = <Success, Failure>(\n options: NodeRuntimeOptions<Success, Failure>\n): void => {\n // oxlint-disable-next-line anti-slop/no-runtime-typeof -- validate untyped options before invoking the callback.\n if (options.onSuccess !== undefined && typeof options.onSuccess !== 'function') {\n throw new TypeError('NodeRuntime onSuccess must be a function')\n }\n\n // oxlint-disable-next-line anti-slop/no-runtime-typeof -- validate untyped options before invoking the callback.\n if (options.onFailure !== undefined && typeof options.onFailure !== 'function') {\n throw new TypeError('NodeRuntime onFailure must be a function')\n }\n\n // oxlint-disable-next-line anti-slop/no-runtime-typeof -- validate untyped options before invoking the callback.\n if (options.onDefect !== undefined && typeof options.onDefect !== 'function') {\n throw new TypeError('NodeRuntime onDefect must be a function')\n }\n\n // oxlint-disable-next-line anti-slop/no-runtime-typeof -- validate untyped options before Runtime invokes the observer.\n if (options.onCleanupFailure !== undefined && typeof options.onCleanupFailure !== 'function') {\n throw new TypeError('NodeRuntime onCleanupFailure must be a function')\n }\n}\n\nconst validateOptions = <Success, Failure>(options: NodeRuntimeOptions<Success, Failure>): void => {\n validateSignals(options.signals)\n validateRuntimeOptions(options)\n validateCallbacks(options)\n\n if (options.observers !== undefined && !Array.isArray(options.observers)) {\n throw new TypeError('NodeRuntime observers must be an array')\n }\n}\n\nconst normalizeSignals = (\n signals: readonly NodeRuntimeSignal[] | undefined\n): readonly NodeRuntimeSignal[] => {\n const unique = new Set<NodeRuntimeSignal>()\n\n for (const signal of signals ?? DEFAULT_SIGNALS) {\n unique.add(signal)\n }\n\n return [...unique]\n}\n\nconst removeSignalListeners = (listeners: InstalledSignalListener[]): readonly unknown[] => {\n const failures: unknown[] = []\n\n for (const { signal, listener } of listeners) {\n try {\n process.removeListener(signal, listener)\n } catch (cause) {\n failures.push(cause)\n }\n }\n\n listeners.length = 0\n\n return failures\n}\n\nconst combineFailures = (failures: readonly unknown[]): readonly unknown[] => {\n if (failures.length === 0) {\n return []\n }\n\n if (failures.length === 1) {\n return [failures[0]]\n }\n\n return [new AggregateError(failures, 'NodeRuntime cleanup failed')]\n}\n\nconst setExitCode = (code: number): void => {\n process.exitCode = validateExitCode(code)\n}\n\nconst reportDefect = (cause: unknown, handler: NodeRuntimeDefectHandler | undefined): void => {\n let exitCode = 1\n\n if (handler) {\n try {\n const requestedExitCode = handler(cause)\n\n if (requestedExitCode !== undefined) {\n exitCode = validateExitCode(requestedExitCode)\n }\n } catch {\n exitCode = 1\n }\n }\n\n setExitCode(ensureFailureExitCode(exitCode))\n}\n\nconst installSignalListeners = (\n signals: readonly NodeRuntimeSignal[],\n listeners: InstalledSignalListener[],\n onSignal: (signal: NodeRuntimeSignal) => void\n): void => {\n for (const signal of signals) {\n const listener = (): void => onSignal(signal)\n process.on(signal, listener)\n listeners.push({ signal, listener })\n }\n}\n\n/** Node.js/Bun process lifecycle helpers. */\nexport class NodeRuntime {\n /**\n * Run a typed main Program, translate its final result to `process.exitCode`,\n * and dispose the Runtime when the program or a configured process signal settles.\n */\n static runMain<A, L extends LayerInput>(\n layer: L & CompleteInput<L>,\n backend: LayerBackend,\n program: CompleteExecution<ProvidedEnvironment<L>, A>,\n options?: MainOptions<A>\n ): Promise<Awaited<A>>\n\n static runMain<A, L extends LayerInput>(\n layer: L & CompleteInput<L>,\n program: CompleteExecution<ProvidedEnvironment<L>, A>,\n options?: MainOptions<A>\n ): Promise<Awaited<A>>\n\n static runMain<A, L extends LayerInput>(\n layer: L & CompleteInput<L>,\n options: MainOptions<A>,\n program: CompleteExecution<ProvidedEnvironment<L>, A>\n ): Promise<Awaited<A>>\n\n static async runMain<A, L extends LayerInput>(\n layer: L & CompleteInput<L>,\n backendOrProgramOrOptions:\n | LayerBackend\n | MainOptions<A>\n | CompleteExecution<ProvidedEnvironment<L>, A>,\n programOrOptions?: CompleteExecution<ProvidedEnvironment<L>, A> | MainOptions<A>,\n legacyOptions?: MainOptions<A>\n ): Promise<Awaited<A>> {\n let backend: LayerBackend | undefined\n let program!: CompleteExecution<ProvidedEnvironment<L>, A>\n let options: MainOptions<A> | undefined\n\n // oxlint-disable-next-line anti-slop/no-runtime-typeof -- overload dispatch distinguishes the Program callback from configuration.\n if (typeof backendOrProgramOrOptions === 'function') {\n program = backendOrProgramOrOptions\n // SAFETY: this branch is selected by the Program overload, so the optional value is its options object.\n options = programOrOptions as MainOptions<A> | undefined\n } else if (isLayerBackend(backendOrProgramOrOptions)) {\n backend = backendOrProgramOrOptions\n // SAFETY: the backend overload requires a Program in the third argument.\n program = programOrOptions as CompleteExecution<ProvidedEnvironment<L>, A>\n options = legacyOptions\n } else {\n options = backendOrProgramOrOptions\n // SAFETY: the options overload requires a Program in the third argument.\n program = programOrOptions as CompleteExecution<ProvidedEnvironment<L>, A>\n }\n\n if (options !== undefined && !isOptionsObject(options)) {\n throw new TypeError('NodeRuntime options must be a non-array object')\n }\n\n // SAFETY: validation above establishes an object; the empty object is the omitted-options case.\n const normalizedOptions = (options ?? {}) as MainOptions<A>\n validateOptions(normalizedOptions)\n\n const shutdownController = new AbortController()\n const configuredSignals = normalizeSignals(normalizedOptions.signals)\n const {\n onSuccess,\n onFailure,\n onDefect,\n signal: callerSignal,\n ...runtimeOptions\n } = normalizedOptions\n const signalLink = linkAbortSignals(callerSignal, shutdownController.signal)\n const listeners: InstalledSignalListener[] = []\n const cleanupFailures: unknown[] = []\n\n let runtime: Runtime<ProvidedEnvironment<L>> | undefined\n let disposalPromise: Promise<void> | undefined\n let disposalObserved = false\n let firstSignal: NodeRuntimeSignal | undefined\n let setupFailed = false\n let setupFailure: unknown\n let programFailed = false\n let programFailure: unknown\n let executionCleanupFailed = false\n let executionOutcome: ScopeOutcome | undefined\n let programSettled = false\n let programValue!: Awaited<A>\n\n const requestDispose = (): Promise<void> => {\n if (disposalPromise) {\n return disposalPromise\n }\n\n try {\n disposalPromise = runtime!.dispose()\n } catch (cause) {\n disposalPromise = Promise.reject(cause)\n }\n\n return disposalPromise\n }\n\n const observeDisposal = async (): Promise<void> => {\n if (!runtime || disposalObserved) {\n return\n }\n\n disposalObserved = true\n\n try {\n await requestDispose()\n } catch (cause) {\n cleanupFailures.push(cause)\n }\n }\n\n const onSignal = (signal: NodeRuntimeSignal): void => {\n if (firstSignal !== undefined) {\n return\n }\n\n firstSignal = signal\n\n try {\n shutdownController.abort(signal)\n } finally {\n void requestDispose().catch(() => {})\n }\n }\n\n try {\n const executionObserver: RuntimeObserver = {\n onExecutionEnd: ({ outcome }: RuntimeExecutionEndEvent): void => {\n executionOutcome = outcome\n }\n }\n const runtimeOptionsWithSignal: RuntimeOptions = {\n ...runtimeOptions,\n observers: [executionObserver, ...(runtimeOptions.observers ?? [])],\n signal: signalLink.signal\n }\n\n runtime = backend\n ? await Runtime.make(layer, backend, runtimeOptionsWithSignal)\n : await Runtime.make(layer, runtimeOptionsWithSignal)\n\n installSignalListeners(configuredSignals, listeners, onSignal)\n\n try {\n programValue = await runtime.run(program)\n programSettled = true\n } catch (cause) {\n if (executionOutcome?.status === 'success') {\n executionCleanupFailed = true\n } else {\n programFailed = true\n }\n programFailure = cause\n }\n\n await observeDisposal()\n } catch (cause) {\n setupFailed = true\n setupFailure = cause\n } finally {\n await observeDisposal()\n cleanupFailures.push(...removeSignalListeners(listeners))\n\n try {\n signalLink.dispose()\n } catch (cause) {\n cleanupFailures.push(cause)\n }\n }\n\n const cleanupFailureValues = combineFailures(cleanupFailures)\n const hasCleanupFailure = cleanupFailureValues.length > 0\n const cleanupFailure = cleanupFailureValues[0]\n\n if (setupFailed) {\n reportDefect(setupFailure, onDefect)\n throw setupFailure\n }\n\n if (programFailed) {\n reportDefect(programFailure, onDefect)\n throw programFailure\n }\n\n if (executionCleanupFailed) {\n setExitCode(1)\n throw programFailure\n }\n\n if (!programSettled) {\n const failure = new Error('NodeRuntime main program did not settle')\n reportDefect(failure, onDefect)\n throw failure\n }\n\n if (programValue instanceof Err) {\n let exitCode = 1\n\n try {\n if (onFailure) {\n // SAFETY: Err carries the failure channel represented by MainFailure<A>.\n exitCode = validateExitCode(onFailure(programValue.error as MainFailure<A>))\n }\n } catch (cause) {\n reportDefect(cause, onDefect)\n throw cause\n }\n\n setExitCode(exitCode)\n return programValue\n }\n\n let exitCode = 0\n\n try {\n if (onSuccess) {\n const successValue = programValue instanceof Ok ? programValue.value : programValue\n // SAFETY: Ok is unwrapped above; plain successful values retain the MainSuccess<A> channel.\n exitCode = validateExitCode(onSuccess(successValue as MainSuccess<A>))\n }\n } catch (cause) {\n reportDefect(cause, onDefect)\n throw cause\n }\n\n if (hasCleanupFailure) {\n exitCode = ensureFailureExitCode(exitCode)\n }\n\n setExitCode(exitCode)\n\n if (hasCleanupFailure) {\n throw cleanupFailure\n }\n\n return programValue\n }\n}\n\n/** Type-level aliases for the Node.js/Bun process boundary. */\nexport declare namespace NodeRuntime {\n /** Options for `NodeRuntime.runMain`. */\n export type Options<Success = unknown, Failure = unknown> = NodeRuntimeOptions<Success, Failure>\n\n /** A process signal accepted by `NodeRuntime.runMain`. */\n export type Signal = NodeRuntimeSignal\n}\n"],"mappings":";;;;;;AAqDA,MAAM,kBAAkB,CAAC,UAAU,SAAS;AAQ5C,MAAM,kBAAkB,UAA0C;CAEhE,IAAI,UAAU,QAAQ,OAAO,UAAU,UACrC,OAAO;CAGT,OACE,cAAc,SACd,aAAa,SACb,gBAAgB,SAEhB,OAAO,MAAM,aAAa,cAE1B,OAAO,MAAM,YAAY,cAEzB,OAAO,MAAM,eAAe;AAEhC;AAGA,MAAM,iBAAiB,UAAyC;CAE9D,IAAI,UAAU,QAAQ,OAAO,UAAU,UACrC,OAAO;CAGT,OAGE,OAAQ,MAAsB,YAAY,aAG1C,OAAQ,MAAsB,qBAAqB,cAGnD,OAAQ,MAAsB,wBAAwB;AAE1D;AAGA,MAAM,mBAAmB,UAAoC;CAE3D,OAAO,UAAU,QAAQ,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAEA,MAAM,oBAAoB,SAAyB;CACjD,IAAI,CAAC,OAAO,cAAc,IAAI,KAAK,OAAO,GACxC,MAAM,IAAI,WAAW,2DAA2D;CAGlF,OAAO;AACT;AAEA,MAAM,yBAAyB,SAA0B,SAAS,IAAI,IAAI;AAE1E,MAAM,mBACJ,YACS;CACT,IAAI,YAAY,KAAA,KAAa,CAAC,MAAM,QAAQ,OAAO,GACjD,MAAM,IAAI,UAAU,gEAAgE;CAGtF,KAAK,MAAM,UAAU,WAAW,iBAE9B,IAAI,OAA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-u.mjs";
|
|
2
|
+
//#region src/utils/types.d.ts
|
|
3
|
+
type MaybePromise<T> = T | PromiseLike<T>;
|
|
4
|
+
//#endregion
|
|
5
|
+
//#region src/runtime/observer.d.ts
|
|
6
|
+
/** Event emitted after a Service resolution attempt settles. */
|
|
7
|
+
type RuntimeServiceResolveEvent = {
|
|
8
|
+
readonly service: AnyServiceToken;
|
|
9
|
+
readonly resolutionPath: readonly AnyServiceToken[];
|
|
10
|
+
readonly outcome: ScopeOutcome;
|
|
11
|
+
/** Runtime execution owner, omitted for warmup and other root activity. */
|
|
12
|
+
readonly executionId?: string;
|
|
13
|
+
};
|
|
14
|
+
/** Event emitted after a provider acquisition attempt settles. */
|
|
15
|
+
type RuntimeServiceAcquireEvent = {
|
|
16
|
+
readonly service: AnyServiceToken;
|
|
17
|
+
readonly resolutionPath: readonly AnyServiceToken[];
|
|
18
|
+
readonly outcome: ScopeOutcome;
|
|
19
|
+
/** Runtime execution owner, omitted for warmup and other root activity. */
|
|
20
|
+
readonly executionId?: string;
|
|
21
|
+
};
|
|
22
|
+
/** Values supplied to one Runtime execution for diagnostic correlation. */
|
|
23
|
+
type RuntimeExecutionAttributes = Readonly<Record<string, unknown>>;
|
|
24
|
+
/** Metadata shared by the start and end events for one execution. */
|
|
25
|
+
type RuntimeExecutionMetadata = {
|
|
26
|
+
readonly executionId: string;
|
|
27
|
+
readonly name?: string;
|
|
28
|
+
readonly attributes?: RuntimeExecutionAttributes;
|
|
29
|
+
/** Monotonic host timestamp captured immediately before the Program starts. */
|
|
30
|
+
readonly startedAt: number;
|
|
31
|
+
};
|
|
32
|
+
/** Event emitted immediately before a program starts in an execution Scope. */
|
|
33
|
+
type RuntimeExecutionStartEvent = RuntimeExecutionMetadata & {
|
|
34
|
+
readonly scope: Scope;
|
|
35
|
+
};
|
|
36
|
+
/** Event emitted after a program and its execution Scope settle. */
|
|
37
|
+
type RuntimeExecutionEndEvent = RuntimeExecutionMetadata & {
|
|
38
|
+
readonly scope: Scope;
|
|
39
|
+
/** The program outcome used to run execution-scope cleanup. */
|
|
40
|
+
readonly outcome: ScopeOutcome;
|
|
41
|
+
/** Execution-scope cleanup failure, without changing the primary program outcome. */
|
|
42
|
+
readonly cleanupFailure?: ScopeCloseError;
|
|
43
|
+
/** Monotonic elapsed time for the Program and its execution cleanup. */
|
|
44
|
+
readonly durationMs: number;
|
|
45
|
+
};
|
|
46
|
+
/** Event emitted after a Layer provider release callback settles. */
|
|
47
|
+
type RuntimeResourceReleaseEvent = {
|
|
48
|
+
readonly service: AnyServiceToken;
|
|
49
|
+
readonly outcome: ScopeOutcome;
|
|
50
|
+
readonly error?: unknown;
|
|
51
|
+
/** Runtime execution owner, omitted for Runtime-root cleanup. */
|
|
52
|
+
readonly executionId?: string;
|
|
53
|
+
};
|
|
54
|
+
/** Optional best-effort hooks for Runtime lifecycle and resolution events. */
|
|
55
|
+
type RuntimeObserver = {
|
|
56
|
+
readonly onServiceResolve?: (event: RuntimeServiceResolveEvent) => MaybePromise<void>;
|
|
57
|
+
readonly onServiceAcquire?: (event: RuntimeServiceAcquireEvent) => MaybePromise<void>;
|
|
58
|
+
readonly onExecutionStart?: (event: RuntimeExecutionStartEvent) => MaybePromise<void>;
|
|
59
|
+
readonly onExecutionEnd?: (event: RuntimeExecutionEndEvent) => MaybePromise<void>;
|
|
60
|
+
readonly onResourceRelease?: (event: RuntimeResourceReleaseEvent) => MaybePromise<void>;
|
|
61
|
+
};
|
|
62
|
+
/** Compose best-effort Runtime observers into one observer. */
|
|
63
|
+
declare const RuntimeObserver: {
|
|
64
|
+
compose: (...observers: readonly RuntimeObserver[]) => RuntimeObserver;
|
|
65
|
+
};
|
|
66
|
+
//#endregion
|
|
67
|
+
export { RuntimeObserver as a, RuntimeServiceResolveEvent as c, RuntimeExecutionStartEvent as i, MaybePromise as l, RuntimeExecutionEndEvent as n, RuntimeResourceReleaseEvent as o, RuntimeExecutionMetadata as r, RuntimeServiceAcquireEvent as s, RuntimeExecutionAttributes as t };
|
|
68
|
+
//# sourceMappingURL=observer-9nhbL7Pr.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observer-9nhbL7Pr.d.mts","names":[],"sources":["../src/utils/types.ts","../src/runtime/observer.ts"],"mappings":";;KAAY,aAAa,KAAK,IAAI,YAAY;;;;KCMlC;WACD,SAAS;WACT,yBAAyB;WACzB,SAAS;;WAET;;;KAIC;WACD,SAAS;WACT,yBAAyB;WACzB,SAAS;;WAET;;;KAKC,6BAA6B,SAAS;;KAGtC;WACD;WACA;WAEA,aAAa;;WAEb;;;KAIC,6BAA6B;WAC9B,OAAO;;;KAIN,2BAA2B;WAC5B,OAAO;;WAEP,SAAS;;WAET,iBAAiB;;WAEjB;;;KAIC;WACD,SAAS;WACT,SAAS;WACT;;WAEA;;;KAIC;WACD,oBAAoB,OAAO,+BAA+B;WAC1D,oBAAoB,OAAO,+BAA+B;WAC1D,oBAAoB,OAAO,+BAA+B;WAC1D,kBAAkB,OAAO,6BAA6B;WACtD,qBAAqB,OAAO,gCAAgC;;;cAI1D;EACa,aAAA,oBAAS,sBAAoB"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { a as RuntimeObserver, c as RuntimeServiceResolveEvent, i as RuntimeExecutionStartEvent, n as RuntimeExecutionEndEvent, o as RuntimeResourceReleaseEvent, s as RuntimeServiceAcquireEvent, t as RuntimeExecutionAttributes } from "./observer-9nhbL7Pr.mjs";
|
|
2
|
+
import { AttributeValue, Tracer, TracerProvider } from "@opentelemetry/api";
|
|
3
|
+
//#region src/opentelemetry/index.d.ts
|
|
4
|
+
/** Controls how Service lifecycle events are represented in telemetry. */
|
|
5
|
+
type ServiceTelemetryMode = 'off' | 'events' | 'spans';
|
|
6
|
+
/** Attribute values accepted by the OpenTelemetry adapter. */
|
|
7
|
+
type OpenTelemetryAttributes = Readonly<Record<string, AttributeValue>>;
|
|
8
|
+
/** A deliberately small, already-sanitized failure representation. */
|
|
9
|
+
type OpenTelemetryFailure = string | {
|
|
10
|
+
readonly message?: string;
|
|
11
|
+
readonly attributes?: OpenTelemetryAttributes;
|
|
12
|
+
};
|
|
13
|
+
/** Select safe execution attributes explicitly before they reach a span. */
|
|
14
|
+
type OpenTelemetryExecutionAttributesSanitizer = (attributes: RuntimeExecutionAttributes) => OpenTelemetryAttributes | undefined;
|
|
15
|
+
/** Select safe failure details explicitly before they reach a span. */
|
|
16
|
+
type OpenTelemetryFailureSanitizer = (cause: unknown) => OpenTelemetryFailure | undefined;
|
|
17
|
+
type OpenTelemetryRuntimeObserverBaseOptions = {
|
|
18
|
+
/** Use an existing tracer. The adapter never registers a global provider. */
|
|
19
|
+
readonly tracer?: Tracer;
|
|
20
|
+
/** Resolve a tracer from an existing provider without registering it globally. */
|
|
21
|
+
readonly provider?: TracerProvider;
|
|
22
|
+
/** Tracer name used only when `provider` is supplied. */
|
|
23
|
+
readonly tracerName?: string;
|
|
24
|
+
/** Optional instrumentation version used only when `provider` is supplied. */
|
|
25
|
+
readonly tracerVersion?: string;
|
|
26
|
+
/** Service resolution policy. Defaults to `off`. */
|
|
27
|
+
readonly serviceResolution?: ServiceTelemetryMode;
|
|
28
|
+
/** Record explicitly sanitized failure details in addition to setting status. */
|
|
29
|
+
readonly recordFailures?: boolean;
|
|
30
|
+
/** Explicitly sanitize arbitrary execution attributes. */
|
|
31
|
+
readonly sanitizeExecutionAttributes?: OpenTelemetryExecutionAttributesSanitizer;
|
|
32
|
+
/** Copy only these execution attribute keys, dropping unsupported values. */
|
|
33
|
+
readonly executionAttributeAllowlist?: readonly string[];
|
|
34
|
+
/** Explicitly sanitize a failure before recording it. */
|
|
35
|
+
readonly sanitizeFailure?: OpenTelemetryFailureSanitizer;
|
|
36
|
+
/** Maximum length for attribute keys and string values. Defaults to 256. */
|
|
37
|
+
readonly maxAttributeLength?: number;
|
|
38
|
+
/** Maximum number of copied execution or failure attributes. Defaults to 32. */
|
|
39
|
+
readonly maxAttributeCount?: number;
|
|
40
|
+
/** Maximum number of Service tags retained in a resolution path. Defaults to 16. */
|
|
41
|
+
readonly maxResolutionPathLength?: number;
|
|
42
|
+
};
|
|
43
|
+
/** Configuration for an observer backed by an existing OpenTelemetry tracer/provider. */
|
|
44
|
+
type OpenTelemetryRuntimeObserverOptions = (OpenTelemetryRuntimeObserverBaseOptions & {
|
|
45
|
+
readonly tracer: Tracer;
|
|
46
|
+
readonly provider?: never;
|
|
47
|
+
}) | (OpenTelemetryRuntimeObserverBaseOptions & {
|
|
48
|
+
readonly provider: TracerProvider;
|
|
49
|
+
readonly tracer?: never;
|
|
50
|
+
});
|
|
51
|
+
/**
|
|
52
|
+
* Best-effort RuntimeObserver adapter for an existing OpenTelemetry tracer.
|
|
53
|
+
*
|
|
54
|
+
* The adapter never installs a global provider, SDK, context manager, or
|
|
55
|
+
* exporter. All observer hooks are synchronous and isolate tracer failures.
|
|
56
|
+
*/
|
|
57
|
+
declare class OpenTelemetryRuntimeObserver implements RuntimeObserver {
|
|
58
|
+
private readonly tracer;
|
|
59
|
+
private readonly options;
|
|
60
|
+
private readonly limits;
|
|
61
|
+
private readonly executionSpans;
|
|
62
|
+
private readonly serviceResolution;
|
|
63
|
+
private readonly recordFailures;
|
|
64
|
+
private disposed;
|
|
65
|
+
constructor(options: OpenTelemetryRuntimeObserverOptions);
|
|
66
|
+
static make(options: OpenTelemetryRuntimeObserverOptions): OpenTelemetryRuntimeObserver;
|
|
67
|
+
readonly onExecutionStart: (event: RuntimeExecutionStartEvent) => void;
|
|
68
|
+
readonly onExecutionEnd: (event: RuntimeExecutionEndEvent) => void;
|
|
69
|
+
readonly onServiceResolve: (event: RuntimeServiceResolveEvent) => void;
|
|
70
|
+
readonly onServiceAcquire: (event: RuntimeServiceAcquireEvent) => void;
|
|
71
|
+
readonly onResourceRelease: (event: RuntimeResourceReleaseEvent) => void;
|
|
72
|
+
/** End any spans whose malformed or missing end event left them pending. */
|
|
73
|
+
dispose(): void;
|
|
74
|
+
[Symbol.dispose](): void;
|
|
75
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
76
|
+
private safely;
|
|
77
|
+
private startSpan;
|
|
78
|
+
private ownsExecutionSpan;
|
|
79
|
+
private claimExecutionSpan;
|
|
80
|
+
private endExecutionSpan;
|
|
81
|
+
private finishPendingExecution;
|
|
82
|
+
private startExecution;
|
|
83
|
+
private endExecution;
|
|
84
|
+
private finishExecution;
|
|
85
|
+
private findCorrelatedExecution;
|
|
86
|
+
private observeService;
|
|
87
|
+
private findExecutionId;
|
|
88
|
+
private observeCorrelatedService;
|
|
89
|
+
private observeStandaloneService;
|
|
90
|
+
private finishServiceSpan;
|
|
91
|
+
}
|
|
92
|
+
//#endregion
|
|
93
|
+
export { OpenTelemetryAttributes, OpenTelemetryExecutionAttributesSanitizer, OpenTelemetryFailure, OpenTelemetryFailureSanitizer, OpenTelemetryRuntimeObserver, OpenTelemetryRuntimeObserverOptions, ServiceTelemetryMode };
|
|
94
|
+
//# sourceMappingURL=opentelemetry.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opentelemetry.d.mts","names":[],"sources":["../src/opentelemetry/index.ts"],"mappings":";;;;KAuBY;;KAGA,0BAA0B,SAAS,eAAe;;KAGlD;WAGG;WACA,aAAa;;;KAIhB,6CACV,YAAY,+BACT;;KAGO,iCAAiC,mBAAmB;KAE3D;;WAEM,SAAS;;WAET,WAAW;;WAEX;;WAEA;;WAEA,oBAAoB;;WAEpB;;WAEA,8BAA8B;;WAE9B;;WAEA,kBAAkB;;WAElB;;WAEA;;WAEA;;;KAIC,uCACP;WACU,QAAQ;WACR;MAEV;WACU,UAAU;WACV;;;;;;;;cAgmBF,wCAAwC;mBAClC;mBAEA;mBAEA;mBAEA;mBAEA;mBAEA;UAET;EAEI,YAAA,SAAS;SAYd,KAAK,SAAS,sCAAsC;WAIlD,mBAAoB,OAAO;WAI3B,iBAAkB,OAAO;WAIzB,mBAAoB,OAAO;WAI3B,mBAAoB,OAAO;WAI3B,oBAAqB,OAAO;;EAKrC;GAoBC,OAAO;GAID,OAAO,iBAAiB;UAIvB;UAYA;UAsBA;UAIA;UASA;UAMA;UAMA;UAyDA;UAiBA;UAgCA;UASA;UAiCA;UAIA;UA0BA;UAuBA"}
|