Skip to content

Commit 84dbfce

Browse files
authored
feat: improve createEndpoint, createMiddleware generic signature (#109)
1 parent 2f5d57f commit 84dbfce

35 files changed

Lines changed: 1353 additions & 1085 deletions

.cspell.jsonc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
// third party libraries
99
"attw",
1010
"bumpp",
11+
"arktype",
1112

1213
// auth words
1314
"scim",
15+
"OpenAPIHTML",
1416

1517
// proper names
1618
"Bereket",

example/bundle.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

example/hello.ts

Lines changed: 0 additions & 39 deletions
This file was deleted.

example/package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
{
2-
"name": "@better-auth/example",
3-
"private": true,
2+
"name": "better-call-example",
3+
"type": "module",
44
"scripts": {
5-
"build": "tsdown"
5+
"build": "tsc -b"
66
},
77
"dependencies": {
8+
"arktype": "^2.1.29",
89
"better-call": "workspace:*",
10+
"effect": "^3.19.18",
11+
"valibot": "^1.2.0",
912
"zod": "^4.3.6"
13+
},
14+
"devDependencies": {
15+
"typescript": "^5.9.3"
1016
}
1117
}

example/src/arktype.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { type } from "arktype";
2+
import { createEndpoint, createMiddleware, createRouter } from "better-call";
3+
import { createClient } from "better-call/client";
4+
5+
type Context = {
6+
readonly test: "demo";
7+
};
8+
9+
const contextMiddleware = createMiddleware(async () => {
10+
return {} as Context;
11+
});
12+
13+
export const getUserEndpoint = createEndpoint(
14+
"/user",
15+
{
16+
method: "POST",
17+
body: type({
18+
name: "string",
19+
}),
20+
use: [contextMiddleware],
21+
},
22+
async (ctx) => {
23+
ctx.context.test;
24+
return ctx.json({});
25+
},
26+
);
27+
28+
export const router = createRouter({
29+
getUserEndpoint,
30+
});
31+
32+
export const client = createClient<typeof router>();

example/src/effect.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { createEndpoint, createMiddleware, createRouter } from "better-call";
2+
import { createClient } from "better-call/client";
3+
import { Schema } from "effect";
4+
5+
type Context = {
6+
readonly test: "demo";
7+
};
8+
9+
const contextMiddleware = createMiddleware(async () => {
10+
return {} as Context;
11+
});
12+
13+
export const getUserEndpoint = createEndpoint(
14+
"/user",
15+
{
16+
method: "POST",
17+
body: Schema.standardSchemaV1(
18+
Schema.Struct({
19+
name: Schema.String,
20+
}),
21+
),
22+
use: [contextMiddleware],
23+
},
24+
async (ctx) => {
25+
ctx.context.test;
26+
return ctx.json({});
27+
},
28+
);
29+
30+
export const router = createRouter({
31+
getUserEndpoint,
32+
});
33+
34+
export const client = createClient<typeof router>();

example/src/valibot.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { createEndpoint, createMiddleware, createRouter } from "better-call";
2+
import { createClient } from "better-call/client";
3+
import * as v from "valibot";
4+
5+
type Context = {
6+
readonly test: "demo";
7+
};
8+
9+
const contextMiddleware = createMiddleware(async () => {
10+
return {} as Context;
11+
});
12+
13+
export const getUserEndpoint = createEndpoint(
14+
"/user",
15+
{
16+
method: "POST",
17+
body: v.object({
18+
name: v.string(),
19+
}),
20+
use: [contextMiddleware],
21+
},
22+
async (ctx) => {
23+
ctx.context.test;
24+
return ctx.json({});
25+
},
26+
);
27+
28+
export const router = createRouter({
29+
getUserEndpoint,
30+
});
31+
32+
export const client = createClient<typeof router>();

example/src/zod.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { createEndpoint, createMiddleware, createRouter } from "better-call";
2+
import { createClient } from "better-call/client";
3+
import * as z from "zod";
4+
5+
type Context = {
6+
readonly test: "demo";
7+
};
8+
9+
const contextMiddleware = createMiddleware(async () => {
10+
return {} as Context;
11+
});
12+
13+
export const getUserEndpoint = createEndpoint(
14+
"/user",
15+
{
16+
method: "POST",
17+
body: z.object({
18+
name: z.string(),
19+
}),
20+
use: [contextMiddleware],
21+
},
22+
async (ctx) => {
23+
ctx.context.test;
24+
return ctx.json({});
25+
},
26+
);
27+
28+
export const router = createRouter({
29+
getUserEndpoint,
30+
});
31+
32+
export const client = createClient<typeof router>();

example/tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
{
22
"extends": "../tsconfig.base.json",
3-
"include": ["./hello.ts", "bundle.ts"],
3+
"include": ["./src"],
44
"compilerOptions": {
5+
"outDir": "./dist",
6+
"rootDir": "./src",
57
"declaration": true
68
},
79
"references": [

example/tsdown.config.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)