@lark-sh/client 0.1.16 → 0.1.17
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/{chunk-CYCSP6TZ.mjs → chunk-VLAAYUVX.mjs} +44 -85
- package/dist/chunk-VLAAYUVX.mjs.map +1 -0
- package/dist/fb-v8/index.js +43 -84
- package/dist/fb-v8/index.js.map +1 -1
- package/dist/fb-v8/index.mjs +1 -1
- package/dist/index.d.mts +14 -19
- package/dist/index.d.ts +14 -19
- package/dist/index.js +43 -84
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/dist/chunk-CYCSP6TZ.mjs.map +0 -1
package/dist/fb-v8/index.mjs
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -106,7 +106,6 @@ declare class DatabaseReference {
|
|
|
106
106
|
* For queries (created via orderBy*, limitTo*, startAt, etc.), this returns
|
|
107
107
|
* a reference to the same path without query constraints.
|
|
108
108
|
* For non-query references, this returns the reference itself.
|
|
109
|
-
* This matches Firebase's Query.ref behavior.
|
|
110
109
|
*/
|
|
111
110
|
get ref(): DatabaseReference;
|
|
112
111
|
/**
|
|
@@ -121,12 +120,12 @@ declare class DatabaseReference {
|
|
|
121
120
|
* Returns "default" for non-query references (no constraints).
|
|
122
121
|
* Returns a sorted JSON string of wire-format params for queries.
|
|
123
122
|
*
|
|
124
|
-
*
|
|
123
|
+
* Used for wire protocol and subscription deduplication.
|
|
125
124
|
*/
|
|
126
125
|
get queryIdentifier(): string;
|
|
127
126
|
/**
|
|
128
127
|
* Get the data at this location. Alias for once('value').
|
|
129
|
-
*
|
|
128
|
+
* Alternative to once('value') for reading data.
|
|
130
129
|
*/
|
|
131
130
|
get(): Promise<DataSnapshot>;
|
|
132
131
|
/**
|
|
@@ -145,7 +144,7 @@ declare class DatabaseReference {
|
|
|
145
144
|
/**
|
|
146
145
|
* Update specific children at this location without overwriting other children.
|
|
147
146
|
*
|
|
148
|
-
* Also supports
|
|
147
|
+
* Also supports multi-path updates when keys look like paths
|
|
149
148
|
* (start with '/'). In this mode, each path is written atomically as a transaction.
|
|
150
149
|
*
|
|
151
150
|
* @example
|
|
@@ -201,7 +200,7 @@ declare class DatabaseReference {
|
|
|
201
200
|
* For objects: injects `.priority` into the value object.
|
|
202
201
|
* For primitives: wraps as `{ '.value': primitive, '.priority': priority }`.
|
|
203
202
|
*
|
|
204
|
-
*
|
|
203
|
+
* Uses { '.value': value, '.priority': priority } format for the wire protocol.
|
|
205
204
|
*
|
|
206
205
|
* @param value - The value to write
|
|
207
206
|
* @param priority - The priority for ordering
|
|
@@ -357,7 +356,7 @@ declare class DatabaseReference {
|
|
|
357
356
|
/**
|
|
358
357
|
* A reference that is also a Promise - returned by push().
|
|
359
358
|
*
|
|
360
|
-
* This allows
|
|
359
|
+
* This allows patterns like:
|
|
361
360
|
* ```javascript
|
|
362
361
|
* const pushed = ref.push();
|
|
363
362
|
* console.log(pushed.key); // Key available immediately
|
|
@@ -422,12 +421,10 @@ type TxOperation = TxSetOp | TxUpdateOp | TxDeleteOp | TxConditionOp;
|
|
|
422
421
|
* - Priority is stored as a regular child value `.priority` in the data
|
|
423
422
|
* - val() strips `.priority` from returned objects (so app code doesn't see it)
|
|
424
423
|
* - getPriority() reads from the data's `.priority` field
|
|
425
|
-
* - This matches Firebase behavior where priority is metadata, not user data
|
|
426
424
|
*
|
|
427
425
|
* Wrapped Primitives:
|
|
428
426
|
* - Primitives with priority are stored as `{ '.value': x, '.priority': y }`
|
|
429
427
|
* - val() automatically unwraps these to return just the primitive value
|
|
430
|
-
* - This follows Firebase's wire format for primitives with priority
|
|
431
428
|
*/
|
|
432
429
|
|
|
433
430
|
declare class DataSnapshot {
|
|
@@ -478,9 +475,9 @@ declare class DataSnapshot {
|
|
|
478
475
|
* Get a child snapshot at the specified path.
|
|
479
476
|
*
|
|
480
477
|
* Special handling:
|
|
481
|
-
* - `.priority` returns the priority value
|
|
478
|
+
* - `.priority` returns the priority value
|
|
482
479
|
* - For wrapped primitives, only `.priority` returns data; other paths return null
|
|
483
|
-
* - Non-existent paths return a snapshot with val() === null
|
|
480
|
+
* - Non-existent paths return a snapshot with val() === null
|
|
484
481
|
*/
|
|
485
482
|
child(path: string): DataSnapshot;
|
|
486
483
|
/**
|
|
@@ -516,14 +513,12 @@ declare class DataSnapshot {
|
|
|
516
513
|
getPriority(): number | string | null;
|
|
517
514
|
/**
|
|
518
515
|
* Check if this snapshot was from a volatile (high-frequency) update.
|
|
519
|
-
* This is a Lark extension not present in Firebase.
|
|
520
516
|
*/
|
|
521
517
|
isVolatile(): boolean;
|
|
522
518
|
/**
|
|
523
519
|
* Get the server timestamp for this snapshot (milliseconds since Unix epoch).
|
|
524
520
|
* Only present on volatile value events. Use deltas between timestamps for
|
|
525
521
|
* interpolation rather than absolute times to avoid clock sync issues.
|
|
526
|
-
* This is a Lark extension not present in Firebase.
|
|
527
522
|
*/
|
|
528
523
|
getServerTimestamp(): number | null;
|
|
529
524
|
/**
|
|
@@ -570,8 +565,8 @@ interface ConnectOptions {
|
|
|
570
565
|
token?: string;
|
|
571
566
|
/** Connect anonymously (server assigns a UID) */
|
|
572
567
|
anonymous?: boolean;
|
|
573
|
-
/**
|
|
574
|
-
|
|
568
|
+
/** Lark domain (default: larkdb.net) */
|
|
569
|
+
domain?: string;
|
|
575
570
|
/**
|
|
576
571
|
* Transport type preference.
|
|
577
572
|
* - 'auto': Try WebTransport first, fall back to WebSocket (default)
|
|
@@ -711,7 +706,7 @@ declare class LarkDatabase {
|
|
|
711
706
|
private _state;
|
|
712
707
|
private _auth;
|
|
713
708
|
private _databaseId;
|
|
714
|
-
private
|
|
709
|
+
private _domain;
|
|
715
710
|
private _volatilePaths;
|
|
716
711
|
private _transportType;
|
|
717
712
|
private _currentToken;
|
|
@@ -789,7 +784,7 @@ declare class LarkDatabase {
|
|
|
789
784
|
* Connect to a database.
|
|
790
785
|
*
|
|
791
786
|
* @param databaseId - Database ID in format "project/database"
|
|
792
|
-
* @param options - Connection options (token, anonymous,
|
|
787
|
+
* @param options - Connection options (token, anonymous, domain)
|
|
793
788
|
*/
|
|
794
789
|
connect(databaseId: string, options?: ConnectOptions): Promise<void>;
|
|
795
790
|
/**
|
|
@@ -871,7 +866,7 @@ declare class LarkDatabase {
|
|
|
871
866
|
*
|
|
872
867
|
* Supports two syntaxes:
|
|
873
868
|
*
|
|
874
|
-
* **Object syntax** (
|
|
869
|
+
* **Object syntax** (multi-path update):
|
|
875
870
|
* ```javascript
|
|
876
871
|
* await db.transaction({
|
|
877
872
|
* '/users/alice/name': 'Alice',
|
|
@@ -1145,7 +1140,7 @@ declare class PendingWriteManager {
|
|
|
1145
1140
|
}
|
|
1146
1141
|
|
|
1147
1142
|
/**
|
|
1148
|
-
* Push ID generation -
|
|
1143
|
+
* Push ID generation - chronologically-sortable unique IDs.
|
|
1149
1144
|
*
|
|
1150
1145
|
* Format: 20 characters
|
|
1151
1146
|
* - First 8 chars: timestamp (milliseconds since epoch, base64-encoded)
|
|
@@ -1156,7 +1151,7 @@ declare class PendingWriteManager {
|
|
|
1156
1151
|
* - IDs created in the same millisecond are unique and still sort correctly
|
|
1157
1152
|
*/
|
|
1158
1153
|
/**
|
|
1159
|
-
* Generate a
|
|
1154
|
+
* Generate a unique push ID.
|
|
1160
1155
|
*/
|
|
1161
1156
|
declare function generatePushId(): string;
|
|
1162
1157
|
|
package/dist/index.d.ts
CHANGED
|
@@ -106,7 +106,6 @@ declare class DatabaseReference {
|
|
|
106
106
|
* For queries (created via orderBy*, limitTo*, startAt, etc.), this returns
|
|
107
107
|
* a reference to the same path without query constraints.
|
|
108
108
|
* For non-query references, this returns the reference itself.
|
|
109
|
-
* This matches Firebase's Query.ref behavior.
|
|
110
109
|
*/
|
|
111
110
|
get ref(): DatabaseReference;
|
|
112
111
|
/**
|
|
@@ -121,12 +120,12 @@ declare class DatabaseReference {
|
|
|
121
120
|
* Returns "default" for non-query references (no constraints).
|
|
122
121
|
* Returns a sorted JSON string of wire-format params for queries.
|
|
123
122
|
*
|
|
124
|
-
*
|
|
123
|
+
* Used for wire protocol and subscription deduplication.
|
|
125
124
|
*/
|
|
126
125
|
get queryIdentifier(): string;
|
|
127
126
|
/**
|
|
128
127
|
* Get the data at this location. Alias for once('value').
|
|
129
|
-
*
|
|
128
|
+
* Alternative to once('value') for reading data.
|
|
130
129
|
*/
|
|
131
130
|
get(): Promise<DataSnapshot>;
|
|
132
131
|
/**
|
|
@@ -145,7 +144,7 @@ declare class DatabaseReference {
|
|
|
145
144
|
/**
|
|
146
145
|
* Update specific children at this location without overwriting other children.
|
|
147
146
|
*
|
|
148
|
-
* Also supports
|
|
147
|
+
* Also supports multi-path updates when keys look like paths
|
|
149
148
|
* (start with '/'). In this mode, each path is written atomically as a transaction.
|
|
150
149
|
*
|
|
151
150
|
* @example
|
|
@@ -201,7 +200,7 @@ declare class DatabaseReference {
|
|
|
201
200
|
* For objects: injects `.priority` into the value object.
|
|
202
201
|
* For primitives: wraps as `{ '.value': primitive, '.priority': priority }`.
|
|
203
202
|
*
|
|
204
|
-
*
|
|
203
|
+
* Uses { '.value': value, '.priority': priority } format for the wire protocol.
|
|
205
204
|
*
|
|
206
205
|
* @param value - The value to write
|
|
207
206
|
* @param priority - The priority for ordering
|
|
@@ -357,7 +356,7 @@ declare class DatabaseReference {
|
|
|
357
356
|
/**
|
|
358
357
|
* A reference that is also a Promise - returned by push().
|
|
359
358
|
*
|
|
360
|
-
* This allows
|
|
359
|
+
* This allows patterns like:
|
|
361
360
|
* ```javascript
|
|
362
361
|
* const pushed = ref.push();
|
|
363
362
|
* console.log(pushed.key); // Key available immediately
|
|
@@ -422,12 +421,10 @@ type TxOperation = TxSetOp | TxUpdateOp | TxDeleteOp | TxConditionOp;
|
|
|
422
421
|
* - Priority is stored as a regular child value `.priority` in the data
|
|
423
422
|
* - val() strips `.priority` from returned objects (so app code doesn't see it)
|
|
424
423
|
* - getPriority() reads from the data's `.priority` field
|
|
425
|
-
* - This matches Firebase behavior where priority is metadata, not user data
|
|
426
424
|
*
|
|
427
425
|
* Wrapped Primitives:
|
|
428
426
|
* - Primitives with priority are stored as `{ '.value': x, '.priority': y }`
|
|
429
427
|
* - val() automatically unwraps these to return just the primitive value
|
|
430
|
-
* - This follows Firebase's wire format for primitives with priority
|
|
431
428
|
*/
|
|
432
429
|
|
|
433
430
|
declare class DataSnapshot {
|
|
@@ -478,9 +475,9 @@ declare class DataSnapshot {
|
|
|
478
475
|
* Get a child snapshot at the specified path.
|
|
479
476
|
*
|
|
480
477
|
* Special handling:
|
|
481
|
-
* - `.priority` returns the priority value
|
|
478
|
+
* - `.priority` returns the priority value
|
|
482
479
|
* - For wrapped primitives, only `.priority` returns data; other paths return null
|
|
483
|
-
* - Non-existent paths return a snapshot with val() === null
|
|
480
|
+
* - Non-existent paths return a snapshot with val() === null
|
|
484
481
|
*/
|
|
485
482
|
child(path: string): DataSnapshot;
|
|
486
483
|
/**
|
|
@@ -516,14 +513,12 @@ declare class DataSnapshot {
|
|
|
516
513
|
getPriority(): number | string | null;
|
|
517
514
|
/**
|
|
518
515
|
* Check if this snapshot was from a volatile (high-frequency) update.
|
|
519
|
-
* This is a Lark extension not present in Firebase.
|
|
520
516
|
*/
|
|
521
517
|
isVolatile(): boolean;
|
|
522
518
|
/**
|
|
523
519
|
* Get the server timestamp for this snapshot (milliseconds since Unix epoch).
|
|
524
520
|
* Only present on volatile value events. Use deltas between timestamps for
|
|
525
521
|
* interpolation rather than absolute times to avoid clock sync issues.
|
|
526
|
-
* This is a Lark extension not present in Firebase.
|
|
527
522
|
*/
|
|
528
523
|
getServerTimestamp(): number | null;
|
|
529
524
|
/**
|
|
@@ -570,8 +565,8 @@ interface ConnectOptions {
|
|
|
570
565
|
token?: string;
|
|
571
566
|
/** Connect anonymously (server assigns a UID) */
|
|
572
567
|
anonymous?: boolean;
|
|
573
|
-
/**
|
|
574
|
-
|
|
568
|
+
/** Lark domain (default: larkdb.net) */
|
|
569
|
+
domain?: string;
|
|
575
570
|
/**
|
|
576
571
|
* Transport type preference.
|
|
577
572
|
* - 'auto': Try WebTransport first, fall back to WebSocket (default)
|
|
@@ -711,7 +706,7 @@ declare class LarkDatabase {
|
|
|
711
706
|
private _state;
|
|
712
707
|
private _auth;
|
|
713
708
|
private _databaseId;
|
|
714
|
-
private
|
|
709
|
+
private _domain;
|
|
715
710
|
private _volatilePaths;
|
|
716
711
|
private _transportType;
|
|
717
712
|
private _currentToken;
|
|
@@ -789,7 +784,7 @@ declare class LarkDatabase {
|
|
|
789
784
|
* Connect to a database.
|
|
790
785
|
*
|
|
791
786
|
* @param databaseId - Database ID in format "project/database"
|
|
792
|
-
* @param options - Connection options (token, anonymous,
|
|
787
|
+
* @param options - Connection options (token, anonymous, domain)
|
|
793
788
|
*/
|
|
794
789
|
connect(databaseId: string, options?: ConnectOptions): Promise<void>;
|
|
795
790
|
/**
|
|
@@ -871,7 +866,7 @@ declare class LarkDatabase {
|
|
|
871
866
|
*
|
|
872
867
|
* Supports two syntaxes:
|
|
873
868
|
*
|
|
874
|
-
* **Object syntax** (
|
|
869
|
+
* **Object syntax** (multi-path update):
|
|
875
870
|
* ```javascript
|
|
876
871
|
* await db.transaction({
|
|
877
872
|
* '/users/alice/name': 'Alice',
|
|
@@ -1145,7 +1140,7 @@ declare class PendingWriteManager {
|
|
|
1145
1140
|
}
|
|
1146
1141
|
|
|
1147
1142
|
/**
|
|
1148
|
-
* Push ID generation -
|
|
1143
|
+
* Push ID generation - chronologically-sortable unique IDs.
|
|
1149
1144
|
*
|
|
1150
1145
|
* Format: 20 characters
|
|
1151
1146
|
* - First 8 chars: timestamp (milliseconds since epoch, base64-encoded)
|
|
@@ -1156,7 +1151,7 @@ declare class PendingWriteManager {
|
|
|
1156
1151
|
* - IDs created in the same millisecond are unique and still sort correctly
|
|
1157
1152
|
*/
|
|
1158
1153
|
/**
|
|
1159
|
-
* Generate a
|
|
1154
|
+
* Generate a unique push ID.
|
|
1160
1155
|
*/
|
|
1161
1156
|
declare function generatePushId(): string;
|
|
1162
1157
|
|
package/dist/index.js
CHANGED
|
@@ -43,62 +43,6 @@ __export(index_exports, {
|
|
|
43
43
|
});
|
|
44
44
|
module.exports = __toCommonJS(index_exports);
|
|
45
45
|
|
|
46
|
-
// src/protocol/constants.ts
|
|
47
|
-
var OnDisconnectAction = {
|
|
48
|
-
SET: "s",
|
|
49
|
-
UPDATE: "u",
|
|
50
|
-
DELETE: "d",
|
|
51
|
-
CANCEL: "c"
|
|
52
|
-
};
|
|
53
|
-
var ErrorCode = {
|
|
54
|
-
PERMISSION_DENIED: "permission_denied",
|
|
55
|
-
INVALID_DATA: "invalid_data",
|
|
56
|
-
NOT_FOUND: "not_found",
|
|
57
|
-
INVALID_PATH: "invalid_path",
|
|
58
|
-
INVALID_OPERATION: "invalid_operation",
|
|
59
|
-
INTERNAL_ERROR: "internal_error",
|
|
60
|
-
CONDITION_FAILED: "condition_failed",
|
|
61
|
-
INVALID_QUERY: "invalid_query",
|
|
62
|
-
AUTH_REQUIRED: "auth_required"
|
|
63
|
-
};
|
|
64
|
-
var DEFAULT_COORDINATOR_URL = "https://db.lark.sh";
|
|
65
|
-
|
|
66
|
-
// src/connection/Coordinator.ts
|
|
67
|
-
var Coordinator = class {
|
|
68
|
-
constructor(baseUrl = DEFAULT_COORDINATOR_URL) {
|
|
69
|
-
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Request connection details from the coordinator.
|
|
73
|
-
*
|
|
74
|
-
* @param database - Database ID in format "project/database"
|
|
75
|
-
* @returns Connection details including WebSocket URL and UDP host/port
|
|
76
|
-
*/
|
|
77
|
-
async connect(database) {
|
|
78
|
-
const body = { database };
|
|
79
|
-
const response = await fetch(`${this.baseUrl}/connect`, {
|
|
80
|
-
method: "POST",
|
|
81
|
-
headers: {
|
|
82
|
-
"Content-Type": "application/json"
|
|
83
|
-
},
|
|
84
|
-
body: JSON.stringify(body)
|
|
85
|
-
});
|
|
86
|
-
if (!response.ok) {
|
|
87
|
-
let errorMessage = `Coordinator request failed: ${response.status}`;
|
|
88
|
-
try {
|
|
89
|
-
const errorBody = await response.json();
|
|
90
|
-
if (errorBody.message) {
|
|
91
|
-
errorMessage = errorBody.message;
|
|
92
|
-
}
|
|
93
|
-
} catch {
|
|
94
|
-
}
|
|
95
|
-
throw new Error(errorMessage);
|
|
96
|
-
}
|
|
97
|
-
const data = await response.json();
|
|
98
|
-
return data;
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
|
|
102
46
|
// src/connection/WebSocketTransport.ts
|
|
103
47
|
var import_ws = __toESM(require("ws"));
|
|
104
48
|
var WebSocketImpl = typeof WebSocket !== "undefined" ? WebSocket : import_ws.default;
|
|
@@ -1465,7 +1409,6 @@ var View = class {
|
|
|
1465
1409
|
/**
|
|
1466
1410
|
* Check if this View loads all data (no limits, no range filters).
|
|
1467
1411
|
* A View that loads all data can serve as a "complete" cache for child paths.
|
|
1468
|
-
* This matches Firebase's loadsAllData() semantics.
|
|
1469
1412
|
*/
|
|
1470
1413
|
loadsAllData() {
|
|
1471
1414
|
if (!this.queryParams) return true;
|
|
@@ -1881,8 +1824,8 @@ var SubscriptionManager = class {
|
|
|
1881
1824
|
/**
|
|
1882
1825
|
* Detect and fire child_moved events for children that changed position OR sort value.
|
|
1883
1826
|
*
|
|
1884
|
-
*
|
|
1885
|
-
* the position actually changes.
|
|
1827
|
+
* child_moved fires for ANY priority/sort value change, regardless of whether
|
|
1828
|
+
* the position actually changes.
|
|
1886
1829
|
*
|
|
1887
1830
|
* IMPORTANT: child_moved should only fire for children whose VALUE or PRIORITY changed.
|
|
1888
1831
|
* Children that are merely "displaced" by another child moving should NOT fire child_moved.
|
|
@@ -2085,9 +2028,6 @@ var SubscriptionManager = class {
|
|
|
2085
2028
|
* A complete View has no limits and no range filters, so it contains all data
|
|
2086
2029
|
* for its subtree. Child subscriptions can use the ancestor's data instead
|
|
2087
2030
|
* of creating their own server subscription.
|
|
2088
|
-
*
|
|
2089
|
-
* This matches Firebase's behavior where child listeners don't need their own
|
|
2090
|
-
* server subscription if an ancestor has an unlimited listener.
|
|
2091
2031
|
*/
|
|
2092
2032
|
hasAncestorCompleteView(path) {
|
|
2093
2033
|
const normalized = normalizePath(path);
|
|
@@ -2213,8 +2153,8 @@ var SubscriptionManager = class {
|
|
|
2213
2153
|
/**
|
|
2214
2154
|
* Recursively sort object keys for consistent comparison.
|
|
2215
2155
|
* This ensures {a:1, b:2} and {b:2, a:1} compare as equal.
|
|
2216
|
-
* Uses simple alphabetical sorting
|
|
2217
|
-
*
|
|
2156
|
+
* Uses simple alphabetical sorting since we're just checking data equality,
|
|
2157
|
+
* not display order.
|
|
2218
2158
|
*/
|
|
2219
2159
|
sortKeysForComparison(value) {
|
|
2220
2160
|
if (value === null || typeof value !== "object") {
|
|
@@ -2808,6 +2748,26 @@ var SubscriptionManager = class {
|
|
|
2808
2748
|
}
|
|
2809
2749
|
};
|
|
2810
2750
|
|
|
2751
|
+
// src/protocol/constants.ts
|
|
2752
|
+
var OnDisconnectAction = {
|
|
2753
|
+
SET: "s",
|
|
2754
|
+
UPDATE: "u",
|
|
2755
|
+
DELETE: "d",
|
|
2756
|
+
CANCEL: "c"
|
|
2757
|
+
};
|
|
2758
|
+
var ErrorCode = {
|
|
2759
|
+
PERMISSION_DENIED: "permission_denied",
|
|
2760
|
+
INVALID_DATA: "invalid_data",
|
|
2761
|
+
NOT_FOUND: "not_found",
|
|
2762
|
+
INVALID_PATH: "invalid_path",
|
|
2763
|
+
INVALID_OPERATION: "invalid_operation",
|
|
2764
|
+
INTERNAL_ERROR: "internal_error",
|
|
2765
|
+
CONDITION_FAILED: "condition_failed",
|
|
2766
|
+
INVALID_QUERY: "invalid_query",
|
|
2767
|
+
AUTH_REQUIRED: "auth_required"
|
|
2768
|
+
};
|
|
2769
|
+
var DEFAULT_LARK_DOMAIN = "larkdb.net";
|
|
2770
|
+
|
|
2811
2771
|
// src/OnDisconnect.ts
|
|
2812
2772
|
var OnDisconnect = class {
|
|
2813
2773
|
constructor(db, path) {
|
|
@@ -3105,7 +3065,6 @@ var DatabaseReference = class _DatabaseReference {
|
|
|
3105
3065
|
* For queries (created via orderBy*, limitTo*, startAt, etc.), this returns
|
|
3106
3066
|
* a reference to the same path without query constraints.
|
|
3107
3067
|
* For non-query references, this returns the reference itself.
|
|
3108
|
-
* This matches Firebase's Query.ref behavior.
|
|
3109
3068
|
*/
|
|
3110
3069
|
get ref() {
|
|
3111
3070
|
if (Object.keys(this._query).length === 0) {
|
|
@@ -3130,7 +3089,7 @@ var DatabaseReference = class _DatabaseReference {
|
|
|
3130
3089
|
* Returns "default" for non-query references (no constraints).
|
|
3131
3090
|
* Returns a sorted JSON string of wire-format params for queries.
|
|
3132
3091
|
*
|
|
3133
|
-
*
|
|
3092
|
+
* Used for wire protocol and subscription deduplication.
|
|
3134
3093
|
*/
|
|
3135
3094
|
get queryIdentifier() {
|
|
3136
3095
|
const queryObj = {};
|
|
@@ -3189,7 +3148,7 @@ var DatabaseReference = class _DatabaseReference {
|
|
|
3189
3148
|
}
|
|
3190
3149
|
/**
|
|
3191
3150
|
* Get the data at this location. Alias for once('value').
|
|
3192
|
-
*
|
|
3151
|
+
* Alternative to once('value') for reading data.
|
|
3193
3152
|
*/
|
|
3194
3153
|
async get() {
|
|
3195
3154
|
return this.once("value");
|
|
@@ -3228,7 +3187,7 @@ var DatabaseReference = class _DatabaseReference {
|
|
|
3228
3187
|
/**
|
|
3229
3188
|
* Update specific children at this location without overwriting other children.
|
|
3230
3189
|
*
|
|
3231
|
-
* Also supports
|
|
3190
|
+
* Also supports multi-path updates when keys look like paths
|
|
3232
3191
|
* (start with '/'). In this mode, each path is written atomically as a transaction.
|
|
3233
3192
|
*
|
|
3234
3193
|
* @example
|
|
@@ -3309,7 +3268,7 @@ var DatabaseReference = class _DatabaseReference {
|
|
|
3309
3268
|
* For objects: injects `.priority` into the value object.
|
|
3310
3269
|
* For primitives: wraps as `{ '.value': primitive, '.priority': priority }`.
|
|
3311
3270
|
*
|
|
3312
|
-
*
|
|
3271
|
+
* Uses { '.value': value, '.priority': priority } format for the wire protocol.
|
|
3313
3272
|
*
|
|
3314
3273
|
* @param value - The value to write
|
|
3315
3274
|
* @param priority - The priority for ordering
|
|
@@ -4069,9 +4028,9 @@ var DataSnapshot = class _DataSnapshot {
|
|
|
4069
4028
|
* Get a child snapshot at the specified path.
|
|
4070
4029
|
*
|
|
4071
4030
|
* Special handling:
|
|
4072
|
-
* - `.priority` returns the priority value
|
|
4031
|
+
* - `.priority` returns the priority value
|
|
4073
4032
|
* - For wrapped primitives, only `.priority` returns data; other paths return null
|
|
4074
|
-
* - Non-existent paths return a snapshot with val() === null
|
|
4033
|
+
* - Non-existent paths return a snapshot with val() === null
|
|
4075
4034
|
*/
|
|
4076
4035
|
child(path) {
|
|
4077
4036
|
const childPath = joinPath(this._path, path);
|
|
@@ -4175,7 +4134,6 @@ var DataSnapshot = class _DataSnapshot {
|
|
|
4175
4134
|
}
|
|
4176
4135
|
/**
|
|
4177
4136
|
* Check if this snapshot was from a volatile (high-frequency) update.
|
|
4178
|
-
* This is a Lark extension not present in Firebase.
|
|
4179
4137
|
*/
|
|
4180
4138
|
isVolatile() {
|
|
4181
4139
|
return this._volatile;
|
|
@@ -4184,7 +4142,6 @@ var DataSnapshot = class _DataSnapshot {
|
|
|
4184
4142
|
* Get the server timestamp for this snapshot (milliseconds since Unix epoch).
|
|
4185
4143
|
* Only present on volatile value events. Use deltas between timestamps for
|
|
4186
4144
|
* interpolation rather than absolute times to avoid clock sync issues.
|
|
4187
|
-
* This is a Lark extension not present in Firebase.
|
|
4188
4145
|
*/
|
|
4189
4146
|
getServerTimestamp() {
|
|
4190
4147
|
return this._serverTimestamp;
|
|
@@ -4307,7 +4264,7 @@ var LarkDatabase = class {
|
|
|
4307
4264
|
this._state = "disconnected";
|
|
4308
4265
|
this._auth = null;
|
|
4309
4266
|
this._databaseId = null;
|
|
4310
|
-
this.
|
|
4267
|
+
this._domain = null;
|
|
4311
4268
|
this._volatilePaths = [];
|
|
4312
4269
|
this._transportType = null;
|
|
4313
4270
|
// Auth state
|
|
@@ -4370,8 +4327,9 @@ var LarkDatabase = class {
|
|
|
4370
4327
|
* @internal Get the base URL for reference toString().
|
|
4371
4328
|
*/
|
|
4372
4329
|
_getBaseUrl() {
|
|
4373
|
-
if (this.
|
|
4374
|
-
|
|
4330
|
+
if (this._domain && this._databaseId) {
|
|
4331
|
+
const projectId = this._databaseId.split("/")[0];
|
|
4332
|
+
return `https://${projectId}.${this._domain}`;
|
|
4375
4333
|
}
|
|
4376
4334
|
return "lark://";
|
|
4377
4335
|
}
|
|
@@ -4423,7 +4381,7 @@ var LarkDatabase = class {
|
|
|
4423
4381
|
* Connect to a database.
|
|
4424
4382
|
*
|
|
4425
4383
|
* @param databaseId - Database ID in format "project/database"
|
|
4426
|
-
* @param options - Connection options (token, anonymous,
|
|
4384
|
+
* @param options - Connection options (token, anonymous, domain)
|
|
4427
4385
|
*/
|
|
4428
4386
|
async connect(databaseId, options = {}) {
|
|
4429
4387
|
if (this._state !== "disconnected") {
|
|
@@ -4447,16 +4405,17 @@ var LarkDatabase = class {
|
|
|
4447
4405
|
const previousState = this._state;
|
|
4448
4406
|
this._state = isReconnect ? "reconnecting" : "connecting";
|
|
4449
4407
|
this._databaseId = databaseId;
|
|
4450
|
-
this.
|
|
4408
|
+
this._domain = options.domain || DEFAULT_LARK_DOMAIN;
|
|
4451
4409
|
if (!isReconnect) {
|
|
4452
4410
|
this._currentToken = options.token || "";
|
|
4453
4411
|
this._isAnonymous = !options.token && options.anonymous !== false;
|
|
4454
4412
|
}
|
|
4455
4413
|
try {
|
|
4456
|
-
const
|
|
4457
|
-
|
|
4458
|
-
|
|
4459
|
-
|
|
4414
|
+
const projectId = databaseId.split("/")[0];
|
|
4415
|
+
if (!projectId) {
|
|
4416
|
+
throw new Error('Invalid database ID: must be in format "projectId/databaseName"');
|
|
4417
|
+
}
|
|
4418
|
+
const wsUrl = `wss://${projectId}.${this._domain}/ws`;
|
|
4460
4419
|
const transportResult = await createTransport(
|
|
4461
4420
|
wsUrl,
|
|
4462
4421
|
{
|
|
@@ -4617,7 +4576,7 @@ var LarkDatabase = class {
|
|
|
4617
4576
|
this._auth = null;
|
|
4618
4577
|
this._databaseId = null;
|
|
4619
4578
|
this._volatilePaths = [];
|
|
4620
|
-
this.
|
|
4579
|
+
this._domain = null;
|
|
4621
4580
|
this._connectionId = null;
|
|
4622
4581
|
this._connectOptions = null;
|
|
4623
4582
|
this._transportType = null;
|
|
@@ -4814,7 +4773,7 @@ var LarkDatabase = class {
|
|
|
4814
4773
|
*
|
|
4815
4774
|
* Supports two syntaxes:
|
|
4816
4775
|
*
|
|
4817
|
-
* **Object syntax** (
|
|
4776
|
+
* **Object syntax** (multi-path update):
|
|
4818
4777
|
* ```javascript
|
|
4819
4778
|
* await db.transaction({
|
|
4820
4779
|
* '/users/alice/name': 'Alice',
|