@digitalaidseattle/firebase 1.0.2 → 1.0.3

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,15 +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[]>;
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>;
13
12
  addBatch: (entities: T[]) => Promise<void>;
14
13
  }
15
14
  export { FirestoreService };
@@ -111,16 +111,25 @@ var FirebaseAuthService = /*#__PURE__*/function () {
111
111
  });
112
112
  }
113
113
  return _createClass(FirebaseAuthService, [{
114
+ key: "getProviders",
115
+ value: function getProviders() {
116
+ return ["google"];
117
+ }
118
+ }, {
119
+ key: "signInWith",
120
+ value: function signInWith(provider) {
121
+ switch (provider) {
122
+ case 'google':
123
+ return this.signInWithGoogle();
124
+ default:
125
+ throw new Error('Unrecognized provider ' + provider);
126
+ }
127
+ }
128
+ }, {
114
129
  key: "hasUser",
115
130
  value: function hasUser() {
116
131
  return Promise.resolve(this.currentUser !== null);
117
132
  }
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
133
  }]);
125
134
  }();
126
135
 
@@ -169,43 +178,39 @@ var FirestoreService = /*#__PURE__*/function () {
169
178
  this.collectionName = collectionName;
170
179
  }
171
180
 
172
- // Add a document to a collection
181
+ // Get all documents from a collection
173
182
  return _createClass(FirestoreService, [{
174
- key: "add",
183
+ key: "getAll",
175
184
  value: function () {
176
- var _add = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(entity) {
177
- var docRef;
185
+ var _getAll = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(count, select) {
186
+ var querySnapshot;
178
187
  return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
179
188
  while (1) switch (_context.prev = _context.next) {
180
189
  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);
190
+ _context.next = 2;
191
+ return firestore.getDocs(firestore.collection(this.db, this.collectionName));
192
+ case 2:
193
+ querySnapshot = _context.sent;
194
+ return _context.abrupt("return", querySnapshot.docs.map(function (doc) {
195
+ return _objectSpread(_objectSpread({}, doc.data()), {}, {
196
+ id: doc.id
197
+ });
198
+ }));
185
199
  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:
195
200
  case "end":
196
201
  return _context.stop();
197
202
  }
198
- }, _callee, this, [[0, 8]]);
203
+ }, _callee, this);
199
204
  }));
200
- function add(_x) {
201
- return _add.apply(this, arguments);
205
+ function getAll(_x, _x2) {
206
+ return _getAll.apply(this, arguments);
202
207
  }
203
- return add;
208
+ return getAll;
204
209
  }() // Update a document to a collection
205
210
  }, {
206
211
  key: "getById",
207
212
  value: function () {
208
- var _getById = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2(id) {
213
+ var _getById = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2(id, select) {
209
214
  var docRef;
210
215
  return _regeneratorRuntime__default["default"].wrap(function _callee2$(_context2) {
211
216
  while (1) switch (_context2.prev = _context2.next) {
@@ -238,95 +243,120 @@ var FirestoreService = /*#__PURE__*/function () {
238
243
  }
239
244
  }, _callee2, this, [[0, 11]]);
240
245
  }));
241
- function getById(_x2) {
246
+ function getById(_x3, _x4) {
242
247
  return _getById.apply(this, arguments);
243
248
  }
244
249
  return getById;
245
- }() // Update a document to a collection
250
+ }() // Add a document to a collection
246
251
  }, {
247
- key: "update",
252
+ key: "batchInsert",
248
253
  value: function () {
249
- var _update = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee3(entity) {
250
- var docRef;
254
+ var _batchInsert = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee3(entities, select, user) {
251
255
  return _regeneratorRuntime__default["default"].wrap(function _callee3$(_context3) {
252
256
  while (1) switch (_context3.prev = _context3.next) {
253
257
  case 0:
254
258
  _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));
259
+ entities.forEach(function (entity) {
260
+ return entity.id = uuid.v4();
261
+ });
262
+ _context3.next = 4;
263
+ return firestore.addDoc(firestore.collection(this.db, this.collectionName), entities);
261
264
  case 4:
262
- throw new Error('Entity does not have an id.');
263
- case 7:
264
- _context3.prev = 7;
265
+ _context3.sent;
266
+ return _context3.abrupt("return", entities);
267
+ case 8:
268
+ _context3.prev = 8;
265
269
  _context3.t0 = _context3["catch"](0);
266
- console.error("Error updating document: ", _context3.t0);
267
- case 10:
270
+ console.error("Error adding document: ", _context3.t0);
271
+ throw _context3.t0;
272
+ case 12:
268
273
  case "end":
269
274
  return _context3.stop();
270
275
  }
271
- }, _callee3, this, [[0, 7]]);
276
+ }, _callee3, this, [[0, 8]]);
272
277
  }));
