@lark-sh/client 0.1.21 → 0.1.23
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 +40 -0
- package/dist/{chunk-HHBHX2EM.mjs → chunk-3MBKCYWV.mjs} +28 -35
- package/dist/chunk-3MBKCYWV.mjs.map +1 -0
- package/dist/fb-v8/index.js +27 -34
- package/dist/fb-v8/index.js.map +1 -1
- package/dist/fb-v8/index.mjs +1 -1
- package/dist/index.d.mts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +27 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/dist/chunk-HHBHX2EM.mjs.map +0 -1
package/dist/fb-v8/index.mjs
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -728,6 +728,7 @@ declare class LarkDatabase {
|
|
|
728
728
|
private infoSubscriptions;
|
|
729
729
|
private _connectionPromise;
|
|
730
730
|
private _serverTimeOffset;
|
|
731
|
+
private _pingInterval;
|
|
731
732
|
/**
|
|
732
733
|
* Create a new LarkDatabase instance.
|
|
733
734
|
*
|
|
@@ -849,6 +850,10 @@ declare class LarkDatabase {
|
|
|
849
850
|
* Used for unexpected disconnect.
|
|
850
851
|
*/
|
|
851
852
|
private cleanupForReconnect;
|
|
853
|
+
private static _realSetInterval;
|
|
854
|
+
private static _realClearInterval;
|
|
855
|
+
private startPingInterval;
|
|
856
|
+
private stopPingInterval;
|
|
852
857
|
/**
|
|
853
858
|
* Check if a path is a .info path (handled locally).
|
|
854
859
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -728,6 +728,7 @@ declare class LarkDatabase {
|
|
|
728
728
|
private infoSubscriptions;
|
|
729
729
|
private _connectionPromise;
|
|
730
730
|
private _serverTimeOffset;
|
|
731
|
+
private _pingInterval;
|
|
731
732
|
/**
|
|
732
733
|
* Create a new LarkDatabase instance.
|
|
733
734
|
*
|
|
@@ -849,6 +850,10 @@ declare class LarkDatabase {
|
|
|
849
850
|
* Used for unexpected disconnect.
|
|
850
851
|
*/
|
|
851
852
|
private cleanupForReconnect;
|
|
853
|
+
private static _realSetInterval;
|
|
854
|
+
private static _realClearInterval;
|
|
855
|
+
private startPingInterval;
|
|
856
|
+
private stopPingInterval;
|
|
852
857
|
/**
|
|
853
858
|
* Check if a path is a .info path (handled locally).
|
|
854
859
|
*/
|
package/dist/index.js
CHANGED
|
@@ -413,9 +413,6 @@ function isEventMessage(msg) {
|
|
|
413
413
|
function isOnceResponseMessage(msg) {
|
|
414
414
|
return "oc" in msg;
|
|
415
415
|
}
|
|
416
|
-
function isPingMessage(msg) {
|
|
417
|
-
return "o" in msg && msg.o === "pi";
|
|
418
|
-
}
|
|
419
416
|
|
|
420
417
|
// src/connection/MessageQueue.ts
|
|
421
418
|
var MessageQueue = class {
|
|
@@ -1710,15 +1707,14 @@ var SubscriptionManager = class {
|
|
|
1710
1707
|
}
|
|
1711
1708
|
/**
|
|
1712
1709
|
* Handle an incoming event message from the server.
|
|
1713
|
-
* Server sends 'put'
|
|
1710
|
+
* Server sends 'put' or 'patch' events; we generate child_* events client-side.
|
|
1711
|
+
* Volatile events use `x: true` flag on patch events.
|
|
1714
1712
|
*/
|
|
1715
1713
|
handleEvent(message) {
|
|
1716
1714
|
if (message.ev === "put") {
|
|
1717
1715
|
this.handlePutEvent(message);
|
|
1718
1716
|
} else if (message.ev === "patch") {
|
|
1719
1717
|
this.handlePatchEvent(message);
|
|
1720
|
-
} else if (message.ev === "vb") {
|
|
1721
|
-
this.handleVolatileBatchEvent(message);
|
|
1722
1718
|
} else {
|
|
1723
1719
|
console.warn("Unknown event type:", message.ev);
|
|
1724
1720
|
}
|
|
@@ -1791,28 +1787,6 @@ var SubscriptionManager = class {
|
|
|
1791
1787
|
this.applyServerUpdateToView(view, updates, isVolatile, serverTimestamp);
|
|
1792
1788
|
}
|
|
1793
1789
|
}
|
|
1794
|
-
/**
|
|
1795
|
-
* Handle a 'vb' (volatile batch) event - batched volatile updates across subscriptions.
|
|
1796
|
-
* Server batches volatile events in 50ms intervals to reduce message overhead.
|
|
1797
|
-
* Format: { ev: 'vb', b: { subscriptionPath: { relativePath: value } }, ts: timestamp }
|
|
1798
|
-
* Dispatches to ALL Views at each subscription path.
|
|
1799
|
-
*/
|
|
1800
|
-
handleVolatileBatchEvent(message) {
|
|
1801
|
-
const batch = message.b;
|
|
1802
|
-
const serverTimestamp = message.ts;
|
|
1803
|
-
if (!batch) return;
|
|
1804
|
-
for (const [subscriptionPath, updates] of Object.entries(batch)) {
|
|
1805
|
-
const views = this.getViewsAtPath(subscriptionPath);
|
|
1806
|
-
if (views.length === 0) continue;
|
|
1807
|
-
const updatesList = [];
|
|
1808
|
-
for (const [relativePath, value] of Object.entries(updates)) {
|
|
1809
|
-
updatesList.push({ relativePath, value });
|
|
1810
|
-
}
|
|
1811
|
-
for (const view of views) {
|
|
1812
|
-
this.applyServerUpdateToView(view, updatesList, true, serverTimestamp);
|
|
1813
|
-
}
|
|
1814
|
-
}
|
|
1815
|
-
}
|
|
1816
1790
|
/**
|
|
1817
1791
|
* Detect and fire child_moved events for children that changed position OR sort value.
|
|
1818
1792
|
*
|
|
@@ -4278,7 +4252,7 @@ var ServerValue = {
|
|
|
4278
4252
|
*/
|
|
4279
4253
|
increment: (delta) => ({ ".sv": { increment: delta } })
|
|
4280
4254
|
};
|
|
4281
|
-
var
|
|
4255
|
+
var _LarkDatabase = class _LarkDatabase {
|
|
4282
4256
|
/**
|
|
4283
4257
|
* Create a new LarkDatabase instance.
|
|
4284
4258
|
*
|
|
@@ -4321,6 +4295,7 @@ var LarkDatabase = class {
|
|
|
4321
4295
|
// Connection promise - shared by connect() and lazy operations
|
|
4322
4296
|
this._connectionPromise = null;
|
|
4323
4297
|
this._serverTimeOffset = 0;
|
|
4298
|
+
this._pingInterval = null;
|
|
4324
4299
|
this.messageQueue = new MessageQueue();
|
|
4325
4300
|
this.subscriptionManager = new SubscriptionManager();
|
|
4326
4301
|
this.pendingWrites = new PendingWriteManager();
|
|
@@ -4518,6 +4493,7 @@ var LarkDatabase = class {
|
|
|
4518
4493
|
};
|
|
4519
4494
|
this._state = "authenticated";
|
|
4520
4495
|
this._reconnectAttempt = 0;
|
|
4496
|
+
this.startPingInterval();
|
|
4521
4497
|
this.fireConnectionStateChange();
|
|
4522
4498
|
if (isReconnect) {
|
|
4523
4499
|
await this.restoreAfterReconnect();
|
|
@@ -4607,6 +4583,7 @@ var LarkDatabase = class {
|
|
|
4607
4583
|
*/
|
|
4608
4584
|
cleanupFull() {
|
|
4609
4585
|
const wasAuthenticated = this._state === "authenticated";
|
|
4586
|
+
this.stopPingInterval();
|
|
4610
4587
|
this.transport?.close();
|
|
4611
4588
|
this.transport = null;
|
|
4612
4589
|
this._state = "disconnected";
|
|
@@ -4629,6 +4606,7 @@ var LarkDatabase = class {
|
|
|
4629
4606
|
* Used for unexpected disconnect.
|
|
4630
4607
|
*/
|
|
4631
4608
|
cleanupForReconnect() {
|
|
4609
|
+
this.stopPingInterval();
|
|
4632
4610
|
this.transport?.close();
|
|
4633
4611
|
this.transport = null;
|
|
4634
4612
|
this._auth = null;
|
|
@@ -4636,6 +4614,21 @@ var LarkDatabase = class {
|
|
|
4636
4614
|
this.messageQueue.rejectAll(new Error("Connection closed"));
|
|
4637
4615
|
this.fireConnectionStateChange();
|
|
4638
4616
|
}
|
|
4617
|
+
startPingInterval() {
|
|
4618
|
+
this.stopPingInterval();
|
|
4619
|
+
this._pingInterval = _LarkDatabase._realSetInterval(() => {
|
|
4620
|
+
this.transport?.send(JSON.stringify({ o: "pi" }));
|
|
4621
|
+
}, 1e4);
|
|
4622
|
+
if (typeof this._pingInterval === "object" && "unref" in this._pingInterval) {
|
|
4623
|
+
this._pingInterval.unref();
|
|
4624
|
+
}
|
|
4625
|
+
}
|
|
4626
|
+
stopPingInterval() {
|
|
4627
|
+
if (this._pingInterval) {
|
|
4628
|
+
_LarkDatabase._realClearInterval(this._pingInterval);
|
|
4629
|
+
this._pingInterval = null;
|
|
4630
|
+
}
|
|
4631
|
+
}
|
|
4639
4632
|
// ============================================
|
|
4640
4633
|
// .info Path Handling
|
|
4641
4634
|
// ============================================
|
|
@@ -5018,10 +5011,6 @@ var LarkDatabase = class {
|
|
|
5018
5011
|
if (process.env.LARK_DEBUG) {
|
|
5019
5012
|
console.log("[LARK] <<< SERVER:", JSON.stringify(message, null, 2));
|
|
5020
5013
|
}
|
|
5021
|
-
if (isPingMessage(message)) {
|
|
5022
|
-
this.transport?.send(JSON.stringify({ o: "po" }));
|
|
5023
|
-
return;
|
|
5024
|
-
}
|
|
5025
5014
|
if (isAckMessage(message)) {
|
|
5026
5015
|
this.pendingWrites.onAck(message.a);
|
|
5027
5016
|
this.subscriptionManager.clearPendingWrite(message.a);
|
|
@@ -5375,7 +5364,11 @@ var LarkDatabase = class {
|
|
|
5375
5364
|
* Server values that are resolved by the server when a write is committed.
|
|
5376
5365
|
* Alias for the exported ServerValue object.
|
|
5377
5366
|
*/
|
|
5378
|
-
|
|
5367
|
+
_LarkDatabase.ServerValue = ServerValue;
|
|
5368
|
+
// Use real timers for ping so fake timers in tests don't cause infinite loops
|
|
5369
|
+
_LarkDatabase._realSetInterval = globalThis.setInterval;
|
|
5370
|
+
_LarkDatabase._realClearInterval = globalThis.clearInterval;
|
|
5371
|
+
var LarkDatabase = _LarkDatabase;
|
|
5379
5372
|
// Annotate the CommonJS export names for ESM import in node:
|
|
5380
5373
|
0 && (module.exports = {
|
|
5381
5374
|
DataSnapshot,
|