@dereekb/firebase 11.1.8 → 12.0.1
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/index.cjs.js +3749 -2018
- package/index.esm.d.ts +1 -0
- package/index.esm.js +3673 -3107
- package/package.json +7 -6
- package/src/lib/common/firestore/accessor/accessor.batch.d.ts +12 -0
- package/src/lib/common/firestore/accessor/accessor.d.ts +90 -30
- package/src/lib/common/firestore/accessor/accessor.default.d.ts +14 -0
- package/src/lib/common/firestore/accessor/accessor.transaction.d.ts +15 -0
- package/src/lib/common/firestore/accessor/accessor.wrap.d.ts +107 -2
- package/src/lib/common/firestore/accessor/context.batch.d.ts +31 -0
- package/src/lib/common/firestore/accessor/context.d.ts +28 -5
- package/src/lib/common/firestore/accessor/context.default.d.ts +21 -0
- package/src/lib/common/firestore/accessor/context.transaction.d.ts +31 -0
- package/src/lib/common/firestore/accessor/converter.d.ts +28 -3
- package/src/lib/common/firestore/accessor/document.rxjs.d.ts +37 -0
- package/src/lib/common/firestore/accessor/document.utility.d.ts +129 -8
- package/src/lib/common/firestore/collection/collection.d.ts +116 -8
- package/src/lib/common/firestore/collection/collection.group.d.ts +38 -3
- package/src/lib/common/firestore/collection/collection.key.d.ts +62 -2
- package/src/lib/common/firestore/collection/collection.query.d.ts +168 -8
- package/src/lib/common/firestore/collection/collection.single.d.ts +33 -0
- package/src/lib/common/firestore/collection/subcollection.d.ts +70 -5
- package/src/lib/common/firestore/collection/subcollection.single.d.ts +40 -0
- package/src/lib/common/firestore/context.d.ts +154 -5
- package/src/lib/common/firestore/query/accumulator.d.ts +78 -5
- package/src/lib/common/firestore/query/constraint.d.ts +401 -15
- package/src/lib/common/firestore/query/constraint.template.d.ts +133 -40
- package/src/lib/common/firestore/query/iterator.d.ts +200 -14
- package/src/lib/common/firestore/query/query.d.ts +120 -11
- package/src/lib/common/firestore/query/query.iterate.array.d.ts +113 -9
- package/src/lib/common/firestore/query/query.iterate.d.ts +136 -13
- package/src/lib/common/firestore/query/query.util.d.ts +74 -7
- package/src/lib/common/firestore/query/watcher.d.ts +133 -2
- package/src/lib/common/firestore/snapshot/snapshot.d.ts +26 -0
- package/src/lib/common/firestore/snapshot/snapshot.field.d.ts +513 -3
- package/src/lib/common/firestore/snapshot/snapshot.type.d.ts +86 -5
- package/src/lib/common/model/function.d.ts +1 -1
- package/src/lib/common/storage/driver/accessor.d.ts +0 -1
- package/src/lib/common/storage/types.d.ts +0 -1
- package/test/CHANGELOG.md +13 -0
- package/test/package.json +3 -2
- package/test/src/lib/client/firebase.authorized.d.ts +2 -2
- package/test/src/lib/client/firebase.authorized.js.map +1 -1
- package/test/src/lib/client/firebase.d.ts +13 -13
- package/test/src/lib/client/firebase.js +4 -4
- package/test/src/lib/client/firebase.js.map +1 -1
- package/test/src/lib/client/firestore.mock.item.fixture.authorized.d.ts +2 -2
- package/test/src/lib/common/firebase.instance.d.ts +6 -6
- package/test/src/lib/common/firebase.instance.js.map +1 -1
- package/test/src/lib/common/firestore/firestore.d.ts +1 -1
- package/test/src/lib/common/firestore/firestore.instance.d.ts +3 -3
- package/test/src/lib/common/firestore/firestore.instance.js.map +1 -1
- package/test/src/lib/common/firestore/firestore.js +3 -4
- package/test/src/lib/common/firestore/firestore.js.map +1 -1
- package/test/src/lib/common/firestore/test.driver.accessor.d.ts +3 -3
- package/test/src/lib/common/firestore/test.driver.accessor.js +5 -6
- package/test/src/lib/common/firestore/test.driver.accessor.js.map +1 -1
- package/test/src/lib/common/firestore/test.driver.query.d.ts +1 -1
- package/test/src/lib/common/firestore/test.driver.query.js +14 -10
- package/test/src/lib/common/firestore/test.driver.query.js.map +1 -1
- package/test/src/lib/common/firestore/test.iterator.d.ts +1 -1
- package/test/src/lib/common/firestore/test.iterator.js +1 -2
- package/test/src/lib/common/firestore/test.iterator.js.map +1 -1
- package/test/src/lib/common/mock/mock.item.collection.fixture.d.ts +5 -5
- package/test/src/lib/common/mock/mock.item.collection.fixture.js +2 -2
- package/test/src/lib/common/mock/mock.item.collection.fixture.js.map +1 -1
- package/test/src/lib/common/mock/mock.item.d.ts +5 -5
- package/test/src/lib/common/mock/mock.item.id.d.ts +1 -1
- package/test/src/lib/common/mock/mock.item.js +19 -19
- package/test/src/lib/common/mock/mock.item.js.map +1 -1
- package/test/src/lib/common/mock/mock.item.query.d.ts +2 -2
- package/test/src/lib/common/mock/mock.item.query.js +3 -4
- package/test/src/lib/common/mock/mock.item.query.js.map +1 -1
- package/test/src/lib/common/mock/mock.item.service.d.ts +3 -3
- package/test/src/lib/common/mock/mock.item.service.js +2 -2
- package/test/src/lib/common/mock/mock.item.service.js.map +1 -1
- package/test/src/lib/common/mock/mock.item.storage.fixture.d.ts +4 -4
- package/test/src/lib/common/mock/mock.item.storage.fixture.js +2 -2
- package/test/src/lib/common/mock/mock.item.storage.fixture.js.map +1 -1
- package/test/src/lib/common/storage/storage.d.ts +1 -1
- package/test/src/lib/common/storage/storage.instance.d.ts +3 -3
- package/test/src/lib/common/storage/storage.instance.js.map +1 -1
- package/test/src/lib/common/storage/storage.js +2 -3
- package/test/src/lib/common/storage/storage.js.map +1 -1
- package/test/src/lib/common/storage/test.driver.accessor.d.ts +1 -1
- package/test/src/lib/common/storage/test.driver.accessor.js +1 -2
- package/test/src/lib/common/storage/test.driver.accessor.js.map +1 -1
|
@@ -1,24 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Firestore Query Utilities
|
|
3
|
+
*
|
|
4
|
+
* This module provides utility functions for working with Firestore queries and documents,
|
|
5
|
+
* including reactive stream helpers and document reference utilities.
|
|
6
|
+
*/
|
|
1
7
|
import { type FirestoreModelKey } from '../collection';
|
|
2
8
|
import { type DocumentReference, type QuerySnapshot, type DocumentSnapshot } from './../types';
|
|
3
9
|
import { Observable } from 'rxjs';
|
|
10
|
+
/**
|
|
11
|
+
* Parameters for the Firestore onSnapshot callback handler.
|
|
12
|
+
*
|
|
13
|
+
* This interface mirrors the standard Observer pattern with next, error, and complete
|
|
14
|
+
* callbacks used in RxJS, allowing for easy conversion of Firestore snapshot events to
|
|
15
|
+
* Observable streams.
|
|
16
|
+
*
|
|
17
|
+
* @template O - The type of output value to emit in the stream
|
|
18
|
+
*/
|
|
4
19
|
export interface StreamDocsWithOnSnapshotFunctionParams<O> {
|
|
5
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Handler for new values in the stream.
|
|
22
|
+
*
|
|
23
|
+
* @param value - The new value to emit
|
|
24
|
+
*/
|
|
25
|
+
readonly next: (value: O) => void;
|
|
26
|
+
/**
|
|
27
|
+
* Handler for errors in the stream.
|
|
28
|
+
*
|
|
29
|
+
* @param err - The error that occurred, if any
|
|
30
|
+
*/
|
|
6
31
|
readonly error: (err?: unknown) => void;
|
|
32
|
+
/**
|
|
33
|
+
* Handler for stream completion.
|
|
34
|
+
*/
|
|
7
35
|
readonly complete: () => void;
|
|
8
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Function to unsubscribe from a Firestore snapshot listener.
|
|
39
|
+
*
|
|
40
|
+
* This function is returned when setting up a snapshot listener and can be called
|
|
41
|
+
* to stop receiving updates and clean up resources.
|
|
42
|
+
*/
|
|
9
43
|
export type StreamDocsUnsubscribeFunction = () => void;
|
|
10
44
|
/**
|
|
11
|
-
*
|
|
45
|
+
* Creates an Observable that wraps a Firestore onSnapshot listener.
|
|
46
|
+
*
|
|
47
|
+
* This utility function bridges the gap between Firestore's callback-based API
|
|
48
|
+
* and RxJS's reactive streams, allowing for seamless integration of Firestore
|
|
49
|
+
* query results into reactive applications.
|
|
12
50
|
*
|
|
13
|
-
* @
|
|
14
|
-
* @
|
|
51
|
+
* @template O - The type of output value to emit in the Observable
|
|
52
|
+
* @param callOnSnapshot - Function that sets up the Firestore snapshot listener
|
|
53
|
+
* and returns an unsubscribe function
|
|
54
|
+
* @returns An Observable that emits values from the Firestore snapshot listener
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* // Create a reactive stream from a Firestore query
|
|
58
|
+
* const usersStream = streamFromOnSnapshot(params => {
|
|
59
|
+
* return collection(firestore, 'users')
|
|
60
|
+
* .where('status', '==', 'active')
|
|
61
|
+
* .onSnapshot(
|
|
62
|
+
* snapshot => params.next(snapshot),
|
|
63
|
+
* error => params.error(error),
|
|
64
|
+
* () => params.complete()
|
|
65
|
+
* );
|
|
66
|
+
* });
|
|
15
67
|
*/
|
|
16
68
|
export declare function streamFromOnSnapshot<O>(callOnSnapshot: (params: StreamDocsWithOnSnapshotFunctionParams<O>) => StreamDocsUnsubscribeFunction): Observable<O>;
|
|
69
|
+
/**
|
|
70
|
+
* Extracts document references from a query snapshot.
|
|
71
|
+
*
|
|
72
|
+
* This utility function converts a Firestore QuerySnapshot into an array of
|
|
73
|
+
* DocumentReference objects, making it easier to work with the references
|
|
74
|
+
* to the documents that matched a query.
|
|
75
|
+
*
|
|
76
|
+
* @template T - The document data type
|
|
77
|
+
* @param snapshots - The query snapshot containing document snapshots
|
|
78
|
+
* @returns Array of document references extracted from the snapshot
|
|
79
|
+
*/
|
|
17
80
|
export declare function documentReferencesFromSnapshot<T>(snapshots: QuerySnapshot<T>): DocumentReference<T>[];
|
|
18
81
|
/**
|
|
19
|
-
*
|
|
82
|
+
* Extracts the Firestore model key (document path) from a document snapshot.
|
|
83
|
+
*
|
|
84
|
+
* This function returns the full path of the document as the model key,
|
|
85
|
+
* which uniquely identifies the document within Firestore. This is useful
|
|
86
|
+
* for tracking documents across queries and preventing duplicate processing.
|
|
20
87
|
*
|
|
21
|
-
* @param snapshot
|
|
22
|
-
* @returns
|
|
88
|
+
* @param snapshot - The document snapshot to extract the key from
|
|
89
|
+
* @returns The document's full path as a FirestoreModelKey
|
|
23
90
|
*/
|
|
24
91
|
export declare function readFirestoreModelKeyFromDocumentSnapshot(snapshot: DocumentSnapshot<any>): FirestoreModelKey;
|
|
@@ -1,34 +1,165 @@
|
|
|
1
1
|
import { type Observable } from 'rxjs';
|
|
2
2
|
import { type DocumentChange, type QuerySnapshot } from '../types';
|
|
3
3
|
import { type FirestoreItemPageIterationInstance } from './iterator';
|
|
4
|
+
/**
|
|
5
|
+
* Default delay in milliseconds before a query change watcher begins processing events.
|
|
6
|
+
*
|
|
7
|
+
* A value of 0 means the watcher will start immediately after the first successful page result.
|
|
8
|
+
*/
|
|
4
9
|
export declare const DEFAULT_QUERY_CHANGE_WATCHER_DELAY = 0;
|
|
10
|
+
/**
|
|
11
|
+
* Configuration for creating a query document change watcher.
|
|
12
|
+
*
|
|
13
|
+
* @template T - The document data type
|
|
14
|
+
*/
|
|
5
15
|
export interface IterationQueryDocChangeWatcherConfig<T = unknown> {
|
|
16
|
+
/**
|
|
17
|
+
* The iteration instance that will be watched for changes.
|
|
18
|
+
*
|
|
19
|
+
* This instance provides access to the underlying Firestore query and its results,
|
|
20
|
+
* which the watcher will monitor for document changes.
|
|
21
|
+
*/
|
|
6
22
|
readonly instance: FirestoreItemPageIterationInstance<T>;
|
|
23
|
+
/**
|
|
24
|
+
* Optional delay in milliseconds before the watcher begins processing events.
|
|
25
|
+
*
|
|
26
|
+
* This delay is applied after the first successful page result is received.
|
|
27
|
+
* Default is 0 (start immediately).
|
|
28
|
+
*/
|
|
7
29
|
readonly delay?: number;
|
|
8
30
|
}
|
|
9
31
|
/**
|
|
10
32
|
* Interface for watching query result changes events.
|
|
33
|
+
*
|
|
34
|
+
* Provides observables for monitoring changes to Firestore query results over time,
|
|
35
|
+
* including document additions, modifications, and removals.
|
|
36
|
+
*
|
|
37
|
+
* @template T - The document data type
|
|
11
38
|
*/
|
|
12
39
|
export interface IterationQueryDocChangeWatcher<T = unknown> {
|
|
13
40
|
/**
|
|
14
|
-
* Streams all subsequent query
|
|
41
|
+
* Streams all subsequent query snapshots after the initial result.
|
|
42
|
+
*
|
|
43
|
+
* This observable emits the raw QuerySnapshot objects from Firestore,
|
|
44
|
+
* allowing direct access to all query results and their changes.
|
|
15
45
|
*/
|
|
16
46
|
readonly stream$: Observable<QuerySnapshot<T>>;
|
|
17
47
|
/**
|
|
18
|
-
*
|
|
48
|
+
* Streams processed change events derived from the query snapshots.
|
|
49
|
+
*
|
|
50
|
+
* This observable transforms the raw query snapshots into structured event
|
|
51
|
+
* objects that categorize document changes into added, removed, and modified
|
|
52
|
+
* groups, making it easier to respond to specific types of changes.
|
|
19
53
|
*/
|
|
20
54
|
readonly event$: Observable<IterationQueryDocChangeWatcherEvent<T>>;
|
|
21
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Event representing a set of changes to a Firestore query result.
|
|
58
|
+
*
|
|
59
|
+
* This event captures all document changes that occurred in a single update,
|
|
60
|
+
* categorized by their type (added, removed, modified) along with metadata
|
|
61
|
+
* about when the changes occurred and an overall classification of the event.
|
|
62
|
+
*
|
|
63
|
+
* @template T - The document data type
|
|
64
|
+
*/
|
|
22
65
|
export interface IterationQueryDocChangeWatcherEvent<T = unknown> extends IterationQueryDocChangeWatcherChangeGroup<T> {
|
|
66
|
+
/**
|
|
67
|
+
* Timestamp when this change event was processed.
|
|
68
|
+
*/
|
|
23
69
|
readonly time: Date;
|
|
70
|
+
/**
|
|
71
|
+
* Array of all document changes in this event.
|
|
72
|
+
*
|
|
73
|
+
* Contains the complete set of changes, regardless of their type.
|
|
74
|
+
*/
|
|
24
75
|
readonly changes: DocumentChange<T>[];
|
|
76
|
+
/**
|
|
77
|
+
* Classification of this change event based on the types of changes it contains.
|
|
78
|
+
*
|
|
79
|
+
* This provides a quick way to determine the nature of the changes without
|
|
80
|
+
* examining the individual document changes.
|
|
81
|
+
*/
|
|
25
82
|
readonly type: IterationQueryDocChangeWatcherChangeType;
|
|
26
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Group of document changes categorized by their change type.
|
|
86
|
+
*
|
|
87
|
+
* This interface organizes document changes into three distinct categories:
|
|
88
|
+
* added, removed, and modified, making it easier to process changes based
|
|
89
|
+
* on their type.
|
|
90
|
+
*
|
|
91
|
+
* @template T - The document data type
|
|
92
|
+
*/
|
|
27
93
|
export interface IterationQueryDocChangeWatcherChangeGroup<T = unknown> {
|
|
94
|
+
/**
|
|
95
|
+
* Documents that were newly added to the query results.
|
|
96
|
+
*/
|
|
28
97
|
readonly added: DocumentChange<T>[];
|
|
98
|
+
/**
|
|
99
|
+
* Documents that were removed from the query results.
|
|
100
|
+
*/
|
|
29
101
|
readonly removed: DocumentChange<T>[];
|
|
102
|
+
/**
|
|
103
|
+
* Documents that remained in the query results but had their data modified.
|
|
104
|
+
*/
|
|
30
105
|
readonly modified: DocumentChange<T>[];
|
|
31
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Classification of a change event based on the types of document changes it contains.
|
|
109
|
+
*
|
|
110
|
+
* - 'addedAndRemoved': Both additions and removals occurred
|
|
111
|
+
* - 'added': Only additions occurred
|
|
112
|
+
* - 'removed': Only removals occurred
|
|
113
|
+
* - 'modified': Only modifications occurred
|
|
114
|
+
* - 'none': No changes occurred
|
|
115
|
+
*/
|
|
32
116
|
export type IterationQueryDocChangeWatcherChangeType = 'addedAndRemoved' | 'added' | 'removed' | 'modified' | 'none';
|
|
117
|
+
/**
|
|
118
|
+
* Creates a watcher for monitoring changes to Firestore query results.
|
|
119
|
+
*
|
|
120
|
+
* This function sets up observables that track document changes (additions, removals,
|
|
121
|
+
* and modifications) in the results of a Firestore query over time. It provides both
|
|
122
|
+
* raw query snapshots and processed change events, making it easier to react to
|
|
123
|
+
* specific types of changes.
|
|
124
|
+
*
|
|
125
|
+
* @template T - The document data type
|
|
126
|
+
* @param config - Configuration for the watcher, including the iteration instance to watch
|
|
127
|
+
* and an optional delay before starting to monitor changes
|
|
128
|
+
* @returns A watcher object with observables for streaming changes
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* // Create a watcher for changes to active users
|
|
132
|
+
* const usersIterator = firestoreItemPageIterator({
|
|
133
|
+
* queryFactory: () => collection(firestore, 'users').where('status', '==', 'active'),
|
|
134
|
+
* pageSize: 10
|
|
135
|
+
* });
|
|
136
|
+
*
|
|
137
|
+
* const watcher = iterationQueryDocChangeWatcher({
|
|
138
|
+
* instance: usersIterator,
|
|
139
|
+
* delay: 1000 // wait 1 second after first results before watching for changes
|
|
140
|
+
* });
|
|
141
|
+
*
|
|
142
|
+
* // React to specific change types
|
|
143
|
+
* watcher.event$.subscribe(event => {
|
|
144
|
+
* if (event.type === 'added') {
|
|
145
|
+
* console.log('New users added:', event.added.map(change => change.doc.data()));
|
|
146
|
+
* }
|
|
147
|
+
* });
|
|
148
|
+
*/
|
|
33
149
|
export declare function iterationQueryDocChangeWatcher<T = unknown>(config: IterationQueryDocChangeWatcherConfig<T>): IterationQueryDocChangeWatcher<T>;
|
|
150
|
+
/**
|
|
151
|
+
* Determines the overall change type for a group of document changes.
|
|
152
|
+
*
|
|
153
|
+
* This function analyzes a change group to classify it based on the types of changes
|
|
154
|
+
* it contains. It follows a priority order for classification:
|
|
155
|
+
* 1. If both additions and removals are present, classify as 'addedAndRemoved'.
|
|
156
|
+
* 2. If only additions are present, classify as 'added'.
|
|
157
|
+
* 3. If only removals are present, classify as 'removed'.
|
|
158
|
+
* 4. If only modifications are present, classify as 'modified'.
|
|
159
|
+
* 5. If no changes are present, classify as 'none'.
|
|
160
|
+
*
|
|
161
|
+
* @template T - The document data type
|
|
162
|
+
* @param group - The change group to classify
|
|
163
|
+
* @returns The overall change type classification
|
|
164
|
+
*/
|
|
34
165
|
export declare function iterationQueryDocChangeWatcherChangeTypeForGroup<T = unknown>(group: IterationQueryDocChangeWatcherChangeGroup<T>): IterationQueryDocChangeWatcherChangeType;
|
|
@@ -1,2 +1,28 @@
|
|
|
1
1
|
import { type FirestoreModelData, type SnapshotConverterConfig, type SnapshotConverterFunctions } from './snapshot.type';
|
|
2
|
+
/**
|
|
3
|
+
* Creates converter functions for transforming between Firestore document snapshots and application model objects.
|
|
4
|
+
*
|
|
5
|
+
* This function generates a set of utility functions that handle the conversion between your application's
|
|
6
|
+
* typed model objects and the data format stored in Firestore. It supports field-level conversions,
|
|
7
|
+
* custom modifiers, and handles Firestore's merge options appropriately.
|
|
8
|
+
*
|
|
9
|
+
* @template T - The application model type that will be used in your application code
|
|
10
|
+
* @template O - The data type that will be stored in Firestore (defaults to FirestoreModelData<T>)
|
|
11
|
+
* @param config - Configuration for the converter, including field mappings and modifiers
|
|
12
|
+
* @returns A set of functions for converting between Firestore data and application models
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // Create a converter for a User model
|
|
16
|
+
* const userConverter = snapshotConverterFunctions<User, UserData>({
|
|
17
|
+
* fields: {
|
|
18
|
+
* createdAt: {
|
|
19
|
+
* from: (date: string) => new Date(date),
|
|
20
|
+
* to: (date: Date) => date.toISOString()
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* // Use with a collection reference
|
|
26
|
+
* const usersCollection = firestore.collection('users').withConverter(userConverter);
|
|
27
|
+
*/
|
|
2
28
|
export declare function snapshotConverterFunctions<T extends object, O extends object = FirestoreModelData<T>>(config: SnapshotConverterConfig<T, O>): SnapshotConverterFunctions<T, O>;
|