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,213 @@
1
+ /**
2
+ * WebSocket types for BurgerAPI
3
+ */
4
+ /**
5
+ * WebSocket connection states
6
+ */
7
+ export var WebSocketReadyState;
8
+ (function (WebSocketReadyState) {
9
+ WebSocketReadyState[WebSocketReadyState["CONNECTING"] = 0] = "CONNECTING";
10
+ WebSocketReadyState[WebSocketReadyState["OPEN"] = 1] = "OPEN";
11
+ WebSocketReadyState[WebSocketReadyState["CLOSING"] = 2] = "CLOSING";
12
+ WebSocketReadyState[WebSocketReadyState["CLOSED"] = 3] = "CLOSED";
13
+ })(WebSocketReadyState || (WebSocketReadyState = {}));
14
+ /**
15
+ * WebSocket close codes
16
+ */
17
+ export var WebSocketCloseCode;
18
+ (function (WebSocketCloseCode) {
19
+ WebSocketCloseCode[WebSocketCloseCode["NORMAL_CLOSURE"] = 1000] = "NORMAL_CLOSURE";
20
+ WebSocketCloseCode[WebSocketCloseCode["GOING_AWAY"] = 1001] = "GOING_AWAY";
21
+ WebSocketCloseCode[WebSocketCloseCode["PROTOCOL_ERROR"] = 1002] = "PROTOCOL_ERROR";
22
+ WebSocketCloseCode[WebSocketCloseCode["UNSUPPORTED_DATA"] = 1003] = "UNSUPPORTED_DATA";
23
+ WebSocketCloseCode[WebSocketCloseCode["NO_STATUS_RECEIVED"] = 1005] = "NO_STATUS_RECEIVED";
24
+ WebSocketCloseCode[WebSocketCloseCode["ABNORMAL_CLOSURE"] = 1006] = "ABNORMAL_CLOSURE";
25
+ WebSocketCloseCode[WebSocketCloseCode["INVALID_FRAME_PAYLOAD_DATA"] = 1007] = "INVALID_FRAME_PAYLOAD_DATA";
26
+ WebSocketCloseCode[WebSocketCloseCode["POLICY_VIOLATION"] = 1008] = "POLICY_VIOLATION";
27
+ WebSocketCloseCode[WebSocketCloseCode["MESSAGE_TOO_BIG"] = 1009] = "MESSAGE_TOO_BIG";
28
+ WebSocketCloseCode[WebSocketCloseCode["MANDATORY_EXTENSION"] = 1010] = "MANDATORY_EXTENSION";
29
+ WebSocketCloseCode[WebSocketCloseCode["INTERNAL_ERROR"] = 1011] = "INTERNAL_ERROR";
30
+ WebSocketCloseCode[WebSocketCloseCode["SERVICE_RESTART"] = 1012] = "SERVICE_RESTART";
31
+ WebSocketCloseCode[WebSocketCloseCode["TRY_AGAIN_LATER"] = 1013] = "TRY_AGAIN_LATER";
32
+ WebSocketCloseCode[WebSocketCloseCode["BAD_GATEWAY"] = 1014] = "BAD_GATEWAY";
33
+ })(WebSocketCloseCode || (WebSocketCloseCode = {}));
34
+ /**
35
+ * Default `BurgerWS` implementation wrapping the runtime's native socket.
36
+ */
37
+ export class BurgerWSContext {
38
+ // Platform boundary: wraps the runtime's native server-side socket (Bun,
39
+ // Cloudflare/Deno, or `ws` on Node). Methods probe the raw socket
40
+ // structurally and fail loud where a capability does not exist.
41
+ _raw;
42
+ _data = {};
43
+ _params;
44
+ _wildcardParams;
45
+ _services = Object.create(null);
46
+ /** Upgrade request URL captured by the adapter (not parsed yet). */
47
+ _url;
48
+ /** Cached parsed URL — lazily built once per socket. */
49
+ _parsedUrl;
50
+ /** Cached query view — shares the parsed URL's `searchParams`. */
51
+ _query;
52
+ // The raw socket is the platform's server-side WebSocket; `providers` is
53
+ // the same map passed to `BurgerContext.create`.
54
+ constructor(rawWebSocket, providers, params = {}, url, wildcardParams = []) {
55
+ this._raw = rawWebSocket;
56
+ this._params = params;
57
+ this._wildcardParams = wildcardParams;
58
+ this._url = url;
59
+ this._parsedUrl = undefined;
60
+ this._query = undefined;
61
+ // Copy data from the raw socket (typed via the `WebSocketData`
62
+ // augmentation).
63
+ if (rawWebSocket.data) {
64
+ this._data = { ...rawWebSocket.data };
65
+ }
66
+ this._services = providers
67
+ ? Object.fromEntries(providers)
68
+ : Object.create(null);
69
+ }
70
+ get data() {
71
+ return this._data;
72
+ }
73
+ set data(value) {
74
+ this._data = value;
75
+ // Sync back to raw WebSocket
76
+ if (this._raw) {
77
+ this._raw.data = value;
78
+ }
79
+ }
80
+ get params() {
81
+ return this._params;
82
+ }
83
+ get wildcardParams() {
84
+ return this._wildcardParams;
85
+ }
86
+ get url() {
87
+ if (this._parsedUrl !== undefined)
88
+ return this._parsedUrl;
89
+ // Wired sockets carry the URL from the upgrade; a raw socket that
90
+ // exposes its own `url` (some framing libraries) is the fallback.
91
+ const raw = this._url ?? this._raw?.url;
92
+ if (typeof raw !== 'string') {
93
+ throw new Error('[burger-api] ws.url is unavailable: this socket was not ' +
94
+ 'created by the BurgerAPI WebSocket upgrade path.');
95
+ }
96
+ return (this._parsedUrl = new URL(raw));
97
+ }
98
+ get query() {
99
+ return (this._query ??= this.url.searchParams);
100
+ }
101
+ get services() {
102
+ return this._services;
103
+ }
104
+ get user() {
105
+ // `user` is not declared on `WebSocketData`; auth plugins seed it.
106
+ return this._data.user;
107
+ }
108
+ send(message) {
109
+ if (typeof this._raw.sendText === 'function') {
110
+ // Bun socket: dedicated text/binary entry points.
111
+ if (typeof message === 'string') {
112
+ this._raw.sendText(message);
113
+ }
114
+ else {
115
+ this._raw.sendBinary(message);
116
+ }
117
+ return;
118
+ }
119
+ // Standard WebSocket (Workers / Deno / `ws`): `send` takes strings
120
+ // and binary views.
121
+ this._raw.send(typeof message === 'string'
122
+ ? message
123
+ : new Uint8Array(message.buffer, message.byteOffset, message.byteLength));
124
+ }
125
+ sendText(message) {
126
+ if (typeof this._raw.sendText === 'function') {
127
+ this._raw.sendText(message);
128
+ return;
129
+ }
130
+ this._raw.send(message);
131
+ }
132
+ sendBinary(message) {
133
+ if (typeof this._raw.sendBinary === 'function') {
134
+ this._raw.sendBinary(message);
135
+ return;
136
+ }
137
+ this._raw.send(new Uint8Array(message.buffer, message.byteOffset, message.byteLength));
138
+ }
139
+ subscribe(topic) {
140
+ this.requireBun('subscribe', topic);
141
+ this._raw.subscribe(topic);
142
+ }
143
+ unsubscribe(topic) {
144
+ this.requireBun('unsubscribe', topic);
145
+ this._raw.unsubscribe(topic);
146
+ }
147
+ publish(topic, message) {
148
+ this.requireBun('publish', topic);
149
+ if (typeof message === 'string') {
150
+ this._raw.publishText(topic, message);
151
+ }
152
+ else {
153
+ this._raw.publishBinary(topic, message);
154
+ }
155
+ }
156
+ publishText(topic, message) {
157
+ this.requireBun('publish', topic);
158
+ this._raw.publishText(topic, message);
159
+ }
160
+ publishBinary(topic, message) {
161
+ this.requireBun('publish', topic);
162
+ this._raw.publishBinary(topic, message);
163
+ }
164
+ isSubscribed(topic) {
165
+ if (typeof this._raw.isSubscribed !== 'function') {
166
+ throw new Error('[burger-api] ws.isSubscribed() requires Bun topic pub/sub, ' +
167
+ 'which this runtime does not provide.');
168
+ }
169
+ return this._raw.isSubscribed(topic);
170
+ }
171
+ get remoteAddress() {
172
+ return this._raw.remoteAddress ?? '';
173
+ }
174
+ get readyState() {
175
+ // Other runtimes expose the same numeric states.
176
+ return this._raw.readyState ?? WebSocketReadyState.OPEN;
177
+ }
178
+ terminate() {
179
+ if (typeof this._raw.terminate !== 'function') {
180
+ this._raw.close(1001, 'Going Away');
181
+ return;
182
+ }
183
+ this._raw.terminate();
184
+ }
185
+ close(code, reason) {
186
+ this._raw.close(code, reason);
187
+ }
188
+ cork(callback) {
189
+ if (typeof this._raw.cork !== 'function') {
190
+ // No batching on this runtime — run directly.
191
+ callback();
192
+ return;
193
+ }
194
+ this._raw.cork(callback);
195
+ }
196
+ get raw() {
197
+ return this._raw;
198
+ }
199
+ /**
200
+ * Fails loud for Bun-only capabilities (topic pub/sub). A silent no-op
201
+ * would hide real delivery failures from application code.
202
+ */
203
+ requireBun(method, topic) {
204
+ const available = typeof this._raw.subscribe === 'function' &&
205
+ typeof this._raw.publishText === 'function';
206
+ if (available)
207
+ return;
208
+ throw new Error(`[burger-api] ws.${method}(${topic ? `"${topic}"` : ''}) requires ` +
209
+ 'Bun topic pub/sub, which this runtime does not provide. ' +
210
+ 'Track per-connection state in ws.data and fan out with an ' +
211
+ 'explicit connection registry instead.');
212
+ }
213
+ }
package/package.json CHANGED
@@ -1,14 +1,44 @@
1
1
  {
2
2
  "name": "burger-api",
3
- "version": "0.9.7",
3
+ "version": "1.0.0-beta",
4
+ "description": "Fast, file-based API framework for Bun with hooks, Standard Schema validation, OpenAPI and WebSockets. Runs on Bun, Node, Cloudflare Workers, Deno and Vercel.",
4
5
  "author": "Isfhan Ahmed",
5
6
  "type": "module",
7
+ "sideEffects": false,
6
8
  "module": "dist/src/index.js",
7
9
  "types": "dist/src/index.d.ts",
8
10
  "exports": {
9
11
  ".": {
10
- "import": "./dist/src/index.js",
11
- "types": "./dist/src/index.d.ts"
12
+ "types": "./dist/src/index.d.ts",
13
+ "import": "./dist/src/index.js"
14
+ },
15
+ "./validation": {
16
+ "types": "./dist/src/validation/index.d.ts",
17
+ "import": "./dist/src/validation/index.js"
18
+ },
19
+ "./compiler": {
20
+ "types": "./dist/src/compiler/index.d.ts",
21
+ "import": "./dist/src/compiler/index.js"
22
+ },
23
+ "./openapi": {
24
+ "types": "./dist/src/core/openapi.d.ts",
25
+ "import": "./dist/src/core/openapi.js"
26
+ },
27
+ "./ws": {
28
+ "types": "./dist/src/ws/index.d.ts",
29
+ "import": "./dist/src/ws/index.js"
30
+ },
31
+ "./adapter": {
32
+ "types": "./dist/src/adapter/index.d.ts",
33
+ "import": "./dist/src/adapter/index.js"
34
+ },
35
+ "./adapter/web-standard": {
36
+ "types": "./dist/src/adapter/web-standard/index.d.ts",
37
+ "import": "./dist/src/adapter/web-standard/index.js"
38
+ },
39
+ "./adapter/bun": {
40
+ "types": "./dist/src/adapter/bun/index.d.ts",
41
+ "import": "./dist/src/adapter/bun/index.js"
12
42
  }
13
43
  },
14
44
  "files": [
@@ -16,85 +46,67 @@
16
46
  ],
17
47
  "scripts": {
18
48
  "typecheck": "tsc --noEmit",
19
- "build": "tsc --project tsconfig.build.json",
49
+ "build": "rm -rf dist && tsc --project tsconfig.build.json",
20
50
  "prepare": "bun run build",
21
- "test": "bun run test:examples && bun run test:ecosystem",
22
- "test:examples": "bun test --timeout 30000 --max-concurrency 1 examples/**/*.test.ts",
23
- "test:ecosystem": "bun test --timeout 60000 --max-concurrency 1 test/ecosystem-middleware-smoke.test.ts",
24
- "dev": "bun run examples/file-base-static-page-routing-app/index.ts"
51
+ "test": "bun run test:examples && bun run test:ecosystem && bun run test:lifecycle && bun run test:context && bun run test:utils && bun run test:chain && bun run test:plugin && bun run test:router && bun run test:core && bun run test:errors && bun run test:validation && bun run test:compiler && bun run test:adapter && bun run test:provider && bun run test:smoke && bun run test:ws",
52
+ "test:examples": "bun test --timeout 30000 --max-concurrency 1 ./examples",
53
+ "test:ecosystem": "bun test --timeout 60000 --max-concurrency 1 test/ecosystem-smoke.test.ts test/ecosystem/u16-hardening.test.ts",
54
+ "test:lifecycle": "bun test --timeout 30000 ./test/lifecycle",
55
+ "test:context": "bun test --timeout 30000 ./test/context",
56
+ "test:utils": "bun test --timeout 30000 ./test/utils",
57
+ "test:chain": "bun test --timeout 30000 ./test/chain",
58
+ "test:plugin": "bun test --timeout 30000 ./test/plugin",
59
+ "test:router": "bun test --timeout 30000 ./test/router",
60
+ "test:core": "bun test --timeout 30000 ./test/core",
61
+ "test:errors": "bun test --timeout 30000 ./test/errors",
62
+ "test:smoke": "bun test --timeout 30000 test/plugin-smoke.test.ts",
63
+ "test:ws": "bun test --timeout 30000 ./test/ws",
64
+ "test:validation": "bun test --timeout 30000 ./test/validation",
65
+ "test:compiler": "bun test --timeout 30000 ./test/compiler",
66
+ "test:adapter": "bun test --timeout 30000 ./test/adapter",
67
+ "test:provider": "bun test --timeout 30000 ./test/provider",
68
+ "dev": "bun run examples/basic/src/index.ts"
25
69
  },
26
70
  "keywords": [
27
71
  "burger-api",
28
- "burger-api-framework",
29
72
  "bun",
30
- "bunjs",
31
73
  "bun-framework",
32
- "fast-backend",
33
- "javascript-backend",
34
- "high-performance",
35
- "esm",
36
- "typescript",
37
- "openapi",
38
- "swagger-ui",
39
- "declarative-routing",
40
74
  "api-framework",
41
- "modern-backend",
42
- "backend-framework",
43
- "server",
44
- "bun-native",
45
- "js-backend",
46
- "fast-api",
47
- "scalable-backend",
48
- "backend-development",
49
- "modern-api",
50
- "api-development",
51
- "backend-engine",
52
- "efficient",
53
- "minimalist-backend",
54
- "bun-powered",
55
- "open-source",
56
- "typescript-backend",
57
- "performance",
58
- "rapid-development",
59
75
  "web-framework",
60
- "api-server",
61
- "dynamic-routing",
62
- "backend-routing",
63
- "extensible",
64
- "modular",
65
- "declarative-api",
66
- "lightweight",
67
- "contemporary-backend",
68
- "fast-javascript",
69
- "bun-js-framework",
70
- "bun-backend",
71
- "bun-api-framework",
72
- "pakistan-backend",
73
- "pakistan-api-framework",
74
- "pakistan-api-server",
75
- "pakistan-backend-framework",
76
- "pakistan-bunjs-framework",
77
- "pakistan-javascript-framework"
76
+ "backend-framework",
77
+ "typescript",
78
+ "javascript",
79
+ "file-based-routing",
80
+ "openapi",
81
+ "zod",
82
+ "standard-schema",
83
+ "websocket",
84
+ "wintercg",
85
+ "cloudflare-workers"
78
86
  ],
79
87
  "license": "MIT",
80
88
  "repository": {
81
89
  "type": "git",
82
- "url": "git+https://github.com/isfhan/burger-api.git"
90
+ "url": "git+https://github.com/Isfhan/burger-api.git",
91
+ "directory": "packages/burger-api"
83
92
  },
84
93
  "bugs": {
85
94
  "url": "https://github.com/isfhan/burger-api/issues"
86
95
  },
87
96
  "homepage": "https://burger-api.com",
88
97
  "engines": {
89
- "bun": ">=1.3.0"
98
+ "bun": ">=1.4.4",
99
+ "node": ">=24.22.1"
90
100
  },
91
101
  "dependencies": {
92
- "zod": "^4.0.17"
102
+ "zod": "^4.6.7"
93
103
  },
94
104
  "devDependencies": {
95
- "@types/bun": "latest"
105
+ "@types/bun": "latest",
106
+ "arktype": "^2.2.9",
107
+ "valibot": "^1.4.2"
96
108
  },
97
109
  "peerDependencies": {
98
- "typescript": "^5"
110
+ "typescript": ">=5"
99
111
  }
100
- }
112
+ }
@@ -1,65 +0,0 @@
1
- import type { RouteDefinition, TrieNode } from '../types/index';
2
- /**
3
- * ApiRouter class for handling file-based routing.
4
- * Loads routes from a directory structure and matches requests to the appropriate route handlers.
5
- * Supports dynamic segments (e.g., [id] ,(group),[...]) and HTTP method handlers.
6
- * Routes are sorted to prioritize static routes over dynamic and wildcard ones to prevent overlapping route issues.
7
- */
8
- export declare class ApiRouter {
9
- private routesDir;
10
- private prefix;
11
- /** The root of the trie where all routes will begin*/
12
- private root;
13
- /**
14
- * Constructor for the ApiRouter class.
15
- * @param routesDir The directory path where route modules are located.
16
- * @param prefix Optional prefix to prepend to all routes (e.g., "api" becomes "/api/...").
17
- * @throws {Error} If the routes directory path is not provided.
18
- */
19
- constructor(routesDir: string, prefix?: string);
20
- /**
21
- * Getter for the routes trie.
22
- * @returns The root of the trie.
23
- */
24
- get routes(): TrieNode;
25
- /**
26
- * Loads all routes from the routes directory into the trie structure.
27
- * @returns {Promise<void>} A promise that resolves when all routes are loaded.
28
- * @throws {Error} If the routes directory is not found or if an error occurs during route loading.
29
- */
30
- loadRoutes(): Promise<void>;
31
- /**
32
- * Inserts a route definition into the trie structure.
33
- * @param routeDef The route definition to insert, containing path, handlers, middleware, schema, and OpenAPI metadata.
34
- * @throws {Error} If the route definition is invalid or causes a conflict in the trie.
35
- */
36
- private insertRoute;
37
- /**
38
- * Recursively scans a directory for route modules (route.ts files) and loads them into the trie.
39
- * @param dir The current directory path to scan.
40
- * @param basePath The base path used to construct route paths from the directory structure.
41
- * @returns {Promise<void>} A promise that resolves when the directory scan is complete.
42
- * @throws {Error} If multiple dynamic folders are found at the same level or if directory access fails.
43
- */
44
- private scanDirectory;
45
- /**
46
- * Loads a route module from a file and inserts it into the trie.
47
- * @param entryPath The full file system path to the route module (route.ts).
48
- * @param relativePath The relative path used to construct the route path.
49
- * @returns {Promise<void>} A promise that resolves when the module is loaded and inserted.
50
- * @throws {Error} If the route module fails to load or is invalid.
51
- */
52
- private loadRouteModule;
53
- /**
54
- * Resolves a request to a route definition and its parameters.
55
- * @param pathname The normalized request pathname.
56
- * @param method The uppercase HTTP method.
57
- * @returns {{ route?: RouteDefinition; params: Record<string, string>; wildcardParams?: string[] }} An object containing the matched route (if any), extracted parameters, and wildcard segments (if applicable).
58
- * @throws {Error} If the request URL is malformed.
59
- */
60
- resolve(pathname: string, method: string): {
61
- route?: RouteDefinition;
62
- params: Record<string, string>;
63
- wildcardParams?: string[];
64
- };
65
- }