@noxfly/noxus 2.4.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 +1114 -1239
  7. package/dist/child.mjs +1090 -1193
  8. package/dist/main.d.mts +304 -261
  9. package/dist/main.d.ts +304 -261
  10. package/dist/main.js +1473 -1873
  11. package/dist/main.mjs +1423 -1791
  12. package/dist/renderer.d.mts +113 -2
  13. package/dist/renderer.d.ts +113 -2
  14. package/dist/renderer.js +144 -132
  15. package/dist/renderer.mjs +143 -132
  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 +100 -81
  21. package/src/DI/token.ts +53 -0
  22. package/src/app.ts +141 -131
  23. package/src/bootstrap.ts +79 -40
  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 +3 -0
  30. package/src/main.ts +4 -11
  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 +221 -369
  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/index-BxWQVi6C.d.ts +0 -253
  45. package/dist/index-DQBQQfMw.d.mts +0 -253
  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
  };
@@ -188,10 +157,56 @@ function isRendererEventMessage(value) {
188
157
  }
189
158
  __name(isRendererEventMessage, "isRendererEventMessage");
190
159
 
160
+ // src/preload-bridge.ts
161
+ import { contextBridge, ipcRenderer } from "electron/renderer";
162
+ var DEFAULT_EXPOSE_NAME = "noxus";
163
+ var DEFAULT_INIT_EVENT = "init-port";
164
+ var DEFAULT_REQUEST_CHANNEL = "gimme-my-port";
165
+ var DEFAULT_RESPONSE_CHANNEL = "port";
166
+ function exposeNoxusBridge(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;
174
+ const api = {
175
+ requestPort: /* @__PURE__ */ __name(() => {
176
+ ipcRenderer.send(requestChannel);
177
+ ipcRenderer.once(responseChannel, (event, message) => {
178
+ const ports = (event.ports ?? []).filter((port) => port !== void 0);
179
+ if (ports.length === 0) {
180
+ console.error("[Noxus] No MessagePort received from main process.");
181
+ return;
182
+ }
183
+ for (const port of ports) {
184
+ try {
185
+ port.start();
186
+ } catch (error) {
187
+ console.error("[Noxus] Failed to start MessagePort.", error);
188
+ }
189
+ }
190
+ targetWindow.postMessage(
191
+ {
192
+ type: initMessageType,
193
+ senderId: message?.senderId
194
+ },
195
+ "*",
196
+ ports
197
+ );
198
+ });
199
+ }, "requestPort")
200
+ };
201
+ contextBridge.exposeInMainWorld(exposeAs, api);
202
+ return api;
203
+ }
204
+ __name(exposeNoxusBridge, "exposeNoxusBridge");
205
+
191
206
  // src/renderer-events.ts
