@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
|
@@ -2,10 +2,26 @@ import { type Maybe } from '@dereekb/util';
|
|
|
2
2
|
import { type GrantedRole, type ContextGrantedModelRoles } from '@dereekb/model';
|
|
3
3
|
import { type DocumentSnapshot, type FirestoreDocument } from '../../firestore';
|
|
4
4
|
import { type FirebasePermissionErrorContext } from './permission.context';
|
|
5
|
+
/**
|
|
6
|
+
* Snapshot of a Firestore model as loaded by the permission service for role evaluation.
|
|
7
|
+
*
|
|
8
|
+
* Contains the document wrapper, its snapshot, existence status, and deserialized data.
|
|
9
|
+
* Passed to role-mapping functions so they can inspect the model's state to determine permissions.
|
|
10
|
+
*/
|
|
5
11
|
export interface FirebasePermissionServiceModel<T, D extends FirestoreDocument<T> = FirestoreDocument<T>> {
|
|
12
|
+
/** The {@link FirestoreDocument} wrapper. */
|
|
6
13
|
readonly document: D;
|
|
14
|
+
/** The raw Firestore document snapshot. */
|
|
7
15
|
readonly snapshot: DocumentSnapshot<T>;
|
|
16
|
+
/** Whether the document exists in Firestore. */
|
|
8
17
|
readonly exists: boolean;
|
|
18
|
+
/** The deserialized document data, or `undefined` if it doesn't exist. */
|
|
9
19
|
readonly data: Maybe<T>;
|
|
10
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* The result of evaluating permissions for a Firebase model — contains the model data,
|
|
23
|
+
* context, and the computed role map.
|
|
24
|
+
*
|
|
25
|
+
* Used by {@link ContextGrantedModelRolesReader} to make role-based access control decisions.
|
|
26
|
+
*/
|
|
11
27
|
export type FirebaseContextGrantedModelRoles<C extends FirebasePermissionErrorContext, T, D extends FirestoreDocument<T> = FirestoreDocument<T>, R extends GrantedRole = GrantedRole> = ContextGrantedModelRoles<FirebasePermissionServiceModel<T, D>, C, R>;
|
|
@@ -4,12 +4,24 @@ import { type Maybe, type PromiseOrValue } from '@dereekb/util';
|
|
|
4
4
|
import { type FirebaseModelLoader, type InModelContextFirebaseModelLoader } from '../model/model.loader';
|
|
5
5
|
import { type FirebaseModelContext } from '../context';
|
|
6
6
|
import { type FirebasePermissionServiceModel } from './permission';
|
|
7
|
+
/**
|
|
8
|
+
* Permission service interface for a single Firebase model type, specialized from {@link ModelPermissionService}.
|
|
9
|
+
*/
|
|
7
10
|
export type FirebaseModelPermissionService<C extends FirebaseModelContext, T, D extends FirestoreDocument<T> = FirestoreDocument<T>, R extends string = string> = ModelPermissionService<C, D, R, FirebasePermissionServiceModel<T, D>>;
|
|
11
|
+
/**
|
|
12
|
+
* Delegate that provides model loading and role mapping for a {@link FirebaseModelPermissionServiceInstance}.
|
|
13
|
+
*
|
|
14
|
+
* The `roleMapForModel` function is the core of the permission system — it examines the loaded model data
|
|
15
|
+
* and context to produce a {@link GrantedRoleMap} of what the current user can do.
|
|
16
|
+
*/
|
|
8
17
|
export interface FirebasePermissionServiceInstanceDelegate<C extends FirebaseModelContext, T, D extends FirestoreDocument<T> = FirestoreDocument<T>, R extends string = string> extends FirebaseModelLoader<C, T, D> {
|
|
9
18
|
roleMapForModel(output: FirebasePermissionServiceModel<T, D>, context: C, model: D): PromiseOrValue<GrantedRoleMap<R>>;
|
|
10
19
|
}
|
|
11
20
|
/**
|
|
12
|
-
*
|
|
21
|
+
* Concrete permission service implementation for Firebase models.
|
|
22
|
+
*
|
|
23
|
+
* Loads the document snapshot, checks existence, and delegates role computation to the configured delegate.
|
|
24
|
+
* Used internally by {@link firebaseModelPermissionService}.
|
|
13
25
|
*/
|
|
14
26
|
export declare class FirebaseModelPermissionServiceInstance<C extends FirebaseModelContext, T, D extends FirestoreDocument<T> = FirestoreDocument<T>, R extends string = string> extends AbstractModelPermissionService<C, D, R, FirebasePermissionServiceModel<T, D>> implements FirebaseModelPermissionService<C, T, D, R> {
|
|
15
27
|
private readonly _delegate;
|
|
@@ -19,6 +31,17 @@ export declare class FirebaseModelPermissionServiceInstance<C extends FirebaseMo
|
|
|
19
31
|
protected outputForModel(document: D): Promise<Maybe<FirebasePermissionServiceModel<T, D>>>;
|
|
20
32
|
protected isUsableOutputForRoles(output: FirebasePermissionServiceModel<T, D>): boolean;
|
|
21
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Creates a {@link FirebaseModelPermissionServiceInstance} from a delegate.
|
|
36
|
+
*
|
|
37
|
+
* @param delegate - provides model loading and role computation
|
|
38
|
+
*/
|
|
22
39
|
export declare function firebaseModelPermissionService<C extends FirebaseModelContext, T, D extends FirestoreDocument<T> = FirestoreDocument<T>, R extends string = string>(delegate: FirebasePermissionServiceInstanceDelegate<C, T, D, R>): FirebaseModelPermissionServiceInstance<C, T, D, R>;
|
|
40
|
+
/**
|
|
41
|
+
* Context-bound permission service — evaluates roles for any model by key or document.
|
|
42
|
+
*/
|
|
23
43
|
export type InContextFirebaseModelPermissionService<C, T, D extends FirestoreDocument<T> = FirestoreDocument<T>, R extends string = string> = InContextModelPermissionService<C, D, R, FirebasePermissionServiceModel<T, D>>;
|
|
44
|
+
/**
|
|
45
|
+
* Fully bound permission service for a specific model and context — provides the computed role map.
|
|
46
|
+
*/
|
|
24
47
|
export type InModelContextFirebaseModelPermissionService<C, T, D extends FirestoreDocument<T> = FirestoreDocument<T>, R extends string = string> = InModelContextModelPermissionService<C, D, R, FirebasePermissionServiceModel<T, D>> & InModelContextFirebaseModelLoader<T, D>;
|
|
@@ -4,42 +4,67 @@ import { type AsyncDecisionFunction, type AuthRole, type Getter, type GetterOrVa
|
|
|
4
4
|
import { type FirebaseModelContext } from '../context';
|
|
5
5
|
import { type UserRelated } from '../../../model/user';
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Decision function that checks if the current user is an admin in the given context.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
* @returns
|
|
9
|
+
* Returns `false` if no auth is present.
|
|
11
10
|
*/
|
|
12
11
|
export declare const isAdminInFirebaseModelContext: AsyncDecisionFunction<FirebaseModelContext>;
|
|
13
12
|
/**
|
|
14
|
-
*
|
|
13
|
+
* Creates a {@link GrantRolesIfFunction} that grants the specified roles when the user is an admin.
|
|
15
14
|
*
|
|
16
|
-
* @param
|
|
17
|
-
*
|
|
18
|
-
* @
|
|
19
|
-
*
|
|
15
|
+
* @param rolesToGrantToAdmin - roles to grant if the user is an admin
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const grantIfAdmin = grantModelRolesIfAdminFunction(fullAccessRoleMap);
|
|
20
|
+
* const roles = await grantIfAdmin(context);
|
|
21
|
+
* ```
|
|
20
22
|
*/
|
|
21
23
|
export declare function grantModelRolesIfAdminFunction<R extends string = string>(rolesToGrantToAdmin: GetterOrValue<GrantedRoleMap<R>>): GrantRolesIfFunction<FirebaseModelContext, R>;
|
|
22
24
|
/**
|
|
23
|
-
*
|
|
25
|
+
* Pre-built grant function that gives full access (all roles) when the user is an admin.
|
|
24
26
|
*/
|
|
25
27
|
export declare const grantFullAccessIfAdmin: GeneralGrantRolesIfFunction<FirebaseModelContext>;
|
|
28
|
+
/**
|
|
29
|
+
* Convenience function that evaluates admin status and grants roles in a single call.
|
|
30
|
+
*
|
|
31
|
+
* @param context - the model context to check
|
|
32
|
+
* @param rolesToGrantToAdmin - roles to grant if admin
|
|
33
|
+
* @param otherwise - fallback role computation when not admin
|
|
34
|
+
*/
|
|
26
35
|
export declare function grantModelRolesIfAdmin<R extends string = string>(context: FirebaseModelContext, rolesToGrantToAdmin: GetterOrValue<GrantedRoleMap<R>>, otherwise?: GrantRolesOtherwiseFunction<R>): PromiseOrValue<GrantedRoleMap<R>>;
|
|
27
36
|
/**
|
|
28
|
-
*
|
|
37
|
+
* Creates a {@link GrantRolesIfFunction} that grants roles when the user has all specified auth roles in their token.
|
|
29
38
|
*
|
|
30
|
-
* @param
|
|
31
|
-
* @param rolesToGrantToAdmin
|
|
32
|
-
* @param otherwise
|
|
33
|
-
* @returns
|
|
39
|
+
* @param authRoles - the auth roles the user must have
|
|
40
|
+
* @param rolesToGrantToAdmin - the model roles to grant if the auth roles are present
|
|
34
41
|
*/
|
|
35
42
|
export declare function grantModelRolesIfHasAuthRolesFunction<R extends string = string>(authRoles: AuthRole[], rolesToGrantToAdmin: GetterOrValue<GrantedRoleMap<R>>): GrantRolesIfFunction<FirebaseModelContext, R>;
|
|
43
|
+
/**
|
|
44
|
+
* Factory function type for auth-role-based role granting.
|
|
45
|
+
*/
|
|
36
46
|
export type GrantModelRolesIfHasAuthRolesFactory = <R extends string = string>(context: FirebaseModelContext, rolesToGrantToAdmin: GetterOrValue<GrantedRoleMap<R>>, otherwise?: GrantRolesOtherwiseFunction<R>) => PromiseOrValue<GrantedRoleMap<R>>;
|
|
47
|
+
/**
|
|
48
|
+
* Creates a reusable factory pre-configured with specific auth roles to check for.
|
|
49
|
+
*
|
|
50
|
+
* @param authRoles - the auth roles the user must have
|
|
51
|
+
*/
|
|
37
52
|
export declare function grantModelRolesIfHasAuthRolesFactory(authRoles: IterableOrValue<AuthRole>): GrantModelRolesIfHasAuthRolesFactory;
|
|
53
|
+
/**
|
|
54
|
+
* Context for evaluating ownership of a {@link UserRelated} model. Accepts either the model data directly
|
|
55
|
+
* or a document reference that will be loaded to check ownership.
|
|
56
|
+
*/
|
|
38
57
|
export type UserRelatedModelFirebaseModelContext<T extends UserRelated = UserRelated> = UserRelatedModelFirebaseModelContextModelInput<T> | UserRelatedModelFirebaseModelContextDocumentInput<T>;
|
|
58
|
+
/**
|
|
59
|
+
* Input variant that provides the model data directly (avoids an extra Firestore read).
|
|
60
|
+
*/
|
|
39
61
|
export type UserRelatedModelFirebaseModelContextModelInput<T extends UserRelated = UserRelated> = {
|
|
40
62
|
model: T;
|
|
41
63
|
context: FirebaseModelContext;
|
|
42
64
|
};
|
|
65
|
+
/**
|
|
66
|
+
* Input variant that provides a document reference — the model data will be loaded to check ownership.
|
|
67
|
+
*/
|
|
43
68
|
export type UserRelatedModelFirebaseModelContextDocumentInput<T extends UserRelated = UserRelated> = {
|
|
44
69
|
document: FirestoreDocument<T>;
|
|
45
70
|
context: FirebaseModelContext;
|
|
@@ -52,12 +77,15 @@ export type UserRelatedModelFirebaseModelContextDocumentInput<T extends UserRela
|
|
|
52
77
|
*/
|
|
53
78
|
export declare const isOwnerOfUserRelatedModelInFirebaseModelContext: AsyncDecisionFunction<UserRelatedModelFirebaseModelContext<UserRelated>>;
|
|
54
79
|
/**
|
|
55
|
-
* Creates a GrantRolesIfFunction that grants roles
|
|
80
|
+
* Creates a {@link GrantRolesIfFunction} that grants roles when the authenticated user's UID matches the model's `uid` field.
|
|
56
81
|
*
|
|
57
|
-
* @param
|
|
58
|
-
*
|
|
59
|
-
* @
|
|
60
|
-
*
|
|
82
|
+
* @param rolesToGrant - the roles to grant if the user owns the model
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* const grantIfOwner = grantModelRolesIfAuthUserRelatedModelFunction<User>(fullAccessRoleMap);
|
|
87
|
+
* const roles = await grantIfOwner({ model: userData, context });
|
|
88
|
+
* ```
|
|
61
89
|
*/
|
|
62
90
|
export declare function grantModelRolesIfAuthUserRelatedModelFunction<T extends UserRelated, R extends string = string>(rolesToGrant: GetterOrValue<GrantedRoleMap<R>>): GrantRolesIfFunction<UserRelatedModelFirebaseModelContext<T>, R>;
|
|
63
91
|
/**
|
|
@@ -65,16 +93,20 @@ export declare function grantModelRolesIfAuthUserRelatedModelFunction<T extends
|
|
|
65
93
|
*/
|
|
66
94
|
export declare const grantFullAccessIfAuthUserRelated: GeneralGrantRolesIfFunction<UserRelatedModelFirebaseModelContext<UserRelated>>;
|
|
67
95
|
/**
|
|
68
|
-
* Grants the configured roles if the decision
|
|
96
|
+
* Grants the configured roles if the decision function returns `true`. Otherwise returns a no-access role map.
|
|
97
|
+
*
|
|
98
|
+
* Unlike {@link GrantRolesIfFunction}, this does not accept an `otherwise` fallback.
|
|
69
99
|
*/
|
|
70
100
|
export type GrantRolesOnlyIfFunction<C, R extends string = string> = (context: C) => Promise<GrantedRoleMap<R>>;
|
|
101
|
+
/**
|
|
102
|
+
* Generic variant of {@link GrantRolesOnlyIfFunction} that works with any role type.
|
|
103
|
+
*/
|
|
71
104
|
export type GeneralGrantRolesOnlyIfFunction<C> = <R extends string = string>(context: C) => Promise<GrantedRoleMap<R>>;
|
|
72
105
|
/**
|
|
73
|
-
* Creates a GrantRolesOnlyIfFunction
|
|
106
|
+
* Creates a {@link GrantRolesOnlyIfFunction} with no fallback — returns no-access if the condition is false.
|
|
74
107
|
*
|
|
75
|
-
* @param grantIf
|
|
76
|
-
* @param grantedRoles
|
|
77
|
-
* @returns
|
|
108
|
+
* @param grantIf - decision function to evaluate
|
|
109
|
+
* @param grantedRoles - roles to grant if the decision is `true`
|
|
78
110
|
*/
|
|
79
111
|
export declare function grantModelRolesOnlyIfFunction<C, R extends string = string>(grantIf: AsyncDecisionFunction<C>, grantedRoles: GetterOrValue<GrantedRoleMap<R>>): GrantRolesOnlyIfFunction<C, R>;
|
|
80
112
|
/**
|
|
@@ -93,10 +125,22 @@ export type GrantedRolesOtherwiseFunctionResult<R extends string = string> = Pro
|
|
|
93
125
|
*/
|
|
94
126
|
export type GrantRolesOtherwiseFunction<R extends string = string> = Getter<GrantedRolesOtherwiseFunctionResult<R>>;
|
|
95
127
|
/**
|
|
96
|
-
* Creates a GrantRolesIfFunction
|
|
128
|
+
* Creates a {@link GrantRolesIfFunction} that evaluates a decision function and grants roles if `true`,
|
|
129
|
+
* or falls back to the `otherwise` function (defaulting to no-access).
|
|
97
130
|
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
* @
|
|
131
|
+
* This is the core building block for composing permission logic.
|
|
132
|
+
*
|
|
133
|
+
* @param grantIf - async decision function to evaluate
|
|
134
|
+
* @param grantedRoles - roles to grant if the decision is `true`
|
|
135
|
+
* @throws {Error} When `grantIf` is not provided.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```ts
|
|
139
|
+
* const grantIfOwner = grantModelRolesIfFunction(
|
|
140
|
+
* isOwnerOfUserRelatedModelInFirebaseModelContext,
|
|
141
|
+
* fullAccessRoleMap
|
|
142
|
+
* );
|
|
143
|
+
* const roles = await grantIfOwner(context, () => noAccessRoleMap());
|
|
144
|
+
* ```
|
|
101
145
|
*/
|
|
102
146
|
export declare function grantModelRolesIfFunction<C, R extends string = string>(grantIf: AsyncDecisionFunction<C>, grantedRoles: GetterOrValue<GrantedRoleMap<R>>): GrantRolesIfFunction<C, R>;
|
|
@@ -4,6 +4,15 @@ import { type InModelContextFirebaseModelPermissionService } from './permission.
|
|
|
4
4
|
import { type SetIncludesMode, type ArrayOrValue } from '@dereekb/util';
|
|
5
5
|
import { type FirebasePermissionErrorContext } from './permission.context';
|
|
6
6
|
import { type FirebaseContextGrantedModelRoles, type FirebasePermissionServiceModel } from './permission';
|
|
7
|
+
/**
|
|
8
|
+
* Reads and asserts granted roles for a specific model in a given context.
|
|
9
|
+
*
|
|
10
|
+
* Combines the computed {@link GrantedRoleMap} with the model's data and provides methods to
|
|
11
|
+
* check and assert roles. Used as the primary interface for permission-guarded operations.
|
|
12
|
+
*
|
|
13
|
+
* Chainable assertion methods (`assertExists`, `assertHasRole`, `assertHasRoles`) return `this`
|
|
14
|
+
* for fluent usage.
|
|
15
|
+
*/
|
|
7
16
|
export interface ContextGrantedModelRolesReader<C extends FirebasePermissionErrorContext, T, D extends FirestoreDocument<T> = FirestoreDocument<T>, R extends GrantedRole = GrantedRole> extends GrantedRoleMapReader<R>, FirebasePermissionServiceModel<T, D> {
|
|
8
17
|
readonly roleMap: GrantedRoleMap<R>;
|
|
9
18
|
readonly contextGrantedModelRoles: FirebaseContextGrantedModelRoles<C, T, D, R>;
|
|
@@ -13,6 +22,12 @@ export interface ContextGrantedModelRolesReader<C extends FirebasePermissionErro
|
|
|
13
22
|
assertContainsRoles(setIncludes: SetIncludesMode, roles: ArrayOrValue<R>): this;
|
|
14
23
|
throwPermissionError(role?: R): never;
|
|
15
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Default implementation of {@link ContextGrantedModelRolesReader}.
|
|
27
|
+
*
|
|
28
|
+
* Wraps a {@link FirebaseContextGrantedModelRoles} result and delegates role reading
|
|
29
|
+
* to a {@link GrantedRoleMapReader}. Throws context-specific errors via the permission error context.
|
|
30
|
+
*/
|
|
16
31
|
export declare class ContextGrantedModelRolesReaderInstance<C extends FirebasePermissionErrorContext, T, D extends FirestoreDocument<T> = FirestoreDocument<T>, R extends GrantedRole = GrantedRole> implements ContextGrantedModelRolesReader<C, T, D, R> {
|
|
17
32
|
private readonly _contextGrantedModelRoles;
|
|
18
33
|
private readonly _roleReader;
|
|
@@ -1,28 +1,45 @@
|
|
|
1
1
|
import { type SlashPath, type SlashPathFolder } from '@dereekb/util';
|
|
2
2
|
import { type ReadFirestoreModelKeyInput } from '../../firestore/collection/collection';
|
|
3
|
+
/**
|
|
4
|
+
* Base storage path prefix for all model-related files.
|
|
5
|
+
*
|
|
6
|
+
* All model storage files are nested under `/model/` in the storage bucket.
|
|
7
|
+
*/
|
|
3
8
|
export declare const BASE_MODEL_STORAGE_FILE_PATH: SlashPathFolder;
|
|
4
9
|
/**
|
|
5
|
-
*
|
|
10
|
+
* Pre-configured {@link slashPathFactory} that produces absolute paths under {@link BASE_MODEL_STORAGE_FILE_PATH}.
|
|
6
11
|
*/
|
|
7
12
|
export declare const MODEL_STORAGE_FILE_SLASH_PATH_FACTORY: import("@dereekb/util").SlashPathFactory;
|
|
13
|
+
/**
|
|
14
|
+
* Configuration for {@link modelStorageSlashPathFactory}.
|
|
15
|
+
*/
|
|
8
16
|
export interface ModelStorageSlashPathFactoryConfig {
|
|
9
17
|
/**
|
|
10
|
-
* Additional base path
|
|
18
|
+
* Additional base path segment appended after `/model/`.
|
|
11
19
|
*
|
|
12
|
-
*
|
|
20
|
+
* For example, `'uploads'` produces paths like `/model/uploads/<modelKey>/...`.
|
|
13
21
|
*/
|
|
14
22
|
readonly basePath?: string;
|
|
15
23
|
}
|
|
16
24
|
/**
|
|
17
|
-
* Factory
|
|
25
|
+
* Factory that generates storage {@link SlashPath} values for Firestore model documents.
|
|
18
26
|
*
|
|
19
|
-
*
|
|
27
|
+
* Takes a model document or key as input and returns a storage path rooted under `/model/<modelKey>/`.
|
|
28
|
+
* An optional additional path can be appended.
|
|
20
29
|
*/
|
|
21
30
|
export type ModelStorageSlashPathFactory<T extends object = object> = (input: ReadFirestoreModelKeyInput<T>, path?: SlashPath) => SlashPath;
|
|
22
31
|
/**
|
|
23
|
-
* Creates a ModelStorageSlashPathFactory.
|
|
32
|
+
* Creates a {@link ModelStorageSlashPathFactory} that maps Firestore model keys to storage paths.
|
|
33
|
+
*
|
|
34
|
+
* The generated paths follow the convention `/model/[basePath/]<modelKey>/[path]`.
|
|
35
|
+
*
|
|
36
|
+
* @param config - optional base path to nest under
|
|
24
37
|
*
|
|
25
|
-
* @
|
|
26
|
-
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* const pathFactory = modelStorageSlashPathFactory({ basePath: 'avatars' });
|
|
41
|
+
* const path = pathFactory(userDocument, 'profile.png');
|
|
42
|
+
* // path === '/model/avatars/users/abc123/profile.png'
|
|
43
|
+
* ```
|
|
27
44
|
*/
|
|
28
45
|
export declare function modelStorageSlashPathFactory<T extends object = object>(config?: ModelStorageSlashPathFactoryConfig): ModelStorageSlashPathFactory<T>;
|
|
@@ -3,18 +3,25 @@ import { type FirebaseStorageDrivers } from './driver/driver';
|
|
|
3
3
|
import { type StorageBucketId } from './storage';
|
|
4
4
|
import { type FirebaseStorage } from './types';
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Central context for Firebase Cloud Storage operations within `@dereekb/firebase`.
|
|
7
|
+
*
|
|
8
|
+
* Wraps the underlying {@link FirebaseStorage} instance and its {@link FirebaseStorageDrivers},
|
|
9
|
+
* while exposing convenience methods for file/folder access via {@link FirebaseStorageAccessor}.
|
|
10
|
+
*
|
|
11
|
+
* Created by {@link firebaseStorageContextFactory}.
|
|
7
12
|
*/
|
|
8
13
|
export interface FirebaseStorageContext<F extends FirebaseStorage = FirebaseStorage> extends FirebaseStorageAccessor {
|
|
9
14
|
readonly storage: F;
|
|
10
15
|
readonly drivers: FirebaseStorageDrivers;
|
|
11
16
|
}
|
|
12
17
|
/**
|
|
13
|
-
* Factory
|
|
18
|
+
* Factory that creates a {@link FirebaseStorageContext} from a {@link FirebaseStorage} instance and optional configuration.
|
|
19
|
+
*
|
|
20
|
+
* Produced by {@link firebaseStorageContextFactory}.
|
|
14
21
|
*/
|
|
15
22
|
export type FirebaseStorageContextFactory<F extends FirebaseStorage = FirebaseStorage> = (firebaseStorage: F, config?: FirebaseStorageContextFactoryConfig) => FirebaseStorageContext;
|
|
16
23
|
/**
|
|
17
|
-
* firebaseStorageContextFactory
|
|
24
|
+
* Configuration for {@link firebaseStorageContextFactory}.
|
|
18
25
|
*/
|
|
19
26
|
export interface FirebaseStorageContextFactoryConfig {
|
|
20
27
|
/**
|
|
@@ -27,9 +34,19 @@ export interface FirebaseStorageContextFactoryConfig {
|
|
|
27
34
|
readonly forceBucket?: boolean;
|
|
28
35
|
}
|
|
29
36
|
/**
|
|
30
|
-
* Creates a
|
|
37
|
+
* Creates a {@link FirebaseStorageContextFactory} that produces storage contexts using the given drivers.
|
|
38
|
+
*
|
|
39
|
+
* The returned factory resolves a default bucket (from driver, config, or error) and builds
|
|
40
|
+
* a {@link StoragePathFactory} to normalize all path inputs.
|
|
41
|
+
*
|
|
42
|
+
* @param drivers - the storage driver implementations to use
|
|
43
|
+
* @throws {Error} When a default bucket ID cannot be resolved from the driver or config.
|
|
31
44
|
*
|
|
32
|
-
* @
|
|
33
|
-
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* const factory = firebaseStorageContextFactory(myDrivers);
|
|
48
|
+
* const storageContext = factory(firebaseStorage, { defaultBucketId: 'my-bucket' });
|
|
49
|
+
* const file = storageContext.file('uploads/doc.pdf');
|
|
50
|
+
* ```
|
|
34
51
|
*/
|
|
35
52
|
export declare function firebaseStorageContextFactory<F extends FirebaseStorage = FirebaseStorage>(drivers: FirebaseStorageDrivers): FirebaseStorageContextFactory<F>;
|
|
@@ -3,7 +3,10 @@ import { type ConfigurableStorageMetadata, type StorageAccessControlObject, type
|
|
|
3
3
|
import { type ArrayOrValue, type Maybe } from '@dereekb/util';
|
|
4
4
|
import { type Readable } from 'stream';
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Core interface for accessing files and folders in Firebase Cloud Storage.
|
|
7
|
+
*
|
|
8
|
+
* Provides a bucket-aware entry point to obtain {@link FirebaseStorageAccessorFile} and
|
|
9
|
+
* {@link FirebaseStorageAccessorFolder} handles. Typically obtained from a {@link FirebaseStorageContext}.
|
|
7
10
|
*/
|
|
8
11
|
export interface FirebaseStorageAccessor {
|
|
9
12
|
defaultBucket: () => StorageBucketId;
|
|
@@ -17,7 +20,10 @@ export interface FirebaseStorageAccessorRef {
|
|
|
17
20
|
readonly storageAccessor: FirebaseStorageAccessor;
|
|
18
21
|
}
|
|
19
22
|
/**
|
|
20
|
-
*
|
|
23
|
+
* Handle for a single file in Firebase Cloud Storage, providing read, write, and metadata operations.
|
|
24
|
+
*
|
|
25
|
+
* Methods marked "optional" are only available on certain platforms (client vs server).
|
|
26
|
+
* The `R` type parameter exposes the underlying SDK reference type for advanced usage.
|
|
21
27
|
*/
|
|
22
28
|
export interface FirebaseStorageAccessorFile<R = unknown> extends StoragePathRef {
|
|
23
29
|
/**
|
|
@@ -222,7 +228,9 @@ export interface StorageListFilesResult<R = unknown> {
|
|
|
222
228
|
nextPageToken(): Maybe<StorageListFilesPageToken>;
|
|
223
229
|
}
|
|
224
230
|
/**
|
|
225
|
-
*
|
|
231
|
+
* Handle for a folder (prefix) in Firebase Cloud Storage, providing listing operations.
|
|
232
|
+
*
|
|
233
|
+
* Folders in Cloud Storage are virtual — they exist only as shared path prefixes of files.
|
|
226
234
|
*/
|
|
227
235
|
export interface FirebaseStorageAccessorFolder<R = unknown> extends StoragePathRef {
|
|
228
236
|
readonly reference: R;
|
|
@@ -241,7 +249,10 @@ export type FirebaseStorageAccessorDriverDefaultBucketFunction = (storage: Fireb
|
|
|
241
249
|
export type FirebaseStorageAccessorDriverFileFunction<R = unknown> = (storage: FirebaseStorage, path: StoragePath) => FirebaseStorageAccessorFile<R>;
|
|
242
250
|
export type FirebaseStorageAccessorDriverFolderFunction<R = unknown> = (storage: FirebaseStorage, path: StoragePath) => FirebaseStorageAccessorFolder<R>;
|
|
243
251
|
/**
|
|
244
|
-
*
|
|
252
|
+
* Low-level driver that creates file and folder accessors from a {@link FirebaseStorage} instance.
|
|
253
|
+
*
|
|
254
|
+
* Implementations exist for the Firebase client SDK and the Google Cloud server SDK.
|
|
255
|
+
* Used internally by {@link FirebaseStorageContext} — consumers typically don't interact with this directly.
|
|
245
256
|
*/
|
|
246
257
|
export interface FirebaseStorageAccessorDriver {
|
|
247
258
|
/**
|
|
@@ -1,29 +1,46 @@
|
|
|
1
1
|
import { type FirebaseStorageAccessorFolder, type StorageListFilesOptions, type StorageListFilesResult } from './accessor';
|
|
2
2
|
import { type FetchPageFactory, type IterateFetchPagesByEachItemConfig, type IterateFetchPagesConfigWithFactoryAndInput } from '@dereekb/util/fetch';
|
|
3
3
|
/**
|
|
4
|
-
* Configuration for iterateStorageListFilesFactory
|
|
4
|
+
* Configuration for {@link iterateStorageListFilesFactory}. Excludes `pageToken` since it is managed internally during iteration.
|
|
5
5
|
*/
|
|
6
6
|
export type IterateStorageListFilesFactoryConfig = Omit<StorageListFilesOptions, 'pageToken'>;
|
|
7
|
+
/**
|
|
8
|
+
* Input for a single page fetch during storage file iteration.
|
|
9
|
+
*/
|
|
7
10
|
export interface IterateStorageListFilesInput extends StorageListFilesOptions {
|
|
8
11
|
/**
|
|
9
|
-
* The folder to iterate
|
|
12
|
+
* The folder to iterate files within.
|
|
10
13
|
*/
|
|
11
14
|
readonly folder: FirebaseStorageAccessorFolder;
|
|
12
15
|
}
|
|
13
16
|
/**
|
|
14
|
-
* A FetchPageFactory
|
|
17
|
+
* A {@link FetchPageFactory} specialized for paginating through files in a storage folder.
|
|
18
|
+
*
|
|
19
|
+
* Produced by {@link iterateStorageListFilesFactory}.
|
|
15
20
|
*/
|
|
16
21
|
export type IterateStorageListFilesFactory = FetchPageFactory<IterateStorageListFilesInput, StorageListFilesResult>;
|
|
17
22
|
/**
|
|
18
|
-
* Creates a
|
|
23
|
+
* Creates an {@link IterateStorageListFilesFactory} for paginated iteration over files in a storage folder.
|
|
19
24
|
*
|
|
20
|
-
* @
|
|
21
|
-
*
|
|
25
|
+
* Wraps the folder's `list()` API with cursor-based pagination via {@link fetchPageFactory}.
|
|
26
|
+
*
|
|
27
|
+
* @param config - default listing options (e.g., maxResults)
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* const factory = iterateStorageListFilesFactory({ maxResults: 100 });
|
|
32
|
+
* ```
|
|
22
33
|
*/
|
|
23
34
|
export declare function iterateStorageListFilesFactory(config: IterateStorageListFilesFactoryConfig): IterateStorageListFilesFactory;
|
|
35
|
+
/**
|
|
36
|
+
* Configuration for {@link iterateStorageListFilesByEachFile}, extending the per-item iteration config
|
|
37
|
+
* with folder and listing options.
|
|
38
|
+
*/
|
|
24
39
|
export type IterateStorageListFilesByEachFileConfig<T, R> = Omit<IterateFetchPagesByEachItemConfig<IterateStorageListFilesInput, StorageListFilesResult, T, R>, 'fetchPageFactory'> & Pick<IterateStorageListFilesInput, 'folder' | 'includeNestedResults' | 'pageToken'>;
|
|
25
40
|
/**
|
|
26
|
-
*
|
|
41
|
+
* Iterates through every file in a storage folder, invoking a callback for each individual file result.
|
|
42
|
+
*
|
|
43
|
+
* Convenience wrapper around {@link iterateFetchPagesByEachItem} pre-configured for storage listing.
|
|
27
44
|
*/
|
|
28
45
|
export declare function iterateStorageListFilesByEachFile<T, R>(input: IterateStorageListFilesByEachFileConfig<T, R>): Promise<{
|
|
29
46
|
totalItemsLoaded: number;
|
|
@@ -31,8 +48,14 @@ export declare function iterateStorageListFilesByEachFile<T, R>(input: IterateSt
|
|
|
31
48
|
totalPages: number;
|
|
32
49
|
totalPagesLimitReached: boolean;
|
|
33
50
|
}>;
|
|
51
|
+
/**
|
|
52
|
+
* Configuration for {@link iterateStorageListFiles}, extending the page-level iteration config
|
|
53
|
+
* with folder and listing options.
|
|
54
|
+
*/
|
|
34
55
|
export type IterateStorageListFilesConfig<R> = Omit<IterateFetchPagesConfigWithFactoryAndInput<IterateStorageListFilesInput, StorageListFilesResult, R>, 'fetchPageFactory'> & Pick<IterateStorageListFilesInput, 'folder' | 'includeNestedResults' | 'pageToken'>;
|
|
35
56
|
/**
|
|
36
|
-
*
|
|
57
|
+
* Iterates through pages of file results in a storage folder, invoking a callback for each page.
|
|
58
|
+
*
|
|
59
|
+
* Convenience wrapper around {@link iterateFetchPages} pre-configured for storage listing.
|
|
37
60
|
*/
|
|
38
61
|
export declare function iterateStorageListFiles<R>(input: IterateStorageListFilesConfig<R>): Promise<import("@dereekb/util/fetch").IterateFetchPagesResult>;
|
|
@@ -2,13 +2,20 @@ import { type Readable } from 'stream';
|
|
|
2
2
|
import { type StorageUploadOptions } from '../types';
|
|
3
3
|
import { type FirebaseStorageAccessorFile } from './accessor';
|
|
4
4
|
/**
|
|
5
|
-
* Uploads a file
|
|
5
|
+
* Uploads data to a storage file by piping a readable stream into the file's writable upload stream.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
* This is a server-side convenience — most client implementations don't support `uploadStream()`.
|
|
8
8
|
*
|
|
9
|
-
* @param file
|
|
10
|
-
* @param readableStream
|
|
11
|
-
* @param options
|
|
12
|
-
* @
|
|
9
|
+
* @param file - the target file accessor to upload to
|
|
10
|
+
* @param readableStream - the source stream to pipe
|
|
11
|
+
* @param options - optional upload configuration (content type, metadata, etc.)
|
|
12
|
+
* @throws {StorageFileUploadStreamUnsupportedError} When the file accessor does not support stream uploads.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const file = storageContext.file('data/export.csv');
|
|
17
|
+
* const readable = fs.createReadStream('/tmp/export.csv');
|
|
18
|
+
* await uploadFileWithStream(file, readable, { contentType: 'text/csv' });
|
|
19
|
+
* ```
|
|
13
20
|
*/
|
|
14
21
|
export declare function uploadFileWithStream<R = unknown>(file: FirebaseStorageAccessorFile<R>, readableStream: Pick<Readable, 'pipe'>, options?: StorageUploadOptions): Promise<void>;
|
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
import { type FirebaseStorageAccessorDriverRef } from './accessor';
|
|
2
|
+
/**
|
|
3
|
+
* Unique identifier string for a storage driver implementation.
|
|
4
|
+
*/
|
|
2
5
|
export type FirebaseStorageDriverIdentifier = string;
|
|
6
|
+
/**
|
|
7
|
+
* Indicates whether the driver targets production Firebase or a test/emulator environment.
|
|
8
|
+
*/
|
|
3
9
|
export type FirebaseStorageDriverType = 'production' | 'testing';
|
|
4
10
|
/**
|
|
5
|
-
*
|
|
11
|
+
* Aggregates all storage driver references needed by {@link FirebaseStorageContext}.
|
|
12
|
+
*
|
|
13
|
+
* The driver abstraction allows swapping between production (Firebase/Google Cloud) and testing
|
|
14
|
+
* (in-memory or emulator) implementations without changing consumer code.
|
|
6
15
|
*/
|
|
7
16
|
export interface FirebaseStorageDrivers extends FirebaseStorageAccessorDriverRef {
|
|
8
17
|
readonly storageDriverIdentifier?: FirebaseStorageDriverIdentifier;
|
|
@@ -1,7 +1,23 @@
|
|
|
1
1
|
import { type StorageDataStringType, type StorageUploadOptions } from '../types';
|
|
2
2
|
import { BaseError } from 'make-error';
|
|
3
|
+
/**
|
|
4
|
+
* Extracts and asserts that a `stringFormat` is present in the upload options.
|
|
5
|
+
*
|
|
6
|
+
* Required when the upload input is a string, since the format (raw, base64, etc.) must be explicit.
|
|
7
|
+
*
|
|
8
|
+
* @param options - the upload options to extract from
|
|
9
|
+
* @throws {Error} When `stringFormat` is not set in the options.
|
|
10
|
+
*/
|
|
3
11
|
export declare function assertStorageUploadOptionsStringFormat(options?: StorageUploadOptions): StorageDataStringType;
|
|
12
|
+
/**
|
|
13
|
+
* Creates an error indicating that `stringFormat` was missing from upload options.
|
|
14
|
+
*/
|
|
4
15
|
export declare function noStringFormatInStorageUploadOptionsError(): Error;
|
|
16
|
+
/**
|
|
17
|
+
* Thrown when attempting to use `uploadStream()` on a file accessor that does not support it.
|
|
18
|
+
*
|
|
19
|
+
* Stream uploads are typically only available on server-side (Google Cloud Storage) implementations.
|
|
20
|
+
*/
|
|
5
21
|
export declare class StorageFileUploadStreamUnsupportedError extends BaseError {
|
|
6
22
|
constructor();
|
|
7
23
|
}
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { type Maybe } from '@dereekb/util';
|
|
2
2
|
import { type StorageListFilesPageToken, type FirebaseStorageAccessorFile, type FirebaseStorageAccessorFolder, type StorageListFilesOptions, type StorageListFilesResult, type StorageListItemResult } from './accessor';
|
|
3
|
+
/**
|
|
4
|
+
* Delegate that adapts platform-specific list results into the generic {@link StorageListFilesResult} interface.
|
|
5
|
+
*
|
|
6
|
+
* Implementations extract items, pagination tokens, and convert raw results into typed file/folder accessors.
|
|
7
|
+
* Used by {@link storageListFilesResultFactory} to create the normalized result objects.
|
|
8
|
+
*
|
|
9
|
+
* @template S - the storage instance type (client or server SDK)
|
|
10
|
+
* @template R - the raw list result type from the underlying SDK
|
|
11
|
+
*/
|
|
3
12
|
export interface StorageListFilesResultFactoryDelegate<S, R> {
|
|
4
13
|
hasItems(result: R): boolean;
|
|
5
14
|
hasNext(result: R): boolean;
|
|
@@ -10,6 +19,27 @@ export interface StorageListFilesResultFactoryDelegate<S, R> {
|
|
|
10
19
|
filesFromResult(result: R, folder: FirebaseStorageAccessorFolder): StorageListItemResult[];
|
|
11
20
|
foldersFromResult(result: R, folder: FirebaseStorageAccessorFolder): StorageListItemResult[];
|
|
12
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Factory function that transforms a raw SDK list result into a normalized {@link StorageListFilesResult}.
|
|
24
|
+
*/
|
|
13
25
|
export type StorageListFilesResultFactory<S, R> = (storage: S, folder: FirebaseStorageAccessorFolder, options: StorageListFilesOptions | undefined, result: R) => StorageListFilesResult;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a {@link StorageListFilesResultFactory} from a platform-specific delegate.
|
|
28
|
+
*
|
|
29
|
+
* The returned factory lazily computes file and folder arrays (via {@link cachedGetter}) and
|
|
30
|
+
* provides cursor-based pagination through the `next()` method.
|
|
31
|
+
*
|
|
32
|
+
* @param delegate - platform-specific implementation for extracting results
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* const factory = storageListFilesResultFactory(myDelegate);
|
|
37
|
+
* const result = factory(storage, folder, { maxResults: 50 }, rawSdkResult);
|
|
38
|
+
* const files = result.files();
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
14
41
|
export declare function storageListFilesResultFactory<S, R>(delegate: StorageListFilesResultFactoryDelegate<S, R>): StorageListFilesResultFactory<S, R>;
|
|
42
|
+
/**
|
|
43
|
+
* Creates an error thrown when `next()` is called on a list result that has no more pages.
|
|
44
|
+
*/
|
|
15
45
|
export declare function storageListFilesResultHasNoNextError(): Error;
|