@dereekb/rxjs 13.0.7 → 13.2.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 (52) hide show
  1. package/index.cjs.js +1284 -336
  2. package/index.cjs.js.map +1 -1
  3. package/index.esm.js +1284 -336
  4. package/index.esm.js.map +1 -1
  5. package/package.json +2 -2
  6. package/src/lib/filter/filter.d.ts +28 -13
  7. package/src/lib/filter/filter.map.d.ts +69 -2
  8. package/src/lib/filter/filter.preset.d.ts +35 -0
  9. package/src/lib/filter/filter.source.d.ts +61 -2
  10. package/src/lib/iterator/iteration.accumulator.d.ts +39 -13
  11. package/src/lib/iterator/iteration.accumulator.rxjs.d.ts +25 -8
  12. package/src/lib/iterator/iteration.d.ts +16 -5
  13. package/src/lib/iterator/iteration.mapped.d.ts +19 -6
  14. package/src/lib/iterator/iteration.mapped.page.d.ts +9 -6
  15. package/src/lib/iterator/iteration.next.d.ts +17 -14
  16. package/src/lib/iterator/iterator.page.d.ts +54 -16
  17. package/src/lib/loading/loading.context.rxjs.d.ts +17 -1
  18. package/src/lib/loading/loading.context.simple.d.ts +38 -1
  19. package/src/lib/loading/loading.context.state.d.ts +32 -4
  20. package/src/lib/loading/loading.context.state.list.d.ts +25 -3
  21. package/src/lib/loading/loading.context.value.d.ts +43 -3
  22. package/src/lib/loading/loading.state.d.ts +272 -41
  23. package/src/lib/loading/loading.state.list.d.ts +50 -9
  24. package/src/lib/lock.d.ts +149 -6
  25. package/src/lib/object.d.ts +28 -4
  26. package/src/lib/rxjs/array.d.ts +39 -13
  27. package/src/lib/rxjs/boolean.d.ts +8 -4
  28. package/src/lib/rxjs/decision.d.ts +13 -7
  29. package/src/lib/rxjs/delta.d.ts +14 -2
  30. package/src/lib/rxjs/expires.d.ts +20 -8
  31. package/src/lib/rxjs/factory.d.ts +16 -3
  32. package/src/lib/rxjs/getter.d.ts +24 -10
  33. package/src/lib/rxjs/key.d.ts +7 -5
  34. package/src/lib/rxjs/lifecycle.d.ts +10 -7
  35. package/src/lib/rxjs/loading.d.ts +10 -2
  36. package/src/lib/rxjs/map.d.ts +6 -5
  37. package/src/lib/rxjs/misc.d.ts +26 -6
  38. package/src/lib/rxjs/model.d.ts +2 -2
  39. package/src/lib/rxjs/number.d.ts +8 -4
  40. package/src/lib/rxjs/rxjs.async.d.ts +20 -7
  41. package/src/lib/rxjs/rxjs.d.ts +26 -18
  42. package/src/lib/rxjs/rxjs.error.d.ts +17 -0
  43. package/src/lib/rxjs/rxjs.map.d.ts +37 -9
  44. package/src/lib/rxjs/rxjs.unique.d.ts +6 -3
  45. package/src/lib/rxjs/set.d.ts +34 -0
  46. package/src/lib/rxjs/string.d.ts +18 -1
  47. package/src/lib/rxjs/timeout.d.ts +21 -1
  48. package/src/lib/rxjs/use.d.ts +4 -2
  49. package/src/lib/rxjs/value.d.ts +73 -39
  50. package/src/lib/subscription.d.ts +80 -3
  51. package/src/lib/work/work.factory.d.ts +42 -9
  52. package/src/lib/work/work.instance.d.ts +26 -2
@@ -20,19 +20,32 @@ export interface LoadingErrorPair {
20
20
  readonly error?: Maybe<ReadableError>;
21
21
  }
