@noxfly/noxus 3.0.0-dev.0 → 3.0.0-dev.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.
Files changed (37) hide show
  1. package/README.md +12 -9
  2. package/dist/child.d.mts +112 -4
  3. package/dist/child.d.ts +112 -4
  4. package/dist/child.js +30 -30
  5. package/dist/child.mjs +30 -30
  6. package/dist/main.d.mts +450 -6
  7. package/dist/main.d.ts +450 -6
  8. package/dist/main.js +229 -229
  9. package/dist/main.mjs +231 -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 +11 -58
  17. package/dist/renderer.mjs +7 -53
  18. package/package.json +18 -13
  19. package/src/DI/injector-explorer.ts +2 -2
  20. package/src/decorators/guards.decorator.ts +1 -1
  21. package/src/decorators/middleware.decorator.ts +1 -1
  22. package/src/index.ts +2 -5
  23. package/src/{app.ts → internal/app.ts} +8 -8
  24. package/src/{bootstrap.ts → internal/bootstrap.ts} +4 -4
  25. package/src/{request.ts → internal/request.ts} +2 -2
  26. package/src/{router.ts → internal/router.ts} +9 -9
  27. package/src/{routes.ts → internal/routes.ts} +2 -2
  28. package/src/{socket.ts → internal/socket.ts} +2 -2
  29. package/src/main.ts +7 -7
  30. package/src/non-electron-process.ts +1 -1
  31. package/src/preload.ts +10 -0
  32. package/src/renderer.ts +13 -0
  33. package/tsup.config.ts +27 -11
  34. /package/src/{exceptions.ts → internal/exceptions.ts} +0 -0
  35. /package/src/{preload-bridge.ts → internal/preload-bridge.ts} +0 -0
  36. /package/src/{renderer-client.ts → internal/renderer-client.ts} +0 -0
  37. /package/src/{renderer-events.ts → internal/renderer-events.ts} +0 -0
package/dist/main.js CHANGED
@@ -633,10 +633,172 @@ var init_method_decorator = __esm({
633
633
  }
634
634
  });
635
635
 
