@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.
@@ -1,59 +1,3 @@
1
- // src/protocol/constants.ts
2
- var OnDisconnectAction = {
3
- SET: "s",
4
- UPDATE: "u",
5
- DELETE: "d",
6
- CANCEL: "c"
7
- };
8
- var ErrorCode = {
9
- PERMISSION_DENIED: "permission_denied",
10
- INVALID_DATA: "invalid_data",
11
- NOT_FOUND: "not_found",
12
- INVALID_PATH: "invalid_path",
13
- INVALID_OPERATION: "invalid_operation",
14
- INTERNAL_ERROR: "internal_error",
15
- CONDITION_FAILED: "condition_failed",
16
- INVALID_QUERY: "invalid_query",
17
- AUTH_REQUIRED: "auth_required"
18
- };
19
- var DEFAULT_COORDINATOR_URL = "https://db.lark.sh";
20
-
21
- // src/connection/Coordinator.ts
22
- var Coordinator = class {
23
- constructor(baseUrl = DEFAULT_COORDINATOR_URL) {
24
- this.baseUrl = baseUrl.replace(/\/$/, "");
25
- }
26
- /**
27
- * Request connection details from the coordinator.
28
- *
29
- * @param database - Database ID in format "project/database"
30
- * @returns Connection details including WebSocket URL and UDP host/port
31
- */
32
- async connect(database) {
33
- const body = { database };
34
- const response = await fetch(`${this.baseUrl}/connect`, {
35
- method: "POST",
36
- headers: {
37
- "Content-Type": "application/json"
38
- },
39
- body: JSON.stringify(body)
40
- });
41
- if (!response.ok) {
42
- let errorMessage = `Coordinator request failed: ${response.status}`;
43
- try {
44
- const errorBody = await response.json();
45
- if (errorBody.message) {
46
- errorMessage = errorBody.message;
47
- }
48
- } catch {
49
- }
50
- throw new Error(errorMessage);
51
- }
52
- const data = await response.json();
53
- return data;
54
- }
55
- };
56
-
57
1
  // src/connection/WebSocketTransport.ts
58
2
  import WebSocketNode from "ws";
59
3
  var WebSocketImpl = typeof WebSocket !== "undefined" ? WebSocket : WebSocketNode;
