firetender-admin 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.
Files changed (43) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +349 -0
  3. package/dist/FiretenderCollection.d.ts +116 -0
  4. package/dist/FiretenderCollection.js +225 -0
  5. package/dist/FiretenderCollection.js.map +1 -0
  6. package/dist/FiretenderDoc.d.ts +172 -0
  7. package/dist/FiretenderDoc.js +361 -0
  8. package/dist/FiretenderDoc.js.map +1 -0
  9. package/dist/errors.d.ts +30 -0
  10. package/dist/errors.js +49 -0
  11. package/dist/errors.js.map +1 -0
  12. package/dist/firestore-deps-admin.d.ts +26 -0
  13. package/dist/firestore-deps-admin.js +62 -0
  14. package/dist/firestore-deps-admin.js.map +1 -0
  15. package/dist/firestore-deps-web.d.ts +10 -0
  16. package/dist/firestore-deps-web.js +29 -0
  17. package/dist/firestore-deps-web.js.map +1 -0
  18. package/dist/firestore-deps.d.ts +26 -0
  19. package/dist/firestore-deps.js +62 -0
  20. package/dist/firestore-deps.js.map +1 -0
  21. package/dist/index.d.ts +6 -0
  22. package/dist/index.js +18 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/proxies.d.ts +62 -0
  25. package/dist/proxies.js +243 -0
  26. package/dist/proxies.js.map +1 -0
  27. package/dist/timestamps.d.ts +37 -0
  28. package/dist/timestamps.js +58 -0
  29. package/dist/timestamps.js.map +1 -0
  30. package/dist/ts-helpers.d.ts +14 -0
  31. package/dist/ts-helpers.js +19 -0
  32. package/dist/ts-helpers.js.map +1 -0
  33. package/package.json +72 -0
  34. package/src/FiretenderCollection.ts +311 -0
  35. package/src/FiretenderDoc.ts +483 -0
  36. package/src/errors.ts +47 -0
  37. package/src/firestore-deps-admin.ts +111 -0
  38. package/src/firestore-deps-web.ts +14 -0
  39. package/src/firestore-deps.ts +111 -0
  40. package/src/index.ts +29 -0
  41. package/src/proxies.ts +286 -0
  42. package/src/timestamps.ts +62 -0
  43. package/src/ts-helpers.ts +39 -0
