@digitalaidseattle/firebase 1.0.3 → 1.0.4

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.
@@ -9,7 +9,6 @@ declare class FirestoreService<T extends Entity> implements EntityService<T> {
9
9
  insert(entity: T, select?: string, user?: User): Promise<T>;
10
10
  update(entityId: Identifier, updatedFields: T, select?: string, user?: User): Promise<T>;
11
11
  delete(entityId: Identifier): Promise<void>;
12
- addBatch: (entities: T[]) => Promise<void>;
13
12
  }
14
13
  export { FirestoreService };
15
14
  export type { Entity };
@@ -12,7 +12,6 @@ var app = require('firebase/app');
12
12
  var storage = require('firebase/storage');
13
13
  var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
14
14
  var firestore = require('firebase/firestore');
15
- var uuid = require('uuid');
16
15
 
17
16
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
18
17
 
@@ -38,7 +37,7 @@ var FirebaseAuthService = /*#__PURE__*/function () {
38
37
  _defineProperty(this, "currentUser", undefined);
39
38
  _defineProperty(this, "auth", auth.getAuth(firebaseClient));
40
39
  _defineProperty(this, "getUser", /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee() {
41
- return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
40
+ return _regeneratorRuntime__default["default"].wrap(function (_context) {
42
41
  while (1) switch (_context.prev = _context.next) {
43
42
  case 0:
44
43
  return _context.abrupt("return", _this.currentUser);
@@ -49,7 +48,7 @@ var FirebaseAuthService = /*#__PURE__*/function () {
49
48
  }, _callee);
50
49
  })));
51
50
  _defineProperty(this, "signOut", /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2() {
52
- return _regeneratorRuntime__default["default"].wrap(function _callee2$(_context2) {
51
+ return _regeneratorRuntime__default["default"].wrap(function (_context2) {
53
52
  while (1) switch (_context2.prev = _context2.next) {
54
53
  case 0:
55
54
  _this.currentUser = undefined;
@@ -57,22 +56,22 @@ var FirebaseAuthService = /*#__PURE__*/function () {
57
56
  return _context2.abrupt("return", {
58
57
  error: null
59
58
  });
60
- case 3:
59
+ case 1:
61
60
  case "end":
62
61
  return _context2.stop();
63
62
  }
64
63
  }, _callee2);
65
64
  })));
66
65
  _defineProperty(this, "signInWithGoogle", /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee3() {
67
- var provider, resp;
68
- return _regeneratorRuntime__default["default"].wrap(function _callee3$(_context3) {
66
+ var provider, resp, _t;
67
+ return _regeneratorRuntime__default["default"].wrap(function (_context3) {
69
68
  while (1) switch (_context3.prev = _context3.next) {
70
69
  case 0:
71
70
  _context3.prev = 0;
72
71
  provider = new auth.GoogleAuthProvider();
73
- _context3.next = 4;
72
+ _context3.next = 1;
74
73
  return auth.signInWithPopup(_this.auth, provider);
75
- case 4:
74
+ case 1:
76
75
  resp = _context3.sent;
77
76
  _this.currentUser = {
78
77
  email: resp.user.email,
@@ -87,15 +86,15 @@ var FirebaseAuthService = /*#__PURE__*/function () {
87
86
  url: undefined.VITE_AUTH_DOMAIN
88
87
  }
89
88
  });
90
- case 9:
91
- _context3.prev = 9;
92
- _context3.t0 = _context3["catch"](0);
93
- console.error(_context3.t0);
94
- case 12:
89
+ case 2:
90
+ _context3.prev = 2;
91
+ _t = _context3["catch"](0);
92
+ console.error(_t);
93
+ case 3:
95
94
  case "end":
96
95
  return _context3.stop();
97
96
  }
98
- }, _callee3, null, [[0, 9]]);
97
+ }, _callee3, null, [[0, 2]]);
99
98
  })));
