vector-framework 1.2.1 → 1.2.3
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 +18 -6
- package/dist/auth/protected.d.ts +4 -4
- package/dist/auth/protected.d.ts.map +1 -1
- package/dist/auth/protected.js +10 -7
- package/dist/auth/protected.js.map +1 -1
- package/dist/cache/manager.d.ts +2 -0
- package/dist/cache/manager.d.ts.map +1 -1
- package/dist/cache/manager.js +21 -4
- package/dist/cache/manager.js.map +1 -1
- package/dist/checkpoint/artifacts/compressor.d.ts +5 -0
- package/dist/checkpoint/artifacts/compressor.d.ts.map +1 -0
- package/dist/checkpoint/artifacts/compressor.js +24 -0
- package/dist/checkpoint/artifacts/compressor.js.map +1 -0
- package/dist/checkpoint/artifacts/decompress-worker.d.ts +2 -0
- package/dist/checkpoint/artifacts/decompress-worker.d.ts.map +1 -0
- package/dist/checkpoint/artifacts/decompress-worker.js +31 -0
- package/dist/checkpoint/artifacts/decompress-worker.js.map +1 -0
- package/dist/checkpoint/artifacts/hasher.d.ts +2 -0
- package/dist/checkpoint/artifacts/hasher.d.ts.map +1 -0
- package/dist/checkpoint/artifacts/hasher.js +7 -0
- package/dist/checkpoint/artifacts/hasher.js.map +1 -0
- package/dist/checkpoint/artifacts/manifest.d.ts +6 -0
- package/dist/checkpoint/artifacts/manifest.d.ts.map +1 -0
- package/dist/checkpoint/artifacts/manifest.js +55 -0
- package/dist/checkpoint/artifacts/manifest.js.map +1 -0
- package/dist/checkpoint/artifacts/materializer.d.ts +16 -0
- package/dist/checkpoint/artifacts/materializer.d.ts.map +1 -0
- package/dist/checkpoint/artifacts/materializer.js +168 -0
- package/dist/checkpoint/artifacts/materializer.js.map +1 -0
- package/dist/checkpoint/artifacts/packager.d.ts +12 -0
- package/dist/checkpoint/artifacts/packager.d.ts.map +1 -0
- package/dist/checkpoint/artifacts/packager.js +82 -0
- package/dist/checkpoint/artifacts/packager.js.map +1 -0
- package/dist/checkpoint/artifacts/repository.d.ts +11 -0
- package/dist/checkpoint/artifacts/repository.d.ts.map +1 -0
- package/dist/checkpoint/artifacts/repository.js +29 -0
- package/dist/checkpoint/artifacts/repository.js.map +1 -0
- package/dist/checkpoint/artifacts/store.d.ts +13 -0
- package/dist/checkpoint/artifacts/store.d.ts.map +1 -0
- package/dist/checkpoint/artifacts/store.js +85 -0
- package/dist/checkpoint/artifacts/store.js.map +1 -0
- package/dist/checkpoint/artifacts/types.d.ts +21 -0
- package/dist/checkpoint/artifacts/types.d.ts.map +1 -0
- package/dist/checkpoint/artifacts/types.js +2 -0
- package/dist/checkpoint/artifacts/types.js.map +1 -0
- package/dist/checkpoint/artifacts/worker-decompressor.d.ts +17 -0
- package/dist/checkpoint/artifacts/worker-decompressor.d.ts.map +1 -0
- package/dist/checkpoint/artifacts/worker-decompressor.js +148 -0
- package/dist/checkpoint/artifacts/worker-decompressor.js.map +1 -0
- package/dist/checkpoint/asset-store.d.ts +10 -0
- package/dist/checkpoint/asset-store.d.ts.map +1 -0
- package/dist/checkpoint/asset-store.js +46 -0
- package/dist/checkpoint/asset-store.js.map +1 -0
- package/dist/checkpoint/bundler.d.ts +15 -0
- package/dist/checkpoint/bundler.d.ts.map +1 -0
- package/dist/checkpoint/bundler.js +45 -0
- package/dist/checkpoint/bundler.js.map +1 -0
- package/dist/checkpoint/cli.d.ts +2 -0
- package/dist/checkpoint/cli.d.ts.map +1 -0
- package/dist/checkpoint/cli.js +157 -0
- package/dist/checkpoint/cli.js.map +1 -0
- package/dist/checkpoint/entrypoint-generator.d.ts +17 -0
- package/dist/checkpoint/entrypoint-generator.d.ts.map +1 -0
- package/dist/checkpoint/entrypoint-generator.js +251 -0
- package/dist/checkpoint/entrypoint-generator.js.map +1 -0
- package/dist/checkpoint/forwarder.d.ts +6 -0
- package/dist/checkpoint/forwarder.d.ts.map +1 -0
- package/dist/checkpoint/forwarder.js +74 -0
- package/dist/checkpoint/forwarder.js.map +1 -0
- package/dist/checkpoint/gateway.d.ts +11 -0
- package/dist/checkpoint/gateway.d.ts.map +1 -0
- package/dist/checkpoint/gateway.js +30 -0
- package/dist/checkpoint/gateway.js.map +1 -0
- package/dist/checkpoint/ipc.d.ts +12 -0
- package/dist/checkpoint/ipc.d.ts.map +1 -0
- package/dist/checkpoint/ipc.js +96 -0
- package/dist/checkpoint/ipc.js.map +1 -0
- package/dist/checkpoint/manager.d.ts +20 -0
- package/dist/checkpoint/manager.d.ts.map +1 -0
- package/dist/checkpoint/manager.js +214 -0
- package/dist/checkpoint/manager.js.map +1 -0
- package/dist/checkpoint/process-manager.d.ts +35 -0
- package/dist/checkpoint/process-manager.d.ts.map +1 -0
- package/dist/checkpoint/process-manager.js +203 -0
- package/dist/checkpoint/process-manager.js.map +1 -0
- package/dist/checkpoint/resolver.d.ts +25 -0
- package/dist/checkpoint/resolver.d.ts.map +1 -0
- package/dist/checkpoint/resolver.js +95 -0
- package/dist/checkpoint/resolver.js.map +1 -0
- package/dist/checkpoint/socket-path.d.ts +2 -0
- package/dist/checkpoint/socket-path.d.ts.map +1 -0
- package/dist/checkpoint/socket-path.js +51 -0
- package/dist/checkpoint/socket-path.js.map +1 -0
- package/dist/checkpoint/types.d.ts +54 -0
- package/dist/checkpoint/types.d.ts.map +1 -0
- package/dist/checkpoint/types.js +2 -0
- package/dist/checkpoint/types.js.map +1 -0
- package/dist/cli/index.js +10 -2
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/option-resolution.d.ts +1 -1
- package/dist/cli/option-resolution.d.ts.map +1 -1
- package/dist/cli/option-resolution.js.map +1 -1
- package/dist/cli.js +3817 -350
- package/dist/core/config-loader.d.ts +1 -0
- package/dist/core/config-loader.d.ts.map +1 -1
- package/dist/core/config-loader.js +10 -2
- package/dist/core/config-loader.js.map +1 -1
- package/dist/core/router.d.ts +24 -3
- package/dist/core/router.d.ts.map +1 -1
- package/dist/core/router.js +398 -249
- package/dist/core/router.js.map +1 -1
- package/dist/core/server.d.ts +3 -0
- package/dist/core/server.d.ts.map +1 -1
- package/dist/core/server.js +35 -10
- package/dist/core/server.js.map +1 -1
- package/dist/core/vector.d.ts +3 -0
- package/dist/core/vector.d.ts.map +1 -1
- package/dist/core/vector.js +51 -1
- package/dist/core/vector.js.map +1 -1
- package/dist/dev/route-scanner.d.ts.map +1 -1
- package/dist/dev/route-scanner.js +2 -1
- package/dist/dev/route-scanner.js.map +1 -1
- package/dist/errors/index.cjs +2 -0
- package/dist/http.d.ts +32 -7
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +144 -13
- package/dist/http.js.map +1 -1
- package/dist/index.cjs +2657 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -1433
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1301 -77
- package/dist/middleware/manager.d.ts +3 -3
- package/dist/middleware/manager.d.ts.map +1 -1
- package/dist/middleware/manager.js +9 -8
- package/dist/middleware/manager.js.map +1 -1
- package/dist/openapi/docs-ui.d.ts.map +1 -1
- package/dist/openapi/docs-ui.js +1097 -61
- package/dist/openapi/docs-ui.js.map +1 -1
- package/dist/openapi/generator.d.ts +2 -1
- package/dist/openapi/generator.d.ts.map +1 -1
- package/dist/openapi/generator.js +332 -16
- package/dist/openapi/generator.js.map +1 -1
- package/dist/types/index.d.ts +71 -28
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +24 -1
- package/dist/types/index.js.map +1 -1
- package/dist/utils/validation.d.ts.map +1 -1
- package/dist/utils/validation.js +3 -2
- package/dist/utils/validation.js.map +1 -1
- package/package.json +9 -14
- package/src/auth/protected.ts +11 -8
- package/src/cache/manager.ts +23 -4
- package/src/checkpoint/artifacts/compressor.ts +30 -0
- package/src/checkpoint/artifacts/decompress-worker.ts +49 -0
- package/src/checkpoint/artifacts/hasher.ts +6 -0
- package/src/checkpoint/artifacts/manifest.ts +72 -0
- package/src/checkpoint/artifacts/materializer.ts +211 -0
- package/src/checkpoint/artifacts/packager.ts +100 -0
- package/src/checkpoint/artifacts/repository.ts +36 -0
- package/src/checkpoint/artifacts/store.ts +102 -0
- package/src/checkpoint/artifacts/types.ts +24 -0
- package/src/checkpoint/artifacts/worker-decompressor.ts +192 -0
- package/src/checkpoint/asset-store.ts +61 -0
- package/src/checkpoint/bundler.ts +64 -0
- package/src/checkpoint/cli.ts +177 -0
- package/src/checkpoint/entrypoint-generator.ts +275 -0
- package/src/checkpoint/forwarder.ts +84 -0
- package/src/checkpoint/gateway.ts +40 -0
- package/src/checkpoint/ipc.ts +107 -0
- package/src/checkpoint/manager.ts +254 -0
- package/src/checkpoint/process-manager.ts +250 -0
- package/src/checkpoint/resolver.ts +124 -0
- package/src/checkpoint/socket-path.ts +61 -0
- package/src/checkpoint/types.ts +63 -0
- package/src/cli/index.ts +11 -2
- package/src/cli/option-resolution.ts +5 -1
- package/src/core/config-loader.ts +11 -2
- package/src/core/router.ts +505 -264
- package/src/core/server.ts +51 -11
- package/src/core/vector.ts +60 -1
- package/src/dev/route-scanner.ts +2 -1
- package/src/http.ts +219 -19
- package/src/index.ts +3 -2
- package/src/middleware/manager.ts +10 -10
- package/src/openapi/docs-ui.ts +1097 -61
- package/src/openapi/generator.ts +380 -13
- package/src/types/index.ts +83 -30
- package/src/utils/validation.ts +5 -3
package/src/types/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { StandardJSONSchemaV1, StandardSchemaV1, StandardTypedV1 } from './standard-schema';
|
|
2
2
|
import type { Server } from 'bun';
|
|
3
|
+
import type { CheckpointConfig } from '../checkpoint/types';
|
|
3
4
|
|
|
4
5
|
// Default AuthUser type - users can override this with their own type
|
|
5
6
|
export interface DefaultAuthUser {
|
|
@@ -14,7 +15,6 @@ export interface DefaultAuthUser {
|
|
|
14
15
|
// Users can override any of these types without breaking changes
|
|
15
16
|
export interface VectorTypes {
|
|
16
17
|
auth?: any; // Custom auth user type
|
|
17
|
-
context?: any; // Custom request context (future)
|
|
18
18
|
cache?: any; // Custom cache value type (future)
|
|
19
19
|
metadata?: any; // Custom metadata type (future)
|
|
20
20
|
}
|
|
@@ -22,7 +22,6 @@ export interface VectorTypes {
|
|
|
22
22
|
// Default types
|
|
23
23
|
export interface DefaultVectorTypes extends VectorTypes {
|
|
24
24
|
auth: DefaultAuthUser;
|
|
25
|
-
context: Record<string, any>;
|
|
26
25
|
cache: any;
|
|
27
26
|
metadata: Record<string, any>;
|
|
28
27
|
}
|
|
@@ -30,8 +29,6 @@ export interface DefaultVectorTypes extends VectorTypes {
|
|
|
30
29
|
// Type helpers
|
|
31
30
|
export type GetAuthType<T extends VectorTypes> = T['auth'] extends undefined ? DefaultAuthUser : T['auth'];
|
|
32
31
|
|
|
33
|
-
export type GetContextType<T extends VectorTypes> = T['context'] extends undefined ? Record<string, any> : T['context'];
|
|
34
|
-
|
|
35
32
|
export type GetCacheType<T extends VectorTypes> = T['cache'] extends undefined ? any : T['cache'];
|
|
36
33
|
|
|
37
34
|
export type GetMetadataType<T extends VectorTypes> = T['metadata'] extends undefined
|
|
@@ -41,11 +38,7 @@ export type GetMetadataType<T extends VectorTypes> = T['metadata'] extends undef
|
|
|
41
38
|
// Legacy support - keep AuthUser for backward compatibility
|
|
42
39
|
export type AuthUser = DefaultAuthUser;
|
|
43
40
|
|
|
44
|
-
type
|
|
45
|
-
type DefaultParamsShape = Record<string, string>;
|
|
46
|
-
type DefaultCookiesShape = Record<string, string>;
|
|
47
|
-
|
|
48
|
-
type BaseVectorRequest = Omit<Request, 'body' | 'json' | 'text' | 'formData' | 'arrayBuffer' | 'blob'>;
|
|
41
|
+
type BaseVectorRequest = Request;
|
|
49
42
|
|
|
50
43
|
type InferValidatedSection<TValidatedInput, TKey extends string, TFallback> = [TValidatedInput] extends [undefined]
|
|
51
44
|
? TFallback
|
|
@@ -56,27 +49,35 @@ type InferValidatedSection<TValidatedInput, TKey extends string, TFallback> = [T
|
|
|
56
49
|
: TFallback;
|
|
57
50
|
|
|
58
51
|
type InferValidatedInputValue<TValidatedInput> = [TValidatedInput] extends [undefined] ? unknown : TValidatedInput;
|
|
52
|
+
type ValidatedInputField<TValidatedInput> = [TValidatedInput] extends [undefined]
|
|
53
|
+
? { validatedInput?: InferValidatedInputValue<TValidatedInput> }
|
|
54
|
+
: { validatedInput: InferValidatedInputValue<TValidatedInput> };
|
|
59
55
|
|
|
60
56
|
export type BunRouteHandler = (req: Request) => Response | Promise<Response>;
|
|
61
57
|
export type BunMethodMap = Record<string, BunRouteHandler>;
|
|
62
58
|
export type BunRouteTable = Record<string, BunMethodMap | Response>;
|
|
63
59
|
export type LegacyRouteEntry = [string, RegExp, [BunRouteHandler, ...BunRouteHandler[]], string?];
|
|
64
60
|
|
|
65
|
-
|
|
66
|
-
|
|
61
|
+
type VectorRequestTypeBrand<TTypes extends VectorTypes, TValidatedInput> = {
|
|
62
|
+
readonly __vectorTypesBrand__?: TTypes;
|
|
63
|
+
readonly __validatedInputBrand__?: TValidatedInput;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export type VectorRequest<
|
|
67
|
+
TTypes extends VectorTypes = DefaultVectorTypes,
|
|
68
|
+
TValidatedInput = undefined,
|
|
69
|
+
> = BaseVectorRequest & VectorRequestTypeBrand<TTypes, TValidatedInput>;
|
|
70
|
+
|
|
71
|
+
export type VectorContext<TTypes extends VectorTypes = DefaultVectorTypes, TValidatedInput = undefined> = {
|
|
72
|
+
request: VectorRequest<TTypes, TValidatedInput>;
|
|
67
73
|
authUser?: GetAuthType<TTypes>;
|
|
68
|
-
|
|
69
|
-
|
|
74
|
+
metadata: GetMetadataType<TTypes>;
|
|
75
|
+
params: InferValidatedSection<TValidatedInput, 'params', Record<string, string>>;
|
|
76
|
+
query: InferValidatedSection<TValidatedInput, 'query', Record<string, string | string[]>>;
|
|
77
|
+
cookies: InferValidatedSection<TValidatedInput, 'cookies', Record<string, string>>;
|
|
70
78
|
content?: InferValidatedSection<TValidatedInput, 'body', any>;
|
|
71
|
-
body?: InferValidatedSection<TValidatedInput, 'body', any>;
|
|
72
|
-
params?: InferValidatedSection<TValidatedInput, 'params', DefaultParamsShape>;
|
|
73
|
-
query: InferValidatedSection<TValidatedInput, 'query', DefaultQueryShape>;
|
|
74
|
-
headers: Headers;
|
|
75
|
-
cookies?: InferValidatedSection<TValidatedInput, 'cookies', DefaultCookiesShape>;
|
|
76
|
-
validatedInput?: InferValidatedInputValue<TValidatedInput>;
|
|
77
|
-
startTime?: number;
|
|
78
79
|
[key: string]: any;
|
|
79
|
-
}
|
|
80
|
+
} & ValidatedInputField<TValidatedInput>;
|
|
80
81
|
|
|
81
82
|
export interface CacheOptions {
|
|
82
83
|
key?: string;
|
|
@@ -97,6 +98,52 @@ export interface RouteSchemaDefinition<
|
|
|
97
98
|
input?: TInput;
|
|
98
99
|
output?: TOutput;
|
|
99
100
|
tag?: string;
|
|
101
|
+
summary?: string;
|
|
102
|
+
description?: string;
|
|
103
|
+
descrition?: string;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export enum OpenApiSecuritySchemeType {
|
|
107
|
+
ApiKey = 'apiKey',
|
|
108
|
+
Http = 'http',
|
|
109
|
+
MutualTls = 'mutualTLS',
|
|
110
|
+
OAuth2 = 'oauth2',
|
|
111
|
+
OpenIdConnect = 'openIdConnect',
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export enum HttpAuthScheme {
|
|
115
|
+
Basic = 'basic',
|
|
116
|
+
Bearer = 'bearer',
|
|
117
|
+
Digest = 'digest',
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export enum AuthKind {
|
|
121
|
+
ApiKey = 'ApiKey',
|
|
122
|
+
HttpBasic = 'HttpBasic',
|
|
123
|
+
HttpBearer = 'HttpBearer',
|
|
124
|
+
HttpDigest = 'HttpDigest',
|
|
125
|
+
OAuth2 = 'OAuth2',
|
|
126
|
+
OpenIdConnect = 'OpenIdConnect',
|
|
127
|
+
MutualTls = 'MutualTls',
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export type RouteAuthOption = boolean | AuthKind;
|
|
131
|
+
|
|
132
|
+
export interface OpenAPISecurityScheme {
|
|
133
|
+
type: OpenApiSecuritySchemeType | ({} & string);
|
|
134
|
+
description?: string;
|
|
135
|
+
name?: string;
|
|
136
|
+
in?: 'query' | 'header' | 'cookie';
|
|
137
|
+
scheme?: string;
|
|
138
|
+
bearerFormat?: string;
|
|
139
|
+
flows?: Record<string, unknown>;
|
|
140
|
+
openIdConnectUrl?: string;
|
|
141
|
+
[key: string]: unknown;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export interface OpenAPIAuthOptions {
|
|
145
|
+
securitySchemeNames?: Partial<Record<AuthKind, string>>;
|
|
146
|
+
securitySchemes?: Partial<Record<AuthKind, OpenAPISecurityScheme>>;
|
|
100
147
|
}
|
|
101
148
|
|
|
102
149
|
export type InferStandardSchemaInput<TSchema extends StandardRouteSchema> = StandardSchemaV1.InferInput<TSchema>;
|
|
@@ -113,8 +160,9 @@ export type InferRouteInputFromSchemaDefinition<TSchemaDef extends RouteSchemaDe
|
|
|
113
160
|
export interface RouteOptions<TTypes extends VectorTypes = DefaultVectorTypes> {
|
|
114
161
|
method: string;
|
|
115
162
|
path: string;
|
|
116
|
-
auth?:
|
|
163
|
+
auth?: RouteAuthOption;
|
|
117
164
|
expose?: boolean; // defaults to true
|
|
165
|
+
deprecated?: boolean; // OpenAPI operation.deprecated flag
|
|
118
166
|
cache?: CacheOptions | number;
|
|
119
167
|
rawRequest?: boolean;
|
|
120
168
|
validate?: boolean; // defaults to validating schema.input unless false
|
|
@@ -125,7 +173,7 @@ export interface RouteOptions<TTypes extends VectorTypes = DefaultVectorTypes> {
|
|
|
125
173
|
}
|
|
126
174
|
|
|
127
175
|
export interface RouteBooleanDefaults {
|
|
128
|
-
auth?:
|
|
176
|
+
auth?: RouteAuthOption;
|
|
129
177
|
expose?: boolean;
|
|
130
178
|
rawRequest?: boolean;
|
|
131
179
|
validate?: boolean;
|
|
@@ -138,7 +186,7 @@ export interface VectorDefaults {
|
|
|
138
186
|
|
|
139
187
|
// Legacy config interface - will be deprecated
|
|
140
188
|
export interface VectorConfig<TTypes extends VectorTypes = DefaultVectorTypes> {
|
|
141
|
-
port?: number;
|
|
189
|
+
port?: number | string;
|
|
142
190
|
hostname?: string;
|
|
143
191
|
reusePort?: boolean;
|
|
144
192
|
development?: boolean;
|
|
@@ -153,6 +201,7 @@ export interface VectorConfig<TTypes extends VectorTypes = DefaultVectorTypes> {
|
|
|
153
201
|
openapi?: OpenAPIOptions | boolean;
|
|
154
202
|
startup?: StartupHandler;
|
|
155
203
|
shutdown?: ShutdownHandler;
|
|
204
|
+
checkpoint?: CheckpointConfig;
|
|
156
205
|
}
|
|
157
206
|
|
|
158
207
|
export interface StartVectorContext {
|
|
@@ -181,7 +230,7 @@ export interface StartedVectorApp<TTypes extends VectorTypes = DefaultVectorType
|
|
|
181
230
|
// New config-driven schema - flat structure
|
|
182
231
|
export interface VectorConfigSchema<TTypes extends VectorTypes = DefaultVectorTypes> {
|
|
183
232
|
// Server configuration
|
|
184
|
-
port?: number;
|
|
233
|
+
port?: number | string;
|
|
185
234
|
hostname?: string;
|
|
186
235
|
reusePort?: boolean;
|
|
187
236
|
development?: boolean;
|
|
@@ -208,6 +257,9 @@ export interface VectorConfigSchema<TTypes extends VectorTypes = DefaultVectorTy
|
|
|
208
257
|
startup?: StartupHandler;
|
|
209
258
|
shutdown?: ShutdownHandler;
|
|
210
259
|
|
|
260
|
+
// Checkpoints
|
|
261
|
+
checkpoint?: CheckpointConfig;
|
|
262
|
+
|
|
211
263
|
// Custom types for TypeScript
|
|
212
264
|
types?: VectorTypes;
|
|
213
265
|
}
|
|
@@ -239,15 +291,16 @@ export interface OpenAPIOptions {
|
|
|
239
291
|
target?: 'openapi-3.0' | 'draft-2020-12' | 'draft-07' | ({} & string);
|
|
240
292
|
docs?: boolean | OpenAPIDocsOptions;
|
|
241
293
|
info?: OpenAPIInfoOptions;
|
|
294
|
+
auth?: OpenAPIAuthOptions;
|
|
242
295
|
}
|
|
243
296
|
|
|
244
297
|
export type BeforeMiddlewareHandler<TTypes extends VectorTypes = DefaultVectorTypes> = (
|
|
245
|
-
|
|
246
|
-
) => Promise<
|
|
298
|
+
context: VectorContext<TTypes>
|
|
299
|
+
) => Promise<void | Response> | void | Response;
|
|
247
300
|
|
|
248
301
|
export type AfterMiddlewareHandler<TTypes extends VectorTypes = DefaultVectorTypes> = (
|
|
249
302
|
response: Response,
|
|
250
|
-
|
|
303
|
+
context: VectorContext<TTypes>
|
|
251
304
|
) => Promise<Response> | Response;
|
|
252
305
|
export type MiddlewareHandler = BeforeMiddlewareHandler | AfterMiddlewareHandler;
|
|
253
306
|
|
|
@@ -255,11 +308,11 @@ export type StartupHandler = () => Promise<void> | void;
|
|
|
255
308
|
export type ShutdownHandler = () => Promise<void> | void;
|
|
256
309
|
|
|
257
310
|
export type RouteHandler<TTypes extends VectorTypes = DefaultVectorTypes, TValidatedInput = undefined> = (
|
|
258
|
-
|
|
311
|
+
context: VectorContext<TTypes, TValidatedInput>
|
|
259
312
|
) => Promise<any> | any;
|
|
260
313
|
|
|
261
314
|
export type ProtectedHandler<TTypes extends VectorTypes = DefaultVectorTypes> = (
|
|
262
|
-
|
|
315
|
+
context: VectorContext<TTypes>
|
|
263
316
|
) => Promise<GetAuthType<TTypes>> | GetAuthType<TTypes>;
|
|
264
317
|
|
|
265
318
|
export type CacheHandler = (key: string, factory: () => Promise<any>, ttl: number) => Promise<any>;
|
package/src/utils/validation.ts
CHANGED
|
@@ -20,16 +20,18 @@ export function validateConfig(config: VectorConfig): VectorConfig {
|
|
|
20
20
|
return validatedConfig;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
function validatePort(port?: number): number {
|
|
23
|
+
function validatePort(port?: number | string): number {
|
|
24
24
|
if (port === undefined) {
|
|
25
25
|
return DEFAULT_CONFIG.PORT;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
const normalizedPort = Number(port);
|
|
29
|
+
|
|
30
|
+
if (!Number.isInteger(normalizedPort) || normalizedPort < 1 || normalizedPort > 65535) {
|
|
29
31
|
throw new Error(`Invalid port: ${port}. Port must be between 1 and 65535.`);
|
|
30
32
|
}
|
|
31
33
|
|
|
32
|
-
return
|
|
34
|
+
return normalizedPort;
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
function validateCorsOptions(cors: CorsOptions | boolean): CorsOptions | undefined {
|