Skip to content

Commit

Permalink
Update target to ES2020 and replace Long with bigint
Browse files Browse the repository at this point in the history
  • Loading branch information
hackerwins committed Oct 21, 2024
1 parent b7c769c commit e238015
Show file tree
Hide file tree
Showing 13 changed files with 3,621 additions and 88 deletions.
23 changes: 7 additions & 16 deletions packages/sdk/src/api/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* limitations under the License.
*/

import Long from 'long';
import { ConnectError } from '@connectrpc/connect';
import { ErrorInfo } from '@buf/googleapis_googleapis.bufbuild_es/google/rpc/error_details_pb';
import { Code, YorkieError } from '@yorkie-js-sdk/src/util/error';
Expand Down Expand Up @@ -149,7 +148,7 @@ function toPresenceChange(
*/
function toCheckpoint(checkpoint: Checkpoint): PbCheckpoint {
return new PbCheckpoint({
serverSeq: checkpoint.getServerSeqAsString(),
serverSeq: checkpoint.getServerSeq(),
clientSeq: checkpoint.getClientSeq(),
});
}
Expand All @@ -160,7 +159,7 @@ function toCheckpoint(checkpoint: Checkpoint): PbCheckpoint {
function toChangeID(changeID: ChangeID): PbChangeID {
return new PbChangeID({
clientSeq: changeID.getClientSeq(),
lamport: changeID.getLamportAsString(),
lamport: changeID.getLamport(),
actorId: toUint8Array(changeID.getActorID()),
});
}
Expand All @@ -174,7 +173,7 @@ function toTimeTicket(ticket?: TimeTicket): PbTimeTicket | undefined {
}

return new PbTimeTicket({
lamport: ticket.getLamportAsString(),
lamport: ticket.getLamport(),
delimiter: ticket.getDelimiter(),
actorId: toUint8Array(ticket.getActorID()),
});
Expand Down Expand Up @@ -805,16 +804,11 @@ export function errorCodeOf(error: ConnectError): string {
* `fromChangeID` converts the given Protobuf format to model format.
*/
function fromChangeID(pbChangeID: PbChangeID): ChangeID {
let serverSeq: Long | undefined;
if (pbChangeID.serverSeq) {
serverSeq = Long.fromString(pbChangeID.serverSeq, true);
}

return ChangeID.of(
pbChangeID.clientSeq,
Long.fromString(pbChangeID.lamport, true),
BigInt(pbChangeID.lamport),
toHexString(pbChangeID.actorId),
serverSeq,
BigInt(pbChangeID.serverSeq),
);
}

Expand All @@ -827,7 +821,7 @@ function fromTimeTicket(pbTimeTicket?: PbTimeTicket): TimeTicket | undefined {
}

return TimeTicket.of(
Long.fromString(pbTimeTicket.lamport, true),
BigInt(pbTimeTicket.lamport),
pbTimeTicket.delimiter,
toHexString(pbTimeTicket.actorId),
);
Expand Down Expand Up @@ -1314,10 +1308,7 @@ function fromChanges<P extends Indexable>(
* `fromCheckpoint` converts the given Protobuf format to model format.
*/
function fromCheckpoint(pbCheckpoint: PbCheckpoint): Checkpoint {
return Checkpoint.of(
Long.fromString(pbCheckpoint.serverSeq, true),
pbCheckpoint.clientSeq,
);
return Checkpoint.of(BigInt(pbCheckpoint.serverSeq), pbCheckpoint.clientSeq);
}

/**
Expand Down
15 changes: 11 additions & 4 deletions packages/sdk/src/api/yorkie/v1/resources.proto
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ message Change {

message ChangeID {
uint32 client_seq = 1;
int64 server_seq = 2 [jstype = JS_STRING];
int64 lamport = 3 [jstype = JS_STRING];
int64 server_seq = 2;
int64 lamport = 3;
bytes actor_id = 4;
}

Expand Down Expand Up @@ -136,6 +136,12 @@ message Operation {
repeated string attributes_to_remove = 6;
map<string, TimeTicket> created_at_map_by_actor = 7;
}
message ArraySet {
TimeTicket parent_created_at = 1;
TimeTicket created_at = 2;
JSONElementSimple value = 3;
TimeTicket executed_at = 4;
}

oneof body {
Set set = 1;
Expand All @@ -148,6 +154,7 @@ message Operation {
Increase increase = 8;
TreeEdit tree_edit = 9;
TreeStyle tree_style = 10;
ArraySet array_set = 11;
}
}

Expand Down Expand Up @@ -325,7 +332,7 @@ message Presence {
}

message Checkpoint {
int64 server_seq = 1 [jstype = JS_STRING];
int64 server_seq = 1;
uint32 client_seq = 2;
}

Expand All @@ -336,7 +343,7 @@ message TextNodePos {
}

message TimeTicket {
int64 lamport = 1 [jstype = JS_STRING];
int64 lamport = 1;
uint32 delimiter = 2;
bytes actor_id = 3;
}
Expand Down
Loading

0 comments on commit e238015

Please sign in to comment.