better-effect 0.7.0 → 0.9.1

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.
@@ -0,0 +1,406 @@
1
+ import { A as ProgramFromGenerator, C as EffectError, D as EffectYield, E as EffectSuccess, M as AnyService, S as Effect$1, T as EffectRequirements, f as DisposableResource, h as ScopeOutcome, k as Program$1, p as MaybePromise$1, w as EffectFromGenerator, x as AnyEffect } from "./index-BFgG9zZC.mjs";
2
+ import { C as ProvidedEnvironment, _ as Layer, a as RuntimeShutdownDiagnostic, b as CompleteInput, i as RuntimeRunOptions, n as RuntimeDisposeOptions, r as RuntimeOptions, v as CompleteExecution, x as LayerInput, y as CompleteExecutionLayer } from "./index-BSRPIYII.mjs";
3
+ import { n as LayerBackend } from "./map-layer-backend-CGibcwkc.mjs";
4
+ import { Err, Result, UnhandledException } from "better-result";
5
+ //#region src/effect/combinators.d.ts
6
+ type EffectInput<A, E> = Result<A, E> | PromiseLike<Result<A, E>>;
7
+ type AnyEffectInput = EffectInput<any, any>;
8
+ type AnyEffectValue = Result<any, any>;
9
+ type AnyAsyncEffectInput = PromiseLike<Result<any, any>>;
10
+ type PreserveAsync<Input, Output> = Input extends PromiseLike<unknown> ? Promise<Output> : Output;
11
+ type MappedResult<Input, B> = Effect$1<B, EffectError<Input>, EffectRequirements<Input>>;
12
+ type ErrorMappedResult<Input, E2> = Effect$1<EffectSuccess<Input>, E2, EffectRequirements<Input>>;
13
+ type ChainedResult<First, Next> = Effect$1<EffectSuccess<Next>, EffectError<First> | EffectError<Next>, EffectRequirements<First> | EffectRequirements<Next>>;
14
+ type ChainedOutput<First, Next> = ChainedResult<First, Next>;
15
+ type AsyncChainedOutput<First, Next> = Promise<ChainedResult<First, Next>>;
16
+ type MapOperation<A, B> = {
17
+ <Input>(effect: Input & EffectInput<A, any>): PreserveAsync<Input, MappedResult<Input, B>>;
18
+ };
19
+ type MapErrorOperation<E1, E2> = {
20
+ <Input>(effect: Input & EffectInput<any, E1>): PreserveAsync<Input, ErrorMappedResult<Input, E2>>;
21
+ };
22
+ type AndThenOperation<Next> = {
23
+ <Input>(effect: Input & AnyEffectValue): ChainedOutput<Input, Next>;
24
+ };
25
+ type AndThenAsyncOperation<A, Next> = {
26
+ <Input>(effect: Input & EffectInput<A, any>): AsyncChainedOutput<Input, Next>;
27
+ };
28
+ type TappedResult<Input> = Effect$1<EffectSuccess<Input>, EffectError<Input>, EffectRequirements<Input>>;
29
+ type RecoveredResult<Input, Next> = Effect$1<EffectSuccess<Input> | EffectSuccess<Next>, EffectError<Next>, EffectRequirements<Input> | EffectRequirements<Next>>;
30
+ type FlattenedResult<Input> = Effect$1<EffectSuccess<EffectSuccess<Input>>, EffectError<Input> | EffectError<EffectSuccess<Input>>, EffectRequirements<Input> | EffectRequirements<EffectSuccess<Input>>>;
31
+ type AsResult<Input, Value> = Effect$1<Value, EffectError<Input>, EffectRequirements<Input>>;
32
+ type MatchedResult<Input, OkResult, ErrResult> = Effect$1<EffectSuccess<OkResult> | EffectSuccess<ErrResult>, EffectError<OkResult> | EffectError<ErrResult>, EffectRequirements<Input> | EffectRequirements<OkResult> | EffectRequirements<ErrResult>>;
33
+ type AllResult<Results extends readonly AnyEffectValue[]> = Effect$1<{ -readonly [Index in keyof Results]: EffectSuccess<Results[Index]>; }, EffectError<Results[number]>, EffectRequirements<Results[number]>>;
34
+ type ZipResult<Left, Right> = Effect$1<[EffectSuccess<Left>, EffectSuccess<Right>], EffectError<Left> | EffectError<Right>, EffectRequirements<Left> | EffectRequirements<Right>>;
35
+ type TapOperation = {
36
+ <Input>(effect: Input & AnyEffectInput, fn: (value: EffectSuccess<Input>) => void): PreserveAsync<Input, TappedResult<Input>>;
37
+ };
38
+ type TapErrorOperation = {
39
+ <Input>(effect: Input & AnyEffectInput, fn: (error: EffectError<Input>) => void): PreserveAsync<Input, TappedResult<Input>>;
40
+ };
41
+ type TapBothOperation = {
42
+ <Input>(effect: Input & AnyEffectInput, handlers: {
43
+ ok: (value: EffectSuccess<Input>) => void;
44
+ err: (error: EffectError<Input>) => void;
45
+ }): PreserveAsync<Input, TappedResult<Input>>;
46
+ };
47
+ type RecoverOperation<Next> = {
48
+ <Input>(effect: Input & AnyEffectInput, fn: (error: EffectError<Input>) => Next): PreserveAsync<Input, RecoveredResult<Input, Next>>;
49
+ };
50
+ type RecoverAsyncOperation<Next> = {
51
+ <Input>(effect: Input & AnyEffectInput, fn: (error: EffectError<Input>) => Next): Promise<RecoveredResult<Input, Next>>;
52
+ };
53
+ /**
54
+ * Map the successful value of a Result or Effect result.
55
+ *
56
+ * Supports both data-first and data-last forms and preserves asynchronous
57
+ * results and declaration-only Service requirements.
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * const doubled = Effect.map(Result.ok(2), (value) => value * 2)
62
+ * const toLabel = Effect.map((value: number) => `#${value}`)
63
+ * ```
64
+ */
65
+ declare function map<A, B>(fn: (value: A) => B): MapOperation<A, B>;
66
+ declare function map<Input, B>(effect: Input & AnyEffectInput, fn: (value: EffectSuccess<Input>) => B): PreserveAsync<Input, MappedResult<Input, B>>;
67
+ /**
68
+ * Map the error value of a Result or Effect result while preserving its
69
+ * successful value, asynchronous shape, and declaration-only Service requirements.
70
+ *
71
+ * @example
72
+ * ```ts
73
+ * const labelled = Effect.mapError(Result.err('missing'), (error) => ({ error }))
74
+ * ```
75
+ */
76
+ declare function mapError<E1, E2>(fn: (error: E1) => E2): MapErrorOperation<E1, E2>;
77
+ declare function mapError<Input, E2>(effect: Input & AnyEffectInput, fn: (error: EffectError<Input>) => E2): PreserveAsync<Input, ErrorMappedResult<Input, E2>>;
78
+ /**
79
+ * Chain a synchronous Result-producing operation after a successful result.
80
+ *
81
+ * The next operation is skipped when the input is an error. Both error types
82
+ * and both sets of Service requirements are preserved in the output.
83
+ *
84
+ * @example
85
+ * ```ts
86
+ * const user = Effect.andThen(Result.ok('u1'), (id) => repository.find(id))
87
+ * ```
88
+ */
89
+ declare function andThen<A, Next extends AnyEffectValue>(next: (value: A) => Next): AndThenOperation<Next>;
90
+ declare function andThen<Input, Next extends AnyEffectValue>(effect: Input & AnyEffectValue, next: (value: EffectSuccess<Input>) => Next): ChainedOutput<Input, Next>;
91
+ /**
92
+ * Chain an asynchronous Result-producing operation after a successful result.
93
+ *
94
+ * The returned value is always a Promise and retains both operations' error
95
+ * and Service-requirement metadata.
96
+ *
97
+ * @example
98
+ * ```ts
99
+ * const user = Effect.andThenAsync(loadUser(), (user) => fetchProfile(user.id))
100
+ * ```
101
+ */
102
+ declare function andThenAsync<A, Next extends AnyAsyncEffectInput>(next: (value: A) => Next): AndThenAsyncOperation<A, Next>;
103
+ declare function andThenAsync<Input, Next extends AnyAsyncEffectInput>(effect: Input & AnyEffectInput, next: (value: EffectSuccess<Input>) => Next): AsyncChainedOutput<Input, Next>;
104
+ /** Observe a successful value without changing the Result. */
105
+ declare function tap(fn: (value: any) => void): TapOperation;
106
+ declare function tap<Input>(effect: Input & AnyEffectInput, fn: (value: EffectSuccess<Input>) => void): PreserveAsync<Input, TappedResult<Input>>;
107
+ /** Observe an error value without changing the Result. */
108
+ declare function tapError(fn: (error: any) => void): TapErrorOperation;
109
+ declare function tapError<Input>(effect: Input & AnyEffectInput, fn: (error: EffectError<Input>) => void): PreserveAsync<Input, TappedResult<Input>>;
110
+ /** Observe whichever Result branch is active without changing the Result. */
111
+ declare function tapBoth(handlers: {
112
+ ok: (value: any) => void;
113
+ err: (error: any) => void;
114
+ }): TapBothOperation;
115
+ declare function tapBoth<Input>(effect: Input & AnyEffectInput, handlers: {
116
+ ok: (value: EffectSuccess<Input>) => void;
117
+ err: (error: EffectError<Input>) => void;
118
+ }): PreserveAsync<Input, TappedResult<Input>>;
119
+ /** Recover an Err with a synchronous Result-producing callback. */
120
+ declare function recover<Next extends AnyEffectValue>(fn: (error: any) => Next): RecoverOperation<Next>;
121
+ declare function recover<Input, Next extends AnyEffectValue>(effect: Input & AnyEffectInput, fn: (error: EffectError<Input>) => Next): PreserveAsync<Input, RecoveredResult<Input, Next>>;
122
+ /** Recover an Err with an asynchronous Result-producing callback. */
123
+ declare function recoverAsync<Next extends AnyAsyncEffectInput>(fn: (error: any) => Next): RecoverAsyncOperation<Next>;
124
+ declare function recoverAsync<Input, Next extends AnyAsyncEffectInput>(effect: Input & AnyEffectInput, fn: (error: EffectError<Input>) => Next): Promise<RecoveredResult<Input, Next>>;
125
+ /** Remove one nested Result/Effect layer. */
126
+ declare function flatten<Input>(effect: Input & AnyEffectValue): FlattenedResult<Input>;
127
+ /** Replace a successful value while preserving errors and requirements. */
128
+ declare function as<Value>(value: Value): <Input>(effect: Input & AnyEffectValue) => AsResult<Input, Value>;
129
+ declare function as<Input, Value>(effect: Input & AnyEffectValue, value: Value): AsResult<Input, Value>;
130
+ /** Replace a successful value with void. */
131
+ declare function asVoid<Input>(effect: Input & AnyEffectValue): AsResult<Input, void>;
132
+ /** Match an Effect and return branch Effects with their channels unioned. */
133
+ declare function match<Input, OkResult extends AnyEffectValue, ErrResult extends AnyEffectValue>(effect: Input & AnyEffectValue, handlers: {
134
+ ok: (value: EffectSuccess<Input>) => OkResult;
135
+ err: (error: EffectError<Input>) => ErrResult;
136
+ }): PreserveAsync<Input, MatchedResult<Input, OkResult, ErrResult>>;
137
+ declare function match<Input, OkValue, ErrValue>(effect: Input & AnyEffectValue, handlers: {
138
+ ok: (value: EffectSuccess<Input>) => OkValue;
139
+ err: (error: EffectError<Input>) => ErrValue;
140
+ }): PreserveAsync<Input, OkValue | ErrValue>;
141
+ /** Collect already-created Effects in input order. */
142
+ declare function all<const Results extends readonly AnyEffectValue[]>(results: Results): AllResult<Results>;
143
+ /** Combine two already-created Effects in input order. */
144
+ declare function zip<Left, Right>(left: Left & AnyEffectValue, right: Right & AnyEffectValue): ZipResult<Left, Right>;
145
+ //#endregion
146
+ //#region src/effect/effect.d.ts
147
+ type Effect<A, E, R extends AnyService = never> = Effect$1<A, E, R>;
148
+ type LazyProgram<A, E, R extends AnyService = never> = Program$1<A, E, R>;
149
+ /** A nominal lazy computation that produces an Effect when invoked. */
150
+ type Program<A, E, R extends AnyService = never> = LazyProgram<A, E, R>;
151
+ type AnyResult = Result<any, any>;
152
+ type AnyProgram = Program$1<any, any, AnyService>;
153
+ type ProgramAllSuccess<Programs extends readonly AnyProgram[]> = { -readonly [Index in keyof Programs]: EffectSuccess<Programs[Index]>; };
154
+ type ProgramAllError<Programs extends readonly AnyProgram[]> = EffectError<Programs[number]>;
155
+ type ProgramAllRequirements<Programs extends readonly AnyProgram[]> = EffectRequirements<Programs[number]>;
156
+ type ProgramAllResult<Programs extends readonly AnyProgram[]> = Program$1<ProgramAllSuccess<Programs>, ProgramAllError<Programs>, ProgramAllRequirements<Programs>>;
157
+ type ProgramAllOptions = {
158
+ readonly concurrency?: number;
159
+ };
160
+ /**
161
+ * Compose `better-result` operations while preserving Service requirements in
162
+ * a declaration-only type channel.
163
+ *
164
+ * A generator may yield Service tokens and Result operations. It must return a
165
+ * `Result` as its final value; Service yields are resolved by the active
166
+ * Runtime and do not add runtime values to the Result stream.
167
+ * Use `fn` when generator execution should wait for a Runtime boundary.
168
+ *
169
+ * @example
170
+ * ```ts
171
+ * const loadUser = Effect.gen(async function* () {
172
+ * const database = yield* Database
173
+ * const user = yield* Result.await(database.findUser('u1'))
174
+ *
175
+ * return Result.ok(user)
176
+ * })
177
+ * ```
178
+ */
179
+ declare function gen<Yield extends EffectYield, Returned extends AnyResult>(body: () => Generator<Yield, Returned, unknown>): EffectFromGenerator<Yield, Returned>;
180
+ declare function gen<Yield extends EffectYield, Returned extends AnyResult>(body: () => AsyncGenerator<Yield, Returned, unknown>): Promise<EffectFromGenerator<Yield, Returned>>;
181
+ /** Build a lazy Program without running its generator. */
182
+ declare function fn<Yield extends EffectYield, Returned extends AnyResult>(body: () => Generator<Yield, Returned, unknown>): ProgramFromGenerator<Yield, Returned>;
183
+ declare function fn<Yield extends EffectYield, Returned extends AnyResult>(body: () => AsyncGenerator<Yield, Returned, unknown>): ProgramFromGenerator<Yield, Returned>;
184
+ /** Build a lazy Program collection with optional bounded concurrency. */
185
+ declare function programAll<const Programs extends readonly AnyProgram[]>(programs: Programs, options?: ProgramAllOptions): ProgramAllResult<Programs>;
186
+ /** Value-level namespace for lazy Program combinators. */
187
+ declare const Program: {
188
+ readonly all: typeof programAll;
189
+ };
190
+ /**
191
+ * Acquire a resource in the current Scope and register its release callback.
192
+ *
193
+ * Acquisition failures are represented in the Effect Result error channel;
194
+ * release failures remain owned by Scope cleanup. The release callback
195
+ * receives the final outcome chosen by the enclosing execution boundary.
196
+ *
197
+ * @example
198
+ * ```ts
199
+ * const connection = yield* Effect.acquireRelease(
200
+ * () => pool.connect(),
201
+ * (connection, outcome) => connection.close(outcome)
202
+ * )
203
+ * ```
204
+ */
205
+ declare function acquireRelease<R>(acquire: () => MaybePromise$1<R>, release: (resource: R, outcome: ScopeOutcome) => MaybePromise$1<void>): AsyncGenerator<Err<never, UnhandledException>, R, unknown>;
206
+ /**
207
+ * Register an already-acquired disposable resource in the current Scope.
208
+ *
209
+ * The resource is not acquired by this helper. Registration failures are
210
+ * represented in the Effect Result error channel; disposal failures remain
211
+ * owned by Scope cleanup.
212
+ *
213
+ * @example
214
+ * ```ts
215
+ * const file = yield* Effect.add(await openFile('notes.txt'))
216
+ * ```
217
+ */
218
+ declare function add<R extends DisposableResource>(resource: R): AsyncGenerator<Err<never, UnhandledException>, R, unknown>;
219
+ /**
220
+ * Effect namespace containing generator, resource, and Result combinators.
221
+ *
222
+ * Prefer these helpers when a program needs typed Service requirements or
223
+ * Scope-aware acquisition and cleanup.
224
+ */
225
+ type EffectNamespace = {
226
+ readonly gen: typeof gen;
227
+ readonly fn: typeof fn;
228
+ readonly acquireRelease: typeof acquireRelease;
229
+ readonly add: typeof add;
230
+ readonly map: typeof map;
231
+ readonly mapError: typeof mapError;
232
+ readonly andThen: typeof andThen;
233
+ readonly andThenAsync: typeof andThenAsync;
234
+ readonly tap: typeof tap;
235
+ readonly tapError: typeof tapError;
236
+ readonly tapBoth: typeof tapBoth;
237
+ readonly recover: typeof recover;
238
+ readonly recoverAsync: typeof recoverAsync;
239
+ readonly flatten: typeof flatten;
240
+ readonly as: typeof as;
241
+ readonly asVoid: typeof asVoid;
242
+ readonly match: typeof match;
243
+ readonly all: typeof all;
244
+ readonly zip: typeof zip;
245
+ };
246
+ declare const Effect: EffectNamespace;
247
+ /** Type-level aliases for inspecting Effect result channels and requirements. */
248
+ declare namespace Effect {
249
+ /** A nominal lazy computation that produces an Effect when invoked. */
250
+ type Program<A, E, R extends AnyService = never> = LazyProgram<A, E, R>;
251
+ /** Extract the success channel from an Effect result or Promise. */
252
+ type Success<T> = EffectSuccess<T>;
253
+ /** Extract the error channel from an Effect result or Promise. */
254
+ type Error<T> = EffectError<T>;
255
+ /** Extract the Service requirements from an Effect result or Promise. */
256
+ type Requirements<T> = EffectRequirements<T>;
257
+ /** An Effect with erased success, error, and requirements. */
258
+ type Any = AnyEffect;
259
+ }
260
+ //#endregion
261
+ //#region src/function/pipe.d.ts
262
+ type Unary<A, B> = (value: A) => B;
263
+ declare function pipe<A>(value: A): A;
264
+ declare function pipe<A, B>(value: A, ab: Unary<A, B>): B;
265
+ declare function pipe<A, B, C>(value: A, ab: Unary<A, B>, bc: Unary<B, C>): C;
266
+ declare function pipe<A, B, C, D>(value: A, ab: Unary<A, B>, bc: Unary<B, C>, cd: Unary<C, D>): D;
267
+ declare function pipe<A, B, C, D, E>(value: A, ab: Unary<A, B>, bc: Unary<B, C>, cd: Unary<C, D>, de: Unary<D, E>): E;
268
+ declare function pipe<A, B, C, D, E, F>(value: A, ab: Unary<A, B>, bc: Unary<B, C>, cd: Unary<C, D>, de: Unary<D, E>, ef: Unary<E, F>): F;
269
+ declare function pipe<A, B, C, D, E, F, G>(value: A, ab: Unary<A, B>, bc: Unary<B, C>, cd: Unary<C, D>, de: Unary<D, E>, ef: Unary<E, F>, fg: Unary<F, G>): G;
270
+ declare function pipe<A, B, C, D, E, F, G, H>(value: A, ab: Unary<A, B>, bc: Unary<B, C>, cd: Unary<C, D>, de: Unary<D, E>, ef: Unary<E, F>, fg: Unary<F, G>, gh: Unary<G, H>): H;
271
+ declare function pipe<A, B, C, D, E, F, G, H, I>(value: A, ab: Unary<A, B>, bc: Unary<B, C>, cd: Unary<C, D>, de: Unary<D, E>, ef: Unary<E, F>, fg: Unary<F, G>, gh: Unary<G, H>, hi: Unary<H, I>): I;
272
+ declare function pipe<A, B, C, D, E, F, G, H, I, J>(value: A, ab: Unary<A, B>, bc: Unary<B, C>, cd: Unary<C, D>, de: Unary<D, E>, ef: Unary<E, F>, fg: Unary<F, G>, gh: Unary<G, H>, hi: Unary<H, I>, ij: Unary<I, J>): J;
273
+ declare function pipe<A, B, C, D, E, F, G, H, I, J, K>(value: A, ab: Unary<A, B>, bc: Unary<B, C>, cd: Unary<C, D>, de: Unary<D, E>, ef: Unary<E, F>, fg: Unary<F, G>, gh: Unary<G, H>, hi: Unary<H, I>, ij: Unary<I, J>, jk: Unary<J, K>): K;
274
+ //#endregion
275
+ //#region src/resource/errors.d.ts
276
+ declare const ResourceReleaseFailure_base: import("better-result").TaggedErrorClass<"ResourceReleaseFailure">;
277
+ /** Describes a failure encountered while releasing a Resource. */
278
+ declare class ResourceReleaseFailure extends ResourceReleaseFailure_base<{
279
+ readonly resource: string;
280
+ readonly cause: unknown;
281
+ readonly message: string;
282
+ }> {}
283
+ //#endregion
284
+ //#region src/resource/types.d.ts
285
+ /** A value that may be delivered synchronously or through a thenable. */
286
+ type MaybePromise<T> = T | PromiseLike<T>;
287
+ /** A synchronous or asynchronous better-result Result operation. */
288
+ type AsyncResult<T, E> = MaybePromise<Result<T, E>>;
289
+ /** The allowed return value of a custom Resource release callback. */
290
+ type ReleaseOutcome = void | Result<void, unknown>;
291
+ /** Receives release failures for diagnostics without changing error precedence. */
292
+ type ReleaseFailureObserver = (failure: ResourceReleaseFailure) => MaybePromise<void>;
293
+ /** Options controlling `Resource.acquireUseRelease`. */
294
+ type AcquireUseReleaseOptions<R, A, AcquireError, UseError> = {
295
+ /** Human-readable name included in release failures. */
296
+ readonly name: string;
297
+ /** Acquire the resource. A failure skips use and release. */
298
+ readonly acquire: () => AsyncResult<R, AcquireError>;
299
+ /** Use the acquired resource. Release is attempted afterward. */
300
+ readonly use: (resource: R) => AsyncResult<A, UseError>;
301
+ /** Release the resource, or omit it to use its disposal protocol. */
302
+ readonly release?: (resource: R) => MaybePromise<ReleaseOutcome>;
303
+ /**
304
+ * Observe cleanup failures without changing error precedence. This is most
305
+ * useful when both `use` and `release` can fail.
306
+ */
307
+ readonly onReleaseFailure?: ReleaseFailureObserver;
308
+ };
309
+ //#endregion
310
+ //#region src/resource/resource.d.ts
311
+ declare const Resource: {
312
+ /** Acquire, use, and release a resource with deterministic error precedence. */
313
+ readonly acquireUseRelease: <R, A, AcquireError, UseError>({ name, acquire, use, release, onReleaseFailure }: AcquireUseReleaseOptions<R, A, AcquireError, UseError>) => Promise<Result<A, AcquireError | UseError | UnhandledException | ResourceReleaseFailure>>;
314
+ };
315
+ //#endregion
316
+ //#region src/runtime/types.d.ts
317
+ /**
318
+ * Name a Runtime type from a concrete Layer without repeating its provided
319
+ * branded Service instance union.
320
+ *
321
+ * @example
322
+ * ```ts
323
+ * type AppRuntime = RuntimeFor<typeof AppLive>
324
+ * ```
325
+ */
326
+ type RuntimeFor<L extends LayerInput> = Runtime<Layer.Provided<L>>;
327
+ //#endregion
328
+ //#region src/runtime/runtime.d.ts
329
+ /**
330
+ * Long-lived execution environment backed by a complete Layer.
331
+ *
332
+ * A Runtime owns Layer resources until `dispose()` is called. Each `run()` is
333
+ * isolated in a child Scope, while Layer-scoped resources remain shared.
334
+ *
335
+ * @example
336
+ * ```ts
337
+ * const runtime = await Runtime.make(AppLive)
338
+ * const result = await runtime.run(loadUser('u1'))
339
+ * await runtime.dispose()
340
+ * ```
341
+ *
342
+ * @typeParam Provided The branded Service instances supplied by the Layer.
343
+ */
344
+ declare class Runtime<Provided extends AnyService = any> {
345
+ private readonly handle;
346
+ private constructor();
347
+ /**
348
+ * Create a long-lived Runtime that owns its Layer resources.
349
+ *
350
+ * @example
351
+ * ```ts
352
+ * const runtime = await Runtime.make(AppLive)
353
+ * const result = await runtime.run(program)
354
+ * await runtime.dispose()
355
+ * ```
356
+ */
357
+ static make<L extends LayerInput>(layer: L & CompleteInput<L>, backend: LayerBackend, options?: RuntimeOptions): Promise<Runtime<ProvidedEnvironment<L>>>;
358
+ static make<L extends LayerInput>(layer: L & CompleteInput<L>, options?: RuntimeOptions): Promise<Runtime<ProvidedEnvironment<L>>>;
359
+ /**
360
+ * Run one program and dispose its Layer resources before resolving.
361
+ *
362
+ * This is convenient for request-style or command-style execution where a
363
+ * Runtime should not outlive the operation.
364
+ */
365
+ static run<A, L extends LayerInput>(layer: L & CompleteInput<L>, backend: LayerBackend, program: CompleteExecution<ProvidedEnvironment<L>, A>, options?: RuntimeOptions): Promise<Awaited<A>>;
366
+ static run<A, L extends LayerInput>(layer: L & CompleteInput<L>, program: CompleteExecution<ProvidedEnvironment<L>, A>, options?: RuntimeOptions): Promise<Awaited<A>>;
367
+ static run<A, L extends LayerInput>(layer: L & CompleteInput<L>, options: RuntimeOptions, program: CompleteExecution<ProvidedEnvironment<L>, A>): Promise<Awaited<A>>;
368
+ /** Run a callback with a managed Runtime and always dispose it afterward. */
369
+ static use<A, L extends LayerInput>(layer: L & CompleteInput<L>, use: (runtime: Runtime<ProvidedEnvironment<L>>) => A | PromiseLike<A>, options?: RuntimeOptions): Promise<Awaited<A>>;
370
+ /** Resolve every Layer provider and dispose the Runtime if warmup fails. */
371
+ warmup(): Promise<void>;
372
+ /** Run one execution in this Runtime's child Scope. */
373
+ run<A>(program: CompleteExecution<Provided, A>, options?: RuntimeRunOptions): Promise<Awaited<A>>;
374
+ /** Run one execution with a Layer owned by that execution's child Scope. */
375
+ runWith<Request extends LayerInput, A>(layer: Request & CompleteExecutionLayer<Provided, Request>, program: CompleteExecution<Provided | ProvidedEnvironment<Request>, A>, options?: RuntimeRunOptions): Promise<Awaited<A>>;
376
+ private runUnchecked;
377
+ /** Stop new executions and release the Runtime's Layer resources. */
378
+ dispose(options?: RuntimeDisposeOptions): Promise<void>;
379
+ /** @deprecated Scope outcomes are kept for internal compatibility. */
380
+ dispose(outcome: ScopeOutcome): Promise<void>;
381
+ /** Release Runtime-owned resources through JavaScript's async disposal protocol. */
382
+ [Symbol.asyncDispose](): Promise<void>;
383
+ private disposeWithOutcome;
384
+ }
385
+ /** Type-level aliases for naming Runtime handles and shutdown options. */
386
+ declare namespace Runtime {
387
+ /** Name a Runtime type from a concrete Layer. */
388
+ type For<L extends LayerInput> = RuntimeFor<L>;
389
+ /** Optional Runtime shutdown configuration. */
390
+ type Options = RuntimeOptions;
391
+ /** Optional signal supplied to one managed Runtime execution. */
392
+ type RunOptions = RuntimeRunOptions;
393
+ /** Cooperative shutdown policy for a managed Runtime. */
394
+ type DisposeOptions = RuntimeDisposeOptions;
395
+ /** Diagnostic reported for aggregated Runtime shutdown cleanup failures. */
396
+ type ShutdownDiagnostic = RuntimeShutdownDiagnostic;
397
+ }
398
+ //#endregion
399
+ //#region src/runtime/signal.d.ts
400
+ /** Yieldable access to the signal of the current Runtime execution. */
401
+ declare const CurrentAbortSignal: {
402
+ readonly [Symbol.iterator]: () => Generator<never, AbortSignal, unknown>;
403
+ };
404
+ //#endregion
405
+ export { AcquireUseReleaseOptions as a, ReleaseOutcome as c, Effect as d, Program as f, Resource as i, ResourceReleaseFailure as l, Runtime as n, AsyncResult as o, ProgramAllOptions as p, RuntimeFor as r, ReleaseFailureObserver as s, CurrentAbortSignal as t, pipe as u };
406
+ //# sourceMappingURL=index-yOfq7LKL.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-yOfq7LKL.d.mts","names":[],"sources":["../src/effect/combinators.ts","../src/effect/effect.ts","../src/function/pipe.ts","../src/resource/errors.ts","../src/resource/types.ts","../src/resource/resource.ts","../src/runtime/types.ts","../src/runtime/runtime.ts","../src/runt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