@dereekb/rxjs 13.43.0 → 14.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import { type Maybe, type ReadableError, type EqualityComparatorFunction, type GetterOrValue, type MaybeSoStrict } from '@dereekb/util';
2
2
  import { type MonoTypeOperatorFunction, type OperatorFunction, type Observable, type ObservableInputTuple } from 'rxjs';
3
- import { type LoadingState, type PageLoadingState, type MapLoadingStateResultsConfiguration, type LoadingStateValue, LoadingStateType, type LoadingStateWithValueType, type LoadingStateWithDefinedValue, type LoadingStateWithError } from './loading.state';
3
+ import { type LoadingState, type PageLoadingState, type MapLoadingStateResultsConfiguration, type LoadingStateValue, LoadingStateType, type LoadingStateWithValueType, type LoadingStateWithError } from './loading.state';
4
4
  /**
5
5
  * Wraps an observable output and maps the value to a {@link LoadingState}.
6
6
  *
@@ -52,7 +52,7 @@ export declare function loadingStateFromObs<T>(obs: Observable<T>, firstOnly?: b
52
52
  * @param obsB - the second LoadingState observable to combine
53
53
  * @returns An observable emitting the merged {@link LoadingState}.
54
54
  */
55
- export declare function combineLoadingStates<A, B>(obsA: Observable<LoadingState<A>>, obsB: Observable<LoadingState<B>>): Observable<LoadingState<A & B>>;
55
+ export declare function combineLoadingStates<A extends object, B extends object>(obsA: Observable<LoadingState<A>>, obsB: Observable<LoadingState<B>>): Observable<LoadingState<A & B>>;
56
56
  export declare function combineLoadingStates<A extends object, B extends object, O>(obsA: Observable<LoadingState<A>>, obsB: Observable<LoadingState<B>>, mergeFn: (a: A, b: B) => O): Observable<LoadingState<O>>;
57
57
  export declare function combineLoadingStates<A extends object, B extends object, C extends object>(obsA: Observable<LoadingState<A>>, obsB: Observable<LoadingState<B>>, obsC: Observable<LoadingState<C>>): Observable<LoadingState<A & B & C>>;
58
58
  export declare function combineLoadingStates<A extends object, B extends object, C extends object, O>(obsA: Observable<LoadingState<A>>, obsB: Observable<LoadingState<B>>, obsC: Observable<LoadingState<C>>, mergeFn: (a: A, b: B, c: C) => O): Observable<LoadingState<O>>;
@@ -84,13 +84,16 @@ export declare function combineLoadingStates<O>(...args: any[]): Observable<Load
84
84
  * const status$ = combineLoadingStatesStatus([loading$, success$]);
85
85
  * ```
86
86
  */
87
- export declare function combineLoadingStatesStatus<A extends readonly LoadingState<any>[]>(sources: readonly [...ObservableInputTuple<A>]): Observable<LoadingState<boolean>>;
87
+ export declare function combineLoadingStatesStatus<A extends readonly LoadingState[]>(sources: readonly [...ObservableInputTuple<A>]): Observable<LoadingState<boolean>>;
88
88
  /**
89
89
  * Merges `startWith()` with `beginLoading()` into a single typed operator.
90
90
  *
91
91
  * Preferred over using both individually, as typing information can get lost when chaining them separately.
92
92
  * An optional partial state can be provided to include additional metadata (e.g., page info) in the initial loading state.
93
93
  *
94
+ * @param state - Optional partial loading state to include in the initial emission.
95
+ * @returns A `MonoTypeOperatorFunction` that prepends a loading state to the observable.
96
+ *
94
97
  * @example
95
98
  * ```ts
96
99
  * // Emit a loading state immediately before the source observable emits
@@ -110,13 +113,8 @@ export declare function combineLoadingStatesStatus<A extends readonly LoadingSta
110
113
  * shareReplay(1)
111
114
  * );