22
22
  /**
23
- * Returns true if the two LoadingStates are considered equal, by comparing the loading, loadingProgress, error, and value properties.
23
+ * Compares two {@link LoadingState} instances for shallow equality across all key properties.
24
24
  *
25
- * @param a LoadingState a
26
- * @param b LoadingState b
27
- * @returns Returns true if the input LoadingStates are considered equal.
25
+ * @example
26
+ * ```ts
27
+ * const a = successResult('hello');
28
+ * const b = successResult('hello');
29
+ * isLoadingStateEqual(a, b); // true (same value reference is not required, but same primitive is)
30
+ *
31
+ * const c = beginLoading();
32
+ * isLoadingStateEqual(a, c); // false
33
+ * ```
34
+ *
35
+ * @param a - first loading state
36
+ * @param b - second loading state
37
+ * @returns true if loading, loadingProgress, error, and value are all strictly equal
28
38
  */
29
39
  export declare function isLoadingStateEqual<T extends LoadingState>(a: T, b: T): boolean;
30
40
  /**
31
- * Returns true if the input LoadingErrorPair has the same loading (truthy vs falsy) and error values as the other LoadingErrorPair.
41
+ * Compares the metadata (loading flag, loading progress, and error) of two {@link LoadingErrorPair} instances,
42
+ * using loose equality for loading and nullish-aware comparison for progress and error.
43
+ *
44
+ * Does not compare the `value` property — only structural metadata.
32
45
  *
33
- * @param a LoadingErrorPair a
34
- * @param b LoadingErrorPair b
35
- * @returns Returns true if the input's metadata is considered equivalent.
46
+ * @param a - first loading error pair
47
+ * @param b - second loading error pair
48
+ * @returns true if both pairs have equivalent metadata
36
49
  */
37
50
  export declare function isLoadingStateMetadataEqual(a: Partial<LoadingErrorPair>, b: Partial<LoadingErrorPair>): boolean;
38
51
  /**
@@ -115,39 +128,158 @@ export declare enum LoadingStateType {
115
128
  ERROR = "error"
116
129
  }
117
130
  /**
118
- * Returns the LoadingStateType for the input LoadingState
131
+ * Determines the current {@link LoadingStateType} of a {@link LoadingState}.
119
132
  *
120
- * @param loadingState
121
- * @returns
133
+ * Returns `LOADING` if still loading, `SUCCESS` if finished with a value key,
134
+ * `ERROR` if finished with an error key, or `IDLE` if finished with neither.
135
+ *
136
+ * @example
137
+ * ```ts
138
+ * loadingStateType(beginLoading()); // LoadingStateType.LOADING
139
+ * loadingStateType(successResult(42)); // LoadingStateType.SUCCESS
140
+ * loadingStateType(errorResult(new Error())); // LoadingStateType.ERROR
141
+ * loadingStateType({ loading: false }); // LoadingStateType.IDLE
142
+ * ```
143
+ *
144
+ * @param loadingState - the loading state to classify
145
+ * @returns the corresponding {@link LoadingStateType}
122
146
  */
123
147
  export declare function loadingStateType(loadingState: LoadingState): LoadingStateType;
148
+ /**
149
+ * Whether the given {@link LoadingState} has finished loading.
150
+ *
151
+ * Returns `true` when `loading` is explicitly `false`, or when `loading` is not `true`
152
+ * and either a value, error, or `null` value is present.
153
+ *
154
+ * @example
155
+ * ```ts
156
+ * isLoadingStateFinishedLoading(successResult('done')); // true
157
+ * isLoadingStateFinishedLoading(beginLoading()); // false
158
+ * isLoadingStateFinishedLoading({ loading: false }); // true
159
+ * isLoadingStateFinishedLoading(null); // false
160
+ * ```
161
+ *
162
+ * @param state - the loading state to check (may be null/undefined)
163
+ * @returns true if loading is complete
164
+ */
124
165
  export declare function isLoadingStateFinishedLoading<L extends LoadingState>(state: Maybe<L>): boolean;
125
166
  /**
126
- * Returns a LoadingState that has no result and is not loading.
167
+ * Creates an idle {@link LoadingState} with `loading: false` and no value or error.
168
+ *
169
+ * Represents a state where no loading has been initiated yet.
170
+ *
171
+ * @example
172
+ * ```ts
173
+ * const state = idleLoadingState();
174
+ * // { loading: false }
175
+ * loadingStateType(state); // LoadingStateType.IDLE
176
+ * ```
127
177
  */
128
178
  export declare function idleLoadingState<T>(): LoadingState<T>;
