@noxfly/noxus 1.0.4 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +16 -0
- package/README.md +108 -6
- package/dist/noxus.d.mts +108 -12
- package/dist/noxus.d.ts +108 -12
- package/dist/noxus.js +287 -85
- package/dist/noxus.mjs +280 -85
- package/dist/noxus.mjs.map +1 -1
- package/eslint.config.js +1 -0
- package/package.json +3 -2
- package/scripts/postbuild.js +26 -0
- package/src/DI/app-injector.ts +15 -2
- package/src/DI/injector-explorer.ts +6 -0
- package/src/app.ts +153 -0
- package/src/bootstrap.ts +13 -112
- package/src/decorators/controller.decorator.ts +6 -0
- package/src/decorators/guards.decorator.ts +8 -2
- package/src/decorators/injectable.decorator.ts +6 -0
- package/src/decorators/method.decorator.ts +6 -0
- package/src/decorators/middleware.decorator.ts +54 -0
- package/src/decorators/module.decorator.ts +5 -1
- package/src/exceptions.ts +48 -26
- package/src/index.ts +7 -0
- package/src/request.ts +9 -7
- package/src/router.ts +103 -19
- package/src/utils/logger.ts +6 -0
- package/src/utils/radix-tree.ts +6 -0
- package/src/utils/types.ts +6 -0
- package/tsup.config.ts +11 -0
- package/dist/noxus.js.map +0 -1
- package/images/screenshot-requests.png +0 -0
- package/images/screenshot-startup.png +0 -0
package/dist/noxus.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright 2025 NoxFly
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @author NoxFly
|
|
5
|
+
*/
|
|
1
6
|
"use strict";
|
|
2
7
|
var __defProp = Object.defineProperty;
|
|
3
8
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -23,6 +28,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
23
28
|
// src/index.ts
|
|
24
29
|
var src_exports = {};
|
|
25
30
|
__export(src_exports, {
|
|
31
|
+
AppInjector: () => AppInjector,
|
|
26
32
|
Authorize: () => Authorize,
|
|
27
33
|
BadGatewayException: () => BadGatewayException,
|
|
28
34
|
BadRequestException: () => BadRequestException,
|
|
@@ -49,7 +55,9 @@ __export(src_exports, {
|
|
|
49
55
|
NotExtendedException: () => NotExtendedException,
|
|
50
56
|
NotFoundException: () => NotFoundException,
|
|
51
57
|
NotImplementedException: () => NotImplementedException,
|
|
58
|
+
NoxApp: () => NoxApp,
|
|
52
59
|
Patch: () => Patch,
|
|
60
|
+
PaymentRequiredException: () => PaymentRequiredException,
|
|
53
61
|
Post: () => Post,
|
|
54
62
|
Put: () => Put,
|
|
55
63
|
ROUTE_METADATA_KEY: () => ROUTE_METADATA_KEY,
|
|
@@ -62,14 +70,18 @@ __export(src_exports, {
|
|
|
62
70
|
TooManyRequestsException: () => TooManyRequestsException,
|
|
63
71
|
UnauthorizedException: () => UnauthorizedException,
|
|
64
72
|
UpgradeRequiredException: () => UpgradeRequiredException,
|
|
73
|
+
UseMiddlewares: () => UseMiddlewares,
|
|
65
74
|
VariantAlsoNegotiatesException: () => VariantAlsoNegotiatesException,
|
|
66
75
|
bootstrapApplication: () => bootstrapApplication,
|
|
67
76
|
getControllerMetadata: () => getControllerMetadata,
|
|
68
77
|
getGuardForController: () => getGuardForController,
|
|
69
78
|
getGuardForControllerAction: () => getGuardForControllerAction,
|
|
70
79
|
getInjectableMetadata: () => getInjectableMetadata,
|
|
80
|
+
getMiddlewaresForController: () => getMiddlewaresForController,
|
|
81
|
+
getMiddlewaresForControllerAction: () => getMiddlewaresForControllerAction,
|
|
71
82
|
getModuleMetadata: () => getModuleMetadata,
|
|
72
|
-
getRouteMetadata: () => getRouteMetadata
|
|
83
|
+
getRouteMetadata: () => getRouteMetadata,
|
|
84
|
+
inject: () => inject
|
|
73
85
|
});
|
|
74
86
|
module.exports = __toCommonJS(src_exports);
|
|
75
87
|
|
|
@@ -78,8 +90,18 @@ var import_reflect_metadata = require("reflect-metadata");
|
|
|
78
90
|
|
|
79
91
|
// src/exceptions.ts
|
|
80
92
|
var _ResponseException = class _ResponseException extends Error {
|
|
81
|
-
constructor(message
|
|
82
|
-
|
|
93
|
+
constructor(statusOrMessage, message) {
|
|
94
|
+
let statusCode;
|
|
95
|
+
if (typeof statusOrMessage === "number") {
|
|
96
|
+
statusCode = statusOrMessage;
|
|
97
|
+
} else if (typeof statusOrMessage === "string") {
|
|
98
|
+
message = statusOrMessage;
|
|
99
|
+
}
|
|
100
|
+
super(message ?? "");
|
|
101
|
+
__publicField(this, "status", 0);
|
|
102
|
+
if (statusCode !== void 0) {
|
|
103
|
+
this.status = statusCode;
|
|
104
|
+
}
|
|
83
105
|
this.name = this.constructor.name.replace(/([A-Z])/g, " $1");
|
|
84
106
|
}
|
|
85
107
|
};
|
|
@@ -101,6 +123,14 @@ var _UnauthorizedException = class _UnauthorizedException extends ResponseExcept
|
|
|
101
123
|
};
|
|
102
124
|
__name(_UnauthorizedException, "UnauthorizedException");
|
|
103
125
|
var UnauthorizedException = _UnauthorizedException;
|
|
126
|
+
var _PaymentRequiredException = class _PaymentRequiredException extends ResponseException {
|
|
127
|
+
constructor() {
|
|
128
|
+
super(...arguments);
|
|
129
|
+
__publicField(this, "status", 402);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
__name(_PaymentRequiredException, "PaymentRequiredException");
|
|
133
|
+
var PaymentRequiredException = _PaymentRequiredException;
|
|
104
134
|
var _ForbiddenException = class _ForbiddenException extends ResponseException {
|
|
105
135
|
constructor() {
|
|
106
136
|
super(...arguments);
|
|
@@ -263,8 +293,7 @@ __name(_NetworkConnectTimeoutException, "NetworkConnectTimeoutException");
|
|
|
263
293
|
var NetworkConnectTimeoutException = _NetworkConnectTimeoutException;
|
|
264
294
|
|
|
265
295
|
// src/DI/app-injector.ts
|
|
266
|
-
var
|
|
267
|
-
var AppInjector = (_a = class {
|
|
296
|
+
var _AppInjector = class _AppInjector {
|
|
268
297
|
constructor(name = null) {
|
|
269
298
|
__publicField(this, "name");
|
|
270
299
|
__publicField(this, "bindings", /* @__PURE__ */ new Map());
|
|
@@ -277,7 +306,7 @@ var AppInjector = (_a = class {
|
|
|
277
306
|
* au niveau "scope" (donc durée de vie d'une requête)
|
|
278
307
|
*/
|
|
279
308
|
createScope() {
|
|
280
|
-
const scope = new
|
|
309
|
+
const scope = new _AppInjector();
|
|
281
310
|
scope.bindings = this.bindings;
|
|
282
311
|
scope.singletons = this.singletons;
|
|
283
312
|
return scope;
|
|
@@ -288,7 +317,8 @@ var AppInjector = (_a = class {
|
|
|
288
317
|
*/
|
|
289
318
|
resolve(target) {
|
|
290
319
|
const binding = this.bindings.get(target);
|
|
291
|
-
if (!binding) throw new InternalServerException(`Failed to resolve a dependency injection : No binding for type ${target.name}
|
|
320
|
+
if (!binding) throw new InternalServerException(`Failed to resolve a dependency injection : No binding for type ${target.name}.
|
|
321
|
+
Did you forget to use @Injectable() decorator ?`);
|
|
292
322
|
switch (binding.lifetime) {
|
|
293
323
|
case "transient":
|
|
294
324
|
return this.instantiate(binding.implementation);
|
|
@@ -317,8 +347,14 @@ var AppInjector = (_a = class {
|
|
|
317
347
|
const params = paramTypes.map((p) => this.resolve(p));
|
|
318
348
|
return new target(...params);
|
|
319
349
|
}
|
|
320
|
-
}
|
|
350
|
+
};
|
|
351
|
+
__name(_AppInjector, "AppInjector");
|
|
352
|
+
var AppInjector = _AppInjector;
|
|
321
353
|
var RootInjector = new AppInjector("root");
|
|
354
|
+
function inject(t) {
|
|
355
|
+
return RootInjector.resolve(t);
|
|
356
|
+
}
|
|
357
|
+
__name(inject, "inject");
|
|
322
358
|
|
|
323
359
|
// src/router.ts
|
|
324
360
|
var import_reflect_metadata2 = require("reflect-metadata");
|
|
@@ -453,7 +489,7 @@ function Authorize(...guardClasses) {
|
|
|
453
489
|
if (authorizations.has(key)) {
|
|
454
490
|
throw new Error(`Guard(s) already registered for ${key}`);
|
|
455
491
|
}
|
|
456
|
-
Logger.debug(`Registering
|
|
492
|
+
Logger.debug(`Registering guard(s) for ${key}: ${guardClasses.map((c) => c.name).join(", ")}`);
|
|
457
493
|
authorizations.set(key, guardClasses);
|
|
458
494
|
};
|
|
459
495
|
}
|
|
@@ -616,9 +652,41 @@ function getControllerMetadata(target) {
|
|
|
616
652
|
}
|
|
617
653
|
__name(getControllerMetadata, "getControllerMetadata");
|
|
618
654
|
|
|
655
|
+
// src/decorators/middleware.decorator.ts
|
|
656
|
+
var middlewares = /* @__PURE__ */ new Map();
|
|
657
|
+
function UseMiddlewares(mdlw) {
|
|
658
|
+
return (target, propertyKey) => {
|
|
659
|
+
let key;
|
|
660
|
+
if (propertyKey) {
|
|
661
|
+
const ctrlName = target.constructor.name;
|
|
662
|
+
const actionName = propertyKey;
|
|
663
|
+
key = `${ctrlName}.${actionName}`;
|
|
664
|
+
} else {
|
|
665
|
+
const ctrlName = target.name;
|
|
666
|
+
key = `${ctrlName}`;
|
|
667
|
+
}
|
|
668
|
+
if (middlewares.has(key)) {
|
|
669
|
+
throw new Error(`Middlewares(s) already registered for ${key}`);
|
|
670
|
+
}
|
|
671
|
+
Logger.debug(`Registering middleware(s) for ${key}: ${mdlw.map((c) => c.name).join(", ")}`);
|
|
672
|
+
middlewares.set(key, mdlw);
|
|
673
|
+
};
|
|
674
|
+
}
|
|
675
|
+
__name(UseMiddlewares, "UseMiddlewares");
|
|
676
|
+
function getMiddlewaresForController(controllerName) {
|
|
677
|
+
const key = `${controllerName}`;
|
|
678
|
+
return middlewares.get(key) ?? [];
|
|
679
|
+
}
|
|
680
|
+
__name(getMiddlewaresForController, "getMiddlewaresForController");
|
|
681
|
+
function getMiddlewaresForControllerAction(controllerName, actionName) {
|
|
682
|
+
const key = `${controllerName}.${actionName}`;
|
|
683
|
+
return middlewares.get(key) ?? [];
|
|
684
|
+
}
|
|
685
|
+
__name(getMiddlewaresForControllerAction, "getMiddlewaresForControllerAction");
|
|
686
|
+
|
|
619
687
|
// src/utils/radix-tree.ts
|
|
620
|
-
var
|
|
621
|
-
var RadixNode = (
|
|
688
|
+
var _a;
|
|
689
|
+
var RadixNode = (_a = class {
|
|
622
690
|
constructor(segment) {
|
|
623
691
|
__publicField(this, "segment");
|
|
624
692
|
__publicField(this, "children", []);
|
|
@@ -643,7 +711,7 @@ var RadixNode = (_a2 = class {
|
|
|
643
711
|
addChild(node) {
|
|
644
712
|
this.children.push(node);
|
|
645
713
|
}
|
|
646
|
-
}, __name(
|
|
714
|
+
}, __name(_a, "RadixNode"), _a);
|
|
647
715
|
var _RadixTree = class _RadixTree {
|
|
648
716
|
constructor() {
|
|
649
717
|
__publicField(this, "root", new RadixNode(""));
|
|
@@ -730,19 +798,29 @@ __name(_ts_decorate, "_ts_decorate");
|
|
|
730
798
|
var _Router = class _Router {
|
|
731
799
|
constructor() {
|
|
732
800
|
__publicField(this, "routes", new RadixTree());
|
|
801
|
+
__publicField(this, "rootMiddlewares", []);
|
|
733
802
|
}
|
|
803
|
+
/**
|
|
804
|
+
*
|
|
805
|
+
*/
|
|
734
806
|
registerController(controllerClass) {
|
|
735
807
|
const controllerMeta = getControllerMetadata(controllerClass);
|
|
736
808
|
const controllerGuards = getGuardForController(controllerClass.name);
|
|
809
|
+
const controllerMiddlewares = getMiddlewaresForController(controllerClass.name);
|
|
737
810
|
if (!controllerMeta) throw new Error(`Missing @Controller decorator on ${controllerClass.name}`);
|
|
738
811
|
const routeMetadata = getRouteMetadata(controllerClass);
|
|
739
812
|
for (const def of routeMetadata) {
|
|
740
813
|
const fullPath = `${controllerMeta.path}/${def.path}`.replace(/\/+/g, "/");
|
|
741
814
|
const routeGuards = getGuardForControllerAction(controllerClass.name, def.handler);
|
|
815
|
+
const routeMiddlewares = getMiddlewaresForControllerAction(controllerClass.name, def.handler);
|
|
742
816
|
const guards = /* @__PURE__ */ new Set([
|
|
743
817
|
...controllerGuards,
|
|
744
818
|
...routeGuards
|
|
745
819
|
]);
|
|
820
|
+
const middlewares2 = /* @__PURE__ */ new Set([
|
|
821
|
+
...controllerMiddlewares,
|
|
822
|
+
...routeMiddlewares
|
|
823
|
+
]);
|
|
746
824
|
const routeDef = {
|
|
747
825
|
method: def.method,
|
|
748
826
|
path: fullPath,
|
|
@@ -750,6 +828,9 @@ var _Router = class _Router {
|
|
|
750
828
|
handler: def.handler,
|
|
751
829
|
guards: [
|
|
752
830
|
...guards
|
|
831
|
+
],
|
|
832
|
+
middlewares: [
|
|
833
|
+
...middlewares2
|
|
753
834
|
]
|
|
754
835
|
};
|
|
755
836
|
this.routes.insert(fullPath + "/" + def.method, routeDef);
|
|
@@ -762,6 +843,17 @@ var _Router = class _Router {
|
|
|
762
843
|
Logger.log(`Mapped ${controllerClass.name}${controllerGuardsInfo} controller's routes`);
|
|
763
844
|
return this;
|
|
764
845
|
}
|
|
846
|
+
/**
|
|
847
|
+
*
|
|
848
|
+
*/
|
|
849
|
+
defineRootMiddleware(middleware) {
|
|
850
|
+
Logger.debug(`Registering root middleware: ${middleware.name}`);
|
|
851
|
+
this.rootMiddlewares.push(middleware);
|
|
852
|
+
return this;
|
|
853
|
+
}
|
|
854
|
+
/**
|
|
855
|
+
*
|
|
856
|
+
*/
|
|
765
857
|
async handle(request) {
|
|
766
858
|
Logger.log(`> Received request: {${request.method} /${request.path}}`);
|
|
767
859
|
const t0 = performance.now();
|
|
@@ -773,10 +865,10 @@ var _Router = class _Router {
|
|
|
773
865
|
};
|
|
774
866
|
try {
|
|
775
867
|
const routeDef = this.findRoute(request);
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
868
|
+
await this.resolveController(request, response, routeDef);
|
|
869
|
+
if (response.status > 400) {
|
|
870
|
+
throw new ResponseException(response.status, response.error);
|
|
871
|
+
}
|
|
780
872
|
} catch (error) {
|
|
781
873
|
if (error instanceof ResponseException) {
|
|
782
874
|
response.status = error.status;
|
|
@@ -800,6 +892,9 @@ var _Router = class _Router {
|
|
|
800
892
|
return response;
|
|
801
893
|
}
|
|
802
894
|
}
|
|
895
|
+
/**
|
|
896
|
+
*
|
|
897
|
+
*/
|
|
803
898
|
findRoute(request) {
|
|
804
899
|
const matchedRoutes = this.routes.search(request.path);
|
|
805
900
|
if (matchedRoutes?.node === void 0 || matchedRoutes.node.children.length === 0) {
|
|
@@ -811,21 +906,68 @@ var _Router = class _Router {
|
|
|
811
906
|
}
|
|
812
907
|
return routeDef.value;
|
|
813
908
|
}
|
|
814
|
-
|
|
909
|
+
/**
|
|
910
|
+
*
|
|
911
|
+
*/
|
|
912
|
+
async resolveController(request, response, routeDef) {
|
|
815
913
|
const controllerInstance = request.context.resolve(routeDef.controller);
|
|
816
914
|
Object.assign(request.params, this.extractParams(request.path, routeDef.path));
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
915
|
+
await this.runRequestPipeline(request, response, routeDef, controllerInstance);
|
|
916
|
+
}
|
|
917
|
+
/**
|
|
918
|
+
*
|
|
919
|
+
*/
|
|
920
|
+
async runRequestPipeline(request, response, routeDef, controllerInstance) {
|
|
921
|
+
const middlewares2 = [
|
|
922
|
+
.../* @__PURE__ */ new Set([
|
|
923
|
+
...this.rootMiddlewares,
|
|
924
|
+
...routeDef.middlewares
|
|
925
|
+
])
|
|
926
|
+
];
|
|
927
|
+
const middlewareMaxIndex = middlewares2.length - 1;
|
|
928
|
+
const guardsMaxIndex = middlewareMaxIndex + routeDef.guards.length;
|
|
929
|
+
let index = -1;
|
|
930
|
+
const dispatch = /* @__PURE__ */ __name(async (i) => {
|
|
931
|
+
if (i <= index) throw new Error("next() called multiple times");
|
|
932
|
+
index = i;
|
|
933
|
+
if (i <= middlewareMaxIndex) {
|
|
934
|
+
const nextFn = dispatch.bind(null, i + 1);
|
|
935
|
+
await this.runMiddleware(request, response, nextFn, middlewares2[i]);
|
|
936
|
+
if (response.status >= 400) {
|
|
937
|
+
throw new ResponseException(response.status, response.error);
|
|
938
|
+
}
|
|
939
|
+
return;
|
|
822
940
|
}
|
|
823
|
-
|
|
824
|
-
|
|
941
|
+
if (i <= guardsMaxIndex) {
|
|
942
|
+
const guardIndex = i - middlewares2.length;
|
|
943
|
+
const guardType = routeDef.guards[guardIndex];
|
|
944
|
+
await this.runGuard(request, guardType);
|
|
945
|
+
dispatch(i + 1);
|
|
946
|
+
return;
|
|
947
|
+
}
|
|
948
|
+
const action = controllerInstance[routeDef.handler];
|
|
949
|
+
response.body = await action.call(controllerInstance, request, response);
|
|
950
|
+
}, "dispatch");
|
|
951
|
+
await dispatch(0);
|
|
952
|
+
}
|
|
953
|
+
/**
|
|
954
|
+
*
|
|
955
|
+
*/
|
|
956
|
+
async runMiddleware(request, response, next, middlewareType) {
|
|
957
|
+
const middleware = request.context.resolve(middlewareType);
|
|
958
|
+
await middleware.invoke(request, response, next);
|
|
825
959
|
}
|
|
826
|
-
|
|
827
|
-
|
|
960
|
+
/**
|
|
961
|
+
*
|
|
962
|
+
*/
|
|
963
|
+
async runGuard(request, guardType) {
|
|
964
|
+
const guard = request.context.resolve(guardType);
|
|
965
|
+
const allowed = await guard.canActivate(request);
|
|
966
|
+
if (!allowed) throw new UnauthorizedException(`Unauthorized for ${request.method} ${request.path}`);
|
|
828
967
|
}
|
|
968
|
+
/**
|
|
969
|
+
*
|
|
970
|
+
*/
|
|
829
971
|
extractParams(actual, template) {
|
|
830
972
|
const aParts = actual.split("/");
|
|
831
973
|
const tParts = template.split("/");
|
|
@@ -844,15 +986,13 @@ Router = _ts_decorate([
|
|
|
844
986
|
Injectable("singleton")
|
|
845
987
|
], Router);
|
|
846
988
|
|
|
847
|
-
// src/
|
|
848
|
-
var import_electron = require("electron");
|
|
989
|
+
// src/app.ts
|
|
849
990
|
var import_main = require("electron/main");
|
|
850
991
|
|
|
851
992
|
// src/request.ts
|
|
852
993
|
var import_reflect_metadata3 = require("reflect-metadata");
|
|
853
994
|
var _Request = class _Request {
|
|
854
|
-
constructor(
|
|
855
|
-
__publicField(this, "app");
|
|
995
|
+
constructor(event, id, method, path, body) {
|
|
856
996
|
__publicField(this, "event");
|
|
857
997
|
__publicField(this, "id");
|
|
858
998
|
__publicField(this, "method");
|
|
@@ -860,7 +1000,6 @@ var _Request = class _Request {
|
|
|
860
1000
|
__publicField(this, "body");
|
|
861
1001
|
__publicField(this, "context", RootInjector.createScope());
|
|
862
1002
|
__publicField(this, "params", {});
|
|
863
|
-
this.app = app2;
|
|
864
1003
|
this.event = event;
|
|
865
1004
|
this.id = id;
|
|
866
1005
|
this.method = method;
|
|
@@ -872,69 +1011,68 @@ var _Request = class _Request {
|
|
|
872
1011
|
__name(_Request, "Request");
|
|
873
1012
|
var Request = _Request;
|
|
874
1013
|
|
|
875
|
-
// src/
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
throw new Error(`Root application must be decorated with @Injectable`);
|
|
882
|
-
}
|
|
883
|
-
await import_main.app.whenReady();
|
|
884
|
-
RootInjector.resolve(Router);
|
|
885
|
-
const noxEngine = new Nox(root, rootModule);
|
|
886
|
-
const application = await noxEngine.init();
|
|
887
|
-
return application;
|
|
1014
|
+
// src/app.ts
|
|
1015
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
1016
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1017
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1018
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1019
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
888
1020
|
}
|
|
889
|
-
__name(
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
this
|
|
897
|
-
this
|
|
1021
|
+
__name(_ts_decorate2, "_ts_decorate");
|
|
1022
|
+
function _ts_metadata(k, v) {
|
|
1023
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1024
|
+
}
|
|
1025
|
+
__name(_ts_metadata, "_ts_metadata");
|
|
1026
|
+
var _NoxApp = class _NoxApp {
|
|
1027
|
+
constructor(router) {
|
|
1028
|
+
__publicField(this, "router");
|
|
1029
|
+
__publicField(this, "messagePorts", /* @__PURE__ */ new Map());
|
|
1030
|
+
__publicField(this, "app");
|
|
1031
|
+
this.router = router;
|
|
898
1032
|
}
|
|
899
1033
|
/**
|
|
900
1034
|
*
|
|
901
1035
|
*/
|
|
902
1036
|
async init() {
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
import_main.app.once("
|
|
906
|
-
import_main.app.once("window-all-closed", this.onAllWindowsClosed.bind(this, application));
|
|
907
|
-
await application.onReady();
|
|
1037
|
+
import_main.ipcMain.on("gimme-my-port", this.giveTheRendererAPort.bind(this));
|
|
1038
|
+
import_main.app.once("activate", this.onAppActivated.bind(this));
|
|
1039
|
+
import_main.app.once("window-all-closed", this.onAllWindowsClosed.bind(this));
|
|
908
1040
|
console.log("");
|
|
909
|
-
return
|
|
1041
|
+
return this;
|
|
910
1042
|
}
|
|
911
1043
|
/**
|
|
912
1044
|
*
|
|
913
1045
|
*/
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
this.
|
|
918
|
-
this.messagePort = void 0;
|
|
1046
|
+
giveTheRendererAPort(event) {
|
|
1047
|
+
const senderId = event.sender.id;
|
|
1048
|
+
if (this.messagePorts.has(senderId)) {
|
|
1049
|
+
this.shutdownChannel(senderId);
|
|
919
1050
|
}
|
|
920
|
-
|
|
921
|
-
this.
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
1051
|
+
const channel = new import_main.MessageChannelMain();
|
|
1052
|
+
this.messagePorts.set(senderId, channel);
|
|
1053
|
+
channel.port1.on("message", this.onRendererMessage.bind(this));
|
|
1054
|
+
channel.port1.start();
|
|
1055
|
+
event.sender.postMessage("port", {
|
|
1056
|
+
senderId
|
|
1057
|
+
}, [
|
|
1058
|
+
channel.port2
|
|
925
1059
|
]);
|
|
926
1060
|
}
|
|
927
1061
|
/**
|
|
928
1062
|
* Electron specific message handling.
|
|
929
1063
|
* Replaces HTTP calls by using Electron's IPC mechanism.
|
|
930
1064
|
*/
|
|
931
|
-
async
|
|
932
|
-
const { requestId, path, method, body } = event.data;
|
|
1065
|
+
async onRendererMessage(event) {
|
|
1066
|
+
const { senderId, requestId, path, method, body } = event.data;
|
|
1067
|
+
const channel = this.messagePorts.get(senderId);
|
|
1068
|
+
if (!channel) {
|
|
1069
|
+
Logger.error(`No message channel found for sender ID: ${senderId}`);
|
|
1070
|
+
return;
|
|
1071
|
+
}
|
|
933
1072
|
try {
|
|
934
|
-
const request = new Request(
|
|
935
|
-
const
|
|
936
|
-
|
|
937
|
-
this.messagePort?.port1.postMessage(response);
|
|
1073
|
+
const request = new Request(event, requestId, method, path, body);
|
|
1074
|
+
const response = await this.router.handle(request);
|
|
1075
|
+
channel.port1.postMessage(response);
|
|
938
1076
|
} catch (err) {
|
|
939
1077
|
const response = {
|
|
940
1078
|
requestId,
|
|
@@ -942,30 +1080,83 @@ var Nox = (_a3 = class {
|
|
|
942
1080
|
body: null,
|
|
943
1081
|
error: err.message || "Internal Server Error"
|
|
944
1082
|
};
|
|
945
|
-
|
|
1083
|
+
channel.port1.postMessage(response);
|
|
946
1084
|
}
|
|
947
1085
|
}
|
|
948
1086
|
/**
|
|
949
|
-
*
|
|
1087
|
+
* MacOS specific behavior.
|
|
950
1088
|
*/
|
|
951
|
-
onAppActivated(
|
|
952
|
-
if (import_main.BrowserWindow.getAllWindows().length === 0) {
|
|
953
|
-
|
|
1089
|
+
onAppActivated() {
|
|
1090
|
+
if (process.platform === "darwin" && import_main.BrowserWindow.getAllWindows().length === 0) {
|
|
1091
|
+
this.app?.onActivated();
|
|
954
1092
|
}
|
|
955
1093
|
}
|
|
1094
|
+
shutdownChannel(channelSenderId, remove = true) {
|
|
1095
|
+
const channel = this.messagePorts.get(channelSenderId);
|
|
1096
|
+
if (!channel) {
|
|
1097
|
+
Logger.warn(`No message channel found for sender ID: ${channelSenderId}`);
|
|
1098
|
+
return;
|
|
1099
|
+
}
|
|
1100
|
+
channel.port1.off("message", this.onRendererMessage.bind(this));
|
|
1101
|
+
channel.port1.close();
|
|
1102
|
+
channel.port2.close();
|
|
1103
|
+
this.messagePorts.delete(channelSenderId);
|
|
1104
|
+
}
|
|
956
1105
|
/**
|
|
957
1106
|
*
|
|
958
1107
|
*/
|
|
959
|
-
async onAllWindowsClosed(
|
|
960
|
-
this.
|
|
961
|
-
|
|
1108
|
+
async onAllWindowsClosed() {
|
|
1109
|
+
this.messagePorts.forEach((channel, senderId) => {
|
|
1110
|
+
this.shutdownChannel(senderId, false);
|
|
1111
|
+
});
|
|
1112
|
+
this.messagePorts.clear();
|
|
1113
|
+
this.app?.dispose();
|
|
962
1114
|
if (process.platform !== "darwin") {
|
|
963
1115
|
import_main.app.quit();
|
|
964
1116
|
}
|
|
965
1117
|
}
|
|
966
|
-
|
|
1118
|
+
// ---
|
|
1119
|
+
configure(app3) {
|
|
1120
|
+
this.app = inject(app3);
|
|
1121
|
+
return this;
|
|
1122
|
+
}
|
|
1123
|
+
use(middleware) {
|
|
1124
|
+
this.router.defineRootMiddleware(middleware);
|
|
1125
|
+
return this;
|
|
1126
|
+
}
|
|
1127
|
+
/**
|
|
1128
|
+
* Should be called after the bootstrapApplication function is called.
|
|
1129
|
+
*/
|
|
1130
|
+
start() {
|
|
1131
|
+
this.app?.onReady();
|
|
1132
|
+
return this;
|
|
1133
|
+
}
|
|
1134
|
+
};
|
|
1135
|
+
__name(_NoxApp, "NoxApp");
|
|
1136
|
+
var NoxApp = _NoxApp;
|
|
1137
|
+
NoxApp = _ts_decorate2([
|
|
1138
|
+
Injectable("singleton"),
|
|
1139
|
+
_ts_metadata("design:type", Function),
|
|
1140
|
+
_ts_metadata("design:paramtypes", [
|
|
1141
|
+
typeof Router === "undefined" ? Object : Router
|
|
1142
|
+
])
|
|
1143
|
+
], NoxApp);
|
|
1144
|
+
|
|
1145
|
+
// src/bootstrap.ts
|
|
1146
|
+
var import_main2 = require("electron/main");
|
|
1147
|
+
async function bootstrapApplication(rootModule) {
|
|
1148
|
+
if (!getModuleMetadata(rootModule)) {
|
|
1149
|
+
throw new Error(`Root module must be decorated with @Module`);
|
|
1150
|
+
}
|
|
1151
|
+
await import_main2.app.whenReady();
|
|
1152
|
+
const noxApp = inject(NoxApp);
|
|
1153
|
+
await noxApp.init();
|
|
1154
|
+
return noxApp;
|
|
1155
|
+
}
|
|
1156
|
+
__name(bootstrapApplication, "bootstrapApplication");
|
|
967
1157
|
// Annotate the CommonJS export names for ESM import in node:
|
|
968
1158
|
0 && (module.exports = {
|
|
1159
|
+
AppInjector,
|
|
969
1160
|
Authorize,
|
|
970
1161
|
BadGatewayException,
|
|
971
1162
|
BadRequestException,
|
|
@@ -992,7 +1183,9 @@ var Nox = (_a3 = class {
|
|
|
992
1183
|
NotExtendedException,
|
|
993
1184
|
NotFoundException,
|
|
994
1185
|
NotImplementedException,
|
|
1186
|
+
NoxApp,
|
|
995
1187
|
Patch,
|
|
1188
|
+
PaymentRequiredException,
|
|
996
1189
|
Post,
|
|
997
1190
|
Put,
|
|
998
1191
|
ROUTE_METADATA_KEY,
|
|
@@ -1005,13 +1198,22 @@ var Nox = (_a3 = class {
|
|
|
1005
1198
|
TooManyRequestsException,
|
|
1006
1199
|
UnauthorizedException,
|
|
1007
1200
|
UpgradeRequiredException,
|
|
1201
|
+
UseMiddlewares,
|
|
1008
1202
|
VariantAlsoNegotiatesException,
|
|
1009
1203
|
bootstrapApplication,
|
|
1010
1204
|
getControllerMetadata,
|
|
1011
1205
|
getGuardForController,
|
|
1012
1206
|
getGuardForControllerAction,
|
|
1013
1207
|
getInjectableMetadata,
|
|
1208
|
+
getMiddlewaresForController,
|
|
1209
|
+
getMiddlewaresForControllerAction,
|
|
1014
1210
|
getModuleMetadata,
|
|
1015
|
-
getRouteMetadata
|
|
1211
|
+
getRouteMetadata,
|
|
1212
|
+
inject
|
|
1016
1213
|
});
|
|
1214
|
+
/**
|
|
1215
|
+
* @copyright 2025 NoxFly
|
|
1216
|
+
* @license MIT
|
|
1217
|
+
* @author NoxFly
|
|
1218
|
+
*/
|
|
1017
1219
|
//# sourceMappingURL=noxus.js.map
|