@oondemand/oon-core-back 0.3.47 → 0.3.48

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oondemand/oon-core-back",
3
- "version": "0.3.47",
3
+ "version": "0.3.48",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/oondemand/oon-platform.git",
@@ -5,10 +5,21 @@ const { DomainRuleError, valuesEquivalent } = require("./domainRules");
5
5
 
6
6
  function idKey(value) {
7
7
  if (value === null || value === undefined || value === "") return null;
8
- if (typeof value === "object" && value._id) return String(value._id);
8
+ if (typeof value === "object") {
9
+ if (value._id) return idKey(value._id);
10
+ if (typeof value.toHexString === "function") return String(value.toHexString());
11
+ return null;
12
+ }
9
13
  return String(value);
10
14
  }
11
15
 
16
+ function referenceValuesEquivalent(left, right) {
17
+ if (valuesEquivalent(left, right)) return true;
18
+ const leftKey = idKey(left);
19
+ const rightKey = idKey(right);
20
+ return leftKey !== null && rightKey !== null && leftKey === rightKey;
21
+ }
22
+
12
23
  function queryWithSession(query, session) {
13
24
  return session && query && typeof query.session === "function" ? query.session(session) : query;
14
25
  }
@@ -36,7 +47,9 @@ function requiredProjection(rules) {
36
47
 
37
48
  function constraintMatches(constraint, source, local) {
38
49
  const value = source?.[constraint.sourceField];
39
- if (constraint.equalsField) return valuesEquivalent(value, local?.[constraint.equalsField]);
50
+ if (constraint.equalsField) {
51
+ return referenceValuesEquivalent(value, local?.[constraint.equalsField]);
52
+ }
40
53
  if (Object.prototype.hasOwnProperty.call(constraint, "equals")) {
41
54
  return valuesEquivalent(value, constraint.equals);
42
55
  }