@_henriquewilson/gabirubi-domain 1.2.4 → 1.2.5
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/dist/model/iugu/iugu-charge.d.mts +2 -2
- package/dist/model/iugu/iugu-charge.d.ts +2 -2
- package/dist/model/iugu/iugu-client.d.mts +12 -12
- package/dist/model/iugu/iugu-client.d.ts +12 -12
- package/dist/repository/base.repository.js +1 -1
- package/dist/repository/base.repository.js.map +1 -1
- package/dist/repository/base.repository.mjs +1 -1
- package/dist/repository/base.repository.mjs.map +1 -1
- package/dist/repository/product.repository.js +1 -1
- package/dist/repository/product.repository.js.map +1 -1
- package/dist/repository/product.repository.mjs +1 -1
- package/dist/repository/product.repository.mjs.map +1 -1
- package/dist/test/repository/firestore.service.test.d.mts +2 -0
- package/dist/test/repository/firestore.service.test.d.ts +2 -0
- package/dist/test/repository/firestore.service.test.js +864 -0
- package/dist/test/repository/firestore.service.test.js.map +1 -0
- package/dist/test/repository/firestore.service.test.mjs +275 -0
- package/dist/test/repository/firestore.service.test.mjs.map +1 -0
- package/package.json +1 -1
|
@@ -26,9 +26,9 @@ declare const IuguChargeSchema: z.ZodObject<{
|
|
|
26
26
|
pdf: string;
|
|
27
27
|
invoice_id: string;
|
|
28
28
|
LR: string;
|
|
29
|
+
reversible?: string | null | undefined;
|
|
29
30
|
brand?: string | null | undefined;
|
|
30
31
|
bin?: string | null | undefined;
|
|
31
|
-
reversible?: string | null | undefined;
|
|
32
32
|
last4?: string | null | undefined;
|
|
33
33
|
issuer?: string | null | undefined;
|
|
34
34
|
identification?: string | null | undefined;
|
|
@@ -42,9 +42,9 @@ declare const IuguChargeSchema: z.ZodObject<{
|
|
|
42
42
|
pdf: string;
|
|
43
43
|
invoice_id: string;
|
|
44
44
|
LR: string;
|
|
45
|
+
reversible?: string | null | undefined;
|
|
45
46
|
brand?: string | null | undefined;
|
|
46
47
|
bin?: string | null | undefined;
|
|
47
|
-
reversible?: string | null | undefined;
|
|
48
48
|
last4?: string | null | undefined;
|
|
49
49
|
issuer?: string | null | undefined;
|
|
50
50
|
identification?: string | null | undefined;
|
|
@@ -26,9 +26,9 @@ declare const IuguChargeSchema: z.ZodObject<{
|
|
|
26
26
|
pdf: string;
|
|
27
27
|
invoice_id: string;
|
|
28
28
|
LR: string;
|
|
29
|
+
reversible?: string | null | undefined;
|
|
29
30
|
brand?: string | null | undefined;
|
|
30
31
|
bin?: string | null | undefined;
|
|
31
|
-
reversible?: string | null | undefined;
|
|
32
32
|
last4?: string | null | undefined;
|
|
33
33
|
issuer?: string | null | undefined;
|
|
34
34
|
identification?: string | null | undefined;
|
|
@@ -42,9 +42,9 @@ declare const IuguChargeSchema: z.ZodObject<{
|
|
|
42
42
|
pdf: string;
|
|
43
43
|
invoice_id: string;
|
|
44
44
|
LR: string;
|
|
45
|
+
reversible?: string | null | undefined;
|
|
45
46
|
brand?: string | null | undefined;
|
|
46
47
|
bin?: string | null | undefined;
|
|
47
|
-
reversible?: string | null | undefined;
|
|
48
48
|
last4?: string | null | undefined;
|
|
49
49
|
issuer?: string | null | undefined;
|
|
50
50
|
identification?: string | null | undefined;
|
|
@@ -12,9 +12,9 @@ declare const dataSchema: z.ZodObject<{
|
|
|
12
12
|
masked_number: z.ZodString;
|
|
13
13
|
}, "strip", z.ZodTypeAny, {
|
|
14
14
|
brand: string;
|
|
15
|
+
bin: string;
|
|
15
16
|
holder_name: string;
|
|
16
17
|
display_number: string;
|
|
17
|
-
bin: string;
|
|
18
18
|
year: number;
|
|
19
19
|
month: number;
|
|
20
20
|
last_digits: string;
|
|
@@ -22,9 +22,9 @@ declare const dataSchema: z.ZodObject<{
|
|
|
22
22
|
masked_number: string;
|
|
23
23
|
}, {
|
|
24
24
|
brand: string;
|
|
25
|
+
bin: string;
|
|
25
26
|
holder_name: string;
|
|
26
27
|
display_number: string;
|
|
27
|
-
bin: string;
|
|
28
28
|
year: number;
|
|
29
29
|
month: number;
|
|
30
30
|
last_digits: string;
|
|
@@ -47,9 +47,9 @@ declare const paymentMethodSchema: z.ZodObject<{
|
|
|
47
47
|
masked_number: z.ZodString;
|
|
48
48
|
}, "strip", z.ZodTypeAny, {
|
|
49
49
|
brand: string;
|
|
50
|
+
bin: string;
|
|
50
51
|
holder_name: string;
|
|
51
52
|
display_number: string;
|
|
52
|
-
bin: string;
|
|
53
53
|
year: number;
|
|
54
54
|
month: number;
|
|
55
55
|
last_digits: string;
|
|
@@ -57,9 +57,9 @@ declare const paymentMethodSchema: z.ZodObject<{
|
|
|
57
57
|
masked_number: string;
|
|
58
58
|
}, {
|
|
59
59
|
brand: string;
|
|
60
|
+
bin: string;
|
|
60
61
|
holder_name: string;
|
|
61
62
|
display_number: string;
|
|
62
|
-
bin: string;
|
|
63
63
|
year: number;
|
|
64
64
|
month: number;
|
|
65
65
|
last_digits: string;
|
|
@@ -72,9 +72,9 @@ declare const paymentMethodSchema: z.ZodObject<{
|
|
|
72
72
|
item_type: string;
|
|
73
73
|
data: {
|
|
74
74
|
brand: string;
|
|
75
|
+
bin: string;
|
|
75
76
|
holder_name: string;
|
|
76
77
|
display_number: string;
|
|
77
|
-
bin: string;
|
|
78
78
|
year: number;
|
|
79
79
|
month: number;
|
|
80
80
|
last_digits: string;
|
|
@@ -87,9 +87,9 @@ declare const paymentMethodSchema: z.ZodObject<{
|
|
|
87
87
|
item_type: string;
|
|
88
88
|
data: {
|
|
89
89
|
brand: string;
|
|
90
|
+
bin: string;
|
|
90
91
|
holder_name: string;
|
|
91
92
|
display_number: string;
|
|
92
|
-
bin: string;
|
|
93
93
|
year: number;
|
|
94
94
|
month: number;
|
|
95
95
|
last_digits: string;
|
|
@@ -139,9 +139,9 @@ declare const IuguClientSchema: z.ZodObject<z.objectUtil.extendShape<{
|
|
|
139
139
|
masked_number: z.ZodString;
|
|
140
140
|
}, "strip", z.ZodTypeAny, {
|
|
141
141
|
brand: string;
|
|
142
|
+
bin: string;
|
|
142
143
|
holder_name: string;
|
|
143
144
|
display_number: string;
|
|
144
|
-
bin: string;
|
|
145
145
|
year: number;
|
|
146
146
|
month: number;
|
|
147
147
|
last_digits: string;
|
|
@@ -149,9 +149,9 @@ declare const IuguClientSchema: z.ZodObject<z.objectUtil.extendShape<{
|
|
|
149
149
|
masked_number: string;
|
|
150
150
|
}, {
|
|
151
151
|
brand: string;
|
|
152
|
+
bin: string;
|
|
152
153
|
holder_name: string;
|
|
153
154
|
display_number: string;
|
|
154
|
-
bin: string;
|
|
155
155
|
year: number;
|
|
156
156
|
month: number;
|
|
157
157
|
last_digits: string;
|
|
@@ -164,9 +164,9 @@ declare const IuguClientSchema: z.ZodObject<z.objectUtil.extendShape<{
|
|
|
164
164
|
item_type: string;
|
|
165
165
|
data: {
|
|
166
166
|
brand: string;
|
|
167
|
+
bin: string;
|
|
167
168
|
holder_name: string;
|
|
168
169
|
display_number: string;
|
|
169
|
-
bin: string;
|
|
170
170
|
year: number;
|
|
171
171
|
month: number;
|
|
172
172
|
last_digits: string;
|
|
@@ -179,9 +179,9 @@ declare const IuguClientSchema: z.ZodObject<z.objectUtil.extendShape<{
|
|
|
179
179
|
item_type: string;
|
|
180
180
|
data: {
|
|
181
181
|
brand: string;
|
|
182
|
+
bin: string;
|
|
182
183
|
holder_name: string;
|
|
183
184
|
display_number: string;
|
|
184
|
-
bin: string;
|
|
185
185
|
year: number;
|
|
186
186
|
month: number;
|
|
187
187
|
last_digits: string;
|
|
@@ -216,9 +216,9 @@ declare const IuguClientSchema: z.ZodObject<z.objectUtil.extendShape<{
|
|
|
216
216
|
item_type: string;
|
|
217
217
|
data: {
|
|
218
218
|
brand: string;
|
|
219
|
+
bin: string;
|
|
219
220
|
holder_name: string;
|
|
220
221
|
display_number: string;
|
|
221
|
-
bin: string;
|
|
222
222
|
year: number;
|
|
223
223
|
month: number;
|
|
224
224
|
last_digits: string;
|
|
@@ -253,9 +253,9 @@ declare const IuguClientSchema: z.ZodObject<z.objectUtil.extendShape<{
|
|
|
253
253
|
item_type: string;
|
|
254
254
|
data: {
|
|
255
255
|
brand: string;
|
|
256
|
+
bin: string;
|
|
256
257
|
holder_name: string;
|
|
257
258
|
display_number: string;
|
|
258
|
-
bin: string;
|
|
259
259
|
year: number;
|
|
260
260
|
month: number;
|
|
261
261
|
last_digits: string;
|
|
@@ -12,9 +12,9 @@ declare const dataSchema: z.ZodObject<{
|
|
|
12
12
|
masked_number: z.ZodString;
|
|
13
13
|
}, "strip", z.ZodTypeAny, {
|
|
14
14
|
brand: string;
|
|
15
|
+
bin: string;
|
|
15
16
|
holder_name: string;
|
|
16
17
|
display_number: string;
|
|
17
|
-
bin: string;
|
|
18
18
|
year: number;
|
|
19
19
|
month: number;
|
|
20
20
|
last_digits: string;
|
|
@@ -22,9 +22,9 @@ declare const dataSchema: z.ZodObject<{
|
|
|
22
22
|
masked_number: string;
|
|
23
23
|
}, {
|
|
24
24
|
brand: string;
|
|
25
|
+
bin: string;
|
|
25
26
|
holder_name: string;
|
|
26
27
|
display_number: string;
|
|
27
|
-
bin: string;
|
|
28
28
|
year: number;
|
|
29
29
|
month: number;
|
|
30
30
|
last_digits: string;
|
|
@@ -47,9 +47,9 @@ declare const paymentMethodSchema: z.ZodObject<{
|
|
|
47
47
|
masked_number: z.ZodString;
|
|
48
48
|
}, "strip", z.ZodTypeAny, {
|
|
49
49
|
brand: string;
|
|
50
|
+
bin: string;
|
|
50
51
|
holder_name: string;
|
|
51
52
|
display_number: string;
|
|
52
|
-
bin: string;
|
|
53
53
|
year: number;
|
|
54
54
|
month: number;
|
|
55
55
|
last_digits: string;
|
|
@@ -57,9 +57,9 @@ declare const paymentMethodSchema: z.ZodObject<{
|
|
|
57
57
|
masked_number: string;
|
|
58
58
|
}, {
|
|
59
59
|
brand: string;
|
|
60
|
+
bin: string;
|
|
60
61
|
holder_name: string;
|
|
61
62
|
display_number: string;
|
|
62
|
-
bin: string;
|
|
63
63
|
year: number;
|
|
64
64
|
month: number;
|
|
65
65
|
last_digits: string;
|
|
@@ -72,9 +72,9 @@ declare const paymentMethodSchema: z.ZodObject<{
|
|
|
72
72
|
item_type: string;
|
|
73
73
|
data: {
|
|
74
74
|
brand: string;
|
|
75
|
+
bin: string;
|
|
75
76
|
holder_name: string;
|
|
76
77
|
display_number: string;
|
|
77
|
-
bin: string;
|
|
78
78
|
year: number;
|
|
79
79
|
month: number;
|
|
80
80
|
last_digits: string;
|
|
@@ -87,9 +87,9 @@ declare const paymentMethodSchema: z.ZodObject<{
|
|
|
87
87
|
item_type: string;
|
|
88
88
|
data: {
|
|
89
89
|
brand: string;
|
|
90
|
+
bin: string;
|
|
90
91
|
holder_name: string;
|
|
91
92
|
display_number: string;
|
|
92
|
-
bin: string;
|
|
93
93
|
year: number;
|
|
94
94
|
month: number;
|
|
95
95
|
last_digits: string;
|
|
@@ -139,9 +139,9 @@ declare const IuguClientSchema: z.ZodObject<z.objectUtil.extendShape<{
|
|
|
139
139
|
masked_number: z.ZodString;
|
|
140
140
|
}, "strip", z.ZodTypeAny, {
|
|
141
141
|
brand: string;
|
|
142
|
+
bin: string;
|
|
142
143
|
holder_name: string;
|
|
143
144
|
display_number: string;
|
|
144
|
-
bin: string;
|
|
145
145
|
year: number;
|
|
146
146
|
month: number;
|
|
147
147
|
last_digits: string;
|
|
@@ -149,9 +149,9 @@ declare const IuguClientSchema: z.ZodObject<z.objectUtil.extendShape<{
|
|
|
149
149
|
masked_number: string;
|
|
150
150
|
}, {
|
|
151
151
|
brand: string;
|
|
152
|
+
bin: string;
|
|
152
153
|
holder_name: string;
|
|
153
154
|
display_number: string;
|
|
154
|
-
bin: string;
|
|
155
155
|
year: number;
|
|
156
156
|
month: number;
|
|
157
157
|
last_digits: string;
|
|
@@ -164,9 +164,9 @@ declare const IuguClientSchema: z.ZodObject<z.objectUtil.extendShape<{
|
|
|
164
164
|
item_type: string;
|
|
165
165
|
data: {
|
|
166
166
|
brand: string;
|
|
167
|
+
bin: string;
|
|
167
168
|
holder_name: string;
|
|
168
169
|
display_number: string;
|
|
169
|
-
bin: string;
|
|
170
170
|
year: number;
|
|
171
171
|
month: number;
|
|
172
172
|
last_digits: string;
|
|
@@ -179,9 +179,9 @@ declare const IuguClientSchema: z.ZodObject<z.objectUtil.extendShape<{
|
|
|
179
179
|
item_type: string;
|
|
180
180
|
data: {
|
|
181
181
|
brand: string;
|
|
182
|
+
bin: string;
|
|
182
183
|
holder_name: string;
|
|
183
184
|
display_number: string;
|
|
184
|
-
bin: string;
|
|
185
185
|
year: number;
|
|
186
186
|
month: number;
|
|
187
187
|
last_digits: string;
|
|
@@ -216,9 +216,9 @@ declare const IuguClientSchema: z.ZodObject<z.objectUtil.extendShape<{
|
|
|
216
216
|
item_type: string;
|
|
217
217
|
data: {
|
|
218
218
|
brand: string;
|
|
219
|
+
bin: string;
|
|
219
220
|
holder_name: string;
|
|
220
221
|
display_number: string;
|
|
221
|
-
bin: string;
|
|
222
222
|
year: number;
|
|
223
223
|
month: number;
|
|
224
224
|
last_digits: string;
|
|
@@ -253,9 +253,9 @@ declare const IuguClientSchema: z.ZodObject<z.objectUtil.extendShape<{
|
|
|
253
253
|
item_type: string;
|
|
254
254
|
data: {
|
|
255
255
|
brand: string;
|
|
256
|
+
bin: string;
|
|
256
257
|
holder_name: string;
|
|
257
258
|
display_number: string;
|
|
258
|
-
bin: string;
|
|
259
259
|
year: number;
|
|
260
260
|
month: number;
|
|
261
261
|
last_digits: 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).
|
|
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"],"m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B,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;;;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,IAAI,kBAAiB,SAAS;AAAA,IAC/D;AACA,WAAO,kBA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F;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).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"]}
|
|
@@ -193,7 +193,7 @@ var BaseRepository = class {
|
|
|
193
193
|
}
|
|
194
194
|
getAll() {
|
|
195
195
|
this.resetFluentState();
|
|
196
|
-
return FirestoreService.getInstance(this.firestore).path(this.path).
|
|
196
|
+
return FirestoreService.getInstance(this.firestore).path(this.path).getAll();
|
|
197
197
|
}
|
|
198
198
|
async update(doc2) {
|
|
199
199
|
await FirestoreService.getInstance(this.firestore).path(this.path).id(doc2.id).update(doc2);
|
|
@@ -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;AA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;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 {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).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;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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,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"]}
|
|
@@ -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).
|
|
776
|
+
return FirestoreService.getInstance(this.firestore).path(this.path).getAll();
|
|
777
777
|
}
|
|
778
778
|
},
|
|
779
779
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/repository/product.repository.ts","../../src/firebase/firebase.ts","../../src/repository/base.repository.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,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;AACvC,WAAO;AAAA,EACX;AAAA,EAEA,MAAa,MAA4B;AACrC,QAAI,CAAC,KAAK,SAAS,KAAK,OAAO;AAAM,YAAM,IAAI,MAAM,yBAAyB;AAC9E,UAAM,OAAO,UAAM,6BAAO,sBAAI,KAAK,YAAY,KAAK,OAAO,GAAG,KAAK,GAAG,EAAE,CAAC;AACzE,SAAK,MAAM;AACX,WAAO,KAAK,OAAO,IAAI,kBAAiB,YAAe,IAAI,IAAI;AAAA,EACnE;AAAA,EAEA,MAAa,SAA0B;AACnC,Q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K,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;;;AFpEO,IAAM,oBAAN,MAAM,2BAA0B,eAAuB;AAAA,EAMpD,YAAY,WAAsB;AACxC,UAAM;AANR,SAAU,OAAO;AAOf,SAAK,YAAY;AAAA,EACnB;AAAA,EAEA,OAAc,YAAY,WAAyC;AACjE,QAAI,CAAC,mBAAkB,UAAU;AAC/B,yBAAkB,WAAW,IAAI,mBAAkB,SAAS;AAAA,IAC9D;AACA,WAAO,mBAAkB;AAAA,EAC3B;AACF","sourcesContent":["import {BaseRepository} from \"./base.repository\";\nimport {Product} from \"../model/integrada/product\";\nimport {Firestore} from \"firebase/firestore\";\n\nexport class ProductRepository extends BaseRepository<Product>{\n protected path = 'lojaintegrada/products/products';\n protected firestore: Firestore\n\n private static instance: ProductRepository;\n\n private constructor(firestore: Firestore) {\n super();\n this.firestore = firestore;\n }\n\n public static getInstance(firestore: Firestore): ProductRepository {\n if (!ProductRepository.instance) {\n ProductRepository.instance = new ProductRepository(firestore);\n }\n return ProductRepository.instance;\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","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"]}
|
|
1
|
+
{"version":3,"sources":["../../src/repository/product.repository.ts","../../src/firebase/firebase.ts","../../src/repository/base.repository.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,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;AACvC,WAAO;AAAA,EACX;AAAA,EAEA,MAAa,MAA4B;AACrC,QAAI,CAAC,KAAK,SAAS,KAAK,OAAO;AAAM,YAAM,IAAI,MAAM,yBAAyB;AAC9E,UAAM,OAAO,UAAM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,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;;;AFpEO,IAAM,oBAAN,MAAM,2BAA0B,eAAuB;AAAA,EAMpD,YAAY,WAAsB;AACxC,UAAM;AANR,SAAU,OAAO;AAOf,SAAK,YAAY;AAAA,EACnB;AAAA,EAEA,OAAc,YAAY,WAAyC;AACjE,QAAI,CAAC,mBAAkB,UAAU;AAC/B,yBAAkB,WAAW,IAAI,mBAAkB,SAAS;AAAA,IAC9D;AACA,WAAO,mBAAkB;AAAA,EAC3B;AACF","sourcesContent":["import {BaseRepository} from \"./base.repository\";\nimport {Product} from \"../model/integrada/product\";\nimport {Firestore} from \"firebase/firestore\";\n\nexport class ProductRepository extends BaseRepository<Product>{\n protected path = 'lojaintegrada/products/products';\n protected firestore: Firestore\n\n private static instance: ProductRepository;\n\n private constructor(firestore: Firestore) {\n super();\n this.firestore = firestore;\n }\n\n public static getInstance(firestore: Firestore): ProductRepository {\n if (!ProductRepository.instance) {\n ProductRepository.instance = new ProductRepository(firestore);\n }\n return ProductRepository.instance;\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","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).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"]}
|
|
@@ -193,7 +193,7 @@ var BaseRepository = class {
|
|
|
193
193
|
}
|
|
194
194
|
getAll() {
|
|
195
195
|
this.resetFluentState();
|
|
196
|
-
return FirestoreService.getInstance(this.firestore).path(this.path).
|
|
196
|
+
return FirestoreService.getInstance(this.firestore).path(this.path).getAll();
|
|
197
197
|
}
|
|
198
198
|
async update(doc2) {
|
|
199
199
|
await FirestoreService.getInstance(this.firestore).path(this.path).id(doc2.id).update(doc2);
|