@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
@@ -19,9 +19,10 @@ export type IsEqualFunction<T = unknown> = IsCheckFunction<T>;
19
19
  */
20
20
  export type IsModifiedFunction<T = unknown> = IsCheckFunction<T>;
21
21
  /**
22
- * Creates an IsModifiedFunction from an IsEqualFunction, or from IsModifiedFunctionInput.
22
+ * Creates an {@link IsModifiedFunction} by inverting the result of an {@link IsEqualFunction}.
23
23
  *
24
- * @param isEqualFunction
24
+ * @param isEqualFunction - equality check function to invert
25
+ * @returns a function that returns true when the value has been modified
25
26
  */
26
27
  export declare function makeIsModifiedFunction<T>(isEqualFunction: IsEqualFunction<T>): IsModifiedFunction<T>;
27
28
  /**
@@ -44,18 +45,49 @@ export interface MakeIsModifiedFunctionObservableConfig<T = unknown> {
44
45
  readonly defaultFunction?: Maybe<IsModifiedFunction<T>>;
45
46
  }
46
47
  /**
47
- * Creates an Observable<IsModifiedFunction> from the input config.
48
+ * Creates an observable that emits an {@link IsModifiedFunction} derived from the config.
48
49
  *
49
- * @param config MakeIsModifiedFunctionObservableConfig.
50
- * @returns Observable<IsModifiedFunction<T>>
50
+ * Prefers `isModified` over `isEqual` (which is inverted), falling back to `defaultFunction`
51
+ * or a function that always returns true.
52
+ *
53
+ * @param config - configuration with isModified, isEqual, and/or defaultFunction
54
+ * @returns an observable of the resolved IsModifiedFunction
51
55
  */
52
56
  export declare function makeIsModifiedFunctionObservable<T>(config: MakeIsModifiedFunctionObservableConfig<T>): Observable<IsModifiedFunction<T>>;
57
+ /**
58
+ * Creates a function that returns the value if the check function returns true, otherwise undefined.
59
+ *
60
+ * @param isCheckFunction - optional check function
61
+ * @param defaultValueOnMaybe - default result for null/undefined values
62
+ */
53
63
  export declare function makeReturnIfIsFunction<T>(isCheckFunction: Maybe<IsModifiedFunction<T>>, defaultValueOnMaybe?: boolean): (value: Maybe<T>) => Observable<Maybe<T>>;
64
+ /**
65
+ * Returns the value wrapped in an observable if the check function passes, otherwise emits undefined.
66
+ *
67
+ * @param isCheckFunction - optional check function
68
+ * @param value - the value to check
69
+ * @param defaultValueOnMaybe - default result for null/undefined values
70
+ */
54
71
  export declare function returnIfIs<T>(isCheckFunction: Maybe<IsModifiedFunction<T>>, value: Maybe<T>, defaultValueOnMaybe?: boolean): Observable<Maybe<T>>;
72
+ /**
73
+ * Creates a function that checks a value against the check function and returns an observable boolean.
74
+ *
75
+ * @param isCheckFunction - optional check function
76
+ * @param defaultValueOnMaybe - default result for null/undefined values
77
+ */
55
78
  export declare function makeCheckIsFunction<T>(isCheckFunction: Maybe<IsModifiedFunction<T>>, defaultValueOnMaybe?: boolean): (value: Maybe<T>) => Observable<boolean>;
79
+ /**
80
+ * Evaluates a value against an optional check function, returning an observable boolean.
81
+ *
82
+ * Returns `of(true)` when no check function is provided.
83
+ *
84
+ * @param isCheckFunction - optional check function
85
+ * @param value - the value to check
86
+ * @param defaultValueOnMaybe - default result for null/undefined values (defaults to false)
87
+ */
56
88
  export declare function checkIs<T>(isCheckFunction: Maybe<IsModifiedFunction<T>>, value: Maybe<T>, defaultValueOnMaybe?: boolean): Observable<boolean>;
57
89
  /**
58
- * Observable filter that filters maybe value that are defined.
90
+ * RxJS operator that filters out null and undefined values, only passing through defined values.
59
91
  */
