Skip to content

Commit d7e317c

Browse files
committed
can't use convex strat - $ is reserved
1 parent 279f177 commit d7e317c

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

packages/convex-helpers/server/stream.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1852,21 +1852,35 @@ function compareKeys(key1: Key, key2: Key): number {
18521852
function serializeCursor(key: IndexKey): string {
18531853
return JSON.stringify(
18541854
convexToJson(
1855-
key.map((v): Value => (v === undefined ? { $undefined: true } : v)),
1855+
key.map(
1856+
(v): Value =>
1857+
v === undefined
1858+
? "$_"
1859+
: typeof v === "string" && v.endsWith("$_")
1860+
? // in the unlikely case their string was "$_" or "$$_" etc.
1861+
// we need to escape it. Always add a $ so "$$_" becomes "$$$_"
1862+
"$" + v
1863+
: v,
1864+
),
18561865
),
18571866
);
18581867
}
18591868

18601869
function deserializeCursor(cursor: string): IndexKey {
18611870
return (jsonToConvex(JSON.parse(cursor)) as Value[]).map((v) => {
1862-
if (typeof v === "object" && !Array.isArray(v) && v !== null) {
1863-
const entries = Object.entries(v);
1864-
if (entries.length === 1 && entries[0]![0] === "$undefined") {
1871+
if (typeof v === "string") {
1872+
if (v === "$_") {
18651873
// This is a special case for the undefined value.
18661874
// It's not a valid value in the index, but it's a valid value in the
18671875
// cursor.
18681876
return undefined;
18691877
}
1878+
if (v.endsWith("$_")) {
1879+
// in the unlikely case their string was "$_" it was changed to "$$_"
1880+
// in the serialization process. If it was "$$_", it was changed to
1881+
// "$$$_" and so on.
1882+
return v.slice(1);
1883+
}
18701884
}
18711885
return v;
18721886
});

0 commit comments

Comments
 (0)