@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.
- package/index.cjs.js +1284 -336
- package/index.cjs.js.map +1 -1
- package/index.esm.js +1284 -336
- package/index.esm.js.map +1 -1
- package/package.json +2 -2
- package/src/lib/filter/filter.d.ts +28 -13
- package/src/lib/filter/filter.map.d.ts +69 -2
- package/src/lib/filter/filter.preset.d.ts +35 -0
- package/src/lib/filter/filter.source.d.ts +61 -2
- package/src/lib/iterator/iteration.accumulator.d.ts +39 -13
- package/src/lib/iterator/iteration.accumulator.rxjs.d.ts +25 -8
- package/src/lib/iterator/iteration.d.ts +16 -5
- package/src/lib/iterator/iteration.mapped.d.ts +19 -6
- package/src/lib/iterator/iteration.mapped.page.d.ts +9 -6
- package/src/lib/iterator/iteration.next.d.ts +17 -14
- package/src/lib/iterator/iterator.page.d.ts +54 -16
- package/src/lib/loading/loading.context.rxjs.d.ts +17 -1
- package/src/lib/loading/loading.context.simple.d.ts +38 -1
- package/src/lib/loading/loading.context.state.d.ts +32 -4
- package/src/lib/loading/loading.context.state.list.d.ts +25 -3
- package/src/lib/loading/loading.context.value.d.ts +43 -3
- package/src/lib/loading/loading.state.d.ts +272 -41
- package/src/lib/loading/loading.state.list.d.ts +50 -9
- package/src/lib/lock.d.ts +149 -6
- package/src/lib/object.d.ts +28 -4
- package/src/lib/rxjs/array.d.ts +39 -13
- package/src/lib/rxjs/boolean.d.ts +8 -4
- package/src/lib/rxjs/decision.d.ts +13 -7
- package/src/lib/rxjs/delta.d.ts +14 -2
- package/src/lib/rxjs/expires.d.ts +20 -8
- package/src/lib/rxjs/factory.d.ts +16 -3
- package/src/lib/rxjs/getter.d.ts +24 -10
- package/src/lib/rxjs/key.d.ts +7 -5
- package/src/lib/rxjs/lifecycle.d.ts +10 -7
- package/src/lib/rxjs/loading.d.ts +10 -2
- package/src/lib/rxjs/map.d.ts +6 -5
- package/src/lib/rxjs/misc.d.ts +26 -6
- package/src/lib/rxjs/model.d.ts +2 -2
- package/src/lib/rxjs/number.d.ts +8 -4
- package/src/lib/rxjs/rxjs.async.d.ts +20 -7
- package/src/lib/rxjs/rxjs.d.ts +26 -18
- package/src/lib/rxjs/rxjs.error.d.ts +17 -0
- package/src/lib/rxjs/rxjs.map.d.ts +37 -9
- package/src/lib/rxjs/rxjs.unique.d.ts +6 -3
- package/src/lib/rxjs/set.d.ts +34 -0
- package/src/lib/rxjs/string.d.ts +18 -1
- package/src/lib/rxjs/timeout.d.ts +21 -1
- package/src/lib/rxjs/use.d.ts +4 -2
- package/src/lib/rxjs/value.d.ts +73 -39
- package/src/lib/subscription.d.ts +80 -3
- package/src/lib/work/work.factory.d.ts +42 -9
- package/src/lib/work/work.instance.d.ts +26 -2
package/src/lib/lock.d.ts
CHANGED
|
@@ -1,19 +1,40 @@
|
|
|
1
1
|
import { type ObservableOrValue } from './rxjs/getter';
|
|
2
2
|
import { type Subscription, type Observable } from 'rxjs';
|
|
3
3
|
import { type Destroyable, type Maybe } from '@dereekb/util';
|
|
4
|
+
/**
|
|
5
|
+
* Key used to identify a specific lock within a {@link LockSet}.
|
|
6
|
+
*/
|
|
4
7
|
export type LockKey = string;
|
|
5
8
|
/**
|
|
6
|
-
*
|
|
9
|
+
* Callback invoked when a {@link LockSet} becomes unlocked or the wait times out.
|
|
10
|
+
*
|
|
11
|
+
* @param unlocked - `true` if the lock set unlocked normally, `false` if the timeout was reached
|
|
7
12
|
*/
|
|
8
13
|
export type OnLockSetUnlockedFunction = (unlocked: boolean) => void;
|
|
14
|
+
/**
|
|
15
|
+
* Function returned by {@link LockSet.addLock} that removes the associated lock when called.
|
|
16
|
+
*/
|
|
9
17
|
export type RemoveLockFunction = () => void;
|
|
18
|
+
/**
|
|
19
|
+
* Configuration for {@link onLockSetNextUnlock} that specifies how to wait for a {@link LockSet} to unlock.
|
|
20
|
+
*/
|
|
10
21
|
export interface OnLockSetUnlockedConfig {
|
|
22
|
+
/** The lock set to monitor for the next unlock event. */
|
|
11
23
|
readonly lockSet: LockSet;
|
|
24
|
+
/** Optional callback to invoke when the lock set unlocks or the timeout is reached. */
|
|
12
25
|
readonly fn?: Maybe<OnLockSetUnlockedFunction>;
|
|
26
|
+
/** Maximum time in milliseconds to wait for unlock before timing out. Defaults to 50 seconds. */
|
|
13
27
|
readonly timeout?: Maybe<number>;
|
|
28
|
+
/** Optional delay in milliseconds after the unlock is detected before invoking the callback. */
|
|
14
29
|
readonly delayTime?: Maybe<number>;
|
|
15
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Configuration for {@link LockSet.destroyOnNextUnlock}, excluding the lock set reference.
|
|
33
|
+
*/
|
|
16
34
|
export type DestroyOnNextUnlockConfig = Omit<OnLockSetUnlockedConfig, 'lockSet'>;
|
|
35
|
+
/**
|
|
36
|
+
* Configuration for {@link LockSet.setLocked} that controls the locked state and optional auto-unlock duration.
|
|
37
|
+
*/
|
|
17
38
|
export interface SetLockedConfig {
|
|
18
39
|
/**
|
|
19
40
|
* Whether or not to lock the config.
|
|
@@ -26,15 +47,55 @@ export interface SetLockedConfig {
|
|
|
26
47
|
*/
|
|
27
48
|
readonly duration?: number;
|
|
28
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Default lock key used by {@link LockSet.lockForTime} when no custom key is provided.
|
|
52
|
+
*/
|
|
29
53
|
export declare const DEFAULT_LOCK_SET_TIME_LOCK_KEY = "timelock";
|
|
30
54
|
/**
|
|
31
|
-
*
|
|
55
|
+
* Subscribes to the next unlock event of a {@link LockSet}, invoking the callback when it becomes unlocked or the timeout expires.
|
|
56
|
+
*
|
|
57
|
+
* Useful for deferring an action until all locks are released, with a safety timeout to avoid waiting indefinitely.
|
|
58
|
+
*
|
|
59
|
+
* @param config - configuration specifying the lock set, callback, timeout, and optional delay
|
|
60
|
+
* @returns subscription that can be unsubscribed to cancel the wait
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* const lockSet = new LockSet();
|
|
65
|
+
* lockSet.addLock('busy', of(true));
|
|
66
|
+
*
|
|
67
|
+
* const sub = onLockSetNextUnlock({
|
|
68
|
+
* lockSet,
|
|
69
|
+
* fn: (unlocked) => console.log('Unlocked:', unlocked),
|
|
70
|
+
* timeout: 5000
|
|
71
|
+
* });
|
|
72
|
+
* ```
|
|
32
73
|
*/
|
|
33
74
|
export declare function onLockSetNextUnlock({ lockSet, fn, timeout: inputTimeout, delayTime }: OnLockSetUnlockedConfig): Subscription;
|
|
34
75
|
/**
|
|
35
|
-
*
|
|
76
|
+
* Observable-based locking mechanism that prevents actions until all registered locks are released.
|
|
77
|
+
*
|
|
78
|
+
* Each lock is identified by a {@link LockKey} and backed by an `Observable<boolean>`. The lock set
|
|
79
|
+
* is considered locked when any registered observable emits `true`. Empty or completed observables
|
|
80
|
+
* are treated as unlocked, so locks do not need to be explicitly removed.
|
|
81
|
+
*
|
|
82
|
+
* Supports hierarchical locking via parent/child relationships between lock sets.
|
|
36
83
|
*
|
|
37
|
-
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* const lockSet = new LockSet();
|
|
87
|
+
*
|
|
88
|
+
* // Add a lock that is currently active
|
|
89
|
+
* const removeLock = lockSet.addLock('saving', of(true));
|
|
90
|
+
*
|
|
91
|
+
* // Check locked state
|
|
92
|
+
* lockSet.isLocked$.subscribe(locked => console.log('Locked:', locked));
|
|
93
|
+
* // Output: Locked: true
|
|
94
|
+
*
|
|
95
|
+
* // Remove the lock
|
|
96
|
+
* removeLock();
|
|
97
|
+
* // Output: Locked: false
|
|
98
|
+
* ```
|
|
38
99
|
*/
|
|
39
100
|
export declare class LockSet implements Destroyable {
|
|
40
101
|
private static LOCK_SET_CHILD_INDEX_STEPPER;
|
|
@@ -42,28 +103,110 @@ export declare class LockSet implements Destroyable {
|
|
|
42
103
|
private readonly _onDestroy;
|
|
43
104
|
private readonly _locks;
|
|
44
105
|
private readonly _parentSub;
|
|
106
|
+
/**
|
|
107
|
+
* Observable of the current lock map, emitting whenever locks are added or removed.
|
|
108
|
+
*/
|
|
45
109
|
readonly locks$: Observable<Map<string, Observable<boolean>>>;
|
|
46
110
|
/**
|
|
47
|
-
*
|
|
111
|
+
* Observable that emits `true` when any registered lock observable is emitting `true`.
|
|
112
|
+
* Emits `false` when all locks are released or the map is empty.
|
|
48
113
|
*/
|
|
49
114
|
readonly isLocked$: Observable<boolean>;
|
|
115
|
+
/**
|
|
116
|
+
* Observable that emits `true` when no locks are active. Inverse of {@link isLocked$}.
|
|
117
|
+
*/
|
|
50
118
|
readonly isUnlocked$: Observable<boolean>;
|
|
119
|
+
/**
|
|
120
|
+
* Observable that emits when this lock set is destroyed. Useful for cleanup coordination.
|
|
121
|
+
*/
|
|
51
122
|
readonly onDestroy$: Observable<void>;
|
|
52
123
|
private get locks();
|
|
124
|
+
/**
|
|
125
|
+
* Sets the locked state for a given key, optionally with an auto-unlock duration.
|
|
126
|
+
*
|
|
127
|
+
* When locked with a duration, the lock automatically releases after the specified time.
|
|
128
|
+
* When unlocked, the lock is removed from the set.
|
|
129
|
+
*
|
|
130
|
+
* @param key - identifier for this lock
|
|
131
|
+
* @param config - locked state or configuration object
|
|
132
|
+
* @param duration - optional auto-unlock duration in milliseconds (only used with boolean config)
|
|
133
|
+
*/
|
|
53
134
|
setLocked(key: LockKey, config: SetLockedConfig): void;
|
|
54
135
|
setLocked(key: LockKey, config: boolean, duration?: number): void;
|
|
136
|
+
/**
|
|
137
|
+
* Locks for a specified number of seconds using the default time lock key.
|
|
138
|
+
*
|
|
139
|
+
* @param seconds - duration in seconds
|
|
140
|
+
*/
|
|
55
141
|
lockForSeconds(seconds: number): void;
|
|
142
|
+
/**
|
|
143
|
+
* Locks for a specified duration in milliseconds, automatically unlocking when the time elapses.
|
|
144
|
+
*
|
|
145
|
+
* @param milliseconds - lock duration
|
|
146
|
+
* @param key - optional lock key, defaults to {@link DEFAULT_LOCK_SET_TIME_LOCK_KEY}
|
|
147
|
+
*/
|
|
56
148
|
lockForTime(milliseconds: number, key?: LockKey): void;
|
|
149
|
+
/**
|
|
150
|
+
* Registers a lock observable under the given key. The lock is considered active when
|
|
151
|
+
* the observable emits `true`. Empty observables are treated as unlocked.
|
|
152
|
+
*
|
|
153
|
+
* @param key - identifier for this lock
|
|
154
|
+
* @param obs - observable that emits the lock state
|
|
155
|
+
* @returns function that removes this specific lock when called
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```ts
|
|
159
|
+
* const lockSet = new LockSet();
|
|
160
|
+
* const remove = lockSet.addLock('saving', of(true));
|
|
161
|
+
*
|
|
162
|
+
* // Later, release the lock
|
|
163
|
+
* remove();
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
57
166
|
addLock(key: LockKey, obs: Observable<boolean>): RemoveLockFunction;
|
|
58
167
|
private _removeObsForKey;
|
|
168
|
+
/**
|
|
169
|
+
* Removes the lock registered under the given key, if it exists.
|
|
170
|
+
*
|
|
171
|
+
* @param key - identifier of the lock to remove
|
|
172
|
+
*/
|
|
59
173
|
removeLock(key: LockKey): void;
|
|
174
|
+
/**
|
|
175
|
+
* Registers a callback for the next time this lock set becomes unlocked.
|
|
176
|
+
*
|
|
177
|
+
* @param config - callback function or configuration object
|
|
178
|
+
* @param delayTime - optional delay in milliseconds after unlock before invoking the callback
|
|
179
|
+
* @returns subscription that can be unsubscribed to cancel the wait
|
|
180
|
+
*/
|
|
60
181
|
onNextUnlock(config: OnLockSetUnlockedFunction | Omit<OnLockSetUnlockedConfig, 'lockSet'>, delayTime?: number): Subscription;
|
|
182
|
+
/**
|
|
183
|
+
* Establishes a parent-child relationship where this lock set's locked state is propagated
|
|
184
|
+
* to the parent. When this lock set is locked, the parent will also reflect a locked state.
|
|
185
|
+
*
|
|
186
|
+
* @param parent - parent lock set or observable of one; pass `undefined` to detach
|
|
187
|
+
*/
|
|
61
188
|
setParentLockSet(parent: ObservableOrValue<Maybe<LockSet>>): void;
|
|
62
189
|
/**
|
|
63
|
-
*
|
|
190
|
+
* Registers a child lock set so its locked state propagates upward to this lock set.
|
|
191
|
+
*
|
|
192
|
+
* @param lockSet - child lock set to monitor
|
|
193
|
+
* @param key - optional lock key, auto-generated if not provided
|
|
194
|
+
* @returns function that removes the child lock relationship when called
|
|
64
195
|
*/
|
|
65
196
|
addChildLockSet(lockSet: LockSet, key?: LockKey): RemoveLockFunction;
|
|
66
197
|
get isDestroyed(): boolean;
|
|
198
|
+
/**
|
|
199
|
+
* Schedules this lock set for destruction when it next becomes unlocked.
|
|
200
|
+
*
|
|
201
|
+
* After the unlock event (or timeout), the optional callback is invoked and then
|
|
202
|
+
* {@link destroy} is called after a short delay.
|
|
203
|
+
*
|
|
204
|
+
* @param config - optional callback or configuration for the unlock wait
|
|
205
|
+
* @param delayTime - optional delay in milliseconds after unlock before invoking the callback
|
|
206
|
+
*/
|
|
67
207
|
destroyOnNextUnlock(config?: Maybe<DestroyOnNextUnlockConfig['fn'] | DestroyOnNextUnlockConfig>, delayTime?: number): void;
|
|
208
|
+
/**
|
|
209
|
+
* Completes all internal subjects, unsubscribes from the parent lock set, and marks this lock set as destroyed.
|
|
210
|
+
*/
|
|
68
211
|
destroy(): void;
|
|
69
212
|
}
|
package/src/lib/object.d.ts
CHANGED
|
@@ -1,14 +1,38 @@
|
|
|
1
1
|
import { type MonoTypeOperatorFunction, type Observable } from 'rxjs';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* RxJS operator that suppresses consecutive emissions when the emitted POJO values are deeply equal.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
5
|
+
* Uses {@link areEqualPOJOValues} for comparison, so the emitted objects should be plain objects
|
|
6
|
+
* or compatible with deep value equality checks.
|
|
7
|
+
*
|
|
8
|
+
* @returns operator that filters out consecutive duplicate POJO emissions
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* of({ a: 1 }, { a: 1 }, { a: 2 }).pipe(
|
|
13
|
+
* distinctUntilObjectValuesChanged()
|
|
14
|
+
* ).subscribe(console.log);
|
|
15
|
+
* // Output: { a: 1 }, { a: 2 }
|
|
16
|
+
* ```
|
|
6
17
|
*/
|
|
7
18
|
export declare function distinctUntilObjectValuesChanged<T>(): MonoTypeOperatorFunction<T>;
|
|
8
19
|
/**
|
|
9
|
-
*
|
|
20
|
+
* RxJS operator that filters out emissions that are deeply equal to a reference value.
|
|
21
|
+
*
|
|
22
|
+
* Accepts either a static reference value or an observable of reference values. When given an observable,
|
|
23
|
+
* each emission is compared against the latest reference value. Uses {@link areEqualPOJOValues} for comparison.
|
|
24
|
+
*
|
|
25
|
+
* @param input - static reference value or observable of reference values to compare against
|
|
26
|
+
* @returns operator that only passes through values that differ from the reference
|
|
10
27
|
*
|
|
11
|
-
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* const ref = { status: 'active' };
|
|
31
|
+
* of({ status: 'active' }, { status: 'inactive' }).pipe(
|
|
32
|
+
* filterIfObjectValuesUnchanged(ref)
|
|
33
|
+
* ).subscribe(console.log);
|
|
34
|
+
* // Output: { status: 'inactive' }
|
|
35
|
+
* ```
|
|
12
36
|
*/
|
|
13
37
|
export declare function filterIfObjectValuesUnchanged<F>(inputFilter: F): MonoTypeOperatorFunction<F>;
|
|
14
38
|
export declare function filterIfObjectValuesUnchanged<F>(obs: Observable<F>): MonoTypeOperatorFunction<F>;
|
package/src/lib/rxjs/array.d.ts
CHANGED
|
@@ -1,14 +1,34 @@
|
|
|
1
1
|
import { type MonoTypeOperatorFunction, type Observable, type OperatorFunction, type ObservableInput } from 'rxjs';
|
|
2
2
|
import { type Maybe, type ArrayOrValue, type MapFunction } from '@dereekb/util';
|
|
3
|
+
/**
|
|
4
|
+
* `distinctUntilChanged` variant that only emits when the array length changes.
|
|
5
|
+
*
|
|
6
|
+
* Optionally accepts an accessor function to extract the array from a complex value.
|
|
7
|
+
*
|
|
8
|
+
* @param getArray - optional function to extract the array from the emitted value
|
|
9
|
+
* @returns an operator that filters emissions with unchanged array lengths
|
|
10
|
+
*/
|
|
3
11
|
export declare function distinctUntilArrayLengthChanges<A>(getArray: (value: A) => unknown[]): MonoTypeOperatorFunction<A>;
|
|
4
12
|
export declare function distinctUntilArrayLengthChanges<T>(): MonoTypeOperatorFunction<T[]>;
|
|
5
13
|
export interface ScanIntoArrayConfig {
|
|
6
14
|
readonly immutable?: boolean;
|
|
7
15
|
}
|
|
8
16
|
/**
|
|
9
|
-
*
|
|
17
|
+
* Accumulates emitted values into a growing array using `scan`.
|
|
18
|
+
*
|
|
19
|
+
* Each emission adds to the accumulated array. When `immutable` is true (default),
|
|
20
|
+
* a new array is created on each emission via `concat`. When false, the array is mutated in place.
|
|
10
21
|
*
|
|
11
|
-
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* of(1, 2, 3).pipe(
|
|
25
|
+
* scanIntoArray()
|
|
26
|
+
* ).subscribe(console.log);
|
|
27
|
+
* // [1], [1, 2], [1, 2, 3]
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @param config - optional immutability setting
|
|
31
|
+
* @returns an operator that accumulates values into an array
|
|
12
32
|
*/
|
|
13
33
|
export declare function scanIntoArray<T>(config?: ScanIntoArrayConfig): OperatorFunction<Maybe<ArrayOrValue<T>>, T[]>;
|
|
14
34
|
export declare function scanIntoArray<T>(config?: ScanIntoArrayConfig): OperatorFunction<Maybe<T>, T[]>;
|
|
@@ -29,22 +49,21 @@ export interface ScanBuildArrayConfig<T> {
|
|
|
29
49
|
}
|
|
30
50
|
export type ScanBuildArrayConfigFn<S, T> = (seedState: S) => ScanBuildArrayConfig<T>;
|
|
31
51
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* The piped observable is for retrieving the seed value, and the accumulatorObs observable is used for
|
|
35
|
-
* retrieving values going forward.
|
|
52
|
+
* Lazily builds an array from a seed observable and an accumulator observable.
|
|
36
53
|
*
|
|
37
|
-
*
|
|
54
|
+
* The piped observable provides the seed state, while `accumulatorObs` provides values that
|
|
55
|
+
* are incrementally appended. Useful when loading large datasets where the initial page and
|
|
56
|
+
* subsequent pages come from different sources.
|
|
38
57
|
*
|
|
39
|
-
* @param
|
|
40
|
-
* @returns
|
|
58
|
+
* @param init - function that receives the seed state and returns the accumulator config
|
|
59
|
+
* @returns an operator that emits the growing array
|
|
41
60
|
*/
|
|
42
61
|
export declare function scanBuildArray<S, T>(init: ScanBuildArrayConfigFn<S, T>): OperatorFunction<S, T[]>;
|
|
43
62
|
/**
|
|
44
|
-
*
|
|
63
|
+
* RxJS operator that executes a side-effect on each element of the emitted array, then passes the array through.
|
|
45
64
|
*
|
|
46
|
-
* @param forEach
|
|
47
|
-
* @returns
|
|
65
|
+
* @param forEach - callback to run for each element, or null/undefined to pass through unchanged
|
|
66
|
+
* @returns an operator that taps each element in emitted arrays
|
|
48
67
|
*/
|
|
49
68
|
export declare function mapForEach<T>(forEach: Maybe<(value: T) => void>): MonoTypeOperatorFunction<T[]>;
|
|
50
69
|
export interface MapEachAsyncConfig {
|
|
@@ -54,6 +73,13 @@ export interface MapEachAsyncConfig {
|
|
|
54
73
|
readonly onlyFirst?: boolean;
|
|
55
74
|
}
|
|
56
75
|
/**
|
|
57
|
-
*
|
|
76
|
+
* RxJS operator that maps each element in an emitted array through an async observable function,
|
|
77
|
+
* then combines all results using `combineLatest`.
|
|
78
|
+
*
|
|
79
|
+
* Emits `[]` for empty arrays. When `onlyFirst` is true, takes only the first combined emission.
|
|
80
|
+
*
|
|
81
|
+
* @param mapFunction - function that maps each item to an ObservableInput
|
|
82
|
+
* @param config - optional config (e.g., `onlyFirst`)
|
|
83
|
+
* @returns an operator that async-maps each array element
|
|
58
84
|
*/
|
|
59
85
|
export declare function mapEachAsync<I, O>(mapFunction: MapFunction<I, ObservableInput<O>>, config?: MapEachAsyncConfig): OperatorFunction<I[], O[]>;
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import { type OperatorFunction, type MonoTypeOperatorFunction } from 'rxjs';
|
|
2
2
|
/**
|
|
3
|
-
* Returns the pipe
|
|
3
|
+
* Conditionally applies an operator. Returns the given pipe when `usePipe` is true, otherwise returns identity (pass-through).
|
|
4
|
+
*
|
|
5
|
+
* @param usePipe - whether to apply the pipe
|
|
6
|
+
* @param pipe - the operator to conditionally apply
|
|
7
|
+
* @returns the pipe or identity operator
|
|
4
8
|
*/
|
|
5
9
|
export declare function pipeIf<A>(usePipe: boolean, pipe: OperatorFunction<A, A>): OperatorFunction<A, A>;
|
|
6
10
|
/**
|
|
7
|
-
*
|
|
11
|
+
* RxJS operator that negates each emitted boolean value.
|
|
8
12
|
*/
|
|
9
13
|
export declare function isNot(): MonoTypeOperatorFunction<boolean>;
|
|
10
14
|
/**
|
|
11
|
-
*
|
|
15
|
+
* RxJS operator that only emits when a boolean stream transitions from `true` to `false`.
|
|
12
16
|
*/
|
|
13
17
|
export declare function onTrueToFalse(): MonoTypeOperatorFunction<boolean>;
|
|
14
18
|
/**
|
|
15
|
-
*
|
|
19
|
+
* RxJS operator that only emits when a boolean stream transitions from `false` to `true`.
|
|
16
20
|
*/
|
|
17
21
|
export declare function onFalseToTrue(): MonoTypeOperatorFunction<boolean>;
|
|
@@ -5,17 +5,23 @@ import { type MonoTypeOperatorFunction, type Observable } from 'rxjs';
|
|
|
5
5
|
*/
|
|
6
6
|
export type ObservableDecisionFunction<T> = (value: T) => Observable<boolean>;
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Wraps an {@link ObservableDecisionFunction} to negate its boolean result.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* @
|
|
10
|
+
* When `invert` is false, returns the original function unchanged.
|
|
11
|
+
*
|
|
12
|
+
* @param decisionFn - the decision function to invert
|
|
13
|
+
* @param invert - whether to apply the inversion (defaults to true)
|
|
14
|
+
* @returns the inverted (or original) decision function
|
|
13
15
|
*/
|
|
14
16
|
export declare function invertObservableDecision<F extends ObservableDecisionFunction<any>>(decisionFn: F, invert?: boolean): F;
|
|
15
17
|
/**
|
|
16
|
-
*
|
|
18
|
+
* RxJS operator that filters an emitted array by evaluating each item through an async {@link ObservableDecisionFunction}.
|
|
19
|
+
*
|
|
20
|
+
* Items where the decision returns true are kept; others are removed. Results are throttled
|
|
21
|
+
* to prevent excessive re-emissions.
|
|
17
22
|
*
|
|
18
|
-
* @param observableDecisionFunction
|
|
19
|
-
* @
|
|
23
|
+
* @param observableDecisionFunction - async predicate to evaluate each item
|
|
24
|
+
* @param throttle - throttle duration in ms (defaults to 20)
|
|
25
|
+
* @returns an operator that async-filters array elements
|
|
20
26
|
*/
|
|
21
27
|
export declare function filterItemsWithObservableDecision<T>(observableDecisionFunction: ObservableDecisionFunction<T>, throttle?: Milliseconds): MonoTypeOperatorFunction<T[]>;
|
package/src/lib/rxjs/delta.d.ts
CHANGED
|
@@ -25,8 +25,20 @@ export interface OnMatchDeltaConfig<T> {
|
|
|
25
25
|
requireConsecutive?: boolean;
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
28
|
+
* RxJS operator that emits only when the stream transitions from a `from` value to a `to` value.
|
|
29
29
|
*
|
|
30
|
-
* The
|
|
30
|
+
* The `from` value must be seen first; only then is the `to` value emitted. When `requireConsecutive`
|
|
31
|
+
* is true, the two values must be adjacent emissions.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* // Emit when transitioning from true to false
|
|
36
|
+
* source$.pipe(
|
|
37
|
+
* onMatchDelta({ from: true, to: false, requireConsecutive: true })
|
|
38
|
+
* ).subscribe((val) => console.log('Transitioned to false'));
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @param config - from/to values, optional comparator, and consecutive requirement
|
|
42
|
+
* @returns an operator that emits on value transitions
|
|
31
43
|
*/
|
|
32
44
|
export declare function onMatchDelta<T>(config: OnMatchDeltaConfig<T>): MonoTypeOperatorFunction<T>;
|
|
@@ -1,29 +1,41 @@
|
|
|
1
1
|
import { type Milliseconds, type DateOrUnixDateTimeMillisecondsNumber, type Expires } from '@dereekb/util';
|
|
2
2
|
import { type MonoTypeOperatorFunction, type Observable, type OperatorFunction } from 'rxjs';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* RxJS operator that maps each emission to a new {@link Expires} object with an expiration
|
|
5
|
+
* time relative to the current moment.
|
|
5
6
|
*
|
|
6
|
-
* @param expiresIn
|
|
7
|
-
* @returns
|
|
7
|
+
* @param expiresIn - duration in milliseconds until expiration
|
|
8
|
+
* @returns an operator that maps values to Expires objects
|
|
8
9
|
*/
|
|
9
10
|
export declare function toExpiration<T>(expiresIn: number): OperatorFunction<T, Expires>;
|
|
10
11
|
/**
|
|
11
|
-
*
|
|
12
|
+
* RxJS operator that filters out emissions whose {@link Expires} value has already expired.
|
|
12
13
|
*/
|
|
13
14
|
export declare function skipExpired<T extends Expires>(): MonoTypeOperatorFunction<T>;
|
|
14
15
|
/**
|
|
15
|
-
*
|
|
16
|
+
* RxJS operator that skips emissions until the elapsed time since the emitted date/timestamp has exceeded `expiresIn`.
|
|
17
|
+
*
|
|
18
|
+
* @param expiresIn - duration in milliseconds
|
|
16
19
|
*/
|
|
17
20
|
export declare function skipUntilExpiration(expiresIn?: number): MonoTypeOperatorFunction<DateOrUnixDateTimeMillisecondsNumber>;
|
|
18
21
|
/**
|
|
19
|
-
*
|
|
22
|
+
* RxJS operator that skips emissions after the elapsed time since the emitted date/timestamp has exceeded `expiresIn`.
|
|
23
|
+
*
|
|
24
|
+
* @param expiresIn - duration in milliseconds
|
|
20
25
|
*/
|
|
21
26
|
export declare function skipAfterExpiration(expiresIn?: number): MonoTypeOperatorFunction<DateOrUnixDateTimeMillisecondsNumber>;
|
|
22
27
|
/**
|
|
23
|
-
*
|
|
28
|
+
* RxJS operator that only takes emissions from the source within a time window after each emission from a watch observable.
|
|
29
|
+
*
|
|
30
|
+
* @param watch - observable whose emissions reset the time window
|
|
31
|
+
* @param takeFor - duration in milliseconds of each time window
|
|
24
32
|
*/
|
|
25
33
|
export declare function skipUntilTimeElapsedAfterLastEmission<T>(watch: Observable<unknown>, takeFor: Milliseconds): MonoTypeOperatorFunction<T>;
|
|
26
34
|
/**
|
|
27
|
-
*
|
|
35
|
+
* RxJS operator that skips emissions from the source for a duration after each emission from a watch observable,
|
|
36
|
+
* then passes values through once the time has elapsed.
|
|
37
|
+
*
|
|
38
|
+
* @param watch - observable whose emissions reset the skip window
|
|
39
|
+
* @param skipFor - duration in milliseconds to skip after each watch emission
|
|
28
40
|
*/
|
|
29
41
|
export declare function takeAfterTimeElapsedSinceLastEmission<T>(watch: Observable<unknown>, skipFor: Milliseconds): MonoTypeOperatorFunction<T>;
|
|
@@ -23,9 +23,22 @@ export interface FactoryTimerConfig<T> {
|
|
|
23
23
|
}
|
|
24
24
|
export declare const DEFAULT_FACTORY_TIMER_INTERVAL = 1000;
|
|
25
25
|
/**
|
|
26
|
-
* Creates an observable that
|
|
26
|
+
* Creates an observable that emits values produced by a factory function on a timer interval.
|
|
27
27
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
28
|
+
* Wraps `timer()` internally and maps each tick index through the factory. Optionally limits
|
|
29
|
+
* the total number of emissions.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* const countdown$ = factoryTimer({
|
|
34
|
+
* factory: (i) => 10 - i,
|
|
35
|
+
* interval: 1000,
|
|
36
|
+
* limit: 11
|
|
37
|
+
* });
|
|
38
|
+
* // emits 10, 9, 8, ... 0
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @param config - timer configuration including factory, interval, wait, and limit
|
|
42
|
+
* @returns an observable of factory-produced values
|
|
30
43
|
*/
|
|
31
44
|
export declare function factoryTimer<T>(config: FactoryTimerConfig<T>): Observable<T>;
|
package/src/lib/rxjs/getter.d.ts
CHANGED
|
@@ -6,20 +6,21 @@ import { type Observable, type OperatorFunction, type Subscription, type Observe
|
|
|
6
6
|
export type ObservableOrValue<T> = T | Observable<T>;
|
|
7
7
|
export type MaybeObservableOrValue<T> = Maybe<ObservableOrValue<Maybe<T>>>;
|
|
8
8
|
/**
|
|
9
|
-
* Wraps
|
|
9
|
+
* Wraps a value as an observable using `of()`, or returns it directly if it is already an observable.
|
|
10
10
|
*/
|
|
11
11
|
export declare function asObservable<T>(valueOrObs: ObservableOrValue<T>): Observable<T>;
|
|
12
12
|
export declare function asObservable<T>(valueOrObs: Maybe<ObservableOrValue<T>>): Observable<Maybe<T>>;
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
* RxJS operator that flattens an emitted {@link ObservableOrValue} into its unwrapped value via `switchMap`.
|
|
15
15
|
*
|
|
16
|
-
* @returns
|
|
16
|
+
* @returns an operator that unwraps ObservableOrValue emissions
|
|
17
17
|
*/
|
|
18
18
|
export declare function valueFromObservableOrValue<T>(): OperatorFunction<ObservableOrValue<T>, T>;
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
20
|
+
* RxJS operator that flattens an emitted Maybe<{@link ObservableOrValue}> into its unwrapped value,
|
|
21
|
+
* emitting `undefined` when the input is nullish.
|
|
21
22
|
*
|
|
22
|
-
* @returns
|
|
23
|
+
* @returns an operator that unwraps Maybe<ObservableOrValue> emissions
|
|
23
24
|
*/
|
|
24
25
|
export declare function maybeValueFromObservableOrValue<T>(): OperatorFunction<MaybeObservableOrValue<T>, Maybe<T>>;
|
|
25
26
|
/**
|
|
@@ -29,22 +30,35 @@ export type ObservableOrValueGetter<T> = GetterOrValue<ObservableOrValue<T>>;
|
|
|
29
30
|
export type ObservableOrValueFactoryWithInput<T extends GetterDistinctValue, A> = GetterOrValueWithInput<ObservableOrValue<T>, A>;
|
|
30
31
|
export type ObservableFactoryWithRequiredInput<T extends GetterDistinctValue, A> = FactoryWithRequiredInput<ObservableOrValue<T>, A>;
|
|
31
32
|
export type MaybeObservableOrValueGetter<T> = Maybe<ObservableOrValueGetter<Maybe<T>>>;
|
|
33
|
+
/**
|
|
34
|
+
* Resolves an {@link ObservableOrValueGetter} into an Observable by first evaluating the getter,
|
|
35
|
+
* then wrapping the result with {@link asObservable} if needed.
|
|
36
|
+
*
|
|
37
|
+
* @param input - a getter or value that produces an observable or value
|
|
38
|
+
* @param args - optional arguments passed to the getter
|
|
39
|
+
* @returns an observable of the resolved value
|
|
40
|
+
*/
|
|
32
41
|
export declare function asObservableFromGetter<T>(input: ObservableOrValueGetter<T>): Observable<T>;
|
|
33
42
|
export declare function asObservableFromGetter<T>(this: unknown, input: ObservableOrValueGetter<T>): Observable<T>;
|
|
34
43
|
export declare function asObservableFromGetter<T extends GetterDistinctValue, A>(this: unknown, input: ObservableFactoryWithRequiredInput<T, A>, args: A): Observable<T>;
|
|
35
44
|
export declare function asObservableFromGetter<T extends GetterDistinctValue, A>(this: unknown, input: ObservableOrValueFactoryWithInput<T, A>, args?: A): Observable<T>;
|
|
36
45
|
/**
|
|
37
|
-
*
|
|
46
|
+
* RxJS operator that flattens an emitted {@link ObservableOrValueGetter} into its resolved value via `switchMap`.
|
|
38
47
|
*
|
|
39
|
-
* @returns
|
|
48
|
+
* @returns an operator that unwraps getter emissions
|
|
40
49
|
*/
|
|
41
50
|
export declare function valueFromObservableOrValueGetter<T>(): OperatorFunction<ObservableOrValueGetter<T>, T>;
|
|
51
|
+
/**
|
|
52
|
+
* RxJS operator that flattens an emitted Maybe<{@link ObservableOrValueGetter}> into its resolved value,
|
|
53
|
+
* emitting `undefined` when the input is nullish.
|
|
54
|
+
*/
|
|
42
55
|
export declare function maybeValueFromObservableOrValueGetter<T>(): OperatorFunction<MaybeObservableOrValueGetter<T>, Maybe<T>>;
|
|
43
56
|
/**
|
|
44
|
-
*
|
|
57
|
+
* Subscribes to an {@link ObservableOrValue} and calls the observer/next function with each emitted value.
|
|
45
58
|
*
|
|
46
|
-
* @param input
|
|
47
|
-
* @param
|
|
59
|
+
* @param input - the observable or value to subscribe to
|
|
60
|
+
* @param observer - callback or partial observer
|
|
61
|
+
* @returns the subscription
|
|
48
62
|
*/
|
|
49
63
|
export declare function useAsObservable<T>(input: ObservableOrValue<T>, next: (value: T) => void): Subscription;
|
|
50
64
|
export declare function useAsObservable<T>(input: ObservableOrValue<T>, observer: Partial<Observer<T>>): Subscription;
|
package/src/lib/rxjs/key.d.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { type PrimativeKey, type ReadKeyFunction, type ReadMultipleKeysFunction } from '@dereekb/util';
|
|
2
2
|
import { type MonoTypeOperatorFunction } from 'rxjs';
|
|
3
3
|
/**
|
|
4
|
-
* distinctUntilChanged
|
|
4
|
+
* `distinctUntilChanged` variant for arrays that only emits when the set of keys extracted from
|
|
5
|
+
* the array elements changes.
|
|
5
6
|
*
|
|
6
|
-
* @param
|
|
7
|
+
* @param readKey - function to extract one or more keys from each element
|
|
8
|
+
* @returns an operator that filters out arrays with unchanged key sets
|
|
7
9
|
*/
|
|
8
10
|
export declare function distinctUntilKeysChange<T, K extends PrimativeKey = PrimativeKey>(readKey: ReadKeyFunction<T, K> | ReadMultipleKeysFunction<T, K>): MonoTypeOperatorFunction<T[]>;
|
|
9
11
|
/**
|
|
10
|
-
*
|
|
12
|
+
* `distinctUntilChanged` variant for single objects that only emits when the extracted key changes.
|
|
11
13
|
*
|
|
12
|
-
* @param readKey
|
|
13
|
-
* @returns
|
|
14
|
+
* @param readKey - function to extract a key from the emitted object
|
|
15
|
+
* @returns an operator that filters out emissions with unchanged keys
|
|
14
16
|
*/
|
|
15
17
|
export declare function distinctUntilObjectKeyChange<T>(readKey: ReadKeyFunction<T>): MonoTypeOperatorFunction<T>;
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import { type Destroyable, type PromiseOrValue } from '@dereekb/util';
|
|
2
2
|
import { type MonoTypeOperatorFunction } from 'rxjs';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* RxJS operator that calls a destroy function on the previous value whenever a new value is emitted.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
6
|
+
* Ensures proper cleanup of resources when switching between instances. When `wait` is true,
|
|
7
|
+
* delays emitting the new value until the previous destruction completes.
|
|
8
|
+
* On unsubscription, the last emitted instance is also destroyed.
|
|
7
9
|
*
|
|
8
|
-
* @param destroy
|
|
9
|
-
* @param wait
|
|
10
|
-
* @returns
|
|
10
|
+
* @param destroy - function to clean up each replaced instance
|
|
11
|
+
* @param wait - whether to wait for the previous destroy to complete before emitting
|
|
12
|
+
* @returns an operator that manages instance lifecycle
|
|
11
13
|
*/
|
|
12
14
|
export declare function cleanup<T>(destroy: (instance: T) => PromiseOrValue<void>, wait?: boolean): MonoTypeOperatorFunction<T>;
|
|
13
15
|
/**
|
|
14
|
-
* Convenience
|
|
16
|
+
* Convenience wrapper for {@link cleanup} that calls `destroy()` on each replaced {@link Destroyable} instance.
|
|
15
17
|
*
|
|
16
|
-
* @
|
|
18
|
+
* @param wait - whether to wait for the previous destroy to complete before emitting
|
|
19
|
+
* @returns an operator that manages Destroyable lifecycle
|
|
17
20
|
*/
|
|
18
21
|
export declare function cleanupDestroyable<T extends Destroyable>(wait?: boolean): MonoTypeOperatorFunction<T>;
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import { type OperatorFunction } from 'rxjs';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* RxJS operator that emits `true` immediately (loading), then `false` after the source emits its first value.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
5
|
+
* Only considers the first emission from the source. The result is shared via `shareReplay(1)`.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* const loading$ = dataFetch$.pipe(isLoading());
|
|
10
|
+
* // emits true initially, then false once dataFetch$ emits
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @returns an operator that tracks whether the first value has been emitted
|
|
6
14
|
*/
|
|
7
15
|
export declare function isLoading<T>(): OperatorFunction<T, boolean>;
|