@hyper-fetch/firebase 5.0.1 → 5.1.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 (45) hide show
  1. package/README.md +2 -2
  2. package/dist/index.cjs.js +261 -750
  3. package/dist/index.cjs.js.map +4 -4
  4. package/dist/index.d.ts +20 -86
  5. package/dist/index.esm.js +207 -760
  6. package/dist/index.esm.js.map +4 -4
  7. package/package.json +2 -9
  8. package/src/adapter/{browser/adapter.browser.sockets.ts → adapter.sockets.ts} +1 -1
  9. package/src/adapter/index.ts +2 -2
  10. package/src/adapter/{browser/adapter.browser.types.ts → types/adapter.base.types.ts} +1 -1
  11. package/src/adapter/types/index.ts +1 -2
  12. package/src/constraints/constraints.types.ts +0 -24
  13. package/src/firestore/{browser/firestore.browser.methods.ts → firestore.methods.ts} +3 -4
  14. package/src/firestore/{browser/firestore.browser.sockets.ts → firestore.sockets.ts} +3 -2
  15. package/src/firestore/index.ts +2 -2
  16. package/src/firestore/utils/index.ts +2 -1
  17. package/src/firestore/utils/{firestore.utils.ts → result.utils.ts} +1 -1
  18. package/src/index.ts +0 -1
  19. package/src/realtime/index.ts +2 -2
  20. package/src/realtime/{browser/realtime.browser.methods.ts → realtime.methods.ts} +2 -2
  21. package/src/realtime/{browser/realtime.browser.sockets.ts → realtime.sockets.ts} +1 -1
  22. package/src/realtime/utils/index.ts +2 -1
  23. package/src/realtime/utils/{realtime.utils.ts → result.utils.ts} +1 -1
  24. package/src/utils/index.ts +0 -1
  25. package/src/adapter/admin/adapter.admin.sockets.ts +0 -14
  26. package/src/adapter/admin/adapter.admin.ts +0 -72
  27. package/src/adapter/admin/adapter.admin.types.ts +0 -15
  28. package/src/adapter/admin/index.ts +0 -3
  29. package/src/adapter/browser/index.ts +0 -3
  30. package/src/adapter/types/firestore.admin.types.ts +0 -17
  31. package/src/adapter/types/realtime.admin.types.ts +0 -17
  32. package/src/firestore/admin/firestore.admin.methods.ts +0 -86
  33. package/src/firestore/admin/firestore.admin.sockets.ts +0 -86
  34. package/src/firestore/admin/firestore.admin.utils.ts +0 -69
  35. package/src/firestore/admin/index.ts +0 -2
  36. package/src/firestore/browser/index.ts +0 -3
  37. package/src/realtime/admin/index.ts +0 -2
  38. package/src/realtime/admin/realtime.admin.methods.ts +0 -74
  39. package/src/realtime/admin/realtime.admin.sockets.ts +0 -93
  40. package/src/realtime/admin/realtime.admin.utils.ts +0 -54
  41. package/src/realtime/browser/index.ts +0 -3
  42. package/src/utils/cache.utils.ts +0 -33
  43. /package/src/adapter/{browser/adapter.browser.ts → adapter.ts} +0 -0
  44. /package/src/firestore/{browser/firestore.browser.utils.ts → utils/constraints.utils.ts} +0 -0
  45. /package/src/realtime/{browser/realtime.browser.utils.ts → utils/constraints.utils.ts} +0 -0
