@effuse/store 1.0.5 → 1.0.6

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/dist/index.d.cts CHANGED
@@ -300,10 +300,6 @@ interface RetryConfig {
300
300
  backoffFactor?: number;
301
301
  }
302
302
  declare const withRetry: <A extends unknown[], R>(fn: ActionFn<A, R>, config: RetryConfig) => ((...args: A) => Promise<R>);
303
- declare const takeLatest: <A extends unknown[], R>(fn: ActionFn<A, R>) => CancellableAction<A, R>;
304
- declare const takeFirst: <A extends unknown[], R>(fn: ActionFn<A, R>) => AsyncAction<A, R | undefined>;
305
- declare const debounceAction: <A extends unknown[], R>(fn: ActionFn<A, R>, delayMs: number) => ((...args: A) => Promise<R>);
306
- declare const throttleAction: <A extends unknown[], R>(fn: ActionFn<A, R>, intervalMs: number) => ((...args: A) => Promise<R | undefined>);
307
303
  declare const dispatch: <T>(store: Store<T>, actionName: keyof T, ...args: unknown[]) => Promise<unknown>;
308
304
  declare const dispatchSync: <T>(store: Store<T>, actionName: keyof T, ...args: unknown[]) => unknown;
309
305
  declare const withAbortSignal: <A extends unknown[], R>(fn: ActionFn<A, R>) => ((signal: AbortSignal, ...args: A) => Promise<R>);
