@mongorm/orm 0.1.0 → 0.1.1-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,145 @@
1
+ <p align="center">
2
+ <img src="./.github/assets/backdrop.svg" alt="Mongorm" width="100%" style="border-radius: 10px;" />
3
+ </p>
4
+
5
+ <p align="center">
6
+ TypeScript-first MongoDB ORM with a small, strongly typed API.
7
+ </p>
8
+
9
+ <p align="center">
10
+ <img src="https://img.shields.io/badge/TypeScript-3178C6?style=for-the-badge&logo=typescript&logoColor=white" alt="TypeScript" />
11
+ <img src="https://img.shields.io/badge/MongoDB-47A248?style=for-the-badge&logo=mongodb&logoColor=white" alt="MongoDB" />
12
+ <img src="https://img.shields.io/badge/Zod-3E67B1?style=for-the-badge&logo=zod&logoColor=white" alt="Zod" />
13
+ <img src="https://img.shields.io/badge/Vitest-6E9F18?style=for-the-badge&logo=vitest&logoColor=white" alt="Vitest" />
14
+ </p>
15
+
16
+ Mongorm is a TypeScript-first MongoDB ORM for applications that want strong types and validation without hiding MongoDB behind a large abstraction.
17
+
18
+ It was created to make the common parts of MongoDB application development consistent: define data once, validate it at the boundary, query it with inferred types, and still keep access to MongoDB when the application needs it.
19
+
20
+ ## Features
21
+
22
+ ### Typed Schemas
23
+
24
+ Define the shape of your data once. Mongorm infers the input and output types from the schema and validates writes with Zod-backed fields.
25
+
26
+ ```ts
27
+ const ROLES = ['admin', 'member'];
28
+
29
+ const userSchema = orm.schema({
30
+ name: orm.string(),
31
+ email: orm.string().email(),
32
+ role: orm.enum(ROLES),
33
+ });
34
+ ```
35
+
36
+ ### Create, Read, Update, and Delete and Queries
37
+
38
+ Create records and build readable queries without losing MongoDB filter semantics.
39
+
40
+ ```ts
41
+ const user = await db.users.create({
42
+ name: 'Ada Lovelace',
43
+ email: 'ada@example.com',
44
+ role: 'admin',
45
+ });
46
+
47
+ const users = await db.users
48
+ .select(['name', 'email'])
49
+ .find({ role: 'admin' })
50
+ .sort({ name: 'asc' })
51
+ .limit(20);
52
+ ```
53
+
54
+ Use `.first()` when a query should return one record or `null`:
55
+
56
+ ```ts
57
+ const user = await db.users.find({ email: 'ada@example.com' }).first();
58
+ ```
59
+
60
+ ### Relations and Population
61
+
62
+ Connect related records and load them only when needed.
63
+
64
+ ```ts
65
+ const user = await db.users
66
+ .find({ email: 'ada@example.com' })
67
+ .populate([
68
+ {
69
+ ref: 'company',
70
+ select: ['name'. 'address'],
71
+ },
72
+ ])
73
+ .first();
74
+ ```
75
+
76
+ ### Bulk Operations
77
+
78
+ Use the same model for individual writes and larger batches.
79
+
80
+ ```ts
81
+ await db.users.bulk.create([
82
+ { name: 'Grace Hopper', email: 'grace@example.com', role: 'admin' },
83
+ { name: 'Alan Turing', email: 'alan@example.com', role: 'member' },
84
+ ]);
85
+ ```
86
+
87
+ ### Built-In Application Features
88
+
89
+ - Optional timestamps and soft deletes.
90
+ - Hidden fields for sensitive values.
91
+ - Reusable scopes for common read views.
92
+ - Explicit schema indexes with MongoDB options.
93
+ - Cursors, pagination, projections, sorting, and population.
94
+ - Access to the native collection for advanced MongoDB operations.
95
+
96
+ ## Getting Started
97
+
98
+ ```bash
99
+ pnpm add @mongorm/orm
100
+ ```
101
+
102
+ ```ts
103
+ import { createDatabase, orm } from '@mongorm/orm';
104
+
105
+ const ROLES = ['admin', 'member'];
106
+ const userSchema = orm
107
+ .schema({
108
+ email: orm.email(),
109
+ role: orm.enum(ROLES),
110
+ password: orm.string().hidden(),
111
+ })
112
+ .options({
113
+ timestamps: true,
114
+ });
115
+
116
+ const schema = orm.defineSchemas({
117
+ users: userSchema,
118
+ });
119
+
120
+ const db = createDatabase({
121
+ uri: process.env.MONGODB_URI,
122
+ database: 'app',
123
+ schema,
124
+ });
125
+
126
+ await db.connect();
127
+ await db.users.bulk.create([
128
+ { email: 'grace@example.com', role: 'member', password: 'password' },
129
+ { email: 'alan@example.com', role: 'admin', password: 'password' },
130
+ ]);
131
+
132
+ const user = await db.users
133
+ .find({ email: 'alan@example.com', role: 'admin' })
134
+ .show(['password'])
135
+ .first();
136
+
137
+ if (!user) throw new Error('User not found');
138
+ console.log(user);
139
+ ```
140
+
141
+ Mongorm keeps the MongoDB driver close at hand, so it simplifies everyday work without limiting access to MongoDB's full feature set.
142
+
143
+ ## License
144
+
145
+ MIT
@@ -0,0 +1,7 @@
1
+ import { defineConfig } from 'bumpp';
2
+
3
+ export default defineConfig({
4
+ commit: true,
5
+ push: false,
6
+ tag: true,
7
+ });
package/package.json CHANGED
@@ -1,6 +1,23 @@
1
1
  {
2
2
  "name": "@mongorm/orm",
3
- "version": "0.1.0",
3
+ "version": "0.1.1-beta.1",
4
+ "description": "A TypeScript-first MongoDB ORM for applications that want strong types without hiding MongoDB",
5
+ "keywords": [
6
+ "mongodb",
7
+ "orm",
8
+ "typescript",
9
+ "zod"
10
+ ],
11
+ "homepage": "https://github.com/hdytrfli/orm#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/hdytrfli/orm/issues"
14
+ },
15
+ "license": "MIT",
16
+ "author": "hdytrfli",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/hdytrfli/orm"
20
+ },
4
21
  "type": "module",
5
22
  "exports": {
6
23
  ".": {
@@ -8,17 +25,23 @@
8
25
  "import": "./dist/index.mjs"
9
26
  }
10
27
  },
28
+ "publishConfig": {
29
+ "access": "public",
30
+ "registry": "https://registry.npmjs.org/"
31
+ },
11
32
  "dependencies": {
12
33
  "mongodb": "^7.6.0",
13
34
  "zod": "^4.6.5"
14
35
  },
15
36
  "devDependencies": {
16
37
  "@types/node": "^26.6.2",
38
+ "bumpp": "^12.3.0",
17
39
  "dotenv": "^17.2.2"
18
40
  },
19
41
  "scripts": {
20
42
  "build": "tsdown",
21
43
  "test": "vitest run --config vitest.config.ts",
22
- "typecheck": "pnpm build && tsc --noEmit"
44
+ "typecheck": "pnpm build && tsc --noEmit",
45
+ "version:bump": "bumpp"
23
46
  }
24
47
  }