@rpcbase/server 0.357.0 → 0.358.0

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/mongoose/index.ts CHANGED
@@ -1,12 +1,10 @@
1
- export * from "mongoose"
2
-
3
1
  import mongoose from "mongoose"
4
2
  import {object_id_plugin} from "./object_id_plugin"
5
3
 
6
-
7
4
  mongoose.set("strictQuery", false)
8
5
 
9
6
  mongoose.plugin(object_id_plugin)
10
7
 
11
-
12
8
  export default mongoose
9
+
10
+ export * from "mongoose"
@@ -3,12 +3,24 @@ import mongoose, { Schema } from "./"
3
3
  import {get_object_id} from "../get_object_id"
4
4
 
5
5
  export const object_id_plugin = (schema: Schema) => {
6
- if (!schema.path("_id")) {
7
- schema.add({
8
- _id: {
9
- type: mongoose.Types.ObjectId,
10
- default: () => get_object_id(),
11
- },
12
- })
13
- }
6
+ // Disable Mongoose's automatic _id field creation
7
+ if (!schema.options._id) {
8
+ schema.options._id = false
9
+ }
10
+
11
+ // Add your custom _id field
12
+ schema.add({
13
+ _id: {
14
+ type: mongoose.Schema.Types.ObjectId,
15
+ default: () => get_object_id(),
16
+ },
17
+ })
18
+
19
+ // Optional: Ensure the _id field is always set
20
+ schema.pre("save", function(next) {
21
+ if (!this._id) {
22
+ this._id = get_object_id()
23
+ }
24
+ next()
25
+ })
14
26
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/server",
3
- "version": "0.357.0",
3
+ "version": "0.358.0",
4
4
  "license": "SSPL-1.0",
5
5
  "main": "./index.js",
6
6
  "scripts": {
@@ -81,6 +81,8 @@ const dispatch_change_handler = (change) => {
81
81
  return
82
82
  }
83
83
 
84
+ const op = change.operationType
85
+
84
86
  dispatch_queue(queue, model_name, op, change.fullDocument, change.updateDescription)
85
87
  }
86
88