@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
package/dist/renderer.mjs CHANGED
@@ -4,72 +4,44 @@
4
4
  * @author NoxFly
5
5
  */
6
6
  var __defProp = Object.defineProperty;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
7
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
10
-
11
- // src/request.ts
12
- import "reflect-metadata";
13
-
14
- // src/DI/app-injector.ts
15
- import "reflect-metadata";
16
-
17
- // src/decorators/inject.decorator.ts
18
- import "reflect-metadata";
19
- var INJECT_METADATA_KEY = "custom:inject";
20
-
21
- // src/exceptions.ts
22
- var _ResponseException = class _ResponseException extends Error {
23
- constructor(statusOrMessage, message) {
24
- let statusCode;
25
- if (typeof statusOrMessage === "number") {
26
- statusCode = statusOrMessage;
27
- } else if (typeof statusOrMessage === "string") {
28
- message = statusOrMessage;
29
- }
30
- super(message ?? "");
31
- __publicField(this, "status", 0);
32
- if (statusCode !== void 0) {
33
- this.status = statusCode;
34
- }
35
- this.name = this.constructor.name.replace(/([A-Z])/g, " $1");
36
- }
37
- };
38
- __name(_ResponseException, "ResponseException");
39
- var ResponseException = _ResponseException;
40
- var _InternalServerException = class _InternalServerException extends ResponseException {
41
- constructor() {
42
- super(...arguments);
43
- __publicField(this, "status", 500);
44
- }
45
- };
46
- __name(_InternalServerException, "InternalServerException");
47
- var InternalServerException = _InternalServerException;
48
8
 
49
9
  // src/utils/forward-ref.ts
50
10
  var _ForwardReference = class _ForwardReference {
51
11
  constructor(forwardRefFn) {
52
- __publicField(this, "forwardRefFn");
53
12
  this.forwardRefFn = forwardRefFn;
54
13
  }
55
14
  };
56
15
  __name(_ForwardReference, "ForwardReference");
57
16
  var ForwardReference = _ForwardReference;
58
17
 
18
+ // src/DI/token.ts
19
+ var _Token = class _Token {
20
+ constructor(target) {
21
+ this.target = target;
22
+ this.description = typeof target === "string" ? target : target.name;
23
+ }
24
+ toString() {
25
+ return `Token(${this.description})`;
26
+ }
27
+ };
28
+ __name(_Token, "Token");
29
+ var Token = _Token;
30
+
59
31
  // src/DI/app-injector.ts
