@velajs/vela 0.1.0 → 0.2.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.
@@ -0,0 +1,5 @@
1
+ import type { DynamicModule } from '../module/types';
2
+ import type { ConfigModuleOptions } from './config.types';
3
+ export declare class ConfigModule {
4
+ static forRoot<T extends Record<string, unknown>>(options: ConfigModuleOptions<T>): DynamicModule;
5
+ }
@@ -0,0 +1,32 @@
1
+ import { METADATA_KEYS } from "../constants.js";
2
+ import { defineMetadata } from "../metadata.js";
3
+ import { MetadataRegistry } from "../registry/metadata.registry.js";
4
+ import { ConfigService } from "./config.service.js";
5
+ import { CONFIG_OPTIONS } from "./config.tokens.js";
6
+ export class ConfigModule {
7
+ static forRoot(options) {
8
+ const config = options.validate ? options.validate(options.config) : options.config;
9
+ const moduleClass = class ConfigDynamicModule {
10
+ };
11
+ Object.defineProperty(moduleClass, 'name', {
12
+ value: 'ConfigModule'
13
+ });
14
+ defineMetadata(METADATA_KEYS.MODULE, true, moduleClass);
15
+ MetadataRegistry.setModuleOptions(moduleClass, {
16
+ exports: [
17
+ ConfigService,
18
+ CONFIG_OPTIONS
19
+ ]
20
+ });
21
+ return {
22
+ module: moduleClass,
23
+ providers: [
24
+ {
25
+ token: CONFIG_OPTIONS,
26
+ useValue: config
27
+ },
28
+ ConfigService
29
+ ]
30
+ };
31
+ }
32
+ }
@@ -0,0 +1,7 @@
1
+ export declare class ConfigService<T extends Record<string, unknown> = Record<string, unknown>> {
2
+ private readonly config;
3
+ constructor(config: T);
4
+ get<V>(key: string): V | undefined;
5
+ get<V>(key: string, defaultValue: V): V;
6
+ getAll(): T;
7
+ }
@@ -0,0 +1,45 @@
1
+ function _ts_decorate(decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ }
7
+ function _ts_metadata(k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ }
10
+ function _ts_param(paramIndex, decorator) {
11
+ return function(target, key) {
12
+ decorator(target, key, paramIndex);
13
+ };
14
+ }
15
+ import { Injectable } from "../container/decorators.js";
16
+ import { Inject } from "../container/decorators.js";
17
+ import { CONFIG_OPTIONS } from "./config.tokens.js";
18
+ export class ConfigService {
19
+ config;
20
+ constructor(config){
21
+ this.config = config;
22
+ }
23
+ get(key, defaultValue) {
24
+ const parts = key.split('.');
25
+ let current = this.config;
26
+ for (const part of parts){
27
+ if (current === null || current === undefined || typeof current !== 'object') {
28
+ return defaultValue;
29
+ }
30
+ current = current[part];
31
+ }
32
+ return current ?? defaultValue;
33
+ }
34
+ getAll() {
35
+ return this.config;
36
+ }
37
+ }
38
+ ConfigService = _ts_decorate([
39
+ Injectable(),
40
+ _ts_param(0, Inject(CONFIG_OPTIONS)),
41
+ _ts_metadata("design:type", Function),
42
+ _ts_metadata("design:paramtypes", [
43
+ typeof T === "undefined" ? Object : T
44
+ ])
45
+ ], ConfigService);
@@ -0,0 +1,2 @@
1
+ import { InjectionToken } from '../container/types';
2
+ export declare const CONFIG_OPTIONS: InjectionToken<Record<string, unknown>>;
@@ -0,0 +1,2 @@
1
+ import { InjectionToken } from "../container/types.js";
2
+ export const CONFIG_OPTIONS = new InjectionToken('CONFIG_OPTIONS');
@@ -0,0 +1,4 @@
1
+ export interface ConfigModuleOptions<T extends Record<string, unknown> = Record<string, unknown>> {
2
+ config: T;
3
+ validate?: (config: T) => T;
4
+ }
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,4 @@
1
+ export { ConfigModule } from './config.module';
2
+ export { ConfigService } from './config.service';
3
+ export { CONFIG_OPTIONS } from './config.tokens';
4
+ export type { ConfigModuleOptions } from './config.types';
@@ -0,0 +1,3 @@
1
+ export { ConfigModule } from "./config.module.js";
2
+ export { ConfigService } from "./config.service.js";
3
+ export { CONFIG_OPTIONS } from "./config.tokens.js";
@@ -38,6 +38,7 @@ export declare const Patch: (path?: string) => MethodDecorator;
38
38
  export declare const Delete: (path?: string) => MethodDecorator;
