@noxfly/noxus 2.5.0 → 3.0.0-dev.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.
Files changed (48) hide show
  1. package/README.md +403 -341
  2. package/dist/app-injector-Bz3Upc0y.d.mts +125 -0
  3. package/dist/app-injector-Bz3Upc0y.d.ts +125 -0
  4. package/dist/child.d.mts +48 -22
  5. package/dist/child.d.ts +48 -22
  6. package/dist/child.js +1111 -1341
  7. package/dist/child.mjs +1087 -1295
  8. package/dist/main.d.mts +301 -309
  9. package/dist/main.d.ts +301 -309
  10. package/dist/main.js +1471 -1650
  11. package/dist/main.mjs +1420 -1570
  12. package/dist/renderer.d.mts +3 -3
  13. package/dist/renderer.d.ts +3 -3
  14. package/dist/renderer.js +109 -135
  15. package/dist/renderer.mjs +109 -135
  16. package/dist/request-BlTtiHbi.d.ts +112 -0
  17. package/dist/request-qJ9EiDZc.d.mts +112 -0
  18. package/package.json +7 -7
  19. package/src/DI/app-injector.ts +95 -106
  20. package/src/DI/injector-explorer.ts +93 -119
  21. package/src/DI/token.ts +53 -0
  22. package/src/app.ts +141 -168
  23. package/src/bootstrap.ts +78 -54
  24. package/src/decorators/controller.decorator.ts +38 -27
  25. package/src/decorators/guards.decorator.ts +5 -64
  26. package/src/decorators/injectable.decorator.ts +68 -15
  27. package/src/decorators/method.decorator.ts +40 -81
  28. package/src/decorators/middleware.decorator.ts +5 -72
  29. package/src/index.ts +2 -0
  30. package/src/main.ts +4 -8
  31. package/src/non-electron-process.ts +0 -1
  32. package/src/preload-bridge.ts +1 -1
  33. package/src/renderer-client.ts +2 -2
  34. package/src/renderer-events.ts +1 -1
  35. package/src/request.ts +3 -3
  36. package/src/router.ts +190 -431
  37. package/src/routes.ts +78 -0
  38. package/src/socket.ts +4 -4
  39. package/src/window/window-manager.ts +255 -0
  40. package/tsconfig.json +5 -10
  41. package/tsup.config.ts +2 -2
  42. package/dist/app-injector-B3MvgV3k.d.mts +0 -95
  43. package/dist/app-injector-B3MvgV3k.d.ts +0 -95
  44. package/dist/request-CdpZ9qZL.d.ts +0 -167
  45. package/dist/request-Dx_5Prte.d.mts +0 -167
  46. package/src/decorators/inject.decorator.ts +0 -24
  47. package/src/decorators/injectable.metadata.ts +0 -15
  48. package/src/decorators/module.decorator.ts +0 -75
@@ -1,6 +1,6 @@
1
- import { I as IRendererEventMessage, a as IResponse, b as IRequest, c as IBatchRequestItem, d as IBatchResponsePayload } from './request-Dx_5Prte.mjs';
2
- export { A as AtomicHttpMethod, H as HttpMethod, e as IBatchRequestPayload, f as RENDERER_EVENT_TYPE, R as Request, g as createRendererEventMessage, i as isRendererEventMessage } from './request-Dx_5Prte.mjs';
3
- import './app-injector-B3MvgV3k.mjs';
1
+ import { I as IRendererEventMessage, a as IResponse, b as IRequest, c as IBatchRequestItem, d as IBatchResponsePayload } from './request-qJ9EiDZc.mjs';
2
+ export { A as AtomicHttpMethod, H as HttpMethod, e as IBatchRequestPayload, R as RENDERER_EVENT_TYPE, f as Request, g as createRendererEventMessage, i as isRendererEventMessage } from './request-qJ9EiDZc.mjs';
3
+ import './app-injector-Bz3Upc0y.mjs';
4
4
 