179
+ /**
180
+ * Creates a {@link LoadingState} with `loading: true`, optionally merged with additional state properties.
181
+ *
182
+ * @example
183
+ * ```ts
184
+ * const state = beginLoading();
185
+ * // { loading: true }
186
+ *
187
+ * const pageState = beginLoading({ page: 2 });
188
+ * // { page: 2, loading: true }
189
+ * ```
190
+ *
191
+ * @param state - optional partial state to merge with the loading flag
192
+ * @returns a loading state with `loading: true`
193
+ */
129
194
  export declare function beginLoading<T>(): LoadingState<T>;
130
195
  export declare function beginLoading<T>(state?: Partial<PageLoadingState<T>>): PageLoadingState<T>;
131
196
  export declare function beginLoading<T>(state?: Partial<LoadingState<T>>): LoadingState<T>;
197
+ /**
198
+ * Creates a {@link PageLoadingState} that is loading for the given page number.
199
+ *
200
+ * @param page - the page number being loaded
201
+ * @param state - optional partial state to merge
202
+ * @returns a page loading state with `loading: true`
203
+ */
132
204
  export declare function beginLoadingPage<T>(page: PageNumber, state?: Partial<PageLoadingState<T>>): PageLoadingState<T>;
205
+ /**
206
+ * Creates a successful {@link LoadingState} with the given value and `loading: false`.
207
+ *
208
+ * @example
209
+ * ```ts
210
+ * const state = successResult({ name: 'Alice' });
211
+ * // { value: { name: 'Alice' }, loading: false }
212
+ * ```
213
+ *
214
+ * @param value - the loaded value
215
+ * @returns a loading state representing a successful result
216
+ */
133
217
  export declare function successResult<T>(value: T): LoadingStateWithValue<T>;
218
+ /**
219
+ * Creates a successful {@link PageLoadingState} for a specific page.
220
+ *
221
+ * @param page - the page number
222
+ * @param value - the loaded value
223
+ * @returns a page loading state representing success
224
+ */
134
225
  export declare function successPageResult<T>(page: PageNumber, value: T): PageLoadingState<T>;
226
+ /**
227
+ * Creates a {@link LoadingState} representing an error with `loading: false`.
228
+ *
229
+ * Converts the input error to a {@link ReadableError} via {@link toReadableError}.
230
+ *
231
+ * @example
232
+ * ```ts
233
+ * const state = errorResult(new Error('Not found'));
234
+ * // { error: { message: 'Not found', ... }, loading: false }
235
+ * ```
236
+ *
237
+ * @param error - the error to wrap (string, Error, or ReadableError)
238
+ * @returns a loading state representing an error
239
+ */
135
240
  export declare function errorResult<T>(error?: Maybe<ErrorInput>): LoadingState<T>;
241
+ /**
242
+ * Creates a {@link PageLoadingState} representing an error for a specific page.
243
+ *
244
+ * @param page - the page number
245
+ * @param error - the error to include
246
+ * @returns a page loading state representing an error
247
+ */
136
248
  export declare function errorPageResult<T>(page: PageNumber, error?: Maybe<ReadableError | ReadableDataError>): PageLoadingState<T>;
137
249
  /**
138
- * Returns true if any of the input LoadingStates return true for isLoadingStateLoading().
250
+ * Whether any of the given {@link LoadingState} instances are currently loading.
139
251
  *
140
- * @param states
141
- * @returns
252
+ * @example
253
+ * ```ts
254
+ * isAnyLoadingStateInLoadingState([successResult(1), beginLoading()]); // true
255
+ * isAnyLoadingStateInLoadingState([successResult(1), successResult(2)]); // false
256
+ * ```
257
+ *
258
+ * @param states - array of loading states to check
259
+ * @returns true if at least one state is loading
142
260
  */
143
261
  export declare function isAnyLoadingStateInLoadingState(states: LoadingState[]): boolean;
144
262
  /**
145
- * Returns true if all input LoadingStates return true for isLoadingStateLoading().
263
+ * Whether all given {@link LoadingState} instances have finished loading.
146
264
  *
147
- * @param states
148
- * @returns
265
+ * @example
266
+ * ```ts
267
+ * areAllLoadingStatesFinishedLoading([successResult(1), successResult(2)]); // true
268
+ * areAllLoadingStatesFinishedLoading([successResult(1), beginLoading()]); // false
269
+ * ```
270
+ *
271
+ * @param states - array of loading states to check
272
+ * @returns true if every state has finished loading
149
273
  */
