@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
package/dist/Bound.cjs
ADDED
|
@@ -0,0 +1,1532 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/Bound.ts
|
|
21
|
+
var Bound_exports = {};
|
|
22
|
+
__export(Bound_exports, {
|
|
23
|
+
make: () => make4
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(Bound_exports);
|
|
26
|
+
|
|
27
|
+
// src/internal/runtime/core/BoundApiRuntime.ts
|
|
28
|
+
var import_effect16 = require("effect");
|
|
29
|
+
|
|
30
|
+
// src/internal/action.ts
|
|
31
|
+
var import_effect = require("effect");
|
|
32
|
+
var isActionToken = (value) => typeof value === "function" && value._kind === "ActionToken" && typeof value.tag === "string" && import_effect.Schema.isSchema(value.schema);
|
|
33
|
+
|
|
34
|
+
// src/internal/runtime/core/TaskRunner.ts
|
|
35
|
+
var import_effect6 = require("effect");
|
|
36
|
+
|
|
37
|
+
// src/internal/runtime/core/DebugSink.ts
|
|
38
|
+
var import_effect4 = require("effect");
|
|
39
|
+
|
|
40
|
+
// src/internal/observability/jsonValue.ts
|
|
41
|
+
var defaultOptions = {
|
|
42
|
+
maxDepth: 6,
|
|
43
|
+
maxObjectKeys: 32,
|
|
44
|
+
maxArrayLength: 32,
|
|
45
|
+
maxStringLength: 256,
|
|
46
|
+
maxJsonBytes: 4 * 1024,
|
|
47
|
+
oversizedPreviewBytes: 256
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// src/internal/runtime/core/errorSummary.ts
|
|
51
|
+
var import_effect2 = require("effect");
|
|
52
|
+
|
|
53
|
+
// src/internal/runtime/core/EffectOpCore.ts
|
|
54
|
+
var import_effect3 = require("effect");
|
|
55
|
+
var currentLinkId = import_effect3.FiberRef.unsafeMake(void 0);
|
|
56
|
+
var EffectOpMiddlewareTag = class extends import_effect3.Context.Tag("Logix/EffectOpMiddleware")() {
|
|
57
|
+
};
|
|
58
|
+
var composeMiddleware = (stack) => {
|
|
59
|
+
return (op) => stack.reduceRight(
|
|
60
|
+
(eff, mw) => mw({ ...op, effect: eff }),
|
|
61
|
+
op.effect
|
|
62
|
+
);
|
|
63
|
+
};
|
|
64
|
+
var runWithMiddleware = (op, stack) => {
|
|
65
|
+
return import_effect3.Effect.gen(function* () {
|
|
66
|
+
const existing = yield* import_effect3.FiberRef.get(currentLinkId);
|
|
67
|
+
const metaLinkId = op.meta?.linkId;
|
|
68
|
+
const linkId = typeof metaLinkId === "string" && metaLinkId.length > 0 ? metaLinkId : existing ?? op.id;
|
|
69
|
+
const nextOp = {
|
|
70
|
+
...op,
|
|
71
|
+
meta: {
|
|
72
|
+
...op.meta ?? {},
|
|
73
|
+
linkId
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const program = stack.length ? composeMiddleware(stack)(nextOp) : nextOp.effect;
|
|
77
|
+
return yield* import_effect3.Effect.locally(currentLinkId, linkId)(program);
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// src/internal/runtime/core/DebugSink.ts
|
|
82
|
+
var currentDebugSinks = import_effect4.FiberRef.unsafeMake([]);
|
|
83
|
+
var currentRuntimeLabel = import_effect4.FiberRef.unsafeMake(void 0);
|
|
84
|
+
var currentTxnId = import_effect4.FiberRef.unsafeMake(void 0);
|
|
85
|
+
var currentOpSeq = import_effect4.FiberRef.unsafeMake(void 0);
|
|
86
|
+
var currentDiagnosticsLevel = import_effect4.FiberRef.unsafeMake("off");
|
|
87
|
+
var currentTraitConvergeDiagnosticsSampling = import_effect4.FiberRef.unsafeMake({
|
|
88
|
+
sampleEveryN: 32,
|
|
89
|
+
topK: 3
|
|
90
|
+
});
|
|
91
|
+
var browserLifecycleSeen = /* @__PURE__ */ new Set();
|
|
92
|
+
var browserDiagnosticSeen = /* @__PURE__ */ new Set();
|
|
93
|
+
var lifecycleErrorLog = (event) => {
|
|
94
|
+
const moduleId = event.moduleId ?? "unknown";
|
|
95
|
+
const causePretty = (() => {
|
|
96
|
+
try {
|
|
97
|
+
return import_effect4.Cause.pretty(event.cause, {
|
|
98
|
+
renderErrorCause: true
|
|
99
|
+
});
|
|
100
|
+
} catch {
|
|
101
|
+
try {
|
|
102
|
+
return JSON.stringify(event.cause, null, 2);
|
|
103
|
+
} catch {
|
|
104
|
+
return String(event.cause);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
})();
|
|
108
|
+
const message = `[Logix][module=${moduleId}] lifecycle:error
|
|
109
|
+
${causePretty}`;
|
|
110
|
+
return import_effect4.Effect.logError(message).pipe(
|
|
111
|
+
import_effect4.Effect.annotateLogs({
|
|
112
|
+
"logix.moduleId": moduleId,
|
|
113
|
+
"logix.event": "lifecycle:error",
|
|
114
|
+
"logix.cause": causePretty
|
|
115
|
+
})
|
|
116
|
+
);
|
|
117
|
+
};
|
|
118
|
+
var diagnosticLog = (event) => {
|
|
119
|
+
const moduleId = event.moduleId ?? "unknown";
|
|
120
|
+
const header = `[Logix][module=${moduleId}] diagnostic(${event.severity})`;
|
|
121
|
+
const detail = `code=${event.code} message=${event.message}${event.actionTag ? ` action=${event.actionTag}` : ""}${event.hint ? `
|
|
122
|
+
hint: ${event.hint}` : ""}`;
|
|
123
|
+
const msg = `${header}
|
|
124
|
+
${detail}`;
|
|
125
|
+
const base = event.severity === "warning" ? import_effect4.Effect.logWarning(msg) : event.severity === "info" ? import_effect4.Effect.logInfo(msg) : import_effect4.Effect.logError(msg);
|
|
126
|
+
const annotations = {
|
|
127
|
+
"logix.moduleId": moduleId,
|
|
128
|
+
"logix.event": `diagnostic(${event.severity})`,
|
|
129
|
+
"logix.diagnostic.code": event.code,
|
|
130
|
+
"logix.diagnostic.message": event.message
|
|
131
|
+
};
|
|
132
|
+
if (event.hint) {
|
|
133
|
+
annotations["logix.diagnostic.hint"] = event.hint;
|
|
134
|
+
}
|
|
135
|
+
if (event.actionTag) {
|
|
136
|
+
annotations["logix.diagnostic.actionTag"] = event.actionTag;
|
|
137
|
+
}
|
|
138
|
+
return base.pipe(import_effect4.Effect.annotateLogs(annotations));
|
|
139
|
+
};
|
|
140
|
+
var noopLayer = import_effect4.Layer.locallyScoped(currentDebugSinks, []);
|
|
141
|
+
var errorOnlySink = {
|
|
142
|
+
record: (event) => event.type === "lifecycle:error" ? lifecycleErrorLog(event) : event.type === "diagnostic" && event.severity !== "info" ? diagnosticLog(event) : import_effect4.Effect.void
|
|
143
|
+
};
|
|
144
|
+
var errorOnlyLayer = import_effect4.Layer.locallyScoped(currentDebugSinks, [errorOnlySink]);
|
|
145
|
+
var isErrorOnlyOnlySinks = (sinks) => sinks.length === 1 && sinks[0] === errorOnlySink;
|
|
146
|
+
var consoleSink = {
|
|
147
|
+
record: (event) => event.type === "lifecycle:error" ? lifecycleErrorLog(event) : event.type === "diagnostic" ? diagnosticLog(event) : import_effect4.Effect.logDebug({ debugEvent: event })
|
|
148
|
+
};
|
|
149
|
+
var consoleLayer = import_effect4.Layer.locallyScoped(currentDebugSinks, [consoleSink]);
|
|
150
|
+
var isBrowser = typeof window !== "undefined" && typeof document !== "undefined";
|
|
151
|
+
var renderBrowserConsoleEvent = (event) => {
|
|
152
|
+
if (typeof event.type === "string" && event.type.startsWith("trace:")) {
|
|
153
|
+
const moduleId = event.moduleId ?? "unknown";
|
|
154
|
+
const type = event.type;
|
|
155
|
+
return import_effect4.Effect.sync(() => {
|
|
156
|
+
console.groupCollapsed(
|
|
157
|
+
"%c[Logix]%c trace %c" + moduleId + "%c " + String(type),
|
|
158
|
+
"color:#6b7280;font-weight:bold",
|
|
159
|
+
// tag
|
|
160
|
+
"color:#3b82f6",
|
|
161
|
+
// label
|
|
162
|
+
"color:#9ca3af",
|
|
163
|
+
// module id
|
|
164
|
+
"color:#6b7280"
|
|
165
|
+
// type
|
|
166
|
+
);
|
|
167
|
+
console.log(event);
|
|
168
|
+
console.groupEnd();
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
if (event.type === "lifecycle:error") {
|
|
172
|
+
const moduleId = event.moduleId ?? "unknown";
|
|
173
|
+
const causePretty = (() => {
|
|
174
|
+
try {
|
|
175
|
+
return import_effect4.Cause.pretty(event.cause, { renderErrorCause: true });
|
|
176
|
+
} catch {
|
|
177
|
+
try {
|
|
178
|
+
return JSON.stringify(event.cause, null, 2);
|
|
179
|
+
} catch {
|
|
180
|
+
return String(event.cause);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
})();
|
|
184
|
+
const key = `${moduleId}|${causePretty}`;
|
|
185
|
+
if (browserLifecycleSeen.has(key)) {
|
|
186
|
+
return import_effect4.Effect.void;
|
|
187
|
+
}
|
|
188
|
+
browserLifecycleSeen.add(key);
|
|
189
|
+
return import_effect4.Effect.sync(() => {
|
|
190
|
+
console.groupCollapsed(
|
|
191
|
+
"%c[Logix]%c lifecycle:error %c" + moduleId,
|
|
192
|
+
"color:#ef4444;font-weight:bold",
|
|
193
|
+
// tag
|
|
194
|
+
"color:#ef4444",
|
|
195
|
+
// label
|
|
196
|
+
"color:#9ca3af"
|
|
197
|
+
// module id
|
|
198
|
+
);
|
|
199
|
+
console.error(causePretty);
|
|
200
|
+
console.groupEnd();
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
if (event.type === "diagnostic") {
|
|
204
|
+
const moduleId = event.moduleId ?? "unknown";
|
|
205
|
+
const detail = `code=${event.code} message=${event.message}${event.actionTag ? ` action=${event.actionTag}` : ""}${event.hint ? `
|
|
206
|
+
hint: ${event.hint}` : ""}`;
|
|
207
|
+
const color = event.severity === "warning" ? "color:#d97706" : event.severity === "info" ? "color:#3b82f6" : "color:#ef4444";
|
|
208
|
+
const label = event.severity === "warning" ? "diagnostic(warning)" : event.severity === "info" ? "diagnostic(info)" : "diagnostic(error)";
|
|
209
|
+
const key = `${moduleId}|${event.code}|${event.message}`;
|
|
210
|
+
if (browserDiagnosticSeen.has(key)) {
|
|
211
|
+
return import_effect4.Effect.void;
|
|
212
|
+
}
|
|
213
|
+
browserDiagnosticSeen.add(key);
|
|
214
|
+
return import_effect4.Effect.sync(() => {
|
|
215
|
+
console.groupCollapsed(
|
|
216
|
+
"%c[Logix]%c " + label + "%c module=" + moduleId,
|
|
217
|
+
"color:#6b7280;font-weight:bold",
|
|
218
|
+
color,
|
|
219
|
+
"color:#9ca3af"
|
|
220
|
+
);
|
|
221
|
+
if (event.severity === "warning") {
|
|
222
|
+
console.warn(detail);
|
|
223
|
+
} else if (event.severity === "info") {
|
|
224
|
+
console.info(detail);
|
|
225
|
+
} else {
|
|
226
|
+
console.error(detail);
|
|
227
|
+
}
|
|
228
|
+
console.groupEnd();
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
return import_effect4.Effect.void;
|
|
232
|
+
};
|
|
233
|
+
var browserConsoleSink = {
|
|
234
|
+
record: (event) => {
|
|
235
|
+
if (!isBrowser) {
|
|
236
|
+
return event.type === "lifecycle:error" ? lifecycleErrorLog(event) : event.type === "diagnostic" ? diagnosticLog(event) : import_effect4.Effect.logDebug({ debugEvent: event });
|
|
237
|
+
}
|
|
238
|
+
return renderBrowserConsoleEvent(event);
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
var browserConsoleLayer = import_effect4.Layer.locallyScoped(currentDebugSinks, [browserConsoleSink]);
|
|
242
|
+
var browserDiagnosticConsoleSink = {
|
|
243
|
+
record: (event) => {
|
|
244
|
+
if (!isBrowser) {
|
|
245
|
+
return event.type === "lifecycle:error" ? lifecycleErrorLog(event) : event.type === "diagnostic" && event.severity !== "info" ? diagnosticLog(event) : import_effect4.Effect.void;
|
|
246
|
+
}
|
|
247
|
+
return event.type === "lifecycle:error" || event.type === "diagnostic" && event.severity !== "info" ? renderBrowserConsoleEvent(event) : import_effect4.Effect.void;
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
var browserDiagnosticConsoleLayer = import_effect4.Layer.locallyScoped(currentDebugSinks, [browserDiagnosticConsoleSink]);
|
|
251
|
+
var browserPrettyLoggerLayer = import_effect4.Logger.replace(
|
|
252
|
+
import_effect4.Logger.defaultLogger,
|
|
253
|
+
import_effect4.Logger.prettyLogger({ mode: "browser", colors: true })
|
|
254
|
+
);
|
|
255
|
+
var record = (event) => import_effect4.Effect.gen(function* () {
|
|
256
|
+
const sinks = yield* import_effect4.FiberRef.get(currentDebugSinks);
|
|
257
|
+
if (isErrorOnlyOnlySinks(sinks)) {
|
|
258
|
+
if (event.type === "lifecycle:error") {
|
|
259
|
+
yield* lifecycleErrorLog(event);
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
if (event.type === "diagnostic") {
|
|
263
|
+
if (event.severity !== "info") {
|
|
264
|
+
yield* diagnosticLog(event);
|
|
265
|
+
} else {
|
|
266
|
+
yield* import_effect4.Effect.void;
|
|
267
|
+
}
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
yield* import_effect4.Effect.void;
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
if (sinks.length === 0) {
|
|
274
|
+
if (isBrowser) {
|
|
275
|
+
if (event.type === "lifecycle:error" || event.type === "diagnostic") {
|
|
276
|
+
yield* renderBrowserConsoleEvent(event);
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
yield* import_effect4.Effect.void;
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
if (event.type === "lifecycle:error") {
|
|
283
|
+
yield* lifecycleErrorLog(event);
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
if (event.type === "diagnostic") {
|
|
287
|
+
yield* diagnosticLog(event);
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
yield* import_effect4.Effect.void;
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
const enriched = event;
|
|
294
|
+
const diagnosticsLevel = yield* import_effect4.FiberRef.get(currentDiagnosticsLevel);
|
|
295
|
+
let now;
|
|
296
|
+
const getNow = () => {
|
|
297
|
+
if (now === void 0) now = Date.now();
|
|
298
|
+
return now;
|
|
299
|
+
};
|
|
300
|
+
if (enriched.timestamp === void 0 && (diagnosticsLevel !== "off" || enriched.type === "lifecycle:error" || enriched.type === "diagnostic")) {
|
|
301
|
+
;
|
|
302
|
+
enriched.timestamp = getNow();
|
|
303
|
+
}
|
|
304
|
+
if (diagnosticsLevel !== "off" && enriched.runtimeLabel === void 0) {
|
|
305
|
+
const runtimeLabel = yield* import_effect4.FiberRef.get(currentRuntimeLabel);
|
|
306
|
+
if (runtimeLabel) {
|
|
307
|
+
;
|
|
308
|
+
enriched.runtimeLabel = runtimeLabel;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
if (enriched.type === "diagnostic" && enriched.txnId === void 0) {
|
|
312
|
+
const txnId = yield* import_effect4.FiberRef.get(currentTxnId);
|
|
313
|
+
if (txnId) {
|
|
314
|
+
;
|
|
315
|
+
enriched.txnId = txnId;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
if (diagnosticsLevel !== "off" && enriched.type === "trace:effectop" && enriched.linkId === void 0) {
|
|
319
|
+
const linkId = yield* import_effect4.FiberRef.get(currentLinkId);
|
|
320
|
+
if (linkId) {
|
|
321
|
+
;
|
|
322
|
+
enriched.linkId = linkId;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
if (sinks.length === 1) {
|
|
326
|
+
yield* sinks[0].record(enriched);
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
yield* import_effect4.Effect.forEach(sinks, (sink) => sink.record(enriched), { discard: true });
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
// src/internal/runtime/core/env.ts
|
|
333
|
+
var import_effect5 = require("effect");
|
|
334
|
+
var getNodeEnv = () => {
|
|
335
|
+
try {
|
|
336
|
+
const env = globalThis?.process?.env;
|
|
337
|
+
return typeof env?.NODE_ENV === "string" ? env.NODE_ENV : void 0;
|
|
338
|
+
} catch {
|
|
339
|
+
return void 0;
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
var isDevEnv = () => getNodeEnv() !== "production";
|
|
343
|
+
var StateTransactionConfigTagImpl = class extends import_effect5.Context.Tag("@logixjs/core/StateTransactionRuntimeConfig")() {
|
|
344
|
+
};
|
|
345
|
+
var ReadQueryStrictGateConfigTagImpl = class extends import_effect5.Context.Tag("@logixjs/core/ReadQueryStrictGateRuntimeConfig")() {
|
|
346
|
+
};
|
|
347
|
+
var ReplayModeConfigTagImpl = class extends import_effect5.Context.Tag("@logixjs/core/ReplayModeConfig")() {
|
|
348
|
+
};
|
|
349
|
+
var StateTransactionOverridesTagImpl = class extends import_effect5.Context.Tag("@logixjs/core/StateTransactionOverrides")() {
|
|
350
|
+
};
|
|
351
|
+
var ConcurrencyPolicyTagImpl = class extends import_effect5.Context.Tag("@logixjs/core/ConcurrencyPolicy")() {
|
|
352
|
+
};
|
|
353
|
+
var ConcurrencyPolicyOverridesTagImpl = class extends import_effect5.Context.Tag("@logixjs/core/ConcurrencyPolicyOverrides")() {
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
// src/internal/runtime/core/TaskRunner.ts
|
|
357
|
+
var inSyncTransactionFiber = import_effect6.FiberRef.unsafeMake(false);
|
|
358
|
+
var forceSourceRefresh = import_effect6.FiberRef.unsafeMake(false);
|
|
359
|
+
var resolve = (eff, payload) => typeof eff === "function" ? eff(payload) : eff;
|
|
360
|
+
var defaultOrigins = (triggerName) => ({
|
|
361
|
+
pending: {
|
|
362
|
+
kind: "task:pending",
|
|
363
|
+
name: triggerName
|
|
364
|
+
},
|
|
365
|
+
success: {
|
|
366
|
+
kind: "service-callback",
|
|
367
|
+
name: "task:success"
|
|
368
|
+
},
|
|
369
|
+
failure: {
|
|
370
|
+
kind: "service-callback",
|
|
371
|
+
name: "task:failure"
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
var shouldNoopInSyncTransactionFiber = (options) => import_effect6.Effect.gen(function* () {
|
|
375
|
+
const inTxn = yield* import_effect6.FiberRef.get(inSyncTransactionFiber);
|
|
376
|
+
if (!inTxn) {
|
|
377
|
+
return false;
|
|
378
|
+
}
|
|
379
|
+
if (isDevEnv()) {
|
|
380
|
+
yield* record({
|
|
381
|
+
type: "diagnostic",
|
|
382
|
+
moduleId: options.moduleId,
|
|
383
|
+
instanceId: options.instanceId,
|
|
384
|
+
code: options.code,
|
|
385
|
+
severity: options.severity,
|
|
386
|
+
message: options.message,
|
|
387
|
+
hint: options.hint,
|
|
388
|
+
actionTag: options.actionTag,
|
|
389
|
+
kind: options.kind
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
return true;
|
|
393
|
+
});
|
|
394
|
+
var resolveConcurrencyLimit = (runtime) => runtime.resolveConcurrencyPolicy ? runtime.resolveConcurrencyPolicy().pipe(import_effect6.Effect.map((p) => p.concurrencyLimit)) : import_effect6.Effect.succeed(16);
|
|
395
|
+
var runTaskLifecycle = (payload, runtime, config, getCanWriteBack) => import_effect6.Effect.gen(function* () {
|
|
396
|
+
const noop = yield* shouldNoopInSyncTransactionFiber({
|
|
397
|
+
moduleId: runtime.moduleId,
|
|
398
|
+
instanceId: runtime.instanceId,
|
|
399
|
+
code: "logic::invalid_usage",
|
|
400
|
+
severity: "error",
|
|
401
|
+
message: "run*Task is not allowed inside a synchronous StateTransaction body (it may deadlock the txnQueue).",
|
|
402
|
+
hint: "Call run*Task from the run section of a watcher (e.g. $.onAction/$.onState/$.on); do not call it directly inside a reducer / trait.run / synchronous transaction body. For long-lived flows, use a multi-entry pattern (pending \u2192 IO \u2192 writeback).",
|
|
403
|
+
kind: "run_task_in_transaction"
|
|
404
|
+
});
|
|
405
|
+
if (noop) {
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
const defaults = defaultOrigins(config.triggerName);
|
|
409
|
+
const origins = {
|
|
410
|
+
pending: config.origin?.pending ?? defaults.pending,
|
|
411
|
+
success: config.origin?.success ?? defaults.success,
|
|
412
|
+
failure: config.origin?.failure ?? defaults.failure
|
|
413
|
+
};
|
|
414
|
+
const pending = config.pending;
|
|
415
|
+
if (pending) {
|
|
416
|
+
yield* import_effect6.Effect.uninterruptible(
|
|
417
|
+
runtime.runWithStateTransaction(origins.pending, () => import_effect6.Effect.asVoid(resolve(pending, payload)))
|
|
418
|
+
);
|
|
419
|
+
}
|
|
420
|
+
const io = resolve(config.effect, payload);
|
|
421
|
+
const exit = yield* import_effect6.Effect.exit(io);
|
|
422
|
+
if (getCanWriteBack) {
|
|
423
|
+
const ok = yield* getCanWriteBack;
|
|
424
|
+
if (!ok) {
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
if (exit._tag === "Success") {
|
|
429
|
+
const success = config.success;
|
|
430
|
+
if (success) {
|
|
431
|
+
yield* runtime.runWithStateTransaction(origins.success, () => import_effect6.Effect.asVoid(success(exit.value, payload)));
|
|
432
|
+
}
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
const cause = exit.cause;
|
|
436
|
+
if (import_effect6.Cause.isInterrupted(cause)) {
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
const failure = config.failure;
|
|
440
|
+
if (failure) {
|
|
441
|
+
yield* runtime.runWithStateTransaction(origins.failure, () => import_effect6.Effect.asVoid(failure(cause, payload)));
|
|
442
|
+
}
|
|
443
|
+
}).pipe(
|
|
444
|
+
// Watchers must not crash as a whole due to a single task failure: swallow errors, but keep them diagnosable.
|
|
445
|
+
import_effect6.Effect.catchAllCause(
|
|
446
|
+
(cause) => record({
|
|
447
|
+
type: "diagnostic",
|
|
448
|
+
moduleId: runtime.moduleId,
|
|
449
|
+
instanceId: runtime.instanceId,
|
|
450
|
+
code: "task_runner::unhandled_failure",
|
|
451
|
+
severity: "error",
|
|
452
|
+
message: "TaskRunner encountered an unhandled failure (pending/IO/writeback).",
|
|
453
|
+
hint: "Add a failure writeback for this task or handle errors explicitly upstream; avoid fire-and-forget swallowing errors.",
|
|
454
|
+
actionTag: config.triggerName,
|
|
455
|
+
kind: "task_runner_unhandled_failure",
|
|
456
|
+
trigger: {
|
|
457
|
+
kind: "task",
|
|
458
|
+
name: config.triggerName
|
|
459
|
+
}
|
|
460
|
+
}).pipe(import_effect6.Effect.zipRight(import_effect6.Effect.logError("TaskRunner error", cause)))
|
|
461
|
+
)
|
|
462
|
+
);
|
|
463
|
+
var makeTaskRunner = (stream, mode, runtime, config) => {
|
|
464
|
+
if (mode === "latest") {
|
|
465
|
+
return import_effect6.Effect.gen(function* () {
|
|
466
|
+
const taskIdRef = yield* import_effect6.Ref.make(0);
|
|
467
|
+
const currentFiberRef = yield* import_effect6.Ref.make(void 0);
|
|
468
|
+
const start = (payload) => import_effect6.Effect.gen(function* () {
|
|
469
|
+
const taskId = yield* import_effect6.Ref.updateAndGet(taskIdRef, (n) => n + 1);
|
|
470
|
+
const prev = yield* import_effect6.Ref.get(currentFiberRef);
|
|
471
|
+
if (prev) {
|
|
472
|
+
yield* import_effect6.Fiber.interruptFork(prev);
|
|
473
|
+
}
|
|
474
|
+
const canWriteBack = import_effect6.Ref.get(taskIdRef).pipe(import_effect6.Effect.map((current) => current === taskId));
|
|
475
|
+
const fiber = yield* import_effect6.Effect.fork(
|
|
476
|
+
runTaskLifecycle(payload, runtime, config, canWriteBack)
|
|
477
|
+
);
|
|
478
|
+
yield* import_effect6.Ref.set(currentFiberRef, fiber);
|
|
479
|
+
});
|
|
480
|
+
return yield* import_effect6.Stream.runForEach(stream, start);
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
if (mode === "exhaust") {
|
|
484
|
+
return import_effect6.Effect.gen(function* () {
|
|
485
|
+
const concurrency = yield* resolveConcurrencyLimit(runtime);
|
|
486
|
+
const busyRef = yield* import_effect6.Ref.make(false);
|
|
487
|
+
const mapper = (payload) => import_effect6.Effect.gen(function* () {
|
|
488
|
+
const acquired = yield* import_effect6.Ref.modify(
|
|
489
|
+
busyRef,
|
|
490
|
+
(busy) => busy ? [false, busy] : [true, true]
|
|
491
|
+
);
|
|
492
|
+
if (!acquired) {
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
try {
|
|
496
|
+
yield* runTaskLifecycle(payload, runtime, config);
|
|
497
|
+
} finally {
|
|
498
|
+
yield* import_effect6.Ref.set(busyRef, false);
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
return yield* import_effect6.Stream.runDrain(stream.pipe(import_effect6.Stream.mapEffect(mapper, { concurrency })));
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
if (mode === "parallel") {
|
|
505
|
+
return import_effect6.Effect.gen(function* () {
|
|
506
|
+
const concurrency = yield* resolveConcurrencyLimit(runtime);
|
|
507
|
+
return yield* import_effect6.Stream.runDrain(
|
|
508
|
+
stream.pipe(
|
|
509
|
+
import_effect6.Stream.mapEffect((payload) => runTaskLifecycle(payload, runtime, config), {
|
|
510
|
+
concurrency
|
|
511
|
+
})
|
|
512
|
+
)
|
|
513
|
+
);
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
return import_effect6.Stream.runForEach(
|
|
517
|
+
stream,
|
|
518
|
+
(payload) => runTaskLifecycle(payload, runtime, config)
|
|
519
|
+
);
|
|
520
|
+
};
|
|
521
|
+
|
|
522
|
+
// src/internal/runtime/core/mutativePatches.ts
|
|
523
|
+
var import_mutative = require("mutative");
|
|
524
|
+
|
|
525
|
+
// src/internal/field-path.ts
|
|
526
|
+
var isFieldPathSegment = (seg) => {
|
|
527
|
+
if (!seg) return false;
|
|
528
|
+
if (seg === "*") return false;
|
|
529
|
+
if (/^\d+$/.test(seg)) return false;
|
|
530
|
+
if (seg.includes("[") || seg.includes("]")) return false;
|
|
531
|
+
return true;
|
|
532
|
+
};
|
|
533
|
+
|
|
534
|
+
// src/internal/runtime/core/mutativePatches.ts
|
|
535
|
+
var toPatchFieldPath = (path) => {
|
|
536
|
+
if (typeof path === "string") {
|
|
537
|
+
const trimmed = path.trim();
|
|
538
|
+
return trimmed.length > 0 ? "*" : void 0;
|
|
539
|
+
}
|
|
540
|
+
if (!Array.isArray(path)) return void 0;
|
|
541
|
+
const parts = [];
|
|
542
|
+
for (const seg of path) {
|
|
543
|
+
if (typeof seg === "string") {
|
|
544
|
+
if (isFieldPathSegment(seg)) parts.push(seg);
|
|
545
|
+
continue;
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
if (parts.length === 0) return "*";
|
|
549
|
+
return parts;
|
|
550
|
+
};
|
|
551
|
+
var mutateWithPatchPaths = (base, mutator) => {
|
|
552
|
+
const out = (0, import_mutative.create)(base, mutator, {
|
|
553
|
+
enablePatches: {
|
|
554
|
+
pathAsArray: true,
|
|
555
|
+
arrayLengthAssignment: false
|
|
556
|
+
}
|
|
557
|
+
});
|
|
558
|
+
if (!Array.isArray(out)) {
|
|
559
|
+
return { nextState: out, patchPaths: [] };
|
|
560
|
+
}
|
|
561
|
+
const nextState = out[0];
|
|
562
|
+
const patches = out[1] ?? [];
|
|
563
|
+
const dedup = /* @__PURE__ */ new Map();
|
|
564
|
+
for (const patch of patches) {
|
|
565
|
+
const p = toPatchFieldPath(patch?.path);
|
|
566
|
+
if (!p) continue;
|
|
567
|
+
const key = p === "*" ? "*" : JSON.stringify(p);
|
|
568
|
+
if (!dedup.has(key)) dedup.set(key, p);
|
|
569
|
+
}
|
|
570
|
+
return {
|
|
571
|
+
nextState,
|
|
572
|
+
patchPaths: Array.from(dedup.values())
|
|
573
|
+
};
|
|
574
|
+
};
|
|
575
|
+
|
|
576
|
+
// src/internal/runtime/core/FlowRuntime.ts
|
|
577
|
+
var import_effect9 = require("effect");
|
|
578
|
+
|
|
579
|
+
// src/internal/effect-op.ts
|
|
580
|
+
var import_effect8 = require("effect");
|
|
581
|
+
|
|
582
|
+
// src/internal/observability/runSession.ts
|
|
583
|
+
var import_effect7 = require("effect");
|
|
584
|
+
var RunSessionTagImpl = class extends import_effect7.Context.Tag("@logixjs/core/RunSession")() {
|
|
585
|
+
};
|
|
586
|
+
var RunSessionTag = RunSessionTagImpl;
|
|
587
|
+
|
|
588
|
+
// src/internal/effect-op.ts
|
|
589
|
+
var nextGlobalOpSeq = 0;
|
|
590
|
+
var nextOpSeq = () => {
|
|
591
|
+
nextGlobalOpSeq += 1;
|
|
592
|
+
return nextGlobalOpSeq;
|
|
593
|
+
};
|
|
594
|
+
var makeId = (instanceId, opSeq) => instanceId ? `${instanceId}::o${opSeq}` : `o${opSeq}`;
|
|
595
|
+
var make = (params) => ({
|
|
596
|
+
...params.id ? { id: params.id, meta: params.meta } : (() => {
|
|
597
|
+
const meta = params.meta ?? {};
|
|
598
|
+
const instanceId = meta.instanceId;
|
|
599
|
+
const opSeq = typeof meta.opSeq === "number" && Number.isFinite(meta.opSeq) ? Math.floor(meta.opSeq) : nextOpSeq();
|
|
600
|
+
return {
|
|
601
|
+
id: makeId(instanceId, opSeq),
|
|
602
|
+
meta: meta.opSeq === opSeq ? meta : { ...meta, opSeq }
|
|
603
|
+
};
|
|
604
|
+
})(),
|
|
605
|
+
kind: params.kind,
|
|
606
|
+
name: params.name,
|
|
607
|
+
payload: params.payload,
|
|
608
|
+
effect: params.effect
|
|
609
|
+
});
|
|
610
|
+
var run = (op, stack) => runWithMiddleware(op, stack);
|
|
611
|
+
|
|
612
|
+
// src/internal/runtime/core/ReadQuery.ts
|
|
613
|
+
function isReadQuery(input) {
|
|
614
|
+
if (!input || typeof input !== "object" && typeof input !== "function") return false;
|
|
615
|
+
const maybe = input;
|
|
616
|
+
return typeof maybe.selectorId === "string" && typeof maybe.select === "function" && Array.isArray(maybe.reads);
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
// src/internal/runtime/core/FlowRuntime.ts
|
|
620
|
+
var getMiddlewareStack = () => import_effect9.Effect.serviceOption(EffectOpMiddlewareTag).pipe(
|
|
621
|
+
import_effect9.Effect.map((maybe) => import_effect9.Option.isSome(maybe) ? maybe.value.stack : [])
|
|
622
|
+
);
|
|
623
|
+
var getRuntimeScope = (runtime) => {
|
|
624
|
+
if (!runtime) return {};
|
|
625
|
+
if (typeof runtime !== "object" && typeof runtime !== "function") return {};
|
|
626
|
+
const scope = runtime;
|
|
627
|
+
return {
|
|
628
|
+
moduleId: typeof scope.moduleId === "string" ? scope.moduleId : void 0,
|
|
629
|
+
instanceId: typeof scope.instanceId === "string" ? scope.instanceId : void 0
|
|
630
|
+
};
|
|
631
|
+
};
|
|
632
|
+
var resolveEffect = (eff, payload) => typeof eff === "function" ? eff(payload) : eff;
|
|
633
|
+
var make2 = (runtime, runtimeInternals) => {
|
|
634
|
+
const scope = getRuntimeScope(runtime);
|
|
635
|
+
const resolveConcurrencyLimit2 = () => runtimeInternals ? runtimeInternals.concurrency.resolveConcurrencyPolicy().pipe(import_effect9.Effect.map((p) => p.concurrencyLimit)) : import_effect9.Effect.succeed(16);
|
|
636
|
+
const runAsFlowOp = (name, payload, eff, options) => import_effect9.Effect.gen(function* () {
|
|
637
|
+
const stack = yield* getMiddlewareStack();
|
|
638
|
+
const meta = {
|
|
639
|
+
...options?.meta ?? {},
|
|
640
|
+
policy: options?.policy,
|
|
641
|
+
tags: options?.tags,
|
|
642
|
+
trace: options?.trace,
|
|
643
|
+
moduleId: scope.moduleId,
|
|
644
|
+
instanceId: scope.instanceId
|
|
645
|
+
};
|
|
646
|
+
if (!(typeof meta.opSeq === "number" && Number.isFinite(meta.opSeq))) {
|
|
647
|
+
const sessionOpt = yield* import_effect9.Effect.serviceOption(RunSessionTag);
|
|
648
|
+
if (import_effect9.Option.isSome(sessionOpt)) {
|
|
649
|
+
const key = meta.instanceId ?? "global";
|
|
650
|
+
meta.opSeq = sessionOpt.value.local.nextSeq("opSeq", key);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
const op = make({
|
|
654
|
+
kind: "flow",
|
|
655
|
+
name,
|
|
656
|
+
payload,
|
|
657
|
+
effect: eff,
|
|
658
|
+
meta
|
|
659
|
+
});
|
|
660
|
+
return yield* run(op, stack);
|
|
661
|
+
});
|
|
662
|
+
const runEffect = (eff) => (payload) => resolveEffect(eff, payload);
|
|
663
|
+
const runStreamSequential = (eff, options) => (stream) => import_effect9.Stream.runForEach(
|
|
664
|
+
stream,
|
|
665
|
+
(payload) => runAsFlowOp("flow.run", payload, runEffect(eff)(payload), options)
|
|
666
|
+
);
|
|
667
|
+
const runStreamParallel = (eff, options) => (stream) => import_effect9.Effect.gen(function* () {
|
|
668
|
+
const concurrency = yield* resolveConcurrencyLimit2();
|
|
669
|
+
return yield* import_effect9.Stream.runDrain(
|
|
670
|
+
stream.pipe(
|
|
671
|
+
import_effect9.Stream.mapEffect(
|
|
672
|
+
(payload) => runAsFlowOp("flow.runParallel", payload, runEffect(eff)(payload), options),
|
|
673
|
+
{ concurrency }
|
|
674
|
+
)
|
|
675
|
+
)
|
|
676
|
+
).pipe(
|
|
677
|
+
import_effect9.Effect.catchAllCause(
|
|
678
|
+
(cause) => record({
|
|
679
|
+
type: "diagnostic",
|
|
680
|
+
moduleId: scope.moduleId,
|
|
681
|
+
instanceId: scope.instanceId,
|
|
682
|
+
code: "flow::unhandled_failure",
|
|
683
|
+
severity: "error",
|
|
684
|
+
message: "Flow watcher (runParallel) failed with an unhandled error.",
|
|
685
|
+
hint: "Handle errors explicitly inside the watcher (catch/catchAll) or write back via TaskRunner failure; avoid silent failures.",
|
|
686
|
+
kind: "flow_unhandled_failure",
|
|
687
|
+
trigger: {
|
|
688
|
+
kind: "flow",
|
|
689
|
+
name: "runParallel"
|
|
690
|
+
}
|
|
691
|
+
}).pipe(import_effect9.Effect.zipRight(import_effect9.Effect.failCause(cause)))
|
|
692
|
+
)
|
|
693
|
+
);
|
|
694
|
+
});
|
|
695
|
+
return {
|
|
696
|
+
fromAction: (predicate) => runtime.actions$.pipe(import_effect9.Stream.filter(predicate)),
|
|
697
|
+
fromState: (selectorOrQuery) => runtime.changes(isReadQuery(selectorOrQuery) ? selectorOrQuery.select : selectorOrQuery),
|
|
698
|
+
debounce: (ms) => (stream) => import_effect9.Stream.debounce(stream, ms),
|
|
699
|
+
throttle: (ms) => (stream) => import_effect9.Stream.throttle(stream, {
|
|
700
|
+
cost: () => 1,
|
|
701
|
+
units: 1,
|
|
702
|
+
duration: ms,
|
|
703
|
+
strategy: "enforce"
|
|
704
|
+
}),
|
|
705
|
+
filter: (predicate) => (stream) => import_effect9.Stream.filter(stream, predicate),
|
|
706
|
+
run: (eff, options) => (stream) => runStreamSequential(eff, options)(stream),
|
|
707
|
+
runParallel: (eff, options) => (stream) => runStreamParallel(eff, options)(stream),
|
|
708
|
+
runLatest: (eff, options) => (stream) => import_effect9.Stream.runDrain(
|
|
709
|
+
import_effect9.Stream.map(
|
|
710
|
+
stream,
|
|
711
|
+
(payload) => runAsFlowOp(
|
|
712
|
+
"flow.runLatest",
|
|
713
|
+
payload,
|
|
714
|
+
runEffect(eff)(payload),
|
|
715
|
+
options
|
|
716
|
+
)
|
|
717
|
+
).pipe(
|
|
718
|
+
import_effect9.Stream.flatMap((effect) => import_effect9.Stream.fromEffect(effect), {
|
|
719
|
+
switch: true
|
|
720
|
+
})
|
|
721
|
+
)
|
|
722
|
+
),
|
|
723
|
+
runExhaust: (eff, options) => (stream) => import_effect9.Effect.gen(function* () {
|
|
724
|
+
const concurrency = yield* resolveConcurrencyLimit2();
|
|
725
|
+
const busyRef = yield* import_effect9.Ref.make(false);
|
|
726
|
+
const mapper = (payload) => import_effect9.Effect.gen(function* () {
|
|
727
|
+
const acquired = yield* import_effect9.Ref.modify(
|
|
728
|
+
busyRef,
|
|
729
|
+
(busy) => busy ? [false, busy] : [true, true]
|
|
730
|
+
);
|
|
731
|
+
if (!acquired) {
|
|
732
|
+
return;
|
|
733
|
+
}
|
|
734
|
+
try {
|
|
735
|
+
yield* runAsFlowOp(
|
|
736
|
+
"flow.runExhaust",
|
|
737
|
+
payload,
|
|
738
|
+
runEffect(eff)(payload),
|
|
739
|
+
options
|
|
740
|
+
);
|
|
741
|
+
} finally {
|
|
742
|
+
yield* import_effect9.Ref.set(busyRef, false);
|
|
743
|
+
}
|
|
744
|
+
});
|
|
745
|
+
return yield* import_effect9.Stream.runDrain(stream.pipe(import_effect9.Stream.mapEffect(mapper, { concurrency })));
|
|
746
|
+
})
|
|
747
|
+
};
|
|
748
|
+
};
|
|
749
|
+
|
|
750
|
+
// src/internal/runtime/core/MatchBuilder.ts
|
|
751
|
+
var import_effect10 = require("effect");
|
|
752
|
+
var makeMatch = (value) => {
|
|
753
|
+
let result;
|
|
754
|
+
const chain = {
|
|
755
|
+
with: (predicate, handler) => {
|
|
756
|
+
if (result) return chain;
|
|
757
|
+
if (predicate(value)) {
|
|
758
|
+
result = handler(value);
|
|
759
|
+
}
|
|
760
|
+
return chain;
|
|
761
|
+
},
|
|
762
|
+
otherwise: (handler) => {
|
|
763
|
+
if (result) return result;
|
|
764
|
+
return handler(value);
|
|
765
|
+
},
|
|
766
|
+
exhaustive: () => {
|
|
767
|
+
if (result) {
|
|
768
|
+
return result;
|
|
769
|
+
}
|
|
770
|
+
return import_effect10.Effect.dieMessage("[FluentMatch] Non-exhaustive match: no pattern matched value");
|
|
771
|
+
}
|
|
772
|
+
};
|
|
773
|
+
return chain;
|
|
774
|
+
};
|
|
775
|
+
var makeMatchTag = (value) => {
|
|
776
|
+
let result;
|
|
777
|
+
const chain = {
|
|
778
|
+
with: (t, handler) => {
|
|
779
|
+
if (result) return chain;
|
|
780
|
+
if (value._tag === t) {
|
|
781
|
+
result = handler(value);
|
|
782
|
+
}
|
|
783
|
+
return chain;
|
|
784
|
+
},
|
|
785
|
+
otherwise: (handler) => {
|
|
786
|
+
if (result) return result;
|
|
787
|
+
return handler(value);
|
|
788
|
+
},
|
|
789
|
+
exhaustive: () => {
|
|
790
|
+
if (result) {
|
|
791
|
+
return result;
|
|
792
|
+
}
|
|
793
|
+
return import_effect10.Effect.dieMessage("[FluentMatchTag] Non-exhaustive match: no tag handler matched value");
|
|
794
|
+
}
|
|
795
|
+
};
|
|
796
|
+
return chain;
|
|
797
|
+
};
|
|
798
|
+
|
|
799
|
+
// src/internal/runtime/core/Platform.ts
|
|
800
|
+
var import_effect11 = require("effect");
|
|
801
|
+
var Tag = import_effect11.Context.GenericTag("@logixjs/Platform");
|
|
802
|
+
|
|
803
|
+
// src/internal/runtime/core/Lifecycle.ts
|
|
804
|
+
var import_effect12 = require("effect");
|
|
805
|
+
var LifecycleContext = import_effect12.Context.GenericTag("@logixjs/LifecycleManager");
|
|
806
|
+
|
|
807
|
+
// src/internal/runtime/core/LogicDiagnostics.ts
|
|
808
|
+
var import_effect13 = require("effect");
|
|
809
|
+
var LogicPhaseServiceTag = import_effect13.Context.GenericTag("@logixjs/LogicPhaseService");
|
|
810
|
+
var LogicUnitServiceTag = class extends import_effect13.Context.Tag("@logixjs/LogicUnitService")() {
|
|
811
|
+
};
|
|
812
|
+
var makeLogicPhaseError = (kind, api, phase, moduleId) => Object.assign(new Error(`[LogicPhaseError] ${api} is not allowed in ${phase} phase (kind=${kind}).`), {
|
|
813
|
+
_tag: "LogicPhaseError",
|
|
814
|
+
kind,
|
|
815
|
+
api,
|
|
816
|
+
phase,
|
|
817
|
+
moduleId
|
|
818
|
+
});
|
|
819
|
+
|
|
820
|
+
// src/internal/root.ts
|
|
821
|
+
var import_effect15 = require("effect");
|
|
822
|
+
|
|
823
|
+
// src/internal/runtime/core/RootContext.ts
|
|
824
|
+
var import_effect14 = require("effect");
|
|
825
|
+
var RootContextTagImpl = class extends import_effect14.Context.Tag("@logixjs/core/RootContext")() {
|
|
826
|
+
};
|
|
827
|
+
var RootContextTag = RootContextTagImpl;
|
|
828
|
+
|
|
829
|
+
// src/internal/root.ts
|
|
830
|
+
var tagIdOf = (tag) => typeof tag?.id === "string" ? String(tag.id) : typeof tag?.key === "string" ? String(tag.key) : "<unknown tag>";
|
|
831
|
+
var makeMissingRootProviderError = (tag, entrypoint, extra) => {
|
|
832
|
+
const dev = isDevEnv();
|
|
833
|
+
const tokenId = tagIdOf(tag);
|
|
834
|
+
const fix = dev ? [
|
|
835
|
+
"- Provide it when creating the runtime tree (Logix.Runtime.make(...,{ layer }) / ManagedRuntime.make(Layer.mergeAll(...))).",
|
|
836
|
+
"- If you're in React and want the current runtime environment singleton, use useModule(ModuleTag).",
|
|
837
|
+
"- Do not rely on nested RuntimeProvider.layer to mock Root.resolve."
|
|
838
|
+
] : [];
|
|
839
|
+
const message = dev ? [
|
|
840
|
+
"[MissingRootProviderError] Cannot resolve Tag from root provider.",
|
|
841
|
+
extra ? `
|
|
842
|
+
${extra}` : "",
|
|
843
|
+
`tokenId: ${tokenId}`,
|
|
844
|
+
`entrypoint: ${entrypoint}`,
|
|
845
|
+
"mode: global",
|
|
846
|
+
"startScope: root",
|
|
847
|
+
"",
|
|
848
|
+
"fix:",
|
|
849
|
+
...fix
|
|
850
|
+
].filter((s) => s.length > 0).join("\n") : "[MissingRootProviderError] tag not found in root provider";
|
|
851
|
+
const err = new Error(message);
|
|
852
|
+
err.name = "MissingRootProviderError";
|
|
853
|
+
err.tokenId = tokenId;
|
|
854
|
+
err.entrypoint = entrypoint;
|
|
855
|
+
err.mode = "global";
|
|
856
|
+
err.startScope = { kind: "root" };
|
|
857
|
+
err.fix = fix;
|
|
858
|
+
return err;
|
|
859
|
+
};
|
|
860
|
+
var resolve2 = (tag, options) => import_effect15.Effect.gen(function* () {
|
|
861
|
+
const entrypoint = options?.entrypoint ?? "logic.root.resolve";
|
|
862
|
+
const root = yield* RootContextTag;
|
|
863
|
+
const rootContext = root.context ?? (options?.waitForReady ? yield* root.ready : void 0);
|
|
864
|
+
if (!rootContext) {
|
|
865
|
+
return yield* import_effect15.Effect.die(
|
|
866
|
+
makeMissingRootProviderError(tag, entrypoint, "reason: rootContextNotReady")
|
|
867
|
+
);
|
|
868
|
+
}
|
|
869
|
+
try {
|
|
870
|
+
return import_effect15.Context.get(rootContext, tag);
|
|
871
|
+
} catch {
|
|
872
|
+
return yield* import_effect15.Effect.die(makeMissingRootProviderError(tag, entrypoint));
|
|
873
|
+
}
|
|
874
|
+
});
|
|
875
|
+
|
|
876
|
+
// src/internal/runtime/core/runtimeInternalsAccessor.ts
|
|
877
|
+
var RUNTIME_INTERNALS = /* @__PURE__ */ Symbol.for("@logixjs/core/runtimeInternals");
|
|
878
|
+
var BOUND_INTERNALS = /* @__PURE__ */ Symbol.for("@logixjs/core/boundInternals");
|
|
879
|
+
var defineHidden = (target, key, value) => {
|
|
880
|
+
Object.defineProperty(target, key, {
|
|
881
|
+
value,
|
|
882
|
+
enumerable: false,
|
|
883
|
+
configurable: true,
|
|
884
|
+
writable: false
|
|
885
|
+
});
|
|
886
|
+
};
|
|
887
|
+
var setBoundInternals = (bound, internals) => {
|
|
888
|
+
defineHidden(bound, BOUND_INTERNALS, internals);
|
|
889
|
+
};
|
|
890
|
+
var formatScope = (moduleId, instanceId) => {
|
|
891
|
+
const m = typeof moduleId === "string" && moduleId.length > 0 ? moduleId : "unknown";
|
|
892
|
+
const i = typeof instanceId === "string" && instanceId.length > 0 ? instanceId : "unknown";
|
|
893
|
+
return `moduleId=${m}, instanceId=${i}`;
|
|
894
|
+
};
|
|
895
|
+
var getRuntimeInternals = (runtime) => {
|
|
896
|
+
const scope = runtime;
|
|
897
|
+
const internals = runtime[RUNTIME_INTERNALS];
|
|
898
|
+
if (!internals) {
|
|
899
|
+
const msg = isDevEnv() ? [
|
|
900
|
+
"[MissingRuntimeInternals] Runtime internals not installed on ModuleRuntime instance.",
|
|
901
|
+
`scope: ${formatScope(scope.moduleId, scope.instanceId)}`,
|
|
902
|
+
"fix:",
|
|
903
|
+
"- Ensure ModuleRuntime.make calls internalHooks.installInternalHooks (020 foundation).",
|
|
904
|
+
"- If you created a mock runtime for tests, attach internals or avoid calling internal-only APIs."
|
|
905
|
+
].join("\n") : "Runtime internals not installed";
|
|
906
|
+
throw new Error(msg);
|
|
907
|
+
}
|
|
908
|
+
const runtimeInstanceId = scope.instanceId;
|
|
909
|
+
if (typeof runtimeInstanceId === "string" && runtimeInstanceId.length > 0 && runtimeInstanceId !== internals.instanceId) {
|
|
910
|
+
throw new Error(
|
|
911
|
+
isDevEnv() ? [
|
|
912
|
+
"[InconsistentRuntimeInternals] Runtime internals instanceId mismatch.",
|
|
913
|
+
`runtime: ${formatScope(scope.moduleId, runtimeInstanceId)}`,
|
|
914
|
+
`internals: ${formatScope(internals.moduleId, internals.instanceId)}`
|
|
915
|
+
].join("\n") : "Runtime internals mismatch"
|
|
916
|
+
);
|
|
917
|
+
}
|
|
918
|
+
return internals;
|
|
919
|
+
};
|
|
920
|
+
|
|
921
|
+
// src/internal/runtime/core/BoundApiRuntime.ts
|
|
922
|
+
var LogicBuilderFactory = (runtime, runtimeInternals) => {
|
|
923
|
+
const flowApi = make2(runtime, runtimeInternals);
|
|
924
|
+
return (stream, triggerName) => {
|
|
925
|
+
const runWithStateTransaction = (origin, body) => runtimeInternals.txn.runWithStateTransaction(origin, body);
|
|
926
|
+
const taskRunnerRuntime = {
|
|
927
|
+
moduleId: runtime.moduleId,
|
|
928
|
+
instanceId: runtimeInternals.instanceId,
|
|
929
|
+
runWithStateTransaction,
|
|
930
|
+
resolveConcurrencyPolicy: runtimeInternals.concurrency.resolveConcurrencyPolicy
|
|
931
|
+
};
|
|
932
|
+
const builder = {
|
|
933
|
+
debounce: (ms) => LogicBuilderFactory(runtime, runtimeInternals)(flowApi.debounce(ms)(stream), triggerName),
|
|
934
|
+
throttle: (ms) => LogicBuilderFactory(runtime, runtimeInternals)(flowApi.throttle(ms)(stream), triggerName),
|
|
935
|
+
filter: (predicate) => LogicBuilderFactory(runtime, runtimeInternals)(flowApi.filter(predicate)(stream), triggerName),
|
|
936
|
+
map: (f) => LogicBuilderFactory(runtime, runtimeInternals)(stream.pipe(import_effect16.Stream.map(f)), triggerName),
|
|
937
|
+
run(eff, options) {
|
|
938
|
+
return flowApi.run(eff, options)(stream);
|
|
939
|
+
},
|
|
940
|
+
runLatest(eff, options) {
|
|
941
|
+
return flowApi.runLatest(eff, options)(stream);
|
|
942
|
+
},
|
|
943
|
+
runExhaust(eff, options) {
|
|
944
|
+
return flowApi.runExhaust(eff, options)(stream);
|
|
945
|
+
},
|
|
946
|
+
runParallel(eff, options) {
|
|
947
|
+
return flowApi.runParallel(eff, options)(stream);
|
|
948
|
+
},
|
|
949
|
+
runFork: (eff) => import_effect16.Effect.forkScoped(flowApi.run(eff)(stream)).pipe(import_effect16.Effect.asVoid),
|
|
950
|
+
runParallelFork: (eff) => import_effect16.Effect.forkScoped(flowApi.runParallel(eff)(stream)).pipe(import_effect16.Effect.asVoid),
|
|
951
|
+
runTask: (config) => makeTaskRunner(stream, "task", taskRunnerRuntime, {
|
|
952
|
+
...config,
|
|
953
|
+
triggerName: config.triggerName ?? triggerName
|
|
954
|
+
}),
|
|
955
|
+
runParallelTask: (config) => makeTaskRunner(stream, "parallel", taskRunnerRuntime, {
|
|
956
|
+
...config,
|
|
957
|
+
triggerName: config.triggerName ?? triggerName
|
|
958
|
+
}),
|
|
959
|
+
runLatestTask: (config) => makeTaskRunner(stream, "latest", taskRunnerRuntime, {
|
|
960
|
+
...config,
|
|
961
|
+
triggerName: config.triggerName ?? triggerName
|
|
962
|
+
}),
|
|
963
|
+
runExhaustTask: (config) => makeTaskRunner(stream, "exhaust", taskRunnerRuntime, {
|
|
964
|
+
...config,
|
|
965
|
+
triggerName: config.triggerName ?? triggerName
|
|
966
|
+
}),
|
|
967
|
+
toStream: () => stream,
|
|
968
|
+
update: (reducer) => import_effect16.Stream.runForEach(
|
|
969
|
+
stream,
|
|
970
|
+
(payload) => taskRunnerRuntime.runWithStateTransaction(
|
|
971
|
+
{
|
|
972
|
+
kind: "watcher:update",
|
|
973
|
+
name: triggerName
|
|
974
|
+
},
|
|
975
|
+
() => import_effect16.Effect.gen(function* () {
|
|
976
|
+
const prev = yield* runtime.getState;
|
|
977
|
+
const next = reducer(prev, payload);
|
|
978
|
+
if (import_effect16.Effect.isEffect(next)) {
|
|
979
|
+
const exit = yield* import_effect16.Effect.exit(next);
|
|
980
|
+
if (exit._tag === "Failure") {
|
|
981
|
+
yield* import_effect16.Effect.logError("Flow error", exit.cause);
|
|
982
|
+
return;
|
|
983
|
+
}
|
|
984
|
+
yield* runtime.setState(exit.value);
|
|
985
|
+
return;
|
|
986
|
+
}
|
|
987
|
+
yield* runtime.setState(next);
|
|
988
|
+
})
|
|
989
|
+
)
|
|
990
|
+
).pipe(import_effect16.Effect.catchAllCause((cause) => import_effect16.Effect.logError("Flow error", cause))),
|
|
991
|
+
mutate: (reducer) => import_effect16.Stream.runForEach(
|
|
992
|
+
stream,
|
|
993
|
+
(payload) => taskRunnerRuntime.runWithStateTransaction(
|
|
994
|
+
{
|
|
995
|
+
kind: "watcher:mutate",
|
|
996
|
+
name: triggerName
|
|
997
|
+
},
|
|
998
|
+
() => import_effect16.Effect.gen(function* () {
|
|
999
|
+
const prev = yield* runtime.getState;
|
|
1000
|
+
const recordPatch = runtimeInternals.txn.recordStatePatch;
|
|
1001
|
+
const updateDraft = runtimeInternals.txn.updateDraft;
|
|
1002
|
+
const { nextState, patchPaths } = mutateWithPatchPaths(prev, (draft) => {
|
|
1003
|
+
reducer(draft, payload);
|
|
1004
|
+
});
|
|
1005
|
+
for (const path of patchPaths) {
|
|
1006
|
+
recordPatch(path, "unknown");
|
|
1007
|
+
}
|
|
1008
|
+
updateDraft(nextState);
|
|
1009
|
+
})
|
|
1010
|
+
)
|
|
1011
|
+
).pipe(import_effect16.Effect.catchAllCause((cause) => import_effect16.Effect.logError("Flow error", cause)))
|
|
1012
|
+
};
|
|
1013
|
+
const pipe = function() {
|
|
1014
|
+
const fns = arguments;
|
|
1015
|
+
let acc = builder;
|
|
1016
|
+
for (let i = 0; i < fns.length; i++) {
|
|
1017
|
+
acc = fns[i](acc);
|
|
1018
|
+
}
|
|
1019
|
+
return acc;
|
|
1020
|
+
};
|
|
1021
|
+
return Object.assign(builder, { pipe });
|
|
1022
|
+
};
|
|
1023
|
+
};
|
|
1024
|
+
function make3(shape, runtime, options) {
|
|
1025
|
+
const runtimeInternals = getRuntimeInternals(runtime);
|
|
1026
|
+
const getPhase = options?.getPhase ?? (() => "run");
|
|
1027
|
+
const getCurrentPhase = () => {
|
|
1028
|
+
const phaseService = options?.phaseService;
|
|
1029
|
+
const phase = phaseService?.current ?? getPhase();
|
|
1030
|
+
return phase === "setup" ? "setup" : "run";
|
|
1031
|
+
};
|
|
1032
|
+
const guardRunOnly = (kind, api2) => {
|
|
1033
|
+
const phaseService = options?.phaseService;
|
|
1034
|
+
const phase = phaseService?.current ?? getPhase();
|
|
1035
|
+
if (phase === "setup") {
|
|
1036
|
+
throw makeLogicPhaseError(kind, api2, "setup", options?.moduleId);
|
|
1037
|
+
}
|
|
1038
|
+
};
|
|
1039
|
+
const flowApi = make2(runtime, runtimeInternals);
|
|
1040
|
+
const makeIntentBuilder = (runtime_) => LogicBuilderFactory(runtime_, runtimeInternals);
|
|
1041
|
+
const withLifecycle = (available, missing) => import_effect16.Effect.serviceOption(LifecycleContext).pipe(
|
|
1042
|
+
import_effect16.Effect.flatMap(
|
|
1043
|
+
(maybe) => import_effect16.Option.match(maybe, {
|
|
1044
|
+
onSome: available,
|
|
1045
|
+
onNone: missing
|
|
1046
|
+
})
|
|
1047
|
+
)
|
|
1048
|
+
);
|
|
1049
|
+
const withPlatform = (invoke) => import_effect16.Effect.serviceOption(Tag).pipe(
|
|
1050
|
+
import_effect16.Effect.flatMap(
|
|
1051
|
+
(maybe) => import_effect16.Option.match(maybe, {
|
|
1052
|
+
onSome: invoke,
|
|
1053
|
+
onNone: () => import_effect16.Effect.void
|
|
1054
|
+
})
|
|
1055
|
+
)
|
|
1056
|
+
);
|
|
1057
|
+
const emitSetupOnlyViolation = (api2) => record({
|
|
1058
|
+
type: "diagnostic",
|
|
1059
|
+
moduleId: runtime.moduleId,
|
|
1060
|
+
instanceId: runtime.instanceId,
|
|
1061
|
+
code: "logic::invalid_phase",
|
|
1062
|
+
severity: "error",
|
|
1063
|
+
message: `${api2} is setup-only and is not allowed in run phase.`,
|
|
1064
|
+
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.",
|
|
1065
|
+
kind: "lifecycle_in_run"
|
|
1066
|
+
});
|
|
1067
|
+
const createIntentBuilder = (stream, triggerName) => makeIntentBuilder(runtime)(stream, triggerName);
|
|
1068
|
+
const onceInRunSession = (key) => import_effect16.Effect.serviceOption(RunSessionTag).pipe(
|
|
1069
|
+
import_effect16.Effect.map((maybe) => import_effect16.Option.isSome(maybe) ? maybe.value.local.once(key) : true)
|
|
1070
|
+
);
|
|
1071
|
+
let cachedDiagnosticsLevel;
|
|
1072
|
+
const isModuleLike = (value) => Boolean(
|
|
1073
|
+
value && typeof value === "object" && (value._kind === "ModuleDef" || value._kind === "Module") && "tag" in value && import_effect16.Context.isTag(value.tag)
|
|
1074
|
+
);
|
|
1075
|
+
const buildModuleHandle = (tag, rt) => {
|
|
1076
|
+
const actionsProxy = new Proxy(
|
|
1077
|
+
{},
|
|
1078
|
+
{
|
|
1079
|
+
get: (_target, prop) => (payload) => rt.dispatch({
|
|
1080
|
+
_tag: prop,
|
|
1081
|
+
payload
|
|
1082
|
+
})
|
|
1083
|
+
}
|
|
1084
|
+
);
|
|
1085
|
+
const handle = {
|
|
1086
|
+
read: (selector) => import_effect16.Effect.map(rt.getState, selector),
|
|
1087
|
+
changes: rt.changes,
|
|
1088
|
+
dispatch: rt.dispatch,
|
|
1089
|
+
actions$: rt.actions$,
|
|
1090
|
+
actions: actionsProxy
|
|
1091
|
+
};
|
|
1092
|
+
const EXTEND_HANDLE = /* @__PURE__ */ Symbol.for("logix.module.handle.extend");
|
|
1093
|
+
const extend = tag?.[EXTEND_HANDLE];
|
|
1094
|
+
return typeof extend === "function" ? extend(rt, handle) ?? handle : handle;
|
|
1095
|
+
};
|
|
1096
|
+
const emitModuleDescriptorOnce = (module2, rt) => import_effect16.Effect.gen(function* () {
|
|
1097
|
+
if (cachedDiagnosticsLevel === "off") return;
|
|
1098
|
+
const key = `module_descriptor:${String(rt.instanceId ?? "unknown")}`;
|
|
1099
|
+
const shouldEmit = yield* onceInRunSession(key);
|
|
1100
|
+
if (!shouldEmit) return;
|
|
1101
|
+
const actionKeys = Object.keys(module2.tag?.shape?.actionMap ?? {});
|
|
1102
|
+
const internalSymbol = /* @__PURE__ */ Symbol.for("logix.module.internal");
|
|
1103
|
+
const internal = module2[internalSymbol];
|
|
1104
|
+
const logicUnits = (internal?.mounted ?? []).map((u) => ({
|
|
1105
|
+
kind: String(u?.kind ?? "user"),
|
|
1106
|
+
id: String(u?.id ?? ""),
|
|
1107
|
+
derived: u?.derived ? true : void 0,
|
|
1108
|
+
name: typeof u?.name === "string" ? u.name : void 0
|
|
1109
|
+
}));
|
|
1110
|
+
const schemaKeys = module2.schemas && typeof module2.schemas === "object" ? Object.keys(module2.schemas) : void 0;
|
|
1111
|
+
const meta = module2.meta && typeof module2.meta === "object" ? module2.meta : void 0;
|
|
1112
|
+
const source = module2.dev?.source;
|
|
1113
|
+
const traitsSnapshot = runtimeInternals.traits.getModuleTraitsSnapshot();
|
|
1114
|
+
const traits = traitsSnapshot ? {
|
|
1115
|
+
digest: traitsSnapshot.digest,
|
|
1116
|
+
count: traitsSnapshot.traits.length
|
|
1117
|
+
} : void 0;
|
|
1118
|
+
const data = {
|
|
1119
|
+
id: module2.id,
|
|
1120
|
+
moduleId: String(rt.moduleId),
|
|
1121
|
+
instanceId: String(rt.instanceId),
|
|
1122
|
+
actionKeys,
|
|
1123
|
+
logicUnits,
|
|
1124
|
+
schemaKeys,
|
|
1125
|
+
meta,
|
|
1126
|
+
source,
|
|
1127
|
+
traits
|
|
1128
|
+
};
|
|
1129
|
+
yield* record({
|
|
1130
|
+
type: "trace:module:descriptor",
|
|
1131
|
+
moduleId: rt.moduleId,
|
|
1132
|
+
instanceId: rt.instanceId,
|
|
1133
|
+
data
|
|
1134
|
+
});
|
|
1135
|
+
});
|
|
1136
|
+
const resolveModuleRuntime = (tag) => import_effect16.Effect.gen(function* () {
|
|
1137
|
+
const requestedModuleId = typeof tag?.id === "string" ? tag.id : void 0;
|
|
1138
|
+
const fromModuleId = typeof options?.moduleId === "string" ? options.moduleId : runtime.moduleId;
|
|
1139
|
+
if (requestedModuleId && requestedModuleId === runtime.moduleId) {
|
|
1140
|
+
return runtime;
|
|
1141
|
+
}
|
|
1142
|
+
const fromImports = runtimeInternals.imports.get(tag);
|
|
1143
|
+
if (fromImports) {
|
|
1144
|
+
return fromImports;
|
|
1145
|
+
}
|
|
1146
|
+
if (typeof options?.moduleId !== "string") {
|
|
1147
|
+
const fromEnv = yield* import_effect16.Effect.serviceOption(tag);
|
|
1148
|
+
if (import_effect16.Option.isSome(fromEnv)) {
|
|
1149
|
+
return fromEnv.value;
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
const tokenId = requestedModuleId ?? "<unknown module id>";
|
|
1153
|
+
const fix = isDevEnv() ? [
|
|
1154
|
+
"- Provide the child implementation in the same scope (imports).",
|
|
1155
|
+
` Example: ${fromModuleId ?? "ParentModule"}.implement({ imports: [${requestedModuleId ?? "ChildModule"}.impl], ... })`,
|
|
1156
|
+
"- If you intentionally want a root singleton, provide it at app root (Runtime.make(...,{ layer }) / root imports),",
|
|
1157
|
+
" and use Root.resolve(ModuleTag) (instead of $.use) at the callsite."
|
|
1158
|
+
] : [];
|
|
1159
|
+
const err = new Error(
|
|
1160
|
+
isDevEnv() ? [
|
|
1161
|
+
"[MissingModuleRuntimeError] Cannot resolve ModuleRuntime for ModuleTag.",
|
|
1162
|
+
"",
|
|
1163
|
+
`tokenId: ${tokenId}`,
|
|
1164
|
+
"entrypoint: logic.$.use",
|
|
1165
|
+
"mode: strict",
|
|
1166
|
+
`from: ${fromModuleId ?? "<unknown module id>"}`,
|
|
1167
|
+
`startScope: moduleId=${fromModuleId ?? "<unknown>"}, instanceId=${String(runtime.instanceId ?? "<unknown>")}`,
|
|
1168
|
+
"",
|
|
1169
|
+
"fix:",
|
|
1170
|
+
...fix
|
|
1171
|
+
].join("\n") : "[MissingModuleRuntimeError] module runtime not found"
|
|
1172
|
+
);
|
|
1173
|
+
err.tokenId = tokenId;
|
|
1174
|
+
err.entrypoint = "logic.$.use";
|
|
1175
|
+
err.mode = "strict";
|
|
1176
|
+
err.from = fromModuleId;
|
|
1177
|
+
err.startScope = {
|
|
1178
|
+
moduleId: fromModuleId,
|
|
1179
|
+
instanceId: String(runtime.instanceId ?? "<unknown>")
|
|
1180
|
+
};
|
|
1181
|
+
err.fix = fix;
|
|
1182
|
+
err.name = "MissingModuleRuntimeError";
|
|
1183
|
+
return yield* import_effect16.Effect.die(err);
|
|
1184
|
+
});
|
|
1185
|
+
const stateApi = {
|
|
1186
|
+
read: runtime.getState,
|
|
1187
|
+
update: (f) => import_effect16.Effect.gen(function* () {
|
|
1188
|
+
const inTxn = yield* import_effect16.FiberRef.get(inSyncTransactionFiber);
|
|
1189
|
+
if (inTxn) {
|
|
1190
|
+
const prev = yield* runtime.getState;
|
|
1191
|
+
return yield* runtime.setState(f(prev));
|
|
1192
|
+
}
|
|
1193
|
+
const body = () => import_effect16.Effect.flatMap(runtime.getState, (prev) => runtime.setState(f(prev)));
|
|
1194
|
+
return yield* runtimeInternals ? runtimeInternals.txn.runWithStateTransaction({ kind: "state", name: "update" }, body) : body();
|
|
1195
|
+
}),
|
|
1196
|
+
mutate: (f) => import_effect16.Effect.gen(function* () {
|
|
1197
|
+
const recordPatch = runtimeInternals?.txn.recordStatePatch;
|
|
1198
|
+
const updateDraft = runtimeInternals?.txn.updateDraft;
|
|
1199
|
+
const inTxn = yield* import_effect16.FiberRef.get(inSyncTransactionFiber);
|
|
1200
|
+
if (inTxn) {
|
|
1201
|
+
const prev = yield* runtime.getState;
|
|
1202
|
+
const { nextState, patchPaths } = mutateWithPatchPaths(prev, (draft) => {
|
|
1203
|
+
f(draft);
|
|
1204
|
+
});
|
|
1205
|
+
for (const path of patchPaths) {
|
|
1206
|
+
recordPatch?.(path, "unknown");
|
|
1207
|
+
}
|
|
1208
|
+
updateDraft?.(nextState);
|
|
1209
|
+
return;
|
|
1210
|
+
}
|
|
1211
|
+
const body = () => import_effect16.Effect.gen(function* () {
|
|
1212
|
+
const prev = yield* runtime.getState;
|
|
1213
|
+
const { nextState, patchPaths } = mutateWithPatchPaths(prev, (draft) => {
|
|
1214
|
+
f(draft);
|
|
1215
|
+
});
|
|
1216
|
+
for (const path of patchPaths) {
|
|
1217
|
+
recordPatch?.(path, "unknown");
|
|
1218
|
+
}
|
|
1219
|
+
updateDraft?.(nextState);
|
|
1220
|
+
});
|
|
1221
|
+
return yield* runtimeInternals ? runtimeInternals.txn.runWithStateTransaction({ kind: "state", name: "mutate" }, body) : body();
|
|
1222
|
+
}),
|
|
1223
|
+
ref: runtime.ref
|
|
1224
|
+
};
|
|
1225
|
+
const actions = shape.actionMap;
|
|
1226
|
+
const dispatcherCache = /* @__PURE__ */ new Map();
|
|
1227
|
+
const hasAction = (key) => Object.prototype.hasOwnProperty.call(actions, key);
|
|
1228
|
+
const dispatchers = new Proxy({}, {
|
|
1229
|
+
get: (_target, prop) => {
|
|
1230
|
+
if (typeof prop !== "string") return void 0;
|
|
1231
|
+
if (!hasAction(prop)) return void 0;
|
|
1232
|
+
const cached = dispatcherCache.get(prop);
|
|
1233
|
+
if (cached) return cached;
|
|
1234
|
+
const token = actions[prop];
|
|
1235
|
+
const fn = (...args) => runtime.dispatch(token(...args));
|
|
1236
|
+
dispatcherCache.set(prop, fn);
|
|
1237
|
+
return fn;
|
|
1238
|
+
},
|
|
1239
|
+
has: (_target, prop) => typeof prop === "string" && hasAction(prop),
|
|
1240
|
+
ownKeys: () => Object.keys(actions),
|
|
1241
|
+
getOwnPropertyDescriptor: (_target, prop) => {
|
|
1242
|
+
if (typeof prop !== "string") return void 0;
|
|
1243
|
+
if (!hasAction(prop)) return void 0;
|
|
1244
|
+
return { enumerable: true, configurable: true };
|
|
1245
|
+
}
|
|
1246
|
+
});
|
|
1247
|
+
const dispatch = (...args) => {
|
|
1248
|
+
const [first, second] = args;
|
|
1249
|
+
if (typeof first === "string") {
|
|
1250
|
+
return runtime.dispatch({ _tag: first, payload: second });
|
|
1251
|
+
}
|
|
1252
|
+
if (isActionToken(first)) {
|
|
1253
|
+
return runtime.dispatch(first(second));
|
|
1254
|
+
}
|
|
1255
|
+
return runtime.dispatch(first);
|
|
1256
|
+
};
|
|
1257
|
+
const matchApi = (value) => makeMatch(value);
|
|
1258
|
+
const matchTagApi = (value) => makeMatchTag(value);
|
|
1259
|
+
const reducer = (tag, fn) => {
|
|
1260
|
+
return import_effect16.Effect.sync(() => {
|
|
1261
|
+
runtimeInternals.txn.registerReducer(String(tag), fn);
|
|
1262
|
+
});
|
|
1263
|
+
};
|
|
1264
|
+
const effect = (token, handler) => import_effect16.Effect.gen(function* () {
|
|
1265
|
+
if (!isActionToken(token)) {
|
|
1266
|
+
return yield* import_effect16.Effect.dieMessage("[BoundApi.effect] token must be an ActionToken");
|
|
1267
|
+
}
|
|
1268
|
+
const phase = getCurrentPhase();
|
|
1269
|
+
const logicUnit = options?.logicUnit;
|
|
1270
|
+
yield* runtimeInternals.effects.registerEffect({
|
|
1271
|
+
actionTag: token.tag,
|
|
1272
|
+
handler,
|
|
1273
|
+
phase,
|
|
1274
|
+
...logicUnit ? {
|
|
1275
|
+
logicUnit: {
|
|
1276
|
+
logicUnitId: logicUnit.logicUnitId,
|
|
1277
|
+
logicUnitLabel: logicUnit.logicUnitLabel,
|
|
1278
|
+
path: logicUnit.path
|
|
1279
|
+
}
|
|
1280
|
+
} : {}
|
|
1281
|
+
});
|
|
1282
|
+
});
|
|
1283
|
+
const api = {
|
|
1284
|
+
root: {
|
|
1285
|
+
resolve: (tag) => {
|
|
1286
|
+
guardRunOnly("root_resolve_in_setup", "$.root.resolve");
|
|
1287
|
+
return resolve2(tag, {
|
|
1288
|
+
entrypoint: "logic.$.root.resolve",
|
|
1289
|
+
waitForReady: true
|
|
1290
|
+
});
|
|
1291
|
+
}
|
|
1292
|
+
},
|
|
1293
|
+
state: stateApi,
|
|
1294
|
+
actions,
|
|
1295
|
+
dispatchers,
|
|
1296
|
+
dispatch,
|
|
1297
|
+
flow: flowApi,
|
|
1298
|
+
match: matchApi,
|
|
1299
|
+
matchTag: matchTagApi,
|
|
1300
|
+
lifecycle: {
|
|
1301
|
+
onInitRequired: (eff) => {
|
|
1302
|
+
if (getCurrentPhase() === "run") {
|
|
1303
|
+
return emitSetupOnlyViolation("$.lifecycle.onInitRequired");
|
|
1304
|
+
}
|
|
1305
|
+
runtimeInternals.lifecycle.registerInitRequired(eff);
|
|
1306
|
+
return import_effect16.Effect.void;
|
|
1307
|
+
},
|
|
1308
|
+
onStart: (eff) => {
|
|
1309
|
+
if (getCurrentPhase() === "run") {
|
|
1310
|
+
return emitSetupOnlyViolation("$.lifecycle.onStart");
|
|
1311
|
+
}
|
|
1312
|
+
runtimeInternals.lifecycle.registerStart(eff);
|
|
1313
|
+
return import_effect16.Effect.void;
|
|
1314
|
+
},
|
|
1315
|
+
onInit: (eff) => {
|
|
1316
|
+
if (getCurrentPhase() === "run") {
|
|
1317
|
+
return emitSetupOnlyViolation("$.lifecycle.onInit");
|
|
1318
|
+
}
|
|
1319
|
+
runtimeInternals.lifecycle.registerInitRequired(eff);
|
|
1320
|
+
return import_effect16.Effect.void;
|
|
1321
|
+
},
|
|
1322
|
+
onDestroy: (eff) => {
|
|
1323
|
+
if (getCurrentPhase() === "run") {
|
|
1324
|
+
return emitSetupOnlyViolation("$.lifecycle.onDestroy");
|
|
1325
|
+
}
|
|
1326
|
+
runtimeInternals.lifecycle.registerDestroy(eff);
|
|
1327
|
+
return import_effect16.Effect.void;
|
|
1328
|
+
},
|
|
1329
|
+
onError: (handler) => {
|
|
1330
|
+
if (getCurrentPhase() === "run") {
|
|
1331
|
+
return emitSetupOnlyViolation("$.lifecycle.onError");
|
|
1332
|
+
}
|
|
1333
|
+
runtimeInternals.lifecycle.registerOnError(handler);
|
|
1334
|
+
return import_effect16.Effect.void;
|
|
1335
|
+
},
|
|
1336
|
+
onSuspend: (eff) => {
|
|
1337
|
+
if (getCurrentPhase() === "run") {
|
|
1338
|
+
return emitSetupOnlyViolation("$.lifecycle.onSuspend");
|
|
1339
|
+
}
|
|
1340
|
+
runtimeInternals.lifecycle.registerPlatformSuspend(import_effect16.Effect.asVoid(eff));
|
|
1341
|
+
return import_effect16.Effect.void;
|
|
1342
|
+
},
|
|
1343
|
+
onResume: (eff) => {
|
|
1344
|
+
if (getCurrentPhase() === "run") {
|
|
1345
|
+
return emitSetupOnlyViolation("$.lifecycle.onResume");
|
|
1346
|
+
}
|
|
1347
|
+
runtimeInternals.lifecycle.registerPlatformResume(import_effect16.Effect.asVoid(eff));
|
|
1348
|
+
return import_effect16.Effect.void;
|
|
1349
|
+
},
|
|
1350
|
+
onReset: (eff) => {
|
|
1351
|
+
if (getCurrentPhase() === "run") {
|
|
1352
|
+
return emitSetupOnlyViolation("$.lifecycle.onReset");
|
|
1353
|
+
}
|
|
1354
|
+
runtimeInternals.lifecycle.registerPlatformReset(import_effect16.Effect.asVoid(eff));
|
|
1355
|
+
return import_effect16.Effect.void;
|
|
1356
|
+
}
|
|
1357
|
+
},
|
|
1358
|
+
traits: {
|
|
1359
|
+
declare: (traits) => {
|
|
1360
|
+
if (getCurrentPhase() === "run") {
|
|
1361
|
+
throw makeLogicPhaseError(
|
|
1362
|
+
"traits_declare_in_run",
|
|
1363
|
+
"$.traits.declare",
|
|
1364
|
+
"run",
|
|
1365
|
+
options?.moduleId
|
|
1366
|
+
);
|
|
1367
|
+
}
|
|
1368
|
+
if (!traits || typeof traits !== "object") {
|
|
1369
|
+
throw new Error("[InvalidTraitsDeclaration] $.traits.declare expects an object.");
|
|
1370
|
+
}
|
|
1371
|
+
const logicUnit = options?.logicUnit ?? {
|
|
1372
|
+
logicUnitId: "unknown",
|
|
1373
|
+
logicUnitIdKind: "derived",
|
|
1374
|
+
logicUnitLabel: "logicUnit:unknown",
|
|
1375
|
+
path: void 0
|
|
1376
|
+
};
|
|
1377
|
+
runtimeInternals.traits.registerModuleTraitsContribution({
|
|
1378
|
+
traits,
|
|
1379
|
+
provenance: {
|
|
1380
|
+
originType: "logicUnit",
|
|
1381
|
+
originId: logicUnit.logicUnitId,
|
|
1382
|
+
originIdKind: logicUnit.logicUnitIdKind,
|
|
1383
|
+
originLabel: logicUnit.logicUnitLabel,
|
|
1384
|
+
path: logicUnit.path
|
|
1385
|
+
}
|
|
1386
|
+
});
|
|
1387
|
+
},
|
|
1388
|
+
source: {
|
|
1389
|
+
refresh: (fieldPath, options2) => import_effect16.Effect.gen(function* () {
|
|
1390
|
+
const handler = runtimeInternals.traits.getSourceRefreshHandler(fieldPath);
|
|
1391
|
+
if (!handler) {
|
|
1392
|
+
return yield* import_effect16.Effect.void;
|
|
1393
|
+
}
|
|
1394
|
+
const force = options2?.force === true;
|
|
1395
|
+
const runHandler = (state) => force ? import_effect16.Effect.locally(forceSourceRefresh, true)(handler(state)) : handler(state);
|
|
1396
|
+
const inTxn = yield* import_effect16.FiberRef.get(inSyncTransactionFiber);
|
|
1397
|
+
if (inTxn) {
|
|
1398
|
+
const state = yield* runtime.getState;
|
|
1399
|
+
return yield* runHandler(state);
|
|
1400
|
+
}
|
|
1401
|
+
return yield* runtimeInternals.txn.runWithStateTransaction(
|
|
1402
|
+
{
|
|
1403
|
+
kind: "source-refresh",
|
|
1404
|
+
name: fieldPath
|
|
1405
|
+
},
|
|
1406
|
+
() => import_effect16.Effect.gen(function* () {
|
|
1407
|
+
const state = yield* runtime.getState;
|
|
1408
|
+
return yield* runHandler(state);
|
|
1409
|
+
})
|
|
1410
|
+
);
|
|
1411
|
+
})
|
|
1412
|
+
}
|
|
1413
|
+
},
|
|
1414
|
+
reducer,
|
|
1415
|
+
effect,
|
|
1416
|
+
use: new Proxy(() => {
|
|
1417
|
+
}, {
|
|
1418
|
+
apply: (_target, _thisArg, [arg]) => {
|
|
1419
|
+
guardRunOnly("use_in_setup", "$.use");
|
|
1420
|
+
if (isModuleLike(arg)) {
|
|
1421
|
+
const domain = arg;
|
|
1422
|
+
const tag = domain.tag;
|
|
1423
|
+
const resolveAndBuild = resolveModuleRuntime(tag).pipe(import_effect16.Effect.map((rt) => buildModuleHandle(tag, rt)));
|
|
1424
|
+
const resolveWithDescriptor = resolveModuleRuntime(tag).pipe(
|
|
1425
|
+
import_effect16.Effect.tap((rt) => emitModuleDescriptorOnce(domain, rt)),
|
|
1426
|
+
import_effect16.Effect.map((rt) => buildModuleHandle(tag, rt))
|
|
1427
|
+
);
|
|
1428
|
+
const detectAndSelect = import_effect16.FiberRef.get(currentDiagnosticsLevel).pipe(
|
|
1429
|
+
import_effect16.Effect.tap((level) => {
|
|
1430
|
+
cachedDiagnosticsLevel = level;
|
|
1431
|
+
}),
|
|
1432
|
+
import_effect16.Effect.flatMap((level) => level === "off" ? resolveAndBuild : resolveWithDescriptor)
|
|
1433
|
+
);
|
|
1434
|
+
return import_effect16.Effect.suspend(() => {
|
|
1435
|
+
if (cachedDiagnosticsLevel === "off") {
|
|
1436
|
+
return resolveAndBuild;
|
|
1437
|
+
}
|
|
1438
|
+
if (cachedDiagnosticsLevel !== void 0) {
|
|
1439
|
+
return resolveWithDescriptor;
|
|
1440
|
+
}
|
|
1441
|
+
return detectAndSelect;
|
|
1442
|
+
});
|
|
1443
|
+
}
|
|
1444
|
+
if (import_effect16.Context.isTag(arg)) {
|
|
1445
|
+
const candidate = arg;
|
|
1446
|
+
if (candidate._kind === "ModuleTag") {
|
|
1447
|
+
return resolveModuleRuntime(arg).pipe(
|
|
1448
|
+
import_effect16.Effect.map((rt) => buildModuleHandle(arg, rt))
|
|
1449
|
+
);
|
|
1450
|
+
}
|
|
1451
|
+
return arg;
|
|
1452
|
+
}
|
|
1453
|
+
return import_effect16.Effect.die("BoundApi.use: unsupported argument");
|
|
1454
|
+
}
|
|
1455
|
+
}),
|
|
1456
|
+
onAction: new Proxy(() => {
|
|
1457
|
+
}, {
|
|
1458
|
+
apply: (_target, _thisArg, args) => {
|
|
1459
|
+
guardRunOnly("use_in_setup", "$.onAction");
|
|
1460
|
+
const arg = args[0];
|
|
1461
|
+
if (isActionToken(arg)) {
|
|
1462
|
+
const tag = arg.tag;
|
|
1463
|
+
return createIntentBuilder(
|
|
1464
|
+
runtime.actions$.pipe(
|
|
1465
|
+
import_effect16.Stream.filter((a) => a._tag === tag || a.type === tag),
|
|
1466
|
+
import_effect16.Stream.map((a) => a.payload)
|
|
1467
|
+
),
|
|
1468
|
+
tag
|
|
1469
|
+
);
|
|
1470
|
+
}
|
|
1471
|
+
if (typeof arg === "function") {
|
|
1472
|
+
return createIntentBuilder(runtime.actions$.pipe(import_effect16.Stream.filter(arg)));
|
|
1473
|
+
}
|
|
1474
|
+
if (typeof arg === "string") {
|
|
1475
|
+
return createIntentBuilder(
|
|
1476
|
+
runtime.actions$.pipe(import_effect16.Stream.filter((a) => a._tag === arg || a.type === arg)),
|
|
1477
|
+
arg
|
|
1478
|
+
);
|
|
1479
|
+
}
|
|
1480
|
+
if (typeof arg === "object" && arg !== null) {
|
|
1481
|
+
if ("_tag" in arg) {
|
|
1482
|
+
return createIntentBuilder(
|
|
1483
|
+
runtime.actions$.pipe(import_effect16.Stream.filter((a) => a._tag === arg._tag)),
|
|
1484
|
+
String(arg._tag)
|
|
1485
|
+
);
|
|
1486
|
+
}
|
|
1487
|
+
if (import_effect16.Schema.isSchema(arg)) {
|
|
1488
|
+
return createIntentBuilder(
|
|
1489
|
+
runtime.actions$.pipe(
|
|
1490
|
+
import_effect16.Stream.filter((a) => {
|
|
1491
|
+
const result = import_effect16.Schema.decodeUnknownSync(arg)(a);
|
|
1492
|
+
return !!result;
|
|
1493
|
+
})
|
|
1494
|
+
)
|
|
1495
|
+
);
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
return createIntentBuilder(runtime.actions$);
|
|
1499
|
+
},
|
|
1500
|
+
get: (_target, prop) => {
|
|
1501
|
+
guardRunOnly("use_in_setup", "$.onAction");
|
|
1502
|
+
if (typeof prop === "string") {
|
|
1503
|
+
return createIntentBuilder(
|
|
1504
|
+
runtime.actions$.pipe(import_effect16.Stream.filter((a) => a._tag === prop || a.type === prop)),
|
|
1505
|
+
prop
|
|
1506
|
+
);
|
|
1507
|
+
}
|
|
1508
|
+
return void 0;
|
|
1509
|
+
}
|
|
1510
|
+
}),
|
|
1511
|
+
onState: (selector) => {
|
|
1512
|
+
guardRunOnly("use_in_setup", "$.onState");
|
|
1513
|
+
return createIntentBuilder(runtime.changes(selector));
|
|
1514
|
+
},
|
|
1515
|
+
on: (stream) => {
|
|
1516
|
+
guardRunOnly("use_in_setup", "$.on");
|
|
1517
|
+
return createIntentBuilder(stream);
|
|
1518
|
+
}
|
|
1519
|
+
};
|
|
1520
|
+
setBoundInternals(api, runtimeInternals);
|
|
1521
|
+
return api;
|
|
1522
|
+
}
|
|
1523
|
+
|
|
1524
|
+
// src/Bound.ts
|
|
1525
|
+
function make4(shape, runtime) {
|
|
1526
|
+
return make3(shape, runtime);
|
|
1527
|
+
}
|
|
1528
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1529
|
+
0 && (module.exports = {
|
|
1530
|
+
make
|
|
1531
|
+
});
|
|
1532
|
+
//# sourceMappingURL=Bound.cjs.map
|