@dereekb/firebase 10.2.0 → 11.0.1

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 (38) hide show
  1. package/index.cjs.js +1005 -729
  2. package/index.esm.js +47 -162
  3. package/package.json +1 -1
  4. package/src/lib/client/firestore/driver.accessor.batch.d.ts +2 -2
  5. package/src/lib/client/firestore/driver.accessor.transaction.d.ts +1 -1
  6. package/src/lib/client/function/model.function.factory.d.ts +0 -10
  7. package/src/lib/common/firestore/snapshot/snapshot.field.d.ts +5 -9
  8. package/src/lib/common/model/function.d.ts +15 -37
  9. package/src/lib/common/model/model/model.param.d.ts +5 -5
  10. package/test/CHANGELOG.md +18 -0
  11. package/test/package.json +1 -1
  12. package/test/src/lib/client/firebase.js +36 -21
  13. package/test/src/lib/client/firebase.js.map +1 -1
  14. package/test/src/lib/common/firebase.instance.js +2 -0
  15. package/test/src/lib/common/firebase.instance.js.map +1 -1
  16. package/test/src/lib/common/firestore/firestore.instance.js +1 -0
  17. package/test/src/lib/common/firestore/firestore.instance.js.map +1 -1
  18. package/test/src/lib/common/firestore/firestore.js +18 -10
  19. package/test/src/lib/common/firestore/firestore.js.map +1 -1
  20. package/test/src/lib/common/firestore/test.driver.accessor.js +273 -277
  21. package/test/src/lib/common/firestore/test.driver.accessor.js.map +1 -1
  22. package/test/src/lib/common/firestore/test.driver.query.js +315 -329
  23. package/test/src/lib/common/firestore/test.driver.query.js.map +1 -1
  24. package/test/src/lib/common/firestore/test.iterator.js +6 -7
  25. package/test/src/lib/common/firestore/test.iterator.js.map +1 -1
  26. package/test/src/lib/common/mock/mock.item.collection.fixture.d.ts +2 -1
  27. package/test/src/lib/common/mock/mock.item.collection.fixture.js +4 -2
  28. package/test/src/lib/common/mock/mock.item.collection.fixture.js.map +1 -1
  29. package/test/src/lib/common/mock/mock.item.service.js +6 -11
  30. package/test/src/lib/common/mock/mock.item.service.js.map +1 -1
  31. package/test/src/lib/common/mock/mock.item.storage.fixture.js +2 -1
  32. package/test/src/lib/common/mock/mock.item.storage.fixture.js.map +1 -1
  33. package/test/src/lib/common/storage/storage.instance.js +1 -0
  34. package/test/src/lib/common/storage/storage.instance.js.map +1 -1
  35. package/test/src/lib/common/storage/storage.js +10 -3
  36. package/test/src/lib/common/storage/storage.js.map +1 -1
  37. package/test/src/lib/common/storage/test.driver.accessor.js +132 -133
  38. package/test/src/lib/common/storage/test.driver.accessor.js.map +1 -1
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.describeFirestoreDocumentAccessorTests = exports.describeFirestoreAccessorDriverTests = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const test_1 = require("@dereekb/util/test");
6
5
  const rxjs_1 = require("rxjs");
7
6
  const rxjs_2 = require("@dereekb/rxjs");
