@digitalaidseattle/firebase 1.0.0 → 1.0.1
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.
@@ -6,6 +6,7 @@ declare class FirestoreService<T extends Entity> {
|
|
6
6
|
db: import("@firebase/firestore").Firestore;
|
7
7
|
constructor(collectionName: string);
|
8
8
|
add: (entity: T) => Promise<void>;
|
9
|
+
getById: (id: string) => Promise<T>;
|
9
10
|
update: (entity: T) => Promise<void>;
|
10
11
|
delete: (entity: T) => Promise<void>;
|
11
12
|
getAll: () => Promise<T[]>;
|
@@ -187,77 +187,116 @@ var FirestoreService = /*#__PURE__*/_createClass(function FirestoreService(colle
|
|
187
187
|
};
|
188
188
|
}());
|
189
189
|
// Update a document to a collection
|
190
|
-
_defineProperty(this, "
|
191
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2(
|
190
|
+
_defineProperty(this, "getById", /*#__PURE__*/function () {
|
191
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2(id) {
|
192
192
|
var docRef;
|
193
193
|
return _regeneratorRuntime__default["default"].wrap(function _callee2$(_context2) {
|
194
194
|
while (1) switch (_context2.prev = _context2.next) {
|
195
195
|
case 0:
|
196
196
|
_context2.prev = 0;
|
197
|
-
|
198
|
-
|
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;
|
199
203
|
break;
|
200
204
|
}
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
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;
|
207
215
|
_context2.t0 = _context2["catch"](0);
|
208
|
-
console.error("Error
|
209
|
-
|
216
|
+
console.error("Error getting document: ", _context2.t0);
|
217
|
+
throw _context2.t0;
|
218
|
+
case 15:
|
210
219
|
case "end":
|
211
220
|
return _context2.stop();
|
212
221
|
}
|
213
|
-
}, _callee2, null, [[0,
|
222
|
+
}, _callee2, null, [[0, 11]]);
|
214
223
|
}));
|
215
224
|
return function (_x2) {
|
216
225
|
return _ref2.apply(this, arguments);
|
217
226
|
};
|
218
227
|
}());
|
219
|
-
|
228
|
+
// Update a document to a collection
|
229
|
+
_defineProperty(this, "update", /*#__PURE__*/function () {
|
220
230
|
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee3(entity) {
|
231
|
+
var docRef;
|
221
232
|
return _regeneratorRuntime__default["default"].wrap(function _callee3$(_context3) {
|
222
233
|
while (1) switch (_context3.prev = _context3.next) {
|
223
234
|
case 0:
|
235
|
+
_context3.prev = 0;
|
224
236
|
if (!entity.id) {
|
225
|
-
_context3.next =
|
237
|
+
_context3.next = 4;
|
226
238
|
break;
|
227
239
|
}
|
228
|
-
|
229
|
-
|
240
|
+
docRef = firestore.doc(_this.db, _this.collectionName, entity.id);
|
241
|
+
return _context3.abrupt("return", firestore.updateDoc(docRef, entity));
|
242
|
+
case 4:
|
230
243
|
throw new Error('Entity does not have an id.');
|
231
|
-
case
|
244
|
+
case 7:
|
245
|
+
_context3.prev = 7;
|
246
|
+
_context3.t0 = _context3["catch"](0);
|
247
|
+
console.error("Error updating document: ", _context3.t0);
|
248
|
+
case 10:
|
232
249
|
case "end":
|
233
250
|
return _context3.stop();
|
234
251
|
}
|
235
|
-
}, _callee3);
|
252
|
+
}, _callee3, null, [[0, 7]]);
|
236
253
|
}));
|
237
254
|
return function (_x3) {
|
238
255
|
return _ref3.apply(this, arguments);
|
239
256
|
};
|
240
257
|
}());
|
258
|
+
_defineProperty(this, "delete", /*#__PURE__*/function () {
|
259
|
+
var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee4(entity) {
|
260
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee4$(_context4) {
|
261
|
+
while (1) switch (_context4.prev = _context4.next) {
|
262
|
+
case 0:
|
263
|
+
if (!entity.id) {
|
264
|
+
_context4.next = 2;
|
265
|
+
break;
|
266
|
+
}
|
267
|
+
return _context4.abrupt("return", firestore.deleteDoc(firestore.doc(_this.db, _this.collectionName, entity.id)));
|
268
|
+
case 2:
|
269
|
+
throw new Error('Entity does not have an id.');
|
270
|
+
case 3:
|
271
|
+
case "end":
|
272
|
+
return _context4.stop();
|
273
|
+
}
|
274
|
+
}, _callee4);
|
275
|
+
}));
|
276
|
+
return function (_x4) {
|
277
|
+
return _ref4.apply(this, arguments);
|
278
|
+
};
|
279
|
+
}());
|
241
280
|
// Get all documents from a collection
|
242
|
-
_defineProperty(this, "getAll", /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function
|
281
|
+
_defineProperty(this, "getAll", /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee5() {
|
243
282
|
var querySnapshot;
|
244
|
-
return _regeneratorRuntime__default["default"].wrap(function
|
245
|
-
while (1) switch (
|
283
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee5$(_context5) {
|
284
|
+
while (1) switch (_context5.prev = _context5.next) {
|
246
285
|
case 0:
|
247
|
-
|
286
|
+
_context5.next = 2;
|
248
287
|
return firestore.getDocs(firestore.collection(_this.db, _this.collectionName));
|
249
288
|
case 2:
|
250
|
-
querySnapshot =
|
251
|
-
return
|
289
|
+
querySnapshot = _context5.sent;
|
290
|
+
return _context5.abrupt("return", querySnapshot.docs.map(function (doc) {
|
252
291
|
return _objectSpread(_objectSpread({}, doc.data()), {}, {
|
253
292
|
id: doc.id
|
254
293
|
});
|
255
294
|
}));
|
256
295
|
case 4:
|
257
296
|
case "end":
|
258
|
-
return
|
297
|
+
return _context5.stop();
|
259
298
|
}
|
260
|
-
},
|
299
|
+
}, _callee5);
|
261
300
|
})));
|
262
301
|
_defineProperty(this, "addBatch", function (entities) {
|
263
302
|
var batch = firestore.writeBatch(_this.db);
|
@@ -187,77 +187,116 @@ var FirestoreService = /*#__PURE__*/_createClass(function FirestoreService(colle
|
|
187
187
|
};
|
188
188
|
}());
|
189
189
|
// Update a document to a collection
|
190
|
-
_defineProperty(this, "
|
191
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2(
|
190
|
+
_defineProperty(this, "getById", /*#__PURE__*/function () {
|
191
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2(id) {
|
192
192
|
var docRef;
|
193
193
|
return _regeneratorRuntime__default["default"].wrap(function _callee2$(_context2) {
|
194
194
|
while (1) switch (_context2.prev = _context2.next) {
|
195
195
|
case 0:
|
196
196
|
_context2.prev = 0;
|
197
|
-
|
198
|
-
|
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;
|
199
203
|
break;
|
200
204
|
}
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
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;
|
207
215
|
_context2.t0 = _context2["catch"](0);
|
208
|
-
console.error("Error
|
209
|
-
|
216
|
+
console.error("Error getting document: ", _context2.t0);
|
217
|
+
throw _context2.t0;
|
218
|
+
case 15:
|
210
219
|
case "end":
|
211
220
|
return _context2.stop();
|
212
221
|
}
|
213
|
-
}, _callee2, null, [[0,
|
222
|
+
}, _callee2, null, [[0, 11]]);
|
214
223
|
}));
|
215
224
|
return function (_x2) {
|
216
225
|
return _ref2.apply(this, arguments);
|
217
226
|
};
|
218
227
|
}());
|
219
|
-
|
228
|
+
// Update a document to a collection
|
229
|
+
_defineProperty(this, "update", /*#__PURE__*/function () {
|
220
230
|
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee3(entity) {
|
231
|
+
var docRef;
|
221
232
|
return _regeneratorRuntime__default["default"].wrap(function _callee3$(_context3) {
|
222
233
|
while (1) switch (_context3.prev = _context3.next) {
|
223
234
|
case 0:
|
235
|
+
_context3.prev = 0;
|
224
236
|
if (!entity.id) {
|
225
|
-
_context3.next =
|
237
|
+
_context3.next = 4;
|
226
238
|
break;
|
227
239
|
}
|
228
|
-
|
229
|
-
|
240
|
+
docRef = firestore.doc(_this.db, _this.collectionName, entity.id);
|
241
|
+
return _context3.abrupt("return", firestore.updateDoc(docRef, entity));
|
242
|
+
case 4:
|
230
243
|
throw new Error('Entity does not have an id.');
|
231
|
-
case
|
244
|
+
case 7:
|
245
|
+
_context3.prev = 7;
|
246
|
+
_context3.t0 = _context3["catch"](0);
|
247
|
+
console.error("Error updating document: ", _context3.t0);
|
248
|
+
case 10:
|
232
249
|
case "end":
|
233
250
|
return _context3.stop();
|
234
251
|
}
|
235
|
-
}, _callee3);
|
252
|
+
}, _callee3, null, [[0, 7]]);
|
236
253
|
}));
|
237
254
|
return function (_x3) {
|
238
255
|
return _ref3.apply(this, arguments);
|
239
256
|
};
|
240
257
|
}());
|
258
|
+
_defineProperty(this, "delete", /*#__PURE__*/function () {
|
259
|
+
var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee4(entity) {
|
260
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee4$(_context4) {
|
261
|
+
while (1) switch (_context4.prev = _context4.next) {
|
262
|
+
case 0:
|
263
|
+
if (!entity.id) {
|
264
|
+
_context4.next = 2;
|
265
|
+
break;
|
266
|
+
}
|
267
|
+
return _context4.abrupt("return", firestore.deleteDoc(firestore.doc(_this.db, _this.collectionName, entity.id)));
|
268
|
+
case 2:
|
269
|
+
throw new Error('Entity does not have an id.');
|
270
|
+
case 3:
|
271
|
+
case "end":
|
272
|
+
return _context4.stop();
|
273
|
+
}
|
274
|
+
}, _callee4);
|
275
|
+
}));
|
276
|
+
return function (_x4) {
|
277
|
+
return _ref4.apply(this, arguments);
|
278
|
+
};
|
279
|
+
}());
|
241
280
|
// Get all documents from a collection
|
242
|
-
_defineProperty(this, "getAll", /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function
|
281
|
+
_defineProperty(this, "getAll", /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee5() {
|
243
282
|
var querySnapshot;
|
244
|
-
return _regeneratorRuntime__default["default"].wrap(function
|
245
|
-
while (1) switch (
|
283
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee5$(_context5) {
|
284
|
+
while (1) switch (_context5.prev = _context5.next) {
|
246
285
|
case 0:
|
247
|
-
|
286
|
+
_context5.next = 2;
|
248
287
|
return firestore.getDocs(firestore.collection(_this.db, _this.collectionName));
|
249
288
|
case 2:
|
250
|
-
querySnapshot =
|
251
|
-
return
|
289
|
+
querySnapshot = _context5.sent;
|
290
|
+
return _context5.abrupt("return", querySnapshot.docs.map(function (doc) {
|
252
291
|
return _objectSpread(_objectSpread({}, doc.data()), {}, {
|
253
292
|
id: doc.id
|
254
293
|
});
|
255
294
|
}));
|
256
295
|
case 4:
|
257
296
|
case "end":
|
258
|
-
return
|
297
|
+
return _context5.stop();
|
259
298
|
}
|
260
|
-
},
|
299
|
+
}, _callee5);
|
261
300
|
})));
|
262
301
|
_defineProperty(this, "addBatch", function (entities) {
|
263
302
|
var batch = firestore.writeBatch(_this.db);
|
@@ -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 { getFirestore, addDoc, collection, doc, updateDoc, deleteDoc, getDocs, writeBatch } from 'firebase/firestore';
|
10
|
+
import { getFirestore, addDoc, collection, getDoc, doc, updateDoc, deleteDoc, getDocs, writeBatch } from 'firebase/firestore';
|
11
11
|
import { v4 } from 'uuid';
|
12
12
|
|
13
13
|
var firebaseConfig = {
|
@@ -179,77 +179,116 @@ var FirestoreService = /*#__PURE__*/_createClass(function FirestoreService(colle
|
|
179
179
|
};
|
180
180
|
}());
|
181
181
|
// Update a document to a collection
|
182
|
-
_defineProperty(this, "
|
183
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(
|
182
|
+
_defineProperty(this, "getById", /*#__PURE__*/function () {
|
183
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(id) {
|
184
184
|
var docRef;
|
185
185
|
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
186
186
|
while (1) switch (_context2.prev = _context2.next) {
|
187
187
|
case 0:
|
188
188
|
_context2.prev = 0;
|
189
|
-
|
190
|
-
|
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;
|
191
195
|
break;
|
192
196
|
}
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
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;
|
199
207
|
_context2.t0 = _context2["catch"](0);
|
200
|
-
console.error("Error
|
201
|
-
|
208
|
+
console.error("Error getting document: ", _context2.t0);
|
209
|
+
throw _context2.t0;
|
210
|
+
case 15:
|
202
211
|
case "end":
|
203
212
|
return _context2.stop();
|
204
213
|
}
|
205
|
-
}, _callee2, null, [[0,
|
214
|
+
}, _callee2, null, [[0, 11]]);
|
206
215
|
}));
|
207
216
|
return function (_x2) {
|
208
217
|
return _ref2.apply(this, arguments);
|
209
218
|
};
|
210
219
|
}());
|
211
|
-
|
220
|
+
// Update a document to a collection
|
221
|
+
_defineProperty(this, "update", /*#__PURE__*/function () {
|
212
222
|
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(entity) {
|
223
|
+
var docRef;
|
213
224
|
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
214
225
|
while (1) switch (_context3.prev = _context3.next) {
|
215
226
|
case 0:
|
227
|
+
_context3.prev = 0;
|
216
228
|
if (!entity.id) {
|
217
|
-
_context3.next =
|
229
|
+
_context3.next = 4;
|
218
230
|
break;
|
219
231
|
}
|
220
|
-
|
221
|
-
|
232
|
+
docRef = doc(_this.db, _this.collectionName, entity.id);
|
233
|
+
return _context3.abrupt("return", updateDoc(docRef, entity));
|
234
|
+
case 4:
|
222
235
|
throw new Error('Entity does not have an id.');
|
223
|
-
case
|
236
|
+
case 7:
|
237
|
+
_context3.prev = 7;
|
238
|
+
_context3.t0 = _context3["catch"](0);
|
239
|
+
console.error("Error updating document: ", _context3.t0);
|
240
|
+
case 10:
|
224
241
|
case "end":
|
225
242
|
return _context3.stop();
|
226
243
|
}
|
227
|
-
}, _callee3);
|
244
|
+
}, _callee3, null, [[0, 7]]);
|
228
245
|
}));
|
229
246
|
return function (_x3) {
|
230
247
|
return _ref3.apply(this, arguments);
|
231
248
|
};
|
232
249
|
}());
|
250
|
+
_defineProperty(this, "delete", /*#__PURE__*/function () {
|
251
|
+
var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(entity) {
|
252
|
+
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
253
|
+
while (1) switch (_context4.prev = _context4.next) {
|
254
|
+
case 0:
|
255
|
+
if (!entity.id) {
|
256
|
+
_context4.next = 2;
|
257
|
+
break;
|
258
|
+
}
|
259
|
+
return _context4.abrupt("return", deleteDoc(doc(_this.db, _this.collectionName, entity.id)));
|
260
|
+
case 2:
|
261
|
+
throw new Error('Entity does not have an id.');
|
262
|
+
case 3:
|
263
|
+
case "end":
|
264
|
+
return _context4.stop();
|
265
|
+
}
|
266
|
+
}, _callee4);
|
267
|
+
}));
|
268
|
+
return function (_x4) {
|
269
|
+
return _ref4.apply(this, arguments);
|
270
|
+
};
|
271
|
+
}());
|
233
272
|
// Get all documents from a collection
|
234
|
-
_defineProperty(this, "getAll", /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function
|
273
|
+
_defineProperty(this, "getAll", /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
|
235
274
|
var querySnapshot;
|
236
|
-
return _regeneratorRuntime.wrap(function
|
237
|
-
while (1) switch (
|
275
|
+
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
276
|
+
while (1) switch (_context5.prev = _context5.next) {
|
238
277
|
case 0:
|
239
|
-
|
278
|
+
_context5.next = 2;
|
240
279
|
return getDocs(collection(_this.db, _this.collectionName));
|
241
280
|
case 2:
|
242
|
-
querySnapshot =
|
243
|
-
return
|
281
|
+
querySnapshot = _context5.sent;
|
282
|
+
return _context5.abrupt("return", querySnapshot.docs.map(function (doc) {
|
244
283
|
return _objectSpread(_objectSpread({}, doc.data()), {}, {
|
245
284
|
id: doc.id
|
246
285
|
});
|
247
286
|
}));
|
248
287
|
case 4:
|
249
288
|
case "end":
|
250
|
-
return
|
289
|
+
return _context5.stop();
|
251
290
|
}
|
252
|
-
},
|
291
|
+
}, _callee5);
|
253
292
|
})));
|
254
293
|
_defineProperty(this, "addBatch", function (entities) {
|
255
294
|
var batch = writeBatch(_this.db);
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@digitalaidseattle/firebase",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.1",
|
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",
|