273
- function update(_x3) {
274
- return _update.apply(this, arguments);
278
+ function batchInsert(_x5, _x6, _x7) {
279
+ return _batchInsert.apply(this, arguments);
275
280
  }
276
- return update;
277
- }()
281
+ return batchInsert;
282
+ }() // Add a document to a collection
278
283
  }, {
279
- key: "delete",
284
+ key: "insert",
280
285
  value: function () {
281
- var _delete2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee4(entity) {
286
+ var _insert = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee4(entity, select, user) {
282
287
  return _regeneratorRuntime__default["default"].wrap(function _callee4$(_context4) {
283
288
  while (1) switch (_context4.prev = _context4.next) {
284
289
  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)));
290
- case 2:
291
- throw new Error('Entity does not have an id.');
292
- case 3:
290
+ _context4.prev = 0;
291
+ entity.id = uuid.v4();
292
+ _context4.next = 4;
293
+ 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:
293
303
  case "end":
294
304
  return _context4.stop();
295
305
  }
296
- }, _callee4, this);
306
+ }, _callee4, this, [[0, 8]]);
297
307
  }));
298
- function _delete(_x4) {
299
- return _delete2.apply(this, arguments);
308
+ function insert(_x8, _x9, _x10) {
309
+ return _insert.apply(this, arguments);
300
310
  }
301
- return _delete;
302
- }() // Get all documents from a collection
311
+ return insert;
312
+ }() // Update a document to a collection
303
313
  }, {
304
- key: "getAll",
314
+ key: "update",
305
315
  value: function () {
306
- var _getAll = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee5() {
307
- var querySnapshot;
316
+ var _update = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee5(entityId, updatedFields, select, user) {
317
+ var docRef;
308
318
  return _regeneratorRuntime__default["default"].wrap(function _callee5$(_context5) {
309
319
  while (1) switch (_context5.prev = _context5.next) {
310
320
  case 0:
311
- _context5.next = 2;
312
- return firestore.getDocs(firestore.collection(this.db, this.collectionName));
313
- 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
+ _context5.prev = 0;
322
+ docRef = firestore.doc(this.db, this.collectionName, entityId);
323
+ 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:
321
331
  case "end":
322
332
  return _context5.stop();
323
333
  }
324
- }, _callee5, this);
334
+ }, _callee5, this, [[0, 6]]);
325
335
  }));
326
- function getAll() {
327
- return _getAll.apply(this, arguments);
336
+ function update(_x11, _x12, _x13, _x14) {
337
+ return _update.apply(this, arguments);
328
338
  }
329
- return getAll;
339
+ return update;
340
+ }()
341
+ }, {
342
+ key: "delete",
343
+ value: function () {
344
+ var _delete2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee6(entityId) {
345
+ return _regeneratorRuntime__default["default"].wrap(function _callee6$(_context6) {
346
+ while (1) switch (_context6.prev = _context6.next) {
347
+ case 0:
348
+ console.log('delete', entityId);
349
+ return _context6.abrupt("return", firestore.deleteDoc(firestore.doc(this.db, this.collectionName, entityId)));
350
+ case 2:
351
+ case "end":
352
+ return _context6.stop();
353
+ }
354
+ }, _callee6, this);
355
+ }));
356
+ function _delete(_x15) {
357
+ return _delete2.apply(this, arguments);
358
+ }
359
+ return _delete;
330
360
  }()
