@digitalaidseattle/firebase 1.0.2 → 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.
@@ -3,12 +3,13 @@ declare class FirebaseAuthService implements AuthService {
3
3
  currentUser: User | undefined;
4
4
  auth: import("@firebase/auth").Auth;
5
5
  constructor();
6
+ getProviders(): string[];
7
+ signInWith(provider: string): Promise<OAuthResponse>;
6
8
  hasUser(): Promise<boolean>;
7
9
  getUser: () => Promise<any | null>;
8
10
  signOut: () => Promise<{
9
11
  error: AuthError | null;
10
12
  }>;
11
13
  signInWithGoogle: () => Promise<any>;
12
- signInWithAzure(): Promise<OAuthResponse>;
13
14
  }
14
15
  export { FirebaseAuthService };
@@ -1,16 +1,14 @@
1
- type Entity = {
2
- id: string | undefined;
3
- };
4
- declare class FirestoreService<T extends Entity> {
1
+ import { Entity, EntityService, Identifier, User } from "@digitalaidseattle/core";
2
+ declare class FirestoreService<T extends Entity> implements EntityService<T> {
5
3
  collectionName: string;
6
4
  db: import("@firebase/firestore").Firestore;
7
5
  constructor(collectionName: string);
8
- add(entity: T): Promise<void>;
9
- getById(id: string): Promise<T>;
10
- update(entity: T): Promise<void>;
11
- delete(entity: T): Promise<void>;
12
- getAll(): Promise<T[]>;
13
- addBatch: (entities: T[]) => Promise<void>;
6
+ getAll(count?: number, select?: string): Promise<T[]>;
7
+ getById(id: string, select?: string): Promise<T>;
8
+ batchInsert(entities: T[], select?: string, user?: User): Promise<T[]>;
9
+ insert(entity: T, select?: string, user?: User): Promise<T>;
10
+ update(entityId: Identifier, updatedFields: T, select?: string, user?: User): Promise<T>;
11
+ delete(entityId: Identifier): Promise<void>;
14
12
  }
15
13
  export { FirestoreService };
16
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) {
@@ -111,16 +110,25 @@ var FirebaseAuthService = /*#__PURE__*/function () {
111
110
  });
112
111
  }
113
112
  return _createClass(FirebaseAuthService, [{
113
+ key: "getProviders",
114
+ value: function getProviders() {
115
+ return ["google"];
116
+ }
117
+ }, {
118
+ key: "signInWith",
119
+ value: function signInWith(provider) {
120
+ switch (provider) {
121
+ case 'google':
122
+ return this.signInWithGoogle();
123
+ default:
124
+ throw new Error('Unrecognized provider ' + provider);
125
+ }
126
+ }
127
+ }, {
114
128
  key: "hasUser",
115
129
  value: function hasUser() {
116
130
  return Promise.resolve(this.currentUser !== null);
117
131
  }
118
- }, {
119
- key: "signInWithAzure",
120
- value: function signInWithAzure() {
121
- // Placeholder implementation, as Azure sign-in is not implemented
122
- return Promise.reject(new Error('Method not implemented.'));
123
- }
124
132
  }]);
125
133
  }();
126
134
 
