Skip to content

Commit

Permalink
Replace TextNodeIDWithLength to RGATreeSplitPos
Browse files Browse the repository at this point in the history
  • Loading branch information
chacha912 committed Sep 25, 2023
1 parent 9fc9ab8 commit c987984
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 354 deletions.
34 changes: 4 additions & 30 deletions src/api/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ import {
TextNode as PbTextNode,
TextNodeID as PbTextNodeID,
TextNodePos as PbTextNodePos,
TextNodeIDWithLength as PbTextNodeIDWithLength,
TimeTicket as PbTimeTicket,
TreeNode as PbTreeNode,
TreeNodes as PbTreeNodes,
Expand Down Expand Up @@ -279,19 +278,6 @@ function toTreeNodeID(treeNodeID: CRDTTreeNodeID): PbTreeNodeID {
return pbTreeNodeID;
}

/**
* `toTextNodeIDWithLength` converts the given model to Protobuf format.
*/
function toTextNodeIDWithLength(treeNodeIDWithLength: {
nodeID: RGATreeSplitNodeID;
length: number;
}): PbTextNodeIDWithLength {
const pbTextNodeIDWithLength = new PbTextNodeIDWithLength();
pbTextNodeIDWithLength.setNodeId(toTextNodeID(treeNodeIDWithLength.nodeID));
pbTextNodeIDWithLength.setLength(treeNodeIDWithLength.length);
return pbTextNodeIDWithLength;
}

/**
* `toOperation` converts the given model to Protobuf format.
*/
Expand Down Expand Up @@ -376,12 +362,12 @@ function toOperation(operation: Operation): PbOperation {
const pbDeletedIDs = [];
const deletedIDs = editReverseOperation.getDeletedIDs();
for (const deletedID of deletedIDs) {
pbDeletedIDs.push(toTextNodeIDWithLength(deletedID));
pbDeletedIDs.push(toTextNodePos(deletedID));
}
const pbInsertedIDs = [];
const insertedIDs = editReverseOperation.getInsertedIDs();
for (const insertedID of insertedIDs) {
pbInsertedIDs.push(toTextNodeIDWithLength(insertedID));
pbInsertedIDs.push(toTextNodePos(insertedID));
}
pbEditReverseOperation.setDeletedIdsList(pbDeletedIDs);
pbEditReverseOperation.setInsertedIdsList(pbInsertedIDs);
Expand Down Expand Up @@ -951,18 +937,6 @@ function fromTextNodeID(pbTextNodeID: PbTextNodeID): RGATreeSplitNodeID {
);
}

/**
* `fromTextNodeIDWithLength` converts the given Protobuf format to model format.
*/
function fromTextNodeIDWithLength(
pbTextNodeIDWithLength: PbTextNodeIDWithLength,
): { nodeID: RGATreeSplitNodeID; length: number } {
return {
nodeID: fromTextNodeID(pbTextNodeIDWithLength.getNodeId()!),
length: pbTextNodeIDWithLength.getLength(),
};
}

/**
* `fromTextNode` converts the given Protobuf format to model format.
*/
Expand Down Expand Up @@ -1158,12 +1132,12 @@ function fromOperations(pbOperations: Array<PbOperation>): Array<Operation> {
const pbDeletedIDs = pbEditReverseOperation!.getDeletedIdsList()!;
const deletedIDs = [];
for (const pbDeletedID of pbDeletedIDs) {
deletedIDs.push(fromTextNodeIDWithLength(pbDeletedID));
deletedIDs.push(fromTextNodePos(pbDeletedID));
}
const pbInsertedIDs = pbEditReverseOperation!.getInsertedIdsList()!;
const insertedIDs = [];
for (const pbInsertedID of pbInsertedIDs) {
insertedIDs.push(fromTextNodeIDWithLength(pbInsertedID));
insertedIDs.push(fromTextNodePos(pbInsertedID));
}

operation = EditReverseOperation.create({
Expand Down
9 changes: 2 additions & 7 deletions src/api/yorkie/v1/resources.proto
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ message Operation {
}
message EditReverse {
TimeTicket parent_created_at = 1;
repeated TextNodeIDWithLength deleted_ids = 2;
repeated TextNodeIDWithLength inserted_ids = 3;
repeated TextNodePos deleted_ids = 2;
repeated TextNodePos inserted_ids = 3;
map<string, TimeTicket> created_at_map_by_actor = 4;
TimeTicket executed_at = 5;
map<string, string> attributes = 6;
Expand Down Expand Up @@ -247,11 +247,6 @@ message TextNodeID {
int32 offset = 2;
}

message TextNodeIDWithLength {
TextNodeID node_id = 1;
int32 length = 2;
}

message TreeNode {
TreeNodeID id = 1;
string type = 2;
Expand Down
40 changes: 8 additions & 32 deletions src/api/yorkie/v1/resources_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -639,15 +639,15 @@ export namespace Operation {
hasParentCreatedAt(): boolean;
clearParentCreatedAt(): EditReverse;

getDeletedIdsList(): Array<TextNodeIDWithLength>;
setDeletedIdsList(value: Array<TextNodeIDWithLength>): EditReverse;
getDeletedIdsList(): Array<TextNodePos>;
setDeletedIdsList(value: Array<TextNodePos>): EditReverse;
clearDeletedIdsList(): EditReverse;
addDeletedIds(value?: TextNodeIDWithLength, index?: number): TextNodeIDWithLength;
addDeletedIds(value?: TextNodePos, index?: number): TextNodePos;

getInsertedIdsList(): Array<TextNodeIDWithLength>;
setInsertedIdsList(value: Array<TextNodeIDWithLength>): EditReverse;
getInsertedIdsList(): Array<TextNodePos>;
setInsertedIdsList(value: Array<TextNodePos>): EditReverse;
clearInsertedIdsList(): EditReverse;
addInsertedIds(value?: TextNodeIDWithLength, index?: number): TextNodeIDWithLength;
addInsertedIds(value?: TextNodePos, index?: number): TextNodePos;

getCreatedAtMapByActorMap(): jspb.Map<string, TimeTicket>;
clearCreatedAtMapByActorMap(): EditReverse;
Expand All @@ -671,8 +671,8 @@ export namespace Operation {
export namespace EditReverse {
export type AsObject = {
parentCreatedAt?: TimeTicket.AsObject,
deletedIdsList: Array<TextNodeIDWithLength.AsObject>,
insertedIdsList: Array<TextNodeIDWithLength.AsObject>,
deletedIdsList: Array<TextNodePos.AsObject>,
insertedIdsList: Array<TextNodePos.AsObject>,
createdAtMapByActorMap: Array<[string, TimeTicket.AsObject]>,
executedAt?: TimeTicket.AsObject,
attributesMap: Array<[string, string]>,
Expand Down Expand Up @@ -1180,30 +1180,6 @@ export namespace TextNodeID {
}
}

export class TextNodeIDWithLength extends jspb.Message {
getNodeId(): TextNodeID | undefined;
setNodeId(value?: TextNodeID): TextNodeIDWithLength;
hasNodeId(): boolean;
clearNodeId(): TextNodeIDWithLength;

getLength(): number;
setLength(value: number): TextNodeIDWithLength;

serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): TextNodeIDWithLength.AsObject;
static toObject(includeInstance: boolean, msg: TextNodeIDWithLength): TextNodeIDWithLength.AsObject;
static serializeBinaryToWriter(message: TextNodeIDWithLength, writer: jspb.BinaryWriter): void;
static deserializeBinary(bytes: Uint8Array): TextNodeIDWithLength;
static deserializeBinaryFromReader(message: TextNodeIDWithLength, reader: jspb.BinaryReader): TextNodeIDWithLength;
}

export namespace TextNodeIDWithLength {
export type AsObject = {
nodeId?: TextNodeID.AsObject,
length: number,
}
}

export class TreeNode extends jspb.Message {
getId(): TreeNodeID | undefined;
setId(value?: TreeNodeID): TreeNode;
Expand Down
Loading

0 comments on commit c987984

Please sign in to comment.