@storesjs/stores 0.10.0 → 0.11.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 (48) hide show
  1. package/dist/createBaseStore.d.ts +2 -2
  2. package/dist/createQueryStore.d.ts +7 -13
  3. package/dist/internal/derivedStore/deriveProxy.d.ts +2 -2
  4. package/dist/internal/queryStore/queryParams.d.ts +18 -0
  5. package/dist/internal/runtime.d.ts +0 -1
  6. package/dist/internal/types/internalSubscribeTypes.d.ts +16 -0
  7. package/dist/native/index.js +1 -1
  8. package/dist/native/index.mjs +1 -1
  9. package/dist/queryStore/classes/SubscriptionManager.d.ts +3 -31
  10. package/dist/queryStore/queryKey.d.ts +9 -2
  11. package/dist/queryStore/queryParam.d.ts +37 -0
  12. package/dist/queryStore/types.d.ts +10 -52
  13. package/dist/{vanilla/internal/derivedStore → store}/cascadeScheduler.d.ts +13 -5
  14. package/dist/types/subscribe.d.ts +4 -5
  15. package/dist/types.d.ts +10 -8
  16. package/dist/utils/createMicrotaskScheduler.d.ts +2 -1
  17. package/dist/vanilla/createBaseStore.d.ts +2 -2
  18. package/dist/vanilla/createQueryStore.d.ts +7 -13
  19. package/dist/vanilla/index.js +1 -1
  20. package/dist/vanilla/index.mjs +1 -1
  21. package/dist/vanilla/internal/derivedStore/deriveProxy.d.ts +2 -2
  22. package/dist/vanilla/internal/queryStore/queryParams.d.ts +17 -0
  23. package/dist/vanilla/internal/runtime.d.ts +0 -1
  24. package/dist/vanilla/internal/types/internalSubscribeTypes.d.ts +15 -0
  25. package/dist/vanilla/queryStore/classes/SubscriptionManager.d.ts +3 -31
  26. package/dist/vanilla/queryStore/queryKey.d.ts +9 -2
  27. package/dist/vanilla/queryStore/queryParam.d.ts +36 -0
  28. package/dist/vanilla/queryStore/types.d.ts +10 -52
  29. package/dist/{internal/derivedStore → vanilla/store}/cascadeScheduler.d.ts +12 -6
  30. package/dist/vanilla/types/subscribe.d.ts +4 -5
  31. package/dist/vanilla/types.d.ts +10 -8
  32. package/dist/vanilla/utils/createMicrotaskScheduler.d.ts +2 -1
  33. package/dist/web/chrome.js +1 -1
  34. package/dist/web/chrome.mjs +1 -1
  35. package/dist/web/chunk-FENSEQ3V.mjs +1 -0
  36. package/dist/web/chunk-FPYZVFBM.mjs +1 -0
  37. package/dist/web/chunk-PLDNKWGX.mjs +1 -0
  38. package/dist/web/index.js +1 -1
  39. package/dist/web/index.mjs +1 -1
  40. package/dist/web/internal/runtime.js +1 -1
  41. package/dist/web/internal/runtime.mjs +1 -1
  42. package/package.json +1 -1
  43. package/dist/internal/signal.d.ts +0 -12
  44. package/dist/queryStore/signalTypes.d.ts +0 -14
  45. package/dist/vanilla/internal/signal.d.ts +0 -11
  46. package/dist/vanilla/queryStore/signalTypes.d.ts +0 -13
  47. package/dist/web/chunk-QJLWBD7M.mjs +0 -1
  48. package/dist/web/chunk-V4LHP7LR.mjs +0 -1
@@ -2,6 +2,9 @@ import { defaultRetryDelay } from './internal/runtime';
2
2
  import type { QueryStoreConfig, QueryStoreState } from './queryStore/types';
3
3
  import type { BaseStoreOptions, OptionallyPersistedStore, PersistedStore, StateCreator, Store } from './types';
4
4
  export { defaultRetryDelay };
5
+ export { getQueryKey, parseQueryKey } from './queryStore/queryKey';
6
+ export { queryParam } from './queryStore/queryParam';
7
+ export type { QueryParam, QueryParamConfig, QueryParamKey, ReactiveParam } from './queryStore/queryParam';
5
8
  /**
6
9
  * Creates a persisted, query-enabled store with data fetching capabilities (sync storage).
7
10
  *
@@ -10,7 +13,7 @@ export { defaultRetryDelay };
10
13
  * @template TData - The transformed data type, if applicable (defaults to `TQueryFnData`)
11
14
  * @template PersistedState - The persisted state type, if a stricter type than `Partial<CustomState>` is desired
12
15
  */
13
- export declare function createQueryStore<TQueryFnData, TParams extends Record<string, unknown> = Record<string, never>, TData = TQueryFnData, PersistedState extends Partial<QueryStoreState<TData, TParams>> = Partial<QueryStoreState<TData, TParams>>, PersistReturn extends void = void>(config: QueryStoreConfig<TQueryFnData, TParams, TData>, options: BaseStoreOptions<QueryStoreState<TData, TParams>, PersistedState, PersistReturn>): PersistedStore<QueryStoreState<TData, TParams>, PersistedState, PersistReturn, false>;
16
+ export declare function createQueryStore<TQueryFnData, TParams extends Record<string, unknown> = Record<string, never>, TData = TQueryFnData, PersistedState extends Partial<QueryStoreState<TData, TParams>> = Partial<QueryStoreState<TData, TParams>>, PersistReturn extends void = void>(config: QueryStoreConfig<TQueryFnData, TParams, TData>, options: BaseStoreOptions<QueryStoreState<TData, TParams>, PersistedState, PersistReturn>): PersistedStore<QueryStoreState<TData, TParams>, PersistedState, PersistReturn>;
14
17
  /**
15
18
  * Creates a persisted, query-enabled store with data fetching capabilities (async storage).
16
19
  *
@@ -19,7 +22,7 @@ export declare function createQueryStore<TQueryFnData, TParams extends Record<st
19
22
  * @template TData - The transformed data type, if applicable (defaults to `TQueryFnData`)
20
23
  * @template PersistedState - The persisted state type, if a stricter type than `Partial<CustomState>` is desired
21
24
  */
22
- export declare function createQueryStore<TQueryFnData, TParams extends Record<string, unknown> = Record<string, never>, TData = TQueryFnData, PersistedState extends Partial<QueryStoreState<TData, TParams>> = Partial<QueryStoreState<TData, TParams>>, PersistReturn extends Promise<void> = Promise<void>>(config: QueryStoreConfig<TQueryFnData, TParams, TData>, options: BaseStoreOptions<QueryStoreState<TData, TParams>, PersistedState, PersistReturn>): PersistedStore<QueryStoreState<TData, TParams>, PersistedState, PersistReturn, false>;
25
+ export declare function createQueryStore<TQueryFnData, TParams extends Record<string, unknown> = Record<string, never>, TData = TQueryFnData, PersistedState extends Partial<QueryStoreState<TData, TParams>> = Partial<QueryStoreState<TData, TParams>>, PersistReturn extends Promise<void> = Promise<void>>(config: QueryStoreConfig<TQueryFnData, TParams, TData>, options: BaseStoreOptions<QueryStoreState<TData, TParams>, PersistedState, PersistReturn>): PersistedStore<QueryStoreState<TData, TParams>, PersistedState, PersistReturn>;
23
26
  /**
24
27
  * Creates a persisted, query-enabled store with data fetching capabilities (sync storage).
25
28
  *
@@ -29,7 +32,7 @@ export declare function createQueryStore<TQueryFnData, TParams extends Record<st
29
32
  * @template TData - The transformed data type, if applicable (defaults to `TQueryFnData`)
30
33
  * @template PersistedState - The persisted state type, if a stricter type than `Partial<CustomState>` is desired
31
34
  */
32
- export declare function createQueryStore<TQueryFnData, TParams extends Record<string, unknown> = Record<string, never>, CustomState = unknown, TData = TQueryFnData, PersistedState extends Partial<QueryStoreState<TData, TParams, CustomState>> = Partial<QueryStoreState<TData, TParams, CustomState>>, PersistReturn extends void = void>(config: QueryStoreConfig<TQueryFnData, TParams, TData, CustomState>, stateCreator: StateCreator<QueryStoreState<TData, TParams, CustomState>, CustomState>, options: BaseStoreOptions<QueryStoreState<TData, TParams, CustomState>, PersistedState, PersistReturn>): PersistedStore<QueryStoreState<TData, TParams, CustomState>, PersistedState, PersistReturn, false>;
35
+ export declare function createQueryStore<TQueryFnData, TParams extends Record<string, unknown> = Record<string, never>, CustomState = unknown, TData = TQueryFnData, PersistedState extends Partial<QueryStoreState<TData, TParams, CustomState>> = Partial<QueryStoreState<TData, TParams, CustomState>>, PersistReturn extends void = void>(config: QueryStoreConfig<TQueryFnData, TParams, TData, CustomState>, stateCreator: StateCreator<QueryStoreState<TData, TParams, CustomState>, CustomState>, options: BaseStoreOptions<QueryStoreState<TData, TParams, CustomState>, PersistedState, PersistReturn>): PersistedStore<QueryStoreState<TData, TParams, CustomState>, PersistedState, PersistReturn>;
33
36
  /**
34
37
  * Creates a persisted, query-enabled store with data fetching capabilities (async storage).
35
38
  *
@@ -39,7 +42,7 @@ export declare function createQueryStore<TQueryFnData, TParams extends Record<st
39
42
  * @template TData - The transformed data type, if applicable (defaults to `TQueryFnData`)
40
43
  * @template PersistedState - The persisted state type, if a stricter type than `Partial<CustomState>` is desired
41
44
  */
42
- export declare function createQueryStore<TQueryFnData, TParams extends Record<string, unknown> = Record<string, never>, CustomState = unknown, TData = TQueryFnData, PersistedState extends Partial<QueryStoreState<TData, TParams, CustomState>> = Partial<QueryStoreState<TData, TParams, CustomState>>, PersistReturn extends Promise<void> = Promise<void>>(config: QueryStoreConfig<TQueryFnData, TParams, TData, CustomState>, stateCreator: StateCreator<QueryStoreState<TData, TParams, CustomState>, CustomState>, options: BaseStoreOptions<QueryStoreState<TData, TParams, CustomState>, PersistedState, PersistReturn>): PersistedStore<QueryStoreState<TData, TParams, CustomState>, PersistedState, PersistReturn, false>;
45
+ export declare function createQueryStore<TQueryFnData, TParams extends Record<string, unknown> = Record<string, never>, CustomState = unknown, TData = TQueryFnData, PersistedState extends Partial<QueryStoreState<TData, TParams, CustomState>> = Partial<QueryStoreState<TData, TParams, CustomState>>, PersistReturn extends Promise<void> = Promise<void>>(config: QueryStoreConfig<TQueryFnData, TParams, TData, CustomState>, stateCreator: StateCreator<QueryStoreState<TData, TParams, CustomState>, CustomState>, options: BaseStoreOptions<QueryStoreState<TData, TParams, CustomState>, PersistedState, PersistReturn>): PersistedStore<QueryStoreState<TData, TParams, CustomState>, PersistedState, PersistReturn>;
43
46
  /**
44
47
  * Creates a query-enabled store with data fetching capabilities.
45
48
  *
@@ -105,12 +108,3 @@ export declare function createQueryStore<TQueryFnData, TParams extends Record<st
105
108
  * @template PersistedState - The persisted state type, if a stricter type than `Partial<CustomState>` is desired
106
109
  */
