@react-native-firebase/database 18.4.0 → 18.6.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +10 -0
- package/android/build.gradle +1 -1
- package/lib/DatabaseStatics.js +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/modular/index.d.ts +217 -0
- package/lib/modular/index.js +124 -0
- package/lib/modular/query.d.ts +1025 -0
- package/lib/modular/query.js +291 -0
- package/lib/modular/transaction.d.ts +56 -0
- package/lib/modular/transaction.js +15 -0
- package/lib/version.js +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
@@ -3,6 +3,16 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
5
5
|
|
6
|
+
## [18.6.0](https://github.com/invertase/react-native-firebase/compare/v18.5.0...v18.6.0) (2023-10-26)
|
7
|
+
|
8
|
+
**Note:** Version bump only for package @react-native-firebase/database
|
9
|
+
|
10
|
+
## [18.5.0](https://github.com/invertase/react-native-firebase/compare/v18.4.0...v18.5.0) (2023-09-22)
|
11
|
+
|
12
|
+
### Features
|
13
|
+
|
14
|
+
- **database:** Firebase V9 modular API ([#7136](https://github.com/invertase/react-native-firebase/issues/7136)) ([21531f2](https://github.com/invertase/react-native-firebase/commit/21531f26438cc34e4b86f17d58102263a73f2747))
|
15
|
+
|
6
16
|
## [18.4.0](https://github.com/invertase/react-native-firebase/compare/v18.3.2...v18.4.0) (2023-09-11)
|
7
17
|
|
8
18
|
**Note:** Version bump only for package @react-native-firebase/database
|
package/android/build.gradle
CHANGED
package/lib/DatabaseStatics.js
CHANGED
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
@@ -216,6 +216,8 @@ export default createModuleNamespace({
|
|
216
216
|
ModuleClass: FirebaseDatabaseModule,
|
217
217
|
});
|
218
218
|
|
219
|
+
export * from './modular';
|
220
|
+
|
219
221
|
// import database, { firebase } from '@react-native-firebase/database';
|
220
222
|
// database().X(...);
|
221
223
|
// firebase.database().X(...);
|
@@ -0,0 +1,217 @@
|
|
1
|
+
import { ReactNativeFirebase } from '@react-native-firebase/app';
|
2
|
+
import { FirebaseDatabaseTypes } from '..';
|
3
|
+
|
4
|
+
import FirebaseApp = ReactNativeFirebase.FirebaseApp;
|
5
|
+
import Database = FirebaseDatabaseTypes.Module;
|
6
|
+
import DatabaseReference = FirebaseDatabaseTypes.Reference;
|
7
|
+
|
8
|
+
/**
|
9
|
+
* Returns the instance of the Realtime Database SDK that is associated with
|
10
|
+
* the provided FirebaseApp. Initializes a new instance with
|
11
|
+
* default settings if no instance exists or if the existing
|
12
|
+
* instance uses a custom database URL.
|
13
|
+
*
|
14
|
+
* @param {FirebaseApp?} app - The FirebaseApp instance that the returned Realtime Database instance is associated with.
|
15
|
+
* @param {string?} url
|
16
|
+
* @returns {*}
|
17
|
+
*/
|
18
|
+
export declare function getDatabase(app?: FirebaseApp, url?: string): Database;
|
19
|
+
|
20
|
+
/**
|
21
|
+
* Modify this Database instance to communicate with the Firebase Database emulator.
|
22
|
+
* This must be called synchronously immediately following the first call to firebase.database().
|
23
|
+
* Do not use with production credentials as emulator traffic is not encrypted.
|
24
|
+
*
|
25
|
+
* Note: on android, hosts 'localhost' and '127.0.0.1' are automatically remapped to '10.0.2.2' (the
|
26
|
+
* "host" computer IP address for android emulators) to make the standard development experience easy.
|
27
|
+
* If you want to use the emulator on a real android device, you will need to specify the actual host
|
28
|
+
* computer IP address.
|
29
|
+
*
|
30
|
+
* @param db: The Database instance
|
31
|
+
* @param host: emulator host (eg, 'localhost')
|
32
|
+
* @param port: emulator port (eg, 9000)
|
33
|
+
*/
|
34
|
+
export declare function connectDatabaseEmulator(
|
35
|
+
db: Database,
|
36
|
+
host: string,
|
37
|
+
port: number,
|
38
|
+
// TODO: this exists in both the JS namespaced and modular versions of the SDK.
|
39
|
+
// But the RNFB namespaced version doesn't have it.
|
40
|
+
// options?: {
|
41
|
+
// mockUserToken?: EmulatorMockTokenOptions | string;
|
42
|
+
// },
|
43
|
+
): void;
|
44
|
+
|
45
|
+
/**
|
46
|
+
* Disconnects from the server (all Database operations will be completed offline).
|
47
|
+
*
|
48
|
+
* The client automatically maintains a persistent connection to the Database server, which
|
49
|
+
* will remain active indefinitely and reconnect when disconnected. However, the `goOffline()` and
|
50
|
+
* `goOnline()` methods may be used to control the client connection in cases where a persistent
|
51
|
+
* connection is undesirable.
|
52
|
+
*
|
53
|
+
* While offline, the client will no longer receive data updates from the Database. However,
|
54
|
+
* all Database operations performed locally will continue to immediately fire events, allowing
|
55
|
+
* your application to continue behaving normally. Additionally, each operation performed locally
|
56
|
+
* will automatically be queued and retried upon reconnection to the Database server.
|
57
|
+
*
|
58
|
+
* To reconnect to the Database and begin receiving remote events, see `goOnline()`.
|
59
|
+
*
|
60
|
+
* #### Example
|
61
|
+
*
|
62
|
+
* ```js
|
63
|
+
* const db = getDatabase();;
|
64
|
+
* await goOnline(db);
|
65
|
+
* ```
|
66
|
+
*/
|
67
|
+
export declare function goOffline(db: Database): Promise<void>;
|
68
|
+
|
69
|
+
/**
|
70
|
+
* Reconnects to the server and synchronizes the offline Database state with the server state.
|
71
|
+
*
|
72
|
+
* This method should be used after disabling the active connection with `goOffline()`. Once
|
73
|
+
* reconnected, the client will transmit the proper data and fire the appropriate events so that
|
74
|
+
* your client "catches up" automatically.
|
75
|
+
*
|
76
|
+
* #### Example
|
77
|
+
*
|
78
|
+
* ```js
|
79
|
+
* const db = getDatabase();
|
80
|
+
* await goOnline(db);
|
81
|
+
* ```
|
82
|
+
*/
|
83
|
+
export declare function goOnline(db: Database): Promise<void>;
|
84
|
+
|
85
|
+
/**
|
86
|
+
* Returns a `Reference` representing the location in the Database corresponding to the provided path.
|
87
|
+
* If no path is provided, the Reference will point to the root of the Database.
|
88
|
+
*
|
89
|
+
* #### Example
|
90
|
+
*
|
91
|
+
* ```js
|
92
|
+
* const db = getDatabase();
|
93
|
+
*
|
94
|
+
* // Get a reference to the root of the Database
|
95
|
+
* const rootRef = ref(db);
|
96
|
+
*
|
97
|
+
* // Get a reference to the /users/ada node
|
98
|
+
* const adaRef = ref(db, "users/ada");
|
99
|
+
* ```
|
100
|
+
*
|
101
|
+
* @param db The Database instance.
|
102
|
+
* @param path Optional path representing the location the returned `Reference` will point. If not provided, the returned `Reference` will point to the root of the Database.
|
103
|
+
*/
|
104
|
+
export declare function ref(db: Database, path?: string): DatabaseReference;
|
105
|
+
|
106
|
+
/**
|
107
|
+
* Generates a Reference from a database URL.
|
108
|
+
* Note domain must be the same.
|
109
|
+
* Any query parameters are stripped as per the web SDK.
|
110
|
+
*
|
111
|
+
* @param db The Database instance.
|
112
|
+
* @param url The Firebase URL at which the returned Reference will point.
|
113
|
+
* @returns {DatabaseReference}
|
114
|
+
*/
|
115
|
+
export declare function refFromURL(db: Database, url: string): DatabaseReference;
|
116
|
+
|
117
|
+
/**
|
118
|
+
* Sets whether persistence is enabled for all database calls for the current app
|
119
|
+
* instance.
|
120
|
+
*
|
121
|
+
* > Ensure this is called before any database calls are performed, otherwise
|
122
|
+
* persistence will only come into effect when the app is next started.
|
123
|
+
*
|
124
|
+
* #### Example
|
125
|
+
*
|
126
|
+
* ```js
|
127
|
+
* const db = getDatabase();
|
128
|
+
* setPersistenceEnabled(db, true);
|
129
|
+
*
|
130
|
+
* async function bootstrap() {
|
131
|
+
* // Bootstrapping application
|
132
|
+
* const snapshot = await ref(db, "settings").once("value");
|
133
|
+
* }
|
134
|
+
* ```
|
135
|
+
*
|
136
|
+
* @param db The Database instance.
|
137
|
+
* @param enabled Whether persistence is enabled for the Database service.
|
138
|
+
*/
|
139
|
+
export declare function setPersistenceEnabled(db: Database, enabled: boolean): void;
|
140
|
+
|
141
|
+
/**
|
142
|
+
* Sets the native logging level for the database module. By default,
|
143
|
+
* only warnings and errors are logged natively. Setting this to true will log all
|
144
|
+
* database events.
|
145
|
+
*
|
146
|
+
* > Ensure logging is disabled for production apps, as excessive logging can cause performance issues.
|
147
|
+
*
|
148
|
+
* #### Example
|
149
|
+
*
|
150
|
+
* ```js
|
151
|
+
* const db = getDatabase();
|
152
|
+
*
|
153
|
+
* // Set debug logging if developing
|
154
|
+
* if (__DEV__) {
|
155
|
+
* setLoggingEnabled(db, true);
|
156
|
+
* }
|
157
|
+
* ```
|
158
|
+
*
|
159
|
+
* @param db The Database instance.
|
160
|
+
* @param enabled Whether debug logging is enabled.
|
161
|
+
* @returns {void}
|
162
|
+
*/
|
163
|
+
export declare function setLoggingEnabled(db: Database, enabled: boolean): void;
|
164
|
+
|
165
|
+
/**
|
166
|
+
* By default, Firebase Database will use up to 10MB of disk space to cache data. If the cache grows beyond this size,
|
167
|
+
* Firebase Database will start removing data that hasn't been recently used. If you find that your application
|
168
|
+
* caches too little or too much data, call this method to change the cache size. This method must be called before
|
169
|
+
* creating your first Database reference and only needs to be called once per application.
|
170
|
+
*
|
171
|
+
* Note that the specified cache size is only an approximation and the size on disk may temporarily exceed it at times.
|
172
|
+
* Cache sizes smaller than 1 MB or greater than 100 MB are not supported.
|
173
|
+
*
|
174
|
+
* #### Example
|
175
|
+
*
|
176
|
+
* ```js
|
177
|
+
* const db = getDatabase();
|
178
|
+
*
|
179
|
+
* setPersistenceEnabled(db, true);
|
180
|
+
* setPersistenceCacheSizeBytes(db, 2000000); // 2MB
|
181
|
+
*
|
182
|
+
* async function bootstrap() {
|
183
|
+
* // Bootstrapping application
|
184
|
+
* const snapshot = await ref(db, 'settings').once("value");
|
185
|
+
* }
|
186
|
+
* ```
|
187
|
+
*
|
188
|
+
* @param db The Database instance.
|
189
|
+
* @param bytes The new size of the cache in bytes.
|
190
|
+
*/
|
191
|
+
export declare function setPersistenceCacheSizeBytes(db: Database, bytes: number): void;
|
192
|
+
|
193
|
+
/**
|
194
|
+
* Force the use of longPolling instead of websockets. This will be ignored if websocket protocol is used in databaseURL.
|
195
|
+
*/
|
196
|
+
export declare function forceLongPolling(): void;
|
197
|
+
|
198
|
+
/**
|
199
|
+
* Force the use of websockets instead of longPolling.
|
200
|
+
*/
|
201
|
+
export declare function forceWebSockets(): void;
|
202
|
+
|
203
|
+
/**
|
204
|
+
* Returns a placeholder value for auto-populating the current timestamp (time
|
205
|
+
* since the Unix epoch, in milliseconds) as determined by the Firebase
|
206
|
+
* servers.
|
207
|
+
*/
|
208
|
+
export function serverTimestamp(): object;
|
209
|
+
|
210
|
+
/**
|
211
|
+
* Returns a placeholder value that can be used to atomically increment the
|
212
|
+
* current database value by the provided delta.
|
213
|
+
*
|
214
|
+
* @param delta - the amount to modify the current value atomically.
|
215
|
+
* @returns A placeholder value for modifying data atomically server-side.
|
216
|
+
*/
|
217
|
+
export function increment(delta: number): object;
|
@@ -0,0 +1,124 @@
|
|
1
|
+
import { firebase } from '..';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* @typedef {import("..").FirebaseApp} FirebaseApp
|
5
|
+
* @typedef {import("..").FirebaseDatabaseTypes.Module} Database
|
6
|
+
*/
|
7
|
+
|
8
|
+
/**
|
9
|
+
* @param {FirebaseApp?} app - The FirebaseApp instance that the returned Realtime Database instance is associated with.
|
10
|
+
* @param {string?} url
|
11
|
+
* @returns {Database}
|
12
|
+
*/
|
13
|
+
export function getDatabase(app, url) {
|
14
|
+
if (app) {
|
15
|
+
return firebase.app(app.name).database(url);
|
16
|
+
}
|
17
|
+
|
18
|
+
return firebase.app().database(url);
|
19
|
+
}
|
20
|
+
|
21
|
+
/**
|
22
|
+
* @param {Database} db
|
23
|
+
* @param {string} host
|
24
|
+
* @param {number} port
|
25
|
+
* @returns {void}
|
26
|
+
*/
|
27
|
+
export function connectDatabaseEmulator(db, host, port) {
|
28
|
+
db.useEmulator(host, port);
|
29
|
+
}
|
30
|
+
|
31
|
+
/**
|
32
|
+
* @param {Database} db
|
33
|
+
* @returns {Promise<void>}
|
34
|
+
*/
|
35
|
+
export function goOffline(db) {
|
36
|
+
return db.goOffline();
|
37
|
+
}
|
38
|
+
|
39
|
+
/**
|
40
|
+
* @param {Database} db
|
41
|
+
* @returns {Promise<void>}
|
42
|
+
*/
|
43
|
+
export function goOnline(db) {
|
44
|
+
return db.goOnline();
|
45
|
+
}
|
46
|
+
|
47
|
+
/**
|
48
|
+
* @param {Database} db
|
49
|
+
* @param {string?} path
|
50
|
+
* @returns {DatabaseReference}
|
51
|
+
*/
|
52
|
+
export function ref(db, path) {
|
53
|
+
return db.ref(path);
|
54
|
+
}
|
55
|
+
|
56
|
+
/**
|
57
|
+
* @param {Database} db
|
58
|
+
* @param {string} url
|
59
|
+
* @returns {DatabaseReference}
|
60
|
+
*/
|
61
|
+
export function refFromURL(db, url) {
|
62
|
+
return db.refFromURL(url);
|
63
|
+
}
|
64
|
+
|
65
|
+
/**
|
66
|
+
* @param {Database} db
|
67
|
+
* @param {boolean} enabled
|
68
|
+
* @returns {void}
|
69
|
+
*/
|
70
|
+
export function setPersistenceEnabled(db, enabled) {
|
71
|
+
return db.setPersistenceEnabled(enabled);
|
72
|
+
}
|
73
|
+
|
74
|
+
/**
|
75
|
+
* @param {Database} db
|
76
|
+
* @param {boolean} enabled
|
77
|
+
* @returns {void}
|
78
|
+
*/
|
79
|
+
export function setLoggingEnabled(db, enabled) {
|
80
|
+
return db.setLoggingEnabled(enabled);
|
81
|
+
}
|
82
|
+
|
83
|
+
/**
|
84
|
+
* @param {Database} db
|
85
|
+
* @param {number} bytes
|
86
|
+
* @returns {void}
|
87
|
+
*/
|
88
|
+
export function setPersistenceCacheSizeBytes(db, bytes) {
|
89
|
+
return db.setPersistenceCacheSizeBytes(bytes);
|
90
|
+
}
|
91
|
+
|
92
|
+
export function forceLongPolling() {
|
93
|
+
throw new Error('forceLongPolling() is not implemented');
|
94
|
+
}
|
95
|
+
|
96
|
+
export function forceWebSockets() {
|
97
|
+
throw new Error('forceWebSockets() is not implemented');
|
98
|
+
}
|
99
|
+
|
100
|
+
/**
|
101
|
+
* @param {Database} db
|
102
|
+
* @returns {Date}
|
103
|
+
*/
|
104
|
+
export function getServerTime(db) {
|
105
|
+
return db.getServerTime();
|
106
|
+
}
|
107
|
+
|
108
|
+
/**
|
109
|
+
* @returns {object}
|
110
|
+
*/
|
111
|
+
export function serverTimestamp() {
|
112
|
+
return firebase.database.ServerValue.TIMESTAMP;
|
113
|
+
}
|
114
|
+
|
115
|
+
/**
|
116
|
+
* @param {number} delta
|
117
|
+
* @returns {object}
|
118
|
+
*/
|
119
|
+
export function increment(delta) {
|
120
|
+
return firebase.database.ServerValue.increment(delta);
|
121
|
+
}
|
122
|
+
|
123
|
+
export * from './query';
|
124
|
+
export * from './transaction';
|