burger-api 0.2.3 → 0.3.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 +8 -8
- package/dist/src/core/api-router.js +1 -1
- package/dist/src/core/openapi.js +2 -1
- package/dist/src/core/page-router.js +1 -1
- package/dist/src/core/server.js +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +9 -9
- package/dist/src/utils/error.js +1 -1
- package/dist/src/utils/index.d.ts +1 -1
- package/dist/src/utils/index.js +1 -1
- package/dist/src/utils/zod-to-json.d.ts +11 -0
- package/dist/src/utils/zod-to-json.js +117 -0
- package/package.json +88 -89
package/README.md
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
[](https://github.com/isfhan/burger-api)
|
|
6
6
|
[](LICENSE)
|
|
7
|
-
[](https://bun.sh)
|
|
8
|
+
[](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
|
|
@@ -59,13 +59,13 @@ burger-api is built to offer a robust developer experience through:
|
|
|
59
59
|
|
|
60
60
|
## 📣 Changelog
|
|
61
61
|
|
|
62
|
-
### Latest Version: 0.
|
|
62
|
+
### Latest Version: 0.3.0 (August 15, 2025)
|
|
63
63
|
|
|
64
|
-
-
|
|
65
|
-
-
|
|
66
|
-
-
|
|
67
|
-
- Updated
|
|
68
|
-
-
|
|
64
|
+
- 🔧 **Updated Zod to version 4:**
|
|
65
|
+
- Updated Zod version from 3.x to 4.x
|
|
66
|
+
- Updated built-in request validation middleware to use Zod 4
|
|
67
|
+
- Updated and better request validation middleware error handling
|
|
68
|
+
- Removed Zod-to-json-schema dependency and use Zod 4 directly
|
|
69
69
|
|
|
70
70
|
For a complete list of changes, please check the [Changelog](CHANGELOG.md) file.
|
|
71
71
|
|
|
@@ -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 '
|
|
5
|
+
import { cleanPrefix, normalizePath, ROUTE_CONSTANTS, HTTP_METHODS, } from '@utils';
|
|
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.
|
package/dist/src/core/openapi.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { zodToJsonSchema } from 'zod-to-json
|
|
1
|
+
import { zodToJsonSchema } from '../utils/zod-to-json.js';
|
|
2
2
|
/**
|
|
3
3
|
* Builds an array of OpenAPI 3.0 parameters based on the Zod schema.
|
|
4
4
|
* For each property in the Zod schema, an OpenAPI parameter is constructed
|
|
@@ -46,6 +46,7 @@ function buildParameters(zodSchema, location) {
|
|
|
46
46
|
function buildRequestBody(zodSchema) {
|
|
47
47
|
if (!zodSchema)
|
|
48
48
|
return undefined;
|
|
49
|
+
// Use our custom Zod to JSON schema converter
|
|
49
50
|
const jsonSchema = zodToJsonSchema(zodSchema);
|
|
50
51
|
return {
|
|
51
52
|
content: {
|
|
@@ -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 '
|
|
5
|
+
import { cleanPrefix, normalizePath, compareRoutes, ROUTE_CONSTANTS, } from '@utils';
|
|
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.
|
package/dist/src/core/server.js
CHANGED
package/dist/src/index.d.ts
CHANGED
|
@@ -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 '
|
|
76
|
+
export { setDir } from '@utils';
|
|
77
77
|
export type { ServerOptions, RequestHandler, BurgerRequest, BurgerNext, Middleware, openapi, } from '@burgerTypes';
|
package/dist/src/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// Import stuff from core
|
|
2
|
-
import { Server } from '
|
|
3
|
-
import { ApiRouter } from '
|
|
4
|
-
import { PageRouter } from '
|
|
5
|
-
import { generateOpenAPIDocument } from '
|
|
6
|
-
import { swaggerHtml } from '
|
|
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';
|
|
7
7
|
// Import utils
|
|
8
|
-
import { collectRoutes } from '
|
|
9
|
-
import { METHOD_NOT_ALLOWED, NOT_FOUND, OPENAPI_ERROR } from '
|
|
8
|
+
import { collectRoutes } from '@utils';
|
|
9
|
+
import { METHOD_NOT_ALLOWED, NOT_FOUND, OPENAPI_ERROR } from '@utils/response';
|
|
10
10
|
// Import middleware
|
|
11
|
-
import { createValidationMiddleware } from '
|
|
11
|
+
import { createValidationMiddleware } from '@middleware/validator.js';
|
|
12
12
|
export class Burger {
|
|
13
13
|
options;
|
|
14
14
|
/**
|
|
@@ -284,4 +284,4 @@ export class Burger {
|
|
|
284
284
|
}
|
|
285
285
|
}
|
|
286
286
|
// Export utils
|
|
287
|
-
export { setDir } from '
|
|
287
|
+
export { setDir } from '@utils';
|
package/dist/src/utils/error.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { ROUTE_CONSTANTS, HTTP_METHODS, compareRoutes, getRouteSpecificity, collectRoutes, } from '
|
|
1
|
+
export { ROUTE_CONSTANTS, HTTP_METHODS, compareRoutes, getRouteSpecificity, collectRoutes, } from '@utils/routing.js';
|
|
2
2
|
/**
|
|
3
3
|
* Resolves the given path to the specified directory.
|
|
4
4
|
* @param directory the directory to resolve to
|
package/dist/src/utils/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { resolve } from 'path';
|
|
2
2
|
// Export constants
|
|
3
|
-
export { ROUTE_CONSTANTS, HTTP_METHODS, compareRoutes, getRouteSpecificity, collectRoutes, } from '
|
|
3
|
+
export { ROUTE_CONSTANTS, HTTP_METHODS, compareRoutes, getRouteSpecificity, collectRoutes, } from '@utils/routing.js';
|
|
4
4
|
/**
|
|
5
5
|
* Resolves the given path to the specified directory.
|
|
6
6
|
* @param directory the directory to resolve to
|
|
@@ -0,0 +1,11 @@
|
|
|
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;
|
|
@@ -0,0 +1,117 @@
|
|
|
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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,90 +1,89 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "burger-api",
|
|
3
|
-
"version": "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": "^
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
"
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "burger-api",
|
|
3
|
+
"version": "0.3.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
|
+
}
|
|
90
89
|
}
|