107
110
  export declare function createQueryStore<TQueryFnData, TParams extends Record<string, unknown> = Record<string, never>, TData = TQueryFnData, PersistedState extends Partial<QueryStoreState<TData, TParams>> = Partial<QueryStoreState<TData, TParams>>, PersistReturn extends Promise<void> = Promise<void>>(config: QueryStoreConfig<TQueryFnData, TParams, TData>, options: BaseStoreOptions<QueryStoreState<TData, TParams>, PersistedState, PersistReturn> | undefined): OptionallyPersistedStore<QueryStoreState<TData, TParams>, PersistedState, PersistReturn>;
108
- /**
109
- * Generates a deterministic query store `queryKey` from the given parameters,
110
- * consistent with internally generated keys.
111
- */
112
- export declare function getQueryKey<TParams extends Record<string, unknown>>(params: TParams): string;
113
- /**
114
- * Parses a query store `queryKey` into the corresponding parameters.
115
- */
116
- export declare function parseQueryKey<TParams extends Record<string, unknown>>(queryKey: string): TParams;
@@ -1 +1 @@
1
- var e=require("../web/internal/runtime.js");function t(e,t,r,n){return e}Object.defineProperty(exports,"QueryStatuses",{enumerable:!0,get:function(){return e.QueryStatuses}}),Object.defineProperty(exports,"StoresError",{enumerable:!0,get:function(){return e.StoresError}}),Object.defineProperty(exports,"applyStateUpdate",{enumerable:!0,get:function(){return e.applyStateUpdate}}),Object.defineProperty(exports,"configureStores",{enumerable:!0,get:function(){return e.configureStores}}),Object.defineProperty(exports,"createStoreActions",{enumerable:!0,get:function(){return e.createStoreActions}}),Object.defineProperty(exports,"deepEqual",{enumerable:!0,get:function(){return e.deepEqual}}),Object.defineProperty(exports,"defaultRetryDelay",{enumerable:!0,get:function(){return e.defaultRetryDelay}}),Object.defineProperty(exports,"destroyStore",{enumerable:!0,get:function(){return e.destroyStore}}),Object.defineProperty(exports,"destroyStores",{enumerable:!0,get:function(){return e.destroyStores}}),Object.defineProperty(exports,"getStoreName",{enumerable:!0,get:function(){return e.getStoreName}}),Object.defineProperty(exports,"hasGetSnapshot",{enumerable:!0,get:function(){return e.hasGetSnapshot}}),Object.defineProperty(exports,"identity",{enumerable:!0,get:function(){return e.identity}}),Object.defineProperty(exports,"isDerivedStore",{enumerable:!0,get:function(){return e.isDerivedStore}}),Object.defineProperty(exports,"isPersistedStore",{enumerable:!0,get:function(){return e.isPersistedStore}}),Object.defineProperty(exports,"isQueryStore",{enumerable:!0,get:function(){return e.isQueryStore}}),Object.defineProperty(exports,"isVirtualStore",{enumerable:!0,get:function(){return e.isVirtualStore}}),Object.defineProperty(exports,"nullObject",{enumerable:!0,get:function(){return e.nullObject}}),Object.defineProperty(exports,"replacer",{enumerable:!0,get:function(){return e.replacer}}),Object.defineProperty(exports,"reviver",{enumerable:!0,get:function(){return e.reviver}}),Object.defineProperty(exports,"shallowEqual",{enumerable:!0,get:function(){return e.shallowEqual}}),Object.defineProperty(exports,"time",{enumerable:!0,get:function(){return e.time}}),exports.createBaseStore=function(r,n){const o=e.baseStore(r,n);return t(o,o.getState,o.getInitialState)},exports.createDerivedStore=function(r,n=Object.is){const o=e.derivedStore(r,n);return t(o,o.getSnapshot)},exports.createQueryStore=function(r,n,o){const u=e.queryStore(r,n,o);return t(u,u.getState,u.getInitialState)},exports.createVirtualStore=function(r,n,o){const u=e.virtualStore(r,n,o);return t(u,u.getState,u.getInitialState)},exports.getQueryKey=function(t){return e.getQueryKey(t)},exports.parseQueryKey=function(t){return e.parseQueryKey(t)};
1
+ var e=require("../web/internal/runtime.js");function t(e,t,r,n){return e}process.env.NODE_ENV,process.env.NODE_ENV;var r=Object.freeze(Object.create(null));function n(e){return"object"!=typeof e||null===e?e:Object.keys(e).sort().reduce((t,r)=>{const o=e[r];return t[r]=function(e){if("object"!=typeof e||null===e)return!1;const t=Object.getPrototypeOf(e);return null===t||t===Object.prototype}(o)?n(o):o,t},Object.create(r))}var o=Symbol("stores.queryParamConfig");Object.defineProperty(exports,"QueryStatuses",{enumerable:!0,get:function(){return e.QueryStatuses}}),Object.defineProperty(exports,"StoresError",{enumerable:!0,get:function(){return e.StoresError}}),Object.defineProperty(exports,"applyStateUpdate",{enumerable:!0,get:function(){return e.applyStateUpdate}}),Object.defineProperty(exports,"configureStores",{enumerable:!0,get:function(){return e.configureStores}}),Object.defineProperty(exports,"createStoreActions",{enumerable:!0,get:function(){return e.createStoreActions}}),Object.defineProperty(exports,"deepEqual",{enumerable:!0,get:function(){return e.deepEqual}}),Object.defineProperty(exports,"defaultRetryDelay",{enumerable:!0,get:function(){return e.defaultRetryDelay}}),Object.defineProperty(exports,"destroyStore",{enumerable:!0,get:function(){return e.destroyStore}}),Object.defineProperty(exports,"destroyStores",{enumerable:!0,get:function(){return e.destroyStores}}),Object.defineProperty(exports,"getStoreName",{enumerable:!0,get:function(){return e.getStoreName}}),Object.defineProperty(exports,"hasGetSnapshot",{enumerable:!0,get:function(){return e.hasGetSnapshot}}),Object.defineProperty(exports,"identity",{enumerable:!0,get:function(){return e.identity}}),Object.defineProperty(exports,"isDerivedStore",{enumerable:!0,get:function(){return e.isDerivedStore}}),Object.defineProperty(exports,"isPersistedStore",{enumerable:!0,get:function(){return e.isPersistedStore}}),Object.defineProperty(exports,"isQueryStore",{enumerable:!0,get:function(){return e.isQueryStore}}),Object.defineProperty(exports,"isVirtualStore",{enumerable:!0,get:function(){return e.isVirtualStore}}),Object.defineProperty(exports,"nullObject",{enumerable:!0,get:function(){return e.nullObject}}),Object.defineProperty(exports,"replacer",{enumerable:!0,get:function(){return e.replacer}}),Object.defineProperty(exports,"reviver",{enumerable:!0,get:function(){return e.reviver}}),Object.defineProperty(exports,"shallowEqual",{enumerable:!0,get:function(){return e.shallowEqual}}),Object.defineProperty(exports,"time",{enumerable:!0,get:function(){return e.time}}),exports.createBaseStore=function(r,n){const o=e.baseStore(r,n);return t(o,o.getState,o.getInitialState)},exports.createDerivedStore=function(r,n=Object.is){const o=e.derivedStore(r,n);return t(o,o.getSnapshot)},exports.createQueryStore=function(r,n,o){const u=e.queryStore(r,n,o);return t(u,u.getState,u.getInitialState)},exports.createVirtualStore=function(r,n,o){const u=e.virtualStore(r,n,o);return t(u,u.getState,u.getInitialState)},exports.getQueryKey=function(e){return JSON.stringify(n(e))},exports.parseQueryKey=function(e){return JSON.parse(e)},exports.queryParam=function(e,t){return{[o]:!0,key:t.key,value:e}};
@@ -1 +1 @@
1
- import{baseStore as t,derivedStore as e,queryStore as r,getQueryKey as n,parseQueryKey as o,virtualStore as i}from"../web/internal/runtime.mjs";export{QueryStatuses,StoresError,applyStateUpdate,configureStores,createStoreActions,deepEqual,defaultRetryDelay,destroyStore,destroyStores,getStoreName,hasGetSnapshot,identity,isDerivedStore,isPersistedStore,isQueryStore,isVirtualStore,nullObject,replacer,reviver,shallowEqual,time}from"../web/internal/runtime.mjs";function a(t,e,r,n){return t}function s(e,r){const n=t(e,r);return a(n,n.getState,n.getInitialState)}function u(t,r=Object.is){const n=e(t,r);return a(n,n.getSnapshot)}function S(t,e,n){const o=r(t,e,n);return a(o,o.getState,o.getInitialState)}function c(t){return n(t)}function l(t){return o(t)}function y(t,e,r){const n=i(t,e,r);return a(n,n.getState,n.getInitialState)}export{s as createBaseStore,u as createDerivedStore,S as createQueryStore,y as createVirtualStore,c as getQueryKey,l as parseQueryKey};
1
+ import{baseStore as t,derivedStore as e,queryStore as r,virtualStore as n}from"../web/internal/runtime.mjs";export{QueryStatuses,StoresError,applyStateUpdate,configureStores,createStoreActions,deepEqual,defaultRetryDelay,destroyStore,destroyStores,getStoreName,hasGetSnapshot,identity,isDerivedStore,isPersistedStore,isQueryStore,isVirtualStore,nullObject,replacer,reviver,shallowEqual,time}from"../web/internal/runtime.mjs";function o(t,e,r,n){return t}function u(e,r){const n=t(e,r);return o(n,n.getState,n.getInitialState)}function i(t,r=Object.is){const n=e(t,r);return o(n,n.getSnapshot)}process.env.NODE_ENV,process.env.NODE_ENV;var s=Object.freeze(Object.create(null));function a(t){return JSON.stringify(l(t))}function c(t){return JSON.parse(t)}function l(t){return"object"!=typeof t||null===t?t:Object.keys(t).sort().reduce((e,r)=>{const n=t[r];return e[r]=function(t){if("object"!=typeof t||null===t)return!1;const e=Object.getPrototypeOf(t);return null===e||e===Object.prototype}(n)?l(n):n,e},Object.create(s))}var S=Symbol("stores.queryParamConfig");function f(t,e){return{[S]:!0,key:e.key,value:t}}function p(t,e,n){const u=r(t,e,n);return o(u,u.getState,u.getInitialState)}function y(t,e,r){const u=n(t,e,r);return o(u,u.getState,u.getInitialState)}export{u as createBaseStore,i as createDerivedStore,p as createQueryStore,y as createVirtualStore,a as getQueryKey,c as parseQueryKey,f as queryParam};
@@ -1,11 +1,11 @@
1
- import { BaseStore } from '../../types';
1
+ import type { StoreApi } from '../../store/types';
2
2
  import { TrackPathFn } from './pathFinder';
3
3
  /**
4
4
  * Gets or creates a lightweight tracking proxy that records path access and store
5
5
  * method invocations via proxy traps. Used to auto-generate selectors that point
6
6
  * to either the accessed path or the value returned by an invoked store method.
7
7
  */
