@noxfly/noxus 2.5.0 → 3.0.0-dev.1

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 (58) hide show
  1. package/README.md +405 -340
  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 +157 -23
  5. package/dist/child.d.ts +157 -23
  6. package/dist/child.js +1111 -1341
  7. package/dist/child.mjs +1086 -1294
  8. package/dist/main.d.mts +720 -284
  9. package/dist/main.d.ts +720 -284
  10. package/dist/main.js +1471 -1650
  11. package/dist/main.mjs +1409 -1559
  12. package/dist/preload.d.mts +28 -0
  13. package/dist/preload.d.ts +28 -0
  14. package/dist/preload.js +95 -0
  15. package/dist/preload.mjs +70 -0
  16. package/dist/renderer.d.mts +159 -22
  17. package/dist/renderer.d.ts +159 -22
  18. package/dist/renderer.js +104 -177
  19. package/dist/renderer.mjs +100 -172
  20. package/dist/request-BlTtiHbi.d.ts +112 -0
  21. package/dist/request-qJ9EiDZc.d.mts +112 -0
  22. package/package.json +24 -19
  23. package/src/DI/app-injector.ts +95 -106
  24. package/src/DI/injector-explorer.ts +93 -119
  25. package/src/DI/token.ts +53 -0
  26. package/src/decorators/controller.decorator.ts +38 -27
  27. package/src/decorators/guards.decorator.ts +5 -64
  28. package/src/decorators/injectable.decorator.ts +68 -15
  29. package/src/decorators/method.decorator.ts +40 -81
  30. package/src/decorators/middleware.decorator.ts +5 -72
  31. package/src/index.ts +4 -5
  32. package/src/internal/app.ts +217 -0
  33. package/src/internal/bootstrap.ts +108 -0
  34. package/src/{preload-bridge.ts → internal/preload-bridge.ts} +1 -1
  35. package/src/{renderer-client.ts → internal/renderer-client.ts} +2 -2
  36. package/src/{renderer-events.ts → internal/renderer-events.ts} +1 -1
  37. package/src/{request.ts → internal/request.ts} +3 -3
  38. package/src/internal/router.ts +353 -0
  39. package/src/internal/routes.ts +78 -0
  40. package/src/{socket.ts → internal/socket.ts} +4 -4
  41. package/src/main.ts +10 -14
  42. package/src/non-electron-process.ts +1 -2
  43. package/src/preload.ts +10 -0
  44. package/src/renderer.ts +13 -0
  45. package/src/window/window-manager.ts +255 -0
  46. package/tsconfig.json +5 -10
  47. package/tsup.config.ts +29 -13
  48. package/dist/app-injector-B3MvgV3k.d.mts +0 -95
  49. package/dist/app-injector-B3MvgV3k.d.ts +0 -95
  50. package/dist/request-CdpZ9qZL.d.ts +0 -167
  51. package/dist/request-Dx_5Prte.d.mts +0 -167
  52. package/src/app.ts +0 -244
  53. package/src/bootstrap.ts +0 -84
  54. package/src/decorators/inject.decorator.ts +0 -24
  55. package/src/decorators/injectable.metadata.ts +0 -15
  56. package/src/decorators/module.decorator.ts +0 -75
  57. package/src/router.ts +0 -594
  58. /package/src/{exceptions.ts → internal/exceptions.ts} +0 -0
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,93 +50,90 @@ 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");
148
123
  var AppInjector = _AppInjector;
149
124
  var RootInjector = new AppInjector("root");
150
125
 
151
- // src/request.ts
126
+ // src/internal/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,46 +157,10 @@ function isRendererEventMessage(value) {
188
157
  }
189
158
  __name(isRendererEventMessage, "isRendererEventMessage");
190
159
 