@@ -17,9 +16,9 @@ function describeFirestoreAccessorDriverTests(f) {
17
16
  const testDocumentCount = 5;
18
17
  let mockItemFirestoreDocumentAccessor;
19
18
  let items;
20
- beforeEach(() => tslib_1.__awaiter(this, void 0, void 0, function* () {
19
+ beforeEach(async () => {
21
20
  mockItemFirestoreDocumentAccessor = f.instance.firestoreCollection.documentAccessor();
22
- items = yield (0, firebase_1.makeDocuments)(f.instance.firestoreCollection.documentAccessor(), {
21
+ items = await (0, firebase_1.makeDocuments)(f.instance.firestoreCollection.documentAccessor(), {
23
22
  count: testDocumentCount,
24
23
  init: (i) => {
25
24
  return {
@@ -29,7 +28,7 @@ function describeFirestoreAccessorDriverTests(f) {
29
28
  };
30
29
  }
31
30
  });
32
- }));
31
+ });
33
32
  describe('MockItem', () => {
34
33
  let itemDocument;
35
34
  let accessor;
@@ -47,63 +46,63 @@ function describeFirestoreAccessorDriverTests(f) {
47
46
  loadDocumentForWriteBatch: (writeBatch, ref) => f.instance.firestoreCollection.documentAccessorForWriteBatch(writeBatch).loadDocument(ref)
48
47
  }));
49
48
  describe('increment()', () => {
50
- it(`should increase the item's value`, () => tslib_1.__awaiter(this, void 0, void 0, function* () {
51
- let data = yield itemDocument.snapshotData();
52
- expect(data === null || data === void 0 ? void 0 : data.number).toBe(undefined);
49
+ it(`should increase the item's value`, async () => {
50
+ let data = await itemDocument.snapshotData();
51
+ expect(data?.number).toBe(undefined);
53
52
  const update = { number: 3 };
54
- yield itemDocument.increment(update);
55
- data = yield itemDocument.snapshotData();
56
- expect(data === null || data === void 0 ? void 0 : data.number).toBe(update.number);
53
+ await itemDocument.increment(update);
54
+ data = await itemDocument.snapshotData();
55
+ expect(data?.number).toBe(update.number);
57
56
  // increment again
58
- yield itemDocument.increment(update);
59
- data = yield itemDocument.snapshotData();
60
- expect(data === null || data === void 0 ? void 0 : data.number).toBe(update.number * 2);
61
- }));
62
- it(`should decrease the item's value`, () => tslib_1.__awaiter(this, void 0, void 0, function* () {
63
- let data = yield itemDocument.snapshotData();
64
- expect(data === null || data === void 0 ? void 0 : data.number).toBe(undefined);
57
+ await itemDocument.increment(update);
58
+ data = await itemDocument.snapshotData();
59
+ expect(data?.number).toBe(update.number * 2);
60
+ });
61
+ it(`should decrease the item's value`, async () => {
62
+ let data = await itemDocument.snapshotData();
63
+ expect(data?.number).toBe(undefined);
65
64
  const update = { number: -3 };
66
- yield itemDocument.increment(update);
67
- data = yield itemDocument.snapshotData();
68
- expect(data === null || data === void 0 ? void 0 : data.number).toBe(update.number);
65
+ await itemDocument.increment(update);
66
+ data = await itemDocument.snapshotData();
67
+ expect(data?.number).toBe(update.number);
69
68
  // increment again
70
- yield itemDocument.increment(update);
71
- data = yield itemDocument.snapshotData();
72
- expect(data === null || data === void 0 ? void 0 : data.number).toBe(update.number * 2);
73
- }));
74
- it(`should increase and decrease the item's value`, () => tslib_1.__awaiter(this, void 0, void 0, function* () {
75
- let data = yield itemDocument.snapshotData();
76
- expect(data === null || data === void 0 ? void 0 : data.number).toBe(undefined);
69
+ await itemDocument.increment(update);
70
+ data = await itemDocument.snapshotData();
71
+ expect(data?.number).toBe(update.number * 2);
72
+ });
73
+ it(`should increase and decrease the item's value`, async () => {
74
+ let data = await itemDocument.snapshotData();
75
+ expect(data?.number).toBe(undefined);
77
76
  const update = { number: 3 };
78
- yield itemDocument.increment(update);
77
+ await itemDocument.increment(update);
79
78
  const update2 = { number: -6 };
80
- yield itemDocument.increment(update2);
81
- data = yield itemDocument.snapshotData();
82
- expect(data === null || data === void 0 ? void 0 : data.number).toBe(update.number + update2.number);
83
- }));
79
+ await itemDocument.increment(update2);
80
+ data = await itemDocument.snapshotData();
81
+ expect(data?.number).toBe(update.number + update2.number);
82
+ });
84
83
  describe('in transaction', () => {
85
- it(`should increase the item's value`, () => tslib_1.__awaiter(this, void 0, void 0, function* () {
84
+ it(`should increase the item's value`, async () => {
86
85
  const update = { number: 3 };
87
- yield f.parent.firestoreContext.runTransaction((transaction) => tslib_1.__awaiter(this, void 0, void 0, function* () {
88
- const itemDocumentInTransaction = yield f.instance.firestoreCollection.documentAccessorForTransaction(transaction).loadDocumentForId(itemDocument.id);
89
- let data = yield itemDocumentInTransaction.snapshotData();
90
- expect(data === null || data === void 0 ? void 0 : data.number).toBe(undefined);
91
- yield itemDocumentInTransaction.increment(update);
92
- }));
93
- const result = yield itemDocument.snapshotData();
94
- expect(result === null || result === void 0 ? void 0 : result.number).toBe(update.number);
95
- }));
86
+ await f.parent.firestoreContext.runTransaction(async (transaction) => {
87
+ const itemDocumentInTransaction = await f.instance.firestoreCollection.documentAccessorForTransaction(transaction).loadDocumentForId(itemDocument.id);
88
+ let data = await itemDocumentInTransaction.snapshotData();
89
+ expect(data?.number).toBe(undefined);
90
+ await itemDocumentInTransaction.increment(update);
91
+ });
92
+ const result = await itemDocument.snapshotData();
93
+ expect(result?.number).toBe(update.number);
94
+ });
96
95
  });
97
96
  describe('in write batch', () => {
98
- it(`should increase the item's value`, () => tslib_1.__awaiter(this, void 0, void 0, function* () {
97
+ it(`should increase the item's value`, async () => {
99
98
  const update = { number: 3 };
100
99
  const writeBatch = f.parent.firestoreContext.batch();
101
- const itemDocumentForWriteBatch = yield f.instance.firestoreCollection.documentAccessorForWriteBatch(writeBatch).loadDocumentForId(itemDocument.id);
102
- yield itemDocumentForWriteBatch.increment(update);
103
- yield writeBatch.commit();
104
- const result = yield itemDocument.snapshotData();
105
- expect(result === null || result === void 0 ? void 0 : result.number).toBe(update.number);
106
- }));
100
+ const itemDocumentForWriteBatch = await f.instance.firestoreCollection.documentAccessorForWriteBatch(writeBatch).loadDocumentForId(itemDocument.id);
101
+ await itemDocumentForWriteBatch.increment(update);
102
+ await writeBatch.commit();
103
+ const result = await itemDocument.snapshotData();
104
+ expect(result?.number).toBe(update.number);
105
+ });
107
106
  });
108
107
  });
109
108
  });
@@ -121,28 +120,26 @@ function describeFirestoreAccessorDriverTests(f) {
121
120
  });
122
121
  describe('create()', () => {
123
122
  describe('mockItemUserAccessorFactory usage', () => {
124
- it('should copy the documents identifier to the uid field on create.', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
125
- var _a;
126
- yield itemUserDataDocument.accessor.create({
123
+ it('should copy the documents identifier to the uid field on create.', async () => {
124
+ await itemUserDataDocument.accessor.create({
127
125
  uid: '',
128
126
  name: 'hello'
129
127
  });
130
- const snapshot = yield itemUserDataDocument.accessor.get();
131
- expect((_a = snapshot.data()) === null || _a === void 0 ? void 0 : _a.uid).toBe(testUserId);
132
- }));
128
+ const snapshot = await itemUserDataDocument.accessor.get();
129
+ expect(snapshot.data()?.uid).toBe(testUserId);
130
+ });
133
131
  });
134
132
  });
135
133
  describe('set()', () => {
136
134
  describe('mockItemUserAccessorFactory usage', () => {
137
- it('should copy the documents identifier to the uid field on set.', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
138
- var _a;
139
- yield itemUserDataDocument.accessor.set({
135
+ it('should copy the documents identifier to the uid field on set.', async () => {
136
+ await itemUserDataDocument.accessor.set({
140
137
  uid: '',
141
138
  name: 'hello'
142
139
  });
143
- const snapshot = yield itemUserDataDocument.accessor.get();
144
- expect((_a = snapshot.data()) === null || _a === void 0 ? void 0 : _a.uid).toBe(testUserId);
145
- }));
140
+ const snapshot = await itemUserDataDocument.accessor.get();
141
+ expect(snapshot.data()?.uid).toBe(testUserId);
142
+ });
146
143
  });
147
144
  });
148
145
  });
