Update paths in sync.sh, master/main.go, and CLAUDE.md to reflect the directory rename. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
60 lines
1.3 KiB
TypeScript
60 lines
1.3 KiB
TypeScript
import {
|
|
ColumnType,
|
|
Generated,
|
|
Insertable,
|
|
JSONColumnType,
|
|
Selectable,
|
|
Updateable,
|
|
} from "kysely";
|
|
import type { TypeID } from "typeid-js";
|
|
import { z } from "zod";
|
|
import { db, Hydrator } from "./hydrator";
|
|
|
|
const parser = z.object({
|
|
// id: z.uuidv7(),
|
|
id: z.uuid(),
|
|
display_name: z.string(),
|
|
// FIXME: status is duplicated elsewhere
|
|
status: z.union([
|
|
z.literal("active"),
|
|
z.literal("suspended"),
|
|
z.literal("pending"),
|
|
]),
|
|
email: z.email(),
|
|
});
|
|
|
|
const tp = parser.parse({
|
|
id: "cfae0a19-6515-4813-bc2d-1e032b72b203",
|
|
display_name: "foo",
|
|
status: "active",
|
|
email: "mw@philologue.net",
|
|
});
|
|
|
|
export type User = z.infer<typeof parser>;
|
|
|
|
const get = async (id: string): Promise<null | User> => {
|
|
const ret = await db
|
|
.selectFrom("users")
|
|
.where("users.id", "=", id)
|
|
.innerJoin("user_emails", "user_emails.user_id", "users.id")
|
|
.select([
|
|
"users.id",
|
|
"users.status",
|
|
"users.display_name",
|
|
"user_emails.email",
|
|
])
|
|
.executeTakeFirst();
|
|
|
|
if (ret === undefined) {
|
|
return null;
|
|
}
|
|
|
|
console.dir(ret);
|
|
|
|
const parsed = parser.parse(ret);
|
|
|
|
return parsed;
|
|
};
|
|
|
|
export { get };
|