Skip to content

Commit

Permalink
feat(all): migrate use of Long to bigint (stephenh#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
zfy0701 authored Dec 31, 2022
1 parent 0594440 commit 2539313
Show file tree
Hide file tree
Showing 37 changed files with 413 additions and 548 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/publish-sdk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ jobs:
- name: Install
run: yarn install
- name: Build
run: yarn lerna run --scope=@sentio/sdk build
run: yarn build_all
working-directory: packages/sdk
- name: Semantic Release
id: semantic
uses: cycjimmy/semantic-release-action@v3
Expand Down
12 changes: 6 additions & 6 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ write_source_files(
name = "write_gen",
files = {
"packages/protos/processor.proto": "//processor/protos:proto_file",
"packages/protos/src/gen/chainquery/protos/chainquery.ts": "//chainquery/protos:chainquery_ts_proto",
"packages/protos/src/gen/processor/protos/processor.ts": "//processor/protos:processor_ts_proto",
"packages/protos/src/gen/service/price/protos/price.ts": "//service/price/protos:protos_ts_proto",
"packages/protos/src/gen/google/protobuf/empty.ts": "//processor/protos:empty_ts_proto",
"packages/protos/src/gen/google/protobuf/struct.ts": "//processor/protos:struct_ts_proto",
"packages/protos/src/gen/google/protobuf/timestamp.ts": "//processor/protos:timestamp_ts_proto",
"packages/protos/src/chainquery/protos/chainquery.ts": "//chainquery/protos:chainquery_ts_proto",
"packages/protos/src/processor/protos/processor.ts": "//processor/protos:processor_ts_proto",
"packages/protos/src/service/price/protos/price.ts": "//service/price/protos:protos_ts_proto",
"packages/protos/src/google/protobuf/empty.ts": "//processor/protos:empty_ts_proto",
"packages/protos/src/google/protobuf/struct.ts": "//processor/protos:struct_ts_proto",
"packages/protos/src/google/protobuf/timestamp.ts": "//processor/protos:timestamp_ts_proto",

"packages/runtime/processor_full.proto": "//processor/protos:proto_full_file",
"packages/runtime/src/gen/processor/protos/processor.ts": "//processor/protos:processor_ts_proto",
Expand Down
File renamed without changes.
4 changes: 0 additions & 4 deletions packages/protos/src/builtin.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import Long from 'long'

type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined

export type DeepPartial<T> = T extends Builtin
? T
: T extends Long
? string | number | Long
: T extends Array<infer U>
? Array<DeepPartial<U>>
: T extends ReadonlyArray<infer U>
Expand Down
287 changes: 130 additions & 157 deletions packages/protos/src/chainquery/protos/chainquery.ts

Large diffs are not rendered by default.

8 changes: 0 additions & 8 deletions packages/protos/src/google/protobuf/empty.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable */
import Long from 'long'
import _m0 from 'protobufjs/minimal'

export interface Empty {}
Expand Down Expand Up @@ -47,17 +46,10 @@ type Builtin = Date | Function | Uint8Array | string | number | boolean | undefi

type DeepPartial<T> = T extends Builtin
? T
: T extends Long
? string | number | Long
: T extends Array<infer U>
? Array<DeepPartial<U>>
: T extends ReadonlyArray<infer U>
? ReadonlyArray<DeepPartial<U>>
: T extends {}
? { [K in keyof T]?: DeepPartial<T[K]> }
: Partial<T>

if (_m0.util.Long !== Long) {
_m0.util.Long = Long as any
_m0.configure()
}
8 changes: 0 additions & 8 deletions packages/protos/src/google/protobuf/struct.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable */
import Long from 'long'
import _m0 from 'protobufjs/minimal'

export enum NullValue {
Expand Down Expand Up @@ -404,8 +403,6 @@ type Builtin = Date | Function | Uint8Array | string | number | boolean | undefi

type DeepPartial<T> = T extends Builtin
? T
: T extends Long
? string | number | Long
: T extends Array<infer U>
? Array<DeepPartial<U>>
: T extends ReadonlyArray<infer U>
Expand All @@ -414,11 +411,6 @@ type DeepPartial<T> = T extends Builtin
? { [K in keyof T]?: DeepPartial<T[K]> }
: Partial<T>

if (_m0.util.Long !== Long) {
_m0.util.Long = Long as any
_m0.configure()
}

function isObject(value: any): boolean {
return typeof value === 'object' && value !== null
}
Expand Down
23 changes: 12 additions & 11 deletions packages/protos/src/google/protobuf/timestamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ import Long from 'long'
import _m0 from 'protobufjs/minimal'

export interface Timestamp {
seconds: Long
seconds: bigint
nanos: number
}

function createBaseTimestamp(): Timestamp {
return { seconds: Long.ZERO, nanos: 0 }
return { seconds: BigInt('0'), nanos: 0 }
}

export const Timestamp = {
encode(message: Timestamp, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (!message.seconds.isZero()) {
writer.uint32(8).int64(message.seconds)
if (message.seconds !== BigInt('0')) {
writer.uint32(8).int64(message.seconds.toString())
}
if (message.nanos !== 0) {
writer.uint32(16).int32(message.nanos)
Expand All @@ -30,7 +30,7 @@ export const Timestamp = {
const tag = reader.uint32()
switch (tag >>> 3) {
case 1:
message.seconds = reader.int64() as Long
message.seconds = longToBigint(reader.int64() as Long)
break
case 2:
message.nanos = reader.int32()
Expand All @@ -45,22 +45,21 @@ export const Timestamp = {

fromJSON(object: any): Timestamp {
return {
seconds: isSet(object.seconds) ? Long.fromValue(object.seconds) : Long.ZERO,
seconds: isSet(object.seconds) ? BigInt(object.seconds) : BigInt('0'),
nanos: isSet(object.nanos) ? Number(object.nanos) : 0,
}
},

toJSON(message: Timestamp): unknown {
const obj: any = {}
message.seconds !== undefined && (obj.seconds = (message.seconds || Long.ZERO).toString())
message.seconds !== undefined && (obj.seconds = message.seconds.toString())
message.nanos !== undefined && (obj.nanos = Math.round(message.nanos))
return obj
},

fromPartial(object: DeepPartial<Timestamp>): Timestamp {
const message = createBaseTimestamp()
message.seconds =
object.seconds !== undefined && object.seconds !== null ? Long.fromValue(object.seconds) : Long.ZERO
message.seconds = object.seconds ?? BigInt('0')
message.nanos = object.nanos ?? 0
return message
},
Expand All @@ -70,8 +69,6 @@ type Builtin = Date | Function | Uint8Array | string | number | boolean | undefi

type DeepPartial<T> = T extends Builtin
? T
: T extends Long
? string | number | Long
: T extends Array<infer U>
? Array<DeepPartial<U>>
: T extends ReadonlyArray<infer U>
Expand All @@ -80,6 +77,10 @@ type DeepPartial<T> = T extends Builtin
? { [K in keyof T]?: DeepPartial<T[K]> }
: Partial<T>

function longToBigint(long: Long) {
return BigInt(long.toString())
}

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

0 comments on commit 2539313

Please sign in to comment.