60
92
  export declare function filterMaybe<T>(): OperatorFunction<Maybe<T>, T>;
61
93
  /**
@@ -63,26 +95,28 @@ export declare function filterMaybe<T>(): OperatorFunction<Maybe<T>, T>;
63
95
  */
64
96
  export declare const filterMaybeStrict: <T>() => OperatorFunction<Maybe<T>, MaybeSoStrict<T>>;
65
97
  /**
66
- * Observable filter that filters out MaybeNot values from the input array of maybe values
98
+ * RxJS operator that filters out null/undefined elements from an emitted array, keeping only defined values.
67
99
  */
68
100
  export declare function filterMaybeArray<T>(): OperatorFunction<Maybe<T>[], T[]>;
69
101
  /**
70
- * Skips all initial maybe values, and then returns all values after the first non-null/undefined value is returned.
102
+ * RxJS operator that skips all leading null/undefined emissions, then passes all subsequent values through.
71
103
  */
72
104
  export declare function skipAllInitialMaybe<T>(): MonoTypeOperatorFunction<T>;
73
105
  /**
74
- * Skips only the first maybe value, then returns all values afterwards.
106
+ * RxJS operator that skips only the first emission if it is null/undefined, then passes all subsequent values.
75
107
  */
76
108
  export declare function skipInitialMaybe<T>(): MonoTypeOperatorFunction<T>;
77
109
  /**
78
- * Skips up to the given number of maybe values, and then returns all values after the first non-null/undefined value is returned.
110
+ * RxJS operator that skips up to `maxToSkip` null/undefined emissions, then passes all subsequent values.
111
+ *
112
+ * @param maxToSkip - maximum number of null/undefined emissions to skip
79
113
  */
80
114
  export declare function skipMaybes<T>(maxToSkip: number): MonoTypeOperatorFunction<T>;
81
115
  /**
82
- * Provides a switchMap that will emit the observable if the observable is defined, otherwise will return the default value.
116
+ * RxJS operator that switches to the emitted observable if defined, or emits the default value if null/undefined.
83
117
  *
84
- * @param defaultValue
85
- * @returns
118
+ * @param defaultValue - fallback value when the observable is nullish (defaults to undefined)
119
+ * @returns an operator that handles optional observables
86
120
  */
87
121
  export declare function switchMapMaybeDefault<T = unknown>(defaultValue?: Maybe<T>): OperatorFunction<Maybe<Observable<Maybe<T>>>, Maybe<T>>;
88
122
  /**
@@ -90,10 +124,12 @@ export declare function switchMapMaybeDefault<T = unknown>(defaultValue?: Maybe<
90
124
  */
91
125
  export type SwitchMapToDefaultFilterFunction<T> = ObservableDecisionFunction<Maybe<T>>;
92
126
  /**
93
- * Provides a switchMap that will emit the observable value if the observable is defined, otherwise will use the input default.
127
+ * RxJS operator that emits the source value if defined, or switches to the default observable/getter when
128
+ * the value is nullish (or when the custom `useDefault` decision function returns true).
94
129
  *
95
- * @param defaultValue
96
- * @returns
130
+ * @param defaultObs - default value/observable/getter to use as fallback
131
+ * @param useDefault - optional decision function to determine when to use the default
132
+ * @returns an operator that provides a default for nullish values
97
133
  */
98
134
  export declare function switchMapToDefault<T = unknown>(defaultObs: MaybeObservableOrValueGetter<T>): OperatorFunction<Maybe<T>, Maybe<T>>;
99
135
  export declare function switchMapToDefault<T = unknown>(defaultObs: ObservableOrValueGetter<T>): OperatorFunction<Maybe<T>, T>;
@@ -102,61 +138,59 @@ export interface SwitchMapObjectConfig<T> {
102
138
  defaultGetter?: GetterOrValue<Maybe<T>>;
103
139
  }
104
140
  /**
105
- * Provides a switchMap that retrieves and emits the value from the observable, unless the value is null/undefined/true in which case it emits the default value. If the value is false, null is emitted.
141
+ * RxJS operator that resolves an observable/getter config input into a value, applying defaults
142
+ * for `null`/`undefined`/`true` inputs and emitting `null` for `false`.
106
143
  */
