burger-api 0.9.7 → 1.0.0-beta

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 (175) hide show
  1. package/README.md +84 -241
  2. package/dist/src/adapter/bun/index.d.ts +14 -0
  3. package/dist/src/adapter/bun/index.js +73 -0
  4. package/dist/src/adapter/bun/types.d.ts +15 -0
  5. package/dist/src/adapter/bun/types.js +1 -0
  6. package/dist/src/adapter/index.d.ts +1 -0
  7. package/dist/src/adapter/index.js +1 -0
  8. package/dist/src/adapter/types.d.ts +49 -0
  9. package/dist/src/adapter/types.js +1 -0
  10. package/dist/src/adapter/web-standard/fetch-handler.d.ts +39 -0
  11. package/dist/src/adapter/web-standard/fetch-handler.js +54 -0
  12. package/dist/src/adapter/web-standard/index.d.ts +8 -0
  13. package/dist/src/adapter/web-standard/index.js +7 -0
  14. package/dist/src/analysis/route-access-analyzer.d.ts +10 -0
  15. package/dist/src/analysis/route-access-analyzer.js +287 -0
  16. package/dist/src/chain/chain.d.ts +16 -0
  17. package/dist/src/chain/chain.js +17 -0
  18. package/dist/src/chain/flattener.d.ts +3 -0
  19. package/dist/src/chain/flattener.js +78 -0
  20. package/dist/src/chain/node.d.ts +25 -0
  21. package/dist/src/chain/node.js +1 -0
  22. package/dist/src/compiler/conventions.d.ts +67 -0
  23. package/dist/src/compiler/conventions.js +129 -0
  24. package/dist/src/compiler/index.d.ts +13 -0
  25. package/dist/src/compiler/index.js +11 -0
  26. package/dist/src/compiler/module-loader.d.ts +75 -0
  27. package/dist/src/compiler/module-loader.js +276 -0
  28. package/dist/src/compiler/route-module.d.ts +97 -0
  29. package/dist/src/compiler/route-module.js +1 -0
  30. package/dist/src/compiler/route-tree.d.ts +19 -0
  31. package/dist/src/compiler/route-tree.js +28 -0
  32. package/dist/src/compiler/scanner.d.ts +42 -0
  33. package/dist/src/compiler/scanner.js +201 -0
  34. package/dist/src/context/context-set.d.ts +26 -0
  35. package/dist/src/context/context-set.js +45 -0
  36. package/dist/src/context/context.d.ts +357 -0
  37. package/dist/src/context/context.js +401 -0
  38. package/dist/src/context/query-parser.d.ts +23 -0
  39. package/dist/src/context/query-parser.js +132 -0
  40. package/dist/src/context/route-access.d.ts +7 -0
  41. package/dist/src/context/route-access.js +18 -0
  42. package/dist/src/context/types.d.ts +62 -0
  43. package/dist/src/context/types.js +5 -0
  44. package/dist/src/core/asset-mime.d.ts +9 -0
  45. package/dist/src/core/asset-mime.js +35 -0
  46. package/dist/src/core/assets.d.ts +30 -0
  47. package/dist/src/core/assets.js +67 -0
  48. package/dist/src/core/docs-providers.d.ts +13 -0
  49. package/dist/src/core/docs-providers.js +89 -0
  50. package/dist/src/core/embedded-assets.d.ts +18 -0
  51. package/dist/src/core/embedded-assets.js +13 -0
  52. package/dist/src/core/openapi.d.ts +9 -10
  53. package/dist/src/core/openapi.js +333 -127
  54. package/dist/src/core/page-router.d.ts +13 -17
  55. package/dist/src/core/page-router.js +86 -55
  56. package/dist/src/core/server.d.ts +20 -11
  57. package/dist/src/core/server.js +41 -45
  58. package/dist/src/errors/forbidden.d.ts +14 -0
  59. package/dist/src/errors/forbidden.js +16 -0
  60. package/dist/src/errors/http-error.d.ts +47 -0
  61. package/dist/src/errors/http-error.js +146 -0
  62. package/dist/src/errors/method-not-allowed.d.ts +13 -0
  63. package/dist/src/errors/method-not-allowed.js +15 -0
  64. package/dist/src/errors/not-found.d.ts +14 -0
  65. package/dist/src/errors/not-found.js +16 -0
  66. package/dist/src/errors/unauthorized.d.ts +14 -0
  67. package/dist/src/errors/unauthorized.js +16 -0
  68. package/dist/src/index.d.ts +263 -50
  69. package/dist/src/index.js +919 -332
  70. package/dist/src/lifecycle/executor.d.ts +64 -0
  71. package/dist/src/lifecycle/executor.js +201 -0
  72. package/dist/src/lifecycle/hook-runner.d.ts +11 -0
  73. package/dist/src/lifecycle/hook-runner.js +156 -0
  74. package/dist/src/lifecycle/jit.d.ts +50 -0
  75. package/dist/src/lifecycle/jit.js +258 -0
  76. package/dist/src/lifecycle/transform.d.ts +26 -0
  77. package/dist/src/lifecycle/transform.js +99 -0
  78. package/dist/src/lifecycle/types.d.ts +135 -0
  79. package/dist/src/lifecycle/types.js +1 -0
  80. package/dist/src/plugin/composer.d.ts +3 -0
  81. package/dist/src/plugin/composer.js +28 -0
  82. package/dist/src/plugin/registry.d.ts +25 -0
  83. package/dist/src/plugin/registry.js +107 -0
  84. package/dist/src/plugin/types.d.ts +20 -0
  85. package/dist/src/plugin/types.js +1 -0
  86. package/dist/src/router/allow-cache.d.ts +20 -0
  87. package/dist/src/router/allow-cache.js +26 -0
  88. package/dist/src/router/compiler.d.ts +39 -0
  89. package/dist/src/router/compiler.js +817 -0
  90. package/dist/src/router/define.d.ts +67 -0
  91. package/dist/src/router/define.js +34 -0
  92. package/dist/src/router/index.d.ts +6 -0
  93. package/dist/src/router/index.js +5 -0
  94. package/dist/src/router/param-extract.d.ts +33 -0
  95. package/dist/src/router/param-extract.js +87 -0
  96. package/dist/src/router/regex-matcher.d.ts +42 -0
  97. package/dist/src/router/regex-matcher.js +216 -0
  98. package/dist/src/router/router.d.ts +201 -0
  99. package/dist/src/router/router.js +600 -0
  100. package/dist/src/router/static-map.d.ts +39 -0
  101. package/dist/src/router/static-map.js +48 -0
  102. package/dist/src/router/trie.d.ts +69 -0
  103. package/dist/src/router/trie.js +572 -0
  104. package/dist/src/router/types.d.ts +104 -0
  105. package/dist/src/router/types.js +1 -0
  106. package/dist/src/runtime/capabilities.d.ts +29 -0
  107. package/dist/src/runtime/capabilities.js +48 -0
  108. package/dist/src/types/index.d.ts +260 -109
  109. package/dist/src/types/index.js +1 -1
  110. package/dist/src/types/inference.d.ts +78 -0
  111. package/dist/src/types/inference.js +20 -0
  112. package/dist/src/types/openapi-config.d.ts +164 -0
  113. package/dist/src/types/openapi-config.js +8 -0
  114. package/dist/src/utils/env.d.ts +13 -0
  115. package/dist/src/utils/env.js +24 -0
  116. package/dist/src/utils/fs.d.ts +29 -0
  117. package/dist/src/utils/fs.js +75 -0
  118. package/dist/src/utils/index.d.ts +1 -1
  119. package/dist/src/utils/index.js +2 -2
  120. package/dist/src/utils/pathConversion.js +13 -7
  121. package/dist/src/utils/response.d.ts +42 -6
  122. package/dist/src/utils/response.js +172 -7
  123. package/dist/src/utils/routing.d.ts +32 -13
  124. package/dist/src/utils/routing.js +41 -18
  125. package/dist/src/utils/thenable.d.ts +8 -0
  126. package/dist/src/utils/thenable.js +12 -0
  127. package/dist/src/utils/timing-safe.d.ts +9 -0
  128. package/dist/src/utils/timing-safe.js +20 -0
  129. package/dist/src/utils/wildcard.d.ts +2 -9
  130. package/dist/src/utils/wildcard.js +20 -58
  131. package/dist/src/validation/adapter.d.ts +54 -0
  132. package/dist/src/validation/adapter.js +75 -0
  133. package/dist/src/validation/adapters/standard.d.ts +11 -0
  134. package/dist/src/validation/adapters/standard.js +110 -0
  135. package/dist/src/validation/adapters/zod.d.ts +9 -0
  136. package/dist/src/validation/adapters/zod.js +128 -0
  137. package/dist/src/validation/cache.d.ts +26 -0
  138. package/dist/src/validation/cache.js +35 -0
  139. package/dist/src/validation/coerce.d.ts +28 -0
  140. package/dist/src/validation/coerce.js +176 -0
  141. package/dist/src/validation/compiler.d.ts +27 -0
  142. package/dist/src/validation/compiler.js +191 -0
  143. package/dist/src/validation/error.d.ts +69 -0
  144. package/dist/src/validation/error.js +137 -0
  145. package/dist/src/validation/index.d.ts +16 -0
  146. package/dist/src/validation/index.js +12 -0
  147. package/dist/src/validation/response.d.ts +25 -0
  148. package/dist/src/validation/response.js +79 -0
  149. package/dist/src/validation/types.d.ts +148 -0
  150. package/dist/src/validation/types.js +6 -0
  151. package/dist/src/validation/validator.d.ts +39 -0
  152. package/dist/src/validation/validator.js +441 -0
  153. package/dist/src/ws/adapter.d.ts +219 -0
  154. package/dist/src/ws/adapter.js +623 -0
  155. package/dist/src/ws/compiler.d.ts +37 -0
  156. package/dist/src/ws/compiler.js +156 -0
  157. package/dist/src/ws/index.d.ts +11 -0
  158. package/dist/src/ws/index.js +8 -0
  159. package/dist/src/ws/platform.d.ts +81 -0
  160. package/dist/src/ws/platform.js +113 -0
  161. package/dist/src/ws/router.d.ts +48 -0
  162. package/dist/src/ws/router.js +174 -0
  163. package/dist/src/ws/scanner.d.ts +97 -0
  164. package/dist/src/ws/scanner.js +193 -0
  165. package/dist/src/ws/types.d.ts +380 -0
  166. package/dist/src/ws/types.js +213 -0
  167. package/package.json +72 -60
  168. package/dist/src/core/api-router.d.ts +0 -65
  169. package/dist/src/core/api-router.js +0 -264
  170. package/dist/src/core/swagger-ui.d.ts +0 -1
  171. package/dist/src/core/swagger-ui.js +0 -33
  172. package/dist/src/middleware/validator.d.ts +0 -14
  173. package/dist/src/middleware/validator.js +0 -133
  174. package/dist/src/utils/error.d.ts +0 -17
  175. package/dist/src/utils/error.js +0 -63
