Skip to content

Commit

Permalink
Use bigint instead of BitInt
Browse files Browse the repository at this point in the history
BigInt is a name of the contructor, but the type in TypeScript is bigint
  • Loading branch information
drogus committed Mar 12, 2024
1 parent 6036fdb commit c414260
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 32 deletions.
4 changes: 2 additions & 2 deletions examples/quickstart/client/src/module_bindings/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ export class Message extends DatabaseTable {
public static db: ClientDB = __SPACETIMEDB__.clientDB;
public static tableName = "Message";
public sender: Identity;
public sent: BigInt;
public sent: bigint;
public text: string;

constructor(sender: Identity, sent: BigInt, text: string) {
constructor(sender: Identity, sent: bigint, text: string) {
super();
this.sender = sender;
this.sent = sent;
Expand Down
52 changes: 26 additions & 26 deletions src/algebraic_value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ export interface ValueAdapter {
readU16: () => number;
readI32: () => number;
readU32: () => number;
readI64: () => BigInt;
readU64: () => BigInt;
readU128: () => BigInt;
readI128: () => BigInt;
readI64: () => bigint;
readU64: () => bigint;
readU128: () => bigint;
readI128: () => bigint;
readF32: () => number;
readF64: () => number;

Expand Down Expand Up @@ -161,16 +161,16 @@ export class BinaryAdapter implements ValueAdapter {
readU32(): number {
return this.reader.readU32();
}
readI64(): BigInt {
readI64(): bigint {
return this.reader.readI64();
}
readU64(): BigInt {
readU64(): bigint {
return this.reader.readU64();
}
readU128(): BigInt {
readU128(): bigint {
return this.reader.readU128();
}
readI128(): BigInt {
readI128(): bigint {
return this.reader.readI128();
}
readF32(): number {
Expand Down Expand Up @@ -281,16 +281,16 @@ export class JSONAdapter implements ValueAdapter {
readU32(): number {
return this.value;
}
readI64(): BigInt {
readI64(): bigint {
return this.value;
}
readU64(): BigInt {
readU64(): bigint {
return this.value;
}
readU128(): BigInt {
readU128(): bigint {
return this.value;
}
readI128(): BigInt {
readI128(): bigint {
return this.value;
}
readF32(): number {
Expand All @@ -305,10 +305,10 @@ export class JSONAdapter implements ValueAdapter {
export class SumValue {
/** A tag representing the choice of one variant of the sum type's variants. */
public tag: number;
/**
* Given a variant `Var(Ty)` in a sum type `{ Var(Ty), ... }`,
* this provides the `value` for `Ty`.
*/
/**
* Given a variant `Var(Ty)` in a sum type `{ Var(Ty), ... }`,
* this provides the `value` for `Ty`.
*/
public value: AlgebraicValue;

constructor(tag: number, value: AlgebraicValue) {
Expand All @@ -329,12 +329,12 @@ export class SumValue {
}
}

/**
* A product value is made of a list of
* "elements" / "fields" / "factors" of other `AlgebraicValue`s.
*
* The type of product value is a [product type](`ProductType`).
*/
/**
* A product value is made of a list of
* "elements" / "fields" / "factors" of other `AlgebraicValue`s.
*
* The type of product value is a [product type](`ProductType`).
*/
export class ProductValue {
elements: AlgebraicValue[];

Expand All @@ -360,7 +360,7 @@ type BuiltinValueType =
| string
| number
| AlgebraicValue[]
| BigInt
| bigint
| Map<AlgebraicValue, AlgebraicValue>
| Uint8Array;

Expand Down Expand Up @@ -430,8 +430,8 @@ export class BuiltinValue {
return this.value as boolean;
}

public asBigInt(): BigInt {
return this.value as BigInt;
public asBigInt(): bigint {
return this.value as bigint;
}

public asBoolean(): boolean {
Expand Down Expand Up @@ -529,7 +529,7 @@ export class AlgebraicValue {
return (this.builtin as BuiltinValue).asBool();
}

public asBigInt(): BigInt {
public asBigInt(): bigint {
this.assertBuiltin();
return (this.builtin as BuiltinValue).asBigInt();
}
Expand Down
8 changes: 4 additions & 4 deletions src/binary_reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,27 +75,27 @@ export default class BinaryReader {
return value;
}

readI64(): BigInt {
readI64(): bigint {
const value = this.buffer.getBigInt64(this.offset, true);
this.offset += 8;
return value;
}

readU64(): BigInt {
readU64(): bigint {
const value = this.buffer.getBigUint64(this.offset, true);
this.offset += 8;
return value;
}

readU128(): BigInt {
readU128(): bigint {
const lowerPart = this.buffer.getBigUint64(this.offset, true);
const upperPart = this.buffer.getBigUint64(this.offset + 8, true);
this.offset += 16;

return (upperPart << BigInt(64)) + lowerPart;
}

readI128(): BigInt {
readI128(): bigint {
const lowerPart = this.buffer.getBigInt64(this.offset, true);
const upperPart = this.buffer.getBigInt64(this.offset + 8, true);
this.offset += 16;
Expand Down

0 comments on commit c414260

Please sign in to comment.