331
361
  }]);
332
362
  }();
@@ -111,16 +111,25 @@ var FirebaseAuthService = /*#__PURE__*/function () {
111
111
  });
112
112
  }
113
113
  return _createClass(FirebaseAuthService, [{
114
+ key: "getProviders",
115
+ value: function getProviders() {
116
+ return ["google"];
117
+ }
118
+ }, {
119
+ key: "signInWith",
120
+ value: function signInWith(provider) {
121
+ switch (provider) {
122
+ case 'google':
123
+ return this.signInWithGoogle();
124
+ default:
125
+ throw new Error('Unrecognized provider ' + provider);
126
+ }
127
+ }
128
+ }, {
114
129
  key: "hasUser",
115
130
  value: function hasUser() {
116
131
  return Promise.resolve(this.currentUser !== null);
117
132
  }
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
133
  }]);
125
134
  }();
126
135
 
@@ -169,43 +178,39 @@ var FirestoreService = /*#__PURE__*/function () {
169
178
  this.collectionName = collectionName;
170
179
  }
171
180
 
172
- // Add a document to a collection
181
+ // Get all documents from a collection
173
182
  return _createClass(FirestoreService, [{
174
- key: "add",
183
+ key: "getAll",
175
184
  value: function () {
176
- var _add = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(entity) {
177
- var docRef;
185
+ var _getAll = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(count, select) {
186
+ var querySnapshot;
178
187
  return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
179
188
  while (1) switch (_context.prev = _context.next) {
180
189
  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);
190
+ _context.next = 2;
191
+ return firestore.getDocs(firestore.collection(this.db, this.collectionName));
192
+ case 2:
193
+ querySnapshot = _context.sent;
194
+ return _context.abrupt("return", querySnapshot.docs.map(function (doc) {
195
+ return _objectSpread(_objectSpread({}, doc.data()), {}, {
196
+ id: doc.id
197
+ });
198
+ }));
185
199
  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:
195
200
  case "end":
196
201
  return _context.stop();
197
202
  }
198
- }, _callee, this, [[0, 8]]);
203
+ }, _callee, this);
199
204
  }));
200
- function add(_x) {
201
- return _add.apply(this, arguments);
205
+ function getAll(_x, _x2) {
206
+ return _getAll.apply(this, arguments);
202
207
  }
203
- return add;
208
+ return getAll;
204
209
  }() // Update a document to a collection
205
210
  }, {
206
211
  key: "getById",
207
212
  value: function () {
208
- var _getById = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2(id) {
213
+ var _getById = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2(id, select) {
209
214
  var docRef;
210
215
  return _regeneratorRuntime__default["default"].wrap(function _callee2$(_context2) {
211
216
  while (1) switch (_context2.prev = _context2.next) {
@@ -238,95 +243,120 @@ var FirestoreService = /*#__PURE__*/function () {
238
243
  }
239
244
  }, _callee2, this, [[0, 11]]);
240
245
  }));
241
- function getById(_x2) {
246
+ function getById(_x3, _x4) {
242
247
  return _getById.apply(this, arguments);
243
248
  }
244
249
  return getById;
245
- }() // Update a document to a collection
250
+ }() // Add a document to a collection
246
251
  }, {
247
- key: "update",
252
+ key: "batchInsert",
248
253
  value: function () {
249
- var _update = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee3(entity) {
250
- var docRef;
254
+ var _batchInsert = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee3(entities, select, user) {
251
255
  return _regeneratorRuntime__default["default"].wrap(function _callee3$(_context3) {
252
256
  while (1) switch (_context3.prev = _context3.next) {
253
257
  case 0:
254
258
  _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));
259
+ entities.forEach(function (entity) {
260
+ return entity.id = uuid.v4();
261
+ });
262
+ _context3.next = 4;
263
+ return firestore.addDoc(firestore.collection(this.db, this.collectionName), entities);
261
264
  case 4:
262
- throw new Error('Entity does not have an id.');
263
- case 7:
264
- _context3.prev = 7;
265
+ _context3.sent;
266
+ return _context3.abrupt("return", entities);
267
+ case 8:
268
+ _context3.prev = 8;
265
269
  _context3.t0 = _context3["catch"](0);
266
- console.error("Error updating document: ", _context3.t0);
267
- case 10:
270
+ console.error("Error adding document: ", _context3.t0);
271
+ throw _context3.t0;
272
+ case 12:
268
273
  case "end":
269
274
  return _context3.stop();
270
275
  }
271
- }, _callee3, this, [[0, 7]]);
276
+ }, _callee3, this, [[0, 8]]);
272
277
  }));