@@ -132,14 +140,14 @@ var FirebaseStorageService = /*#__PURE__*/_createClass(function FirebaseStorageS
132
140
  _defineProperty(this, "downloadFile", /*#__PURE__*/function () {
133
141
  var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(filepath) {
134
142
  var fileRef;
135
- return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
143
+ return _regeneratorRuntime__default["default"].wrap(function (_context) {
136
144
  while (1) switch (_context.prev = _context.next) {
137
145
  case 0:
138
146
  fileRef = storage.ref(_this.storage, filepath);
139
147
  return _context.abrupt("return", storage.getBytes(fileRef).then(function (b) {
140
148
  return _this.decoder.decode(b);
141
149
  }));
142
- case 2:
150
+ case 1:
143
151
  case "end":
144
152
  return _context.stop();
145
153
  }
@@ -153,180 +161,191 @@ var FirebaseStorageService = /*#__PURE__*/_createClass(function FirebaseStorageS
153
161
 
154
162
  var FirestoreService = /*#__PURE__*/function () {
155
163
  function FirestoreService(collectionName) {
156
- var _this = this;
157
164
  _classCallCheck(this, FirestoreService);
158
165
  _defineProperty(this, "collectionName", "player");
159
166
  _defineProperty(this, "db", firestore.getFirestore(firebaseClient));
160
- _defineProperty(this, "addBatch", function (entities) {
161
- var batch = firestore.writeBatch(_this.db);
162
- entities.forEach(function (e) {
163
- e.id = uuid.v4();
164
- var docRef = firestore.doc(_this.db, _this.collectionName, e.id);
165
- batch.set(docRef, e);
166
- });
167
- return batch.commit();
168
- });
169
167
  this.collectionName = collectionName;
170
168
  }
171
169
 
172
- // Add a document to a collection
170
+ // Get all documents from a collection
173
171
  return _createClass(FirestoreService, [{
174
- key: "add",
172
+ key: "getAll",
175
173
  value: function () {
176
- var _add = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(entity) {
177
- var docRef;
178
- return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
174
+ var _getAll = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(count, select) {
175
+ var querySnapshot;
176
+ return _regeneratorRuntime__default["default"].wrap(function (_context) {
179
177
  while (1) switch (_context.prev = _context.next) {
180
178
  case 0:
181
- _context.prev = 0;
182
- entity.id = uuid.v4();
183
- _context.next = 4;
184
- return firestore.addDoc(firestore.collection(this.db, this.collectionName), entity);
185
- case 4:
186
- docRef = _context.sent;
187
- console.log("Document written with ID: ", docRef.id);
188
- _context.next = 11;
189
- break;
190
- case 8:
191
- _context.prev = 8;
192
- _context.t0 = _context["catch"](0);
193
- console.error("Error adding document: ", _context.t0);
194
- case 11:
179
+ _context.next = 1;
180
+ return firestore.getDocs(firestore.collection(this.db, this.collectionName));
181
+ case 1:
182
+ querySnapshot = _context.sent;
183
+ return _context.abrupt("return", querySnapshot.docs.map(function (doc) {
184
+ return _objectSpread(_objectSpread({}, doc.data()), {}, {
185
+ id: doc.id
186
+ });
187
+ }));
188
+ case 2:
195
189
  case "end":
196
190
  return _context.stop();
197
191
  }
198
- }, _callee, this, [[0, 8]]);
192
+ }, _callee, this);
199
193
  }));
200
- function add(_x) {
201
- return _add.apply(this, arguments);
194
+ function getAll(_x, _x2) {
195
+ return _getAll.apply(this, arguments);
202
196
  }
203
- return add;
197
+ return getAll;
204
198
  }() // Update a document to a collection
205
199
  }, {
206
200
  key: "getById",
207
201
  value: function () {
208
- var _getById = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2(id) {
209
- var docRef;
210
- return _regeneratorRuntime__default["default"].wrap(function _callee2$(_context2) {
202
+ var _getById = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2(id, select) {
203
+ var docRef, _t;
204
+ return _regeneratorRuntime__default["default"].wrap(function (_context2) {
211
205
  while (1) switch (_context2.prev = _context2.next) {
212
206
  case 0:
213
207
  _context2.prev = 0;
214
- _context2.next = 3;
208
+ _context2.next = 1;
215
209
  return firestore.getDoc(firestore.doc(this.db, this.collectionName, id));
216
- case 3:
210
+ case 1:
217
211
  docRef = _context2.sent;
218
212
  if (!docRef.exists()) {
219
- _context2.next = 8;
213
+ _context2.next = 2;
220
214
  break;
221
215
  }
222
216
  return _context2.abrupt("return", _objectSpread(_objectSpread({}, docRef.data()), {}, {
223
217
  id: docRef.id
224
218
  }));
225
- case 8:
219
+ case 2:
226
220
  throw Error("entity with id: ".concat(id, ", does not exist"));
227
- case 9:
228
- _context2.next = 15;
221
+ case 3:
222
+ _context2.next = 5;
229
223
  break;
230
- case 11:
231
- _context2.prev = 11;
232
- _context2.t0 = _context2["catch"](0);
233
- console.error("Error getting document: ", _context2.t0);
234
- throw _context2.t0;
235
- 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:
236
230
  case "end":
237
231
  return _context2.stop();
238
232
  }
239
- }, _callee2, this, [[0, 11]]);
233
+ }, _callee2, this, [[0, 4]]);
240
234
  }));
241
- function getById(_x2) {
235
+ function getById(_x3, _x4) {
242
236
  return _getById.apply(this, arguments);
243
237
  }
244
238
  return getById;
245
- }() // Update a document to a collection
239
+ }() // Add a document to a collection
246
240
  }, {
247
- key: "update",
241
+ key: "batchInsert",
248
242
  value: function () {
249
- var _update = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee3(entity) {
250
- var docRef;
251
- return _regeneratorRuntime__default["default"].wrap(function _callee3$(_context3) {
243
+ var _batchInsert = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee3(entities, select, user) {
244
+ var _t2;
245
+ return _regeneratorRuntime__default["default"].wrap(function (_context3) {
252
246
  while (1) switch (_context3.prev = _context3.next) {
253
247
  case 0:
254
248
  _context3.prev = 0;
255
- if (!entity.id) {
256
- _context3.next = 4;
257
- break;
258
- }
259
- docRef = firestore.doc(this.db, this.collectionName, entity.id);
260
- return _context3.abrupt("return", firestore.updateDoc(docRef, entity));
261
- case 4:
262
- throw new Error('Entity does not have an id.');
263
- case 7:
264
- _context3.prev = 7;
265
- _context3.t0 = _context3["catch"](0);
266
- console.error("Error updating document: ", _context3.t0);
267
- case 10:
249
+ _context3.next = 1;
250
+ return firestore.addDoc(firestore.collection(this.db, this.collectionName), entities);
251
+ case 1:
252
+ _context3.sent;
253
+ return _context3.abrupt("return", entities);
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:
268
260
  case "end":
269
261
  return _context3.stop();
270
262
  }
271
- }, _callee3, this, [[0, 7]]);
263
+ }, _callee3, this, [[0, 2]]);
272
264
  }));
273
- function update(_x3) {
274
- return _update.apply(this, arguments);
265
+ function batchInsert(_x5, _x6, _x7) {
266
+ return _batchInsert.apply(this, arguments);
275
267
  }
276
- return update;
277
- }()
268
+ return batchInsert;
269
+ }() // Add a document to a collection
278
270
  }, {
279
- key: "delete",
271
+ key: "insert",
280
272
  value: function () {
281
- var _delete2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee4(entity) {
282
- return _regeneratorRuntime__default["default"].wrap(function _callee4$(_context4) {
273
+ var _insert = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee4(entity, select, user) {
274
+ var docRef, _t3;
275
+ return _regeneratorRuntime__default["default"].wrap(function (_context4) {
283
276
  while (1) switch (_context4.prev = _context4.next) {
284
277
  case 0:
285
- if (!entity.id) {
286
- _context4.next = 2;
287
- break;
288
- }
289
- return _context4.abrupt("return", firestore.deleteDoc(firestore.doc(this.db, this.collectionName, entity.id)));
278
+ _context4.prev = 0;
279
+ _context4.next = 1;
280
+ return firestore.addDoc(firestore.collection(this.db, this.collectionName), entity);
281
+ case 1:
282
+ docRef = _context4.sent;
283
+ return _context4.abrupt("return", _objectSpread(_objectSpread({}, docRef.toJSON()), {}, {
284
+ id: docRef.id
285
+ }));
290
286
  case 2:
291
- throw new Error('Entity does not have an id.');
287
+ _context4.prev = 2;
288
+ _t3 = _context4["catch"](0);
289
+ console.error("Error adding document: ", _t3);
290
+ throw _t3;
292
291
  case 3:
293
292
  case "end":
294
293
  return _context4.stop();
295
294
  }
296
- }, _callee4, this);
295
+ }, _callee4, this, [[0, 2]]);
297
296
  }));
298
- function _delete(_x4) {
299
- return _delete2.apply(this, arguments);
297
+ function insert(_x8, _x9, _x0) {
298
+ return _insert.apply(this, arguments);
300
299
  }
301
- return _delete;
302
- }() // Get all documents from a collection
300
+ return insert;
301
+ }() // Update a document to a collection
303
302
  }, {
304
- key: "getAll",
303
+ key: "update",
305
304
  value: function () {
306
- var _getAll = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee5() {
307
- var querySnapshot;
308
- return _regeneratorRuntime__default["default"].wrap(function _callee5$(_context5) {
305
+ var _update = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee5(entityId, updatedFields, select, user) {
306
+ var docRef, _t4;
307
+ return _regeneratorRuntime__default["default"].wrap(function (_context5) {
309
308
  while (1) switch (_context5.prev = _context5.next) {
310
309
  case 0:
311
- _context5.next = 2;
312
- return firestore.getDocs(firestore.collection(this.db, this.collectionName));
310
+ _context5.prev = 0;
311
+ docRef = firestore.doc(this.db, this.collectionName, entityId);
312
+ firestore.updateDoc(docRef, updatedFields);
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;
313
319
  case 2:
314
- querySnapshot = _context5.sent;
315
- return _context5.abrupt("return", querySnapshot.docs.map(function (doc) {
316
- return _objectSpread(_objectSpread({}, doc.data()), {}, {
317
- id: doc.id
318
- });
319
- }));
320
- case 4:
321
320
  case "end":
322
321
  return _context5.stop();
323
322
  }
324
- }, _callee5, this);
323
+ }, _callee5, this, [[0, 1]]);
325
324
  }));
326
- function getAll() {
327
- return _getAll.apply(this, arguments);
325
+ function update(_x1, _x10, _x11, _x12) {
326
+ return _update.apply(this, arguments);
328
327
  }
329
- return getAll;
328
+ return update;
329
+ }()
330
+ }, {
331
+ key: "delete",
332
+ value: function () {
333
+ var _delete2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee6(entityId) {
334
+ return _regeneratorRuntime__default["default"].wrap(function (_context6) {
335
+ while (1) switch (_context6.prev = _context6.next) {
336
+ case 0:
337
+ console.log('delete', entityId);
338
+ return _context6.abrupt("return", firestore.deleteDoc(firestore.doc(this.db, this.collectionName, entityId)));
339
+ case 1:
340
+ case "end":
341
+ return _context6.stop();
342
+ }
343
+ }, _callee6, this);
344
+ }));
345
+ function _delete(_x13) {
346
+ return _delete2.apply(this, arguments);
347
+ }
348
+ return _delete;
330
349
  }()
331
350
  }]);
332
351
  }();
