@react-native-firebase/database 18.3.2 → 18.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,291 @@
1
+ /**
2
+ * @typedef {import('../..').DatabaseReference} DatabaseReference
3
+ * @typedef {import('../..').DataSnapshot} DataSnapshot
4
+ * @typedef {import('./query').QueryConstraint} IQueryConstraint
5
+ * @typedef {import('./query').Query} Query
6
+ * @typedef {import('./query').OnDisconnect} OnDisconnect
7
+ * @typedef {import('./query').ListenOptions} ListenOptions
8
+ * @typedef {import('./query').Unsubscribe} Unsubscribe
9
+ * @typedef {import('./query').EventType} EventType
10
+ * @typedef {import('./query').ThenableReference} ThenableReference
11
+ */
12
+
13
+ /**
14
+ * @implements {IQueryConstraint}
15
+ */
16
+ class QueryConstraint {
17
+ constructor(type, ...args) {
18
+ this._type = type;
19
+ this._args = args;
20
+ }
21
+
22
+ _apply(query) {
23
+ return query[this._type].apply(query, this._args);
24
+ }
25
+ }
26
+
27
+ /**
28
+ * @param {number | string | boolean | null} value
29
+ * @param {string?} key
30
+ * @returns {QueryConstraint}
31
+ */
32
+ export function endAt(value, key) {
33
+ return new QueryConstraint('endAt', value, key);
34
+ }
35
+
36
+ /**
37
+ * @param {number | string | boolean | null} value
38
+ * @param {string?} key
39
+ * @returns {QueryConstraint}
40
+ */
41
+ export function endBefore(value, key) {
42
+ return new QueryConstraint('endBefore', value, key);
43
+ }
44
+
45
+ /**
46
+ * @param {number | string | boolean | null} value,
47
+ * @param {string?} key,
48
+ * @returns {QueryConstraint}
49
+ */
50
+ export function startAt(value, key) {
51
+ return new QueryConstraint('startAt', value, key);
52
+ }
53
+
54
+ /**
55
+ * @param {number | string | boolean | null} value,
56
+ * @param {string?} key,
57
+ * @returns {QueryConstraint}
58
+ */
59
+ export function startAfter(value, key) {
60
+ return new QueryConstraint('startAfter', value, key);
61
+ }
62
+
63
+ /**
64
+ * @param {number} limit
65
+ * @returns {QueryConstraint}
66
+ */
67
+ export function limitToFirst(limit) {
68
+ return new QueryConstraint('limitToFirst', limit);
69
+ }
70
+
71
+ /**
72
+ * @param {number} limit
73
+ * @returns {QueryConstraint}
74
+ */
75
+ export function limitToLast(limit) {
76
+ return new QueryConstraint('limitToLast', limit);
77
+ }
78
+
79
+ /**
80
+ * @param {string} path
81
+ * @returns {QueryConstraint}
82
+ */
83
+ export function orderByChild(path) {
84
+ return new QueryConstraint('orderByChild', path);
85
+ }
86
+
87
+ export function orderByKey() {
88
+ return new QueryConstraint('orderByKey');
89
+ }
90
+
91
+ export function orderByPriority() {
92
+ return new QueryConstraint('orderByPriority');
93
+ }
94
+
95
+ export function orderByValue() {
96
+ return new QueryConstraint('orderByValue');
97
+ }
98
+
99
+ /**
100
+ * @param {number | string | boolean | null} value
101
+ * @param {string?} key
102
+ * @returns {QueryConstraint}
103
+ */
104
+ export function equalTo(value, key) {
105
+ return new QueryConstraint('equalTo', value, key);
106
+ }
107
+
108
+ /**
109
+ * @param {Query} query
110
+ * @param {QueryConstraint[]} queryConstraints
111
+ * @returns {Query}
112
+ */
113
+ export function query(query, ...queryConstraints) {
114
+ let q = query;
115
+ for (const queryConstraint of queryConstraints) {
116
+ q = queryConstraint._apply(q);
117
+ }
118
+ return q;
119
+ }
120
+
121
+ /**
122
+ * @param {Query} query
123
+ * @param {EventType} eventType
124
+ * @param {(snapshot: DataSnapshot) => unknown} callback
125
+ * @param {((error: Error) => unknown) | ListenOptions} cancelCallbackOrListenOptions
126
+ * @param {ListenOptions?} options
127
+ * @returns {Unsubscribe}
128
+ */
129
+ function addEventListener(query, eventType, callback, cancelCallbackOrListenOptions, options) {
130
+ let cancelCallback = cancelCallbackOrListenOptions;
131
+
132
+ if (typeof cancelCallbackOrListenOptions === 'object') {
133
+ cancelCallback = undefined;
134
+ options = cancelCallbackOrListenOptions;
135
+ }
136
+
137
+ if (options && options.onlyOnce) {
138
+ const userCallback = callback;
139
+ callback = snapshot => {
140
+ query.off(eventType, callback);
141
+ return userCallback(snapshot);
142
+ };
143
+ }
144
+
145
+ query.on(eventType, callback, cancelCallback);
146
+
147
+ return () => query.off(eventType, callback);
148
+ }
149
+
150
+ /**
151
+ * @param {Query} query
152
+ * @param {(snapshot: DataSnapshot) => unknown} callback
153
+ * @param {((error: Error) => unknown) | ListenOptions | undefined} cancelCallbackOrListenOptions
154
+ * @param {ListenOptions?} options
155
+ * @returns {Unsubscribe}
156
+ */
157
+ export function onValue(query, callback, cancelCallbackOrListenOptions, options) {
158
+ return addEventListener(query, 'value', callback, cancelCallbackOrListenOptions, options);
159
+ }
160
+
161
+ /**
162
+ * @param {Query} query
163
+ * @param {(snapshot: DataSnapshot, previousChildName: string | null) => unknown} callback
164
+ * @param {((error: Error) => unknown) | ListenOptions | undefined} cancelCallbackOrListenOptions
165
+ * @param {ListenOptions?} options
166
+ * @returns {Unsubscribe}
167
+ */
168
+ export function onChildAdded(query, callback, cancelCallbackOrListenOptions, options) {
169
+ return addEventListener(query, 'child_added', callback, cancelCallbackOrListenOptions, options);
170
+ }
171
+
172
+ /**
173
+ * @param {Query} query
174
+ * @param {(snapshot: DataSnapshot, previousChildName: string | null) => unknown} callback
175
+ * @param {((error: Error) => unknown) | ListenOptions | undefined} cancelCallbackOrListenOptions
176
+ * @param {ListenOptions?} options
177
+ * @returns {Unsubscribe}
178
+ */
179
+ export function onChildChanged(query, callback, cancelCallbackOrListenOptions, options) {
180
+ return addEventListener(query, 'child_changed', callback, cancelCallbackOrListenOptions, options);
181
+ }
182
+
183
+ /**
184
+ * @param {Query} query
185
+ * @param {(snapshot: DataSnapshot, previousChildName: string | null) => unknown} callback
186
+ * @param {((error: Error) => unknown) | ListenOptions | undefined} cancelCallbackOrListenOptions
187
+ * @param {ListenOptions?} options
188
+ * @returns {Unsubscribe}
189
+ */
190
+ export function onChildMoved(query, callback, cancelCallbackOrListenOptions, options) {
191
+ return addEventListener(query, 'child_moved', callback, cancelCallbackOrListenOptions, options);
192
+ }
193
+
194
+ /**
195
+ * @param {Query} query
196
+ * @param {(snapshot: DataSnapshot, previousChildName: string | null) => unknown} callback
197
+ * @param {((error: Error) => unknown) | ListenOptions | undefined} cancelCallbackOrListenOptions
198
+ * @param {ListenOptions?} options
199
+ * @returns {Unsubscribe}
200
+ */
201
+ export function onChildRemoved(query, callback, cancelCallbackOrListenOptions, options) {
202
+ return addEventListener(query, 'child_removed', callback, cancelCallbackOrListenOptions, options);
203
+ }
204
+
205
+ /**
206
+ * @param {DatabaseReference} ref
207
+ * @param {unknown} value
208
+ * @returns {Promise<void>}
209
+ */
210
+ export function set(ref, value) {
211
+ return ref.set(value);
212
+ }
213
+
214
+ /**
215
+ * @param {DatabaseReference} ref
216
+ * @param {string | number | null} priority
217
+ * @returns {Promise<void>}
218
+ */
219
+ export function setPriority(ref, priority) {
220
+ return ref.setPriority(priority);
221
+ }
222
+
223
+ /**
224
+ * @param {DatabaseReference} ref
225
+ * @param {unknown} value
226
+ * @param {string | number | null} priority
227
+ * @returns {Promise<void>}
228
+ */
229
+ export function setWithPriority(ref, value, priority) {
230
+ return ref.setWithPriority(value, priority);
231
+ }
232
+
233
+ /**
234
+ * @param {Query} query
235
+ * @returns {DataSnapshot}
236
+ */
237
+ export function get(query) {
238
+ return query.once('value');
239
+ }
240
+
241
+ /**
242
+ * @param {DatabaseReference} parent
243
+ * @param {string} path
244
+ * @returns {DatabaseReference}
245
+ */
246
+ export function child(parent, path) {
247
+ return parent.child(path);
248
+ }
249
+
250
+ /**
251
+ * @param {DatabaseReference} ref
252
+ * @returns {OnDisconnect}
253
+ */
254
+ export function onDisconnect(ref) {
255
+ return ref.onDisconnect();
256
+ }
257
+
258
+ /**
259
+ * @param {DatabaseReference} ref
260
+ * @param {boolean} value
261
+ * @returns {Promise<void>}
262
+ */
263
+ export function keepSynced(ref, value) {
264
+ return ref.keepSynced(value);
265
+ }
266
+
267
+ /**
268
+ * @param {DatabaseReference} parent
269
+ * @param {unknown} value
270
+ * @returns {ThenableReference}
271
+ */
272
+ export function push(parent, value) {
273
+ return parent.push(value);
274
+ }
275
+
276
+ /**
277
+ * @param {DatabaseReference} ref
278
+ * @returns {Promise<void>}
279
+ */
280
+ export function remove(ref) {
281
+ return ref.remove();
282
+ }
283
+
284
+ /**
285
+ * @param {DatabaseReference} ref
286
+ * @param {object} values
287
+ * @returns {Promise<void>}
288
+ */
289
+ export function update(ref, values) {
290
+ return ref.update(values);
291
+ }
@@ -0,0 +1,56 @@
1
+ import { FirebaseDatabaseTypes } from '../../index';
2
+
3
+ import TransactionResult = FirebaseDatabaseTypes.TransactionResult;
4
+ import DatabaseReference = FirebaseDatabaseTypes.Reference;
5
+
6
+ export { TransactionResult };
7
+
8
+ /**
9
+ * An options object to configure transactions.
10
+ */
11
+ export interface TransactionOptions {
12
+ readonly applyLocally?: boolean;
13
+ }
14
+
15
+ /**
16
+ * Atomically modifies the data at this location.
17
+ *
18
+ * Atomically modify the data at this location. Unlike a normal `set()`, which
19
+ * just overwrites the data regardless of its previous value, `runTransaction()` is
20
+ * used to modify the existing value to a new value, ensuring there are no
21
+ * conflicts with other clients writing to the same location at the same time.
22
+ *
23
+ * To accomplish this, you pass `runTransaction()` an update function which is
24
+ * used to transform the current value into a new value. If another client
25
+ * writes to the location before your new value is successfully written, your
26
+ * update function will be called again with the new current value, and the
27
+ * write will be retried. This will happen repeatedly until your write succeeds
28
+ * without conflict or you abort the transaction by not returning a value from
29
+ * your update function.
30
+ *
31
+ * Note: Modifying data with `set()` will cancel any pending transactions at
32
+ * that location, so extreme care should be taken if mixing `set()` and
33
+ * `runTransaction()` to update the same data.
34
+ *
35
+ * Note: When using transactions with Security and Firebase Rules in place, be
36
+ * aware that a client needs `.read` access in addition to `.write` access in
37
+ * order to perform a transaction. This is because the client-side nature of
38
+ * transactions requires the client to read the data in order to transactionally
39
+ * update it.
40
+ *
41
+ * @param ref - The location to atomically modify.
42
+ * @param transactionUpdate - A developer-supplied function which will be passed
43
+ * the current data stored at this location (as a JavaScript object). The
44
+ * function should return the new value it would like written (as a JavaScript
45
+ * object). If `undefined` is returned (i.e. you return with no arguments) the
46
+ * transaction will be aborted and the data at this location will not be
47
+ * modified.
48
+ * @param options - An options object to configure transactions.
49
+ * @returns A `Promise` that can optionally be used instead of the `onComplete`
50
+ * callback to handle success and failure.
51
+ */
52
+ export function runTransaction(
53
+ ref: DatabaseReference,
54
+ transactionUpdate: (currentData: any) => unknown,
55
+ options?: TransactionOptions,
56
+ ): Promise<TransactionResult>;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @typedef {import('./database').DatabaseReference} DatabaseReference
3
+ * @typedef {import('./transaction').TransactionOptions} TransactionOptions
4
+ * @typedef {import('./transaction').TransactionResult} TransactionResult
5
+ */
6
+
7
+ /**
8
+ * @param {DatabaseReference} ref
9
+ * @param {(options: any) => unknown} transactionUpdate
10
+ * @param {TransactionOptions?} options
11
+ * @returns {Promise<TransactionResult>}
12
+ */
13
+ export function runTransaction(ref, transactionUpdate, options) {
14
+ return ref.transaction(transactionUpdate, undefined, options && options.applyLocally);
15
+ }
package/lib/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- module.exports = '18.3.2';
2
+ module.exports = '18.5.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-firebase/database",
3
- "version": "18.3.2",
3
+ "version": "18.5.0",
4
4
  "author": "Invertase <oss@invertase.io> (http://invertase.io)",
5
5
  "description": "React Native Firebase - The Firebase Realtime Database is a cloud-hosted database. Data is stored as JSON and synchronized in realtime to every connected client. React Native Firebase provides native integration with the Android & iOS Firebase SDKs, supporting both realtime data sync and offline capabilities.",
6
6
  "main": "lib/index.js",
@@ -25,10 +25,10 @@
25
25
  "realtome database"
26
26
  ],
27
27
  "peerDependencies": {
28
- "@react-native-firebase/app": "18.3.2"
28
+ "@react-native-firebase/app": "18.5.0"
29
29
  },
30
30
  "publishConfig": {
31
31
  "access": "public"
32
32
  },
33
- "gitHead": "f323891622441c9d59a25ef37b19534db512b372"
33
+ "gitHead": "c9b695aa8fd75d5a1d070ecbb6bb9ac4e9ff062e"
34
34
  }