@firestore-repository/google-cloud-firestore 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 +6 -4
- 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, Filter, type Firestore, type Query as FirestoreQuery, Transaction, type WriteBatch } from '@google-cloud/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 { FilterExpression, Offset, 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): 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): repository.Unsubscribe;
|
22
|
-
aggregate<U extends
|
22
|
+
aggregate<U extends AggregateSpec<T>>(query: Query<T>, spec: U): Promise<Aggregated<U>>;
|
23
23
|
/**
|
24
24
|
* Create a new document
|
25
25
|
* @throws If the document already exists
|
package/build/esm/index.js
CHANGED
@@ -29,9 +29,9 @@ export class Repository {
|
|
29
29
|
next(snapshot.docs.map((doc) => this.fromFirestore(doc)));
|
30
30
|
}, error);
|
31
31
|
}
|
32
|
-
async aggregate(
|
32
|
+
async aggregate(query, spec) {
|
33
33
|
const aggregateSpec = {};
|
34
|
-
for (const [k, v] of Object.entries(
|
34
|
+
for (const [k, v] of Object.entries(spec)) {
|
35
35
|
switch (v.kind) {
|
36
36
|
case 'count':
|
37
37
|
aggregateSpec[k] = AggregateField.count();
|
@@ -46,7 +46,7 @@ export class Repository {
|
|
46
46
|
return assertNever(v);
|
47
47
|
}
|
48
48
|
}
|
49
|
-
const res = await toFirestoreQuery(this.db,
|
49
|
+
const res = await toFirestoreQuery(this.db, query).aggregate(aggregateSpec).get();
|
50
50
|
return res.data();
|
51
51
|
}
|
52
52
|
/**
|
@@ -167,7 +167,9 @@ export const toFirestoreQuery = (db, query) => {
|
|
167
167
|
return (query.constraints?.reduce((q, constraint) => {
|
168
168
|
switch (constraint.kind) {
|
169
169
|
case 'where':
|
170
|
-
|
170
|
+
case 'or':
|
171
|
+
case 'and':
|
172
|
+
return q.where(toFirestoreFilter(constraint));
|
171
173
|
case 'orderBy':
|
172
174
|
return q.orderBy(constraint.field, constraint.direction);
|
173
175
|
case 'limit':
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@firestore-repository/google-cloud-firestore",
|
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
|
"@google-cloud/firestore": "^7.10.0",
|
13
|
-
"firestore-repository": "0.
|
13
|
+
"firestore-repository": "0.4.0"
|
14
14
|
},
|
15
15
|
"exports": {
|
16
16
|
".": {
|