better-effect 0.12.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 +599 -30
- 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 +95 -0
- package/dist/bun.d.mts.map +1 -0
- package/dist/bun.mjs +177 -0
- package/dist/bun.mjs.map +1 -0
- package/dist/{context-BUEf1qjL.mjs → context-DSGSqcJj.mjs} +14 -3
- package/dist/context-DSGSqcJj.mjs.map +1 -0
- package/dist/current-request-Bc1YHL0w.mjs +21 -0
- package/dist/current-request-Bc1YHL0w.mjs.map +1 -0
- package/dist/current-request-Dm-QQ3Xr.d.mts +22 -0
- package/dist/current-request-Dm-QQ3Xr.d.mts.map +1 -0
- package/dist/{effect-CK4YZaX0.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 +65 -27
- package/dist/hono.d.mts.map +1 -1
- package/dist/hono.mjs +177 -53
- package/dist/hono.mjs.map +1 -1
- package/dist/{index-CX6iAoCB.d.mts → index-3Bkl-sxS.d.mts} +7 -2
- package/dist/{index-CX6iAoCB.d.mts.map → index-3Bkl-sxS.d.mts.map} +1 -1
- package/dist/{index-B1nH4luq.d.mts → index-C2ed9Ilq.d.mts} +32 -21
- package/dist/index-C2ed9Ilq.d.mts.map +1 -0
- package/dist/{index-GYJ4qm9K.d.mts → index-ClNndn2-.d.mts} +93 -62
- package/dist/index-ClNndn2-.d.mts.map +1 -0
- package/dist/{index-BMdU_Z72.d.mts → index-Cy1VsU-u.d.mts} +2 -3
- package/dist/index-Cy1VsU-u.d.mts.map +1 -0
- package/dist/index.d.mts +6 -7
- package/dist/index.mjs +8 -8
- 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/{outcome-CB43bnFW.d.mts → layer-C2OaqTmB.d.mts} +683 -138
- package/dist/layer-C2OaqTmB.d.mts.map +1 -0
- package/dist/next.d.mts +192 -0
- package/dist/next.d.mts.map +1 -0
- package/dist/next.mjs +185 -0
- package/dist/next.mjs.map +1 -0
- package/dist/{node-context-DWsCUBRa.d.mts → node-context-1YEjrU9g.d.mts} +2 -2
- package/dist/{node-context-DWsCUBRa.d.mts.map → node-context-1YEjrU9g.d.mts.map} +1 -1
- package/dist/{node-context-lggRF4bR.mjs → node-context-g3bCcY9t.mjs} +2 -2
- package/dist/{node-context-lggRF4bR.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 +112 -0
- package/dist/opentelemetry.d.mts.map +1 -0
- package/dist/opentelemetry.mjs +871 -0
- package/dist/opentelemetry.mjs.map +1 -0
- 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-5Rg9bUUe.mjs +52 -0
- package/dist/signal-5Rg9bUUe.mjs.map +1 -0
- package/dist/{standard-services-GBZ32tll.mjs → standard-services-B-iMM_W7.mjs} +39 -19
- package/dist/standard-services-B-iMM_W7.mjs.map +1 -0
- package/dist/standard-services.d.mts +4 -3
- package/dist/standard-services.mjs +3 -2
- package/dist/testing.d.mts +25 -6
- package/dist/testing.d.mts.map +1 -1
- package/dist/testing.mjs +51 -7
- package/dist/testing.mjs.map +1 -1
- package/dist/types-BFTqCCcw.d.mts +81 -0
- 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 +56 -0
- package/dist/web.d.mts.map +1 -0
- package/dist/web.mjs +2 -0
- package/package.json +36 -11
- package/dist/context-BUEf1qjL.mjs.map +0 -1
- package/dist/effect-CK4YZaX0.mjs.map +0 -1
- package/dist/errors-BKcsQ0ip.d.mts.map +0 -1
- package/dist/index-B1nH4luq.d.mts.map +0 -1
- package/dist/index-BMdU_Z72.d.mts.map +0 -1
- package/dist/index-GYJ4qm9K.d.mts.map +0 -1
- package/dist/index-heuaRmXR.d.mts +0 -374
- package/dist/index-heuaRmXR.d.mts.map +0 -1
- package/dist/layer-D56fRdLt.mjs +0 -269
- package/dist/layer-D56fRdLt.mjs.map +0 -1
- package/dist/outcome-CB43bnFW.d.mts.map +0 -1
- package/dist/program-metadata-DhQCCirO.mjs +0 -260
- package/dist/program-metadata-DhQCCirO.mjs.map +0 -1
- package/dist/registration-drnZk0SY.mjs.map +0 -1
- package/dist/runtime-CBMrX8Wl.mjs +0 -776
- package/dist/runtime-CBMrX8Wl.mjs.map +0 -1
- package/dist/signal-D2UTcaaG.mjs +0 -105
- package/dist/signal-D2UTcaaG.mjs.map +0 -1
- package/dist/standard-services-GBZ32tll.mjs.map +0 -1
package/dist/hono.mjs
CHANGED
|
@@ -1,11 +1,73 @@
|
|
|
1
|
-
import { t as Layer } from "./layer-
|
|
2
|
-
import { t as
|
|
3
|
-
import {
|
|
1
|
+
import { 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 Effect } from "./effect-W0IQXY8P.mjs";
|
|
5
|
+
import { a as assertResponse, n as makeManagedResponse, r as runManagedWith } from "./web-effect-B9hp9jIe.mjs";
|
|
4
6
|
import { Result } from "better-result";
|
|
5
7
|
import { createMiddleware } from "hono/factory";
|
|
6
8
|
//#region src/hono/request-boundary.ts
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
+
const recordRequestFailure = (state, cause) => {
|
|
10
|
+
state.outcome ??= {
|
|
11
|
+
kind: "failure",
|
|
12
|
+
cause
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
const recordRequestSuccess = (state, value, options) => {
|
|
16
|
+
state.outcome ??= {
|
|
17
|
+
kind: "success",
|
|
18
|
+
value,
|
|
19
|
+
options
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
const recordRequestStream = (state, descriptor, options) => {
|
|
23
|
+
state.outcome ??= {
|
|
24
|
+
kind: "stream",
|
|
25
|
+
descriptor,
|
|
26
|
+
options
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
const responsePlan = (response) => {
|
|
30
|
+
const readiness = Promise.resolve(response).then((value) => assertResponse(value));
|
|
31
|
+
return {
|
|
32
|
+
readiness,
|
|
33
|
+
completion: readiness.then(() => void 0),
|
|
34
|
+
cancel: async () => {}
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
const makeBoundaryOptions = (options, state, context) => {
|
|
38
|
+
const boundaryOptions = {
|
|
39
|
+
onSuccess: ({ value }, managed) => {
|
|
40
|
+
if (context.finalized) return responsePlan(context.res);
|
|
41
|
+
const outcome = state.outcome;
|
|
42
|
+
if (outcome?.kind === "stream") return makeManagedResponse(outcome.descriptor, managed, outcome.options.unconsumedTimeoutMs);
|
|
43
|
+
if (outcome?.kind !== "success") return responsePlan(value);
|
|
44
|
+
if (outcome.options.respond !== void 0) return responsePlan(outcome.options.respond(value, context));
|
|
45
|
+
const success = { value };
|
|
46
|
+
if (outcome.options.status !== void 0) Object.assign(success, { status: outcome.options.status });
|
|
47
|
+
if (outcome.options.serialize !== void 0) Object.assign(success, { serialize: outcome.options.serialize });
|
|
48
|
+
return responsePlan(options.onSuccess(success, context));
|
|
49
|
+
},
|
|
50
|
+
onFailure: (error) => {
|
|
51
|
+
if (context.error !== void 0 || context.finalized) return context.res;
|
|
52
|
+
if (state.outcome?.kind === "defect") return context.res;
|
|
53
|
+
return options.onFailure(error, context);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
if (options.requestLayer !== void 0) Object.assign(boundaryOptions, { requestLayer: (_request) => options.requestLayer(context) });
|
|
57
|
+
return boundaryOptions;
|
|
58
|
+
};
|
|
59
|
+
const selectBoundaryResult = (state, context) => {
|
|
60
|
+
const outcome = state.outcome;
|
|
61
|
+
if (outcome?.kind === "failure") return Result.err(outcome.cause);
|
|
62
|
+
if (context.error !== void 0) {
|
|
63
|
+
state.outcome = {
|
|
64
|
+
kind: "defect",
|
|
65
|
+
cause: context.error
|
|
66
|
+
};
|
|
67
|
+
return Result.err(context.error);
|
|
68
|
+
}
|
|
69
|
+
if (outcome?.kind === "success") return Result.ok(outcome.value);
|
|
70
|
+
return Result.ok(context.res);
|
|
9
71
|
};
|
|
10
72
|
const makeRequestBoundary = (options) => {
|
|
11
73
|
return createMiddleware(async (context, next) => {
|
|
@@ -17,19 +79,14 @@ const makeRequestBoundary = (options) => {
|
|
|
17
79
|
const state = {};
|
|
18
80
|
options.states.set(key, state);
|
|
19
81
|
try {
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
if (state.failure !== void 0) return Result.err(state.failure.cause);
|
|
30
|
-
if (context.error !== void 0) return Result.err(context.error);
|
|
31
|
-
return Result.ok(context.res);
|
|
32
|
-
}, { signal: context.req.raw.signal });
|
|
82
|
+
const program = Effect.fn(async function* () {
|
|
83
|
+
await next();
|
|
84
|
+
return selectBoundaryResult(state, context);
|
|
85
|
+
});
|
|
86
|
+
const boundaryOptions = makeBoundaryOptions(options, state, context);
|
|
87
|
+
let response;
|
|
88
|
+
response = await runManagedWith(options.executor, context.req.raw, program, boundaryOptions);
|
|
89
|
+
if (!context.finalized || context.res !== response) context.res = response;
|
|
33
90
|
} finally {
|
|
34
91
|
options.states.delete(key);
|
|
35
92
|
}
|
|
@@ -50,29 +107,37 @@ const defaultFailure = (error, context) => {
|
|
|
50
107
|
return context.json({ error: DEFAULT_FAILURE_MESSAGE }, 500);
|
|
51
108
|
};
|
|
52
109
|
//#endregion
|
|
53
|
-
//#region src/hono/
|
|
54
|
-
/**
|
|
55
|
-
|
|
56
|
-
|
|
110
|
+
//#region src/hono/builder.ts
|
|
111
|
+
/** Capture the active Runtime executor while a Hono application Layer is acquired. */
|
|
112
|
+
const makeOperation = (factory) => ({
|
|
113
|
+
*[Symbol.iterator]() {
|
|
114
|
+
const executor = yield* Runtime.executor();
|
|
115
|
+
return factory(eraseRuntimeExecutor(executor));
|
|
116
|
+
},
|
|
117
|
+
async *[Symbol.asyncIterator]() {
|
|
118
|
+
const executor = yield* Runtime.executor();
|
|
119
|
+
return factory(eraseRuntimeExecutor(executor));
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
/** Build Hono-native handlers whose Runtime capability is captured by the app Layer. */
|
|
123
|
+
var HonoEffectBuilder = class {
|
|
57
124
|
states = /* @__PURE__ */ new WeakMap();
|
|
58
125
|
onSuccess;
|
|
59
126
|
onFailure;
|
|
60
127
|
requestLayer;
|
|
61
|
-
constructor(
|
|
62
|
-
this.runtime = runtime;
|
|
128
|
+
constructor(options) {
|
|
63
129
|
this.onSuccess = options.onSuccess ?? defaultSuccess;
|
|
64
130
|
this.onFailure = options.onFailure ?? defaultFailure;
|
|
65
131
|
this.requestLayer = options.requestLayer;
|
|
66
132
|
}
|
|
67
|
-
static make(runtime, options) {
|
|
68
|
-
return new HonoEffect(runtime, options ?? {});
|
|
69
|
-
}
|
|
70
133
|
middleware() {
|
|
71
|
-
return makeRequestBoundary({
|
|
72
|
-
|
|
134
|
+
return makeOperation((executor) => makeRequestBoundary({
|
|
135
|
+
executor,
|
|
73
136
|
states: this.states,
|
|
74
|
-
requestLayer: this.requestLayer
|
|
75
|
-
|
|
137
|
+
requestLayer: this.requestLayer,
|
|
138
|
+
onSuccess: this.onSuccess,
|
|
139
|
+
onFailure: this.onFailure
|
|
140
|
+
}));
|
|
76
141
|
}
|
|
77
142
|
handler(...args) {
|
|
78
143
|
const last = args.at(-1);
|
|
@@ -80,9 +145,11 @@ var HonoEffect = class HonoEffect {
|
|
|
80
145
|
const options = (hasOptions ? last : {}) ?? {};
|
|
81
146
|
const bodyIndex = hasOptions ? args.length - 2 : args.length - 1;
|
|
82
147
|
const makeProgram = args[bodyIndex];
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
148
|
+
return makeOperation(() => {
|
|
149
|
+
let handler = this.makeHandler(makeProgram, options);
|
|
150
|
+
for (let index = bodyIndex - 1; index >= 0; index -= 1) handler = this.composeInputMiddleware(args[index], handler);
|
|
151
|
+
return handler;
|
|
152
|
+
});
|
|
86
153
|
}
|
|
87
154
|
gen(...args) {
|
|
88
155
|
const last = args.at(-1);
|
|
@@ -90,37 +157,62 @@ var HonoEffect = class HonoEffect {
|
|
|
90
157
|
const options = (hasOptions ? last : {}) ?? {};
|
|
91
158
|
const bodyIndex = hasOptions ? args.length - 2 : args.length - 1;
|
|
92
159
|
const body = args[bodyIndex];
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
160
|
+
return makeOperation(() => {
|
|
161
|
+
let handler = this.makeHandler((context) => {
|
|
162
|
+
return Effect.fn(() => body(context));
|
|
163
|
+
}, options);
|
|
164
|
+
for (let index = bodyIndex - 1; index >= 0; index -= 1) handler = this.composeInputMiddleware(args[index], handler);
|
|
165
|
+
return handler;
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
stream(...args) {
|
|
169
|
+
const last = args.at(-1);
|
|
170
|
+
const hasOptions = args.length > 1 && (last === void 0 || typeof last !== "function");
|
|
171
|
+
const options = (hasOptions ? last : {}) ?? {};
|
|
172
|
+
const programIndex = hasOptions ? args.length - 2 : args.length - 1;
|
|
173
|
+
const streamProgram = args[programIndex];
|
|
174
|
+
return makeOperation(() => {
|
|
175
|
+
let handler = this.makeStreamHandler(streamProgram, options);
|
|
176
|
+
for (let index = programIndex - 1; index >= 0; index -= 1) handler = this.composeInputMiddleware(args[index], handler);
|
|
177
|
+
return handler;
|
|
178
|
+
});
|
|
98
179
|
}
|
|
99
180
|
guard(body) {
|
|
100
|
-
return async (context, next) => {
|
|
181
|
+
return makeOperation(() => async (context, next) => {
|
|
101
182
|
const state = this.getState(context);
|
|
102
183
|
const result = await Effect.fn(() => body(context))();
|
|
103
184
|
if (Result.isError(result)) return await this.handleFailure(state, result.error, context);
|
|
104
185
|
await next();
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
handleFailure(state, error, context) {
|
|
108
|
-
state.failure ??= { cause: error };
|
|
109
|
-
return this.onFailure(error, context);
|
|
186
|
+
});
|
|
110
187
|
}
|
|
111
188
|
makeHandler(makeProgram, options) {
|
|
112
189
|
return async (context) => {
|
|
113
190
|
const state = this.getState(context);
|
|
114
191
|
const result = await makeProgram(context)();
|
|
115
192
|
if (Result.isError(result)) return await this.handleFailure(state, result.error, context);
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
193
|
+
recordRequestSuccess(state, result.value, options);
|
|
194
|
+
return await this.handleSuccess(result.value, options, context);
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
makeStreamHandler(streamProgram, options) {
|
|
198
|
+
return async (context) => {
|
|
199
|
+
const state = this.getState(context);
|
|
200
|
+
const result = await streamProgram();
|
|
201
|
+
if (Result.isError(result)) return await this.handleFailure(state, result.error, context);
|
|
202
|
+
recordRequestStream(state, result.value, options);
|
|
122
203
|
};
|
|
123
204
|
}
|
|
205
|
+
async handleSuccess(value, options, context) {
|
|
206
|
+
if (options.respond !== void 0) return assertResponse(await options.respond(value, context));
|
|
207
|
+
const success = { value };
|
|
208
|
+
if (options.status !== void 0) Object.assign(success, { status: options.status });
|
|
209
|
+
if (options.serialize !== void 0) Object.assign(success, { serialize: options.serialize });
|
|
210
|
+
return assertResponse(await this.onSuccess(success, context));
|
|
211
|
+
}
|
|
212
|
+
async handleFailure(state, error, context) {
|
|
213
|
+
recordRequestFailure(state, error);
|
|
214
|
+
return assertResponse(await this.onFailure(error, context));
|
|
215
|
+
}
|
|
124
216
|
composeInputMiddleware(inputMiddleware, handler) {
|
|
125
217
|
return async (context, next) => {
|
|
126
218
|
let downstreamResponse;
|
|
@@ -128,12 +220,13 @@ var HonoEffect = class HonoEffect {
|
|
|
128
220
|
const nextOnce = async () => {
|
|
129
221
|
if (nextCalled) throw new Error("next() called multiple times");
|
|
130
222
|
nextCalled = true;
|
|
131
|
-
|
|
223
|
+
const response = await handler(context, next);
|
|
224
|
+
if (response !== void 0) downstreamResponse = response;
|
|
132
225
|
};
|
|
133
226
|
const middlewareResponse = await inputMiddleware(context, nextOnce);
|
|
134
227
|
if (middlewareResponse instanceof Response) return middlewareResponse;
|
|
135
228
|
if (downstreamResponse !== void 0) return downstreamResponse;
|
|
136
|
-
return context.res;
|
|
229
|
+
if (context.finalized) return context.res;
|
|
137
230
|
};
|
|
138
231
|
}
|
|
139
232
|
getState(context) {
|
|
@@ -149,6 +242,37 @@ var HonoEffectBoundaryMissingError = class extends Error {
|
|
|
149
242
|
}
|
|
150
243
|
};
|
|
151
244
|
//#endregion
|
|
245
|
+
//#region src/hono/hono-effect.ts
|
|
246
|
+
const defineLayerProperty = (token, layer) => {
|
|
247
|
+
Object.defineProperty(token, "layer", {
|
|
248
|
+
configurable: false,
|
|
249
|
+
enumerable: true,
|
|
250
|
+
value: layer,
|
|
251
|
+
writable: false
|
|
252
|
+
});
|
|
253
|
+
return token;
|
|
254
|
+
};
|
|
255
|
+
const makeHonoLayer = (service, options, factory) => {
|
|
256
|
+
return Layer.gen(service, () => {
|
|
257
|
+
return factory(new HonoEffectBuilder(options));
|
|
258
|
+
});
|
|
259
|
+
};
|
|
260
|
+
/** Layer-first Hono integration. The application owns the Runtime composition. */
|
|
261
|
+
var HonoEffect = class {
|
|
262
|
+
constructor() {}
|
|
263
|
+
/** Create a yieldable Hono application token and its Layer. */
|
|
264
|
+
static app(tag, options, factory) {
|
|
265
|
+
const literalTag = tag;
|
|
266
|
+
const token = Service()(literalTag);
|
|
267
|
+
const layer = makeHonoLayer(token, options, factory);
|
|
268
|
+
return defineLayerProperty(token, layer);
|
|
269
|
+
}
|
|
270
|
+
/** Provide an application-chosen Service token with a Hono Layer. */
|
|
271
|
+
static layer(service, options, factory) {
|
|
272
|
+
return makeHonoLayer(service, options, factory);
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
//#endregion
|
|
152
276
|
export { HonoEffect, HonoEffectBoundaryMissingError };
|
|
153
277
|
|
|
154
278
|
//# sourceMappingURL=hono.mjs.map
|
package/dist/hono.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hono.mjs","names":[],"sources":["../src/hono/request-boundary.ts","../src/hono/responses.ts","../src/hono/hono-effect.ts"],"sourcesContent":["import { Result } from 'better-result'\nimport { createMiddleware } from 'hono/factory'\nimport type { Env, MiddlewareHandler } from 'hono'\n\nimport { CurrentRequest } from '../standard-services'\nimport { Layer } from '../layer'\nimport type { LayerInput } from '../layer/inference'\nimport { Runtime } from '../runtime'\nimport type { AnyService } from '../service'\nimport type { HonoContext } from './types'\n\nexport type RequestState = {\n failure?: {\n readonly cause: unknown\n }\n}\n\nexport type RequestBoundaryOptions<Provided extends AnyService, RequestLayer extends LayerInput> = {\n readonly runtime: Runtime<Provided>\n readonly states: WeakMap<object, RequestState>\n readonly requestLayer?: ((context: HonoContext) => RequestLayer) | undefined\n}\n\nconst overrideRequestLayer = (base: LayerInput, replacement: LayerInput): Layer<any, any> => {\n // SAFETY: HonoEffect.make validates the concrete replacement before this erased dispatch boundary.\n return Layer.override(base, replacement as never)\n}\n\nexport const makeRequestBoundary = <\n Provided extends AnyService,\n RequestLayer extends LayerInput,\n E extends Env = Env,\n Path extends string = string\n>(\n options: RequestBoundaryOptions<Provided, RequestLayer>\n): MiddlewareHandler<E, Path> => {\n // SAFETY: createMiddleware preserves the Hono handler contract; only the generic Context is restored here.\n return createMiddleware(async (context, next) => {\n const key = context\n const existing = options.states.get(key)\n\n if (existing !== undefined) {\n await next()\n return\n }\n\n const state: RequestState = {}\n options.states.set(key, state)\n\n try {\n const requestLayer = CurrentRequest.layer(context.req.raw)\n const customLayer = options.requestLayer?.(context)\n const layer: Layer<any, any> =\n customLayer === undefined ? requestLayer : overrideRequestLayer(requestLayer, customLayer)\n\n await options.runtime.runWith(\n layer,\n async () => {\n try {\n await next()\n } catch (cause) {\n state.failure ??= { cause }\n }\n\n if (state.failure !== undefined) {\n return Result.err(state.failure.cause)\n }\n\n if (context.error !== undefined) {\n return Result.err(context.error)\n }\n\n return Result.ok(context.res)\n },\n { signal: context.req.raw.signal }\n )\n } finally {\n options.states.delete(key)\n }\n }) as MiddlewareHandler<E, Path>\n}\n","import type { HonoContext, HonoEffectSuccess } from './types'\n\nconst DEFAULT_FAILURE_MESSAGE = 'Internal Server Error'\n\nexport const defaultSuccess = (\n { value, status, serialize }: HonoEffectSuccess,\n context: HonoContext\n): Response => {\n if (value instanceof Response) {\n return value\n }\n\n const body = serialize === undefined ? value : serialize(value)\n\n if (body === undefined) {\n // SAFETY: route status is intentionally configurable and Hono validates it at response construction.\n return context.body(null, (status ?? 204) as never)\n }\n\n if (status === undefined) {\n return context.json({ data: body })\n }\n\n // SAFETY: route status is intentionally configurable and Hono validates it at response construction.\n return context.json({ data: body }, status as never)\n}\n\n// oxlint-disable-next-line anti-slop/no-unknown-parameters -- Result errors are intentionally opaque at this HTTP boundary.\nexport const defaultFailure = (error: unknown, context: HonoContext): Response => {\n if (error instanceof Response) {\n return error\n }\n\n return context.json({ error: DEFAULT_FAILURE_MESSAGE }, 500)\n}\n","import { Result } from 'better-result'\nimport type { Context, Env, Handler, Input, MiddlewareHandler } from 'hono'\n\nimport { Effect } from '../effect'\nimport type { EffectSuccess, EffectYield, ProgramFromGenerator } from '../effect/types'\nimport { Runtime } from '../runtime'\nimport type { LayerInput } from '../layer/inference'\nimport type { AnyService } from '../service'\nimport { makeRequestBoundary, type RequestState } from './request-boundary'\nimport { defaultFailure, defaultSuccess } from './responses'\nimport type {\n AnyGeneratorBody,\n AnyHonoMiddleware,\n AnyProgram,\n AnyProgramFactory,\n AnyResult,\n AnyRouteOptions,\n AvailableServices,\n CompleteProgram,\n DefaultRequestLayer,\n GeneratorBody,\n GeneratorChecks,\n HonoContext,\n HonoEffectContext,\n HonoEffectOptions,\n HonoEffectRouteOptions,\n HonoRequestLayerChecks,\n HonoEffectSuccess,\n MiddlewareEnvironment,\n ResponseLike,\n MiddlewareInputs,\n MiddlewarePath\n} from './types'\n\ntype HonoRouteArguments<Middlewares extends readonly AnyHonoMiddleware[], Body, Options> =\n | [...middlewares: Middlewares, body: Body]\n | [...middlewares: Middlewares, body: Body, options: Options | undefined]\n\ntype HonoHandlerFactory<\n ContextType extends object,\n Provided extends AnyService,\n Failure,\n ProgramFactory extends (context: ContextType) => AnyProgram\n> = ProgramFactory &\n ([ReturnType<ProgramFactory>] extends [\n CompleteProgram<Provided, ReturnType<ProgramFactory>, Failure>\n ]\n ? unknown\n : (context: ContextType) => CompleteProgram<Provided, ReturnType<ProgramFactory>, Failure>)\n\n/** Run Effect Programs inside one Runtime execution per Hono request. */\nexport class HonoEffect<\n Provided extends AnyService = any,\n Failure = unknown,\n RequestLayer extends LayerInput = DefaultRequestLayer\n> {\n readonly runtime: Runtime<Provided>\n\n private readonly states = new WeakMap<object, RequestState>()\n\n private readonly onSuccess: NonNullable<HonoEffectOptions<Failure, RequestLayer>['onSuccess']>\n\n private readonly onFailure: NonNullable<HonoEffectOptions<Failure, RequestLayer>['onFailure']>\n\n private readonly requestLayer: HonoEffectOptions<Failure, RequestLayer>['requestLayer']\n\n private constructor(\n runtime: Runtime<Provided>,\n options: HonoEffectOptions<Failure, RequestLayer>\n ) {\n this.runtime = runtime\n this.onSuccess = options.onSuccess ?? defaultSuccess\n this.onFailure = options.onFailure ?? defaultFailure\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?: HonoEffectOptions<Failure, RequestLayer> &\n HonoRequestLayerChecks<Provided, RequestLayer>\n ): HonoEffect<Provided, Failure, RequestLayer> {\n return new HonoEffect(runtime, options ?? {})\n }\n\n middleware<E extends Env = Env, Path extends string = string>(): MiddlewareHandler<E, Path> {\n return makeRequestBoundary<Provided, RequestLayer, E, Path>({\n runtime: this.runtime,\n states: this.states,\n requestLayer: this.requestLayer\n })\n }\n\n handler<\n E extends Env = Env,\n Path extends string = string,\n InputType extends Input = Input,\n Program extends AnyProgram = AnyProgram\n >(\n makeProgram: (\n context: Context<E, Path, InputType>\n ) => CompleteProgram<AvailableServices<Provided, RequestLayer>, Program, Failure>,\n options?: HonoEffectRouteOptions<EffectSuccess<Program>, Context<E, Path, InputType>>\n ): Handler<E, Path, InputType, Promise<Response>>\n handler<\n const Middlewares extends readonly AnyHonoMiddleware[],\n E extends Env = MiddlewareEnvironment<Middlewares>,\n Path extends string = MiddlewarePath<Middlewares>,\n const ProgramFactory extends (\n context: HonoEffectContext<E, Path, MiddlewareInputs<Middlewares>>\n ) => AnyProgram = (\n context: HonoEffectContext<E, Path, MiddlewareInputs<Middlewares>>\n ) => AnyProgram\n >(\n ...args: HonoRouteArguments<\n Middlewares,\n HonoHandlerFactory<\n HonoEffectContext<E, Path, MiddlewareInputs<Middlewares>>,\n AvailableServices<Provided, RequestLayer>,\n Failure,\n ProgramFactory\n >,\n HonoEffectRouteOptions<\n EffectSuccess<ReturnType<ProgramFactory>>,\n Context<E, Path, MiddlewareInputs<Middlewares>>\n >\n >\n ): Handler<E, Path, MiddlewareInputs<Middlewares>, Promise<Response>>\n handler(...args: unknown[]): Handler<any, any, any, Promise<Response>> {\n const last = args.at(-1)\n // oxlint-disable-next-line anti-slop/no-runtime-typeof -- overload dispatch separates route options from function callbacks.\n const hasOptions = args.length > 1 && (last === undefined || typeof last !== 'function')\n // SAFETY: the overloads restrict the optional trailing argument to route options.\n const options = ((hasOptions ? last : {}) ?? {}) as AnyRouteOptions\n const bodyIndex = hasOptions ? args.length - 2 : args.length - 1\n // SAFETY: the overloads place the program factory immediately before route options.\n const makeProgram = args[bodyIndex] as AnyProgramFactory\n let handler = this.makeHandler(makeProgram, options)\n\n for (let index = bodyIndex - 1; index >= 0; index -= 1) {\n // SAFETY: every argument before the program factory is an input middleware by the overloads.\n handler = this.composeInputMiddleware(args[index] as AnyHonoMiddleware, handler)\n }\n\n return handler\n }\n\n gen<\n E extends Env = Env,\n Path extends string = string,\n InputType extends Input = Input,\n const Yield extends EffectYield = EffectYield,\n const Returned extends AnyResult = AnyResult\n >(\n body: GeneratorBody<Context<E, Path, InputType>, Yield, Returned> &\n GeneratorChecks<AvailableServices<Provided, RequestLayer>, Yield, Returned, Failure>,\n options?: HonoEffectRouteOptions<\n EffectSuccess<ProgramFromGenerator<Yield, Returned>>,\n Context<E, Path, InputType>\n >\n ): Handler<E, Path, InputType, Promise<Response>>\n gen<\n const Middlewares extends readonly AnyHonoMiddleware[],\n E extends Env = MiddlewareEnvironment<Middlewares>,\n Path extends string = MiddlewarePath<Middlewares>,\n const Yield extends EffectYield = EffectYield,\n const Returned extends AnyResult = AnyResult\n >(\n ...args: HonoRouteArguments<\n Middlewares,\n GeneratorBody<HonoEffectContext<E, Path, MiddlewareInputs<Middlewares>>, Yield, Returned> &\n GeneratorChecks<AvailableServices<Provided, RequestLayer>, Yield, Returned, Failure>,\n HonoEffectRouteOptions<\n EffectSuccess<ProgramFromGenerator<Yield, Returned>>,\n Context<E, Path, MiddlewareInputs<Middlewares>>\n >\n >\n ): Handler<E, Path, MiddlewareInputs<Middlewares>, Promise<Response>>\n gen(...args: unknown[]): Handler<any, any, any, Promise<Response>> {\n // oxlint-disable-next-line anti-slop/no-runtime-typeof -- overload dispatch distinguishes middleware from the generator body.\n const last = args.at(-1)\n // oxlint-disable-next-line anti-slop/no-runtime-typeof -- overload dispatch separates route options from function callbacks.\n const hasOptions = args.length > 1 && (last === undefined || typeof last !== 'function')\n // SAFETY: the overloads restrict the optional trailing argument to route options.\n const options = ((hasOptions ? last : {}) ?? {}) as AnyRouteOptions\n const bodyIndex = hasOptions ? args.length - 2 : args.length - 1\n // SAFETY: the overloads place the generator body immediately before route options.\n const body = args[bodyIndex] as AnyGeneratorBody\n\n let handler = this.makeHandler((context) => {\n // SAFETY: Effect.fn's runtime generator accepts both sync and async generators; the cast only joins its overloads.\n const program = Effect.fn(\n () => body(context) as AsyncGenerator<EffectYield, AnyResult, unknown>\n )\n\n // SAFETY: the public GeneratorChecks overload validates requirements before this erased boundary.\n return program as AnyProgram\n }, options)\n\n for (let index = bodyIndex - 1; index >= 0; index -= 1) {\n // SAFETY: every argument before the generator body is an input middleware by the overloads.\n handler = this.composeInputMiddleware(args[index] as AnyHonoMiddleware, handler)\n }\n\n return handler\n }\n\n guard<\n E extends Env = Env,\n Path extends string = string,\n InputType extends Input = Input,\n const Yield extends EffectYield = EffectYield,\n const Returned extends AnyResult = AnyResult\n >(\n body: GeneratorBody<Context<E, Path, InputType>, Yield, Returned> &\n GeneratorChecks<AvailableServices<Provided, RequestLayer>, Yield, Returned, Failure>\n ): MiddlewareHandler<E, Path> {\n return async (context, next) => {\n const state = this.getState(context)\n // SAFETY: Effect.fn accepts the sync or async generator supplied by the caller; this joins its overloads.\n const program = Effect.fn(() => body(context) as AsyncGenerator<Yield, Returned, unknown>)\n const result = await program()\n\n if (Result.isError(result)) {\n return await this.handleFailure(state, result.error, context)\n }\n\n await next()\n }\n }\n\n private handleFailure(\n state: RequestState,\n // oxlint-disable-next-line anti-slop/no-unknown-parameters -- Result errors are intentionally opaque at this HTTP boundary.\n error: unknown,\n context: HonoContext\n ): ResponseLike {\n state.failure ??= { cause: error }\n // SAFETY: the public handler, gen, and guard constraints validate this error against Failure.\n return this.onFailure(error as Failure, context)\n }\n\n private makeHandler(\n makeProgram: (context: HonoContext) => AnyProgram,\n options: HonoEffectRouteOptions<any, any>\n ): Handler<any, any, any, Promise<Response>> {\n return async (context) => {\n const state = this.getState(context)\n const program = makeProgram(context)\n const result = await program()\n\n if (Result.isError(result)) {\n return await this.handleFailure(state, result.error, context)\n }\n\n const value = result.value\n\n if (options.respond !== undefined) {\n return await options.respond(value, context)\n }\n\n const success: HonoEffectSuccess<any> = { value }\n\n if (options.status !== undefined) {\n Object.assign(success, { status: options.status })\n }\n\n if (options.serialize !== undefined) {\n Object.assign(success, { serialize: options.serialize })\n }\n\n return await this.onSuccess(success, context)\n }\n }\n\n private composeInputMiddleware(\n inputMiddleware: AnyHonoMiddleware,\n handler: Handler<any, any, any, Promise<Response>>\n ): Handler<any, any, any, Promise<Response>> {\n return async (context, next) => {\n let downstreamResponse: Response | undefined\n let nextCalled = false\n\n // Match Hono's compose guard: a middleware may advance the chain only once.\n const nextOnce = async (): Promise<void> => {\n if (nextCalled) {\n throw new Error('next() called multiple times')\n }\n\n nextCalled = true\n downstreamResponse = await handler(context, next)\n }\n const middlewareResponse = await inputMiddleware(context, nextOnce)\n\n if (middlewareResponse instanceof Response) {\n return middlewareResponse\n }\n\n if (downstreamResponse !== undefined) {\n return downstreamResponse\n }\n\n return context.res\n }\n }\n\n private getState(context: HonoContext): RequestState {\n const state = this.states.get(context)\n\n if (state === undefined) {\n throw new HonoEffectBoundaryMissingError()\n }\n\n return state\n }\n}\n\nexport class HonoEffectBoundaryMissingError extends Error {\n constructor() {\n super('Register HonoEffect.middleware() before better-effect handlers')\n this.name = 'HonoEffectBoundaryMissingError'\n }\n}\n"],"mappings":";;;;;;AAuBA,MAAM,wBAAwB,MAAkB,gBAA6C;CAE3F,OAAO,MAAM,SAAS,MAAM,WAAoB;AAClD;AAEA,MAAa,uBAMX,YAC+B;CAE/B,OAAO,iBAAiB,OAAO,SAAS,SAAS;EAC/C,MAAM,MAAM;EAGZ,IAFiB,QAAQ,OAAO,IAAI,GAEzB,MAAM,KAAA,GAAW;GAC1B,MAAM,KAAK;GACX;EACF;EAEA,MAAM,QAAsB,CAAC;EAC7B,QAAQ,OAAO,IAAI,KAAK,KAAK;EAE7B,IAAI;GACF,MAAM,eAAe,eAAe,MAAM,QAAQ,IAAI,GAAG;GACzD,MAAM,cAAc,QAAQ,eAAe,OAAO;GAClD,MAAM,QACJ,gBAAgB,KAAA,IAAY,eAAe,qBAAqB,cAAc,WAAW;GAE3F,MAAM,QAAQ,QAAQ,QACpB,OACA,YAAY;IACV,IAAI;KACF,MAAM,KAAK;IACb,SAAS,OAAO;KACd,MAAM,YAAY,EAAE,MAAM;IAC5B;IAEA,IAAI,MAAM,YAAY,KAAA,GACpB,OAAO,OAAO,IAAI,MAAM,QAAQ,KAAK;IAGvC,IAAI,QAAQ,UAAU,KAAA,GACpB,OAAO,OAAO,IAAI,QAAQ,KAAK;IAGjC,OAAO,OAAO,GAAG,QAAQ,GAAG;GAC9B,GACA,EAAE,QAAQ,QAAQ,IAAI,IAAI,OAAO,CACnC;EACF,UAAU;GACR,QAAQ,OAAO,OAAO,GAAG;EAC3B;CACF,CAAC;AACH;;;AC9EA,MAAM,0BAA0B;AAEhC,MAAa,kBACX,EAAE,OAAO,QAAQ,aACjB,YACa;CACb,IAAI,iBAAiB,UACnB,OAAO;CAGT,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B,OAAO,OAAO,SAAS,EAAE,QAAQ,QAAQ,OAAO,CAAC;GAGnD,IAAI,QAAQ,cAAc,KAAA,GACxB,OAAO,OAAO,SAAS,EAAE,WAAW,QAAQ,UAAU,CAAC;GAGzD,OAAO,MAAM,KAAK,UAAU,SAAS,OAAO;EAC9C;CACF;CAEA,uBACE,iBACA,SAC2C;EAC3C,OAAO,OAAO,SAAS,SAAS;GAC9B,IAAI;GACJ,IAAI,aAAa;GAGjB,MAAM,WAAW,YAA2B;IAC1C,IAAI,YACF,MAAM,IAAI,MAAM,8BAA8B;IAGhD,aAAa;IACb,qBAAqB,MAAM,QAAQ,SAAS,IAAI;GAClD;GACA,MAAM,qBAAqB,MAAM,gBAAgB,SAAS,QAAQ;GAElE,IAAI,8BAA8B,UAChC,OAAO;GAGT,IAAI,uBAAuB,KAAA,GACzB,OAAO;GAGT,OAAO,QAAQ;EACjB;CACF;CAEA,SAAiB,SAAoC;EACnD,MAAM,QAAQ,KAAK,OAAO,IAAI,OAAO;EAErC,IAAI,UAAU,KAAA,GACZ,MAAM,IAAI,+BAA+B;EAG3C,OAAO;CACT;AACF;AAEA,IAAa,iCAAb,cAAoD,MAAM;CACxD,cAAc;EACZ,MAAM,gEAAgE;EACtE,KAAK,OAAO;CACd;AACF"}
|
|
1
|
+
{"version":3,"file":"hono.mjs","names":[],"sources":["../src/hono/request-boundary.ts","../src/hono/responses.ts","../src/hono/builder.ts","../src/hono/hono-effect.ts"],"sourcesContent":["import { Result } from 'better-result'\nimport { createMiddleware } from 'hono/factory'\nimport type { Env, MiddlewareHandler } from 'hono'\n\nimport { Effect } from '../effect'\nimport type { LayerInput } from '../layer/inference'\nimport type { RuntimeExecutor, RuntimeManagedExecution, RuntimeManagedPlan } from '../runtime'\nimport type { AnyService } from '../service'\nimport { makeManagedResponse, runManagedWith } from '../web/web-effect'\nimport { assertResponse } from '../web/responses'\nimport type {\n AnyRouteOptions,\n HonoContext,\n HonoEffectStreamOptions,\n HonoEffectSuccess,\n ResponseLike\n} from './types'\nimport type { WebEffectStream } from '../web/types'\n\n/* oxlint-disable anti-slop/no-unknown-parameters -- Hono handlers carry opaque Result values until the typed adapter callbacks consume them. */\n\ntype RequestOutcome =\n | {\n readonly kind: 'success'\n readonly value: unknown\n readonly options: AnyRouteOptions\n }\n | {\n readonly kind: 'failure'\n readonly cause: unknown\n }\n | {\n readonly kind: 'defect'\n readonly cause: unknown\n }\n | {\n readonly kind: 'stream'\n readonly descriptor: WebEffectStream\n readonly options: HonoEffectStreamOptions\n }\n\nexport type RequestState = {\n outcome?: RequestOutcome\n}\n\n// oxlint-disable-next-line anti-slop/no-unknown-parameters -- Result failures are intentionally opaque until the Hono policy narrows them.\nexport const recordRequestFailure = (state: RequestState, cause: unknown): void => {\n state.outcome ??= { kind: 'failure', cause }\n}\n\n// oxlint-disable-next-line anti-slop/no-unknown-parameters -- Route success values retain their public generic type only at the Hono handler boundary.\nexport const recordRequestSuccess = (\n state: RequestState,\n value: unknown,\n options: AnyRouteOptions\n): void => {\n state.outcome ??= { kind: 'success', value, options }\n}\n\nexport const recordRequestStream = (\n state: RequestState,\n descriptor: WebEffectStream,\n options: HonoEffectStreamOptions\n): void => {\n state.outcome ??= { kind: 'stream', descriptor, options }\n}\n\nexport type RequestBoundaryOptions<RequestLayer extends LayerInput, Failure> = {\n readonly executor: RuntimeExecutor<AnyService>\n readonly states: WeakMap<object, RequestState>\n readonly requestLayer?: ((context: HonoContext) => RequestLayer) | undefined\n readonly onSuccess: (result: HonoEffectSuccess<any>, context: HonoContext) => ResponseLike\n readonly onFailure: (error: Failure, context: HonoContext) => ResponseLike\n}\n\ntype BoundaryOptions<RequestLayer extends LayerInput> = {\n readonly requestLayer?: (request: Request) => RequestLayer\n readonly onSuccess: (\n result: { readonly value: unknown },\n managed: Promise<RuntimeManagedExecution<unknown>>\n ) => RuntimeManagedPlan<Response> | PromiseLike<RuntimeManagedPlan<Response>>\n readonly onFailure: (error: unknown) => ResponseLike\n}\n\nconst responsePlan = (response: ResponseLike): RuntimeManagedPlan<Response> => {\n const readiness = Promise.resolve(response).then((value) => assertResponse(value))\n\n return {\n readiness,\n completion: readiness.then(() => undefined),\n cancel: async () => {}\n }\n}\n\nconst makeBoundaryOptions = <RequestLayer extends LayerInput, Failure>(\n options: RequestBoundaryOptions<RequestLayer, Failure>,\n state: RequestState,\n context: HonoContext\n): BoundaryOptions<RequestLayer> => {\n const boundaryOptions: BoundaryOptions<RequestLayer> = {\n onSuccess: ({ value }, managed) => {\n if (context.finalized) {\n return responsePlan(context.res)\n }\n\n const outcome = state.outcome\n\n if (outcome?.kind === 'stream') {\n return makeManagedResponse(outcome.descriptor, managed, outcome.options.unconsumedTimeoutMs)\n }\n\n if (outcome?.kind !== 'success') {\n // SAFETY: Values without a Hono route outcome are existing Web Responses; WebEffect validates them.\n return responsePlan(value as Response)\n }\n\n if (outcome.options.respond !== undefined) {\n return responsePlan(outcome.options.respond(value, context))\n }\n\n const success: HonoEffectSuccess = { value }\n\n if (outcome.options.status !== undefined) {\n Object.assign(success, { status: outcome.options.status })\n }\n\n if (outcome.options.serialize !== undefined) {\n Object.assign(success, { serialize: outcome.options.serialize })\n }\n\n return responsePlan(options.onSuccess(success, context))\n },\n onFailure: (error) => {\n if (context.error !== undefined || context.finalized) {\n return context.res\n }\n\n if (state.outcome?.kind === 'defect') {\n // SAFETY: Hono has already converted its Error into context.res through app.onError; WebEffect validates it.\n return context.res\n }\n\n // SAFETY: HonoEffect validates the Program failure channel against Failure before this erased Web boundary.\n return options.onFailure(error as Failure, context)\n }\n }\n\n if (options.requestLayer !== undefined) {\n Object.assign(boundaryOptions, {\n requestLayer: (_request: Request) => options.requestLayer!(context)\n })\n }\n\n return boundaryOptions\n}\n\nconst selectBoundaryResult = (state: RequestState, context: HonoContext) => {\n const outcome = state.outcome\n\n if (outcome?.kind === 'failure') {\n return Result.err(outcome.cause)\n }\n\n if (context.error !== undefined) {\n state.outcome = { kind: 'defect', cause: context.error }\n return Result.err(context.error)\n }\n\n if (outcome?.kind === 'success') {\n return Result.ok(outcome.value)\n }\n\n return Result.ok(context.res)\n}\n\nexport const makeRequestBoundary = <\n Failure,\n RequestLayer extends LayerInput,\n E extends Env = Env,\n Path extends string = string\n>(\n options: RequestBoundaryOptions<RequestLayer, Failure>\n): MiddlewareHandler<E, Path> => {\n // SAFETY: createMiddleware preserves the Hono handler contract; only the generic Context is restored here.\n return createMiddleware(async (context, next) => {\n const key = context\n const existing = options.states.get(key)\n\n if (existing !== undefined) {\n await next()\n return\n }\n\n const state: RequestState = {}\n options.states.set(key, state)\n\n try {\n // oxlint-disable-next-line require-yield -- The bridge turns the complete Hono chain into one lazy WebEffect Program.\n const program = Effect.fn(async function* () {\n await next()\n return selectBoundaryResult(state, context)\n })\n const boundaryOptions = makeBoundaryOptions(options, state, context)\n let response: Response\n\n // SAFETY: HonoEffect's public Layer boundary validates the request Layer before this erased WebEffect dispatch.\n response = await runManagedWith(\n options.executor,\n context.req.raw,\n program,\n boundaryOptions as never\n )\n\n if (!context.finalized || context.res !== response) {\n context.res = response\n }\n } finally {\n options.states.delete(key)\n }\n }) as MiddlewareHandler<E, Path>\n}\n","import type { HonoContext, HonoEffectSuccess } from './types'\n\nconst DEFAULT_FAILURE_MESSAGE = 'Internal Server Error'\n\nexport const defaultSuccess = (\n { value, status, serialize }: HonoEffectSuccess,\n context: HonoContext\n): Response => {\n if (value instanceof Response) {\n return value\n }\n\n const body = serialize === undefined ? value : serialize(value)\n\n if (body === undefined) {\n // SAFETY: route status is intentionally configurable and Hono validates it at response construction.\n return context.body(null, (status ?? 204) as never)\n }\n\n if (status === undefined) {\n return context.json({ data: body })\n }\n\n // SAFETY: route status is intentionally configurable and Hono validates it at response construction.\n return context.json({ data: body }, status as never)\n}\n\n// oxlint-disable-next-line anti-slop/no-unknown-parameters -- Result errors are intentionally opaque at this HTTP boundary.\nexport const defaultFailure = (error: unknown, context: HonoContext): Response => {\n if (error instanceof Response) {\n return error\n }\n\n return context.json({ error: DEFAULT_FAILURE_MESSAGE }, 500)\n}\n","import { Result } from 'better-result'\nimport type { Context, Env, Handler, Input, MiddlewareHandler } from 'hono'\n\nimport { Effect } from '../effect'\nimport type {\n EffectSuccess,\n EffectYield,\n ProgramFromGenerator,\n ServiceRequirement\n} from '../effect/types'\nimport type { LayerInput, RequiredEnvironment } from '../layer/inference'\nimport { Runtime } from '../runtime'\nimport { eraseRuntimeExecutor, type RuntimeExecutor } from '../runtime/executor'\nimport type { AnyService } from '../service'\n\nimport {\n makeRequestBoundary,\n recordRequestFailure,\n recordRequestSuccess,\n recordRequestStream,\n type RequestState\n} from './request-boundary'\nimport { assertResponse } from '../web/responses'\nimport { defaultFailure, defaultSuccess } from './responses'\nimport type {\n AnyGeneratorBody,\n AnyHonoMiddleware,\n AnyProgram,\n AnyProgramFactory,\n AnyResult,\n AnyRouteOptions,\n CompleteHonoStreamProgram,\n CompleteProgram,\n GeneratorBody,\n GeneratorChecks,\n HonoContext,\n HonoEffectContext,\n HonoEffectOperation,\n HonoEffectOptions,\n HonoEffectRouteOptions,\n HonoEffectStreamOptions,\n HonoEffectSuccess,\n HonoProgramRequirements,\n MiddlewareEnvironment,\n MiddlewareInputs,\n MiddlewarePath\n} from './types'\n\ntype HonoRouteArguments<Middlewares extends readonly AnyHonoMiddleware[], Body, Options> =\n | [...middlewares: Middlewares, body: Body]\n | [...middlewares: Middlewares, body: Body, options: Options | undefined]\n\ntype HonoInternalHandler = (\n context: HonoContext,\n next: () => Promise<void>\n) => Promise<Response | void>\n\ntype HonoHandlerFactory<\n ContextType extends object,\n Failure,\n ProgramFactory extends (context: ContextType) => AnyProgram\n> = ProgramFactory &\n ([ReturnType<ProgramFactory>] extends [CompleteProgram<ReturnType<ProgramFactory>, Failure>]\n ? unknown\n : (context: ContextType) => CompleteProgram<ReturnType<ProgramFactory>, Failure>)\n\ntype OperationFactory<A> = (executor: RuntimeExecutor<AnyService>) => A\n\n/** Capture the active Runtime executor while a Hono application Layer is acquired. */\nconst makeOperation = <A, Requirements extends AnyService>(\n factory: OperationFactory<A>\n): HonoEffectOperation<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\n/** Build Hono-native handlers whose Runtime capability is captured by the app Layer. */\nexport class HonoEffectBuilder<Failure, RequestLayer extends LayerInput> {\n private readonly states = new WeakMap<object, RequestState>()\n\n private readonly onSuccess: NonNullable<HonoEffectOptions<Failure, RequestLayer>['onSuccess']>\n\n private readonly onFailure: NonNullable<HonoEffectOptions<Failure, RequestLayer>['onFailure']>\n\n private readonly requestLayer: HonoEffectOptions<Failure, RequestLayer>['requestLayer']\n\n constructor(options: HonoEffectOptions<Failure, RequestLayer>) {\n this.onSuccess = options.onSuccess ?? defaultSuccess\n this.onFailure = options.onFailure ?? defaultFailure\n this.requestLayer = options.requestLayer\n }\n\n middleware<E extends Env = Env, Path extends string = string>(): HonoEffectOperation<\n MiddlewareHandler<E, Path>,\n Extract<RequiredEnvironment<RequestLayer>, AnyService>\n > {\n return makeOperation((executor) =>\n makeRequestBoundary<Failure, RequestLayer, E, Path>({\n executor,\n states: this.states,\n requestLayer: this.requestLayer,\n onSuccess: this.onSuccess,\n onFailure: this.onFailure\n })\n )\n }\n\n handler<\n E extends Env = Env,\n Path extends string = string,\n InputType extends Input = Input,\n Program extends AnyProgram = AnyProgram\n >(\n makeProgram: (context: Context<E, Path, InputType>) => CompleteProgram<Program, Failure>,\n options?: HonoEffectRouteOptions<EffectSuccess<Program>, Context<E, Path, InputType>>\n ): HonoEffectOperation<\n Handler<E, Path, InputType, Promise<Response>>,\n HonoProgramRequirements<RequestLayer, Program>\n >\n handler<\n const Middlewares extends readonly AnyHonoMiddleware[],\n E extends Env = MiddlewareEnvironment<Middlewares>,\n Path extends string = MiddlewarePath<Middlewares>,\n const ProgramFactory extends (\n context: HonoEffectContext<E, Path, MiddlewareInputs<Middlewares>>\n ) => AnyProgram = (\n context: HonoEffectContext<E, Path, MiddlewareInputs<Middlewares>>\n ) => AnyProgram\n >(\n ...args: HonoRouteArguments<\n Middlewares,\n HonoHandlerFactory<\n HonoEffectContext<E, Path, MiddlewareInputs<Middlewares>>,\n Failure,\n ProgramFactory\n >,\n HonoEffectRouteOptions<\n EffectSuccess<ReturnType<ProgramFactory>>,\n Context<E, Path, MiddlewareInputs<Middlewares>>\n >\n >\n ): HonoEffectOperation<\n Handler<E, Path, MiddlewareInputs<Middlewares>, Promise<Response>>,\n HonoProgramRequirements<RequestLayer, ReturnType<ProgramFactory>>\n >\n handler(...args: unknown[]): HonoEffectOperation<any, AnyService> {\n const last = args.at(-1)\n // oxlint-disable-next-line anti-slop/no-runtime-typeof -- overload dispatch separates route options from function callbacks.\n const hasOptions = args.length > 1 && (last === undefined || typeof last !== 'function')\n // SAFETY: the overloads restrict the optional trailing argument to route options.\n const options = ((hasOptions ? last : {}) ?? {}) as AnyRouteOptions\n const bodyIndex = hasOptions ? args.length - 2 : args.length - 1\n // SAFETY: the overloads place the program factory immediately before route options.\n const makeProgram = args[bodyIndex] as AnyProgramFactory\n\n return makeOperation(() => {\n let handler = this.makeHandler(makeProgram, options)\n\n for (let index = bodyIndex - 1; index >= 0; index -= 1) {\n // SAFETY: every argument before the program factory is an input middleware by the overloads.\n handler = this.composeInputMiddleware(args[index] as AnyHonoMiddleware, handler)\n }\n\n // SAFETY: the public overload restores Hono's concrete handler channels after this erased implementation.\n return handler as Handler<any, any, any, Promise<Response>>\n })\n }\n\n gen<\n E extends Env = Env,\n Path extends string = string,\n InputType extends Input = Input,\n const Yield extends EffectYield = EffectYield,\n const Returned extends AnyResult = AnyResult\n >(\n body: GeneratorBody<Context<E, Path, InputType>, Yield, Returned> &\n GeneratorChecks<Yield, Returned, Failure>,\n options?: HonoEffectRouteOptions<\n EffectSuccess<ProgramFromGenerator<Yield, Returned>>,\n Context<E, Path, InputType>\n >\n ): HonoEffectOperation<\n Handler<E, Path, InputType, Promise<Response>>,\n HonoProgramRequirements<RequestLayer, ProgramFromGenerator<Yield, Returned>>\n >\n gen<\n const Middlewares extends readonly AnyHonoMiddleware[],\n E extends Env = MiddlewareEnvironment<Middlewares>,\n Path extends string = MiddlewarePath<Middlewares>,\n const Yield extends EffectYield = EffectYield,\n const Returned extends AnyResult = AnyResult\n >(\n ...args: HonoRouteArguments<\n Middlewares,\n GeneratorBody<HonoEffectContext<E, Path, MiddlewareInputs<Middlewares>>, Yield, Returned> &\n GeneratorChecks<Yield, Returned, Failure>,\n HonoEffectRouteOptions<\n EffectSuccess<ProgramFromGenerator<Yield, Returned>>,\n Context<E, Path, MiddlewareInputs<Middlewares>>\n >\n >\n ): HonoEffectOperation<\n Handler<E, Path, MiddlewareInputs<Middlewares>, Promise<Response>>,\n HonoProgramRequirements<RequestLayer, ProgramFromGenerator<Yield, Returned>>\n >\n gen(...args: unknown[]): HonoEffectOperation<any, AnyService> {\n const last = args.at(-1)\n // oxlint-disable-next-line anti-slop/no-runtime-typeof -- overload dispatch distinguishes middleware from the generator body.\n const hasOptions = args.length > 1 && (last === undefined || typeof last !== 'function')\n // SAFETY: the overloads restrict the optional trailing argument to route options.\n const options = ((hasOptions ? last : {}) ?? {}) as AnyRouteOptions\n const bodyIndex = hasOptions ? args.length - 2 : args.length - 1\n // SAFETY: the overloads place the generator body immediately before route options.\n const body = args[bodyIndex] as AnyGeneratorBody\n\n return makeOperation(() => {\n let handler = this.makeHandler((context) => {\n // SAFETY: Effect.fn's runtime generator accepts both sync and async generators; the cast only joins its overloads.\n const program = Effect.fn(\n () => body(context) as AsyncGenerator<EffectYield, AnyResult, unknown>\n )\n\n // SAFETY: the public GeneratorChecks overload validates failures before this erased boundary.\n return program as AnyProgram\n }, options)\n\n for (let index = bodyIndex - 1; index >= 0; index -= 1) {\n // SAFETY: every argument before the generator body is an input middleware by the overloads.\n handler = this.composeInputMiddleware(args[index] as AnyHonoMiddleware, handler)\n }\n\n // SAFETY: the public overload restores Hono's concrete handler channels after this erased implementation.\n return handler as Handler<any, any, any, Promise<Response>>\n })\n }\n\n stream<\n E extends Env = Env,\n Path extends string = string,\n InputType extends Input = Input,\n Program extends AnyProgram = AnyProgram\n >(\n program: CompleteHonoStreamProgram<Program, Failure>,\n options?: HonoEffectStreamOptions\n ): HonoEffectOperation<\n Handler<E, Path, InputType, Promise<Response>>,\n HonoProgramRequirements<RequestLayer, Program>\n >\n stream<\n const Middlewares extends readonly AnyHonoMiddleware[],\n E extends Env = MiddlewareEnvironment<Middlewares>,\n Path extends string = MiddlewarePath<Middlewares>,\n Program extends AnyProgram = AnyProgram\n >(\n ...args: HonoRouteArguments<\n Middlewares,\n CompleteHonoStreamProgram<Program, Failure>,\n HonoEffectStreamOptions\n >\n ): HonoEffectOperation<\n Handler<E, Path, MiddlewareInputs<Middlewares>, Promise<Response>>,\n HonoProgramRequirements<RequestLayer, Program>\n >\n stream(...args: unknown[]): HonoEffectOperation<any, AnyService> {\n const last = args.at(-1)\n // oxlint-disable-next-line anti-slop/no-runtime-typeof -- overload dispatch separates route options from the stream Program.\n const hasOptions = args.length > 1 && (last === undefined || typeof last !== 'function')\n // SAFETY: the overloads restrict the optional trailing argument to stream options.\n const options = ((hasOptions ? last : {}) ?? {}) as HonoEffectStreamOptions\n const programIndex = hasOptions ? args.length - 2 : args.length - 1\n // SAFETY: the overloads place the stream Program immediately before route options.\n const streamProgram = args[programIndex] as AnyProgram\n\n return makeOperation(() => {\n let handler = this.makeStreamHandler(streamProgram, options)\n\n for (let index = programIndex - 1; index >= 0; index -= 1) {\n // SAFETY: every argument before the stream Program is an input middleware by the overloads.\n handler = this.composeInputMiddleware(args[index] as AnyHonoMiddleware, handler)\n }\n\n // SAFETY: the public overload restores Hono's concrete handler channels after this erased boundary.\n return handler as Handler<any, any, any, Promise<Response>>\n })\n }\n\n guard<\n E extends Env = Env,\n Path extends string = string,\n InputType extends Input = Input,\n const Yield extends EffectYield = EffectYield,\n const Returned extends AnyResult = AnyResult\n >(\n body: GeneratorBody<Context<E, Path, InputType>, Yield, Returned> &\n GeneratorChecks<Yield, Returned, Failure>\n ): HonoEffectOperation<\n MiddlewareHandler<E, Path>,\n HonoProgramRequirements<RequestLayer, ProgramFromGenerator<Yield, Returned>>\n > {\n return makeOperation(() => async (context, next) => {\n const state = this.getState(context)\n // SAFETY: Effect.fn accepts the sync or async generator supplied by the caller; this joins its overloads.\n const program = Effect.fn(() => body(context) as AsyncGenerator<Yield, Returned, unknown>)\n const result = await program()\n\n if (Result.isError(result)) {\n return await this.handleFailure(state, result.error, context)\n }\n\n await next()\n })\n }\n\n private makeHandler(\n makeProgram: (context: HonoContext) => AnyProgram,\n options: HonoEffectRouteOptions<any, any>\n ): HonoInternalHandler {\n return async (context) => {\n const state = this.getState(context)\n const result = await makeProgram(context)()\n\n if (Result.isError(result)) {\n return await this.handleFailure(state, result.error, context)\n }\n\n recordRequestSuccess(state, result.value, options)\n return await this.handleSuccess(result.value, options, context)\n }\n }\n\n private makeStreamHandler(\n streamProgram: AnyProgram,\n options: HonoEffectStreamOptions\n ): HonoInternalHandler {\n return async (context) => {\n const state = this.getState(context)\n const result = await streamProgram()\n\n if (Result.isError(result)) {\n return await this.handleFailure(state, result.error, context)\n }\n\n recordRequestStream(state, result.value, options)\n }\n }\n\n private async handleSuccess(\n // oxlint-disable-next-line anti-slop/no-unknown-parameters -- Route values are intentionally opaque until the Hono success policy consumes them.\n value: unknown,\n options: AnyRouteOptions,\n context: HonoContext\n ): Promise<Response> {\n if (options.respond !== undefined) {\n return assertResponse(await options.respond(value, context))\n }\n\n const success: HonoEffectSuccess = { value }\n\n if (options.status !== undefined) {\n Object.assign(success, { status: options.status })\n }\n\n if (options.serialize !== undefined) {\n Object.assign(success, { serialize: options.serialize })\n }\n\n return assertResponse(await this.onSuccess(success, context))\n }\n\n private async handleFailure(\n state: RequestState,\n // oxlint-disable-next-line anti-slop/no-unknown-parameters -- Result errors are intentionally opaque until the Hono failure policy consumes them.\n error: unknown,\n context: HonoContext\n ): Promise<Response> {\n recordRequestFailure(state, error)\n // SAFETY: the public handler, generator, and guard constraints validate this error against Failure.\n return assertResponse(await this.onFailure(error as Failure, context))\n }\n\n private composeInputMiddleware(\n inputMiddleware: AnyHonoMiddleware,\n handler: HonoInternalHandler\n ): HonoInternalHandler {\n return async (context, next) => {\n let downstreamResponse: Response | undefined\n let nextCalled = false\n\n // Match Hono's compose guard: a middleware may advance the chain only once.\n const nextOnce = async (): Promise<void> => {\n if (nextCalled) {\n throw new Error('next() called multiple times')\n }\n\n nextCalled = true\n const response = await handler(context, next)\n\n if (response !== undefined) {\n downstreamResponse = response\n }\n }\n const middlewareResponse = await inputMiddleware(context, nextOnce)\n\n if (middlewareResponse instanceof Response) {\n return middlewareResponse\n }\n\n if (downstreamResponse !== undefined) {\n return downstreamResponse\n }\n\n if (context.finalized) {\n return context.res\n }\n }\n }\n\n private getState(context: HonoContext): RequestState {\n const state = this.states.get(context)\n\n if (state === undefined) {\n throw new HonoEffectBoundaryMissingError()\n }\n\n return state\n }\n}\n\nexport class HonoEffectBoundaryMissingError extends Error {\n constructor() {\n super('Register HonoEffect.middleware() before better-effect handlers')\n this.name = 'HonoEffectBoundaryMissingError'\n }\n}\n","import type { InferYieldRequirements, ServiceRequirement } from '../effect/types'\nimport { Layer } from '../layer'\nimport type { LayerInput, LayerResult } from '../layer/inference'\nimport { Service } from '../service'\nimport type {\n AnyService,\n ServiceContract,\n ServiceIdentity,\n ServiceRequirements,\n ServiceToken\n} from '../service'\n\nimport { HonoEffectBuilder } from './builder'\nimport type { DefaultRequestLayer, HonoEffectOptions, HonoRequestLayerChecks } from './types'\n\ntype HonoFactoryFor<Builder, Returned extends object> = (\n http: Builder\n) =>\n | Generator<ServiceRequirement<unknown>, Returned, unknown>\n | AsyncGenerator<ServiceRequirement<unknown>, Returned, unknown>\n\ntype HonoFactory<Builder> = HonoFactoryFor<Builder, object>\n\ntype HonoFactoryReturn<Factory> = Factory extends (...arguments_: any[]) => infer Iterator\n ? Iterator extends Generator<any, infer Returned, any>\n ? Returned extends object\n ? Returned\n : never\n : Iterator extends AsyncGenerator<any, infer Returned, any>\n ? Returned extends object\n ? Returned\n : never\n : never\n : never\n\ntype HonoFactoryYield<Factory> = Factory extends (...arguments_: any[]) => infer Iterator\n ? Iterator extends Generator<infer Yield, object, any>\n ? Yield\n : Iterator extends AsyncGenerator<infer Yield, object, any>\n ? Yield\n : never\n : never\n\n/** A Hono application Layer with inferred Service requirements. */\nexport type HonoEffectLayer<\n Service extends ServiceToken<any, any>,\n Yield extends ServiceRequirement<unknown>\n> = LayerResult<\n import('../layer/metadata').ProviderEntry<\n InstanceType<Service>,\n Extract<ServiceRequirements<InstanceType<Service>> | InferYieldRequirements<Yield>, AnyService>\n >\n>\n\nexport type HonoApplicationToken<\n Tag extends string,\n App extends object,\n Service extends ServiceToken<any, any>,\n Yield extends ServiceRequirement<unknown>\n> = ServiceToken<Tag, App & ServiceIdentity<Tag>> & {\n readonly layer: HonoEffectLayer<Service, Yield>\n}\n\ntype HonoLiteralTag<Tag extends string> = string extends Tag ? never : Tag extends '' ? never : Tag\n\nconst defineLayerProperty = <Token extends object, AppLayer extends LayerInput>(\n token: Token,\n layer: AppLayer\n): Token & { readonly layer: AppLayer } => {\n Object.defineProperty(token, 'layer', {\n configurable: false,\n enumerable: true,\n value: layer,\n writable: false\n })\n\n // SAFETY: The property was defined above as a non-writable value with the exact Layer type.\n return token as Token & { readonly layer: AppLayer }\n}\n\nconst makeHonoLayer = <\n Service extends ServiceToken<any, any>,\n Failure,\n RequestLayer extends LayerInput,\n Factory extends HonoFactory<HonoEffectBuilder<Failure, RequestLayer>>\n>(\n service: Service,\n options: HonoEffectOptions<Failure, RequestLayer>,\n factory: Factory\n): HonoEffectLayer<Service, Extract<HonoFactoryYield<Factory>, ServiceRequirement<unknown>>> => {\n const layer = Layer.gen(service, () => {\n const builder = new HonoEffectBuilder(options)\n\n // SAFETY: the public factory is constrained to a Hono Service contract; this erasure only adapts it to Layer.gen's runtime-erased provider storage.\n return factory(builder) as Generator<\n ServiceRequirement<unknown>,\n ServiceContract<InstanceType<Service>>,\n unknown\n >\n })\n\n // SAFETY: Layer.gen derives the same provider requirements from the factory's yield metadata.\n return layer as HonoEffectLayer<\n Service,\n Extract<HonoFactoryYield<Factory>, ServiceRequirement<unknown>>\n >\n}\n\n/** Layer-first Hono integration. The application owns the Runtime composition. */\nexport class HonoEffect {\n private constructor() {}\n\n /** Create a yieldable Hono application token and its Layer. */\n static app<\n const Tag extends string,\n RequestLayer extends LayerInput = DefaultRequestLayer,\n Failure = unknown,\n const Factory extends HonoFactory<HonoEffectBuilder<Failure, RequestLayer>> = HonoFactory<\n HonoEffectBuilder<Failure, RequestLayer>\n >\n >(\n tag: Tag & HonoLiteralTag<Tag>,\n options: HonoEffectOptions<Failure, RequestLayer> & HonoRequestLayerChecks<RequestLayer>,\n factory: Factory\n ): HonoApplicationToken<\n Tag,\n HonoFactoryReturn<Factory>,\n ServiceToken<Tag, HonoFactoryReturn<Factory> & ServiceIdentity<Tag>>,\n Extract<HonoFactoryYield<Factory>, ServiceRequirement<unknown>>\n > {\n const literalTag: HonoLiteralTag<Tag> = tag\n const tokenFactory = Service<HonoFactoryReturn<Factory> & ServiceIdentity<Tag>>()<Tag>\n // SAFETY: Service's factory returns the class-backed token; this assertion restores the precise application instance contract.\n // oxlint-disable-next-line anti-slop/no-chained-type-assertions -- the Service factory erases only the application instance contract.\n const token = tokenFactory(literalTag) as unknown as ServiceToken<\n Tag,\n HonoFactoryReturn<Factory> & ServiceIdentity<Tag>\n >\n const layer = makeHonoLayer(token, options, factory)\n\n // SAFETY: The token and Layer were created together above and the return type mirrors both exact values.\n return defineLayerProperty(token, layer) as HonoApplicationToken<\n Tag,\n HonoFactoryReturn<Factory>,\n ServiceToken<Tag, HonoFactoryReturn<Factory> & ServiceIdentity<Tag>>,\n Extract<HonoFactoryYield<Factory>, ServiceRequirement<unknown>>\n >\n }\n\n /** Provide an application-chosen Service token with a Hono Layer. */\n static layer<\n Service extends ServiceToken<any, any>,\n RequestLayer extends LayerInput = DefaultRequestLayer,\n Failure = unknown,\n const Returned extends ServiceContract<InstanceType<Service>> = ServiceContract<\n InstanceType<Service>\n >,\n const Factory extends HonoFactoryFor<HonoEffectBuilder<Failure, RequestLayer>, Returned> =\n HonoFactoryFor<HonoEffectBuilder<Failure, RequestLayer>, Returned>\n >(\n service: Service,\n options: HonoEffectOptions<Failure, RequestLayer> & HonoRequestLayerChecks<RequestLayer>,\n factory: Factory\n ): HonoEffectLayer<Service, Extract<HonoFactoryYield<Factory>, ServiceRequirement<unknown>>> {\n return makeHonoLayer(service, options, factory)\n }\n}\n"],"mappings":";;;;;;;;AA8CA,MAAa,wBAAwB,OAAqB,UAAyB;CACjF,MAAM,YAAY;EAAE,MAAM;EAAW;CAAM;AAC7C;AAGA,MAAa,wBACX,OACA,OACA,YACS;CACT,MAAM,YAAY;EAAE,MAAM;EAAW;EAAO;CAAQ;AACtD;AAEA,MAAa,uBACX,OACA,YACA,YACS;CACT,MAAM,YAAY;EAAE,MAAM;EAAU;EAAY;CAAQ;AAC1D;AAmBA,MAAM,gBAAgB,aAAyD;CAC7E,MAAM,YAAY,QAAQ,QAAQ,QAAQ,CAAC,CAAC,MAAM,UAAU,eAAe,KAAK,CAAC;CAEjF,OAAO;EACL;EACA,YAAY,UAAU,WAAW,KAAA,CAAS;EAC1C,QAAQ,YAAY,CAAC;CACvB;AACF;AAEA,MAAM,uBACJ,SACA,OACA,YACkC;CAClC,MAAM,kBAAiD;EACrD,YAAY,EAAE,SAAS,YAAY;GACjC,IAAI,QAAQ,WACV,OAAO,aAAa,QAAQ,GAAG;GAGjC,MAAM,UAAU,MAAM;GAEtB,IAAI,SAAS,SAAS,UACpB,OAAO,oBAAoB,QAAQ,YAAY,SAAS,QAAQ,QA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M,IAAI,+BAA+B;EAG3C,OAAO;CACT;AACF;AAEA,IAAa,iCAAb,cAAoD,MAAM;CACxD,cAAc;EACZ,MAAM,gEAAgE;EACtE,KAAK,OAAO;CACd;AACF;;;ACtXA,MAAM,uBACJ,OACA,UACyC;CACzC,OAAO,eAAe,OAAO,SAAS;EACpC,cAAc;EACd,YAAY;EACZ,OAAO;EACP,UAAU;CACZ,CAAC;CAGD,OAAO;AACT;AAEA,MAAM,iBAMJ,SACA,SACA,YAC8F;CAa9F,OAZc,MAAM,IAAI,eAAe;EAIrC,OAAO,QAAQ,IAHK,kBAAkB,OAGjB,CAAC;CAKxB,CAGW;AAIb;;AAGA,IAAa,aAAb,MAAwB;CACtB,cAAsB,CAAC;;CAGvB,OAAO,IAQL,KACA,SACA,SAMA;EACA,MAAM,aAAkC;EAIxC,MAAM,QAHe,QAGI,CAAC,CAAC,UAAU;EAIrC,MAAM,QAAQ,cAAc,OAAO,SAAS,OAAO;EAGnD,OAAO,oBAAoB,OAAO,KAAK;CAMzC;;CAGA,OAAO,MAUL,SACA,SACA,SAC2F;EAC3F,OAAO,cAAc,SAAS,SAAS,OAAO;CAChD;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { At as EffectRequirements, B as forkScoped, Dt as Effect$1, Et as AnyEffect, Ft as ProgramFromGenerator, L as ScopedTask, Lt as AnyService, Mt as EffectYield, Ot as EffectError, Pt as Program$1, R as ScopedTaskExit, _t as DisposableResource, bt as ScopeOutcome, jt as EffectSuccess, kt as EffectFromGenerator, vt as MaybePromise } from "./layer-C2OaqTmB.mjs";
|
|
2
2
|
import { Err, Result, UnhandledException } from "better-result";
|
|
3
3
|
//#region src/effect/combinators.d.ts
|
|
4
4
|
type EffectInput<A, E> = Result<A, E> | PromiseLike<Result<A, E>>;
|
|
@@ -360,6 +360,7 @@ type EffectNamespace = {
|
|
|
360
360
|
readonly acquireReleaseResult: typeof acquireReleaseResult;
|
|
361
361
|
readonly acquireDisposable: typeof acquireDisposable;
|
|
362
362
|
readonly add: typeof add;
|
|
363
|
+
readonly forkScoped: typeof forkScoped;
|
|
363
364
|
readonly map: typeof map$1;
|
|
364
365
|
readonly mapError: typeof mapError$1;
|
|
365
366
|
readonly andThen: typeof andThen$1;
|
|
@@ -394,7 +395,11 @@ declare namespace Effect {
|
|
|
394
395
|
type Requirements<T> = EffectRequirements<T>;
|
|
395
396
|
/** An Effect with erased success, error, and requirements. */
|
|
396
397
|
type Any = AnyEffect;
|
|
398
|
+
/** A small handle for a Scope-owned child task. */
|
|
399
|
+
type Task<A, E> = ScopedTask<A, E>;
|
|
400
|
+
/** The terminal observation returned by a Scope-owned child task. */
|
|
401
|
+
type TaskExit<A, E> = ScopedTaskExit<A, E>;
|
|
397
402
|
}
|
|
398
403
|
//#endregion
|
|
399
404
|
export { Program as n, ProgramAllOptions as r, Effect as t };
|
|
400
|
-
//# sourceMappingURL=index-
|
|
405
|
+
//# sourceMappingURL=index-3Bkl-sxS.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-
|
|
1
|
+
{"version":3,"file":"index-3Bkl-sxS.d.mts","names":[],"sources":["../src/effect/combinators.ts","../src/effect/program-combinators.ts","../src/effect/effect.ts"],"mappings":";;;KAYK,YAAY,GAAG,KAAK,OAAW,GAAG,KAAK,YAAY,OAAW,GAAG;KAEjE,iBAAiB;KACjB,iBAAiB;KACjB,sBAAsB,YAAY;KAIlC,cAAc,OAAO,UAAU,cAAc,uBAAuB,QAAQ,UAAU;KAEtF,aAAa,OAAO,KAAK,SAAO,GAAG,YAAY,QAAQ,mBAAmB;KAE1E,kBAAkB,OAAO,MAAM,SAAO,cAAc,QAAQ,IAAI,mBAAmB;KAEnF,cAAc,OAAO,QAAQ,SAChC,cAAc,OACd,YAAY,SAAS,YAAY,OACjC,mBAAmB,SAAS,mBAAmB;KAG5C,cAAc,OAAO,QAAQ,cAAc,OAAO;KAElD,mBAAmB,OAAO,QAAQ,Q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