mirror of
https://github.com/nestriness/nestri.git
synced 2026-08-02 01:35:18 +03:00
fix: Use Zod in the actor.ts file
This commit is contained in:
@@ -1,45 +1,64 @@
|
||||
import { z } from "zod/v4";
|
||||
import { Log } from "./utils/log.js";
|
||||
import { Context } from "./context.js";
|
||||
import { ErrorCodes, VisibleError } from "./error.js";
|
||||
|
||||
export namespace Actor {
|
||||
export interface User {
|
||||
type: "user";
|
||||
properties: {
|
||||
userID: string;
|
||||
email: string;
|
||||
};
|
||||
}
|
||||
export const User = z.object({
|
||||
type: z.literal("user"),
|
||||
properties: z.object({
|
||||
userID: z.string(),
|
||||
email: z.string(),
|
||||
}),
|
||||
});
|
||||
|
||||
export interface Steam {
|
||||
type: "steam";
|
||||
properties: {
|
||||
userID: string;
|
||||
steamID: string;
|
||||
};
|
||||
}
|
||||
export type User = z.Infer<typeof User>;
|
||||
|
||||
export interface System {
|
||||
type: "system";
|
||||
properties: {
|
||||
userID: string;
|
||||
};
|
||||
}
|
||||
export const Steam = z.object({
|
||||
type: z.literal("steam"),
|
||||
properties: z.object({
|
||||
userID: z.string(),
|
||||
steamID: z.string(),
|
||||
}),
|
||||
});
|
||||
|
||||
export interface Token {
|
||||
type: "token";
|
||||
properties: {
|
||||
teamID: string;
|
||||
tokenID: string;
|
||||
};
|
||||
}
|
||||
export type Steam = z.Infer<typeof Steam>;
|
||||
|
||||
export interface Public {
|
||||
type: "public";
|
||||
properties: {};
|
||||
}
|
||||
export const System = z.object({
|
||||
type: z.literal("system"),
|
||||
properties: z.object({
|
||||
userID: z.string(),
|
||||
}),
|
||||
});
|
||||
|
||||
export type Info = Steam | User | Public | Token | System;
|
||||
export type System = z.Infer<typeof System>;
|
||||
|
||||
export const Token = z.object({
|
||||
type: z.literal("token"),
|
||||
properties: z.object({
|
||||
teamID: z.string(),
|
||||
tokenID: z.string(),
|
||||
}),
|
||||
});
|
||||
|
||||
export type Token = z.Infer<typeof Token>;
|
||||
|
||||
export const Public = z.object({
|
||||
type: z.literal("public"),
|
||||
properties: z.object({}),
|
||||
});
|
||||
|
||||
export type Public = z.Infer<typeof Public>;
|
||||
|
||||
export const Info = z.discriminatedUnion("type", [
|
||||
User,
|
||||
Token,
|
||||
Steam,
|
||||
Public,
|
||||
System,
|
||||
]);
|
||||
|
||||
export type Info = z.Infer<typeof Info>;
|
||||
|
||||
export const ctx = Context.create<Info>();
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ export namespace Steam {
|
||||
export const fromID = fn(Info.shape.id, async (id) => {
|
||||
const userID = Actor.userID();
|
||||
|
||||
return Database.transaction((tx) =>
|
||||
return Database.use((tx) =>
|
||||
tx
|
||||
.select()
|
||||
.from(steamTable)
|
||||
|
||||
Reference in New Issue
Block a user