Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions sdks/typescript/src/dsl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,9 @@ export class StreamBound implements Encodable {
readonly payload: unknown,
) {}
static literal(value: number | bigint): StreamBound {
if ((typeof value === "number" && value < 0) || (typeof value === "bigint" && value < 0n)) {
throw new TypeError("stream bound literal must be non-negative");
}
const safe = intToJson(value);
if (typeof safe === "bigint") {
if (safe > BigInt(Number.MAX_SAFE_INTEGER)) throw new TypeError(`stream bound exceeds JavaScript safe integer range: ${safe}`);
Expand Down
9 changes: 9 additions & 0 deletions sdks/typescript/test/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
RepeatConfig,
ShortestPathDirection,
SourcePredicate,
StreamBound,
VectorDistanceMetric,
WhenThen,
bytes,
Expand Down Expand Up @@ -116,6 +117,14 @@ for (const value of [-1, 1.5, 256, "7", true]) {
}
assert.deepEqual(parsed(PropertyInput.param("limit")), { expr: { param: "limit" } });
assert.deepEqual(parsed(NodeRef.param("node_ids")), { param: "node_ids" });
assert.deepEqual(parsed(StreamBound.literal(0)), { literal: 0 });
assert.deepEqual(parsed(StreamBound.literal(BigInt(Number.MAX_SAFE_INTEGER))), {
literal: Number.MAX_SAFE_INTEGER,
});
for (const value of [-1, -1n, -9_007_199_254_740_993n]) {
assert.throws(() => StreamBound.literal(value), TypeError);
}
assert.throws(() => StreamBound.literal(BigInt(Number.MAX_SAFE_INTEGER) + 1n), TypeError);
assert.deepEqual(parsed(QueryParamType.array(QueryParamType.array(QueryParamType.f64()))), { array: { array: "f64" } });
assert.equal(Object.isFrozen(param.array(param.string())), true);
assert.equal(Object.isFrozen(QueryParamType.array(QueryParamType.string())), true);
Expand Down
Loading