@lark-sh/client 0.1.12 → 0.1.14

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.
@@ -0,0 +1,195 @@
1
+ import { EventType, SnapshotCallback, AuthInfo, ConnectOptions, TransactionOp, TransactionObject, DatabaseReference as DatabaseReference$1, ThenableReference as ThenableReference$1, TransactionResult, DataSnapshot, OnDisconnect } from '../index.mjs';
2
+ export { LarkError, PendingWriteManager, QueryParams, QueryState, ServerValue, TransactionConditionOp, TransactionDeleteOp, TransactionSetOp, TransactionUpdateOp, TransportType, generatePushId, isVolatilePath } from '../index.mjs';
3
+
4
+ /**
5
+ * Firebase v8 Compatibility Layer
6
+ *
7
+ * This module provides Firebase v8-style behavior for users migrating from Firebase.
8
+ *
9
+ * Key differences from modern API:
10
+ * 1. on() returns the callback (not an unsubscribe function)
11
+ * 2. off(eventType, callback, context?) removes specific listener by callback reference
12
+ * 3. once(eventType, successCallback, cancelCallback, context?) supports callback style
13
+ * 4. Context parameter binds `this` inside callbacks
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * import { LarkDatabase, DatabaseReference } from '@lark-sh/client/fb-v8';
18
+ *
19
+ * const db = new LarkDatabase();
20
+ * await db.connect('project/database', { anonymous: true });
21
+ *
22
+ * const ref = db.ref('players');
23
+ * const callback = ref.on('value', (snap) => console.log(snap.val()));
24
+ * // callback === the function you passed in
25
+ *
26
+ * // Later: remove by callback reference (works from any ref at same path)
27
+ * ref.off('value', callback);
28
+ *
29
+ * // With context (binds `this`):
30
+ * ref.on('value', this.handleValue, this);
31
+ * ref.off('value', this.handleValue, this);
32
+ * ```
33
+ */
34
+
35
+ /**
36
+ * Firebase v8 compatible DatabaseReference.
37
+ * Wraps the modern DatabaseReference with v8-style on/off behavior.
38
+ */
39
+ declare class DatabaseReference {
40
+ private readonly _modernRef;
41
+ private readonly _db;
42
+ constructor(db: LarkDatabase, modernRef: DatabaseReference$1);
43
+ get path(): string;
44
+ get key(): string | null;
45
+ get parent(): DatabaseReference | null;
46
+ get root(): DatabaseReference;
47
+ get database(): LarkDatabase;
48
+ /**
49
+ * Get the underlying reference for a query.
50
+ * For queries, returns a reference without query constraints.
51
+ */
52
+ get ref(): DatabaseReference;
53
+ get queryIdentifier(): string;
54
+ child(path: string): DatabaseReference;
55
+ set(value: unknown): Promise<void>;
56
+ update(values: Record<string, unknown>): Promise<void>;
57
+ remove(): Promise<void>;
58
+ push(): ThenableReference;
59
+ push(value: unknown): ThenableReference;
60
+ setWithPriority(value: unknown, priority: number | string): Promise<void>;
61
+ setPriority(priority: number | string | null): Promise<void>;
62
+ transaction(updateFunction: (currentValue: unknown) => unknown, maxRetries?: number): Promise<TransactionResult>;
63
+ get(): Promise<DataSnapshot>;
64
+ /**
65
+ * Read data once.
66
+ *
67
+ * Supports both promise style and Firebase v8 callback style:
68
+ * - `once('value')` - returns Promise<DataSnapshot>
69
+ * - `once('value', callback)` - calls callback with snapshot, returns Promise
70
+ * - `once('value', callback, cancelCallback)` - also handles errors
71
+ * - `once('value', callback, cancelCallback, context)` - binds `this` to context
72
+ */
73
+ once(eventType?: EventType): Promise<DataSnapshot>;
74
+ once(eventType: EventType, successCallback: SnapshotCallback, cancelCallback?: (error: Error) => void, context?: unknown): Promise<DataSnapshot>;
75
+ /**
76
+ * Subscribe to events at this location.
77
+ *
78
+ * **Firebase v8 behavior**: Returns the callback function (not an unsubscribe function).
79
+ * Use `off(eventType, callback, context?)` to remove the listener.
80
+ *
81
+ * Note: Callbacks are tracked globally by path, so off() on any ref at the same
82
+ * path can remove this callback by reference.
83
+ *
84
+ * @param eventType - The event type to listen for
85
+ * @param callback - The callback to invoke
86
+ * @param cancelCallbackOrContext - Optional cancel callback or context
87
+ * @param context - Optional context to bind `this` in callback
88
+ * @returns The callback function (for use with off())
89
+ */
90
+ on(eventType: EventType, callback: SnapshotCallback, cancelCallbackOrContext?: ((error: Error) => void) | unknown, context?: unknown): SnapshotCallback;
91
+ /**
92
+ * Unsubscribe from events.
93
+ *
94
+ * **Firebase v8 behavior**: Can remove specific listeners by callback reference.
95
+ *
96
+ * - `off()` - removes all listeners on this specific query (or all queries if base ref)
97
+ * - `off('value')` - removes all 'value' listeners on this specific query
98
+ * - `off('value', callback)` - removes callback (any context) from ANY query at this path
99
+ * - `off('value', callback, context)` - removes specific callback+context combo
100
+ */
101
+ off(eventType?: EventType, callback?: SnapshotCallback, context?: unknown): void;
102
+ onDisconnect(): OnDisconnect;
103
+ orderByKey(): DatabaseReference;
104
+ orderByPriority(): DatabaseReference;
105
+ orderByChild(path: string): DatabaseReference;
106
+ orderByValue(): DatabaseReference;
107
+ limitToFirst(limit: number): DatabaseReference;
108
+ limitToLast(limit: number): DatabaseReference;
109
+ startAt(value?: unknown, key?: string): DatabaseReference;
110
+ startAfter(value?: unknown, key?: string): DatabaseReference;
111
+ endAt(value?: unknown, key?: string): DatabaseReference;
112
+ endBefore(value?: unknown, key?: string): DatabaseReference;
113
+ equalTo(value: unknown, key?: string): DatabaseReference;
114
+ isEqual(other: DatabaseReference | null): boolean;
115
+ toString(): string;
116
+ toJSON(): string;
117
+ }
118
+ /**
119
+ * Firebase v8 compatible ThenableReference.
120
+ */
121
+ declare class ThenableReference extends DatabaseReference implements PromiseLike<DatabaseReference> {
122
+ private readonly _modernThenable;
123
+ constructor(db: LarkDatabase, modernThenable: ThenableReference$1);
124
+ then<TResult1 = DatabaseReference, TResult2 = never>(onfulfilled?: ((value: DatabaseReference) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;
125
+ catch<TResult = never>(onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | undefined | null): Promise<DatabaseReference | TResult>;
126
+ }
127
+ /**
128
+ * Firebase v8 compatible LarkDatabase.
129
+ * Returns Firebase v8 compatible references.
130
+ */
131
+ declare class LarkDatabase {
132
+ private readonly _modernDb;
133
+ /**
134
+ * Global callback registry for Firebase v8 compatibility.
135
+ * Structure: path -> eventType -> callback -> unsubscribe function
136
+ */
137
+ private readonly _callbackRegistry;
138
+ static ServerValue: {
139
+ TIMESTAMP: {
140
+ readonly '.sv': "timestamp";
141
+ };
142
+ increment: (delta: number) => {
143
+ '.sv': {
144
+ increment: number;
145
+ };
146
+ };
147
+ };
148
+ constructor();
149
+ /**
150
+ * @internal Register a callback in the global registry.
151
+ */
152
+ _registerCallback(path: string, queryId: string, eventType: EventType, callback: SnapshotCallback, context: unknown, unsubscribe: () => void): void;
153
+ /**
154
+ * @internal Unregister callbacks from the global registry.
155
+ *
156
+ * Behavior:
157
+ * - With callback+context: Finds and removes that specific callback+context combo from ANY query
158
+ * - With callback only: Removes ALL registrations of that callback (any context) from ANY query
159
+ * - Without callback: Removes all callbacks from the specified query only
160
+ * - If queryId is 'default' (base ref), removes from ALL queries at the path
161
+ */
162
+ _unregisterCallback(path: string, queryId: string, eventType?: EventType, callback?: SnapshotCallback, context?: unknown): void;
163
+ /**
164
+ * @internal Clean up empty nested maps in the registry.
165
+ */
166
+ private _cleanupEmptyMaps;
167
+ get connected(): boolean;
168
+ get reconnecting(): boolean;
169
+ get state(): string;
170
+ get auth(): AuthInfo | null;
171
+ get volatilePaths(): string[];
172
+ get transportType(): 'websocket' | 'webtransport' | null;
173
+ get serverTimeOffset(): number;
174
+ hasPendingWrites(): boolean;
175
+ getPendingWriteCount(): number;
176
+ clearPendingWrites(): void;
177
+ connect(databaseId: string, options?: ConnectOptions): Promise<void>;
178
+ disconnect(): Promise<void>;
179
+ goOffline(): void;
180
+ goOnline(): void;
181
+ /**
182
+ * Get a Firebase v8 compatible reference to a path.
183
+ */
184
+ ref(path?: string): DatabaseReference;
185
+ transaction(operations: TransactionOp[] | TransactionObject): Promise<void>;
186
+ onConnect(callback: () => void): () => void;
187
+ onDisconnect(callback: () => void): () => void;
188
+ onError(callback: (error: Error) => void): () => void;
189
+ onReconnecting(callback: () => void): () => void;
190
+ onAuthStateChanged(callback: (auth: AuthInfo | null) => void): () => void;
191
+ signIn(token: string): Promise<void>;
192
+ signOut(): Promise<void>;
193
+ }
194
+
195
+ export { AuthInfo, ConnectOptions, DataSnapshot, DatabaseReference, EventType, LarkDatabase, OnDisconnect, SnapshotCallback, ThenableReference, TransactionObject, TransactionOp, TransactionResult };
@@ -0,0 +1,195 @@
1
+ import { EventType, SnapshotCallback, AuthInfo, ConnectOptions, TransactionOp, TransactionObject, DatabaseReference as DatabaseReference$1, ThenableReference as ThenableReference$1, TransactionResult, DataSnapshot, OnDisconnect } from '../index.js';
2
+ export { LarkError, PendingWriteManager, QueryParams, QueryState, ServerValue, TransactionConditionOp, TransactionDeleteOp, TransactionSetOp, TransactionUpdateOp, TransportType, generatePushId, isVolatilePath } from '../index.js';
3
+
4
+ /**
5
+ * Firebase v8 Compatibility Layer
6
+ *
7
+ * This module provides Firebase v8-style behavior for users migrating from Firebase.
8
+ *
9
+ * Key differences from modern API:
10
+ * 1. on() returns the callback (not an unsubscribe function)
11
+ * 2. off(eventType, callback, context?) removes specific listener by callback reference
12
+ * 3. once(eventType, successCallback, cancelCallback, context?) supports callback style
13
+ * 4. Context parameter binds `this` inside callbacks
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * import { LarkDatabase, DatabaseReference } from '@lark-sh/client/fb-v8';
18
+ *
19
+ * const db = new LarkDatabase();
20
+ * await db.connect('project/database', { anonymous: true });
21
+ *
22
+ * const ref = db.ref('players');
23
+ * const callback = ref.on('value', (snap) => console.log(snap.val()));
24
+ * // callback === the function you passed in
25
+ *
26
+ * // Later: remove by callback reference (works from any ref at same path)
27
+ * ref.off('value', callback);
28
+ *
29
+ * // With context (binds `this`):
30
+ * ref.on('value', this.handleValue, this);
31
+ * ref.off('value', this.handleValue, this);
32
+ * ```
33
+ */
34
+
35
+ /**
36
+ * Firebase v8 compatible DatabaseReference.
37
+ * Wraps the modern DatabaseReference with v8-style on/off behavior.
38
+ */
39
+ declare class DatabaseReference {
40
+ private readonly _modernRef;
41
+ private readonly _db;
42
+ constructor(db: LarkDatabase, modernRef: DatabaseReference$1);
43
+ get path(): string;
44
+ get key(): string | null;
45
+ get parent(): DatabaseReference | null;
46
+ get root(): DatabaseReference;
47
+ get database(): LarkDatabase;
48
+ /**
49
+ * Get the underlying reference for a query.
50
+ * For queries, returns a reference without query constraints.
51
+ */
52
+ get ref(): DatabaseReference;
53
+ get queryIdentifier(): string;
54
+ child(path: string): DatabaseReference;
55
+ set(value: unknown): Promise<void>;
56
+ update(values: Record<string, unknown>): Promise<void>;
57
+ remove(): Promise<void>;
58
+ push(): ThenableReference;
59
+ push(value: unknown): ThenableReference;
60
+ setWithPriority(value: unknown, priority: number | string): Promise<void>;
61
+ setPriority(priority: number | string | null): Promise<void>;
62
+ transaction(updateFunction: (currentValue: unknown) => unknown, maxRetries?: number): Promise<TransactionResult>;
63
+ get(): Promise<DataSnapshot>;
64
+ /**
65
+ * Read data once.
66
+ *
67
+ * Supports both promise style and Firebase v8 callback style:
68
+ * - `once('value')` - returns Promise<DataSnapshot>
69
+ * - `once('value', callback)` - calls callback with snapshot, returns Promise
70
+ * - `once('value', callback, cancelCallback)` - also handles errors
71
+ * - `once('value', callback, cancelCallback, context)` - binds `this` to context
72
+ */
73
+ once(eventType?: EventType): Promise<DataSnapshot>;
74
+ once(eventType: EventType, successCallback: SnapshotCallback, cancelCallback?: (error: Error) => void, context?: unknown): Promise<DataSnapshot>;
75
+ /**
76
+ * Subscribe to events at this location.
77
+ *
78
+ * **Firebase v8 behavior**: Returns the callback function (not an unsubscribe function).
79
+ * Use `off(eventType, callback, context?)` to remove the listener.
80
+ *
81
+ * Note: Callbacks are tracked globally by path, so off() on any ref at the same
82
+ * path can remove this callback by reference.
83
+ *
84
+ * @param eventType - The event type to listen for
85
+ * @param callback - The callback to invoke
86
+ * @param cancelCallbackOrContext - Optional cancel callback or context
87
+ * @param context - Optional context to bind `this` in callback
88
+ * @returns The callback function (for use with off())
89
+ */
90
+ on(eventType: EventType, callback: SnapshotCallback, cancelCallbackOrContext?: ((error: Error) => void) | unknown, context?: unknown): SnapshotCallback;
91
+ /**
92
+ * Unsubscribe from events.
93
+ *
94
+ * **Firebase v8 behavior**: Can remove specific listeners by callback reference.
95
+ *
96
+ * - `off()` - removes all listeners on this specific query (or all queries if base ref)
97
+ * - `off('value')` - removes all 'value' listeners on this specific query
98
+ * - `off('value', callback)` - removes callback (any context) from ANY query at this path
99
+ * - `off('value', callback, context)` - removes specific callback+context combo
100
+ */
101
+ off(eventType?: EventType, callback?: SnapshotCallback, context?: unknown): void;
102
+ onDisconnect(): OnDisconnect;
103
+ orderByKey(): DatabaseReference;
104
+ orderByPriority(): DatabaseReference;
105
+ orderByChild(path: string): DatabaseReference;
106
+ orderByValue(): DatabaseReference;
107
+ limitToFirst(limit: number): DatabaseReference;
108
+ limitToLast(limit: number): DatabaseReference;
109
+ startAt(value?: unknown, key?: string): DatabaseReference;
110
+ startAfter(value?: unknown, key?: string): DatabaseReference;
111
+ endAt(value?: unknown, key?: string): DatabaseReference;
112
+ endBefore(value?: unknown, key?: string): DatabaseReference;
113
+ equalTo(value: unknown, key?: string): DatabaseReference;
114
+ isEqual(other: DatabaseReference | null): boolean;
115
+ toString(): string;
116
+ toJSON(): string;
117
+ }
118
+ /**
119
+ * Firebase v8 compatible ThenableReference.
120
+ */
121
+ declare class ThenableReference extends DatabaseReference implements PromiseLike<DatabaseReference> {
122
+ private readonly _modernThenable;
123
+ constructor(db: LarkDatabase, modernThenable: ThenableReference$1);
124
+ then<TResult1 = DatabaseReference, TResult2 = never>(onfulfilled?: ((value: DatabaseReference) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;
125
+ catch<TResult = never>(onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | undefined | null): Promise<DatabaseReference | TResult>;
126
+ }
127
+ /**
128
+ * Firebase v8 compatible LarkDatabase.
129
+ * Returns Firebase v8 compatible references.
130
+ */
131
+ declare class LarkDatabase {
132
+ private readonly _modernDb;
133
+ /**
134
+ * Global callback registry for Firebase v8 compatibility.
135
+ * Structure: path -> eventType -> callback -> unsubscribe function
136
+ */
137
+ private readonly _callbackRegistry;
138
+ static ServerValue: {
139
+ TIMESTAMP: {
140
+ readonly '.sv': "timestamp";
141
+ };
142
+ increment: (delta: number) => {
143
+ '.sv': {
144
+ increment: number;
145
+ };
146
+ };
147
+ };
148
+ constructor();
149
+ /**
150
+ * @internal Register a callback in the global registry.
151
+ */
152
+ _registerCallback(path: string, queryId: string, eventType: EventType, callback: SnapshotCallback, context: unknown, unsubscribe: () => void): void;
153
+ /**
154
+ * @internal Unregister callbacks from the global registry.
155
+ *
156
+ * Behavior:
157
+ * - With callback+context: Finds and removes that specific callback+context combo from ANY query
158
+ * - With callback only: Removes ALL registrations of that callback (any context) from ANY query
159
+ * - Without callback: Removes all callbacks from the specified query only
160
+ * - If queryId is 'default' (base ref), removes from ALL queries at the path
161
+ */
162
+ _unregisterCallback(path: string, queryId: string, eventType?: EventType, callback?: SnapshotCallback, context?: unknown): void;
163
+ /**
164
+ * @internal Clean up empty nested maps in the registry.
165
+ */
166
+ private _cleanupEmptyMaps;
167
+ get connected(): boolean;
168
+ get reconnecting(): boolean;
169
+ get state(): string;
170
+ get auth(): AuthInfo | null;
171
+ get volatilePaths(): string[];
172
+ get transportType(): 'websocket' | 'webtransport' | null;
173
+ get serverTimeOffset(): number;
174
+ hasPendingWrites(): boolean;
175
+ getPendingWriteCount(): number;
176
+ clearPendingWrites(): void;
177
+ connect(databaseId: string, options?: ConnectOptions): Promise<void>;
178
+ disconnect(): Promise<void>;
179
+ goOffline(): void;
180
+ goOnline(): void;
181
+ /**
182
+ * Get a Firebase v8 compatible reference to a path.
183
+ */
184
+ ref(path?: string): DatabaseReference;
185
+ transaction(operations: TransactionOp[] | TransactionObject): Promise<void>;
186
+ onConnect(callback: () => void): () => void;
187
+ onDisconnect(callback: () => void): () => void;
188
+ onError(callback: (error: Error) => void): () => void;
189
+ onReconnecting(callback: () => void): () => void;
190
+ onAuthStateChanged(callback: (auth: AuthInfo | null) => void): () => void;
191
+ signIn(token: string): Promise<void>;
192
+ signOut(): Promise<void>;
193
+ }
194
+
195
+ export { AuthInfo, ConnectOptions, DataSnapshot, DatabaseReference, EventType, LarkDatabase, OnDisconnect, SnapshotCallback, ThenableReference, TransactionObject, TransactionOp, TransactionResult };