@dereekb/firebase 13.2.2 → 13.3.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 +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,14 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Platform-agnostic Firestore type definitions.
|
|
3
|
+
*
|
|
4
|
+
* These types mirror the interfaces from both `@google-cloud/firestore` (Admin SDK) and
|
|
5
|
+
* `firebase/firestore` (Web SDK) so that the rest of the codebase can work with either
|
|
6
|
+
* platform without importing platform-specific packages directly. This is the foundation
|
|
7
|
+
* of the cross-platform driver abstraction.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
1
11
|
import { StringKeyPropertyKeys } from '@dereekb/util';
|
|
2
12
|
import { UnionToIntersection } from 'ts-essentials';
|
|
3
13
|
import { FirestoreModelKey, FirestoreModelId } from './collection';
|
|
14
|
+
/**
|
|
15
|
+
* Minimal shape of the Firebase Web SDK Firestore instance.
|
|
16
|
+
*/
|
|
4
17
|
export type FirebaseFirestoreLikeFirestore = {
|
|
5
18
|
type: string;
|
|
6
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* Minimal shape of the Google Cloud Admin SDK Firestore instance.
|
|
22
|
+
*/
|
|
7
23
|
export type GoogleCloudLikeFirestore = {
|
|
8
24
|
terminate(): Promise<void>;
|
|
9
25
|
};
|
|
10
26
|
/**
|
|
11
|
-
*
|
|
27
|
+
* Union type representing either a Web SDK or Admin SDK Firestore instance.
|
|
28
|
+
*
|
|
29
|
+
* Code that needs the concrete type should cast through the driver layer.
|
|
30
|
+
* Direct access to this type is rarely needed outside of driver implementations.
|
|
12
31
|
*/
|
|
13
32
|
export type Firestore = FirebaseFirestoreLikeFirestore | GoogleCloudLikeFirestore;
|
|
14
33
|
export type Primitive = string | number | boolean | undefined | null;
|
|
@@ -34,9 +53,28 @@ export type UpdateData<T> = T extends Primitive ? T : T extends {} ? {
|
|
|
34
53
|
export interface FieldPath {
|
|
35
54
|
isEqual(other: FieldPath): boolean;
|
|
36
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* A field path expressed as either a dot-separated string or a {@link FieldPath} object.
|
|
58
|
+
*/
|
|
37
59
|
export type FieldPathOrStringPath = string | FieldPath;
|
|
60
|
+
/**
|
|
61
|
+
* A type-safe field path that restricts string keys to those present on `T`.
|
|
62
|
+
*/
|
|
38
63
|
export type FieldPathOrStringPathOf<T = object> = StringKeyPropertyKeys<T> | FieldPath;
|
|
64
|
+
/**
|
|
65
|
+
* Extracts the top-level field name from each path, discarding nested segments.
|
|
66
|
+
*
|
|
67
|
+
* @param input - Array of field paths (strings or FieldPath objects)
|
|
68
|
+
* @returns Array of top-level field name strings
|
|
69
|
+
*/
|
|
39
70
|
export declare function asTopLevelFieldPaths(input: (string | FieldPath)[]): string[];
|
|
71
|
+
/**
|
|
72
|
+
* Extracts the top-level field name from a path, discarding nested segments.
|
|
73
|
+
* For example, `'address.city'` returns `'address'`.
|
|
74
|
+
*
|
|
75
|
+
* @param input - A field path (string or FieldPath object)
|
|
76
|
+
* @returns The top-level field name
|
|
77
|
+
*/
|
|
40
78
|
export declare function asTopLevelFieldPath(input: string | FieldPath): string;
|
|
41
79
|
export interface Timestamp {
|
|
42
80
|
readonly seconds: number;
|
|
@@ -2,24 +2,76 @@ import { type ArrayOrValue, type FactoryWithRequiredInput, type IdBatchVerifier,
|
|
|
2
2
|
import { type FirestoreCollectionLike } from '../collection';
|
|
3
3
|
import { type FirestoreQueryConstraint } from '../query/constraint';
|
|
4
4
|
import { type DocumentSnapshot } from '../types';
|
|
5
|
+
/**
|
|
6
|
+
* Base configuration for creating a Firestore-backed {@link IdBatchVerifier}.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The Firestore document data type
|
|
9
|
+
* @template I - The identifier/key type (must be a primitive key)
|
|
10
|
+
*/
|
|
5
11
|
export type FirestoreIdBatchVerifierFactoryBaseConfig<T, I extends PrimativeKey> = {
|
|
6
12
|
/**
|
|
7
|
-
*
|
|
13
|
+
* Extracts the identifier(s) from a queried document snapshot.
|
|
14
|
+
* Used to determine which keys from a batch already exist in Firestore.
|
|
8
15
|
*/
|
|
9
16
|
readKeys: ReadMultipleKeysFunction<DocumentSnapshot<T>, I>;
|
|
10
17
|
};
|
|
18
|
+
/**
|
|
19
|
+
* Configuration that queries a specific document field for existence checks.
|
|
20
|
+
* Use `'_id'` as the field value to query by document ID instead of a data field.
|
|
21
|
+
*
|
|
22
|
+
* @template T - The Firestore document data type
|
|
23
|
+
* @template I - The identifier/key type
|
|
24
|
+
*/
|
|
11
25
|
export type FirestoreIdBatchVerifierFactoryFieldsQueryConfig<T, I extends PrimativeKey> = FirestoreIdBatchVerifierFactoryBaseConfig<T, I> & {
|
|
12
26
|
/**
|
|
13
|
-
*
|
|
27
|
+
* The document field to query with an `in` filter, or `'_id'` to query by document ID.
|
|
14
28
|
*/
|
|
15
29
|
fieldToQuery: keyof T | '_id';
|
|
16
30
|
};
|
|
31
|
+
/**
|
|
32
|
+
* Configuration that provides custom query constraints for existence checks.
|
|
33
|
+
*
|
|
34
|
+
* @template T - The Firestore document data type
|
|
35
|
+
* @template I - The identifier/key type
|
|
36
|
+
*/
|
|
17
37
|
export type FirestoreIdBatchVerifierFactoryMakeQueryConfig<T, I extends PrimativeKey> = FirestoreIdBatchVerifierFactoryBaseConfig<T, I> & {
|
|
18
38
|
/**
|
|
19
|
-
*
|
|
39
|
+
* Creates query constraints to find documents matching the given keys.
|
|
20
40
|
*/
|
|
21
41
|
makeQueryConstraints: FactoryWithRequiredInput<ArrayOrValue<FirestoreQueryConstraint>, I[]>;
|
|
22
42
|
};
|
|
43
|
+
/**
|
|
44
|
+
* Union config type: either specify a field to query or provide custom query constraints.
|
|
45
|
+
*/
|
|
23
46
|
export type FirestoreIdBatchVerifierFactoryConfig<T, I extends PrimativeKey> = FirestoreIdBatchVerifierFactoryMakeQueryConfig<T, I> | FirestoreIdBatchVerifierFactoryFieldsQueryConfig<T, I>;
|
|
47
|
+
/**
|
|
48
|
+
* Factory that creates an {@link IdBatchVerifier} bound to a specific Firestore collection.
|
|
49
|
+
*
|
|
50
|
+
* @template T - The Firestore document data type
|
|
51
|
+
* @template I - The identifier/key type
|
|
52
|
+
*/
|
|
24
53
|
export type FirestoreIdBatchVerifierFactory<T, I extends PrimativeKey> = FactoryWithRequiredInput<IdBatchVerifier<I, I>, FirestoreCollectionLike<T>>;
|
|
54
|
+
/**
|
|
55
|
+
* Creates a factory for Firestore-backed {@link IdBatchVerifier} instances.
|
|
56
|
+
*
|
|
57
|
+
* The verifier checks which keys from a batch do **not** already exist in a Firestore
|
|
58
|
+
* collection, respecting Firestore's `where('in')` limit of {@link FIRESTORE_MAX_WHERE_IN_FILTER_ARGS_COUNT}
|
|
59
|
+
* items per query. This is used for batch ID generation to ensure uniqueness.
|
|
60
|
+
*
|
|
61
|
+
* @template T - The Firestore document data type
|
|
62
|
+
* @template I - The identifier/key type
|
|
63
|
+
* @param config - Specifies how to query for existing keys (by field or custom constraints)
|
|
64
|
+
* @returns A factory that produces verifiers bound to a specific collection
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* const factory = firestoreIdBatchVerifierFactory<MyDoc, string>({
|
|
69
|
+
* fieldToQuery: '_id',
|
|
70
|
+
* readKeys: (snapshot) => [snapshot.id]
|
|
71
|
+
* });
|
|
72
|
+
*
|
|
73
|
+
* const verifier = factory(myCollection);
|
|
74
|
+
* // verifier can now check batches of IDs for uniqueness
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
25
77
|
export declare function firestoreIdBatchVerifierFactory<T, I extends PrimativeKey>(config: FirestoreIdBatchVerifierFactoryConfig<T, I>): FirestoreIdBatchVerifierFactory<T, I>;
|
|
@@ -1,9 +1,44 @@
|
|
|
1
1
|
import { type TransformAndValidateFunctionResult } from '@dereekb/model';
|
|
2
|
+
/**
|
|
3
|
+
* A validated create action for a Firebase function.
|
|
4
|
+
*
|
|
5
|
+
* Wraps a {@link TransformAndValidateFunctionResult} that validates parameters `P` then executes a create operation
|
|
6
|
+
* returning `T`. Optionally accepts an input `I`.
|
|
7
|
+
*
|
|
8
|
+
* @template P - the validated parameters type
|
|
9
|
+
* @template T - the created entity type
|
|
10
|
+
* @template I - optional input for the create operation
|
|
11
|
+
*/
|
|
2
12
|
export type FirebaseFunctionCreateAction<P extends object, T, I = void> = I extends void ? TransformAndValidateFunctionResult<P, () => Promise<T>> : TransformAndValidateFunctionResult<P, (input: I) => Promise<T>>;
|
|
13
|
+
/**
|
|
14
|
+
* Async variant of {@link FirebaseFunctionCreateAction} — the action itself is produced asynchronously.
|
|
15
|
+
*/
|
|
3
16
|
export type AsyncFirebaseFunctionCreateAction<P extends object, T, I = void> = Promise<FirebaseFunctionCreateAction<P, T, I>>;
|
|
17
|
+
/**
|
|
18
|
+
* A validated read action for a Firebase function. Structurally identical to {@link FirebaseFunctionCreateAction}.
|
|
19
|
+
*/
|
|
4
20
|
export type FirebaseFunctionReadAction<P extends object, T, I = void> = FirebaseFunctionCreateAction<P, T, I>;
|
|
21
|
+
/**
|
|
22
|
+
* Async variant of {@link FirebaseFunctionReadAction}.
|
|
23
|
+
*/
|
|
5
24
|
export type AsyncFirebaseFunctionReadAction<P extends object, T, I = void> = Promise<FirebaseFunctionReadAction<P, T, I>>;
|
|
25
|
+
/**
|
|
26
|
+
* A validated update action for a Firebase function.
|
|
27
|
+
*
|
|
28
|
+
* Takes the entity `T` as input and returns the updated entity.
|
|
29
|
+
*/
|
|
6
30
|
export type FirebaseFunctionUpdateAction<P extends object, T> = TransformAndValidateFunctionResult<P, (input: T) => Promise<T>>;
|
|
31
|
+
/**
|
|
32
|
+
* Async variant of {@link FirebaseFunctionUpdateAction}.
|
|
33
|
+
*/
|
|
7
34
|
export type AsyncFirebaseFunctionUpdateAction<P extends object, T> = Promise<FirebaseFunctionUpdateAction<P, T>>;
|
|
35
|
+
/**
|
|
36
|
+
* A validated delete action for a Firebase function.
|
|
37
|
+
*
|
|
38
|
+
* Takes the entity `T` as input and returns void on successful deletion.
|
|
39
|
+
*/
|
|
8
40
|
export type FirebaseFunctionDeleteAction<P extends object, T> = TransformAndValidateFunctionResult<P, (input: T) => Promise<void>>;
|
|
41
|
+
/**
|
|
42
|
+
* Async variant of {@link FirebaseFunctionDeleteAction}.
|
|
43
|
+
*/
|
|
9
44
|
export type AsyncFirebaseFunctionDeleteAction<P extends object, T> = Promise<FirebaseFunctionDeleteAction<P, T>>;
|
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
import { type FirebaseAuthContext } from '../auth/auth.context';
|
|
2
2
|
import { type FirebasePermissionContext, type FirebasePermissionErrorContext } from './permission';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Base context for Firebase model operations, combining authentication, permission checks, and error handling.
|
|
5
|
+
*
|
|
6
|
+
* Passed to model services, permission evaluators, and action handlers to provide
|
|
7
|
+
* information about the current caller and their authorization state.
|
|
8
|
+
*
|
|
9
|
+
* See {@link FirebaseAuthContext} for auth details and {@link FirebasePermissionContext} for transaction access.
|
|
5
10
|
*/
|
|
6
11
|
export interface FirebaseModelContext extends FirebasePermissionContext, FirebasePermissionErrorContext, FirebaseAuthContext {
|
|
7
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Extends {@link FirebaseModelContext} with an application-specific context (e.g., Firestore collections).
|
|
15
|
+
*
|
|
16
|
+
* @template C - the application context type (typically the Firestore collections container)
|
|
17
|
+
*/
|
|
8
18
|
export interface FirebaseAppModelContext<C> extends FirebaseModelContext {
|
|
9
19
|
readonly app: C;
|
|
10
20
|
}
|
|
@@ -2,36 +2,53 @@ import { type ArrayOrValue, type Maybe } from '@dereekb/util';
|
|
|
2
2
|
import { type DocumentReferenceRef } from '../firestore/reference';
|
|
3
3
|
import { type FirestoreModelKey, type FirestoreModelType, type FirestoreModelTypeRef } from '../firestore/collection/collection';
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Standard CRUD call types used by the `callModel` Firebase function pattern.
|
|
6
6
|
*/
|
|
7
7
|
export type KnownOnCallFunctionType = 'create' | 'read' | 'update' | 'delete';
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* Call type identifier — one of the standard CRUD types or a custom string.
|
|
10
10
|
*/
|
|
11
11
|
export type OnCallFunctionType = KnownOnCallFunctionType | string;
|
|
12
|
+
/**
|
|
13
|
+
* Parameters for a typed model call through the `callModel` Firebase function.
|
|
14
|
+
*
|
|
15
|
+
* Combines the target model type, CRUD call type, optional specifier for sub-operations,
|
|
16
|
+
* and the call payload. This is the standard envelope format for all model API calls.
|
|
17
|
+
*
|
|
18
|
+
* @template T - the call data payload type
|
|
19
|
+
*/
|
|
12
20
|
export interface OnCallTypedModelParams<T = unknown> extends FirestoreModelTypeRef {
|
|
13
21
|
/**
|
|
14
|
-
*
|
|
22
|
+
* CRUD call type (create, read, update, delete) or a custom action type.
|
|
15
23
|
*/
|
|
16
24
|
readonly call?: Maybe<OnCallFunctionType>;
|
|
17
25
|
/**
|
|
18
|
-
*
|
|
26
|
+
* Sub-function specifier for distinguishing different operations within the same call type.
|
|
19
27
|
*/
|
|
20
28
|
readonly specifier?: string;
|
|
21
29
|
/**
|
|
22
|
-
*
|
|
30
|
+
* The call payload data.
|
|
23
31
|
*/
|
|
24
32
|
readonly data: T;
|
|
25
33
|
}
|
|
26
34
|
/**
|
|
27
|
-
*
|
|
35
|
+
* Function that creates {@link OnCallTypedModelParams} for a given model type, pre-configured with a call type.
|
|
28
36
|
*/
|
|
29
37
|
export type OnCallTypeModelParamsFunction = <T>(modelTypeInput: FirestoreModelType | FirestoreModelTypeRef, data: T, specifier?: string) => OnCallTypedModelParams<T>;
|
|
30
38
|
/**
|
|
31
|
-
* Creates
|
|
39
|
+
* Creates an {@link OnCallTypeModelParamsFunction} pre-configured with the given call type.
|
|
32
40
|
*
|
|
33
|
-
* @
|
|
34
|
-
*
|
|
41
|
+
* The returned function builds {@link OnCallTypedModelParams} for any model type.
|
|
42
|
+
*
|
|
43
|
+
* @param call - the CRUD call type to embed in generated params
|
|
44
|
+
* @throws {Error} When `modelType` is not provided or empty.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* const createParams = onCallTypedModelParamsFunction('create');
|
|
49
|
+
* const params = createParams('notification', { title: 'Hello' });
|
|
50
|
+
* // params === { call: 'create', modelType: 'notification', data: { title: 'Hello' } }
|
|
51
|
+
* ```
|
|
35
52
|
*/
|
|
36
53
|
export declare function onCallTypedModelParamsFunction(call?: Maybe<OnCallFunctionType>): OnCallTypeModelParamsFunction;
|
|
37
54
|
/**
|
|
@@ -82,11 +99,30 @@ export type OnCallUpdateModelParams<T = unknown> = OnCallTypedModelParams<T>;
|
|
|
82
99
|
* OnCallTypedModelParams for Delete calls.
|
|
83
100
|
*/
|
|
84
101
|
export type OnCallDeleteModelParams<T = unknown> = OnCallTypedModelParams<T>;
|
|
102
|
+
/**
|
|
103
|
+
* Standard result returned by model create operations, containing the key(s) of the created document(s).
|
|
104
|
+
*/
|
|
85
105
|
export interface OnCallCreateModelResult {
|
|
86
106
|
/**
|
|
87
107
|
* Key(s)/Paths of the created object(s)
|
|
88
108
|
*/
|
|
89
109
|
readonly modelKeys: ArrayOrValue<FirestoreModelKey>;
|
|
90
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Creates an {@link OnCallCreateModelResult} from document references by extracting their paths as model keys.
|
|
113
|
+
*
|
|
114
|
+
* @param result - document reference(s) from a create operation
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```ts
|
|
118
|
+
* const result = onCallCreateModelResultWithDocs(createdDocs);
|
|
119
|
+
* // result.modelKeys === ['notifications/abc123']
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
91
122
|
export declare function onCallCreateModelResultWithDocs(result: ArrayOrValue<DocumentReferenceRef<unknown>>): OnCallCreateModelResult;
|
|
123
|
+
/**
|
|
124
|
+
* Creates an {@link OnCallCreateModelResult} from model key(s), normalizing to an array.
|
|
125
|
+
*
|
|
126
|
+
* @param modelKeys - the model key(s) of the created document(s)
|
|
127
|
+
*/
|
|
92
128
|
export declare function onCallCreateModelResult(modelKeys: ArrayOrValue<FirestoreModelKey>): OnCallCreateModelResult;
|
|
@@ -1,11 +1,26 @@
|
|
|
1
1
|
import { type FirebaseTransactionContext, type FirestoreCollectionLike, type FirestoreDocument, type FirestoreModelKey } from '../../firestore';
|
|
2
2
|
import { type InContextModelLoader, type ModelLoader } from '@dereekb/model';
|
|
3
3
|
import { type Getter } from '@dereekb/util';
|
|
4
|
+
/**
|
|
5
|
+
* Context type for model loading operations — requires optional transaction support.
|
|
6
|
+
*/
|
|
4
7
|
export type FirebaseModelLoaderContext = FirebaseTransactionContext;
|
|
8
|
+
/**
|
|
9
|
+
* Function that retrieves a {@link FirestoreCollectionLike} from a context, used by loaders to access the correct collection.
|
|
10
|
+
*/
|
|
5
11
|
export type FirebaseModelGetFirestoreCollectionFunction<C extends FirebaseModelLoaderContext, T, D extends FirestoreDocument<T>> = (context: C) => FirestoreCollectionLike<T, D>;
|
|
12
|
+
/**
|
|
13
|
+
* Provides access to a Firestore collection for a specific model type within a given context.
|
|
14
|
+
*/
|
|
6
15
|
export interface FirebaseModelCollectionLoader<C extends FirebaseModelLoaderContext, T, D extends FirestoreDocument<T>> {
|
|
7
16
|
readonly getFirestoreCollection: FirebaseModelGetFirestoreCollectionFunction<C, T, D>;
|
|
8
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Loads a {@link FirestoreDocument} wrapper for a given model key and context.
|
|
20
|
+
*
|
|
21
|
+
* Does not verify that the document actually exists in Firestore — it creates a document reference
|
|
22
|
+
* that can then be used for reads, writes, or permission checks.
|
|
23
|
+
*/
|
|
9
24
|
export interface FirebaseModelLoader<C extends FirebaseModelLoaderContext, T, D extends FirestoreDocument<T>> extends ModelLoader<C, D> {
|
|
10
25
|
/**
|
|
11
26
|
* Loads a FirestoreDocument for the input key.
|
|
@@ -17,10 +32,29 @@ export interface FirebaseModelLoader<C extends FirebaseModelLoaderContext, T, D
|
|
|
17
32
|
*/
|
|
18
33
|
loadModelForKey(key: FirestoreModelKey, context: C): D;
|
|
19
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Creates a {@link FirebaseModelLoader} that loads document wrappers from the given collection function.
|
|
37
|
+
*
|
|
38
|
+
* Automatically uses a transaction accessor when the context has an active transaction.
|
|
39
|
+
*
|
|
40
|
+
* @param getFirestoreCollection - function to retrieve the Firestore collection from context
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* const loader = firebaseModelLoader((ctx) => ctx.app.notifications);
|
|
45
|
+
* const doc = loader.loadModelForKey('notifications/abc123', context);
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
20
48
|
export declare function firebaseModelLoader<C extends FirebaseModelLoaderContext, T, D extends FirestoreDocument<T>>(getFirestoreCollection: FirebaseModelGetFirestoreCollectionFunction<C, T, D>): FirebaseModelLoader<C, T, D>;
|
|
49
|
+
/**
|
|
50
|
+
* Context-bound variant of {@link FirebaseModelCollectionLoader} — the context is already captured.
|
|
51
|
+
*/
|
|
21
52
|
export interface InContextFirebaseModelCollectionLoader<T, D extends FirestoreDocument<T>> {
|
|
22
53
|
readonly getFirestoreCollection: Getter<FirestoreCollectionLike<T, D>>;
|
|
23
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Context-bound variant of {@link FirebaseModelLoader} — the context is already captured.
|
|
57
|
+
*/
|
|
24
58
|
export interface InContextFirebaseModelLoader<T, D extends FirestoreDocument<T>> extends InContextModelLoader<D> {
|
|
25
59
|
loadModelForKey(key: FirestoreModelKey): D;
|
|
26
60
|
}
|
|
@@ -28,6 +62,9 @@ export interface InContextFirebaseModelLoader<T, D extends FirestoreDocument<T>>
|
|
|
28
62
|
* Type used to convert a FirebaseModelLoader into an InContextFirebaseModelLoader
|
|
29
63
|
*/
|
|
30
64
|
export type AsInContextFirebaseModelLoader<X> = X extends FirebaseModelLoader<infer C, infer T, infer D> ? InContextFirebaseModelLoader<T, D> : never;
|
|
65
|
+
/**
|
|
66
|
+
* A loader that is already bound to a specific model document instance.
|
|
67
|
+
*/
|
|
31
68
|
export interface InModelContextFirebaseModelLoader<T, D extends FirestoreDocument<T>> {
|
|
32
69
|
readonly model: D;
|
|
33
70
|
}
|
|
@@ -1,24 +1,46 @@
|
|
|
1
1
|
import { type Type } from 'arktype';
|
|
2
2
|
import { type FirestoreModelKey, type FirestoreModelKeyRef } from '../../firestore/collection/collection';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* API parameter type that targets a specific Firestore model by its full key path (e.g., `"collection/id"`).
|
|
5
|
+
*
|
|
6
|
+
* Used in `callModel` function parameter validation.
|
|
5
7
|
*/
|
|
6
8
|
export interface TargetModelParams extends FirestoreModelKeyRef {
|
|
7
9
|
readonly key: FirestoreModelKey;
|
|
8
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* ArkType validator for {@link TargetModelParams} — requires a valid full model key.
|
|
13
|
+
*/
|
|
9
14
|
export declare const targetModelParamsType: Type<TargetModelParams>;
|
|
15
|
+
/**
|
|
16
|
+
* Variant of {@link TargetModelParams} where the key is optional, allowing the server to infer it from context.
|
|
17
|
+
*/
|
|
10
18
|
export interface InferredTargetModelParams extends Partial<FirestoreModelKeyRef> {
|
|
11
19
|
readonly key?: FirestoreModelKey;
|
|
12
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* ArkType validator for {@link InferredTargetModelParams}.
|
|
23
|
+
*/
|
|
13
24
|
export declare const inferredTargetModelParamsType: Type<InferredTargetModelParams>;
|
|
14
25
|
/**
|
|
15
|
-
*
|
|
26
|
+
* API parameter type that targets a specific Firestore model by its document ID only (not the full path).
|
|
27
|
+
*
|
|
28
|
+
* Used when the collection is already known from the call context.
|
|
16
29
|
*/
|
|
17
30
|
export interface TargetModelIdParams extends FirestoreModelKeyRef {
|
|
18
31
|
readonly key: FirestoreModelKey;
|
|
19
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* ArkType validator for {@link TargetModelIdParams} — requires a valid document ID.
|
|
35
|
+
*/
|
|
20
36
|
export declare const targetModelIdParamsType: Type<TargetModelIdParams>;
|
|
37
|
+
/**
|
|
38
|
+
* Variant of {@link TargetModelIdParams} where the key is optional.
|
|
39
|
+
*/
|
|
21
40
|
export interface InferredTargetModelIdParams extends Partial<FirestoreModelKeyRef> {
|
|
22
41
|
readonly key?: FirestoreModelKey;
|
|
23
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* ArkType validator for {@link InferredTargetModelIdParams}.
|
|
45
|
+
*/
|
|
24
46
|
export declare const inferredTargetModelIdParamsType: Type<InferredTargetModelIdParams>;
|
|
@@ -5,21 +5,88 @@ import { type FirestoreModelIdentity, type FirestoreModelKey, type FirestoreMode
|
|
|
5
5
|
import { type FirebaseModelCollectionLoader, type FirebaseModelLoader, type InContextFirebaseModelCollectionLoader, type InContextFirebaseModelLoader } from './model/model.loader';
|
|
6
6
|
import { type InContextFirebaseModelPermissionService, type FirebasePermissionContext, type FirebaseModelPermissionService, type FirebasePermissionServiceInstanceDelegate, type InModelContextFirebaseModelPermissionService, type FirebasePermissionErrorContext } from './permission';
|
|
7
7
|
import { type ContextGrantedModelRolesReader } from './permission/permission.service.role';
|
|
8
|
+
/**
|
|
9
|
+
* Context type required by the model service layer — combines permission and error handling contexts.
|
|
10
|
+
*/
|
|
8
11
|
export type FirebaseModelServiceContext = FirebasePermissionContext & FirebasePermissionErrorContext;
|
|
12
|
+
/**
|
|
13
|
+
* Unified service for a single Firestore model type that combines permission checking, model loading, and collection access.
|
|
14
|
+
*
|
|
15
|
+
* Each model type in the application (e.g., Notification, StorageFile) gets its own {@link FirebaseModelService}.
|
|
16
|
+
* The service is the central point for CRUD operations that need permission-aware model access.
|
|
17
|
+
*
|
|
18
|
+
* @template C - the model context type
|
|
19
|
+
* @template T - the Firestore document data type
|
|
20
|
+
* @template D - the FirestoreDocument wrapper type
|
|
21
|
+
* @template R - the granted role type for this model
|
|
22
|
+
*/
|
|
9
23
|
export interface FirebaseModelService<C extends FirebaseModelServiceContext, T, D extends FirestoreDocument<T> = FirestoreDocument<T>, R extends GrantedRole = GrantedRole> extends FirebaseModelPermissionService<C, T, D, R>, FirebaseModelLoader<C, T, D>, FirebaseModelCollectionLoader<any, T, D> {
|
|
10
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Lazy getter for a {@link FirebaseModelService}, typically used in the service factory map.
|
|
27
|
+
*/
|
|
11
28
|
export type FirebaseModelServiceGetter<C extends FirebaseModelServiceContext, T, D extends FirestoreDocument<T> = FirestoreDocument<T>, R extends GrantedRole = GrantedRole> = Getter<FirebaseModelService<C, T, D, R>>;
|
|
29
|
+
/**
|
|
30
|
+
* Configuration for creating a {@link FirebaseModelService} via {@link firebaseModelService}.
|
|
31
|
+
*
|
|
32
|
+
* Provides the collection loader and the role-mapping delegate. Model loading is derived automatically
|
|
33
|
+
* from the collection loader.
|
|
34
|
+
*/
|
|
12
35
|
export interface FirebaseModelServiceConfig<C extends FirebaseModelServiceContext, T, D extends FirestoreDocument<T> = FirestoreDocument<T>, R extends GrantedRole = GrantedRole> extends Omit<FirebasePermissionServiceInstanceDelegate<C, T, D, R>, 'loadModelForKey'>, FirebaseModelCollectionLoader<C, T, D> {
|
|
13
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Creates a {@link FirebaseModelService} that wires together model loading and permission evaluation.
|
|
39
|
+
*
|
|
40
|
+
* @param config - collection loader and role mapping functions
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* const notificationService = firebaseModelService({
|
|
45
|
+
* getFirestoreCollection: (context) => context.app.notification,
|
|
46
|
+
* roleMapForModel: (output, context, model) => computeRoles(output, context)
|
|
47
|
+
* });
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
14
50
|
export declare function firebaseModelService<C extends FirebaseModelServiceContext, T, D extends FirestoreDocument<T> = FirestoreDocument<T>, R extends GrantedRole = GrantedRole>(config: FirebaseModelServiceConfig<C, T, D, R>): FirebaseModelService<C, T, D, R>;
|
|
51
|
+
/**
|
|
52
|
+
* Cached getter that lazily creates and memoizes a {@link FirebaseModelService}.
|
|
53
|
+
*/
|
|
15
54
|
export type FirebaseModelServiceFactory<C extends FirebaseModelServiceContext, T, D extends FirestoreDocument<T> = FirestoreDocument<T>, R extends GrantedRole = GrantedRole> = Getter<FirebaseModelService<C, T, D, R>>;
|
|
55
|
+
/**
|
|
56
|
+
* Creates a {@link FirebaseModelServiceFactory} that lazily instantiates and caches the service.
|
|
57
|
+
*
|
|
58
|
+
* @param config - the service configuration
|
|
59
|
+
*/
|
|
16
60
|
export declare function firebaseModelServiceFactory<C extends FirebaseModelServiceContext, T, D extends FirestoreDocument<T> = FirestoreDocument<T>, R extends GrantedRole = GrantedRole>(config: FirebaseModelServiceConfig<C, T, D, R>): FirebaseModelServiceFactory<C, T, D, R>;
|
|
61
|
+
/**
|
|
62
|
+
* A context-bound model service with permission checking, model loading, and collection access.
|
|
63
|
+
*
|
|
64
|
+
* Does not include the `forKey` method — use {@link InContextFirebaseModelService} for the full interface.
|
|
65
|
+
*/
|
|
17
66
|
export type LimitedInContextFirebaseModelService<C extends FirebasePermissionErrorContext, T, D extends FirestoreDocument<T> = FirestoreDocument<T>, R extends GrantedRole = GrantedRole> = InContextFirebaseModelPermissionService<C, T, D, R> & InContextFirebaseModelLoader<T, D> & InContextFirebaseModelCollectionLoader<T, D> & {
|
|
18
67
|
forKey: (key: FirestoreModelKey) => InModelContextFirebaseModelService<C, T, D, R>;
|
|
19
68
|
};
|
|
69
|
+
/**
|
|
70
|
+
* Full context-bound model service that can also be called directly with a model/key to get a model-bound service.
|
|
71
|
+
*
|
|
72
|
+
* Calling `service(modelOrKey)` returns an {@link InModelContextFirebaseModelService} with role checking and assertions.
|
|
73
|
+
* Also provides `forKey(key)` for key-based lookup.
|
|
74
|
+
*/
|
|
20
75
|
export type InContextFirebaseModelService<C extends FirebasePermissionErrorContext, T, D extends FirestoreDocument<T> = FirestoreDocument<T>, R extends GrantedRole = GrantedRole> = InModelContextFirebaseModelServiceFactory<C, T, D, R> & LimitedInContextFirebaseModelService<C, T, D, R>;
|
|
76
|
+
/**
|
|
77
|
+
* Factory that binds a {@link FirebaseModelService} to a specific context, producing an {@link InContextFirebaseModelService}.
|
|
78
|
+
*/
|
|
21
79
|
export type InContextFirebaseModelServiceFactory<C extends FirebasePermissionErrorContext, T, D extends FirestoreDocument<T> = FirestoreDocument<T>, R extends GrantedRole = GrantedRole> = (context: C) => InContextFirebaseModelService<C, T, D, R>;
|
|
80
|
+
/**
|
|
81
|
+
* Factory that binds a context-aware model service to a specific model document or key.
|
|
82
|
+
*/
|
|
22
83
|
export type InModelContextFirebaseModelServiceFactory<C extends FirebasePermissionErrorContext, T, D extends FirestoreDocument<T> = FirestoreDocument<T>, R extends GrantedRole = GrantedRole> = (modelOrKey: D | FirestoreModelKey) => InModelContextFirebaseModelService<C, T, D, R>;
|
|
84
|
+
/**
|
|
85
|
+
* A model service bound to both a context and a specific model document.
|
|
86
|
+
*
|
|
87
|
+
* Provides role-based access control via `roleReader()`, `requireRole()`, and `use()`.
|
|
88
|
+
* Can be called as a function with roles to get a {@link UsePromiseFunction} for the role reader.
|
|
89
|
+
*/
|
|
23
90
|
export type InModelContextFirebaseModelService<C extends FirebasePermissionErrorContext, T, D extends FirestoreDocument<T> = FirestoreDocument<T>, R extends GrantedRole = GrantedRole> = InModelContextFirebaseModelPermissionService<C, T, D, R> & InModelContextFirebaseModelServiceUseFunction<C, T, D, R> & InContextFirebaseModelCollectionLoader<T, D> & {
|
|
24
91
|
roleReader: () => Promise<ContextGrantedModelRolesReader<C, T, D, R>>;
|
|
25
92
|
requireRole: (roles: ArrayOrValue<R>, setIncludes?: SetIncludesMode) => Promise<ContextGrantedModelRolesReader<C, T, D, R>>;
|
|
@@ -27,17 +94,39 @@ export type InModelContextFirebaseModelService<C extends FirebasePermissionError
|
|
|
27
94
|
use: UsePromiseFunction<ContextGrantedModelRolesReader<C, T, D, R>>;
|
|
28
95
|
};
|
|
29
96
|
export type InModelContextFirebaseModelServiceUseFunction<C extends FirebasePermissionErrorContext, T, D extends FirestoreDocument<T> = FirestoreDocument<T>, R extends GrantedRole = GrantedRole> = (roles: ArrayOrValue<R>, setIncludes?: SetIncludesMode) => UsePromiseFunction<ContextGrantedModelRolesReader<C, T, D, R>>;
|
|
97
|
+
/**
|
|
98
|
+
* Creates an {@link InContextFirebaseModelServiceFactory} from a service getter.
|
|
99
|
+
*
|
|
100
|
+
* The returned factory, when given a context, produces a callable service that can be invoked
|
|
101
|
+
* with a model or key to perform permission-checked operations.
|
|
102
|
+
*
|
|
103
|
+
* @param factory - lazy getter for the underlying model service
|
|
104
|
+
*/
|
|
30
105
|
export declare function inContextFirebaseModelServiceFactory<C extends FirebaseModelServiceContext, T, D extends FirestoreDocument<T> = FirestoreDocument<T>, R extends GrantedRole = GrantedRole>(factory: FirebaseModelServiceGetter<C, T, D, R>): InContextFirebaseModelServiceFactory<C, T, D, R>;
|
|
106
|
+
/**
|
|
107
|
+
* Map of model type identifiers to their corresponding {@link FirebaseModelServiceGetter} factories.
|
|
108
|
+
*
|
|
109
|
+
* Defines the full set of model services available in the application.
|
|
110
|
+
*/
|
|
31
111
|
export type FirebaseModelsServiceFactory<C extends FirebaseModelServiceContext, I extends FirestoreModelIdentity = FirestoreModelIdentity> = {
|
|
32
112
|
[J in FirestoreModelTypes<I>]: FirebaseModelServiceGetter<C, any>;
|
|
33
113
|
};
|
|
114
|
+
/**
|
|
115
|
+
* Provides access to the list of all registered model types.
|
|
116
|
+
*/
|
|
34
117
|
export type FirebaseModelsServiceTypesAccessor = {
|
|
35
118
|
allTypes(): FirestoreModelType[];
|
|
36
119
|
};
|
|
37
120
|
/**
|
|
38
|
-
*
|
|
121
|
+
* Multi-model service function that returns a context-bound service for any registered model type.
|
|
122
|
+
*
|
|
123
|
+
* Call with a model type key and context to get an {@link InContextFirebaseModelService} for that model.
|
|
124
|
+
* This is the top-level entry point for permission-checked model operations in server-side code.
|
|
39
125
|
*/
|
|
40
126
|
export type FirebaseModelsService<X extends FirebaseModelsServiceFactory<C>, C extends FirebaseModelServiceContext> = (<K extends keyof X>(type: K, context: C) => X[K] extends FirebaseModelServiceGetter<C, infer T, infer D, infer R> ? InContextFirebaseModelService<C, T, D, R> : never) & FirebaseModelsServiceTypesAccessor;
|
|
127
|
+
/**
|
|
128
|
+
* Extracts the union of model type keys from a {@link FirebaseModelsService}.
|
|
129
|
+
*/
|
|
41
130
|
export type FirebaseModelsServiceTypes<S extends FirebaseModelsService<any, any>> = S extends FirebaseModelsService<infer X, any> ? keyof X : never;
|
|
42
131
|
/**
|
|
43
132
|
* Creates a new FirebaseModelsService.
|
|
@@ -55,15 +144,25 @@ export type FirebaseModelsServiceTypes<S extends FirebaseModelsService<any, any>
|
|
|
55
144
|
* @returns
|
|
56
145
|
*/
|
|
57
146
|
export declare function firebaseModelsService<X extends FirebaseModelsServiceFactory<C, I>, C extends FirebaseModelServiceContext, I extends FirestoreModelIdentity = FirestoreModelIdentity>(services: X): FirebaseModelsService<X, C>;
|
|
147
|
+
/**
|
|
148
|
+
* A context-bound multi-model service — call with a model type to get the context-bound single-model service.
|
|
149
|
+
*/
|
|
58
150
|
export type InContextFirebaseModelsService<Y> = FirebaseModelsServiceTypesAccessor & (Y extends FirebaseModelsService<infer X, infer C> ? <K extends keyof X>(type: K) => X[K] extends FirebaseModelServiceGetter<C, infer T, infer D, infer R> ? InContextFirebaseModelService<C, T, D, R> : never : never);
|
|
151
|
+
/**
|
|
152
|
+
* Factory that creates an {@link InContextFirebaseModelsService} from a context.
|
|
153
|
+
*/
|
|
59
154
|
export type InContextFirebaseModelsServiceFactory<Y> = FirebaseModelsServiceTypesAccessor & (Y extends FirebaseModelsService<infer X, infer C> ? (context: C) => InContextFirebaseModelsService<Y> : never);
|
|
60
155
|
/**
|
|
61
|
-
* Creates
|
|
156
|
+
* Creates an {@link InContextFirebaseModelsServiceFactory} from a {@link FirebaseModelsService}.
|
|
62
157
|
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
158
|
+
* The returned factory binds a context, so callers can then select individual model services by type.
|
|
159
|
+
*
|
|
160
|
+
* @param service - the multi-model service to wrap
|
|
65
161
|
*/
|
|
66
162
|
export declare function inContextFirebaseModelsServiceFactory<X extends FirebaseModelsServiceFactory<C, I>, C extends FirebaseModelServiceContext, I extends FirestoreModelIdentity = FirestoreModelIdentity>(service: FirebaseModelsService<X, C>): InContextFirebaseModelsServiceFactory<FirebaseModelsService<X, C>>;
|
|
163
|
+
/**
|
|
164
|
+
* Selection parameters for accessing a specific model by type and key (without role requirements).
|
|
165
|
+
*/
|
|
67
166
|
export type FirebaseModelsServiceSelection<Y extends FirebaseModelsService<any, any>, T extends FirebaseModelsServiceTypes<Y>> = Omit<UseFirebaseModelsServiceSelection<Y, T>, 'roles' | 'rolesSetIncludes'>;
|
|
68
167
|
export type FirebaseModelsServiceSelectionResult<Y extends FirebaseModelsService<any, any>, T extends FirebaseModelsServiceTypes<Y>> = Y extends FirebaseModelsService<infer X, infer C> ? (T extends keyof X ? (X[T] extends FirebaseModelServiceGetter<C, infer T, infer D, infer R> ? InModelContextFirebaseModelService<C, T, D, R> : never) : never) : never;
|
|
69
168
|
export type FirebaseModelsServiceSelectionResultRolesReader<Y extends FirebaseModelsService<any, any>, T extends FirebaseModelsServiceTypes<Y>> = Y extends FirebaseModelsService<infer X, infer C> ? (T extends keyof X ? (X[T] extends FirebaseModelServiceGetter<C, infer T, infer D, infer R> ? ContextGrantedModelRolesReader<C, T, D, R> : never) : never) : never;
|
|
@@ -76,6 +175,29 @@ export type UseFirebaseModelsServiceSelection<Y extends FirebaseModelsService<an
|
|
|
76
175
|
} : never : never;
|
|
77
176
|
export type UseFirebaseModelsServiceSelectionResult<Y extends FirebaseModelsService<any, any>, T extends FirebaseModelsServiceTypes<Y>> = Y extends FirebaseModelsService<infer X, infer C> ? (T extends keyof X ? (X[T] extends FirebaseModelServiceGetter<C, infer T, infer D, infer R> ? UsePromiseFunction<ContextGrantedModelRolesReader<C, T, D, R>> : never) : never) : never;
|
|
78
177
|
export type UseFirebaseModelsServiceSelectionUseFunction<Y extends FirebaseModelsService<any, any>, T extends FirebaseModelsServiceTypes<Y>, O> = Y extends FirebaseModelsService<infer X, infer C> ? (T extends keyof X ? (X[T] extends FirebaseModelServiceGetter<C, infer T, infer D, infer R> ? UseAsync<ContextGrantedModelRolesReader<C, T, D, R>, O> : never) : never) : never;
|
|
178
|
+
/**
|
|
179
|
+
* Selects a model-bound service instance from a multi-model service by type and key.
|
|
180
|
+
*
|
|
181
|
+
* @param service - the multi-model service
|
|
182
|
+
* @param type - the model type to select
|
|
183
|
+
* @param select - selection params including context and key
|
|
184
|
+
*/
|
|
79
185
|
export declare function selectFromFirebaseModelsService<Y extends FirebaseModelsService<any, any>, T extends FirebaseModelsServiceTypes<Y>>(service: Y, type: T, select: FirebaseModelsServiceSelection<Y, T>): FirebaseModelsServiceSelectionResult<Y, T>;
|
|
186
|
+
/**
|
|
187
|
+
* Selects a model-bound service and returns a {@link UsePromiseFunction} that lazily evaluates roles on use.
|
|
188
|
+
*
|
|
189
|
+
* If roles are provided, uses `requireUse` to assert them. Otherwise, returns the basic `use` function.
|
|
190
|
+
*
|
|
191
|
+
* @param service - the multi-model service
|
|
192
|
+
* @param type - the model type to select
|
|
193
|
+
* @param select - selection params including context, key, and optional role requirements
|
|
194
|
+
*/
|
|
80
195
|
export declare function useFirebaseModelsService<Y extends FirebaseModelsService<any, any>, T extends FirebaseModelsServiceTypes<Y>>(service: Y, type: T, select: UseFirebaseModelsServiceSelection<Y, T>): UseFirebaseModelsServiceSelectionResult<Y, T>;
|
|
196
|
+
/**
|
|
197
|
+
* Builds a type map from collection type to {@link FirestoreModelIdentity} for all registered models.
|
|
198
|
+
*
|
|
199
|
+
* Useful for routing incoming requests to the correct model service by collection path.
|
|
200
|
+
*
|
|
201
|
+
* @param inContextFirebaseModelsService - context-bound multi-model service
|
|
202
|
+
*/
|
|
81
203
|
export declare function buildFirebaseCollectionTypeModelTypeMap<Y extends FirebaseModelsService<any, any>>(inContextFirebaseModelsService: InContextFirebaseModelsService<Y>): import("..").FirestoreModelIdentityTypeMap;
|
|
@@ -2,9 +2,24 @@ import { type GrantedRole } from '@dereekb/model';
|
|
|
2
2
|
import { type ArrayOrValue } from '@dereekb/util';
|
|
3
3
|
import { type FirebaseTransactionContext } from '../../firestore/reference';
|
|
4
4
|
import { type FirebaseContextGrantedModelRoles } from './permission';
|
|
5
|
+
/**
|
|
6
|
+
* Context type for permission operations — provides optional Firestore transaction access.
|
|
7
|
+
*/
|
|
5
8
|
export type FirebasePermissionContext = FirebaseTransactionContext;
|
|
9
|
+
/**
|
|
10
|
+
* Factory function for creating permission-denied errors, given the model roles and the required role(s).
|
|
11
|
+
*/
|
|
6
12
|
export type FirebasePermissionErrorContextErrorFunction = (firebaseContextGrantedModelRoles: FirebaseContextGrantedModelRoles<FirebasePermissionErrorContext, unknown>, role?: ArrayOrValue<GrantedRole>) => Error;
|
|
13
|
+
/**
|
|
14
|
+
* Factory function for creating "does not exist" errors when a model document is not found.
|
|
15
|
+
*/
|
|
7
16
|
export type FirebaseDoesNotExistErrorContextErrorFunction = (firebaseContextGrantedModelRoles: FirebaseContextGrantedModelRoles<FirebasePermissionErrorContext, unknown>) => Error;
|
|
17
|
+
/**
|
|
18
|
+
* Context that provides custom error factories for permission and existence checks.
|
|
19
|
+
*
|
|
20
|
+
* When these factories are not provided, the system falls back to generic error messages.
|
|
21
|
+
* Applications typically supply these to produce HTTP-appropriate errors (e.g., 403, 404).
|
|
22
|
+
*/
|
|
8
23
|
export interface FirebasePermissionErrorContext {
|
|
9
24
|
makePermissionError?: FirebasePermissionErrorContextErrorFunction;
|
|
10
25
|
makeDoesNotExistError?: FirebasePermissionErrorContextErrorFunction;
|