@noxfly/noxus 3.0.0-dev.0 → 3.0.0-dev.2

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 (38) hide show
  1. package/README.md +14 -11
  2. package/dist/child.d.mts +112 -4
  3. package/dist/child.d.ts +112 -4
  4. package/dist/child.js +33 -30
  5. package/dist/child.mjs +33 -30
  6. package/dist/main.d.mts +450 -6
  7. package/dist/main.d.ts +450 -6
  8. package/dist/main.js +232 -229
  9. package/dist/main.mjs +234 -231
  10. package/dist/preload.d.mts +28 -0
  11. package/dist/preload.d.ts +28 -0
  12. package/dist/preload.js +95 -0
  13. package/dist/preload.mjs +70 -0
  14. package/dist/renderer.d.mts +159 -22
  15. package/dist/renderer.d.ts +159 -22
  16. package/dist/renderer.js +14 -58
  17. package/dist/renderer.mjs +10 -53
  18. package/package.json +26 -13
  19. package/src/DI/app-injector.ts +10 -1
  20. package/src/DI/injector-explorer.ts +2 -2
  21. package/src/decorators/guards.decorator.ts +1 -1
  22. package/src/decorators/middleware.decorator.ts +1 -1
  23. package/src/index.ts +2 -5
  24. package/src/{app.ts → internal/app.ts} +8 -8
  25. package/src/{bootstrap.ts → internal/bootstrap.ts} +5 -4
  26. package/src/{request.ts → internal/request.ts} +2 -2
  27. package/src/{router.ts → internal/router.ts} +9 -9
  28. package/src/{routes.ts → internal/routes.ts} +2 -2
  29. package/src/{socket.ts → internal/socket.ts} +2 -2
  30. package/src/main.ts +7 -7
  31. package/src/non-electron-process.ts +1 -1
  32. package/src/preload.ts +10 -0
  33. package/src/renderer.ts +13 -0
  34. package/tsup.config.ts +27 -11
  35. /package/src/{exceptions.ts → internal/exceptions.ts} +0 -0
  36. /package/src/{preload-bridge.ts → internal/preload-bridge.ts} +0 -0
  37. /package/src/{renderer-client.ts → internal/renderer-client.ts} +0 -0
  38. /package/src/{renderer-events.ts → internal/renderer-events.ts} +0 -0
