import { buildJsonSchemas } from "fastify-zod"; import mongoose from "mongoose"; import { z } from "zod"; export const tokenModel = mongoose.model( "token", new mongoose.Schema({ tenantId: { type: String, required: true, }, pid: { type: String, unique: true, }, name: String, claims: [], userId: mongoose.Types.ObjectId, hash: { type: String, required: true }, createdAt: Date, }) ); const tokenCore = { name: z.string().max(30), claims: z.array(z.string()).nonempty(), }; const createTokenInput = z.object({ ...tokenCore, }); const createTokenResponse = z.object({ pid: z.string(), token: z.string(), ...tokenCore, }); const getTokenResponse = z.object({ pid: z.string(), name: z.string(), createdAt: z.string(), }); export type CreateTokenInput = z.infer; export const { schemas: tokenSchemas, $ref: $token } = buildJsonSchemas( { createTokenInput, createTokenResponse, getTokenResponse, }, { $id: "token" } );