@oakbun/logger 0.1.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/dist/index.d.ts +63 -0
  2. package/package.json +5 -5
  3. package/dist/core/src/adapter/mysql.d.ts +0 -21
  4. package/dist/core/src/adapter/mysql.d.ts.map +0 -1
  5. package/dist/core/src/adapter/postgres.d.ts +0 -16
  6. package/dist/core/src/adapter/postgres.d.ts.map +0 -1
  7. package/dist/core/src/adapter/resolve.d.ts +0 -16
  8. package/dist/core/src/adapter/resolve.d.ts.map +0 -1
  9. package/dist/core/src/adapter/sqlite.d.ts +0 -17
  10. package/dist/core/src/adapter/sqlite.d.ts.map +0 -1
  11. package/dist/core/src/adapter/types.d.ts +0 -29
  12. package/dist/core/src/adapter/types.d.ts.map +0 -1
  13. package/dist/core/src/app/audit-wiring.d.ts +0 -6
  14. package/dist/core/src/app/audit-wiring.d.ts.map +0 -1
  15. package/dist/core/src/app/body-size-limit.d.ts +0 -29
  16. package/dist/core/src/app/body-size-limit.d.ts.map +0 -1
  17. package/dist/core/src/app/compression.d.ts +0 -25
  18. package/dist/core/src/app/compression.d.ts.map +0 -1
  19. package/dist/core/src/app/cookies.d.ts +0 -17
  20. package/dist/core/src/app/cookies.d.ts.map +0 -1
  21. package/dist/core/src/app/cors.d.ts +0 -65
  22. package/dist/core/src/app/cors.d.ts.map +0 -1
  23. package/dist/core/src/app/csrf.d.ts +0 -52
  24. package/dist/core/src/app/csrf.d.ts.map +0 -1
  25. package/dist/core/src/app/health.d.ts +0 -36
  26. package/dist/core/src/app/health.d.ts.map +0 -1
  27. package/dist/core/src/app/index.d.ts +0 -282
  28. package/dist/core/src/app/index.d.ts.map +0 -1
  29. package/dist/core/src/app/logger.d.ts +0 -4
  30. package/dist/core/src/app/logger.d.ts.map +0 -1
  31. package/dist/core/src/app/middleware.d.ts +0 -20
  32. package/dist/core/src/app/middleware.d.ts.map +0 -1
  33. package/dist/core/src/app/module.d.ts +0 -273
  34. package/dist/core/src/app/module.d.ts.map +0 -1
  35. package/dist/core/src/app/plugin.d.ts +0 -112
  36. package/dist/core/src/app/plugin.d.ts.map +0 -1
  37. package/dist/core/src/app/rate-limit.d.ts +0 -76
  38. package/dist/core/src/app/rate-limit.d.ts.map +0 -1
  39. package/dist/core/src/app/request-id.d.ts +0 -52
  40. package/dist/core/src/app/request-id.d.ts.map +0 -1
  41. package/dist/core/src/app/router.d.ts +0 -6
  42. package/dist/core/src/app/router.d.ts.map +0 -1
  43. package/dist/core/src/app/scalar.d.ts +0 -40
  44. package/dist/core/src/app/scalar.d.ts.map +0 -1
  45. package/dist/core/src/app/secure-headers.d.ts +0 -48
  46. package/dist/core/src/app/secure-headers.d.ts.map +0 -1
  47. package/dist/core/src/app/system-ctx.d.ts +0 -3
  48. package/dist/core/src/app/system-ctx.d.ts.map +0 -1
  49. package/dist/core/src/app/types.d.ts +0 -277
  50. package/dist/core/src/app/types.d.ts.map +0 -1
  51. package/dist/core/src/cli/config/types.d.ts +0 -31
  52. package/dist/core/src/cli/config/types.d.ts.map +0 -1
  53. package/dist/core/src/cli/index.d.ts +0 -3
  54. package/dist/core/src/cli/index.d.ts.map +0 -1
  55. package/dist/core/src/client/error.d.ts +0 -8
  56. package/dist/core/src/client/error.d.ts.map +0 -1
  57. package/dist/core/src/client/index.d.ts +0 -33
  58. package/dist/core/src/client/index.d.ts.map +0 -1
  59. package/dist/core/src/client/proxy.d.ts +0 -88
  60. package/dist/core/src/client/proxy.d.ts.map +0 -1
  61. package/dist/core/src/client/test-client.d.ts +0 -30
  62. package/dist/core/src/client/test-client.d.ts.map +0 -1
  63. package/dist/core/src/cron/index.d.ts +0 -73
  64. package/dist/core/src/cron/index.d.ts.map +0 -1
  65. package/dist/core/src/db/index.d.ts +0 -281
  66. package/dist/core/src/db/index.d.ts.map +0 -1
  67. package/dist/core/src/db/migrations/diff.d.ts +0 -5
  68. package/dist/core/src/db/migrations/diff.d.ts.map +0 -1
  69. package/dist/core/src/db/migrations/generator.d.ts +0 -26
  70. package/dist/core/src/db/migrations/generator.d.ts.map +0 -1
  71. package/dist/core/src/db/migrations/index.d.ts +0 -9
  72. package/dist/core/src/db/migrations/index.d.ts.map +0 -1
  73. package/dist/core/src/db/migrations/introspect.d.ts +0 -8
  74. package/dist/core/src/db/migrations/introspect.d.ts.map +0 -1
  75. package/dist/core/src/db/migrations/migrator.d.ts +0 -10
  76. package/dist/core/src/db/migrations/migrator.d.ts.map +0 -1
  77. package/dist/core/src/db/migrations/runner.d.ts +0 -7
  78. package/dist/core/src/db/migrations/runner.d.ts.map +0 -1
  79. package/dist/core/src/db/migrations/tracker.d.ts +0 -7
  80. package/dist/core/src/db/migrations/tracker.d.ts.map +0 -1
  81. package/dist/core/src/db/migrations/types.d.ts +0 -70
  82. package/dist/core/src/db/migrations/types.d.ts.map +0 -1
  83. package/dist/core/src/db/sql.d.ts +0 -148
  84. package/dist/core/src/db/sql.d.ts.map +0 -1
  85. package/dist/core/src/errors/index.d.ts +0 -30
  86. package/dist/core/src/errors/index.d.ts.map +0 -1
  87. package/dist/core/src/events/handler.d.ts +0 -42
  88. package/dist/core/src/events/handler.d.ts.map +0 -1
  89. package/dist/core/src/events/index.d.ts +0 -48
  90. package/dist/core/src/events/index.d.ts.map +0 -1
  91. package/dist/core/src/hooks/executor.d.ts +0 -20
  92. package/dist/core/src/hooks/executor.d.ts.map +0 -1
  93. package/dist/core/src/hooks/types.d.ts +0 -10
  94. package/dist/core/src/hooks/types.d.ts.map +0 -1
  95. package/dist/core/src/index.d.ts +0 -83
  96. package/dist/core/src/index.d.ts.map +0 -1
  97. package/dist/core/src/model/index.d.ts +0 -24
  98. package/dist/core/src/model/index.d.ts.map +0 -1
  99. package/dist/core/src/openapi/generator.d.ts +0 -58
  100. package/dist/core/src/openapi/generator.d.ts.map +0 -1
  101. package/dist/core/src/openapi/zod-to-schema.d.ts +0 -4
  102. package/dist/core/src/openapi/zod-to-schema.d.ts.map +0 -1
  103. package/dist/core/src/resource/errors.d.ts +0 -2
  104. package/dist/core/src/resource/errors.d.ts.map +0 -1
  105. package/dist/core/src/resource/index.d.ts +0 -98
  106. package/dist/core/src/resource/index.d.ts.map +0 -1
  107. package/dist/core/src/resource/zod-table.d.ts +0 -6
  108. package/dist/core/src/resource/zod-table.d.ts.map +0 -1
  109. package/dist/core/src/schema/audit.d.ts +0 -25
  110. package/dist/core/src/schema/audit.d.ts.map +0 -1
  111. package/dist/core/src/schema/column.d.ts +0 -31
  112. package/dist/core/src/schema/column.d.ts.map +0 -1
  113. package/dist/core/src/schema/table.d.ts +0 -68
  114. package/dist/core/src/schema/table.d.ts.map +0 -1
  115. package/dist/core/src/service/index.d.ts +0 -27
  116. package/dist/core/src/service/index.d.ts.map +0 -1
  117. package/dist/logger/src/colors.d.ts +0 -20
  118. package/dist/logger/src/colors.d.ts.map +0 -1
  119. package/dist/logger/src/formatter.d.ts +0 -3
  120. package/dist/logger/src/formatter.d.ts.map +0 -1
  121. package/dist/logger/src/index.d.ts +0 -11
  122. package/dist/logger/src/index.d.ts.map +0 -1
  123. package/dist/logger/src/masker.d.ts +0 -2
  124. package/dist/logger/src/masker.d.ts.map +0 -1
  125. package/dist/logger/src/plugin.d.ts +0 -6
  126. package/dist/logger/src/plugin.d.ts.map +0 -1
  127. package/dist/logger/src/tree.d.ts +0 -12
  128. package/dist/logger/src/tree.d.ts.map +0 -1
  129. package/dist/logger/src/types.d.ts +0 -17
  130. package/dist/logger/src/types.d.ts.map +0 -1