@@ -331,7 +327,7 @@ declare const withAbortSignal: <A extends unknown[], R>(fn: ActionFn<A, R>) => (
331
327
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
332
328
  * SOFTWARE.
333
329
  */
334
- declare const StoreNotFoundError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
330
+ declare const StoreNotFoundError_base: new <A extends Record<string, any> = {}>(args: effect_Types.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => effect_Cause.YieldableError & {
335
331
  readonly _tag: "StoreNotFoundError";
336
332
  } & Readonly<A>;
337
333
  declare class StoreNotFoundError extends StoreNotFoundError_base<{
@@ -339,7 +335,7 @@ declare class StoreNotFoundError extends StoreNotFoundError_base<{
339
335
  }> {
340
336
  get message(): string;
341
337
  }
342
- declare const StoreAlreadyExistsError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
338
+ declare const StoreAlreadyExistsError_base: new <A extends Record<string, any> = {}>(args: effect_Types.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => effect_Cause.YieldableError & {
343
339
  readonly _tag: "StoreAlreadyExistsError";
344
340
  } & Readonly<A>;
345
341
  declare class StoreAlreadyExistsError extends StoreAlreadyExistsError_base<{
@@ -347,14 +343,14 @@ declare class StoreAlreadyExistsError extends StoreAlreadyExistsError_base<{
347
343
  }> {
348
344
  get message(): string;
349
345
  }
350
- declare const ActionNotFoundError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
346
+ declare const ActionNotFoundError_base: new <A extends Record<string, any> = {}>(args: effect_Types.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => effect_Cause.YieldableError & {
351
347
  readonly _tag: "ActionNotFoundError";
352
348
  } & Readonly<A>;
353
349
  declare class ActionNotFoundError extends ActionNotFoundError_base<{
354
350
  readonly actionName: string;
355
351
  }> {
356
352
  }
357
- declare const TimeoutError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
353
+ declare const TimeoutError_base: new <A extends Record<string, any> = {}>(args: effect_Types.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => effect_Cause.YieldableError & {
358
354
  readonly _tag: "TimeoutError";
359
355
  } & Readonly<A>;
360
356
  declare class TimeoutError extends TimeoutError_base<{
@@ -362,14 +358,14 @@ declare class TimeoutError extends TimeoutError_base<{
362
358
  }> {
363
359
  get message(): string;
364
360
  }
365
- declare const CancellationError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
361
+ declare const CancellationError_base: new <A extends Record<string, any> = {}>(args: effect_Types.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => effect_Cause.YieldableError & {
366
362
  readonly _tag: "CancellationError";
367
363
  } & Readonly<A>;
368
364
  declare class CancellationError extends CancellationError_base<{
369
365
  readonly message: string;
370
366
  }> {
371
367
  }
372
- declare const ValidationError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
368
+ declare const ValidationError_base: new <A extends Record<string, any> = {}>(args: effect_Types.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => effect_Cause.YieldableError & {
373
369
  readonly _tag: "ValidationError";
374
370
  } & Readonly<A>;
375
371
  declare class ValidationError extends ValidationError_base<{
@@ -416,6 +412,38 @@ interface CancellationScope {
416
412
  }
417
413
  declare const createCancellationScope: () => CancellationScope;
418
414
 
415
+ /**
416
+ * MIT License
417
+ *
418
+ * Copyright (c) 2025 Chris M. Perez
419
+ *
420
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
421
+ * of this software and associated documentation files (the "Software"), to deal
422
+ * in the Software without restriction, including without limitation the rights
423
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
424
+ * copies of the Software, and to permit persons to whom the Software is
425
+ * furnished to do so, subject to the following conditions:
426
+ *
427
+ * The above copyright notice and this permission notice shall be included in all
428
+ * copies or substantial portions of the Software.
429
+ *
430
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
431
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
432
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
433
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
434
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
435
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
436
+ * SOFTWARE.
437
+ */
438
+
439
+ type ConcurrencyStrategy = 'switch' | 'exhaust' | 'merge' | 'concat';
440
+ interface ConcurrencyOptions {
441
+ strategy?: ConcurrencyStrategy;
442
+ debounceMs?: number;
443
+ throttleMs?: number;
444
+ }
445
+ declare function useConcurrency<A extends unknown[], R, E = never>(action: (...args: A) => Effect.Effect<R, E>, options?: ConcurrencyOptions): (...args: A) => void;
446
+
419
447
  /**
420
448
  * MIT License
421
449
  *
@@ -699,4 +727,4 @@ declare const removeStore: (name: string) => boolean;
699
727
  declare const clearStores: () => void;
700
728
  declare const getStoreNames: () => string[];
701
729
 
702
- export { type ActionContext, ActionNotFoundError, type ActionResult, type AsyncAction, type AsyncSelector, type AtomicState, type CancellableAction, CancellationError, type CancellationScope, type CancellationToken, type ComposedStore, type CreateStoreOptions, DEFAULT_RETRY_BACKOFF_FACTOR, DEFAULT_RETRY_INITIAL_DELAY_MS, DEFAULT_RETRY_MAX_DELAY_MS, DEFAULT_TIMEOUT_MS, type EqualityFn, type InferStoreState, type Middleware, type MiddlewareManager, ROOT_SCOPE_ID, type RetryConfig, SCOPE_PREFIX, STORAGE_PREFIX, type ScopeId, type ScopeNode, type Selector, type StateSchema, type Store, StoreAlreadyExistsError, type StoreConfigValues, StoreConstants, type StoreContext, type StoreDefinition, StoreNotFoundError, type StoreOptions, type StoreSlice, type StoreState, type StoreStream, TimeoutError, ValidationError, type ValidationResult, clearStores, combineSelectors, composeStores, connectDevTools, createAsyncAction, createAtomicState, createCancellableAction, createCancellationScope, createCancellationToken, createDevToolsMiddleware, createFieldValidator, createMiddlewareManager, createSafeFieldSetter, createScope, createSelector, createSelectorAsync, createStore, createStoreStream, createValidatedSetter, debounceAction, defineSlice, deriveFrom, deriveFromAsync, devToolsMiddleware, disconnectAllDevTools, disconnectDevTools, dispatch, dispatchSync, disposeScope, enterScope, exitScope, getCurrentScope, getRootScope, getScopedStore, getStore, getStoreConfig, getStoreNames, hasDevTools, hasScopedStore, hasStore, hydrateStoresSync, mergeStores, pick, registerScopedStore, removeStore, resetStoreConfigCache, runInScope, serializeStores, shallowEqual, streamAll, takeFirst, takeLatest, throttleAction, validateState, validateStateAsync, withAbortSignal, withRetry, withScope, withTimeout };
730
+ export { type ActionContext, ActionNotFoundError, type ActionResult, type AsyncAction, type AsyncSelector, type AtomicState, type CancellableAction, CancellationError, type CancellationScope, type CancellationToken, type ComposedStore, type ConcurrencyOptions, type ConcurrencyStrategy, type CreateStoreOptions, DEFAULT_RETRY_BACKOFF_FACTOR, DEFAULT_RETRY_INITIAL_DELAY_MS, DEFAULT_RETRY_MAX_DELAY_MS, DEFAULT_TIMEOUT_MS, type EqualityFn, type InferStoreState, type Middleware, type MiddlewareManager, ROOT_SCOPE_ID, type RetryConfig, SCOPE_PREFIX, STORAGE_PREFIX, type ScopeId, type ScopeNode, type Selector, type StateSchema, type Store, StoreAlreadyExistsError, type StoreConfigValues, StoreConstants, type StoreContext, type StoreDefinition, StoreNotFoundError, type StoreOptions, type StoreSlice, type StoreState, type StoreStream, TimeoutError, ValidationError, type ValidationResult, clearStores, combineSelectors, composeStores, connectDevTools, createAsyncAction, createAtomicState, createCancellableAction, createCancellationScope, createCancellationToken, createDevToolsMiddleware, createFieldValidator, createMiddlewareManager, createSafeFieldSetter, createScope, createSelector, createSelectorAsync, createStore, createStoreStream, createValidatedSetter, defineSlice, deriveFrom, deriveFromAsync, devToolsMiddleware, disconnectAllDevTools, disconnectDevTools, dispatch, dispatchSync, disposeScope, enterScope, exitScope, getCurrentScope, getRootScope, getScopedStore, getStore, getStoreConfig, getStoreNames, hasDevTools, hasScopedStore, hasStore, hydrateStoresSync, mergeStores, pick, registerScopedStore, removeStore, resetStoreConfigCache, runInScope, serializeStores, shallowEqual, streamAll, useConcurrency, validateState, validateStateAsync, withAbortSignal, withRetry, withScope, withTimeout };
package/dist/index.d.ts CHANGED
@@ -300,10 +300,6 @@ interface RetryConfig {
300
300
  backoffFactor?: number;
301
301
  }
302
302
  declare const withRetry: <A extends unknown[], R>(fn: ActionFn<A, R>, config: RetryConfig) => ((...args: A) => Promise<R>);
303
- declare const takeLatest: <A extends unknown[], R>(fn: ActionFn<A, R>) => CancellableAction<A, R>;
304
- declare const takeFirst: <A extends unknown[], R>(fn: ActionFn<A, R>) => AsyncAction<A, R | undefined>;
305
- declare const debounceAction: <A extends unknown[], R>(fn: ActionFn<A, R>, delayMs: number) => ((...args: A) => Promise<R>);
306
- declare const throttleAction: <A extends unknown[], R>(fn: ActionFn<A, R>, intervalMs: number) => ((...args: A) => Promise<R | undefined>);
307
303
  declare const dispatch: <T>(store: Store<T>, actionName: keyof T, ...args: unknown[]) => Promise<unknown>;
308
304
  declare const dispatchSync: <T>(store: Store<T>, actionName: keyof T, ...args: unknown[]) => unknown;
309
305
  declare const withAbortSignal: <A extends unknown[], R>(fn: ActionFn<A, R>) => ((signal: AbortSignal, ...args: A) => Promise<R>);
@@ -331,7 +327,7 @@ declare const withAbortSignal: <A extends unknown[], R>(fn: ActionFn<A, R>) => (
331
327
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
332
328
  * SOFTWARE.
333
329
  */
334
- declare const StoreNotFoundError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
330
+ declare const StoreNotFoundError_base: new <A extends Record<string, any> = {}>(args: effect_Types.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => effect_Cause.YieldableError & {
335
331
  readonly _tag: "StoreNotFoundError";
336
332
  } & Readonly<A>;
337
333
  declare class StoreNotFoundError extends StoreNotFoundError_base<{
@@ -339,7 +335,7 @@ declare class StoreNotFoundError extends StoreNotFoundError_base<{
339
335
  }> {
340
336
  get message(): string;
341
337
  }
342
- declare const StoreAlreadyExistsError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
338
+ declare const StoreAlreadyExistsError_base: new <A extends Record<string, any> = {}>(args: effect_Types.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => effect_Cause.YieldableError & {
343
339
  readonly _tag: "StoreAlreadyExistsError";
344
340
  } & Readonly<A>;
345
341
  declare class StoreAlreadyExistsError extends StoreAlreadyExistsError_base<{
@@ -347,14 +343,14 @@ declare class StoreAlreadyExistsError extends StoreAlreadyExistsError_base<{
347
343
  }> {
348
344
  get message(): string;
349
345
  }
350
- declare const ActionNotFoundError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
346
+ declare const ActionNotFoundError_base: new <A extends Record<string, any> = {}>(args: effect_Types.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => effect_Cause.YieldableError & {
351
347
  readonly _tag: "ActionNotFoundError";
352
348
  } & Readonly<A>;
353
349
  declare class ActionNotFoundError extends ActionNotFoundError_base<{
354
350
  readonly actionName: string;
355
351
  }> {
356
352
  }
357
- declare const TimeoutError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
353
+ declare const TimeoutError_base: new <A extends Record<string, any> = {}>(args: effect_Types.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => effect_Cause.YieldableError & {
358
354
  readonly _tag: "TimeoutError";
359
355
  } & Readonly<A>;
360
356
  declare class TimeoutError extends TimeoutError_base<{
@@ -362,14 +358,14 @@ declare class TimeoutError extends TimeoutError_base<{
362
358
  }> {
363
359
  get message(): string;
364
360
  }
365
- declare const CancellationError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
361
+ declare const CancellationError_base: new <A extends Record<string, any> = {}>(args: effect_Types.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => effect_Cause.YieldableError & {
366
362
  readonly _tag: "CancellationError";
367
363
  } & Readonly<A>;
368
364
  declare class CancellationError extends CancellationError_base<{
369
365
  readonly message: string;
370
366
  }> {
371
367
  }
372
- declare const ValidationError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
368
+ declare const ValidationError_base: new <A extends Record<string, any> = {}>(args: effect_Types.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => effect_Cause.YieldableError & {
373
369
  readonly _tag: "ValidationError";
374
370
  } & Readonly<A>;
375
371
  declare class ValidationError extends ValidationError_base<{
@@ -416,6 +412,38 @@ interface CancellationScope {
416
412
  }
417
413
  declare const createCancellationScope: () => CancellationScope;
418
414
 
415
+ /**
416
+ * MIT License
417
+ *
418
+ * Copyright (c) 2025 Chris M. Perez
419
+ *
420
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
421
+ * of this software and associated documentation files (the "Software"), to deal
422
+ * in the Software without restriction, including without limitation the rights
423
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
424
+ * copies of the Software, and to permit persons to whom the Software is
425
+ * furnished to do so, subject to the following conditions:
426
+ *
427
+ * The above copyright notice and this permission notice shall be included in all
428
+ * copies or substantial portions of the Software.
429
+ *
430
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
431
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
432
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
433
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
434
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
435
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
436
+ * SOFTWARE.
437
+ */
438
+
439
+ type ConcurrencyStrategy = 'switch' | 'exhaust' | 'merge' | 'concat';
440
+ interface ConcurrencyOptions {
441
+ strategy?: ConcurrencyStrategy;
442
+ debounceMs?: number;
443
+ throttleMs?: number;
444
+ }
445
+ declare function useConcurrency<A extends unknown[], R, E = never>(action: (...args: A) => Effect.Effect<R, E>, options?: ConcurrencyOptions): (...args: A) => void;
446
+
419
447
  /**
420
448
  * MIT License
421
449
  *
@@ -699,4 +727,4 @@ declare const removeStore: (name: string) => boolean;
699
727
  declare const clearStores: () => void;
700
728
  declare const getStoreNames: () => string[];
701
729
 
702
- export { type ActionContext, ActionNotFoundError, type ActionResult, type AsyncAction, type AsyncSelector, type AtomicState, type CancellableAction, CancellationError, type CancellationScope, type CancellationToken, type ComposedStore, type CreateStoreOptions, DEFAULT_RETRY_BACKOFF_FACTOR, DEFAULT_RETRY_INITIAL_DELAY_MS, DEFAULT_RETRY_MAX_DELAY_MS, DEFAULT_TIMEOUT_MS, type EqualityFn, type InferStoreState, type Middleware, type MiddlewareManager, ROOT_SCOPE_ID, type RetryConfig, SCOPE_PREFIX, STORAGE_PREFIX, type ScopeId, type ScopeNode, type Selector, type StateSchema, type Store, StoreAlreadyExistsError, type StoreConfigValues, StoreConstants, type StoreContext, type StoreDefinition, StoreNotFoundError, type StoreOptions, type StoreSlice, type StoreState, type StoreStream, TimeoutError, ValidationError, type ValidationResult, clearStores, combineSelectors, composeStores, connectDevTools, createAsyncAction, createAtomicState, createCancellableAction, createCancellationScope, createCancellationToken, createDevToolsMiddleware, createFieldValidator, createMiddlewareManager, createSafeFieldSetter, createScope, createSelector, createSelectorAsync, createStore, createStoreStream, createValidatedSetter, debounceAction, defineSlice, deriveFrom, deriveFromAsync, devToolsMiddleware, disconnectAllDevTools, disconnectDevTools, dispatch, dispatchSync, disposeScope, enterScope, exitScope, getCurrentScope, getRootScope, getScopedStore, getStore, getStoreConfig, getStoreNames, hasDevTools, hasScopedStore, hasStore, hydrateStoresSync, mergeStores, pick, registerScopedStore, removeStore, resetStoreConfigCache, runInScope, serializeStores, shallowEqual, streamAll, takeFirst, takeLatest, throttleAction, validateState, validateStateAsync, withAbortSignal, withRetry, withScope, withTimeout };
730
+ export { type ActionContext, ActionNotFoundError, type ActionResult, type AsyncAction, type AsyncSelector, type AtomicState, type CancellableAction, CancellationError, type CancellationScope, type CancellationToken, type ComposedStore, type ConcurrencyOptions, type ConcurrencyStrategy, type CreateStoreOptions, DEFAULT_RETRY_BACKOFF_FACTOR, DEFAULT_RETRY_INITIAL_DELAY_MS, DEFAULT_RETRY_MAX_DELAY_MS, DEFAULT_TIMEOUT_MS, type EqualityFn, type InferStoreState, type Middleware, type MiddlewareManager, ROOT_SCOPE_ID, type RetryConfig, SCOPE_PREFIX, STORAGE_PREFIX, type ScopeId, type ScopeNode, type Selector, type StateSchema, type Store, StoreAlreadyExistsError, type StoreConfigValues, StoreConstants, type StoreContext, type StoreDefinition, StoreNotFoundError, type StoreOptions, type StoreSlice, type StoreState, type StoreStream, TimeoutError, ValidationError, type ValidationResult, clearStores, combineSelectors, composeStores, connectDevTools, createAsyncAction, createAtomicState, createCancellableAction, createCancellationScope, createCancellationToken, createDevToolsMiddleware, createFieldValidator, createMiddlewareManager, createSafeFieldSetter, createScope, createSelector, createSelectorAsync, createStore, createStoreStream, createValidatedSetter, defineSlice, deriveFrom, deriveFromAsync, devToolsMiddleware, disconnectAllDevTools, disconnectDevTools, dispatch, dispatchSync, disposeScope, enterScope, exitScope, getCurrentScope, getRootScope, getScopedStore, getStore, getStoreConfig, getStoreNames, hasDevTools, hasScopedStore, hasStore, hydrateStoresSync, mergeStores, pick, registerScopedStore, removeStore, resetStoreConfigCache, runInScope, serializeStores, shallowEqual, streamAll, useConcurrency, validateState, validateStateAsync, withAbortSignal, withRetry, withScope, withTimeout };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Duration, Config, Effect, Data, SubscriptionRef, Array as Array$1, pipe, Option, Schedule, Schema, Predicate } from 'effect';
1
+ import { Duration, Config, Effect, Data, SubscriptionRef, Array as Array$1, pipe, Option, Schedule, Queue, Schema, Predicate, Fiber } from 'effect';
2
2
  import { signal } from '@effuse/core';
3
3
 
4
4
  // src/core/store.ts
@@ -831,99 +831,6 @@ var withRetry = (fn, config) => {
831
831
  return Effect.runPromise(effect);
832
832
  };
833
833
  };
834
- var takeLatest = (fn) => {
835
- let pending = false;
836
- let currentToken = createCancellationToken();
837
- let callId = 0;
838
- const action = async (...args) => {
839
- currentToken.cancel();
840
- currentToken = createCancellationToken();
841
- const myToken = currentToken;
842
- const myCallId = ++callId;
843
- pending = true;
844
- try {
845
- const result = await fn(...args);
846
- if (myToken.isCancelled || myCallId !== callId) {
847
- throw new CancellationError({ message: "Superseded by newer call" });
848
- }
849
- return result;
850
- } finally {
851
- if (myCallId === callId) {
852
- pending = false;
853
- }
854
- }
855
- };
856
- Object.defineProperty(action, "pending", {
857
- get: () => pending,
858
- enumerable: true
859
- });
860
- Object.defineProperty(action, "cancel", {
861
- value: () => {
862
- currentToken.cancel();
863
- pending = false;
864
- },
865
- enumerable: true
866
- });
867
- return action;
868
- };
869
- var takeFirst = (fn) => {
870
- let pending = false;
871
- const action = async (...args) => {
872
- if (pending) {
873
- return void 0;
874
- }
875
- pending = true;
876
- try {
877
- return await fn(...args);
878
- } finally {
879
- pending = false;
880
- }
881
- };
882
- Object.defineProperty(action, "pending", {
883
- get: () => pending,
884
- enumerable: true
885
- });
886
- return action;
887
- };
888
- var debounceAction = (fn, delayMs) => {
889
- let timeout = null;
890
- let currentToken = createCancellationToken();
891
- return (...args) => {
892
- if (timeout) {
893
- clearTimeout(timeout);
894
- currentToken.cancel();
895
- }
896
- currentToken = createCancellationToken();
897
- const myToken = currentToken;
898
- return new Promise((resolve, reject) => {
899
- timeout = setTimeout(() => {
900
- if (myToken.isCancelled) return;
901
- Promise.resolve(fn(...args)).then((result) => {
902
- if (!myToken.isCancelled) resolve(result);
903
- }).catch((error) => {
904
- if (!myToken.isCancelled) reject(error);
905
- });
906
- }, delayMs);
907
- });
908
- };
909
- };
910
- var throttleAction = (fn, intervalMs) => {
911
- let lastCallTime = 0;
912
- let pending = false;
913
- return async (...args) => {
914
- const now = Date.now();
915
- if (now - lastCallTime < intervalMs || pending) {
916
- return void 0;
917
- }
918
- lastCallTime = now;
919
- pending = true;
920
- try {
921
- return await fn(...args);
922
- } finally {
923
- pending = false;
924
- }
925
- };
926
- };
927
834
  var dispatch = (store, actionName, ...args) => {
928
835
  const storeRecord = store;
929
836
  const action = storeRecord[actionName];
@@ -958,6 +865,86 @@ var withAbortSignal = (fn) => {
958
865
  return Effect.runPromise(runWithAbortSignal(effect, signal6));
959
866
  };
960
867
  };
868
+ function useConcurrency(action, options = {}) {
869
+ const { strategy = "switch", debounceMs, throttleMs } = options;
870
+ let runningFiber = null;
871
+ let debounceTimeout = null;
872
+ let lastCallTime = 0;
873
+ const queue = strategy === "concat" ? Effect.runSync(Queue.unbounded()) : null;
874
+ if (queue) {
875
+ Effect.runFork(
876
+ Effect.forever(
877
+ Effect.gen(function* () {
878
+ const args = yield* Queue.take(queue);
879
+ yield* Effect.catchAll(action(...args), () => Effect.void);
880
+ })
881
+ )
882
+ );
883
+ }
884
+ const execute = (...args) => {
885
+ switch (strategy) {
886
+ case "switch":
887
+ if (runningFiber) {
888
+ Effect.runFork(Fiber.interrupt(runningFiber));
889
+ }
890
+ runningFiber = Effect.runFork(
891
+ Effect.match(action(...args), {
892
+ onFailure: () => {
893
+ runningFiber = null;
894
+ },
895
+ onSuccess: () => {
896
+ runningFiber = null;
897
+ }
898
+ })
899
+ );
900
+ break;
901
+ case "exhaust":
902
+ if (runningFiber) {
903
+ return;
904
+ }
905
+ runningFiber = Effect.runFork(
906
+ Effect.match(action(...args), {
907
+ onFailure: () => {
908
+ runningFiber = null;
909
+ },
910
+ onSuccess: () => {
911
+ runningFiber = null;
912
+ }
913
+ })
914
+ );
915
+ break;
916
+ case "merge":
917
+ Effect.runFork(
918
+ Effect.catchAll(action(...args), () => Effect.void)
919
+ );
920
+ break;
921
+ case "concat":
922
+ if (queue) {
923
+ Effect.runFork(Queue.offer(queue, args));
924
+ }
925
+ break;
926
+ }
927
+ };
928
+ return (...args) => {
929
+ const now = Date.now();
930
+ if (throttleMs !== void 0 && throttleMs > 0) {
931
+ if (now - lastCallTime < throttleMs) {
932
+ return;
933
+ }
934
+ lastCallTime = now;
935
+ }
936
+ if (debounceMs !== void 0 && debounceMs > 0) {
937
+ if (debounceTimeout) {
938
+ clearTimeout(debounceTimeout);
939
+ }
940
+ debounceTimeout = setTimeout(() => {
941
+ execute(...args);
942
+ }, debounceMs);
943
+ return;
944
+ }
945
+ execute(...args);
946
+ };
947
+ }
961
948
  var validateState = (schema, state) => {
962
949
  const result = Effect.runSync(
963
950
  Schema.decodeUnknown(schema)(state).pipe(
@@ -1196,7 +1183,7 @@ var hydrateStores = (serialized) => Effect.try({
1196
1183
  );
1197
1184
  }
1198
1185
  },
1199
- catch: () => new HydrationError({})
1186
+ catch: () => new HydrationError()
1200
1187
  }).pipe(Effect.catchAll(() => Effect.void));
1201
1188
  var hydrateStoresSync = (serialized) => {
1202
1189
  Effect.runSync(
@@ -1472,6 +1459,6 @@ var disconnectAllDevTools = () => {
1472
1459
  connections.clear();
1473
1460
  };
1474
1461
 
1475
- export { ActionNotFoundError, CancellationError, DEFAULT_RETRY_BACKOFF_FACTOR, DEFAULT_RETRY_INITIAL_DELAY_MS, DEFAULT_RETRY_MAX_DELAY_MS, DEFAULT_TIMEOUT_MS, ROOT_SCOPE_ID, SCOPE_PREFIX, STORAGE_PREFIX, StoreAlreadyExistsError, StoreConstants, StoreNotFoundError, TimeoutError, ValidationError, clearStores, combineSelectors, composeStores, connectDevTools, createAsyncAction, createAtomicState, createCancellableAction, createCancellationScope, createCancellationToken, createDevToolsMiddleware, createFieldValidator, createMiddlewareManager, createSafeFieldSetter, createScope, createSelector, createSelectorAsync, createStore, createStoreStream, createValidatedSetter, debounceAction, defineSlice, deriveFrom, deriveFromAsync, devToolsMiddleware, disconnectAllDevTools, disconnectDevTools, dispatch, dispatchSync, disposeScope, enterScope, exitScope, getCurrentScope, getRootScope, getScopedStore, getStore, getStoreConfig, getStoreNames, hasDevTools, hasScopedStore, hasStore, hydrateStoresSync, mergeStores, pick, registerScopedStore, removeStore, resetStoreConfigCache, runInScope, serializeStores, shallowEqual, streamAll, takeFirst, takeLatest, throttleAction, validateState, validateStateAsync, withAbortSignal, withRetry, withScope, withTimeout };
1462
+ export { ActionNotFoundError, CancellationError, DEFAULT_RETRY_BACKOFF_FACTOR, DEFAULT_RETRY_INITIAL_DELAY_MS, DEFAULT_RETRY_MAX_DELAY_MS, DEFAULT_TIMEOUT_MS, ROOT_SCOPE_ID, SCOPE_PREFIX, STORAGE_PREFIX, StoreAlreadyExistsError, StoreConstants, StoreNotFoundError, TimeoutError, ValidationError, clearStores, combineSelectors, composeStores, connectDevTools, createAsyncAction, createAtomicState, createCancellableAction, createCancellationScope, createCancellationToken, createDevToolsMiddleware, createFieldValidator, createMiddlewareManager, createSafeFieldSetter, createScope, createSelector, createSelectorAsync, createStore, createStoreStream, createValidatedSetter, defineSlice, deriveFrom, deriveFromAsync, devToolsMiddleware, disconnectAllDevTools, disconnectDevTools, dispatch, dispatchSync, disposeScope, enterScope, exitScope, getCurrentScope, getRootScope, getScopedStore, getStore, getStoreConfig, getStoreNames, hasDevTools, hasScopedStore, hasStore, hydrateStoresSync, mergeStores, pick, registerScopedStore, removeStore, resetStoreConfigCache, runInScope, serializeStores, shallowEqual, streamAll, useConcurrency, validateState, validateStateAsync, withAbortSignal, withRetry, withScope, withTimeout };
1476
1463
  //# sourceMappingURL=index.js.map
1477
1464
  //# sourceMappingURL=index.js.map