@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/engine.ts
948
1214
  init_logger();
949
1215
  init_result();
@@ -1066,10 +1332,140 @@ class Engine {
1066
1332
  }
1067
1333
  }
1068
1334
 
1335
+ // src/remote/server.ts
1336
+ init_app();
1337
+
1338
+ // src/remote/session.ts
1339
+ class SessionManager {
1340
+ activeSessions = new Map;
1341
+ pendingSessions = new Map;
1342
+ sessionConnections = new Map;
1343
+ config;
1344
+ constructor(config2 = {}) {
1345
+ this.config = {
1346
+ ttl: config2.ttl ?? 3600,
1347
+ concurrent: config2.concurrent ?? "kick-old",
1348
+ generateId: config2.generateId ?? (() => crypto.randomUUID())
1349
+ };
1350
+ }
1351
+ getTtl() {
1352
+ return this.config.ttl;
1353
+ }
1354
+ getConcurrentPolicy() {
1355
+ return this.config.concurrent;
1356
+ }
1357
+ createSession(props) {
1358
+ const now = new Date;
1359
+ const session = {
1360
+ id: this.config.generateId(),
1361
+ ttl: this.config.ttl,
1362
+ createdAt: now,
1363
+ lastConnectedAt: now,
1364
+ props
1365
+ };
1366
+ this.activeSessions.set(session.id, session);
1367
+ return session;
1368
+ }
1369
+ getActiveSession(id) {
1370
+ return this.activeSessions.get(id) ?? null;
1371
+ }
1372
+ getPendingSession(id) {
1373
+ return this.pendingSessions.get(id) ?? null;
1374
+ }
1375
+ hasSession(id) {
1376
+ return this.activeSessions.has(id) || this.pendingSessions.has(id);
1377
+ }
1378
+ suspendSession(sessionId, savedState, onExpire) {
1379
+ const session = this.activeSessions.get(sessionId);
1380
+ if (!session)
1381
+ return;
1382
+ this.activeSessions.delete(sessionId);
1383
+ const expiryTimer = setTimeout(async () => {
1384
+ const pending = this.pendingSessions.get(sessionId);
1385
+ if (pending) {
1386
+ this.pendingSessions.delete(sessionId);
1387
+ await onExpire(pending.session);
1388
+ }
1389
+ }, session.ttl * 1000);
1390
+ this.pendingSessions.set(sessionId, {
1391
+ session,
1392
+ savedState,
1393
+ expiryTimer
1394
+ });
1395
+ }
1396
+ resumeSession(sessionId) {
1397
+ const pending = this.pendingSessions.get(sessionId);
1398
+ if (!pending)
1399
+ return null;
1400
+ clearTimeout(pending.expiryTimer);
1401
+ this.pendingSessions.delete(sessionId);
1402
+ pending.session.lastConnectedAt = new Date;
1403
+ this.activeSessions.set(sessionId, pending.session);
1404
+ return {
1405
+ session: pending.session,
1406
+ savedState: pending.savedState
1407
+ };
1408
+ }
1409
+ destroySession(sessionId) {
1410
+ this.activeSessions.delete(sessionId);
1411
+ const pending = this.pendingSessions.get(sessionId);
1412
+ if (pending) {
1413
+ clearTimeout(pending.expiryTimer);
1414
+ this.pendingSessions.delete(sessionId);
1415
+ }
1416
+ this.sessionConnections.delete(sessionId);
1417
+ }
1418
+ trackConnection(sessionId, ws) {
1419
+ let connections = this.sessionConnections.get(sessionId);
1420
+ if (!connections) {
1421
+ connections = new Set;
1422
+ this.sessionConnections.set(sessionId, connections);
1423
+ }
1424
+ connections.add(ws);
1425
+ }
1426
+ untrackConnection(sessionId, ws) {
1427
+ const connections = this.sessionConnections.get(sessionId);
1428
+ if (connections) {
1429
+ connections.delete(ws);
1430
+ if (connections.size === 0) {
1431
+ this.sessionConnections.delete(sessionId);
1432
+ }
1433
+ }
1434
+ }
1435
+ getConnections(sessionId) {
1436
+ return this.sessionConnections.get(sessionId);
1437
+ }
1438
+ getConnectionCount(sessionId) {
1439
+ return this.sessionConnections.get(sessionId)?.size ?? 0;
1440
+ }
1441
+ getStats() {
1442
+ let totalConnections = 0;
1443
+ for (const connections of this.sessionConnections.values()) {
1444
+ totalConnections += connections.size;
1445
+ }
1446
+ return {
1447
+ activeSessions: this.activeSessions.size,
1448
+ pendingSessions: this.pendingSessions.size,
1449
+ totalConnections
1450
+ };
1451
+ }
1452
+ destroy() {
1453
+ for (const pending of this.pendingSessions.values()) {
1454
+ clearTimeout(pending.expiryTimer);
1455
+ }
1456
+ this.activeSessions.clear();
1457
+ this.pendingSessions.clear();
1458
+ this.sessionConnections.clear();
1459
+ }
1460
+ }
1461
+
1462
+ // src/remote/server.ts
1463
+ init_logger();
1464
+
1069
1465
  // src/discovery.ts
