Skip to content

Commit 9eb547a

Browse files
committed
can't use convex strat - $ is reserved
1 parent c8096f0 commit 9eb547a

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
@@ -1822,21 +1822,35 @@ function compareKeys(key1: Key, key2: Key): number {
18221822
function serializeCursor(key: IndexKey): string {
18231823
return JSON.stringify(
18241824
convexToJson(
1825-
key.map((v): Value => (v === undefined ? { $undefined: true } : v)),
1825+
key.map(
1826+
(v): Value =>
1827+
v === undefined
1828+
? "$_"
1829+
: typeof v === "string" && v.endsWith("$_")
1830+
? // in the unlikely case their string was "$_" or "$$_" etc.
1831+
// we need to escape it. Always add a $ so "$$_" becomes "$$$_"
1832+
"$" + v
1833+
: v,
1834+
),
18261835
),
18271836
);
18281837
}
18291838

18301839
function deserializeCursor(cursor: string): IndexKey {
18311840
return (jsonToConvex(JSON.parse(cursor)) as Value[]).map((v) => {
1832-
if (typeof v === "object" && !Array.isArray(v) && v !== null) {
1833-
const entries = Object.entries(v);
1834-
if (entries.length === 1 && entries[0]![0] === "$undefined") {
1841+
if (typeof v === "string") {
1842+
if (v === "$_") {
18351843
// This is a special case for the undefined value.
18361844
// It's not a valid value in the index, but it's a valid value in the
18371845
// cursor.
18381846
return undefined;
18391847
}
1848+
if (v.endsWith("$_")) {
1849+
// in the unlikely case their string was "$_" it was changed to "$$_"
1850+
// in the serialization process. If it was "$$_", it was changed to
1851+
// "$$$_" and so on.
1852+
return v.slice(1);
1853+
}
18401854
}
18411855
return v;
18421856
});

0 commit comments

Comments
 (0)