@dereekb/rxjs 10.1.0 → 10.1.2

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 CHANGED
@@ -3923,6 +3923,42 @@ function multiKeyValueMap(read) {
3923
3923
  return rxjs.map(util.multiKeyValueMapFactory(read));
3924
3924
  }
3925
3925
 
3926
+ function errorOnEmissionsInPeriod(config) {
3927
+ const {
3928
+ period = 1000,
3929
+ maxEmissionsPerPeriod,
3930
+ onError,
3931
+ errorFactory: inputErrorFactory,
3932
+ errorMessage: inputErrorMessage,
3933
+ switchToObs
3934
+ } = config;
3935
+ const errorMessage = inputErrorMessage !== null && inputErrorMessage !== void 0 ? inputErrorMessage : 'errorOnEmissionsInPeriod(): Too many emissions in time period.';
3936
+ const errorFactory = inputErrorFactory ? inputErrorFactory : !switchToObs ? () => new Error(errorMessage) : undefined;
3937
+ return source => {
3938
+ const counter = util.timePeriodCounter(period);
3939
+ if (errorFactory) {
3940
+ return source.pipe(rxjs.map(x => {
3941
+ if (counter() > maxEmissionsPerPeriod) {
3942
+ const error = errorFactory();
3943
+ onError === null || onError === void 0 ? void 0 : onError(error);
3944
+ throw error;
3945
+ } else {
3946
+ return x;
3947
+ }
3948
+ }));
3949
+ } else {
3950
+ // switchToObs was provided.
3951
+ return source.pipe(rxjs.switchMap(x => {
3952
+ if (counter() > maxEmissionsPerPeriod) {
3953
+ return switchToObs;
3954
+ } else {
3955
+ return rxjs.of(x);
3956
+ }
3957
+ }));
3958
+ }
3959
+ };
3960
+ }
3961
+
3926
3962
  function setContainsAllValuesFrom(valuesObs) {
3927
3963
  return combineLatestMapFrom(valuesObs, (set, values) => util.setContainsAllValues(set, values !== null && values !== void 0 ? values : []));
3928
3964
  }
@@ -5604,6 +5640,7 @@ exports.distinctUntilObjectValuesChanged = distinctUntilObjectValuesChanged;
5604
5640
  exports.emitAfterDelay = emitAfterDelay;
5605
5641
  exports.emitDelayObs = emitDelayObs;
5606
5642
  exports.errorFromLoadingState = errorFromLoadingState;
5643
+ exports.errorOnEmissionsInPeriod = errorOnEmissionsInPeriod;
5607
5644
  exports.errorPageResult = errorPageResult;
5608
5645
  exports.errorResult = errorResult;
5609
5646
  exports.factoryTimer = factoryTimer;
package/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { isObservable, of, switchMap, map, filter, skipWhile, EMPTY, combineLatest, delay, startWith, distinctUntilChanged, mergeMap, BehaviorSubject, shareReplay, skip, first, merge, finalize, firstValueFrom, scan, exhaustMap, identity, throttleTime, timeout, tap, throwError, timer, takeWhile, delayWhen, asyncScheduler, from, catchError, defaultIfEmpty } from 'rxjs';
2
- import { getValueFromGetter, isMaybeSo, areEqualPOJOValues, convertToArray, asGetter, performTaskLoop, isMaybeNot, pushItemOrArrayItemsIntoArray, pushArrayItemsIntoArray, forEachWithArray, asArray, filterAndMapFunction, objectKeysEqualityComparatorFunction, objectKeyEqualityComparatorFunction, asPromise, randomNumberFactory, mapKeysIntersectionObjectToArray, mapsHaveSameKeys, incrementingNumberFactory, filterUniqueFunction, build, cachedGetter, allKeyValueTuples, keyValueMapFactory, multiKeyValueMapFactory, setContainsAllValues, setContainsAnyValue, setContainsNoneOfValue, hasSameValues, compareEqualityWithValueFromItemsFunction, searchStringFilterFunction, objectHasKey, toReadableError, reduceBooleansWithOr, reduceBooleansWithAnd, valuesAreBothNullishOrEquivalent, filterMaybeValues, mergeObjects, safeCompareEquality, limitArray, hasNonNullValue, mapFunctionOutputPair, lastValue, flattenArray, filteredPage, FIRST_PAGE, hasValueOrNotEmpty, getNextPageNumber, reduceBooleansWithOrFn } from '@dereekb/util';
2
+ import { getValueFromGetter, isMaybeSo, areEqualPOJOValues, convertToArray, asGetter, performTaskLoop, isMaybeNot, pushItemOrArrayItemsIntoArray, pushArrayItemsIntoArray, forEachWithArray, asArray, filterAndMapFunction, objectKeysEqualityComparatorFunction, objectKeyEqualityComparatorFunction, asPromise, randomNumberFactory, mapKeysIntersectionObjectToArray, mapsHaveSameKeys, incrementingNumberFactory, filterUniqueFunction, build, cachedGetter, allKeyValueTuples, keyValueMapFactory, multiKeyValueMapFactory, timePeriodCounter, setContainsAllValues, setContainsAnyValue, setContainsNoneOfValue, hasSameValues, compareEqualityWithValueFromItemsFunction, searchStringFilterFunction, objectHasKey, toReadableError, reduceBooleansWithOr, reduceBooleansWithAnd, valuesAreBothNullishOrEquivalent, filterMaybeValues, mergeObjects, safeCompareEquality, limitArray, hasNonNullValue, mapFunctionOutputPair, lastValue, flattenArray, filteredPage, FIRST_PAGE, hasValueOrNotEmpty, getNextPageNumber, reduceBooleansWithOrFn } from '@dereekb/util';
3
3
  import ms from 'ms';