191
- // src/preload-bridge.ts
192
- import { contextBridge, ipcRenderer } from "electron/renderer";
193
- var DEFAULT_EXPOSE_NAME = "noxus";
194
- var DEFAULT_INIT_EVENT = "init-port";
195
- var DEFAULT_REQUEST_CHANNEL = "gimme-my-port";
196
- var DEFAULT_RESPONSE_CHANNEL = "port";
197
- function exposeNoxusBridge(options = {}) {
198
- const { exposeAs = DEFAULT_EXPOSE_NAME, initMessageType = DEFAULT_INIT_EVENT, requestChannel = DEFAULT_REQUEST_CHANNEL, responseChannel = DEFAULT_RESPONSE_CHANNEL, targetWindow = window } = options;
199
- const api = {
200
- requestPort: /* @__PURE__ */ __name(() => {
201
- ipcRenderer.send(requestChannel);
202
- ipcRenderer.once(responseChannel, (event, message) => {
203
- const ports = (event.ports ?? []).filter((port) => port !== void 0);
204
- if (ports.length === 0) {
205
- console.error("[Noxus] No MessagePort received from main process.");
206
- return;
207
- }
208
- for (const port of ports) {
209
- try {
210
- port.start();
211
- } catch (error) {
212
- console.error("[Noxus] Failed to start MessagePort.", error);
213
- }
214
- }
215
- targetWindow.postMessage({
216
- type: initMessageType,
217
- senderId: message?.senderId
218
- }, "*", ports);
219
- });
220
- }, "requestPort")
221
- };
222
- contextBridge.exposeInMainWorld(exposeAs, api);
223
- return api;
224
- }
225
- __name(exposeNoxusBridge, "exposeNoxusBridge");
226
-
227
- // src/renderer-events.ts
160
+ // src/internal/renderer-events.ts
228
161
  var _RendererEventRegistry = class _RendererEventRegistry {
229
162
  constructor() {
230
- __publicField(this, "listeners", /* @__PURE__ */ new Map());
163
+ this.listeners = /* @__PURE__ */ new Map();
231
164
  }
232
165
  /**
233
166
  *
@@ -304,12 +237,9 @@ var _RendererEventRegistry = class _RendererEventRegistry {
304
237
  __name(_RendererEventRegistry, "RendererEventRegistry");
305
238
  var RendererEventRegistry = _RendererEventRegistry;
306
239
 
307
- // src/renderer-client.ts
308
- var DEFAULT_INIT_EVENT2 = "init-port";
309
- var DEFAULT_BRIDGE_NAMES = [
310
- "noxus",
311
- "ipcRenderer"
312
- ];
240
+ // src/internal/renderer-client.ts
241
+ var DEFAULT_INIT_EVENT = "init-port";
242
+ var DEFAULT_BRIDGE_NAMES = ["noxus", "ipcRenderer"];
313
243
  function defaultRequestId() {
314
244
  if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
315
245
  return crypto.randomUUID();
@@ -320,7 +250,8 @@ __name(defaultRequestId, "defaultRequestId");
320
250
  function normalizeBridgeNames(preferred) {
321
251
  const names = [];
322
252
  const add = /* @__PURE__ */ __name((name) => {
323
- if (!name) return;
253
+ if (!name)
254
+ return;
324
255
  if (!names.includes(name)) {
325
256
  names.push(name);
326
257
  }
@@ -355,20 +286,10 @@ function resolveBridgeFromWindow(windowRef, preferred) {
355
286
  __name(resolveBridgeFromWindow, "resolveBridgeFromWindow");
356
287
  var _NoxRendererClient = class _NoxRendererClient {
357
288
  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) => {
289
+ this.events = new RendererEventRegistry();
290
+ this.pendingRequests = /* @__PURE__ */ new Map();
291
+ this.isReady = false;
292
+ this.onWindowMessage = /* @__PURE__ */ __name((event) => {
372
293
  if (event.data?.type !== this.initMessageType) {
373
294
  return;
374
295
  }
@@ -395,14 +316,14 @@ var _NoxRendererClient = class _NoxRendererClient {
395
316
  this.isReady = true;
396
317
  this.setupResolve?.();
397
318
  this.resetSetupState(true);
398
- }, "onWindowMessage"));
399
- __publicField(this, "onSocketMessage", /* @__PURE__ */ __name((event) => {
319
+ }, "onWindowMessage");
320
+ this.onSocketMessage = /* @__PURE__ */ __name((event) => {
400
321
  if (this.events.tryDispatchFromMessageEvent(event)) {
401
322
  return;
402
323
  }
403
324
  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) => {
325
+ }, "onSocketMessage");
326
+ this.onRequestMessage = /* @__PURE__ */ __name((event) => {
406
327
  if (this.events.tryDispatchFromMessageEvent(event)) {
407
328
  return;
408
329
  }
@@ -423,11 +344,11 @@ var _NoxRendererClient = class _NoxRendererClient {
423
344
  return;
424
345
  }
425
346
  pending.resolve(response.body);
426
- }, "onRequestMessage"));
347
+ }, "onRequestMessage");
427
348
  this.windowRef = options.windowRef ?? window;
428
349
  const resolvedBridge = options.bridge ?? resolveBridgeFromWindow(this.windowRef, options.bridgeName);
429
350
  this.bridge = resolvedBridge ?? null;
430
- this.initMessageType = options.initMessageType ?? DEFAULT_INIT_EVENT2;
351
+ this.initMessageType = options.initMessageType ?? DEFAULT_INIT_EVENT;
431
352
  this.generateRequestId = options.generateRequestId ?? defaultRequestId;
432
353
  }
433
354
  async setup() {
@@ -555,7 +476,6 @@ export {
555
476
  RendererEventRegistry,
556
477
  Request,
557
478
  createRendererEventMessage,
558
- exposeNoxusBridge,
559
479
  isRendererEventMessage
560
480
  };
561
481
  /**
@@ -563,4 +483,12 @@ export {
563
483
  * @license MIT
564
484
  * @author NoxFly
565
485
  */
486
+ /**
487
+ * @copyright 2025 NoxFly
488
+ * @license MIT
489
+ * @author NoxFly
490
+ *
491
+ * Entry point for renderer web consumers (Angular, React, Vue, Vanilla...).
492
+ * No Electron imports — safe to bundle with any web bundler.
493
+ */
566
494
  //# 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 };