better-effect 0.12.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.
Files changed (87) hide show
  1. package/README.md +327 -7
  2. package/dist/adapters/iti.d.mts +3 -3
  3. package/dist/bun.d.mts +43 -0
  4. package/dist/bun.d.mts.map +1 -0
  5. package/dist/bun.mjs +40 -0
  6. package/dist/bun.mjs.map +1 -0
  7. package/dist/{context-BUEf1qjL.mjs → context-BphfFUMO.mjs} +4 -2
  8. package/dist/context-BphfFUMO.mjs.map +1 -0
  9. package/dist/current-request-CIU7AHhF.d.mts +22 -0
  10. package/dist/current-request-CIU7AHhF.d.mts.map +1 -0
  11. package/dist/current-request-DDKNyymv.mjs +20 -0
  12. package/dist/current-request-DDKNyymv.mjs.map +1 -0
  13. package/dist/{signal-D2UTcaaG.mjs → disposable-CP-Q2H3l.mjs} +4 -52
  14. package/dist/disposable-CP-Q2H3l.mjs.map +1 -0
  15. package/dist/{effect-CK4YZaX0.mjs → effect-CPdV7Yv8.mjs} +2 -2
  16. package/dist/{effect-CK4YZaX0.mjs.map → effect-CPdV7Yv8.mjs.map} +1 -1
  17. package/dist/hono.d.mts +7 -5
  18. package/dist/hono.d.mts.map +1 -1
  19. package/dist/hono.mjs +88 -30
  20. package/dist/hono.mjs.map +1 -1
  21. package/dist/{index-heuaRmXR.d.mts → index-AiKM71-u.d.mts} +3 -1
  22. package/dist/{index-heuaRmXR.d.mts.map → index-AiKM71-u.d.mts.map} +1 -1
  23. package/dist/{index-GYJ4qm9K.d.mts → index-BodMy6rO.d.mts} +6 -5
  24. package/dist/index-BodMy6rO.d.mts.map +1 -0
  25. package/dist/{index-CX6iAoCB.d.mts → index-CCi07kUw.d.mts} +2 -2
  26. package/dist/{index-CX6iAoCB.d.mts.map → index-CCi07kUw.d.mts.map} +1 -1
  27. package/dist/{index-BMdU_Z72.d.mts → index-DAKn0qHk.d.mts} +4 -3
  28. package/dist/index-DAKn0qHk.d.mts.map +1 -0
  29. package/dist/{index-B1nH4luq.d.mts → index-cXgyMa0v.d.mts} +6 -20
  30. package/dist/index-cXgyMa0v.d.mts.map +1 -0
  31. package/dist/index.d.mts +6 -5
  32. package/dist/index.mjs +7 -6
  33. package/dist/index.mjs.map +1 -1
  34. package/dist/{layer-D56fRdLt.mjs → layer-D16GKxuX.mjs} +4 -4
  35. package/dist/layer-D16GKxuX.mjs.map +1 -0
  36. package/dist/next.d.mts +116 -0
  37. package/dist/next.d.mts.map +1 -0
  38. package/dist/next.mjs +68 -0
  39. package/dist/next.mjs.map +1 -0
  40. package/dist/{node-context-lggRF4bR.mjs → node-context-Ca18oNSg.mjs} +2 -2
  41. package/dist/{node-context-lggRF4bR.mjs.map → node-context-Ca18oNSg.mjs.map} +1 -1
  42. package/dist/{node-context-DWsCUBRa.d.mts → node-context-DczjAcrX.d.mts} +2 -2
  43. package/dist/{node-context-DWsCUBRa.d.mts.map → node-context-DczjAcrX.d.mts.map} +1 -1
  44. package/dist/node.d.mts +4 -4
  45. package/dist/node.mjs +4 -4
  46. package/dist/observer-9nhbL7Pr.d.mts +68 -0
  47. package/dist/observer-9nhbL7Pr.d.mts.map +1 -0
  48. package/dist/opentelemetry.d.mts +94 -0
  49. package/dist/opentelemetry.d.mts.map +1 -0
  50. package/dist/opentelemetry.mjs +453 -0
  51. package/dist/opentelemetry.mjs.map +1 -0
  52. package/dist/{outcome-CB43bnFW.d.mts → outcome-DI8LPIQ4.d.mts} +14 -69
  53. package/dist/outcome-DI8LPIQ4.d.mts.map +1 -0
  54. package/dist/{program-metadata-DhQCCirO.mjs → program-metadata-BxjGkT17.mjs} +3 -3
  55. package/dist/{program-metadata-DhQCCirO.mjs.map → program-metadata-BxjGkT17.mjs.map} +1 -1
  56. package/dist/runtime/explicit.d.mts +1 -1
  57. package/dist/runtime/explicit.mjs +1 -1
  58. package/dist/runtime/node.d.mts +2 -2
  59. package/dist/runtime/node.mjs +2 -2
  60. package/dist/{runtime-CBMrX8Wl.mjs → runtime-C_55ofnL.mjs} +42 -27
  61. package/dist/runtime-C_55ofnL.mjs.map +1 -0
  62. package/dist/signal-nfgFyNCk.mjs +52 -0
  63. package/dist/signal-nfgFyNCk.mjs.map +1 -0
  64. package/dist/{standard-services-GBZ32tll.mjs → standard-services-vnGIafkS.mjs} +3 -17
  65. package/dist/standard-services-vnGIafkS.mjs.map +1 -0
  66. package/dist/standard-services.d.mts +3 -2
  67. package/dist/standard-services.mjs +3 -2
  68. package/dist/testing.d.mts +6 -5
  69. package/dist/testing.d.mts.map +1 -1
  70. package/dist/testing.mjs +6 -6
  71. package/dist/types-oihI-ESv.d.mts +54 -0
  72. package/dist/types-oihI-ESv.d.mts.map +1 -0
  73. package/dist/web-Bq3MfMrj.mjs +147 -0
  74. package/dist/web-Bq3MfMrj.mjs.map +1 -0
  75. package/dist/web.d.mts +47 -0
  76. package/dist/web.d.mts.map +1 -0
  77. package/dist/web.mjs +2 -0
  78. package/package.json +33 -2
  79. package/dist/context-BUEf1qjL.mjs.map +0 -1
  80. package/dist/index-B1nH4luq.d.mts.map +0 -1
  81. package/dist/index-BMdU_Z72.d.mts.map +0 -1
  82. package/dist/index-GYJ4qm9K.d.mts.map +0 -1
  83. package/dist/layer-D56fRdLt.mjs.map +0 -1
  84. package/dist/outcome-CB43bnFW.d.mts.map +0 -1
  85. package/dist/runtime-CBMrX8Wl.mjs.map +0 -1
  86. package/dist/signal-D2UTcaaG.mjs.map +0 -1
  87. package/dist/standard-services-GBZ32tll.mjs.map +0 -1
@@ -1,13 +1,11 @@
1
- import { F as ServiceContract, H as ServiceToken, L as ServiceIdentityTypeId, M as AnyService, N as AnyServiceToken, O as InferYieldRequirements, P as ServiceClass, T as EffectRequirements, U as ServiceTokenOf, V as ServiceTagOf, a as ServiceResolver, c as RuntimeContextStorage, d as CleanupFailureDiagnostic, f as DisposableResource, h as ScopeOutcome, j as ServiceRequirement, m as ScopeFinalizer, p as MaybePromise$1, u as Scope, z as ServiceRequirements } from "./index-heuaRmXR.mjs";
1
+ import { F as ServiceContract, H as ServiceToken, L as ServiceIdentityTypeId, M as AnyService, N as AnyServiceToken, O as InferYieldRequirements, P as ServiceClass, T as EffectRequirements, U as ServiceTokenOf, V as ServiceTagOf, a as ServiceResolver, c as RuntimeContextStorage, d as CleanupFailureDiagnostic, f as DisposableResource, h as ScopeOutcome, j as ServiceRequirement, m as ScopeFinalizer, p as MaybePromise, z as ServiceRequirements } from "./index-AiKM71-u.mjs";
2
+ import { a as RuntimeObserver, l as MaybePromise$1, t as RuntimeExecutionAttributes } from "./observer-9nhbL7Pr.mjs";
2
3
  //#region src/internal/variance.d.ts
3
4
  /** Type-level marker for a value produced by `A`. */
4
5
  type Covariant<A> = () => A;
5
6
  /** Type-level marker that both consumes and produces `A`. */
6
7
  type Invariant<A> = (value: A) => A;
7
8
  //#endregion
8
- //#region src/utils/types.d.ts
9
- type MaybePromise<T> = T | PromiseLike<T>;
10
- //#endregion
11
9
  //#region src/internal/missing-dependencies.d.ts
