Skip to content

Commit

Permalink
Continue to use Long.gt and lt
Browse files Browse the repository at this point in the history
  • Loading branch information
timostamm committed Jun 7, 2024
1 parent 4a3c229 commit 8ee95c0
Show file tree
Hide file tree
Showing 70 changed files with 210 additions and 280 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -648,14 +648,13 @@ export type Exact<P, I extends P> = P extends Builtin ? P
: P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };

function longToNumber(long: Long): number {
const num = long.toNumber();
if (num > globalThis.Number.MAX_SAFE_INTEGER) {
if (long.gt(globalThis.Number.MAX_SAFE_INTEGER)) {
throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
}
if (num < globalThis.Number.MIN_SAFE_INTEGER) {
if (long.lt(globalThis.Number.MIN_SAFE_INTEGER)) {
throw new globalThis.Error("Value is smaller than Number.MIN_SAFE_INTEGER");
}
return num;
return long.toNumber();
}

if (_m0.util.Long !== Long) {
Expand Down
7 changes: 3 additions & 4 deletions integration/bytes-node/google/protobuf/wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -631,14 +631,13 @@ export type Exact<P, I extends P> = P extends Builtin ? P
: P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };

function longToNumber(long: Long): number {
const num = long.toNumber();
if (num > globalThis.Number.MAX_SAFE_INTEGER) {
if (long.gt(globalThis.Number.MAX_SAFE_INTEGER)) {
throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
}
if (num < globalThis.Number.MIN_SAFE_INTEGER) {
if (long.lt(globalThis.Number.MIN_SAFE_INTEGER)) {
throw new globalThis.Error("Value is smaller than Number.MIN_SAFE_INTEGER");
}
return num;
return long.toNumber();
}

if (_m0.util.Long !== Long) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,13 @@ export type Exact<P, I extends P> = P extends Builtin ? P
: P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };

function longToNumber(long: Long): number {
const num = long.toNumber();
if (num > globalThis.Number.MAX_SAFE_INTEGER) {
if (long.gt(globalThis.Number.MAX_SAFE_INTEGER)) {
throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
}
if (num < globalThis.Number.MIN_SAFE_INTEGER) {
if (long.lt(globalThis.Number.MIN_SAFE_INTEGER)) {
throw new globalThis.Error("Value is smaller than Number.MIN_SAFE_INTEGER");
}
return num;
return long.toNumber();
}

if (_m0.util.Long !== Long) {
Expand Down
7 changes: 3 additions & 4 deletions integration/emit-default-values-json/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -751,14 +751,13 @@ function fromJsonTimestamp(o: any): Date {
}

function longToNumber(long: Long): number {
const num = long.toNumber();
if (num > globalThis.Number.MAX_SAFE_INTEGER) {
if (long.gt(globalThis.Number.MAX_SAFE_INTEGER)) {
throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
}
if (num < globalThis.Number.MIN_SAFE_INTEGER) {
if (long.lt(globalThis.Number.MIN_SAFE_INTEGER)) {
throw new globalThis.Error("Value is smaller than Number.MIN_SAFE_INTEGER");
}
return num;
return long.toNumber();
}

if (_m0.util.Long !== Long) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,13 @@ export type Exact<P, I extends P> = P extends Builtin ? P
: P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };

function longToNumber(long: Long): number {
const num = long.toNumber();
if (num > globalThis.Number.MAX_SAFE_INTEGER) {
if (long.gt(globalThis.Number.MAX_SAFE_INTEGER)) {
throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
}
if (num < globalThis.Number.MIN_SAFE_INTEGER) {
if (long.lt(globalThis.Number.MIN_SAFE_INTEGER)) {
throw new globalThis.Error("Value is smaller than Number.MIN_SAFE_INTEGER");
}
return num;
return long.toNumber();
}

function longToString(long: Long) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,13 @@ export type Exact<P, I extends P> = P extends Builtin ? P
: P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };

function longToNumber(long: Long): number {
const num = long.toNumber();
if (num > globalThis.Number.MAX_SAFE_INTEGER) {
if (long.gt(globalThis.Number.MAX_SAFE_INTEGER)) {
throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
}
if (num < globalThis.Number.MIN_SAFE_INTEGER) {
if (long.lt(globalThis.Number.MIN_SAFE_INTEGER)) {
throw new globalThis.Error("Value is smaller than Number.MIN_SAFE_INTEGER");
}
return num;
return long.toNumber();
}

function longToString(long: Long) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,13 @@ export type Exact<P, I extends P> = P extends Builtin ? P
: P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };

function longToNumber(long: Long): number {
const num = long.toNumber();
if (num > globalThis.Number.MAX_SAFE_INTEGER) {
if (long.gt(globalThis.Number.MAX_SAFE_INTEGER)) {
throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
}
if (num < globalThis.Number.MIN_SAFE_INTEGER) {
if (long.lt(globalThis.Number.MIN_SAFE_INTEGER)) {
throw new globalThis.Error("Value is smaller than Number.MIN_SAFE_INTEGER");
}
return num;
return long.toNumber();
}

function longToString(long: Long) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,13 @@ export type Exact<P, I extends P> = P extends Builtin ? P
: P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };

function longToNumber(long: Long): number {
const num = long.toNumber();
if (num > globalThis.Number.MAX_SAFE_INTEGER) {
if (long.gt(globalThis.Number.MAX_SAFE_INTEGER)) {
throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
}
if (num < globalThis.Number.MIN_SAFE_INTEGER) {
if (long.lt(globalThis.Number.MIN_SAFE_INTEGER)) {
throw new globalThis.Error("Value is smaller than Number.MIN_SAFE_INTEGER");
}
return num;
return long.toNumber();
}

function longToString(long: Long) {
Expand Down
7 changes: 3 additions & 4 deletions integration/fieldoption-jstype/fieldoption-jstype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,14 +495,13 @@ export type Exact<P, I extends P> = P extends Builtin ? P
: P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };

function longToNumber(long: Long): number {
const num = long.toNumber();
if (num > globalThis.Number.MAX_SAFE_INTEGER) {
if (long.gt(globalThis.Number.MAX_SAFE_INTEGER)) {
throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
}
if (num < globalThis.Number.MIN_SAFE_INTEGER) {
if (long.lt(globalThis.Number.MIN_SAFE_INTEGER)) {
throw new globalThis.Error("Value is smaller than Number.MIN_SAFE_INTEGER");
}
return num;
return long.toNumber();
}

function longToString(long: Long) {
Expand Down
7 changes: 3 additions & 4 deletions integration/file-suffix/google/protobuf/timestamp.pb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,13 @@ export type Exact<P, I extends P> = P extends Builtin ? P
: P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };

function longToNumber(long: Long): number {
const num = long.toNumber();
if (num > globalThis.Number.MAX_SAFE_INTEGER) {
if (long.gt(globalThis.Number.MAX_SAFE_INTEGER)) {
throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
}
if (num < globalThis.Number.MIN_SAFE_INTEGER) {
if (long.lt(globalThis.Number.MIN_SAFE_INTEGER)) {
throw new globalThis.Error("Value is smaller than Number.MIN_SAFE_INTEGER");
}
return num;
return long.toNumber();
}

if (_m0.util.Long !== Long) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,13 @@ export type Exact<P, I extends P> = P extends Builtin ? P
: P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };

function longToNumber(long: Long): number {
const num = long.toNumber();
if (num > globalThis.Number.MAX_SAFE_INTEGER) {
if (long.gt(globalThis.Number.MAX_SAFE_INTEGER)) {
throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
}
if (num < globalThis.Number.MIN_SAFE_INTEGER) {
if (long.lt(globalThis.Number.MIN_SAFE_INTEGER)) {
throw new globalThis.Error("Value is smaller than Number.MIN_SAFE_INTEGER");
}
return num;
return long.toNumber();
}

if (_m0.util.Long !== Long) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,13 @@ export type Exact<P, I extends P> = P extends Builtin ? P
: P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };

function longToNumber(long: Long): number {
const num = long.toNumber();
if (num > globalThis.Number.MAX_SAFE_INTEGER) {
if (long.gt(globalThis.Number.MAX_SAFE_INTEGER)) {
throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
}
if (num < globalThis.Number.MIN_SAFE_INTEGER) {
if (long.lt(globalThis.Number.MIN_SAFE_INTEGER)) {
throw new globalThis.Error("Value is smaller than Number.MIN_SAFE_INTEGER");
}
return num;
return long.toNumber();
}

if (_m0.util.Long !== Long) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,13 @@ export type Exact<P, I extends P> = P extends Builtin ? P
: P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };

function longToNumber(long: Long): number {
const num = long.toNumber();
if (num > globalThis.Number.MAX_SAFE_INTEGER) {
if (long.gt(globalThis.Number.MAX_SAFE_INTEGER)) {
throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
}
if (num < globalThis.Number.MIN_SAFE_INTEGER) {
if (long.lt(globalThis.Number.MIN_SAFE_INTEGER)) {
throw new globalThis.Error("Value is smaller than Number.MIN_SAFE_INTEGER");
}
return num;
return long.toNumber();
}

if (_m0.util.Long !== Long) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,13 @@ export type Exact<P, I extends P> = P extends Builtin ? P
: P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };

function longToNumber(long: Long): number {
const num = long.toNumber();
if (num > globalThis.Number.MAX_SAFE_INTEGER) {
if (long.gt(globalThis.Number.MAX_SAFE_INTEGER)) {
throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
}
if (num < globalThis.Number.MIN_SAFE_INTEGER) {
if (long.lt(globalThis.Number.MIN_SAFE_INTEGER)) {
throw new globalThis.Error("Value is smaller than Number.MIN_SAFE_INTEGER");
}
return num;
return long.toNumber();
}

if (_m0.util.Long !== Long) {
Expand Down
7 changes: 3 additions & 4 deletions integration/grpc-js/google/protobuf/timestamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,13 @@ export type Exact<P, I extends P> = P extends Builtin ? P
: P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };

function longToNumber(long: Long): number {
const num = long.toNumber();
if (num > globalThis.Number.MAX_SAFE_INTEGER) {
if (long.gt(globalThis.Number.MAX_SAFE_INTEGER)) {
throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
}
if (num < globalThis.Number.MIN_SAFE_INTEGER) {
if (long.lt(globalThis.Number.MIN_SAFE_INTEGER)) {
throw new globalThis.Error("Value is smaller than Number.MIN_SAFE_INTEGER");
}
return num;
return long.toNumber();
}

if (_m0.util.Long !== Long) {
Expand Down
7 changes: 3 additions & 4 deletions integration/grpc-js/google/protobuf/wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -648,14 +648,13 @@ export type Exact<P, I extends P> = P extends Builtin ? P
: P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };

function longToNumber(long: Long): number {
const num = long.toNumber();
if (num > globalThis.Number.MAX_SAFE_INTEGER) {
if (long.gt(globalThis.Number.MAX_SAFE_INTEGER)) {
throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
}
if (num < globalThis.Number.MIN_SAFE_INTEGER) {
if (long.lt(globalThis.Number.MIN_SAFE_INTEGER)) {
throw new globalThis.Error("Value is smaller than Number.MIN_SAFE_INTEGER");
}
return num;
return long.toNumber();
}

if (_m0.util.Long !== Long) {
Expand Down
7 changes: 3 additions & 4 deletions integration/grpc-web/google/protobuf/wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -648,14 +648,13 @@ export type Exact<P, I extends P> = P extends Builtin ? P
: P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };

function longToNumber(long: Long): number {
const num = long.toNumber();
if (num > globalThis.Number.MAX_SAFE_INTEGER) {
if (long.gt(globalThis.Number.MAX_SAFE_INTEGER)) {
throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
}
if (num < globalThis.Number.MIN_SAFE_INTEGER) {
if (long.lt(globalThis.Number.MIN_SAFE_INTEGER)) {
throw new globalThis.Error("Value is smaller than Number.MIN_SAFE_INTEGER");
}
return num;
return long.toNumber();
}

if (_m0.util.Long !== Long) {
Expand Down
7 changes: 3 additions & 4 deletions integration/import-mapping/google/protobuf/timestamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,13 @@ export type Exact<P, I extends P> = P extends Builtin ? P
: P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };

function longToNumber(long: Long): number {
const num = long.toNumber();
if (num > globalThis.Number.MAX_SAFE_INTEGER) {
if (long.gt(globalThis.Number.MAX_SAFE_INTEGER)) {
throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
}
if (num < globalThis.Number.MIN_SAFE_INTEGER) {
if (long.lt(globalThis.Number.MIN_SAFE_INTEGER)) {
throw new globalThis.Error("Value is smaller than Number.MIN_SAFE_INTEGER");
}
return num;
return long.toNumber();
}

if (_m0.util.Long !== Long) {
Expand Down
7 changes: 3 additions & 4 deletions integration/import-suffix/google/protobuf/timestamp.pb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,13 @@ export type Exact<P, I extends P> = P extends Builtin ? P
: P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };

function longToNumber(long: Long): number {
const num = long.toNumber();
if (num > globalThis.Number.MAX_SAFE_INTEGER) {
if (long.gt(globalThis.Number.MAX_SAFE_INTEGER)) {
throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
}
if (num < globalThis.Number.MIN_SAFE_INTEGER) {
if (long.lt(globalThis.Number.MIN_SAFE_INTEGER)) {
throw new globalThis.Error("Value is smaller than Number.MIN_SAFE_INTEGER");
}
return num;
return long.toNumber();
}

if (_m0.util.Long !== Long) {
Expand Down
7 changes: 3 additions & 4 deletions integration/map-long-optional/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,13 @@ export type Exact<P, I extends P> = P extends Builtin ? P
: P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };

function longToNumber(long: Long): number {
const num = long.toNumber();
if (num > globalThis.Number.MAX_SAFE_INTEGER) {
if (long.gt(globalThis.Number.MAX_SAFE_INTEGER)) {
throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
}
if (num < globalThis.Number.MIN_SAFE_INTEGER) {
if (long.lt(globalThis.Number.MIN_SAFE_INTEGER)) {
throw new globalThis.Error("Value is smaller than Number.MIN_SAFE_INTEGER");
}
return num;
return long.toNumber();
}

if (_m0.util.Long !== Long) {
Expand Down
7 changes: 3 additions & 4 deletions integration/meta-typings/google/protobuf/timestamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,13 @@ export const protoMetadata: ProtoMetadata = {
};

function longToNumber(long: Long): number {
const num = long.toNumber();
if (num > globalThis.Number.MAX_SAFE_INTEGER) {
if (long.gt(globalThis.Number.MAX_SAFE_INTEGER)) {
throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
}
if (num < globalThis.Number.MIN_SAFE_INTEGER) {
if (long.lt(globalThis.Number.MIN_SAFE_INTEGER)) {
throw new globalThis.Error("Value is smaller than Number.MIN_SAFE_INTEGER");
}
return num;
return long.toNumber();
}

if (_m0.util.Long !== Long) {
Expand Down
7 changes: 3 additions & 4 deletions integration/meta-typings/google/protobuf/wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -821,14 +821,13 @@ export const protoMetadata: ProtoMetadata = {
};

function longToNumber(long: Long): number {
const num = long.toNumber();
if (num > globalThis.Number.MAX_SAFE_INTEGER) {
if (long.gt(globalThis.Number.MAX_SAFE_INTEGER)) {
throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
}
if (num < globalThis.Number.MIN_SAFE_INTEGER) {
if (long.lt(globalThis.Number.MIN_SAFE_INTEGER)) {
throw new globalThis.Error("Value is smaller than Number.MIN_SAFE_INTEGER");
}
return num;
return long.toNumber();
}

if (_m0.util.Long !== Long) {
Expand Down
Loading

0 comments on commit 8ee95c0

Please sign in to comment.