Skip to content

Commit

Permalink
StateVectors and DocDiffs are now type annotated as bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
Waidhoferj committed Jun 3, 2022
1 parent d92a17f commit 4d13308
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions y_py.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,10 @@ class YDoc:
A subscription identifier that can be used to cancel the callback.
"""

EncodedStateVector = List[int]
EncodedDeleteSet = List[int]
EncodedStateVector = bytes
EncodedDeleteSet = bytes
YDocUpdate = bytes


class AfterTransactionEvent:
"""
Expand Down Expand Up @@ -176,10 +178,9 @@ def encode_state_vector(doc: YDoc) -> EncodedStateVector:
"""

YDocUpdate = List[int]

def encode_state_as_update(
doc: YDoc, vector: Optional[EncodedStateVector]=None
doc: YDoc, vector: Optional[Union[EncodedStateVector, List[int]]]=None
) -> YDocUpdate:
"""
Encodes all updates that have happened since a given version `vector` into a compact delta
Expand All @@ -202,7 +203,7 @@ def encode_state_as_update(
apply_update(local_doc, remote_delta)
"""

def apply_update(doc: YDoc, diff: YDocUpdate):
def apply_update(doc: YDoc, diff: Union[YDocUpdate, List[int]]):
"""
Applies delta update generated by the remote document replica to a current document. This
method assumes that a payload maintains lib0 v1 encoding format.
Expand Down Expand Up @@ -276,7 +277,7 @@ class YTransaction:
compaction and optimization of internal representation of updates, triggering events etc.
Ypy transactions are auto-committed when they are `free`d.
"""
def state_vector_v1(self) -> List[int]:
def state_vector_v1(self) -> EncodedStateVector:
"""
Encodes a state vector of a given transaction document into its binary representation using
lib0 v1 encoding. State vector is a compact representation of updates performed on a given
Expand Down Expand Up @@ -304,7 +305,7 @@ class YTransaction:
del remote_txn
"""
def diff_v1(self, vector: Optional[List[int]]=None) -> List[int]:
def diff_v1(self, vector: Optional[EncodedStateVector]=None) -> YDocUpdate:
"""
Encodes all updates that have happened since a given version `vector` into a compact delta
representation using lib0 v1 encoding. If `vector` parameter has not been provided, generated
Expand All @@ -331,7 +332,7 @@ class YTransaction:
del local_txn
del remote_txn
"""
def apply_v1(self, diff: List[int]):
def apply_v1(self, diff: YDocUpdate):
"""
Applies delta update generated by the remote document replica to a current transaction's
document. This method assumes that a payload maintains lib0 v1 encoding format.
Expand Down

0 comments on commit 4d13308

Please sign in to comment.