@@ -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) {
@@ -111,16 +110,25 @@ var FirebaseAuthService = /*#__PURE__*/function () {
111
110
  });
112
111
  }
113
112
  return _createClass(FirebaseAuthService, [{
113
+ key: "getProviders",
114
+ value: function getProviders() {
115
+ return ["google"];
116
+ }
117
+ }, {
118
+ key: "signInWith",
119
+ value: function signInWith(provider) {
120
+ switch (provider) {
121
+ case 'google':
122
+ return this.signInWithGoogle();
123
+ default:
124
+ throw new Error('Unrecognized provider ' + provider);
125
+ }
126
+ }
127
+ }, {
114
128
  key: "hasUser",
115
129
  value: function hasUser() {
116
130
  return Promise.resolve(this.currentUser !== null);
117
131
  }
118
- }, {
119
- key: "signInWithAzure",
120
- value: function signInWithAzure() {
121
- // Placeholder implementation, as Azure sign-in is not implemented
122
- return Promise.reject(new Error('Method not implemented.'));
123
- }
124
132
  }]);
125
133
  }();
126
134
 
@@ -132,14 +140,14 @@ var FirebaseStorageService = /*#__PURE__*/_createClass(function FirebaseStorageS
132
140
  _defineProperty(this, "downloadFile", /*#__PURE__*/function () {
133
141
  var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(filepath) {
134
142
  var fileRef;
135
- return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
143
+ return _regeneratorRuntime__default["default"].wrap(function (_context) {
136
144
  while (1) switch (_context.prev = _context.next) {
137
145
  case 0:
138
146
  fileRef = storage.ref(_this.storage, filepath);
139
147
  return _context.abrupt("return", storage.getBytes(fileRef).then(function (b) {
140
148
  return _this.decoder.decode(b);
141
149
  }));
142
- case 2:
150
+ case 1:
143
151
  case "end":
144
152
  return _context.stop();
145
153
  }
@@ -153,180 +161,191 @@ var FirebaseStorageService = /*#__PURE__*/_createClass(function FirebaseStorageS
153
161
 
154
162
  var FirestoreService = /*#__PURE__*/function () {
155
163
  function FirestoreService(collectionName) {
156
- var _this = this;
157
164
  _classCallCheck(this, FirestoreService);
158
165
  _defineProperty(this, "collectionName", "player");
159
166
  _defineProperty(this, "db", firestore.getFirestore(firebaseClient));
160
- _defineProperty(this, "addBatch", function (entities) {
161
- var batch = firestore.writeBatch(_this.db);
162
- entities.forEach(function (e) {
163
- e.id = uuid.v4();
164
- var docRef = firestore.doc(_this.db, _this.collectionName, e.id);
165
- batch.set(docRef, e);
166
- });
167
- return batch.commit();
168
- });
169
167
  this.collectionName = collectionName;
170
168
  }
171
169
 
172
- // Add a document to a collection
170
+ // Get all documents from a collection
173
171
  return _createClass(FirestoreService, [{
174
- key: "add",
172
+ key: "getAll",
175
173
  value: function () {
176
- var _add = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(entity) {
177
- var docRef;
178
- return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
174
+ var _getAll = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(count, select) {
175
+ var querySnapshot;
176
+ return _regeneratorRuntime__default["default"].wrap(function (_context) {
179
177
  while (1) switch (_context.prev = _context.next) {
180
178
  case 0:
181
- _context.prev = 0;
182
- entity.id = uuid.v4();
183
- _context.next = 4;
184
- return firestore.addDoc(firestore.collection(this.db, this.collectionName), entity);
185
- case 4:
186
- docRef = _context.sent;
187
- console.log("Document written with ID: ", docRef.id);
188
- _context.next = 11;
189
- break;
190
- case 8:
191
- _context.prev = 8;
192
- _context.t0 = _context["catch"](0);
193
- console.error("Error adding document: ", _context.t0);
194
- case 11:
179
+ _context.next = 1;
180
+ return firestore.getDocs(firestore.collection(this.db, this.collectionName));
181
+ case 1:
182
+ querySnapshot = _context.sent;
183
+ return _context.abrupt("return", querySnapshot.docs.map(function (doc) {
184
+ return _objectSpread(_objectSpread({}, doc.data()), {}, {
185
+ id: doc.id
186
+ });
187
+ }));
188
+ case 2:
195
189
  case "end":
196
190
  return _context.stop();
197
191
  }
198
- }, _callee, this, [[0, 8]]);
192
+ }, _callee, this);
199
193
  }));
200
- function add(_x) {
201
- return _add.apply(this, arguments);
194
+ function getAll(_x, _x2) {
195
+ return _getAll.apply(this, arguments);
202
196
  }
203
- return add;
197
+ return getAll;
204
198
  }() // Update a document to a collection
205
199
  }, {
206
200
  key: "getById",
207
201
  value: function () {
208
- var _getById = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2(id) {
209
- var docRef;
210
- return _regeneratorRuntime__default["default"].wrap(function _callee2$(_context2) {
202
+ var _getById = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2(id, select) {
203
+ var docRef, _t;
204
+ return _regeneratorRuntime__default["default"].wrap(function (_context2) {
211
205
  while (1) switch (_context2.prev = _context2.next) {
212
206
  case 0:
213
207
  _context2.prev = 0;
214
- _context2.next = 3;
208
+ _context2.next = 1;
215
209
  return firestore.getDoc(firestore.doc(this.db, this.collectionName, id));
216
- case 3:
210
+ case 1:
217
211
  docRef = _context2.sent;
218
212
  if (!docRef.exists()) {
219
- _context2.next = 8;
213
+ _context2.next = 2;
220
214
  break;
221
215
  }
222
216
  return _context2.abrupt("return", _objectSpread(_objectSpread({}, docRef.data()), {}, {
223
217
  id: docRef.id
224
218
  }));
225
- case 8:
219
+ case 2:
226
220
  throw Error("entity with id: ".concat(id, ", does not exist"));
227
- case 9:
228
- _context2.next = 15;
221
+ case 3:
222
+ _context2.next = 5;
229
223
  break;
230
- case 11:
231
- _context2.prev = 11;
232
- _context2.t0 = _context2["catch"](0);
233
- console.error("Error getting document: ", _context2.t0);
234
- throw _context2.t0;
235
- 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:
236
230
  case "end":
237
231
  return _context2.stop();
238
232
  }
239
- }, _callee2, this, [[0, 11]]);
233
+ }, _callee2, this, [[0, 4]]);
240
234
  }));
241
- function getById(_x2) {
235
+ function getById(_x3, _x4) {
242
236
  return _getById.apply(this, arguments);
243
237
  }
244
238
  return getById;
245
- }() // Update a document to a collection
239
+ }() // Add a document to a collection
246
240
  }, {
247
- key: "update",
241
+ key: "batchInsert",
248
242
  value: function () {
249
- var _update = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee3(entity) {
250
- var docRef;
251
- return _regeneratorRuntime__default["default"].wrap(function _callee3$(_context3) {
243
+ var _batchInsert = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee3(entities, select, user) {
244
+ var _t2;
245
+ return _regeneratorRuntime__default["default"].wrap(function (_context3) {
252
246
  while (1) switch (_context3.prev = _context3.next) {
253
247
  case 0:
254
248
  _context3.prev = 0;
255
- if (!entity.id) {
256
- _context3.next = 4;
257
- break;
258
- }
259
- docRef = firestore.doc(this.db, this.collectionName, entity.id);
260
- return _context3.abrupt("return", firestore.updateDoc(docRef, entity));
261
- case 4:
262
- throw new Error('Entity does not have an id.');
263
- case 7:
264
- _context3.prev = 7;
265
- _context3.t0 = _context3["catch"](0);
266
- console.error("Error updating document: ", _context3.t0);
267
- case 10:
249
+ _context3.next = 1;
250
+ return firestore.addDoc(firestore.collection(this.db, this.collectionName), entities);
251
+ case 1:
252
+ _context3.sent;
253
+ return _context3.abrupt("return", entities);
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:
268
260
  case "end":
269
261
  return _context3.stop();
270
262
  }
271
- }, _callee3, this, [[0, 7]]);
263
+ }, _callee3, this, [[0, 2]]);
272
264
  }));
273
- function update(_x3) {
274
- return _update.apply(this, arguments);
265
+ function batchInsert(_x5, _x6, _x7) {
266
+ return _batchInsert.apply(this, arguments);
275
267
  }
276
- return update;
277
- }()
268
+ return batchInsert;
269
+ }() // Add a document to a collection
278
270
  }, {
279
- key: "delete",
271
+ key: "insert",
280
272
  value: function () {
281
- var _delete2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee4(entity) {
282
- return _regeneratorRuntime__default["default"].wrap(function _callee4$(_context4) {
273
+ var _insert = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee4(entity, select, user) {
274
+ var docRef, _t3;
275
+ return _regeneratorRuntime__default["default"].wrap(function (_context4) {
283
276
  while (1) switch (_context4.prev = _context4.next) {
284
277
  case 0:
285
- if (!entity.id) {
286
- _context4.next = 2;
287
- break;
288
- }
289
- return _context4.abrupt("return", firestore.deleteDoc(firestore.doc(this.db, this.collectionName, entity.id)));
278
+ _context4.prev = 0;
279
+ _context4.next = 1;
280
+ return firestore.addDoc(firestore.collection(this.db, this.collectionName), entity);
281
+ case 1:
282
+ docRef = _context4.sent;
283
+ return _context4.abrupt("return", _objectSpread(_objectSpread({}, docRef.toJSON()), {}, {
284
+ id: docRef.id
285
+ }));
290
286
  case 2:
291
- throw new Error('Entity does not have an id.');
287
+ _context4.prev = 2;
288
+ _t3 = _context4["catch"](0);
289
+ console.error("Error adding document: ", _t3);
290
+ throw _t3;
292
291
  case 3:
293
292
  case "end":
294
293
  return _context4.stop();
295
294
  }
296
- }, _callee4, this);
295
+ }, _callee4, this, [[0, 2]]);
297
296
  }));
298
- function _delete(_x4) {
299
- return _delete2.apply(this, arguments);
297
+ function insert(_x8, _x9, _x0) {
298
+ return _insert.apply(this, arguments);
300
299
  }
301
- return _delete;
302
- }() // Get all documents from a collection
300
+ return insert;
301
+ }() // Update a document to a collection
303
302
  }, {
304
- key: "getAll",
303
+ key: "update",
305
304
  value: function () {
306
- var _getAll = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee5() {
307
- var querySnapshot;
308
- return _regeneratorRuntime__default["default"].wrap(function _callee5$(_context5) {
305
+ var _update = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee5(entityId, updatedFields, select, user) {
306
+ var docRef, _t4;
307
+ return _regeneratorRuntime__default["default"].wrap(function (_context5) {
309
308
  while (1) switch (_context5.prev = _context5.next) {
310
309
  case 0:
311
- _context5.next = 2;
312
- return firestore.getDocs(firestore.collection(this.db, this.collectionName));
310
+ _context5.prev = 0;
311
+ docRef = firestore.doc(this.db, this.collectionName, entityId);
312
+ firestore.updateDoc(docRef, updatedFields);
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;
313
319
  case 2:
314
- querySnapshot = _context5.sent;
315
- return _context5.abrupt("return", querySnapshot.docs.map(function (doc) {
316
- return _objectSpread(_objectSpread({}, doc.data()), {}, {
317
- id: doc.id
318
- });
319
- }));
320
- case 4:
321
320
  case "end":
322
321
  return _context5.stop();
323
322
  }
324
- }, _callee5, this);
323
+ }, _callee5, this, [[0, 1]]);
325
324
  }));
326
- function getAll() {
327
- return _getAll.apply(this, arguments);
325
+ function update(_x1, _x10, _x11, _x12) {
326
+ return _update.apply(this, arguments);
328
327
  }
329
- return getAll;
328
+ return update;
329
+ }()
330
+ }, {
331
+ key: "delete",
332
+ value: function () {
333
+ var _delete2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee6(entityId) {
334
+ return _regeneratorRuntime__default["default"].wrap(function (_context6) {
335
+ while (1) switch (_context6.prev = _context6.next) {
336
+ case 0:
337
+ console.log('delete', entityId);
338
+ return _context6.abrupt("return", firestore.deleteDoc(firestore.doc(this.db, this.collectionName, entityId)));
339
+ case 1:
340
+ case "end":
341
+ return _context6.stop();
342
+ }
343
+ }, _callee6, this);
344
+ }));
345
+ function _delete(_x13) {
346
+ return _delete2.apply(this, arguments);
347
+ }
348
+ return _delete;
330
349
  }()
331
350
  }]);
332
351
  }();
