@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.
Files changed (135) hide show
  1. package/index.cjs.js +12893 -4062
  2. package/index.esm.js +12872 -4065
  3. package/package.json +5 -5
  4. package/src/lib/client/error/error.d.ts +18 -3
  5. package/src/lib/client/firestore/array.d.ts +16 -3
  6. package/src/lib/client/firestore/driver.accessor.batch.d.ts +35 -4
  7. package/src/lib/client/firestore/driver.accessor.create.d.ts +15 -0
  8. package/src/lib/client/firestore/driver.accessor.d.ts +15 -0
  9. package/src/lib/client/firestore/driver.accessor.default.d.ts +32 -0
  10. package/src/lib/client/firestore/driver.accessor.transaction.d.ts +35 -4
  11. package/src/lib/client/firestore/driver.d.ts +16 -0
  12. package/src/lib/client/firestore/driver.query.d.ts +36 -0
  13. package/src/lib/client/firestore/firestore.d.ts +11 -1
  14. package/src/lib/client/firestore/increment.d.ts +12 -3
  15. package/src/lib/client/function/development.function.factory.d.ts +27 -2
  16. package/src/lib/client/function/error.d.ts +27 -0
  17. package/src/lib/client/function/function.callable.d.ts +50 -5
  18. package/src/lib/client/function/function.factory.d.ts +70 -4
  19. package/src/lib/client/function/model.function.factory.d.ts +64 -9
  20. package/src/lib/client/storage/driver.accessor.d.ts +93 -0
  21. package/src/lib/client/storage/driver.d.ts +15 -0
  22. package/src/lib/client/storage/storage.d.ts +10 -1
  23. package/src/lib/common/auth/auth.context.d.ts +17 -2
  24. package/src/lib/common/auth/auth.d.ts +38 -9
  25. package/src/lib/common/auth/auth.error.d.ts +25 -0
  26. package/src/lib/common/auth/auth.server.error.d.ts +6 -2
  27. package/src/lib/common/development/function.d.ts +17 -6
  28. package/src/lib/common/development/function.schedule.d.ts +30 -1
  29. package/src/lib/common/firestore/accessor/accessor.wrap.modify.d.ts +36 -12
  30. package/src/lib/common/firestore/accessor/array.d.ts +14 -4
  31. package/src/lib/common/firestore/accessor/document.d.ts +77 -2
  32. package/src/lib/common/firestore/accessor/increment.d.ts +15 -3
  33. package/src/lib/common/firestore/collection/collection.d.ts +22 -4
  34. package/src/lib/common/firestore/collection/collection.util.d.ts +12 -2
  35. package/src/lib/common/firestore/driver/accessor.d.ts +28 -1
  36. package/src/lib/common/firestore/driver/batch.d.ts +6 -4
  37. package/src/lib/common/firestore/driver/driver.d.ts +18 -1
  38. package/src/lib/common/firestore/driver/query.d.ts +20 -1
  39. package/src/lib/common/firestore/driver/query.handler.d.ts +23 -0
  40. package/src/lib/common/firestore/driver/transaction.d.ts +18 -6
  41. package/src/lib/common/firestore/error.d.ts +16 -4
  42. package/src/lib/common/firestore/query/iterator.d.ts +11 -0
  43. package/src/lib/common/firestore/reference.d.ts +11 -6
  44. package/src/lib/common/firestore/snapshot/snapshot.d.ts +4 -0
  45. package/src/lib/common/firestore/snapshot/snapshot.field.d.ts +263 -63
  46. package/src/lib/common/firestore/types.d.ts +39 -1
  47. package/src/lib/common/firestore/util/id.batch.d.ts +55 -3
  48. package/src/lib/common/function/action.d.ts +35 -0
  49. package/src/lib/common/model/context.d.ts +11 -1
  50. package/src/lib/common/model/function.d.ts +45 -9
  51. package/src/lib/common/model/model/model.loader.d.ts +37 -0
  52. package/src/lib/common/model/model/model.param.d.ts +24 -2
  53. package/src/lib/common/model/model.service.d.ts +126 -4
  54. package/src/lib/common/model/permission/permission.context.d.ts +15 -0
  55. package/src/lib/common/model/permission/permission.d.ts +16 -0
  56. package/src/lib/common/model/permission/permission.service.d.ts +24 -1
  57. package/src/lib/common/model/permission/permission.service.grant.d.ts +72 -28
  58. package/src/lib/common/model/permission/permission.service.role.d.ts +15 -0
  59. package/src/lib/common/storage/accessor/path.model.d.ts +25 -8
  60. package/src/lib/common/storage/context.d.ts +23 -6
  61. package/src/lib/common/storage/driver/accessor.d.ts +15 -4
  62. package/src/lib/common/storage/driver/accessor.iterate.d.ts +31 -8
  63. package/src/lib/common/storage/driver/accessor.util.d.ts +13 -6
  64. package/src/lib/common/storage/driver/driver.d.ts +10 -1
  65. package/src/lib/common/storage/driver/error.d.ts +16 -0
  66. package/src/lib/common/storage/driver/list.d.ts +30 -0
  67. package/src/lib/common/storage/storage.d.ts +76 -19
  68. package/src/lib/common/storage/types.d.ts +23 -5
  69. package/src/lib/model/index.d.ts +1 -0
  70. package/src/lib/model/notification/notification.action.d.ts +8 -0
  71. package/src/lib/model/notification/notification.api.d.ts +26 -0
  72. package/src/lib/model/notification/notification.api.error.d.ts +15 -0
  73. package/src/lib/model/notification/notification.api.util.d.ts +27 -12
  74. package/src/lib/model/notification/notification.config.d.ts +193 -64
  75. package/src/lib/model/notification/notification.create.d.ts +62 -13
  76. package/src/lib/model/notification/notification.create.task.d.ts +25 -4
  77. package/src/lib/model/notification/notification.d.ts +258 -99
  78. package/src/lib/model/notification/notification.details.d.ts +66 -18
  79. package/src/lib/model/notification/notification.id.d.ts +90 -12
  80. package/src/lib/model/notification/notification.item.d.ts +57 -16
  81. package/src/lib/model/notification/notification.message.d.ts +84 -18
  82. package/src/lib/model/notification/notification.query.d.ts +21 -24
  83. package/src/lib/model/notification/notification.send.d.ts +38 -5
  84. package/src/lib/model/notification/notification.task.d.ts +87 -16
  85. package/src/lib/model/notification/notification.task.subtask.d.ts +42 -13
  86. package/src/lib/model/notification/notification.util.d.ts +68 -18
  87. package/src/lib/model/oidcmodel/index.d.ts +8 -0
  88. package/src/lib/model/oidcmodel/oidcmodel.action.d.ts +37 -0
  89. package/src/lib/model/oidcmodel/oidcmodel.api.d.ts +131 -0
  90. package/src/lib/model/oidcmodel/oidcmodel.d.ts +114 -0
  91. package/src/lib/model/oidcmodel/oidcmodel.data.d.ts +17 -0
  92. package/src/lib/model/oidcmodel/oidcmodel.id.d.ts +18 -0
  93. package/src/lib/model/oidcmodel/oidcmodel.interaction.d.ts +40 -0
  94. package/src/lib/model/oidcmodel/oidcmodel.interaction.oauth.d.ts +73 -0
  95. package/src/lib/model/oidcmodel/oidcmodel.query.d.ts +21 -0
  96. package/src/lib/model/storagefile/storagefile.action.d.ts +47 -0
  97. package/src/lib/model/storagefile/storagefile.api.d.ts +54 -4
  98. package/src/lib/model/storagefile/storagefile.create.d.ts +40 -3
  99. package/src/lib/model/storagefile/storagefile.d.ts +153 -16
  100. package/src/lib/model/storagefile/storagefile.file.d.ts +22 -7
  101. package/src/lib/model/storagefile/storagefile.group.d.ts +30 -1
  102. package/src/lib/model/storagefile/storagefile.group.processing.d.ts +20 -2
  103. package/src/lib/model/storagefile/storagefile.id.d.ts +44 -5
  104. package/src/lib/model/storagefile/storagefile.permission.d.ts +23 -4
  105. package/src/lib/model/storagefile/storagefile.query.d.ts +63 -11
  106. package/src/lib/model/storagefile/storagefile.task.d.ts +47 -4
  107. package/src/lib/model/storagefile/storagefile.upload.claims.d.ts +21 -4
  108. package/src/lib/model/storagefile/storagefile.upload.d.ts +41 -9
  109. package/src/lib/model/storagefile/storagefile.upload.determiner.d.ts +112 -20
  110. package/src/lib/model/storagefile/storagefile.util.d.ts +66 -3
  111. package/src/lib/model/system/system.action.d.ts +25 -0
  112. package/src/lib/model/system/system.d.ts +80 -4
  113. package/src/lib/model/user.d.ts +8 -2
  114. package/test/index.cjs.js +11168 -3295
  115. package/test/index.esm.js +11176 -3303
  116. package/test/package.json +6 -6
  117. package/test/src/lib/client/firebase.authorized.d.ts +18 -0
  118. package/test/src/lib/client/firebase.d.ts +60 -0
  119. package/test/src/lib/common/firebase.instance.d.ts +21 -0
  120. package/test/src/lib/common/firestore/firestore.d.ts +40 -0
  121. package/test/src/lib/common/firestore/firestore.instance.d.ts +16 -0
  122. package/test/src/lib/common/firestore/test.driver.accessor.d.ts +39 -2
  123. package/test/src/lib/common/firestore/test.driver.utility.d.ts +8 -2
  124. package/test/src/lib/common/firestore/test.iterator.d.ts +7 -2
  125. package/test/src/lib/common/mock/mock.item.collection.fixture.d.ts +29 -1
  126. package/test/src/lib/common/mock/mock.item.d.ts +219 -5
  127. package/test/src/lib/common/mock/mock.item.id.d.ts +6 -0
  128. package/test/src/lib/common/mock/mock.item.query.d.ts +12 -0
  129. package/test/src/lib/common/mock/mock.item.service.d.ts +60 -0
  130. package/test/src/lib/common/mock/mock.item.storage.fixture.d.ts +28 -1
  131. package/test/src/lib/common/storage/storage.d.ts +30 -0
  132. package/test/src/lib/common/storage/storage.instance.d.ts +22 -0
  133. package/test/src/lib/common/storage/test.driver.accessor.d.ts +7 -2
  134. package/index.cjs.js.map +0 -1
  135. package/index.esm.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dereekb/firebase",