150
274
  export declare function areAllLoadingStatesFinishedLoading(states: LoadingState[]): boolean;
275
+ /**
276
+ * Creates a predicate function that checks whether a {@link LoadingState} matches the given {@link LoadingStateType}.
277
+ *
278
+ * When the target type is `IDLE`, returns `true` for null/undefined states.
279
+ *
280
+ * @param type - the loading state type to match against
281
+ * @returns a predicate function for the given type
282
+ */
151
283
  export declare function isLoadingStateWithStateType(type: LoadingStateType): <L extends LoadingState>(state: Maybe<L>) => boolean;
152
284
  /**
153
285
  * Returns true if the input LoadingState passed to loadingStateType() returns IDLE.
@@ -182,48 +314,97 @@ export declare const isLoadingStateInSuccessState: <L extends LoadingState>(stat
182
314
  */
183
315
  export declare const isLoadingStateInErrorState: <L extends LoadingState>(state: Maybe<L>) => boolean;
184
316
  /**
185
- * Whether or not the input LoadingState has a non-undefined value.
317
+ * Type guard that checks whether a {@link LoadingState} has a non-undefined value, regardless of loading status.
186
318
  *
187
- * @param state
188
- * @returns
319
+ * @example
320
+ * ```ts
321
+ * isLoadingStateWithDefinedValue(successResult('hello')); // true
322
+ * isLoadingStateWithDefinedValue(successResult(null)); // true (null is defined)
323
+ * isLoadingStateWithDefinedValue(beginLoading()); // false
324
+ * ```
325
+ *
326
+ * @param state - the loading state to check
327
+ * @returns true if the state has a defined (non-undefined) value
189
328
  */
190
329
  export declare function isLoadingStateWithDefinedValue<L extends LoadingState>(state: Maybe<L> | LoadingStateWithDefinedValue<LoadingStateValue<L>>): state is LoadingStateWithDefinedValue<LoadingStateValue<L>>;
191
330
  /**
192
- * Whether or not the input LoadingState has a non-null error defined. It may be loading.
331
+ * Type guard that checks whether a {@link LoadingState} has a non-null error, regardless of loading status.
193
332
  *
194
- * @param state
195
- * @returns
333
+ * @example
334
+ * ```ts
335
+ * isLoadingStateWithError(errorResult(new Error('fail'))); // true
336
+ * isLoadingStateWithError(successResult('ok')); // false
337
+ * ```
338
+ *
339
+ * @param state - the loading state to check
340
+ * @returns true if the state has an error
196
341
  */
197
342
  export declare function isLoadingStateWithError<L extends LoadingState>(state: Maybe<L> | LoadingState<LoadingStateValue<L>>): state is LoadingStateWithError<LoadingStateValue<L>>;
198
343
  /**
199
- * Whether or not the input LoadingState is not loading and has a non-null value.
344
+ * Type guard that checks whether a {@link LoadingState} has finished loading and has a defined value.
200
345
  *
201
- * @param state
202
- * @returns
346
+ * @param state - the loading state to check
347
+ * @returns true if finished loading with a non-undefined value
203
348
  */
204
349
  export declare function isLoadingStateFinishedLoadingWithDefinedValue<L extends LoadingState>(state: Maybe<L> | LoadingStateWithDefinedValue<LoadingStateValue<L>>): state is LoadingStateWithDefinedValue<LoadingStateValue<L>>;
205
350
  /**
206
- * Whether or not the input LoadingState is not loading and has an error defined.
351
+ * Type guard that checks whether a {@link LoadingState} has finished loading and has an error.
207
352
  *
208
- * @param state
209
- * @returns
353
+ * @param state - the loading state to check
354
+ * @returns true if finished loading with an error
210
355
  */
211
356
  export declare function isLoadingStateFinishedLoadingWithError<L extends LoadingState>(state: Maybe<L> | LoadingState<LoadingStateValue<L>>): state is LoadingStateWithError<LoadingStateValue<L>>;