112
115
  * ```
113
- *
114
- * @param state - Optional partial loading state to include in the initial emission.
115
- * @returns A `MonoTypeOperatorFunction` that prepends a loading state to the observable.
116
116
  */
117
- export declare function startWithBeginLoading<L extends LoadingState>(): MonoTypeOperatorFunction<L>;
118
- export declare function startWithBeginLoading<L extends LoadingState>(state?: Partial<LoadingState>): MonoTypeOperatorFunction<L>;
119
- export declare function startWithBeginLoading<L extends PageLoadingState>(state?: Partial<PageLoadingState>): MonoTypeOperatorFunction<L>;
117
+ export declare function startWithBeginLoading<L extends LoadingState>(state?: Partial<NoInfer<L>>): MonoTypeOperatorFunction<L>;
120
118
  /**
121
119
  * Returns the current value from the {@link LoadingState}, including `undefined` when still loading or no value is set.
122
120
  *
@@ -133,7 +131,7 @@ export declare function startWithBeginLoading<L extends PageLoadingState>(state?
133
131
  * );
134
132
  * ```
135
133
  */
136
- export declare function currentValueFromLoadingState<L extends LoadingState>(): OperatorFunction<L, Maybe<LoadingStateValue<L>>>;
134
+ export declare function currentValueFromLoadingState<T>(): OperatorFunction<LoadingState<T>, Maybe<T>>;
137
135
  /**
138
136
  * Returns the current non-null/non-undefined value from the {@link LoadingState}.
139
137
  *
@@ -151,7 +149,7 @@ export declare function currentValueFromLoadingState<L extends LoadingState>():
151
149
  * );
152
150
  * ```
153
151
  */
154
- export declare function valueFromLoadingState<L extends LoadingStateWithDefinedValue>(): OperatorFunction<L, MaybeSoStrict<LoadingStateValue<L>>>;
152
+ export declare function valueFromLoadingState<T>(): OperatorFunction<LoadingState<T>, MaybeSoStrict<T>>;
155
153
  /**
156
154
  * Returns the error once the {@link LoadingState} has finished loading with an error.
157
155
  *
@@ -168,7 +166,7 @@ export declare function valueFromLoadingState<L extends LoadingStateWithDefinedV
168
166
  * ).subscribe();
169
167
  * ```
170
168
  */
171
- export declare function errorFromLoadingState<L extends LoadingState>(): OperatorFunction<L, ReadableError>;
169
+ export declare function errorFromLoadingState(): OperatorFunction<LoadingState, ReadableError>;
172
170
  /**
173
171
  * Throws an error if the {@link LoadingState} value has an error.
174
172
  *
@@ -188,7 +186,7 @@ export declare function errorFromLoadingState<L extends LoadingState>(): Operato
188
186
  * );
189
187
  * ```
190
188
  */
191
- export declare function throwErrorFromLoadingStateError<L extends LoadingState>(): OperatorFunction<L, L>;
189
+ export declare function throwErrorFromLoadingStateError<L extends LoadingState>(): MonoTypeOperatorFunction<L>;
192
190
  /**
193
191
  * Returns the value once the {@link LoadingState} has finished loading, even if an error occurred or there is no value.
194
192
  *
@@ -213,14 +211,17 @@ export declare function throwErrorFromLoadingStateError<L extends LoadingState>(
213
211
  * @param defaultValue - Optional default value or getter to use when the finished state has no value.
214
212
  * @returns An `OperatorFunction` that emits the value (or default) once loading is finished.
215
213
  */
