bro-framework 1.2.7 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/bin/bro.js +5 -1
- package/package.json +7 -2
- package/src/index.d.ts +16 -12
- package/src/router.js +1 -1
package/README.md
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
+
<img src="https://brojs.yessindevs.me/bro.js.png" alt="bro.js Logo" width="256" height="256">
|
|
2
3
|
<h1 align="center">bro.js</h1>
|
|
3
4
|
<p align="center">
|
|
4
5
|
<strong>The zero-boilerplate Node.js framework that actually has your back.</strong>
|
|
5
6
|
</p>
|
|
6
7
|
<p align="center">
|
|
8
|
+
<a href="https://www.npmjs.com/package/bro-framework"><img src="https://img.shields.io/npm/v/bro-framework.svg?style=flat-square&color=e11d48" alt="npm version"></a>
|
|
7
9
|
<img src="https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square" alt="License: MIT">
|
|
8
10
|
<img src="https://img.shields.io/badge/Node.js-%3E%3D%2018-green.svg?style=flat-square" alt="Node.js: >= 18">
|
|
9
11
|
<img src="https://img.shields.io/badge/Architecture-Pure%20ESM-orange.svg?style=flat-square" alt="Architecture: Pure ESM">
|
|
@@ -15,7 +17,6 @@
|
|
|
15
17
|
<a href="https://brojs.yessindevs.me">Documentation Website</a>
|
|
16
18
|
</p>
|
|
17
19
|
</p>
|
|
18
|
-
|
|
19
20
|
---
|
|
20
21
|
|
|
21
22
|
> "NestJS wants four decorators, three modules, and an existential crisis just to handle a GET request. Express makes you write the same 40 lines of CORS, JSON parsing, and auth middleware for every project. bro.js gives you file routing, auto-validation, JWT auth, WebSockets, and live docs out of the box. Be honest: you just want to return an object."
|
package/bin/bro.js
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import fs from 'fs';
|
|
5
5
|
import { pathToFileURL } from 'url';
|
|
6
|
+
import { register } from 'tsx/esm/api';
|
|
7
|
+
|
|
8
|
+
register();
|
|
9
|
+
|
|
6
10
|
import { createServer } from '../src/server.js';
|
|
7
11
|
import { colors, printBanner, printRoute, printHotReload } from '../src/logger.js';
|
|
8
12
|
import { scanTasks } from '../src/tasks.js';
|
|
@@ -218,7 +222,7 @@ async function bootstrap() {
|
|
|
218
222
|
const watcher = chokidar.watch(routesDir, { ignoreInitial: true });
|
|
219
223
|
|
|
220
224
|
watcher.on('all', async (event, filepath) => {
|
|
221
|
-
if (!filepath.endsWith('.js')) return;
|
|
225
|
+
if (!filepath.endsWith('.js') && !filepath.endsWith('.ts')) return;
|
|
222
226
|
|
|
223
227
|
try {
|
|
224
228
|
const reloadStartTime = performance.now();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bro-framework",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "The No-BS Backend Framework for Node.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -10,9 +10,13 @@
|
|
|
10
10
|
"author": "Yessindevs",
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"main": "src/index.js",
|
|
13
|
+
"types": "src/index.d.ts",
|
|
13
14
|
"type": "module",
|
|
14
15
|
"exports": {
|
|
15
|
-
".":
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./src/index.d.ts",
|
|
18
|
+
"default": "./src/index.js"
|
|
19
|
+
}
|
|
16
20
|
},
|
|
17
21
|
"bin": {
|
|
18
22
|
"bro": "./bin/bro.js"
|
|
@@ -32,6 +36,7 @@
|
|
|
32
36
|
"multer": "^2.3.0",
|
|
33
37
|
"node-cron": "^4.6.0",
|
|
34
38
|
"socket.io": "^4.8.3",
|
|
39
|
+
"tsx": "^4.23.13",
|
|
35
40
|
"zod": "^3.23.8",
|
|
36
41
|
"zod-to-json-schema": "^3.25.2"
|
|
37
42
|
},
|
package/src/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { z, ZodTypeAny } from 'zod';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
type InferZod<T> = T extends ZodTypeAny ? z.infer<T> : any;
|
|
4
|
+
|
|
5
|
+
export interface BroContext<Body = any, Params = any, Query = any> {
|
|
6
|
+
body: InferZod<Body>;
|
|
7
|
+
params: InferZod<Params>;
|
|
8
|
+
query: InferZod<Query>;
|
|
7
9
|
user?: any;
|
|
8
10
|
db?: any;
|
|
9
11
|
io?: any;
|
|
@@ -11,24 +13,26 @@ export interface BroContext {
|
|
|
11
13
|
error?: any;
|
|
12
14
|
}
|
|
13
15
|
|
|
14
|
-
export interface RouteConfig {
|
|
16
|
+
export interface RouteConfig<Body = any, Params = any, Query = any> {
|
|
15
17
|
auth?: boolean;
|
|
16
18
|
upload?: boolean;
|
|
17
|
-
body?:
|
|
18
|
-
params?:
|
|
19
|
-
query?:
|
|
19
|
+
body?: Body;
|
|
20
|
+
params?: Params;
|
|
21
|
+
query?: Query;
|
|
20
22
|
rateLimit?: {
|
|
21
23
|
windowMs: number;
|
|
22
24
|
max: number;
|
|
23
25
|
};
|
|
24
26
|
summary?: string;
|
|
25
|
-
handler: (ctx: BroContext) => Promise<any> | any;
|
|
27
|
+
handler: (ctx: BroContext<Body, Params, Query>) => Promise<any> | any;
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
export function defineRoute
|
|
30
|
+
export function defineRoute<Body = any, Params = any, Query = any>(
|
|
31
|
+
config: RouteConfig<Body, Params, Query>
|
|
32
|
+
): RouteConfig<Body, Params, Query>;
|
|
29
33
|
|
|
30
34
|
export interface BroConfig {
|
|
31
|
-
env?:
|
|
35
|
+
env?: ZodTypeAny;
|
|
32
36
|
server?: {
|
|
33
37
|
port?: number;
|
|
34
38
|
cors?: boolean | object;
|
package/src/router.js
CHANGED
|
@@ -18,7 +18,7 @@ export function scanDir(dir, fileList = []) {
|
|
|
18
18
|
const filePath = path.join(dir, file);
|
|
19
19
|
if (fs.statSync(filePath).isDirectory()) {
|
|
20
20
|
scanDir(filePath, fileList);
|
|
21
|
-
} else if (filePath.endsWith('.js')) {
|
|
21
|
+
} else if (filePath.endsWith('.js') || filePath.endsWith('.ts')) {
|
|
22
22
|
fileList.push(filePath);
|
|
23
23
|
}
|
|
24
24
|
}
|