12
10
  type MissingDependencies<Missing extends AnyService> = {
13
11
  /** Names the Services that must be supplied before execution. */
@@ -196,7 +194,7 @@ interface LayerRegistration {
196
194
  */
197
195
  readonly serviceTag?: string;
198
196
  /** Lazily acquire the Service instance; concrete types are erased at this backend boundary. */
199
- readonly acquire: () => MaybePromise<unknown>;
197
+ readonly acquire: () => MaybePromise$1<unknown>;
200
198
  }
201
199
  /** Generator shape used by `Layer.gen` and `Layer.scopedGen`. */
202
200
  type LayerGenerator<S extends ServiceClass<any, any>, Yield extends ServiceRequirement<unknown> = ServiceRequirement<unknown>> = () => AsyncGenerator<Yield, ServiceContract<InstanceType<S>>, unknown>;
@@ -217,9 +215,9 @@ interface LayerProvider extends LayerRegistration {
217
215
  /** The tag captured before this provider can cross an asynchronous boundary. */
218
216
  readonly serviceTag: string;
219
217
  /** Provider storage deliberately erases the concrete instance type. */
220
- readonly release?: (instance: unknown, outcome: ScopeOutcome) => MaybePromise<void>;
218
+ readonly release?: (instance: unknown, outcome: ScopeOutcome) => MaybePromise$1<void>;
221
219
  /** Capture acquisition-local cleanup without retaining the acquired instance. */
222
- readonly acquireWithRelease?: () => MaybePromise<CapturedLayerAcquisition>;
220
+ readonly acquireWithRelease?: () => MaybePromise$1<CapturedLayerAcquisition>;
223
221
  }
224
222
  /** A Service class whose constructor can be called without arguments. */
225
223
  type DefaultConstructibleServiceClass<Tag extends string = string, Instance extends AnyService = AnyService> = ServiceClass<Tag, Instance> & (new () => Instance);
@@ -260,17 +258,17 @@ declare class Layer<in out Provided extends AnyService = AnyService, out Require
260
258
  static readonly empty: Layer<never, never>;
261
259
  /** Create a Layer that lazily acquires a Service instance. */
262
260
  static make<S extends DefaultConstructibleServiceClass<any, any>>(service: S): LayerResult<ProviderEntry<InstanceType<S>, ServiceRequirements<InstanceType<S>>>>;
263
- static make<S extends ServiceClass<any, any>>(service: S, acquire: () => MaybePromise<ServiceContract<InstanceType<S>>>): LayerResult<ProviderEntry<InstanceType<S>, ServiceRequirements<InstanceType<S>>>>;
261
+ static make<S extends ServiceClass<any, any>>(service: S, acquire: () => MaybePromise$1<ServiceContract<InstanceType<S>>>): LayerResult<ProviderEntry<InstanceType<S>, ServiceRequirements<InstanceType<S>>>>;
264
262
  /** Create a Layer from an already-constructed Service instance. */
265
263
  static succeed<S extends ServiceClass<any, any>>(service: S, instance: ServiceContract<InstanceType<S>>): LayerResult<ProviderEntry<InstanceType<S>, ServiceRequirements<InstanceType<S>>>>;
266
264
  /** Alias a source Service under a compatible target contract. */
267
265
  static alias<From extends ServiceClass<any, any>, To extends ServiceClass<any, any>>(options: LayerAliasOptions<From, To>): LayerResult<ProviderEntry<InstanceType<To>, InstanceType<From> | ServiceRequirements<InstanceType<To>>>>;
268
266
  /** Define a provider with Runtime-root cleanup. */
269
- static scoped<S extends ServiceClass<any, any>>(service: S, acquire: () => MaybePromise<ServiceContract<InstanceType<S>>>, release: (instance: InstanceType<S>, outcome: ScopeOutcome) => MaybePromise<void>): LayerResult<ProviderEntry<InstanceType<S>, ServiceRequirements<InstanceType<S>>>>;
267
+ static scoped<S extends ServiceClass<any, any>>(service: S, acquire: () => MaybePromise$1<ServiceContract<InstanceType<S>>>, release: (instance: InstanceType<S>, outcome: ScopeOutcome) => MaybePromise$1<void>): LayerResult<ProviderEntry<InstanceType<S>, ServiceRequirements<InstanceType<S>>>>;
270
268
  /** Define a provider with Runtime-root cleanup through its disposal protocol. */
271
- static scopedDisposable<S extends ServiceClass<any, any>>(service: S, acquire: () => MaybePromise<ServiceContract<InstanceType<S>> & DisposableResource>): LayerResult<ProviderEntry<InstanceType<S>, ServiceRequirements<InstanceType<S>>>>;
269
+ static scopedDisposable<S extends ServiceClass<any, any>>(service: S, acquire: () => MaybePromise$1<ServiceContract<InstanceType<S>> & DisposableResource>): LayerResult<ProviderEntry<InstanceType<S>, ServiceRequirements<InstanceType<S>>>>;
272
270
  /** Define a provider whose acquisition can yield contextual Services. */
273
- static scopedGen<S extends ServiceClass<any, any>, Yield extends ServiceRequirement<unknown>>(service: S, factory: LayerGenerator<S, Yield>, release: (instance: InstanceType<S>, outcome: ScopeOutcome) => MaybePromise<void>): LayerResult<ProviderEntry<InstanceType<S>, LayerGeneratorRequirements<S, Yield>>>;
271
+ static scopedGen<S extends ServiceClass<any, any>, Yield extends ServiceRequirement<unknown>>(service: S, factory: LayerGenerator<S, Yield>, release: (instance: InstanceType<S>, outcome: ScopeOutcome) => MaybePromise$1<void>): LayerResult<ProviderEntry<InstanceType<S>, LayerGeneratorRequirements<S, Yield>>>;
274
272
  /** Define a provider whose acquisition can yield contextual Services. */
275
273
  static gen<S extends ServiceClass<any, any>, Yield extends ServiceRequirement<unknown>>(service: S, factory: LayerGenerator<S, Yield>): LayerResult<ProviderEntry<InstanceType<S>, LayerGeneratorRequirements<S, Yield>>>;
276
274
  /** Compose Layers without replacing providers. */
@@ -308,9 +306,9 @@ type LayerBackendDisposeOptions = {
308
306
  /** Runtime adapter responsible for registering, resolving, and disposing Layer providers. */
309
307
  interface LayerBackend extends ServiceResolver {
310
308
  /** Register one Service provider with the backend. */
311
- register(registration: LayerRegistration): MaybePromise<void>;
309
+ register(registration: LayerRegistration): MaybePromise$1<void>;
312
310
  /** Dispose all backend-owned instances and provider registrations. */
313
- disposeAll(options?: LayerBackendDisposeOptions): MaybePromise<void>;
311
+ disposeAll(options?: LayerBackendDisposeOptions): MaybePromise$1<void>;
314
312
  }
315
313
  //#endregion
316
314
  //#region src/layer/errors.d.ts
@@ -346,59 +344,6 @@ declare class LayerGeneratorYieldError extends Error {
346
344
  constructor(service: ServiceClass<any>);
347
345
  }
348
346
  //#endregion
349
- //#region src/runtime/observer.d.ts
350
- /** Event emitted after a Service resolution attempt settles. */
351
- type RuntimeServiceResolveEvent = {
352
- readonly service: AnyServiceToken;
353
- readonly resolutionPath: readonly AnyServiceToken[];
354
- readonly outcome: ScopeOutcome;
355
- };
356
- /** Event emitted after a provider acquisition attempt settles. */
357
- type RuntimeServiceAcquireEvent = {
358
- readonly service: AnyServiceToken;
359
- readonly resolutionPath: readonly AnyServiceToken[];
360
- readonly outcome: ScopeOutcome;
361
- };
362
- /** Values supplied to one Runtime execution for diagnostic correlation. */
363
- type RuntimeExecutionAttributes = Readonly<Record<string, unknown>>;
364
- /** Metadata shared by the start and end events for one execution. */
365
- type RuntimeExecutionMetadata = {
366
- readonly executionId: string;
367
- readonly name?: string;
368
- readonly attributes?: RuntimeExecutionAttributes;
369
- /** Monotonic host timestamp captured immediately before the Program starts. */
370
- readonly startedAt: number;
371
- };
372
- /** Event emitted immediately before a program starts in an execution Scope. */
373
- type RuntimeExecutionStartEvent = RuntimeExecutionMetadata & {
374
- readonly scope: Scope;
375
- };
376
- /** Event emitted after a program and its execution Scope settle. */
377
- type RuntimeExecutionEndEvent = RuntimeExecutionMetadata & {
378
- readonly scope: Scope;
379
- readonly outcome: ScopeOutcome;
380
- /** Monotonic elapsed time for the Program and its execution cleanup. */
381
- readonly durationMs: number;
382
- };
383
- /** Event emitted after a Layer provider release callback settles. */
384
- type RuntimeResourceReleaseEvent = {
385
- readonly service: AnyServiceToken;
386
- readonly outcome: ScopeOutcome;
387
- readonly error?: unknown;
388
- };
389
- /** Optional best-effort hooks for Runtime lifecycle and resolution events. */
390
- type RuntimeObserver = {
391
- readonly onServiceResolve?: (event: RuntimeServiceResolveEvent) => MaybePromise<void>;
392
- readonly onServiceAcquire?: (event: RuntimeServiceAcquireEvent) => MaybePromise<void>;
393
- readonly onExecutionStart?: (event: RuntimeExecutionStartEvent) => MaybePromise<void>;
394
- readonly onExecutionEnd?: (event: RuntimeExecutionEndEvent) => MaybePromise<void>;
395
- readonly onResourceRelease?: (event: RuntimeResourceReleaseEvent) => MaybePromise<void>;
396
- };
397
- /** Compose best-effort Runtime observers into one observer. */
398
- declare const RuntimeObserver: {
399
- compose: (...observers: readonly RuntimeObserver[]) => RuntimeObserver;
400
- };
401
- //#endregion
402
347
  //#region src/runtime/outcome.d.ts
403
348
  /** Aggregated cleanup information reported during Runtime shutdown. */
404
349
  type RuntimeShutdownDiagnostic = {
@@ -408,7 +353,7 @@ type RuntimeShutdownDiagnostic = {
408
353
  readonly error: LayerDisposeError;
409
354
  };
410
355
  /** Observer notified about cleanup failures without changing primary results. */
411
- type CleanupFailureObserver = (diagnostic: CleanupFailureDiagnostic | RuntimeShutdownDiagnostic) => MaybePromise$1<void>;
356
+ type CleanupFailureObserver = (diagnostic: CleanupFailureDiagnostic | RuntimeShutdownDiagnostic) => MaybePromise<void>;
412
357
  /** Optional Runtime configuration for cleanup diagnostics. */
413
358
  type RuntimeOptions = {
414
359
  /** Backend used to register and resolve the Layer. Defaults to MapLayerBackend. */
@@ -438,5 +383,5 @@ type RuntimeDisposeOptions = {
438
383
  readonly abortAfterGracePeriod?: boolean;
439
384
  };
440
385
  //#endregion
441
- export { MissingServices as A, CompleteExecution as C, LayerInput as D, ExecutionMissing as E, ValidateOneOverride as F, ValidateOverrides as I, ValidateOverridesWitness as L, ProvidedEnvironment as M, RequiredEnvironment as N, LayerInputState as O, ValidateLayerInput as P, ProviderEntry as R, LayerRegistration as S, CompleteInput as T, LayerRegistrationError as _, RuntimeShutdownDiagnostic as a, LayerBackendDisposeOptions as b, RuntimeExecutionMetadata as c, RuntimeResourceReleaseEvent as d, RuntimeServiceAcquireEvent as f, LayerGeneratorYieldError as g, LayerDisposeError as h, RuntimeRunOptions as i, OverrideLayerResult as j, LayerResult as k, RuntimeExecutionStartEvent as l, DuplicateServiceError as m, RuntimeDisposeOptions as n, RuntimeExecutionAttributes as o, RuntimeServiceResolveEvent as p, RuntimeOptions as r, RuntimeExecutionEndEvent as s, CleanupFailureObserver as t, RuntimeObserver as u, ServiceTagCollisionError as v, CompleteExecutionLayer as w, Layer as x, LayerBackend as y, MissingDependencies as z };
442
- //# sourceMappingURL=outcome-CB43bnFW.d.mts.map
386
+ export { ProviderEntry as A, OverrideLayerResult as C, ValidateOneOverride as D, ValidateLayerInput as E, ValidateOverrides as O, MissingServices as S, RequiredEnvironment as T, CompleteInput as _, RuntimeShutdownDiagnostic as a, LayerInputState as b, LayerGeneratorYieldError as c, LayerBackend as d, LayerBackendDisposeOptions as f, CompleteExecutionLayer as g, CompleteExecution as h, RuntimeRunOptions as i, MissingDependencies as j, ValidateOverridesWitness as k, LayerRegistrationError as l, LayerRegistration as m, RuntimeDisposeOptions as n, DuplicateServiceError as o, Layer as p, RuntimeOptions as r, LayerDisposeError as s, CleanupFailureObserver as t, ServiceTagCollisionError as u, ExecutionMissing as v, ProvidedEnvironment as w, LayerResult as x, LayerInput as y };
387
+ //# sourceMappingURL=outcome-DI8LPIQ4.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"outcome-DI8LPIQ4.d.mts","names":[],"sources":["../src/internal/variance.ts","../src/internal/missing-dependencies.ts","../src/layer/metadata.ts","../src/layer/inference.ts","../src/layer/types.ts","../src/layer/layer.ts","../src/layer/backend.ts","../src/layer/errors.ts","../src/runtime/outcome.ts"],"mappings":";;;;KACY,UAAU,WAAW;;KAGrB,UAA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,MAAM;SAEtB,SAAS,aAAa,kBAAkB,2BAA2B,cACxE,MAAM,OAAO,mBAAmB,UAC7B,WAAW,YAAY,kBAAkB,MAAM,aACjD,oBAAoB,MAAM;;;kBAuCN;;OAEX,MAAM;;OAGN,SAAS,UAAU,cAAc,oBAAoB;;OAGrD,SAAS,UAAU,cAAc,oBAAoB;;OAGrD,QAAQ,UAAU,cAAc,oBAAoB;;OAGpD,SAAS,UAAU,cAAc,cAAc;;;;;KCjYjD;;;;;WAKD,yBACP,uBAAuB,8BACb;;;UAIG,qBAAqB;;EAEpC,SAAS,cAAc,oBAAoB;;EAG3C,WAAW,UAAU,6BAA6B;;;;KClB/C,aAAa,QAAQ;WAAyB;;;cAGtC,8BAA8B;WACpB,SAAS;EAAT,YAAA,SAAS;;;cAQnB,iCAAiC;WAEjC,UAAU;WACV,UAAU;EADV,YAAA,UAAU,iBACV,UAAU;;;cAYV,+BAA+B;WAE/B,SAAS;WACT,mBAAmB;WACnB,eAAe;EAFf,YAAA,SAAS,+BACT,mBAAmB,YACnB,eAAe;;;cAgBf,0BAA0B;WAChB;EAAA,YAAA;;;cAQV,iCAAiC;WACvB,SAAS;EAAT,YAAA,SAAS;;;;;KChDpB;;WAED,SAAS;;WAET,OAAO;;;KAIN,0BACV,YAAY,2BAA2B,8BACpC;;KAGO;;WAED,UAAU;;WAEV;;WAEA,qBAAqB;;WAErB,mBAAmB;;WAEnB,iBAAiB;;WAEjB,SAAS;;;KAIR;WACD,SAAS;;WAET,aAAa;;;KAIZ;;WAED;;WAEA"}
@@ -1,5 +1,5 @@
1
- import { h as RuntimeContextNotConfiguredError, i as getRuntimeContext, l as makeRuntimeContext, n as currentRuntimeContext, t as activeRuntimeContextStorage, u as runRuntimeContext } from "./context-BUEf1qjL.mjs";
2
- import { a as ResourceNotDisposableError, c as ScopeRuntimeNotConfiguredError, i as getDisposeFinalizer, o as ScopeCloseError, s as ScopeClosedError } from "./signal-D2UTcaaG.mjs";
1
+ import { h as RuntimeContextNotConfiguredError, i as getRuntimeContext, l as makeRuntimeContext, n as currentRuntimeContext, t as activeRuntimeContextStorage, u as runRuntimeContext } from "./context-BphfFUMO.mjs";
2
+ import { a as ScopeClosedError, i as ScopeCloseError, n as getDisposeFinalizer, o as ScopeRuntimeNotConfiguredError, r as ResourceNotDisposableError } from "./disposable-CP-Q2H3l.mjs";
3
3
  //#region src/scope/runtime.ts
4
4
  const scopeStorages = /* @__PURE__ */ new WeakMap();
5
5
  /** Bridges the current Scope through async execution context. */
@@ -257,4 +257,4 @@ const inheritProgramName = (source, derived) => {
257
257
  //#endregion
258
258
  export { runScoped as a, Scope as i, inheritProgramName as n, ScopeRuntime as o, setProgramName as r, getProgramName as t };
259
259
 
260
- //# sourceMappingURL=program-metadata-DhQCCirO.mjs.map
260
+ //# sourceMappingURL=program-metadata-BxjGkT17.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"program-metadata-DhQCCirO.mjs","names":[],"sources":["../src/scope/runtime.ts","../src/scope/internal.ts","../src/scope/scope.ts","../src/effect/program-metadata.ts"],"sourcesContent":["import { ScopeRuntimeNotConfiguredError } from './errors'\n\nimport { RuntimeContextNotConfiguredError } from '../runtime/errors'\n\nimport type { Scope } from './scope'\n\nimport {\n activeRuntimeContextStorage,\n currentRuntimeContext,\n getRuntimeContext,\n makeRuntimeContext,\n runRuntimeContext\n} from '../runtime/context'\n\nimport type { RuntimeContextStorage } from '../runtime/context'\n\nconst scopeStorages = new WeakMap<object, RuntimeContextStorage>()\n\n/** Bridges the current Scope through async execution context. */\nexport class ScopeRuntime {\n /** Supply a Scope while invoking a callback. */\n static run<A>(\n scope: Scope,\n program: () => A,\n storage: RuntimeContextStorage = scopeStorages.get(scope) ?? activeRuntimeContextStorage()\n ): A {\n scopeStorages.set(scope, storage)\n\n const current = getRuntimeContext(storage)\n const context = makeRuntimeContext(\n current?.resolver,\n scope,\n current?.resolutionPath ?? [],\n current?.signal,\n current\n )\n\n return runRuntimeContext(storage, context, program)\n }\n\n /** Return the Scope active in the current execution context. */\n static current(): Scope {\n let context\n\n try {\n context = currentRuntimeContext()\n } catch (cause) {\n if (cause instanceof RuntimeContextNotConfiguredError) {\n throw new ScopeRuntimeNotConfiguredError()\n }\n\n throw cause\n }\n\n if (!context.scope) {\n throw new ScopeRuntimeNotConfiguredError()\n }\n\n return context.scope\n }\n\n /** Associate a Runtime-owned Scope with its context storage. */\n static bind(scope: Scope, storage: RuntimeContextStorage): void {\n scopeStorages.set(scope, storage)\n }\n}\n","import { ScopeCloseError } from './errors'\n\nimport { ScopeRuntime } from './runtime'\n\nimport type { CloseableScope } from './scope'\n\nimport {\n runRuntimeContext,\n type CompleteRuntimeContext,\n type RuntimeContextStorage\n} from '../runtime/context'\n\nimport type { CleanupFailureDiagnostic, MaybePromise, ScopeOutcome } from './types'\n\nexport type OutcomeClassifier<A> = (value: A) => ScopeOutcome\n\nexport type RunScopedOptions<A> = {\n readonly classify: OutcomeClassifier<A>\n readonly onOutcome?: (outcome: ScopeOutcome) => void\n readonly onCleanupFailure?: (diagnostic: CleanupFailureDiagnostic) => MaybePromise<void>\n readonly contextStorage?: RuntimeContextStorage\n readonly context?: CompleteRuntimeContext\n}\n\nconst notifyCleanupFailure = async (\n observer: ((diagnostic: CleanupFailureDiagnostic) => MaybePromise<void>) | undefined,\n diagnostic: CleanupFailureDiagnostic\n): Promise<void> => {\n if (!observer) {\n return\n }\n\n try {\n await observer(diagnostic)\n } catch {\n // Cleanup diagnostics are best effort and never affect the primary result.\n }\n}\n\nexport const runScoped = async <A>(\n scope: CloseableScope,\n program: () => A | PromiseLike<A>,\n options: RunScopedOptions<Awaited<A>>\n): Promise<Awaited<A>> => {\n let value!: Awaited<A>\n\n let programFailed = false\n let programFailure: unknown\n\n try {\n const run = () => ScopeRuntime.run(scope, program, options.contextStorage)\n\n value = await (options.context && options.contextStorage\n ? runRuntimeContext(options.contextStorage, options.context, run)\n : run())\n } catch (cause) {\n programFailed = true\n programFailure = cause\n }\n\n let outcome: ScopeOutcome\n let outcomeStatus: ScopeOutcome['status']\n\n if (programFailed) {\n outcome = {\n status: 'failure',\n cause: programFailure\n }\n outcomeStatus = 'failure'\n } else {\n try {\n outcome = options.classify(value)\n // Read the discriminant before cleanup so a throwing classifier or proxy is a program failure.\n outcomeStatus = outcome.status\n } catch (cause) {\n programFailed = true\n programFailure = cause\n outcome = {\n status: 'failure',\n cause\n }\n outcomeStatus = 'failure'\n }\n }\n\n options.onOutcome?.(outcome)\n\n let cleanupFailed = false\n let cleanupFailure: unknown\n\n try {\n await scope.close(outcome)\n } catch (cause) {\n cleanupFailed = true\n cleanupFailure = cause\n }\n\n if (cleanupFailed) {\n const error =\n cleanupFailure instanceof ScopeCloseError\n ? cleanupFailure\n : new ScopeCloseError([cleanupFailure])\n\n await notifyCleanupFailure(options.onCleanupFailure, {\n outcome,\n error\n })\n\n cleanupFailure = error\n }\n\n if (programFailed) {\n throw programFailure\n }\n\n if (outcomeStatus === 'failure') {\n return value\n }\n\n if (cleanupFailed) {\n throw cleanupFailure\n }\n\n return value\n}\n","import { ResourceNotDisposableError, ScopeCloseError, ScopeClosedError } from './errors'\n\nimport { getDisposeFinalizer } from './disposable'\n\nimport { runScoped } from './internal'\n\nimport { ScopeRuntime } from './runtime'\n\nimport type { DisposableResource, MaybePromise, ScopeFinalizer, ScopeOutcome } from './types'\n\n/**\n * Non-owning lifecycle context for finalizers and child Scopes.\n *\n * A Scope can register cleanup and create children, but it cannot close\n * itself. Use `Scope.make()` or `Scope.run()` when your code owns the Scope.\n */\nexport interface Scope {\n /** Register a finalizer that runs when the owning Scope closes. */\n addFinalizer(finalizer: ScopeFinalizer): void\n\n /** Acquire a resource and register its outcome-aware release callback. */\n acquire<R>(\n acquire: () => MaybePromise<R>,\n release: (resource: R, outcome: ScopeOutcome) => MaybePromise<void>\n ): Promise<R>\n\n /** Register an already-acquired disposable resource. */\n add<R extends DisposableResource>(resource: R): Promise<R>\n\n /** Create a child Scope owned by this Scope. */\n fork(): CloseableScope\n}\n\n/** A Scope whose owner is responsible for calling `close()`. */\nexport interface CloseableScope extends Scope {\n /** Close the Scope and run children and finalizers in child-first LIFO order. */\n close(outcome?: ScopeOutcome): Promise<void>\n}\n\nconst SCOPE_SUCCESS: ScopeOutcome = Object.freeze({ status: 'success' })\n\nclass ScopeImpl implements CloseableScope {\n private readonly children = new Set<ScopeImpl>()\n\n private readonly finalizers: ScopeFinalizer[] = []\n\n private closePromise: Promise<void> | undefined\n\n private closeOutcome: ScopeOutcome | undefined\n\n constructor(private parent?: ScopeImpl) {}\n\n fork(): CloseableScope {\n this.assertOpen()\n\n const child = new ScopeImpl(this)\n\n this.children.add(child)\n\n return child\n }\n\n addFinalizer(finalizer: ScopeFinalizer): void {\n this.assertOpen()\n\n this.finalizers.push(finalizer)\n }\n\n async acquire<R>(\n acquire: () => MaybePromise<R>,\n release: (resource: R, outcome: ScopeOutcome) => MaybePromise<void>\n ): Promise<R> {\n this.assertOpen()\n\n const resource = await acquire()\n\n try {\n this.addFinalizer((outcome) => release(resource, outcome))\n\n return resource\n } catch (scopeFailure) {\n try {\n await release(resource, this.closeOutcome ?? SCOPE_SUCCESS)\n } catch (releaseFailure) {\n throw new AggregateError(\n [scopeFailure, releaseFailure],\n 'Scope closed while acquiring a resource and immediate cleanup also failed'\n )\n }\n\n throw scopeFailure\n }\n }\n\n async add<R extends DisposableResource>(resource: R): Promise<R> {\n const finalizer = getDisposeFinalizer(resource)\n\n if (!finalizer) {\n throw new ResourceNotDisposableError()\n }\n\n try {\n this.addFinalizer(finalizer)\n\n return resource\n } catch (scopeFailure) {\n try {\n await finalizer(this.closeOutcome ?? SCOPE_SUCCESS)\n } catch (releaseFailure) {\n throw new AggregateError(\n [scopeFailure, releaseFailure],\n 'Scope closed while adding a disposable resource and cleanup also failed'\n )\n }\n\n throw scopeFailure\n }\n }\n\n close(outcome: ScopeOutcome = SCOPE_SUCCESS): Promise<void> {\n if (this.closePromise) {\n return this.closePromise\n }\n\n this.closeOutcome = outcome\n this.closePromise = Promise.resolve().then(() => this.closeWithRuntime(outcome))\n\n return this.closePromise\n }\n\n private async closeWithRuntime(outcome: ScopeOutcome): Promise<void> {\n let started = false\n\n try {\n await ScopeRuntime.run(this, () => {\n started = true\n return this.closeInternal(outcome)\n })\n } catch (storageFailure) {\n if (started) {\n throw storageFailure\n }\n\n // Context propagation cannot prevent direct Scope cleanup.\n try {\n await this.closeInternal(outcome)\n } catch (cleanupFailure) {\n const cleanupCauses =\n cleanupFailure instanceof ScopeCloseError ? cleanupFailure.causes : [cleanupFailure]\n\n throw new ScopeCloseError([storageFailure, ...cleanupCauses])\n }\n\n throw storageFailure\n }\n }\n\n private async closeInternal(outcome: ScopeOutcome): Promise<void> {\n const failures: unknown[] = []\n\n const children = [...this.children]\n\n this.children.clear()\n\n for (let index = children.length - 1; index >= 0; index--) {\n const child = children[index]\n\n if (!child) {\n continue\n }\n\n try {\n await child.close(outcome)\n } catch (cause) {\n if (cause instanceof ScopeCloseError) {\n failures.push(...cause.causes)\n } else {\n failures.push(cause)\n }\n }\n }\n\n for (let index = this.finalizers.length - 1; index >= 0; index--) {\n const finalizer = this.finalizers[index]\n\n if (!finalizer) {\n continue\n }\n\n try {\n await finalizer(outcome)\n } catch (cause) {\n failures.push(cause)\n }\n }\n\n this.finalizers.length = 0\n\n this.detach()\n\n if (failures.length > 0) {\n throw new ScopeCloseError(failures)\n }\n }\n\n private detach(): void {\n const parent = this.parent\n\n if (!parent) {\n return\n }\n\n parent.children.delete(this)\n this.parent = undefined\n }\n\n private assertOpen(): void {\n if (this.closePromise) {\n throw new ScopeClosedError()\n }\n }\n}\n\nexport const Scope = {\n /** Create an owned, initially open Scope. */\n make(): CloseableScope {\n return new ScopeImpl()\n },\n\n /** Return the non-owning Scope available in the current execution context. */\n current(): Scope {\n return ScopeRuntime.current()\n },\n\n /** Run a callback with an existing Scope supplied as the current context. */\n provide<A>(scope: Scope, program: () => A): A {\n return ScopeRuntime.run(scope, program)\n },\n\n /** Resolve the current Scope through `yield* Scope` inside an Effect. */\n // oxlint-disable-next-line require-yield\n *[Symbol.iterator](): Generator<never, Scope, unknown> {\n return ScopeRuntime.current()\n },\n\n /**\n * Run a program in a newly owned Scope.\n *\n * Scope is independent from `better-result`, so returned values—including\n * `Result.err`—close this Scope with a successful outcome. Result-aware\n * outcome classification belongs to `Runtime.run`.\n *\n * @example\n * ```ts\n * await Scope.run(async (scope) => {\n * const connection = await scope.acquire(connect, (connection) => connection.close())\n * return connection.query()\n * })\n * ```\n */\n run<A>(program: (scope: Scope) => A | PromiseLike<A>): Promise<Awaited<A>> {\n const scope = new ScopeImpl()\n\n return runScoped(scope, () => program(scope), {\n classify: () => SCOPE_SUCCESS\n })\n }\n} as const\n\n/** Type-level aliases for Scope ownership, outcomes, and cleanup contracts. */\nexport declare namespace Scope {\n /** A Scope whose owner is responsible for calling `close()`. */\n export type Closeable = CloseableScope\n\n /** The outcome supplied to Scope finalizers and resource releases. */\n export type Outcome = ScopeOutcome\n\n /** A cleanup callback registered with a Scope. */\n export type Finalizer = ScopeFinalizer\n\n /** A value implementing a JavaScript disposal protocol. */\n export type Disposable = DisposableResource\n}\n","export type ProgramIdentity = (...arguments_: never[]) => void\n\nconst programNames = new WeakMap<ProgramIdentity, string>()\n\n/** Return the private diagnostic name attached to a callable Program. */\nexport const getProgramName = (program: ProgramIdentity): string | undefined =>\n programNames.get(program)\n\n/** Attach a name without changing the callable Program facade. */\nexport const setProgramName = <Program extends ProgramIdentity>(\n program: Program,\n name: string\n): Program => {\n programNames.set(program, name)\n return program\n}\n\n/** Copy a source Program's name to a lazily-created derived Program. */\nexport const inheritProgramName = <Source extends ProgramIdentity, Derived extends ProgramIdentity>(\n source: Source,\n derived: Derived\n): Derived => {\n const name = getProgramName(source)\n\n return name === undefined ? derived : setProgramName(derived, name)\n}\n"],"mappings":";;;AAgBA,MAAM,gCAAgB,IAAI,QAAuC;;AAGjE,IAAa,eAAb,MAA0B;;CAExB,OAAO,IACL,OACA,SACA,UAAiC,cAAc,IA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AS,GAAG,SAAS;GAChE,MAAM,YAAY,KAAK,WAAW;GAElC,IAAI,CAAC,WACH;GAGF,IAAI;IACF,MAAM,UAAU,OAAO;GACzB,SAAS,OAAO;IACd,SAAS,KAAK,KAAK;GACrB;EACF;EAEA,KAAK,WAAW,SAAS;EAEzB,KAAK,OAAO;EAEZ,IAAI,SAAS,SAAS,GACpB,MAAM,IAAI,gBAAgB,QAAQ;CAEtC;CAEA,SAAuB;EACrB,MAAM,SAAS,KAAK;EAEpB,IAAI,CAAC,QACH;EAGF,OAAO,SAAS,OAAO,IAAI;EAC3B,KAAK,SAAS,KAAA;CAChB;CAEA,aAA2B;EACzB,IAAI,KAAK,cACP,MAAM,IAAI,iBAAiB;CAE/B;AACF;AAEA,MAAa,QAAQ;;CAEnB,OAAuB;EACrB,OAAO,IAAI,UAAU;CACvB;;CAGA,UAAiB;EACf,OAAO,aAAa,QAAQ;CAC9B;;CAGA,QAAW,OAAc,SAAqB;EAC5C,OAAO,aAAa,IAAI,OAAO,OAAO;CACxC;;CAIA,EAAE,OAAO,YAA8C;EACrD,OAAO,aAAa,QAAQ;CAC9B;;;;;;;;;;;;;;;;CAiBA,IAAO,SAAoE;EACzE,MAAM,QAAQ,IAAI,UAAU;EAE5B,OAAO,UAAU,aAAa,QAAQ,KAAK,GAAG,EAC5C,gBAAgB,cAClB,CAAC;CACH;AACF;;;ACzQA,MAAM,+BAAe,IAAI,QAAiC;;AAG1D,MAAa,kBAAkB,YAC7B,aAAa,IAAI,OAAO;;AAG1B,MAAa,kBACX,SACA,SACY;CACZ,aAAa,IAAI,SAAS,IAAI;CAC9B,OAAO;AACT;;AAGA,MAAa,sBACX,QACA,YACY;CACZ,MAAM,OAAO,eAAe,MAAM;CAElC,OAAO,SAAS,KAAA,IAAY,UAAU,eAAe,SAAS,IAAI;AACpE"}
1
+ {"version":3,"file":"program-metadata-BxjGkT17.mjs","names":[],"sources":["../src/scope/runtime.ts","../src/scope/internal.ts","../src/scope/scope.ts","../src/effect/program-metadata.ts"],"sourcesContent":["import { ScopeRuntimeNotConfiguredError } from './errors'\n\nimport { RuntimeContextNotConfiguredError } from '../runtime/errors'\n\nimport type { Scope } from './scope'\n\nimport {\n activeRuntimeContextStorage,\n currentRuntimeContext,\n getRuntimeContext,\n makeRuntimeContext,\n runRuntimeContext\n} from '../runtime/context'\n\nimport type { RuntimeContextStorage } from '../runtime/context'\n\nconst scopeStorages = new WeakMap<object, RuntimeContextStorage>()\n\n/** Bridges the current Scope through async execution context. */\nexport class ScopeRuntime {\n /** Supply a Scope while invoking a callback. */\n static run<A>(\n scope: Scope,\n program: () => A,\n storage: RuntimeContextStorage = scopeStorages.get(scope) ?? activeRuntimeContextStorage()\n ): A {\n scopeStorages.set(scope, storage)\n\n const current = getRuntimeContext(storage)\n const context = makeRuntimeContext(\n current?.resolver,\n scope,\n current?.resolutionPath ?? [],\n current?.signal,\n current\n )\n\n return runRuntimeContext(storage, context, program)\n }\n\n /** Return the Scope active in the current execution context. */\n static current(): Scope {\n let context\n\n try {\n context = currentRuntimeContext()\n } catch (cause) {\n if (cause instanceof RuntimeContextNotConfiguredError) {\n throw new ScopeRuntimeNotConfiguredError()\n }\n\n throw cause\n }\n\n if (!context.scope) {\n throw new ScopeRuntimeNotConfiguredError()\n }\n\n return context.scope\n }\n\n /** Associate a Runtime-owned Scope with its context storage. */\n static bind(scope: Scope, storage: RuntimeContextStorage): void {\n scopeStorages.set(scope, storage)\n }\n}\n","import { ScopeCloseError } from './errors'\n\nimport { ScopeRuntime } from './runtime'\n\nimport type { CloseableScope } from './scope'\n\nimport {\n runRuntimeContext,\n type CompleteRuntimeContext,\n type RuntimeContextStorage\n} from '../runtime/context'\n\nimport type { CleanupFailureDiagnostic, MaybePromise, ScopeOutcome } from './types'\n\nexport type OutcomeClassifier<A> = (value: A) => ScopeOutcome\n\nexport type RunScopedOptions<A> = {\n readonly classify: OutcomeClassifier<A>\n readonly onOutcome?: (outcome: ScopeOutcome) => void\n readonly onCleanupFailure?: (diagnostic: CleanupFailureDiagnostic) => MaybePromise<void>\n readonly contextStorage?: RuntimeContextStorage\n readonly context?: CompleteRuntimeContext\n}\n\nconst notifyCleanupFailure = async (\n observer: ((diagnostic: CleanupFailureDiagnostic) => MaybePromise<void>) | undefined,\n diagnostic: CleanupFailureDiagnostic\n): Promise<void> => {\n if (!observer) {\n return\n }\n\n try {\n await observer(diagnostic)\n } catch {\n // Cleanup diagnostics are best effort and never affect the primary result.\n }\n}\n\nexport const runScoped = async <A>(\n scope: CloseableScope,\n program: () => A | PromiseLike<A>,\n options: RunScopedOptions<Awaited<A>>\n): Promise<Awaited<A>> => {\n let value!: Awaited<A>\n\n let programFailed = false\n let programFailure: unknown\n\n try {\n const run = () => ScopeRuntime.run(scope, program, options.contextStorage)\n\n value = await (options.context && options.contextStorage\n ? runRuntimeContext(options.contextStorage, options.context, run)\n : run())\n } catch (cause) {\n programFailed = true\n programFailure = cause\n }\n\n let outcome: ScopeOutcome\n let outcomeStatus: ScopeOutcome['status']\n\n if (programFailed) {\n outcome = {\n status: 'failure',\n cause: programFailure\n }\n outcomeStatus = 'failure'\n } else {\n try {\n outcome = options.classify(value)\n // Read the discriminant before cleanup so a throwing classifier or proxy is a program failure.\n outcomeStatus = outcome.status\n } catch (cause) {\n programFailed = true\n programFailure = cause\n outcome = {\n status: 'failure',\n cause\n }\n outcomeStatus = 'failure'\n }\n }\n\n options.onOutcome?.(outcome)\n\n let cleanupFailed = false\n let cleanupFailure: unknown\n\n try {\n await scope.close(outcome)\n } catch (cause) {\n cleanupFailed = true\n cleanupFailure = cause\n }\n\n if (cleanupFailed) {\n const error =\n cleanupFailure instanceof ScopeCloseError\n ? cleanupFailure\n : new ScopeCloseError([cleanupFailure])\n\n await notifyCleanupFailure(options.onCleanupFailure, {\n outcome,\n error\n })\n\n cleanupFailure = error\n }\n\n if (programFailed) {\n throw programFailure\n }\n\n if (outcomeStatus === 'failure') {\n return value\n }\n\n if (cleanupFailed) {\n throw cleanupFailure\n }\n\n return value\n}\n","import { ResourceNotDisposableError, ScopeCloseError, ScopeClosedError } from './errors'\n\nimport { getDisposeFinalizer } from './disposable'\n\nimport { runScoped } from './internal'\n\nimport { ScopeRuntime } from './runtime'\n\nimport type { DisposableResource, MaybePromise, ScopeFinalizer, ScopeOutcome } from './types'\n\n/**\n * Non-owning lifecycle context for finalizers and child Scopes.\n *\n * A Scope can register cleanup and create children, but it cannot close\n * itself. Use `Scope.make()` or `Scope.run()` when your code owns the Scope.\n */\nexport interface Scope {\n /** Register a finalizer that runs when the owning Scope closes. */\n addFinalizer(finalizer: ScopeFinalizer): void\n\n /** Acquire a resource and register its outcome-aware release callback. */\n acquire<R>(\n acquire: () => MaybePromise<R>,\n release: (resource: R, outcome: ScopeOutcome) => MaybePromise<void>\n ): Promise<R>\n\n /** Register an already-acquired disposable resource. */\n add<R extends DisposableResource>(resource: R): Promise<R>\n\n /** Create a child Scope owned by this Scope. */\n fork(): CloseableScope\n}\n\n/** A Scope whose owner is responsible for calling `close()`. */\nexport interface CloseableScope extends Scope {\n /** Close the Scope and run children and finalizers in child-first LIFO order. */\n close(outcome?: ScopeOutcome): Promise<void>\n}\n\nconst SCOPE_SUCCESS: ScopeOutcome = Object.freeze({ status: 'success' })\n\nclass ScopeImpl implements CloseableScope {\n private readonly children = new Set<ScopeImpl>()\n\n private readonly finalizers: ScopeFinalizer[] = []\n\n private closePromise: Promise<void> | undefined\n\n private closeOutcome: ScopeOutcome | undefined\n\n constructor(private parent?: ScopeImpl) {}\n\n fork(): CloseableScope {\n this.assertOpen()\n\n const child = new ScopeImpl(this)\n\n this.children.add(child)\n\n return child\n }\n\n addFinalizer(finalizer: ScopeFinalizer): void {\n this.assertOpen()\n\n this.finalizers.push(finalizer)\n }\n\n async acquire<R>(\n acquire: () => MaybePromise<R>,\n release: (resource: R, outcome: ScopeOutcome) => MaybePromise<void>\n ): Promise<R> {\n this.assertOpen()\n\n const resource = await acquire()\n\n try {\n this.addFinalizer((outcome) => release(resource, outcome))\n\n return resource\n } catch (scopeFailure) {\n try {\n await release(resource, this.closeOutcome ?? SCOPE_SUCCESS)\n } catch (releaseFailure) {\n throw new AggregateError(\n [scopeFailure, releaseFailure],\n 'Scope closed while acquiring a resource and immediate cleanup also failed'\n )\n }\n\n throw scopeFailure\n }\n }\n\n async add<R extends DisposableResource>(resource: R): Promise<R> {\n const finalizer = getDisposeFinalizer(resource)\n\n if (!finalizer) {\n throw new ResourceNotDisposableError()\n }\n\n try {\n this.addFinalizer(finalizer)\n\n return resource\n } catch (scopeFailure) {\n try {\n await finalizer(this.closeOutcome ?? SCOPE_SUCCESS)\n } catch (releaseFailure) {\n throw new AggregateError(\n [scopeFailure, releaseFailure],\n 'Scope closed while adding a disposable resource and cleanup also failed'\n )\n }\n\n throw scopeFailure\n }\n }\n\n close(outcome: ScopeOutcome = SCOPE_SUCCESS): Promise<void> {\n if (this.closePromise) {\n return this.closePromise\n }\n\n this.closeOutcome = outcome\n this.closePromise = Promise.resolve().then(() => this.closeWithRuntime(outcome))\n\n return this.closePromise\n }\n\n private async closeWithRuntime(outcome: ScopeOutcome): Promise<void> {\n let started = false\n\n try {\n await ScopeRuntime.run(this, () => {\n started = true\n return this.closeInternal(outcome)\n })\n } catch (storageFailure) {\n if (started) {\n throw storageFailure\n }\n\n // Context propagation cannot prevent direct Scope cleanup.\n try {\n await this.closeInternal(outcome)\n } catch (cleanupFailure) {\n const cleanupCauses =\n cleanupFailure instanceof ScopeCloseError ? cleanupFailure.causes : [cleanupFailure]\n\n throw new ScopeCloseError([storageFailure, ...cleanupCauses])\n }\n\n throw storageFailure\n }\n }\n\n private async closeInternal(outcome: ScopeOutcome): Promise<void> {\n const failures: unknown[] = []\n\n const children = [...this.children]\n\n this.children.clear()\n\n for (let index = children.length - 1; index >= 0; index--) {\n const child = children[index]\n\n if (!child) {\n continue\n }\n\n try {\n await child.close(outcome)\n } catch (cause) {\n if (cause instanceof ScopeCloseError) {\n failures.push(...cause.causes)\n } else {\n failures.push(cause)\n }\n }\n }\n\n for (let index = this.finalizers.length - 1; index >= 0; index--) {\n const finalizer = this.finalizers[index]\n\n if (!finalizer) {\n continue\n }\n\n try {\n await finalizer(outcome)\n } catch (cause) {\n failures.push(cause)\n }\n }\n\n this.finalizers.length = 0\n\n this.detach()\n\n if (failures.length > 0) {\n throw new ScopeCloseError(failures)\n }\n }\n\n private detach(): void {\n const parent = this.parent\n\n if (!parent) {\n return\n }\n\n parent.children.delete(this)\n this.parent = undefined\n }\n\n private assertOpen(): void {\n if (this.closePromise) {\n throw new ScopeClosedError()\n }\n }\n}\n\nexport const Scope = {\n /** Create an owned, initially open Scope. */\n make(): CloseableScope {\n return new ScopeImpl()\n },\n\n /** Return the non-owning Scope available in the current execution context. */\n current(): Scope {\n return ScopeRuntime.current()\n },\n\n /** Run a callback with an existing Scope supplied as the current context. */\n provide<A>(scope: Scope, program: () => A): A {\n return ScopeRuntime.run(scope, program)\n },\n\n /** Resolve the current Scope through `yield* Scope` inside an Effect. */\n // oxlint-disable-next-line require-yield\n *[Symbol.iterator](): Generator<never, Scope, unknown> {\n return ScopeRuntime.current()\n },\n\n /**\n * Run a program in a newly owned Scope.\n *\n * Scope is independent from `better-result`, so returned values—including\n * `Result.err`—close this Scope with a successful outcome. Result-aware\n * outcome classification belongs to `Runtime.run`.\n *\n * @example\n * ```ts\n * await Scope.run(async (scope) => {\n * const connection = await scope.acquire(connect, (connection) => connection.close())\n * return connection.query()\n * })\n * ```\n */\n run<A>(program: (scope: Scope) => A | PromiseLike<A>): Promise<Awaited<A>> {\n const scope = new ScopeImpl()\n\n return runScoped(scope, () => program(scope), {\n classify: () => SCOPE_SUCCESS\n })\n }\n} as const\n\n/** Type-level aliases for Scope ownership, outcomes, and cleanup contracts. */\nexport declare namespace Scope {\n /** A Scope whose owner is responsible for calling `close()`. */\n export type Closeable = CloseableScope\n\n /** The outcome supplied to Scope finalizers and resource releases. */\n export type Outcome = ScopeOutcome\n\n /** A cleanup callback registered with a Scope. */\n export type Finalizer = ScopeFinalizer\n\n /** A value implementing a JavaScript disposal protocol. */\n export type Disposable = DisposableResource\n}\n","export type ProgramIdentity = (...arguments_: never[]) => void\n\nconst programNames = new WeakMap<ProgramIdentity, string>()\n\n/** Return the private diagnostic name attached to a callable Program. */\nexport const getProgramName = (program: ProgramIdentity): string | undefined =>\n programNames.get(program)\n\n/** Attach a name without changing the callable Program facade. */\nexport const setProgramName = <Program extends ProgramIdentity>(\n program: Program,\n name: string\n): Program => {\n programNames.set(program, name)\n return program\n}\n\n/** Copy a source Program's name to a lazily-created derived Program. */\nexport const inheritProgramName = <Source extends ProgramIdentity, Derived extends ProgramIdentity>(\n source: Source,\n derived: Derived\n): Derived => {\n const name = getProgramName(source)\n\n return name === undefined ? derived : setProgramName(derived, name)\n}\n"],"mappings":";;;AAgBA,MAAM,gCAAgB,IAAI,QAAuC;;AAGjE,IAAa,eAAb,MAA0B;;CAExB,OAAO,IACL,OACA,SACA,UAAiC,cAAc,IAAI,KAAK,KAAK,4BAA4B,GACtF;EACH,cAAc,IAAI,OAAO,OAAO;EAEhC,MAAM,UAAU,kBAAkB,OAAO;EACzC,MAAM,UAAU,mBACd,SAAS,UACT,OACA,SAAS,kBAAkB,CAAC,GAC5B,SAAS,QACT,OACF;EAEA,OAAO,kBAAkB,SAAS,SAAS,OAAO;CACpD;;CAGA,OAAO,UAAiB;EACtB,IAAI;EAEJ,IAAI;GACF,UAAU,sBAAsB;EAClC,SAAS,OAAO;GACd,IAAI,iBAAiB,kCACnB,MAAM,IAAI,+BAA+B;GAG3C,MAAM;EACR;EAEA,IAAI,CAAC,QAAQ,OACX,MAAM,IAAI,+BAA+B;EAG3C,OAAO,QAAQ;CACjB;;CAGA,OAAO,KAAK,OAAc,SAAsC;EAC9D,cAAc,IAAI,OAAO,OAAO;CAClC;AACF;;;ACzCA,MAAM,uBAAuB,OAC3B,UACA,eACkB;CAClB,IAAI,CAAC,UACH;CAGF,IAAI;EACF,MAAM,SAAS,UAAU;CAC3B,QAAQ,CAER;A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IA,EAAE,OAAO,YAA8C;EACrD,OAAO,aAAa,QAAQ;CAC9B;;;;;;;;;;;;;;;;CAiBA,IAAO,SAAoE;EACzE,MAAM,QAAQ,IAAI,UAAU;EAE5B,OAAO,UAAU,aAAa,QAAQ,KAAK,GAAG,EAC5C,gBAAgB,cAClB,CAAC;CACH;AACF;;;ACzQA,MAAM,+BAAe,IAAI,QAAiC;;AAG1D,MAAa,kBAAkB,YAC7B,aAAa,IAAI,OAAO;;AAG1B,MAAa,kBACX,SACA,SACY;CACZ,aAAa,IAAI,SAAS,IAAI;CAC9B,OAAO;AACT;;AAGA,MAAa,sBACX,QACA,YACY;CACZ,MAAM,OAAO,eAAe,MAAM;CAElC,OAAO,SAAS,KAAA,IAAY,UAAU,eAAe,SAAS,IAAI;AACpE"}
@@ -1,4 +1,4 @@
1
- import { c as RuntimeContextStorage, s as RuntimeContext } from "../index-heuaRmXR.mjs";
1
+ import { c as RuntimeContextStorage, s as RuntimeContext } from "../index-AiKM71-u.mjs";
2
2
  import { n as RuntimeContextOverlapError, t as RuntimeContextNotConfiguredError } from "../errors-BKcsQ0ip.mjs";
3
3
  //#region src/runtime/explicit.d.ts
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { a as getRuntimeContextLineage, c as isRuntimeContextFrameCarrierInstalled, g as RuntimeContextOverlapError, h as RuntimeContextNotConfiguredError, m as withActiveRuntimeContextStorage, o as inheritRuntimeContextLineage, p as setRuntimeContextLineage, r as currentRuntimeContextFrame, s as isDerivedRuntimeContext } from "../context-BUEf1qjL.mjs";
1
+ import { a as getRuntimeContextLineage, c as isRuntimeContextFrameCarrierInstalled, g as RuntimeContextOverlapError, h as RuntimeContextNotConfiguredError, m as withActiveRuntimeContextStorage, o as inheritRuntimeContextLineage, p as setRuntimeContextLineage, r as currentRuntimeContextFrame, s as isDerivedRuntimeContext } from "../context-BphfFUMO.mjs";
2
2
  import { t as isPromiseLike } from "../runtime-CDcCF5cb.mjs";
3
3
  //#region src/runtime/explicit.ts
4
4
  let fallbackRootLease = false;
@@ -1,4 +1,4 @@
1
- import { c as RuntimeContextStorage, s as RuntimeContext } from "../index-heuaRmXR.mjs";
1
+ import { c as RuntimeContextStorage, s as RuntimeContext } from "../index-AiKM71-u.mjs";
2
2
  import { t as RuntimeContextNotConfiguredError } from "../errors-BKcsQ0ip.mjs";
3
- import { n as nodeRuntimeContextStorage, t as NodeRuntimeContextStorage } from "../node-context-DWsCUBRa.mjs";
3
+ import { n as nodeRuntimeContextStorage, t as NodeRuntimeContextStorage } from "../node-context-DczjAcrX.mjs";
4
4
  export { NodeRuntimeContextStorage, type RuntimeContext, RuntimeContextNotConfiguredError, type RuntimeContextStorage, nodeRuntimeContextStorage };
@@ -1,3 +1,3 @@
1
- import { h as RuntimeContextNotConfiguredError } from "../context-BUEf1qjL.mjs";
2
- import { n as nodeRuntimeContextStorage, t as NodeRuntimeContextStorage } from "../node-context-lggRF4bR.mjs";
1
+ import { h as RuntimeContextNotConfiguredError } from "../context-BphfFUMO.mjs";
2
+ import { n as nodeRuntimeContextStorage, t as NodeRuntimeContextStorage } from "../node-context-Ca18oNSg.mjs";
3
3
  export { NodeRuntimeContextStorage, RuntimeContextNotConfiguredError, nodeRuntimeContextStorage };
@@ -1,8 +1,9 @@
1
1
  import { c as CircularDependencyError, f as captureServiceTag, i as LayerDisposeError, l as ServiceAcquisitionError, n as normalizeLayerRegistration, o as LayerRegistrationError, r as DuplicateServiceError, s as ServiceTagCollisionError, t as captureLayerRegistrationTag, u as ServiceNotFoundError } from "./registration-drnZk0SY.mjs";
2
- import { i as getRuntimeContext, l as makeRuntimeContext, u as runRuntimeContext } from "./context-BUEf1qjL.mjs";
3
- import { l as defaultRuntimeContextStorage, n as linkAbortSignals } from "./signal-D2UTcaaG.mjs";
4
- import { a as runScoped, i as Scope, o as ScopeRuntime, t as getProgramName } from "./program-metadata-DhQCCirO.mjs";
2
+ import { i as getRuntimeContext, l as makeRuntimeContext, u as runRuntimeContext } from "./context-BphfFUMO.mjs";
3
+ import { s as defaultRuntimeContextStorage } from "./disposable-CP-Q2H3l.mjs";
4
+ import { a as runScoped, i as Scope, o as ScopeRuntime, t as getProgramName } from "./program-metadata-BxjGkT17.mjs";
5
5
  import { t as assertServiceCompatibility } from "./internal-identity-CbXoZIfw.mjs";
6
+ import { n as linkAbortSignals } from "./signal-nfgFyNCk.mjs";
6
7
  import { Err } from "better-result";
7
8
  //#region src/layer/map-layer-backend.ts
8
9
  /** Native map-backed Layer backend used by Runtime when no adapter is supplied. */
@@ -109,11 +110,13 @@ const createResolutionResolver = (resolver, storage = defaultRuntimeContextStora
109
110
  const cycleStart = findCycleStart(path, tag);
110
111
  const resolutionPath = [...path, token];
111
112
  const notifyResolve = (outcome) => {
112
- notifyRuntimeObservers(observers, (observer) => observer.onServiceResolve, {
113
+ const event = {
113
114
  service: token,
114
115
  resolutionPath,
115
116
  outcome
116
- });
117
+ };
118
+ if (context?.executionId !== void 0) Object.assign(event, { executionId: context.executionId });
119
+ notifyRuntimeObservers(observers, (observer) => observer.onServiceResolve, event);
117
120
  };
118
121
  if (cycleStart >= 0) {
119
122
  const error = new CircularDependencyError([...path.slice(cycleStart), token]);
@@ -228,47 +231,56 @@ const notifyShutdownFailure = async (observer, diagnostic) => {
228
231
  await observer(diagnostic);
229
232
  } catch {}
230
233
  };
231
- const releaseLayerResource = async (service, release, outcome, observers) => {
234
+ const releaseLayerResource = async (service, release, outcome, observers, executionId) => {
232
235
  try {
233
236
  await release(outcome);
234
- notifyRuntimeObservers(observers, (observer) => observer.onResourceRelease, {
237
+ const event = {
235
238
  service,
236
239
  outcome
237
- });
240
+ };
241
+ if (executionId !== void 0) Object.assign(event, { executionId });
242
+ notifyRuntimeObservers(observers, (observer) => observer.onResourceRelease, event);
238
243
  } catch (cause) {
239
- notifyRuntimeObservers(observers, (observer) => observer.onResourceRelease, {
244
+ const event = {
240
245
  service,
241
246
  outcome,
242
247
  error: cause
243
- });
248
+ };
249
+ if (executionId !== void 0) Object.assign(event, { executionId });
250
+ notifyRuntimeObservers(observers, (observer) => observer.onResourceRelease, event);
244
251
  throw cause;
245
252
  }
246
253
  };
247
- const bindProviderToScope = (provider, scope, contextStorage, resolver, observers) => ({
254
+ const bindProviderToScope = (provider, scope, contextStorage, resolver, observers, ownerExecutionId) => ({
248
255
  service: provider.service,
249
256
  serviceTag: provider.serviceTag,
250
257
  acquire: () => {
251
258
  const current = getRuntimeContext(contextStorage);
259
+ const executionId = current?.executionId ?? ownerExecutionId;
252
260
  const context = makeRuntimeContext(resolver, scope, current?.resolutionPath ?? [], current?.signal, current);
253
261
  return runRuntimeContext(contextStorage, context, () => ScopeRuntime.run(scope, async () => {
254
262
  const resolutionPath = current?.resolutionPath ?? [provider.service];
255
263
  try {
256
- const instance = provider.acquireWithRelease ? (await scope.acquire(provider.acquireWithRelease, (acquired, outcome) => releaseLayerResource(provider.service, acquired.release, outcome, observers))).instance : provider.release ? await scope.acquire(() => provider.acquire(), (resource, outcome) => releaseLayerResource(provider.service, (releaseOutcome) => provider.release(resource, releaseOutcome), outcome, observers)) : await provider.acquire();
257
- notifyRuntimeObservers(observers, (observer) => observer.onServiceAcquire, {
264
+ const instance = provider.acquireWithRelease ? (await scope.acquire(provider.acquireWithRelease, (acquired, outcome) => releaseLayerResource(provider.service, acquired.release, outcome, observers, ownerExecutionId))).instance : provider.release ? await scope.acquire(() => provider.acquire(), (resource, outcome) => releaseLayerResource(provider.service, (releaseOutcome) => provider.release(resource, releaseOutcome), outcome, observers, ownerExecutionId)) : await provider.acquire();
265
+ const event = {
258
266
  service: provider.service,
259
267
  resolutionPath,
260
268
  outcome: SCOPE_SUCCESS
261
- });
269
+ };
270
+ if (executionId !== void 0) Object.assign(event, { executionId });
271
+ notifyRuntimeObservers(observers, (observer) => observer.onServiceAcquire, event);
262
272
  return instance;
263
273
  } catch (cause) {
264
- notifyRuntimeObservers(observers, (observer) => observer.onServiceAcquire, {
274
+ const event = {
265
275
  service: provider.service,
266
276
  resolutionPath,
267
277
  outcome: {
268
278
  status: "failure",
269
279
  cause
270
280
  }
271
- });
281
+ };
282
+ if (executionId !== void 0) Object.assign(event, { executionId });
283
+ notifyRuntimeObservers(observers, (observer) => observer.onServiceAcquire, event);
272
284
  throw cause;
273
285
  }
274
286
  }, contextStorage));
@@ -394,7 +406,7 @@ var RuntimeHandleImpl = class {
394
406
  return this.startExecution(prepared.signalLink, prepared.metadata, async () => {
395
407
  try {
396
408
  return await this.runExecution(executionScope, async () => {
397
- for (const provider of layer.providers) backend.register(bindProviderToScope(provider, executionScope, this.contextStorage, resolver, this.observers));
409
+ for (const provider of layer.providers) backend.register(bindProviderToScope(provider, executionScope, this.contextStorage, resolver, this.observers, prepared.metadata.executionId));
398
410
  return await program();
399
411
  }, resolver, prepared.signalLink.signal, prepared.metadata);
400
412
  } finally {
@@ -461,16 +473,18 @@ var RuntimeHandleImpl = class {
461
473
  }
462
474
  runExecution(executionScope, program, resolver = this.resolver, signal = this.shutdownController.signal, metadata) {
463
475
  let outcome;
476
+ let cleanupFailure;
464
477
  const onOutcome = (determinedOutcome) => {
465
478
  outcome = determinedOutcome;
466
479
  };
467
- const runOptions = this.onCleanupFailure ? {
480
+ const onExecutionCleanupFailure = async (diagnostic) => {
481
+ cleanupFailure = diagnostic.error;
482
+ if (this.onCleanupFailure !== void 0) await this.onCleanupFailure(diagnostic);
483
+ };
484
+ const runOptions = {
468
485
  classify: classifyRuntimeOutcome,
469
486
  onOutcome,
470
- onCleanupFailure: this.onCleanupFailure
471
- } : {
472
- classify: classifyRuntimeOutcome,
473
- onOutcome
487
+ onCleanupFailure: onExecutionCleanupFailure
474
488
  };
475
489
  const startEvent = Object.freeze({
476
490
  ...metadata,
@@ -481,20 +495,21 @@ var RuntimeHandleImpl = class {
481
495
  const notifyEnd = (finalOutcome) => {
482
496
  if (ended) return;
483
497
  ended = true;
484
- const endEvent = Object.freeze({
498
+ const endEvent = {
485
499
  ...metadata,
486
500
  scope: executionScope,
487
501
  outcome: finalOutcome,
488
502
  durationMs: executionDuration(metadata, this.executionDependencies)
489
- });
490
- notifyRuntimeObservers(this.observers, (observer) => observer.onExecutionEnd, endEvent);
503
+ };
504
+ if (cleanupFailure !== void 0) Object.assign(endEvent, { cleanupFailure });
505
+ notifyRuntimeObservers(this.observers, (observer) => observer.onExecutionEnd, Object.freeze(endEvent));
491
506
  };
492
507
  let execution;
493
508
  try {
494
509
  execution = runScoped(executionScope, program, {
495
510
  ...runOptions,
496
511
  contextStorage: this.contextStorage,
497
- context: makeRuntimeContext(resolver, executionScope, [], signal)
512
+ context: makeRuntimeContext(resolver, executionScope, [], signal, void 0, metadata.executionId)
498
513
  });
499
514
  } catch (cause) {
500
515
  notifyEnd({
@@ -773,4 +788,4 @@ var Runtime = class Runtime {
773
788
  //#endregion
774
789
  export { MapLayerBackend as i, RuntimeObserver as n, classifyRuntimeOutcome as r, Runtime as t };
775
790
 
776
- //# sourceMappingURL=runtime-CBMrX8Wl.mjs.map
791
+ //# sourceMappingURL=runtime-C_55ofnL.mjs.map