@dereekb/firebase 13.2.2 → 13.3.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/index.cjs.js +12893 -4062
- package/index.esm.js +12872 -4065
- package/package.json +5 -5
- package/src/lib/client/error/error.d.ts +18 -3
- package/src/lib/client/firestore/array.d.ts +16 -3
- package/src/lib/client/firestore/driver.accessor.batch.d.ts +35 -4
- package/src/lib/client/firestore/driver.accessor.create.d.ts +15 -0
- package/src/lib/client/firestore/driver.accessor.d.ts +15 -0
- package/src/lib/client/firestore/driver.accessor.default.d.ts +32 -0
- package/src/lib/client/firestore/driver.accessor.transaction.d.ts +35 -4
- package/src/lib/client/firestore/driver.d.ts +16 -0
- package/src/lib/client/firestore/driver.query.d.ts +36 -0
- package/src/lib/client/firestore/firestore.d.ts +11 -1
- package/src/lib/client/firestore/increment.d.ts +12 -3
- package/src/lib/client/function/development.function.factory.d.ts +27 -2
- package/src/lib/client/function/error.d.ts +27 -0
- package/src/lib/client/function/function.callable.d.ts +50 -5
- package/src/lib/client/function/function.factory.d.ts +70 -4
- package/src/lib/client/function/model.function.factory.d.ts +64 -9
- package/src/lib/client/storage/driver.accessor.d.ts +93 -0
- package/src/lib/client/storage/driver.d.ts +15 -0
- package/src/lib/client/storage/storage.d.ts +10 -1
- package/src/lib/common/auth/auth.context.d.ts +17 -2
- package/src/lib/common/auth/auth.d.ts +38 -9
- package/src/lib/common/auth/auth.error.d.ts +25 -0
- package/src/lib/common/auth/auth.server.error.d.ts +6 -2
- package/src/lib/common/development/function.d.ts +17 -6
- package/src/lib/common/development/function.schedule.d.ts +30 -1
- package/src/lib/common/firestore/accessor/accessor.wrap.modify.d.ts +36 -12
- package/src/lib/common/firestore/accessor/array.d.ts +14 -4
- package/src/lib/common/firestore/accessor/document.d.ts +77 -2
- package/src/lib/common/firestore/accessor/increment.d.ts +15 -3
- package/src/lib/common/firestore/collection/collection.d.ts +22 -4
- package/src/lib/common/firestore/collection/collection.util.d.ts +12 -2
- package/src/lib/common/firestore/driver/accessor.d.ts +28 -1
- package/src/lib/common/firestore/driver/batch.d.ts +6 -4
- package/src/lib/common/firestore/driver/driver.d.ts +18 -1
- package/src/lib/common/firestore/driver/query.d.ts +20 -1
- package/src/lib/common/firestore/driver/query.handler.d.ts +23 -0
- package/src/lib/common/firestore/driver/transaction.d.ts +18 -6
- package/src/lib/common/firestore/error.d.ts +16 -4
- package/src/lib/common/firestore/query/iterator.d.ts +11 -0
- package/src/lib/common/firestore/reference.d.ts +11 -6
- package/src/lib/common/firestore/snapshot/snapshot.d.ts +4 -0
- package/src/lib/common/firestore/snapshot/snapshot.field.d.ts +263 -63
- package/src/lib/common/firestore/types.d.ts +39 -1
- package/src/lib/common/firestore/util/id.batch.d.ts +55 -3
- package/src/lib/common/function/action.d.ts +35 -0
- package/src/lib/common/model/context.d.ts +11 -1
- package/src/lib/common/model/function.d.ts +45 -9
- package/src/lib/common/model/model/model.loader.d.ts +37 -0
- package/src/lib/common/model/model/model.param.d.ts +24 -2
- package/src/lib/common/model/model.service.d.ts +126 -4
- package/src/lib/common/model/permission/permission.context.d.ts +15 -0
- package/src/lib/common/model/permission/permission.d.ts +16 -0
- package/src/lib/common/model/permission/permission.service.d.ts +24 -1
- package/src/lib/common/model/permission/permission.service.grant.d.ts +72 -28
- package/src/lib/common/model/permission/permission.service.role.d.ts +15 -0
- package/src/lib/common/storage/accessor/path.model.d.ts +25 -8
- package/src/lib/common/storage/context.d.ts +23 -6
- package/src/lib/common/storage/driver/accessor.d.ts +15 -4
- package/src/lib/common/storage/driver/accessor.iterate.d.ts +31 -8
- package/src/lib/common/storage/driver/accessor.util.d.ts +13 -6
- package/src/lib/common/storage/driver/driver.d.ts +10 -1
- package/src/lib/common/storage/driver/error.d.ts +16 -0
- package/src/lib/common/storage/driver/list.d.ts +30 -0
- package/src/lib/common/storage/storage.d.ts +76 -19
- package/src/lib/common/storage/types.d.ts +23 -5
- package/src/lib/model/index.d.ts +1 -0
- package/src/lib/model/notification/notification.action.d.ts +8 -0
- package/src/lib/model/notification/notification.api.d.ts +26 -0
- package/src/lib/model/notification/notification.api.error.d.ts +15 -0
- package/src/lib/model/notification/notification.api.util.d.ts +27 -12
- package/src/lib/model/notification/notification.config.d.ts +193 -64
- package/src/lib/model/notification/notification.create.d.ts +62 -13
- package/src/lib/model/notification/notification.create.task.d.ts +25 -4
- package/src/lib/model/notification/notification.d.ts +258 -99
- package/src/lib/model/notification/notification.details.d.ts +66 -18
- package/src/lib/model/notification/notification.id.d.ts +90 -12
- package/src/lib/model/notification/notification.item.d.ts +57 -16
- package/src/lib/model/notification/notification.message.d.ts +84 -18
- package/src/lib/model/notification/notification.query.d.ts +21 -24
- package/src/lib/model/notification/notification.send.d.ts +38 -5
- package/src/lib/model/notification/notification.task.d.ts +87 -16
- package/src/lib/model/notification/notification.task.subtask.d.ts +42 -13
- package/src/lib/model/notification/notification.util.d.ts +68 -18
- package/src/lib/model/oidcmodel/index.d.ts +8 -0
- package/src/lib/model/oidcmodel/oidcmodel.action.d.ts +37 -0
- package/src/lib/model/oidcmodel/oidcmodel.api.d.ts +131 -0
- package/src/lib/model/oidcmodel/oidcmodel.d.ts +114 -0
- package/src/lib/model/oidcmodel/oidcmodel.data.d.ts +17 -0
- package/src/lib/model/oidcmodel/oidcmodel.id.d.ts +18 -0
- package/src/lib/model/oidcmodel/oidcmodel.interaction.d.ts +40 -0
- package/src/lib/model/oidcmodel/oidcmodel.interaction.oauth.d.ts +73 -0
- package/src/lib/model/oidcmodel/oidcmodel.query.d.ts +21 -0
- package/src/lib/model/storagefile/storagefile.action.d.ts +47 -0
- package/src/lib/model/storagefile/storagefile.api.d.ts +54 -4
- package/src/lib/model/storagefile/storagefile.create.d.ts +40 -3
- package/src/lib/model/storagefile/storagefile.d.ts +153 -16
- package/src/lib/model/storagefile/storagefile.file.d.ts +22 -7
- package/src/lib/model/storagefile/storagefile.group.d.ts +30 -1
- package/src/lib/model/storagefile/storagefile.group.processing.d.ts +20 -2
- package/src/lib/model/storagefile/storagefile.id.d.ts +44 -5
- package/src/lib/model/storagefile/storagefile.permission.d.ts +23 -4
- package/src/lib/model/storagefile/storagefile.query.d.ts +63 -11
- package/src/lib/model/storagefile/storagefile.task.d.ts +47 -4
- package/src/lib/model/storagefile/storagefile.upload.claims.d.ts +21 -4
- package/src/lib/model/storagefile/storagefile.upload.d.ts +41 -9
- package/src/lib/model/storagefile/storagefile.upload.determiner.d.ts +112 -20
- package/src/lib/model/storagefile/storagefile.util.d.ts +66 -3
- package/src/lib/model/system/system.action.d.ts +25 -0
- package/src/lib/model/system/system.d.ts +80 -4
- package/src/lib/model/user.d.ts +8 -2
- package/test/index.cjs.js +11168 -3295
- package/test/index.esm.js +11176 -3303
- package/test/package.json +6 -6
- package/test/src/lib/client/firebase.authorized.d.ts +18 -0
- package/test/src/lib/client/firebase.d.ts +60 -0
- package/test/src/lib/common/firebase.instance.d.ts +21 -0
- package/test/src/lib/common/firestore/firestore.d.ts +40 -0
- package/test/src/lib/common/firestore/firestore.instance.d.ts +16 -0
- package/test/src/lib/common/firestore/test.driver.accessor.d.ts +39 -2
- package/test/src/lib/common/firestore/test.driver.utility.d.ts +8 -2
- package/test/src/lib/common/firestore/test.iterator.d.ts +7 -2
- package/test/src/lib/common/mock/mock.item.collection.fixture.d.ts +29 -1
- package/test/src/lib/common/mock/mock.item.d.ts +219 -5
- package/test/src/lib/common/mock/mock.item.id.d.ts +6 -0
- package/test/src/lib/common/mock/mock.item.query.d.ts +12 -0
- package/test/src/lib/common/mock/mock.item.service.d.ts +60 -0
- package/test/src/lib/common/mock/mock.item.storage.fixture.d.ts +28 -1
- package/test/src/lib/common/storage/storage.d.ts +30 -0
- package/test/src/lib/common/storage/storage.instance.d.ts +22 -0
- package/test/src/lib/common/storage/test.driver.accessor.d.ts +7 -2
- package/index.cjs.js.map +0 -1
- package/index.esm.js.map +0 -1
|
@@ -1,27 +1,56 @@
|
|
|
1
1
|
import { type Type } from 'arktype';
|
|
2
|
+
/**
|
|
3
|
+
* Action types for the scheduled function development endpoint.
|
|
4
|
+
*/
|
|
2
5
|
export type ScheduledFunctionDevelopmentFunctionType = 'list' | 'run';
|
|
6
|
+
/**
|
|
7
|
+
* Enum variant of {@link ScheduledFunctionDevelopmentFunctionType} for runtime usage.
|
|
8
|
+
*/
|
|
3
9
|
export declare enum ScheduledFunctionDevelopmentFunctionTypeEnum {
|
|
4
10
|
LIST = "list",
|
|
5
11
|
RUN = "run"
|
|
6
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Parameters for the scheduled function development endpoint.
|
|
15
|
+
*
|
|
16
|
+
* Use `type: 'list'` to discover available scheduled functions, or `type: 'run'` with a function name to execute one.
|
|
17
|
+
*/
|
|
7
18
|
export interface ScheduledFunctionDevelopmentFirebaseFunctionParams {
|
|
8
19
|
readonly type: ScheduledFunctionDevelopmentFunctionTypeEnum;
|
|
20
|
+
/** Name of the scheduled function to run (required when type is 'run'). */
|
|
9
21
|
readonly run?: string;
|
|
10
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* ArkType validator for {@link ScheduledFunctionDevelopmentFirebaseFunctionParams}.
|
|
25
|
+
*/
|
|
11
26
|
export declare const scheduledFunctionDevelopmentFirebaseFunctionParamsType: Type<ScheduledFunctionDevelopmentFirebaseFunctionParams>;
|
|
27
|
+
/**
|
|
28
|
+
* Entry in the list of available scheduled functions returned by the development endpoint.
|
|
29
|
+
*/
|
|
12
30
|
export declare class ScheduledFunctionDevelopmentFirebaseFunctionListEntry {
|
|
13
31
|
name: string;
|
|
14
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Result returned when listing available scheduled functions.
|
|
35
|
+
*/
|
|
15
36
|
export interface ScheduledFunctionDevelopmentFirebaseFunctionListResult {
|
|
16
37
|
readonly type: 'list';
|
|
17
38
|
readonly list: ScheduledFunctionDevelopmentFirebaseFunctionListEntry[];
|
|
18
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Result returned after successfully running a scheduled function.
|
|
42
|
+
*/
|
|
19
43
|
export interface ScheduledFunctionDevelopmentFirebaseFunctionRunResult {
|
|
20
44
|
readonly type: 'run';
|
|
21
45
|
readonly success: true;
|
|
22
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Union of all possible results from the scheduled function development endpoint.
|
|
49
|
+
*/
|
|
23
50
|
export type ScheduledFunctionDevelopmentFirebaseFunctionResult = ScheduledFunctionDevelopmentFirebaseFunctionListResult | ScheduledFunctionDevelopmentFirebaseFunctionRunResult;
|
|
24
51
|
/**
|
|
25
|
-
*
|
|
52
|
+
* Development function specifier used to route requests to the scheduled function endpoint.
|
|
53
|
+
*
|
|
54
|
+
* Used as the `specifier` value in {@link OnCallDevelopmentParams}.
|
|
26
55
|
*/
|
|
27
56
|
export declare const SCHEDULED_FUNCTION_DEV_FUNCTION_SPECIFIER = "scheduledFunction";
|
|
@@ -5,15 +5,16 @@ import { type DocumentData, type SetOptions } from '../types';
|
|
|
5
5
|
import { type FirestoreDocumentDataAccessor, type FirestoreDocumentDataAccessorSetFunction } from './accessor';
|
|
6
6
|
import { AbstractFirestoreDocumentDataAccessorWrapper, type InterceptAccessorFactoryFunction } from './accessor.wrap';
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* -
|
|
11
|
-
* -
|
|
12
|
-
* -
|
|
8
|
+
* Controls when the modifier function is applied to document data.
|
|
9
|
+
*
|
|
10
|
+
* - `'always'`: Modifies data on every create, set, and update operation
|
|
11
|
+
* - `'update'`: Only modifies when calling `set()` with merge options (updating existing documents)
|
|
12
|
+
* - `'set'`: Only modifies when calling `create()` or `set()` without merge options (new documents)
|
|
13
|
+
* - `'create'`: Only modifies on `create()` calls
|
|
13
14
|
*/
|
|
14
15
|
export type ModifyBeforeSetFistoreDataAccessorMode = 'always' | 'update' | 'set' | 'create';
|
|
15
16
|
/**
|
|
16
|
-
* Input
|
|
17
|
+
* Input passed to the modifier function, containing the document data and reference context.
|
|
17
18
|
*/
|
|
18
19
|
export interface ModifyBeforeSetFistoreDataAccessorInput<T> extends DocumentReferenceRef<T> {
|
|
19
20
|
/**
|
|
@@ -37,7 +38,14 @@ export interface ModifyBeforeSetConfig<T extends object> {
|
|
|
37
38
|
readonly modifier: ArrayOrValue<ModifyBeforeSetModifierFunction<T>>;
|
|
38
39
|
}
|
|
39
40
|
/**
|
|
40
|
-
*
|
|
41
|
+
* Accessor wrapper that applies a modifier function to data before it is written to Firestore.
|
|
42
|
+
*
|
|
43
|
+
* The `when` mode in the config controls which write operations trigger the modifier.
|
|
44
|
+
* Common use case: automatically copying the document ID into a `uid` field for {@link UserRelated} models
|
|
45
|
+
* via {@link copyUserRelatedDataModifierConfig}.
|
|
46
|
+
*
|
|
47
|
+
* @template T - The document data type
|
|
48
|
+
* @template D - The raw document data type in Firestore
|
|
41
49
|
*/
|
|
42
50
|
export declare class ModifyBeforeSetFirestoreDocumentDataAccessorWrapper<T extends object, D = DocumentData> extends AbstractFirestoreDocumentDataAccessorWrapper<T, D> {
|
|
43
51
|
readonly config: ModifyBeforeSetConfig<T>;
|
|
@@ -46,18 +54,34 @@ export declare class ModifyBeforeSetFirestoreDocumentDataAccessorWrapper<T exten
|
|
|
46
54
|
constructor(accessor: FirestoreDocumentDataAccessor<T, D>, config: ModifyBeforeSetConfig<T>);
|
|
47
55
|
}
|
|
48
56
|
/**
|
|
49
|
-
* Creates a
|
|
57
|
+
* Creates a modifier function that copies the document reference's ID into the specified field on the data.
|
|
50
58
|
*
|
|
51
|
-
* @
|
|
52
|
-
*
|
|
59
|
+
* Useful for models that need to store their own document ID as a field (e.g., `uid` on {@link UserRelated} models).
|
|
60
|
+
*
|
|
61
|
+
* @param fieldName - The field to copy the document ID into
|
|
62
|
+
* @returns A modifier function that sets the field to the document's ID
|
|
53
63
|
*/
|
|
54
64
|
export declare function copyDocumentIdToFieldModifierFunction<T extends object>(fieldName: keyof T): ModifyBeforeSetModifierFunction<T>;
|
|
65
|
+
/**
|
|
66
|
+
* Creates an {@link InterceptAccessorFactoryFunction} that wraps all created accessors with
|
|
67
|
+
* {@link ModifyBeforeSetFirestoreDocumentDataAccessorWrapper} using the provided config.
|
|
68
|
+
*/
|
|
55
69
|
export declare function modifyBeforeSetInterceptAccessorFactoryFunction<T extends object, D = DocumentData>(config: ModifyBeforeSetConfig<T>): InterceptAccessorFactoryFunction<T, D>;
|
|
70
|
+
/**
|
|
71
|
+
* Creates a modifier that copies the document ID to the `uid` field for {@link UserRelated} models.
|
|
72
|
+
*/
|
|
56
73
|
export declare function copyDocumentIdForUserRelatedModifierFunction<T extends UserRelated>(): ModifyBeforeSetModifierFunction<T>;
|
|
57
74
|
/**
|
|
58
|
-
* Returns a pre-configured ModifyBeforeSetConfig
|
|
59
|
-
*
|
|
75
|
+
* Returns a pre-configured {@link ModifyBeforeSetConfig} for {@link UserRelated} models
|
|
76
|
+
* that copies the document ID to the `uid` field on set operations (new document creation).
|
|
60
77
|
*/
|
|
61
78
|
export declare function copyUserRelatedDataModifierConfig<T extends UserRelated>(): ModifyBeforeSetConfig<T>;
|
|
79
|
+
/**
|
|
80
|
+
* Cached singleton factory for the UserRelated data modifier accessor interceptor.
|
|
81
|
+
*/
|
|
62
82
|
export declare const COPY_USER_RELATED_DATA_ACCESSOR_FACTORY_FUNCTION: import("@dereekb/util").CachedFactoryWithInput<InterceptAccessorFactoryFunction<import("../..").FirebaseAuthUserIdRef, DocumentData>, unknown>;
|
|
83
|
+
/**
|
|
84
|
+
* Returns a typed {@link InterceptAccessorFactoryFunction} that applies the UserRelated
|
|
85
|
+
* document ID copy modifier to all accessors created by the factory.
|
|
86
|
+
*/
|
|
63
87
|
export declare function copyUserRelatedDataAccessorFactoryFunction<T extends UserRelated, D = DocumentData>(): InterceptAccessorFactoryFunction<T, D>;
|
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
import { type WriteResult } from '../types';
|
|
2
2
|
import { type FirestoreAccessorArrayUpdate, type FirestoreDocumentDataAccessor } from './accessor';
|
|
3
|
+
/**
|
|
4
|
+
* Function that applies array union/remove operations to a Firestore document's array fields.
|
|
5
|
+
*
|
|
6
|
+
* @template T - The document data type
|
|
7
|
+
*/
|
|
3
8
|
export type ArrayFieldUpdateWithAccessorFunction<T> = (data: FirestoreAccessorArrayUpdate<T>) => Promise<WriteResult | void>;
|
|
4
9
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
10
|
+
* Creates a function that performs atomic array field operations (union/remove) on a Firestore document.
|
|
11
|
+
*
|
|
12
|
+
* The returned function filters out falsy/empty values from the update data and skips
|
|
13
|
+
* the operation entirely if no valid fields remain. Uses Firestore's built-in `arrayUnion`
|
|
14
|
+
* and `arrayRemove` operations, which are safe for concurrent updates.
|
|
15
|
+
*
|
|
16
|
+
* @param accessor - The document accessor to perform the array update on
|
|
17
|
+
* @returns A function that applies array updates to the document
|
|
7
18
|
*
|
|
8
|
-
* @
|
|
9
|
-
* @returns
|
|
19
|
+
* @see https://firebase.google.com/docs/firestore/manage-data/add-data#update_elements_in_an_array
|
|
10
20
|
*/
|
|
11
21
|
export declare function arrayUpdateWithAccessorFunction<T>(accessor: FirestoreDocumentDataAccessor<T>): ArrayFieldUpdateWithAccessorFunction<T>;
|
|
@@ -8,6 +8,23 @@ import { type FirestoreDocumentContext } from './context';
|
|
|
8
8
|
import { type Building, type Maybe } from '@dereekb/util';
|
|
9
9
|
import { type InterceptAccessorFactoryFunction } from './accessor.wrap';
|
|
10
10
|
import { type FirestoreDataConverterFactory, type FirestoreDataConverterFactoryRef, type InterceptFirestoreDataConverterFactory } from './converter';
|
|
11
|
+
/**
|
|
12
|
+
* Represents a typed Firestore document with full CRUD capabilities and reactive streaming.
|
|
13
|
+
*
|
|
14
|
+
* This is the primary interface for interacting with individual Firestore documents in the application.
|
|
15
|
+
* It combines document reference metadata, data conversion, and all read/write operations into a
|
|
16
|
+
* single cohesive interface. Documents are created via {@link FirestoreDocumentAccessor} which provides
|
|
17
|
+
* the appropriate execution context (standard, transaction, or batch).
|
|
18
|
+
*
|
|
19
|
+
* Key capabilities:
|
|
20
|
+
* - **Read**: `snapshot()`, `snapshotData()`, `exists()`
|
|
21
|
+
* - **Stream**: `snapshotStream()`, `snapshotDataStream()` for real-time updates
|
|
22
|
+
* - **Write**: `create()`, `update()`, `increment()`, `arrayUpdate()`
|
|
23
|
+
* - **Identity**: `id`, `key` (full path), `modelType`, `collectionName`
|
|
24
|
+
*
|
|
25
|
+
* @template T - The document data type
|
|
26
|
+
* @template I - The model identity type (provides modelType and collectionName)
|
|
27
|
+
*/
|
|
11
28
|
export interface FirestoreDocument<T, I extends FirestoreModelIdentity = FirestoreModelIdentity> extends FirestoreDataConverterRef<T>, DocumentReferenceRef<T>, CollectionReferenceRef<T>, FirestoreModelIdentityRef<I>, FirestoreModelTypeRef<FirestoreModelIdentityModelType<I>>, FirestoreCollectionNameRef<FirestoreModelIdentityCollectionName<I>>, FirestoreModelKeyRef, FirestoreModelIdRef {
|
|
12
29
|
readonly accessor: FirestoreDocumentDataAccessor<T>;
|
|
13
30
|
readonly id: string;
|
|
@@ -26,7 +43,19 @@ export interface FirestoreDocument<T, I extends FirestoreModelIdentity = Firesto
|
|
|
26
43
|
*/
|
|
27
44
|
export type FirestoreDocumentData<D extends FirestoreDocument<any>> = D extends FirestoreDocument<infer T> ? T : never;
|
|
28
45
|
/**
|
|
29
|
-
* Abstract
|
|
46
|
+
* Abstract base implementation of {@link FirestoreDocument}.
|
|
47
|
+
*
|
|
48
|
+
* Provides the standard implementation for all document operations by delegating to the
|
|
49
|
+
* underlying {@link FirestoreDocumentDataAccessor}. The `update()` method uses the document's
|
|
50
|
+
* converter (via {@link updateWithAccessorUpdateAndConverterFunction}) so that partial updates
|
|
51
|
+
* go through the same conversion pipeline as full writes.
|
|
52
|
+
*
|
|
53
|
+
* Subclasses must implement `modelIdentity` to provide the model type and collection name.
|
|
54
|
+
* Also exposes `stream$` and `data$` lazy observables for reactive consumption.
|
|
55
|
+
*
|
|
56
|
+
* @template T - The document data type
|
|
57
|
+
* @template D - The concrete document subclass type (for self-referential typing)
|
|
58
|
+
* @template I - The model identity type
|
|
30
59
|
*/
|
|
31
60
|
export declare abstract class AbstractFirestoreDocument<T, D extends AbstractFirestoreDocument<T, any, I>, I extends FirestoreModelIdentity = FirestoreModelIdentity> implements FirestoreDocument<T>, LimitedFirestoreDocumentAccessorRef<T, D>, CollectionReferenceRef<T> {
|
|
32
61
|
private readonly _accessor;
|
|
@@ -106,10 +135,24 @@ export declare abstract class AbstractFirestoreDocument<T, D extends AbstractFir
|
|
|
106
135
|
*/
|
|
107
136
|
arrayUpdate(data: FirestoreAccessorArrayUpdate<T>): Promise<WriteResult | void>;
|
|
108
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Reference to a {@link LimitedFirestoreDocumentAccessor}.
|
|
140
|
+
*/
|
|
109
141
|
export interface LimitedFirestoreDocumentAccessorRef<T, D extends FirestoreDocument<T> = FirestoreDocument<T>, A extends LimitedFirestoreDocumentAccessor<T, D> = LimitedFirestoreDocumentAccessor<T, D>> {
|
|
110
142
|
readonly documentAccessor: A;
|
|
111
143
|
}
|
|
112
144
|
export type FirestoreDocumentAccessorRef<T, D extends FirestoreDocument<T> = FirestoreDocument<T>> = LimitedFirestoreDocumentAccessorRef<T, D, FirestoreDocumentAccessor<T, D>>;
|
|
145
|
+
/**
|
|
146
|
+
* Provides document loading capabilities without the ability to create new documents.
|
|
147
|
+
*
|
|
148
|
+
* Used in contexts where you have a document reference or key but don't have (or need) access
|
|
149
|
+
* to the parent collection — for example, in subcollection accessors or when loading documents
|
|
150
|
+
* from known paths. For full access including `newDocument()` and `loadDocumentForId()`,
|
|
151
|
+
* use {@link FirestoreDocumentAccessor}.
|
|
152
|
+
*
|
|
153
|
+
* @template T - The document data type
|
|
154
|
+
* @template D - The concrete FirestoreDocument subclass
|
|
155
|
+
*/
|
|
113
156
|
export interface LimitedFirestoreDocumentAccessor<T, D extends FirestoreDocument<T> = FirestoreDocument<T>> extends FirestoreDataConverterRef<T>, FirestoreModelTypeModelIdentityRef, FirestoreAccessorDriverRef {
|
|
114
157
|
readonly databaseContext: FirestoreDocumentContext<T>;
|
|
115
158
|
/**
|
|
@@ -145,6 +188,16 @@ export interface LimitedFirestoreDocumentAccessor<T, D extends FirestoreDocument
|
|
|
145
188
|
*/
|
|
146
189
|
readonly converterFactory: FirestoreDataConverterFactory<T>;
|
|
147
190
|
}
|
|
191
|
+
/**
|
|
192
|
+
* Full document accessor with collection-level operations including creating new documents.
|
|
193
|
+
*
|
|
194
|
+
* Extends {@link LimitedFirestoreDocumentAccessor} with `newDocument()` (auto-generates an ID)
|
|
195
|
+
* and `loadDocumentForId()` (loads by document ID relative to the collection). This is the
|
|
196
|
+
* standard accessor used when you have access to the collection reference.
|
|
197
|
+
*
|
|
198
|
+
* @template T - The document data type
|
|
199
|
+
* @template D - The concrete FirestoreDocument subclass
|
|
200
|
+
*/
|
|
148
201
|
export interface FirestoreDocumentAccessor<T, D extends FirestoreDocument<T> = FirestoreDocument<T>> extends LimitedFirestoreDocumentAccessor<T, D>, CollectionReferenceRef<T>, FirestoreAccessorDriverRef {
|
|
149
202
|
readonly databaseContext: FirestoreDocumentContext<T>;
|
|
150
203
|
/**
|
|
@@ -166,7 +219,10 @@ export interface FirestoreDocumentAccessor<T, D extends FirestoreDocument<T> = F
|
|
|
166
219
|
documentRefForId(id: FirestoreModelId): DocumentReference<T>;
|
|
167
220
|
}
|
|
168
221
|
/**
|
|
169
|
-
*
|
|
222
|
+
* Factory function that creates a typed {@link FirestoreDocument} from a raw data accessor.
|
|
223
|
+
*
|
|
224
|
+
* Used by the accessor factory system to create concrete document instances (e.g., `NotificationDocument`)
|
|
225
|
+
* from their underlying accessor and document accessor context.
|
|
170
226
|
*/
|
|
171
227
|
export type FirestoreDocumentFactoryFunction<T, D extends FirestoreDocument<T> = FirestoreDocument<T>> = (accessor: FirestoreDocumentDataAccessor<T>, documentAccessor: LimitedFirestoreDocumentAccessor<T, D>) => D;
|
|
172
228
|
/**
|
|
@@ -240,6 +296,13 @@ export interface FirestoreDocumentAccessorContextExtension<T, D extends Firestor
|
|
|
240
296
|
}
|
|
241
297
|
export declare function firestoreDocumentAccessorContextExtension<T, D extends FirestoreDocument<T> = FirestoreDocument<T>>({ documentAccessor, firestoreAccessorDriver }: FirestoreDocumentAccessorContextExtensionConfig<T, D>): FirestoreDocumentAccessorContextExtension<T, D>;
|
|
242
298
|
export declare function firestoreDocumentAccessorContextExtension<T, D extends FirestoreDocument<T> = FirestoreDocument<T>>({ documentAccessor, firestoreAccessorDriver }: LimitedFirestoreDocumentAccessorContextExtensionConfig<T, D>): LimitedFirestoreDocumentAccessorContextExtension<T, D>;
|
|
299
|
+
/**
|
|
300
|
+
* A {@link FirestoreDocument} that resides in a subcollection and provides access to its parent document reference.
|
|
301
|
+
*
|
|
302
|
+
* @template P - The parent document's data type
|
|
303
|
+
* @template T - This document's data type
|
|
304
|
+
* @template I - The model identity type
|
|
305
|
+
*/
|
|
243
306
|
export interface FirestoreDocumentWithParent<P, T, I extends FirestoreModelIdentity = FirestoreModelIdentity> extends FirestoreDocument<T, I> {
|
|
244
307
|
readonly parent: DocumentReference<P>;
|
|
245
308
|
}
|
|
@@ -247,6 +310,15 @@ export declare abstract class AbstractFirestoreDocumentWithParent<P, T, D extend
|
|
|
247
310
|
get parent(): DocumentReference<P>;
|
|
248
311
|
constructor(accessor: FirestoreDocumentDataAccessor<T>, documentAccessor: LimitedFirestoreDocumentAccessor<T, D>);
|
|
249
312
|
}
|
|
313
|
+
/**
|
|
314
|
+
* Accessor for collections that contain only a single known document (e.g., system state, user profile).
|
|
315
|
+
*
|
|
316
|
+
* Provides convenience methods that load the single document by its fixed identifier,
|
|
317
|
+
* supporting both transaction and write batch contexts.
|
|
318
|
+
*
|
|
319
|
+
* @template T - The document data type
|
|
320
|
+
* @template D - The concrete FirestoreDocument subclass
|
|
321
|
+
*/
|
|
250
322
|
export interface FirestoreSingleDocumentAccessor<T, D extends FirestoreDocument<T> = FirestoreDocument<T>> {
|
|
251
323
|
readonly singleItemIdentifier: string;
|
|
252
324
|
loadDocument(): D;
|
|
@@ -259,6 +331,9 @@ export interface FirestoreSingleDocumentAccessorConfig<T, D extends FirestoreDoc
|
|
|
259
331
|
readonly accessors: FirestoreDocumentAccessorContextExtension<T, D>;
|
|
260
332
|
}
|
|
261
333
|
export declare function firestoreSingleDocumentAccessor<T, D extends FirestoreDocument<T> = FirestoreDocument<T>>(config: FirestoreSingleDocumentAccessorConfig<T, D>): FirestoreSingleDocumentAccessor<T, D>;
|
|
334
|
+
/**
|
|
335
|
+
* Default document ID used for single-document collections. The document is stored at path `<collection>/0`.
|
|
336
|
+
*/
|
|
262
337
|
export declare const DEFAULT_SINGLE_ITEM_FIRESTORE_COLLECTION_DOCUMENT_IDENTIFIER = "0";
|
|
263
338
|
export type SingleItemFirestoreCollectionDocumentIdentifier = string;
|
|
264
339
|
export interface SingleItemFirestoreCollectionDocumentIdentifierRef {
|
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
import { type WriteResult } from '../types';
|
|
2
2
|
import { type FirestoreAccessorIncrementUpdate, type FirestoreDocumentDataAccessor } from './accessor';
|
|
3
|
+
/**
|
|
4
|
+
* Function that applies an atomic increment update to a Firestore document's numeric fields.
|
|
5
|
+
*
|
|
6
|
+
* @template T - The document data type
|
|
7
|
+
*/
|
|
3
8
|
export type IncrementUpdateWithAccessorFunction<T> = (data: FirestoreAccessorIncrementUpdate<T>) => Promise<WriteResult | void>;
|
|
4
9
|
/**
|
|
5
|
-
*
|
|
10
|
+
* Creates a function that atomically increments numeric fields in a Firestore document.
|
|
11
|
+
*
|
|
12
|
+
* The returned function filters out falsy/empty values from the increment data and skips
|
|
13
|
+
* the update entirely if no valid fields remain. This avoids unnecessary Firestore writes.
|
|
14
|
+
*
|
|
15
|
+
* Uses Firestore's built-in atomic increment operation, which is safe for concurrent updates.
|
|
16
|
+
*
|
|
17
|
+
* @param accessor - The document accessor to perform the increment on
|
|
18
|
+
* @returns A function that applies increment updates to the document
|
|
6
19
|
*
|
|
7
|
-
* @
|
|
8
|
-
* @returns
|
|
20
|
+
* @see https://cloud.google.com/firestore/docs/samples/firestore-data-set-numeric-increment
|
|
9
21
|
*/
|
|
10
22
|
export declare function incrementUpdateWithAccessorFunction<T>(accessor: FirestoreDocumentDataAccessor<T>): IncrementUpdateWithAccessorFunction<T>;
|
|
@@ -19,11 +19,12 @@ export type FirestoreModelType = ModelTypeString;
|
|
|
19
19
|
* An all lowercase name that references a collection. Is usually the lowercase version of the FirestoreModelType.
|
|
20
20
|
*
|
|
21
21
|
* This is the part of the path that identifies what the collection is. Collection names are used in
|
|
22
|
-
* Firestore paths and should follow Firestore naming conventions (lowercase, no spaces).
|
|
22
|
+
* Firestore paths and should follow Firestore naming conventions (lowercase, no spaces, no special characters, since "_" is reserved/used for TwoWayFlatFirestoreModelKey).
|
|
23
23
|
*
|
|
24
24
|
* Each collection name in the app should be unique, as usage of CollectionGroups would cause collections
|
|
25
25
|
* with the same name to be returned regardless of their location in the document hierarchy.
|
|
26
26
|
*
|
|
27
|
+
*
|
|
27
28
|
* @example 'u', 'ps', 'or'
|
|
28
29
|
*/
|
|
29
30
|
export type FirestoreCollectionName = string;
|
|
@@ -494,7 +495,15 @@ export interface FirestoreModelKeyRef {
|
|
|
494
495
|
readonly key: FirestoreModelKey;
|
|
495
496
|
}
|
|
496
497
|
/**
|
|
497
|
-
*
|
|
498
|
+
* Base interface for accessing documents in a Firestore collection.
|
|
499
|
+
*
|
|
500
|
+
* Combines document accessor factories, query capabilities, and iteration support into a single
|
|
501
|
+
* interface. This is the foundation for both {@link FirestoreCollection} (full access) and
|
|
502
|
+
* collection group queries (limited access without collection reference).
|
|
503
|
+
*
|
|
504
|
+
* @template T - The document data type
|
|
505
|
+
* @template D - The concrete FirestoreDocument subclass
|
|
506
|
+
* @template A - The accessor type (limited or full)
|
|
498
507
|
*/
|
|
499
508
|
export interface FirestoreCollectionLike<T, D extends FirestoreDocument<T> = FirestoreDocument<T>, A extends LimitedFirestoreDocumentAccessor<T, D> = LimitedFirestoreDocumentAccessor<T, D>> extends FirestoreContextReference, FirestoreModelIdentityRef, QueryLikeReferenceRef<T>, FirestoreItemPageIterationFactory<T>, FirestoreQueryFactory<T>, LimitedFirestoreDocumentAccessorFactory<T, D, A>, LimitedFirestoreDocumentAccessorForTransactionFactory<T, D, A>, LimitedFirestoreDocumentAccessorForWriteBatchFactory<T, D, A>, FirestoreCollectionQueryFactory<T, D> {
|
|
500
509
|
}
|
|
@@ -504,9 +513,18 @@ export interface FirestoreCollectionLike<T, D extends FirestoreDocument<T> = Fir
|
|
|
504
513
|
export interface FirestoreCollectionConfig<T, D extends FirestoreDocument<T> = FirestoreDocument<T>> extends FirestoreContextReference, FirestoreDrivers, Omit<FirestoreItemPageIterationBaseConfig<T>, 'queryLike'>, Partial<QueryLikeReferenceRef<T>>, FirestoreDocumentAccessorFactoryConfig<T, D> {
|
|
505
514
|
}
|
|
506
515
|
/**
|
|
507
|
-
*
|
|
516
|
+
* Full Firestore collection interface with document CRUD, querying, iteration, and context support.
|
|
517
|
+
*
|
|
518
|
+
* This is the primary interface used to interact with a Firestore collection. It provides:
|
|
519
|
+
* - **Document access**: Create, load, and manage documents via {@link FirestoreDocumentAccessor}
|
|
520
|
+
* - **Querying**: Build typed queries via the query factory
|
|
521
|
+
* - **Iteration**: Paginate through results via firestore iteration factories
|
|
522
|
+
* - **Context support**: Create accessors for transactions and write batches
|
|
523
|
+
*
|
|
524
|
+
* Created via {@link makeFirestoreCollection}.
|
|
508
525
|
*
|
|
509
|
-
*
|
|
526
|
+
* @template T - The document data type
|
|
527
|
+
* @template D - The concrete FirestoreDocument subclass
|
|
510
528
|
*/
|
|
511
529
|
export interface FirestoreCollection<T, D extends FirestoreDocument<T> = FirestoreDocument<T>> extends FirestoreCollectionLike<T, D, FirestoreDocumentAccessor<T, D>>, CollectionReferenceRef<T>, FirestoreDocumentAccessorFactory<T, D>, FirestoreDocumentAccessorForTransactionFactory<T, D>, FirestoreDocumentAccessorForWriteBatchFactory<T, D> {
|
|
512
530
|
readonly config: FirestoreCollectionConfig<T, D>;
|
|
@@ -3,7 +3,17 @@ import { type FirestoreModelId } from './collection';
|
|
|
3
3
|
/**
|
|
4
4
|
* Creates a valid FirestoreModelId from an email address.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* Replaces `@` with `AAA` and strips all non-alphanumeric characters, producing an ID
|
|
7
|
+
* that satisfies Firestore's document ID constraints. This encoding is one-way; the
|
|
8
|
+
* original email cannot be recovered from the result.
|
|
9
|
+
*
|
|
10
|
+
* @param emailAddress - The email address to convert
|
|
11
|
+
* @returns A Firestore-safe document ID derived from the email
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const id = firestoreModelIdFromEmail('user@example.com');
|
|
16
|
+
* // id === 'userAAAexamplecom'
|
|
17
|
+
* ```
|
|
8
18
|
*/
|
|
9
19
|
export declare function firestoreModelIdFromEmail(emailAddress: EmailAddress): FirestoreModelId;
|
|
@@ -5,14 +5,41 @@ import { type WriteBatchFirestoreDocumentContextFactory } from '../accessor/cont
|
|
|
5
5
|
import { type TransactionFirestoreDocumentContextFactory } from '../accessor/context.transaction';
|
|
6
6
|
import { type FirestoreWriteBatchFactoryDriver } from './batch';
|
|
7
7
|
import { type FirestoreTransactionFactoryDriver } from './transaction';
|
|
8
|
+
/**
|
|
9
|
+
* Creates a {@link CollectionGroup} reference spanning all collections with the given ID.
|
|
10
|
+
*/
|
|
8
11
|
export type FirestoreAccessorDriverCollectionGroupFunction = <T = DocumentData>(firestore: Firestore, collectionId: string) => CollectionGroup<T>;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a {@link CollectionReference} at the specified path.
|
|
14
|
+
*/
|
|
9
15
|
export type FirestoreAccessorDriverCollectionRefFunction = <T = DocumentData>(firestore: Firestore, path: string, ...pathSegments: string[]) => CollectionReference<T>;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a {@link CollectionReference} for a subcollection under the given document.
|
|
18
|
+
*/
|
|
10
19
|
export type FirestoreAccessorDriverSubcollectionRefFunction = <T = DocumentData>(document: DocumentReference, path: string, ...pathSegments: string[]) => CollectionReference<T>;
|
|
20
|
+
/**
|
|
21
|
+
* Creates a {@link DocumentReference} within a collection, optionally at a specific path.
|
|
22
|
+
* When no path is provided, a new auto-generated document ID is used.
|
|
23
|
+
*/
|
|
11
24
|
export type FirestoreAccessorDriverDocumentRefFunction = <T = DocumentData>(collection: CollectionReference<T>, path?: string, ...pathSegments: string[]) => DocumentReference<T>;
|
|
25
|
+
/**
|
|
26
|
+
* Creates a {@link DocumentReference} from a full slash-separated Firestore path (e.g., `'users/abc123'`).
|
|
27
|
+
*/
|
|
12
28
|
export type FirestoreAccessorDriverFullPathDocumentRefFunction = <T = DocumentData>(firestore: Firestore, fullPath: string) => DocumentReference<T>;
|
|
29
|
+
/**
|
|
30
|
+
* Transforms collection paths, typically by appending a random suffix, to isolate concurrent
|
|
31
|
+
* test runs from each other. Only used in testing environments.
|
|
32
|
+
*/
|
|
13
33
|
export type FirestoreAccessorPathFuzzerFunction = (path: FirestoreCollectionName) => FirestoreCollectionName;
|
|
14
34
|
/**
|
|
15
|
-
*
|
|
35
|
+
* Driver interface for document and collection CRUD operations.
|
|
36
|
+
*
|
|
37
|
+
* Provides factory functions for creating Firestore references (documents, collections,
|
|
38
|
+
* subcollections, collection groups) as well as context factories for standard, batch,
|
|
39
|
+
* and transaction execution modes. Platform implementations (Web SDK, Admin SDK, test mocks)
|
|
40
|
+
* each provide their own implementation of this interface.
|
|
41
|
+
*
|
|
42
|
+
* @see {@link FirestoreQueryDriver} for the complementary query execution driver
|
|
16
43
|
*/
|
|
17
44
|
export interface FirestoreAccessorDriver extends FirestoreTransactionFactoryDriver, FirestoreWriteBatchFactoryDriver {
|
|
18
45
|
readonly doc: FirestoreAccessorDriverDocumentRefFunction;
|
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
import { type Factory } from '@dereekb/util';
|
|
2
2
|
import { type Firestore, type WriteBatch } from '../types';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Creates a new {@link WriteBatch} for atomically committing multiple write operations.
|
|
5
5
|
*/
|
|
6
6
|
export type WriteBatchFactory = Factory<WriteBatch>;
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Creates a {@link WriteBatchFactory} bound to the given Firestore instance.
|
|
9
|
+
* Used by the driver layer to provide batch writing capabilities per-Firestore.
|
|
9
10
|
*/
|
|
10
11
|
export type WriteBatchForFirestoreFactory = (firestore: Firestore) => WriteBatchFactory;
|
|
11
12
|
/**
|
|
12
|
-
*
|
|
13
|
+
* Holds a reference to a {@link WriteBatchFactory} for creating write batches.
|
|
13
14
|
*/
|
|
14
15
|
export interface WriteBatchFactoryReference {
|
|
15
16
|
readonly batch: WriteBatchFactory;
|
|
16
17
|
}
|
|
17
18
|
/**
|
|
18
|
-
* Driver for
|
|
19
|
+
* Driver component that provides {@link WriteBatch} creation for a Firestore instance.
|
|
20
|
+
* Implemented by platform-specific drivers (Web SDK, Admin SDK).
|
|
19
21
|
*/
|
|
20
22
|
export interface FirestoreWriteBatchFactoryDriver {
|
|
21
23
|
readonly writeBatchFactoryForFirestore: WriteBatchForFirestoreFactory;
|
|
@@ -1,9 +1,26 @@
|
|
|
1
1
|
import { type FirestoreAccessorDriverRef } from './accessor';
|
|
2
2
|
import { type FirestoreQueryDriverRef } from './query';
|
|
3
|
+
/**
|
|
4
|
+
* Optional human-readable identifier for the Firestore driver (e.g., 'firebase-admin', 'firebase-web', 'testing').
|
|
5
|
+
*/
|
|
3
6
|
export type FirestoreDriverIdentifier = string;
|
|
7
|
+
/**
|
|
8
|
+
* Indicates whether the driver targets a real Firestore instance or a test environment.
|
|
9
|
+
*
|
|
10
|
+
* Used to conditionally enable behaviors like path fuzzing in tests, or to gate
|
|
11
|
+
* production-only optimizations.
|
|
12
|
+
*/
|
|
4
13
|
export type FirestoreDriverType = 'production' | 'testing';
|
|
5
14
|
/**
|
|
6
|
-
*
|
|
15
|
+
* Combined driver interface that provides all Firestore operational capabilities.
|
|
16
|
+
*
|
|
17
|
+
* This is the top-level driver abstraction that platform-specific implementations
|
|
18
|
+
* (e.g., Firebase Web SDK, Firebase Admin SDK, or test mocks) must satisfy.
|
|
19
|
+
* It is consumed by {@link FirestoreContext} to wire up collection factories, query
|
|
20
|
+
* execution, batch writes, and transactions in a platform-agnostic way.
|
|
21
|
+
*
|
|
22
|
+
* @see {@link FirestoreAccessorDriver} for document/collection CRUD operations
|
|
23
|
+
* @see {@link FirestoreQueryDriver} for query execution operations
|
|
7
24
|
*/
|
|
8
25
|
export interface FirestoreDrivers extends FirestoreQueryDriverRef, FirestoreAccessorDriverRef {
|
|
9
26
|
firestoreDriverIdentifier?: FirestoreDriverIdentifier;
|
|
@@ -2,15 +2,34 @@ import { type FieldPath, type SnapshotListenOptions, type Transaction, type Quer
|
|
|
2
2
|
import { type Observable } from 'rxjs';
|
|
3
3
|
import { type FirestoreQueryConstraint } from '../query/constraint';
|
|
4
4
|
import { type Maybe } from '@dereekb/util';
|
|
5
|
+
/**
|
|
6
|
+
* Applies query constraints to a base query and returns the constrained query.
|
|
7
|
+
*/
|
|
5
8
|
export type FirestoreQueryDriverQueryFunction = <T>(query: Query<T>, ...queryConstraints: FirestoreQueryConstraint[]) => Query<T>;
|
|
9
|
+
/**
|
|
10
|
+
* Returns the platform-specific {@link FieldPath} sentinel for the document ID.
|
|
11
|
+
* Used internally by `whereDocumentId()` constraints.
|
|
12
|
+
*/
|
|
6
13
|
export type FirestoreDocumentIdFieldPathAccessor = () => FieldPath;
|
|
14
|
+
/**
|
|
15
|
+
* Low-level driver for building queries from constraint objects.
|
|
16
|
+
*
|
|
17
|
+
* Tracks which constraint types (where, orderBy, limit, etc.) the current platform
|
|
18
|
+
* supports and provides the function to apply them to a query.
|
|
19
|
+
*/
|
|
7
20
|
export interface FirestoreQueryConstraintFunctionsDriver {
|
|
8
21
|
readonly availableConstraintTypes: Set<string>;
|
|
9
22
|
readonly query: FirestoreQueryDriverQueryFunction;
|
|
10
23
|
readonly documentIdFieldPath: FirestoreDocumentIdFieldPathAccessor;
|
|
11
24
|
}
|
|
12
25
|
/**
|
|
13
|
-
*
|
|
26
|
+
* Driver interface for executing Firestore queries.
|
|
27
|
+
*
|
|
28
|
+
* Extends {@link FirestoreQueryConstraintFunctionsDriver} with methods for counting,
|
|
29
|
+
* fetching, and streaming query results. Platform implementations (Web SDK, Admin SDK,
|
|
30
|
+
* test mocks) each provide their own implementation.
|
|
31
|
+
*
|
|
32
|
+
* @see {@link FirestoreAccessorDriver} for the complementary document CRUD driver
|
|
14
33
|
*/
|
|
15
34
|
export interface FirestoreQueryDriver extends FirestoreQueryConstraintFunctionsDriver {
|
|
16
35
|
/**
|
|
@@ -1,9 +1,32 @@
|
|
|
1
1
|
import { type Query } from '../types';
|
|
2
2
|
import { type FirestoreQueryConstraintHandlerMap } from '../query/constraint';
|
|
3
3
|
import { type FirestoreQueryConstraintFunctionsDriver } from './query';
|
|
4
|
+
/**
|
|
5
|
+
* Configuration for building a {@link FirestoreQueryConstraintFunctionsDriver} from a
|
|
6
|
+
* handler map pattern. Each platform (Web SDK, Admin SDK) provides its own handler map
|
|
7
|
+
* that maps constraint type strings to builder functions.
|
|
8
|
+
*
|
|
9
|
+
* @template B - The platform-specific query builder type (e.g., the Firestore Query itself)
|
|
10
|
+
*/
|
|
4
11
|
export interface MakeFirestoreQueryConstraintFunctionsDriver<B> extends Omit<FirestoreQueryConstraintFunctionsDriver, 'query' | 'availableConstraintTypes'> {
|
|
12
|
+
/** Maps constraint type names to handler functions that apply them to the builder. */
|
|
5
13
|
mapping: FirestoreQueryConstraintHandlerMap<B>;
|
|
14
|
+
/** Initializes a builder from a base query. */
|
|
6
15
|
init: <T>(query: Query<T>) => B;
|
|
16
|
+
/** Converts the finalized builder back to a query. */
|
|
7
17
|
build: <T>(builder: B) => Query<T>;
|
|
8
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Creates a {@link FirestoreQueryConstraintFunctionsDriver} from a handler map configuration.
|
|
21
|
+
*
|
|
22
|
+
* This factory enables platform-specific query implementations to register their constraint
|
|
23
|
+
* handlers declaratively. The returned driver applies constraints sequentially using the
|
|
24
|
+
* registered handlers and throws if an unsupported constraint type is encountered.
|
|
25
|
+
*
|
|
26
|
+
* @template B - The platform-specific query builder type
|
|
27
|
+
* @param config - The handler map configuration
|
|
28
|
+
* @returns A fully configured constraint functions driver
|
|
29
|
+
*
|
|
30
|
+
* @throws {Error} When a query uses a constraint type not present in the handler map
|
|
31
|
+
*/
|
|
9
32
|
export declare function makeFirestoreQueryConstraintFunctionsDriver<B>(config: MakeFirestoreQueryConstraintFunctionsDriver<B>): FirestoreQueryConstraintFunctionsDriver;
|
|
@@ -1,25 +1,37 @@
|
|
|
1
1
|
import { type Firestore, type Transaction, type ReadOnlyTransactionOptions, type ReadWriteTransactionOptions } from '../types';
|
|
2
2
|
/**
|
|
3
|
-
* Function that
|
|
3
|
+
* Function that executes within a Firestore transaction context and returns a result.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The return type of the transaction
|
|
4
6
|
*/
|
|
5
7
|
export type TransactionFunction<T = unknown> = (transaction: Transaction) => Promise<T>;
|
|
6
8
|
/**
|
|
7
|
-
*
|
|
9
|
+
* Executes a Firestore transaction by creating a new {@link Transaction}, running the provided
|
|
10
|
+
* function within it, and returning the result. Handles retries automatically on contention.
|
|
8
11
|
*
|
|
9
|
-
* All transactions
|
|
10
|
-
* the transaction in a bad state
|
|
12
|
+
* **Important:** All transactions must include at least one read before any writes.
|
|
13
|
+
* Omitting reads can leave the transaction in a bad state and defeats the idempotent
|
|
14
|
+
* purpose of transactions.
|
|
11
15
|
*/
|
|
12
16
|
export type RunTransaction = <T>(fn: TransactionFunction<T>, options?: RunTransactionParams) => Promise<T>;
|
|
17
|
+
/**
|
|
18
|
+
* Options for controlling transaction behavior — either read-only or read-write.
|
|
19
|
+
*/
|
|
13
20
|
export type RunTransactionParams = ReadOnlyTransactionOptions | ReadWriteTransactionOptions;
|
|
14
21
|
/**
|
|
15
|
-
*
|
|
22
|
+
* Creates a {@link RunTransaction} function bound to the given Firestore instance.
|
|
23
|
+
* Used by the driver layer to provide transaction capabilities per-Firestore.
|
|
16
24
|
*/
|
|
17
25
|
export type RunTransactionForFirestoreFactory = (firestore: Firestore) => RunTransaction;
|
|
26
|
+
/**
|
|
27
|
+
* Holds a reference to a {@link RunTransaction} function for executing transactions.
|
|
28
|
+
*/
|
|
18
29
|
export interface RunTransactionFactoryReference {
|
|
19
30
|
readonly runTransaction: RunTransaction;
|
|
20
31
|
}
|
|
21
32
|
/**
|
|
22
|
-
* Driver for
|
|
33
|
+
* Driver component that provides {@link Transaction} execution for a Firestore instance.
|
|
34
|
+
* Implemented by platform-specific drivers (Web SDK, Admin SDK).
|
|
23
35
|
*/
|
|
24
36
|
export interface FirestoreTransactionFactoryDriver {
|
|
25
37
|
readonly transactionFactoryForFirestore: RunTransactionForFirestoreFactory;
|