39
39
  export declare const Options: (path?: string) => MethodDecorator;
40
40
  export declare const Head: (path?: string) => MethodDecorator;
41
+ export declare const Sse: (path?: string) => MethodDecorator;
41
42
  export declare const Param: (nameOrPipe?: string | PipeType, ...pipes: PipeType[]) => ParameterDecorator;
42
43
  export declare const Query: (nameOrPipe?: string | PipeType, ...pipes: PipeType[]) => ParameterDecorator;
43
44
  export declare const Body: (nameOrPipe?: string | PipeType, ...pipes: PipeType[]) => ParameterDecorator;
@@ -96,6 +96,7 @@ export const Patch = createMethodDecorator(HttpMethod.PATCH);
96
96
  export const Delete = createMethodDecorator(HttpMethod.DELETE);
97
97
  export const Options = createMethodDecorator(HttpMethod.OPTIONS);
98
98
  export const Head = createMethodDecorator(HttpMethod.HEAD);
99
+ export const Sse = createMethodDecorator(HttpMethod.GET);
99
100
  // Parameter decorators
100
101
  const CUSTOM_PARAM_TYPE = 'custom';
101
102
  function createBuiltinParamDecorator(type) {
@@ -1,3 +1,3 @@
1
1
  export { RouteManager } from './route.manager';
2
- export { Controller, Version, Get, Post, Put, Patch, Delete, Options, Head, Param, Query, Body, Headers, Req, HttpCode, Header, Redirect, createParamDecorator, isController, } from './decorators';
2
+ export { Controller, Version, Get, Post, Put, Patch, Delete, Options, Head, Sse, Param, Query, Body, Headers, Req, HttpCode, Header, Redirect, createParamDecorator, isController, } from './decorators';
3
3
  export type { RouteMetadata, ControllerMetadata, ControllerOptions, ParamMetadata, ControllerRegistration, } from './types';
@@ -1,2 +1,2 @@
1
1
  export { RouteManager } from "./route.manager.js";
2
- export { Controller, Version, Get, Post, Put, Patch, Delete, Options, Head, Param, Query, Body, Headers, Req, HttpCode, Header, Redirect, createParamDecorator, isController } from "./decorators.js";
2
+ export { Controller, Version, Get, Post, Put, Patch, Delete, Options, Head, Sse, Param, Query, Body, Headers, Req, HttpCode, Header, Redirect, createParamDecorator, isController } from "./decorators.js";
package/dist/index.d.ts CHANGED
@@ -5,7 +5,11 @@ export { VelaApplication } from './application';
5
5
  export { Container, Injectable, Inject, InjectionToken } from './container/index';
6
6
  export type { Type, Token, InjectableOptions, ProviderOptions, } from './container/index';
7
7
  export { METADATA_KEYS, HttpMethod, ParamType, Scope } from './constants';
8
- export { Controller, Version, Get, Post, Put, Patch, Delete, Options, Head, Param, Query, Body, Headers, Req, HttpCode, Header, Redirect, createParamDecorator, } from './http/index';
8
+ export { Controller, Version, Get, Post, Put, Patch, Delete, Options, Head, Sse, Param, Query, Body, Headers, Req, HttpCode, Header, Redirect, createParamDecorator, } from './http/index';
9
+ export { Logger, LogLevel } from './services/index';
10
+ export type { LoggerService } from './services/index';
11
+ export { ConfigModule, ConfigService, CONFIG_OPTIONS } from './config/index';
12
+ export type { ConfigModuleOptions } from './config/index';
9
13
  export { Module } from './module/index';
10
14
  export type { ModuleOptions, DynamicModule } from './module/index';
11
15
  export { UseMiddleware, UseGuards, UsePipes, UseInterceptors, UseFilters, Catch, SetMetadata, Reflector, APP_GUARD, APP_PIPE, APP_INTERCEPTOR, APP_FILTER, APP_MIDDLEWARE, } from './pipeline/index';
package/dist/index.js CHANGED
@@ -8,7 +8,11 @@ export { Container, Injectable, Inject, InjectionToken } from "./container/index
8
8
  // Constants
9
9
  export { METADATA_KEYS, HttpMethod, ParamType, Scope } from "./constants.js";
10
10
  // HTTP Decorators
11
- export { Controller, Version, Get, Post, Put, Patch, Delete, Options, Head, Param, Query, Body, Headers, Req, HttpCode, Header, Redirect, createParamDecorator } from "./http/index.js";
11
+ export { Controller, Version, Get, Post, Put, Patch, Delete, Options, Head, Sse, Param, Query, Body, Headers, Req, HttpCode, Header, Redirect, createParamDecorator } from "./http/index.js";
12
+ // Services
13
+ export { Logger, LogLevel } from "./services/index.js";
14
+ // Config
15
+ export { ConfigModule, ConfigService, CONFIG_OPTIONS } from "./config/index.js";
12
16
  // Module
13
17
  export { Module } from "./module/index.js";
14
18
  // Pipeline Decorators
@@ -0,0 +1,2 @@
1
+ export { Logger, LogLevel } from './logger';
2
+ export type { LoggerService } from './logger';
@@ -0,0 +1 @@
1
+ export { Logger, LogLevel } from "./logger.js";
@@ -0,0 +1,30 @@
1
+ export declare enum LogLevel {
2
+ VERBOSE = 0,
3
+ DEBUG = 1,
4
+ LOG = 2,
5
+ WARN = 3,
6
+ ERROR = 4,
7
+ SILENT = 5
8
+ }
9
+ export interface LoggerService {
10
+ log(message: unknown, ...optionalParams: unknown[]): void;
11
+ error(message: unknown, ...optionalParams: unknown[]): void;
12
+ warn(message: unknown, ...optionalParams: unknown[]): void;
13
+ debug?(message: unknown, ...optionalParams: unknown[]): void;
14
+ verbose?(message: unknown, ...optionalParams: unknown[]): void;
15
+ }
16
+ export declare class Logger implements LoggerService {
17
+ static level: LogLevel;
18
+ private static globalLogger;
19
+ private context?;
20
+ static setLogLevel(level: LogLevel): void;
21
+ static overrideLogger(logger: LoggerService | false): void;
22
+ constructor(context?: string);
23
+ setContext(context: string): void;
24
+ log(message: unknown, ...optionalParams: unknown[]): void;
25
+ error(message: unknown, ...optionalParams: unknown[]): void;
26
+ warn(message: unknown, ...optionalParams: unknown[]): void;
27
+ debug(message: unknown, ...optionalParams: unknown[]): void;
28
+ verbose(message: unknown, ...optionalParams: unknown[]): void;
29
+ private formatMessage;
30
+ }
@@ -0,0 +1,95 @@
1
+ function _ts_decorate(decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ }
7
+ function _ts_metadata(k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ }
10
+ import { Injectable } from "../container/decorators.js";
11
+ export var LogLevel = /*#__PURE__*/ function(LogLevel) {
12
+ LogLevel[LogLevel["VERBOSE"] = 0] = "VERBOSE";
13
+ LogLevel[LogLevel["DEBUG"] = 1] = "DEBUG";
14
+ LogLevel[LogLevel["LOG"] = 2] = "LOG";
15
+ LogLevel[LogLevel["WARN"] = 3] = "WARN";
16
+ LogLevel[LogLevel["ERROR"] = 4] = "ERROR";
17
+ LogLevel[LogLevel["SILENT"] = 5] = "SILENT";
18
+ return LogLevel;
19
+ }({});
20
+ export class Logger {
21
+ static level = 2;
22
+ static globalLogger;
23
+ context;
24
+ static setLogLevel(level) {
25
+ Logger.level = level;
26
+ }
27
+ static overrideLogger(logger) {
28
+ Logger.globalLogger = logger;
29
+ }
30
+ constructor(context){
31
+ if (context) {
32
+ this.context = context;
33
+ }
34
+ }
35
+ setContext(context) {
36
+ this.context = context;
37
+ }
38
+ log(message, ...optionalParams) {
39
+ if (Logger.level > 2) return;
40
+ if (Logger.globalLogger === false) return;
41
+ if (Logger.globalLogger) {
42
+ Logger.globalLogger.log(message, ...optionalParams);
43
+ return;
44
+ }
45
+ console.log(this.formatMessage('LOG', message), ...optionalParams);
46
+ }
47
+ error(message, ...optionalParams) {
48
+ if (Logger.level > 4) return;
49
+ if (Logger.globalLogger === false) return;
50
+ if (Logger.globalLogger) {
51
+ Logger.globalLogger.error(message, ...optionalParams);
52
+ return;
53
+ }
54
+ console.error(this.formatMessage('ERROR', message), ...optionalParams);
55
+ }
56
+ warn(message, ...optionalParams) {
57
+ if (Logger.level > 3) return;
58
+ if (Logger.globalLogger === false) return;
59
+ if (Logger.globalLogger) {
60
+ Logger.globalLogger.warn(message, ...optionalParams);
61
+ return;
62
+ }
63
+ console.warn(this.formatMessage('WARN', message), ...optionalParams);
64
+ }
65
+ debug(message, ...optionalParams) {
66
+ if (Logger.level > 1) return;
67
+ if (Logger.globalLogger === false) return;
68
+ if (Logger.globalLogger) {
69
+ Logger.globalLogger.debug?.(message, ...optionalParams);
70
+ return;
71
+ }
72
+ console.debug(this.formatMessage('DEBUG', message), ...optionalParams);
73
+ }
74
+ verbose(message, ...optionalParams) {
75
+ if (Logger.level > 0) return;
76
+ if (Logger.globalLogger === false) return;
77
+ if (Logger.globalLogger) {
78
+ Logger.globalLogger.verbose?.(message, ...optionalParams);
79
+ return;
80
+ }
81
+ console.debug(this.formatMessage('VERBOSE', message), ...optionalParams);
82
+ }
83
+ formatMessage(level, message) {
84
+ const timestamp = new Date().toISOString();
85
+ const ctx = this.context ? ` [${this.context}]` : '';
86
+ return `[Vela] ${timestamp} ${level}${ctx} ${message}`;
87
+ }
88
+ }
89
+ Logger = _ts_decorate([
90
+ Injectable(),
91
+ _ts_metadata("design:type", Function),
92
+ _ts_metadata("design:paramtypes", [
93
+ String
94
+ ])
95
+ ], Logger);
@@ -0,0 +1,2 @@
1
+ export { streamSSE, stream, streamText } from 'hono/streaming';
2
+ export type { SSEStreamingApi, SSEMessage } from 'hono/streaming';
@@ -0,0 +1 @@
1
+ export { streamSSE, stream, streamText } from "hono/streaming";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@velajs/vela",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "NestJS-compatible framework for edge runtimes, powered by Hono",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -9,6 +9,10 @@
9
9
  ".": {
10
10
  "types": "./dist/index.d.ts",
11
11
  "import": "./dist/index.js"
12
+ },
13
+ "./streaming": {
14
+ "types": "./dist/streaming/index.d.ts",
15
+ "import": "./dist/streaming/index.js"
12
16
  }
13
17
  },
14
18
  "files": [