@lark-sh/client 0.1.9 → 0.1.11
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 +361 -58
- package/dist/index.d.ts +361 -58
- package/dist/index.js +1735 -350
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1733 -350
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -59,10 +59,18 @@ interface QueryState {
|
|
|
59
59
|
value: unknown;
|
|
60
60
|
key?: string;
|
|
61
61
|
};
|
|
62
|
+
startAfter?: {
|
|
63
|
+
value: unknown;
|
|
64
|
+
key?: string;
|
|
65
|
+
};
|
|
62
66
|
endAt?: {
|
|
63
67
|
value: unknown;
|
|
64
68
|
key?: string;
|
|
65
69
|
};
|
|
70
|
+
endBefore?: {
|
|
71
|
+
value: unknown;
|
|
72
|
+
key?: string;
|
|
73
|
+
};
|
|
66
74
|
equalTo?: {
|
|
67
75
|
value: unknown;
|
|
68
76
|
key?: string;
|
|
@@ -89,6 +97,38 @@ declare class DatabaseReference {
|
|
|
89
97
|
* Get a reference to the root of the database.
|
|
90
98
|
*/
|
|
91
99
|
get root(): DatabaseReference;
|
|
100
|
+
/**
|
|
101
|
+
* Get the LarkDatabase instance this reference belongs to.
|
|
102
|
+
*/
|
|
103
|
+
get database(): LarkDatabase;
|
|
104
|
+
/**
|
|
105
|
+
* Get the underlying reference for a query.
|
|
106
|
+
* For queries (created via orderBy*, limitTo*, startAt, etc.), this returns
|
|
107
|
+
* a reference to the same path without query constraints.
|
|
108
|
+
* For non-query references, this returns the reference itself.
|
|
109
|
+
* This matches Firebase's Query.ref behavior.
|
|
110
|
+
*/
|
|
111
|
+
get ref(): DatabaseReference;
|
|
112
|
+
/**
|
|
113
|
+
* Check if this reference/query is equal to another.
|
|
114
|
+
* Two references are equal if they have the same database, path, and query constraints.
|
|
115
|
+
*/
|
|
116
|
+
isEqual(other: DatabaseReference | null): boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Get the unique identifier for this query's parameters.
|
|
119
|
+
* Used to differentiate multiple queries on the same path.
|
|
120
|
+
*
|
|
121
|
+
* Returns "default" for non-query references (no constraints).
|
|
122
|
+
* Returns a sorted JSON string of wire-format params for queries.
|
|
123
|
+
*
|
|
124
|
+
* This matches Firebase's queryIdentifier format for wire compatibility.
|
|
125
|
+
*/
|
|
126
|
+
get queryIdentifier(): string;
|
|
127
|
+
/**
|
|
128
|
+
* Get the data at this location. Alias for once('value').
|
|
129
|
+
* This is Firebase's newer API for reading data.
|
|
130
|
+
*/
|
|
131
|
+
get(): Promise<DataSnapshot>;
|
|
92
132
|
/**
|
|
93
133
|
* Get a reference to a child path.
|
|
94
134
|
*/
|
|
@@ -98,6 +138,8 @@ declare class DatabaseReference {
|
|
|
98
138
|
*
|
|
99
139
|
* For volatile paths (high-frequency updates), this is fire-and-forget
|
|
100
140
|
* and resolves immediately without waiting for server confirmation.
|
|
141
|
+
*
|
|
142
|
+
* @param value - The value to write
|
|
101
143
|
*/
|
|
102
144
|
set(value: unknown): Promise<void>;
|
|
103
145
|
/**
|
|
@@ -118,6 +160,8 @@ declare class DatabaseReference {
|
|
|
118
160
|
* '/leaderboard/alice': null // null = delete
|
|
119
161
|
* });
|
|
120
162
|
* ```
|
|
163
|
+
*
|
|
164
|
+
* @param values - The values to update
|
|
121
165
|
*/
|
|
122
166
|
update(values: Record<string, unknown>): Promise<void>;
|
|
123
167
|
/**
|
|
@@ -129,16 +173,38 @@ declare class DatabaseReference {
|
|
|
129
173
|
/**
|
|
130
174
|
* Generate a new child location with a unique key and optionally set its value.
|
|
131
175
|
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
176
|
+
* Returns a ThenableReference - an object that is both a DatabaseReference
|
|
177
|
+
* AND a Promise. You can access reference properties immediately (like `.key`)
|
|
178
|
+
* and also await the result.
|
|
134
179
|
*
|
|
135
|
-
* If
|
|
136
|
-
*
|
|
180
|
+
* If value is provided, the promise resolves after the write completes.
|
|
181
|
+
* If no value is provided, the promise resolves immediately.
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```javascript
|
|
185
|
+
* // Without value - returns ThenableReference, resolves immediately
|
|
186
|
+
* const pushed = ref.push();
|
|
187
|
+
* console.log(pushed.key); // "-Abc123..." (available immediately)
|
|
188
|
+
* await pushed; // Resolves immediately to the same reference
|
|
189
|
+
*
|
|
190
|
+
* // With value - returns ThenableReference, resolves after write
|
|
191
|
+
* const pushed2 = ref.push({ name: 'Alice' });
|
|
192
|
+
* console.log(pushed2.key); // "-Xyz789..." (available immediately)
|
|
193
|
+
* await pushed2; // Waits for write to complete
|
|
194
|
+
* ```
|
|
137
195
|
*/
|
|
138
|
-
push(
|
|
196
|
+
push(): ThenableReference;
|
|
197
|
+
push(value: unknown): ThenableReference;
|
|
139
198
|
/**
|
|
140
199
|
* Set the data with a priority value for ordering.
|
|
141
|
-
*
|
|
200
|
+
*
|
|
201
|
+
* For objects: injects `.priority` into the value object.
|
|
202
|
+
* For primitives: wraps as `{ '.value': primitive, '.priority': priority }`.
|
|
203
|
+
*
|
|
204
|
+
* This follows Firebase's wire format for primitives with priority.
|
|
205
|
+
*
|
|
206
|
+
* @param value - The value to write
|
|
207
|
+
* @param priority - The priority for ordering
|
|
142
208
|
*/
|
|
143
209
|
setWithPriority(value: unknown, priority: number | string): Promise<void>;
|
|
144
210
|
/**
|
|
@@ -168,9 +234,12 @@ declare class DatabaseReference {
|
|
|
168
234
|
* @param maxRetries - Maximum number of retries (default: 25)
|
|
169
235
|
* @returns TransactionResult with committed status and final snapshot
|
|
170
236
|
*/
|
|
171
|
-
transaction(updateFunction: (currentValue:
|
|
237
|
+
transaction(updateFunction: (currentValue: any) => any, maxRetries?: number): Promise<TransactionResult>;
|
|
172
238
|
/**
|
|
173
239
|
* Read the data at this location once.
|
|
240
|
+
*
|
|
241
|
+
* @param eventType - The event type (only 'value' is supported)
|
|
242
|
+
* @returns Promise that resolves to the DataSnapshot
|
|
174
243
|
*/
|
|
175
244
|
once(eventType?: 'value'): Promise<DataSnapshot>;
|
|
176
245
|
/**
|
|
@@ -180,8 +249,14 @@ declare class DatabaseReference {
|
|
|
180
249
|
on(eventType: EventType, callback: SnapshotCallback$1): () => void;
|
|
181
250
|
/**
|
|
182
251
|
* Unsubscribe from events.
|
|
183
|
-
*
|
|
184
|
-
*
|
|
252
|
+
*
|
|
253
|
+
* - `off()` - removes ALL listeners at this path
|
|
254
|
+
* - `off('value')` - removes all 'value' listeners at this path
|
|
255
|
+
*
|
|
256
|
+
* Note: To unsubscribe a specific callback, use the unsubscribe function
|
|
257
|
+
* returned by `on()`.
|
|
258
|
+
*
|
|
259
|
+
* @param eventType - Optional event type to unsubscribe from
|
|
185
260
|
*/
|
|
186
261
|
off(eventType?: EventType): void;
|
|
187
262
|
/**
|
|
@@ -214,16 +289,52 @@ declare class DatabaseReference {
|
|
|
214
289
|
limitToLast(limit: number): DatabaseReference;
|
|
215
290
|
/**
|
|
216
291
|
* Start at a specific value/key.
|
|
292
|
+
* If no value is provided, starts at the beginning (null priority).
|
|
217
293
|
*/
|
|
218
|
-
startAt(value
|
|
294
|
+
startAt(value?: unknown, key?: string): DatabaseReference;
|
|
295
|
+
/**
|
|
296
|
+
* Start after a specific value/key (exclusive).
|
|
297
|
+
* Like startAt() but excludes the starting point.
|
|
298
|
+
*/
|
|
299
|
+
startAfter(value?: unknown, key?: string): DatabaseReference;
|
|
219
300
|
/**
|
|
220
301
|
* End at a specific value/key.
|
|
302
|
+
* If no value is provided, ends at the end (null priority).
|
|
303
|
+
*/
|
|
304
|
+
endAt(value?: unknown, key?: string): DatabaseReference;
|
|
305
|
+
/**
|
|
306
|
+
* End before a specific value/key (exclusive).
|
|
307
|
+
* Like endAt() but excludes the ending point.
|
|
221
308
|
*/
|
|
222
|
-
|
|
309
|
+
endBefore(value?: unknown, key?: string): DatabaseReference;
|
|
223
310
|
/**
|
|
224
311
|
* Filter to items equal to a specific value.
|
|
225
312
|
*/
|
|
226
313
|
equalTo(value: unknown, key?: string): DatabaseReference;
|
|
314
|
+
/**
|
|
315
|
+
* Validate that no orderBy has been set yet.
|
|
316
|
+
*/
|
|
317
|
+
private _validateNoOrderBy;
|
|
318
|
+
/**
|
|
319
|
+
* Validate that no key parameter has been set on startAt/endAt/equalTo.
|
|
320
|
+
* Used when calling orderByKey() after startAt/endAt/equalTo.
|
|
321
|
+
*/
|
|
322
|
+
private _validateNoKeyParameterForOrderByKey;
|
|
323
|
+
/**
|
|
324
|
+
* Validate that startAt/endAt/equalTo values are strings.
|
|
325
|
+
* Used when calling orderByKey() after startAt/endAt/equalTo.
|
|
326
|
+
*/
|
|
327
|
+
private _validateStringValuesForOrderByKey;
|
|
328
|
+
/**
|
|
329
|
+
* Validate value and key types for query methods (startAt, endAt, equalTo, etc.)
|
|
330
|
+
*/
|
|
331
|
+
private _validateQueryValue;
|
|
332
|
+
/**
|
|
333
|
+
* Validate that a key is a valid Firebase key format.
|
|
334
|
+
* Invalid characters: . $ # [ ] /
|
|
335
|
+
* Also cannot start or end with .
|
|
336
|
+
*/
|
|
337
|
+
private _validateKeyFormat;
|
|
227
338
|
/**
|
|
228
339
|
* Build query parameters for wire protocol.
|
|
229
340
|
*/
|
|
@@ -234,6 +345,65 @@ declare class DatabaseReference {
|
|
|
234
345
|
*/
|
|
235
346
|
toString(): string;
|
|
236
347
|
}
|
|
348
|
+
/**
|
|
349
|
+
* A reference that is also a Promise - returned by push().
|
|
350
|
+
*
|
|
351
|
+
* This allows Firebase-compatible patterns like:
|
|
352
|
+
* ```javascript
|
|
353
|
+
* const pushed = ref.push();
|
|
354
|
+
* console.log(pushed.key); // Key available immediately
|
|
355
|
+
* await pushed; // Wait for write to complete
|
|
356
|
+
* ```
|
|
357
|
+
*/
|
|
358
|
+
declare class ThenableReference extends DatabaseReference implements PromiseLike<DatabaseReference> {
|
|
359
|
+
private readonly _promise;
|
|
360
|
+
constructor(db: LarkDatabase, path: string, promise?: Promise<DatabaseReference>);
|
|
361
|
+
then<TResult1 = DatabaseReference, TResult2 = never>(onfulfilled?: ((value: DatabaseReference) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;
|
|
362
|
+
catch<TResult = never>(onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | undefined | null): Promise<DatabaseReference | TResult>;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
interface QueryParams {
|
|
366
|
+
orderBy?: 'key' | 'priority' | 'child' | 'value';
|
|
367
|
+
orderByChild?: string;
|
|
368
|
+
limitToFirst?: number;
|
|
369
|
+
limitToLast?: number;
|
|
370
|
+
startAt?: unknown;
|
|
371
|
+
startAtKey?: string;
|
|
372
|
+
startAfter?: unknown;
|
|
373
|
+
startAfterKey?: string;
|
|
374
|
+
endAt?: unknown;
|
|
375
|
+
endAtKey?: string;
|
|
376
|
+
endBefore?: unknown;
|
|
377
|
+
endBeforeKey?: string;
|
|
378
|
+
equalTo?: unknown;
|
|
379
|
+
equalToKey?: string;
|
|
380
|
+
}
|
|
381
|
+
interface TxSetOp {
|
|
382
|
+
o: 's';
|
|
383
|
+
p: string;
|
|
384
|
+
v: unknown;
|
|
385
|
+
}
|
|
386
|
+
interface TxUpdateOp {
|
|
387
|
+
o: 'u';
|
|
388
|
+
p: string;
|
|
389
|
+
v: Record<string, unknown>;
|
|
390
|
+
}
|
|
391
|
+
interface TxDeleteOp {
|
|
392
|
+
o: 'd';
|
|
393
|
+
p: string;
|
|
394
|
+
}
|
|
395
|
+
interface TxConditionValueOp {
|
|
396
|
+
o: 'c';
|
|
397
|
+
p: string;
|
|
398
|
+
v: unknown;
|
|
399
|
+
}
|
|
400
|
+
interface TxConditionHashOp {
|
|
401
|
+
o: 'c';
|
|
402
|
+
p: string;
|
|
403
|
+
h: string;
|
|
404
|
+
}
|
|
405
|
+
type TxConditionOp = TxConditionValueOp | TxConditionHashOp;
|
|
406
|
+
type TxOperation = TxSetOp | TxUpdateOp | TxDeleteOp | TxConditionOp;
|
|
237
407
|
|
|
238
408
|
/**
|
|
239
409
|
* DataSnapshot - an immutable snapshot of data at a location.
|
|
@@ -244,6 +414,11 @@ declare class DatabaseReference {
|
|
|
244
414
|
* - val() strips `.priority` from returned objects (so app code doesn't see it)
|
|
245
415
|
* - getPriority() reads from the data's `.priority` field
|
|
246
416
|
* - This matches Firebase behavior where priority is metadata, not user data
|
|
417
|
+
*
|
|
418
|
+
* Wrapped Primitives:
|
|
419
|
+
* - Primitives with priority are stored as `{ '.value': x, '.priority': y }`
|
|
420
|
+
* - val() automatically unwraps these to return just the primitive value
|
|
421
|
+
* - This follows Firebase's wire format for primitives with priority
|
|
247
422
|
*/
|
|
248
423
|
|
|
249
424
|
declare class DataSnapshot {
|
|
@@ -252,9 +427,13 @@ declare class DataSnapshot {
|
|
|
252
427
|
private readonly _db;
|
|
253
428
|
private readonly _volatile;
|
|
254
429
|
private readonly _serverTimestamp;
|
|
430
|
+
private readonly _queryParams;
|
|
431
|
+
private readonly _orderedKeys;
|
|
255
432
|
constructor(data: unknown, path: string, db: LarkDatabase, options?: {
|
|
256
433
|
volatile?: boolean;
|
|
257
434
|
serverTimestamp?: number | null;
|
|
435
|
+
queryParams?: QueryParams | null;
|
|
436
|
+
orderedKeys?: string[] | null;
|
|
258
437
|
});
|
|
259
438
|
/**
|
|
260
439
|
* Get a DatabaseReference for the location of this snapshot.
|
|
@@ -265,32 +444,59 @@ declare class DataSnapshot {
|
|
|
265
444
|
*/
|
|
266
445
|
get key(): string | null;
|
|
267
446
|
/**
|
|
268
|
-
* Get the data value, with
|
|
269
|
-
*
|
|
447
|
+
* Get the data value, with metadata stripped.
|
|
448
|
+
*
|
|
449
|
+
* - Strips `.priority` from objects (it's metadata, not user data)
|
|
450
|
+
* - Unwraps `{ '.value': x, '.priority': y }` to just `x` (wrapped primitives)
|
|
451
|
+
*
|
|
452
|
+
* @typeParam T - Optional type for the returned value. Defaults to `any`.
|
|
453
|
+
* @example
|
|
454
|
+
* ```typescript
|
|
455
|
+
* // Untyped (returns any)
|
|
456
|
+
* const data = snapshot.val();
|
|
457
|
+
*
|
|
458
|
+
* // Typed (returns User)
|
|
459
|
+
* const user = snapshot.val<User>();
|
|
460
|
+
* ```
|
|
270
461
|
*/
|
|
271
|
-
val():
|
|
462
|
+
val<T = any>(): T;
|
|
272
463
|
/**
|
|
273
464
|
* Check if data exists at this location (is not null/undefined).
|
|
274
465
|
*/
|
|
275
466
|
exists(): boolean;
|
|
276
467
|
/**
|
|
277
468
|
* Get a child snapshot at the specified path.
|
|
469
|
+
*
|
|
470
|
+
* Special handling:
|
|
471
|
+
* - `.priority` returns the priority value (Firebase compatible)
|
|
472
|
+
* - For wrapped primitives, only `.priority` returns data; other paths return null
|
|
473
|
+
* - Non-existent paths return a snapshot with val() === null (Firebase compatible)
|
|
278
474
|
*/
|
|
279
475
|
child(path: string): DataSnapshot;
|
|
280
476
|
/**
|
|
281
477
|
* Check if this snapshot has any children.
|
|
478
|
+
* Excludes `.priority` metadata from consideration.
|
|
479
|
+
* Wrapped primitives have no children.
|
|
282
480
|
*/
|
|
283
481
|
hasChildren(): boolean;
|
|
284
482
|
/**
|
|
285
483
|
* Check if this snapshot has a specific child.
|
|
484
|
+
* `.priority` is always accessible if it exists.
|
|
485
|
+
* Wrapped primitives have no children except `.priority`.
|
|
286
486
|
*/
|
|
287
487
|
hasChild(path: string): boolean;
|
|
288
488
|
/**
|
|
289
489
|
* Get the number of children.
|
|
490
|
+
* Excludes `.priority` metadata from count.
|
|
491
|
+
* Wrapped primitives have 0 children.
|
|
290
492
|
*/
|
|
291
493
|
numChildren(): number;
|
|
292
494
|
/**
|
|
293
|
-
* Iterate over children
|
|
495
|
+
* Iterate over children in the correct order.
|
|
496
|
+
* Uses pre-computed orderedKeys if available (from subscription View),
|
|
497
|
+
* otherwise computes sorted keys based on query params.
|
|
498
|
+
* Excludes `.priority` metadata from iteration.
|
|
499
|
+
* Wrapped primitives have no children to iterate.
|
|
294
500
|
*/
|
|
295
501
|
forEach(callback: (child: DataSnapshot) => boolean | void): void;
|
|
296
502
|
/**
|
|
@@ -311,49 +517,21 @@ declare class DataSnapshot {
|
|
|
311
517
|
*/
|
|
312
518
|
getServerTimestamp(): number | null;
|
|
313
519
|
/**
|
|
314
|
-
* Export the snapshot data
|
|
520
|
+
* Export the snapshot data with priority metadata intact.
|
|
521
|
+
* Unlike val(), this preserves `.value` and `.priority` wrappers.
|
|
522
|
+
* Useful for serializing data while preserving priorities.
|
|
523
|
+
*
|
|
524
|
+
* @typeParam T - Optional type for the returned value. Defaults to `any`.
|
|
315
525
|
*/
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
startAt?: unknown;
|
|
325
|
-
startAtKey?: string;
|
|
326
|
-
endAt?: unknown;
|
|
327
|
-
endAtKey?: string;
|
|
328
|
-
equalTo?: unknown;
|
|
329
|
-
equalToKey?: string;
|
|
330
|
-
}
|
|
331
|
-
interface TxSetOp {
|
|
332
|
-
o: 's';
|
|
333
|
-
p: string;
|
|
334
|
-
v: unknown;
|
|
335
|
-
}
|
|
336
|
-
interface TxUpdateOp {
|
|
337
|
-
o: 'u';
|
|
338
|
-
p: string;
|
|
339
|
-
v: Record<string, unknown>;
|
|
340
|
-
}
|
|
341
|
-
interface TxDeleteOp {
|
|
342
|
-
o: 'd';
|
|
343
|
-
p: string;
|
|
344
|
-
}
|
|
345
|
-
interface TxConditionValueOp {
|
|
346
|
-
o: 'c';
|
|
347
|
-
p: string;
|
|
348
|
-
v: unknown;
|
|
349
|
-
}
|
|
350
|
-
interface TxConditionHashOp {
|
|
351
|
-
o: 'c';
|
|
352
|
-
p: string;
|
|
353
|
-
h: string;
|
|
526
|
+
exportVal<T = any>(): T;
|
|
527
|
+
/**
|
|
528
|
+
* Export the snapshot data as JSON.
|
|
529
|
+
* Same as exportVal() - preserves priority metadata.
|
|
530
|
+
*
|
|
531
|
+
* @typeParam T - Optional type for the returned value. Defaults to `any`.
|
|
532
|
+
*/
|
|
533
|
+
toJSON<T = any>(): T;
|
|
354
534
|
}
|
|
355
|
-
type TxConditionOp = TxConditionValueOp | TxConditionHashOp;
|
|
356
|
-
type TxOperation = TxSetOp | TxUpdateOp | TxDeleteOp | TxConditionOp;
|
|
357
535
|
|
|
358
536
|
/**
|
|
359
537
|
* View - represents a client's subscription to a database path.
|
|
@@ -391,6 +569,13 @@ interface ConnectOptions {
|
|
|
391
569
|
* - 'webtransport': Force WebTransport only (fails if unavailable)
|
|
392
570
|
*/
|
|
393
571
|
transport?: TransportType;
|
|
572
|
+
/**
|
|
573
|
+
* Timeout for WebTransport connection attempt in milliseconds.
|
|
574
|
+
* If WebTransport doesn't connect within this time, falls back to WebSocket.
|
|
575
|
+
* Only applies when transport is 'auto'.
|
|
576
|
+
* Default: 2000 (2 seconds)
|
|
577
|
+
*/
|
|
578
|
+
webtransportTimeout?: number;
|
|
394
579
|
}
|
|
395
580
|
interface AuthInfo {
|
|
396
581
|
uid: string;
|
|
@@ -425,7 +610,85 @@ type TransactionOp = TransactionSetOp | TransactionUpdateOp | TransactionDeleteO
|
|
|
425
610
|
/** Object syntax for transactions: path -> value (null = delete) */
|
|
426
611
|
type TransactionObject = Record<string, unknown>;
|
|
427
612
|
type ConnectionState = 'disconnected' | 'connecting' | 'connected' | 'reconnecting';
|
|
613
|
+
/**
|
|
614
|
+
* Server values that are resolved by the server when a write is committed.
|
|
615
|
+
* Use these with set(), update(), or push() to have the server fill in values.
|
|
616
|
+
*/
|
|
617
|
+
declare const ServerValue: {
|
|
618
|
+
/**
|
|
619
|
+
* A placeholder value for auto-populating the current server timestamp.
|
|
620
|
+
* The server will replace this with the actual Unix timestamp in milliseconds.
|
|
621
|
+
*
|
|
622
|
+
* @example
|
|
623
|
+
* ```javascript
|
|
624
|
+
* import { ServerValue } from '@lark-sh/client';
|
|
625
|
+
* await ref.set({ createdAt: ServerValue.TIMESTAMP });
|
|
626
|
+
* // Server stores: { createdAt: 1704067200000 }
|
|
627
|
+
* ```
|
|
628
|
+
*/
|
|
629
|
+
TIMESTAMP: {
|
|
630
|
+
readonly '.sv': "timestamp";
|
|
631
|
+
};
|
|
632
|
+
/**
|
|
633
|
+
* Returns a placeholder value for atomically incrementing a numeric field.
|
|
634
|
+
* If the field doesn't exist or isn't a number, it's treated as 0.
|
|
635
|
+
*
|
|
636
|
+
* @param delta - The amount to increment by (can be negative to decrement)
|
|
637
|
+
* @returns A server value placeholder
|
|
638
|
+
*
|
|
639
|
+
* @example
|
|
640
|
+
* ```javascript
|
|
641
|
+
* import { ServerValue } from '@lark-sh/client';
|
|
642
|
+
* await ref.child('score').set(ServerValue.increment(10));
|
|
643
|
+
* // Atomically adds 10 to the current score
|
|
644
|
+
* ```
|
|
645
|
+
*/
|
|
646
|
+
increment: (delta: number) => {
|
|
647
|
+
'.sv': {
|
|
648
|
+
increment: number;
|
|
649
|
+
};
|
|
650
|
+
};
|
|
651
|
+
};
|
|
428
652
|
declare class LarkDatabase {
|
|
653
|
+
/**
|
|
654
|
+
* Server values that are resolved by the server when a write is committed.
|
|
655
|
+
* Alias for the exported ServerValue object.
|
|
656
|
+
*/
|
|
657
|
+
static ServerValue: {
|
|
658
|
+
/**
|
|
659
|
+
* A placeholder value for auto-populating the current server timestamp.
|
|
660
|
+
* The server will replace this with the actual Unix timestamp in milliseconds.
|
|
661
|
+
*
|
|
662
|
+
* @example
|
|
663
|
+
* ```javascript
|
|
664
|
+
* import { ServerValue } from '@lark-sh/client';
|
|
665
|
+
* await ref.set({ createdAt: ServerValue.TIMESTAMP });
|
|
666
|
+
* // Server stores: { createdAt: 1704067200000 }
|
|
667
|
+
* ```
|
|
668
|
+
*/
|
|
669
|
+
TIMESTAMP: {
|
|
670
|
+
readonly '.sv': "timestamp";
|
|
671
|
+
};
|
|
672
|
+
/**
|
|
673
|
+
* Returns a placeholder value for atomically incrementing a numeric field.
|
|
674
|
+
* If the field doesn't exist or isn't a number, it's treated as 0.
|
|
675
|
+
*
|
|
676
|
+
* @param delta - The amount to increment by (can be negative to decrement)
|
|
677
|
+
* @returns A server value placeholder
|
|
678
|
+
*
|
|
679
|
+
* @example
|
|
680
|
+
* ```javascript
|
|
681
|
+
* import { ServerValue } from '@lark-sh/client';
|
|
682
|
+
* await ref.child('score').set(ServerValue.increment(10));
|
|
683
|
+
* // Atomically adds 10 to the current score
|
|
684
|
+
* ```
|
|
685
|
+
*/
|
|
686
|
+
increment: (delta: number) => {
|
|
687
|
+
'.sv': {
|
|
688
|
+
increment: number;
|
|
689
|
+
};
|
|
690
|
+
};
|
|
691
|
+
};
|
|
429
692
|
private _state;
|
|
430
693
|
private _auth;
|
|
431
694
|
private _databaseId;
|
|
@@ -445,6 +708,8 @@ declare class LarkDatabase {
|
|
|
445
708
|
private disconnectCallbacks;
|
|
446
709
|
private errorCallbacks;
|
|
447
710
|
private reconnectingCallbacks;
|
|
711
|
+
private infoSubscriptions;
|
|
712
|
+
private _serverTimeOffset;
|
|
448
713
|
constructor();
|
|
449
714
|
/**
|
|
450
715
|
* Whether the database is currently connected.
|
|
@@ -476,6 +741,11 @@ declare class LarkDatabase {
|
|
|
476
741
|
* Returns 'websocket' or 'webtransport', or null if not connected.
|
|
477
742
|
*/
|
|
478
743
|
get transportType(): 'websocket' | 'webtransport' | null;
|
|
744
|
+
/**
|
|
745
|
+
* Get the estimated server time offset in milliseconds.
|
|
746
|
+
* Add this to Date.now() to get approximate server time.
|
|
747
|
+
*/
|
|
748
|
+
get serverTimeOffset(): number;
|
|
479
749
|
/**
|
|
480
750
|
* Check if there are any pending writes waiting for acknowledgment.
|
|
481
751
|
* Useful for showing "saving..." indicators in UI.
|
|
@@ -506,6 +776,16 @@ declare class LarkDatabase {
|
|
|
506
776
|
* This triggers onDisconnect hooks on the server.
|
|
507
777
|
*/
|
|
508
778
|
disconnect(): Promise<void>;
|
|
779
|
+
/**
|
|
780
|
+
* Temporarily disable the connection.
|
|
781
|
+
* Disconnects from the server but preserves subscriptions for later reconnection via goOnline().
|
|
782
|
+
*/
|
|
783
|
+
goOffline(): void;
|
|
784
|
+
/**
|
|
785
|
+
* Re-enable the connection after goOffline().
|
|
786
|
+
* Reconnects to the database and restores subscriptions.
|
|
787
|
+
*/
|
|
788
|
+
goOnline(): void;
|
|
509
789
|
/**
|
|
510
790
|
* Full cleanup - clears all state including subscriptions.
|
|
511
791
|
* Used for intentional disconnect.
|
|
@@ -516,6 +796,27 @@ declare class LarkDatabase {
|
|
|
516
796
|
* Used for unexpected disconnect.
|
|
517
797
|
*/
|
|
518
798
|
private cleanupForReconnect;
|
|
799
|
+
/**
|
|
800
|
+
* Check if a path is a .info path (handled locally).
|
|
801
|
+
*/
|
|
802
|
+
private isInfoPath;
|
|
803
|
+
/**
|
|
804
|
+
* Get the current value for a .info path.
|
|
805
|
+
*/
|
|
806
|
+
private getInfoValue;
|
|
807
|
+
/**
|
|
808
|
+
* Subscribe to a .info path.
|
|
809
|
+
* Returns an unsubscribe function.
|
|
810
|
+
*/
|
|
811
|
+
private subscribeToInfo;
|
|
812
|
+
/**
|
|
813
|
+
* Fire events for .info path changes.
|
|
814
|
+
*/
|
|
815
|
+
private fireInfoEvents;
|
|
816
|
+
/**
|
|
817
|
+
* Fire connection state change events to .info/connected subscribers.
|
|
818
|
+
*/
|
|
819
|
+
private fireConnectionStateChange;
|
|
519
820
|
/**
|
|
520
821
|
* Schedule a reconnection attempt with exponential backoff.
|
|
521
822
|
*/
|
|
@@ -663,10 +964,12 @@ declare class LarkDatabase {
|
|
|
663
964
|
_sendOnDisconnect(path: string, action: string, value?: unknown): Promise<void>;
|
|
664
965
|
/**
|
|
665
966
|
* @internal Send a subscribe message to server.
|
|
967
|
+
* Includes tag for non-default queries to enable proper event routing.
|
|
666
968
|
*/
|
|
667
969
|
private sendSubscribeMessage;
|
|
668
970
|
/**
|
|
669
971
|
* @internal Send an unsubscribe message to server.
|
|
972
|
+
* Includes query params and tag so server can identify which specific subscription to remove.
|
|
670
973
|
*/
|
|
671
974
|
private sendUnsubscribeMessage;
|
|
672
975
|
/**
|
|
@@ -676,7 +979,7 @@ declare class LarkDatabase {
|
|
|
676
979
|
/**
|
|
677
980
|
* @internal Subscribe to events at a path.
|
|
678
981
|
*/
|
|
679
|
-
_subscribe(path: string, eventType: EventType, callback: SnapshotCallback, queryParams?: QueryParams): () => void;
|
|
982
|
+
_subscribe(path: string, eventType: EventType, callback: SnapshotCallback, queryParams?: QueryParams, queryIdentifier?: string): () => void;
|
|
680
983
|
/**
|
|
681
984
|
* @internal Unsubscribe from a specific event type at a path.
|
|
682
985
|
*/
|
|
@@ -800,4 +1103,4 @@ declare function generatePushId(): string;
|
|
|
800
1103
|
*/
|
|
801
1104
|
declare function isVolatilePath(path: string, patterns: string[] | null | undefined): boolean;
|
|
802
1105
|
|
|
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 };
|
|
1106
|
+
export { type AuthInfo, type ConnectOptions, DataSnapshot, DatabaseReference, type EventType, LarkDatabase, LarkError, OnDisconnect, type PendingWrite, PendingWriteManager, type QueryParams, type QueryState, ServerValue, type SnapshotCallback$1 as SnapshotCallback, ThenableReference, type TransactionConditionOp, type TransactionDeleteOp, type TransactionObject, type TransactionOp, type TransactionResult, type TransactionSetOp, type TransactionUpdateOp, type TransportType, type WriteOperation, generatePushId, isVolatilePath };
|