@noxfly/noxus 2.4.0 → 2.5.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/dist/child.js +115 -10
- package/dist/child.mjs +115 -10
- package/dist/main.d.mts +72 -21
- package/dist/main.d.ts +72 -21
- package/dist/main.js +160 -381
- package/dist/main.mjs +161 -379
- package/dist/renderer.d.mts +112 -1
- package/dist/renderer.d.ts +112 -1
- package/dist/renderer.js +40 -2
- package/dist/renderer.mjs +39 -2
- package/dist/{index-BxWQVi6C.d.ts → request-CdpZ9qZL.d.ts} +1 -87
- package/dist/{index-DQBQQfMw.d.mts → request-Dx_5Prte.d.mts} +1 -87
- package/package.json +1 -1
- package/src/DI/injector-explorer.ts +49 -4
- package/src/app.ts +37 -0
- package/src/bootstrap.ts +18 -3
- package/src/index.ts +1 -0
- package/src/main.ts +0 -3
- package/src/router.ts +99 -6
package/dist/child.js
CHANGED
|
@@ -963,6 +963,7 @@ var _Router = class _Router {
|
|
|
963
963
|
constructor() {
|
|
964
964
|
__publicField(this, "routes", new RadixTree());
|
|
965
965
|
__publicField(this, "rootMiddlewares", []);
|
|
966
|
+
__publicField(this, "lazyRoutes", /* @__PURE__ */ new Map());
|
|
966
967
|
}
|
|
967
968
|
/**
|
|
968
969
|
* Registers a controller class with the router.
|
|
@@ -1010,6 +1011,24 @@ var _Router = class _Router {
|
|
|
1010
1011
|
Logger.log(`Mapped ${controllerClass.name}${controllerGuardsInfo} controller's routes`);
|
|
1011
1012
|
return this;
|
|
1012
1013
|
}
|
|
1014
|
+
/**
|
|
1015
|
+
* Registers a lazy route. The module behind this route prefix will only
|
|
1016
|
+
* be imported (and its controllers/services registered in DI) the first
|
|
1017
|
+
* time a request targets this prefix.
|
|
1018
|
+
*
|
|
1019
|
+
* @param pathPrefix - Route prefix (e.g. "auth"). Matched against the first segment of the request path.
|
|
1020
|
+
* @param loadModule - A function that returns a dynamic import promise.
|
|
1021
|
+
*/
|
|
1022
|
+
registerLazyRoute(pathPrefix, loadModule) {
|
|
1023
|
+
const normalized = pathPrefix.replace(/^\/+|\/+$/g, "");
|
|
1024
|
+
this.lazyRoutes.set(normalized, {
|
|
1025
|
+
loadModule,
|
|
1026
|
+
loading: null,
|
|
1027
|
+
loaded: false
|
|
1028
|
+
});
|
|
1029
|
+
Logger.log(`Registered lazy route prefix {${normalized}}`);
|
|
1030
|
+
return this;
|
|
1031
|
+
}
|
|
1013
1032
|
/**
|
|
1014
1033
|
* Defines a middleware for the root of the application.
|
|
1015
1034
|
* This method allows you to register a middleware that will be applied to all requests
|
|
@@ -1042,7 +1061,7 @@ var _Router = class _Router {
|
|
|
1042
1061
|
};
|
|
1043
1062
|
let isCritical = false;
|
|
1044
1063
|
try {
|
|
1045
|
-
const routeDef = this.findRoute(request);
|
|
1064
|
+
const routeDef = await this.findRoute(request);
|
|
1046
1065
|
await this.resolveController(request, response, routeDef);
|
|
1047
1066
|
if (response.status > 400) {
|
|
1048
1067
|
throw new ResponseException(response.status, response.error);
|
|
@@ -1200,16 +1219,62 @@ var _Router = class _Router {
|
|
|
1200
1219
|
* @param request - The Request object containing the method and path to search for.
|
|
1201
1220
|
* @returns The IRouteDefinition for the matched route.
|
|
1202
1221
|
*/
|
|
1203
|
-
|
|
1222
|
+
/**
|
|
1223
|
+
* Attempts to find a route definition for the given request.
|
|
1224
|
+
* Returns undefined instead of throwing when the route is not found,
|
|
1225
|
+
* so the caller can try lazy-loading first.
|
|
1226
|
+
*/
|
|
1227
|
+
tryFindRoute(request) {
|
|
1204
1228
|
const matchedRoutes = this.routes.search(request.path);
|
|
1205
1229
|
if (matchedRoutes?.node === void 0 || matchedRoutes.node.children.length === 0) {
|
|
1206
|
-
|
|
1230
|
+
return void 0;
|
|
1207
1231
|
}
|
|
1208
1232
|
const routeDef = matchedRoutes.node.findExactChild(request.method);
|
|
1209
|
-
|
|
1210
|
-
|
|
1233
|
+
return routeDef?.value;
|
|
1234
|
+
}
|
|
1235
|
+
/**
|
|
1236
|
+
* Finds the route definition for a given request.
|
|
1237
|
+
* If no eagerly-registered route matches, attempts to load a lazy module
|
|
1238
|
+
* whose prefix matches the request path, then retries.
|
|
1239
|
+
*/
|
|
1240
|
+
async findRoute(request) {
|
|
1241
|
+
const direct = this.tryFindRoute(request);
|
|
1242
|
+
if (direct) return direct;
|
|
1243
|
+
await this.tryLoadLazyRoute(request.path);
|
|
1244
|
+
const afterLazy = this.tryFindRoute(request);
|
|
1245
|
+
if (afterLazy) return afterLazy;
|
|
1246
|
+
throw new NotFoundException(`No route matches ${request.method} ${request.path}`);
|
|
1247
|
+
}
|
|
1248
|
+
/**
|
|
1249
|
+
* Given a request path, checks whether a lazy route prefix matches
|
|
1250
|
+
* and triggers the dynamic import if it hasn't been loaded yet.
|
|
1251
|
+
*/
|
|
1252
|
+
async tryLoadLazyRoute(requestPath) {
|
|
1253
|
+
const firstSegment = requestPath.replace(/^\/+/, "").split("/")[0] ?? "";
|
|
1254
|
+
for (const [prefix, entry] of this.lazyRoutes) {
|
|
1255
|
+
if (entry.loaded) continue;
|
|
1256
|
+
const normalizedPath = requestPath.replace(/^\/+/, "");
|
|
1257
|
+
if (normalizedPath === prefix || normalizedPath.startsWith(prefix + "/") || firstSegment === prefix) {
|
|
1258
|
+
if (!entry.loading) {
|
|
1259
|
+
entry.loading = this.loadLazyModule(prefix, entry);
|
|
1260
|
+
}
|
|
1261
|
+
await entry.loading;
|
|
1262
|
+
return;
|
|
1263
|
+
}
|
|
1211
1264
|
}
|
|
1212
|
-
|
|
1265
|
+
}
|
|
1266
|
+
/**
|
|
1267
|
+
* Dynamically imports a lazy module and registers its decorated classes
|
|
1268
|
+
* (controllers, services) in the DI container using the two-phase strategy.
|
|
1269
|
+
*/
|
|
1270
|
+
async loadLazyModule(prefix, entry) {
|
|
1271
|
+
const t0 = performance.now();
|
|
1272
|
+
InjectorExplorer.beginAccumulate();
|
|
1273
|
+
await entry.loadModule();
|
|
1274
|
+
InjectorExplorer.flushAccumulated();
|
|
1275
|
+
entry.loaded = true;
|
|
1276
|
+
const t1 = performance.now();
|
|
1277
|
+
Logger.info(`Lazy-loaded module for prefix {${prefix}} in ${Math.round(t1 - t0)}ms`);
|
|
1213
1278
|
}
|
|
1214
1279
|
/**
|
|
1215
1280
|
* Resolves the controller for a given route definition.
|
|
@@ -1333,12 +1398,17 @@ var _InjectorExplorer = class _InjectorExplorer {
|
|
|
1333
1398
|
* Enqueues a class for deferred registration.
|
|
1334
1399
|
* Called by the @Injectable decorator at import time.
|
|
1335
1400
|
*
|
|
1336
|
-
* If {@link processPending} has already been called (i.e. after bootstrap)
|
|
1337
|
-
*
|
|
1338
|
-
* (e.g. middlewares loaded after bootstrap)
|
|
1401
|
+
* If {@link processPending} has already been called (i.e. after bootstrap)
|
|
1402
|
+
* and accumulation mode is not active, the class is registered immediately
|
|
1403
|
+
* so that late dynamic imports (e.g. middlewares loaded after bootstrap)
|
|
1404
|
+
* work correctly.
|
|
1405
|
+
*
|
|
1406
|
+
* When accumulation mode is active (between {@link beginAccumulate} and
|
|
1407
|
+
* {@link flushAccumulated}), classes are queued instead — preserving the
|
|
1408
|
+
* two-phase binding/resolution guarantee for lazy-loaded modules.
|
|
1339
1409
|
*/
|
|
1340
1410
|
static enqueue(target, lifetime) {
|
|
1341
|
-
if (_InjectorExplorer.processed) {
|
|
1411
|
+
if (_InjectorExplorer.processed && !_InjectorExplorer.accumulating) {
|
|
1342
1412
|
_InjectorExplorer.registerImmediate(target, lifetime);
|
|
1343
1413
|
return;
|
|
1344
1414
|
}
|
|
@@ -1347,6 +1417,40 @@ var _InjectorExplorer = class _InjectorExplorer {
|
|
|
1347
1417
|
lifetime
|
|
1348
1418
|
});
|
|
1349
1419
|
}
|
|
1420
|
+
/**
|
|
1421
|
+
* Enters accumulation mode. While active, all decorated classes discovered
|
|
1422
|
+
* via dynamic imports are queued in {@link pending} rather than registered
|
|
1423
|
+
* immediately. Call {@link flushAccumulated} to process them with the
|
|
1424
|
+
* full two-phase (bind-then-resolve) guarantee.
|
|
1425
|
+
*/
|
|
1426
|
+
static beginAccumulate() {
|
|
1427
|
+
_InjectorExplorer.accumulating = true;
|
|
1428
|
+
}
|
|
1429
|
+
/**
|
|
1430
|
+
* Exits accumulation mode and processes every class queued since
|
|
1431
|
+
* {@link beginAccumulate} was called. Uses the same two-phase strategy
|
|
1432
|
+
* as {@link processPending} (register all bindings first, then resolve
|
|
1433
|
+
* singletons / controllers) so import ordering within a lazy batch
|
|
1434
|
+
* does not cause resolution failures.
|
|
1435
|
+
*/
|
|
1436
|
+
static flushAccumulated() {
|
|
1437
|
+
_InjectorExplorer.accumulating = false;
|
|
1438
|
+
const queue = [
|
|
1439
|
+
..._InjectorExplorer.pending
|
|
1440
|
+
];
|
|
1441
|
+
_InjectorExplorer.pending.length = 0;
|
|
1442
|
+
for (const { target, lifetime } of queue) {
|
|
1443
|
+
if (!RootInjector.bindings.has(target)) {
|
|
1444
|
+
RootInjector.bindings.set(target, {
|
|
1445
|
+
implementation: target,
|
|
1446
|
+
lifetime
|
|
1447
|
+
});
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
for (const { target, lifetime } of queue) {
|
|
1451
|
+
_InjectorExplorer.processRegistration(target, lifetime);
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1350
1454
|
/**
|
|
1351
1455
|
* Processes all pending registrations in two phases:
|
|
1352
1456
|
* 1. Register all bindings (no instantiation) so every dependency is known.
|
|
@@ -1414,6 +1518,7 @@ var _InjectorExplorer = class _InjectorExplorer {
|
|
|
1414
1518
|
__name(_InjectorExplorer, "InjectorExplorer");
|
|
1415
1519
|
__publicField(_InjectorExplorer, "pending", []);
|
|
1416
1520
|
__publicField(_InjectorExplorer, "processed", false);
|
|
1521
|
+
__publicField(_InjectorExplorer, "accumulating", false);
|
|
1417
1522
|
var InjectorExplorer = _InjectorExplorer;
|
|
1418
1523
|
|
|
1419
1524
|
// src/decorators/injectable.decorator.ts
|
package/dist/child.mjs
CHANGED
|
@@ -894,6 +894,7 @@ var _Router = class _Router {
|
|
|
894
894
|
constructor() {
|
|
895
895
|
__publicField(this, "routes", new RadixTree());
|
|
896
896
|
__publicField(this, "rootMiddlewares", []);
|
|
897
|
+
__publicField(this, "lazyRoutes", /* @__PURE__ */ new Map());
|
|
897
898
|
}
|
|
898
899
|
/**
|
|
899
900
|
* Registers a controller class with the router.
|
|
@@ -941,6 +942,24 @@ var _Router = class _Router {
|
|
|
941
942
|
Logger.log(`Mapped ${controllerClass.name}${controllerGuardsInfo} controller's routes`);
|
|
942
943
|
return this;
|
|
943
944
|
}
|
|
945
|
+
/**
|
|
946
|
+
* Registers a lazy route. The module behind this route prefix will only
|
|
947
|
+
* be imported (and its controllers/services registered in DI) the first
|
|
948
|
+
* time a request targets this prefix.
|
|
949
|
+
*
|
|
950
|
+
* @param pathPrefix - Route prefix (e.g. "auth"). Matched against the first segment of the request path.
|
|
951
|
+
* @param loadModule - A function that returns a dynamic import promise.
|
|
952
|
+
*/
|
|
953
|
+
registerLazyRoute(pathPrefix, loadModule) {
|
|
954
|
+
const normalized = pathPrefix.replace(/^\/+|\/+$/g, "");
|
|
955
|
+
this.lazyRoutes.set(normalized, {
|
|
956
|
+
loadModule,
|
|
957
|
+
loading: null,
|
|
958
|
+
loaded: false
|
|
959
|
+
});
|
|
960
|
+
Logger.log(`Registered lazy route prefix {${normalized}}`);
|
|
961
|
+
return this;
|
|
962
|
+
}
|
|
944
963
|
/**
|
|
945
964
|
* Defines a middleware for the root of the application.
|
|
946
965
|
* This method allows you to register a middleware that will be applied to all requests
|
|
@@ -973,7 +992,7 @@ var _Router = class _Router {
|
|
|
973
992
|
};
|
|
974
993
|
let isCritical = false;
|
|
975
994
|
try {
|
|
976
|
-
const routeDef = this.findRoute(request);
|
|
995
|
+
const routeDef = await this.findRoute(request);
|
|
977
996
|
await this.resolveController(request, response, routeDef);
|
|
978
997
|
if (response.status > 400) {
|
|
979
998
|
throw new ResponseException(response.status, response.error);
|
|
@@ -1131,16 +1150,62 @@ var _Router = class _Router {
|
|
|
1131
1150
|
* @param request - The Request object containing the method and path to search for.
|
|
1132
1151
|
* @returns The IRouteDefinition for the matched route.
|
|
1133
1152
|
*/
|
|
1134
|
-
|
|
1153
|
+
/**
|
|
1154
|
+
* Attempts to find a route definition for the given request.
|
|
1155
|
+
* Returns undefined instead of throwing when the route is not found,
|
|
1156
|
+
* so the caller can try lazy-loading first.
|
|
1157
|
+
*/
|
|
1158
|
+
tryFindRoute(request) {
|
|
1135
1159
|
const matchedRoutes = this.routes.search(request.path);
|
|
1136
1160
|
if (matchedRoutes?.node === void 0 || matchedRoutes.node.children.length === 0) {
|
|
1137
|
-
|
|
1161
|
+
return void 0;
|
|
1138
1162
|
}
|
|
1139
1163
|
const routeDef = matchedRoutes.node.findExactChild(request.method);
|
|
1140
|
-
|
|
1141
|
-
|
|
1164
|
+
return routeDef?.value;
|
|
1165
|
+
}
|
|
1166
|
+
/**
|
|
1167
|
+
* Finds the route definition for a given request.
|
|
1168
|
+
* If no eagerly-registered route matches, attempts to load a lazy module
|
|
1169
|
+
* whose prefix matches the request path, then retries.
|
|
1170
|
+
*/
|
|
1171
|
+
async findRoute(request) {
|
|
1172
|
+
const direct = this.tryFindRoute(request);
|
|
1173
|
+
if (direct) return direct;
|
|
1174
|
+
await this.tryLoadLazyRoute(request.path);
|
|
1175
|
+
const afterLazy = this.tryFindRoute(request);
|
|
1176
|
+
if (afterLazy) return afterLazy;
|
|
1177
|
+
throw new NotFoundException(`No route matches ${request.method} ${request.path}`);
|
|
1178
|
+
}
|
|
1179
|
+
/**
|
|
1180
|
+
* Given a request path, checks whether a lazy route prefix matches
|
|
1181
|
+
* and triggers the dynamic import if it hasn't been loaded yet.
|
|
1182
|
+
*/
|
|
1183
|
+
async tryLoadLazyRoute(requestPath) {
|
|
1184
|
+
const firstSegment = requestPath.replace(/^\/+/, "").split("/")[0] ?? "";
|
|
1185
|
+
for (const [prefix, entry] of this.lazyRoutes) {
|
|
1186
|
+
if (entry.loaded) continue;
|
|
1187
|
+
const normalizedPath = requestPath.replace(/^\/+/, "");
|
|
1188
|
+
if (normalizedPath === prefix || normalizedPath.startsWith(prefix + "/") || firstSegment === prefix) {
|
|
1189
|
+
if (!entry.loading) {
|
|
1190
|
+
entry.loading = this.loadLazyModule(prefix, entry);
|
|
1191
|
+
}
|
|
1192
|
+
await entry.loading;
|
|
1193
|
+
return;
|
|
1194
|
+
}
|
|
1142
1195
|
}
|
|
1143
|
-
|
|
1196
|
+
}
|
|
1197
|
+
/**
|
|
1198
|
+
* Dynamically imports a lazy module and registers its decorated classes
|
|
1199
|
+
* (controllers, services) in the DI container using the two-phase strategy.
|
|
1200
|
+
*/
|
|
1201
|
+
async loadLazyModule(prefix, entry) {
|
|
1202
|
+
const t0 = performance.now();
|
|
1203
|
+
InjectorExplorer.beginAccumulate();
|
|
1204
|
+
await entry.loadModule();
|
|
1205
|
+
InjectorExplorer.flushAccumulated();
|
|
1206
|
+
entry.loaded = true;
|
|
1207
|
+
const t1 = performance.now();
|
|
1208
|
+
Logger.info(`Lazy-loaded module for prefix {${prefix}} in ${Math.round(t1 - t0)}ms`);
|
|
1144
1209
|
}
|
|
1145
1210
|
/**
|
|
1146
1211
|
* Resolves the controller for a given route definition.
|
|
@@ -1264,12 +1329,17 @@ var _InjectorExplorer = class _InjectorExplorer {
|
|
|
1264
1329
|
* Enqueues a class for deferred registration.
|
|
1265
1330
|
* Called by the @Injectable decorator at import time.
|
|
1266
1331
|
*
|
|
1267
|
-
* If {@link processPending} has already been called (i.e. after bootstrap)
|
|
1268
|
-
*
|
|
1269
|
-
* (e.g. middlewares loaded after bootstrap)
|
|
1332
|
+
* If {@link processPending} has already been called (i.e. after bootstrap)
|
|
1333
|
+
* and accumulation mode is not active, the class is registered immediately
|
|
1334
|
+
* so that late dynamic imports (e.g. middlewares loaded after bootstrap)
|
|
1335
|
+
* work correctly.
|
|
1336
|
+
*
|
|
1337
|
+
* When accumulation mode is active (between {@link beginAccumulate} and
|
|
1338
|
+
* {@link flushAccumulated}), classes are queued instead — preserving the
|
|
1339
|
+
* two-phase binding/resolution guarantee for lazy-loaded modules.
|
|
1270
1340
|
*/
|
|
1271
1341
|
static enqueue(target, lifetime) {
|
|
1272
|
-
if (_InjectorExplorer.processed) {
|
|
1342
|
+
if (_InjectorExplorer.processed && !_InjectorExplorer.accumulating) {
|
|
1273
1343
|
_InjectorExplorer.registerImmediate(target, lifetime);
|
|
1274
1344
|
return;
|
|
1275
1345
|
}
|
|
@@ -1278,6 +1348,40 @@ var _InjectorExplorer = class _InjectorExplorer {
|
|
|
1278
1348
|
lifetime
|
|
1279
1349
|
});
|
|
1280
1350
|
}
|
|
1351
|
+
/**
|
|
1352
|
+
* Enters accumulation mode. While active, all decorated classes discovered
|
|
1353
|
+
* via dynamic imports are queued in {@link pending} rather than registered
|
|
1354
|
+
* immediately. Call {@link flushAccumulated} to process them with the
|
|
1355
|
+
* full two-phase (bind-then-resolve) guarantee.
|
|
1356
|
+
*/
|
|
1357
|
+
static beginAccumulate() {
|
|
1358
|
+
_InjectorExplorer.accumulating = true;
|
|
1359
|
+
}
|
|
1360
|
+
/**
|
|
1361
|
+
* Exits accumulation mode and processes every class queued since
|
|
1362
|
+
* {@link beginAccumulate} was called. Uses the same two-phase strategy
|
|
1363
|
+
* as {@link processPending} (register all bindings first, then resolve
|
|
1364
|
+
* singletons / controllers) so import ordering within a lazy batch
|
|
1365
|
+
* does not cause resolution failures.
|
|
1366
|
+
*/
|
|
1367
|
+
static flushAccumulated() {
|
|
1368
|
+
_InjectorExplorer.accumulating = false;
|
|
1369
|
+
const queue = [
|
|
1370
|
+
..._InjectorExplorer.pending
|
|
1371
|
+
];
|
|
1372
|
+
_InjectorExplorer.pending.length = 0;
|
|
1373
|
+
for (const { target, lifetime } of queue) {
|
|
1374
|
+
if (!RootInjector.bindings.has(target)) {
|
|
1375
|
+
RootInjector.bindings.set(target, {
|
|
1376
|
+
implementation: target,
|
|
1377
|
+
lifetime
|
|
1378
|
+
});
|
|
1379
|
+
}
|
|
1380
|
+
}
|
|
1381
|
+
for (const { target, lifetime } of queue) {
|
|
1382
|
+
_InjectorExplorer.processRegistration(target, lifetime);
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1281
1385
|
/**
|
|
1282
1386
|
* Processes all pending registrations in two phases:
|
|
1283
1387
|
* 1. Register all bindings (no instantiation) so every dependency is known.
|
|
@@ -1345,6 +1449,7 @@ var _InjectorExplorer = class _InjectorExplorer {
|
|
|
1345
1449
|
__name(_InjectorExplorer, "InjectorExplorer");
|
|
1346
1450
|
__publicField(_InjectorExplorer, "pending", []);
|
|
1347
1451
|
__publicField(_InjectorExplorer, "processed", false);
|
|
1452
|
+
__publicField(_InjectorExplorer, "accumulating", false);
|
|
1348
1453
|
var InjectorExplorer = _InjectorExplorer;
|
|
1349
1454
|
|
|
1350
1455
|
// src/decorators/injectable.decorator.ts
|
package/dist/main.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { M as MaybeAsync, T as Type } from './app-injector-B3MvgV3k.mjs';
|
|
2
2
|
export { A as AppInjector, F as ForwardRefFn, a as ForwardReference, I as IBinding, L as Lifetime, R as RootInjector, f as forwardRef, i as inject } from './app-injector-B3MvgV3k.mjs';
|
|
3
|
-
import { R as Request,
|
|
4
|
-
export {
|
|
3
|
+
import { R as Request, a as IResponse, h as IGuard } from './request-Dx_5Prte.mjs';
|
|
4
|
+
export { A as AtomicHttpMethod, j as Authorize, D as Delete, G as Get, H as HttpMethod, c as IBatchRequestItem, e as IBatchRequestPayload, d as IBatchResponsePayload, I as IRendererEventMessage, b as IRequest, m as IRouteMetadata, p as Patch, P as Post, o as Put, f as RENDERER_EVENT_TYPE, q as ROUTE_METADATA_KEY, g as createRendererEventMessage, k as getGuardForController, l as getGuardForControllerAction, n as getRouteMetadata, i as isRendererEventMessage } from './request-Dx_5Prte.mjs';
|
|
5
5
|
import { BrowserWindow } from 'electron/main';
|
|
6
6
|
export { BadGatewayException, BadRequestException, ConflictException, ForbiddenException, GatewayTimeoutException, HttpVersionNotSupportedException, INJECTABLE_METADATA_KEY, INJECT_METADATA_KEY, Inject, Injectable, InsufficientStorageException, InternalServerException, LogLevel, Logger, LoopDetectedException, MethodNotAllowedException, NetworkAuthenticationRequiredException, NetworkConnectTimeoutException, NotAcceptableException, NotExtendedException, NotFoundException, NotImplementedException, PaymentRequiredException, RequestTimeoutException, ResponseException, ServiceUnavailableException, TooManyRequestsException, UnauthorizedException, UpgradeRequiredException, VariantAlsoNegotiatesException, getInjectableMetadata, hasInjectableMetadata } from './child.mjs';
|
|
7
7
|
|
|
@@ -51,6 +51,16 @@ declare function getMiddlewaresForController(controllerName: string): Type<IMidd
|
|
|
51
51
|
declare function getMiddlewaresForControllerAction(controllerName: string, actionName: string): Type<IMiddleware>[];
|
|
52
52
|
|
|
53
53
|
|
|
54
|
+
/**
|
|
55
|
+
* A lazy route entry maps a path prefix to a dynamic import function.
|
|
56
|
+
* The module is loaded on the first request matching the prefix.
|
|
57
|
+
*/
|
|
58
|
+
interface ILazyRoute {
|
|
59
|
+
/** Path prefix (e.g. "auth", "printing"). Matched against the first segment(s) of the request path. */
|
|
60
|
+
path: string;
|
|
61
|
+
/** Dynamic import function returning the module file. */
|
|
62
|
+
loadModule: () => Promise<unknown>;
|
|
63
|
+
}
|
|
54
64
|
/**
|
|
55
65
|
* IRouteDefinition interface defines the structure of a route in the application.
|
|
56
66
|
* It includes the HTTP method, path, controller class, handler method name,
|
|
@@ -76,6 +86,7 @@ type ControllerAction = (request: Request, response: IResponse) => any;
|
|
|
76
86
|
declare class Router {
|
|
77
87
|
private readonly routes;
|
|
78
88
|
private readonly rootMiddlewares;
|
|
89
|
+
private readonly lazyRoutes;
|
|
79
90
|
/**
|
|
80
91
|
* Registers a controller class with the router.
|
|
81
92
|
* This method extracts the route metadata from the controller class and registers it in the routing tree.
|
|
@@ -83,6 +94,15 @@ declare class Router {
|
|
|
83
94
|
* @param controllerClass - The controller class to register.
|
|
84
95
|
*/
|
|
85
96
|
registerController(controllerClass: Type<unknown>): Router;
|
|
97
|
+
/**
|
|
98
|
+
* Registers a lazy route. The module behind this route prefix will only
|
|
99
|
+
* be imported (and its controllers/services registered in DI) the first
|
|
100
|
+
* time a request targets this prefix.
|
|
101
|
+
*
|
|
102
|
+
* @param pathPrefix - Route prefix (e.g. "auth"). Matched against the first segment of the request path.
|
|
103
|
+
* @param loadModule - A function that returns a dynamic import promise.
|
|
104
|
+
*/
|
|
105
|
+
registerLazyRoute(pathPrefix: string, loadModule: () => Promise<unknown>): Router;
|
|
86
106
|
/**
|
|
87
107
|
* Defines a middleware for the root of the application.
|
|
88
108
|
* This method allows you to register a middleware that will be applied to all requests
|
|
@@ -108,7 +128,28 @@ declare class Router {
|
|
|
108
128
|
* @param request - The Request object containing the method and path to search for.
|
|
109
129
|
* @returns The IRouteDefinition for the matched route.
|
|
110
130
|
*/
|
|
131
|
+
/**
|
|
132
|
+
* Attempts to find a route definition for the given request.
|
|
133
|
+
* Returns undefined instead of throwing when the route is not found,
|
|
134
|
+
* so the caller can try lazy-loading first.
|
|
135
|
+
*/
|
|
136
|
+
private tryFindRoute;
|
|
137
|
+
/**
|
|
138
|
+
* Finds the route definition for a given request.
|
|
139
|
+
* If no eagerly-registered route matches, attempts to load a lazy module
|
|
140
|
+
* whose prefix matches the request path, then retries.
|
|
141
|
+
*/
|
|
111
142
|
private findRoute;
|
|
143
|
+
/**
|
|
144
|
+
* Given a request path, checks whether a lazy route prefix matches
|
|
145
|
+
* and triggers the dynamic import if it hasn't been loaded yet.
|
|
146
|
+
*/
|
|
147
|
+
private tryLoadLazyRoute;
|
|
148
|
+
/**
|
|
149
|
+
* Dynamically imports a lazy module and registers its decorated classes
|
|
150
|
+
* (controllers, services) in the DI container using the two-phase strategy.
|
|
151
|
+
*/
|
|
152
|
+
private loadLazyModule;
|
|
112
153
|
/**
|
|
113
154
|
* Resolves the controller for a given route definition.
|
|
114
155
|
* This method creates an instance of the controller class and prepares the request parameters.
|
|
@@ -239,6 +280,33 @@ declare class NoxApp {
|
|
|
239
280
|
* @param window - The BrowserWindow created during bootstrap.
|
|
240
281
|
*/
|
|
241
282
|
setMainWindow(window: BrowserWindow): void;
|
|
283
|
+
/**
|
|
284
|
+
* Registers a lazy-loaded route. The module behind this path prefix
|
|
285
|
+
* will only be dynamically imported when the first IPC request
|
|
286
|
+
* targets this prefix — like Angular's loadChildren.
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
* ```ts
|
|
290
|
+
* noxApp.lazy("auth", () => import("./modules/auth/auth.module.js"));
|
|
291
|
+
* noxApp.lazy("printing", () => import("./modules/printing/printing.module.js"));
|
|
292
|
+
* ```
|
|
293
|
+
*
|
|
294
|
+
* @param pathPrefix - The route prefix (e.g. "auth", "cash-register").
|
|
295
|
+
* @param loadModule - A function returning a dynamic import promise.
|
|
296
|
+
* @returns NoxApp instance for method chaining.
|
|
297
|
+
*/
|
|
298
|
+
lazy(pathPrefix: string, loadModule: () => Promise<unknown>): NoxApp;
|
|
299
|
+
/**
|
|
300
|
+
* Eagerly loads one or more modules with a two-phase DI guarantee.
|
|
301
|
+
* Use this when a service needed at startup lives inside a module
|
|
302
|
+
* (e.g. the Application service depends on LoaderService).
|
|
303
|
+
*
|
|
304
|
+
* All dynamic imports run in parallel; bindings are registered first,
|
|
305
|
+
* then singletons are resolved — safe regardless of import ordering.
|
|
306
|
+
*
|
|
307
|
+
* @param importFns - Functions returning dynamic import promises.
|
|
308
|
+
*/
|
|
309
|
+
loadModules(importFns: Array<() => Promise<unknown>>): Promise<void>;
|
|
242
310
|
/**
|
|
243
311
|
* Configures the NoxApp instance with the provided application class.
|
|
244
312
|
* This method allows you to set the application class that will handle lifecycle events.
|
|
@@ -288,7 +356,7 @@ interface BootstrapOptions {
|
|
|
288
356
|
* @return A promise that resolves to the NoxApp instance.
|
|
289
357
|
* @throws Error if the root module is not decorated with @Module, or if the electron process could not start.
|
|
290
358
|
*/
|
|
291
|
-
declare function bootstrapApplication(rootModule
|
|
359
|
+
declare function bootstrapApplication(rootModule?: Type<any> | null, options?: BootstrapOptions): Promise<NoxApp>;
|
|
292
360
|
|
|
293
361
|
|
|
294
362
|
/**
|
|
@@ -331,21 +399,4 @@ declare function Module(metadata: IModuleMetadata): ClassDecorator;
|
|
|
331
399
|
declare function getModuleMetadata(target: Function): IModuleMetadata | undefined;
|
|
332
400
|
declare const MODULE_METADATA_KEY: unique symbol;
|
|
333
401
|
|
|
334
|
-
|
|
335
|
-
interface NoxusPreloadAPI extends IPortRequester {
|
|
336
|
-
}
|
|
337
|
-
interface NoxusPreloadOptions {
|
|
338
|
-
exposeAs?: string;
|
|
339
|
-
initMessageType?: string;
|
|
340
|
-
requestChannel?: string;
|
|
341
|
-
responseChannel?: string;
|
|
342
|
-
targetWindow?: Window;
|
|
343
|
-
}
|
|
344
|
-
/**
|
|
345
|
-
* Exposes a minimal bridge in the isolated preload context so renderer processes
|
|
346
|
-
* can request the two MessagePorts required by Noxus. The bridge forwards both
|
|
347
|
-
* request/response and socket ports to the renderer via window.postMessage.
|
|
348
|
-
*/
|
|
349
|
-
declare function exposeNoxusBridge(options?: NoxusPreloadOptions): NoxusPreloadAPI;
|
|
350
|
-
|
|
351
|
-
export { type BootstrapOptions, CONTROLLER_METADATA_KEY, Controller, type ControllerAction, type IApp, type IControllerMetadata, IGuard, type IMiddleware, type IModuleMetadata, IPortRequester, IResponse, type IRouteDefinition, MODULE_METADATA_KEY, MaybeAsync, Module, type NextFunction, NoxApp, NoxSocket, type NoxusPreloadAPI, type NoxusPreloadOptions, Request, Router, Type, UseMiddlewares, bootstrapApplication, exposeNoxusBridge, getControllerMetadata, getMiddlewaresForController, getMiddlewaresForControllerAction, getModuleMetadata };
|
|
402
|
+
export { type BootstrapOptions, CONTROLLER_METADATA_KEY, Controller, type ControllerAction, type IApp, type IControllerMetadata, IGuard, type ILazyRoute, type IMiddleware, type IModuleMetadata, IResponse, type IRouteDefinition, MODULE_METADATA_KEY, MaybeAsync, Module, type NextFunction, NoxApp, NoxSocket, Request, Router, Type, UseMiddlewares, bootstrapApplication, getControllerMetadata, getMiddlewaresForController, getMiddlewaresForControllerAction, getModuleMetadata };
|
package/dist/main.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { M as MaybeAsync, T as Type } from './app-injector-B3MvgV3k.js';
|
|
2
2
|
export { A as AppInjector, F as ForwardRefFn, a as ForwardReference, I as IBinding, L as Lifetime, R as RootInjector, f as forwardRef, i as inject } from './app-injector-B3MvgV3k.js';
|
|
3
|
-
import { R as Request,
|
|
4
|
-
export {
|
|
3
|
+
import { R as Request, a as IResponse, h as IGuard } from './request-CdpZ9qZL.js';
|
|
4
|
+
export { A as AtomicHttpMethod, j as Authorize, D as Delete, G as Get, H as HttpMethod, c as IBatchRequestItem, e as IBatchRequestPayload, d as IBatchResponsePayload, I as IRendererEventMessage, b as IRequest, m as IRouteMetadata, p as Patch, P as Post, o as Put, f as RENDERER_EVENT_TYPE, q as ROUTE_METADATA_KEY, g as createRendererEventMessage, k as getGuardForController, l as getGuardForControllerAction, n as getRouteMetadata, i as isRendererEventMessage } from './request-CdpZ9qZL.js';
|
|
5
5
|
import { BrowserWindow } from 'electron/main';
|
|
6
6
|
export { BadGatewayException, BadRequestException, ConflictException, ForbiddenException, GatewayTimeoutException, HttpVersionNotSupportedException, INJECTABLE_METADATA_KEY, INJECT_METADATA_KEY, Inject, Injectable, InsufficientStorageException, InternalServerException, LogLevel, Logger, LoopDetectedException, MethodNotAllowedException, NetworkAuthenticationRequiredException, NetworkConnectTimeoutException, NotAcceptableException, NotExtendedException, NotFoundException, NotImplementedException, PaymentRequiredException, RequestTimeoutException, ResponseException, ServiceUnavailableException, TooManyRequestsException, UnauthorizedException, UpgradeRequiredException, VariantAlsoNegotiatesException, getInjectableMetadata, hasInjectableMetadata } from './child.js';
|
|
7
7
|
|
|
@@ -51,6 +51,16 @@ declare function getMiddlewaresForController(controllerName: string): Type<IMidd
|
|
|
51
51
|
declare function getMiddlewaresForControllerAction(controllerName: string, actionName: string): Type<IMiddleware>[];
|
|
52
52
|
|
|
53
53
|
|
|
54
|
+
/**
|
|
55
|
+
* A lazy route entry maps a path prefix to a dynamic import function.
|
|
56
|
+
* The module is loaded on the first request matching the prefix.
|
|
57
|
+
*/
|
|
58
|
+
interface ILazyRoute {
|
|
59
|
+
/** Path prefix (e.g. "auth", "printing"). Matched against the first segment(s) of the request path. */
|
|
60
|
+
path: string;
|
|
61
|
+
/** Dynamic import function returning the module file. */
|
|
62
|
+
loadModule: () => Promise<unknown>;
|
|
63
|
+
}
|
|
54
64
|
/**
|
|
55
65
|
* IRouteDefinition interface defines the structure of a route in the application.
|
|
56
66
|
* It includes the HTTP method, path, controller class, handler method name,
|
|
@@ -76,6 +86,7 @@ type ControllerAction = (request: Request, response: IResponse) => any;
|
|
|
76
86
|
declare class Router {
|
|
77
87
|
private readonly routes;
|
|
78
88
|
private readonly rootMiddlewares;
|
|
89
|
+
private readonly lazyRoutes;
|
|
79
90
|
/**
|
|
80
91
|
* Registers a controller class with the router.
|
|
81
92
|
* This method extracts the route metadata from the controller class and registers it in the routing tree.
|
|
@@ -83,6 +94,15 @@ declare class Router {
|
|
|
83
94
|
* @param controllerClass - The controller class to register.
|
|
84
95
|
*/
|
|
85
96
|
registerController(controllerClass: Type<unknown>): Router;
|
|
97
|
+
/**
|
|
98
|
+
* Registers a lazy route. The module behind this route prefix will only
|
|
99
|
+
* be imported (and its controllers/services registered in DI) the first
|
|
100
|
+
* time a request targets this prefix.
|
|
101
|
+
*
|
|
102
|
+
* @param pathPrefix - Route prefix (e.g. "auth"). Matched against the first segment of the request path.
|
|
103
|
+
* @param loadModule - A function that returns a dynamic import promise.
|
|
104
|
+
*/
|
|
105
|
+
registerLazyRoute(pathPrefix: string, loadModule: () => Promise<unknown>): Router;
|
|
86
106
|
/**
|
|
87
107
|
* Defines a middleware for the root of the application.
|
|
88
108
|
* This method allows you to register a middleware that will be applied to all requests
|
|
@@ -108,7 +128,28 @@ declare class Router {
|
|
|
108
128
|
* @param request - The Request object containing the method and path to search for.
|
|
109
129
|
* @returns The IRouteDefinition for the matched route.
|
|
110
130
|
*/
|
|
131
|
+
/**
|
|
132
|
+
* Attempts to find a route definition for the given request.
|
|
133
|
+
* Returns undefined instead of throwing when the route is not found,
|
|
134
|
+
* so the caller can try lazy-loading first.
|
|
135
|
+
*/
|
|
136
|
+
private tryFindRoute;
|
|
137
|
+
/**
|
|
138
|
+
* Finds the route definition for a given request.
|
|
139
|
+
* If no eagerly-registered route matches, attempts to load a lazy module
|
|
140
|
+
* whose prefix matches the request path, then retries.
|
|
141
|
+
*/
|
|
111
142
|
private findRoute;
|
|
143
|
+
/**
|
|
144
|
+
* Given a request path, checks whether a lazy route prefix matches
|
|
145
|
+
* and triggers the dynamic import if it hasn't been loaded yet.
|
|
146
|
+
*/
|
|
147
|
+
private tryLoadLazyRoute;
|
|
148
|
+
/**
|
|
149
|
+
* Dynamically imports a lazy module and registers its decorated classes
|
|
150
|
+
* (controllers, services) in the DI container using the two-phase strategy.
|
|
151
|
+
*/
|
|
152
|
+
private loadLazyModule;
|
|
112
153
|
/**
|
|
113
154
|
* Resolves the controller for a given route definition.
|
|
114
155
|
* This method creates an instance of the controller class and prepares the request parameters.
|
|
@@ -239,6 +280,33 @@ declare class NoxApp {
|
|
|
239
280
|
* @param window - The BrowserWindow created during bootstrap.
|
|
240
281
|
*/
|
|
241
282
|
setMainWindow(window: BrowserWindow): void;
|
|
283
|
+
/**
|
|
284
|
+
* Registers a lazy-loaded route. The module behind this path prefix
|
|
285
|
+
* will only be dynamically imported when the first IPC request
|
|
286
|
+
* targets this prefix — like Angular's loadChildren.
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
* ```ts
|
|
290
|
+
* noxApp.lazy("auth", () => import("./modules/auth/auth.module.js"));
|
|
291
|
+
* noxApp.lazy("printing", () => import("./modules/printing/printing.module.js"));
|
|
292
|
+
* ```
|
|
293
|
+
*
|
|
294
|
+
* @param pathPrefix - The route prefix (e.g. "auth", "cash-register").
|
|
295
|
+
* @param loadModule - A function returning a dynamic import promise.
|
|
296
|
+
* @returns NoxApp instance for method chaining.
|
|
297
|
+
*/
|
|
298
|
+
lazy(pathPrefix: string, loadModule: () => Promise<unknown>): NoxApp;
|
|
299
|
+
/**
|
|
300
|
+
* Eagerly loads one or more modules with a two-phase DI guarantee.
|
|
301
|
+
* Use this when a service needed at startup lives inside a module
|
|
302
|
+
* (e.g. the Application service depends on LoaderService).
|
|
303
|
+
*
|
|
304
|
+
* All dynamic imports run in parallel; bindings are registered first,
|
|
305
|
+
* then singletons are resolved — safe regardless of import ordering.
|
|
306
|
+
*
|
|
307
|
+
* @param importFns - Functions returning dynamic import promises.
|
|
308
|
+
*/
|
|
309
|
+
loadModules(importFns: Array<() => Promise<unknown>>): Promise<void>;
|
|
242
310
|
/**
|
|
243
311
|
* Configures the NoxApp instance with the provided application class.
|
|
244
312
|
* This method allows you to set the application class that will handle lifecycle events.
|
|
@@ -288,7 +356,7 @@ interface BootstrapOptions {
|
|
|
288
356
|
* @return A promise that resolves to the NoxApp instance.
|
|
289
357
|
* @throws Error if the root module is not decorated with @Module, or if the electron process could not start.
|
|
290
358
|
*/
|
|
291
|
-
declare function bootstrapApplication(rootModule
|
|
359
|
+
declare function bootstrapApplication(rootModule?: Type<any> | null, options?: BootstrapOptions): Promise<NoxApp>;
|
|
292
360
|
|
|
293
361
|
|
|
294
362
|
/**
|
|
@@ -331,21 +399,4 @@ declare function Module(metadata: IModuleMetadata): ClassDecorator;
|
|
|
331
399
|
declare function getModuleMetadata(target: Function): IModuleMetadata | undefined;
|
|
332
400
|
declare const MODULE_METADATA_KEY: unique symbol;
|
|
333
401
|
|
|
334
|
-
|
|
335
|
-
interface NoxusPreloadAPI extends IPortRequester {
|
|
336
|
-
}
|
|
337
|
-
interface NoxusPreloadOptions {
|
|
338
|
-
exposeAs?: string;
|
|
339
|
-
initMessageType?: string;
|
|
340
|
-
requestChannel?: string;
|
|
341
|
-
responseChannel?: string;
|
|
342
|
-
targetWindow?: Window;
|
|
343
|
-
}
|
|
344
|
-
/**
|
|
345
|
-
* Exposes a minimal bridge in the isolated preload context so renderer processes
|
|
346
|
-
* can request the two MessagePorts required by Noxus. The bridge forwards both
|
|
347
|
-
* request/response and socket ports to the renderer via window.postMessage.
|
|
348
|
-
*/
|
|
349
|
-
declare function exposeNoxusBridge(options?: NoxusPreloadOptions): NoxusPreloadAPI;
|
|
350
|
-
|
|
351
|
-
export { type BootstrapOptions, CONTROLLER_METADATA_KEY, Controller, type ControllerAction, type IApp, type IControllerMetadata, IGuard, type IMiddleware, type IModuleMetadata, IPortRequester, IResponse, type IRouteDefinition, MODULE_METADATA_KEY, MaybeAsync, Module, type NextFunction, NoxApp, NoxSocket, type NoxusPreloadAPI, type NoxusPreloadOptions, Request, Router, Type, UseMiddlewares, bootstrapApplication, exposeNoxusBridge, getControllerMetadata, getMiddlewaresForController, getMiddlewaresForControllerAction, getModuleMetadata };
|
|
402
|
+
export { type BootstrapOptions, CONTROLLER_METADATA_KEY, Controller, type ControllerAction, type IApp, type IControllerMetadata, IGuard, type ILazyRoute, type IMiddleware, type IModuleMetadata, IResponse, type IRouteDefinition, MODULE_METADATA_KEY, MaybeAsync, Module, type NextFunction, NoxApp, NoxSocket, Request, Router, Type, UseMiddlewares, bootstrapApplication, getControllerMetadata, getMiddlewaresForController, getMiddlewaresForControllerAction, getModuleMetadata };
|