107
144
  export declare function switchMapObject<T extends object>(config: SwitchMapObjectConfig<T>): OperatorFunction<Maybe<ObservableOrValueGetter<Maybe<T | boolean>>>, Maybe<T>>;
108
145
  /**
109
- * Provides a switchMap that will emit from the input observable if the value is true, otherwise emits the otherwise value or empty.
110
- *
111
- * @param defaultValue
112
- * @returns
146
+ * RxJS operator that emits from the given observable/getter when the source boolean is `true`,
147
+ * otherwise emits from the `otherwise` source or `EMPTY`.
113
148
  */
114
149
  export declare function switchMapWhileTrue<T = unknown>(obs: ObservableOrValueGetter<T>): OperatorFunction<boolean, T>;
115
150
  export declare function switchMapWhileTrue<T = unknown>(obs: MaybeObservableOrValueGetter<T>): OperatorFunction<boolean, T>;
116
151
  export declare function switchMapWhileTrue<T = unknown>(obs: ObservableOrValueGetter<T>, otherwise: ObservableOrValueGetter<T>): OperatorFunction<boolean, T>;
117
152
  export declare function switchMapWhileTrue<T = unknown>(obs: MaybeObservableOrValueGetter<T>, otherwise?: MaybeObservableOrValueGetter<T>): OperatorFunction<boolean, Maybe<T>>;
118
153
  /**
119
- * Provides a switchMap that will emit from the input observable if the value is false, otherwise emits the otherwise value or empty.
120
- *
121
- * @param defaultValue
122
- * @returns
154
+ * RxJS operator that emits from the given observable/getter when the source boolean is `false`,
155
+ * otherwise emits from the `otherwise` source or `EMPTY`.
123
156
  */
124
157
  export declare function switchMapWhileFalse<T = unknown>(obs: ObservableOrValueGetter<T>): OperatorFunction<boolean, T>;
125
158
  export declare function switchMapWhileFalse<T = unknown>(obs: MaybeObservableOrValueGetter<T>): OperatorFunction<boolean, T>;
126
159
  export declare function switchMapWhileFalse<T = unknown>(obs: ObservableOrValueGetter<T>, otherwise: ObservableOrValueGetter<T>): OperatorFunction<boolean, T>;
127
160
  export declare function switchMapWhileFalse<T = unknown>(obs: MaybeObservableOrValueGetter<T>, otherwise?: MaybeObservableOrValueGetter<T>): OperatorFunction<boolean, Maybe<T>>;
128
161
  /**
129
- * Provides a switchMap that will emit from the input observable if the value matches the switchOnValue, otherwise emits the otherwise value or empty.
162
+ * RxJS operator that emits from `obs` when the source boolean matches `switchOnValue`,
163
+ * otherwise emits from `otherwise` or `EMPTY`.
130
164
  *
131
- * @param defaultValue
132
- * @returns
165
+ * @param switchOnValue - the boolean value that triggers emitting from `obs`
166
+ * @param obs - observable/getter to emit from when matched
167
+ * @param otherwise - optional observable/getter for the non-matching case
133
168
  */
134
169
  export declare function switchMapOnBoolean<T = unknown>(switchOnValue: boolean, obs: MaybeObservableOrValueGetter<T>): OperatorFunction<boolean, T>;
135
170
  export declare function switchMapOnBoolean<T = unknown>(switchOnValue: boolean, obs: MaybeObservableOrValueGetter<T>, otherwise?: MaybeObservableOrValueGetter<T>): OperatorFunction<boolean, Maybe<T>>;
136
171
  /**
137
- * Combines both filterMaybe and switchMap to build a subscriber that emits values only from a concrete Observable, filtering out null/undefined Observables.
172
+ * RxJS operator that filters out null/undefined observables and then switches to the remaining ones.
138
173
  *
139
- * @returns
174
+ * Combines {@link filterMaybe} and `switchMap` to only subscribe to non-nullish observables.
140
175
  */