5
5
  /**
6
6
  * @copyright 2025 NoxFly
@@ -1,6 +1,6 @@
1
- import { I as IRendererEventMessage, a as IResponse, b as IRequest, c as IBatchRequestItem, d as IBatchResponsePayload } from './request-CdpZ9qZL.js';
2
- export { A as AtomicHttpMethod, H as HttpMethod, e as IBatchRequestPayload, f as RENDERER_EVENT_TYPE, R as Request, g as createRendererEventMessage, i as isRendererEventMessage } from './request-CdpZ9qZL.js';
3
- import './app-injector-B3MvgV3k.js';
1
+ import { I as IRendererEventMessage, a as IResponse, b as IRequest, c as IBatchRequestItem, d as IBatchResponsePayload } from './request-BlTtiHbi.js';
2
+ export { A as AtomicHttpMethod, H as HttpMethod, e as IBatchRequestPayload, R as RENDERER_EVENT_TYPE, f as Request, g as createRendererEventMessage, i as isRendererEventMessage } from './request-BlTtiHbi.js';
3
+ import './app-injector-Bz3Upc0y.js';
4
4
 
5
5
  /**
6
6
  * @copyright 2025 NoxFly
package/dist/renderer.js CHANGED
@@ -8,7 +8,6 @@ var __defProp = Object.defineProperty;
8
8
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
9
9
  var __getOwnPropNames = Object.getOwnPropertyNames;
10
10
  var __hasOwnProp = Object.prototype.hasOwnProperty;
11
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
11
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
13
12
  var __export = (target, all) => {
14
13
  for (var name in all)
@@ -23,7 +22,6 @@ var __copyProps = (to, from, except, desc) => {
23
22
  return to;
24
23
  };
25
24
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
26
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
27
25
 
28
26
  // src/index.ts
29
27
  var src_exports = {};
@@ -38,68 +36,42 @@ __export(src_exports, {
38
36
  });
39
37
  module.exports = __toCommonJS(src_exports);
40
38
 
41
- // src/request.ts
42
- var import_reflect_metadata3 = require("reflect-metadata");
43
-
44
- // src/DI/app-injector.ts
45
- var import_reflect_metadata2 = require("reflect-metadata");
46
-
47
- // src/decorators/inject.decorator.ts
48
- var import_reflect_metadata = require("reflect-metadata");
49
- var INJECT_METADATA_KEY = "custom:inject";
50
-
51
- // src/exceptions.ts
52
- var _ResponseException = class _ResponseException extends Error {
53
- constructor(statusOrMessage, message) {
54
- let statusCode;
55
- if (typeof statusOrMessage === "number") {
56
- statusCode = statusOrMessage;
57
- } else if (typeof statusOrMessage === "string") {
58
- message = statusOrMessage;
59
- }
60
- super(message ?? "");
61
- __publicField(this, "status", 0);
62
- if (statusCode !== void 0) {
63
- this.status = statusCode;
64
- }
65
- this.name = this.constructor.name.replace(/([A-Z])/g, " $1");
66
- }
67
- };
68
- __name(_ResponseException, "ResponseException");
69
- var ResponseException = _ResponseException;
70
- var _InternalServerException = class _InternalServerException extends ResponseException {
71
- constructor() {
72
- super(...arguments);
73
- __publicField(this, "status", 500);
74
- }
75
- };
76
- __name(_InternalServerException, "InternalServerException");
77
- var InternalServerException = _InternalServerException;
78
-
79
39
  // src/utils/forward-ref.ts
80
40
  var _ForwardReference = class _ForwardReference {
81
41
  constructor(forwardRefFn) {
82
- __publicField(this, "forwardRefFn");
83
42
  this.forwardRefFn = forwardRefFn;
84
43
  }
85
44
  };
86
45
  __name(_ForwardReference, "ForwardReference");
87
46
  var ForwardReference = _ForwardReference;
88
47
 
48
+ // src/DI/token.ts
49
+ var _Token = class _Token {
50
+ constructor(target) {
51
+ this.target = target;
52
+ this.description = typeof target === "string" ? target : target.name;
53
+ }
54
+ toString() {
55
+ return `Token(${this.description})`;
56
+ }
57
+ };
58
+ __name(_Token, "Token");
59
+ var Token = _Token;
60
+
89
61
  // src/DI/app-injector.ts
62
+ function keyOf(k) {
63
+ return k;
64
+ }
65
+ __name(keyOf, "keyOf");
90
66
  var _AppInjector = class _AppInjector {
91
67
  constructor(name = null) {
92
- __publicField(this, "name");
93
- __publicField(this, "bindings", /* @__PURE__ */ new Map());
94
- __publicField(this, "singletons", /* @__PURE__ */ new Map());
95
- __publicField(this, "scoped", /* @__PURE__ */ new Map());
96
68
  this.name = name;
69
+ this.bindings = /* @__PURE__ */ new Map();
70
+ this.singletons = /* @__PURE__ */ new Map();
71
+ this.scoped = /* @__PURE__ */ new Map();
97
72
  }