@@ -170,45 +167,44 @@ function describeFirestoreAccessorDriverTests(f) {
170
167
  });
171
168
  });
172
169
  describe('get()', () => {
173
- it('should read that data using the configured converter', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
174
- var _a;
175
- yield itemPrivateDataDocument.accessor.set({ values: null });
176
- const dataWithoutConverter = (yield itemPrivateDataDocument.accessor.getWithConverter(null)).data();
170
+ it('should read that data using the configured converter', async () => {
171
+ await itemPrivateDataDocument.accessor.set({ values: null });
172
+ const dataWithoutConverter = (await itemPrivateDataDocument.accessor.getWithConverter(null)).data();
177
173
  expect(dataWithoutConverter).toBeDefined();
178
174
  expect(dataWithoutConverter.values).toBeNull();
179
175
  // converter on client, _converter on server
180
- expect((_a = itemPrivateDataDocument.documentRef.converter) !== null && _a !== void 0 ? _a : itemPrivateDataDocument.documentRef._converter).toBeDefined();
181
- const data = yield itemPrivateDataDocument.snapshotData();
182
- expect(data === null || data === void 0 ? void 0 : data.values).toBeDefined();
183
- expect(data === null || data === void 0 ? void 0 : data.values).not.toBeNull(); // should not be null due to the snapshot converter config
184
- }));
176
+ expect(itemPrivateDataDocument.documentRef.converter ?? itemPrivateDataDocument.documentRef._converter).toBeDefined();
177
+ const data = await itemPrivateDataDocument.snapshotData();
178
+ expect(data?.values).toBeDefined();
179
+ expect(data?.values).not.toBeNull(); // should not be null due to the snapshot converter config
180
+ });
185
181
  });
186
182
  describe('getWithConverter()', () => {
187
- it('should get the results with the input converter', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
188
- yield itemPrivateDataDocument.accessor.set({ values: null });
189
- const data = yield itemPrivateDataDocument.snapshotData();
190
- expect(data === null || data === void 0 ? void 0 : data.values).toBeDefined();
191
- const dataWithoutConverter = (yield itemPrivateDataDocument.accessor.getWithConverter(null)).data();
183
+ it('should get the results with the input converter', async () => {
184
+ await itemPrivateDataDocument.accessor.set({ values: null });
185
+ const data = await itemPrivateDataDocument.snapshotData();
186
+ expect(data?.values).toBeDefined();
187
+ const dataWithoutConverter = (await itemPrivateDataDocument.accessor.getWithConverter(null)).data();
192
188
  expect(dataWithoutConverter).toBeDefined();
193
189
  expect(dataWithoutConverter.values).toBeNull();
194
- }));
195
- it('should get the results with the input converter with a type', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
196
- yield itemPrivateDataDocument.accessor.set({ values: null });
197
- const data = yield itemPrivateDataDocument.snapshotData();
198
- expect(data === null || data === void 0 ? void 0 : data.values).toBeDefined();
190
+ });
191
+ it('should get the results with the input converter with a type', async () => {
192
+ await itemPrivateDataDocument.accessor.set({ values: null });
193
+ const data = await itemPrivateDataDocument.snapshotData();
194
+ expect(data?.values).toBeDefined();
199
195
  const converter = mock_1.mockItemConverter;
200
- const dataWithoutConverter = yield itemPrivateDataDocument.accessor.getWithConverter(converter);
196
+ const dataWithoutConverter = await itemPrivateDataDocument.accessor.getWithConverter(converter);
201
197
  expect(dataWithoutConverter).toBeDefined();
202
- }));
198
+ });
203
199
  });
