reselect-kit 1.1.0 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"reselectKit.development.cjs","names":["createSelector","createSelector","createCachedSelector","reselectStructuredSelector","createCachedSelector","FlatObjectCache"],"sources":["../../src/createSegmentSelector.ts","../../src/_helpers/isObject.ts","../../src/_helpers/defineDynamicSelectorName.ts","../../src/debug/debug.ts","../../src/debug/withDebugName.ts","../../src/_helpers/getSelectorName.ts","../../src/createPathSelector.ts","../../src/createPropSelector.ts","../../src/keys/createKeySelectorComposer.ts","../../src/_helpers/arePathsEqual.ts","../../src/keys/defaultKeySelector.ts","../../src/_helpers/isCachedSelector.ts","../../src/keys/createKeySelectorCreator.ts","../../src/keys/stringComposeKeySelectors.ts","../../src/_helpers/temporaryAssign.ts","../../src/_helpers/getObjectPaths.ts","../../src/createBoundSelector.ts","../../src/createEmptySelector.ts","../../src/createAdaptedSelector.ts","../../src/_helpers/stringifyFunction.ts","../../src/_helpers/generateSelectorKey.ts","../../src/createChainSelector.ts","../../src/createSequenceSelector.ts","../../src/createCachedSequenceSelector.ts","../../src/createStructuredSelector.ts","../../src/createCachedStructuredSelector.ts","../../src/keys/arrayComposeKeySelectors.ts","../../src/cache/intervalMapCache.ts","../../src/cache/TreeCache.ts","../../src/_helpers/unfreezeProps.ts","../../src/_hooks/selectorOptions.ts","../../src/_hooks/useSelector.ts","../../src/_hooks/useSelectors.ts"],"sourcesContent":["export function createSegmentSelector<State, SelectedSegment extends State | State[keyof State]>(\n fn: (state: State) => SelectedSegment,\n initial: SelectedSegment,\n): (state: State) => SelectedSegment {\n return (state: State) => fn(state) ?? initial;\n}\n","export const isObject = (value: unknown): value is Record<string, unknown> => {\n return value !== null && typeof value === 'object';\n};\n","export const defineDynamicSelectorName = (selector: unknown, selectorNameGetter: () => string) => {\n let overriddenSelectorName: string;\n Object.defineProperty(selector, 'selectorName', {\n configurable: true,\n get: () => overriddenSelectorName ?? selectorNameGetter(),\n set: (value: string) => {\n overriddenSelectorName = value;\n },\n });\n};\n","let debugMode = false;\n\nexport const isDebugMode = () => debugMode;\n\nexport const setDebugMode = (value: boolean) => {\n debugMode = value;\n};\n","import { defineDynamicSelectorName } from '../_helpers/defineDynamicSelectorName';\nimport { isDebugMode } from './debug';\n\n/**\n * Runs `callback` only outside production and only while debug mode is enabled.\n * Centralizes the `NODE_ENV` / `isDebugMode` guard that the selector factories\n * would otherwise repeat around every debug-name assignment.\n */\nexport const runInDebug = (callback: () => void) => {\n /* istanbul ignore else */\n if (process.env.NODE_ENV !== 'production') {\n /* istanbul ignore else */\n if (isDebugMode()) {\n callback();\n }\n }\n};\n\n/**\n * Assigns a lazily-computed debug name to `selector`, guarded by\n * {@link runInDebug}. Covers the common single-name case; use `runInDebug`\n * directly when a block needs to name several selectors at once.\n */\nexport const withDebugName = (selector: unknown, selectorNameGetter: () => string) => {\n runInDebug(() => {\n defineDynamicSelectorName(selector, selectorNameGetter);\n });\n};\n","export const getSelectorName = (selector: { name: string; selectorName?: string }): string => {\n if ('selectorName' in selector && selector.selectorName) {\n return selector.selectorName;\n }\n\n return selector.name;\n};\n","import { NamedSelector, Path } from './types';\nimport { isObject } from './_helpers/isObject';\nimport { withDebugName } from './debug/withDebugName';\nimport { getSelectorName } from './_helpers/getSelectorName';\n\nexport type Defined<T> = Exclude<T, undefined>;\n\nexport type IsOptional<T> = undefined extends T ? true : null extends T ? true : false;\n\nexport type IsObject<T> = T extends object ? true : false;\n\n/**\n * The selector a path builder produces. `Params` is carried through untouched\n * from the base selector: walking a path changes the result, never the\n * arguments, so the plain and the parametric case are the same type.\n */\nexport type PathSelector<S, R, Params extends readonly any[], D> = NamedSelector<\n S,\n R,\n Params,\n D\n> & {\n path: Path;\n};\n\ntype Required<T> = { [P in keyof T]-?: Exclude<T[P], undefined | null> };\n\nexport type RequiredSelectorBuilder<S, R, Params extends readonly any[], D> = R extends object\n ? { [K in keyof R]: () => PathSelector<S, NonNullable<R[K]>, Params, D> }\n : {};\n\nexport type OptionalSelectorBuilder<S, R, Params extends readonly any[], D> = ((\n defaultValue?: R,\n) => PathSelector<S, R extends undefined ? Defined<R> : R, Params, D>) &\n (R extends object\n ? { [K in keyof Required<R>]: () => PathSelector<S, NonNullable<R[K]>, Params, D> }\n : {});\n\nexport type RequiredObjectSelectorWrapper<S, R, Params extends readonly any[], D> = {\n [K in keyof R]-?: IsOptional<R[K]> extends true\n ? OptionalPathSelectorType<S, R[K], Params, D>\n : RequiredPathSelectorType<S, R[K], Params, D>;\n};\n\nexport type OptionalObjectSelectorWrapper<S, R, Params extends readonly any[], D> = {\n [K in keyof R]-?: OptionalPathSelectorType<S, R[K], Params, D>;\n};\n\nexport type RequiredArraySelectorWrapper<S, R, Params extends readonly any[], D> = {\n length: RequiredPathSelectorType<S, number, Params, D>;\n\n [K: number]: IsOptional<R> extends true\n ? OptionalPathSelectorType<S, R, Params, D>\n : RequiredPathSelectorType<S, R, Params, D>;\n};\n\nexport type OptionalArraySelectorWrapper<S, R, Params extends readonly any[], D> = {\n length: RequiredPathSelectorType<S, number, Params, D>;\n\n [K: number]: OptionalPathSelectorType<S, R, Params, D>;\n};\n\nexport type RequiredDataSelectorWrapper<\n S,\n R,\n Params extends readonly any[],\n D,\n> = R extends unknown[]\n ? RequiredArraySelectorWrapper<S, R[number], Params, D>\n : IsObject<R> extends true\n ? RequiredObjectSelectorWrapper<S, R, Params, D>\n : RequiredSelectorBuilder<S, R, Params, D>;\n\nexport type OptionalDataSelectorWrapper<\n S,\n R,\n Params extends readonly any[],\n D,\n> = R extends unknown[]\n ? OptionalArraySelectorWrapper<S, R[number], Params, D>\n : IsObject<R> extends true\n ? OptionalObjectSelectorWrapper<S, R, Params, D>\n : OptionalSelectorBuilder<S, R, Params, D>;\n\nexport type RequiredPathSelectorType<\n S,\n R,\n Params extends readonly any[],\n D,\n> = RequiredSelectorBuilder<S, R, Params, D> &\n RequiredDataSelectorWrapper<S, NonNullable<R>, Params, D>;\n\nexport type OptionalPathSelectorType<\n S,\n R,\n Params extends readonly any[],\n D,\n> = OptionalSelectorBuilder<S, R, Params, D> &\n OptionalDataSelectorWrapper<S, NonNullable<R>, Params, D>;\n\nconst defaultVoidFunction = () => {\n return;\n};\n\n/** @internal */\nexport const innerCreatePathSelector = (\n baseSelector: (...args: unknown[]) => unknown,\n path: Path = [],\n applyMeta: (selector: unknown) => void = defaultVoidFunction,\n): unknown => {\n const pathLength = path.length;\n\n const proxyTarget = (defaultValue?: unknown) => {\n function resultSelector(state?: unknown, props?: unknown) {\n // Selectors are almost always reached as `(state)` or `(state, props)`, and\n // dispatching those two arities directly keeps `arguments` out of the hot\n // path. The arity is matched exactly rather than always passing two: reselect\n // memoizes on the argument list, so handing a one-argument selector a second\n // `undefined` would change its cache key.\n let result: unknown;\n\n if (arguments.length === 2) {\n result = baseSelector(state, props);\n } else if (arguments.length === 1) {\n result = baseSelector(state);\n } else {\n result = baseSelector.apply(null, arguments as unknown as unknown[]);\n }\n\n for (let i = 0; i < pathLength && isObject(result); i += 1) {\n result = result[path[i]];\n }\n\n // For optional properties, we want to exclude undefined from the return type\n // but still return undefined if the property doesn't exist\n return result === undefined ? defaultValue : result;\n }\n\n Object.assign(resultSelector, baseSelector, { path });\n resultSelector.dependencies = [baseSelector];\n\n applyMeta(resultSelector);\n\n withDebugName(resultSelector, () => {\n const baseName = getSelectorName(baseSelector);\n\n return [baseName, ...path].join('.');\n });\n\n return resultSelector;\n };\n\n return new Proxy(proxyTarget, {\n get: (_target, key) => {\n return innerCreatePathSelector(baseSelector, [...path, String(key)], applyMeta);\n },\n });\n};\n\n/**\n * Builds a proxy that turns property access into a selector reading that path.\n *\n * `Params` is inferred straight from the base selector, so the plain and the\n * parametric case share one signature — and one set of builder types — instead\n * of being told apart by a conditional in the parameter position. It defaults\n * to empty so that `createPathSelector<State, Result>(selector)` keeps working\n * for callers that spell the type arguments out.\n */\nexport function createPathSelector<S, R, Params extends readonly any[] = []>(\n baseSelector: (state: S, ...params: Params) => R,\n): IsOptional<R> extends true\n ? OptionalPathSelectorType<S, R, Params, [typeof baseSelector]>\n : RequiredPathSelectorType<S, R, Params, [typeof baseSelector]> {\n return innerCreatePathSelector(baseSelector as (...args: unknown[]) => unknown) as any;\n}\n","import { Selector } from '@veksa/reselect';\nimport { innerCreatePathSelector, RequiredPathSelectorType } from './createPathSelector';\nimport { Path } from './types';\n\nconst propSelectorSymbol = Symbol.for('PropSelector');\n\nexport const isPropSelector = (selector: unknown): selector is { path: Path } => {\n return selector instanceof Object && propSelectorSymbol in selector;\n};\n\nexport function createPropSelector<P>(): RequiredPathSelectorType<\n unknown,\n P,\n [P],\n [Selector<unknown, P, [P]>]\n> {\n const propsSelector = (_state: unknown, props: unknown) => props;\n\n const applyMeta = (selector: unknown) => {\n Object.defineProperty(selector, propSelectorSymbol, { value: true });\n };\n\n return innerCreatePathSelector(propsSelector, [], applyMeta) as RequiredPathSelectorType<\n unknown,\n P,\n [P],\n [Selector<unknown, P, [P]>]\n >;\n}\n","import { KeySelector } from '@veksa/re-reselect';\nimport { MergedParams, MergedState } from '../types';\n\nexport const composedKeySelectorSymbol = Symbol.for('ComposedKeySelector');\n\n/**\n * The loosest shape a key selector can take: a function of `state` plus any\n * number of extra arguments (props, ...). Used for variadic tuple inference.\n */\ntype AnyKeySelector = KeySelector<any>;\n\n/**\n * The key selector produced by a {@link KeySelectorComposer}: a function that\n * intersects the `state` and the extra arguments of every composed key\n * selector, tagged with the original inputs as `dependencies`.\n */\nexport type OutputKeySelector<\n S,\n Params extends readonly any[],\n D extends readonly AnyKeySelector[],\n> = ((state: S, ...params: Params) => unknown) & {\n dependencies: D;\n};\n\n/**\n * Composes N key selectors into a single one. A single variadic signature with\n * tuple inference replaces the former per-arity overload set; `state` and the\n * extra arguments are merged by the same helpers every other multi-selector\n * creator in the library uses.\n */\nexport type KeySelectorComposer = <Ks extends readonly AnyKeySelector[]>(\n ...keySelectors: Ks\n) => OutputKeySelector<MergedState<Ks>, MergedParams<Ks>, Ks>;\n\nexport function isComposedKeySelector(\n keySelector: AnyKeySelector,\n): keySelector is AnyKeySelector & { dependencies: AnyKeySelector[] } {\n return 'dependencies' in keySelector && composedKeySelectorSymbol in keySelector;\n}\n\nexport function createKeySelectorComposer(\n baseKeySelectorComposer: (...keySelectors: AnyKeySelector[]) => AnyKeySelector,\n): KeySelectorComposer {\n return ((...keySelectors: AnyKeySelector[]) => {\n const resultSelector = baseKeySelectorComposer(...keySelectors) as AnyKeySelector & {\n dependencies: AnyKeySelector[];\n };\n\n resultSelector.dependencies = keySelectors;\n\n Object.defineProperty(resultSelector, composedKeySelectorSymbol, {\n value: true,\n });\n\n return resultSelector;\n }) as KeySelectorComposer;\n}\n","import { Path } from '../types';\n\nexport const arePathsEqual = (path: Path, anotherPath: Path) => {\n if (path.length !== anotherPath.length) {\n return false;\n }\n\n for (let i = 0; i < path.length; i += 1) {\n if (path[i] !== anotherPath[i]) {\n return false;\n }\n }\n\n return true;\n};\n","export const defaultKeySelector = () => '<DefaultKey>';\n","import { CachedSelector } from '../types';\n\nexport const isCachedSelector = (selector: unknown): selector is CachedSelector => {\n return (\n selector instanceof Object &&\n 'keySelector' in selector &&\n typeof (selector as CachedSelector).keySelector === 'function'\n );\n};\n","import { KeySelector } from '@veksa/re-reselect';\nimport { isPropSelector } from '../createPropSelector';\nimport { isComposedKeySelector, KeySelectorComposer } from './createKeySelectorComposer';\nimport { arePathsEqual } from '../_helpers/arePathsEqual';\nimport { defaultKeySelector } from './defaultKeySelector';\nimport { isCachedSelector } from '../_helpers/isCachedSelector';\n\nconst areSelectorsEqual = (selector: unknown, another: unknown) => {\n if (selector === another) {\n return true;\n }\n\n if (isPropSelector(selector) && isPropSelector(another)) {\n return arePathsEqual(selector.path, another.path);\n }\n\n return false;\n};\n\nconst flatKeySelectors = <S>(keySelectors: KeySelector<S>[]) => {\n const result: typeof keySelectors = [];\n\n for (let i = 0; i < keySelectors.length; i += 1) {\n const keySelector = keySelectors[i];\n\n if (isComposedKeySelector(keySelector)) {\n result.push(...flatKeySelectors(keySelector.dependencies));\n } else {\n result.push(keySelector);\n }\n }\n\n return result;\n};\n\nconst uniqKeySelectors = <S>(keySelectors: KeySelector<S>[]) => {\n const result: typeof keySelectors = [];\n\n for (let i = 0; i < keySelectors.length; i += 1) {\n const keySelector = keySelectors[i];\n\n const isKeySelectorAdded = result.some((resultKeySelector) =>\n areSelectorsEqual(keySelector, resultKeySelector),\n );\n if (!isKeySelectorAdded) {\n result.push(keySelector);\n }\n }\n\n return result;\n};\n\nexport const excludeDefaultSelectors = <S>(keySelectors: KeySelector<S>[]) => {\n const result: typeof keySelectors = [];\n\n for (let i = 0; i < keySelectors.length; i += 1) {\n const keySelector = keySelectors[i];\n\n if (keySelector !== defaultKeySelector) {\n result.push(keySelector);\n }\n }\n\n return result;\n};\n\nexport function createKeySelectorCreator(\n keySelectorComposer: KeySelectorComposer,\n): <S, D>(selectorInputs: { inputSelectors: D; keySelector?: KeySelector<S> }) => KeySelector<S> {\n return <S>({\n inputSelectors,\n keySelector,\n }: {\n inputSelectors: unknown;\n keySelector?: KeySelector<S>;\n }) => {\n let keySelectors: KeySelector<S>[] = [];\n\n if (keySelector) {\n keySelectors.push(keySelector);\n }\n\n (inputSelectors as unknown[]).forEach((selector) => {\n if (isCachedSelector(selector)) {\n keySelectors.push(selector.keySelector);\n }\n });\n\n keySelectors = flatKeySelectors(keySelectors);\n keySelectors = uniqKeySelectors(keySelectors);\n keySelectors = excludeDefaultSelectors(keySelectors);\n\n if (keySelectors.length === 0) {\n return defaultKeySelector;\n }\n\n if (keySelectors.length === 1) {\n const [resultSelector] = keySelectors;\n return resultSelector;\n }\n\n // The composer infers a `UnionToIntersection` state from the runtime array,\n // which TS can't see as identical to `S`; narrow it back for the caller.\n return keySelectorComposer(...keySelectors) as KeySelector<S>;\n };\n}\n","import { createKeySelectorComposer } from './createKeySelectorComposer';\n\nexport const stringComposeKeySelectors = createKeySelectorComposer(\n (...keySelectors) =>\n (state, props) => {\n let key: unknown = keySelectors[0](state, props);\n\n for (let i = 1; i < keySelectors.length; i += 1) {\n key += ':';\n key += keySelectors[i](state, props);\n }\n\n return key;\n },\n);\n","const noop = () => undefined;\n\nexport function temporaryAssign(\n target: Record<string, unknown>,\n source: Record<string, unknown>,\n): {\n result: Record<string, unknown>;\n rollback: () => void;\n} {\n if (typeof target !== 'object' || target === null) {\n return {\n result: source,\n rollback: noop,\n };\n }\n\n // Both containers and the closure are allocated only once something actually has\n // to be restored. This runs on every call of every bound selector, and the usual\n // case is a binding whose keys the target does not have — one entry in\n // `deleteProps`, nothing in `temporary` — while a re-entrant call that finds the\n // binding already applied changes nothing at all and can share `noop`.\n let temporary: Record<string, unknown> | null = null;\n let deleteProps: string[] | null = null;\n\n for (const prop in source as unknown as object) {\n if (Object.prototype.hasOwnProperty.call(source, prop)) {\n const targetProp = target[prop];\n const sourceProp = source[prop];\n\n if (targetProp !== sourceProp) {\n if (Object.prototype.hasOwnProperty.call(target, prop)) {\n if (temporary === null) {\n temporary = {};\n }\n temporary[prop] = targetProp;\n } else {\n if (deleteProps === null) {\n deleteProps = [];\n }\n deleteProps.push(prop);\n }\n\n target[prop] = sourceProp;\n }\n }\n }\n\n if (temporary === null && deleteProps === null) {\n return {\n result: target,\n rollback: noop,\n };\n }\n\n const restore = temporary;\n const remove = deleteProps;\n\n const rollback = () => {\n if (restore !== null) {\n for (const prop in restore) {\n if (Object.prototype.hasOwnProperty.call(restore, prop)) {\n target[prop] = restore[prop];\n }\n }\n }\n\n if (remove !== null) {\n for (const prop of remove) {\n if (Object.prototype.hasOwnProperty.call(target, prop)) {\n delete target[prop];\n }\n }\n }\n };\n\n return {\n result: target,\n rollback,\n };\n}\n","import { Path } from '../types';\nimport { isObject } from './isObject';\n\nexport const getObjectPaths = (value: unknown, parentPath: Path = []): Path[] => {\n if (!isObject(value)) {\n return [parentPath];\n }\n\n return Object.keys(value).reduce<Path[]>((result, key) => {\n const paths = getObjectPaths(value[key], parentPath.concat([key]));\n return result.concat(paths);\n }, []);\n};\n","import { CachedSelector, NamedSelector } from './types';\nimport { isComposedKeySelector, KeySelectorComposer } from './keys/createKeySelectorComposer';\nimport { isPropSelector } from './createPropSelector';\nimport { excludeDefaultSelectors } from './keys/createKeySelectorCreator';\nimport { stringComposeKeySelectors } from './keys/stringComposeKeySelectors';\nimport { temporaryAssign } from './_helpers/temporaryAssign';\nimport { withDebugName } from './debug/withDebugName';\nimport { getSelectorName } from './_helpers/getSelectorName';\nimport { isCachedSelector } from './_helpers/isCachedSelector';\nimport { isObject } from './_helpers/isObject';\nimport { getObjectPaths } from './_helpers/getObjectPaths';\nimport { arePathsEqual } from './_helpers/arePathsEqual';\nimport { defaultKeySelector } from './keys/defaultKeySelector';\n\nconst generateBindingName = <P extends object>(binding: P) => {\n const structure = Object.keys(binding).reduce(\n (result, key) => ({\n ...result,\n [key]: '[*]',\n }),\n {},\n );\n const structureKeys = Object.keys(structure).join();\n const structureValues = Object.values(structure).join();\n\n return `${structureKeys} -> ${structureValues}`;\n};\n\n/**\n * The bound selector: what the binding did not supply is what is left to pass.\n * A binding covering every prop leaves an empty argument tuple, which is what a\n * plain selector is in the unified model — so one type covers both cases.\n *\n * The outer condition is the guard against binding a prop the base selector\n * declares as optional with a value that is not.\n */\nexport type BoundSelector<S, P2, P1 extends Partial<P2>, R> =\n P2 extends Pick<P1, keyof P2>\n ? NamedSelector<S, R, Exclude<keyof P1, keyof P2> extends never ? [] : [Omit<P1, keyof P2>]>\n : never;\n\nexport type BoundSelectorOptions<S, P2, P1 extends Partial<P2>, R> = {\n bindingStrategy?: (\n baseSelector: (state: S, props: P1) => R,\n binding: P2,\n ) => (state: S, props: Omit<P1, keyof P2>) => R;\n keySelectorComposer?: KeySelectorComposer;\n};\n\n/**\n * The default binding strategy: applies the binding to the props the caller\n * passed, hands them to the base selector, and puts them back as they were.\n *\n * Almost every binding is a single key — `bound(selector, { positionId })` —\n * and specialising it removes the two allocations the generic path costs per\n * call: the `{ result, rollback }` object and the `rollback` closure. On a\n * graph with a bound selector per row those are the calls that dominate.\n *\n * The `delete` in the restore stays deliberately. Leaving the key behind as\n * `undefined` would be cheaper — it avoids putting the caller's props object\n * into dictionary mode — but it also changes the object's shape, and\n * `useSelector` memoizes props shallowly: a props object that has grown an\n * extra key never again compares equal to a freshly built one, so the\n * memoization the binding exists to protect would be defeated.\n */\nconst applyBinding = <S, P2, P1 extends Partial<P2>, R>(\n baseSelector: (state: S, props: P1) => R,\n binding: P2,\n) => {\n const source = binding as unknown as Record<string, unknown>;\n const keys = Object.keys(source);\n\n if (keys.length === 1) {\n const key = keys[0];\n const value = source[key];\n\n return (state: S, props: Omit<P1, keyof P2> | void) => {\n const target = props as unknown as Record<string, unknown>;\n\n // Nothing to merge into when the selector is read without props, which is\n // what a fully bound selector is called like.\n if (typeof target !== 'object' || target === null) {\n return baseSelector(state, source as unknown as P1);\n }\n\n const previous = target[key];\n\n // A re-entrant call that finds the binding already applied has nothing to\n // save and nothing to restore.\n if (previous === value) {\n return baseSelector(state, props as unknown as P1);\n }\n\n const had = Object.prototype.hasOwnProperty.call(target, key);\n target[key] = value;\n\n try {\n return baseSelector(state, props as unknown as P1);\n } finally {\n if (had) {\n target[key] = previous;\n } else {\n delete target[key];\n }\n }\n };\n }\n\n return (state: S, props: Omit<P1, keyof P2> | void) => {\n // `temporaryAssign` falls back to the binding itself when there are no props\n // to merge into, which is the read of a fully bound selector.\n const { result: nextProps, rollback } = temporaryAssign(\n props as unknown as Record<string, unknown>,\n source,\n );\n\n // Restored through `finally` for the same reason the single-key path does\n // it: the props object belongs to the caller, and a selector that throws\n // must not leave the binding written into it.\n try {\n return baseSelector(state, nextProps as unknown as P1);\n } finally {\n rollback();\n }\n };\n};\n\nexport const createBoundSelector = <S, P2 extends object, P1 extends Partial<P2>, R, OR extends R>(\n baseSelector: (state: S, props: P1) => R,\n binding: P2,\n options: BoundSelectorOptions<S, P2, P1, OR> = {},\n): BoundSelector<S, P2, P1, R> => {\n const bindingStrategy = (options.bindingStrategy as typeof applyBinding) ?? applyBinding;\n\n const keySelectorComposer = options.keySelectorComposer ?? stringComposeKeySelectors;\n\n const boundSelector = bindingStrategy(baseSelector, binding) as unknown as BoundSelector<\n S,\n P2,\n P1,\n R\n >;\n\n Object.assign(boundSelector, baseSelector);\n boundSelector.dependencies = [baseSelector];\n\n withDebugName(boundSelector, () => {\n const baseName = getSelectorName(baseSelector);\n const bindingName = generateBindingName(binding);\n\n return `${baseName} (${bindingName})`;\n });\n\n if (isCachedSelector(baseSelector)) {\n const cachedBoundSelector = boundSelector as unknown as CachedSelector;\n\n if (baseSelector.getMatchingSelector) {\n cachedBoundSelector.getMatchingSelector = bindingStrategy(\n baseSelector.getMatchingSelector,\n binding,\n );\n }\n\n if (baseSelector.removeMatchingSelector) {\n cachedBoundSelector.removeMatchingSelector = bindingStrategy(\n baseSelector.removeMatchingSelector,\n binding,\n );\n }\n\n const baseKeySelector = baseSelector.keySelector;\n\n if (isObject(binding)) {\n const paths = getObjectPaths(binding);\n let keySelectors = isComposedKeySelector(baseKeySelector)\n ? baseKeySelector.dependencies\n : [baseKeySelector];\n\n keySelectors = excludeDefaultSelectors(keySelectors);\n\n keySelectors = keySelectors\n .filter(\n (keySelector) =>\n !isPropSelector(keySelector) ||\n !paths.some((path) => arePathsEqual(keySelector.path, path)),\n )\n .map((keySelector) =>\n isPropSelector(keySelector) ? keySelector : bindingStrategy(keySelector, binding),\n );\n\n if (keySelectors.length === 0) {\n cachedBoundSelector.keySelector = defaultKeySelector;\n } else if (keySelectors.length === 1) {\n const [keySelector] = keySelectors;\n cachedBoundSelector.keySelector = keySelector;\n } else {\n cachedBoundSelector.keySelector = keySelectorComposer(...keySelectors);\n }\n } else {\n cachedBoundSelector.keySelector = bindingStrategy(baseKeySelector, binding);\n }\n }\n\n return boundSelector;\n};\n","import { Selector } from '@veksa/reselect';\nimport { CachedSelector } from './types';\nimport { isCachedSelector } from './_helpers/isCachedSelector';\nimport { defaultKeySelector } from './keys/defaultKeySelector';\n\n/**\n * Creates a selector that always resolves to `undefined`. Used as the \"no link\"\n * branch of a chain (e.g. an optional relation that isn't present).\n *\n * When the base selector is cached, the empty selector is tagged with\n * {@link defaultKeySelector} so that it still passes {@link isCachedSelector}\n * and takes part in key-selector composition. The default key is deliberately\n * the only cache-related metadata copied: an empty selector has no result to\n * memoize, so it needs no `cache` / `getMatchingSelector` of its own, and the\n * default key is dropped by `excludeDefaultSelectors` during composition.\n */\nexport const createEmptySelector = <S, R>(\n baseSelector: Selector<S, R, any[]>,\n): Selector<S, R | undefined> => {\n const emptySelector = () => undefined;\n\n if (isCachedSelector(baseSelector)) {\n (emptySelector as unknown as CachedSelector).keySelector = defaultKeySelector;\n }\n\n return emptySelector;\n};\n","import { CachedSelector, NamedSelector } from './types';\nimport { withDebugName } from './debug/withDebugName';\nimport { getSelectorName } from './_helpers/getSelectorName';\nimport { isCachedSelector } from './_helpers/isCachedSelector';\n\nconst generateMappingName = <P1 extends object, P2>(mapping: (props: P2) => P1) => {\n if (mapping.name) {\n return mapping.name;\n }\n\n const structure = mapping(\n new Proxy(\n {},\n {\n get: (_target, key) => key,\n },\n ) as P2,\n );\n const structureKeys = Object.keys(structure).join();\n const structureValues = Object.values(structure).join();\n\n return `${structureKeys} -> ${structureValues}`;\n};\n\nconst innerCreateAdaptedSelector =\n <S, P1, P2, R>(\n baseSelector: (state: S, props: P1) => R,\n mapping: (props: P2) => P1,\n ): NamedSelector<S, R, [P2]> =>\n (state: S, props: P2) => {\n return baseSelector(state, mapping(props));\n };\n\n/**\n * Rewrites the props a selector reads. Only the props argument changes: the\n * adapted selector takes `[P2]` where the base took `[P1]`, which is the same\n * argument tuple every other creator in the library carries.\n */\nexport const createAdaptedSelector = <S, P1 extends object, P2, R>(\n baseSelector: (state: S, props: P1) => R,\n mapping: (props: P2) => P1,\n) => {\n const adaptedSelector = innerCreateAdaptedSelector(baseSelector, mapping);\n\n Object.assign(adaptedSelector, baseSelector);\n adaptedSelector.dependencies = [baseSelector];\n\n withDebugName(adaptedSelector, () => {\n const baseName = getSelectorName(baseSelector);\n const mappingName = generateMappingName(mapping);\n\n return `${baseName} (${mappingName})`;\n });\n\n if (isCachedSelector(baseSelector)) {\n const cachedAdaptedSelector = adaptedSelector as unknown as CachedSelector;\n\n if (baseSelector.getMatchingSelector) {\n cachedAdaptedSelector.getMatchingSelector = innerCreateAdaptedSelector(\n baseSelector.getMatchingSelector,\n mapping,\n );\n }\n\n if (baseSelector.removeMatchingSelector) {\n cachedAdaptedSelector.removeMatchingSelector = innerCreateAdaptedSelector(\n baseSelector.removeMatchingSelector,\n mapping,\n );\n }\n\n cachedAdaptedSelector.keySelector = innerCreateAdaptedSelector(\n baseSelector.keySelector,\n mapping,\n );\n }\n\n return adaptedSelector;\n};\n","export const stringifyFunction = (source: unknown) => {\n return String(source).replace(/\\s+/g, ' ').trim();\n};\n","import { stringifyFunction } from './stringifyFunction';\n\nexport const generateSelectorKey = (selector: unknown) => {\n const dependencies = (selector as { dependencies?: unknown[] }).dependencies ?? [];\n\n let result = stringifyFunction(selector);\n\n for (let i = dependencies.length - 1; i >= 0; i -= 1) {\n const dependency = dependencies[i];\n\n result += stringifyFunction(dependency);\n }\n\n return result;\n};\n","import { createSelector, createSelectorCreator, Selector } from '@veksa/reselect';\nimport { createCachedSelector, ICacheObject, KeySelector } from '@veksa/re-reselect';\nimport { KeySelectorComposer } from './keys/createKeySelectorComposer';\nimport { isCachedSelector } from './_helpers/isCachedSelector';\nimport { defaultKeySelector } from './keys/defaultKeySelector';\nimport { stringComposeKeySelectors } from './keys/stringComposeKeySelectors';\nimport { createKeySelectorCreator } from './keys/createKeySelectorCreator';\nimport { MergeParams } from './types';\nimport { runInDebug, withDebugName } from './debug/withDebugName';\nimport { defineDynamicSelectorName } from './_helpers/defineDynamicSelectorName';\nimport { getSelectorName } from './_helpers/getSelectorName';\nimport { generateSelectorKey } from './_helpers/generateSelectorKey';\nimport { stringifyFunction } from './_helpers/stringifyFunction';\n\n/**\n * A chain step: given the previous level's result, it returns the selector the\n * next level reads. `Params` is empty for a step that only needs `state`, so a\n * single type covers what used to be a plain and a parametric variant.\n */\nexport type SelectorChain<R1, S1, R2, Params extends readonly any[] = []> = (\n result: R1,\n) => Selector<S1, R2, Params>;\n\nexport type SelectorChainHierarchy<\n C extends SelectorChain<any, any, any, any>,\n H extends SelectorChainHierarchy<any, any>,\n> = C & { parentChain?: H };\n\nexport type CreateSelectorOptions<SelectorCreator extends typeof createSelectorCreator> = {\n selectorCreator: ReturnType<SelectorCreator>;\n cacheObject: ICacheObject;\n};\n\nexport type ChainSelectorOptions<\n SelectorCreator extends typeof createSelectorCreator = typeof createSelectorCreator,\n> = {\n createSelectorOptions?: () => CreateSelectorOptions<SelectorCreator>;\n keySelectorComposer?: KeySelectorComposer;\n};\n\n/**\n * Every level of the chain carries the arguments its selector needs. A level\n * that only reads `state` leaves `Params` empty, and one that reads props adds\n * them — so a step introducing props makes them required for the whole built\n * selector, whether or not the base selector had any.\n *\n * `Params` defaults to empty on the entry point, so that\n * `createChainSelector<State, Result>(selector)` keeps working for callers that\n * spell the type arguments out.\n */\ninterface ChainSelectorResult<S1, R1, Params extends readonly any[]> {\n chain: <S2, R2, Params2 extends readonly any[]>(\n fn: (result: R1) => (state: S2, ...params: Params2) => R2,\n chainOptions?: ChainSelectorOptions,\n ) => ChainSelectorResult<S1 & S2, R2, MergeParams<Params, Params2>>;\n map: <R2>(\n fn: (result: R1) => R2,\n mapOptions?: ChainSelectorOptions,\n ) => ChainSelectorResult<S1, R2, Params>;\n build: () => Selector<S1, R1, Params> & {\n chainHierarchy: SelectorChainHierarchy<any, any> | undefined;\n };\n}\n\nexport function createChainSelector<S1, R1, Params extends readonly any[] = []>(\n selector: (state: S1, ...params: Params) => R1,\n options?: ChainSelectorOptions,\n prevChain?: SelectorChainHierarchy<any, any>,\n): ChainSelectorResult<S1, R1, Params>;\n\nexport function createChainSelector(\n selector: any,\n options?: ChainSelectorOptions,\n prevChain?: any,\n): any {\n const createLevel = (\n fn: any,\n chainOptions: ChainSelectorOptions | undefined,\n isDerivedKeyless: boolean,\n ) => {\n const combinedOptions = {\n ...options,\n ...chainOptions,\n };\n\n const keySelector = isCachedSelector(selector) ? selector.keySelector : defaultKeySelector;\n\n const { createSelectorOptions = () => ({}), keySelectorComposer = stringComposeKeySelectors } =\n combinedOptions;\n\n const keySelectorCreator = createKeySelectorCreator(keySelectorComposer);\n\n /**\n * Nothing below this level is keyed, so the cache would hold a single entry\n * for the lifetime of the chain and every call would still pay for the key\n * computation and the lookup that guard it. A plain memoized selector is the\n * same mapping — re-reselect under a constant key is one `createSelector`\n * instance — without the layer.\n */\n const isKeyless = keySelector === defaultKeySelector;\n\n const selectorOptions = createSelectorOptions() as Partial<CreateSelectorOptions<any>>;\n\n const higherOrderSelector = isKeyless\n ? ((selectorOptions.selectorCreator ?? createSelector) as typeof createSelector)(\n [selector],\n fn,\n )\n : createCachedSelector(\n [selector],\n fn,\n )({\n ...selectorOptions,\n keySelector,\n });\n\n withDebugName(higherOrderSelector, () => {\n const baseName = getSelectorName(selector);\n\n return `higher order for ${baseName} (${stringifyFunction(fn)})`;\n });\n\n type CombineSelector = Selector<any, any, [any]> & {\n dependencies: any;\n cache?: ICacheObject;\n keySelector?: KeySelector<any>;\n };\n\n const combinedSelector: CombineSelector = (state: any, props: any): any => {\n const derivedSelector: any = (higherOrderSelector as any)(state, props);\n\n runInDebug(() => {\n // Debug-only: shows the branch this call took. Nothing outside the debug\n // tooling reads it, so in production it was an array allocated per call and\n // abandoned. The static `[higherOrderSelector]` below still stands.\n combinedSelector.dependencies = [higherOrderSelector, derivedSelector];\n\n const derivedSelectorName = getSelectorName(derivedSelector);\n\n if (!derivedSelectorName) {\n defineDynamicSelectorName(derivedSelector, () => {\n const baseName = getSelectorName(selector);\n const derivedSelectorKey = generateSelectorKey(derivedSelector);\n\n return `derived from ${baseName} (${derivedSelectorKey})`;\n });\n }\n\n defineDynamicSelectorName(combinedSelector, () => {\n const baseName = getSelectorName(selector);\n const dependencyName = getSelectorName(derivedSelector);\n\n return `${baseName} (chained by ${dependencyName})`;\n });\n });\n\n return derivedSelector(state, props);\n };\n\n combinedSelector.dependencies = [higherOrderSelector];\n\n if (!isKeyless) {\n combinedSelector.cache = (higherOrderSelector as unknown as { cache: ICacheObject }).cache;\n }\n\n /**\n * Assigned through a local and written to the selector once. Assigning the\n * property in both branches instead reads as two expando declarations of\n * `keySelector` to TypeScript before 7, which rejects it as a duplicate\n * identifier.\n */\n let levelKeySelector: KeySelector<any>;\n\n if (isDerivedKeyless) {\n /**\n * A `map` level derives a plain `() => output`, never a cached selector, so\n * it contributes nothing to the composed key and the whole composition is\n * known at build time. It is the same call the wrapper below makes, minus\n * the derived selector — so the key is composed exactly as before, once,\n * instead of on every key computation of every level above.\n */\n levelKeySelector = keySelectorCreator({\n inputSelectors: [higherOrderSelector],\n }) as KeySelector<any>;\n } else {\n /**\n * The derived selector's key selector, memoized on the derived selector itself.\n *\n * This used to be a second `createCachedSelector` over `[higherOrderSelector]`,\n * which meant every key computation paid a whole extra cached-selector layer —\n * its own key computation, its own cache lookup, and its own evaluation of\n * `higherOrderSelector` — to produce a value that depends on nothing but the\n * derived selector. A `WeakMap` keyed on that selector is the same mapping with\n * none of the layer, and it shares across cache keys rather than per key.\n *\n * Note what is deliberately *not* memoized: the `(state, props)` pair. `props`\n * is mutated in place by `createBoundSelector`, so two calls can pass the same\n * object reference with different contents, and a reference-keyed cache would\n * hand back a stale selector.\n */\n const derivedKeySelectors = new WeakMap<object, KeySelector<any>>();\n\n levelKeySelector = (state: any, props: any) => {\n const derivedSelector: any = (higherOrderSelector as any)(state, props);\n\n let derivedKeySelector = derivedKeySelectors.get(derivedSelector);\n\n if (derivedKeySelector === undefined) {\n derivedKeySelector = keySelectorCreator({\n inputSelectors: [higherOrderSelector, derivedSelector],\n }) as KeySelector<any>;\n\n derivedKeySelectors.set(derivedSelector, derivedKeySelector);\n }\n\n return (derivedKeySelector as any)(state, props);\n };\n }\n\n /**\n * When nothing keyed is left the composition yields the default key, and\n * leaving the property off is what lets the next level skip its cache too.\n * The wrapper above is a fresh closure, so only a `map` level can land here\n * with the default.\n */\n if (levelKeySelector !== defaultKeySelector) {\n combinedSelector.keySelector = levelKeySelector;\n }\n\n withDebugName(combinedSelector, () => {\n const baseName = getSelectorName(selector);\n\n return `${baseName} (will be chained ${stringifyFunction(fn)})`;\n });\n\n const nextPrevChain = Object.assign(fn, {\n parentChain: prevChain,\n });\n\n return createChainSelector(combinedSelector, combinedOptions, nextPrevChain);\n };\n\n const chain = (fn: any, chainOptions?: ChainSelectorOptions) => {\n return createLevel(fn, chainOptions, false);\n };\n\n const map = (fn: (result: any) => any, mapOptions?: ChainSelectorOptions) => {\n const mapSelector = (result: any) => {\n const output = fn(result);\n const mapSelector = () => output;\n\n withDebugName(mapSelector, () => {\n const baseName = getSelectorName(selector);\n\n return `mapped from ${baseName} (${stringifyFunction(fn)})`;\n });\n\n return mapSelector;\n };\n\n return createLevel(mapSelector, mapOptions, true);\n };\n\n const build = () => {\n return Object.assign(selector, {\n chainHierarchy: prevChain,\n });\n };\n\n return {\n chain,\n map,\n build,\n };\n}\n","import { createSelector, Selector, SelectorResultArray } from '@veksa/reselect';\nimport { AnySelector, MergedParams, MergedState } from './types';\n\n/**\n * Runs a group of selectors and collects their results positionally.\n *\n * The selectors are inferred as a tuple rather than an array, which is what\n * makes the result a tuple of the individual result types and lets `state` and\n * the extra arguments be merged per position. An array would collapse them into\n * a union and resolve everything past `state` to `never`, which is why the\n * plain and the parametric case used to need an overload each.\n */\nexport function createSequenceSelector<Selectors extends readonly AnySelector[]>(\n selectors: [...Selectors],\n selectorCreator?: typeof createSelector,\n): Selector<MergedState<Selectors>, SelectorResultArray<Selectors>, MergedParams<Selectors>>;\n\nexport function createSequenceSelector(selectors: any, selectorCreator = createSelector) {\n return selectorCreator(selectors, (...results: unknown[]) => results);\n}\n","import { createSelector, Selector, SelectorResultArray } from '@veksa/reselect';\nimport { createCachedSelector, PolymorphicCachedOptions } from '@veksa/re-reselect';\nimport { createSequenceSelector } from './createSequenceSelector';\nimport { AnySelector, MergedParams, MergedState } from './types';\n\n/**\n * The cached counterpart of {@link createSequenceSelector}. The inferred tuple\n * reaches `PolymorphicCachedOptions` as-is, so re-reselect types the caller's\n * `keySelector` with the exact arguments of the group.\n */\nexport function createCachedSequenceSelector<Selectors extends readonly AnySelector[]>(\n selectors: [...Selectors],\n): (\n options: PolymorphicCachedOptions<Selectors, SelectorResultArray<Selectors>>,\n) => Selector<MergedState<Selectors>, SelectorResultArray<Selectors>, MergedParams<Selectors>>;\n\nexport function createCachedSequenceSelector(selectors: any): any {\n return createSequenceSelector(\n selectors,\n createCachedSelector as unknown as typeof createSelector,\n );\n}\n","import { createStructuredSelector as reselectStructuredSelector } from '@veksa/reselect';\n\nexport const createStructuredSelector = reselectStructuredSelector;\n","import { createSelector, Selector, SelectorResultsMap, SelectorsObject } from '@veksa/reselect';\nimport { createCachedSelector, PolymorphicCachedOptions } from '@veksa/re-reselect';\nimport { createStructuredSelector } from './createStructuredSelector';\nimport { MergedParams, MergedState } from './types';\n\n/**\n * The input selectors as re-reselect reads them when typing the caller's\n * `keySelector`: it takes `state` and the extra arguments off the group, and\n * both are already merged here. Putting the selectors back in key order would\n * type the arguments no more precisely and would cost a type instantiation per\n * key, capping the batch at roughly fifty fields.\n */\ntype StructuredInputs<M extends SelectorsObject> = Selector<\n MergedState<M>,\n unknown,\n MergedParams<M>\n>[];\n\n/**\n * A single variadic signature replaces the former `Selector` / `ParametricSelector`\n * conditional: `state` and `props` are derived from the selectors object, so a\n * parametric input keeps its props type without a separate overload.\n */\nexport function createCachedStructuredSelector<M extends SelectorsObject>(\n selectors: M,\n): (\n options: PolymorphicCachedOptions<StructuredInputs<M>, SelectorResultsMap<M>>,\n) => Selector<MergedState<M>, SelectorResultsMap<M>, MergedParams<M>>;\n\nexport function createCachedStructuredSelector(selectors: any): any {\n return createStructuredSelector(\n selectors,\n createCachedSelector as unknown as typeof createSelector,\n );\n}\n","import { createKeySelectorComposer } from './createKeySelectorComposer';\n\nexport const arrayComposeKeySelectors = createKeySelectorComposer(\n (...keySelectors) =>\n (state, props) => {\n let keyPath: unknown[] = [];\n\n for (let i = 0; i < keySelectors.length; i += 1) {\n const key: unknown = keySelectors[i](state, props);\n\n if (Array.isArray(key)) {\n keyPath = keyPath.concat(key);\n } else {\n keyPath.push(key);\n }\n }\n\n return keyPath;\n },\n);\n","import { ICacheObject } from '@veksa/re-reselect';\n\ninterface CacheEntry {\n data: unknown;\n time: number;\n}\n\n/**\n * Buckets used to live in a module-level `Record<string, …>` keyed by an\n * incrementing numeric id, which meant every `get` and `set` coerced that number to\n * a string and re-read the global record — four times per cache hit in `get`.\n * Holding the entries on the instance removes both, and a `Map` keeps non-string\n * keys as they are instead of stringifying them.\n */\nconst buckets = new Set<IntervalMapCache>();\n\nconst cacheLifetime = 10000;\n\nlet garbageCollectorStarted = false;\n\nconst runGarbageCollector = () => {\n const currentTime = Date.now();\n\n buckets.forEach((bucket) => {\n if (bucket.sweep(currentTime)) {\n // A bucket the sweep emptied is dropped from the registry, so a cache whose\n // selector has been discarded stops being reachable from module scope and\n // becomes collectable. Registration happens again on the next `set`, so a\n // cache that is still in use simply re-enters.\n buckets.delete(bucket);\n }\n });\n\n window.setTimeout(runGarbageCollector, cacheLifetime);\n};\n\nexport const initGarbageCollector = () => {\n if (garbageCollectorStarted) {\n return;\n }\n\n if (typeof window !== 'undefined') {\n garbageCollectorStarted = true;\n window.setTimeout(runGarbageCollector, cacheLifetime);\n }\n};\n\nexport class IntervalMapCache implements ICacheObject {\n private entries = new Map<unknown, CacheEntry>();\n\n public set(key: any, data: any) {\n const entry = this.entries.get(key);\n\n if (entry === undefined) {\n buckets.add(this);\n this.entries.set(key, { data, time: Date.now() });\n } else {\n entry.data = data;\n entry.time = Date.now();\n }\n }\n\n public get(key: any) {\n const entry = this.entries.get(key);\n\n if (entry === undefined) {\n return undefined;\n }\n\n entry.time = Date.now();\n\n return entry.data;\n }\n\n public remove(key: any) {\n this.entries.delete(key);\n }\n\n public clear() {\n this.entries.clear();\n buckets.delete(this);\n }\n\n /**\n * Drops entries untouched for longer than the lifetime. Returns whether the\n * bucket is now empty, which is what lets the collector unregister it.\n */\n public sweep(currentTime: number) {\n this.entries.forEach((entry, key) => {\n if (currentTime - entry.time > cacheLifetime) {\n this.entries.delete(key);\n }\n });\n\n return this.entries.size === 0;\n }\n}\n","import { FlatObjectCache, ICacheObject } from '@veksa/re-reselect';\n\nexport type TreeCacheObjectOptions = {\n cacheObjectCreator?: () => ICacheObject;\n};\n\nconst normalizeKey = (key: unknown): unknown[] => (Array.isArray(key) ? key : [key]);\n\nclass TreeCacheNode {\n public cache?: ICacheObject;\n\n public selectorFn?: unknown;\n}\n\nexport class TreeCache implements ICacheObject {\n private readonly cacheObjectCreator: () => ICacheObject;\n\n private root: TreeCacheNode;\n\n constructor(options: TreeCacheObjectOptions) {\n this.cacheObjectCreator = options.cacheObjectCreator ?? (() => new FlatObjectCache());\n\n const root = new TreeCacheNode();\n root.cache = this.cacheObjectCreator();\n this.root = root;\n }\n\n public clear() {\n const root = new TreeCacheNode();\n root.cache = this.cacheObjectCreator();\n this.root = root;\n }\n\n public get(key: unknown) {\n // A scalar key is the common case and `normalizeKey` would wrap it in a fresh\n // array on every lookup. The tree walk for one level is a single cache read, so\n // it is spelled out rather than allocated for.\n if (!Array.isArray(key)) {\n const cacheResponse: unknown = this.root.cache?.get(key);\n\n return cacheResponse instanceof TreeCacheNode ? cacheResponse.selectorFn : undefined;\n }\n\n let currentNode = this.root;\n\n for (let i = 0; i < key.length; i += 1) {\n const item = key[i];\n const cacheResponse: unknown = currentNode.cache?.get(item);\n\n if (cacheResponse instanceof TreeCacheNode) {\n currentNode = cacheResponse;\n } else {\n return undefined;\n }\n }\n\n return currentNode.selectorFn;\n }\n\n public set(key: unknown, selectorFn: unknown) {\n const keyPath = normalizeKey(key);\n let currentNode = this.root;\n\n for (let i = 0; i < keyPath.length; i += 1) {\n const item = keyPath[i];\n\n if (!currentNode.cache) {\n currentNode.cache = this.cacheObjectCreator();\n }\n\n const cacheResponse: unknown = currentNode.cache.get(item);\n\n if (cacheResponse instanceof TreeCacheNode) {\n currentNode = cacheResponse;\n } else {\n const node = new TreeCacheNode();\n currentNode.cache.set(item, node);\n currentNode = node;\n }\n }\n\n currentNode.selectorFn = selectorFn;\n }\n\n public remove(key: unknown) {\n const keyPath = normalizeKey(key);\n let currentNode = this.root;\n\n for (let i = 0; i < keyPath.length; i += 1) {\n const item = keyPath[i];\n const cacheResponse: unknown = currentNode.cache?.get(item);\n\n if (cacheResponse instanceof TreeCacheNode) {\n currentNode = cacheResponse;\n } else {\n return;\n }\n }\n\n currentNode.selectorFn = undefined;\n }\n\n /**\n * Called by re-reselect on every cache operation, so neither the wrapping array\n * nor the `every` callback is allocated here.\n */\n public isValidCacheKey(key: unknown) {\n const rootCache = this.root.cache;\n\n if (rootCache?.isValidCacheKey === undefined) {\n return true;\n }\n\n if (!Array.isArray(key)) {\n return rootCache.isValidCacheKey(key);\n }\n\n for (let i = 0; i < key.length; i += 1) {\n if (!rootCache.isValidCacheKey(key[i])) {\n return false;\n }\n }\n\n return true;\n }\n}\n","/**\n * Bound selectors write the binding into the props object in place and roll it\n * back afterwards (see temporaryAssign.ts), which throws on a frozen target in\n * strict mode. React freezes element props in development, and immer-based\n * stores hand out frozen objects in production too, so the copy stays in both\n * builds — the hooks only ever call this when props actually change.\n */\nexport const unfreezeProps = (props: unknown) => {\n if (typeof props !== 'object' || props === null || !Object.isFrozen(props)) {\n return props;\n }\n\n return Array.isArray(props) ? props.slice() : { ...props };\n};\n","/**\n * Hoisted: react-redux reads the options object on every render, so there is no\n * reason to allocate a fresh one per call site per render. The dev-mode checks\n * re-run the selector to compare results, which these hooks control themselves.\n */\nexport const selectorOptions = {\n devModeChecks: {\n stabilityCheck: 'never',\n identityFunctionCheck: 'never',\n },\n} as const;\n","import { shallowEqual, useSelector as useReduxSelector } from '@veksa/react-redux';\nimport { useRef } from 'react';\nimport { unfreezeProps } from '../_helpers/unfreezeProps';\nimport { selectorOptions } from './selectorOptions';\n\ntype SelectorCache = {\n props: unknown;\n unfrozenProps: unknown;\n selector: Function;\n boundSelector: (state: unknown) => unknown;\n};\n\n/**\n * Reads one selector from the store. Props are compared shallowly, so an inline\n * object literal does not invalidate the selector on every render.\n *\n * A single variadic signature covers both the plain and the parametric case:\n * `Params` is inferred from the selector itself and is empty when the selector\n * takes nothing but `state`, so the props argument is required exactly when the\n * selector declares one. `NoInfer` keeps the props argument out of that\n * inference -- otherwise an inline object literal would widen `Params` instead\n * of being checked against what the selector declares. It defaults to empty so\n * that `useSelector<State, Result>(selector)` -- the call site of the former\n * plain overload -- keeps compiling without spelling the tuple out.\n *\n * Use {@link useSelectors} to read several selectors through a single store\n * subscription.\n */\nexport function useSelector<S extends object, R, Params extends readonly any[] = []>(\n selector: (state: S, ...params: Params) => R,\n ...params: NoInfer<Params>\n): R;\n\nexport function useSelector(selector: Function, ...params: any[]) {\n const props = params[0];\n\n // One ref cell instead of a memo-by-comparator hook, a `useMemo` and a\n // `useCallback`: three hook slots and two dependency arrays per call site,\n // none of which this hook needs — every transition it cares about is an\n // explicit comparison it already performs.\n const cacheRef = useRef<SelectorCache | null>(null);\n\n let cache = cacheRef.current;\n\n if (cache === null) {\n const unfrozenProps = unfreezeProps(props);\n\n cache = cacheRef.current = {\n props,\n unfrozenProps,\n selector,\n boundSelector: (state: unknown) => selector(state, unfrozenProps),\n };\n } else {\n // A new-but-shallow-equal props object keeps the previous reference, so the\n // bound selector stays stable across renders that changed nothing.\n const propsChanged = !shallowEqual(props, cache.props);\n\n if (propsChanged) {\n cache.props = props;\n cache.unfrozenProps = unfreezeProps(props);\n }\n\n if (propsChanged || cache.selector !== selector) {\n const { unfrozenProps } = cache;\n\n cache.selector = selector;\n // react-redux memoizes the selection on the selector's identity, so a new\n // identity is what makes it recompute when the state has not changed but\n // the props or the selector have.\n cache.boundSelector = (state: unknown) => selector(state, unfrozenProps);\n }\n }\n\n return useReduxSelector(cache.boundSelector, selectorOptions);\n}\n","import { shallowEqual, useSelector as useReduxSelector } from '@veksa/react-redux';\nimport { SelectorResultsMap, SelectorsObject } from '@veksa/reselect';\nimport { useRef } from 'react';\nimport { unfreezeProps } from '../_helpers/unfreezeProps';\nimport { MergedParams } from '../types';\nimport { selectorOptions } from './selectorOptions';\n\ntype SelectorsMap = Record<string, Function>;\n\ntype SelectorsCache = {\n keys: string[];\n selectors: Function[];\n props: unknown;\n unfrozenProps: unknown;\n results: unknown[];\n value: Record<string, unknown> | null;\n boundSelector: (state: unknown) => unknown;\n};\n\nconst readSelectors = (cache: SelectorsCache, selectors: SelectorsMap) => {\n const keys: string[] = [];\n const fns: Function[] = [];\n\n for (const key in selectors) {\n if (Object.prototype.hasOwnProperty.call(selectors, key)) {\n keys.push(key);\n fns.push(selectors[key]);\n }\n }\n\n cache.keys = keys;\n cache.selectors = fns;\n // Filled in ascending index order on the first run, so the array stays packed.\n cache.results = [];\n cache.value = null;\n};\n\n/**\n * One pass over the incoming object instead of `shallowEqual`, which would\n * allocate a key array for each side on every render of every call site. Key\n * order is part of the comparison, so a renamed key is caught as well.\n */\nconst hasSameSelectors = (cache: SelectorsCache, selectors: SelectorsMap) => {\n const { keys, selectors: fns } = cache;\n let index = 0;\n\n for (const key in selectors) {\n if (Object.prototype.hasOwnProperty.call(selectors, key)) {\n if (index === keys.length || keys[index] !== key || fns[index] !== selectors[key]) {\n return false;\n }\n\n index++;\n }\n }\n\n return index === keys.length;\n};\n\n/**\n * The structured part: every selector runs, but the result object is rebuilt\n * only when some field actually changed. An unchanged batch keeps its previous\n * reference, so react-redux's default reference equality already bails out —\n * no result allocation and no comparison pass on the steady path.\n */\nconst select = (cache: SelectorsCache, state: unknown) => {\n const { keys, selectors, unfrozenProps, results } = cache;\n const count = keys.length;\n\n let changed = cache.value === null;\n\n for (let index = 0; index < count; index++) {\n const result = selectors[index](state, unfrozenProps);\n\n if (!Object.is(result, results[index])) {\n results[index] = result;\n changed = true;\n }\n }\n\n if (!changed) {\n return cache.value;\n }\n\n const value: Record<string, unknown> = {};\n\n for (let index = 0; index < count; index++) {\n value[keys[index]] = results[index];\n }\n\n cache.value = value;\n\n return value;\n};\n\n/**\n * Reads a batch of selectors through a single store subscription and returns\n * their results as one object.\n *\n * Seven `useSelector` calls in a row component mean seven store listeners,\n * seven `useSyncExternalStore` instances and seven snapshot comparisons per\n * dispatch. This collapses them into one of each; the trade-off is that any\n * tracked state segment changing re-runs the whole batch, which for memoized\n * selectors is a cache hit per field.\n *\n * The memoization lives in the component instance, so rows do not compete for\n * a shared cache the way a module-level structured selector would.\n */\nexport function useSelectors<M extends SelectorsObject>(\n selectors: M,\n ...params: MergedParams<M>\n): SelectorResultsMap<M>;\n\nexport function useSelectors(selectors: SelectorsMap, ...params: any[]) {\n const props = params[0];\n\n const cacheRef = useRef<SelectorsCache | null>(null);\n\n let cache = cacheRef.current;\n\n if (cache === null) {\n const created: SelectorsCache = {\n keys: [],\n selectors: [],\n props,\n unfrozenProps: unfreezeProps(props),\n results: [],\n value: null,\n boundSelector: (state: unknown) => select(created, state),\n };\n\n readSelectors(created, selectors);\n\n cache = cacheRef.current = created;\n } else {\n // An object literal is a new reference on every render, so the batch is\n // compared by content — the common case is the very same selectors.\n const selectorsChanged = !hasSameSelectors(cache, selectors);\n const propsChanged = !shallowEqual(props, cache.props);\n\n if (selectorsChanged) {\n readSelectors(cache, selectors);\n }\n\n if (propsChanged) {\n cache.props = props;\n cache.unfrozenProps = unfreezeProps(props);\n }\n\n if (selectorsChanged || propsChanged) {\n // react-redux memoizes the selection on the selector's identity, so a new\n // identity is what makes it recompute when the state has not changed but\n // the batch or the props have. The closure reads the cell, so it never\n // captures a stale batch.\n const current = cache;\n\n cache.boundSelector = (state: unknown) => select(current, state);\n }\n }\n\n return useReduxSelector(cache.boundSelector, selectorOptions) as Record<string,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AmB,CAAC,iBAAiB,OAAO,SAAS;EAC3D,MAAM,eAAe,EAAA,GAAA,mBAAA,aAAA,CAAc,OAAO,MAAM,KAAK;EAErD,IAAI,kBACF,cAAc,OAAO,SAAS;EAGhC,IAAI,cAAc;GAChB,MAAM,QAAQ;GACd,MAAM,gBAAgB,cAAc,KAAK;EAC3C;EAEA,IAAI,oBAAoB,cAAc;GAKpC,MAAM,UAAU;GAEhB,MAAM,iBAAiB,UAAmB,OAAO,SAAS,KAAK;EACjE;CACF;CAEA,QAAA,GAAA,mBAAA,YAAA,CAAwB,MAAM,eAAe,eAAe;AAC9D"}
1
+ {"version":3,"file":"reselectKit.development.cjs","names":["createSelector","createSelector","createCachedSelector","reselectStructuredSelector","createCachedSelector","FlatObjectCache"],"sources":["../../src/createSegmentSelector.ts","../../src/_helpers/isObject.ts","../../src/_helpers/defineDynamicSelectorName.ts","../../src/debug/debug.ts","../../src/debug/withDebugName.ts","../../src/_helpers/getSelectorName.ts","../../src/createPathSelector.ts","../../src/createPropSelector.ts","../../src/keys/createKeySelectorComposer.ts","../../src/_helpers/arePathsEqual.ts","../../src/keys/defaultKeySelector.ts","../../src/_helpers/isCachedSelector.ts","../../src/keys/createKeySelectorCreator.ts","../../src/keys/stringComposeKeySelectors.ts","../../src/_helpers/temporaryAssign.ts","../../src/_helpers/getObjectPaths.ts","../../src/createBoundSelector.ts","../../src/createEmptySelector.ts","../../src/createAdaptedSelector.ts","../../src/_helpers/stringifyFunction.ts","../../src/_helpers/generateSelectorKey.ts","../../src/createChainSelector.ts","../../src/createSequenceSelector.ts","../../src/createCachedSequenceSelector.ts","../../src/createStructuredSelector.ts","../../src/createCachedStructuredSelector.ts","../../src/keys/arrayComposeKeySelectors.ts","../../src/cache/intervalMapCache.ts","../../src/cache/TreeCache.ts","../../src/_helpers/unfreezeProps.ts","../../src/_hooks/selectorOptions.ts","../../src/_hooks/useSelector.ts","../../src/_hooks/useSelectors.ts"],"sourcesContent":["export function createSegmentSelector<State, SelectedSegment extends State | State[keyof State]>(\n fn: (state: State) => SelectedSegment,\n initial: SelectedSegment,\n): (state: State) => SelectedSegment {\n return (state: State) => fn(state) ?? initial;\n}\n","export const isObject = (value: unknown): value is Record<string, unknown> => {\n return value !== null && typeof value === 'object';\n};\n","export const defineDynamicSelectorName = (selector: unknown, selectorNameGetter: () => string) => {\n let overriddenSelectorName: string;\n Object.defineProperty(selector, 'selectorName', {\n configurable: true,\n get: () => overriddenSelectorName ?? selectorNameGetter(),\n set: (value: string) => {\n overriddenSelectorName = value;\n },\n });\n};\n","let debugMode = false;\n\nexport const isDebugMode = () => debugMode;\n\nexport const setDebugMode = (value: boolean) => {\n debugMode = value;\n};\n","import { defineDynamicSelectorName } from '../_helpers/defineDynamicSelectorName';\nimport { isDebugMode } from './debug';\n\n/**\n * Runs `callback` only outside production and only while debug mode is enabled.\n * Centralizes the `NODE_ENV` / `isDebugMode` guard that the selector factories\n * would otherwise repeat around every debug-name assignment.\n */\nexport const runInDebug = (callback: () => void) => {\n /* istanbul ignore else */\n if (process.env.NODE_ENV !== 'production') {\n /* istanbul ignore else */\n if (isDebugMode()) {\n callback();\n }\n }\n};\n\n/**\n * Assigns a lazily-computed debug name to `selector`, guarded by\n * {@link runInDebug}. Covers the common single-name case; use `runInDebug`\n * directly when a block needs to name several selectors at once.\n */\nexport const withDebugName = (selector: unknown, selectorNameGetter: () => string) => {\n runInDebug(() => {\n defineDynamicSelectorName(selector, selectorNameGetter);\n });\n};\n","export const getSelectorName = (selector: { name: string; selectorName?: string }): string => {\n if ('selectorName' in selector && selector.selectorName) {\n return selector.selectorName;\n }\n\n return selector.name;\n};\n","import { NamedSelector, Path } from './types';\nimport { isObject } from './_helpers/isObject';\nimport { withDebugName } from './debug/withDebugName';\nimport { getSelectorName } from './_helpers/getSelectorName';\n\nexport type Defined<T> = Exclude<T, undefined>;\n\nexport type IsOptional<T> = undefined extends T ? true : null extends T ? true : false;\n\nexport type IsObject<T> = T extends object ? true : false;\n\n/**\n * The selector a path builder produces. `Params` is carried through untouched\n * from the base selector: walking a path changes the result, never the\n * arguments, so the plain and the parametric case are the same type.\n */\nexport type PathSelector<S, R, Params extends readonly any[], D> = NamedSelector<\n S,\n R,\n Params,\n D\n> & {\n path: Path;\n};\n\ntype Required<T> = { [P in keyof T]-?: Exclude<T[P], undefined | null> };\n\nexport type RequiredSelectorBuilder<S, R, Params extends readonly any[], D> = R extends object\n ? { [K in keyof R]: () => PathSelector<S, NonNullable<R[K]>, Params, D> }\n : {};\n\nexport type OptionalSelectorBuilder<S, R, Params extends readonly any[], D> = ((\n defaultValue?: R,\n) => PathSelector<S, R extends undefined ? Defined<R> : R, Params, D>) &\n (R extends object\n ? { [K in keyof Required<R>]: () => PathSelector<S, NonNullable<R[K]>, Params, D> }\n : {});\n\nexport type RequiredObjectSelectorWrapper<S, R, Params extends readonly any[], D> = {\n [K in keyof R]-?: IsOptional<R[K]> extends true\n ? OptionalPathSelectorType<S, R[K], Params, D>\n : RequiredPathSelectorType<S, R[K], Params, D>;\n};\n\nexport type OptionalObjectSelectorWrapper<S, R, Params extends readonly any[], D> = {\n [K in keyof R]-?: OptionalPathSelectorType<S, R[K], Params, D>;\n};\n\nexport type RequiredArraySelectorWrapper<S, R, Params extends readonly any[], D> = {\n length: RequiredPathSelectorType<S, number, Params, D>;\n\n [K: number]: IsOptional<R> extends true\n ? OptionalPathSelectorType<S, R, Params, D>\n : RequiredPathSelectorType<S, R, Params, D>;\n};\n\nexport type OptionalArraySelectorWrapper<S, R, Params extends readonly any[], D> = {\n length: RequiredPathSelectorType<S, number, Params, D>;\n\n [K: number]: OptionalPathSelectorType<S, R, Params, D>;\n};\n\nexport type RequiredDataSelectorWrapper<\n S,\n R,\n Params extends readonly any[],\n D,\n> = R extends unknown[]\n ? RequiredArraySelectorWrapper<S, R[number], Params, D>\n : IsObject<R> extends true\n ? RequiredObjectSelectorWrapper<S, R, Params, D>\n : RequiredSelectorBuilder<S, R, Params, D>;\n\nexport type OptionalDataSelectorWrapper<\n S,\n R,\n Params extends readonly any[],\n D,\n> = R extends unknown[]\n ? OptionalArraySelectorWrapper<S, R[number], Params, D>\n : IsObject<R> extends true\n ? OptionalObjectSelectorWrapper<S, R, Params, D>\n : OptionalSelectorBuilder<S, R, Params, D>;\n\nexport type RequiredPathSelectorType<\n S,\n R,\n Params extends readonly any[],\n D,\n> = RequiredSelectorBuilder<S, R, Params, D> &\n RequiredDataSelectorWrapper<S, NonNullable<R>, Params, D>;\n\nexport type OptionalPathSelectorType<\n S,\n R,\n Params extends readonly any[],\n D,\n> = OptionalSelectorBuilder<S, R, Params, D> &\n OptionalDataSelectorWrapper<S, NonNullable<R>, Params, D>;\n\nconst defaultVoidFunction = () => {\n return;\n};\n\n/** @internal */\nexport const innerCreatePathSelector = (\n baseSelector: (...args: unknown[]) => unknown,\n path: Path = [],\n applyMeta: (selector: unknown) => void = defaultVoidFunction,\n): unknown => {\n const pathLength = path.length;\n\n const proxyTarget = (defaultValue?: unknown) => {\n function resultSelector(state?: unknown, props?: unknown) {\n // Selectors are almost always reached as `(state)` or `(state, props)`, and\n // dispatching those two arities directly keeps `arguments` out of the hot\n // path. The arity is matched exactly rather than always passing two: reselect\n // memoizes on the argument list, so handing a one-argument selector a second\n // `undefined` would change its cache key.\n let result: unknown;\n\n if (arguments.length === 2) {\n result = baseSelector(state, props);\n } else if (arguments.length === 1) {\n result = baseSelector(state);\n } else {\n result = baseSelector.apply(null, arguments as unknown as unknown[]);\n }\n\n for (let i = 0; i < pathLength && isObject(result); i += 1) {\n result = result[path[i]];\n }\n\n // For optional properties, we want to exclude undefined from the return type\n // but still return undefined if the property doesn't exist\n return result === undefined ? defaultValue : result;\n }\n\n Object.assign(resultSelector, baseSelector, { path });\n resultSelector.dependencies = [baseSelector];\n\n applyMeta(resultSelector);\n\n withDebugName(resultSelector, () => {\n const baseName = getSelectorName(baseSelector);\n\n return [baseName, ...path].join('.');\n });\n\n return resultSelector;\n };\n\n return new Proxy(proxyTarget, {\n get: (_target, key) => {\n return innerCreatePathSelector(baseSelector, [...path, String(key)], applyMeta);\n },\n });\n};\n\n/**\n * Builds a proxy that turns property access into a selector reading that path.\n *\n * `Params` is inferred straight from the base selector, so the plain and the\n * parametric case share one signature — and one set of builder types — instead\n * of being told apart by a conditional in the parameter position. It defaults\n * to empty so that `createPathSelector<State, Result>(selector)` keeps working\n * for callers that spell the type arguments out.\n */\nexport function createPathSelector<S, R, Params extends readonly any[] = []>(\n baseSelector: (state: S, ...params: Params) => R,\n): IsOptional<R> extends true\n ? OptionalPathSelectorType<S, R, Params, [typeof baseSelector]>\n : RequiredPathSelectorType<S, R, Params, [typeof baseSelector]> {\n return innerCreatePathSelector(baseSelector as (...args: unknown[]) => unknown) as any;\n}\n","import { Selector } from '@veksa/reselect';\nimport { innerCreatePathSelector, RequiredPathSelectorType } from './createPathSelector';\nimport { Path } from './types';\n\nconst propSelectorSymbol = Symbol.for('PropSelector');\n\nexport const isPropSelector = (selector: unknown): selector is { path: Path } => {\n return selector instanceof Object && propSelectorSymbol in selector;\n};\n\nexport function createPropSelector<P>(): RequiredPathSelectorType<\n unknown,\n P,\n [P],\n [Selector<unknown, P, [P]>]\n> {\n const propsSelector = (_state: unknown, props: unknown) => props;\n\n const applyMeta = (selector: unknown) => {\n Object.defineProperty(selector, propSelectorSymbol, { value: true });\n };\n\n return innerCreatePathSelector(propsSelector, [], applyMeta) as RequiredPathSelectorType<\n unknown,\n P,\n [P],\n [Selector<unknown, P, [P]>]\n >;\n}\n","import { KeySelector } from '@veksa/re-reselect';\nimport { MergedParams, MergedState } from '../types';\n\nexport const composedKeySelectorSymbol = Symbol.for('ComposedKeySelector');\n\n/**\n * The loosest shape a key selector can take: a function of `state` plus any\n * number of extra arguments (props, ...). Used for variadic tuple inference.\n */\ntype AnyKeySelector = KeySelector<any>;\n\n/**\n * The key selector produced by a {@link KeySelectorComposer}: a function that\n * intersects the `state` and the extra arguments of every composed key\n * selector, tagged with the original inputs as `dependencies`.\n */\nexport type OutputKeySelector<\n S,\n Params extends readonly any[],\n D extends readonly AnyKeySelector[],\n> = ((state: S, ...params: Params) => unknown) & {\n dependencies: D;\n};\n\n/**\n * Composes N key selectors into a single one. A single variadic signature with\n * tuple inference replaces the former per-arity overload set; `state` and the\n * extra arguments are merged by the same helpers every other multi-selector\n * creator in the library uses.\n */\nexport type KeySelectorComposer = <Ks extends readonly AnyKeySelector[]>(\n ...keySelectors: Ks\n) => OutputKeySelector<MergedState<Ks>, MergedParams<Ks>, Ks>;\n\nexport function isComposedKeySelector(\n keySelector: AnyKeySelector,\n): keySelector is AnyKeySelector & { dependencies: AnyKeySelector[] } {\n return 'dependencies' in keySelector && composedKeySelectorSymbol in keySelector;\n}\n\nexport function createKeySelectorComposer(\n baseKeySelectorComposer: (...keySelectors: AnyKeySelector[]) => AnyKeySelector,\n): KeySelectorComposer {\n return ((...keySelectors: AnyKeySelector[]) => {\n const resultSelector = baseKeySelectorComposer(...keySelectors) as AnyKeySelector & {\n dependencies: AnyKeySelector[];\n };\n\n resultSelector.dependencies = keySelectors;\n\n Object.defineProperty(resultSelector, composedKeySelectorSymbol, {\n value: true,\n });\n\n return resultSelector;\n }) as KeySelectorComposer;\n}\n","import { Path } from '../types';\n\nexport const arePathsEqual = (path: Path, anotherPath: Path) => {\n if (path.length !== anotherPath.length) {\n return false;\n }\n\n for (let i = 0; i < path.length; i += 1) {\n if (path[i] !== anotherPath[i]) {\n return false;\n }\n }\n\n return true;\n};\n","export const defaultKeySelector = () => '<DefaultKey>';\n","import { CachedSelector } from '../types';\n\nexport const isCachedSelector = (selector: unknown): selector is CachedSelector => {\n return (\n selector instanceof Object &&\n 'keySelector' in selector &&\n typeof (selector as CachedSelector).keySelector === 'function'\n );\n};\n","import { KeySelector } from '@veksa/re-reselect';\nimport { isPropSelector } from '../createPropSelector';\nimport { isComposedKeySelector, KeySelectorComposer } from './createKeySelectorComposer';\nimport { arePathsEqual } from '../_helpers/arePathsEqual';\nimport { defaultKeySelector } from './defaultKeySelector';\nimport { isCachedSelector } from '../_helpers/isCachedSelector';\n\nconst areSelectorsEqual = (selector: unknown, another: unknown) => {\n if (selector === another) {\n return true;\n }\n\n if (isPropSelector(selector) && isPropSelector(another)) {\n return arePathsEqual(selector.path, another.path);\n }\n\n return false;\n};\n\nconst flatKeySelectors = <S>(keySelectors: KeySelector<S>[]) => {\n const result: typeof keySelectors = [];\n\n for (let i = 0; i < keySelectors.length; i += 1) {\n const keySelector = keySelectors[i];\n\n if (isComposedKeySelector(keySelector)) {\n result.push(...flatKeySelectors(keySelector.dependencies));\n } else {\n result.push(keySelector);\n }\n }\n\n return result;\n};\n\nconst uniqKeySelectors = <S>(keySelectors: KeySelector<S>[]) => {\n const result: typeof keySelectors = [];\n\n for (let i = 0; i < keySelectors.length; i += 1) {\n const keySelector = keySelectors[i];\n\n const isKeySelectorAdded = result.some((resultKeySelector) =>\n areSelectorsEqual(keySelector, resultKeySelector),\n );\n if (!isKeySelectorAdded) {\n result.push(keySelector);\n }\n }\n\n return result;\n};\n\nexport const excludeDefaultSelectors = <S>(keySelectors: KeySelector<S>[]) => {\n const result: typeof keySelectors = [];\n\n for (let i = 0; i < keySelectors.length; i += 1) {\n const keySelector = keySelectors[i];\n\n if (keySelector !== defaultKeySelector) {\n result.push(keySelector);\n }\n }\n\n return result;\n};\n\nexport function createKeySelectorCreator(\n keySelectorComposer: KeySelectorComposer,\n): <S, D>(selectorInputs: { inputSelectors: D; keySelector?: KeySelector<S> }) => KeySelector<S> {\n return <S>({\n inputSelectors,\n keySelector,\n }: {\n inputSelectors: unknown;\n keySelector?: KeySelector<S>;\n }) => {\n let keySelectors: KeySelector<S>[] = [];\n\n if (keySelector) {\n keySelectors.push(keySelector);\n }\n\n (inputSelectors as unknown[]).forEach((selector) => {\n if (isCachedSelector(selector)) {\n keySelectors.push(selector.keySelector);\n }\n });\n\n keySelectors = flatKeySelectors(keySelectors);\n keySelectors = uniqKeySelectors(keySelectors);\n keySelectors = excludeDefaultSelectors(keySelectors);\n\n if (keySelectors.length === 0) {\n return defaultKeySelector;\n }\n\n if (keySelectors.length === 1) {\n const [resultSelector] = keySelectors;\n return resultSelector;\n }\n\n // The composer infers a `UnionToIntersection` state from the runtime array,\n // which TS can't see as identical to `S`; narrow it back for the caller.\n return keySelectorComposer(...keySelectors) as KeySelector<S>;\n };\n}\n","import { createKeySelectorComposer } from './createKeySelectorComposer';\n\nexport const stringComposeKeySelectors = createKeySelectorComposer(\n (...keySelectors) =>\n (state, props) => {\n let key: unknown = keySelectors[0](state, props);\n\n for (let i = 1; i < keySelectors.length; i += 1) {\n key += ':';\n key += keySelectors[i](state, props);\n }\n\n return key;\n },\n);\n","const noop = () => undefined;\n\nexport function temporaryAssign(\n target: Record<string, unknown>,\n source: Record<string, unknown>,\n): {\n result: Record<string, unknown>;\n rollback: () => void;\n} {\n if (typeof target !== 'object' || target === null) {\n return {\n result: source,\n rollback: noop,\n };\n }\n\n // Both containers and the closure are allocated only once something actually has\n // to be restored. This runs on every call of every bound selector, and the usual\n // case is a binding whose keys the target does not have — one entry in\n // `deleteProps`, nothing in `temporary` — while a re-entrant call that finds the\n // binding already applied changes nothing at all and can share `noop`.\n let temporary: Record<string, unknown> | null = null;\n let deleteProps: string[] | null = null;\n\n for (const prop in source as unknown as object) {\n if (Object.prototype.hasOwnProperty.call(source, prop)) {\n const targetProp = target[prop];\n const sourceProp = source[prop];\n\n if (targetProp !== sourceProp) {\n if (Object.prototype.hasOwnProperty.call(target, prop)) {\n if (temporary === null) {\n temporary = {};\n }\n temporary[prop] = targetProp;\n } else {\n if (deleteProps === null) {\n deleteProps = [];\n }\n deleteProps.push(prop);\n }\n\n target[prop] = sourceProp;\n }\n }\n }\n\n if (temporary === null && deleteProps === null) {\n return {\n result: target,\n rollback: noop,\n };\n }\n\n const restore = temporary;\n const remove = deleteProps;\n\n const rollback = () => {\n if (restore !== null) {\n for (const prop in restore) {\n if (Object.prototype.hasOwnProperty.call(restore, prop)) {\n target[prop] = restore[prop];\n }\n }\n }\n\n if (remove !== null) {\n for (const prop of remove) {\n if (Object.prototype.hasOwnProperty.call(target, prop)) {\n delete target[prop];\n }\n }\n }\n };\n\n return {\n result: target,\n rollback,\n };\n}\n","import { Path } from '../types';\nimport { isObject } from './isObject';\n\nexport const getObjectPaths = (value: unknown, parentPath: Path = []): Path[] => {\n if (!isObject(value)) {\n return [parentPath];\n }\n\n return Object.keys(value).reduce<Path[]>((result, key) => {\n const paths = getObjectPaths(value[key], parentPath.concat([key]));\n return result.concat(paths);\n }, []);\n};\n","import { CachedSelector, NamedSelector } from './types';\nimport { isComposedKeySelector, KeySelectorComposer } from './keys/createKeySelectorComposer';\nimport { isPropSelector } from './createPropSelector';\nimport { excludeDefaultSelectors } from './keys/createKeySelectorCreator';\nimport { stringComposeKeySelectors } from './keys/stringComposeKeySelectors';\nimport { temporaryAssign } from './_helpers/temporaryAssign';\nimport { withDebugName } from './debug/withDebugName';\nimport { getSelectorName } from './_helpers/getSelectorName';\nimport { isCachedSelector } from './_helpers/isCachedSelector';\nimport { isObject } from './_helpers/isObject';\nimport { getObjectPaths } from './_helpers/getObjectPaths';\nimport { arePathsEqual } from './_helpers/arePathsEqual';\nimport { defaultKeySelector } from './keys/defaultKeySelector';\n\nconst generateBindingName = <P extends object>(binding: P) => {\n const structure = Object.keys(binding).reduce(\n (result, key) => ({\n ...result,\n [key]: '[*]',\n }),\n {},\n );\n const structureKeys = Object.keys(structure).join();\n const structureValues = Object.values(structure).join();\n\n return `${structureKeys} -> ${structureValues}`;\n};\n\n/**\n * The bound selector: what the binding did not supply is what is left to pass.\n * A binding covering every prop leaves an empty argument tuple, which is what a\n * plain selector is in the unified model — so one type covers both cases.\n *\n * The outer condition is the guard against binding a prop the base selector\n * declares as optional with a value that is not.\n */\nexport type BoundSelector<S, P2, P1 extends Partial<P2>, R> =\n P2 extends Pick<P1, keyof P2>\n ? NamedSelector<S, R, Exclude<keyof P1, keyof P2> extends never ? [] : [Omit<P1, keyof P2>]>\n : never;\n\nexport type BoundSelectorOptions<S, P2, P1 extends Partial<P2>, R> = {\n bindingStrategy?: (\n baseSelector: (state: S, props: P1) => R,\n binding: P2,\n ) => (state: S, props: Omit<P1, keyof P2>) => R;\n keySelectorComposer?: KeySelectorComposer;\n};\n\n/**\n * The default binding strategy: applies the binding to the props the caller\n * passed, hands them to the base selector, and puts them back as they were.\n *\n * Almost every binding is a single key — `bound(selector, { positionId })` —\n * and specialising it removes the two allocations the generic path costs per\n * call: the `{ result, rollback }` object and the `rollback` closure. On a\n * graph with a bound selector per row those are the calls that dominate.\n *\n * The `delete` in the restore stays deliberately. Leaving the key behind as\n * `undefined` would be cheaper — it avoids putting the caller's props object\n * into dictionary mode — but it also changes the object's shape, and\n * `useSelector` memoizes props shallowly: a props object that has grown an\n * extra key never again compares equal to a freshly built one, so the\n * memoization the binding exists to protect would be defeated.\n */\nconst applyBinding = <S, P2, P1 extends Partial<P2>, R>(\n baseSelector: (state: S, props: P1) => R,\n binding: P2,\n) => {\n const source = binding as unknown as Record<string, unknown>;\n const keys = Object.keys(source);\n\n if (keys.length === 1) {\n const key = keys[0];\n const value = source[key];\n\n return (state: S, props: Omit<P1, keyof P2> | void) => {\n const target = props as unknown as Record<string, unknown>;\n\n // Nothing to merge into when the selector is read without props, which is\n // what a fully bound selector is called like.\n if (typeof target !== 'object' || target === null) {\n return baseSelector(state, source as unknown as P1);\n }\n\n const previous = target[key];\n\n // A re-entrant call that finds the binding already applied has nothing to\n // save and nothing to restore.\n if (previous === value) {\n return baseSelector(state, props as unknown as P1);\n }\n\n const had = Object.prototype.hasOwnProperty.call(target, key);\n target[key] = value;\n\n try {\n return baseSelector(state, props as unknown as P1);\n } finally {\n if (had) {\n target[key] = previous;\n } else {\n delete target[key];\n }\n }\n };\n }\n\n return (state: S, props: Omit<P1, keyof P2> | void) => {\n // `temporaryAssign` falls back to the binding itself when there are no props\n // to merge into, which is the read of a fully bound selector.\n const { result: nextProps, rollback } = temporaryAssign(\n props as unknown as Record<string, unknown>,\n source,\n );\n\n // Restored through `finally` for the same reason the single-key path does\n // it: the props object belongs to the caller, and a selector that throws\n // must not leave the binding written into it.\n try {\n return baseSelector(state, nextProps as unknown as P1);\n } finally {\n rollback();\n }\n };\n};\n\nexport const createBoundSelector = <S, P2 extends object, P1 extends Partial<P2>, R, OR extends R>(\n baseSelector: (state: S, props: P1) => R,\n binding: P2,\n options: BoundSelectorOptions<S, P2, P1, OR> = {},\n): BoundSelector<S, P2, P1, R> => {\n const bindingStrategy = (options.bindingStrategy as typeof applyBinding) ?? applyBinding;\n\n const keySelectorComposer = options.keySelectorComposer ?? stringComposeKeySelectors;\n\n const boundSelector = bindingStrategy(baseSelector, binding) as unknown as BoundSelector<\n S,\n P2,\n P1,\n R\n >;\n\n Object.assign(boundSelector, baseSelector);\n boundSelector.dependencies = [baseSelector];\n\n withDebugName(boundSelector, () => {\n const baseName = getSelectorName(baseSelector);\n const bindingName = generateBindingName(binding);\n\n return `${baseName} (${bindingName})`;\n });\n\n if (isCachedSelector(baseSelector)) {\n const cachedBoundSelector = boundSelector as unknown as CachedSelector;\n\n if (baseSelector.getMatchingSelector) {\n cachedBoundSelector.getMatchingSelector = bindingStrategy(\n baseSelector.getMatchingSelector,\n binding,\n );\n }\n\n if (baseSelector.removeMatchingSelector) {\n cachedBoundSelector.removeMatchingSelector = bindingStrategy(\n baseSelector.removeMatchingSelector,\n binding,\n );\n }\n\n const baseKeySelector = baseSelector.keySelector;\n\n if (isObject(binding)) {\n const paths = getObjectPaths(binding);\n let keySelectors = isComposedKeySelector(baseKeySelector)\n ? baseKeySelector.dependencies\n : [baseKeySelector];\n\n keySelectors = excludeDefaultSelectors(keySelectors);\n\n keySelectors = keySelectors\n .filter(\n (keySelector) =>\n !isPropSelector(keySelector) ||\n !paths.some((path) => arePathsEqual(keySelector.path, path)),\n )\n .map((keySelector) =>\n isPropSelector(keySelector) ? keySelector : bindingStrategy(keySelector, binding),\n );\n\n if (keySelectors.length === 0) {\n cachedBoundSelector.keySelector = defaultKeySelector;\n } else if (keySelectors.length === 1) {\n const [keySelector] = keySelectors;\n cachedBoundSelector.keySelector = keySelector;\n } else {\n cachedBoundSelector.keySelector = keySelectorComposer(...keySelectors);\n }\n } else {\n cachedBoundSelector.keySelector = bindingStrategy(baseKeySelector, binding);\n }\n }\n\n return boundSelector;\n};\n","import { Selector } from '@veksa/reselect';\nimport { CachedSelector } from './types';\nimport { isCachedSelector } from './_helpers/isCachedSelector';\nimport { defaultKeySelector } from './keys/defaultKeySelector';\n\n/**\n * Creates a selector that always resolves to `undefined`. Used as the \"no link\"\n * branch of a chain (e.g. an optional relation that isn't present).\n *\n * When the base selector is cached, the empty selector is tagged with\n * {@link defaultKeySelector} so that it still passes {@link isCachedSelector}\n * and takes part in key-selector composition. The default key is deliberately\n * the only cache-related metadata copied: an empty selector has no result to\n * memoize, so it needs no `cache` / `getMatchingSelector` of its own, and the\n * default key is dropped by `excludeDefaultSelectors` during composition.\n */\nexport const createEmptySelector = <S, R>(\n baseSelector: Selector<S, R, any[]>,\n): Selector<S, R | undefined> => {\n const emptySelector = () => undefined;\n\n if (isCachedSelector(baseSelector)) {\n (emptySelector as unknown as CachedSelector).keySelector = defaultKeySelector;\n }\n\n return emptySelector;\n};\n","import { CachedSelector, NamedSelector } from './types';\nimport { withDebugName } from './debug/withDebugName';\nimport { getSelectorName } from './_helpers/getSelectorName';\nimport { isCachedSelector } from './_helpers/isCachedSelector';\n\nconst generateMappingName = <P1 extends object, P2>(mapping: (props: P2) => P1) => {\n if (mapping.name) {\n return mapping.name;\n }\n\n const structure = mapping(\n new Proxy(\n {},\n {\n get: (_target, key) => key,\n },\n ) as P2,\n );\n const structureKeys = Object.keys(structure).join();\n const structureValues = Object.values(structure).join();\n\n return `${structureKeys} -> ${structureValues}`;\n};\n\nconst innerCreateAdaptedSelector =\n <S, P1, P2, R>(\n baseSelector: (state: S, props: P1) => R,\n mapping: (props: P2) => P1,\n ): NamedSelector<S, R, [P2]> =>\n (state: S, props: P2) => {\n return baseSelector(state, mapping(props));\n };\n\n/**\n * Rewrites the props a selector reads. Only the props argument changes: the\n * adapted selector takes `[P2]` where the base took `[P1]`, which is the same\n * argument tuple every other creator in the library carries.\n */\nexport const createAdaptedSelector = <S, P1 extends object, P2, R>(\n baseSelector: (state: S, props: P1) => R,\n mapping: (props: P2) => P1,\n) => {\n const adaptedSelector = innerCreateAdaptedSelector(baseSelector, mapping);\n\n Object.assign(adaptedSelector, baseSelector);\n adaptedSelector.dependencies = [baseSelector];\n\n withDebugName(adaptedSelector, () => {\n const baseName = getSelectorName(baseSelector);\n const mappingName = generateMappingName(mapping);\n\n return `${baseName} (${mappingName})`;\n });\n\n if (isCachedSelector(baseSelector)) {\n const cachedAdaptedSelector = adaptedSelector as unknown as CachedSelector;\n\n if (baseSelector.getMatchingSelector) {\n cachedAdaptedSelector.getMatchingSelector = innerCreateAdaptedSelector(\n baseSelector.getMatchingSelector,\n mapping,\n );\n }\n\n if (baseSelector.removeMatchingSelector) {\n cachedAdaptedSelector.removeMatchingSelector = innerCreateAdaptedSelector(\n baseSelector.removeMatchingSelector,\n mapping,\n );\n }\n\n cachedAdaptedSelector.keySelector = innerCreateAdaptedSelector(\n baseSelector.keySelector,\n mapping,\n );\n }\n\n return adaptedSelector;\n};\n","export const stringifyFunction = (source: unknown) => {\n return String(source).replace(/\\s+/g, ' ').trim();\n};\n","import { stringifyFunction } from './stringifyFunction';\n\nexport const generateSelectorKey = (selector: unknown) => {\n const dependencies = (selector as { dependencies?: unknown[] }).dependencies ?? [];\n\n let result = stringifyFunction(selector);\n\n for (let i = dependencies.length - 1; i >= 0; i -= 1) {\n const dependency = dependencies[i];\n\n result += stringifyFunction(dependency);\n }\n\n return result;\n};\n","import { createSelector, createSelectorCreator, Selector } from '@veksa/reselect';\nimport { createCachedSelector, ICacheObject, KeySelector } from '@veksa/re-reselect';\nimport { KeySelectorComposer } from './keys/createKeySelectorComposer';\nimport { isCachedSelector } from './_helpers/isCachedSelector';\nimport { defaultKeySelector } from './keys/defaultKeySelector';\nimport { stringComposeKeySelectors } from './keys/stringComposeKeySelectors';\nimport { createKeySelectorCreator } from './keys/createKeySelectorCreator';\nimport { MergeParams } from './types';\nimport { runInDebug, withDebugName } from './debug/withDebugName';\nimport { defineDynamicSelectorName } from './_helpers/defineDynamicSelectorName';\nimport { getSelectorName } from './_helpers/getSelectorName';\nimport { generateSelectorKey } from './_helpers/generateSelectorKey';\nimport { stringifyFunction } from './_helpers/stringifyFunction';\n\n/**\n * A chain step: given the previous level's result, it returns the selector the\n * next level reads. `Params` is empty for a step that only needs `state`, so a\n * single type covers what used to be a plain and a parametric variant.\n */\nexport type SelectorChain<R1, S1, R2, Params extends readonly any[] = []> = (\n result: R1,\n) => Selector<S1, R2, Params>;\n\nexport type SelectorChainHierarchy<\n C extends SelectorChain<any, any, any, any>,\n H extends SelectorChainHierarchy<any, any>,\n> = C & { parentChain?: H };\n\nexport type CreateSelectorOptions<SelectorCreator extends typeof createSelectorCreator> = {\n selectorCreator: ReturnType<SelectorCreator>;\n cacheObject: ICacheObject;\n};\n\nexport type ChainSelectorOptions<\n SelectorCreator extends typeof createSelectorCreator = typeof createSelectorCreator,\n> = {\n createSelectorOptions?: () => CreateSelectorOptions<SelectorCreator>;\n keySelectorComposer?: KeySelectorComposer;\n};\n\n/**\n * Every level of the chain carries the arguments its selector needs. A level\n * that only reads `state` leaves `Params` empty, and one that reads props adds\n * them — so a step introducing props makes them required for the whole built\n * selector, whether or not the base selector had any.\n *\n * `Params` defaults to empty on the entry point, so that\n * `createChainSelector<State, Result>(selector)` keeps working for callers that\n * spell the type arguments out.\n */\ninterface ChainSelectorResult<S1, R1, Params extends readonly any[]> {\n chain: <S2, R2, Params2 extends readonly any[]>(\n fn: (result: R1) => (state: S2, ...params: Params2) => R2,\n chainOptions?: ChainSelectorOptions,\n ) => ChainSelectorResult<S1 & S2, R2, MergeParams<Params, Params2>>;\n map: <R2>(\n fn: (result: R1) => R2,\n mapOptions?: ChainSelectorOptions,\n ) => ChainSelectorResult<S1, R2, Params>;\n build: () => Selector<S1, R1, Params> & {\n chainHierarchy: SelectorChainHierarchy<any, any> | undefined;\n };\n}\n\nexport function createChainSelector<S1, R1, Params extends readonly any[] = []>(\n selector: (state: S1, ...params: Params) => R1,\n options?: ChainSelectorOptions,\n prevChain?: SelectorChainHierarchy<any, any>,\n): ChainSelectorResult<S1, R1, Params>;\n\nexport function createChainSelector(\n selector: any,\n options?: ChainSelectorOptions,\n prevChain?: any,\n): any {\n const createLevel = (\n fn: any,\n chainOptions: ChainSelectorOptions | undefined,\n isDerivedKeyless: boolean,\n ) => {\n const combinedOptions = {\n ...options,\n ...chainOptions,\n };\n\n const keySelector = isCachedSelector(selector) ? selector.keySelector : defaultKeySelector;\n\n const { createSelectorOptions = () => ({}), keySelectorComposer = stringComposeKeySelectors } =\n combinedOptions;\n\n const keySelectorCreator = createKeySelectorCreator(keySelectorComposer);\n\n /**\n * Nothing below this level is keyed, so the cache would hold a single entry\n * for the lifetime of the chain and every call would still pay for the key\n * computation and the lookup that guard it. A plain memoized selector is the\n * same mapping — re-reselect under a constant key is one `createSelector`\n * instance — without the layer.\n */\n const isKeyless = keySelector === defaultKeySelector;\n\n const selectorOptions = createSelectorOptions() as Partial<CreateSelectorOptions<any>>;\n\n const higherOrderSelector = isKeyless\n ? ((selectorOptions.selectorCreator ?? createSelector) as typeof createSelector)(\n [selector],\n fn,\n )\n : createCachedSelector(\n [selector],\n fn,\n )({\n ...selectorOptions,\n keySelector,\n });\n\n withDebugName(higherOrderSelector, () => {\n const baseName = getSelectorName(selector);\n\n return `higher order for ${baseName} (${stringifyFunction(fn)})`;\n });\n\n type CombineSelector = Selector<any, any, [any]> & {\n dependencies: any;\n cache?: ICacheObject;\n keySelector?: KeySelector<any>;\n };\n\n const combinedSelector: CombineSelector = (state: any, props: any): any => {\n const derivedSelector: any = (higherOrderSelector as any)(state, props);\n\n runInDebug(() => {\n // Debug-only: shows the branch this call took. Nothing outside the debug\n // tooling reads it, so in production it was an array allocated per call and\n // abandoned. The static `[higherOrderSelector]` below still stands.\n combinedSelector.dependencies = [higherOrderSelector, derivedSelector];\n\n const derivedSelectorName = getSelectorName(derivedSelector);\n\n if (!derivedSelectorName) {\n defineDynamicSelectorName(derivedSelector, () => {\n const baseName = getSelectorName(selector);\n const derivedSelectorKey = generateSelectorKey(derivedSelector);\n\n return `derived from ${baseName} (${derivedSelectorKey})`;\n });\n }\n\n defineDynamicSelectorName(combinedSelector, () => {\n const baseName = getSelectorName(selector);\n const dependencyName = getSelectorName(derivedSelector);\n\n return `${baseName} (chained by ${dependencyName})`;\n });\n });\n\n return derivedSelector(state, props);\n };\n\n combinedSelector.dependencies = [higherOrderSelector];\n\n if (!isKeyless) {\n combinedSelector.cache = (higherOrderSelector as unknown as { cache: ICacheObject }).cache;\n }\n\n /**\n * Assigned through a local and written to the selector once. Assigning the\n * property in both branches instead reads as two expando declarations of\n * `keySelector` to TypeScript before 7, which rejects it as a duplicate\n * identifier.\n */\n let levelKeySelector: KeySelector<any>;\n\n if (isDerivedKeyless) {\n /**\n * A `map` level derives a plain `() => output`, never a cached selector, so\n * it contributes nothing to the composed key and the whole composition is\n * known at build time. It is the same call the wrapper below makes, minus\n * the derived selector — so the key is composed exactly as before, once,\n * instead of on every key computation of every level above.\n */\n levelKeySelector = keySelectorCreator({\n inputSelectors: [higherOrderSelector],\n }) as KeySelector<any>;\n } else {\n /**\n * The derived selector's key selector, memoized on the derived selector itself.\n *\n * This used to be a second `createCachedSelector` over `[higherOrderSelector]`,\n * which meant every key computation paid a whole extra cached-selector layer —\n * its own key computation, its own cache lookup, and its own evaluation of\n * `higherOrderSelector` — to produce a value that depends on nothing but the\n * derived selector. A `WeakMap` keyed on that selector is the same mapping with\n * none of the layer, and it shares across cache keys rather than per key.\n *\n * Note what is deliberately *not* memoized: the `(state, props)` pair. `props`\n * is mutated in place by `createBoundSelector`, so two calls can pass the same\n * object reference with different contents, and a reference-keyed cache would\n * hand back a stale selector.\n */\n const derivedKeySelectors = new WeakMap<object, KeySelector<any>>();\n\n levelKeySelector = (state: any, props: any) => {\n const derivedSelector: any = (higherOrderSelector as any)(state, props);\n\n let derivedKeySelector = derivedKeySelectors.get(derivedSelector);\n\n if (derivedKeySelector === undefined) {\n derivedKeySelector = keySelectorCreator({\n inputSelectors: [higherOrderSelector, derivedSelector],\n }) as KeySelector<any>;\n\n derivedKeySelectors.set(derivedSelector, derivedKeySelector);\n }\n\n return (derivedKeySelector as any)(state, props);\n };\n }\n\n /**\n * When nothing keyed is left the composition yields the default key, and\n * leaving the property off is what lets the next level skip its cache too.\n * The wrapper above is a fresh closure, so only a `map` level can land here\n * with the default.\n */\n if (levelKeySelector !== defaultKeySelector) {\n combinedSelector.keySelector = levelKeySelector;\n }\n\n withDebugName(combinedSelector, () => {\n const baseName = getSelectorName(selector);\n\n return `${baseName} (will be chained ${stringifyFunction(fn)})`;\n });\n\n const nextPrevChain = Object.assign(fn, {\n parentChain: prevChain,\n });\n\n return createChainSelector(combinedSelector, combinedOptions, nextPrevChain);\n };\n\n const chain = (fn: any, chainOptions?: ChainSelectorOptions) => {\n return createLevel(fn, chainOptions, false);\n };\n\n const map = (fn: (result: any) => any, mapOptions?: ChainSelectorOptions) => {\n const mapSelector = (result: any) => {\n const output = fn(result);\n const mapSelector = () => output;\n\n withDebugName(mapSelector, () => {\n const baseName = getSelectorName(selector);\n\n return `mapped from ${baseName} (${stringifyFunction(fn)})`;\n });\n\n return mapSelector;\n };\n\n return createLevel(mapSelector, mapOptions, true);\n };\n\n const build = () => {\n return Object.assign(selector, {\n chainHierarchy: prevChain,\n });\n };\n\n return {\n chain,\n map,\n build,\n };\n}\n","import { createSelector, Selector, SelectorResultArray } from '@veksa/reselect';\nimport { AnySelector, MergedParams, MergedState } from './types';\n\n/**\n * Runs a group of selectors and collects their results positionally.\n *\n * The selectors are inferred as a tuple rather than an array, which is what\n * makes the result a tuple of the individual result types and lets `state` and\n * the extra arguments be merged per position. An array would collapse them into\n * a union and resolve everything past `state` to `never`, which is why the\n * plain and the parametric case used to need an overload each.\n */\nexport function createSequenceSelector<Selectors extends readonly AnySelector[]>(\n selectors: [...Selectors],\n selectorCreator?: typeof createSelector,\n): Selector<MergedState<Selectors>, SelectorResultArray<Selectors>, MergedParams<Selectors>>;\n\nexport function createSequenceSelector(selectors: any, selectorCreator = createSelector) {\n return selectorCreator(selectors, (...results: unknown[]) => results);\n}\n","import { createSelector, Selector, SelectorResultArray } from '@veksa/reselect';\nimport { createCachedSelector, PolymorphicCachedOptions } from '@veksa/re-reselect';\nimport { createSequenceSelector } from './createSequenceSelector';\nimport { AnySelector, MergedParams, MergedState, WithKeyParams } from './types';\n\n/**\n * The cached counterpart of {@link createSequenceSelector}. The inferred tuple\n * reaches `PolymorphicCachedOptions` as-is, so re-reselect types the caller's\n * `keySelector` with the exact arguments of the group.\n *\n * `KeyParams` defaults to those arguments, which is what an inline `keySelector`\n * gets typed from. A `keySelector` that reads props of its own — keying a group\n * of bound selectors by `accountId`, say, where no member declares it — sets it\n * instead, and those props join the group's own on the resulting selector.\n */\nexport function createCachedSequenceSelector<Selectors extends readonly AnySelector[]>(\n selectors: [...Selectors],\n): <KeyParams extends readonly any[] = MergedParams<Selectors>>(\n options: PolymorphicCachedOptions<Selectors, SelectorResultArray<Selectors>, KeyParams>,\n) => Selector<\n MergedState<Selectors>,\n SelectorResultArray<Selectors>,\n WithKeyParams<MergedParams<Selectors>, KeyParams>\n>;\n\nexport function createCachedSequenceSelector(selectors: any): any {\n return createSequenceSelector(\n selectors,\n createCachedSelector as unknown as typeof createSelector,\n );\n}\n","import { createStructuredSelector as reselectStructuredSelector } from '@veksa/reselect';\n\nexport const createStructuredSelector = reselectStructuredSelector;\n","import { createSelector, Selector, SelectorResultsMap, SelectorsObject } from '@veksa/reselect';\nimport { createCachedSelector, PolymorphicCachedOptions } from '@veksa/re-reselect';\nimport { createStructuredSelector } from './createStructuredSelector';\nimport { MergedParams, MergedState, WithKeyParams } from './types';\n\n/**\n * The input selectors as re-reselect reads them when typing the caller's\n * `keySelector`: it takes `state` and the extra arguments off the group, and\n * both are already merged here. Putting the selectors back in key order would\n * type the arguments no more precisely and would cost a type instantiation per\n * key, capping the batch at roughly fifty fields.\n */\ntype StructuredInputs<M extends SelectorsObject> = Selector<\n MergedState<M>,\n unknown,\n MergedParams<M>\n>[];\n\n/**\n * A single variadic signature replaces the former `Selector` / `ParametricSelector`\n * conditional: `state` and `props` are derived from the selectors object, so a\n * parametric input keeps its props type without a separate overload.\n */\nexport function createCachedStructuredSelector<M extends SelectorsObject>(\n selectors: M,\n): <KeyParams extends readonly any[] = MergedParams<M>>(\n options: PolymorphicCachedOptions<StructuredInputs<M>, SelectorResultsMap<M>, KeyParams>,\n) => Selector<MergedState<M>, SelectorResultsMap<M>, WithKeyParams<MergedParams<M>, KeyParams>>;\n\nexport function createCachedStructuredSelector(selectors: any): any {\n return createStructuredSelector(\n selectors,\n createCachedSelector as unknown as typeof createSelector,\n );\n}\n","import { createKeySelectorComposer } from './createKeySelectorComposer';\n\nexport const arrayComposeKeySelectors = createKeySelectorComposer(\n (...keySelectors) =>\n (state, props) => {\n let keyPath: unknown[] = [];\n\n for (let i = 0; i < keySelectors.length; i += 1) {\n const key: unknown = keySelectors[i](state, props);\n\n if (Array.isArray(key)) {\n keyPath = keyPath.concat(key);\n } else {\n keyPath.push(key);\n }\n }\n\n return keyPath;\n },\n);\n","import { ICacheObject } from '@veksa/re-reselect';\n\ninterface CacheEntry {\n data: unknown;\n time: number;\n}\n\n/**\n * Buckets used to live in a module-level `Record<string, …>` keyed by an\n * incrementing numeric id, which meant every `get` and `set` coerced that number to\n * a string and re-read the global record — four times per cache hit in `get`.\n * Holding the entries on the instance removes both, and a `Map` keeps non-string\n * keys as they are instead of stringifying them.\n */\nconst buckets = new Set<IntervalMapCache>();\n\nconst cacheLifetime = 10000;\n\nlet garbageCollectorStarted = false;\n\nconst runGarbageCollector = () => {\n const currentTime = Date.now();\n\n buckets.forEach((bucket) => {\n if (bucket.sweep(currentTime)) {\n // A bucket the sweep emptied is dropped from the registry, so a cache whose\n // selector has been discarded stops being reachable from module scope and\n // becomes collectable. Registration happens again on the next `set`, so a\n // cache that is still in use simply re-enters.\n buckets.delete(bucket);\n }\n });\n\n window.setTimeout(runGarbageCollector, cacheLifetime);\n};\n\nexport const initGarbageCollector = () => {\n if (garbageCollectorStarted) {\n return;\n }\n\n if (typeof window !== 'undefined') {\n garbageCollectorStarted = true;\n window.setTimeout(runGarbageCollector, cacheLifetime);\n }\n};\n\nexport class IntervalMapCache implements ICacheObject {\n private entries = new Map<unknown, CacheEntry>();\n\n public set(key: any, data: any) {\n const entry = this.entries.get(key);\n\n if (entry === undefined) {\n buckets.add(this);\n this.entries.set(key, { data, time: Date.now() });\n } else {\n entry.data = data;\n entry.time = Date.now();\n }\n }\n\n public get(key: any) {\n const entry = this.entries.get(key);\n\n if (entry === undefined) {\n return undefined;\n }\n\n entry.time = Date.now();\n\n return entry.data;\n }\n\n public remove(key: any) {\n this.entries.delete(key);\n }\n\n public clear() {\n this.entries.clear();\n buckets.delete(this);\n }\n\n /**\n * Drops entries untouched for longer than the lifetime. Returns whether the\n * bucket is now empty, which is what lets the collector unregister it.\n */\n public sweep(currentTime: number) {\n this.entries.forEach((entry, key) => {\n if (currentTime - entry.time > cacheLifetime) {\n this.entries.delete(key);\n }\n });\n\n return this.entries.size === 0;\n }\n}\n","import { FlatObjectCache, ICacheObject } from '@veksa/re-reselect';\n\nexport type TreeCacheObjectOptions = {\n cacheObjectCreator?: () => ICacheObject;\n};\n\nconst normalizeKey = (key: unknown): unknown[] => (Array.isArray(key) ? key : [key]);\n\nclass TreeCacheNode {\n public cache?: ICacheObject;\n\n public selectorFn?: unknown;\n}\n\nexport class TreeCache implements ICacheObject {\n private readonly cacheObjectCreator: () => ICacheObject;\n\n private root: TreeCacheNode;\n\n constructor(options: TreeCacheObjectOptions) {\n this.cacheObjectCreator = options.cacheObjectCreator ?? (() => new FlatObjectCache());\n\n const root = new TreeCacheNode();\n root.cache = this.cacheObjectCreator();\n this.root = root;\n }\n\n public clear() {\n const root = new TreeCacheNode();\n root.cache = this.cacheObjectCreator();\n this.root = root;\n }\n\n public get(key: unknown) {\n // A scalar key is the common case and `normalizeKey` would wrap it in a fresh\n // array on every lookup. The tree walk for one level is a single cache read, so\n // it is spelled out rather than allocated for.\n if (!Array.isArray(key)) {\n const cacheResponse: unknown = this.root.cache?.get(key);\n\n return cacheResponse instanceof TreeCacheNode ? cacheResponse.selectorFn : undefined;\n }\n\n let currentNode = this.root;\n\n for (let i = 0; i < key.length; i += 1) {\n const item = key[i];\n const cacheResponse: unknown = currentNode.cache?.get(item);\n\n if (cacheResponse instanceof TreeCacheNode) {\n currentNode = cacheResponse;\n } else {\n return undefined;\n }\n }\n\n return currentNode.selectorFn;\n }\n\n public set(key: unknown, selectorFn: unknown) {\n const keyPath = normalizeKey(key);\n let currentNode = this.root;\n\n for (let i = 0; i < keyPath.length; i += 1) {\n const item = keyPath[i];\n\n if (!currentNode.cache) {\n currentNode.cache = this.cacheObjectCreator();\n }\n\n const cacheResponse: unknown = currentNode.cache.get(item);\n\n if (cacheResponse instanceof TreeCacheNode) {\n currentNode = cacheResponse;\n } else {\n const node = new TreeCacheNode();\n currentNode.cache.set(item, node);\n currentNode = node;\n }\n }\n\n currentNode.selectorFn = selectorFn;\n }\n\n public remove(key: unknown) {\n const keyPath = normalizeKey(key);\n let currentNode = this.root;\n\n for (let i = 0; i < keyPath.length; i += 1) {\n const item = keyPath[i];\n const cacheResponse: unknown = currentNode.cache?.get(item);\n\n if (cacheResponse instanceof TreeCacheNode) {\n currentNode = cacheResponse;\n } else {\n return;\n }\n }\n\n currentNode.selectorFn = undefined;\n }\n\n /**\n * Called by re-reselect on every cache operation, so neither the wrapping array\n * nor the `every` callback is allocated here.\n */\n public isValidCacheKey(key: unknown) {\n const rootCache = this.root.cache;\n\n if (rootCache?.isValidCacheKey === undefined) {\n return true;\n }\n\n if (!Array.isArray(key)) {\n return rootCache.isValidCacheKey(key);\n }\n\n for (let i = 0; i < key.length; i += 1) {\n if (!rootCache.isValidCacheKey(key[i])) {\n return false;\n }\n }\n\n return true;\n }\n}\n","/**\n * Bound selectors write the binding into the props object in place and roll it\n * back afterwards (see temporaryAssign.ts), which throws on a frozen target in\n * strict mode. React freezes element props in development, and immer-based\n * stores hand out frozen objects in production too, so the copy stays in both\n * builds — the hooks only ever call this when props actually change.\n */\nexport const unfreezeProps = (props: unknown) => {\n if (typeof props !== 'object' || props === null || !Object.isFrozen(props)) {\n return props;\n }\n\n return Array.isArray(props) ? props.slice() : { ...props };\n};\n","/**\n * Hoisted: react-redux reads the options object on every render, so there is no\n * reason to allocate a fresh one per call site per render. The dev-mode checks\n * re-run the selector to compare results, which these hooks control themselves.\n */\nexport const selectorOptions = {\n devModeChecks: {\n stabilityCheck: 'never',\n identityFunctionCheck: 'never',\n },\n} as const;\n","import { shallowEqual, useSelector as useReduxSelector } from '@veksa/react-redux';\nimport { useRef } from 'react';\nimport { unfreezeProps } from '../_helpers/unfreezeProps';\nimport { selectorOptions } from './selectorOptions';\n\ntype SelectorCache = {\n props: unknown;\n unfrozenProps: unknown;\n selector: Function;\n boundSelector: (state: unknown) => unknown;\n};\n\n/**\n * Reads one selector from the store. Props are compared shallowly, so an inline\n * object literal does not invalidate the selector on every render.\n *\n * A single variadic signature covers both the plain and the parametric case:\n * `Params` is inferred from the selector itself and is empty when the selector\n * takes nothing but `state`, so the props argument is required exactly when the\n * selector declares one. `NoInfer` keeps the props argument out of that\n * inference -- otherwise an inline object literal would widen `Params` instead\n * of being checked against what the selector declares. It defaults to empty so\n * that `useSelector<State, Result>(selector)` -- the call site of the former\n * plain overload -- keeps compiling without spelling the tuple out.\n *\n * Use {@link useSelectors} to read several selectors through a single store\n * subscription.\n */\nexport function useSelector<S extends object, R, Params extends readonly any[] = []>(\n selector: (state: S, ...params: Params) => R,\n ...params: NoInfer<Params>\n): R;\n\nexport function useSelector(selector: Function, ...params: any[]) {\n const props = params[0];\n\n // One ref cell instead of a memo-by-comparator hook, a `useMemo` and a\n // `useCallback`: three hook slots and two dependency arrays per call site,\n // none of which this hook needs — every transition it cares about is an\n // explicit comparison it already performs.\n const cacheRef = useRef<SelectorCache | null>(null);\n\n let cache = cacheRef.current;\n\n if (cache === null) {\n const unfrozenProps = unfreezeProps(props);\n\n cache = cacheRef.current = {\n props,\n unfrozenProps,\n selector,\n boundSelector: (state: unknown) => selector(state, unfrozenProps),\n };\n } else {\n // A new-but-shallow-equal props object keeps the previous reference, so the\n // bound selector stays stable across renders that changed nothing.\n const propsChanged = !shallowEqual(props, cache.props);\n\n if (propsChanged) {\n cache.props = props;\n cache.unfrozenProps = unfreezeProps(props);\n }\n\n if (propsChanged || cache.selector !== selector) {\n const { unfrozenProps } = cache;\n\n cache.selector = selector;\n // react-redux memoizes the selection on the selector's identity, so a new\n // identity is what makes it recompute when the state has not changed but\n // the props or the selector have.\n cache.boundSelector = (state: unknown) => selector(state, unfrozenProps);\n }\n }\n\n return useReduxSelector(cache.boundSelector, selectorOptions);\n}\n","import { shallowEqual, useSelector as useReduxSelector } from '@veksa/react-redux';\nimport { SelectorResultsMap, SelectorsObject } from '@veksa/reselect';\nimport { useRef } from 'react';\nimport { unfreezeProps } from '../_helpers/unfreezeProps';\nimport { MergedParams } from '../types';\nimport { selectorOptions } from './selectorOptions';\n\ntype SelectorsMap = Record<string, Function>;\n\ntype SelectorsCache = {\n keys: string[];\n selectors: Function[];\n props: unknown;\n unfrozenProps: unknown;\n results: unknown[];\n value: Record<string, unknown> | null;\n boundSelector: (state: unknown) => unknown;\n};\n\nconst readSelectors = (cache: SelectorsCache, selectors: SelectorsMap) => {\n const keys: string[] = [];\n const fns: Function[] = [];\n\n for (const key in selectors) {\n if (Object.prototype.hasOwnProperty.call(selectors, key)) {\n keys.push(key);\n fns.push(selectors[key]);\n }\n }\n\n cache.keys = keys;\n cache.selectors = fns;\n // Filled in ascending index order on the first run, so the array stays packed.\n cache.results = [];\n cache.value = null;\n};\n\n/**\n * One pass over the incoming object instead of `shallowEqual`, which would\n * allocate a key array for each side on every render of every call site. Key\n * order is part of the comparison, so a renamed key is caught as well.\n */\nconst hasSameSelectors = (cache: SelectorsCache, selectors: SelectorsMap) => {\n const { keys, selectors: fns } = cache;\n let index = 0;\n\n for (const key in selectors) {\n if (Object.prototype.hasOwnProperty.call(selectors, key)) {\n if (index === keys.length || keys[index] !== key || fns[index] !== selectors[key]) {\n return false;\n }\n\n index++;\n }\n }\n\n return index === keys.length;\n};\n\n/**\n * The structured part: every selector runs, but the result object is rebuilt\n * only when some field actually changed. An unchanged batch keeps its previous\n * reference, so react-redux's default reference equality already bails out —\n * no result allocation and no comparison pass on the steady path.\n */\nconst select = (cache: SelectorsCache, state: unknown) => {\n const { keys, selectors, unfrozenProps, results } = cache;\n const count = keys.length;\n\n let changed = cache.value === null;\n\n for (let index = 0; index < count; index++) {\n const result = selectors[index](state, unfrozenProps);\n\n if (!Object.is(result, results[index])) {\n results[index] = result;\n changed = true;\n }\n }\n\n if (!changed) {\n return cache.value;\n }\n\n const value: Record<string, unknown> = {};\n\n for (let index = 0; index < count; index++) {\n value[keys[index]] = results[index];\n }\n\n cache.value = value;\n\n return value;\n};\n\n/**\n * Reads a batch of selectors through a single store subscription and returns\n * their results as one object.\n *\n * Seven `useSelector` calls in a row component mean seven store listeners,\n * seven `useSyncExternalStore` instances and seven snapshot comparisons per\n * dispatch. This collapses them into one of each; the trade-off is that any\n * tracked state segment changing re-runs the whole batch, which for memoized\n * selectors is a cache hit per field.\n *\n * The memoization lives in the component instance, so rows do not compete for\n * a shared cache the way a module-level structured selector would.\n */\nexport function useSelectors<M extends SelectorsObject>(\n selectors: M,\n ...params: MergedParams<M>\n): SelectorResultsMap<M>;\n\nexport function useSelectors(selectors: SelectorsMap, ...params: any[]) {\n const props = params[0];\n\n const cacheRef = useRef<SelectorsCache | null>(null);\n\n let cache = cacheRef.current;\n\n if (cache === null) {\n const created: SelectorsCache = {\n keys: [],\n selectors: [],\n props,\n unfrozenProps: unfreezeProps(props),\n results: [],\n value: null,\n boundSelector: (state: unknown) => select(created, state),\n };\n\n readSelectors(created, selectors);\n\n cache = cacheRef.current = created;\n } else {\n // An object literal is a new reference on every render, so the batch is\n // compared by content — the common case is the very same selectors.\n const selectorsChanged = !hasSameSelectors(cache, selectors);\n const propsChanged = !shallowEqual(props, cache.props);\n\n if (selectorsChanged) {\n readSelectors(cache, selectors);\n }\n\n if (propsChanged) {\n cache.props = props;\n cache.unfrozenProps = unfreezeProps(props);\n }\n\n if (selectorsChanged || propsChanged) {\n // react-redux memoizes the selection on the selector's identity, so a new\n // identity is what makes it recompute when the state has not changed but\n // the batch or the props have. The closure reads the cell, so it never\n // captures a stale batch.\n const current = cache;\n\n cache.boundSelector = (state: unknown) => select(current, state);\n }\n }\n\n return useReduxSelector(cache.boundSelector, selectorOptions) as Record<string, unknown>;\n}\n"],"mappings":";;;;;;AAAA,SAAgB,sBACd,IACA,SACmC;CACnC,QAAQ,UAAiB,GAAG,KAAK,KAAK;AACxC;;;ACLA,MAAa,YAAY,UAAqD;CAC5E,OAAO,UAAU,QAAQ,OAAO,UAAU;AAC5C;;;ACFA,MAAa,6BAA6B,UAAmB,uBAAqC;CAChG,IAAI;CACJ,OAAO,eAAe,UAAU,gBAAgB;EAC9C,cAAc;EACd,WAAW,0BAA0B,mBAAmB;EACxD,MAAM,UAAkB;GACtB,yBAAyB;EAC3B;CACF,CAAC;AACH;;;ACTA,IAAI,YAAY;AAEhB,MAAa,oBAAoB;AAEjC,MAAa,gBAAgB,UAAmB;CAC9C,YAAY;AACd;;;;;;;;ACEA,MAAa,cAAc,aAAyB;;CAIhD,IAAI,YAAY,GACd,SAAS;AAGf;;;;;;AAOA,MAAa,iBAAiB,UAAmB,uBAAqC;CACpF,iBAAiB;EACf,0BAA0B,UAAU,kBAAkB;CACxD,CAAC;AACH;;;AC3BA,MAAa,mBAAmB,aAA8D;CAC5F,IAAI,kBAAkB,YAAY,SAAS,cACzC,OAAO,S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