@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.
- package/dist/declarations/src/FirebaseAuthService.d.ts +2 -1
- package/dist/declarations/src/FirestoreService.d.ts +8 -9
- package/dist/digitalaidseattle-firebase.cjs.dev.js +111 -81
- package/dist/digitalaidseattle-firebase.cjs.prod.js +111 -81
- package/dist/digitalaidseattle-firebase.esm.js +112 -82
- package/package.json +2 -2
@@ -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
|
-
|
2
|
-
|
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
|
-
|
9
|
-
getById(id: string): Promise<T>;
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
//
|
181
|
+
// Get all documents from a collection
|
173
182
|
return _createClass(FirestoreService, [{
|
174
|
-
key: "
|
183
|
+
key: "getAll",
|
175
184
|
value: function () {
|
176
|
-
var
|
177
|
-
var
|
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.
|
182
|
-
|
183
|
-
|
184
|
-
|
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
|
203
|
+
}, _callee, this);
|
199
204
|
}));
|
200
|
-
function
|
201
|
-
return
|
205
|
+
function getAll(_x, _x2) {
|
206
|
+
return _getAll.apply(this, arguments);
|
202
207
|
}
|
203
|
-
return
|
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(
|
246
|
+
function getById(_x3, _x4) {
|
242
247
|
return _getById.apply(this, arguments);
|
243
248
|
}
|
244
249
|
return getById;
|
245
|
-
}() //
|
250
|
+
}() // Add a document to a collection
|
246
251
|
}, {
|
247
|
-
key: "
|
252
|
+
key: "batchInsert",
|
248
253
|
value: function () {
|
249
|
-
var
|
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
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
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
|
-
|
263
|
-
|
264
|
-
|
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
|
267
|
-
|
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,
|
276
|
+
}, _callee3, this, [[0, 8]]);
|
272
277
|
}));
|
273
|
-
function
|
274
|
-
return
|
278
|
+
function batchInsert(_x5, _x6, _x7) {
|
279
|
+
return _batchInsert.apply(this, arguments);
|
275
280
|
}
|
276
|
-
return
|
277
|
-
}()
|
281
|
+
return batchInsert;
|
282
|
+
}() // Add a document to a collection
|
278
283
|
}, {
|
279
|
-
key: "
|
284
|
+
key: "insert",
|
280
285
|
value: function () {
|
281
|
-
var
|
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
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
case
|
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
|
299
|
-
return
|
308
|
+
function insert(_x8, _x9, _x10) {
|
309
|
+
return _insert.apply(this, arguments);
|
300
310
|
}
|
301
|
-
return
|
302
|
-
}() //
|
311
|
+
return insert;
|
312
|
+
}() // Update a document to a collection
|
303
313
|
}, {
|
304
|
-
key: "
|
314
|
+
key: "update",
|
305
315
|
value: function () {
|
306
|
-
var
|
307
|
-
var
|
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.
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
case
|
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
|
327
|
-
return
|
336
|
+
function update(_x11, _x12, _x13, _x14) {
|
337
|
+
return _update.apply(this, arguments);
|
328
338
|
}
|
329
|
-
return
|
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
|
-
//
|
181
|
+
// Get all documents from a collection
|
173
182
|
return _createClass(FirestoreService, [{
|
174
|
-
key: "
|
183
|
+
key: "getAll",
|
175
184
|
value: function () {
|
176
|
-
var
|
177
|
-
var
|
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.
|
182
|
-
|
183
|
-
|
184
|
-
|
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
|
203
|
+
}, _callee, this);
|
199
204
|
}));
|
200
|
-
function
|
201
|
-
return
|
205
|
+
function getAll(_x, _x2) {
|
206
|
+
return _getAll.apply(this, arguments);
|
202
207
|
}
|
203
|
-
return
|
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(
|
246
|
+
function getById(_x3, _x4) {
|
242
247
|
return _getById.apply(this, arguments);
|
243
248
|
}
|
244
249
|
return getById;
|
245
|
-
}() //
|
250
|
+
}() // Add a document to a collection
|
246
251
|
}, {
|
247
|
-
key: "
|
252
|
+
key: "batchInsert",
|
248
253
|
value: function () {
|
249
|
-
var
|
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
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
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
|
-
|
263
|
-
|
264
|
-
|
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
|
267
|
-
|
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,
|
276
|
+
}, _callee3, this, [[0, 8]]);
|
272
277
|
}));
|
273
|
-
function
|
274
|
-
return
|
278
|
+
function batchInsert(_x5, _x6, _x7) {
|
279
|
+
return _batchInsert.apply(this, arguments);
|
275
280
|
}
|
276
|
-
return
|
277
|
-
}()
|
281
|
+
return batchInsert;
|
282
|
+
}() // Add a document to a collection
|
278
283
|
}, {
|
279
|
-
key: "
|
284
|
+
key: "insert",
|
280
285
|
value: function () {
|
281
|
-
var
|
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
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
case
|
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
|
299
|
-
return
|
308
|
+
function insert(_x8, _x9, _x10) {
|
309
|
+
return _insert.apply(this, arguments);
|
300
310
|
}
|
301
|
-
return
|
302
|
-
}() //
|
311
|
+
return insert;
|
312
|
+
}() // Update a document to a collection
|
303
313
|
}, {
|
304
|
-
key: "
|
314
|
+
key: "update",
|
305
315
|
value: function () {
|
306
|
-
var
|
307
|
-
var
|
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.
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
case
|
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
|
327
|
-
return
|
336
|
+
function update(_x11, _x12, _x13, _x14) {
|
337
|
+
return _update.apply(this, arguments);
|
328
338
|
}
|
329
|
-
return
|
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 {
|
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
|
-
//
|
173
|
+
// Get all documents from a collection
|
165
174
|
return _createClass(FirestoreService, [{
|
166
|
-
key: "
|
175
|
+
key: "getAll",
|
167
176
|
value: function () {
|
168
|
-
var
|
169
|
-
var
|
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.
|
174
|
-
|
175
|
-
|
176
|
-
|
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
|
195
|
+
}, _callee, this);
|
191
196
|
}));
|
192
|
-
function
|
193
|
-
return
|
197
|
+
function getAll(_x, _x2) {
|
198
|
+
return _getAll.apply(this, arguments);
|
194
199
|
}
|
195
|
-
return
|
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(
|
238
|
+
function getById(_x3, _x4) {
|
234
239
|
return _getById.apply(this, arguments);
|
235
240
|
}
|
236
241
|
return getById;
|
237
|
-
}() //
|
242
|
+
}() // Add a document to a collection
|
238
243
|
}, {
|
239
|
-
key: "
|
244
|
+
key: "batchInsert",
|
240
245
|
value: function () {
|
241
|
-
var
|
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
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
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
|
-
|
255
|
-
|
256
|
-
|
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
|
259
|
-
|
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,
|
268
|
+
}, _callee3, this, [[0, 8]]);
|
264
269
|
}));
|
265
|
-
function
|
266
|
-
return
|
270
|
+
function batchInsert(_x5, _x6, _x7) {
|
271
|
+
return _batchInsert.apply(this, arguments);
|
267
272
|
}
|
268
|
-
return
|
269
|
-
}()
|
273
|
+
return batchInsert;
|
274
|
+
}() // Add a document to a collection
|
270
275
|
}, {
|
271
|
-
key: "
|
276
|
+
key: "insert",
|
272
277
|
value: function () {
|
273
|
-
var
|
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
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
case
|
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
|
291
|
-
return
|
300
|
+
function insert(_x8, _x9, _x10) {
|
301
|
+
return _insert.apply(this, arguments);
|
292
302
|
}
|
293
|
-
return
|
294
|
-
}() //
|
303
|
+
return insert;
|
304
|
+
}() // Update a document to a collection
|
295
305
|
}, {
|
296
|
-
key: "
|
306
|
+
key: "update",
|
297
307
|
value: function () {
|
298
|
-
var
|
299
|
-
var
|
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.
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
case
|
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
|
319
|
-
return
|
328
|
+
function update(_x11, _x12, _x13, _x14) {
|
329
|
+
return _update.apply(this, arguments);
|
320
330
|
}
|
321
|
-
return
|
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.
|
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.
|
11
|
+
"@digitalaidseattle/core": "1.0.8",
|
12
12
|
"firebase": "^11.2.0",
|
13
13
|
"react": "^18.3.1",
|
14
14
|
"uuid": "^11.0.5"
|