@classytic/mongokit 3.16.1 → 3.16.2

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 CHANGED
@@ -284,6 +284,28 @@ type UserRepo = Repository<UserDoc> &
284
284
  BatchOperationsMethods;
285
285
  ```
286
286
 
287
+ ### Type your Mongoose model — never cast `as never`
288
+
289
+ Declare the model with its doc type so `Model<UserDoc>` flows straight into
290
+ `Repository<UserDoc>` and `createMongooseAdapter` with no casts:
291
+
292
+ ```ts
293
+ // ✅ Typed — flows cleanly into Repository + the arc adapter
294
+ export type UserDoc = InferSchemaType<typeof UserSchema> & { _id: Types.ObjectId };
295
+ export const UserModel = model<UserDoc>('User', UserSchema);
296
+ export const userRepo = new Repository<UserDoc>(UserModel, [/* plugins */]);
297
+
298
+ // ❌ Untyped — the inferred doc type diverges from `UserDoc`, and
299
+ // `mongoose.Model<T>` is INVARIANT in T, so it won't unify. The
300
+ // tempting "fix" is `as never` — don't; type the model instead.
301
+ export const UserModel = model('User', UserSchema); // Model<inferred>
302
+ new Repository<UserDoc>(UserModel as never, []); // ⛔ cast smell
303
+ ```
304
+
305
+ The cast isn't a mongokit typing gap — it's a symptom of an untyped model.
306
+ One generic at the `model<Doc>(...)` call site removes it everywhere
307
+ (`Repository`, `createMongooseAdapter`, and any `RepositoryLike<Doc>` site).
308
+
287
309
  Feature-detect portable behavior with:
288
310
 
289
311
  ```ts
@@ -65,8 +65,11 @@ interface RegisterBetterAuthStubsOptions {
65
65
  * Mongoose-based resources can `.populate()` references to BA-owned
66
66
  * documents. Idempotent — safe to call multiple times.
67
67
  *
68
- * Schemas are `strict: false` and `_id: false` so BA's writes flow through
69
- * unchanged and Mongoose hydrates whatever BA wrote. Use this when you have
68
+ * Schemas are `strict: false` (so BA's writes flow through unchanged and
69
+ * Mongoose hydrates whatever BA wrote) and keep the DEFAULT ObjectId `_id`
70
+ * SchemaType — BA's mongo adapter stores ObjectId `_id`s, so the caster is
71
+ * required for `findById`, `_id` filters, and `populate`/`ref` to resolve a
72
+ * hex-string id (see the NOTE in the loop below). Use this when you have
70
73
  * resources that *reference* BA collections (`createdBy: { ref: 'user' }`)
71
74
  * but don't expose CRUD on the BA collection itself.
72
75
  *
@@ -7,8 +7,11 @@ import { pluralizeBetterAuthCollection, resolveBetterAuthCollections } from "@cl
7
7
  * Mongoose-based resources can `.populate()` references to BA-owned
8
8
  * documents. Idempotent — safe to call multiple times.
9
9
  *
10
- * Schemas are `strict: false` and `_id: false` so BA's writes flow through
11
- * unchanged and Mongoose hydrates whatever BA wrote. Use this when you have
10
+ * Schemas are `strict: false` (so BA's writes flow through unchanged and
11
+ * Mongoose hydrates whatever BA wrote) and keep the DEFAULT ObjectId `_id`
12
+ * SchemaType — BA's mongo adapter stores ObjectId `_id`s, so the caster is
13
+ * required for `findById`, `_id` filters, and `populate`/`ref` to resolve a
14
+ * hex-string id (see the NOTE in the loop below). Use this when you have
12
15
  * resources that *reference* BA collections (`createdBy: { ref: 'user' }`)
13
16
  * but don't expose CRUD on the BA collection itself.
14
17
  *
@@ -26,7 +29,6 @@ function registerBetterAuthStubs(mongoose, options = {}) {
26
29
  const schema = new mongoose.Schema({}, {
27
30
  strict: false,
28
31
  collection: finalName,
29
- _id: false,
30
32
  timestamps: false
31
33
  });
32
34
  mongoose.model(finalName, schema);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@classytic/mongokit",
3
- "version": "3.16.1",
3
+ "version": "3.16.2",
4
4
  "description": "Production-grade MongoDB repositories - smart pagination, events, and plugins. Built on @classytic/repo-core.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -145,8 +145,8 @@
145
145
  },
146
146
  "devDependencies": {
147
147
  "@arethetypeswrong/cli": "^0.18.2",
148
- "@better-auth/api-key": "^1.6.9",
149
- "@better-auth/mongo-adapter": "^1.6.9",
148
+ "@better-auth/api-key": "^1.6.22",
149
+ "@better-auth/mongo-adapter": "^1.6.22",
150
150
  "@biomejs/biome": "^2.4.10",
151
151
  "@classytic/dev-tools": "^0.2.0",
152
152
  "@classytic/repo-core": "0.6.0",
@@ -154,7 +154,7 @@
154
154
  "@vitest/coverage-v8": "^4.1.4",
155
155
  "ajv": "^8.18.0",
156
156
  "ajv-formats": "^3.0.1",
157
- "better-auth": "^1.6.9",
157
+ "better-auth": "^1.6.22",
158
158
  "dotenv": "^17.4.2",
159
159
  "knip": "^6.3.0",
160
160
  "mongodb-memory-server": "^10.4.3",
@@ -163,5 +163,9 @@
163
163
  "tsdown": "^0.21.8",
164
164
  "typescript": "^6.0.3",
165
165
  "vitest": "^4.1.4"
166
+ },
167
+ "overrides": {
168
+ "mongodb": "7.2.0",
169
+ "bson": "7.2.0"
166
170
  }
167
171
  }