Thin MongoDB ODM built for Standard Schema
mongodb zod deno
1import type { z } from "@zod/zod"; 2import type { Document, ObjectId, IndexDescription } from "mongodb"; 3 4/** 5 * Type alias for Zod schema objects 6 */ 7export type Schema = z.ZodObject<z.ZodRawShape>; 8 9/** 10 * Infer the TypeScript type from a Zod schema, including MongoDB Document 11 */ 12export type Infer<T extends Schema> = z.infer<T> & Document; 13 14 15/** 16 * Infer the model type from a Zod schema, including MongoDB Document and ObjectId 17 */ 18export type InferModel<T extends Schema> = Infer<T> & { 19 _id?: ObjectId; 20 }; 21 22/** 23 * Infer the input type for a Zod schema (handles defaults) 24 */ 25export type Input<T extends Schema> = z.input<T>; 26 27/** 28 * Type for indexes that can be passed to the Model constructor 29 */ 30export type Indexes = IndexDescription[]; 31 32/** 33 * Complete definition of a model, including schema and indexes 34 * 35 * @example 36 * ```ts 37 * const userDef: ModelDef<typeof userSchema> = { 38 * schema: userSchema, 39 * indexes: [ 40 * { key: { email: 1 }, unique: true }, 41 * { key: { name: 1 } } 42 * ] 43 * }; 44 * ``` 45 */ 46export type ModelDef<T extends Schema> = { 47 schema: T; 48 indexes?: Indexes; 49};