273
- function update(_x3) {
274
- return _update.apply(this, arguments);
278
+ function batchInsert(_x5, _x6, _x7) {
279
+ return _batchInsert.apply(this, arguments);
275
280
  }
276
- return update;
277
- }()
281
+ return batchInsert;
282
+ }() // Add a document to a collection
278
283
  }, {
279
- key: "delete",
284
+ key: "insert",
280
285
  value: function () {
281
- var _delete2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee4(entity) {
286
+ var _insert = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee4(entity, select, user) {
282
287
  return _regeneratorRuntime__default["default"].wrap(function _callee4$(_context4) {
283
288
  while (1) switch (_context4.prev = _context4.next) {
284
289
  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)));
290
- case 2:
291
- throw new Error('Entity does not have an id.');
292
- case 3:
290
+ _context4.prev = 0;
291
+ entity.id = uuid.v4();
292
+ _context4.next = 4;
293
+ 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:
293
303
  case "end":
294
304
  return _context4.stop();
295
305
  }
296
- }, _callee4, this);
306
+ }, _callee4, this, [[0, 8]]);
297
307
  }));
298
- function _delete(_x4) {
299
- return _delete2.apply(this, arguments);
308
+ function insert(_x8, _x9, _x10) {
309
+ return _insert.apply(this, arguments);
300
310
  }
301
- return _delete;
302
- }() // Get all documents from a collection
311
+ return insert;
312
+ }() // Update a document to a collection
303
313
  }, {
304
- key: "getAll",
314
+ key: "update",
305
315
  value: function () {
306
- var _getAll = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee5() {
307
- var querySnapshot;
316
+ var _update = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee5(entityId, updatedFields, select, user) {
317
+ var docRef;
308
318
  return _regeneratorRuntime__default["default"].wrap(function _callee5$(_context5) {
309
319
  while (1) switch (_context5.prev = _context5.next) {
310
320
  case 0:
311
- _context5.next = 2;
312
- return firestore.getDocs(firestore.collection(this.db, this.collectionName));
313
- 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
+ _context5.prev = 0;
322
+ docRef = firestore.doc(this.db, this.collectionName, entityId);
323
+ 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:
321
331
  case "end":
322
332
  return _context5.stop();
323
333
  }
324
- }, _callee5, this);
334
+ }, _callee5, this, [[0, 6]]);
325
335
  }));
326
- function getAll() {
327
- return _getAll.apply(this, arguments);
336
+ function update(_x11, _x12, _x13, _x14) {
337
+ return _update.apply(this, arguments);
328
338
  }
329
- return getAll;
339
+ return update;
340
+ }()
341
+ }, {
342
+ key: "delete",
343
+ value: function () {
344
+ var _delete2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee6(entityId) {
345
+ return _regeneratorRuntime__default["default"].wrap(function _callee6$(_context6) {
346
+ while (1) switch (_context6.prev = _context6.next) {
347
+ case 0:
348
+ console.log('delete', entityId);
349
+ return _context6.abrupt("return", firestore.deleteDoc(firestore.doc(this.db, this.collectionName, entityId)));
350
+ case 2:
351
+ case "end":
352
+ return _context6.stop();
353
+ }
354
+ }, _callee6, this);
355
+ }));
356
+ function _delete(_x15) {
357
+ return _delete2.apply(this, arguments);
358
+ }
359
+ return _delete;
330
360
  }()
331
361
  }]);
332
362
  }();