216
- export declare function valueFromFinishedLoadingState<L extends LoadingState>(defaultValue: GetterOrValue<LoadingStateValue<L>>): OperatorFunction<L, LoadingStateValue<L>>;
217
- export declare function valueFromFinishedLoadingState<L extends LoadingState>(defaultValue?: Maybe<GetterOrValue<LoadingStateValue<L>>>): OperatorFunction<L, Maybe<LoadingStateValue<L>>>;
218
- export declare function valueFromFinishedLoadingState<L extends LoadingStateWithDefinedValue>(): OperatorFunction<L, LoadingStateValue<L>>;
214
+ export declare function valueFromFinishedLoadingState<T>(defaultValue: GetterOrValue<NoInfer<T>>): OperatorFunction<LoadingState<T>, T>;
215
+ export declare function valueFromFinishedLoadingState<T>(defaultValue?: Maybe<GetterOrValue<NoInfer<T>>>): OperatorFunction<LoadingState<T>, Maybe<T>>;
219
216
  /**
220
217
  * Executes a side-effect function when the piped {@link LoadingState} matches the given {@link LoadingStateType}.
221
218
  *
222
219
  * This is a tap-style operator that does not modify the stream, but calls `fn` when the state matches the specified type.
223
220
  *
221
+ * @param fn - The side-effect function to call when the state matches.
222
+ * @param type - The {@link LoadingStateType} to match against.
223
+ * @returns A `MonoTypeOperatorFunction` that taps on matching states.
224
+ *
224
225
  * @example
225
226
  * ```ts
226
227
  * // Log whenever the state transitions to an error
@@ -233,19 +234,16 @@ export declare function valueFromFinishedLoadingState<L extends LoadingStateWith
233
234
  * tapOnLoadingStateType(() => showSpinner(), LoadingStateType.LOADING)
234
235
  * ).subscribe();
235
236
  * ```
236
- *
237
- * @param fn - The side-effect function to call when the state matches.
238
- * @param type - The {@link LoadingStateType} to match against.
239
- * @returns A `MonoTypeOperatorFunction` that taps on matching states.
240
237
  */
241
238
  export declare function tapOnLoadingStateType<L extends LoadingState>(fn: (state: L) => void, type: LoadingStateType): MonoTypeOperatorFunction<L>;
242
- export declare function tapOnLoadingStateType<L extends LoadingState>(fn: (state: L) => void, type: LoadingStateType): MonoTypeOperatorFunction<L>;
243
- export declare function tapOnLoadingStateType<L extends PageLoadingState>(fn: (state: L) => void, type: LoadingStateType): MonoTypeOperatorFunction<L>;
244
239
  /**
245
240
  * Executes a side-effect function when the input {@link LoadingState} has a successful value.
246
241
  *
247
242
  * This is a convenience wrapper around {@link tapOnLoadingStateType} with {@link LoadingStateType.SUCCESS}.
248
243
  *
244
+ * @param fn - The side-effect function to call on success states.
245
+ * @returns A `MonoTypeOperatorFunction` that taps on successful states.
246
+ *
249
247
  * @example
250
248
  * ```ts
251
249
  * // Log the successful value
@@ -253,18 +251,16 @@ export declare function tapOnLoadingStateType<L extends PageLoadingState>(fn: (s
253
251
  * tapOnLoadingStateSuccess((state) => console.log('Loaded:', state.value))
254
252
  * ).subscribe();
255
253
  * ```
256
- *
257
- * @param fn - The side-effect function to call on success states.
258
- * @returns A `MonoTypeOperatorFunction` that taps on successful states.
259
254
  */
260
255
  export declare function tapOnLoadingStateSuccess<L extends LoadingState>(fn: (state: L) => void): MonoTypeOperatorFunction<L>;
261
- export declare function tapOnLoadingStateSuccess<L extends LoadingState>(fn: (state: L) => void): MonoTypeOperatorFunction<L>;
262
- export declare function tapOnLoadingStateSuccess<L extends PageLoadingState>(fn: (state: L) => void): MonoTypeOperatorFunction<L>;
263
256
  /**
264
257
  * Convenience function for using {@link mapLoadingStateResults} with an Observable.
265
258
  *
266
259
  * Maps the value within a {@link LoadingState} using the provided configuration, preserving the loading/error state metadata.
267
260
  *
261
+ * @param config - Configuration for mapping the loading state value.
262
+ * @returns An `OperatorFunction` that maps the value within the loading state.
263
+ *
268
264
  * @example
269
265
  * ```ts
270
266
  * // Map a SystemState<T> loading state to just its data property
@@ -273,13 +269,8 @@ export declare function tapOnLoadingStateSuccess<L extends PageLoadingState>(fn:
273
269
  * shareReplay(1)
274
270
  * );
275
271
  * ```
276
- *
277
- * @param config - Configuration for mapping the loading state value.
278
- * @returns An `OperatorFunction` that maps the value within the loading state.
279
272
  */
