@yorkie-js/sdk 0.7.2 → 0.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/yorkie-js-sdk.d.ts +49 -4
- package/dist/yorkie-js-sdk.es.js +117 -9
- package/dist/yorkie-js-sdk.es.js.map +1 -1
- package/dist/yorkie-js-sdk.js +117 -9
- package/dist/yorkie-js-sdk.js.map +1 -1
- package/package.json +2 -2
package/dist/yorkie-js-sdk.d.ts
CHANGED
|
@@ -2398,7 +2398,7 @@ export { Devtools }
|
|
|
2398
2398
|
* `DocEvent` is an event that occurs in `Document`. It can be delivered
|
|
2399
2399
|
* using `Document.subscribe()`.
|
|
2400
2400
|
*/
|
|
2401
|
-
export declare type DocEvent<P extends Indexable = Indexable, T = OpInfo> = StatusChangedEvent_2 | ConnectionChangedEvent | SyncStatusChangedEvent | SnapshotEvent | LocalChangeEvent<T, P> | RemoteChangeEvent<T, P> | PresenceEvent_2<P> | AuthErrorEvent_2;
|
|
2401
|
+
export declare type DocEvent<P extends Indexable = Indexable, T = OpInfo> = StatusChangedEvent_2 | ConnectionChangedEvent | SyncStatusChangedEvent | SnapshotEvent | LocalChangeEvent<T, P> | RemoteChangeEvent<T, P> | PresenceEvent_2<P> | AuthErrorEvent_2 | EpochMismatchEvent;
|
|
2402
2402
|
|
|
2403
2403
|
/**
|
|
2404
2404
|
* `DocEvent` is an event that occurs in `Document`. It can be delivered
|
|
@@ -2412,7 +2412,8 @@ declare type DocEvent_2<P extends Indexable_2 = Indexable_2, T = OpInfo_2> =
|
|
|
2412
2412
|
| LocalChangeEvent_2<T, P>
|
|
2413
2413
|
| RemoteChangeEvent_2<T, P>
|
|
2414
2414
|
| PresenceEvent<P>
|
|
2415
|
-
| AuthErrorEvent
|
|
2415
|
+
| AuthErrorEvent
|
|
2416
|
+
| EpochMismatchEvent_2;
|
|
2416
2417
|
|
|
2417
2418
|
declare type DocEventCallbackMap<P extends Indexable> = {
|
|
2418
2419
|
default: NextFn<LocalChangeEvent<OpInfo, P> | RemoteChangeEvent<OpInfo, P> | SnapshotEvent>;
|
|
@@ -2423,6 +2424,7 @@ declare type DocEventCallbackMap<P extends Indexable> = {
|
|
|
2423
2424
|
status: NextFn<StatusChangedEvent_2>;
|
|
2424
2425
|
sync: NextFn<SyncStatusChangedEvent>;
|
|
2425
2426
|
'auth-error': NextFn<AuthErrorEvent_2>;
|
|
2427
|
+
'epoch-mismatch': NextFn<EpochMismatchEvent>;
|
|
2426
2428
|
all: NextFn<DocEvents<P>>;
|
|
2427
2429
|
};
|
|
2428
2430
|
|
|
@@ -2508,7 +2510,12 @@ export declare enum DocEventType {
|
|
|
2508
2510
|
/**
|
|
2509
2511
|
* `AuthError` indicates an authorization failure in syncLoop or watchLoop.
|
|
2510
2512
|
*/
|
|
2511
|
-
AuthError = "auth-error"
|
|
2513
|
+
AuthError = "auth-error",
|
|
2514
|
+
/**
|
|
2515
|
+
* `EpochMismatch` indicates the document was compacted on the server
|
|
2516
|
+
* and this client must detach and reattach to recover.
|
|
2517
|
+
*/
|
|
2518
|
+
EpochMismatch = "epoch-mismatch"
|
|
2512
2519
|
}
|
|
2513
2520
|
|
|
2514
2521
|
/**
|
|
@@ -2570,6 +2577,12 @@ declare enum DocEventType_2 {
|
|
|
2570
2577
|
* `AuthError` indicates an authorization failure in syncLoop or watchLoop.
|
|
2571
2578
|
*/
|
|
2572
2579
|
AuthError = 'auth-error',
|
|
2580
|
+
|
|
2581
|
+
/**
|
|
2582
|
+
* `EpochMismatch` indicates the document was compacted on the server
|
|
2583
|
+
* and this client must detach and reattach to recover.
|
|
2584
|
+
*/
|
|
2585
|
+
EpochMismatch = 'epoch-mismatch',
|
|
2573
2586
|
}
|
|
2574
2587
|
|
|
2575
2588
|
/**
|
|
@@ -2762,6 +2775,11 @@ declare class Document_2<R, P extends Indexable = Indexable> implements Attachab
|
|
|
2762
2775
|
* The callback will be called when the authentification error occurs.
|
|
2763
2776
|
*/
|
|
2764
2777
|
subscribe(type: 'auth-error', next: DocEventCallbackMap<P>['auth-error'], error?: ErrorFn): Unsubscribe;
|
|
2778
|
+
/**
|
|
2779
|
+
* `subscribe` registers a callback to subscribe to events on the document.
|
|
2780
|
+
* The callback will be called when an epoch mismatch error occurs.
|
|
2781
|
+
*/
|
|
2782
|
+
subscribe(type: 'epoch-mismatch', next: DocEventCallbackMap<P>['epoch-mismatch'], error?: ErrorFn): Unsubscribe;
|
|
2765
2783
|
/**
|
|
2766
2784
|
* `subscribe` registers a callback to subscribe to events on the document.
|
|
2767
2785
|
*/
|
|
@@ -3154,6 +3172,20 @@ declare interface Entry<K, V> {
|
|
|
3154
3172
|
value: V;
|
|
3155
3173
|
}
|
|
3156
3174
|
|
|
3175
|
+
export declare interface EpochMismatchEvent extends BaseDocEvent_2 {
|
|
3176
|
+
type: DocEventType.EpochMismatch;
|
|
3177
|
+
value: {
|
|
3178
|
+
method: 'PushPull';
|
|
3179
|
+
};
|
|
3180
|
+
}
|
|
3181
|
+
|
|
3182
|
+
declare interface EpochMismatchEvent_2 extends BaseDocEvent {
|
|
3183
|
+
type: DocEventType_2.EpochMismatch;
|
|
3184
|
+
value: {
|
|
3185
|
+
method: 'PushPull';
|
|
3186
|
+
};
|
|
3187
|
+
}
|
|
3188
|
+
|
|
3157
3189
|
export declare type ErrorFn = (error: Error) => void;
|
|
3158
3190
|
|
|
3159
3191
|
/**
|
|
@@ -6231,11 +6263,19 @@ export declare class Tree {
|
|
|
6231
6263
|
*/
|
|
6232
6264
|
mergeByPath(path: Array<number>): void;
|
|
6233
6265
|
/**
|
|
6234
|
-
* `styleByPath` sets the attributes to the
|
|
6266
|
+
* `styleByPath` sets the attributes to the element at the given
|
|
6267
|
+
* path.
|
|
6235
6268
|
*/
|
|
6236
6269
|
styleByPath(path: Array<number>, attributes: {
|
|
6237
6270
|
[key: string]: any;
|
|
6238
6271
|
}): void;
|
|
6272
|
+
/**
|
|
6273
|
+
* `styleByPath` sets the attributes to the elements in the given
|
|
6274
|
+
* path range.
|
|
6275
|
+
*/
|
|
6276
|
+
styleByPath(fromPath: Array<number>, toPath: Array<number>, attributes: {
|
|
6277
|
+
[key: string]: any;
|
|
6278
|
+
}): void;
|
|
6239
6279
|
/**
|
|
6240
6280
|
* `style` sets the attributes to the elements of the given range.
|
|
6241
6281
|
*/
|
|
@@ -6246,6 +6286,11 @@ export declare class Tree {
|
|
|
6246
6286
|
* `removeStyle` removes the attributes to the elements of the given range.
|
|
6247
6287
|
*/
|
|
6248
6288
|
removeStyle(fromIdx: number, toIdx: number, attributesToRemove: Array<string>): void;
|
|
6289
|
+
/**
|
|
6290
|
+
* `removeStyleByPath` removes the attributes of the elements in
|
|
6291
|
+
* the given path range.
|
|
6292
|
+
*/
|
|
6293
|
+
removeStyleByPath(fromPath: Array<number>, toPath: Array<number>, attributesToRemove: Array<string>): void;
|
|
6249
6294
|
private editInternal;
|
|
6250
6295
|
/**
|
|
6251
6296
|
* `editByPath` edits this tree with the given node and path.
|
package/dist/yorkie-js-sdk.es.js
CHANGED
|
@@ -5495,6 +5495,7 @@ var Code = /* @__PURE__ */ ((Code2) => {
|
|
|
5495
5495
|
Code2["ErrUnauthenticated"] = "ErrUnauthenticated";
|
|
5496
5496
|
Code2["ErrTooManySubscribers"] = "ErrTooManySubscribers";
|
|
5497
5497
|
Code2["ErrTooManyAttachments"] = "ErrTooManyAttachments";
|
|
5498
|
+
Code2["ErrEpochMismatch"] = "ErrEpochMismatch";
|
|
5498
5499
|
return Code2;
|
|
5499
5500
|
})(Code || {});
|
|
5500
5501
|
class YorkieError extends Error {
|
|
@@ -17217,22 +17218,49 @@ class Tree {
|
|
|
17217
17218
|
}
|
|
17218
17219
|
}
|
|
17219
17220
|
/**
|
|
17220
|
-
* `styleByPath` sets the attributes to the elements of the given
|
|
17221
|
+
* `styleByPath` sets the attributes to the elements of the given
|
|
17222
|
+
* path. When called with two paths, it styles the range between
|
|
17223
|
+
* them.
|
|
17221
17224
|
*/
|
|
17222
|
-
styleByPath(
|
|
17225
|
+
styleByPath(fromPathOrPath, toPathOrAttrs, maybeAttrs) {
|
|
17223
17226
|
if (!this.context || !this.tree) {
|
|
17224
17227
|
throw new YorkieError(
|
|
17225
17228
|
Code.ErrNotInitialized,
|
|
17226
17229
|
"Tree is not initialized yet"
|
|
17227
17230
|
);
|
|
17228
17231
|
}
|
|
17229
|
-
|
|
17230
|
-
|
|
17231
|
-
|
|
17232
|
-
|
|
17233
|
-
|
|
17232
|
+
let fromPos;
|
|
17233
|
+
let toPos;
|
|
17234
|
+
let attributes;
|
|
17235
|
+
if (Array.isArray(toPathOrAttrs)) {
|
|
17236
|
+
const fromPath = fromPathOrPath;
|
|
17237
|
+
const toPath = toPathOrAttrs;
|
|
17238
|
+
attributes = maybeAttrs;
|
|
17239
|
+
if (fromPath.length !== toPath.length) {
|
|
17240
|
+
throw new YorkieError(
|
|
17241
|
+
Code.ErrInvalidArgument,
|
|
17242
|
+
"path length should be equal"
|
|
17243
|
+
);
|
|
17244
|
+
}
|
|
17245
|
+
if (!fromPath.length || !toPath.length) {
|
|
17246
|
+
throw new YorkieError(
|
|
17247
|
+
Code.ErrInvalidArgument,
|
|
17248
|
+
"path should not be empty"
|
|
17249
|
+
);
|
|
17250
|
+
}
|
|
17251
|
+
fromPos = this.tree.pathToPos(fromPath);
|
|
17252
|
+
toPos = this.tree.pathToPos(toPath);
|
|
17253
|
+
} else {
|
|
17254
|
+
const path = fromPathOrPath;
|
|
17255
|
+
attributes = toPathOrAttrs;
|
|
17256
|
+
if (!path.length) {
|
|
17257
|
+
throw new YorkieError(
|
|
17258
|
+
Code.ErrInvalidArgument,
|
|
17259
|
+
"path should not be empty"
|
|
17260
|
+
);
|
|
17261
|
+
}
|
|
17262
|
+
[fromPos, toPos] = this.tree.pathToPosRange(path);
|
|
17234
17263
|
}
|
|
17235
|
-
const [fromPos, toPos] = this.tree.pathToPosRange(path);
|
|
17236
17264
|
const ticket = this.context.issueTimeTicket();
|
|
17237
17265
|
const attrs = attributes ? stringifyObjectValues(attributes) : void 0;
|
|
17238
17266
|
const [pairs, , diff] = this.tree.style([fromPos, toPos], attrs, ticket);
|
|
@@ -17323,6 +17351,51 @@ class Tree {
|
|
|
17323
17351
|
)
|
|
17324
17352
|
);
|
|
17325
17353
|
}
|
|
17354
|
+
/**
|
|
17355
|
+
* `removeStyleByPath` removes the attributes of the elements in
|
|
17356
|
+
* the given path range.
|
|
17357
|
+
*/
|
|
17358
|
+
removeStyleByPath(fromPath, toPath, attributesToRemove) {
|
|
17359
|
+
if (!this.context || !this.tree) {
|
|
17360
|
+
throw new YorkieError(
|
|
17361
|
+
Code.ErrNotInitialized,
|
|
17362
|
+
"Tree is not initialized yet"
|
|
17363
|
+
);
|
|
17364
|
+
}
|
|
17365
|
+
if (fromPath.length !== toPath.length) {
|
|
17366
|
+
throw new YorkieError(
|
|
17367
|
+
Code.ErrInvalidArgument,
|
|
17368
|
+
"path length should be equal"
|
|
17369
|
+
);
|
|
17370
|
+
}
|
|
17371
|
+
if (!fromPath.length || !toPath.length) {
|
|
17372
|
+
throw new YorkieError(
|
|
17373
|
+
Code.ErrInvalidArgument,
|
|
17374
|
+
"path should not be empty"
|
|
17375
|
+
);
|
|
17376
|
+
}
|
|
17377
|
+
const fromPos = this.tree.pathToPos(fromPath);
|
|
17378
|
+
const toPos = this.tree.pathToPos(toPath);
|
|
17379
|
+
const ticket = this.context.issueTimeTicket();
|
|
17380
|
+
const [pairs, , diff] = this.tree.removeStyle(
|
|
17381
|
+
[fromPos, toPos],
|
|
17382
|
+
attributesToRemove,
|
|
17383
|
+
ticket
|
|
17384
|
+
);
|
|
17385
|
+
this.context.acc(diff);
|
|
17386
|
+
for (const pair of pairs) {
|
|
17387
|
+
this.context.registerGCPair(pair);
|
|
17388
|
+
}
|
|
17389
|
+
this.context.push(
|
|
17390
|
+
TreeStyleOperation.createTreeRemoveStyleOperation(
|
|
17391
|
+
this.tree.getCreatedAt(),
|
|
17392
|
+
fromPos,
|
|
17393
|
+
toPos,
|
|
17394
|
+
attributesToRemove,
|
|
17395
|
+
ticket
|
|
17396
|
+
)
|
|
17397
|
+
);
|
|
17398
|
+
}
|
|
17326
17399
|
editInternal(fromPos, toPos, contents, splitLevel = 0) {
|
|
17327
17400
|
if (contents.length !== 0 && contents[0]) {
|
|
17328
17401
|
validateTreeNodes(contents);
|
|
@@ -18707,6 +18780,7 @@ var DocEventType = /* @__PURE__ */ ((DocEventType2) => {
|
|
|
18707
18780
|
DocEventType2["Unwatched"] = "unwatched";
|
|
18708
18781
|
DocEventType2["PresenceChanged"] = "presence-changed";
|
|
18709
18782
|
DocEventType2["AuthError"] = "auth-error";
|
|
18783
|
+
DocEventType2["EpochMismatch"] = "epoch-mismatch";
|
|
18710
18784
|
return DocEventType2;
|
|
18711
18785
|
})(DocEventType || {});
|
|
18712
18786
|
var StreamConnectionStatus = /* @__PURE__ */ ((StreamConnectionStatus2) => {
|
|
@@ -18996,6 +19070,17 @@ class Document {
|
|
|
18996
19070
|
}
|
|
18997
19071
|
}, arg3);
|
|
18998
19072
|
}
|
|
19073
|
+
if (arg1 === "epoch-mismatch") {
|
|
19074
|
+
const callback2 = arg2;
|
|
19075
|
+
return this.eventStream.subscribe((event) => {
|
|
19076
|
+
for (const docEvent of event) {
|
|
19077
|
+
if (docEvent.type !== "epoch-mismatch") {
|
|
19078
|
+
continue;
|
|
19079
|
+
}
|
|
19080
|
+
callback2(docEvent);
|
|
19081
|
+
}
|
|
19082
|
+
}, arg3);
|
|
19083
|
+
}
|
|
18999
19084
|
if (arg1 === "all") {
|
|
19000
19085
|
const callback2 = arg2;
|
|
19001
19086
|
return this.eventStream.subscribe(callback2, arg3, arg4);
|
|
@@ -19943,7 +20028,7 @@ function createAuthInterceptor(apiKey, token) {
|
|
|
19943
20028
|
};
|
|
19944
20029
|
}
|
|
19945
20030
|
const name = "@yorkie-js/sdk";
|
|
19946
|
-
const version = "0.7.
|
|
20031
|
+
const version = "0.7.3";
|
|
19947
20032
|
const pkg = {
|
|
19948
20033
|
name,
|
|
19949
20034
|
version
|
|
@@ -20744,6 +20829,16 @@ class Client {
|
|
|
20744
20829
|
).catch(
|
|
20745
20830
|
async (err) => {
|
|
20746
20831
|
logger.error(`[SY] c:"${this.getKey()}" err :`, err);
|
|
20832
|
+
if (isErrorCode(err, Code.ErrEpochMismatch)) {
|
|
20833
|
+
attachment.resource.publish([
|
|
20834
|
+
{
|
|
20835
|
+
type: DocEventType.EpochMismatch,
|
|
20836
|
+
value: {
|
|
20837
|
+
method: "PushPull"
|
|
20838
|
+
}
|
|
20839
|
+
}
|
|
20840
|
+
]);
|
|
20841
|
+
}
|
|
20747
20842
|
await this.handleConnectError(err);
|
|
20748
20843
|
throw err;
|
|
20749
20844
|
}
|
|
@@ -21127,6 +21222,16 @@ class Client {
|
|
|
21127
21222
|
}
|
|
21128
21223
|
]);
|
|
21129
21224
|
}
|
|
21225
|
+
if (isErrorCode(e, Code.ErrEpochMismatch)) {
|
|
21226
|
+
attachment.resource.publish([
|
|
21227
|
+
{
|
|
21228
|
+
type: DocEventType.EpochMismatch,
|
|
21229
|
+
value: {
|
|
21230
|
+
method: "PushPull"
|
|
21231
|
+
}
|
|
21232
|
+
}
|
|
21233
|
+
]);
|
|
21234
|
+
}
|
|
21130
21235
|
throw e;
|
|
21131
21236
|
})
|
|
21132
21237
|
);
|
|
@@ -21556,6 +21661,9 @@ class Client {
|
|
|
21556
21661
|
if (errorCodeOf(err) === Code.ErrTooManyAttachments) {
|
|
21557
21662
|
return false;
|
|
21558
21663
|
}
|
|
21664
|
+
if (errorCodeOf(err) === Code.ErrEpochMismatch) {
|
|
21665
|
+
return false;
|
|
21666
|
+
}
|
|
21559
21667
|
if (errorCodeOf(err) === Code.ErrClientNotActivated || errorCodeOf(err) === Code.ErrClientNotFound) {
|
|
21560
21668
|
this.deactivateInternal();
|
|
21561
21669
|
}
|