@veloxts/core 0.6.90 → 0.6.92
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.
- package/CHANGELOG.md +12 -0
- package/GUIDE.md +1 -49
- package/README.md +1 -1
- package/dist/app.d.ts +0 -32
- package/dist/app.js +0 -38
- package/dist/index.d.ts +3 -7
- package/dist/index.js +3 -8
- package/package.json +3 -8
package/CHANGELOG.md
CHANGED
package/GUIDE.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @veloxts/core
|
|
2
2
|
|
|
3
|
-
Core foundation for VeloxTS Framework providing application bootstrap, plugin system, and
|
|
3
|
+
Core foundation for VeloxTS Framework providing application bootstrap, plugin system, and error handling.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -76,54 +76,6 @@ declare module '@veloxts/core' {
|
|
|
76
76
|
// Now ctx.db is available with full type safety
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
-
## Dependency Injection
|
|
80
|
-
|
|
81
|
-
VeloxTS provides a powerful DI container for managing service dependencies:
|
|
82
|
-
|
|
83
|
-
```typescript
|
|
84
|
-
import { Injectable, Inject, Scope, singleton, scoped } from '@veloxts/core';
|
|
85
|
-
|
|
86
|
-
@Injectable()
|
|
87
|
-
class UserService {
|
|
88
|
-
constructor(private db: PrismaClient) {}
|
|
89
|
-
|
|
90
|
-
async getUser(id: string) {
|
|
91
|
-
return this.db.user.findUniqueOrThrow({ where: { id } });
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// Register services
|
|
96
|
-
app.container.register(singleton(UserService));
|
|
97
|
-
|
|
98
|
-
// Resolve in procedures
|
|
99
|
-
const userService = app.container.resolve(UserService);
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
### Lifecycle Scopes
|
|
103
|
-
|
|
104
|
-
- `Scope.SINGLETON` - One instance for entire application
|
|
105
|
-
- `Scope.REQUEST` - One instance per HTTP request
|
|
106
|
-
- `Scope.TRANSIENT` - New instance every time
|
|
107
|
-
|
|
108
|
-
### Succinct Helpers
|
|
109
|
-
|
|
110
|
-
```typescript
|
|
111
|
-
import { singleton, scoped, transient, value, factory } from '@veloxts/core';
|
|
112
|
-
|
|
113
|
-
// Class services
|
|
114
|
-
app.container.register(singleton(ConfigService));
|
|
115
|
-
app.container.register(scoped(UserContext));
|
|
116
|
-
app.container.register(transient(RequestLogger));
|
|
117
|
-
|
|
118
|
-
// Values
|
|
119
|
-
app.container.register(value(CONFIG, { port: 3030 }));
|
|
120
|
-
|
|
121
|
-
// Factories
|
|
122
|
-
app.container.register(
|
|
123
|
-
factory(DATABASE, (config) => new PrismaClient({ url: config.dbUrl }), [ConfigService])
|
|
124
|
-
);
|
|
125
|
-
```
|
|
126
|
-
|
|
127
79
|
## Error Handling
|
|
128
80
|
|
|
129
81
|
Use structured error classes for consistent API responses:
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> **Early Preview (v0.6.x)** - APIs are stabilizing but may still change. Do not use in production yet.
|
|
4
4
|
|
|
5
|
-
Core foundation package for VeloxTS Framework - provides the Fastify wrapper, plugin system,
|
|
5
|
+
Core foundation package for VeloxTS Framework - provides the Fastify wrapper, plugin system, error handling, and base context. Learn more at [@veloxts/velox](https://www.npmjs.com/package/@veloxts/velox).
|
|
6
6
|
|
|
7
7
|
## License
|
|
8
8
|
|
package/dist/app.d.ts
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* @module app
|
|
5
5
|
*/
|
|
6
6
|
import { type FastifyInstance, type FastifyPluginAsync } from 'fastify';
|
|
7
|
-
import { type Container } from './di/index.js';
|
|
8
7
|
import type { PluginOptions, VeloxPlugin } from './plugin.js';
|
|
9
8
|
import type { StaticOptions } from './plugins/static.js';
|
|
10
9
|
import type { ShutdownHandler } from './types.js';
|
|
@@ -40,7 +39,6 @@ export declare class VeloxApp {
|
|
|
40
39
|
private readonly _server;
|
|
41
40
|
private readonly _config;
|
|
42
41
|
private readonly _lifecycle;
|
|
43
|
-
private readonly _container;
|
|
44
42
|
private _isRunning;
|
|
45
43
|
private _address;
|
|
46
44
|
/**
|
|
@@ -72,36 +70,6 @@ export declare class VeloxApp {
|
|
|
72
70
|
* Application configuration (readonly, frozen)
|
|
73
71
|
*/
|
|
74
72
|
get config(): FrozenVeloxAppConfig;
|
|
75
|
-
/**
|
|
76
|
-
* DI container for the application
|
|
77
|
-
*
|
|
78
|
-
* Provides access to the dependency injection container.
|
|
79
|
-
* Use this to register services and resolve dependencies.
|
|
80
|
-
*
|
|
81
|
-
* @example
|
|
82
|
-
* ```typescript
|
|
83
|
-
* import { Injectable, createStringToken } from '@veloxts/core';
|
|
84
|
-
*
|
|
85
|
-
* const DATABASE = createStringToken<DatabaseClient>('DATABASE');
|
|
86
|
-
*
|
|
87
|
-
* @Injectable()
|
|
88
|
-
* class UserService {
|
|
89
|
-
* constructor(@Inject(DATABASE) private db: DatabaseClient) {}
|
|
90
|
-
* }
|
|
91
|
-
*
|
|
92
|
-
* // Register services
|
|
93
|
-
* app.container.register({
|
|
94
|
-
* provide: DATABASE,
|
|
95
|
-
* useFactory: () => createDatabaseClient()
|
|
96
|
-
* });
|
|
97
|
-
*
|
|
98
|
-
* app.container.register({
|
|
99
|
-
* provide: UserService,
|
|
100
|
-
* useClass: UserService
|
|
101
|
-
* });
|
|
102
|
-
* ```
|
|
103
|
-
*/
|
|
104
|
-
get container(): Container;
|
|
105
73
|
/**
|
|
106
74
|
* Check if server is currently running
|
|
107
75
|
*/
|
package/dist/app.js
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
import fastify from 'fastify';
|
|
7
7
|
import fp from 'fastify-plugin';
|
|
8
8
|
import { setupContextHook } from './context.js';
|
|
9
|
-
import { container } from './di/index.js';
|
|
10
9
|
import { isVeloxError, VeloxError } from './errors.js';
|
|
11
10
|
import { isFastifyPlugin, isVeloxPlugin, validatePluginMetadata } from './plugin.js';
|
|
12
11
|
import { requestLogger } from './plugins/request-logger.js';
|
|
@@ -38,7 +37,6 @@ export class VeloxApp {
|
|
|
38
37
|
_server;
|
|
39
38
|
_config;
|
|
40
39
|
_lifecycle;
|
|
41
|
-
_container;
|
|
42
40
|
_isRunning = false;
|
|
43
41
|
_address = null;
|
|
44
42
|
/**
|
|
@@ -60,10 +58,6 @@ export class VeloxApp {
|
|
|
60
58
|
this._server = fastify(fastifyOptions);
|
|
61
59
|
// Initialize lifecycle manager
|
|
62
60
|
this._lifecycle = new LifecycleManager();
|
|
63
|
-
// Use global container by default
|
|
64
|
-
this._container = container;
|
|
65
|
-
// Attach container to Fastify for request-scoped services
|
|
66
|
-
this._container.attachToFastify(this._server);
|
|
67
61
|
// Set up context decorator
|
|
68
62
|
this._setupContext();
|
|
69
63
|
// Set up error handling
|
|
@@ -101,38 +95,6 @@ export class VeloxApp {
|
|
|
101
95
|
get config() {
|
|
102
96
|
return this._config;
|
|
103
97
|
}
|
|
104
|
-
/**
|
|
105
|
-
* DI container for the application
|
|
106
|
-
*
|
|
107
|
-
* Provides access to the dependency injection container.
|
|
108
|
-
* Use this to register services and resolve dependencies.
|
|
109
|
-
*
|
|
110
|
-
* @example
|
|
111
|
-
* ```typescript
|
|
112
|
-
* import { Injectable, createStringToken } from '@veloxts/core';
|
|
113
|
-
*
|
|
114
|
-
* const DATABASE = createStringToken<DatabaseClient>('DATABASE');
|
|
115
|
-
*
|
|
116
|
-
* @Injectable()
|
|
117
|
-
* class UserService {
|
|
118
|
-
* constructor(@Inject(DATABASE) private db: DatabaseClient) {}
|
|
119
|
-
* }
|
|
120
|
-
*
|
|
121
|
-
* // Register services
|
|
122
|
-
* app.container.register({
|
|
123
|
-
* provide: DATABASE,
|
|
124
|
-
* useFactory: () => createDatabaseClient()
|
|
125
|
-
* });
|
|
126
|
-
*
|
|
127
|
-
* app.container.register({
|
|
128
|
-
* provide: UserService,
|
|
129
|
-
* useClass: UserService
|
|
130
|
-
* });
|
|
131
|
-
* ```
|
|
132
|
-
*/
|
|
133
|
-
get container() {
|
|
134
|
-
return this._container;
|
|
135
|
-
}
|
|
136
98
|
/**
|
|
137
99
|
* Check if server is currently running
|
|
138
100
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @veloxts/core - Foundation package for the VeloxTS framework
|
|
3
3
|
*
|
|
4
|
-
* Provides the core Fastify wrapper, plugin system, base context
|
|
5
|
-
*
|
|
6
|
-
* packages build upon.
|
|
4
|
+
* Provides the core Fastify wrapper, plugin system, and base context
|
|
5
|
+
* that all other framework packages build upon.
|
|
7
6
|
*
|
|
8
7
|
* @example
|
|
9
8
|
* ```typescript
|
|
10
|
-
* import { velox, definePlugin
|
|
9
|
+
* import { velox, definePlugin } from '@veloxts/core';
|
|
11
10
|
*
|
|
12
11
|
* const app = await velox({ port: 3030 });
|
|
13
12
|
* await app.start();
|
|
@@ -15,7 +14,6 @@
|
|
|
15
14
|
*
|
|
16
15
|
* @module @veloxts/core
|
|
17
16
|
*/
|
|
18
|
-
import 'reflect-metadata';
|
|
19
17
|
/** VeloxTS framework version */
|
|
20
18
|
export declare const VELOX_VERSION: string;
|
|
21
19
|
export type { FastifyLoggerOptions, FastifyReply, FastifyRequest } from 'fastify';
|
|
@@ -23,8 +21,6 @@ export type { StartOptions } from './app.js';
|
|
|
23
21
|
export { VeloxApp, velox, veloxApp } from './app.js';
|
|
24
22
|
export type { BaseContext } from './context.js';
|
|
25
23
|
export { createContext, isContext, setupContextHook, setupTestContext } from './context.js';
|
|
26
|
-
export type { AbstractClass, ClassConstructor, ClassProvider, ContainerOptions, ExistingProvider, FactoryProvider, InjectableOptions, InjectionToken, Provider, ResolutionContext, StringToken, SymbolToken, TokenType, ValueProvider, } from './di/index.js';
|
|
27
|
-
export { asClass, asExisting, asFactory, asValue, Container, container, factory, getConstructorTokens, getExplicitInjectTokens, getInjectableScope, getOptionalParams, getTokenName, Inject, Injectable, isClassProvider, isClassToken, isExistingProvider, isFactoryProvider, isInjectable, isStringToken, isSymbolToken, isValueProvider, makeInjectable, Optional, Scope, ScopeManager, scoped, setInjectTokens, singleton, token, transient, validateProvider, validateToken, value, } from './di/index.js';
|
|
28
24
|
export type { ErrorCode, ErrorResponse, GenericErrorResponse, InterpolationVars, NotFoundErrorResponse, ValidationErrorResponse, VeloxCoreErrorCode, VeloxErrorCode, VeloxErrorCodeRegistry, } from './errors.js';
|
|
29
25
|
export { assertNever, ConfigurationError, fail, isConfigurationError, isNotFoundError, isNotFoundErrorResponse, isValidationError, isValidationErrorResponse, isVeloxError, isVeloxFailure, logDeprecation, logWarning, NotFoundError, ValidationError, VeloxError, VeloxFailure, } from './errors.js';
|
|
30
26
|
export type { InferPluginOptions, PluginMetadata, PluginOptions, VeloxPlugin } from './plugin.js';
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @veloxts/core - Foundation package for the VeloxTS framework
|
|
3
3
|
*
|
|
4
|
-
* Provides the core Fastify wrapper, plugin system, base context
|
|
5
|
-
*
|
|
6
|
-
* packages build upon.
|
|
4
|
+
* Provides the core Fastify wrapper, plugin system, and base context
|
|
5
|
+
* that all other framework packages build upon.
|
|
7
6
|
*
|
|
8
7
|
* @example
|
|
9
8
|
* ```typescript
|
|
10
|
-
* import { velox, definePlugin
|
|
9
|
+
* import { velox, definePlugin } from '@veloxts/core';
|
|
11
10
|
*
|
|
12
11
|
* const app = await velox({ port: 3030 });
|
|
13
12
|
* await app.start();
|
|
@@ -15,8 +14,6 @@
|
|
|
15
14
|
*
|
|
16
15
|
* @module @veloxts/core
|
|
17
16
|
*/
|
|
18
|
-
// Import reflect-metadata for decorator support
|
|
19
|
-
import 'reflect-metadata';
|
|
20
17
|
import { createRequire } from 'node:module';
|
|
21
18
|
// Read version from package.json dynamically
|
|
22
19
|
const require = createRequire(import.meta.url);
|
|
@@ -25,8 +22,6 @@ const packageJson = require('../package.json');
|
|
|
25
22
|
export const VELOX_VERSION = packageJson.version ?? '0.0.0-unknown';
|
|
26
23
|
export { VeloxApp, velox, veloxApp } from './app.js';
|
|
27
24
|
export { createContext, isContext, setupContextHook, setupTestContext } from './context.js';
|
|
28
|
-
// Dependency Injection
|
|
29
|
-
export { asClass, asExisting, asFactory, asValue, Container, container, factory, getConstructorTokens, getExplicitInjectTokens, getInjectableScope, getOptionalParams, getTokenName, Inject, Injectable, isClassProvider, isClassToken, isExistingProvider, isFactoryProvider, isInjectable, isStringToken, isSymbolToken, isValueProvider, makeInjectable, Optional, Scope, ScopeManager, scoped, setInjectTokens, singleton, token, transient, validateProvider, validateToken, value, } from './di/index.js';
|
|
30
25
|
export { assertNever, ConfigurationError,
|
|
31
26
|
// Elegant error creation API
|
|
32
27
|
fail, isConfigurationError, isNotFoundError, isNotFoundErrorResponse, isValidationError, isValidationErrorResponse, isVeloxError, isVeloxFailure,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@veloxts/core",
|
|
3
|
-
"version": "0.6.
|
|
4
|
-
"description": "Fastify wrapper
|
|
3
|
+
"version": "0.6.92",
|
|
4
|
+
"description": "Fastify wrapper and plugin system for VeloxTS framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -9,10 +9,6 @@
|
|
|
9
9
|
".": {
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
11
|
"import": "./dist/index.js"
|
|
12
|
-
},
|
|
13
|
-
"./di": {
|
|
14
|
-
"types": "./dist/di/index.d.ts",
|
|
15
|
-
"import": "./dist/di/index.js"
|
|
16
12
|
}
|
|
17
13
|
},
|
|
18
14
|
"files": [
|
|
@@ -35,8 +31,7 @@
|
|
|
35
31
|
"dependencies": {
|
|
36
32
|
"fastify": "5.7.2",
|
|
37
33
|
"fastify-plugin": "5.1.0",
|
|
38
|
-
"picocolors": "1.1.1"
|
|
39
|
-
"reflect-metadata": "0.2.2"
|
|
34
|
+
"picocolors": "1.1.1"
|
|
40
35
|
},
|
|
41
36
|
"peerDependencies": {
|
|
42
37
|
"@fastify/static": ">=8.0.0"
|