Skip to content

Commit

Permalink
Validate cursor for feeds (#296)
Browse files Browse the repository at this point in the history
  • Loading branch information
ecooper authored Nov 4, 2024
1 parent 5e7313b commit 19458fe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions __tests__/functional/feed-client-configuration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,16 @@ describe("FeedClientConfiguration", () => {
expect(e).toBeInstanceOf(RangeError);
}
});

it("throws a TypeError if 'cursor' is not a string", async () => {
const config = { ...defaultConfig, cursor: null };
try {
new FeedClient(
dummyStreamToken,
config as unknown as FeedClientConfiguration,
);
} catch (e: any) {
expect(e).toBeInstanceOf(TypeError);
}
});
});
4 changes: 4 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,10 @@ export class FeedClient<T extends QueryValue = any> {
"Only one of 'start_ts' or 'cursor' can be defined in the client configuration.",
);
}

if (config.cursor !== undefined && typeof config.cursor !== "string") {
throw new TypeError("'cursor' must be a string.");
}
}
}

Expand Down

0 comments on commit 19458fe

Please sign in to comment.