@veloxts/core 0.3.3 → 0.3.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.
- package/README.md +697 -16
- package/dist/app.d.ts +67 -10
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +79 -12
- package/dist/app.js.map +1 -1
- package/dist/context.d.ts +26 -1
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +29 -0
- package/dist/context.js.map +1 -1
- package/dist/di/container.d.ts +406 -0
- package/dist/di/container.d.ts.map +1 -0
- package/dist/di/container.js +699 -0
- package/dist/di/container.js.map +1 -0
- package/dist/di/decorators.d.ts +235 -0
- package/dist/di/decorators.d.ts.map +1 -0
- package/dist/di/decorators.js +297 -0
- package/dist/di/decorators.js.map +1 -0
- package/dist/di/index.d.ts +65 -0
- package/dist/di/index.d.ts.map +1 -0
- package/dist/di/index.js +73 -0
- package/dist/di/index.js.map +1 -0
- package/dist/di/providers.d.ts +397 -0
- package/dist/di/providers.d.ts.map +1 -0
- package/dist/di/providers.js +380 -0
- package/dist/di/providers.js.map +1 -0
- package/dist/di/scope.d.ts +230 -0
- package/dist/di/scope.d.ts.map +1 -0
- package/dist/di/scope.js +294 -0
- package/dist/di/scope.js.map +1 -0
- package/dist/di/tokens.d.ts +227 -0
- package/dist/di/tokens.d.ts.map +1 -0
- package/dist/di/tokens.js +192 -0
- package/dist/di/tokens.js.map +1 -0
- package/dist/errors/catalog.d.ts +79 -0
- package/dist/errors/catalog.d.ts.map +1 -0
- package/dist/errors/catalog.js +492 -0
- package/dist/errors/catalog.js.map +1 -0
- package/dist/errors/formatter.d.ts +101 -0
- package/dist/errors/formatter.d.ts.map +1 -0
- package/dist/errors/formatter.js +330 -0
- package/dist/errors/formatter.js.map +1 -0
- package/dist/errors/index.d.ts +14 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +16 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/errors.d.ts +35 -5
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +57 -4
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +10 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +29 -6
- package/dist/index.js.map +1 -1
- package/package.json +14 -2
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service tokens for dependency injection
|
|
3
|
+
*
|
|
4
|
+
* Tokens are unique identifiers used to register and resolve services.
|
|
5
|
+
* VeloxTS supports three token types:
|
|
6
|
+
* - Class tokens: The class constructor itself
|
|
7
|
+
* - String tokens: String literals for named services
|
|
8
|
+
* - Symbol tokens: Unique symbols for collision-free tokens
|
|
9
|
+
*
|
|
10
|
+
* @module di/tokens
|
|
11
|
+
*/
|
|
12
|
+
import { VeloxError } from '../errors.js';
|
|
13
|
+
// ============================================================================
|
|
14
|
+
// Token Creation Functions
|
|
15
|
+
// ============================================================================
|
|
16
|
+
/**
|
|
17
|
+
* Creates a typed string token for service registration
|
|
18
|
+
*
|
|
19
|
+
* String tokens are useful when you want human-readable identifiers.
|
|
20
|
+
* The type parameter ensures type safety when resolving the service.
|
|
21
|
+
*
|
|
22
|
+
* @template T - The type of service this token represents
|
|
23
|
+
* @param name - The string identifier for this token
|
|
24
|
+
* @returns A typed string token
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* interface DatabaseClient {
|
|
29
|
+
* query(sql: string): Promise<unknown>;
|
|
30
|
+
* }
|
|
31
|
+
*
|
|
32
|
+
* const DATABASE = createStringToken<DatabaseClient>('DATABASE');
|
|
33
|
+
*
|
|
34
|
+
* // Registration
|
|
35
|
+
* container.register({
|
|
36
|
+
* provide: DATABASE,
|
|
37
|
+
* useFactory: () => createDatabaseClient()
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* // Resolution - type is inferred as DatabaseClient
|
|
41
|
+
* const db = container.resolve(DATABASE);
|
|
42
|
+
* await db.query('SELECT * FROM users');
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export function createStringToken(name) {
|
|
46
|
+
return name;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Creates a typed symbol token for service registration
|
|
50
|
+
*
|
|
51
|
+
* Symbol tokens guarantee uniqueness across the application,
|
|
52
|
+
* preventing name collisions between different modules.
|
|
53
|
+
*
|
|
54
|
+
* @template T - The type of service this token represents
|
|
55
|
+
* @param description - Optional description for debugging
|
|
56
|
+
* @returns A typed symbol token
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* interface Logger {
|
|
61
|
+
* log(message: string): void;
|
|
62
|
+
* }
|
|
63
|
+
*
|
|
64
|
+
* const LOGGER = createSymbolToken<Logger>('Logger');
|
|
65
|
+
*
|
|
66
|
+
* // Registration
|
|
67
|
+
* container.register({
|
|
68
|
+
* provide: LOGGER,
|
|
69
|
+
* useClass: ConsoleLogger
|
|
70
|
+
* });
|
|
71
|
+
*
|
|
72
|
+
* // Resolution - type is inferred as Logger
|
|
73
|
+
* const logger = container.resolve(LOGGER);
|
|
74
|
+
* logger.log('Hello, world!');
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export function createSymbolToken(description) {
|
|
78
|
+
return Symbol(description);
|
|
79
|
+
}
|
|
80
|
+
// ============================================================================
|
|
81
|
+
// Succinct Token API
|
|
82
|
+
// ============================================================================
|
|
83
|
+
/**
|
|
84
|
+
* Creates a typed string token for service registration
|
|
85
|
+
*
|
|
86
|
+
* This is the preferred API for creating tokens. String tokens are
|
|
87
|
+
* useful when you want human-readable identifiers.
|
|
88
|
+
*
|
|
89
|
+
* @template T - The type of service this token represents
|
|
90
|
+
* @param name - The string identifier for this token
|
|
91
|
+
* @returns A typed string token
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* const DATABASE = token<DatabaseClient>('DATABASE');
|
|
96
|
+
* const CONFIG = token<AppConfig>('CONFIG');
|
|
97
|
+
*
|
|
98
|
+
* container.register({ provide: DATABASE, useFactory: createDb });
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
export function token(name) {
|
|
102
|
+
return name;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Token creation namespace with factory methods
|
|
106
|
+
*
|
|
107
|
+
* Provides a succinct, grouped API for creating different token types.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* // String token (most common)
|
|
112
|
+
* const DATABASE = token<DatabaseClient>('DATABASE');
|
|
113
|
+
*
|
|
114
|
+
* // Symbol token (guaranteed unique)
|
|
115
|
+
* const LOGGER = token.symbol<Logger>('LOGGER');
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
token.symbol = function symbolToken(description) {
|
|
119
|
+
return Symbol(description);
|
|
120
|
+
};
|
|
121
|
+
// ============================================================================
|
|
122
|
+
// Token Utilities
|
|
123
|
+
// ============================================================================
|
|
124
|
+
/**
|
|
125
|
+
* Gets a human-readable name for a token
|
|
126
|
+
*
|
|
127
|
+
* @param token - The token to get the name for
|
|
128
|
+
* @returns A string representation of the token
|
|
129
|
+
*
|
|
130
|
+
* @internal
|
|
131
|
+
*/
|
|
132
|
+
export function getTokenName(token) {
|
|
133
|
+
// Cast to unknown for proper typeof narrowing without IDE warnings
|
|
134
|
+
// This is safe because InjectionToken runtime values are always string | symbol | function
|
|
135
|
+
const rawToken = token;
|
|
136
|
+
if (typeof rawToken === 'string') {
|
|
137
|
+
return rawToken;
|
|
138
|
+
}
|
|
139
|
+
if (typeof rawToken === 'symbol') {
|
|
140
|
+
return rawToken.description ?? 'Symbol()';
|
|
141
|
+
}
|
|
142
|
+
if (typeof rawToken === 'function') {
|
|
143
|
+
return rawToken.name || 'AnonymousClass';
|
|
144
|
+
}
|
|
145
|
+
return 'Unknown';
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Type guard for class constructor tokens
|
|
149
|
+
*
|
|
150
|
+
* @param token - The token to check
|
|
151
|
+
* @returns true if the token is a class constructor
|
|
152
|
+
*/
|
|
153
|
+
export function isClassToken(token) {
|
|
154
|
+
return typeof token === 'function';
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Type guard for string tokens
|
|
158
|
+
*
|
|
159
|
+
* @param token - The token to check
|
|
160
|
+
* @returns true if the token is a string token
|
|
161
|
+
*/
|
|
162
|
+
export function isStringToken(token) {
|
|
163
|
+
return typeof token === 'string';
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Type guard for symbol tokens
|
|
167
|
+
*
|
|
168
|
+
* @param token - The token to check
|
|
169
|
+
* @returns true if the token is a symbol token
|
|
170
|
+
*/
|
|
171
|
+
export function isSymbolToken(token) {
|
|
172
|
+
// Cast to unknown for proper typeof narrowing without IDE warnings
|
|
173
|
+
return typeof token === 'symbol';
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Validates that a token is a valid injection token
|
|
177
|
+
*
|
|
178
|
+
* @param token - The value to validate
|
|
179
|
+
* @throws {VeloxError} If the token is not valid
|
|
180
|
+
*
|
|
181
|
+
* @internal
|
|
182
|
+
*/
|
|
183
|
+
export function validateToken(token) {
|
|
184
|
+
if (token === null || token === undefined) {
|
|
185
|
+
throw new VeloxError('Injection token cannot be null or undefined', 500, 'INVALID_INJECTION_TOKEN');
|
|
186
|
+
}
|
|
187
|
+
const tokenType = typeof token;
|
|
188
|
+
if (tokenType !== 'string' && tokenType !== 'symbol' && tokenType !== 'function') {
|
|
189
|
+
throw new VeloxError(`Invalid injection token type: ${tokenType}. Expected string, symbol, or class constructor.`, 500, 'INVALID_INJECTION_TOKEN');
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
//# sourceMappingURL=tokens.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.js","sourceRoot":"","sources":["../../src/di/tokens.ts"],"names":[],"mappings":"AAAA;;;;;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AChD,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC;AACrC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,KAAqB;IACjD,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;AACnC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,KAAqB;IACjD,mEAAmE;IACnE,OAAO,OAAQ,KAAiB,KAAK,QAAQ,CAAC;AAChD,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QAC1C,MAAM,IAAI,UAAU,CAClB,6CAA6C,EAC7C,GAAG,EACH,yBAAyB,CAC1B,CAAC;IACJ,CAAC;IAED,MAAM,SAAS,GAAG,OAAO,KAAK,CAAC;IAE/B,IAAI,SAAS,KAAK,QAAQ,IAAI,SAAS,KAAK,QAAQ,IAAI,SAAS,KAAK,UAAU,EAAE,CAAC;QACjF,MAAM,IAAI,UAAU,CAClB,iCAAiC,SAAS,kDAAkD,EAC5F,GAAG,EACH,yBAAyB,CAC1B,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error Catalog - Centralized error definitions with fix suggestions
|
|
3
|
+
*
|
|
4
|
+
* Error codes follow the pattern: VELOX-XYYY
|
|
5
|
+
* - X: Domain (1=Core, 2=Router, 3=Auth, 4=ORM, 5=Validation, 6=Client)
|
|
6
|
+
* - YYY: Sequential number within domain
|
|
7
|
+
*
|
|
8
|
+
* @module errors/catalog
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Error code domain prefixes
|
|
12
|
+
*/
|
|
13
|
+
export declare const ERROR_DOMAINS: {
|
|
14
|
+
readonly CORE: 1;
|
|
15
|
+
readonly ROUTER: 2;
|
|
16
|
+
readonly AUTH: 3;
|
|
17
|
+
readonly ORM: 4;
|
|
18
|
+
readonly VALIDATION: 5;
|
|
19
|
+
readonly CLIENT: 6;
|
|
20
|
+
};
|
|
21
|
+
export type ErrorDomain = keyof typeof ERROR_DOMAINS;
|
|
22
|
+
/**
|
|
23
|
+
* A single error catalog entry with all metadata for developer assistance
|
|
24
|
+
*/
|
|
25
|
+
export interface ErrorCatalogEntry {
|
|
26
|
+
/** Unique error code (e.g., 'VELOX-1001') */
|
|
27
|
+
code: string;
|
|
28
|
+
/** Short title for the error */
|
|
29
|
+
title: string;
|
|
30
|
+
/** Detailed explanation of why this error occurs */
|
|
31
|
+
description: string;
|
|
32
|
+
/** HTTP status code to use */
|
|
33
|
+
statusCode: number;
|
|
34
|
+
/** Suggested fix with code example */
|
|
35
|
+
fix?: {
|
|
36
|
+
/** What the developer should do */
|
|
37
|
+
suggestion: string;
|
|
38
|
+
/** Code example showing the fix (optional) */
|
|
39
|
+
example?: string;
|
|
40
|
+
};
|
|
41
|
+
/** Link to documentation page */
|
|
42
|
+
docsUrl?: string;
|
|
43
|
+
/** Related error codes */
|
|
44
|
+
seeAlso?: string[];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The complete error catalog
|
|
48
|
+
* Organized by domain for easy navigation
|
|
49
|
+
*/
|
|
50
|
+
export declare const ERROR_CATALOG: Record<string, ErrorCatalogEntry>;
|
|
51
|
+
/**
|
|
52
|
+
* Get an error catalog entry by code
|
|
53
|
+
*
|
|
54
|
+
* @param code - The error code (e.g., 'VELOX-1001')
|
|
55
|
+
* @returns The catalog entry or undefined if not found
|
|
56
|
+
*/
|
|
57
|
+
export declare function getErrorEntry(code: string): ErrorCatalogEntry | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* Get all error codes for a specific domain
|
|
60
|
+
*
|
|
61
|
+
* @param domain - The error domain (e.g., 'CORE', 'AUTH')
|
|
62
|
+
* @returns Array of error codes in that domain
|
|
63
|
+
*/
|
|
64
|
+
export declare function getErrorsByDomain(domain: ErrorDomain): string[];
|
|
65
|
+
/**
|
|
66
|
+
* Check if an error code exists in the catalog
|
|
67
|
+
*
|
|
68
|
+
* @param code - The error code to check
|
|
69
|
+
* @returns true if the code exists
|
|
70
|
+
*/
|
|
71
|
+
export declare function isKnownErrorCode(code: string): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Get the documentation URL for an error code
|
|
74
|
+
*
|
|
75
|
+
* @param code - The error code
|
|
76
|
+
* @returns The documentation URL or undefined
|
|
77
|
+
*/
|
|
78
|
+
export declare function getDocsUrl(code: string): string | undefined;
|
|
79
|
+
//# sourceMappingURL=catalog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../../src/errors/catalog.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH;;GAEG;AACH,eAAO,MAAM,aAAa;;;;;;;CAOhB,CAAC;AAEX,MAAM,MAAM,WAAW,GAAG,MAAM,OAAO,aAAa,CAAC;AAMrD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,6CAA6C;IAC7C,IAAI,EAAE,MAAM,CAAC;IAEb,gCAAgC;IAChC,KAAK,EAAE,MAAM,CAAC;IAEd,oDAAoD;IACpD,WAAW,EAAE,MAAM,CAAC;IAEpB,8BAA8B;IAC9B,UAAU,EAAE,MAAM,CAAC;IAEnB,sCAAsC;IACtC,GAAG,CAAC,EAAE;QACJ,mCAAmC;QACnC,UAAU,EAAE,MAAM,CAAC;QACnB,8CAA8C;QAC9C,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;IAEF,iCAAiC;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,0BAA0B;IAC1B,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AAMD;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAqc3D,CAAC;AAMF;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,iBAAiB,GAAG,SAAS,CAEzE;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,EAAE,CAG/D;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEtD;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAE3D"}
|