プレイグラウンド、サンドボックス、使い捨てスクリプト置き場
0

Configure Feed

Select the types of activity you want to include in your feed.

create better-call

Kohei Watanabe (Oct 22, 2025, 2:30 PM +0900) ce39b932 d01e3104

+133
+10
better-call/deno.json
··· 1 + { 2 + "tasks": { 3 + "dev": "deno run --watch main.ts" 4 + }, 5 + "imports": { 6 + "@std/assert": "jsr:@std/assert@1", 7 + "better-call": "npm:better-call@^1.0.24", 8 + "zod": "npm:zod@^4.1.12" 9 + } 10 + }
+62
better-call/deno.lock
··· 1 + { 2 + "version": "5", 3 + "specifiers": { 4 + "jsr:@std/assert@1": "1.0.11", 5 + "jsr:@std/internal@^1.0.5": "1.0.5", 6 + "npm:better-call@*": "1.0.24", 7 + "npm:better-call@^1.0.24": "1.0.24", 8 + "npm:zod@*": "4.0.15", 9 + "npm:zod@^4.1.12": "4.1.12" 10 + }, 11 + "jsr": { 12 + "@std/assert@1.0.11": { 13 + "integrity": "2461ef3c368fe88bc60e186e7744a93112f16fd110022e113a0849e94d1c83c1", 14 + "dependencies": [ 15 + "jsr:@std/internal" 16 + ] 17 + }, 18 + "@std/internal@1.0.5": { 19 + "integrity": "54a546004f769c1ac9e025abd15a76b6671ddc9687e2313b67376125650dc7ba" 20 + } 21 + }, 22 + "npm": { 23 + "@better-auth/utils@0.3.0": { 24 + "integrity": "sha512-W+Adw6ZA6mgvnSnhOki270rwJ42t4XzSK6YWGF//BbVXL6SwCLWfyzBc1lN2m/4RM28KubdBKQ4X5VMoLRNPQw==" 25 + }, 26 + "@better-fetch/fetch@1.1.18": { 27 + "integrity": "sha512-rEFOE1MYIsBmoMJtQbl32PGHHXuG2hDxvEd7rUHE0vCBoFQVSDqaVs9hkZEtHCxRoY+CljXKFCOuJ8uxqw1LcA==" 28 + }, 29 + "better-call@1.0.24": { 30 + "integrity": "sha512-iGqL29cstPp4xLD2MjKL1EmyAqQHjYS+cBMt4W27rPs3vf+kuqkVPA0NYaf7JciBOzVsJdNj4cbZWXC5TardWQ==", 31 + "dependencies": [ 32 + "@better-auth/utils", 33 + "@better-fetch/fetch", 34 + "rou3", 35 + "set-cookie-parser", 36 + "uncrypto" 37 + ] 38 + }, 39 + "rou3@0.5.1": { 40 + "integrity": "sha512-OXMmJ3zRk2xeXFGfA3K+EOPHC5u7RDFG7lIOx0X1pdnhUkI8MdVrbV+sNsD80ElpUZ+MRHdyxPnFthq9VHs8uQ==" 41 + }, 42 + "set-cookie-parser@2.7.1": { 43 + "integrity": "sha512-IOc8uWeOZgnb3ptbCURJWNjWUPcO3ZnTTdzsurqERrP6nPyv+paC55vJM0LpOlT2ne+Ix+9+CRG1MNLlyZ4GjQ==" 44 + }, 45 + "uncrypto@0.1.3": { 46 + "integrity": "sha512-Ql87qFHB3s/De2ClA9e0gsnS6zXG27SkTiSJwjCc9MebbfapQfuPzumMIUMi38ezPZVNFcHI9sUIepeQfw8J8Q==" 47 + }, 48 + "zod@4.0.15": { 49 + "integrity": "sha512-2IVHb9h4Mt6+UXkyMs0XbfICUh1eUrlJJAOupBHUhLRnKkruawyDddYRCs0Eizt900ntIMk9/4RksYl+FgSpcQ==" 50 + }, 51 + "zod@4.1.12": { 52 + "integrity": "sha512-JInaHOamG8pt5+Ey8kGmdcAcg3OL9reK8ltczgHTAwNhMys/6ThXHityHxVV2p3fkw/c+MAvBHFVYHFZDmjMCQ==" 53 + } 54 + }, 55 + "workspace": { 56 + "dependencies": [ 57 + "jsr:@std/assert@1", 58 + "npm:better-call@^1.0.24", 59 + "npm:zod@^4.1.12" 60 + ] 61 + } 62 + }
+54
better-call/main.ts
··· 1 + import { createEndpoint, createRouter } from "npm:better-call"; 2 + import { z } from "npm:zod"; 3 + 4 + export const createItem = createEndpoint( 5 + "/item/:id", 6 + { 7 + method: "GET", 8 + query: z.object({ 9 + id: z.string("The id of the item"), 10 + }), 11 + metadata: { 12 + openapi: { 13 + description: "This endpoint creates an item based on the provided ID.", 14 + responses: { 15 + 200: { 16 + description: "Successful response with the created item.", 17 + content: { 18 + "application/json": { 19 + schema: { 20 + type: "object", 21 + properties: { 22 + item: { 23 + type: "object", 24 + properties: { 25 + id: { 26 + type: "string", 27 + description: "The ID of the created item.", 28 + }, 29 + }, 30 + required: ["id"], 31 + }, 32 + }, 33 + required: ["item"], 34 + }, 35 + }, 36 + }, 37 + }, 38 + }, 39 + }, 40 + }, 41 + }, 42 + async (ctx) => ({ item: { id: ctx.query.id } }), 43 + ); 44 + 45 + if (import.meta.main) { 46 + Deno.serve( 47 + createRouter({ 48 + redirectToDocs: createEndpoint("/", { method: "GET" }, async (ctx) => 49 + ctx.redirect("/api/reference"), 50 + ), 51 + createItem, 52 + }), 53 + ); 54 + }
+7
better-call/main_test.ts
··· 1 + import { assertEquals } from "@std/assert"; 2 + import { createItem } from "./main.ts"; 3 + 4 + Deno.test(async function addTest() { 5 + const res = await createItem({ query: { id: "1" }, params: { id: "user1" } }); 6 + assertEquals(res.item.id, "1"); 7 + });