@firebase/firestore-compat 0.4.0-20230301000120 → 0.4.0-20250716004940

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.
Files changed (85) hide show
  1. package/dist/index.cjs.js +980 -972
  2. package/dist/index.cjs.js.map +1 -1
  3. package/dist/{index.esm2017.js → index.esm.js} +981 -973
  4. package/dist/index.esm.js.map +1 -0
  5. package/dist/index.node.cjs.js +980 -972
  6. package/dist/index.node.cjs.js.map +1 -1
  7. package/dist/index.rn.js +980 -972
  8. package/dist/index.rn.js.map +1 -1
  9. package/dist/node-esm/index.node.esm.js +980 -972
  10. package/dist/node-esm/index.node.esm.js.map +1 -1
  11. package/dist/node-esm/src/api/blob.d.ts +29 -29
  12. package/dist/node-esm/src/api/database.d.ts +228 -228
  13. package/dist/node-esm/src/api/field_path.d.ts +36 -36
  14. package/dist/node-esm/src/api/field_value.d.ts +29 -29
  15. package/dist/node-esm/src/api/geo_point.d.ts +17 -17
  16. package/dist/node-esm/src/api/observer.d.ts +29 -29
  17. package/dist/node-esm/src/api/timestamp.d.ts +17 -17
  18. package/dist/node-esm/src/config.d.ts +28 -28
  19. package/dist/node-esm/src/index.console.d.ts +48 -48
  20. package/dist/node-esm/src/index.d.ts +49 -49
  21. package/dist/node-esm/src/index.node.d.ts +22 -22
  22. package/dist/node-esm/src/index.rn.d.ts +22 -22
  23. package/dist/node-esm/src/register-module.d.ts +42 -42
  24. package/dist/node-esm/src/util/input_validation.d.ts +18 -18
  25. package/dist/node-esm/test/array_transforms.test.d.ts +17 -17
  26. package/dist/node-esm/test/batch_writes.test.d.ts +17 -17
  27. package/dist/node-esm/test/bootstrap.d.ts +17 -17
  28. package/dist/node-esm/test/bundle.test.d.ts +17 -17
  29. package/dist/node-esm/test/cursor.test.d.ts +17 -17
  30. package/dist/node-esm/test/database.test.d.ts +17 -17
  31. package/dist/node-esm/test/fields.test.d.ts +17 -17
  32. package/dist/node-esm/test/get_options.test.d.ts +17 -17
  33. package/dist/node-esm/test/numeric_transforms.test.d.ts +17 -17
  34. package/dist/node-esm/test/query.test.d.ts +17 -17
  35. package/dist/node-esm/test/server_timestamp.test.d.ts +17 -17
  36. package/dist/node-esm/test/smoke.test.d.ts +17 -17
  37. package/dist/node-esm/test/transactions.test.d.ts +17 -17
  38. package/dist/node-esm/test/type.test.d.ts +17 -17
  39. package/dist/node-esm/test/util/equality_matcher.d.ts +33 -33
  40. package/dist/node-esm/test/util/events_accumulator.d.ts +39 -39
  41. package/dist/node-esm/test/util/firebase_export.d.ts +29 -29
  42. package/dist/node-esm/test/util/helpers.d.ts +49 -49
  43. package/dist/node-esm/test/util/promise.d.ts +28 -28
  44. package/dist/node-esm/test/util/settings.d.ts +23 -23
  45. package/dist/node-esm/test/validation.test.d.ts +17 -17
  46. package/dist/src/api/blob.d.ts +29 -29
  47. package/dist/src/api/database.d.ts +228 -228
  48. package/dist/src/api/field_path.d.ts +36 -36
  49. package/dist/src/api/field_value.d.ts +29 -29
  50. package/dist/src/api/geo_point.d.ts +17 -17
  51. package/dist/src/api/observer.d.ts +29 -29
  52. package/dist/src/api/timestamp.d.ts +17 -17
  53. package/dist/src/config.d.ts +28 -28
  54. package/dist/src/index.console.d.ts +48 -48
  55. package/dist/src/index.d.ts +117 -85
  56. package/dist/src/index.node.d.ts +22 -22
  57. package/dist/src/index.rn.d.ts +22 -22
  58. package/dist/src/register-module.d.ts +42 -42
  59. package/dist/src/util/input_validation.d.ts +18 -18
  60. package/dist/test/array_transforms.test.d.ts +17 -17
  61. package/dist/test/batch_writes.test.d.ts +17 -17
  62. package/dist/test/bootstrap.d.ts +17 -17
  63. package/dist/test/bundle.test.d.ts +17 -17
  64. package/dist/test/cursor.test.d.ts +17 -17
  65. package/dist/test/database.test.d.ts +17 -17
  66. package/dist/test/fields.test.d.ts +17 -17
  67. package/dist/test/get_options.test.d.ts +17 -17
  68. package/dist/test/numeric_transforms.test.d.ts +17 -17
  69. package/dist/test/query.test.d.ts +17 -17
  70. package/dist/test/server_timestamp.test.d.ts +17 -17
  71. package/dist/test/smoke.test.d.ts +17 -17
  72. package/dist/test/transactions.test.d.ts +17 -17
  73. package/dist/test/type.test.d.ts +17 -17
  74. package/dist/test/util/equality_matcher.d.ts +33 -33
  75. package/dist/test/util/events_accumulator.d.ts +39 -39
  76. package/dist/test/util/firebase_export.d.ts +29 -29
  77. package/dist/test/util/helpers.d.ts +49 -49
  78. package/dist/test/util/promise.d.ts +28 -28
  79. package/dist/test/util/settings.d.ts +23 -23
  80. package/dist/test/validation.test.d.ts +17 -17
  81. package/package.json +25 -23
  82. package/CHANGELOG.md +0 -330
  83. package/dist/index.esm2017.js.map +0 -1
  84. package/dist/index.esm5.js +0 -1196
  85. package/dist/index.esm5.js.map +0 -1
package/dist/index.cjs.js CHANGED
@@ -12,993 +12,1001 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
12
12
  var firebase__default = /*#__PURE__*/_interopDefaultLegacy(firebase);
13
13
 
14
14
  const name = "@firebase/firestore-compat";
15
- const version = "0.4.0-20230301000120";
15
+ const version = "0.4.0-20250716004940";
16
16
 