204
200
  describe('update()', () => {
205
- (0, test_1.itShouldFail)('if the item does not exist', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
206
- const exists = yield itemPrivateDataDocument.accessor.exists();
201
+ (0, test_1.itShouldFail)('if the item does not exist', async () => {
202
+ const exists = await itemPrivateDataDocument.accessor.exists();
207
203
  expect(exists).toBe(false);
208
- yield (0, test_1.expectFail)(() => itemPrivateDataDocument.update({ createdAt: new Date() }));
209
- }));
210
- it('should update the item if it exist', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
211
- yield itemPrivateDataDocument.create({
204
+ await (0, test_1.expectFail)(() => itemPrivateDataDocument.update({ createdAt: new Date() }));
205
+ });
206
+ it('should update the item if it exist', async () => {
207
+ await itemPrivateDataDocument.create({
212
208
  createdAt: new Date(),
213
209
  num: 0,
214
210
  values: [],
@@ -220,23 +216,23 @@ function describeFirestoreAccessorDriverTests(f) {
220
216
  }
221
217
  });
222
218
  const newDate = new Date(0);
223
- const exists = yield itemPrivateDataDocument.accessor.exists();
219
+ const exists = await itemPrivateDataDocument.accessor.exists();
224
220
  expect(exists).toBe(true);
225
- yield itemPrivateDataDocument.update({ createdAt: newDate });
226
- const data = yield itemPrivateDataDocument.snapshotData();
227
- expect(data === null || data === void 0 ? void 0 : data.createdAt.getTime()).toBe(newDate.getTime());
221
+ await itemPrivateDataDocument.update({ createdAt: newDate });
222
+ const data = await itemPrivateDataDocument.snapshotData();
223
+ expect(data?.createdAt.getTime()).toBe(newDate.getTime());
228
224
  // check was not modified
229
- expect(data === null || data === void 0 ? void 0 : data.settings['test'].north).toBe(true);
230
- expect(data === null || data === void 0 ? void 0 : data.settings['test'].south).toBe(true);
231
- expect(data === null || data === void 0 ? void 0 : data.settings['test'].east).toBeUndefined();
232
- expect(data === null || data === void 0 ? void 0 : data.settings['test'].west).toBeUndefined();
233
- }));
225
+ expect(data?.settings['test'].north).toBe(true);
226
+ expect(data?.settings['test'].south).toBe(true);
227
+ expect(data?.settings['test'].east).toBeUndefined();
228
+ expect(data?.settings['test'].west).toBeUndefined();
229
+ });
234
230
  });
235
231
  describe('set()', () => {
236
- it('should create the item', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
237
- let exists = yield privateDataAccessor.exists();
232
+ it('should create the item', async () => {
233
+ let exists = await privateDataAccessor.exists();
238
234
  expect(exists).toBe(false);
239
- yield privateDataAccessor.set({
235
+ await privateDataAccessor.set({
240
236
  values: [],
241
237
  num: 0,
242
238
  createdAt: new Date(),
@@ -246,23 +242,23 @@ function describeFirestoreAccessorDriverTests(f) {
246
242
  }
247
243
  }
248
244
  });
249
- exists = yield privateDataAccessor.exists();
245
+ exists = await privateDataAccessor.exists();
250
246
  expect(exists).toBe(true);
251
- }));
247
+ });
252
248
  });