@@ -0,0 +1,193 @@
1
+ /**
2
+ * Scans a directory tree for WebSocket convention files.
3
+ */
4
+ import { readdir } from 'node:fs/promises';
5
+ import * as path from 'node:path';
6
+ import { resolveScanDir } from '../utils/fs.js';
7
+ import { splitConventionName, } from '../compiler/conventions.js';
8
+ /** WebSocket convention stems (extension is `.ts` / `.js` / `.mjs`). */
9
+ const WS_CONVENTION_FILES = ['ws', 'hooks', 'config'];
10
+ /**
11
+ * WebSocket directory scanner
12
+ */
13
+ export class WebSocketScanner {
14
+ wsDir;
15
+ prefix;
16
+ constructor(wsDir, prefix = '') {
17
+ this.wsDir = wsDir;
18
+ this.prefix = prefix;
19
+ if (!wsDir) {
20
+ throw new Error('WebSocket directory path is required');
21
+ }
22
+ this.wsDir = resolveScanDir(wsDir, 'WebSocket', 'wsDir');
23
+ }
24
+ /**
25
+ * Scans the WebSocket directory tree and returns scanned routes
26
+ */
27
+ async scan() {
28
+ const routes = [];
29
+ await this.walk(this.wsDir, routes);
30
+ // Detect global hooks at the parent directory
31
+ let globalHooks;
32
+ const parentDir = path.dirname(this.wsDir);
33
+ let rootEntries = [];
34
+ try {
35
+ rootEntries = await readdir(parentDir, {
36
+ withFileTypes: true,
37
+ });
38
+ }
39
+ catch {
40
+ // Parent directory may not exist
41
+ }
42
+ for (const entry of rootEntries) {
43
+ if (!entry.isFile())
44
+ continue;
45
+ const split = splitConventionName(entry.name);
46
+ if (!split || split.stem !== 'hooks')
47
+ continue;
48
+ if (globalHooks) {
49
+ throw new Error(`Conflicting app-level hooks files "${globalHooks}" and "${path.join(parentDir, entry.name)}" — ` +
50
+ `use only one of .ts/.js/.mjs.`);
51
+ }
52
+ globalHooks = path.resolve(path.join(parentDir, entry.name));
53
+ }
54
+ return { routes, globalHooks };
55
+ }
56
+ /**
57
+ * Recursively walks the directory, emitting a route per ws file found.
58
+ */
59
+ async walk(dir, out) {
60
+ let dynamicFolderFound = false;
61
+ let wildcardFolderFound = false;
62
+ const entries = await readdir(dir, { withFileTypes: true });
63
+ const subDirs = [];
64
+ // Collect ws / hooks / config files across all accepted extensions.
65
+ const wsFiles = new Map();
66
+ for (const entry of entries) {
67
+ if (entry.isDirectory()) {
68
+ subDirs.push(entry.name);
69
+ continue;
70
+ }
71
+ if (!entry.isFile())
72
+ continue;
73
+ const split = splitConventionName(entry.name);
74
+ if (!split ||
75
+ !WS_CONVENTION_FILES.includes(split.stem)) {
76
+ continue;
77
+ }
78
+ const abs = path.resolve(path.join(dir, entry.name));
79
+ const existing = wsFiles.get(split.stem);
80
+ if (existing) {
81
+ throw new Error(`Conflicting convention files "${existing}" and "${abs}" in "${dir}" — ` +
82
+ `use only one of .ts/.js/.mjs per convention file.`);
83
+ }
84
+ wsFiles.set(split.stem, abs);
85
+ }
86
+ const wsFile = wsFiles.get('ws');
87
+ if (wsFile) {
88
+ const dirName = path.basename(dir);
89
+ const hooksFile = wsFiles.get('hooks');
90
+ const configFile = wsFiles.get('config');
91
+ // Build route path
92
+ const routePath = this.buildRoutePath(dir);
93
+ const params = this.extractParams(routePath);
94
+ const isWildcard = this.isWildcardDir(dirName);
95
+ const isGroup = this.isGroupDir(dirName);
96
+ const groupName = isGroup
97
+ ? this.extractGroupName(dirName)
98
+ : undefined;
99
+ out.push({
100
+ path: routePath,
101
+ wsFile,
102
+ hooksFile,
103
+ configFile,
104
+ params,
105
+ isWildcard,
106
+ isGroup,
107
+ groupName,
108
+ });
109
+ }
110
+ // Process subdirectories. Group directories only affect the URL but
111
+ // are still walked.
112
+ for (const subDir of subDirs) {
113
+ await this.walk(path.join(dir, subDir), out);
114
+ }
115
+ }
116
+ /**
117
+ * Builds the route path from the directory structure
118
+ */
119
+ buildRoutePath(dir) {
120
+ const relativePath = path.relative(this.wsDir, dir);
121
+ const parts = relativePath.split(path.sep);
122
+ // Convert directory names to route path
123
+ const routeParts = [];
124
+ for (const part of parts) {
125
+ // Skip group directories in URL
126
+ if (this.isGroupDir(part))
127
+ continue;
128
+ // Convert dynamic folders
129
+ if (this.isWildcardDir(part)) {
130
+ routeParts.push('*');
131
+ continue;
132
+ }
133
+ if (this.isDynamicDir(part)) {
134
+ const paramName = this.extractParamName(part);
135
+ routeParts.push(`:${paramName}`);
136
+ continue;
137
+ }
138
+ routeParts.push(part);
139
+ }
140
+ const routePath = '/' + routeParts.join('/');
141
+ return this.prefix
142
+ ? `/${this.prefix}${routePath}`.replace(/\/+/g, '/')
143
+ : routePath;
144
+ }
145
+ /**
146
+ * Extracts route parameters from the path
147
+ */
148
+ extractParams(routePath) {
149
+ const params = {};
150
+ const parts = routePath.split('/');
151
+ let hasParams = false;
152
+ for (const part of parts) {
153
+ if (part.startsWith(':')) {
154
+ const paramName = part.slice(1);
155
+ params[paramName] = paramName;
156
+ hasParams = true;
157
+ }
158
+ }
159
+ return hasParams ? params : undefined;
160
+ }
161
+ /**
162
+ * Checks if a directory name is a dynamic parameter folder
163
+ */
164
+ isDynamicDir(name) {
165
+ return /^\[([^\]]+)\]$/.test(name);
166
+ }
167
+ /**
168
+ * Extracts the parameter name from a dynamic folder
169
+ */
170
+ extractParamName(name) {
171
+ const match = name.match(/^\[([^\]]+)\]$/);
172
+ return match ? match[1] : name;
173
+ }
174
+ /**
175
+ * Checks if a directory name is a wildcard folder
176
+ */
177
+ isWildcardDir(name) {
178
+ return /^\[\.\.\.([^\]]*)\]$/.test(name);
179
+ }
180
+ /**
181
+ * Checks if a directory name is a group folder
182
+ */
183
+ isGroupDir(name) {
184
+ return /^\(.+\)$/.test(name);
185
+ }
186
+ /**
187
+ * Extracts the group name from a group folder
188
+ */
189
+ extractGroupName(name) {
190
+ const match = name.match(/^\((.+)\)$/);
191
+ return match ? (match[1] ?? name) : name;
192
+ }
193
+ }
@@ -0,0 +1,380 @@
1
+ /**
2
+ * WebSocket types for BurgerAPI
3
+ */
4
+ import type { BurgerContext, BurgerServices } from '../context/context.js';
5
+ /**
6
+ * Per-connection data, extended via module augmentation:
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * declare module "burger-api" {
11
+ * interface WebSocketData {
12
+ * userId: string;
13
+ * username: string;
14
+ * }
15
+ * }
16
+ * ```
17
+ */
18
+ export interface WebSocketData {
19
+ }
20
+ /**
21
+ * WebSocket connection states
22
+ */
23
+ export declare const enum WebSocketReadyState {
24
+ CONNECTING = 0,
25
+ OPEN = 1,
26
+ CLOSING = 2,
27
+ CLOSED = 3
28
+ }
29
+ /**
30
+ * WebSocket close codes
31
+ */
32
+ export declare const enum WebSocketCloseCode {
33
+ NORMAL_CLOSURE = 1000,
34
+ GOING_AWAY = 1001,
35
+ PROTOCOL_ERROR = 1002,
36
+ UNSUPPORTED_DATA = 1003,
37
+ NO_STATUS_RECEIVED = 1005,
38
+ ABNORMAL_CLOSURE = 1006,
39
+ INVALID_FRAME_PAYLOAD_DATA = 1007,
40
+ POLICY_VIOLATION = 1008,
41
+ MESSAGE_TOO_BIG = 1009,
42
+ MANDATORY_EXTENSION = 1010,
43
+ INTERNAL_ERROR = 1011,
44
+ SERVICE_RESTART = 1012,
45
+ TRY_AGAIN_LATER = 1013,
46
+ BAD_GATEWAY = 1014
47
+ }
48
+ /**
49
+ * WebSocket configuration options
50
+ */
51
+ export interface WebSocketConfig {
52
+ /**
53
+ * Maximum length of incoming message in bytes (default: 1024 * 1024 = 1MB)
54
+ */
55
+ maxPayloadLength?: number;
56
+ /**
57
+ * Idle timeout in seconds (default: 30)
58
+ */
59
+ idleTimeout?: number;
60
+ /**
61
+ * Backpressure limit in bytes (default: 1024 * 1024 = 1MB)
62
+ */
63
+ backpressureLimit?: number;
64
+ /**
65
+ * Close connection when backpressure limit reached (default: false)
66
+ */
67
+ closeOnBackpressureLimit?: boolean;
68
+ /**
69
+ * Require server per-message compression (default: false)
70
+ */
71
+ compression?: boolean;
72
+ /**
73
+ * Auth configuration. Set to `false` to disable auth for this route.
74
+ */
75
+ auth?: false | {
76
+ required?: boolean;
77
+ roles?: string[];
78
+ };
79
+ }
80
+ /**
81
+ * WebSocket route definition
82
+ */
83
+ export interface WebSocketRouteDefinition {
84
+ /**
85
+ * Route path (e.g., "/chat", "/notifications/:room")
86
+ */
87
+ path: string;
88
+ /**
89
+ * Route parameters
90
+ */
91
+ params?: Record<string, string>;
92
+ /**
93
+ * Handler functions
94
+ */
95
+ handlers: WebSocketHandlers;
96
+ /**
97
+ * Route hooks
98
+ */
99
+ hooks?: WebSocketHooks;
100
+ /**
101
+ * Route configuration
102
+ */
103
+ config?: WebSocketConfig;
104
+ }
105
+ /**
106
+ * WebSocket handler functions
107
+ */
108
+ export interface WebSocketHandlers {
109
+ open?: (ws: BurgerWS) => void | Promise<void>;
110
+ message?: (ws: BurgerWS, message: string | Buffer) => void | Promise<void>;
111
+ close?: (ws: BurgerWS, code: number, reason: string) => void | Promise<void>;
112
+ drain?: (ws: BurgerWS) => void | Promise<void>;
113
+ ping?: (ws: BurgerWS) => void | Promise<void>;
114
+ pong?: (ws: BurgerWS) => void | Promise<void>;
115
+ }
116
+ /**
117
+ * WebSocket hook functions
118
+ */
119
+ export interface WebSocketHooks {
120
+ onOpen?: (ws: BurgerWS) => void | Promise<void>;
121
+ onMessage?: (ws: BurgerWS, message: string | Buffer) => void | Promise<void>;
122
+ onClose?: (ws: BurgerWS, code: number, reason: string) => void | Promise<void>;
123
+ }
124
+ /**
125
+ * Compiled WebSocket route
126
+ */
127
+ export interface CompiledWebSocketRoute {
128
+ /**
129
+ * Route path
130
+ */
131
+ path: string;
132
+ /**
133
+ * Route parameters
134
+ */
135
+ params?: Record<string, string>;
136
+ /**
137
+ * Compiled handlers
138
+ */
139
+ handlers: WebSocketHandlers;
140
+ /**
141
+ * Compiled hooks
142
+ */
143
+ hooks?: WebSocketHooks;
144
+ /**
145
+ * Merged configuration
146
+ */
147
+ config: WebSocketConfig;
148
+ }
149
+ /**
150
+ * WebSocket context interface
151
+ * Provides connection methods and data access
152
+ */
153
+ export interface BurgerWS {
154
+ /**
155
+ * Per-connection data. Typed via module augmentation of `WebSocketData`:
156
+ *
157
+ * ```typescript
158
+ * declare module "burger-api" {
159
+ * interface WebSocketData {
160
+ * userId: string;
161
+ * username: string;
162
+ * }
163
+ * }
164
+ * ```
165
+ */
166
+ data: WebSocketData;
167
+ /**
168
+ * URL-decoded route params of the matched WebSocket route (e.g.
169
+ * `{ room: 'lobby' }` for `/chat/:room`). Empty object when none.
170
+ */
171
+ readonly params: Record<string, string>;
172
+ /**
173
+ * Wildcard segments of the matched route, decoded per segment (e.g.
174
+ * `['a', 'b c']` for `/files/a/b%20c` with `/files/*`). Mirrors HTTP
175
+ * `ctx.wildcardParams`; `params['*']` still carries the raw remainder.
176
+ * Empty array for non-wildcard routes.
177
+ */
178
+ readonly wildcardParams: string[];
179
+ /**
180
+ * The URL of the upgrade request. Parsed lazily on first access and
181
+ * cached for the life of the socket.
182
+ *
183
+ * @example
184
+ * ```typescript
185
+ * const room = ws.url.pathname;
186
+ * ```
187
+ */
188
+ readonly url: URL;
189
+ /**
190
+ * Query string parameters of the upgrade request. Parsed lazily on first
191
+ * access and cached for the life of the socket.
192
+ *
193
+ * @example
194
+ * ```typescript
195
+ * const token = ws.query.get('token');
196
+ * ```
197
+ */
198
+ readonly query: URLSearchParams;
199
+ /**
200
+ * Injected application services, populated by `burger.provide()` (the
201
+ * `ctx.services` equivalent). Extend `BurgerServices` via module augmentation.
202
+ *
203
+ * @example
204
+ * ```typescript
205
+ * const db = ws.services.db;
206
+ * const logger = ws.services.logger;
207
+ * ```
208
+ */
209
+ services: BurgerServices;
210
+ /**
211
+ * Authenticated user from auth plugins, available when auth succeeds
212
+ * during the upgrade. Same type as `ctx.user` (the shared
213
+ * `BurgerAuthUser` augmentation point):
214
+ *
215
+ * ```typescript
216
+ * declare module "burger-api" {
217
+ * interface BurgerAuthUser {
218
+ * tenantId: string;
219
+ * }
220
+ * }
221
+ * ```
222
+ */
223
+ user?: BurgerContext['user'];
224
+ /**
225
+ * Send a message to the client
226
+ */
227
+ send(message: string | Buffer): void;
228
+ /**
229
+ * Send a text message to the client
230
+ */
231
+ sendText(message: string): void;
232
+ /**
233
+ * Send a binary message to the client
234
+ */
235
+ sendBinary(message: Buffer): void;
236
+ /**
237
+ * Subscribe to a topic for pub/sub
238
+ */
239
+ subscribe(topic: string): void;
240
+ /**
241
+ * Unsubscribe from a topic
242
+ */
243
+ unsubscribe(topic: string): void;
244
+ /**
245
+ * Publish a message to all subscribers of a topic
246
+ */
247
+ publish(topic: string, message: string | Buffer): void;
248
+ /**
249
+ * Publish a text message to all subscribers of a topic
250
+ */
251
+ publishText(topic: string, message: string): void;
252
+ /**
253
+ * Publish a binary message to all subscribers of a topic
254
+ */
255
+ publishBinary(topic: string, message: Buffer): void;
256
+ /**
257
+ * Check if connected to a topic
258
+ */
259
+ isSubscribed(topic: string): boolean;
260
+ /**
261
+ * Remote IP address
262
+ */
263
+ remoteAddress: string;
264
+ /**
265
+ * Connection ready state
266
+ */
267
+ readyState: WebSocketReadyState;
268
+ /**
269
+ * Terminate the connection immediately
270
+ */
271
+ terminate(): void;
272
+ /**
273
+ * Close the connection with code and reason
274
+ */
275
+ close(code?: number, reason?: string): void;
276
+ /**
277
+ * Batch messages for efficiency
278
+ */
279
+ cork(callback: () => void): void;
280
+ /**
281
+ * The underlying raw Bun ServerWebSocket (advanced use)
282
+ */
283
+ readonly raw: unknown;
284
+ }
285
+ /**
286
+ * WebSocket module definition for a route
287
+ */
288
+ export interface WebSocketModule {
289
+ /**
290
+ * Connection opened handler
291
+ */
292
+ open?: (ws: BurgerWS) => void | Promise<void>;
293
+ /**
294
+ * Message received handler
295
+ */
296
+ message?: (ws: BurgerWS, message: string | Buffer) => void | Promise<void>;
297
+ /**
298
+ * Connection closed handler
299
+ */
300
+ close?: (ws: BurgerWS, code: number, reason: string) => void | Promise<void>;
301
+ /**
302
+ * Backpressure relieved handler
303
+ */
304
+ drain?: (ws: BurgerWS) => void | Promise<void>;
305
+ /**
306
+ * Ping received handler
307
+ */
308
+ ping?: (ws: BurgerWS) => void | Promise<void>;
309
+ /**
310
+ * Pong received handler
311
+ */
312
+ pong?: (ws: BurgerWS) => void | Promise<void>;
313
+ }
314
+ /**
315
+ * WebSocket hooks module
316
+ */
317
+ export interface WebSocketHooksModule {
318
+ /**
319
+ * Hook runs when connection opens
320
+ */
321
+ onOpen?: (ws: BurgerWS) => void | Promise<void>;
322
+ /**
323
+ * Hook runs when message received
324
+ */
325
+ onMessage?: (ws: BurgerWS, message: string | Buffer) => void | Promise<void>;
326
+ /**
327
+ * Hook runs when connection closes
328
+ */
329
+ onClose?: (ws: BurgerWS, code: number, reason: string) => void | Promise<void>;
330
+ }
331
+ /**
332
+ * WebSocket config module
333
+ */
334
+ export interface WebSocketConfigModule extends WebSocketConfig {
335
+ }
336
+ /**
337
+ * Default `BurgerWS` implementation wrapping the runtime's native socket.
338
+ */
339
+ export declare class BurgerWSContext implements BurgerWS {
340
+ private _raw;
341
+ private _data;
342
+ private _params;
343
+ private _wildcardParams;
344
+ private _services;
345
+ /** Upgrade request URL captured by the adapter (not parsed yet). */
346
+ private _url;
347
+ /** Cached parsed URL — lazily built once per socket. */
348
+ private _parsedUrl;
349
+ /** Cached query view — shares the parsed URL's `searchParams`. */
350
+ private _query;
351
+ constructor(rawWebSocket: any, providers?: Map<string, unknown>, params?: Record<string, string>, url?: string, wildcardParams?: string[]);
352
+ get data(): WebSocketData;
353
+ set data(value: WebSocketData);
354
+ get params(): Record<string, string>;
355
+ get wildcardParams(): string[];
356
+ get url(): URL;
357
+ get query(): URLSearchParams;
358
+ get services(): BurgerServices;
359
+ get user(): BurgerWS['user'];
360
+ send(message: string | Buffer): void;
361
+ sendText(message: string): void;
362
+ sendBinary(message: Buffer): void;
363
+ subscribe(topic: string): void;
364
+ unsubscribe(topic: string): void;
365
+ publish(topic: string, message: string | Buffer): void;
366
+ publishText(topic: string, message: string): void;
367
+ publishBinary(topic: string, message: Buffer): void;
368
+ isSubscribed(topic: string): boolean;
369
+ get remoteAddress(): string;
370
+ get readyState(): WebSocketReadyState;
371
+ terminate(): void;
372
+ close(code?: number, reason?: string): void;
373
+ cork(callback: () => void): void;
374
+ get raw(): unknown;
375
+ /**
376
+ * Fails loud for Bun-only capabilities (topic pub/sub). A silent no-op
377
+ * would hide real delivery failures from application code.
378
+ */
379
+ private requireBun;
380
+ }