8
- export declare function getOrCreateProxy<S>(store: BaseStore<S>, rootProxyCache: WeakMap<object, unknown>, trackPath: TrackPathFn): S;
8
+ export declare function getOrCreateProxy<S>(store: StoreApi<S>, rootProxyCache: WeakMap<object, unknown>, trackPath: TrackPathFn): S;
9
9
  /**
10
10
  * Strips tracking proxies from published values to ensure
11
11
  * proxies remain confined to internal tracking contexts.
@@ -0,0 +1,17 @@
1
+ import type { QueryParam, ReactiveParam } from '../../queryStore/queryParam';
2
+ import type { StoreApi } from '../../store/types';
3
+ import type { InternalUnsubscribeFn } from '../types/internalSubscribeTypes';
4
+ export type TrackedValue<T> = {
5
+ readonly initialValue: T;
6
+ subscribe(listener: (value: T) => void): InternalUnsubscribeFn;
7
+ };
8
+ export type QueryParams<TParams extends Record<string, unknown>> = {
9
+ buildKey(params?: TParams): string;
10
+ complete(params: Partial<TParams> | undefined): TParams;
11
+ get(): TParams;
12
+ subscribe(onChange: (key: keyof TParams, oldValue: unknown, newValue: unknown) => void): InternalUnsubscribeFn;
13
+ };
14
+ export declare function createQueryParams<TParams extends Record<string, unknown>, State>(params: {
15
+ [K in keyof TParams]: QueryParam<TParams[K], State>;
16
+ } | undefined, store: StoreApi<State>, requiredKeys: (keyof TParams)[]): QueryParams<TParams>;
17
+ export declare function trackQueryValue<T, State>(getValue: ReactiveParam<T, State>, ownerStore: StoreApi<State>): TrackedValue<T>;
@@ -2,7 +2,6 @@ export { configureStores } from './config';
2
2
  export { StoresError } from './errors';
3
3
  export { QueryStatuses } from '../queryStore/types';
4
4
  export { defaultRetryDelay } from './queryStore/queryStoreDefaults';
5
- export { getQueryKey, parseQueryKey } from '../queryStore/queryKey';
6
5
  export { applyStateUpdate } from '../store/stateUpdate';
7
6
  export { replacer, reviver } from '../utils/serialization';
8
7
  export { destroyStore, destroyStores, getStoreName, hasGetSnapshot, isDerivedStore, isPersistedStore, isQueryStore, isVirtualStore, } from './storeUtils';
@@ -0,0 +1,15 @@
1
+ import type { Listener, ListenerArgs, Selector, SubscribeOptions } from '../../types/subscribe';
2
+ export type InternalSubscribeOptions<Selected> = SubscribeOptions<Selected> & {
3
+ isCascadeParticipant?: boolean;
4
+ };
5
+ export type InternalSelectorArgs<S, Selected> = [
6
+ selector: Selector<S, Selected>,
7
+ listener: Listener<Selected>,
8
+ options?: InternalSubscribeOptions<Selected>
9
+ ];
10
+ export type InternalSubscribeArgs<S, Selected = unknown> = ListenerArgs<S> | InternalSelectorArgs<S, Selected>;
11
+ export type InternalUnsubscribeFn = (skipAbortFetch?: boolean) => void;
12
+ export type InternalSubscribeOverloads<S> = {
13
+ (...args: ListenerArgs<S>): InternalUnsubscribeFn;
14
+ <Selected>(...args: InternalSelectorArgs<S, Selected>): InternalUnsubscribeFn;
15
+ };
@@ -1,27 +1,13 @@
1
- /**
2
- * Initialization config for the SubscriptionManager.
3
- */
4
- interface SubscriptionManagerConfig {
5
- /**
6
- * The store's `disableAutoRefetching` option, passed through from the query config.
7
- */
8
- disableAutoRefetching: boolean;
9
- /**
10
- * The initial enabled state for the SubscriptionManager.
11
- */
12
- initialEnabled: boolean;
13
- }
14
1
  /**
15
2
  * Lazy initialization config for subscription handlers.
16
3
  */
17
4
  interface SubscriptionHandlerConfig {
18
5
  /**
19
6
  * Callback executed when a subscription is added.
20
- * @param enabled - The current enabled state
21
7
  * @param isFirstSubscription - Whether this is the first subscription
22
8
  * @param shouldThrottle - Whether to throttle the fetch
23
9
  */
24
- onSubscribe: (enabled: boolean, isFirstSubscription: boolean, shouldThrottle: boolean) => void;
10
+ onSubscribe: (isFirstSubscription: boolean, shouldThrottle: boolean) => void;
25
11
  /** Callback executed when the last remaining subscription is removed. */
26
12
  onLastUnsubscribe: (willResubscribe?: boolean) => void;
27
13
  }
