@rpcbase/server 0.357.0 → 0.359.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/boot/shared.js CHANGED
@@ -5,7 +5,7 @@ if (typeof __RB_IS_WEBPACK__ === "undefined") {
5
5
 
6
6
  require("./setup_env")
7
7
 
8
- require("../extend-expect")
8
+ require("@rpcbase/std/extend-expect")
9
9
 
10
10
  const mongoose = require("../mongoose")
11
11
 
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.359.0",
4
4
  "license": "SSPL-1.0",
5
5
  "main": "./index.js",
6
6
  "scripts": {
@@ -69,12 +69,10 @@
69
69
  "cors": "2.8.5",
70
70
  "debug": "4.3.6",
71
71
  "dotenv": "16.4.5",
72
- "expect": "29.7.0",
73
72
  "express": "4.19.2",
74
73
  "express-session": "1.18.0",
75
74
  "firebase-admin": "12.3.0",
76
75
  "glob": "11.0.0",
77
- "jest-extended": "4.0.2",
78
76
  "lodash": "4.17.21",
79
77
  "mkdirp": "3.0.1",
80
78
  "mongoose": "8.5.2",
@@ -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
 
@@ -1,7 +0,0 @@
1
- /* @flow */
2
- // WARNING: must be first import here
3
- require("./mactchers")
4
-
5
- // add all jest-extended matchers
6
- const matchers = require("jest-extended")
7
- expect.extend(matchers)
@@ -1,42 +0,0 @@
1
- /* @flow */
2
- const {expect} = require("expect")
3
-
4
- const isMongoId = require("validator/lib/isMongoId")
5
- const isEmail = require("validator/lib/isEmail")
6
-
7
-
8
- expect.extend({
9
- toBeMongoId: function(actual) {
10
- const pass = isMongoId(actual)
11
-
12
- if (pass) {
13
- return {
14
- message: () => `expected ${this.utils.printReceived(actual)} not to be a valid mongoId`,
15
- pass: true,
16
- }
17
- } else {
18
- return {
19
- message: () => `expected ${this.utils.printReceived(actual)} to be a valid mongoId`,
20
- pass: false,
21
- }
22
- }
23
- },
24
- toBeEmail: function(actual) {
25
- const pass = actual && isEmail(actual)
26
-
27
- if (pass) {
28
- return {
29
- message: () =>
30
- `expected ${this.utils.printReceived(actual)} not to be a valid email address`,
31
- pass: true,
32
- }
33
- } else {
34
- return {
35
- message: () => `expected ${this.utils.printReceived(actual)} to be a valid email address`,
36
- pass: false,
37
- }
38
- }
39
- },
40
- })
41
-
42
- global.expect = expect