@@ -7,7 +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';
10
+ import { getDocs, collection, getDoc, doc, addDoc, updateDoc, deleteDoc, getFirestore, writeBatch } from 'firebase/firestore';
11
11
  import { v4 } from 'uuid';
12
12
 
13
13
  var firebaseConfig = {
@@ -103,16 +103,25 @@ var FirebaseAuthService = /*#__PURE__*/function () {
103
103
  });
104
104
  }
105
105
  return _createClass(FirebaseAuthService, [{
106
+ key: "getProviders",
107
+ value: function getProviders() {
108
+ return ["google"];
109
+ }
110
+ }, {
111
+ key: "signInWith",
112
+ value: function signInWith(provider) {
113
+ switch (provider) {
114
+ case 'google':
115
+ return this.signInWithGoogle();
116
+ default:
117
+ throw new Error('Unrecognized provider ' + provider);
118
+ }
119
+ }
120
+ }, {
106
121
  key: "hasUser",
107
122
  value: function hasUser() {
108
123
  return Promise.resolve(this.currentUser !== null);
109
124
  }
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
125
  }]);
117
126
  }();
118
127
 
@@ -161,43 +170,39 @@ var FirestoreService = /*#__PURE__*/function () {
161
170
  this.collectionName = collectionName;
162
171
  }
163
172
 
164
- // Add a document to a collection
173
+ // Get all documents from a collection
165
174
  return _createClass(FirestoreService, [{
166
- key: "add",
175
+ key: "getAll",
167
176
  value: function () {
168
- var _add = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(entity) {
169
- var docRef;
177
+ var _getAll = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(count, select) {
178
+ var querySnapshot;
170
179
  return _regeneratorRuntime.wrap(function _callee$(_context) {
171
180
  while (1) switch (_context.prev = _context.next) {
172
181
  case 0:
173
- _context.prev = 0;
174
- entity.id = v4();
175
- _context.next = 4;
176
- return addDoc(collection(this.db, this.collectionName), entity);
182
+ _context.next = 2;
183
+ return getDocs(collection(this.db, this.collectionName));
184
+ case 2:
185
+ querySnapshot = _context.sent;
186
+ return _context.abrupt("return", querySnapshot.docs.map(function (doc) {
187
+ return _objectSpread(_objectSpread({}, doc.data()), {}, {
188
+ id: doc.id
189
+ });
190
+ }));
177
191
  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:
187
192
  case "end":
188
193
  return _context.stop();
189
194
  }
190
- }, _callee, this, [[0, 8]]);
195
+ }, _callee, this);
191
196
  }));
192
- function add(_x) {
193
- return _add.apply(this, arguments);
197
+ function getAll(_x, _x2) {
198
+ return _getAll.apply(this, arguments);
194
199
  }
195
- return add;
200
+ return getAll;
196
201
  }() // Update a document to a collection
197
202
  }, {
198
203
  key: "getById",
199
204
  value: function () {
200
- var _getById = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(id) {
205
+ var _getById = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(id, select) {
201
206
  var docRef;
202
207
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
203
208
  while (1) switch (_context2.prev = _context2.next) {
@@ -230,95 +235,120 @@ var FirestoreService = /*#__PURE__*/function () {
230
235
  }
231
236
  }, _callee2, this, [[0, 11]]);
232
237
  }));
233
- function getById(_x2) {
238
+ function getById(_x3, _x4) {
234
239
  return _getById.apply(this, arguments);
235
240
  }
236
241
  return getById;
237
- }() // Update a document to a collection
242
+ }() // Add a document to a collection
238
243
  }, {
239
- key: "update",
244
+ key: "batchInsert",
240
245
  value: function () {
241
- var _update = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(entity) {
242
- var docRef;
246
+ var _batchInsert = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(entities, select, user) {
243
247
  return _regeneratorRuntime.wrap(function _callee3$(_context3) {
244
248
  while (1) switch (_context3.prev = _context3.next) {
245
249
  case 0:
246
250
  _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));
251
+ entities.forEach(function (entity) {
252
+ return entity.id = v4();
253
+ });
254
+ _context3.next = 4;
255
+ return addDoc(collection(this.db, this.collectionName), entities);
253
256
  case 4:
254
- throw new Error('Entity does not have an id.');
255
- case 7:
256
- _context3.prev = 7;
257
+ _context3.sent;
258
+ return _context3.abrupt("return", entities);
259
+ case 8:
260
+ _context3.prev = 8;
257
261
  _context3.t0 = _context3["catch"](0);
258
- console.error("Error updating document: ", _context3.t0);
259
- case 10:
262
+ console.error("Error adding document: ", _context3.t0);
263
+ throw _context3.t0;
264
+ case 12:
260
265
  case "end":
261
266
  return _context3.stop();
262
267
  }
263
- }, _callee3, this, [[0, 7]]);
268
+ }, _callee3, this, [[0, 8]]);
264
269
  }));
