Browse Source

fix: DataModule object checking false positive

Kristian Vos 2 năm trước cách đây
mục cha
commit
18170454db
2 tập tin đã thay đổi với 26 bổ sung14 xóa
  1. 10 0
      backend/src/main.ts
  2. 16 14
      backend/src/modules/DataModule.ts

+ 10 - 0
backend/src/main.ts

@@ -1,4 +1,5 @@
 import * as readline from "node:readline";
+import { ObjectId } from "mongodb";
 import ModuleManager from "./ModuleManager";
 import LogBook from "./LogBook";
 
@@ -194,6 +195,15 @@ setTimeout(async () => {
 	// 	})
 	// 	.then(console.log)
 	// 	.catch(console.error);
+
+	moduleManager
+		.runJob("data", "find", {
+			collection: "abc",
+			filter: { _id: new ObjectId(_id) },
+			limit: 1
+		})
+		.then(console.log)
+		.catch(console.error);
 }, 0);
 
 const rl = readline.createInterface({

+ 16 - 14
backend/src/modules/DataModule.ts

@@ -624,8 +624,9 @@ export default class DataModule extends BaseModule {
 							value.map(async _value => {
 								// Value must be an actual object, so if it's not, throw an error
 								if (
-									Object.prototype.toString.call(value) !==
-									"[object Object]"
+									!_value ||
+									typeof _value !== "object" ||
+									_value.constructor.name !== "Object"
 								)
 									throw Error("not an object");
 
@@ -777,8 +778,9 @@ export default class DataModule extends BaseModule {
 
 						// Sub-filter must be an actual object, so if it's not, throw an error
 						if (
-							Object.prototype.toString.call(subFilter) !==
-							"[object Object]"
+							!subFilter ||
+							typeof subFilter !== "object" ||
+							subFilter.constructor.name !== "Object"
 						)
 							throw Error("not an object");
 
@@ -834,8 +836,8 @@ export default class DataModule extends BaseModule {
 
 							// Sub-filter must be an actual object, so if it's not, throw an error
 							if (
-								Object.prototype.toString.call(subFilter) !==
-								"[object Object]"
+								typeof subFilter !== "object" ||
+								subFilter.constructor.name !== "Object"
 							)
 								throw Error("not an object");
 
@@ -869,8 +871,8 @@ export default class DataModule extends BaseModule {
 
 							// Value must not be an actual object, so if it is, throw an error
 							if (
-								Object.prototype.toString.call(value) ===
-								"[object Object]"
+								typeof value === "object" &&
+								value.constructor.name === "Object"
 							)
 								throw Error("an object");
 
@@ -900,8 +902,8 @@ export default class DataModule extends BaseModule {
 
 							// Value must not be an actual object, so if it is, throw an error
 							if (
-								Object.prototype.toString.call(value) ===
-								"[object Object]"
+								typeof value === "object" &&
+								value.constructor.name === "Object"
 							)
 								throw Error("an object");
 
@@ -971,8 +973,8 @@ export default class DataModule extends BaseModule {
 
 					// Value must be an actual object, so if it's not, throw an error
 					if (
-						Object.prototype.toString.call(value) !==
-						"[object Object]"
+						typeof value !== "object" ||
+						value.constructor.name !== "Object"
 					)
 						throw Error("not an object");
 
@@ -1033,8 +1035,8 @@ export default class DataModule extends BaseModule {
 
 								// Item must be an actual object, so if it's not, throw an error
 								if (
-									Object.prototype.toString.call(item) !==
-									"[object Object]"
+									typeof item !== "object" ||
+									item.constructor.name !== "Object"
 								)
 									throw Error("not an object");