better-effect 0.9.3 → 0.10.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/LICENSE +21 -0
- package/README.md +52 -16
- package/dist/adapters/iti.d.mts +10 -4
- package/dist/adapters/iti.d.mts.map +1 -1
- package/dist/adapters/iti.mjs +24 -4
- package/dist/adapters/iti.mjs.map +1 -1
- package/dist/context-BUEf1qjL.mjs +152 -0
- package/dist/context-BUEf1qjL.mjs.map +1 -0
- package/dist/{effect-CZdZCZLW.mjs → effect-DAMqvegy.mjs} +35 -13
- package/dist/effect-DAMqvegy.mjs.map +1 -0
- package/dist/errors-BKcsQ0ip.d.mts +12 -0
- package/dist/errors-BKcsQ0ip.d.mts.map +1 -0
- package/dist/hono.d.mts +52 -18
- package/dist/hono.d.mts.map +1 -1
- package/dist/hono.mjs +36 -41
- package/dist/hono.mjs.map +1 -1
- package/dist/{index-BsPr7qHf.d.mts → index-BafDna0B.d.mts} +4 -4
- package/dist/{index-BsPr7qHf.d.mts.map → index-BafDna0B.d.mts.map} +1 -1
- package/dist/{index-EJlskfAW.d.mts → index-C7KX5rAP.d.mts} +8 -4
- package/dist/index-C7KX5rAP.d.mts.map +1 -0
- package/dist/{index-1NLNdkJy.d.mts → index-CULgSzUw.d.mts} +4 -4
- package/dist/{index-1NLNdkJy.d.mts.map → index-CULgSzUw.d.mts.map} +1 -1
- package/dist/{index-CITM15SE.d.mts → index-DklNCz7w.d.mts} +4 -4
- package/dist/{index-CITM15SE.d.mts.map → index-DklNCz7w.d.mts.map} +1 -1
- package/dist/index.d.mts +5 -5
- package/dist/index.mjs +31 -34
- package/dist/index.mjs.map +1 -1
- package/dist/{map-layer-backend-DMJauecV.d.mts → map-layer-backend-rNwfH0Bz.d.mts} +2 -2
- package/dist/{map-layer-backend-DMJauecV.d.mts.map → map-layer-backend-rNwfH0Bz.d.mts.map} +1 -1
- package/dist/runtime/explicit.d.mts +11 -7
- package/dist/runtime/explicit.d.mts.map +1 -1
- package/dist/runtime/explicit.mjs +96 -23
- package/dist/runtime/explicit.mjs.map +1 -1
- package/dist/runtime/node.d.mts +2 -2
- package/dist/runtime/node.d.mts.map +1 -1
- package/dist/runtime/node.mjs +10 -6
- package/dist/runtime/node.mjs.map +1 -1
- package/dist/{signal-Cl9tqGyX.mjs → signal-C1bagvrO.mjs} +6 -5
- package/dist/signal-C1bagvrO.mjs.map +1 -0
- package/dist/{standard-services-QseopL9g.mjs → standard-services-DW-i4UuA.mjs} +2 -2
- package/dist/{standard-services-QseopL9g.mjs.map → standard-services-DW-i4UuA.mjs.map} +1 -1
- package/dist/standard-services.d.mts +2 -2
- package/dist/standard-services.mjs +2 -2
- package/dist/testing.d.mts +1 -1
- package/package.json +6 -3
- package/dist/context-B4yO5LaH.mjs +0 -80
- package/dist/context-B4yO5LaH.mjs.map +0 -1
- package/dist/effect-CZdZCZLW.mjs.map +0 -1
- package/dist/errors-BXKc7juX.d.mts +0 -8
- package/dist/errors-BXKc7juX.d.mts.map +0 -1
- package/dist/index-EJlskfAW.d.mts.map +0 -1
- package/dist/signal-Cl9tqGyX.mjs.map +0 -1
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
import { c as RuntimeContextStorage, s as RuntimeContext } from "../index-
|
|
2
|
-
import { t as RuntimeContextNotConfiguredError } from "../errors-
|
|
1
|
+
import { c as RuntimeContextStorage, s as RuntimeContext } from "../index-CULgSzUw.mjs";
|
|
2
|
+
import { n as RuntimeContextOverlapError, t as RuntimeContextNotConfiguredError } from "../errors-BKcsQ0ip.mjs";
|
|
3
3
|
//#region src/runtime/explicit.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* RuntimeContextStorage for hosts without transparent async context support.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* concurrent async branches need isolation.
|
|
7
|
+
* Nested derived contexts are supported, but unrelated root or lineage runs
|
|
8
|
+
* cannot overlap safely on one mutable storage instance. Use
|
|
9
|
+
* NodeRuntimeContextStorage when concurrent async branches need isolation.
|
|
10
10
|
*/
|
|
11
11
|
declare class ExplicitRuntimeContextStorage implements RuntimeContextStorage {
|
|
12
|
-
private
|
|
12
|
+
private readonly states;
|
|
13
|
+
private rootState;
|
|
13
14
|
run<A>(context: RuntimeContext, program: () => A): A;
|
|
15
|
+
private enter;
|
|
16
|
+
private exit;
|
|
17
|
+
private settle;
|
|
14
18
|
current(): RuntimeContext;
|
|
15
19
|
}
|
|
16
20
|
//#endregion
|
|
17
|
-
export { ExplicitRuntimeContextStorage, type RuntimeContext, RuntimeContextNotConfiguredError, type RuntimeContextStorage };
|
|
21
|
+
export { ExplicitRuntimeContextStorage, type RuntimeContext, RuntimeContextNotConfiguredError, RuntimeContextOverlapError, type RuntimeContextStorage };
|
|
18
22
|
//# sourceMappingURL=explicit.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"explicit.d.mts","names":[],"sources":["../../src/runtime/explicit.ts"],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"explicit.d.mts","names":[],"sources":["../../src/runtime/explicit.ts"],"mappings":";;;;;;;;;;cAmCa,yCAAyC;mBACnC;UAET;EAER,IAAI,GAAG,SAAS,gBAAgB,eAAe,IAAI;UAqC3C;UAgEA;UAuBA;EAiCR,WAAW"}
|
|
@@ -1,46 +1,119 @@
|
|
|
1
|
-
import { c as RuntimeContextNotConfiguredError,
|
|
1
|
+
import { a as getRuntimeContextLineage, c as isRuntimeContextFrameCarrierInstalled, g as RuntimeContextOverlapError, h as RuntimeContextNotConfiguredError, m as withActiveRuntimeContextStorage, o as inheritRuntimeContextLineage, p as setRuntimeContextLineage, r as currentRuntimeContextFrame, s as isDerivedRuntimeContext } from "../context-BUEf1qjL.mjs";
|
|
2
|
+
import { t as isPromiseLike } from "../runtime-CDcCF5cb.mjs";
|
|
2
3
|
//#region src/runtime/explicit.ts
|
|
3
|
-
|
|
4
|
+
let fallbackRootLease = false;
|
|
4
5
|
/**
|
|
5
6
|
* RuntimeContextStorage for hosts without transparent async context support.
|
|
6
7
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* concurrent async branches need isolation.
|
|
8
|
+
* Nested derived contexts are supported, but unrelated root or lineage runs
|
|
9
|
+
* cannot overlap safely on one mutable storage instance. Use
|
|
10
|
+
* NodeRuntimeContextStorage when concurrent async branches need isolation.
|
|
10
11
|
*/
|
|
11
12
|
var ExplicitRuntimeContextStorage = class {
|
|
12
|
-
|
|
13
|
+
states = /* @__PURE__ */ new WeakMap();
|
|
14
|
+
rootState;
|
|
13
15
|
run(context, program) {
|
|
14
|
-
return withActiveRuntimeContextStorage(this, () => {
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
return withActiveRuntimeContextStorage(this, context, () => {
|
|
17
|
+
const frame = currentRuntimeContextFrame();
|
|
18
|
+
if (!frame || frame.storage !== this) throw new RuntimeContextOverlapError();
|
|
19
|
+
const existing = this.states.get(frame);
|
|
20
|
+
if (existing?.context === context) {
|
|
21
|
+
if (existing.activeChild !== void 0 || !isRuntimeContextFrameCarrierInstalled() && !existing.invoking) throw new RuntimeContextOverlapError();
|
|
22
|
+
return program();
|
|
23
|
+
}
|
|
24
|
+
const state = this.enter(frame, context);
|
|
25
|
+
state.invoking = true;
|
|
26
|
+
const restore = () => this.exit(state);
|
|
18
27
|
try {
|
|
19
|
-
value = program();
|
|
28
|
+
const value = program();
|
|
29
|
+
state.invoking = false;
|
|
30
|
+
return this.settle(value, restore);
|
|
20
31
|
} catch (cause) {
|
|
21
|
-
|
|
32
|
+
state.invoking = false;
|
|
33
|
+
restore();
|
|
22
34
|
throw cause;
|
|
23
35
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
enter(frame, context) {
|
|
39
|
+
const parentFrame = frame.parent;
|
|
40
|
+
const parent = parentFrame ? this.states.get(parentFrame) : void 0;
|
|
41
|
+
if (parent === void 0) {
|
|
42
|
+
if (this.rootState !== void 0 || !isRuntimeContextFrameCarrierInstalled() && fallbackRootLease) throw new RuntimeContextOverlapError();
|
|
43
|
+
setRuntimeContextLineage(context);
|
|
44
|
+
const state = {
|
|
45
|
+
frame,
|
|
46
|
+
context,
|
|
47
|
+
parent: void 0,
|
|
48
|
+
activeChild: void 0,
|
|
49
|
+
invoking: false
|
|
50
|
+
};
|
|
51
|
+
this.states.set(frame, state);
|
|
52
|
+
this.rootState = state;
|
|
53
|
+
if (!isRuntimeContextFrameCarrierInstalled()) fallbackRootLease = true;
|
|
54
|
+
return state;
|
|
55
|
+
}
|
|
56
|
+
if (parent.activeChild !== void 0) throw new RuntimeContextOverlapError();
|
|
57
|
+
const contextLineage = getRuntimeContextLineage(context);
|
|
58
|
+
const parentLineage = getRuntimeContextLineage(parent.context) ?? parent.context;
|
|
59
|
+
if (!(context !== parent.context && (contextLineage !== void 0 && contextLineage === parentLineage || contextLineage === void 0 && isDerivedRuntimeContext(parent.context, context))) || !isRuntimeContextFrameCarrierInstalled() && parent.parent !== void 0 && !parent.invoking) throw new RuntimeContextOverlapError();
|
|
60
|
+
inheritRuntimeContextLineage(context, parent.context);
|
|
61
|
+
const state = {
|
|
62
|
+
frame,
|
|
63
|
+
context,
|
|
64
|
+
parent,
|
|
65
|
+
activeChild: void 0,
|
|
66
|
+
invoking: false
|
|
67
|
+
};
|
|
68
|
+
this.states.set(frame, state);
|
|
69
|
+
parent.activeChild = state;
|
|
70
|
+
return state;
|
|
71
|
+
}
|
|
72
|
+
exit(state) {
|
|
73
|
+
if (this.states.get(state.frame) !== state) return;
|
|
74
|
+
this.states.delete(state.frame);
|
|
75
|
+
if (state.parent !== void 0) {
|
|
76
|
+
if (state.parent.activeChild === state) state.parent.activeChild = void 0;
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (this.rootState === state) {
|
|
80
|
+
this.rootState = void 0;
|
|
81
|
+
if (fallbackRootLease) fallbackRootLease = false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
settle(value, restore) {
|
|
85
|
+
let promiseLike;
|
|
86
|
+
try {
|
|
87
|
+
promiseLike = isPromiseLike(value);
|
|
88
|
+
} catch (cause) {
|
|
89
|
+
restore();
|
|
90
|
+
throw cause;
|
|
91
|
+
}
|
|
92
|
+
if (!promiseLike) {
|
|
93
|
+
restore();
|
|
94
|
+
return value;
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
28
97
|
return Promise.resolve(value).then((resolved) => {
|
|
29
|
-
|
|
98
|
+
restore();
|
|
30
99
|
return resolved;
|
|
31
100
|
}, (cause) => {
|
|
32
|
-
|
|
101
|
+
restore();
|
|
33
102
|
throw cause;
|
|
34
103
|
});
|
|
35
|
-
})
|
|
104
|
+
} catch (cause) {
|
|
105
|
+
restore();
|
|
106
|
+
throw cause;
|
|
107
|
+
}
|
|
36
108
|
}
|
|
37
109
|
current() {
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
110
|
+
const frame = currentRuntimeContextFrame();
|
|
111
|
+
const state = frame && frame.storage === this ? this.states.get(frame) : void 0;
|
|
112
|
+
if (!state) throw new RuntimeContextNotConfiguredError();
|
|
113
|
+
return state.context;
|
|
41
114
|
}
|
|
42
115
|
};
|
|
43
116
|
//#endregion
|
|
44
|
-
export { ExplicitRuntimeContextStorage, RuntimeContextNotConfiguredError };
|
|
117
|
+
export { ExplicitRuntimeContextStorage, RuntimeContextNotConfiguredError, RuntimeContextOverlapError };
|
|
45
118
|
|
|
46
119
|
//# sourceMappingURL=explicit.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"explicit.mjs","names":[],"sources":["../../src/runtime/explicit.ts"],"sourcesContent":["import { RuntimeContextNotConfiguredError } from './errors'\n\nimport {
|
|
1
|
+
{"version":3,"file":"explicit.mjs","names":[],"sources":["../../src/runtime/explicit.ts"],"sourcesContent":["import { RuntimeContextNotConfiguredError, RuntimeContextOverlapError } from './errors'\n\nimport {\n currentRuntimeContextFrame,\n getRuntimeContextLineage,\n inheritRuntimeContextLineage,\n isDerivedRuntimeContext,\n isRuntimeContextFrameCarrierInstalled,\n setRuntimeContextLineage,\n withActiveRuntimeContextStorage\n} from './context'\n\nimport { isPromiseLike } from '../utils/runtime'\n\nimport type { ActiveRuntimeContextFrame, RuntimeContext, RuntimeContextStorage } from './context'\n\ntype ExplicitRunState = {\n readonly frame: ActiveRuntimeContextFrame\n readonly context: RuntimeContext\n readonly parent: ExplicitRunState | undefined\n activeChild: ExplicitRunState | undefined\n invoking: boolean\n}\n\n// Without async-local propagation, separate explicit storages share one mutable\n// frame and must not hold root leases concurrently.\nlet fallbackRootLease = false\n\n/**\n * RuntimeContextStorage for hosts without transparent async context support.\n *\n * Nested derived contexts are supported, but unrelated root or lineage runs\n * cannot overlap safely on one mutable storage instance. Use\n * NodeRuntimeContextStorage when concurrent async branches need isolation.\n */\nexport class ExplicitRuntimeContextStorage implements RuntimeContextStorage {\n private readonly states = new WeakMap<ActiveRuntimeContextFrame, ExplicitRunState>()\n\n private rootState: ExplicitRunState | undefined\n\n run<A>(context: RuntimeContext, program: () => A): A {\n return withActiveRuntimeContextStorage(this, context, () => {\n const frame = currentRuntimeContextFrame()\n\n if (!frame || frame.storage !== this) {\n throw new RuntimeContextOverlapError()\n }\n\n const existing = this.states.get(frame)\n\n if (existing?.context === context) {\n if (\n existing.activeChild !== undefined ||\n (!isRuntimeContextFrameCarrierInstalled() && !existing.invoking)\n ) {\n throw new RuntimeContextOverlapError()\n }\n\n return program()\n }\n\n const state = this.enter(frame, context)\n state.invoking = true\n const restore = (): void => this.exit(state)\n\n try {\n const value = program()\n state.invoking = false\n return this.settle(value, restore)\n } catch (cause) {\n state.invoking = false\n restore()\n throw cause\n }\n })\n }\n\n private enter(frame: ActiveRuntimeContextFrame, context: RuntimeContext): ExplicitRunState {\n const parentFrame = frame.parent\n const parent = parentFrame ? this.states.get(parentFrame) : undefined\n\n if (parent === undefined) {\n if (\n this.rootState !== undefined ||\n (!isRuntimeContextFrameCarrierInstalled() && fallbackRootLease)\n ) {\n throw new RuntimeContextOverlapError()\n }\n\n setRuntimeContextLineage(context)\n\n const state: ExplicitRunState = {\n frame,\n context,\n parent: undefined,\n activeChild: undefined,\n invoking: false\n }\n this.states.set(frame, state)\n this.rootState = state\n\n if (!isRuntimeContextFrameCarrierInstalled()) {\n fallbackRootLease = true\n }\n\n return state\n }\n\n if (parent.activeChild !== undefined) {\n throw new RuntimeContextOverlapError()\n }\n\n const contextLineage = getRuntimeContextLineage(context)\n const parentLineage = getRuntimeContextLineage(parent.context) ?? parent.context\n const nested =\n context !== parent.context &&\n ((contextLineage !== undefined && contextLineage === parentLineage) ||\n (contextLineage === undefined && isDerivedRuntimeContext(parent.context, context)))\n\n if (\n !nested ||\n (!isRuntimeContextFrameCarrierInstalled() && parent.parent !== undefined && !parent.invoking)\n ) {\n throw new RuntimeContextOverlapError()\n }\n\n inheritRuntimeContextLineage(context, parent.context)\n\n const state: ExplicitRunState = {\n frame,\n context,\n parent,\n activeChild: undefined,\n invoking: false\n }\n this.states.set(frame, state)\n parent.activeChild = state\n\n return state\n }\n\n private exit(state: ExplicitRunState): void {\n if (this.states.get(state.frame) !== state) {\n return\n }\n\n this.states.delete(state.frame)\n\n if (state.parent !== undefined) {\n if (state.parent.activeChild === state) {\n state.parent.activeChild = undefined\n }\n return\n }\n\n if (this.rootState === state) {\n this.rootState = undefined\n\n if (fallbackRootLease) {\n fallbackRootLease = false\n }\n }\n }\n\n private settle<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\n current(): RuntimeContext {\n const frame = currentRuntimeContextFrame()\n const state = frame && frame.storage === this ? this.states.get(frame) : undefined\n\n if (!state) {\n throw new RuntimeContextNotConfiguredError()\n }\n\n return state.context\n }\n}\n\nexport { RuntimeContextNotConfiguredError, RuntimeContextOverlapError } from './errors'\n\nexport type { RuntimeContext, RuntimeContextStorage } from './context'\n"],"mappings":";;;AA0BA,IAAI,oBAAoB;;;;;;;;AASxB,IAAa,gCAAb,MAA4E;CAC1E,yBAA0B,IAAI,QAAqD;CAEnF;CAEA,IAAO,SAAyB,SAAqB;EACnD,OAAO,gCAAgC,MAAM,eAAe;GAC1D,MAAM,QAAQ,2BAA2B;GAEzC,IAAI,CAAC,SAAS,MAAM,YAAY,MAC9B,MAAM,IAAI,2BAA2B;GAGvC,MAAM,WAAW,KAAK,OAAO,IAAI,KAAK;GAEtC,IAAI,UAAU,YAAY,SAAS;IACjC,IACE,SAAS,gBAAgB,KAAA,KACxB,CAAC,sCAAsC,KAAK,CAAC,SAAS,UAEvD,MAAM,IAAI,2BAA2B;IAGvC,OAAO,QAAQ;GACjB;GAEA,MAAM,QAAQ,KAAK,MAAM,OAAO,OAAO;GACvC,MAAM,WAAW;GACjB,MAAM,gBAAsB,KAAK,KAAK,KAAK;GAE3C,IAAI;IACF,MAAM,QAAQ,QAAQ;IACtB,MAAM,WAAW;IACjB,OAAO,KAAK,OAAO,OAAO,OAAO;GACnC,SAAS,OAAO;IACd,MAAM,WAAW;IACjB,QAAQ;IACR,MAAM;GACR;EACF,CAAC;CACH;CAEA,MAAc,OAAkC,SAA2C;EACzF,MAAM,cAAc,MAAM;EAC1B,MAAM,SAAS,cAAc,KAAK,OAAO,IAAI,WAAW,IAAI,KAAA;EAE5D,IAAI,WAAW,KAAA,GAAW;GACxB,IACE,KAAK,cAAc,KAAA,KAClB,CAAC,sCAAsC,KAAK,mBAE7C,MAAM,IAAI,2BAA2B;GAGvC,yBAAyB,OAAO;GAEhC,MAAM,QAA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AAQ,QAAQ,KAAK,CAAC,CAAC,MAC3B,aAAa;IACZ,QAAQ;IACR,OAAO;GACT,IACC,UAAU;IACT,QAAQ;IACR,MAAM;GACR,CACF;EACF,SAAS,OAAO;GACd,QAAQ;GACR,MAAM;EACR;CACF;CAEA,UAA0B;EACxB,MAAM,QAAQ,2BAA2B;EACzC,MAAM,QAAQ,SAAS,MAAM,YAAY,OAAO,KAAK,OAAO,IAAI,KAAK,IAAI,KAAA;EAEzE,IAAI,CAAC,OACH,MAAM,IAAI,iCAAiC;EAG7C,OAAO,MAAM;CACf;AACF"}
|
package/dist/runtime/node.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as RuntimeContextStorage, s as RuntimeContext } from "../index-
|
|
2
|
-
import { t as RuntimeContextNotConfiguredError } from "../errors-
|
|
1
|
+
import { c as RuntimeContextStorage, s as RuntimeContext } from "../index-CULgSzUw.mjs";
|
|
2
|
+
import { t as RuntimeContextNotConfiguredError } from "../errors-BKcsQ0ip.mjs";
|
|
3
3
|
//#region src/runtime/node.d.ts
|
|
4
4
|
/** RuntimeContextStorage backed by Node/Bun async context propagation. */
|
|
5
5
|
declare class NodeRuntimeContextStorage implements RuntimeContextStorage {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.mts","names":[],"sources":["../../src/runtime/node.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"node.d.mts","names":[],"sources":["../../src/runtime/node.ts"],"mappings":";;;;cA2Ba,qCAAqC;EAChD,IAAI,GAAG,SAAS,gBAAgB,eAAe,IAAI;EAInD,WAAW;;;cAYA,2BAAyB"}
|
package/dist/runtime/node.mjs
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { f as setRuntimeContextFrameCarrier, h as RuntimeContextNotConfiguredError, m as withActiveRuntimeContextStorage, r as currentRuntimeContextFrame } from "../context-BUEf1qjL.mjs";
|
|
2
2
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
3
3
|
//#region src/runtime/node.ts
|
|
4
|
-
const
|
|
4
|
+
const asyncLocalStorage = new AsyncLocalStorage();
|
|
5
|
+
setRuntimeContextFrameCarrier({
|
|
6
|
+
run: (frame, program) => asyncLocalStorage.run(frame, program),
|
|
7
|
+
current: () => asyncLocalStorage.getStore()
|
|
8
|
+
});
|
|
5
9
|
/** RuntimeContextStorage backed by Node/Bun async context propagation. */
|
|
6
10
|
var NodeRuntimeContextStorage = class {
|
|
7
11
|
run(context, program) {
|
|
8
|
-
return withActiveRuntimeContextStorage(this,
|
|
12
|
+
return withActiveRuntimeContextStorage(this, context, program);
|
|
9
13
|
}
|
|
10
14
|
current() {
|
|
11
|
-
const
|
|
12
|
-
if (!
|
|
13
|
-
return context;
|
|
15
|
+
const frame = currentRuntimeContextFrame();
|
|
16
|
+
if (!frame || frame.storage !== this) throw new RuntimeContextNotConfiguredError();
|
|
17
|
+
return frame.context;
|
|
14
18
|
}
|
|
15
19
|
};
|
|
16
20
|
/** Shared Node/Bun storage used by the compatibility APIs and default Runtime. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.mjs","names":[],"sources":["../../src/runtime/node.ts"],"sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks'\n\nimport { RuntimeContextNotConfiguredError } from './errors'\n\nimport {
|
|
1
|
+
{"version":3,"file":"node.mjs","names":[],"sources":["../../src/runtime/node.ts"],"sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks'\n\nimport { RuntimeContextNotConfiguredError } from './errors'\n\nimport {\n currentRuntimeContextFrame,\n setRuntimeContextFrameCarrier,\n withActiveRuntimeContextStorage\n} from './context'\n\nimport type {\n ActiveRuntimeContextFrame,\n RuntimeContext,\n RuntimeContextFrameCarrier,\n RuntimeContextStorage\n} from './context'\n\nconst asyncLocalStorage = new AsyncLocalStorage<ActiveRuntimeContextFrame>()\n\nconst frameCarrier: RuntimeContextFrameCarrier = {\n run: (frame, program) => asyncLocalStorage.run(frame, program),\n current: () => asyncLocalStorage.getStore()\n}\n\nsetRuntimeContextFrameCarrier(frameCarrier)\n\n/** RuntimeContextStorage backed by Node/Bun async context propagation. */\nexport class NodeRuntimeContextStorage implements RuntimeContextStorage {\n run<A>(context: RuntimeContext, program: () => A): A {\n return withActiveRuntimeContextStorage(this, context, program)\n }\n\n current(): RuntimeContext {\n const frame = currentRuntimeContextFrame()\n\n if (!frame || frame.storage !== this) {\n throw new RuntimeContextNotConfiguredError()\n }\n\n return frame.context\n }\n}\n\n/** Shared Node/Bun storage used by the compatibility APIs and default Runtime. */\nexport const nodeRuntimeContextStorage = new NodeRuntimeContextStorage()\n\nexport { RuntimeContextNotConfiguredError } from './errors'\n\nexport type { RuntimeContext, RuntimeContextStorage } from './context'\n"],"mappings":";;;AAiBA,MAAM,oBAAoB,IAAI,kBAA6C;AAO3E,8BAA8B;CAJ5B,MAAM,OAAO,YAAY,kBAAkB,IAAI,OAAO,OAAO;CAC7D,eAAe,kBAAkB,SAAS;AAGH,CAAC;;AAG1C,IAAa,4BAAb,MAAwE;CACtE,IAAO,SAAyB,SAAqB;EACnD,OAAO,gCAAgC,MAAM,SAAS,OAAO;CAC/D;CAEA,UAA0B;EACxB,MAAM,QAAQ,2BAA2B;EAEzC,IAAI,CAAC,SAAS,MAAM,YAAY,MAC9B,MAAM,IAAI,iCAAiC;EAG7C,OAAO,MAAM;CACf;AACF;;AAGA,MAAa,4BAA4B,IAAI,0BAA0B"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as ServiceTagCollisionError, l as ServiceRuntimeNotConfiguredError, r as LayerGeneratorYieldError, t as DuplicateServiceError } from "./errors-Dnjhzbt0.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { d as setDefaultRuntimeContextStorage, h as RuntimeContextNotConfiguredError, i as getRuntimeContext, l as makeRuntimeContext, n as currentRuntimeContext, u as runRuntimeContext } from "./context-BUEf1qjL.mjs";
|
|
3
3
|
import { nodeRuntimeContextStorage } from "./runtime/node.mjs";
|
|
4
4
|
//#region src/runtime/default.ts
|
|
5
5
|
/** The Node/Bun storage used by the main Runtime entrypoint. */
|
|
@@ -23,7 +23,7 @@ var ServiceRuntime = class ServiceRuntime {
|
|
|
23
23
|
*/
|
|
24
24
|
static run(resolver, program, storage = defaultRuntimeContextStorage) {
|
|
25
25
|
const current = getRuntimeContext(storage);
|
|
26
|
-
const context = makeRuntimeContext(resolver, current?.scope, current?.resolver === resolver ? current.resolutionPath : [], current?.signal);
|
|
26
|
+
const context = makeRuntimeContext(resolver, current?.scope, current?.resolver === resolver ? current.resolutionPath : [], current?.signal, current?.resolver === resolver ? current : void 0);
|
|
27
27
|
return runRuntimeContext(storage, context, program);
|
|
28
28
|
}
|
|
29
29
|
/** Return the resolver active in the current execution context. */
|
|
@@ -31,8 +31,9 @@ var ServiceRuntime = class ServiceRuntime {
|
|
|
31
31
|
let context;
|
|
32
32
|
try {
|
|
33
33
|
context = currentRuntimeContext();
|
|
34
|
-
} catch {
|
|
35
|
-
throw new ServiceRuntimeNotConfiguredError();
|
|
34
|
+
} catch (cause) {
|
|
35
|
+
if (cause instanceof RuntimeContextNotConfiguredError) throw new ServiceRuntimeNotConfiguredError();
|
|
36
|
+
throw cause;
|
|
36
37
|
}
|
|
37
38
|
if (!context.resolver) throw new ServiceRuntimeNotConfiguredError();
|
|
38
39
|
return context.resolver;
|
|
@@ -267,4 +268,4 @@ const CurrentAbortSignal = { *[Symbol.iterator]() {
|
|
|
267
268
|
//#endregion
|
|
268
269
|
export { ServiceRuntime as a, Service as i, linkAbortSignals as n, defaultRuntimeContextStorage as o, Layer as r, CurrentAbortSignal as t };
|
|
269
270
|
|
|
270
|
-
//# sourceMappingURL=signal-
|
|
271
|
+
//# sourceMappingURL=signal-C1bagvrO.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signal-C1bagvrO.mjs","names":["Constructor"],"sources":["../src/runtime/default.ts","../src/service/runtime.ts","../src/service/service.ts","../src/layer/internal.ts","../src/layer/layer.ts","../src/runtime/signal.ts"],"sourcesContent":["import { nodeRuntimeContextStorage } from './node'\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","import { ServiceRuntimeNotConfiguredError } from './errors'\n\nimport { RuntimeContextNotConfiguredError } from '../runtime/errors'\n\nimport {\n currentRuntimeContext,\n getRuntimeContext,\n makeRuntimeContext,\n runRuntimeContext\n} from '../runtime/context'\n\nimport { defaultRuntimeContextStorage } from '../runtime/default'\n\nimport type { AnyServiceToken } from './types'\n\nimport type { RuntimeContextStorage } from '../runtime/context'\n\n/** Resolves class-backed Service tokens for a runtime execution. */\nexport interface ServiceResolver {\n /** Resolve a token to its corresponding Service instance. */\n resolve<T extends AnyServiceToken>(token: T): InstanceType<T> | PromiseLike<InstanceType<T>>\n}\n\n/** Provides the resolver context used by Service tokens during execution. */\nexport class ServiceRuntime {\n /**\n * Run a callback with a resolver available to `yield* Service` expressions.\n *\n * The context is scoped to the callback and is restored afterward.\n *\n * @example\n * ```ts\n * const value = ServiceRuntime.run(resolver, () => {\n * return ServiceRuntime.resolve(Database)\n * })\n * ```\n */\n static run<A>(\n resolver: ServiceResolver,\n program: () => A,\n storage: RuntimeContextStorage = defaultRuntimeContextStorage\n ): A {\n const current = getRuntimeContext(storage)\n const context = makeRuntimeContext(\n resolver,\n current?.scope,\n current?.resolver === resolver ? current.resolutionPath : [],\n current?.signal,\n current?.resolver === resolver ? current : undefined\n )\n\n return runRuntimeContext(storage, context, program)\n }\n\n /** Return the resolver active in the current execution context. */\n static current(): ServiceResolver {\n let context\n\n try {\n context = currentRuntimeContext()\n } catch (cause) {\n if (cause instanceof RuntimeContextNotConfiguredError) {\n throw new ServiceRuntimeNotConfiguredError()\n }\n\n throw cause\n }\n\n if (!context.resolver) {\n throw new ServiceRuntimeNotConfiguredError()\n }\n\n return context.resolver\n }\n\n /** Resolve a Service token using the active resolver. */\n static async resolve<T extends AnyServiceToken>(token: T): Promise<InstanceType<T>> {\n const resolver = ServiceRuntime.current()\n\n return await resolver.resolve(token)\n }\n}\n","import { ServiceRuntime } from './runtime'\n\nimport type { ServiceRequirement } from '../effect/types'\n\nimport type {\n AnyService,\n AnyServiceToken,\n ServiceClass,\n ServiceContract,\n ServiceIdentity,\n ServiceIdentityTypeId,\n ServiceInstance,\n ServiceRequirements,\n ServiceTag,\n ServiceToken,\n ServiceTokenOf\n} from './types'\n\ntype ServiceTagLiteral<Tag extends string> = string extends Tag\n ? never\n : Tag extends ''\n ? never\n : Tag\n\ninterface ServiceFactory<Self> {\n <const Tag extends string>(\n tag: ServiceTagLiteral<Tag>\n ): (abstract new () => ServiceIdentity<Tag>) & {\n readonly name: string\n readonly serviceTag: Tag\n } & {\n readonly of: Service.FactoryOf<Self, Tag>\n readonly [Symbol.asyncIterator]: (\n this: ServiceToken<Tag, Self & ServiceIdentity<Tag>>\n ) => AsyncGenerator<ServiceRequirement<Self>, Self, unknown>\n }\n}\n\n/**\n * Declare a class-backed Service with a stable string-literal identity.\n *\n * The returned class is simultaneously the implementation type, the runtime\n * dependency token, and the value yielded by `yield*` in an Effect generator.\n * The explicit self type preserves exact instance inference, while the second\n * call captures the tag as a literal for Layer composition and diagnostics.\n *\n * @example\n * ```ts\n * class Database extends Service<Database>()('Database') {\n * query(): string {\n * return 'ok'\n * }\n * }\n *\n * const database = yield* Database\n * database.query()\n * ```\n *\n * @typeParam Self The instance type implemented by the declared Service.\n */\nexport function Service<Self>(): ServiceFactory<Self> {\n return function <const Tag extends string>(tag: ServiceTagLiteral<Tag>) {\n if (tag.length === 0) {\n throw new TypeError('Service tags must not be empty')\n }\n\n abstract class BaseService implements ServiceIdentity<Tag> {\n /** The stable logical identity used by Layers and resolver backends. */\n static readonly serviceTag: Tag = tag\n declare readonly [ServiceIdentityTypeId]: Tag\n\n /**\n * Type-check a structural implementation of this Service.\n *\n * This is an identity helper. It returns the supplied value unchanged\n * and does not invoke a constructor or modify its prototype.\n *\n * @example\n * ```ts\n * class Database extends Service<Database>()('Database') {\n * query(sql: string): string {\n * return sql\n * }\n * }\n *\n * const database = Database.of({\n * query: (sql) => `Result: ${sql}`\n * })\n *\n * database.query('SELECT 1')\n * // 'Result: SELECT 1'\n * // database is the original object, not an instance of Database\n * ```\n */\n static of(this: void, implementation: ServiceContract<Self & ServiceIdentity<Tag>>): Self {\n // SAFETY: ServiceContract removes only the phantom marker; this boundary restores Self.\n return implementation as Self\n }\n\n /** Resolve this Service from the resolver active in the current runtime. */\n // oxlint-disable-next-line require-yield\n static async *[Symbol.asyncIterator](\n this: ServiceToken<Tag, Self & ServiceIdentity<Tag>>\n ): AsyncGenerator<ServiceRequirement<Self>, Self, unknown> {\n return await ServiceRuntime.resolve(this)\n }\n }\n\n return BaseService\n }\n}\n\n/** Type-level aliases for Service tokens and their instance contracts. */\nexport declare namespace Service {\n /** The widened Service instance constraint. */\n export type Any = AnyService\n\n /** A class-backed Service token with a stable tag and instance contract. */\n export type Token<Tag extends string = string, Instance extends AnyService = any> = ServiceToken<\n Tag,\n Instance\n >\n\n /** A constructible Service class with a stable tag and instance contract. */\n export type Class<\n Tag extends string = string,\n Instance extends AnyService = AnyService\n > = ServiceClass<Tag, Instance>\n\n /** Extract the instance represented by a Service token. */\n export type Instance<T extends AnyServiceToken> = ServiceInstance<T>\n\n /** Extract the stable tag represented by a Service instance. */\n export type Tag<S extends AnyService> = ServiceTag<S>\n\n /** A branded Service instance identity with a stable tag. */\n export type Identity<Tag extends string = string> = ServiceIdentity<Tag>\n\n /** Remove the internal identity marker from a Service implementation contract. */\n export type Contract<S extends AnyService> = ServiceContract<S>\n\n /** Extract the Service token represented by a branded Service instance. */\n export type TokenOf<S extends AnyService> = ServiceTokenOf<S>\n\n /** Declaration bridge for the recursive structural `Service.of` signature. */\n export type FactoryOf<Self, Tag extends string> = (\n this: void,\n implementation: ServiceContract<Self & ServiceIdentity<Tag>>\n ) => Self\n\n /** Extract Effect Service requirements from a Service instance. */\n export type Requirements<S extends AnyService> = ServiceRequirements<S>\n}\n","import { LayerGeneratorYieldError } from './errors'\n\nimport type { ServiceRequirement } from '../effect/types'\nimport type { ServiceClass } from '../service'\n\nimport type { LayerGenerator } from './types'\n\nexport const runLayerGenerator = async <\n S extends ServiceClass<any, any>,\n Yield extends ServiceRequirement<unknown>\n>(\n service: S,\n factory: LayerGenerator<S, Yield>\n): Promise<InstanceType<S>> => {\n const iterator = factory()\n\n const state = await iterator.next()\n\n if (!state.done) {\n try {\n // SAFETY: The iterator is closed only to discard an invalid yield; its return value is ignored.\n await iterator.return(undefined as never)\n } finally {\n // oxlint-disable-next-line no-unsafe-finally\n throw new LayerGeneratorYieldError(service)\n }\n }\n\n // SAFETY: The public generator boundary accepts only the requested Service contract.\n return state.value as InstanceType<S>\n}\n","import type { ServiceRequirement } from '../effect/types'\nimport type { AnyService, ServiceClass, ServiceContract, ServiceRequirements } from '../service'\nimport type { ScopeOutcome } from '../scope'\nimport type { Covariant, Invariant } from '../internal/variance'\nimport type { MaybePromise } from '../utils/types'\n\nimport { DuplicateServiceError, ServiceTagCollisionError } from './errors'\nimport { runLayerGenerator } from './internal'\n\nimport type {\n LayerInput,\n CompleteInput,\n LayerResult,\n MergeResult,\n OverrideLayerResult,\n ValidateLayerInput,\n ValidateLayerTuple,\n ValidateOverrides,\n ProvidedEnvironment,\n RequiredEnvironment\n} from './inference'\nimport type { ProviderEntry } from './metadata'\nimport type { LayerGenerator, LayerGeneratorRequirements, LayerRegistration } from './types'\n\ndeclare const LayerTypeId: unique symbol\n\ninterface LayerVariance<in out Provided, out Required> {\n readonly _Provided: Invariant<Provided>\n readonly _Required: Covariant<Required>\n}\n\ninterface LayerProvider extends LayerRegistration {\n /** Provider storage deliberately erases the concrete instance type. */\n // oxlint-disable-next-line anti-slop/no-unknown-parameters\n readonly release?: (instance: unknown, outcome: ScopeOutcome) => MaybePromise<void>\n}\n\n/** A Service class whose constructor can be called without arguments. */\ntype DefaultConstructibleServiceClass<\n Tag extends string = string,\n Instance extends AnyService = AnyService\n> = ServiceClass<Tag, Instance> & (new () => Instance)\n\n/**\n * Declarative collection of Service providers.\n *\n * A Layer describes how to acquire implementations; it does not execute\n * providers until a `Runtime` is created. Use `merge` to compose distinct\n * providers and `override` when replacing an existing provider intentionally.\n *\n * @example\n * ```ts\n * const AppLive = Layer.merge(\n * Layer.succeed(Database, database),\n * Layer.make(UserRepository)\n * )\n *\n * const runtime = await Runtime.make(AppLive, backend)\n * ```\n */\nexport class Layer<\n in out Provided extends AnyService = AnyService,\n out Required extends AnyService = AnyService\n> {\n declare readonly [LayerTypeId]: LayerVariance<Provided, Required>\n\n /** The provider registrations retained by this Layer. */\n readonly providers: readonly LayerProvider[]\n\n private constructor(providers: readonly LayerProvider[]) {\n this.providers = Object.freeze([...providers])\n }\n\n /** Create a Layer that lazily acquires a Service instance. */\n static make<S extends DefaultConstructibleServiceClass<any, any>>(\n service: S\n ): LayerResult<ProviderEntry<InstanceType<S>, ServiceRequirements<InstanceType<S>>>>\n\n static make<S extends ServiceClass<any, any>>(\n service: S,\n acquire: () => MaybePromise<ServiceContract<InstanceType<S>>>\n ): LayerResult<ProviderEntry<InstanceType<S>, ServiceRequirements<InstanceType<S>>>>\n\n static make<S extends ServiceClass<any, any>>(\n service: S,\n acquire?: () => MaybePromise<ServiceContract<InstanceType<S>>>\n ): LayerResult<ProviderEntry<InstanceType<S>, ServiceRequirements<InstanceType<S>>>> {\n const defaultAcquire = (): InstanceType<S> => {\n // SAFETY: The no-argument overload constrains `service` to a default constructible class.\n const Constructor = service as new () => InstanceType<S>\n\n return new Constructor()\n }\n\n const normalizedAcquire = normalizeAcquire<S>(acquire ?? defaultAcquire)\n\n // SAFETY: Runtime storage erases only the concrete provider metadata; the public constructor result restores its typed provenance.\n return new Layer([\n {\n service,\n acquire: normalizedAcquire\n }\n ]) as LayerResult<ProviderEntry<InstanceType<S>, ServiceRequirements<InstanceType<S>>>>\n }\n\n /** Create a Layer from an already-constructed Service instance. */\n static succeed<S extends ServiceClass<any, any>>(\n service: S,\n instance: ServiceContract<InstanceType<S>>\n ): LayerResult<ProviderEntry<InstanceType<S>, ServiceRequirements<InstanceType<S>>>> {\n const normalizedAcquire = normalizeAcquire<S>(() => instance)\n\n // SAFETY: The structural instance has been checked against the requested Service contract.\n return new Layer([\n {\n service,\n acquire: normalizedAcquire\n }\n ]) as LayerResult<ProviderEntry<InstanceType<S>, ServiceRequirements<InstanceType<S>>>>\n }\n\n /** Define a provider with Runtime-root cleanup. */\n static scoped<S extends ServiceClass<any, any>>(\n service: S,\n acquire: () => MaybePromise<ServiceContract<InstanceType<S>>>,\n release: (instance: InstanceType<S>, outcome: ScopeOutcome) => MaybePromise<void>\n ): LayerResult<ProviderEntry<InstanceType<S>, ServiceRequirements<InstanceType<S>>>> {\n // SAFETY: The public callbacks constrain acquisition and release to the requested Service.\n return new Layer([\n {\n service,\n acquire: normalizeAcquire<S>(acquire),\n release: (instance, outcome) => {\n // SAFETY: The backend invokes release with the instance acquired for this token.\n return release(instance as InstanceType<S>, outcome)\n }\n }\n ]) as LayerResult<ProviderEntry<InstanceType<S>, ServiceRequirements<InstanceType<S>>>>\n }\n\n /** Define a provider whose acquisition can yield contextual Services. */\n static scopedGen<S extends ServiceClass<any, any>, Yield extends ServiceRequirement<unknown>>(\n service: S,\n factory: LayerGenerator<S, Yield>,\n release: (instance: InstanceType<S>, outcome: ScopeOutcome) => MaybePromise<void>\n ): LayerResult<ProviderEntry<InstanceType<S>, LayerGeneratorRequirements<S, Yield>>> {\n // SAFETY: The generator and release callback are checked against the requested Service.\n return new Layer([\n {\n service,\n acquire: () => runLayerGenerator(service, factory),\n release: (instance, outcome) => {\n // SAFETY: The backend invokes release with the instance acquired for this token.\n return release(instance as InstanceType<S>, outcome)\n }\n }\n ]) as LayerResult<ProviderEntry<InstanceType<S>, LayerGeneratorRequirements<S, Yield>>>\n }\n\n /** Define a provider whose acquisition can yield contextual Services. */\n static gen<S extends ServiceClass<any, any>, Yield extends ServiceRequirement<unknown>>(\n service: S,\n factory: LayerGenerator<S, Yield>\n ): LayerResult<ProviderEntry<InstanceType<S>, LayerGeneratorRequirements<S, Yield>>> {\n // SAFETY: The generator result is normalized to the requested Service at the runtime boundary.\n return new Layer([\n {\n service,\n acquire: () => runLayerGenerator(service, factory)\n }\n ]) as LayerResult<ProviderEntry<InstanceType<S>, LayerGeneratorRequirements<S, Yield>>>\n }\n\n /** Compose Layers without replacing providers. */\n static merge<const Layers extends readonly LayerInput[]>(\n ...layers: Layers & ValidateLayerTuple<Layers>\n ): MergeResult<Layers> {\n const providers = new Map<string, LayerProvider>()\n\n for (const layer of layers) {\n for (const provider of layer.providers) {\n const service = provider.service\n const existing = providers.get(service.serviceTag)\n\n if (existing) {\n if (existing.service !== service) {\n throw new ServiceTagCollisionError(existing.service, service)\n }\n\n throw new DuplicateServiceError(service)\n }\n\n providers.set(service.serviceTag, provider)\n }\n }\n\n // SAFETY: The heterogeneous provider list is erased only at this internal storage boundary.\n return new Layer([...providers.values()]) as MergeResult<Layers>\n }\n\n /** Mark a Layer composition root as complete without changing its runtime value. */\n static complete<L extends LayerInput>(layer: L & CompleteInput<L>): L {\n return layer\n }\n\n /** Replace providers in a base Layer, using tag identity and compatible contracts. */\n static override<Base extends LayerInput>(\n base: Base & ValidateLayerInput<Base>\n ): OverrideLayerResult<Base, readonly []>\n\n static override<\n Base extends LayerInput,\n const Overrides extends readonly [LayerInput, ...LayerInput[]]\n >(\n base: Base & ValidateLayerInput<Base>,\n ...overrides: Overrides & ValidateOverrides<Base, Overrides>\n ): OverrideLayerResult<Base, Overrides>\n\n static override<Base extends LayerInput, const Overrides extends readonly LayerInput[]>(\n base: Base & ValidateLayerInput<Base>,\n ...overrides: Overrides extends readonly [LayerInput, ...LayerInput[]]\n ? never\n : Overrides & ValidateOverrides<Base, Overrides>\n ): OverrideLayerResult<Base, Overrides>\n\n static override(base: LayerInput, ...overrides: readonly LayerInput[]): Layer<any, any> {\n const providers = new Map<string, LayerProvider>()\n\n for (const provider of base.providers) {\n providers.set(provider.service.serviceTag, provider)\n }\n\n for (const layer of overrides) {\n for (const provider of layer.providers) {\n providers.set(provider.service.serviceTag, provider)\n }\n }\n\n // SAFETY: Runtime provider replacement preserves the computed override metadata.\n return new Layer([...providers.values()]) as Layer<any, any>\n }\n}\n\nconst normalizeAcquire =\n <S extends ServiceClass<any, any>>(\n acquire: () => MaybePromise<ServiceContract<InstanceType<S>>>\n ): (() => MaybePromise<InstanceType<S>>) =>\n () => {\n // SAFETY: ServiceContract removes only the declaration-only identity; runtime values are unchanged.\n return acquire() as MaybePromise<InstanceType<S>>\n }\n\n/** Type-level aliases for inspecting Layer environments and completeness. */\nexport declare namespace Layer {\n /** The widened Layer shape accepted by generic Layer infrastructure. */\n export type Any = LayerInput\n\n /** Extract the branded Service instances provided by a Layer. */\n export type Provided<L extends LayerInput> = ProvidedEnvironment<L>\n\n /** Extract the external Service requirements of a Layer. */\n export type Required<L extends LayerInput> = RequiredEnvironment<L>\n\n /** Extract the Services still missing from a Layer composition. */\n export type Missing<L extends LayerInput> = RequiredEnvironment<L>\n\n /** Validate a Layer's requirements and input shape. */\n export type Complete<L extends LayerInput> = CompleteInput<L>\n}\n","import { currentRuntimeContext } from './context'\n\nconst neverAbortedSignal = new AbortController().signal\n\ntype SignalListener = readonly [AbortSignal, () => void]\n\nexport type AbortSignalLink = {\n readonly signal: AbortSignal\n readonly dispose: () => void\n}\n\n/** Link caller, Runtime and shutdown signals without owning the caller's controller. */\nexport const linkAbortSignals = (\n ...signals: readonly (AbortSignal | undefined)[]\n): AbortSignalLink => {\n const active = signals.filter((signal): signal is AbortSignal => signal !== undefined)\n\n if (active.length === 0) {\n return { signal: neverAbortedSignal, dispose: () => {} }\n }\n\n if (active.length === 1) {\n return { signal: active[0]!, dispose: () => {} }\n }\n\n const controller = new AbortController()\n const listeners: SignalListener[] = []\n let disposed = false\n\n const dispose = (): void => {\n if (disposed) {\n return\n }\n\n disposed = true\n\n for (const [source, listener] of listeners) {\n source.removeEventListener('abort', listener)\n }\n\n listeners.length = 0\n }\n\n const abortFrom = (source: AbortSignal): void => {\n if (controller.signal.aborted) {\n return\n }\n\n controller.abort(source.reason)\n dispose()\n }\n\n for (const source of active) {\n if (source.aborted) {\n abortFrom(source)\n break\n }\n\n const listener = (): void => abortFrom(source)\n listeners.push([source, listener])\n source.addEventListener('abort', listener, { once: true })\n }\n\n return { signal: controller.signal, dispose }\n}\n\n/** Return the current cooperative-cancellation signal. */\nexport const currentAbortSignal = (): AbortSignal =>\n currentRuntimeContext().signal ?? neverAbortedSignal\n\n/** Yieldable access to the signal of the current Runtime execution. */\nexport const CurrentAbortSignal = {\n // oxlint-disable-next-line require-yield\n *[Symbol.iterator](): Generator<never, AbortSignal, unknown> {\n return currentAbortSignal()\n }\n} as const\n"],"mappings":";;;;;AAKA,MAAa,+BAA+B;AAE5C,gCAAgC,4BAA4B;;;;ACiB5D,IAAa,iBAAb,MAAa,eAAe;;;;;;;;;;;;;CAa1B,OAAO,IACL,UACA,SACA,UAAiC,8BAC9B;EACH,MAAM,UAAU,kBAAkB,OAAO;EACzC,MAAM,UAAU,mBACd,UACA,SAAS,OACT,SAAS,aAAa,WAAW,QAAQ,iBAAiB,CAAC,GAC3D,SAAS,QACT,SAAS,aAAa,WAAW,UAAU,KAAA,CAC7C;EAEA,OAAO,kBAAkB,SAAS,SAAS,OAAO;CACpD;;CAGA,OAAO,UAA2B;EAChC,IAAI;EAEJ,IAAI;GACF,UAAU,sBAAsB;EAClC,SAAS,OAAO;GACd,IAAI,iBAAiB,kCACnB,MAAM,IAAI,iCAAiC;GAG7C,MAAM;EACR;EAEA,IAAI,CAAC,QAAQ,UACX,MAAM,IAAI,iCAAiC;EAG7C,OAAO,QAAQ;CACjB;;CAGA,aAAa,QAAmC,OAAoC;EAGlF,OAAO,MAFU,eAAe,QAEZ,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gBAAgB,CAAC,CAAC;;AAUjD,MAAa,oBACX,GAAG,YACiB;CACpB,MAAM,SAAS,QAAQ,QAAQ,WAAkC,WAAW,KAAA,CAAS;CAErF,IAAI,OAAO,WAAW,GACpB,OAAO;EAAE,QAAQ;EAAoB,eAAe,CAAC;CAAE;CAGzD,IAAI,OAAO,WAAW,GACpB,OAAO;EAAE,QAAQ,OAAO;EAAK,eAAe,CAAC;CAAE;CAGjD,MAAM,aAAa,IAAI,gBAAgB;CACvC,MAAM,YAA8B,CAAC;CACrC,IAAI,WAAW;CAEf,MAAM,gBAAsB;EAC1B,IAAI,UACF;EAGF,WAAW;EAEX,KAAK,MAAM,CAAC,QAAQ,aAAa,WAC/B,OAAO,oBAAoB,SAAS,QAAQ;EAG9C,UAAU,SAAS;CACrB;CAEA,MAAM,aAAa,WAA8B;EAC/C,IAAI,WAAW,OAAO,SACpB;EAGF,WAAW,MAAM,OAAO,MAAM;EAC9B,QAAQ;CACV;CAEA,KAAK,MAAM,UAAU,QAAQ;EAC3B,IAAI,OAAO,SAAS;GAClB,UAAU,MAAM;GAChB;EACF;EAEA,MAAM,iBAAuB,UAAU,MAAM;EAC7C,UAAU,KAAK,CAAC,QAAQ,QAAQ,CAAC;EACjC,OAAO,iBAAiB,SAAS,UAAU,EAAE,MAAM,KAAK,CAAC;CAC3D;CAEA,OAAO;EAAE,QAAQ,WAAW;EAAQ;CAAQ;AAC9C;;AAGA,MAAa,2BACX,sBAAsB,CAAC,CAAC,UAAU;;AAGpC,MAAa,qBAAqB,EAEhC,EAAE,OAAO,YAAoD;CAC3D,OAAO,mBAAmB;AAC5B,EACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as Service, r as Layer } from "./signal-
|
|
1
|
+
import { i as Service, r as Layer } from "./signal-C1bagvrO.mjs";
|
|
2
2
|
import { Result, TaggedError } from "better-result";
|
|
3
3
|
//#region src/standard-services/config.ts
|
|
4
4
|
/** A schema validation failure. Raw source values are intentionally omitted. */
|
|
@@ -337,4 +337,4 @@ const CurrentRequestLayer = (value) => CurrentRequest.layer(value);
|
|
|
337
337
|
//#endregion
|
|
338
338
|
export { ConfigSourceError as _, CurrentRequest as a, LoggerLive as c, Random as d, RandomLive as f, ConfigLive as g, Config as h, ClockTestLayer as i, LoggerTest as l, RandomSeededLayer as m, ClockLive as n, CurrentRequestLayer as o, RandomSeeded as p, ClockTest as r, Logger as s, Clock as t, LoggerTestLayer as u, ConfigValidationError as v };
|
|
339
339
|
|
|
340
|
-
//# sourceMappingURL=standard-services-
|
|
340
|
+
//# sourceMappingURL=standard-services-DW-i4UuA.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standard-services-QseopL9g.mjs","names":[],"sources":["../src/standard-services/config.ts","../src/standard-services/index.ts"],"sourcesContent":["import {\n Result,\n TaggedError,\n type Err,\n type Result as ResultType,\n type StandardSchemaV1,\n type UnhandledException\n} from 'better-result'\n\nimport type { ServiceRequirement } from '../effect/types'\nimport { Layer } from '../layer'\nimport { Service } from '../service'\n\n/** Raw string values supplied to a configuration schema. */\nexport type ConfigSource = Readonly<Record<string, string | undefined>>\n\n/** Optional sources used by environment-backed configuration values. */\nexport type ConfigSourceOptions = {\n readonly dotEnvPath?: string\n readonly envSource?: ConfigSource\n}\n\n/** Options for the one-call schema-bound configuration API. */\nexport type ConfigFromEnvOptions<Schema extends StandardSchemaV1> = ConfigSourceOptions & {\n readonly schema: Schema\n}\n\n/** The decoded value produced by a Standard Schema. */\nexport type ConfigOutput<Schema extends StandardSchemaV1> = StandardSchemaV1.InferOutput<Schema>\n\n/** The raw input type described by a Standard Schema. */\nexport type ConfigInput<Schema extends StandardSchemaV1> = StandardSchemaV1.InferInput<Schema>\n\n/** A safe validation issue exposed by a configuration failure. */\nexport type ConfigIssue = StandardSchemaV1.Issue\n\n/** A schema validation failure. Raw source values are intentionally omitted. */\nexport class ConfigValidationError extends TaggedError('ConfigValidationError')<{\n readonly issues: ReadonlyArray<ConfigIssue>\n readonly message: string\n}> {}\n\n/** A dotenv or host-source loading failure. Raw source values are intentionally omitted. */\nexport class ConfigSourceError extends TaggedError('ConfigSourceError')<{\n readonly cause: unknown\n readonly message: string\n readonly path?: string\n}> {}\n\n/** Errors that may be returned while loading or validating configuration. */\nexport type ConfigError = ConfigValidationError | ConfigSourceError | UnhandledException\n\ntype ConfigYield<Requirements extends Service.Any, Error> =\n | Err<never, Error>\n | ServiceRequirement<Requirements>\n\n/** A reusable, async-yieldable Standard Schema configuration descriptor. */\nexport type ConfigValue<\n Schema extends StandardSchemaV1,\n Requirements extends Service.Any = never,\n Error = ConfigError\n> = {\n [Symbol.asyncIterator](): AsyncGenerator<\n ConfigYield<Requirements, Error>,\n ConfigOutput<Schema>,\n unknown\n >\n}\n\ntype RuntimeConfigYield = Err<never, ConfigError> | ServiceRequirement<Service.Any>\n\ntype ConfigValueSpec<Schema extends StandardSchemaV1> = {\n readonly schema: Schema\n readonly source: 'bound' | 'provider'\n readonly sourceOptions?: ConfigSourceOptions\n}\n\ntype MutableConfigSourceOptions = {\n dotEnvPath?: string\n envSource?: ConfigSource\n}\n\ntype RuntimeGlobal = typeof globalThis & {\n readonly process?: { readonly env?: ConfigSource }\n readonly Bun?: {\n readonly env?: ConfigSource\n readonly file?: (path: string) => { text(): Promise<string> }\n }\n}\n\n// SAFETY: Hosts may expose process/Bun globals at runtime without declaring them on globalThis.\nconst runtimeGlobal = globalThis as RuntimeGlobal\n\nconst hostEnvironment = (): ConfigSource => {\n const processEnvironment = runtimeGlobal.process?.env\n\n if (processEnvironment !== undefined) {\n return processEnvironment\n }\n\n return runtimeGlobal.Bun?.env ?? {}\n}\n\nconst readText = async (path: string): Promise<string> => {\n const file = runtimeGlobal.Bun?.file\n\n if (file !== undefined) {\n return await file(path).text()\n }\n\n const { readFile } = await import('node:fs/promises')\n\n return await readFile(path, 'utf8')\n}\n\nconst parseDotEnv = (text: string) => {\n const values = new Map<string, string>()\n\n for (const [lineIndex, rawLine] of text\n .replace(/^\\uFEFF/, '')\n .split(/\\r?\\n/u)\n .entries()) {\n let line = rawLine.trim()\n\n if (line === '' || line.startsWith('#')) {\n continue\n }\n\n if (/^export\\s/u.test(line)) {\n line = line.replace(/^export\\s+/u, '')\n }\n\n const separator = line.indexOf('=')\n\n if (separator <= 0) {\n throw new Error(`Invalid dotenv entry at line ${lineIndex + 1}`)\n }\n\n const key = line.slice(0, separator).trim()\n\n if (!/^[A-Za-z_][A-Za-z0-9_]*$/u.test(key)) {\n throw new Error(`Invalid dotenv key at line ${lineIndex + 1}`)\n }\n\n let value = line.slice(separator + 1).trim()\n const quote = value[0]\n\n if (quote === '\"' || quote === \"'\") {\n const closingQuote = value.indexOf(quote, 1)\n const trailing = closingQuote < 0 ? '' : value.slice(closingQuote + 1).trim()\n\n if (closingQuote < 0 || (trailing !== '' && !trailing.startsWith('#'))) {\n throw new Error(`Unterminated dotenv value at line ${lineIndex + 1}`)\n }\n\n value = value.slice(1, closingQuote)\n } else {\n const comment = value.search(/\\s+#/u)\n\n if (comment >= 0) {\n value = value.slice(0, comment).trimEnd()\n }\n }\n\n values.set(key, value)\n }\n\n return Object.fromEntries(values)\n}\n\nconst loadSource = async (options: ConfigSourceOptions = {}): Promise<ConfigSource> => {\n const dotenv =\n options.dotEnvPath === undefined ? {} : parseDotEnv(await readText(options.dotEnvPath))\n const explicit = options.envSource ?? hostEnvironment()\n\n return {\n ...dotenv,\n ...explicit\n }\n}\n\nconst sourceError = (path: string | undefined, cause: unknown): ConfigSourceError => {\n const message =\n path === undefined\n ? 'Failed to load configuration source'\n : `Failed to load configuration source at ${path}`\n\n if (path === undefined) {\n return new ConfigSourceError({ cause, message })\n }\n\n return new ConfigSourceError({ cause, message, path })\n}\n\nconst validate = async <Schema extends StandardSchemaV1>(\n schema: Schema,\n source: ConfigSource\n): Promise<ResultType<ConfigOutput<Schema>, ConfigValidationError | UnhandledException>> => {\n const checked = await Result.tryPromise(() =>\n Promise.resolve(schema['~standard'].validate(source))\n )\n\n if (checked.status === 'error') {\n return checked\n }\n\n if (checked.value.issues !== undefined) {\n return Result.err(\n new ConfigValidationError({\n issues: Object.freeze([...checked.value.issues]),\n message: 'Configuration validation failed'\n })\n )\n }\n\n // SAFETY: A successful Standard Schema result carries its declared output type.\n return Result.ok(checked.value.value as ConfigOutput<Schema>)\n}\n\nconst evaluate = async <Schema extends StandardSchemaV1>(\n spec: ConfigValueSpec<Schema>,\n provider?: Config\n): Promise<ResultType<ConfigOutput<Schema>, ConfigError>> => {\n const loaded = await Result.tryPromise({\n try: async () => {\n if (spec.source === 'provider') {\n const base = provider?.source\n\n if (base === undefined) {\n throw new Error('Config provider did not expose a source')\n }\n\n if (spec.sourceOptions === undefined) {\n return base\n }\n\n return {\n ...base,\n ...(await loadSource(spec.sourceOptions))\n }\n }\n\n return await loadSource(spec.sourceOptions)\n },\n catch: (cause) => sourceError(spec.sourceOptions?.dotEnvPath, cause)\n })\n\n if (loaded.status === 'error') {\n return loaded\n }\n\n return await validate(spec.schema, loaded.value)\n}\n\nconst makeConfigValue = <Schema extends StandardSchemaV1, Requirements extends Service.Any>(\n spec: ConfigValueSpec<Schema>\n): ConfigValue<Schema, Requirements> => {\n const value = {\n ...spec,\n async *[Symbol.asyncIterator](): AsyncGenerator<\n RuntimeConfigYield,\n ConfigOutput<Schema>,\n unknown\n > {\n let provider: Config | undefined\n\n if (spec.source === 'provider') {\n provider = yield* Config\n }\n\n return yield* Result.await(evaluate(spec, provider))\n }\n }\n\n // SAFETY: The runtime iterator only yields Result errors and Service values; the public cast restores the phantom requirement.\n return value as ConfigValue<Schema, Requirements>\n}\n\n/** Host-backed raw configuration source and provider token. */\nexport class Config extends Service<Config>()('Config') {\n constructor(readonly source: ConfigSource) {\n super()\n }\n\n /** Read one raw value from the configured source. */\n get(key: string): string | undefined {\n return this.source[key]\n }\n\n /** Create a provider from an already-loaded source. */\n static layer(source: ConfigSource) {\n return Layer.succeed(Config, new Config(source))\n }\n\n /** Create a provider whose source is loaded from dotenv and the host environment. */\n static layerFromEnv(options: ConfigSourceOptions = {}) {\n return Layer.make(Config, async () => {\n try {\n return new Config(await loadSource(options))\n } catch (cause) {\n throw sourceError(options.dotEnvPath, cause)\n }\n })\n }\n\n /** Describe a configuration read from the contextual Config provider. */\n static schema<Schema extends StandardSchemaV1>(schema: Schema): ConfigValue<Schema, Config> {\n return makeConfigValue({ schema, source: 'provider' })\n }\n\n /** Describe a reusable configuration loaded from dotenv and the host environment. */\n static fromEnv<Schema extends StandardSchemaV1>(\n options: ConfigFromEnvOptions<Schema>\n ): ConfigValue<Schema> {\n const sourceOptions: MutableConfigSourceOptions = {}\n\n if (options.dotEnvPath !== undefined) {\n sourceOptions.dotEnvPath = options.dotEnvPath\n }\n\n if (options.envSource !== undefined) {\n sourceOptions.envSource = options.envSource\n }\n\n return makeConfigValue({\n schema: options.schema,\n source: 'bound',\n sourceOptions\n })\n }\n\n /** Add an environment source to a provider-backed descriptor for functional `pipe` composition. */\n static withEnv(options: ConfigSourceOptions) {\n return <Schema extends StandardSchemaV1, Requirements extends Service.Any, Error = ConfigError>(\n value: ConfigValue<Schema, Requirements, Error>\n ): ConfigValue<Schema, Requirements, Error> => {\n // SAFETY: Values produced by this module retain their schema/source descriptor fields; custom iterables pass through unchanged.\n const internal = value as ConfigValue<Schema, Requirements> & ConfigValueSpec<Schema>\n\n if (!('schema' in internal)) {\n return value\n }\n\n // SAFETY: The internal descriptor preserves the original schema and requirement phantom.\n return makeConfigValue({\n schema: internal.schema,\n source: internal.source,\n sourceOptions: options\n }) as ConfigValue<Schema, Requirements, Error>\n }\n }\n}\n\n/** The default lazy host-environment Config provider. */\nexport const ConfigLive = Config.layerFromEnv()\n\nexport type { StandardSchemaV1 }\n","import { CurrentAbortSignal } from '../runtime'\nimport { Layer } from '../layer'\nimport { Service } from '../service'\n\nexport { CurrentAbortSignal }\n\nexport { Config, ConfigLive, ConfigSourceError, ConfigValidationError } from './config'\n\nexport type {\n ConfigError,\n ConfigFromEnvOptions,\n ConfigInput,\n ConfigIssue,\n ConfigOutput,\n ConfigSource,\n ConfigSourceOptions,\n ConfigValue,\n StandardSchemaV1\n} from './config'\n\nconst assertDelay = (milliseconds: number): void => {\n if (!Number.isFinite(milliseconds) || milliseconds < 0) {\n throw new RangeError('Delay must be a finite non-negative number')\n }\n}\n\n/** Host-backed time and waiting service. */\nexport class Clock extends Service<Clock>()('Clock') {\n now(): Date {\n return new Date()\n }\n\n sleep(milliseconds: number): Promise<void> {\n assertDelay(milliseconds)\n return new Promise((resolve) => setTimeout(resolve, milliseconds))\n }\n}\n\n/** The default host Clock provider. */\nexport const ClockLive = Layer.make(Clock)\n\ntype ClockWaiter = {\n readonly at: number\n readonly resolve: () => void\n}\n\n/** Deterministic Clock implementation for tests. */\nexport class ClockTest implements Service.Contract<Clock> {\n private currentTime: number\n\n private readonly waiters: ClockWaiter[] = []\n\n constructor(initial: Date | number = 0) {\n this.currentTime = initial instanceof Date ? initial.getTime() : initial\n\n if (!Number.isFinite(this.currentTime)) {\n throw new RangeError('ClockTest time must be finite')\n }\n }\n\n now(): Date {\n return new Date(this.currentTime)\n }\n\n setTime(value: Date | number): void {\n const next = value instanceof Date ? value.getTime() : value\n\n if (!Number.isFinite(next)) {\n throw new RangeError('ClockTest time must be finite')\n }\n\n this.currentTime = next\n this.flushWaiters()\n }\n\n advance(milliseconds: number): void {\n assertDelay(milliseconds)\n this.currentTime += milliseconds\n this.flushWaiters()\n }\n\n sleep(milliseconds: number): Promise<void> {\n assertDelay(milliseconds)\n\n return new Promise((resolve) => {\n this.waiters.push({ at: this.currentTime + milliseconds, resolve })\n this.flushWaiters()\n })\n }\n\n static layer(initial: Date | number = 0) {\n return Layer.succeed(Clock, new ClockTest(initial))\n }\n\n private flushWaiters(): void {\n for (let index = this.waiters.length - 1; index >= 0; index--) {\n const waiter = this.waiters[index]!\n\n if (waiter.at <= this.currentTime) {\n this.waiters.splice(index, 1)\n waiter.resolve()\n }\n }\n }\n}\n\nexport const ClockTestLayer = (initial: Date | number = 0) => ClockTest.layer(initial)\n\n/** Host-backed pseudo-random number service. */\nexport class Random extends Service<Random>()('Random') {\n next(): number {\n return Math.random()\n }\n\n nextInt(maxExclusive: number): number {\n if (!Number.isInteger(maxExclusive) || maxExclusive <= 0) {\n throw new RangeError('Random.nextInt maxExclusive must be a positive integer')\n }\n\n return Math.floor(this.next() * maxExclusive)\n }\n}\n\n/** The default host Random provider. */\nexport const RandomLive = Layer.make(Random)\n\n/** Reproducible pseudo-random implementation with isolated mutable state. */\nexport class RandomSeeded implements Service.Contract<Random> {\n private state: number\n\n constructor(seed: number) {\n if (!Number.isFinite(seed)) {\n throw new RangeError('RandomSeeded seed must be finite')\n }\n\n this.state = seed >>> 0\n }\n\n next(): number {\n this.state = (1664525 * this.state + 1013904223) >>> 0\n return this.state / 0x1_0000_0000\n }\n\n nextInt(maxExclusive: number): number {\n if (!Number.isInteger(maxExclusive) || maxExclusive <= 0) {\n throw new RangeError('RandomSeeded.nextInt maxExclusive must be a positive integer')\n }\n\n return Math.floor(this.next() * maxExclusive)\n }\n\n static layer(seed: number) {\n return Layer.succeed(Random, new RandomSeeded(seed))\n }\n}\n\nexport const RandomSeededLayer = (seed: number) => RandomSeeded.layer(seed)\n\nexport type LoggerLevel = 'debug' | 'info' | 'warn' | 'error'\n\nexport type LoggerEvent = {\n level: LoggerLevel\n message: string\n data?: LoggerData\n}\n\nexport type LoggerData =\n | string\n | number\n | boolean\n | bigint\n | null\n | readonly LoggerData[]\n | { readonly [key: string]: LoggerData }\ntype LoggerInput = LoggerEvent | LoggerLevel\n\nconst isLoggerLevel = (value: LoggerInput): value is LoggerLevel =>\n value === 'debug' || value === 'info' || value === 'warn' || value === 'error'\n\nconst toLoggerEvent = (input: LoggerInput, message?: string, data?: LoggerData): LoggerEvent => {\n if (!isLoggerLevel(input)) {\n return input\n }\n\n const event: LoggerEvent = { level: input, message: message ?? '' }\n\n if (data !== undefined) {\n event.data = data\n }\n\n return event\n}\n\n/** Structured host logger bridge. */\nexport class Logger extends Service<Logger>()('Logger') {\n log(event: LoggerEvent): void\n log(level: LoggerLevel, message: string, data?: LoggerData): void\n log(first: LoggerInput, message?: string, data?: LoggerData): void {\n const event = toLoggerEvent(first, message, data)\n\n const write = console[event.level]\n\n if (event.data === undefined) {\n write.call(console, event.message)\n } else {\n write.call(console, event.message, event.data)\n }\n }\n\n debug(message: string, data?: LoggerData): void {\n this.log('debug', message, data)\n }\n\n info(message: string, data?: LoggerData): void {\n this.log('info', message, data)\n }\n\n warn(message: string, data?: LoggerData): void {\n this.log('warn', message, data)\n }\n\n error(message: string, data?: LoggerData): void {\n this.log('error', message, data)\n }\n}\n\n/** The default host Logger provider. */\nexport const LoggerLive = Layer.make(Logger)\n\n/** Ordered in-memory Logger implementation for tests. */\nexport class LoggerTest implements Service.Contract<Logger> {\n readonly events: LoggerEvent[] = []\n\n log(event: LoggerEvent): void\n log(level: LoggerLevel, message: string, data?: LoggerData): void\n log(first: LoggerInput, message?: string, data?: LoggerData): void {\n const event = toLoggerEvent(first, message, data)\n\n this.events.push(event)\n }\n\n debug(message: string, data?: LoggerData): void {\n this.log('debug', message, data)\n }\n\n info(message: string, data?: LoggerData): void {\n this.log('info', message, data)\n }\n\n warn(message: string, data?: LoggerData): void {\n this.log('warn', message, data)\n }\n\n error(message: string, data?: LoggerData): void {\n this.log('error', message, data)\n }\n\n clear(): void {\n this.events.length = 0\n }\n\n static make() {\n const logger = new LoggerTest()\n return { logger, layer: Layer.succeed(Logger, logger) }\n }\n\n static layer(logger: LoggerTest = new LoggerTest()) {\n return Layer.succeed(Logger, logger)\n }\n}\n\nexport const LoggerTestLayer = () => LoggerTest.layer()\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":";;;;AAqCA,IAAa,wBAAb,cAA2C,YAAY,uBAAuB,CAAC,CAG5E,CAAC;;AAGJ,IAAa,oBAAb,cAAuC,YAAY,mBAAmB,CAAC,CAIpE,CAAC;AA4CJ,MAAM,gBAAgB;AAEtB,MAAM,wBAAsC;CAC1C,MAAM,qBAAqB,cAAc,SAAS;CAElD,IAAI,uBAAuB,KAAA,GACzB,OAAO;CAGT,OAAO,cAAc,KAAK,OAAO,CAAC;AACpC;AAEA,MAAM,WAAW,OAAO,SAAkC;CACxD,MAAM,OAAO,cAAc,KAAK;CAEhC,IAAI,SAAS,KAAA,GACX,OAAO,MAAM,KAAK,IAAI,CAAC,CAAC,KAAK;CAG/B,MAAM,EAAE,aAAa,MAAM,OAAO;CAElC,OAAO,MAAM,SAAS,MAAM,MAAM;AACpC;AAEA,MAAM,eAAe,SAAiB;CACpC,MAAM,yBAAS,IAAI,IAAoB;CAEvC,KAAK,MAAM,CAAC,WAAW,YAAY,KAChC,QAAQ,WAAW,EAAE,CAAC,CACtB,MAAM,QAAQ,CAAC,CACf,QAAQ,GAAG;EACZ,IAAI,OAAO,QAAQ,KAAK;EAExB,IAAI,SAAS,MAAM,KAAK,WAAW,GAAG,GACpC;EAGF,IAAI,aAAa,KAAK,IAAI,GACxB,OAAO,KAAK,QAAQ,eAAe,EAAE;EAGvC,MAAM,YAAY,KAAK,QAAQ,GAAG;EAElC,IAAI,aAAa,GACf,MAAM,IAAI,MAAM,gCAAgC,YAAY,GAAG;EAGjE,MAAM,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC,CAAC,KAAK;EAE1C,IAAI,CAAC,4BAA4B,KAAK,GAAG,GACvC,MAAM,IAAI,MAAM,8BAA8B,YAAY,GAAG;EAG/D,IAAI,QAAQ,KAAK,MAAM,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
|
|
1
|
+
{"version":3,"file":"standard-services-DW-i4UuA.mjs","names":[],"sources":["../src/standard-services/config.ts","../src/standard-services/index.ts"],"sourcesContent":["import {\n Result,\n TaggedError,\n type Err,\n type Result as ResultType,\n type StandardSchemaV1,\n type UnhandledException\n} from 'better-result'\n\nimport type { ServiceRequirement } from '../effect/types'\nimport { Layer } from '../layer'\nimport { Service } from '../service'\n\n/** Raw string values supplied to a configuration schema. */\nexport type ConfigSource = Readonly<Record<string, string | undefined>>\n\n/** Optional sources used by environment-backed configuration values. */\nexport type ConfigSourceOptions = {\n readonly dotEnvPath?: string\n readonly envSource?: ConfigSource\n}\n\n/** Options for the one-call schema-bound configuration API. */\nexport type ConfigFromEnvOptions<Schema extends StandardSchemaV1> = ConfigSourceOptions & {\n readonly schema: Schema\n}\n\n/** The decoded value produced by a Standard Schema. */\nexport type ConfigOutput<Schema extends StandardSchemaV1> = StandardSchemaV1.InferOutput<Schema>\n\n/** The raw input type described by a Standard Schema. */\nexport type ConfigInput<Schema extends StandardSchemaV1> = StandardSchemaV1.InferInput<Schema>\n\n/** A safe validation issue exposed by a configuration failure. */\nexport type ConfigIssue = StandardSchemaV1.Issue\n\n/** A schema validation failure. Raw source values are intentionally omitted. */\nexport class ConfigValidationError extends TaggedError('ConfigValidationError')<{\n readonly issues: ReadonlyArray<ConfigIssue>\n readonly message: string\n}> {}\n\n/** A dotenv or host-source loading failure. Raw source values are intentionally omitted. */\nexport class ConfigSourceError extends TaggedError('ConfigSourceError')<{\n readonly cause: unknown\n readonly message: string\n readonly path?: string\n}> {}\n\n/** Errors that may be returned while loading or validating configuration. */\nexport type ConfigError = ConfigValidationError | ConfigSourceError | UnhandledException\n\ntype ConfigYield<Requirements extends Service.Any, Error> =\n | Err<never, Error>\n | ServiceRequirement<Requirements>\n\n/** A reusable, async-yieldable Standard Schema configuration descriptor. */\nexport type ConfigValue<\n Schema extends StandardSchemaV1,\n Requirements extends Service.Any = never,\n Error = ConfigError\n> = {\n [Symbol.asyncIterator](): AsyncGenerator<\n ConfigYield<Requirements, Error>,\n ConfigOutput<Schema>,\n unknown\n >\n}\n\ntype RuntimeConfigYield = Err<never, ConfigError> | ServiceRequirement<Service.Any>\n\ntype ConfigValueSpec<Schema extends StandardSchemaV1> = {\n readonly schema: Schema\n readonly source: 'bound' | 'provider'\n readonly sourceOptions?: ConfigSourceOptions\n}\n\ntype MutableConfigSourceOptions = {\n dotEnvPath?: string\n envSource?: ConfigSource\n}\n\ntype RuntimeGlobal = typeof globalThis & {\n readonly process?: { readonly env?: ConfigSource }\n readonly Bun?: {\n readonly env?: ConfigSource\n readonly file?: (path: string) => { text(): Promise<string> }\n }\n}\n\n// SAFETY: Hosts may expose process/Bun globals at runtime without declaring them on globalThis.\nconst runtimeGlobal = globalThis as RuntimeGlobal\n\nconst hostEnvironment = (): ConfigSource => {\n const processEnvironment = runtimeGlobal.process?.env\n\n if (processEnvironment !== undefined) {\n return processEnvironment\n }\n\n return runtimeGlobal.Bun?.env ?? {}\n}\n\nconst readText = async (path: string): Promise<string> => {\n const file = runtimeGlobal.Bun?.file\n\n if (file !== undefined) {\n return await file(path).text()\n }\n\n const { readFile } = await import('node:fs/promises')\n\n return await readFile(path, 'utf8')\n}\n\nconst parseDotEnv = (text: string) => {\n const values = new Map<string, string>()\n\n for (const [lineIndex, rawLine] of text\n .replace(/^\\uFEFF/, '')\n .split(/\\r?\\n/u)\n .entries()) {\n let line = rawLine.trim()\n\n if (line === '' || line.startsWith('#')) {\n continue\n }\n\n if (/^export\\s/u.test(line)) {\n line = line.replace(/^export\\s+/u, '')\n }\n\n const separator = line.indexOf('=')\n\n if (separator <= 0) {\n throw new Error(`Invalid dotenv entry at line ${lineIndex + 1}`)\n }\n\n const key = line.slice(0, separator).trim()\n\n if (!/^[A-Za-z_][A-Za-z0-9_]*$/u.test(key)) {\n throw new Error(`Invalid dotenv key at line ${lineIndex + 1}`)\n }\n\n let value = line.slice(separator + 1).trim()\n const quote = value[0]\n\n if (quote === '\"' || quote === \"'\") {\n const closingQuote = value.indexOf(quote, 1)\n const trailing = closingQuote < 0 ? '' : value.slice(closingQuote + 1).trim()\n\n if (closingQuote < 0 || (trailing !== '' && !trailing.startsWith('#'))) {\n throw new Error(`Unterminated dotenv value at line ${lineIndex + 1}`)\n }\n\n value = value.slice(1, closingQuote)\n } else {\n const comment = value.search(/\\s+#/u)\n\n if (comment >= 0) {\n value = value.slice(0, comment).trimEnd()\n }\n }\n\n values.set(key, value)\n }\n\n return Object.fromEntries(values)\n}\n\nconst loadSource = async (options: ConfigSourceOptions = {}): Promise<ConfigSource> => {\n const dotenv =\n options.dotEnvPath === undefined ? {} : parseDotEnv(await readText(options.dotEnvPath))\n const explicit = options.envSource ?? hostEnvironment()\n\n return {\n ...dotenv,\n ...explicit\n }\n}\n\nconst sourceError = (path: string | undefined, cause: unknown): ConfigSourceError => {\n const message =\n path === undefined\n ? 'Failed to load configuration source'\n : `Failed to load configuration source at ${path}`\n\n if (path === undefined) {\n return new ConfigSourceError({ cause, message })\n }\n\n return new ConfigSourceError({ cause, message, path })\n}\n\nconst validate = async <Schema extends StandardSchemaV1>(\n schema: Schema,\n source: ConfigSource\n): Promise<ResultType<ConfigOutput<Schema>, ConfigValidationError | UnhandledException>> => {\n const checked = await Result.tryPromise(() =>\n Promise.resolve(schema['~standard'].validate(source))\n )\n\n if (checked.status === 'error') {\n return checked\n }\n\n if (checked.value.issues !== undefined) {\n return Result.err(\n new ConfigValidationError({\n issues: Object.freeze([...checked.value.issues]),\n message: 'Configuration validation failed'\n })\n )\n }\n\n // SAFETY: A successful Standard Schema result carries its declared output type.\n return Result.ok(checked.value.value as ConfigOutput<Schema>)\n}\n\nconst evaluate = async <Schema extends StandardSchemaV1>(\n spec: ConfigValueSpec<Schema>,\n provider?: Config\n): Promise<ResultType<ConfigOutput<Schema>, ConfigError>> => {\n const loaded = await Result.tryPromise({\n try: async () => {\n if (spec.source === 'provider') {\n const base = provider?.source\n\n if (base === undefined) {\n throw new Error('Config provider did not expose a source')\n }\n\n if (spec.sourceOptions === undefined) {\n return base\n }\n\n return {\n ...base,\n ...(await loadSource(spec.sourceOptions))\n }\n }\n\n return await loadSource(spec.sourceOptions)\n },\n catch: (cause) => sourceError(spec.sourceOptions?.dotEnvPath, cause)\n })\n\n if (loaded.status === 'error') {\n return loaded\n }\n\n return await validate(spec.schema, loaded.value)\n}\n\nconst makeConfigValue = <Schema extends StandardSchemaV1, Requirements extends Service.Any>(\n spec: ConfigValueSpec<Schema>\n): ConfigValue<Schema, Requirements> => {\n const value = {\n ...spec,\n async *[Symbol.asyncIterator](): AsyncGenerator<\n RuntimeConfigYield,\n ConfigOutput<Schema>,\n unknown\n > {\n let provider: Config | undefined\n\n if (spec.source === 'provider') {\n provider = yield* Config\n }\n\n return yield* Result.await(evaluate(spec, provider))\n }\n }\n\n // SAFETY: The runtime iterator only yields Result errors and Service values; the public cast restores the phantom requirement.\n return value as ConfigValue<Schema, Requirements>\n}\n\n/** Host-backed raw configuration source and provider token. */\nexport class Config extends Service<Config>()('Config') {\n constructor(readonly source: ConfigSource) {\n super()\n }\n\n /** Read one raw value from the configured source. */\n get(key: string): string | undefined {\n return this.source[key]\n }\n\n /** Create a provider from an already-loaded source. */\n static layer(source: ConfigSource) {\n return Layer.succeed(Config, new Config(source))\n }\n\n /** Create a provider whose source is loaded from dotenv and the host environment. */\n static layerFromEnv(options: ConfigSourceOptions = {}) {\n return Layer.make(Config, async () => {\n try {\n return new Config(await loadSource(options))\n } catch (cause) {\n throw sourceError(options.dotEnvPath, cause)\n }\n })\n }\n\n /** Describe a configuration read from the contextual Config provider. */\n static schema<Schema extends StandardSchemaV1>(schema: Schema): ConfigValue<Schema, Config> {\n return makeConfigValue({ schema, source: 'provider' })\n }\n\n /** Describe a reusable configuration loaded from dotenv and the host environment. */\n static fromEnv<Schema extends StandardSchemaV1>(\n options: ConfigFromEnvOptions<Schema>\n ): ConfigValue<Schema> {\n const sourceOptions: MutableConfigSourceOptions = {}\n\n if (options.dotEnvPath !== undefined) {\n sourceOptions.dotEnvPath = options.dotEnvPath\n }\n\n if (options.envSource !== undefined) {\n sourceOptions.envSource = options.envSource\n }\n\n return makeConfigValue({\n schema: options.schema,\n source: 'bound',\n sourceOptions\n })\n }\n\n /** Add an environment source to a provider-backed descriptor for functional `pipe` composition. */\n static withEnv(options: ConfigSourceOptions) {\n return <Schema extends StandardSchemaV1, Requirements extends Service.Any, Error = ConfigError>(\n value: ConfigValue<Schema, Requirements, Error>\n ): ConfigValue<Schema, Requirements, Error> => {\n // SAFETY: Values produced by this module retain their schema/source descriptor fields; custom iterables pass through unchanged.\n const internal = value as ConfigValue<Schema, Requirements> & ConfigValueSpec<Schema>\n\n if (!('schema' in internal)) {\n return value\n }\n\n // SAFETY: The internal descriptor preserves the original schema and requirement phantom.\n return makeConfigValue({\n schema: internal.schema,\n source: internal.source,\n sourceOptions: options\n }) as ConfigValue<Schema, Requirements, Error>\n }\n }\n}\n\n/** The default lazy host-environment Config provider. */\nexport const ConfigLive = Config.layerFromEnv()\n\nexport type { StandardSchemaV1 }\n","import { CurrentAbortSignal } from '../runtime'\nimport { Layer } from '../layer'\nimport { Service } from '../service'\n\nexport { CurrentAbortSignal }\n\nexport { Config, ConfigLive, ConfigSourceError, ConfigValidationError } from './config'\n\nexport type {\n ConfigError,\n ConfigFromEnvOptions,\n ConfigInput,\n ConfigIssue,\n ConfigOutput,\n ConfigSource,\n ConfigSourceOptions,\n ConfigValue,\n StandardSchemaV1\n} from './config'\n\nconst assertDelay = (milliseconds: number): void => {\n if (!Number.isFinite(milliseconds) || milliseconds < 0) {\n throw new RangeError('Delay must be a finite non-negative number')\n }\n}\n\n/** Host-backed time and waiting service. */\nexport class Clock extends Service<Clock>()('Clock') {\n now(): Date {\n return new Date()\n }\n\n sleep(milliseconds: number): Promise<void> {\n assertDelay(milliseconds)\n return new Promise((resolve) => setTimeout(resolve, milliseconds))\n }\n}\n\n/** The default host Clock provider. */\nexport const ClockLive = Layer.make(Clock)\n\ntype ClockWaiter = {\n readonly at: number\n readonly resolve: () => void\n}\n\n/** Deterministic Clock implementation for tests. */\nexport class ClockTest implements Service.Contract<Clock> {\n private currentTime: number\n\n private readonly waiters: ClockWaiter[] = []\n\n constructor(initial: Date | number = 0) {\n this.currentTime = initial instanceof Date ? initial.getTime() : initial\n\n if (!Number.isFinite(this.currentTime)) {\n throw new RangeError('ClockTest time must be finite')\n }\n }\n\n now(): Date {\n return new Date(this.currentTime)\n }\n\n setTime(value: Date | number): void {\n const next = value instanceof Date ? value.getTime() : value\n\n if (!Number.isFinite(next)) {\n throw new RangeError('ClockTest time must be finite')\n }\n\n this.currentTime = next\n this.flushWaiters()\n }\n\n advance(milliseconds: number): void {\n assertDelay(milliseconds)\n this.currentTime += milliseconds\n this.flushWaiters()\n }\n\n sleep(milliseconds: number): Promise<void> {\n assertDelay(milliseconds)\n\n return new Promise((resolve) => {\n this.waiters.push({ at: this.currentTime + milliseconds, resolve })\n this.flushWaiters()\n })\n }\n\n static layer(initial: Date | number = 0) {\n return Layer.succeed(Clock, new ClockTest(initial))\n }\n\n private flushWaiters(): void {\n for (let index = this.waiters.length - 1; index >= 0; index--) {\n const waiter = this.waiters[index]!\n\n if (waiter.at <= this.currentTime) {\n this.waiters.splice(index, 1)\n waiter.resolve()\n }\n }\n }\n}\n\nexport const ClockTestLayer = (initial: Date | number = 0) => ClockTest.layer(initial)\n\n/** Host-backed pseudo-random number service. */\nexport class Random extends Service<Random>()('Random') {\n next(): number {\n return Math.random()\n }\n\n nextInt(maxExclusive: number): number {\n if (!Number.isInteger(maxExclusive) || maxExclusive <= 0) {\n throw new RangeError('Random.nextInt maxExclusive must be a positive integer')\n }\n\n return Math.floor(this.next() * maxExclusive)\n }\n}\n\n/** The default host Random provider. */\nexport const RandomLive = Layer.make(Random)\n\n/** Reproducible pseudo-random implementation with isolated mutable state. */\nexport class RandomSeeded implements Service.Contract<Random> {\n private state: number\n\n constructor(seed: number) {\n if (!Number.isFinite(seed)) {\n throw new RangeError('RandomSeeded seed must be finite')\n }\n\n this.state = seed >>> 0\n }\n\n next(): number {\n this.state = (1664525 * this.state + 1013904223) >>> 0\n return this.state / 0x1_0000_0000\n }\n\n nextInt(maxExclusive: number): number {\n if (!Number.isInteger(maxExclusive) || maxExclusive <= 0) {\n throw new RangeError('RandomSeeded.nextInt maxExclusive must be a positive integer')\n }\n\n return Math.floor(this.next() * maxExclusive)\n }\n\n static layer(seed: number) {\n return Layer.succeed(Random, new RandomSeeded(seed))\n }\n}\n\nexport const RandomSeededLayer = (seed: number) => RandomSeeded.layer(seed)\n\nexport type LoggerLevel = 'debug' | 'info' | 'warn' | 'error'\n\nexport type LoggerEvent = {\n level: LoggerLevel\n message: string\n data?: LoggerData\n}\n\nexport type LoggerData =\n | string\n | number\n | boolean\n | bigint\n | null\n | readonly LoggerData[]\n | { readonly [key: string]: LoggerData }\ntype LoggerInput = LoggerEvent | LoggerLevel\n\nconst isLoggerLevel = (value: LoggerInput): value is LoggerLevel =>\n value === 'debug' || value === 'info' || value === 'warn' || value === 'error'\n\nconst toLoggerEvent = (input: LoggerInput, message?: string, data?: LoggerData): LoggerEvent => {\n if (!isLoggerLevel(input)) {\n return input\n }\n\n const event: LoggerEvent = { level: input, message: message ?? '' }\n\n if (data !== undefined) {\n event.data = data\n }\n\n return event\n}\n\n/** Structured host logger bridge. */\nexport class Logger extends Service<Logger>()('Logger') {\n log(event: LoggerEvent): void\n log(level: LoggerLevel, message: string, data?: LoggerData): void\n log(first: LoggerInput, message?: string, data?: LoggerData): void {\n const event = toLoggerEvent(first, message, data)\n\n const write = console[event.level]\n\n if (event.data === undefined) {\n write.call(console, event.message)\n } else {\n write.call(console, event.message, event.data)\n }\n }\n\n debug(message: string, data?: LoggerData): void {\n this.log('debug', message, data)\n }\n\n info(message: string, data?: LoggerData): void {\n this.log('info', message, data)\n }\n\n warn(message: string, data?: LoggerData): void {\n this.log('warn', message, data)\n }\n\n error(message: string, data?: LoggerData): void {\n this.log('error', message, data)\n }\n}\n\n/** The default host Logger provider. */\nexport const LoggerLive = Layer.make(Logger)\n\n/** Ordered in-memory Logger implementation for tests. */\nexport class LoggerTest implements Service.Contract<Logger> {\n readonly events: LoggerEvent[] = []\n\n log(event: LoggerEvent): void\n log(level: LoggerLevel, message: string, data?: LoggerData): void\n log(first: LoggerInput, message?: string, data?: LoggerData): void {\n const event = toLoggerEvent(first, message, data)\n\n this.events.push(event)\n }\n\n debug(message: string, data?: LoggerData): void {\n this.log('debug', message, data)\n }\n\n info(message: string, data?: LoggerData): void {\n this.log('info', message, data)\n }\n\n warn(message: string, data?: LoggerData): void {\n this.log('warn', message, data)\n }\n\n error(message: string, data?: LoggerData): void {\n this.log('error', message, data)\n }\n\n clear(): void {\n this.events.length = 0\n }\n\n static make() {\n const logger = new LoggerTest()\n return { logger, layer: Layer.succeed(Logger, logger) }\n }\n\n static layer(logger: LoggerTest = new LoggerTest()) {\n return Layer.succeed(Logger, logger)\n }\n}\n\nexport const LoggerTestLayer = () => LoggerTest.layer()\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":";;;;AAqCA,IAAa,wBAAb,cAA2C,YAAY,uBAAuB,CAAC,CAG5E,CAAC;;AAGJ,IAAa,oBAAb,cAAuC,YAAY,mBAAmB,CAAC,CAIpE,CAAC;AA4CJ,MAAM,gBAAgB;AAEtB,MAAM,wBAAsC;CAC1C,MAAM,qBAAqB,cAAc,SAAS;CAElD,IAAI,uBAAuB,KAAA,GACzB,OAAO;CAGT,OAAO,cAAc,K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I,SAAS,SAAS,IAAI;CACjC;CAEA,KAAK,SAAiB,MAAyB;EAC7C,KAAK,IAAI,QAAQ,SAAS,IAAI;CAChC;CAEA,KAAK,SAAiB,MAAyB;EAC7C,KAAK,IAAI,QAAQ,SAAS,IAAI;CAChC;CAEA,MAAM,SAAiB,MAAyB;EAC9C,KAAK,IAAI,SAAS,SAAS,IAAI;CACjC;CAEA,QAAc;EACZ,KAAK,OAAO,SAAS;CACvB;CAEA,OAAO,OAAO;EACZ,MAAM,SAAS,IAAI,WAAW;EAC9B,OAAO;GAAE;GAAQ,OAAO,MAAM,QAAQ,QAAQ,MAAM;EAAE;CACxD;CAEA,OAAO,MAAM,SAAqB,IAAI,WAAW,GAAG;EAClD,OAAO,MAAM,QAAQ,QAAQ,MAAM;CACrC;AACF;AAEA,MAAa,wBAAwB,WAAW,MAAM;;AAGtD,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,3 +1,3 @@
|
|
|
1
|
-
import { d as CurrentAbortSignal } from "./index-
|
|
2
|
-
import { A as StandardSchemaV1, C as ConfigLive, D as ConfigSourceOptions, E as ConfigSourceError, O as ConfigValidationError, S as ConfigIssue, T as ConfigSource, _ as RandomSeededLayer, a as CurrentRequest, b as ConfigFromEnvOptions, c as LoggerData, d as LoggerLive, f as LoggerTest, g as RandomSeeded, h as RandomLive, i as ClockTestLayer, k as ConfigValue, l as LoggerEvent, m as Random, n as ClockLive, o as CurrentRequestLayer, p as LoggerTestLayer, r as ClockTest, s as Logger, t as Clock, u as LoggerLevel, v as Config, w as ConfigOutput, x as ConfigInput, y as ConfigError } from "./index-
|
|
1
|
+
import { d as CurrentAbortSignal } from "./index-BafDna0B.mjs";
|
|
2
|
+
import { A as StandardSchemaV1, C as ConfigLive, D as ConfigSourceOptions, E as ConfigSourceError, O as ConfigValidationError, S as ConfigIssue, T as ConfigSource, _ as RandomSeededLayer, a as CurrentRequest, b as ConfigFromEnvOptions, c as LoggerData, d as LoggerLive, f as LoggerTest, g as RandomSeeded, h as RandomLive, i as ClockTestLayer, k as ConfigValue, l as LoggerEvent, m as Random, n as ClockLive, o as CurrentRequestLayer, p as LoggerTestLayer, r as ClockTest, s as Logger, t as Clock, u as LoggerLevel, v as Config, w as ConfigOutput, x as ConfigInput, y as ConfigError } from "./index-DklNCz7w.mjs";
|
|
3
3
|
export { Clock, ClockLive, ClockTest, ClockTestLayer, Config, type ConfigError, type ConfigFromEnvOptions, type ConfigInput, type ConfigIssue, ConfigLive, type ConfigOutput, type ConfigSource, ConfigSourceError, type ConfigSourceOptions, ConfigValidationError, type ConfigValue, CurrentAbortSignal, CurrentRequest, CurrentRequestLayer, Logger, LoggerData, LoggerEvent, LoggerLevel, LoggerLive, LoggerTest, LoggerTestLayer, Random, RandomLive, RandomSeeded, RandomSeededLayer, type StandardSchemaV1 };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { t as CurrentAbortSignal } from "./signal-
|
|
2
|
-
import { _ as ConfigSourceError, a as CurrentRequest, c as LoggerLive, d as Random, f as RandomLive, g as ConfigLive, h as Config, i as ClockTestLayer, l as LoggerTest, m as RandomSeededLayer, n as ClockLive, o as CurrentRequestLayer, p as RandomSeeded, r as ClockTest, s as Logger, t as Clock, u as LoggerTestLayer, v as ConfigValidationError } from "./standard-services-
|
|
1
|
+
import { t as CurrentAbortSignal } from "./signal-C1bagvrO.mjs";
|
|
2
|
+
import { _ as ConfigSourceError, a as CurrentRequest, c as LoggerLive, d as Random, f as RandomLive, g as ConfigLive, h as Config, i as ClockTestLayer, l as LoggerTest, m as RandomSeededLayer, n as ClockLive, o as CurrentRequestLayer, p as RandomSeeded, r as ClockTest, s as Logger, t as Clock, u as LoggerTestLayer, v as ConfigValidationError } from "./standard-services-DW-i4UuA.mjs";
|
|
3
3
|
export { Clock, ClockLive, ClockTest, ClockTestLayer, Config, ConfigLive, ConfigSourceError, ConfigValidationError, CurrentAbortSignal, CurrentRequest, CurrentRequestLayer, Logger, LoggerLive, LoggerTest, LoggerTestLayer, Random, RandomLive, RandomSeeded, RandomSeededLayer };
|
package/dist/testing.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as MapLayerBackend } from "./map-layer-backend-
|
|
1
|
+
import { t as MapLayerBackend } from "./map-layer-backend-rNwfH0Bz.mjs";
|
|
2
2
|
export { MapLayerBackend as MemoryLayerBackend };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "better-effect",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Effect-inspired application architecture for better-result with typechecked Services and environments, scoped resource lifetimes, and pluggable DI backends.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"better-result",
|
|
@@ -21,7 +21,9 @@
|
|
|
21
21
|
"url": "git+https://github.com/nitoba/better-effect.git"
|
|
22
22
|
},
|
|
23
23
|
"files": [
|
|
24
|
-
"dist"
|
|
24
|
+
"dist",
|
|
25
|
+
"LICENSE",
|
|
26
|
+
"README.md"
|
|
25
27
|
],
|
|
26
28
|
"type": "module",
|
|
27
29
|
"sideEffects": false,
|
|
@@ -55,12 +57,13 @@
|
|
|
55
57
|
"lint": "oxlint --type-aware .",
|
|
56
58
|
"lint:fix": "oxlint --type-aware --fix .",
|
|
57
59
|
"format": "oxfmt --write .",
|
|
60
|
+
"format:check": "oxfmt --check .",
|
|
58
61
|
"publint": "publint",
|
|
59
62
|
"check:public-type-namespaces": "bun run test:package-types && bun run test:package-types:minimum && bun tests/package/public-type-namespaces/check.ts",
|
|
60
63
|
"check:standard-services": "bun run test:package-standard-services && bun run test:package-standard-services:minimum",
|
|
61
64
|
"check:public-type-variance": "bun run test:package-variance && bun run test:package-variance:minimum && bun tests/package/public-type-variance/check.ts",
|
|
62
65
|
"check:instance-requirements": "bun tests/package/instance-requirements/check.ts",
|
|
63
|
-
"check": "bun run typecheck && bun test && bun run format && bun run build && bun run check:public-type-namespaces && bun run check:standard-services && bun run check:public-type-variance && bun run check:instance-requirements && bun run publint && bun run lint",
|
|
66
|
+
"check": "bun run typecheck && bun test && bun run format:check && bun run build && bun run check:public-type-namespaces && bun run check:standard-services && bun run check:public-type-variance && bun run check:instance-requirements && bun run publint && bun run lint",
|
|
64
67
|
"prepublishOnly": "bun run check",
|
|
65
68
|
"release:dry": "bun publish --dry-run"
|
|
66
69
|
},
|