141
176
  export declare function switchMapFilterMaybe<T = unknown>(): OperatorFunction<Maybe<Observable<Maybe<T>>>, T>;
142
177
  /**
143
- * Converts a Maybe<Observable<Maybe<T>>> to an Observable<Maybe<T>> that emits null/undefined if the input observable is also null/undefined.
144
- *
145
- * @returns
178
+ * RxJS operator that switches to the emitted observable if defined, or emits `undefined` when the observable is nullish.
146
179
  */
147
180
  export declare function switchMapMaybe<T = unknown>(): OperatorFunction<Maybe<Observable<Maybe<T>>>, Maybe<T>>;
148
181
  /**
149
- * Performs the input map function on the input if it is not null/undefined.
182
+ * RxJS operator that applies a map function only when the emitted value is non-null/non-undefined.
150
183
  *
151
- * @param mapFn
152
- * @returns
184
+ * @param mapFn - function to transform defined values
185
+ * @returns an operator that maps defined values and passes through undefined
153
186
  */
154
187
  export declare function mapMaybe<A, B>(mapFn: MapFunction<A, Maybe<B>>): OperatorFunction<Maybe<A>, Maybe<B>>;
155
188
  /**
156
- * Performs the input map function on the input if the decision returns true.
189
+ * RxJS operator that applies a map function only when the decision function returns true.
157
190
  *
158
- * @param mapFn
159
- * @returns
191
+ * @param mapFn - function to transform the value
192
+ * @param decision - predicate that determines whether to apply the map
193
+ * @returns an operator that conditionally maps values
160
194
  */
161
195
  export declare function mapIf<A, B>(mapFn: MapFunction<Maybe<A>, Maybe<B>>, decision: DecisionFunction<Maybe<A>>): OperatorFunction<Maybe<A>, Maybe<B>>;
162
196
  /**
@@ -1,29 +1,106 @@
1
1
  import { type Unsubscribable } from 'rxjs';
2
2
  import { type ArrayOrValue, type Destroyable, type Maybe } from '@dereekb/util';
3
3
  /**
4
- * Destroyable object that wraps an Unsubscribable.
4
+ * Manages a single RxJS subscription with automatic cleanup on reassignment.
5
+ *
6
+ * When a new subscription is assigned, the previous one is automatically unsubscribed.
7
+ * Implements {@link Destroyable} for integration with lifecycle management patterns.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * const sub = new SubscriptionObject();
12
+ *
13
+ * // Assign a subscription — previous one is automatically unsubscribed
14
+ * sub.subscription = interval(1000).subscribe(console.log);
15
+ * sub.subscription = interval(500).subscribe(console.log); // first subscription is cleaned up
16
+ *
17
+ * // Clean up when done
18
+ * sub.destroy();
19
+ * ```
5
20
  */
6
21
  export declare class SubscriptionObject<T extends Unsubscribable = Unsubscribable> implements Destroyable {
7
22
  private _subscription?;
23
+ /**
24
+ * @param sub - optional initial subscription to manage
25
+ */
8
26
  constructor(sub?: Maybe<T>);
27
+ /**
28
+ * Whether a subscription is currently being managed.
29
+ */
9
30
  get hasSubscription(): boolean;
31
+ /**
32
+ * Sets the managed subscription, unsubscribing from any previous one.
33
+ */
10
34
  set subscription(sub: Maybe<T | void>);
35
+ /**
36
+ * Replaces the current subscription with the given one, unsubscribing from the previous.
37
+ *
38
+ * @param sub - new subscription to manage, or `undefined`/`void` to just unsubscribe
39
+ */
11
40
  setSub(sub: Maybe<T | void>): void;
41
+ /**
42
+ * Unsubscribes from the current subscription, if any.
43
+ */
12
44
  unsub(): void;
45
+ /**
46
+ * Unsubscribes from the current subscription and releases the reference.
47
+ */
13
48
  destroy(): void;
14
49
  }