100
99
  this.auth.onAuthStateChanged(function (user) {
101
100
  if (user) {
@@ -141,14 +140,14 @@ var FirebaseStorageService = /*#__PURE__*/_createClass(function FirebaseStorageS
141
140
  _defineProperty(this, "downloadFile", /*#__PURE__*/function () {
142
141
  var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(filepath) {
143
142
  var fileRef;
144
- return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
143
+ return _regeneratorRuntime__default["default"].wrap(function (_context) {
145
144
  while (1) switch (_context.prev = _context.next) {
146
145
  case 0:
147
146
  fileRef = storage.ref(_this.storage, filepath);
148
147
  return _context.abrupt("return", storage.getBytes(fileRef).then(function (b) {
149
148
  return _this.decoder.decode(b);
150
149
  }));
151
- case 2:
150
+ case 1:
152
151
  case "end":
153
152
  return _context.stop();
154
153
  }
@@ -162,19 +161,9 @@ var FirebaseStorageService = /*#__PURE__*/_createClass(function FirebaseStorageS
162
161
 
163
162
  var FirestoreService = /*#__PURE__*/function () {
164
163
  function FirestoreService(collectionName) {
165
- var _this = this;
166
164
  _classCallCheck(this, FirestoreService);
167
165
  _defineProperty(this, "collectionName", "player");
168
166
  _defineProperty(this, "db", firestore.getFirestore(firebaseClient));
169
- _defineProperty(this, "addBatch", function (entities) {
170
- var batch = firestore.writeBatch(_this.db);
171
- entities.forEach(function (e) {
172
- e.id = uuid.v4();
173
- var docRef = firestore.doc(_this.db, _this.collectionName, e.id);
174
- batch.set(docRef, e);
175
- });
176
- return batch.commit();
177
- });
178
167
  this.collectionName = collectionName;
179
168
  }
180
169
 
@@ -184,19 +173,19 @@ var FirestoreService = /*#__PURE__*/function () {
184
173
  value: function () {
185
174
  var _getAll = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(count, select) {
186
175
  var querySnapshot;
187
- return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
176
+ return _regeneratorRuntime__default["default"].wrap(function (_context) {
188
177
  while (1) switch (_context.prev = _context.next) {
189
178
  case 0:
190
- _context.next = 2;
179
+ _context.next = 1;
191
180
  return firestore.getDocs(firestore.collection(this.db, this.collectionName));
192
- case 2:
181
+ case 1:
193
182
  querySnapshot = _context.sent;
194
183
  return _context.abrupt("return", querySnapshot.docs.map(function (doc) {
195
184
  return _objectSpread(_objectSpread({}, doc.data()), {}, {
196
185
  id: doc.id
197
186
  });
198
187
  }));
199
- case 4:
188
+ case 2:
200
189
  case "end":
201
190
  return _context.stop();
202
191
  }
@@ -211,37 +200,37 @@ var FirestoreService = /*#__PURE__*/function () {
211
200
  key: "getById",
212
201
  value: function () {
213
202
  var _getById = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2(id, select) {
214
- var docRef;
215
- return _regeneratorRuntime__default["default"].wrap(function _callee2$(_context2) {
203
+ var docRef, _t;
204
+ return _regeneratorRuntime__default["default"].wrap(function (_context2) {
216
205
  while (1) switch (_context2.prev = _context2.next) {
217
206
  case 0:
218
207
  _context2.prev = 0;
219
- _context2.next = 3;
208
+ _context2.next = 1;
220
209
  return firestore.getDoc(firestore.doc(this.db, this.collectionName, id));
221
- case 3:
210
+ case 1:
222
211
  docRef = _context2.sent;
223
212
  if (!docRef.exists()) {
224
- _context2.next = 8;
213
+ _context2.next = 2;
225
214
  break;
226
215
  }
227
216
  return _context2.abrupt("return", _objectSpread(_objectSpread({}, docRef.data()), {}, {
228
217
  id: docRef.id
229
218
  }));
230
- case 8:
219
+ case 2:
231
220
  throw Error("entity with id: ".concat(id, ", does not exist"));
232
- case 9:
233
- _context2.next = 15;
221
+ case 3:
222
+ _context2.next = 5;
234
223
  break;
235
- case 11:
236
- _context2.prev = 11;
237
- _context2.t0 = _context2["catch"](0);
238
- console.error("Error getting document: ", _context2.t0);
239
- throw _context2.t0;
240
- case 15:
224
+ case 4:
225
+ _context2.prev = 4;
226
+ _t = _context2["catch"](0);
227
+ console.error("Error getting document: ", _t);
228
+ throw _t;
229
+ case 5:
241
230
  case "end":
242
231
  return _context2.stop();
243
232
  }
244
- }, _callee2, this, [[0, 11]]);
233
+ }, _callee2, this, [[0, 4]]);
245
234
  }));
246
235
  function getById(_x3, _x4) {
247
236
  return _getById.apply(this, arguments);
@@ -252,28 +241,26 @@ var FirestoreService = /*#__PURE__*/function () {
252
241
  key: "batchInsert",
253
242
  value: function () {
254
243
  var _batchInsert = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee3(entities, select, user) {
255
- return _regeneratorRuntime__default["default"].wrap(function _callee3$(_context3) {
244
+ var _t2;
245
+ return _regeneratorRuntime__default["default"].wrap(function (_context3) {
256
246
  while (1) switch (_context3.prev = _context3.next) {
257
247
  case 0:
258
248
  _context3.prev = 0;
259
- entities.forEach(function (entity) {
260
- return entity.id = uuid.v4();
261
- });
262
- _context3.next = 4;
249
+ _context3.next = 1;
263
250
  return firestore.addDoc(firestore.collection(this.db, this.collectionName), entities);
264
- case 4:
251
+ case 1:
265
252
  _context3.sent;
266
253
  return _context3.abrupt("return", entities);
267
- case 8:
268
- _context3.prev = 8;
269
- _context3.t0 = _context3["catch"](0);
270
- console.error("Error adding document: ", _context3.t0);
271
- throw _context3.t0;
272
- case 12:
254
+ case 2:
255
+ _context3.prev = 2;
256
+ _t2 = _context3["catch"](0);
257
+ console.error("Error adding document: ", _t2);
258
+ throw _t2;
259
+ case 3:
273
260
  case "end":
274
261
  return _context3.stop();
275
262
  }
276
- }, _callee3, this, [[0, 8]]);
263
+ }, _callee3, this, [[0, 2]]);
277
264
  }));
278
265
  function batchInsert(_x5, _x6, _x7) {
279
266
  return _batchInsert.apply(this, arguments);
@@ -284,28 +271,30 @@ var FirestoreService = /*#__PURE__*/function () {
284
271
  key: "insert",
285
272
  value: function () {
286
273
  var _insert = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee4(entity, select, user) {
287
- return _regeneratorRuntime__default["default"].wrap(function _callee4$(_context4) {
274
+ var docRef, _t3;
275
+ return _regeneratorRuntime__default["default"].wrap(function (_context4) {
288
276
  while (1) switch (_context4.prev = _context4.next) {
289
277
  case 0:
290
278
  _context4.prev = 0;
291
- entity.id = uuid.v4();
292
- _context4.next = 4;
279
+ _context4.next = 1;
293
280
  return firestore.addDoc(firestore.collection(this.db, this.collectionName), entity);
294
- case 4:
295
- _context4.sent;
296
- return _context4.abrupt("return", entity);
297
- case 8:
298
- _context4.prev = 8;
299
- _context4.t0 = _context4["catch"](0);
300
- console.error("Error adding document: ", _context4.t0);
301
- throw _context4.t0;
302
- case 12:
281
+ case 1:
282
+ docRef = _context4.sent;
283
+ return _context4.abrupt("return", _objectSpread(_objectSpread({}, docRef.toJSON()), {}, {
284
+ id: docRef.id
285
+ }));
286
+ case 2:
287
+ _context4.prev = 2;
288
+ _t3 = _context4["catch"](0);
289
+ console.error("Error adding document: ", _t3);
290
+ throw _t3;
291
+ case 3:
303
292
  case "end":
304
293
  return _context4.stop();
305
294
  }
306
- }, _callee4, this, [[0, 8]]);
295
+ }, _callee4, this, [[0, 2]]);
307
296
  }));
308
- function insert(_x8, _x9, _x10) {
297
+ function insert(_x8, _x9, _x0) {
309
298
  return _insert.apply(this, arguments);
310
299
  }
311
300
  return insert;
@@ -314,26 +303,26 @@ var FirestoreService = /*#__PURE__*/function () {
314
303
  key: "update",
315
304
  value: function () {
316
305
  var _update = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee5(entityId, updatedFields, select, user) {
317
- var docRef;
318
- return _regeneratorRuntime__default["default"].wrap(function _callee5$(_context5) {
306
+ var docRef, _t4;
307
+ return _regeneratorRuntime__default["default"].wrap(function (_context5) {
319
308
  while (1) switch (_context5.prev = _context5.next) {
320
309
  case 0:
321
310
  _context5.prev = 0;
322
311
  docRef = firestore.doc(this.db, this.collectionName, entityId);
323
312
  firestore.updateDoc(docRef, updatedFields);
324
- return _context5.abrupt("return", updatedFields);
325
- case 6:
326
- _context5.prev = 6;
327
- _context5.t0 = _context5["catch"](0);
328
- console.error("Error updating document: ", _context5.t0);
329
- throw _context5.t0;
330
- case 10:
313
+ return _context5.abrupt("return", _objectSpread({}, updatedFields));
314
+ case 1:
315
+ _context5.prev = 1;
316
+ _t4 = _context5["catch"](0);
317
+ console.error("Error updating document: ", _t4);
318
+ throw _t4;
319
+ case 2:
331
320
  case "end":
332
321
  return _context5.stop();
333
322
  }
334
- }, _callee5, this, [[0, 6]]);
323
+ }, _callee5, this, [[0, 1]]);
335
324
  }));
336
- function update(_x11, _x12, _x13, _x14) {
325
+ function update(_x1, _x10, _x11, _x12) {
337
326
  return _update.apply(this, arguments);
338
327
  }
339
328
  return update;
@@ -342,18 +331,18 @@ var FirestoreService = /*#__PURE__*/function () {
342
331
  key: "delete",
343
332
  value: function () {
344
333
  var _delete2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee6(entityId) {
345
- return _regeneratorRuntime__default["default"].wrap(function _callee6$(_context6) {
334
+ return _regeneratorRuntime__default["default"].wrap(function (_context6) {
346
335
  while (1) switch (_context6.prev = _context6.next) {
347
336
  case 0:
348
337
  console.log('delete', entityId);
349
338
  return _context6.abrupt("return", firestore.deleteDoc(firestore.doc(this.db, this.collectionName, entityId)));
350
- case 2:
339
+ case 1:
351
340
  case "end":
352
341
  return _context6.stop();
353
342
  }
354
343
  }, _callee6, this);
355
344
  }));
356
- function _delete(_x15) {
345
+ function _delete(_x13) {
357
346
  return _delete2.apply(this, arguments);
358
347
  }
359
348
  return _delete;
@@ -12,7 +12,6 @@ var app = require('firebase/app');
12
12
  var storage = require('firebase/storage');
13
13
  var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
14
14
  var firestore = require('firebase/firestore');
15
- var uuid = require('uuid');
16
15
 
17
16
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
18
17
 
@@ -38,7 +37,7 @@ var FirebaseAuthService = /*#__PURE__*/function () {
38
37
  _defineProperty(this, "currentUser", undefined);
39
38
  _defineProperty(this, "auth", auth.getAuth(firebaseClient));
40
39
  _defineProperty(this, "getUser", /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee() {
41
- return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
40
+ return _regeneratorRuntime__default["default"].wrap(function (_context) {
42
41
  while (1) switch (_context.prev = _context.next) {
43
42
  case 0:
44
43
  return _context.abrupt("return", _this.currentUser);
@@ -49,7 +48,7 @@ var FirebaseAuthService = /*#__PURE__*/function () {
49
48
  }, _callee);
50
49
  })));
51
50
  _defineProperty(this, "signOut", /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2() {
52
- return _regeneratorRuntime__default["default"].wrap(function _callee2$(_context2) {
51
+ return _regeneratorRuntime__default["default"].wrap(function (_context2) {
53
52
  while (1) switch (_context2.prev = _context2.next) {
54
53
  case 0:
55
54
  _this.currentUser = undefined;
@@ -57,22 +56,22 @@ var FirebaseAuthService = /*#__PURE__*/function () {
57
56
  return _context2.abrupt("return", {
58
57
  error: null
59
58
  });
60
- case 3:
59
+ case 1:
61
60
  case "end":
62
61
  return _context2.stop();
63
62
  }
64
63
  }, _callee2);
65
64
  })));
66
65
  _defineProperty(this, "signInWithGoogle", /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee3() {
67
- var provider, resp;
68
- return _regeneratorRuntime__default["default"].wrap(function _callee3$(_context3) {
66
+ var provider, resp, _t;
67
+ return _regeneratorRuntime__default["default"].wrap(function (_context3) {
69
68
  while (1) switch (_context3.prev = _context3.next) {
70
69
  case 0:
71
70
  _context3.prev = 0;
72
71
  provider = new auth.GoogleAuthProvider();
73
- _context3.next = 4;
72
+ _context3.next = 1;
74
73
  return auth.signInWithPopup(_this.auth, provider);
75
- case 4:
74
+ case 1:
76
75
  resp = _context3.sent;
77
76
  _this.currentUser = {
78
77
  email: resp.user.email,
@@ -87,15 +86,15 @@ var FirebaseAuthService = /*#__PURE__*/function () {
87
86
  url: undefined.VITE_AUTH_DOMAIN
88
87
  }
89
88
  });
90
- case 9:
91
- _context3.prev = 9;
92
- _context3.t0 = _context3["catch"](0);
93
- console.error(_context3.t0);
94
- case 12:
89
+ case 2:
90
+ _context3.prev = 2;
91
+ _t = _context3["catch"](0);
92
+ console.error(_t);
93
+ case 3:
95
94
  case "end":
96
95
  return _context3.stop();
97
96
  }
98
- }, _callee3, null, [[0, 9]]);
97
+ }, _callee3, null, [[0, 2]]);
99
98
  })));
100
99
  this.auth.onAuthStateChanged(function (user) {
101
100
  if (user) {
@@ -141,14 +140,14 @@ var FirebaseStorageService = /*#__PURE__*/_createClass(function FirebaseStorageS
141
140
  _defineProperty(this, "downloadFile", /*#__PURE__*/function () {
142
141
  var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(filepath) {
143
142
  var fileRef;
144
- return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
143
+ return _regeneratorRuntime__default["default"].wrap(function (_context) {
145
144
  while (1) switch (_context.prev = _context.next) {
146
145
  case 0:
147
146
  fileRef = storage.ref(_this.storage, filepath);
148
147
  return _context.abrupt("return", storage.getBytes(fileRef).then(function (b) {
149
148
  return _this.decoder.decode(b);
150
149
  }));
151
- case 2:
150
+ case 1:
152
151
  case "end":
153
152
  return _context.stop();
154
153
  }
@@ -162,19 +161,9 @@ var FirebaseStorageService = /*#__PURE__*/_createClass(function FirebaseStorageS
162
161
 
163
162
  var FirestoreService = /*#__PURE__*/function () {
164
163
  function FirestoreService(collectionName) {
165
- var _this = this;
166
164
  _classCallCheck(this, FirestoreService);
167
165
  _defineProperty(this, "collectionName", "player");
168
166
  _defineProperty(this, "db", firestore.getFirestore(firebaseClient));
169
- _defineProperty(this, "addBatch", function (entities) {
170
- var batch = firestore.writeBatch(_this.db);
171
- entities.forEach(function (e) {
172
- e.id = uuid.v4();
173
- var docRef = firestore.doc(_this.db, _this.collectionName, e.id);
174
- batch.set(docRef, e);
175
- });
176
- return batch.commit();
177
- });
178
167
  this.collectionName = collectionName;
179
168
  }
180
169
 
@@ -184,19 +173,19 @@ var FirestoreService = /*#__PURE__*/function () {
184
173
  value: function () {
185
174
  var _getAll = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(count, select) {
186
175
  var querySnapshot;
187
- return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
176
+ return _regeneratorRuntime__default["default"].wrap(function (_context) {
188
177
  while (1) switch (_context.prev = _context.next) {
189
178
  case 0:
190
- _context.next = 2;
179
+ _context.next = 1;
191
180
  return firestore.getDocs(firestore.collection(this.db, this.collectionName));
192
- case 2:
181
+ case 1:
193
182
  querySnapshot = _context.sent;
194
183
  return _context.abrupt("return", querySnapshot.docs.map(function (doc) {
195
184
  return _objectSpread(_objectSpread({}, doc.data()), {}, {
196
185
  id: doc.id
197
186
  });
198
187
  }));
199
- case 4:
188
+ case 2:
200
189
  case "end":
201
190
  return _context.stop();
202
191
  }
@@ -211,37 +200,37 @@ var FirestoreService = /*#__PURE__*/function () {
211
200
  key: "getById",
212
201
  value: function () {
213
202
  var _getById = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2(id, select) {
214
- var docRef;
215
- return _regeneratorRuntime__default["default"].wrap(function _callee2$(_context2) {
203
+ var docRef, _t;
204
+ return _regeneratorRuntime__default["default"].wrap(function (_context2) {
216
205
  while (1) switch (_context2.prev = _context2.next) {
217
206
  case 0:
218
207
  _context2.prev = 0;
219
- _context2.next = 3;
208
+ _context2.next = 1;
220
209
  return firestore.getDoc(firestore.doc(this.db, this.collectionName, id));
221
- case 3:
210
+ case 1:
222
211
  docRef = _context2.sent;
223
212
  if (!docRef.exists()) {
224
- _context2.next = 8;
213
+ _context2.next = 2;
225
214
  break;
226
215
  }
227
216
  return _context2.abrupt("return", _objectSpread(_objectSpread({}, docRef.data()), {}, {
228
217
  id: docRef.id
229
218
  }));
230
- case 8:
219
+ case 2:
231
220
  throw Error("entity with id: ".concat(id, ", does not exist"));
232
- case 9:
233
- _context2.next = 15;
221
+ case 3:
222
+ _context2.next = 5;
234
223
  break;
235
- case 11:
236
- _context2.prev = 11;
237
- _context2.t0 = _context2["catch"](0);
238
- console.error("Error getting document: ", _context2.t0);
239
- throw _context2.t0;
240
- case 15:
224
+ case 4:
225
+ _context2.prev = 4;
226
+ _t = _context2["catch"](0);
227
+ console.error("Error getting document: ", _t);
228
+ throw _t;
229
+ case 5:
241
230
  case "end":
242
231
  return _context2.stop();
243
232
  }
244
- }, _callee2, this, [[0, 11]]);
233
+ }, _callee2, this, [[0, 4]]);
245
234
  }));
246
235
  function getById(_x3, _x4) {
247
236
  return _getById.apply(this, arguments);
@@ -252,28 +241,26 @@ var FirestoreService = /*#__PURE__*/function () {
252
241
  key: "batchInsert",
253
242
  value: function () {
254
243
  var _batchInsert = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee3(entities, select, user) {
255
- return _regeneratorRuntime__default["default"].wrap(function _callee3$(_context3) {
244
+ var _t2;
245
+ return _regeneratorRuntime__default["default"].wrap(function (_context3) {
256
246
  while (1) switch (_context3.prev = _context3.next) {
257
247
  case 0:
258
248
  _context3.prev = 0;
259
- entities.forEach(function (entity) {
260
- return entity.id = uuid.v4();
261
- });
262
- _context3.next = 4;
249
+ _context3.next = 1;
263
250
  return firestore.addDoc(firestore.collection(this.db, this.collectionName), entities);
264
- case 4:
251
+ case 1:
265
252
  _context3.sent;
266
253
  return _context3.abrupt("return", entities);
267
- case 8:
268
- _context3.prev = 8;
269
- _context3.t0 = _context3["catch"](0);
270
- console.error("Error adding document: ", _context3.t0);
271
- throw _context3.t0;
272
- case 12:
254
+ case 2:
255
+ _context3.prev = 2;
256
+ _t2 = _context3["catch"](0);
257
+ console.error("Error adding document: ", _t2);
258
+ throw _t2;
259
+ case 3:
273
260
  case "end":
274
261
  return _context3.stop();
275
262
  }
276
- }, _callee3, this, [[0, 8]]);
263
+ }, _callee3, this, [[0, 2]]);
277
264
  }));
278
265
  function batchInsert(_x5, _x6, _x7) {
279
266
  return _batchInsert.apply(this, arguments);
@@ -284,28 +271,30 @@ var FirestoreService = /*#__PURE__*/function () {
284
271
  key: "insert",
285
272
  value: function () {
286
273
  var _insert = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee4(entity, select, user) {
287
- return _regeneratorRuntime__default["default"].wrap(function _callee4$(_context4) {
274
+ var docRef, _t3;
275
+ return _regeneratorRuntime__default["default"].wrap(function (_context4) {
288
276
  while (1) switch (_context4.prev = _context4.next) {
289
277
  case 0:
290
278
  _context4.prev = 0;
291
- entity.id = uuid.v4();
292
- _context4.next = 4;
279
+ _context4.next = 1;
293
280
  return firestore.addDoc(firestore.collection(this.db, this.collectionName), entity);
294
- case 4:
295
- _context4.sent;
296
- return _context4.abrupt("return", entity);
297
- case 8:
298
- _context4.prev = 8;
299
- _context4.t0 = _context4["catch"](0);
300
- console.error("Error adding document: ", _context4.t0);
301
- throw _context4.t0;
302
- case 12:
281
+ case 1:
282
+ docRef = _context4.sent;
283
+ return _context4.abrupt("return", _objectSpread(_objectSpread({}, docRef.toJSON()), {}, {
284
+ id: docRef.id
285
+ }));
286
+ case 2:
287
+ _context4.prev = 2;
288
+ _t3 = _context4["catch"](0);
289
+ console.error("Error adding document: ", _t3);
290
+ throw _t3;
291
+ case 3:
303
292
  case "end":
304
293
  return _context4.stop();
305
294
  }
306
- }, _callee4, this, [[0, 8]]);
295
+ }, _callee4, this, [[0, 2]]);
307
296
  }));
308
- function insert(_x8, _x9, _x10) {
297
+ function insert(_x8, _x9, _x0) {
309
298
  return _insert.apply(this, arguments);
310
299
  }
311
300
  return insert;
@@ -314,26 +303,26 @@ var FirestoreService = /*#__PURE__*/function () {
314
303
  key: "update",
315
304
  value: function () {
316
305
  var _update = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee5(entityId, updatedFields, select, user) {
317
- var docRef;
318
- return _regeneratorRuntime__default["default"].wrap(function _callee5$(_context5) {
306
+ var docRef, _t4;
307
+ return _regeneratorRuntime__default["default"].wrap(function (_context5) {
319
308
  while (1) switch (_context5.prev = _context5.next) {
320
309
  case 0:
321
310
  _context5.prev = 0;
322
311
  docRef = firestore.doc(this.db, this.collectionName, entityId);
323
312
  firestore.updateDoc(docRef, updatedFields);
324
- return _context5.abrupt("return", updatedFields);
325
- case 6:
326
- _context5.prev = 6;
327
- _context5.t0 = _context5["catch"](0);
328
- console.error("Error updating document: ", _context5.t0);
329
- throw _context5.t0;
330
- case 10:
313
+ return _context5.abrupt("return", _objectSpread({}, updatedFields));
314
+ case 1:
315
+ _context5.prev = 1;
316
+ _t4 = _context5["catch"](0);
317
+ console.error("Error updating document: ", _t4);
318
+ throw _t4;
319
+ case 2:
331
320
  case "end":
332
321
  return _context5.stop();
333
322
  }
334
- }, _callee5, this, [[0, 6]]);
323
+ }, _callee5, this, [[0, 1]]);
335
324
  }));
336
- function update(_x11, _x12, _x13, _x14) {
325
+ function update(_x1, _x10, _x11, _x12) {
337
326
  return _update.apply(this, arguments);
338
327
  }
339
328
  return update;
@@ -342,18 +331,18 @@ var FirestoreService = /*#__PURE__*/function () {
342
331
  key: "delete",
343
332
  value: function () {
344
333
  var _delete2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee6(entityId) {
345
- return _regeneratorRuntime__default["default"].wrap(function _callee6$(_context6) {
334
+ return _regeneratorRuntime__default["default"].wrap(function (_context6) {
346
335
  while (1) switch (_context6.prev = _context6.next) {
347
336
  case 0:
348
337
  console.log('delete', entityId);
349
338
  return _context6.abrupt("return", firestore.deleteDoc(firestore.doc(this.db, this.collectionName, entityId)));
350
- case 2:
339
+ case 1:
351
340
  case "end":
352
341
  return _context6.stop();
353
342
  }
354
343
  }, _callee6, this);
355
344
  }));
356
- function _delete(_x15) {
345
+ function _delete(_x13) {
357
346
  return _delete2.apply(this, arguments);
358
347
  }
359
348
  return _delete;
@@ -7,8 +7,7 @@ import { getAuth, GoogleAuthProvider, signInWithPopup } from 'firebase/auth';
7
7
  import { initializeApp } from 'firebase/app';
8
8
  import { getStorage, ref, getBytes } from 'firebase/storage';
9
9
  import _objectSpread from '@babel/runtime/helpers/esm/objectSpread2';
10
- import { getDocs, collection, getDoc, doc, addDoc, updateDoc, deleteDoc, getFirestore, writeBatch } from 'firebase/firestore';
11
- import { v4 } from 'uuid';
10
+ import { getDocs, collection, getDoc, doc, addDoc, updateDoc, deleteDoc, getFirestore } from 'firebase/firestore';
12
11
 
13
12
  var firebaseConfig = {
14
13
  apiKey: import.meta.env.VITE_FIREBASE_API_KEY,
@@ -30,7 +29,7 @@ var FirebaseAuthService = /*#__PURE__*/function () {
30
29
  _defineProperty(this, "currentUser", undefined);
31
30
  _defineProperty(this, "auth", getAuth(firebaseClient));
32
31
  _defineProperty(this, "getUser", /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
33
- return _regeneratorRuntime.wrap(function _callee$(_context) {
32
+ return _regeneratorRuntime.wrap(function (_context) {
34
33
  while (1) switch (_context.prev = _context.next) {
35
34
  case 0:
36
35
  return _context.abrupt("return", _this.currentUser);
@@ -41,7 +40,7 @@ var FirebaseAuthService = /*#__PURE__*/function () {
41
40
  }, _callee);
42
41
  })));
43
42
  _defineProperty(this, "signOut", /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
44
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
43
+ return _regeneratorRuntime.wrap(function (_context2) {
45
44
  while (1) switch (_context2.prev = _context2.next) {
46
45
  case 0:
47
46
  _this.currentUser = undefined;
@@ -49,22 +48,22 @@ var FirebaseAuthService = /*#__PURE__*/function () {
49
48
  return _context2.abrupt("return", {
50
49
  error: null
51
50
  });
52
- case 3:
51
+ case 1:
53
52
  case "end":
54
53
  return _context2.stop();
55
54
  }
56
55
  }, _callee2);
57
56
  })));
58
57
  _defineProperty(this, "signInWithGoogle", /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
59
- var provider, resp;
60
- return _regeneratorRuntime.wrap(function _callee3$(_context3) {
58
+ var provider, resp, _t;
59
+ return _regeneratorRuntime.wrap(function (_context3) {
61
60
  while (1) switch (_context3.prev = _context3.next) {
62
61
  case 0:
63
62
  _context3.prev = 0;
64
63
  provider = new GoogleAuthProvider();
65
- _context3.next = 4;
64
+ _context3.next = 1;
66
65
  return signInWithPopup(_this.auth, provider);
67
- case 4:
66
+ case 1:
68
67
  resp = _context3.sent;
69
68
  _this.currentUser = {
70
69
  email: resp.user.email,
@@ -79,15 +78,15 @@ var FirebaseAuthService = /*#__PURE__*/function () {
79
78
  url: import.meta.env.VITE_AUTH_DOMAIN
80
79
  }
81
80
  });
82
- case 9:
83
- _context3.prev = 9;
84
- _context3.t0 = _context3["catch"](0);
85
- console.error(_context3.t0);
86
- case 12:
81
+ case 2:
82
+ _context3.prev = 2;
83
+ _t = _context3["catch"](0);
84
+ console.error(_t);
85
+ case 3:
87
86
  case "end":
88
87
  return _context3.stop();
89
88
  }
90
- }, _callee3, null, [[0, 9]]);
89
+ }, _callee3, null, [[0, 2]]);
91
90
  })));
92
91
  this.auth.onAuthStateChanged(function (user) {
93
92
  if (user) {
@@ -133,14 +132,14 @@ var FirebaseStorageService = /*#__PURE__*/_createClass(function FirebaseStorageS
133
132
  _defineProperty(this, "downloadFile", /*#__PURE__*/function () {
134
133
  var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(filepath) {
135
134
  var fileRef;
136
- return _regeneratorRuntime.wrap(function _callee$(_context) {
135
+ return _regeneratorRuntime.wrap(function (_context) {
137
136
  while (1) switch (_context.prev = _context.next) {
138
137
  case 0:
139
138
  fileRef = ref(_this.storage, filepath);
140
139
  return _context.abrupt("return", getBytes(fileRef).then(function (b) {
141
140
  return _this.decoder.decode(b);
142
141
  }));
143
- case 2:
142
+ case 1:
144
143
  case "end":
145
144
  return _context.stop();
146
145
  }
@@ -154,19 +153,9 @@ var FirebaseStorageService = /*#__PURE__*/_createClass(function FirebaseStorageS
154
153
 
155
154
  var FirestoreService = /*#__PURE__*/function () {
156
155
  function FirestoreService(collectionName) {
157
- var _this = this;
158
156
  _classCallCheck(this, FirestoreService);
159
157
  _defineProperty(this, "collectionName", "player");
160
158
  _defineProperty(this, "db", getFirestore(firebaseClient));
161
- _defineProperty(this, "addBatch", function (entities) {
162
- var batch = writeBatch(_this.db);
163
- entities.forEach(function (e) {
164
- e.id = v4();
165
- var docRef = doc(_this.db, _this.collectionName, e.id);
166
- batch.set(docRef, e);
167
- });
168
- return batch.commit();
169
- });
170
159
  this.collectionName = collectionName;
171
160
  }
172
161
 
@@ -176,19 +165,19 @@ var FirestoreService = /*#__PURE__*/function () {
176
165
  value: function () {
177
166
  var _getAll = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(count, select) {
178
167
  var querySnapshot;
179
- return _regeneratorRuntime.wrap(function _callee$(_context) {
168
+ return _regeneratorRuntime.wrap(function (_context) {
180
169
  while (1) switch (_context.prev = _context.next) {
181
170
  case 0:
182
- _context.next = 2;
171
+ _context.next = 1;
183
172
  return getDocs(collection(this.db, this.collectionName));
184
- case 2:
173
+ case 1:
185
174
  querySnapshot = _context.sent;
186
175
  return _context.abrupt("return", querySnapshot.docs.map(function (doc) {
187
176
  return _objectSpread(_objectSpread({}, doc.data()), {}, {
188
177
  id: doc.id
189
178
  });
190
179
  }));
191
- case 4:
180
+ case 2:
192
181
  case "end":
193
182
  return _context.stop();
194
183
  }
@@ -203,37 +192,37 @@ var FirestoreService = /*#__PURE__*/function () {
203
192
  key: "getById",
204
193
  value: function () {
205
194
  var _getById = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(id, select) {
206
- var docRef;
207
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
195
+ var docRef, _t;
196
+ return _regeneratorRuntime.wrap(function (_context2) {
208
197
  while (1) switch (_context2.prev = _context2.next) {
209
198
  case 0:
210
199
  _context2.prev = 0;
211
- _context2.next = 3;
200
+ _context2.next = 1;
212
201
  return getDoc(doc(this.db, this.collectionName, id));
213
- case 3:
202
+ case 1:
214
203
  docRef = _context2.sent;
215
204
  if (!docRef.exists()) {
216
- _context2.next = 8;
205
+ _context2.next = 2;
217
206
  break;
218
207
  }
219
208
  return _context2.abrupt("return", _objectSpread(_objectSpread({}, docRef.data()), {}, {
220
209
  id: docRef.id
221
210
  }));
222
- case 8:
211
+ case 2:
223
212
  throw Error("entity with id: ".concat(id, ", does not exist"));
224
- case 9:
225
- _context2.next = 15;
213
+ case 3:
214
+ _context2.next = 5;
226
215
  break;
227
- case 11:
228
- _context2.prev = 11;
229
- _context2.t0 = _context2["catch"](0);
230
- console.error("Error getting document: ", _context2.t0);
231
- throw _context2.t0;
232
- case 15:
216
+ case 4:
217
+ _context2.prev = 4;
218
+ _t = _context2["catch"](0);
219
+ console.error("Error getting document: ", _t);
220
+ throw _t;
221
+ case 5:
233
222
  case "end":
234
223
  return _context2.stop();
235
224
  }
236
- }, _callee2, this, [[0, 11]]);
225
+ }, _callee2, this, [[0, 4]]);
237
226
  }));
238
227
  function getById(_x3, _x4) {
239
228
  return _getById.apply(this, arguments);
@@ -244,28 +233,26 @@ var FirestoreService = /*#__PURE__*/function () {
244
233
  key: "batchInsert",
245
234
  value: function () {
246
235
  var _batchInsert = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(entities, select, user) {
247
- return _regeneratorRuntime.wrap(function _callee3$(_context3) {
236
+ var _t2;
237
+ return _regeneratorRuntime.wrap(function (_context3) {
248
238
  while (1) switch (_context3.prev = _context3.next) {
249
239
  case 0:
250
240
  _context3.prev = 0;
251
- entities.forEach(function (entity) {
252
- return entity.id = v4();
253
- });
254
- _context3.next = 4;
241
+ _context3.next = 1;
255
242
  return addDoc(collection(this.db, this.collectionName), entities);
256
- case 4:
243
+ case 1:
257
244
  _context3.sent;
258
245
  return _context3.abrupt("return", entities);
259
- case 8:
260
- _context3.prev = 8;
261
- _context3.t0 = _context3["catch"](0);
262
- console.error("Error adding document: ", _context3.t0);
263
- throw _context3.t0;
264
- case 12:
246
+ case 2:
247
+ _context3.prev = 2;
248
+ _t2 = _context3["catch"](0);
249
+ console.error("Error adding document: ", _t2);
250
+ throw _t2;
251
+ case 3:
265
252
  case "end":
266
253
  return _context3.stop();
267
254
  }
268
- }, _callee3, this, [[0, 8]]);
255
+ }, _callee3, this, [[0, 2]]);
269
256
  }));
270
257
  function batchInsert(_x5, _x6, _x7) {
271
258
  return _batchInsert.apply(this, arguments);
@@ -276,28 +263,30 @@ var FirestoreService = /*#__PURE__*/function () {
276
263
  key: "insert",
277
264
  value: function () {
278
265
  var _insert = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(entity, select, user) {
279
- return _regeneratorRuntime.wrap(function _callee4$(_context4) {
266
+ var docRef, _t3;
267
+ return _regeneratorRuntime.wrap(function (_context4) {
280
268
  while (1) switch (_context4.prev = _context4.next) {
281
269
  case 0:
282
270
  _context4.prev = 0;
283
- entity.id = v4();
284
- _context4.next = 4;
271
+ _context4.next = 1;
285
272
  return addDoc(collection(this.db, this.collectionName), entity);
286
- case 4:
287
- _context4.sent;
288
- return _context4.abrupt("return", entity);
289
- case 8:
290
- _context4.prev = 8;
291
- _context4.t0 = _context4["catch"](0);
292
- console.error("Error adding document: ", _context4.t0);
293
- throw _context4.t0;
294
- case 12:
273
+ case 1:
274
+ docRef = _context4.sent;
275
+ return _context4.abrupt("return", _objectSpread(_objectSpread({}, docRef.toJSON()), {}, {
276
+ id: docRef.id
277
+ }));
278
+ case 2:
279
+ _context4.prev = 2;
280
+ _t3 = _context4["catch"](0);
281
+ console.error("Error adding document: ", _t3);
282
+ throw _t3;
283
+ case 3:
295
284
  case "end":
296
285
  return _context4.stop();
297
286
  }
298
- }, _callee4, this, [[0, 8]]);
287
+ }, _callee4, this, [[0, 2]]);
299
288
  }));
300
- function insert(_x8, _x9, _x10) {
289
+ function insert(_x8, _x9, _x0) {
301
290
  return _insert.apply(this, arguments);
302
291
  }
303
292
  return insert;
@@ -306,26 +295,26 @@ var FirestoreService = /*#__PURE__*/function () {
306
295
  key: "update",
307
296
  value: function () {
308
297
  var _update = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(entityId, updatedFields, select, user) {
309
- var docRef;
310
- return _regeneratorRuntime.wrap(function _callee5$(_context5) {
298
+ var docRef, _t4;
299
+ return _regeneratorRuntime.wrap(function (_context5) {
311
300
  while (1) switch (_context5.prev = _context5.next) {
312
301
  case 0:
313
302
  _context5.prev = 0;
314
303
  docRef = doc(this.db, this.collectionName, entityId);
315
304
  updateDoc(docRef, updatedFields);
316
- return _context5.abrupt("return", updatedFields);
317
- case 6:
318
- _context5.prev = 6;
319
- _context5.t0 = _context5["catch"](0);
320
- console.error("Error updating document: ", _context5.t0);
321
- throw _context5.t0;
322
- case 10:
305
+ return _context5.abrupt("return", _objectSpread({}, updatedFields));
306
+ case 1:
307
+ _context5.prev = 1;
308
+ _t4 = _context5["catch"](0);
309
+ console.error("Error updating document: ", _t4);
310
+ throw _t4;
311
+ case 2:
323
312
  case "end":
324
313
  return _context5.stop();
325
314
  }
326
- }, _callee5, this, [[0, 6]]);
315
+ }, _callee5, this, [[0, 1]]);
327
316
  }));
328
- function update(_x11, _x12, _x13, _x14) {
317
+ function update(_x1, _x10, _x11, _x12) {
329
318
  return _update.apply(this, arguments);
330
319
  }
331
320
  return update;
@@ -334,18 +323,18 @@ var FirestoreService = /*#__PURE__*/function () {
334
323
  key: "delete",
335
324
  value: function () {
336
325
  var _delete2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6(entityId) {
337
- return _regeneratorRuntime.wrap(function _callee6$(_context6) {
326
+ return _regeneratorRuntime.wrap(function (_context6) {
338
327
  while (1) switch (_context6.prev = _context6.next) {
339
328
  case 0:
340
329
  console.log('delete', entityId);
341
330
  return _context6.abrupt("return", deleteDoc(doc(this.db, this.collectionName, entityId)));
342
- case 2:
331
+ case 1:
343
332
  case "end":
344
333
  return _context6.stop();
345
334
  }
346
335
  }, _callee6, this);
347
336
  }));
348
- function _delete(_x15) {
337
+ function _delete(_x13) {
349
338
  return _delete2.apply(this, arguments);
350
339
  }
351
340
  return _delete;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitalaidseattle/firebase",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Wrapper for firebase that works with DAS Component library",
5
5
  "repository": "null//github.com/null/github.com/tree/master/packages/firebase",
6
6
  "main": "dist/digitalaidseattle-firebase.cjs.js",