1466
+ init_path();
1070
1467
  init_logger();
1071
- import { existsSync, readdirSync, readFileSync, watch } from "fs";
1072
- import { join, basename, resolve, relative } from "path";
1468
+ var {existsSync, readdirSync, readFileSync, watch} = (() => ({}));
1073
1469
  async function discoverComponents(baseDir, options = {}) {
1074
1470
  const {
1075
1471
  patterns = ["single-file", "folder", "sibling", "index"],
@@ -1238,254 +1634,8 @@ async function loadDiscoveredComponents(components) {
1238
1634
  }
1239
1635
  return loaded;
1240
1636
  }
1241
- function watchComponents(baseDir, options = {}) {
1242
- const resolvedDir = resolve(baseDir);
1243
- const {
1244
- onChange,
1245
- onAdd,
1246
- onRemove,
1247
- onUpdate,
1248
- debug = false,
1249
- ...discoveryOptions
1250
- } = options;
1251
- const log4 = debug ? (...args) => frameworkLoggers.discovery.debug("[watch]", ...args) : () => {};
1252
- let currentComponents = new Map;
1253
- let debounceTimer = null;
1254
- const initialScan = async () => {
1255
- const components = await discoverComponents(resolvedDir, discoveryOptions);
1256
- currentComponents = new Map(components.map((c) => [c.name, c]));
1257
- onChange?.(components);
1258
- };
1259
- const rescan = async () => {
1260
- if (debounceTimer) {
1261
- clearTimeout(debounceTimer);
1262
- }
1263
- debounceTimer = setTimeout(async () => {
1264
- log4("Rescanning...");
1265
- const newComponents = await discoverComponents(resolvedDir, discoveryOptions);
1266
- const newMap = new Map(newComponents.map((c) => [c.name, c]));
1267
- for (const [name, component] of newMap) {
1268
- const existing = currentComponents.get(name);
1269
- if (!existing) {
1270
- log4("Added:", name);
1271
- onAdd?.(component);
1272
- } else if (existing.template !== component.template || existing.modulePath !== component.modulePath) {
1273
- log4("Updated:", name);
1274
- onUpdate?.(component);
1275
- }
1276
- }
1277
- for (const name of currentComponents.keys()) {
1278
- if (!newMap.has(name)) {
1279
- log4("Removed:", name);
1280
- onRemove?.(name);
1281
- }
1282
- }
1283
- currentComponents = newMap;
1284
- onChange?.(newComponents);
1285
- }, 100);
1286
- };
1287
- const watcher = watch(resolvedDir, { recursive: true }, (event, filename) => {
1288
- if (!filename)
1289
- return;
1290
- if (filename.endsWith(".hypen") || filename.endsWith(".ts")) {
1291
- log4("File changed:", filename);
1292
- rescan();
1293
- }
1294
- });
1295
- initialScan();
1296
- return {
1297
- stop: () => {
1298
- watcher.close();
1299
- if (debounceTimer) {
1300
- clearTimeout(debounceTimer);
1301
- }
1302
- }
1303
- };
1304
- }
1305
- async function generateComponentsCode(baseDir, options = {}) {
1306
- const components = await discoverComponents(baseDir, options);
1307
- const resolvedDir = resolve(baseDir);
1308
- const outputBase = options.outputDir ? resolve(options.outputDir) : resolvedDir;
1309
- let code = `/**
1310
- * Auto-generated component imports
1311
- * Generated by @hypen-space/core discovery
1312
- */
1313
-
1314
- `;
1315
- for (const component of components) {
1316
- let importPath = null;
1317
- if (component.modulePath) {
1318
- const rel = relative(outputBase, component.modulePath).replace(/\.ts$/, ".js");
1319
- importPath = rel.startsWith(".") ? rel : "./" + rel;
1320
- }
1321
- if (importPath) {
1322
- code += `import ${component.name}Module from "${importPath}";
1323
- `;
1324
- }
1325
- }
1326
- code += `
1327
- import { app } from "@hypen-space/core";
1328
-
1329
- `;
1330
- for (const component of components) {
1331
- if (component.isSingleFile) {
1332
- code += `export const ${component.name} = {
1333
- module: ${component.name}Module,
1334
- template: ${component.name}Module.template,
1335
- };
1336
-
1337
- `;
1338
- } else if (component.hasModule) {
1339
- const templateJson = JSON.stringify(component.template);
1340
- code += `export const ${component.name} = {
1341
- module: ${component.name}Module,
1342
- template: ${templateJson},
1343
- };
1344
-
1345
- `;
1346
- } else {
1347
- const templateJson = JSON.stringify(component.template);
1348
- code += `const ${component.name}Module = app.defineState({}).build();
1349
- export const ${component.name} = {
1350
- module: ${component.name}Module,
1351
- template: ${templateJson},
1352
- };
1353
-
1354
- `;
1355
- }
1356
- }
1357
- return code;
1358
- }
1359
1637
 
1360
1638
  // src/remote/server.ts
1361
- init_app();
1362
-
1363
- // src/remote/session.ts
1364
- class SessionManager {
1365
- activeSessions = new Map;
1366
- pendingSessions = new Map;
1367
- sessionConnections = new Map;
1368
- config;
1369
- constructor(config2 = {}) {
1370
- this.config = {
1371
- ttl: config2.ttl ?? 3600,
1372
- concurrent: config2.concurrent ?? "kick-old",
1373
- generateId: config2.generateId ?? (() => crypto.randomUUID())
1374
- };
1375
- }
1376
- getTtl() {
1377
- return this.config.ttl;
1378
- }
1379
- getConcurrentPolicy() {
1380
- return this.config.concurrent;
1381
- }
1382
- createSession(props) {
1383
- const now = new Date;
1384
- const session = {
1385
- id: this.config.generateId(),
1386
- ttl: this.config.ttl,
1387
- createdAt: now,
1388
- lastConnectedAt: now,
1389
- props
1390
- };
1391
- this.activeSessions.set(session.id, session);
1392
- return session;
1393
- }
1394
- getActiveSession(id) {
1395
- return this.activeSessions.get(id) ?? null;
1396
- }
1397
- getPendingSession(id) {
1398
- return this.pendingSessions.get(id) ?? null;
1399
- }
1400
- hasSession(id) {
1401
- return this.activeSessions.has(id) || this.pendingSessions.has(id);
1402
- }
1403
- suspendSession(sessionId, savedState, onExpire) {
1404
- const session = this.activeSessions.get(sessionId);
1405
- if (!session)
1406
- return;
1407
- this.activeSessions.delete(sessionId);
1408
- const expiryTimer = setTimeout(async () => {
1409
- const pending = this.pendingSessions.get(sessionId);
1410
- if (pending) {
1411
- this.pendingSessions.delete(sessionId);
1412
- await onExpire(pending.session);
1413
- }
1414
- }, session.ttl * 1000);
1415
- this.pendingSessions.set(sessionId, {
1416
- session,
1417
- savedState,
1418
- expiryTimer
1419
- });
1420
- }
1421
- resumeSession(sessionId) {
1422
- const pending = this.pendingSessions.get(sessionId);
1423
- if (!pending)
1424
- return null;
1425
- clearTimeout(pending.expiryTimer);
1426
- this.pendingSessions.delete(sessionId);
1427
- pending.session.lastConnectedAt = new Date;
1428
- this.activeSessions.set(sessionId, pending.session);
1429
- return {
1430
- session: pending.session,
1431
- savedState: pending.savedState
1432
- };
1433
- }
1434
- destroySession(sessionId) {
1435
- this.activeSessions.delete(sessionId);
1436
- const pending = this.pendingSessions.get(sessionId);
1437
- if (pending) {
1438
- clearTimeout(pending.expiryTimer);
1439
- this.pendingSessions.delete(sessionId);
1440
- }
1441
- this.sessionConnections.delete(sessionId);
1442
- }
1443
- trackConnection(sessionId, ws) {
1444
- let connections = this.sessionConnections.get(sessionId);
1445
- if (!connections) {
1446
- connections = new Set;
1447
- this.sessionConnections.set(sessionId, connections);
1448
- }
1449
- connections.add(ws);
1450
- }
1451
- untrackConnection(sessionId, ws) {
1452
- const connections = this.sessionConnections.get(sessionId);
1453
- if (connections) {
1454
- connections.delete(ws);
1455
- if (connections.size === 0) {
1456
- this.sessionConnections.delete(sessionId);
1457
- }
1458
- }
1459
- }
1460
- getConnections(sessionId) {
1461
- return this.sessionConnections.get(sessionId);
1462
- }
1463
- getConnectionCount(sessionId) {
1464
- return this.sessionConnections.get(sessionId)?.size ?? 0;
1465
- }
1466
- getStats() {
1467
- let totalConnections = 0;
1468
- for (const connections of this.sessionConnections.values()) {
1469
- totalConnections += connections.size;
1470
- }
1471
- return {
1472
- activeSessions: this.activeSessions.size,
1473
- pendingSessions: this.pendingSessions.size,
1474
- totalConnections
1475
- };
1476
- }
1477
- destroy() {
1478
- for (const pending of this.pendingSessions.values()) {
1479
- clearTimeout(pending.expiryTimer);
1480
- }
1481
- this.activeSessions.clear();
1482
- this.pendingSessions.clear();
1483
- this.sessionConnections.clear();
1484
- }
1485
- }
1486
-
1487
- // src/remote/server.ts
1488
- init_logger();
1489
1639
  var log4 = frameworkLoggers.remote;
1490
1640
 
1491
1641
  class RemoteServer {
@@ -1906,4 +2056,4 @@ export {
1906
2056
  RemoteServer
1907
2057
  };
1908
2058
 
1909
- //# debugId=33D5969822E0782864756E2164756E21
2059
+ //# debugId=9DC45B65323497E764756E2164756E21