@spacelr/sdk 0.10.9 → 0.10.10

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/dist/index.d.mts CHANGED
@@ -1211,14 +1211,22 @@ interface SubscribeWithSnapshotOptions<T> {
1211
1211
  * `{ status: { $in: [...] } }`, `{ ts: { $gt: ... } }`, etc. Always fully
1212
1212
  * applied to the snapshot `find()`.
1213
1213
  *
1214
- * **Live-stream semantics** — three cases (#712):
1214
+ * **Live-stream semantics** — three cases (#712, #719):
1215
1215
  *
1216
- * 1. Every clause is scalar equality or `{ $in: [...] }` of finite scalars
1217
- * (e.g. `{ chatId: 'c1' }` or `{ room: 'r1', status: { $in: ['a','b'] } }`):
1216
+ * 1. Every clause is in the safe subset — scalar equality, `{ $in: [...] }` of
1217
+ * finite scalars, or `$and`/`$or` composing those leaves (#719), e.g.
1218
+ * `{ chatId: 'c1' }`, `{ room: 'r1', status: { $in: ['a','b'] } }`, or
1219
+ * `{ $or: [{ authorId: 'me' }, { sharedWith: { $in: ['me'] } }] }`:
1218
1220
  * the filter is enforced on `onChange` too, via a client-side post-filter,
1219
- * so live delivery matches the snapshot exactly. No re-check needed.
1220
- * 2. `where` contains ANY other clause (`$gt`, `$ne`, a `Date`, a dotted
1221
- * path, a nested object, a non-finite number, …): the WHOLE `where` falls
1221
+ * so live delivery matches the snapshot's scope: `onChange` never MISSES a
1222
+ * document the snapshot includes (no under-delivery). For plain JSON scalar
1223
+ * fields this is exact; when a value's stored BSON type differs from its
1224
+ * JSON wire form (e.g. a `Date`/`ObjectId` field compared by equality to a
1225
+ * matching string), the post-filter may OVER-deliver slightly — never
1226
+ * under-deliver — so a re-check is only needed if that edge matters.
1227
+ * 2. `where` contains ANY other clause (`$gt`, `$ne`, `$nin`, `$nor`, a `Date`,
1228
+ * a dotted path, a nested object, a non-finite number, …): the WHOLE `where`
1229
+ * falls
1222
1230
  * back to server-side filtering only, which keeps top-level scalar
1223
1231
  * equality but drops operator clauses. The snapshot is still fully
1224
1232
  * filtered, but `onChange` may OVER-deliver (you may see events outside
package/dist/index.d.ts CHANGED
@@ -1211,14 +1211,22 @@ interface SubscribeWithSnapshotOptions<T> {
1211
1211
  * `{ status: { $in: [...] } }`, `{ ts: { $gt: ... } }`, etc. Always fully
1212
1212
  * applied to the snapshot `find()`.
1213
1213
  *
1214
- * **Live-stream semantics** — three cases (#712):
1214
+ * **Live-stream semantics** — three cases (#712, #719):
1215
1215
  *
1216
- * 1. Every clause is scalar equality or `{ $in: [...] }` of finite scalars
1217
- * (e.g. `{ chatId: 'c1' }` or `{ room: 'r1', status: { $in: ['a','b'] } }`):
1216
+ * 1. Every clause is in the safe subset — scalar equality, `{ $in: [...] }` of
1217
+ * finite scalars, or `$and`/`$or` composing those leaves (#719), e.g.
1218
+ * `{ chatId: 'c1' }`, `{ room: 'r1', status: { $in: ['a','b'] } }`, or
1219
+ * `{ $or: [{ authorId: 'me' }, { sharedWith: { $in: ['me'] } }] }`:
1218
1220
  * the filter is enforced on `onChange` too, via a client-side post-filter,
1219
- * so live delivery matches the snapshot exactly. No re-check needed.
1220
- * 2. `where` contains ANY other clause (`$gt`, `$ne`, a `Date`, a dotted
1221
- * path, a nested object, a non-finite number, …): the WHOLE `where` falls
1221
+ * so live delivery matches the snapshot's scope: `onChange` never MISSES a
1222
+ * document the snapshot includes (no under-delivery). For plain JSON scalar
1223
+ * fields this is exact; when a value's stored BSON type differs from its
1224
+ * JSON wire form (e.g. a `Date`/`ObjectId` field compared by equality to a
1225
+ * matching string), the post-filter may OVER-deliver slightly — never
1226
+ * under-deliver — so a re-check is only needed if that edge matters.
1227
+ * 2. `where` contains ANY other clause (`$gt`, `$ne`, `$nin`, `$nor`, a `Date`,
1228
+ * a dotted path, a nested object, a non-finite number, …): the WHOLE `where`
1229
+ * falls
1222
1230
  * back to server-side filtering only, which keeps top-level scalar
1223
1231
  * equality but drops operator clauses. The snapshot is still fully
1224
1232
  * filtered, but `onChange` may OVER-deliver (you may see events outside
package/dist/index.js CHANGED
@@ -741,11 +741,28 @@ function isSupportedInClause(v) {
741
741
  const candidates = v["$in"];
742
742
  return Array.isArray(candidates) && candidates.every(isFiniteScalar);
743
743
  }
744
+ var MAX_WHERE_DEPTH = 10;
744
745
  function isMongoWhereFullySupported(where) {
746
+ return isSupportedWhereObject(where, 0);
747
+ }
748
+ function isSupportedWhereObject(where, depth) {
749
+ if (depth > MAX_WHERE_DEPTH) return false;
745
750
  for (const [key, value] of Object.entries(where)) {
751
+ if (key === "$and" || key === "$or") {
752
+ if (!Array.isArray(value) || value.length === 0) return false;
753
+ for (const clause of value) {
754
+ if (clause === null || typeof clause !== "object" || Array.isArray(clause)) {
755
+ return false;
756
+ }
757
+ if (!isSupportedWhereObject(clause, depth + 1)) {
758
+ return false;
759
+ }
760
+ }
761
+ continue;
762
+ }
763
+ if (key.startsWith("$")) return false;
746
764
  if (key.includes(".")) return false;
747
765
  if (RESERVED_PATH_SEGMENTS.has(key)) return false;
748
- if (key.startsWith("$")) return false;
749
766
  if (isFiniteScalar(value)) continue;
750
767
  if (isSupportedInClause(value)) continue;
751
768
  return false;
@@ -754,6 +771,20 @@ function isMongoWhereFullySupported(where) {
754
771
  }
755
772
  function matchesMongoWhere(document2, where) {
756
773
  for (const [key, value] of Object.entries(where)) {
774
+ if (key === "$and") {
775
+ const clauses = value;
776
+ if (!clauses.every((clause) => matchesMongoWhere(document2, clause))) {
777
+ return false;
778
+ }
779
+ continue;
780
+ }
781
+ if (key === "$or") {
782
+ const clauses = value;
783
+ if (!clauses.some((clause) => matchesMongoWhere(document2, clause))) {
784
+ return false;
785
+ }
786
+ continue;
787
+ }
757
788
  const actual = resolveWherePath(document2, key);
758
789
  if (actual === WHERE_PATH_ABSENT || actual === WHERE_PATH_UNRESOLVABLE) {
759
790
  return false;