@hypen-space/core 0.4.14 → 0.4.16

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.
Files changed (46) hide show
  1. package/dist/app.js +9 -83
  2. package/dist/app.js.map +3 -3
  3. package/dist/components/builtin.js +9 -83
  4. package/dist/components/builtin.js.map +3 -3
  5. package/dist/context.js +9 -4
  6. package/dist/context.js.map +3 -3
  7. package/dist/discovery.js +250 -250
  8. package/dist/discovery.js.map +5 -5
  9. package/dist/disposable.js +9 -4
  10. package/dist/disposable.js.map +3 -3
  11. package/dist/engine.browser.js +167 -131
  12. package/dist/engine.browser.js.map +3 -3
  13. package/dist/engine.js +2 -2
  14. package/dist/engine.js.map +2 -2
  15. package/dist/events.js +9 -4
  16. package/dist/events.js.map +3 -3
  17. package/dist/index.browser.js +278 -154
  18. package/dist/index.browser.js.map +7 -6
  19. package/dist/index.js +427 -434
  20. package/dist/index.js.map +10 -10
  21. package/dist/loader.js +2 -2
  22. package/dist/loader.js.map +2 -2
  23. package/dist/logger.js +9 -4
  24. package/dist/logger.js.map +3 -3
  25. package/dist/plugin.js +351 -6
  26. package/dist/plugin.js.map +5 -4
  27. package/dist/remote/client.js +9 -94
  28. package/dist/remote/client.js.map +3 -3
  29. package/dist/remote/index.js +481 -342
  30. package/dist/remote/index.js.map +7 -6
  31. package/dist/remote/server.js +481 -331
  32. package/dist/remote/server.js.map +7 -6
  33. package/dist/renderer.js +9 -4
  34. package/dist/renderer.js.map +3 -3
  35. package/dist/resolver.js +350 -5
  36. package/dist/resolver.js.map +4 -3
  37. package/dist/router.js +9 -4
  38. package/dist/router.js.map +3 -3
  39. package/dist/state.js +8 -3
  40. package/dist/state.js.map +2 -2
  41. package/package.json +1 -1
  42. package/src/logger.ts +1 -1
  43. package/wasm-browser/hypen_engine_bg.wasm +0 -0
  44. package/wasm-browser/package.json +1 -1
  45. package/wasm-node/hypen_engine_bg.wasm +0 -0
  46. package/wasm-node/package.json +1 -1
@@ -1,4 +1,3 @@
1
- import { createRequire } from "node:module";
2
1
  var __create = Object.create;
3
2
  var __getProtoOf = Object.getPrototypeOf;
4
3
  var __defProp = Object.defineProperty;
@@ -25,7 +24,13 @@ var __export = (target, all) => {
25
24
  });
26
25
  };
27
26
  var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
28
- var __require = /* @__PURE__ */ createRequire(import.meta.url);
27
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
28
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
29
+ }) : x)(function(x) {
30
+ if (typeof require !== "undefined")
31
+ return require.apply(this, arguments);
32
+ throw Error('Dynamic require of "' + x + '" is not supported');
33
+ });
29
34
 
30
35
  // src/state.ts