212
357
  /**
213
- * Returns true if the metadata from both input states are equivalent.
358
+ * Compares the metadata (page, loading, error) of two {@link PageLoadingState} instances for equivalence.
359
+ *
360
+ * Does not compare values — only structural metadata.
214
361
  *
215
- * The considered metadata is the page, loading, and error values.
362
+ * @example
363
+ * ```ts
364
+ * isPageLoadingStateMetadataEqual(
365
+ * { page: 1, loading: true },
366
+ * { page: 1, loading: true }
367
+ * ); // true
216
368
  *
217
- * @param a
218
- * @param b
369
+ * isPageLoadingStateMetadataEqual(
370
+ * { page: 1 },
371
+ * { page: 2 }
372
+ * ); // false
373
+ * ```
374
+ *
375
+ * @param a - first page loading state
376
+ * @param b - second page loading state
377
+ * @returns true if metadata is equivalent
219
378
  */
220
379
  export declare function isPageLoadingStateMetadataEqual(a: Partial<PageLoadingState>, b: Partial<PageLoadingState>): boolean;
221
380
  /**
222
- * Merges the input LoadingStates.
381
+ * Merges multiple {@link LoadingState} instances into a single combined state.
382
+ *
383
+ * If any input is loading, returns a loading state. If any has an error (and is not still loading),
384
+ * returns the first error. When all are successful, merges the values using the optional merge function
385
+ * or `mergeObjects` by default.
223
386
  *
224
- * If one is unavailable, it is considered loading.
225
- * If one is loading, will return the loading state.
226
- * If one has an error and is not loading, will return the error with loading false.
387
+ * @example
388
+ * ```ts
389
+ * // Merge two successful states (values spread-merged)
390
+ * const merged = mergeLoadingStates(
391
+ * successResult({ a: 1 }),
392
+ * successResult({ b: 2 })
393
+ * );
394
+ * // { loading: false, value: { a: 1, b: 2 } }
395
+ *
396
+ * // Merge with a custom function
397
+ * const merged = mergeLoadingStates(
398
+ * successResult({ x: 10 }),
399
+ * successResult({ y: 20 }),
400
+ * (a, b) => ({ sum: a.x + b.y })
401
+ * );
402
+ * // { loading: false, value: { sum: 30 } }
403
+ *
404
+ * // Any loading input makes the result loading
405
+ * const merged = mergeLoadingStates(beginLoading(), successResult({ a: 1 }));
406
+ * // { loading: true }
407
+ * ```
227
408
  */
228
409
  export declare function mergeLoadingStates<A extends object, B extends object>(a: LoadingState<A>, b: LoadingState<B>): LoadingState<A & B>;
229
410
  export declare function mergeLoadingStates<A extends object, B extends object, O>(a: LoadingState<A>, b: LoadingState<B>, mergeFn: (a: A, b: B) => O): LoadingState<O>;
@@ -235,15 +416,29 @@ export declare function mergeLoadingStates<A extends object, B extends object, C
235
416
  export declare function mergeLoadingStates<A extends object, B extends object, C extends object, D extends object, E extends object, O>(a: LoadingState<A>, b: LoadingState<B>, c: LoadingState<C>, d: LoadingState<D>, e: LoadingState<E>, mergeFn: (a: A, b: B, c: C, d: D, e: E) => O): LoadingState<O>;
236
417
  export declare function mergeLoadingStates<O>(...args: any[]): LoadingState<O>;
237
418
  /**
238
- * Returns a new merged state to be loading or idle, and clears the current/error value. It will have a LoadingStateType of LOADING if loading is true.
419
+ * Returns a copy of the state with the value and error cleared, and `loading` set to the given flag.
420
+ *
421
+ * Useful for resetting a state back to loading or idle without losing other metadata (e.g., page).
422
+ *
423
+ * @param state - the state to copy metadata from
424
+ * @param loading - whether to mark as loading (defaults to true)
425
+ * @returns a new state with value/error cleared
239
426
  */
240
427
  export declare function mergeLoadingStateWithLoading<S extends LoadingState>(state: S, loading?: boolean): S;
241
428
  /**
242
- * Returns a new merged state with the input value. It will have a LoadingStateType of SUCCESS now.
429
+ * Returns a copy of the state with the given value, `loading: false`, and error cleared.
430
+ *
431
+ * @param state - the state to copy metadata from
432
+ * @param value - the new value to set
433
+ * @returns a new state representing success
243
434
  */
244
435
  export declare function mergeLoadingStateWithValue<S extends LoadingState>(state: S, value: LoadingStateValue<S> | undefined): S;
