@dereekb/firebase 13.11.11 → 13.11.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dereekb/firebase",
3
- "version": "13.11.11",
3
+ "version": "13.11.13",
4
4
  "sideEffects": false,
5
5
  "exports": {
6
6
  "./test": {
@@ -18,10 +18,10 @@
18
18
  }
19
19
  },
20
20
  "peerDependencies": {
21
- "@dereekb/util": "13.11.11",
22
- "@dereekb/date": "13.11.11",
23
- "@dereekb/model": "13.11.11",
24
- "@dereekb/rxjs": "13.11.11",
21
+ "@dereekb/util": "13.11.13",
22
+ "@dereekb/date": "13.11.13",
23
+ "@dereekb/model": "13.11.13",
24
+ "@dereekb/rxjs": "13.11.13",
25
25
  "@firebase/rules-unit-testing": "5.0.0",
26
26
  "arktype": "^2.2.0",
27
27
  "date-fns": "^4.1.0",
@@ -2,7 +2,27 @@ import { type DateRange, type DateRangeInput } from '@dereekb/date';
2
2
  import { type StringKeyPropertyKeys } from '@dereekb/util';
3
3
  import { type RootFirestoreModelIdentity } from '../collection/collection';
4
4
  import { type DocumentReference, type FieldPathOrStringPath, type FieldPathOrStringPathOf } from '../types';
5
- import { type FirestoreQueryConstraint, type OrderByDirection } from './constraint';
5
+ import { type EndAtValueQueryConstraintData, type FirestoreQueryConstraint, type OrderByDocumentIdQueryConstraintData, type OrderByQueryConstraintData, type StartAtValueQueryConstraintData, type OrderByDirection, type WhereQueryConstraintData } from './constraint';
6
+ /**
7
+ * Fixed-shape tuple returned by helpers that combine `orderBy` with `startAtValue` + `endAtValue`
8
+ * range bounds on the same field (e.g. {@link whereStringValueHasPrefix}, {@link allChildDocumentsUnderRelativePath}).
9
+ */
10
+ export type FirestoreQueryOrderByRangeBoundsTuple = [FirestoreQueryConstraint<OrderByQueryConstraintData>, FirestoreQueryConstraint<StartAtValueQueryConstraintData>, FirestoreQueryConstraint<EndAtValueQueryConstraintData>];
11
+ /**
12
+ * Fixed-shape tuple returned by helpers that combine `orderByDocumentId` with `startAtValue` + `endAtValue`
13
+ * range bounds on the document id (e.g. {@link allChildDocumentsUnderParentPath}).
14
+ */
15
+ export type FirestoreQueryOrderByDocumentIdRangeBoundsTuple = [FirestoreQueryConstraint<OrderByDocumentIdQueryConstraintData>, FirestoreQueryConstraint<StartAtValueQueryConstraintData>, FirestoreQueryConstraint<EndAtValueQueryConstraintData>];
16
+ /**
17
+ * Fixed-shape tuple returned by helpers that pair an `orderBy` with a single `where` comparison
18
+ * on the same field (e.g. the `whereDateIs*WithSort` family).
19
+ */
20
+ export type FirestoreQueryOrderByAndWhereTuple = [FirestoreQueryConstraint<OrderByQueryConstraintData>, FirestoreQueryConstraint<WhereQueryConstraintData>];
21
+ /**
22
+ * Fixed-shape tuple returned by helpers that pair an `orderBy` with two `where` comparisons
23
+ * on the same field, defining a closed range (e.g. {@link whereDateIsBetween}).
24
+ */
25
+ export type FirestoreQueryOrderByAndRangeWhereTuple = [FirestoreQueryConstraint<OrderByQueryConstraintData>, FirestoreQueryConstraint<WhereQueryConstraintData>, FirestoreQueryConstraint<WhereQueryConstraintData>];
6
26
  /**
7
27
  * Creates constraints to query all child documents under a specific parent document reference.
8
28
  *
@@ -20,7 +40,7 @@ import { type FirestoreQueryConstraint, type OrderByDirection } from './constrai
20
40
  * const query = collectionGroup(firestore, 'comments')
21
41
  * .where(...allChildDocumentsUnderParent(postRef));
22
42
  */
23
- export declare function allChildDocumentsUnderParent<P>(parentRef: DocumentReference<P>): FirestoreQueryConstraint[];
43
+ export declare function allChildDocumentsUnderParent<P>(parentRef: DocumentReference<P>): FirestoreQueryOrderByDocumentIdRangeBoundsTuple;
24
44
  /**
25
45
  * Creates constraints to query all child documents under a specific parent path.
26
46
  *
@@ -36,7 +56,7 @@ export declare function allChildDocumentsUnderParent<P>(parentRef: DocumentRefer
36
56
  * const query = collectionGroup(firestore, 'comments')
37
57
  * .where(...allChildDocumentsUnderParentPath('posts/abc123'));
38
58
  */
39
- export declare function allChildDocumentsUnderParentPath(parentPath: string): FirestoreQueryConstraint[];
59
+ export declare function allChildDocumentsUnderParentPath(parentPath: string): FirestoreQueryOrderByDocumentIdRangeBoundsTuple;
40
60
  /**
41
61
  * Creates constraints to query documents that have a field value starting with a specific prefix.
42
62
  *
@@ -58,8 +78,8 @@ export declare function allChildDocumentsUnderParentPath(parentPath: string): Fi
58
78
  * const query = collectionGroup(firestore, 'tasks')
59
79
  * .where(...allChildDocumentsUnderRelativePath('parentPath', 'organizations/org123/'));
60
80
  */
61
- export declare function allChildDocumentsUnderRelativePath<T>(orderByFieldPath: StringKeyPropertyKeys<T>, parentValue: string, sortDirection?: OrderByDirection): FirestoreQueryConstraint[];
62
- export declare function allChildDocumentsUnderRelativePath(orderByFieldPath: FieldPathOrStringPath, parentValue: string, sortDirection?: OrderByDirection): FirestoreQueryConstraint[];
81
+ export declare function allChildDocumentsUnderRelativePath<T>(orderByFieldPath: StringKeyPropertyKeys<T>, parentValue: string, sortDirection?: OrderByDirection): FirestoreQueryOrderByRangeBoundsTuple;
82
+ export declare function allChildDocumentsUnderRelativePath(orderByFieldPath: FieldPathOrStringPath, parentValue: string, sortDirection?: OrderByDirection): FirestoreQueryOrderByRangeBoundsTuple;
63
83
  /**
64
84
  * Creates constraints to find documents where a field contains a reference to a specific model type.
65
85
  *
@@ -78,7 +98,7 @@ export declare function allChildDocumentsUnderRelativePath(orderByFieldPath: Fie
78
98
  * const query = collection(firestore, 'documents')
79
99
  * .where(...whereStringHasRootIdentityModelKey('reference', { collectionType: 'users' }));
80
100
  */
81
- export declare function whereStringHasRootIdentityModelKey<T = object>(orderByFieldPath: FieldPathOrStringPathOf<T> | FieldPathOrStringPath, value: RootFirestoreModelIdentity, sortDirection?: OrderByDirection): FirestoreQueryConstraint[];
101
+ export declare function whereStringHasRootIdentityModelKey<T = object>(orderByFieldPath: FieldPathOrStringPathOf<T> | FieldPathOrStringPath, value: RootFirestoreModelIdentity, sortDirection?: OrderByDirection): FirestoreQueryOrderByRangeBoundsTuple;
82
102
  /**
83
103
  * Creates constraints to find documents where a string field starts with a specific prefix.
84
104
  *
@@ -97,8 +117,8 @@ export declare function whereStringHasRootIdentityModelKey<T = object>(orderByFi
97
117
  * const query = collection(firestore, 'users')
98
118
  * .where(...whereStringValueHasPrefix('email', 'admin@'));
99
119
  */
100
- export declare function whereStringValueHasPrefix<T>(orderByFieldPath: StringKeyPropertyKeys<T>, parentValue: string, sortDirection?: OrderByDirection): FirestoreQueryConstraint[];
101
- export declare function whereStringValueHasPrefix(orderByFieldPath: FieldPathOrStringPath, parentValue: string, sortDirection?: OrderByDirection): FirestoreQueryConstraint[];
120
+ export declare function whereStringValueHasPrefix<T>(orderByFieldPath: StringKeyPropertyKeys<T>, parentValue: string, sortDirection?: OrderByDirection): FirestoreQueryOrderByRangeBoundsTuple;
121
+ export declare function whereStringValueHasPrefix(orderByFieldPath: FieldPathOrStringPath, parentValue: string, sortDirection?: OrderByDirection): FirestoreQueryOrderByRangeBoundsTuple;
102
122
  /**
103
123
  * Creates constraints to filter documents by a date field within a specific date range.
104
124
  *
@@ -138,8 +158,8 @@ export declare function filterWithDateRange(field: FieldPathOrStringPath, dateRa
138
158
  * const query = collection(firestore, 'documents')
139
159
  * .where(...whereDateIsInRange('createdAt', { month: 0, year: 2023 }));
140
160
  */
141
- export declare function whereDateIsInRange<T>(field: StringKeyPropertyKeys<T>, rangeInput: DateRangeInput, sortDirection?: OrderByDirection): FirestoreQueryConstraint[];
142
- export declare function whereDateIsInRange(field: FieldPathOrStringPath, rangeInput: DateRangeInput, sortDirection?: OrderByDirection): FirestoreQueryConstraint[];
161
+ export declare function whereDateIsInRange<T>(field: StringKeyPropertyKeys<T>, rangeInput: DateRangeInput, sortDirection?: OrderByDirection): FirestoreQueryOrderByAndRangeWhereTuple;
162
+ export declare function whereDateIsInRange(field: FieldPathOrStringPath, rangeInput: DateRangeInput, sortDirection?: OrderByDirection): FirestoreQueryOrderByAndRangeWhereTuple;
143
163
  /**
144
164
  * Creates constraints to filter documents where a date field falls within a half-open range `[start, end)`.
145
165
  *
@@ -151,8 +171,8 @@ export declare function whereDateIsInRange(field: FieldPathOrStringPath, rangeIn
151
171
  * @param sortDirection - Direction to sort results (default: 'asc')
152
172
  * @returns Array of query constraints for the date range filter and sort
153
173
  */
154
- export declare function whereDateIsBetween<T>(field: StringKeyPropertyKeys<T>, range: DateRange, sortDirection?: OrderByDirection): FirestoreQueryConstraint[];
155
- export declare function whereDateIsBetween(field: FieldPathOrStringPath, range: DateRange, sortDirection?: OrderByDirection): FirestoreQueryConstraint[];
174
+ export declare function whereDateIsBetween<T>(field: StringKeyPropertyKeys<T>, range: DateRange, sortDirection?: OrderByDirection): FirestoreQueryOrderByAndRangeWhereTuple;
175
+ export declare function whereDateIsBetween(field: FieldPathOrStringPath, range: DateRange, sortDirection?: OrderByDirection): FirestoreQueryOrderByAndRangeWhereTuple;
156
176
  /**
157
177
  * Creates a constraint to filter documents where a date field is greater than or equal to a specified date.
158
178
  *
@@ -174,8 +194,8 @@ export declare function whereDateIsBetween(field: FieldPathOrStringPath, range:
174
194
  * const query = collection(firestore, 'documents')
175
195
  * .where(whereDateIsOnOrAfter('createdAt', startOfYear));
176
196
  */
177
- export declare function whereDateIsOnOrAfter<T>(field: StringKeyPropertyKeys<T>, date?: Date): FirestoreQueryConstraint;
178
- export declare function whereDateIsOnOrAfter(field: FieldPathOrStringPath, date?: Date): FirestoreQueryConstraint;
197
+ export declare function whereDateIsOnOrAfter<T>(field: StringKeyPropertyKeys<T>, date?: Date): FirestoreQueryConstraint<WhereQueryConstraintData>;
198
+ export declare function whereDateIsOnOrAfter(field: FieldPathOrStringPath, date?: Date): FirestoreQueryConstraint<WhereQueryConstraintData>;
179
199
  /**
180
200
  * Creates constraints to filter documents by dates on or after a specified date, with sorting.
181
201
  *
@@ -194,8 +214,8 @@ export declare function whereDateIsOnOrAfter(field: FieldPathOrStringPath, date?
194
214
  * const query = collection(firestore, 'documents')
195
215
  * .where(...whereDateIsOnOrAfterWithSort('createdAt', new Date(), 'desc'));
196
216
  */
197
- export declare function whereDateIsOnOrAfterWithSort<T>(field: StringKeyPropertyKeys<T>, date?: Date, sortDirection?: OrderByDirection): FirestoreQueryConstraint[];
198
- export declare function whereDateIsOnOrAfterWithSort(field: FieldPathOrStringPath, date?: Date, sortDirection?: OrderByDirection): FirestoreQueryConstraint[];
217
+ export declare function whereDateIsOnOrAfterWithSort<T>(field: StringKeyPropertyKeys<T>, date?: Date, sortDirection?: OrderByDirection): FirestoreQueryOrderByAndWhereTuple;
218
+ export declare function whereDateIsOnOrAfterWithSort(field: FieldPathOrStringPath, date?: Date, sortDirection?: OrderByDirection): FirestoreQueryOrderByAndWhereTuple;
199
219
  /**
200
220
  * Creates a constraint to filter documents where a date field is less than or equal to a specified date.
201
221
  *
@@ -205,8 +225,8 @@ export declare function whereDateIsOnOrAfterWithSort(field: FieldPathOrStringPat
205
225
  * @param date - The maximum date to include (default: current date/time)
206
226
  * @returns A query constraint for dates on or before the specified date
207
227
  */
208
- export declare function whereDateIsOnOrBefore<T>(field: StringKeyPropertyKeys<T>, date?: Date): FirestoreQueryConstraint;
209
- export declare function whereDateIsOnOrBefore(field: FieldPathOrStringPath, date?: Date): FirestoreQueryConstraint;
228
+ export declare function whereDateIsOnOrBefore<T>(field: StringKeyPropertyKeys<T>, date?: Date): FirestoreQueryConstraint<WhereQueryConstraintData>;
229
+ export declare function whereDateIsOnOrBefore(field: FieldPathOrStringPath, date?: Date): FirestoreQueryConstraint<WhereQueryConstraintData>;
210
230
  /**
211
231
  * Creates constraints to filter documents where a date field is on or before a specified date, with sorting.
212
232
  *
@@ -219,8 +239,8 @@ export declare function whereDateIsOnOrBefore(field: FieldPathOrStringPath, date
219
239
  * @param sortDirection - Direction to sort results (default: 'desc')
220
240
  * @returns Array of query constraints for filtering and sorting
221
241
  */
222
- export declare function whereDateIsOnOrBeforeWithSort<T>(field: StringKeyPropertyKeys<T>, date?: Date, sortDirection?: OrderByDirection): FirestoreQueryConstraint[];
223
- export declare function whereDateIsOnOrBeforeWithSort(field: FieldPathOrStringPath, date?: Date, sortDirection?: OrderByDirection): FirestoreQueryConstraint[];
242
+ export declare function whereDateIsOnOrBeforeWithSort<T>(field: StringKeyPropertyKeys<T>, date?: Date, sortDirection?: OrderByDirection): FirestoreQueryOrderByAndWhereTuple;
243
+ export declare function whereDateIsOnOrBeforeWithSort(field: FieldPathOrStringPath, date?: Date, sortDirection?: OrderByDirection): FirestoreQueryOrderByAndWhereTuple;
224
244
  /**
225
245
  * Creates a constraint to filter documents where a date field is strictly after a specified date.
226
246
  *
@@ -230,8 +250,8 @@ export declare function whereDateIsOnOrBeforeWithSort(field: FieldPathOrStringPa
230
250
  * @param date - The exclusive lower bound date (default: current date/time)
231
251
  * @returns A query constraint for dates strictly after the specified date
232
252
  */
233
- export declare function whereDateIsAfter<T>(field: StringKeyPropertyKeys<T>, date?: Date): FirestoreQueryConstraint;
234
- export declare function whereDateIsAfter(field: FieldPathOrStringPath, date?: Date): FirestoreQueryConstraint;
253
+ export declare function whereDateIsAfter<T>(field: StringKeyPropertyKeys<T>, date?: Date): FirestoreQueryConstraint<WhereQueryConstraintData>;
254
+ export declare function whereDateIsAfter(field: FieldPathOrStringPath, date?: Date): FirestoreQueryConstraint<WhereQueryConstraintData>;
235
255
  /**
236
256
  * Creates constraints to filter documents where a date field is strictly after a specified date, with sorting.
237
257
  *
@@ -243,8 +263,8 @@ export declare function whereDateIsAfter(field: FieldPathOrStringPath, date?: Da
243
263
  * @param sortDirection - Direction to sort results (default: 'asc')
244
264
  * @returns Array of query constraints for filtering and sorting
245
265
  */
246
- export declare function whereDateIsAfterWithSort<T>(field: StringKeyPropertyKeys<T>, date?: Date, sortDirection?: OrderByDirection): FirestoreQueryConstraint[];
247
- export declare function whereDateIsAfterWithSort(field: FieldPathOrStringPath, date?: Date, sortDirection?: OrderByDirection): FirestoreQueryConstraint[];
266
+ export declare function whereDateIsAfterWithSort<T>(field: StringKeyPropertyKeys<T>, date?: Date, sortDirection?: OrderByDirection): FirestoreQueryOrderByAndWhereTuple;
267
+ export declare function whereDateIsAfterWithSort(field: FieldPathOrStringPath, date?: Date, sortDirection?: OrderByDirection): FirestoreQueryOrderByAndWhereTuple;
248
268
  /**
249
269
  * Creates a constraint to filter documents where a date field is strictly before a specified date.
250
270
  *
@@ -254,8 +274,8 @@ export declare function whereDateIsAfterWithSort(field: FieldPathOrStringPath, d
254
274
  * @param date - The exclusive upper bound date (default: current date/time)
255
275
  * @returns A query constraint for dates strictly before the specified date
256
276
  */
257
- export declare function whereDateIsBefore<T>(field: StringKeyPropertyKeys<T>, date?: Date): FirestoreQueryConstraint;
258
- export declare function whereDateIsBefore(field: FieldPathOrStringPath, date?: Date): FirestoreQueryConstraint;
277
+ export declare function whereDateIsBefore<T>(field: StringKeyPropertyKeys<T>, date?: Date): FirestoreQueryConstraint<WhereQueryConstraintData>;
278
+ export declare function whereDateIsBefore(field: FieldPathOrStringPath, date?: Date): FirestoreQueryConstraint<WhereQueryConstraintData>;
259
279
  /**
260
280
  * Creates constraints to filter documents where a date field is strictly before a specified date, with sorting.
261
281
  *
@@ -268,5 +288,5 @@ export declare function whereDateIsBefore(field: FieldPathOrStringPath, date?: D
268
288
  * @param sortDirection - Direction to sort results (default: 'desc')
269
289
  * @returns Array of query constraints for filtering and sorting
270
290
  */
271
- export declare function whereDateIsBeforeWithSort<T>(field: StringKeyPropertyKeys<T>, date?: Date, sortDirection?: OrderByDirection): FirestoreQueryConstraint[];
272
- export declare function whereDateIsBeforeWithSort(field: FieldPathOrStringPath, date?: Date, sortDirection?: OrderByDirection): FirestoreQueryConstraint[];
291
+ export declare function whereDateIsBeforeWithSort<T>(field: StringKeyPropertyKeys<T>, date?: Date, sortDirection?: OrderByDirection): FirestoreQueryOrderByAndWhereTuple;
292
+ export declare function whereDateIsBeforeWithSort(field: FieldPathOrStringPath, date?: Date, sortDirection?: OrderByDirection): FirestoreQueryOrderByAndWhereTuple;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Marker interface for a Firestore model whose document id IS the id of a
3
+ * record in an external system (e.g. a Zoho candidate id, a CheckHQ payroll
4
+ * id, a Typeform response id). Generic over a phantom `TId` discriminator so
5
+ * different external systems' ids do not interchange at compile-time.
6
+ *
7
+ * The phantom `__externalIdType` field is never persisted — it only exists in
8
+ * the TypeScript surface so semantic-typed external-id aliases (`type
9
+ * HellosubsZohoRecruitCandidateId = string`) flow through.
10
+ *
11
+ * The `extract-firebase-models` extractor recognises the exact-name marker
12
+ * and emits the `external-id-keyed-entity-root` archetype on the model.
13
+ */
14
+ export interface ExternalRelatedById<TId extends string = string> {
15
+ /**
16
+ * Phantom type discriminator; never persisted.
17
+ */
18
+ readonly __externalIdType?: TId;
19
+ }
@@ -1,3 +1,4 @@
1
+ export * from './external';
1
2
  export * from './user';
2
3
  export * from './notification';
3
4
  export * from './oidcmodel';
@@ -194,6 +194,9 @@ export declare const NOTIFICATION_SUMMARY_EMBEDDED_NOTIFICATION_ITEM_MESSAGE_MAX
194
194
  * Implements {@link InitializedNotificationModel} — requires server-side initialization to populate the owner (`o`) field.
195
195
  *
196
196
  * @dbxModel
197
+ * @dbxModelArchetype root-singleton-aggregate
198
+ * @dbxModelArchetype composite-key-root
199
+ * @dbxModelCompositeKey from=* encoding=two-way
197
200
  */
198
201
  export interface NotificationSummary extends InitializedNotificationModel {
199
202
  /**
@@ -288,6 +291,8 @@ export declare const notificationBoxIdentity: import("../..").RootFirestoreModel
288
291
  * @see `NotificationServerActions.createNotificationBox` in `@dereekb/firebase-server/model` for creation logic
289
292
  *
290
293
  * @dbxModel
294
+ * @dbxModelArchetype composite-key-root
295
+ * @dbxModelCompositeKey from=* encoding=two-way
291
296
  */
292
297
  export interface NotificationBox extends InitializedNotificationModel {
293
298
  /**
@@ -46,6 +46,7 @@ export declare const OIDC_ENTRY_CLIENT_TYPE: OidcEntryType;
46
46
  * (used primarily for Client entries so users can query their own registered OAuth clients).
47
47
  *
48
48
  * @dbxModel
49
+ * @dbxModelArchetype reference-registry hasChildren=false,hasInheritance=false
49
50
  */
50
51
  export interface OidcEntry {
51
52
  /**
@@ -262,6 +262,8 @@ export type StorageFileDownloadUrl = StorageFilePublicDownloadUrl | StorageFileS
262
262
  *
263
263
  * @template M - type of the arbitrary metadata stored in the `d` field
264
264
  * @dbxModel
265
+ * @dbxModelArchetype root-entity
266
+ * @dbxModelArchetype state-machine-item
265
267
  */
266
268
  export interface StorageFile<M extends StorageFileMetadata = StorageFileMetadata> extends StoragePath {
267
269
  /**
@@ -60,6 +60,7 @@ export type SystemStateStoredData = Record<string, any>;
60
60
  *
61
61
  * @template T - shape of the stored data record
62
62
  * @dbxModel
63
+ * @dbxModelArchetype system-state-singleton
63
64
  */
64
65
  export interface SystemState<T extends SystemStateStoredData = SystemStateStoredData> {
65
66
  /**
package/test/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@dereekb/firebase/test",
3
- "version": "13.11.11",
3
+ "version": "13.11.13",
4
4
  "peerDependencies": {
5
- "@dereekb/date": "13.11.11",
6
- "@dereekb/firebase": "13.11.11",
7
- "@dereekb/model": "13.11.11",
8
- "@dereekb/rxjs": "13.11.11",
9
- "@dereekb/util": "13.11.11",
5
+ "@dereekb/date": "13.11.13",
6
+ "@dereekb/firebase": "13.11.13",
7
+ "@dereekb/model": "13.11.13",
8
+ "@dereekb/rxjs": "13.11.13",
9
+ "@dereekb/util": "13.11.13",
10
10
  "@firebase/rules-unit-testing": "5.0.0",
11
11
  "date-fns": "^4.1.0",
12
12
  "firebase": "^12.12.1",