@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.js
CHANGED
|
@@ -43,62 +43,6 @@ __export(fb_v8_exports, {
|
|
|
43
43
|
});
|
|
44
44
|
module.exports = __toCommonJS(fb_v8_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',
|