Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update target to ES2020 and replace Long with bigint #912

Merged
merged 1 commit into from
Oct 21, 2024
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
4 changes: 2 additions & 2 deletions packages/sdk/buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ plugins:
out: .
opt:
- target=ts
- js_import_style=module
- import_extension=none
- plugin: connect-es
out: .
opt:
- target=ts
- js_import_style=module
- import_extension=none
25 changes: 9 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,13 @@ 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);
}

// TODO(hackerwins): Remove BigInt conversion. Some of the bigint values are
// passed as string in the protobuf. We should fix this in the future.
return ChangeID.of(
pbChangeID.clientSeq,
Long.fromString(pbChangeID.lamport, true),
BigInt(pbChangeID.lamport),
toHexString(pbChangeID.actorId),
serverSeq,
BigInt(pbChangeID.serverSeq),
);
}

Expand All @@ -827,7 +823,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 +1310,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
Loading