@lark-sh/client 0.1.22 → 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-T5RXZAER.mjs → chunk-3MBKCYWV.mjs} +26 -10
- package/dist/{chunk-T5RXZAER.mjs.map → chunk-3MBKCYWV.mjs.map} +1 -1
- package/dist/fb-v8/index.js +25 -9
- 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 +25 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/fb-v8/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 {
|
|
@@ -4255,7 +4252,7 @@ var ServerValue = {
|
|
|
4255
4252
|
*/
|
|
4256
4253
|
increment: (delta) => ({ ".sv": { increment: delta } })
|
|
4257
4254
|
};
|
|
4258
|
-
var
|
|
4255
|
+
var _LarkDatabase = class _LarkDatabase {
|
|
4259
4256
|
/**
|
|
4260
4257
|
* Create a new LarkDatabase instance.
|
|
4261
4258
|
*
|
|
@@ -4298,6 +4295,7 @@ var LarkDatabase = class {
|
|
|
4298
4295
|
// Connection promise - shared by connect() and lazy operations
|
|
4299
4296
|
this._connectionPromise = null;
|
|
4300
4297
|
this._serverTimeOffset = 0;
|
|
4298
|
+
this._pingInterval = null;
|
|
4301
4299
|
this.messageQueue = new MessageQueue();
|
|
4302
4300
|
this.subscriptionManager = new SubscriptionManager();
|
|
4303
4301
|
this.pendingWrites = new PendingWriteManager();
|
|
@@ -4495,6 +4493,7 @@ var LarkDatabase = class {
|
|
|
4495
4493
|
};
|
|
4496
4494
|
this._state = "authenticated";
|
|
4497
4495
|
this._reconnectAttempt = 0;
|
|
4496
|
+
this.startPingInterval();
|
|
4498
4497
|
this.fireConnectionStateChange();
|
|
4499
4498
|
if (isReconnect) {
|
|
4500
4499
|
await this.restoreAfterReconnect();
|
|
@@ -4584,6 +4583,7 @@ var LarkDatabase = class {
|
|
|
4584
4583
|
*/
|
|
4585
4584
|
cleanupFull() {
|
|
4586
4585
|
const wasAuthenticated = this._state === "authenticated";
|
|
4586
|
+
this.stopPingInterval();
|
|
4587
4587
|
this.transport?.close();
|
|
4588
4588
|
this.transport = null;
|
|
4589
4589
|
this._state = "disconnected";
|
|
@@ -4606,6 +4606,7 @@ var LarkDatabase = class {
|
|
|
4606
4606
|
* Used for unexpected disconnect.
|
|
4607
4607
|
*/
|
|
4608
4608
|
cleanupForReconnect() {
|
|
4609
|
+
this.stopPingInterval();
|
|
4609
4610
|
this.transport?.close();
|
|
4610
4611
|
this.transport = null;
|
|
4611
4612
|
this._auth = null;
|
|
@@ -4613,6 +4614,21 @@ var LarkDatabase = class {
|
|
|
4613
4614
|
this.messageQueue.rejectAll(new Error("Connection closed"));
|
|
4614
4615
|
this.fireConnectionStateChange();
|
|
4615
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
|
+
}
|
|
4616
4632
|
// ============================================
|
|
4617
4633
|
// .info Path Handling
|
|
4618
4634
|
// ============================================
|
|
@@ -4995,10 +5011,6 @@ var LarkDatabase = class {
|
|
|
4995
5011
|
if (process.env.LARK_DEBUG) {
|
|
4996
5012
|
console.log("[LARK] <<< SERVER:", JSON.stringify(message, null, 2));
|
|
4997
5013
|
}
|
|
4998
|
-
if (isPingMessage(message)) {
|
|
4999
|
-
this.transport?.send(JSON.stringify({ o: "po" }));
|
|
5000
|
-
return;
|
|
5001
|
-
}
|
|
5002
5014
|
if (isAckMessage(message)) {
|
|
5003
5015
|
this.pendingWrites.onAck(message.a);
|
|
5004
5016
|
this.subscriptionManager.clearPendingWrite(message.a);
|
|
@@ -5352,7 +5364,11 @@ var LarkDatabase = class {
|
|
|
5352
5364
|
* Server values that are resolved by the server when a write is committed.
|
|
5353
5365
|
* Alias for the exported ServerValue object.
|
|
5354
5366
|
*/
|
|
5355
|
-
|
|
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;
|
|
5356
5372
|
|
|
5357
5373
|
// src/fb-v8/index.ts
|
|
5358
5374
|
var DatabaseReference2 = class _DatabaseReference {
|