Thin MongoDB ODM built for Standard Schema
mongodb zod deno

remove definemodel

Changed files
+11 -27
examples
tests
+3 -3
README.md
···
```ts
// src/schemas/user.ts
import { z } from "zod";
-
import { defineModel } from "mizzleorm";
+
import { defineModel } from "@nozzle/nozzle";
-
export const userSchema = defineModel(z.object({
+
export const userSchema = z.object({
name: z.string(),
email: z.string().email(),
age: z.number().int().positive().optional(),
createdAt: z.date().default(() => new Date()),
-
}));
+
});
export type User = z.infer<typeof userSchema>;
```
+2 -5
deno.json
···
{
-
"name": "mizzleorm",
+
"name": "@nozzle/nozzle",
"version": "0.1.0",
"exports": "./mod.ts",
"license": "MIT",
"tasks": {
"build": "tsc",
-
"test": "deno run --allow-run --allow-read scripts/test.ts --all",
"test:mock": "deno test tests/mock_test.ts",
-
"test:integration": "deno test --allow-net --allow-read --allow-write --allow-env --allow-sys tests/main_test.ts",
-
"test:watch": "deno run --allow-run --allow-read scripts/test.ts --mock --watch",
-
"example": "deno run --allow-net --allow-read --allow-write --allow-env --allow-sys examples/user.ts"
+
"test:watch": "deno run -A scripts/test.ts --mock --watch"
},
"imports": {
"zod": "jsr:@zod/zod@^4.0.17",
+2 -3
examples/user.ts
···
import { ObjectId } from "mongodb";
import {
connect,
-
defineModel,
disconnect,
type InferModel,
type InsertType,
···
} from "../mod.ts";
// 1. Define your schema using Zod
-
const userSchema = defineModel(z.object({
+
const userSchema = z.object({
name: z.string(),
email: z.string().email(),
age: z.number().int().positive().optional(),
createdAt: z.date().default(() => new Date()),
-
}));
+
});
// Infer the TypeScript type from the Zod schema
type User = InferModel<typeof userSchema>;
+1 -1
mod.ts
···
-
export { defineModel, type InferModel, type InsertType } from "./schema.ts";
+
export { type InferModel, type InsertType } from "./schema.ts";
export { connect, disconnect } from "./client.ts";
export { Model } from "./model.ts";
-4
schema.ts
···
import type { z } from "zod";
import type { ObjectId } from "mongodb";
-
export function defineModel<T extends z.ZodObject>(schema: T) {
-
return schema;
-
}
-
export type InferModel<T extends z.ZodObject> = z.infer<T> & {
_id?: ObjectId;
};
+3 -11
tests/main_test.ts
···
import { assertEquals, assertExists, assertRejects } from "jsr:@std/assert";
import { z } from "zod";
-
import {
-
connect,
-
defineModel,
-
disconnect,
-
type InferModel,
-
type InsertType,
-
Model,
-
} from "../mod.ts";
+
import { connect, disconnect, type InsertType, Model } from "../mod.ts";
import { ObjectId } from "mongodb";
-
const userSchema = defineModel(z.object({
+
const userSchema = z.object({
name: z.string(),
email: z.email(),
age: z.number().int().positive().optional(),
createdAt: z.date().default(() => new Date()),
-
}));
+
});
-
type User = InferModel<typeof userSchema>;
type UserInsert = InsertType<typeof userSchema>;
let UserModel: Model<typeof userSchema>;