@dereekb/firebase 9.25.15 → 10.0.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/CHANGELOG.md +12 -0
- package/package.json +12 -21
- package/src/lib/client/firestore/driver.accessor.batch.js.map +1 -1
- package/src/lib/client/firestore/driver.accessor.default.js +2 -1
- package/src/lib/client/firestore/driver.accessor.default.js.map +1 -1
- package/src/lib/client/firestore/driver.accessor.transaction.d.ts +1 -1
- package/src/lib/client/firestore/driver.accessor.transaction.js +2 -1
- package/src/lib/client/firestore/driver.accessor.transaction.js.map +1 -1
- package/src/lib/client/firestore/driver.d.ts +1 -1
- package/src/lib/client/function/development.function.d.ts +1 -1
- package/src/lib/client/function/development.function.factory.d.ts +4 -4
- package/src/lib/client/function/error.js +4 -4
- package/src/lib/client/function/error.js.map +1 -1
- package/src/lib/client/function/function.callable.d.ts +1 -1
- package/src/lib/client/function/function.d.ts +6 -6
- package/src/lib/client/function/function.factory.d.ts +9 -9
- package/src/lib/client/function/model.function.factory.d.ts +29 -29
- package/src/lib/client/storage/driver.accessor.d.ts +2 -2
- package/src/lib/client/storage/driver.d.ts +1 -1
- package/src/lib/common/auth/auth.context.d.ts +1 -1
- package/src/lib/common/auth/auth.d.ts +3 -3
- package/src/lib/common/development/function.d.ts +2 -2
- package/src/lib/common/development/function.schedule.d.ts +2 -2
- package/src/lib/common/development/function.schedule.js +2 -2
- package/src/lib/common/development/function.schedule.js.map +1 -1
- package/src/lib/common/error.d.ts +1 -1
- package/src/lib/common/firestore/accessor/accessor.batch.d.ts +1 -1
- package/src/lib/common/firestore/accessor/accessor.d.ts +4 -4
- package/src/lib/common/firestore/accessor/accessor.default.d.ts +1 -1
- package/src/lib/common/firestore/accessor/accessor.js +1 -1
- package/src/lib/common/firestore/accessor/accessor.js.map +1 -1
- package/src/lib/common/firestore/accessor/accessor.transaction.d.ts +1 -1
- package/src/lib/common/firestore/accessor/accessor.wrap.d.ts +2 -2
- package/src/lib/common/firestore/accessor/accessor.wrap.modify.d.ts +2 -2
- package/src/lib/common/firestore/accessor/context.batch.d.ts +1 -1
- package/src/lib/common/firestore/accessor/context.default.d.ts +1 -1
- package/src/lib/common/firestore/accessor/context.js +1 -1
- package/src/lib/common/firestore/accessor/context.js.map +1 -1
- package/src/lib/common/firestore/accessor/context.transaction.d.ts +1 -1
- package/src/lib/common/firestore/accessor/converter.d.ts +2 -2
- package/src/lib/common/firestore/accessor/document.d.ts +9 -9
- package/src/lib/common/firestore/accessor/document.rxjs.d.ts +0 -10
- package/src/lib/common/firestore/accessor/document.rxjs.js +1 -21
- package/src/lib/common/firestore/accessor/document.rxjs.js.map +1 -1
- package/src/lib/common/firestore/accessor/document.utility.d.ts +9 -17
- package/src/lib/common/firestore/accessor/document.utility.js +5 -9
- package/src/lib/common/firestore/accessor/document.utility.js.map +1 -1
- package/src/lib/common/firestore/accessor/increment.d.ts +1 -1
- package/src/lib/common/firestore/collection/collection.d.ts +34 -28
- package/src/lib/common/firestore/collection/collection.js +11 -3
- package/src/lib/common/firestore/collection/collection.js.map +1 -1
- package/src/lib/common/firestore/collection/collection.key.d.ts +10 -10
- package/src/lib/common/firestore/collection/collection.query.d.ts +1 -1
- package/src/lib/common/firestore/collection/subcollection.d.ts +1 -1
- package/src/lib/common/firestore/collection/subcollection.single.d.ts +0 -8
- package/src/lib/common/firestore/collection/subcollection.single.js +1 -6
- package/src/lib/common/firestore/collection/subcollection.single.js.map +1 -1
- package/src/lib/common/firestore/context.d.ts +3 -3
- package/src/lib/common/firestore/driver/accessor.d.ts +6 -6
- package/src/lib/common/firestore/driver/batch.d.ts +2 -2
- package/src/lib/common/firestore/driver/driver.d.ts +2 -2
- package/src/lib/common/firestore/driver/query.d.ts +2 -2
- package/src/lib/common/firestore/driver/transaction.d.ts +4 -4
- package/src/lib/common/firestore/query/accumulator.d.ts +3 -3
- package/src/lib/common/firestore/query/constraint.d.ts +11 -11
- package/src/lib/common/firestore/query/constraint.js +1 -1
- package/src/lib/common/firestore/query/constraint.js.map +1 -1
- package/src/lib/common/firestore/query/constraint.template.d.ts +25 -5
- package/src/lib/common/firestore/query/constraint.template.js +13 -5
- package/src/lib/common/firestore/query/constraint.template.js.map +1 -1
- package/src/lib/common/firestore/query/index.d.ts +1 -0
- package/src/lib/common/firestore/query/index.js +1 -0
- package/src/lib/common/firestore/query/index.js.map +1 -1
- package/src/lib/common/firestore/query/iterator.d.ts +3 -3
- package/src/lib/common/firestore/query/iterator.js +1 -1
- package/src/lib/common/firestore/query/iterator.js.map +1 -1
- package/src/lib/common/firestore/query/query.d.ts +1 -1
- package/src/lib/common/firestore/query/query.iterate.d.ts +178 -0
- package/src/lib/common/firestore/query/query.iterate.js +158 -0
- package/src/lib/common/firestore/query/query.iterate.js.map +1 -0
- package/src/lib/common/firestore/query/query.util.d.ts +1 -1
- package/src/lib/common/firestore/query/watcher.d.ts +1 -1
- package/src/lib/common/firestore/snapshot/snapshot.field.d.ts +37 -104
- package/src/lib/common/firestore/snapshot/snapshot.field.js +12 -74
- package/src/lib/common/firestore/snapshot/snapshot.field.js.map +1 -1
- package/src/lib/common/firestore/snapshot/snapshot.type.d.ts +9 -9
- package/src/lib/common/firestore/types.d.ts +19 -19
- package/src/lib/common/firestore/util/id.batch.d.ts +5 -5
- package/src/lib/common/firestore/util/id.batch.js +1 -1
- package/src/lib/common/firestore/util/id.batch.js.map +1 -1
- package/src/lib/common/function/action.d.ts +8 -8
- package/src/lib/common/model/function.d.ts +4 -4
- package/src/lib/common/model/model/model.loader.d.ts +3 -3
- package/src/lib/common/model/model/model.param.js +4 -4
- package/src/lib/common/model/model/model.param.js.map +1 -1
- package/src/lib/common/model/model.service.d.ts +22 -22
- package/src/lib/common/model/permission/permission.context.d.ts +3 -3
- package/src/lib/common/model/permission/permission.d.ts +1 -1
- package/src/lib/common/model/permission/permission.service.d.ts +3 -3
- package/src/lib/common/model/permission/permission.service.grant.d.ts +9 -9
- package/src/lib/common/storage/accessor/path.model.d.ts +1 -1
- package/src/lib/common/storage/context.d.ts +1 -1
- package/src/lib/common/storage/driver/accessor.d.ts +3 -3
- package/src/lib/common/storage/driver/driver.d.ts +2 -2
- package/src/lib/common/storage/driver/list.d.ts +1 -1
- package/src/lib/common/storage/storage.d.ts +8 -8
- package/src/lib/common/storage/types.d.ts +24 -24
- package/src/lib/model/system/system.action.d.ts +6 -6
- package/src/lib/model/system/system.d.ts +8 -8
- package/src/lib/model/user.d.ts +2 -2
- package/test/CHANGELOG.md +12 -0
- package/test/package.json +2 -26
- package/test/src/lib/client/firebase.authorized.d.ts +1 -1
- package/test/src/lib/client/firebase.d.ts +3 -3
- package/test/src/lib/common/firebase.instance.d.ts +1 -1
- package/test/src/lib/common/firestore/firestore.d.ts +2 -2
- package/test/src/lib/common/firestore/firestore.instance.d.ts +1 -1
- package/test/src/lib/common/firestore/firestore.js +1 -1
- package/test/src/lib/common/firestore/firestore.js.map +1 -1
- package/test/src/lib/common/firestore/test.driver.query.js +115 -7
- package/test/src/lib/common/firestore/test.driver.query.js.map +1 -1
- package/test/src/lib/common/mock/index.d.ts +1 -0
- package/test/src/lib/common/mock/index.js +1 -0
- package/test/src/lib/common/mock/index.js.map +1 -1
- package/test/src/lib/common/mock/mock.item.collection.fixture.d.ts +1 -1
- package/test/src/lib/common/mock/mock.item.collection.fixture.js +4 -4
- package/test/src/lib/common/mock/mock.item.collection.fixture.js.map +1 -1
- package/test/src/lib/common/mock/mock.item.d.ts +25 -25
- package/test/src/lib/common/mock/mock.item.id.d.ts +2 -0
- package/test/src/lib/common/mock/mock.item.id.js +3 -0
- package/test/src/lib/common/mock/mock.item.id.js.map +1 -0
- package/test/src/lib/common/mock/mock.item.js +1 -1
- package/test/src/lib/common/mock/mock.item.js.map +1 -1
- package/test/src/lib/common/mock/mock.item.service.d.ts +4 -4
- package/test/src/lib/common/mock/mock.item.storage.fixture.d.ts +2 -2
- package/test/src/lib/common/storage/storage.d.ts +2 -2
- package/test/src/lib/common/storage/storage.instance.d.ts +1 -1
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { GetterOrValue, PromiseOrValue, IndexRef, Maybe, PerformAsyncTasksConfig, IndexNumber, PerformAsyncTasksResult } from '@dereekb/util';
|
|
2
|
+
import { FirestoreDocument, FirestoreDocumentSnapshotDataPair, LimitedFirestoreDocumentAccessor } from '../accessor';
|
|
3
|
+
import { QueryDocumentSnapshot, QuerySnapshot, DocumentSnapshot } from '../types';
|
|
4
|
+
import { FirestoreQueryConstraint } from './constraint';
|
|
5
|
+
import { FirestoreQueryFactory } from './query';
|
|
6
|
+
/**
|
|
7
|
+
* Config for iterateFirestoreDocumentSnapshots().
|
|
8
|
+
*/
|
|
9
|
+
export interface IterateFirestoreDocumentSnapshotPairsConfig<T, R, D extends FirestoreDocument<T> = FirestoreDocument<T>> extends Omit<IterateFirestoreDocumentSnapshotsConfig<T, R>, 'iterateSnapshot'> {
|
|
10
|
+
/**
|
|
11
|
+
* Document accessor to retrieve the documents for the references.
|
|
12
|
+
*/
|
|
13
|
+
readonly documentAccessor: LimitedFirestoreDocumentAccessor<T, D>;
|
|
14
|
+
/**
|
|
15
|
+
* The iterate function per each snapshot.
|
|
16
|
+
*/
|
|
17
|
+
iterateSnapshotPair(snapshot: FirestoreDocumentSnapshotDataPair<D>): Promise<R>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Iterates through the results of a Firestore query by each FirestoreDocumentSnapshotDataPair.
|
|
21
|
+
*
|
|
22
|
+
* @param config
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
export declare function iterateFirestoreDocumentSnapshotPairs<T, R, D extends FirestoreDocument<T> = FirestoreDocument<T>>(config: IterateFirestoreDocumentSnapshotPairsConfig<T, R>): Promise<IterateFirestoreDocumentSnapshotCheckpointsResult>;
|
|
26
|
+
/**
|
|
27
|
+
* Config for iterateFirestoreDocumentSnapshots().
|
|
28
|
+
*/
|
|
29
|
+
export interface IterateFirestoreDocumentSnapshotsConfig<T, R> extends Omit<IterateFirestoreDocumentSnapshotBatchesConfig<T, IterateFirestoreDocumentSnapshotsResult<T, R>>, 'iterateSnapshotBatch'> {
|
|
30
|
+
/**
|
|
31
|
+
* The iterate function per each snapshot individually
|
|
32
|
+
*/
|
|
33
|
+
iterateSnapshot(snapshot: QueryDocumentSnapshot<T>): Promise<R>;
|
|
34
|
+
/**
|
|
35
|
+
* (Optional) Additional config for the snapshot's PerformAsyncTasks call. By default user the performTasksConfig value.
|
|
36
|
+
*/
|
|
37
|
+
readonly snapshotsPerformTasksConfig?: Partial<PerformAsyncTasksConfig>;
|
|
38
|
+
}
|
|
39
|
+
export type IterateFirestoreDocumentSnapshotsResult<T, R> = PerformAsyncTasksResult<QueryDocumentSnapshot<T>, R>;
|
|
40
|
+
/**
|
|
41
|
+
* Iterates through the results of a Firestore query by each document snapshot by itself.
|
|
42
|
+
*
|
|
43
|
+
* @param config
|
|
44
|
+
* @returns
|
|
45
|
+
*/
|
|
46
|
+
export declare function iterateFirestoreDocumentSnapshots<T, R>(config: IterateFirestoreDocumentSnapshotsConfig<T, R>): Promise<IterateFirestoreDocumentSnapshotCheckpointsResult>;
|
|
47
|
+
/**
|
|
48
|
+
* Config for iterateFirestoreDocumentSnapshots().
|
|
49
|
+
*/
|
|
50
|
+
export interface IterateFirestoreDocumentSnapshotPairBatchesConfig<T, R, D extends FirestoreDocument<T> = FirestoreDocument<T>> extends Omit<IterateFirestoreDocumentSnapshotBatchesConfig<T, R>, 'iterateSnapshotBatch'> {
|
|
51
|
+
/**
|
|
52
|
+
* Document accessor to retrieve the documents for the references.
|
|
53
|
+
*/
|
|
54
|
+
readonly documentAccessor: LimitedFirestoreDocumentAccessor<T, D>;
|
|
55
|
+
/**
|
|
56
|
+
* The iterate function per each snapshot batch.
|
|
57
|
+
*/
|
|
58
|
+
iterateSnapshotPairsBatch(snapshotDataPairs: FirestoreDocumentSnapshotDataPair<D>[]): Promise<R>;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Iterates through the results of a Firestore query by each FirestoreDocumentSnapshotDataPair.
|
|
62
|
+
*
|
|
63
|
+
* @param config
|
|
64
|
+
* @returns
|
|
65
|
+
*/
|
|
66
|
+
export declare function iterateFirestoreDocumentSnapshotPairBatches<T, R, D extends FirestoreDocument<T> = FirestoreDocument<T>>(config: IterateFirestoreDocumentSnapshotPairBatchesConfig<T, R>): Promise<IterateFirestoreDocumentSnapshotCheckpointsResult>;
|
|
67
|
+
/**
|
|
68
|
+
* Single batch result from iterateFirestoreDocumentSnapshotBatches().
|
|
69
|
+
*
|
|
70
|
+
* Contains the batch index, the snapshots, and the final result for this batch.
|
|
71
|
+
*/
|
|
72
|
+
export interface IterateFirestoreDocumentSnapshotBatchesResult<T, R> extends IndexRef {
|
|
73
|
+
/***
|
|
74
|
+
* Batch index number
|
|
75
|
+
*/
|
|
76
|
+
readonly i: IndexNumber;
|
|
77
|
+
/**
|
|
78
|
+
* Document snapshots in this batch.
|
|
79
|
+
*/
|
|
80
|
+
readonly snapshots: QueryDocumentSnapshot<T>[];
|
|
81
|
+
/**
|
|
82
|
+
* Result for this batch.
|
|
83
|
+
*/
|
|
84
|
+
readonly result: R;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Config for iterateFirestoreDocumentSnapshots().
|
|
88
|
+
*/
|
|
89
|
+
export interface IterateFirestoreDocumentSnapshotBatchesConfig<T, R> extends Omit<IterateFirestoreDocumentSnapshotCheckpointsConfig<T, IterateFirestoreDocumentSnapshotBatchesResult<T, R>>, 'iterateCheckpoint'> {
|
|
90
|
+
/**
|
|
91
|
+
* Max number of documents per batch. Defaults to 25.
|
|
92
|
+
*/
|
|
93
|
+
readonly batchSize?: Maybe<number>;
|
|
94
|
+
/**
|
|
95
|
+
* The iterate function per each snapshot.
|
|
96
|
+
*/
|
|
97
|
+
iterateSnapshotBatch(snapshotBatch: QueryDocumentSnapshot<T>[], batchIndex: number): Promise<R>;
|
|
98
|
+
/**
|
|
99
|
+
* (Optional) additional config for the PerformAsyncTasks call.
|
|
100
|
+
*
|
|
101
|
+
* By default:
|
|
102
|
+
* - retriesAllowed = 0
|
|
103
|
+
* - throwError = true
|
|
104
|
+
* - sequential = true
|
|
105
|
+
*/
|
|
106
|
+
readonly performTasksConfig?: Partial<PerformAsyncTasksConfig>;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Default batch size for iterateFirestoreDocumentSnapshotBatches().
|
|
110
|
+
*
|
|
111
|
+
* 25 documents per batch.
|
|
112
|
+
*/
|
|
113
|
+
export declare const DEFAULT_ITERATE_FIRESTORE_DOCUMENT_SNAPSHOT_BATCHES_BATCH_SIZE = 25;
|
|
114
|
+
/**
|
|
115
|
+
* Iterates through the results of a Firestore query by each document snapshot.
|
|
116
|
+
*
|
|
117
|
+
* @param config
|
|
118
|
+
* @returns
|
|
119
|
+
*/
|
|
120
|
+
export declare function iterateFirestoreDocumentSnapshotBatches<T, R>(config: IterateFirestoreDocumentSnapshotBatchesConfig<T, R>): Promise<IterateFirestoreDocumentSnapshotCheckpointsResult>;
|
|
121
|
+
/**
|
|
122
|
+
* Config for iterateFirestoreDocumentSnapshotCheckpoints().
|
|
123
|
+
*/
|
|
124
|
+
export interface IterateFirestoreDocumentSnapshotCheckpointsConfig<T, R> {
|
|
125
|
+
readonly queryFactory: FirestoreQueryFactory<T>;
|
|
126
|
+
readonly constraintsFactory: GetterOrValue<FirestoreQueryConstraint[]>;
|
|
127
|
+
/**
|
|
128
|
+
* Convenience paramenter to add a limit constraint to the query.
|
|
129
|
+
*/
|
|
130
|
+
readonly limitPerCheckpoint?: number;
|
|
131
|
+
/**
|
|
132
|
+
* The total number of snapshots allowed. Ends on the checkpoint that
|
|
133
|
+
*/
|
|
134
|
+
readonly totalSnapshotsLimit?: number;
|
|
135
|
+
/**
|
|
136
|
+
* The iterate function per each snapshot.
|
|
137
|
+
*/
|
|
138
|
+
iterateCheckpoint(snapshot: QueryDocumentSnapshot<T>[], query: QuerySnapshot<T>): Promise<R[]>;
|
|
139
|
+
/**
|
|
140
|
+
* (Optional) Called at the end of each checkpoint.
|
|
141
|
+
*/
|
|
142
|
+
useCheckpointResult?(checkpointResults: IterateFirestoreDocumentSnapshotCheckpointsIterationResult<T, R>): PromiseOrValue<void>;
|
|
143
|
+
}
|
|
144
|
+
export interface IterateFirestoreDocumentSnapshotCheckpointsIterationResult<T, R> extends IndexRef {
|
|
145
|
+
/***
|
|
146
|
+
* Checkpoint index number
|
|
147
|
+
*/
|
|
148
|
+
readonly i: IndexNumber;
|
|
149
|
+
/**
|
|
150
|
+
* The cursor document used in this query.
|
|
151
|
+
*/
|
|
152
|
+
readonly cursorDocument?: Maybe<DocumentSnapshot<T>>;
|
|
153
|
+
/**
|
|
154
|
+
* Results returned from each checkpoint.
|
|
155
|
+
*/
|
|
156
|
+
readonly results: R[];
|
|
157
|
+
/**
|
|
158
|
+
* All document snapshots in this checkpoint.
|
|
159
|
+
*/
|
|
160
|
+
readonly docSnapshots: QueryDocumentSnapshot<T>[];
|
|
161
|
+
}
|
|
162
|
+
export interface IterateFirestoreDocumentSnapshotCheckpointsResult {
|
|
163
|
+
/**
|
|
164
|
+
* The total number of batches visited.
|
|
165
|
+
*/
|
|
166
|
+
readonly totalCheckpoints: number;
|
|
167
|
+
/**
|
|
168
|
+
* The total number of snapshots that were visited.
|
|
169
|
+
*/
|
|
170
|
+
readonly totalSnapshotsVisited: number;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Iterates through the results of a Firestore query in several batches.
|
|
174
|
+
*
|
|
175
|
+
* @param config
|
|
176
|
+
* @returns
|
|
177
|
+
*/
|
|
178
|
+
export declare function iterateFirestoreDocumentSnapshotCheckpoints<T, R>(config: IterateFirestoreDocumentSnapshotCheckpointsConfig<T, R>): Promise<IterateFirestoreDocumentSnapshotCheckpointsResult>;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.iterateFirestoreDocumentSnapshotCheckpoints = exports.iterateFirestoreDocumentSnapshotBatches = exports.DEFAULT_ITERATE_FIRESTORE_DOCUMENT_SNAPSHOT_BATCHES_BATCH_SIZE = exports.iterateFirestoreDocumentSnapshotPairBatches = exports.iterateFirestoreDocumentSnapshots = exports.iterateFirestoreDocumentSnapshotPairs = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const util_1 = require("@dereekb/util");
|
|
6
|
+
const accessor_1 = require("../accessor");
|
|
7
|
+
const constraint_1 = require("./constraint");
|
|
8
|
+
/**
|
|
9
|
+
* Iterates through the results of a Firestore query by each FirestoreDocumentSnapshotDataPair.
|
|
10
|
+
*
|
|
11
|
+
* @param config
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
function iterateFirestoreDocumentSnapshotPairs(config) {
|
|
15
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const { iterateSnapshotPair, documentAccessor } = config;
|
|
17
|
+
return iterateFirestoreDocumentSnapshots(Object.assign(Object.assign({}, config), { iterateSnapshot: (snapshot) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
const document = documentAccessor.loadDocument(snapshot.ref);
|
|
19
|
+
const data = (0, accessor_1.documentDataWithIdAndKey)(snapshot);
|
|
20
|
+
const pair = {
|
|
21
|
+
document,
|
|
22
|
+
snapshot,
|
|
23
|
+
data
|
|
24
|
+
};
|
|
25
|
+
return iterateSnapshotPair(pair);
|
|
26
|
+
}) }));
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
exports.iterateFirestoreDocumentSnapshotPairs = iterateFirestoreDocumentSnapshotPairs;
|
|
30
|
+
/**
|
|
31
|
+
* Iterates through the results of a Firestore query by each document snapshot by itself.
|
|
32
|
+
*
|
|
33
|
+
* @param config
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
function iterateFirestoreDocumentSnapshots(config) {
|
|
37
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
const { iterateSnapshot, performTasksConfig, snapshotsPerformTasksConfig } = config;
|
|
39
|
+
return iterateFirestoreDocumentSnapshotBatches(Object.assign(Object.assign({}, config), { iterateSnapshotBatch: (docSnapshots) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
const performTasksResult = yield (0, util_1.performAsyncTasks)(docSnapshots, iterateSnapshot, Object.assign({ sequential: true }, (snapshotsPerformTasksConfig !== null && snapshotsPerformTasksConfig !== void 0 ? snapshotsPerformTasksConfig : performTasksConfig)));
|
|
41
|
+
return performTasksResult;
|
|
42
|
+
}) }));
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
exports.iterateFirestoreDocumentSnapshots = iterateFirestoreDocumentSnapshots;
|
|
46
|
+
/**
|
|
47
|
+
* Iterates through the results of a Firestore query by each FirestoreDocumentSnapshotDataPair.
|
|
48
|
+
*
|
|
49
|
+
* @param config
|
|
50
|
+
* @returns
|
|
51
|
+
*/
|
|
52
|
+
function iterateFirestoreDocumentSnapshotPairBatches(config) {
|
|
53
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
const { iterateSnapshotPairsBatch, documentAccessor } = config;
|
|
55
|
+
return iterateFirestoreDocumentSnapshotBatches(Object.assign(Object.assign({}, config), { iterateSnapshotBatch: (snapshots) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
const pairs = snapshots.map((snapshot) => {
|
|
57
|
+
const document = documentAccessor.loadDocument(snapshot.ref);
|
|
58
|
+
const data = (0, accessor_1.documentDataWithIdAndKey)(snapshot);
|
|
59
|
+
const pair = {
|
|
60
|
+
document,
|
|
61
|
+
snapshot,
|
|
62
|
+
data
|
|
63
|
+
};
|
|
64
|
+
return pair;
|
|
65
|
+
});
|
|
66
|
+
return iterateSnapshotPairsBatch(pairs);
|
|
67
|
+
}) }));
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
exports.iterateFirestoreDocumentSnapshotPairBatches = iterateFirestoreDocumentSnapshotPairBatches;
|
|
71
|
+
/**
|
|
72
|
+
* Default batch size for iterateFirestoreDocumentSnapshotBatches().
|
|
73
|
+
*
|
|
74
|
+
* 25 documents per batch.
|
|
75
|
+
*/
|
|
76
|
+
exports.DEFAULT_ITERATE_FIRESTORE_DOCUMENT_SNAPSHOT_BATCHES_BATCH_SIZE = 25;
|
|
77
|
+
/**
|
|
78
|
+
* Iterates through the results of a Firestore query by each document snapshot.
|
|
79
|
+
*
|
|
80
|
+
* @param config
|
|
81
|
+
* @returns
|
|
82
|
+
*/
|
|
83
|
+
function iterateFirestoreDocumentSnapshotBatches(config) {
|
|
84
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
const { iterateSnapshotBatch, performTasksConfig, batchSize: inputBatchSize } = config;
|
|
86
|
+
const batchSize = inputBatchSize !== null && inputBatchSize !== void 0 ? inputBatchSize : exports.DEFAULT_ITERATE_FIRESTORE_DOCUMENT_SNAPSHOT_BATCHES_BATCH_SIZE;
|
|
87
|
+
return iterateFirestoreDocumentSnapshotCheckpoints(Object.assign(Object.assign({}, config), { iterateCheckpoint: (docSnapshots) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
const batches = (0, util_1.batch)(docSnapshots, batchSize);
|
|
89
|
+
let i = 0;
|
|
90
|
+
const performTasksResult = yield (0, util_1.performAsyncTasks)(batches, (x) => iterateSnapshotBatch(x, i++), Object.assign({ sequential: true }, performTasksConfig));
|
|
91
|
+
return performTasksResult.results.map(([snapshots, result], i) => ({ snapshots, result, i }));
|
|
92
|
+
}) }));
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
exports.iterateFirestoreDocumentSnapshotBatches = iterateFirestoreDocumentSnapshotBatches;
|
|
96
|
+
/**
|
|
97
|
+
* Iterates through the results of a Firestore query in several batches.
|
|
98
|
+
*
|
|
99
|
+
* @param config
|
|
100
|
+
* @returns
|
|
101
|
+
*/
|
|
102
|
+
function iterateFirestoreDocumentSnapshotCheckpoints(config) {
|
|
103
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
const { iterateCheckpoint, useCheckpointResult, constraintsFactory: inputConstraintsFactory, queryFactory, limitPerCheckpoint, totalSnapshotsLimit = Number.MAX_SAFE_INTEGER } = config;
|
|
105
|
+
const constraintsFactory = (0, util_1.asGetter)(inputConstraintsFactory);
|
|
106
|
+
let i = 0;
|
|
107
|
+
function iterateFromCursor(cursorDocument) {
|
|
108
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
const constraints = constraintsFactory();
|
|
110
|
+
const startAfterFilter = cursorDocument ? (0, constraint_1.startAfter)(cursorDocument) : undefined;
|
|
111
|
+
if (startAfterFilter) {
|
|
112
|
+
constraints.push(startAfterFilter);
|
|
113
|
+
}
|
|
114
|
+
if (limitPerCheckpoint) {
|
|
115
|
+
constraints.push((0, constraint_1.limit)(limitPerCheckpoint));
|
|
116
|
+
}
|
|
117
|
+
const query = queryFactory.query(constraints);
|
|
118
|
+
const docQuerySnapshot = yield query.getDocs();
|
|
119
|
+
const docSnapshots = docQuerySnapshot.docs;
|
|
120
|
+
const results = yield iterateCheckpoint(docSnapshots, docQuerySnapshot);
|
|
121
|
+
const checkpointResults = {
|
|
122
|
+
i,
|
|
123
|
+
cursorDocument,
|
|
124
|
+
results,
|
|
125
|
+
docSnapshots
|
|
126
|
+
};
|
|
127
|
+
return checkpointResults;
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
let cursorDocument;
|
|
131
|
+
let totalSnapshotsVisited = 0;
|
|
132
|
+
while (true) {
|
|
133
|
+
const iterateResults = yield iterateFromCursor(cursorDocument);
|
|
134
|
+
yield (useCheckpointResult === null || useCheckpointResult === void 0 ? void 0 : useCheckpointResult(iterateResults));
|
|
135
|
+
const newSnapshotsVisited = iterateResults.docSnapshots.length;
|
|
136
|
+
const hasResults = newSnapshotsVisited > 0;
|
|
137
|
+
if (hasResults) {
|
|
138
|
+
cursorDocument = hasResults ? (0, util_1.lastValue)(iterateResults.docSnapshots) : undefined;
|
|
139
|
+
i += 1;
|
|
140
|
+
totalSnapshotsVisited += newSnapshotsVisited;
|
|
141
|
+
// if at the limit, bail out
|
|
142
|
+
if (totalSnapshotsVisited > totalSnapshotsLimit) {
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
const result = {
|
|
151
|
+
totalCheckpoints: i,
|
|
152
|
+
totalSnapshotsVisited
|
|
153
|
+
};
|
|
154
|
+
return result;
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
exports.iterateFirestoreDocumentSnapshotCheckpoints = iterateFirestoreDocumentSnapshotCheckpoints;
|
|
158
|
+
//# sourceMappingURL=query.iterate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.iterate.js","sourceRoot":"","sources":["../../../../../../../../packages/firebase/src/lib/common/firestore/query/query.iterate.ts"],"names":[],"mappings":";;;;AAAA,wCAA6L;AAC7L,0CAA+I;AAE/I,6CAA2E;AAkB3E;;;;;GAKG;AACH,SAAsB,qCAAqC,CAA8D,MAAyD;;QAChL,MAAM,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,GAAG,MAAM,CAAC;QACzD,OAAO,iCAAiC,iCACnC,MAAM,KACT,eAAe,EAAE,CAAO,QAAQ,EAAE,EAAE;gBAClC,MAAM,QAAQ,GAAG,gBAAgB,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAM,CAAC;gBAClE,MAAM,IAAI,GAAG,IAAA,mCAAwB,EAAC,QAAQ,CAAC,CAAC;gBAChD,MAAM,IAAI,GAAG;oBACX,QAAQ;oBACR,QAAQ;oBACR,IAAI;iBACL,CAAC;gBAEF,OAAO,mBAAmB,CAAC,IAAI,CAAC,CAAC;YACnC,CAAC,CAAA,IACD,CAAC;IACL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AC,CAAC;gBACP,qBAAqB,IAAI,mBAAmB,CAAC;gBAE7C,4BAA4B;gBAC5B,IAAI,qBAAqB,GAAG,mBAAmB,EAAE;oBAC/C,MAAM;iBACP;aACF;iBAAM;gBACL,MAAM;aACP;SACF;QAED,MAAM,MAAM,GAAsD;YAChE,gBAAgB,EAAE,CAAC;YACnB,qBAAqB;SACtB,CAAC;QAEF,OAAO,MAAM,CAAC;IAChB,CAAC;CAAA;AAhED,kGAgEC"}
|
|
@@ -5,7 +5,7 @@ export interface StreamDocsWithOnSnapshotFunctionParams<O> {
|
|
|
5
5
|
error: (err?: unknown) => void;
|
|
6
6
|
complete: () => void;
|
|
7
7
|
}
|
|
8
|
-
export
|
|
8
|
+
export type StreamDocsUnsubscribeFunction = () => void;
|
|
9
9
|
/**
|
|
10
10
|
* Use to build an Observable that reacts to OnSnapshot events from queries.
|
|
11
11
|
*
|
|
@@ -29,6 +29,6 @@ export interface IterationQueryDocChangeWatcherChangeGroup<T = unknown> {
|
|
|
29
29
|
readonly removed: DocumentChange<T>[];
|
|
30
30
|
readonly modified: DocumentChange<T>[];
|
|
31
31
|
}
|
|
32
|
-
export
|
|
32
|
+
export type IterationQueryDocChangeWatcherChangeType = 'addedAndRemoved' | 'added' | 'removed' | 'modified' | 'none';
|
|
33
33
|
export declare function iterationQueryDocChangeWatcher<T = unknown>(config: IterationQueryDocChangeWatcherConfig<T>): IterationQueryDocChangeWatcher<T>;
|
|
34
34
|
export declare function iterationQueryDocChangeWatcherChangeTypeForGroup<T = unknown>(group: IterationQueryDocChangeWatcherChangeGroup<T>): IterationQueryDocChangeWatcherChangeType;
|