@logixjs/core 0.0.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/dist/Action-BkRHy2vg.d.cts +10 -0
- package/dist/Action-mqVvtEHt.d.ts +10 -0
- package/dist/Action.cjs +57 -0
- package/dist/Action.cjs.map +1 -0
- package/dist/Action.d.cts +2 -0
- package/dist/Action.d.ts +2 -0
- package/dist/Action.js +9 -0
- package/dist/Action.js.map +1 -0
- package/dist/Actions-AsQ07yTP.d.cts +22 -0
- package/dist/Actions-AsQ07yTP.d.ts +22 -0
- package/dist/Actions.cjs +19 -0
- package/dist/Actions.cjs.map +1 -0
- package/dist/Actions.d.cts +2 -0
- package/dist/Actions.d.ts +2 -0
- package/dist/Actions.js +2 -0
- package/dist/Actions.js.map +1 -0
- package/dist/Bound-BN1DQ_lM.d.ts +23 -0
- package/dist/Bound-BPIfH9SS.d.cts +23 -0
- package/dist/Bound.cjs +1532 -0
- package/dist/Bound.cjs.map +1 -0
- package/dist/Bound.d.cts +7 -0
- package/dist/Bound.d.ts +7 -0
- package/dist/Bound.js +25 -0
- package/dist/Bound.js.map +1 -0
- package/dist/Debug-B5q5Bkzx.d.ts +320 -0
- package/dist/Debug-Bq8Sqjcr.d.cts +320 -0
- package/dist/Debug.cjs +1821 -0
- package/dist/Debug.cjs.map +1 -0
- package/dist/Debug.d.cts +13 -0
- package/dist/Debug.d.ts +13 -0
- package/dist/Debug.js +76 -0
- package/dist/Debug.js.map +1 -0
- package/dist/EffectOp.cjs +169 -0
- package/dist/EffectOp.cjs.map +1 -0
- package/dist/EffectOp.d.cts +118 -0
- package/dist/EffectOp.d.ts +118 -0
- package/dist/EffectOp.js +28 -0
- package/dist/EffectOp.js.map +1 -0
- package/dist/Env-DuJ6JrU2.d.cts +10 -0
- package/dist/Env-DuJ6JrU2.d.ts +10 -0
- package/dist/Env.cjs +60 -0
- package/dist/Env.cjs.map +1 -0
- package/dist/Env.d.cts +1 -0
- package/dist/Env.d.ts +1 -0
- package/dist/Env.js +11 -0
- package/dist/Env.js.map +1 -0
- package/dist/Flow-1fZT8MpX.d.cts +152 -0
- package/dist/Flow-BhpjE22E.d.ts +152 -0
- package/dist/Flow.cjs +504 -0
- package/dist/Flow.cjs.map +1 -0
- package/dist/Flow.d.cts +8 -0
- package/dist/Flow.d.ts +8 -0
- package/dist/Flow.js +15 -0
- package/dist/Flow.js.map +1 -0
- package/dist/Handle-D8D1zPb_.d.cts +30 -0
- package/dist/Handle-D_cLW1Z3.d.ts +30 -0
- package/dist/Handle.cjs +42 -0
- package/dist/Handle.cjs.map +1 -0
- package/dist/Handle.d.cts +7 -0
- package/dist/Handle.d.ts +7 -0
- package/dist/Handle.js +10 -0
- package/dist/Handle.js.map +1 -0
- package/dist/Kernel-8kC-jOda.d.cts +171 -0
- package/dist/Kernel-CnGE1Fyk.d.ts +171 -0
- package/dist/Kernel.cjs +284 -0
- package/dist/Kernel.cjs.map +1 -0
- package/dist/Kernel.d.cts +14 -0
- package/dist/Kernel.d.ts +14 -0
- package/dist/Kernel.js +36 -0
- package/dist/Kernel.js.map +1 -0
- package/dist/Link-Db7975nU.d.ts +45 -0
- package/dist/Link-fX8x1eCK.d.cts +45 -0
- package/dist/Link.cjs +542 -0
- package/dist/Link.cjs.map +1 -0
- package/dist/Link.d.cts +7 -0
- package/dist/Link.d.ts +7 -0
- package/dist/Link.js +35 -0
- package/dist/Link.js.map +1 -0
- package/dist/Logic-BRjEMr-W.d.ts +38 -0
- package/dist/Logic-DRh4sDZj.d.cts +38 -0
- package/dist/Logic.cjs +37 -0
- package/dist/Logic.cjs.map +1 -0
- package/dist/Logic.d.cts +7 -0
- package/dist/Logic.d.ts +7 -0
- package/dist/Logic.js +10 -0
- package/dist/Logic.js.map +1 -0
- package/dist/MatchBuilder-0QOc-nlU.d.ts +14 -0
- package/dist/MatchBuilder-CJk5oCkR.d.cts +14 -0
- package/dist/MatchBuilder.cjs +85 -0
- package/dist/MatchBuilder.cjs.map +1 -0
- package/dist/MatchBuilder.d.cts +8 -0
- package/dist/MatchBuilder.d.ts +8 -0
- package/dist/MatchBuilder.js +11 -0
- package/dist/MatchBuilder.js.map +1 -0
- package/dist/Middleware.cjs +411 -0
- package/dist/Middleware.cjs.map +1 -0
- package/dist/Middleware.d.cts +88 -0
- package/dist/Middleware.d.ts +88 -0
- package/dist/Middleware.js +27 -0
- package/dist/Middleware.js.map +1 -0
- package/dist/Module-B_0xRDMR.d.cts +203 -0
- package/dist/Module-DnzluX2J.d.ts +203 -0
- package/dist/Module.cjs +13512 -0
- package/dist/Module.cjs.map +1 -0
- package/dist/Module.d.cts +8 -0
- package/dist/Module.d.ts +8 -0
- package/dist/Module.js +53 -0
- package/dist/Module.js.map +1 -0
- package/dist/ModuleTag-C8FHY_sY.d.ts +93 -0
- package/dist/ModuleTag-EGbgBMpZ.d.cts +93 -0
- package/dist/ModuleTag.cjs +12231 -0
- package/dist/ModuleTag.cjs.map +1 -0
- package/dist/ModuleTag.d.cts +8 -0
- package/dist/ModuleTag.d.ts +8 -0
- package/dist/ModuleTag.js +39 -0
- package/dist/ModuleTag.js.map +1 -0
- package/dist/Observability-COqEvp2C.d.cts +713 -0
- package/dist/Observability-cY4kLn0S.d.ts +713 -0
- package/dist/Observability.cjs +5865 -0
- package/dist/Observability.cjs.map +1 -0
- package/dist/Observability.d.cts +9 -0
- package/dist/Observability.d.ts +9 -0
- package/dist/Observability.js +41 -0
- package/dist/Observability.js.map +1 -0
- package/dist/Platform-C49Pv956.d.cts +21 -0
- package/dist/Platform-C49Pv956.d.ts +21 -0
- package/dist/Platform-CHX8o-U4.d.ts +51 -0
- package/dist/Platform-CVlv0xLQ.d.cts +51 -0
- package/dist/Platform.cjs +58 -0
- package/dist/Platform.cjs.map +1 -0
- package/dist/Platform.d.cts +4 -0
- package/dist/Platform.d.ts +4 -0
- package/dist/Platform.js +15 -0
- package/dist/Platform.js.map +1 -0
- package/dist/Process-CM9xbMdP.d.ts +92 -0
- package/dist/Process-mL8fHDSB.d.cts +92 -0
- package/dist/Process.cjs +575 -0
- package/dist/Process.cjs.map +1 -0
- package/dist/Process.d.cts +8 -0
- package/dist/Process.d.ts +8 -0
- package/dist/Process.js +42 -0
- package/dist/Process.js.map +1 -0
- package/dist/ReadQuery-BlMwhe-F.d.ts +30 -0
- package/dist/ReadQuery-CL5XlXts.d.cts +30 -0
- package/dist/ReadQuery-SinbStGF.d.cts +38 -0
- package/dist/ReadQuery-SinbStGF.d.ts +38 -0
- package/dist/ReadQuery.cjs +377 -0
- package/dist/ReadQuery.cjs.map +1 -0
- package/dist/ReadQuery.d.cts +2 -0
- package/dist/ReadQuery.d.ts +2 -0
- package/dist/ReadQuery.js +14 -0
- package/dist/ReadQuery.js.map +1 -0
- package/dist/Reflection-CQnKwPXj.d.ts +182 -0
- package/dist/Reflection-Kabo1mlU.d.cts +182 -0
- package/dist/Reflection.cjs +2954 -0
- package/dist/Reflection.cjs.map +1 -0
- package/dist/Reflection.d.cts +17 -0
- package/dist/Reflection.d.ts +17 -0
- package/dist/Reflection.js +40 -0
- package/dist/Reflection.js.map +1 -0
- package/dist/Resource-Dy1xD_DG.d.cts +75 -0
- package/dist/Resource-Dy1xD_DG.d.ts +75 -0
- package/dist/Resource.cjs +166 -0
- package/dist/Resource.cjs.map +1 -0
- package/dist/Resource.d.cts +3 -0
- package/dist/Resource.d.ts +3 -0
- package/dist/Resource.js +21 -0
- package/dist/Resource.js.map +1 -0
- package/dist/Root-7ADUMk4t.d.cts +29 -0
- package/dist/Root-7ADUMk4t.d.ts +29 -0
- package/dist/Root.cjs +125 -0
- package/dist/Root.cjs.map +1 -0
- package/dist/Root.d.cts +4 -0
- package/dist/Root.d.ts +4 -0
- package/dist/Root.js +12 -0
- package/dist/Root.js.map +1 -0
- package/dist/Runtime-B-aL-f29.d.cts +274 -0
- package/dist/Runtime-CtyzZG4i.d.ts +274 -0
- package/dist/Runtime.cjs +5740 -0
- package/dist/Runtime.cjs.map +1 -0
- package/dist/Runtime.d.cts +19 -0
- package/dist/Runtime.d.ts +19 -0
- package/dist/Runtime.js +62 -0
- package/dist/Runtime.js.map +1 -0
- package/dist/ScopeRegistry-D1owDNSm.d.cts +61 -0
- package/dist/ScopeRegistry-D1owDNSm.d.ts +61 -0
- package/dist/ScopeRegistry.cjs +152 -0
- package/dist/ScopeRegistry.cjs.map +1 -0
- package/dist/ScopeRegistry.d.cts +2 -0
- package/dist/ScopeRegistry.d.ts +2 -0
- package/dist/ScopeRegistry.js +16 -0
- package/dist/ScopeRegistry.js.map +1 -0
- package/dist/State-CU50R26M.d.cts +19 -0
- package/dist/State-CU50R26M.d.ts +19 -0
- package/dist/State.cjs +19 -0
- package/dist/State.cjs.map +1 -0
- package/dist/State.d.cts +2 -0
- package/dist/State.d.ts +2 -0
- package/dist/State.js +2 -0
- package/dist/State.js.map +1 -0
- package/dist/StateTrait-BGsZghTz.d.ts +122 -0
- package/dist/StateTrait-OWhbj12c.d.cts +122 -0
- package/dist/StateTrait.cjs +2737 -0
- package/dist/StateTrait.cjs.map +1 -0
- package/dist/StateTrait.d.cts +9 -0
- package/dist/StateTrait.d.ts +9 -0
- package/dist/StateTrait.js +39 -0
- package/dist/StateTrait.js.map +1 -0
- package/dist/TraitLifecycle-CwV5WPFX.d.cts +88 -0
- package/dist/TraitLifecycle-LdIWmKlg.d.ts +88 -0
- package/dist/TraitLifecycle.cjs +581 -0
- package/dist/TraitLifecycle.cjs.map +1 -0
- package/dist/TraitLifecycle.d.cts +8 -0
- package/dist/TraitLifecycle.d.ts +8 -0
- package/dist/TraitLifecycle.js +24 -0
- package/dist/TraitLifecycle.js.map +1 -0
- package/dist/action-DiMDD_0v.d.cts +35 -0
- package/dist/action-DiMDD_0v.d.ts +35 -0
- package/dist/chunk-24VULZ7A.js +76 -0
- package/dist/chunk-24VULZ7A.js.map +1 -0
- package/dist/chunk-3IYZ5IGG.js +17 -0
- package/dist/chunk-3IYZ5IGG.js.map +1 -0
- package/dist/chunk-3QMIVH35.js +43 -0
- package/dist/chunk-3QMIVH35.js.map +1 -0
- package/dist/chunk-3RMKLXHX.js +83 -0
- package/dist/chunk-3RMKLXHX.js.map +1 -0
- package/dist/chunk-3TMODYZV.js +111 -0
- package/dist/chunk-3TMODYZV.js.map +1 -0
- package/dist/chunk-3VG5TWQR.js +27 -0
- package/dist/chunk-3VG5TWQR.js.map +1 -0
- package/dist/chunk-4CQAV7YB.js +37 -0
- package/dist/chunk-4CQAV7YB.js.map +1 -0
- package/dist/chunk-4SO6JMZL.js +7 -0
- package/dist/chunk-4SO6JMZL.js.map +1 -0
- package/dist/chunk-66ALHVEX.js +40 -0
- package/dist/chunk-66ALHVEX.js.map +1 -0
- package/dist/chunk-76WT3HOR.js +397 -0
- package/dist/chunk-76WT3HOR.js.map +1 -0
- package/dist/chunk-ANLBCBDC.js +285 -0
- package/dist/chunk-ANLBCBDC.js.map +1 -0
- package/dist/chunk-AUIR5O6W.js +75 -0
- package/dist/chunk-AUIR5O6W.js.map +1 -0
- package/dist/chunk-BABLDP24.js +445 -0
- package/dist/chunk-BABLDP24.js.map +1 -0
- package/dist/chunk-BE3HW4FY.js +1099 -0
- package/dist/chunk-BE3HW4FY.js.map +1 -0
- package/dist/chunk-BZ2SHDN2.js +54 -0
- package/dist/chunk-BZ2SHDN2.js.map +1 -0
- package/dist/chunk-CW6T36TN.js +393 -0
- package/dist/chunk-CW6T36TN.js.map +1 -0
- package/dist/chunk-DFNM3WX2.js +632 -0
- package/dist/chunk-DFNM3WX2.js.map +1 -0
- package/dist/chunk-DMBALCE2.js +1034 -0
- package/dist/chunk-DMBALCE2.js.map +1 -0
- package/dist/chunk-EGK3KN7B.js +406 -0
- package/dist/chunk-EGK3KN7B.js.map +1 -0
- package/dist/chunk-EY4NZKDR.js +19 -0
- package/dist/chunk-EY4NZKDR.js.map +1 -0
- package/dist/chunk-G5ZBFPNU.js +23 -0
- package/dist/chunk-G5ZBFPNU.js.map +1 -0
- package/dist/chunk-GMPEOUP2.js +31 -0
- package/dist/chunk-GMPEOUP2.js.map +1 -0
- package/dist/chunk-IHVBV5C2.js +279 -0
- package/dist/chunk-IHVBV5C2.js.map +1 -0
- package/dist/chunk-IPF7E66P.js +23 -0
- package/dist/chunk-IPF7E66P.js.map +1 -0
- package/dist/chunk-JCXGZRMU.js +204 -0
- package/dist/chunk-JCXGZRMU.js.map +1 -0
- package/dist/chunk-JGIWG6SR.js +6359 -0
- package/dist/chunk-JGIWG6SR.js.map +1 -0
- package/dist/chunk-JWOYLO27.js +241 -0
- package/dist/chunk-JWOYLO27.js.map +1 -0
- package/dist/chunk-KIXAU3GM.js +137 -0
- package/dist/chunk-KIXAU3GM.js.map +1 -0
- package/dist/chunk-KL5ACTCT.js +8 -0
- package/dist/chunk-KL5ACTCT.js.map +1 -0
- package/dist/chunk-KP7MUZNX.js +83 -0
- package/dist/chunk-KP7MUZNX.js.map +1 -0
- package/dist/chunk-LEU6UA5J.js +1 -0
- package/dist/chunk-LEU6UA5J.js.map +1 -0
- package/dist/chunk-M2RGJPXX.js +35 -0
- package/dist/chunk-M2RGJPXX.js.map +1 -0
- package/dist/chunk-M3BFQ7HK.js +13 -0
- package/dist/chunk-M3BFQ7HK.js.map +1 -0
- package/dist/chunk-M3WTHJHJ.js +1051 -0
- package/dist/chunk-M3WTHJHJ.js.map +1 -0
- package/dist/chunk-M7IYCTJV.js +79 -0
- package/dist/chunk-M7IYCTJV.js.map +1 -0
- package/dist/chunk-NBD3KUOZ.js +838 -0
- package/dist/chunk-NBD3KUOZ.js.map +1 -0
- package/dist/chunk-NQZ2OSGR.js +151 -0
- package/dist/chunk-NQZ2OSGR.js.map +1 -0
- package/dist/chunk-NZJKFF45.js +106 -0
- package/dist/chunk-NZJKFF45.js.map +1 -0
- package/dist/chunk-OFADUJWJ.js +175 -0
- package/dist/chunk-OFADUJWJ.js.map +1 -0
- package/dist/chunk-OGWBVHB3.js +461 -0
- package/dist/chunk-OGWBVHB3.js.map +1 -0
- package/dist/chunk-PAYXCY6A.js +1696 -0
- package/dist/chunk-PAYXCY6A.js.map +1 -0
- package/dist/chunk-PYOE4VSI.js +1924 -0
- package/dist/chunk-PYOE4VSI.js.map +1 -0
- package/dist/chunk-PZ5AY32C.js +10 -0
- package/dist/chunk-PZ5AY32C.js.map +1 -0
- package/dist/chunk-QCHIQWAJ.js +21 -0
- package/dist/chunk-QCHIQWAJ.js.map +1 -0
- package/dist/chunk-QMM6O4CD.js +71 -0
- package/dist/chunk-QMM6O4CD.js.map +1 -0
- package/dist/chunk-RNFE3ML2.js +22 -0
- package/dist/chunk-RNFE3ML2.js.map +1 -0
- package/dist/chunk-TAAPQVZN.js +23 -0
- package/dist/chunk-TAAPQVZN.js.map +1 -0
- package/dist/chunk-THATMZXD.js +21 -0
- package/dist/chunk-THATMZXD.js.map +1 -0
- package/dist/chunk-TKZ7MEIA.js +27 -0
- package/dist/chunk-TKZ7MEIA.js.map +1 -0
- package/dist/chunk-TQOBJYDP.js +7 -0
- package/dist/chunk-TQOBJYDP.js.map +1 -0
- package/dist/chunk-VZB726PE.js +93 -0
- package/dist/chunk-VZB726PE.js.map +1 -0
- package/dist/chunk-W3TEWHLO.js +568 -0
- package/dist/chunk-W3TEWHLO.js.map +1 -0
- package/dist/chunk-YS3AZQ2G.js +52 -0
- package/dist/chunk-YS3AZQ2G.js.map +1 -0
- package/dist/chunk-ZDTRWK5F.js +40 -0
- package/dist/chunk-ZDTRWK5F.js.map +1 -0
- package/dist/chunk-ZFLHVFUC.js +192 -0
- package/dist/chunk-ZFLHVFUC.js.map +1 -0
- package/dist/chunk-ZFY7U2FR.js +133 -0
- package/dist/chunk-ZFY7U2FR.js.map +1 -0
- package/dist/chunk-ZGDVUPTM.js +270 -0
- package/dist/chunk-ZGDVUPTM.js.map +1 -0
- package/dist/index.cjs +19700 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +195 -0
- package/dist/index.d.ts +195 -0
- package/dist/index.js +286 -0
- package/dist/index.js.map +1 -0
- package/dist/ir-BMP7yxJJ.d.cts +39 -0
- package/dist/ir-DUOz6H-5.d.ts +39 -0
- package/dist/module-B8CBqIZ_.d.cts +1191 -0
- package/dist/module-k7m3txak.d.ts +1191 -0
- package/dist/protocol-g_1897M2.d.cts +127 -0
- package/dist/protocol-g_1897M2.d.ts +127 -0
- package/package.json +162 -0
|
@@ -0,0 +1,1099 @@
|
|
|
1
|
+
import {
|
|
2
|
+
forceSourceRefresh,
|
|
3
|
+
inSyncTransactionFiber,
|
|
4
|
+
makeTaskRunner
|
|
5
|
+
} from "./chunk-ZFLHVFUC.js";
|
|
6
|
+
import {
|
|
7
|
+
Tag
|
|
8
|
+
} from "./chunk-KL5ACTCT.js";
|
|
9
|
+
import {
|
|
10
|
+
resolve
|
|
11
|
+
} from "./chunk-AUIR5O6W.js";
|
|
12
|
+
import {
|
|
13
|
+
makeMatch,
|
|
14
|
+
makeMatchTag
|
|
15
|
+
} from "./chunk-BZ2SHDN2.js";
|
|
16
|
+
import {
|
|
17
|
+
isActionToken
|
|
18
|
+
} from "./chunk-YS3AZQ2G.js";
|
|
19
|
+
import {
|
|
20
|
+
isFieldPathSegment
|
|
21
|
+
} from "./chunk-IHVBV5C2.js";
|
|
22
|
+
import {
|
|
23
|
+
getRuntimeInternals,
|
|
24
|
+
setBoundInternals
|
|
25
|
+
} from "./chunk-3RMKLXHX.js";
|
|
26
|
+
import {
|
|
27
|
+
isDevEnv
|
|
28
|
+
} from "./chunk-3QMIVH35.js";
|
|
29
|
+
import {
|
|
30
|
+
make
|
|
31
|
+
} from "./chunk-NQZ2OSGR.js";
|
|
32
|
+
import {
|
|
33
|
+
currentDiagnosticsLevel,
|
|
34
|
+
record,
|
|
35
|
+
toSerializableErrorSummary
|
|
36
|
+
} from "./chunk-DMBALCE2.js";
|
|
37
|
+
import {
|
|
38
|
+
RunSessionTag
|
|
39
|
+
} from "./chunk-OFADUJWJ.js";
|
|
40
|
+
|
|
41
|
+
// src/internal/runtime/core/mutativePatches.ts
|
|
42
|
+
import { create } from "mutative";
|
|
43
|
+
var mutateWithoutPatches = (base, mutator) => {
|
|
44
|
+
return create(base, mutator);
|
|
45
|
+
};
|
|
46
|
+
var toPatchFieldPath = (path) => {
|
|
47
|
+
if (typeof path === "string") {
|
|
48
|
+
const trimmed = path.trim();
|
|
49
|
+
return trimmed.length > 0 ? "*" : void 0;
|
|
50
|
+
}
|
|
51
|
+
if (!Array.isArray(path)) return void 0;
|
|
52
|
+
const parts = [];
|
|
53
|
+
for (const seg of path) {
|
|
54
|
+
if (typeof seg === "string") {
|
|
55
|
+
if (isFieldPathSegment(seg)) parts.push(seg);
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (parts.length === 0) return "*";
|
|
60
|
+
return parts;
|
|
61
|
+
};
|
|
62
|
+
var mutateWithPatchPaths = (base, mutator) => {
|
|
63
|
+
const out = create(base, mutator, {
|
|
64
|
+
enablePatches: {
|
|
65
|
+
pathAsArray: true,
|
|
66
|
+
arrayLengthAssignment: false
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
if (!Array.isArray(out)) {
|
|
70
|
+
return { nextState: out, patchPaths: [] };
|
|
71
|
+
}
|
|
72
|
+
const nextState = out[0];
|
|
73
|
+
const patches = out[1] ?? [];
|
|
74
|
+
const dedup = /* @__PURE__ */ new Map();
|
|
75
|
+
for (const patch of patches) {
|
|
76
|
+
const p = toPatchFieldPath(patch?.path);
|
|
77
|
+
if (!p) continue;
|
|
78
|
+
const key = p === "*" ? "*" : JSON.stringify(p);
|
|
79
|
+
if (!dedup.has(key)) dedup.set(key, p);
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
nextState,
|
|
83
|
+
patchPaths: Array.from(dedup.values())
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// src/internal/runtime/core/BoundApiRuntime.ts
|
|
88
|
+
import { Context as Context3, Effect as Effect3, FiberRef, Option, Schema, Stream } from "effect";
|
|
89
|
+
|
|
90
|
+
// src/internal/runtime/core/Lifecycle.ts
|
|
91
|
+
import { Cause, Context, Effect, Ref } from "effect";
|
|
92
|
+
var LifecycleContext = Context.GenericTag("@logixjs/LifecycleManager");
|
|
93
|
+
var safeRun = (label, eff) => eff.pipe(
|
|
94
|
+
Effect.matchCauseEffect({
|
|
95
|
+
onSuccess: () => Effect.void,
|
|
96
|
+
onFailure: (cause) => Effect.logError(`[${label}] failed: ${Cause.pretty(cause)}`)
|
|
97
|
+
})
|
|
98
|
+
);
|
|
99
|
+
var makeTaskId = (kind, order) => `${kind}:${order}`;
|
|
100
|
+
var makeLifecycleManager = (identity) => Effect.gen(function* () {
|
|
101
|
+
const budgets = {
|
|
102
|
+
maxEventsPerInstance: 20,
|
|
103
|
+
maxEventBytes: 4 * 1024
|
|
104
|
+
};
|
|
105
|
+
const statusRef = yield* Ref.make({
|
|
106
|
+
identity,
|
|
107
|
+
status: "creating"
|
|
108
|
+
});
|
|
109
|
+
const initRequired = [];
|
|
110
|
+
const start = [];
|
|
111
|
+
const destroy = [];
|
|
112
|
+
const platformSuspend = [];
|
|
113
|
+
const platformResume = [];
|
|
114
|
+
const platformReset = [];
|
|
115
|
+
const onErrorHandlers = [];
|
|
116
|
+
const getStatus = Ref.get(statusRef);
|
|
117
|
+
const recordPhase = (phase, name, payload) => record({
|
|
118
|
+
type: "lifecycle:phase",
|
|
119
|
+
moduleId: identity.moduleId,
|
|
120
|
+
instanceId: identity.instanceId,
|
|
121
|
+
phase,
|
|
122
|
+
name,
|
|
123
|
+
payload
|
|
124
|
+
});
|
|
125
|
+
const setStatus = (status, patch) => Ref.update(statusRef, (prev) => ({
|
|
126
|
+
...prev,
|
|
127
|
+
identity: {
|
|
128
|
+
...prev.identity,
|
|
129
|
+
...patch?.runtimeLabel ? { runtimeLabel: patch.runtimeLabel } : null
|
|
130
|
+
},
|
|
131
|
+
status,
|
|
132
|
+
...patch?.initOutcome !== void 0 ? { initOutcome: patch.initOutcome } : null,
|
|
133
|
+
...patch?.initProgress !== void 0 ? { initProgress: patch.initProgress } : null
|
|
134
|
+
}));
|
|
135
|
+
const registerInitRequired = (effect, options) => {
|
|
136
|
+
const order = initRequired.length;
|
|
137
|
+
initRequired.push({
|
|
138
|
+
taskId: makeTaskId("initRequired", order),
|
|
139
|
+
kind: "initRequired",
|
|
140
|
+
order,
|
|
141
|
+
name: options?.name,
|
|
142
|
+
effect
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
const registerStart = (effect, options) => {
|
|
146
|
+
const order = start.length;
|
|
147
|
+
start.push({
|
|
148
|
+
taskId: makeTaskId("start", order),
|
|
149
|
+
kind: "start",
|
|
150
|
+
order,
|
|
151
|
+
name: options?.name,
|
|
152
|
+
fatalOnFailure: options?.fatalOnFailure,
|
|
153
|
+
effect
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
const registerDestroy = (effect, options) => {
|
|
157
|
+
const order = destroy.length;
|
|
158
|
+
destroy.push({
|
|
159
|
+
taskId: makeTaskId("destroy", order),
|
|
160
|
+
kind: "destroy",
|
|
161
|
+
order,
|
|
162
|
+
name: options?.name,
|
|
163
|
+
effect
|
|
164
|
+
});
|
|
165
|
+
};
|
|
166
|
+
const registerOnError = (handler) => {
|
|
167
|
+
onErrorHandlers.push(handler);
|
|
168
|
+
};
|
|
169
|
+
const registerPlatformSuspend = (effect, options) => {
|
|
170
|
+
const order = platformSuspend.length;
|
|
171
|
+
platformSuspend.push({
|
|
172
|
+
taskId: makeTaskId("platformSuspend", order),
|
|
173
|
+
kind: "platformSuspend",
|
|
174
|
+
order,
|
|
175
|
+
name: options?.name,
|
|
176
|
+
effect
|
|
177
|
+
});
|
|
178
|
+
};
|
|
179
|
+
const registerPlatformResume = (effect, options) => {
|
|
180
|
+
const order = platformResume.length;
|
|
181
|
+
platformResume.push({
|
|
182
|
+
taskId: makeTaskId("platformResume", order),
|
|
183
|
+
kind: "platformResume",
|
|
184
|
+
order,
|
|
185
|
+
name: options?.name,
|
|
186
|
+
effect
|
|
187
|
+
});
|
|
188
|
+
};
|
|
189
|
+
const registerPlatformReset = (effect, options) => {
|
|
190
|
+
const order = platformReset.length;
|
|
191
|
+
platformReset.push({
|
|
192
|
+
taskId: makeTaskId("platformReset", order),
|
|
193
|
+
kind: "platformReset",
|
|
194
|
+
order,
|
|
195
|
+
name: options?.name,
|
|
196
|
+
effect
|
|
197
|
+
});
|
|
198
|
+
};
|
|
199
|
+
const notifyError = (cause, context) => {
|
|
200
|
+
if (Cause.isInterrupted(cause)) {
|
|
201
|
+
return Effect.void;
|
|
202
|
+
}
|
|
203
|
+
return record({
|
|
204
|
+
type: "lifecycle:error",
|
|
205
|
+
moduleId: context.moduleId,
|
|
206
|
+
instanceId: context.instanceId,
|
|
207
|
+
cause,
|
|
208
|
+
phase: context.phase,
|
|
209
|
+
hook: context.hook,
|
|
210
|
+
taskId: context.taskId,
|
|
211
|
+
txnSeq: context.txnSeq,
|
|
212
|
+
opSeq: context.opSeq,
|
|
213
|
+
origin: context.origin
|
|
214
|
+
}).pipe(
|
|
215
|
+
Effect.zipRight(
|
|
216
|
+
Effect.forEach(
|
|
217
|
+
onErrorHandlers,
|
|
218
|
+
(handler) => handler(cause, context).pipe(
|
|
219
|
+
Effect.catchAllCause((inner) => Effect.logError(`[lifecycle.onError] failed: ${Cause.pretty(inner)}`))
|
|
220
|
+
),
|
|
221
|
+
{ discard: true }
|
|
222
|
+
)
|
|
223
|
+
)
|
|
224
|
+
);
|
|
225
|
+
};
|
|
226
|
+
const runInitRequired = Effect.gen(function* () {
|
|
227
|
+
const total = initRequired.length;
|
|
228
|
+
if (total === 0) {
|
|
229
|
+
yield* setStatus("ready", {
|
|
230
|
+
initProgress: { total: 0, completed: 0 },
|
|
231
|
+
initOutcome: { status: "success" }
|
|
232
|
+
});
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
const startedAt = Date.now();
|
|
236
|
+
yield* recordPhase("init", "initRequired:start", { total });
|
|
237
|
+
yield* setStatus("initializing", {
|
|
238
|
+
initProgress: { total, completed: 0, current: 0, startedAt }
|
|
239
|
+
});
|
|
240
|
+
let completed = 0;
|
|
241
|
+
for (let i = 0; i < initRequired.length; i++) {
|
|
242
|
+
yield* setStatus("initializing", {
|
|
243
|
+
initProgress: { total, completed, current: i, startedAt }
|
|
244
|
+
});
|
|
245
|
+
const task = initRequired[i];
|
|
246
|
+
const exit = yield* Effect.exit(task.effect);
|
|
247
|
+
if (exit._tag === "Success") {
|
|
248
|
+
completed += 1;
|
|
249
|
+
yield* setStatus("initializing", {
|
|
250
|
+
initProgress: { total, completed, current: i + 1, startedAt }
|
|
251
|
+
});
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
const summary = toSerializableErrorSummary(exit.cause);
|
|
255
|
+
yield* notifyError(exit.cause, {
|
|
256
|
+
phase: "init",
|
|
257
|
+
hook: "initRequired",
|
|
258
|
+
moduleId: identity.moduleId,
|
|
259
|
+
instanceId: identity.instanceId,
|
|
260
|
+
taskId: task.taskId,
|
|
261
|
+
origin: "initRequired"
|
|
262
|
+
});
|
|
263
|
+
yield* setStatus("failed", {
|
|
264
|
+
initProgress: { total, completed, current: i, startedAt },
|
|
265
|
+
initOutcome: { status: "failure", error: summary.errorSummary }
|
|
266
|
+
});
|
|
267
|
+
return yield* Effect.failCause(exit.cause);
|
|
268
|
+
}
|
|
269
|
+
yield* recordPhase("init", "initRequired:success", { total });
|
|
270
|
+
yield* setStatus("ready", {
|
|
271
|
+
initProgress: { total, completed, current: total, startedAt },
|
|
272
|
+
initOutcome: { status: "success" }
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
const runStart = recordPhase("run", "start:schedule", {
|
|
276
|
+
total: start.length
|
|
277
|
+
}).pipe(
|
|
278
|
+
Effect.zipRight(
|
|
279
|
+
Effect.forEach(
|
|
280
|
+
start,
|
|
281
|
+
(task) => Effect.forkScoped(
|
|
282
|
+
task.effect.pipe(
|
|
283
|
+
Effect.catchAllCause(
|
|
284
|
+
(cause) => notifyError(cause, {
|
|
285
|
+
phase: "run",
|
|
286
|
+
hook: "start",
|
|
287
|
+
moduleId: identity.moduleId,
|
|
288
|
+
instanceId: identity.instanceId,
|
|
289
|
+
taskId: task.taskId,
|
|
290
|
+
origin: "start"
|
|
291
|
+
})
|
|
292
|
+
)
|
|
293
|
+
)
|
|
294
|
+
).pipe(Effect.asVoid),
|
|
295
|
+
{ discard: true, concurrency: "unbounded" }
|
|
296
|
+
)
|
|
297
|
+
)
|
|
298
|
+
);
|
|
299
|
+
const runDestroy = Effect.gen(function* () {
|
|
300
|
+
yield* recordPhase("destroy", "destroy:start", { total: destroy.length });
|
|
301
|
+
yield* setStatus("terminating");
|
|
302
|
+
for (let i = destroy.length - 1; i >= 0; i--) {
|
|
303
|
+
const task = destroy[i];
|
|
304
|
+
yield* safeRun(
|
|
305
|
+
"lifecycle.onDestroy",
|
|
306
|
+
task.effect.pipe(
|
|
307
|
+
Effect.catchAllCause(
|
|
308
|
+
(cause) => notifyError(cause, {
|
|
309
|
+
phase: "destroy",
|
|
310
|
+
hook: "destroy",
|
|
311
|
+
moduleId: identity.moduleId,
|
|
312
|
+
instanceId: identity.instanceId,
|
|
313
|
+
taskId: task.taskId,
|
|
314
|
+
origin: "destroy"
|
|
315
|
+
})
|
|
316
|
+
)
|
|
317
|
+
)
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
yield* setStatus("terminated");
|
|
321
|
+
yield* recordPhase("destroy", "destroy:done", { total: destroy.length });
|
|
322
|
+
});
|
|
323
|
+
const runPlatformSuspend = Effect.gen(function* () {
|
|
324
|
+
if (platformSuspend.length === 0) return;
|
|
325
|
+
yield* recordPhase("platform", "signal:suspend", { total: platformSuspend.length });
|
|
326
|
+
for (const task of platformSuspend) {
|
|
327
|
+
yield* safeRun(
|
|
328
|
+
"lifecycle.onSuspend",
|
|
329
|
+
task.effect.pipe(
|
|
330
|
+
Effect.catchAllCause(
|
|
331
|
+
(cause) => notifyError(cause, {
|
|
332
|
+
phase: "platform",
|
|
333
|
+
hook: "suspend",
|
|
334
|
+
moduleId: identity.moduleId,
|
|
335
|
+
instanceId: identity.instanceId,
|
|
336
|
+
taskId: task.taskId,
|
|
337
|
+
origin: "platform.suspend"
|
|
338
|
+
})
|
|
339
|
+
)
|
|
340
|
+
)
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
const runPlatformResume = Effect.gen(function* () {
|
|
345
|
+
if (platformResume.length === 0) return;
|
|
346
|
+
yield* recordPhase("platform", "signal:resume", { total: platformResume.length });
|
|
347
|
+
for (const task of platformResume) {
|
|
348
|
+
yield* safeRun(
|
|
349
|
+
"lifecycle.onResume",
|
|
350
|
+
task.effect.pipe(
|
|
351
|
+
Effect.catchAllCause(
|
|
352
|
+
(cause) => notifyError(cause, {
|
|
353
|
+
phase: "platform",
|
|
354
|
+
hook: "resume",
|
|
355
|
+
moduleId: identity.moduleId,
|
|
356
|
+
instanceId: identity.instanceId,
|
|
357
|
+
taskId: task.taskId,
|
|
358
|
+
origin: "platform.resume"
|
|
359
|
+
})
|
|
360
|
+
)
|
|
361
|
+
)
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
const runPlatformReset = Effect.gen(function* () {
|
|
366
|
+
if (platformReset.length === 0) return;
|
|
367
|
+
yield* recordPhase("platform", "signal:reset", { total: platformReset.length });
|
|
368
|
+
for (const task of platformReset) {
|
|
369
|
+
yield* safeRun(
|
|
370
|
+
"lifecycle.onReset",
|
|
371
|
+
task.effect.pipe(
|
|
372
|
+
Effect.catchAllCause(
|
|
373
|
+
(cause) => notifyError(cause, {
|
|
374
|
+
phase: "platform",
|
|
375
|
+
hook: "reset",
|
|
376
|
+
moduleId: identity.moduleId,
|
|
377
|
+
instanceId: identity.instanceId,
|
|
378
|
+
taskId: task.taskId,
|
|
379
|
+
origin: "platform.reset"
|
|
380
|
+
})
|
|
381
|
+
)
|
|
382
|
+
)
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
const getTaskSnapshot = Effect.sync(() => ({
|
|
387
|
+
initRequired: initRequired.map(({ effect: _eff, ...rest }) => rest),
|
|
388
|
+
start: start.map(({ effect: _eff, ...rest }) => rest),
|
|
389
|
+
destroy: destroy.map(({ effect: _eff, ...rest }) => rest),
|
|
390
|
+
platformSuspend: platformSuspend.map(({ effect: _eff, ...rest }) => rest),
|
|
391
|
+
platformResume: platformResume.map(({ effect: _eff, ...rest }) => rest),
|
|
392
|
+
platformReset: platformReset.map(({ effect: _eff, ...rest }) => rest)
|
|
393
|
+
}));
|
|
394
|
+
const hasOnErrorHandlers = Effect.sync(() => onErrorHandlers.length > 0);
|
|
395
|
+
return {
|
|
396
|
+
identity,
|
|
397
|
+
budgets,
|
|
398
|
+
registerPlatformSuspend,
|
|
399
|
+
registerPlatformResume,
|
|
400
|
+
registerPlatformReset,
|
|
401
|
+
registerInitRequired,
|
|
402
|
+
registerStart,
|
|
403
|
+
registerDestroy,
|
|
404
|
+
registerOnError,
|
|
405
|
+
getStatus,
|
|
406
|
+
setStatus,
|
|
407
|
+
notifyError,
|
|
408
|
+
runPlatformSuspend,
|
|
409
|
+
runPlatformResume,
|
|
410
|
+
runPlatformReset,
|
|
411
|
+
runInitRequired,
|
|
412
|
+
runStart,
|
|
413
|
+
runDestroy,
|
|
414
|
+
hasOnErrorHandlers,
|
|
415
|
+
getTaskSnapshot
|
|
416
|
+
};
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
// src/internal/runtime/core/LogicDiagnostics.ts
|
|
420
|
+
import { Cause as Cause2, Context as Context2, Effect as Effect2 } from "effect";
|
|
421
|
+
var phaseDiagnosticsEnabled = () => isDevEnv();
|
|
422
|
+
var SERVICE_NOT_FOUND_PREFIX = "Service not found:";
|
|
423
|
+
var emitEnvServiceNotFoundDiagnosticIfNeeded = (cause, moduleId) => Effect2.gen(function* () {
|
|
424
|
+
let pretty;
|
|
425
|
+
try {
|
|
426
|
+
pretty = Cause2.pretty(cause, { renderErrorCause: true });
|
|
427
|
+
} catch {
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
if (!pretty.includes(SERVICE_NOT_FOUND_PREFIX)) {
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
yield* record({
|
|
434
|
+
type: "diagnostic",
|
|
435
|
+
moduleId,
|
|
436
|
+
code: "logic::env_service_not_found",
|
|
437
|
+
severity: "warning",
|
|
438
|
+
message: pretty,
|
|
439
|
+
hint: "Logic attempted to access an Env service before it was provided. This is a known initialization timing noise in Runtime/React integration. If it happens once during early startup and everything works afterward, it's likely harmless; if it persists or correlates with app issues, verify Runtime.make / RuntimeProvider.layer provides the service."
|
|
440
|
+
});
|
|
441
|
+
yield* record({
|
|
442
|
+
type: "diagnostic",
|
|
443
|
+
moduleId,
|
|
444
|
+
code: "logic::invalid_phase",
|
|
445
|
+
severity: "error",
|
|
446
|
+
message: "$.use is not allowed before Env is fully ready.",
|
|
447
|
+
hint: "Avoid reading services during setup or before Env is ready; move Env access to the Logic run section, or wrap init via $.lifecycle.onInitRequired.",
|
|
448
|
+
kind: "env_service_not_ready"
|
|
449
|
+
});
|
|
450
|
+
});
|
|
451
|
+
var LogicPhaseServiceTag = Context2.GenericTag("@logixjs/LogicPhaseService");
|
|
452
|
+
var LogicUnitServiceTag = class extends Context2.Tag("@logixjs/LogicUnitService")() {
|
|
453
|
+
};
|
|
454
|
+
var makeLogicPhaseError = (kind, api, phase, moduleId) => Object.assign(new Error(`[LogicPhaseError] ${api} is not allowed in ${phase} phase (kind=${kind}).`), {
|
|
455
|
+
_tag: "LogicPhaseError",
|
|
456
|
+
kind,
|
|
457
|
+
api,
|
|
458
|
+
phase,
|
|
459
|
+
moduleId
|
|
460
|
+
});
|
|
461
|
+
var emitInvalidPhaseDiagnosticIfNeeded = (cause, moduleId) => Effect2.gen(function* () {
|
|
462
|
+
if (!phaseDiagnosticsEnabled()) {
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
const allErrors = [...Cause2.failures(cause), ...Cause2.defects(cause)];
|
|
466
|
+
for (const err of allErrors) {
|
|
467
|
+
const logicErr = err;
|
|
468
|
+
if (logicErr && logicErr._tag === "LogicPhaseError") {
|
|
469
|
+
const phaseErr = logicErr;
|
|
470
|
+
const hint = phaseErr.kind === "use_in_setup" || phaseErr.kind === "lifecycle_in_setup" ? "The setup phase must not read Env/services or run long-lived logic; move the relevant calls to the run phase." : phaseErr.kind === "lifecycle_in_run" ? "Do not register $.lifecycle.* in the run phase (setup-only). Move lifecycle registrations to the synchronous part of Module.logic builder (before return)." : phaseErr.kind === "traits_in_run" || phaseErr.kind === "traits_declare_in_run" ? "Traits are frozen after setup; move $.traits.declare to LogicPlan.setup or the setup registration phase of Module.logic builder." : "Move logic to the run phase; keep setup for registrations only.";
|
|
471
|
+
yield* record({
|
|
472
|
+
type: "diagnostic",
|
|
473
|
+
moduleId: phaseErr.moduleId ?? moduleId,
|
|
474
|
+
code: "logic::invalid_phase",
|
|
475
|
+
severity: "error",
|
|
476
|
+
message: `${phaseErr.api ?? phaseErr.kind} is not allowed in ${phaseErr.phase} phase.`,
|
|
477
|
+
hint,
|
|
478
|
+
kind: phaseErr.kind
|
|
479
|
+
});
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
// src/internal/runtime/core/BoundApiRuntime.ts
|
|
486
|
+
var LogicBuilderFactory = (runtime, runtimeInternals) => {
|
|
487
|
+
const flowApi = make(runtime, runtimeInternals);
|
|
488
|
+
return (stream, triggerName) => {
|
|
489
|
+
const runWithStateTransaction = (origin, body) => runtimeInternals.txn.runWithStateTransaction(origin, body);
|
|
490
|
+
const taskRunnerRuntime = {
|
|
491
|
+
moduleId: runtime.moduleId,
|
|
492
|
+
instanceId: runtimeInternals.instanceId,
|
|
493
|
+
runWithStateTransaction,
|
|
494
|
+
resolveConcurrencyPolicy: runtimeInternals.concurrency.resolveConcurrencyPolicy
|
|
495
|
+
};
|
|
496
|
+
const builder = {
|
|
497
|
+
debounce: (ms) => LogicBuilderFactory(runtime, runtimeInternals)(flowApi.debounce(ms)(stream), triggerName),
|
|
498
|
+
throttle: (ms) => LogicBuilderFactory(runtime, runtimeInternals)(flowApi.throttle(ms)(stream), triggerName),
|
|
499
|
+
filter: (predicate) => LogicBuilderFactory(runtime, runtimeInternals)(flowApi.filter(predicate)(stream), triggerName),
|
|
500
|
+
map: (f) => LogicBuilderFactory(runtime, runtimeInternals)(stream.pipe(Stream.map(f)), triggerName),
|
|
501
|
+
run(eff, options) {
|
|
502
|
+
return flowApi.run(eff, options)(stream);
|
|
503
|
+
},
|
|
504
|
+
runLatest(eff, options) {
|
|
505
|
+
return flowApi.runLatest(eff, options)(stream);
|
|
506
|
+
},
|
|
507
|
+
runExhaust(eff, options) {
|
|
508
|
+
return flowApi.runExhaust(eff, options)(stream);
|
|
509
|
+
},
|
|
510
|
+
runParallel(eff, options) {
|
|
511
|
+
return flowApi.runParallel(eff, options)(stream);
|
|
512
|
+
},
|
|
513
|
+
runFork: (eff) => Effect3.forkScoped(flowApi.run(eff)(stream)).pipe(Effect3.asVoid),
|
|
514
|
+
runParallelFork: (eff) => Effect3.forkScoped(flowApi.runParallel(eff)(stream)).pipe(Effect3.asVoid),
|
|
515
|
+
runTask: (config) => makeTaskRunner(stream, "task", taskRunnerRuntime, {
|
|
516
|
+
...config,
|
|
517
|
+
triggerName: config.triggerName ?? triggerName
|
|
518
|
+
}),
|
|
519
|
+
runParallelTask: (config) => makeTaskRunner(stream, "parallel", taskRunnerRuntime, {
|
|
520
|
+
...config,
|
|
521
|
+
triggerName: config.triggerName ?? triggerName
|
|
522
|
+
}),
|
|
523
|
+
runLatestTask: (config) => makeTaskRunner(stream, "latest", taskRunnerRuntime, {
|
|
524
|
+
...config,
|
|
525
|
+
triggerName: config.triggerName ?? triggerName
|
|
526
|
+
}),
|
|
527
|
+
runExhaustTask: (config) => makeTaskRunner(stream, "exhaust", taskRunnerRuntime, {
|
|
528
|
+
...config,
|
|
529
|
+
triggerName: config.triggerName ?? triggerName
|
|
530
|
+
}),
|
|
531
|
+
toStream: () => stream,
|
|
532
|
+
update: (reducer) => Stream.runForEach(
|
|
533
|
+
stream,
|
|
534
|
+
(payload) => taskRunnerRuntime.runWithStateTransaction(
|
|
535
|
+
{
|
|
536
|
+
kind: "watcher:update",
|
|
537
|
+
name: triggerName
|
|
538
|
+
},
|
|
539
|
+
() => Effect3.gen(function* () {
|
|
540
|
+
const prev = yield* runtime.getState;
|
|
541
|
+
const next = reducer(prev, payload);
|
|
542
|
+
if (Effect3.isEffect(next)) {
|
|
543
|
+
const exit = yield* Effect3.exit(next);
|
|
544
|
+
if (exit._tag === "Failure") {
|
|
545
|
+
yield* Effect3.logError("Flow error", exit.cause);
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
yield* runtime.setState(exit.value);
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
yield* runtime.setState(next);
|
|
552
|
+
})
|
|
553
|
+
)
|
|
554
|
+
).pipe(Effect3.catchAllCause((cause) => Effect3.logError("Flow error", cause))),
|
|
555
|
+
mutate: (reducer) => Stream.runForEach(
|
|
556
|
+
stream,
|
|
557
|
+
(payload) => taskRunnerRuntime.runWithStateTransaction(
|
|
558
|
+
{
|
|
559
|
+
kind: "watcher:mutate",
|
|
560
|
+
name: triggerName
|
|
561
|
+
},
|
|
562
|
+
() => Effect3.gen(function* () {
|
|
563
|
+
const prev = yield* runtime.getState;
|
|
564
|
+
const recordPatch = runtimeInternals.txn.recordStatePatch;
|
|
565
|
+
const updateDraft = runtimeInternals.txn.updateDraft;
|
|
566
|
+
const { nextState, patchPaths } = mutateWithPatchPaths(prev, (draft) => {
|
|
567
|
+
reducer(draft, payload);
|
|
568
|
+
});
|
|
569
|
+
for (const path of patchPaths) {
|
|
570
|
+
recordPatch(path, "unknown");
|
|
571
|
+
}
|
|
572
|
+
updateDraft(nextState);
|
|
573
|
+
})
|
|
574
|
+
)
|
|
575
|
+
).pipe(Effect3.catchAllCause((cause) => Effect3.logError("Flow error", cause)))
|
|
576
|
+
};
|
|
577
|
+
const pipe = function() {
|
|
578
|
+
const fns = arguments;
|
|
579
|
+
let acc = builder;
|
|
580
|
+
for (let i = 0; i < fns.length; i++) {
|
|
581
|
+
acc = fns[i](acc);
|
|
582
|
+
}
|
|
583
|
+
return acc;
|
|
584
|
+
};
|
|
585
|
+
return Object.assign(builder, { pipe });
|
|
586
|
+
};
|
|
587
|
+
};
|
|
588
|
+
function make2(shape, runtime, options) {
|
|
589
|
+
const runtimeInternals = getRuntimeInternals(runtime);
|
|
590
|
+
const getPhase = options?.getPhase ?? (() => "run");
|
|
591
|
+
const getCurrentPhase = () => {
|
|
592
|
+
const phaseService = options?.phaseService;
|
|
593
|
+
const phase = phaseService?.current ?? getPhase();
|
|
594
|
+
return phase === "setup" ? "setup" : "run";
|
|
595
|
+
};
|
|
596
|
+
const guardRunOnly = (kind, api2) => {
|
|
597
|
+
const phaseService = options?.phaseService;
|
|
598
|
+
const phase = phaseService?.current ?? getPhase();
|
|
599
|
+
if (phase === "setup") {
|
|
600
|
+
throw makeLogicPhaseError(kind, api2, "setup", options?.moduleId);
|
|
601
|
+
}
|
|
602
|
+
};
|
|
603
|
+
const flowApi = make(runtime, runtimeInternals);
|
|
604
|
+
const makeIntentBuilder = (runtime_) => LogicBuilderFactory(runtime_, runtimeInternals);
|
|
605
|
+
const withLifecycle = (available, missing) => Effect3.serviceOption(LifecycleContext).pipe(
|
|
606
|
+
Effect3.flatMap(
|
|
607
|
+
(maybe) => Option.match(maybe, {
|
|
608
|
+
onSome: available,
|
|
609
|
+
onNone: missing
|
|
610
|
+
})
|
|
611
|
+
)
|
|
612
|
+
);
|
|
613
|
+
const withPlatform = (invoke) => Effect3.serviceOption(Tag).pipe(
|
|
614
|
+
Effect3.flatMap(
|
|
615
|
+
(maybe) => Option.match(maybe, {
|
|
616
|
+
onSome: invoke,
|
|
617
|
+
onNone: () => Effect3.void
|
|
618
|
+
})
|
|
619
|
+
)
|
|
620
|
+
);
|
|
621
|
+
const emitSetupOnlyViolation = (api2) => record({
|
|
622
|
+
type: "diagnostic",
|
|
623
|
+
moduleId: runtime.moduleId,
|
|
624
|
+
instanceId: runtime.instanceId,
|
|
625
|
+
code: "logic::invalid_phase",
|
|
626
|
+
severity: "error",
|
|
627
|
+
message: `${api2} is setup-only and is not allowed in run phase.`,
|
|
628
|
+
hint: "Move $.lifecycle.* calls to the synchronous part of Module.logic builder (before return) for registration; for dynamic resource cleanup in the run phase, use Effect.acquireRelease / Scope finalizer instead of registering onDestroy late.",
|
|
629
|
+
kind: "lifecycle_in_run"
|
|
630
|
+
});
|
|
631
|
+
const createIntentBuilder = (stream, triggerName) => makeIntentBuilder(runtime)(stream, triggerName);
|
|
632
|
+
const onceInRunSession = (key) => Effect3.serviceOption(RunSessionTag).pipe(
|
|
633
|
+
Effect3.map((maybe) => Option.isSome(maybe) ? maybe.value.local.once(key) : true)
|
|
634
|
+
);
|
|
635
|
+
let cachedDiagnosticsLevel;
|
|
636
|
+
const isModuleLike = (value) => Boolean(
|
|
637
|
+
value && typeof value === "object" && (value._kind === "ModuleDef" || value._kind === "Module") && "tag" in value && Context3.isTag(value.tag)
|
|
638
|
+
);
|
|
639
|
+
const buildModuleHandle = (tag, rt) => {
|
|
640
|
+
const actionsProxy = new Proxy(
|
|
641
|
+
{},
|
|
642
|
+
{
|
|
643
|
+
get: (_target, prop) => (payload) => rt.dispatch({
|
|
644
|
+
_tag: prop,
|
|
645
|
+
payload
|
|
646
|
+
})
|
|
647
|
+
}
|
|
648
|
+
);
|
|
649
|
+
const handle = {
|
|
650
|
+
read: (selector) => Effect3.map(rt.getState, selector),
|
|
651
|
+
changes: rt.changes,
|
|
652
|
+
dispatch: rt.dispatch,
|
|
653
|
+
actions$: rt.actions$,
|
|
654
|
+
actions: actionsProxy
|
|
655
|
+
};
|
|
656
|
+
const EXTEND_HANDLE = /* @__PURE__ */ Symbol.for("logix.module.handle.extend");
|
|
657
|
+
const extend = tag?.[EXTEND_HANDLE];
|
|
658
|
+
return typeof extend === "function" ? extend(rt, handle) ?? handle : handle;
|
|
659
|
+
};
|
|
660
|
+
const emitModuleDescriptorOnce = (module, rt) => Effect3.gen(function* () {
|
|
661
|
+
if (cachedDiagnosticsLevel === "off") return;
|
|
662
|
+
const key = `module_descriptor:${String(rt.instanceId ?? "unknown")}`;
|
|
663
|
+
const shouldEmit = yield* onceInRunSession(key);
|
|
664
|
+
if (!shouldEmit) return;
|
|
665
|
+
const actionKeys = Object.keys(module.tag?.shape?.actionMap ?? {});
|
|
666
|
+
const internalSymbol = /* @__PURE__ */ Symbol.for("logix.module.internal");
|
|
667
|
+
const internal = module[internalSymbol];
|
|
668
|
+
const logicUnits = (internal?.mounted ?? []).map((u) => ({
|
|
669
|
+
kind: String(u?.kind ?? "user"),
|
|
670
|
+
id: String(u?.id ?? ""),
|
|
671
|
+
derived: u?.derived ? true : void 0,
|
|
672
|
+
name: typeof u?.name === "string" ? u.name : void 0
|
|
673
|
+
}));
|
|
674
|
+
const schemaKeys = module.schemas && typeof module.schemas === "object" ? Object.keys(module.schemas) : void 0;
|
|
675
|
+
const meta = module.meta && typeof module.meta === "object" ? module.meta : void 0;
|
|
676
|
+
const source = module.dev?.source;
|
|
677
|
+
const traitsSnapshot = runtimeInternals.traits.getModuleTraitsSnapshot();
|
|
678
|
+
const traits = traitsSnapshot ? {
|
|
679
|
+
digest: traitsSnapshot.digest,
|
|
680
|
+
count: traitsSnapshot.traits.length
|
|
681
|
+
} : void 0;
|
|
682
|
+
const data = {
|
|
683
|
+
id: module.id,
|
|
684
|
+
moduleId: String(rt.moduleId),
|
|
685
|
+
instanceId: String(rt.instanceId),
|
|
686
|
+
actionKeys,
|
|
687
|
+
logicUnits,
|
|
688
|
+
schemaKeys,
|
|
689
|
+
meta,
|
|
690
|
+
source,
|
|
691
|
+
traits
|
|
692
|
+
};
|
|
693
|
+
yield* record({
|
|
694
|
+
type: "trace:module:descriptor",
|
|
695
|
+
moduleId: rt.moduleId,
|
|
696
|
+
instanceId: rt.instanceId,
|
|
697
|
+
data
|
|
698
|
+
});
|
|
699
|
+
});
|
|
700
|
+
const resolveModuleRuntime = (tag) => Effect3.gen(function* () {
|
|
701
|
+
const requestedModuleId = typeof tag?.id === "string" ? tag.id : void 0;
|
|
702
|
+
const fromModuleId = typeof options?.moduleId === "string" ? options.moduleId : runtime.moduleId;
|
|
703
|
+
if (requestedModuleId && requestedModuleId === runtime.moduleId) {
|
|
704
|
+
return runtime;
|
|
705
|
+
}
|
|
706
|
+
const fromImports = runtimeInternals.imports.get(tag);
|
|
707
|
+
if (fromImports) {
|
|
708
|
+
return fromImports;
|
|
709
|
+
}
|
|
710
|
+
if (typeof options?.moduleId !== "string") {
|
|
711
|
+
const fromEnv = yield* Effect3.serviceOption(tag);
|
|
712
|
+
if (Option.isSome(fromEnv)) {
|
|
713
|
+
return fromEnv.value;
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
const tokenId = requestedModuleId ?? "<unknown module id>";
|
|
717
|
+
const fix = isDevEnv() ? [
|
|
718
|
+
"- Provide the child implementation in the same scope (imports).",
|
|
719
|
+
` Example: ${fromModuleId ?? "ParentModule"}.implement({ imports: [${requestedModuleId ?? "ChildModule"}.impl], ... })`,
|
|
720
|
+
"- If you intentionally want a root singleton, provide it at app root (Runtime.make(...,{ layer }) / root imports),",
|
|
721
|
+
" and use Root.resolve(ModuleTag) (instead of $.use) at the callsite."
|
|
722
|
+
] : [];
|
|
723
|
+
const err = new Error(
|
|
724
|
+
isDevEnv() ? [
|
|
725
|
+
"[MissingModuleRuntimeError] Cannot resolve ModuleRuntime for ModuleTag.",
|
|
726
|
+
"",
|
|
727
|
+
`tokenId: ${tokenId}`,
|
|
728
|
+
"entrypoint: logic.$.use",
|
|
729
|
+
"mode: strict",
|
|
730
|
+
`from: ${fromModuleId ?? "<unknown module id>"}`,
|
|
731
|
+
`startScope: moduleId=${fromModuleId ?? "<unknown>"}, instanceId=${String(runtime.instanceId ?? "<unknown>")}`,
|
|
732
|
+
"",
|
|
733
|
+
"fix:",
|
|
734
|
+
...fix
|
|
735
|
+
].join("\n") : "[MissingModuleRuntimeError] module runtime not found"
|
|
736
|
+
);
|
|
737
|
+
err.tokenId = tokenId;
|
|
738
|
+
err.entrypoint = "logic.$.use";
|
|
739
|
+
err.mode = "strict";
|
|
740
|
+
err.from = fromModuleId;
|
|
741
|
+
err.startScope = {
|
|
742
|
+
moduleId: fromModuleId,
|
|
743
|
+
instanceId: String(runtime.instanceId ?? "<unknown>")
|
|
744
|
+
};
|
|
745
|
+
err.fix = fix;
|
|
746
|
+
err.name = "MissingModuleRuntimeError";
|
|
747
|
+
return yield* Effect3.die(err);
|
|
748
|
+
});
|
|
749
|
+
const stateApi = {
|
|
750
|
+
read: runtime.getState,
|
|
751
|
+
update: (f) => Effect3.gen(function* () {
|
|
752
|
+
const inTxn = yield* FiberRef.get(inSyncTransactionFiber);
|
|
753
|
+
if (inTxn) {
|
|
754
|
+
const prev = yield* runtime.getState;
|
|
755
|
+
return yield* runtime.setState(f(prev));
|
|
756
|
+
}
|
|
757
|
+
const body = () => Effect3.flatMap(runtime.getState, (prev) => runtime.setState(f(prev)));
|
|
758
|
+
return yield* runtimeInternals ? runtimeInternals.txn.runWithStateTransaction({ kind: "state", name: "update" }, body) : body();
|
|
759
|
+
}),
|
|
760
|
+
mutate: (f) => Effect3.gen(function* () {
|
|
761
|
+
const recordPatch = runtimeInternals?.txn.recordStatePatch;
|
|
762
|
+
const updateDraft = runtimeInternals?.txn.updateDraft;
|
|
763
|
+
const inTxn = yield* FiberRef.get(inSyncTransactionFiber);
|
|
764
|
+
if (inTxn) {
|
|
765
|
+
const prev = yield* runtime.getState;
|
|
766
|
+
const { nextState, patchPaths } = mutateWithPatchPaths(prev, (draft) => {
|
|
767
|
+
f(draft);
|
|
768
|
+
});
|
|
769
|
+
for (const path of patchPaths) {
|
|
770
|
+
recordPatch?.(path, "unknown");
|
|
771
|
+
}
|
|
772
|
+
updateDraft?.(nextState);
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
const body = () => Effect3.gen(function* () {
|
|
776
|
+
const prev = yield* runtime.getState;
|
|
777
|
+
const { nextState, patchPaths } = mutateWithPatchPaths(prev, (draft) => {
|
|
778
|
+
f(draft);
|
|
779
|
+
});
|
|
780
|
+
for (const path of patchPaths) {
|
|
781
|
+
recordPatch?.(path, "unknown");
|
|
782
|
+
}
|
|
783
|
+
updateDraft?.(nextState);
|
|
784
|
+
});
|
|
785
|
+
return yield* runtimeInternals ? runtimeInternals.txn.runWithStateTransaction({ kind: "state", name: "mutate" }, body) : body();
|
|
786
|
+
}),
|
|
787
|
+
ref: runtime.ref
|
|
788
|
+
};
|
|
789
|
+
const actions = shape.actionMap;
|
|
790
|
+
const dispatcherCache = /* @__PURE__ */ new Map();
|
|
791
|
+
const hasAction = (key) => Object.prototype.hasOwnProperty.call(actions, key);
|
|
792
|
+
const dispatchers = new Proxy({}, {
|
|
793
|
+
get: (_target, prop) => {
|
|
794
|
+
if (typeof prop !== "string") return void 0;
|
|
795
|
+
if (!hasAction(prop)) return void 0;
|
|
796
|
+
const cached = dispatcherCache.get(prop);
|
|
797
|
+
if (cached) return cached;
|
|
798
|
+
const token = actions[prop];
|
|
799
|
+
const fn = (...args) => runtime.dispatch(token(...args));
|
|
800
|
+
dispatcherCache.set(prop, fn);
|
|
801
|
+
return fn;
|
|
802
|
+
},
|
|
803
|
+
has: (_target, prop) => typeof prop === "string" && hasAction(prop),
|
|
804
|
+
ownKeys: () => Object.keys(actions),
|
|
805
|
+
getOwnPropertyDescriptor: (_target, prop) => {
|
|
806
|
+
if (typeof prop !== "string") return void 0;
|
|
807
|
+
if (!hasAction(prop)) return void 0;
|
|
808
|
+
return { enumerable: true, configurable: true };
|
|
809
|
+
}
|
|
810
|
+
});
|
|
811
|
+
const dispatch = (...args) => {
|
|
812
|
+
const [first, second] = args;
|
|
813
|
+
if (typeof first === "string") {
|
|
814
|
+
return runtime.dispatch({ _tag: first, payload: second });
|
|
815
|
+
}
|
|
816
|
+
if (isActionToken(first)) {
|
|
817
|
+
return runtime.dispatch(first(second));
|
|
818
|
+
}
|
|
819
|
+
return runtime.dispatch(first);
|
|
820
|
+
};
|
|
821
|
+
const matchApi = (value) => makeMatch(value);
|
|
822
|
+
const matchTagApi = (value) => makeMatchTag(value);
|
|
823
|
+
const reducer = (tag, fn) => {
|
|
824
|
+
return Effect3.sync(() => {
|
|
825
|
+
runtimeInternals.txn.registerReducer(String(tag), fn);
|
|
826
|
+
});
|
|
827
|
+
};
|
|
828
|
+
const effect = (token, handler) => Effect3.gen(function* () {
|
|
829
|
+
if (!isActionToken(token)) {
|
|
830
|
+
return yield* Effect3.dieMessage("[BoundApi.effect] token must be an ActionToken");
|
|
831
|
+
}
|
|
832
|
+
const phase = getCurrentPhase();
|
|
833
|
+
const logicUnit = options?.logicUnit;
|
|
834
|
+
yield* runtimeInternals.effects.registerEffect({
|
|
835
|
+
actionTag: token.tag,
|
|
836
|
+
handler,
|
|
837
|
+
phase,
|
|
838
|
+
...logicUnit ? {
|
|
839
|
+
logicUnit: {
|
|
840
|
+
logicUnitId: logicUnit.logicUnitId,
|
|
841
|
+
logicUnitLabel: logicUnit.logicUnitLabel,
|
|
842
|
+
path: logicUnit.path
|
|
843
|
+
}
|
|
844
|
+
} : {}
|
|
845
|
+
});
|
|
846
|
+
});
|
|
847
|
+
const api = {
|
|
848
|
+
root: {
|
|
849
|
+
resolve: (tag) => {
|
|
850
|
+
guardRunOnly("root_resolve_in_setup", "$.root.resolve");
|
|
851
|
+
return resolve(tag, {
|
|
852
|
+
entrypoint: "logic.$.root.resolve",
|
|
853
|
+
waitForReady: true
|
|
854
|
+
});
|
|
855
|
+
}
|
|
856
|
+
},
|
|
857
|
+
state: stateApi,
|
|
858
|
+
actions,
|
|
859
|
+
dispatchers,
|
|
860
|
+
dispatch,
|
|
861
|
+
flow: flowApi,
|
|
862
|
+
match: matchApi,
|
|
863
|
+
matchTag: matchTagApi,
|
|
864
|
+
lifecycle: {
|
|
865
|
+
onInitRequired: (eff) => {
|
|
866
|
+
if (getCurrentPhase() === "run") {
|
|
867
|
+
return emitSetupOnlyViolation("$.lifecycle.onInitRequired");
|
|
868
|
+
}
|
|
869
|
+
runtimeInternals.lifecycle.registerInitRequired(eff);
|
|
870
|
+
return Effect3.void;
|
|
871
|
+
},
|
|
872
|
+
onStart: (eff) => {
|
|
873
|
+
if (getCurrentPhase() === "run") {
|
|
874
|
+
return emitSetupOnlyViolation("$.lifecycle.onStart");
|
|
875
|
+
}
|
|
876
|
+
runtimeInternals.lifecycle.registerStart(eff);
|
|
877
|
+
return Effect3.void;
|
|
878
|
+
},
|
|
879
|
+
onInit: (eff) => {
|
|
880
|
+
if (getCurrentPhase() === "run") {
|
|
881
|
+
return emitSetupOnlyViolation("$.lifecycle.onInit");
|
|
882
|
+
}
|
|
883
|
+
runtimeInternals.lifecycle.registerInitRequired(eff);
|
|
884
|
+
return Effect3.void;
|
|
885
|
+
},
|
|
886
|
+
onDestroy: (eff) => {
|
|
887
|
+
if (getCurrentPhase() === "run") {
|
|
888
|
+
return emitSetupOnlyViolation("$.lifecycle.onDestroy");
|
|
889
|
+
}
|
|
890
|
+
runtimeInternals.lifecycle.registerDestroy(eff);
|
|
891
|
+
return Effect3.void;
|
|
892
|
+
},
|
|
893
|
+
onError: (handler) => {
|
|
894
|
+
if (getCurrentPhase() === "run") {
|
|
895
|
+
return emitSetupOnlyViolation("$.lifecycle.onError");
|
|
896
|
+
}
|
|
897
|
+
runtimeInternals.lifecycle.registerOnError(handler);
|
|
898
|
+
return Effect3.void;
|
|
899
|
+
},
|
|
900
|
+
onSuspend: (eff) => {
|
|
901
|
+
if (getCurrentPhase() === "run") {
|
|
902
|
+
return emitSetupOnlyViolation("$.lifecycle.onSuspend");
|
|
903
|
+
}
|
|
904
|
+
runtimeInternals.lifecycle.registerPlatformSuspend(Effect3.asVoid(eff));
|
|
905
|
+
return Effect3.void;
|
|
906
|
+
},
|
|
907
|
+
onResume: (eff) => {
|
|
908
|
+
if (getCurrentPhase() === "run") {
|
|
909
|
+
return emitSetupOnlyViolation("$.lifecycle.onResume");
|
|
910
|
+
}
|
|
911
|
+
runtimeInternals.lifecycle.registerPlatformResume(Effect3.asVoid(eff));
|
|
912
|
+
return Effect3.void;
|
|
913
|
+
},
|
|
914
|
+
onReset: (eff) => {
|
|
915
|
+
if (getCurrentPhase() === "run") {
|
|
916
|
+
return emitSetupOnlyViolation("$.lifecycle.onReset");
|
|
917
|
+
}
|
|
918
|
+
runtimeInternals.lifecycle.registerPlatformReset(Effect3.asVoid(eff));
|
|
919
|
+
return Effect3.void;
|
|
920
|
+
}
|
|
921
|
+
},
|
|
922
|
+
traits: {
|
|
923
|
+
declare: (traits) => {
|
|
924
|
+
if (getCurrentPhase() === "run") {
|
|
925
|
+
throw makeLogicPhaseError(
|
|
926
|
+
"traits_declare_in_run",
|
|
927
|
+
"$.traits.declare",
|
|
928
|
+
"run",
|
|
929
|
+
options?.moduleId
|
|
930
|
+
);
|
|
931
|
+
}
|
|
932
|
+
if (!traits || typeof traits !== "object") {
|
|
933
|
+
throw new Error("[InvalidTraitsDeclaration] $.traits.declare expects an object.");
|
|
934
|
+
}
|
|
935
|
+
const logicUnit = options?.logicUnit ?? {
|
|
936
|
+
logicUnitId: "unknown",
|
|
937
|
+
logicUnitIdKind: "derived",
|
|
938
|
+
logicUnitLabel: "logicUnit:unknown",
|
|
939
|
+
path: void 0
|
|
940
|
+
};
|
|
941
|
+
runtimeInternals.traits.registerModuleTraitsContribution({
|
|
942
|
+
traits,
|
|
943
|
+
provenance: {
|
|
944
|
+
originType: "logicUnit",
|
|
945
|
+
originId: logicUnit.logicUnitId,
|
|
946
|
+
originIdKind: logicUnit.logicUnitIdKind,
|
|
947
|
+
originLabel: logicUnit.logicUnitLabel,
|
|
948
|
+
path: logicUnit.path
|
|
949
|
+
}
|
|
950
|
+
});
|
|
951
|
+
},
|
|
952
|
+
source: {
|
|
953
|
+
refresh: (fieldPath, options2) => Effect3.gen(function* () {
|
|
954
|
+
const handler = runtimeInternals.traits.getSourceRefreshHandler(fieldPath);
|
|
955
|
+
if (!handler) {
|
|
956
|
+
return yield* Effect3.void;
|
|
957
|
+
}
|
|
958
|
+
const force = options2?.force === true;
|
|
959
|
+
const runHandler = (state) => force ? Effect3.locally(forceSourceRefresh, true)(handler(state)) : handler(state);
|
|
960
|
+
const inTxn = yield* FiberRef.get(inSyncTransactionFiber);
|
|
961
|
+
if (inTxn) {
|
|
962
|
+
const state = yield* runtime.getState;
|
|
963
|
+
return yield* runHandler(state);
|
|
964
|
+
}
|
|
965
|
+
return yield* runtimeInternals.txn.runWithStateTransaction(
|
|
966
|
+
{
|
|
967
|
+
kind: "source-refresh",
|
|
968
|
+
name: fieldPath
|
|
969
|
+
},
|
|
970
|
+
() => Effect3.gen(function* () {
|
|
971
|
+
const state = yield* runtime.getState;
|
|
972
|
+
return yield* runHandler(state);
|
|
973
|
+
})
|
|
974
|
+
);
|
|
975
|
+
})
|
|
976
|
+
}
|
|
977
|
+
},
|
|
978
|
+
reducer,
|
|
979
|
+
effect,
|
|
980
|
+
use: new Proxy(() => {
|
|
981
|
+
}, {
|
|
982
|
+
apply: (_target, _thisArg, [arg]) => {
|
|
983
|
+
guardRunOnly("use_in_setup", "$.use");
|
|
984
|
+
if (isModuleLike(arg)) {
|
|
985
|
+
const domain = arg;
|
|
986
|
+
const tag = domain.tag;
|
|
987
|
+
const resolveAndBuild = resolveModuleRuntime(tag).pipe(Effect3.map((rt) => buildModuleHandle(tag, rt)));
|
|
988
|
+
const resolveWithDescriptor = resolveModuleRuntime(tag).pipe(
|
|
989
|
+
Effect3.tap((rt) => emitModuleDescriptorOnce(domain, rt)),
|
|
990
|
+
Effect3.map((rt) => buildModuleHandle(tag, rt))
|
|
991
|
+
);
|
|
992
|
+
const detectAndSelect = FiberRef.get(currentDiagnosticsLevel).pipe(
|
|
993
|
+
Effect3.tap((level) => {
|
|
994
|
+
cachedDiagnosticsLevel = level;
|
|
995
|
+
}),
|
|
996
|
+
Effect3.flatMap((level) => level === "off" ? resolveAndBuild : resolveWithDescriptor)
|
|
997
|
+
);
|
|
998
|
+
return Effect3.suspend(() => {
|
|
999
|
+
if (cachedDiagnosticsLevel === "off") {
|
|
1000
|
+
return resolveAndBuild;
|
|
1001
|
+
}
|
|
1002
|
+
if (cachedDiagnosticsLevel !== void 0) {
|
|
1003
|
+
return resolveWithDescriptor;
|
|
1004
|
+
}
|
|
1005
|
+
return detectAndSelect;
|
|
1006
|
+
});
|
|
1007
|
+
}
|
|
1008
|
+
if (Context3.isTag(arg)) {
|
|
1009
|
+
const candidate = arg;
|
|
1010
|
+
if (candidate._kind === "ModuleTag") {
|
|
1011
|
+
return resolveModuleRuntime(arg).pipe(
|
|
1012
|
+
Effect3.map((rt) => buildModuleHandle(arg, rt))
|
|
1013
|
+
);
|
|
1014
|
+
}
|
|
1015
|
+
return arg;
|
|
1016
|
+
}
|
|
1017
|
+
return Effect3.die("BoundApi.use: unsupported argument");
|
|
1018
|
+
}
|
|
1019
|
+
}),
|
|
1020
|
+
onAction: new Proxy(() => {
|
|
1021
|
+
}, {
|
|
1022
|
+
apply: (_target, _thisArg, args) => {
|
|
1023
|
+
guardRunOnly("use_in_setup", "$.onAction");
|
|
1024
|
+
const arg = args[0];
|
|
1025
|
+
if (isActionToken(arg)) {
|
|
1026
|
+
const tag = arg.tag;
|
|
1027
|
+
return createIntentBuilder(
|
|
1028
|
+
runtime.actions$.pipe(
|
|
1029
|
+
Stream.filter((a) => a._tag === tag || a.type === tag),
|
|
1030
|
+
Stream.map((a) => a.payload)
|
|
1031
|
+
),
|
|
1032
|
+
tag
|
|
1033
|
+
);
|
|
1034
|
+
}
|
|
1035
|
+
if (typeof arg === "function") {
|
|
1036
|
+
return createIntentBuilder(runtime.actions$.pipe(Stream.filter(arg)));
|
|
1037
|
+
}
|
|
1038
|
+
if (typeof arg === "string") {
|
|
1039
|
+
return createIntentBuilder(
|
|
1040
|
+
runtime.actions$.pipe(Stream.filter((a) => a._tag === arg || a.type === arg)),
|
|
1041
|
+
arg
|
|
1042
|
+
);
|
|
1043
|
+
}
|
|
1044
|
+
if (typeof arg === "object" && arg !== null) {
|
|
1045
|
+
if ("_tag" in arg) {
|
|
1046
|
+
return createIntentBuilder(
|
|
1047
|
+
runtime.actions$.pipe(Stream.filter((a) => a._tag === arg._tag)),
|
|
1048
|
+
String(arg._tag)
|
|
1049
|
+
);
|
|
1050
|
+
}
|
|
1051
|
+
if (Schema.isSchema(arg)) {
|
|
1052
|
+
return createIntentBuilder(
|
|
1053
|
+
runtime.actions$.pipe(
|
|
1054
|
+
Stream.filter((a) => {
|
|
1055
|
+
const result = Schema.decodeUnknownSync(arg)(a);
|
|
1056
|
+
return !!result;
|
|
1057
|
+
})
|
|
1058
|
+
)
|
|
1059
|
+
);
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
return createIntentBuilder(runtime.actions$);
|
|
1063
|
+
},
|
|
1064
|
+
get: (_target, prop) => {
|
|
1065
|
+
guardRunOnly("use_in_setup", "$.onAction");
|
|
1066
|
+
if (typeof prop === "string") {
|
|
1067
|
+
return createIntentBuilder(
|
|
1068
|
+
runtime.actions$.pipe(Stream.filter((a) => a._tag === prop || a.type === prop)),
|
|
1069
|
+
prop
|
|
1070
|
+
);
|
|
1071
|
+
}
|
|
1072
|
+
return void 0;
|
|
1073
|
+
}
|
|
1074
|
+
}),
|
|
1075
|
+
onState: (selector) => {
|
|
1076
|
+
guardRunOnly("use_in_setup", "$.onState");
|
|
1077
|
+
return createIntentBuilder(runtime.changes(selector));
|
|
1078
|
+
},
|
|
1079
|
+
on: (stream) => {
|
|
1080
|
+
guardRunOnly("use_in_setup", "$.on");
|
|
1081
|
+
return createIntentBuilder(stream);
|
|
1082
|
+
}
|
|
1083
|
+
};
|
|
1084
|
+
setBoundInternals(api, runtimeInternals);
|
|
1085
|
+
return api;
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
export {
|
|
1089
|
+
mutateWithoutPatches,
|
|
1090
|
+
mutateWithPatchPaths,
|
|
1091
|
+
LifecycleContext,
|
|
1092
|
+
makeLifecycleManager,
|
|
1093
|
+
emitEnvServiceNotFoundDiagnosticIfNeeded,
|
|
1094
|
+
LogicPhaseServiceTag,
|
|
1095
|
+
LogicUnitServiceTag,
|
|
1096
|
+
emitInvalidPhaseDiagnosticIfNeeded,
|
|
1097
|
+
make2 as make
|
|
1098
|
+
};
|
|
1099
|
+
//# sourceMappingURL=chunk-BE3HW4FY.js.map
|