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