15
50
  /**
16
- * Destroyable object that wraps an array of subscriptions.
51
+ * Manages multiple RxJS subscriptions as a group, with bulk unsubscribe and cleanup.
52
+ *
53
+ * Useful when multiple independent subscriptions share a lifecycle. For subscriptions that
54
+ * should be merged into a single stream, consider using RxJS `merge(...)` instead.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * const subs = new MultiSubscriptionObject();
59
+ *
60
+ * subs.subscriptions = [
61
+ * source1$.subscribe(console.log),
62
+ * source2$.subscribe(console.log)
63
+ * ];
64
+ *
65
+ * // Add more subscriptions later
66
+ * subs.addSubs(source3$.subscribe(console.log));
17
67
  *
18
- * NOTE: In some cases it might be better to use RXJS's merge(...[]) and subscribe to a single item.
68
+ * // Clean up all at once
69
+ * subs.destroy();
70
+ * ```
19
71
  */
20
72
  export declare class MultiSubscriptionObject<T extends Unsubscribable = Unsubscribable> implements Destroyable {
21
73
  private _subscriptions?;
74
+ /**
75
+ * @param subs - optional initial subscription(s) to manage
76
+ */
22
77
  constructor(subs?: ArrayOrValue<T>);
78
+ /**
79
+ * Whether any subscriptions are currently being managed.
80
+ */
23
81
  get hasSubscription(): boolean;
82
+ /**
83
+ * Replaces all managed subscriptions, unsubscribing from previous ones.
84
+ */
24
85
  set subscriptions(subs: ArrayOrValue<T>);
86
+ /**
87
+ * Replaces all managed subscriptions with the given ones, unsubscribing from all previous.
88
+ *
89
+ * @param subs - new subscription(s) to manage
90
+ */
25
91
  setSubs(subs: ArrayOrValue<T>): void;
92
+ /**
93
+ * Adds subscription(s) to the managed set without affecting existing ones. Duplicate subscriptions are ignored.
94
+ *
95
+ * @param subs - subscription(s) to add
96
+ */
26
97
  addSubs(subs: ArrayOrValue<T>): void;
98
+ /**
99
+ * Unsubscribes from all managed subscriptions and clears the list.
100
+ */
27
101
  unsub(): void;
102
+ /**
103
+ * Unsubscribes from all managed subscriptions and releases references.
104
+ */
28
105
  destroy(): void;
29
106
  }
@@ -2,36 +2,69 @@ import { type Observable } from 'rxjs';
2
2
  import { type FactoryWithRequiredInput, type Maybe } from '@dereekb/util';
3
3
  import { WorkInstance, type WorkInstanceDelegate } from './work.instance';
4
4
  /**
5
- * A function that handles the incoming value to do work and creates a WorkContext.
5
+ * A function that accepts an input value, performs asynchronous work, and returns a {@link WorkInstance}
6
+ * to track progress and results.
6
7
  */
7
8
  export type WorkFactory<T, O> = FactoryWithRequiredInput<Maybe<WorkInstance<T, O>>, T>;
8
9
  /**
9
- * Performs the work.
10
- *
11
- * Can either return an observable that will use the handler, or can use the handler itself.
10
+ * Union type for work that can either return an observable result directly or interact with
11
+ * the {@link WorkInstance} handler to manage the work lifecycle manually.
12
12
  */
13
13
  export type Work<T = unknown, O = unknown> = WorkUsingObservable<T, O> | WorkUsingContext<T, O>;
14
14
  /**
15
- * Performs the work using the value and returns an observable.
15
+ * Work implementation that returns an observable of the result, allowing the framework
16
+ * to manage subscription and lifecycle.
16
17
  */
17
18
  export type WorkUsingObservable<T = unknown, O = unknown> = (value: T) => Observable<O>;
18
19
  /**
19
- * Performs the work that uses the context handler to handle the event.
20
+ * Work implementation that manages its own lifecycle by calling methods on the
21
+ * {@link WorkInstance} handler directly (e.g. `startWorking()`, `success()`, `reject()`).
20
22
  */
21
23
  export type WorkUsingContext<T = unknown, O = unknown> = (value: T, instance: WorkInstance<T, O>) => void;
22
24
  /**
23
- * Config for workFactory().
25
+ * Configuration for {@link workFactory}.
24
26
  */