17
- /**
18
- * @license
19
- * Copyright 2021 Google LLC
20
- *
21
- * Licensed under the Apache License, Version 2.0 (the "License");
22
- * you may not use this file except in compliance with the License.
23
- * You may obtain a copy of the License at
24
- *
25
- * http://www.apache.org/licenses/LICENSE-2.0
26
- *
27
- * Unless required by applicable law or agreed to in writing, software
28
- * distributed under the License is distributed on an "AS IS" BASIS,
29
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30
- * See the License for the specific language governing permissions and
31
- * limitations under the License.
32
- */
33
- function validateSetOptions(methodName, options) {
34
- if (options === undefined) {
35
- return {
36
- merge: false
37
- };
38
- }
39
- if (options.mergeFields !== undefined && options.merge !== undefined) {
40
- throw new firestore.FirestoreError('invalid-argument', `Invalid options passed to function ${methodName}(): You cannot ` +
41
- 'specify both "merge" and "mergeFields".');
42
- }
43
- return options;
17
+ /**
18
+ * @license
19
+ * Copyright 2021 Google LLC
20
+ *
21
+ * Licensed under the Apache License, Version 2.0 (the "License");
22
+ * you may not use this file except in compliance with the License.
23
+ * You may obtain a copy of the License at
24
+ *
25
+ * http://www.apache.org/licenses/LICENSE-2.0
26
+ *
27
+ * Unless required by applicable law or agreed to in writing, software
28
+ * distributed under the License is distributed on an "AS IS" BASIS,
29
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30
+ * See the License for the specific language governing permissions and
31
+ * limitations under the License.
32
+ */
33
+ function validateSetOptions(methodName, options) {
34
+ if (options === undefined) {
35
+ return {
36
+ merge: false
37
+ };
38
+ }
39
+ if (options.mergeFields !== undefined && options.merge !== undefined) {
40
+ throw new firestore.FirestoreError('invalid-argument', `Invalid options passed to function ${methodName}(): You cannot ` +
41
+ 'specify both "merge" and "mergeFields".');
42
+ }
43
+ return options;
44
44
  }
45
45
 
46
- /**
47
- * @license
48
- * Copyright 2017 Google LLC
49
- *
50
- * Licensed under the Apache License, Version 2.0 (the "License");
51
- * you may not use this file except in compliance with the License.
52
- * You may obtain a copy of the License at
53
- *
54
- * http://www.apache.org/licenses/LICENSE-2.0
55
- *
56
- * Unless required by applicable law or agreed to in writing, software
57
- * distributed under the License is distributed on an "AS IS" BASIS,
58
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
59
- * See the License for the specific language governing permissions and
60
- * limitations under the License.
61
- */
62
- /** Helper function to assert Uint8Array is available at runtime. */
63
- function assertUint8ArrayAvailable() {
64
- if (typeof Uint8Array === 'undefined') {
65
- throw new firestore.FirestoreError('unimplemented', 'Uint8Arrays are not available in this environment.');
66
- }
67
- }
68
- /** Helper function to assert Base64 functions are available at runtime. */
69
- function assertBase64Available() {
70
- if (!firestore._isBase64Available()) {
71
- throw new firestore.FirestoreError('unimplemented', 'Blobs are unavailable in Firestore in this environment.');
72
- }
73
- }
74
- /** Immutable class holding a blob (binary data) */
75
- class Blob {
76
- constructor(_delegate) {
77
- this._delegate = _delegate;
78
- }
79
- static fromBase64String(base64) {
80
- assertBase64Available();
81
- return new Blob(firestore.Bytes.fromBase64String(base64));
82
- }
83
- static fromUint8Array(array) {
84
- assertUint8ArrayAvailable();
85
- return new Blob(firestore.Bytes.fromUint8Array(array));
86
- }
87
- toBase64() {
88
- assertBase64Available();
89
- return this._delegate.toBase64();
90
- }
91
- toUint8Array() {
92
- assertUint8ArrayAvailable();
93
- return this._delegate.toUint8Array();
94
- }
95
- isEqual(other) {
96
- return this._delegate.isEqual(other._delegate);
97
- }
98
- toString() {
99
- return 'Blob(base64: ' + this.toBase64() + ')';
100
- }
46
+ /**
47
+ * @license
48
+ * Copyright 2017 Google LLC
49
+ *
50
+ * Licensed under the Apache License, Version 2.0 (the "License");
51
+ * you may not use this file except in compliance with the License.
52
+ * You may obtain a copy of the License at
53
+ *
54
+ * http://www.apache.org/licenses/LICENSE-2.0
55
+ *
56
+ * Unless required by applicable law or agreed to in writing, software
57
+ * distributed under the License is distributed on an "AS IS" BASIS,
58
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
59
+ * See the License for the specific language governing permissions and
60
+ * limitations under the License.
61
+ */
62
+ /** Helper function to assert Uint8Array is available at runtime. */
63
+ function assertUint8ArrayAvailable() {
64
+ if (typeof Uint8Array === 'undefined') {
65
+ throw new firestore.FirestoreError('unimplemented', 'Uint8Arrays are not available in this environment.');
66
+ }
67
+ }
68
+ /** Helper function to assert Base64 functions are available at runtime. */
69
+ function assertBase64Available() {
70
+ if (!firestore._isBase64Available()) {
71
+ throw new firestore.FirestoreError('unimplemented', 'Blobs are unavailable in Firestore in this environment.');
72
+ }
73
+ }
74
+ /** Immutable class holding a blob (binary data) */
75
+ class Blob {
76
+ constructor(_delegate) {
77
+ this._delegate = _delegate;
78
+ }
79
+ static fromBase64String(base64) {
80
+ assertBase64Available();
81
+ return new Blob(firestore.Bytes.fromBase64String(base64));
82
+ }
83
+ static fromUint8Array(array) {
84
+ assertUint8ArrayAvailable();
85
+ return new Blob(firestore.Bytes.fromUint8Array(array));
86
+ }
87
+ toBase64() {
88
+ assertBase64Available();
89
+ return this._delegate.toBase64();
90
+ }
91
+ toUint8Array() {
92
+ assertUint8ArrayAvailable();
93
+ return this._delegate.toUint8Array();
94
+ }
95
+ isEqual(other) {
96
+ return this._delegate.isEqual(other._delegate);
97
+ }
98
+ toString() {
99
+ return 'Blob(base64: ' + this.toBase64() + ')';
100
+ }
101
101
  }
102
102
 
103
- /**
104
- * @license
105
- * Copyright 2017 Google LLC
106
- *
107
- * Licensed under the Apache License, Version 2.0 (the "License");
108
- * you may not use this file except in compliance with the License.
109
- * You may obtain a copy of the License at
110
- *
111
- * http://www.apache.org/licenses/LICENSE-2.0
112
- *
113
- * Unless required by applicable law or agreed to in writing, software
114
- * distributed under the License is distributed on an "AS IS" BASIS,
115
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
116
- * See the License for the specific language governing permissions and
117
- * limitations under the License.
118
- */
119
- function isPartialObserver(obj) {
120
- return implementsAnyMethods(obj, ['next', 'error', 'complete']);
121
- }
122
- /**
123
- * Returns true if obj is an object and contains at least one of the specified
124
- * methods.
125
- */
126
- function implementsAnyMethods(obj, methods) {
127
- if (typeof obj !== 'object' || obj === null) {
128
- return false;
129
- }
130
- const object = obj;
131
- for (const method of methods) {
132
- if (method in object && typeof object[method] === 'function') {
133
- return true;
134
- }
135
- }
136
- return false;
103
+ /**
104
+ * @license
105
+ * Copyright 2017 Google LLC
106
+ *
107
+ * Licensed under the Apache License, Version 2.0 (the "License");
108
+ * you may not use this file except in compliance with the License.
109
+ * You may obtain a copy of the License at
110
+ *
111
+ * http://www.apache.org/licenses/LICENSE-2.0
112
+ *
113
+ * Unless required by applicable law or agreed to in writing, software
114
+ * distributed under the License is distributed on an "AS IS" BASIS,
115
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
116
+ * See the License for the specific language governing permissions and
117
+ * limitations under the License.
118
+ */
119
+ function isPartialObserver(obj) {
120
+ return implementsAnyMethods(obj, ['next', 'error', 'complete']);
121
+ }
122
+ /**
123
+ * Returns true if obj is an object and contains at least one of the specified
124
+ * methods.
125
+ */
126
+ function implementsAnyMethods(obj, methods) {
127
+ if (typeof obj !== 'object' || obj === null) {
128
+ return false;
129
+ }
130
+ const object = obj;
131
+ for (const method of methods) {
132
+ if (method in object && typeof object[method] === 'function') {
133
+ return true;
134
+ }
135
+ }
136
+ return false;
137
137
  }
138
138
 
139
- /**
140
- * @license
141
- * Copyright 2017 Google LLC
142
- *
143
- * Licensed under the Apache License, Version 2.0 (the "License");
144
- * you may not use this file except in compliance with the License.
145
- * You may obtain a copy of the License at
146
- *
147
- * http://www.apache.org/licenses/LICENSE-2.0
148
- *
149
- * Unless required by applicable law or agreed to in writing, software
150
- * distributed under the License is distributed on an "AS IS" BASIS,
151
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
152
- * See the License for the specific language governing permissions and
153
- * limitations under the License.
154
- */
155
- /**
156
- * The persistence provider included with the full Firestore SDK.
157
- */
158
- class IndexedDbPersistenceProvider {
159
- enableIndexedDbPersistence(firestore$1, forceOwnership) {
160
- return firestore.enableIndexedDbPersistence(firestore$1._delegate, { forceOwnership });
161
- }
162
- enableMultiTabIndexedDbPersistence(firestore$1) {
163
- return firestore.enableMultiTabIndexedDbPersistence(firestore$1._delegate);
164
- }
165
- clearIndexedDbPersistence(firestore$1) {
166
- return firestore.clearIndexedDbPersistence(firestore$1._delegate);
167
- }
168
- }
169
- /**
170
- * Compat class for Firestore. Exposes Firestore Legacy API, but delegates
171
- * to the functional API of firestore-exp.
172
- */
173
- class Firestore {
174
- constructor(databaseIdOrApp, _delegate, _persistenceProvider) {
175
- this._delegate = _delegate;
176
- this._persistenceProvider = _persistenceProvider;
177
- this.INTERNAL = {
178
- delete: () => this.terminate()
179
- };
180
- if (!(databaseIdOrApp instanceof firestore._DatabaseId)) {
181
- this._appCompat = databaseIdOrApp;
182
- }
183
- }
184
- get _databaseId() {
185
- return this._delegate._databaseId;
186
- }
187
- settings(settingsLiteral) {
188
- const currentSettings = this._delegate._getSettings();
189
- if (!settingsLiteral.merge &&
190
- currentSettings.host !== settingsLiteral.host) {
191
- firestore._logWarn('You are overriding the original host. If you did not intend ' +
192
- 'to override your settings, use {merge: true}.');
193
- }
194
- if (settingsLiteral.merge) {
195
- settingsLiteral = Object.assign(Object.assign({}, currentSettings), settingsLiteral);
196
- // Remove the property from the settings once the merge is completed
197
- delete settingsLiteral.merge;
198
- }
199
- this._delegate._setSettings(settingsLiteral);
200
- }
201
- useEmulator(host, port, options = {}) {
202
- firestore.connectFirestoreEmulator(this._delegate, host, port, options);
203
- }
204
- enableNetwork() {
205
- return firestore.enableNetwork(this._delegate);
206
- }
207
- disableNetwork() {
208
- return firestore.disableNetwork(this._delegate);
209
- }
210
- enablePersistence(settings) {
211
- let synchronizeTabs = false;
212
- let experimentalForceOwningTab = false;
213
- if (settings) {
214
- synchronizeTabs = !!settings.synchronizeTabs;
215
- experimentalForceOwningTab = !!settings.experimentalForceOwningTab;
216
- firestore._validateIsNotUsedTogether('synchronizeTabs', synchronizeTabs, 'experimentalForceOwningTab', experimentalForceOwningTab);
217
- }
218
- return synchronizeTabs
219
- ? this._persistenceProvider.enableMultiTabIndexedDbPersistence(this)
220
- : this._persistenceProvider.enableIndexedDbPersistence(this, experimentalForceOwningTab);
221
- }
222
- clearPersistence() {
223
- return this._persistenceProvider.clearIndexedDbPersistence(this);
224
- }
225
- terminate() {
226
- if (this._appCompat) {
227
- this._appCompat._removeServiceInstance('firestore-compat');
228
- this._appCompat._removeServiceInstance('firestore');
229
- }
230
- return this._delegate._delete();
231
- }
232
- waitForPendingWrites() {
233
- return firestore.waitForPendingWrites(this._delegate);
234
- }
235
- onSnapshotsInSync(arg) {
236
- return firestore.onSnapshotsInSync(this._delegate, arg);
237
- }
238
- get app() {
239
- if (!this._appCompat) {
240
- throw new firestore.FirestoreError('failed-precondition', "Firestore was not initialized using the Firebase SDK. 'app' is " +
241
- 'not available');
242
- }
243
- return this._appCompat;
244
- }
245
- collection(pathString) {
246
- try {
247
- return new CollectionReference(this, firestore.collection(this._delegate, pathString));
248
- }
249
- catch (e) {
250
- throw replaceFunctionName(e, 'collection()', 'Firestore.collection()');
251
- }
252
- }
253
- doc(pathString) {
254
- try {
255
- return new DocumentReference(this, firestore.doc(this._delegate, pathString));
256
- }
257
- catch (e) {
258
- throw replaceFunctionName(e, 'doc()', 'Firestore.doc()');
259
- }
260
- }
261
- collectionGroup(collectionId) {
262
- try {
263
- return new Query(this, firestore.collectionGroup(this._delegate, collectionId));
264
- }
265
- catch (e) {
266
- throw replaceFunctionName(e, 'collectionGroup()', 'Firestore.collectionGroup()');
267
- }
268
- }
269
- runTransaction(updateFunction) {
270
- return firestore.runTransaction(this._delegate, transaction => updateFunction(new Transaction(this, transaction)));
271
- }
272
- batch() {
273
- firestore.ensureFirestoreConfigured(this._delegate);
274
- return new WriteBatch(new firestore.WriteBatch(this._delegate, mutations => firestore.executeWrite(this._delegate, mutations)));
275
- }
276
- loadBundle(bundleData) {
277
- return firestore.loadBundle(this._delegate, bundleData);
278
- }
279
- namedQuery(name) {
280
- return firestore.namedQuery(this._delegate, name).then(expQuery => {
281
- if (!expQuery) {
282
- return null;
283
- }
284
- return new Query(this,
285
- // We can pass `expQuery` here directly since named queries don't have a UserDataConverter.
286
- // Otherwise, we would have to create a new ExpQuery and pass the old UserDataConverter.
287
- expQuery);
288
- });
289
- }
290
- }
291
- class UserDataWriter extends firestore.AbstractUserDataWriter {
292
- constructor(firestore) {
293
- super();
294
- this.firestore = firestore;
295
- }
296
- convertBytes(bytes) {
297
- return new Blob(new firestore.Bytes(bytes));
298
- }
299
- convertReference(name) {
300
- const key = this.convertDocumentKey(name, this.firestore._databaseId);
301
- return DocumentReference.forKey(key, this.firestore, /* converter= */ null);
302
- }
303
- }
304
- function setLogLevel(level) {
305
- firestore.setLogLevel(level);
306
- }
307
- /**
308
- * A reference to a transaction.
309
- */
310
- class Transaction {
311
- constructor(_firestore, _delegate) {
312
- this._firestore = _firestore;
313
- this._delegate = _delegate;
314
- this._userDataWriter = new UserDataWriter(_firestore);
315
- }
316
- get(documentRef) {
317
- const ref = castReference(documentRef);
318
- return this._delegate
319
- .get(ref)
320
- .then(result => new DocumentSnapshot(this._firestore, new firestore.DocumentSnapshot(this._firestore._delegate, this._userDataWriter, result._key, result._document, result.metadata, ref.converter)));
321
- }
322
- set(documentRef, data, options) {
323
- const ref = castReference(documentRef);
324
- if (options) {
325
- validateSetOptions('Transaction.set', options);
326
- this._delegate.set(ref, data, options);
327
- }
328
- else {
329
- this._delegate.set(ref, data);
330
- }
331
- return this;
332
- }
333
- update(documentRef, dataOrField, value, ...moreFieldsAndValues) {
334
- const ref = castReference(documentRef);
335
- if (arguments.length === 2) {
336
- this._delegate.update(ref, dataOrField);
337
- }
338
- else {
339
- this._delegate.update(ref, dataOrField, value, ...moreFieldsAndValues);
340
- }
341
- return this;
342
- }
343
- delete(documentRef) {
344
- const ref = castReference(documentRef);
345
- this._delegate.delete(ref);
346
- return this;
347
- }
348
- }
349
- class WriteBatch {
350
- constructor(_delegate) {
351
- this._delegate = _delegate;
352
- }
353
- set(documentRef, data, options) {
354
- const ref = castReference(documentRef);
355
- if (options) {
356
- validateSetOptions('WriteBatch.set', options);
357
- this._delegate.set(ref, data, options);
358
- }
359
- else {
360
- this._delegate.set(ref, data);
361
- }
362
- return this;
363
- }
364
- update(documentRef, dataOrField, value, ...moreFieldsAndValues) {
365
- const ref = castReference(documentRef);
366
- if (arguments.length === 2) {
367
- this._delegate.update(ref, dataOrField);
368
- }
369
- else {
370
- this._delegate.update(ref, dataOrField, value, ...moreFieldsAndValues);
371
- }
372
- return this;
373
- }
374
- delete(documentRef) {
375
- const ref = castReference(documentRef);
376
- this._delegate.delete(ref);
377
- return this;
378
- }
379
- commit() {
380
- return this._delegate.commit();
381
- }
382
- }
383
- /**
384
- * Wraps a `PublicFirestoreDataConverter` translating the types from the
385
- * experimental SDK into corresponding types from the Classic SDK before passing
386
- * them to the wrapped converter.
387
- */
388
- class FirestoreDataConverter {
389
- constructor(_firestore, _userDataWriter, _delegate) {
390
- this._firestore = _firestore;
391
- this._userDataWriter = _userDataWriter;
392
- this._delegate = _delegate;
393
- }
394
- fromFirestore(snapshot, options) {
395
- const expSnapshot = new firestore.QueryDocumentSnapshot(this._firestore._delegate, this._userDataWriter, snapshot._key, snapshot._document, snapshot.metadata,
396
- /* converter= */ null);
397
- return this._delegate.fromFirestore(new QueryDocumentSnapshot(this._firestore, expSnapshot), options !== null && options !== void 0 ? options : {});
398
- }
399
- toFirestore(modelObject, options) {
400
- if (!options) {
401
- return this._delegate.toFirestore(modelObject);
402
- }
403
- else {
404
- return this._delegate.toFirestore(modelObject, options);
405
- }
406
- }
407
- // Use the same instance of `FirestoreDataConverter` for the given instances
408
- // of `Firestore` and `PublicFirestoreDataConverter` so that isEqual() will
409
- // compare equal for two objects created with the same converter instance.
410
- static getInstance(firestore, converter) {
411
- const converterMapByFirestore = FirestoreDataConverter.INSTANCES;
412
- let untypedConverterByConverter = converterMapByFirestore.get(firestore);
413
- if (!untypedConverterByConverter) {
414
- untypedConverterByConverter = new WeakMap();
415
- converterMapByFirestore.set(firestore, untypedConverterByConverter);
416
- }
417
- let instance = untypedConverterByConverter.get(converter);
418
- if (!instance) {
419
- instance = new FirestoreDataConverter(firestore, new UserDataWriter(firestore), converter);
420
- untypedConverterByConverter.set(converter, instance);
421
- }
422
- return instance;
423
- }
424
- }
425
- FirestoreDataConverter.INSTANCES = new WeakMap();
426
- /**
427
- * A reference to a particular document in a collection in the database.
428
- */
429
- class DocumentReference {
430
- constructor(firestore, _delegate) {
431
- this.firestore = firestore;
432
- this._delegate = _delegate;
433
- this._userDataWriter = new UserDataWriter(firestore);
434
- }
435
- static forPath(path, firestore$1, converter) {
436
- if (path.length % 2 !== 0) {
437
- throw new firestore.FirestoreError('invalid-argument', 'Invalid document reference. Document ' +
438
- 'references must have an even number of segments, but ' +
439
- `${path.canonicalString()} has ${path.length}`);
440
- }
441
- return new DocumentReference(firestore$1, new firestore.DocumentReference(firestore$1._delegate, converter, new firestore._DocumentKey(path)));
442
- }
443
- static forKey(key, firestore$1, converter) {
444
- return new DocumentReference(firestore$1, new firestore.DocumentReference(firestore$1._delegate, converter, key));
445
- }
446
- get id() {
447
- return this._delegate.id;
448
- }
449
- get parent() {
450
- return new CollectionReference(this.firestore, this._delegate.parent);
451
- }
452
- get path() {
453
- return this._delegate.path;
454
- }
455
- collection(pathString) {
456
- try {
457
- return new CollectionReference(this.firestore, firestore.collection(this._delegate, pathString));
458
- }
459
- catch (e) {
460
- throw replaceFunctionName(e, 'collection()', 'DocumentReference.collection()');
461
- }
462
- }
463
- isEqual(other) {
464
- other = util.getModularInstance(other);
465
- if (!(other instanceof firestore.DocumentReference)) {
466
- return false;
467
- }
468
- return firestore.refEqual(this._delegate, other);
469
- }
470
- set(value, options) {
471
- options = validateSetOptions('DocumentReference.set', options);
472
- try {
473
- if (options) {
474
- return firestore.setDoc(this._delegate, value, options);
475
- }
476
- else {
477
- return firestore.setDoc(this._delegate, value);
478
- }
479
- }
480
- catch (e) {
481
- throw replaceFunctionName(e, 'setDoc()', 'DocumentReference.set()');
482
- }
483
- }
484
- update(fieldOrUpdateData, value, ...moreFieldsAndValues) {
485
- try {
486
- if (arguments.length === 1) {
487
- return firestore.updateDoc(this._delegate, fieldOrUpdateData);
488
- }
489
- else {
490
- return firestore.updateDoc(this._delegate, fieldOrUpdateData, value, ...moreFieldsAndValues);
491
- }
492
- }
493
- catch (e) {
494
- throw replaceFunctionName(e, 'updateDoc()', 'DocumentReference.update()');
495
- }
496
- }
497
- delete() {
498
- return firestore.deleteDoc(this._delegate);
499
- }
500
- onSnapshot(...args) {
501
- const options = extractSnapshotOptions(args);
502
- const observer = wrapObserver(args, result => new DocumentSnapshot(this.firestore, new firestore.DocumentSnapshot(this.firestore._delegate, this._userDataWriter, result._key, result._document, result.metadata, this._delegate.converter)));
503
- return firestore.onSnapshot(this._delegate, options, observer);
504
- }
505
- get(options) {
506
- let snap;
507
- if ((options === null || options === void 0 ? void 0 : options.source) === 'cache') {
508
- snap = firestore.getDocFromCache(this._delegate);
509
- }
510
- else if ((options === null || options === void 0 ? void 0 : options.source) === 'server') {
511
- snap = firestore.getDocFromServer(this._delegate);
512
- }
513
- else {
514
- snap = firestore.getDoc(this._delegate);
515
- }
516
- return snap.then(result => new DocumentSnapshot(this.firestore, new firestore.DocumentSnapshot(this.firestore._delegate, this._userDataWriter, result._key, result._document, result.metadata, this._delegate.converter)));
517
- }
518
- withConverter(converter) {
519
- return new DocumentReference(this.firestore, converter
520
- ? this._delegate.withConverter(FirestoreDataConverter.getInstance(this.firestore, converter))
521
- : this._delegate.withConverter(null));
522
- }
523
- }
524
- /**
525
- * Replaces the function name in an error thrown by the firestore-exp API
526
- * with the function names used in the classic API.
527
- */
528
- function replaceFunctionName(e, original, updated) {
529
- e.message = e.message.replace(original, updated);
530
- return e;
531
- }
532
- /**
533
- * Iterates the list of arguments from an `onSnapshot` call and returns the
534
- * first argument that may be an `SnapshotListenOptions` object. Returns an
535
- * empty object if none is found.
536
- */
537
- function extractSnapshotOptions(args) {
538
- for (const arg of args) {
539
- if (typeof arg === 'object' && !isPartialObserver(arg)) {
540
- return arg;
541
- }
542
- }
543
- return {};
544
- }
545
- /**
546
- * Creates an observer that can be passed to the firestore-exp SDK. The
547
- * observer converts all observed values into the format expected by the classic
548
- * SDK.
549
- *
550
- * @param args - The list of arguments from an `onSnapshot` call.
551
- * @param wrapper - The function that converts the firestore-exp type into the
552
- * type used by this shim.
553
- */
554
- function wrapObserver(args, wrapper) {
555
- var _a, _b;
556
- let userObserver;
557
- if (isPartialObserver(args[0])) {
558
- userObserver = args[0];
559
- }
560
- else if (isPartialObserver(args[1])) {
561
- userObserver = args[1];
562
- }
563
- else if (typeof args[0] === 'function') {
564
- userObserver = {
565
- next: args[0],
566
- error: args[1],
567
- complete: args[2]
568
- };
569
- }
570
- else {
571
- userObserver = {
572
- next: args[1],
573
- error: args[2],
574
- complete: args[3]
575
- };
576
- }
577
- return {
578
- next: val => {
579
- if (userObserver.next) {
580
- userObserver.next(wrapper(val));
581
- }
582
- },
583
- error: (_a = userObserver.error) === null || _a === void 0 ? void 0 : _a.bind(userObserver),
584
- complete: (_b = userObserver.complete) === null || _b === void 0 ? void 0 : _b.bind(userObserver)
585
- };
586
- }
587
- class DocumentSnapshot {
588
- constructor(_firestore, _delegate) {
589
- this._firestore = _firestore;
590
- this._delegate = _delegate;
591
- }
592
- get ref() {
593
- return new DocumentReference(this._firestore, this._delegate.ref);
594
- }
595
- get id() {
596
- return this._delegate.id;
597
- }
598
- get metadata() {
599
- return this._delegate.metadata;
600
- }
601
- get exists() {
602
- return this._delegate.exists();
603
- }
604
- data(options) {
605
- return this._delegate.data(options);
606
- }
607
- get(fieldPath, options
608
- // We are using `any` here to avoid an explicit cast by our users.
609
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
610
- ) {
611
- return this._delegate.get(fieldPath, options);
612
- }
613
- isEqual(other) {
614
- return firestore.snapshotEqual(this._delegate, other._delegate);
615
- }
616
- }
617
- class QueryDocumentSnapshot extends DocumentSnapshot {
618
- data(options) {
619
- const data = this._delegate.data(options);
620
- firestore._debugAssert(data !== undefined, 'Document in a QueryDocumentSnapshot should exist');
621
- return data;
622
- }
623
- }
624
- class Query {
625
- constructor(firestore, _delegate) {
626
- this.firestore = firestore;
627
- this._delegate = _delegate;
628
- this._userDataWriter = new UserDataWriter(firestore);
629
- }
630
- where(fieldPath, opStr, value) {
631
- try {
632
- // The "as string" cast is a little bit of a hack. `where` accepts the
633
- // FieldPath Compat type as input, but is not typed as such in order to
634
- // not expose this via our public typings file.
635
- return new Query(this.firestore, firestore.query(this._delegate, firestore.where(fieldPath, opStr, value)));
636
- }
637
- catch (e) {
638
- throw replaceFunctionName(e, /(orderBy|where)\(\)/, 'Query.$1()');
639
- }
640
- }
641
- orderBy(fieldPath, directionStr) {
642
- try {
643
- // The "as string" cast is a little bit of a hack. `orderBy` accepts the
644
- // FieldPath Compat type as input, but is not typed as such in order to
645
- // not expose this via our public typings file.
646
- return new Query(this.firestore, firestore.query(this._delegate, firestore.orderBy(fieldPath, directionStr)));
647
- }
648
- catch (e) {
649
- throw replaceFunctionName(e, /(orderBy|where)\(\)/, 'Query.$1()');
650
- }
651
- }
652
- limit(n) {
653
- try {
654
- return new Query(this.firestore, firestore.query(this._delegate, firestore.limit(n)));
655
- }
656
- catch (e) {
657
- throw replaceFunctionName(e, 'limit()', 'Query.limit()');
658
- }
659
- }
660
- limitToLast(n) {
661
- try {
662
- return new Query(this.firestore, firestore.query(this._delegate, firestore.limitToLast(n)));
663
- }
664
- catch (e) {
665
- throw replaceFunctionName(e, 'limitToLast()', 'Query.limitToLast()');
666
- }
667
- }
668
- startAt(...args) {
669
- try {
670
- return new Query(this.firestore, firestore.query(this._delegate, firestore.startAt(...args)));
671
- }
672
- catch (e) {
673
- throw replaceFunctionName(e, 'startAt()', 'Query.startAt()');
674
- }
675
- }
676
- startAfter(...args) {
677
- try {
678
- return new Query(this.firestore, firestore.query(this._delegate, firestore.startAfter(...args)));
679
- }
680
- catch (e) {
681
- throw replaceFunctionName(e, 'startAfter()', 'Query.startAfter()');
682
- }
683
- }
684
- endBefore(...args) {
685
- try {
686
- return new Query(this.firestore, firestore.query(this._delegate, firestore.endBefore(...args)));
687
- }
688
- catch (e) {
689
- throw replaceFunctionName(e, 'endBefore()', 'Query.endBefore()');
690
- }
691
- }
692
- endAt(...args) {
693
- try {
694
- return new Query(this.firestore, firestore.query(this._delegate, firestore.endAt(...args)));
695
- }
696
- catch (e) {
697
- throw replaceFunctionName(e, 'endAt()', 'Query.endAt()');
698
- }
699
- }
700
- isEqual(other) {
701
- return firestore.queryEqual(this._delegate, other._delegate);
702
- }
703
- get(options) {
704
- let query;
705
- if ((options === null || options === void 0 ? void 0 : options.source) === 'cache') {
706
- query = firestore.getDocsFromCache(this._delegate);
707
- }
708
- else if ((options === null || options === void 0 ? void 0 : options.source) === 'server') {
709
- query = firestore.getDocsFromServer(this._delegate);
710
- }
711
- else {
712
- query = firestore.getDocs(this._delegate);
713
- }
714
- return query.then(result => new QuerySnapshot(this.firestore, new firestore.QuerySnapshot(this.firestore._delegate, this._userDataWriter, this._delegate, result._snapshot)));
715
- }
716
- onSnapshot(...args) {
717
- const options = extractSnapshotOptions(args);
718
- const observer = wrapObserver(args, snap => new QuerySnapshot(this.firestore, new firestore.QuerySnapshot(this.firestore._delegate, this._userDataWriter, this._delegate, snap._snapshot)));
719
- return firestore.onSnapshot(this._delegate, options, observer);
720
- }
721
- withConverter(converter) {
722
- return new Query(this.firestore, converter
723
- ? this._delegate.withConverter(FirestoreDataConverter.getInstance(this.firestore, converter))
724
- : this._delegate.withConverter(null));
725
- }
726
- }
727
- class DocumentChange {
728
- constructor(_firestore, _delegate) {
729
- this._firestore = _firestore;
730
- this._delegate = _delegate;
731
- }
732
- get type() {
733
- return this._delegate.type;
734
- }
735
- get doc() {
736
- return new QueryDocumentSnapshot(this._firestore, this._delegate.doc);
737
- }
738
- get oldIndex() {
739
- return this._delegate.oldIndex;
740
- }
741
- get newIndex() {
742
- return this._delegate.newIndex;
743
- }
744
- }
745
- class QuerySnapshot {
746
- constructor(_firestore, _delegate) {
747
- this._firestore = _firestore;
748
- this._delegate = _delegate;
749
- }
750
- get query() {
751
- return new Query(this._firestore, this._delegate.query);
752
- }
753
- get metadata() {
754
- return this._delegate.metadata;
755
- }
756
- get size() {
757
- return this._delegate.size;
758
- }
759
- get empty() {
760
- return this._delegate.empty;
761
- }
762
- get docs() {
763
- return this._delegate.docs.map(doc => new QueryDocumentSnapshot(this._firestore, doc));
764
- }
765
- docChanges(options) {
766
- return this._delegate
767
- .docChanges(options)
768
- .map(docChange => new DocumentChange(this._firestore, docChange));
769
- }
770
- forEach(callback, thisArg) {
771
- this._delegate.forEach(snapshot => {
772
- callback.call(thisArg, new QueryDocumentSnapshot(this._firestore, snapshot));
773
- });
774
- }
775
- isEqual(other) {
776
- return firestore.snapshotEqual(this._delegate, other._delegate);
777
- }
778
- }
779
- class CollectionReference extends Query {
780
- constructor(firestore, _delegate) {
781
- super(firestore, _delegate);
782
- this.firestore = firestore;
783
- this._delegate = _delegate;
784
- }
785
- get id() {
786
- return this._delegate.id;
787
- }
788
- get path() {
789
- return this._delegate.path;
790
- }
791
- get parent() {
792
- const docRef = this._delegate.parent;
793
- return docRef ? new DocumentReference(this.firestore, docRef) : null;
794
- }
795
- doc(documentPath) {
796
- try {
797
- if (documentPath === undefined) {
798
- // Call `doc` without `documentPath` if `documentPath` is `undefined`
799
- // as `doc` validates the number of arguments to prevent users from
800
- // accidentally passing `undefined`.
801
- return new DocumentReference(this.firestore, firestore.doc(this._delegate));
802
- }
803
- else {
804
- return new DocumentReference(this.firestore, firestore.doc(this._delegate, documentPath));
805
- }
806
- }
807
- catch (e) {
808
- throw replaceFunctionName(e, 'doc()', 'CollectionReference.doc()');
809
- }
810
- }
811
- add(data) {
812
- return firestore.addDoc(this._delegate, data).then(docRef => new DocumentReference(this.firestore, docRef));
813
- }
814
- isEqual(other) {
815
- return firestore.refEqual(this._delegate, other._delegate);
816
- }
817
- withConverter(converter) {
818
- return new CollectionReference(this.firestore, converter
819
- ? this._delegate.withConverter(FirestoreDataConverter.getInstance(this.firestore, converter))
820
- : this._delegate.withConverter(null));
821
- }
822
- }
823
- function castReference(documentRef) {
824
- return firestore._cast(documentRef, firestore.DocumentReference);
139
+ /**
140
+ * @license
141
+ * Copyright 2017 Google LLC
142
+ *
143
+ * Licensed under the Apache License, Version 2.0 (the "License");
144
+ * you may not use this file except in compliance with the License.
145
+ * You may obtain a copy of the License at
146
+ *
147
+ * http://www.apache.org/licenses/LICENSE-2.0
148
+ *
149
+ * Unless required by applicable law or agreed to in writing, software
150
+ * distributed under the License is distributed on an "AS IS" BASIS,
151
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
152
+ * See the License for the specific language governing permissions and
153
+ * limitations under the License.
154
+ */
155
+ /**
156
+ * The persistence provider included with the full Firestore SDK.
157
+ */
158
+ class IndexedDbPersistenceProvider {
159
+ enableIndexedDbPersistence(firestore$1, forceOwnership) {
160
+ return firestore.enableIndexedDbPersistence(firestore$1._delegate, { forceOwnership });
161
+ }
162
+ enableMultiTabIndexedDbPersistence(firestore$1) {
163
+ return firestore.enableMultiTabIndexedDbPersistence(firestore$1._delegate);
164
+ }
165
+ clearIndexedDbPersistence(firestore$1) {
166
+ return firestore.clearIndexedDbPersistence(firestore$1._delegate);
167
+ }
168
+ }
169
+ /**
170
+ * Compat class for Firestore. Exposes Firestore Legacy API, but delegates
171
+ * to the functional API of firestore-exp.
172
+ */
173
+ class Firestore {
174
+ constructor(databaseIdOrApp, _delegate, _persistenceProvider) {
175
+ this._delegate = _delegate;
176
+ this._persistenceProvider = _persistenceProvider;
177
+ this.INTERNAL = {
178
+ delete: () => this.terminate()
179
+ };
180
+ if (!(databaseIdOrApp instanceof firestore._DatabaseId)) {
181
+ this._appCompat = databaseIdOrApp;
182
+ }
183
+ }
184
+ get _databaseId() {
185
+ return this._delegate._databaseId;
186
+ }
187
+ settings(settingsLiteral) {
188
+ const currentSettings = this._delegate._getSettings();
189
+ if (!settingsLiteral.merge &&
190
+ currentSettings.host !== settingsLiteral.host) {
191
+ firestore._logWarn('You are overriding the original host. If you did not intend ' +
192
+ 'to override your settings, use {merge: true}.');
193
+ }
194
+ if (settingsLiteral.merge) {
195
+ settingsLiteral = {
196
+ ...currentSettings,
197
+ ...settingsLiteral
198
+ };
199
+ // Remove the property from the settings once the merge is completed
200
+ delete settingsLiteral.merge;
201
+ }
202
+ this._delegate._setSettings(settingsLiteral);
203
+ }
204
+ useEmulator(host, port, options = {}) {
205
+ firestore.connectFirestoreEmulator(this._delegate, host, port, options);
206
+ }
207
+ enableNetwork() {
208
+ return firestore.enableNetwork(this._delegate);
209
+ }
210
+ disableNetwork() {
211
+ return firestore.disableNetwork(this._delegate);
212
+ }
213
+ enablePersistence(settings) {
214
+ let synchronizeTabs = false;
215
+ let experimentalForceOwningTab = false;
216
+ if (settings) {
217
+ synchronizeTabs = !!settings.synchronizeTabs;
218
+ experimentalForceOwningTab = !!settings.experimentalForceOwningTab;
219
+ firestore._validateIsNotUsedTogether('synchronizeTabs', synchronizeTabs, 'experimentalForceOwningTab', experimentalForceOwningTab);
220
+ }
221
+ return synchronizeTabs
222
+ ? this._persistenceProvider.enableMultiTabIndexedDbPersistence(this)
223
+ : this._persistenceProvider.enableIndexedDbPersistence(this, experimentalForceOwningTab);
224
+ }
225
+ clearPersistence() {
226
+ return this._persistenceProvider.clearIndexedDbPersistence(this);
227
+ }
228
+ terminate() {
229
+ if (this._appCompat) {
230
+ this._appCompat._removeServiceInstance('firestore-compat');
231
+ this._appCompat._removeServiceInstance('firestore');
232
+ }
233
+ return this._delegate._delete();
234
+ }
235
+ waitForPendingWrites() {
236
+ return firestore.waitForPendingWrites(this._delegate);
237
+ }
238
+ onSnapshotsInSync(arg) {
239
+ return firestore.onSnapshotsInSync(this._delegate, arg);
240
+ }
241
+ get app() {
242
+ if (!this._appCompat) {
243
+ throw new firestore.FirestoreError('failed-precondition', "Firestore was not initialized using the Firebase SDK. 'app' is " +
244
+ 'not available');
245
+ }
246
+ return this._appCompat;
247
+ }
248
+ collection(pathString) {
249
+ try {
250
+ return new CollectionReference(this, firestore.collection(this._delegate, pathString));
251
+ }
252
+ catch (e) {
253
+ throw replaceFunctionName(e, 'collection()', 'Firestore.collection()');
254
+ }
255
+ }
256
+ doc(pathString) {
257
+ try {
258
+ return new DocumentReference(this, firestore.doc(this._delegate, pathString));
259
+ }
260
+ catch (e) {
261
+ throw replaceFunctionName(e, 'doc()', 'Firestore.doc()');
262
+ }
263
+ }
264
+ collectionGroup(collectionId) {
265
+ try {
266
+ return new Query(this, firestore.collectionGroup(this._delegate, collectionId));
267
+ }
268
+ catch (e) {
269
+ throw replaceFunctionName(e, 'collectionGroup()', 'Firestore.collectionGroup()');
270
+ }
271
+ }
272
+ runTransaction(updateFunction) {
273
+ return firestore.runTransaction(this._delegate, transaction => updateFunction(new Transaction(this, transaction)));
274
+ }
275
+ batch() {
276
+ firestore.ensureFirestoreConfigured(this._delegate);
277
+ return new WriteBatch(new firestore.WriteBatch(this._delegate, mutations => firestore.executeWrite(this._delegate, mutations)));
278
+ }
279
+ loadBundle(bundleData) {
280
+ return firestore.loadBundle(this._delegate, bundleData);
281
+ }
282
+ namedQuery(name) {
283
+ return firestore.namedQuery(this._delegate, name).then(expQuery => {
284
+ if (!expQuery) {
285
+ return null;
286
+ }
287
+ return new Query(this,
288
+ // We can pass `expQuery` here directly since named queries don't have a UserDataConverter.
289
+ // Otherwise, we would have to create a new ExpQuery and pass the old UserDataConverter.
290
+ expQuery);
291
+ });
292
+ }
293
+ }
294
+ class UserDataWriter extends firestore.AbstractUserDataWriter {
295
+ constructor(firestore) {
296
+ super();
297
+ this.firestore = firestore;
298
+ }
299
+ convertBytes(bytes) {
300
+ return new Blob(new firestore.Bytes(bytes));
301
+ }
302
+ convertReference(name) {
303
+ const key = this.convertDocumentKey(name, this.firestore._databaseId);
304
+ return DocumentReference.forKey(key, this.firestore, /* converter= */ null);
305
+ }
306
+ }
307
+ function setLogLevel(level) {
308
+ firestore.setLogLevel(level);
309
+ }
310
+ /**
311
+ * A reference to a transaction.
312
+ */
313
+ class Transaction {
314
+ constructor(_firestore, _delegate) {
315
+ this._firestore = _firestore;
316
+ this._delegate = _delegate;
317
+ this._userDataWriter = new UserDataWriter(_firestore);
318
+ }
319
+ get(documentRef) {
320
+ const ref = castReference(documentRef);
321
+ return this._delegate
322
+ .get(ref)
323
+ .then(result => new DocumentSnapshot(this._firestore, new firestore.DocumentSnapshot(this._firestore._delegate, this._userDataWriter, result._key, result._document, result.metadata, ref.converter)));
324
+ }
325
+ set(documentRef, data, options) {
326
+ const ref = castReference(documentRef);
327
+ if (options) {
328
+ validateSetOptions('Transaction.set', options);
329
+ this._delegate.set(ref, data, options);
330
+ }
331
+ else {
332
+ this._delegate.set(ref, data);
333
+ }
334
+ return this;
335
+ }
336
+ update(documentRef, dataOrField, value, ...moreFieldsAndValues) {
337
+ const ref = castReference(documentRef);
338
+ if (arguments.length === 2) {
339
+ this._delegate.update(ref, dataOrField);
340
+ }
341
+ else {
342
+ this._delegate.update(ref, dataOrField, value, ...moreFieldsAndValues);
343
+ }
344
+ return this;
345
+ }
346
+ delete(documentRef) {
347
+ const ref = castReference(documentRef);
348
+ this._delegate.delete(ref);
349
+ return this;
350
+ }
351
+ }
352
+ class WriteBatch {
353
+ constructor(_delegate) {
354
+ this._delegate = _delegate;
355
+ }
356
+ set(documentRef, data, options) {
357
+ const ref = castReference(documentRef);
358
+ if (options) {
359
+ validateSetOptions('WriteBatch.set', options);
360
+ this._delegate.set(ref, data, options);
361
+ }
362
+ else {
363
+ this._delegate.set(ref, data);
364
+ }
365
+ return this;
366
+ }
367
+ update(documentRef, dataOrField, value, ...moreFieldsAndValues) {
368
+ const ref = castReference(documentRef);
369
+ if (arguments.length === 2) {
370
+ this._delegate.update(ref, dataOrField);
371
+ }
372
+ else {
373
+ this._delegate.update(ref, dataOrField, value, ...moreFieldsAndValues);
374
+ }
375
+ return this;
376
+ }
377
+ delete(documentRef) {
378
+ const ref = castReference(documentRef);
379
+ this._delegate.delete(ref);
380
+ return this;
381
+ }
382
+ commit() {
383
+ return this._delegate.commit();
384
+ }
385
+ }
386
+ /**
387
+ * Wraps a `PublicFirestoreDataConverter` translating the types from the
388
+ * experimental SDK into corresponding types from the Classic SDK before passing
389
+ * them to the wrapped converter.
390
+ */
391
+ class FirestoreDataConverter {
392
+ constructor(_firestore, _userDataWriter, _delegate) {
393
+ this._firestore = _firestore;
394
+ this._userDataWriter = _userDataWriter;
395
+ this._delegate = _delegate;
396
+ }
397
+ fromFirestore(snapshot, options) {
398
+ const expSnapshot = new firestore.QueryDocumentSnapshot(this._firestore._delegate, this._userDataWriter, snapshot._key, snapshot._document, snapshot.metadata,
399
+ /* converter= */ null);
400
+ return this._delegate.fromFirestore(new QueryDocumentSnapshot(this._firestore, expSnapshot), options ?? {});
401
+ }
402
+ toFirestore(modelObject, options) {
403
+ if (!options) {
404
+ return this._delegate.toFirestore(modelObject);
405
+ }
406
+ else {
407
+ return this._delegate.toFirestore(modelObject, options);
408
+ }
409
+ }
410
+ // Use the same instance of `FirestoreDataConverter` for the given instances
411
+ // of `Firestore` and `PublicFirestoreDataConverter` so that isEqual() will
412
+ // compare equal for two objects created with the same converter instance.
413
+ static getInstance(firestore, converter) {
414
+ const converterMapByFirestore = FirestoreDataConverter.INSTANCES;
415
+ let untypedConverterByConverter = converterMapByFirestore.get(firestore);
416
+ if (!untypedConverterByConverter) {
417
+ untypedConverterByConverter = new WeakMap();
418
+ converterMapByFirestore.set(firestore, untypedConverterByConverter);
419
+ }
420
+ let instance = untypedConverterByConverter.get(converter);
421
+ if (!instance) {
422
+ instance = new FirestoreDataConverter(firestore, new UserDataWriter(firestore), converter);
423
+ untypedConverterByConverter.set(converter, instance);
424
+ }
425
+ return instance;
426
+ }
427
+ }
428
+ FirestoreDataConverter.INSTANCES = new WeakMap();
429
+ /**
430
+ * A reference to a particular document in a collection in the database.
431
+ */
432
+ class DocumentReference {
433
+ constructor(firestore, _delegate) {
434
+ this.firestore = firestore;
435
+ this._delegate = _delegate;
436
+ this._userDataWriter = new UserDataWriter(firestore);
437
+ }
438
+ static forPath(path, firestore$1, converter) {
439
+ if (path.length % 2 !== 0) {
440
+ throw new firestore.FirestoreError('invalid-argument', 'Invalid document reference. Document ' +
441
+ 'references must have an even number of segments, but ' +
442
+ `${path.canonicalString()} has ${path.length}`);
443
+ }
444
+ return new DocumentReference(firestore$1, new firestore.DocumentReference(firestore$1._delegate, converter, new firestore._DocumentKey(path)));
445
+ }
446
+ static forKey(key, firestore$1, converter) {
447
+ return new DocumentReference(firestore$1, new firestore.DocumentReference(firestore$1._delegate, converter, key));
448
+ }
449
+ get id() {
450
+ return this._delegate.id;
451
+ }
452
+ get parent() {
453
+ return new CollectionReference(this.firestore, this._delegate.parent);
454
+ }
455
+ get path() {
456
+ return this._delegate.path;
457
+ }
458
+ collection(pathString) {
459
+ try {
460
+ return new CollectionReference(this.firestore, firestore.collection(this._delegate, pathString));
461
+ }
462
+ catch (e) {
463
+ throw replaceFunctionName(e, 'collection()', 'DocumentReference.collection()');
464
+ }
465
+ }
466
+ isEqual(other) {
467
+ other = util.getModularInstance(other);
468
+ if (!(other instanceof firestore.DocumentReference)) {
469
+ return false;
470
+ }
471
+ return firestore.refEqual(this._delegate, other);
472
+ }
473
+ set(value, options) {
474
+ options = validateSetOptions('DocumentReference.set', options);
475
+ try {
476
+ if (options) {
477
+ return firestore.setDoc(this._delegate, value, options);
478
+ }
479
+ else {
480
+ return firestore.setDoc(this._delegate, value);
481
+ }
482
+ }
483
+ catch (e) {
484
+ throw replaceFunctionName(e, 'setDoc()', 'DocumentReference.set()');
485
+ }
486
+ }
487
+ update(fieldOrUpdateData, value, ...moreFieldsAndValues) {
488
+ try {
489
+ if (arguments.length === 1) {
490
+ return firestore.updateDoc(this._delegate, fieldOrUpdateData);
491
+ }
492
+ else {
493
+ return firestore.updateDoc(this._delegate, fieldOrUpdateData, value, ...moreFieldsAndValues);
494
+ }
495
+ }
496
+ catch (e) {
497
+ throw replaceFunctionName(e, 'updateDoc()', 'DocumentReference.update()');
498
+ }
499
+ }
500
+ delete() {
501
+ return firestore.deleteDoc(this._delegate);
502
+ }
503
+ onSnapshot(...args) {
504
+ const options = extractSnapshotOptions(args);
505
+ const observer = wrapObserver(args, result => new DocumentSnapshot(this.firestore, new firestore.DocumentSnapshot(this.firestore._delegate, this._userDataWriter, result._key, result._document, result.metadata, this._delegate.converter)));
506
+ return firestore.onSnapshot(this._delegate, options, observer);
507
+ }
508
+ get(options) {
509
+ let snap;
510
+ if (options?.source === 'cache') {
511
+ snap = firestore.getDocFromCache(this._delegate);
512
+ }
513
+ else if (options?.source === 'server') {
514
+ snap = firestore.getDocFromServer(this._delegate);
515
+ }
516
+ else {
517
+ snap = firestore.getDoc(this._delegate);
518
+ }
519
+ return snap.then(result => new DocumentSnapshot(this.firestore, new firestore.DocumentSnapshot(this.firestore._delegate, this._userDataWriter, result._key, result._document, result.metadata, this._delegate.converter)));
520
+ }
521
+ withConverter(converter) {
522
+ return new DocumentReference(this.firestore, converter
523
+ ? this._delegate.withConverter(FirestoreDataConverter.getInstance(this.firestore, converter))
524
+ : this._delegate.withConverter(null));
525
+ }
526
+ }
527
+ /**
528
+ * Replaces the function name in an error thrown by the firestore-exp API
529
+ * with the function names used in the classic API.
530
+ */
531
+ function replaceFunctionName(e, original, updated) {
532
+ e.message = e.message.replace(original, updated);
533
+ return e;
534
+ }
535
+ /**
536
+ * Iterates the list of arguments from an `onSnapshot` call and returns the
537
+ * first argument that may be an `SnapshotListenOptions` object. Returns an
538
+ * empty object if none is found.
539
+ */
540
+ function extractSnapshotOptions(args) {
541
+ for (const arg of args) {
542
+ if (typeof arg === 'object' && !isPartialObserver(arg)) {
543
+ return arg;
544
+ }
545
+ }
546
+ return {};
547
+ }
548
+ /**
549
+ * Creates an observer that can be passed to the firestore-exp SDK. The
550
+ * observer converts all observed values into the format expected by the classic
551
+ * SDK.
552
+ *
553
+ * @param args - The list of arguments from an `onSnapshot` call.
554
+ * @param wrapper - The function that converts the firestore-exp type into the
555
+ * type used by this shim.
556
+ */
557
+ function wrapObserver(args, wrapper) {
558
+ let userObserver;
559
+ if (isPartialObserver(args[0])) {
560
+ userObserver = args[0];
561
+ }
562
+ else if (isPartialObserver(args[1])) {
563
+ userObserver = args[1];
564
+ }
565
+ else if (typeof args[0] === 'function') {
566
+ userObserver = {
567
+ next: args[0],
568
+ error: args[1],
569
+ complete: args[2]
570
+ };
571
+ }
572
+ else {
573
+ userObserver = {
574
+ next: args[1],
575
+ error: args[2],
576
+ complete: args[3]
577
+ };
578
+ }
579
+ return {
580
+ next: val => {
581
+ if (userObserver.next) {
582
+ userObserver.next(wrapper(val));
583
+ }
584
+ },
585
+ error: userObserver.error?.bind(userObserver),
586
+ complete: userObserver.complete?.bind(userObserver)
587
+ };
588
+ }
589
+ class DocumentSnapshot {
590
+ constructor(_firestore, _delegate) {
591
+ this._firestore = _firestore;
592
+ this._delegate = _delegate;
593
+ }
594
+ get ref() {
595
+ return new DocumentReference(this._firestore, this._delegate.ref);
596
+ }
597
+ get id() {
598
+ return this._delegate.id;
599
+ }
600
+ get metadata() {
601
+ return this._delegate.metadata;
602
+ }
603
+ get exists() {
604
+ return this._delegate.exists();
605
+ }
606
+ data(options) {
607
+ return this._delegate.data(options);
608
+ }
609
+ get(fieldPath, options
610
+ // We are using `any` here to avoid an explicit cast by our users.
611
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
612
+ ) {
613
+ return this._delegate.get(fieldPath, options);
614
+ }
615
+ isEqual(other) {
616
+ return firestore.snapshotEqual(this._delegate, other._delegate);
617
+ }
618
+ }
619
+ class QueryDocumentSnapshot extends DocumentSnapshot {
620
+ data(options) {
621
+ const data = this._delegate.data(options);
622
+ if (this._delegate._converter) {
623
+ // Undefined is a possible valid value from converter.
624
+ return data;
625
+ }
626
+ else {
627
+ firestore._debugAssert(data !== undefined, 'Document in a QueryDocumentSnapshot should exist');
628
+ return data;
629
+ }
630
+ }
631
+ }
632
+ class Query {
633
+ constructor(firestore, _delegate) {
634
+ this.firestore = firestore;
635
+ this._delegate = _delegate;
636
+ this._userDataWriter = new UserDataWriter(firestore);
637
+ }
638
+ where(fieldPath, opStr, value) {
639
+ try {
640
+ // The "as string" cast is a little bit of a hack. `where` accepts the
641
+ // FieldPath Compat type as input, but is not typed as such in order to
642
+ // not expose this via our public typings file.
643
+ return new Query(this.firestore, firestore.query(this._delegate, firestore.where(fieldPath, opStr, value)));
644
+ }
645
+ catch (e) {
646
+ throw replaceFunctionName(e, /(orderBy|where)\(\)/, 'Query.$1()');
647
+ }
648
+ }
649
+ orderBy(fieldPath, directionStr) {
650
+ try {
651
+ // The "as string" cast is a little bit of a hack. `orderBy` accepts the
652
+ // FieldPath Compat type as input, but is not typed as such in order to
653
+ // not expose this via our public typings file.
654
+ return new Query(this.firestore, firestore.query(this._delegate, firestore.orderBy(fieldPath, directionStr)));
655
+ }
656
+ catch (e) {
657
+ throw replaceFunctionName(e, /(orderBy|where)\(\)/, 'Query.$1()');
658
+ }
659
+ }
660
+ limit(n) {
661
+ try {
662
+ return new Query(this.firestore, firestore.query(this._delegate, firestore.limit(n)));
663
+ }
664
+ catch (e) {
665
+ throw replaceFunctionName(e, 'limit()', 'Query.limit()');
666
+ }
667
+ }
668
+ limitToLast(n) {
669
+ try {
670
+ return new Query(this.firestore, firestore.query(this._delegate, firestore.limitToLast(n)));
671
+ }
672
+ catch (e) {
673
+ throw replaceFunctionName(e, 'limitToLast()', 'Query.limitToLast()');
674
+ }
675
+ }
676
+ startAt(...args) {
677
+ try {
678
+ return new Query(this.firestore, firestore.query(this._delegate, firestore.startAt(...args)));
679
+ }
680
+ catch (e) {
681
+ throw replaceFunctionName(e, 'startAt()', 'Query.startAt()');
682
+ }
683
+ }
684
+ startAfter(...args) {
685
+ try {
686
+ return new Query(this.firestore, firestore.query(this._delegate, firestore.startAfter(...args)));
687
+ }
688
+ catch (e) {
689
+ throw replaceFunctionName(e, 'startAfter()', 'Query.startAfter()');
690
+ }
691
+ }
692
+ endBefore(...args) {
693
+ try {
694
+ return new Query(this.firestore, firestore.query(this._delegate, firestore.endBefore(...args)));
695
+ }
696
+ catch (e) {
697
+ throw replaceFunctionName(e, 'endBefore()', 'Query.endBefore()');
698
+ }
699
+ }
700
+ endAt(...args) {
701
+ try {
702
+ return new Query(this.firestore, firestore.query(this._delegate, firestore.endAt(...args)));
703
+ }
704
+ catch (e) {
705
+ throw replaceFunctionName(e, 'endAt()', 'Query.endAt()');
706
+ }
707
+ }
708
+ isEqual(other) {
709
+ return firestore.queryEqual(this._delegate, other._delegate);
710
+ }
711
+ get(options) {
712
+ let query;
713
+ if (options?.source === 'cache') {
714
+ query = firestore.getDocsFromCache(this._delegate);
715
+ }
716
+ else if (options?.source === 'server') {
717
+ query = firestore.getDocsFromServer(this._delegate);
718
+ }
719
+ else {
720
+ query = firestore.getDocs(this._delegate);
721
+ }
722
+ return query.then(result => new QuerySnapshot(this.firestore, new firestore.QuerySnapshot(this.firestore._delegate, this._userDataWriter, this._delegate, result._snapshot)));
723
+ }
724
+ onSnapshot(...args) {
725
+ const options = extractSnapshotOptions(args);
726
+ const observer = wrapObserver(args, snap => new QuerySnapshot(this.firestore, new firestore.QuerySnapshot(this.firestore._delegate, this._userDataWriter, this._delegate, snap._snapshot)));
727
+ return firestore.onSnapshot(this._delegate, options, observer);
728
+ }
729
+ withConverter(converter) {
730
+ return new Query(this.firestore, converter
731
+ ? this._delegate.withConverter(FirestoreDataConverter.getInstance(this.firestore, converter))
732
+ : this._delegate.withConverter(null));
733
+ }
734
+ }
735
+ class DocumentChange {
736
+ constructor(_firestore, _delegate) {
737
+ this._firestore = _firestore;
738
+ this._delegate = _delegate;
739
+ }
740
+ get type() {
741
+ return this._delegate.type;
742
+ }
743
+ get doc() {
744
+ return new QueryDocumentSnapshot(this._firestore, this._delegate.doc);
745
+ }
746
+ get oldIndex() {
747
+ return this._delegate.oldIndex;
748
+ }
749
+ get newIndex() {
750
+ return this._delegate.newIndex;
751
+ }
752
+ }
753
+ class QuerySnapshot {
754
+ constructor(_firestore, _delegate) {
755
+ this._firestore = _firestore;
756
+ this._delegate = _delegate;
757
+ }
758
+ get query() {
759
+ return new Query(this._firestore, this._delegate.query);
760
+ }
761
+ get metadata() {
762
+ return this._delegate.metadata;
763
+ }
764
+ get size() {
765
+ return this._delegate.size;
766
+ }
767
+ get empty() {
768
+ return this._delegate.empty;
769
+ }
770
+ get docs() {
771
+ return this._delegate.docs.map(doc => new QueryDocumentSnapshot(this._firestore, doc));
772
+ }
773
+ docChanges(options) {
774
+ return this._delegate
775
+ .docChanges(options)
776
+ .map(docChange => new DocumentChange(this._firestore, docChange));
777
+ }
778
+ forEach(callback, thisArg) {
779
+ this._delegate.forEach(snapshot => {
780
+ callback.call(thisArg, new QueryDocumentSnapshot(this._firestore, snapshot));
781
+ });
782
+ }
783
+ isEqual(other) {
784
+ return firestore.snapshotEqual(this._delegate, other._delegate);
785
+ }
786
+ }
787
+ class CollectionReference extends Query {
788
+ constructor(firestore, _delegate) {
789
+ super(firestore, _delegate);
790
+ this.firestore = firestore;
791
+ this._delegate = _delegate;
792
+ }
793
+ get id() {
794
+ return this._delegate.id;
795
+ }
796
+ get path() {
797
+ return this._delegate.path;
798
+ }
799
+ get parent() {
800
+ const docRef = this._delegate.parent;
801
+ return docRef ? new DocumentReference(this.firestore, docRef) : null;
802
+ }
803
+ doc(documentPath) {
804
+ try {
805
+ if (documentPath === undefined) {
806
+ // Call `doc` without `documentPath` if `documentPath` is `undefined`
807
+ // as `doc` validates the number of arguments to prevent users from
808
+ // accidentally passing `undefined`.
809
+ return new DocumentReference(this.firestore, firestore.doc(this._delegate));
810
+ }
811
+ else {
812
+ return new DocumentReference(this.firestore, firestore.doc(this._delegate, documentPath));
813
+ }
814
+ }
815
+ catch (e) {
816
+ throw replaceFunctionName(e, 'doc()', 'CollectionReference.doc()');
817
+ }
818
+ }
819
+ add(data) {
820
+ return firestore.addDoc(this._delegate, data).then(docRef => new DocumentReference(this.firestore, docRef));
821
+ }
822
+ isEqual(other) {
823
+ return firestore.refEqual(this._delegate, other._delegate);
824
+ }
825
+ withConverter(converter) {
826
+ return new CollectionReference(this.firestore, converter
827
+ ? this._delegate.withConverter(FirestoreDataConverter.getInstance(this.firestore, converter))
828
+ : this._delegate.withConverter(null));
829
+ }
830
+ }
831
+ function castReference(documentRef) {
832
+ return firestore._cast(documentRef, firestore.DocumentReference);
825
833
  }
826
834
 
827
- /**
828
- * @license
829
- * Copyright 2017 Google LLC
830
- *
831
- * Licensed under the Apache License, Version 2.0 (the "License");
832
- * you may not use this file except in compliance with the License.
833
- * You may obtain a copy of the License at
834
- *
835
- * http://www.apache.org/licenses/LICENSE-2.0
836
- *
837
- * Unless required by applicable law or agreed to in writing, software
838
- * distributed under the License is distributed on an "AS IS" BASIS,
839
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
840
- * See the License for the specific language governing permissions and
841
- * limitations under the License.
842
- */
843
- // The objects that are a part of this API are exposed to third-parties as
844
- // compiled javascript so we want to flag our private members with a leading
845
- // underscore to discourage their use.
846
- /**
847
- * A `FieldPath` refers to a field in a document. The path may consist of a
848
- * single field name (referring to a top-level field in the document), or a list
849
- * of field names (referring to a nested field in the document).
850
- */
851
- class FieldPath {
852
- /**
853
- * Creates a FieldPath from the provided field names. If more than one field
854
- * name is provided, the path will point to a nested field in a document.
855
- *
856
- * @param fieldNames - A list of field names.
857
- */
858
- constructor(...fieldNames) {
859
- this._delegate = new firestore.FieldPath(...fieldNames);
860
- }
861
- static documentId() {
862
- /**
863
- * Internal Note: The backend doesn't technically support querying by
864
- * document ID. Instead it queries by the entire document name (full path
865
- * included), but in the cases we currently support documentId(), the net
866
- * effect is the same.
867
- */
868
- return new FieldPath(firestore._FieldPath.keyField().canonicalString());
869
- }
870
- isEqual(other) {
871
- other = util.getModularInstance(other);
872
- if (!(other instanceof firestore.FieldPath)) {
873
- return false;
874
- }
875
- return this._delegate._internalPath.isEqual(other._internalPath);
876
- }
835
+ /**
836
+ * @license
837
+ * Copyright 2017 Google LLC
838
+ *
839
+ * Licensed under the Apache License, Version 2.0 (the "License");
840
+ * you may not use this file except in compliance with the License.
841
+ * You may obtain a copy of the License at
842
+ *
843
+ * http://www.apache.org/licenses/LICENSE-2.0
844
+ *
845
+ * Unless required by applicable law or agreed to in writing, software
846
+ * distributed under the License is distributed on an "AS IS" BASIS,
847
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
848
+ * See the License for the specific language governing permissions and
849
+ * limitations under the License.
850
+ */
851
+ // The objects that are a part of this API are exposed to third-parties as
852
+ // compiled javascript so we want to flag our private members with a leading
853
+ // underscore to discourage their use.
854
+ /**
855
+ * A `FieldPath` refers to a field in a document. The path may consist of a
856
+ * single field name (referring to a top-level field in the document), or a list
857
+ * of field names (referring to a nested field in the document).
858
+ */
859
+ class FieldPath {
860
+ /**
861
+ * Creates a FieldPath from the provided field names. If more than one field
862
+ * name is provided, the path will point to a nested field in a document.
863
+ *
864
+ * @param fieldNames - A list of field names.
865
+ */
866
+ constructor(...fieldNames) {
867
+ this._delegate = new firestore.FieldPath(...fieldNames);
868
+ }
869
+ static documentId() {
870
+ /**
871
+ * Internal Note: The backend doesn't technically support querying by
872
+ * document ID. Instead it queries by the entire document name (full path
873
+ * included), but in the cases we currently support documentId(), the net
874
+ * effect is the same.
875
+ */
876
+ return new FieldPath(firestore._FieldPath.keyField().canonicalString());
877
+ }
878
+ isEqual(other) {
879
+ other = util.getModularInstance(other);
880
+ if (!(other instanceof firestore.FieldPath)) {
881
+ return false;
882
+ }
883
+ return this._delegate._internalPath.isEqual(other._internalPath);
884
+ }
877
885
  }
878
886
 
879
- /**
880
- * @license
881
- * Copyright 2017 Google LLC
882
- *
883
- * Licensed under the Apache License, Version 2.0 (the "License");
884
- * you may not use this file except in compliance with the License.
885
- * You may obtain a copy of the License at
886
- *
887
- * http://www.apache.org/licenses/LICENSE-2.0
888
- *
889
- * Unless required by applicable law or agreed to in writing, software
890
- * distributed under the License is distributed on an "AS IS" BASIS,
891
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
892
- * See the License for the specific language governing permissions and
893
- * limitations under the License.
894
- */
895
- class FieldValue {
896
- constructor(_delegate) {
897
- this._delegate = _delegate;
898
- }
899
- static serverTimestamp() {
900
- const delegate = firestore.serverTimestamp();
901
- delegate._methodName = 'FieldValue.serverTimestamp';
902
- return new FieldValue(delegate);
903
- }
904
- static delete() {
905
- const delegate = firestore.deleteField();
906
- delegate._methodName = 'FieldValue.delete';
907
- return new FieldValue(delegate);
908
- }
909
- static arrayUnion(...elements) {
910
- const delegate = firestore.arrayUnion(...elements);
911
- delegate._methodName = 'FieldValue.arrayUnion';
912
- return new FieldValue(delegate);
913
- }
914
- static arrayRemove(...elements) {
915
- const delegate = firestore.arrayRemove(...elements);
916
- delegate._methodName = 'FieldValue.arrayRemove';
917
- return new FieldValue(delegate);
918
- }
919
- static increment(n) {
920
- const delegate = firestore.increment(n);
921
- delegate._methodName = 'FieldValue.increment';
922
- return new FieldValue(delegate);
923
- }
924
- isEqual(other) {
925
- return this._delegate.isEqual(other._delegate);
926
- }
887
+ /**
888
+ * @license
889
+ * Copyright 2017 Google LLC
890
+ *
891
+ * Licensed under the Apache License, Version 2.0 (the "License");
892
+ * you may not use this file except in compliance with the License.
893
+ * You may obtain a copy of the License at
894
+ *
895
+ * http://www.apache.org/licenses/LICENSE-2.0
896
+ *
897
+ * Unless required by applicable law or agreed to in writing, software
898
+ * distributed under the License is distributed on an "AS IS" BASIS,
899
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
900
+ * See the License for the specific language governing permissions and
901
+ * limitations under the License.
902
+ */
903
+ class FieldValue {
904
+ static serverTimestamp() {
905
+ const delegate = firestore.serverTimestamp();
906
+ delegate._methodName = 'FieldValue.serverTimestamp';
907
+ return new FieldValue(delegate);
908
+ }
909
+ static delete() {
910
+ const delegate = firestore.deleteField();
911
+ delegate._methodName = 'FieldValue.delete';
912
+ return new FieldValue(delegate);
913
+ }
914
+ static arrayUnion(...elements) {
915
+ const delegate = firestore.arrayUnion(...elements);
916
+ delegate._methodName = 'FieldValue.arrayUnion';
917
+ return new FieldValue(delegate);
918
+ }
919
+ static arrayRemove(...elements) {
920
+ const delegate = firestore.arrayRemove(...elements);
921
+ delegate._methodName = 'FieldValue.arrayRemove';
922
+ return new FieldValue(delegate);
923
+ }
924
+ static increment(n) {
925
+ const delegate = firestore.increment(n);
926
+ delegate._methodName = 'FieldValue.increment';
927
+ return new FieldValue(delegate);
928
+ }
929
+ constructor(_delegate) {
930
+ this._delegate = _delegate;
931
+ }
932
+ isEqual(other) {
933
+ return this._delegate.isEqual(other._delegate);
934
+ }
927
935
  }
928
936
 
929
- /**
930
- * @license
931
- * Copyright 2021 Google LLC
932
- *
933
- * Licensed under the Apache License, Version 2.0 (the "License");
934
- * you may not use this file except in compliance with the License.
935
- * You may obtain a copy of the License at
936
- *
937
- * http://www.apache.org/licenses/LICENSE-2.0
938
- *
939
- * Unless required by applicable law or agreed to in writing, software
940
- * distributed under the License is distributed on an "AS IS" BASIS,
941
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
942
- * See the License for the specific language governing permissions and
943
- * limitations under the License.
944
- */
945
- const firestoreNamespace = {
946
- Firestore,
947
- GeoPoint: firestore.GeoPoint,
948
- Timestamp: firestore.Timestamp,
949
- Blob,
950
- Transaction,
951
- WriteBatch,
952
- DocumentReference,
953
- DocumentSnapshot,
954
- Query,
955
- QueryDocumentSnapshot,
956
- QuerySnapshot,
957
- CollectionReference,
958
- FieldPath,
959
- FieldValue,
960
- setLogLevel,
961
- CACHE_SIZE_UNLIMITED: firestore.CACHE_SIZE_UNLIMITED
962
- };
963
- /**
964
- * Configures Firestore as part of the Firebase SDK by calling registerComponent.
965
- *
966
- * @param firebase - The FirebaseNamespace to register Firestore with
967
- * @param firestoreFactory - A factory function that returns a new Firestore
968
- * instance.
969
- */
970
- function configureForFirebase(firebase, firestoreFactory) {
971
- firebase.INTERNAL.registerComponent(new component.Component('firestore-compat', container => {
972
- const app = container.getProvider('app-compat').getImmediate();
973
- const firestoreExp = container.getProvider('firestore').getImmediate();
974
- return firestoreFactory(app, firestoreExp);
975
- }, 'PUBLIC').setServiceProps(Object.assign({}, firestoreNamespace)));
937
+ /**
938
+ * @license
939
+ * Copyright 2021 Google LLC
940
+ *
941
+ * Licensed under the Apache License, Version 2.0 (the "License");
942
+ * you may not use this file except in compliance with the License.
943
+ * You may obtain a copy of the License at
944
+ *
945
+ * http://www.apache.org/licenses/LICENSE-2.0
946
+ *
947
+ * Unless required by applicable law or agreed to in writing, software
948
+ * distributed under the License is distributed on an "AS IS" BASIS,
949
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
950
+ * See the License for the specific language governing permissions and
951
+ * limitations under the License.
952
+ */
953
+ const firestoreNamespace = {
954
+ Firestore,
955
+ GeoPoint: firestore.GeoPoint,
956
+ Timestamp: firestore.Timestamp,
957
+ Blob,
958
+ Transaction,
959
+ WriteBatch,
960
+ DocumentReference,
961
+ DocumentSnapshot,
962
+ Query,
963
+ QueryDocumentSnapshot,
964
+ QuerySnapshot,
965
+ CollectionReference,
966
+ FieldPath,
967
+ FieldValue,
968
+ setLogLevel,
969
+ CACHE_SIZE_UNLIMITED: firestore.CACHE_SIZE_UNLIMITED
970
+ };
971
+ /**
972
+ * Configures Firestore as part of the Firebase SDK by calling registerComponent.
973
+ *
974
+ * @param firebase - The FirebaseNamespace to register Firestore with
975
+ * @param firestoreFactory - A factory function that returns a new Firestore
976
+ * instance.
977
+ */
978
+ function configureForFirebase(firebase, firestoreFactory) {
979
+ firebase.INTERNAL.registerComponent(new component.Component('firestore-compat', container => {
980
+ const app = container.getProvider('app-compat').getImmediate();
981
+ const firestoreExp = container.getProvider('firestore').getImmediate();
982
+ return firestoreFactory(app, firestoreExp);
983
+ }, 'PUBLIC').setServiceProps({ ...firestoreNamespace }));
976
984
  }
977
985
 
978
- /**
979
- * @license
980
- * Copyright 2020 Google LLC
981
- *
982
- * Licensed under the Apache License, Version 2.0 (the "License");
983
- * you may not use this file except in compliance with the License.
984
- * You may obtain a copy of the License at
985
- *
986
- * http://www.apache.org/licenses/LICENSE-2.0
987
- *
988
- * Unless required by applicable law or agreed to in writing, software
989
- * distributed under the License is distributed on an "AS IS" BASIS,
990
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
991
- * See the License for the specific language governing permissions and
992
- * limitations under the License.
993
- */
994
- /**
995
- * Registers the main Firestore build with the components framework.
996
- * Persistence can be enabled via `firebase.firestore().enablePersistence()`.
997
- */
998
- function registerFirestore(instance) {
999
- configureForFirebase(instance, (app, firestoreExp) => new Firestore(app, firestoreExp, new IndexedDbPersistenceProvider()));
1000
- instance.registerVersion(name, version);
1001
- }
986
+ /**
987
+ * @license
988
+ * Copyright 2020 Google LLC
989
+ *
990
+ * Licensed under the Apache License, Version 2.0 (the "License");
991
+ * you may not use this file except in compliance with the License.
992
+ * You may obtain a copy of the License at
993
+ *
994
+ * http://www.apache.org/licenses/LICENSE-2.0
995
+ *
996
+ * Unless required by applicable law or agreed to in writing, software
997
+ * distributed under the License is distributed on an "AS IS" BASIS,
998
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
999
+ * See the License for the specific language governing permissions and
1000
+ * limitations under the License.
1001
+ */
1002
+ /**
1003
+ * Registers the main Firestore build with the components framework.
1004
+ * Persistence can be enabled via `firebase.firestore().enablePersistence()`.
1005
+ */
1006
+ function registerFirestore(instance) {
1007
+ configureForFirebase(instance, (app, firestoreExp) => new Firestore(app, firestoreExp, new IndexedDbPersistenceProvider()));
1008
+ instance.registerVersion(name, version);
1009
+ }
1002
1010
  registerFirestore(firebase__default["default"]);
1003
1011
 
1004
1012
  exports.registerFirestore = registerFirestore;