@yorkie-js/sdk 0.7.6 → 0.7.8

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/README.md CHANGED
@@ -10,7 +10,7 @@ To get started using Yorkie JavaScript SDK, see: https://yorkie.dev/docs/js-sdk
10
10
 
11
11
  ## Contributing
12
12
 
13
- See [CONTRIBUTING](CONTRIBUTING.md) for details on submitting patches and the contribution workflow.
13
+ See [CONTRIBUTING](../../CONTRIBUTING.md) for details on submitting patches and the contribution workflow.
14
14
 
15
15
  ## Contributors ✨
16
16
 
@@ -93,20 +93,30 @@ declare interface Attachable {
93
93
  /**
94
94
  * `AttachChannelOptions` are user-settable options used when attaching channels.
95
95
  */
96
- declare interface AttachChannelOptions {
96
+ export declare interface AttachChannelOptions {
97
97
  /**
98
- * `isRealtime` determines whether to automatically watch channel changes
99
- * and send heartbeats. If false (manual mode), the client must call sync()
100
- * explicitly to refresh the TTL.
101
- * Default is true for backward compatibility.
98
+ * `syncMode` selects how the channel keeps presence in sync with the server.
99
+ * Default is `SyncMode.Realtime`.
100
+ * - `SyncMode.Realtime`: open a watch stream and run the heartbeat. Required
101
+ * to receive broadcast events.
102
+ * - `SyncMode.Polling`: heartbeat-only. No watch stream is opened. The
103
+ * heartbeat refreshes TTL and brings the latest sessionCount. Recommended
104
+ * for large channels where broadcast is not needed.
105
+ * - `SyncMode.Manual`: no automatic activity. Caller must invoke `sync()`.
102
106
  */
103
- isRealtime?: boolean;
107
+ syncMode?: SyncMode;
108
+ /**
109
+ * `channelHeartbeatInterval` overrides the heartbeat interval (ms) for this
110
+ * attachment. If unset, mode-specific defaults apply: Polling=3000,
111
+ * Realtime=30000.
112
+ */
113
+ channelHeartbeatInterval?: number;
104
114
  }
105
115
 
106
116
  /**
107
117
  * `AttachOptions` are user-settable options used when attaching documents.
108
118
  */
109
- declare interface AttachOptions<R, P> {
119
+ export declare interface AttachOptions<R, P> {
110
120
  /**
111
121
  * `initialRoot` is the initial root of the document. It is used to
112
122
  * initialize the document. It is used when the fields are not set in the
@@ -121,6 +131,11 @@ declare interface AttachOptions<R, P> {
121
131
  * `syncMode` defines the synchronization mode of the document.
122
132
  */
123
133
  syncMode?: SyncMode;
134
+ /**
135
+ * `documentPollInterval` (ms) — only used when `syncMode` is `Polling`.
136
+ * Default: 3000.
137
+ */
138
+ documentPollInterval?: number;
124
139
  /**
125
140
  * `schema` is the schema of the document. It is used to validate the
126
141
  * document.
@@ -1039,6 +1054,17 @@ export declare class Client {
1039
1054
  * `changeSyncMode` changes the synchronization mode of the given document.
1040
1055
  */
1041
1056
  changeSyncMode<R, P extends Indexable>(doc: Document_2<R, P>, syncMode: SyncMode): Promise<Document_2<R, P>>;
1057
+ /**
1058
+ * `changeSyncMode` changes the synchronization mode of the given channel.
1059
+ */
1060
+ changeSyncMode(channel: Channel, syncMode: SyncMode): Promise<Channel>;
1061
+ private changeDocumentSyncMode;
1062
+ /**
1063
+ * `assertValidChannelSyncMode` rejects sync modes that are not valid for
1064
+ * channels. `RealtimePushOnly` and `RealtimeSyncOff` are document-only.
1065
+ */
1066
+ private assertValidChannelSyncMode;
1067
+ private changeChannelSyncMode;
1042
1068
  /**
1043
1069
  * `sync` pushes local changes of the attached documents to the server and
1044
1070
  * receives changes of the remote replica from the server then apply them to
@@ -1997,12 +2023,28 @@ declare class CRDTTree extends CRDTElement implements GCParent {
1997
2023
  * `edit` edits the tree with the given range and content.
1998
2024
  * If the content is undefined, the range will be removed.
1999
2025
  */
2000
- edit(range: [CRDTTreePos, CRDTTreePos], contents: Array<CRDTTreeNode> | undefined, splitLevel: number, editedAt: TimeTicket, issueTimeTicket: (() => TimeTicket) | undefined, versionVector?: VersionVector): [Array<TreeChange>, Array<GCPair>, DataSize, Array<CRDTTreeNode>, number];
2026
+ edit(range: [CRDTTreePos, CRDTTreePos], contents: Array<CRDTTreeNode> | undefined, splitLevel: number, editedAt: TimeTicket, issueTimeTicket: (() => TimeTicket) | undefined, versionVector?: VersionVector): [
2027
+ Array<TreeChange>,
2028
+ Array<GCPair>,
2029
+ DataSize,
2030
+ Array<CRDTTreeNode>,
2031
+ number,
2032
+ number,
2033
+ Set<string>
2034
+ ];
2001
2035
  /**
2002
2036
  * `editT` edits the given range with the given value.
2003
2037
  * This method uses indexes instead of a pair of TreePos for testing.
2004
2038
  */
2005
- editT(range: [number, number], contents: Array<CRDTTreeNode> | undefined, splitLevel: number, editedAt: TimeTicket, issueTimeTicket: () => TimeTicket): [Array<TreeChange>, Array<GCPair>, DataSize, Array<CRDTTreeNode>, number];
2039
+ editT(range: [number, number], contents: Array<CRDTTreeNode> | undefined, splitLevel: number, editedAt: TimeTicket, issueTimeTicket: () => TimeTicket): [
2040
+ Array<TreeChange>,
2041
+ Array<GCPair>,
2042
+ DataSize,
2043
+ Array<CRDTTreeNode>,
2044
+ number,
2045
+ number,
2046
+ Set<string>
2047
+ ];
2006
2048
  /**
2007
2049
  * `move` move the given source range to the given target range.
2008
2050
  */
@@ -3035,7 +3077,12 @@ declare class Document_2<R, P extends Indexable = Indexable> implements Attachab
3035
3077
  * `applySnapshot` applies the given snapshot into this document.
3036
3078
  */
3037
3079
  applySnapshot(serverSeq: bigint, snapshotVector: VersionVector, snapshot?: Uint8Array, clientSeq?: number): void;
3038
- private clearHistory;
3080
+ /**
3081
+ * `clearHistory` flushes both undo and redo stacks. This is used
3082
+ * after applying a snapshot or initialRoot so that setup operations
3083
+ * are not reachable via undo.
3084
+ */
3085
+ clearHistory(): void;
3039
3086
  /**
3040
3087
  * `applyChanges` applies the given changes into this document.
3041
3088
  */
@@ -3716,6 +3763,19 @@ declare function isDate(value: any): value is YSONDate {
3716
3763
  );
3717
3764
  }
3718
3765
 
3766
+ /**
3767
+ * `isDedupCounter` checks if a value is a YSONDedupCounter object.
3768
+ */
3769
+ declare function isDedupCounter(value: any): value is YSONDedupCounter {
3770
+ return (
3771
+ typeof value === 'object' &&
3772
+ value !== null &&
3773
+ value.type === 'DedupCounter' &&
3774
+ typeof value.value === 'object' &&
3775
+ typeof value.registers === 'string'
3776
+ );
3777
+ }
3778
+
3719
3779
  /**
3720
3780
  * `isDocEventForReplay` checks if an event can be used to replay a document.
3721
3781
  */
@@ -3783,7 +3843,8 @@ declare function isObject(value: any): value is { [key: string]: YSONValue } {
3783
3843
  !isLong(value) &&
3784
3844
  !isDate(value) &&
3785
3845
  !isBinData(value) &&
3786
- !isCounter(value)
3846
+ !isCounter(value) &&
3847
+ !isDedupCounter(value)
3787
3848
  );
3788
3849
  }
3789
3850
 
@@ -5991,7 +6052,8 @@ declare interface SubscribeFn<T> {
5991
6052
  }
5992
6053
 
5993
6054
  /**
5994
- * `SyncMode` defines synchronization modes for the PushPullChanges API.
6055
+ * `SyncMode` defines synchronization modes for the PushPullChanges API
6056
+ * (documents) and the RefreshChannel heartbeat (channels).
5995
6057
  */
5996
6058
  export declare enum SyncMode {
5997
6059
  /**
@@ -6010,7 +6072,15 @@ export declare enum SyncMode {
6010
6072
  * `RealtimeSyncOff` mode indicates that changes are not automatically pushed or pulled,
6011
6073
  * but the watch stream is kept active.
6012
6074
  */
6013
- RealtimeSyncOff = "realtime-syncoff"
6075
+ RealtimeSyncOff = "realtime-syncoff",
6076
+ /**
6077
+ * `Polling` mode runs the sync loop without opening a watch stream.
6078
+ * - For Channel: heartbeat refreshes TTL and brings sessionCount.
6079
+ * - For Document: PushPullChanges runs at the polling interval. Remote
6080
+ * changes arrive on the next tick (latency = interval). Not suitable
6081
+ * for collaborative editing — use Realtime for that.
6082
+ */
6083
+ Polling = "polling"
6014
6084
  }
6015
6085
 
6016
6086
  /**
@@ -7019,6 +7089,7 @@ declare namespace YSON {
7019
7089
  YSONDate as Date,
7020
7090
  YSONBinData as BinData,
7021
7091
  YSONCounter as Counter,
7092
+ YSONDedupCounter as DedupCounter,
7022
7093
  isText,
7023
7094
  isTree,
7024
7095
  isInt,
@@ -7026,6 +7097,7 @@ declare namespace YSON {
7026
7097
  isDate,
7027
7098
  isBinData,
7028
7099
  isCounter,
7100
+ isDedupCounter,
7029
7101
  isObject,
7030
7102
  parse,
7031
7103
  textToString,
@@ -7073,6 +7145,21 @@ declare interface YSONDate {
7073
7145
  value: string;
7074
7146
  }
7075
7147
 
7148
+ /**
7149
+ * `YSONDedupCounter` represents a DedupCounter CRDT that uses HyperLogLog
7150
+ * to count unique actors.
7151
+ *
7152
+ * @example
7153
+ * ```typescript
7154
+ * { type: 'DedupCounter', value: { type: 'Int', value: 15 }, registers: 'AQID...' }
7155
+ * ```
7156
+ */
7157
+ declare interface YSONDedupCounter {
7158
+ type: 'DedupCounter';
7159
+ value: YSONInt;
7160
+ registers: string;
7161
+ }
7162
+
7076
7163
  /**
7077
7164
  * `YSONInt` represents a 32-bit integer.
7078
7165
  *
@@ -7209,6 +7296,7 @@ declare type YSONValue =
7209
7296
  | YSONDate
7210
7297
  | YSONBinData
7211
7298
  | YSONCounter
7299
+ | YSONDedupCounter
7212
7300
  | { [key: string]: YSONValue }
7213
7301
  | Array<YSONValue>;
7214
7302