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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iti.mjs","names":[],"sources":["../../src/adapters/iti.ts"],"sourcesContent":["import { createContainer } from 'iti'\n\nimport {\n DuplicateServiceError,\n ServiceTagCollisionError,\n type LayerBackend,\n type LayerBackendDisposeOptions,\n type LayerRegistration\n} from '../layer'\n\nimport { ServiceNotFoundError, type AnyServiceToken } from '../service'\n\nimport { assertServiceCompatibility } from '../layer/internal-identity'\nimport { isPromiseLike } from '../utils/runtime'\n\ntype LayerAcquiredValue = Awaited<ReturnType<LayerRegistration['acquire']>>\n\n/**\n * ITI-backed Layer backend.\n *\n * Install `iti` as the optional peer dependency and pass an instance to\n * `Runtime.make` when using ITI's container implementation.\n */\nexport class ItiLayerBackend implements LayerBackend {\n private container: any = createContainer()\n\n private readonly keys = new Map<string, string>()\n\n private readonly registered = new Map<string, AnyServiceToken>()\n\n /**\n * Track async gets so disposal cannot reset ITI while a provider is acquiring.\n * ITI caches rejected acquisitions; replacing the container is the explicit\n * retry boundary for that sticky failure behavior.\n */\n private readonly pending = new Map<Promise<unknown>, AnyServiceToken>()\n\n private keyFor(
|
|
1
|
+
{"version":3,"file":"iti.mjs","names":[],"sources":["../../src/adapters/iti.ts"],"sourcesContent":["import { createContainer } from 'iti'\n\nimport {\n DuplicateServiceError,\n ServiceTagCollisionError,\n type LayerBackend,\n type LayerBackendDisposeOptions,\n type LayerRegistration\n} from '../layer'\n\nimport { ServiceNotFoundError, type AnyServiceToken } from '../service'\nimport { captureServiceTag } from '../service/tag'\n\nimport { assertServiceCompatibility } from '../layer/internal-identity'\nimport { captureLayerRegistrationTag, normalizeLayerRegistration } from '../layer/registration'\nimport { isPromiseLike } from '../utils/runtime'\n\ntype LayerAcquiredValue = Awaited<ReturnType<LayerRegistration['acquire']>>\n\n/**\n * ITI-backed Layer backend.\n *\n * Install `iti` as the optional peer dependency and pass an instance to\n * `Runtime.make` when using ITI's container implementation.\n */\nexport class ItiLayerBackend implements LayerBackend {\n private container: any = createContainer()\n\n private readonly keys = new Map<string, string>()\n\n private readonly registered = new Map<string, AnyServiceToken>()\n\n /**\n * Track async gets so disposal cannot reset ITI while a provider is acquiring.\n * ITI caches rejected acquisitions; replacing the container is the explicit\n * retry boundary for that sticky failure behavior.\n */\n private readonly pending = new Map<Promise<unknown>, AnyServiceToken>()\n\n private keyFor(tag: string): string {\n const existing = this.keys.get(tag)\n\n if (existing) {\n return existing\n }\n\n const key = `better-effect:${tag}`\n\n this.keys.set(tag, key)\n\n return key\n }\n\n /** Register a Layer provider under its deterministic Service-tag key. */\n register(registration: LayerRegistration): void {\n const normalized = normalizeLayerRegistration(registration)\n const token = normalized.service\n const tag = captureLayerRegistrationTag(normalized)\n const existing = this.registered.get(tag)\n\n if (existing === token) {\n throw new DuplicateServiceError(token)\n }\n\n if (existing) {\n throw new ServiceTagCollisionError(existing, token)\n }\n\n const key = this.keyFor(tag)\n\n this.container = this.container.add({\n [key]: normalized.acquire\n })\n\n this.registered.set(tag, token)\n }\n\n /** Resolve a registered Service through the ITI container. */\n resolve<T extends AnyServiceToken>(token: T): InstanceType<T> | PromiseLike<InstanceType<T>> {\n const tag = captureServiceTag(token)\n const registered = this.registered.get(tag)\n\n if (registered === undefined) {\n throw new ServiceNotFoundError(token)\n }\n\n const key = this.keyFor(tag)\n const resolved = this.container.get(key)\n\n const validate = (instance: LayerAcquiredValue): InstanceType<T> => {\n assertServiceCompatibility(token, registered, instance)\n\n // SAFETY: The registered tag and compatibility check establish the constructor-to-instance relationship after ITI erases it.\n return instance as InstanceType<T>\n }\n\n if (isPromiseLike(resolved)) {\n const pending = Promise.resolve(resolved).then(validate)\n\n this.pending.set(pending, registered)\n void pending.then(\n () => this.pending.delete(pending),\n () => this.pending.delete(pending)\n )\n\n return pending\n }\n\n return validate(resolved)\n }\n\n /** Reset container-owned ITI state; Scope owns Layer provider releases. */\n async disposeAll(options?: LayerBackendDisposeOptions): Promise<void> {\n const container = this.container\n const acquisitions = [...this.pending.keys()]\n\n try {\n if (acquisitions.length > 0) {\n const observePending = options?.onPendingAcquisitions\n\n if (observePending) {\n await observePending(acquisitions)\n }\n\n await Promise.allSettled(acquisitions)\n }\n await container.disposeAll()\n } finally {\n this.container = createContainer()\n this.registered.clear()\n this.keys.clear()\n this.pending.clear()\n }\n }\n}\n"],"mappings":";;;;;;;;;;;AAyBA,IAAa,kBAAb,MAAqD;CACnD,YAAyB,gBAAgB;CAEzC,uBAAwB,IAAI,IAAoB;CAEhD,6BAA8B,IAAI,IAA6B;;;;;;CAO/D,0BAA2B,IAAI,IAAuC;CAEtE,OAAe,KAAqB;EAClC,MAAM,WAAW,KAAK,KAAK,IAAI,GAAG;EAElC,IAAI,UACF,OAAO;EAGT,MAAM,MAAM,iBAAiB;EAE7B,KAAK,KAAK,IAAI,KAAK,GAAG;EAEtB,OAAO;CACT;;CAGA,SAAS,cAAuC;EAC9C,MAAM,aAAa,2BAA2B,YAAY;EAC1D,MAAM,QAAQ,WAAW;EACzB,MAAM,MAAM,4BAA4B,UAAU;EAClD,MAAM,WAAW,KAAK,WAAW,IAAI,GAAG;EAExC,IAAI,aAAa,OACf,MAAM,IAAI,sBAAsB,KAAK;EAGvC,IAAI,UACF,MAAM,IAAI,yBAAyB,UAAU,KAAK;EAGpD,MAAM,MAAM,KAAK,OAAO,GAAG;EAE3B,KAAK,YAAY,KAAK,UAAU,IAAI,GACjC,MAAM,WAAW,QACpB,CAAC;EAED,KAAK,WAAW,IAAI,KAAK,KAAK;CAChC;;CAGA,QAAmC,OAA0D;EAC3F,MAAM,MAAM,kBAAkB,KAAK;EACnC,MAAM,aAAa,KAAK,WAAW,IAAI,GAAG;EAE1C,IAAI,eAAe,KAAA,GACjB,MAAM,IAAI,qBAAqB,KAAK;EAGtC,MAAM,MAAM,KAAK,OAAO,GAAG;EAC3B,MAAM,WAAW,KAAK,UAAU,IAAI,GAAG;EAEvC,MAAM,YAAY,aAAkD;GAClE,2BAA2B,OAAO,YAAY,QAAQ;GAGtD,OAAO;EACT;EAEA,IAAI,cAAc,QAAQ,GAAG;GAC3B,MAAM,UAAU,QAAQ,QAAQ,QAAQ,CAAC,CAAC,KAAK,QAAQ;GAEvD,KAAK,QAAQ,IAAI,SAAS,UAAU;GACpC,QAAa,WACL,KAAK,QAAQ,OAAO,OAAO,SAC3B,KAAK,QAAQ,OAAO,OAAO,CACnC;GAEA,OAAO;EACT;EAEA,OAAO,SAAS,QAAQ;CAC1B;;CAGA,MAAM,WAAW,SAAqD;EACpE,MAAM,YAAY,KAAK;EACvB,MAAM,eAAe,CAAC,GAAG,KAAK,QAAQ,KAAK,CAAC;EAE5C,IAAI;GACF,IAAI,aAAa,SAAS,GAAG;IAC3B,MAAM,iBAAiB,SAAS;IAEhC,IAAI,gBACF,MAAM,eAAe,YAAY;IAGnC,MAAM,QAAQ,WAAW,YAAY;GACvC;GACA,MAAM,UAAU,WAAW;EAC7B,UAAU;GACR,KAAK,YAAY,gBAAgB;GACjC,KAAK,WAAW,MAAM;GACtB,KAAK,KAAK,MAAM;GAChB,KAAK,QAAQ,MAAM;EACrB;CACF;AACF"}
|
package/dist/bun.d.mts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { M as AnyService } from "./index-AiKM71-u.mjs";
|
|
2
|
+
import { y as LayerInput } from "./outcome-DI8LPIQ4.mjs";
|
|
3
|
+
import { l as Runtime } from "./index-BodMy6rO.mjs";
|
|
4
|
+
import { a as WebEffectOptions, n as CompleteWebProgram, o as WebEffectProgram, r as DefaultRequestLayer, s as WebEffectSuccess, t as AnyProgram, u as WebRequestLayerChecks } from "./types-oihI-ESv.mjs";
|
|
5
|
+
//#region src/bun/types.d.ts
|
|
6
|
+
/** A Bun server passed to a Bun.serve fetch handler. */
|
|
7
|
+
type BunServer<WebSocketData = undefined> = Bun.Server<WebSocketData>;
|
|
8
|
+
/** The Promise<Response> handler shape accepted by Bun.serve. */
|
|
9
|
+
type BunFetchHandler<WebSocketData = undefined> = (request: Request, server: BunServer<WebSocketData>) => Promise<Response>;
|
|
10
|
+
/** A lazy Result-valued Program accepted by the Bun adapter. */
|
|
11
|
+
type BunEffectProgram<A = unknown, E = unknown, R extends AnyService = never> = WebEffectProgram<A, E, R>;
|
|
12
|
+
/** Options for adapting a WebEffect boundary to Bun's fetch callback. */
|
|
13
|
+
type BunEffectOptions<Failure = unknown, RequestLayer extends LayerInput = DefaultRequestLayer> = Omit<WebEffectOptions<Failure, RequestLayer>, 'onFailure' | 'onSuccess'> & {
|
|
14
|
+
/** Convert a successful Program value into a Response. */
|
|
15
|
+
readonly onSuccess?: (result: WebEffectSuccess, request: Request) => ResponseLike;
|
|
16
|
+
/** Convert a typed Program failure into a Response. */
|
|
17
|
+
readonly onFailure?: (error: Failure, request: Request) => ResponseLike;
|
|
18
|
+
};
|
|
19
|
+
/** A standard Web response or an asynchronous response. */
|
|
20
|
+
type ResponseLike = Response | PromiseLike<Response>;
|
|
21
|
+
/** @internal */
|
|
22
|
+
type BunAnyProgram = AnyProgram;
|
|
23
|
+
/** @internal */
|
|
24
|
+
type BunHandlerProgram<Provided extends AnyService, RequestLayer extends LayerInput, Program extends AnyProgram, Failure> = CompleteWebProgram<Provided, RequestLayer, Program, Failure>;
|
|
25
|
+
/** @internal */
|
|
26
|
+
type BunRequestLayerChecks<Provided extends AnyService, RequestLayer extends LayerInput> = WebRequestLayerChecks<Provided, RequestLayer>;
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region src/bun/index.d.ts
|
|
29
|
+
type BunHandlerFactory<Provided extends AnyService, RequestLayer extends LayerInput, Failure, WebSocketData, ProgramFactory extends (request: Request, server: Bun.Server<WebSocketData>) => BunAnyProgram> = ProgramFactory & ([ReturnType<ProgramFactory>] extends [BunHandlerProgram<Provided, RequestLayer, ReturnType<ProgramFactory>, Failure>] ? unknown : (request: Request, server: Bun.Server<WebSocketData>) => BunHandlerProgram<Provided, RequestLayer, ReturnType<ProgramFactory>, Failure>);
|
|
30
|
+
/** Bind a Runtime and WebEffect policy to a Bun.serve fetch handler. */
|
|
31
|
+
declare class BunEffect<Provided extends AnyService = never, Failure = unknown, RequestLayer extends LayerInput = DefaultRequestLayer> {
|
|
32
|
+
readonly runtime: Runtime<Provided>;
|
|
33
|
+
private readonly onSuccess;
|
|
34
|
+
private readonly onFailure;
|
|
35
|
+
private readonly requestLayer;
|
|
36
|
+
private constructor();
|
|
37
|
+
static make<Provided extends AnyService, Failure = unknown, RequestLayer extends LayerInput = DefaultRequestLayer>(runtime: Runtime<Provided>, options?: BunEffectOptions<Failure, RequestLayer> & BunRequestLayerChecks<Provided, RequestLayer>): BunEffect<Provided, Failure, RequestLayer>;
|
|
38
|
+
handler<WebSocketData = undefined, const ProgramFactory extends (request: Request, server: Bun.Server<WebSocketData>) => BunAnyProgram = (request: Request, server: Bun.Server<WebSocketData>) => BunAnyProgram>(makeProgram: BunHandlerFactory<Provided, RequestLayer, Failure, WebSocketData, ProgramFactory>): BunFetchHandler<WebSocketData>;
|
|
39
|
+
private makeWebOptions;
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
export { BunEffect, type BunEffectOptions, type BunEffectProgram, type BunFetchHandler, type BunServer, type ResponseLike };
|
|
43
|
+
//# sourceMappingURL=bun.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bun.d.mts","names":[],"sources":["../src/bun/types.ts","../src/bun/index.ts"],"mappings":";;;;;;KAaY,UAAU,6BAA6B,IAAI,OAAO;;KAGlD,gBAAgB,8BAC1B,SAAS,SACT,QAAQ,UAAU,mBACf,QAAQ;;KAGD,iBACV,aACA,aACA,UAAU,sBACR,iBAAiB,GAAG,GAAG;;KAGf,iBACV,mBACA,qBAAqB,aAAa,uBAChC,KAAK,iBAAiB,SAAS;;WAExB,aAAa,QAAQ,kBAAkB,SAAS,YAAY;;WAE5D,aAAa,OAAO,SAAS,SAAS,YAAY;;;KAIjD,eAAe,WAAW,YAAY;;KAGtC,gBAAgB;;KAGhB,kBACV,iBAAiB,YACjB,qBAAqB,YACrB,gBAAgB,YAChB,WACE,mBAAmB,UAAU,cAAc,SAAS;;KAG5C,sBACV,iBAAiB,YACjB,qBAAqB,cACnB,sBAAsB,UAAU;;;KCjC/B,kBACH,iBAAiB,YACjB,qBAAqB,YACrB,SACA,eACA,wBAAwB,SAAS,SAAS,QAAQ,IAAI,OAAO,mBAAmB,iBAC9E,mBACA,WAAW,0BACX,kBAAkB,UAAU,cAAc,WAAW,iBAAiB,uBAIlE,SAAS,SACT,QAAQ,IAAI,OAAO,mBAChB,kBAAkB,UAAU,cAAc,WAAW,iBAAiB;;cAGpE,UACX,iBAAiB,oBACjB,mBACA,qBAAqB,aAAa;WAEzB,SAAS,QAAQ;mBAET;mBAEA;mBAEA;UAEV;SAUA,KACL,iBAAiB,YACjB,mBACA,qBAAqB,aAAa,qBAElC,SAAS,QAAQ,WACjB,UAAU,iBAAiB,SAAS,gBAClC,sBAAsB,UAAU,gBACjC,UAAU,UAAU,SAAS;EAIhC,QACE,iCACM,wBACJ,SAAS,SACT,QAAQ,IAAI,OAAO,mBAChB,iBAAiB,SAAS,SAAS,QAAQ,IAAI,OAAO,mBAAmB,eAE9E,aAAa,kBAAkB,UAAU,cAAc,SAAS,eAAe,kBAC9E,gBAAgB;UASX"}
|
package/dist/bun.mjs
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { t as Layer } from "./layer-D16GKxuX.mjs";
|
|
2
|
+
import { t as WebEffect } from "./web-Bq3MfMrj.mjs";
|
|
3
|
+
//#region src/bun/index.ts
|
|
4
|
+
const runWebEffect = (runtime, request, program, options) => {
|
|
5
|
+
return WebEffect.handle(runtime, request, program, options);
|
|
6
|
+
};
|
|
7
|
+
/** Bind a Runtime and WebEffect policy to a Bun.serve fetch handler. */
|
|
8
|
+
var BunEffect = class BunEffect {
|
|
9
|
+
runtime;
|
|
10
|
+
onSuccess;
|
|
11
|
+
onFailure;
|
|
12
|
+
requestLayer;
|
|
13
|
+
constructor(runtime, options) {
|
|
14
|
+
this.runtime = runtime;
|
|
15
|
+
this.onSuccess = options.onSuccess;
|
|
16
|
+
this.onFailure = options.onFailure;
|
|
17
|
+
this.requestLayer = options.requestLayer;
|
|
18
|
+
}
|
|
19
|
+
static make(runtime, options) {
|
|
20
|
+
return new BunEffect(runtime, options ?? {});
|
|
21
|
+
}
|
|
22
|
+
handler(makeProgram) {
|
|
23
|
+
return async (request, server) => {
|
|
24
|
+
const program = (() => makeProgram(request, server)());
|
|
25
|
+
return runWebEffect(this.runtime, request, program, this.makeWebOptions(request));
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
makeWebOptions(request) {
|
|
29
|
+
const options = { requestLayer: this.requestLayer ?? (() => Layer.empty) };
|
|
30
|
+
const onSuccess = this.onSuccess;
|
|
31
|
+
if (onSuccess !== void 0) options.onSuccess = (result) => onSuccess(result, request);
|
|
32
|
+
const onFailure = this.onFailure;
|
|
33
|
+
if (onFailure !== void 0) options.onFailure = (error) => onFailure(error, request);
|
|
34
|
+
return options;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
//#endregion
|
|
38
|
+
export { BunEffect };
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=bun.mjs.map
|
package/dist/bun.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bun.mjs","names":[],"sources":["../src/bun/index.ts"],"sourcesContent":["import { Layer } from '../layer'\nimport { WebEffect } from '../web'\nimport type { AnyService } from '../service'\nimport type { LayerInput } from '../layer/inference'\nimport type { Runtime } from '../runtime'\nimport type {\n BunAnyProgram,\n BunEffectOptions,\n BunFetchHandler,\n BunHandlerProgram,\n BunRequestLayerChecks\n} from './types'\nimport type { DefaultRequestLayer, WebEffectOptions } from '../web/types'\n\nconst runWebEffect = <Provided extends AnyService>(\n runtime: Runtime<Provided>,\n request: Request,\n program: BunAnyProgram,\n options: WebEffectOptions<unknown, LayerInput, unknown>\n): Promise<Response> => {\n // SAFETY: BunHandlerFactory validates the Program; WebEffect owns this erased request boundary.\n return WebEffect.handle(runtime, request, program, options as never)\n}\n\ntype BunHandlerFactory<\n Provided extends AnyService,\n RequestLayer extends LayerInput,\n Failure,\n WebSocketData,\n ProgramFactory extends (request: Request, server: Bun.Server<WebSocketData>) => BunAnyProgram\n> = ProgramFactory &\n ([ReturnType<ProgramFactory>] extends [\n BunHandlerProgram<Provided, RequestLayer, ReturnType<ProgramFactory>, Failure>\n ]\n ? unknown\n : (\n request: Request,\n server: Bun.Server<WebSocketData>\n ) => BunHandlerProgram<Provided, RequestLayer, ReturnType<ProgramFactory>, Failure>)\n\n/** Bind a Runtime and WebEffect policy to a Bun.serve fetch handler. */\nexport class BunEffect<\n Provided extends AnyService = never,\n Failure = unknown,\n RequestLayer extends LayerInput = DefaultRequestLayer\n> {\n readonly runtime: Runtime<Provided>\n\n private readonly onSuccess: BunEffectOptions<Failure, RequestLayer>['onSuccess']\n\n private readonly onFailure: BunEffectOptions<Failure, RequestLayer>['onFailure']\n\n private readonly requestLayer: BunEffectOptions<Failure, RequestLayer>['requestLayer']\n\n private constructor(\n runtime: Runtime<Provided>,\n options: BunEffectOptions<Failure, RequestLayer>\n ) {\n this.runtime = runtime\n this.onSuccess = options.onSuccess\n this.onFailure = options.onFailure\n this.requestLayer = options.requestLayer\n }\n\n static make<\n Provided extends AnyService,\n Failure = unknown,\n RequestLayer extends LayerInput = DefaultRequestLayer\n >(\n runtime: Runtime<Provided>,\n options?: BunEffectOptions<Failure, RequestLayer> &\n BunRequestLayerChecks<Provided, RequestLayer>\n ): BunEffect<Provided, Failure, RequestLayer> {\n return new BunEffect(runtime, options ?? {})\n }\n\n handler<\n WebSocketData = undefined,\n const ProgramFactory extends (\n request: Request,\n server: Bun.Server<WebSocketData>\n ) => BunAnyProgram = (request: Request, server: Bun.Server<WebSocketData>) => BunAnyProgram\n >(\n makeProgram: BunHandlerFactory<Provided, RequestLayer, Failure, WebSocketData, ProgramFactory>\n ): BunFetchHandler<WebSocketData> {\n return async (request, server) => {\n // SAFETY: the public factory check validates the returned Program before this erased wrapper.\n const program = (() => makeProgram(request, server)()) as BunAnyProgram\n\n return runWebEffect(this.runtime, request, program, this.makeWebOptions(request))\n }\n }\n\n private makeWebOptions(request: Request): WebEffectOptions<unknown, LayerInput, unknown> & {\n readonly requestLayer: (request: Request) => LayerInput\n } {\n type MutableWebOptions = {\n -readonly [Key in keyof WebEffectOptions<unknown, LayerInput, unknown>]?: WebEffectOptions<\n unknown,\n LayerInput,\n unknown\n >[Key]\n }\n const options: MutableWebOptions & {\n requestLayer: (request: Request) => LayerInput\n } = {\n requestLayer: this.requestLayer ?? (() => Layer.empty)\n }\n\n const onSuccess = this.onSuccess\n\n if (onSuccess !== undefined) {\n options.onSuccess = (result) => onSuccess(result, request)\n }\n\n const onFailure = this.onFailure\n\n if (onFailure !== undefined) {\n // SAFETY: the public handler check ties this wrapper to the configured Failure channel.\n options.onFailure = (error) => onFailure(error as Failure, request)\n }\n\n return options\n }\n}\n\nexport type {\n BunEffectOptions,\n BunEffectProgram,\n BunFetchHandler,\n BunServer,\n ResponseLike\n} from './types'\n"],"mappings":";;;AAcA,MAAM,gBACJ,SACA,SACA,SACA,YACsB;CAEtB,OAAO,UAAU,OAAO,SAAS,SAAS,SAAS,OAAgB;AACrE;;AAmBA,IAAa,YAAb,MAAa,UAIX;CACA;CAEA;CAEA;CAEA;CAEA,YACE,SACA,SACA;EACA,KAAK,UAAU;EACf,KAAK,YAAY,QAAQ;EACzB,KAAK,YAAY,QAAQ;EACzB,KAAK,eAAe,QAAQ;CAC9B;CAEA,OAAO,KAKL,SACA,SAE4C;EAC5C,OAAO,IAAI,UAAU,SAAS,WAAW,CAAC,CAAC;CAC7C;CAEA,QAOE,aACgC;EAChC,OAAO,OAAO,SAAS,WAAW;GAEhC,MAAM,iBAAiB,YAAY,SAAS,MAAM,CAAC,CAAC;GAEpD,OAAO,aAAa,KAAK,SAAS,SAAS,SAAS,KAAK,eAAe,OAAO,CAAC;EAClF;CACF;CAEA,eAAuB,SAErB;EAQA,MAAM,UAEF,EACF,cAAc,KAAK,uBAAuB,MAAM,OAClD;EAEA,MAAM,YAAY,KAAK;EAEvB,IAAI,cAAc,KAAA,GAChB,QAAQ,aAAa,WAAW,UAAU,QAAQ,OAAO;EAG3D,MAAM,YAAY,KAAK;EAEvB,IAAI,cAAc,KAAA,GAEhB,QAAQ,aAAa,UAAU,UAAU,OAAkB,OAAO;EAGpE,OAAO;CACT;AACF"}
|
|
@@ -39,11 +39,13 @@ const setRuntimeContextLineage = (context) => {
|
|
|
39
39
|
const hasPathPrefix = (parent, child) => child.length >= parent.length && parent.every((token, index) => child[index] === token);
|
|
40
40
|
/** Recognize contexts created by a nested Service, Scope, or Layer operation. */
|
|
41
41
|
const isDerivedRuntimeContext = (parent, child) => parent.resolver !== void 0 && child.resolver === parent.resolver && parent.resolutionPath.length > 0 && hasPathPrefix(parent.resolutionPath, child.resolutionPath) && (child.resolutionPath.length > parent.resolutionPath.length || child.scope !== parent.scope);
|
|
42
|
-
function makeRuntimeContext(resolver, scope, resolutionPath, signal, parent) {
|
|
42
|
+
function makeRuntimeContext(resolver, scope, resolutionPath, signal, parent, executionId) {
|
|
43
43
|
const context = { resolutionPath };
|
|
44
|
+
const ownerExecutionId = executionId ?? parent?.executionId;
|
|
44
45
|
if (resolver !== void 0) Object.assign(context, { resolver });
|
|
45
46
|
if (scope !== void 0) Object.assign(context, { scope });
|
|
46
47
|
if (signal !== void 0) Object.assign(context, { signal });
|
|
48
|
+
if (ownerExecutionId !== void 0) Object.assign(context, { executionId: ownerExecutionId });
|
|
47
49
|
if (parent !== void 0) inheritRuntimeContextLineage(context, parent);
|
|
48
50
|
return context;
|
|
49
51
|
}
|
|
@@ -149,4 +151,4 @@ const runRuntimeContext = (storage, context, program) => {
|
|
|
149
151
|
//#endregion
|
|
150
152
|
export { getRuntimeContextLineage as a, isRuntimeContextFrameCarrierInstalled as c, setDefaultRuntimeContextStorage as d, setRuntimeContextFrameCarrier as f, RuntimeContextOverlapError as g, RuntimeContextNotConfiguredError as h, getRuntimeContext as i, makeRuntimeContext as l, withActiveRuntimeContextStorage as m, currentRuntimeContext as n, inheritRuntimeContextLineage as o, setRuntimeContextLineage as p, currentRuntimeContextFrame as r, isDerivedRuntimeContext as s, activeRuntimeContextStorage as t, runRuntimeContext as u };
|
|
151
153
|
|
|
152
|
-
//# sourceMappingURL=context-
|
|
154
|
+
//# sourceMappingURL=context-BphfFUMO.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-BphfFUMO.mjs","names":[],"sources":["../src/runtime/errors.ts","../src/runtime/context.ts"],"sourcesContent":["/** Thrown when no RuntimeContext is active in the selected storage. */\nexport class RuntimeContextNotConfiguredError extends Error {\n constructor() {\n super('No RuntimeContext is available in the current execution context')\n\n this.name = 'RuntimeContextNotConfiguredError'\n }\n}\n\n/** Thrown when ExplicitRuntimeContextStorage cannot safely overlap lineages. */\nexport class RuntimeContextOverlapError extends Error {\n constructor() {\n super(\n 'ExplicitRuntimeContextStorage does not support overlapping root or derived context runs; use NodeRuntimeContextStorage for concurrent async branches'\n )\n\n this.name = 'RuntimeContextOverlapError'\n }\n}\n","import { RuntimeContextNotConfiguredError } from './errors'\n\nimport type { Scope } from '../scope/scope'\nimport type { AnyServiceToken, ServiceResolver } from '../service'\nimport { isPromiseLike } from '../utils/runtime'\n\n/** Contextual state shared by Service, Scope and Layer resolution. */\nexport interface RuntimeContext {\n readonly resolver?: ServiceResolver\n readonly scope?: Scope\n readonly signal?: AbortSignal\n readonly resolutionPath: readonly AnyServiceToken[]\n /** Runtime execution owner, omitted for warmup and Runtime-root activity. */\n readonly executionId?: string\n}\n\n/** A context with both channels required by a Runtime execution. */\nexport type CompleteRuntimeContext = RuntimeContext & {\n readonly resolver: ServiceResolver\n readonly scope: Scope\n}\n\n/** Host-specific storage for the current RuntimeContext. */\nexport interface RuntimeContextStorage {\n run<A>(context: RuntimeContext, program: () => A): A\n current(): RuntimeContext\n}\n\nconst unconfiguredRuntimeContextStorage: RuntimeContextStorage = {\n run: (_context, program) => program(),\n current: () => {\n throw new RuntimeContextNotConfiguredError()\n }\n}\n\nconst contextLineages = new WeakMap<object, RuntimeContext>()\n\n/** Associate a derived context with the root context of its execution lineage. */\nexport const inheritRuntimeContextLineage = (\n context: RuntimeContext,\n parent: RuntimeContext\n): RuntimeContext => {\n const lineage = contextLineages.get(parent) ?? parent\n contextLineages.set(context, lineage)\n return context\n}\n\n/** Return the root context associated with a contextual value, when known. */\nexport const getRuntimeContextLineage = (context: RuntimeContext): RuntimeContext | undefined =>\n contextLineages.get(context)\n\n/** Associate a newly-entered root context with itself. */\nexport const setRuntimeContextLineage = (context: RuntimeContext): RuntimeContext => {\n contextLineages.set(context, context)\n return context\n}\n\nconst hasPathPrefix = (\n parent: readonly AnyServiceToken[],\n child: readonly AnyServiceToken[]\n): boolean =>\n child.length >= parent.length && parent.every((token, index) => child[index] === token)\n\n/** Recognize contexts created by a nested Service, Scope, or Layer operation. */\nexport const isDerivedRuntimeContext = (parent: RuntimeContext, child: RuntimeContext): boolean =>\n parent.resolver !== undefined &&\n child.resolver === parent.resolver &&\n parent.resolutionPath.length > 0 &&\n hasPathPrefix(parent.resolutionPath, child.resolutionPath) &&\n (child.resolutionPath.length > parent.resolutionPath.length || child.scope !== parent.scope)\n\n/** Build a context while retaining only channels that are actually available. */\nexport function makeRuntimeContext(\n resolver: ServiceResolver,\n scope: Scope,\n resolutionPath: readonly AnyServiceToken[],\n signal: AbortSignal | undefined,\n parent?: RuntimeContext,\n executionId?: string\n): CompleteRuntimeContext\nexport function makeRuntimeContext(\n resolver: ServiceResolver | undefined,\n scope: Scope | undefined,\n resolutionPath: readonly AnyServiceToken[],\n signal: AbortSignal | undefined,\n parent?: RuntimeContext,\n executionId?: string\n): RuntimeContext\nexport function makeRuntimeContext(\n resolver: ServiceResolver | undefined,\n scope: Scope | undefined,\n resolutionPath: readonly AnyServiceToken[],\n signal: AbortSignal | undefined,\n parent?: RuntimeContext,\n executionId?: string\n): RuntimeContext {\n const context: RuntimeContext = { resolutionPath }\n const ownerExecutionId = executionId ?? parent?.executionId\n\n if (resolver !== undefined) {\n Object.assign(context, { resolver })\n }\n\n if (scope !== undefined) {\n Object.assign(context, { scope })\n }\n\n if (signal !== undefined) {\n Object.assign(context, { signal })\n }\n\n if (ownerExecutionId !== undefined) {\n Object.assign(context, { executionId: ownerExecutionId })\n }\n\n if (parent !== undefined) {\n inheritRuntimeContextLineage(context, parent)\n }\n\n return context\n}\n\n/** A context frame selected for one logical Runtime execution branch. */\nexport type ActiveRuntimeContextFrame = {\n readonly storage: RuntimeContextStorage\n readonly context: RuntimeContext\n readonly parent?: ActiveRuntimeContextFrame\n}\n\n/** Host-provided propagation for Runtime context frames. */\nexport interface RuntimeContextFrameCarrier {\n run<A>(frame: ActiveRuntimeContextFrame, program: () => A): A\n current(): ActiveRuntimeContextFrame | undefined\n}\n\nlet defaultStorage = unconfiguredRuntimeContextStorage\nlet fallbackFrame: ActiveRuntimeContextFrame | undefined\nconst fallbackFrames = new Set<ActiveRuntimeContextFrame>()\n\nconst settleWithRuntimeStorage = <A>(value: A, restore: () => void): A => {\n let promiseLike: boolean\n\n try {\n promiseLike = isPromiseLike(value)\n } catch (cause) {\n restore()\n throw cause\n }\n\n if (!promiseLike) {\n restore()\n return value\n }\n\n try {\n // SAFETY: PromiseLike values are normalized only to restore the storage after settlement; the public generic retains the callback's awaited shape.\n return Promise.resolve(value).then(\n (resolved) => {\n restore()\n return resolved\n },\n (cause) => {\n restore()\n throw cause\n }\n ) as A\n } catch (cause) {\n restore()\n throw cause\n }\n}\n\nconst restoreFallbackFrame = (frame: ActiveRuntimeContextFrame): void => {\n fallbackFrames.delete(frame)\n\n if (fallbackFrame !== frame) {\n return\n }\n\n let parent = frame.parent\n\n while (parent !== undefined && !fallbackFrames.has(parent)) {\n parent = parent.parent\n }\n\n fallbackFrame = parent\n}\n\nconst fallbackRuntimeContextFrameCarrier: RuntimeContextFrameCarrier = {\n run<A>(frame: ActiveRuntimeContextFrame, program: () => A): A {\n fallbackFrames.add(frame)\n fallbackFrame = frame\n const restore = (): void => restoreFallbackFrame(frame)\n\n try {\n return settleWithRuntimeStorage(program(), restore)\n } catch (cause) {\n restore()\n throw cause\n }\n },\n\n current: () => fallbackFrame\n}\n\nlet runtimeContextFrameCarrier: RuntimeContextFrameCarrier = fallbackRuntimeContextFrameCarrier\n\n/** Install host async-context propagation for Runtime context frames. */\nexport const setRuntimeContextFrameCarrier = (carrier: RuntimeContextFrameCarrier): void => {\n runtimeContextFrameCarrier = carrier\n}\n\n/** Return whether a host async-context carrier has been installed. */\nexport const isRuntimeContextFrameCarrierInstalled = (): boolean =>\n runtimeContextFrameCarrier !== fallbackRuntimeContextFrameCarrier\n\n/** Return the frame associated with the executing callback. */\nexport const currentRuntimeContextFrame = (): ActiveRuntimeContextFrame | undefined =>\n runtimeContextFrameCarrier.current()\n\n/** Install the host default used by the main Runtime entrypoint. */\nexport const setDefaultRuntimeContextStorage = (storage: RuntimeContextStorage): void => {\n defaultStorage = storage\n}\n\n/** Return the storage currently associated with the executing callback. */\nexport const activeRuntimeContextStorage = (): RuntimeContextStorage =>\n currentRuntimeContextFrame()?.storage ?? defaultStorage\n\n/** Return the active context, or undefined when the storage has not been entered. */\nexport const getRuntimeContext = (\n storage: RuntimeContextStorage = activeRuntimeContextStorage()\n): RuntimeContext | undefined => {\n const frame = currentRuntimeContextFrame()\n\n if (frame?.storage === storage) {\n return frame.context\n }\n\n try {\n return storage.current()\n } catch (cause) {\n if (cause instanceof RuntimeContextNotConfiguredError) {\n return undefined\n }\n\n throw cause\n }\n}\n\n/** Return the active context or throw the storage's standard missing-context error. */\nexport const currentRuntimeContext = (): RuntimeContext => {\n const frame = currentRuntimeContextFrame()\n\n return frame?.context ?? defaultStorage.current()\n}\n\n/** Keep a storage discoverable to Service and Scope compatibility bridges. */\nexport const withActiveRuntimeContextStorage = <A>(\n storage: RuntimeContextStorage,\n context: RuntimeContext,\n program: () => A\n): A => {\n const current = currentRuntimeContextFrame()\n\n if (current?.storage === storage && current.context === context) {\n return program()\n }\n\n const frame: ActiveRuntimeContextFrame =\n current === undefined ? { storage, context } : { storage, context, parent: current }\n\n return runtimeContextFrameCarrier.run(frame, program)\n}\n\n/** Run a callback in a context while keeping the selected storage discoverable to bridges. */\nexport const runRuntimeContext = <A>(\n storage: RuntimeContextStorage,\n context: RuntimeContext,\n program: () => A\n): A => {\n const current = getRuntimeContext(storage)\n const contextual =\n current !== undefined && isDerivedRuntimeContext(current, context)\n ? inheritRuntimeContextLineage(context, current)\n : context\n\n return storage.run(contextual, () =>\n withActiveRuntimeContextStorage(storage, contextual, program)\n )\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { H as ServiceToken, I as ServiceIdentity, b as Service, j as ServiceRequirement } from "./index-AiKM71-u.mjs";
|
|
2
|
+
import { A as ProviderEntry, x as LayerResult } from "./outcome-DI8LPIQ4.mjs";
|
|
3
|
+
import "./index-BodMy6rO.mjs";
|
|
4
|
+
//#region src/standard-services/current-request.d.ts
|
|
5
|
+
declare const CurrentRequest_base: (abstract new () => ServiceIdentity<"CurrentRequest">) & {
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly serviceTag: "CurrentRequest";
|
|
8
|
+
} & {
|
|
9
|
+
readonly of: Service.FactoryOf<CurrentRequest, "CurrentRequest">;
|
|
10
|
+
readonly [Symbol.asyncIterator]: (this: ServiceToken<"CurrentRequest", CurrentRequest & ServiceIdentity<"CurrentRequest">>) => AsyncGenerator<ServiceRequirement<CurrentRequest>, CurrentRequest, unknown>;
|
|
11
|
+
};
|
|
12
|
+
/** Execution-local request value carried by a normal Service provider. */
|
|
13
|
+
declare class CurrentRequest extends CurrentRequest_base {
|
|
14
|
+
readonly value: unknown;
|
|
15
|
+
readonly request: unknown;
|
|
16
|
+
constructor(value: unknown);
|
|
17
|
+
static layer(value: unknown): LayerResult<ProviderEntry<CurrentRequest, never>>;
|
|
18
|
+
}
|
|
19
|
+
declare const CurrentRequestLayer: (value: unknown) => LayerResult<ProviderEntry<CurrentRequest, never>>;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { CurrentRequestLayer as n, CurrentRequest as t };
|
|
22
|
+
//# sourceMappingURL=current-request-CIU7AHhF.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"current-request-CIU7AHhF.d.mts","names":[],"sources":["../src/standard-services/current-request.ts"],"mappings":";;;;;;;;;;;;cAIa,uBAAuB;WAIb;WAHZ;EAGY,YAAA;SAMd,MAAM,iBAAc,YAAA,cAAA;;cAMhB,sBAAuB,mBAAc,YAAA,cAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { n as Service, t as Layer } from "./layer-D16GKxuX.mjs";
|
|
2
|
+
//#region src/standard-services/current-request.ts
|
|
3
|
+
/** Execution-local request value carried by a normal Service provider. */
|
|
4
|
+
var CurrentRequest = class CurrentRequest extends Service()("CurrentRequest") {
|
|
5
|
+
value;
|
|
6
|
+
request;
|
|
7
|
+
constructor(value) {
|
|
8
|
+
super();
|
|
9
|
+
this.value = value;
|
|
10
|
+
this.request = value;
|
|
11
|
+
}
|
|
12
|
+
static layer(value) {
|
|
13
|
+
return Layer.succeed(CurrentRequest, new CurrentRequest(value));
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
const CurrentRequestLayer = (value) => CurrentRequest.layer(value);
|
|
17
|
+
//#endregion
|
|
18
|
+
export { CurrentRequestLayer as n, CurrentRequest as t };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=current-request-DDKNyymv.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"current-request-DDKNyymv.mjs","names":[],"sources":["../src/standard-services/current-request.ts"],"sourcesContent":["import { Layer } from '../layer'\nimport { Service } from '../service'\n\n/** Execution-local request value carried by a normal Service provider. */\nexport class CurrentRequest extends Service<CurrentRequest>()('CurrentRequest') {\n readonly request: unknown\n\n // oxlint-disable-next-line anti-slop/no-unknown-parameters\n constructor(readonly value: unknown) {\n super()\n this.request = value\n }\n\n // oxlint-disable-next-line anti-slop/no-unknown-parameters\n static layer(value: unknown) {\n return Layer.succeed(CurrentRequest, new CurrentRequest(value))\n }\n}\n\n// oxlint-disable-next-line anti-slop/no-unknown-parameters\nexport const CurrentRequestLayer = (value: unknown) => CurrentRequest.layer(value)\n"],"mappings":";;;AAIA,IAAa,iBAAb,MAAa,uBAAuB,QAAwB,CAAC,CAAC,gBAAgB,CAAC,CAAC;CAIzD;CAHrB;CAGA,YAAY,OAAyB;EACnC,MAAM;EADa,KAAA,QAAA;EAEnB,KAAK,UAAU;CACjB;CAGA,OAAO,MAAM,OAAgB;EAC3B,OAAO,MAAM,QAAQ,gBAAgB,IAAI,eAAe,KAAK,CAAC;CAChE;AACF;AAGA,MAAa,uBAAuB,UAAmB,eAAe,MAAM,KAAK"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { d as setDefaultRuntimeContextStorage } from "./context-BphfFUMO.mjs";
|
|
2
|
+
import { n as nodeRuntimeContextStorage } from "./node-context-Ca18oNSg.mjs";
|
|
3
|
+
//#region src/runtime/default.ts
|
|
4
|
+
/** The Node/Bun storage used by the main Runtime entrypoint. */
|
|
5
|
+
const defaultRuntimeContextStorage = nodeRuntimeContextStorage;
|
|
6
|
+
setDefaultRuntimeContextStorage(defaultRuntimeContextStorage);
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/scope/errors.ts
|
|
9
|
+
/** Thrown when Scope context is accessed outside an active Scope execution. */
|
|
10
|
+
var ScopeRuntimeNotConfiguredError = class extends Error {
|
|
11
|
+
constructor() {
|
|
12
|
+
super("No Scope is available in the current execution context");
|
|
13
|
+
this.name = "ScopeRuntimeNotConfiguredError";
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
/** Thrown when a resource or finalizer is added after Scope closure begins. */
|
|
17
|
+
var ScopeClosedError = class extends Error {
|
|
18
|
+
constructor() {
|
|
19
|
+
super("Cannot add resources or finalizers to a closed Scope");
|
|
20
|
+
this.name = "ScopeClosedError";
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
/** Aggregates finalizer failures encountered while closing a Scope. */
|
|
24
|
+
var ScopeCloseError = class extends Error {
|
|
25
|
+
causes;
|
|
26
|
+
constructor(causes) {
|
|
27
|
+
super(`Failed to close Scope (${causes.length} finalizer${causes.length === 1 ? "" : "s"} failed)`);
|
|
28
|
+
this.causes = causes;
|
|
29
|
+
this.name = "ScopeCloseError";
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
/** Thrown when a value has neither Symbol.dispose nor Symbol.asyncDispose. */
|
|
33
|
+
var ResourceNotDisposableError = class extends Error {
|
|
34
|
+
constructor() {
|
|
35
|
+
super("Resource does not implement Symbol.dispose or Symbol.asyncDispose");
|
|
36
|
+
this.name = "ResourceNotDisposableError";
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/scope/disposable.ts
|
|
41
|
+
const SCOPE_SUCCESS = { status: "success" };
|
|
42
|
+
/** Return a Scope finalizer for a value's async or sync disposal protocol. */
|
|
43
|
+
const getDisposeFinalizer = (resource) => {
|
|
44
|
+
const candidate = Object(resource);
|
|
45
|
+
const asyncDispose = candidate[Symbol.asyncDispose];
|
|
46
|
+
if (asyncDispose instanceof Function) return () => asyncDispose.call(resource);
|
|
47
|
+
const dispose = candidate[Symbol.dispose];
|
|
48
|
+
if (dispose instanceof Function) return () => dispose.call(resource);
|
|
49
|
+
};
|
|
50
|
+
/** Dispose a value immediately when it implements a disposal protocol. */
|
|
51
|
+
const disposeResource = (resource) => {
|
|
52
|
+
return getDisposeFinalizer(resource)?.(SCOPE_SUCCESS);
|
|
53
|
+
};
|
|
54
|
+
//#endregion
|
|
55
|
+
export { ScopeClosedError as a, ScopeCloseError as i, getDisposeFinalizer as n, ScopeRuntimeNotConfiguredError as o, ResourceNotDisposableError as r, defaultRuntimeContextStorage as s, disposeResource as t };
|
|
56
|
+
|
|
57
|
+
//# sourceMappingURL=disposable-CP-Q2H3l.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"disposable-CP-Q2H3l.mjs","names":[],"sources":["../src/runtime/default.ts","../src/scope/errors.ts","../src/scope/disposable.ts"],"sourcesContent":["import { nodeRuntimeContextStorage } from './node-context'\n\nimport { setDefaultRuntimeContextStorage } from './context'\n\n/** The Node/Bun storage used by the main Runtime entrypoint. */\nexport const defaultRuntimeContextStorage = nodeRuntimeContextStorage\n\nsetDefaultRuntimeContextStorage(defaultRuntimeContextStorage)\n","/** Thrown when Scope context is accessed outside an active Scope execution. */\nexport class ScopeRuntimeNotConfiguredError extends Error {\n constructor() {\n super('No Scope is available in the current execution context')\n\n this.name = 'ScopeRuntimeNotConfiguredError'\n }\n}\n\n/** Thrown when a resource or finalizer is added after Scope closure begins. */\nexport class ScopeClosedError extends Error {\n constructor() {\n super('Cannot add resources or finalizers to a closed Scope')\n\n this.name = 'ScopeClosedError'\n }\n}\n\n/** Aggregates finalizer failures encountered while closing a Scope. */\nexport class ScopeCloseError extends Error {\n constructor(readonly causes: readonly unknown[]) {\n super(\n `Failed to close Scope (${causes.length} finalizer${causes.length === 1 ? '' : 's'} failed)`\n )\n\n this.name = 'ScopeCloseError'\n }\n}\n\n/** Thrown when a value has neither Symbol.dispose nor Symbol.asyncDispose. */\nexport class ResourceNotDisposableError extends Error {\n constructor() {\n super('Resource does not implement Symbol.dispose or Symbol.asyncDispose')\n\n this.name = 'ResourceNotDisposableError'\n }\n}\n","import type { ScopeFinalizer } from './types'\n\nconst SCOPE_SUCCESS = { status: 'success' } as const\n\ntype Disposer = (...args: never[]) => void | PromiseLike<void>\n\ntype DisposableCandidate = {\n [Symbol.dispose]?: Disposer\n\n [Symbol.asyncDispose]?: Disposer\n}\n\n/** Return a Scope finalizer for a value's async or sync disposal protocol. */\nexport const getDisposeFinalizer = <Resource>(resource: Resource): ScopeFinalizer | undefined => {\n // SAFETY: Object() provides a property-bearing view for protocol lookup; each method is checked for callability before invocation.\n const candidate = Object(resource) as DisposableCandidate\n const asyncDispose = candidate[Symbol.asyncDispose]\n\n if (asyncDispose instanceof Function) {\n return () => asyncDispose.call(resource)\n }\n\n const dispose = candidate[Symbol.dispose]\n\n if (dispose instanceof Function) {\n return () => dispose.call(resource)\n }\n\n return undefined\n}\n\n/** Dispose a value immediately when it implements a disposal protocol. */\nexport const disposeResource = <Resource>(resource: Resource): void | PromiseLike<void> => {\n const finalizer = getDisposeFinalizer(resource)\n\n return finalizer?.(SCOPE_SUCCESS)\n}\n"],"mappings":";;;;AAKA,MAAa,+BAA+B;AAE5C,gCAAgC,4BAA4B;;;;ACN5D,IAAa,iCAAb,cAAoD,MAAM;CACxD,cAAc;EACZ,MAAM,wDAAwD;EAE9D,KAAK,OAAO;CACd;AACF;;AAGA,IAAa,mBAAb,cAAsC,MAAM;CAC1C,cAAc;EACZ,MAAM,sDAAsD;EAE5D,KAAK,OAAO;CACd;AACF;;AAGA,IAAa,kBAAb,cAAqC,MAAM;CACpB;CAArB,YAAY,QAAqC;EAC/C,MACE,0BAA0B,OAAO,OAAO,YAAY,OAAO,WAAW,IAAI,KAAK,IAAI,SACrF;EAHmB,KAAA,SAAA;EAKnB,KAAK,OAAO;CACd;AACF;;AAGA,IAAa,6BAAb,cAAgD,MAAM;CACpD,cAAc;EACZ,MAAM,mEAAmE;EAEzE,KAAK,OAAO;CACd;AACF;;;AClCA,MAAM,gBAAgB,EAAE,QAAQ,UAAU;;AAW1C,MAAa,uBAAiC,aAAmD;CAE/F,MAAM,YAAY,OAAO,QAAQ;CACjC,MAAM,eAAe,UAAU,OAAO;CAEtC,IAAI,wBAAwB,UAC1B,aAAa,aAAa,KAAK,QAAQ;CAGzC,MAAM,UAAU,UAAU,OAAO;CAEjC,IAAI,mBAAmB,UACrB,aAAa,QAAQ,KAAK,QAAQ;AAItC;;AAGA,MAAa,mBAA6B,aAAiD;CAGzF,OAFkB,oBAAoB,QAEvB,CAAC,GAAG,aAAa;AAClC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as isPromiseLike } from "./runtime-CDcCF5cb.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { i as Scope, n as inheritProgramName, r as setProgramName } from "./program-metadata-BxjGkT17.mjs";
|
|
3
3
|
import { Err, Result, matchError, matchErrorPartial } from "better-result";
|
|
4
4
|
//#region src/effect/combinators.ts
|
|
5
5
|
const asResult = (value) => {
|
|
@@ -227,10 +227,22 @@ const recoverRuntime = (effect, recover) => {
|
|
|
227
227
|
if (isAsyncEffect(effect)) return Promise.resolve(effect).then((result) => Result.tryRecoverAsync(result, continueWith));
|
|
228
228
|
return Result.tryRecoverAsync(effect, continueWith);
|
|
229
229
|
};
|
|
230
|
-
const mapProgram = (program, fn) =>
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
|
|
230
|
+
const mapProgram = (program, fn) => {
|
|
231
|
+
const mapped = asProgram(() => mapRuntime(program(), fn));
|
|
232
|
+
return inheritProgramName(program, mapped);
|
|
233
|
+
};
|
|
234
|
+
const mapErrorProgram = (program, fn) => {
|
|
235
|
+
const mapped = asProgram(() => mapErrorRuntime(program(), fn));
|
|
236
|
+
return inheritProgramName(program, mapped);
|
|
237
|
+
};
|
|
238
|
+
const tapProgram = (program, fn) => {
|
|
239
|
+
const tapped = asProgram(() => tapRuntime(program(), fn));
|
|
240
|
+
return inheritProgramName(program, tapped);
|
|
241
|
+
};
|
|
242
|
+
const tapErrorProgram = (program, fn) => {
|
|
243
|
+
const tapped = asProgram(() => tapErrorRuntime(program(), fn));
|
|
244
|
+
return inheritProgramName(program, tapped);
|
|
245
|
+
};
|
|
234
246
|
function map(first, second) {
|
|
235
247
|
if (second === void 0) return (program) => {
|
|
236
248
|
return mapProgram(program, first);
|
|
@@ -244,8 +256,13 @@ function mapError(first, second) {
|
|
|
244
256
|
return mapErrorProgram(first, second);
|
|
245
257
|
}
|
|
246
258
|
function andThen(first, second) {
|
|
247
|
-
if (second === void 0) return (program) =>
|
|
248
|
-
|
|
259
|
+
if (second === void 0) return (program) => {
|
|
260
|
+
const chained = () => andThenRuntime(program(), first);
|
|
261
|
+
return inheritProgramName(program, chained);
|
|
262
|
+
};
|
|
263
|
+
const source = first;
|
|
264
|
+
const chained = () => andThenRuntime(source(), second);
|
|
265
|
+
return inheritProgramName(source, chained);
|
|
249
266
|
}
|
|
250
267
|
function tap(first, second) {
|
|
251
268
|
if (second === void 0) return (program) => {
|
|
@@ -260,8 +277,13 @@ function tapError(first, second) {
|
|
|
260
277
|
return tapErrorProgram(first, second);
|
|
261
278
|
}
|
|
262
279
|
function recover(first, second) {
|
|
263
|
-
if (second === void 0) return (program) =>
|
|
264
|
-
|
|
280
|
+
if (second === void 0) return (program) => {
|
|
281
|
+
const recovered = () => recoverRuntime(program(), first);
|
|
282
|
+
return inheritProgramName(program, recovered);
|
|
283
|
+
};
|
|
284
|
+
const source = first;
|
|
285
|
+
const recovered = () => recoverRuntime(source(), second);
|
|
286
|
+
return inheritProgramName(source, recovered);
|
|
265
287
|
}
|
|
266
288
|
//#endregion
|
|
267
289
|
//#region src/effect/program-scheduler.ts
|
|
@@ -326,6 +348,14 @@ function fn(body) {
|
|
|
326
348
|
const program = () => runResultGenerator(body);
|
|
327
349
|
return program;
|
|
328
350
|
}
|
|
351
|
+
const validateProgramName = (name) => {
|
|
352
|
+
if (typeof name !== "string") throw new TypeError("Program name must be a string");
|
|
353
|
+
};
|
|
354
|
+
function programNamed(name, program) {
|
|
355
|
+
validateProgramName(name);
|
|
356
|
+
if (program === void 0) return (source) => setProgramName(source, name);
|
|
357
|
+
return setProgramName(program, name);
|
|
358
|
+
}
|
|
329
359
|
const runShortCircuitingCollection = async (length, task, concurrency) => {
|
|
330
360
|
const outcome = await runProgramCollection(length, task, {
|
|
331
361
|
concurrency,
|
|
@@ -348,26 +378,42 @@ const runAllResultsCollection = async (length, task, concurrency) => {
|
|
|
348
378
|
/** Build a lazy Program collection with optional bounded concurrency. */
|
|
349
379
|
function programAll(programs, options = {}) {
|
|
350
380
|
const concurrency = options.concurrency;
|
|
381
|
+
const name = options?.name;
|
|
351
382
|
validateProgramConcurrency(concurrency);
|
|
352
383
|
const program = () => runShortCircuitingCollection(programs.length, (index) => programs[index](), concurrency);
|
|
384
|
+
if (name !== void 0) {
|
|
385
|
+
validateProgramName(name);
|
|
386
|
+
setProgramName(program, name);
|
|
387
|
+
}
|
|
353
388
|
return program;
|
|
354
389
|
}
|
|
355
390
|
/** Build a lazy Program collection from an input array and Program factory. */
|
|
356
391
|
function programForEach(items, makeProgram, options = {}) {
|
|
357
392
|
const concurrency = options.concurrency;
|
|
393
|
+
const name = options?.name;
|
|
358
394
|
validateProgramConcurrency(concurrency);
|
|
359
395
|
const program = () => runShortCircuitingCollection(items.length, (index) => makeProgram(items[index], index)(), concurrency);
|
|
396
|
+
if (name !== void 0) {
|
|
397
|
+
validateProgramName(name);
|
|
398
|
+
setProgramName(program, name);
|
|
399
|
+
}
|
|
360
400
|
return program;
|
|
361
401
|
}
|
|
362
402
|
/** Build a lazy Program collection that retains every child Result. */
|
|
363
403
|
function programAllResults(programs, options = {}) {
|
|
364
404
|
const concurrency = options.concurrency;
|
|
405
|
+
const name = options?.name;
|
|
365
406
|
validateProgramConcurrency(concurrency);
|
|
366
407
|
const program = () => runAllResultsCollection(programs.length, (index) => programs[index](), concurrency);
|
|
408
|
+
if (name !== void 0) {
|
|
409
|
+
validateProgramName(name);
|
|
410
|
+
setProgramName(program, name);
|
|
411
|
+
}
|
|
367
412
|
return program;
|
|
368
413
|
}
|
|
369
414
|
/** Value-level namespace for lazy Program combinators. */
|
|
370
415
|
const Program = {
|
|
416
|
+
named: programNamed,
|
|
371
417
|
all: programAll,
|
|
372
418
|
forEach: programForEach,
|
|
373
419
|
allResults: programAllResults,
|
|
@@ -510,4 +556,4 @@ const Effect = {
|
|
|
510
556
|
//#endregion
|
|
511
557
|
export { Program as n, Effect as t };
|
|
512
558
|
|
|
513
|
-
//# sourceMappingURL=effect-
|
|
559
|
+
//# sourceMappingURL=effect-CPdV7Yv8.mjs.map
|