package/dist/index.esm.js CHANGED
@@ -1,36 +1,22 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
8
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
9
- }) : x)(function(x) {
10
- if (typeof require !== "undefined")
11
- return require.apply(this, arguments);
12
- throw new Error('Dynamic require of "' + x + '" is not supported');
13
- });
14
- var __commonJS = (cb, mod) => function __require2() {
15
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
16
- };
17
- var __export = (target, all) => {
18
- for (var name in all)
19
- __defProp(target, name, { get: all[name], enumerable: true });
20
- };
21
- var __copyProps = (to, from, except, desc) => {
22
- if (from && typeof from === "object" || typeof from === "function") {
23
- for (let key of __getOwnPropNames(from))
24
- if (!__hasOwnProp.call(to, key) && key !== except)
25
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
26
- }
27
- return to;
28
- };
29
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
30
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
31
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
32
- mod
33
- ));
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
34
20
  var __async = (__this, __arguments, generator) => {
35
21
  return new Promise((resolve, reject) => {
36
22
  var fulfilled = (value) => {
@@ -52,93 +38,6 @@ var __async = (__this, __arguments, generator) => {
52
38
  });
53
39
  };
54
40
 
55
- // ../../node_modules/methods/index.js
56
- var require_methods = __commonJS({
57
- "../../node_modules/methods/index.js"(exports, module) {
58
- "use strict";
59
- var http = __require("http");
60
- module.exports = getCurrentNodeMethods() || getBasicNodeMethods();
61
- function getCurrentNodeMethods() {
62
- return http.METHODS && http.METHODS.map(function lowerCaseMethod(method) {
63
- return method.toLowerCase();
64
- });
65
- }
66
- function getBasicNodeMethods() {
67
- return [
68
- "get",
69
- "post",
70
- "put",
71
- "head",
72
- "delete",
73
- "options",
74
- "trace",
75
- "copy",
76
- "lock",
77
- "mkcol",
78
- "move",
79
- "purge",
80
- "propfind",
81
- "proppatch",
82
- "unlock",
83
- "report",
84
- "mkactivity",
85
- "checkout",
86
- "merge",
87
- "m-search",
88
- "notify",
89
- "subscribe",
90
- "unsubscribe",
91
- "patch",
92
- "search",
93
- "connect"
94
- ];
95
- }
96
- }
97
- });
98
-
99
- // src/index.ts
100
- var src_exports = {};
101
- __export(src_exports, {
102
- $endAt: () => $endAt,
103
- $endBefore: () => $endBefore,
104
- $equalTo: () => $equalTo,
105
- $limit: () => $limit,
106
- $limitToFirst: () => $limitToFirst,
107
- $limitToLast: () => $limitToLast,
108
- $orderBy: () => $orderBy,
109
- $orderByChild: () => $orderByChild,
110
- $orderByKey: () => $orderByKey,
111
- $orderByValue: () => $orderByValue,
112
- $startAfter: () => $startAfter,
113
- $startAt: () => $startAt,
114
- $where: () => $where,
115
- FirestoreMethods: () => FirestoreMethods,
116
- FirestoreQueryConstraints: () => FirestoreQueryConstraints,
117
- RealtimeDBMethods: () => RealtimeDBMethods,
118
- RealtimeQueryConstraints: () => RealtimeQueryConstraints,
119
- SharedQueryConstraints: () => SharedQueryConstraints,
120
- applyFireStoreAdminConstraint: () => applyFireStoreAdminConstraint,
121
- applyFireStoreAdminConstraints: () => applyFireStoreAdminConstraints,
122
- applyRealtimeAdminConstraint: () => applyRealtimeAdminConstraint,
123
- applyRealtimeAdminConstraints: () => applyRealtimeAdminConstraints,
124
- firebaseAdapter: () => firebaseAdapter,
125
- firebaseAdminAdapter: () => firebaseAdminAdapter,
126
- firebaseSocketsAdapter: () => firebaseSocketsAdapter,
127
- firebaseSocketsAdminAdapter: () => firebaseSocketsAdminAdapter,
128
- firestoreSockets: () => firestoreSockets,
129
- getFirestoreAdminMethods: () => getFirestoreAdminMethods,
130
- getFirestoreBrowserMethods: () => getFirestoreBrowserMethods,
131
- getGroupedResultFirestore: () => getGroupedResultFirestore,
132
- getOrderedResultFirestore: () => getOrderedResultFirestore,
133
- getOrderedResultRealtime: () => getOrderedResultRealtime,
134
- getRealtimeDbAdminMethods: () => getRealtimeDbAdminMethods,
135
- getRealtimeDbBrowserMethods: () => getRealtimeDbBrowserMethods,
136
- getRef: () => getRef,
137
- mapConstraint: () => mapConstraint,
138
- mapRealtimeConstraint: () => mapRealtimeConstraint,
139
- realtimeSockets: () => realtimeSockets
140
- });
141
-
142
41
  // src/adapter/types/adapter.firestore.types.ts
143
42
  var FirestoreMethods = /* @__PURE__ */ ((FirestoreMethods2) => {
144
43
  FirestoreMethods2["addDoc"] = "addDoc";
@@ -160,51 +59,32 @@ var RealtimeDBMethods = /* @__PURE__ */ ((RealtimeDBMethods2) => {
160
59
  return RealtimeDBMethods2;
161
60
  })(RealtimeDBMethods || {});
162
61
 
163
- // src/adapter/admin/adapter.admin.ts
62
+ // src/adapter/adapter.ts
164
63
  import { getAdapterBindings } from "@hyper-fetch/core";
165
- import { Firestore as Firestore3 } from "firebase-admin/firestore";
166
-
167
- // src/firestore/browser/firestore.browser.methods.ts
168
- import {
169
- addDoc,
170
- collection,
171
- deleteDoc,
172
- doc,
173
- getDoc,
174
- getDocs,
175
- query,
176
- setDoc,
177
- updateDoc
178
- } from "firebase/firestore";
179
-
180
- // src/utils/misc.ts
181
- var getStatus = (res) => {
182
- return Array.isArray(res) && res.length === 0 || res == null ? "emptyResource" : "success";
183
- };
184
- var isDocOrQuery = (fullUrl) => {
185
- const withoutSurroundingSlashes = fullUrl.replace(/^\/|\/$/g, "");
186
- const pathElements = withoutSurroundingSlashes.split("/").length;
187
- return pathElements % 2 === 0 ? "doc" : "query";
188
- };
64
+ import { Database as Database3 } from "firebase/database";
189
65
 
190
- // src/firestore/utils/firestore.utils.ts
191
- var getOrderedResultFirestore = (snapshot) => {
192
- const result = [];
193
- snapshot.docs.forEach((d) => {
194
- result.push(d.data());
195
- });
196
- return result.length > 0 ? result : null;
197
- };
198
- var getGroupedResultFirestore = (snapshot) => {
199
- const groupedResult = { added: [], modified: [], removed: [] };
200
- snapshot.docChanges().forEach((change) => {
201
- groupedResult[change.type].push(change.doc.data());
66
+ // src/realtime/utils/result.utils.ts
67
+ var getOrderedResultRealtime = (snapshot) => {
68
+ const res = [];
69
+ snapshot.forEach((child) => {
70
+ res.push(__spreadProps(__spreadValues({}, child.val()), { __key: child.key }));
202
71
  });
203
- return [...groupedResult.added, ...groupedResult.modified, ...groupedResult.removed].length > 0 ? groupedResult : null;
72
+ return res.length > 0 ? res : null;
204
73
  };
205
74
 
206
- // src/firestore/browser/firestore.browser.utils.ts
207
- import { endAt, endBefore, limit, orderBy, startAfter, startAt, where } from "firebase/firestore";
75
+ // src/realtime/utils/constraints.utils.ts
76
+ import {
77
+ endAt,
78
+ endBefore,
79
+ equalTo,
80
+ limitToFirst,
81
+ limitToLast,
82
+ orderByChild,
83
+ orderByKey,
84
+ orderByValue,
85
+ startAfter,
86
+ startAt
87
+ } from "firebase/database";
208
88
 
209
89
  // src/constraints/firebase.constraints.ts
210
90
  var SharedQueryConstraints = /* @__PURE__ */ ((SharedQueryConstraints2) => {
@@ -316,107 +196,68 @@ var $equalTo = (value) => {
316
196
  };
317
197
  };
318
198
 
319
- // src/firestore/browser/firestore.browser.utils.ts
320
- var mapConstraint = ({ type, values }) => {
199
+ // src/realtime/utils/constraints.utils.ts
200
+ var mapRealtimeConstraint = ({ type, values }) => {
321
201
  switch (type) {
322
- case "where" /* WHERE */: {
323
- const [fieldPath, strOp, value] = values;
324
- return where(fieldPath, strOp, value);
202
+ case "orderByChild" /* ORDER_BY_CHILD */: {
203
+ const [value] = values;
204
+ return orderByChild(value);
325
205
  }
326
- case "orderBy" /* ORDER_BY */: {
327
- const [field, ord] = values;
328
- return orderBy(field, ord);
206
+ case "orderByKey" /* ORDER_BY_KEY */: {
207
+ return orderByKey();
329
208
  }
330
- case "limit" /* LIMIT */: {
331
- const [limitValue] = values;
332
- return limit(limitValue);
209
+ case "orderByValue" /* ORDER_BY_VALUE */: {
210
+ return orderByValue();
333
211
  }
334
212
  case "startAt" /* START_AT */: {
335
- const [docOrFields] = values;
336
- return startAt(docOrFields);
213
+ const [[value]] = values;
214
+ return startAt(value);
337
215
  }
338
216
  case "startAfter" /* START_AFTER */: {
339
- const [docOrFields] = values;
340
- return startAfter(docOrFields);
217
+ const [[value]] = values;
218
+ return startAfter(value);
341
219
  }
342
220
  case "endAt" /* END_AT */: {
343
- const [docOrFields] = values;
344
- return endAt(docOrFields);
221
+ const [[value]] = values;
222
+ return endAt(value);
345
223
  }
346
224
  case "endBefore" /* END_BEFORE */: {
347
- const [docOrFields] = values;
348
- return endBefore(docOrFields);
225
+ const [[value]] = values;
226
+ return endBefore(value);
227
+ }
228
+ case "limitToFirst" /* LIMIT_TO_FIRST */: {
229
+ const [value] = values;
230
+ return limitToFirst(value);
231
+ }
232
+ case "limitToLast" /* LIMIT_TO_LAST */: {
233
+ const [value] = values;
234
+ return limitToLast(value);
235
+ }
236
+ case "equalTo" /* EQUAL_TO */: {
237
+ const [value] = values;
238
+ return equalTo(value);
349
239
  }
350
240
  default:
351
241
  throw new Error(`Unknown method ${type}`);
352
242
  }
353
243
  };
354
244
 
355
- // src/firestore/browser/firestore.browser.methods.ts
356
- var getFirestoreBrowserMethods = (request, database, url, onSuccess, onError, resolve, events) => {
357
- const [cleanUrl] = url.split("?");
358
- const methods = {
359
- getDoc: () => __async(void 0, null, function* () {
360
- const path = doc(database, cleanUrl);
361
- const snapshot = yield getDoc(path);
362
- const result = snapshot.data() || null;
363
- const status = result ? "success" : "emptyResource";
364
- return { result, status, extra: { ref: path, snapshot } };
365
- }),
366
- getDocs: (_0) => __async(void 0, [_0], function* ({
367
- constraints = []
368
- }) {
369
- const queryConstraints = constraints.map((constr) => mapConstraint(constr));
370
- const path = collection(database, cleanUrl);
371
- const q = query(path, ...queryConstraints);
372
- const querySnapshot = yield getDocs(q);
373
- const result = getOrderedResultFirestore(querySnapshot);
374
- const status = getStatus(result);
375
- return { result, status, extra: { ref: path, snapshot: querySnapshot } };
376
- }),
377
- setDoc: (_0) => __async(void 0, [_0], function* ({ data, options }) {
378
- const path = doc(database, cleanUrl);
379
- const merge = (options == null ? void 0 : options.merge) === true;
380
- yield setDoc(path, data, { merge });
381
- return { result: data, status: "success", extra: { ref: path } };
382
- }),
383
- addDoc: (_0) => __async(void 0, [_0], function* ({ data }) {
384
- const path = collection(database, cleanUrl);
385
- const docRef = yield addDoc(path, data);
386
- return { result: data, status: "success", extra: { ref: docRef } };
387
- }),
388
- updateDoc: (_0) => __async(void 0, [_0], function* ({ data }) {
389
- const path = doc(database, cleanUrl);
390
- yield updateDoc(path, data);
391
- return { result: data, status: "success", extra: { ref: path } };
392
- }),
393
- deleteDoc: () => __async(void 0, null, function* () {
394
- const path = doc(database, cleanUrl);
395
- yield deleteDoc(path);
396
- return { result: null, status: "success", extra: { ref: path } };
397
- })
398
- };
399
- return (methodName, data) => __async(void 0, null, function* () {
400
- try {
401
- events.onRequestStart();
402
- const { result, status, extra } = yield methods[methodName](data);
403
- events.onRequestEnd();
404
- events.onResponseStart();
405
- onSuccess(result, status, extra, resolve);
406
- events.onResponseEnd();
407
- } catch (e) {
408
- events.onRequestEnd();
409
- events.onResponseStart();
410
- onError(e, "error", {}, resolve);
411
- events.onResponseEnd();
412
- }
413
- });
245
+ // src/realtime/realtime.sockets.ts
246
+ import { getSocketAdapterBindings } from "@hyper-fetch/sockets";
247
+ import { onValue, query, ref, goOffline, goOnline } from "firebase/database";
248
+
249
+ // src/utils/misc.ts
250
+ var getStatus = (res) => {
251
+ return Array.isArray(res) && res.length === 0 || res == null ? "emptyResource" : "success";
252
+ };
253
+ var isDocOrQuery = (fullUrl) => {
254
+ const withoutSurroundingSlashes = fullUrl.replace(/^\/|\/$/g, "");
255
+ const pathElements = withoutSurroundingSlashes.split("/").length;
256
+ return pathElements % 2 === 0 ? "doc" : "query";
414
257
  };
415
258
 
416
- // src/firestore/browser/firestore.browser.sockets.ts
417
- import { getSocketAdapterBindings } from "@hyper-fetch/sockets";
418
- import { onSnapshot, doc as doc2, query as query2, collection as collection2, disableNetwork, enableNetwork } from "firebase/firestore";
419
- var firestoreSockets = (database) => {
259
+ // src/realtime/realtime.sockets.ts
260
+ var realtimeSockets = (database) => {
420
261
  return (socket) => {
421
262
  const {
422
263
  open,
@@ -436,12 +277,12 @@ var firestoreSockets = (database) => {
436
277
  const connect = () => {
437
278
  const enabled = onConnect();
438
279
  if (enabled) {
439
- enableNetwork(database);
280
+ goOnline(database);
440
281
  onOpen();
441
282
  }
442
283
  };
443
284
  const disconnect = () => {
444
- disableNetwork(database);
285
+ goOffline(database);
445
286
  onDisconnect();
446
287
  onClose();
447
288
  };
@@ -449,36 +290,32 @@ var firestoreSockets = (database) => {
449
290
  onReconnect(disconnect, connect);
450
291
  };
451
292
  const listen = (listener, callback) => {
293
+ var _a;
452
294
  const fullUrl = socket.url + listener.endpoint;
295
+ const path = ref(database, fullUrl);
453
296
  const { options } = listener;
454
- let path;
455
- const queryType = isDocOrQuery(fullUrl);
456
- if (queryType === "doc") {
457
- path = doc2(database, fullUrl);
458
- } else {
459
- const constraints = (options == null ? void 0 : options.constraints) || [];
460
- const queryConstraints = constraints.map((constr) => mapConstraint(constr)) || [];
461
- path = query2(collection2(database, fullUrl), ...queryConstraints);
462
- }
297
+ const onlyOnce = (options == null ? void 0 : options.onlyOnce) || false;
298
+ const params = ((_a = options == null ? void 0 : options.constraints) == null ? void 0 : _a.map((constraint) => mapRealtimeConstraint(constraint))) || [];
299
+ const queryConstraints = query(path, ...params);
463
300
  let unsubscribe = () => {
464
301
  };
465
302
  let unmount = () => {
466
303
  };
467
304
  let clearListeners = () => {
468
305
  };
469
- unsubscribe = onSnapshot(
470
- path,
306
+ unsubscribe = onValue(
307
+ queryConstraints,
471
308
  (snapshot) => {
472
- const response = queryType === "doc" ? snapshot.data() || null : getOrderedResultFirestore(snapshot);
309
+ const response = isDocOrQuery(fullUrl) === "doc" ? snapshot.val() : getOrderedResultRealtime(snapshot);
473
310
  const status = getStatus(response);
474
- const groupedResult = (options == null ? void 0 : options.groupByChangeType) === true ? getGroupedResultFirestore(snapshot) : null;
475
- const extra = { ref: path, snapshot, groupedResult, status };
311
+ const extra = { ref: path, snapshot, status };
476
312
  callback({ data: response, extra });
477
313
  onEvent(listener.endpoint, response, extra);
478
314
  },
479
315
  (error) => {
480
316
  onError(error);
481
- }
317
+ },
318
+ { onlyOnce }
482
319
  );
483
320
  unmount = onListen(listener, callback, unsubscribe);
484
321
  clearListeners = () => {
@@ -488,7 +325,7 @@ var firestoreSockets = (database) => {
488
325
  return clearListeners;
489
326
  };
490
327
  const emit = () => __async(void 0, null, function* () {
491
- throw new Error("Cannot emit from Firestore database socket.");
328
+ throw new Error("Cannot emit from Realtime database socket.");
492
329
  });
493
330
  return {
494
331
  open,
@@ -505,44 +342,36 @@ var firestoreSockets = (database) => {
505
342
  };
506
343
  };
507
344
 
508
- // src/firestore/admin/firestore.admin.methods.ts
509
- var getFirestoreAdminMethods = (request, database, url, onSuccess, onError, resolve, events) => {
510
- const [cleanUrl] = url.split("?");
345
+ // src/realtime/realtime.methods.ts
346
+ import { get, push, query as query2, ref as ref2, remove, set, update } from "firebase/database";
347
+ var getRealtimeDbBrowserMethods = (request, database, url, onSuccess, onError, resolve, events) => {
348
+ const [fullUrl] = url.split("?");
349
+ const path = ref2(database, fullUrl);
511
350
  const methods = {
512
- getDoc: () => __async(void 0, null, function* () {
513
- const path = getRef(database, cleanUrl);
514
- const snapshot = yield path.get();
515
- const result = snapshot.data() || null;
516
- const status = result ? "success" : "emptyResource";
517
- return { result, status, extra: { ref: path, snapshot } };
518
- }),
519
- getDocs: (_0) => __async(void 0, [_0], function* ({ constraints = [] }) {
520
- const path = getRef(database, cleanUrl);
521
- const query5 = applyFireStoreAdminConstraints(path, constraints);
522
- const querySnapshot = yield query5.get();
523
- const result = getOrderedResultFirestore(querySnapshot);
524
- const status = getStatus(result);
525
- return { result, status, extra: { ref: path, snapshot: querySnapshot } };
351
+ get: (_0) => __async(void 0, [_0], function* ({
352
+ constraints = []
353
+ }) {
354
+ const params = constraints.map((constraint) => mapRealtimeConstraint(constraint));
355
+ const q = query2(path, ...params);
356
+ const snapshot = yield get(q);
357
+ const res = isDocOrQuery(fullUrl) === "doc" ? snapshot.val() : getOrderedResultRealtime(snapshot);
358
+ const status = getStatus(res);
359
+ return { result: res, status, extra: { ref: path, snapshot } };
526
360
  }),
527
- setDoc: (_0) => __async(void 0, [_0], function* ({ data, options }) {
528
- const path = getRef(database, cleanUrl);
529
- const merge = (options == null ? void 0 : options.merge) === true;
530
- const res = yield path.set(data, { merge });
531
- return { result: res, status: "success", extra: { ref: path } };
361
+ set: (_0) => __async(void 0, [_0], function* ({ data }) {
362
+ yield set(path, data);
363
+ return { result: data, status: "success", extra: { ref: path } };
532
364
  }),
533
- addDoc: (_0) => __async(void 0, [_0], function* ({ data }) {
534
- const ref3 = getRef(database, cleanUrl);
535
- const docRef = yield ref3.add(data);
536
- return { result: data, status: "success", extra: { ref: docRef } };
365
+ push: (_0) => __async(void 0, [_0], function* ({ data }) {
366
+ const resRef = yield push(path, data);
367
+ return { result: __spreadProps(__spreadValues({}, data), { __key: resRef.key }), status: "success", extra: { ref: resRef, key: resRef.key } };
537
368
  }),
538
- updateDoc: (_0) => __async(void 0, [_0], function* ({ data }) {
539
- const path = getRef(database, cleanUrl);
540
- yield path.update(data);
369
+ update: (_0) => __async(void 0, [_0], function* ({ data }) {
370
+ yield update(path, data);
541
371
  return { result: data, status: "success", extra: { ref: path } };
542
372
  }),
543
- deleteDoc: () => __async(void 0, null, function* () {
544
- const path = getRef(database, cleanUrl);
545
- yield path.delete();
373
+ remove: () => __async(void 0, null, function* () {
374
+ yield remove(path);
546
375
  return { result: null, status: "success", extra: { ref: path } };
547
376
  })
548
377
  };
@@ -563,191 +392,111 @@ var getFirestoreAdminMethods = (request, database, url, onSuccess, onError, reso
563
392
  });
564
393
  };
565
394
 
566
- // src/firestore/admin/firestore.admin.utils.ts
567
- var getRef = (db, fullUrl) => {
568
- const withoutSurroundingSlashes = fullUrl.replace(/^\/|\/$/g, "");
569
- const urlParts = withoutSurroundingSlashes.split("/").map((element, index) => {
570
- return index % 2 === 0 ? ["collection", element] : ["doc", element];
395
+ // src/firestore/utils/result.utils.ts
396
+ var getOrderedResultFirestore = (snapshot) => {
397
+ const result = [];
398
+ snapshot.docs.forEach((d) => {
399
+ result.push(__spreadProps(__spreadValues({}, d.data()), { __key: d.id }));
571
400
  });
572
- return urlParts.reduce((_db, value) => {
573
- const [method, pathPart] = value;
574
- if (method === "doc" && "doc" in _db) {
575
- return _db.doc(pathPart);
576
- }
577
- if (method === "collection" && "collection" in _db) {
578
- return _db.collection(pathPart);
579
- }
580
- return _db;
581
- }, db);
401
+ return result.length > 0 ? result : null;
402
+ };
403
+ var getGroupedResultFirestore = (snapshot) => {
404
+ const groupedResult = { added: [], modified: [], removed: [] };
405
+ snapshot.docChanges().forEach((change) => {
406
+ groupedResult[change.type].push(change.doc.data());
407
+ });
408
+ return [...groupedResult.added, ...groupedResult.modified, ...groupedResult.removed].length > 0 ? groupedResult : null;
582
409
  };
583
- var applyFireStoreAdminConstraint = (collectionRef, { type, values }) => {
410
+
411
+ // src/firestore/utils/constraints.utils.ts
412
+ import { endAt as endAt2, endBefore as endBefore2, limit, orderBy, startAfter as startAfter2, startAt as startAt2, where } from "firebase/firestore";
413
+ var mapConstraint = ({ type, values }) => {
584
414
  switch (type) {
585
415
  case "where" /* WHERE */: {
586
416
  const [fieldPath, strOp, value] = values;
587
- return collectionRef.where(fieldPath, strOp, value);
417
+ return where(fieldPath, strOp, value);
588
418
  }
589
419
  case "orderBy" /* ORDER_BY */: {
590
420
  const [field, ord] = values;
591
- return collectionRef.orderBy(field, ord);
421
+ return orderBy(field, ord);
592
422
  }
593
423
  case "limit" /* LIMIT */: {
594
424
  const [limitValue] = values;
595
- return collectionRef.limit(limitValue);
425
+ return limit(limitValue);
596
426
  }
597
427
  case "startAt" /* START_AT */: {
598
428
  const [docOrFields] = values;
599
- return collectionRef.startAt(docOrFields);
429
+ return startAt2(docOrFields);
600
430
  }
601
431
  case "startAfter" /* START_AFTER */: {
602
432
  const [docOrFields] = values;
603
- return collectionRef.startAfter(docOrFields);
433
+ return startAfter2(docOrFields);
604
434
  }
605
435
  case "endAt" /* END_AT */: {
606
436
  const [docOrFields] = values;
607
- return collectionRef.endAt(docOrFields);
437
+ return endAt2(docOrFields);
608
438
  }
609
439
  case "endBefore" /* END_BEFORE */: {
610
440
  const [docOrFields] = values;
611
- return collectionRef.endBefore(docOrFields);
441
+ return endBefore2(docOrFields);
612
442
  }
613
443
  default:
614
444
  throw new Error(`Unknown method ${type}`);
615
445
  }
616
446
  };
617
- var applyFireStoreAdminConstraints = (collectionRef, constraints) => {
618
- return constraints.reduce((collection3, constraint) => {
619
- return applyFireStoreAdminConstraint(collection3, constraint);
620
- }, collectionRef);
621
- };
622
447
 
623
- // src/realtime/admin/realtime.admin.methods.ts
624
- var getRealtimeDbAdminMethods = (request, database, url, onSuccess, onError, resolve, events) => {
625
- const [fullUrl] = url.split("?");
626
- const path = database.ref(fullUrl);
448
+ // src/firestore/firestore.methods.ts
449
+ import {
450
+ addDoc,
451
+ collection,
452
+ deleteDoc,
453
+ doc,
454
+ getDoc,
455
+ getDocs,
456
+ query as query3,
457
+ setDoc,
458
+ updateDoc
459
+ } from "firebase/firestore";
460
+ var getFirestoreBrowserMethods = (request, database, url, onSuccess, onError, resolve, events) => {
461
+ const [cleanUrl] = url.split("?");
627
462
  const methods = {
628
- get: (_0) => __async(void 0, [_0], function* ({ constraints }) {
629
- const docOrQuery = isDocOrQuery(fullUrl);
630
- const q = applyRealtimeAdminConstraints(path, constraints);
631
- const snapshot = yield q.get();
632
- const res = docOrQuery === "doc" ? snapshot.val() : getOrderedResultRealtime(snapshot);
633
- const status = getStatus(res);
634
- return { result: res, status, extra: { ref: path, snapshot } };
635
- }),
636
- set: (_0) => __async(void 0, [_0], function* ({ data }) {
637
- yield path.set(data);
638
- return { result: data, status: "success", extra: { ref: path } };
639
- }),
640
- push: (_0) => __async(void 0, [_0], function* ({ data }) {
641
- const resRef = yield path.push(data);
642
- return { result: data, status: "success", extra: { ref: resRef, key: resRef.key } };
643
- }),
644
- update: (_0) => __async(void 0, [_0], function* ({ data }) {
645
- yield path.update(data);
646
- return { result: data, status: "success", extra: { ref: path } };
463
+ getDoc: () => __async(void 0, null, function* () {
464
+ const path = doc(database, cleanUrl);
465
+ const snapshot = yield getDoc(path);
466
+ const result = snapshot.data() ? __spreadProps(__spreadValues({}, snapshot.data()), { __key: snapshot.id }) : null;
467
+ const status = result ? "success" : "emptyResource";
468
+ return { result, status, extra: { ref: path, snapshot } };
647
469
  }),
648
- remove: () => __async(void 0, null, function* () {
649
- yield path.remove();
650
- return { result: null, status: "success", extra: { ref: path } };
651
- })
652
- };
653
- return (methodName, data) => __async(void 0, null, function* () {
654
- try {
655
- events.onRequestStart();
656
- const { result, status, extra } = yield methods[methodName](data);
657
- events.onRequestEnd();
658
- events.onResponseStart();
659
- onSuccess(result, status, extra, resolve);
660
- events.onResponseEnd();
661
- } catch (e) {
662
- events.onRequestEnd();
663
- events.onResponseStart();
664
- onError(e, "error", {}, resolve);
665
- events.onResponseEnd();
666
- }
667
- });
668
- };
669
-
670
- // src/realtime/admin/realtime.admin.utils.ts
671
- var applyRealtimeAdminConstraint = (ref3, { type, values }) => {
672
- switch (type) {
673
- case "orderByChild" /* ORDER_BY_CHILD */: {
674
- const [value] = values;
675
- return ref3.orderByChild(value);
676
- }
677
- case "orderByKey" /* ORDER_BY_KEY */: {
678
- return ref3.orderByKey();
679
- }
680
- case "orderByValue" /* ORDER_BY_VALUE */: {
681
- return ref3.orderByValue();
682
- }
683
- case "startAt" /* START_AT */: {
684
- const [[value]] = values;
685
- return ref3.startAt(value);
686
- }
687
- case "startAfter" /* START_AFTER */: {
688
- const [[value]] = values;
689
- return ref3.startAfter(value);
690
- }
691
- case "endAt" /* END_AT */: {
692
- const [[value]] = values;
693
- return ref3.endAt(value);
694
- }
695
- case "endBefore" /* END_BEFORE */: {
696
- const [[value]] = values;
697
- return ref3.endBefore(value);
698
- }
699
- case "limitToFirst" /* LIMIT_TO_FIRST */: {
700
- const [value] = values;
701
- return ref3.limitToFirst(value);
702
- }
703
- case "limitToLast" /* LIMIT_TO_LAST */: {
704
- const [value] = values;
705
- return ref3.limitToLast(value);
706
- }
707
- case "equalTo" /* EQUAL_TO */: {
708
- const [value] = values;
709
- return ref3.equalTo(value);
710
- }
711
- default:
712
- throw new Error(`Unknown method ${type}`);
713
- }
714
- };
715
- var applyRealtimeAdminConstraints = (ref3, constraints) => {
716
- return constraints.reduce((collection3, constraint) => {
717
- return applyRealtimeAdminConstraint(collection3, constraint);
718
- }, ref3);
719
- };
720
-
721
- // src/realtime/browser/realtime.browser.methods.ts
722
- import { get, push, query as query3, ref, remove, set, update } from "firebase/database";
723
- var getRealtimeDbBrowserMethods = (request, database, url, onSuccess, onError, resolve, events) => {
724
- const [fullUrl] = url.split("?");
725
- const path = ref(database, fullUrl);
726
- const methods = {
727
- get: (_0) => __async(void 0, [_0], function* ({
470
+ getDocs: (_0) => __async(void 0, [_0], function* ({
728
471
  constraints = []
729
472
  }) {
730
- const params = constraints.map((constraint) => mapRealtimeConstraint(constraint));
731
- const q = query3(path, ...params);
732
- const snapshot = yield get(q);
733
- const res = isDocOrQuery(fullUrl) === "doc" ? snapshot.val() : getOrderedResultRealtime(snapshot);
734
- const status = getStatus(res);
735
- return { result: res, status, extra: { ref: path, snapshot } };
473
+ const queryConstraints = constraints.map((constr) => mapConstraint(constr));
474
+ const path = collection(database, cleanUrl);
475
+ const q = query3(path, ...queryConstraints);
476
+ const querySnapshot = yield getDocs(q);
477
+ const result = getOrderedResultFirestore(querySnapshot);
478
+ const status = getStatus(result);
479
+ return { result, status, extra: { ref: path, snapshot: querySnapshot } };
736
480
  }),
737
- set: (_0) => __async(void 0, [_0], function* ({ data }) {
738
- yield set(path, data);
481
+ setDoc: (_0) => __async(void 0, [_0], function* ({ data, options }) {
482
+ const path = doc(database, cleanUrl);
483
+ const merge = (options == null ? void 0 : options.merge) === true;
484
+ yield setDoc(path, data, { merge });
739
485
  return { result: data, status: "success", extra: { ref: path } };
740
486
  }),
741
- push: (_0) => __async(void 0, [_0], function* ({ data }) {
742
- const resRef = yield push(path, data);
743
- return { result: data, status: "success", extra: { ref: resRef, key: resRef.key } };
487
+ addDoc: (_0) => __async(void 0, [_0], function* ({ data }) {
488
+ const path = collection(database, cleanUrl);
489
+ const docRef = yield addDoc(path, data);
490
+ return { result: __spreadProps(__spreadValues({}, data), { __key: docRef.id }), status: "success", extra: { ref: docRef } };
744
491
  }),
745
- update: (_0) => __async(void 0, [_0], function* ({ data }) {
746
- yield update(path, data);
492
+ updateDoc: (_0) => __async(void 0, [_0], function* ({ data }) {
493
+ const path = doc(database, cleanUrl);
494
+ yield updateDoc(path, data);
747
495
  return { result: data, status: "success", extra: { ref: path } };
748
496
  }),
749
- remove: () => __async(void 0, null, function* () {
750
- yield remove(path);
497
+ deleteDoc: () => __async(void 0, null, function* () {
498
+ const path = doc(database, cleanUrl);
499
+ yield deleteDoc(path);
751
500
  return { result: null, status: "success", extra: { ref: path } };
752
501
  })
753
502
  };
@@ -768,68 +517,10 @@ var getRealtimeDbBrowserMethods = (request, database, url, onSuccess, onError, r
768
517
  });
769
518
  };
770
519
 
771
- // src/realtime/browser/realtime.browser.utils.ts
772
- import {
773
- endAt as endAt2,
774
- endBefore as endBefore2,
775
- equalTo,
776
- limitToFirst,
777
- limitToLast,
778
- orderByChild,
779
- orderByKey,
780
- orderByValue,
781
- startAfter as startAfter2,
782
- startAt as startAt2
783
- } from "firebase/database";
784
- var mapRealtimeConstraint = ({ type, values }) => {
785
- switch (type) {
786
- case "orderByChild" /* ORDER_BY_CHILD */: {
787
- const [value] = values;
788
- return orderByChild(value);
789
- }
790
- case "orderByKey" /* ORDER_BY_KEY */: {
791
- return orderByKey();
792
- }
793
- case "orderByValue" /* ORDER_BY_VALUE */: {
794
- return orderByValue();
795
- }
796
- case "startAt" /* START_AT */: {
797
- const [[value]] = values;
798
- return startAt2(value);
799
- }
800
- case "startAfter" /* START_AFTER */: {
801
- const [[value]] = values;
802
- return startAfter2(value);
803
- }
804
- case "endAt" /* END_AT */: {
805
- const [[value]] = values;
806
- return endAt2(value);
807
- }
808
- case "endBefore" /* END_BEFORE */: {
809
- const [[value]] = values;
810
- return endBefore2(value);
811
- }
812
- case "limitToFirst" /* LIMIT_TO_FIRST */: {
813
- const [value] = values;
814
- return limitToFirst(value);
815
- }
816
- case "limitToLast" /* LIMIT_TO_LAST */: {
817
- const [value] = values;
818
- return limitToLast(value);
819
- }
820
- case "equalTo" /* EQUAL_TO */: {
821
- const [value] = values;
822
- return equalTo(value);
823
- }
824
- default:
825
- throw new Error(`Unknown method ${type}`);
826
- }
827
- };
828
-
829
- // src/realtime/browser/realtime.browser.sockets.ts
520
+ // src/firestore/firestore.sockets.ts
830
521
  import { getSocketAdapterBindings as getSocketAdapterBindings2 } from "@hyper-fetch/sockets";
831
- import { onValue, query as query4, ref as ref2, goOffline, goOnline } from "firebase/database";
832
- var realtimeSockets = (database) => {
522
+ import { onSnapshot, doc as doc2, query as query4, collection as collection2, disableNetwork, enableNetwork } from "firebase/firestore";
523
+ var firestoreSockets = (database) => {
833
524
  return (socket) => {
834
525
  const {
835
526
  open,
@@ -849,12 +540,12 @@ var realtimeSockets = (database) => {
849
540
  const connect = () => {
850
541
  const enabled = onConnect();
851
542
  if (enabled) {
852
- goOnline(database);
543
+ enableNetwork(database);
853
544
  onOpen();
854
545
  }
855
546
  };
856
547
  const disconnect = () => {
857
- goOffline(database);
548
+ disableNetwork(database);
858
549
  onDisconnect();
859
550
  onClose();
860
551
  };
@@ -862,234 +553,16 @@ var realtimeSockets = (database) => {
862
553
  onReconnect(disconnect, connect);
863
554
  };
864
555
  const listen = (listener, callback) => {
865
- var _a;
866
556
  const fullUrl = socket.url + listener.endpoint;
867
- const path = ref2(database, fullUrl);
868
557
  const { options } = listener;
869
- const onlyOnce = (options == null ? void 0 : options.onlyOnce) || false;
870
- const params = ((_a = options == null ? void 0 : options.constraints) == null ? void 0 : _a.map((constraint) => mapRealtimeConstraint(constraint))) || [];
871
- const queryConstraints = query4(path, ...params);
872
- let unsubscribe = () => {
873
- };
874
- let unmount = () => {
875
- };
876
- let clearListeners = () => {
877
- };
878
- unsubscribe = onValue(
879
- queryConstraints,
880
- (snapshot) => {
881
- const response = isDocOrQuery(fullUrl) === "doc" ? snapshot.val() : getOrderedResultRealtime(snapshot);
882
- const status = getStatus(response);
883
- const extra = { ref: path, snapshot, status };
884
- callback({ data: response, extra });
885
- onEvent(listener.endpoint, response, extra);
886
- },
887
- (error) => {
888
- onError(error);
889
- },
890
- { onlyOnce }
891
- );
892
- unmount = onListen(listener, callback, unsubscribe);
893
- clearListeners = () => {
894
- unsubscribe();
895
- unmount();
896
- };
897
- return clearListeners;
898
- };
899
- const emit = () => __async(void 0, null, function* () {
900
- throw new Error("Cannot emit from Realtime database socket.");
901
- });
902
- return {
903
- open,
904
- reconnectionAttempts,
905
- listeners,
906
- connecting,
907
- listen,
908
- removeListener,
909
- emit,
910
- connect,
911
- reconnect,
912
- disconnect
913
- };
914
- };
915
- };
916
-
917
- // src/realtime/utils/realtime.utils.ts
918
- var getOrderedResultRealtime = (snapshot) => {
919
- const res = [];
920
- snapshot.forEach((child) => {
921
- res.push(child.val());
922
- });
923
- return res.length > 0 ? res : null;
924
- };
925
-
926
- // src/adapter/admin/adapter.admin.ts
927
- var firebaseAdminAdapter = (database) => () => {
928
- const adapter = (request, requestId) => __async(void 0, null, function* () {
929
- const { fullUrl, onSuccess, onError, onRequestStart, onResponseEnd, onResponseStart, onRequestEnd } = yield getAdapterBindings(request, requestId, "error", {});
930
- return new Promise((resolve) => {
931
- if (database instanceof Firestore3) {
932
- const {
933
- method = "getDocs" /* getDocs */,
934
- queryParams,
935
- data,
936
- options
937
- } = request;
938
- const availableMethods = getFirestoreAdminMethods(request, database, fullUrl, onSuccess, onError, resolve, {
939
- onRequestStart,
940
- onResponseEnd,
941
- onResponseStart,
942
- onRequestEnd
943
- });
944
- if (!Object.values(FirestoreMethods).includes(method)) {
945
- throw new Error(`Cannot find method ${method} in Firestore available methods.`);
946
- }
947
- availableMethods(method, {
948
- constraints: (queryParams == null ? void 0 : queryParams.constraints) ? queryParams.constraints : [],
949
- data,
950
- options
951
- });
558
+ let path;
559
+ const queryType = isDocOrQuery(fullUrl);
560
+ if (queryType === "doc") {
561
+ path = doc2(database, fullUrl);
952
562
  } else {
953
- const {
954
- method = "get" /* get */,
955
- queryParams,
956
- data,
957
- options
958
- } = request;
959
- const availableMethods = getRealtimeDbAdminMethods(request, database, fullUrl, onSuccess, onError, resolve, {
960
- onRequestStart,
961
- onResponseEnd,
962
- onResponseStart,
963
- onRequestEnd
964
- });
965
- if (!Object.values(RealtimeDBMethods).includes(method)) {
966
- throw new Error(`Cannot find method ${method} in Realtime database available methods.`);
967
- }
968
- availableMethods(method, {
969
- constraints: (queryParams == null ? void 0 : queryParams.constraints) ? queryParams.constraints : [],
970
- options,
971
- data
972
- });
973
- }
974
- });
975
- });
976
- return adapter;
977
- };
978
-
979
- // src/adapter/admin/adapter.admin.sockets.ts
980
- import { Firestore as Firestore5 } from "firebase-admin/firestore";
981
-
982
- // src/realtime/admin/realtime.admin.sockets.ts
983
- import { getSocketAdapterBindings as getSocketAdapterBindings3 } from "@hyper-fetch/sockets";
984
- var realtimeSocketsAdmin = (database) => {
985
- return (socket) => {
986
- const {
987
- open,
988
- connecting,
989
- reconnectionAttempts,
990
- listeners,
991
- removeListener,
992
- onConnect,
993
- onReconnect,
994
- onDisconnect,
995
- onListen,
996
- onOpen,
997
- onClose,
998
- onEvent,
999
- onError
1000
- } = getSocketAdapterBindings3(socket, { open: true });
1001
- const connect = () => {
1002
- const enabled = onConnect();
1003
- if (enabled) {
1004
- database.goOnline();
1005
- onOpen();
1006
- }
1007
- };
1008
- const disconnect = () => {
1009
- database.goOffline();
1010
- onDisconnect();
1011
- onClose();
1012
- };
1013
- const reconnect = () => {
1014
- onReconnect(disconnect, connect);
1015
- };
1016
- const listen = (listener, callback) => {
1017
- const fullUrl = socket.url + listener.endpoint;
1018
- const path = database.ref(fullUrl);
1019
- const { options } = listener;
1020
- const onlyOnce = (options == null ? void 0 : options.onlyOnce) || false;
1021
- const q = applyRealtimeAdminConstraints(path, (options == null ? void 0 : options.constraints) || []);
1022
- const method = onlyOnce === true ? "once" : "on";
1023
- q[method](
1024
- "value",
1025
- (snapshot) => {
1026
- const response = isDocOrQuery(fullUrl) === "doc" ? snapshot.val() : getOrderedResultRealtime(snapshot);
1027
- const status = getStatus(response);
1028
- const extra = { ref: path, snapshot, status };
1029
- callback({ data: response, extra });
1030
- onEvent(listener.endpoint, response, extra);
1031
- },
1032
- (error) => {
1033
- onError(error);
1034
- }
1035
- );
1036
- const unsubscribe = () => q.off("value");
1037
- const unmount = onListen(listener, callback, unsubscribe);
1038
- const clearListeners = () => {
1039
- unsubscribe();
1040
- unmount();
1041
- };
1042
- return clearListeners;
1043
- };
1044
- const emit = () => __async(void 0, null, function* () {
1045
- throw new Error("Cannot emit from Realtime database socket.");
1046
- });
1047
- return {
1048
- open,
1049
- reconnectionAttempts,
1050
- listeners,
1051
- connecting,
1052
- listen,
1053
- removeListener,
1054
- emit,
1055
- connect,
1056
- reconnect,
1057
- disconnect
1058
- };
1059
- };
1060
- };
1061
-
1062
- // src/firestore/admin/firestore.admin.sockets.ts
1063
- import { CollectionReference, DocumentSnapshot } from "firebase-admin/firestore";
1064
- import { getSocketAdapterBindings as getSocketAdapterBindings4 } from "@hyper-fetch/sockets";
1065
- var firestoreAdminSockets = (database) => {
1066
- return (socket) => {
1067
- const {
1068
- open,
1069
- connecting,
1070
- reconnectionAttempts,
1071
- listeners,
1072
- removeListener,
1073
- onReconnect,
1074
- onListen,
1075
- onEvent,
1076
- onError
1077
- } = getSocketAdapterBindings4(socket, { open: true });
1078
- const connect = () => {
1079
- throw new Error("Connect function is not implemented for Firestore Admin socket.");
1080
- };
1081
- const disconnect = () => {
1082
- throw new Error("Cannot disconnect from Firestore database socket. Use 'app.delete()' instead.");
1083
- };
1084
- const reconnect = () => {
1085
- onReconnect(disconnect, connect);
1086
- };
1087
- const listen = (listener, callback) => {
1088
- const fullUrl = socket.url + listener.endpoint;
1089
- const { options } = listener;
1090
- let pathRef = getRef(database, fullUrl);
1091
- if (pathRef instanceof CollectionReference) {
1092
- pathRef = applyFireStoreAdminConstraints(pathRef, (options == null ? void 0 : options.constraints) || []);
563
+ const constraints = (options == null ? void 0 : options.constraints) || [];
564
+ const queryConstraints = constraints.map((constr) => mapConstraint(constr)) || [];
565
+ path = query4(collection2(database, fullUrl), ...queryConstraints);
1093
566
  }
1094
567
  let unsubscribe = () => {
1095
568
  };
@@ -1097,12 +570,14 @@ var firestoreAdminSockets = (database) => {
1097
570
  };
1098
571
  let clearListeners = () => {
1099
572
  };
1100
- unsubscribe = pathRef.onSnapshot(
573
+ unsubscribe = onSnapshot(
574
+ path,
1101
575
  (snapshot) => {
1102
- const response = snapshot instanceof DocumentSnapshot ? snapshot.data() || null : getOrderedResultFirestore(snapshot);
576
+ const getDocData = (s) => s.data() ? __spreadProps(__spreadValues({}, s.data()), { __key: s.id }) : null;
577
+ const response = queryType === "doc" ? getDocData(snapshot) : getOrderedResultFirestore(snapshot);
1103
578
  const status = getStatus(response);
1104
579
  const groupedResult = (options == null ? void 0 : options.groupByChangeType) === true ? getGroupedResultFirestore(snapshot) : null;
1105
- const extra = { ref: pathRef, snapshot, unsubscribe, groupedResult, status };
580
+ const extra = { ref: path, snapshot, groupedResult, status };
1106
581
  callback({ data: response, extra });
1107
582
  onEvent(listener.endpoint, response, extra);
1108
583
  },
@@ -1135,20 +610,10 @@ var firestoreAdminSockets = (database) => {
1135
610
  };
1136
611
  };
1137
612
 
1138
- // src/adapter/admin/adapter.admin.sockets.ts
1139
- var firebaseSocketsAdminAdapter = (database) => {
1140
- if (database instanceof Firestore5) {
1141
- return firestoreAdminSockets(database);
1142
- }
1143
- return realtimeSocketsAdmin(database);
1144
- };
1145
-
1146
- // src/adapter/browser/adapter.browser.ts
1147
- import { getAdapterBindings as getAdapterBindings2 } from "@hyper-fetch/core";
1148
- import { Database as Database3 } from "firebase/database";
613
+ // src/adapter/adapter.ts
1149
614
  var firebaseAdapter = (database) => () => {
1150
615
  const adapter = (request, requestId) => __async(void 0, null, function* () {
1151
- const { fullUrl, onSuccess, onError, onResponseStart, onResponseEnd, onRequestStart, onRequestEnd } = yield getAdapterBindings2(request, requestId, "error", {});
616
+ const { fullUrl, onSuccess, onError, onResponseStart, onResponseEnd, onRequestStart, onRequestEnd } = yield getAdapterBindings(request, requestId, "error", {});
1152
617
  return new Promise((resolve) => {
1153
618
  if (database instanceof Database3) {
1154
619
  const {
@@ -1206,21 +671,18 @@ var firebaseAdapter = (database) => () => {
1206
671
  return adapter;
1207
672
  };
1208
673
 
1209
- // src/adapter/browser/adapter.browser.sockets.ts
674
+ // src/adapter/adapter.sockets.ts
1210
675
  import { Database as Database4 } from "firebase/database";
1211
- import { Firestore as Firestore6 } from "firebase/firestore";
676
+ import { Firestore as Firestore3 } from "firebase/firestore";
1212
677
  var firebaseSocketsAdapter = (database) => {
1213
678
  if (database instanceof Database4) {
1214
679
  return realtimeSockets(database);
1215
680
  }
1216
- if (database instanceof Firestore6) {
681
+ if (database instanceof Firestore3) {
1217
682
  return firestoreSockets(database);
1218
683
  }
1219
684
  throw new Error("Unknown database type");
1220
685
  };
1221
-
1222
- // src/index.ts
1223
- __reExport(src_exports, __toESM(require_methods()));
1224
686
  export {
1225
687
  $endAt,
1226
688
  $endBefore,
@@ -1240,31 +702,16 @@ export {
1240
702
  RealtimeDBMethods,
1241
703
  RealtimeQueryConstraints,
1242
704
  SharedQueryConstraints,
1243
- applyFireStoreAdminConstraint,
1244
- applyFireStoreAdminConstraints,
1245
- applyRealtimeAdminConstraint,
1246
- applyRealtimeAdminConstraints,
1247
705
  firebaseAdapter,
1248
- firebaseAdminAdapter,
1249
706
  firebaseSocketsAdapter,
1250
- firebaseSocketsAdminAdapter,
1251
707
  firestoreSockets,
1252
- getFirestoreAdminMethods,
1253
708
  getFirestoreBrowserMethods,
1254
709
  getGroupedResultFirestore,
1255
710
  getOrderedResultFirestore,
1256
711
  getOrderedResultRealtime,
1257
- getRealtimeDbAdminMethods,
1258
712
  getRealtimeDbBrowserMethods,
1259
- getRef,
1260
713
  mapConstraint,
1261
714
  mapRealtimeConstraint,
1262
715
  realtimeSockets
1263
716
  };
1264
- /*!
1265
- * methods
1266
- * Copyright(c) 2013-2014 TJ Holowaychuk
1267
- * Copyright(c) 2015-2016 Douglas Christopher Wilson
1268
- * MIT Licensed
1269
- */
1270
717
  //# sourceMappingURL=index.esm.js.map