98
73
  /**
99
- * Typically used to create a dependency injection scope
100
- * at the "scope" level (i.e., per-request lifetime).
101
- *
102
- * SHOULD NOT BE USED by anything else than the framework itself.
74
+ * Creates a child scope for per-request lifetime resolution.
103
75
  */
104
76
  createScope() {
105
77
  const scope = new _AppInjector();
@@ -108,70 +80,73 @@ var _AppInjector = class _AppInjector {
108
80
  return scope;
109
81
  }
110
82
  /**
111
- * Called when resolving a dependency,
112
- * i.e., retrieving the instance of a given class.
83
+ * Registers a binding explicitly.
84
+ */
85
+ register(key, implementation, lifetime, deps = []) {
86
+ const k = keyOf(key);
87
+ if (!this.bindings.has(k)) {
88
+ this.bindings.set(k, { lifetime, implementation, deps });
89
+ }
90
+ }
91
+ /**
92
+ * Resolves a dependency by token or class reference.
113
93
  */
114
94
  resolve(target) {
115
95
  if (target instanceof ForwardReference) {
116
- return new Proxy({}, {
117
- get: /* @__PURE__ */ __name((obj, prop, receiver) => {
118
- const realType = target.forwardRefFn();
119
- const instance = this.resolve(realType);
120
- const value = Reflect.get(instance, prop, receiver);
121
- return typeof value === "function" ? value.bind(instance) : value;
122
- }, "get"),
123
- set: /* @__PURE__ */ __name((obj, prop, value, receiver) => {
124
- const realType = target.forwardRefFn();
125
- const instance = this.resolve(realType);
126
- return Reflect.set(instance, prop, value, receiver);
127
- }, "set"),
128
- getPrototypeOf: /* @__PURE__ */ __name(() => {
129
- const realType = target.forwardRefFn();
130
- return realType.prototype;
131
- }, "getPrototypeOf")
132
- });
96
+ return this._resolveForwardRef(target);
133
97
  }
134
- const binding = this.bindings.get(target);
98
+ const k = keyOf(target);
99
+ const binding = this.bindings.get(k);
135
100
  if (!binding) {
136
- if (target === void 0) {
137
- throw new InternalServerException("Failed to resolve a dependency injection : Undefined target type.\nThis might be caused by a circular dependency.");
138
- }
139
- const name = target.name || "unknown";
140
- throw new InternalServerException(`Failed to resolve a dependency injection : No binding for type ${name}.
141
- Did you forget to use @Injectable() decorator ?`);
101
+ const name = target instanceof Token ? target.description : target.name ?? "unknown";
102
+ throw new Error(
103
+ `[Noxus DI] No binding found for "${name}".
104
+ Did you forget to declare it in @Injectable({ deps }) or in bootstrapApplication({ singletons })?`
105
+ );
142
106
  }
143
107
  switch (binding.lifetime) {
144
108
  case "transient":
145
- return this.instantiate(binding.implementation);
109
+ return this._instantiate(binding);
146
110
  case "scope": {
147
- if (this.scoped.has(target)) {
148
- return this.scoped.get(target);
149
- }
150
- const instance = this.instantiate(binding.implementation);
151
- this.scoped.set(target, instance);
152
- return instance;
111
+ if (this.scoped.has(k)) return this.scoped.get(k);
112
+ const inst = this._instantiate(binding);
113
+ this.scoped.set(k, inst);
114
+ return inst;
153
115
  }
154
116
  case "singleton": {
155
- if (binding.instance === void 0 && this.name === "root") {
156
- binding.instance = this.instantiate(binding.implementation);
157
- this.singletons.set(target, binding.instance);
117
+ if (this.singletons.has(k)) return this.singletons.get(k);
118
+ const inst = this._instantiate(binding);
119
+ this.singletons.set(k, inst);
120
+ if (binding.instance === void 0) {
121
+ binding.instance = inst;
158
122
  }
159
- return binding.instance;
123
+ return inst;
160
124
  }
161
125
  }
162
126
  }
163
- /**
164
- * Instantiates a class, resolving its dependencies.
165
- */
166
- instantiate(target) {
167
- const paramTypes = Reflect.getMetadata("design:paramtypes", target) || [];
168
- const injectParams = Reflect.getMetadata(INJECT_METADATA_KEY, target) || [];
169
- const params = paramTypes.map((paramType, index) => {
170
- const overrideToken = injectParams[index];
171
- const actualToken = overrideToken !== void 0 ? overrideToken : paramType;
172
- return this.resolve(actualToken);
127
+ // -------------------------------------------------------------------------
128
+ _resolveForwardRef(ref) {
129
+ return new Proxy({}, {
130
+ get: /* @__PURE__ */ __name((_obj, prop, receiver) => {
131
+ const realType = ref.forwardRefFn();
132
+ const instance = this.resolve(realType);
133
+ const value = Reflect.get(instance, prop, receiver);
134
+ return typeof value === "function" ? value.bind(instance) : value;
135
+ }, "get"),
136
+ set: /* @__PURE__ */ __name((_obj, prop, value, receiver) => {
137
+ const realType = ref.forwardRefFn();
138
+ const instance = this.resolve(realType);
139
+ return Reflect.set(instance, prop, value, receiver);
140
+ }, "set"),
141
+ getPrototypeOf: /* @__PURE__ */ __name(() => {
142
+ const realType = ref.forwardRefFn();
143
+ return realType.prototype;
144
+ }, "getPrototypeOf")
173
145
  });
174
- return new target(...params);
146
+ }
147
+ _instantiate(binding) {
148
+ const resolvedDeps = binding.deps.map((dep) => this.resolve(dep));
149
+ return new binding.implementation(...resolvedDeps);
175
150
  }
176
151
  };
177
152
  __name(_AppInjector, "AppInjector");
@@ -181,20 +156,14 @@ var RootInjector = new AppInjector("root");
181
156
  // src/request.ts
182
157
  var _Request = class _Request {
183
158
  constructor(event, senderId, id, method, path, body) {
184
- __publicField(this, "event");
185
- __publicField(this, "senderId");
186
- __publicField(this, "id");
187
- __publicField(this, "method");
188
- __publicField(this, "path");
189
- __publicField(this, "body");
190
- __publicField(this, "context", RootInjector.createScope());
191
- __publicField(this, "params", {});
192
159
  this.event = event;
193
160
  this.senderId = senderId;
194
161
  this.id = id;
195
162
  this.method = method;
196
163
  this.path = path;
197
164
  this.body = body;
165
+ this.context = RootInjector.createScope();
166
+ this.params = {};
198
167
  this.path = path.replace(/^\/|\/$/g, "");
199
168
  }
200
169
  };
@@ -225,7 +194,13 @@ var DEFAULT_INIT_EVENT = "init-port";
225
194
  var DEFAULT_REQUEST_CHANNEL = "gimme-my-port";
226
195
  var DEFAULT_RESPONSE_CHANNEL = "port";
227
196
  function exposeNoxusBridge(options = {}) {
228
- const { exposeAs = DEFAULT_EXPOSE_NAME, initMessageType = DEFAULT_INIT_EVENT, requestChannel = DEFAULT_REQUEST_CHANNEL, responseChannel = DEFAULT_RESPONSE_CHANNEL, targetWindow = window } = options;
197
+ const {
198
+ exposeAs = DEFAULT_EXPOSE_NAME,
199
+ initMessageType = DEFAULT_INIT_EVENT,
200
+ requestChannel = DEFAULT_REQUEST_CHANNEL,
201
+ responseChannel = DEFAULT_RESPONSE_CHANNEL,
202
+ targetWindow = window
203
+ } = options;
229
204
  const api = {
230
205
  requestPort: /* @__PURE__ */ __name(() => {
231
206
  import_renderer.ipcRenderer.send(requestChannel);
@@ -242,10 +217,14 @@ function exposeNoxusBridge(options = {}) {
242
217
  console.error("[Noxus] Failed to start MessagePort.", error);
243
218
  }
244
219
  }
245
- targetWindow.postMessage({
246
- type: initMessageType,
247
- senderId: message?.senderId
248
- }, "*", ports);
220
+ targetWindow.postMessage(
221
+ {
222
+ type: initMessageType,
223
+ senderId: message?.senderId
224
+ },
225
+ "*",
226
+ ports
227
+ );
249
228
  });
250
229
  }, "requestPort")
251
230
  };
@@ -257,7 +236,7 @@ __name(exposeNoxusBridge, "exposeNoxusBridge");
257
236
  // src/renderer-events.ts
258
237
  var _RendererEventRegistry = class _RendererEventRegistry {
259
238
  constructor() {
260
- __publicField(this, "listeners", /* @__PURE__ */ new Map());
239
+ this.listeners = /* @__PURE__ */ new Map();
261
240
  }
262
241
  /**
263
242
  *
@@ -336,10 +315,7 @@ var RendererEventRegistry = _RendererEventRegistry;
336
315
 
337
316
  // src/renderer-client.ts
338
317
  var DEFAULT_INIT_EVENT2 = "init-port";
339
- var DEFAULT_BRIDGE_NAMES = [
340
- "noxus",
341
- "ipcRenderer"
342
- ];
318
+ var DEFAULT_BRIDGE_NAMES = ["noxus", "ipcRenderer"];
343
319
  function defaultRequestId() {
344
320
  if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
345
321
  return crypto.randomUUID();
@@ -350,7 +326,8 @@ __name(defaultRequestId, "defaultRequestId");
350
326
  function normalizeBridgeNames(preferred) {
351
327
  const names = [];
352
328
  const add = /* @__PURE__ */ __name((name) => {
353
- if (!name) return;
329
+ if (!name)
330
+ return;
354
331
  if (!names.includes(name)) {
355
332
  names.push(name);
356
333
  }
@@ -385,20 +362,10 @@ function resolveBridgeFromWindow(windowRef, preferred) {
385
362
  __name(resolveBridgeFromWindow, "resolveBridgeFromWindow");
386
363
  var _NoxRendererClient = class _NoxRendererClient {
387
364
  constructor(options = {}) {
388
- __publicField(this, "events", new RendererEventRegistry());
389
- __publicField(this, "pendingRequests", /* @__PURE__ */ new Map());
390
- __publicField(this, "requestPort");
391
- __publicField(this, "socketPort");
392
- __publicField(this, "senderId");
393
- __publicField(this, "bridge");
394
- __publicField(this, "initMessageType");
395
- __publicField(this, "windowRef");
396
- __publicField(this, "generateRequestId");
397
- __publicField(this, "isReady", false);
398
- __publicField(this, "setupPromise");
399
- __publicField(this, "setupResolve");
400
- __publicField(this, "setupReject");
401
- __publicField(this, "onWindowMessage", /* @__PURE__ */ __name((event) => {
365
+ this.events = new RendererEventRegistry();
366
+ this.pendingRequests = /* @__PURE__ */ new Map();
367
+ this.isReady = false;
368
+ this.onWindowMessage = /* @__PURE__ */ __name((event) => {
402
369
  if (event.data?.type !== this.initMessageType) {
403
370
  return;
404
371
  }
@@ -425,14 +392,14 @@ var _NoxRendererClient = class _NoxRendererClient {
425
392
  this.isReady = true;
426
393
  this.setupResolve?.();
427
394
  this.resetSetupState(true);
428
- }, "onWindowMessage"));
429
- __publicField(this, "onSocketMessage", /* @__PURE__ */ __name((event) => {
395
+ }, "onWindowMessage");
396
+ this.onSocketMessage = /* @__PURE__ */ __name((event) => {
430
397
  if (this.events.tryDispatchFromMessageEvent(event)) {
431
398
  return;
432
399
  }
433
400
  console.warn("[Noxus] Received a socket message that is not a renderer event payload.", event.data);
434
- }, "onSocketMessage"));
435
- __publicField(this, "onRequestMessage", /* @__PURE__ */ __name((event) => {
401
+ }, "onSocketMessage");
402
+ this.onRequestMessage = /* @__PURE__ */ __name((event) => {
436
403
  if (this.events.tryDispatchFromMessageEvent(event)) {
437
404
  return;
438
405
  }
@@ -453,7 +420,7 @@ var _NoxRendererClient = class _NoxRendererClient {
453
420
  return;
454
421
  }
455
422
  pending.resolve(response.body);
456
- }, "onRequestMessage"));
423
+ }, "onRequestMessage");
457
424
  this.windowRef = options.windowRef ?? window;
458
425
  const resolvedBridge = options.bridge ?? resolveBridgeFromWindow(this.windowRef, options.bridgeName);
459
426
  this.bridge = resolvedBridge ?? null;
@@ -594,4 +561,11 @@ var NoxRendererClient = _NoxRendererClient;
594
561
  * @license MIT
595
562
  * @author NoxFly
596
563
  */
564
+ /**
565
+ * @copyright 2025 NoxFly
566
+ * @license MIT
567
+ * @author NoxFly
568
+ *
569
+ * Entry point for renderer process and preload consumers.
570
+ */
597
571
  //# sourceMappingURL=renderer.js.map