package/dist/main.js CHANGED
@@ -133,6 +133,9 @@ var init_app_injector = __esm({
133
133
  return this._resolveForwardRef(target);
134
134
  }
135
135
  const k = keyOf(target);
136
+ if (this.singletons.has(k)) {
137
+ return this.singletons.get(k);
138
+ }
136
139
  const binding = this.bindings.get(k);
137
140
  if (!binding) {
138
141
  const name = target instanceof Token ? target.description : target.name ?? "unknown";
@@ -633,10 +636,172 @@ var init_method_decorator = __esm({
633
636
  }
634
637
  });
635
638
 
636
- // src/exceptions.ts
639
+ // src/utils/radix-tree.ts
640
+ var _RadixNode, RadixNode, _RadixTree, RadixTree;
641
+ var init_radix_tree = __esm({
642
+ "src/utils/radix-tree.ts"() {
643
+ "use strict";
644
+ _RadixNode = class _RadixNode {
645
+ /**
646
+ * Creates a new RadixNode.
647
+ * @param segment - The segment of the path this node represents.
648
+ */
649
+ constructor(segment) {
650
+ this.children = [];
651
+ this.segment = segment;
652
+ this.isParam = segment.startsWith(":");
653
+ if (this.isParam) {
654
+ this.paramName = segment.slice(1);
655
+ }
656
+ }
657
+ /**
658
+ * Matches a child node against a given segment.
659
+ * This method checks if the segment matches any of the children nodes.
660
+ * @param segment - The segment to match against the children of this node.
661
+ * @returns A child node that matches the segment, or undefined if no match is found.
662
+ */
663
+ matchChild(segment) {
664
+ for (const child of this.children) {
665
+ if (child.isParam || segment.startsWith(child.segment))
666
+ return child;
667
+ }
668
+ return void 0;
669
+ }
670
+ /**
671
+ * Finds a child node that matches the segment exactly.
672
+ * This method checks if there is a child node that matches the segment exactly.
673
+ * @param segment - The segment to find an exact match for among the children of this node.
674
+ * @returns A child node that matches the segment exactly, or undefined if no match is found.
675
+ */
676
+ findExactChild(segment) {
677
+ return this.children.find((c) => c.segment === segment);
678
+ }
679
+ /**
680
+ * Adds a child node to this node's children.
681
+ * This method adds a new child node to the list of children for this node.
682
+ * @param node - The child node to add to this node's children.
683
+ */
684
+ addChild(node) {
685
+ this.children.push(node);
686
+ }
687
+ };
688
+ __name(_RadixNode, "RadixNode");
689
+ RadixNode = _RadixNode;
690
+ _RadixTree = class _RadixTree {
691
+ constructor() {
692
+ this.root = new RadixNode("");
693
+ }
694
+ /**
695
+ * Inserts a path and its associated value into the Radix Tree.
696
+ * This method normalizes the path and inserts it into the tree, associating it with
697
+ * @param path - The path to insert into the tree.
698
+ * @param value - The value to associate with the path.
699
+ */
700
+ insert(path2, value) {
701
+ const segments = this.normalize(path2);
702
+ this.insertRecursive(this.root, segments, value);
703
+ }
704
+ /**
705
+ * Recursively inserts a path into the Radix Tree.
706
+ * This method traverses the tree and inserts the segments of the path, creating new nodes
707
+ * @param node - The node to start inserting from.
708
+ * @param segments - The segments of the path to insert.
709
+ * @param value - The value to associate with the path.
710
+ */
711
+ insertRecursive(node, segments, value) {
712
+ if (segments.length === 0) {
713
+ node.value = value;
714
+ return;
715
+ }
716
+ const segment = segments[0] ?? "";
717
+ let child = node.children.find(
718
+ (c) => c.isParam === segment.startsWith(":") && (c.isParam || c.segment === segment)
719
+ );
720
+ if (!child) {
721
+ child = new RadixNode(segment);
722
+ node.addChild(child);
723
+ }
724
+ this.insertRecursive(child, segments.slice(1), value);
725
+ }
726
+ /**
727
+ * Searches for a path in the Radix Tree.
728
+ * This method normalizes the path and searches for it in the tree, returning the node
729
+ * @param path - The path to search for in the Radix Tree.
730
+ * @returns An ISearchResult containing the node and parameters if a match is found, otherwise undefined.
731
+ */
732
+ search(path2) {
733
+ const segments = this.normalize(path2);
734
+ return this.searchRecursive(this.root, segments, {});
735
+ }
736
+ /**
737
+ * Recursively searches for a path in the Radix Tree.
738
+ * This method traverses the tree and searches for the segments of the path, collecting parameters
739
+ * @param node - The node to start searching from.
740
+ * @param segments - The segments of the path to search for.
741
+ * @param params - The parameters collected during the search.
742
+ * @returns An ISearchResult containing the node and parameters if a match is found, otherwise undefined.
743
+ */
744
+ searchRecursive(node, segments, params) {
745
+ if (segments.length === 0) {
746
+ if (node.value !== void 0) {
747
+ return {
748
+ node,
749
+ params
750
+ };
751
+ }
752
+ return void 0;
753
+ }
754
+ const [segment, ...rest] = segments;
755
+ for (const child of node.children) {
756
+ if (child.isParam) {
757
+ const paramName = child.paramName;
758
+ const childParams = {
759
+ ...params,
760
+ [paramName]: segment ?? ""
761
+ };
762
+ if (rest.length === 0) {
763
+ return {
764
+ node: child,
765
+ params: childParams
766
+ };
767
+ }
768
+ const result = this.searchRecursive(child, rest, childParams);
769
+ if (result)
770
+ return result;
771
+ } else if (segment === child.segment) {
772
+ if (rest.length === 0) {
773
+ return {
774
+ node: child,
775
+ params
776
+ };
777
+ }
778
+ const result = this.searchRecursive(child, rest, params);
779
+ if (result)
780
+ return result;
781
+ }
782
+ }
783
+ return void 0;
784
+ }
785
+ /**
786
+ * Normalizes a path into an array of segments.
787
+ * This method removes leading and trailing slashes, splits the path by slashes, and
788
+ * @param path - The path to normalize.
789
+ * @returns An array of normalized path segments.
790
+ */
791
+ normalize(path2) {
792
+ const segments = path2.replace(/^\/+|\/+$/g, "").split("/").filter(Boolean);
793
+ return ["", ...segments];
794
+ }
795
+ };
796
+ __name(_RadixTree, "RadixTree");
797
+ RadixTree = _RadixTree;
798
+ }
799
+ });
800
+
801
+ // src/internal/exceptions.ts
637
802
  var _ResponseException, ResponseException, _BadRequestException, BadRequestException, _UnauthorizedException, UnauthorizedException, _PaymentRequiredException, PaymentRequiredException, _ForbiddenException, ForbiddenException, _NotFoundException, NotFoundException, _MethodNotAllowedException, MethodNotAllowedException, _NotAcceptableException, NotAcceptableException, _RequestTimeoutException, RequestTimeoutException, _ConflictException, ConflictException, _UpgradeRequiredException, UpgradeRequiredException, _TooManyRequestsException, TooManyRequestsException, _InternalServerException, InternalServerException, _NotImplementedException, NotImplementedException, _BadGatewayException, BadGatewayException, _ServiceUnavailableException, ServiceUnavailableException, _GatewayTimeoutException, GatewayTimeoutException, _HttpVersionNotSupportedException, HttpVersionNotSupportedException, _VariantAlsoNegotiatesException, VariantAlsoNegotiatesException, _InsufficientStorageException, InsufficientStorageException, _LoopDetectedException, LoopDetectedException, _NotExtendedException, NotExtendedException, _NetworkAuthenticationRequiredException, NetworkAuthenticationRequiredException, _NetworkConnectTimeoutException, NetworkConnectTimeoutException;
638
803
  var init_exceptions = __esm({
639
- "src/exceptions.ts"() {
804
+ "src/internal/exceptions.ts"() {
640
805
  "use strict";
641
806
  _ResponseException = class _ResponseException extends Error {
642
807
  constructor(statusOrMessage, message) {
@@ -843,7 +1008,7 @@ var init_exceptions = __esm({
843
1008
  }
844
1009
  });
845
1010
 
846
- // src/request.ts
1011
+ // src/internal/request.ts
847
1012
  function createRendererEventMessage(event, payload) {
848
1013
  return {
849
1014
  type: RENDERER_EVENT_TYPE,
@@ -860,7 +1025,7 @@ function isRendererEventMessage(value) {
860
1025
  }
861
1026
  var _Request, Request, RENDERER_EVENT_TYPE;
862
1027
  var init_request = __esm({
863
- "src/request.ts"() {
1028
+ "src/internal/request.ts"() {
864
1029
  "use strict";
865
1030
  init_app_injector();
866
1031
  _Request = class _Request {
@@ -884,185 +1049,23 @@ var init_request = __esm({
884
1049
  }
885
1050
  });
886
1051
 
887
- // src/utils/radix-tree.ts
888
- var _RadixNode, RadixNode, _RadixTree, RadixTree;
889
- var init_radix_tree = __esm({
890
- "src/utils/radix-tree.ts"() {
891
- "use strict";
892
- _RadixNode = class _RadixNode {
893
- /**
894
- * Creates a new RadixNode.
895
- * @param segment - The segment of the path this node represents.
896
- */
897
- constructor(segment) {
898
- this.children = [];
899
- this.segment = segment;
900
- this.isParam = segment.startsWith(":");
901
- if (this.isParam) {
902
- this.paramName = segment.slice(1);
903
- }
904
- }
905
- /**
906
- * Matches a child node against a given segment.
907
- * This method checks if the segment matches any of the children nodes.
908
- * @param segment - The segment to match against the children of this node.
909
- * @returns A child node that matches the segment, or undefined if no match is found.
910
- */
911
- matchChild(segment) {
912
- for (const child of this.children) {
913
- if (child.isParam || segment.startsWith(child.segment))
914
- return child;
915
- }
916
- return void 0;
917
- }
918
- /**
919
- * Finds a child node that matches the segment exactly.
920
- * This method checks if there is a child node that matches the segment exactly.
921
- * @param segment - The segment to find an exact match for among the children of this node.
922
- * @returns A child node that matches the segment exactly, or undefined if no match is found.
923
- */
924
- findExactChild(segment) {
925
- return this.children.find((c) => c.segment === segment);
926
- }
927
- /**
928
- * Adds a child node to this node's children.
929
- * This method adds a new child node to the list of children for this node.
930
- * @param node - The child node to add to this node's children.
931
- */
932
- addChild(node) {
933
- this.children.push(node);
934
- }
935
- };
936
- __name(_RadixNode, "RadixNode");
937
- RadixNode = _RadixNode;
938
- _RadixTree = class _RadixTree {
939
- constructor() {
940
- this.root = new RadixNode("");
941
- }
942
- /**
943
- * Inserts a path and its associated value into the Radix Tree.
944
- * This method normalizes the path and inserts it into the tree, associating it with
945
- * @param path - The path to insert into the tree.
946
- * @param value - The value to associate with the path.
947
- */
948
- insert(path2, value) {
949
- const segments = this.normalize(path2);
950
- this.insertRecursive(this.root, segments, value);
951
- }
952
- /**
953
- * Recursively inserts a path into the Radix Tree.
954
- * This method traverses the tree and inserts the segments of the path, creating new nodes
955
- * @param node - The node to start inserting from.
956
- * @param segments - The segments of the path to insert.
957
- * @param value - The value to associate with the path.
958
- */
959
- insertRecursive(node, segments, value) {
960
- if (segments.length === 0) {
961
- node.value = value;
962
- return;
963
- }
964
- const segment = segments[0] ?? "";
965
- let child = node.children.find(
966
- (c) => c.isParam === segment.startsWith(":") && (c.isParam || c.segment === segment)
967
- );
968
- if (!child) {
969
- child = new RadixNode(segment);
970
- node.addChild(child);
971
- }
972
- this.insertRecursive(child, segments.slice(1), value);
973
- }
974
- /**
975
- * Searches for a path in the Radix Tree.
976
- * This method normalizes the path and searches for it in the tree, returning the node
977
- * @param path - The path to search for in the Radix Tree.
978
- * @returns An ISearchResult containing the node and parameters if a match is found, otherwise undefined.
979
- */
980
- search(path2) {
981
- const segments = this.normalize(path2);
982
- return this.searchRecursive(this.root, segments, {});
983
- }
984
- /**
985
- * Recursively searches for a path in the Radix Tree.
986
- * This method traverses the tree and searches for the segments of the path, collecting parameters
987
- * @param node - The node to start searching from.
988
- * @param segments - The segments of the path to search for.
989
- * @param params - The parameters collected during the search.
990
- * @returns An ISearchResult containing the node and parameters if a match is found, otherwise undefined.
991
- */
992
- searchRecursive(node, segments, params) {
993
- if (segments.length === 0) {
994
- if (node.value !== void 0) {
995
- return {
996
- node,
997
- params
998
- };
999
- }
1000
- return void 0;
1001
- }
1002
- const [segment, ...rest] = segments;
1003
- for (const child of node.children) {
1004
- if (child.isParam) {
1005
- const paramName = child.paramName;
1006
- const childParams = {
1007
- ...params,
1008
- [paramName]: segment ?? ""
1009
- };
1010
- if (rest.length === 0) {
1011
- return {
1012
- node: child,
1013
- params: childParams
1014
- };
1015
- }
1016
- const result = this.searchRecursive(child, rest, childParams);
1017
- if (result)
1018
- return result;
1019
- } else if (segment === child.segment) {
1020
- if (rest.length === 0) {
1021
- return {
1022
- node: child,
1023
- params
1024
- };
1025
- }
1026
- const result = this.searchRecursive(child, rest, params);
1027
- if (result)
1028
- return result;
1029
- }
1030
- }
1031
- return void 0;
1032
- }
1033
- /**
1034
- * Normalizes a path into an array of segments.
1035
- * This method removes leading and trailing slashes, splits the path by slashes, and
1036
- * @param path - The path to normalize.
1037
- * @returns An array of normalized path segments.
1038
- */
1039
- normalize(path2) {
1040
- const segments = path2.replace(/^\/+|\/+$/g, "").split("/").filter(Boolean);
1041
- return ["", ...segments];
1042
- }
1043
- };
1044
- __name(_RadixTree, "RadixTree");
1045
- RadixTree = _RadixTree;
1046
- }
1047
- });
1048
-
1049
- // src/router.ts
1052
+ // src/internal/router.ts
1050
1053
  var router_exports = {};
1051
1054
  __export(router_exports, {
1052
1055
  Router: () => Router
1053
1056
  });
1054
1057
  var Router;
1055
1058
  var init_router = __esm({
1056
- "src/router.ts"() {
1059
+ "src/internal/router.ts"() {
1057
1060
  "use strict";
1058
1061
  init_controller_decorator();
1059
1062
  init_injectable_decorator();
1060
1063
  init_method_decorator();
1061
1064
  init_injector_explorer();
1062
- init_exceptions();
1063
- init_request();
1064
1065
  init_logger();
1065
1066
  init_radix_tree();
1067
+ init_exceptions();
1068
+ init_request();
1066
1069
  Router = class {
1067
1070
  constructor() {
1068
1071
  this.routes = new RadixTree();
@@ -1362,66 +1365,11 @@ init_app_injector();
1362
1365
  init_token();
1363
1366
  init_router();
1364
1367
 
1365
- // src/app.ts
1368
+ // src/internal/app.ts
1366
1369
  var import_main2 = require("electron/main");
1367
1370
  init_injectable_decorator();
1368
1371
  init_app_injector();
1369
1372
  init_injector_explorer();
1370
- init_request();
1371
- init_router();
1372
-
1373
- // src/socket.ts
1374
- init_injectable_decorator();
1375
- init_request();
1376
- init_logger();
1377
- var NoxSocket = class {
1378
- constructor() {
1379
- this.channels = /* @__PURE__ */ new Map();
1380
- }
1381
- register(senderId, requestChannel, socketChannel) {
1382
- this.channels.set(senderId, { request: requestChannel, socket: socketChannel });
1383
- }
1384
- get(senderId) {
1385
- return this.channels.get(senderId);
1386
- }
1387
- unregister(senderId) {
1388
- this.channels.delete(senderId);
1389
- }
1390
- getSenderIds() {
1391
- return [...this.channels.keys()];
1392
- }
1393
- emit(eventName, payload, targetSenderIds) {
1394
- const normalizedEvent = eventName.trim();
1395
- if (normalizedEvent.length === 0) {
1396
- throw new Error("Renderer event name must be a non-empty string.");
1397
- }
1398
- const recipients = targetSenderIds ?? this.getSenderIds();
1399
- let delivered = 0;
1400
- for (const senderId of recipients) {
1401
- const channel = this.channels.get(senderId);
1402
- if (!channel) {
1403
- Logger.warn(`No message channel found for sender ID: ${senderId} while emitting "${normalizedEvent}".`);
1404
- continue;
1405
- }
1406
- try {
1407
- channel.socket.port1.postMessage(createRendererEventMessage(normalizedEvent, payload));
1408
- delivered++;
1409
- } catch (error) {
1410
- Logger.error(`[Noxus] Failed to emit "${normalizedEvent}" to sender ${senderId}.`, error);
1411
- }
1412
- }
1413
- return delivered;
1414
- }
1415
- emitToRenderer(senderId, eventName, payload) {
1416
- return this.emit(eventName, payload, [senderId]) > 0;
1417
- }
1418
- };
1419
- __name(NoxSocket, "NoxSocket");
1420
- NoxSocket = __decorateClass([
1421
- Injectable({ lifetime: "singleton" })
1422
- ], NoxSocket);
1423
-
1424
- // src/app.ts
1425
1373
  init_logger();
1426
1374
 
1427
1375
  // src/window/window-manager.ts
@@ -1593,7 +1541,62 @@ WindowManager = __decorateClass([
1593
1541
  Injectable({ lifetime: "singleton" })
1594
1542
  ], WindowManager);
1595
1543
 
1596
- // src/app.ts
1544
+ // src/internal/app.ts
1545
+ init_request();
1546
+ init_router();
1547
+
1548
+ // src/internal/socket.ts
1549
+ init_injectable_decorator();
1550
+ init_logger();
1551
+ init_request();
1552
+ var NoxSocket = class {
1553
+ constructor() {
1554
+ this.channels = /* @__PURE__ */ new Map();
1555
+ }
1556
+ register(senderId, requestChannel, socketChannel) {
1557
+ this.channels.set(senderId, { request: requestChannel, socket: socketChannel });
1558
+ }
1559
+ get(senderId) {
1560
+ return this.channels.get(senderId);
1561
+ }
1562
+ unregister(senderId) {
1563
+ this.channels.delete(senderId);
1564
+ }
1565
+ getSenderIds() {
1566
+ return [...this.channels.keys()];
1567
+ }
1568
+ emit(eventName, payload, targetSenderIds) {
1569
+ const normalizedEvent = eventName.trim();
1570
+ if (normalizedEvent.length === 0) {
1571
+ throw new Error("Renderer event name must be a non-empty string.");
1572
+ }
1573
+ const recipients = targetSenderIds ?? this.getSenderIds();
1574
+ let delivered = 0;
1575
+ for (const senderId of recipients) {
1576
+ const channel = this.channels.get(senderId);
1577
+ if (!channel) {
1578
+ Logger.warn(`No message channel found for sender ID: ${senderId} while emitting "${normalizedEvent}".`);
1579
+ continue;
1580
+ }
1581
+ try {
1582
+ channel.socket.port1.postMessage(createRendererEventMessage(normalizedEvent, payload));
1583
+ delivered++;
1584
+ } catch (error) {
1585
+ Logger.error(`[Noxus] Failed to emit "${normalizedEvent}" to sender ${senderId}.`, error);
1586
+ }
1587
+ }
1588
+ return delivered;
1589
+ }
1590
+ emitToRenderer(senderId, eventName, payload) {
1591
+ return this.emit(eventName, payload, [senderId]) > 0;
1592
+ }
1593
+ };
1594
+ __name(NoxSocket, "NoxSocket");
1595
+ NoxSocket = __decorateClass([
1596
+ Injectable({ lifetime: "singleton" })
1597
+ ], NoxSocket);
1598
+
1599
+ // src/internal/app.ts
1597
1600
  var NoxApp = class {
1598
1601
  constructor() {
1599
1602
  this.router = inject(Router);
@@ -1735,7 +1738,7 @@ NoxApp = __decorateClass([
1735
1738
  Injectable({ lifetime: "singleton", deps: [Router, NoxSocket, WindowManager] })
1736
1739
  ], NoxApp);
1737
1740
 
1738
- // src/bootstrap.ts
1741
+ // src/internal/bootstrap.ts
1739
1742
  var import_main3 = require("electron/main");
1740
1743
  init_app_injector();
1741
1744
  init_injector_explorer();
@@ -1770,7 +1773,7 @@ init_logger();
1770
1773
  init_forward_ref();
1771
1774
  init_request();
1772
1775
 
1773
- // src/routes.ts
1776
+ // src/internal/routes.ts
1774
1777
  function defineRoutes(routes) {
1775
1778
  const paths = routes.map((r) => r.path.replace(/^\/+|\/+$/g, ""));
1776
1779
  const duplicates = paths.filter((p, i) => paths.indexOf(p) !== i);