253
249
  describe('with item', () => {
254
- beforeEach(() => tslib_1.__awaiter(this, void 0, void 0, function* () {
255
- yield privateDataAccessor.set({ num: 0, values: [], createdAt: new Date(), settings: {} });
256
- }));
250
+ beforeEach(async () => {
251
+ await privateDataAccessor.set({ num: 0, values: [], createdAt: new Date(), settings: {} });
252
+ });
257
253
  describe('increment()', () => {
258
- it(`should increase the item's value`, () => tslib_1.__awaiter(this, void 0, void 0, function* () {
259
- let data = yield itemPrivateDataDocument.snapshotData();
260
- expect(data === null || data === void 0 ? void 0 : data.num).toBe(0);
254
+ it(`should increase the item's value`, async () => {
255
+ let data = await itemPrivateDataDocument.snapshotData();
256
+ expect(data?.num).toBe(0);
261
257
  const update = { num: 3 };
262
- yield itemPrivateDataDocument.increment(update);
263
- data = yield itemPrivateDataDocument.snapshotData();
264
- expect(data === null || data === void 0 ? void 0 : data.num).toBe(update.num);
265
- }));
258
+ await itemPrivateDataDocument.increment(update);
259
+ data = await itemPrivateDataDocument.snapshotData();
260
+ expect(data?.num).toBe(update.num);
261
+ });
266
262
  });
267
263
  describe('accessors', () => {
268
264
  const TEST_COMMENTS = 'test';
@@ -279,10 +275,10 @@ function describeFirestoreAccessorDriverTests(f) {
279
275
  });
280
276
  describe('MockItemSubItem', () => {
281
277
  let subItemDocument;
282
- beforeEach(() => tslib_1.__awaiter(this, void 0, void 0, function* () {
278
+ beforeEach(async () => {
283
279
  subItemDocument = f.instance.collections.mockItemSubItemCollectionFactory(itemDocument).documentAccessor().newDocument();
284
- yield subItemDocument.accessor.set({ value: 0 });
285
- }));
280
+ await subItemDocument.accessor.set({ value: 0 });
281
+ });
286
282
  describe('firestoreCollectionWithParent (MockItemSubItem)', () => {
287
283
  let mockItemSubItemFirestoreCollection;
288
284
  beforeEach(() => {
@@ -326,11 +322,11 @@ function describeFirestoreAccessorDriverTests(f) {
326
322
  });
327
323
  describe('documentAccessor()', () => {
328
324
  describe('loadDocumentForKey()', () => {
329
- it('should load an existing document from the path.', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
325
+ it('should load an existing document from the path.', async () => {
330
326
  const document = mockItemFirestoreDocumentAccessor.loadDocumentForKey(items[0].key);
331
- const exists = yield document.accessor.exists();
327
+ const exists = await document.accessor.exists();
332
328
  expect(exists).toBe(true);
333
- }));
329
+ });
334
330
  (0, test_1.itShouldFail)('if the path is invalid (points to collection)', () => {
335
331
  (0, test_1.expectFail)(() => {
336
332
  mockItemFirestoreDocumentAccessor.loadDocumentForKey('path');
@@ -393,166 +389,166 @@ function describeFirestoreDocumentAccessorTests(init) {
393
389
  });
394
390
  describe('utilities', () => {
395
391
  describe('getDocumentSnapshotPairs()', () => {
396
- it('should return the document and snapshot pairs for the input.', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
397
- const pairs = yield (0, firebase_1.getDocumentSnapshotPairs)([firestoreDocument]);
392
+ it('should return the document and snapshot pairs for the input.', async () => {
393
+ const pairs = await (0, firebase_1.getDocumentSnapshotPairs)([firestoreDocument]);
398
394
  expect(pairs.length).toBe(1);
399
395
  expect(pairs[0]).toBeDefined();
400
396
  expect(pairs[0].document).toBe(firestoreDocument);
401
397
  expect(pairs[0].snapshot).toBeDefined();
402
398
  expect(pairs[0].snapshot.data()).toBeDefined();
403
- }));
399
+ });
404
400
  });
405
401
  describe('useDocumentSnapshot()', () => {
406
- it(`should use the input document value if it exists`, () => tslib_1.__awaiter(this, void 0, void 0, function* () {
407
- const exists = yield firestoreDocument.exists();
402
+ it(`should use the input document value if it exists`, async () => {
403
+ const exists = await firestoreDocument.exists();
408
404
  expect(exists).toBe(true);
409
405
  let snapshotUsed = false;
410
- yield (0, firebase_1.useDocumentSnapshot)(firestoreDocument, (snapshot) => {
406
+ await (0, firebase_1.useDocumentSnapshot)(firestoreDocument, (snapshot) => {
411
407
  expect(snapshot).toBeDefined();
412
408
  snapshotUsed = true;
413
409
  });
414
410
  expect(snapshotUsed).toBe(true);
415
- }));
416
- it(`should not use the input undefined value`, () => tslib_1.__awaiter(this, void 0, void 0, function* () {
411
+ });
412
+ it(`should not use the input undefined value`, async () => {
417
413
  let snapshotUsed = false;
418
- yield (0, firebase_1.useDocumentSnapshot)(undefined, (snapshot) => {
414
+ await (0, firebase_1.useDocumentSnapshot)(undefined, (snapshot) => {
419
415
  expect(snapshot).toBeDefined();
420
416
  snapshotUsed = true;
421
417
  });
422
418
  expect(snapshotUsed).toBe(false);
423
- }));
419
+ });
424
420
  });
425
421
  describe('useDocumentSnapshotData()', () => {
426
- it(`should use the input document's snapshot data if it exists`, () => tslib_1.__awaiter(this, void 0, void 0, function* () {
427
- const exists = yield firestoreDocument.exists();
422
+ it(`should use the input document's snapshot data if it exists`, async () => {
423
+ const exists = await firestoreDocument.exists();
428
424
  expect(exists).toBe(true);
429
425
  let snapshotUsed = false;
430
- yield (0, firebase_1.useDocumentSnapshotData)(firestoreDocument, (data) => {
426
+ await (0, firebase_1.useDocumentSnapshotData)(firestoreDocument, (data) => {
431
427
  expect(data).toBeDefined();
432
428
  snapshotUsed = true;
433
429
  });
434
430
  expect(snapshotUsed).toBe(true);
435
- }));
431
+ });
436
432
  });
437
433
  });
438
434
  describe('AbstractFirestoreDocument', () => {
439
435
  describe('snapshot()', () => {
440
- it('should return the snapshot.', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
441
- const snapshot = yield firestoreDocument.snapshot();
436
+ it('should return the snapshot.', async () => {
437
+ const snapshot = await firestoreDocument.snapshot();
442
438
  expect(snapshot).toBeDefined();
443
- }));
439
+ });
444
440
  });
445
441
  describe('snapshotData()', () => {
446
- it('should return the snapshot data if the model exists.', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
447
- const exists = yield firestoreDocument.exists();
442
+ it('should return the snapshot data if the model exists.', async () => {
443
+ const exists = await firestoreDocument.exists();
448
444
  expect(exists).toBe(true);
449
- const data = yield firestoreDocument.snapshotData();
445
+ const data = await firestoreDocument.snapshotData();
450
446
  expect(data).toBeDefined();
451
- }));
452
- it('should return the undefined if the model does not exist.', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
453
- yield accessor.delete();
454
- const exists = yield firestoreDocument.exists();
447
+ });
448
+ it('should return the undefined if the model does not exist.', async () => {
449
+ await accessor.delete();
450
+ const exists = await firestoreDocument.exists();
455
451
  expect(exists).toBe(false);
456
- const data = yield firestoreDocument.snapshotData();
452
+ const data = await firestoreDocument.snapshotData();
457
453
  expect(data).toBeUndefined();
458
- }));
454
+ });
459
455
  });
460
456
  describe('create()', () => {
461
- it('should create the document if it does not exist.', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
462
- const snapshot = yield firestoreDocument.snapshot();
463
- yield accessor.delete();
464
- let exists = yield firestoreDocument.exists();
457
+ it('should create the document if it does not exist.', async () => {
458
+ const snapshot = await firestoreDocument.snapshot();
459
+ await accessor.delete();
460
+ let exists = await firestoreDocument.exists();
465
461
  expect(exists).toBe(false);
466
- yield firestoreDocument.create(snapshot.data());
467
- exists = yield firestoreDocument.exists();
462
+ await firestoreDocument.create(snapshot.data());
463
+ exists = await firestoreDocument.exists();
468
464
  expect(exists).toBe(true);
469
- }));
470
- (0, test_1.itShouldFail)('if the document exists.', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
471
- const snapshot = yield firestoreDocument.snapshot();
472
- const exists = yield firestoreDocument.exists();
465
+ });
466
+ (0, test_1.itShouldFail)('if the document exists.', async () => {
467
+ const snapshot = await firestoreDocument.snapshot();
468
+ const exists = await firestoreDocument.exists();
473
469
  expect(exists).toBe(true);
474
- yield (0, test_1.expectFail)(() => firestoreDocument.create(snapshot.data()));
475
- }));
470
+ await (0, test_1.expectFail)(() => firestoreDocument.create(snapshot.data()));
471
+ });
476
472
  });
477
473
  describe('update()', () => {
478
- it('should update the data if the document exists.', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
474
+ it('should update the data if the document exists.', async () => {
479
475
  const data = c.dataForUpdate();
480
- yield firestoreDocument.update(data);
481
- const snapshot = yield firestoreDocument.snapshot();
476
+ await firestoreDocument.update(data);
477
+ const snapshot = await firestoreDocument.snapshot();
482
478
  expect(c.hasDataFromUpdate(snapshot.data())).toBe(true);
483
- }));
484
- (0, test_1.itShouldFail)('if the document does not exist.', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
485
- yield accessor.delete();
486
- const snapshot = yield firestoreDocument.snapshot();
479
+ });
480
+ (0, test_1.itShouldFail)('if the document does not exist.', async () => {
481
+ await accessor.delete();
482
+ const snapshot = await firestoreDocument.snapshot();
487
483
  expect(snapshot.data()).toBe(undefined);
488
- const exists = yield firestoreDocument.exists();
484
+ const exists = await firestoreDocument.exists();
489
485
  expect(exists).toBe(false);
490
- yield (0, test_1.expectFail)(() => firestoreDocument.update(c.dataForUpdate()));
491
- }));
492
- it('should not throw an error if the input update data is empty.', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
493
- yield firestoreDocument.update({});
494
- }));
486
+ await (0, test_1.expectFail)(() => firestoreDocument.update(c.dataForUpdate()));
487
+ });
488
+ it('should not throw an error if the input update data is empty.', async () => {
489
+ await firestoreDocument.update({});
490
+ });
495
491
  });
496
492
  describe('transaction', () => {
497
493
  describe('stream$', () => {
498
- it('should not cause the transaction to fail if the document is loaded after changes have begun.', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
499
- yield c.context.runTransaction((transaction) => tslib_1.__awaiter(this, void 0, void 0, function* () {
500
- const transactionDocument = yield c.loadDocumentForTransaction(transaction, firestoreDocument.documentRef);
501
- const currentData = yield transactionDocument.snapshotData();
494
+ it('should not cause the transaction to fail if the document is loaded after changes have begun.', async () => {
495
+ await c.context.runTransaction(async (transaction) => {
496
+ const transactionDocument = await c.loadDocumentForTransaction(transaction, firestoreDocument.documentRef);
497
+ const currentData = await transactionDocument.snapshotData();
502
498
  expect(currentData).toBeDefined();
503
499
  const data = c.dataForUpdate();
504
- yield transactionDocument.update(data);
500
+ await transactionDocument.update(data);
505
501
  // stream$ and data$ do not call stream() until called directly.
506
- const secondLoading = yield c.loadDocumentForTransaction(transaction, firestoreDocument.documentRef);
502
+ const secondLoading = await c.loadDocumentForTransaction(transaction, firestoreDocument.documentRef);
507
503
  expect(secondLoading).toBeDefined();
508
- }));
509
- }));
510
- (0, test_1.itShouldFail)('if stream$ is called after an update has occured in the transaction', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
511
- yield (0, test_1.expectFail)(() => c.context.runTransaction((transaction) => tslib_1.__awaiter(this, void 0, void 0, function* () {
512
- const transactionDocument = yield c.loadDocumentForTransaction(transaction, firestoreDocument.documentRef);
513
- const currentData = yield transactionDocument.snapshotData();
504
+ });
505
+ });
506
+ (0, test_1.itShouldFail)('if stream$ is called after an update has occured in the transaction', async () => {
507
+ await (0, test_1.expectFail)(() => c.context.runTransaction(async (transaction) => {
508
+ const transactionDocument = await c.loadDocumentForTransaction(transaction, firestoreDocument.documentRef);
509
+ const currentData = await transactionDocument.snapshotData();
514
510
  expect(currentData).toBeDefined();
515
511
  const data = c.dataForUpdate();
516
- yield transactionDocument.update(data);
512
+ await transactionDocument.update(data);
517
513
  // read the stream using a promise so the error is captured
518
- yield (0, rxjs_1.firstValueFrom)(c.loadDocumentForTransaction(transaction, firestoreDocument.documentRef).stream$);
519
- })));
520
- }));
514
+ await (0, rxjs_1.firstValueFrom)(c.loadDocumentForTransaction(transaction, firestoreDocument.documentRef).stream$);
515
+ }));
516
+ });
521
517
  });
522
518
  describe('update()', () => {
523
- it('should update the data if the document exists.', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
524
- yield c.context.runTransaction((transaction) => tslib_1.__awaiter(this, void 0, void 0, function* () {
525
- const transactionDocument = yield c.loadDocumentForTransaction(transaction, firestoreDocument.documentRef);
526
- const currentData = yield transactionDocument.snapshotData();
519
+ it('should update the data if the document exists.', async () => {
520
+ await c.context.runTransaction(async (transaction) => {
521
+ const transactionDocument = await c.loadDocumentForTransaction(transaction, firestoreDocument.documentRef);
522
+ const currentData = await transactionDocument.snapshotData();
527
523
  expect(currentData).toBeDefined();
528
524
  const data = c.dataForUpdate();
529
- yield transactionDocument.update(data);
530
- }));
531
- const snapshot = yield firestoreDocument.snapshot();
525
+ await transactionDocument.update(data);
526
+ });
527
+ const snapshot = await firestoreDocument.snapshot();
532
528
  expect(c.hasDataFromUpdate(snapshot.data())).toBe(true);
533
- }));
529
+ });
534
530
  });