265
- function update(_x3) {
266
- return _update.apply(this, arguments);
270
+ function batchInsert(_x5, _x6, _x7) {
271
+ return _batchInsert.apply(this, arguments);
267
272
  }
268
- return update;
269
- }()
273
+ return batchInsert;
274
+ }() // Add a document to a collection
270
275
  }, {
271
- key: "delete",
276
+ key: "insert",
272
277
  value: function () {
273
- var _delete2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(entity) {
278
+ var _insert = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(entity, select, user) {
274
279
  return _regeneratorRuntime.wrap(function _callee4$(_context4) {
275
280
  while (1) switch (_context4.prev = _context4.next) {
276
281
  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)));
282
- case 2:
283
- throw new Error('Entity does not have an id.');
284
- case 3:
282
+ _context4.prev = 0;
283
+ entity.id = v4();
284
+ _context4.next = 4;
285
+ 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:
285
295
  case "end":
286
296
  return _context4.stop();
287
297
  }
288
- }, _callee4, this);
298
+ }, _callee4, this, [[0, 8]]);
289
299
  }));
290
- function _delete(_x4) {
291
- return _delete2.apply(this, arguments);
300
+ function insert(_x8, _x9, _x10) {
301
+ return _insert.apply(this, arguments);
292
302
  }
293
- return _delete;
294
- }() // Get all documents from a collection
303
+ return insert;
304
+ }() // Update a document to a collection
295
305
  }, {
296
- key: "getAll",
306
+ key: "update",
297
307
  value: function () {
298
- var _getAll = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
299
- var querySnapshot;
308
+ var _update = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(entityId, updatedFields, select, user) {
309
+ var docRef;
300
310
  return _regeneratorRuntime.wrap(function _callee5$(_context5) {
301
311
  while (1) switch (_context5.prev = _context5.next) {
302
312
  case 0:
303
- _context5.next = 2;
304
- return getDocs(collection(this.db, this.collectionName));
305
- 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
+ _context5.prev = 0;
314
+ docRef = doc(this.db, this.collectionName, entityId);
315
+ 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:
313
323
  case "end":
314
324
  return _context5.stop();
315
325
  }
316
- }, _callee5, this);
326
+ }, _callee5, this, [[0, 6]]);
317
327
  }));
318
- function getAll() {
319
- return _getAll.apply(this, arguments);
328
+ function update(_x11, _x12, _x13, _x14) {
329
+ return _update.apply(this, arguments);
320
330
  }
321
- return getAll;
331
+ return update;
332
+ }()
333
+ }, {
334
+ key: "delete",
335
+ value: function () {
336
+ var _delete2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6(entityId) {
337
+ return _regeneratorRuntime.wrap(function _callee6$(_context6) {
338
+ while (1) switch (_context6.prev = _context6.next) {
339
+ case 0:
340
+ console.log('delete', entityId);
341
+ return _context6.abrupt("return", deleteDoc(doc(this.db, this.collectionName, entityId)));
342
+ case 2:
343
+ case "end":
344
+ return _context6.stop();
345
+ }
346
+ }, _callee6, this);
347
+ }));
348
+ function _delete(_x15) {
349
+ return _delete2.apply(this, arguments);
350
+ }
351
+ return _delete;
322
352
  }()
323
353
  }]);
324
354
  }();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitalaidseattle/firebase",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
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"