@data-weave/backend-firestore 0.4.27 → 0.5.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.
- package/dist/FirestoreAdminAdapter.d.ts +31 -0
- package/dist/FirestoreAdminAdapter.js +106 -0
- package/dist/FirestoreDataManager.d.ts +76 -0
- package/dist/FirestoreDataManager.js +243 -0
- package/{lib → dist}/FirestoreList.d.ts +3 -7
- package/dist/FirestoreList.js +95 -0
- package/{lib → dist}/FirestoreMetadata.d.ts +1 -0
- package/{lib → dist}/FirestoreMetadata.js +3 -3
- package/{lib → dist}/FirestoreReference.d.ts +3 -10
- package/dist/FirestoreReference.js +75 -0
- package/dist/errors.d.ts +29 -0
- package/dist/errors.js +38 -0
- package/{lib → dist}/firestoreTypes.d.ts +18 -11
- package/dist/firestoreTypes.js +29 -0
- package/{lib → dist}/index.d.ts +3 -0
- package/{lib → dist}/index.js +3 -0
- package/{lib → dist}/utils.d.ts +3 -2
- package/{lib → dist}/utils.js +49 -7
- package/package.json +20 -9
- package/lib/FirestoreDataManager.d.ts +0 -46
- package/lib/FirestoreDataManager.js +0 -227
- package/lib/FirestoreList.js +0 -96
- package/lib/FirestoreReference.js +0 -85
- package/lib/firestoreTypes.js +0 -127
- package/lib/version.d.ts +0 -2
- package/lib/version.js +0 -3
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
3
|
-
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
4
|
-
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
5
|
-
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
6
|
-
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
7
|
-
var _, done = false;
|
|
8
|
-
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
9
|
-
var context = {};
|
|
10
|
-
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
11
|
-
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
12
|
-
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
13
|
-
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
14
|
-
if (kind === "accessor") {
|
|
15
|
-
if (result === void 0) continue;
|
|
16
|
-
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
17
|
-
if (_ = accept(result.get)) descriptor.get = _;
|
|
18
|
-
if (_ = accept(result.set)) descriptor.set = _;
|
|
19
|
-
if (_ = accept(result.init)) initializers.unshift(_);
|
|
20
|
-
}
|
|
21
|
-
else if (_ = accept(result)) {
|
|
22
|
-
if (kind === "field") initializers.unshift(_);
|
|
23
|
-
else descriptor[key] = _;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
27
|
-
done = true;
|
|
28
|
-
};
|
|
29
|
-
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
30
|
-
var useValue = arguments.length > 2;
|
|
31
|
-
for (var i = 0; i < initializers.length; i++) {
|
|
32
|
-
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
33
|
-
}
|
|
34
|
-
return useValue ? value : void 0;
|
|
35
|
-
};
|
|
36
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
37
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
38
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
39
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
40
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
41
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
42
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
|
|
46
|
-
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
|
47
|
-
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
|
48
|
-
};
|
|
49
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
-
exports.FirestoreDataManager = void 0;
|
|
51
|
-
const inversify_1 = require("inversify");
|
|
52
|
-
const datamanager_1 = require("@data-weave/datamanager");
|
|
53
|
-
const FirestoreList_1 = require("./FirestoreList");
|
|
54
|
-
const FirestoreMetadata_1 = require("./FirestoreMetadata");
|
|
55
|
-
const FirestoreReference_1 = require("./FirestoreReference");
|
|
56
|
-
const utils_1 = require("./utils");
|
|
57
|
-
const defaultFirebaseDataManagerOptions = {
|
|
58
|
-
deleteMode: 'soft',
|
|
59
|
-
preventOverwriteOnCreate: true,
|
|
60
|
-
readMode: 'static',
|
|
61
|
-
Reference: FirestoreReference_1.FirestoreReference,
|
|
62
|
-
List: FirestoreList_1.FirestoreList,
|
|
63
|
-
};
|
|
64
|
-
let FirestoreDataManager = (() => {
|
|
65
|
-
let _classDecorators = [(0, inversify_1.injectable)()];
|
|
66
|
-
let _classDescriptor;
|
|
67
|
-
let _classExtraInitializers = [];
|
|
68
|
-
let _classThis;
|
|
69
|
-
var FirestoreDataManager = _classThis = class {
|
|
70
|
-
constructor(firestore, collectionPath, converter, opts) {
|
|
71
|
-
this.firestore = firestore;
|
|
72
|
-
this.collectionPath = collectionPath;
|
|
73
|
-
this.converter = converter;
|
|
74
|
-
this.opts = opts;
|
|
75
|
-
// @ts-expect-error - Force merge FirestoreDataConverter and InternalFirestoreDataConverter
|
|
76
|
-
this.mergedConverter = new utils_1.MergeConverters(this.converter, new FirestoreMetadata_1.FirestoreMetadataConverter());
|
|
77
|
-
this.managerOptions = Object.assign(defaultFirebaseDataManagerOptions, this.opts);
|
|
78
|
-
this.refCache = this.managerOptions.refCache || new datamanager_1.MapCache(100);
|
|
79
|
-
this.listCache = this.managerOptions.listCache || new datamanager_1.MapCache(100);
|
|
80
|
-
this.collection = this.firestore
|
|
81
|
-
.collection(this.firestore.app, this.collectionPath)
|
|
82
|
-
.withConverter(this.mergedConverter);
|
|
83
|
-
this.collectionQuery =
|
|
84
|
-
this.managerOptions.deleteMode === 'soft'
|
|
85
|
-
? (0, FirestoreMetadata_1.queryNotDeleted)(this.collection, this.firestore.query, this.firestore.where)
|
|
86
|
-
: this.collection;
|
|
87
|
-
}
|
|
88
|
-
read(id, options) {
|
|
89
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
-
var _a;
|
|
91
|
-
if (!((_a = this.managerOptions) === null || _a === void 0 ? void 0 : _a.Reference))
|
|
92
|
-
throw new Error('ReferenceClass not defined');
|
|
93
|
-
const ref = this.getRef(id);
|
|
94
|
-
if (options === null || options === void 0 ? void 0 : options.transaction) {
|
|
95
|
-
const snapshot = yield options.transaction.get(this.firestore.doc(this.collection, id));
|
|
96
|
-
if (!(0, utils_1.checkIfReferenceExists)(snapshot))
|
|
97
|
-
return undefined;
|
|
98
|
-
return snapshot.data();
|
|
99
|
-
}
|
|
100
|
-
return yield ref.resolve();
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
create(data, options) {
|
|
104
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
-
var _a;
|
|
106
|
-
let id = undefined;
|
|
107
|
-
if (options === null || options === void 0 ? void 0 : options.id) {
|
|
108
|
-
id = options === null || options === void 0 ? void 0 : options.id;
|
|
109
|
-
}
|
|
110
|
-
else if ((_a = this.managerOptions) === null || _a === void 0 ? void 0 : _a.idResolver) {
|
|
111
|
-
id = this.managerOptions.idResolver();
|
|
112
|
-
}
|
|
113
|
-
let docRef;
|
|
114
|
-
let docExists = false;
|
|
115
|
-
if (id) {
|
|
116
|
-
docRef = this.firestore.doc(this.collection, id);
|
|
117
|
-
docExists = yield this.preventOverwriteOnCreate(docRef, options);
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
docRef = this.firestore.doc(this.collection);
|
|
121
|
-
}
|
|
122
|
-
const docDataWithMetadata = Object.assign(Object.assign({}, data), { [FirestoreMetadata_1.FIRESTORE_KEYS.CREATED_AT]: docExists ? undefined : this.firestore.serverTimestamp(), [FirestoreMetadata_1.FIRESTORE_KEYS.UPDATED_AT]: this.firestore.serverTimestamp(), [FirestoreMetadata_1.FIRESTORE_KEYS.DELETED]: false });
|
|
123
|
-
const firebaseOptions = { merge: options === null || options === void 0 ? void 0 : options.merge };
|
|
124
|
-
if (options === null || options === void 0 ? void 0 : options.transaction) {
|
|
125
|
-
options === null || options === void 0 ? void 0 : options.transaction.set(docRef, docDataWithMetadata, firebaseOptions);
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
yield this.firestore.setDoc(docRef, docDataWithMetadata, firebaseOptions);
|
|
129
|
-
}
|
|
130
|
-
return this.getRef(docRef.id);
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
_update(id, data, options) {
|
|
134
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
-
const extendedData = Object.assign(Object.assign({}, data), { [FirestoreMetadata_1.FIRESTORE_KEYS.UPDATED_AT]: this.firestore.serverTimestamp() });
|
|
136
|
-
// Firestore update method doesn't call converter like setDoc does, so we need to serialize the data manually.
|
|
137
|
-
const serializedData = this.mergedConverter.toFirestore(extendedData);
|
|
138
|
-
const ref = this.firestore.doc(this.collection, id);
|
|
139
|
-
if (options === null || options === void 0 ? void 0 : options.transaction) {
|
|
140
|
-
return options.transaction.update(ref, serializedData);
|
|
141
|
-
}
|
|
142
|
-
return this.firestore.updateDoc(ref, serializedData);
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
update(id, data, options) {
|
|
146
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
-
yield this._update(id, data, options);
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
upsert(id, data, options) {
|
|
151
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
152
|
-
this.create(data, Object.assign(Object.assign({}, options), { id, merge: true }));
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
delete(id, options) {
|
|
156
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
157
|
-
if (this.managerOptions.deleteMode === 'soft') {
|
|
158
|
-
yield this._update(id, Object.assign(Object.assign({}, {}), { [FirestoreMetadata_1.FIRESTORE_KEYS.DELETED]: true }), options);
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
return this.firestore.deleteDoc(this.firestore.doc(this.collection, id));
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
getRef(id) {
|
|
165
|
-
var _a;
|
|
166
|
-
if (!((_a = this.managerOptions) === null || _a === void 0 ? void 0 : _a.Reference))
|
|
167
|
-
throw new Error('ReferenceClass not defined');
|
|
168
|
-
if (this.refCache.has(id) && !this.managerOptions.disableCache) {
|
|
169
|
-
return this.refCache.get(id);
|
|
170
|
-
}
|
|
171
|
-
const newRef = new this.managerOptions.Reference(this.firestore, this.firestore.doc(this.collection, id), {
|
|
172
|
-
readMode: this.managerOptions.readMode,
|
|
173
|
-
errorInterceptor: this.managerOptions.errorInterceptor,
|
|
174
|
-
snapshotOptions: this.managerOptions.snapshotOptions,
|
|
175
|
-
});
|
|
176
|
-
if (!this.managerOptions.disableCache) {
|
|
177
|
-
this.refCache.set(id, newRef);
|
|
178
|
-
}
|
|
179
|
-
return newRef;
|
|
180
|
-
}
|
|
181
|
-
_getFilteredQuery(params) {
|
|
182
|
-
var _a, _b;
|
|
183
|
-
let compoundQuery = this.collectionQuery;
|
|
184
|
-
(_a = params === null || params === void 0 ? void 0 : params.filters) === null || _a === void 0 ? void 0 : _a.forEach(filter => {
|
|
185
|
-
compoundQuery = this.firestore.query(compoundQuery, this.firestore.where(filter[0], filter[1], filter[2]));
|
|
186
|
-
});
|
|
187
|
-
(_b = params === null || params === void 0 ? void 0 : params.orderBy) === null || _b === void 0 ? void 0 : _b.forEach(orderBy => {
|
|
188
|
-
compoundQuery = this.firestore.query(compoundQuery, this.firestore.orderBy(orderBy[0], orderBy[1]));
|
|
189
|
-
});
|
|
190
|
-
return compoundQuery;
|
|
191
|
-
}
|
|
192
|
-
getList(params) {
|
|
193
|
-
if (!this.managerOptions.List)
|
|
194
|
-
throw new Error('ListClass not defined');
|
|
195
|
-
const compoundQuery = this._getFilteredQuery(params);
|
|
196
|
-
const key = JSON.stringify(params || {});
|
|
197
|
-
if (this.listCache.has(key) && !this.managerOptions.disableCache) {
|
|
198
|
-
return this.listCache.get(key);
|
|
199
|
-
}
|
|
200
|
-
const newList = new this.managerOptions.List(this.firestore, compoundQuery, Object.assign({ readMode: this.managerOptions.readMode, errorInterceptor: this.managerOptions.errorInterceptor }, params));
|
|
201
|
-
if (!this.managerOptions.disableCache) {
|
|
202
|
-
this.listCache.set(key, newList);
|
|
203
|
-
}
|
|
204
|
-
return newList;
|
|
205
|
-
}
|
|
206
|
-
preventOverwriteOnCreate(docRef, createOptions) {
|
|
207
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
208
|
-
const doc = yield this.firestore.getDoc(docRef);
|
|
209
|
-
const docExists = (0, utils_1.checkIfReferenceExists)(doc);
|
|
210
|
-
if (docExists && this.managerOptions.preventOverwriteOnCreate && (createOptions === null || createOptions === void 0 ? void 0 : createOptions.merge) !== true) {
|
|
211
|
-
throw new Error(`Document already exists - ${doc.ref.path}`);
|
|
212
|
-
}
|
|
213
|
-
return docExists;
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
__setFunctionName(_classThis, "FirestoreDataManager");
|
|
218
|
-
(() => {
|
|
219
|
-
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
220
|
-
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
221
|
-
FirestoreDataManager = _classThis = _classDescriptor.value;
|
|
222
|
-
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
223
|
-
__runInitializers(_classThis, _classExtraInitializers);
|
|
224
|
-
})();
|
|
225
|
-
return FirestoreDataManager = _classThis;
|
|
226
|
-
})();
|
|
227
|
-
exports.FirestoreDataManager = FirestoreDataManager;
|
package/lib/FirestoreList.js
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.FirestoreList = void 0;
|
|
13
|
-
const datamanager_1 = require("@data-weave/datamanager");
|
|
14
|
-
class FirestoreList extends datamanager_1.LiveList {
|
|
15
|
-
constructor(firestore, query, options) {
|
|
16
|
-
super(options);
|
|
17
|
-
this.firestore = firestore;
|
|
18
|
-
this.query = query;
|
|
19
|
-
this.options = options;
|
|
20
|
-
}
|
|
21
|
-
resolve() {
|
|
22
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
var _a;
|
|
24
|
-
if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.readMode) === 'realtime') {
|
|
25
|
-
let initialLoad = true;
|
|
26
|
-
return new Promise((resolve, reject) => {
|
|
27
|
-
this.unsubscribeFromSnapshot = this.firestore.onSnapshot(this.query, querySnapshot => {
|
|
28
|
-
try {
|
|
29
|
-
if (initialLoad) {
|
|
30
|
-
initialLoad = false;
|
|
31
|
-
this.handleInitialDataChange(querySnapshot.docs);
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
// handle every change as inital dataload
|
|
35
|
-
this.handleInitialDataChange(querySnapshot.docs);
|
|
36
|
-
// this.handleSubsequentDataChanges(querySnapshot.docChanges())
|
|
37
|
-
}
|
|
38
|
-
// TODO: When calling ".resolve()" with realtime listener,
|
|
39
|
-
// the snapshot data might be stale from cache.
|
|
40
|
-
resolve(this.values);
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
this.onError(error);
|
|
44
|
-
reject(error);
|
|
45
|
-
}
|
|
46
|
-
}, error => {
|
|
47
|
-
this.onError(error);
|
|
48
|
-
reject(error);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
const snapshot = yield this.firestore.getDocs(this.query);
|
|
54
|
-
this.handleInitialDataChange(snapshot.docs);
|
|
55
|
-
return this.values;
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
handleInitialDataChange(values) {
|
|
60
|
-
const newValues = values.map(v => v.data());
|
|
61
|
-
this.onUpdateAll(newValues);
|
|
62
|
-
}
|
|
63
|
-
handleSubsequentDataChanges(changes) {
|
|
64
|
-
changes.forEach(change => {
|
|
65
|
-
if (change.type === 'added') {
|
|
66
|
-
this.onAddAtIndex(change.newIndex, change.doc.data());
|
|
67
|
-
}
|
|
68
|
-
else if (change.type === 'modified') {
|
|
69
|
-
this.onUpdateAtIndex(change.newIndex, change.doc.data());
|
|
70
|
-
}
|
|
71
|
-
else if (change.type === 'removed') {
|
|
72
|
-
this.onRemoveAtIndex(change.oldIndex);
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
// TODO: handle onUpdate in the parent class - make sure it's only called once after all changes are processed
|
|
76
|
-
this.onUpdate();
|
|
77
|
-
}
|
|
78
|
-
unSubscribe() {
|
|
79
|
-
var _a;
|
|
80
|
-
(_a = this.unsubscribeFromSnapshot) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
81
|
-
this.setStale();
|
|
82
|
-
}
|
|
83
|
-
onError(error) {
|
|
84
|
-
var _a, _b, _c, _d, _e;
|
|
85
|
-
// Try to provide useful collection details using internal properties
|
|
86
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
87
|
-
console.error(`FirestoreList Collection: ${(_b = (_a = this.query) === null || _a === void 0 ? void 0 : _a._collectionPath) === null || _b === void 0 ? void 0 : _b.id} error`, error);
|
|
88
|
-
(_d = (_c = this.options) === null || _c === void 0 ? void 0 : _c.errorInterceptor) === null || _d === void 0 ? void 0 : _d.call(_c, error, {
|
|
89
|
-
query: this.query,
|
|
90
|
-
readMode: (_e = this.options) === null || _e === void 0 ? void 0 : _e.readMode,
|
|
91
|
-
type: 'list',
|
|
92
|
-
});
|
|
93
|
-
super.onError(error);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
exports.FirestoreList = FirestoreList;
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.FirestoreReference = void 0;
|
|
13
|
-
const datamanager_1 = require("@data-weave/datamanager");
|
|
14
|
-
const utils_1 = require("./utils");
|
|
15
|
-
class FirestoreReference extends datamanager_1.LiveReference {
|
|
16
|
-
constructor(firestore, docRef, options) {
|
|
17
|
-
super(options);
|
|
18
|
-
this.firestore = firestore;
|
|
19
|
-
this.docRef = docRef;
|
|
20
|
-
this.options = options;
|
|
21
|
-
}
|
|
22
|
-
resolve() {
|
|
23
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
var _a;
|
|
25
|
-
if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.readMode) === 'realtime') {
|
|
26
|
-
return new Promise((res, reject) => {
|
|
27
|
-
this.unsubscribeFromSnapshot = this.firestore.onSnapshot(this.docRef, documentSnapshot => {
|
|
28
|
-
try {
|
|
29
|
-
this.onUpdate(this.parseDocumentSnapshot(documentSnapshot));
|
|
30
|
-
// TODO: When calling ".resolve()" with realtime listener,
|
|
31
|
-
// the snapshot data might be stale from cache.
|
|
32
|
-
res(this.value);
|
|
33
|
-
}
|
|
34
|
-
catch (error) {
|
|
35
|
-
this.onError(error);
|
|
36
|
-
reject(error);
|
|
37
|
-
}
|
|
38
|
-
}, error => {
|
|
39
|
-
this.onError(error);
|
|
40
|
-
reject(error);
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
try {
|
|
45
|
-
const doc = yield this.firestore.getDoc(this.docRef);
|
|
46
|
-
this.onUpdate(this.parseDocumentSnapshot(doc));
|
|
47
|
-
}
|
|
48
|
-
catch (error) {
|
|
49
|
-
this.onError(error);
|
|
50
|
-
throw error;
|
|
51
|
-
}
|
|
52
|
-
return this.value;
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
get id() {
|
|
56
|
-
return this.docRef.id;
|
|
57
|
-
}
|
|
58
|
-
get path() {
|
|
59
|
-
return this.docRef.path;
|
|
60
|
-
}
|
|
61
|
-
onError(error) {
|
|
62
|
-
var _a, _b, _c, _d;
|
|
63
|
-
console.error(`FirestoreReference error ${this.docRef.path}`, error);
|
|
64
|
-
(_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.errorInterceptor) === null || _b === void 0 ? void 0 : _b.call(_a, error, {
|
|
65
|
-
path: this.docRef.path,
|
|
66
|
-
id: this.docRef.id,
|
|
67
|
-
readMode: (_c = this.options) === null || _c === void 0 ? void 0 : _c.readMode,
|
|
68
|
-
snapshotOptions: (_d = this.options) === null || _d === void 0 ? void 0 : _d.snapshotOptions,
|
|
69
|
-
type: 'reference',
|
|
70
|
-
});
|
|
71
|
-
super.onError(error);
|
|
72
|
-
}
|
|
73
|
-
unSubscribe() {
|
|
74
|
-
var _a;
|
|
75
|
-
(_a = this.unsubscribeFromSnapshot) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
76
|
-
this.setStale();
|
|
77
|
-
}
|
|
78
|
-
parseDocumentSnapshot(docSnapshot) {
|
|
79
|
-
var _a;
|
|
80
|
-
if (!(0, utils_1.checkIfReferenceExists)(docSnapshot))
|
|
81
|
-
throw new Error(`Document does not exist ${this.docRef.path}`);
|
|
82
|
-
return docSnapshot.data((_a = this.options) === null || _a === void 0 ? void 0 : _a.snapshotOptions);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
exports.FirestoreReference = FirestoreReference;
|
package/lib/firestoreTypes.js
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
3
|
-
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
4
|
-
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
5
|
-
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
6
|
-
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
7
|
-
var _, done = false;
|
|
8
|
-
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
9
|
-
var context = {};
|
|
10
|
-
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
11
|
-
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
12
|
-
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
13
|
-
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
14
|
-
if (kind === "accessor") {
|
|
15
|
-
if (result === void 0) continue;
|
|
16
|
-
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
17
|
-
if (_ = accept(result.get)) descriptor.get = _;
|
|
18
|
-
if (_ = accept(result.set)) descriptor.set = _;
|
|
19
|
-
if (_ = accept(result.init)) initializers.unshift(_);
|
|
20
|
-
}
|
|
21
|
-
else if (_ = accept(result)) {
|
|
22
|
-
if (kind === "field") initializers.unshift(_);
|
|
23
|
-
else descriptor[key] = _;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
27
|
-
done = true;
|
|
28
|
-
};
|
|
29
|
-
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
30
|
-
var useValue = arguments.length > 2;
|
|
31
|
-
for (var i = 0; i < initializers.length; i++) {
|
|
32
|
-
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
33
|
-
}
|
|
34
|
-
return useValue ? value : void 0;
|
|
35
|
-
};
|
|
36
|
-
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
|
|
37
|
-
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
|
38
|
-
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
|
39
|
-
};
|
|
40
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
-
exports.DummyFirestoreFunctions = exports.FirestoreFunctions = exports.FirestoreSettings = exports.Firestore = exports.FirestoreApp = exports.FieldValues = void 0;
|
|
42
|
-
const inversify_1 = require("inversify");
|
|
43
|
-
class FieldValues {
|
|
44
|
-
}
|
|
45
|
-
exports.FieldValues = FieldValues;
|
|
46
|
-
class FirestoreApp {
|
|
47
|
-
}
|
|
48
|
-
exports.FirestoreApp = FirestoreApp;
|
|
49
|
-
let Firestore = (() => {
|
|
50
|
-
let _classDecorators = [(0, inversify_1.injectable)()];
|
|
51
|
-
let _classDescriptor;
|
|
52
|
-
let _classExtraInitializers = [];
|
|
53
|
-
let _classThis;
|
|
54
|
-
var Firestore = _classThis = class {
|
|
55
|
-
};
|
|
56
|
-
__setFunctionName(_classThis, "Firestore");
|
|
57
|
-
(() => {
|
|
58
|
-
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
59
|
-
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
60
|
-
Firestore = _classThis = _classDescriptor.value;
|
|
61
|
-
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
62
|
-
__runInitializers(_classThis, _classExtraInitializers);
|
|
63
|
-
})();
|
|
64
|
-
return Firestore = _classThis;
|
|
65
|
-
})();
|
|
66
|
-
exports.Firestore = Firestore;
|
|
67
|
-
let FirestoreSettings = (() => {
|
|
68
|
-
let _classDecorators = [(0, inversify_1.injectable)()];
|
|
69
|
-
let _classDescriptor;
|
|
70
|
-
let _classExtraInitializers = [];
|
|
71
|
-
let _classThis;
|
|
72
|
-
var FirestoreSettings = _classThis = class {
|
|
73
|
-
};
|
|
74
|
-
__setFunctionName(_classThis, "FirestoreSettings");
|
|
75
|
-
(() => {
|
|
76
|
-
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
77
|
-
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
78
|
-
FirestoreSettings = _classThis = _classDescriptor.value;
|
|
79
|
-
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
80
|
-
__runInitializers(_classThis, _classExtraInitializers);
|
|
81
|
-
})();
|
|
82
|
-
return FirestoreSettings = _classThis;
|
|
83
|
-
})();
|
|
84
|
-
exports.FirestoreSettings = FirestoreSettings;
|
|
85
|
-
let FirestoreFunctions = (() => {
|
|
86
|
-
let _classDecorators = [(0, inversify_1.injectable)()];
|
|
87
|
-
let _classDescriptor;
|
|
88
|
-
let _classExtraInitializers = [];
|
|
89
|
-
let _classThis;
|
|
90
|
-
var FirestoreFunctions = _classThis = class {
|
|
91
|
-
};
|
|
92
|
-
__setFunctionName(_classThis, "FirestoreFunctions");
|
|
93
|
-
(() => {
|
|
94
|
-
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
95
|
-
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
96
|
-
FirestoreFunctions = _classThis = _classDescriptor.value;
|
|
97
|
-
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
98
|
-
__runInitializers(_classThis, _classExtraInitializers);
|
|
99
|
-
})();
|
|
100
|
-
return FirestoreFunctions = _classThis;
|
|
101
|
-
})();
|
|
102
|
-
exports.FirestoreFunctions = FirestoreFunctions;
|
|
103
|
-
let DummyFirestoreFunctions = (() => {
|
|
104
|
-
let _classDecorators = [(0, inversify_1.injectable)()];
|
|
105
|
-
let _classDescriptor;
|
|
106
|
-
let _classExtraInitializers = [];
|
|
107
|
-
let _classThis;
|
|
108
|
-
var DummyFirestoreFunctions = _classThis = class {
|
|
109
|
-
httpsCallable() {
|
|
110
|
-
return () => {
|
|
111
|
-
throw new Error('httpsCallable not implemented - DummyFirestoreFunctions');
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
useEmulator() { }
|
|
115
|
-
useFunctionsEmulator() { }
|
|
116
|
-
};
|
|
117
|
-
__setFunctionName(_classThis, "DummyFirestoreFunctions");
|
|
118
|
-
(() => {
|
|
119
|
-
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
120
|
-
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
121
|
-
DummyFirestoreFunctions = _classThis = _classDescriptor.value;
|
|
122
|
-
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
123
|
-
__runInitializers(_classThis, _classExtraInitializers);
|
|
124
|
-
})();
|
|
125
|
-
return DummyFirestoreFunctions = _classThis;
|
|
126
|
-
})();
|
|
127
|
-
exports.DummyFirestoreFunctions = DummyFirestoreFunctions;
|
package/lib/version.d.ts
DELETED
package/lib/version.js
DELETED