Thin MongoDB ODM built for Standard Schema
mongodb zod deno

remove definemodel

+11 -27
+3 -3
README.md
··· 38 ```ts 39 // src/schemas/user.ts 40 import { z } from "zod"; 41 - import { defineModel } from "mizzleorm"; 42 43 - export const userSchema = defineModel(z.object({ 44 name: z.string(), 45 email: z.string().email(), 46 age: z.number().int().positive().optional(), 47 createdAt: z.date().default(() => new Date()), 48 - })); 49 50 export type User = z.infer<typeof userSchema>; 51 ```
··· 38 ```ts 39 // src/schemas/user.ts 40 import { z } from "zod"; 41 + import { defineModel } from "@nozzle/nozzle"; 42 43 + export const userSchema = z.object({ 44 name: z.string(), 45 email: z.string().email(), 46 age: z.number().int().positive().optional(), 47 createdAt: z.date().default(() => new Date()), 48 + }); 49 50 export type User = z.infer<typeof userSchema>; 51 ```
+2 -5
deno.json
··· 1 { 2 - "name": "mizzleorm", 3 "version": "0.1.0", 4 "exports": "./mod.ts", 5 "license": "MIT", 6 "tasks": { 7 "build": "tsc", 8 - "test": "deno run --allow-run --allow-read scripts/test.ts --all", 9 "test:mock": "deno test tests/mock_test.ts", 10 - "test:integration": "deno test --allow-net --allow-read --allow-write --allow-env --allow-sys tests/main_test.ts", 11 - "test:watch": "deno run --allow-run --allow-read scripts/test.ts --mock --watch", 12 - "example": "deno run --allow-net --allow-read --allow-write --allow-env --allow-sys examples/user.ts" 13 }, 14 "imports": { 15 "zod": "jsr:@zod/zod@^4.0.17",
··· 1 { 2 + "name": "@nozzle/nozzle", 3 "version": "0.1.0", 4 "exports": "./mod.ts", 5 "license": "MIT", 6 "tasks": { 7 "build": "tsc", 8 "test:mock": "deno test tests/mock_test.ts", 9 + "test:watch": "deno run -A scripts/test.ts --mock --watch" 10 }, 11 "imports": { 12 "zod": "jsr:@zod/zod@^4.0.17",
+2 -3
examples/user.ts
··· 2 import { ObjectId } from "mongodb"; 3 import { 4 connect, 5 - defineModel, 6 disconnect, 7 type InferModel, 8 type InsertType, ··· 10 } from "../mod.ts"; 11 12 // 1. Define your schema using Zod 13 - const userSchema = defineModel(z.object({ 14 name: z.string(), 15 email: z.string().email(), 16 age: z.number().int().positive().optional(), 17 createdAt: z.date().default(() => new Date()), 18 - })); 19 20 // Infer the TypeScript type from the Zod schema 21 type User = InferModel<typeof userSchema>;
··· 2 import { ObjectId } from "mongodb"; 3 import { 4 connect, 5 disconnect, 6 type InferModel, 7 type InsertType, ··· 9 } from "../mod.ts"; 10 11 // 1. Define your schema using Zod 12 + const userSchema = z.object({ 13 name: z.string(), 14 email: z.string().email(), 15 age: z.number().int().positive().optional(), 16 createdAt: z.date().default(() => new Date()), 17 + }); 18 19 // Infer the TypeScript type from the Zod schema 20 type User = InferModel<typeof userSchema>;
+1 -1
mod.ts
··· 1 - export { defineModel, type InferModel, type InsertType } from "./schema.ts"; 2 export { connect, disconnect } from "./client.ts"; 3 export { Model } from "./model.ts";
··· 1 + export { type InferModel, type InsertType } from "./schema.ts"; 2 export { connect, disconnect } from "./client.ts"; 3 export { Model } from "./model.ts";
-4
schema.ts
··· 1 import type { z } from "zod"; 2 import type { ObjectId } from "mongodb"; 3 4 - export function defineModel<T extends z.ZodObject>(schema: T) { 5 - return schema; 6 - } 7 - 8 export type InferModel<T extends z.ZodObject> = z.infer<T> & { 9 _id?: ObjectId; 10 };
··· 1 import type { z } from "zod"; 2 import type { ObjectId } from "mongodb"; 3 4 export type InferModel<T extends z.ZodObject> = z.infer<T> & { 5 _id?: ObjectId; 6 };
+3 -11
tests/main_test.ts
··· 1 import { assertEquals, assertExists, assertRejects } from "jsr:@std/assert"; 2 import { z } from "zod"; 3 - import { 4 - connect, 5 - defineModel, 6 - disconnect, 7 - type InferModel, 8 - type InsertType, 9 - Model, 10 - } from "../mod.ts"; 11 import { ObjectId } from "mongodb"; 12 13 - const userSchema = defineModel(z.object({ 14 name: z.string(), 15 email: z.email(), 16 age: z.number().int().positive().optional(), 17 createdAt: z.date().default(() => new Date()), 18 - })); 19 20 - type User = InferModel<typeof userSchema>; 21 type UserInsert = InsertType<typeof userSchema>; 22 23 let UserModel: Model<typeof userSchema>;
··· 1 import { assertEquals, assertExists, assertRejects } from "jsr:@std/assert"; 2 import { z } from "zod"; 3 + import { connect, disconnect, type InsertType, Model } from "../mod.ts"; 4 import { ObjectId } from "mongodb"; 5 6 + const userSchema = z.object({ 7 name: z.string(), 8 email: z.email(), 9 age: z.number().int().positive().optional(), 10 createdAt: z.date().default(() => new Date()), 11 + }); 12 13 type UserInsert = InsertType<typeof userSchema>; 14 15 let UserModel: Model<typeof userSchema>;