@@ -1420,7 +1364,6 @@ var View = class {
1420
1364
  /**
1421
1365
  * Check if this View loads all data (no limits, no range filters).
1422
1366
  * A View that loads all data can serve as a "complete" cache for child paths.
1423
- * This matches Firebase's loadsAllData() semantics.
1424
1367
  */
1425
1368
  loadsAllData() {
1426
1369
  if (!this.queryParams) return true;
@@ -1836,8 +1779,8 @@ var SubscriptionManager = class {
1836
1779
  /**
1837
1780
  * Detect and fire child_moved events for children that changed position OR sort value.
1838
1781
  *
1839
- * Firebase fires child_moved for ANY priority/sort value change, regardless of whether
1840
- * the position actually changes. This is Case 2003 behavior.
1782
+ * child_moved fires for ANY priority/sort value change, regardless of whether
1783
+ * the position actually changes.
1841
1784
  *
1842
1785
  * IMPORTANT: child_moved should only fire for children whose VALUE or PRIORITY changed.
1843
1786
  * Children that are merely "displaced" by another child moving should NOT fire child_moved.
@@ -2040,9 +1983,6 @@ var SubscriptionManager = class {
2040
1983
  * A complete View has no limits and no range filters, so it contains all data
2041
1984
  * for its subtree. Child subscriptions can use the ancestor's data instead
2042
1985
  * of creating their own server subscription.
2043
- *
2044
- * This matches Firebase's behavior where child listeners don't need their own
2045
- * server subscription if an ancestor has an unlimited listener.
2046
1986
  */
2047
1987
  hasAncestorCompleteView(path) {
2048
1988
  const normalized = normalizePath(path);
@@ -2168,8 +2108,8 @@ var SubscriptionManager = class {
2168
2108
  /**
2169
2109
  * Recursively sort object keys for consistent comparison.
2170
2110
  * This ensures {a:1, b:2} and {b:2, a:1} compare as equal.
2171
- * Uses simple alphabetical sorting (not Firebase key sorting) since we're
2172
- * just checking data equality, not display order.
2111
+ * Uses simple alphabetical sorting since we're just checking data equality,
2112
+ * not display order.
2173
2113
  */
2174
2114
  sortKeysForComparison(value) {
2175
2115
  if (value === null || typeof value !== "object") {
@@ -2763,6 +2703,26 @@ var SubscriptionManager = class {
2763
2703
  }
2764
2704
  };
2765
2705
 
2706
+ // src/protocol/constants.ts
2707
+ var OnDisconnectAction = {
2708
+ SET: "s",
2709
+ UPDATE: "u",
2710
+ DELETE: "d",
2711
+ CANCEL: "c"
2712
+ };
2713
+ var ErrorCode = {
2714
+ PERMISSION_DENIED: "permission_denied",
2715
+ INVALID_DATA: "invalid_data",
2716
+ NOT_FOUND: "not_found",
2717
+ INVALID_PATH: "invalid_path",
2718
+ INVALID_OPERATION: "invalid_operation",
2719
+ INTERNAL_ERROR: "internal_error",
2720
+ CONDITION_FAILED: "condition_failed",
2721
+ INVALID_QUERY: "invalid_query",
2722
+ AUTH_REQUIRED: "auth_required"
2723
+ };
2724
+ var DEFAULT_LARK_DOMAIN = "larkdb.net";
2725
+
2766
2726
  // src/OnDisconnect.ts
2767
2727
  var OnDisconnect = class {
2768
2728
  constructor(db, path) {
@@ -3060,7 +3020,6 @@ var DatabaseReference = class _DatabaseReference {
3060
3020
  * For queries (created via orderBy*, limitTo*, startAt, etc.), this returns
3061
3021
  * a reference to the same path without query constraints.
3062
3022
  * For non-query references, this returns the reference itself.
3063
- * This matches Firebase's Query.ref behavior.
3064
3023
  */
3065
3024
  get ref() {
3066
3025
  if (Object.keys(this._query).length === 0) {
@@ -3085,7 +3044,7 @@ var DatabaseReference = class _DatabaseReference {
3085
3044
  * Returns "default" for non-query references (no constraints).
3086
3045
  * Returns a sorted JSON string of wire-format params for queries.
3087
3046
  *
3088
- * This matches Firebase's queryIdentifier format for wire compatibility.
3047
+ * Used for wire protocol and subscription deduplication.
3089
3048
  */
3090
3049
  get queryIdentifier() {
3091
3050
  const queryObj = {};
@@ -3144,7 +3103,7 @@ var DatabaseReference = class _DatabaseReference {
3144
3103
  }
3145
3104
  /**
3146
3105
  * Get the data at this location. Alias for once('value').
3147
- * This is Firebase's newer API for reading data.
3106
+ * Alternative to once('value') for reading data.
3148
3107
  */
3149
3108
  async get() {
3150
3109
  return this.once("value");
@@ -3183,7 +3142,7 @@ var DatabaseReference = class _DatabaseReference {
3183
3142
  /**
3184
3143
  * Update specific children at this location without overwriting other children.
3185
3144
  *
3186
- * Also supports Firebase-style multi-path updates when keys look like paths
3145
+ * Also supports multi-path updates when keys look like paths
3187
3146
  * (start with '/'). In this mode, each path is written atomically as a transaction.
3188
3147
  *
3189
3148
  * @example
@@ -3264,7 +3223,7 @@ var DatabaseReference = class _DatabaseReference {
3264
3223
  * For objects: injects `.priority` into the value object.
3265
3224
  * For primitives: wraps as `{ '.value': primitive, '.priority': priority }`.
3266
3225
  *
3267
- * This follows Firebase's wire format for primitives with priority.
3226
+ * Uses { '.value': value, '.priority': priority } format for the wire protocol.
3268
3227
  *
3269
3228
  * @param value - The value to write
3270
3229
  * @param priority - The priority for ordering
@@ -4024,9 +3983,9 @@ var DataSnapshot = class _DataSnapshot {
4024
3983
  * Get a child snapshot at the specified path.
4025
3984
  *
4026
3985
  * Special handling:
4027
- * - `.priority` returns the priority value (Firebase compatible)
3986
+ * - `.priority` returns the priority value
4028
3987
  * - For wrapped primitives, only `.priority` returns data; other paths return null
4029
- * - Non-existent paths return a snapshot with val() === null (Firebase compatible)
3988
+ * - Non-existent paths return a snapshot with val() === null
4030
3989
  */
4031
3990
  child(path) {
4032
3991
  const childPath = joinPath(this._path, path);
@@ -4130,7 +4089,6 @@ var DataSnapshot = class _DataSnapshot {
4130
4089
  }
4131
4090
  /**
4132
4091
  * Check if this snapshot was from a volatile (high-frequency) update.
4133
- * This is a Lark extension not present in Firebase.
4134
4092
  */
4135
4093
  isVolatile() {
4136
4094
  return this._volatile;
@@ -4139,7 +4097,6 @@ var DataSnapshot = class _DataSnapshot {
4139
4097
  * Get the server timestamp for this snapshot (milliseconds since Unix epoch).
4140
4098
  * Only present on volatile value events. Use deltas between timestamps for
4141
4099
  * interpolation rather than absolute times to avoid clock sync issues.
4142
- * This is a Lark extension not present in Firebase.
4143
4100
  */
4144
4101
  getServerTimestamp() {
4145
4102
  return this._serverTimestamp;
@@ -4262,7 +4219,7 @@ var LarkDatabase = class {
4262
4219
  this._state = "disconnected";
4263
4220
  this._auth = null;
4264
4221
  this._databaseId = null;
4265
- this._coordinatorUrl = null;
4222
+ this._domain = null;
4266
4223
  this._volatilePaths = [];
4267
4224
  this._transportType = null;
4268
4225
  // Auth state
@@ -4325,8 +4282,9 @@ var LarkDatabase = class {
4325
4282
  * @internal Get the base URL for reference toString().
4326
4283
  */
4327
4284
  _getBaseUrl() {
4328
- if (this._coordinatorUrl && this._databaseId) {
4329
- return `${this._coordinatorUrl}/${this._databaseId}`;
4285
+ if (this._domain && this._databaseId) {
4286
+ const projectId = this._databaseId.split("/")[0];
4287
+ return `https://${projectId}.${this._domain}`;
4330
4288
  }
4331
4289
  return "lark://";
4332
4290
  }
@@ -4378,7 +4336,7 @@ var LarkDatabase = class {
4378
4336
  * Connect to a database.
4379
4337
  *
4380
4338
  * @param databaseId - Database ID in format "project/database"
4381
- * @param options - Connection options (token, anonymous, coordinator URL)
4339
+ * @param options - Connection options (token, anonymous, domain)
4382
4340
  */
4383
4341
  async connect(databaseId, options = {}) {
4384
4342
  if (this._state !== "disconnected") {
@@ -4402,16 +4360,17 @@ var LarkDatabase = class {
4402
4360
  const previousState = this._state;
4403
4361
  this._state = isReconnect ? "reconnecting" : "connecting";
4404
4362
  this._databaseId = databaseId;
4405
- this._coordinatorUrl = options.coordinator || DEFAULT_COORDINATOR_URL;
4363
+ this._domain = options.domain || DEFAULT_LARK_DOMAIN;
4406
4364
  if (!isReconnect) {
4407
4365
  this._currentToken = options.token || "";
4408
4366
  this._isAnonymous = !options.token && options.anonymous !== false;
4409
4367
  }
4410
4368
  try {
4411
- const coordinatorUrl = this._coordinatorUrl;
4412
- const coordinator = new Coordinator(coordinatorUrl);
4413
- const connectResponse = await coordinator.connect(databaseId);
4414
- const wsUrl = connectResponse.ws_url;
4369
+ const projectId = databaseId.split("/")[0];
4370
+ if (!projectId) {
4371
+ throw new Error('Invalid database ID: must be in format "projectId/databaseName"');
4372
+ }
4373
+ const wsUrl = `wss://${projectId}.${this._domain}/ws`;
4415
4374
  const transportResult = await createTransport(
4416
4375
  wsUrl,
4417
4376
  {
@@ -4572,7 +4531,7 @@ var LarkDatabase = class {
4572
4531
  this._auth = null;
4573
4532
  this._databaseId = null;
4574
4533
  this._volatilePaths = [];
4575
- this._coordinatorUrl = null;
4534
+ this._domain = null;
4576
4535
  this._connectionId = null;
4577
4536
  this._connectOptions = null;
4578
4537
  this._transportType = null;
@@ -4769,7 +4728,7 @@ var LarkDatabase = class {
4769
4728
  *
4770
4729
  * Supports two syntaxes:
4771
4730
  *
4772
- * **Object syntax** (like Firebase multi-path update):
4731
+ * **Object syntax** (multi-path update):
4773
4732
  * ```javascript
4774
4733
  * await db.transaction({
4775
4734
  * '/users/alice/name': 'Alice',
@@ -5389,4 +5348,4 @@ export {
5389
5348
  ServerValue,
5390
5349
  LarkDatabase
5391
5350
  };
5392
- //# sourceMappingURL=chunk-CYCSP6TZ.mjs.map
5351
+ //# sourceMappingURL=chunk-VLAAYUVX.mjs.map