636
- // src/exceptions.ts
636
+ // src/utils/radix-tree.ts
637
+ var _RadixNode, RadixNode, _RadixTree, RadixTree;
638
+ var init_radix_tree = __esm({
639
+ "src/utils/radix-tree.ts"() {
640
+ "use strict";
641
+ _RadixNode = class _RadixNode {
642
+ /**
643
+ * Creates a new RadixNode.
644
+ * @param segment - The segment of the path this node represents.
645
+ */
646
+ constructor(segment) {
647
+ this.children = [];
648
+ this.segment = segment;
649
+ this.isParam = segment.startsWith(":");
650
+ if (this.isParam) {
651
+ this.paramName = segment.slice(1);
652
+ }
653
+ }
654
+ /**
655
+ * Matches a child node against a given segment.
656
+ * This method checks if the segment matches any of the children nodes.
657
+ * @param segment - The segment to match against the children of this node.
658
+ * @returns A child node that matches the segment, or undefined if no match is found.
659
+ */
660
+ matchChild(segment) {
661
+ for (const child of this.children) {
662
+ if (child.isParam || segment.startsWith(child.segment))
663
+ return child;
664
+ }
665
+ return void 0;
666
+ }
667
+ /**
668
+ * Finds a child node that matches the segment exactly.
669
+ * This method checks if there is a child node that matches the segment exactly.
670
+ * @param segment - The segment to find an exact match for among the children of this node.
671
+ * @returns A child node that matches the segment exactly, or undefined if no match is found.
672
+ */
673
+ findExactChild(segment) {
674
+ return this.children.find((c) => c.segment === segment);
675
+ }
676
+ /**
677
+ * Adds a child node to this node's children.
678
+ * This method adds a new child node to the list of children for this node.
679
+ * @param node - The child node to add to this node's children.
680
+ */
681
+ addChild(node) {
682
+ this.children.push(node);
683
+ }
684
+ };
685
+ __name(_RadixNode, "RadixNode");
686
+ RadixNode = _RadixNode;
687
+ _RadixTree = class _RadixTree {
688
+ constructor() {
689
+ this.root = new RadixNode("");
690
+ }
691
+ /**
692
+ * Inserts a path and its associated value into the Radix Tree.
693
+ * This method normalizes the path and inserts it into the tree, associating it with
694
+ * @param path - The path to insert into the tree.
695
+ * @param value - The value to associate with the path.
696
+ */
697
+ insert(path2, value) {
698
+ const segments = this.normalize(path2);
699
+ this.insertRecursive(this.root, segments, value);
700
+ }
701
+ /**
702
+ * Recursively inserts a path into the Radix Tree.
703
+ * This method traverses the tree and inserts the segments of the path, creating new nodes
704
+ * @param node - The node to start inserting from.
705
+ * @param segments - The segments of the path to insert.
706
+ * @param value - The value to associate with the path.
707
+ */
708
+ insertRecursive(node, segments, value) {
709
+ if (segments.length === 0) {
710
+ node.value = value;
711
+ return;
712
+ }
713
+ const segment = segments[0] ?? "";
714
+ let child = node.children.find(
715
+ (c) => c.isParam === segment.startsWith(":") && (c.isParam || c.segment === segment)
716
+ );
717
+ if (!child) {
718
+ child = new RadixNode(segment);
719
+ node.addChild(child);
720
+ }
721
+ this.insertRecursive(child, segments.slice(1), value);
722
+ }
723
+ /**
724
+ * Searches for a path in the Radix Tree.
725
+ * This method normalizes the path and searches for it in the tree, returning the node
726
+ * @param path - The path to search for in the Radix Tree.
727
+ * @returns An ISearchResult containing the node and parameters if a match is found, otherwise undefined.
728
+ */
729
+ search(path2) {
730
+ const segments = this.normalize(path2);
731
+ return this.searchRecursive(this.root, segments, {});
732
+ }
733
+ /**
734
+ * Recursively searches for a path in the Radix Tree.
735
+ * This method traverses the tree and searches for the segments of the path, collecting parameters
736
+ * @param node - The node to start searching from.
737
+ * @param segments - The segments of the path to search for.
738
+ * @param params - The parameters collected during the search.
739
+ * @returns An ISearchResult containing the node and parameters if a match is found, otherwise undefined.
740
+ */
741
+ searchRecursive(node, segments, params) {
742
+ if (segments.length === 0) {
743
+ if (node.value !== void 0) {
744
+ return {
745
+ node,
746
+ params
747
+ };
748
+ }
749
+ return void 0;
750
+ }
751
+ const [segment, ...rest] = segments;
752
+ for (const child of node.children) {
753
+ if (child.isParam) {
754
+ const paramName = child.paramName;
755
+ const childParams = {
756
+ ...params,
757
+ [paramName]: segment ?? ""
758
+ };
759
+ if (rest.length === 0) {
760
+ return {
761
+ node: child,
762
+ params: childParams
763
+ };
764
+ }
765
+ const result = this.searchRecursive(child, rest, childParams);
766
+ if (result)
767
+ return result;
768
+ } else if (segment === child.segment) {
769
+ if (rest.length === 0) {
770
+ return {
771
+ node: child,
772
+ params
773
+ };
774
+ }
775
+ const result = this.searchRecursive(child, rest, params);
776
+ if (result)
777
+ return result;
778
+ }
779
+ }
780
+ return void 0;
781
+ }
782
+ /**
783
+ * Normalizes a path into an array of segments.
784
+ * This method removes leading and trailing slashes, splits the path by slashes, and
785
+ * @param path - The path to normalize.
786
+ * @returns An array of normalized path segments.
787
+ */
788
+ normalize(path2) {
789
+ const segments = path2.replace(/^\/+|\/+$/g, "").split("/").filter(Boolean);
790
+ return ["", ...segments];
791
+ }
792
+ };
793
+ __name(_RadixTree, "RadixTree");
794
+ RadixTree = _RadixTree;
795
+ }
796
+ });
797
+
798
+ // src/internal/exceptions.ts
637
799
  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
