@spacelr/sdk 0.10.8 → 0.10.9
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 +20 -13
- package/dist/index.d.ts +20 -13
- package/dist/index.js +51 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +51 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -684,6 +684,47 @@ function whereValueMatches(actual, expected) {
|
|
|
684
684
|
if (Array.isArray(actual)) return actual.includes(expected);
|
|
685
685
|
return actual === expected;
|
|
686
686
|
}
|
|
687
|
+
function isFiniteScalar(v) {
|
|
688
|
+
const t = typeof v;
|
|
689
|
+
if (t === "string" || t === "boolean") return true;
|
|
690
|
+
if (t === "number") return Number.isFinite(v);
|
|
691
|
+
return false;
|
|
692
|
+
}
|
|
693
|
+
function isSupportedInClause(v) {
|
|
694
|
+
if (typeof v !== "object" || v === null || Array.isArray(v)) return false;
|
|
695
|
+
const keys = Object.keys(v);
|
|
696
|
+
if (keys.length !== 1 || keys[0] !== "$in") return false;
|
|
697
|
+
const candidates = v["$in"];
|
|
698
|
+
return Array.isArray(candidates) && candidates.every(isFiniteScalar);
|
|
699
|
+
}
|
|
700
|
+
function isMongoWhereFullySupported(where) {
|
|
701
|
+
for (const [key, value] of Object.entries(where)) {
|
|
702
|
+
if (key.includes(".")) return false;
|
|
703
|
+
if (RESERVED_PATH_SEGMENTS.has(key)) return false;
|
|
704
|
+
if (key.startsWith("$")) return false;
|
|
705
|
+
if (isFiniteScalar(value)) continue;
|
|
706
|
+
if (isSupportedInClause(value)) continue;
|
|
707
|
+
return false;
|
|
708
|
+
}
|
|
709
|
+
return true;
|
|
710
|
+
}
|
|
711
|
+
function matchesMongoWhere(document2, where) {
|
|
712
|
+
for (const [key, value] of Object.entries(where)) {
|
|
713
|
+
const actual = resolveWherePath(document2, key);
|
|
714
|
+
if (actual === WHERE_PATH_ABSENT || actual === WHERE_PATH_UNRESOLVABLE) {
|
|
715
|
+
return false;
|
|
716
|
+
}
|
|
717
|
+
if (isSupportedInClause(value)) {
|
|
718
|
+
const candidates = value["$in"];
|
|
719
|
+
const matched2 = Array.isArray(actual) ? actual.some((el) => candidates.includes(el)) : candidates.includes(actual);
|
|
720
|
+
if (!matched2) return false;
|
|
721
|
+
continue;
|
|
722
|
+
}
|
|
723
|
+
const matched = Array.isArray(actual) ? actual.includes(value) : actual === value;
|
|
724
|
+
if (!matched) return false;
|
|
725
|
+
}
|
|
726
|
+
return true;
|
|
727
|
+
}
|
|
687
728
|
var RealtimeClient = class {
|
|
688
729
|
constructor(config) {
|
|
689
730
|
this.socket = null;
|
|
@@ -2784,9 +2825,11 @@ var CollectionRef = class {
|
|
|
2784
2825
|
}
|
|
2785
2826
|
return Object.keys(out).length > 0 ? out : void 0;
|
|
2786
2827
|
})();
|
|
2787
|
-
|
|
2828
|
+
const postFilterWhere = opts.where && Object.keys(opts.where).length > 0 && isMongoWhereFullySupported(opts.where) ? opts.where : void 0;
|
|
2829
|
+
const postFilter = postFilterWhere !== void 0;
|
|
2830
|
+
if (opts.where && Object.keys(opts.where).length > 0 && !postFilter) {
|
|
2788
2831
|
console.warn(
|
|
2789
|
-
`[spacelr] subscribeWithSnapshot on ${this.projectId}:${this.collectionName}: 'where' filter contains
|
|
2832
|
+
`[spacelr] subscribeWithSnapshot on ${this.projectId}:${this.collectionName}: 'where' filter contains clauses (e.g. $gt, $ne, Date, dotted paths) that may not be enforced on the live stream. onChange may receive events beyond the filter; snapshot is still fully filtered.`
|
|
2790
2833
|
);
|
|
2791
2834
|
}
|
|
2792
2835
|
const runRecovery = async () => {
|
|
@@ -2805,6 +2848,9 @@ var CollectionRef = class {
|
|
|
2805
2848
|
where: streamWhere,
|
|
2806
2849
|
onEvent: async ({ event }) => {
|
|
2807
2850
|
if (!isActive) return;
|
|
2851
|
+
if (postFilterWhere && (!event.document || !matchesMongoWhere(event.document, postFilterWhere))) {
|
|
2852
|
+
return;
|
|
2853
|
+
}
|
|
2808
2854
|
if (!recoverySnapshotDelivered) {
|
|
2809
2855
|
pendingRecoveryEvents.push(event);
|
|
2810
2856
|
return;
|
|
@@ -2936,6 +2982,9 @@ var CollectionRef = class {
|
|
|
2936
2982
|
where: streamWhere,
|
|
2937
2983
|
onEvent: async ({ event }) => {
|
|
2938
2984
|
if (!isActive) return;
|
|
2985
|
+
if (postFilterWhere && (!event.document || !matchesMongoWhere(event.document, postFilterWhere))) {
|
|
2986
|
+
return;
|
|
2987
|
+
}
|
|
2939
2988
|
if (!initialSnapshotDelivered) {
|
|
2940
2989
|
pendingInitialEvents.push(event);
|
|
2941
2990
|
return;
|