@lark-sh/client 0.1.8 → 0.1.10
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 +38 -4
- package/dist/index.d.ts +38 -4
- package/dist/index.js +489 -137
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +489 -137
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transport factory - creates appropriate transport based on availability and options.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
type TransportType = 'auto' | 'websocket' | 'webtransport';
|
|
6
|
+
|
|
1
7
|
/**
|
|
2
8
|
* OnDisconnect - registers operations to perform on the server when this client disconnects.
|
|
3
9
|
*/
|
|
@@ -336,11 +342,17 @@ interface TxDeleteOp {
|
|
|
336
342
|
o: 'd';
|
|
337
343
|
p: string;
|
|
338
344
|
}
|
|
339
|
-
interface
|
|
345
|
+
interface TxConditionValueOp {
|
|
340
346
|
o: 'c';
|
|
341
347
|
p: string;
|
|
342
348
|
v: unknown;
|
|
343
349
|
}
|
|
350
|
+
interface TxConditionHashOp {
|
|
351
|
+
o: 'c';
|
|
352
|
+
p: string;
|
|
353
|
+
h: string;
|
|
354
|
+
}
|
|
355
|
+
type TxConditionOp = TxConditionValueOp | TxConditionHashOp;
|
|
344
356
|
type TxOperation = TxSetOp | TxUpdateOp | TxDeleteOp | TxConditionOp;
|
|
345
357
|
|
|
346
358
|
/**
|
|
@@ -372,6 +384,20 @@ interface ConnectOptions {
|
|
|
372
384
|
anonymous?: boolean;
|
|
373
385
|
/** Coordinator URL (default: https://db.lark.dev) */
|
|
374
386
|
coordinator?: string;
|
|
387
|
+
/**
|
|
388
|
+
* Transport type preference.
|
|
389
|
+
* - 'auto': Try WebTransport first, fall back to WebSocket (default)
|
|
390
|
+
* - 'websocket': Force WebSocket only
|
|
391
|
+
* - 'webtransport': Force WebTransport only (fails if unavailable)
|
|
392
|
+
*/
|
|
393
|
+
transport?: TransportType;
|
|
394
|
+
/**
|
|
395
|
+
* Timeout for WebTransport connection attempt in milliseconds.
|
|
396
|
+
* If WebTransport doesn't connect within this time, falls back to WebSocket.
|
|
397
|
+
* Only applies when transport is 'auto'.
|
|
398
|
+
* Default: 2000 (2 seconds)
|
|
399
|
+
*/
|
|
400
|
+
webtransportTimeout?: number;
|
|
375
401
|
}
|
|
376
402
|
interface AuthInfo {
|
|
377
403
|
uid: string;
|
|
@@ -412,12 +438,13 @@ declare class LarkDatabase {
|
|
|
412
438
|
private _databaseId;
|
|
413
439
|
private _coordinatorUrl;
|
|
414
440
|
private _volatilePaths;
|
|
441
|
+
private _transportType;
|
|
415
442
|
private _connectionId;
|
|
416
443
|
private _connectOptions;
|
|
417
444
|
private _intentionalDisconnect;
|
|
418
445
|
private _reconnectAttempt;
|
|
419
446
|
private _reconnectTimer;
|
|
420
|
-
private
|
|
447
|
+
private transport;
|
|
421
448
|
private messageQueue;
|
|
422
449
|
private subscriptionManager;
|
|
423
450
|
private pendingWrites;
|
|
@@ -449,9 +476,13 @@ declare class LarkDatabase {
|
|
|
449
476
|
/**
|
|
450
477
|
* Get the volatile path patterns from the server.
|
|
451
478
|
* These patterns indicate which paths should use unreliable transport.
|
|
452
|
-
* WebSocket always uses reliable transport, but this is stored for future UDP support.
|
|
453
479
|
*/
|
|
454
480
|
get volatilePaths(): string[];
|
|
481
|
+
/**
|
|
482
|
+
* Get the current transport type.
|
|
483
|
+
* Returns 'websocket' or 'webtransport', or null if not connected.
|
|
484
|
+
*/
|
|
485
|
+
get transportType(): 'websocket' | 'webtransport' | null;
|
|
455
486
|
/**
|
|
456
487
|
* Check if there are any pending writes waiting for acknowledgment.
|
|
457
488
|
* Useful for showing "saving..." indicators in UI.
|
|
@@ -543,6 +574,7 @@ declare class LarkDatabase {
|
|
|
543
574
|
transaction(operations: TransactionOp[] | TransactionObject): Promise<void>;
|
|
544
575
|
/**
|
|
545
576
|
* Convert a public TransactionOp to wire format TxOperation.
|
|
577
|
+
* Async because condition operations may require hash computation.
|
|
546
578
|
*/
|
|
547
579
|
private convertToTxOp;
|
|
548
580
|
/**
|
|
@@ -603,6 +635,8 @@ declare class LarkDatabase {
|
|
|
603
635
|
*
|
|
604
636
|
* The write is applied optimistically to local cache for UI feedback,
|
|
605
637
|
* but we don't await server confirmation.
|
|
638
|
+
*
|
|
639
|
+
* When using WebTransport, volatile writes are sent via datagrams (UDP).
|
|
606
640
|
*/
|
|
607
641
|
_sendVolatileSet(path: string, value: unknown): void;
|
|
608
642
|
/**
|
|
@@ -773,4 +807,4 @@ declare function generatePushId(): string;
|
|
|
773
807
|
*/
|
|
774
808
|
declare function isVolatilePath(path: string, patterns: string[] | null | undefined): boolean;
|
|
775
809
|
|
|
776
|
-
export { type AuthInfo, type ConnectOptions, DataSnapshot, DatabaseReference, type EventType, LarkDatabase, LarkError, OnDisconnect, type PendingWrite, PendingWriteManager, type QueryParams, type QueryState, type SnapshotCallback$1 as SnapshotCallback, type TransactionConditionOp, type TransactionDeleteOp, type TransactionObject, type TransactionOp, type TransactionResult, type TransactionSetOp, type TransactionUpdateOp, type WriteOperation, generatePushId, isVolatilePath };
|
|
810
|
+
export { type AuthInfo, type ConnectOptions, DataSnapshot, DatabaseReference, type EventType, LarkDatabase, LarkError, OnDisconnect, type PendingWrite, PendingWriteManager, type QueryParams, type QueryState, type SnapshotCallback$1 as SnapshotCallback, type TransactionConditionOp, type TransactionDeleteOp, type TransactionObject, type TransactionOp, type TransactionResult, type TransactionSetOp, type TransactionUpdateOp, type TransportType, type WriteOperation, generatePushId, isVolatilePath };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transport factory - creates appropriate transport based on availability and options.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
type TransportType = 'auto' | 'websocket' | 'webtransport';
|
|
6
|
+
|
|
1
7
|
/**
|
|
2
8
|
* OnDisconnect - registers operations to perform on the server when this client disconnects.
|
|
3
9
|
*/
|
|
@@ -336,11 +342,17 @@ interface TxDeleteOp {
|
|
|
336
342
|
o: 'd';
|
|
337
343
|
p: string;
|
|
338
344
|
}
|
|
339
|
-
interface
|
|
345
|
+
interface TxConditionValueOp {
|
|
340
346
|
o: 'c';
|
|
341
347
|
p: string;
|
|
342
348
|
v: unknown;
|
|
343
349
|
}
|
|
350
|
+
interface TxConditionHashOp {
|
|
351
|
+
o: 'c';
|
|
352
|
+
p: string;
|
|
353
|
+
h: string;
|
|
354
|
+
}
|
|
355
|
+
type TxConditionOp = TxConditionValueOp | TxConditionHashOp;
|
|
344
356
|
type TxOperation = TxSetOp | TxUpdateOp | TxDeleteOp | TxConditionOp;
|
|
345
357
|
|
|
346
358
|
/**
|
|
@@ -372,6 +384,20 @@ interface ConnectOptions {
|
|
|
372
384
|
anonymous?: boolean;
|
|
373
385
|
/** Coordinator URL (default: https://db.lark.dev) */
|
|
374
386
|
coordinator?: string;
|
|
387
|
+
/**
|
|
388
|
+
* Transport type preference.
|
|
389
|
+
* - 'auto': Try WebTransport first, fall back to WebSocket (default)
|
|
390
|
+
* - 'websocket': Force WebSocket only
|
|
391
|
+
* - 'webtransport': Force WebTransport only (fails if unavailable)
|
|
392
|
+
*/
|
|
393
|
+
transport?: TransportType;
|
|
394
|
+
/**
|
|
395
|
+
* Timeout for WebTransport connection attempt in milliseconds.
|
|
396
|
+
* If WebTransport doesn't connect within this time, falls back to WebSocket.
|
|
397
|
+
* Only applies when transport is 'auto'.
|
|
398
|
+
* Default: 2000 (2 seconds)
|
|
399
|
+
*/
|
|
400
|
+
webtransportTimeout?: number;
|
|
375
401
|
}
|
|
376
402
|
interface AuthInfo {
|
|
377
403
|
uid: string;
|
|
@@ -412,12 +438,13 @@ declare class LarkDatabase {
|
|
|
412
438
|
private _databaseId;
|
|
413
439
|
private _coordinatorUrl;
|
|
414
440
|
private _volatilePaths;
|
|
441
|
+
private _transportType;
|
|
415
442
|
private _connectionId;
|
|
416
443
|
private _connectOptions;
|
|
417
444
|
private _intentionalDisconnect;
|
|
418
445
|
private _reconnectAttempt;
|
|
419
446
|
private _reconnectTimer;
|
|
420
|
-
private
|
|
447
|
+
private transport;
|
|
421
448
|
private messageQueue;
|
|
422
449
|
private subscriptionManager;
|
|
423
450
|
private pendingWrites;
|
|
@@ -449,9 +476,13 @@ declare class LarkDatabase {
|
|
|
449
476
|
/**
|
|
450
477
|
* Get the volatile path patterns from the server.
|
|
451
478
|
* These patterns indicate which paths should use unreliable transport.
|
|
452
|
-
* WebSocket always uses reliable transport, but this is stored for future UDP support.
|
|
453
479
|
*/
|
|
454
480
|
get volatilePaths(): string[];
|
|
481
|
+
/**
|
|
482
|
+
* Get the current transport type.
|
|
483
|
+
* Returns 'websocket' or 'webtransport', or null if not connected.
|
|
484
|
+
*/
|
|
485
|
+
get transportType(): 'websocket' | 'webtransport' | null;
|
|
455
486
|
/**
|
|
456
487
|
* Check if there are any pending writes waiting for acknowledgment.
|
|
457
488
|
* Useful for showing "saving..." indicators in UI.
|
|
@@ -543,6 +574,7 @@ declare class LarkDatabase {
|
|
|
543
574
|
transaction(operations: TransactionOp[] | TransactionObject): Promise<void>;
|
|
544
575
|
/**
|
|
545
576
|
* Convert a public TransactionOp to wire format TxOperation.
|
|
577
|
+
* Async because condition operations may require hash computation.
|
|
546
578
|
*/
|
|
547
579
|
private convertToTxOp;
|
|
548
580
|
/**
|
|
@@ -603,6 +635,8 @@ declare class LarkDatabase {
|
|
|
603
635
|
*
|
|
604
636
|
* The write is applied optimistically to local cache for UI feedback,
|
|
605
637
|
* but we don't await server confirmation.
|
|
638
|
+
*
|
|
639
|
+
* When using WebTransport, volatile writes are sent via datagrams (UDP).
|
|
606
640
|
*/
|
|
607
641
|
_sendVolatileSet(path: string, value: unknown): void;
|
|
608
642
|
/**
|
|
@@ -773,4 +807,4 @@ declare function generatePushId(): string;
|
|
|
773
807
|
*/
|
|
774
808
|
declare function isVolatilePath(path: string, patterns: string[] | null | undefined): boolean;
|
|
775
809
|
|
|
776
|
-
export { type AuthInfo, type ConnectOptions, DataSnapshot, DatabaseReference, type EventType, LarkDatabase, LarkError, OnDisconnect, type PendingWrite, PendingWriteManager, type QueryParams, type QueryState, type SnapshotCallback$1 as SnapshotCallback, type TransactionConditionOp, type TransactionDeleteOp, type TransactionObject, type TransactionOp, type TransactionResult, type TransactionSetOp, type TransactionUpdateOp, type WriteOperation, generatePushId, isVolatilePath };
|
|
810
|
+
export { type AuthInfo, type ConnectOptions, DataSnapshot, DatabaseReference, type EventType, LarkDatabase, LarkError, OnDisconnect, type PendingWrite, PendingWriteManager, type QueryParams, type QueryState, type SnapshotCallback$1 as SnapshotCallback, type TransactionConditionOp, type TransactionDeleteOp, type TransactionObject, type TransactionOp, type TransactionResult, type TransactionSetOp, type TransactionUpdateOp, type TransportType, type WriteOperation, generatePushId, isVolatilePath };
|