better-effect 0.6.0 → 0.6.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.
- package/README.md +24 -14
- package/dist/adapters/iti.d.mts +2 -1
- package/dist/adapters/iti.d.mts.map +1 -1
- package/dist/adapters/iti.mjs +1 -2
- package/dist/adapters/iti.mjs.map +1 -1
- package/dist/{index-DMfjhNR_.d.mts → index-R3FdVmdr.d.mts} +14 -217
- package/dist/index-R3FdVmdr.d.mts.map +1 -0
- package/dist/index.d.mts +30 -17
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +77 -30
- package/dist/index.mjs.map +1 -1
- package/dist/internal-identity-Cm4-KIUj.mjs +122 -0
- package/dist/internal-identity-Cm4-KIUj.mjs.map +1 -0
- package/dist/map-layer-backend-7hQkf_QP.d.mts +287 -0
- package/dist/map-layer-backend-7hQkf_QP.d.mts.map +1 -0
- package/dist/map-layer-backend-BodcEeNA.mjs +52 -0
- package/dist/map-layer-backend-BodcEeNA.mjs.map +1 -0
- package/dist/testing.d.mts +2 -22
- package/dist/testing.mjs +2 -58
- package/package.json +1 -1
- package/dist/errors-GR3K_nRu.mjs +0 -74
- package/dist/errors-GR3K_nRu.mjs.map +0 -1
- package/dist/index-DMfjhNR_.d.mts.map +0 -1
- package/dist/internal-identity-C6Awrc33.mjs +0 -27
- package/dist/internal-identity-C6Awrc33.mjs.map +0 -1
- package/dist/testing.d.mts.map +0 -1
- package/dist/testing.mjs.map +0 -1
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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/types.ts","../src/runtime/runtime.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/types.ts","../src/runtime/runtime.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;;;kBAUhD;;OAEX,YAAY;;OAGZ,UAAU;;OAGV,YAAY;;OAGZ,aAAa;;;;KCtPtB,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,QAAQ,cAAc,OAAO;KAE/D,aAAa,GAAG;GAClB,OAAO,QAAQ,QAAQ,YAAY,UAAU,cAAc,OAAO,aAAa,OAAO;;KAGpF,kBAAkB,IAAI;GACxB,OAAO,QAAQ,QAAQ,iBAAiB,MAAM,cAAc,OAAO,k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GAAG,SAAS,kBAAkB,UAAU,KAAK,QAAQ,QAAQ;UAIzD;;EAMR,WAAW;UAIH;;;kBAMe;;OAEX,IAAI,UAAU,cAAc,WAAW;;OAGvC,UAAU;;OAGV,qBAAqB"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as LayerRegistrationError, c as ServiceAcquisitionError, i as LayerGeneratorYieldError, l as ServiceNotFoundError, n as DuplicateServiceError, o as ServiceTagCollisionError, r as LayerDisposeError, s as CircularDependencyError, u as ServiceRuntimeNotConfiguredError } from "./internal-identity-Cm4-KIUj.mjs";
|
|
2
|
+
import { t as MapLayerBackend } from "./map-layer-backend-BodcEeNA.mjs";
|
|
2
3
|
import { t as isPromiseLike } from "./runtime-CDcCF5cb.mjs";
|
|
3
4
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
4
5
|
import { Result, TaggedError } from "better-result";
|
|
@@ -156,8 +157,8 @@ var Layer = class Layer {
|
|
|
156
157
|
return new Layer([{
|
|
157
158
|
service,
|
|
158
159
|
acquire: normalizeAcquire(acquire),
|
|
159
|
-
release: (instance) => {
|
|
160
|
-
return release(instance);
|
|
160
|
+
release: (instance, outcome) => {
|
|
161
|
+
return release(instance, outcome);
|
|
161
162
|
}
|
|
162
163
|
}]);
|
|
163
164
|
}
|
|
@@ -509,10 +510,14 @@ function andThenAsync(first, second) {
|
|
|
509
510
|
}
|
|
510
511
|
//#endregion
|
|
511
512
|
//#region src/effect/effect.ts
|
|
513
|
+
const runResultGenerator = Result.gen;
|
|
512
514
|
function gen(body) {
|
|
513
|
-
const runResultGenerator = Result.gen;
|
|
514
515
|
return runResultGenerator(body);
|
|
515
516
|
}
|
|
517
|
+
function fn(body) {
|
|
518
|
+
const program = () => runResultGenerator(body);
|
|
519
|
+
return program;
|
|
520
|
+
}
|
|
516
521
|
/**
|
|
517
522
|
* Acquire a resource in the current Scope and register its release callback.
|
|
518
523
|
*
|
|
@@ -557,6 +562,8 @@ function add(resource) {
|
|
|
557
562
|
const Effect = {
|
|
558
563
|
/** Compose a generator-based Effect program. */
|
|
559
564
|
gen,
|
|
565
|
+
/** Build a lazy Program from a generator. */
|
|
566
|
+
fn,
|
|
560
567
|
/** Acquire and register a resource in the current Scope. */
|
|
561
568
|
acquireRelease,
|
|
562
569
|
/** Register an already-acquired disposable in the current Scope. */
|
|
@@ -666,6 +673,33 @@ const classifyRuntimeOutcome = (value) => {
|
|
|
666
673
|
return { status: "success" };
|
|
667
674
|
};
|
|
668
675
|
//#endregion
|
|
676
|
+
//#region src/layer/resolution.ts
|
|
677
|
+
const resolutionStorage = new AsyncLocalStorage();
|
|
678
|
+
const findCycleStart = (path, token) => path.findIndex((current) => current.serviceTag === token.serviceTag);
|
|
679
|
+
const shouldPreserve = (cause) => cause instanceof CircularDependencyError || cause instanceof ServiceAcquisitionError || cause instanceof ServiceNotFoundError || cause instanceof ServiceTagCollisionError;
|
|
680
|
+
/** Wrap a backend with Runtime-local resolution paths and acquisition errors. */
|
|
681
|
+
const createResolutionResolver = (resolver) => {
|
|
682
|
+
const wrapped = { async resolve(token) {
|
|
683
|
+
const context = resolutionStorage.getStore();
|
|
684
|
+
const path = context?.resolver === wrapped ? context.path : [];
|
|
685
|
+
const cycleStart = findCycleStart(path, token);
|
|
686
|
+
if (cycleStart >= 0) throw new CircularDependencyError([...path.slice(cycleStart), token]);
|
|
687
|
+
const resolutionPath = [...path, token];
|
|
688
|
+
return await resolutionStorage.run({
|
|
689
|
+
resolver: wrapped,
|
|
690
|
+
path: resolutionPath
|
|
691
|
+
}, async () => {
|
|
692
|
+
try {
|
|
693
|
+
return await resolver.resolve(token);
|
|
694
|
+
} catch (cause) {
|
|
695
|
+
if (shouldPreserve(cause)) throw cause;
|
|
696
|
+
throw new ServiceAcquisitionError(token, resolutionPath, cause);
|
|
697
|
+
}
|
|
698
|
+
});
|
|
699
|
+
} };
|
|
700
|
+
return wrapped;
|
|
701
|
+
};
|
|
702
|
+
//#endregion
|
|
669
703
|
//#region src/layer/runtime.ts
|
|
670
704
|
const SCOPE_SUCCESS = Object.freeze({ status: "success" });
|
|
671
705
|
var RuntimeHandleDisposedError = class extends Error {
|
|
@@ -693,13 +727,15 @@ const bindProviderToScope = (provider, rootScope) => ({
|
|
|
693
727
|
});
|
|
694
728
|
var RuntimeHandleImpl = class {
|
|
695
729
|
backend;
|
|
730
|
+
resolver;
|
|
696
731
|
rootScope;
|
|
697
732
|
onCleanupFailure;
|
|
698
733
|
disposePromise;
|
|
699
734
|
executions = /* @__PURE__ */ new Set();
|
|
700
735
|
state = "active";
|
|
701
|
-
constructor(backend, rootScope, onCleanupFailure) {
|
|
736
|
+
constructor(backend, resolver, rootScope, onCleanupFailure) {
|
|
702
737
|
this.backend = backend;
|
|
738
|
+
this.resolver = resolver;
|
|
703
739
|
this.rootScope = rootScope;
|
|
704
740
|
this.onCleanupFailure = onCleanupFailure;
|
|
705
741
|
}
|
|
@@ -734,7 +770,7 @@ var RuntimeHandleImpl = class {
|
|
|
734
770
|
classify: classifyRuntimeOutcome,
|
|
735
771
|
onCleanupFailure: this.onCleanupFailure
|
|
736
772
|
} : { classify: classifyRuntimeOutcome };
|
|
737
|
-
return runScoped(executionScope, () => ServiceRuntime.run(this.
|
|
773
|
+
return runScoped(executionScope, () => ServiceRuntime.run(this.resolver, program), options);
|
|
738
774
|
}
|
|
739
775
|
dispose(outcome = SCOPE_SUCCESS) {
|
|
740
776
|
if (this.disposePromise) return this.disposePromise;
|
|
@@ -747,7 +783,7 @@ var RuntimeHandleImpl = class {
|
|
|
747
783
|
const failures = [];
|
|
748
784
|
await Promise.allSettled(executions);
|
|
749
785
|
try {
|
|
750
|
-
await ServiceRuntime.run(this.
|
|
786
|
+
await ServiceRuntime.run(this.resolver, () => this.rootScope.close(outcome));
|
|
751
787
|
} catch (cause) {
|
|
752
788
|
failures.push(cause);
|
|
753
789
|
}
|
|
@@ -773,6 +809,7 @@ var RuntimeHandleImpl = class {
|
|
|
773
809
|
/** Build a Runtime handle for a complete Layer and register its providers. */
|
|
774
810
|
const createRuntimeHandle = async (layer, backend, options = {}) => {
|
|
775
811
|
const rootScope = Scope.make();
|
|
812
|
+
const resolver = createResolutionResolver(backend);
|
|
776
813
|
let current;
|
|
777
814
|
try {
|
|
778
815
|
for (const provider of layer.providers) {
|
|
@@ -786,7 +823,7 @@ const createRuntimeHandle = async (layer, backend, options = {}) => {
|
|
|
786
823
|
};
|
|
787
824
|
const cleanupCauses = [];
|
|
788
825
|
try {
|
|
789
|
-
await ServiceRuntime.run(
|
|
826
|
+
await ServiceRuntime.run(resolver, () => rootScope.close(outcome));
|
|
790
827
|
} catch (cause) {
|
|
791
828
|
cleanupCauses.push(cause);
|
|
792
829
|
}
|
|
@@ -805,10 +842,22 @@ const createRuntimeHandle = async (layer, backend, options = {}) => {
|
|
|
805
842
|
const cleanupCause = cleanupCauses.length === 1 ? cleanupCauses[0] : cleanupCauses.length > 1 ? new LayerDisposeError(cleanupCauses.flatMap(normalizeDisposeCauses)) : void 0;
|
|
806
843
|
throw new LayerRegistrationError(current?.service, registrationCause, cleanupCause);
|
|
807
844
|
}
|
|
808
|
-
return new RuntimeHandleImpl(backend, rootScope, options.onCleanupFailure);
|
|
845
|
+
return new RuntimeHandleImpl(backend, resolver, rootScope, options.onCleanupFailure);
|
|
809
846
|
};
|
|
810
847
|
//#endregion
|
|
811
848
|
//#region src/runtime/runtime.ts
|
|
849
|
+
const isLayerBackend = (value) => value !== void 0 && "register" in value && "resolve" in value && "disposeAll" in value;
|
|
850
|
+
const resolveRuntimeConfig = (backendOrOptions, legacyOptions) => {
|
|
851
|
+
if (isLayerBackend(backendOrOptions)) return {
|
|
852
|
+
backend: backendOrOptions,
|
|
853
|
+
options: legacyOptions ?? {}
|
|
854
|
+
};
|
|
855
|
+
const options = backendOrOptions ?? {};
|
|
856
|
+
return {
|
|
857
|
+
backend: options.backend ?? new MapLayerBackend(),
|
|
858
|
+
options
|
|
859
|
+
};
|
|
860
|
+
};
|
|
812
861
|
/**
|
|
813
862
|
* Long-lived execution environment backed by a complete Layer.
|
|
814
863
|
*
|
|
@@ -817,7 +866,7 @@ const createRuntimeHandle = async (layer, backend, options = {}) => {
|
|
|
817
866
|
*
|
|
818
867
|
* @example
|
|
819
868
|
* ```ts
|
|
820
|
-
* const runtime = await Runtime.make(AppLive
|
|
869
|
+
* const runtime = await Runtime.make(AppLive)
|
|
821
870
|
* const result = await runtime.run(loadUser('u1'))
|
|
822
871
|
* await runtime.dispose()
|
|
823
872
|
* ```
|
|
@@ -829,28 +878,26 @@ var Runtime = class Runtime {
|
|
|
829
878
|
constructor(handle) {
|
|
830
879
|
this.handle = handle;
|
|
831
880
|
}
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
*
|
|
835
|
-
* @example
|
|
836
|
-
* ```ts
|
|
837
|
-
* const runtime = await Runtime.make(AppLive, backend)
|
|
838
|
-
* const result = await runtime.run(program)
|
|
839
|
-
* await runtime.dispose()
|
|
840
|
-
* ```
|
|
841
|
-
*/
|
|
842
|
-
static async make(layer, backend, options = {}) {
|
|
881
|
+
static async make(layer, backendOrOptions, legacyOptions) {
|
|
882
|
+
const { backend, options } = resolveRuntimeConfig(backendOrOptions, legacyOptions);
|
|
843
883
|
const handle = await createRuntimeHandle(layer, backend, options);
|
|
844
884
|
return new Runtime(handle);
|
|
845
885
|
}
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
886
|
+
static async run(layer, backendOrProgramOrOptions, programOrOptions, legacyOptions) {
|
|
887
|
+
let program;
|
|
888
|
+
let backendOrOptions;
|
|
889
|
+
let options;
|
|
890
|
+
if (typeof backendOrProgramOrOptions === "function") {
|
|
891
|
+
program = backendOrProgramOrOptions;
|
|
892
|
+
backendOrOptions = programOrOptions;
|
|
893
|
+
options = void 0;
|
|
894
|
+
} else {
|
|
895
|
+
backendOrOptions = backendOrProgramOrOptions;
|
|
896
|
+
program = programOrOptions;
|
|
897
|
+
options = legacyOptions;
|
|
898
|
+
}
|
|
899
|
+
const config = resolveRuntimeConfig(backendOrOptions, options);
|
|
900
|
+
const runtime = await Runtime.make(layer, config.backend, config.options);
|
|
854
901
|
let value;
|
|
855
902
|
let executionFailed = false;
|
|
856
903
|
let executionFailure;
|
|
@@ -901,6 +948,6 @@ var Runtime = class Runtime {
|
|
|
901
948
|
}
|
|
902
949
|
};
|
|
903
950
|
//#endregion
|
|
904
|
-
export { DuplicateServiceError, Effect, Layer, LayerDisposeError, LayerGeneratorYieldError, LayerRegistrationError, Resource, ResourceNotDisposableError, ResourceReleaseFailure, Runtime, Scope, ScopeCloseError, ScopeClosedError, ScopeRuntimeNotConfiguredError, Service, ServiceNotFoundError, ServiceRuntime, ServiceRuntimeNotConfiguredError, ServiceTagCollisionError, pipe };
|
|
951
|
+
export { CircularDependencyError, DuplicateServiceError, Effect, Layer, LayerDisposeError, LayerGeneratorYieldError, LayerRegistrationError, MapLayerBackend, Resource, ResourceNotDisposableError, ResourceReleaseFailure, Runtime, Scope, ScopeCloseError, ScopeClosedError, ScopeRuntimeNotConfiguredError, Service, ServiceAcquisitionError, ServiceNotFoundError, ServiceRuntime, ServiceRuntimeNotConfiguredError, ServiceTagCollisionError, pipe };
|
|
905
952
|
|
|
906
953
|
//# sourceMappingURL=index.mjs.map
|