webspresso 0.0.105 → 0.0.107
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/.agents/AGENTS.md +15 -2
- package/.agents/CLI.md +219 -7
- package/.agents/FLAGS.md +118 -0
- package/.agents/LOGGING.md +93 -0
- package/.agents/METRICS.md +127 -0
- package/.agents/MIGRATION_JOBS.md +95 -0
- package/.agents/PLUGINS.md +10 -3
- package/.agents/QUEUE.md +42 -0
- package/.agents/RATE_LIMIT.md +147 -0
- package/.agents/SCALE_OUT.md +109 -0
- package/.agents/SECRETS.md +117 -0
- package/AGENTS.md +10 -0
- package/bin/commands/add-aws.js +396 -0
- package/bin/commands/add-ci.js +523 -0
- package/bin/commands/add-cloudflare.js +240 -0
- package/bin/commands/add-cloudrun.js +381 -0
- package/bin/commands/add-migration-job.js +396 -0
- package/bin/commands/assets-sync.js +209 -0
- package/bin/commands/client-generate.js +52 -0
- package/bin/commands/console.js +53 -0
- package/bin/commands/db-migrate.js +47 -2
- package/bin/commands/db-studio.js +84 -0
- package/bin/commands/deploy-check.js +242 -13
- package/bin/commands/export.js +87 -0
- package/bin/commands/secrets-pull.js +208 -0
- package/bin/utils/db.js +7 -1
- package/bin/webspresso.js +39 -7
- package/core/app.js +453 -0
- package/core/auth/authenticate.js +93 -0
- package/core/auth/index.js +38 -5
- package/core/auth/jwt.js +85 -13
- package/core/auth/magic-link.js +23 -5
- package/core/auth/manager.js +57 -6
- package/core/auth/middleware.js +16 -68
- package/core/auth/redis-session.js +1045 -0
- package/core/auth/session-manager.js +28 -2
- package/core/auth/sessions.js +308 -22
- package/core/cache/cdn.js +296 -0
- package/core/cache/index.js +12 -0
- package/core/cache/tagged-lru.js +9 -1
- package/core/console/commands.js +148 -0
- package/core/console/context.js +260 -0
- package/core/console/eval.js +73 -0
- package/core/console/index.js +22 -0
- package/core/console/repl.js +102 -0
- package/core/content/service.js +1 -0
- package/core/errors/domain.js +20 -1
- package/core/errors/http.js +1 -0
- package/core/events/dispatcher.js +7 -0
- package/core/events/signal.js +7 -0
- package/core/export/discovery.js +191 -0
- package/core/export/exporter.js +277 -0
- package/core/export/index.js +24 -0
- package/core/flags/evaluator.js +252 -0
- package/core/flags/hasher.js +37 -0
- package/core/flags/index.js +21 -0
- package/core/flags/manager.js +263 -0
- package/core/flags/store.js +126 -0
- package/core/health/middleware.js +3 -3
- package/core/http/adapter.js +74 -0
- package/core/http/express-adapter.js +46 -0
- package/core/http/hono-adapter.js +531 -0
- package/core/http/index.js +41 -0
- package/core/http/pipeline.js +519 -0
- package/core/index.js +347 -0
- package/core/limits/middleware.js +9 -1
- package/core/logger/formatters.js +264 -0
- package/core/logger/index.js +260 -0
- package/core/logger/trace.js +137 -0
- package/core/mail/mailer.js +1 -1
- package/core/metrics/collectors.js +125 -0
- package/core/metrics/index.js +45 -0
- package/core/metrics/middleware.js +230 -0
- package/core/metrics/registry.js +366 -0
- package/core/orm/d1.js +265 -0
- package/core/orm/eager-loader.js +81 -1
- package/core/orm/index.js +122 -8
- package/core/orm/json-fields.js +44 -13
- package/core/orm/migrate-cloud.js +194 -0
- package/core/orm/model.js +12 -0
- package/core/orm/pool.js +97 -0
- package/core/orm/query-builder.js +42 -15
- package/core/orm/repository.js +59 -12
- package/core/orm/scopes.js +54 -4
- package/core/queue/adapters/cloudflare.js +131 -0
- package/core/queue/adapters/pubsub.js +400 -0
- package/core/queue/adapters/sqs.js +419 -0
- package/core/queue/adapters/wait-until.js +77 -0
- package/core/queue/index.js +8 -0
- package/core/queue/manager.js +11 -0
- package/core/rate-limit/index.js +22 -0
- package/core/rate-limit/limiter.js +219 -0
- package/core/rate-limit/stores/memory.js +129 -0
- package/core/rate-limit/stores/redis.js +151 -0
- package/core/rate-limit/utils.js +112 -0
- package/core/resilience/circuit-breaker.js +31 -0
- package/core/secrets/index.js +113 -0
- package/core/secrets/manager.js +308 -0
- package/core/secrets/providers/aws.js +288 -0
- package/core/secrets/providers/env.js +44 -0
- package/core/secrets/providers/gcp.js +307 -0
- package/core/secrets/providers/memory.js +76 -0
- package/core/services/index.js +9 -0
- package/core/shutdown/shutdown-manager.js +66 -38
- package/core/stream/index.js +19 -0
- package/core/stream/text-stream.js +326 -0
- package/core/studio/index.js +43 -0
- package/core/studio/inspector.js +266 -0
- package/core/studio/server.js +341 -0
- package/core/studio/ui.js +681 -0
- package/core/utils/string.js +77 -16
- package/core/validation/index.js +18 -0
- package/index.d.ts +1106 -10
- package/index.js +129 -3
- package/package.json +20 -8
- package/plugins/admin-panel/client/parts/07-model-list.js +5 -2
- package/plugins/admin-panel/index.js +36 -16
- package/plugins/admin-panel/modules/user-management.js +3 -2
- package/plugins/api-key/index.js +3 -2
- package/plugins/audit-log/index.js +3 -1
- package/plugins/basic-auth/index.js +3 -2
- package/plugins/cors.js +3 -2
- package/plugins/csrf/index.js +6 -4
- package/plugins/csv/index.js +8 -5
- package/plugins/dashboard/index.js +27 -7
- package/plugins/email/index.js +11 -9
- package/plugins/index.js +3 -0
- package/plugins/queue/index.js +18 -2
- package/plugins/redirect/index.js +7 -2
- package/plugins/seo-checker/index.js +2 -2
- package/plugins/site-analytics/index.js +3 -1
- package/plugins/swagger.js +8 -2
- package/plugins/upload/gcs-provider.js +148 -0
- package/plugins/upload/index.js +132 -74
- package/plugins/upload/s3-provider.js +257 -0
- package/plugins/webhooks/index.js +27 -23
- package/plugins/xlsx/index.js +7 -5
- package/src/api/api-loader.js +12 -95
- package/src/api/define-api.js +1 -0
- package/src/app-context.js +9 -1
- package/src/client-runtime/constants.js +10 -0
- package/src/client-runtime/mount.js +2 -3
- package/src/dev/client-gen.js +458 -0
- package/src/discovery/scan-routes.js +5 -2
- package/src/file-router.js +14 -3
- package/src/helpers.js +53 -0
- package/src/pages/page-loader.js +12 -205
- package/src/plugin-manager.js +280 -47
- package/src/server.js +253 -169
- package/src/services/discovery.js +9 -1
- package/src/services/executor.js +271 -49
- package/src/services/index.js +52 -3
- package/src/services/loader.js +120 -0
- package/src/services/memoize.js +223 -49
- package/src/services/registry.js +501 -95
- package/src/services/validator.js +202 -33
package/index.d.ts
CHANGED
|
@@ -24,10 +24,12 @@ export interface ErrorPageContext {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
export interface CreateAppOptions {
|
|
27
|
+
core?: CoreApp;
|
|
27
28
|
pagesDir: string;
|
|
28
29
|
viewsDir?: string;
|
|
29
30
|
publicDir?: string;
|
|
30
31
|
logging?: boolean;
|
|
32
|
+
logger?: boolean | CloudLogger | LoggerOptions;
|
|
31
33
|
helmet?: boolean | Record<string, unknown>;
|
|
32
34
|
middlewares?: Record<string, WebspressoRegisteredMiddleware>;
|
|
33
35
|
plugins?: WebspressoPlugin[];
|
|
@@ -82,6 +84,8 @@ export interface CreateAppOptions {
|
|
|
82
84
|
limits?: string | number | PayloadLimitsConfig;
|
|
83
85
|
/** Cloud & Kubernetes Health check probes (/healthz & /readyz) */
|
|
84
86
|
healthCheck?: boolean | string | HealthCheckConfig;
|
|
87
|
+
/** Cloud Metrics & Distributed Tracing (/metrics) */
|
|
88
|
+
metrics?: boolean | MetricsConfig;
|
|
85
89
|
/** High-Performance In-Memory LRU & Tagged Cache options */
|
|
86
90
|
cache?: boolean | LruCacheConfig;
|
|
87
91
|
/** Shutdown and lifecycle configuration */
|
|
@@ -112,6 +116,7 @@ export interface CreateAppOptions {
|
|
|
112
116
|
earlyHints?: boolean | (string | EarlyHintLink)[] | EarlyHintsOptions;
|
|
113
117
|
limits?: string | number | PayloadLimitsConfig;
|
|
114
118
|
healthCheck?: boolean | string | HealthCheckConfig;
|
|
119
|
+
metrics?: boolean | MetricsConfig;
|
|
115
120
|
cache?: boolean | LruCacheConfig;
|
|
116
121
|
trustProxy?: boolean | number | string;
|
|
117
122
|
[key: string]: unknown;
|
|
@@ -213,8 +218,14 @@ export interface ServiceContext {
|
|
|
213
218
|
t?: unknown;
|
|
214
219
|
service?: {
|
|
215
220
|
<T = unknown>(name: string, input?: unknown, options?: unknown): Promise<T>;
|
|
221
|
+
call?: <T = unknown>(name: string, input?: unknown, options?: unknown) => Promise<T>;
|
|
222
|
+
execute?: <T = unknown>(name: string, input?: unknown, options?: unknown) => Promise<T>;
|
|
216
223
|
invalidate?: (name: string, input?: unknown, ctx?: unknown) => boolean;
|
|
217
224
|
clearCache?: (name?: string) => boolean;
|
|
225
|
+
invalidateByTag?: (tag: string, serviceName?: string) => number | Promise<number>;
|
|
226
|
+
invalidateByTags?: (tags: string | string[], serviceName?: string) => number | Promise<number>;
|
|
227
|
+
invalidateTag?: (tag: string, serviceName?: string) => number | Promise<number>;
|
|
228
|
+
invalidateTags?: (tags: string | string[], serviceName?: string) => number | Promise<number>;
|
|
218
229
|
};
|
|
219
230
|
breaker?: (name: string, options?: CircuitBreakerOptions) => CircuitBreaker;
|
|
220
231
|
retry?: typeof retry;
|
|
@@ -226,6 +237,43 @@ export type ServiceHandler<TInput = unknown, TOutput = unknown> = (
|
|
|
226
237
|
ctx: ServiceContext
|
|
227
238
|
) => Promise<TOutput> | TOutput;
|
|
228
239
|
|
|
240
|
+
export interface ServiceMiddlewareContext<TInput = unknown> {
|
|
241
|
+
name: string;
|
|
242
|
+
input: TInput;
|
|
243
|
+
ctx: ServiceContext;
|
|
244
|
+
serviceDef: ServiceDefinition<TInput, any>;
|
|
245
|
+
options: unknown;
|
|
246
|
+
registry: ServiceRegistry;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export interface ServiceBeforeContext<TInput = unknown> {
|
|
250
|
+
name: string;
|
|
251
|
+
input: TInput;
|
|
252
|
+
ctx: ServiceContext;
|
|
253
|
+
serviceDef: ServiceDefinition<TInput, any>;
|
|
254
|
+
options: unknown;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export interface ServiceAfterContext<TInput = unknown, TOutput = unknown> {
|
|
258
|
+
name: string;
|
|
259
|
+
result: TOutput;
|
|
260
|
+
input: TInput;
|
|
261
|
+
ctx: ServiceContext;
|
|
262
|
+
serviceDef: ServiceDefinition<TInput, TOutput>;
|
|
263
|
+
duration: number;
|
|
264
|
+
options: unknown;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export interface ServiceErrorContext<TInput = unknown> {
|
|
268
|
+
name: string;
|
|
269
|
+
error: Error;
|
|
270
|
+
input: TInput;
|
|
271
|
+
ctx: ServiceContext;
|
|
272
|
+
serviceDef: ServiceDefinition<TInput, any>;
|
|
273
|
+
duration: number;
|
|
274
|
+
options: unknown;
|
|
275
|
+
}
|
|
276
|
+
|
|
229
277
|
export interface ServiceDefinition<TInput = unknown, TOutput = unknown> {
|
|
230
278
|
schema?: import('zod').ZodType<any> | Record<string, unknown> | ((input: unknown) => unknown) | null;
|
|
231
279
|
handler: ServiceHandler<TInput, TOutput>;
|
|
@@ -243,21 +291,66 @@ export interface ServiceDefinition<TInput = unknown, TOutput = unknown> {
|
|
|
243
291
|
transaction?: boolean;
|
|
244
292
|
circuitBreaker?: boolean | string | CircuitBreakerOptions | CircuitBreaker;
|
|
245
293
|
retry?: boolean | number | RetryOptions;
|
|
294
|
+
before?: ((input: TInput, ctx: ServiceContext) => unknown) | Array<(input: TInput, ctx: ServiceContext) => unknown>;
|
|
295
|
+
after?: ((result: TOutput, input: TInput, ctx: ServiceContext) => unknown) | Array<(result: TOutput, input: TInput, ctx: ServiceContext) => unknown>;
|
|
296
|
+
onError?: ((error: Error, input: TInput, ctx: ServiceContext) => unknown) | Array<(error: Error, input: TInput, ctx: ServiceContext) => unknown>;
|
|
297
|
+
middleware?: ((context: ServiceMiddlewareContext<TInput>, next: () => Promise<unknown>) => Promise<unknown>) | Array<(context: ServiceMiddlewareContext<TInput>, next: () => Promise<unknown>) => Promise<unknown>>;
|
|
246
298
|
[key: string]: unknown;
|
|
247
299
|
}
|
|
248
300
|
|
|
249
301
|
export class ServiceRegistry {
|
|
250
|
-
constructor(options?: {
|
|
302
|
+
constructor(options?: {
|
|
303
|
+
servicesDir?: string;
|
|
304
|
+
isDev?: boolean;
|
|
305
|
+
logger?: unknown;
|
|
306
|
+
timeouts?: unknown;
|
|
307
|
+
timeout?: number | string;
|
|
308
|
+
lazy?: boolean;
|
|
309
|
+
middlewares?: Array<(context: ServiceMiddlewareContext, next: () => Promise<unknown>) => Promise<unknown>>;
|
|
310
|
+
middleware?: (context: ServiceMiddlewareContext, next: () => Promise<unknown>) => Promise<unknown>;
|
|
311
|
+
before?: Array<(context: ServiceBeforeContext) => unknown> | ((context: ServiceBeforeContext) => unknown);
|
|
312
|
+
after?: Array<(context: ServiceAfterContext) => unknown> | ((context: ServiceAfterContext) => unknown);
|
|
313
|
+
onError?: Array<(context: ServiceErrorContext) => unknown> | ((context: ServiceErrorContext) => unknown);
|
|
314
|
+
events?: unknown;
|
|
315
|
+
cacheProvider?: unknown;
|
|
316
|
+
cache?: unknown;
|
|
317
|
+
});
|
|
251
318
|
readonly services: Map<string, ServiceDefinition>;
|
|
319
|
+
readonly lazyServices: Map<string, unknown>;
|
|
320
|
+
readonly aliases: Map<string, string>;
|
|
321
|
+
readonly middlewares: Array<(context: ServiceMiddlewareContext, next: () => Promise<unknown>) => Promise<unknown>>;
|
|
322
|
+
readonly beforeHooks: Array<(context: ServiceBeforeContext) => unknown>;
|
|
323
|
+
readonly afterHooks: Array<(context: ServiceAfterContext) => unknown>;
|
|
324
|
+
readonly onErrorHooks: Array<(context: ServiceErrorContext) => unknown>;
|
|
252
325
|
load(): this;
|
|
253
|
-
|
|
326
|
+
loadAsync(): Promise<this>;
|
|
327
|
+
register(name: string, definition: ServiceDefinition | ServiceHandler, options?: { overwrite?: boolean; aliases?: string[] }): this;
|
|
328
|
+
registerLazy(
|
|
329
|
+
name: string,
|
|
330
|
+
loader: (() => Promise<unknown> | unknown) | string,
|
|
331
|
+
options?: { overwrite?: boolean; aliases?: string[]; filePath?: string }
|
|
332
|
+
): this;
|
|
333
|
+
use(middleware: (context: ServiceMiddlewareContext, next: () => Promise<unknown>) => Promise<unknown>): this;
|
|
334
|
+
before(hook: (context: ServiceBeforeContext) => unknown): this;
|
|
335
|
+
after(hook: (context: ServiceAfterContext) => unknown): this;
|
|
336
|
+
onError(hook: (context: ServiceErrorContext) => unknown): this;
|
|
337
|
+
setEventDispatcher(events: unknown): this;
|
|
254
338
|
get(name: string): ServiceDefinition | undefined;
|
|
339
|
+
getAsync(name: string): Promise<ServiceDefinition | undefined>;
|
|
255
340
|
has(name: string): boolean;
|
|
256
341
|
list(): string[];
|
|
342
|
+
unregister(name: string): boolean;
|
|
257
343
|
invalidate(name: string, input?: unknown, ctx?: unknown): boolean;
|
|
258
344
|
clearCache(name?: string): boolean;
|
|
345
|
+
clearAllCaches(): boolean;
|
|
346
|
+
invalidateByTag(tag: string, serviceName?: string): number | Promise<number>;
|
|
347
|
+
invalidateByTags(tags: string | string[], serviceName?: string): number | Promise<number>;
|
|
348
|
+
invalidateTag?(tag: string, serviceName?: string): number | Promise<number>;
|
|
349
|
+
invalidateTags?(tags: string | string[], serviceName?: string): number | Promise<number>;
|
|
259
350
|
call<T = unknown>(name: string, input?: unknown, ctx?: unknown, options?: unknown): Promise<T>;
|
|
351
|
+
execute<T = unknown>(name: string, input?: unknown, ctx?: unknown, options?: unknown): Promise<T>;
|
|
260
352
|
reload(): this;
|
|
353
|
+
reloadAsync(): Promise<this>;
|
|
261
354
|
}
|
|
262
355
|
|
|
263
356
|
export function createServiceRegistry(options?: {
|
|
@@ -265,8 +358,42 @@ export function createServiceRegistry(options?: {
|
|
|
265
358
|
isDev?: boolean;
|
|
266
359
|
logger?: unknown;
|
|
267
360
|
autoLoad?: boolean;
|
|
361
|
+
lazy?: boolean;
|
|
362
|
+
timeouts?: unknown;
|
|
363
|
+
timeout?: number | string;
|
|
364
|
+
middlewares?: Array<(context: ServiceMiddlewareContext, next: () => Promise<unknown>) => Promise<unknown>>;
|
|
365
|
+
middleware?: (context: ServiceMiddlewareContext, next: () => Promise<unknown>) => Promise<unknown>;
|
|
366
|
+
before?: Array<(context: ServiceBeforeContext) => unknown> | ((context: ServiceBeforeContext) => unknown);
|
|
367
|
+
after?: Array<(context: ServiceAfterContext) => unknown> | ((context: ServiceAfterContext) => unknown);
|
|
368
|
+
onError?: Array<(context: ServiceErrorContext) => unknown> | ((context: ServiceErrorContext) => unknown);
|
|
369
|
+
events?: unknown;
|
|
370
|
+
cacheProvider?: unknown;
|
|
371
|
+
cache?: unknown;
|
|
268
372
|
}): ServiceRegistry;
|
|
269
373
|
|
|
374
|
+
export function createServiceRegistryAsync(options?: {
|
|
375
|
+
servicesDir?: string;
|
|
376
|
+
isDev?: boolean;
|
|
377
|
+
logger?: unknown;
|
|
378
|
+
autoLoad?: boolean;
|
|
379
|
+
lazy?: boolean;
|
|
380
|
+
timeouts?: unknown;
|
|
381
|
+
timeout?: number | string;
|
|
382
|
+
middlewares?: Array<(context: ServiceMiddlewareContext, next: () => Promise<unknown>) => Promise<unknown>>;
|
|
383
|
+
middleware?: (context: ServiceMiddlewareContext, next: () => Promise<unknown>) => Promise<unknown>;
|
|
384
|
+
before?: Array<(context: ServiceBeforeContext) => unknown> | ((context: ServiceBeforeContext) => unknown);
|
|
385
|
+
after?: Array<(context: ServiceAfterContext) => unknown> | ((context: ServiceAfterContext) => unknown);
|
|
386
|
+
onError?: Array<(context: ServiceErrorContext) => unknown> | ((context: ServiceErrorContext) => unknown);
|
|
387
|
+
events?: unknown;
|
|
388
|
+
cacheProvider?: unknown;
|
|
389
|
+
cache?: unknown;
|
|
390
|
+
}): Promise<ServiceRegistry>;
|
|
391
|
+
|
|
392
|
+
export function composeMiddleware(middlewares: Function[]): (context: unknown, next?: Function) => Promise<unknown>;
|
|
393
|
+
export function loadModuleSync(filePath: string, options?: { isDev?: boolean }): unknown;
|
|
394
|
+
export function loadModuleAsync(filePath: string, options?: { isDev?: boolean }): Promise<unknown>;
|
|
395
|
+
export function extractModuleExport(mod: unknown): unknown;
|
|
396
|
+
|
|
270
397
|
export type InferServiceInput<T> = T extends ServiceDefinition<infer TInput, any>
|
|
271
398
|
? TInput
|
|
272
399
|
: T extends { schema: import('zod').ZodType<infer TInput> }
|
|
@@ -292,15 +419,22 @@ export const service: typeof defineService;
|
|
|
292
419
|
export interface MemoizeOptions {
|
|
293
420
|
ttl?: string | number | boolean;
|
|
294
421
|
maxSize?: number;
|
|
422
|
+
clone?: boolean;
|
|
295
423
|
key?: (input: unknown, ctx?: unknown) => string;
|
|
424
|
+
tags?: string | string[] | ((input: unknown, ctx?: unknown) => string | string[]);
|
|
425
|
+
provider?: unknown;
|
|
296
426
|
}
|
|
297
427
|
|
|
298
428
|
export interface MemoizedFunction<TArgs extends unknown[], TReturn> {
|
|
299
429
|
(...args: TArgs): Promise<TReturn>;
|
|
300
|
-
invalidate(...args: TArgs): boolean
|
|
301
|
-
delete(...args: TArgs): boolean
|
|
302
|
-
|
|
303
|
-
|
|
430
|
+
invalidate(...args: TArgs): boolean | Promise<boolean>;
|
|
431
|
+
delete(...args: TArgs): boolean | Promise<boolean>;
|
|
432
|
+
invalidateByTag(tag: string): number | Promise<number>;
|
|
433
|
+
invalidateByTags(tags: string | string[]): number | Promise<number>;
|
|
434
|
+
invalidateTag?(tag: string): number | Promise<number>;
|
|
435
|
+
invalidateTags?(tags: string | string[]): number | Promise<number>;
|
|
436
|
+
clear(): void | Promise<void>;
|
|
437
|
+
has(...args: TArgs): boolean | Promise<boolean>;
|
|
304
438
|
readonly size: number;
|
|
305
439
|
}
|
|
306
440
|
|
|
@@ -358,7 +492,28 @@ export function createExchangeServices(options?: {
|
|
|
358
492
|
db?: unknown;
|
|
359
493
|
}): Record<string, ServiceDefinition>;
|
|
360
494
|
|
|
361
|
-
export function validateServiceInput(
|
|
495
|
+
export function validateServiceInput(
|
|
496
|
+
schema: unknown,
|
|
497
|
+
input: unknown,
|
|
498
|
+
serviceName: string,
|
|
499
|
+
options?: { rejectDangerousKeys?: boolean }
|
|
500
|
+
): unknown;
|
|
501
|
+
|
|
502
|
+
export function createServiceValidationError(
|
|
503
|
+
message: string,
|
|
504
|
+
options?: {
|
|
505
|
+
serviceName: string;
|
|
506
|
+
fields?: Record<string, string>;
|
|
507
|
+
fieldErrors?: Record<string, string[]>;
|
|
508
|
+
details?: unknown[];
|
|
509
|
+
cause?: unknown;
|
|
510
|
+
status?: number;
|
|
511
|
+
}
|
|
512
|
+
): ValidationError;
|
|
513
|
+
|
|
514
|
+
export function normalizeValidationIssues(
|
|
515
|
+
issues: unknown[]
|
|
516
|
+
): Array<{ path: string; message: string; code?: string }>;
|
|
362
517
|
|
|
363
518
|
export function executeService(
|
|
364
519
|
registry: ServiceRegistry,
|
|
@@ -444,15 +599,20 @@ export interface SetupRoutesContext {
|
|
|
444
599
|
pluginManager: PluginManager;
|
|
445
600
|
options: CreateAppOptions;
|
|
446
601
|
clientRuntime: { alpine: boolean; swup: boolean };
|
|
602
|
+
http?: HttpAdapter;
|
|
447
603
|
}
|
|
448
604
|
|
|
449
605
|
export interface WebspressoApplication extends Application {
|
|
606
|
+
core?: CoreApp;
|
|
607
|
+
http?: HttpAdapter;
|
|
450
608
|
server?: unknown;
|
|
451
609
|
readonly isShuttingDown: boolean;
|
|
452
610
|
shutdownManager: ShutdownManager;
|
|
453
611
|
serviceRegistry: ServiceRegistry;
|
|
454
612
|
breakers?: CircuitBreakerRegistry;
|
|
613
|
+
metrics?: MetricsRegistry;
|
|
455
614
|
getBreaker?(name: string, options?: CircuitBreakerOptions): CircuitBreaker;
|
|
615
|
+
service<T = unknown>(name: string, input?: unknown, options?: unknown): Promise<T>;
|
|
456
616
|
onShutdown(fn: () => Promise<void> | void): this;
|
|
457
617
|
close(reason?: string): Promise<void>;
|
|
458
618
|
enableShutdownHooks(): this;
|
|
@@ -473,6 +633,45 @@ export interface CreateAppResult {
|
|
|
473
633
|
shutdownManager: ShutdownManager;
|
|
474
634
|
}
|
|
475
635
|
|
|
636
|
+
export interface CoreAppOptions {
|
|
637
|
+
servicesDir?: string | null;
|
|
638
|
+
moduleServices?: Record<string, unknown>;
|
|
639
|
+
plugins?: WebspressoPlugin[];
|
|
640
|
+
http?: HttpAdapter | null;
|
|
641
|
+
db?: unknown;
|
|
642
|
+
queue?: unknown;
|
|
643
|
+
timeouts?: unknown;
|
|
644
|
+
cache?: unknown;
|
|
645
|
+
server?: unknown;
|
|
646
|
+
[key: string]: unknown;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
export class CoreApp {
|
|
650
|
+
options: CoreAppOptions;
|
|
651
|
+
http?: HttpAdapter | null;
|
|
652
|
+
services: ServiceRegistry;
|
|
653
|
+
serviceRegistry: ServiceRegistry;
|
|
654
|
+
shutdown: ShutdownManager;
|
|
655
|
+
shutdownManager: ShutdownManager;
|
|
656
|
+
breakers: CircuitBreakerRegistry;
|
|
657
|
+
events: EventDispatcher;
|
|
658
|
+
cache: TaggedLruCache | null;
|
|
659
|
+
metrics?: MetricsRegistry | null;
|
|
660
|
+
db: unknown;
|
|
661
|
+
queue: unknown;
|
|
662
|
+
timeouts: unknown;
|
|
663
|
+
plugins: PluginManager;
|
|
664
|
+
pluginManager: PluginManager;
|
|
665
|
+
context: Record<string, unknown>;
|
|
666
|
+
|
|
667
|
+
constructor(options?: CoreAppOptions);
|
|
668
|
+
createContext(extra?: Record<string, unknown>): Record<string, unknown>;
|
|
669
|
+
service<T = unknown>(name: string, input?: unknown, contextOrOptions?: unknown, maybeOptions?: unknown): Promise<T>;
|
|
670
|
+
close(reason?: string): Promise<void>;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
export function createCoreApp(options?: CoreAppOptions): CoreApp;
|
|
674
|
+
|
|
476
675
|
export function createApp(options?: CreateAppOptions): CreateAppResult;
|
|
477
676
|
|
|
478
677
|
export function formatDevBanner(context?: Record<string, unknown>, options?: Record<string, unknown>): { bannerText: string; plainText: string; summary: Record<string, unknown> };
|
|
@@ -480,6 +679,73 @@ export function printDevBanner(context?: Record<string, unknown>, options?: Reco
|
|
|
480
679
|
export function formatRouteTable(routeTable: unknown, options?: Record<string, unknown>): string;
|
|
481
680
|
export function createDevProfilerMiddleware(options?: Record<string, unknown>): RequestHandler;
|
|
482
681
|
|
|
682
|
+
// --- HTTP Layer & Adapters ---
|
|
683
|
+
|
|
684
|
+
export class HttpAdapter {
|
|
685
|
+
app: unknown;
|
|
686
|
+
options: Record<string, unknown>;
|
|
687
|
+
constructor(app?: unknown, options?: Record<string, unknown>);
|
|
688
|
+
use(...args: unknown[]): unknown;
|
|
689
|
+
route(method: string, path: string, ...handlers: unknown[]): unknown;
|
|
690
|
+
get(path: string, ...handlers: unknown[]): unknown;
|
|
691
|
+
post(path: string, ...handlers: unknown[]): unknown;
|
|
692
|
+
put(path: string, ...handlers: unknown[]): unknown;
|
|
693
|
+
delete(path: string, ...handlers: unknown[]): unknown;
|
|
694
|
+
patch(path: string, ...handlers: unknown[]): unknown;
|
|
695
|
+
all(path: string, ...handlers: unknown[]): unknown;
|
|
696
|
+
listen(port: number | string, callback?: () => void): unknown;
|
|
697
|
+
getApp(): unknown;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
export class ExpressHttpAdapter extends HttpAdapter {
|
|
701
|
+
constructor(app: Application, options?: Record<string, unknown>);
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
export function createExpressHttpAdapter(app: Application, options?: Record<string, unknown>): ExpressHttpAdapter;
|
|
705
|
+
|
|
706
|
+
export class HonoHttpAdapter extends HttpAdapter {
|
|
707
|
+
constructor(app?: unknown, options?: Record<string, unknown>);
|
|
708
|
+
registerApi(method: string, path: string, apiDef: unknown, context?: Record<string, unknown>): this;
|
|
709
|
+
registerPage(path: string, pageDef: unknown, context?: Record<string, unknown>): this;
|
|
710
|
+
request(input: string | unknown, init?: unknown): Promise<Response>;
|
|
711
|
+
fetch(request: unknown, env?: unknown, ctx?: unknown): Response | Promise<Response>;
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
export function createHonoHttpAdapter(app?: unknown, options?: Record<string, unknown>): HonoHttpAdapter;
|
|
715
|
+
|
|
716
|
+
export function runMiddlewares(middlewares: unknown[], req: unknown, res: unknown): Promise<void>;
|
|
717
|
+
export function enrichRouteError(err: unknown, descriptor: RouteDescriptor | Record<string, unknown>, req: unknown): unknown;
|
|
718
|
+
export function executeApiPipeline(params: {
|
|
719
|
+
descriptor: RouteDescriptor | Record<string, unknown>;
|
|
720
|
+
context?: Record<string, unknown>;
|
|
721
|
+
apiDef?: unknown;
|
|
722
|
+
handlerFn: Function;
|
|
723
|
+
compiledSchema?: unknown;
|
|
724
|
+
middlewares?: unknown[];
|
|
725
|
+
req: unknown;
|
|
726
|
+
res: unknown;
|
|
727
|
+
}): Promise<unknown>;
|
|
728
|
+
export function executePagePipeline(params: {
|
|
729
|
+
descriptor: RouteDescriptor | Record<string, unknown>;
|
|
730
|
+
context?: Record<string, unknown>;
|
|
731
|
+
pageDef: unknown;
|
|
732
|
+
middlewares?: unknown[];
|
|
733
|
+
req: unknown;
|
|
734
|
+
res: unknown;
|
|
735
|
+
nunjucks?: unknown;
|
|
736
|
+
njkCandidate?: string;
|
|
737
|
+
hasNjkTemplate?: boolean;
|
|
738
|
+
}): Promise<unknown>;
|
|
739
|
+
|
|
740
|
+
// --- Auth & Verification ---
|
|
741
|
+
|
|
742
|
+
export function authenticateRequest(
|
|
743
|
+
req: Request | Record<string, unknown>,
|
|
744
|
+
res?: Response | Record<string, unknown>,
|
|
745
|
+
authManager?: unknown
|
|
746
|
+
): Promise<unknown>;
|
|
747
|
+
|
|
748
|
+
|
|
483
749
|
// --- Exceptions & Errors ---
|
|
484
750
|
|
|
485
751
|
export interface ErrorOptions {
|
|
@@ -534,7 +800,19 @@ export class CircuitBreakerTimeoutError extends GatewayTimeoutError {
|
|
|
534
800
|
|
|
535
801
|
export class ValidationError extends HttpError {
|
|
536
802
|
fields: Record<string, string[] | string>;
|
|
537
|
-
|
|
803
|
+
fieldErrors?: Record<string, string[]>;
|
|
804
|
+
service?: string;
|
|
805
|
+
issues?: unknown[];
|
|
806
|
+
details?: unknown[];
|
|
807
|
+
normalizedIssues?: Array<{ path: string; message: string; code?: string }>;
|
|
808
|
+
constructor(message?: string, options?: ErrorOptions & {
|
|
809
|
+
fields?: Record<string, string[] | string>;
|
|
810
|
+
fieldErrors?: Record<string, string[]>;
|
|
811
|
+
service?: string;
|
|
812
|
+
statusCode?: number;
|
|
813
|
+
issues?: unknown[];
|
|
814
|
+
details?: unknown[];
|
|
815
|
+
});
|
|
538
816
|
}
|
|
539
817
|
|
|
540
818
|
export class ConfigurationError extends WebspressoError { constructor(message: string, options?: ErrorOptions); }
|
|
@@ -759,8 +1037,113 @@ export function createLruCache<V = unknown>(options?: LruCacheConfig): LruCache<
|
|
|
759
1037
|
export function createTaggedLruCache<V = unknown>(options?: LruCacheConfig): TaggedLruCache<V>;
|
|
760
1038
|
export function approximateByteSize(value: unknown): number;
|
|
761
1039
|
|
|
1040
|
+
export interface CdnCacheOptions {
|
|
1041
|
+
maxAge?: number | string;
|
|
1042
|
+
sMaxAge?: number | string;
|
|
1043
|
+
staleWhileRevalidate?: number | string;
|
|
1044
|
+
staleIfError?: number | string;
|
|
1045
|
+
tags?: string[] | string;
|
|
1046
|
+
public?: boolean;
|
|
1047
|
+
private?: boolean;
|
|
1048
|
+
mustRevalidate?: boolean;
|
|
1049
|
+
immutable?: boolean;
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
export function buildCdnCacheHeaders(options?: CdnCacheOptions): Record<string, string>;
|
|
1053
|
+
export function setCdnCache(res: unknown, options?: CdnCacheOptions): void;
|
|
1054
|
+
|
|
1055
|
+
export interface CdnPurgeOptions {
|
|
1056
|
+
provider?: 'cloudflare' | 'fastly' | 'custom' | 'mock';
|
|
1057
|
+
apiToken?: string;
|
|
1058
|
+
zoneId?: string;
|
|
1059
|
+
serviceId?: string;
|
|
1060
|
+
purge?: (params: { tags: string[] }) => Promise<Record<string, unknown>>;
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
export interface CdnPurgeClient {
|
|
1064
|
+
purgeTags(tags: string[] | string): Promise<{ success: boolean; count?: number; error?: string }>;
|
|
1065
|
+
purgeAll(): Promise<{ success: boolean; error?: string }>;
|
|
1066
|
+
purgedHistory: Array<{ type: string; tags?: string[]; timestamp: Date }>;
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
export function createCdnPurgeClient(options?: CdnPurgeOptions): CdnPurgeClient;
|
|
1070
|
+
export function bindOrmCdnPurge(db: unknown, config: { modelTags: Record<string, (record: any) => string[]>; client: CdnPurgeClient }): void;
|
|
1071
|
+
|
|
762
1072
|
export namespace cache {
|
|
763
|
-
export {
|
|
1073
|
+
export {
|
|
1074
|
+
LruCache,
|
|
1075
|
+
TaggedLruCache,
|
|
1076
|
+
createLruCache,
|
|
1077
|
+
createTaggedLruCache,
|
|
1078
|
+
approximateByteSize,
|
|
1079
|
+
buildCdnCacheHeaders,
|
|
1080
|
+
setCdnCache,
|
|
1081
|
+
createCdnPurgeClient,
|
|
1082
|
+
bindOrmCdnPurge,
|
|
1083
|
+
};
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
// --- Cloud Secrets Management (Google Cloud Secret Manager & AWS Secrets Manager) ---
|
|
1087
|
+
|
|
1088
|
+
export interface SecretManagerOptions {
|
|
1089
|
+
provider?: 'auto' | 'gcp' | 'cloudrun' | 'aws' | 'env' | 'memory' | any;
|
|
1090
|
+
cache?: boolean;
|
|
1091
|
+
cacheTtl?: string | number;
|
|
1092
|
+
projectId?: string;
|
|
1093
|
+
region?: string;
|
|
1094
|
+
accessKeyId?: string;
|
|
1095
|
+
secretAccessKey?: string;
|
|
1096
|
+
sessionToken?: string;
|
|
1097
|
+
token?: string;
|
|
1098
|
+
credentials?: Record<string, unknown>;
|
|
1099
|
+
client?: any;
|
|
1100
|
+
mockSecrets?: Record<string, unknown>;
|
|
1101
|
+
secrets?: Record<string, unknown>;
|
|
1102
|
+
httpTransport?: (url: string, options?: any) => Promise<any>;
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
export interface SecretGetOptions {
|
|
1106
|
+
fallback?: any;
|
|
1107
|
+
required?: boolean;
|
|
1108
|
+
parseJson?: boolean;
|
|
1109
|
+
bypassCache?: boolean;
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
export interface SecretLoadOptions {
|
|
1113
|
+
inject?: boolean;
|
|
1114
|
+
override?: boolean;
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
export declare class SecretManager {
|
|
1118
|
+
constructor(options?: SecretManagerOptions);
|
|
1119
|
+
get<T = any>(secretName: string, options?: SecretGetOptions): Promise<T>;
|
|
1120
|
+
invalidate(secretName: string): void;
|
|
1121
|
+
clearCache(): void;
|
|
1122
|
+
load(secretsMapOrArray: Record<string, string> | string[], options?: SecretLoadOptions): Promise<Record<string, string>>;
|
|
1123
|
+
loadBundle(bundleName: string, options?: SecretLoadOptions): Promise<Record<string, any>>;
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
export declare class SecretNotFoundError extends Error {
|
|
1127
|
+
secretName: string;
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
export function createSecretManager(options?: SecretManagerOptions): SecretManager;
|
|
1131
|
+
export function resolveSecret<T = any>(secretName: string, options?: SecretManagerOptions & SecretGetOptions): Promise<T>;
|
|
1132
|
+
export function loadSecrets(options?: SecretManagerOptions & {
|
|
1133
|
+
secrets?: Record<string, string> | string[];
|
|
1134
|
+
bundle?: string;
|
|
1135
|
+
inject?: boolean;
|
|
1136
|
+
override?: boolean;
|
|
1137
|
+
}): Promise<Record<string, any>>;
|
|
1138
|
+
|
|
1139
|
+
export namespace secrets {
|
|
1140
|
+
export {
|
|
1141
|
+
SecretManager,
|
|
1142
|
+
SecretNotFoundError,
|
|
1143
|
+
createSecretManager,
|
|
1144
|
+
resolveSecret,
|
|
1145
|
+
loadSecrets,
|
|
1146
|
+
};
|
|
764
1147
|
}
|
|
765
1148
|
|
|
766
1149
|
// --- Enterprise Resilience & Fault Tolerance (Circuit Breaker & Retry Engine) ---
|
|
@@ -1400,6 +1783,7 @@ export interface RoutesReadyContext {
|
|
|
1400
1783
|
|
|
1401
1784
|
export interface PluginRegisterContext {
|
|
1402
1785
|
app: Application;
|
|
1786
|
+
http?: HttpAdapter;
|
|
1403
1787
|
nunjucksEnv: unknown;
|
|
1404
1788
|
options: Record<string, unknown>;
|
|
1405
1789
|
/** Same object as `createApp({ middlewares })` for registering named route middleware. */
|
|
@@ -1875,6 +2259,7 @@ export interface OrmDatabaseCacheConfig {
|
|
|
1875
2259
|
export interface DatabaseConfig {
|
|
1876
2260
|
client?: string;
|
|
1877
2261
|
connection?: string | Record<string, unknown>;
|
|
2262
|
+
d1?: unknown;
|
|
1878
2263
|
models?: string;
|
|
1879
2264
|
migrations?: MigrationConfig;
|
|
1880
2265
|
pool?: Record<string, unknown>;
|
|
@@ -1984,6 +2369,9 @@ export interface DatabaseInstance {
|
|
|
1984
2369
|
};
|
|
1985
2370
|
transaction<T>(callback: (ctx: TransactionContext) => Promise<T>, scopeContext?: ScopeContext): Promise<T>;
|
|
1986
2371
|
runInTransaction<T>(callback: (ctx: TransactionContext) => Promise<T>, scopeContext?: ScopeContext): Promise<T>;
|
|
2372
|
+
batch<T = any>(
|
|
2373
|
+
queriesOrCallback: Array<any> | ((batch: { add(q: any): any; raw(sql: string, bindings?: any[]): any }) => Promise<any> | any)
|
|
2374
|
+
): Promise<T[]>;
|
|
1987
2375
|
getAmbientTransaction(): Knex.Transaction | null;
|
|
1988
2376
|
hasActiveTransaction(): boolean;
|
|
1989
2377
|
createSeeder(): unknown;
|
|
@@ -1992,6 +2380,85 @@ export interface DatabaseInstance {
|
|
|
1992
2380
|
}
|
|
1993
2381
|
|
|
1994
2382
|
export function createDatabase(config: DatabaseConfig): DatabaseInstance;
|
|
2383
|
+
export function createD1Knex(d1Database: unknown, options?: Record<string, unknown>): Knex;
|
|
2384
|
+
export const Client_D1: unknown;
|
|
2385
|
+
export function executeD1Batch(
|
|
2386
|
+
d1Database: unknown,
|
|
2387
|
+
queriesOrCallback: Array<any> | ((batch: { add(q: any): any; raw(sql: string, bindings?: any[]): any }) => Promise<any> | any)
|
|
2388
|
+
): Promise<Array<any>>;
|
|
2389
|
+
export function normalizeD1Bindings(rawBindings?: any[]): any[];
|
|
2390
|
+
|
|
2391
|
+
export interface ServerlessPoolEnvironment {
|
|
2392
|
+
isServerless: boolean;
|
|
2393
|
+
platform: 'cloudrun' | 'aws-lambda' | 'ecs' | 'serverless' | 'standard';
|
|
2394
|
+
}
|
|
2395
|
+
|
|
2396
|
+
export function isServerlessEnvironment(env?: Record<string, string>): ServerlessPoolEnvironment;
|
|
2397
|
+
export function normalizeServerlessPoolConfig(
|
|
2398
|
+
knexConfig?: any,
|
|
2399
|
+
optionsOrEnv?: Record<string, any>
|
|
2400
|
+
): any;
|
|
2401
|
+
|
|
2402
|
+
// --- Webspresso DB Studio Subsystem ---
|
|
2403
|
+
|
|
2404
|
+
export interface StudioOptions {
|
|
2405
|
+
knex?: Knex;
|
|
2406
|
+
db?: DatabaseInstance;
|
|
2407
|
+
app?: any;
|
|
2408
|
+
queue?: any;
|
|
2409
|
+
port?: number;
|
|
2410
|
+
host?: string;
|
|
2411
|
+
open?: boolean;
|
|
2412
|
+
silent?: boolean;
|
|
2413
|
+
}
|
|
2414
|
+
|
|
2415
|
+
export interface StudioTelemetrySnapshot {
|
|
2416
|
+
timestamp: string;
|
|
2417
|
+
uptimeSeconds: number;
|
|
2418
|
+
nodeVersion: string;
|
|
2419
|
+
pid: number;
|
|
2420
|
+
memory: {
|
|
2421
|
+
rssMb: number;
|
|
2422
|
+
heapUsedMb: number;
|
|
2423
|
+
heapTotalMb: number;
|
|
2424
|
+
externalMb: number;
|
|
2425
|
+
};
|
|
2426
|
+
pool: {
|
|
2427
|
+
client: string;
|
|
2428
|
+
used: number;
|
|
2429
|
+
free: number;
|
|
2430
|
+
pending: number;
|
|
2431
|
+
};
|
|
2432
|
+
breakers: Array<{
|
|
2433
|
+
name: string;
|
|
2434
|
+
state: string;
|
|
2435
|
+
failures: number;
|
|
2436
|
+
successes: number;
|
|
2437
|
+
totalCalls: number;
|
|
2438
|
+
failureRate: number;
|
|
2439
|
+
lastFailureTime: number | null;
|
|
2440
|
+
}>;
|
|
2441
|
+
queue: {
|
|
2442
|
+
enabled: boolean;
|
|
2443
|
+
activeWorkers?: number;
|
|
2444
|
+
concurrency?: number;
|
|
2445
|
+
registeredJobs?: string[];
|
|
2446
|
+
isPaused?: boolean;
|
|
2447
|
+
isRunning?: boolean;
|
|
2448
|
+
waiting?: number;
|
|
2449
|
+
[key: string]: any;
|
|
2450
|
+
};
|
|
2451
|
+
}
|
|
2452
|
+
|
|
2453
|
+
export interface StudioInstance {
|
|
2454
|
+
server: import('http').Server;
|
|
2455
|
+
url: string;
|
|
2456
|
+
close: () => Promise<void>;
|
|
2457
|
+
}
|
|
2458
|
+
|
|
2459
|
+
export function startStudio(options?: StudioOptions): Promise<StudioInstance>;
|
|
2460
|
+
export function createStudioApp(options?: StudioOptions): import('express').Express;
|
|
2461
|
+
export function getTelemetrySnapshot(knex?: Knex, options?: StudioOptions): Promise<StudioTelemetrySnapshot>;
|
|
1995
2462
|
|
|
1996
2463
|
export function runWithAmbientTransaction<T>(trx: Knex.Transaction, callback: () => Promise<T> | T): Promise<T>;
|
|
1997
2464
|
export function getAmbientTransaction(): Knex.Transaction | null;
|
|
@@ -2033,6 +2500,31 @@ export function defineFactory<T = Record<string, any>>(
|
|
|
2033
2500
|
export function diffSchema(options: { knex: Knex; models?: ModelDefinition<any>[]; includeDrops?: boolean }): Promise<{ hasChanges: boolean; changes: Array<any> }>;
|
|
2034
2501
|
export function makeMigrations(options: { knex: Knex; modelsDir?: string; migrationDir?: string; dryRun?: boolean; includeDrops?: boolean; name?: string }): Promise<{ hasChanges: boolean; created: Array<any>; skipped: Array<any> }>;
|
|
2035
2502
|
|
|
2503
|
+
// --- Cloud Database Migrations ---
|
|
2504
|
+
|
|
2505
|
+
export interface CloudMigrationOptions {
|
|
2506
|
+
migrationConfig?: Record<string, unknown>;
|
|
2507
|
+
dryRun?: boolean;
|
|
2508
|
+
unlockIfStale?: boolean;
|
|
2509
|
+
waitForDb?: boolean;
|
|
2510
|
+
retries?: number;
|
|
2511
|
+
logger?: (message: string) => void;
|
|
2512
|
+
}
|
|
2513
|
+
|
|
2514
|
+
export interface CloudMigrationResult {
|
|
2515
|
+
success: boolean;
|
|
2516
|
+
batch: number;
|
|
2517
|
+
applied: string[];
|
|
2518
|
+
pendingBefore: string[];
|
|
2519
|
+
durationMs: number;
|
|
2520
|
+
dryRun: boolean;
|
|
2521
|
+
}
|
|
2522
|
+
|
|
2523
|
+
export function waitForDatabaseConnection(knex: unknown, options?: { retries?: number; initialDelayMs?: number; maxDelayMs?: number; onRetry?: (info: unknown) => void }): Promise<boolean>;
|
|
2524
|
+
export function freeStaleMigrationLock(knex: unknown, migrationConfig?: Record<string, unknown>): Promise<boolean>;
|
|
2525
|
+
export function getMigrationStatus(knex: unknown, migrationConfig?: Record<string, unknown>): Promise<{ completed: string[]; pending: string[] }>;
|
|
2526
|
+
export function runCloudMigration(knex: unknown, options?: CloudMigrationOptions): Promise<CloudMigrationResult>;
|
|
2527
|
+
|
|
2036
2528
|
// --- ORM: nanoid / zod ---
|
|
2037
2529
|
|
|
2038
2530
|
export function generateNanoid(options?: { maxLength?: number } | number): string;
|
|
@@ -2574,6 +3066,147 @@ export interface RateLimitPluginOptions {
|
|
|
2574
3066
|
|
|
2575
3067
|
export function rateLimitPlugin(options?: RateLimitPluginOptions): WebspressoPlugin;
|
|
2576
3068
|
|
|
3069
|
+
export interface RateLimitInfo {
|
|
3070
|
+
totalHits: number;
|
|
3071
|
+
remaining: number;
|
|
3072
|
+
resetTime: Date;
|
|
3073
|
+
limit: number;
|
|
3074
|
+
}
|
|
3075
|
+
|
|
3076
|
+
export interface RateLimitStore {
|
|
3077
|
+
increment(key: string, windowMs: number): Promise<{ totalHits: number; resetTime: Date }>;
|
|
3078
|
+
decrement?(key: string): Promise<void>;
|
|
3079
|
+
resetKey?(key: string): Promise<void>;
|
|
3080
|
+
resetAll?(): Promise<void>;
|
|
3081
|
+
}
|
|
3082
|
+
|
|
3083
|
+
export class MemoryRateLimitStore implements RateLimitStore {
|
|
3084
|
+
constructor(options?: { cleanupIntervalMs?: number });
|
|
3085
|
+
increment(key: string, windowMs: number): Promise<{ totalHits: number; resetTime: Date }>;
|
|
3086
|
+
decrement(key: string): Promise<void>;
|
|
3087
|
+
resetKey(key: string): Promise<void>;
|
|
3088
|
+
resetAll(): Promise<void>;
|
|
3089
|
+
sweep(): void;
|
|
3090
|
+
destroy(): void;
|
|
3091
|
+
}
|
|
3092
|
+
|
|
3093
|
+
export class RedisRateLimitStore implements RateLimitStore {
|
|
3094
|
+
constructor(options: { client: unknown; prefix?: string; passOnStoreError?: boolean });
|
|
3095
|
+
increment(key: string, windowMs: number): Promise<{ totalHits: number; resetTime: Date }>;
|
|
3096
|
+
decrement(key: string): Promise<void>;
|
|
3097
|
+
resetKey(key: string): Promise<void>;
|
|
3098
|
+
resetAll(): Promise<void>;
|
|
3099
|
+
}
|
|
3100
|
+
|
|
3101
|
+
export interface RateLimitOptions {
|
|
3102
|
+
limit?: number;
|
|
3103
|
+
max?: number;
|
|
3104
|
+
window?: string | number;
|
|
3105
|
+
windowMs?: string | number;
|
|
3106
|
+
store?: RateLimitStore;
|
|
3107
|
+
keyGenerator?: (req: any) => string;
|
|
3108
|
+
skip?: (req: any) => boolean;
|
|
3109
|
+
standardHeaders?: boolean | string;
|
|
3110
|
+
legacyHeaders?: boolean;
|
|
3111
|
+
skipFailedRequests?: boolean;
|
|
3112
|
+
skipSuccessfulRequests?: boolean;
|
|
3113
|
+
statusCode?: number;
|
|
3114
|
+
message?: string | Record<string, unknown>;
|
|
3115
|
+
handler?: (req: any, res: any, next: any, info: RateLimitInfo) => unknown;
|
|
3116
|
+
}
|
|
3117
|
+
|
|
3118
|
+
export class RateLimiter {
|
|
3119
|
+
constructor(options?: RateLimitOptions);
|
|
3120
|
+
limit: number;
|
|
3121
|
+
windowMs: number;
|
|
3122
|
+
store: RateLimitStore;
|
|
3123
|
+
middleware(reqOrC: unknown, resOrNext: unknown, maybeNext?: unknown): Promise<unknown>;
|
|
3124
|
+
}
|
|
3125
|
+
|
|
3126
|
+
export function createRateLimiter(options?: RateLimitOptions): ((req: any, res: any, next: any) => unknown) & { limiter: RateLimiter };
|
|
3127
|
+
export function rateLimit(options?: RateLimitOptions): ((req: any, res: any, next: any) => unknown) & { limiter: RateLimiter };
|
|
3128
|
+
|
|
3129
|
+
// --- Feature Flags & Canary Traffic Splitter ---
|
|
3130
|
+
|
|
3131
|
+
export interface FeatureFlagVariant {
|
|
3132
|
+
name: string;
|
|
3133
|
+
weight?: number;
|
|
3134
|
+
[key: string]: unknown;
|
|
3135
|
+
}
|
|
3136
|
+
|
|
3137
|
+
export interface FeatureFlagDefinition {
|
|
3138
|
+
enabled?: boolean;
|
|
3139
|
+
rollout?: number;
|
|
3140
|
+
users?: string[];
|
|
3141
|
+
roles?: string[];
|
|
3142
|
+
emailDomains?: string[];
|
|
3143
|
+
condition?: (context: FeatureFlagContext) => boolean;
|
|
3144
|
+
variants?: FeatureFlagVariant[];
|
|
3145
|
+
variant?: string;
|
|
3146
|
+
default?: boolean;
|
|
3147
|
+
[key: string]: unknown;
|
|
3148
|
+
}
|
|
3149
|
+
|
|
3150
|
+
export interface FeatureFlagContext {
|
|
3151
|
+
user?: any;
|
|
3152
|
+
distinctId?: string;
|
|
3153
|
+
role?: string;
|
|
3154
|
+
roles?: string[] | Set<string>;
|
|
3155
|
+
email?: string;
|
|
3156
|
+
ip?: string;
|
|
3157
|
+
[key: string]: unknown;
|
|
3158
|
+
}
|
|
3159
|
+
|
|
3160
|
+
export interface FeatureFlagEvaluation {
|
|
3161
|
+
enabled: boolean;
|
|
3162
|
+
variant: string | null;
|
|
3163
|
+
reason: string;
|
|
3164
|
+
bucket?: number;
|
|
3165
|
+
}
|
|
3166
|
+
|
|
3167
|
+
export class MemoryFlagStore {
|
|
3168
|
+
constructor(initialFlags?: Record<string, any> | string);
|
|
3169
|
+
get(key: string): any;
|
|
3170
|
+
set(key: string, definition: any): void;
|
|
3171
|
+
has(key: string): boolean;
|
|
3172
|
+
delete(key: string): boolean;
|
|
3173
|
+
clear(): void;
|
|
3174
|
+
getAll(): Record<string, any>;
|
|
3175
|
+
load(source: Record<string, any> | string): void;
|
|
3176
|
+
}
|
|
3177
|
+
|
|
3178
|
+
export interface FeatureFlagOptions {
|
|
3179
|
+
flags?: Record<string, any> | string;
|
|
3180
|
+
store?: MemoryFlagStore | any;
|
|
3181
|
+
envPrefix?: string;
|
|
3182
|
+
identify?: (req: any) => string;
|
|
3183
|
+
}
|
|
3184
|
+
|
|
3185
|
+
export class FeatureFlagManager {
|
|
3186
|
+
constructor(options?: FeatureFlagOptions);
|
|
3187
|
+
store: MemoryFlagStore | any;
|
|
3188
|
+
envPrefix: string;
|
|
3189
|
+
isEnabled(flagKey: string, context?: FeatureFlagContext): boolean;
|
|
3190
|
+
getVariant(flagKey: string, context?: FeatureFlagContext): string | null;
|
|
3191
|
+
evaluate(flagKey: string, context?: FeatureFlagContext): FeatureFlagEvaluation;
|
|
3192
|
+
getAllFlags(context?: FeatureFlagContext): Record<string, boolean>;
|
|
3193
|
+
setFlag(flagKey: string, definition: any): void;
|
|
3194
|
+
removeFlag(flagKey: string): boolean;
|
|
3195
|
+
forContext(context?: FeatureFlagContext): {
|
|
3196
|
+
isEnabled: (key: string) => boolean;
|
|
3197
|
+
getVariant: (key: string) => string | null;
|
|
3198
|
+
evaluate: (key: string) => FeatureFlagEvaluation;
|
|
3199
|
+
all: () => Record<string, boolean>;
|
|
3200
|
+
};
|
|
3201
|
+
middleware(): (reqOrC: any, resOrNext: any, maybeNext?: any) => Promise<unknown> | unknown;
|
|
3202
|
+
guard(flagKey: string, options?: { statusCode?: number; message?: string; fallback?: Function }): (req: any, res: any, next: any) => unknown;
|
|
3203
|
+
}
|
|
3204
|
+
|
|
3205
|
+
export function createFeatureFlagManager(options?: FeatureFlagOptions): FeatureFlagManager;
|
|
3206
|
+
export function evaluateFlag(flagKey: string, definition: any, rawContext?: any, options?: { envPrefix?: string }): FeatureFlagEvaluation;
|
|
3207
|
+
export function getBucket(flagKey: string, distinctId: string | number): number;
|
|
3208
|
+
export function fnv1a(str: string): number;
|
|
3209
|
+
|
|
2577
3210
|
export interface CsrfCookieOptions {
|
|
2578
3211
|
key?: string;
|
|
2579
3212
|
signed?: boolean;
|
|
@@ -2832,7 +3465,7 @@ export function restResourcePlugin(options?: RestResourcePluginOptions): Webspre
|
|
|
2832
3465
|
|
|
2833
3466
|
export function ormCacheAdminPlugin(options: { db: DatabaseInstance }): WebspressoPlugin;
|
|
2834
3467
|
|
|
2835
|
-
/** Multipart upload storage (e.g. local disk or S3). */
|
|
3468
|
+
/** Multipart upload storage (e.g. local disk, R2, or S3). */
|
|
2836
3469
|
export interface UploadStorageProvider {
|
|
2837
3470
|
put(args: {
|
|
2838
3471
|
buffer?: Buffer;
|
|
@@ -2842,6 +3475,20 @@ export interface UploadStorageProvider {
|
|
|
2842
3475
|
size: number;
|
|
2843
3476
|
req: Request;
|
|
2844
3477
|
}): Promise<{ publicUrl: string; key?: string }>;
|
|
3478
|
+
delete?(key: string): Promise<boolean | void>;
|
|
3479
|
+
createSignedUploadUrl?(params?: {
|
|
3480
|
+
originalName?: string;
|
|
3481
|
+
mimeType?: string;
|
|
3482
|
+
expiresInSeconds?: number;
|
|
3483
|
+
expiresInMs?: number;
|
|
3484
|
+
key?: string;
|
|
3485
|
+
}): Promise<{
|
|
3486
|
+
uploadUrl: string;
|
|
3487
|
+
publicUrl: string;
|
|
3488
|
+
key: string;
|
|
3489
|
+
method: string;
|
|
3490
|
+
headers?: Record<string, string>;
|
|
3491
|
+
}>;
|
|
2845
3492
|
}
|
|
2846
3493
|
|
|
2847
3494
|
export interface UploadPluginOptions {
|
|
@@ -2853,6 +3500,11 @@ export interface UploadPluginOptions {
|
|
|
2853
3500
|
extensionAllowlist?: string[] | null;
|
|
2854
3501
|
middleware?: RequestHandler | RequestHandler[];
|
|
2855
3502
|
fieldName?: string;
|
|
3503
|
+
multiple?: boolean;
|
|
3504
|
+
maxFiles?: number;
|
|
3505
|
+
presigned?: boolean;
|
|
3506
|
+
presignedRoute?: string;
|
|
3507
|
+
presignedMiddleware?: RequestHandler | RequestHandler[];
|
|
2856
3508
|
}
|
|
2857
3509
|
|
|
2858
3510
|
export function uploadPlugin(options?: UploadPluginOptions): WebspressoPlugin;
|
|
@@ -2862,6 +3514,27 @@ export function createLocalFileProvider(options?: {
|
|
|
2862
3514
|
publicBasePath?: string;
|
|
2863
3515
|
}): UploadStorageProvider;
|
|
2864
3516
|
|
|
3517
|
+
export function createR2FileProvider(options: {
|
|
3518
|
+
bucket: unknown;
|
|
3519
|
+
publicBaseUrl?: string;
|
|
3520
|
+
prefix?: string;
|
|
3521
|
+
}): UploadStorageProvider;
|
|
3522
|
+
|
|
3523
|
+
export function createS3FileProvider(options: {
|
|
3524
|
+
s3Client: unknown;
|
|
3525
|
+
bucket: string;
|
|
3526
|
+
publicBaseUrl?: string;
|
|
3527
|
+
prefix?: string;
|
|
3528
|
+
createSignedUrl?: (params: { bucket: string; key: string; mimeType: string; expiresInSeconds: number }) => Promise<string>;
|
|
3529
|
+
}): UploadStorageProvider;
|
|
3530
|
+
|
|
3531
|
+
export function createGcsFileProvider(options: {
|
|
3532
|
+
bucket: unknown;
|
|
3533
|
+
storageClient?: unknown;
|
|
3534
|
+
publicBaseUrl?: string;
|
|
3535
|
+
prefix?: string;
|
|
3536
|
+
}): UploadStorageProvider;
|
|
3537
|
+
|
|
2865
3538
|
export interface OrphanedUploadsResult {
|
|
2866
3539
|
destDir: string;
|
|
2867
3540
|
totalFiles: number;
|
|
@@ -3271,6 +3944,64 @@ export class RedisQueueAdapter implements QueueAdapter {
|
|
|
3271
3944
|
}): Promise<number>;
|
|
3272
3945
|
}
|
|
3273
3946
|
|
|
3947
|
+
export class WaitUntilQueueAdapter extends MemoryQueueAdapter {
|
|
3948
|
+
constructor(options?: { waitUntil?: (promise: Promise<unknown>) => void; maxRetainedJobs?: number });
|
|
3949
|
+
setWaitUntil(fn: (promise: Promise<unknown>) => void): void;
|
|
3950
|
+
runInBackground(promise: Promise<unknown>): void;
|
|
3951
|
+
}
|
|
3952
|
+
|
|
3953
|
+
export class CloudflareQueueAdapter {
|
|
3954
|
+
constructor(options: { queue: { send(message: unknown, options?: unknown): Promise<unknown> } });
|
|
3955
|
+
enqueue(job: Job): Promise<Job>;
|
|
3956
|
+
dequeue(): Promise<null>;
|
|
3957
|
+
complete(jobId: string | number, result?: unknown): Promise<Job | null>;
|
|
3958
|
+
fail(jobId: string | number, error?: unknown): Promise<Job | null>;
|
|
3959
|
+
retry(jobId: string | number, delayMs: number, error?: unknown): Promise<Job | null>;
|
|
3960
|
+
processBatch(batch: unknown, queueManager: unknown): Promise<{ processed: number; failed: number }>;
|
|
3961
|
+
}
|
|
3962
|
+
|
|
3963
|
+
export interface SqsQueueAdapterOptions {
|
|
3964
|
+
queueUrl?: string;
|
|
3965
|
+
region?: string;
|
|
3966
|
+
accessKeyId?: string;
|
|
3967
|
+
secretAccessKey?: string;
|
|
3968
|
+
sessionToken?: string;
|
|
3969
|
+
waitTimeSeconds?: number;
|
|
3970
|
+
visibilityTimeout?: number;
|
|
3971
|
+
sqsClient?: unknown;
|
|
3972
|
+
httpTransport?: unknown;
|
|
3973
|
+
}
|
|
3974
|
+
|
|
3975
|
+
export class SqsQueueAdapter implements QueueAdapter {
|
|
3976
|
+
constructor(options?: SqsQueueAdapterOptions);
|
|
3977
|
+
enqueue(job: Job): Promise<Job>;
|
|
3978
|
+
dequeue(jobNames?: string[]): Promise<Job | null>;
|
|
3979
|
+
complete(jobId: string | number, result?: unknown): Promise<Job | null>;
|
|
3980
|
+
fail(jobId: string | number, error?: unknown): Promise<Job | null>;
|
|
3981
|
+
retry(jobId: string | number, delayMs: number, error?: unknown): Promise<Job | null>;
|
|
3982
|
+
getStats(): Promise<{ pending: number; running: number; delayed: number; total: number }>;
|
|
3983
|
+
processBatch(records: unknown[], queueManager: unknown): Promise<{ processed: number; failed: number }>;
|
|
3984
|
+
}
|
|
3985
|
+
|
|
3986
|
+
export interface PubSubQueueAdapterOptions {
|
|
3987
|
+
projectId?: string;
|
|
3988
|
+
topic: string;
|
|
3989
|
+
subscription?: string;
|
|
3990
|
+
token?: string;
|
|
3991
|
+
pubsubClient?: unknown;
|
|
3992
|
+
httpTransport?: unknown;
|
|
3993
|
+
}
|
|
3994
|
+
|
|
3995
|
+
export class PubSubQueueAdapter implements QueueAdapter {
|
|
3996
|
+
constructor(options: PubSubQueueAdapterOptions);
|
|
3997
|
+
enqueue(job: Job): Promise<Job>;
|
|
3998
|
+
dequeue(jobNames?: string[]): Promise<Job | null>;
|
|
3999
|
+
complete(jobId: string | number, result?: unknown): Promise<Job | null>;
|
|
4000
|
+
fail(jobId: string | number, error?: unknown): Promise<Job | null>;
|
|
4001
|
+
retry(jobId: string | number, delayMs: number, error?: unknown): Promise<Job | null>;
|
|
4002
|
+
processPushRequest(req: unknown, res: unknown, queueManager: unknown): Promise<boolean>;
|
|
4003
|
+
}
|
|
4004
|
+
|
|
3274
4005
|
export interface DispatchOptions {
|
|
3275
4006
|
delay?: number | Date;
|
|
3276
4007
|
attempts?: number;
|
|
@@ -3499,6 +4230,43 @@ export const ssr: {
|
|
|
3499
4230
|
renderStream: typeof renderStream;
|
|
3500
4231
|
};
|
|
3501
4232
|
|
|
4233
|
+
// --- Static Site Export & Prerendering ---
|
|
4234
|
+
|
|
4235
|
+
export interface StaticExportOptions {
|
|
4236
|
+
cwd?: string;
|
|
4237
|
+
app?: import('express').Express;
|
|
4238
|
+
createApp?: (config?: any) => any;
|
|
4239
|
+
serverConfig?: Record<string, unknown>;
|
|
4240
|
+
pagesDir?: string;
|
|
4241
|
+
publicDir?: string;
|
|
4242
|
+
outDir?: string;
|
|
4243
|
+
clean?: boolean;
|
|
4244
|
+
cleanUrls?: boolean;
|
|
4245
|
+
copyAssets?: boolean;
|
|
4246
|
+
sitemap?: boolean;
|
|
4247
|
+
baseUrl?: string;
|
|
4248
|
+
concurrency?: number;
|
|
4249
|
+
extraRoutes?: string[];
|
|
4250
|
+
silent?: boolean;
|
|
4251
|
+
db?: unknown;
|
|
4252
|
+
}
|
|
4253
|
+
|
|
4254
|
+
export interface StaticExportResult {
|
|
4255
|
+
total: number;
|
|
4256
|
+
rendered: number;
|
|
4257
|
+
skipped: number;
|
|
4258
|
+
errors: Array<{ path: string; error: string }>;
|
|
4259
|
+
outDir: string;
|
|
4260
|
+
durationMs: number;
|
|
4261
|
+
}
|
|
4262
|
+
|
|
4263
|
+
export function exportStaticSite(options?: StaticExportOptions): Promise<StaticExportResult>;
|
|
4264
|
+
export function discoverExportRoutes(options?: {
|
|
4265
|
+
pagesDir?: string;
|
|
4266
|
+
db?: unknown;
|
|
4267
|
+
extraRoutes?: string[];
|
|
4268
|
+
}): Promise<Array<{ path: string; sourceFile: string | null; isDynamic: boolean; params?: Record<string, any> }>>;
|
|
4269
|
+
|
|
3502
4270
|
// --- Server-Sent Events (SSE) Streaming ---
|
|
3503
4271
|
|
|
3504
4272
|
export interface SseOptions {
|
|
@@ -3547,6 +4315,51 @@ export const sseStream: {
|
|
|
3547
4315
|
formatSseFrame: (data?: any, event?: string, id?: string | number, retry?: number) => string;
|
|
3548
4316
|
};
|
|
3549
4317
|
|
|
4318
|
+
// --- AI & LLM Text / NDJSON Streaming ---
|
|
4319
|
+
|
|
4320
|
+
export interface TextStreamOptions {
|
|
4321
|
+
status?: number;
|
|
4322
|
+
contentType?: string;
|
|
4323
|
+
headers?: Record<string, string>;
|
|
4324
|
+
map?: (chunk: any) => any;
|
|
4325
|
+
}
|
|
4326
|
+
|
|
4327
|
+
export class TextStreamController extends EventEmitter {
|
|
4328
|
+
req: import('http').IncomingMessage;
|
|
4329
|
+
res: import('http').ServerResponse;
|
|
4330
|
+
options: TextStreamOptions;
|
|
4331
|
+
ndjson: boolean;
|
|
4332
|
+
isOpen: boolean;
|
|
4333
|
+
isClosed: boolean;
|
|
4334
|
+
|
|
4335
|
+
constructor(req: import('http').IncomingMessage, res: import('http').ServerResponse, options?: TextStreamOptions & { ndjson?: boolean });
|
|
4336
|
+
write(chunk: any): Promise<boolean>;
|
|
4337
|
+
pipe(source: AsyncIterable<any> | Iterable<any> | import('stream').Readable, transform?: (chunk: any) => any): Promise<void>;
|
|
4338
|
+
stream(runnerFn: (stream: TextStreamController) => any): Promise<void>;
|
|
4339
|
+
close(): void;
|
|
4340
|
+
end(): void;
|
|
4341
|
+
}
|
|
4342
|
+
|
|
4343
|
+
export function streamText(
|
|
4344
|
+
req: import('http').IncomingMessage,
|
|
4345
|
+
res: import('http').ServerResponse,
|
|
4346
|
+
sourceOrCallback?: TextStreamOptions | AsyncIterable<any> | Iterable<any> | import('stream').Readable | ((stream: TextStreamController) => any),
|
|
4347
|
+
maybeOptions?: TextStreamOptions
|
|
4348
|
+
): TextStreamController | Promise<void>;
|
|
4349
|
+
|
|
4350
|
+
export function streamJson(
|
|
4351
|
+
req: import('http').IncomingMessage,
|
|
4352
|
+
res: import('http').ServerResponse,
|
|
4353
|
+
sourceOrCallback?: TextStreamOptions | AsyncIterable<any> | Iterable<any> | import('stream').Readable | ((stream: TextStreamController) => any),
|
|
4354
|
+
maybeOptions?: TextStreamOptions
|
|
4355
|
+
): TextStreamController | Promise<void>;
|
|
4356
|
+
|
|
4357
|
+
export const stream: {
|
|
4358
|
+
TextStreamController: typeof TextStreamController;
|
|
4359
|
+
streamText: typeof streamText;
|
|
4360
|
+
streamJson: typeof streamJson;
|
|
4361
|
+
};
|
|
4362
|
+
|
|
3550
4363
|
// --- Model Context Protocol (MCP) Plugin ---
|
|
3551
4364
|
|
|
3552
4365
|
export interface McpPluginOptions {
|
|
@@ -3834,13 +4647,19 @@ export interface ApiContext<TBody = any, TParams = Record<string, string>, TQuer
|
|
|
3834
4647
|
config: Record<string, unknown>;
|
|
3835
4648
|
logger: Console;
|
|
3836
4649
|
db: unknown;
|
|
4650
|
+
flags?: any;
|
|
4651
|
+
hasFeature?: (key: string, customContext?: any) => boolean;
|
|
4652
|
+
getVariant?: (key: string, customContext?: any) => string | null;
|
|
3837
4653
|
sse?: (sourceOrOptions?: any, maybeOptions?: any) => any;
|
|
4654
|
+
streamText?: (sourceOrCallback?: any, maybeOptions?: any) => any;
|
|
4655
|
+
streamJson?: (sourceOrCallback?: any, maybeOptions?: any) => any;
|
|
3838
4656
|
}
|
|
3839
4657
|
|
|
3840
4658
|
export interface DefineApiOptions<TResult = any, TBody = any, TParams = Record<string, string>, TQuery = Record<string, string>> {
|
|
3841
4659
|
description?: string;
|
|
3842
4660
|
tags?: string[];
|
|
3843
4661
|
middleware?: (string | import('express').RequestHandler | [string, Record<string, unknown>])[];
|
|
4662
|
+
flag?: string | { key: string; statusCode?: number; message?: string };
|
|
3844
4663
|
schema?: {
|
|
3845
4664
|
params?: unknown;
|
|
3846
4665
|
query?: unknown;
|
|
@@ -4043,6 +4862,21 @@ export interface GenerateTypesResult {
|
|
|
4043
4862
|
|
|
4044
4863
|
export function generateTypes(options?: GenerateTypesOptions): GenerateTypesResult;
|
|
4045
4864
|
|
|
4865
|
+
export interface ClientGeneratorOptions {
|
|
4866
|
+
rootDir?: string;
|
|
4867
|
+
pagesDir?: string;
|
|
4868
|
+
outFile?: string;
|
|
4869
|
+
baseUrl?: string;
|
|
4870
|
+
silent?: boolean;
|
|
4871
|
+
}
|
|
4872
|
+
|
|
4873
|
+
export interface ClientGeneratorResult {
|
|
4874
|
+
outFile: string;
|
|
4875
|
+
routesCount: number;
|
|
4876
|
+
}
|
|
4877
|
+
|
|
4878
|
+
export function generateClient(options?: ClientGeneratorOptions): ClientGeneratorResult;
|
|
4879
|
+
|
|
4046
4880
|
// --- OAuth 2.0 & Social Login Plugin ---
|
|
4047
4881
|
|
|
4048
4882
|
export class OAuthError extends Error {
|
|
@@ -4404,9 +5238,45 @@ export function createUserSessionsTable(knex: any): Promise<void>;
|
|
|
4404
5238
|
export function dropUserSessionsTable(knex: any): Promise<void>;
|
|
4405
5239
|
export function createKnexSessionTracker(db: any, options?: { tableName?: string }): SessionTracker;
|
|
4406
5240
|
export function createMemorySessionTracker(): SessionTracker;
|
|
5241
|
+
export function createKvSessionTracker(kv: any, options?: { prefix?: string; ttlSeconds?: number }): SessionTracker;
|
|
4407
5242
|
export function createListSessionsHandler(authManager: any): (req: any, res: any) => Promise<any>;
|
|
4408
5243
|
export function createRevokeSessionHandler(authManager: any): (req: any, res: any) => Promise<any>;
|
|
4409
5244
|
|
|
5245
|
+
export interface RedisSessionStoreOptions {
|
|
5246
|
+
client?: any;
|
|
5247
|
+
url?: string;
|
|
5248
|
+
prefix?: string;
|
|
5249
|
+
ttl?: number;
|
|
5250
|
+
disableTouch?: boolean;
|
|
5251
|
+
inMemory?: boolean;
|
|
5252
|
+
serializer?: { parse: (s: string) => any; stringify: (o: any) => string };
|
|
5253
|
+
}
|
|
5254
|
+
|
|
5255
|
+
export class RedisSessionStore {
|
|
5256
|
+
constructor(options?: RedisSessionStoreOptions);
|
|
5257
|
+
prefix: string;
|
|
5258
|
+
ttl: number;
|
|
5259
|
+
disableTouch: boolean;
|
|
5260
|
+
get(sid: string, callback?: (err?: any, session?: any) => void): void;
|
|
5261
|
+
set(sid: string, session: any, callback?: (err?: any) => void): void;
|
|
5262
|
+
destroy(sid: string, callback?: (err?: any) => void): void;
|
|
5263
|
+
touch(sid: string, session: any, callback?: (err?: any) => void): void;
|
|
5264
|
+
all(callback?: (err?: any, sessions?: any[]) => void): void;
|
|
5265
|
+
length(callback?: (err?: any, count?: number) => void): void;
|
|
5266
|
+
clear(callback?: (err?: any) => void): void;
|
|
5267
|
+
close(): Promise<void>;
|
|
5268
|
+
}
|
|
5269
|
+
|
|
5270
|
+
export function createRedisSessionStore(options?: RedisSessionStoreOptions): RedisSessionStore;
|
|
5271
|
+
export function createRedisSessionTracker(options?: {
|
|
5272
|
+
client?: any;
|
|
5273
|
+
url?: string;
|
|
5274
|
+
prefix?: string;
|
|
5275
|
+
ttlSeconds?: number;
|
|
5276
|
+
inMemory?: boolean;
|
|
5277
|
+
}): SessionTracker;
|
|
5278
|
+
export function createMiniRedisClient(urlOrOptions?: string | { host?: string; port?: number; password?: string; db?: number; inMemory?: boolean }): any;
|
|
5279
|
+
|
|
4410
5280
|
export namespace sessions {
|
|
4411
5281
|
export {
|
|
4412
5282
|
SessionManager,
|
|
@@ -4414,6 +5284,11 @@ export namespace sessions {
|
|
|
4414
5284
|
dropUserSessionsTable,
|
|
4415
5285
|
createKnexSessionTracker,
|
|
4416
5286
|
createMemorySessionTracker,
|
|
5287
|
+
createKvSessionTracker,
|
|
5288
|
+
createRedisSessionStore,
|
|
5289
|
+
createRedisSessionTracker,
|
|
5290
|
+
RedisSessionStore,
|
|
5291
|
+
createMiniRedisClient,
|
|
4417
5292
|
getClientIp,
|
|
4418
5293
|
parseUserAgent,
|
|
4419
5294
|
createListSessionsHandler,
|
|
@@ -4483,5 +5358,226 @@ export interface RlsPluginOptions {
|
|
|
4483
5358
|
export function rlsPlugin(options?: RlsPluginOptions): import('./src/plugin-manager').Plugin;
|
|
4484
5359
|
export function createRlsMiddleware(options?: RlsPluginOptions): (req: any, res: any, next: (err?: any) => void) => void;
|
|
4485
5360
|
|
|
5361
|
+
// --- Structured Cloud Logging ---
|
|
5362
|
+
export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'fatal' | 'silent';
|
|
5363
|
+
export type LogFormat = 'auto' | 'gcp' | 'aws' | 'json' | 'pretty';
|
|
5364
|
+
|
|
5365
|
+
export interface LoggerOptions {
|
|
5366
|
+
format?: LogFormat;
|
|
5367
|
+
level?: LogLevel;
|
|
5368
|
+
stream?: NodeJS.WritableStream;
|
|
5369
|
+
defaultMeta?: Record<string, unknown>;
|
|
5370
|
+
redact?: string[];
|
|
5371
|
+
project?: string;
|
|
5372
|
+
exclude?: string[];
|
|
5373
|
+
}
|
|
5374
|
+
|
|
5375
|
+
export class CloudLogger {
|
|
5376
|
+
constructor(options?: LoggerOptions);
|
|
5377
|
+
format: LogFormat;
|
|
5378
|
+
level: LogLevel;
|
|
5379
|
+
child(additionalMeta?: Record<string, unknown>): CloudLogger;
|
|
5380
|
+
debug(message: string, meta?: Record<string, unknown>): void;
|
|
5381
|
+
info(message: string, meta?: Record<string, unknown>): void;
|
|
5382
|
+
warn(message: string, meta?: Record<string, unknown>): void;
|
|
5383
|
+
error(message: string, meta?: Record<string, unknown>): void;
|
|
5384
|
+
fatal(message: string, meta?: Record<string, unknown>): void;
|
|
5385
|
+
log(level: string, message: string, meta?: Record<string, unknown>): void;
|
|
5386
|
+
}
|
|
5387
|
+
|
|
5388
|
+
export function createLogger(options?: LoggerOptions): CloudLogger;
|
|
5389
|
+
export function createLogMiddleware(logger?: CloudLogger, options?: LoggerOptions): RequestHandler;
|
|
5390
|
+
export function extractTraceContext(req: unknown): {
|
|
5391
|
+
traceId: string;
|
|
5392
|
+
spanId?: string | null;
|
|
5393
|
+
sampled: boolean;
|
|
5394
|
+
raw?: string | null;
|
|
5395
|
+
platform?: string;
|
|
5396
|
+
};
|
|
5397
|
+
|
|
5398
|
+
// --- Cloud Metrics & Distributed Tracing ---
|
|
5399
|
+
|
|
5400
|
+
export interface MetricLabels {
|
|
5401
|
+
[key: string]: string | number;
|
|
5402
|
+
}
|
|
5403
|
+
|
|
5404
|
+
export interface MetricSeries<T = unknown> {
|
|
5405
|
+
labels: MetricLabels;
|
|
5406
|
+
value?: number;
|
|
5407
|
+
sum?: number;
|
|
5408
|
+
count?: number;
|
|
5409
|
+
buckets?: Array<{ le: number | string; count: number }>;
|
|
5410
|
+
}
|
|
5411
|
+
|
|
5412
|
+
export class Counter {
|
|
5413
|
+
name: string;
|
|
5414
|
+
help: string;
|
|
5415
|
+
type: 'counter';
|
|
5416
|
+
constructor(name: string, help?: string);
|
|
5417
|
+
inc(labels?: MetricLabels, value?: number): void;
|
|
5418
|
+
inc(value?: number): void;
|
|
5419
|
+
get(labels?: MetricLabels): number;
|
|
5420
|
+
reset(): void;
|
|
5421
|
+
toPrometheus(): string;
|
|
5422
|
+
}
|
|
5423
|
+
|
|
5424
|
+
export class Gauge {
|
|
5425
|
+
name: string;
|
|
5426
|
+
help: string;
|
|
5427
|
+
type: 'gauge';
|
|
5428
|
+
constructor(name: string, help?: string);
|
|
5429
|
+
set(labels: MetricLabels, value: number): void;
|
|
5430
|
+
set(value: number): void;
|
|
5431
|
+
inc(labels?: MetricLabels, value?: number): void;
|
|
5432
|
+
inc(value?: number): void;
|
|
5433
|
+
dec(labels?: MetricLabels, value?: number): void;
|
|
5434
|
+
dec(value?: number): void;
|
|
5435
|
+
get(labels?: MetricLabels): number;
|
|
5436
|
+
reset(): void;
|
|
5437
|
+
toPrometheus(): string;
|
|
5438
|
+
}
|
|
5439
|
+
|
|
5440
|
+
export class Histogram {
|
|
5441
|
+
name: string;
|
|
5442
|
+
help: string;
|
|
5443
|
+
type: 'histogram';
|
|
5444
|
+
buckets: number[];
|
|
5445
|
+
constructor(name: string, help?: string, buckets?: number[]);
|
|
5446
|
+
observe(labels: MetricLabels, value: number): void;
|
|
5447
|
+
observe(value: number): void;
|
|
5448
|
+
reset(): void;
|
|
5449
|
+
toPrometheus(): string;
|
|
5450
|
+
}
|
|
5451
|
+
|
|
5452
|
+
export class MetricsRegistry {
|
|
5453
|
+
constructor();
|
|
5454
|
+
counter(name: string, help?: string): Counter;
|
|
5455
|
+
gauge(name: string, help?: string): Gauge;
|
|
5456
|
+
histogram(name: string, help?: string, buckets?: number[]): Histogram;
|
|
5457
|
+
remove(name: string): void;
|
|
5458
|
+
reset(): void;
|
|
5459
|
+
formatPrometheus(): string;
|
|
5460
|
+
formatJson(): Record<string, unknown>;
|
|
5461
|
+
}
|
|
5462
|
+
|
|
5463
|
+
export function createMetricsRegistry(): MetricsRegistry;
|
|
5464
|
+
|
|
5465
|
+
export interface MetricsConfig {
|
|
5466
|
+
/** Enable or disable metrics collection and endpoint (default: true if metrics option is provided) */
|
|
5467
|
+
enabled?: boolean;
|
|
5468
|
+
/** Custom endpoint path (default: '/metrics') */
|
|
5469
|
+
path?: string;
|
|
5470
|
+
/** Whether to collect default Node.js system, event loop, pool, and cache metrics (default: true) */
|
|
5471
|
+
collectDefault?: boolean;
|
|
5472
|
+
/** Whether to inject x-trace-id and W3C traceparent response headers (default: true) */
|
|
5473
|
+
traceHeader?: boolean;
|
|
5474
|
+
/** Authentication bearer token required to access /metrics (string or { token: string }) */
|
|
5475
|
+
auth?: string | { token: string } | null;
|
|
5476
|
+
/** Custom histogram latency buckets in seconds */
|
|
5477
|
+
buckets?: number[];
|
|
5478
|
+
}
|
|
5479
|
+
|
|
5480
|
+
export function setupMetricsMiddleware(
|
|
5481
|
+
app: unknown,
|
|
5482
|
+
options?: boolean | MetricsConfig,
|
|
5483
|
+
context?: Record<string, unknown>
|
|
5484
|
+
): {
|
|
5485
|
+
config: MetricsConfig;
|
|
5486
|
+
registry: MetricsRegistry;
|
|
5487
|
+
requestMiddleware: RequestHandler;
|
|
5488
|
+
getPrometheusMetrics: (scrapeContext?: Record<string, unknown>) => string;
|
|
5489
|
+
getJsonMetrics: (scrapeContext?: Record<string, unknown>) => Record<string, unknown>;
|
|
5490
|
+
requestsTotal: Counter;
|
|
5491
|
+
requestDuration: Histogram;
|
|
5492
|
+
activeRequests: Gauge;
|
|
5493
|
+
} | null;
|
|
5494
|
+
|
|
5495
|
+
export namespace metrics {
|
|
5496
|
+
export {
|
|
5497
|
+
MetricsRegistry,
|
|
5498
|
+
createMetricsRegistry,
|
|
5499
|
+
Counter,
|
|
5500
|
+
Gauge,
|
|
5501
|
+
Histogram,
|
|
5502
|
+
setupMetricsMiddleware,
|
|
5503
|
+
MetricsConfig,
|
|
5504
|
+
};
|
|
5505
|
+
}
|
|
5506
|
+
|
|
5507
|
+
export interface ConsoleOptions {
|
|
5508
|
+
rootDir?: string;
|
|
5509
|
+
configPath?: string;
|
|
5510
|
+
env?: string;
|
|
5511
|
+
input?: NodeJS.ReadableStream;
|
|
5512
|
+
output?: NodeJS.WritableStream;
|
|
5513
|
+
useColors?: boolean;
|
|
5514
|
+
history?: boolean;
|
|
5515
|
+
historyPath?: string;
|
|
5516
|
+
banner?: boolean;
|
|
5517
|
+
prompt?: string;
|
|
5518
|
+
eval?: string;
|
|
5519
|
+
}
|
|
5520
|
+
|
|
5521
|
+
export interface ConsoleContext {
|
|
5522
|
+
db: any;
|
|
5523
|
+
models: Record<string, any>;
|
|
5524
|
+
services: any;
|
|
5525
|
+
service: (name: string, input?: any, ctx?: any) => Promise<any>;
|
|
5526
|
+
queue: any;
|
|
5527
|
+
events: any;
|
|
5528
|
+
flags: any;
|
|
5529
|
+
cache: any;
|
|
5530
|
+
mailer: any;
|
|
5531
|
+
webspresso: any;
|
|
5532
|
+
env: string;
|
|
5533
|
+
rootDir: string;
|
|
5534
|
+
context: ConsoleContext;
|
|
5535
|
+
help: () => void;
|
|
5536
|
+
reload: () => Promise<{ models: string[]; services: string[] }>;
|
|
5537
|
+
[key: string]: any;
|
|
5538
|
+
}
|
|
5539
|
+
|
|
5540
|
+
export interface ConsoleSession {
|
|
5541
|
+
replServer: any;
|
|
5542
|
+
context: ConsoleContext;
|
|
5543
|
+
meta: {
|
|
5544
|
+
env: string;
|
|
5545
|
+
rootDir: string;
|
|
5546
|
+
hasDb: boolean;
|
|
5547
|
+
modelsCount: number;
|
|
5548
|
+
modelNames: string[];
|
|
5549
|
+
hasServices: boolean;
|
|
5550
|
+
servicesCount: number;
|
|
5551
|
+
serviceNames: string[];
|
|
5552
|
+
};
|
|
5553
|
+
teardown: () => Promise<void>;
|
|
5554
|
+
}
|
|
5555
|
+
|
|
5556
|
+
export function buildConsoleContext(options?: ConsoleOptions): Promise<{
|
|
5557
|
+
context: ConsoleContext;
|
|
5558
|
+
meta: ConsoleSession['meta'];
|
|
5559
|
+
teardown: () => Promise<void>;
|
|
5560
|
+
}>;
|
|
5561
|
+
|
|
5562
|
+
export function startConsole(options?: ConsoleOptions): Promise<ConsoleSession>;
|
|
5563
|
+
|
|
5564
|
+
export function evaluateInConsole(
|
|
5565
|
+
code: string,
|
|
5566
|
+
options?: ConsoleOptions
|
|
5567
|
+
): Promise<{ result?: any; output: string | null; error?: Error }>;
|
|
5568
|
+
|
|
5569
|
+
export namespace repl {
|
|
5570
|
+
export {
|
|
5571
|
+
buildConsoleContext,
|
|
5572
|
+
startConsole,
|
|
5573
|
+
evaluateInConsole,
|
|
5574
|
+
ConsoleOptions,
|
|
5575
|
+
ConsoleContext,
|
|
5576
|
+
ConsoleSession,
|
|
5577
|
+
};
|
|
5578
|
+
}
|
|
5579
|
+
|
|
5580
|
+
|
|
5581
|
+
|
|
4486
5582
|
|
|
4487
5583
|
|