32
+ function keyOf(k) {
33
+ return k;
34
+ }
35
+ __name(keyOf, "keyOf");
60
36
  var _AppInjector = class _AppInjector {
61
37
  constructor(name = null) {
62
- __publicField(this, "name");
63
- __publicField(this, "bindings", /* @__PURE__ */ new Map());
64
- __publicField(this, "singletons", /* @__PURE__ */ new Map());
65
- __publicField(this, "scoped", /* @__PURE__ */ new Map());
66
38
  this.name = name;
39
+ this.bindings = /* @__PURE__ */ new Map();
40
+ this.singletons = /* @__PURE__ */ new Map();
41
+ this.scoped = /* @__PURE__ */ new Map();
67
42
  }
68
43
  /**
69
- * Typically used to create a dependency injection scope
70
- * at the "scope" level (i.e., per-request lifetime).
71
- *
72
- * SHOULD NOT BE USED by anything else than the framework itself.
44
+ * Creates a child scope for per-request lifetime resolution.
73
45
  */
74
46
  createScope() {
75
47
  const scope = new _AppInjector();
@@ -78,70 +50,73 @@ var _AppInjector = class _AppInjector {
78
50
  return scope;
79
51
  }
80
52
  /**
81
- * Called when resolving a dependency,
82
- * i.e., retrieving the instance of a given class.
53
+ * Registers a binding explicitly.
54
+ */
55
+ register(key, implementation, lifetime, deps = []) {
56
+ const k = keyOf(key);
57
+ if (!this.bindings.has(k)) {
58
+ this.bindings.set(k, { lifetime, implementation, deps });
59
+ }
60
+ }
61
+ /**
62
+ * Resolves a dependency by token or class reference.
83
63
  */
84
64
  resolve(target) {
85
65
  if (target instanceof ForwardReference) {
86
- return new Proxy({}, {
87
- get: /* @__PURE__ */ __name((obj, prop, receiver) => {
88
- const realType = target.forwardRefFn();
89
- const instance = this.resolve(realType);
90
- const value = Reflect.get(instance, prop, receiver);
91
- return typeof value === "function" ? value.bind(instance) : value;
92
- }, "get"),
93
- set: /* @__PURE__ */ __name((obj, prop, value, receiver) => {
94
- const realType = target.forwardRefFn();
95
- const instance = this.resolve(realType);
96
- return Reflect.set(instance, prop, value, receiver);
97
- }, "set"),
98
- getPrototypeOf: /* @__PURE__ */ __name(() => {
99
- const realType = target.forwardRefFn();
100
- return realType.prototype;
101
- }, "getPrototypeOf")
102
- });
66
+ return this._resolveForwardRef(target);
103
67
  }
104
- const binding = this.bindings.get(target);
68
+ const k = keyOf(target);
69
+ const binding = this.bindings.get(k);
105
70
  if (!binding) {
106
- if (target === void 0) {
107
- throw new InternalServerException("Failed to resolve a dependency injection : Undefined target type.\nThis might be caused by a circular dependency.");
108
- }
109
- const name = target.name || "unknown";
110
- throw new InternalServerException(`Failed to resolve a dependency injection : No binding for type ${name}.
111
- Did you forget to use @Injectable() decorator ?`);
71
+ const name = target instanceof Token ? target.description : target.name ?? "unknown";
72
+ throw new Error(
73
+ `[Noxus DI] No binding found for "${name}".
74
+ Did you forget to declare it in @Injectable({ deps }) or in bootstrapApplication({ singletons })?`
75
+ );
112
76
  }
113
77
  switch (binding.lifetime) {
114
78
  case "transient":
115
- return this.instantiate(binding.implementation);
79
+ return this._instantiate(binding);
116
80
  case "scope": {
117
- if (this.scoped.has(target)) {
118
- return this.scoped.get(target);
119
- }
120
- const instance = this.instantiate(binding.implementation);
121
- this.scoped.set(target, instance);
122
- return instance;
81
+ if (this.scoped.has(k)) return this.scoped.get(k);
82
+ const inst = this._instantiate(binding);
83
+ this.scoped.set(k, inst);
84
+ return inst;
123
85
  }
124
86
  case "singleton": {
125
- if (binding.instance === void 0 && this.name === "root") {
126
- binding.instance = this.instantiate(binding.implementation);
127
- this.singletons.set(target, binding.instance);
87
+ if (this.singletons.has(k)) return this.singletons.get(k);
88
+ const inst = this._instantiate(binding);
89
+ this.singletons.set(k, inst);
90
+ if (binding.instance === void 0) {
91
+ binding.instance = inst;
128
92
  }
129
- return binding.instance;
93
+ return inst;
130
94
  }
131
95
  }
132
96
  }
133
- /**
134
- * Instantiates a class, resolving its dependencies.
135
- */
136
- instantiate(target) {
137
- const paramTypes = Reflect.getMetadata("design:paramtypes", target) || [];
138
- const injectParams = Reflect.getMetadata(INJECT_METADATA_KEY, target) || [];
139
- const params = paramTypes.map((paramType, index) => {
140
- const overrideToken = injectParams[index];
141
- const actualToken = overrideToken !== void 0 ? overrideToken : paramType;
142
- return this.resolve(actualToken);
97
+ // -------------------------------------------------------------------------
98
+ _resolveForwardRef(ref) {
99
+ return new Proxy({}, {
100
+ get: /* @__PURE__ */ __name((_obj, prop, receiver) => {
101
+ const realType = ref.forwardRefFn();
102
+ const instance = this.resolve(realType);
103
+ const value = Reflect.get(instance, prop, receiver);
104
+ return typeof value === "function" ? value.bind(instance) : value;
105
+ }, "get"),
106
+ set: /* @__PURE__ */ __name((_obj, prop, value, receiver) => {
107
+ const realType = ref.forwardRefFn();
108
+ const instance = this.resolve(realType);
109
+ return Reflect.set(instance, prop, value, receiver);
110
+ }, "set"),
111
+ getPrototypeOf: /* @__PURE__ */ __name(() => {
112
+ const realType = ref.forwardRefFn();
113
+ return realType.prototype;
114
+ }, "getPrototypeOf")
143
115
  });
144
- return new target(...params);
116
+ }
117
+ _instantiate(binding) {
118
+ const resolvedDeps = binding.deps.map((dep) => this.resolve(dep));
119
+ return new binding.implementation(...resolvedDeps);
145
120
  }
146
121
  };
147
122
  __name(_AppInjector, "AppInjector");
@@ -151,20 +126,14 @@ var RootInjector = new AppInjector("root");
151
126
  // src/request.ts
152
127
  var _Request = class _Request {
153
128
  constructor(event, senderId, id, method, path, body) {
154
- __publicField(this, "event");
155
- __publicField(this, "senderId");
156
- __publicField(this, "id");
157
- __publicField(this, "method");
158
- __publicField(this, "path");
159
- __publicField(this, "body");
160
- __publicField(this, "context", RootInjector.createScope());
161
- __publicField(this, "params", {});
162
129
  this.event = event;
163
130
  this.senderId = senderId;
164
131
  this.id = id;
165
132
  this.method = method;
166
133
  this.path = path;
167
134
  this.body = body;
135
+ this.context = RootInjector.createScope();
136
+ this.params = {};
168
137
  this.path = path.replace(/^\/|\/$/g, "");
169
138
  }
170
139
  };
@@ -195,7 +164,13 @@ var DEFAULT_INIT_EVENT = "init-port";
195
164
  var DEFAULT_REQUEST_CHANNEL = "gimme-my-port";
196
165
  var DEFAULT_RESPONSE_CHANNEL = "port";
197
166
  function exposeNoxusBridge(options = {}) {
198
- const { exposeAs = DEFAULT_EXPOSE_NAME, initMessageType = DEFAULT_INIT_EVENT, requestChannel = DEFAULT_REQUEST_CHANNEL, responseChannel = DEFAULT_RESPONSE_CHANNEL, targetWindow = window } = options;
167
+ const {
168
+ exposeAs = DEFAULT_EXPOSE_NAME,
169
+ initMessageType = DEFAULT_INIT_EVENT,
170
+ requestChannel = DEFAULT_REQUEST_CHANNEL,
171
+ responseChannel = DEFAULT_RESPONSE_CHANNEL,
172
+ targetWindow = window
173
+ } = options;
199
174
  const api = {
200
175
  requestPort: /* @__PURE__ */ __name(() => {
201
176
  ipcRenderer.send(requestChannel);
@@ -212,10 +187,14 @@ function exposeNoxusBridge(options = {}) {
212
187
  console.error("[Noxus] Failed to start MessagePort.", error);
213
188
  }
214
189
  }
215
- targetWindow.postMessage({
216
- type: initMessageType,
217
- senderId: message?.senderId
218
- }, "*", ports);
190
+ targetWindow.postMessage(
191
+ {
192
+ type: initMessageType,
193
+ senderId: message?.senderId
194
+ },
195
+ "*",
196
+ ports
197
+ );
219
198
  });
220
199
  }, "requestPort")
221
200
  };
@@ -227,7 +206,7 @@ __name(exposeNoxusBridge, "exposeNoxusBridge");
227
206
  // src/renderer-events.ts
228
207
  var _RendererEventRegistry = class _RendererEventRegistry {
229
208
  constructor() {
230
- __publicField(this, "listeners", /* @__PURE__ */ new Map());
209
+ this.listeners = /* @__PURE__ */ new Map();
231
210
  }
232
211
  /**
233
212
  *
@@ -306,10 +285,7 @@ var RendererEventRegistry = _RendererEventRegistry;
306
285
 
307
286
  // src/renderer-client.ts
308
287
  var DEFAULT_INIT_EVENT2 = "init-port";
309
- var DEFAULT_BRIDGE_NAMES = [
310
- "noxus",
311
- "ipcRenderer"
312
- ];
288
+ var DEFAULT_BRIDGE_NAMES = ["noxus", "ipcRenderer"];
313
289
  function defaultRequestId() {
314
290
  if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
315
291
  return crypto.randomUUID();
@@ -320,7 +296,8 @@ __name(defaultRequestId, "defaultRequestId");
320
296
  function normalizeBridgeNames(preferred) {
321
297
  const names = [];
322
298
  const add = /* @__PURE__ */ __name((name) => {
323
- if (!name) return;
299
+ if (!name)
300
+ return;
324
301
  if (!names.includes(name)) {
325
302
  names.push(name);
326
303
  }
@@ -355,20 +332,10 @@ function resolveBridgeFromWindow(windowRef, preferred) {
355
332
  __name(resolveBridgeFromWindow, "resolveBridgeFromWindow");
356
333
  var _NoxRendererClient = class _NoxRendererClient {
357
334
  constructor(options = {}) {
358
- __publicField(this, "events", new RendererEventRegistry());
359
- __publicField(this, "pendingRequests", /* @__PURE__ */ new Map());
360
- __publicField(this, "requestPort");
361
- __publicField(this, "socketPort");
362
- __publicField(this, "senderId");
363
- __publicField(this, "bridge");
364
- __publicField(this, "initMessageType");
365
- __publicField(this, "windowRef");
366
- __publicField(this, "generateRequestId");
367
- __publicField(this, "isReady", false);
368
- __publicField(this, "setupPromise");
369
- __publicField(this, "setupResolve");
370
- __publicField(this, "setupReject");
371
- __publicField(this, "onWindowMessage", /* @__PURE__ */ __name((event) => {
335
+ this.events = new RendererEventRegistry();
336
+ this.pendingRequests = /* @__PURE__ */ new Map();
337
+ this.isReady = false;
338
+ this.onWindowMessage = /* @__PURE__ */ __name((event) => {
372
339
  if (event.data?.type !== this.initMessageType) {
373
340
  return;
374
341
  }
@@ -395,14 +362,14 @@ var _NoxRendererClient = class _NoxRendererClient {
395
362
  this.isReady = true;
396
363
  this.setupResolve?.();
397
364
  this.resetSetupState(true);
398
- }, "onWindowMessage"));
399
- __publicField(this, "onSocketMessage", /* @__PURE__ */ __name((event) => {
365
+ }, "onWindowMessage");
366
+ this.onSocketMessage = /* @__PURE__ */ __name((event) => {
400
367
  if (this.events.tryDispatchFromMessageEvent(event)) {
401
368
  return;
402
369
  }
403
370
  console.warn("[Noxus] Received a socket message that is not a renderer event payload.", event.data);
404
- }, "onSocketMessage"));
405
- __publicField(this, "onRequestMessage", /* @__PURE__ */ __name((event) => {
371
+ }, "onSocketMessage");
372
+ this.onRequestMessage = /* @__PURE__ */ __name((event) => {
406
373
  if (this.events.tryDispatchFromMessageEvent(event)) {
407
374
  return;
408
375
  }
@@ -423,7 +390,7 @@ var _NoxRendererClient = class _NoxRendererClient {
423
390
  return;
424
391
  }
425
392
  pending.resolve(response.body);
426
- }, "onRequestMessage"));
393
+ }, "onRequestMessage");
427
394
  this.windowRef = options.windowRef ?? window;
428
395
  const resolvedBridge = options.bridge ?? resolveBridgeFromWindow(this.windowRef, options.bridgeName);
429
396
  this.bridge = resolvedBridge ?? null;
@@ -563,4 +530,11 @@ export {
563
530
  * @license MIT
564
531
  * @author NoxFly
565
532
  */
533
+ /**
534
+ * @copyright 2025 NoxFly
535
+ * @license MIT
536
+ * @author NoxFly
537
+ *
538
+ * Entry point for renderer process and preload consumers.
539
+ */
566
540
  //# sourceMappingURL=renderer.mjs.map
@@ -0,0 +1,112 @@
1
+ import { M as MaybeAsync, A as AppInjector } from './app-injector-Bz3Upc0y.js';
2
+
3
+ /**
4
+ * @copyright 2025 NoxFly
5
+ * @license MIT
6
+ * @author NoxFly
7
+ */
8
+
9
+ /**
10
+ * A guard decides whether an incoming request should reach the handler.
11
+ * Implement this interface and pass the class to @Controller({ guards }) or @Get('path', { guards }).
12
+ */
13
+ type Guard = (request: Request) => MaybeAsync<boolean>;
14
+
15
+
16
+ /**
17
+ * A middleware intercepts requests before they reach guards and the handler.
18
+ * Implement this interface and pass the class to @Controller({ middlewares }) or per-route options.
19
+ */
20
+ type Middleware = (request: Request, response: IResponse, next: NextFunction) => MaybeAsync<void>;
21
+ type NextFunction = () => Promise<void>;
22
+
23
+
24
+ type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'BATCH';
25
+ type AtomicHttpMethod = Exclude<HttpMethod, 'BATCH'>;
26
+ declare function isAtomicHttpMethod(m: unknown): m is AtomicHttpMethod;
27
+ interface IRouteOptions {
28
+ /**
29
+ * Guards specific to this route (merged with controller guards).
30
+ */
31
+ guards?: Guard[];
32
+ /**
33
+ * Middlewares specific to this route (merged with controller middlewares).
34
+ */
35
+ middlewares?: Middleware[];
36
+ }
37
+ interface IRouteMetadata {
38
+ method: HttpMethod;
39
+ path: string;
40
+ handler: string;
41
+ guards: Guard[];
42
+ middlewares: Middleware[];
43
+ }
44
+ declare function getRouteMetadata(target: object): IRouteMetadata[];
45
+ declare const Get: (path: string, options?: IRouteOptions) => MethodDecorator;
46
+ declare const Post: (path: string, options?: IRouteOptions) => MethodDecorator;
47
+ declare const Put: (path: string, options?: IRouteOptions) => MethodDecorator;
48
+ declare const Patch: (path: string, options?: IRouteOptions) => MethodDecorator;
49
+ declare const Delete: (path: string, options?: IRouteOptions) => MethodDecorator;
50
+
51
+
52
+ /**
53
+ * The Request class represents an HTTP request in the Noxus framework.
54
+ * It encapsulates the request data, including the event, ID, method, path, and body.
55
+ * It also provides a context for dependency injection through the AppInjector.
56
+ */
57
+ declare class Request {
58
+ readonly event: Electron.MessageEvent;
59
+ readonly senderId: number;
60
+ readonly id: string;
61
+ readonly method: HttpMethod;
62
+ readonly path: string;
63
+ readonly body: any;
64
+ readonly context: AppInjector;
65
+ readonly params: Record<string, string>;
66
+ constructor(event: Electron.MessageEvent, senderId: number, id: string, method: HttpMethod, path: string, body: any);
67
+ }
68
+ /**
69
+ * The IRequest interface defines the structure of a request object.
70
+ * It includes properties for the sender ID, request ID, path, method, and an optional body.
71
+ * This interface is used to standardize the request data across the application.
72
+ */
73
+ interface IRequest<TBody = unknown> {
74
+ senderId: number;
75
+ requestId: string;
76
+ path: string;
77
+ method: HttpMethod;
78
+ body?: TBody;
79
+ }
80
+ interface IBatchRequestItem<TBody = unknown> {
81
+ requestId?: string;
82
+ path: string;
83
+ method: AtomicHttpMethod;
84
+ body?: TBody;
85
+ }
86
+ interface IBatchRequestPayload {
87
+ requests: IBatchRequestItem[];
88
+ }
89
+ /**
90
+ * Creates a Request object from the IPC event data.
91
+ * This function extracts the necessary information from the IPC event and constructs a Request instance.
92
+ */
93
+ interface IResponse<TBody = unknown> {
94
+ requestId: string;
95
+ status: number;
96
+ body?: TBody;
97
+ error?: string;
98
+ stack?: string;
99
+ }
100
+ interface IBatchResponsePayload {
101
+ responses: IResponse[];
102
+ }
103
+ declare const RENDERER_EVENT_TYPE = "noxus:event";
104
+ interface IRendererEventMessage<TPayload = unknown> {
105
+ type: typeof RENDERER_EVENT_TYPE;
106
+ event: string;
107
+ payload?: TPayload;
108
+ }
109
+ declare function createRendererEventMessage<TPayload = unknown>(event: string, payload?: TPayload): IRendererEventMessage<TPayload>;
110
+ declare function isRendererEventMessage(value: unknown): value is IRendererEventMessage;
111
+
112
+ export { type AtomicHttpMethod as A, Delete as D, type Guard as G, type HttpMethod as H, type IRendererEventMessage as I, type Middleware as M, type NextFunction as N, Patch as P, RENDERER_EVENT_TYPE as R, type IResponse as a, type IRequest as b, type IBatchRequestItem as c, type IBatchResponsePayload as d, type IBatchRequestPayload as e, Request as f, createRendererEventMessage as g, Get as h, isRendererEventMessage as i, type IRouteMetadata as j, type IRouteOptions as k, Post as l, Put as m, getRouteMetadata as n, isAtomicHttpMethod as o };
@@ -0,0 +1,112 @@
1
+ import { M as MaybeAsync, A as AppInjector } from './app-injector-Bz3Upc0y.mjs';
2
+
3
+ /**
4
+ * @copyright 2025 NoxFly
5
+ * @license MIT
6
+ * @author NoxFly
7
+ */
8
+
9
+ /**
10
+ * A guard decides whether an incoming request should reach the handler.
11
+ * Implement this interface and pass the class to @Controller({ guards }) or @Get('path', { guards }).
12
+ */
13
+ type Guard = (request: Request) => MaybeAsync<boolean>;
14
+
15
+
16
+ /**
17
+ * A middleware intercepts requests before they reach guards and the handler.
18
+ * Implement this interface and pass the class to @Controller({ middlewares }) or per-route options.
19
+ */
20
+ type Middleware = (request: Request, response: IResponse, next: NextFunction) => MaybeAsync<void>;
21
+ type NextFunction = () => Promise<void>;
22
+
23
+
24
+ type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'BATCH';
25
+ type AtomicHttpMethod = Exclude<HttpMethod, 'BATCH'>;
26
+ declare function isAtomicHttpMethod(m: unknown): m is AtomicHttpMethod;
27
+ interface IRouteOptions {
28
+ /**
29
+ * Guards specific to this route (merged with controller guards).
30
+ */
31
+ guards?: Guard[];
32
+ /**
33
+ * Middlewares specific to this route (merged with controller middlewares).
34
+ */
35
+ middlewares?: Middleware[];
36
+ }
37
+ interface IRouteMetadata {
38
+ method: HttpMethod;
39
+ path: string;
40
+ handler: string;
41
+ guards: Guard[];
42
+ middlewares: Middleware[];
43
+ }
44
+ declare function getRouteMetadata(target: object): IRouteMetadata[];
45
+ declare const Get: (path: string, options?: IRouteOptions) => MethodDecorator;
46
+ declare const Post: (path: string, options?: IRouteOptions) => MethodDecorator;
47
+ declare const Put: (path: string, options?: IRouteOptions) => MethodDecorator;
48
+ declare const Patch: (path: string, options?: IRouteOptions) => MethodDecorator;
49
+ declare const Delete: (path: string, options?: IRouteOptions) => MethodDecorator;
50
+
51
+
52
+ /**
53
+ * The Request class represents an HTTP request in the Noxus framework.
54
+ * It encapsulates the request data, including the event, ID, method, path, and body.
55
+ * It also provides a context for dependency injection through the AppInjector.
56
+ */
57
+ declare class Request {
58
+ readonly event: Electron.MessageEvent;
59
+ readonly senderId: number;
60
+ readonly id: string;
61
+ readonly method: HttpMethod;
62
+ readonly path: string;
63
+ readonly body: any;
64
+ readonly context: AppInjector;
65
+ readonly params: Record<string, string>;
66
+ constructor(event: Electron.MessageEvent, senderId: number, id: string, method: HttpMethod, path: string, body: any);
67
+ }
68
+ /**
69
+ * The IRequest interface defines the structure of a request object.
70
+ * It includes properties for the sender ID, request ID, path, method, and an optional body.
71
+ * This interface is used to standardize the request data across the application.
72
+ */
73
+ interface IRequest<TBody = unknown> {
74
+ senderId: number;
75
+ requestId: string;
76
+ path: string;
77
+ method: HttpMethod;
78
+ body?: TBody;
79
+ }
80
+ interface IBatchRequestItem<TBody = unknown> {
81
+ requestId?: string;
82
+ path: string;
83
+ method: AtomicHttpMethod;
84
+ body?: TBody;
85
+ }
86
+ interface IBatchRequestPayload {
87
+ requests: IBatchRequestItem[];
88
+ }
89
+ /**
90
+ * Creates a Request object from the IPC event data.
91
+ * This function extracts the necessary information from the IPC event and constructs a Request instance.
92
+ */
93
+ interface IResponse<TBody = unknown> {
94
+ requestId: string;
95
+ status: number;
96
+ body?: TBody;
97
+ error?: string;
98
+ stack?: string;
99
+ }
100
+ interface IBatchResponsePayload {
101
+ responses: IResponse[];
102
+ }
103
+ declare const RENDERER_EVENT_TYPE = "noxus:event";
104
+ interface IRendererEventMessage<TPayload = unknown> {
105
+ type: typeof RENDERER_EVENT_TYPE;
106
+ event: string;
107
+ payload?: TPayload;
108
+ }
109
+ declare function createRendererEventMessage<TPayload = unknown>(event: string, payload?: TPayload): IRendererEventMessage<TPayload>;
110
+ declare function isRendererEventMessage(value: unknown): value is IRendererEventMessage;
111
+
112
+ export { type AtomicHttpMethod as A, Delete as D, type Guard as G, type HttpMethod as H, type IRendererEventMessage as I, type Middleware as M, type NextFunction as N, Patch as P, RENDERER_EVENT_TYPE as R, type IResponse as a, type IRequest as b, type IBatchRequestItem as c, type IBatchResponsePayload as d, type IBatchRequestPayload as e, Request as f, createRendererEventMessage as g, Get as h, isRendererEventMessage as i, type IRouteMetadata as j, type IRouteOptions as k, Post as l, Put as m, getRouteMetadata as n, isAtomicHttpMethod as o };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noxfly/noxus",
3
- "version": "2.5.0",
3
+ "version": "3.0.0-dev.0",
4
4
  "main": "dist/main.js",
5
5
  "module": "dist/main.mjs",
6
6
  "types": "dist/main.d.ts",
@@ -45,12 +45,15 @@
45
45
  "nodejs",
46
46
  "typescript",
47
47
  "framework",
48
- "web framework",
49
- "electron"
48
+ "electron",
49
+ "ipc",
50
+ "dependency-injection",
51
+ "standalone",
52
+ "lazy-loading"
50
53
  ],
51
54
  "author": "NoxFly",
52
55
  "license": "MIT",
53
- "description": "Simulate lightweight HTTP-like requests between renderer and main process in Electron applications with MessagePort, with structured and modular design.",
56
+ "description": "Lightweight HTTP-like IPC framework for Electron with standalone controllers, explicit DI, and lazy route loading. No reflect-metadata required.",
54
57
  "homepage": "https://github.com/NoxFly/noxus",
55
58
  "repository": {
56
59
  "type": "git",
@@ -73,8 +76,5 @@
73
76
  "tsup": "^8.5.0",
74
77
  "typescript": "^5.8.3",
75
78
  "typescript-eslint": "^8.36.0"
76
- },
77
- "peerDependencies": {
78
- "reflect-metadata": "^0.2.2"
79
79
  }
80
80
  }