31
36
  function deepClone(obj) {
@@ -428,7 +433,7 @@ var init_logger = __esm(() => {
428
433
  error: "\x1B[31m"
429
434
  };
430
435
  config = {
431
- level: isProduction() ? "error" : "debug",
436
+ level: isProduction() ? "error" : "info",
432
437
  colors: true,
433
438
  timestamps: false
434
439
  };
@@ -481,85 +486,6 @@ function Ok(value) {
481
486
  function Err(error) {
482
487
  return { ok: false, error };
483
488
  }
484
- function isOk(result) {
485
- return result.ok;
486
- }
487
- function isErr(result) {
488
- return !result.ok;
489
- }
490
- async function fromPromise(promise, mapError) {
491
- try {
492
- const value = await promise;
493
- return Ok(value);
494
- } catch (e) {
495
- if (mapError) {
496
- return Err(mapError(e));
497
- }
498
- return Err(e);
499
- }
500
- }
501
- function fromTry(fn, mapError) {
502
- try {
503
- return Ok(fn());
504
- } catch (e) {
505
- if (mapError) {
506
- return Err(mapError(e));
507
- }
508
- return Err(e);
509
- }
510
- }
511
- function map(result, fn) {
512
- if (result.ok) {
513
- return Ok(fn(result.value));
514
- }
515
- return result;
516
- }
517
- function mapErr(result, fn) {
518
- if (!result.ok) {
519
- return Err(fn(result.error));
520
- }
521
- return result;
522
- }
523
- function flatMap(result, fn) {
524
- if (result.ok) {
525
- return fn(result.value);
526
- }
527
- return result;
528
- }
529
- function unwrap(result) {
530
- if (result.ok) {
531
- return result.value;
532
- }
533
- throw result.error;
534
- }
535
- function unwrapOr(result, defaultValue) {
536
- if (result.ok) {
537
- return result.value;
538
- }
539
- return defaultValue;
540
- }
541
- function unwrapOrElse(result, fn) {
542
- if (result.ok) {
543
- return result.value;
544
- }
545
- return fn(result.error);
546
- }
547
- function match(result, handlers) {
548
- if (result.ok) {
549
- return handlers.ok(result.value);
550
- }
551
- return handlers.err(result.error);
552
- }
553
- function all(results) {
554
- const values = [];
555
- for (const result of results) {
556
- if (!result.ok) {
557
- return result;
558
- }
559
- values.push(result.value);
560
- }
561
- return Ok(values);
562
- }
563
489
  function classifyEngineError(err) {
564
490
  const message = err instanceof Error ? err.message : String(err);
565
491
  if (message.startsWith("Parse error:")) {
@@ -944,6 +870,346 @@ var init_app = __esm(() => {
944
870
  app = new HypenApp;
945
871
  });
946
872
 
873
+ // node:path
874
+ var exports_path = {};
875
+ __export(exports_path, {
876
+ sep: () => sep,
877
+ resolve: () => resolve,
878
+ relative: () => relative,
879
+ posix: () => posix,
880
+ parse: () => parse,
881
+ normalize: () => normalize,
882
+ join: () => join,
883
+ isAbsolute: () => isAbsolute,
884
+ format: () => format,
885
+ extname: () => extname,
886
+ dirname: () => dirname,
887
+ delimiter: () => delimiter,
888
+ default: () => path_default,
889
+ basename: () => basename,
890
+ _makeLong: () => _makeLong
891
+ });
892
+ function assertPath(path) {
893
+ if (typeof path !== "string")
894
+ throw new TypeError("Path must be a string. Received " + JSON.stringify(path));
895
+ }
896
+ function normalizeStringPosix(path, allowAboveRoot) {
897
+ var res = "", lastSegmentLength = 0, lastSlash = -1, dots = 0, code;
898
+ for (var i = 0;i <= path.length; ++i) {
899
+ if (i < path.length)
900
+ code = path.charCodeAt(i);
901
+ else if (code === 47)
902
+ break;
903
+ else
904
+ code = 47;
905
+ if (code === 47) {
906
+ if (lastSlash === i - 1 || dots === 1)
907
+ ;
908
+ else if (lastSlash !== i - 1 && dots === 2) {
909
+ if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46 || res.charCodeAt(res.length - 2) !== 46) {
910
+ if (res.length > 2) {
911
+ var lastSlashIndex = res.lastIndexOf("/");
912
+ if (lastSlashIndex !== res.length - 1) {
913
+ if (lastSlashIndex === -1)
914
+ res = "", lastSegmentLength = 0;
915
+ else
916
+ res = res.slice(0, lastSlashIndex), lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
917
+ lastSlash = i, dots = 0;
918
+ continue;
919
+ }
920
+ } else if (res.length === 2 || res.length === 1) {
921
+ res = "", lastSegmentLength = 0, lastSlash = i, dots = 0;
922
+ continue;
923
+ }
924
+ }
925
+ if (allowAboveRoot) {
926
+ if (res.length > 0)
927
+ res += "/..";
928
+ else
929
+ res = "..";
930
+ lastSegmentLength = 2;
931
+ }
932
+ } else {
933
+ if (res.length > 0)
934
+ res += "/" + path.slice(lastSlash + 1, i);
935
+ else
936
+ res = path.slice(lastSlash + 1, i);
937
+ lastSegmentLength = i - lastSlash - 1;
938
+ }
939
+ lastSlash = i, dots = 0;
940
+ } else if (code === 46 && dots !== -1)
941
+ ++dots;
942
+ else
943
+ dots = -1;
944
+ }
945
+ return res;
946
+ }
947
+ function _format(sep, pathObject) {
948
+ var dir = pathObject.dir || pathObject.root, base = pathObject.base || (pathObject.name || "") + (pathObject.ext || "");
949
+ if (!dir)
950
+ return base;
951
+ if (dir === pathObject.root)
952
+ return dir + base;
953
+ return dir + sep + base;
954
+ }
955
+ function resolve() {
956
+ var resolvedPath = "", resolvedAbsolute = false, cwd;
957
+ for (var i = arguments.length - 1;i >= -1 && !resolvedAbsolute; i--) {
958
+ var path;
959
+ if (i >= 0)
960
+ path = arguments[i];
961
+ else {
962
+ if (cwd === undefined)
963
+ cwd = process.cwd();
964
+ path = cwd;
965
+ }
966
+ if (assertPath(path), path.length === 0)
967
+ continue;
968
+ resolvedPath = path + "/" + resolvedPath, resolvedAbsolute = path.charCodeAt(0) === 47;
969
+ }
970
+ if (resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute), resolvedAbsolute)
971
+ if (resolvedPath.length > 0)
972
+ return "/" + resolvedPath;
973
+ else
974
+ return "/";
975
+ else if (resolvedPath.length > 0)
976
+ return resolvedPath;
977
+ else
978
+ return ".";
979
+ }
980
+ function normalize(path) {
981
+ if (assertPath(path), path.length === 0)
982
+ return ".";
983
+ var isAbsolute = path.charCodeAt(0) === 47, trailingSeparator = path.charCodeAt(path.length - 1) === 47;
984
+ if (path = normalizeStringPosix(path, !isAbsolute), path.length === 0 && !isAbsolute)
985
+ path = ".";
986
+ if (path.length > 0 && trailingSeparator)
987
+ path += "/";
988
+ if (isAbsolute)
989
+ return "/" + path;
990
+ return path;
991
+ }
992
+ function isAbsolute(path) {
993
+ return assertPath(path), path.length > 0 && path.charCodeAt(0) === 47;
994
+ }
995
+ function join() {
996
+ if (arguments.length === 0)
997
+ return ".";
998
+ var joined;
999
+ for (var i = 0;i < arguments.length; ++i) {
1000
+ var arg = arguments[i];
1001
+ if (assertPath(arg), arg.length > 0)
1002
+ if (joined === undefined)
1003
+ joined = arg;
1004
+ else
1005
+ joined += "/" + arg;
1006
+ }
1007
+ if (joined === undefined)
1008
+ return ".";
1009
+ return normalize(joined);
1010
+ }
1011
+ function relative(from, to) {
1012
+ if (assertPath(from), assertPath(to), from === to)
1013
+ return "";
1014
+ if (from = resolve(from), to = resolve(to), from === to)
1015
+ return "";
1016
+ var fromStart = 1;
1017
+ for (;fromStart < from.length; ++fromStart)
1018
+ if (from.charCodeAt(fromStart) !== 47)
1019
+ break;
1020
+ var fromEnd = from.length, fromLen = fromEnd - fromStart, toStart = 1;
1021
+ for (;toStart < to.length; ++toStart)
1022
+ if (to.charCodeAt(toStart) !== 47)
1023
+ break;
1024
+ var toEnd = to.length, toLen = toEnd - toStart, length = fromLen < toLen ? fromLen : toLen, lastCommonSep = -1, i = 0;
1025
+ for (;i <= length; ++i) {
1026
+ if (i === length) {
1027
+ if (toLen > length) {
1028
+ if (to.charCodeAt(toStart + i) === 47)
1029
+ return to.slice(toStart + i + 1);
1030
+ else if (i === 0)
1031
+ return to.slice(toStart + i);
1032
+ } else if (fromLen > length) {
1033
+ if (from.charCodeAt(fromStart + i) === 47)
1034
+ lastCommonSep = i;
1035
+ else if (i === 0)
1036
+ lastCommonSep = 0;
1037
+ }
1038
+ break;
1039
+ }
1040
+ var fromCode = from.charCodeAt(fromStart + i), toCode = to.charCodeAt(toStart + i);
1041
+ if (fromCode !== toCode)
1042
+ break;
1043
+ else if (fromCode === 47)
1044
+ lastCommonSep = i;
1045
+ }
1046
+ var out = "";
1047
+ for (i = fromStart + lastCommonSep + 1;i <= fromEnd; ++i)
1048
+ if (i === fromEnd || from.charCodeAt(i) === 47)
1049
+ if (out.length === 0)
1050
+ out += "..";
1051
+ else
1052
+ out += "/..";
1053
+ if (out.length > 0)
1054
+ return out + to.slice(toStart + lastCommonSep);
1055
+ else {
1056
+ if (toStart += lastCommonSep, to.charCodeAt(toStart) === 47)
1057
+ ++toStart;
1058
+ return to.slice(toStart);
1059
+ }
1060
+ }
1061
+ function _makeLong(path) {
1062
+ return path;
1063
+ }
1064
+ function dirname(path) {
1065
+ if (assertPath(path), path.length === 0)
1066
+ return ".";
1067
+ var code = path.charCodeAt(0), hasRoot = code === 47, end = -1, matchedSlash = true;
1068
+ for (var i = path.length - 1;i >= 1; --i)
1069
+ if (code = path.charCodeAt(i), code === 47) {
1070
+ if (!matchedSlash) {
1071
+ end = i;
1072
+ break;
1073
+ }
1074
+ } else
1075
+ matchedSlash = false;
1076
+ if (end === -1)
1077
+ return hasRoot ? "/" : ".";
1078
+ if (hasRoot && end === 1)
1079
+ return "//";
1080
+ return path.slice(0, end);
1081
+ }
1082
+ function basename(path, ext) {
1083
+ if (ext !== undefined && typeof ext !== "string")
1084
+ throw new TypeError('"ext" argument must be a string');
1085
+ assertPath(path);
1086
+ var start = 0, end = -1, matchedSlash = true, i;
1087
+ if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
1088
+ if (ext.length === path.length && ext === path)
1089
+ return "";
1090
+ var extIdx = ext.length - 1, firstNonSlashEnd = -1;
1091
+ for (i = path.length - 1;i >= 0; --i) {
1092
+ var code = path.charCodeAt(i);
1093
+ if (code === 47) {
1094
+ if (!matchedSlash) {
1095
+ start = i + 1;
1096
+ break;
1097
+ }
1098
+ } else {
1099
+ if (firstNonSlashEnd === -1)
1100
+ matchedSlash = false, firstNonSlashEnd = i + 1;
1101
+ if (extIdx >= 0)
1102
+ if (code === ext.charCodeAt(extIdx)) {
1103
+ if (--extIdx === -1)
1104
+ end = i;
1105
+ } else
1106
+ extIdx = -1, end = firstNonSlashEnd;
1107
+ }
1108
+ }
1109
+ if (start === end)
1110
+ end = firstNonSlashEnd;
1111
+ else if (end === -1)
1112
+ end = path.length;
1113
+ return path.slice(start, end);
1114
+ } else {
1115
+ for (i = path.length - 1;i >= 0; --i)
1116
+ if (path.charCodeAt(i) === 47) {
1117
+ if (!matchedSlash) {
1118
+ start = i + 1;
1119
+ break;
1120
+ }
1121
+ } else if (end === -1)
1122
+ matchedSlash = false, end = i + 1;
1123
+ if (end === -1)
1124
+ return "";
1125
+ return path.slice(start, end);
1126
+ }
1127
+ }
1128
+ function extname(path) {
1129
+ assertPath(path);
1130
+ var startDot = -1, startPart = 0, end = -1, matchedSlash = true, preDotState = 0;
1131
+ for (var i = path.length - 1;i >= 0; --i) {
1132
+ var code = path.charCodeAt(i);
1133
+ if (code === 47) {
1134
+ if (!matchedSlash) {
1135
+ startPart = i + 1;
1136
+ break;
1137
+ }
1138
+ continue;
1139
+ }
1140
+ if (end === -1)
1141
+ matchedSlash = false, end = i + 1;
1142
+ if (code === 46) {
1143
+ if (startDot === -1)
1144
+ startDot = i;
1145
+ else if (preDotState !== 1)
1146
+ preDotState = 1;
1147
+ } else if (startDot !== -1)
1148
+ preDotState = -1;
1149
+ }
1150
+ if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)
1151
+ return "";
1152
+ return path.slice(startDot, end);
1153
+ }
1154
+ function format(pathObject) {
1155
+ if (pathObject === null || typeof pathObject !== "object")
1156
+ throw new TypeError('The "pathObject" argument must be of type Object. Received type ' + typeof pathObject);
1157
+ return _format("/", pathObject);
1158
+ }
1159
+ function parse(path) {
1160
+ assertPath(path);
1161
+ var ret = { root: "", dir: "", base: "", ext: "", name: "" };
1162
+ if (path.length === 0)
1163
+ return ret;
1164
+ var code = path.charCodeAt(0), isAbsolute2 = code === 47, start;
1165
+ if (isAbsolute2)
1166
+ ret.root = "/", start = 1;
1167
+ else
1168
+ start = 0;
1169
+ var startDot = -1, startPart = 0, end = -1, matchedSlash = true, i = path.length - 1, preDotState = 0;
1170
+ for (;i >= start; --i) {
1171
+ if (code = path.charCodeAt(i), code === 47) {
1172
+ if (!matchedSlash) {
1173
+ startPart = i + 1;
1174
+ break;
1175
+ }
1176
+ continue;
1177
+ }
1178
+ if (end === -1)
1179
+ matchedSlash = false, end = i + 1;
1180
+ if (code === 46) {
1181
+ if (startDot === -1)
1182
+ startDot = i;
1183
+ else if (preDotState !== 1)
1184
+ preDotState = 1;
1185
+ } else if (startDot !== -1)
1186
+ preDotState = -1;
1187
+ }
1188
+ if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
1189
+ if (end !== -1)
1190
+ if (startPart === 0 && isAbsolute2)
1191
+ ret.base = ret.name = path.slice(1, end);
1192
+ else
1193
+ ret.base = ret.name = path.slice(startPart, end);
1194
+ } else {
1195
+ if (startPart === 0 && isAbsolute2)
1196
+ ret.name = path.slice(1, startDot), ret.base = path.slice(1, end);
1197
+ else
1198
+ ret.name = path.slice(startPart, startDot), ret.base = path.slice(startPart, end);
1199
+ ret.ext = path.slice(startDot, end);
1200
+ }
1201
+ if (startPart > 0)
1202
+ ret.dir = path.slice(0, startPart - 1);
1203
+ else if (isAbsolute2)
1204
+ ret.dir = "/";
1205
+ return ret;
1206
+ }
1207
+ var sep = "/", delimiter = ":", posix, path_default;
1208
+ var init_path = __esm(() => {
1209
+ posix = ((p) => (p.posix = p, p))({ resolve, normalize, isAbsolute, join, relative, _makeLong, dirname, basename, extname, format, parse, sep, delimiter, win32: null, posix: null });
1210
+ path_default = posix;
1211
+ });
1212
+
947
1213
  // src/disposable.ts
