better-effect 0.3.0 → 0.5.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 +167 -486
- package/dist/adapters/iti.d.mts +11 -3
- package/dist/adapters/iti.d.mts.map +1 -1
- package/dist/adapters/iti.mjs +34 -14
- package/dist/adapters/iti.mjs.map +1 -1
- package/dist/errors-GR3K_nRu.mjs +74 -0
- package/dist/errors-GR3K_nRu.mjs.map +1 -0
- package/dist/index-D77AvuBl.d.mts +510 -0
- package/dist/index-D77AvuBl.d.mts.map +1 -0
- package/dist/index.d.mts +263 -13
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +444 -106
- package/dist/index.mjs.map +1 -1
- package/dist/internal-identity-BnZC3Au-.mjs +26 -0
- package/dist/internal-identity-BnZC3Au-.mjs.map +1 -0
- package/dist/testing.d.mts +11 -2
- package/dist/testing.d.mts.map +1 -1
- package/dist/testing.mjs +33 -12
- package/dist/testing.mjs.map +1 -1
- package/package.json +6 -9
- package/dist/errors-CnvKqBpb.mjs +0 -63
- package/dist/errors-CnvKqBpb.mjs.map +0 -1
- package/dist/index-Bg6ofRE1.d.mts +0 -232
- package/dist/index-Bg6ofRE1.d.mts.map +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,28 +1,148 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { A as ServiceResolver, B as ServiceRequirement, C as ScopeOutcome, D as ScopeRuntimeNotConfiguredError, E as ScopeClosedError, F as EffectFromGenerator, G as ServiceTag, H as ServiceClass, I as EffectRequirements, K as ServiceToken, L as EffectResult, M as Service, N as AnyEffectResult, O as ServiceNotFoundError, P as EffectError, R as EffectSuccess, S as ScopeFinalizer, T as ScopeCloseError, U as ServiceInstance, V as AnyServiceToken, W as ServiceRequirements, _ as LayerSpecs, a as DuplicateServiceError, b as DisposableResource, c as LayerRegistrationError, d as AnyLayer, f as CompleteExecution, g as LayerRawRequired, h as LayerProvided, i as RuntimeShutdownDiagnostic, j as ServiceRuntime, k as ServiceRuntimeNotConfiguredError, l as ServiceTagCollisionError, m as LayerMissing, n as CleanupFailureObserver, o as LayerDisposeError, p as CompleteLayer, r as RuntimeOptions, s as LayerGeneratorYieldError, t as LayerBackend, u as Layer, v as LayerRegistration, w as ResourceNotDisposableError, x as MaybePromise$1, y as CleanupFailureDiagnostic, z as EffectYield } from "./index-D77AvuBl.mjs";
|
|
2
2
|
import { Err, Result, UnhandledException } from "better-result";
|
|
3
3
|
//#region src/scope/scope.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Non-owning lifecycle context for finalizers and child Scopes.
|
|
6
|
+
*
|
|
7
|
+
* A Scope can register cleanup and create children, but it cannot close
|
|
8
|
+
* itself. Use `Scope.make()` or `Scope.run()` when your code owns the Scope.
|
|
9
|
+
*/
|
|
4
10
|
interface Scope {
|
|
11
|
+
/** Register a finalizer that runs when the owning Scope closes. */
|
|
5
12
|
addFinalizer(finalizer: ScopeFinalizer): void;
|
|
13
|
+
/** Acquire a resource and register its outcome-aware release callback. */
|
|
6
14
|
acquire<R>(acquire: () => MaybePromise$1<R>, release: (resource: R, outcome: ScopeOutcome) => MaybePromise$1<void>): Promise<R>;
|
|
15
|
+
/** Register an already-acquired disposable resource. */
|
|
7
16
|
add<R extends DisposableResource>(resource: R): Promise<R>;
|
|
17
|
+
/** Create a child Scope owned by this Scope. */
|
|
8
18
|
fork(): CloseableScope;
|
|
9
19
|
}
|
|
20
|
+
/** A Scope whose owner is responsible for calling `close()`. */
|
|
10
21
|
interface CloseableScope extends Scope {
|
|
22
|
+
/** Close the Scope and run children and finalizers in child-first LIFO order. */
|
|
11
23
|
close(outcome?: ScopeOutcome): Promise<void>;
|
|
12
24
|
}
|
|
13
25
|
declare const Scope: {
|
|
26
|
+
/** Create an owned, initially open Scope. */
|
|
14
27
|
readonly make: () => CloseableScope;
|
|
28
|
+
/** Return the non-owning Scope available in the current execution context. */
|
|
15
29
|
readonly current: () => Scope;
|
|
30
|
+
/** Run a callback with an existing Scope supplied as the current context. */
|
|
16
31
|
readonly provide: <A>(scope: Scope, program: () => A) => A;
|
|
32
|
+
/** Resolve the current Scope through `yield* Scope` inside an Effect. */
|
|
17
33
|
readonly [Symbol.iterator]: () => Generator<never, Scope, unknown>;
|
|
34
|
+
/**
|
|
35
|
+
* Run a program in a newly owned Scope.
|
|
36
|
+
*
|
|
37
|
+
* Scope is independent from `better-result`, so returned values—including
|
|
38
|
+
* `Result.err`—close this Scope with a successful outcome. Result-aware
|
|
39
|
+
* outcome classification belongs to `Runtime.run`.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* await Scope.run(async (scope) => {
|
|
44
|
+
* const connection = await scope.acquire(connect, (connection) => connection.close())
|
|
45
|
+
* return connection.query()
|
|
46
|
+
* })
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
18
49
|
readonly run: <A>(program: (scope: Scope) => A | PromiseLike<A>) => Promise<Awaited<A>>;
|
|
19
50
|
};
|
|
20
51
|
//#endregion
|
|
52
|
+
//#region src/effect/combinators.d.ts
|
|
53
|
+
type EffectInput<A, E, Requirements> = EffectResult<A, E, Requirements> | PromiseLike<EffectResult<A, E, Requirements>>;
|
|
54
|
+
type AnyEffectInput = EffectInput<any, any, any>;
|
|
55
|
+
type AnyEffectResult$1 = EffectResult<any, any, any>;
|
|
56
|
+
type AnyAsyncEffectInput = PromiseLike<AnyEffectResult$1>;
|
|
57
|
+
type PreserveAsync<Input, Output> = Input extends PromiseLike<unknown> ? Promise<Output> : Output;
|
|
58
|
+
type MappedResult<Input, B> = EffectResult<B, EffectError<Input>, EffectRequirements<Input>>;
|
|
59
|
+
type ErrorMappedResult<Input, E2> = EffectResult<EffectSuccess<Input>, E2, EffectRequirements<Input>>;
|
|
60
|
+
type ChainedResult<First, Next> = EffectResult<EffectSuccess<Next>, EffectError<First> | EffectError<Next>, EffectRequirements<First> | EffectRequirements<Next>>;
|
|
61
|
+
type ChainedOutput<First, Next> = ChainedResult<First, Next>;
|
|
62
|
+
type AsyncChainedOutput<First, Next> = Promise<ChainedResult<First, Next>>;
|
|
63
|
+
type MapOperation<A, B> = {
|
|
64
|
+
<Input>(effect: Input & EffectInput<A, any, any>): PreserveAsync<Input, MappedResult<Input, B>>;
|
|
65
|
+
};
|
|
66
|
+
type MapErrorOperation<E1, E2> = {
|
|
67
|
+
<Input>(effect: Input & EffectInput<any, E1, any>): PreserveAsync<Input, ErrorMappedResult<Input, E2>>;
|
|
68
|
+
};
|
|
69
|
+
type AndThenOperation<A, Next> = {
|
|
70
|
+
<Input>(effect: Input & EffectResult<A, any, any>): ChainedOutput<Input, Next>;
|
|
71
|
+
};
|
|
72
|
+
type AndThenAsyncOperation<A, Next> = {
|
|
73
|
+
<Input>(effect: Input & EffectInput<A, any, any>): AsyncChainedOutput<Input, Next>;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Map the successful value of a Result or Effect result.
|
|
77
|
+
*
|
|
78
|
+
* Supports both data-first and data-last forms and preserves asynchronous
|
|
79
|
+
* results and phantom Service requirements.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* const doubled = Effect.map(Result.ok(2), (value) => value * 2)
|
|
84
|
+
* const toLabel = Effect.map((value: number) => `#${value}`)
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
declare function map<A, B>(fn: (value: A) => B): MapOperation<A, B>;
|
|
88
|
+
declare function map<Input, B>(effect: Input & AnyEffectInput, fn: (value: EffectSuccess<Input>) => B): PreserveAsync<Input, MappedResult<Input, B>>;
|
|
89
|
+
/**
|
|
90
|
+
* Map the error value of a Result or Effect result while preserving its
|
|
91
|
+
* successful value, asynchronous shape, and Service requirements.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* const labelled = Effect.mapError(Result.err('missing'), (error) => ({ error }))
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
declare function mapError<E1, E2>(fn: (error: E1) => E2): MapErrorOperation<E1, E2>;
|
|
99
|
+
declare function mapError<Input, E2>(effect: Input & AnyEffectInput, fn: (error: EffectError<Input>) => E2): PreserveAsync<Input, ErrorMappedResult<Input, E2>>;
|
|
100
|
+
/**
|
|
101
|
+
* Chain a synchronous Result-producing operation after a successful result.
|
|
102
|
+
*
|
|
103
|
+
* The next operation is skipped when the input is an error. Both error types
|
|
104
|
+
* and both sets of Service requirements are preserved in the output.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```ts
|
|
108
|
+
* const user = Effect.andThen(Result.ok('u1'), (id) => repository.find(id))
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
declare function andThen<A, Next extends AnyEffectResult$1>(next: (value: A) => Next): AndThenOperation<A, Next>;
|
|
112
|
+
declare function andThen<Input, Next extends AnyEffectResult$1>(effect: Input & AnyEffectResult$1, next: (value: EffectSuccess<Input>) => Next): ChainedOutput<Input, Next>;
|
|
113
|
+
/**
|
|
114
|
+
* Chain an asynchronous Result-producing operation after a successful result.
|
|
115
|
+
*
|
|
116
|
+
* The returned value is always a Promise and retains both operations' error
|
|
117
|
+
* and Service-requirement metadata.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* const user = Effect.andThenAsync(loadUser(), (user) => fetchProfile(user.id))
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
declare function andThenAsync<A, Next extends AnyAsyncEffectInput>(next: (value: A) => Next): AndThenAsyncOperation<A, Next>;
|
|
125
|
+
declare function andThenAsync<Input, Next extends AnyAsyncEffectInput>(effect: Input & AnyEffectInput, next: (value: EffectSuccess<Input>) => Next): AsyncChainedOutput<Input, Next>;
|
|
126
|
+
//#endregion
|
|
21
127
|
//#region src/effect/effect.d.ts
|
|
22
128
|
type AnyResult = Result<any, any>;
|
|
23
129
|
/**
|
|
24
|
-
* Compose better-result operations while preserving Service requirements in
|
|
130
|
+
* Compose `better-result` operations while preserving Service requirements in
|
|
25
131
|
* a phantom type channel.
|
|
132
|
+
*
|
|
133
|
+
* A generator may yield Service tokens and Result operations. It must return a
|
|
134
|
+
* `Result` as its final value; Service yields are resolved by the active
|
|
135
|
+
* Runtime and do not add runtime values to the Result stream.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```ts
|
|
139
|
+
* const loadUser = Effect.gen(async function* () {
|
|
140
|
+
* const database = yield* Database
|
|
141
|
+
* const user = yield* Result.await(database.findUser('u1'))
|
|
142
|
+
*
|
|
143
|
+
* return Result.ok(user)
|
|
144
|
+
* })
|
|
145
|
+
* ```
|
|
26
146
|
*/
|
|
27
147
|
declare function gen<Yield extends EffectYield, Returned extends AnyResult>(body: () => Generator<Yield, Returned, unknown>): EffectFromGenerator<Yield, Returned>;
|
|
28
148
|
declare function gen<Yield extends EffectYield, Returned extends AnyResult>(body: () => AsyncGenerator<Yield, Returned, unknown>): Promise<EffectFromGenerator<Yield, Returned>>;
|
|
@@ -30,24 +150,86 @@ declare function gen<Yield extends EffectYield, Returned extends AnyResult>(body
|
|
|
30
150
|
* Acquire a resource in the current Scope and register its release callback.
|
|
31
151
|
*
|
|
32
152
|
* Acquisition failures are represented in the Effect Result error channel;
|
|
33
|
-
* release failures remain owned by Scope cleanup.
|
|
153
|
+
* release failures remain owned by Scope cleanup. The release callback
|
|
154
|
+
* receives the final outcome chosen by the enclosing execution boundary.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```ts
|
|
158
|
+
* const connection = yield* Effect.acquireRelease(
|
|
159
|
+
* () => pool.connect(),
|
|
160
|
+
* (connection, outcome) => connection.close(outcome)
|
|
161
|
+
* )
|
|
162
|
+
* ```
|
|
34
163
|
*/
|
|
35
164
|
declare function acquireRelease<R>(acquire: () => MaybePromise$1<R>, release: (resource: R, outcome: ScopeOutcome) => MaybePromise$1<void>): AsyncGenerator<Err<never, UnhandledException>, R, unknown>;
|
|
36
165
|
/**
|
|
37
166
|
* Register an already-acquired disposable resource in the current Scope.
|
|
38
167
|
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
168
|
+
* The resource is not acquired by this helper. Registration failures are
|
|
169
|
+
* represented in the Effect Result error channel; disposal failures remain
|
|
170
|
+
* owned by Scope cleanup.
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```ts
|
|
174
|
+
* const file = yield* Effect.add(await openFile('notes.txt'))
|
|
175
|
+
* ```
|
|
41
176
|
*/
|
|
42
177
|
declare function add<R extends DisposableResource>(resource: R): AsyncGenerator<Err<never, UnhandledException>, R, unknown>;
|
|
178
|
+
/**
|
|
179
|
+
* Effect namespace containing generator, resource, and Result combinators.
|
|
180
|
+
*
|
|
181
|
+
* Prefer these helpers when a program needs typed Service requirements or
|
|
182
|
+
* Scope-aware acquisition and cleanup.
|
|
183
|
+
*/
|
|
43
184
|
declare const Effect: {
|
|
185
|
+
/** Compose a generator-based Effect program. */
|
|
44
186
|
readonly gen: typeof gen;
|
|
187
|
+
/** Acquire and register a resource in the current Scope. */
|
|
45
188
|
readonly acquireRelease: typeof acquireRelease;
|
|
189
|
+
/** Register an already-acquired disposable in the current Scope. */
|
|
46
190
|
readonly add: typeof add;
|
|
191
|
+
/** Map a successful Effect result. */
|
|
192
|
+
readonly map: typeof map;
|
|
193
|
+
/** Map an Effect error. */
|
|
194
|
+
readonly mapError: typeof mapError;
|
|
195
|
+
/** Chain a synchronous Effect result. */
|
|
196
|
+
readonly andThen: typeof andThen;
|
|
197
|
+
/** Chain an asynchronous Effect result. */
|
|
198
|
+
readonly andThenAsync: typeof andThenAsync;
|
|
47
199
|
};
|
|
48
200
|
//#endregion
|
|
201
|
+
//#region src/function/pipe.d.ts
|
|
202
|
+
type Unary<A, B> = (value: A) => B;
|
|
203
|
+
/**
|
|
204
|
+
* Compose a value through a sequence of unary functions.
|
|
205
|
+
*
|
|
206
|
+
* `pipe` is deliberately independent of Effect, Result, Promise, Scope, and
|
|
207
|
+
* Service metadata.
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```ts
|
|
211
|
+
* const label = pipe(
|
|
212
|
+
* 'alice',
|
|
213
|
+
* (name) => name.trim(),
|
|
214
|
+
* (name) => name.toUpperCase()
|
|
215
|
+
* )
|
|
216
|
+
* ```
|
|
217
|
+
*/
|
|
218
|
+
declare function pipe<A>(value: A): A;
|
|
219
|
+
declare function pipe<A, B>(value: A, ab: Unary<A, B>): B;
|
|
220
|
+
declare function pipe<A, B, C>(value: A, ab: Unary<A, B>, bc: Unary<B, C>): C;
|
|
221
|
+
declare function pipe<A, B, C, D>(value: A, ab: Unary<A, B>, bc: Unary<B, C>, cd: Unary<C, D>): D;
|
|
222
|
+
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;
|
|
223
|
+
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;
|
|
224
|
+
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;
|
|
225
|
+
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;
|
|
226
|
+
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;
|
|
227
|
+
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;
|
|
228
|
+
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;
|
|
229
|
+
//#endregion
|
|
49
230
|
//#region src/resource/errors.d.ts
|
|
50
231
|
declare const ResourceReleaseFailure_base: import("better-result").TaggedErrorClass<"ResourceReleaseFailure">;
|
|
232
|
+
/** Describes a failure encountered while releasing a Resource. */
|
|
51
233
|
declare class ResourceReleaseFailure extends ResourceReleaseFailure_base<{
|
|
52
234
|
readonly resource: string;
|
|
53
235
|
readonly cause: unknown;
|
|
@@ -55,46 +237,114 @@ declare class ResourceReleaseFailure extends ResourceReleaseFailure_base<{
|
|
|
55
237
|
}> {}
|
|
56
238
|
//#endregion
|
|
57
239
|
//#region src/resource/types.d.ts
|
|
240
|
+
/** A value that may be delivered synchronously or through a thenable. */
|
|
58
241
|
type MaybePromise<T> = T | PromiseLike<T>;
|
|
242
|
+
/** A synchronous or asynchronous better-result Result operation. */
|
|
59
243
|
type AsyncResult<T, E> = MaybePromise<Result<T, E>>;
|
|
244
|
+
/** The allowed return value of a custom Resource release callback. */
|
|
60
245
|
type ReleaseOutcome = void | Result<void, unknown>;
|
|
246
|
+
/** Receives release failures for diagnostics without changing error precedence. */
|
|
61
247
|
type ReleaseFailureObserver = (failure: ResourceReleaseFailure) => MaybePromise<void>;
|
|
248
|
+
/** Options controlling `Resource.acquireUseRelease`. */
|
|
62
249
|
type AcquireUseReleaseOptions<R, A, AcquireError, UseError> = {
|
|
250
|
+
/** Human-readable name included in release failures. */
|
|
63
251
|
readonly name: string;
|
|
252
|
+
/** Acquire the resource. A failure skips use and release. */
|
|
64
253
|
readonly acquire: () => AsyncResult<R, AcquireError>;
|
|
254
|
+
/** Use the acquired resource. Release is attempted afterward. */
|
|
65
255
|
readonly use: (resource: R) => AsyncResult<A, UseError>;
|
|
256
|
+
/** Release the resource, or omit it to use its disposal protocol. */
|
|
66
257
|
readonly release?: (resource: R) => MaybePromise<ReleaseOutcome>;
|
|
67
258
|
/**
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* Útil principalmente quando use
|
|
72
|
-
* e release falham juntos.
|
|
259
|
+
* Observe cleanup failures without changing error precedence. This is most
|
|
260
|
+
* useful when both `use` and `release` can fail.
|
|
73
261
|
*/
|
|
74
262
|
readonly onReleaseFailure?: ReleaseFailureObserver;
|
|
75
263
|
};
|
|
76
264
|
//#endregion
|
|
77
265
|
//#region src/resource/resource.d.ts
|
|
266
|
+
/**
|
|
267
|
+
* Acquire a resource, use it, and always attempt release afterward.
|
|
268
|
+
*
|
|
269
|
+
* Acquisition, use, and release may be synchronous or asynchronous Result
|
|
270
|
+
* operations. If both use and release fail, the use error remains primary and
|
|
271
|
+
* `onReleaseFailure` receives the cleanup failure as a diagnostic.
|
|
272
|
+
*
|
|
273
|
+
* When `release` is omitted, `Symbol.asyncDispose` is preferred over
|
|
274
|
+
* `Symbol.dispose`.
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
* ```ts
|
|
278
|
+
* const result = await Resource.acquireUseRelease({
|
|
279
|
+
* name: 'database connection',
|
|
280
|
+
* acquire: () => connect(),
|
|
281
|
+
* use: (connection) => query(connection),
|
|
282
|
+
* release: (connection) => connection.close()
|
|
283
|
+
* })
|
|
284
|
+
* ```
|
|
285
|
+
*/
|
|
78
286
|
declare const acquireUseRelease: <R, A, AcquireError, UseError>({ name, acquire, use, release, onReleaseFailure }: AcquireUseReleaseOptions<R, A, AcquireError, UseError>) => Promise<Result<A, AcquireError | UseError | UnhandledException | ResourceReleaseFailure>>;
|
|
79
287
|
declare const Resource: {
|
|
288
|
+
/** Acquire, use, and release a resource with deterministic error precedence. */
|
|
80
289
|
readonly acquireUseRelease: typeof acquireUseRelease;
|
|
81
290
|
};
|
|
82
291
|
//#endregion
|
|
83
292
|
//#region src/runtime/runtime.d.ts
|
|
293
|
+
/**
|
|
294
|
+
* Long-lived execution environment backed by a complete Layer.
|
|
295
|
+
*
|
|
296
|
+
* A Runtime owns Layer resources until `dispose()` is called. Each `run()` is
|
|
297
|
+
* isolated in a child Scope, while Layer-scoped resources remain shared.
|
|
298
|
+
*
|
|
299
|
+
* @example
|
|
300
|
+
* ```ts
|
|
301
|
+
* const runtime = await Runtime.make(AppLive, new MemoryLayerBackend())
|
|
302
|
+
* const result = await runtime.run(loadUser('u1'))
|
|
303
|
+
* await runtime.dispose()
|
|
304
|
+
* ```
|
|
305
|
+
*
|
|
306
|
+
* @typeParam Provided The Service constructors supplied by the Layer.
|
|
307
|
+
*/
|
|
84
308
|
declare class Runtime<Provided extends AnyServiceToken = AnyServiceToken> {
|
|
85
|
-
private readonly
|
|
309
|
+
private readonly handle;
|
|
86
310
|
private constructor();
|
|
311
|
+
/**
|
|
312
|
+
* Create a long-lived Runtime that owns its Layer resources.
|
|
313
|
+
*
|
|
314
|
+
* @example
|
|
315
|
+
* ```ts
|
|
316
|
+
* const runtime = await Runtime.make(AppLive, backend)
|
|
317
|
+
* const result = await runtime.run(program)
|
|
318
|
+
* await runtime.dispose()
|
|
319
|
+
* ```
|
|
320
|
+
*/
|
|
87
321
|
static make<L extends AnyLayer>(layer: CompleteLayer<L>, backend: LayerBackend, options?: RuntimeOptions): Promise<Runtime<LayerProvided<L>>>;
|
|
322
|
+
/**
|
|
323
|
+
* Run one program and dispose its Layer resources before resolving.
|
|
324
|
+
*
|
|
325
|
+
* This is convenient for request-style or command-style execution where a
|
|
326
|
+
* Runtime should not outlive the operation.
|
|
327
|
+
*/
|
|
88
328
|
static run<A, L extends AnyLayer>(layer: CompleteLayer<L>, backend: LayerBackend, program: CompleteExecution<LayerProvided<L>, A>, options?: RuntimeOptions): Promise<Awaited<A>>;
|
|
329
|
+
/** Run one execution in this Runtime's child Scope. */
|
|
89
330
|
run<A>(program: CompleteExecution<Provided, A>): Promise<Awaited<A>>;
|
|
90
331
|
private runUnchecked;
|
|
332
|
+
/** Stop new executions and release the Runtime's Layer resources. */
|
|
91
333
|
dispose(): Promise<void>;
|
|
92
334
|
private disposeWithOutcome;
|
|
93
335
|
}
|
|
94
336
|
//#endregion
|
|
95
337
|
//#region src/runtime/types.d.ts
|
|
96
|
-
/**
|
|
338
|
+
/**
|
|
339
|
+
* Name a Runtime type from a concrete Layer without repeating its provided
|
|
340
|
+
* Service constructor union.
|
|
341
|
+
*
|
|
342
|
+
* @example
|
|
343
|
+
* ```ts
|
|
344
|
+
* type AppRuntime = RuntimeFor<typeof AppLive>
|
|
345
|
+
* ```
|
|
346
|
+
*/
|
|
97
347
|
type RuntimeFor<L extends AnyLayer> = Runtime<LayerProvided<L>>;
|
|
98
348
|
//#endregion
|
|
99
|
-
export { type AcquireUseReleaseOptions, type AnyEffectResult, type AnyServiceToken, type AsyncResult, type
|
|
349
|
+
export { type AcquireUseReleaseOptions, type AnyEffectResult, type AnyServiceToken, type AsyncResult, type CleanupFailureDiagnostic, type CleanupFailureObserver, type CloseableScope, type DisposableResource, DuplicateServiceError, Effect, type EffectError, type EffectRequirements, type EffectResult, type EffectSuccess, type EffectYield, Layer, type LayerBackend, LayerDisposeError, LayerGeneratorYieldError, type LayerMissing, type LayerProvided, type LayerRawRequired, type LayerRegistration, LayerRegistrationError, type LayerSpecs, type ReleaseFailureObserver, type ReleaseOutcome, Resource, ResourceNotDisposableError, ResourceReleaseFailure, Runtime, type RuntimeFor, type RuntimeOptions, type RuntimeShutdownDiagnostic, Scope, ScopeCloseError, ScopeClosedError, type ScopeFinalizer, type ScopeOutcome, ScopeRuntimeNotConfiguredError, Service, type ServiceClass, type ServiceInstance, ServiceNotFoundError, type ServiceRequirement, type ServiceRequirements, type ServiceResolver, ServiceRuntime, ServiceRuntimeNotConfiguredError, type ServiceTag, ServiceTagCollisionError, type ServiceToken, pipe };
|
|
100
350
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/scope/scope.ts","../src/effect/effect.ts","../src/resource/errors.ts","../src/resource/types.ts","../src/resource/resource.ts","../src/runtime/runtime.ts","../src/runtime/types.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/scope/scope.ts","../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/runtime.ts","../src/runtime/types.ts"],"mappings":";;;;;;;;;UAgBiB;;EAEf,aAAa,WAAW;;EAGxB,QAAQ,GACN,eAAe,eAAa,IAC5B,UAAU,UAAU,GAAG,SAAS,iBAAiB,uBAChD,QAAQ;;EAGX,IAAI,UAAU,oBAAoB,UAAU,IAAI,QAAQ;;EAGxD,QAAQ;;;UAIO,uBAAuB;;EAEtC,MAAM,UAAU,eAAe;;cAgKpB;;WAEH,YAAA;;WAKG,eAAA;;WAKH,UAAA,GAAC,OAAS,OAAK,eAAiB,MAAI;;YAMtB,OAAA,iBAAA,iBAAiB;;;;;;;;;;;;;;;;WAmBnC,MAAA,GAAC,UAAY,OAAO,UAAU,IAAI,YAAY,OAAK,QAAQ,QAAQ;;;;KCnOpE,YAAY,GAAG,GAAG,gBACnB,aAAa,GAAG,GAAG,gBACnB,YAAY,aAAa,GAAG,GAAG;KAE9B,iBAAiB;KACjB,oBAAkB;KAClB,sBAAsB,YAAY;KAElC,cAAc,OAAO,UAAU,cAAc,uBAAuB,QAAQ,UAAU;KAEtF,aAAa,OAAO,KAAK,aAAa,GAAG,YAAY,QAAQ,mBAAmB;KAEhF,kBAAkB,OAAO,MAAM,aAClC,cAAc,QACd,IACA,mBAAmB;KAGhB,cAAc,OAAO,QAAQ,aAChC,cAAc,OACd,YAAY,SAAS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