Skip to content

Commit 23bf3e0

Browse files
committed
change to more readable
1 parent 78fdf75 commit 23bf3e0

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

packages/convex-helpers/server/stream.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ describe("stream", () => {
763763
await ctx.db.insert("foo", { a: undefined, b: 5 });
764764
const query = stream(ctx.db, schema).query("foo").withIndex("ab");
765765
const result = await query.paginate({ numItems: 1, cursor: null });
766-
expect(result.continueCursor).toMatch('["$_",');
766+
expect(result.continueCursor).toMatch('["undefined",');
767767
expect(result.page.map(stripSystemFields)).toEqual([
768768
{ a: undefined, b: 3 },
769769
]);

packages/convex-helpers/server/stream.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,11 +1855,11 @@ function serializeCursor(key: IndexKey): string {
18551855
key.map(
18561856
(v): Value =>
18571857
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
1858+
? "undefined"
1859+
: typeof v === "string" && v.endsWith("undefined")
1860+
? // in the unlikely case their string was "undefined"
1861+
// or "_undefined" etc, we escape it.
1862+
"_" + v
18631863
: v,
18641864
),
18651865
),
@@ -1869,16 +1869,17 @@ function serializeCursor(key: IndexKey): string {
18691869
function deserializeCursor(cursor: string): IndexKey {
18701870
return (jsonToConvex(JSON.parse(cursor)) as Value[]).map((v) => {
18711871
if (typeof v === "string") {
1872-
if (v === "$_") {
1872+
if (v === "undefined") {
18731873
// This is a special case for the undefined value.
18741874
// It's not a valid value in the index, but it's a valid value in the
18751875
// cursor.
18761876
return undefined;
18771877
}
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.
1878+
if (v.endsWith("undefined")) {
1879+
// in the unlikely case their string was "undefined" it was changed to
1880+
// "_undefined" in the serialization process.
1881+
// NB: if their string was "_undefined" it was changed to
1882+
// "__undefined" in the serialization process, and so on.
18821883
return v.slice(1);
18831884
}
18841885
}

0 commit comments

Comments
 (0)