@loro-dev/flock 4.3.0 → 4.4.1

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/index.d.mts CHANGED
@@ -120,6 +120,9 @@ type EventBatch = {
120
120
  };
121
121
  declare class Flock {
122
122
  private inner;
123
+ private listeners;
124
+ private nativeUnsubscribe;
125
+ private readonly eventBatcher;
123
126
  constructor(peerId?: string);
124
127
  private static fromInner;
125
128
  static fromJson(bundle: ExportBundle, peerId: string): Flock;
@@ -186,7 +189,50 @@ declare class Flock {
186
189
  putMvr(key: KeyPart[], value: Value, now?: number): void;
187
190
  getMvr(key: KeyPart[]): Value[];
188
191
  scan(options?: ScanOptions): ScanRow[];
192
+ private ensureNativeSubscription;
193
+ private handleBatch;
194
+ private deliverBatch;
189
195
  subscribe(listener: (batch: EventBatch) => void): () => void;
196
+ /**
197
+ * Enable auto-debounce mode. Events will be accumulated and emitted after
198
+ * the specified timeout of inactivity. Each new operation resets the timer.
199
+ *
200
+ * Use `commit()` to force immediate emission of pending events.
201
+ * Use `disableAutoDebounceCommit()` to disable and emit pending events.
202
+ *
203
+ * @param timeout - Debounce timeout in milliseconds
204
+ * @param options - Optional configuration object with maxDebounceTime (default: 10000ms)
205
+ * @throws Error if called while a transaction is active
206
+ * @throws Error if autoDebounceCommit is already active
207
+ *
208
+ * @example
209
+ * ```ts
210
+ * flock.autoDebounceCommit(100);
211
+ * flock.put(["a"], 1);
212
+ * flock.put(["b"], 2);
213
+ * // No events emitted yet...
214
+ * // After 100ms of inactivity, subscribers receive single EventBatch
215
+ * // If operations keep coming, commit happens after maxDebounceTime (10s default)
216
+ * ```
217
+ */
218
+ autoDebounceCommit(timeout: number, options?: {
219
+ maxDebounceTime?: number;
220
+ }): void;
221
+ /**
222
+ * Disable auto-debounce mode and emit any pending events immediately.
223
+ * No-op if autoDebounceCommit is not active.
224
+ */
225
+ disableAutoDebounceCommit(): void;
226
+ /**
227
+ * Force immediate emission of any pending debounced events.
228
+ * Does not disable auto-debounce mode - new operations will continue to be debounced.
229
+ * No-op if autoDebounceCommit is not active or no events are pending.
230
+ */
231
+ commit(): void;
232
+ /**
233
+ * Check if auto-debounce mode is currently active.
234
+ */
235
+ isAutoDebounceActive(): boolean;
190
236
  /**
191
237
  * Execute operations within a transaction. All put/delete operations inside
192
238
  * the callback will be batched and emitted as a single EventBatch when the
@@ -202,6 +248,7 @@ declare class Flock {
202
248
  * @returns The return value of the callback
203
249
  * @throws Error if nested transaction attempted
204
250
  * @throws Error if import is called during the transaction (auto-commits first)
251
+ * @throws Error if called while autoDebounceCommit is active
205
252
  *
206
253
  * @example
207
254
  * ```ts
package/dist/index.d.ts CHANGED
@@ -120,6 +120,9 @@ type EventBatch = {
120
120
  };
121
121
  declare class Flock {
122
122
  private inner;
123
+ private listeners;
124
+ private nativeUnsubscribe;
125
+ private readonly eventBatcher;
123
126
  constructor(peerId?: string);
124
127
  private static fromInner;
125
128
  static fromJson(bundle: ExportBundle, peerId: string): Flock;
@@ -186,7 +189,50 @@ declare class Flock {
186
189
  putMvr(key: KeyPart[], value: Value, now?: number): void;
187
190
  getMvr(key: KeyPart[]): Value[];
188
191
  scan(options?: ScanOptions): ScanRow[];
192
+ private ensureNativeSubscription;
193
+ private handleBatch;
194
+ private deliverBatch;
189
195
  subscribe(listener: (batch: EventBatch) => void): () => void;
196
+ /**
197
+ * Enable auto-debounce mode. Events will be accumulated and emitted after
198
+ * the specified timeout of inactivity. Each new operation resets the timer.
199
+ *
200
+ * Use `commit()` to force immediate emission of pending events.
201
+ * Use `disableAutoDebounceCommit()` to disable and emit pending events.
202
+ *
203
+ * @param timeout - Debounce timeout in milliseconds
204
+ * @param options - Optional configuration object with maxDebounceTime (default: 10000ms)
205
+ * @throws Error if called while a transaction is active
206
+ * @throws Error if autoDebounceCommit is already active
207
+ *
208
+ * @example
209
+ * ```ts
210
+ * flock.autoDebounceCommit(100);
211
+ * flock.put(["a"], 1);
212
+ * flock.put(["b"], 2);
213
+ * // No events emitted yet...
214
+ * // After 100ms of inactivity, subscribers receive single EventBatch
215
+ * // If operations keep coming, commit happens after maxDebounceTime (10s default)
216
+ * ```
217
+ */
218
+ autoDebounceCommit(timeout: number, options?: {
219
+ maxDebounceTime?: number;
220
+ }): void;
221
+ /**
222
+ * Disable auto-debounce mode and emit any pending events immediately.
223
+ * No-op if autoDebounceCommit is not active.
224
+ */
225
+ disableAutoDebounceCommit(): void;
226
+ /**
227
+ * Force immediate emission of any pending debounced events.
228
+ * Does not disable auto-debounce mode - new operations will continue to be debounced.
229
+ * No-op if autoDebounceCommit is not active or no events are pending.
230
+ */
231
+ commit(): void;
232
+ /**
233
+ * Check if auto-debounce mode is currently active.
234
+ */
235
+ isAutoDebounceActive(): boolean;
190
236
  /**
191
237
  * Execute operations within a transaction. All put/delete operations inside
192
238
  * the callback will be batched and emitted as a single EventBatch when the
@@ -202,6 +248,7 @@ declare class Flock {
202
248
  * @returns The return value of the callback
203
249
  * @throws Error if nested transaction attempted
204
250
  * @throws Error if import is called during the transaction (auto-commits first)
251
+ * @throws Error if called while autoDebounceCommit is active
205
252
  *
206
253
  * @example
207
254
  * ```ts