@digitalaidseattle/firebase 1.0.1 → 1.0.2
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.
@@ -5,11 +5,11 @@ declare class FirestoreService<T extends Entity> {
|
|
5
5
|
collectionName: string;
|
6
6
|
db: import("@firebase/firestore").Firestore;
|
7
7
|
constructor(collectionName: string);
|
8
|
-
add
|
9
|
-
getById
|
10
|
-
update
|
11
|
-
delete
|
12
|
-
getAll
|
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
13
|
addBatch: (entities: T[]) => Promise<void>;
|
14
14
|
}
|
15
15
|
export { FirestoreService };
|
@@ -151,164 +151,185 @@ var FirebaseStorageService = /*#__PURE__*/_createClass(function FirebaseStorageS
|
|
151
151
|
}());
|
152
152
|
});
|
153
153
|
|
154
|
-
var FirestoreService = /*#__PURE__*/
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
154
|
+
var FirestoreService = /*#__PURE__*/function () {
|
155
|
+
function FirestoreService(collectionName) {
|
156
|
+
var _this = this;
|
157
|
+
_classCallCheck(this, FirestoreService);
|
158
|
+
_defineProperty(this, "collectionName", "player");
|
159
|
+
_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
|
+
this.collectionName = collectionName;
|
170
|
+
}
|
171
|
+
|
159
172
|
// Add a document to a collection
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
_context.prev = 8;
|
177
|
-
_context.t0 = _context["catch"](0);
|
178
|
-
console.error("Error adding document: ", _context.t0);
|
179
|
-
case 11:
|
180
|
-
case "end":
|
181
|
-
return _context.stop();
|
182
|
-
}
|
183
|
-
}, _callee, null, [[0, 8]]);
|
184
|
-
}));
|
185
|
-
return function (_x) {
|
186
|
-
return _ref.apply(this, arguments);
|
187
|
-
};
|
188
|
-
}());
|
189
|
-
// Update a document to a collection
|
190
|
-
_defineProperty(this, "getById", /*#__PURE__*/function () {
|
191
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2(id) {
|
192
|
-
var docRef;
|
193
|
-
return _regeneratorRuntime__default["default"].wrap(function _callee2$(_context2) {
|
194
|
-
while (1) switch (_context2.prev = _context2.next) {
|
195
|
-
case 0:
|
196
|
-
_context2.prev = 0;
|
197
|
-
_context2.next = 3;
|
198
|
-
return firestore.getDoc(firestore.doc(_this.db, _this.collectionName, id));
|
199
|
-
case 3:
|
200
|
-
docRef = _context2.sent;
|
201
|
-
if (!docRef.exists()) {
|
202
|
-
_context2.next = 8;
|
203
|
-
break;
|
204
|
-
}
|
205
|
-
return _context2.abrupt("return", _objectSpread(_objectSpread({}, docRef.data()), {}, {
|
206
|
-
id: docRef.id
|
207
|
-
}));
|
208
|
-
case 8:
|
209
|
-
throw Error("entity with id: ".concat(id, ", does not exist"));
|
210
|
-
case 9:
|
211
|
-
_context2.next = 15;
|
212
|
-
break;
|
213
|
-
case 11:
|
214
|
-
_context2.prev = 11;
|
215
|
-
_context2.t0 = _context2["catch"](0);
|
216
|
-
console.error("Error getting document: ", _context2.t0);
|
217
|
-
throw _context2.t0;
|
218
|
-
case 15:
|
219
|
-
case "end":
|
220
|
-
return _context2.stop();
|
221
|
-
}
|
222
|
-
}, _callee2, null, [[0, 11]]);
|
223
|
-
}));
|
224
|
-
return function (_x2) {
|
225
|
-
return _ref2.apply(this, arguments);
|
226
|
-
};
|
227
|
-
}());
|
228
|
-
// Update a document to a collection
|
229
|
-
_defineProperty(this, "update", /*#__PURE__*/function () {
|
230
|
-
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee3(entity) {
|
231
|
-
var docRef;
|
232
|
-
return _regeneratorRuntime__default["default"].wrap(function _callee3$(_context3) {
|
233
|
-
while (1) switch (_context3.prev = _context3.next) {
|
234
|
-
case 0:
|
235
|
-
_context3.prev = 0;
|
236
|
-
if (!entity.id) {
|
237
|
-
_context3.next = 4;
|
173
|
+
return _createClass(FirestoreService, [{
|
174
|
+
key: "add",
|
175
|
+
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) {
|
179
|
+
while (1) switch (_context.prev = _context.next) {
|
180
|
+
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;
|
238
189
|
break;
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
})
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
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
|
+
case "end":
|
196
|
+
return _context.stop();
|
197
|
+
}
|
198
|
+
}, _callee, this, [[0, 8]]);
|
199
|
+
}));
|
200
|
+
function add(_x) {
|
201
|
+
return _add.apply(this, arguments);
|
202
|
+
}
|
203
|
+
return add;
|
204
|
+
}() // Update a document to a collection
|
205
|
+
}, {
|
206
|
+
key: "getById",
|
207
|
+
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) {
|
211
|
+
while (1) switch (_context2.prev = _context2.next) {
|
212
|
+
case 0:
|
213
|
+
_context2.prev = 0;
|
214
|
+
_context2.next = 3;
|
215
|
+
return firestore.getDoc(firestore.doc(this.db, this.collectionName, id));
|
216
|
+
case 3:
|
217
|
+
docRef = _context2.sent;
|
218
|
+
if (!docRef.exists()) {
|
219
|
+
_context2.next = 8;
|
220
|
+
break;
|
221
|
+
}
|
222
|
+
return _context2.abrupt("return", _objectSpread(_objectSpread({}, docRef.data()), {}, {
|
223
|
+
id: docRef.id
|
224
|
+
}));
|
225
|
+
case 8:
|
226
|
+
throw Error("entity with id: ".concat(id, ", does not exist"));
|
227
|
+
case 9:
|
228
|
+
_context2.next = 15;
|
265
229
|
break;
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
}());
|
280
|
-
// Get all documents from a collection
|
281
|
-
_defineProperty(this, "getAll", /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee5() {
|
282
|
-
var querySnapshot;
|
283
|
-
return _regeneratorRuntime__default["default"].wrap(function _callee5$(_context5) {
|
284
|
-
while (1) switch (_context5.prev = _context5.next) {
|
285
|
-
case 0:
|
286
|
-
_context5.next = 2;
|
287
|
-
return firestore.getDocs(firestore.collection(_this.db, _this.collectionName));
|
288
|
-
case 2:
|
289
|
-
querySnapshot = _context5.sent;
|
290
|
-
return _context5.abrupt("return", querySnapshot.docs.map(function (doc) {
|
291
|
-
return _objectSpread(_objectSpread({}, doc.data()), {}, {
|
292
|
-
id: doc.id
|
293
|
-
});
|
294
|
-
}));
|
295
|
-
case 4:
|
296
|
-
case "end":
|
297
|
-
return _context5.stop();
|
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:
|
236
|
+
case "end":
|
237
|
+
return _context2.stop();
|
238
|
+
}
|
239
|
+
}, _callee2, this, [[0, 11]]);
|
240
|
+
}));
|
241
|
+
function getById(_x2) {
|
242
|
+
return _getById.apply(this, arguments);
|
298
243
|
}
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
244
|
+
return getById;
|
245
|
+
}() // Update a document to a collection
|
246
|
+
}, {
|
247
|
+
key: "update",
|
248
|
+
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) {
|
252
|
+
while (1) switch (_context3.prev = _context3.next) {
|
253
|
+
case 0:
|
254
|
+
_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:
|
268
|
+
case "end":
|
269
|
+
return _context3.stop();
|
270
|
+
}
|
271
|
+
}, _callee3, this, [[0, 7]]);
|
272
|
+
}));
|
273
|
+
function update(_x3) {
|
274
|
+
return _update.apply(this, arguments);
|
275
|
+
}
|
276
|
+
return update;
|
277
|
+
}()
|
278
|
+
}, {
|
279
|
+
key: "delete",
|
280
|
+
value: function () {
|
281
|
+
var _delete2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee4(entity) {
|
282
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee4$(_context4) {
|
283
|
+
while (1) switch (_context4.prev = _context4.next) {
|
284
|
+
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:
|
293
|
+
case "end":
|
294
|
+
return _context4.stop();
|
295
|
+
}
|
296
|
+
}, _callee4, this);
|
297
|
+
}));
|
298
|
+
function _delete(_x4) {
|
299
|
+
return _delete2.apply(this, arguments);
|
300
|
+
}
|
301
|
+
return _delete;
|
302
|
+
}() // Get all documents from a collection
|
303
|
+
}, {
|
304
|
+
key: "getAll",
|
305
|
+
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) {
|
309
|
+
while (1) switch (_context5.prev = _context5.next) {
|
310
|
+
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
|
+
case "end":
|
322
|
+
return _context5.stop();
|
323
|
+
}
|
324
|
+
}, _callee5, this);
|
325
|
+
}));
|
326
|
+
function getAll() {
|
327
|
+
return _getAll.apply(this, arguments);
|
328
|
+
}
|
329
|
+
return getAll;
|
330
|
+
}()
|
331
|
+
}]);
|
332
|
+
}();
|
312
333
|
|
313
334
|
exports.FirebaseAuthService = FirebaseAuthService;
|
314
335
|
exports.FirebaseStorageService = FirebaseStorageService;
|
@@ -151,164 +151,185 @@ var FirebaseStorageService = /*#__PURE__*/_createClass(function FirebaseStorageS
|
|
151
151
|
}());
|
152
152
|
});
|
153
153
|
|
154
|
-
var FirestoreService = /*#__PURE__*/
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
154
|
+
var FirestoreService = /*#__PURE__*/function () {
|
155
|
+
function FirestoreService(collectionName) {
|
156
|
+
var _this = this;
|
157
|
+
_classCallCheck(this, FirestoreService);
|
158
|
+
_defineProperty(this, "collectionName", "player");
|
159
|
+
_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
|
+
this.collectionName = collectionName;
|
170
|
+
}
|
171
|
+
|
159
172
|
// Add a document to a collection
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
_context.prev = 8;
|
177
|
-
_context.t0 = _context["catch"](0);
|
178
|
-
console.error("Error adding document: ", _context.t0);
|
179
|
-
case 11:
|
180
|
-
case "end":
|
181
|
-
return _context.stop();
|
182
|
-
}
|
183
|
-
}, _callee, null, [[0, 8]]);
|
184
|
-
}));
|
185
|
-
return function (_x) {
|
186
|
-
return _ref.apply(this, arguments);
|
187
|
-
};
|
188
|
-
}());
|
189
|
-
// Update a document to a collection
|
190
|
-
_defineProperty(this, "getById", /*#__PURE__*/function () {
|
191
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2(id) {
|
192
|
-
var docRef;
|
193
|
-
return _regeneratorRuntime__default["default"].wrap(function _callee2$(_context2) {
|
194
|
-
while (1) switch (_context2.prev = _context2.next) {
|
195
|
-
case 0:
|
196
|
-
_context2.prev = 0;
|
197
|
-
_context2.next = 3;
|
198
|
-
return firestore.getDoc(firestore.doc(_this.db, _this.collectionName, id));
|
199
|
-
case 3:
|
200
|
-
docRef = _context2.sent;
|
201
|
-
if (!docRef.exists()) {
|
202
|
-
_context2.next = 8;
|
203
|
-
break;
|
204
|
-
}
|
205
|
-
return _context2.abrupt("return", _objectSpread(_objectSpread({}, docRef.data()), {}, {
|
206
|
-
id: docRef.id
|
207
|
-
}));
|
208
|
-
case 8:
|
209
|
-
throw Error("entity with id: ".concat(id, ", does not exist"));
|
210
|
-
case 9:
|
211
|
-
_context2.next = 15;
|
212
|
-
break;
|
213
|
-
case 11:
|
214
|
-
_context2.prev = 11;
|
215
|
-
_context2.t0 = _context2["catch"](0);
|
216
|
-
console.error("Error getting document: ", _context2.t0);
|
217
|
-
throw _context2.t0;
|
218
|
-
case 15:
|
219
|
-
case "end":
|
220
|
-
return _context2.stop();
|
221
|
-
}
|
222
|
-
}, _callee2, null, [[0, 11]]);
|
223
|
-
}));
|
224
|
-
return function (_x2) {
|
225
|
-
return _ref2.apply(this, arguments);
|
226
|
-
};
|
227
|
-
}());
|
228
|
-
// Update a document to a collection
|
229
|
-
_defineProperty(this, "update", /*#__PURE__*/function () {
|
230
|
-
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee3(entity) {
|
231
|
-
var docRef;
|
232
|
-
return _regeneratorRuntime__default["default"].wrap(function _callee3$(_context3) {
|
233
|
-
while (1) switch (_context3.prev = _context3.next) {
|
234
|
-
case 0:
|
235
|
-
_context3.prev = 0;
|
236
|
-
if (!entity.id) {
|
237
|
-
_context3.next = 4;
|
173
|
+
return _createClass(FirestoreService, [{
|
174
|
+
key: "add",
|
175
|
+
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) {
|
179
|
+
while (1) switch (_context.prev = _context.next) {
|
180
|
+
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;
|
238
189
|
break;
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
})
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
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
|
+
case "end":
|
196
|
+
return _context.stop();
|
197
|
+
}
|
198
|
+
}, _callee, this, [[0, 8]]);
|
199
|
+
}));
|
200
|
+
function add(_x) {
|
201
|
+
return _add.apply(this, arguments);
|
202
|
+
}
|
203
|
+
return add;
|
204
|
+
}() // Update a document to a collection
|
205
|
+
}, {
|
206
|
+
key: "getById",
|
207
|
+
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) {
|
211
|
+
while (1) switch (_context2.prev = _context2.next) {
|
212
|
+
case 0:
|
213
|
+
_context2.prev = 0;
|
214
|
+
_context2.next = 3;
|
215
|
+
return firestore.getDoc(firestore.doc(this.db, this.collectionName, id));
|
216
|
+
case 3:
|
217
|
+
docRef = _context2.sent;
|
218
|
+
if (!docRef.exists()) {
|
219
|
+
_context2.next = 8;
|
220
|
+
break;
|
221
|
+
}
|
222
|
+
return _context2.abrupt("return", _objectSpread(_objectSpread({}, docRef.data()), {}, {
|
223
|
+
id: docRef.id
|
224
|
+
}));
|
225
|
+
case 8:
|
226
|
+
throw Error("entity with id: ".concat(id, ", does not exist"));
|
227
|
+
case 9:
|
228
|
+
_context2.next = 15;
|
265
229
|
break;
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
}());
|
280
|
-
// Get all documents from a collection
|
281
|
-
_defineProperty(this, "getAll", /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee5() {
|
282
|
-
var querySnapshot;
|
283
|
-
return _regeneratorRuntime__default["default"].wrap(function _callee5$(_context5) {
|
284
|
-
while (1) switch (_context5.prev = _context5.next) {
|
285
|
-
case 0:
|
286
|
-
_context5.next = 2;
|
287
|
-
return firestore.getDocs(firestore.collection(_this.db, _this.collectionName));
|
288
|
-
case 2:
|
289
|
-
querySnapshot = _context5.sent;
|
290
|
-
return _context5.abrupt("return", querySnapshot.docs.map(function (doc) {
|
291
|
-
return _objectSpread(_objectSpread({}, doc.data()), {}, {
|
292
|
-
id: doc.id
|
293
|
-
});
|
294
|
-
}));
|
295
|
-
case 4:
|
296
|
-
case "end":
|
297
|
-
return _context5.stop();
|
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:
|
236
|
+
case "end":
|
237
|
+
return _context2.stop();
|
238
|
+
}
|
239
|
+
}, _callee2, this, [[0, 11]]);
|
240
|
+
}));
|
241
|
+
function getById(_x2) {
|
242
|
+
return _getById.apply(this, arguments);
|
298
243
|
}
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
244
|
+
return getById;
|
245
|
+
}() // Update a document to a collection
|
246
|
+
}, {
|
247
|
+
key: "update",
|
248
|
+
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) {
|
252
|
+
while (1) switch (_context3.prev = _context3.next) {
|
253
|
+
case 0:
|
254
|
+
_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:
|
268
|
+
case "end":
|
269
|
+
return _context3.stop();
|
270
|
+
}
|
271
|
+
}, _callee3, this, [[0, 7]]);
|
272
|
+
}));
|
273
|
+
function update(_x3) {
|
274
|
+
return _update.apply(this, arguments);
|
275
|
+
}
|
276
|
+
return update;
|
277
|
+
}()
|
278
|
+
}, {
|
279
|
+
key: "delete",
|
280
|
+
value: function () {
|
281
|
+
var _delete2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee4(entity) {
|
282
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee4$(_context4) {
|
283
|
+
while (1) switch (_context4.prev = _context4.next) {
|
284
|
+
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:
|
293
|
+
case "end":
|
294
|
+
return _context4.stop();
|
295
|
+
}
|
296
|
+
}, _callee4, this);
|
297
|
+
}));
|
298
|
+
function _delete(_x4) {
|
299
|
+
return _delete2.apply(this, arguments);
|
300
|
+
}
|
301
|
+
return _delete;
|
302
|
+
}() // Get all documents from a collection
|
303
|
+
}, {
|
304
|
+
key: "getAll",
|
305
|
+
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) {
|
309
|
+
while (1) switch (_context5.prev = _context5.next) {
|
310
|
+
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
|
+
case "end":
|
322
|
+
return _context5.stop();
|
323
|
+
}
|
324
|
+
}, _callee5, this);
|
325
|
+
}));
|
326
|
+
function getAll() {
|
327
|
+
return _getAll.apply(this, arguments);
|
328
|
+
}
|
329
|
+
return getAll;
|
330
|
+
}()
|
331
|
+
}]);
|
332
|
+
}();
|
312
333
|
|
313
334
|
exports.FirebaseAuthService = FirebaseAuthService;
|
314
335
|
exports.FirebaseStorageService = FirebaseStorageService;
|
@@ -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 { addDoc, collection, getDoc, doc, updateDoc, deleteDoc, getDocs, getFirestore, writeBatch } from 'firebase/firestore';
|
11
11
|
import { v4 } from 'uuid';
|
12
12
|
|
13
13
|
var firebaseConfig = {
|
@@ -143,163 +143,184 @@ var FirebaseStorageService = /*#__PURE__*/_createClass(function FirebaseStorageS
|
|
143
143
|
}());
|
144
144
|
});
|
145
145
|
|
146
|
-
var FirestoreService = /*#__PURE__*/
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
146
|
+
var FirestoreService = /*#__PURE__*/function () {
|
147
|
+
function FirestoreService(collectionName) {
|
148
|
+
var _this = this;
|
149
|
+
_classCallCheck(this, FirestoreService);
|
150
|
+
_defineProperty(this, "collectionName", "player");
|
151
|
+
_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
|
+
this.collectionName = collectionName;
|
162
|
+
}
|
163
|
+
|
151
164
|
// Add a document to a collection
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
_context.prev = 8;
|
169
|
-
_context.t0 = _context["catch"](0);
|
170
|
-
console.error("Error adding document: ", _context.t0);
|
171
|
-
case 11:
|
172
|
-
case "end":
|
173
|
-
return _context.stop();
|
174
|
-
}
|
175
|
-
}, _callee, null, [[0, 8]]);
|
176
|
-
}));
|
177
|
-
return function (_x) {
|
178
|
-
return _ref.apply(this, arguments);
|
179
|
-
};
|
180
|
-
}());
|
181
|
-
// Update a document to a collection
|
182
|
-
_defineProperty(this, "getById", /*#__PURE__*/function () {
|
183
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(id) {
|
184
|
-
var docRef;
|
185
|
-
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
186
|
-
while (1) switch (_context2.prev = _context2.next) {
|
187
|
-
case 0:
|
188
|
-
_context2.prev = 0;
|
189
|
-
_context2.next = 3;
|
190
|
-
return getDoc(doc(_this.db, _this.collectionName, id));
|
191
|
-
case 3:
|
192
|
-
docRef = _context2.sent;
|
193
|
-
if (!docRef.exists()) {
|
194
|
-
_context2.next = 8;
|
195
|
-
break;
|
196
|
-
}
|
197
|
-
return _context2.abrupt("return", _objectSpread(_objectSpread({}, docRef.data()), {}, {
|
198
|
-
id: docRef.id
|
199
|
-
}));
|
200
|
-
case 8:
|
201
|
-
throw Error("entity with id: ".concat(id, ", does not exist"));
|
202
|
-
case 9:
|
203
|
-
_context2.next = 15;
|
204
|
-
break;
|
205
|
-
case 11:
|
206
|
-
_context2.prev = 11;
|
207
|
-
_context2.t0 = _context2["catch"](0);
|
208
|
-
console.error("Error getting document: ", _context2.t0);
|
209
|
-
throw _context2.t0;
|
210
|
-
case 15:
|
211
|
-
case "end":
|
212
|
-
return _context2.stop();
|
213
|
-
}
|
214
|
-
}, _callee2, null, [[0, 11]]);
|
215
|
-
}));
|
216
|
-
return function (_x2) {
|
217
|
-
return _ref2.apply(this, arguments);
|
218
|
-
};
|
219
|
-
}());
|
220
|
-
// Update a document to a collection
|
221
|
-
_defineProperty(this, "update", /*#__PURE__*/function () {
|
222
|
-
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(entity) {
|
223
|
-
var docRef;
|
224
|
-
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
225
|
-
while (1) switch (_context3.prev = _context3.next) {
|
226
|
-
case 0:
|
227
|
-
_context3.prev = 0;
|
228
|
-
if (!entity.id) {
|
229
|
-
_context3.next = 4;
|
165
|
+
return _createClass(FirestoreService, [{
|
166
|
+
key: "add",
|
167
|
+
value: function () {
|
168
|
+
var _add = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(entity) {
|
169
|
+
var docRef;
|
170
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
171
|
+
while (1) switch (_context.prev = _context.next) {
|
172
|
+
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;
|
230
181
|
break;
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
})
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
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
|
+
case "end":
|
188
|
+
return _context.stop();
|
189
|
+
}
|
190
|
+
}, _callee, this, [[0, 8]]);
|
191
|
+
}));
|
192
|
+
function add(_x) {
|
193
|
+
return _add.apply(this, arguments);
|
194
|
+
}
|
195
|
+
return add;
|
196
|
+
}() // Update a document to a collection
|
197
|
+
}, {
|
198
|
+
key: "getById",
|
199
|
+
value: function () {
|
200
|
+
var _getById = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(id) {
|
201
|
+
var docRef;
|
202
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
203
|
+
while (1) switch (_context2.prev = _context2.next) {
|
204
|
+
case 0:
|
205
|
+
_context2.prev = 0;
|
206
|
+
_context2.next = 3;
|
207
|
+
return getDoc(doc(this.db, this.collectionName, id));
|
208
|
+
case 3:
|
209
|
+
docRef = _context2.sent;
|
210
|
+
if (!docRef.exists()) {
|
211
|
+
_context2.next = 8;
|
212
|
+
break;
|
213
|
+
}
|
214
|
+
return _context2.abrupt("return", _objectSpread(_objectSpread({}, docRef.data()), {}, {
|
215
|
+
id: docRef.id
|
216
|
+
}));
|
217
|
+
case 8:
|
218
|
+
throw Error("entity with id: ".concat(id, ", does not exist"));
|
219
|
+
case 9:
|
220
|
+
_context2.next = 15;
|
257
221
|
break;
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
}());
|
272
|
-
// Get all documents from a collection
|
273
|
-
_defineProperty(this, "getAll", /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
|
274
|
-
var querySnapshot;
|
275
|
-
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
276
|
-
while (1) switch (_context5.prev = _context5.next) {
|
277
|
-
case 0:
|
278
|
-
_context5.next = 2;
|
279
|
-
return getDocs(collection(_this.db, _this.collectionName));
|
280
|
-
case 2:
|
281
|
-
querySnapshot = _context5.sent;
|
282
|
-
return _context5.abrupt("return", querySnapshot.docs.map(function (doc) {
|
283
|
-
return _objectSpread(_objectSpread({}, doc.data()), {}, {
|
284
|
-
id: doc.id
|
285
|
-
});
|
286
|
-
}));
|
287
|
-
case 4:
|
288
|
-
case "end":
|
289
|
-
return _context5.stop();
|
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:
|
228
|
+
case "end":
|
229
|
+
return _context2.stop();
|
230
|
+
}
|
231
|
+
}, _callee2, this, [[0, 11]]);
|
232
|
+
}));
|
233
|
+
function getById(_x2) {
|
234
|
+
return _getById.apply(this, arguments);
|
290
235
|
}
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
236
|
+
return getById;
|
237
|
+
}() // Update a document to a collection
|
238
|
+
}, {
|
239
|
+
key: "update",
|
240
|
+
value: function () {
|
241
|
+
var _update = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(entity) {
|
242
|
+
var docRef;
|
243
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
244
|
+
while (1) switch (_context3.prev = _context3.next) {
|
245
|
+
case 0:
|
246
|
+
_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:
|
260
|
+
case "end":
|
261
|
+
return _context3.stop();
|
262
|
+
}
|
263
|
+
}, _callee3, this, [[0, 7]]);
|
264
|
+
}));
|
265
|
+
function update(_x3) {
|
266
|
+
return _update.apply(this, arguments);
|
267
|
+
}
|
268
|
+
return update;
|
269
|
+
}()
|
270
|
+
}, {
|
271
|
+
key: "delete",
|
272
|
+
value: function () {
|
273
|
+
var _delete2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(entity) {
|
274
|
+
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
275
|
+
while (1) switch (_context4.prev = _context4.next) {
|
276
|
+
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:
|
285
|
+
case "end":
|
286
|
+
return _context4.stop();
|
287
|
+
}
|
288
|
+
}, _callee4, this);
|
289
|
+
}));
|
290
|
+
function _delete(_x4) {
|
291
|
+
return _delete2.apply(this, arguments);
|
292
|
+
}
|
293
|
+
return _delete;
|
294
|
+
}() // Get all documents from a collection
|
295
|
+
}, {
|
296
|
+
key: "getAll",
|
297
|
+
value: function () {
|
298
|
+
var _getAll = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
|
299
|
+
var querySnapshot;
|
300
|
+
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
301
|
+
while (1) switch (_context5.prev = _context5.next) {
|
302
|
+
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
|
+
case "end":
|
314
|
+
return _context5.stop();
|
315
|
+
}
|
316
|
+
}, _callee5, this);
|
317
|
+
}));
|
318
|
+
function getAll() {
|
319
|
+
return _getAll.apply(this, arguments);
|
320
|
+
}
|
321
|
+
return getAll;
|
322
|
+
}()
|
323
|
+
}]);
|
324
|
+
}();
|
304
325
|
|
305
326
|
export { FirebaseAuthService, FirebaseStorageService, FirestoreService, firebaseClient };
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@digitalaidseattle/firebase",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.2",
|
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.5",
|
12
12
|
"firebase": "^11.2.0",
|
13
13
|
"react": "^18.3.1",
|
14
14
|
"uuid": "^11.0.5"
|