535
531
  });
536
532
  describe('write batch', () => {
537
533
  describe('update()', () => {
538
- it('should update the data if the document exists.', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
534
+ it('should update the data if the document exists.', async () => {
539
535
  const batch = c.context.batch();
540
- const batchDocument = yield c.loadDocumentForWriteBatch(batch, firestoreDocument.documentRef);
536
+ const batchDocument = await c.loadDocumentForWriteBatch(batch, firestoreDocument.documentRef);
541
537
  const data = c.dataForUpdate();
542
- yield batchDocument.update(data);
543
- yield batch.commit();
544
- const snapshot = yield firestoreDocument.snapshot();
538
+ await batchDocument.update(data);
539
+ await batch.commit();
540
+ const snapshot = await firestoreDocument.snapshot();
545
541
  expect(c.hasDataFromUpdate(snapshot.data())).toBe(true);
546
- }));
542
+ });
547
543
  });
548
544
  });
549
545
  });
550
546
  describe('accessor', () => {
551
547
  describe('stream()', () => {
552
- it('should return a snapshot stream', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
553
- const result = yield accessor.stream();
548
+ it('should return a snapshot stream', async () => {
549
+ const result = await accessor.stream();
554
550
  expect(result).toBeDefined();
555
- }));
551
+ });
556
552
  it('should emit values on updates from the observable.', (done) => {
557
553
  let count = 0;
558
554
  sub.subscription = accessor.stream().subscribe((item) => {
@@ -574,133 +570,133 @@ function describeFirestoreDocumentAccessorTests(init) {
574
570
  beforeEach(() => {
575
571
  runTransaction = c.context.runTransaction;
576
572
  });
577
- it('should return the first emitted value (observable completes immediately)', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
578
- yield runTransaction((transaction) => tslib_1.__awaiter(this, void 0, void 0, function* () {
573
+ it('should return the first emitted value (observable completes immediately)', async () => {
574
+ await runTransaction(async (transaction) => {
579
575
  const transactionItemDocument = c.loadDocumentForTransaction(transaction, accessor.documentRef);
580
576
  // load the value
581
- const value = yield (0, rxjs_1.firstValueFrom)(transactionItemDocument.accessor.stream());
577
+ const value = await (0, rxjs_1.firstValueFrom)(transactionItemDocument.accessor.stream());
582
578
  expect(value).toBeDefined();
583
579
  // set to make the transaction valid
584
- yield transactionItemDocument.accessor.set({ value: 0 }, { merge: true });
580
+ await transactionItemDocument.accessor.set({ value: 0 }, { merge: true });
585
581
  return value;
586
- }));
587
- }));
582
+ });
583
+ });
588
584
  });
589
585
  describe('in batch context', () => {
590
- it('should return the first emitted value (observable completes immediately)', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
586
+ it('should return the first emitted value (observable completes immediately)', async () => {
591
587
  const writeBatch = c.context.batch();
592
588
  const batchItemDocument = c.loadDocumentForWriteBatch(writeBatch, accessor.documentRef);
593
589
  // load the value
594
- const value = yield (0, rxjs_1.firstValueFrom)(batchItemDocument.accessor.stream());
590
+ const value = await (0, rxjs_1.firstValueFrom)(batchItemDocument.accessor.stream());
595
591
  expect(value).toBeDefined();
596
592
  // set to make the batch changes valid
597
- yield batchItemDocument.accessor.set({ value: 0 }, { merge: true });
593
+ await batchItemDocument.accessor.set({ value: 0 }, { merge: true });
598
594
  // commit the changes
599
- yield writeBatch.commit();
600
- }));
595
+ await writeBatch.commit();
596
+ });
601
597
  });
602
598
  });