245
436
  /**
246
- * Returns a new merged state with the input error. It will have a LoadingStateType of ERROR now.
437
+ * Returns a copy of the state with the given error and `loading: false`.
438
+ *
439
+ * @param state - the state to copy metadata from
440
+ * @param error - the error to set
441
+ * @returns a new state representing an error
247
442
  */
248
443
  export declare function mergeLoadingStateWithError<S extends LoadingState = LoadingState>(state: S, error?: ReadableDataError): S;
249
444
  export type MapMultipleLoadingStateValuesFn<T, X> = (input: X[]) => T;
@@ -251,6 +446,17 @@ export interface MapMultipleLoadingStateResultsConfiguration<T, X, L extends Loa
251
446
  mapValues?: MapMultipleLoadingStateValuesFn<T, X>;
252
447
  mapState?: (input: L) => R;
253
448
  }
449
+ /**
450
+ * Maps multiple {@link LoadingState} results into a single state using a value mapping or state mapping function.
451
+ *
452
+ * Returns `undefined` if any input is still loading or has an error.
453
+ *
454
+ * @param input - array of loading states to combine
455
+ * @param config - mapping configuration with either `mapValues` or `mapState`
456
+ * @returns the combined loading state, or undefined if inputs are not ready
457
+ *
458
+ * @throws {Error} When neither `mapValues` nor `mapState` is provided in the config.
459
+ */
254
460
  export declare function mapMultipleLoadingStateResults<T, X, L extends LoadingState<X>[], R extends LoadingState<T>>(input: L, config: MapMultipleLoadingStateResultsConfiguration<T, X, L, R>): Maybe<R>;
255
461
  export type MapLoadingStateFn<A, B, L extends LoadingState<A> = LoadingState<A>, O extends LoadingState<B> = LoadingState<B>> = (input: L, value?: B) => O;
256
462
  export type MapLoadingStateValuesFn<A, B, L extends LoadingState<A> = LoadingState<A>> = (input: A, state: L) => B;
@@ -259,9 +465,34 @@ export interface MapLoadingStateResultsConfiguration<A, B, L extends LoadingStat
259
465
  mapValue?: MapLoadingStateValuesFn<A, B, L>;
260
466
  mapState?: MapLoadingStateFn<A, B, L, O>;
261
467
  }
468
+ /**
469
+ * Maps the value of a single {@link LoadingState} to a new type using the provided configuration.
470
+ *
471
+ * Preserves the loading/error metadata while transforming the value via `mapValue` or the entire
472
+ * state via `mapState`. When `alwaysMapValue` is true, maps even when the value is null/undefined.
473
+ *
474
+ * @example
475
+ * ```ts
476
+ * const result = mapLoadingStateResults(successResult(0), {
477
+ * mapValue: (v) => `Value: ${v}`
478
+ * });
479
+ * // { value: 'Value: 0', loading: false }
480
+ * ```
481
+ *
482
+ * @param input - the loading state to transform
483
+ * @param config - mapping configuration
484
+ * @returns the transformed loading state
485
+ */
262
486
  export declare function mapLoadingStateResults<A, B, L extends LoadingState<A> = LoadingState<A>, O extends LoadingState<B> = LoadingState<B>>(input: L, config: MapLoadingStateResultsConfiguration<A, B, L, O>): O;
263
487
  export declare function mapLoadingStateResults<A, B, L extends PageLoadingState<A> = PageLoadingState<A>, O extends PageLoadingState<B> = PageLoadingState<B>>(input: L, config: MapLoadingStateResultsConfiguration<A, B, L, O>): O;
264
488
  export declare function mapLoadingStateResults<A, B, L extends Partial<PageLoadingState<A>> = Partial<PageLoadingState<A>>, O extends Partial<PageLoadingState<B>> = Partial<PageLoadingState<B>>>(input: L, config: MapLoadingStateResultsConfiguration<A, B, L, O>): O;
265
489
  export type MapLoadingStateValueFunction<O, I, L extends LoadingState<I> = LoadingState<I>> = MapFunction<L, Maybe<O>>;
266
490
  export type MapLoadingStateValueMapFunction<O, I, L extends LoadingState<I> = LoadingState<I>> = (item: I, state: L) => Maybe<O>;
