@mateosuarezdev/brpc 1.0.50 → 1.0.53
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 +701 -0
- package/dist/auth/types.d.ts +1 -0
- package/dist/auth/utils.d.ts +1 -0
- package/dist/cache/index.d.ts +118 -0
- package/dist/client/index.js +2 -2
- package/dist/client/index.js.map +6 -6
- package/dist/client/storage.d.ts +1 -1
- package/dist/client/types.d.ts +12 -0
- package/dist/client/ws-manager.d.ts +1 -1
- package/dist/context.d.ts +2 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -3
- package/dist/index.js.map +10 -8
- package/dist/middlewares/cors/index.d.ts +1 -0
- package/dist/middlewares/createMiddleware.d.ts +25 -0
- package/dist/middlewares/index.d.ts +1 -0
- package/dist/procedure.d.ts +4 -3
- package/dist/router/RouteMatcher.d.ts +3 -0
- package/dist/types.d.ts +2 -2
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/measure.d.ts +1 -0
- package/package.json +103 -103
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { BaseContext } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* Helper to define a reusable, typed middleware outside of a procedure chain.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* // Infer context type from your context creator
|
|
8
|
+
* const authMiddleware = createMiddleware(context, async (ctx) => {
|
|
9
|
+
* const session = await getSession(ctx.req);
|
|
10
|
+
* if (!session) throw new BRPCError({ code: "UNAUTHORIZED" });
|
|
11
|
+
* return { session };
|
|
12
|
+
* });
|
|
13
|
+
*
|
|
14
|
+
* // Or with an explicit generic (no context reference needed)
|
|
15
|
+
* const authMiddleware = createMiddleware<MyContext>(async (ctx) => {
|
|
16
|
+
* return { session: await getSession(ctx.req) };
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* createProcedure(context)
|
|
20
|
+
* .use(authMiddleware) // ctx.session is typed in the handler ✅
|
|
21
|
+
* .query(async ({ ctx }) => ctx.session.user);
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function createMiddleware<C extends BaseContext, TReturn extends Record<string, any> | void = void>(_context: (req: Request) => Promise<C>, fn: (ctx: C) => Promise<TReturn>): (ctx: C) => Promise<TReturn>;
|
|
25
|
+
export declare function createMiddleware<C extends BaseContext, TReturn extends Record<string, any> | void = void>(fn: (ctx: C) => Promise<TReturn>): (ctx: C) => Promise<TReturn>;
|
package/dist/procedure.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ import type { BaseContext, Handler, InferInput, Procedure, StreamableResponse }
|
|
|
3
3
|
import type { BunFile } from "bun";
|
|
4
4
|
declare class ProcedureBuilder<C extends BaseContext> {
|
|
5
5
|
private middlewares;
|
|
6
|
-
constructor(middlewares?: ((ctx:
|
|
7
|
-
use
|
|
6
|
+
constructor(middlewares?: ((ctx: any) => Promise<Record<string, any> | void>)[]);
|
|
7
|
+
use<M extends (ctx: C) => Promise<Record<string, any> | void>>(middleware: M): ProcedureBuilder<Awaited<ReturnType<M>> extends Record<string, any> ? C & Awaited<ReturnType<M>> : C>;
|
|
8
8
|
input<I extends z.ZodType>(schema: I): InputProcedureBuilder<C, I>;
|
|
9
9
|
query<O>(handler: Handler<C, {}, O>): Procedure<C, z.ZodObject<{}>, O, "query">;
|
|
10
10
|
mutation<O>(handler: Handler<C, {}, O>): Procedure<C, z.ZodObject<{}>, O, "mutation">;
|
|
@@ -18,7 +18,7 @@ declare class InputProcedureBuilder<C extends BaseContext, I extends z.ZodType>
|
|
|
18
18
|
private middlewares;
|
|
19
19
|
private inputSchema;
|
|
20
20
|
private timeoutMs?;
|
|
21
|
-
constructor(middlewares: ((ctx:
|
|
21
|
+
constructor(middlewares: ((ctx: any) => Promise<Record<string, any> | void>)[], inputSchema: I, timeoutMs?: number | undefined);
|
|
22
22
|
/**
|
|
23
23
|
* Set a custom timeout for this procedure (in milliseconds).
|
|
24
24
|
* Overrides the default router timeout.
|
|
@@ -32,5 +32,6 @@ declare class InputProcedureBuilder<C extends BaseContext, I extends z.ZodType>
|
|
|
32
32
|
fileStream(handler: Handler<C, InferInput<I>, StreamableResponse | Blob | string>): Procedure<C, I, StreamableResponse | Blob | string, "fileStream">;
|
|
33
33
|
html(handler: Handler<C, {}, string>): Procedure<C, z.ZodObject<{}>, string, "html">;
|
|
34
34
|
}
|
|
35
|
+
export declare function createProcedure<C extends BaseContext>(_context: (req: Request) => Promise<C>): ProcedureBuilder<C>;
|
|
35
36
|
export declare function createProcedure<C extends BaseContext>(): ProcedureBuilder<C>;
|
|
36
37
|
export {};
|
package/dist/types.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ export type Procedure<C extends BaseContext, I extends z.ZodType, O, P> = {
|
|
|
37
37
|
_ctx: C;
|
|
38
38
|
_type: P;
|
|
39
39
|
_timeout?: number;
|
|
40
|
-
middlewares: ((ctx:
|
|
40
|
+
middlewares: ((ctx: any) => Promise<Record<string, any> | void>)[];
|
|
41
41
|
handler?: Handler<C, InferInput<I>, O>;
|
|
42
42
|
};
|
|
43
43
|
export type Routes = {
|
|
@@ -46,7 +46,7 @@ export type Routes = {
|
|
|
46
46
|
export type RouterConfig<C extends BaseContext> = {
|
|
47
47
|
context: (req: Request) => Promise<C>;
|
|
48
48
|
routes: Routes;
|
|
49
|
-
globalMiddlewares?: ((ctx: C) => Promise<void>)[];
|
|
49
|
+
globalMiddlewares?: ((ctx: C) => Promise<Record<string, any> | void>)[];
|
|
50
50
|
/**
|
|
51
51
|
* Simple hooks to debug websockets, you don't need to pass anything
|
|
52
52
|
* for brpc subscription procedures to work
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./measure";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function measure<T>(label: string, fn: () => Promise<T>): Promise<T>;
|
package/package.json
CHANGED
|
@@ -1,103 +1,103 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@mateosuarezdev/brpc",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "A Type-Safe, Flexible Web application framework for Bun",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "./dist/index.cjs",
|
|
7
|
-
"module": "./dist/index.js",
|
|
8
|
-
"types": "./dist/index.d.ts",
|
|
9
|
-
"exports": {
|
|
10
|
-
".": {
|
|
11
|
-
"types": "./dist/index.d.ts",
|
|
12
|
-
"import": "./dist/index.js",
|
|
13
|
-
"require": "./dist/index.cjs"
|
|
14
|
-
},
|
|
15
|
-
"./storage": {
|
|
16
|
-
"types": "./dist/storage/index.d.ts",
|
|
17
|
-
"import": "./dist/storage/index.js",
|
|
18
|
-
"require": "./dist/storage/index.cjs"
|
|
19
|
-
},
|
|
20
|
-
"./client": {
|
|
21
|
-
"types": "./dist/client/index.d.ts",
|
|
22
|
-
"import": "./dist/client/index.js",
|
|
23
|
-
"require": "./dist/client/index.cjs"
|
|
24
|
-
},
|
|
25
|
-
"./client/react": {
|
|
26
|
-
"types": "./dist/client/react/index.d.ts",
|
|
27
|
-
"import": "./dist/client/react/index.js",
|
|
28
|
-
"require": "./dist/client/react/index.cjs"
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
"files": [
|
|
32
|
-
"dist/**/*.js",
|
|
33
|
-
"dist/**/*.cjs",
|
|
34
|
-
"dist/**/*.d.ts",
|
|
35
|
-
"dist/**/*.map"
|
|
36
|
-
],
|
|
37
|
-
"sideEffects": false,
|
|
38
|
-
"scripts": {
|
|
39
|
-
"build": "yarn clean && bun run build.ts && tsc --emitDeclarationOnly",
|
|
40
|
-
"typecheck": "tsc --noEmit",
|
|
41
|
-
"clean": "rimraf dist",
|
|
42
|
-
"prepublish": "yarn typecheck && yarn build",
|
|
43
|
-
"rel": "yarn npm publish --access public",
|
|
44
|
-
"rel:patch": "yarn version patch && yarn npm publish --access public",
|
|
45
|
-
"rel:minor": "yarn version minor && yarn npm publish --access public",
|
|
46
|
-
"rel:major": "yarn version major && yarn npm publish --access public"
|
|
47
|
-
},
|
|
48
|
-
"
|
|
49
|
-
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
"
|
|
59
|
-
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
"
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
"@types/
|
|
93
|
-
"react": "^19.2.
|
|
94
|
-
"react-dom": "^19.2.
|
|
95
|
-
"rimraf": "^6.0.1",
|
|
96
|
-
"sharp": "^0.34.4",
|
|
97
|
-
"typescript": "^5.9.3",
|
|
98
|
-
"zod": "^3.23.8"
|
|
99
|
-
},
|
|
100
|
-
"dependencies": {
|
|
101
|
-
"@mateosuarezdev/headers-builder": "^1.0.5"
|
|
102
|
-
}
|
|
103
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@mateosuarezdev/brpc",
|
|
3
|
+
"version": "1.0.53",
|
|
4
|
+
"description": "A Type-Safe, Flexible Web application framework for Bun",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"./storage": {
|
|
16
|
+
"types": "./dist/storage/index.d.ts",
|
|
17
|
+
"import": "./dist/storage/index.js",
|
|
18
|
+
"require": "./dist/storage/index.cjs"
|
|
19
|
+
},
|
|
20
|
+
"./client": {
|
|
21
|
+
"types": "./dist/client/index.d.ts",
|
|
22
|
+
"import": "./dist/client/index.js",
|
|
23
|
+
"require": "./dist/client/index.cjs"
|
|
24
|
+
},
|
|
25
|
+
"./client/react": {
|
|
26
|
+
"types": "./dist/client/react/index.d.ts",
|
|
27
|
+
"import": "./dist/client/react/index.js",
|
|
28
|
+
"require": "./dist/client/react/index.cjs"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist/**/*.js",
|
|
33
|
+
"dist/**/*.cjs",
|
|
34
|
+
"dist/**/*.d.ts",
|
|
35
|
+
"dist/**/*.map"
|
|
36
|
+
],
|
|
37
|
+
"sideEffects": false,
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "yarn clean && bun run build.ts && tsc --emitDeclarationOnly",
|
|
40
|
+
"typecheck": "tsc --noEmit",
|
|
41
|
+
"clean": "rimraf dist",
|
|
42
|
+
"prepublish": "yarn typecheck && yarn build",
|
|
43
|
+
"rel": "yarn npm publish --access public",
|
|
44
|
+
"rel:patch": "yarn version patch && yarn npm publish --access public",
|
|
45
|
+
"rel:minor": "yarn version minor && yarn npm publish --access public",
|
|
46
|
+
"rel:major": "yarn version major && yarn npm publish --access public"
|
|
47
|
+
},
|
|
48
|
+
"keywords": [
|
|
49
|
+
"bun",
|
|
50
|
+
"router",
|
|
51
|
+
"brpc",
|
|
52
|
+
"rpc",
|
|
53
|
+
"trpc",
|
|
54
|
+
"api",
|
|
55
|
+
"http"
|
|
56
|
+
],
|
|
57
|
+
"author": "Mateo Suarez <msdevuy@gmail.com>",
|
|
58
|
+
"repository": {
|
|
59
|
+
"type": "git",
|
|
60
|
+
"url": "git+https://github.com/mateosuarezdev/brpc-space.git",
|
|
61
|
+
"directory": "packages/brpc"
|
|
62
|
+
},
|
|
63
|
+
"bugs": {
|
|
64
|
+
"url": "https://github.com/mateosuarezdev/brpc-space/issues"
|
|
65
|
+
},
|
|
66
|
+
"homepage": "https://github.com/mateosuarezdev/brpc-space/tree/main/packages/brpc#readme",
|
|
67
|
+
"license": "MIT",
|
|
68
|
+
"engines": {
|
|
69
|
+
"bun": ">=1.2.0"
|
|
70
|
+
},
|
|
71
|
+
"peerDependencies": {
|
|
72
|
+
"react": "^19.0.0",
|
|
73
|
+
"react-dom": "^19.0.0",
|
|
74
|
+
"sharp": "^0.34.4",
|
|
75
|
+
"zod": "^3.23.8"
|
|
76
|
+
},
|
|
77
|
+
"peerDependenciesMeta": {
|
|
78
|
+
"react": {
|
|
79
|
+
"optional": true
|
|
80
|
+
},
|
|
81
|
+
"react-dom": {
|
|
82
|
+
"optional": true
|
|
83
|
+
},
|
|
84
|
+
"sharp": {
|
|
85
|
+
"optional": true
|
|
86
|
+
},
|
|
87
|
+
"zod": {
|
|
88
|
+
"optional": false
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
"devDependencies": {
|
|
92
|
+
"@types/bun": "^1.2.23",
|
|
93
|
+
"@types/react": "^19.2.2",
|
|
94
|
+
"@types/react-dom": "^19.2.2",
|
|
95
|
+
"rimraf": "^6.0.1",
|
|
96
|
+
"sharp": "^0.34.4",
|
|
97
|
+
"typescript": "^5.9.3",
|
|
98
|
+
"zod": "^3.23.8"
|
|
99
|
+
},
|
|
100
|
+
"dependencies": {
|
|
101
|
+
"@mateosuarezdev/headers-builder": "^1.0.5"
|
|
102
|
+
}
|
|
103
|
+
}
|