@lark-sh/client 0.1.7 → 0.1.9
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 +66 -8
- package/dist/index.d.ts +66 -8
- package/dist/index.js +565 -149
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +565 -149
- 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
|
*/
|
|
@@ -89,6 +95,9 @@ declare class DatabaseReference {
|
|
|
89
95
|
child(path: string): DatabaseReference;
|
|
90
96
|
/**
|
|
91
97
|
* Set the data at this location, overwriting any existing data.
|
|
98
|
+
*
|
|
99
|
+
* For volatile paths (high-frequency updates), this is fire-and-forget
|
|
100
|
+
* and resolves immediately without waiting for server confirmation.
|
|
92
101
|
*/
|
|
93
102
|
set(value: unknown): Promise<void>;
|
|
94
103
|
/**
|
|
@@ -113,6 +122,8 @@ declare class DatabaseReference {
|
|
|
113
122
|
update(values: Record<string, unknown>): Promise<void>;
|
|
114
123
|
/**
|
|
115
124
|
* Remove the data at this location.
|
|
125
|
+
*
|
|
126
|
+
* For volatile paths, this is fire-and-forget.
|
|
116
127
|
*/
|
|
117
128
|
remove(): Promise<void>;
|
|
118
129
|
/**
|
|
@@ -331,11 +342,17 @@ interface TxDeleteOp {
|
|
|
331
342
|
o: 'd';
|
|
332
343
|
p: string;
|
|
333
344
|
}
|
|
334
|
-
interface
|
|
345
|
+
interface TxConditionValueOp {
|
|
335
346
|
o: 'c';
|
|
336
347
|
p: string;
|
|
337
348
|
v: unknown;
|
|
338
349
|
}
|
|
350
|
+
interface TxConditionHashOp {
|
|
351
|
+
o: 'c';
|
|
352
|
+
p: string;
|
|
353
|
+
h: string;
|
|
354
|
+
}
|
|
355
|
+
type TxConditionOp = TxConditionValueOp | TxConditionHashOp;
|
|
339
356
|
type TxOperation = TxSetOp | TxUpdateOp | TxDeleteOp | TxConditionOp;
|
|
340
357
|
|
|
341
358
|
/**
|
|
@@ -367,6 +384,13 @@ interface ConnectOptions {
|
|
|
367
384
|
anonymous?: boolean;
|
|
368
385
|
/** Coordinator URL (default: https://db.lark.dev) */
|
|
369
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;
|
|
370
394
|
}
|
|
371
395
|
interface AuthInfo {
|
|
372
396
|
uid: string;
|
|
@@ -407,12 +431,13 @@ declare class LarkDatabase {
|
|
|
407
431
|
private _databaseId;
|
|
408
432
|
private _coordinatorUrl;
|
|
409
433
|
private _volatilePaths;
|
|
434
|
+
private _transportType;
|
|
410
435
|
private _connectionId;
|
|
411
436
|
private _connectOptions;
|
|
412
437
|
private _intentionalDisconnect;
|
|
413
438
|
private _reconnectAttempt;
|
|
414
439
|
private _reconnectTimer;
|
|
415
|
-
private
|
|
440
|
+
private transport;
|
|
416
441
|
private messageQueue;
|
|
417
442
|
private subscriptionManager;
|
|
418
443
|
private pendingWrites;
|
|
@@ -444,9 +469,13 @@ declare class LarkDatabase {
|
|
|
444
469
|
/**
|
|
445
470
|
* Get the volatile path patterns from the server.
|
|
446
471
|
* These patterns indicate which paths should use unreliable transport.
|
|
447
|
-
* WebSocket always uses reliable transport, but this is stored for future UDP support.
|
|
448
472
|
*/
|
|
449
473
|
get volatilePaths(): string[];
|
|
474
|
+
/**
|
|
475
|
+
* Get the current transport type.
|
|
476
|
+
* Returns 'websocket' or 'webtransport', or null if not connected.
|
|
477
|
+
*/
|
|
478
|
+
get transportType(): 'websocket' | 'webtransport' | null;
|
|
450
479
|
/**
|
|
451
480
|
* Check if there are any pending writes waiting for acknowledgment.
|
|
452
481
|
* Useful for showing "saving..." indicators in UI.
|
|
@@ -538,6 +567,7 @@ declare class LarkDatabase {
|
|
|
538
567
|
transaction(operations: TransactionOp[] | TransactionObject): Promise<void>;
|
|
539
568
|
/**
|
|
540
569
|
* Convert a public TransactionOp to wire format TxOperation.
|
|
570
|
+
* Async because condition operations may require hash computation.
|
|
541
571
|
*/
|
|
542
572
|
private convertToTxOp;
|
|
543
573
|
/**
|
|
@@ -587,6 +617,33 @@ declare class LarkDatabase {
|
|
|
587
617
|
* @internal Send a delete operation.
|
|
588
618
|
*/
|
|
589
619
|
_sendDelete(path: string): Promise<void>;
|
|
620
|
+
/**
|
|
621
|
+
* @internal Send a volatile set operation (fire-and-forget).
|
|
622
|
+
*
|
|
623
|
+
* Volatile writes skip:
|
|
624
|
+
* - Recovery checks (volatile paths don't participate in recovery)
|
|
625
|
+
* - Request ID generation (no ack expected)
|
|
626
|
+
* - Pending write tracking (no retry on reconnect)
|
|
627
|
+
* - pw field (no dependency tracking)
|
|
628
|
+
*
|
|
629
|
+
* The write is applied optimistically to local cache for UI feedback,
|
|
630
|
+
* but we don't await server confirmation.
|
|
631
|
+
*
|
|
632
|
+
* When using WebTransport, volatile writes are sent via datagrams (UDP).
|
|
633
|
+
*/
|
|
634
|
+
_sendVolatileSet(path: string, value: unknown): void;
|
|
635
|
+
/**
|
|
636
|
+
* @internal Send a volatile update operation (fire-and-forget).
|
|
637
|
+
*/
|
|
638
|
+
_sendVolatileUpdate(path: string, values: Record<string, unknown>): void;
|
|
639
|
+
/**
|
|
640
|
+
* @internal Send a volatile delete operation (fire-and-forget).
|
|
641
|
+
*/
|
|
642
|
+
_sendVolatileDelete(path: string): void;
|
|
643
|
+
/**
|
|
644
|
+
* Check if a path is a volatile path (high-frequency, fire-and-forget).
|
|
645
|
+
*/
|
|
646
|
+
isVolatilePath(path: string): boolean;
|
|
590
647
|
/**
|
|
591
648
|
* @internal Send a once (read) operation.
|
|
592
649
|
*
|
|
@@ -726,20 +783,21 @@ declare function generatePushId(): string;
|
|
|
726
783
|
* Volatile path matching utilities.
|
|
727
784
|
*
|
|
728
785
|
* Volatile paths are patterns where a wildcard matches exactly one path segment.
|
|
729
|
-
* These paths use unreliable transport for better performance (
|
|
786
|
+
* These paths use unreliable transport for better performance (WebTransport datagrams when available).
|
|
730
787
|
*/
|
|
731
788
|
/**
|
|
732
789
|
* Check if a path matches any of the volatile path patterns.
|
|
733
790
|
*
|
|
734
791
|
* Pattern matching rules:
|
|
735
|
-
* - Wildcard matches exactly one path segment
|
|
792
|
+
* - Wildcard matches exactly one path segment
|
|
736
793
|
* - Patterns and paths are compared segment by segment
|
|
737
|
-
* -
|
|
794
|
+
* - If pattern is exhausted before path, it's still a match (descendant rule)
|
|
795
|
+
* - If path is exhausted before pattern, no match
|
|
738
796
|
*
|
|
739
|
-
* @param path - The path to check
|
|
797
|
+
* @param path - The path to check
|
|
740
798
|
* @param patterns - Array of volatile patterns with wildcards
|
|
741
799
|
* @returns true if the path matches any pattern
|
|
742
800
|
*/
|
|
743
801
|
declare function isVolatilePath(path: string, patterns: string[] | null | undefined): boolean;
|
|
744
802
|
|
|
745
|
-
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 };
|
|
803
|
+
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
|
*/
|
|
@@ -89,6 +95,9 @@ declare class DatabaseReference {
|
|
|
89
95
|
child(path: string): DatabaseReference;
|
|
90
96
|
/**
|
|
91
97
|
* Set the data at this location, overwriting any existing data.
|
|
98
|
+
*
|
|
99
|
+
* For volatile paths (high-frequency updates), this is fire-and-forget
|
|
100
|
+
* and resolves immediately without waiting for server confirmation.
|
|
92
101
|
*/
|
|
93
102
|
set(value: unknown): Promise<void>;
|
|
94
103
|
/**
|
|
@@ -113,6 +122,8 @@ declare class DatabaseReference {
|
|
|
113
122
|
update(values: Record<string, unknown>): Promise<void>;
|
|
114
123
|
/**
|
|
115
124
|
* Remove the data at this location.
|
|
125
|
+
*
|
|
126
|
+
* For volatile paths, this is fire-and-forget.
|
|
116
127
|
*/
|
|
117
128
|
remove(): Promise<void>;
|
|
118
129
|
/**
|
|
@@ -331,11 +342,17 @@ interface TxDeleteOp {
|
|
|
331
342
|
o: 'd';
|
|
332
343
|
p: string;
|
|
333
344
|
}
|
|
334
|
-
interface
|
|
345
|
+
interface TxConditionValueOp {
|
|
335
346
|
o: 'c';
|
|
336
347
|
p: string;
|
|
337
348
|
v: unknown;
|
|
338
349
|
}
|
|
350
|
+
interface TxConditionHashOp {
|
|
351
|
+
o: 'c';
|
|
352
|
+
p: string;
|
|
353
|
+
h: string;
|
|
354
|
+
}
|
|
355
|
+
type TxConditionOp = TxConditionValueOp | TxConditionHashOp;
|
|
339
356
|
type TxOperation = TxSetOp | TxUpdateOp | TxDeleteOp | TxConditionOp;
|
|
340
357
|
|
|
341
358
|
/**
|
|
@@ -367,6 +384,13 @@ interface ConnectOptions {
|
|
|
367
384
|
anonymous?: boolean;
|
|
368
385
|
/** Coordinator URL (default: https://db.lark.dev) */
|
|
369
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;
|
|
370
394
|
}
|
|
371
395
|
interface AuthInfo {
|
|
372
396
|
uid: string;
|
|
@@ -407,12 +431,13 @@ declare class LarkDatabase {
|
|
|
407
431
|
private _databaseId;
|
|
408
432
|
private _coordinatorUrl;
|
|
409
433
|
private _volatilePaths;
|
|
434
|
+
private _transportType;
|
|
410
435
|
private _connectionId;
|
|
411
436
|
private _connectOptions;
|
|
412
437
|
private _intentionalDisconnect;
|
|
413
438
|
private _reconnectAttempt;
|
|
414
439
|
private _reconnectTimer;
|
|
415
|
-
private
|
|
440
|
+
private transport;
|
|
416
441
|
private messageQueue;
|
|
417
442
|
private subscriptionManager;
|
|
418
443
|
private pendingWrites;
|
|
@@ -444,9 +469,13 @@ declare class LarkDatabase {
|
|
|
444
469
|
/**
|
|
445
470
|
* Get the volatile path patterns from the server.
|
|
446
471
|
* These patterns indicate which paths should use unreliable transport.
|
|
447
|
-
* WebSocket always uses reliable transport, but this is stored for future UDP support.
|
|
448
472
|
*/
|
|
449
473
|
get volatilePaths(): string[];
|
|
474
|
+
/**
|
|
475
|
+
* Get the current transport type.
|
|
476
|
+
* Returns 'websocket' or 'webtransport', or null if not connected.
|
|
477
|
+
*/
|
|
478
|
+
get transportType(): 'websocket' | 'webtransport' | null;
|
|
450
479
|
/**
|
|
451
480
|
* Check if there are any pending writes waiting for acknowledgment.
|
|
452
481
|
* Useful for showing "saving..." indicators in UI.
|
|
@@ -538,6 +567,7 @@ declare class LarkDatabase {
|
|
|
538
567
|
transaction(operations: TransactionOp[] | TransactionObject): Promise<void>;
|
|
539
568
|
/**
|
|
540
569
|
* Convert a public TransactionOp to wire format TxOperation.
|
|
570
|
+
* Async because condition operations may require hash computation.
|
|
541
571
|
*/
|
|
542
572
|
private convertToTxOp;
|
|
543
573
|
/**
|
|
@@ -587,6 +617,33 @@ declare class LarkDatabase {
|
|
|
587
617
|
* @internal Send a delete operation.
|
|
588
618
|
*/
|
|
589
619
|
_sendDelete(path: string): Promise<void>;
|
|
620
|
+
/**
|
|
621
|
+
* @internal Send a volatile set operation (fire-and-forget).
|
|
622
|
+
*
|
|
623
|
+
* Volatile writes skip:
|
|
624
|
+
* - Recovery checks (volatile paths don't participate in recovery)
|
|
625
|
+
* - Request ID generation (no ack expected)
|
|
626
|
+
* - Pending write tracking (no retry on reconnect)
|
|
627
|
+
* - pw field (no dependency tracking)
|
|
628
|
+
*
|
|
629
|
+
* The write is applied optimistically to local cache for UI feedback,
|
|
630
|
+
* but we don't await server confirmation.
|
|
631
|
+
*
|
|
632
|
+
* When using WebTransport, volatile writes are sent via datagrams (UDP).
|
|
633
|
+
*/
|
|
634
|
+
_sendVolatileSet(path: string, value: unknown): void;
|
|
635
|
+
/**
|
|
636
|
+
* @internal Send a volatile update operation (fire-and-forget).
|
|
637
|
+
*/
|
|
638
|
+
_sendVolatileUpdate(path: string, values: Record<string, unknown>): void;
|
|
639
|
+
/**
|
|
640
|
+
* @internal Send a volatile delete operation (fire-and-forget).
|
|
641
|
+
*/
|
|
642
|
+
_sendVolatileDelete(path: string): void;
|
|
643
|
+
/**
|
|
644
|
+
* Check if a path is a volatile path (high-frequency, fire-and-forget).
|
|
645
|
+
*/
|
|
646
|
+
isVolatilePath(path: string): boolean;
|
|
590
647
|
/**
|
|
591
648
|
* @internal Send a once (read) operation.
|
|
592
649
|
*
|
|
@@ -726,20 +783,21 @@ declare function generatePushId(): string;
|
|
|
726
783
|
* Volatile path matching utilities.
|
|
727
784
|
*
|
|
728
785
|
* Volatile paths are patterns where a wildcard matches exactly one path segment.
|
|
729
|
-
* These paths use unreliable transport for better performance (
|
|
786
|
+
* These paths use unreliable transport for better performance (WebTransport datagrams when available).
|
|
730
787
|
*/
|
|
731
788
|
/**
|
|
732
789
|
* Check if a path matches any of the volatile path patterns.
|
|
733
790
|
*
|
|
734
791
|
* Pattern matching rules:
|
|
735
|
-
* - Wildcard matches exactly one path segment
|
|
792
|
+
* - Wildcard matches exactly one path segment
|
|
736
793
|
* - Patterns and paths are compared segment by segment
|
|
737
|
-
* -
|
|
794
|
+
* - If pattern is exhausted before path, it's still a match (descendant rule)
|
|
795
|
+
* - If path is exhausted before pattern, no match
|
|
738
796
|
*
|
|
739
|
-
* @param path - The path to check
|
|
797
|
+
* @param path - The path to check
|
|
740
798
|
* @param patterns - Array of volatile patterns with wildcards
|
|
741
799
|
* @returns true if the path matches any pattern
|
|
742
800
|
*/
|
|
743
801
|
declare function isVolatilePath(path: string, patterns: string[] | null | undefined): boolean;
|
|
744
802
|
|
|
745
|
-
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 };
|
|
803
|
+
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 };
|