@@ -30,7 +16,6 @@ interface SubscriptionHandlerConfig {
30
16
  */
31
17
  export declare class SubscriptionManager {
32
18
  private count;
33
- private enabled;
34
19
  private lastSubscriptionTime;
35
20
  private readonly fetchThrottleMs;
36
21
  private onSubscribe;
@@ -38,25 +23,12 @@ export declare class SubscriptionManager {
38
23
  /**
39
24
  * Creates a new SubscriptionManager instance.
40
25
  */
41
- constructor({ disableAutoRefetching, initialEnabled }: SubscriptionManagerConfig);
26
+ constructor(disableAutoRefetching: boolean);
42
27
  /**
43
28
  * Initializes subscription event handlers.
44
29
  */
45
30
  init({ onSubscribe, onLastUnsubscribe }: SubscriptionHandlerConfig): void;
46
- /**
47
- * Returns the current subscription state.
48
- * @returns An object containing `enabled`, `lastSubscriptionTime`, and `subscriptionCount`
49
- */
50
- get(): {
51
- enabled: boolean;
52
- lastSubscriptionTime: number | null;
53
- subscriptionCount: number;
54
- };
55
- /**
56
- * Updates the enabled state for queries.
57
- * @param enabled - The new enabled state
58
- */
59
- setEnabled(enabled: boolean): void;
31
+ hasSubscribers(): boolean;
60
32
  /**
61
33
  * Adds a new subscription and triggers relevant lifecycle callbacks.
62
34
  * @returns A cleanup function that removes the subscription when called
@@ -1,2 +1,9 @@
1
- export declare function getQueryKey<TParams extends Record<string, unknown>>(params: TParams): string;
2
- export declare function parseQueryKey<TParams extends Record<string, unknown>>(queryKey: string): TParams;
1
+ /**
2
+ * Generates a deterministic query store `queryKey` from the given
3
+ * key payload, consistent with internally generated keys.
4
+ */
5
+ export declare function getQueryKey<TKeyPayload extends Record<string, unknown>>(keyPayload: TKeyPayload): string;
6
+ /**
7
+ * Parses a query store `queryKey` into the key payload it encodes.
8
+ */
9
+ export declare function parseQueryKey<TKeyPayload extends Record<string, unknown> = Record<string, unknown>>(queryKey: string): TKeyPayload;
@@ -0,0 +1,36 @@
1
+ import type { StoreApi } from '../store/types';
2
+ import type { DeriveGetter } from '../types';
3
+ import type { NonFunction } from '../types/functions';
4
+ declare const QUERY_PARAM_CONFIG: unique symbol;
5
+ /**
6
+ * Selects how a query parameter participates in the query key.
7
+ */
8
+ export type QueryParamKey<T> = false | ((value: T) => unknown);
9
+ /**
10
+ * A query value derived from stores via `$`.
11
+ */
12
+ export type ReactiveParam<T, State> = ($: DeriveGetter, store: StoreApi<State>) => T;
13
+ /**
14
+ * Query parameter wrapper for values whose fetcher value and key value differ.
15
+ */
16
+ export type QueryParamConfig<T, State> = {
17
+ readonly [QUERY_PARAM_CONFIG]: true;
18
+ readonly key: QueryParamKey<T>;
19
+ readonly value: NonFunction<T> | ReactiveParam<T, State>;
20
+ };
21
+ /**
22
+ * A direct, reactive, or key-configured query parameter.
23
+ */
24
+ export type QueryParam<T, State> = NonFunction<T> | ReactiveParam<T, State> | QueryParamConfig<T, State>;
25
+ /**
26
+ * Wraps a query parameter when its full fetcher value should be excluded
27
+ * from the query key or represented by a smaller key value.
28
+ */
29
+ export declare function queryParam<T, State>(value: NonFunction<T> | ReactiveParam<T, State>, options: {
30
+ key: QueryParamKey<T>;
31
+ }): QueryParamConfig<T, State>;
32
+ /**
33
+ * Checks if a `QueryParam` value is a custom `queryParam(...)` config.
34
+ */
35
+ export declare function isQueryParamConfig<T, State>(value: QueryParam<T, State>): value is QueryParamConfig<T, State>;
36
+ export {};
@@ -1,6 +1,6 @@
1
- import type { AttachValue, SignalFunction } from './signalTypes';
2
- import type { StoreApi } from '../store/types';
1
+ import type { QueryParam, ReactiveParam } from './queryParam';
3
2
  import type { DebounceOptions, SetPartial, Store } from '../types';
3
+ export type { QueryParam, QueryParamConfig, QueryParamKey, ReactiveParam } from './queryParam';
4
4
  /**
5
5
  * Helper type that represents the store returned by `createQueryStore()`.
6
6
  */
@@ -92,7 +92,7 @@ export type QueryStoreConfig<TQueryFnData, TParams extends Record<string, unknow
92
92
  * When `false`, the store will not automatically fetch data until explicitly enabled.
93
93
  * @default true
94
94
  */
95
- enabled?: boolean | ReactiveParam<boolean, TParams, S, TData>;
95
+ enabled?: boolean | ReactiveParam<boolean, S>;
96
96
  /**
97
97
  * When `true`, the store's `getData` method will always return existing data from the cache if it exists,
98
98
  * regardless of whether the cached data is expired, until the data is pruned following a successful refetch.
@@ -116,8 +116,7 @@ export type QueryStoreConfig<TQueryFnData, TParams extends Record<string, unknow
116
116
  */
117
117
  paramChangeThrottle?: false | number | DebounceOptions;
118
118
  /**
119
- * Parameters to be passed to the fetcher, defined as either direct values or `ReactiveParam` functions.
120
- * Dynamic parameters using `AttachValue` will cause the store to refetch when their values change.
119
+ * Reactive or static parameters to be passed to the fetcher.
121
120
  */
122
121
  params?: QueryStoreParams<TParams, TData, S, CustomState>;
123
122
  /**
@@ -135,7 +134,7 @@ export type QueryStoreConfig<TQueryFnData, TParams extends Record<string, unknow
135
134
  * After becoming stale, the store may automatically refetch data in the background if there are active subscribers.
136
135
  * @default time.minutes(2)
137
136
  */
138
- staleTime?: number | ReactiveParam<number, TParams, S, TData>;
137
+ staleTime?: number | ReactiveParam<number, S>;
139
138
  /**
140
139
  * Suppresses warnings in the event a `staleTime` under the minimum is desired.
141
140
  * @default false
@@ -213,11 +212,11 @@ export type QueryStoreInternalState<TData, TParams extends Record<string, unknow
213
212
  */
214
213
  lastFetchedAt: number | null;
215
214
  /**
216
- * A cache of fetched data and metadata, keyed by query stringified params.
215
+ * A cache of fetched data and metadata, keyed by generated query keys.
217
216
  */
218
217
  queryCache: Record<string, CacheEntry<TData> | undefined>;
219
218
  /**
220
- * The current query key, which is a string representation of the current query parameter values.
219
+ * The current query key, generated deterministically from store parameters.
221
220
  */
222
221
  queryKey: string;
223
222
  /**
@@ -275,7 +274,8 @@ export type FetchOptions = {
275
274
  * `queryKey` (which determines where `getData()` points to).
276
275
  *
277
276
  * ---
278
- * Defaults to `true` unless `skipStoreUpdates: true` is specified, in which case the default is `false`.
277
+ * Manual fetches default to `false`. Internal query-store fetches default to the store's `keepPreviousData`
278
+ * behavior. When `skipStoreUpdates` is set, the query key is never updated.
279
279
  */
280
280
  updateQueryKey?: boolean;
281
281
  };
@@ -334,49 +334,7 @@ export type CacheEntry<T> = {
334
334
  * Internal helper type for the config’s params clause.
335
335
  */
336
336
  export type QueryStoreParams<TParams extends Record<string, unknown>, TData, S extends QueryStoreState<TData, TParams, CustomState>, CustomState = unknown> = [TParams] extends [Record<string, never>] ? undefined : {
337
- [K in keyof TParams]: ReactiveParam<TParams[K], TParams, S, TData>;
338
- };
339
- /**
340
- * Represents a parameter that can be provided directly or defined via a reactive `AttachValue`.
341
- * A parameter can be:
342
- * - A static value (e.g. `string`, `number`).
343
- * - A function that returns an `AttachValue<T>` when given a `SignalFunction`.
344
- */
345
- export type ReactiveParam<T, TParams extends Record<string, unknown>, S extends QueryStoreState<TData, TParams>, TData> = T | (($: SignalFunction, store: StoreApi<S>) => AttachValue<T>);
346
- export type AttachValueParams<TParams extends Record<string, unknown>> = Partial<Record<keyof TParams, AttachValue<TParams[Extract<keyof TParams, string>]>>>;
347
- /**
348
- * The result of resolving reactive and static parameter values.
349
- */
350
- export type ResolvedParamsResult<TParams extends Record<string, unknown>> = {
351
- /**
352
- * Reactive parameter values wrapped in `AttachValue`, which trigger refetches when they change.
353
- */
354
- attachVals: AttachValueParams<TParams>;
355
- /**
356
- * Direct, non-reactive values resolved from the initial configuration.
357
- */
358
- directValues: Partial<TParams>;
359
- /**
360
- * Fully resolved parameters, merging both direct and reactive values.
361
- */
362
- resolvedParams: TParams;
363
- };
364
- /**
365
- * The result of resolving the `enabled` option.
366
- */
367
- export type ResolvedEnabledResult = {
368
- /**
369
- * The reactive enabled state, if provided as a function returning an AttachValue.
370
- */
371
- enabledAttachVal: AttachValue<boolean> | null;
372
- /**
373
- * The static enabled state, if provided as a direct boolean value.
374
- */
375
- enabledDirectValue: boolean | null;
376
- /**
377
- * The final enabled state, derived from either the reactive or static value.
378
- */
379
- resolvedEnabled: boolean;
337
+ [K in keyof TParams]: QueryParam<TParams[K], S>;
380
338
  };
381
339
  /**
382
340
  * The keys that make up the internal state of the store.
@@ -4,10 +4,9 @@
4
4
  * - Coalesces derivations into a single microtask.
5
5
  * - Tasks run once at their maximum rank via a ranked dirty queue.
6
6
  * - Doesn't retain snapshots or dependency graphs.
7
- * - Component listeners get notified after all derivations have settled.
7
+ * - Deferred listeners run after all derivations have settled.
8
8
  */
9
9
  type Rank = number;
10
- type StoreId = string;
11
10
  type Task = () => void;
12
11
  export declare function isCascadeActive(): boolean;
13
12
  /**
@@ -19,13 +18,20 @@ export declare function getCurrentDeriveRank(): Rank | null;
19
18
  */
20
19
  export declare function activateCascade(): void;
21
20
  /**
22
- * Enlist one per-store component flush (idempotent per store).
21
+ * Synchronously drains the active cascade.
23
22
  */
24
- export declare function joinCascade(storeId: StoreId, task: Task): void;
23
+ export declare function flushCascade(): void;
24
+ /**
25
+ * Synchronously settles derivations without delivering deferred listeners.
26
+ */
27
+ export declare function settleCascadeDerivations(): void;
28
+ /**
29
+ * Enlist a deferred listener flush task.
30
+ */
31
+ export declare function joinCascade(task: Task): void;
25
32
  /**
26
33
  * Enqueue (or upgrade) a derive task with the given rank.
27
- * If the task is already present, we keep the maximum rank (run later).
34
+ * If the task is already present, its rank is upgraded and it is run later.
28
35
  */
29
36
  export declare function enqueueDerive(task: Task, rank: Rank): void;
30
37
  export {};
31
- //# sourceMappingURL=cascadeScheduler.d.ts.map
@@ -10,7 +10,6 @@ export type SubscribableStore = {
10
10
  export type SubscribeOptions<Selected> = {
11
11
  equalityFn?: EqualityFn<Selected>;
12
12
  fireImmediately?: boolean;
13
- isDerivedStore?: boolean;
14
13
  };
15
14
  export type ListenerArgs<S> = [listener: Listener<S>];
16
15
  export type SelectorArgs<S, Selected> = [
@@ -19,9 +18,9 @@ export type SelectorArgs<S, Selected> = [
19
18
  options?: SubscribeOptions<Selected>
20
19
  ];
21
20
  export type SubscribeArgs<S, Selected = unknown> = ListenerArgs<S> | SelectorArgs<S, Selected>;
22
- export type UnsubscribeFn<Options extends boolean = false> = Options extends true ? (skipAbortFetch?: boolean) => void : () => void;
21
+ export type UnsubscribeFn = () => void;
23
22
  export type SubscribeFn<S, Selected = S> = (...args: SubscribeArgs<S, Selected>) => UnsubscribeFn;
24
- export type SubscribeOverloads<S, ExtraOptions extends boolean = false> = {
25
- (listener: Listener<S>): UnsubscribeFn<ExtraOptions>;
26
- <Selected>(selector: Selector<S, Selected>, listener: Listener<Selected>, options?: SubscribeOptions<Selected>): UnsubscribeFn<ExtraOptions>;
23
+ export type SubscribeOverloads<S> = {
24
+ (listener: Listener<S>): UnsubscribeFn;
25
+ <Selected>(selector: Selector<S, Selected>, listener: Listener<Selected>, options?: SubscribeOptions<Selected>): UnsubscribeFn;
27
26
  };
@@ -14,17 +14,19 @@ export type StateCreator<S, U = S> = StoreStateCreator<S, [], [], U>;
14
14
  export type UseBoundStoreWithEqualityFn<Store extends {
15
15
  getState: () => unknown;
16
16
  }, State = InferStoreState<Store>> = UseStoreCallSignatures<State> & Store;
17
- export type BaseStore<S, ExtraSubscribeOptions extends boolean = false> = UseBoundStoreWithEqualityFn<StoreApi<S>> & {
18
- subscribe: SubscribeOverloads<S, ExtraSubscribeOptions>;
17
+ export type BaseStore<S> = UseBoundStoreWithEqualityFn<StoreApi<S>> & {
18
+ subscribe: SubscribeOverloads<S>;
19
19
  };
20
- export type PersistedStore<S, PersistedState = Partial<S>, PersistReturn extends void | Promise<void> = void | Promise<void>, ExtraSubscribeOptions extends boolean = false> = UseStoreCallSignatures<S> & WithPersist<BaseStore<S, ExtraSubscribeOptions>, PersistedState, PersistReturn>;
21
- export type Store<S, PersistedState extends Partial<S> = never, PersistReturn extends void | Promise<void> = void | Promise<void>, ExtraSubscribeOptions extends boolean = false> = [PersistedState] extends [never] ? BaseStore<S, ExtraSubscribeOptions> : PersistedStore<S, PersistedState, PersistReturn, ExtraSubscribeOptions>;
20
+ export type PersistedStore<S, PersistedState = Partial<S>, PersistReturn extends void | Promise<void> = void | Promise<void>> = UseStoreCallSignatures<S> & WithPersist<BaseStore<S>, PersistedState, PersistReturn>;
21
+ export type Store<S, PersistedState extends Partial<S> = never, PersistReturn extends void | Promise<void> = void | Promise<void>> = [
22
+ PersistedState
23
+ ] extends [never] ? BaseStore<S> : PersistedStore<S, PersistedState, PersistReturn>;
22
24
  /**
23
25
  * Store returned by creators that accept optional persistence options.
24
26
  * `persist` exists only when persistence is configured.
25
27
  */
26
28
  export type OptionallyPersistedStore<S, PersistedState, PersistReturn extends void | Promise<void> = void> = UseStoreCallSignatures<S> & Omit<BaseStore<S>, 'setState'> & {
27
- persist?: PersistedStore<S, PersistedState, PersistReturn, false>['persist'];
29
+ persist?: PersistedStore<S, PersistedState, PersistReturn>['persist'];
28
30
  setState(update: SetPartial<S>, replace?: false): PersistReturn;
29
31
  setState(update: SetFull<S>, replace: true): PersistReturn;
30
32
  };
@@ -51,13 +53,13 @@ export type InferSetStateReturn<Store> = Store extends {
51
53
  */
52
54
  export type InferPersistedState<PersistedStore> = PersistedStore extends Store<infer _, infer PersistedState> ? PersistedState : never;
53
55
  /**
54
- * Reads store state and records the dependencies of a derived computation.
56
+ * Reads store state and records dependencies for tracked computations.
55
57
  * - `$(store, selector, equalityFn?)` depends on the selected state
56
58
  * - `$(store)` depends on accessed state paths
57
59
  */
58
60
  export type DeriveGetter = {
59
- <S extends Store<InferStoreState<S>>>(store: S): InferStoreState<S>;
60
- <S extends Store<InferStoreState<S>>, Selected>(store: S, selector: Selector<InferStoreState<S>, Selected>, equalityFn?: EqualityFn<Selected>): Selected;
61
+ <Store extends StoreApi<InferStoreState<Store>>>(store: Store): InferStoreState<Store>;
62
+ <Store extends StoreApi<InferStoreState<Store>>, Selected>(store: Store, selector: Selector<InferStoreState<Store>, Selected>, equalityFn?: EqualityFn<Selected>): Selected;
61
63
  };
62
64
  export type DerivedStore<S> = WithFlushUpdates<ReadOnlyDerivedStore<BaseStore<S>>>;
63
65
  export type WithFlushUpdates<Store extends StoreApi<unknown>> = Store & {
@@ -10,6 +10,7 @@
10
10
  *
11
11
  * @template TArgs - The argument types of the function to schedule
12
12
  * @param fn - The function to schedule for microtask execution
13
+ * @param enqueue - The queue that should run the scheduled task
13
14
  * @returns A scheduler function with the same signature as the input function
14
15
  *
15
16
  * @example
@@ -24,4 +25,4 @@
24
25
  * // Logs "Updated: 3" once in the next microtask
25
26
  * ```
26
27
  */
27
- export declare function createMicrotaskScheduler<Args extends unknown[]>(fn: (...args: Args) => void): (...args: Args) => void;
28
+ export declare function createMicrotaskScheduler<Args extends unknown[]>(fn: (...args: Args) => void, enqueue?: (task: () => void) => void): (...args: Args) => void;
@@ -1 +1 @@
1
- "use strict";var e=require("./internal/runtime.js"),t=Object.prototype.hasOwnProperty;function r(e,r){return t.call(e,r)}function s(e){if("object"!=typeof e||null===e)return!1;const t=Object.getPrototypeOf(e);return null===t||t===Object.prototype}process.env.NODE_ENV,process.env.NODE_ENV;var n=Object.freeze(Object.create(null));function i(e,t){return t instanceof Map?{__type:"Map",entries:Array.from(t.entries())}:t instanceof Set?{__type:"Set",values:Array.from(t)}:t}function o(e,t){return function(e){return"object"==typeof e&&null!==e&&"__type"in e&&"Map"===e.__type}(t)?new Map(t.entries):function(e){return"object"==typeof e&&null!==e&&"__type"in e&&"Set"===e.__type}(t)?new Set(t.values):t}var a=class{constructor(t){this.async=!0,this.deserializer=h,this.serializer=c,this.area=t?.area??"local",this.storageKeyPrefix=t?.storageKeyPrefix??e.DEFAULT_STORAGE_KEY_PREFIX}async clearAll(){const e=this.ensureStorage();if(!e)return;if(!this.storageKeyPrefix)throw new Error("Cannot clear all storage with empty storageKeyPrefix. This would delete all storage entries.");const t=await this.listPrefixedKeys(e,this.storageKeyPrefix);t.length&&await this.execute(e,r=>e.remove(t,r))}async contains(e){const t=this.ensureStorage();if(!t)return!1;const r=this.toStorageKey(e),s=await this.getFromStorage(t,r);return Object.prototype.hasOwnProperty.call(s,r)}async delete(e){const t=this.ensureStorage();if(!t)return;const r=this.toStorageKey(e);await this.execute(t,e=>t.remove(r,e))}async getAllKeys(){const e=this.ensureStorage();if(!e)return[];const t=await this.getFromStorage(e,null),r=this.storageKeyPrefix;return r?Object.keys(t).filter(e=>e.startsWith(r)).map(e=>e.slice(r.length)):Object.keys(t)}async get(e){const t=this.ensureStorage();if(!t)return;const r=this.toStorageKey(e);return u((await this.getFromStorage(t,r))[r])||void 0}async set(e,t){const r=this.ensureStorage();if(!r)return;const s=this.toStorageKey(e);await this.execute(r,e=>r.set({[s]:t},e))}ensureStorage(){return e=this.area,"undefined"!=typeof chrome&&chrome.storage?chrome.storage[e]??null:null;var e}toStorageKey(e){return this.storageKeyPrefix?`${this.storageKeyPrefix}${e}`:e}async listPrefixedKeys(e,t){const r=await this.getFromStorage(e,null);return Object.keys(r).filter(e=>e.startsWith(t))}async getFromStorage(e,t){return this.invokeWithCallbackSupport(r=>e.get(t,r))}async execute(e,t){await this.invokeWithCallbackSupport(t)}async invokeWithCallbackSupport(e){return new Promise((t,r)=>{let s=!1;function n(e){if(s)return;s=!0;const n="undefined"!=typeof chrome&&chrome.runtime&&chrome.runtime.lastError?new Error(chrome.runtime.lastError.message):null;n?r(n):t(e)}try{const t=e(n);(i=t)&&"object"==typeof i&&"then"in i&&"function"==typeof i.then&&t.then(n).catch(r)}catch(e){r(e)}var i})}};function c(e){return{state:g(e.state),syncMetadata:e.syncMetadata,version:e.version}}function h(e){const t=u(e);if(!t)throw new Error("[ChromeStorageAdapter] Invalid serialized state format");return{state:f(t.state),syncMetadata:t.syncMetadata,version:t.version}}function u(e){if(l(e))return e;if("string"==typeof e)try{const t=JSON.parse(e);if(l(t))return t}catch{}return null}function l(e){return!(!e||"object"!=typeof e)&&Object.prototype.hasOwnProperty.call(e,"state")}function g(e,t=i){if(e instanceof Map||e instanceof Set)return t.call(void 0,"",e);if(!s(e))return e;const r={};for(const[s,n]of Object.entries(e))r[s]=t.call(e,s,n);return r}function f(e,t=o){const r=t.call(void 0,"",e);if(!s(r))return r;const n={};for(const e of Object.entries(r)){const s=e[0],i=e[1];n[s]=t.call(r,s,i)}return n}var y=class{constructor(t){this.injectStorageMetadata=!0,this.registrations=new Map,this.isListening=!1,this.onStorageChanged=async(e,t)=>{if(t===this.area)for(const t of this.registrations){const r=t[0],s=t[1];if(s.destroyed)continue;const n=e[this.toStorageKey(r)];if(n&&void 0!==n.newValue)try{const e=this.parsePersistValue(n.newValue);if(!e||e.syncMetadata?.origin===this.sessionId)continue;const t=e?.syncMetadata,r=this.extractChangedFields(s,e.state,t,n.oldValue);if(!Object.keys(r).length)continue;s.registration.apply({replace:!1,sessionId:t?.origin??"unknown",timestamp:t?.timestamp??Date.now(),values:r})}catch(e){continue}}},t&&"storage"in t?(this.area=t.storage.area,this.storageKeyPrefix=t.storage.storageKeyPrefix):(this.area=t?.area??"local",this.storageKeyPrefix=t?.storageKeyPrefix??e.DEFAULT_STORAGE_KEY_PREFIX),this.sessionId=this.generateSessionId(),this.attachListener()}destroy(){for(const e of this.registrations.values())e.destroyed=!0,e.listeners.clear();this.detachListener()}register(e){this.attachListener();const t={destroyed:!1,hydrated:!0,listeners:new Set,registration:e};return this.setRegistration(e.key,t),{destroy:()=>{t.destroyed=!0,t.listeners.clear(),this.registrations.delete(e.key),this.registrations.size||this.detachListener()},publish:null}}generateSessionId(){return"undefined"!=typeof crypto&&"randomUUID"in crypto?crypto.randomUUID():`${Math.random().toString(36).slice(2)}:${Date.now().toString(36)}`}attachListener(){"undefined"!=typeof chrome&&chrome.storage&&!this.isListening&&(this.isListening=!0,chrome.storage.onChanged.addListener(this.onStorageChanged))}detachListener(){"undefined"!=typeof chrome&&chrome.storage&&this.isListening&&(chrome.storage.onChanged.removeListener(this.onStorageChanged),this.isListening=!1)}extractChangedFields(e,t,s,i){const o=Object.create(n),a=s?.fields;if(a&&Object.keys(a).length>0){let s=!1;for(const n of e.registration.fields)r(a,String(n))&&(o[n]=t[n],s=!0);if(s)return o}const c=this.parsePersistValue(i);for(const r of e.registration.fields){const e=t[r],s=c?.state[r];Object.is(e,s)||(o[r]=e)}return o}setRegistration(e,t){this.registrations.set(e,t)}toStorageKey(e){return this.storageKeyPrefix?`${this.storageKeyPrefix}${e}`:e}parsePersistValue(e){return h(e)}};exports.ChromeExtensionSyncEngine=y,exports.ChromeStorageAdapter=a,exports.createSyncedChromeStorage=function(e){const t=new a(e);return{storage:t,syncEngine:new y({storage:t})}};
1
+ var e=require("./internal/runtime.js"),t=Object.prototype.hasOwnProperty;function r(e,r){return t.call(e,r)}function s(e){if("object"!=typeof e||null===e)return!1;const t=Object.getPrototypeOf(e);return null===t||t===Object.prototype}process.env.NODE_ENV,process.env.NODE_ENV;var n=Object.freeze(Object.create(null));function i(e,t){return t instanceof Map?{__type:"Map",entries:Array.from(t.entries())}:t instanceof Set?{__type:"Set",values:Array.from(t)}:t}function o(e,t){return function(e){return"object"==typeof e&&null!==e&&"__type"in e&&"Map"===e.__type}(t)?new Map(t.entries):function(e){return"object"==typeof e&&null!==e&&"__type"in e&&"Set"===e.__type}(t)?new Set(t.values):t}var a=class{constructor(t){this.async=!0,this.deserializer=h,this.serializer=c,this.area=t?.area??"local",this.storageKeyPrefix=t?.storageKeyPrefix??e.DEFAULT_STORAGE_KEY_PREFIX}async clearAll(){const e=this.ensureStorage();if(!e)return;if(!this.storageKeyPrefix)throw new Error("Cannot clear all storage with empty storageKeyPrefix. This would delete all storage entries.");const t=await this.listPrefixedKeys(e,this.storageKeyPrefix);t.length&&await this.execute(e,r=>e.remove(t,r))}async contains(e){const t=this.ensureStorage();if(!t)return!1;const r=this.toStorageKey(e),s=await this.getFromStorage(t,r);return Object.prototype.hasOwnProperty.call(s,r)}async delete(e){const t=this.ensureStorage();if(!t)return;const r=this.toStorageKey(e);await this.execute(t,e=>t.remove(r,e))}async getAllKeys(){const e=this.ensureStorage();if(!e)return[];const t=await this.getFromStorage(e,null),r=this.storageKeyPrefix;return r?Object.keys(t).filter(e=>e.startsWith(r)).map(e=>e.slice(r.length)):Object.keys(t)}async get(e){const t=this.ensureStorage();if(!t)return;const r=this.toStorageKey(e);return u((await this.getFromStorage(t,r))[r])||void 0}async set(e,t){const r=this.ensureStorage();if(!r)return;const s=this.toStorageKey(e);await this.execute(r,e=>r.set({[s]:t},e))}ensureStorage(){return e=this.area,"undefined"!=typeof chrome&&chrome.storage?chrome.storage[e]??null:null;var e}toStorageKey(e){return this.storageKeyPrefix?`${this.storageKeyPrefix}${e}`:e}async listPrefixedKeys(e,t){const r=await this.getFromStorage(e,null);return Object.keys(r).filter(e=>e.startsWith(t))}async getFromStorage(e,t){return this.invokeWithCallbackSupport(r=>e.get(t,r))}async execute(e,t){await this.invokeWithCallbackSupport(t)}async invokeWithCallbackSupport(e){return new Promise((t,r)=>{let s=!1;function n(e){if(s)return;s=!0;const n="undefined"!=typeof chrome&&chrome.runtime&&chrome.runtime.lastError?new Error(chrome.runtime.lastError.message):null;n?r(n):t(e)}try{const t=e(n);(i=t)&&"object"==typeof i&&"then"in i&&"function"==typeof i.then&&t.then(n).catch(r)}catch(e){r(e)}var i})}};function c(e){return{state:g(e.state),syncMetadata:e.syncMetadata,version:e.version}}function h(e){const t=u(e);if(!t)throw new Error("[ChromeStorageAdapter] Invalid serialized state format");return{state:f(t.state),syncMetadata:t.syncMetadata,version:t.version}}function u(e){if(l(e))return e;if("string"==typeof e)try{const t=JSON.parse(e);if(l(t))return t}catch{}return null}function l(e){return!(!e||"object"!=typeof e)&&Object.prototype.hasOwnProperty.call(e,"state")}function g(e,t=i){if(e instanceof Map||e instanceof Set)return t.call(void 0,"",e);if(!s(e))return e;const r={};for(const[s,n]of Object.entries(e))r[s]=t.call(e,s,n);return r}function f(e,t=o){const r=t.call(void 0,"",e);if(!s(r))return r;const n={};for(const e of Object.entries(r)){const s=e[0],i=e[1];n[s]=t.call(r,s,i)}return n}var y=class{constructor(t){this.injectStorageMetadata=!0,this.registrations=new Map,this.isListening=!1,this.onStorageChanged=async(e,t)=>{if(t===this.area)for(const t of this.registrations){const r=t[0],s=t[1];if(s.destroyed)continue;const n=e[this.toStorageKey(r)];if(n&&void 0!==n.newValue)try{const e=this.parsePersistValue(n.newValue);if(!e||e.syncMetadata?.origin===this.sessionId)continue;const t=e?.syncMetadata,r=this.extractChangedFields(s,e.state,t,n.oldValue);if(!Object.keys(r).length)continue;s.registration.apply({replace:!1,sessionId:t?.origin??"unknown",timestamp:t?.timestamp??Date.now(),values:r})}catch(e){continue}}},t&&"storage"in t?(this.area=t.storage.area,this.storageKeyPrefix=t.storage.storageKeyPrefix):(this.area=t?.area??"local",this.storageKeyPrefix=t?.storageKeyPrefix??e.DEFAULT_STORAGE_KEY_PREFIX),this.sessionId=this.generateSessionId(),this.attachListener()}destroy(){for(const e of this.registrations.values())e.destroyed=!0,e.listeners.clear();this.detachListener()}register(e){this.attachListener();const t={destroyed:!1,hydrated:!0,listeners:new Set,registration:e};return this.setRegistration(e.key,t),{destroy:()=>{t.destroyed=!0,t.listeners.clear(),this.registrations.delete(e.key),this.registrations.size||this.detachListener()},publish:null}}generateSessionId(){return"undefined"!=typeof crypto&&"randomUUID"in crypto?crypto.randomUUID():`${Math.random().toString(36).slice(2)}:${Date.now().toString(36)}`}attachListener(){"undefined"!=typeof chrome&&chrome.storage&&!this.isListening&&(this.isListening=!0,chrome.storage.onChanged.addListener(this.onStorageChanged))}detachListener(){"undefined"!=typeof chrome&&chrome.storage&&this.isListening&&(chrome.storage.onChanged.removeListener(this.onStorageChanged),this.isListening=!1)}extractChangedFields(e,t,s,i){const o=Object.create(n),a=s?.fields;if(a&&Object.keys(a).length>0){let s=!1;for(const n of e.registration.fields)r(a,String(n))&&(o[n]=t[n],s=!0);if(s)return o}const c=this.parsePersistValue(i);for(const r of e.registration.fields){const e=t[r],s=c?.state[r];Object.is(e,s)||(o[r]=e)}return o}setRegistration(e,t){this.registrations.set(e,t)}toStorageKey(e){return this.storageKeyPrefix?`${this.storageKeyPrefix}${e}`:e}parsePersistValue(e){return h(e)}};exports.ChromeExtensionSyncEngine=y,exports.ChromeStorageAdapter=a,exports.createSyncedChromeStorage=function(e){const t=new a(e);return{storage:t,syncEngine:new y({storage:t})}};
@@ -1 +1 @@
1
- import{isPromiseLike as t,replacer as e,reviver as r,isPlainObject as s,hasOwn as i}from"./chunk-QJLWBD7M.mjs";import{nullObject as n}from"./chunk-V4LHP7LR.mjs";import{DEFAULT_STORAGE_KEY_PREFIX as o}from"./internal/runtime.mjs";var a=class{constructor(t){this.async=!0,this.deserializer=h,this.serializer=c,this.area=t?.area??"local",this.storageKeyPrefix=t?.storageKeyPrefix??o}async clearAll(){const t=this.ensureStorage();if(!t)return;if(!this.storageKeyPrefix)throw new Error("Cannot clear all storage with empty storageKeyPrefix. This would delete all storage entries.");const e=await this.listPrefixedKeys(t,this.storageKeyPrefix);e.length&&await this.execute(t,r=>t.remove(e,r))}async contains(t){const e=this.ensureStorage();if(!e)return!1;const r=this.toStorageKey(t),s=await this.getFromStorage(e,r);return Object.prototype.hasOwnProperty.call(s,r)}async delete(t){const e=this.ensureStorage();if(!e)return;const r=this.toStorageKey(t);await this.execute(e,t=>e.remove(r,t))}async getAllKeys(){const t=this.ensureStorage();if(!t)return[];const e=await this.getFromStorage(t,null),r=this.storageKeyPrefix;return r?Object.keys(e).filter(t=>t.startsWith(r)).map(t=>t.slice(r.length)):Object.keys(e)}async get(t){const e=this.ensureStorage();if(!e)return;const r=this.toStorageKey(t);return g((await this.getFromStorage(e,r))[r])||void 0}async set(t,e){const r=this.ensureStorage();if(!r)return;const s=this.toStorageKey(t);await this.execute(r,t=>r.set({[s]:e},t))}ensureStorage(){return t=this.area,"undefined"!=typeof chrome&&chrome.storage?chrome.storage[t]??null:null;var t}toStorageKey(t){return this.storageKeyPrefix?`${this.storageKeyPrefix}${t}`:t}async listPrefixedKeys(t,e){const r=await this.getFromStorage(t,null);return Object.keys(r).filter(t=>t.startsWith(e))}async getFromStorage(t,e){return this.invokeWithCallbackSupport(r=>t.get(e,r))}async execute(t,e){await this.invokeWithCallbackSupport(e)}async invokeWithCallbackSupport(e){return new Promise((r,s)=>{let i=!1;function n(t){if(i)return;i=!0;const e="undefined"!=typeof chrome&&chrome.runtime&&chrome.runtime.lastError?new Error(chrome.runtime.lastError.message):null;e?s(e):r(t)}try{const r=e(n);t(r)&&r.then(n).catch(s)}catch(t){s(t)}})}};function c(t){return{state:u(t.state),syncMetadata:t.syncMetadata,version:t.version}}function h(t){const e=g(t);if(!e)throw new Error("[ChromeStorageAdapter] Invalid serialized state format");return{state:f(e.state),syncMetadata:e.syncMetadata,version:e.version}}function g(t){if(l(t))return t;if("string"==typeof t)try{const e=JSON.parse(t);if(l(e))return e}catch{}return null}function l(t){return!(!t||"object"!=typeof t)&&Object.prototype.hasOwnProperty.call(t,"state")}function u(t,r=e){if(t instanceof Map||t instanceof Set)return r.call(void 0,"",t);if(!s(t))return t;const i={};for(const[e,s]of Object.entries(t))i[e]=r.call(t,e,s);return i}function f(t,e=r){const i=e.call(void 0,"",t);if(!s(i))return i;const n={};for(const t of Object.entries(i)){const r=t[0],s=t[1];n[r]=e.call(i,r,s)}return n}var y=class{constructor(t){this.injectStorageMetadata=!0,this.registrations=new Map,this.isListening=!1,this.onStorageChanged=async(t,e)=>{if(e===this.area)for(const e of this.registrations){const r=e[0],s=e[1];if(s.destroyed)continue;const i=t[this.toStorageKey(r)];if(i&&void 0!==i.newValue)try{const t=this.parsePersistValue(i.newValue);if(!t||t.syncMetadata?.origin===this.sessionId)continue;const e=t?.syncMetadata,r=this.extractChangedFields(s,t.state,e,i.oldValue);if(!Object.keys(r).length)continue;s.registration.apply({replace:!1,sessionId:e?.origin??"unknown",timestamp:e?.timestamp??Date.now(),values:r})}catch(t){continue}}},t&&"storage"in t?(this.area=t.storage.area,this.storageKeyPrefix=t.storage.storageKeyPrefix):(this.area=t?.area??"local",this.storageKeyPrefix=t?.storageKeyPrefix??o),this.sessionId=this.generateSessionId(),this.attachListener()}destroy(){for(const t of this.registrations.values())t.destroyed=!0,t.listeners.clear();this.detachListener()}register(t){this.attachListener();const e={destroyed:!1,hydrated:!0,listeners:new Set,registration:t};return this.setRegistration(t.key,e),{destroy:()=>{e.destroyed=!0,e.listeners.clear(),this.registrations.delete(t.key),this.registrations.size||this.detachListener()},publish:null}}generateSessionId(){return"undefined"!=typeof crypto&&"randomUUID"in crypto?crypto.randomUUID():`${Math.random().toString(36).slice(2)}:${Date.now().toString(36)}`}attachListener(){"undefined"!=typeof chrome&&chrome.storage&&!this.isListening&&(this.isListening=!0,chrome.storage.onChanged.addListener(this.onStorageChanged))}detachListener(){"undefined"!=typeof chrome&&chrome.storage&&this.isListening&&(chrome.storage.onChanged.removeListener(this.onStorageChanged),this.isListening=!1)}extractChangedFields(t,e,r,s){const o=n(),a=r?.fields;if(a&&Object.keys(a).length>0){let r=!1;for(const s of t.registration.fields){const t=String(s);i(a,t)&&(o[s]=e[s],r=!0)}if(r)return o}const c=this.parsePersistValue(s);for(const r of t.registration.fields){const t=e[r],s=c?.state[r];Object.is(t,s)||(o[r]=t)}return o}setRegistration(t,e){this.registrations.set(t,e)}toStorageKey(t){return this.storageKeyPrefix?`${this.storageKeyPrefix}${t}`:t}parsePersistValue(t){return h(t)}};function d(t){const e=new a(t);return{storage:e,syncEngine:new y({storage:e})}}export{y as ChromeExtensionSyncEngine,a as ChromeStorageAdapter,d as createSyncedChromeStorage};
1
+ import{isPromiseLike as t,replacer as e,reviver as r}from"./chunk-FENSEQ3V.mjs";import{isPlainObject as s,nullObject as i,hasOwn as n}from"./chunk-FPYZVFBM.mjs";import{DEFAULT_STORAGE_KEY_PREFIX as o}from"./internal/runtime.mjs";var a=class{constructor(t){this.async=!0,this.deserializer=h,this.serializer=c,this.area=t?.area??"local",this.storageKeyPrefix=t?.storageKeyPrefix??o}async clearAll(){const t=this.ensureStorage();if(!t)return;if(!this.storageKeyPrefix)throw new Error("Cannot clear all storage with empty storageKeyPrefix. This would delete all storage entries.");const e=await this.listPrefixedKeys(t,this.storageKeyPrefix);e.length&&await this.execute(t,r=>t.remove(e,r))}async contains(t){const e=this.ensureStorage();if(!e)return!1;const r=this.toStorageKey(t),s=await this.getFromStorage(e,r);return Object.prototype.hasOwnProperty.call(s,r)}async delete(t){const e=this.ensureStorage();if(!e)return;const r=this.toStorageKey(t);await this.execute(e,t=>e.remove(r,t))}async getAllKeys(){const t=this.ensureStorage();if(!t)return[];const e=await this.getFromStorage(t,null),r=this.storageKeyPrefix;return r?Object.keys(e).filter(t=>t.startsWith(r)).map(t=>t.slice(r.length)):Object.keys(e)}async get(t){const e=this.ensureStorage();if(!e)return;const r=this.toStorageKey(t);return g((await this.getFromStorage(e,r))[r])||void 0}async set(t,e){const r=this.ensureStorage();if(!r)return;const s=this.toStorageKey(t);await this.execute(r,t=>r.set({[s]:e},t))}ensureStorage(){return t=this.area,"undefined"!=typeof chrome&&chrome.storage?chrome.storage[t]??null:null;var t}toStorageKey(t){return this.storageKeyPrefix?`${this.storageKeyPrefix}${t}`:t}async listPrefixedKeys(t,e){const r=await this.getFromStorage(t,null);return Object.keys(r).filter(t=>t.startsWith(e))}async getFromStorage(t,e){return this.invokeWithCallbackSupport(r=>t.get(e,r))}async execute(t,e){await this.invokeWithCallbackSupport(e)}async invokeWithCallbackSupport(e){return new Promise((r,s)=>{let i=!1;function n(t){if(i)return;i=!0;const e="undefined"!=typeof chrome&&chrome.runtime&&chrome.runtime.lastError?new Error(chrome.runtime.lastError.message):null;e?s(e):r(t)}try{const r=e(n);t(r)&&r.then(n).catch(s)}catch(t){s(t)}})}};function c(t){return{state:u(t.state),syncMetadata:t.syncMetadata,version:t.version}}function h(t){const e=g(t);if(!e)throw new Error("[ChromeStorageAdapter] Invalid serialized state format");return{state:f(e.state),syncMetadata:e.syncMetadata,version:e.version}}function g(t){if(l(t))return t;if("string"==typeof t)try{const e=JSON.parse(t);if(l(e))return e}catch{}return null}function l(t){return!(!t||"object"!=typeof t)&&Object.prototype.hasOwnProperty.call(t,"state")}function u(t,r=e){if(t instanceof Map||t instanceof Set)return r.call(void 0,"",t);if(!s(t))return t;const i={};for(const[e,s]of Object.entries(t))i[e]=r.call(t,e,s);return i}function f(t,e=r){const i=e.call(void 0,"",t);if(!s(i))return i;const n={};for(const t of Object.entries(i)){const r=t[0],s=t[1];n[r]=e.call(i,r,s)}return n}var y=class{constructor(t){this.injectStorageMetadata=!0,this.registrations=new Map,this.isListening=!1,this.onStorageChanged=async(t,e)=>{if(e===this.area)for(const e of this.registrations){const r=e[0],s=e[1];if(s.destroyed)continue;const i=t[this.toStorageKey(r)];if(i&&void 0!==i.newValue)try{const t=this.parsePersistValue(i.newValue);if(!t||t.syncMetadata?.origin===this.sessionId)continue;const e=t?.syncMetadata,r=this.extractChangedFields(s,t.state,e,i.oldValue);if(!Object.keys(r).length)continue;s.registration.apply({replace:!1,sessionId:e?.origin??"unknown",timestamp:e?.timestamp??Date.now(),values:r})}catch(t){continue}}},t&&"storage"in t?(this.area=t.storage.area,this.storageKeyPrefix=t.storage.storageKeyPrefix):(this.area=t?.area??"local",this.storageKeyPrefix=t?.storageKeyPrefix??o),this.sessionId=this.generateSessionId(),this.attachListener()}destroy(){for(const t of this.registrations.values())t.destroyed=!0,t.listeners.clear();this.detachListener()}register(t){this.attachListener();const e={destroyed:!1,hydrated:!0,listeners:new Set,registration:t};return this.setRegistration(t.key,e),{destroy:()=>{e.destroyed=!0,e.listeners.clear(),this.registrations.delete(t.key),this.registrations.size||this.detachListener()},publish:null}}generateSessionId(){return"undefined"!=typeof crypto&&"randomUUID"in crypto?crypto.randomUUID():`${Math.random().toString(36).slice(2)}:${Date.now().toString(36)}`}attachListener(){"undefined"!=typeof chrome&&chrome.storage&&!this.isListening&&(this.isListening=!0,chrome.storage.onChanged.addListener(this.onStorageChanged))}detachListener(){"undefined"!=typeof chrome&&chrome.storage&&this.isListening&&(chrome.storage.onChanged.removeListener(this.onStorageChanged),this.isListening=!1)}extractChangedFields(t,e,r,s){const o=i(),a=r?.fields;if(a&&Object.keys(a).length>0){let r=!1;for(const s of t.registration.fields){const t=String(s);n(a,t)&&(o[s]=e[s],r=!0)}if(r)return o}const c=this.parsePersistValue(s);for(const r of t.registration.fields){const t=e[r],s=c?.state[r];Object.is(t,s)||(o[r]=t)}return o}setRegistration(t,e){this.registrations.set(t,e)}toStorageKey(t){return this.storageKeyPrefix?`${this.storageKeyPrefix}${t}`:t}parsePersistValue(t){return h(t)}};function d(t){const e=new a(t);return{storage:e,syncEngine:new y({storage:e})}}export{y as ChromeExtensionSyncEngine,a as ChromeStorageAdapter,d as createSyncedChromeStorage};
@@ -0,0 +1 @@
1
+ function e(e,t){return t instanceof Map?{__type:"Map",entries:Array.from(t.entries())}:t instanceof Set?{__type:"Set",values:Array.from(t)}:t}function t(e,t){return function(e){return"object"==typeof e&&null!==e&&"__type"in e&&"Map"===e.__type}(t)?new Map(t.entries):function(e){return"object"==typeof e&&null!==e&&"__type"in e&&"Set"===e.__type}(t)?new Set(t.values):t}function n(e){return!!e&&"object"==typeof e&&"then"in e&&"function"==typeof e.then}export{n as isPromiseLike,e as replacer,t as reviver};
@@ -0,0 +1 @@
1
+ var e="undefined"!=typeof window&&"undefined"!=typeof document,t=!1,n="development"===process.env.NODE_ENV,r="test"===process.env.NODE_ENV,o=Object.freeze(Object.create(null));function c(e){return e}function u(){return Object.create(o)}function f(e,t){return void 0===t?Object.assign(u(),e):Object.assign(u(),e,t)}function i(){}var p=Object.prototype.hasOwnProperty;function s(e,t){return p.call(e,t)}function O(e){if("object"!=typeof e||null===e)return!1;const t=Object.getPrototypeOf(e);return null===t||t===Object.prototype}function l(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}export{e as IS_BROWSER,n as IS_DEV,t as IS_IOS,r as IS_TEST,f as buildNullObject,s as hasOwn,c as identity,O as isPlainObject,l as isRecordLike,i as noop,u as nullObject};
@@ -0,0 +1 @@
1
+ import{isPlainObject as r,nullObject as n}from"./chunk-FPYZVFBM.mjs";function t(r){return JSON.stringify(o(r))}function e(r){return JSON.parse(r)}function o(t){return"object"!=typeof t||null===t?t:Object.keys(t).sort().reduce((n,e)=>{const u=t[e];return n[e]=r(u)?o(u):u,n},n())}var u=Symbol("stores.queryParamConfig");function c(r,n){return{[u]:!0,key:n.key,value:r}}function f(r){return!!r&&"object"==typeof r&&u in r}export{t as getQueryKey,f as isQueryParamConfig,e as parseQueryKey,c as queryParam};
package/dist/web/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var e=require("react"),t=require("./internal/runtime.js");function r(){}process.env.NODE_ENV,process.env.NODE_ENV,Object.freeze(Object.create(null));var n=Symbol("empty selection"),o=Object.is;function u(e,t){return r=>(function(e){e.committedEqualityFn=e.equalityFn,e.committedSelector=e.selector,e.committedSource=e.source,e.committedValue=e.value===n?c(e):e.value}(e),t(u=>{e.latestSnapshot=u,e.latestSource=t;const c=e.committedValue;if(c===n||e.committedSource!==t)return void r();const i=e.committedSelector,a=e.committedEqualityFn;if(e.selector===i&&e.equalityFn===a){const t=i(u);if(a===o?o(c,t):a(c,t))return;return e.committedValue=t,e.value=t,e.valueEqualityFn=a,e.valueSelector=i,e.valueSnapshot=u,void r()}if(e.source!==t)return void r();const l=e.value;if(l===n)return;const S=e.selector(u),f=e.equalityFn(l,S);e.committedEqualityFn=e.equalityFn,e.committedSelector=e.selector,e.committedValue=s(e,u,f?l:S),f||r()}))}function c(e){const t=function(e){if(e.latestSource===e.source&&e.latestSnapshot!==n)return e.latestSnapshot;const t=e.getStoreSnapshot();return e.latestSnapshot=t,e.latestSource=e.source,t}(e);return i(e,t)}function i(e,t){const r=e.value;if(r!==n&&o(e.valueSnapshot,t)&&e.valueSelector===e.selector&&e.valueEqualityFn===e.equalityFn)return r;const u=e.selector(t);if(r!==n&&(e.equalityFn===o?o(r,u):e.equalityFn(r,u)))return s(e,t,r);const c=e.committedValue;return c!==n&&c!==r&&e.committedSource===e.source&&(e.equalityFn===o?o(c,u):e.equalityFn(c,u))?s(e,t,c):s(e,t,u)}function s(e,t,r){return e.value=r,e.valueEqualityFn=e.equalityFn,e.valueSelector=e.selector,e.valueSnapshot=t,r}function a(t,s,a,l){return Object.assign(function(S,f){return function(t,s,a,l,S=o){const f=e.useRef(null);let p=t,b=s,d=a;if(l){let e=f.current;null===e&&(e=function(e,t,o,s,a){const l={committedEqualityFn:a,committedSelector:s,committedSource:e,committedValue:n,equalityFn:a,getSelectedServerSnapshot:()=>function(e){return i(e,(e.getServerStoreSnapshot??e.getStoreSnapshot)())}(l),getSelectedSnapshot:()=>c(l),getServerStoreSnapshot:o,getStoreSnapshot:t,latestSnapshot:n,latestSource:n,selector:s,selectedSource:e,selectedSubscribe:()=>r,source:e,value:n,valueEqualityFn:a,valueSelector:s,valueSnapshot:n};return l.selectedSubscribe=u(l,e),l}(t,s,a,l,S),f.current=e),function(e,t,r,o,c,i){e.source===t&&e.getStoreSnapshot===r||(e.latestSnapshot=n),e.source=t,e.getStoreSnapshot=r,e.getServerStoreSnapshot=o,e.selector=c,e.equalityFn=i,e.selectedSource!==t&&(e.selectedSource=t,e.selectedSubscribe=u(e,t))}(e,t,s,a,l,S),p=e.selectedSubscribe,b=e.getSelectedSnapshot,d=void 0===a?void 0:e.getSelectedServerSnapshot}const y=e.useSyncExternalStore(p,b,d);return e.useDebugValue(y),y}(t.subscribe,s,a,S,f??l)},t)}var l=Symbol(),S=Object.freeze({debugMode:!1,enabled:!0,equalityFn:Object.is,fireImmediately:!1}),f=Object.freeze({fireImmediately:!1,forceResubscribe:!1});function p(e,t,r=f){if(t.current.isActive){if(!r?.forceResubscribe)return;t.current.unsubscribe()}t.current.options.debugMode&&console.log("[📡 useListen 📡] Attaching listener"),t.current.isActive=!0,t.current.resubscribe=(r=f)=>p(e,t,r);const n=e.subscribe(e=>t.current.selector(e),(e,r)=>t.current.react(e,r,()=>{n(),t.current.isActive=!1}),r.fireImmediately?{...t.current.options,fireImmediately:!0}:t.current.options);t.current.unsubscribe=()=>{t.current.isActive&&(n(),t.current.isActive=!1)}}function b(e){return"function"==typeof e?{equalityFn:e}:e??S}var d=Symbol();Object.defineProperty(exports,"QueryStatuses",{enumerable:!0,get:function(){return t.QueryStatuses}}),Object.defineProperty(exports,"StoresError",{enumerable:!0,get:function(){return t.StoresError}}),Object.defineProperty(exports,"applyStateUpdate",{enumerable:!0,get:function(){return t.applyStateUpdate}}),Object.defineProperty(exports,"configureStores",{enumerable:!0,get:function(){return t.configureStores}}),Object.defineProperty(exports,"createStoreActions",{enumerable:!0,get:function(){return t.createStoreActions}}),Object.defineProperty(exports,"deepEqual",{enumerable:!0,get:function(){return t.deepEqual}}),Object.defineProperty(exports,"defaultRetryDelay",{enumerable:!0,get:function(){return t.defaultRetryDelay}}),Object.defineProperty(exports,"destroyStore",{enumerable:!0,get:function(){return t.destroyStore}}),Object.defineProperty(exports,"destroyStores",{enumerable:!0,get:function(){return t.destroyStores}}),Object.defineProperty(exports,"getStoreName",{enumerable:!0,get:function(){return t.getStoreName}}),Object.defineProperty(exports,"hasGetSnapshot",{enumerable:!0,get:function(){return t.hasGetSnapshot}}),Object.defineProperty(exports,"identity",{enumerable:!0,get:function(){return t.identity}}),Object.defineProperty(exports,"isDerivedStore",{enumerable:!0,get:function(){return t.isDerivedStore}}),Object.defineProperty(exports,"isPersistedStore",{enumerable:!0,get:function(){return t.isPersistedStore}}),Object.defineProperty(exports,"isQueryStore",{enumerable:!0,get:function(){return t.isQueryStore}}),Object.defineProperty(exports,"isVirtualStore",{enumerable:!0,get:function(){return t.isVirtualStore}}),Object.defineProperty(exports,"nullObject",{enumerable:!0,get:function(){return t.nullObject}}),Object.defineProperty(exports,"replacer",{enumerable:!0,get:function(){return t.replacer}}),Object.defineProperty(exports,"reviver",{enumerable:!0,get:function(){return t.reviver}}),Object.defineProperty(exports,"shallowEqual",{enumerable:!0,get:function(){return t.shallowEqual}}),Object.defineProperty(exports,"time",{enumerable:!0,get:function(){return t.time}}),exports.createBaseStore=function(e,r){const n=t.baseStore(e,r);return a(n,n.getState,n.getInitialState,Object.is)},exports.createDerivedStore=function(e,r=Object.is){const n=t.derivedStore(e,r);return a(n,n.getSnapshot)},exports.createQueryStore=function(e,r,n){const o=t.queryStore(e,r,n);return a(o,o.getState,o.getInitialState,Object.is)},exports.createVirtualStore=function(e,r,n){const o=t.virtualStore(e,r,n);return a(o,o.getState,o.getInitialState)},exports.getQueryKey=function(e){return t.getQueryKey(e)},exports.parseQueryKey=function(e){return t.parseQueryKey(e)},exports.useListen=function(t,r,n,o=S){const u=function(){const t=e.useRef(l);return t.current===l&&(t.current=function(e,t,r){return{selector:e,react:t,isActive:!1,options:b(r),resubscribe:()=>{},unsubscribe:()=>{}}}(r,n,o)),t}(),c=function(e){return"function"==typeof e?S.enabled:e?.enabled??S.enabled}(o);return u.current.react=n,u.current.selector=r,function(e,t){"function"==typeof t?e.current.options.equalityFn=t:t&&(e.current.options=t??S)}(u,o),e.useLayoutEffect(()=>{if(c)return p(t,u),()=>function(e){e.current.options.debugMode&&console.log("[🗑️ useListen 🗑️] Detaching listener"),e.current.resubscribe=()=>{},e.current.unsubscribe(),e.current.unsubscribe=()=>{},e.current.isActive=!1}(u)},[c,t]),u},exports.useStableValue=function(t){const r=e.useRef(d);return r.current===d&&(r.current=t()),r.current};
1
+ var e=require("react"),t=require("./internal/runtime.js");process.env.NODE_ENV,process.env.NODE_ENV;var r=Object.freeze(Object.create(null));function n(){}var o=Symbol("empty selection"),u=Object.is;function c(e,t){return r=>(function(e){e.committedEqualityFn=e.equalityFn,e.committedSelector=e.selector,e.committedSource=e.source,e.committedValue=e.value===o?i(e):e.value}(e),t(n=>{e.latestSnapshot=n,e.latestSource=t;const c=e.committedValue;if(c===o||e.committedSource!==t)return void r();const i=e.committedSelector,s=e.committedEqualityFn;if(e.selector===i&&e.equalityFn===s){const t=i(n);if(s===u?u(c,t):s(c,t))return;return e.committedValue=t,e.value=t,e.valueEqualityFn=s,e.valueSelector=i,e.valueSnapshot=n,void r()}if(e.source!==t)return void r();const l=e.value;if(l===o)return;const f=e.selector(n),S=e.equalityFn(l,f);e.committedEqualityFn=e.equalityFn,e.committedSelector=e.selector,e.committedValue=a(e,n,S?l:f),S||r()}))}function i(e){const t=function(e){if(e.latestSource===e.source&&e.latestSnapshot!==o)return e.latestSnapshot;const t=e.getStoreSnapshot();return e.latestSnapshot=t,e.latestSource=e.source,t}(e);return s(e,t)}function s(e,t){const r=e.value;if(r!==o&&u(e.valueSnapshot,t)&&e.valueSelector===e.selector&&e.valueEqualityFn===e.equalityFn)return r;const n=e.selector(t);if(r!==o&&(e.equalityFn===u?u(r,n):e.equalityFn(r,n)))return a(e,t,r);const c=e.committedValue;return c!==o&&c!==r&&e.committedSource===e.source&&(e.equalityFn===u?u(c,n):e.equalityFn(c,n))?a(e,t,c):a(e,t,n)}function a(e,t,r){return e.value=r,e.valueEqualityFn=e.equalityFn,e.valueSelector=e.selector,e.valueSnapshot=t,r}function l(t,r,a,l){return Object.assign(function(f,S){return function(t,r,a,l,f=u){const S=e.useRef(null);let b=t,p=r,y=a;if(l){let e=S.current;null===e&&(e=function(e,t,r,u,a){const l={committedEqualityFn:a,committedSelector:u,committedSource:e,committedValue:o,equalityFn:a,getSelectedServerSnapshot:()=>function(e){return s(e,(e.getServerStoreSnapshot??e.getStoreSnapshot)())}(l),getSelectedSnapshot:()=>i(l),getServerStoreSnapshot:r,getStoreSnapshot:t,latestSnapshot:o,latestSource:o,selector:u,selectedSource:e,selectedSubscribe:()=>n,source:e,value:o,valueEqualityFn:a,valueSelector:u,valueSnapshot:o};return l.selectedSubscribe=c(l,e),l}(t,r,a,l,f),S.current=e),function(e,t,r,n,u,i){e.source===t&&e.getStoreSnapshot===r||(e.latestSnapshot=o),e.source=t,e.getStoreSnapshot=r,e.getServerStoreSnapshot=n,e.selector=u,e.equalityFn=i,e.selectedSource!==t&&(e.selectedSource=t,e.selectedSubscribe=c(e,t))}(e,t,r,a,l,f),b=e.selectedSubscribe,p=e.getSelectedSnapshot,y=void 0===a?void 0:e.getSelectedServerSnapshot}const d=e.useSyncExternalStore(b,p,y);return e.useDebugValue(d),d}(t.subscribe,r,a,f,S??l)},t)}function f(e){return"object"!=typeof e||null===e?e:Object.keys(e).sort().reduce((t,r)=>{const n=e[r];return t[r]=function(e){if("object"!=typeof e||null===e)return!1;const t=Object.getPrototypeOf(e);return null===t||t===Object.prototype}(n)?f(n):n,t},Object.create(r))}var S=Symbol("stores.queryParamConfig"),b=Symbol(),p=Object.freeze({debugMode:!1,enabled:!0,equalityFn:Object.is,fireImmediately:!1}),y=Object.freeze({fireImmediately:!1,forceResubscribe:!1});function d(e,t,r=y){if(t.current.isActive){if(!r?.forceResubscribe)return;t.current.unsubscribe()}t.current.options.debugMode&&console.log("[📡 useListen 📡] Attaching listener"),t.current.isActive=!0,t.current.resubscribe=(r=y)=>d(e,t,r);const n=e.subscribe(e=>t.current.selector(e),(e,r)=>t.current.react(e,r,()=>{n(),t.current.isActive=!1}),r.fireImmediately?{...t.current.options,fireImmediately:!0}:t.current.options);t.current.unsubscribe=()=>{t.current.isActive&&(n(),t.current.isActive=!1)}}function m(e){return"function"==typeof e?{equalityFn:e}:e??p}var g=Symbol();Object.defineProperty(exports,"QueryStatuses",{enumerable:!0,get:function(){return t.QueryStatuses}}),Object.defineProperty(exports,"StoresError",{enumerable:!0,get:function(){return t.StoresError}}),Object.defineProperty(exports,"applyStateUpdate",{enumerable:!0,get:function(){return t.applyStateUpdate}}),Object.defineProperty(exports,"configureStores",{enumerable:!0,get:function(){return t.configureStores}}),Object.defineProperty(exports,"createStoreActions",{enumerable:!0,get:function(){return t.createStoreActions}}),Object.defineProperty(exports,"deepEqual",{enumerable:!0,get:function(){return t.deepEqual}}),Object.defineProperty(exports,"defaultRetryDelay",{enumerable:!0,get:function(){return t.defaultRetryDelay}}),Object.defineProperty(exports,"destroyStore",{enumerable:!0,get:function(){return t.destroyStore}}),Object.defineProperty(exports,"destroyStores",{enumerable:!0,get:function(){return t.destroyStores}}),Object.defineProperty(exports,"getStoreName",{enumerable:!0,get:function(){return t.getStoreName}}),Object.defineProperty(exports,"hasGetSnapshot",{enumerable:!0,get:function(){return t.hasGetSnapshot}}),Object.defineProperty(exports,"identity",{enumerable:!0,get:function(){return t.identity}}),Object.defineProperty(exports,"isDerivedStore",{enumerable:!0,get:function(){return t.isDerivedStore}}),Object.defineProperty(exports,"isPersistedStore",{enumerable:!0,get:function(){return t.isPersistedStore}}),Object.defineProperty(exports,"isQueryStore",{enumerable:!0,get:function(){return t.isQueryStore}}),Object.defineProperty(exports,"isVirtualStore",{enumerable:!0,get:function(){return t.isVirtualStore}}),Object.defineProperty(exports,"nullObject",{enumerable:!0,get:function(){return t.nullObject}}),Object.defineProperty(exports,"replacer",{enumerable:!0,get:function(){return t.replacer}}),Object.defineProperty(exports,"reviver",{enumerable:!0,get:function(){return t.reviver}}),Object.defineProperty(exports,"shallowEqual",{enumerable:!0,get:function(){return t.shallowEqual}}),Object.defineProperty(exports,"time",{enumerable:!0,get:function(){return t.time}}),exports.createBaseStore=function(e,r){const n=t.baseStore(e,r);return l(n,n.getState,n.getInitialState,Object.is)},exports.createDerivedStore=function(e,r=Object.is){const n=t.derivedStore(e,r);return l(n,n.getSnapshot)},exports.createQueryStore=function(e,r,n){const o=t.queryStore(e,r,n);return l(o,o.getState,o.getInitialState,Object.is)},exports.createVirtualStore=function(e,r,n){const o=t.virtualStore(e,r,n);return l(o,o.getState,o.getInitialState)},exports.getQueryKey=function(e){return JSON.stringify(f(e))},exports.parseQueryKey=function(e){return JSON.parse(e)},exports.queryParam=function(e,t){return{[S]:!0,key:t.key,value:e}},exports.useListen=function(t,r,o,u=p){const c=function(){const t=e.useRef(b);return t.current===b&&(t.current=function(e,t,r){return{selector:e,react:t,isActive:!1,options:m(r),resubscribe:n,unsubscribe:n}}(r,o,u)),t}(),i=function(e){return"function"==typeof e?p.enabled:e?.enabled??p.enabled}(u);return c.current.react=o,c.current.selector=r,function(e,t){"function"==typeof t?e.current.options.equalityFn=t:t&&(e.current.options=t??p)}(c,u),e.useLayoutEffect(()=>{if(i)return d(t,c),()=>function(e){e.current.options.debugMode&&console.log("[🗑️ useListen 🗑️] Detaching listener"),e.current.resubscribe=n,e.current.unsubscribe(),e.current.unsubscribe=n,e.current.isActive=!1}(c)},[i,t]),c},exports.useStableValue=function(t){const r=e.useRef(g);return r.current===g&&(r.current=t()),r.current};