Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/yorkie-team/yorkie-js-sdk i…
Browse files Browse the repository at this point in the history
…nto refresh-auth-token
  • Loading branch information
chacha912 committed Oct 23, 2024
2 parents 0b3d3a9 + 1d8adb3 commit 840cf00
Show file tree
Hide file tree
Showing 38 changed files with 5,354 additions and 3,632 deletions.
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,33 @@ and Yorkie JS SDK adheres to [Semantic Versioning](https://semver.org/spec/v2.0.

## [Unreleased]

## [0.5.3] - 2024-10-23

### Changed

- Introducing version vector to solve GC problem by @JOOHOJANG in https://github.com/yorkie-team/yorkie-js-sdk/pull/899

## [0.5.2] - 2024-10-22

### Changed

- Update target to ES2020 and replace Long with bigint by @hackerwins in https://github.com/yorkie-team/yorkie-js-sdk/pull/912

## [0.5.1] - 2024-10-15

### Added

- Add configurable retry mechanism to broadcast interface by @gwbaik9717 in https://github.com/yorkie-team/yorkie-js-sdk/pull/901

### Changed

- Ensure `find` and `indexOf` perform splay by @m4ushold in https://github.com/yorkie-team/yorkie-js-sdk/pull/904
- Restrict presence object type to JSON serializable values by @gwbaik9717 in https://github.com/yorkie-team/yorkie-js-sdk/pull/898

### Fixed

- Automate Linting with Husky and lint-staged to Prevent CI Failures by @gwbaik9717 in https://github.com/yorkie-team/yorkie-js-sdk/pull/896

## [0.5.0] - 2024-09-05

### Added
Expand Down
2 changes: 1 addition & 1 deletion MAINTAINING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

### 1. Update the version number.

- Update `version` in [package.json](https://github.com/yorkie-team/yorkie-js-sdk/blob/main/package.json#L3).
- Update `version` in [package.json](https://github.com/yorkie-team/yorkie-js-sdk/blob/main/packages/sdk/package.json#L3).

### 2. Write changelog of this version in [CHANGELOG.md](https://github.com/yorkie-team/yorkie-js-sdk/blob/main/CHANGELOG.md).

Expand Down
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
4 changes: 2 additions & 2 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yorkie-js-sdk",
"version": "0.5.0",
"version": "0.5.3",
"description": "Yorkie JS SDK",
"main": "./src/yorkie.ts",
"publishConfig": {
Expand Down Expand Up @@ -64,7 +64,7 @@
"vite": "^5.0.12",
"vite-plugin-commonjs": "^0.10.1",
"vite-plugin-dts": "^3.9.1",
"vite-tsconfig-paths": "^4.2.1",
"vite-tsconfig-paths": "^4.3.1",
"vitest": "^0.34.5"
},
"dependencies": {
Expand Down
84 changes: 68 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 @@ -45,6 +44,7 @@ import { RGATreeList } from '@yorkie-js-sdk/src/document/crdt/rga_tree_list';
import { CRDTElement } from '@yorkie-js-sdk/src/document/crdt/element';
import { CRDTObject } from '@yorkie-js-sdk/src/document/crdt/object';
import { CRDTArray } from '@yorkie-js-sdk/src/document/crdt/array';
import { VersionVector } from '@yorkie-js-sdk/src/document/time/version_vector';
import { CRDTTreePos } from './../document/crdt/tree';
import {
RGATreeSplit,
Expand Down Expand Up @@ -79,6 +79,7 @@ import {
TreeNodes as PbTreeNodes,
TreePos as PbTreePos,
TreeNodeID as PbTreeNodeID,
VersionVector as PbVersionVector,
ValueType as PbValueType,
JSONElement_Tree as PbJSONElement_Tree,
JSONElement_Text as PbJSONElement_Text,
Expand Down Expand Up @@ -149,7 +150,7 @@ function toPresenceChange(
*/
function toCheckpoint(checkpoint: Checkpoint): PbCheckpoint {
return new PbCheckpoint({
serverSeq: checkpoint.getServerSeqAsString(),
serverSeq: checkpoint.getServerSeq(),
clientSeq: checkpoint.getClientSeq(),
});
}
Expand All @@ -160,8 +161,9 @@ 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()),
versionVector: toVersionVector(changeID.getVersionVector()),
});
}

Expand All @@ -174,12 +176,27 @@ function toTimeTicket(ticket?: TimeTicket): PbTimeTicket | undefined {
}

return new PbTimeTicket({
lamport: ticket.getLamportAsString(),
lamport: ticket.getLamport(),
delimiter: ticket.getDelimiter(),
actorId: toUint8Array(ticket.getActorID()),
});
}

/**
* `toVersionVector` converts the given model to Protobuf format.
*/
function toVersionVector(vector?: VersionVector): PbVersionVector | undefined {
if (!vector) {
return;
}

const pbVector = new PbVersionVector();
for (const [actorID, lamport] of vector) {
pbVector.vector[actorID] = BigInt(lamport.toString());
}
return pbVector;
}

/**
* `toValueType` converts the given model to Protobuf format.
*/
Expand Down Expand Up @@ -781,6 +798,7 @@ function toChangePack(pack: ChangePack<Indexable>): PbChangePack {
isRemoved: pack.getIsRemoved(),
changes: toChanges(pack.getChanges()),
snapshot: pack.getSnapshot(),
versionVector: toVersionVector(pack.getVersionVector()),
minSyncedTicket: toTimeTicket(pack.getMinSyncedTicket()),
});
}
Expand Down Expand Up @@ -817,19 +835,34 @@ export function errorMetadataOf(error: ConnectError): Record<string, 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,
fromVersionVector(pbChangeID.versionVector)!,
BigInt(pbChangeID.serverSeq),
);
}