948
1214
  init_logger();
949
1215
  var log3 = frameworkLoggers.lifecycle;
@@ -1160,17 +1426,6 @@ async function retry(fn, options = {}) {
1160
1426
  }
1161
1427
  throw lastError;
1162
1428
  }
1163
- async function retryResult(fn, options = {}) {
1164
- try {
1165
- const value = await retry(fn, options);
1166
- return Ok(value);
1167
- } catch (e) {
1168
- return Err(e instanceof Error ? e : new Error(String(e)));
1169
- }
1170
- }
1171
- function withRetry(fn, options = {}) {
1172
- return (...args) => retry(() => fn(...args), options);
1173
- }
1174
1429
  var RetryConditions = {
1175
1430
  networkErrors: (error) => {
1176
1431
  const message = error.message.toLowerCase();
@@ -1591,10 +1846,140 @@ class Engine {
1591
1846
  }
1592
1847
  }
1593
1848
 
1849
+ // src/remote/server.ts
1850
+ init_app();
1851
+
1852
+ // src/remote/session.ts
1853
+ class SessionManager {
1854
+ activeSessions = new Map;
1855
+ pendingSessions = new Map;
1856
+ sessionConnections = new Map;
1857
+ config;
1858
+ constructor(config2 = {}) {
1859
+ this.config = {
1860
+ ttl: config2.ttl ?? 3600,
1861
+ concurrent: config2.concurrent ?? "kick-old",
1862
+ generateId: config2.generateId ?? (() => crypto.randomUUID())
1863
+ };
1864
+ }
1865
+ getTtl() {
1866
+ return this.config.ttl;
1867
+ }
1868
+ getConcurrentPolicy() {
1869
+ return this.config.concurrent;
1870
+ }
1871
+ createSession(props) {
1872
+ const now = new Date;
1873
+ const session = {
1874
+ id: this.config.generateId(),
1875
+ ttl: this.config.ttl,
1876
+ createdAt: now,
1877
+ lastConnectedAt: now,
1878
+ props
1879
+ };
1880
+ this.activeSessions.set(session.id, session);
1881
+ return session;
1882
+ }
1883
+ getActiveSession(id) {
1884
+ return this.activeSessions.get(id) ?? null;
1885
+ }
1886
+ getPendingSession(id) {
1887
+ return this.pendingSessions.get(id) ?? null;
1888
+ }
1889
+ hasSession(id) {
1890
+ return this.activeSessions.has(id) || this.pendingSessions.has(id);
1891
+ }
1892
+ suspendSession(sessionId, savedState, onExpire) {
1893
+ const session = this.activeSessions.get(sessionId);
1894
+ if (!session)
1895
+ return;
1896
+ this.activeSessions.delete(sessionId);
1897
+ const expiryTimer = setTimeout(async () => {
1898
+ const pending = this.pendingSessions.get(sessionId);
1899
+ if (pending) {
1900
+ this.pendingSessions.delete(sessionId);
1901
+ await onExpire(pending.session);
1902
+ }
1903
+ }, session.ttl * 1000);
1904
+ this.pendingSessions.set(sessionId, {
1905
+ session,
1906
+ savedState,
1907
+ expiryTimer
1908
+ });
1909
+ }
1910
+ resumeSession(sessionId) {
1911
+ const pending = this.pendingSessions.get(sessionId);
1912
+ if (!pending)
1913
+ return null;
1914
+ clearTimeout(pending.expiryTimer);
1915
+ this.pendingSessions.delete(sessionId);
1916
+ pending.session.lastConnectedAt = new Date;
1917
+ this.activeSessions.set(sessionId, pending.session);
1918
+ return {
1919
+ session: pending.session,
1920
+ savedState: pending.savedState
1921
+ };
1922
+ }
1923
+ destroySession(sessionId) {
1924
+ this.activeSessions.delete(sessionId);
1925
+ const pending = this.pendingSessions.get(sessionId);
1926
+ if (pending) {
1927
+ clearTimeout(pending.expiryTimer);
1928
+ this.pendingSessions.delete(sessionId);
1929
+ }
1930
+ this.sessionConnections.delete(sessionId);
1931
+ }
1932
+ trackConnection(sessionId, ws) {
1933
+ let connections = this.sessionConnections.get(sessionId);
1934
+ if (!connections) {
1935
+ connections = new Set;
1936
+ this.sessionConnections.set(sessionId, connections);
1937
+ }
1938
+ connections.add(ws);
1939
+ }
1940
+ untrackConnection(sessionId, ws) {
1941
+ const connections = this.sessionConnections.get(sessionId);
1942
+ if (connections) {
1943
+ connections.delete(ws);
1944
+ if (connections.size === 0) {
1945
+ this.sessionConnections.delete(sessionId);
1946
+ }
1947
+ }
1948
+ }
1949
+ getConnections(sessionId) {
1950
+ return this.sessionConnections.get(sessionId);
1951
+ }
1952
+ getConnectionCount(sessionId) {
1953
+ return this.sessionConnections.get(sessionId)?.size ?? 0;
1954
+ }
1955
+ getStats() {
1956
+ let totalConnections = 0;
1957
+ for (const connections of this.sessionConnections.values()) {
1958
+ totalConnections += connections.size;
1959
+ }
1960
+ return {
1961
+ activeSessions: this.activeSessions.size,
1962
+ pendingSessions: this.pendingSessions.size,
1963
+ totalConnections
1964
+ };
1965
+ }
1966
+ destroy() {
1967
+ for (const pending of this.pendingSessions.values()) {
1968
+ clearTimeout(pending.expiryTimer);
1969
+ }
1970
+ this.activeSessions.clear();
1971
+ this.pendingSessions.clear();
1972
+ this.sessionConnections.clear();
1973
+ }
1974
+ }
1975
+
1976
+ // src/remote/server.ts
1977
+ init_logger();
1978
+
1594
1979
  // src/discovery.ts
1980
+ init_path();
1595
1981
  init_logger();
1596
- import { existsSync, readdirSync, readFileSync, watch } from "fs";
1597
- import { join, basename, resolve, relative } from "path";
1982
+ var {existsSync, readdirSync, readFileSync, watch} = (() => ({}));
1598
1983
  async function discoverComponents(baseDir, options = {}) {
1599
1984
  const {
1600
1985
  patterns = ["single-file", "folder", "sibling", "index"],
@@ -1763,254 +2148,8 @@ async function loadDiscoveredComponents(components) {
1763
2148
  }
1764
2149
  return loaded;
1765
2150
  }
1766
- function watchComponents(baseDir, options = {}) {
1767
- const resolvedDir = resolve(baseDir);
1768
- const {
1769
- onChange,
1770
- onAdd,
1771
- onRemove,
1772
- onUpdate,
1773
- debug = false,
1774
- ...discoveryOptions
1775
- } = options;
1776
- const log6 = debug ? (...args) => frameworkLoggers.discovery.debug("[watch]", ...args) : () => {};
1777
- let currentComponents = new Map;
1778
- let debounceTimer = null;
1779
- const initialScan = async () => {
1780
- const components = await discoverComponents(resolvedDir, discoveryOptions);
1781
- currentComponents = new Map(components.map((c) => [c.name, c]));
1782
- onChange?.(components);
1783
- };
1784
- const rescan = async () => {
1785
- if (debounceTimer) {
1786
- clearTimeout(debounceTimer);
1787
- }
1788
- debounceTimer = setTimeout(async () => {
1789
- log6("Rescanning...");
1790
- const newComponents = await discoverComponents(resolvedDir, discoveryOptions);
1791
- const newMap = new Map(newComponents.map((c) => [c.name, c]));
1792
- for (const [name, component] of newMap) {
1793
- const existing = currentComponents.get(name);
1794
- if (!existing) {
1795
- log6("Added:", name);
1796
- onAdd?.(component);
1797
- } else if (existing.template !== component.template || existing.modulePath !== component.modulePath) {
1798
- log6("Updated:", name);
1799
- onUpdate?.(component);
1800
- }
1801
- }
1802
- for (const name of currentComponents.keys()) {
1803
- if (!newMap.has(name)) {
1804
- log6("Removed:", name);
1805
- onRemove?.(name);
1806
- }
1807
- }
1808
- currentComponents = newMap;
1809
- onChange?.(newComponents);
1810
- }, 100);
1811
- };
1812
- const watcher = watch(resolvedDir, { recursive: true }, (event, filename) => {
1813
- if (!filename)
1814
- return;
1815
- if (filename.endsWith(".hypen") || filename.endsWith(".ts")) {
1816
- log6("File changed:", filename);
1817
- rescan();
1818
- }
1819
- });
1820
- initialScan();
1821
- return {
1822
- stop: () => {
1823
- watcher.close();
1824
- if (debounceTimer) {
1825
- clearTimeout(debounceTimer);
1826
- }
1827
- }
1828
- };
1829
- }
1830
- async function generateComponentsCode(baseDir, options = {}) {
1831
- const components = await discoverComponents(baseDir, options);
1832
- const resolvedDir = resolve(baseDir);
1833
- const outputBase = options.outputDir ? resolve(options.outputDir) : resolvedDir;
1834
- let code = `/**
1835
- * Auto-generated component imports
1836
- * Generated by @hypen-space/core discovery
1837
- */
1838
-
1839
- `;
1840
- for (const component of components) {
1841
- let importPath = null;
1842
- if (component.modulePath) {
1843
- const rel = relative(outputBase, component.modulePath).replace(/\.ts$/, ".js");
1844
- importPath = rel.startsWith(".") ? rel : "./" + rel;
1845
- }
1846
- if (importPath) {
1847
- code += `import ${component.name}Module from "${importPath}";
1848
- `;
1849
- }
1850
- }
1851
- code += `
1852
- import { app } from "@hypen-space/core";
1853
-
1854
- `;
1855
- for (const component of components) {
1856
- if (component.isSingleFile) {
1857
- code += `export const ${component.name} = {
1858
- module: ${component.name}Module,
1859
- template: ${component.name}Module.template,
1860
- };
1861
-
1862
- `;
1863
- } else if (component.hasModule) {
1864
- const templateJson = JSON.stringify(component.template);
1865
- code += `export const ${component.name} = {
1866
- module: ${component.name}Module,
1867
- template: ${templateJson},
1868
- };
1869
-
1870
- `;
1871
- } else {
1872
- const templateJson = JSON.stringify(component.template);
1873
- code += `const ${component.name}Module = app.defineState({}).build();
1874
- export const ${component.name} = {
1875
- module: ${component.name}Module,
1876
- template: ${templateJson},
1877
- };
1878
-
1879
- `;
1880
- }
1881
- }
1882
- return code;
1883
- }
1884
2151
 
1885
2152
  // src/remote/server.ts
1886
- init_app();
1887
-
1888
- // src/remote/session.ts
1889
- class SessionManager {
1890
- activeSessions = new Map;
1891
- pendingSessions = new Map;
1892
- sessionConnections = new Map;
1893
- config;
1894
- constructor(config2 = {}) {
1895
- this.config = {
1896
- ttl: config2.ttl ?? 3600,
1897
- concurrent: config2.concurrent ?? "kick-old",
1898
- generateId: config2.generateId ?? (() => crypto.randomUUID())
1899
- };
1900
- }
1901
- getTtl() {
1902
- return this.config.ttl;
1903
- }
1904
- getConcurrentPolicy() {
1905
- return this.config.concurrent;
1906
- }
1907
- createSession(props) {
1908
- const now = new Date;
1909
- const session = {
1910
- id: this.config.generateId(),
1911
- ttl: this.config.ttl,
1912
- createdAt: now,
1913
- lastConnectedAt: now,
1914
- props
1915
- };
1916
- this.activeSessions.set(session.id, session);
1917
- return session;
1918
- }
1919
- getActiveSession(id) {
1920
- return this.activeSessions.get(id) ?? null;
1921
- }
1922
- getPendingSession(id) {
1923
- return this.pendingSessions.get(id) ?? null;
1924
- }
1925
- hasSession(id) {
1926
- return this.activeSessions.has(id) || this.pendingSessions.has(id);
1927
- }
1928
- suspendSession(sessionId, savedState, onExpire) {
1929
- const session = this.activeSessions.get(sessionId);
1930
- if (!session)
1931
- return;
1932
- this.activeSessions.delete(sessionId);
1933
- const expiryTimer = setTimeout(async () => {
1934
- const pending = this.pendingSessions.get(sessionId);
1935
- if (pending) {
1936
- this.pendingSessions.delete(sessionId);
1937
- await onExpire(pending.session);
1938
- }
1939
- }, session.ttl * 1000);
1940
- this.pendingSessions.set(sessionId, {
1941
- session,
1942
- savedState,
1943
- expiryTimer
1944
- });
1945
- }
1946
- resumeSession(sessionId) {
1947
- const pending = this.pendingSessions.get(sessionId);
1948
- if (!pending)
1949
- return null;
1950
- clearTimeout(pending.expiryTimer);
1951
- this.pendingSessions.delete(sessionId);
1952
- pending.session.lastConnectedAt = new Date;
1953
- this.activeSessions.set(sessionId, pending.session);
1954
- return {
1955
- session: pending.session,
1956
- savedState: pending.savedState
1957
- };
1958
- }
1959
- destroySession(sessionId) {
1960
- this.activeSessions.delete(sessionId);
1961
- const pending = this.pendingSessions.get(sessionId);
1962
- if (pending) {
1963
- clearTimeout(pending.expiryTimer);
1964
- this.pendingSessions.delete(sessionId);
1965
- }
1966
- this.sessionConnections.delete(sessionId);
1967
- }
1968
- trackConnection(sessionId, ws) {
1969
- let connections = this.sessionConnections.get(sessionId);
1970
- if (!connections) {
1971
- connections = new Set;
1972
- this.sessionConnections.set(sessionId, connections);
1973
- }
1974
- connections.add(ws);
1975
- }
1976
- untrackConnection(sessionId, ws) {
1977
- const connections = this.sessionConnections.get(sessionId);
1978
- if (connections) {
1979
- connections.delete(ws);
1980
- if (connections.size === 0) {
1981
- this.sessionConnections.delete(sessionId);
1982
- }
1983
- }
1984
- }
1985
- getConnections(sessionId) {
1986
- return this.sessionConnections.get(sessionId);
1987
- }
1988
- getConnectionCount(sessionId) {
1989
- return this.sessionConnections.get(sessionId)?.size ?? 0;
1990
- }
1991
- getStats() {
1992
- let totalConnections = 0;
1993
- for (const connections of this.sessionConnections.values()) {
1994
- totalConnections += connections.size;
1995
- }
1996
- return {
1997
- activeSessions: this.activeSessions.size,
1998
- pendingSessions: this.pendingSessions.size,
1999
- totalConnections
2000
- };
2001
- }
2002
- destroy() {
2003
- for (const pending of this.pendingSessions.values()) {
2004
- clearTimeout(pending.expiryTimer);
2005
- }
2006
- this.activeSessions.clear();
2007
- this.pendingSessions.clear();
2008
- this.sessionConnections.clear();
2009
- }
2010
- }
2011
-
2012
- // src/remote/server.ts
2013
- init_logger();
2014
2153
  var log6 = frameworkLoggers.remote;
2015
2154
 
2016
2155
  class RemoteServer {
@@ -2433,4 +2572,4 @@ export {
2433
2572
  RemoteEngine
2434
2573
  };
2435
2574
 
2436
- //# debugId=6490411AAAF0974364756E2164756E21
2575
+ //# debugId=914D90741C165F9464756E2164756E21