25
27
  export interface WorkFactoryConfig<T, O> {
28
+ /**
29
+ * The work function to execute.
30
+ */
26
31
  readonly work: Work<T, O>;
32
+ /**
33
+ * Delegate that receives lifecycle callbacks (start, success, reject).
34
+ */
27
35
  readonly delegate: WorkInstanceDelegate<O>;
28
36
  }
29
37
  /**
30
- * Creates a function that handles the incoming value and creates a WorkContext.
38
+ * Creates a {@link WorkFactory} that executes the configured work function with a {@link WorkInstance} handler.
39
+ *
40
+ * If the work function returns an observable, it is automatically subscribed to. If it uses
41
+ * the handler directly, the observable return is ignored.
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * const factory = workFactory({
46
+ * work: (value: number) => of(`result: ${value}`),
47
+ * delegate: { startWorking: () => {}, success: () => {}, reject: () => {} }
48
+ * });
49
+ *
50
+ * const instance = factory(42);
51
+ * // instance tracks the work lifecycle
52
+ * ```
53
+ *
54
+ * @param config - work function and delegate configuration
55
+ * @returns a factory function that creates WorkInstance for each input
31
56
  */
32
57
  export declare function workFactory<T, O>({ work, delegate }: WorkFactoryConfig<T, O>): WorkFactory<T, O>;
58
+ /**
59
+ * A factory that produces a fresh {@link WorkFactoryConfig} for each input value, allowing
60
+ * per-invocation customization of work and delegate.
61
+ */
33
62
  export type WorkFactoryConfigFactory<T, O> = FactoryWithRequiredInput<WorkFactoryConfig<T, O>, T>;
34
63
  /**
35
- * Creates a WorkFactory using the input WorkFactoryConfigFactory that generates new work configuration given the input.
64
+ * Creates a {@link WorkFactory} that generates a new {@link WorkFactoryConfig} for each input,
65
+ * enabling dynamic work and delegate selection per invocation.
66
+ *
67
+ * @param configFactory - factory that produces work configuration from the input value
68
+ * @returns a work factory with per-invocation configuration
36
69
  */
37
70
  export declare function workFactoryForConfigFactory<T, O>(configFactory: WorkFactoryConfigFactory<T, O>): WorkFactory<T, O>;
@@ -2,15 +2,39 @@ import { type Maybe, type Destroyable, type ErrorInput } from '@dereekb/util';
2
2
  import { type Observable } from 'rxjs';
3
3
  import { type LoadingState } from '../loading';
4
4
  /**
5
- * Delegate for WorkInstance
5
+ * Delegate that receives lifecycle callbacks from a {@link WorkInstance} as work progresses
6
+ * through its start, success, and rejection phases.
6
7
  */
7
8
  export interface WorkInstanceDelegate<O = unknown> {
9
+ /**
10
+ * Called when work begins.
11
+ */
8
12
  startWorking(): void;
13
+ /**
14
+ * Called when work completes successfully.
15
+ */
9
16
  success(result?: Maybe<O>): void;
17
+ /**
18
+ * Called when work fails.
19
+ */
10
20
  reject(error?: Maybe<unknown>): void;
11
21
  }
12
22
  /**
13
- * Instance that tracks doing an arbitrary piece of asynchronous work that has an input value and an output value.
23
+ * Tracks the lifecycle of an asynchronous work unit from start through completion (success or error).
24
+ *
25
+ * Exposes reactive streams for monitoring progress (`hasStarted$`, `isComplete$`, `loadingState$`)
26
+ * and provides methods for starting work via observables, promises, or direct state management.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * const instance = new WorkInstance(inputValue, {
31
+ * startWorking: () => console.log('started'),
32
+ * success: (result) => console.log('done:', result),
33
+ * reject: (err) => console.error('failed:', err)
34
+ * });
35
+ *
36
+ * instance.startWorkingWithObservable(of('result'));
37
+ * ```
14
38
  */
15
39
  export declare class WorkInstance<I = unknown, O = unknown> implements Destroyable {
16
40
  private readonly _value;