@hyper-fetch/firebase-admin 10.0.0 → 10.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +111 -63
- package/__tests__/features/constraints/constraints.base.spec.ts +44 -0
- package/__tests__/features/constraints/listener-extra.types.spec.ts +14 -0
- package/__tests__/features/constraints/query-params.types.spec.ts +83 -0
- package/__tests__/features/firestore/admin/constraints.admin.spec.ts +1 -0
- package/__tests__/features/firestore/admin/sockets.base.spec.ts +4 -1
- package/__tests__/features/firestore/shared/constraints.shared.tests.ts +87 -6
- package/__tests__/features/firestore/shared/methods/get-doc.test.suite.ts +15 -0
- package/__tests__/features/firestore/shared/methods/get-docs.test.suite.ts +1 -1
- package/__tests__/features/firestore/shared/methods/on-snapshot.test.suite.ts +79 -5
- package/__tests__/features/firestore/shared/methods/update-doc.test.suite.ts +1 -0
- package/__tests__/features/firestore/shared/methods.shared.tests.ts +2 -2
- package/__tests__/features/realtime/shared/constraints.shared.tests.ts +58 -8
- package/__tests__/features/realtime/shared/methods/get.test.suite.ts +23 -0
- package/__tests__/features/realtime/shared/methods/on-value.test.suite.ts +108 -5
- package/__tests__/features/realtime/shared/methods/push.test.suite.ts +3 -3
- package/__tests__/features/realtime/shared/methods/remove.test.suite.ts +3 -3
- package/__tests__/features/realtime/shared/methods/update.test.suite.ts +3 -3
- package/__tests__/shared/request-events.shared.ts +1 -4
- package/dist/adapter/adapter.d.ts +19 -0
- package/dist/adapter/adapter.d.ts.map +1 -1
- package/dist/adapter/adapter.sockets.d.ts +17 -0
- package/dist/adapter/adapter.sockets.d.ts.map +1 -1
- package/dist/adapter/types/adapter.firestore.types.d.ts +28 -6
- package/dist/adapter/types/adapter.firestore.types.d.ts.map +1 -1
- package/dist/adapter/types/adapter.realtime.types.d.ts +26 -6
- package/dist/adapter/types/adapter.realtime.types.d.ts.map +1 -1
- package/dist/adapter/types/firestore.socket.types.d.ts +6 -4
- package/dist/adapter/types/firestore.socket.types.d.ts.map +1 -1
- package/dist/adapter/types/realtime.socket.types.d.ts +2 -4
- package/dist/adapter/types/realtime.socket.types.d.ts.map +1 -1
- package/dist/constraints/constraints.builder.d.ts +98 -0
- package/dist/constraints/constraints.builder.d.ts.map +1 -0
- package/dist/constraints/firebase.constraints.d.ts +109 -1
- package/dist/constraints/firebase.constraints.d.ts.map +1 -1
- package/dist/constraints/index.d.ts +1 -0
- package/dist/constraints/index.d.ts.map +1 -1
- package/dist/firestore/firestore.sockets.d.ts.map +1 -1
- package/dist/index.mjs +277 -94
- package/dist/index.mjs.map +1 -1
- package/dist/realtime/realtime.methods.d.ts +7 -5
- package/dist/realtime/realtime.methods.d.ts.map +1 -1
- package/dist/realtime/realtime.sockets.d.ts.map +1 -1
- package/dist/utils/misc.d.ts.map +1 -1
- package/package.json +8 -7
- package/src/adapter/adapter.sockets.ts +17 -0
- package/src/adapter/adapter.ts +77 -46
- package/src/adapter/types/adapter.firestore.types.ts +40 -7
- package/src/adapter/types/adapter.realtime.types.ts +39 -7
- package/src/adapter/types/firestore.socket.types.ts +10 -2
- package/src/adapter/types/realtime.socket.types.ts +6 -3
- package/src/constraints/constraints.builder.ts +214 -0
- package/src/constraints/firebase.constraints.ts +111 -3
- package/src/constraints/index.ts +1 -0
- package/src/firestore/firestore.methods.ts +8 -8
- package/src/firestore/firestore.sockets.ts +65 -56
- package/src/firestore/utils/constraints.utils.ts +4 -4
- package/src/realtime/realtime.methods.ts +19 -20
- package/src/realtime/realtime.sockets.ts +57 -52
- package/src/realtime/utils/constraints.utils.ts +10 -10
- package/src/utils/misc.ts +1 -1
- package/vite.config.ts +2 -0
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/adapter/types/adapter.firestore.types.ts","../src/adapter/types/adapter.realtime.types.ts","../src/utils/misc.ts","../src/firestore/utils/result.utils.ts","../src/firestore/utils/ref.utils.ts","../src/constraints/firebase.constraints.ts","../src/firestore/utils/constraints.utils.ts","../src/firestore/firestore.sockets.ts","../src/firestore/firestore.methods.ts","../src/realtime/utils/result.utils.ts","../src/realtime/utils/constraints.utils.ts","../src/realtime/realtime.methods.ts","../src/realtime/realtime.sockets.ts","../src/adapter/adapter.sockets.ts","../src/adapter/adapter.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\nimport type { Adapter } from \"@hyper-fetch/core\";\nimport type { SocketAdapter } from \"@hyper-fetch/sockets\";\nimport type {\n FirestoreConstraintsUnion,\n FirestorePermittedMethods,\n PermittedConstraints,\n SharedQueryConstraints,\n} from \"constraints\";\nimport type {\n Unsubscribe as FirestoreUnsubscribe,\n CollectionReference,\n DocumentReference,\n DocumentSnapshot,\n QuerySnapshot,\n} from \"firebase/firestore\";\n\nexport type FirestoreSocketAdapterType = SocketAdapter<\n never,\n FirestoreOnSnapshotExtra,\n { groupByChangeType?: boolean } & FirestoreQueryParams\n>;\n\nexport type FirestoreAdapterType =\n | Adapter<\n Record<string, never>,\n \"getDoc\",\n FirestoreStatuses,\n FirestoreExtra,\n FirestoreQueryParams,\n FirestoreQueryParams\n >\n | Adapter<\n Record<string, never>,\n \"getDocs\",\n FirestoreStatuses,\n FirestoreGetDocsExtra,\n FirestoreQueryParams,\n FirestoreQueryParams\n >\n | Adapter<{ merge: boolean }, \"setDoc\", FirestoreStatuses, FirestoreRefOnlyExtra, Record<string, never>, undefined>\n | Adapter<\n Record<string, never>,\n \"updateDoc\" | \"addDoc\" | \"deleteDoc\" | \"setDoc\",\n FirestoreStatuses,\n FirestoreRefOnlyExtra,\n Record<string, never>,\n undefined\n >;\n\nexport type FirestoreQueryParams = {\n constraints?: PermittedConstraints<FirestorePermittedMethods, FirestoreConstraintsUnion | SharedQueryConstraints>[];\n};\n\nexport enum FirestoreMethods {\n addDoc = \"addDoc\",\n getDoc = \"getDoc\",\n getDocs = \"getDocs\",\n setDoc = \"setDoc\",\n updateDoc = \"updateDoc\",\n deleteDoc = \"deleteDoc\",\n}\n\nexport type FirestoreMethodsUnion =\n | FirestoreMethods.addDoc\n | FirestoreMethods.getDoc\n | FirestoreMethods.getDocs\n | FirestoreMethods.setDoc\n | FirestoreMethods.updateDoc\n | FirestoreMethods.deleteDoc;\n\nexport type FirestoreExtra = {\n ref?: DocumentReference;\n snapshot?: DocumentSnapshot;\n};\n\nexport type FirestoreOnSnapshotExtra = {\n ref?: DocumentReference | CollectionReference;\n snapshot?: DocumentSnapshot;\n unsubscribe?: FirestoreUnsubscribe;\n groupedResult?: { added: DocumentSnapshot[]; modified: DocumentSnapshot[]; removed: DocumentSnapshot[] };\n};\n\nexport type FirestoreGetDocsExtra = {\n ref?: CollectionReference;\n snapshot?: QuerySnapshot;\n};\n\nexport type FirestoreRefOnlyExtra = {\n ref?: DocumentReference;\n};\n\nexport type FirestoreStatuses = \"success\" | \"error\" | \"emptyResource\";\n","/* eslint-disable @typescript-eslint/naming-convention */\nimport type { Adapter } from \"@hyper-fetch/core\";\nimport type { SocketAdapter } from \"@hyper-fetch/sockets\";\nimport type {\n PermittedConstraints,\n RealtimeConstraintsUnion,\n RealtimePermittedMethods,\n SharedQueryConstraints,\n} from \"constraints\";\nimport type { DatabaseReference, DataSnapshot } from \"firebase/database\";\n\nexport type RealtimeSocketAdapterType = SocketAdapter<\n never,\n RealtimeDbOnValueMethodExtra,\n { onlyOnce?: boolean } & RealtimeDBQueryParams\n>;\n\nexport type RealtimeDbAdapterType =\n | Adapter<\n DefaultRealtimeDBAdapterOptions,\n \"get\",\n RealtimeDBStatuses,\n RealtimeDbGetMethodExtra,\n RealtimeDBQueryParams,\n RealtimeDBQueryParams\n >\n | Adapter<\n DefaultRealtimeDBAdapterOptions,\n \"push\",\n RealtimeDBStatuses,\n RealtimeDbPushMethodExtra,\n Record<string, never>,\n undefined\n >\n | Adapter<\n DefaultRealtimeDBAdapterOptions,\n \"set\" | \"update\" | \"remove\",\n RealtimeDBStatuses,\n RealtimeDbDefaultExtra,\n Record<string, never>,\n undefined\n >;\n\nexport type DefaultRealtimeDBAdapterOptions = {\n priority?: number;\n};\n\nexport enum RealtimeDBMethods {\n set = \"set\",\n push = \"push\",\n update = \"update\",\n get = \"get\",\n remove = \"remove\",\n}\n\nexport type RealtimeDBMethodsUnion =\n | RealtimeDBMethods.set\n | RealtimeDBMethods.push\n | RealtimeDBMethods.update\n | RealtimeDBMethods.get\n | RealtimeDBMethods.remove;\n\nexport type RealtimeDBStatuses = \"success\" | \"error\" | \"emptyResource\";\nexport type RealtimeDbOnValueMethodExtra = {\n ref: DatabaseReference;\n snapshot: DataSnapshot;\n};\n\nexport type RealtimeDbGetMethodExtra = {\n ref: DatabaseReference;\n snapshot: DataSnapshot;\n};\n\nexport type RealtimeDbDefaultExtra = {\n ref: DatabaseReference;\n};\n\nexport type RealtimeDbPushMethodExtra = {\n ref: DatabaseReference;\n key: string;\n};\n\nexport type RealtimeDBQueryParams = {\n constraints?: PermittedConstraints<RealtimePermittedMethods, RealtimeConstraintsUnion | SharedQueryConstraints>[];\n};\n","export const getStatus = (res: any) => {\n // Deliberate == instead of ===\n return (Array.isArray(res) && res.length === 0) || res == null ? \"emptyResource\" : \"success\";\n};\n\nexport const isDocOrQuery = (fullUrl: string): string => {\n const withoutSurroundingSlashes = fullUrl.replace(/^\\/|\\/$/g, \"\");\n const pathElements = withoutSurroundingSlashes.split(\"/\").length;\n return pathElements % 2 === 0 ? \"doc\" : \"query\";\n};\n","import type { QuerySnapshot, DocumentData } from \"firebase-admin/firestore\";\n\nexport const getOrderedResultFirestore = (snapshot: QuerySnapshot) => {\n const result: (DocumentData & { __key: string })[] = [];\n snapshot.docs.forEach((d) => {\n result.push({ ...d.data(), __key: d.id });\n });\n return result;\n};\n\nexport const getGroupedResultFirestore = (snapshot: QuerySnapshot) => {\n const groupedResult: { added: DocumentData[]; modified: DocumentData[]; removed: DocumentData[] } = {\n added: [],\n modified: [],\n removed: [],\n };\n snapshot.docChanges().forEach((change) => {\n groupedResult[change.type].push(change.doc.data());\n });\n return [...groupedResult.added, ...groupedResult.modified, ...groupedResult.removed].length > 0\n ? groupedResult\n : null;\n};\n","import type { CollectionReference, DocumentReference, Firestore } from \"firebase-admin/firestore\";\n\nexport const getRef = (db: Firestore, fullUrl: string) => {\n const withoutSurroundingSlashes = fullUrl.replace(/^\\/|\\/$/g, \"\");\n const urlParts = withoutSurroundingSlashes.split(\"/\").map((element, index) => {\n return index % 2 === 0 ? [\"collection\", element] : [\"doc\", element];\n });\n\n return urlParts.reduce(\n (_db, value) => {\n const [method, pathPart] = value;\n if (method === \"doc\" && \"doc\" in _db) {\n return _db.doc(pathPart);\n }\n if (method === \"collection\" && \"collection\" in _db) {\n return _db.collection(pathPart);\n }\n return _db;\n },\n db as unknown as Firestore | CollectionReference | DocumentReference,\n ) as CollectionReference | DocumentReference;\n};\n","import type { OrderByDirection, WhereFilterOp } from \"firebase-admin/firestore\";\n\nexport enum SharedQueryConstraints {\n START_AT = \"startAt\",\n START_AFTER = \"startAfter\",\n END_AT = \"endAt\",\n END_BEFORE = \"endBefore\",\n}\nexport enum RealtimeQueryConstraints {\n ORDER_BY_CHILD = \"orderByChild\",\n ORDER_BY_KEY = \"orderByKey\",\n ORDER_BY_VALUE = \"orderByValue\",\n LIMIT_TO_FIRST = \"limitToFirst\",\n LIMIT_TO_LAST = \"limitToLast\",\n EQUAL_TO = \"equalTo\",\n}\n\nexport enum FirestoreQueryConstraints {\n WHERE = \"where\",\n ORDER_BY = \"orderBy\",\n LIMIT = \"limit\",\n}\n\nexport const $where = (fieldPath: string, opStr: WhereFilterOp, value: any) => {\n return {\n toString: () => `${FirestoreQueryConstraints.WHERE}_${fieldPath}${opStr}${value}`,\n type: FirestoreQueryConstraints.WHERE as const,\n values: [fieldPath, opStr, value],\n };\n};\n\nexport const $orderBy = (fieldPath: string, directionStr?: OrderByDirection) => {\n return {\n toString: () => `${FirestoreQueryConstraints.ORDER_BY}_${fieldPath}_${directionStr || \"\"}`,\n type: FirestoreQueryConstraints.ORDER_BY as const,\n values: [fieldPath, directionStr],\n };\n};\n\nexport const $limit = (num: number) => {\n return {\n toString: () => `${FirestoreQueryConstraints.LIMIT}_${num}`,\n type: FirestoreQueryConstraints.LIMIT as const,\n values: [num],\n };\n};\n\nconst startEndConstraintsImpl = (constraintType: SharedQueryConstraints) => {\n return (...docOrFields: any[]) => {\n if (docOrFields.length === 1 && docOrFields[0].query) {\n return {\n toString: () => `${constraintType}_${docOrFields[0].query?._query?.memoizedTarget?.memoizedCanonicalId}`,\n type: constraintType,\n values: [docOrFields],\n };\n }\n return {\n toString: () => `${constraintType}_${docOrFields}`,\n type: constraintType,\n values: [docOrFields],\n };\n };\n};\n\nexport const $startAt = startEndConstraintsImpl(SharedQueryConstraints.START_AT as const);\nexport const $startAfter = startEndConstraintsImpl(SharedQueryConstraints.START_AFTER as const);\n\nexport const $endAt = startEndConstraintsImpl(SharedQueryConstraints.END_AT as const);\nexport const $endBefore = startEndConstraintsImpl(SharedQueryConstraints.END_BEFORE as const);\n\nexport const $orderByChild = (path: string) => {\n return {\n toString: () => `${RealtimeQueryConstraints.ORDER_BY_CHILD}_${path}`,\n type: RealtimeQueryConstraints.ORDER_BY_CHILD as const,\n values: [path],\n };\n};\n\nexport const $orderByKey = () => {\n return {\n toString: () => `${RealtimeQueryConstraints.ORDER_BY_KEY}`,\n type: RealtimeQueryConstraints.ORDER_BY_KEY as const,\n values: [],\n };\n};\n\nexport const $orderByValue = () => {\n return {\n toString: () => `${RealtimeQueryConstraints.ORDER_BY_VALUE}`,\n type: RealtimeQueryConstraints.ORDER_BY_VALUE as const,\n values: [],\n };\n};\n\nexport const $limitToFirst = (num: number) => {\n return {\n toString: () => `${RealtimeQueryConstraints.LIMIT_TO_FIRST}_${num}`,\n type: RealtimeQueryConstraints.LIMIT_TO_FIRST as const,\n values: [num],\n };\n};\n\nexport const $limitToLast = (num: number) => {\n return {\n toString: () => `${RealtimeQueryConstraints.LIMIT_TO_LAST}_${num}`,\n type: RealtimeQueryConstraints.LIMIT_TO_LAST as const,\n values: [num],\n };\n};\n\nexport const $equalTo = (value: any) => {\n return {\n toString: () => `${RealtimeQueryConstraints.LIMIT_TO_LAST}_${value}`,\n type: RealtimeQueryConstraints.EQUAL_TO as const,\n values: [value],\n };\n};\n","import type { Query } from \"firebase-admin/firestore\";\nimport type { OrderByDirection } from \"firebase/firestore\";\n\nimport type { FirestorePermittedMethods } from \"../../constraints\";\nimport { FirestoreQueryConstraints, SharedQueryConstraints } from \"../../constraints\";\n\nexport const applyFireStoreAdminConstraint = (collectionRef: Query, { type, values }: FirestorePermittedMethods) => {\n switch (type) {\n case FirestoreQueryConstraints.WHERE: {\n const [fieldPath, strOp, value] = values;\n return collectionRef.where(fieldPath, strOp, value);\n }\n case FirestoreQueryConstraints.ORDER_BY: {\n const [field, ord] = values;\n return collectionRef.orderBy(field!, ord as OrderByDirection);\n }\n case FirestoreQueryConstraints.LIMIT: {\n const [limitValue] = values;\n return collectionRef.limit(limitValue);\n }\n case SharedQueryConstraints.START_AT: {\n const [docOrFields] = values;\n return collectionRef.startAt(docOrFields);\n }\n case SharedQueryConstraints.START_AFTER: {\n const [docOrFields] = values;\n return collectionRef.startAfter(docOrFields);\n }\n case SharedQueryConstraints.END_AT: {\n const [docOrFields] = values;\n return collectionRef.endAt(docOrFields);\n }\n case SharedQueryConstraints.END_BEFORE: {\n const [docOrFields] = values;\n return collectionRef.endBefore(docOrFields);\n }\n default:\n throw new Error(`Unknown method ${type}`);\n }\n};\n\nexport const applyFireStoreAdminConstraints = (collectionRef: Query, constraints: FirestorePermittedMethods[]) => {\n return constraints.reduce((collection, constraint) => {\n return applyFireStoreAdminConstraint(collection, constraint);\n }, collectionRef);\n};\n","import { SocketAdapter } from \"@hyper-fetch/sockets\";\nimport type { FirestoreAdminSocketAdapterType } from \"adapter\";\nimport type { DocumentReference, Firestore, Query, QuerySnapshot } from \"firebase-admin/firestore\";\nimport { CollectionReference, DocumentSnapshot } from \"firebase-admin/firestore\";\nimport { getStatus } from \"utils\";\n\nimport { getGroupedResultFirestore, getOrderedResultFirestore, getRef, applyFireStoreAdminConstraints } from \"./utils\";\n\nexport const firestoreAdminSockets = (database: Firestore) => {\n return (\n new SocketAdapter({\n name: \"firebase-admin-firestore\",\n defaultConnected: true,\n }) as unknown as FirestoreAdminSocketAdapterType\n ).setConnector(({ socket, onReconnect, onListen, onEvent, onError }) => {\n const connect = () => {\n throw new Error(\"Connect function is not implemented for Firestore Admin socket.\");\n };\n\n const disconnect = () => {\n throw new Error(\"Cannot disconnect from Firestore database socket. Use 'app.delete()' instead.\");\n };\n\n const reconnect = () => {\n onReconnect({ disconnect, connect });\n };\n\n const listen: FirestoreAdminSocketAdapterType[\"listen\"] = (listener, callback) => {\n const fullUrl = socket.url + listener.topic;\n const { options } = listener;\n let pathRef: DocumentReference | Query = getRef(database, fullUrl);\n if (pathRef instanceof CollectionReference) {\n pathRef = applyFireStoreAdminConstraints(pathRef, options?.constraints || []);\n }\n let unsubscribe = () => {};\n let unmount = () => {};\n let clearListeners = () => {};\n\n unsubscribe = pathRef.onSnapshot(\n (snapshot) => {\n const getSnapshotData = (s: DocumentSnapshot) => (s.data() ? { ...s.data(), __key: s.id } : null);\n const response =\n snapshot instanceof DocumentSnapshot\n ? getSnapshotData(snapshot)\n : getOrderedResultFirestore(snapshot as QuerySnapshot);\n const status = getStatus(response);\n const groupedResult =\n options?.groupByChangeType === true ? getGroupedResultFirestore(snapshot as QuerySnapshot) : null;\n const extra = { ref: pathRef, snapshot, unsubscribe, groupedResult, status };\n callback({ data: response, extra });\n onEvent({ topic: listener.topic, data: response, extra });\n },\n (error) => {\n onError({ error });\n },\n );\n unmount = onListen({ listener, callback, onUnmount: unsubscribe });\n clearListeners = () => {\n unsubscribe();\n unmount();\n };\n\n return clearListeners;\n };\n\n const emit = async () => {\n throw new Error(\"Cannot emit from Firestore database socket.\");\n };\n\n return {\n connect,\n reconnect,\n disconnect,\n emit,\n listen,\n };\n });\n};\n","import type { getAdapterBindings } from \"@hyper-fetch/core\";\nimport type { FirestoreMethodsUnion } from \"adapter\";\nimport type {\n FirestoreConstraintsUnion,\n FirestorePermittedMethods,\n PermittedConstraints,\n SharedQueryConstraints,\n} from \"constraints\";\n/* eslint-disable max-params */\nimport type { CollectionReference, DocumentReference, DocumentSnapshot, Firestore } from \"firebase-admin/firestore\";\nimport { getStatus } from \"utils\";\n\nimport { applyFireStoreAdminConstraints, getOrderedResultFirestore, getRef } from \"./utils\";\n\ntype DataType = {\n constraints?: PermittedConstraints<FirestorePermittedMethods, FirestoreConstraintsUnion | SharedQueryConstraints>[];\n payload?: any;\n options?: Record<string, any>;\n};\n\nexport const getFirestoreAdminMethods = ({\n database,\n url,\n onSuccess,\n onError,\n onResponseStart,\n onRequestStart,\n onRequestEnd,\n onResponseEnd,\n}: {\n database: Firestore;\n url: string;\n onSuccess: Awaited<ReturnType<typeof getAdapterBindings>>[\"onSuccess\"];\n onError: Awaited<ReturnType<typeof getAdapterBindings>>[\"onError\"];\n onResponseStart: Awaited<ReturnType<typeof getAdapterBindings>>[\"onResponseStart\"];\n onRequestStart: Awaited<ReturnType<typeof getAdapterBindings>>[\"onRequestStart\"];\n onRequestEnd: Awaited<ReturnType<typeof getAdapterBindings>>[\"onRequestEnd\"];\n onResponseEnd: Awaited<ReturnType<typeof getAdapterBindings>>[\"onResponseEnd\"];\n}): ((methodName: FirestoreMethodsUnion, data: DataType) => Promise<void>) => {\n const [cleanUrl] = url.split(\"?\");\n const methods = {\n getDoc: async () => {\n const path = getRef(database, cleanUrl);\n const snapshot = (await path.get()) as DocumentSnapshot;\n const result = snapshot.data() ? { ...snapshot.data(), __key: snapshot.id } : null;\n const status = result ? \"success\" : \"emptyResource\";\n return { result, status, extra: { ref: path, snapshot } };\n },\n getDocs: async ({\n constraints = [],\n }: {\n constraints?: PermittedConstraints<\n FirestorePermittedMethods,\n FirestoreConstraintsUnion | SharedQueryConstraints\n >[];\n }) => {\n const path = getRef(database, cleanUrl) as CollectionReference;\n const query = applyFireStoreAdminConstraints(path, constraints);\n const querySnapshot = await query.get();\n const result = getOrderedResultFirestore(querySnapshot);\n const status = getStatus(result);\n\n return { result, status, extra: { ref: path, snapshot: querySnapshot } };\n },\n setDoc: async ({ data, options }: { data?: any; options?: any }) => {\n const path = getRef(database, cleanUrl) as DocumentReference;\n const merge = options?.merge === true;\n const res = await path.set(data, { merge });\n return { result: res, status: \"success\", extra: { ref: path } };\n },\n addDoc: async ({ data }: { data?: any }) => {\n const ref = getRef(database, cleanUrl) as CollectionReference;\n const docRef = await ref.add(data);\n return { result: { ...data, __key: docRef.id }, status: \"success\", extra: { ref: docRef } };\n },\n updateDoc: async ({ data }: { data?: any }) => {\n const path = getRef(database, cleanUrl) as DocumentReference;\n await path.update(data);\n return { result: data, status: \"success\", extra: { ref: path } };\n },\n deleteDoc: async () => {\n const path = getRef(database, cleanUrl) as DocumentReference;\n await path.delete();\n return { result: null, status: \"success\", extra: { ref: path } };\n },\n };\n\n return async (methodName: FirestoreMethodsUnion, data: DataType) => {\n try {\n onRequestStart();\n const { result, status, extra } = await methods[methodName](data);\n onRequestEnd();\n onResponseStart();\n onSuccess({ data: result, status, extra });\n onResponseEnd();\n } catch (error) {\n onRequestEnd();\n onResponseStart();\n onError({ error, status: \"error\", extra: {} });\n onResponseEnd();\n }\n };\n};\n","import type { DataSnapshot } from \"firebase-admin/database\";\n\nexport const getOrderedResultRealtime = (snapshot: DataSnapshot) => {\n const res: any = [];\n snapshot.forEach((child) => {\n res.push({ ...child.val(), __key: child.key });\n });\n return res.length > 0 ? res : null;\n};\n","import type { RealtimePermittedMethods } from \"constraints\";\nimport { RealtimeQueryConstraints, SharedQueryConstraints } from \"constraints\";\nimport type { Query } from \"firebase-admin/database\";\n\nexport const applyRealtimeAdminConstraint = (ref: Query, { type, values }: RealtimePermittedMethods) => {\n switch (type) {\n case RealtimeQueryConstraints.ORDER_BY_CHILD: {\n const [value] = values;\n return ref.orderByChild(value);\n }\n case RealtimeQueryConstraints.ORDER_BY_KEY: {\n return ref.orderByKey();\n }\n case RealtimeQueryConstraints.ORDER_BY_VALUE: {\n return ref.orderByValue();\n }\n case SharedQueryConstraints.START_AT: {\n const [[value]] = values;\n return ref.startAt(value);\n }\n case SharedQueryConstraints.START_AFTER: {\n const [[value]] = values;\n return ref.startAfter(value);\n }\n case SharedQueryConstraints.END_AT: {\n const [[value]] = values;\n return ref.endAt(value);\n }\n case SharedQueryConstraints.END_BEFORE: {\n const [[value]] = values;\n return ref.endBefore(value);\n }\n case RealtimeQueryConstraints.LIMIT_TO_FIRST: {\n const [value] = values;\n return ref.limitToFirst(value);\n }\n case RealtimeQueryConstraints.LIMIT_TO_LAST: {\n const [value] = values;\n return ref.limitToLast(value);\n }\n case RealtimeQueryConstraints.EQUAL_TO: {\n const [value] = values;\n return ref.equalTo(value);\n }\n default:\n throw new Error(`Unknown method ${type}`);\n }\n};\n\nexport const applyRealtimeAdminConstraints = (ref: Query, constraints: RealtimePermittedMethods[]) => {\n return constraints.reduce((collection, constraint) => {\n return applyRealtimeAdminConstraint(collection, constraint);\n }, ref);\n};\n","import type { getAdapterBindings } from \"@hyper-fetch/core\";\nimport type { RealtimeDBMethodsUnion } from \"adapter/types\";\nimport type {\n PermittedConstraints,\n RealtimeConstraintsUnion,\n RealtimePermittedMethods,\n SharedQueryConstraints,\n} from \"constraints\";\n/* eslint-disable max-params */\nimport type { Database } from \"firebase-admin/database\";\nimport { applyRealtimeAdminConstraints, getOrderedResultRealtime } from \"realtime/index\";\nimport { getStatus, isDocOrQuery } from \"utils\";\n\nexport const getRealtimeDbAdminMethods = ({\n database,\n url,\n onSuccess,\n onError,\n onResponseStart,\n onRequestStart,\n onRequestEnd,\n onResponseEnd,\n}: {\n database: Database;\n url: string;\n onSuccess: Awaited<ReturnType<typeof getAdapterBindings>>[\"onSuccess\"];\n onError: Awaited<ReturnType<typeof getAdapterBindings>>[\"onError\"];\n onResponseStart: Awaited<ReturnType<typeof getAdapterBindings>>[\"onResponseStart\"];\n onRequestStart: Awaited<ReturnType<typeof getAdapterBindings>>[\"onRequestStart\"];\n onRequestEnd: Awaited<ReturnType<typeof getAdapterBindings>>[\"onRequestEnd\"];\n onResponseEnd: Awaited<ReturnType<typeof getAdapterBindings>>[\"onResponseEnd\"];\n}): ((\n methodName: RealtimeDBMethodsUnion,\n data: {\n constraints: PermittedConstraints<RealtimePermittedMethods, RealtimeConstraintsUnion | SharedQueryConstraints>[];\n payload: any;\n options: Record<string, any>;\n },\n) => Promise<void>) => {\n const [fullUrl] = url.split(\"?\");\n const path = database.ref(fullUrl);\n const methods = {\n get: async ({ constraints = [] }) => {\n const docOrQuery = isDocOrQuery(fullUrl);\n const q = applyRealtimeAdminConstraints(path, constraints);\n const snapshot = await q.get();\n const res = docOrQuery === \"doc\" ? snapshot.val() : getOrderedResultRealtime(snapshot);\n const status = getStatus(res);\n return { result: res, status, extra: { ref: path, snapshot } };\n },\n set: async ({ data }: { data?: any }) => {\n await path.set(data);\n return { result: data, status: \"success\", extra: { ref: path } };\n },\n push: async ({ data }: { data?: any }) => {\n const resRef = await path.push(data);\n return { result: { ...data, __key: resRef.key }, status: \"success\", extra: { ref: resRef, key: resRef.key } };\n },\n update: async ({ data }: { data?: any }) => {\n await path.update(data);\n return { result: data, status: \"success\", extra: { ref: path } };\n },\n remove: async () => {\n await path.remove();\n return { result: null, status: \"success\", extra: { ref: path } };\n },\n };\n\n return async (methodName: RealtimeDBMethodsUnion, data) => {\n try {\n onRequestStart();\n const { result, status, extra } = await methods[methodName](data as any);\n onRequestEnd();\n onResponseStart();\n onSuccess({ data: result, status, extra });\n onResponseEnd();\n } catch (error) {\n onRequestEnd();\n onResponseStart();\n onError({ error, status: \"error\", extra: {} });\n onResponseEnd();\n }\n };\n};\n","import { SocketAdapter } from \"@hyper-fetch/sockets\";\nimport type { RealtimeAdminOnValueMethodExtra, RealtimeAdminSocketAdapterType } from \"adapter\";\nimport type { Database, DataSnapshot } from \"firebase-admin/database\";\nimport { getStatus, isDocOrQuery } from \"utils\";\n\nimport { applyRealtimeAdminConstraints, getOrderedResultRealtime } from \"./utils\";\n\nexport const realtimeSocketsAdmin = (database: Database) => {\n return (\n new SocketAdapter({\n name: \"firebase-admin-realtime\",\n defaultConnected: true,\n }) as unknown as RealtimeAdminSocketAdapterType\n ).setConnector(\n ({ socket, onReconnect, onConnect, onConnected, onDisconnect, onDisconnected, onListen, onEvent, onError }) => {\n const connect = async () => {\n const connection = await onConnect();\n\n if (connection) {\n database.goOnline();\n onConnected();\n }\n };\n\n const disconnect = async () => {\n database.goOffline();\n onDisconnect();\n onDisconnected();\n };\n\n const reconnect = () => {\n onReconnect({ disconnect, connect });\n };\n\n const listen: RealtimeAdminSocketAdapterType[\"listen\"] = (listener, callback) => {\n const fullUrl = socket.url + listener.topic;\n const path = database.ref(fullUrl);\n const { options } = listener;\n const onlyOnce = options?.onlyOnce || false;\n const q = applyRealtimeAdminConstraints(path, options?.constraints || []);\n const method = onlyOnce === true ? \"once\" : \"on\";\n q[method](\n \"value\",\n (snapshot) => {\n const getSnapshotData = (s: DataSnapshot) => (s.val() ? { ...s.val(), __key: s.key } : null);\n const response =\n isDocOrQuery(fullUrl) === \"doc\" ? getSnapshotData(snapshot) : getOrderedResultRealtime(snapshot);\n const status = getStatus(response);\n const extra: RealtimeAdminOnValueMethodExtra = { ref: path, snapshot, status };\n callback({ data: response, extra });\n onEvent({ topic: listener.topic, data: response, extra });\n },\n (error) => {\n onError({ error });\n },\n );\n const unsubscribe = () => q.off(\"value\");\n const unmount = onListen({ listener, callback, onUnmount: unsubscribe });\n\n const clearListeners = () => {\n unsubscribe();\n unmount();\n };\n\n return clearListeners;\n };\n\n const emit = async () => {\n throw new Error(\"Cannot emit from Realtime database socket.\");\n };\n\n return {\n connect,\n reconnect,\n disconnect,\n listen,\n emit,\n };\n },\n );\n};\n","import { Firestore } from \"firebase-admin/firestore\";\n\nimport { firestoreAdminSockets } from \"../firestore\";\nimport { realtimeSocketsAdmin } from \"../realtime\";\nimport type { FirebaseAdminDBTypes, FirebaseAdminSocketAdapterTypes } from \"./types\";\n\nexport const FirebaseSocketsAdminAdapter = <T extends FirebaseAdminDBTypes>(\n database: T,\n): FirebaseAdminSocketAdapterTypes<T> => {\n if (database instanceof Firestore) {\n return firestoreAdminSockets(database) as unknown as FirebaseAdminSocketAdapterTypes<T>;\n }\n return realtimeSocketsAdmin(database) as unknown as FirebaseAdminSocketAdapterTypes<T>;\n};\n","import { Adapter } from \"@hyper-fetch/core\";\nimport type {\n FirebaseAdminDBTypes,\n FirebaseAdminAdapterTypes,\n FirestoreRequestType,\n RealtimeDBRequestType,\n} from \"adapter\";\nimport { FirestoreMethods, RealtimeDBMethods } from \"adapter\";\nimport { Firestore } from \"firebase-admin/firestore\";\n\nimport { getFirestoreAdminMethods } from \"../firestore\";\nimport { getRealtimeDbAdminMethods } from \"../realtime\";\n\nexport const FirebaseAdminAdapter = <T extends FirebaseAdminDBTypes>(database: T): FirebaseAdminAdapterTypes<T> => {\n const adapter = new Adapter({\n name: \"firebase-admin\",\n defaultMethod: \"getDoc\",\n defaultExtra: {},\n systemErrorStatus: \"error\",\n systemErrorExtra: {},\n }).setFetcher(\n async ({ request, onSuccess, onError, onResponseStart, onResponseEnd, onRequestStart, onRequestEnd }) => {\n const fullUrl = `${request.client.url}${request.endpoint}`;\n if (database instanceof Firestore) {\n const { method = FirestoreMethods.getDocs, queryParams, payload, options } = request as FirestoreRequestType;\n const availableMethods = getFirestoreAdminMethods({\n database,\n url: fullUrl,\n onSuccess,\n onError,\n onRequestStart,\n onResponseEnd,\n onResponseStart,\n onRequestEnd,\n });\n if (!Object.values(FirestoreMethods).includes(method)) {\n throw new Error(`Cannot find method ${method} in Firestore available methods.`);\n }\n availableMethods(method, {\n constraints: queryParams?.constraints ? queryParams.constraints : [],\n payload,\n options,\n });\n } else {\n const { method = RealtimeDBMethods.get, queryParams, payload, options } = request as RealtimeDBRequestType;\n const availableMethods = getRealtimeDbAdminMethods({\n database,\n url: fullUrl,\n onSuccess,\n onError,\n onRequestStart,\n onResponseEnd,\n onResponseStart,\n onRequestEnd,\n });\n if (!Object.values(RealtimeDBMethods).includes(method)) {\n throw new Error(`Cannot find method ${method} in Realtime database available methods.`);\n }\n availableMethods(method, {\n constraints: queryParams?.constraints ? queryParams.constraints : [],\n options,\n payload,\n });\n }\n },\n );\n\n return adapter as unknown as FirebaseAdminAdapterTypes<T>;\n};\n"],"mappings":";;;;AAsDA,IAAY,mBAAL,yBAAA,kBAAA;AACL,kBAAA,YAAA;AACA,kBAAA,YAAA;AACA,kBAAA,aAAA;AACA,kBAAA,YAAA;AACA,kBAAA,eAAA;AACA,kBAAA,eAAA;;KACD;;;ACdD,IAAY,oBAAL,yBAAA,mBAAA;AACL,mBAAA,SAAA;AACA,mBAAA,UAAA;AACA,mBAAA,YAAA;AACA,mBAAA,SAAA;AACA,mBAAA,YAAA;;KACD;;;ACrDD,IAAa,aAAa,QAAa;AAErC,QAAQ,MAAM,QAAQ,IAAI,IAAI,IAAI,WAAW,KAAM,OAAO,OAAO,kBAAkB;;AAGrF,IAAa,gBAAgB,YAA4B;AAGvD,QAFkC,QAAQ,QAAQ,YAAY,GAAG,CAClB,MAAM,IAAI,CAAC,SACpC,MAAM,IAAI,QAAQ;;;;ACN1C,IAAa,6BAA6B,aAA4B;CACpE,MAAM,SAA+C,EAAE;AACvD,UAAS,KAAK,SAAS,MAAM;AAC3B,SAAO,KAAK;GAAE,GAAG,EAAE,MAAM;GAAE,OAAO,EAAE;GAAI,CAAC;GACzC;AACF,QAAO;;AAGT,IAAa,6BAA6B,aAA4B;CACpE,MAAM,gBAA8F;EAClG,OAAO,EAAE;EACT,UAAU,EAAE;EACZ,SAAS,EAAE;EACZ;AACD,UAAS,YAAY,CAAC,SAAS,WAAW;AACxC,gBAAc,OAAO,MAAM,KAAK,OAAO,IAAI,MAAM,CAAC;GAClD;AACF,QAAO;EAAC,GAAG,cAAc;EAAO,GAAG,cAAc;EAAU,GAAG,cAAc;EAAQ,CAAC,SAAS,IAC1F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,EAAE,SAAS,kBAAkB,KAAK,aAAa,SAAS,YAAY;GAC1E,MAAM,mBAAmB,0BAA0B;IACjD;IACA,KAAK;IACL;IACA;IACA;IACA;IACA;IACA;IACD,CAAC;AACF,OAAI,CAAC,OAAO,OAAO,kBAAkB,CAAC,SAAS,OAAO,CACpD,OAAM,IAAI,MAAM,sBAAsB,OAAO,0CAA0C;AAEzF,oBAAiB,QAAQ;IACvB,aAAa,aAAa,cAAc,YAAY,cAAc,EAAE;IACpE;IACA;IACD,CAAC;;GAGP"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/adapter/types/adapter.firestore.types.ts","../src/adapter/types/adapter.realtime.types.ts","../src/utils/misc.ts","../src/constraints/firebase.constraints.ts","../src/constraints/constraints.builder.ts","../src/firestore/utils/result.utils.ts","../src/firestore/utils/ref.utils.ts","../src/firestore/utils/constraints.utils.ts","../src/firestore/firestore.sockets.ts","../src/firestore/firestore.methods.ts","../src/realtime/utils/result.utils.ts","../src/realtime/utils/constraints.utils.ts","../src/realtime/realtime.methods.ts","../src/realtime/realtime.sockets.ts","../src/adapter/adapter.sockets.ts","../src/adapter/adapter.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\nimport type { Adapter } from \"@hyper-fetch/core\";\nimport type { SocketAdapter } from \"@hyper-fetch/sockets\";\nimport type {\n FirestoreConstraints,\n FirestoreConstraintsUnion,\n FirestorePermittedMethods,\n PermittedConstraints,\n SharedQueryConstraints,\n} from \"constraints\";\nimport type {\n Unsubscribe as FirestoreUnsubscribe,\n CollectionReference,\n DocumentReference,\n DocumentSnapshot,\n QuerySnapshot,\n} from \"firebase/firestore\";\n\nexport type FirestoreSocketAdapterType = SocketAdapter<never, FirestoreOnSnapshotExtra, FirestoreListenerOptions>;\n\nexport type FirestoreAdapterType =\n | Adapter<\n Record<string, never>,\n \"getDoc\",\n FirestoreStatuses,\n FirestoreExtra,\n FirestoreQueryParams,\n FirestoreQueryParams\n >\n | Adapter<\n Record<string, never>,\n \"getDocs\",\n FirestoreStatuses,\n FirestoreGetDocsExtra,\n FirestoreQueryParams,\n FirestoreQueryParams\n >\n | Adapter<{ merge: boolean }, \"setDoc\", FirestoreStatuses, FirestoreRefOnlyExtra, Record<string, never>, undefined>\n | Adapter<\n Record<string, never>,\n \"updateDoc\" | \"addDoc\" | \"deleteDoc\" | \"setDoc\",\n FirestoreStatuses,\n FirestoreRefOnlyExtra,\n Record<string, never>,\n undefined\n >;\n\n/** One Firestore query constraint, built with `$where`, `$orderBy`, `$limit` or a cursor helper such as `$startAfter`. */\nexport type FirestoreConstraint = PermittedConstraints<\n FirestorePermittedMethods,\n FirestoreConstraintsUnion | SharedQueryConstraints\n>;\n\n/**\n * Query params of a Firestore request: a callback that builds typed constraints, or the constraints array it\n * resolves to. Pass the document type to check field names and values: `queryParams?: FirestoreQueryParams<Tea>`.\n *\n * @example\n * getTeas.send({ queryParams: (c) => c.where(\"type\", \"==\", \"Green\").orderBy(\"year\", \"desc\").limit(20) });\n */\nexport type FirestoreQueryParams<Doc = any> =\n | FirestoreConstraint[]\n | ((constraints: FirestoreConstraints<Doc>) => FirestoreConstraints<Doc, any>)\n | FirestoreDeprecatedQueryParams;\n\n/** @deprecated Pass the constraints directly: `queryParams: (c) => c.where(...)` or `queryParams: [$where(...)]`. */\nexport type FirestoreDeprecatedQueryParams = {\n /** @deprecated Pass the constraints directly: `queryParams: (c) => c.where(...)` or `queryParams: [$where(...)]`. */\n constraints?: FirestoreConstraint[];\n};\n\n/** Query params of a Firestore listener: a callback that builds typed constraints, or the constraints array. */\nexport type FirestoreListenerQueryParams<Doc = any> =\n | FirestoreConstraint[]\n | ((constraints: FirestoreConstraints<Doc>) => FirestoreConstraints<Doc, any>);\n\n/** Options of a Firestore `onSnapshot` listener. Constraints go in the listener's `queryParams`. */\nexport type FirestoreListenerOptions = {\n /** @deprecated Use the listener's query params: `setQueryParams((c) => c.where(...))`. */\n constraints?: FirestoreConstraint[];\n /**\n * On collection listeners, adds `extra.groupedResult` with the `added`, `modified` and `removed` documents of each\n * snapshot. Document listeners get `null`.\n */\n groupByChangeType?: boolean;\n};\n\nexport enum FirestoreMethods {\n addDoc = \"addDoc\",\n getDoc = \"getDoc\",\n getDocs = \"getDocs\",\n setDoc = \"setDoc\",\n updateDoc = \"updateDoc\",\n deleteDoc = \"deleteDoc\",\n}\n\nexport type FirestoreMethodsUnion =\n | FirestoreMethods.addDoc\n | FirestoreMethods.getDoc\n | FirestoreMethods.getDocs\n | FirestoreMethods.setDoc\n | FirestoreMethods.updateDoc\n | FirestoreMethods.deleteDoc;\n\nexport type FirestoreExtra = {\n ref?: DocumentReference;\n snapshot?: DocumentSnapshot;\n};\n\nexport type FirestoreOnSnapshotExtra = {\n ref?: DocumentReference | CollectionReference;\n snapshot?: DocumentSnapshot;\n unsubscribe?: FirestoreUnsubscribe;\n groupedResult?: { added: DocumentSnapshot[]; modified: DocumentSnapshot[]; removed: DocumentSnapshot[] };\n};\n\nexport type FirestoreGetDocsExtra = {\n ref?: CollectionReference;\n snapshot?: QuerySnapshot;\n};\n\nexport type FirestoreRefOnlyExtra = {\n ref?: DocumentReference;\n};\n\nexport type FirestoreStatuses = \"success\" | \"error\" | \"emptyResource\";\n","/* eslint-disable @typescript-eslint/naming-convention */\nimport type { Adapter } from \"@hyper-fetch/core\";\nimport type { SocketAdapter } from \"@hyper-fetch/sockets\";\nimport type {\n OrderedRealtimeConstraints,\n PermittedConstraints,\n RealtimeConstraints,\n RealtimeConstraintsUnion,\n RealtimePermittedMethods,\n SharedQueryConstraints,\n} from \"constraints\";\nimport type { DatabaseReference, DataSnapshot } from \"firebase/database\";\n\nexport type RealtimeSocketAdapterType = SocketAdapter<never, RealtimeDbOnValueMethodExtra, RealtimeDBListenerOptions>;\n\nexport type RealtimeDbAdapterType =\n | Adapter<\n DefaultRealtimeDBAdapterOptions,\n \"get\",\n RealtimeDBStatuses,\n RealtimeDbGetMethodExtra,\n RealtimeDBQueryParams,\n RealtimeDBQueryParams\n >\n | Adapter<\n DefaultRealtimeDBAdapterOptions,\n \"push\",\n RealtimeDBStatuses,\n RealtimeDbPushMethodExtra,\n Record<string, never>,\n undefined\n >\n | Adapter<\n DefaultRealtimeDBAdapterOptions,\n \"set\" | \"update\" | \"remove\",\n RealtimeDBStatuses,\n RealtimeDbDefaultExtra,\n Record<string, never>,\n undefined\n >;\n\nexport type DefaultRealtimeDBAdapterOptions = {\n priority?: number;\n};\n\nexport enum RealtimeDBMethods {\n set = \"set\",\n push = \"push\",\n update = \"update\",\n get = \"get\",\n remove = \"remove\",\n}\n\nexport type RealtimeDBMethodsUnion =\n | RealtimeDBMethods.set\n | RealtimeDBMethods.push\n | RealtimeDBMethods.update\n | RealtimeDBMethods.get\n | RealtimeDBMethods.remove;\n\nexport type RealtimeDBStatuses = \"success\" | \"error\" | \"emptyResource\";\nexport type RealtimeDbOnValueMethodExtra = {\n ref: DatabaseReference;\n snapshot: DataSnapshot;\n};\n\nexport type RealtimeDbGetMethodExtra = {\n ref: DatabaseReference;\n snapshot: DataSnapshot;\n};\n\nexport type RealtimeDbDefaultExtra = {\n ref: DatabaseReference;\n};\n\nexport type RealtimeDbPushMethodExtra = {\n ref: DatabaseReference;\n key: string;\n};\n\n/** One Realtime Database query constraint, built with `$orderByChild`, `$limitToFirst`, `$equalTo` or a cursor helper. */\nexport type RealtimeDBConstraint = PermittedConstraints<\n RealtimePermittedMethods,\n RealtimeConstraintsUnion | SharedQueryConstraints\n>;\n\n/**\n * Query params of a Realtime Database request: a callback that builds typed constraints, or the constraints array it\n * resolves to. Pass the type of the list's children to check paths and values:\n * `queryParams?: RealtimeDBQueryParams<Message>`.\n *\n * @example\n * getMessages.send({ queryParams: (c) => c.orderByChild(\"sentAt\").limitToLast(50) });\n */\nexport type RealtimeDBQueryParams<Doc = any> =\n | RealtimeDBConstraint[]\n | ((constraints: RealtimeConstraints<Doc>) => RealtimeConstraints<Doc> | OrderedRealtimeConstraints<Doc, any>)\n | RealtimeDBDeprecatedQueryParams;\n\n/** @deprecated Pass the constraints directly: `queryParams: (c) => c.orderByChild(...)` or an array. */\nexport type RealtimeDBDeprecatedQueryParams = {\n /** @deprecated Pass the constraints directly: `queryParams: (c) => c.orderByChild(...)` or an array. */\n constraints?: RealtimeDBConstraint[];\n};\n\n/** Query params of a Realtime Database listener: a callback that builds typed constraints, or the array. */\nexport type RealtimeDBListenerQueryParams<Doc = any> =\n | RealtimeDBConstraint[]\n | ((constraints: RealtimeConstraints<Doc>) => RealtimeConstraints<Doc> | OrderedRealtimeConstraints<Doc, any>);\n\n/** Options of a Realtime Database `onValue` listener. Constraints go in the listener's `queryParams`. */\nexport type RealtimeDBListenerOptions = {\n /** @deprecated Use the listener's query params: `setQueryParams((c) => c.orderByChild(...))`. */\n constraints?: RealtimeDBConstraint[];\n /** Receive only the first value, then stop listening. */\n onlyOnce?: boolean;\n};\n","export const getStatus = (res: any): \"success\" | \"emptyResource\" => {\n // Deliberate == instead of ===\n return (Array.isArray(res) && res.length === 0) || res == null ? \"emptyResource\" : \"success\";\n};\n\nexport const isDocOrQuery = (fullUrl: string): string => {\n const withoutSurroundingSlashes = fullUrl.replace(/^\\/|\\/$/g, \"\");\n const pathElements = withoutSurroundingSlashes.split(\"/\").length;\n return pathElements % 2 === 0 ? \"doc\" : \"query\";\n};\n","import type { OrderByDirection, WhereFilterOp } from \"firebase-admin/firestore\";\n\nexport enum SharedQueryConstraints {\n START_AT = \"startAt\",\n START_AFTER = \"startAfter\",\n END_AT = \"endAt\",\n END_BEFORE = \"endBefore\",\n}\nexport enum RealtimeQueryConstraints {\n ORDER_BY_CHILD = \"orderByChild\",\n ORDER_BY_KEY = \"orderByKey\",\n ORDER_BY_VALUE = \"orderByValue\",\n LIMIT_TO_FIRST = \"limitToFirst\",\n LIMIT_TO_LAST = \"limitToLast\",\n EQUAL_TO = \"equalTo\",\n}\n\nexport enum FirestoreQueryConstraints {\n WHERE = \"where\",\n ORDER_BY = \"orderBy\",\n LIMIT = \"limit\",\n}\n\n/**\n * Firestore filter, the HyperFetch form of Firestore's `where()`.\n *\n * @param fieldPath - Field to compare, dot notation reaches nested fields (`\"address.city\"`)\n * @param opStr - Firestore operator such as `\"==\"`, `\">=\"`, `\"in\"` or `\"array-contains\"`\n * @param value - Value to compare the field with\n * @example\n * getTeas.send({ queryParams: [$where(\"type\", \"==\", \"Green\"), $where(\"year\", \">=\", 2020)] });\n */\nexport const $where = (fieldPath: string, opStr: WhereFilterOp, value: any) => {\n return {\n toString: () => `${FirestoreQueryConstraints.WHERE}_${fieldPath}${opStr}${value}`,\n type: FirestoreQueryConstraints.WHERE as const,\n values: [fieldPath, opStr, value],\n };\n};\n\n/**\n * Firestore ordering, the HyperFetch form of Firestore's `orderBy()`. Cursors take one value per `$orderBy`, in the same\n * order.\n *\n * @param fieldPath - Field to order by\n * @param directionStr - `\"asc\"` (default) or `\"desc\"`\n * @example\n * getTeas.send({ queryParams: [$orderBy(\"year\", \"desc\"), $orderBy(\"name\")] });\n */\nexport const $orderBy = (fieldPath: string, directionStr?: OrderByDirection) => {\n return {\n toString: () => `${FirestoreQueryConstraints.ORDER_BY}_${fieldPath}_${directionStr || \"\"}`,\n type: FirestoreQueryConstraints.ORDER_BY as const,\n values: [fieldPath, directionStr],\n };\n};\n\n/**\n * Firestore limit, the HyperFetch form of Firestore's `limit()`.\n *\n * @param num - Maximum number of documents to return\n * @example\n * getTeas.send({ queryParams: [$orderBy(\"year\"), $limit(20)] });\n */\nexport const $limit = (num: number) => {\n return {\n toString: () => `${FirestoreQueryConstraints.LIMIT}_${num}`,\n type: FirestoreQueryConstraints.LIMIT as const,\n values: [num],\n };\n};\n\nconst startEndConstraintsImpl = (constraintType: SharedQueryConstraints) => {\n return (...docOrFields: any[]) => {\n if (docOrFields.length === 1 && docOrFields[0].query) {\n return {\n toString: () => `${constraintType}_${docOrFields[0].query?._query?.memoizedTarget?.memoizedCanonicalId}`,\n type: constraintType,\n values: [docOrFields],\n };\n }\n return {\n toString: () => `${constraintType}_${docOrFields}`,\n type: constraintType,\n values: [docOrFields],\n };\n };\n};\n\n/**\n * Cursor that starts the ordered query at the given values, inclusive.\n *\n * In Firestore pass one value per `$orderBy`, in the same order. In Realtime Database pass the value of the\n * `$orderBy*` field and, optionally, a key that breaks ties between equal values.\n *\n * @example\n * // Firestore\n * getTeas.send({ queryParams: [$orderBy(\"year\"), $orderBy(\"name\"), $startAt(2022, \"Bi Luo Chun\")] });\n * // Realtime Database\n * getTeas.send({ queryParams: [$orderByChild(\"year\"), $startAt(2022)] });\n */\nexport const $startAt = startEndConstraintsImpl(SharedQueryConstraints.START_AT as const);\n/**\n * Cursor that starts the ordered query after the given values, exclusive. Use it to load the next page.\n *\n * In Firestore pass one value per `$orderBy`, in the same order. In Realtime Database pass the value of the\n * `$orderBy*` field and, optionally, a key that breaks ties between equal values.\n *\n * @example\n * const last = page.data?.at(-1);\n * getTeas.send({ queryParams: [$orderBy(\"year\"), $startAfter(last?.year), $limit(20)] });\n */\nexport const $startAfter = startEndConstraintsImpl(SharedQueryConstraints.START_AFTER as const);\n\n/**\n * Cursor that ends the ordered query at the given values, inclusive.\n *\n * In Firestore pass one value per `$orderBy`, in the same order. In Realtime Database pass the value of the\n * `$orderBy*` field and, optionally, a key that breaks ties between equal values.\n *\n * @example\n * getTeas.send({ queryParams: [$orderBy(\"year\"), $endAt(2011)] });\n */\nexport const $endAt = startEndConstraintsImpl(SharedQueryConstraints.END_AT as const);\n/**\n * Cursor that ends the ordered query before the given values, exclusive.\n *\n * In Firestore pass one value per `$orderBy`, in the same order. In Realtime Database pass the value of the\n * `$orderBy*` field and, optionally, a key that breaks ties between equal values.\n *\n * @example\n * getTeas.send({ queryParams: [$orderBy(\"year\"), $endBefore(2011)] });\n */\nexport const $endBefore = startEndConstraintsImpl(SharedQueryConstraints.END_BEFORE as const);\n\n/**\n * Realtime Database ordering by a child value, the HyperFetch form of `orderByChild()`. A query can have one `$orderBy*`.\n *\n * @param path - Child path to order by, for example `\"year\"` or `\"author/name\"`\n * @example\n * getTeas.send({ queryParams: [$orderByChild(\"year\"), $limitToFirst(10)] });\n */\nexport const $orderByChild = (path: string) => {\n return {\n toString: () => `${RealtimeQueryConstraints.ORDER_BY_CHILD}_${path}`,\n type: RealtimeQueryConstraints.ORDER_BY_CHILD as const,\n values: [path],\n };\n};\n\n/**\n * Realtime Database ordering by key, the HyperFetch form of `orderByKey()`. A query can have one `$orderBy*`.\n *\n * @example\n * getTeas.send({ queryParams: [$orderByKey(), $limitToLast(10)] });\n */\nexport const $orderByKey = () => {\n return {\n toString: () => `${RealtimeQueryConstraints.ORDER_BY_KEY}`,\n type: RealtimeQueryConstraints.ORDER_BY_KEY as const,\n values: [],\n };\n};\n\n/**\n * Realtime Database ordering by the child values themselves, the HyperFetch form of `orderByValue()`. A query can have\n * one `$orderBy*`.\n *\n * @example\n * getScores.send({ queryParams: [$orderByValue(), $limitToLast(3)] });\n */\nexport const $orderByValue = () => {\n return {\n toString: () => `${RealtimeQueryConstraints.ORDER_BY_VALUE}`,\n type: RealtimeQueryConstraints.ORDER_BY_VALUE as const,\n values: [],\n };\n};\n\n/**\n * Realtime Database limit from the start of the ordered list, the HyperFetch form of `limitToFirst()`.\n *\n * @param num - Maximum number of children to return\n * @example\n * getTeas.send({ queryParams: [$orderByChild(\"year\"), $limitToFirst(5)] });\n */\nexport const $limitToFirst = (num: number) => {\n return {\n toString: () => `${RealtimeQueryConstraints.LIMIT_TO_FIRST}_${num}`,\n type: RealtimeQueryConstraints.LIMIT_TO_FIRST as const,\n values: [num],\n };\n};\n\n/**\n * Realtime Database limit from the end of the ordered list, the HyperFetch form of `limitToLast()`.\n *\n * @param num - Maximum number of children to return\n * @example\n * getMessages.send({ queryParams: [$orderByChild(\"sentAt\"), $limitToLast(50)] });\n */\nexport const $limitToLast = (num: number) => {\n return {\n toString: () => `${RealtimeQueryConstraints.LIMIT_TO_LAST}_${num}`,\n type: RealtimeQueryConstraints.LIMIT_TO_LAST as const,\n values: [num],\n };\n};\n\n/**\n * Realtime Database filter for children equal to a value, the HyperFetch form of `equalTo()`. Combine it with an\n * `$orderBy*` that picks the compared value.\n *\n * @param value - Value the ordered field must equal\n * @param key - Optional key that breaks ties between children with the same value\n * @example\n * getTeas.send({ queryParams: [$orderByChild(\"type\"), $equalTo(\"Green\")] });\n */\nexport const $equalTo = (value: any, key?: string) => {\n return {\n toString: () => `${RealtimeQueryConstraints.EQUAL_TO}_${value}${key === undefined ? \"\" : `_${key}`}`,\n type: RealtimeQueryConstraints.EQUAL_TO as const,\n values: key === undefined ? [value] : [value, key],\n };\n};\n","import type { OrderByDirection, WhereFilterOp } from \"firebase-admin/firestore\";\n\nimport type { FirestorePermittedMethods, RealtimePermittedMethods } from \"./constraints.types\";\nimport {\n $endAt,\n $endBefore,\n $equalTo,\n $limit,\n $limitToFirst,\n $limitToLast,\n $orderBy,\n $orderByChild,\n $orderByKey,\n $orderByValue,\n $startAfter,\n $startAt,\n $where,\n} from \"./firebase.constraints\";\n\ntype Primitive = string | number | boolean | bigint | symbol | null | undefined | Date;\ntype IsAny<T> = 0 extends 1 & T ? true : false;\ntype PreviousDepth = [never, 0, 1, 2, 3, 4];\n\n/**\n * Paths to the fields of a document, nested objects included (up to 4 levels), joined with `Separator`: `.` for\n * Firestore field paths, `/` for Realtime Database child paths. The `__key` id added by the adapter is not a field.\n */\nexport type FieldPath<Doc, Separator extends string = \".\", Depth extends number = 4> =\n IsAny<Doc> extends true\n ? string\n : [Depth] extends [never]\n ? never\n : Doc extends Primitive | readonly any[]\n ? never\n : {\n [Key in Exclude<keyof Doc, \"__key\"> & string]: NonNullable<Doc[Key]> extends Primitive | readonly any[]\n ? Key\n : Key | `${Key}${Separator}${FieldPath<NonNullable<Doc[Key]>, Separator, PreviousDepth[Depth]>}`;\n }[Exclude<keyof Doc, \"__key\"> & string];\n\n/** Value type of the field at `Path`. */\nexport type FieldValue<Doc, Path extends string, Separator extends string = \".\"> =\n IsAny<Doc> extends true\n ? any\n : Path extends `${infer Key}${Separator}${infer Rest}`\n ? Key extends keyof Doc\n ? FieldValue<NonNullable<Doc[Key]>, Rest, Separator>\n : never\n : Path extends keyof Doc\n ? Doc[Path]\n : never;\n\n/** Value a Firestore `where` takes for an operator: arrays for `in` / `not-in`, an element for `array-contains`. */\nexport type WhereValue<Value, Operator extends WhereFilterOp> = Operator extends \"in\" | \"not-in\"\n ? Value[]\n : Operator extends \"array-contains\"\n ? NonNullable<Value> extends readonly (infer Element)[]\n ? Element\n : never\n : Operator extends \"array-contains-any\"\n ? NonNullable<Value> extends readonly (infer Element)[]\n ? Element[]\n : never\n : Value;\n\ntype CursorPrefixes<Values extends unknown[]> = Values extends [...infer Init, any]\n ? Values | (Init extends [] ? never : CursorPrefixes<Init>)\n : never;\n\n/** Cursor values: one per `orderBy`, in order (a prefix is allowed), or a document id without `orderBy`. */\nexport type FirestoreCursorValues<Ordered extends unknown[]> = Ordered extends []\n ? [documentId: string]\n : CursorPrefixes<Ordered>;\n\n/**\n * Typed Firestore constraints for a document type, built as a chain. Received by the `queryParams` callback of\n * Firestore requests and listeners; the adapter stores the constraints it collected.\n *\n * @example\n * getTeas.send({ queryParams: (c) => c.where(\"type\", \"==\", \"Green\").orderBy(\"year\", \"desc\").limit(20) });\n */\nexport interface FirestoreConstraints<Doc = any, Ordered extends unknown[] = []> {\n /** Filter by a field, like Firestore's `where()`. The value type follows the field and the operator. */\n where<Path extends FieldPath<Doc>, Operator extends WhereFilterOp>(\n field: Path,\n operator: Operator,\n value: WhereValue<FieldValue<Doc, Path>, Operator>,\n ): FirestoreConstraints<Doc, Ordered>;\n /** Order by a field, like Firestore's `orderBy()`. Each `orderBy` adds one value the cursors take. */\n orderBy<Path extends FieldPath<Doc>>(\n field: Path,\n direction?: OrderByDirection,\n ): FirestoreConstraints<Doc, [...Ordered, FieldValue<Doc, Path>]>;\n /** Limit the number of documents, like Firestore's `limit()`. */\n limit(limit: number): FirestoreConstraints<Doc, Ordered>;\n /** Start at these values, inclusive: one per `orderBy`, in order. */\n startAt(...values: FirestoreCursorValues<Ordered>): FirestoreConstraints<Doc, Ordered>;\n /** Start after these values, exclusive. Pass the values of the last document to load the next page. */\n startAfter(...values: FirestoreCursorValues<Ordered>): FirestoreConstraints<Doc, Ordered>;\n /** End at these values, inclusive: one per `orderBy`, in order. */\n endAt(...values: FirestoreCursorValues<Ordered>): FirestoreConstraints<Doc, Ordered>;\n /** End before these values, exclusive: one per `orderBy`, in order. */\n endBefore(...values: FirestoreCursorValues<Ordered>): FirestoreConstraints<Doc, Ordered>;\n /** The collected constraints, the data a request or listener stores. */\n toJSON(): FirestorePermittedMethods[];\n}\n\n/**\n * Typed Realtime Database constraints for the type of a list's children, built as a chain. A query can have one\n * `orderBy*`; cursors and `equalTo` become available after it and take the ordered value.\n *\n * @example\n * getMessages.send({ queryParams: (c) => c.orderByChild(\"sentAt\").limitToLast(50) });\n */\nexport interface RealtimeConstraints<Doc = any> {\n /** Order by a child value, like `orderByChild()`. Nested children use `/`: `\"author/name\"`. */\n orderByChild<Path extends FieldPath<Doc, \"/\">>(\n path: Path,\n ): OrderedRealtimeConstraints<Doc, FieldValue<Doc, Path, \"/\">>;\n /** Order by key, like `orderByKey()`. */\n orderByKey(): OrderedRealtimeConstraints<Doc, string>;\n /** Order by the children's own values, like `orderByValue()`. */\n orderByValue(): OrderedRealtimeConstraints<Doc, Doc>;\n /** Limit to the first children, like `limitToFirst()`. */\n limitToFirst(limit: number): RealtimeConstraints<Doc>;\n /** Limit to the last children, like `limitToLast()`. */\n limitToLast(limit: number): RealtimeConstraints<Doc>;\n /** The collected constraints, the data a request or listener stores. */\n toJSON(): RealtimePermittedMethods[];\n}\n\n/** Realtime Database constraints after an `orderBy*`. Cursors and `equalTo` take the ordered value and a tie key. */\nexport interface OrderedRealtimeConstraints<Doc = any, Value = any> {\n /** Limit to the first children, like `limitToFirst()`. */\n limitToFirst(limit: number): OrderedRealtimeConstraints<Doc, Value>;\n /** Limit to the last children, like `limitToLast()`. */\n limitToLast(limit: number): OrderedRealtimeConstraints<Doc, Value>;\n /** Keep children whose ordered value equals `value`, like `equalTo()`. */\n equalTo(value: Value, key?: string): OrderedRealtimeConstraints<Doc, Value>;\n /** Start at `value`, inclusive. `key` breaks ties between equal values. */\n startAt(value: Value, key?: string): OrderedRealtimeConstraints<Doc, Value>;\n /** Start after `value`, exclusive. `key` breaks ties between equal values. */\n startAfter(value: Value, key?: string): OrderedRealtimeConstraints<Doc, Value>;\n /** End at `value`, inclusive. `key` breaks ties between equal values. */\n endAt(value: Value, key?: string): OrderedRealtimeConstraints<Doc, Value>;\n /** End before `value`, exclusive. `key` breaks ties between equal values. */\n endBefore(value: Value, key?: string): OrderedRealtimeConstraints<Doc, Value>;\n /** The collected constraints, the data a request or listener stores. */\n toJSON(): RealtimePermittedMethods[];\n}\n\n/** Untyped shape of the chains below; the factories cast it to the typed interfaces. */\ntype AnyChain = Record<string, (...args: any[]) => unknown>;\n\nconst firestoreChain = (constraints: FirestorePermittedMethods[]): AnyChain => {\n const add = (constraint: FirestorePermittedMethods) => firestoreChain([...constraints, constraint]);\n return {\n where: (field: string, operator: WhereFilterOp, value: unknown) => add($where(field, operator, value)),\n orderBy: (field: string, direction?: OrderByDirection) => add($orderBy(field, direction)),\n limit: (limit: number) => add($limit(limit)),\n startAt: (...values: unknown[]) => add($startAt(...values)),\n startAfter: (...values: unknown[]) => add($startAfter(...values)),\n endAt: (...values: unknown[]) => add($endAt(...values)),\n endBefore: (...values: unknown[]) => add($endBefore(...values)),\n toJSON: () => constraints,\n };\n};\n\nconst realtimeChain = (constraints: RealtimePermittedMethods[]): AnyChain => {\n const add = (constraint: RealtimePermittedMethods) => realtimeChain([...constraints, constraint]);\n return {\n orderByChild: (path: string) => add($orderByChild(path)),\n orderByKey: () => add($orderByKey()),\n orderByValue: () => add($orderByValue()),\n limitToFirst: (limit: number) => add($limitToFirst(limit)),\n limitToLast: (limit: number) => add($limitToLast(limit)),\n equalTo: (value: unknown, key?: string) => add($equalTo(value, key)),\n startAt: (value: unknown, key?: string) => add(key === undefined ? $startAt(value) : $startAt(value, key)),\n startAfter: (value: unknown, key?: string) => add(key === undefined ? $startAfter(value) : $startAfter(value, key)),\n endAt: (value: unknown, key?: string) => add(key === undefined ? $endAt(value) : $endAt(value, key)),\n endBefore: (value: unknown, key?: string) => add(key === undefined ? $endBefore(value) : $endBefore(value, key)),\n toJSON: () => constraints,\n };\n};\n\n/** Start an empty Firestore constraints chain. The adapter passes one to every `queryParams` callback. */\nexport const createFirestoreConstraints = <Doc = any>(): FirestoreConstraints<Doc> =>\n firestoreChain([]) as unknown as FirestoreConstraints<Doc>;\n\n/** Start an empty Realtime Database constraints chain. The adapter passes one to every `queryParams` callback. */\nexport const createRealtimeConstraints = <Doc = any>(): RealtimeConstraints<Doc> =>\n realtimeChain([]) as unknown as RealtimeConstraints<Doc>;\n\n/** Resolve a `queryParams` callback with a fresh chain into the constraints it collected. */\nexport const resolveConstraints =\n (createChain: () => { toJSON(): unknown[] }) => (callback: (...args: any[]) => unknown) =>\n (callback(createChain()) as { toJSON(): unknown[] }).toJSON();\n\n/**\n * The constraints of `queryParams` or listener options: an array, or the deprecated `{ constraints }` object.\n */\nexport const getConstraints = <Constraint>(queryParams: unknown): Constraint[] => {\n if (Array.isArray(queryParams)) {\n return queryParams as Constraint[];\n }\n if (\n queryParams &&\n typeof queryParams === \"object\" &&\n Array.isArray((queryParams as { constraints?: unknown }).constraints)\n ) {\n return (queryParams as { constraints: Constraint[] }).constraints;\n }\n return [];\n};\n","import type { QuerySnapshot, DocumentData } from \"firebase-admin/firestore\";\n\nexport const getOrderedResultFirestore = (snapshot: QuerySnapshot) => {\n const result: (DocumentData & { __key: string })[] = [];\n snapshot.docs.forEach((d) => {\n result.push({ ...d.data(), __key: d.id });\n });\n return result;\n};\n\nexport const getGroupedResultFirestore = (snapshot: QuerySnapshot) => {\n const groupedResult: { added: DocumentData[]; modified: DocumentData[]; removed: DocumentData[] } = {\n added: [],\n modified: [],\n removed: [],\n };\n snapshot.docChanges().forEach((change) => {\n groupedResult[change.type].push(change.doc.data());\n });\n return [...groupedResult.added, ...groupedResult.modified, ...groupedResult.removed].length > 0\n ? groupedResult\n : null;\n};\n","import type { CollectionReference, DocumentReference, Firestore } from \"firebase-admin/firestore\";\n\nexport const getRef = (db: Firestore, fullUrl: string) => {\n const withoutSurroundingSlashes = fullUrl.replace(/^\\/|\\/$/g, \"\");\n const urlParts = withoutSurroundingSlashes.split(\"/\").map((element, index) => {\n return index % 2 === 0 ? [\"collection\", element] : [\"doc\", element];\n });\n\n return urlParts.reduce(\n (_db, value) => {\n const [method, pathPart] = value;\n if (method === \"doc\" && \"doc\" in _db) {\n return _db.doc(pathPart);\n }\n if (method === \"collection\" && \"collection\" in _db) {\n return _db.collection(pathPart);\n }\n return _db;\n },\n db as unknown as Firestore | CollectionReference | DocumentReference,\n ) as CollectionReference | DocumentReference;\n};\n","import type { Query } from \"firebase-admin/firestore\";\nimport type { OrderByDirection } from \"firebase/firestore\";\n\nimport type { FirestorePermittedMethods } from \"../../constraints\";\nimport { FirestoreQueryConstraints, SharedQueryConstraints } from \"../../constraints\";\n\nexport const applyFireStoreAdminConstraint = (collectionRef: Query, { type, values }: FirestorePermittedMethods) => {\n switch (type) {\n case FirestoreQueryConstraints.WHERE: {\n const [fieldPath, strOp, value] = values;\n return collectionRef.where(fieldPath, strOp, value);\n }\n case FirestoreQueryConstraints.ORDER_BY: {\n const [field, ord] = values;\n return collectionRef.orderBy(field!, ord as OrderByDirection);\n }\n case FirestoreQueryConstraints.LIMIT: {\n const [limitValue] = values;\n return collectionRef.limit(limitValue);\n }\n case SharedQueryConstraints.START_AT: {\n const [docOrFields] = values;\n return collectionRef.startAt(...docOrFields);\n }\n case SharedQueryConstraints.START_AFTER: {\n const [docOrFields] = values;\n return collectionRef.startAfter(...docOrFields);\n }\n case SharedQueryConstraints.END_AT: {\n const [docOrFields] = values;\n return collectionRef.endAt(...docOrFields);\n }\n case SharedQueryConstraints.END_BEFORE: {\n const [docOrFields] = values;\n return collectionRef.endBefore(...docOrFields);\n }\n default:\n throw new Error(`Unknown method ${type}`);\n }\n};\n\nexport const applyFireStoreAdminConstraints = (collectionRef: Query, constraints: FirestorePermittedMethods[]) => {\n return constraints.reduce((collection, constraint) => {\n return applyFireStoreAdminConstraint(collection, constraint);\n }, collectionRef);\n};\n","import { SocketAdapter } from \"@hyper-fetch/sockets\";\nimport type { FirestoreAdminSocketAdapterType } from \"adapter\";\nimport type { DocumentReference, Firestore, Query, QuerySnapshot } from \"firebase-admin/firestore\";\nimport { CollectionReference, DocumentSnapshot } from \"firebase-admin/firestore\";\nimport { getStatus } from \"utils\";\n\nimport { createFirestoreConstraints, getConstraints, resolveConstraints } from \"../constraints\";\nimport type { FirestorePermittedMethods } from \"../constraints\";\nimport { getGroupedResultFirestore, getOrderedResultFirestore, getRef, applyFireStoreAdminConstraints } from \"./utils\";\n\nexport const firestoreAdminSockets = (database: Firestore) => {\n return (\n new SocketAdapter({\n name: \"firebase-admin-firestore\",\n defaultConnected: true,\n }) as unknown as FirestoreAdminSocketAdapterType\n )\n .setListenerQueryParamsResolver(resolveConstraints(createFirestoreConstraints))\n .setConnector(({ socket, onReconnect, onListen, onEvent, onError }) => {\n const connect = () => {\n throw new Error(\"Connect function is not implemented for Firestore Admin socket.\");\n };\n\n const disconnect = () => {\n throw new Error(\"Cannot disconnect from Firestore database socket. Use 'app.delete()' instead.\");\n };\n\n const reconnect = () => {\n onReconnect({ disconnect, connect });\n };\n\n const listen: FirestoreAdminSocketAdapterType[\"listen\"] = (listener, callback) => {\n const fullUrl = socket.url + listener.topic;\n const { options } = listener;\n let pathRef: DocumentReference | Query = getRef(database, fullUrl);\n if (pathRef instanceof CollectionReference) {\n // `options.constraints` is the deprecated place for constraints, kept working in v10\n pathRef = applyFireStoreAdminConstraints(\n pathRef,\n getConstraints<FirestorePermittedMethods>(listener.queryParams ?? options?.constraints),\n );\n }\n let unsubscribe = () => {};\n let unmount = () => {};\n let clearListeners = () => {};\n\n unsubscribe = pathRef.onSnapshot(\n (snapshot) => {\n const getSnapshotData = (s: DocumentSnapshot) => (s.data() ? { ...s.data(), __key: s.id } : null);\n const response =\n snapshot instanceof DocumentSnapshot\n ? getSnapshotData(snapshot)\n : getOrderedResultFirestore(snapshot as QuerySnapshot);\n const status = getStatus(response);\n const groupedResult =\n options?.groupByChangeType === true && !(snapshot instanceof DocumentSnapshot)\n ? getGroupedResultFirestore(snapshot as QuerySnapshot)\n : null;\n const extra = { ref: pathRef, snapshot, unsubscribe, groupedResult, status };\n onEvent({ topic: listener.topic, data: response, extra });\n },\n (error) => {\n onError({ error });\n },\n );\n unmount = onListen({ listener, callback, onUnmount: unsubscribe });\n clearListeners = () => {\n unsubscribe();\n unmount();\n };\n\n return clearListeners;\n };\n\n const emit = async () => {\n throw new Error(\"Cannot emit from Firestore database socket.\");\n };\n\n return {\n connect,\n reconnect,\n disconnect,\n emit,\n listen,\n };\n });\n};\n","import type { getAdapterBindings } from \"@hyper-fetch/core\";\nimport type { FirestoreMethodsUnion } from \"adapter\";\nimport type {\n FirestoreConstraintsUnion,\n FirestorePermittedMethods,\n PermittedConstraints,\n SharedQueryConstraints,\n} from \"constraints\";\n/* eslint-disable max-params */\nimport type { CollectionReference, DocumentReference, DocumentSnapshot, Firestore } from \"firebase-admin/firestore\";\nimport { getStatus } from \"utils\";\n\nimport { applyFireStoreAdminConstraints, getOrderedResultFirestore, getRef } from \"./utils\";\n\ntype DataType = {\n constraints?: PermittedConstraints<FirestorePermittedMethods, FirestoreConstraintsUnion | SharedQueryConstraints>[];\n payload?: any;\n options?: Record<string, any>;\n};\n\nexport const getFirestoreAdminMethods = ({\n database,\n url,\n onSuccess,\n onError,\n onResponseStart,\n onRequestStart,\n onRequestEnd,\n onResponseEnd,\n}: {\n database: Firestore;\n url: string;\n onSuccess: Awaited<ReturnType<typeof getAdapterBindings>>[\"onSuccess\"];\n onError: Awaited<ReturnType<typeof getAdapterBindings>>[\"onError\"];\n onResponseStart: Awaited<ReturnType<typeof getAdapterBindings>>[\"onResponseStart\"];\n onRequestStart: Awaited<ReturnType<typeof getAdapterBindings>>[\"onRequestStart\"];\n onRequestEnd: Awaited<ReturnType<typeof getAdapterBindings>>[\"onRequestEnd\"];\n onResponseEnd: Awaited<ReturnType<typeof getAdapterBindings>>[\"onResponseEnd\"];\n}): ((methodName: FirestoreMethodsUnion, data: DataType) => Promise<void>) => {\n const [cleanUrl] = url.split(\"?\");\n const methods = {\n getDoc: async () => {\n const path = getRef(database, cleanUrl);\n const snapshot = (await path.get()) as DocumentSnapshot;\n const result = snapshot.data() ? { ...snapshot.data(), __key: snapshot.id } : null;\n const status = result ? \"success\" : \"emptyResource\";\n return { result, status, extra: { ref: path, snapshot } };\n },\n getDocs: async ({\n constraints = [],\n }: {\n constraints?: PermittedConstraints<\n FirestorePermittedMethods,\n FirestoreConstraintsUnion | SharedQueryConstraints\n >[];\n }) => {\n const path = getRef(database, cleanUrl) as CollectionReference;\n const query = applyFireStoreAdminConstraints(path, constraints);\n const querySnapshot = await query.get();\n const result = getOrderedResultFirestore(querySnapshot);\n const status = getStatus(result);\n\n return { result, status, extra: { ref: path, snapshot: querySnapshot } };\n },\n setDoc: async ({ payload, options }: DataType) => {\n const path = getRef(database, cleanUrl) as DocumentReference;\n const merge = options?.merge === true;\n const res = await path.set(payload, { merge });\n return { result: res, status: \"success\", extra: { ref: path } };\n },\n addDoc: async ({ payload }: DataType) => {\n const ref = getRef(database, cleanUrl) as CollectionReference;\n const docRef = await ref.add(payload);\n return { result: { ...payload, __key: docRef.id }, status: \"success\", extra: { ref: docRef } };\n },\n updateDoc: async ({ payload }: DataType) => {\n const path = getRef(database, cleanUrl) as DocumentReference;\n await path.update(payload);\n return { result: payload, status: \"success\", extra: { ref: path } };\n },\n deleteDoc: async () => {\n const path = getRef(database, cleanUrl) as DocumentReference;\n await path.delete();\n return { result: null, status: \"success\", extra: { ref: path } };\n },\n };\n\n return async (methodName: FirestoreMethodsUnion, data: DataType) => {\n try {\n onRequestStart();\n const { result, status, extra } = await methods[methodName](data);\n onRequestEnd();\n onResponseStart();\n onSuccess({ data: result, status, extra });\n onResponseEnd();\n } catch (error) {\n onRequestEnd();\n onResponseStart();\n onError({ error, status: \"error\", extra: {} });\n onResponseEnd();\n }\n };\n};\n","import type { DataSnapshot } from \"firebase-admin/database\";\n\nexport const getOrderedResultRealtime = (snapshot: DataSnapshot) => {\n const res: any = [];\n snapshot.forEach((child) => {\n res.push({ ...child.val(), __key: child.key });\n });\n return res.length > 0 ? res : null;\n};\n","import type { RealtimePermittedMethods } from \"constraints\";\nimport { RealtimeQueryConstraints, SharedQueryConstraints } from \"constraints\";\nimport type { Query } from \"firebase-admin/database\";\n\nexport const applyRealtimeAdminConstraint = (ref: Query, { type, values }: RealtimePermittedMethods) => {\n switch (type) {\n case RealtimeQueryConstraints.ORDER_BY_CHILD: {\n const [value] = values;\n return ref.orderByChild(value);\n }\n case RealtimeQueryConstraints.ORDER_BY_KEY: {\n return ref.orderByKey();\n }\n case RealtimeQueryConstraints.ORDER_BY_VALUE: {\n return ref.orderByValue();\n }\n case SharedQueryConstraints.START_AT: {\n const [[value, key]] = values;\n return ref.startAt(value, key);\n }\n case SharedQueryConstraints.START_AFTER: {\n const [[value, key]] = values;\n return ref.startAfter(value, key);\n }\n case SharedQueryConstraints.END_AT: {\n const [[value, key]] = values;\n return ref.endAt(value, key);\n }\n case SharedQueryConstraints.END_BEFORE: {\n const [[value, key]] = values;\n return ref.endBefore(value, key);\n }\n case RealtimeQueryConstraints.LIMIT_TO_FIRST: {\n const [value] = values;\n return ref.limitToFirst(value);\n }\n case RealtimeQueryConstraints.LIMIT_TO_LAST: {\n const [value] = values;\n return ref.limitToLast(value);\n }\n case RealtimeQueryConstraints.EQUAL_TO: {\n const [value, key] = values;\n return ref.equalTo(value, key);\n }\n default:\n throw new Error(`Unknown method ${type}`);\n }\n};\n\nexport const applyRealtimeAdminConstraints = (ref: Query, constraints: RealtimePermittedMethods[]) => {\n return constraints.reduce((collection, constraint) => {\n return applyRealtimeAdminConstraint(collection, constraint);\n }, ref);\n};\n","import type { getAdapterBindings } from \"@hyper-fetch/core\";\nimport type { RealtimeDBMethodsUnion } from \"adapter/types\";\nimport type {\n PermittedConstraints,\n RealtimeConstraintsUnion,\n RealtimePermittedMethods,\n SharedQueryConstraints,\n} from \"constraints\";\n/* eslint-disable max-params */\nimport type { Database } from \"firebase-admin/database\";\nimport { applyRealtimeAdminConstraints, getOrderedResultRealtime } from \"realtime/index\";\nimport { getStatus, isDocOrQuery } from \"utils\";\n\ntype DataType = {\n constraints: PermittedConstraints<RealtimePermittedMethods, RealtimeConstraintsUnion | SharedQueryConstraints>[];\n payload: any;\n options: Record<string, any>;\n};\n\nexport const getRealtimeDbAdminMethods = ({\n database,\n url,\n onSuccess,\n onError,\n onResponseStart,\n onRequestStart,\n onRequestEnd,\n onResponseEnd,\n}: {\n database: Database;\n url: string;\n onSuccess: Awaited<ReturnType<typeof getAdapterBindings>>[\"onSuccess\"];\n onError: Awaited<ReturnType<typeof getAdapterBindings>>[\"onError\"];\n onResponseStart: Awaited<ReturnType<typeof getAdapterBindings>>[\"onResponseStart\"];\n onRequestStart: Awaited<ReturnType<typeof getAdapterBindings>>[\"onRequestStart\"];\n onRequestEnd: Awaited<ReturnType<typeof getAdapterBindings>>[\"onRequestEnd\"];\n onResponseEnd: Awaited<ReturnType<typeof getAdapterBindings>>[\"onResponseEnd\"];\n}): ((methodName: RealtimeDBMethodsUnion, data: DataType) => Promise<void>) => {\n const [fullUrl] = url.split(\"?\");\n const path = database.ref(fullUrl);\n const methods = {\n get: async ({ constraints = [] }: DataType) => {\n const docOrQuery = isDocOrQuery(fullUrl);\n const q = applyRealtimeAdminConstraints(path, constraints);\n const snapshot = await q.get();\n const res = docOrQuery === \"doc\" ? snapshot.val() : getOrderedResultRealtime(snapshot);\n const status = getStatus(res);\n return { result: res, status, extra: { ref: path, snapshot } };\n },\n set: async ({ payload }: DataType) => {\n await path.set(payload);\n return { result: payload, status: \"success\", extra: { ref: path } };\n },\n push: async ({ payload }: DataType) => {\n const resRef = await path.push(payload);\n return { result: { ...payload, __key: resRef.key }, status: \"success\", extra: { ref: resRef, key: resRef.key } };\n },\n update: async ({ payload }: DataType) => {\n await path.update(payload);\n return { result: payload, status: \"success\", extra: { ref: path } };\n },\n remove: async () => {\n await path.remove();\n return { result: null, status: \"success\", extra: { ref: path } };\n },\n };\n\n return async (methodName: RealtimeDBMethodsUnion, data: DataType) => {\n try {\n onRequestStart();\n const { result, status, extra } = await methods[methodName](data);\n onRequestEnd();\n onResponseStart();\n onSuccess({ data: result, status, extra });\n onResponseEnd();\n } catch (error) {\n onRequestEnd();\n onResponseStart();\n onError({ error, status: \"error\", extra: {} });\n onResponseEnd();\n }\n };\n};\n","import { SocketAdapter } from \"@hyper-fetch/sockets\";\nimport type { RealtimeAdminOnValueMethodExtra, RealtimeAdminSocketAdapterType } from \"adapter\";\nimport type { Database, DataSnapshot } from \"firebase-admin/database\";\nimport { getStatus, isDocOrQuery } from \"utils\";\n\nimport { createRealtimeConstraints, getConstraints, resolveConstraints } from \"../constraints\";\nimport type { RealtimePermittedMethods } from \"../constraints\";\nimport { applyRealtimeAdminConstraints, getOrderedResultRealtime } from \"./utils\";\n\nexport const realtimeSocketsAdmin = (database: Database) => {\n return (\n new SocketAdapter({\n name: \"firebase-admin-realtime\",\n defaultConnected: true,\n }) as unknown as RealtimeAdminSocketAdapterType\n )\n .setListenerQueryParamsResolver(resolveConstraints(createRealtimeConstraints))\n .setConnector(\n ({ socket, onReconnect, onConnect, onConnected, onDisconnect, onDisconnected, onListen, onEvent, onError }) => {\n const connect = async () => {\n const connection = await onConnect();\n\n if (connection) {\n database.goOnline();\n onConnected();\n }\n };\n\n const disconnect = async () => {\n database.goOffline();\n onDisconnect();\n onDisconnected();\n };\n\n const reconnect = () => {\n onReconnect({ disconnect, connect });\n };\n\n const listen: RealtimeAdminSocketAdapterType[\"listen\"] = (listener, callback) => {\n const fullUrl = socket.url + listener.topic;\n const path = database.ref(fullUrl);\n const { options } = listener;\n const onlyOnce = options?.onlyOnce || false;\n // `options.constraints` is the deprecated place for constraints, kept working in v10\n const q = applyRealtimeAdminConstraints(\n path,\n getConstraints<RealtimePermittedMethods>(listener.queryParams ?? options?.constraints),\n );\n const method = onlyOnce === true ? \"once\" : \"on\";\n const onValue = (snapshot: DataSnapshot) => {\n const getSnapshotData = (s: DataSnapshot) => (s.val() ? { ...s.val(), __key: s.key } : null);\n const response =\n isDocOrQuery(fullUrl) === \"doc\" ? getSnapshotData(snapshot) : getOrderedResultRealtime(snapshot);\n const status = getStatus(response);\n const extra: RealtimeAdminOnValueMethodExtra = { ref: path, snapshot, status };\n onEvent({ topic: listener.topic, data: response, extra });\n };\n q[method](\"value\", onValue, (error) => {\n onError({ error });\n });\n // Detach only this listener's callback, other subscriptions on the same path keep receiving updates\n const unsubscribe = () => q.off(\"value\", onValue);\n const unmount = onListen({ listener, callback, onUnmount: unsubscribe });\n\n const clearListeners = () => {\n unsubscribe();\n unmount();\n };\n\n return clearListeners;\n };\n\n const emit = async () => {\n throw new Error(\"Cannot emit from Realtime database socket.\");\n };\n\n return {\n connect,\n reconnect,\n disconnect,\n listen,\n emit,\n };\n },\n );\n};\n","import { Firestore } from \"firebase-admin/firestore\";\n\nimport { firestoreAdminSockets } from \"../firestore\";\nimport { realtimeSocketsAdmin } from \"../realtime\";\nimport type { FirebaseAdminDBTypes, FirebaseAdminSocketAdapterTypes } from \"./types\";\n\n/**\n * Socket adapter for live data from the Firebase Admin SDK: Firestore `onSnapshot` or Realtime Database `on(\"value\")`.\n *\n * Create one adapter per socket. The listener topic is appended to `socket.url`, listener `options` take `constraints`\n * plus `groupByChangeType` (Firestore) or `onlyOnce` (Realtime Database), and every snapshot is delivered as the full\n * current result. The Firestore socket cannot `connect()` or `disconnect()`; stop listeners with the function `listen()`\n * returns.\n *\n * @param database - Instance from `getFirestore()` or `getDatabase()` of `firebase-admin`\n * @example\n * const socket = new Socket({ url: \"jobs/\", adapter: FirebaseSocketsAdminAdapter(getFirestore()) });\n * const onQueued = socket.createListener<Job[]>()({\n * topic: \"\",\n * options: { constraints: [$where(\"state\", \"==\", \"queued\")] },\n * });\n * const stop = onQueued.listen(({ data }) => process(data));\n */\nexport const FirebaseSocketsAdminAdapter = <T extends FirebaseAdminDBTypes>(\n database: T,\n): FirebaseAdminSocketAdapterTypes<T> => {\n if (database instanceof Firestore) {\n return firestoreAdminSockets(database) as unknown as FirebaseAdminSocketAdapterTypes<T>;\n }\n return realtimeSocketsAdmin(database) as unknown as FirebaseAdminSocketAdapterTypes<T>;\n};\n","import { Adapter } from \"@hyper-fetch/core\";\nimport type {\n FirebaseAdminDBTypes,\n FirebaseAdminAdapterTypes,\n FirestoreRequestType,\n RealtimeDBRequestType,\n} from \"adapter\";\nimport { FirestoreMethods, RealtimeDBMethods } from \"adapter\";\nimport { Firestore } from \"firebase-admin/firestore\";\n\nimport {\n createFirestoreConstraints,\n createRealtimeConstraints,\n getConstraints,\n resolveConstraints,\n} from \"../constraints\";\nimport { getFirestoreAdminMethods } from \"../firestore\";\nimport { getRealtimeDbAdminMethods } from \"../realtime\";\n\n/**\n * Request adapter for the Firebase Admin SDK. Pass a Firestore or Realtime Database instance from `firebase-admin` and\n * the adapter picks the matching methods and types. Admin access bypasses security rules.\n *\n * - Firestore methods: `getDoc` (default), `getDocs`, `addDoc`, `setDoc`, `updateDoc`, `deleteDoc`\n * - Realtime Database methods: `get` (default), `set`, `push`, `update`, `remove`\n *\n * The full path is `client.url + endpoint`. Constraints go in `queryParams` as an array. Firebase errors resolve the\n * request with `status: \"error\"`; `send()` never rejects.\n *\n * @param database - Instance from `getFirestore()` or `getDatabase()` of `firebase-admin`\n * @example\n * const client = new Client({ url: \"orders/\" }).setAdapter(FirebaseAdminAdapter(getFirestore()));\n * const getOpenOrders = client.createRequest<{ response: Order[]; queryParams?: FirestoreQueryParams }>()({\n * endpoint: \"\",\n * method: \"getDocs\",\n * });\n * const { data } = await getOpenOrders.send({ queryParams: [$where(\"status\", \"==\", \"open\")] });\n */\nexport const FirebaseAdminAdapter = <T extends FirebaseAdminDBTypes>(database: T): FirebaseAdminAdapterTypes<T> => {\n const adapter = new Adapter({\n name: \"firebase-admin\",\n // Requests without a method read: `getDoc` in Firestore, `get` in Realtime Database\n defaultMethod: database instanceof Firestore ? FirestoreMethods.getDoc : RealtimeDBMethods.get,\n defaultExtra: {},\n systemErrorStatus: \"error\",\n systemErrorExtra: {},\n })\n // A `queryParams` callback gets a typed constraints chain; requests store the constraints it collected\n .setQueryParamsResolver(\n resolveConstraints(!(database instanceof Firestore) ? createRealtimeConstraints : createFirestoreConstraints),\n )\n .setFetcher(\n async ({ request, onSuccess, onError, onResponseStart, onResponseEnd, onRequestStart, onRequestEnd }) => {\n const fullUrl = `${request.client.url}${request.endpoint}`;\n if (database instanceof Firestore) {\n const { method = FirestoreMethods.getDocs, queryParams, payload, options } = request as FirestoreRequestType;\n const availableMethods = getFirestoreAdminMethods({\n database,\n url: fullUrl,\n onSuccess,\n onError,\n onRequestStart,\n onResponseEnd,\n onResponseStart,\n onRequestEnd,\n });\n if (!Object.values(FirestoreMethods).includes(method)) {\n throw new Error(`Cannot find method ${method} in Firestore available methods.`);\n }\n availableMethods(method, {\n constraints: getConstraints(queryParams),\n payload,\n options,\n });\n } else {\n const { method = RealtimeDBMethods.get, queryParams, payload, options } = request as RealtimeDBRequestType;\n const availableMethods = getRealtimeDbAdminMethods({\n database,\n url: fullUrl,\n onSuccess,\n onError,\n onRequestStart,\n onResponseEnd,\n onResponseStart,\n onRequestEnd,\n });\n if (!Object.values(RealtimeDBMethods).includes(method)) {\n throw new Error(`Cannot find method ${method} in Realtime database available methods.`);\n }\n availableMethods(method, {\n constraints: getConstraints(queryParams),\n options,\n payload,\n });\n }\n },\n );\n\n return adapter as unknown as FirebaseAdminAdapterTypes<T>;\n};\n"],"mappings":";;;;AAuFA,IAAY,mBAAL,yBAAA,kBAAA;AACL,kBAAA,YAAA;AACA,kBA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AmB;EACnB,kBAAkB,EAAE;EACrB,CAAC,CAEC,uBACC,mBAAmB,EAAE,oBAAoB,aAAa,4BAA4B,2BAA2B,CAC9G,CACA,WACC,OAAO,EAAE,SAAS,WAAW,SAAS,iBAAiB,eAAe,gBAAgB,mBAAmB;EACvG,MAAM,UAAU,GAAG,QAAQ,OAAO,MAAM,QAAQ;AAChD,MAAI,oBAAoB,WAAW;GACjC,MAAM,EAAE,SAAS,iBAAiB,SAAS,aAAa,SAAS,YAAY;GAC7E,MAAM,mBAAmB,yBAAyB;IAChD;IACA,KAAK;IACL;IACA;IACA;IACA;IACA;IACA;IACD,CAAC;AACF,OAAI,CAAC,OAAO,OAAO,iBAAiB,CAAC,SAAS,OAAO,CACnD,OAAM,IAAI,MAAM,sBAAsB,OAAO,kCAAkC;AAEjF,oBAAiB,QAAQ;IACvB,aAAa,eAAe,YAAY;IACxC;IACA;IACD,CAAC;SACG;GACL,MAAM,EAAE,SAAS,kBAAkB,KAAK,aAAa,SAAS,YAAY;GAC1E,MAAM,mBAAmB,0BAA0B;IACjD;IACA,KAAK;IACL;IACA;IACA;IACA;IACA;IACA;IACD,CAAC;AACF,OAAI,CAAC,OAAO,OAAO,kBAAkB,CAAC,SAAS,OAAO,CACpD,OAAM,IAAI,MAAM,sBAAsB,OAAO,0CAA0C;AAEzF,oBAAiB,QAAQ;IACvB,aAAa,eAAe,YAAY;IACxC;IACA;IACD,CAAC;;GAGP"}
|
|
@@ -2,6 +2,11 @@ import { getAdapterBindings } from '@hyper-fetch/core';
|
|
|
2
2
|
import { RealtimeDBMethodsUnion } from '../adapter/types';
|
|
3
3
|
import { PermittedConstraints, RealtimeConstraintsUnion, RealtimePermittedMethods, SharedQueryConstraints } from '../constraints';
|
|
4
4
|
import { Database } from 'firebase-admin/database';
|
|
5
|
+
type DataType = {
|
|
6
|
+
constraints: PermittedConstraints<RealtimePermittedMethods, RealtimeConstraintsUnion | SharedQueryConstraints>[];
|
|
7
|
+
payload: any;
|
|
8
|
+
options: Record<string, any>;
|
|
9
|
+
};
|
|
5
10
|
export declare const getRealtimeDbAdminMethods: ({ database, url, onSuccess, onError, onResponseStart, onRequestStart, onRequestEnd, onResponseEnd, }: {
|
|
6
11
|
database: Database;
|
|
7
12
|
url: string;
|
|
@@ -11,9 +16,6 @@ export declare const getRealtimeDbAdminMethods: ({ database, url, onSuccess, onE
|
|
|
11
16
|
onRequestStart: Awaited<ReturnType<typeof getAdapterBindings>>["onRequestStart"];
|
|
12
17
|
onRequestEnd: Awaited<ReturnType<typeof getAdapterBindings>>["onRequestEnd"];
|
|
13
18
|
onResponseEnd: Awaited<ReturnType<typeof getAdapterBindings>>["onResponseEnd"];
|
|
14
|
-
}) => ((methodName: RealtimeDBMethodsUnion, data:
|
|
15
|
-
|
|
16
|
-
payload: any;
|
|
17
|
-
options: Record<string, any>;
|
|
18
|
-
}) => Promise<void>);
|
|
19
|
+
}) => ((methodName: RealtimeDBMethodsUnion, data: DataType) => Promise<void>);
|
|
20
|
+
export {};
|
|
19
21
|
//# sourceMappingURL=realtime.methods.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"realtime.methods.d.ts","sourceRoot":"","sources":["../../src/realtime/realtime.methods.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,KAAK,EACV,oBAAoB,EACpB,wBAAwB,EACxB,wBAAwB,EACxB,sBAAsB,EACvB,MAAM,aAAa,CAAC;AAErB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAIxD,eAAO,MAAM,yBAAyB,GAAI,sGASvC;IACD,QAAQ,EAAE,QAAQ,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC,CAAC,WAAW,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AAkB,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;IACvE,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IACnE,eAAe,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC;IACnF,cAAc,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC;IACjF,YAAY,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC;IAC7E,aAAa,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC;CAChF,KAAG,CAAC,CAAC,UAAU,EAAE,sBAAsB,EAAE,IAAI,EAAE,QAAQ,KAAK,OAAO,CAAC,IAAI,CAAC,CA6CzE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"realtime.sockets.d.ts","sourceRoot":"","sources":["../../src/realtime/realtime.sockets.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAmC,8BAA8B,EAAE,MAAM,SAAS,CAAC;AAC/F,OAAO,KAAK,EAAE,QAAQ,EAAgB,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"realtime.sockets.d.ts","sourceRoot":"","sources":["../../src/realtime/realtime.sockets.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAmC,8BAA8B,EAAE,MAAM,SAAS,CAAC;AAC/F,OAAO,KAAK,EAAE,QAAQ,EAAgB,MAAM,yBAAyB,CAAC;AAOtE,eAAO,MAAM,oBAAoB,GAAI,UAAU,QAAQ,mCA4EtD,CAAC"}
|
package/dist/utils/misc.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"misc.d.ts","sourceRoot":"","sources":["../../src/utils/misc.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,GAAI,KAAK,GAAG,
|
|
1
|
+
{"version":3,"file":"misc.d.ts","sourceRoot":"","sources":["../../src/utils/misc.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,GAAI,KAAK,GAAG,KAAG,SAAS,GAAG,eAGhD,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,SAAS,MAAM,KAAG,MAI9C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyper-fetch/firebase-admin",
|
|
3
|
-
"version": "10.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "10.1.1",
|
|
4
|
+
"description": "Firebase Admin adapter for HyperFetch: typed Firestore and Realtime Database requests from Node.js servers",
|
|
5
5
|
"author": "Maciej Pyrc <maciekpyrc@gmail.com>, Kacper Skawina <kacper.skawina@gmail.com>",
|
|
6
|
-
"homepage": "https://hyperfetch.bettertyped.com/",
|
|
6
|
+
"homepage": "https://hyperfetch.bettertyped.com/docs/integrations/adapter-firebase-admin/overview/",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"main": "dist/index.mjs",
|
|
9
9
|
"module": "dist/index.mjs",
|
|
@@ -59,10 +59,11 @@
|
|
|
59
59
|
},
|
|
60
60
|
"keywords": [
|
|
61
61
|
"firebase",
|
|
62
|
+
"firebase-admin",
|
|
62
63
|
"firestore",
|
|
63
|
-
"realtime",
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
64
|
+
"realtime-database",
|
|
65
|
+
"nodejs",
|
|
66
|
+
"typescript",
|
|
67
|
+
"hyperfetch"
|
|
67
68
|
]
|
|
68
69
|
}
|
|
@@ -4,6 +4,23 @@ import { firestoreAdminSockets } from "../firestore";
|
|
|
4
4
|
import { realtimeSocketsAdmin } from "../realtime";
|
|
5
5
|
import type { FirebaseAdminDBTypes, FirebaseAdminSocketAdapterTypes } from "./types";
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Socket adapter for live data from the Firebase Admin SDK: Firestore `onSnapshot` or Realtime Database `on("value")`.
|
|
9
|
+
*
|
|
10
|
+
* Create one adapter per socket. The listener topic is appended to `socket.url`, listener `options` take `constraints`
|
|
11
|
+
* plus `groupByChangeType` (Firestore) or `onlyOnce` (Realtime Database), and every snapshot is delivered as the full
|
|
12
|
+
* current result. The Firestore socket cannot `connect()` or `disconnect()`; stop listeners with the function `listen()`
|
|
13
|
+
* returns.
|
|
14
|
+
*
|
|
15
|
+
* @param database - Instance from `getFirestore()` or `getDatabase()` of `firebase-admin`
|
|
16
|
+
* @example
|
|
17
|
+
* const socket = new Socket({ url: "jobs/", adapter: FirebaseSocketsAdminAdapter(getFirestore()) });
|
|
18
|
+
* const onQueued = socket.createListener<Job[]>()({
|
|
19
|
+
* topic: "",
|
|
20
|
+
* options: { constraints: [$where("state", "==", "queued")] },
|
|
21
|
+
* });
|
|
22
|
+
* const stop = onQueued.listen(({ data }) => process(data));
|
|
23
|
+
*/
|
|
7
24
|
export const FirebaseSocketsAdminAdapter = <T extends FirebaseAdminDBTypes>(
|
|
8
25
|
database: T,
|
|
9
26
|
): FirebaseAdminSocketAdapterTypes<T> => {
|
package/src/adapter/adapter.ts
CHANGED
|
@@ -8,62 +8,93 @@ import type {
|
|
|
8
8
|
import { FirestoreMethods, RealtimeDBMethods } from "adapter";
|
|
9
9
|
import { Firestore } from "firebase-admin/firestore";
|
|
10
10
|
|
|
11
|
+
import {
|
|
12
|
+
createFirestoreConstraints,
|
|
13
|
+
createRealtimeConstraints,
|
|
14
|
+
getConstraints,
|
|
15
|
+
resolveConstraints,
|
|
16
|
+
} from "../constraints";
|
|
11
17
|
import { getFirestoreAdminMethods } from "../firestore";
|
|
12
18
|
import { getRealtimeDbAdminMethods } from "../realtime";
|
|
13
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Request adapter for the Firebase Admin SDK. Pass a Firestore or Realtime Database instance from `firebase-admin` and
|
|
22
|
+
* the adapter picks the matching methods and types. Admin access bypasses security rules.
|
|
23
|
+
*
|
|
24
|
+
* - Firestore methods: `getDoc` (default), `getDocs`, `addDoc`, `setDoc`, `updateDoc`, `deleteDoc`
|
|
25
|
+
* - Realtime Database methods: `get` (default), `set`, `push`, `update`, `remove`
|
|
26
|
+
*
|
|
27
|
+
* The full path is `client.url + endpoint`. Constraints go in `queryParams` as an array. Firebase errors resolve the
|
|
28
|
+
* request with `status: "error"`; `send()` never rejects.
|
|
29
|
+
*
|
|
30
|
+
* @param database - Instance from `getFirestore()` or `getDatabase()` of `firebase-admin`
|
|
31
|
+
* @example
|
|
32
|
+
* const client = new Client({ url: "orders/" }).setAdapter(FirebaseAdminAdapter(getFirestore()));
|
|
33
|
+
* const getOpenOrders = client.createRequest<{ response: Order[]; queryParams?: FirestoreQueryParams }>()({
|
|
34
|
+
* endpoint: "",
|
|
35
|
+
* method: "getDocs",
|
|
36
|
+
* });
|
|
37
|
+
* const { data } = await getOpenOrders.send({ queryParams: [$where("status", "==", "open")] });
|
|
38
|
+
*/
|
|
14
39
|
export const FirebaseAdminAdapter = <T extends FirebaseAdminDBTypes>(database: T): FirebaseAdminAdapterTypes<T> => {
|
|
15
40
|
const adapter = new Adapter({
|
|
16
41
|
name: "firebase-admin",
|
|
17
|
-
|
|
42
|
+
// Requests without a method read: `getDoc` in Firestore, `get` in Realtime Database
|
|
43
|
+
defaultMethod: database instanceof Firestore ? FirestoreMethods.getDoc : RealtimeDBMethods.get,
|
|
18
44
|
defaultExtra: {},
|
|
19
45
|
systemErrorStatus: "error",
|
|
20
46
|
systemErrorExtra: {},
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
47
|
+
})
|
|
48
|
+
// A `queryParams` callback gets a typed constraints chain; requests store the constraints it collected
|
|
49
|
+
.setQueryParamsResolver(
|
|
50
|
+
resolveConstraints(!(database instanceof Firestore) ? createRealtimeConstraints : createFirestoreConstraints),
|
|
51
|
+
)
|
|
52
|
+
.setFetcher(
|
|
53
|
+
async ({ request, onSuccess, onError, onResponseStart, onResponseEnd, onRequestStart, onRequestEnd }) => {
|
|
54
|
+
const fullUrl = `${request.client.url}${request.endpoint}`;
|
|
55
|
+
if (database instanceof Firestore) {
|
|
56
|
+
const { method = FirestoreMethods.getDocs, queryParams, payload, options } = request as FirestoreRequestType;
|
|
57
|
+
const availableMethods = getFirestoreAdminMethods({
|
|
58
|
+
database,
|
|
59
|
+
url: fullUrl,
|
|
60
|
+
onSuccess,
|
|
61
|
+
onError,
|
|
62
|
+
onRequestStart,
|
|
63
|
+
onResponseEnd,
|
|
64
|
+
onResponseStart,
|
|
65
|
+
onRequestEnd,
|
|
66
|
+
});
|
|
67
|
+
if (!Object.values(FirestoreMethods).includes(method)) {
|
|
68
|
+
throw new Error(`Cannot find method ${method} in Firestore available methods.`);
|
|
69
|
+
}
|
|
70
|
+
availableMethods(method, {
|
|
71
|
+
constraints: getConstraints(queryParams),
|
|
72
|
+
payload,
|
|
73
|
+
options,
|
|
74
|
+
});
|
|
75
|
+
} else {
|
|
76
|
+
const { method = RealtimeDBMethods.get, queryParams, payload, options } = request as RealtimeDBRequestType;
|
|
77
|
+
const availableMethods = getRealtimeDbAdminMethods({
|
|
78
|
+
database,
|
|
79
|
+
url: fullUrl,
|
|
80
|
+
onSuccess,
|
|
81
|
+
onError,
|
|
82
|
+
onRequestStart,
|
|
83
|
+
onResponseEnd,
|
|
84
|
+
onResponseStart,
|
|
85
|
+
onRequestEnd,
|
|
86
|
+
});
|
|
87
|
+
if (!Object.values(RealtimeDBMethods).includes(method)) {
|
|
88
|
+
throw new Error(`Cannot find method ${method} in Realtime database available methods.`);
|
|
89
|
+
}
|
|
90
|
+
availableMethods(method, {
|
|
91
|
+
constraints: getConstraints(queryParams),
|
|
92
|
+
options,
|
|
93
|
+
payload,
|
|
94
|
+
});
|
|
38
95
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
payload,
|
|
42
|
-
options,
|
|
43
|
-
});
|
|
44
|
-
} else {
|
|
45
|
-
const { method = RealtimeDBMethods.get, queryParams, payload, options } = request as RealtimeDBRequestType;
|
|
46
|
-
const availableMethods = getRealtimeDbAdminMethods({
|
|
47
|
-
database,
|
|
48
|
-
url: fullUrl,
|
|
49
|
-
onSuccess,
|
|
50
|
-
onError,
|
|
51
|
-
onRequestStart,
|
|
52
|
-
onResponseEnd,
|
|
53
|
-
onResponseStart,
|
|
54
|
-
onRequestEnd,
|
|
55
|
-
});
|
|
56
|
-
if (!Object.values(RealtimeDBMethods).includes(method)) {
|
|
57
|
-
throw new Error(`Cannot find method ${method} in Realtime database available methods.`);
|
|
58
|
-
}
|
|
59
|
-
availableMethods(method, {
|
|
60
|
-
constraints: queryParams?.constraints ? queryParams.constraints : [],
|
|
61
|
-
options,
|
|
62
|
-
payload,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
);
|
|
96
|
+
},
|
|
97
|
+
);
|
|
67
98
|
|
|
68
99
|
return adapter as unknown as FirebaseAdminAdapterTypes<T>;
|
|
69
100
|
};
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import type { Adapter } from "@hyper-fetch/core";
|
|
3
3
|
import type { SocketAdapter } from "@hyper-fetch/sockets";
|
|
4
4
|
import type {
|
|
5
|
+
FirestoreConstraints,
|
|
5
6
|
FirestoreConstraintsUnion,
|
|
6
7
|
FirestorePermittedMethods,
|
|
7
8
|
PermittedConstraints,
|
|
@@ -15,11 +16,7 @@ import type {
|
|
|
15
16
|
QuerySnapshot,
|
|
16
17
|
} from "firebase/firestore";
|
|
17
18
|
|
|
18
|
-
export type FirestoreSocketAdapterType = SocketAdapter<
|
|
19
|
-
never,
|
|
20
|
-
FirestoreOnSnapshotExtra,
|
|
21
|
-
{ groupByChangeType?: boolean } & FirestoreQueryParams
|
|
22
|
-
>;
|
|
19
|
+
export type FirestoreSocketAdapterType = SocketAdapter<never, FirestoreOnSnapshotExtra, FirestoreListenerOptions>;
|
|
23
20
|
|
|
24
21
|
export type FirestoreAdapterType =
|
|
25
22
|
| Adapter<
|
|
@@ -48,8 +45,44 @@ export type FirestoreAdapterType =
|
|
|
48
45
|
undefined
|
|
49
46
|
>;
|
|
50
47
|
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
/** One Firestore query constraint, built with `$where`, `$orderBy`, `$limit` or a cursor helper such as `$startAfter`. */
|
|
49
|
+
export type FirestoreConstraint = PermittedConstraints<
|
|
50
|
+
FirestorePermittedMethods,
|
|
51
|
+
FirestoreConstraintsUnion | SharedQueryConstraints
|
|
52
|
+
>;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Query params of a Firestore request: a callback that builds typed constraints, or the constraints array it
|
|
56
|
+
* resolves to. Pass the document type to check field names and values: `queryParams?: FirestoreQueryParams<Tea>`.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* getTeas.send({ queryParams: (c) => c.where("type", "==", "Green").orderBy("year", "desc").limit(20) });
|
|
60
|
+
*/
|
|
61
|
+
export type FirestoreQueryParams<Doc = any> =
|
|
62
|
+
| FirestoreConstraint[]
|
|
63
|
+
| ((constraints: FirestoreConstraints<Doc>) => FirestoreConstraints<Doc, any>)
|
|
64
|
+
| FirestoreDeprecatedQueryParams;
|
|
65
|
+
|
|
66
|
+
/** @deprecated Pass the constraints directly: `queryParams: (c) => c.where(...)` or `queryParams: [$where(...)]`. */
|
|
67
|
+
export type FirestoreDeprecatedQueryParams = {
|
|
68
|
+
/** @deprecated Pass the constraints directly: `queryParams: (c) => c.where(...)` or `queryParams: [$where(...)]`. */
|
|
69
|
+
constraints?: FirestoreConstraint[];
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/** Query params of a Firestore listener: a callback that builds typed constraints, or the constraints array. */
|
|
73
|
+
export type FirestoreListenerQueryParams<Doc = any> =
|
|
74
|
+
| FirestoreConstraint[]
|
|
75
|
+
| ((constraints: FirestoreConstraints<Doc>) => FirestoreConstraints<Doc, any>);
|
|
76
|
+
|
|
77
|
+
/** Options of a Firestore `onSnapshot` listener. Constraints go in the listener's `queryParams`. */
|
|
78
|
+
export type FirestoreListenerOptions = {
|
|
79
|
+
/** @deprecated Use the listener's query params: `setQueryParams((c) => c.where(...))`. */
|
|
80
|
+
constraints?: FirestoreConstraint[];
|
|
81
|
+
/**
|
|
82
|
+
* On collection listeners, adds `extra.groupedResult` with the `added`, `modified` and `removed` documents of each
|
|
83
|
+
* snapshot. Document listeners get `null`.
|
|
84
|
+
*/
|
|
85
|
+
groupByChangeType?: boolean;
|
|
53
86
|
};
|
|
54
87
|
|
|
55
88
|
export enum FirestoreMethods {
|