@@ -6,29 +6,41 @@ class Doc:
6
6
def __init__ (self , client_id : int | None ) -> None :
7
7
"""Create a new document with an optional global client ID.
8
8
If no client ID is passed, a random one will be generated."""
9
+
9
10
def client_id (self ) -> int :
10
11
"""Returns the document unique client identifier."""
12
+
11
13
def guid (self ) -> int :
12
14
"""Returns the document globally unique identifier."""
15
+
13
16
def create_transaction (self ) -> Transaction :
14
17
"""Create a document transaction."""
18
+
15
19
def get_or_insert_text (self , name : str ) -> Text :
16
20
"""Create a text root type on this document, or get an existing one."""
21
+
17
22
def get_or_insert_array (self , name : str ) -> Array :
18
23
"""Create an array root type on this document, or get an existing one."""
24
+
19
25
def get_or_insert_map (self , name : str ) -> Map :
20
26
"""Create a map root type on this document, or get an existing one."""
27
+
21
28
def get_state (self ) -> bytes :
22
29
"""Get the current document state."""
30
+
23
31
def get_update (self , state : bytes ) -> bytes :
24
32
"""Get the update from the given state to the current state."""
33
+
25
34
def apply_update (self , update : bytes ) -> None :
26
35
"""Apply the update to the document."""
36
+
27
37
def roots (self , txn : Transaction ) -> dict [str , Text | Array | Map ]:
28
38
"""Get top-level (root) shared types available in current document."""
39
+
29
40
def observe (self , callback : Callable [[TransactionEvent ], None ]) -> int :
30
41
"""Subscribes a callback to be called with the shared document change event.
31
42
Returns a subscription ID that can be used to unsubscribe."""
43
+
32
44
def observe_subdocs (self , callback : Callable [[SubdocsEvent ], None ]) -> int :
33
45
"""Subscribes a callback to be called with the shared document subdoc change event.
34
46
Returns a subscription ID that can be used to unsubscribe."""
@@ -38,6 +50,7 @@ class Transaction:
38
50
39
51
def drop (self ) -> None :
40
52
"""Drop the transaction, effectively committing document changes."""
53
+
41
54
def commit (self ) -> None :
42
55
"""Commit the document changes."""
43
56
@@ -66,16 +79,21 @@ class Text:
66
79
67
80
def len (self , txn : Transaction ) -> int :
68
81
"""Returns the number of characters visible in the current shared text."""
82
+
69
83
def insert (self , txn : Transaction , index : int , chunk : str ) -> None :
70
84
"""Inserts a `chunk` of text at a given `index`."""
85
+
71
86
def remove_range (self , txn : Transaction , index : int , len : int ) -> None :
72
87
"""Removes up to `len` characters from th current shared text, starting at
73
88
given`index`."""
89
+
74
90
def get_string (self , txn : Transaction ) -> str :
75
91
"""Returns a text representation of the current shared text."""
92
+
76
93
def observe (self , callback : Callable [[TextEvent ], None ]) -> int :
77
94
"""Subscribes a callback to be called with the shared text change event.
78
95
Returns a subscription ID that can be used to unsubscribe."""
96
+
79
97
def unobserve (self , subscription_id : int ) -> None :
80
98
"""Unsubscribes previously subscribed event callback identified by given
81
99
`subscription_id`."""
@@ -85,23 +103,31 @@ class Array:
85
103
86
104
def len (self , txn : Transaction ) -> int :
87
105
"""Returns the number of elements in the current array."""
106
+
88
107
def insert (self , txn : Transaction , index : int , value : Any ) -> None :
89
108
"""Inserts `value` at the given `index`."""
109
+
90
110
def move_to (self , txn : Transaction , source : int , target : int ) -> None :
91
111
"""Moves element found at `source` index into `target` index position.."""
112
+
92
113
def remove_range (self , txn : Transaction , index : int , len : int ) -> None :
93
114
"""Removes 'len' elements starting at provided `index`."""
115
+
94
116
def get (self , txn : Transaction , index : int ) -> Any :
95
117
"""Retrieves a value stored at a given `index`."""
118
+
96
119
def to_json (self , txn : Transaction ) -> str :
97
120
"""Returns a JSON representation of the current array."""
121
+
98
122
def observe (self , callback : Callable [[TextEvent ], None ]) -> int :
99
123
"""Subscribes a callback to be called with the array change event.
100
124
Returns a subscription ID that can be used to unsubscribe."""
125
+
101
126
def observe_deep (self , callback : Callable [[TextEvent ], None ]) -> int :
102
127
"""Subscribes a callback to be called with the array change event
103
128
and its nested elements.
104
129
Returns a subscription ID that can be used to unsubscribe."""
130
+
105
131
def unobserve (self , subscription_id : int ) -> None :
106
132
"""Unsubscribes previously subscribed event callback identified by given
107
133
`subscription_id`."""
@@ -111,21 +137,28 @@ class Map:
111
137
112
138
def len (self , txn : Transaction ) -> int :
113
139
"""Returns a number of characters visible in a current text data structure."""
140
+
114
141
def insert (self , txn : Transaction , key : str , value : Any ) -> None :
115
142
"""Inserts `value` at the given `key`."""
143
+
116
144
def remove (self , txn : Transaction , key : str ) -> None :
117
145
"""Removes the `key` entry."""
146
+
118
147
def get (self , txn : Transaction , key : str ) -> Any :
119
148
"""Retrieves a value stored under a given `key`."""
149
+
120
150
def to_json (self , txn : Transaction ) -> str :
121
151
"""Returns a JSON representation of the current map."""
152
+
122
153
def observe (self , callback : Callable [[TextEvent ], None ]) -> int :
123
154
"""Subscribes a callback to be called with the map change event.
124
155
Returns a subscription ID that can be used to unsubscribe."""
156
+
125
157
def observe_deep (self , callback : Callable [[TextEvent ], None ]) -> int :
126
158
"""Subscribes a callback to be called with the map change event
127
159
and its nested elements.
128
160
Returns a subscription ID that can be used to unsubscribe."""
161
+
129
162
def unobserve (self , subscription_id : int ) -> None :
130
163
"""Unsubscribes previously subscribed event callback identified by given
131
164
`subscription_id`."""
0 commit comments