Skip to content

Commit 5dd14db

Browse files
committed
can't use convex strat - $ is reserved
1 parent fd81d21 commit 5dd14db

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
@@ -1851,21 +1851,35 @@ function compareKeys(key1: Key, key2: Key): number {
18511851
function serializeCursor(key: IndexKey): string {
18521852
return JSON.stringify(
18531853
convexToJson(
1854-
key.map((v): Value => (v === undefined ? { $undefined: true } : v)),
1854+
key.map(
1855+
(v): Value =>
1856+
v === undefined
1857+
? "$_"
1858+
: typeof v === "string" && v.endsWith("$_")
1859+
? // in the unlikely case their string was "$_" or "$$_" etc.
1860+
// we need to escape it. Always add a $ so "$$_" becomes "$$$_"
1861+
"$" + v
1862+
: v,
1863+
),
18551864
),
18561865
);
18571866
}
18581867

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

0 commit comments

Comments
 (0)