@_henriquewilson/gabirubi-domain 1.2.4 → 1.2.6

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.
@@ -1,7 +1,7 @@
1
1
  import * as _firebase_firestore from '@firebase/firestore';
2
- import { Model } from '../model.mjs';
3
2
  import { Firestore, QueryConstraint } from 'firebase/firestore';
4
3
  import { FieldPath, WhereFilterOp } from '@google-cloud/firestore';
4
+ import { Model } from '../model.mjs';
5
5
  import 'zod';
6
6
 
7
7
  interface Operator {
@@ -1,7 +1,7 @@
1
1
  import * as _firebase_firestore from '@firebase/firestore';
2
- import { Model } from '../model.js';
3
2
  import { Firestore, QueryConstraint } from 'firebase/firestore';
4
3
  import { FieldPath, WhereFilterOp } from '@google-cloud/firestore';
4
+ import { Model } from '../model.js';
5
5
  import 'zod';
6
6
 
7
7
  interface Operator {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/firebase/firebase.ts"],"names":["limitConstraint","orderByConstraint","doc"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAgBO;AAYA,IAAM,oBAAN,MAAM,kBAAiB;AAAA,EAUlB,YAAY,WAAsB;AAN1C,SAAQ,QAAuB;AAC/B,SAAQ,MAA8B;AACtC,SAAQ,SAAsC;AAC9C,SAAQ,SAA4B,CAAC;AACrC,SAAQ,WAA4D,CAAC;AAGjE,SAAK,aAAa;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA,EAKA,OAAc,YAAY,WAAwC;AAC9D,QAAI,CAAC,kBAAiB,WAAW;AAC7B,wBAAiB,YAAY,IAAI,kBAAiB,SAAS;AAAA,IAC/D;AACA,WAAO,kBAAiB;AAAA,EAC5B;AAAA,EAEO,KAAK,MAAoB;AAC5B,SAAK,QAAQ;AACb,WAAO;AAAA,EACX;AAAA,EAEO,GAAG,IAA2B;AACjC,SAAK,MAAM;AACX,WAAO;AAAA,EACX;AAAA,EAEO,SAAS,OA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AA,IAChD;AAAA,EACJ;AAAA;AAAA,EAIA,OAAe,YAAe,UAA+B;AACzD,WAAO;AAAA,MACH,GAAG,SAAS,KAAK;AAAA,MACjB,IAAI,SAAS,KAAK,GAAG,MAAM,SAAS;AAAA,IACxC;AAAA,EACJ;AAAA,EAEA,OAAe,iBAAoB,MAAS;AACxC,WAAO,OAAO;AAAA,MACZ,OAAO,QAAQ,IAAa,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM;AAAA,QAChD;AAAA,QACA,UAAU,SAAY,OAAO;AAAA,MACjC,CAAC;AAAA,IACH;AAAA,EACJ;AAAA,EAEQ,QAAQ;AACZ,SAAK,QAAQ;AACb,SAAK,MAAM;AACX,SAAK,SAAS,CAAC;AACf,SAAK,WAAW,CAAC;AACjB,SAAK,SAAS;AAAA,EAClB;AACJ;AAnLa,kBACM,YAAqC;AADjD,IAAM,mBAAN","sourcesContent":["import {Model} from \"../model\";\nimport {\n addDoc,\n collection,\n deleteDoc,\n doc,\n getDoc,\n getDocs,\n onSnapshot,\n limit as limitConstraint,\n query,\n orderBy as orderByConstraint,\n setDoc,\n updateDoc,\n Firestore,\n QueryConstraint,\n DocumentSnapshot,\n} from 'firebase/firestore'\nimport {QueryLimitConstraint} from \"@firebase/firestore\";\nimport {FieldPath, WhereFilterOp} from \"@google-cloud/firestore\";\n\n\nexport interface Operator {\n fieldPath: string | FieldPath,\n opStr: WhereFilterOp,\n value: string | object | number | boolean\n}\n\n\nexport class FirestoreService {\n private static _instance: FirestoreService | null = null\n private readonly _firestore: Firestore\n\n private _path: string | null = null\n private _id: string | number | null = null\n private _limit: QueryLimitConstraint | null = null\n private _where: QueryConstraint[] = []\n private _orderBy: { field: string; direction?: 'asc' | 'desc' }[] = []\n\n private constructor(firestore: Firestore) {\n this._firestore = firestore\n }\n\n /**\n * Get singleton instance using provided Firestore\n */\n public static getInstance(firestore: Firestore): FirestoreService {\n if (!FirestoreService._instance) {\n FirestoreService._instance = new FirestoreService(firestore)\n }\n return FirestoreService._instance\n }\n\n public path(path: string): this {\n this._path = path\n return this\n }\n\n public id(id: string | number): this {\n this._id = id\n return this\n }\n\n public where(...where: QueryConstraint[]): this {\n this._where = where\n return this\n }\n\n public limit(limit: number): this {\n this._limit = limitConstraint(limit)\n return this\n }\n\n public orderBy(field: string, direction: 'asc' | 'desc' = 'desc'): this {\n this._orderBy.push({ field, direction })\n return this\n }\n\n public async get<T>(): Promise<T | null> {\n if (!this._path || this._id == null) throw new Error('Path and ID must be set')\n const snap = await getDoc(doc(this._firestore, this._path, `${this._id}`))\n this.reset()\n return snap.exists() ? FirestoreService.dataToModel<T>(snap) : null\n }\n\n public async getAll<T>(): Promise<T[]> {\n if (!this._path) throw new Error('Path must be set')\n console.log(this._path)\n const snap = await getDocs(query(\n collection(this._firestore, this._path),\n ...this._where,\n ...this._orderBy.map(o => orderByConstraint(o.field, o.direction)),\n ...(this._limit ? [this._limit] : [])\n ))\n this.reset()\n return snap.docs.map((doc) => FirestoreService.dataToModel<T>(doc))\n }\n\n public onSnapshotById<T>(callback: (doc: T | null) => void, onNotFound?: () => void) {\n if (!this._path || this._id == null) throw new Error('Path and ID must be set')\n const unsubscribe = onSnapshot(\n doc(this._firestore, this._path, `${this._id}`),\n { includeMetadataChanges: true },\n (snap) => {\n if (snap.exists()) {\n callback(FirestoreService.dataToModel<T>(snap))\n } else {\n console.warn(`doc not found: ${this._id} path: ${this._path}`)\n callback(null)\n if (onNotFound) onNotFound()\n }\n }\n )\n this.reset()\n return unsubscribe\n }\n\n public onSnapshot<T>(callback: (docs: T[]) => void, onNotFound?: () => void) {\n if (!this._path) throw new Error('Path must be set')\n const unsubscribe = onSnapshot(\n query(\n collection(this._firestore, this._path),\n ...this._where,\n ...this._orderBy.map(o => orderByConstraint(o.field, o.direction)),\n ...(this._limit ? [this._limit] : [])\n ),\n (snapshot) => {\n if (!snapshot.empty) {\n callback(snapshot.docs.map((value) => FirestoreService.dataToModel<T>(value)))\n } else {\n console.warn(`no docs found in path: ${this._path}`)\n callback([])\n if (onNotFound) onNotFound()\n }\n }\n )\n this.reset()\n return unsubscribe\n }\n\n public async add<T>(data: T): Promise<T> {\n if (!this._path) throw new Error('Path must be set')\n const ref = await addDoc(collection(this._firestore, this._path), FirestoreService.replaceUndefined(data))\n this.reset()\n return { ...data, id: ref.id } as T\n }\n\n public async set<T extends Model>(data: T, merge = true): Promise<T> {\n if (!this._path) throw new Error('Path must be set')\n const docId = this._id ?? data.id ?? null\n\n if (docId) {\n await setDoc(doc(this._firestore, this._path, `${docId}`), FirestoreService.replaceUndefined(data), { merge })\n this.reset()\n return { ...data, id: docId } as T\n } else {\n const ref = await addDoc(collection(this._firestore, this._path), FirestoreService.replaceUndefined(data))\n this.reset()\n return { ...data, id: ref.id } as T\n }\n }\n\n public async update<T>(data: T): Promise<void> {\n if (!this._path || this._id == null) throw new Error('Path and ID must be set')\n await updateDoc(doc(this._firestore, this._path, `${this._id}`), FirestoreService.replaceUndefined(data))\n this.reset()\n }\n\n public async delete(): Promise<void> {\n if (!this._path || this._id == null) throw new Error('Path and ID must be set')\n await deleteDoc(doc(this._firestore, this._path, `${this._id}`))\n this.reset()\n }\n\n public async save<T extends Model>(data: T, merge = true): Promise<T> {\n if (data.id) {\n await this.path(this._path!).id(data.id).set(data, merge)\n return data\n } else {\n return await this.path(this._path!).add(data)\n }\n }\n\n // ---------- UTILS ----------\n\n private static dataToModel<T>(snapshot: DocumentSnapshot): T {\n return {\n ...snapshot.data(),\n id: snapshot.data()?.id || snapshot.id,\n } as T\n }\n\n private static replaceUndefined<T>(data: T) {\n return Object.fromEntries(\n Object.entries(data as Model).map(([key, value]) => [\n key,\n value === undefined ? null : value,\n ])\n )\n }\n\n private reset() {\n this._path = null\n this._id = null\n this._where = []\n this._orderBy = []\n this._limit = null\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/firebase/firebase.ts"],"names":["limitConstraint","orderByConstraint","doc"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAA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["import {\n addDoc,\n collection,\n deleteDoc,\n doc,\n getDoc,\n getDocs,\n onSnapshot,\n limit as limitConstraint,\n query,\n orderBy as orderByConstraint,\n setDoc,\n updateDoc,\n Firestore,\n QueryConstraint,\n DocumentSnapshot,\n} from 'firebase/firestore'\nimport { QueryLimitConstraint } from '@firebase/firestore'\nimport { FieldPath, WhereFilterOp } from '@google-cloud/firestore'\nimport {Model} from \"../model\";\n\nexport interface Operator {\n fieldPath: string | FieldPath\n opStr: WhereFilterOp\n value: string | object | number | boolean\n}\n\nexport class FirestoreService {\n private static _instance: FirestoreService | null = null\n private readonly _firestore: Firestore\n\n private _path: string | null = null\n private _id: string | number | null = null\n private _limit: QueryLimitConstraint | null = null\n private _where: QueryConstraint[] = []\n private _orderBy: { field: string; direction?: 'asc' | 'desc' }[] = []\n\n private constructor(firestore: Firestore) {\n this._firestore = firestore\n }\n\n /**\n * Get singleton instance using provided Firestore\n */\n public static getInstance(firestore: Firestore): FirestoreService {\n if (!FirestoreService._instance) {\n FirestoreService._instance = new FirestoreService(firestore)\n }\n return FirestoreService._instance\n }\n\n public path(path: string): this {\n this._path = path\n return this\n }\n\n public id(id: string | number): this {\n this._id = id\n return this\n }\n\n public where(...where: QueryConstraint[]): this {\n this._where = where\n return this\n }\n\n public limit(limit: number): this {\n this._limit = limitConstraint(limit)\n return this\n }\n\n public orderBy(field: string, direction: 'asc' | 'desc' = 'desc'): this {\n this._orderBy.push({ field, direction })\n return this\n }\n\n public async get<T>(): Promise<T | null> {\n if (!this._path || this._id == null)\n throw new Error('Path and ID must be set')\n const snap = await getDoc(doc(this._firestore, this._path, `${this._id}`))\n this.reset()\n return snap.exists() ? FirestoreService.dataToModel<T>(snap) : null\n }\n\n public async getAll<T>(): Promise<T[]> {\n if (!this._path) throw new Error('Path must be set')\n console.log(this._path)\n const snap = await getDocs(\n query(\n collection(this._firestore, this._path),\n ...this._where,\n ...this._orderBy.map((o) => orderByConstraint(o.field, o.direction)),\n ...(this._limit ? [this._limit] : []),\n ),\n )\n this.reset()\n return snap.docs.map((doc) => FirestoreService.dataToModel<T>(doc))\n }\n\n public onSnapshotById<T>(\n callback: (doc: T | null) => void,\n onNotFound?: () => void,\n ) {\n if (!this._path || this._id == null)\n throw new Error('Path and ID must be set')\n const unsubscribe = onSnapshot(\n doc(this._firestore, this._path, `${this._id}`),\n { includeMetadataChanges: true },\n (snap) => {\n if (snap.exists()) {\n callback(FirestoreService.dataToModel<T>(snap))\n } else {\n console.warn(`doc not found: ${this._id} path: ${this._path}`)\n callback(null)\n if (onNotFound) onNotFound()\n }\n },\n )\n this.reset()\n return unsubscribe\n }\n\n public onSnapshot<T>(callback: (docs: T[]) => void, onNotFound?: () => void) {\n if (!this._path) throw new Error('Path must be set')\n const unsubscribe = onSnapshot(\n query(\n collection(this._firestore, this._path),\n ...this._where,\n ...this._orderBy.map((o) => orderByConstraint(o.field, o.direction)),\n ...(this._limit ? [this._limit] : []),\n ),\n (snapshot) => {\n if (!snapshot.empty) {\n callback(\n snapshot.docs.map((value) =>\n FirestoreService.dataToModel<T>(value),\n ),\n )\n } else {\n console.warn(`no docs found in path: ${this._path}`)\n callback([])\n if (onNotFound) onNotFound()\n }\n },\n )\n this.reset()\n return unsubscribe\n }\n\n public async add<T>(data: T): Promise<T> {\n if (!this._path) throw new Error('Path must be set')\n const ref = await addDoc(\n collection(this._firestore, this._path),\n FirestoreService.replaceUndefined(data),\n )\n this.reset()\n return { ...data, id: ref.id } as T\n }\n\n public async set<T extends Model>(data: T, merge = true): Promise<T> {\n if (!this._path) throw new Error('Path must be set')\n const docId = this._id ?? data.id ?? null\n\n if (docId) {\n await setDoc(\n doc(this._firestore, this._path, `${docId}`),\n FirestoreService.replaceUndefined(data),\n { merge },\n )\n this.reset()\n return { ...data, id: docId } as T\n } else {\n const ref = await addDoc(\n collection(this._firestore, this._path),\n FirestoreService.replaceUndefined(data),\n )\n this.reset()\n return { ...data, id: ref.id } as T\n }\n }\n\n public async update<T>(data: T): Promise<void> {\n if (!this._path || this._id == null)\n throw new Error('Path and ID must be set')\n await updateDoc(\n doc(this._firestore, this._path, `${this._id}`),\n FirestoreService.replaceUndefined(data),\n )\n this.reset()\n }\n\n public async delete(): Promise<void> {\n if (!this._path || this._id == null)\n throw new Error('Path and ID must be set')\n await deleteDoc(doc(this._firestore, this._path, `${this._id}`))\n this.reset()\n }\n\n public async save<T extends Model>(data: T, merge = true): Promise<T> {\n if (data.id) {\n await this.path(this._path!).id(data.id).set(data, merge)\n return data\n } else {\n return await this.path(this._path!).add(data)\n }\n }\n\n // ---------- UTILS ----------\n\n private static dataToModel<T>(snapshot: DocumentSnapshot): T {\n return {\n ...snapshot.data(),\n id: snapshot.data()?.id || snapshot.id,\n } as T\n }\n\n private static replaceUndefined<T>(data: T) {\n return Object.fromEntries(\n Object.entries(data as Model).map(([key, value]) => [\n key,\n value === undefined ? null : value,\n ]),\n )\n }\n\n private reset() {\n this._path = null\n this._id = null\n this._where = []\n this._orderBy = []\n this._limit = null\n }\n}\n"]}
@@ -62,12 +62,14 @@ var _FirestoreService = class _FirestoreService {
62
62
  if (!this._path)
63
63
  throw new Error("Path must be set");
64
64
  console.log(this._path);
65
- const snap = await getDocs(query(
66
- collection(this._firestore, this._path),
67
- ...this._where,
68
- ...this._orderBy.map((o) => orderByConstraint(o.field, o.direction)),
69
- ...this._limit ? [this._limit] : []
70
- ));
65
+ const snap = await getDocs(
66
+ query(
67
+ collection(this._firestore, this._path),
68
+ ...this._where,
69
+ ...this._orderBy.map((o) => orderByConstraint(o.field, o.direction)),
70
+ ...this._limit ? [this._limit] : []
71
+ )
72
+ );
71
73
  this.reset();
72
74
  return snap.docs.map((doc2) => _FirestoreService.dataToModel(doc2));
73
75
  }
@@ -103,7 +105,11 @@ var _FirestoreService = class _FirestoreService {
103
105
  ),
104
106
  (snapshot) => {
105
107
  if (!snapshot.empty) {
106
- callback(snapshot.docs.map((value) => _FirestoreService.dataToModel(value)));
108
+ callback(
109
+ snapshot.docs.map(
110
+ (value) => _FirestoreService.dataToModel(value)
111
+ )
112
+ );
107
113
  } else {
108
114
  console.warn(`no docs found in path: ${this._path}`);
109
115
  callback([]);
@@ -118,7 +124,10 @@ var _FirestoreService = class _FirestoreService {
118
124
  async add(data) {
119
125
  if (!this._path)
120
126
  throw new Error("Path must be set");
121
- const ref = await addDoc(collection(this._firestore, this._path), _FirestoreService.replaceUndefined(data));
127
+ const ref = await addDoc(
128
+ collection(this._firestore, this._path),
129
+ _FirestoreService.replaceUndefined(data)
130
+ );
122
131
  this.reset();
123
132
  return { ...data, id: ref.id };
124
133
  }
@@ -127,11 +136,18 @@ var _FirestoreService = class _FirestoreService {
127
136
  throw new Error("Path must be set");
128
137
  const docId = this._id ?? data.id ?? null;
129
138
  if (docId) {
130
- await setDoc(doc(this._firestore, this._path, `${docId}`), _FirestoreService.replaceUndefined(data), { merge });
139
+ await setDoc(
140
+ doc(this._firestore, this._path, `${docId}`),
141
+ _FirestoreService.replaceUndefined(data),
142
+ { merge }
143
+ );
131
144
  this.reset();
132
145
  return { ...data, id: docId };
133
146
  } else {
134
- const ref = await addDoc(collection(this._firestore, this._path), _FirestoreService.replaceUndefined(data));
147
+ const ref = await addDoc(
148
+ collection(this._firestore, this._path),
149
+ _FirestoreService.replaceUndefined(data)
150
+ );
135
151
  this.reset();
136
152
  return { ...data, id: ref.id };
137
153
  }
@@ -139,7 +155,10 @@ var _FirestoreService = class _FirestoreService {
139
155
  async update(data) {
140
156
  if (!this._path || this._id == null)
141
157
  throw new Error("Path and ID must be set");
142
- await updateDoc(doc(this._firestore, this._path, `${this._id}`), _FirestoreService.replaceUndefined(data));
158
+ await updateDoc(
159
+ doc(this._firestore, this._path, `${this._id}`),
160
+ _FirestoreService.replaceUndefined(data)
161
+ );
143
162
  this.reset();
144
163
  }
145
164
  async delete() {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/firebase/firebase.ts"],"sourcesContent":["import {Model} from \"../model\";\nimport {\n addDoc,\n collection,\n deleteDoc,\n doc,\n getDoc,\n getDocs,\n onSnapshot,\n limit as limitConstraint,\n query,\n orderBy as orderByConstraint,\n setDoc,\n updateDoc,\n Firestore,\n QueryConstraint,\n DocumentSnapshot,\n} from 'firebase/firestore'\nimport {QueryLimitConstraint} from \"@firebase/firestore\";\nimport {FieldPath, WhereFilterOp} from \"@google-cloud/firestore\";\n\n\nexport interface Operator {\n fieldPath: string | FieldPath,\n opStr: WhereFilterOp,\n value: string | object | number | boolean\n}\n\n\nexport class FirestoreService {\n private static _instance: FirestoreService | null = null\n private readonly _firestore: Firestore\n\n private _path: string | null = null\n private _id: string | number | null = null\n private _limit: QueryLimitConstraint | null = null\n private _where: QueryConstraint[] = []\n private _orderBy: { field: string; direction?: 'asc' | 'desc' }[] = []\n\n private constructor(firestore: Firestore) {\n this._firestore = firestore\n }\n\n /**\n * Get singleton instance using provided Firestore\n */\n public static getInstance(firestore: Firestore): FirestoreService {\n if (!FirestoreService._instance) {\n FirestoreService._instance = new FirestoreService(firestore)\n }\n return FirestoreService._instance\n }\n\n public path(path: string): this {\n this._path = path\n return this\n }\n\n public id(id: string | number): this {\n this._id = id\n return this\n }\n\n public where(...where: QueryConstraint[]): this {\n this._where = where\n return this\n }\n\n public limit(limit: number): this {\n this._limit = limitConstraint(limit)\n return this\n }\n\n public orderBy(field: string, direction: 'asc' | 'desc' = 'desc'): this {\n this._orderBy.push({ field, direction })\n return this\n }\n\n public async get<T>(): Promise<T | null> {\n if (!this._path || this._id == null) throw new Error('Path and ID must be set')\n const snap = await getDoc(doc(this._firestore, this._path, `${this._id}`))\n this.reset()\n return snap.exists() ? FirestoreService.dataToModel<T>(snap) : null\n }\n\n public async getAll<T>(): Promise<T[]> {\n if (!this._path) throw new Error('Path must be set')\n console.log(this._path)\n const snap = await getDocs(query(\n collection(this._firestore, this._path),\n ...this._where,\n ...this._orderBy.map(o => orderByConstraint(o.field, o.direction)),\n ...(this._limit ? [this._limit] : [])\n ))\n this.reset()\n return snap.docs.map((doc) => FirestoreService.dataToModel<T>(doc))\n }\n\n public onSnapshotById<T>(callback: (doc: T | null) => void, onNotFound?: () => void) {\n if (!this._path || this._id == null) throw new Error('Path and ID must be set')\n const unsubscribe = onSnapshot(\n doc(this._firestore, this._path, `${this._id}`),\n { includeMetadataChanges: true },\n (snap) => {\n if (snap.exists()) {\n callback(FirestoreService.dataToModel<T>(snap))\n } else {\n console.warn(`doc not found: ${this._id} path: ${this._path}`)\n callback(null)\n if (onNotFound) onNotFound()\n }\n }\n )\n this.reset()\n return unsubscribe\n }\n\n public onSnapshot<T>(callback: (docs: T[]) => void, onNotFound?: () => void) {\n if (!this._path) throw new Error('Path must be set')\n const unsubscribe = onSnapshot(\n query(\n collection(this._firestore, this._path),\n ...this._where,\n ...this._orderBy.map(o => orderByConstraint(o.field, o.direction)),\n ...(this._limit ? [this._limit] : [])\n ),\n (snapshot) => {\n if (!snapshot.empty) {\n callback(snapshot.docs.map((value) => FirestoreService.dataToModel<T>(value)))\n } else {\n console.warn(`no docs found in path: ${this._path}`)\n callback([])\n if (onNotFound) onNotFound()\n }\n }\n )\n this.reset()\n return unsubscribe\n }\n\n public async add<T>(data: T): Promise<T> {\n if (!this._path) throw new Error('Path must be set')\n const ref = await addDoc(collection(this._firestore, this._path), FirestoreService.replaceUndefined(data))\n this.reset()\n return { ...data, id: ref.id } as T\n }\n\n public async set<T extends Model>(data: T, merge = true): Promise<T> {\n if (!this._path) throw new Error('Path must be set')\n const docId = this._id ?? data.id ?? null\n\n if (docId) {\n await setDoc(doc(this._firestore, this._path, `${docId}`), FirestoreService.replaceUndefined(data), { merge })\n this.reset()\n return { ...data, id: docId } as T\n } else {\n const ref = await addDoc(collection(this._firestore, this._path), FirestoreService.replaceUndefined(data))\n this.reset()\n return { ...data, id: ref.id } as T\n }\n }\n\n public async update<T>(data: T): Promise<void> {\n if (!this._path || this._id == null) throw new Error('Path and ID must be set')\n await updateDoc(doc(this._firestore, this._path, `${this._id}`), FirestoreService.replaceUndefined(data))\n this.reset()\n }\n\n public async delete(): Promise<void> {\n if (!this._path || this._id == null) throw new Error('Path and ID must be set')\n await deleteDoc(doc(this._firestore, this._path, `${this._id}`))\n this.reset()\n }\n\n public async save<T extends Model>(data: T, merge = true): Promise<T> {\n if (data.id) {\n await this.path(this._path!).id(data.id).set(data, merge)\n return data\n } else {\n return await this.path(this._path!).add(data)\n }\n }\n\n // ---------- UTILS ----------\n\n private static dataToModel<T>(snapshot: DocumentSnapshot): T {\n return {\n ...snapshot.data(),\n id: snapshot.data()?.id || snapshot.id,\n } as T\n }\n\n private static replaceUndefined<T>(data: T) {\n return Object.fromEntries(\n Object.entries(data as Model).map(([key, value]) => [\n key,\n value === undefined ? null : value,\n ])\n )\n }\n\n private reset() {\n this._path = null\n this._id = null\n this._where = []\n this._orderBy = []\n this._limit = null\n }\n}\n"],"mappings":";AACA;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT;AAAA,EACA,WAAW;AAAA,EACX;AAAA,EACA;AAAA,OAIG;AAYA,IAAM,oBAAN,MAAM,kBAAiB;AAAA,EAUlB,YAAY,WAAsB;AAN1C,SAAQ,QAAuB;AAC/B,SAAQ,MAA8B;AACtC,SAAQ,SAAsC;AAC9C,SAAQ,SAA4B,CAAC;AACrC,SAAQ,WAA4D,CAAC;AAGjE,SAAK,aAAa;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA,EAKA,OAAc,YAAY,WAAwC;AAC9D,QAAI,CAAC,kBAAiB,WAAW;AAC7B,wBAAiB,YAAY,IAAI,kBAAiB,SAAS;AAAA,IAC/D;AACA,WAAO,kBAAiB;AAAA,EAC5B;AAAA,EAEO,KAAK,MAAoB;AAC5B,SAAK,QAAQ;AACb,WAAO;AAAA,EACX;AAAA,EAEO,GAAG,IAA2B;AACjC,SAAK,MAAM;AACX,WAAO;AAAA,EACX;AAAA,EAEO,SAAS,OAAgC;AAC5C,SAAK,SAAS;AACd,WAAO;A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,GAAG,SAAS,KAAK;AAAA,MACjB,IAAI,SAAS,KAAK,GAAG,MAAM,SAAS;AAAA,IACxC;AAAA,EACJ;AAAA,EAEA,OAAe,iBAAoB,MAAS;AACxC,WAAO,OAAO;AAAA,MACZ,OAAO,QAAQ,IAAa,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM;AAAA,QAChD;AAAA,QACA,UAAU,SAAY,OAAO;AAAA,MACjC,CAAC;AAAA,IACH;AAAA,EACJ;AAAA,EAEQ,QAAQ;AACZ,SAAK,QAAQ;AACb,SAAK,MAAM;AACX,SAAK,SAAS,CAAC;AACf,SAAK,WAAW,CAAC;AACjB,SAAK,SAAS;AAAA,EAClB;AACJ;AAnLa,kBACM,YAAqC;AADjD,IAAM,mBAAN;","names":["doc"]}
1
+ {"version":3,"sources":["../../src/firebase/firebase.ts"],"sourcesContent":["import {\n addDoc,\n collection,\n deleteDoc,\n doc,\n getDoc,\n getDocs,\n onSnapshot,\n limit as limitConstraint,\n query,\n orderBy as orderByConstraint,\n setDoc,\n updateDoc,\n Firestore,\n QueryConstraint,\n DocumentSnapshot,\n} from 'firebase/firestore'\nimport { QueryLimitConstraint } from '@firebase/firestore'\nimport { FieldPath, WhereFilterOp } from '@google-cloud/firestore'\nimport {Model} from \"../model\";\n\nexport interface Operator {\n fieldPath: string | FieldPath\n opStr: WhereFilterOp\n value: string | object | number | boolean\n}\n\nexport class FirestoreService {\n private static _instance: FirestoreService | null = null\n private readonly _firestore: Firestore\n\n private _path: string | null = null\n private _id: string | number | null = null\n private _limit: QueryLimitConstraint | null = null\n private _where: QueryConstraint[] = []\n private _orderBy: { field: string; direction?: 'asc' | 'desc' }[] = []\n\n private constructor(firestore: Firestore) {\n this._firestore = firestore\n }\n\n /**\n * Get singleton instance using provided Firestore\n */\n public static getInstance(firestore: Firestore): FirestoreService {\n if (!FirestoreService._instance) {\n FirestoreService._instance = new FirestoreService(firestore)\n }\n return FirestoreService._instance\n }\n\n public path(path: string): this {\n this._path = path\n return this\n }\n\n public id(id: string | number): this {\n this._id = id\n return this\n }\n\n public where(...where: QueryConstraint[]): this {\n this._where = where\n return this\n }\n\n public limit(limit: number): this {\n this._limit = limitConstraint(limit)\n return this\n }\n\n public orderBy(field: string, direction: 'asc' | 'desc' = 'desc'): this {\n this._orderBy.push({ field, direction })\n return this\n }\n\n public async get<T>(): Promise<T | null> {\n if (!this._path || this._id == null)\n throw new Error('Path and ID must be set')\n const snap = await getDoc(doc(this._firestore, this._path, `${this._id}`))\n this.reset()\n return snap.exists() ? FirestoreService.dataToModel<T>(snap) : null\n }\n\n public async getAll<T>(): Promise<T[]> {\n if (!this._path) throw new Error('Path must be set')\n console.log(this._path)\n const snap = await getDocs(\n query(\n collection(this._firestore, this._path),\n ...this._where,\n ...this._orderBy.map((o) => orderByConstraint(o.field, o.direction)),\n ...(this._limit ? [this._limit] : []),\n ),\n )\n this.reset()\n return snap.docs.map((doc) => FirestoreService.dataToModel<T>(doc))\n }\n\n public onSnapshotById<T>(\n callback: (doc: T | null) => void,\n onNotFound?: () => void,\n ) {\n if (!this._path || this._id == null)\n throw new Error('Path and ID must be set')\n const unsubscribe = onSnapshot(\n doc(this._firestore, this._path, `${this._id}`),\n { includeMetadataChanges: true },\n (snap) => {\n if (snap.exists()) {\n callback(FirestoreService.dataToModel<T>(snap))\n } else {\n console.warn(`doc not found: ${this._id} path: ${this._path}`)\n callback(null)\n if (onNotFound) onNotFound()\n }\n },\n )\n this.reset()\n return unsubscribe\n }\n\n public onSnapshot<T>(callback: (docs: T[]) => void, onNotFound?: () => void) {\n if (!this._path) throw new Error('Path must be set')\n const unsubscribe = onSnapshot(\n query(\n collection(this._firestore, this._path),\n ...this._where,\n ...this._orderBy.map((o) => orderByConstraint(o.field, o.direction)),\n ...(this._limit ? [this._limit] : []),\n ),\n (snapshot) => {\n if (!snapshot.empty) {\n callback(\n snapshot.docs.map((value) =>\n FirestoreService.dataToModel<T>(value),\n ),\n )\n } else {\n console.warn(`no docs found in path: ${this._path}`)\n callback([])\n if (onNotFound) onNotFound()\n }\n },\n )\n this.reset()\n return unsubscribe\n }\n\n public async add<T>(data: T): Promise<T> {\n if (!this._path) throw new Error('Path must be set')\n const ref = await addDoc(\n collection(this._firestore, this._path),\n FirestoreService.replaceUndefined(data),\n )\n this.reset()\n return { ...data, id: ref.id } as T\n }\n\n public async set<T extends Model>(data: T, merge = true): Promise<T> {\n if (!this._path) throw new Error('Path must be set')\n const docId = this._id ?? data.id ?? null\n\n if (docId) {\n await setDoc(\n doc(this._firestore, this._path, `${docId}`),\n FirestoreService.replaceUndefined(data),\n { merge },\n )\n this.reset()\n return { ...data, id: docId } as T\n } else {\n const ref = await addDoc(\n collection(this._firestore, this._path),\n FirestoreService.replaceUndefined(data),\n )\n this.reset()\n return { ...data, id: ref.id } as T\n }\n }\n\n public async update<T>(data: T): Promise<void> {\n if (!this._path || this._id == null)\n throw new Error('Path and ID must be set')\n await updateDoc(\n doc(this._firestore, this._path, `${this._id}`),\n FirestoreService.replaceUndefined(data),\n )\n this.reset()\n }\n\n public async delete(): Promise<void> {\n if (!this._path || this._id == null)\n throw new Error('Path and ID must be set')\n await deleteDoc(doc(this._firestore, this._path, `${this._id}`))\n this.reset()\n }\n\n public async save<T extends Model>(data: T, merge = true): Promise<T> {\n if (data.id) {\n await this.path(this._path!).id(data.id).set(data, merge)\n return data\n } else {\n return await this.path(this._path!).add(data)\n }\n }\n\n // ---------- UTILS ----------\n\n private static dataToModel<T>(snapshot: DocumentSnapshot): T {\n return {\n ...snapshot.data(),\n id: snapshot.data()?.id || snapshot.id,\n } as T\n }\n\n private static replaceUndefined<T>(data: T) {\n return Object.fromEntries(\n Object.entries(data as Model).map(([key, value]) => [\n key,\n value === undefined ? null : value,\n ]),\n )\n }\n\n private reset() {\n this._path = null\n this._id = null\n this._where = []\n this._orderBy = []\n this._limit = null\n }\n}\n"],"mappings":";AAAA;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA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,IAAM,mBAAN;","names":["doc"]}
@@ -1,9 +1,9 @@
1
- import { Model } from '../model.mjs';
2
1
  import { Operator } from '../firebase/firebase.mjs';
3
2
  import { Firestore } from 'firebase/firestore';
4
- import 'zod';
3
+ import { Model } from '../model.mjs';
5
4
  import '@firebase/firestore';
6
5
  import '@google-cloud/firestore';
6
+ import 'zod';
7
7
 
8
8
  declare abstract class BaseRepository<T extends Model> {
9
9
  protected abstract path: string;
@@ -1,9 +1,9 @@
1
- import { Model } from '../model.js';
2
1
  import { Operator } from '../firebase/firebase.js';
3
2
  import { Firestore } from 'firebase/firestore';
4
- import 'zod';
3
+ import { Model } from '../model.js';
5
4
  import '@firebase/firestore';
6
5
  import '@google-cloud/firestore';
6
+ import 'zod';
7
7
 
8
8
  declare abstract class BaseRepository<T extends Model> {
9
9
  protected abstract path: string;
@@ -707,7 +707,7 @@ var BaseRepository = /*#__PURE__*/ function() {
707
707
  key: "getAll",
708
708
  value: function getAll() {
709
709
  this.resetFluentState();
710
- return FirestoreService.getInstance(this.firestore).path(this.path).orderBy("createdAt").getAll();
710
+ return FirestoreService.getInstance(this.firestore).path(this.path).getAll();
711
711
  }
712
712
  },
713
713
  {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/repository/base.repository.ts","../../src/firebase/firebase.ts"],"names":["where","limitConstraint","orderByConstraint","doc","import_firestore"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,uBAgBO;AAYA,IAAM,oBAAN,MAAM,kBAAiB;AAAA,EAUlB,YAAY,WAAsB;AAN1C,SAAQ,QAAuB;AAC/B,SAAQ,MAA8B;AACtC,SAAQ,SAAsC;AAC9C,SAAQ,SAA4B,CAAC;AACrC,SAAQ,WAA4D,CAAC;AAGjE,SAAK,aAAa;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA,EAKA,OAAc,YAAY,WAAwC;AAC9D,QAAI,CAAC,kBAAiB,WAAW;AAC7B,wBAAiB,YAAY,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KAAK,IAAI,EAAE,GAAGA,KAAI,EAAE,EAAE,OAAOA,IAAG;AAAA,EAC1F;AAAA,EAEA,IAAIA,MAAQ,UAA4B,OAAiB;AACvD,QAAI,kBAAmB,iBAAiB,YAAY,KAAK,SAAS,EAAE,KAAK,KAAK,IAAI;AAChF,QAAG;AAAU,wBAAkB,gBAAgB,GAAG,QAAQ;AAC5D,WAAO,gBAAgB,IAAIA,MAAK,KAAK;AAAA,EACvC;AAAA,EAEA,MAAM,WAAmB,OAA0B,OAAiD;AAClG,SAAK,OAAO,KAAK,EAAE,WAAW,OAAO,MAAM,CAAC;AAC5C,WAAO;AAAA,EACT;AAAA,EAEA,QAAQ,OAAqB;AAC3B,SAAK,aAAa;AAClB,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,GAAiB;AACrB,SAAK,aAAa;AAClB,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,MAAoB;AACxB,QAAI,kBAAmB,iBAAiB,YAAY,KAAK,SAAS,EAAE,KAAK,KAAK,IAAI;AAElF,QAAI,KAAK,OAAO,SAAS,GAAG;AAC1B,wBAAkB,gBAAgB;AAAA,QAChC,GAAG,KAAK,OAAO,IAAI,WAAK,yBAAM,EAAE,WAAW,EAAE,OAAO,EAAE,KAAK,CAAC;AAAA,MAC9D;AAAA,IACF;AAEA,QAAI,KAAK,YAAY;AACnB,wBAAkB,gBAAgB,QAAQ,KAAK,UAAU;AAAA,IAC3D;AAEA,QAAI,KAAK,eAAe,QAAW;AACjC,wBAAkB,gBAAgB,MAAM,KAAK,UAAU;AAAA,IACzD;AACA,UAAM,SAAS,MAAM,gBAAgB,OAAU;AAC/C,SAAK,iBAAiB;AACtB,WAAO;AAAA,EACT;AAAA,EAEQ,mBAAmB;AACzB,SAAK,SAAS,CAAC;AACf,SAAK,aAAa;AAClB,SAAK,aAAa;AAAA,EACpB;AACF","sourcesContent":["import {Model} from \"../model\";\nimport {FirestoreService, Operator} from \"../firebase/firebase\";\nimport {Firestore, where} from 'firebase/firestore'\n\nexport abstract class BaseRepository<T extends Model> {\n protected abstract path: string;\n protected abstract firestore: Firestore;\n\n private wheres: Operator[] = [];\n private orderField?: string;\n private limitCount?: number;\n\n getById(id: string | number) {\n return FirestoreService.getInstance(this.firestore).path(this.path).id(id).get<T>();\n }\n\n getAll() {\n this.resetFluentState();\n return FirestoreService.getInstance(this.firestore).path(this.path).orderBy('createdAt').getAll<T>();\n }\n\n async update(doc: T) {\n await FirestoreService.getInstance(this.firestore).path(this.path).id(doc.id).update(doc);\n }\n\n set(doc: T, customId?: string | number, merge?: boolean) {\n let firebaseService = FirestoreService.getInstance(this.firestore).path(this.path)\n if(customId) firebaseService = firebaseService.id(customId)\n return firebaseService.set(doc, merge);\n }\n\n where(fieldPath: string, opStr: Operator['opStr'], value: string | number | boolean | object): this {\n this.wheres.push({ fieldPath, opStr, value });\n return this;\n }\n\n orderBy(field: string): this {\n this.orderField = field;\n return this;\n }\n\n limit(n: number): this {\n this.limitCount = n;\n return this;\n }\n\n async get(): Promise<T[]> {\n let firebaseService = FirestoreService.getInstance(this.firestore).path(this.path)\n\n if (this.wheres.length > 0) {\n firebaseService = firebaseService.where(\n ...this.wheres.map(w => where(w.fieldPath, w.opStr, w.value))\n )\n }\n\n if (this.orderField) {\n firebaseService = firebaseService.orderBy(this.orderField)\n }\n\n if (this.limitCount !== undefined) {\n firebaseService = firebaseService.limit(this.limitCount)\n }\n const result = await firebaseService.getAll<T>();\n this.resetFluentState();\n return result;\n }\n\n private resetFluentState() {\n this.wheres = [];\n this.orderField = undefined;\n this.limitCount = undefined;\n }\n}\n","import {Model} from \"../model\";\nimport {\n addDoc,\n collection,\n deleteDoc,\n doc,\n getDoc,\n getDocs,\n onSnapshot,\n limit as limitConstraint,\n query,\n orderBy as orderByConstraint,\n setDoc,\n updateDoc,\n Firestore,\n QueryConstraint,\n DocumentSnapshot,\n} from 'firebase/firestore'\nimport {QueryLimitConstraint} from \"@firebase/firestore\";\nimport {FieldPath, WhereFilterOp} from \"@google-cloud/firestore\";\n\n\nexport interface Operator {\n fieldPath: string | FieldPath,\n opStr: WhereFilterOp,\n value: string | object | number | boolean\n}\n\n\nexport class FirestoreService {\n private static _instance: FirestoreService | null = null\n private readonly _firestore: Firestore\n\n private _path: string | null = null\n private _id: string | number | null = null\n private _limit: QueryLimitConstraint | null = null\n private _where: QueryConstraint[] = []\n private _orderBy: { field: string; direction?: 'asc' | 'desc' }[] = []\n\n private constructor(firestore: Firestore) {\n this._firestore = firestore\n }\n\n /**\n * Get singleton instance using provided Firestore\n */\n public static getInstance(firestore: Firestore): FirestoreService {\n if (!FirestoreService._instance) {\n FirestoreService._instance = new FirestoreService(firestore)\n }\n return FirestoreService._instance\n }\n\n public path(path: string): this {\n this._path = path\n return this\n }\n\n public id(id: string | number): this {\n this._id = id\n return this\n }\n\n public where(...where: QueryConstraint[]): this {\n this._where = where\n return this\n }\n\n public limit(limit: number): this {\n this._limit = limitConstraint(limit)\n return this\n }\n\n public orderBy(field: string, direction: 'asc' | 'desc' = 'desc'): this {\n this._orderBy.push({ field, direction })\n return this\n }\n\n public async get<T>(): Promise<T | null> {\n if (!this._path || this._id == null) throw new Error('Path and ID must be set')\n const snap = await getDoc(doc(this._firestore, this._path, `${this._id}`))\n this.reset()\n return snap.exists() ? FirestoreService.dataToModel<T>(snap) : null\n }\n\n public async getAll<T>(): Promise<T[]> {\n if (!this._path) throw new Error('Path must be set')\n console.log(this._path)\n const snap = await getDocs(query(\n collection(this._firestore, this._path),\n ...this._where,\n ...this._orderBy.map(o => orderByConstraint(o.field, o.direction)),\n ...(this._limit ? [this._limit] : [])\n ))\n this.reset()\n return snap.docs.map((doc) => FirestoreService.dataToModel<T>(doc))\n }\n\n public onSnapshotById<T>(callback: (doc: T | null) => void, onNotFound?: () => void) {\n if (!this._path || this._id == null) throw new Error('Path and ID must be set')\n const unsubscribe = onSnapshot(\n doc(this._firestore, this._path, `${this._id}`),\n { includeMetadataChanges: true },\n (snap) => {\n if (snap.exists()) {\n callback(FirestoreService.dataToModel<T>(snap))\n } else {\n console.warn(`doc not found: ${this._id} path: ${this._path}`)\n callback(null)\n if (onNotFound) onNotFound()\n }\n }\n )\n this.reset()\n return unsubscribe\n }\n\n public onSnapshot<T>(callback: (docs: T[]) => void, onNotFound?: () => void) {\n if (!this._path) throw new Error('Path must be set')\n const unsubscribe = onSnapshot(\n query(\n collection(this._firestore, this._path),\n ...this._where,\n ...this._orderBy.map(o => orderByConstraint(o.field, o.direction)),\n ...(this._limit ? [this._limit] : [])\n ),\n (snapshot) => {\n if (!snapshot.empty) {\n callback(snapshot.docs.map((value) => FirestoreService.dataToModel<T>(value)))\n } else {\n console.warn(`no docs found in path: ${this._path}`)\n callback([])\n if (onNotFound) onNotFound()\n }\n }\n )\n this.reset()\n return unsubscribe\n }\n\n public async add<T>(data: T): Promise<T> {\n if (!this._path) throw new Error('Path must be set')\n const ref = await addDoc(collection(this._firestore, this._path), FirestoreService.replaceUndefined(data))\n this.reset()\n return { ...data, id: ref.id } as T\n }\n\n public async set<T extends Model>(data: T, merge = true): Promise<T> {\n if (!this._path) throw new Error('Path must be set')\n const docId = this._id ?? data.id ?? null\n\n if (docId) {\n await setDoc(doc(this._firestore, this._path, `${docId}`), FirestoreService.replaceUndefined(data), { merge })\n this.reset()\n return { ...data, id: docId } as T\n } else {\n const ref = await addDoc(collection(this._firestore, this._path), FirestoreService.replaceUndefined(data))\n this.reset()\n return { ...data, id: ref.id } as T\n }\n }\n\n public async update<T>(data: T): Promise<void> {\n if (!this._path || this._id == null) throw new Error('Path and ID must be set')\n await updateDoc(doc(this._firestore, this._path, `${this._id}`), FirestoreService.replaceUndefined(data))\n this.reset()\n }\n\n public async delete(): Promise<void> {\n if (!this._path || this._id == null) throw new Error('Path and ID must be set')\n await deleteDoc(doc(this._firestore, this._path, `${this._id}`))\n this.reset()\n }\n\n public async save<T extends Model>(data: T, merge = true): Promise<T> {\n if (data.id) {\n await this.path(this._path!).id(data.id).set(data, merge)\n return data\n } else {\n return await this.path(this._path!).add(data)\n }\n }\n\n // ---------- UTILS ----------\n\n private static dataToModel<T>(snapshot: DocumentSnapshot): T {\n return {\n ...snapshot.data(),\n id: snapshot.data()?.id || snapshot.id,\n } as T\n }\n\n private static replaceUndefined<T>(data: T) {\n return Object.fromEntries(\n Object.entries(data as Model).map(([key, value]) => [\n key,\n value === undefined ? null : value,\n ])\n )\n }\n\n private reset() {\n this._path = null\n this._id = null\n this._where = []\n this._orderBy = []\n this._limit = null\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/repository/base.repository.ts","../../src/firebase/firebase.ts"],"names":["where","limitConstraint","orderByConstraint","doc","import_firestore"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,uBAgBO;AAWA,IAAM,oBAAN,MAAM,kBAAiB;AAAA,EAUlB,YAAY,WAAsB;AAN1C,SAAQ,QAAuB;AAC/B,SAAQ,MAA8B;AACtC,SAAQ,SAAsC;AAC9C,SAAQ,SAA4B,CAAC;AACrC,SAAQ,WAA4D,CAAC;AAGjE,SAAK,aAAa;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA,EAKA,OAAc,YAAY,WAAwC;AAC9D,QAAI,CAAC,kBAAiB,WAAW;AAC7B,wBAAiB,YAAY,IAAI,kBAAiB,SAAS;AAAA,IAC/D;AACA,WAAO,kBAAiB;AAAA,EAC5B;AAAA,EAEO,KAAK,MAAoB;AAC5B,SAAK,QAAQ;AACb,WAAO;AAAA,EACX;AAAA,EAEO,GAAG,IAA2B;AACjC,SAAK,MAAM;AACX,WAAO;AAAA,EACX;AAAA,EAEO,SAASA,QAAgC;AAC5C,SAAK,SAASA;AACd,WAAO;AAAA,EACX;AAAA,EAEO,MAAM,OAAqB;AAC9B,SAAK,aAAS,iBAAAC,OAAgB,KAAK;AACnC,WAAO;AAAA,EACX;AAAA,EAEO,QAAQ,OAAe,YAA4B,QAAc;AACpE,SAAK,SAAS,KAAK,EAAE,OAAO,UAAU,CAAC;AACv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O,MAAM,CAAC;AAC5C,WAAO;AAAA,EACT;AAAA,EAEA,QAAQ,OAAqB;AAC3B,SAAK,aAAa;AAClB,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,GAAiB;AACrB,SAAK,aAAa;AAClB,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,MAAoB;AACxB,QAAI,kBAAkB,iBAAiB,YAAY,KAAK,SAAS,EAC9D;AAAA,MACC,KAAK;AAAA,IACP;AAEF,QAAI,KAAK,OAAO,SAAS,GAAG;AAC1B,wBAAkB,gBAAgB;AAAA,QAChC,GAAG,KAAK,OAAO,IAAI,CAAC,UAAM,yBAAM,EAAE,WAAW,EAAE,OAAO,EAAE,KAAK,CAAC;AAAA,MAChE;AAAA,IACF;AAEA,QAAI,KAAK,YAAY;AACnB,wBAAkB,gBAAgB,QAAQ,KAAK,UAAU;AAAA,IAC3D;AAEA,QAAI,KAAK,eAAe,QAAW;AACjC,wBAAkB,gBAAgB,MAAM,KAAK,UAAU;AAAA,IACzD;AACA,UAAM,SAAS,MAAM,gBAAgB,OAAU;AAC/C,SAAK,iBAAiB;AACtB,WAAO;AAAA,EACT;AAAA,EAEQ,mBAAmB;AACzB,SAAK,SAAS,CAAC;AACf,SAAK,aAAa;AAClB,SAAK,aAAa;AAAA,EACpB;AACF","sourcesContent":["import { FirestoreService, Operator } from '../firebase/firebase'\nimport { Firestore, where } from 'firebase/firestore'\nimport {Model} from \"../model\";\n\nexport abstract class BaseRepository<T extends Model> {\n protected abstract path: string\n protected abstract firestore: Firestore\n\n private wheres: Operator[] = []\n private orderField?: string\n private limitCount?: number\n\n getById(id: string | number) {\n return FirestoreService.getInstance(this.firestore)\n .path(this.path)\n .id(id)\n .get<T>()\n }\n\n getAll() {\n this.resetFluentState()\n return FirestoreService.getInstance(this.firestore)\n .path(this.path)\n .getAll<T>()\n }\n\n async update(doc: T) {\n await FirestoreService.getInstance(this.firestore)\n .path(this.path)\n .id(doc.id)\n .update(doc)\n }\n\n set(doc: T, customId?: string | number, merge?: boolean) {\n let firebaseService = FirestoreService.getInstance(this.firestore).path(\n this.path,\n )\n if (customId) firebaseService = firebaseService.id(customId)\n return firebaseService.set(doc, merge)\n }\n\n where(\n fieldPath: string,\n opStr: Operator['opStr'],\n value: string | number | boolean | object,\n ): this {\n this.wheres.push({ fieldPath, opStr, value })\n return this\n }\n\n orderBy(field: string): this {\n this.orderField = field\n return this\n }\n\n limit(n: number): this {\n this.limitCount = n\n return this\n }\n\n async get(): Promise<T[]> {\n let firebaseService = FirestoreService.getInstance(this.firestore)\n .path(\n this.path,\n )\n\n if (this.wheres.length > 0) {\n firebaseService = firebaseService.where(\n ...this.wheres.map((w) => where(w.fieldPath, w.opStr, w.value)),\n )\n }\n\n if (this.orderField) {\n firebaseService = firebaseService.orderBy(this.orderField)\n }\n\n if (this.limitCount !== undefined) {\n firebaseService = firebaseService.limit(this.limitCount)\n }\n const result = await firebaseService.getAll<T>()\n this.resetFluentState()\n return result\n }\n\n private resetFluentState() {\n this.wheres = []\n this.orderField = undefined\n this.limitCount = undefined\n }\n}\n","import {\n addDoc,\n collection,\n deleteDoc,\n doc,\n getDoc,\n getDocs,\n onSnapshot,\n limit as limitConstraint,\n query,\n orderBy as orderByConstraint,\n setDoc,\n updateDoc,\n Firestore,\n QueryConstraint,\n DocumentSnapshot,\n} from 'firebase/firestore'\nimport { QueryLimitConstraint } from '@firebase/firestore'\nimport { FieldPath, WhereFilterOp } from '@google-cloud/firestore'\nimport {Model} from \"../model\";\n\nexport interface Operator {\n fieldPath: string | FieldPath\n opStr: WhereFilterOp\n value: string | object | number | boolean\n}\n\nexport class FirestoreService {\n private static _instance: FirestoreService | null = null\n private readonly _firestore: Firestore\n\n private _path: string | null = null\n private _id: string | number | null = null\n private _limit: QueryLimitConstraint | null = null\n private _where: QueryConstraint[] = []\n private _orderBy: { field: string; direction?: 'asc' | 'desc' }[] = []\n\n private constructor(firestore: Firestore) {\n this._firestore = firestore\n }\n\n /**\n * Get singleton instance using provided Firestore\n */\n public static getInstance(firestore: Firestore): FirestoreService {\n if (!FirestoreService._instance) {\n FirestoreService._instance = new FirestoreService(firestore)\n }\n return FirestoreService._instance\n }\n\n public path(path: string): this {\n this._path = path\n return this\n }\n\n public id(id: string | number): this {\n this._id = id\n return this\n }\n\n public where(...where: QueryConstraint[]): this {\n this._where = where\n return this\n }\n\n public limit(limit: number): this {\n this._limit = limitConstraint(limit)\n return this\n }\n\n public orderBy(field: string, direction: 'asc' | 'desc' = 'desc'): this {\n this._orderBy.push({ field, direction })\n return this\n }\n\n public async get<T>(): Promise<T | null> {\n if (!this._path || this._id == null)\n throw new Error('Path and ID must be set')\n const snap = await getDoc(doc(this._firestore, this._path, `${this._id}`))\n this.reset()\n return snap.exists() ? FirestoreService.dataToModel<T>(snap) : null\n }\n\n public async getAll<T>(): Promise<T[]> {\n if (!this._path) throw new Error('Path must be set')\n console.log(this._path)\n const snap = await getDocs(\n query(\n collection(this._firestore, this._path),\n ...this._where,\n ...this._orderBy.map((o) => orderByConstraint(o.field, o.direction)),\n ...(this._limit ? [this._limit] : []),\n ),\n )\n this.reset()\n return snap.docs.map((doc) => FirestoreService.dataToModel<T>(doc))\n }\n\n public onSnapshotById<T>(\n callback: (doc: T | null) => void,\n onNotFound?: () => void,\n ) {\n if (!this._path || this._id == null)\n throw new Error('Path and ID must be set')\n const unsubscribe = onSnapshot(\n doc(this._firestore, this._path, `${this._id}`),\n { includeMetadataChanges: true },\n (snap) => {\n if (snap.exists()) {\n callback(FirestoreService.dataToModel<T>(snap))\n } else {\n console.warn(`doc not found: ${this._id} path: ${this._path}`)\n callback(null)\n if (onNotFound) onNotFound()\n }\n },\n )\n this.reset()\n return unsubscribe\n }\n\n public onSnapshot<T>(callback: (docs: T[]) => void, onNotFound?: () => void) {\n if (!this._path) throw new Error('Path must be set')\n const unsubscribe = onSnapshot(\n query(\n collection(this._firestore, this._path),\n ...this._where,\n ...this._orderBy.map((o) => orderByConstraint(o.field, o.direction)),\n ...(this._limit ? [this._limit] : []),\n ),\n (snapshot) => {\n if (!snapshot.empty) {\n callback(\n snapshot.docs.map((value) =>\n FirestoreService.dataToModel<T>(value),\n ),\n )\n } else {\n console.warn(`no docs found in path: ${this._path}`)\n callback([])\n if (onNotFound) onNotFound()\n }\n },\n )\n this.reset()\n return unsubscribe\n }\n\n public async add<T>(data: T): Promise<T> {\n if (!this._path) throw new Error('Path must be set')\n const ref = await addDoc(\n collection(this._firestore, this._path),\n FirestoreService.replaceUndefined(data),\n )\n this.reset()\n return { ...data, id: ref.id } as T\n }\n\n public async set<T extends Model>(data: T, merge = true): Promise<T> {\n if (!this._path) throw new Error('Path must be set')\n const docId = this._id ?? data.id ?? null\n\n if (docId) {\n await setDoc(\n doc(this._firestore, this._path, `${docId}`),\n FirestoreService.replaceUndefined(data),\n { merge },\n )\n this.reset()\n return { ...data, id: docId } as T\n } else {\n const ref = await addDoc(\n collection(this._firestore, this._path),\n FirestoreService.replaceUndefined(data),\n )\n this.reset()\n return { ...data, id: ref.id } as T\n }\n }\n\n public async update<T>(data: T): Promise<void> {\n if (!this._path || this._id == null)\n throw new Error('Path and ID must be set')\n await updateDoc(\n doc(this._firestore, this._path, `${this._id}`),\n FirestoreService.replaceUndefined(data),\n )\n this.reset()\n }\n\n public async delete(): Promise<void> {\n if (!this._path || this._id == null)\n throw new Error('Path and ID must be set')\n await deleteDoc(doc(this._firestore, this._path, `${this._id}`))\n this.reset()\n }\n\n public async save<T extends Model>(data: T, merge = true): Promise<T> {\n if (data.id) {\n await this.path(this._path!).id(data.id).set(data, merge)\n return data\n } else {\n return await this.path(this._path!).add(data)\n }\n }\n\n // ---------- UTILS ----------\n\n private static dataToModel<T>(snapshot: DocumentSnapshot): T {\n return {\n ...snapshot.data(),\n id: snapshot.data()?.id || snapshot.id,\n } as T\n }\n\n private static replaceUndefined<T>(data: T) {\n return Object.fromEntries(\n Object.entries(data as Model).map(([key, value]) => [\n key,\n value === undefined ? null : value,\n ]),\n )\n }\n\n private reset() {\n this._path = null\n this._id = null\n this._where = []\n this._orderBy = []\n this._limit = null\n }\n}\n"]}
@@ -62,12 +62,14 @@ var _FirestoreService = class _FirestoreService {
62
62
  if (!this._path)
63
63
  throw new Error("Path must be set");
64
64
  console.log(this._path);
65
- const snap = await getDocs(query(
66
- collection(this._firestore, this._path),
67
- ...this._where,
68
- ...this._orderBy.map((o) => orderByConstraint(o.field, o.direction)),
69
- ...this._limit ? [this._limit] : []
70
- ));
65
+ const snap = await getDocs(
66
+ query(
67
+ collection(this._firestore, this._path),
68
+ ...this._where,
69
+ ...this._orderBy.map((o) => orderByConstraint(o.field, o.direction)),
70
+ ...this._limit ? [this._limit] : []
71
+ )
72
+ );
71
73
  this.reset();
72
74
  return snap.docs.map((doc2) => _FirestoreService.dataToModel(doc2));
73
75
  }
@@ -103,7 +105,11 @@ var _FirestoreService = class _FirestoreService {
103
105
  ),
104
106
  (snapshot) => {
105
107
  if (!snapshot.empty) {
106
- callback(snapshot.docs.map((value) => _FirestoreService.dataToModel(value)));
108
+ callback(
109
+ snapshot.docs.map(
110
+ (value) => _FirestoreService.dataToModel(value)
111
+ )
112
+ );
107
113
  } else {
108
114
  console.warn(`no docs found in path: ${this._path}`);
109
115
  callback([]);
@@ -118,7 +124,10 @@ var _FirestoreService = class _FirestoreService {
118
124
  async add(data) {
119
125
  if (!this._path)
120
126
  throw new Error("Path must be set");
121
- const ref = await addDoc(collection(this._firestore, this._path), _FirestoreService.replaceUndefined(data));
127
+ const ref = await addDoc(
128
+ collection(this._firestore, this._path),
129
+ _FirestoreService.replaceUndefined(data)
130
+ );
122
131
  this.reset();
123
132
  return { ...data, id: ref.id };
124
133
  }
@@ -127,11 +136,18 @@ var _FirestoreService = class _FirestoreService {
127
136
  throw new Error("Path must be set");
128
137
  const docId = this._id ?? data.id ?? null;
129
138
  if (docId) {
130
- await setDoc(doc(this._firestore, this._path, `${docId}`), _FirestoreService.replaceUndefined(data), { merge });
139
+ await setDoc(
140
+ doc(this._firestore, this._path, `${docId}`),
141
+ _FirestoreService.replaceUndefined(data),
142
+ { merge }
143
+ );
131
144
  this.reset();
132
145
  return { ...data, id: docId };
133
146
  } else {
134
- const ref = await addDoc(collection(this._firestore, this._path), _FirestoreService.replaceUndefined(data));
147
+ const ref = await addDoc(
148
+ collection(this._firestore, this._path),
149
+ _FirestoreService.replaceUndefined(data)
150
+ );
135
151
  this.reset();
136
152
  return { ...data, id: ref.id };
137
153
  }
@@ -139,7 +155,10 @@ var _FirestoreService = class _FirestoreService {
139
155
  async update(data) {
140
156
  if (!this._path || this._id == null)
141
157
  throw new Error("Path and ID must be set");
142
- await updateDoc(doc(this._firestore, this._path, `${this._id}`), _FirestoreService.replaceUndefined(data));
158
+ await updateDoc(
159
+ doc(this._firestore, this._path, `${this._id}`),
160
+ _FirestoreService.replaceUndefined(data)
161
+ );
143
162
  this.reset();
144
163
  }
145
164
  async delete() {
@@ -193,13 +212,15 @@ var BaseRepository = class {
193
212
  }
194
213
  getAll() {
195
214
  this.resetFluentState();
196
- return FirestoreService.getInstance(this.firestore).path(this.path).orderBy("createdAt").getAll();
215
+ return FirestoreService.getInstance(this.firestore).path(this.path).getAll();
197
216
  }
198
217
  async update(doc2) {
199
218
  await FirestoreService.getInstance(this.firestore).path(this.path).id(doc2.id).update(doc2);
200
219
  }
201
220
  set(doc2, customId, merge) {
202
- let firebaseService = FirestoreService.getInstance(this.firestore).path(this.path);
221
+ let firebaseService = FirestoreService.getInstance(this.firestore).path(
222
+ this.path
223
+ );
203
224
  if (customId)
204
225
  firebaseService = firebaseService.id(customId);
205
226
  return firebaseService.set(doc2, merge);
@@ -217,7 +238,9 @@ var BaseRepository = class {
217
238
  return this;
218
239
  }
219
240
  async get() {
220
- let firebaseService = FirestoreService.getInstance(this.firestore).path(this.path);
241
+ let firebaseService = FirestoreService.getInstance(this.firestore).path(
242
+ this.path
243
+ );
221
244
  if (this.wheres.length > 0) {
222
245
  firebaseService = firebaseService.where(
223
246
  ...this.wheres.map((w) => where(w.fieldPath, w.opStr, w.value))
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/firebase/firebase.ts","../../src/repository/base.repository.ts"],"sourcesContent":["import {Model} from \"../model\";\nimport {\n addDoc,\n collection,\n deleteDoc,\n doc,\n getDoc,\n getDocs,\n onSnapshot,\n limit as limitConstraint,\n query,\n orderBy as orderByConstraint,\n setDoc,\n updateDoc,\n Firestore,\n QueryConstraint,\n DocumentSnapshot,\n} from 'firebase/firestore'\nimport {QueryLimitConstraint} from \"@firebase/firestore\";\nimport {FieldPath, WhereFilterOp} from \"@google-cloud/firestore\";\n\n\nexport interface Operator {\n fieldPath: string | FieldPath,\n opStr: WhereFilterOp,\n value: string | object | number | boolean\n}\n\n\nexport class FirestoreService {\n private static _instance: FirestoreService | null = null\n private readonly _firestore: Firestore\n\n private _path: string | null = null\n private _id: string | number | null = null\n private _limit: QueryLimitConstraint | null = null\n private _where: QueryConstraint[] = []\n private _orderBy: { field: string; direction?: 'asc' | 'desc' }[] = []\n\n private constructor(firestore: Firestore) {\n this._firestore = firestore\n }\n\n /**\n * Get singleton instance using provided Firestore\n */\n public static getInstance(firestore: Firestore): FirestoreService {\n if (!FirestoreService._instance) {\n FirestoreService._instance = new FirestoreService(firestore)\n }\n return FirestoreService._instance\n }\n\n public path(path: string): this {\n this._path = path\n return this\n }\n\n public id(id: string | number): this {\n this._id = id\n return this\n }\n\n public where(...where: QueryConstraint[]): this {\n this._where = where\n return this\n }\n\n public limit(limit: number): this {\n this._limit = limitConstraint(limit)\n return this\n }\n\n public orderBy(field: string, direction: 'asc' | 'desc' = 'desc'): this {\n this._orderBy.push({ field, direction })\n return this\n }\n\n public async get<T>(): Promise<T | null> {\n if (!this._path || this._id == null) throw new Error('Path and ID must be set')\n const snap = await getDoc(doc(this._firestore, this._path, `${this._id}`))\n this.reset()\n return snap.exists() ? FirestoreService.dataToModel<T>(snap) : null\n }\n\n public async getAll<T>(): Promise<T[]> {\n if (!this._path) throw new Error('Path must be set')\n console.log(this._path)\n const snap = await getDocs(query(\n collection(this._firestore, this._path),\n ...this._where,\n ...this._orderBy.map(o => orderByConstraint(o.field, o.direction)),\n ...(this._limit ? [this._limit] : [])\n ))\n this.reset()\n return snap.docs.map((doc) => FirestoreService.dataToModel<T>(doc))\n }\n\n public onSnapshotById<T>(callback: (doc: T | null) => void, onNotFound?: () => void) {\n if (!this._path || this._id == null) throw new Error('Path and ID must be set')\n const unsubscribe = onSnapshot(\n doc(this._firestore, this._path, `${this._id}`),\n { includeMetadataChanges: true },\n (snap) => {\n if (snap.exists()) {\n callback(FirestoreService.dataToModel<T>(snap))\n } else {\n console.warn(`doc not found: ${this._id} path: ${this._path}`)\n callback(null)\n if (onNotFound) onNotFound()\n }\n }\n )\n this.reset()\n return unsubscribe\n }\n\n public onSnapshot<T>(callback: (docs: T[]) => void, onNotFound?: () => void) {\n if (!this._path) throw new Error('Path must be set')\n const unsubscribe = onSnapshot(\n query(\n collection(this._firestore, this._path),\n ...this._where,\n ...this._orderBy.map(o => orderByConstraint(o.field, o.direction)),\n ...(this._limit ? [this._limit] : [])\n ),\n (snapshot) => {\n if (!snapshot.empty) {\n callback(snapshot.docs.map((value) => FirestoreService.dataToModel<T>(value)))\n } else {\n console.warn(`no docs found in path: ${this._path}`)\n callback([])\n if (onNotFound) onNotFound()\n }\n }\n )\n this.reset()\n return unsubscribe\n }\n\n public async add<T>(data: T): Promise<T> {\n if (!this._path) throw new Error('Path must be set')\n const ref = await addDoc(collection(this._firestore, this._path), FirestoreService.replaceUndefined(data))\n this.reset()\n return { ...data, id: ref.id } as T\n }\n\n public async set<T extends Model>(data: T, merge = true): Promise<T> {\n if (!this._path) throw new Error('Path must be set')\n const docId = this._id ?? data.id ?? null\n\n if (docId) {\n await setDoc(doc(this._firestore, this._path, `${docId}`), FirestoreService.replaceUndefined(data), { merge })\n this.reset()\n return { ...data, id: docId } as T\n } else {\n const ref = await addDoc(collection(this._firestore, this._path), FirestoreService.replaceUndefined(data))\n this.reset()\n return { ...data, id: ref.id } as T\n }\n }\n\n public async update<T>(data: T): Promise<void> {\n if (!this._path || this._id == null) throw new Error('Path and ID must be set')\n await updateDoc(doc(this._firestore, this._path, `${this._id}`), FirestoreService.replaceUndefined(data))\n this.reset()\n }\n\n public async delete(): Promise<void> {\n if (!this._path || this._id == null) throw new Error('Path and ID must be set')\n await deleteDoc(doc(this._firestore, this._path, `${this._id}`))\n this.reset()\n }\n\n public async save<T extends Model>(data: T, merge = true): Promise<T> {\n if (data.id) {\n await this.path(this._path!).id(data.id).set(data, merge)\n return data\n } else {\n return await this.path(this._path!).add(data)\n }\n }\n\n // ---------- UTILS ----------\n\n private static dataToModel<T>(snapshot: DocumentSnapshot): T {\n return {\n ...snapshot.data(),\n id: snapshot.data()?.id || snapshot.id,\n } as T\n }\n\n private static replaceUndefined<T>(data: T) {\n return Object.fromEntries(\n Object.entries(data as Model).map(([key, value]) => [\n key,\n value === undefined ? null : value,\n ])\n )\n }\n\n private reset() {\n this._path = null\n this._id = null\n this._where = []\n this._orderBy = []\n this._limit = null\n }\n}\n","import {Model} from \"../model\";\nimport {FirestoreService, Operator} from \"../firebase/firebase\";\nimport {Firestore, where} from 'firebase/firestore'\n\nexport abstract class BaseRepository<T extends Model> {\n protected abstract path: string;\n protected abstract firestore: Firestore;\n\n private wheres: Operator[] = [];\n private orderField?: string;\n private limitCount?: number;\n\n getById(id: string | number) {\n return FirestoreService.getInstance(this.firestore).path(this.path).id(id).get<T>();\n }\n\n getAll() {\n this.resetFluentState();\n return FirestoreService.getInstance(this.firestore).path(this.path).orderBy('createdAt').getAll<T>();\n }\n\n async update(doc: T) {\n await FirestoreService.getInstance(this.firestore).path(this.path).id(doc.id).update(doc);\n }\n\n set(doc: T, customId?: string | number, merge?: boolean) {\n let firebaseService = FirestoreService.getInstance(this.firestore).path(this.path)\n if(customId) firebaseService = firebaseService.id(customId)\n return firebaseService.set(doc, merge);\n }\n\n where(fieldPath: string, opStr: Operator['opStr'], value: string | number | boolean | object): this {\n this.wheres.push({ fieldPath, opStr, value });\n return this;\n }\n\n orderBy(field: string): this {\n this.orderField = field;\n return this;\n }\n\n limit(n: number): this {\n this.limitCount = n;\n return this;\n }\n\n async get(): Promise<T[]> {\n let firebaseService = FirestoreService.getInstance(this.firestore).path(this.path)\n\n if (this.wheres.length > 0) {\n firebaseService = firebaseService.where(\n ...this.wheres.map(w => where(w.fieldPath, w.opStr, w.value))\n )\n }\n\n if (this.orderField) {\n firebaseService = firebaseService.orderBy(this.orderField)\n }\n\n if (this.limitCount !== undefined) {\n firebaseService = firebaseService.limit(this.limitCount)\n }\n const result = await firebaseService.getAll<T>();\n this.resetFluentState();\n return result;\n }\n\n private resetFluentState() {\n this.wheres = [];\n this.orderField = undefined;\n this.limitCount = undefined;\n }\n}\n"],"mappings":";AACA;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT;AAAA,EACA,WAAW;AAAA,EACX;AAAA,EACA;AAAA,OAIG;AAYA,IAAM,oBAAN,MAAM,kBAAiB;AAAA,EAUlB,YAAY,WAAsB;AAN1C,SAAQ,QAAuB;AAC/B,SAAQ,MAA8B;AACtC,SAAQ,SAAsC;AAC9C,SAAQ,SAA4B,CAAC;AACrC,SAAQ,WAA4D,CAAC;AAGjE,SAAK,aAAa;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA,EAKA,OAAc,YAAY,WAAwC;AAC9D,QAAI,CAAC,kBAAiB,WAAW;AAC7B,wBAAiB,YAAY,IAAI,kBAAiB,SAAS;AAAA,IAC/D;AACA,WAAO,kBAAiB;AAAA,EAC5B;AAAA,EAEO,KAAK,MAAoB;AAC5B,SAAK,QAAQ;AACb,WAAO;AAAA,EACX;AAAA,EAEO,GAAG,IAA2B;AACjC,SAAK,MAAM;AACX,WAAO;AAAA,EACX;AAAA,EAEO,SAASA,QAAgC;AAC5C,SAAK,SAASA;AACd,WAAO;AAAA,EACX;AAAA,EAEO,MAAM,OAAqB;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AO,KAAK,EAAE,WAAW,OAAO,MAAM,CAAC;AAC5C,WAAO;AAAA,EACT;AAAA,EAEA,QAAQ,OAAqB;AAC3B,SAAK,aAAa;AAClB,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,GAAiB;AACrB,SAAK,aAAa;AAClB,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,MAAoB;AACxB,QAAI,kBAAmB,iBAAiB,YAAY,KAAK,SAAS,EAAE,KAAK,KAAK,IAAI;AAElF,QAAI,KAAK,OAAO,SAAS,GAAG;AAC1B,wBAAkB,gBAAgB;AAAA,QAChC,GAAG,KAAK,OAAO,IAAI,OAAK,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,KAAK,CAAC;AAAA,MAC9D;AAAA,IACF;AAEA,QAAI,KAAK,YAAY;AACnB,wBAAkB,gBAAgB,QAAQ,KAAK,UAAU;AAAA,IAC3D;AAEA,QAAI,KAAK,eAAe,QAAW;AACjC,wBAAkB,gBAAgB,MAAM,KAAK,UAAU;AAAA,IACzD;AACA,UAAM,SAAS,MAAM,gBAAgB,OAAU;AAC/C,SAAK,iBAAiB;AACtB,WAAO;AAAA,EACT;AAAA,EAEQ,mBAAmB;AACzB,SAAK,SAAS,CAAC;AACf,SAAK,aAAa;AAClB,SAAK,aAAa;AAAA,EACpB;AACF;","names":["where","doc","doc"]}
1
+ {"version":3,"sources":["../../src/firebase/firebase.ts","../../src/repository/base.repository.ts"],"sourcesContent":["import {\n addDoc,\n collection,\n deleteDoc,\n doc,\n getDoc,\n getDocs,\n onSnapshot,\n limit as limitConstraint,\n query,\n orderBy as orderByConstraint,\n setDoc,\n updateDoc,\n Firestore,\n QueryConstraint,\n DocumentSnapshot,\n} from 'firebase/firestore'\nimport { QueryLimitConstraint } from '@firebase/firestore'\nimport { FieldPath, WhereFilterOp } from '@google-cloud/firestore'\nimport {Model} from \"../model\";\n\nexport interface Operator {\n fieldPath: string | FieldPath\n opStr: WhereFilterOp\n value: string | object | number | boolean\n}\n\nexport class FirestoreService {\n private static _instance: FirestoreService | null = null\n private readonly _firestore: Firestore\n\n private _path: string | null = null\n private _id: string | number | null = null\n private _limit: QueryLimitConstraint | null = null\n private _where: QueryConstraint[] = []\n private _orderBy: { field: string; direction?: 'asc' | 'desc' }[] = []\n\n private constructor(firestore: Firestore) {\n this._firestore = firestore\n }\n\n /**\n * Get singleton instance using provided Firestore\n */\n public static getInstance(firestore: Firestore): FirestoreService {\n if (!FirestoreService._instance) {\n FirestoreService._instance = new FirestoreService(firestore)\n }\n return FirestoreService._instance\n }\n\n public path(path: string): this {\n this._path = path\n return this\n }\n\n public id(id: string | number): this {\n this._id = id\n return this\n }\n\n public where(...where: QueryConstraint[]): this {\n this._where = where\n return this\n }\n\n public limit(limit: number): this {\n this._limit = limitConstraint(limit)\n return this\n }\n\n public orderBy(field: string, direction: 'asc' | 'desc' = 'desc'): this {\n this._orderBy.push({ field, direction })\n return this\n }\n\n public async get<T>(): Promise<T | null> {\n if (!this._path || this._id == null)\n throw new Error('Path and ID must be set')\n const snap = await getDoc(doc(this._firestore, this._path, `${this._id}`))\n this.reset()\n return snap.exists() ? FirestoreService.dataToModel<T>(snap) : null\n }\n\n public async getAll<T>(): Promise<T[]> {\n if (!this._path) throw new Error('Path must be set')\n console.log(this._path)\n const snap = await getDocs(\n query(\n collection(this._firestore, this._path),\n ...this._where,\n ...this._orderBy.map((o) => orderByConstraint(o.field, o.direction)),\n ...(this._limit ? [this._limit] : []),\n ),\n )\n this.reset()\n return snap.docs.map((doc) => FirestoreService.dataToModel<T>(doc))\n }\n\n public onSnapshotById<T>(\n callback: (doc: T | null) => void,\n onNotFound?: () => void,\n ) {\n if (!this._path || this._id == null)\n throw new Error('Path and ID must be set')\n const unsubscribe = onSnapshot(\n doc(this._firestore, this._path, `${this._id}`),\n { includeMetadataChanges: true },\n (snap) => {\n if (snap.exists()) {\n callback(FirestoreService.dataToModel<T>(snap))\n } else {\n console.warn(`doc not found: ${this._id} path: ${this._path}`)\n callback(null)\n if (onNotFound) onNotFound()\n }\n },\n )\n this.reset()\n return unsubscribe\n }\n\n public onSnapshot<T>(callback: (docs: T[]) => void, onNotFound?: () => void) {\n if (!this._path) throw new Error('Path must be set')\n const unsubscribe = onSnapshot(\n query(\n collection(this._firestore, this._path),\n ...this._where,\n ...this._orderBy.map((o) => orderByConstraint(o.field, o.direction)),\n ...(this._limit ? [this._limit] : []),\n ),\n (snapshot) => {\n if (!snapshot.empty) {\n callback(\n snapshot.docs.map((value) =>\n FirestoreService.dataToModel<T>(value),\n ),\n )\n } else {\n console.warn(`no docs found in path: ${this._path}`)\n callback([])\n if (onNotFound) onNotFound()\n }\n },\n )\n this.reset()\n return unsubscribe\n }\n\n public async add<T>(data: T): Promise<T> {\n if (!this._path) throw new Error('Path must be set')\n const ref = await addDoc(\n collection(this._firestore, this._path),\n FirestoreService.replaceUndefined(data),\n )\n this.reset()\n return { ...data, id: ref.id } as T\n }\n\n public async set<T extends Model>(data: T, merge = true): Promise<T> {\n if (!this._path) throw new Error('Path must be set')\n const docId = this._id ?? data.id ?? null\n\n if (docId) {\n await setDoc(\n doc(this._firestore, this._path, `${docId}`),\n FirestoreService.replaceUndefined(data),\n { merge },\n )\n this.reset()\n return { ...data, id: docId } as T\n } else {\n const ref = await addDoc(\n collection(this._firestore, this._path),\n FirestoreService.replaceUndefined(data),\n )\n this.reset()\n return { ...data, id: ref.id } as T\n }\n }\n\n public async update<T>(data: T): Promise<void> {\n if (!this._path || this._id == null)\n throw new Error('Path and ID must be set')\n await updateDoc(\n doc(this._firestore, this._path, `${this._id}`),\n FirestoreService.replaceUndefined(data),\n )\n this.reset()\n }\n\n public async delete(): Promise<void> {\n if (!this._path || this._id == null)\n throw new Error('Path and ID must be set')\n await deleteDoc(doc(this._firestore, this._path, `${this._id}`))\n this.reset()\n }\n\n public async save<T extends Model>(data: T, merge = true): Promise<T> {\n if (data.id) {\n await this.path(this._path!).id(data.id).set(data, merge)\n return data\n } else {\n return await this.path(this._path!).add(data)\n }\n }\n\n // ---------- UTILS ----------\n\n private static dataToModel<T>(snapshot: DocumentSnapshot): T {\n return {\n ...snapshot.data(),\n id: snapshot.data()?.id || snapshot.id,\n } as T\n }\n\n private static replaceUndefined<T>(data: T) {\n return Object.fromEntries(\n Object.entries(data as Model).map(([key, value]) => [\n key,\n value === undefined ? null : value,\n ]),\n )\n }\n\n private reset() {\n this._path = null\n this._id = null\n this._where = []\n this._orderBy = []\n this._limit = null\n }\n}\n","import { FirestoreService, Operator } from '../firebase/firebase'\nimport { Firestore, where } from 'firebase/firestore'\nimport {Model} from \"../model\";\n\nexport abstract class BaseRepository<T extends Model> {\n protected abstract path: string\n protected abstract firestore: Firestore\n\n private wheres: Operator[] = []\n private orderField?: string\n private limitCount?: number\n\n getById(id: string | number) {\n return FirestoreService.getInstance(this.firestore)\n .path(this.path)\n .id(id)\n .get<T>()\n }\n\n getAll() {\n this.resetFluentState()\n return FirestoreService.getInstance(this.firestore)\n .path(this.path)\n .getAll<T>()\n }\n\n async update(doc: T) {\n await FirestoreService.getInstance(this.firestore)\n .path(this.path)\n .id(doc.id)\n .update(doc)\n }\n\n set(doc: T, customId?: string | number, merge?: boolean) {\n let firebaseService = FirestoreService.getInstance(this.firestore).path(\n this.path,\n )\n if (customId) firebaseService = firebaseService.id(customId)\n return firebaseService.set(doc, merge)\n }\n\n where(\n fieldPath: string,\n opStr: Operator['opStr'],\n value: string | number | boolean | object,\n ): this {\n this.wheres.push({ fieldPath, opStr, value })\n return this\n }\n\n orderBy(field: string): this {\n this.orderField = field\n return this\n }\n\n limit(n: number): this {\n this.limitCount = n\n return this\n }\n\n async get(): Promise<T[]> {\n let firebaseService = FirestoreService.getInstance(this.firestore)\n .path(\n this.path,\n )\n\n if (this.wheres.length > 0) {\n firebaseService = firebaseService.where(\n ...this.wheres.map((w) => where(w.fieldPath, w.opStr, w.value)),\n )\n }\n\n if (this.orderField) {\n firebaseService = firebaseService.orderBy(this.orderField)\n }\n\n if (this.limitCount !== undefined) {\n firebaseService = firebaseService.limit(this.limitCount)\n }\n const result = await firebaseService.getAll<T>()\n this.resetFluentState()\n return result\n }\n\n private resetFluentState() {\n this.wheres = []\n this.orderField = undefined\n this.limitCount = undefined\n }\n}\n"],"mappings":";AAAA;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT;AAAA,EACA,WAAW;AAAA,EACX;AAAA,EACA;AAAA,OAIG;AAWA,IAAM,oBAAN,MAAM,kBAAiB;AAAA,EAUlB,YAAY,WAAsB;AAN1C,SAAQ,QAAuB;AAC/B,SAAQ,MAA8B;AACtC,SAAQ,SAAsC;AAC9C,SAAQ,SAA4B,CAAC;AACrC,SAAQ,WAA4D,CAAC;AAGjE,SAAK,aAAa;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA,EAKA,OAAc,YAAY,WAAwC;AAC9D,QAAI,CAAC,kBAAiB,WAAW;AAC7B,wBAAiB,YAAY,IAAI,kBAAiB,SAAS;AAAA,IAC/D;AACA,WAAO,kBAAiB;AAAA,EAC5B;AAAA,EAEO,KAAK,MAAoB;AAC5B,SAAK,QAAQ;AACb,WAAO;AAAA,EACX;AAAA,EAEO,GAAG,IAA2B;AACjC,SAAK,MAAM;AACX,WAAO;AAAA,EACX;AAAA,EAEO,SAASA,QAAgC;AAC5C,SAAK,SAASA;AACd,WAAO;AAAA,EACX;AAAA,EAEO,MAAM,OAAqB;AAC9B,SAAK,SAAS,gBAAgB,KAAK;AACnC,WAAO;AAAA,EACX;AAAA,EAEO,QAAQ,OAAe,YAA4B,QAAc;AACpE,SAAK,SAAS,KAAK,EAAE,OAAO,UAAU,CAAC;AACvC,WAAO;AAAA,EACX;AAAA,EAEA,MAAa,MAA4B;AACrC,QAAI,CAAC,KAAK,SAAS,KAAK,OAAO;AAC3B,YAAM,IAAI,MAAM,yBAAyB;AAC7C,UAAM,OAAO,MAAM,OAAO,IAAI,KAAK,YAAY,KAAK,OAAO,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kB,iBAAiB,YAAY,KAAK,SAAS,EAC9D;AAAA,MACC,KAAK;AAAA,IACP;AAEF,QAAI,KAAK,OAAO,SAAS,GAAG;AAC1B,wBAAkB,gBAAgB;AAAA,QAChC,GAAG,KAAK,OAAO,IAAI,CAAC,MAAM,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,KAAK,CAAC;AAAA,MAChE;AAAA,IACF;AAEA,QAAI,KAAK,YAAY;AACnB,wBAAkB,gBAAgB,QAAQ,KAAK,UAAU;AAAA,IAC3D;AAEA,QAAI,KAAK,eAAe,QAAW;AACjC,wBAAkB,gBAAgB,MAAM,KAAK,UAAU;AAAA,IACzD;AACA,UAAM,SAAS,MAAM,gBAAgB,OAAU;AAC/C,SAAK,iBAAiB;AACtB,WAAO;AAAA,EACT;AAAA,EAEQ,mBAAmB;AACzB,SAAK,SAAS,CAAC;AACf,SAAK,aAAa;AAClB,SAAK,aAAa;AAAA,EACpB;AACF;","names":["where","doc","doc"]}
@@ -1,11 +1,11 @@
1
1
  import { BaseRepository } from './base.repository.mjs';
2
2
  import { Product } from '../model/integrada/product.mjs';
3
3
  import { Firestore } from 'firebase/firestore';
4
- import '../model.mjs';
5
- import 'zod';
6
4
  import '../firebase/firebase.mjs';
7
5
  import '@firebase/firestore';
8
6
  import '@google-cloud/firestore';
7
+ import '../model.mjs';
8
+ import 'zod';
9
9
 
10
10
  declare class ProductRepository extends BaseRepository<Product> {
11
11
  protected path: string;
@@ -1,11 +1,11 @@
1
1
  import { BaseRepository } from './base.repository.js';
2
2
  import { Product } from '../model/integrada/product.js';
3
3
  import { Firestore } from 'firebase/firestore';
4
- import '../model.js';
5
- import 'zod';
6
4
  import '../firebase/firebase.js';
7
5
  import '@firebase/firestore';
8
6
  import '@google-cloud/firestore';
7
+ import '../model.js';
8
+ import 'zod';
9
9
 
10
10
  declare class ProductRepository extends BaseRepository<Product> {
11
11
  protected path: string;
@@ -773,7 +773,7 @@ var BaseRepository = /*#__PURE__*/ function() {
773
773
  key: "getAll",
774
774
  value: function getAll() {
775
775
  this.resetFluentState();
776
- return FirestoreService.getInstance(this.firestore).path(this.path).orderBy("createdAt").getAll();
776
+ return FirestoreService.getInstance(this.firestore).path(this.path).getAll();
777
777
  }
778
778
  },
779
779
  {