@ultrst-armada/krnl 0.0.0-stage → 1.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/README.md +95 -2
- package/package.json +75 -4
- package/packages/cli/dist/K_ENT_Entity-PQ5MURQY-ZG6FZXXX.js +13 -0
- package/packages/cli/dist/K_LIB_Krnl_Aiko_Client-OPZAVZCW-K4CRQYA5.js +8 -0
- package/packages/cli/dist/K_LIB_Krnl_Ep_Tools-ROOE2TQF-LNPXZYOE.js +110 -0
- package/packages/cli/dist/K_LIB_Krnl_Frontend_Builder-2ZDUH6PF-3ALZPNX4.js +11 -0
- package/packages/cli/dist/K_LIB_Krnl_Frontend_Generator-UYNRNX2X-PJTICYSW.js +11 -0
- package/packages/cli/dist/K_LIB_Krnl_Registry_Client-NXV6D2QW-M5TYU55O.js +8 -0
- package/packages/cli/dist/K_LIB_Krnl_SubApp_Engine-7HR5HWW2-H6STOXRK.js +20 -0
- package/packages/cli/dist/K_LIB_Krnl_SubApp_Registry-7XYGDKJK-XPJXSF7D.js +19 -0
- package/packages/cli/dist/K_LIB_Krnl_SubApp_Worker_Host-CQVTGGG7-CUYGTWOW.js +7 -0
- package/packages/cli/dist/K_LIB_Krnl_System_App_Adapter-M6FJKLGU-VR6T4N6J.js +17 -0
- package/packages/cli/dist/K_LIB_Krnl_System_Base_Functionality_APIs-ZZUZ6ZG5-RLJ4QWDP.js +58 -0
- package/packages/cli/dist/K_LIB_Krnl_System_Magnetic_Loader-XBQO2KXF-BOQGUASC.js +22 -0
- package/packages/cli/dist/K_LIB_Krnl_System_Unified_Http_Adapter-RCEGP3OG-XJI7KIT5.js +8 -0
- package/packages/cli/dist/K_LIB_Krnl_Telemetry-77FRZ3KV-K5VCWAFW.js +9 -0
- package/packages/cli/dist/bin/krnl.cjs +9758 -0
- package/packages/cli/dist/bin/krnl.d.cts +1 -0
- package/packages/cli/dist/bin/krnl.d.ts +1 -0
- package/packages/cli/dist/bin/krnl.js +2006 -0
- package/packages/cli/dist/chunk-3TRM6CYL.js +152 -0
- package/packages/cli/dist/chunk-5JDK35TG.js +3872 -0
- package/packages/cli/dist/chunk-63PTK33I.js +997 -0
- package/packages/cli/dist/chunk-6NIKAMUZ.js +82 -0
- package/packages/cli/dist/chunk-BOXWWXQG.js +400 -0
- package/packages/cli/dist/chunk-EEKLK7QJ.js +565 -0
- package/packages/cli/dist/chunk-EG7T2IAD.js +107 -0
- package/packages/cli/dist/chunk-F5EHXE2O.js +1036 -0
- package/packages/cli/dist/chunk-F65ANSQG.js +269 -0
- package/packages/cli/dist/chunk-FDNCADFE.js +71 -0
- package/packages/cli/dist/chunk-GDLRMDAN.js +127 -0
- package/packages/cli/dist/chunk-HWMTCMOS.js +656 -0
- package/packages/cli/dist/chunk-I74QIQOD.js +5536 -0
- package/packages/cli/dist/chunk-JTLSTO25.js +71 -0
- package/packages/cli/dist/chunk-JULBBJ27.js +1033 -0
- package/packages/cli/dist/chunk-OHVMVRBP.js +117 -0
- package/packages/cli/dist/chunk-P2PCLEKX.js +666 -0
- package/packages/cli/dist/chunk-PJQIUOX2.js +7767 -0
- package/packages/cli/dist/chunk-PPOF3DJW.js +471 -0
- package/packages/cli/dist/chunk-Q45257P6.js +173 -0
- package/packages/cli/dist/chunk-QNROWGBI.js +1036 -0
- package/packages/cli/dist/chunk-RJNYUXZD.js +977 -0
- package/packages/cli/dist/chunk-SRTOPJ5W.js +104 -0
- package/packages/cli/dist/chunk-TCEX3MPS.js +702 -0
- package/packages/cli/dist/chunk-TNOAJO2J.js +675 -0
- package/packages/cli/dist/chunk-UR2SUCSF.js +701 -0
- package/packages/cli/dist/chunk-X5LOIFM7.js +68 -0
- package/packages/cli/dist/chunk-XIRFOO3H.js +589 -0
- package/packages/cli/dist/chunk-ZAAV3JXQ.js +809 -0
- package/packages/cli/dist/index.cjs +7798 -0
- package/packages/cli/dist/index.d.cts +7 -0
- package/packages/cli/dist/index.d.ts +7 -0
- package/packages/cli/dist/index.js +29 -0
- package/packages/cli/package.json +34 -0
- package/packages/core/dist/K_ENT_Entity-4MB7CU4A.js +12 -0
- package/packages/core/dist/K_ENT_Entity-DEJGIDGH.js +12 -0
- package/packages/core/dist/K_ENT_Entity-FXZO5UZ2.js +12 -0
- package/packages/core/dist/K_ENT_Entity-HDSCXC5F.js +12 -0
- package/packages/core/dist/K_ENT_Entity-JILABHLW.js +12 -0
- package/packages/core/dist/K_ENT_Entity-PQ5MURQY.js +13 -0
- package/packages/core/dist/K_ENT_Entity-ROAKDIHW.js +12 -0
- package/packages/core/dist/K_ENT_Entity-TBVFSKDV.js +12 -0
- package/packages/core/dist/K_ENT_Entity-ZFLKG3JO.js +12 -0
- package/packages/core/dist/K_LIB_Krnl_Aiko_Client-OPZAVZCW.js +8 -0
- package/packages/core/dist/K_LIB_Krnl_Ep_Tools-ROOE2TQF.js +110 -0
- package/packages/core/dist/K_LIB_Krnl_Frontend_Builder-2ZDUH6PF.js +9 -0
- package/packages/core/dist/K_LIB_Krnl_Frontend_Generator-UYNRNX2X.js +9 -0
- package/packages/core/dist/K_LIB_Krnl_Registry_Client-NXV6D2QW.js +8 -0
- package/packages/core/dist/K_LIB_Krnl_SubApp_Engine-7HR5HWW2.js +20 -0
- package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-4C6GBQAG.js +18 -0
- package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-6V23A6F6.js +18 -0
- package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-7XYGDKJK.js +19 -0
- package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-DYLLC5G2.js +18 -0
- package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-F4FOFAUP.js +18 -0
- package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-FBOXXMI3.js +18 -0
- package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-Q73BWLNP.js +18 -0
- package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-QM2C4MVA.js +18 -0
- package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-QUGI6SMP.js +18 -0
- package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-RGMTBHNP.js +18 -0
- package/packages/core/dist/K_LIB_Krnl_SubApp_Registry-RWR7UNDW.js +18 -0
- package/packages/core/dist/K_LIB_Krnl_SubApp_Worker_Host-CQVTGGG7.js +7 -0
- package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-32MFJJ5Z.js +17 -0
- package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-4J4CEWRY.js +17 -0
- package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-A366YHF2.js +17 -0
- package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-LK4LYJHI.js +17 -0
- package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-M6FJKLGU.js +17 -0
- package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-NW3K63II.js +17 -0
- package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-QDHTI5ZV.js +17 -0
- package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-VHCT6VIW.js +17 -0
- package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-WBRKF24R.js +17 -0
- package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-XKYQYT6Q.js +17 -0
- package/packages/core/dist/K_LIB_Krnl_System_App_Adapter-Z2PWZYDZ.js +17 -0
- package/packages/core/dist/K_LIB_Krnl_System_Base_Functionality_APIs-ZZUZ6ZG5.js +58 -0
- package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-2EZU7QF4.js +21 -0
- package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-6G3AQNAV.js +21 -0
- package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-B2NZMQUG.js +21 -0
- package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-C2RABMZP.js +21 -0
- package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-HHE3NZ4F.js +21 -0
- package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-LHFGR6WK.js +21 -0
- package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-M74BLM3N.js +21 -0
- package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-PT6ZA6EA.js +21 -0
- package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-SP52V3CX.js +21 -0
- package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-XBQO2KXF.js +22 -0
- package/packages/core/dist/K_LIB_Krnl_System_Magnetic_Loader-YNSEUHJJ.js +21 -0
- package/packages/core/dist/K_LIB_Krnl_System_Unified_Http_Adapter-M6SBHIVA.js +8 -0
- package/packages/core/dist/K_LIB_Krnl_System_Unified_Http_Adapter-RCEGP3OG.js +8 -0
- package/packages/core/dist/K_LIB_Krnl_Telemetry-77FRZ3KV.js +9 -0
- package/packages/core/dist/chunk-33L2J7V7.js +82 -0
- package/packages/core/dist/chunk-3ES4K2ZP.js +817 -0
- package/packages/core/dist/chunk-3SMHVVLL.js +82 -0
- package/packages/core/dist/chunk-3UEZ7JQA.js +4877 -0
- package/packages/core/dist/chunk-3XIE6KBD.js +4877 -0
- package/packages/core/dist/chunk-46ZLCML6.js +107 -0
- package/packages/core/dist/chunk-4UEL3DWJ.js +107 -0
- package/packages/core/dist/chunk-54GWZ5PC.js +82 -0
- package/packages/core/dist/chunk-6QCYRS5L.js +127 -0
- package/packages/core/dist/chunk-6ULMHNXR.js +104 -0
- package/packages/core/dist/chunk-7WUETJEV.js +117 -0
- package/packages/core/dist/chunk-A5KRAYDB.js +107 -0
- package/packages/core/dist/chunk-ANEAZ3PO.js +107 -0
- package/packages/core/dist/chunk-BE76RL6F.js +82 -0
- package/packages/core/dist/chunk-CIARVYDO.js +107 -0
- package/packages/core/dist/chunk-CR2ANE62.js +107 -0
- package/packages/core/dist/chunk-DI27MOR7.js +173 -0
- package/packages/core/dist/chunk-E6RLFHM5.js +596 -0
- package/packages/core/dist/chunk-EELAPMNV.js +4877 -0
- package/packages/core/dist/chunk-ENZ2RQVJ.js +107 -0
- package/packages/core/dist/chunk-F2U6CX4F.js +4877 -0
- package/packages/core/dist/chunk-FKG64OHL.js +82 -0
- package/packages/core/dist/chunk-FYAZJYM5.js +772 -0
- package/packages/core/dist/chunk-G4NP4RDQ.js +82 -0
- package/packages/core/dist/chunk-GADIRLRS.js +473 -0
- package/packages/core/dist/chunk-GR6CSLQJ.js +772 -0
- package/packages/core/dist/chunk-HDS7AT6O.js +772 -0
- package/packages/core/dist/chunk-HIMEZUU2.js +71 -0
- package/packages/core/dist/chunk-IB4UHG5I.js +596 -0
- package/packages/core/dist/chunk-J7ZYNVRS.js +772 -0
- package/packages/core/dist/chunk-JVLZU4K7.js +604 -0
- package/packages/core/dist/chunk-JYXXI7Q3.js +82 -0
- package/packages/core/dist/chunk-K54K2KZW.js +192 -0
- package/packages/core/dist/chunk-K6VHLBNH.js +3316 -0
- package/packages/core/dist/chunk-KCBP7ZYA.js +596 -0
- package/packages/core/dist/chunk-KFQGP6VL.js +33 -0
- package/packages/core/dist/chunk-KIUEUI7K.js +82 -0
- package/packages/core/dist/chunk-LB67NIZP.js +949 -0
- package/packages/core/dist/chunk-LDTYFUNW.js +596 -0
- package/packages/core/dist/chunk-MLVWARD4.js +596 -0
- package/packages/core/dist/chunk-MPYVXHKO.js +2777 -0
- package/packages/core/dist/chunk-MRQ3MITU.js +772 -0
- package/packages/core/dist/chunk-MVUN7I7O.js +107 -0
- package/packages/core/dist/chunk-NDDOIRW7.js +596 -0
- package/packages/core/dist/chunk-O3KDB5MH.js +3330 -0
- package/packages/core/dist/chunk-OEINUDSE.js +400 -0
- package/packages/core/dist/chunk-OPDENPT4.js +4877 -0
- package/packages/core/dist/chunk-P6XEM2LA.js +429 -0
- package/packages/core/dist/chunk-QKMRSQV4.js +82 -0
- package/packages/core/dist/chunk-R6CCWALL.js +4877 -0
- package/packages/core/dist/chunk-RAMMOO73.js +774 -0
- package/packages/core/dist/chunk-S3FTZFG6.js +772 -0
- package/packages/core/dist/chunk-T2ZVN434.js +4877 -0
- package/packages/core/dist/chunk-TFHLDMIA.js +107 -0
- package/packages/core/dist/chunk-TI3QUCIJ.js +107 -0
- package/packages/core/dist/chunk-TR2BAIGI.js +107 -0
- package/packages/core/dist/chunk-UGVVJKC6.js +4877 -0
- package/packages/core/dist/chunk-V2DX7YIU.js +984 -0
- package/packages/core/dist/chunk-W4IHYUYD.js +772 -0
- package/packages/core/dist/chunk-W6WBG5OY.js +4877 -0
- package/packages/core/dist/chunk-WN3M7O7H.js +3312 -0
- package/packages/core/dist/chunk-WR3NCU7U.js +4877 -0
- package/packages/core/dist/chunk-XC6B6L27.js +82 -0
- package/packages/core/dist/chunk-XNSE64ZY.js +3316 -0
- package/packages/core/dist/chunk-XROES2WN.js +634 -0
- package/packages/core/dist/chunk-XSCKNRCZ.js +5020 -0
- package/packages/core/dist/chunk-XVABPAUZ.js +82 -0
- package/packages/core/dist/chunk-YOBCB5C5.js +596 -0
- package/packages/core/dist/chunk-YUK6Q563.js +666 -0
- package/packages/core/dist/chunk-YXGL3ZEU.js +1030 -0
- package/packages/core/dist/chunk-ZINJ5OUX.js +596 -0
- package/packages/core/dist/chunk-ZPFD4BIQ.js +604 -0
- package/packages/core/dist/chunk-ZQZBFG6F.js +4826 -0
- package/packages/core/dist/chunk-ZZFRJGXM.js +4877 -0
- package/packages/core/dist/index.cjs +760 -0
- package/packages/core/dist/index.d.cts +360 -0
- package/packages/core/dist/index.d.ts +360 -0
- package/packages/core/dist/index.js +707 -0
- package/packages/core/package.json +34 -0
- package/packages/create-krnl/dist/K_ENT_Entity-PQ5MURQY-R2OH4VXE.js +14 -0
- package/packages/create-krnl/dist/K_LIB_Krnl_Aiko_Client-OPZAVZCW-AZM5HF4M.js +9 -0
- package/packages/create-krnl/dist/K_LIB_Krnl_Ep_Tools-ROOE2TQF-X5N6SV2S.js +111 -0
- package/packages/create-krnl/dist/K_LIB_Krnl_Frontend_Builder-2ZDUH6PF-5PFHF4JU.js +12 -0
- package/packages/create-krnl/dist/K_LIB_Krnl_Frontend_Generator-UYNRNX2X-ED33OQPH.js +12 -0
- package/packages/create-krnl/dist/K_LIB_Krnl_Registry_Client-NXV6D2QW-YGQLVR4P.js +9 -0
- package/packages/create-krnl/dist/K_LIB_Krnl_SubApp_Engine-7HR5HWW2-VM7CTU2L.js +21 -0
- package/packages/create-krnl/dist/K_LIB_Krnl_SubApp_Registry-7XYGDKJK-Y2GQFJ7I.js +21 -0
- package/packages/create-krnl/dist/K_LIB_Krnl_SubApp_Worker_Host-CQVTGGG7-L3JQWO54.js +8 -0
- package/packages/create-krnl/dist/K_LIB_Krnl_System_App_Adapter-M6FJKLGU-KQARASPR.js +19 -0
- package/packages/create-krnl/dist/K_LIB_Krnl_System_Base_Functionality_APIs-ZZUZ6ZG5-OF3IGLVL.js +59 -0
- package/packages/create-krnl/dist/K_LIB_Krnl_System_Magnetic_Loader-XBQO2KXF-JOLHKOEX.js +24 -0
- package/packages/create-krnl/dist/K_LIB_Krnl_System_Unified_Http_Adapter-RCEGP3OG-L46LSHKQ.js +10 -0
- package/packages/create-krnl/dist/K_LIB_Krnl_Telemetry-77FRZ3KV-4JUPRR3X.js +10 -0
- package/packages/create-krnl/dist/chunk-3TRM6CYL.js +152 -0
- package/packages/create-krnl/dist/chunk-3URCB3QS.js +127 -0
- package/packages/create-krnl/dist/chunk-5JDK35TG.js +3872 -0
- package/packages/create-krnl/dist/chunk-A2XAXDOW.js +812 -0
- package/packages/create-krnl/dist/chunk-AN6TMQHG.js +1033 -0
- package/packages/create-krnl/dist/chunk-BOXWWXQG.js +400 -0
- package/packages/create-krnl/dist/chunk-BPTBREBG.js +38 -0
- package/packages/create-krnl/dist/chunk-FDNCADFE.js +71 -0
- package/packages/create-krnl/dist/chunk-JTLSTO25.js +71 -0
- package/packages/create-krnl/dist/chunk-M3NCUIPL.js +107 -0
- package/packages/create-krnl/dist/chunk-N2EONSOC.js +7769 -0
- package/packages/create-krnl/dist/chunk-OHVMVRBP.js +117 -0
- package/packages/create-krnl/dist/chunk-Q45257P6.js +173 -0
- package/packages/create-krnl/dist/chunk-QGM4M3NI.js +37 -0
- package/packages/create-krnl/dist/chunk-RJNYUXZD.js +977 -0
- package/packages/create-krnl/dist/chunk-SRTOPJ5W.js +104 -0
- package/packages/create-krnl/dist/chunk-UPBIGEC3.js +666 -0
- package/packages/create-krnl/dist/chunk-V2DB7UD7.js +82 -0
- package/packages/create-krnl/dist/chunk-WMHLIUI6.js +3644 -0
- package/packages/create-krnl/dist/chunk-XIRFOO3H.js +589 -0
- package/packages/create-krnl/dist/chunk-Y2CEEVZP.js +5536 -0
- package/packages/create-krnl/dist/index.cjs +395 -0
- package/packages/create-krnl/dist/index.js +372 -0
- package/packages/create-krnl/dist/main-DXUMPBND.js +2217 -0
- package/packages/create-krnl/dist/wrapper-SDF2VKX3.js +31 -0
- package/packages/create-krnl/package.json +23 -0
- package/packages/eslint-plugin/dist/index.cjs +439 -0
- package/packages/eslint-plugin/dist/index.d.cts +336 -0
- package/packages/eslint-plugin/dist/index.d.ts +336 -0
- package/packages/eslint-plugin/dist/index.js +416 -0
- package/packages/eslint-plugin/package.json +24 -0
- package/packages/validate/dist/index.cjs +499 -0
- package/packages/validate/dist/index.d.cts +49 -0
- package/packages/validate/dist/index.d.ts +49 -0
- package/packages/validate/dist/index.js +462 -0
- package/packages/validate/package.json +27 -0
|
@@ -0,0 +1,707 @@
|
|
|
1
|
+
// src/state/ServiceStateStore.ts
|
|
2
|
+
var ServiceStateStore = class {
|
|
3
|
+
state;
|
|
4
|
+
listeners = /* @__PURE__ */ new Set();
|
|
5
|
+
constructor(initialState) {
|
|
6
|
+
this.state = { ...initialState };
|
|
7
|
+
}
|
|
8
|
+
getState() {
|
|
9
|
+
return Object.freeze({ ...this.state });
|
|
10
|
+
}
|
|
11
|
+
setState(mutation) {
|
|
12
|
+
this.state = { ...this.state, ...mutation };
|
|
13
|
+
const snapshot = this.getState();
|
|
14
|
+
for (const listener of this.listeners) {
|
|
15
|
+
listener(snapshot, mutation);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
subscribe(listener) {
|
|
19
|
+
this.listeners.add(listener);
|
|
20
|
+
return () => {
|
|
21
|
+
this.listeners.delete(listener);
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
reset(newState) {
|
|
25
|
+
this.state = { ...newState || {} };
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// src/events/ServiceEventBus.ts
|
|
30
|
+
var ServiceEventBus = class {
|
|
31
|
+
handlers = /* @__PURE__ */ new Map();
|
|
32
|
+
on(event, handler) {
|
|
33
|
+
if (!this.handlers.has(event)) {
|
|
34
|
+
this.handlers.set(event, /* @__PURE__ */ new Set());
|
|
35
|
+
}
|
|
36
|
+
const set = this.handlers.get(event);
|
|
37
|
+
set.add(handler);
|
|
38
|
+
return () => {
|
|
39
|
+
set.delete(handler);
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
emit(event, payload) {
|
|
43
|
+
const set = this.handlers.get(event);
|
|
44
|
+
if (!set) return;
|
|
45
|
+
for (const handler of Array.from(set)) {
|
|
46
|
+
try {
|
|
47
|
+
handler(payload);
|
|
48
|
+
} catch (err) {
|
|
49
|
+
console.error(`[ServiceEventBus] Handler error for '${event}':`, err);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
clear() {
|
|
54
|
+
this.handlers.clear();
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// src/lifecycle/LifecycleManager.ts
|
|
59
|
+
var LifecycleManager = class {
|
|
60
|
+
status = "uninitialized";
|
|
61
|
+
getStatus() {
|
|
62
|
+
return this.status;
|
|
63
|
+
}
|
|
64
|
+
setStatus(next) {
|
|
65
|
+
this.status = next;
|
|
66
|
+
}
|
|
67
|
+
assertRunning(serviceName) {
|
|
68
|
+
if (this.status !== "running") {
|
|
69
|
+
throw new Error(`[Service:${serviceName}] Cannot invoke operation while status is '${this.status}' (expected 'running').`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// src/services/ServiceInstance.ts
|
|
75
|
+
var ServiceInstance = class {
|
|
76
|
+
constructor(definition) {
|
|
77
|
+
this.definition = definition;
|
|
78
|
+
this.id = definition.id;
|
|
79
|
+
this.name = definition.name;
|
|
80
|
+
this.version = definition.version;
|
|
81
|
+
this.lifecycle = new LifecycleManager();
|
|
82
|
+
this.eventBus = new ServiceEventBus();
|
|
83
|
+
if (definition.state?.initial) {
|
|
84
|
+
this.stateStore = new ServiceStateStore(definition.state.initial);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
definition;
|
|
88
|
+
id;
|
|
89
|
+
name;
|
|
90
|
+
version;
|
|
91
|
+
stateStore;
|
|
92
|
+
eventBus;
|
|
93
|
+
lifecycle;
|
|
94
|
+
getDefinition() {
|
|
95
|
+
return this.definition;
|
|
96
|
+
}
|
|
97
|
+
async start() {
|
|
98
|
+
this.lifecycle.setStatus("starting");
|
|
99
|
+
if (this.definition.lifecycle?.onInit) {
|
|
100
|
+
await this.definition.lifecycle.onInit();
|
|
101
|
+
}
|
|
102
|
+
if (this.definition.lifecycle?.onStart) {
|
|
103
|
+
await this.definition.lifecycle.onStart();
|
|
104
|
+
}
|
|
105
|
+
this.lifecycle.setStatus("running");
|
|
106
|
+
}
|
|
107
|
+
async stop() {
|
|
108
|
+
this.lifecycle.setStatus("stopping");
|
|
109
|
+
if (this.definition.lifecycle?.onStop) {
|
|
110
|
+
await this.definition.lifecycle.onStop();
|
|
111
|
+
}
|
|
112
|
+
if (this.definition.lifecycle?.onDispose) {
|
|
113
|
+
await this.definition.lifecycle.onDispose();
|
|
114
|
+
}
|
|
115
|
+
this.lifecycle.setStatus("stopped");
|
|
116
|
+
}
|
|
117
|
+
async call(op, input, ctx = {}) {
|
|
118
|
+
this.lifecycle.assertRunning(this.name);
|
|
119
|
+
const operation = this.definition.operations[op];
|
|
120
|
+
if (!operation) {
|
|
121
|
+
throw new Error(`[Service:${this.name}] Operation '${op}' not found.`);
|
|
122
|
+
}
|
|
123
|
+
return await operation.handler(input, ctx);
|
|
124
|
+
}
|
|
125
|
+
getState() {
|
|
126
|
+
if (!this.stateStore) {
|
|
127
|
+
return Object.freeze({});
|
|
128
|
+
}
|
|
129
|
+
return this.stateStore.getState();
|
|
130
|
+
}
|
|
131
|
+
setState(mutation) {
|
|
132
|
+
if (!this.stateStore) {
|
|
133
|
+
this.stateStore = new ServiceStateStore(mutation);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
this.stateStore.setState(mutation);
|
|
137
|
+
}
|
|
138
|
+
on(event, handler) {
|
|
139
|
+
return this.eventBus.on(event, handler);
|
|
140
|
+
}
|
|
141
|
+
emit(event, payload) {
|
|
142
|
+
this.eventBus.emit(event, payload);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
// src/services/ServiceProxy.ts
|
|
147
|
+
var ServiceProxy = class {
|
|
148
|
+
constructor(definition, adapter, endpoint) {
|
|
149
|
+
this.definition = definition;
|
|
150
|
+
this.adapter = adapter;
|
|
151
|
+
this.endpoint = endpoint;
|
|
152
|
+
this.id = definition.id;
|
|
153
|
+
this.name = definition.name;
|
|
154
|
+
this.version = definition.version;
|
|
155
|
+
this.stateCache = definition.state?.initial || {};
|
|
156
|
+
}
|
|
157
|
+
definition;
|
|
158
|
+
adapter;
|
|
159
|
+
endpoint;
|
|
160
|
+
id;
|
|
161
|
+
name;
|
|
162
|
+
version;
|
|
163
|
+
stateCache;
|
|
164
|
+
eventHandlers = /* @__PURE__ */ new Map();
|
|
165
|
+
getDefinition() {
|
|
166
|
+
return this.definition;
|
|
167
|
+
}
|
|
168
|
+
async start() {
|
|
169
|
+
}
|
|
170
|
+
async stop() {
|
|
171
|
+
}
|
|
172
|
+
async call(op, input, ctx = {}) {
|
|
173
|
+
if (!this.adapter.send) {
|
|
174
|
+
throw new Error(`[ServiceProxy:${this.name}] Adapter does not support send().`);
|
|
175
|
+
}
|
|
176
|
+
const envelope = {
|
|
177
|
+
id: `req-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`,
|
|
178
|
+
type: "request",
|
|
179
|
+
operation: op,
|
|
180
|
+
payload: input,
|
|
181
|
+
timestamp: Date.now()
|
|
182
|
+
};
|
|
183
|
+
const response = await this.adapter.send(this.endpoint, envelope);
|
|
184
|
+
if (response.error) {
|
|
185
|
+
throw new Error(`[ServiceProxy:${this.name}] Remote error: ${response.error}`);
|
|
186
|
+
}
|
|
187
|
+
return response.payload;
|
|
188
|
+
}
|
|
189
|
+
getState() {
|
|
190
|
+
return Object.freeze({ ...this.stateCache });
|
|
191
|
+
}
|
|
192
|
+
setState(mutation) {
|
|
193
|
+
this.stateCache = { ...this.stateCache, ...mutation };
|
|
194
|
+
}
|
|
195
|
+
on(event, handler) {
|
|
196
|
+
if (!this.eventHandlers.has(event)) {
|
|
197
|
+
this.eventHandlers.set(event, /* @__PURE__ */ new Set());
|
|
198
|
+
}
|
|
199
|
+
const handlers = this.eventHandlers.get(event);
|
|
200
|
+
handlers.add(handler);
|
|
201
|
+
return () => {
|
|
202
|
+
handlers.delete(handler);
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
emit(event, payload) {
|
|
206
|
+
const handlers = this.eventHandlers.get(event);
|
|
207
|
+
if (handlers) {
|
|
208
|
+
for (const handler of Array.from(handlers)) {
|
|
209
|
+
handler(payload);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
// src/services/ServiceGenerators.ts
|
|
216
|
+
function createServiceDefinition(definition) {
|
|
217
|
+
return definition;
|
|
218
|
+
}
|
|
219
|
+
function createService(definition) {
|
|
220
|
+
return new ServiceInstance(definition);
|
|
221
|
+
}
|
|
222
|
+
function createServiceProxy(definition, adapter, endpoint) {
|
|
223
|
+
return new ServiceProxy(definition, adapter, endpoint);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// src/protocols/HttpProtocolAdapter.ts
|
|
227
|
+
import http from "http";
|
|
228
|
+
var HttpProtocolAdapter = class {
|
|
229
|
+
protocol = "http";
|
|
230
|
+
capabilities = {
|
|
231
|
+
requestResponse: true,
|
|
232
|
+
streaming: true,
|
|
233
|
+
pubSub: false,
|
|
234
|
+
datagram: false,
|
|
235
|
+
peerToPeer: false,
|
|
236
|
+
signaling: false,
|
|
237
|
+
discovery: false
|
|
238
|
+
};
|
|
239
|
+
server;
|
|
240
|
+
listeningPort;
|
|
241
|
+
async listen(port, host = "127.0.0.1") {
|
|
242
|
+
this.server = http.createServer();
|
|
243
|
+
await new Promise((resolve, reject) => {
|
|
244
|
+
this.server.listen(port, host, () => {
|
|
245
|
+
const addr = this.server.address();
|
|
246
|
+
this.listeningPort = addr.port;
|
|
247
|
+
resolve();
|
|
248
|
+
});
|
|
249
|
+
this.server.on("error", reject);
|
|
250
|
+
});
|
|
251
|
+
return {
|
|
252
|
+
protocol: "http",
|
|
253
|
+
address: host,
|
|
254
|
+
port: this.listeningPort,
|
|
255
|
+
capabilities: ["requestResponse", "streaming"]
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
async expose(service, port = 0) {
|
|
259
|
+
this.server = http.createServer(async (req, res) => {
|
|
260
|
+
res.setHeader("Content-Type", "application/json");
|
|
261
|
+
const url = new URL(req.url || "/", `http://${req.headers.host || "localhost"}`);
|
|
262
|
+
if (url.pathname === "/manifest") {
|
|
263
|
+
res.writeHead(200);
|
|
264
|
+
res.end(JSON.stringify(service.getDefinition()));
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
if (url.pathname === "/health") {
|
|
268
|
+
res.writeHead(200);
|
|
269
|
+
res.end(JSON.stringify({ status: "ok", service: service.name }));
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
if (url.pathname.startsWith("/call/")) {
|
|
273
|
+
const op = url.pathname.slice("/call/".length);
|
|
274
|
+
let body = "";
|
|
275
|
+
req.on("data", (c) => body += c);
|
|
276
|
+
req.on("end", async () => {
|
|
277
|
+
try {
|
|
278
|
+
const parsed = body ? JSON.parse(body) : {};
|
|
279
|
+
const result = await service.call(op, parsed);
|
|
280
|
+
res.writeHead(200);
|
|
281
|
+
res.end(JSON.stringify({ status: "success", payload: result }));
|
|
282
|
+
} catch (err) {
|
|
283
|
+
res.writeHead(500);
|
|
284
|
+
res.end(JSON.stringify({ status: "error", error: err.message || String(err) }));
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
res.writeHead(404);
|
|
290
|
+
res.end(JSON.stringify({ error: "Route not found" }));
|
|
291
|
+
});
|
|
292
|
+
await new Promise((resolve, reject) => {
|
|
293
|
+
this.server.listen(port, "127.0.0.1", () => {
|
|
294
|
+
const addr = this.server.address();
|
|
295
|
+
this.listeningPort = addr.port;
|
|
296
|
+
resolve();
|
|
297
|
+
});
|
|
298
|
+
this.server.on("error", reject);
|
|
299
|
+
});
|
|
300
|
+
return {
|
|
301
|
+
protocol: "http",
|
|
302
|
+
address: "127.0.0.1",
|
|
303
|
+
port: this.listeningPort,
|
|
304
|
+
capabilities: ["requestResponse", "streaming"]
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
async send(endpoint, envelope) {
|
|
308
|
+
const url = `http://${endpoint.address}:${endpoint.port}/call/${envelope.operation}`;
|
|
309
|
+
const res = await fetch(url, {
|
|
310
|
+
method: "POST",
|
|
311
|
+
headers: { "Content-Type": "application/json" },
|
|
312
|
+
body: JSON.stringify(envelope.payload || {})
|
|
313
|
+
});
|
|
314
|
+
const json = await res.json();
|
|
315
|
+
return {
|
|
316
|
+
id: `res-${Date.now()}`,
|
|
317
|
+
type: "response",
|
|
318
|
+
correlationId: envelope.id,
|
|
319
|
+
payload: json.payload,
|
|
320
|
+
error: json.error,
|
|
321
|
+
timestamp: Date.now()
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
async stop() {
|
|
325
|
+
if (this.server) {
|
|
326
|
+
await new Promise((resolve) => this.server.close(() => resolve()));
|
|
327
|
+
this.server = void 0;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
// src/protocols/WebSocketProtocolAdapter.ts
|
|
333
|
+
import http2 from "http";
|
|
334
|
+
var WebSocketProtocolAdapter = class {
|
|
335
|
+
protocol = "ws";
|
|
336
|
+
capabilities = {
|
|
337
|
+
requestResponse: true,
|
|
338
|
+
streaming: true,
|
|
339
|
+
pubSub: true,
|
|
340
|
+
datagram: false,
|
|
341
|
+
peerToPeer: false,
|
|
342
|
+
signaling: false,
|
|
343
|
+
discovery: false
|
|
344
|
+
};
|
|
345
|
+
server;
|
|
346
|
+
wss;
|
|
347
|
+
port;
|
|
348
|
+
async expose(service, port = 0) {
|
|
349
|
+
const wsMod = await import("ws");
|
|
350
|
+
const WebSocketServer = wsMod.WebSocketServer || wsMod.default?.WebSocketServer || wsMod.Server;
|
|
351
|
+
this.server = http2.createServer();
|
|
352
|
+
this.wss = new WebSocketServer({ server: this.server });
|
|
353
|
+
this.wss.on("connection", (ws) => {
|
|
354
|
+
ws.on("message", async (raw) => {
|
|
355
|
+
try {
|
|
356
|
+
const envelope = JSON.parse(raw.toString());
|
|
357
|
+
if (envelope.type === "request" && envelope.operation) {
|
|
358
|
+
try {
|
|
359
|
+
const res = await service.call(envelope.operation, envelope.payload);
|
|
360
|
+
ws.send(JSON.stringify({
|
|
361
|
+
id: `res-${Date.now()}`,
|
|
362
|
+
type: "response",
|
|
363
|
+
correlationId: envelope.id,
|
|
364
|
+
payload: res,
|
|
365
|
+
timestamp: Date.now()
|
|
366
|
+
}));
|
|
367
|
+
} catch (err) {
|
|
368
|
+
ws.send(JSON.stringify({
|
|
369
|
+
id: `res-${Date.now()}`,
|
|
370
|
+
type: "response",
|
|
371
|
+
correlationId: envelope.id,
|
|
372
|
+
error: err.message || String(err),
|
|
373
|
+
timestamp: Date.now()
|
|
374
|
+
}));
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
} catch (_) {
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
});
|
|
381
|
+
await new Promise((resolve, reject) => {
|
|
382
|
+
this.server.listen(port, "127.0.0.1", () => {
|
|
383
|
+
const addr = this.server.address();
|
|
384
|
+
this.port = addr.port;
|
|
385
|
+
resolve();
|
|
386
|
+
});
|
|
387
|
+
this.server.on("error", reject);
|
|
388
|
+
});
|
|
389
|
+
return {
|
|
390
|
+
protocol: "ws",
|
|
391
|
+
address: "127.0.0.1",
|
|
392
|
+
port: this.port,
|
|
393
|
+
capabilities: ["requestResponse", "pubSub", "streaming"]
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
async send(endpoint, envelope) {
|
|
397
|
+
const wsMod = await import("ws");
|
|
398
|
+
const WS = wsMod.WebSocket || wsMod.default || globalThis.WebSocket;
|
|
399
|
+
return new Promise((resolve, reject) => {
|
|
400
|
+
const ws = new WS(`ws://${endpoint.address}:${endpoint.port}`);
|
|
401
|
+
ws.on("open", () => {
|
|
402
|
+
ws.send(JSON.stringify(envelope));
|
|
403
|
+
});
|
|
404
|
+
ws.on("message", (data) => {
|
|
405
|
+
try {
|
|
406
|
+
const res = JSON.parse(data.toString());
|
|
407
|
+
ws.close();
|
|
408
|
+
resolve(res);
|
|
409
|
+
} catch (e) {
|
|
410
|
+
ws.close();
|
|
411
|
+
reject(e);
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
ws.on("error", (err) => {
|
|
415
|
+
reject(err);
|
|
416
|
+
});
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
async stop() {
|
|
420
|
+
if (this.wss) {
|
|
421
|
+
await new Promise((r) => this.wss.close(() => r()));
|
|
422
|
+
this.wss = void 0;
|
|
423
|
+
}
|
|
424
|
+
if (this.server) {
|
|
425
|
+
await new Promise((r) => this.server.close(() => r()));
|
|
426
|
+
this.server = void 0;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
// src/protocols/UdpProtocolAdapter.ts
|
|
432
|
+
import dgram from "dgram";
|
|
433
|
+
var UdpProtocolAdapter = class {
|
|
434
|
+
protocol = "udp";
|
|
435
|
+
capabilities = {
|
|
436
|
+
requestResponse: true,
|
|
437
|
+
streaming: false,
|
|
438
|
+
pubSub: false,
|
|
439
|
+
datagram: true,
|
|
440
|
+
peerToPeer: false,
|
|
441
|
+
signaling: false,
|
|
442
|
+
discovery: true
|
|
443
|
+
};
|
|
444
|
+
socket;
|
|
445
|
+
port;
|
|
446
|
+
async expose(service, port = 0) {
|
|
447
|
+
this.socket = dgram.createSocket("udp4");
|
|
448
|
+
this.socket.on("message", async (msg, rinfo) => {
|
|
449
|
+
try {
|
|
450
|
+
const envelope = JSON.parse(msg.toString());
|
|
451
|
+
if (envelope.type === "request" && envelope.operation) {
|
|
452
|
+
try {
|
|
453
|
+
const res = await service.call(envelope.operation, envelope.payload);
|
|
454
|
+
const resp = JSON.stringify({
|
|
455
|
+
id: `res-${Date.now()}`,
|
|
456
|
+
type: "response",
|
|
457
|
+
correlationId: envelope.id,
|
|
458
|
+
payload: res,
|
|
459
|
+
timestamp: Date.now()
|
|
460
|
+
});
|
|
461
|
+
this.socket.send(resp, rinfo.port, rinfo.address);
|
|
462
|
+
} catch (err) {
|
|
463
|
+
const resp = JSON.stringify({
|
|
464
|
+
id: `res-${Date.now()}`,
|
|
465
|
+
type: "response",
|
|
466
|
+
correlationId: envelope.id,
|
|
467
|
+
error: err.message || String(err),
|
|
468
|
+
timestamp: Date.now()
|
|
469
|
+
});
|
|
470
|
+
this.socket.send(resp, rinfo.port, rinfo.address);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
} catch (_) {
|
|
474
|
+
}
|
|
475
|
+
});
|
|
476
|
+
await new Promise((resolve) => {
|
|
477
|
+
this.socket.bind(port, "127.0.0.1", () => {
|
|
478
|
+
this.port = this.socket.address().port;
|
|
479
|
+
resolve();
|
|
480
|
+
});
|
|
481
|
+
});
|
|
482
|
+
return {
|
|
483
|
+
protocol: "udp",
|
|
484
|
+
address: "127.0.0.1",
|
|
485
|
+
port: this.port,
|
|
486
|
+
capabilities: ["datagram", "requestResponse"]
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
async send(endpoint, envelope) {
|
|
490
|
+
return new Promise((resolve, reject) => {
|
|
491
|
+
const client = dgram.createSocket("udp4");
|
|
492
|
+
const payload = Buffer.from(JSON.stringify(envelope));
|
|
493
|
+
client.on("message", (msg) => {
|
|
494
|
+
try {
|
|
495
|
+
const res = JSON.parse(msg.toString());
|
|
496
|
+
client.close();
|
|
497
|
+
resolve(res);
|
|
498
|
+
} catch (e) {
|
|
499
|
+
client.close();
|
|
500
|
+
reject(e);
|
|
501
|
+
}
|
|
502
|
+
});
|
|
503
|
+
client.on("error", (err) => {
|
|
504
|
+
client.close();
|
|
505
|
+
reject(err);
|
|
506
|
+
});
|
|
507
|
+
client.send(payload, endpoint.port, endpoint.address);
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
async stop() {
|
|
511
|
+
if (this.socket) {
|
|
512
|
+
await new Promise((r) => this.socket.close(() => r()));
|
|
513
|
+
this.socket = void 0;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
};
|
|
517
|
+
|
|
518
|
+
// src/protocols/P2PProtocolAdapter.ts
|
|
519
|
+
var P2PProtocolAdapter = class _P2PProtocolAdapter {
|
|
520
|
+
protocol = "p2p";
|
|
521
|
+
capabilities = {
|
|
522
|
+
requestResponse: true,
|
|
523
|
+
streaming: true,
|
|
524
|
+
pubSub: true,
|
|
525
|
+
datagram: false,
|
|
526
|
+
peerToPeer: true,
|
|
527
|
+
signaling: true,
|
|
528
|
+
discovery: true
|
|
529
|
+
};
|
|
530
|
+
static peerHub = /* @__PURE__ */ new Map();
|
|
531
|
+
async expose(service) {
|
|
532
|
+
_P2PProtocolAdapter.peerHub.set(service.id, service);
|
|
533
|
+
return {
|
|
534
|
+
protocol: "p2p",
|
|
535
|
+
address: `p2p://${service.id}`,
|
|
536
|
+
capabilities: ["peerToPeer", "requestResponse", "pubSub"]
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
async send(endpoint, envelope) {
|
|
540
|
+
const peerId = endpoint.address.replace("p2p://", "");
|
|
541
|
+
const service = _P2PProtocolAdapter.peerHub.get(peerId);
|
|
542
|
+
if (!service) {
|
|
543
|
+
return {
|
|
544
|
+
id: `res-${Date.now()}`,
|
|
545
|
+
type: "response",
|
|
546
|
+
correlationId: envelope.id,
|
|
547
|
+
error: `Peer '${peerId}' not discovered or offline.`,
|
|
548
|
+
timestamp: Date.now()
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
try {
|
|
552
|
+
const res = await service.call(envelope.operation || "", envelope.payload);
|
|
553
|
+
return {
|
|
554
|
+
id: `res-${Date.now()}`,
|
|
555
|
+
type: "response",
|
|
556
|
+
correlationId: envelope.id,
|
|
557
|
+
payload: res,
|
|
558
|
+
timestamp: Date.now()
|
|
559
|
+
};
|
|
560
|
+
} catch (err) {
|
|
561
|
+
return {
|
|
562
|
+
id: `res-${Date.now()}`,
|
|
563
|
+
type: "response",
|
|
564
|
+
correlationId: envelope.id,
|
|
565
|
+
error: err.message || String(err),
|
|
566
|
+
timestamp: Date.now()
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
async stop() {
|
|
571
|
+
_P2PProtocolAdapter.peerHub.clear();
|
|
572
|
+
}
|
|
573
|
+
};
|
|
574
|
+
|
|
575
|
+
// src/transports/MemoryTransport.ts
|
|
576
|
+
var MemoryTransport = class {
|
|
577
|
+
handlers = /* @__PURE__ */ new Set();
|
|
578
|
+
onMessage(handler) {
|
|
579
|
+
this.handlers.add(handler);
|
|
580
|
+
return () => {
|
|
581
|
+
this.handlers.delete(handler);
|
|
582
|
+
};
|
|
583
|
+
}
|
|
584
|
+
async send(envelope) {
|
|
585
|
+
for (const handler of this.handlers) {
|
|
586
|
+
const res = await handler(envelope);
|
|
587
|
+
if (res) return res;
|
|
588
|
+
}
|
|
589
|
+
return {
|
|
590
|
+
id: `res-${Date.now()}`,
|
|
591
|
+
type: "response",
|
|
592
|
+
correlationId: envelope.id,
|
|
593
|
+
payload: null,
|
|
594
|
+
timestamp: Date.now()
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
};
|
|
598
|
+
|
|
599
|
+
// src/registry/ServiceRegistry.ts
|
|
600
|
+
var ServiceRegistry = class {
|
|
601
|
+
services = /* @__PURE__ */ new Map();
|
|
602
|
+
register(definition, endpoints = []) {
|
|
603
|
+
this.services.set(definition.id, {
|
|
604
|
+
definition,
|
|
605
|
+
endpoints,
|
|
606
|
+
registeredAt: Date.now()
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
unregister(serviceId) {
|
|
610
|
+
this.services.delete(serviceId);
|
|
611
|
+
}
|
|
612
|
+
get(serviceId) {
|
|
613
|
+
return this.services.get(serviceId);
|
|
614
|
+
}
|
|
615
|
+
list() {
|
|
616
|
+
return Array.from(this.services.values());
|
|
617
|
+
}
|
|
618
|
+
findByCapability(capabilityName) {
|
|
619
|
+
return this.list().filter(
|
|
620
|
+
(record) => record.definition.capabilities?.some((cap) => cap.name === capabilityName)
|
|
621
|
+
);
|
|
622
|
+
}
|
|
623
|
+
};
|
|
624
|
+
|
|
625
|
+
// src/runtime/ServiceRuntime.ts
|
|
626
|
+
var ServiceRuntime = class {
|
|
627
|
+
instances = /* @__PURE__ */ new Map();
|
|
628
|
+
registry;
|
|
629
|
+
constructor(registry) {
|
|
630
|
+
this.registry = registry || new ServiceRegistry();
|
|
631
|
+
}
|
|
632
|
+
register(service) {
|
|
633
|
+
this.instances.set(service.id, service);
|
|
634
|
+
this.registry.register(service.getDefinition());
|
|
635
|
+
return this;
|
|
636
|
+
}
|
|
637
|
+
get(serviceId) {
|
|
638
|
+
return this.instances.get(serviceId);
|
|
639
|
+
}
|
|
640
|
+
async execute(target, operation, input, ctx) {
|
|
641
|
+
const service = this.instances.get(target);
|
|
642
|
+
if (!service) {
|
|
643
|
+
throw new Error(`[ServiceRuntime] Target service '${target}' not found.`);
|
|
644
|
+
}
|
|
645
|
+
return await service.call(operation, input, ctx);
|
|
646
|
+
}
|
|
647
|
+
async startAll() {
|
|
648
|
+
for (const service of this.instances.values()) {
|
|
649
|
+
await service.start();
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
async stopAll() {
|
|
653
|
+
for (const service of this.instances.values()) {
|
|
654
|
+
await service.stop();
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
};
|
|
658
|
+
|
|
659
|
+
// src/discovery/ServiceDiscovery.ts
|
|
660
|
+
var ServiceDiscovery = class {
|
|
661
|
+
peers = /* @__PURE__ */ new Map();
|
|
662
|
+
registerPeer(id, name, endpoints) {
|
|
663
|
+
this.peers.set(id, {
|
|
664
|
+
id,
|
|
665
|
+
name,
|
|
666
|
+
endpoints,
|
|
667
|
+
lastSeen: Date.now()
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
getPeers() {
|
|
671
|
+
return Array.from(this.peers.values());
|
|
672
|
+
}
|
|
673
|
+
findPeer(id) {
|
|
674
|
+
return this.peers.get(id);
|
|
675
|
+
}
|
|
676
|
+
};
|
|
677
|
+
|
|
678
|
+
// src/connectivity/ProtocolResolver.ts
|
|
679
|
+
var ProtocolResolver = class {
|
|
680
|
+
static selectProtocol(requiredCapabilities, availableEndpoints) {
|
|
681
|
+
return availableEndpoints.find(
|
|
682
|
+
(ep) => requiredCapabilities.every((req) => ep.capabilities.includes(req))
|
|
683
|
+
);
|
|
684
|
+
}
|
|
685
|
+
static getSupportedProtocols(definition) {
|
|
686
|
+
return definition.protocols || ["http"];
|
|
687
|
+
}
|
|
688
|
+
};
|
|
689
|
+
export {
|
|
690
|
+
HttpProtocolAdapter,
|
|
691
|
+
LifecycleManager,
|
|
692
|
+
MemoryTransport,
|
|
693
|
+
P2PProtocolAdapter,
|
|
694
|
+
ProtocolResolver,
|
|
695
|
+
ServiceDiscovery,
|
|
696
|
+
ServiceEventBus,
|
|
697
|
+
ServiceInstance,
|
|
698
|
+
ServiceProxy,
|
|
699
|
+
ServiceRegistry,
|
|
700
|
+
ServiceRuntime,
|
|
701
|
+
ServiceStateStore,
|
|
702
|
+
UdpProtocolAdapter,
|
|
703
|
+
WebSocketProtocolAdapter,
|
|
704
|
+
createService,
|
|
705
|
+
createServiceDefinition,
|
|
706
|
+
createServiceProxy
|
|
707
|
+
};
|