@@ -1,112 +0,0 @@
1
- import type { BaseCtx, Logger, BaseOptions } from './types';
2
- import type { VelnAdapter } from '../adapter/types';
3
- import type { HookExecutor } from '../hooks/executor';
4
- import type { EventBus } from '../events/index';
5
- import type { BoundVelnDB } from '../db/index';
6
- import type { VelnModule } from './module';
7
- import { type AdapterConfig } from '../adapter/resolve';
8
- /** A single navigation item contributed by a plugin via .nav(). */
9
- export interface NavItem {
10
- label: string;
11
- route: string;
12
- icon?: string;
13
- order?: number;
14
- children?: NavItem[];
15
- }
16
- export type ModulesInput<TCtx> = VelnModule[] | ((ctx: TCtx) => VelnModule[]);
17
- export interface Plugin<TCtx, TAdd extends object> {
18
- name: string;
19
- /**
20
- * Optional list of plugin names that must be registered before this plugin.
21
- * app.plugin() validates this at registration time and throws PLUGIN_MISSING_DEP
22
- * if a required plugin is not yet registered.
23
- *
24
- * Example: eventBusPlugin sets requires: ['db'] to enforce registration order.
25
- */
26
- requires?: string[];
27
- /**
28
- * Optional list of modules this plugin contributes.
29
- * app.plugin() calls app.register() on each entry automatically.
30
- *
31
- * Can also be set to a factory function for typed ctx inference (Option A, Spec 04).
32
- * The factory is called once with a dummy ctx to extract the module list —
33
- * it is NEVER called at request time.
34
- */
35
- modules?: VelnModule[];
36
- /**
37
- * Optional permission gate for all routes contributed via .modules().
38
- * app.plugin() checks ctx.user before running plugin.request() for those routes.
39
- * User must have at least one of the listed permissions — checked via AuthAdapter.hasPermission().
40
- * No user → 401. User without any matching permission → 403.
41
- */
42
- permissions?: string[];
43
- /**
44
- * Optional nav items contributed by this plugin.
45
- * GET /nav returns these filtered by the plugin's permissions for the current user.
46
- */
47
- nav?: NavItem[];
48
- install?: (hooks: HookExecutor) => Promise<void> | void;
49
- request: (ctx: TCtx) => Promise<TCtx & TAdd> | (TCtx & TAdd);
50
- teardown?: () => Promise<void> | void;
51
- }
52
- export declare class PluginBuilder<TAdd extends object> {
53
- private readonly _name;
54
- private _options;
55
- private _requires;
56
- private _modules;
57
- private _permissions;
58
- private _nav;
59
- constructor(_name: string);
60
- options(opts: BaseOptions): this;
61
- requires(deps: string[]): this;
62
- modules(input: ModulesInput<BaseCtx & TAdd>): this;
63
- permission(perm: string | string[]): this;
64
- nav(items: NavItem | NavItem[]): this;
65
- extend(fn: (ctx: BaseCtx) => Promise<TAdd> | TAdd): Plugin<BaseCtx, TAdd>;
66
- build(def: {
67
- install?: (hooks: HookExecutor) => Promise<void> | void;
68
- request: (ctx: BaseCtx) => Promise<TAdd> | TAdd;
69
- teardown?: () => Promise<void> | void;
70
- }): Plugin<BaseCtx, TAdd>;
71
- }
72
- /**
73
- * definePlugin — creates a named plugin that extends the request context.
74
- *
75
- * @param name Unique plugin name. Used for deduplication — a plugin with the same
76
- * name is installed at most once per app instance.
77
- *
78
- * @example
79
- * const tenantPlugin = definePlugin<{ tenantId: string }>('tenant')
80
- * .request((ctx) => ({ tenantId: ctx.req.headers.get('x-tenant-id') ?? 'default' }))
81
- * .build()
82
- * app.plugin(tenantPlugin)
83
- */
84
- export declare function definePlugin<TAdd extends object = object>(name: string): PluginBuilder<TAdd>;
85
- export declare function createPlugin<TAdd extends object>(name: string, definition: {
86
- install?: () => Promise<void> | void;
87
- request: (ctx: BaseCtx) => Promise<TAdd> | TAdd;
88
- teardown?: () => Promise<void> | void;
89
- }): () => Plugin<any, TAdd>;
90
- export declare function loggerPlugin<TCtx extends BaseCtx>(): Plugin<TCtx, {
91
- logger: Logger;
92
- }>;
93
- export declare function eventBusPlugin(bus?: EventBus): Plugin<any, {
94
- events: EventBus;
95
- }> & {
96
- bus: EventBus;
97
- };
98
- export type DbPluginConfig = AdapterConfig | VelnAdapter;
99
- export interface DbLogOptions {
100
- /** Whether query logging is enabled. Default: false. */
101
- enabled: boolean;
102
- /** Emit a warning for queries that exceed this threshold in milliseconds. */
103
- slowQueryMs?: number;
104
- /** Log level used for query logging. Default: 'debug'. */
105
- level?: 'debug' | 'info' | 'warn';
106
- /** Custom per-query callback. Receives the full QueryLogEntry for each query. */
107
- onQuery?: (entry: import('../adapter/types').QueryLogEntry) => void;
108
- }
109
- export declare function dbPlugin<TCtx extends BaseCtx>(config: DbPluginConfig, log?: DbLogOptions): Plugin<TCtx, {
110
- db: BoundVelnDB;
111
- }>;
112
- //# sourceMappingURL=plugin.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../../../core/src/app/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,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c,EACtB,GAAG,CAAC,EAAE,YAAY,GACjB,MAAM,CAAC,IAAI,EAAE;IAAE,EAAE,EAAE,WAAW,CAAA;CAAE,CAAC,CAgDnC"}
@@ -1,76 +0,0 @@
1
- import type { BaseCtx, OnRequestHook } from './types';
2
- export interface RateLimitStore {
3
- /**
4
- * Increment the counter for `key` within the given window.
5
- * Returns the new count and the timestamp (ms) when the window resets.
6
- * If the key is new or expired, the window starts fresh from now.
7
- */
8
- increment(key: string, windowMs: number): Promise<{
9
- count: number;
10
- resetAt: number;
11
- }>;
12
- /** Reset the counter for `key` immediately. */
13
- reset(key: string): Promise<void>;
14
- }
15
- export declare class InMemoryStore implements RateLimitStore {
16
- private readonly _map;
17
- private readonly _sweepEvery;
18
- private readonly _maxEntries;
19
- constructor(sweepEvery?: number, maxEntries?: number);
20
- increment(key: string, windowMs: number): Promise<{
21
- count: number;
22
- resetAt: number;
23
- }>;
24
- reset(key: string): Promise<void>;
25
- /** Evict all expired entries. Called automatically on a probabilistic basis
26
- * during increment(). Can also be called manually for eager cleanup. */
27
- cleanup(): void;
28
- private _sweep;
29
- private _evictOldest;
30
- }
31
- export interface RateLimitOptions {
32
- /** Maximum number of requests allowed per window. */
33
- max: number;
34
- /** Window duration in milliseconds. */
35
- windowMs: number;
36
- /** Store implementation. Defaults to InMemoryStore. */
37
- store?: RateLimitStore;
38
- /**
39
- * Extracts the rate-limit key from a request context.
40
- * When not specified, uses the default resolver which respects `trustProxy`.
41
- */
42
- keyResolver?: (ctx: BaseCtx) => string;
43
- /** Response message when limit is exceeded. Defaults to 'Too many requests'. */
44
- message?: string;
45
- /**
46
- * When true, the default keyResolver trusts the X-Forwarded-For header as the
47
- * real client IP. Only enable this if you are behind a trusted reverse proxy.
48
- * Default: false
49
- *
50
- * Without trustProxy, the default resolver uses x-real-ip or 'unknown'.
51
- *
52
- * trustProxy can also be an object for advanced configuration:
53
- * { strict: true } — returns 400 when the expected proxy header is missing,
54
- * instead of falling back to 'unknown'. Use this in security-critical deployments
55
- * where a missing header indicates a misconfigured proxy or direct client access.
56
- */
57
- trustProxy?: boolean | {
58
- strict: boolean;
59
- };
60
- }
61
- /**
62
- * rateLimitPlugin — sliding-window rate limiter.
63
- *
64
- * Returns an OnRequestHook — pass it to app.onRequest() or module.onRequest():
65
- * app.onRequest(rateLimitPlugin({ max: 100, windowMs: 60_000 }))
66
- *
67
- * When the limit is exceeded, returns a 429 response with:
68
- * - Retry-After: seconds until the window resets
69
- * - X-RateLimit-Limit: max
70
- * - X-RateLimit-Remaining: 0
71
- * - X-RateLimit-Reset: unix timestamp (seconds)
72
- *
73
- * Under the limit, the hook returns void — request continues normally.
74
- */
75
- export declare function rateLimitPlugin(options: RateLimitOptions): OnRequestHook;
76
- //# sourceMappingURL=rate-limit.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rate-limit.d.ts","sourceRoot":"","sources":["../../../../../core/src/app/rate-limit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAKrD,MAAM,WAAW,cAAc;IAC7B;;;;OAIG;IACH,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IACrF,+CAA+C;IAC/C,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAClC;AASD,qBAAa,aAAc,YAAW,cAAc;IAClD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA2B;IAKhD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAQ;IAKpC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAQ;gBAExB,UAAU,SAAM,EAAE,UAAU,SAAU;IAK5C,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAyBrF,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIvC;6EACyE;IACzE,OAAO,IAAI,IAAI;IAIf,OAAO,CAAC,MAAM;IAOd,OAAO,CAAC,YAAY;CAMrB;AAID,MAAM,WAAW,gBAAgB;IAC/B,qDAAqD;IACrD,GAAG,EAAE,MAAM,CAAA;IACX,uCAAuC;IACvC,QAAQ,EAAE,MAAM,CAAA;IAChB,uDAAuD;IACvD,KAAK,CAAC,EAAE,cAAc,CAAA;IACtB;;;OAGG;IACH,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,MAAM,CAAA;IACtC,gFAAgF;IAChF,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;;;;;;;;;;OAWG;IACH,UAAU,CAAC,EAAE,OAAO,GAAG;QAAE,MAAM,EAAE,OAAO,CAAA;KAAE,CAAA;CAC3C;AAID;;;;;;;;;;;;;GAaG;AAsBH,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,aAAa,CAoGxE"}
@@ -1,52 +0,0 @@
1
- import type { BaseCtx, OnRequestHook, OnResponseHook } from './types';
2
- export interface RequestIdOptions {
3
- /**
4
- * Name of the incoming request header to read an existing ID from.
5
- * If present and valid, the existing ID is reused (useful for distributed tracing).
6
- * Default: `'x-request-id'`
7
- */
8
- incomingHeader?: string;
9
- /**
10
- * Name of the response header to echo the request ID back to the client.
11
- * Default: `'x-request-id'`
12
- */
13
- responseHeader?: string;
14
- /**
15
- * Custom ID generator. Must return a non-empty string.
16
- * Default: 16 random hex bytes (128 bits, UUID-compatible entropy)
17
- */
18
- generator?: () => string;
19
- }
20
- /** Context extension added by requestIdPlugin. Available after onRequest. */
21
- export interface RequestIdCtx {
22
- /** Unique ID for this request. Set before any route handler runs. */
23
- requestId: string;
24
- }
25
- export interface RequestIdPlugin {
26
- /**
27
- * Register on `app.onRequest()`.
28
- * Assigns `ctx.requestId` — available in all subsequent lifecycle phases.
29
- */
30
- onRequest: OnRequestHook<BaseCtx & RequestIdCtx>;
31
- /**
32
- * Register on `app.onResponse()`.
33
- * Echoes the request ID back in the response header.
34
- */
35
- onResponse: OnResponseHook<BaseCtx & RequestIdCtx>;
36
- }
37
- /**
38
- * requestIdPlugin — assigns a unique ID to every request and echoes it back.
39
- *
40
- * Usage:
41
- * const rid = requestIdPlugin()
42
- * app.onRequest(rid.onRequest)
43
- * app.onResponse(rid.onResponse)
44
- *
45
- * After registration, `ctx.requestId` is available in all handlers, guards,
46
- * and lifecycle hooks. The ID is echoed back in the `x-request-id` response header.
47
- *
48
- * Reuses an existing `x-request-id` header if it passes a safe-characters check,
49
- * enabling distributed tracing across services.
50
- */
51
- export declare function requestIdPlugin(options?: RequestIdOptions): RequestIdPlugin;
52
- //# sourceMappingURL=request-id.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"request-id.d.ts","sourceRoot":"","sources":["../../../../../core/src/app/request-id.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAKrE,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IAEvB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IAEvB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,MAAM,CAAA;CACzB;AAID,6EAA6E;AAC7E,MAAM,WAAW,YAAY;IAC3B,qEAAqE;IACrE,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,SAAS,EAAE,aAAa,CAAC,OAAO,GAAG,YAAY,CAAC,CAAA;IAChD;;;OAGG;IACH,UAAU,EAAE,cAAc,CAAC,OAAO,GAAG,YAAY,CAAC,CAAA;CACnD;AAiBD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAAC,OAAO,GAAE,gBAAqB,GAAG,eAAe,CAkB/E"}
@@ -1,6 +0,0 @@
1
- export interface MatchResult {
2
- params: Record<string, string | undefined>;
3
- }
4
- export declare function matchPath(pattern: string, pathname: string): MatchResult | null;
5
- export declare function parseQuery(search: string): Record<string, string | string[]>;
6
- //# sourceMappingURL=router.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../../../../core/src/app/router.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;CAC3C;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAiD/E;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAc5E"}
@@ -1,40 +0,0 @@
1
- import type { VelnModule } from './module';
2
- import type { Route } from './types';
3
- export interface ScalarOptions {
4
- /** Mount path for the Scalar UI. Default: '/scalar' */
5
- path?: string;
6
- /** API title shown in the Scalar UI. Default: 'Veln API' */
7
- title?: string;
8
- /** API version shown in the OpenAPI spec. Default: '1.0.0' */
9
- version?: string;
10
- /** Optional API description shown in the OpenAPI spec info block. Markdown supported. */
11
- description?: string;
12
- /** Scalar UI theme. Default: 'purple' */
13
- theme?: string;
14
- /**
15
- * Cache the generated OpenAPI spec after the first request.
16
- * Default: false — spec is regenerated on every request (safe for development).
17
- * Set to true in production to avoid repeated traversal of app.routes.
18
- */
19
- cache?: boolean;
20
- }
21
- interface AppRef {
22
- routes: Route<unknown>[];
23
- }
24
- /**
25
- * scalarPlugin — mounts a Scalar API reference UI and an OpenAPI JSON endpoint.
26
- *
27
- * Usage:
28
- * app.register(scalarPlugin(app))
29
- * app.register(scalarPlugin(app, { path: '/docs', title: 'My API', theme: 'blue' }))
30
- *
31
- * Registers two routes (both hidden from the OpenAPI spec itself):
32
- * GET {path} → Scalar UI (HTML, CDN-loaded)
33
- * GET {path}/openapi.json → Raw OpenAPI 3.1 JSON
34
- *
35
- * The app reference is captured by closure so the spec always reflects
36
- * the current route list at request time — including late-registered modules.
37
- */
38
- export declare function scalarPlugin(app: AppRef, options?: ScalarOptions): VelnModule;
39
- export {};
40
- //# sourceMappingURL=scalar.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"scalar.d.ts","sourceRoot":"","sources":["../../../../../core/src/app/scalar.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAC1C,OAAO,KAAK,EAAE,KAAK,EAAW,MAAM,SAAS,CAAA;AAK7C,MAAM,WAAW,aAAa;IAC5B,uDAAuD;IACvD,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,4DAA4D;IAC5D,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,8DAA8D;IAC9D,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,yFAAyF;IACzF,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,yCAAyC;IACzC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;;OAIG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAID,UAAU,MAAM;IACd,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,EAAE,CAAA;CACzB;AAwBD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,UAAU,CAgFjF"}
@@ -1,48 +0,0 @@
1
- import type { OnResponseHook } from './types';
2
- /**
3
- * CSP preset values for `contentSecurityPolicy`.
4
- *
5
- * - `'strict'` — no unsafe-inline; suitable for APIs and security-critical apps.
6
- * - `'relaxed'` — allows unsafe-inline scripts/styles; suitable for dashboards and SSR (default).
7
- * - `false` — omits the Content-Security-Policy header entirely.
8
- * - `string` — passed through as the raw header value.
9
- */
10
- export type CspPreset = 'strict' | 'relaxed' | false | string;
11
- export interface SecureHeadersOptions {
12
- /** Strict-Transport-Security — default: 'max-age=15552000; includeSubDomains' */
13
- strictTransportSecurity?: string | false;
14
- /** X-Content-Type-Options — default: 'nosniff' */
15
- xContentTypeOptions?: string | false;
16
- /** X-Frame-Options — default: 'SAMEORIGIN' */
17
- xFrameOptions?: string | false;
18
- /** X-XSS-Protection — default: '0' (modern recommendation: rely on CSP instead) */
19
- xXssProtection?: string | false;
20
- /** Referrer-Policy — default: 'strict-origin-when-cross-origin' */
21
- referrerPolicy?: string | false;
22
- /** Permissions-Policy — default: 'camera=(), microphone=(), geolocation=()' */
23
- permissionsPolicy?: string | false;
24
- /**
25
- * Content-Security-Policy — accepts a preset or a raw header string.
26
- *
27
- * - `'relaxed'` (default) — allows unsafe-inline scripts/styles.
28
- * - `'strict'` — no unsafe-inline; for APIs and security-critical apps.
29
- * - `false` — omit header entirely.
30
- * - custom string — used as-is.
31
- */
32
- contentSecurityPolicy?: CspPreset;
33
- }
34
- /**
35
- * secureHeadersPlugin — adds security response headers to every response.
36
- *
37
- * Returns an OnResponseHook — pass it to app.onResponse():
38
- * app.onResponse(secureHeadersPlugin())
39
- * app.onResponse(secureHeadersPlugin({ xFrameOptions: 'DENY', contentSecurityPolicy: 'strict' }))
40
- *
41
- * Each option defaults to a secure value. Pass `false` to omit that header entirely.
42
- * Pass a custom string to override the default value.
43
- * `contentSecurityPolicy` also accepts `'strict'` (no unsafe-inline) or `'relaxed'` (default).
44
- *
45
- * Header resolution runs once at call time — zero overhead per request.
46
- */
47
- export declare function secureHeadersPlugin(options?: SecureHeadersOptions): OnResponseHook;
48
- //# sourceMappingURL=secure-headers.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"secure-headers.d.ts","sourceRoot":"","sources":["../../../../../core/src/app/secure-headers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAG7C;;;;;;;GAOG;AACH,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,SAAS,GAAG,KAAK,GAAG,MAAM,CAAA;AAE7D,MAAM,WAAW,oBAAoB;IACnC,iFAAiF;IACjF,uBAAuB,CAAC,EAAE,MAAM,GAAG,KAAK,CAAA;IACxC,kDAAkD;IAClD,mBAAmB,CAAC,EAAM,MAAM,GAAG,KAAK,CAAA;IACxC,8CAA8C;IAC9C,aAAa,CAAC,EAAY,MAAM,GAAG,KAAK,CAAA;IACxC,mFAAmF;IACnF,cAAc,CAAC,EAAW,MAAM,GAAG,KAAK,CAAA;IACxC,mEAAmE;IACnE,cAAc,CAAC,EAAW,MAAM,GAAG,KAAK,CAAA;IACxC,+EAA+E;IAC/E,iBAAiB,CAAC,EAAQ,MAAM,GAAG,KAAK,CAAA;IACxC;;;;;;;OAOG;IACH,qBAAqB,CAAC,EAAI,SAAS,CAAA;CACpC;AA8BD;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,oBAAyB,GAAG,cAAc,CAiCtF"}
@@ -1,3 +0,0 @@
1
- import type { BaseCtx } from './types';
2
- export declare function createSystemCtx<TExtra extends object = Record<never, never>>(extra?: TExtra): BaseCtx & TExtra;
3
- //# sourceMappingURL=system-ctx.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"system-ctx.d.ts","sourceRoot":"","sources":["../../../../../core/src/app/system-ctx.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AA8BtC,wBAAgB,eAAe,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EAC1E,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,GAAG,MAAM,CAwBlB"}
@@ -1,277 +0,0 @@
1
- import type { EventBus, VelnEvents } from '../events/index';
2
- import type { BoundVelnDB } from '../db/index';
3
- import type { ZodTypeAny, ZodIssue } from 'zod';
4
- import { VelnError } from '../errors/index';
5
- export interface VelnWsAdapter {
6
- /** Called in fetch() when an HTTP Upgrade: websocket request arrives. */
7
- handleUpgrade(req: Request, server: import('bun').Server<unknown>, baseCtx: BaseCtx, plugins: ReadonlyArray<import('./plugin').Plugin<any, any>>, installedPlugins: {
8
- value: boolean;
9
- }, installedModulePlugins: Set<string>): Promise<Response | null>;
10
- /** Returns the Bun websocket handler config. Passed to Bun.serve(). */
11
- getWebsocketConfig(): import('bun').WebSocketHandler<Record<string, unknown>>;
12
- /** Registers a WS route. Called from app.ws() and app.register(). */
13
- registerRoute(path: string, route: WsRouteShape): void;
14
- /** Reads all registered WS routes — used by module registration. */
15
- getRoute(path: string): WsRouteShape | undefined;
16
- }
17
- /** Minimal WS route shape that Core knows about. Full type lives in @veln/ws. */
18
- export interface WsRouteShape {
19
- path: string;
20
- _module: unknown | null;
21
- [key: string]: unknown;
22
- }
23
- export interface AuthPayload {
24
- sub?: string;
25
- iat?: number;
26
- exp?: number;
27
- nbf?: number;
28
- aud?: string | string[];
29
- iss?: string;
30
- jti?: string;
31
- [key: string]: unknown;
32
- }
33
- export type RouteKey = `${'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'} /${string}`;
34
- export interface RouteEntry {
35
- params?: ZodTypeAny;
36
- query?: ZodTypeAny;
37
- body?: ZodTypeAny;
38
- response?: ZodTypeAny;
39
- readonly _prefix?: string;
40
- }
41
- export type RouteMap = Record<RouteKey, RouteEntry>;
42
- export declare class ValidationError extends VelnError {
43
- readonly issues: ZodIssue[];
44
- constructor(zodError: import('zod').ZodError);
45
- }
46
- export interface RouteSchema {
47
- params?: ZodTypeAny;
48
- query?: ZodTypeAny;
49
- body?: ZodTypeAny;
50
- response?: ZodTypeAny;
51
- }
52
- /** Additional response code definition for OpenAPI docs (e.g. 401, 404). */
53
- export interface RouteResponseDoc {
54
- description: string;
55
- }
56
- export interface RouteDocs {
57
- /** Human-readable route summary shown in Scalar / Swagger UI. Auto-generated if absent. */
58
- summary?: string;
59
- /** Longer description rendered below the summary. Markdown supported. */
60
- description?: string;
61
- /** Unique operationId. Auto-generated if absent (e.g. "listUsers", "getUserById"). */
62
- operationId?: string;
63
- /**
64
- * Additional HTTP response codes to document in the OpenAPI spec.
65
- * The 200 success response is always generated automatically.
66
- * Use this to document error responses like 401, 403, 404, 422, etc.
67
- *
68
- * @example
69
- * docs: {
70
- * responses: {
71
- * 401: { description: 'Unauthorized' },
72
- * 404: { description: 'Not found' },
73
- * }
74
- * }
75
- */
76
- responses?: Record<number, RouteResponseDoc>;
77
- }
78
- export type InferCtx<TCtx, S extends RouteSchema> = Omit<TCtx, 'params' | 'query'> & {
79
- params: S['params'] extends ZodTypeAny ? import('zod').infer<S['params']> : Record<string, string>;
80
- query: S['query'] extends ZodTypeAny ? import('zod').infer<S['query']> : Record<string, string | string[]>;
81
- body: S['body'] extends ZodTypeAny ? import('zod').infer<S['body']> : unknown;
82
- };
83
- export interface RouteHandlerWithSchema<TCtx, S extends RouteSchema> {
84
- params?: S['params'];
85
- query?: S['query'];
86
- body?: S['body'];
87
- response?: S['response'];
88
- /** Optional OpenAPI documentation override for this route. */
89
- docs?: RouteDocs;
90
- /** Optional route-level guard — runs before the handler. Use `false` to opt out of a module-level guard. */
91
- guard?: Guard<TCtx> | false;
92
- handler: (ctx: InferCtx<TCtx, S>) => Response | Promise<Response>;
93
- }
94
- /** Controls a streaming response. Passed to the ctx.stream() writer callback. */
95
- export interface StreamController {
96
- /** Push a string or binary chunk to the stream. */
97
- send(chunk: string | Uint8Array): void;
98
- /** Close the stream. Must be called to end the response. */
99
- close(): void;
100
- }
101
- /** Options for ctx.stream(). */
102
- export interface StreamOptions {
103
- /**
104
- * Content-Type header for the streaming response.
105
- * Defaults to `'text/plain'`.
106
- * Use `'text/event-stream'` for SSE, `'application/x-ndjson'` for NDJSON.
107
- */
108
- contentType?: string;
109
- /** Additional headers to include in the response. */
110
- headers?: Record<string, string>;
111
- /** HTTP status code. Defaults to 200. */
112
- status?: number;
113
- }
114
- /**
115
- * Controls a Server-Sent Events stream.
116
- * Passed to the ctx.sse() writer callback.
117
- *
118
- * SSE wire format:
119
- * event: <name>\ndata: <json>\n\n — named event
120
- * data: <json>\n\n — unnamed event
121
- * : <text>\n\n — comment / keepalive
122
- * id: <value>\n — event ID for reconnect
123
- * retry: <ms>\n — reconnect interval
124
- */
125
- export interface SseController {
126
- /** Send a named event with a JSON-serializable payload. */
127
- event(name: string, data: unknown): Promise<void>;
128
- /** Send an unnamed data event. */
129
- data(data: unknown): Promise<void>;
130
- /** Send an SSE comment (e.g. keepalive ping). */
131
- comment(text?: string): Promise<void>;
132
- /** Set the last event ID (used by the browser for reconnect). */
133
- id(id: string): Promise<void>;
134
- /** Tell the browser how long to wait before reconnecting (milliseconds). */
135
- retry(ms: number): Promise<void>;
136
- }
137
- export interface Logger {
138
- info(msg: string, ...args: unknown[]): void;
139
- warn(msg: string, ...args: unknown[]): void;
140
- error(msg: string, ...args: unknown[]): void;
141
- debug(msg: string, ...args: unknown[]): void;
142
- }
143
- export interface LogOptions {
144
- /** Minimum level to emit. Defaults to 'info'. */
145
- level?: 'debug' | 'info' | 'warn' | 'error';
146
- /** Keys whose values are replaced with '***' in structured data. Case-insensitive. */
147
- mask?: string[];
148
- /** Suppress all output — useful in tests. */
149
- silent?: boolean;
150
- }
151
- export interface BaseOptions {
152
- log?: LogOptions;
153
- }
154
- export interface AuthUser {
155
- id: string;
156
- permissions: string[];
157
- }
158
- export interface AuthAdapter {
159
- getUser(ctx: BaseCtx): Promise<AuthUser | null>;
160
- hasPermission(user: AuthUser, permission: string): boolean;
161
- }
162
- export interface BaseCtx {
163
- req: Request;
164
- params: Record<string, string>;
165
- query: Record<string, string | string[]>;
166
- body?: unknown;
167
- json: <T>(data: T, status?: number) => Response;
168
- text: (data: string, status?: number) => Response;
169
- html: (data: string, status?: number) => Response;
170
- /**
171
- * Returns a streaming Response backed by a ReadableStream.
172
- *
173
- * The callback receives a StreamController — call `send(chunk)` to push data
174
- * and `close()` to end the stream. Errors thrown inside are caught automatically.
175
- *
176
- * Set `contentType` for SSE (`'text/event-stream'`) or NDJSON (`'application/x-ndjson'`).
177
- * Compression is automatically skipped for streaming responses.
178
- *
179
- * @example
180
- * return ctx.stream((stream) => {
181
- * stream.send('data: hello\n\n')
182
- * stream.send('data: world\n\n')
183
- * stream.close()
184
- * }, { contentType: 'text/event-stream' })
185
- */
186
- stream: (writer: (controller: StreamController) => void | Promise<void>, options?: StreamOptions) => Response;
187
- /**
188
- * Returns a Server-Sent Events Response.
189
- *
190
- * The callback receives an SseController — call `event()`, `data()`,
191
- * `comment()`, `id()`, or `retry()` to push SSE frames, then let the
192
- * callback return (or the async iterator complete) to close the stream.
193
- *
194
- * @example
195
- * return ctx.sse(async (sse) => {
196
- * await sse.event('connected', { userId: '42' })
197
- * for await (const update of source()) {
198
- * await sse.event('update', update)
199
- * await sse.comment('keepalive')
200
- * }
201
- * })
202
- */
203
- sse: (writer: (controller: SseController) => void | Promise<void>) => Response;
204
- events?: EventBus;
205
- logger?: Logger;
206
- db?: BoundVelnDB;
207
- cookie: import('./cookies').CookieJar;
208
- emit: <K extends keyof VelnEvents>(event: K, payload: VelnEvents[K]) => void;
209
- _requestQueue?: import('../events/index').RequestEventQueue;
210
- _queryLog?: import('../db/index').QueryLog;
211
- _startTime?: number;
212
- }
213
- export type Guard<TCtx> = (ctx: TCtx) => Response | null | Promise<Response | null>;
214
- export declare function createGuard<TAdd extends object = object>(fn: (ctx: BaseCtx & TAdd) => Response | null | Promise<Response | null>): Guard<BaseCtx & TAdd>;
215
- /**
216
- * defineGuard — creates a named guard that protects routes or modules.
217
- *
218
- * Call `.check(fn)` to seal into a `Guard`. Throw any error or return a `Response`
219
- * inside `fn` to block the request; return normally to allow it through.
220
- *
221
- * @param name Used in log output for tracing which guard triggered.
222
- *
223
- * @example
224
- * const authGuard = defineGuard('auth')
225
- * .check<{ user: AuthUser }>((ctx) => {
226
- * if (!ctx.user) throw new UnauthorizedError()
227
- * })
228
- */
229
- declare class GuardBuilder {
230
- private readonly _name;
231
- private _options;
232
- constructor(_name: string);
233
- options(opts: BaseOptions): this;
234
- check<TAdd extends object = object>(fn: (ctx: BaseCtx & TAdd) => void | Promise<void>): Guard<BaseCtx & TAdd>;
235
- }
236
- /** @see GuardBuilder */
237
- export declare function defineGuard(name: string): GuardBuilder;
238
- export type ErrorHandler<TCtx = BaseCtx> = (err: unknown, ctx: TCtx) => Response | Promise<Response>;
239
- export interface RouteHandler<TCtx> {
240
- handler: (ctx: TCtx) => Response | Promise<Response>;
241
- }
242
- export type OnRequestFn<TCtx extends BaseCtx = BaseCtx> = (ctx: TCtx) => Response | void | Promise<Response | void>;
243
- export type OnBeforeHandleFn<TCtx extends BaseCtx = BaseCtx> = (ctx: TCtx) => Response | void | Promise<Response | void>;
244
- export type OnResponseFn<TCtx extends BaseCtx = BaseCtx> = (ctx: TCtx, response: Response) => Response | void | Promise<Response | void>;
245
- export interface OnRequestHook<TCtx extends BaseCtx = BaseCtx> {
246
- readonly _phase: 'onRequest';
247
- readonly _fn: OnRequestFn<TCtx>;
248
- }
249
- export interface OnBeforeHandleHook<TCtx extends BaseCtx = BaseCtx> {
250
- readonly _phase: 'onBeforeHandle';
251
- readonly _fn: OnBeforeHandleFn<TCtx>;
252
- }
253
- export interface OnResponseHook<TCtx extends BaseCtx = BaseCtx> {
254
- readonly _phase: 'onResponse';
255
- readonly _fn: OnResponseFn<TCtx>;
256
- }
257
- export declare function createOnRequest<TAdd extends object = object>(fn: OnRequestFn<BaseCtx & TAdd>): OnRequestHook<BaseCtx & TAdd>;
258
- export declare function createOnBeforeHandle<TAdd extends object = object>(fn: OnBeforeHandleFn<BaseCtx & TAdd>): OnBeforeHandleHook<BaseCtx & TAdd>;
259
- export declare function createOnResponse<TAdd extends object = object>(fn: OnResponseFn<BaseCtx & TAdd>): OnResponseHook<BaseCtx & TAdd>;
260
- export interface Route<TCtx = BaseCtx> {
261
- method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
262
- path: string;
263
- summary?: string;
264
- description?: string;
265
- /** OpenAPI documentation override set via the `docs` option on route registration. */
266
- docs?: RouteDocs;
267
- handler: RouteHandler<TCtx>;
268
- guards: Guard<TCtx>[];
269
- onError?: ErrorHandler<TCtx>;
270
- schema?: RouteSchema;
271
- visibility?: 'public' | 'hidden';
272
- moduleGuardOptOut?: true;
273
- _module?: import('./module').VelnModule;
274
- _pluginName?: string;
275
- }
276
- export {};
277
- //# sourceMappingURL=types.d.ts.map