Template
1
0

feat: initial commit

This commit is contained in:
2025-04-18 20:18:50 +00:00
commit 7df57522d2
20 changed files with 2094 additions and 0 deletions

13
tests/mocks/actions.ts Normal file
View File

@@ -0,0 +1,13 @@
import z from "zod";
import { action } from "../../libraries/action.ts";
export const addTwoNumbers = action
.make("addTwoNumbers")
.input({ a: z.number(), b: z.number() })
.output({ added: z.number() })
.handle(async ({ a, b }) => {
return {
added: a + b,
};
});

23
tests/mocks/relay.ts Normal file
View File

@@ -0,0 +1,23 @@
import z from "zod";
import { http } from "../../adapters/http.ts";
import { Relay } from "../../libraries/relay.ts";
import { route } from "../../libraries/route.ts";
import { UserSchema } from "./user.ts";
export const relay = new Relay({ adapter: http }, [
route
.post("/users")
.body(UserSchema.omit({ id: true }))
.response(z.string()),
route.get("/users").response(z.array(UserSchema)),
route
.get("/users/:userId")
.params({ userId: z.string().check(z.uuid()) })
.response(UserSchema.or(z.undefined())),
route
.put("/users/:userId")
.params({ userId: z.string().check(z.uuid()) })
.body(UserSchema.omit({ id: true })),
route.delete("/users/:userId").params({ userId: z.string().check(z.uuid()) }),
]);

32
tests/mocks/server.ts Normal file
View File

@@ -0,0 +1,32 @@
import { relay } from "./relay.ts";
import { User } from "./user.ts";
export let users: User[] = [];
relay.route("POST", "/users").handle(async ({ name, email }) => {
const id = crypto.randomUUID();
users.push({ id, name, email });
return id;
});
relay.route("GET", "/users").handle(async () => {
return users;
});
relay.route("GET", "/users/:userId").handle(async ({ userId }) => {
return users.find((user) => user.id === userId);
});
relay.route("PUT", "/users/:userId").handle(async ({ userId, name, email }) => {
for (const user of users) {
if (user.id === userId) {
user.name = name;
user.email = email;
break;
}
}
});
relay.route("DELETE", "/users/:userId").handle(async ({ userId }) => {
users = users.filter((user) => user.id === userId);
});

9
tests/mocks/user.ts Normal file
View File

@@ -0,0 +1,9 @@
import z from "zod";
export const UserSchema = z.object({
id: z.string().check(z.uuid()),
name: z.string(),
email: z.string().check(z.email()),
});
export type User = z.infer<typeof UserSchema>;