800
  var init_exceptions = __esm({
639
- "src/exceptions.ts"() {
801
+ "src/internal/exceptions.ts"() {
640
802
  "use strict";
641
803
  _ResponseException = class _ResponseException extends Error {
642
804
  constructor(statusOrMessage, message) {
@@ -843,7 +1005,7 @@ var init_exceptions = __esm({
843
1005
  }
844
1006
  });
845
1007
 
846
- // src/request.ts
1008
+ // src/internal/request.ts
847
1009
  function createRendererEventMessage(event, payload) {
848
1010
  return {
849
1011
  type: RENDERER_EVENT_TYPE,
@@ -860,7 +1022,7 @@ function isRendererEventMessage(value) {
860
1022
  }
861
1023
  var _Request, Request, RENDERER_EVENT_TYPE;
862
1024
  var init_request = __esm({
863
- "src/request.ts"() {
1025
+ "src/internal/request.ts"() {
864
1026
  "use strict";
865
1027
  init_app_injector();
866
1028
  _Request = class _Request {
@@ -884,185 +1046,23 @@ var init_request = __esm({
884
1046
  }
885
1047
  });
886
1048
 
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
1049
+ // src/internal/router.ts
1050
1050
  var router_exports = {};
1051
1051
  __export(router_exports, {
1052
1052
  Router: () => Router
1053
1053
  });
1054
1054
  var Router;
1055
1055
  var init_router = __esm({
1056
- "src/router.ts"() {
1056
+ "src/internal/router.ts"() {
1057
1057
  "use strict";
1058
1058
  init_controller_decorator();
1059
1059
  init_injectable_decorator();
1060
1060
  init_method_decorator();
1061
1061
  init_injector_explorer();
1062
- init_exceptions();
1063
- init_request();
1064
1062
  init_logger();
1065
1063
  init_radix_tree();
1064
+ init_exceptions();
1065
+ init_request();
1066
1066
  Router = class {
1067
1067
  constructor() {
1068
1068
  this.routes = new RadixTree();
@@ -1362,66 +1362,11 @@ init_app_injector();
1362
1362
  init_token();
1363
1363
  init_router();
1364
1364
 
1365
- // src/app.ts
1365
+ // src/internal/app.ts
1366
1366
  var import_main2 = require("electron/main");
1367
1367
  init_injectable_decorator();
1368
1368
  init_app_injector();
1369
1369
  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
1370
  init_logger();
1426
1371
 
1427
1372
  // src/window/window-manager.ts
@@ -1593,7 +1538,62 @@ WindowManager = __decorateClass([
1593
1538
  Injectable({ lifetime: "singleton" })
1594
1539
  ], WindowManager);
1595
1540
 
1596
- // src/app.ts
1541
+ // src/internal/app.ts
1542
+ init_request();
1543
+ init_router();
1544
+
1545
+ // src/internal/socket.ts
1546
+ init_injectable_decorator();
1547
+ init_logger();
1548
+ init_request();
1549
+ var NoxSocket = class {
1550
+ constructor() {
1551
+ this.channels = /* @__PURE__ */ new Map();
1552
+ }
1553
+ register(senderId, requestChannel, socketChannel) {
1554
+ this.channels.set(senderId, { request: requestChannel, socket: socketChannel });
1555
+ }
1556
+ get(senderId) {
1557
+ return this.channels.get(senderId);
1558
+ }
1559
+ unregister(senderId) {
1560
+ this.channels.delete(senderId);
1561
+ }
1562
+ getSenderIds() {
1563
+ return [...this.channels.keys()];
1564
+ }
1565
+ emit(eventName, payload, targetSenderIds) {
1566
+ const normalizedEvent = eventName.trim();
1567
+ if (normalizedEvent.length === 0) {
1568
+ throw new Error("Renderer event name must be a non-empty string.");
1569
+ }
1570
+ const recipients = targetSenderIds ?? this.getSenderIds();
1571
+ let delivered = 0;
1572
+ for (const senderId of recipients) {
1573
+ const channel = this.channels.get(senderId);
1574
+ if (!channel) {
1575
+ Logger.warn(`No message channel found for sender ID: ${senderId} while emitting "${normalizedEvent}".`);
1576
+ continue;
1577
+ }
1578
+ try {
1579
+ channel.socket.port1.postMessage(createRendererEventMessage(normalizedEvent, payload));
1580
+ delivered++;
1581
+ } catch (error) {
1582
+ Logger.error(`[Noxus] Failed to emit "${normalizedEvent}" to sender ${senderId}.`, error);
1583
+ }
1584
+ }
1585
+ return delivered;
1586
+ }
1587
+ emitToRenderer(senderId, eventName, payload) {
1588
+ return this.emit(eventName, payload, [senderId]) > 0;
1589
+ }
1590
+ };
1591
+ __name(NoxSocket, "NoxSocket");
1592
+ NoxSocket = __decorateClass([
1593
+ Injectable({ lifetime: "singleton" })
1594
+ ], NoxSocket);
1595
+
1596
+ // src/internal/app.ts
1597
1597
  var NoxApp = class {
1598
1598
  constructor() {
1599
1599
  this.router = inject(Router);
@@ -1735,7 +1735,7 @@ NoxApp = __decorateClass([
1735
1735
  Injectable({ lifetime: "singleton", deps: [Router, NoxSocket, WindowManager] })
1736
1736
  ], NoxApp);
1737
1737
 
1738
- // src/bootstrap.ts
1738
+ // src/internal/bootstrap.ts
1739
1739
  var import_main3 = require("electron/main");
1740
1740
  init_app_injector();
1741
1741
  init_injector_explorer();
@@ -1770,7 +1770,7 @@ init_logger();
1770
1770
  init_forward_ref();
1771
1771
  init_request();
1772
1772
 
1773
- // src/routes.ts
1773
+ // src/internal/routes.ts
1774
1774
  function defineRoutes(routes) {
1775
1775
  const paths = routes.map((r) => r.path.replace(/^\/+|\/+$/g, ""));
1776
1776
  const duplicates = paths.filter((p, i) => paths.indexOf(p) !== i);