280
- export declare function mapLoadingState<A, B, L extends LoadingState<A> = LoadingState<A>, O extends LoadingState<B> = LoadingState<B>>(config: MapLoadingStateResultsConfiguration<A, B, L, O>): OperatorFunction<L, O>;
281
- export declare function mapLoadingState<A, B, L extends PageLoadingState<A> = PageLoadingState<A>, O extends PageLoadingState<B> = PageLoadingState<B>>(config: MapLoadingStateResultsConfiguration<A, B, L, O>): OperatorFunction<L, O>;
282
- export declare function mapLoadingState<A, B, L extends Partial<PageLoadingState<A>> = Partial<PageLoadingState<A>>, O extends Partial<PageLoadingState<B>> = Partial<PageLoadingState<B>>>(config: MapLoadingStateResultsConfiguration<A, B, L, O>): OperatorFunction<L, O>;
273
+ export declare function mapLoadingState<L extends LoadingState, B, O extends LoadingState = LoadingStateWithValueType<L, B>>(config: MapLoadingStateResultsConfiguration<L, B, O>): OperatorFunction<L, O>;
283
274
  /**
284
275
  * Maps the value within a {@link LoadingState} using an arbitrary RxJS operator.
285
276
  *
@@ -289,6 +280,10 @@ export declare function mapLoadingState<A, B, L extends Partial<PageLoadingState
289
280
  *
290
281
  * Error and loading states are passed through without invoking the operator.
291
282
  *
283
+ * @param operator - The RxJS operator to apply to the loading state's value.
284
+ * @param mapOnUndefined - If true, also applies the operator when the value is undefined (but loading is finished and no error).
285
+ * @returns An `OperatorFunction` that transforms the value within the loading state.
286
+ *
292
287
  * @example
293
288
  * ```ts
294
289
  * // Filter loading state values using a search string operator
@@ -312,20 +307,17 @@ export declare function mapLoadingState<A, B, L extends Partial<PageLoadingState
312
307
  * shareReplay(1)
313
308
  * );
314
309
  * ```
315
- *
316
- * @param operator - The RxJS operator to apply to the loading state's value.
317
- * @param mapOnUndefined - If true, also applies the operator when the value is undefined (but loading is finished and no error).
318
- * @returns An `OperatorFunction` that transforms the value within the loading state.
319
310
  */
320
311
  export declare function mapLoadingStateValueWithOperator<L extends LoadingState, O>(operator: OperatorFunction<LoadingStateValue<L>, O>, mapOnUndefined?: boolean): OperatorFunction<L, LoadingStateWithValueType<L, O>>;
321
- export declare function mapLoadingStateValueWithOperator<L extends PageLoadingState, O>(operator: OperatorFunction<LoadingStateValue<L>, O>, mapOnUndefined?: boolean): OperatorFunction<L, LoadingStateWithValueType<L, O>>;
322
- export declare function mapLoadingStateValueWithOperator<L extends Partial<PageLoadingState>, O>(operator: OperatorFunction<LoadingStateValue<L>, O>, mapOnUndefined?: boolean): OperatorFunction<L, LoadingStateWithValueType<L, O>>;
323
312
  /**
324
313
  * Catches a {@link LoadingStateWithError} and transforms it into a new {@link LoadingState} using the provided operator.
325
314
  *
326
315
  * Non-error states are passed through unchanged. When an error state is encountered, it is passed through the
327
316
  * operator to produce a replacement state. If the operator does not emit immediately, a temporary loading state is emitted.
328
317
  *
318
+ * @param operator - The RxJS operator to apply to the error loading state.
319
+ * @returns A `MonoTypeOperatorFunction` that catches and transforms error states.
320
+ *
329
321
  * @example
330
322
  * ```ts
331
323
  * // On error, return an empty list instead of propagating the error
@@ -335,13 +327,8 @@ export declare function mapLoadingStateValueWithOperator<L extends Partial<PageL
335
327
  * )
336
328
  * );
337
329
  * ```
338
- *
339
- * @param operator - The RxJS operator to apply to the error loading state.
340
- * @returns A `MonoTypeOperatorFunction` that catches and transforms error states.
341
330
  */
