@firestore-repository/firebase-js-sdk 0.2.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/build/esm/index.d.ts +2 -2
- package/build/esm/index.js +7 -5
- package/package.json +2 -2
package/README.md
CHANGED
@@ -93,7 +93,7 @@ await repository.delete({ userId: 'user2' });
|
|
93
93
|
import { condition as $, limit, query, where } from 'firestore-repository/query';
|
94
94
|
|
95
95
|
// Define a query
|
96
|
-
const query1 = query(users,
|
96
|
+
const query1 = query(users, $('profile.age', '>=', 20), limit(10));
|
97
97
|
|
98
98
|
// List documents
|
99
99
|
const docs = await repository.list(query1);
|
package/build/esm/index.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { type DocumentReference, type DocumentSnapshot, type Firestore, type Query as FirestoreQuery, Transaction, type WriteBatch } from '@firebase/firestore';
|
2
|
-
import type {
|
2
|
+
import type { AggregateSpec, Aggregated } from 'firestore-repository/aggregate';
|
3
3
|
import type { WriteDocumentData } from 'firestore-repository/document';
|
4
4
|
import type { Query } from 'firestore-repository/query';
|
5
5
|
import type * as repository from 'firestore-repository/repository';
|
@@ -19,7 +19,7 @@ export declare class Repository<T extends CollectionSchema = CollectionSchema> i
|
|
19
19
|
getOnSnapshot(id: Id<T>, next: (snapshot: Model<T> | undefined) => void, error?: (error: Error) => void, complete?: () => void): repository.Unsubscribe;
|
20
20
|
list(query: Query<T>): Promise<Model<T>[]>;
|
21
21
|
listOnSnapshot(query: Query<T>, next: (snapshot: Model<T>[]) => void, error?: (error: Error) => void, complete?: () => void): repository.Unsubscribe;
|
22
|
-
aggregate<U extends
|
22
|
+
aggregate<U extends AggregateSpec<T>>(query: Query<T>, spec: U): Promise<Aggregated<U>>;
|
23
23
|
set(doc: Model<T>, options?: WriteTransactionOption): Promise<void>;
|
24
24
|
delete(id: Id<T>, options?: WriteTransactionOption): Promise<void>;
|
25
25
|
batchSet(docs: Model<T>[], options?: WriteTransactionOption): Promise<void>;
|
package/build/esm/index.js
CHANGED
@@ -41,9 +41,9 @@ export class Repository {
|
|
41
41
|
},
|
42
42
|
});
|
43
43
|
}
|
44
|
-
async aggregate(
|
44
|
+
async aggregate(query, spec) {
|
45
45
|
const aggregateSpec = {};
|
46
|
-
for (const [k, v] of Object.entries(
|
46
|
+
for (const [k, v] of Object.entries(spec)) {
|
47
47
|
switch (v.kind) {
|
48
48
|
case 'count':
|
49
49
|
aggregateSpec[k] = count();
|
@@ -58,7 +58,7 @@ export class Repository {
|
|
58
58
|
return assertNever(v);
|
59
59
|
}
|
60
60
|
}
|
61
|
-
const res = await getAggregateFromServer(toFirestoreQuery(this.db,
|
61
|
+
const res = await getAggregateFromServer(toFirestoreQuery(this.db, query), aggregateSpec);
|
62
62
|
return res.data();
|
63
63
|
}
|
64
64
|
async set(doc, options) {
|
@@ -136,8 +136,10 @@ export const docPathElements = (doc) => {
|
|
136
136
|
export const toFirestoreQuery = (db, query) => {
|
137
137
|
const { filter, nonFilter } = (query.constraints ?? []).reduce((acc, constraint) => {
|
138
138
|
switch (constraint.kind) {
|
139
|
-
case 'where':
|
140
|
-
|
139
|
+
case 'where':
|
140
|
+
case 'and':
|
141
|
+
case 'or': {
|
142
|
+
const filter = toFirestoreQueryFilterConstraint(constraint);
|
141
143
|
acc.filter = acc.filter ? and(acc.filter, filter) : filter;
|
142
144
|
break;
|
143
145
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@firestore-repository/firebase-js-sdk",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.4.0",
|
4
4
|
"description": "A minimum and universal Firestore ORM (Repository Pattern) for TypeScript",
|
5
5
|
"homepage": "https://github.com/ikenox/firestore-repository",
|
6
6
|
"repository": {
|
@@ -10,7 +10,7 @@
|
|
10
10
|
"type": "module",
|
11
11
|
"dependencies": {
|
12
12
|
"@firebase/firestore": "^4.7.5",
|
13
|
-
"firestore-repository": "0.
|
13
|
+
"firestore-repository": "0.4.0"
|
14
14
|
},
|
15
15
|
"devDependencies": {
|
16
16
|
"@firebase/app": "^0.10.16"
|