4
4
 
5
5
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
@@ -4085,6 +4085,42 @@ function multiKeyValueMap(read) {
4085
4085
  return map(multiKeyValueMapFactory(read));
4086
4086
  }
4087
4087
 
4088
+ function errorOnEmissionsInPeriod(config) {
4089
+ const {
4090
+ period = 1000,
4091
+ maxEmissionsPerPeriod,
4092
+ onError,
4093
+ errorFactory: inputErrorFactory,
4094
+ errorMessage: inputErrorMessage,
4095
+ switchToObs
4096
+ } = config;
4097
+ const errorMessage = inputErrorMessage != null ? inputErrorMessage : 'errorOnEmissionsInPeriod(): Too many emissions in time period.';
4098
+ const errorFactory = inputErrorFactory ? inputErrorFactory : !switchToObs ? () => new Error(errorMessage) : undefined;
4099
+ return source => {
4100
+ const counter = timePeriodCounter(period);
4101
+ if (errorFactory) {
4102
+ return source.pipe(map(x => {
4103
+ if (counter() > maxEmissionsPerPeriod) {
4104
+ const error = errorFactory();
4105
+ onError == null || onError(error);
4106
+ throw error;
4107
+ } else {
4108
+ return x;
4109
+ }
4110
+ }));
4111
+ } else {
4112
+ // switchToObs was provided.
4113
+ return source.pipe(switchMap(x => {
4114
+ if (counter() > maxEmissionsPerPeriod) {
4115
+ return switchToObs;
4116
+ } else {
4117
+ return of(x);
4118
+ }
4119
+ }));
4120
+ }
4121
+ };
4122
+ }
4123
+
4088
4124
  function setContainsAllValuesFrom(valuesObs) {
4089
4125
  return combineLatestMapFrom(valuesObs, (set, values) => setContainsAllValues(set, values != null ? values : []));
4090
4126
  }
@@ -5927,4 +5963,4 @@ function workFactoryForConfigFactory(configFactory) {
5927
5963
  };
5928
5964
  }
5929
5965
 