192
207
  var _RendererEventRegistry = class _RendererEventRegistry {
193
208
  constructor() {
194
- __publicField(this, "listeners", /* @__PURE__ */ new Map());
209
+ this.listeners = /* @__PURE__ */ new Map();
195
210
  }
196
211
  /**
197
212
  *
@@ -269,11 +284,8 @@ __name(_RendererEventRegistry, "RendererEventRegistry");
269
284
  var RendererEventRegistry = _RendererEventRegistry;
270
285
 
271
286
  // src/renderer-client.ts
272
- var DEFAULT_INIT_EVENT = "init-port";
273
- var DEFAULT_BRIDGE_NAMES = [
274
- "noxus",
275
- "ipcRenderer"
276
- ];
287
+ var DEFAULT_INIT_EVENT2 = "init-port";
288
+ var DEFAULT_BRIDGE_NAMES = ["noxus", "ipcRenderer"];
277
289
  function defaultRequestId() {
278
290
  if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
279
291
  return crypto.randomUUID();
@@ -284,7 +296,8 @@ __name(defaultRequestId, "defaultRequestId");
284
296
  function normalizeBridgeNames(preferred) {
285
297
  const names = [];
286
298
  const add = /* @__PURE__ */ __name((name) => {
287
- if (!name) return;
299
+ if (!name)
300
+ return;
288
301
  if (!names.includes(name)) {
289
302
  names.push(name);
290
303
  }
@@ -319,20 +332,10 @@ function resolveBridgeFromWindow(windowRef, preferred) {
319
332
  __name(resolveBridgeFromWindow, "resolveBridgeFromWindow");
320
333
  var _NoxRendererClient = class _NoxRendererClient {
321
334
  constructor(options = {}) {
322
- __publicField(this, "events", new RendererEventRegistry());
323
- __publicField(this, "pendingRequests", /* @__PURE__ */ new Map());
324
- __publicField(this, "requestPort");
325
- __publicField(this, "socketPort");
326
- __publicField(this, "senderId");
327
- __publicField(this, "bridge");
328
- __publicField(this, "initMessageType");
329
- __publicField(this, "windowRef");
330
- __publicField(this, "generateRequestId");
331
- __publicField(this, "isReady", false);
332
- __publicField(this, "setupPromise");
333
- __publicField(this, "setupResolve");
334
- __publicField(this, "setupReject");
335
- __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) => {
336
339
  if (event.data?.type !== this.initMessageType) {
337
340
  return;
338
341
  }
@@ -359,14 +362,14 @@ var _NoxRendererClient = class _NoxRendererClient {
359
362
  this.isReady = true;
360
363
  this.setupResolve?.();
361
364
  this.resetSetupState(true);
362
- }, "onWindowMessage"));
363
- __publicField(this, "onSocketMessage", /* @__PURE__ */ __name((event) => {
365
+ }, "onWindowMessage");
366
+ this.onSocketMessage = /* @__PURE__ */ __name((event) => {
364
367
  if (this.events.tryDispatchFromMessageEvent(event)) {
365
368
  return;
366
369
  }
367
370
  console.warn("[Noxus] Received a socket message that is not a renderer event payload.", event.data);
368
- }, "onSocketMessage"));
369
- __publicField(this, "onRequestMessage", /* @__PURE__ */ __name((event) => {
371
+ }, "onSocketMessage");
372
+ this.onRequestMessage = /* @__PURE__ */ __name((event) => {
370
373
  if (this.events.tryDispatchFromMessageEvent(event)) {
371
374
  return;
372
375
  }
@@ -387,11 +390,11 @@ var _NoxRendererClient = class _NoxRendererClient {
387
390
  return;
388
391
  }
389
392
  pending.resolve(response.body);
390
- }, "onRequestMessage"));
393
+ }, "onRequestMessage");
391
394
  this.windowRef = options.windowRef ?? window;
392
395
  const resolvedBridge = options.bridge ?? resolveBridgeFromWindow(this.windowRef, options.bridgeName);
393
396
  this.bridge = resolvedBridge ?? null;
394
- this.initMessageType = options.initMessageType ?? DEFAULT_INIT_EVENT;
397
+ this.initMessageType = options.initMessageType ?? DEFAULT_INIT_EVENT2;
395
398
  this.generateRequestId = options.generateRequestId ?? defaultRequestId;
396
399
  }
397
400
  async setup() {
@@ -519,6 +522,7 @@ export {
519
522
  RendererEventRegistry,
520
523
  Request,
521
524
  createRendererEventMessage,
525
+ exposeNoxusBridge,
522
526
  isRendererEventMessage
523
527
  };
524
528
  /**
@@ -526,4 +530,11 @@ export {
526
530
  * @license MIT
527
531
  * @author NoxFly
528
532
  */
533
+ /**
534
+ * @copyright 2025 NoxFly
535
+ * @license MIT
536
+ * @author NoxFly
537
+ *
538
+ * Entry point for renderer process and preload consumers.
539
+ */
529
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.4.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
  }