603
599
  describe('create()', () => {
604
- it('should create the document if it does not exist.', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
605
- const snapshot = yield accessor.get();
606
- yield accessor.delete();
607
- let exists = yield accessor.exists();
600
+ it('should create the document if it does not exist.', async () => {
601
+ const snapshot = await accessor.get();
602
+ await accessor.delete();
603
+ let exists = await accessor.exists();
608
604
  expect(exists).toBe(false);
609
- yield accessor.create(snapshot.data());
610
- exists = yield accessor.exists();
605
+ await accessor.create(snapshot.data());
606
+ exists = await accessor.exists();
611
607
  expect(exists).toBe(true);
612
- }));
613
- (0, test_1.itShouldFail)('if the document exists.', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
614
- const snapshot = yield accessor.get();
615
- const exists = yield accessor.exists();
608
+ });
609
+ (0, test_1.itShouldFail)('if the document exists.', async () => {
610
+ const snapshot = await accessor.get();
611
+ const exists = await accessor.exists();
616
612
  expect(exists).toBe(true);
617
- yield (0, test_1.expectFail)(() => accessor.create(snapshot.data()));
618
- }));
613
+ await (0, test_1.expectFail)(() => accessor.create(snapshot.data()));
614
+ });
619
615
  });
620
616
  describe('get()', () => {
621
- it('should return a snapshot', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
622
- const result = yield accessor.get();
617
+ it('should return a snapshot', async () => {
618
+ const result = await accessor.get();
623
619
  expect(result).toBeDefined();
624
620
  expect(result.id).toBeDefined();
625
- }));
621
+ });
626
622
  });