5930
- export { AbstractLoadingStateContextInstance, DEFAULT_ASYNC_PUSHER_THROTTLE, DEFAULT_FACTORY_TIMER_INTERVAL, DEFAULT_ITEM_PAGE_ITERATOR_MAX, DEFAULT_LOCK_SET_TIME_LOCK_KEY, FilterMap, FilterMapKeyInstance, FilterSource, FilterSourceConnector, FilterSourceInstance, ItemAccumulatorInstance, ItemPageIterationInstance, ItemPageIterator, ListLoadingStateContextInstance, LoadingStateContextInstance, LoadingStateType, LockSet, MappedItemIterationInstance, MappedPageItemIterationInstance, MultiSubscriptionObject, PresetFilterSource, SimpleLoadingContext, SubscriptionObject, ValuesLoadingContext, WorkInstance, accumulatorCurrentPageListLoadingState, accumulatorFlattenPageListLoadingState, allLoadingStatesHaveFinishedLoading, asObservable, asObservableFromGetter, asyncPusher, asyncPusherCache, beginLoading, beginLoadingPage, checkIs, cleanup, cleanupDestroyable, combineLatestFromArrayObsFn, combineLatestFromMapValuesObsFn, combineLatestFromObject, combineLatestMapFrom, combineLoadingStates, combineLoadingStatesStatus, distinctLoadingState, distinctUntilArrayLengthChanges, distinctUntilHasDifferentValues, distinctUntilItemsHaveDifferentValues, distinctUntilItemsValueChanges, distinctUntilKeysChange, distinctUntilMapHasDifferentKeys, distinctUntilModelIdChange, distinctUntilModelKeyChange, distinctUntilObjectKeyChange, distinctUntilObjectValuesChanged, emitAfterDelay, emitDelayObs, errorFromLoadingState, errorPageResult, errorResult, factoryTimer, filterIfObjectValuesUnchanged, filterItemsWithObservableDecision, filterMaybe, filterUnique, filterWithSearchString, flattenAccumulatorResultItemArray, idleLoadingState, incrementingNumberTimer, initialize, invertObservableDecision, isErrorLoadingState, isItemPageIteratorResultEndResult, isListLoadingStateEmpty, isLoading, isNot, isSuccessLoadingState, itemAccumulator, itemAccumulatorNextPageUntilResultsCount, iterationHasNextAndCanLoadMore, iteratorNextPageUntilMaxPageLoadLimit, iteratorNextPageUntilPage, keyValueMap, lazyFrom, listLoadingStateContext, listLoadingStateIsEmpty, loadingStateContext, loadingStateFromObs, loadingStateHasError, loadingStateHasFinishedLoading, loadingStateHasFinishedLoadingWithError, loadingStateHasFinishedLoadingWithValue, loadingStateHasValue, loadingStateIsIdle, loadingStateIsLoading, loadingStateType, loadingStatesHaveEquivalentMetadata, makeCheckIsFunction, makeMapFilterWithPresetFn, makeReturnIfIsFunction, mapEachAsync, mapFilterWithPreset, mapForEach, mapIf, mapItemIteration, mapKeysIntersectionToArray, mapLoadingState, mapLoadingStateResults, mapLoadingStateValueFunction, mapLoadingStateValueWithOperator, mapMaybe, mapMultipleLoadingStateResults, mapPageItemIteration, maybeValueFromObservableOrValueGetter, mergeLoadingStates, multiKeyValueMap, onFalseToTrue, onLockSetNextUnlock, onMatchDelta, onTrueToFalse, pageItemAccumulatorCurrentPage, pageLoadingStateFromObs, pipeIf, preventComplete, promiseFromLoadingState, randomDelay, randomDelayWithRandomFunction, returnIfIs, scanBuildArray, scanCount, scanIntoArray, setContainsAllValuesFrom, setContainsAnyValueFrom, setContainsNoValueFrom, skipFirstMaybe, startWithBeginLoading, successPageResult, successResult, switchMapMaybeDefault, switchMapMaybeObs, switchMapObject, switchMapOnBoolean, switchMapToDefault, switchMapWhileFalse, switchMapWhileTrue, tapAfterTimeout, tapFirst, tapLog, tapOnLoadingStateSuccess, tapOnLoadingStateType, throwErrorAfterTimeout, timeoutStartWith, unknownLoadingStatesIsLoading, updatedStateForSetError, updatedStateForSetLoading, updatedStateForSetValue, useAsObservable, useFirst, valueFromFinishedLoadingState, valueFromLoadingState, valueFromObservableOrValue, valueFromObservableOrValueGetter, workFactory, workFactoryForConfigFactory };
5966
+ export { AbstractLoadingStateContextInstance, DEFAULT_ASYNC_PUSHER_THROTTLE, DEFAULT_FACTORY_TIMER_INTERVAL, DEFAULT_ITEM_PAGE_ITERATOR_MAX, DEFAULT_LOCK_SET_TIME_LOCK_KEY, FilterMap, FilterMapKeyInstance, FilterSource, FilterSourceConnector, FilterSourceInstance, ItemAccumulatorInstance, ItemPageIterationInstance, ItemPageIterator, ListLoadingStateContextInstance, LoadingStateContextInstance, LoadingStateType, LockSet, MappedItemIterationInstance, MappedPageItemIterationInstance, MultiSubscriptionObject, PresetFilterSource, SimpleLoadingContext, SubscriptionObject, ValuesLoadingContext, WorkInstance, accumulatorCurrentPageListLoadingState, accumulatorFlattenPageListLoadingState, allLoadingStatesHaveFinishedLoading, asObservable, asObservableFromGetter, asyncPusher, asyncPusherCache, beginLoading, beginLoadingPage, checkIs, cleanup, cleanupDestroyable, combineLatestFromArrayObsFn, combineLatestFromMapValuesObsFn, combineLatestFromObject, combineLatestMapFrom, combineLoadingStates, combineLoadingStatesStatus, distinctLoadingState, distinctUntilArrayLengthChanges, distinctUntilHasDifferentValues, distinctUntilItemsHaveDifferentValues, distinctUntilItemsValueChanges, distinctUntilKeysChange, distinctUntilMapHasDifferentKeys, distinctUntilModelIdChange, distinctUntilModelKeyChange, distinctUntilObjectKeyChange, distinctUntilObjectValuesChanged, emitAfterDelay, emitDelayObs, errorFromLoadingState, errorOnEmissionsInPeriod, errorPageResult, errorResult, factoryTimer, filterIfObjectValuesUnchanged, filterItemsWithObservableDecision, filterMaybe, filterUnique, filterWithSearchString, flattenAccumulatorResultItemArray, idleLoadingState, incrementingNumberTimer, initialize, invertObservableDecision, isErrorLoadingState, isItemPageIteratorResultEndResult, isListLoadingStateEmpty, isLoading, isNot, isSuccessLoadingState, itemAccumulator, itemAccumulatorNextPageUntilResultsCount, iterationHasNextAndCanLoadMore, iteratorNextPageUntilMaxPageLoadLimit, iteratorNextPageUntilPage, keyValueMap, lazyFrom, listLoadingStateContext, listLoadingStateIsEmpty, loadingStateContext, loadingStateFromObs, loadingStateHasError, loadingStateHasFinishedLoading, loadingStateHasFinishedLoadingWithError, loadingStateHasFinishedLoadingWithValue, loadingStateHasValue, loadingStateIsIdle, loadingStateIsLoading, loadingStateType, loadingStatesHaveEquivalentMetadata, makeCheckIsFunction, makeMapFilterWithPresetFn, makeReturnIfIsFunction, mapEachAsync, mapFilterWithPreset, mapForEach, mapIf, mapItemIteration, mapKeysIntersectionToArray, mapLoadingState, mapLoadingStateResults, mapLoadingStateValueFunction, mapLoadingStateValueWithOperator, mapMaybe, mapMultipleLoadingStateResults, mapPageItemIteration, maybeValueFromObservableOrValueGetter, mergeLoadingStates, multiKeyValueMap, onFalseToTrue, onLockSetNextUnlock, onMatchDelta, onTrueToFalse, pageItemAccumulatorCurrentPage, pageLoadingStateFromObs, pipeIf, preventComplete, promiseFromLoadingState, randomDelay, randomDelayWithRandomFunction, returnIfIs, scanBuildArray, scanCount, scanIntoArray, setContainsAllValuesFrom, setContainsAnyValueFrom, setContainsNoValueFrom, skipFirstMaybe, startWithBeginLoading, successPageResult, successResult, switchMapMaybeDefault, switchMapMaybeObs, switchMapObject, switchMapOnBoolean, switchMapToDefault, switchMapWhileFalse, switchMapWhileTrue, tapAfterTimeout, tapFirst, tapLog, tapOnLoadingStateSuccess, tapOnLoadingStateType, throwErrorAfterTimeout, timeoutStartWith, unknownLoadingStatesIsLoading, updatedStateForSetError, updatedStateForSetLoading, updatedStateForSetValue, useAsObservable, useFirst, valueFromFinishedLoadingState, valueFromLoadingState, valueFromObservableOrValue, valueFromObservableOrValueGetter, workFactory, workFactoryForConfigFactory };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dereekb/rxjs",
3
- "version": "10.1.0",
3
+ "version": "10.1.2",
4
4
  "exports": {
5
5
  ".": {
6
6
  "types": "./src/index.d.ts",
@@ -16,6 +16,7 @@ export * from './rxjs';
16
16
  export * from './rxjs.unique';
17
17
  export * from './rxjs.async';
18
18
  export * from './rxjs.map';
19
+ export * from './rxjs.error';
19
20
  export * from './set';
20
21
  export * from './string';
21
22
  export * from './use';
@@ -0,0 +1,39 @@
1
+ import { type Factory, type Milliseconds } from '@dereekb/util';
2
+ import { type MonoTypeOperatorFunction, type Observable } from 'rxjs';
3
+ export interface ErrorOnEmissionsInPeriodConfig<T> {
4
+ /**
5
+ * Number of milliseconds before clearing the emission count.
6
+ *
7
+ * Defaults to 1000 ms
8
+ */
9
+ readonly period?: Milliseconds;
10
+ /**
11
+ * The number of max emissions to allow.
12
+ */
13
+ readonly maxEmissionsPerPeriod: number;
14
+ /**
15
+ * Called before the error is thrown.
16
+ *
17
+ * @returns
18
+ */
19
+ readonly onError?: (error: unknown) => void;
20
+ /**
21
+ * Factory used to generate a new error to pass to the observable.
22
+ *
23
+ * If not provided, and switchToObs is not provided, a default error is thrown.
24
+ */
25
+ readonly errorFactory?: Factory<unknown>;
26
+ /**
27
+ * Optional observable to switch to instead of throwing an error.
28
+ *
29
+ * If errorFactory is provided this is ignored.
30
+ */
31
+ readonly switchToObs?: Observable<T>;
32
+ /**
33
+ * Optional error message to use instead of using ErrorFactory.
34
+ *
35
+ * If switchToObs is provided this is ignored.
36
+ */
37
+ readonly errorMessage?: string;
38
+ }
39
+ export declare function errorOnEmissionsInPeriod<T>(config: ErrorOnEmissionsInPeriodConfig<T>): MonoTypeOperatorFunction<T>;