@@ -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 { addDoc, collection, getDoc, doc, updateDoc, deleteDoc, getDocs, 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) {
@@ -103,16 +102,25 @@ var FirebaseAuthService = /*#__PURE__*/function () {
103
102
  });
104
103
  }
105
104
  return _createClass(FirebaseAuthService, [{
105
+ key: "getProviders",
106
+ value: function getProviders() {
107
+ return ["google"];
108
+ }
109
+ }, {
110
+ key: "signInWith",
111
+ value: function signInWith(provider) {
112
+ switch (provider) {
113
+ case 'google':
114
+ return this.signInWithGoogle();
115
+ default:
116
+ throw new Error('Unrecognized provider ' + provider);
117
+ }
118
+ }
119
+ }, {
106
120
  key: "hasUser",
107
121
  value: function hasUser() {
108
122
  return Promise.resolve(this.currentUser !== null);
109
123
  }
110
- }, {
111
- key: "signInWithAzure",
112
- value: function signInWithAzure() {
113
- // Placeholder implementation, as Azure sign-in is not implemented
114
- return Promise.reject(new Error('Method not implemented.'));
115
- }
116
124
  }]);
117
125
  }();
118
126
 
@@ -124,14 +132,14 @@ var FirebaseStorageService = /*#__PURE__*/_createClass(function FirebaseStorageS
124
132
  _defineProperty(this, "downloadFile", /*#__PURE__*/function () {
125
133
  var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(filepath) {
126
134
  var fileRef;
127
- return _regeneratorRuntime.wrap(function _callee$(_context) {
135
+ return _regeneratorRuntime.wrap(function (_context) {
128
136
  while (1) switch (_context.prev = _context.next) {
129
137
  case 0:
130
138
  fileRef = ref(_this.storage, filepath);
131
139
  return _context.abrupt("return", getBytes(fileRef).then(function (b) {
132
140
  return _this.decoder.decode(b);
133
141
  }));
134
- case 2:
142
+ case 1:
135
143
  case "end":
136
144
  return _context.stop();
137
145
  }
@@ -145,180 +153,191 @@ var FirebaseStorageService = /*#__PURE__*/_createClass(function FirebaseStorageS
145
153
 
146
154
  var FirestoreService = /*#__PURE__*/function () {
147
155
  function FirestoreService(collectionName) {
148
- var _this = this;
149
156
  _classCallCheck(this, FirestoreService);
150
157
  _defineProperty(this, "collectionName", "player");
151
158
  _defineProperty(this, "db", getFirestore(firebaseClient));
152
- _defineProperty(this, "addBatch", function (entities) {
153
- var batch = writeBatch(_this.db);
154
- entities.forEach(function (e) {
155
- e.id = v4();
156
- var docRef = doc(_this.db, _this.collectionName, e.id);
157
- batch.set(docRef, e);
158
- });
159
- return batch.commit();
160
- });
161
159
  this.collectionName = collectionName;
162
160
  }
163
161
 
164
- // Add a document to a collection
162
+ // Get all documents from a collection
165
163
  return _createClass(FirestoreService, [{
166
- key: "add",
164
+ key: "getAll",
167
165
  value: function () {
168
- var _add = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(entity) {
169
- var docRef;
170
- return _regeneratorRuntime.wrap(function _callee$(_context) {
166
+ var _getAll = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(count, select) {
167
+ var querySnapshot;
168
+ return _regeneratorRuntime.wrap(function (_context) {
171
169
  while (1) switch (_context.prev = _context.next) {
172
170
  case 0:
173
- _context.prev = 0;
174
- entity.id = v4();
175
- _context.next = 4;
176
- return addDoc(collection(this.db, this.collectionName), entity);
177
- case 4:
178
- docRef = _context.sent;
179
- console.log("Document written with ID: ", docRef.id);
180
- _context.next = 11;
181
- break;
182
- case 8:
183
- _context.prev = 8;
184
- _context.t0 = _context["catch"](0);
185
- console.error("Error adding document: ", _context.t0);
186
- case 11:
171
+ _context.next = 1;
172
+ return getDocs(collection(this.db, this.collectionName));
173
+ case 1:
174
+ querySnapshot = _context.sent;
175
+ return _context.abrupt("return", querySnapshot.docs.map(function (doc) {
176
+ return _objectSpread(_objectSpread({}, doc.data()), {}, {
177
+ id: doc.id
178
+ });
179
+ }));
180
+ case 2:
187
181
  case "end":
188
182
  return _context.stop();
189
183
  }
190
- }, _callee, this, [[0, 8]]);
184
+ }, _callee, this);
191
185
  }));
192
- function add(_x) {
193
- return _add.apply(this, arguments);
186
+ function getAll(_x, _x2) {
187
+ return _getAll.apply(this, arguments);
194
188
  }
195
- return add;
189
+ return getAll;
196
190
  }() // Update a document to a collection
197
191
  }, {
198
192
  key: "getById",
199
193
  value: function () {
200
- var _getById = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(id) {
201
- var docRef;
202
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
194
+ var _getById = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(id, select) {
195
+ var docRef, _t;
196
+ return _regeneratorRuntime.wrap(function (_context2) {
203
197
  while (1) switch (_context2.prev = _context2.next) {
204
198
  case 0:
205
199
  _context2.prev = 0;
206
- _context2.next = 3;
200
+ _context2.next = 1;
207
201
  return getDoc(doc(this.db, this.collectionName, id));
208
- case 3:
202
+ case 1:
209
203
  docRef = _context2.sent;
210
204
  if (!docRef.exists()) {
211
- _context2.next = 8;
205
+ _context2.next = 2;
212
206
  break;
213
207
  }
214
208
  return _context2.abrupt("return", _objectSpread(_objectSpread({}, docRef.data()), {}, {
215
209
  id: docRef.id
216
210
  }));
217
- case 8:
211
+ case 2:
218
212
  throw Error("entity with id: ".concat(id, ", does not exist"));
219
- case 9:
220
- _context2.next = 15;
213
+ case 3:
214
+ _context2.next = 5;
221
215
  break;
222
- case 11:
223
- _context2.prev = 11;
224
- _context2.t0 = _context2["catch"](0);
225
- console.error("Error getting document: ", _context2.t0);
226
- throw _context2.t0;
227
- 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:
228
222
  case "end":
229
223
  return _context2.stop();
230
224
  }
231
- }, _callee2, this, [[0, 11]]);
225
+ }, _callee2, this, [[0, 4]]);
232
226
  }));
233
- function getById(_x2) {
227
+ function getById(_x3, _x4) {
234
228
  return _getById.apply(this, arguments);
235
229
  }
236
230
  return getById;
237
- }() // Update a document to a collection
231
+ }() // Add a document to a collection
238
232
  }, {
239
- key: "update",
233
+ key: "batchInsert",
240
234
  value: function () {
241
- var _update = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(entity) {
242
- var docRef;
243
- return _regeneratorRuntime.wrap(function _callee3$(_context3) {
235
+ var _batchInsert = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(entities, select, user) {
236
+ var _t2;
237
+ return _regeneratorRuntime.wrap(function (_context3) {
244
238
  while (1) switch (_context3.prev = _context3.next) {
245
239
  case 0:
246
240
  _context3.prev = 0;
247
- if (!entity.id) {
248
- _context3.next = 4;
249
- break;
250
- }
251
- docRef = doc(this.db, this.collectionName, entity.id);
252
- return _context3.abrupt("return", updateDoc(docRef, entity));
253
- case 4:
254
- throw new Error('Entity does not have an id.');
255
- case 7:
256
- _context3.prev = 7;
257
- _context3.t0 = _context3["catch"](0);
258
- console.error("Error updating document: ", _context3.t0);
259
- case 10:
241
+ _context3.next = 1;
242
+ return addDoc(collection(this.db, this.collectionName), entities);
243
+ case 1:
244
+ _context3.sent;
245
+ return _context3.abrupt("return", entities);
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:
260
252
  case "end":
261
253
  return _context3.stop();
262
254
  }
263
- }, _callee3, this, [[0, 7]]);
255
+ }, _callee3, this, [[0, 2]]);
264
256
  }));
265
- function update(_x3) {
266
- return _update.apply(this, arguments);
257
+ function batchInsert(_x5, _x6, _x7) {
258
+ return _batchInsert.apply(this, arguments);
267
259
  }
268
- return update;
269
- }()
260
+ return batchInsert;
261
+ }() // Add a document to a collection
270
262
  }, {
271
- key: "delete",
263
+ key: "insert",
272
264
  value: function () {
273
- var _delete2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(entity) {
274
- return _regeneratorRuntime.wrap(function _callee4$(_context4) {
265
+ var _insert = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(entity, select, user) {
266
+ var docRef, _t3;
267
+ return _regeneratorRuntime.wrap(function (_context4) {
275
268
  while (1) switch (_context4.prev = _context4.next) {
276
269
  case 0:
277
- if (!entity.id) {
278
- _context4.next = 2;
279
- break;
280
- }
281
- return _context4.abrupt("return", deleteDoc(doc(this.db, this.collectionName, entity.id)));
270
+ _context4.prev = 0;
271
+ _context4.next = 1;
272
+ return addDoc(collection(this.db, this.collectionName), entity);
273
+ case 1:
274
+ docRef = _context4.sent;
275
+ return _context4.abrupt("return", _objectSpread(_objectSpread({}, docRef.toJSON()), {}, {
276
+ id: docRef.id
277
+ }));
282
278
  case 2:
283
- throw new Error('Entity does not have an id.');
279
+ _context4.prev = 2;
280
+ _t3 = _context4["catch"](0);
281
+ console.error("Error adding document: ", _t3);
282
+ throw _t3;
284
283
  case 3:
285
284
  case "end":
286
285
  return _context4.stop();
287
286
  }
288
- }, _callee4, this);
287
+ }, _callee4, this, [[0, 2]]);
289
288
  }));
290
- function _delete(_x4) {
291
- return _delete2.apply(this, arguments);
289
+ function insert(_x8, _x9, _x0) {
290
+ return _insert.apply(this, arguments);
292
291
  }
293
- return _delete;
294
- }() // Get all documents from a collection
292
+ return insert;
293
+ }() // Update a document to a collection
295
294
  }, {
296
- key: "getAll",
295
+ key: "update",
297
296
  value: function () {
298
- var _getAll = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
299
- var querySnapshot;
300
- return _regeneratorRuntime.wrap(function _callee5$(_context5) {
297
+ var _update = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(entityId, updatedFields, select, user) {
298
+ var docRef, _t4;
299
+ return _regeneratorRuntime.wrap(function (_context5) {
301
300
  while (1) switch (_context5.prev = _context5.next) {
302
301
  case 0:
303
- _context5.next = 2;
304
- return getDocs(collection(this.db, this.collectionName));
302
+ _context5.prev = 0;
303
+ docRef = doc(this.db, this.collectionName, entityId);
304
+ updateDoc(docRef, updatedFields);
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;
305
311
  case 2:
306
- querySnapshot = _context5.sent;
307
- return _context5.abrupt("return", querySnapshot.docs.map(function (doc) {
308
- return _objectSpread(_objectSpread({}, doc.data()), {}, {
309
- id: doc.id
310
- });
311
- }));
312
- case 4:
313
312
  case "end":
314
313
  return _context5.stop();
315
314
  }
316
- }, _callee5, this);
315
+ }, _callee5, this, [[0, 1]]);
317
316
  }));
318
- function getAll() {
319
- return _getAll.apply(this, arguments);
317
+ function update(_x1, _x10, _x11, _x12) {
318
+ return _update.apply(this, arguments);
320
319
  }
321
- return getAll;
320
+ return update;
321
+ }()
322
+ }, {
323
+ key: "delete",
324
+ value: function () {
325
+ var _delete2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6(entityId) {
326
+ return _regeneratorRuntime.wrap(function (_context6) {
327
+ while (1) switch (_context6.prev = _context6.next) {
328
+ case 0:
329
+ console.log('delete', entityId);
330
+ return _context6.abrupt("return", deleteDoc(doc(this.db, this.collectionName, entityId)));
331
+ case 1:
332
+ case "end":
333
+ return _context6.stop();
334
+ }
335
+ }, _callee6, this);
336
+ }));
337
+ function _delete(_x13) {
338
+ return _delete2.apply(this, arguments);
339
+ }
340
+ return _delete;
322
341
  }()
323
342
  }]);
324
343
  }();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitalaidseattle/firebase",
3
- "version": "1.0.2",
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",
@@ -8,7 +8,7 @@
8
8
  "types": "dist/declarations/src/index.d.ts",
9
9
  "dependencies": {
10
10
  "@babel/runtime": "^7.25.0",
11
- "@digitalaidseattle/core": "1.0.5",
11
+ "@digitalaidseattle/core": "1.0.8",
12
12
  "firebase": "^11.2.0",
13
13
  "react": "^18.3.1",
14
14
  "uuid": "^11.0.5"