/**
* `fromVersionVector` converts the given Protobuf format to model format.
*/
function fromVersionVector(
pbVersionVector?: PbVersionVector,
): VersionVector | undefined {
if (!pbVersionVector) {
return;
}

const vector = new VersionVector();
Object.entries(pbVersionVector.vector).forEach(([key, value]) => {
vector.set(key, BigInt(value.toString()));
});
return vector;
}

/**
* `fromTimeTicket` converts the given Protobuf format to model format.
*/
Expand All @@ -839,7 +872,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 @@ -1326,10 +1359,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 All @@ -1343,6 +1373,7 @@ function fromChangePack<P extends Indexable>(
fromCheckpoint(pbPack.checkpoint!),
pbPack.isRemoved,
fromChanges(pbPack.changes),
fromVersionVector(pbPack.versionVector),
pbPack.snapshot,
fromTimeTicket(pbPack.minSyncedTicket),
);
Expand Down Expand Up @@ -1489,6 +1520,25 @@ function bytesToSnapshot<P extends Indexable>(
};
}

/**
* `versionVectorToHex` converts the given VersionVector to bytes.
*/
function versionVectorToHex(vector: VersionVector): string {
const pbVersionVector = toVersionVector(vector)!;

return bytesToHex(pbVersionVector.toBinary());
}

/**
* `hexToVersionVector` creates a VersionVector from the given bytes.
*/
function hexToVersionVector(hex: string): VersionVector {
const bytes = hexToBytes(hex);
const pbVersionVector = PbVersionVector.fromBinary(bytes);

return fromVersionVector(pbVersionVector)!;
}

/**
* `bytesToObject` creates an JSONObject from the given byte array.
*/
Expand Down Expand Up @@ -1621,4 +1671,6 @@ export const converter = {
PbChangeID,
bytesToChangeID,
bytesToOperation,
versionVectorToHex,
hexToVersionVector,
};
21 changes: 17 additions & 4 deletions packages/sdk/src/api/yorkie/v1/resources.proto
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ message ChangePack {
repeated Change changes = 4;
TimeTicket min_synced_ticket = 5;
bool is_removed = 6;
VersionVector version_vector = 7;
}

message Change {
Expand All @@ -57,9 +58,14 @@ 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;
VersionVector version_vector = 5;
}

message VersionVector {
map<string, int64> vector = 1;
}

message Operation {
Expand Down Expand Up @@ -136,6 +142,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 +160,7 @@ message Operation {
Increase increase = 8;
TreeEdit tree_edit = 9;
TreeStyle tree_style = 10;
ArraySet array_set = 11;
}
}

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

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

Expand All @@ -336,7 +349,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 840cf00

Please sign in to comment.