raiton 5.5.0-beta.3 → 5.7.0-beta.5

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.
@@ -4817,7 +4817,7 @@ var {
4817
4817
  Help
4818
4818
  } = import__.default;
4819
4819
  // package.json
4820
- var version = "5.5.0-beta.3";
4820
+ var version = "5.7.0-beta.5";
4821
4821
 
4822
4822
  // source/bin/cli.ts
4823
4823
  var CLI = new Command;
@@ -6257,6 +6257,7 @@ var METADATA_KEYS = {
6257
6257
  API_RESPONSES: Symbol("api:responses"),
6258
6258
  API_REQUEST_BODY: Symbol("api:requestBody"),
6259
6259
  API_PARAMETERS: Symbol("api:parameters"),
6260
+ API_ENUMS: Symbol("api:enums"),
6260
6261
  API_TAGS: Symbol("api:tags"),
6261
6262
  API_OPERATION: Symbol("api:operation"),
6262
6263
  API_SECURITY: Symbol("api:security")
@@ -6695,7 +6696,7 @@ class Injection {
6695
6696
  const name = metadata?.name || ("constructor" in construct ? construct.constructor.name || false : false) || construct.name;
6696
6697
  if (!metadata) {
6697
6698
  if (typeof name === "undefined")
6698
- Logger.debug("Cannot resolve", construct);
6699
+ Logger.debug("Cannot resolve", name, ":", construct);
6699
6700
  throw new Throwable(`Cannot resolve ${name} as dependency`);
6700
6701
  }
6701
6702
  return this.get(name);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "raiton",
3
- "version": "5.5.0-beta.3",
3
+ "version": "5.7.0-beta.5",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Modular TypeScript Backend Framework with Dependency Injection, Plugins, Controllers, Middleware and Hot Reloading.",
@@ -214,7 +214,7 @@ export class Injection {
214
214
  const name = metadata?.name || ('constructor' in construct ? construct.constructor.name || false : false) || construct.name;
215
215
 
216
216
  if (!metadata) {
217
- if (typeof name === 'undefined') Logger.debug('Cannot resolve', construct);
217
+ if (typeof name === 'undefined') Logger.debug('Cannot resolve', name, ':', construct);
218
218
  throw new Throwable(`Cannot resolve ${name} as dependency`);
219
219
  }
220
220
 
@@ -11,6 +11,7 @@ export const METADATA_KEYS = {
11
11
  API_RESPONSES: Symbol('api:responses'),
12
12
  API_REQUEST_BODY: Symbol('api:requestBody'),
13
13
  API_PARAMETERS: Symbol('api:parameters'),
14
+ API_ENUMS: Symbol('api:enums'),
14
15
  API_TAGS: Symbol('api:tags'),
15
16
  API_OPERATION: Symbol('api:operation'),
16
17
  API_SECURITY: Symbol('api:security'),
@@ -34,7 +34,7 @@ export function ApiTags(...tags: (string | ApiTagOptions)[]) {
34
34
 
35
35
  // Convert string tags to objects
36
36
  const processedTags = tags.map(tag =>
37
- typeof tag === 'string' ? { name: tag } : tag
37
+ typeof tag === 'string' ? {name: tag} : tag
38
38
  );
39
39
 
40
40
  if (propertyKey) {
@@ -173,6 +173,11 @@ export function ApiParam(name: string, options: {
173
173
  * @deprecated
174
174
  */
175
175
  deprecated?: boolean;
176
+
177
+ /**
178
+ * enums values (optional)
179
+ */
180
+ enum?: any[]
176
181
  }) {
177
182
  return function (target: any, propertyKey: string | symbol) {
178
183
  const params = Reflect.getMetadata(METADATA_KEYS.API_PARAMETERS, target) || {};
@@ -180,9 +185,20 @@ export function ApiParam(name: string, options: {
180
185
  params[propertyKey] = [];
181
186
  }
182
187
  params[propertyKey].push({name, ...options});
188
+
189
+ if (options.enum) {
190
+ Reflect.defineMetadata(
191
+ METADATA_KEYS.API_ENUMS,
192
+ {
193
+ [propertyKey]: options.enum
194
+ },
195
+ target
196
+ );
197
+ }
183
198
  Reflect.defineMetadata(METADATA_KEYS.API_PARAMETERS, params, target, propertyKey);
184
199
  };
185
200
  }
201
+
186
202
  /**
187
203
  * Decorator to add query parameter metadata (shortcut for ApiParam with in: 'query')
188
204
  * @param name Parameter name
@@ -214,6 +230,11 @@ export function ApiQuery(name: string, options: {
214
230
  * @deprecated
215
231
  */
216
232
  deprecated?: boolean;
233
+
234
+ /**
235
+ * enums values (optional)
236
+ */
237
+ enum?: any[]
217
238
  }) {
218
239
  return ApiParam(name, {...options, in: 'query'});
219
240
  }
@@ -1,5 +1,6 @@
1
1
  import {RuntimeAdapterInterface} from '../../../types'
2
2
  import {Logger} from "@protorians/logger";
3
+ import {getRealIp} from "../../utilities";
3
4
 
4
5
  export const bunRuntime: RuntimeAdapterInterface = {
5
6
  createServer(handler) {
@@ -14,17 +15,21 @@ export const bunRuntime: RuntimeAdapterInterface = {
14
15
  server = Bun.serve({
15
16
  port,
16
17
  hostname,
17
- fetch: async (request: Request) => {
18
+ fetch: async (request: Request, server: any) => {
18
19
  let responseBody: any
19
20
  let statusCode = 200
20
21
  const headers = new Headers()
21
22
 
23
+ const remoteAddress = server.requestIP(request)?.address
24
+
22
25
  await handler(
23
26
  {
24
27
  method: request.method,
25
28
  url: request.url,
26
29
  headers: request.headers as any,
27
- body: request.body ? request.body : null
30
+ body: request.body ? request.body : null,
31
+ remoteAddress,
32
+ ip: getRealIp(request.headers, remoteAddress)
28
33
  },
29
34
  {
30
35
  status(code) {
@@ -1,5 +1,6 @@
1
1
  import {RuntimeAdapterInterface, RuntimeRequestInterface, RuntimeReplyInterface} from '../../../types'
2
2
  import {Logger} from "@protorians/logger";
3
+ import {getRealIp} from "../../utilities";
3
4
 
4
5
  // class DenoRequest implements RuntimeRequestInterface {
5
6
  // constructor(private req: Request) {}
@@ -12,6 +13,7 @@ import {Logger} from "@protorians/logger";
12
13
  // get file(): any { return undefined; }
13
14
  // get files(): any { return undefined; }
14
15
  // get remoteAddress(): string | undefined { return undefined; }
16
+ // get ip(): string | undefined { return getRealIp(this.headers, this.remoteAddress); }
15
17
  // }
16
18
 
17
19
  // class DenoReply implements RuntimeReplyInterface {
@@ -1,5 +1,6 @@
1
1
  import { IncomingMessage } from 'node:http'
2
2
  import type { RuntimeRequestInterface } from '../../../types'
3
+ import {getRealIp} from "../../utilities";
3
4
 
4
5
  export class NodeRequest implements RuntimeRequestInterface {
5
6
  constructor(public req: IncomingMessage) {
@@ -44,4 +45,8 @@ export class NodeRequest implements RuntimeRequestInterface {
44
45
  get remoteAddress(): string | undefined {
45
46
  return this.req.socket?.remoteAddress
46
47
  }
48
+
49
+ get ip(): string | undefined {
50
+ return getRealIp(this.headers, this.remoteAddress)
51
+ }
47
52
  }
@@ -1,5 +1,6 @@
1
1
  // import {RuntimeAdapterInterface} from '../../../types'
2
2
  // import {Logger} from "@protorians/logger";
3
+ // import {getRealIp} from "../../utilities";
3
4
  //
4
5
  // export const webRuntime: RuntimeAdapterInterface = {
5
6
  // createServer(handler) {
@@ -18,7 +19,9 @@
18
19
  // method: request.method,
19
20
  // url: request.url,
20
21
  // headers: request.headers,
21
- // body: request.body ? request.body : null
22
+ // body: request.body ? request.body : null,
23
+ // remoteAddress: undefined,
24
+ // ip: getRealIp(request.headers, undefined)
22
25
  // },
23
26
  // {
24
27
  // status(code) {
@@ -4,4 +4,5 @@ export * from "./artifact.util"
4
4
  export * from "./json.util"
5
5
  export * from "./path.util"
6
6
  export * from "./cookie.util"
7
- export * from "./openapi.utils"
7
+ export * from "./openapi.utils"
8
+ export * from "./ip.util"
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Get the real IP address from headers or remote address
3
+ * @param headers
4
+ * @param remoteAddress
5
+ */
6
+ export const getRealIp = (headers: Headers, remoteAddress?: string): string | undefined => {
7
+ const forwardedFor = headers.get('x-forwarded-for');
8
+ if (forwardedFor) {
9
+ return forwardedFor.split(',')[0].trim();
10
+ }
11
+ return headers.get('x-real-ip') || remoteAddress;
12
+ }
@@ -18,6 +18,7 @@ export interface RuntimeRequestInterface {
18
18
  file?: any
19
19
  files?: any
20
20
  remoteAddress?: string
21
+ ip?: string
21
22
  }
22
23
 
23
24
  export type RuntimeHandlerCallable = (req: RuntimeRequestInterface, reply: RuntimeReplyInterface) => Promise<void>