better-effect 0.13.0 → 0.14.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 +337 -88
- package/dist/adapters/iti.d.mts +2 -3
- package/dist/adapters/iti.d.mts.map +1 -1
- package/dist/adapters/iti.mjs +2 -2
- package/dist/bun.d.mts +75 -23
- package/dist/bun.d.mts.map +1 -1
- package/dist/bun.mjs +170 -33
- package/dist/bun.mjs.map +1 -1
- package/dist/{context-BphfFUMO.mjs → context-DSGSqcJj.mjs} +12 -3
- package/dist/context-DSGSqcJj.mjs.map +1 -0
- package/dist/{current-request-DDKNyymv.mjs → current-request-Bc1YHL0w.mjs} +3 -2
- package/dist/{current-request-DDKNyymv.mjs.map → current-request-Bc1YHL0w.mjs.map} +1 -1
- package/dist/{current-request-CIU7AHhF.d.mts → current-request-Dm-QQ3Xr.d.mts} +4 -4
- package/dist/current-request-Dm-QQ3Xr.d.mts.map +1 -0
- package/dist/{effect-CPdV7Yv8.mjs → effect-W0IQXY8P.mjs} +21 -2
- package/dist/effect-W0IQXY8P.mjs.map +1 -0
- package/dist/{errors-BKcsQ0ip.d.mts → errors-CpHMzPiP.d.mts} +6 -2
- package/dist/errors-CpHMzPiP.d.mts.map +1 -0
- package/dist/hono.d.mts +63 -27
- package/dist/hono.d.mts.map +1 -1
- package/dist/hono.mjs +111 -45
- package/dist/hono.mjs.map +1 -1
- package/dist/{index-CCi07kUw.d.mts → index-3Bkl-sxS.d.mts} +7 -2
- package/dist/{index-CCi07kUw.d.mts.map → index-3Bkl-sxS.d.mts.map} +1 -1
- package/dist/{index-cXgyMa0v.d.mts → index-C2ed9Ilq.d.mts} +32 -7
- package/dist/index-C2ed9Ilq.d.mts.map +1 -0
- package/dist/{index-BodMy6rO.d.mts → index-ClNndn2-.d.mts} +93 -63
- package/dist/index-ClNndn2-.d.mts.map +1 -0
- package/dist/{index-DAKn0qHk.d.mts → index-Cy1VsU-u.d.mts} +2 -4
- package/dist/index-Cy1VsU-u.d.mts.map +1 -0
- package/dist/index.d.mts +6 -8
- package/dist/index.mjs +8 -9
- package/dist/index.mjs.map +1 -1
- package/dist/{internal-identity-CbXoZIfw.mjs → internal-identity-BuHBtP0k.mjs} +2 -2
- package/dist/{internal-identity-CbXoZIfw.mjs.map → internal-identity-BuHBtP0k.mjs.map} +1 -1
- package/dist/layer-2kjHVv4N.mjs +343 -0
- package/dist/layer-2kjHVv4N.mjs.map +1 -0
- package/dist/layer-C2OaqTmB.d.mts +987 -0
- package/dist/layer-C2OaqTmB.d.mts.map +1 -0
- package/dist/next.d.mts +102 -26
- package/dist/next.d.mts.map +1 -1
- package/dist/next.mjs +157 -40
- package/dist/next.mjs.map +1 -1
- package/dist/{node-context-DczjAcrX.d.mts → node-context-1YEjrU9g.d.mts} +2 -2
- package/dist/{node-context-DczjAcrX.d.mts.map → node-context-1YEjrU9g.d.mts.map} +1 -1
- package/dist/{node-context-Ca18oNSg.mjs → node-context-g3bCcY9t.mjs} +2 -2
- package/dist/{node-context-Ca18oNSg.mjs.map → node-context-g3bCcY9t.mjs.map} +1 -1
- package/dist/node.d.mts +11 -6
- package/dist/node.d.mts.map +1 -1
- package/dist/node.mjs +156 -10
- package/dist/node.mjs.map +1 -1
- package/dist/opentelemetry.d.mts +20 -2
- package/dist/opentelemetry.d.mts.map +1 -1
- package/dist/opentelemetry.mjs +423 -5
- package/dist/opentelemetry.mjs.map +1 -1
- package/dist/{registration-drnZk0SY.mjs → registration-Bwe2GbVu.mjs} +8 -2
- package/dist/registration-Bwe2GbVu.mjs.map +1 -0
- package/dist/runtime/explicit.d.mts +2 -2
- package/dist/runtime/explicit.mjs +1 -1
- package/dist/runtime/node.d.mts +3 -3
- package/dist/runtime/node.mjs +2 -2
- package/dist/runtime-qpcVwaz_.mjs +1680 -0
- package/dist/runtime-qpcVwaz_.mjs.map +1 -0
- package/dist/service-CO9VJQYa.mjs +74 -0
- package/dist/service-CO9VJQYa.mjs.map +1 -0
- package/dist/{signal-nfgFyNCk.mjs → signal-5Rg9bUUe.mjs} +2 -2
- package/dist/{signal-nfgFyNCk.mjs.map → signal-5Rg9bUUe.mjs.map} +1 -1
- package/dist/{standard-services-vnGIafkS.mjs → standard-services-B-iMM_W7.mjs} +38 -4
- package/dist/standard-services-B-iMM_W7.mjs.map +1 -0
- package/dist/standard-services.d.mts +4 -4
- package/dist/standard-services.mjs +3 -3
- package/dist/testing.d.mts +25 -7
- package/dist/testing.d.mts.map +1 -1
- package/dist/testing.mjs +51 -7
- package/dist/testing.mjs.map +1 -1
- package/dist/{types-oihI-ESv.d.mts → types-BFTqCCcw.d.mts} +32 -5
- package/dist/types-BFTqCCcw.d.mts.map +1 -0
- package/dist/web-effect-B9hp9jIe.mjs +380 -0
- package/dist/web-effect-B9hp9jIe.mjs.map +1 -0
- package/dist/web.d.mts +22 -13
- package/dist/web.d.mts.map +1 -1
- package/dist/web.mjs +1 -1
- package/package.json +10 -16
- package/dist/context-BphfFUMO.mjs.map +0 -1
- package/dist/current-request-CIU7AHhF.d.mts.map +0 -1
- package/dist/disposable-CP-Q2H3l.mjs +0 -57
- package/dist/disposable-CP-Q2H3l.mjs.map +0 -1
- package/dist/effect-CPdV7Yv8.mjs.map +0 -1
- package/dist/errors-BKcsQ0ip.d.mts.map +0 -1
- package/dist/index-AiKM71-u.d.mts +0 -376
- package/dist/index-AiKM71-u.d.mts.map +0 -1
- package/dist/index-BodMy6rO.d.mts.map +0 -1
- package/dist/index-DAKn0qHk.d.mts.map +0 -1
- package/dist/index-cXgyMa0v.d.mts.map +0 -1
- package/dist/layer-D16GKxuX.mjs +0 -269
- package/dist/layer-D16GKxuX.mjs.map +0 -1
- package/dist/observer-9nhbL7Pr.d.mts +0 -68
- package/dist/observer-9nhbL7Pr.d.mts.map +0 -1
- package/dist/outcome-DI8LPIQ4.d.mts +0 -387
- package/dist/outcome-DI8LPIQ4.d.mts.map +0 -1
- package/dist/program-metadata-BxjGkT17.mjs +0 -260
- package/dist/program-metadata-BxjGkT17.mjs.map +0 -1
- package/dist/registration-drnZk0SY.mjs.map +0 -1
- package/dist/runtime-C_55ofnL.mjs +0 -791
- package/dist/runtime-C_55ofnL.mjs.map +0 -1
- package/dist/standard-services-vnGIafkS.mjs.map +0 -1
- package/dist/types-oihI-ESv.d.mts.map +0 -1
- package/dist/web-Bq3MfMrj.mjs +0 -147
- package/dist/web-Bq3MfMrj.mjs.map +0 -1
package/dist/bun.d.mts
CHANGED
|
@@ -1,43 +1,95 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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";
|
|
1
|
+
import { At as EffectRequirements, Bt as ServiceContract, It as ServiceRequirement, Kt as ServiceToken, Lt as AnyService, Nt as InferYieldRequirements, Ot as EffectError, Ut as ServiceRequirements, Vt as ServiceIdentity, ct as ValidateLayerInput, ft as ProviderEntry, it as MissingServices, lt as ValidateOneOverride, ot as ProvidedEnvironment, rt as LayerResult, st as RequiredEnvironment, tt as LayerInput } from "./layer-C2OaqTmB.mjs";
|
|
2
|
+
import { t as CurrentRequest } from "./current-request-Dm-QQ3Xr.mjs";
|
|
3
|
+
import { f as WebEffectSuccess, i as DefaultRequestLayer, o as WebEffectOptions, s as WebEffectProgram } from "./types-BFTqCCcw.mjs";
|
|
5
4
|
//#region src/bun/types.d.ts
|
|
6
5
|
/** A Bun server passed to a Bun.serve fetch handler. */
|
|
7
6
|
type BunServer<WebSocketData = undefined> = Bun.Server<WebSocketData>;
|
|
7
|
+
/** Options accepted by the public Bun.serve API. */
|
|
8
|
+
type BunServeOptions<WebSocketData = undefined, Route extends string = string> = Bun.Serve.Options<WebSocketData, Route>;
|
|
8
9
|
/** The Promise<Response> handler shape accepted by Bun.serve. */
|
|
9
10
|
type BunFetchHandler<WebSocketData = undefined> = (request: Request, server: BunServer<WebSocketData>) => Promise<Response>;
|
|
10
11
|
/** A lazy Result-valued Program accepted by the Bun adapter. */
|
|
11
12
|
type BunEffectProgram<A = unknown, E = unknown, R extends AnyService = never> = WebEffectProgram<A, E, R>;
|
|
12
|
-
/**
|
|
13
|
-
type
|
|
13
|
+
/** A standard Web response or an asynchronous response. */
|
|
14
|
+
type ResponseLike = Response | PromiseLike<Response>;
|
|
15
|
+
/** Options used by `BunEffect.handler`. */
|
|
16
|
+
type BunEffectOptions<Failure = unknown, RequestLayer extends LayerInput = DefaultRequestLayer, Success = unknown> = Omit<WebEffectOptions<Failure, RequestLayer, Success>, 'onFailure' | 'onSuccess'> & {
|
|
14
17
|
/** Convert a successful Program value into a Response. */
|
|
15
|
-
readonly onSuccess?: (result: WebEffectSuccess
|
|
18
|
+
readonly onSuccess?: (result: WebEffectSuccess<Success>, request: Request) => ResponseLike;
|
|
16
19
|
/** Convert a typed Program failure into a Response. */
|
|
17
20
|
readonly onFailure?: (error: Failure, request: Request) => ResponseLike;
|
|
18
21
|
};
|
|
19
|
-
/** A
|
|
20
|
-
|
|
22
|
+
/** A yieldable operation acquired from a Bun Layer. */
|
|
23
|
+
interface BunEffectOperation<A, Requirements extends AnyService = never> {
|
|
24
|
+
readonly [Symbol.iterator]: () => Generator<ServiceRequirement<Requirements>, A, unknown>;
|
|
25
|
+
readonly [Symbol.asyncIterator]: () => AsyncGenerator<ServiceRequirement<Requirements>, A, unknown>;
|
|
26
|
+
}
|
|
27
|
+
type FailureCheck<Failure, Actual> = [Actual] extends [Failure] ? unknown : {
|
|
28
|
+
readonly __betterEffectInvalidBunFailure: {
|
|
29
|
+
readonly actual: Actual;
|
|
30
|
+
readonly expected: Failure;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
/** Validate a Bun Program's typed failure channel at the handler boundary. */
|
|
34
|
+
type BunProgramChecks<Program extends BunAnyProgram, Failure = unknown> = FailureCheck<Failure, EffectError<Program>>;
|
|
35
|
+
/** Validate a request Layer against Bun's built-in CurrentRequest provider. */
|
|
36
|
+
type BunRequestLayerChecks<RequestLayer extends LayerInput> = ValidateLayerInput<RequestLayer> & ValidateOneOverride<DefaultRequestLayer, RequestLayer>;
|
|
37
|
+
/** Services that a handler's enclosing Layer must provide. */
|
|
38
|
+
type BunHandlerRequirements<RequestLayer extends LayerInput, Program extends BunAnyProgram> = Extract<RequiredEnvironment<RequestLayer> | MissingServices<Extract<EffectRequirements<Program>, AnyService>, Extract<InstanceType<typeof CurrentRequest> | ProvidedEnvironment<RequestLayer>, AnyService>>, AnyService>;
|
|
39
|
+
/** A Bun handler Program factory with its typed failure contract checked. */
|
|
40
|
+
type BunHandlerFactory<Failure, WebSocketData, ProgramFactory extends (request: Request, server: BunServer<WebSocketData>) => BunAnyProgram> = ProgramFactory & ([ReturnType<ProgramFactory>] extends [BunProgramChecks<ReturnType<ProgramFactory>, Failure>] ? unknown : (request: Request, server: BunServer<WebSocketData>) => ReturnType<ProgramFactory> & BunProgramChecks<ReturnType<ProgramFactory>, Failure>);
|
|
41
|
+
/** A Layer-first Bun server factory returning native Bun.serve options. */
|
|
42
|
+
type BunServerFactory<WebSocketData = undefined, Route extends string = string, Yield extends ServiceRequirement<any> = ServiceRequirement<any>> = () => Generator<Yield, BunServeOptions<WebSocketData, Route>, unknown> | AsyncGenerator<Yield, BunServeOptions<WebSocketData, Route>, unknown>;
|
|
43
|
+
/** The result of a custom Bun Service Layer factory. */
|
|
44
|
+
type BunServerLayerSpec<Service extends ServiceToken<any, any>, WebSocketData = undefined, Route extends string = string> = {
|
|
45
|
+
readonly options: BunServeOptions<WebSocketData, Route>;
|
|
46
|
+
readonly map: (server: BunServer<WebSocketData>) => ServiceContract<InstanceType<Service>> | PromiseLike<ServiceContract<InstanceType<Service>>>;
|
|
47
|
+
};
|
|
48
|
+
/** A Layer-first Bun server factory for an application-owned Service token. */
|
|
49
|
+
type BunServerLayerFactory<Service extends ServiceToken<any, any>, WebSocketData = undefined, Route extends string = string, Yield extends ServiceRequirement<any> = ServiceRequirement<any>> = () => Generator<Yield, BunServerLayerSpec<Service, WebSocketData, Route>, unknown> | AsyncGenerator<Yield, BunServerLayerSpec<Service, WebSocketData, Route>, unknown>;
|
|
50
|
+
type BunServerFactoryResult<Factory> = Factory extends ((...arguments_: any[]) => infer Iterator) ? Iterator extends Generator<any, infer Result, any> ? Result : Iterator extends AsyncGenerator<any, infer Result, any> ? Result : never : never;
|
|
51
|
+
type DefaultBunServerData<Data> = unknown extends Data ? undefined : Data;
|
|
52
|
+
type DefaultBunServerRoute<Route> = unknown extends Route ? string : Route;
|
|
53
|
+
/** @internal Infer the native Bun server data generic from a server factory. */
|
|
54
|
+
type InferBunServerData<Factory> = BunServerFactoryResult<Factory> extends Bun.Serve.Options<infer Data, infer _Route extends string> ? DefaultBunServerData<Data> : undefined;
|
|
55
|
+
/** @internal Infer the native Bun route generic from a server factory. */
|
|
56
|
+
type InferBunServerRoute<Factory> = BunServerFactoryResult<Factory> extends Bun.Serve.Options<infer _Data, infer Route extends string> ? DefaultBunServerRoute<Route> : string;
|
|
57
|
+
/** @internal Prefer an explicit data generic, otherwise infer it from options. */
|
|
58
|
+
type BunServerDataFor<Explicit, Factory> = [Explicit] extends [never] ? InferBunServerData<Factory> : Explicit;
|
|
59
|
+
/** @internal Prefer an explicit route generic, otherwise infer it from options. */
|
|
60
|
+
type BunServerRouteFor<Explicit extends string, Factory> = [Explicit] extends [never] ? InferBunServerRoute<Factory> : Explicit;
|
|
61
|
+
/** @internal Validate explicit server generics without blocking factory inference. */
|
|
62
|
+
type BunServerFactoryCheck<ExplicitData, ExplicitRoute extends string, Factory> = [ExplicitData] extends [never] ? unknown : Factory extends BunServerFactory<ExplicitData, BunServerRouteFor<ExplicitRoute, Factory>> ? unknown : {
|
|
63
|
+
readonly __betterEffectInvalidBunServerFactory: {
|
|
64
|
+
readonly data: ExplicitData;
|
|
65
|
+
readonly route: ExplicitRoute;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
/** A Layer that provides the Service selected by `BunEffect.layer`. */
|
|
69
|
+
type BunEffectLayer<Service extends ServiceToken<any, any>, Yield extends ServiceRequirement<any>> = LayerResult<ProviderEntry<InstanceType<Service>, Extract<ServiceRequirements<InstanceType<Service>> | InferYieldRequirements<Yield>, AnyService>>>;
|
|
70
|
+
/** A generated raw Bun server token with its Layer attached. */
|
|
71
|
+
type BunServerToken<Tag extends string, WebSocketData, _Route extends string, Yield extends ServiceRequirement<any>> = ServiceToken<Tag, BunServer<WebSocketData> & ServiceIdentity<Tag>> & {
|
|
72
|
+
readonly layer: BunEffectLayer<ServiceToken<Tag, BunServer<WebSocketData> & ServiceIdentity<Tag>>, Yield>;
|
|
73
|
+
};
|
|
21
74
|
/** @internal */
|
|
22
|
-
type BunAnyProgram =
|
|
75
|
+
type BunAnyProgram = WebEffectProgram<any, any, AnyService>;
|
|
23
76
|
/** @internal */
|
|
24
|
-
type
|
|
77
|
+
type BunLiteralTag<Tag extends string> = string extends Tag ? never : Tag extends '' ? never : Tag;
|
|
25
78
|
/** @internal */
|
|
26
|
-
type
|
|
79
|
+
type InferGeneratorYield<Factory> = Factory extends ((...arguments_: any[]) => infer Iterator) ? Iterator extends Generator<infer Yield, any, any> ? Yield : Iterator extends AsyncGenerator<infer Yield, any, any> ? Yield : never : never;
|
|
27
80
|
//#endregion
|
|
28
81
|
//#region src/bun/index.d.ts
|
|
29
|
-
|
|
30
|
-
|
|
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;
|
|
82
|
+
/** Layer-first Bun integration for effectful handlers and owned servers. */
|
|
83
|
+
declare class BunEffect {
|
|
36
84
|
private constructor();
|
|
37
|
-
|
|
38
|
-
handler<WebSocketData = undefined, const ProgramFactory extends (request: Request, server: Bun.Server<WebSocketData>) => BunAnyProgram = (request: Request, server: Bun.Server<WebSocketData>) => BunAnyProgram>(
|
|
39
|
-
|
|
85
|
+
/** Build a fetch handler by capturing the active Runtime executor. */
|
|
86
|
+
static handler<WebSocketData = undefined, RequestLayer extends LayerInput = DefaultRequestLayer, Failure = unknown, const ProgramFactory extends (request: Request, server: Bun.Server<WebSocketData>) => BunAnyProgram = (request: Request, server: Bun.Server<WebSocketData>) => BunAnyProgram>(options: BunEffectOptions<Failure, RequestLayer> & BunRequestLayerChecks<RequestLayer>, makeProgram: BunHandlerFactory<Failure, WebSocketData, ProgramFactory>): BunEffectOperation<BunFetchHandler<WebSocketData>, BunHandlerRequirements<RequestLayer, ReturnType<ProgramFactory>>>;
|
|
87
|
+
static handler<WebSocketData = undefined, RequestLayer extends LayerInput = DefaultRequestLayer, Failure = unknown, const ProgramFactory extends (request: Request, server: Bun.Server<WebSocketData>) => BunAnyProgram = (request: Request, server: Bun.Server<WebSocketData>) => BunAnyProgram>(makeProgram: BunHandlerFactory<Failure, WebSocketData, ProgramFactory>): BunEffectOperation<BunFetchHandler<WebSocketData>, BunHandlerRequirements<RequestLayer, ReturnType<ProgramFactory>>>;
|
|
88
|
+
/** Create a raw Bun server Service and its lifecycle-owning Layer. */
|
|
89
|
+
static server<const Tag extends string, WebSocketData = never, Route extends string = never, const Factory extends BunServerFactory<any, any> = BunServerFactory<any, any>>(tag: Tag & BunLiteralTag<Tag>, factory: Factory & BunServerFactoryCheck<WebSocketData, Route, Factory>): BunServerToken<Tag, BunServerDataFor<WebSocketData, Factory>, BunServerRouteFor<Route, Factory>, InferGeneratorYield<Factory>>;
|
|
90
|
+
/** Provide an application-chosen Service token backed by a native Bun server. */
|
|
91
|
+
static layer<Service extends ServiceToken<any, any>, WebSocketData = undefined, Route extends string = string, const Factory extends BunServerLayerFactory<Service, WebSocketData, Route> = BunServerLayerFactory<Service, WebSocketData, Route>>(service: Service, factory: Factory): BunEffectLayer<Service, InferGeneratorYield<Factory>>;
|
|
40
92
|
}
|
|
41
93
|
//#endregion
|
|
42
|
-
export { BunEffect, type BunEffectOptions, type BunEffectProgram, type BunFetchHandler, type BunServer, type ResponseLike };
|
|
94
|
+
export { BunEffect, type BunEffectLayer, type BunEffectOperation, type BunEffectOptions, type BunEffectProgram, type BunFetchHandler, type BunHandlerFactory, type BunHandlerRequirements, type BunRequestLayerChecks, type BunServeOptions, type BunServer, type BunServerFactory, type BunServerLayerFactory, type BunServerLayerSpec, type BunServerToken, type ResponseLike };
|
|
43
95
|
//# sourceMappingURL=bun.d.mts.map
|
package/dist/bun.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bun.d.mts","names":[],"sources":["../src/bun/types.ts","../src/bun/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"bun.d.mts","names":[],"sources":["../src/bun/types.ts","../src/bun/index.ts"],"mappings":";;;;;KAgCY,UAAU,6BAA6B,IAAI,OAAO;;KAGlD,gBACV,2BACA,iCACE,IAAI,MAAM,QAAQ,eAAe;;KAGzB,gBAAgB,8BAC1B,SAAS,SACT,QAAQ,UAAU,mBACf,QAAQ;;KAGD,iBACV,aACA,aACA,UAAU,sBACR,iBAAiB,GAAG,GAAG;;KAGf,eAAe,WAAW,YAAY;;KAGtC,iBACV,mBACA,qBAAqB,aAAa,qBAClC,qBACE,KAAK,iBAAiB,SAAS,cAAc;;WAEtC,aAAa,QAAQ,iBAAiB,UAAU,SAAS,YAAY;;WAErE,aAAa,OAAO,SAAS,SAAS,YAAY;;;UAI5C,mBAAmB,GAAG,qBAAqB;YAChD,OAAO,iBAAiB,UAAU,mBAAmB,eAAe;YACpE,OAAO,sBAAsB,eACrC,mBAAmB,eACnB;;KAKC,aAAa,SAAS,WAAW,iBAAiB;WAGxC;aACE,QAAQ;aACR,UAAU;;;;KAKf,iBAAiB,gBAAgB,eAAe,qBAAqB,aAC/E,SACA,YAAY;;KAIF,sBAAsB,qBAAqB,cACrD,mBAAmB,gBAAgB,oB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AAS,SAAS,UAAU,eAAe,SAAS,oBAAoB"}
|
package/dist/bun.mjs
CHANGED
|
@@ -1,37 +1,174 @@
|
|
|
1
|
-
import { t as Layer } from "./layer-
|
|
2
|
-
import { t as
|
|
1
|
+
import { l as ServiceRuntime, t as Layer } from "./layer-2kjHVv4N.mjs";
|
|
2
|
+
import { t as Service } from "./service-CO9VJQYa.mjs";
|
|
3
|
+
import { n as eraseRuntimeExecutor, t as Runtime } from "./runtime-qpcVwaz_.mjs";
|
|
4
|
+
import { t as WebEffect } from "./web-effect-B9hp9jIe.mjs";
|
|
5
|
+
//#region src/bun/handler.ts
|
|
6
|
+
const makeOperation = (factory) => ({
|
|
7
|
+
*[Symbol.iterator]() {
|
|
8
|
+
const executor = yield* Runtime.executor();
|
|
9
|
+
return factory(eraseRuntimeExecutor(executor));
|
|
10
|
+
},
|
|
11
|
+
async *[Symbol.asyncIterator]() {
|
|
12
|
+
const executor = yield* Runtime.executor();
|
|
13
|
+
return factory(eraseRuntimeExecutor(executor));
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
const makeBoundaryOptions = (options, request) => {
|
|
17
|
+
const boundaryOptions = {};
|
|
18
|
+
if (options.requestLayer !== void 0) boundaryOptions.requestLayer = () => options.requestLayer(request);
|
|
19
|
+
if (options.onSuccess !== void 0) boundaryOptions.onSuccess = (result) => options.onSuccess(result, request);
|
|
20
|
+
if (options.onFailure !== void 0) boundaryOptions.onFailure = (error) => options.onFailure(error, request);
|
|
21
|
+
return boundaryOptions;
|
|
22
|
+
};
|
|
23
|
+
const makeHandler = (executor, options, factory) => async (request, server) => {
|
|
24
|
+
const program = () => factory(request, server)();
|
|
25
|
+
const boundaryProgram = program;
|
|
26
|
+
const boundaryOptions = makeBoundaryOptions(options, request);
|
|
27
|
+
return await WebEffect.handleWith(executor, request, boundaryProgram, boundaryOptions);
|
|
28
|
+
};
|
|
29
|
+
/** Build Bun fetch handlers whose Runtime capability is captured by a Layer. */
|
|
30
|
+
const makeBunHandler = (...args) => {
|
|
31
|
+
const first = args[0];
|
|
32
|
+
const isFactory = typeof first === "function";
|
|
33
|
+
const options = isFactory ? {} : first;
|
|
34
|
+
const factory = isFactory ? first : args[1];
|
|
35
|
+
return makeOperation((executor) => {
|
|
36
|
+
return makeHandler(executor, options, factory);
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/bun/server.ts
|
|
41
|
+
const runFactory = async (factory) => {
|
|
42
|
+
const iterator = factory();
|
|
43
|
+
let state = await iterator.next();
|
|
44
|
+
while (!state.done) {
|
|
45
|
+
const token = state.value;
|
|
46
|
+
state = await iterator.next(await ServiceRuntime.resolve(token));
|
|
47
|
+
}
|
|
48
|
+
return state.value;
|
|
49
|
+
};
|
|
50
|
+
var BunServerState = class {
|
|
51
|
+
server;
|
|
52
|
+
binding;
|
|
53
|
+
stopPromise;
|
|
54
|
+
get acquired() {
|
|
55
|
+
return this.server;
|
|
56
|
+
}
|
|
57
|
+
acquire(binding) {
|
|
58
|
+
if (this.server !== void 0) return this.server;
|
|
59
|
+
const server = Bun.serve(binding.options);
|
|
60
|
+
this.binding = binding;
|
|
61
|
+
this.server = server;
|
|
62
|
+
return server;
|
|
63
|
+
}
|
|
64
|
+
currentBinding() {
|
|
65
|
+
return this.binding;
|
|
66
|
+
}
|
|
67
|
+
stop(server) {
|
|
68
|
+
if (this.stopPromise !== void 0) return this.stopPromise;
|
|
69
|
+
try {
|
|
70
|
+
this.stopPromise = server.stop();
|
|
71
|
+
} catch (cause) {
|
|
72
|
+
this.stopPromise = Promise.reject(cause);
|
|
73
|
+
}
|
|
74
|
+
this.stopPromise.catch(() => {});
|
|
75
|
+
return this.stopPromise;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const currentRuntimeExecutor = () => {
|
|
79
|
+
const result = Runtime.executor()[Symbol.iterator]().next();
|
|
80
|
+
if (!result.done) throw new Error("Runtime executor request did not settle synchronously");
|
|
81
|
+
return result.value;
|
|
82
|
+
};
|
|
83
|
+
/** Create a lifecycle-owning Bun server Layer for any Service token. */
|
|
84
|
+
const makeBunLayer = (service, factory) => {
|
|
85
|
+
const states = /* @__PURE__ */ new WeakMap();
|
|
86
|
+
const statesByServer = /* @__PURE__ */ new WeakMap();
|
|
87
|
+
const stateForRuntime = () => {
|
|
88
|
+
const executor = currentRuntimeExecutor();
|
|
89
|
+
let state = states.get(executor);
|
|
90
|
+
if (state === void 0) {
|
|
91
|
+
state = new BunServerState();
|
|
92
|
+
states.set(executor, state);
|
|
93
|
+
}
|
|
94
|
+
return state;
|
|
95
|
+
};
|
|
96
|
+
const acquire = (state, binding) => {
|
|
97
|
+
const server = state.acquire(binding);
|
|
98
|
+
statesByServer.set(server, state);
|
|
99
|
+
return server;
|
|
100
|
+
};
|
|
101
|
+
const stateForServer = (server) => {
|
|
102
|
+
const state = statesByServer.get(server);
|
|
103
|
+
if (state === void 0) throw new Error("Bun server lifecycle state is unavailable");
|
|
104
|
+
return state;
|
|
105
|
+
};
|
|
106
|
+
const lifecycle = Layer.scopedDiscardGen(async function* () {
|
|
107
|
+
const state = stateForRuntime();
|
|
108
|
+
const existing = state.acquired;
|
|
109
|
+
if (existing !== void 0) return existing;
|
|
110
|
+
const binding = yield* factory();
|
|
111
|
+
return acquire(state, binding);
|
|
112
|
+
}, {
|
|
113
|
+
quiesce: (server) => {
|
|
114
|
+
stateForServer(server).stop(server);
|
|
115
|
+
},
|
|
116
|
+
release: (server) => {
|
|
117
|
+
return stateForServer(server).stop(server);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
const provider = Layer.make(service, async () => {
|
|
121
|
+
const state = stateForRuntime();
|
|
122
|
+
let binding = state.currentBinding();
|
|
123
|
+
if (binding === void 0) {
|
|
124
|
+
binding = await runFactory(factory);
|
|
125
|
+
acquire(state, binding);
|
|
126
|
+
}
|
|
127
|
+
const server = state.acquired;
|
|
128
|
+
if (server === void 0) throw new Error("Bun server acquisition did not produce a server");
|
|
129
|
+
return await binding.map(server);
|
|
130
|
+
});
|
|
131
|
+
return Layer.merge(provider, lifecycle);
|
|
132
|
+
};
|
|
133
|
+
const identityBinding = (options) => ({
|
|
134
|
+
options,
|
|
135
|
+
map: (server) => {
|
|
136
|
+
return server;
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
const makeBunServer = (factory, token) => {
|
|
140
|
+
const adaptedFactory = async function* () {
|
|
141
|
+
const options = yield* factory();
|
|
142
|
+
return identityBinding(options);
|
|
143
|
+
};
|
|
144
|
+
return {
|
|
145
|
+
token,
|
|
146
|
+
layer: makeBunLayer(token, adaptedFactory)
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
//#endregion
|
|
3
150
|
//#region src/bun/index.ts
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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;
|
|
151
|
+
/** Layer-first Bun integration for effectful handlers and owned servers. */
|
|
152
|
+
var BunEffect = class {
|
|
153
|
+
constructor() {}
|
|
154
|
+
static handler(...args) {
|
|
155
|
+
return makeBunHandler(...args);
|
|
156
|
+
}
|
|
157
|
+
/** Create a raw Bun server Service and its lifecycle-owning Layer. */
|
|
158
|
+
static server(tag, factory) {
|
|
159
|
+
const token = Service()(tag);
|
|
160
|
+
const built = makeBunServer(factory, token);
|
|
161
|
+
Object.defineProperty(built.token, "layer", {
|
|
162
|
+
configurable: false,
|
|
163
|
+
enumerable: true,
|
|
164
|
+
value: built.layer,
|
|
165
|
+
writable: false
|
|
166
|
+
});
|
|
167
|
+
return built.token;
|
|
168
|
+
}
|
|
169
|
+
/** Provide an application-chosen Service token backed by a native Bun server. */
|
|
170
|
+
static layer(service, factory) {
|
|
171
|
+
return makeBunLayer(service, factory);
|
|
35
172
|
}
|
|
36
173
|
};
|
|
37
174
|
//#endregion
|
package/dist/bun.mjs.map
CHANGED
|
@@ -1 +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"}
|
|
1
|
+
{"version":3,"file":"bun.mjs","names":["typedFactory"],"sources":["../src/bun/handler.ts","../src/bun/server.ts","../src/bun/index.ts"],"sourcesContent":["import type { ServiceRequirement } from '../effect/types'\nimport { Runtime } from '../runtime'\nimport { eraseRuntimeExecutor, type RuntimeExecutor } from '../runtime/executor'\nimport type { AnyService } from '../service'\nimport { WebEffect } from '../web'\nimport type { DefaultRequestLayer } from '../web/types'\nimport type { LayerInput } from '../layer/inference'\n\nimport type {\n BunAnyProgram,\n BunEffectOperation,\n BunEffectOptions,\n BunFetchHandler,\n BunHandlerFactory,\n BunHandlerRequirements,\n BunRequestLayerChecks,\n ResponseLike\n} from './types'\n\ntype HandlerArguments<\n RequestLayer extends LayerInput,\n Failure,\n WebSocketData,\n ProgramFactory extends (request: Request, server: Bun.Server<WebSocketData>) => BunAnyProgram\n> =\n | [\n options: BunEffectOptions<Failure, RequestLayer>,\n makeProgram: BunHandlerFactory<Failure, WebSocketData, ProgramFactory>\n ]\n | [makeProgram: BunHandlerFactory<Failure, WebSocketData, ProgramFactory>]\n\ntype OperationFactory<A> = (executor: RuntimeExecutor<AnyService>) => A\n\ntype BunBoundaryResult = {\n readonly value: unknown\n}\n\ninterface BunBoundaryOptions<RequestLayer extends LayerInput> {\n requestLayer?: (request: Request) => RequestLayer\n onSuccess?: (result: BunBoundaryResult) => ResponseLike\n // oxlint-disable-next-line anti-slop/no-unknown-parameters -- WebEffect failure values are opaque until the typed public policy consumes them.\n onFailure?: (error: unknown) => ResponseLike\n}\n\nconst makeOperation = <A, Requirements extends AnyService>(\n factory: OperationFactory<A>\n): BunEffectOperation<A, Requirements> => ({\n *[Symbol.iterator](): Generator<ServiceRequirement<Requirements>, A, unknown> {\n const executor = yield* Runtime.executor<Requirements>()\n return factory(eraseRuntimeExecutor(executor))\n },\n async *[Symbol.asyncIterator](): AsyncGenerator<ServiceRequirement<Requirements>, A, unknown> {\n const executor = yield* Runtime.executor<Requirements>()\n return factory(eraseRuntimeExecutor(executor))\n }\n})\n\nconst makeBoundaryOptions = <Failure, RequestLayer extends LayerInput>(\n options: BunEffectOptions<Failure, RequestLayer>,\n request: Request\n): BunBoundaryOptions<RequestLayer> => {\n const boundaryOptions: BunBoundaryOptions<RequestLayer> = {}\n\n if (options.requestLayer !== undefined) {\n boundaryOptions.requestLayer = () => options.requestLayer!(request)\n }\n\n if (options.onSuccess !== undefined) {\n boundaryOptions.onSuccess = (result) => options.onSuccess!(result, request)\n }\n\n if (options.onFailure !== undefined) {\n // SAFETY: WebEffect's failure channel is erased here and was checked by BunHandlerFactory at the public boundary.\n boundaryOptions.onFailure = (error) => options.onFailure!(error as Failure, request)\n }\n\n return boundaryOptions\n}\n\nconst makeHandler =\n <\n Failure,\n RequestLayer extends LayerInput,\n WebSocketData,\n const ProgramFactory extends (\n request: Request,\n server: Bun.Server<WebSocketData>\n ) => BunAnyProgram\n >(\n executor: RuntimeExecutor<AnyService>,\n options: BunEffectOptions<Failure, RequestLayer>,\n factory: ProgramFactory\n ): BunFetchHandler<WebSocketData> =>\n async (request, server) => {\n const program = () => factory(request, server)()\n\n // SAFETY: BunHandlerFactory validates the lazy Program before this erased WebEffect boundary.\n const boundaryProgram = program as BunAnyProgram\n // SAFETY: BunBoundaryOptions is structurally compatible with WebEffect's erased policy callbacks.\n const boundaryOptions = makeBoundaryOptions(options, request) as never\n return await WebEffect.handleWith(executor, request, boundaryProgram, boundaryOptions)\n }\n\n/** Build Bun fetch handlers whose Runtime capability is captured by a Layer. */\nexport const makeBunHandler = <\n RequestLayer extends LayerInput = DefaultRequestLayer,\n Failure = unknown,\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 ...args: HandlerArguments<RequestLayer, Failure, WebSocketData, ProgramFactory> &\n BunRequestLayerChecks<RequestLayer>\n): BunEffectOperation<\n BunFetchHandler<WebSocketData>,\n BunHandlerRequirements<RequestLayer, ReturnType<ProgramFactory>>\n> => {\n const first = args[0]\n // oxlint-disable-next-line anti-slop/no-runtime-typeof -- overload dispatch distinguishes the options object from the factory.\n const isFactory = typeof first === 'function'\n const options = isFactory ? {} : first\n // SAFETY: The overload tuple places the Program factory in this position.\n const factory = (isFactory ? first : args[1]) as ProgramFactory\n\n // SAFETY: makeOperation's erased implementation is restored to the validated public requirement channels.\n return makeOperation((executor) => {\n // SAFETY: HandlerArguments and BunRequestLayerChecks validate this erased options object.\n return makeHandler(executor, options as BunEffectOptions<Failure, RequestLayer>, factory)\n }) as BunEffectOperation<\n BunFetchHandler<WebSocketData>,\n BunHandlerRequirements<RequestLayer, ReturnType<ProgramFactory>>\n >\n}\n","import type { ServiceRequirement } from '../effect/types'\nimport { Layer } from '../layer'\nimport { ServiceRuntime } from '../service'\nimport type { AnyServiceToken, ServiceContract, ServiceToken } from '../service'\nimport { Runtime } from '../runtime'\nimport type { RuntimeExecutor } from '../runtime/executor'\n\nimport type {\n BunEffectLayer,\n BunServer,\n BunServerFactory,\n BunServerLayerFactory,\n BunServerLayerSpec,\n BunServeOptions,\n InferGeneratorYield\n} from './types'\n\ntype BunServerBinding<\n Service extends ServiceToken<any, any>,\n WebSocketData,\n Route extends string\n> = BunServerLayerSpec<Service, WebSocketData, Route>\n\ninterface BunServerBuild<\n Service extends ServiceToken<any, any>,\n Yield extends ServiceRequirement<any>\n> {\n readonly token: Service\n readonly layer: BunEffectLayer<Service, Yield>\n}\n\nconst runFactory = async <Returned>(\n factory: () =>\n | Generator<ServiceRequirement<any>, Returned, unknown>\n | AsyncGenerator<ServiceRequirement<any>, Returned, unknown>\n): Promise<Returned> => {\n const iterator = factory()\n let state = await iterator.next()\n\n while (!state.done) {\n // SAFETY: Layer generator yields are declaration-only Service token markers.\n // oxlint-disable-next-line anti-slop/no-chained-type-assertions\n const token = state.value as unknown as AnyServiceToken\n state = await iterator.next(await ServiceRuntime.resolve(token))\n }\n\n return state.value\n}\n\nclass BunServerState<Service extends ServiceToken<any, any>, WebSocketData, Route extends string> {\n private server: BunServer<WebSocketData> | undefined\n\n private binding: BunServerBinding<Service, WebSocketData, Route> | undefined\n\n private stopPromise: Promise<void> | undefined\n\n get acquired(): BunServer<WebSocketData> | undefined {\n return this.server\n }\n\n acquire(binding: BunServerBinding<Service, WebSocketData, Route>): BunServer<WebSocketData> {\n if (this.server !== undefined) {\n return this.server\n }\n\n const server = Bun.serve<WebSocketData, Route>(binding.options)\n this.binding = binding\n this.server = server\n return server\n }\n\n currentBinding(): BunServerBinding<Service, WebSocketData, Route> | undefined {\n return this.binding\n }\n\n stop(server: BunServer<WebSocketData>): Promise<void> {\n if (this.stopPromise !== undefined) {\n return this.stopPromise\n }\n\n try {\n this.stopPromise = server.stop()\n } catch (cause) {\n this.stopPromise = Promise.reject(cause)\n }\n\n this.stopPromise.catch(() => {})\n return this.stopPromise\n }\n}\n\nconst currentRuntimeExecutor = (): RuntimeExecutor<any> => {\n const iterator = Runtime.executor<any>()[Symbol.iterator]()\n const result = iterator.next()\n\n if (!result.done) {\n throw new Error('Runtime executor request did not settle synchronously')\n }\n\n return result.value\n}\n\n/** Create a lifecycle-owning Bun server Layer for any Service token. */\nexport const makeBunLayer = <\n Service extends ServiceToken<any, any>,\n WebSocketData,\n Route extends string,\n const Factory extends BunServerLayerFactory<Service, WebSocketData, Route>\n>(\n service: Service,\n factory: Factory\n): BunEffectLayer<Service, InferGeneratorYield<Factory>> => {\n const states = new WeakMap<RuntimeExecutor<any>, BunServerState<Service, WebSocketData, Route>>()\n const statesByServer = new WeakMap<\n BunServer<WebSocketData>,\n BunServerState<Service, WebSocketData, Route>\n >()\n const stateForRuntime = (): BunServerState<Service, WebSocketData, Route> => {\n const executor = currentRuntimeExecutor()\n let state = states.get(executor)\n\n if (state === undefined) {\n state = new BunServerState<Service, WebSocketData, Route>()\n states.set(executor, state)\n }\n\n return state\n }\n\n const acquire = (\n state: BunServerState<Service, WebSocketData, Route>,\n binding: BunServerBinding<Service, WebSocketData, Route>\n ): BunServer<WebSocketData> => {\n const server = state.acquire(binding)\n statesByServer.set(server, state)\n return server\n }\n\n const stateForServer = (\n server: BunServer<WebSocketData>\n ): BunServerState<Service, WebSocketData, Route> => {\n const state = statesByServer.get(server)\n\n if (state === undefined) {\n throw new Error('Bun server lifecycle state is unavailable')\n }\n\n return state\n }\n\n const lifecycle = Layer.scopedDiscardGen(\n async function* () {\n const state = stateForRuntime()\n const existing = state.acquired\n\n if (existing !== undefined) {\n return existing\n }\n\n const binding = yield* factory()\n return acquire(state, binding)\n },\n {\n quiesce: (server) => {\n // Bun.stop() stops accepting new connections immediately. Its Promise\n // is held for release so Runtime can drain its executions first.\n // SAFETY: Lifecycle callbacks receive the exact Bun server acquired by this state.\n const state = stateForServer(server as BunServer<WebSocketData>)\n // SAFETY: The same acquired server is passed back to the cached stop operation.\n void state.stop(server as BunServer<WebSocketData>)\n },\n release: (server) => {\n // SAFETY: Lifecycle callbacks receive the exact Bun server acquired by this state.\n const state = stateForServer(server as BunServer<WebSocketData>)\n // SAFETY: The same acquired server is passed back to the cached stop operation.\n return state.stop(server as BunServer<WebSocketData>)\n }\n }\n )\n\n const provider = Layer.make(service, async () => {\n const state = stateForRuntime()\n let binding = state.currentBinding()\n\n if (binding === undefined) {\n binding = await runFactory(factory)\n acquire(state, binding)\n }\n\n const server = state.acquired\n\n if (server === undefined) {\n throw new Error('Bun server acquisition did not produce a server')\n }\n\n return await binding.map(server)\n })\n\n // The provider exposes the mapped Service; the lifecycle entry owns the raw\n // server and makes startup happen once during Runtime acquisition.\n // SAFETY: Layer.merge erases heterogeneous provider entries only at this internal storage boundary.\n return Layer.merge(provider as Layer.Any, lifecycle as Layer.Any) as BunEffectLayer<\n Service,\n InferGeneratorYield<Factory>\n >\n}\n\nconst identityBinding = <\n Service extends ServiceToken<any, any>,\n WebSocketData,\n Route extends string\n>(\n options: BunServeOptions<WebSocketData, Route>\n): BunServerBinding<Service, WebSocketData, Route> => ({\n options,\n map: (server) => {\n // SAFETY: The generated token's instance contract is the native Bun server selected by its Data type.\n // oxlint-disable-next-line anti-slop/no-chained-type-assertions\n return server as unknown as ServiceContract<InstanceType<Service>>\n }\n})\n\nexport const makeBunServer = <\n const Tag extends string,\n WebSocketData,\n Route extends string,\n const Factory extends BunServerFactory<WebSocketData, Route>,\n Service extends ServiceToken<\n Tag,\n BunServer<WebSocketData> & import('../service').ServiceIdentity<Tag>\n >\n>(\n factory: Factory,\n token: Service\n): BunServerBuild<Service, InferGeneratorYield<Factory>> => {\n const adaptedFactory = async function* () {\n const options = yield* factory()\n return identityBinding<Service, WebSocketData, Route>(options)\n }\n const layer = makeBunLayer<Service, WebSocketData, Route, typeof adaptedFactory>(\n token,\n adaptedFactory\n )\n\n return { token, layer }\n}\n","import { Service } from '../service'\nimport type { AnyService, ServiceIdentity, ServiceToken } from '../service'\nimport type { LayerInput } from '../layer/inference'\nimport type { DefaultRequestLayer } from '../web/types'\n\nimport { makeBunHandler } from './handler'\nimport { makeBunLayer, makeBunServer } from './server'\nimport type {\n BunAnyProgram,\n BunEffectLayer,\n BunEffectOperation,\n BunEffectOptions,\n BunFetchHandler,\n BunHandlerFactory,\n BunHandlerRequirements,\n BunLiteralTag,\n BunRequestLayerChecks,\n BunServer,\n BunServerFactory,\n BunServerFactoryCheck,\n BunServerLayerFactory,\n BunServerToken,\n BunServerDataFor,\n BunServerRouteFor,\n InferGeneratorYield\n} from './types'\n\n/** Layer-first Bun integration for effectful handlers and owned servers. */\nexport class BunEffect {\n private constructor() {}\n\n /** Build a fetch handler by capturing the active Runtime executor. */\n static handler<\n WebSocketData = undefined,\n RequestLayer extends LayerInput = DefaultRequestLayer,\n Failure = unknown,\n const ProgramFactory extends (\n request: Request,\n server: Bun.Server<WebSocketData>\n ) => BunAnyProgram = (request: Request, server: Bun.Server<WebSocketData>) => BunAnyProgram\n >(\n options: BunEffectOptions<Failure, RequestLayer> & BunRequestLayerChecks<RequestLayer>,\n makeProgram: BunHandlerFactory<Failure, WebSocketData, ProgramFactory>\n ): BunEffectOperation<\n BunFetchHandler<WebSocketData>,\n BunHandlerRequirements<RequestLayer, ReturnType<ProgramFactory>>\n >\n\n static handler<\n WebSocketData = undefined,\n RequestLayer extends LayerInput = DefaultRequestLayer,\n Failure = unknown,\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<Failure, WebSocketData, ProgramFactory>\n ): BunEffectOperation<\n BunFetchHandler<WebSocketData>,\n BunHandlerRequirements<RequestLayer, ReturnType<ProgramFactory>>\n >\n\n static handler(...args: unknown[]): BunEffectOperation<unknown, AnyService> {\n // SAFETY: The overloads validate the argument tuple before this erased implementation.\n return makeBunHandler(...(args as never)) as BunEffectOperation<unknown, AnyService>\n }\n\n /** Create a raw Bun server Service and its lifecycle-owning Layer. */\n static server<\n const Tag extends string,\n WebSocketData = never,\n Route extends string = never,\n const Factory extends BunServerFactory<any, any> = BunServerFactory<any, any>\n >(\n tag: Tag & BunLiteralTag<Tag>,\n factory: Factory & BunServerFactoryCheck<WebSocketData, Route, Factory>\n ): BunServerToken<\n Tag,\n BunServerDataFor<WebSocketData, Factory>,\n BunServerRouteFor<Route, Factory>,\n InferGeneratorYield<Factory>\n > {\n type Data = BunServerDataFor<WebSocketData, Factory>\n type RouteType = BunServerRouteFor<Route, Factory>\n const tokenFactory = Service<BunServer<Data> & ServiceIdentity<Tag>>()<Tag>(tag)\n // SAFETY: Service() returns the class-backed token; this assertion restores the exact Bun server contract.\n // oxlint-disable-next-line anti-slop/no-chained-type-assertions\n const token = tokenFactory as unknown as ServiceToken<\n Tag,\n BunServer<Data> & ServiceIdentity<Tag>\n >\n // SAFETY: The factory check validates explicit generics; inferred Data and Route come from its native Bun options.\n // oxlint-disable-next-line anti-slop/no-chained-type-assertions\n const typedFactory = factory as unknown as BunServerFactory<Data, RouteType>\n const built = makeBunServer<Tag, Data, RouteType, typeof typedFactory, typeof token>(\n typedFactory,\n token\n )\n\n Object.defineProperty(built.token, 'layer', {\n configurable: false,\n enumerable: true,\n value: built.layer,\n writable: false\n })\n\n // SAFETY: makeBunServer constructs the matching token and Layer pair for these exact generic arguments.\n // oxlint-disable-next-line anti-slop/no-chained-type-assertions\n return built.token as unknown as BunServerToken<\n Tag,\n Data,\n RouteType,\n InferGeneratorYield<Factory>\n >\n }\n\n /** Provide an application-chosen Service token backed by a native Bun server. */\n static layer<\n Service extends ServiceToken<any, any>,\n WebSocketData = undefined,\n Route extends string = string,\n const Factory extends BunServerLayerFactory<Service, WebSocketData, Route> =\n BunServerLayerFactory<Service, WebSocketData, Route>\n >(service: Service, factory: Factory): BunEffectLayer<Service, InferGeneratorYield<Factory>> {\n return makeBunLayer<Service, WebSocketData, Route, typeof factory>(service, factory)\n }\n}\n\nexport type {\n BunEffectLayer,\n BunEffectOperation,\n BunEffectOptions,\n BunEffectProgram,\n BunFetchHandler,\n BunHandlerFactory,\n BunHandlerRequirements,\n BunRequestLayerChecks,\n BunServer,\n BunServerFactory,\n BunServerLayerFactory,\n BunServerLayerSpec,\n BunServerToken,\n BunServeOptions,\n ResponseLike\n} from './types'\n"],"mappings":";;;;;AA4CA,MAAM,iBACJ,aACyC;CACzC,EAAE,OAAO,YAAqE;EAC5E,MAAM,WAAW,OAAO,QAAQ,SAAuB;EACvD,OAAO,QAAQ,qBAAqB,QAAQ,CAAC;CAC/C;CACA,QAAQ,OAAO,iBAA+E;EAC5F,MAAM,WAAW,OAAO,QAAQ,SAAuB;EACvD,OAAO,QAAQ,qBAAqB,QAAQ,CAAC;CAC/C;AACF;AAEA,MAAM,uBACJ,SACA,YACqC;CACrC,MAAM,kBAAoD,CAAC;CAE3D,IAAI,QAAQ,iBAAiB,KAAA,GAC3B,gBAAgB,qBAAqB,QAAQ,aAAc,OAAO;CAGpE,IAAI,QAAQ,cAAc,KAAA,GACxB,gBAAgB,aAAa,WAAW,QAAQ,UAAW,QAAQ,OAAO;CAG5E,IAAI,QAAQ,cAAc,KAAA,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,QAAQ,gBAAgB;EAC9B,IAAI,UAAU,MAAM,eAAe;EAEnC,IAAI,YAAY,KAAA,GAAW;GACzB,UAAU,MAAM,WAAW,OAAO;GAClC,QAAQ,OAAO,OAAO;EACxB;EAEA,MAAM,SAAS,MAAM;EAErB,IAAI,WAAW,KAAA,GACb,MAAM,IAAI,MAAM,iDAAiD;EAGnE,OAAO,MAAM,QAAQ,IAAI,MAAM;CACjC,CAAC;CAKD,OAAO,MAAM,MAAM,UAAuB,SAAsB;AAIlE;AAEA,MAAM,mBAKJ,aACqD;CACrD;CACA,MAAM,WAAW;EAGf,OAAO;CACT;AACF;AAEA,MAAa,iBAUX,SACA,UAC0D;CAC1D,MAAM,iBAAiB,mBAAmB;EACxC,MAAM,UAAU,OAAO,QAAQ;EAC/B,OAAO,gBAA+C,OAAO;CAC/D;CAMA,OAAO;EAAE;EAAO,OALF,aACZ,OACA,cAGkB;CAAE;AACxB;;;;ACzNA,IAAa,YAAb,MAAuB;CACrB,cAAsB,CAAC;CAkCvB,OAAO,QAAQ,GAAG,MAA0D;EAE1E,OAAO,eAAe,GAAI,IAAc;CAC1C;;CAGA,OAAO,OAML,KACA,SAMA;EAMA,MAAM,QAHe,QAAgD,CAAC,CAAM,GAGnD;EAOzB,MAAM,QAAQ,cACZA,SACA,KACF;EAEA,OAAO,eAAe,MAAM,OAAO,SAAS;GAC1C,cAAc;GACd,YAAY;GACZ,OAAO,MAAM;GACb,UAAU;EACZ,CAAC;EAID,OAAO,MAAM;CAMf;;CAGA,OAAO,MAML,SAAkB,SAAyE;EAC3F,OAAO,aAA4D,SAAS,OAAO;CACrF;AACF"}
|
|
@@ -14,6 +14,13 @@ var RuntimeContextOverlapError = class extends Error {
|
|
|
14
14
|
this.name = "RuntimeContextOverlapError";
|
|
15
15
|
}
|
|
16
16
|
};
|
|
17
|
+
/** Thrown when a Runtime executor is requested without an active Runtime. */
|
|
18
|
+
var RuntimeExecutorNotConfiguredError = class extends Error {
|
|
19
|
+
constructor() {
|
|
20
|
+
super("No Runtime executor is available in the current execution context");
|
|
21
|
+
this.name = "RuntimeExecutorNotConfiguredError";
|
|
22
|
+
}
|
|
23
|
+
};
|
|
17
24
|
//#endregion
|
|
18
25
|
//#region src/runtime/context.ts
|
|
19
26
|
const unconfiguredRuntimeContextStorage = {
|
|
@@ -39,12 +46,14 @@ const setRuntimeContextLineage = (context) => {
|
|
|
39
46
|
const hasPathPrefix = (parent, child) => child.length >= parent.length && parent.every((token, index) => child[index] === token);
|
|
40
47
|
/** Recognize contexts created by a nested Service, Scope, or Layer operation. */
|
|
41
48
|
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, executionId) {
|
|
49
|
+
function makeRuntimeContext(resolver, scope, resolutionPath, signal, parent, executionId, executor) {
|
|
43
50
|
const context = { resolutionPath };
|
|
44
51
|
const ownerExecutionId = executionId ?? parent?.executionId;
|
|
52
|
+
const runtimeExecutor = executor ?? parent?.executor;
|
|
45
53
|
if (resolver !== void 0) Object.assign(context, { resolver });
|
|
46
54
|
if (scope !== void 0) Object.assign(context, { scope });
|
|
47
55
|
if (signal !== void 0) Object.assign(context, { signal });
|
|
56
|
+
if (runtimeExecutor !== void 0) Object.assign(context, { executor: runtimeExecutor });
|
|
48
57
|
if (ownerExecutionId !== void 0) Object.assign(context, { executionId: ownerExecutionId });
|
|
49
58
|
if (parent !== void 0) inheritRuntimeContextLineage(context, parent);
|
|
50
59
|
return context;
|
|
@@ -149,6 +158,6 @@ const runRuntimeContext = (storage, context, program) => {
|
|
|
149
158
|
return storage.run(contextual, () => withActiveRuntimeContextStorage(storage, contextual, program));
|
|
150
159
|
};
|
|
151
160
|
//#endregion
|
|
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 };
|
|
161
|
+
export { RuntimeExecutorNotConfiguredError as _, 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 };
|
|
153
162
|
|
|
154
|
-
//# sourceMappingURL=context-
|
|
163
|
+
//# sourceMappingURL=context-DSGSqcJj.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-DSGSqcJj.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\n/** Thrown when a Runtime executor is requested without an active Runtime. */\nexport class RuntimeExecutorNotConfiguredError extends Error {\n constructor() {\n super('No Runtime executor is available in the current execution context')\n\n this.name = 'RuntimeExecutorNotConfiguredError'\n }\n}\n","import { RuntimeContextNotConfiguredError } from './errors'\n\nimport type { Scope } from '../scope/scope'\nimport type { AnyService, AnyServiceToken, ServiceResolver } from '../service'\nimport { isPromiseLike } from '../utils/runtime'\n\nimport type { RuntimeExecutor } from './executor'\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 /** Non-owning executor view for the Runtime root of this context. */\n readonly executor?: RuntimeExecutor<AnyService>\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 executor?: RuntimeExecutor<AnyService>\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 executor?: RuntimeExecutor<AnyService>\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 executor?: RuntimeExecutor<AnyService>\n): RuntimeContext {\n const context: RuntimeContext = { resolutionPath }\n const ownerExecutionId = executionId ?? parent?.executionId\n const runtimeExecutor = executor ?? parent?.executor\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 (runtimeExecutor !== undefined) {\n Object.assign(context, { executor: runtimeExecutor })\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"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;;AAG7D,MAAa,iCAAiC,YAA8C;CAC1F,6BAA6B;AAC/B;;AAGA,MAAa,8CACX,+BAA+B;;AAGjC,MAAa,mCACX,2BAA2B,QAAQ;;AAGrC,MAAa,mCAAmC,YAAyC;CACvF,iBAAiB;AACnB;;AAGA,MAAa,oCACX,2BAA2B,CAAC,EAAE,WAAW;;AAG3C,MAAa,qBACX,UAAiC,4BAA4B,MAC9B;CAC/B,MAAM,QAAQ,2BAA2B;CAEzC,IAAI,OAAO,YAAY,SACrB,OAAO,MAAM;CAGf,IAAI;EACF,OAAO,QAAQ,QAAQ;CACzB,SAAS,OAAO;EACd,IAAI,iBAAiB,kCACnB;EAGF,MAAM;CACR;AACF;;AAGA,MAAa,8BAA8C;CAGzD,OAFc,2BAEH,CAAC,EAAE,WAAW,eAAe,QAAQ;AAClD;;AAGA,MAAa,mCACX,SACA,SACA,YACM;CACN,MAAM,UAAU,2BAA2B;CAE3C,IAAI,SAAS,YAAY,WAAW,QAAQ,YAAY,SACtD,OAAO,QAAQ;CAGjB,MAAM,QACJ,YAAY,KAAA,IAAY;EAAE;EAAS;CAAQ,IAAI;EAAE;EAAS;EAAS,QAAQ;CAAQ;CAErF,OAAO,2BAA2B,IAAI,OAAO,OAAO;AACtD;;AAGA,MAAa,qBACX,SACA,SACA,YACM;CACN,MAAM,UAAU,kBAAkB,OAAO;CACzC,MAAM,aACJ,YAAY,KAAA,KAAa,wBAAwB,SAAS,OAAO,IAC7D,6BAA6B,SAAS,OAAO,IAC7C;CAEN,OAAO,QAAQ,IAAI,kBACjB,gCAAgC,SAAS,YAAY,OAAO,CAC9D;AACF"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as Layer } from "./layer-2kjHVv4N.mjs";
|
|
2
|
+
import { t as Service } from "./service-CO9VJQYa.mjs";
|
|
2
3
|
//#region src/standard-services/current-request.ts
|
|
3
4
|
/** Execution-local request value carried by a normal Service provider. */
|
|
4
5
|
var CurrentRequest = class CurrentRequest extends Service()("CurrentRequest") {
|
|
@@ -17,4 +18,4 @@ const CurrentRequestLayer = (value) => CurrentRequest.layer(value);
|
|
|
17
18
|
//#endregion
|
|
18
19
|
export { CurrentRequestLayer as n, CurrentRequest as t };
|
|
19
20
|
|
|
20
|
-
//# sourceMappingURL=current-request-
|
|
21
|
+
//# sourceMappingURL=current-request-Bc1YHL0w.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"current-request-
|
|
1
|
+
{"version":3,"file":"current-request-Bc1YHL0w.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"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import "./index-BodMy6rO.mjs";
|
|
1
|
+
import { It as ServiceRequirement, Kt as ServiceToken, Tt as Service, Vt as ServiceIdentity, ft as ProviderEntry, rt as LayerResult } from "./layer-C2OaqTmB.mjs";
|
|
2
|
+
import "./index-ClNndn2-.mjs";
|
|
4
3
|
//#region src/standard-services/current-request.d.ts
|
|
5
4
|
declare const CurrentRequest_base: (abstract new () => ServiceIdentity<"CurrentRequest">) & {
|
|
6
5
|
readonly name: string;
|
|
7
6
|
readonly serviceTag: "CurrentRequest";
|
|
8
7
|
} & {
|
|
9
8
|
readonly of: Service.FactoryOf<CurrentRequest, "CurrentRequest">;
|
|
9
|
+
readonly [Symbol.iterator]: (this: ServiceToken<"CurrentRequest", CurrentRequest & ServiceIdentity<"CurrentRequest">>) => Generator<ServiceRequirement<CurrentRequest>, CurrentRequest, unknown>;
|
|
10
10
|
readonly [Symbol.asyncIterator]: (this: ServiceToken<"CurrentRequest", CurrentRequest & ServiceIdentity<"CurrentRequest">>) => AsyncGenerator<ServiceRequirement<CurrentRequest>, CurrentRequest, unknown>;
|
|
11
11
|
};
|
|
12
12
|
/** Execution-local request value carried by a normal Service provider. */
|
|
@@ -19,4 +19,4 @@ declare class CurrentRequest extends CurrentRequest_base {
|
|
|
19
19
|
declare const CurrentRequestLayer: (value: unknown) => LayerResult<ProviderEntry<CurrentRequest, never>>;
|
|
20
20
|
//#endregion
|
|
21
21
|
export { CurrentRequestLayer as n, CurrentRequest as t };
|
|
22
|
-
//# sourceMappingURL=current-request-
|
|
22
|
+
//# sourceMappingURL=current-request-Dm-QQ3Xr.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"current-request-Dm-QQ3Xr.d.mts","names":[],"sources":["../src/standard-services/current-request.ts"],"mappings":";;;;;;;;;;;;cAIa,uBAAuB;WAIb;WAHZ;EAGT,YAAqB;SAMd,MAAM,iBAAc,YAAA,cAAA;;cAMhB,sBAAmB,mBAAkB,YAAA,cAAA"}
|
|
@@ -1,6 +1,23 @@
|
|
|
1
|
+
import { h as RuntimeContextNotConfiguredError, n as currentRuntimeContext } from "./context-DSGSqcJj.mjs";
|
|
1
2
|
import { t as isPromiseLike } from "./runtime-CDcCF5cb.mjs";
|
|
2
|
-
import {
|
|
3
|
+
import { l as Scope, o as inheritProgramName, r as getRuntimeTaskSupervisor, s as setProgramName } from "./runtime-qpcVwaz_.mjs";
|
|
3
4
|
import { Err, Result, matchError, matchErrorPartial } from "better-result";
|
|
5
|
+
//#region src/effect/task.ts
|
|
6
|
+
/** Start a nominal Program as a child task supervised by the current Scope. */
|
|
7
|
+
function forkScoped(program) {
|
|
8
|
+
const context = currentRuntimeContext();
|
|
9
|
+
const resolver = context.resolver;
|
|
10
|
+
const scope = context.scope;
|
|
11
|
+
if (!resolver || !scope) throw new RuntimeContextNotConfiguredError();
|
|
12
|
+
const supervisor = getRuntimeTaskSupervisor(scope);
|
|
13
|
+
if (!supervisor) throw new RuntimeContextNotConfiguredError();
|
|
14
|
+
return Result.ok(supervisor.forkScoped(program, {
|
|
15
|
+
...context,
|
|
16
|
+
resolver,
|
|
17
|
+
scope
|
|
18
|
+
}));
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
4
21
|
//#region src/effect/combinators.ts
|
|
5
22
|
const asResult = (value) => {
|
|
6
23
|
return value;
|
|
@@ -512,6 +529,8 @@ const Effect = {
|
|
|
512
529
|
acquireDisposable,
|
|
513
530
|
/** Register an already-acquired disposable in the current Scope. */
|
|
514
531
|
add,
|
|
532
|
+
/** Start a child Program owned by the current Scope. */
|
|
533
|
+
forkScoped,
|
|
515
534
|
/** Map a successful Effect result. */
|
|
516
535
|
map: map$1,
|
|
517
536
|
/** Map an Effect error. */
|
|
@@ -556,4 +575,4 @@ const Effect = {
|
|
|
556
575
|
//#endregion
|
|
557
576
|
export { Program as n, Effect as t };
|
|
558
577
|
|
|
559
|
-
//# sourceMappingURL=effect-
|
|
578
|
+
//# sourceMappingURL=effect-W0IQXY8P.mjs.map
|