@justair/justair-library 7.5.0-alpha.a2c0215 → 7.5.0-alpha.b8c1c8a

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.
@@ -1 +1 @@
1
- {"version":3,"file":"subscribedDevices.d.ts","sourceRoot":"","sources":["../../src/utils/subscribedDevices.js"],"names":[],"mappings":"AA4EA;;;;;GAKG;AAyII,8DANI,KAAK,CAAC;IAAE,QAAQ,EAAE,OAAO,UAAU,EAAE,KAAK,CAAC,QAAQ,CAAC;IAC1D,UAAU,EAAE,OAAO,6BAA6B,EAAE,UAAU,CAAA;CAAE,CAAC,8BACzD;IAAE,qBAAqB,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,UAAU,EAAE,KAAK,CAAC,QAAQ,EAAE,KAC7E,OAAO,CAAC,KAAK,CAAC,OAAO,UAAU,EAAE,KAAK,CAAC,QAAQ,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC,CAAA;CAAE,GAC9D,OAAO,CAAC,OAAO,UAAU,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CA0BxD"}
1
+ {"version":3,"file":"subscribedDevices.d.ts","sourceRoot":"","sources":["../../src/utils/subscribedDevices.js"],"names":[],"mappings":"AA4EA;;;;;GAKG;AA4II,8DANI,KAAK,CAAC;IAAE,QAAQ,EAAE,OAAO,UAAU,EAAE,KAAK,CAAC,QAAQ,CAAC;IAC1D,UAAU,EAAE,OAAO,6BAA6B,EAAE,UAAU,CAAA;CAAE,CAAC,8BACzD;IAAE,qBAAqB,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,UAAU,EAAE,KAAK,CAAC,QAAQ,EAAE,KAC7E,OAAO,CAAC,KAAK,CAAC,OAAO,UAAU,EAAE,KAAK,CAAC,QAAQ,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC,CAAA;CAAE,GAC9D,OAAO,CAAC,OAAO,UAAU,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CA0BxD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@justair/justair-library",
3
- "version": "7.5.0-alpha.a2c0215",
3
+ "version": "7.5.0-alpha.b8c1c8a",
4
4
  "description": "JustAir Internal Library",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -145,15 +145,10 @@ const validateResolvedSiteMonitorIds = (resolved) => {
145
145
  throw error;
146
146
  }
147
147
 
148
- // Discriminating a document from an id without importing mongoose: both
149
- // expose `_id`, because mongoose defines `_id` on ObjectId.prototype as a
150
- // self-reference (`oid._id === oid`). A document's `_id` is a *different*
151
- // object, so the self-reference is the test — checking merely for the
152
- // presence of `_id` would reject every ordinary ObjectId.
153
- // `.map` instead of `.flatMap` yields [[m1, m2]]. It is not caught by the
154
- // document check (an array is not a plain object) and fails inconsistently
155
- // downstream: one monitor per Site casts back to the id and silently works,
156
- // two throws a CastError at write time, far from the cause.
148
+ // `.map` instead of `.flatMap` yields [[m1, m2]]. An array is not a plain
149
+ // object, so the document check below never sees it, and it fails
150
+ // inconsistently downstream: one monitor per Site casts back to the id and
151
+ // silently works, two throws a CastError at write time, far from the cause.
157
152
  if (resolved.some(Array.isArray)) {
158
153
  const error = new TypeError(
159
154
  "resolveSiteMonitorIds must resolve to a flat array of monitor ids"
@@ -162,9 +157,17 @@ const validateResolvedSiteMonitorIds = (resolved) => {
162
157
  throw error;
163
158
  }
164
159
 
160
+ // Discriminating a document from an id without importing mongoose: test for
161
+ // what only an id has. `toHexString` is on ObjectId (mongoose-patched or raw
162
+ // bson) and on nothing a Sites query returns, hydrated or lean.
163
+ //
164
+ // Deliberately not keyed on `_id`, which is wrong in both directions: every
165
+ // ObjectId appears to carry one (mongoose defines `_id` on ObjectId.prototype
166
+ // as a self-reference), and a lean read that projects it away
167
+ // (`Sites.find(..., "monitorIds -_id").lean()`) carries none.
165
168
  if (
166
169
  resolved.some(
167
- (id) => isPlainObject(id) && id._id !== undefined && id._id !== id
170
+ (id) => isPlainObject(id) && typeof id.toHexString !== "function"
168
171
  )
169
172
  ) {
170
173
  const error = new TypeError(
@@ -148,6 +148,20 @@ describe('projectSubscribedMonitors', () => {
148
148
  });
149
149
  });
150
150
 
151
+ test('rejects a lean Site read that projected _id away', async () => {
152
+ // The `_id`-based discriminator missed this: `Sites.find(..., "monitorIds
153
+ // -_id").lean()` yields objects carrying no _id at all, which would
154
+ // otherwise key as "[object Object]" in dedupeById and land in
155
+ // subscribedMonitors as junk.
156
+ await expect(
157
+ projectSubscribedMonitors([{ deviceId: oid(), deviceType: 'linked-device' }], {
158
+ resolveSiteMonitorIds: async () => [{ monitorIds: [oid()] }],
159
+ }),
160
+ ).rejects.toMatchObject({
161
+ code: SUBSCRIBED_DEVICES_ERRORS.RESOLVER_RETURNED_DOCUMENTS,
162
+ });
163
+ });
164
+
151
165
  test('does not mistake ordinary ObjectIds for documents', async () => {
152
166
  // Regression guard for the discriminator: mongoose defines `_id` on
153
167
  // ObjectId.prototype as a self-reference, so a naive "has _id" check