342
- export declare function catchLoadingStateErrorWithOperator<L extends LoadingState>(operator: OperatorFunction<L & LoadingStateWithError, L>): MonoTypeOperatorFunction<L>;
343
- export declare function catchLoadingStateErrorWithOperator<L extends PageLoadingState>(operator: OperatorFunction<L & LoadingStateWithError, L>): MonoTypeOperatorFunction<L>;
344
- export declare function catchLoadingStateErrorWithOperator<L extends Partial<PageLoadingState>>(operator: OperatorFunction<L & LoadingStateWithError, L>): MonoTypeOperatorFunction<L>;
331
+ export declare function catchLoadingStateErrorWithOperator<L extends LoadingState>(operator: OperatorFunction<NoInfer<L> & LoadingStateWithError, NoInfer<L>>): MonoTypeOperatorFunction<L>;
345
332
  /**
346
333
  * Config for {@link distinctLoadingState}.
347
334
  */
@@ -363,7 +350,7 @@ export interface DistinctLoadingStateConfig<L extends LoadingState> {
363
350
  /**
364
351
  * Used for comparing the metadata values of the LoadingState. By default uses isPageLoadingStateMetadataEqual.
365
352
  */
366
- readonly metadataComparator?: EqualityComparatorFunction<Maybe<Partial<L>>>;
353
+ readonly metadataComparator?: EqualityComparatorFunction<Maybe<Partial<PageLoadingState>>>;
367
354
  }
368
355
  /**
369
356
  * A special `distinctUntilChanged`-like operator for {@link LoadingState} and {@link PageLoadingState}.
@@ -375,6 +362,9 @@ export interface DistinctLoadingStateConfig<L extends LoadingState> {
375
362
  * Accepts either a simple {@link EqualityComparatorFunction} for comparing values, or a full
376
363
  * {@link DistinctLoadingStateConfig} for more fine-grained control over comparison behavior.
377
364
  *
365
+ * @param config - Either a value comparator function or a full {@link DistinctLoadingStateConfig}.
366
+ * @returns A `MonoTypeOperatorFunction` that filters out duplicate loading states.
367
+ *
378
368
  * @example
379
369
  * ```ts
380
370
  * // Filter out duplicate loading states using key-based comparison
@@ -389,13 +379,8 @@ export interface DistinctLoadingStateConfig<L extends LoadingState> {
389
379
  * })
390
380
  * );
391
381
  * ```
392
- *
393
- * @param config - Either a value comparator function or a full {@link DistinctLoadingStateConfig}.
394
- * @returns A `MonoTypeOperatorFunction` that filters out duplicate loading states.
395
382
  */
396
- export declare function distinctLoadingState<L extends LoadingState>(config: EqualityComparatorFunction<Maybe<LoadingStateValue<L>>> | DistinctLoadingStateConfig<L>): MonoTypeOperatorFunction<L>;
397
- export declare function distinctLoadingState<L extends PageLoadingState>(config: EqualityComparatorFunction<Maybe<LoadingStateValue<L>>> | DistinctLoadingStateConfig<L>): MonoTypeOperatorFunction<L>;
398
- export declare function distinctLoadingState<L extends Partial<PageLoadingState>>(config: EqualityComparatorFunction<Maybe<LoadingStateValue<L>>> | DistinctLoadingStateConfig<L>): MonoTypeOperatorFunction<L>;
383
+ export declare function distinctLoadingState<L extends LoadingState>(config: NoInfer<EqualityComparatorFunction<Maybe<LoadingStateValue<L>>> | DistinctLoadingStateConfig<L>>): MonoTypeOperatorFunction<L>;
399
384
  /**
400
385
  * Creates a Promise from an Observable of {@link LoadingState} that resolves when loading finishes.
401
386
  *