burger-api 0.4.0 → 0.5.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.
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  [![Under Development](https://img.shields.io/badge/under%20development-red.svg)](https://github.com/isfhan/burger-api)
6
6
  [![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
7
7
  [![Bun](https://img.shields.io/badge/Bun-1.2.20-black?logo=bun)](https://bun.sh)
8
- [![Version](https://img.shields.io/badge/version-0.4.0-green.svg)](https://github.com/isfhan/burger-api/releases)
8
+ [![Version](https://img.shields.io/badge/version-0.5.0-green.svg)](https://github.com/isfhan/burger-api/releases)
9
9
 
10
10
  **burger-api** is a modern, open source API framework built on
11
11
  [Bun.js](https://bun.sh). It combines the simplicity of file-based routing with
@@ -44,6 +44,13 @@ burger-api is built to offer a robust developer experience through:
44
44
  - 🔄 **Middleware Architecture:**
45
45
  Supports both global and route-specific middleware.
46
46
 
47
+ - After middlewares (functions returned by a middleware) run after the
48
+ route handler.
49
+ - They now run even if an earlier middleware returned a Response, so
50
+ post-processing is reliable.
51
+ - They run in reverse order and are useful for adding CORS headers,
52
+ logging, or tweaking the final Response.
53
+
47
54
  - ✅ **Type-Safe Validation:**
48
55
  Utilizes Zod for request validation, ensuring full type safety and automatic
49
56
  error reporting.
@@ -59,19 +66,45 @@ burger-api is built to offer a robust developer experience through:
59
66
 
60
67
  ## 📣 Changelog
61
68
 
62
- ### Latest Version: 0.4.0 (October 21, 2025)
69
+ ### Latest Version: 0.5.0 (November 1, 2025)
70
+
71
+ - 🌟 **Feature:** Auto-injected OPTIONS handler for CORS preflight:
72
+
73
+ - Automatically injects an OPTIONS handler for CORS preflight when needed
74
+ - Only injects if the route defines any preflight-triggering methods and
75
+ lacks an OPTIONS handler
76
+ - Injects a minimal OPTIONS handler that returns a 204 No Content response
77
+ - Works for all HTTP methods that trigger CORS preflight (POST, PUT,
78
+ DELETE, PATCH)
79
+ - Does not inject if the route already has an OPTIONS handler
80
+
81
+ - 🌟 **Feature:** Improved response handling in middleware (after
82
+ middlewares):
83
+
84
+ - After middlewares now run even if the current middleware already
85
+ returned a response
86
+ - After middlewares run in reverse order to make changing the response
87
+ easier and to help with CORS
88
+
89
+ - 🐛 **Bug Fix:** Fixed TypeScript type resolution for package consumers:
90
+ - Users now get full IntelliSense, autocomplete, and type safety out of
91
+ the box
92
+
93
+ ### Previous Version: 0.4.0 (October 21, 2025)
63
94
 
64
- - 🎯 **Wildcard Routes:**
65
- - Added wildcard routes using `[...]` folder name - matches any path after it
95
+ - 🌟 **Feature:** Wildcard Routes:
96
+ - Added wildcard routes using `[...]` folder name - matches any path after
97
+ it
66
98
  - Create routes that handle multiple path segments automatically
67
99
  - Access all matched path parts through `wildcardParams` in your request
68
- - Routes are matched in order: exact paths first, then dynamic routes (like `[id]`), then wildcards last
100
+ - Routes are matched in order: exact paths first, then dynamic routes
101
+ (like `[id]`), then wildcards last
69
102
  - Works inside dynamic routes too (example: `/api/users/[userId]/[...]`)
70
103
  - View wildcard routes in OpenAPI docs and Swagger UI
71
104
 
72
- ### Version 0.3.0 (August 15, 2025)
105
+ ### Previous Version: 0.3.0 (August 15, 2025)
73
106
 
74
- - 🔧 **Updated Zod to version 4:**
107
+ - 🌟 **Feature:** Updated Zod to version 4:
75
108
  - Updated Zod version from 3.x to 4.x
76
109
  - Updated built-in request validation middleware to use Zod 4
77
110
  - Updated and better request validation middleware error handling
@@ -1,4 +1,4 @@
1
- import type { RouteDefinition, TrieNode } from '@burgerTypes';
1
+ import type { RouteDefinition, TrieNode } from '../types/index';
2
2
  /**
3
3
  * ApiRouter class for handling file-based routing.
4
4
  * Loads routes from a directory structure and matches requests to the appropriate route handlers.
@@ -2,7 +2,7 @@
2
2
  import { readdir } from 'fs/promises';
3
3
  import * as path from 'path';
4
4
  // Import utils
5
- import { cleanPrefix, normalizePath, ROUTE_CONSTANTS, HTTP_METHODS, } from '../utils/index.js';
5
+ import { cleanPrefix, normalizePath, ROUTE_CONSTANTS, HTTP_METHODS, } from '../utils/index';
6
6
  /**
7
7
  * ApiRouter class for handling file-based routing.
8
8
  * Loads routes from a directory structure and matches requests to the appropriate route handlers.
@@ -165,6 +165,24 @@ export class ApiRouter {
165
165
  handlers[method] = routeModule[method];
166
166
  }
167
167
  }
168
+ // Auto-inject minimal OPTIONS handler for CORS preflight when needed
169
+ // Only if route defines any preflight-triggering methods and lacks an OPTIONS handler
170
+ const PREFLIGHT_METHODS = ['POST', 'PUT', 'DELETE', 'PATCH'];
171
+ let hasPreflightMethods = false;
172
+ // Manual loop is slightly faster than Array.prototype.some in tight paths
173
+ for (let i = 0; i < PREFLIGHT_METHODS.length; i++) {
174
+ if (handlers[PREFLIGHT_METHODS[i]]) {
175
+ hasPreflightMethods = true;
176
+ break;
177
+ }
178
+ }
179
+ // If the route defines any preflight-triggering methods and lacks an OPTIONS handler, auto-add an OPTIONS handler
180
+ if (hasPreflightMethods && typeof handlers.OPTIONS !== 'function') {
181
+ // if (process.env.NODE_ENV !== 'production') {
182
+ // console.debug('Auto-added OPTIONS handler for route:', routePath);
183
+ // }
184
+ handlers.OPTIONS = () => new Response(null, { status: 204 });
185
+ }
168
186
  const routeDef = {
169
187
  path: routePath,
170
188
  handlers,
@@ -1,4 +1,4 @@
1
- import type { ServerOptions, RouteDefinition } from '@burgerTypes';
1
+ import type { ServerOptions, RouteDefinition } from '../types/index';
2
2
  export declare function generateOpenAPIDocument(apiRoutes: RouteDefinition[], options: ServerOptions): {
3
3
  openapi: string;
4
4
  info: {
@@ -1,4 +1,4 @@
1
- import type { PageDefinition } from '@burgerTypes';
1
+ import type { PageDefinition } from '../types/index';
2
2
  /**
3
3
  * PageRouter class for handling file-based page routing.
4
4
  * Loads pages from a directory structure and matches requests to the appropriate page handlers.
@@ -2,7 +2,7 @@
2
2
  import { readdirSync } from 'fs';
3
3
  import * as path from 'path';
4
4
  // Import utils
5
- import { cleanPrefix, normalizePath, compareRoutes, ROUTE_CONSTANTS, } from '../utils/index.js';
5
+ import { cleanPrefix, normalizePath, compareRoutes, ROUTE_CONSTANTS, } from '../utils/index';
6
6
  /**
7
7
  * PageRouter class for handling file-based page routing.
8
8
  * Loads pages from a directory structure and matches requests to the appropriate page handlers.
@@ -1,4 +1,4 @@
1
- import type { ServerOptions, FetchHandler } from '@burgerTypes';
1
+ import type { ServerOptions, FetchHandler } from '../types/index';
2
2
  export declare class Server {
3
3
  private options;
4
4
  private server;
@@ -1,7 +1,7 @@
1
1
  // Import stuff from Bun
2
2
  import { serve } from 'bun';
3
3
  // Import stuff from utils
4
- import { errorResponse } from '../utils/error.js';
4
+ import { errorResponse } from '../utils/error';
5
5
  export class Server {
6
6
  options;
7
7
  server = null;
@@ -1,4 +1,4 @@
1
- import type { ServerOptions } from '@burgerTypes';
1
+ import type { ServerOptions } from './types/index';
2
2
  export declare class Burger {
3
3
  private options;
4
4
  /**
@@ -73,5 +73,5 @@ export declare class Burger {
73
73
  */
74
74
  serve(port?: number, cb?: () => void): Promise<void>;
75
75
  }
76
- export { setDir } from './utils/index.js';
77
- export type { ServerOptions, RequestHandler, BurgerRequest, BurgerNext, Middleware, openapi, } from '@burgerTypes';
76
+ export { setDir } from './utils/index';
77
+ export type { ServerOptions, RequestHandler, BurgerRequest, BurgerNext, Middleware, openapi, } from './types/index';
package/dist/src/index.js CHANGED
@@ -1,14 +1,14 @@
1
1
  // Import stuff from core
2
- import { Server } from './core/server.js';
3
- import { ApiRouter } from './core/api-router.js';
4
- import { PageRouter } from './core/page-router.js';
5
- import { generateOpenAPIDocument } from './core/openapi.js';
6
- import { swaggerHtml } from './core/swagger-ui.js';
2
+ import { Server } from './core/server';
3
+ import { ApiRouter } from './core/api-router';
4
+ import { PageRouter } from './core/page-router';
5
+ import { generateOpenAPIDocument } from './core/openapi';
6
+ import { swaggerHtml } from './core/swagger-ui';
7
7
  // Import utils
8
- import { collectRoutes } from './utils/index.js';
8
+ import { collectRoutes } from './utils/index';
9
9
  import { METHOD_NOT_ALLOWED, NOT_FOUND, OPENAPI_ERROR } from './utils/response';
10
10
  // Import middleware
11
- import { createValidationMiddleware } from './middleware/validator.js';
11
+ import { createValidationMiddleware } from './middleware/validator';
12
12
  export class Burger {
13
13
  options;
14
14
  /**
@@ -387,9 +387,22 @@ export class Burger {
387
387
  for (let i = 0; i < middlewareLen; i++) {
388
388
  // Get the current middleware
389
389
  const result = await middlewares[i](request);
390
- // If the result is a response, return it
390
+ // If the result is a response
391
391
  if (result instanceof Response) {
392
- return result; // Short-circuit with a response
392
+ // Short-circuit with a response, but still run collected after middlewares (e.g., CORS)
393
+ let response = result;
394
+ // Fast paths for after functions
395
+ if (afterCount === 0) {
396
+ return response;
397
+ }
398
+ if (afterCount === 1) {
399
+ return afterStack[0](response);
400
+ }
401
+ // Apply after middlewares in reverse order (LIFO)
402
+ for (let j = afterCount - 1; j >= 0; j--) {
403
+ response = await afterStack[j](response);
404
+ }
405
+ return response;
393
406
  }
394
407
  // If the result is a function, save it to the afterStack
395
408
  else if (typeof result === 'function') {
@@ -442,4 +455,4 @@ export class Burger {
442
455
  }
443
456
  }
444
457
  // Export utils
445
- export { setDir } from './utils/index.js';
458
+ export { setDir } from './utils/index';
@@ -1,4 +1,4 @@
1
- import type { RouteSchema, Middleware } from '@burgerTypes';
1
+ import type { RouteSchema, Middleware } from '../types/index';
2
2
  /**
3
3
  * createValidationMiddleware:
4
4
  * - Precompute a smaller runtime descriptor per method to avoid
@@ -0,0 +1,216 @@
1
+ import type { BunRequest, Server } from 'bun';
2
+ import type { ServeOptions as BunServerOptions } from 'bun';
3
+ import { z } from 'zod';
4
+ export interface ServerOptions extends Omit<BunServerOptions, 'fetch' | 'port' | 'reusePort' | 'ipv6Only' | 'unix' | 'error' | 'id' | 'development'> {
5
+ /**
6
+ * The title of the API. This is an optional property that can be used
7
+ * to specify a custom title for the API documentation.
8
+ */
9
+ title?: string;
10
+ /**
11
+ * The description of the API. This is an optional property that can be used
12
+ * to provide a brief overview of the API.
13
+ */
14
+ description?: string;
15
+ /**
16
+ * The directory path to load API routes from.
17
+ * If not specified, no API routes are loaded.
18
+ */
19
+ apiDir?: string;
20
+ /**
21
+ * The prefix for the API routes.
22
+ * If not specified, the default prefix is 'api'.
23
+ */
24
+ apiPrefix?: string;
25
+ /**
26
+ * The directory path to load Page routes from.
27
+ * If not specified, no Page routes are loaded.
28
+ * Page routes are not yet supported, but will be supported in the future.
29
+ */
30
+ pageDir?: string;
31
+ /**
32
+ * The prefix for the Page routes.
33
+ * If not specified, the default prefix is 'pages'.
34
+ */
35
+ pagePrefix?: string;
36
+ /**
37
+ * Global middleware to be executed before each request.
38
+ */
39
+ globalMiddleware?: Middleware[];
40
+ /**
41
+ * The version of the API. This is an optional property that can be used
42
+ * to specify the version of the API.
43
+ */
44
+ version?: string;
45
+ /**
46
+ * Enables or disables debug mode. This is an optional property
47
+ * that, when set to true, can be used to output additional debugging
48
+ * information to the console or logs to aid in development and troubleshooting.
49
+ */
50
+ debug?: boolean;
51
+ }
52
+ type DefaultRequestProperties = {
53
+ params?: Record<string, unknown>;
54
+ query?: Record<string, unknown>;
55
+ body?: Record<string, unknown>;
56
+ };
57
+ export interface BurgerRequest<RequestValidatedProperties extends DefaultRequestProperties = DefaultRequestProperties> extends Omit<BunRequest<string>, 'params'> {
58
+ /**
59
+ * Contains URL parameters extracted from the request path.
60
+ * This property is only present if the request path matches a route
61
+ * with dynamic parameters.
62
+ *
63
+ * For example, if the route is `/users/:id`, and the request path is
64
+ * `/users/123`, then the `params` property will be `{ id: '123' }`.
65
+ */
66
+ params?: Record<string, string>;
67
+ /**
68
+ * Contains validated data for the request.
69
+ * This is an optional property that will only be present if
70
+ * a middleware has validated the request data and attached the
71
+ * validated data to the request.
72
+ *
73
+ * Properties:
74
+ * - `params`: Validated URL parameters.
75
+ * - `query`: Validated query string parameters.
76
+ * - `body`: Validated request body (if JSON).
77
+ */
78
+ validated: RequestValidatedProperties;
79
+ /**
80
+ * Contains the wildcard parameters.
81
+ * This is an optional property that will only be present if
82
+ * the request path matches a route with a wildcard parameter.
83
+ * For example, if the route is `/users/[...]`, and the request path is
84
+ * `/users/123/456`, then the `wildcardParams` property will be `['123', '456']`.
85
+ */
86
+ wildcardParams?: string[];
87
+ }
88
+ /**
89
+ * Represents what a middleware can return to control the request flow:
90
+ * - Response: Immediately send this response back to the client
91
+ * - Function: Continue processing, but transform the final response
92
+ * - undefined: Continue to the next middleware or handler
93
+ */
94
+ export type BurgerNext = Response | ((response: Response) => Promise<Response>) | undefined;
95
+ /**
96
+ * A middleware function that processes HTTP requests before they reach the final handler.
97
+ *
98
+ * What middleware can do:
99
+ * - Change the request (add data, modify headers, etc.)
100
+ * - Check if the request is valid
101
+ * - Stop the request by returning a Response
102
+ * - Let the request continue by returning undefined
103
+ * - Transform the final response by returning a function
104
+ *
105
+ * @param request - The HTTP request with Burger framework enhancements
106
+ * @returns One of three things:
107
+ * - Response: Stop here, send this response back
108
+ * - Function: Continue processing, but transform the final response
109
+ * - undefined: I'm done, continue to the next step
110
+ */
111
+ export type Middleware = ((request: BurgerRequest) => Promise<BurgerNext>) | ((request: BurgerRequest) => BurgerNext);
112
+ /**
113
+ * A request handler function that processes incoming HTTP requests.
114
+ * @param request - The BurgerRequest object containing request object.
115
+ * @returns A Response object or a Promise that resolves to a Response object.
116
+ */
117
+ export type RequestHandler = (request: BurgerRequest) => Promise<Response> | Response;
118
+ /**
119
+ * A fetch handler function that can be used to handle a request.
120
+ * This can be a function that returns a Promise of a Response,
121
+ * or a function that returns a Response.
122
+ */
123
+ export type FetchHandler = (request: Request, server?: Server) => Promise<Response> | Response;
124
+ export interface RouteDefinition {
125
+ /**
126
+ * The path of the route.
127
+ */
128
+ path: string;
129
+ /**
130
+ * An object containing the request handlers for each HTTP method.
131
+ * The keys are the HTTP method names (e.g. "GET", "POST", etc.).
132
+ * The values are the request handlers for that method.
133
+ */
134
+ handlers: {
135
+ [method: string]: RequestHandler;
136
+ };
137
+ /**
138
+ * An array of middleware functions to run before the request handler.
139
+ * The middleware functions will be run in the order they are specified.
140
+ */
141
+ middleware?: Middleware[];
142
+ /**
143
+ * An optional route schema to validate the request data against.
144
+ * This property is set by the user when defining a route.
145
+ * The schema is used to validate the request data for each HTTP method.
146
+ * The keys are the HTTP method names (in lowercase) and the values are
147
+ * the Zod schema objects for that method.
148
+ */
149
+ schema?: RouteSchema;
150
+ /**
151
+ * Optional OpenAPI metadata to generate documentation for the route.
152
+ * If provided, this property should define an object where each key
153
+ * is an HTTP method name (in lowercase), and the value is an object
154
+ * containing the OpenAPI metadata for that method.
155
+ */
156
+ openapi?: openapi;
157
+ /**
158
+ * Indicates if this route is a wildcard route.
159
+ * True for routes using the `[...]` syntax.
160
+ * This property is used internally to identify wildcard routes.
161
+ */
162
+ isWildcard?: boolean;
163
+ }
164
+ /**
165
+ * Define a type for the route schema.
166
+ * For each HTTP method (in lowercase), you can optionally define:
167
+ * - params: for URL parameters,
168
+ * - query: for query string parameters,
169
+ * - body: for the request body.
170
+ */
171
+ export type RouteSchema = {
172
+ [method: string]: {
173
+ params?: z.ZodObject<any, any>;
174
+ query?: z.ZodObject<any, any>;
175
+ body?: z.ZodObject<any, any>;
176
+ };
177
+ };
178
+ /**
179
+ * Optional OpenAPI metadata to generate documentation for the route.
180
+ * Each key is an HTTP method name (in lowercase) and the value is an object
181
+ * containing the OpenAPI metadata for that method.
182
+ *
183
+ * If the `openapi` property is not defined, the route will not be included in
184
+ * the generated OpenAPI documentation.
185
+ *
186
+ * See the OpenAPI specification for the possible properties and their
187
+ * descriptions.
188
+ */
189
+ export type openapi = {
190
+ [method: string]: {
191
+ summary?: string;
192
+ description?: string;
193
+ tags?: string[];
194
+ operationId?: string;
195
+ deprecated?: boolean;
196
+ responses?: Record<string, any>;
197
+ externalDocs?: {
198
+ description?: string;
199
+ url?: string;
200
+ };
201
+ };
202
+ };
203
+ export interface PageDefinition {
204
+ path: string;
205
+ handler: RequestHandler;
206
+ middleware?: Middleware[];
207
+ }
208
+ export interface TrieNode {
209
+ children: Map<string, TrieNode>;
210
+ paramChild?: TrieNode;
211
+ paramName?: string;
212
+ wildcardChild?: TrieNode;
213
+ isWildcard?: boolean;
214
+ route?: RouteDefinition;
215
+ }
216
+ export {};
@@ -0,0 +1 @@
1
+ import { z } from 'zod';
@@ -1,4 +1,4 @@
1
- import { normalizePath } from './index.js';
1
+ import { normalizePath } from './index';
2
2
  /**
3
3
  * Generates an HTTP error response based on the request's "Accept" header.
4
4
  *
@@ -1,4 +1,4 @@
1
- export { ROUTE_CONSTANTS, HTTP_METHODS, compareRoutes, getRouteSpecificity, collectRoutes, } from './routing.js';
1
+ export { ROUTE_CONSTANTS, HTTP_METHODS, compareRoutes, getRouteSpecificity, collectRoutes, } from './routing';
2
2
  /**
3
3
  * Resolves the given path to the specified directory.
4
4
  * @param directory the directory to resolve to
@@ -1,6 +1,6 @@
1
1
  import { resolve } from 'path';
2
2
  // Export constants
3
- export { ROUTE_CONSTANTS, HTTP_METHODS, compareRoutes, getRouteSpecificity, collectRoutes, } from './routing.js';
3
+ export { ROUTE_CONSTANTS, HTTP_METHODS, compareRoutes, getRouteSpecificity, collectRoutes, } from './routing';
4
4
  /**
5
5
  * Resolves the given path to the specified directory.
6
6
  * @param directory the directory to resolve to
@@ -1,4 +1,4 @@
1
- import type { PageDefinition, RouteDefinition, TrieNode } from '@burgerTypes';
1
+ import type { PageDefinition, RouteDefinition, TrieNode } from '../types/index';
2
2
  /**
3
3
  * Constants for route handling.
4
4
  */
package/package.json CHANGED
@@ -1,89 +1,89 @@
1
- {
2
- "name": "burger-api",
3
- "version": "0.4.0",
4
- "author": "Isfhan Ahmed",
5
- "type": "module",
6
- "module": "dist/src/index.js",
7
- "types": "dist/src/index.d.ts",
8
- "files": [
9
- "dist"
10
- ],
11
- "scripts": {
12
- "typecheck": "tsc --noEmit",
13
- "build": "tsc --project tsconfig.build.json && tsc-alias -p tsconfig.build.json",
14
- "test": "bun test",
15
- "dev": "bun run examples/file-base-static-page-routing-app/index.ts"
16
- },
17
- "keywords": [
18
- "burger-api",
19
- "burger-api-framework",
20
- "bun",
21
- "bunjs",
22
- "bun-framework",
23
- "fast-backend",
24
- "javascript-backend",
25
- "high-performance",
26
- "esm",
27
- "typescript",
28
- "openapi",
29
- "swagger-ui",
30
- "declarative-routing",
31
- "api-framework",
32
- "modern-backend",
33
- "backend-framework",
34
- "server",
35
- "bun-native",
36
- "js-backend",
37
- "fast-api",
38
- "scalable-backend",
39
- "backend-development",
40
- "modern-api",
41
- "api-development",
42
- "backend-engine",
43
- "efficient",
44
- "minimalist-backend",
45
- "bun-powered",
46
- "open-source",
47
- "typescript-backend",
48
- "performance",
49
- "rapid-development",
50
- "web-framework",
51
- "api-server",
52
- "dynamic-routing",
53
- "backend-routing",
54
- "extensible",
55
- "modular",
56
- "declarative-api",
57
- "lightweight",
58
- "contemporary-backend",
59
- "fast-javascript",
60
- "bun-js-framework",
61
- "bun-backend",
62
- "bun-api-framework",
63
- "pakistan-backend",
64
- "pakistan-api-framework",
65
- "pakistan-api-server",
66
- "pakistan-backend-framework",
67
- "pakistan-bunjs-framework",
68
- "pakistan-javascript-framework"
69
- ],
70
- "license": "MIT",
71
- "repository": {
72
- "type": "git",
73
- "url": "git+https://github.com/isfhan/burger-api.git"
74
- },
75
- "bugs": {
76
- "url": "https://github.com/isfhan/burger-api/issues"
77
- },
78
- "homepage": "https://burger-api.com",
79
- "dependencies": {
80
- "zod": "^4.0.17"
81
- },
82
- "devDependencies": {
83
- "@types/bun": "latest",
84
- "tsc-alias": "^1.8.16"
85
- },
86
- "peerDependencies": {
87
- "typescript": "^5.7.3"
88
- }
1
+ {
2
+ "name": "burger-api",
3
+ "version": "0.5.0",
4
+ "author": "Isfhan Ahmed",
5
+ "type": "module",
6
+ "module": "dist/src/index.js",
7
+ "types": "dist/src/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "scripts": {
12
+ "typecheck": "tsc --noEmit",
13
+ "build": "tsc --project tsconfig.build.json",
14
+ "prepare": "bun run build",
15
+ "test": "bun test",
16
+ "dev": "bun run examples/file-base-static-page-routing-app/index.ts"
17
+ },
18
+ "keywords": [
19
+ "burger-api",
20
+ "burger-api-framework",
21
+ "bun",
22
+ "bunjs",
23
+ "bun-framework",
24
+ "fast-backend",
25
+ "javascript-backend",
26
+ "high-performance",
27
+ "esm",
28
+ "typescript",
29
+ "openapi",
30
+ "swagger-ui",
31
+ "declarative-routing",
32
+ "api-framework",
33
+ "modern-backend",
34
+ "backend-framework",
35
+ "server",
36
+ "bun-native",
37
+ "js-backend",
38
+ "fast-api",
39
+ "scalable-backend",
40
+ "backend-development",
41
+ "modern-api",
42
+ "api-development",
43
+ "backend-engine",
44
+ "efficient",
45
+ "minimalist-backend",
46
+ "bun-powered",
47
+ "open-source",
48
+ "typescript-backend",
49
+ "performance",
50
+ "rapid-development",
51
+ "web-framework",
52
+ "api-server",
53
+ "dynamic-routing",
54
+ "backend-routing",
55
+ "extensible",
56
+ "modular",
57
+ "declarative-api",
58
+ "lightweight",
59
+ "contemporary-backend",
60
+ "fast-javascript",
61
+ "bun-js-framework",
62
+ "bun-backend",
63
+ "bun-api-framework",
64
+ "pakistan-backend",
65
+ "pakistan-api-framework",
66
+ "pakistan-api-server",
67
+ "pakistan-backend-framework",
68
+ "pakistan-bunjs-framework",
69
+ "pakistan-javascript-framework"
70
+ ],
71
+ "license": "MIT",
72
+ "repository": {
73
+ "type": "git",
74
+ "url": "git+https://github.com/isfhan/burger-api.git"
75
+ },
76
+ "bugs": {
77
+ "url": "https://github.com/isfhan/burger-api/issues"
78
+ },
79
+ "homepage": "https://burger-api.com",
80
+ "dependencies": {
81
+ "zod": "^4.0.17"
82
+ },
83
+ "devDependencies": {
84
+ "@types/bun": "latest"
85
+ },
86
+ "peerDependencies": {
87
+ "typescript": "^5.7.3"
88
+ }
89
89
  }
@@ -1,11 +0,0 @@
1
- /**
2
- * Simple Zod to JSON Schema converter for Zod 4.x
3
- * This utility converts Zod schemas to JSON Schema format
4
- * for use in OpenAPI documentation generation
5
- */
6
- /**
7
- * Converts a Zod schema to JSON Schema format
8
- * @param schema - The Zod schema to convert
9
- * @returns JSON Schema object
10
- */
11
- export declare function zodToJsonSchema(schema: any): any;
@@ -1,117 +0,0 @@
1
- /**
2
- * Simple Zod to JSON Schema converter for Zod 4.x
3
- * This utility converts Zod schemas to JSON Schema format
4
- * for use in OpenAPI documentation generation
5
- */
6
- /**
7
- * Converts a Zod schema to JSON Schema format
8
- * @param schema - The Zod schema to convert
9
- * @returns JSON Schema object
10
- */
11
- export function zodToJsonSchema(schema) {
12
- if (!schema) {
13
- return { type: 'string' };
14
- }
15
- // Simple type detection based on schema properties
16
- try {
17
- // Check if it's a string schema
18
- if (schema._def?.typeName === 'ZodString') {
19
- return { type: 'string' };
20
- }
21
- // Check if it's a number schema
22
- if (schema._def?.typeName === 'ZodNumber') {
23
- return { type: 'number' };
24
- }
25
- // Check if it's a boolean schema
26
- if (schema._def?.typeName === 'ZodBoolean') {
27
- return { type: 'boolean' };
28
- }
29
- // Check if it's an array schema
30
- if (schema._def?.typeName === 'ZodArray') {
31
- return {
32
- type: 'array',
33
- items: { type: 'string' } // Default to string items
34
- };
35
- }
36
- // Check if it's an object schema
37
- if (schema._def?.typeName === 'ZodObject') {
38
- const objectSchema = {
39
- type: 'object',
40
- properties: {},
41
- required: []
42
- };
43
- // Try to get the shape
44
- let shape = {};
45
- if (schema.shape) {
46
- shape = typeof schema.shape === 'function' ? schema.shape() : schema.shape;
47
- }
48
- for (const [key, value] of Object.entries(shape)) {
49
- const fieldDef = value;
50
- objectSchema.properties[key] = { type: 'string' }; // Default to string
51
- // Check if field is optional
52
- if (fieldDef._def?.typeName !== 'ZodOptional') {
53
- objectSchema.required.push(key);
54
- }
55
- }
56
- return objectSchema;
57
- }
58
- // Check if it's an optional schema
59
- if (schema._def?.typeName === 'ZodOptional') {
60
- return { type: 'string' };
61
- }
62
- // Check if it's a nullable schema
63
- if (schema._def?.typeName === 'ZodNullable') {
64
- return {
65
- oneOf: [
66
- { type: 'string' },
67
- { type: 'null' }
68
- ]
69
- };
70
- }
71
- // Check if it's a union schema
72
- if (schema._def?.typeName === 'ZodUnion') {
73
- return {
74
- oneOf: [
75
- { type: 'string' },
76
- { type: 'number' }
77
- ]
78
- };
79
- }
80
- // Check if it's an enum schema
81
- if (schema._def?.typeName === 'ZodEnum') {
82
- try {
83
- const values = schema._def.values || [];
84
- return {
85
- type: 'string',
86
- enum: values
87
- };
88
- }
89
- catch {
90
- return { type: 'string' };
91
- }
92
- }
93
- // Check if it's a literal schema
94
- if (schema._def?.typeName === 'ZodLiteral') {
95
- try {
96
- const value = schema._def.value;
97
- return {
98
- type: typeof value,
99
- const: value
100
- };
101
- }
102
- catch {
103
- return { type: 'string' };
104
- }
105
- }
106
- // Check if it's a default schema
107
- if (schema._def?.typeName === 'ZodDefault') {
108
- return { type: 'string' };
109
- }
110
- }
111
- catch (error) {
112
- // If any error occurs, fall back to string type
113
- console.warn('Error processing Zod schema:', error);
114
- }
115
- // Fallback for unknown types
116
- return { type: 'string' };
117
- }