491
+ /**
492
+ * Creates a function that extracts and maps the value from a {@link LoadingState}, returning undefined
493
+ * when the state has no value.
494
+ *
495
+ * @param mapFn - function to transform the value and state into the output type
496
+ * @returns a function that accepts a loading state and returns the mapped value or undefined
497
+ */
267
498
  export declare function mapLoadingStateValueFunction<O, I, L extends LoadingState<I> = LoadingState<I>>(mapFn: MapLoadingStateValueMapFunction<O, I, L>): MapLoadingStateValueFunction<O, I, L>;
@@ -2,27 +2,68 @@ import { type PageNumber } from '@dereekb/util';
2
2
  import { type Observable, type OperatorFunction } from 'rxjs';
3
3
  import { type LoadingStateValue, type ListLoadingState, type PageLoadingState } from './loading.state';
4
4
  /**
5
- * Returns true if the loading state is not loading and is empty.
5
+ * Whether the {@link ListLoadingState} has no value or an empty array.
6
6
  *
7
- * @param listLoadingState
8
- * @returns
7
+ * Returns true if the value is nullish or has zero length, regardless of loading status.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * isListLoadingStateWithEmptyValue(successResult([])); // true
12
+ * isListLoadingStateWithEmptyValue(successResult([1, 2])); // false
13
+ * isListLoadingStateWithEmptyValue(beginLoading()); // true (no value)
14
+ * ```
15
+ *
16
+ * @param listLoadingState - the list loading state to check
17
+ * @returns true if the value is empty or absent
9
18
  */
10
19
  export declare function isListLoadingStateWithEmptyValue<T>(listLoadingState: ListLoadingState<T>): boolean;
11
20
  /**
12
- * Convenience function that merges map() with isListLoadingStateWithEmptyValue()
21
+ * RxJS operator that maps each emitted {@link ListLoadingState} to a boolean indicating whether the list is empty.
13
22
  *
14
- * @returns
23
+ * @example
24
+ * ```ts
25
+ * of(successResult([])).pipe(
26
+ * mapIsListLoadingStateWithEmptyValue()
27
+ * ).subscribe((isEmpty) => console.log(isEmpty)); // true
28
+ * ```
29
+ *
30
+ * @returns an operator that emits true when the list value is empty or absent
15
31
  */
16
32
  export declare function mapIsListLoadingStateWithEmptyValue<T>(): OperatorFunction<ListLoadingState<T>, boolean>;
17
33
  /**
18
- * Wraps an observable output and maps the value to a PageLoadingState.
34
+ * Wraps an observable and converts its emissions into a {@link PageLoadingState} for the given page number.
35
+ *
36
+ * Uses {@link loadingStateFromObs} internally and attaches the page number to each emitted state.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * const pageState$ = pageLoadingStateFromObs(fetchItems$, false, 2);
41
+ * // emits: { loading: true, page: 2 }, then { value: items, loading: false, page: 2 }
42
+ * ```
43
+ *
44
+ * @param obs - the source observable to wrap
45
+ * @param firstOnly - if true, only takes the first value
46
+ * @param page - the page number to attach (defaults to 0)
47
+ * @returns an observable of page loading states
19
48
  */
20
49
  export declare function pageLoadingStateFromObs<T>(obs: Observable<T>, firstOnly?: boolean, page?: PageNumber): Observable<PageLoadingState<T>>;
21
50
  /**
22
- * Returns the value once the LoadingState has finished loading, even if an error occured.
51
+ * RxJS operator that extracts the array value from a finished {@link ListLoadingState},
52
+ * defaulting to an empty array when no value is present.
53
+ *
54
+ * Combines {@link valueFromFinishedLoadingState} with a default of `[]`.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * of(successResult([1, 2, 3])).pipe(
59
+ * arrayValueFromFinishedLoadingState()
60
+ * ).subscribe((items) => console.log(items)); // [1, 2, 3]
23
61
  *
24
- * The value is defaulted to an empty array.
62
+ * of(successResult(null)).pipe(
63
+ * arrayValueFromFinishedLoadingState()
64
+ * ).subscribe((items) => console.log(items)); // []
65
+ * ```
25
66
  *
26
- * @returns Observable of the value
67
+ * @returns an operator that emits the array value or an empty array
27
68
  */
28
69
  export declare function arrayValueFromFinishedLoadingState<L extends ListLoadingState>(): OperatorFunction<L, LoadingStateValue<L>>;