627
623
  describe('exists()', () => {
628
- it('should return true if the document exists', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
629
- const exists = yield accessor.exists();
624
+ it('should return true if the document exists', async () => {
625
+ const exists = await accessor.exists();
630
626
  expect(exists).toBe(true);
631
- }));
632
- it('should return false if the document does not exist', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
633
- yield accessor.delete();
634
- const exists = yield accessor.exists();
627
+ });
628
+ it('should return false if the document does not exist', async () => {
629
+ await accessor.delete();
630
+ const exists = await accessor.exists();
635
631
  expect(exists).toBe(false);
636
- }));
632
+ });
637
633
  });
638
634
  describe('update()', () => {
639
- it('should update the data if the document exists.', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
635
+ it('should update the data if the document exists.', async () => {
640
636
  const data = c.dataForUpdate();
641
- yield accessor.update(data);
642
- const snapshot = yield accessor.get();
637
+ await accessor.update(data);
638
+ const snapshot = await accessor.get();
643
639
  expect(c.hasDataFromUpdate(snapshot.data())).toBe(true);
644
- }));
645
- (0, test_1.itShouldFail)('if the document does not exist.', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
646
- yield accessor.delete();
647
- const snapshot = yield accessor.get();
640
+ });
641
+ (0, test_1.itShouldFail)('if the document does not exist.', async () => {
642
+ await accessor.delete();
643
+ const snapshot = await accessor.get();
648
644
  expect(snapshot.data()).toBe(undefined);
649
- const exists = yield accessor.exists();
645
+ const exists = await accessor.exists();
650
646
  expect(exists).toBe(false);
651
- yield (0, test_1.expectFail)(() => accessor.update(c.dataForUpdate()));
652
- }));
653
- (0, test_1.itShouldFail)('if the input is an empty object.', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
654
- yield (0, test_1.expectFail)(() => accessor.update({}));
655
- }));
656
- // todo: test that update does not call the converter when setting values.
647
+ await (0, test_1.expectFail)(() => accessor.update(c.dataForUpdate()));
648
+ });
649
+ (0, test_1.itShouldFail)('if the input is an empty object.', async () => {
650
+ await (0, test_1.expectFail)(() => accessor.update({}));
651
+ });
652
+ // TODO(TEST): test that update does not call the converter when setting values.
657
653
  });
658
654
  describe('set()', () => {
659
- it('should create the object if it does not exist.', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
660
- yield accessor.delete();
661
- let exists = yield accessor.exists();
655
+ it('should create the object if it does not exist.', async () => {
656
+ await accessor.delete();
657
+ let exists = await accessor.exists();
662
658
  expect(exists).toBe(false);
663
659
  const data = c.dataForUpdate();
664
- yield accessor.set(data);
665
- exists = yield accessor.exists();
660
+ await accessor.set(data);
661
+ exists = await accessor.exists();
666
662
  expect(exists).toBe(true);
667
- const snapshot = yield accessor.get();
663
+ const snapshot = await accessor.get();
668
664
  expect(c.hasDataFromUpdate(snapshot.data())).toBe(true);
669
- }));
670
- it('should update the data on the document for fields that are not undefined.', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
665
+ });
666
+ it('should update the data on the document for fields that are not undefined.', async () => {
671
667
  const data = c.dataForUpdate();
672
- yield accessor.set(data);
673
- const snapshot = yield accessor.get();
668
+ await accessor.set(data);
669
+ const snapshot = await accessor.get();
674
670
  expect(c.hasDataFromUpdate(snapshot.data())).toBe(true);
675
- }));
671
+ });
676
672
  describe('merge=true', () => {
677
- it('should update the data if the document exists.', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
673
+ it('should update the data if the document exists.', async () => {
678
674
  const data = c.dataForUpdate();
679
- yield accessor.set(data, { merge: true });
680
- const snapshot = yield accessor.get();
675
+ await accessor.set(data, { merge: true });
676
+ const snapshot = await accessor.get();
681
677
  expect(c.hasDataFromUpdate(snapshot.data())).toBe(true);
682
- }));
683
- it('should succeed if the document does not exist.', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
684
- yield accessor.delete();
685
- let snapshot = yield accessor.get();
678
+ });
679
+ it('should succeed if the document does not exist.', async () => {
680
+ await accessor.delete();
681
+ let snapshot = await accessor.get();
686
682
  expect(snapshot.data()).toBe(undefined);
687
- const exists = yield accessor.exists();
683
+ const exists = await accessor.exists();
688
684
  expect(exists).toBe(false);
689
- yield accessor.set(c.dataForUpdate(), { merge: true });
690
- snapshot = yield accessor.get();
685
+ await accessor.set(c.dataForUpdate(), { merge: true });
686
+ snapshot = await accessor.get();
691
687
  expect(c.hasDataFromUpdate(snapshot.data())).toBe(true);
692
- }));
688
+ });
693
689
  });
694
- // todo: test that set calls the converter when setting values.
690
+ // TODO(TEST): test that set calls the converter when setting values.
695
691
  });
696
692
  describe('delete()', () => {
697
- it('should delete the document.', () => tslib_1.__awaiter(this, void 0, void 0, function* () {
698
- yield accessor.delete();
699
- const snapshot = yield accessor.get();
693
+ it('should delete the document.', async () => {
694
+ await accessor.delete();
695
+ const snapshot = await accessor.get();
700
696
  expect(snapshot.data()).toBe(undefined);
701
- const exists = yield accessor.exists();
697
+ const exists = await accessor.exists();
702
698
  expect(exists).toBe(false);
703
- }));
699
+ });
704
700
  });
705
701
  });
706
702
  }