firetender 0.9.4 → 0.10.0
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/FiretenderCollection.d.ts +6 -5
- package/dist/FiretenderCollection.js +18 -12
- package/dist/FiretenderCollection.js.map +1 -1
- package/dist/FiretenderDoc.d.ts +1 -1
- package/dist/FiretenderDoc.js +22 -20
- package/dist/FiretenderDoc.js.map +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/firestore-deps-admin.d.ts +26 -0
- package/dist/firestore-deps-admin.js +62 -0
- package/dist/firestore-deps-admin.js.map +1 -0
- package/dist/firestore-deps-web.d.ts +10 -0
- package/dist/firestore-deps-web.js +29 -0
- package/dist/firestore-deps-web.js.map +1 -0
- package/dist/firestore-deps.d.ts +10 -0
- package/dist/firestore-deps.js +29 -0
- package/dist/firestore-deps.js.map +1 -0
- package/dist/proxies.js +3 -3
- package/dist/proxies.js.map +1 -1
- package/dist/timestamps.d.ts +1 -1
- package/dist/timestamps.js +6 -7
- package/dist/timestamps.js.map +1 -1
- package/package.json +7 -2
- package/src/FiretenderCollection.ts +21 -11
- package/src/FiretenderDoc.ts +24 -25
- package/src/errors.ts +1 -1
- package/src/firestore-deps-admin.ts +111 -0
- package/src/firestore-deps-web.ts +14 -0
- package/src/firestore-deps.ts +14 -0
- package/src/proxies.ts +1 -1
- package/src/timestamps.ts +5 -5
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CollectionReference, DocumentReference, Firestore, QueryConstraint } from "firebase/firestore";
|
|
2
1
|
import { z } from "zod";
|
|
2
|
+
import { CollectionReference, DocumentReference, Firestore, QueryConstraint } from "./firestore-deps";
|
|
3
3
|
import { FiretenderDoc, FiretenderDocOptions } from "./FiretenderDoc";
|
|
4
4
|
import { DeepPartial } from "./ts-helpers";
|
|
5
5
|
/**
|
|
@@ -16,17 +16,18 @@ export declare class FiretenderCollection<SchemaType extends z.SomeZodObject> {
|
|
|
16
16
|
readonly firestore: Firestore;
|
|
17
17
|
/** The collection path of this object: a series of collection names */
|
|
18
18
|
readonly collectionPath: string[];
|
|
19
|
-
/**
|
|
20
|
-
readonly
|
|
19
|
+
/** Function to return the initial values when creating a new document. */
|
|
20
|
+
readonly baseInitialDataFactory: (() => DeepPartial<z.input<SchemaType>>) | undefined;
|
|
21
21
|
/**
|
|
22
22
|
* @param schema the Zod object schema describing the documents in this
|
|
23
23
|
* collection.
|
|
24
24
|
* @param firestore the thing you get from getFirestore().
|
|
25
25
|
* @param collectionPath the path of this collection in Firestore: the names
|
|
26
26
|
* of any parent collections and of this collection.
|
|
27
|
-
* @param baseInitialData (optional)
|
|
27
|
+
* @param baseInitialData (optional) an object or object factory providing
|
|
28
|
+
* default field values for this collection.
|
|
28
29
|
*/
|
|
29
|
-
constructor(schema: SchemaType, firestore: Firestore, collectionPath: [string, ...string[]] | string, baseInitialData?: DeepPartial<z.input<SchemaType>> | undefined);
|
|
30
|
+
constructor(schema: SchemaType, firestore: Firestore, collectionPath: [string, ...string[]] | string, baseInitialData?: (() => DeepPartial<z.input<SchemaType>>) | DeepPartial<z.input<SchemaType>> | undefined);
|
|
30
31
|
/**
|
|
31
32
|
* Returns a FiretenderDoc representing a new document in this collection.
|
|
32
33
|
*
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FiretenderCollection = void 0;
|
|
4
|
-
const firestore_1 = require("firebase/firestore");
|
|
5
4
|
const errors_1 = require("./errors");
|
|
5
|
+
const firestore_deps_1 = require("./firestore-deps");
|
|
6
6
|
const FiretenderDoc_1 = require("./FiretenderDoc");
|
|
7
7
|
/**
|
|
8
8
|
* A representation of a Firestore collection or subcollection.
|
|
@@ -18,14 +18,20 @@ class FiretenderCollection {
|
|
|
18
18
|
* @param firestore the thing you get from getFirestore().
|
|
19
19
|
* @param collectionPath the path of this collection in Firestore: the names
|
|
20
20
|
* of any parent collections and of this collection.
|
|
21
|
-
* @param baseInitialData (optional)
|
|
21
|
+
* @param baseInitialData (optional) an object or object factory providing
|
|
22
|
+
* default field values for this collection.
|
|
22
23
|
*/
|
|
23
24
|
constructor(schema, firestore, collectionPath, baseInitialData = undefined) {
|
|
24
25
|
this.schema = schema;
|
|
25
26
|
this.firestore = firestore;
|
|
26
27
|
this.collectionPath = [collectionPath].flat();
|
|
27
28
|
if (baseInitialData) {
|
|
28
|
-
|
|
29
|
+
if (typeof baseInitialData === "function") {
|
|
30
|
+
this.baseInitialDataFactory = baseInitialData;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
this.baseInitialDataFactory = () => baseInitialData;
|
|
34
|
+
}
|
|
29
35
|
}
|
|
30
36
|
}
|
|
31
37
|
/**
|
|
@@ -52,8 +58,8 @@ class FiretenderCollection {
|
|
|
52
58
|
throw new errors_1.FiretenderUsageError("newDoc() requires an ID path for all collections and subcollections, except optionally the last.");
|
|
53
59
|
}
|
|
54
60
|
const data = {};
|
|
55
|
-
if (this.
|
|
56
|
-
Object.assign(data, this.
|
|
61
|
+
if (this.baseInitialDataFactory) {
|
|
62
|
+
Object.assign(data, this.baseInitialDataFactory());
|
|
57
63
|
}
|
|
58
64
|
if (initialData) {
|
|
59
65
|
Object.assign(data, initialData);
|
|
@@ -121,9 +127,9 @@ class FiretenderCollection {
|
|
|
121
127
|
}
|
|
122
128
|
let ref = this.makeCollectionRefInternal(ids);
|
|
123
129
|
if (!ref) {
|
|
124
|
-
ref = (0,
|
|
130
|
+
ref = (0, firestore_deps_1.collectionGroup)(this.firestore, this.collectionPath[this.collectionPath.length - 1]);
|
|
125
131
|
}
|
|
126
|
-
return this.getAndWrapDocs((0,
|
|
132
|
+
return this.getAndWrapDocs((0, firestore_deps_1.query)(ref, ...whereClauses));
|
|
127
133
|
}
|
|
128
134
|
/**
|
|
129
135
|
* Deletes the given document from this collection.
|
|
@@ -141,7 +147,7 @@ class FiretenderCollection {
|
|
|
141
147
|
throw new errors_1.FiretenderUsageError("delete() requires the full ID path of the target document.");
|
|
142
148
|
}
|
|
143
149
|
try {
|
|
144
|
-
await (0,
|
|
150
|
+
await (0, firestore_deps_1.deleteDoc)(ref);
|
|
145
151
|
}
|
|
146
152
|
catch (error) {
|
|
147
153
|
(0, errors_1.addContextToError)(error, "deleteDoc", ref);
|
|
@@ -184,7 +190,7 @@ class FiretenderCollection {
|
|
|
184
190
|
return undefined;
|
|
185
191
|
}
|
|
186
192
|
const path = ids.flatMap((id, i) => [this.collectionPath[i], id]);
|
|
187
|
-
return (0,
|
|
193
|
+
return (0, firestore_deps_1.doc)(this.firestore, path[0], ...path.slice(1));
|
|
188
194
|
}
|
|
189
195
|
/**
|
|
190
196
|
* Builds a collection ref from the given IDs, or returns "undefined" if the
|
|
@@ -195,7 +201,7 @@ class FiretenderCollection {
|
|
|
195
201
|
return undefined;
|
|
196
202
|
}
|
|
197
203
|
const subPath = ids.flatMap((id, i) => [id, this.collectionPath[i + 1]]);
|
|
198
|
-
return (0,
|
|
204
|
+
return (0, firestore_deps_1.collection)(this.firestore, this.collectionPath[0], ...subPath);
|
|
199
205
|
}
|
|
200
206
|
/**
|
|
201
207
|
* Executes the given query and returns an array of the results, wrapped in
|
|
@@ -204,10 +210,10 @@ class FiretenderCollection {
|
|
|
204
210
|
async getAndWrapDocs(query) {
|
|
205
211
|
let querySnapshot;
|
|
206
212
|
try {
|
|
207
|
-
querySnapshot = await (0,
|
|
213
|
+
querySnapshot = await (0, firestore_deps_1.getDocs)(query);
|
|
208
214
|
}
|
|
209
215
|
catch (error) {
|
|
210
|
-
(0, errors_1.addContextToError)(error, "getDocs", query instanceof
|
|
216
|
+
(0, errors_1.addContextToError)(error, "getDocs", query instanceof firestore_deps_1.CollectionReference ? query : undefined);
|
|
211
217
|
throw error;
|
|
212
218
|
}
|
|
213
219
|
return querySnapshot.docs.map((queryDoc) => new FiretenderDoc_1.FiretenderDoc(this.schema, queryDoc.ref, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FiretenderCollection.js","sourceRoot":"","sources":["../src/FiretenderCollection.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"FiretenderCollection.js","sourceRoot":"","sources":["../src/FiretenderCollection.ts"],"names":[],"mappings":";;;AAEA,qCAAmE;AACnE,qDAa0B;AAC1B,mDAAsE;AAGtE;;;;;;GAMG;AACH,MAAa,oBAAoB;IAe/B;;;;;;;;OAQG;IACH,YACE,MAAkB,EAClB,SAAoB,EACpB,cAA8C,EAC9C,kBAGgB,SAAS;QAEzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,cAAc,GAAG,CAAC,cAAc,CAAC,CAAC,IAAI,EAAE,CAAC;QAC9C,IAAI,eAAe,EAAE;YACnB,IAAI,OAAO,eAAe,KAAK,UAAU,EAAE;gBACzC,IAAI,CAAC,sBAAsB,GAAG,eAAe,CAAC;aAC/C;iBAAM;gBACL,IAAI,CAAC,sBAAsB,GAAG,GAAG,EAAE,CAAC,eAAe,CAAC;aACrD;SACF;IACH,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,MAAM,CACJ,KAAoC,SAAS,EAC7C,cAA4D,SAAS,EACrE,UAAgC,EAAE;QAElC,MAAM,GAAG,GAAG,EAAE,YAAY,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACtD,IAAI,GAAG,GACL,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC;QAC/B,IAAI,CAAC,GAAG,EAAE;YACR,GAAG,GAAG,IAAI,CAAC,yBAAyB,CAAC,GAAG,CAAC,CAAC;SAC3C;QACD,IAAI,CAAC,GAAG,EAAE;YACR,MAAM,IAAI,6BAAoB,CAC5B,kGAAkG,CACnG,CAAC;SACH;QACD,MAAM,IAAI,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,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACxD,CAAC;IAED;;;OAGG;IACK,yBAAyB,CAC/B,GAAa;QAEb,IAAI,GAAG,CAAC,MAAM,KAAK,IAAI,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE;YACjD,OAAO,SAAS,CAAC;SAClB;QACD,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACzE,OAAO,IAAA,2BAAU,EAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,CAAC,CAAC;IACxE,CAAC;IAED;;;OAGG;IACK,KAAK,CAAC,cAAc,CAC1B,KAAkC;QAElC,IAAI,aAA4B,CAAC;QACjC,IAAI;YACF,aAAa,GAAG,MAAM,IAAA,wBAAO,EAAC,KAAK,CAAC,CAAC;SACtC;QAAC,OAAO,KAAK,EAAE;YACd,IAAA,0BAAiB,EACf,KAAK,EACL,SAAS,EACT,KAAK,YAAY,oCAAmB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CACzD,CAAC;YACF,MAAM,KAAK,CAAC;SACb;QACD,OAAO,aAAa,CAAC,IAAI,CAAC,GAAG,CAC3B,CAAC,QAAQ,EAAE,EAAE,CACX,IAAI,6BAAa,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,EAAE;YAC3C,WAAW,EAAE,QAAQ,CAAC,IAAI,EAAE;SAC7B,CAAC,CACL,CAAC;IACJ,CAAC;CACF;AA3RD,oDA2RC"}
|
package/dist/FiretenderDoc.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CollectionReference, DocumentReference } from "firebase/firestore";
|
|
2
1
|
import { z } from "zod";
|
|
2
|
+
import { CollectionReference, DocumentReference } from "./firestore-deps";
|
|
3
3
|
import { DeepReadonly } from "./ts-helpers";
|
|
4
4
|
/**
|
|
5
5
|
* Public options for initializing a FiretenderDoc object.
|
package/dist/FiretenderDoc.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FiretenderDoc = void 0;
|
|
4
|
-
const firestore_1 = require("firebase/firestore");
|
|
5
4
|
const errors_1 = require("./errors");
|
|
5
|
+
const firestore_deps_1 = require("./firestore-deps");
|
|
6
6
|
const proxies_1 = require("./proxies");
|
|
7
7
|
const ts_helpers_1 = require("./ts-helpers");
|
|
8
8
|
/**
|
|
@@ -36,7 +36,7 @@ class FiretenderDoc {
|
|
|
36
36
|
else if (this.isNewDoc) {
|
|
37
37
|
throw ReferenceError("Initial data must be given when creating a new doc.");
|
|
38
38
|
}
|
|
39
|
-
if (this.ref
|
|
39
|
+
if (this.ref instanceof firestore_deps_1.DocumentReference) {
|
|
40
40
|
this.docID = this.ref.path.split("/").pop();
|
|
41
41
|
}
|
|
42
42
|
else if (!this.isNewDoc) {
|
|
@@ -96,8 +96,8 @@ class FiretenderDoc {
|
|
|
96
96
|
throw new errors_1.FiretenderUsageError("You must call load() before making a copy.");
|
|
97
97
|
}
|
|
98
98
|
let ref;
|
|
99
|
-
if (dest instanceof
|
|
100
|
-
dest instanceof
|
|
99
|
+
if (dest instanceof firestore_deps_1.DocumentReference ||
|
|
100
|
+
dest instanceof firestore_deps_1.CollectionReference) {
|
|
101
101
|
ref = dest;
|
|
102
102
|
}
|
|
103
103
|
else if (Array.isArray(dest)) {
|
|
@@ -116,14 +116,14 @@ class FiretenderDoc {
|
|
|
116
116
|
});
|
|
117
117
|
ref =
|
|
118
118
|
dest.length === collectionDepth
|
|
119
|
-
? (0,
|
|
120
|
-
: (0,
|
|
119
|
+
? (0, firestore_deps_1.doc)(this.ref.firestore, path[0], ...path.slice(1))
|
|
120
|
+
: (0, firestore_deps_1.collection)(this.ref.firestore, path[0], ...path.slice(1));
|
|
121
121
|
}
|
|
122
122
|
else {
|
|
123
123
|
// For a string or undefined ...
|
|
124
|
-
const collectionRef = this.ref
|
|
124
|
+
const collectionRef = this.ref instanceof firestore_deps_1.DocumentReference ? this.ref.parent : this.ref;
|
|
125
125
|
if (dest) {
|
|
126
|
-
ref = (0,
|
|
126
|
+
ref = (0, firestore_deps_1.doc)(collectionRef, dest);
|
|
127
127
|
}
|
|
128
128
|
else {
|
|
129
129
|
ref = collectionRef;
|
|
@@ -153,7 +153,7 @@ class FiretenderDoc {
|
|
|
153
153
|
* @throws Throws an error if the document does not yet have a reference.
|
|
154
154
|
*/
|
|
155
155
|
get docRef() {
|
|
156
|
-
if (this.ref
|
|
156
|
+
if (!(this.ref instanceof firestore_deps_1.DocumentReference)) {
|
|
157
157
|
throw new errors_1.FiretenderUsageError("docRef can only be accessed after the new doc has been written.");
|
|
158
158
|
}
|
|
159
159
|
return this.ref;
|
|
@@ -184,7 +184,7 @@ class FiretenderDoc {
|
|
|
184
184
|
* the document already contains data.
|
|
185
185
|
*/
|
|
186
186
|
async load(force = false) {
|
|
187
|
-
if (this.isNewDoc || this.ref
|
|
187
|
+
if (this.isNewDoc || this.ref instanceof firestore_deps_1.CollectionReference) {
|
|
188
188
|
throw new errors_1.FiretenderUsageError("load() should not be called for new documents.");
|
|
189
189
|
}
|
|
190
190
|
if (!this.data || force) {
|
|
@@ -198,13 +198,16 @@ class FiretenderDoc {
|
|
|
198
198
|
this.resolvesWaitingForLoad = [];
|
|
199
199
|
let snapshot;
|
|
200
200
|
try {
|
|
201
|
-
snapshot = await (0,
|
|
201
|
+
snapshot = await (0, firestore_deps_1.getDoc)(this.ref);
|
|
202
202
|
}
|
|
203
203
|
catch (error) {
|
|
204
204
|
(0, errors_1.addContextToError)(error, "getDoc", this.ref);
|
|
205
205
|
throw error;
|
|
206
206
|
}
|
|
207
|
-
|
|
207
|
+
// DocumentSnapshot.prototype.exists is a boolean for
|
|
208
|
+
// "firebase-admin/firestore" and a function for "firebase/firestore".
|
|
209
|
+
if ((typeof snapshot.exists === "boolean" && !snapshot.exists) ||
|
|
210
|
+
(typeof snapshot.exists === "function" && !snapshot.exists())) {
|
|
208
211
|
const error = new errors_1.FiretenderIOError(`Document does not exist: "${this.ref.path}"`);
|
|
209
212
|
this.resolvesWaitingForLoad.forEach((wait) => wait.reject(error));
|
|
210
213
|
throw error;
|
|
@@ -262,9 +265,9 @@ class FiretenderDoc {
|
|
|
262
265
|
// For new docs, this.data should contain its initial state.
|
|
263
266
|
if (this.isSettingNewContents) {
|
|
264
267
|
(0, ts_helpers_1.assertIsDefined)(this.data);
|
|
265
|
-
if (this.ref
|
|
268
|
+
if (this.ref instanceof firestore_deps_1.DocumentReference) {
|
|
266
269
|
try {
|
|
267
|
-
await (0,
|
|
270
|
+
await (0, firestore_deps_1.setDoc)(this.ref, this.data);
|
|
268
271
|
}
|
|
269
272
|
catch (error) {
|
|
270
273
|
(0, errors_1.addContextToError)(error, "setDoc", this.ref, this.data);
|
|
@@ -273,7 +276,7 @@ class FiretenderDoc {
|
|
|
273
276
|
}
|
|
274
277
|
else {
|
|
275
278
|
try {
|
|
276
|
-
this.ref = await (0,
|
|
279
|
+
this.ref = await (0, firestore_deps_1.addDoc)(this.ref, this.data);
|
|
277
280
|
}
|
|
278
281
|
catch (error) {
|
|
279
282
|
(0, errors_1.addContextToError)(error, "addDoc", this.ref, this.data);
|
|
@@ -286,18 +289,17 @@ class FiretenderDoc {
|
|
|
286
289
|
}
|
|
287
290
|
// For existing docs, this.updates should contain a list of changes.
|
|
288
291
|
else {
|
|
289
|
-
if (!(this.ref
|
|
292
|
+
if (!(this.ref instanceof firestore_deps_1.DocumentReference)) {
|
|
290
293
|
// We should never get here.
|
|
291
294
|
throw new errors_1.FiretenderInternalError("Internal error. Firetender object should always reference a document when updating an existing doc.");
|
|
292
295
|
}
|
|
293
296
|
if (this.updates.size > 0) {
|
|
294
|
-
|
|
295
|
-
const flatUpdateList = Array.from(this.updates.entries()).flat();
|
|
297
|
+
const updateData = Object.fromEntries(this.updates);
|
|
296
298
|
try {
|
|
297
|
-
await (0,
|
|
299
|
+
await (0, firestore_deps_1.updateDoc)(this.ref, updateData);
|
|
298
300
|
}
|
|
299
301
|
catch (error) {
|
|
300
|
-
(0, errors_1.addContextToError)(error, "updateDoc", this.ref,
|
|
302
|
+
(0, errors_1.addContextToError)(error, "updateDoc", this.ref, updateData);
|
|
301
303
|
throw error;
|
|
302
304
|
}
|
|
303
305
|
this.updates.clear();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FiretenderDoc.js","sourceRoot":"","sources":["../src/FiretenderDoc.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"FiretenderDoc.js","sourceRoot":"","sources":["../src/FiretenderDoc.ts"],"names":[],"mappings":";;;AAEA,qCAKkB;AAClB,qDAU0B;AAC1B,uCAAiD;AACjD,6CAA6D;AA8B7D;;GAEG;AACH,MAAa,aAAa;IAiCxB;;;;;;;OAOG;IACH,YACE,MAAkB,EAClB,GAA4C,EAC5C,UAAmC,EAAE;QArCvC,yEAAyE;QACjE,UAAK,GAAuB,SAAS,CAAC;QAQ9C,gEAAgE;QACxD,SAAI,GAAoC,SAAS,CAAC;QAE1D,6EAA6E;QACrE,cAAS,GAAkD,SAAS,CAAC;QAE7E,2EAA2E;QACnE,YAAO,GAAG,IAAI,GAAG,EAAe,CAAC;QAuBvC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,SAAS,IAAI,KAAK,CAAC;QAC3C,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC1C,IAAI,OAAO,CAAC,WAAW,EAAE;YACvB,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,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,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IACzC,CAAC;CACF;AA7aD,sCA6aC"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provides all dependencies normally imported from "firebase/firestore".
|
|
3
|
+
*
|
|
4
|
+
* For web clients, the "firebase/firestore" API is simply re-exported.
|
|
5
|
+
*
|
|
6
|
+
* For the server client API, ...
|
|
7
|
+
*/
|
|
8
|
+
import { CollectionGroup, CollectionReference, DocumentReference, DocumentSnapshot, FieldValue, Filter, Firestore, Query, QuerySnapshot, Timestamp, UpdateData, WithFieldValue } from "@google-cloud/firestore";
|
|
9
|
+
export declare const FIRESTORE_DEPS_TYPE: "web" | "admin";
|
|
10
|
+
export { CollectionReference, DocumentReference, DocumentSnapshot, Firestore, Query, QuerySnapshot, Timestamp, };
|
|
11
|
+
export type QueryConstraint = Filter;
|
|
12
|
+
export declare const where: typeof Filter.where;
|
|
13
|
+
export declare const arrayRemove: typeof FieldValue.arrayRemove;
|
|
14
|
+
export declare const deleteField: typeof FieldValue.delete;
|
|
15
|
+
export declare const serverTimestamp: typeof FieldValue.serverTimestamp;
|
|
16
|
+
export declare const isServerTimestamp: (x: any) => boolean;
|
|
17
|
+
export declare const addDoc: <T>(ref: CollectionReference<T>, data: WithFieldValue<T>) => Promise<DocumentReference<T>>;
|
|
18
|
+
export declare const collection: (firestoreOrRef: Firestore | CollectionReference, path: string, ...pathSegments: string[]) => CollectionReference;
|
|
19
|
+
export declare const collectionGroup: (firestore: Firestore, collectionID: string) => CollectionGroup;
|
|
20
|
+
export declare const deleteDoc: (ref: DocumentReference<unknown>) => Promise<void>;
|
|
21
|
+
export declare const doc: (firestoreOrRef: Firestore | CollectionReference, path?: string, ...pathSegments: string[]) => DocumentReference;
|
|
22
|
+
export declare const getDoc: <T>(ref: DocumentReference<T>) => Promise<DocumentSnapshot<T>>;
|
|
23
|
+
export declare const getDocs: <T>(query: Query<T>) => Promise<QuerySnapshot<T>>;
|
|
24
|
+
export declare const query: <T>(ref: Query<T>, ...queryConstraints: QueryConstraint[]) => Query<T>;
|
|
25
|
+
export declare const setDoc: <T>(ref: DocumentReference<T>, data: WithFieldValue<T>) => Promise<void>;
|
|
26
|
+
export declare const updateDoc: <T>(ref: DocumentReference<T>, data: UpdateData<T>) => Promise<void>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Provides all dependencies normally imported from "firebase/firestore".
|
|
4
|
+
*
|
|
5
|
+
* For web clients, the "firebase/firestore" API is simply re-exported.
|
|
6
|
+
*
|
|
7
|
+
* For the server client API, ...
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.updateDoc = exports.setDoc = exports.query = exports.getDocs = exports.getDoc = exports.doc = exports.deleteDoc = exports.collectionGroup = exports.collection = exports.addDoc = exports.isServerTimestamp = exports.serverTimestamp = exports.deleteField = exports.arrayRemove = exports.where = exports.Timestamp = exports.QuerySnapshot = exports.Query = exports.Firestore = exports.DocumentSnapshot = exports.DocumentReference = exports.CollectionReference = exports.FIRESTORE_DEPS_TYPE = void 0;
|
|
11
|
+
const firestore_1 = require("@google-cloud/firestore");
|
|
12
|
+
Object.defineProperty(exports, "CollectionReference", { enumerable: true, get: function () { return firestore_1.CollectionReference; } });
|
|
13
|
+
Object.defineProperty(exports, "DocumentReference", { enumerable: true, get: function () { return firestore_1.DocumentReference; } });
|
|
14
|
+
Object.defineProperty(exports, "DocumentSnapshot", { enumerable: true, get: function () { return firestore_1.DocumentSnapshot; } });
|
|
15
|
+
Object.defineProperty(exports, "Firestore", { enumerable: true, get: function () { return firestore_1.Firestore; } });
|
|
16
|
+
Object.defineProperty(exports, "Query", { enumerable: true, get: function () { return firestore_1.Query; } });
|
|
17
|
+
Object.defineProperty(exports, "QuerySnapshot", { enumerable: true, get: function () { return firestore_1.QuerySnapshot; } });
|
|
18
|
+
Object.defineProperty(exports, "Timestamp", { enumerable: true, get: function () { return firestore_1.Timestamp; } });
|
|
19
|
+
exports.FIRESTORE_DEPS_TYPE = "admin";
|
|
20
|
+
exports.where = firestore_1.Filter.where;
|
|
21
|
+
exports.arrayRemove = firestore_1.FieldValue.arrayRemove;
|
|
22
|
+
exports.deleteField = firestore_1.FieldValue.delete;
|
|
23
|
+
exports.serverTimestamp = firestore_1.FieldValue.serverTimestamp;
|
|
24
|
+
const isServerTimestamp = (x) => x instanceof firestore_1.FieldValue;
|
|
25
|
+
exports.isServerTimestamp = isServerTimestamp;
|
|
26
|
+
const addDoc = (ref, data) => ref.add(data);
|
|
27
|
+
exports.addDoc = addDoc;
|
|
28
|
+
const collection = (firestoreOrRef, path, ...pathSegments) => firestoreOrRef instanceof firestore_1.Firestore
|
|
29
|
+
? firestoreOrRef.collection([path, ...pathSegments].join("/"))
|
|
30
|
+
: firestoreOrRef.firestore.collection([firestoreOrRef.path, path, ...pathSegments].join("/"));
|
|
31
|
+
exports.collection = collection;
|
|
32
|
+
const collectionGroup = (firestore, collectionID) => firestore.collectionGroup(collectionID);
|
|
33
|
+
exports.collectionGroup = collectionGroup;
|
|
34
|
+
const deleteDoc = async (ref) => {
|
|
35
|
+
await ref.delete();
|
|
36
|
+
};
|
|
37
|
+
exports.deleteDoc = deleteDoc;
|
|
38
|
+
const doc = (firestoreOrRef, path, ...pathSegments) => firestoreOrRef instanceof firestore_1.Firestore
|
|
39
|
+
? firestoreOrRef.doc([path, ...pathSegments].join("/"))
|
|
40
|
+
: path
|
|
41
|
+
? firestoreOrRef.doc([path, ...pathSegments].join("/"))
|
|
42
|
+
: firestoreOrRef.doc();
|
|
43
|
+
exports.doc = doc;
|
|
44
|
+
const getDoc = (ref) => ref.get();
|
|
45
|
+
exports.getDoc = getDoc;
|
|
46
|
+
const getDocs = (query) => query.get();
|
|
47
|
+
exports.getDocs = getDocs;
|
|
48
|
+
const query = (ref, ...queryConstraints) => queryConstraints.length === 0
|
|
49
|
+
? ref
|
|
50
|
+
: queryConstraints.length === 1
|
|
51
|
+
? ref.where(queryConstraints[0])
|
|
52
|
+
: ref.where(firestore_1.Filter.and(...queryConstraints));
|
|
53
|
+
exports.query = query;
|
|
54
|
+
const setDoc = async (ref, data) => {
|
|
55
|
+
await ref.set(data);
|
|
56
|
+
};
|
|
57
|
+
exports.setDoc = setDoc;
|
|
58
|
+
const updateDoc = async (ref, data) => {
|
|
59
|
+
await ref.update(data);
|
|
60
|
+
};
|
|
61
|
+
exports.updateDoc = updateDoc;
|
|
62
|
+
//# sourceMappingURL=firestore-deps-admin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firestore-deps-admin.js","sourceRoot":"","sources":["../src/firestore-deps-admin.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,uDAaiC;AAK/B,oGAhBA,+BAAmB,OAgBA;AACnB,kGAhBA,6BAAiB,OAgBA;AACjB,iGAhBA,4BAAgB,OAgBA;AAChB,0FAdA,qBAAS,OAcA;AACT,sFAdA,iBAAK,OAcA;AACL,8FAdA,yBAAa,OAcA;AACb,0FAdA,qBAAS,OAcA;AATE,QAAA,mBAAmB,GAAoB,OAAO,CAAC;AAa/C,QAAA,KAAK,GAAG,kBAAM,CAAC,KAAK,CAAC;AACrB,QAAA,WAAW,GAAG,sBAAU,CAAC,WAAW,CAAC;AACrC,QAAA,WAAW,GAAG,sBAAU,CAAC,MAAM,CAAC;AAChC,QAAA,eAAe,GAAG,sBAAU,CAAC,eAAe,CAAC;AAEnD,MAAM,iBAAiB,GAAG,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,YAAY,sBAAU,CAAC;AAAxD,QAAA,iBAAiB,qBAAuC;AAE9D,MAAM,MAAM,GAAG,CACpB,GAA2B,EAC3B,IAAuB,EACQ,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAHrC,QAAA,MAAM,U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,MAAM,OAAO,GAAG,CAAI,KAAe,EAA6B,EAAE,CACvE,KAAK,CAAC,GAAG,EAAE,CAAC;AADD,QAAA,OAAO,WACN;AAEP,MAAM,KAAK,GAAG,CACnB,GAAa,EACb,GAAG,gBAAmC,EAC5B,EAAE,CACZ,gBAAgB,CAAC,MAAM,KAAK,CAAC;IAC3B,CAAC,CAAC,GAAG;IACL,CAAC,CAAC,gBAAgB,CAAC,MAAM,KAAK,CAAC;QAC/B,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC;QAChC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,kBAAM,CAAC,GAAG,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC;AARpC,QAAA,KAAK,SAQ+B;AAE1C,MAAM,MAAM,GAAG,KAAK,EACzB,GAAyB,EACzB,IAAuB,EACR,EAAE;IACjB,MAAM,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AACtB,CAAC,CAAC;AALW,QAAA,MAAM,UAKjB;AAEK,MAAM,SAAS,GAAG,KAAK,EAC5B,GAAyB,EACzB,IAAmB,EACJ,EAAE;IACjB,MAAM,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC,CAAC;AALW,QAAA,SAAS,aAKpB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provides all dependencies normally imported from "firebase/firestore".
|
|
3
|
+
*
|
|
4
|
+
* For web clients, the "firebase/firestore" API is simply re-exported.
|
|
5
|
+
*
|
|
6
|
+
* For the server client API, ...
|
|
7
|
+
*/
|
|
8
|
+
export * from "firebase/firestore";
|
|
9
|
+
export declare const FIRESTORE_DEPS_TYPE: "web" | "admin";
|
|
10
|
+
export declare const isServerTimestamp: (data: any) => boolean;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Provides all dependencies normally imported from "firebase/firestore".
|
|
4
|
+
*
|
|
5
|
+
* For web clients, the "firebase/firestore" API is simply re-exported.
|
|
6
|
+
*
|
|
7
|
+
* For the server client API, ...
|
|
8
|
+
*/
|
|
9
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
12
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
13
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
14
|
+
}
|
|
15
|
+
Object.defineProperty(o, k2, desc);
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
21
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
22
|
+
};
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.isServerTimestamp = exports.FIRESTORE_DEPS_TYPE = void 0;
|
|
25
|
+
__exportStar(require("firebase/firestore"), exports);
|
|
26
|
+
exports.FIRESTORE_DEPS_TYPE = "web";
|
|
27
|
+
const isServerTimestamp = (data) => data._methodName === "serverTimestamp";
|
|
28
|
+
exports.isServerTimestamp = isServerTimestamp;
|
|
29
|
+
//# sourceMappingURL=firestore-deps-web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firestore-deps-web.js","sourceRoot":"","sources":["../src/firestore-deps-web.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;;;;;;;;;;;;;AAEH,qDAAmC;AAEtB,QAAA,mBAAmB,GAAoB,KAAK,CAAC;AAEnD,MAAM,iBAAiB,GAAG,CAAC,IAAS,EAAE,EAAE,CAC7C,IAAI,CAAC,WAAW,KAAK,iBAAiB,CAAC;AAD5B,QAAA,iBAAiB,qBACW"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provides all dependencies normally imported from "firebase/firestore".
|
|
3
|
+
*
|
|
4
|
+
* For web clients, the "firebase/firestore" API is simply re-exported.
|
|
5
|
+
*
|
|
6
|
+
* For the server client API, ...
|
|
7
|
+
*/
|
|
8
|
+
export * from "firebase/firestore";
|
|
9
|
+
export declare const FIRESTORE_DEPS_TYPE: "web" | "admin";
|
|
10
|
+
export declare const isServerTimestamp: (data: any) => boolean;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Provides all dependencies normally imported from "firebase/firestore".
|
|
4
|
+
*
|
|
5
|
+
* For web clients, the "firebase/firestore" API is simply re-exported.
|
|
6
|
+
*
|
|
7
|
+
* For the server client API, ...
|
|
8
|
+
*/
|
|
9
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
12
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
13
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
14
|
+
}
|
|
15
|
+
Object.defineProperty(o, k2, desc);
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
21
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
22
|
+
};
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.isServerTimestamp = exports.FIRESTORE_DEPS_TYPE = void 0;
|
|
25
|
+
__exportStar(require("firebase/firestore"), exports);
|
|
26
|
+
exports.FIRESTORE_DEPS_TYPE = "web";
|
|
27
|
+
const isServerTimestamp = (data) => data._methodName === "serverTimestamp";
|
|
28
|
+
exports.isServerTimestamp = isServerTimestamp;
|
|
29
|
+
//# sourceMappingURL=firestore-deps.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firestore-deps.js","sourceRoot":"","sources":["../src/firestore-deps.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;;;;;;;;;;;;;AAEH,qDAAmC;AAEtB,QAAA,mBAAmB,GAAoB,KAAK,CAAC;AAEnD,MAAM,iBAAiB,GAAG,CAAC,IAAS,EAAE,EAAE,CAC7C,IAAI,CAAC,WAAW,KAAK,iBAAiB,CAAC;AAD5B,QAAA,iBAAiB,qBACW"}
|
package/dist/proxies.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.watchFieldForChanges = exports.watchArrayForChanges = void 0;
|
|
4
|
-
const firestore_1 = require("firebase/firestore");
|
|
5
4
|
const zod_1 = require("zod");
|
|
5
|
+
const firestore_deps_1 = require("./firestore-deps");
|
|
6
6
|
const ts_helpers_1 = require("./ts-helpers");
|
|
7
7
|
/**
|
|
8
8
|
* Given a Zod schema representing a collection, returns the sub-schema of the
|
|
@@ -145,7 +145,7 @@ function watchArrayForChanges(arrayPath, array, fieldSchema, field, addToUpdateL
|
|
|
145
145
|
}
|
|
146
146
|
// Only top-level elements can be deleted with Firestore's arrayRemove.
|
|
147
147
|
if (target === array) {
|
|
148
|
-
addToUpdateList(arrayPath, (0,
|
|
148
|
+
addToUpdateList(arrayPath, (0, firestore_deps_1.arrayRemove)(removedValues[0]));
|
|
149
149
|
}
|
|
150
150
|
else {
|
|
151
151
|
addToUpdateList(arrayPath, array);
|
|
@@ -234,7 +234,7 @@ function watchFieldForChanges(fieldPath, fieldSchema, field, addToUpdateList) {
|
|
|
234
234
|
(0, ts_helpers_1.assertKeyIsString)(propertyKey);
|
|
235
235
|
// Delete the field in Firestore by marking it with the deleteField
|
|
236
236
|
// operator.
|
|
237
|
-
addToUpdateList([...fieldPath, propertyKey], (0,
|
|
237
|
+
addToUpdateList([...fieldPath, propertyKey], (0, firestore_deps_1.deleteField)());
|
|
238
238
|
return Reflect.deleteProperty(target, propertyKey);
|
|
239
239
|
},
|
|
240
240
|
});
|
package/dist/proxies.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxies.js","sourceRoot":"","sources":["../src/proxies.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"proxies.js","sourceRoot":"","sources":["../src/proxies.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAExB,qDAA4D;AAC5D,6CAAiD;AAEjD;;;GAGG;AACH,SAAS,iBAAiB,CACxB,MAAW,EACX,YAA0B,EAC1B,WAAmB;IAEnB,IAAI,MAAM,GAAQ,YAAY,CAAC;IAC/B,iDAAiD;IACjD,OAAO,IAAI,EAAE;QACX,QAAQ,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE;YAC5B,uEAAuE;YACvE,sEAAsE;YACtE,KAAK,OAAC,CAAC,qBAAqB,CAAC,WAAW,CAAC;YACzC,KAAK,OAAC,CAAC,qBAAqB,CAAC,WAAW;gBACtC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;gBACzB,SAAS;YACX,KAAK,OAAC,CAAC,qBAAqB,CAAC,UAAU;gBACrC,MAAM,GAAG,MAAM,CAAC,aAAa,EAAE,CAAC;gBAChC,SAAS;YACX,KAAK,OAAC,CAAC,qBAAqB,CAAC,UAAU;gBACrC,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;gBAC5B,SAAS;YACX,wDAAwD;YACxD,KAAK,OAAC,CAAC,qBAAqB,CAAC,SAAS;gBACpC,IACE,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,Q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AAC,KAAK,CAAC,cAAc,CAAC,CAAC;YACtD,eAAe,CAAC,CAAC,GAAG,SAAS,EAAE,WAAW,CAAC,EAAE,cAAc,CAAC,CAAC;YAC7D,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,WAAW,EAAE,cAAc,CAAC,CAAC;QAC1D,CAAC;QACD,cAAc,CAAC,MAAM,EAAE,WAAW;YAChC,IAAA,8BAAiB,EAAC,WAAW,CAAC,CAAC;YAC/B,mEAAmE;YACnE,YAAY;YACZ,eAAe,CAAC,CAAC,GAAG,SAAS,EAAE,WAAW,CAAC,EAAE,IAAA,4BAAW,GAAE,CAAC,CAAC;YAC5D,OAAO,OAAO,CAAC,cAAc,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;QACrD,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AA3ED,oDA2EC"}
|
package/dist/timestamps.d.ts
CHANGED
package/dist/timestamps.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.serverTimestampWithClientTime = exports.serverTimestamp = exports.futureTimestampDays = exports.timestampSchema = void 0;
|
|
4
|
-
const firestore_1 = require("firebase/firestore");
|
|
5
4
|
const zod_1 = require("zod");
|
|
5
|
+
const firestore_deps_1 = require("./firestore-deps");
|
|
6
6
|
/**
|
|
7
7
|
* Timestamp representation used by Firestore: seconds and nanoseconds since the
|
|
8
8
|
* epoch.
|
|
9
9
|
*/
|
|
10
|
-
exports.timestampSchema = zod_1.z.custom((data) => data instanceof
|
|
10
|
+
exports.timestampSchema = zod_1.z.custom((data) => data instanceof firestore_deps_1.Timestamp || (0, firestore_deps_1.isServerTimestamp)(data));
|
|
11
11
|
/**
|
|
12
12
|
* Returns a Firestore Timestamp for some future date. The result is typically
|
|
13
13
|
* used for writing TTLs.
|
|
@@ -19,7 +19,7 @@ exports.timestampSchema = zod_1.z.custom((data) => data instanceof firestore_1.T
|
|
|
19
19
|
* @param daysFromNow days in the future to set this Timestamp.
|
|
20
20
|
*/
|
|
21
21
|
function futureTimestampDays(daysFromNow) {
|
|
22
|
-
return
|
|
22
|
+
return firestore_deps_1.Timestamp.fromMillis(Date.now() + daysFromNow * 24 * 60 * 60 * 1000);
|
|
23
23
|
}
|
|
24
24
|
exports.futureTimestampDays = futureTimestampDays;
|
|
25
25
|
/**
|
|
@@ -31,7 +31,7 @@ exports.futureTimestampDays = futureTimestampDays;
|
|
|
31
31
|
* as a Timestamp, see {@link serverTimestampWithClientTime}.
|
|
32
32
|
*/
|
|
33
33
|
function serverTimestamp() {
|
|
34
|
-
return (0,
|
|
34
|
+
return (0, firestore_deps_1.serverTimestamp)();
|
|
35
35
|
}
|
|
36
36
|
exports.serverTimestamp = serverTimestamp;
|
|
37
37
|
/**
|
|
@@ -44,12 +44,11 @@ exports.serverTimestamp = serverTimestamp;
|
|
|
44
44
|
* clock is incorrect. Caveat coder.
|
|
45
45
|
*/
|
|
46
46
|
function serverTimestampWithClientTime() {
|
|
47
|
-
const sentinel = (0,
|
|
48
|
-
const timestamp =
|
|
47
|
+
const sentinel = (0, firestore_deps_1.serverTimestamp)();
|
|
48
|
+
const timestamp = firestore_deps_1.Timestamp.now();
|
|
49
49
|
Object.assign(sentinel, timestamp);
|
|
50
50
|
sentinel.isEqual = (other) => timestamp.isEqual(other);
|
|
51
51
|
sentinel.toDate = () => timestamp.toDate();
|
|
52
|
-
sentinel.toJSON = () => timestamp.toJSON();
|
|
53
52
|
sentinel.toMillis = () => timestamp.toMillis();
|
|
54
53
|
sentinel.toString = () => timestamp.toString();
|
|
55
54
|
sentinel.valueOf = () => timestamp.valueOf();
|
package/dist/timestamps.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timestamps.js","sourceRoot":"","sources":["../src/timestamps.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"timestamps.js","sourceRoot":"","sources":["../src/timestamps.ts"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
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "firetender",
|
|
3
3
|
"displayName": "Firetender",
|
|
4
4
|
"description": "Typescript wrapper for Firestore documents",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.10.0",
|
|
6
6
|
"author": "Jake Hartman",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"homepage": "https://github.com/jakes-space/firetender",
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
"exports": {
|
|
21
21
|
".": {
|
|
22
22
|
"types": "./dist/index.d.ts",
|
|
23
|
-
"import": "./dist/index.js"
|
|
23
|
+
"import": "./dist/index.js",
|
|
24
|
+
"require": "./dist/index.js"
|
|
24
25
|
}
|
|
25
26
|
},
|
|
26
27
|
"files": [
|
|
@@ -28,6 +29,9 @@
|
|
|
28
29
|
"/src/*.ts"
|
|
29
30
|
],
|
|
30
31
|
"scripts": {
|
|
32
|
+
"use-admin-firestore": "cp package-admin.json package.json && cp src/firestore-deps-admin.ts src/firestore-deps.ts && npm install",
|
|
33
|
+
"use-web-firestore": "echo Already using web firestore.",
|
|
34
|
+
"diff-web-admin": "diff package-web.json package-admin.json",
|
|
31
35
|
"lint:check": "eslint src --ext .ts",
|
|
32
36
|
"lint:fix": "eslint --fix src --ext .ts",
|
|
33
37
|
"prettier:check": "prettier --check src/*.ts src/**/*.ts",
|
|
@@ -57,6 +61,7 @@
|
|
|
57
61
|
"eslint-plugin-import": "^2.27.5",
|
|
58
62
|
"eslint-plugin-prettier": "^4.2.1",
|
|
59
63
|
"eslint-plugin-simple-import-sort": "^10.0.0",
|
|
64
|
+
"firebase-admin": "^11.6.0",
|
|
60
65
|
"husky": "^8.0.3",
|
|
61
66
|
"jest": "^29.4.3",
|
|
62
67
|
"prettier": "^2.8.4",
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
import { addContextToError, FiretenderUsageError } from "./errors";
|
|
1
4
|
import {
|
|
2
5
|
collection,
|
|
3
6
|
collectionGroup,
|
|
@@ -11,10 +14,7 @@ import {
|
|
|
11
14
|
query,
|
|
12
15
|
QueryConstraint,
|
|
13
16
|
QuerySnapshot,
|
|
14
|
-
} from "
|
|
15
|
-
import { z } from "zod";
|
|
16
|
-
|
|
17
|
-
import { addContextToError, FiretenderUsageError } from "./errors";
|
|
17
|
+
} from "./firestore-deps";
|
|
18
18
|
import { FiretenderDoc, FiretenderDocOptions } from "./FiretenderDoc";
|
|
19
19
|
import { DeepPartial } from "./ts-helpers";
|
|
20
20
|
|
|
@@ -35,8 +35,10 @@ export class FiretenderCollection<SchemaType extends z.SomeZodObject> {
|
|
|
35
35
|
/** The collection path of this object: a series of collection names */
|
|
36
36
|
readonly collectionPath: string[];
|
|
37
37
|
|
|
38
|
-
/**
|
|
39
|
-
readonly
|
|
38
|
+
/** Function to return the initial values when creating a new document. */
|
|
39
|
+
readonly baseInitialDataFactory:
|
|
40
|
+
| (() => DeepPartial<z.input<SchemaType>>)
|
|
41
|
+
| undefined;
|
|
40
42
|
|
|
41
43
|
/**
|
|
42
44
|
* @param schema the Zod object schema describing the documents in this
|
|
@@ -44,19 +46,27 @@ export class FiretenderCollection<SchemaType extends z.SomeZodObject> {
|
|
|
44
46
|
* @param firestore the thing you get from getFirestore().
|
|
45
47
|
* @param collectionPath the path of this collection in Firestore: the names
|
|
46
48
|
* of any parent collections and of this collection.
|
|
47
|
-
* @param baseInitialData (optional)
|
|
49
|
+
* @param baseInitialData (optional) an object or object factory providing
|
|
50
|
+
* default field values for this collection.
|
|
48
51
|
*/
|
|
49
52
|
constructor(
|
|
50
53
|
schema: SchemaType,
|
|
51
54
|
firestore: Firestore,
|
|
52
55
|
collectionPath: [string, ...string[]] | string,
|
|
53
|
-
baseInitialData:
|
|
56
|
+
baseInitialData:
|
|
57
|
+
| (() => DeepPartial<z.input<SchemaType>>)
|
|
58
|
+
| DeepPartial<z.input<SchemaType>>
|
|
59
|
+
| undefined = undefined
|
|
54
60
|
) {
|
|
55
61
|
this.schema = schema;
|
|
56
62
|
this.firestore = firestore;
|
|
57
63
|
this.collectionPath = [collectionPath].flat();
|
|
58
64
|
if (baseInitialData) {
|
|
59
|
-
|
|
65
|
+
if (typeof baseInitialData === "function") {
|
|
66
|
+
this.baseInitialDataFactory = baseInitialData;
|
|
67
|
+
} else {
|
|
68
|
+
this.baseInitialDataFactory = () => baseInitialData;
|
|
69
|
+
}
|
|
60
70
|
}
|
|
61
71
|
}
|
|
62
72
|
|
|
@@ -91,8 +101,8 @@ export class FiretenderCollection<SchemaType extends z.SomeZodObject> {
|
|
|
91
101
|
);
|
|
92
102
|
}
|
|
93
103
|
const data = {};
|
|
94
|
-
if (this.
|
|
95
|
-
Object.assign(data, this.
|
|
104
|
+
if (this.baseInitialDataFactory) {
|
|
105
|
+
Object.assign(data, this.baseInitialDataFactory());
|
|
96
106
|
}
|
|
97
107
|
if (initialData) {
|
|
98
108
|
Object.assign(data, initialData);
|
package/src/FiretenderDoc.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
addContextToError,
|
|
5
|
+
FiretenderInternalError,
|
|
6
|
+
FiretenderIOError,
|
|
7
|
+
FiretenderUsageError,
|
|
8
|
+
} from "./errors";
|
|
1
9
|
import {
|
|
2
10
|
addDoc,
|
|
3
11
|
collection,
|
|
@@ -8,15 +16,7 @@ import {
|
|
|
8
16
|
getDoc,
|
|
9
17
|
setDoc,
|
|
10
18
|
updateDoc,
|
|
11
|
-
} from "
|
|
12
|
-
import { z } from "zod";
|
|
13
|
-
|
|
14
|
-
import {
|
|
15
|
-
addContextToError,
|
|
16
|
-
FiretenderInternalError,
|
|
17
|
-
FiretenderIOError,
|
|
18
|
-
FiretenderUsageError,
|
|
19
|
-
} from "./errors";
|
|
19
|
+
} from "./firestore-deps";
|
|
20
20
|
import { watchFieldForChanges } from "./proxies";
|
|
21
21
|
import { assertIsDefined, DeepReadonly } from "./ts-helpers";
|
|
22
22
|
|
|
@@ -108,7 +108,7 @@ export class FiretenderDoc<SchemaType extends z.SomeZodObject> {
|
|
|
108
108
|
"Initial data must be given when creating a new doc."
|
|
109
109
|
);
|
|
110
110
|
}
|
|
111
|
-
if (this.ref
|
|
111
|
+
if (this.ref instanceof DocumentReference) {
|
|
112
112
|
this.docID = this.ref.path.split("/").pop();
|
|
113
113
|
} else if (!this.isNewDoc) {
|
|
114
114
|
throw TypeError(
|
|
@@ -214,7 +214,7 @@ export class FiretenderDoc<SchemaType extends z.SomeZodObject> {
|
|
|
214
214
|
} else {
|
|
215
215
|
// For a string or undefined ...
|
|
216
216
|
const collectionRef =
|
|
217
|
-
this.ref
|
|
217
|
+
this.ref instanceof DocumentReference ? this.ref.parent : this.ref;
|
|
218
218
|
if (dest) {
|
|
219
219
|
ref = doc(collectionRef, dest);
|
|
220
220
|
} else {
|
|
@@ -249,7 +249,7 @@ export class FiretenderDoc<SchemaType extends z.SomeZodObject> {
|
|
|
249
249
|
* @throws Throws an error if the document does not yet have a reference.
|
|
250
250
|
*/
|
|
251
251
|
get docRef(): DocumentReference {
|
|
252
|
-
if (this.ref
|
|
252
|
+
if (!(this.ref instanceof DocumentReference)) {
|
|
253
253
|
throw new FiretenderUsageError(
|
|
254
254
|
"docRef can only be accessed after the new doc has been written."
|
|
255
255
|
);
|
|
@@ -286,7 +286,7 @@ export class FiretenderDoc<SchemaType extends z.SomeZodObject> {
|
|
|
286
286
|
* the document already contains data.
|
|
287
287
|
*/
|
|
288
288
|
async load(force = false): Promise<this> {
|
|
289
|
-
if (this.isNewDoc || this.ref
|
|
289
|
+
if (this.isNewDoc || this.ref instanceof CollectionReference) {
|
|
290
290
|
throw new FiretenderUsageError(
|
|
291
291
|
"load() should not be called for new documents."
|
|
292
292
|
);
|
|
@@ -306,7 +306,12 @@ export class FiretenderDoc<SchemaType extends z.SomeZodObject> {
|
|
|
306
306
|
addContextToError(error, "getDoc", this.ref);
|
|
307
307
|
throw error;
|
|
308
308
|
}
|
|
309
|
-
|
|
309
|
+
// DocumentSnapshot.prototype.exists is a boolean for
|
|
310
|
+
// "firebase-admin/firestore" and a function for "firebase/firestore".
|
|
311
|
+
if (
|
|
312
|
+
(typeof snapshot.exists === "boolean" && !snapshot.exists) ||
|
|
313
|
+
(typeof snapshot.exists === "function" && !(snapshot.exists as any)())
|
|
314
|
+
) {
|
|
310
315
|
const error = new FiretenderIOError(
|
|
311
316
|
`Document does not exist: "${this.ref.path}"`
|
|
312
317
|
);
|
|
@@ -379,7 +384,7 @@ export class FiretenderDoc<SchemaType extends z.SomeZodObject> {
|
|
|
379
384
|
// For new docs, this.data should contain its initial state.
|
|
380
385
|
if (this.isSettingNewContents) {
|
|
381
386
|
assertIsDefined(this.data);
|
|
382
|
-
if (this.ref
|
|
387
|
+
if (this.ref instanceof DocumentReference) {
|
|
383
388
|
try {
|
|
384
389
|
await setDoc(this.ref, this.data);
|
|
385
390
|
} catch (error) {
|
|
@@ -400,24 +405,18 @@ export class FiretenderDoc<SchemaType extends z.SomeZodObject> {
|
|
|
400
405
|
}
|
|
401
406
|
// For existing docs, this.updates should contain a list of changes.
|
|
402
407
|
else {
|
|
403
|
-
if (!(this.ref
|
|
408
|
+
if (!(this.ref instanceof DocumentReference)) {
|
|
404
409
|
// We should never get here.
|
|
405
410
|
throw new FiretenderInternalError(
|
|
406
411
|
"Internal error. Firetender object should always reference a document when updating an existing doc."
|
|
407
412
|
);
|
|
408
413
|
}
|
|
409
414
|
if (this.updates.size > 0) {
|
|
410
|
-
|
|
411
|
-
const flatUpdateList = Array.from(this.updates.entries()).flat();
|
|
415
|
+
const updateData = Object.fromEntries(this.updates);
|
|
412
416
|
try {
|
|
413
|
-
await updateDoc(
|
|
414
|
-
this.ref,
|
|
415
|
-
flatUpdateList[0],
|
|
416
|
-
flatUpdateList[1],
|
|
417
|
-
...flatUpdateList.slice(2)
|
|
418
|
-
);
|
|
417
|
+
await updateDoc(this.ref, updateData);
|
|
419
418
|
} catch (error: any) {
|
|
420
|
-
addContextToError(error, "updateDoc", this.ref,
|
|
419
|
+
addContextToError(error, "updateDoc", this.ref, updateData);
|
|
421
420
|
throw error;
|
|
422
421
|
}
|
|
423
422
|
this.updates.clear();
|
package/src/errors.ts
CHANGED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provides all dependencies normally imported from "firebase/firestore".
|
|
3
|
+
*
|
|
4
|
+
* For web clients, the "firebase/firestore" API is simply re-exported.
|
|
5
|
+
*
|
|
6
|
+
* For the server client API, ...
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
CollectionGroup,
|
|
11
|
+
CollectionReference,
|
|
12
|
+
DocumentReference,
|
|
13
|
+
DocumentSnapshot,
|
|
14
|
+
FieldValue,
|
|
15
|
+
Filter,
|
|
16
|
+
Firestore,
|
|
17
|
+
Query,
|
|
18
|
+
QuerySnapshot,
|
|
19
|
+
Timestamp,
|
|
20
|
+
UpdateData,
|
|
21
|
+
WithFieldValue,
|
|
22
|
+
} from "@google-cloud/firestore";
|
|
23
|
+
|
|
24
|
+
export const FIRESTORE_DEPS_TYPE: "web" | "admin" = "admin";
|
|
25
|
+
|
|
26
|
+
export {
|
|
27
|
+
CollectionReference,
|
|
28
|
+
DocumentReference,
|
|
29
|
+
DocumentSnapshot,
|
|
30
|
+
Firestore,
|
|
31
|
+
Query,
|
|
32
|
+
QuerySnapshot,
|
|
33
|
+
Timestamp,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type QueryConstraint = Filter;
|
|
37
|
+
export const where = Filter.where;
|
|
38
|
+
export const arrayRemove = FieldValue.arrayRemove;
|
|
39
|
+
export const deleteField = FieldValue.delete;
|
|
40
|
+
export const serverTimestamp = FieldValue.serverTimestamp;
|
|
41
|
+
|
|
42
|
+
export const isServerTimestamp = (x: any) => x instanceof FieldValue;
|
|
43
|
+
|
|
44
|
+
export const addDoc = <T>(
|
|
45
|
+
ref: CollectionReference<T>,
|
|
46
|
+
data: WithFieldValue<T>
|
|
47
|
+
): Promise<DocumentReference<T>> => ref.add(data);
|
|
48
|
+
|
|
49
|
+
export const collection = (
|
|
50
|
+
firestoreOrRef: Firestore | CollectionReference,
|
|
51
|
+
path: string,
|
|
52
|
+
...pathSegments: string[]
|
|
53
|
+
): CollectionReference =>
|
|
54
|
+
firestoreOrRef instanceof Firestore
|
|
55
|
+
? firestoreOrRef.collection([path, ...pathSegments].join("/"))
|
|
56
|
+
: firestoreOrRef.firestore.collection(
|
|
57
|
+
[firestoreOrRef.path, path, ...pathSegments].join("/")
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
export const collectionGroup = (
|
|
61
|
+
firestore: Firestore,
|
|
62
|
+
collectionID: string
|
|
63
|
+
): CollectionGroup => firestore.collectionGroup(collectionID);
|
|
64
|
+
|
|
65
|
+
export const deleteDoc = async (
|
|
66
|
+
ref: DocumentReference<unknown>
|
|
67
|
+
): Promise<void> => {
|
|
68
|
+
await ref.delete();
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const doc = (
|
|
72
|
+
firestoreOrRef: Firestore | CollectionReference,
|
|
73
|
+
path?: string,
|
|
74
|
+
...pathSegments: string[]
|
|
75
|
+
): DocumentReference =>
|
|
76
|
+
firestoreOrRef instanceof Firestore
|
|
77
|
+
? firestoreOrRef.doc([path, ...pathSegments].join("/"))
|
|
78
|
+
: path
|
|
79
|
+
? firestoreOrRef.doc([path, ...pathSegments].join("/"))
|
|
80
|
+
: firestoreOrRef.doc();
|
|
81
|
+
|
|
82
|
+
export const getDoc = <T>(
|
|
83
|
+
ref: DocumentReference<T>
|
|
84
|
+
): Promise<DocumentSnapshot<T>> => ref.get();
|
|
85
|
+
|
|
86
|
+
export const getDocs = <T>(query: Query<T>): Promise<QuerySnapshot<T>> =>
|
|
87
|
+
query.get();
|
|
88
|
+
|
|
89
|
+
export const query = <T>(
|
|
90
|
+
ref: Query<T>,
|
|
91
|
+
...queryConstraints: QueryConstraint[]
|
|
92
|
+
): Query<T> =>
|
|
93
|
+
queryConstraints.length === 0
|
|
94
|
+
? ref
|
|
95
|
+
: queryConstraints.length === 1
|
|
96
|
+
? ref.where(queryConstraints[0])
|
|
97
|
+
: ref.where(Filter.and(...queryConstraints));
|
|
98
|
+
|
|
99
|
+
export const setDoc = async <T>(
|
|
100
|
+
ref: DocumentReference<T>,
|
|
101
|
+
data: WithFieldValue<T>
|
|
102
|
+
): Promise<void> => {
|
|
103
|
+
await ref.set(data);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export const updateDoc = async <T>(
|
|
107
|
+
ref: DocumentReference<T>,
|
|
108
|
+
data: UpdateData<T>
|
|
109
|
+
): Promise<void> => {
|
|
110
|
+
await ref.update(data);
|
|
111
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provides all dependencies normally imported from "firebase/firestore".
|
|
3
|
+
*
|
|
4
|
+
* For web clients, the "firebase/firestore" API is simply re-exported.
|
|
5
|
+
*
|
|
6
|
+
* For the server client API, ...
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export * from "firebase/firestore";
|
|
10
|
+
|
|
11
|
+
export const FIRESTORE_DEPS_TYPE: "web" | "admin" = "web";
|
|
12
|
+
|
|
13
|
+
export const isServerTimestamp = (data: any) =>
|
|
14
|
+
data._methodName === "serverTimestamp";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provides all dependencies normally imported from "firebase/firestore".
|
|
3
|
+
*
|
|
4
|
+
* For web clients, the "firebase/firestore" API is simply re-exported.
|
|
5
|
+
*
|
|
6
|
+
* For the server client API, ...
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export * from "firebase/firestore";
|
|
10
|
+
|
|
11
|
+
export const FIRESTORE_DEPS_TYPE: "web" | "admin" = "web";
|
|
12
|
+
|
|
13
|
+
export const isServerTimestamp = (data: any) =>
|
|
14
|
+
data._methodName === "serverTimestamp";
|
package/src/proxies.ts
CHANGED
package/src/timestamps.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
1
3
|
import {
|
|
4
|
+
isServerTimestamp,
|
|
2
5
|
serverTimestamp as firestoreServerTimestamp,
|
|
3
6
|
Timestamp,
|
|
4
|
-
} from "
|
|
5
|
-
import { z } from "zod";
|
|
7
|
+
} from "./firestore-deps";
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* Timestamp representation used by Firestore: seconds and nanoseconds since the
|
|
9
11
|
* epoch.
|
|
10
12
|
*/
|
|
11
13
|
export const timestampSchema = z.custom<Timestamp>(
|
|
12
|
-
(data: any) =>
|
|
13
|
-
data instanceof Timestamp || data._methodName === "serverTimestamp"
|
|
14
|
+
(data: any) => data instanceof Timestamp || isServerTimestamp(data)
|
|
14
15
|
);
|
|
15
16
|
|
|
16
17
|
/**
|
|
@@ -54,7 +55,6 @@ export function serverTimestampWithClientTime(): Timestamp {
|
|
|
54
55
|
Object.assign(sentinel, timestamp);
|
|
55
56
|
(sentinel as any).isEqual = (other: Timestamp) => timestamp.isEqual(other);
|
|
56
57
|
(sentinel as any).toDate = () => timestamp.toDate();
|
|
57
|
-
(sentinel as any).toJSON = () => timestamp.toJSON();
|
|
58
58
|
(sentinel as any).toMillis = () => timestamp.toMillis();
|
|
59
59
|
(sentinel as any).toString = () => timestamp.toString();
|
|
60
60
|
(sentinel as any).valueOf = () => timestamp.valueOf();
|