3
- "version": "13.2.2",
3
+ "version": "13.3.0",
4
4
  "exports": {
5
5
  "./test": {
6
6
  "module": "./test/index.esm.js",
@@ -17,10 +17,10 @@
17
17
  }
18
18
  },
19
19
  "peerDependencies": {
20
- "@dereekb/date": "13.2.2",
21
- "@dereekb/model": "13.2.2",
22
- "@dereekb/rxjs": "13.2.2",
23
- "@dereekb/util": "13.2.2",
20
+ "@dereekb/util": "13.3.0",
21
+ "@dereekb/date": "13.3.0",
22
+ "@dereekb/model": "13.3.0",
23
+ "@dereekb/rxjs": "13.3.0",
24
24
  "@firebase/rules-unit-testing": "5.0.0",
25
25
  "arktype": "^2.2.0",
26
26
  "date-fns": "^4.0.0",
@@ -1,8 +1,23 @@
1
1
  import { type FirebaseError } from 'firebase/app';
2
2
  /**
3
- * Returns true if the input is seen as a client-side FirebaseError.
3
+ * Type guard that checks whether an error is a client-side {@link FirebaseError} from the `firebase/app` package.
4
4
  *
5
- * @param error
6
- * @returns
5
+ * Distinguishes client Firebase errors from server-side errors or generic errors by checking
6
+ * for the `FirebaseError` name and a string `code` property. Used by {@link convertHttpsCallableErrorToReadableError}
7
+ * to determine the appropriate error wrapping strategy.
8
+ *
9
+ * @param error - the value to check
10
+ * @returns `true` if the input matches the shape of a client-side `FirebaseError`
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * try {
15
+ * await someFirebaseOperation();
16
+ * } catch (e) {
17
+ * if (isClientFirebaseError(e)) {
18
+ * console.log(e.code); // e.g., 'auth/user-not-found'
19
+ * }
20
+ * }
21
+ * ```
7
22
  */
8
23
  export declare function isClientFirebaseError(error: any): error is FirebaseError;
@@ -1,9 +1,22 @@
1
1
  import { type FirestoreAccessorArrayUpdate } from '../../common/firestore/accessor/accessor';
2
2
  import { type UpdateData } from '../../common/firestore/types';
3
3
  /**
4
- * Creates UpdateData corresponding to the input array update.
4
+ * Converts a {@link FirestoreAccessorArrayUpdate} into Firestore `UpdateData` using the
5
+ * client-side `arrayUnion()` and `arrayRemove()` FieldValue sentinels.
5
6
  *
6
- * @param input
7
- * @returns
7
+ * Processes both `union` (add elements) and `remove` (delete elements) operations,
8
+ * spreading array values as individual arguments since Firestore does not allow nested arrays.
9
+ *
10
+ * @param input - object with `union` and/or `remove` maps from field names to arrays of values
11
+ * @returns Firestore `UpdateData` with `FieldValue.arrayUnion()`/`FieldValue.arrayRemove()` sentinels
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const updateData = firestoreClientArrayUpdateToUpdateData<MyModel>({
16
+ * union: { tags: ['newTag'] },
17
+ * remove: { tags: ['oldTag'] }
18
+ * });
19
+ * await updateDoc(docRef, updateData);
20
+ * ```
8
21
  */
9
22
  export declare function firestoreClientArrayUpdateToUpdateData<T extends object>(input: FirestoreAccessorArrayUpdate<T>): UpdateData<T>;
@@ -2,7 +2,11 @@ import { type DocumentReference, type WriteBatch as FirebaseFirestoreWriteBatch
2
2
  import { type FirestoreDocumentContext, type UpdateData, type DocumentData, type WithFieldValue, FirestoreDocumentContextType, type FirestoreDocumentDataAccessor, type FirestoreDocumentDataAccessorFactory, type SetOptions } from '../../common/firestore';
3
3
  import { DefaultFirestoreDocumentDataAccessor } from './driver.accessor.default';
4
4
  /**
5
- * FirestoreDocumentDataAccessor implementation for a batch.
5
+ * Client-side {@link FirestoreDocumentDataAccessor} that queues write operations into a Firestore `WriteBatch`.
6
+ *
7
+ * Extends {@link DefaultFirestoreDocumentDataAccessor} to override `delete`, `set`, and `update` so they
8
+ * add operations to the batch rather than executing immediately. Read operations (`get`, `stream`, `exists`)
9
+ * still execute directly against Firestore. The batch must be committed separately after all operations are queued.
6
10
  */
7
11
  export declare class WriteBatchFirestoreDocumentDataAccessor<T> extends DefaultFirestoreDocumentDataAccessor<T> implements FirestoreDocumentDataAccessor<T> {
8
12
  private readonly _batch;
@@ -13,12 +17,28 @@ export declare class WriteBatchFirestoreDocumentDataAccessor<T> extends DefaultF
13
17
  update(data: UpdateData<object>): Promise<void>;
14
18
  }
15
19
  /**
16
- * Creates a new FirestoreDocumentDataAccessorFactory for a Batch.
20
+ * Creates a {@link FirestoreDocumentDataAccessorFactory} that produces {@link WriteBatchFirestoreDocumentDataAccessor}
21
+ * instances bound to the given `WriteBatch`. All write operations from these accessors are queued
22
+ * into the same batch.
23
+ *
24
+ * @param writeBatch - the Firestore `WriteBatch` to queue operations into
17
25
  *
18
- * @param batch
19
- * @returns
26
+ * @example
27
+ * ```ts
28
+ * const batch = writeBatch(firestore);
29
+ * const factory = writeBatchAccessorFactory<MyModel>(batch);
30
+ * const accessor = factory.accessorFor(docRef);
31
+ * await accessor.set(data);
32
+ * await batch.commit();
33
+ * ```
20
34
  */
21
35
  export declare function writeBatchAccessorFactory<T>(writeBatch: FirebaseFirestoreWriteBatch): FirestoreDocumentDataAccessorFactory<T>;
36
+ /**
37
+ * Client-side {@link FirestoreDocumentContext} that groups all document operations into a single `WriteBatch`.
38
+ *
39
+ * Provides accessors with {@link FirestoreDocumentContextType.BATCH} semantics — writes are queued
40
+ * and only applied when the batch is committed.
41
+ */
22
42
  export declare class WriteBatchFirestoreDocumentContext<T> implements FirestoreDocumentContext<T> {
23
43
  private readonly _batch;
24
44
  readonly contextType = FirestoreDocumentContextType.BATCH;
@@ -26,4 +46,15 @@ export declare class WriteBatchFirestoreDocumentContext<T> implements FirestoreD
26
46
  constructor(batch: FirebaseFirestoreWriteBatch);
27
47
  get batch(): FirebaseFirestoreWriteBatch;
28
48
  }
49
+ /**
50
+ * Factory function that creates a {@link WriteBatchFirestoreDocumentContext} for the given batch.
51
+ *
52
+ * @param batch - the Firestore `WriteBatch` to use for all document operations
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * const batch = writeBatch(firestore);
57
+ * const context = writeBatchDocumentContext<MyModel>(batch);
58
+ * ```
59
+ */
29
60
  export declare function writeBatchDocumentContext<T>(batch: FirebaseFirestoreWriteBatch): WriteBatchFirestoreDocumentContext<T>;
@@ -1,3 +1,18 @@
1
1
  import { type FirestoreDocumentDataAccessor } from '../../common/firestore/accessor/accessor';
2
2
  import { type WithFieldValue, type WriteResult } from '../../common/firestore/types';
3
+ /**
4
+ * Returns a function that creates a document only if it does not already exist.
5
+ *
6
+ * Used by client-side accessor implementations (default, transaction) as their `create()` method.
7
+ * Checks for document existence first, then calls `set()` if the document is absent.
8
+ *
9
+ * @param accessor - the accessor to perform the existence check and set operation on
10
+ * @throws {Error} When the document already exists at the reference path
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * const create = createWithAccessor(accessor);
15
+ * await create({ name: 'New Item' }); // throws if document already exists
16
+ * ```
17
+ */
3
18
  export declare function createWithAccessor<T>(accessor: FirestoreDocumentDataAccessor<T>): (data: WithFieldValue<T>) => Promise<void | WriteResult>;
@@ -1,2 +1,17 @@
1
1
  import { type FirestoreAccessorDriver } from '../../common/firestore/driver/accessor';
2
+ /**
3
+ * Creates a client-side {@link FirestoreAccessorDriver} that maps the abstract accessor interface
4
+ * to the `firebase/firestore` SDK functions (`doc`, `collection`, `collectionGroup`, `runTransaction`, `writeBatch`).
5
+ *
6
+ * This driver provides:
7
+ * - Document, collection, and subcollection reference factories
8
+ * - Transaction and write batch context factories for atomic operations
9
+ * - A default (non-transactional) document context
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const driver = firestoreClientAccessorDriver();
14
+ * // Used internally by firebaseFirestoreClientDrivers()
15
+ * ```
16
+ */
2
17
  export declare function firestoreClientAccessorDriver(): FirestoreAccessorDriver;
@@ -1,6 +1,15 @@
1
1
  import { type DocumentReference, type DocumentSnapshot, type UpdateData, type WithFieldValue } from 'firebase/firestore';
2
2
  import { type Observable } from 'rxjs';
3
3
  import { type DocumentData, type FirestoreAccessorArrayUpdate, type FirestoreAccessorIncrementUpdate, type FirestoreDataConverter, type FirestoreDocumentContext, type FirestoreDocumentDataAccessor, type FirestoreDocumentDataAccessorFactory, type SetOptions, type WriteResult } from '../../common/firestore';
4
+ /**
5
+ * Default (non-transactional) client-side implementation of {@link FirestoreDocumentDataAccessor}.
6
+ *
7
+ * Wraps a single Firestore `DocumentReference` and provides CRUD operations, streaming,
8
+ * and field-level updates (increment, array union/remove) using the `firebase/firestore` SDK.
9
+ *
10
+ * Used as the base accessor class; {@link WriteBatchFirestoreDocumentDataAccessor} extends this
11
+ * to add batch write semantics.
12
+ */
4
13
  export declare class DefaultFirestoreDocumentDataAccessor<T> implements FirestoreDocumentDataAccessor<T> {
5
14
  private readonly _documentRef;
6
15
  constructor(documentRef: DocumentReference<T>);
@@ -16,5 +25,28 @@ export declare class DefaultFirestoreDocumentDataAccessor<T> implements Firestor
16
25
  arrayUpdate(data: FirestoreAccessorArrayUpdate<T>): Promise<void | WriteResult>;
17
26
  update(data: UpdateData<object>): Promise<void>;
18
27
  }
28
+ /**
29
+ * Creates a {@link FirestoreDocumentDataAccessorFactory} that produces {@link DefaultFirestoreDocumentDataAccessor} instances
30
+ * for direct (non-batched, non-transactional) Firestore operations.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * const factory = defaultFirestoreAccessorFactory<MyModel>();
35
+ * const accessor = factory.accessorFor(documentRef);
36
+ * const snapshot = await accessor.get();
37
+ * ```
38
+ */
19
39
  export declare function defaultFirestoreAccessorFactory<T>(): FirestoreDocumentDataAccessorFactory<T>;
40
+ /**
41
+ * Creates a default (non-transactional, non-batched) {@link FirestoreDocumentContext} for client-side use.
42
+ *
43
+ * The context type is {@link FirestoreDocumentContextType.NONE}, meaning operations execute immediately
44
+ * against Firestore without transaction or batch grouping.
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * const context = defaultFirestoreDocumentContext<MyModel>();
49
+ * const accessor = context.accessorFactory.accessorFor(docRef);
50
+ * ```
51
+ */
20
52
  export declare function defaultFirestoreDocumentContext<T>(): FirestoreDocumentContext<T>;
@@ -2,7 +2,11 @@ import { type DocumentReference, type DocumentSnapshot, type Transaction as Fire
2
2
  import { type Observable } from 'rxjs';
3
3
  import { type FirestoreDocumentDataAccessor, type FirestoreDocumentDataAccessorFactory, type FirestoreDocumentContext, FirestoreDocumentContextType, type SetOptions, type DocumentData, type FirestoreDataConverter, type WriteResult, type FirestoreAccessorIncrementUpdate, type FirestoreAccessorArrayUpdate } from '../../common/firestore';
4
4
  /**
5
- * FirestoreDocumentDataAccessor implementation for a transaction.
5
+ * Client-side {@link FirestoreDocumentDataAccessor} that executes all operations within a Firestore `Transaction`.
6
+ *
7
+ * Unlike the default accessor, reads and writes are all routed through the transaction object,
8
+ * providing atomic read-then-write semantics. The `stream()` method emits a single snapshot
9
+ * from the transactional read rather than a live stream.
6
10
  */
7
11
  export declare class TransactionFirestoreDocumentDataAccessor<T> implements FirestoreDocumentDataAccessor<T> {
8
12
  private readonly _transaction;
@@ -22,12 +26,28 @@ export declare class TransactionFirestoreDocumentDataAccessor<T> implements Fire
22
26
  update(data: UpdateData<object>): Promise<void>;
23
27
  }
24
28
  /**
25
- * Creates a new FirestoreDocumentDataAccessorFactory for a Transaction.
29
+ * Creates a {@link FirestoreDocumentDataAccessorFactory} that produces {@link TransactionFirestoreDocumentDataAccessor}
30
+ * instances bound to the given transaction. All operations from these accessors participate in the same transaction.
31
+ *
32
+ * @param transaction - the Firestore `Transaction` to bind operations to
26
33
  *
27
- * @param transaction
28
- * @returns
34
+ * @example
35
+ * ```ts
36
+ * await runTransaction(firestore, async (transaction) => {
37
+ * const factory = transactionAccessorFactory<MyModel>(transaction);
38
+ * const accessor = factory.accessorFor(docRef);
39
+ * const snapshot = await accessor.get();
40
+ * // ... modify and set
41
+ * });
42
+ * ```
29
43
  */
30
44
  export declare function transactionAccessorFactory<T>(transaction: FirebaseFirestoreTransaction): FirestoreDocumentDataAccessorFactory<T>;
45
+ /**
46
+ * Client-side {@link FirestoreDocumentContext} that executes all document operations within a Firestore `Transaction`.
47
+ *
48
+ * Provides accessors with {@link FirestoreDocumentContextType.TRANSACTION} semantics — all reads are
49
+ * consistent and all writes are applied atomically when the transaction completes.
50
+ */
31
51
  export declare class TransactionFirestoreDocumentContext<T> implements FirestoreDocumentContext<T> {
32
52
  private readonly _transaction;
33
53
  readonly contextType = FirestoreDocumentContextType.TRANSACTION;
@@ -35,4 +55,15 @@ export declare class TransactionFirestoreDocumentContext<T> implements Firestore
35
55
  constructor(transaction: FirebaseFirestoreTransaction);
36
56
  get transaction(): FirebaseFirestoreTransaction;
37
57
  }
58
+ /**
59
+ * Factory function that creates a {@link TransactionFirestoreDocumentContext} for the given transaction.
60
+ *
61
+ * @param transaction - the Firestore `Transaction` to use for all document operations
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * const context = transactionDocumentContext<MyModel>(transaction);
66
+ * const accessor = context.accessorFactory.accessorFor(docRef);
67
+ * ```
68
+ */
38
69
  export declare function transactionDocumentContext<T>(transaction: FirebaseFirestoreTransaction): TransactionFirestoreDocumentContext<T>;
@@ -1,3 +1,19 @@
1
1
  import { type FirestoreDrivers } from '../../common/firestore/driver/driver';
2
+ /**
3
+ * Client-side {@link FirestoreDrivers} using the `firebase/firestore` SDK.
4
+ */
2
5
  export type FirebaseFirestoreClientDrivers = FirestoreDrivers;
6
+ /**
7
+ * Creates the client-side {@link FirestoreDrivers} that bind the abstract Firestore driver
8
+ * interfaces to the `firebase/firestore` SDK (browser/client).
9
+ *
10
+ * Provides accessor drivers (default, batch, transaction) and query drivers for use
11
+ * with {@link clientFirebaseFirestoreContextFactory}.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const drivers = firebaseFirestoreClientDrivers();
16
+ * const contextFactory = firestoreContextFactory(drivers);
17
+ * ```
18
+ */
3
19
  export declare function firebaseFirestoreClientDrivers(): FirebaseFirestoreClientDrivers;
@@ -3,11 +3,47 @@ import { type QueryConstraint } from 'firebase/firestore';
3
3
  import { type FullFirestoreQueryConstraintHandlersMapping } from './../../common/firestore/query/constraint';
4
4
  import { type FirestoreQueryConstraintFunctionsDriver, type FirestoreQueryDriver } from '../../common/firestore/driver/query';
5
5
  import { type Query } from '../../common/firestore/types';
6
+ /**
7
+ * Accumulates Firestore query constraints alongside the base query reference.
8
+ *
9
+ * Used internally by the client query driver to build up constraints before
10
+ * combining them into a final query via the `firebase/firestore` `query()` function.
11
+ */
6
12
  export interface FirebaseFirestoreQueryBuilder {
7
13
  readonly query: Query;
8
14
  readonly constraints: QueryConstraint[];
9
15
  }
16
+ /**
17
+ * Appends one or more `QueryConstraint` values to the builder, returning a new builder instance.
18
+ *
19
+ * @param builder - current query builder state
20
+ * @param constraint - constraint(s) to append
21
+ */
10
22
  export declare function addConstraintToBuilder(builder: FirebaseFirestoreQueryBuilder, constraint: ArrayOrValue<QueryConstraint>): FirebaseFirestoreQueryBuilder;
23
+ /**
24
+ * Maps each abstract {@link FirestoreQueryConstraintType} to its client-side `firebase/firestore`
25
+ * implementation. The `FIRESTORE_OFFSET_QUERY_CONSTRAINT_TYPE` is `undefined` because Firestore
26
+ * client SDK does not support offset-based pagination (server-only feature).
27
+ */
11
28
  export declare const FIRESTORE_CLIENT_QUERY_CONSTRAINT_HANDLER_MAPPING: FullFirestoreQueryConstraintHandlersMapping<FirebaseFirestoreQueryBuilder>;
29
+ /**
30
+ * Creates a {@link FirestoreQueryConstraintFunctionsDriver} for the client `firebase/firestore` SDK.
31
+ *
32
+ * Converts abstract query constraints into `firebase/firestore` `QueryConstraint` objects
33
+ * and composes them into an executable `Query`.
34
+ */
12
35
  export declare function firebaseFirestoreQueryConstraintFunctionsDriver(): FirestoreQueryConstraintFunctionsDriver;
36
+ /**
37
+ * Creates the client-side {@link FirestoreQueryDriver} that executes queries, counts, and streams
38
+ * using the `firebase/firestore` SDK.
39
+ *
40
+ * Note: Transactions are not supported for queries on the client; passing a `transaction` to `getDocs`
41
+ * will throw an error.
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * const queryDriver = firebaseFirestoreQueryDriver();
46
+ * // Used internally by firebaseFirestoreClientDrivers()
47
+ * ```
48
+ */
13
49
  export declare function firebaseFirestoreQueryDriver(): FirestoreQueryDriver;
@@ -1,5 +1,15 @@
1
1
  import { type FirestoreContextFactory } from '../../common/firestore/context';
2
2
  /**
3
- * Creates a FirestoreContextFactory that uses the @firebase/firebase package.
3
+ * Pre-configured {@link FirestoreContextFactory} for client-side (browser) Firebase usage.
4
+ *
5
+ * Wires the client Firestore drivers (from the `firebase/firestore` SDK) into the abstract
6
+ * {@link FirestoreContextFactory} so that collections, documents, queries, and transactions
7
+ * all use the client-side Firestore implementation.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * const context = clientFirebaseFirestoreContextFactory(firestore);
12
+ * const collection = context.collection(myCollectionConfig);
13
+ * ```
4
14
  */
5
15
  export declare const clientFirebaseFirestoreContextFactory: FirestoreContextFactory;
@@ -1,9 +1,18 @@
1
1
  import { type UpdateData } from 'firebase/firestore';
2
2
  import { type FirestoreAccessorIncrementUpdate } from '../../common/firestore/accessor/accessor';
3
3
  /**
4
- * Creates UpdateData corresponding to the input increment update.
4
+ * Converts a {@link FirestoreAccessorIncrementUpdate} into Firestore `UpdateData` using the
5
+ * client-side `increment()` FieldValue sentinel.
5
6
  *
6
- * @param input
7
- * @returns
7
+ * Maps each field in the input to an `increment()` call, defaulting to 0 for `undefined` values.
8
+ *
9
+ * @param input - object mapping field names to their increment amounts
10
+ * @returns Firestore `UpdateData` with `FieldValue.increment()` sentinels
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * const updateData = firestoreClientIncrementUpdateToUpdateData<MyModel>({ viewCount: 1, likeCount: -1 });
15
+ * await updateDoc(docRef, updateData);
16
+ * ```
8
17
  */
9
18
  export declare function firestoreClientIncrementUpdateToUpdateData<T extends object>(input: FirestoreAccessorIncrementUpdate<T>): UpdateData<T>;
@@ -1,14 +1,39 @@
1
1
  import { type Functions } from 'firebase/functions';
2
2
  import { type FirebaseFunctionTypeMap, type FirebaseFunctionMap } from './function';
3
3
  import { type FirebaseFunctionTypeConfigMap } from './function.factory';
4
+ /**
5
+ * Type map for development-only Firebase functions.
6
+ */
4
7
  export type DevelopmentFirebaseFunctionTypeMap = FirebaseFunctionTypeMap;
5
8
  /**
6
- * The configuration for a types map.
9
+ * Configuration map for development functions, mapping each function key to optional config.
7
10
  */
8
11
  export type DevelopmentFirebaseFunctionConfigMap<M extends DevelopmentFirebaseFunctionTypeMap> = FirebaseFunctionTypeConfigMap<M>;
12
+ /**
13
+ * Map of instantiated development Firebase callable functions.
14
+ */
9
15
  export type DevelopmentFirebaseFunctionMap<M extends DevelopmentFirebaseFunctionTypeMap> = FirebaseFunctionMap<M>;
10
16
  /**
11
- * Used for building a FirebaseFunctionMap<M> for a specific Functions instance.
17
+ * Factory that creates a {@link DevelopmentFirebaseFunctionMap} for a given `Functions` instance.
12
18
  */
13
19
  export type DevelopmentFirebaseFunctionMapFactory<M extends DevelopmentFirebaseFunctionTypeMap> = (functionsInstance: Functions) => DevelopmentFirebaseFunctionMap<M>;
20
+ /**
21
+ * Creates a {@link DevelopmentFirebaseFunctionMapFactory} that routes all development function calls
22
+ * through the single `runDevFunction` Cloud Function endpoint (identified by {@link RUN_DEV_FUNCTION_APP_FUNCTION_KEY}).
23
+ *
24
+ * Similar to {@link callModelFirebaseFunctionMapFactory}, all development functions are multiplexed
25
+ * through a single endpoint. The function specifier and data are wrapped via {@link onCallDevelopmentParams}.
26
+ *
27
+ * @param configMap - maps each development function key to optional configuration
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * const factory = developmentFirebaseFunctionMapFactory<DevFnMap>({
32
+ * resetData: null,
33
+ * seedDatabase: null
34
+ * });
35
+ * const devFns = factory(getFunctions());
36
+ * await devFns.resetData();
37
+ * ```
38
+ */
14
39
  export declare function developmentFirebaseFunctionMapFactory<M extends DevelopmentFirebaseFunctionTypeMap>(configMap: DevelopmentFirebaseFunctionConfigMap<M>): DevelopmentFirebaseFunctionMapFactory<M>;
@@ -1,7 +1,34 @@
1
1
  import { type ServerError, ServerErrorResponse, type ServerErrorResponseData } from '@dereekb/util';
2
2
  import { type FirebaseError } from 'firebase/app';
3
+ /**
4
+ * Client-side representation of an error originating from a Firebase Cloud Function.
5
+ *
6
+ * Wraps a {@link FirebaseError} with structured server error details (status, message, code)
7
+ * extracted from the error's `details` property. Extends {@link ServerErrorResponse} for
8
+ * consistent error handling across the application.
9
+ *
10
+ * Typically created via {@link convertHttpsCallableErrorToReadableError} when an `HttpsCallable`
11
+ * invocation fails with a server-side error that includes structured details.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * try {
16
+ * await callableFunction(data);
17
+ * } catch (e) {
18
+ * if (e instanceof FirebaseServerError) {
19
+ * console.log(e.code, e.message, e.firebaseError.code);
20
+ * }
21
+ * }
22
+ * ```
23
+ */
3
24
  export declare class FirebaseServerError<T extends ServerErrorResponseData = ServerErrorResponseData> extends ServerErrorResponse<T> {
4
25
  readonly firebaseError: FirebaseError;
26
+ /**
27
+ * Creates a {@link FirebaseServerError} from a raw {@link FirebaseError}, extracting
28
+ * structured error details from the error's `details` property if available.
29
+ *
30
+ * @param error - the Firebase error from an `HttpsCallable` failure
31
+ */
5
32
  static fromFirebaseError(error: FirebaseError): FirebaseServerError;
6
33
  constructor(firebaseError: FirebaseError, serverError: ServerError<T>);
7
34
  get _error(): FirebaseError;
@@ -1,23 +1,68 @@
1
1
  import { type FactoryWithInput, type Maybe, type PromiseOrValue } from '@dereekb/util';
2
2
  import { type HttpsCallable } from 'firebase/functions';
3
+ /**
4
+ * Configuration for mapping input/output values when wrapping an `HttpsCallable`.
5
+ *
6
+ * @template I - the external input type (what callers provide)
7
+ * @template O - the external output type (what callers receive)
8
+ * @template A - the internal input type (what the callable expects)
9
+ * @template B - the internal output type (what the callable returns)
10
+ */
3
11
  export interface MapHttpsCallable<I, O, A, B> {
12
+ /** Transforms the caller's input into the format expected by the underlying callable. */
4
13
  readonly mapInput?: FactoryWithInput<PromiseOrValue<A>, Maybe<I>>;
14
+ /** Transforms the callable's raw output into the format returned to callers. */
5
15
  readonly mapOutput?: FactoryWithInput<PromiseOrValue<O>, Maybe<B>>;
6
16
  }
7
17
  /**
8
- * Maps input and output values when using HttpsCallable.
18
+ * Wraps an `HttpsCallable` with input/output transformations and error conversion.
19
+ *
20
+ * Supports both standard mode (returns `HttpsCallableResult<O>`) and direct-data mode
21
+ * (returns just `O`) depending on the `directData` parameter. Errors from the callable
22
+ * are converted to readable errors via {@link convertHttpsCallableErrorToReadableError}.
9
23
  *
10
- * @param callable
11
- * @param wrap
12
- * @returns
24
+ * @param callable - the underlying Firebase `HttpsCallable` to wrap
25
+ * @param wrap - input/output mapping functions
26
+ * @param directData - when `true`, returns the unwrapped data instead of `HttpsCallableResult`
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * const wrapped = mapHttpsCallable(httpsCallable(functions, 'myFn'), {
31
+ * mapInput: (params) => ({ ...params, timestamp: Date.now() }),
32
+ * mapOutput: (result) => result?.items ?? []
33
+ * }, true);
34
+ * const items = await wrapped({ query: 'test' });
35
+ * ```
13
36
  */
14
37
  export declare function mapHttpsCallable<I, O, A, B = unknown>(callable: HttpsCallable<A, B>, wrap: MapHttpsCallable<I, O, A, B>): HttpsCallable<I, O>;
15
38
  export declare function mapHttpsCallable<I, O, A, B = unknown>(callable: HttpsCallable<A, B>, wrap: MapHttpsCallable<I, O, A, B>, directData: false): HttpsCallable<I, O>;
16
39
  export declare function mapHttpsCallable<I, O, A, B = unknown>(callable: HttpsCallable<A, B>, wrap: MapHttpsCallable<I, O, A, B>, directData: true): DirectDataHttpsCallable<HttpsCallable<I, O>>;
17
40
  export declare function mapHttpsCallable<I, O, A, B = unknown>(callable: HttpsCallable<A, B>, wrap: MapHttpsCallable<I, O, A, B>, directData?: boolean): HttpsCallable<I, O> | DirectDataHttpsCallable<HttpsCallable<I, O>>;
18
41
  /**
19
- * Wraps an HttpsCallable value so it returns only the data from the result, rather than an object with data attached.
42
+ * Unwraps an `HttpsCallable` so it returns the response data directly (`O`) instead of
43
+ * `HttpsCallableResult<O>`. Simplifies consumption when only the data payload is needed.
20
44
  */
21
45
  export type DirectDataHttpsCallable<C extends HttpsCallable<any, any>> = C extends HttpsCallable<infer I, infer O> ? (data?: I | null) => Promise<O> : never;
46
+ /**
47
+ * Wraps an `HttpsCallable` to return the data payload directly, stripping the `HttpsCallableResult` wrapper.
48
+ *
49
+ * Errors are converted to readable errors via {@link convertHttpsCallableErrorToReadableError}.
50
+ *
51
+ * @param callable - the `HttpsCallable` to wrap
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * const fn = directDataHttpsCallable(httpsCallable<Input, Output>(functions, 'myFn'));
56
+ * const output: Output = await fn(input);
57
+ * ```
58
+ */
22
59
  export declare function directDataHttpsCallable<I, O, C extends HttpsCallable<I, O> = HttpsCallable<I, O>>(callable: C): DirectDataHttpsCallable<C>;
60
+ /**
61
+ * Converts errors from `HttpsCallable` calls into more readable error types.
62
+ *
63
+ * If the error is a client-side {@link FirebaseError} with `details`, wraps it as a {@link FirebaseServerError}
64
+ * to preserve server-side error context. Otherwise, converts it to a generic readable error via `toReadableError`.
65
+ *
66
+ * @param error - the caught error from an `HttpsCallable` invocation
67
+ */
23
68
  export declare function convertHttpsCallableErrorToReadableError(error: unknown): unknown;