@@ -160,8 +160,8 @@ export class PatchBuilder {
160160 * @returns ID of the new operation.
161161 */
162162 public insObj ( obj : ITimestampStruct , data : [ key : string , value : ITimestampStruct ] [ ] ) : ITimestampStruct {
163- this . pad ( ) ;
164163 if ( ! data . length ) throw new Error ( 'EMPTY_TUPLES' ) ;
164+ this . pad ( ) ;
165165 const id = this . clock . tick ( 1 ) ;
166166 const op = new operations . InsObjOp ( id , obj , data ) ;
167167 const span = op . span ( ) ;
@@ -176,8 +176,8 @@ export class PatchBuilder {
176176 * @returns ID of the new operation.
177177 */
178178 public insVec ( obj : ITimestampStruct , data : [ index : number , value : ITimestampStruct ] [ ] ) : ITimestampStruct {
179- this . pad ( ) ;
180179 if ( ! data . length ) throw new Error ( 'EMPTY_TUPLES' ) ;
180+ this . pad ( ) ;
181181 const id = this . clock . tick ( 1 ) ;
182182 const op = new operations . InsVecOp ( id , obj , data ) ;
183183 const span = op . span ( ) ;
@@ -206,8 +206,8 @@ export class PatchBuilder {
206206 * @returns ID of the new operation.
207207 */
208208 public insStr ( obj : ITimestampStruct , ref : ITimestampStruct , data : string ) : ITimestampStruct {
209- this . pad ( ) ;
210209 if ( ! data . length ) throw new Error ( 'EMPTY_STRING' ) ;
210+ this . pad ( ) ;
211211 const id = this . clock . tick ( 1 ) ;
212212 const op = new operations . InsStrOp ( id , obj , ref , data ) ;
213213 const span = op . span ( ) ;
@@ -222,8 +222,8 @@ export class PatchBuilder {
222222 * @returns ID of the new operation.
223223 */
224224 public insBin ( obj : ITimestampStruct , ref : ITimestampStruct , data : Uint8Array ) : ITimestampStruct {
225- this . pad ( ) ;
226225 if ( ! data . length ) throw new Error ( 'EMPTY_BINARY' ) ;
226+ this . pad ( ) ;
227227 const id = this . clock . tick ( 1 ) ;
228228 const op = new operations . InsBinOp ( id , obj , ref , data ) ;
229229 const span = op . span ( ) ;
@@ -247,6 +247,19 @@ export class PatchBuilder {
247247 return id ;
248248 }
249249
250+ /**
251+ * Update an element in an "arr" object.
252+ *
253+ * @returns ID of the new operation.
254+ */
255+ public updArr ( arr : ITimestampStruct , ref : ITimestampStruct , val : ITimestampStruct ) : ITimestampStruct {
256+ this . pad ( ) ;
257+ const id = this . clock . tick ( 1 ) ;
258+ const op = new operations . UpdArrOp ( id , arr , ref , val ) ;
259+ this . patch . ops . push ( op ) ;
260+ return id ;
261+ }
262+
250263 /**
251264 * Delete a span of operations.
252265 *
0 commit comments