@@ -0,0 +1,361 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FiretenderDoc = void 0;
4
+ const errors_1 = require("./errors");
5
+ const firestore_deps_1 = require("./firestore-deps");
6
+ const proxies_1 = require("./proxies");
7
+ const ts_helpers_1 = require("./ts-helpers");
8
+ /**
9
+ * A local representation of a Firestore document.
10
+ */
11
+ class FiretenderDoc {
12
+ /**
13
+ * @param schema the Zod object schema describing this document's data.
14
+ * @param ref either a document reference specifying the full path of the
15
+ * document, or a collection reference specifying where a new document will
16
+ * be created.
17
+ * @param options optional parameters for the resulting FiretenderDoc; see
18
+ * FiretenderDocOptions for detail.
19
+ */
20
+ constructor(schema, ref, options = {}) {
21
+ /** Firestore document ID; undefined for new docs not yet on Firestore */
22
+ this.docID = undefined;
23
+ /** Local copy of the document data, parsed into the Zod type */
24
+ this.data = undefined;
25
+ /** Proxy to intercept write (.w) access to the data and track the changes */
26
+ this.dataProxy = undefined;
27
+ /** Map from the dot-delimited field path (per updateDoc()) to new value */
28
+ this.updates = new Map();
29
+ this.schema = schema;
30
+ this.ref = ref;
31
+ this.isNewDoc = options.createDoc ?? false;
32
+ this.isSettingNewContents = this.isNewDoc;
33
+ if (options.initialData) {
34
+ this.data = schema.parse(options.initialData);
35
+ }
36
+ else if (this.isNewDoc) {
37
+ throw ReferenceError("Initial data must be given when creating a new doc.");
38
+ }
39
+ if (this.ref instanceof firestore_deps_1.DocumentReference) {
40
+ this.docID = this.ref.path.split("/").pop();
41
+ }
42
+ else if (!this.isNewDoc) {
43
+ throw TypeError("FiretenderDoc can only take a collection reference when creating a new document. Use .createNewDoc() if this is your intent.");
44
+ }
45
+ }
46
+ /**
47
+ * Returns a FiretenderDoc representing a new Firestore document.
48
+ *
49
+ * This method does not create the document in Firestore. To do so, call the
50
+ * write() method.
51
+ *
52
+ * @param schema the Zod object schema describing this document's data.
53
+ * @param ref either a document reference specifying the full path of the
54
+ * document, or a collection reference specifying where a new document will
55
+ * be created.
56
+ * @param initialData the document's initial data, which must define a valid
57
+ * instance of this document according to its schema.
58
+ * @param options optional parameters for the resulting FiretenderDoc; see
59
+ * FiretenderDocOptions for detail.
60
+ */
61
+ static createNewDoc(schema, ref, initialData, options = {}) {
62
+ const mergedOptions = {
63
+ ...options,
64
+ createDoc: true,
65
+ initialData,
66
+ };
67
+ return new FiretenderDoc(schema, ref, mergedOptions);
68
+ }
69
+ /**
70
+ * Creates a copy of this document. Returns a deep copy of its data with a
71
+ * specified or undefined Firestore ID and reference.
72
+ *
73
+ * This method does not create the document in Firestore. To do so, call the
74
+ * write() method. If a document ID or reference is not provided, those will
75
+ * be unset until the write.
76
+ *
77
+ * The location of the new document depends on the type of the `dest`
78
+ * argument:
79
+ * - `undefined` (default): It will be in the same collection and will be
80
+ * assigned a random ID when written to Firestore.
81
+ * - `string`: It will be in the same collection and have a document ID given
82
+ * by `dest`.
83
+ * - `string[]`: It will be in the specified subcollection and receive a
84
+ * random ID (if `type` does not give an ID for the deepest subcollection)
85
+ * or have the fully specified Firestore path (if `type` does).
86
+ * - `DocumentReference`: It will have the given Firestore reference.
87
+ * - `CollectionReference`: It will be in the given subcollection and have a
88
+ * randomly assigned ID upon writing.
89
+ *
90
+ * @param dest the location of the new document; see above for details.
91
+ * @param options optional parameters for the resulting FiretenderDoc; see
92
+ * FiretenderDocOptions for detail.
93
+ */
94
+ copy(dest = undefined, options = {}) {
95
+ if (!this.data) {
96
+ throw new errors_1.FiretenderUsageError("You must call load() before making a copy.");
97
+ }
98
+ let ref;
99
+ if (dest instanceof firestore_deps_1.DocumentReference ||
100
+ dest instanceof firestore_deps_1.CollectionReference) {
101
+ ref = dest;
102
+ }
103
+ else if (Array.isArray(dest)) {
104
+ const path = this.ref.path.split("/");
105
+ if (path.length % 2 === 0) {
106
+ // If this doc has a ID for the deepest collection, remove it so that
107
+ // path always starts as a collection path.
108
+ path.length -= 1;
109
+ }
110
+ const collectionDepth = (path.length + 1) / 2;
111
+ if (dest.length < collectionDepth - 1 || dest.length > collectionDepth) {
112
+ throw new errors_1.FiretenderUsageError("copy() with a path array requires an ID for all collections and subcollections, except optionally the last.");
113
+ }
114
+ dest.forEach((id, index) => {
115
+ path[index * 2 + 1] = id;
116
+ });
117
+ ref =
118
+ dest.length === collectionDepth
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
+ }
122
+ else {
123
+ // For a string or undefined ...
124
+ const collectionRef = this.ref instanceof firestore_deps_1.DocumentReference ? this.ref.parent : this.ref;
125
+ if (dest) {
126
+ ref = (0, firestore_deps_1.doc)(collectionRef, dest);
127
+ }
128
+ else {
129
+ ref = collectionRef;
130
+ }
131
+ }
132
+ const mergedOptions = {
133
+ ...options,
134
+ createDoc: true,
135
+ initialData: this.data,
136
+ };
137
+ return new FiretenderDoc(this.schema, ref, mergedOptions);
138
+ }
139
+ /**
140
+ * The document's ID string.
141
+ *
142
+ * @throws Throws an error if the document does not yet have an ID.
143
+ */
144
+ get id() {
145
+ if (!this.docID) {
146
+ throw new errors_1.FiretenderUsageError("id can only be accessed after the new doc has been written.");
147
+ }
148
+ return this.docID;
149
+ }
150
+ /**
151
+ * The document's Firestore reference.
152
+ *
153
+ * @throws Throws an error if the document does not yet have a reference.
154
+ */
155
+ get docRef() {
156
+ if (!(this.ref instanceof firestore_deps_1.DocumentReference)) {
157
+ throw new errors_1.FiretenderUsageError("docRef can only be accessed after the new doc has been written.");
158
+ }
159
+ return this.ref;
160
+ }
161
+ /**
162
+ * Is this a new doc that has not yet been written to Firestore?
163
+ */
164
+ isNew() {
165
+ return this.isNewDoc;
166
+ }
167
+ /**
168
+ * Does the document contain data, either because it was successfully loaded
169
+ * or is newly created?
170
+ */
171
+ isLoaded() {
172
+ return this.data !== undefined;
173
+ }
174
+ /**
175
+ * Does this document contain data that has not yet been written to Firestore?
176
+ */
177
+ isPendingWrite() {
178
+ return this.isSettingNewContents || this.updates.size > 0;
179
+ }
180
+ /**
181
+ * Loads this document's data from Firestore.
182
+ *
183
+ * @param force force a read from Firestore. Normally load() does nothing if
184
+ * the document already contains data.
185
+ */
186
+ async load(force = false) {
187
+ if (this.isNewDoc || this.ref instanceof firestore_deps_1.CollectionReference) {
188
+ throw new errors_1.FiretenderUsageError("load() should not be called for new documents.");
189
+ }
190
+ if (!this.data || force) {
191
+ if (this.resolvesWaitingForLoad !== undefined) {
192
+ await new Promise((resolve, reject) => {
193
+ (0, ts_helpers_1.assertIsDefined)(this.resolvesWaitingForLoad);
194
+ this.resolvesWaitingForLoad.push({ resolve, reject });
195
+ });
196
+ }
197
+ else {
198
+ this.resolvesWaitingForLoad = [];
199
+ let snapshot;
200
+ try {
201
+ snapshot = await (0, firestore_deps_1.getDoc)(this.ref);
202
+ }
203
+ catch (error) {
204
+ (0, errors_1.addContextToError)(error, "getDoc", this.ref);
205
+ throw error;
206
+ }
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())) {
211
+ const error = new errors_1.FiretenderIOError(`Document does not exist: "${this.ref.path}"`);
212
+ this.resolvesWaitingForLoad.forEach((wait) => wait.reject(error));
213
+ throw error;
214
+ }
215
+ this.data = this.schema.parse(snapshot.data());
216
+ // Dereference the old proxy, if any, to force a recapture of data.
217
+ this.dataProxy = undefined;
218
+ this.resolvesWaitingForLoad.forEach((wait) => wait.resolve());
219
+ this.resolvesWaitingForLoad = undefined;
220
+ }
221
+ }
222
+ return this;
223
+ }
224
+ /**
225
+ * Read-only accessor to the contents of this document.
226
+ */
227
+ get r() {
228
+ if (!this.data) {
229
+ throw new errors_1.FiretenderUsageError("load() must be called before reading the document.");
230
+ }
231
+ return this.data;
232
+ }
233
+ /**
234
+ * Writable accessor to update the contents of this document.
235
+ *
236
+ * Only use this accessor when making changes to the doc. The .r accessor is
237
+ * considerably more efficient when reading.
238
+ */
239
+ get w() {
240
+ if (this.isSettingNewContents) {
241
+ // No need to monitor changes if we're setting rather than updating.
242
+ return this.data;
243
+ }
244
+ if (!this.dataProxy) {
245
+ if (!this.data) {
246
+ // TODO #23: Consider being able to update a doc without loading it.
247
+ throw new errors_1.FiretenderUsageError("load() must be called before updating the document.");
248
+ }
249
+ this.dataProxy = (0, proxies_1.watchFieldForChanges)([], this.schema, this.data, this.addToUpdateList.bind(this));
250
+ }
251
+ return this.dataProxy;
252
+ }
253
+ /**
254
+ * Writable accessor to overwrite all the document data.
255
+ */
256
+ set w(newData) {
257
+ this.data = this.schema.parse(newData);
258
+ this.isSettingNewContents = true;
259
+ this.dataProxy = undefined;
260
+ }
261
+ /**
262
+ * Writes the document or any updates to Firestore.
263
+ */
264
+ async write() {
265
+ // For new docs, this.data should contain its initial state.
266
+ if (this.isSettingNewContents) {
267
+ (0, ts_helpers_1.assertIsDefined)(this.data);
268
+ if (this.ref instanceof firestore_deps_1.DocumentReference) {
269
+ try {
270
+ await (0, firestore_deps_1.setDoc)(this.ref, this.data);
271
+ }
272
+ catch (error) {
273
+ (0, errors_1.addContextToError)(error, "setDoc", this.ref, this.data);
274
+ throw error;
275
+ }
276
+ }
277
+ else {
278
+ try {
279
+ this.ref = await (0, firestore_deps_1.addDoc)(this.ref, this.data);
280
+ }
281
+ catch (error) {
282
+ (0, errors_1.addContextToError)(error, "addDoc", this.ref, this.data);
283
+ throw error;
284
+ }
285
+ this.docID = this.ref.path.split("/").pop(); // ID is last part of path.
286
+ }
287
+ this.isSettingNewContents = false;
288
+ this.isNewDoc = false;
289
+ }
290
+ // For existing docs, this.updates should contain a list of changes.
291
+ else {
292
+ if (!(this.ref instanceof firestore_deps_1.DocumentReference)) {
293
+ // We should never get here.
294
+ throw new errors_1.FiretenderInternalError("Internal error. Firetender object should always reference a document when updating an existing doc.");
295
+ }
296
+ if (this.updates.size > 0) {
297
+ const updateData = Object.fromEntries(this.updates);
298
+ try {
299
+ await (0, firestore_deps_1.updateDoc)(this.ref, updateData);
300
+ }
301
+ catch (error) {
302
+ (0, errors_1.addContextToError)(error, "updateDoc", this.ref, updateData);
303
+ throw error;
304
+ }
305
+ this.updates.clear();
306
+ }
307
+ }
308
+ return this;
309
+ }
310
+ /**
311
+ * Updates the document's data with a single call.
312
+ *
313
+ * This function loads the document's data, if necessary; calls the given
314
+ * function to make changes to the data; then write the changes to Firestore.
315
+ * If nothing else, it helps you avoid forgetting to call .write()!
316
+ *
317
+ * @param mutator function that accepts a writable data object and makes
318
+ * changes to it.
319
+ */
320
+ async update(mutator) {
321
+ await this.load();
322
+ mutator(this.w);
323
+ await this.write();
324
+ return this;
325
+ }
326
+ //////////////////////////////////////////////////////////////////////////////
327
+ // Private functions
328
+ /**
329
+ * Adds a field and its new value to the list of updates to be passed to
330
+ * Firestore's updateDoc(). Called when the proxies detect changes to the
331
+ * document data.
332
+ */
333
+ addToUpdateList(fieldPath, newValue) {
334
+ let pathString = "";
335
+ if (this.updates.size > 0) {
336
+ // If there is already a list of mutations to send to Firestore, check if
337
+ // a parent of this update is in it. Objects in the update list are
338
+ // references into this.data, so the parent field will automatically
339
+ // reflect this change; no additional Firestore mutation is needed.
340
+ if (fieldPath.some((field, i) => {
341
+ pathString = pathString ? `${pathString}.${field}` : field;
342
+ return i < fieldPath.length - 1 && this.updates.has(pathString);
343
+ })) {
344
+ return;
345
+ }
346
+ // Remove any previous updates that this one overwrites.
347
+ this.updates.forEach((value, key) => {
348
+ if (key.startsWith(pathString)) {
349
+ this.updates.delete(key);
350
+ }
351
+ });
352
+ }
353
+ else {
354
+ // Shortcut for the common case of a single update being made.
355
+ pathString = fieldPath.join(".");
356
+ }
357
+ this.updates.set(pathString, newValue);
358
+ }
359
+ }
360
+ exports.FiretenderDoc = FiretenderDoc;
361
+ //# sourceMappingURL=FiretenderDoc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":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AAE;YACzB,yEAAyE;YACzE,oEAAoE;YACpE,oEAAoE;YACpE,mEAAmE;YACnE,IACE,SAAS,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE;gBAC1B,UAAU,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;gBAC3D,OAAO,CAAC,GAAG,SAAS,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YAClE,CAAC,CAAC,EACF;gBACA,OAAO;aACR;YACD,wDAAwD;YACxD,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;gBAClC,IAAI,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE;oBAC9B,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;iBAC1B;YACH,CAAC,CAAC,CAAC;SACJ;aAAM;YACL,8DAA8D;YAC9D,UAAU,GAAG,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;SAClC;QACD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IACzC,CAAC;CACF;AA7aD,sCA6aC"}
@@ -0,0 +1,30 @@
1
+ import { CollectionReference, DocumentReference } from "./firestore-deps";
2
+ export declare class FiretenderError extends Error {
3
+ }
4
+ /**
5
+ * Something went wrong with a Firestore operation, such as trying to load a
6
+ * document that does not exist.
7
+ */
8
+ export declare class FiretenderIOError extends FiretenderError {
9
+ }
10
+ /**
11
+ * The caller did something wrong: a function was called at the wrong time or
12
+ * with the wrong parameters.
13
+ */
14
+ export declare class FiretenderUsageError extends FiretenderError {
15
+ }
16
+ /**
17
+ * Something went wrong internally. These errors indicate a bug in Firetender.
18
+ */
19
+ export declare class FiretenderInternalError extends FiretenderError {
20
+ }
21
+ /**
22
+ * Adds a "firetenderContext" property to the given error.
23
+ *
24
+ * @param error the error to which the context is added. If `error` is not an
25
+ * object, this call does not modify it.
26
+ * @param call the name of the Firestore function in which the error occurred.
27
+ * @param ref the path of the target document or collection, if any.
28
+ * @param data arbitrary data associated with this call.
29
+ */
30
+ export declare function addContextToError(error: any, call: string, ref?: DocumentReference | CollectionReference, data?: any): void;
package/dist/errors.js ADDED
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addContextToError = exports.FiretenderInternalError = exports.FiretenderUsageError = exports.FiretenderIOError = exports.FiretenderError = void 0;
4
+ class FiretenderError extends Error {
5
+ }
6
+ exports.FiretenderError = FiretenderError;
7
+ /**
8
+ * Something went wrong with a Firestore operation, such as trying to load a
9
+ * document that does not exist.
10
+ */
11
+ class FiretenderIOError extends FiretenderError {
12
+ }
13
+ exports.FiretenderIOError = FiretenderIOError;
14
+ /**
15
+ * The caller did something wrong: a function was called at the wrong time or
16
+ * with the wrong parameters.
17
+ */
18
+ class FiretenderUsageError extends FiretenderError {
19
+ }
20
+ exports.FiretenderUsageError = FiretenderUsageError;
21
+ /**
22
+ * Something went wrong internally. These errors indicate a bug in Firetender.
23
+ */
24
+ class FiretenderInternalError extends FiretenderError {
25
+ }
26
+ exports.FiretenderInternalError = FiretenderInternalError;
27
+ /**
28
+ * Adds a "firetenderContext" property to the given error.
29
+ *
30
+ * @param error the error to which the context is added. If `error` is not an
31
+ * object, this call does not modify it.
32
+ * @param call the name of the Firestore function in which the error occurred.
33
+ * @param ref the path of the target document or collection, if any.
34
+ * @param data arbitrary data associated with this call.
35
+ */
36
+ function addContextToError(error, call, ref, data) {
37
+ if (typeof error !== "object") {
38
+ return;
39
+ }
40
+ error.firetenderContext = { call };
41
+ if (ref) {
42
+ error.firetenderContext.ref = ref.path;
43
+ }
44
+ if (data !== undefined) {
45
+ error.firetenderContext.data = data;
46
+ }
47
+ }
48
+ exports.addContextToError = addContextToError;
49
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAEA,MAAa,eAAgB,SAAQ,KAAK;CAAG;AAA7C,0CAA6C;AAE7C;;;GAGG;AACH,MAAa,iBAAkB,SAAQ,eAAe;CAAG;AAAzD,8CAAyD;AAEzD;;;GAGG;AACH,MAAa,oBAAqB,SAAQ,eAAe;CAAG;AAA5D,oDAA4D;AAE5D;;GAEG;AACH,MAAa,uBAAwB,SAAQ,eAAe;CAAG;AAA/D,0DAA+D;AAE/D;;;;;;;;GAQG;AACH,SAAgB,iBAAiB,CAC/B,KAAU,EACV,IAAY,EACZ,GAA6C,EAC7C,IAAU;IAEV,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC7B,OAAO;KACR;IACD,KAAK,CAAC,iBAAiB,GAAG,EAAE,IAAI,EAAE,CAAC;IACnC,IAAI,GAAG,EAAE;QACP,KAAK,CAAC,iBAAiB,CAAC,GAAG,GAAG,GAAG,CAAC,IAAI,CAAC;KACxC;IACD,IAAI,IAAI,KAAK,SAAS,EAAE;QACtB,KAAK,CAAC,iBAAiB,CAAC,IAAI,GAAG,IAAI,CAAC;KACrC;AACH,CAAC;AAhBD,8CAgBC"}
@@ -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;AAHr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M,UAE0B;AAEtC,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,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>;