@ngxs/store 21.0.0-dev.master-11f0b49 → 21.0.0-dev.master-18ee86d

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":"ngxs-store-operators.mjs","sources":["../../../packages/store/operators/src/utils.ts","../../../packages/store/operators/src/append.ts","../../../packages/store/operators/src/compose.ts","../../../packages/store/operators/src/iif.ts","../../../packages/store/operators/src/insert-item.ts","../../../packages/store/operators/src/patch.ts","../../../packages/store/operators/src/safe-patch.ts","../../../packages/store/operators/src/update-item.ts","../../../packages/store/operators/src/update-items.ts","../../../packages/store/operators/src/remove-item.ts","../../../packages/store/operators/src/remove-items.ts","../../../packages/store/operators/src/index.ts","../../../packages/store/operators/src/ngxs-store-operators.ts"],"sourcesContent":["import { StateOperator } from './types';\n\nexport const isArray = Array.isArray;\n\nexport type Predicate<T = any> = (value: T | Readonly<T>) => boolean;\n\nconst isFunction = (value: unknown) => typeof value == 'function';\n\nexport const isStateOperator = isFunction as <T>(\n value: T | StateOperator<T>\n) => value is StateOperator<T>;\n\nexport const isPredicate = isFunction as <T>(\n value: Predicate<T> | boolean | number\n) => value is Predicate<T>;\n\nexport const isNumber = (value: unknown): value is number => typeof value === 'number';\n\nexport const invalidIndex = (index: number) => Number.isNaN(index) || index === -1;\n","import { ExistingState, NoInfer, StateOperator } from './types';\nimport { isArray } from './utils';\n\n/**\n * Adds items to the end of an array without mutating the original. Handles\n * the case where the array property does not exist yet, so callers do not\n * need to initialise it before appending. A `null`, `undefined`, or empty\n * `items` argument is treated as a no-op to allow safe pass-through of\n * optional data.\n *\n * @param items - Items to add to the end of the array.\n *\n * @example\n * ```ts\n * // Add a new zebra to the end of the list without touching the rest of state.\n * ctx.setState(\n * patch<AnimalsStateModel>({\n * zebras: append<string>([action.payload])\n * })\n * );\n * ```\n */\nexport function append<T>(items: NoInfer<T[]>): StateOperator<T[]> {\n return function appendOperator(existing: ExistingState<T[]>): T[] {\n // Nothing meaningful to append, so preserve the existing reference\n // to avoid invalidating memoized selectors unnecessarily.\n const itemsNotProvidedButExistingIs = (!items || !items.length) && existing;\n if (itemsNotProvidedButExistingIs) {\n return existing as unknown as T[];\n }\n\n if (isArray(existing)) {\n return existing.concat(items as unknown as ExistingState<T[]>);\n }\n\n // The array property was never initialised, so `items` becomes the\n // initial state rather than being appended to a non-existent array.\n return items as unknown as T[];\n };\n}\n","import { ExistingState, NoInfer, StateOperator } from './types';\n\n/**\n * Chains multiple state operators so they execute left-to-right, each\n * receiving the output of the previous one. Useful when several independent\n * transformations must be applied to the same state slice in a single atomic\n * update, avoiding multiple `setState` calls.\n *\n * @example\n * ```ts\n * // Apply two independent array mutations in one atomic setState call.\n * ctx.setState(\n * compose<AnimalsStateModel>(\n * patch({ zebras: append<string>([action.zebraName]) }),\n * patch({ pandas: removeItem<string>(name => name === action.pandaToRemove) })\n * )\n * );\n * ```\n */\nexport function compose<T>(...operators: NoInfer<StateOperator<T>[]>): StateOperator<T> {\n return function composeOperator(existing: ExistingState<T>): T {\n return operators.reduce(\n (accumulator, operator) => operator(accumulator as ExistingState<T>),\n existing as T\n );\n };\n}\n","import { ExistingState, NoInfer, StateOperator } from './types';\n\nimport { isStateOperator, isPredicate, Predicate } from './utils';\n\nfunction retrieveValue<T>(\n operatorOrValue: StateOperator<T> | T,\n existing: ExistingState<T>\n): T {\n // Delegate to the operator so a derived transformation can be applied\n // rather than substituting a static value.\n if (isStateOperator(operatorOrValue)) {\n const value = operatorOrValue(existing);\n return value as T;\n }\n\n // No else branch was provided, so leave the state unchanged.\n if (operatorOrValue === undefined) {\n return existing as T;\n }\n\n return operatorOrValue as T;\n}\n\n/**\n * Applies one of two operators (or values) based on a condition, keeping\n * conditional logic out of action handlers and inside the state mutation\n * pipeline where it belongs.\n *\n * @param condition - A boolean or a predicate receiving the current state value.\n * Use a predicate when the decision depends on the existing state rather than\n * external data available at dispatch time.\n * @param trueOperatorOrValue - Applied when `condition` is truthy.\n * @param elseOperatorOrValue - Applied when `condition` is falsy. Omit to\n * leave the state unchanged in the false branch.\n *\n * @example\n * ```ts\n * // Only add a panda when the list has fewer than 5 — the cap is enforced\n * // inside the operator so the action handler stays free of branching logic.\n * ctx.setState(\n * patch<AnimalsStateModel>({\n * pandas: iif(\n * pandas => pandas.length < 5,\n * append<string>([action.payload])\n * )\n * })\n * );\n * ```\n */\nexport function iif<T>(\n condition: NoInfer<Predicate<T>> | boolean,\n trueOperatorOrValue: NoInfer<StateOperator<T> | T>,\n elseOperatorOrValue?: NoInfer<StateOperator<T> | T>\n): StateOperator<T> {\n return function iifOperator(existing: ExistingState<T>): T {\n // Normalise to a boolean so both plain booleans and predicates\n // share the same resolution path below.\n let result = !!condition;\n // Predicates receive the current state value so the decision can be\n // based on live state rather than values captured at dispatch time.\n if (isPredicate(condition)) {\n result = condition(existing as T);\n }\n\n if (result) {\n return retrieveValue<T>(trueOperatorOrValue as StateOperator<T> | T, existing);\n }\n\n return retrieveValue<T>(elseOperatorOrValue! as StateOperator<T> | T, existing);\n };\n}\n","import { ExistingState, NoInfer, StateOperator } from './types';\nimport { isArray } from './utils';\n\n/**\n * Inserts an item into an array without mutating the original, satisfying\n * NGXS's immutability requirement. Handles the case where the array property\n * does not exist yet, so callers do not need to initialise it first.\n *\n * @param value - The item to insert. A `null` or `undefined` value is a no-op\n * so that callers can pass through optional data safely.\n * @param beforePosition - Index before which to insert. Omit (or pass a\n * non-positive number) to prepend to the beginning of the array.\n *\n * @example\n * ```ts\n * // Prepend a new zebra (no position = insert at index 0).\n * ctx.setState(\n * patch<AnimalsStateModel>({\n * zebras: insertItem<string>(action.payload)\n * })\n * );\n * ```\n *\n * @example\n * ```ts\n * // Insert before index 2, shifting subsequent items right.\n * ctx.setState(\n * patch<AnimalsStateModel>({\n * zebras: insertItem<string>(action.payload, 2)\n * })\n * );\n * ```\n */\nexport function insertItem<T>(value: NoInfer<T>, beforePosition?: number): StateOperator<T[]> {\n return function insertItemOperator(existing: ExistingState<T[]>): T[] {\n // `== null` covers both `null` and `undefined` while letting falsy\n // values like `0` or `false` through, where `!value` would not.\n if (value == null && existing) {\n return existing as T[];\n }\n\n // The array property may not have been initialised yet; treat it as\n // empty so callers don't have to guard against that case themselves.\n if (!isArray(existing)) {\n return [value as unknown as T];\n }\n\n const clone = existing.slice();\n\n let index = 0;\n\n // `> 0` rather than `>= 0` intentionally: non-numeric values coerce\n // to NaN and fail this check, so no explicit `isNumber` call is needed.\n if (beforePosition! > 0) {\n index = beforePosition!;\n }\n\n clone.splice(index, 0, value as unknown as T);\n return clone;\n };\n}\n","import { ExistingState, NoInfer, StateOperator } from './types';\nimport { isStateOperator } from './utils';\n\ntype NotUndefined<T> = T extends undefined ? never : T;\n\nexport type ɵPatchSpec<T> = { [P in keyof T]?: T[P] | StateOperator<NotUndefined<T[P]>> };\n\n/**\n * Applies a partial update to a state object, only cloning it when at least\n * one property actually changes. This preserves referential equality for\n * unchanged states, preventing unnecessary re-renders in `OnPush` components\n * and keeping memoized selectors from recalculating.\n *\n * Each property in `patchObject` can itself be a state operator, enabling\n * nested immutable updates without manually spreading every level of the tree.\n *\n * @example\n * ```ts\n * // Add an optional property to a state slice without touching existing ones.\n * ctx.setState(\n * patch<AnimalsStateModel>({ monkeys: [] })\n * );\n * ```\n *\n * @example\n * ```ts\n * // Deep update — specify explicit types at each level so TypeScript can\n * // catch property name mistakes in nested patches.\n * ctx.setState(\n * patch<AddressStateModel>({\n * country: patch<AddressStateModel['country']>({\n * city: patch<AddressStateModel['country']['city']>({\n * address: patch<AddressStateModel['country']['city']['address']>({\n * line1: action.line1\n * })\n * })\n * })\n * })\n * );\n * ```\n */\nexport function patch<T extends Record<string, any>>(\n patchObject: NoInfer<ɵPatchSpec<T>>\n): StateOperator<T> {\n return function patchStateOperator(existing: ExistingState<T>): T {\n let clone = null;\n for (const k in patchObject) {\n const newValue = patchObject[k];\n const existingPropValue = existing?.[k];\n const newPropValue = isStateOperator(newValue)\n ? newValue(<any>existingPropValue)\n : newValue;\n if (newPropValue !== existingPropValue) {\n if (!clone) {\n clone = { ...(<any>existing) };\n }\n clone[k] = newPropValue;\n }\n }\n return clone || existing;\n };\n}\n","import { patch, type ɵPatchSpec } from './patch';\nimport type { ExistingState, NoInfer, StateOperator } from './types';\n\n/**\n * Like `patch`, but safe to call when the state slice is `null` or\n * `undefined`. Treats a missing slice as an empty object so the patch is\n * applied against a clean baseline rather than throwing. Useful for lazily\n * initialised state properties or optional sub-states that may not have been\n * set yet.\n *\n * @example\n * ```ts\n * // Update a nested preferences slice that starts as null — no prior\n * // null-check needed; safePatch treats null as an empty object.\n * ctx.setState(\n * patch<UserStateModel>({\n * preferences: safePatch<UserPreferences>({ theme: action.theme })\n * })\n * );\n * ```\n */\nexport function safePatch<T extends object>(\n patchSpec: NoInfer<ɵPatchSpec<T>>\n): StateOperator<T> {\n const patcher = patch(patchSpec as ɵPatchSpec<T>) as unknown as StateOperator<\n Readonly<NonNullable<T>>\n >;\n return function patchSafely(existing: ExistingState<T>): T {\n return patcher(existing ?? ({} as ExistingState<Readonly<NonNullable<T>>>));\n };\n}\n","import { ExistingState, NoInfer, StateOperator } from './types';\n\nimport { isStateOperator, isPredicate, isNumber, invalidIndex, Predicate } from './utils';\n\n/**\n * Replaces or transforms a single array element without cloning elements that\n * did not change, preserving referential equality for the rest of the array.\n * Returns the original array reference when nothing changed, keeping\n * memoized selectors and `OnPush` components from re-rendering unnecessarily.\n *\n * @param selector - The index to update, or a predicate used to locate the\n * item. Prefer a predicate when the item's position may have shifted since the\n * index was last known.\n * @param operatorOrValue - The replacement value, or a state operator applied\n * to the existing element when a derived update is needed.\n *\n * @example\n * ```ts\n * // Rename a panda — locate it by current name so the index doesn't need\n * // to be known ahead of time.\n * ctx.setState(\n * patch<AnimalsStateModel>({\n * pandas: updateItem<string>(\n * name => name === action.payload.name,\n * action.payload.newName\n * )\n * })\n * );\n * ```\n */\nexport function updateItem<T>(\n selector: number | NoInfer<Predicate<T>>,\n operatorOrValue: NoInfer<T> | NoInfer<StateOperator<T>>\n): StateOperator<T[]> {\n return function updateItemOperator(existing: ExistingState<T[]>): T[] {\n let index = -1;\n\n if (isPredicate(selector)) {\n index = existing.findIndex(selector as Predicate<T>);\n } else if (isNumber(selector)) {\n index = selector;\n }\n\n if (invalidIndex(index)) {\n return existing as T[];\n }\n\n let value: T = null!;\n // Resolve the new value before touching the array so we can bail out\n // early and skip the clone when nothing actually changed.\n const theOperatorOrValue = operatorOrValue as T | StateOperator<T>;\n if (isStateOperator(theOperatorOrValue)) {\n value = theOperatorOrValue(existing[index] as ExistingState<T>);\n } else {\n value = theOperatorOrValue;\n }\n\n // Return the original reference to prevent memoized selectors and\n // OnPush components from reacting to a no-op update.\n if (value === existing[index]) {\n return existing as T[];\n }\n\n const clone = existing.slice();\n clone[index] = value as T;\n return clone;\n };\n}\n","import { type StateOperator, type ExistingState, type NoInfer } from './types';\nimport { isStateOperator, type Predicate } from './utils';\n\n/**\n * Replaces or transforms every array element that matches the predicate.\n * Unlike `updateItem`, which stops at the first match, this operator walks\n * the entire array so all qualifying elements are updated in one pass.\n *\n * Always returns a new array reference, even when no elements matched or the\n * values produced by the operator are identical to the originals. Use\n * `updateItem` instead when only a single element needs updating and\n * referential equality on no-op updates matters.\n *\n * @param selector - Predicate used to decide which elements to update.\n * @param operatorOrValue - Replacement value, or a state operator applied\n * to each matching element when a derived update is needed.\n *\n * @example\n * ```ts\n * // Mark every inactive animal as active in one setState call.\n * ctx.setState(\n * patch<AnimalsStateModel>({\n * animals: updateItems<Animal>(\n * animal => !animal.active,\n * patch({ active: true })\n * )\n * })\n * );\n * ```\n */\nexport function updateItems<T>(\n selector: NoInfer<Predicate<T>>,\n operatorOrValue: NoInfer<T> | NoInfer<StateOperator<T>>\n) {\n return function updateItemsOperator(existing: ExistingState<T[]>): T[] {\n if (!Array.isArray(existing)) {\n return [] as T[];\n } else if (existing.length === 0) {\n return existing as T[];\n }\n\n const clone = existing.slice();\n for (let index = 0; index < clone.length; index++) {\n let value = clone[index];\n if (selector(value)) {\n const theOperatorOrValue = operatorOrValue as T | StateOperator<T>;\n if (isStateOperator(theOperatorOrValue)) {\n value = theOperatorOrValue(value as ExistingState<T>);\n } else {\n value = theOperatorOrValue;\n }\n clone[index] = value;\n }\n }\n return clone;\n };\n}\n","import { ExistingState, NoInfer, StateOperator } from './types';\nimport { isPredicate, isNumber, invalidIndex, Predicate } from './utils';\n\n/**\n * Removes a single element from an array without mutating the original.\n * Returns the original array reference when no matching item is found, so\n * memoized selectors are not invalidated by a no-op removal.\n *\n * @param selector - The index to remove, or a predicate used to locate the\n * item. Prefer a predicate when the item's position is not guaranteed to be\n * stable across concurrent state updates.\n *\n * @example\n * ```ts\n * // Remove a panda by name — a predicate is safer than a hard-coded index\n * // because the array order may change between dispatch and execution.\n * ctx.setState(\n * patch<AnimalsStateModel>({\n * pandas: removeItem<string>(name => name === action.payload)\n * })\n * );\n * ```\n */\nexport function removeItem<T>(selector: number | NoInfer<Predicate<T>>): StateOperator<T[]> {\n return function removeItemOperator(existing: ExistingState<T[]>): T[] {\n let index = -1;\n\n if (isPredicate(selector)) {\n index = existing.findIndex(selector);\n } else if (isNumber(selector)) {\n index = selector;\n }\n\n if (invalidIndex(index)) {\n return existing as T[];\n }\n\n const clone = existing.slice();\n clone.splice(index, 1);\n return clone;\n };\n}\n","import { type ExistingState, type NoInfer } from './types';\nimport type { Predicate } from './utils';\n\n/**\n * Removes every array element that matches the predicate. Unlike `removeItem`,\n * which stops at the first match, this operator walks the entire array so all\n * qualifying elements are eliminated in one pass.\n *\n * Returns the original array reference when no elements matched, so memoized\n * selectors are not invalidated by a no-op removal.\n *\n * @param selector - Predicate used to decide which elements to remove.\n * Elements for which the predicate returns `true` are dropped; the rest are kept.\n *\n * @example\n * ```ts\n * // Remove all inactive animals in one setState call.\n * ctx.setState(\n * patch<AnimalsStateModel>({\n * animals: removeItems<Animal>(animal => !animal.active)\n * })\n * );\n * ```\n */\nexport function removeItems<T>(selector: NoInfer<Predicate<T>>) {\n return function removeItemsOperator(existing: ExistingState<T[]>): T[] {\n if (!Array.isArray(existing)) {\n return [] as T[];\n } else if (existing.length === 0) {\n return existing as T[];\n }\n\n const newValues: T[] = [];\n for (let index = 0; index < existing.length; index++) {\n const value = existing[index];\n // Keep elements that do NOT match — the predicate describes what to remove.\n if (selector(value) === false) {\n newValues.push(value);\n }\n }\n\n // Return the original reference when nothing was removed to avoid\n // invalidating memoized selectors on a no-op call.\n // Note: checking length equality (not `newValues.length > 0`) is\n // intentional — the latter would incorrectly return `existing` when\n // all elements were removed and `newValues` is empty.\n return newValues.length === existing.length ? (existing as T[]) : newValues;\n };\n}\n","/**\n * @module\n * @description\n * Entry point for all public APIs of this package.\n */\nexport { append } from './append';\nexport { compose } from './compose';\nexport { iif } from './iif';\nexport { insertItem } from './insert-item';\nexport { patch, type ɵPatchSpec } from './patch';\nexport { safePatch } from './safe-patch';\nexport { isStateOperator, isPredicate, type Predicate } from './utils';\nexport { updateItem } from './update-item';\nexport { updateItems } from './update-items';\nexport { removeItem } from './remove-item';\nexport { removeItems } from './remove-items';\nexport type { ExistingState, NoInfer, StateOperator } from './types';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":"AAEO,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO;AAIpC,MAAM,UAAU,GAAG,CAAC,KAAc,KAAK,OAAO,KAAK,IAAI,UAAU;AAE1D,MAAM,eAAe,GAAG;AAIxB,MAAM,WAAW,GAAG;AAIpB,MAAM,QAAQ,GAAG,CAAC,KAAc,KAAsB,OAAO,KAAK,KAAK,QAAQ;AAE/E,MAAM,YAAY,GAAG,CAAC,KAAa,KAAK,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC;;ACflF;;;;;;;;;;;;;;;;;;AAkBG;AACG,SAAU,MAAM,CAAI,KAAmB,EAAA;IAC3C,OAAO,SAAS,cAAc,CAAC,QAA4B,EA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YAAY,CAAC,KAAK,CAAC,EAAE;AACvB,YAAA,OAAO,QAAe;;AAGxB,QAAA,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,EAAE;AAC9B,QAAA,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;AACtB,QAAA,OAAO,KAAK;AACd,KAAC;AACH;;ACtCA;;;;;;;;;;;;;;;;;;;;AAoBG;AACG,SAAU,WAAW,CAAI,QAA+B,EAAA;IAC5D,OAAO,SAAS,mBAAmB,CAAC,QAA4B,EAAA;QAC9D,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;AAC5B,YAAA,OAAO,EAAS;;AACX,aAAA,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;AAChC,YAAA,OAAO,QAAe;;QAGxB,MAAM,SAAS,GAAQ,EAAE;AACzB,QAAA,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;AACpD,YAAA,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;;AAE7B,YAAA,IAAI,QAAQ,CAAC,KAAK,CAAC,KAAK,KAAK,EAAE;AAC7B,gBAAA,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC;;;;;;;;AASzB,QAAA,OAAO,SAAS,CAAC,MAAM,KAAK,QAAQ,CAAC,MAAM,GAAI,QAAgB,GAAG,SAAS;AAC7E,KAAC;AACH;;AChDA;;;;AAIG;;ACJH;;AAEG;;;;"}
1
+ {"version":3,"file":"ngxs-store-operators.mjs","sources":["../../../packages/store/operators/src/utils.ts","../../../packages/store/operators/src/append.ts","../../../packages/store/operators/src/compose.ts","../../../packages/store/operators/src/iif.ts","../../../packages/store/operators/src/insert-item.ts","../../../packages/store/operators/src/patch.ts","../../../packages/store/operators/src/safe-patch.ts","../../../packages/store/operators/src/update-item.ts","../../../packages/store/operators/src/update-items.ts","../../../packages/store/operators/src/remove-item.ts","../../../packages/store/operators/src/remove-items.ts","../../../packages/store/operators/src/index.ts","../../../packages/store/operators/src/ngxs-store-operators.ts"],"sourcesContent":["import { StateOperator } from './types';\n\nexport const isArray = Array.isArray;\n\nexport type Predicate<T = any> = (value: T | Readonly<T>) => boolean;\n\nconst isFunction = (value: unknown) => typeof value == 'function';\n\nexport const isStateOperator = isFunction as <T>(\n value: T | StateOperator<T>\n) => value is StateOperator<T>;\n\nexport const isPredicate = isFunction as <T>(\n value: Predicate<T> | boolean | number\n) => value is Predicate<T>;\n\nexport const isNumber = (value: unknown): value is number => typeof value === 'number';\n\nexport const invalidIndex = (index: number) => Number.isNaN(index) || index === -1;\n","import { ExistingState, StateOperator } from './types';\nimport { isArray } from './utils';\n\n/**\n * Adds items to the end of an array without mutating the original. Handles\n * the case where the array property does not exist yet, so callers do not\n * need to initialise it before appending. A `null`, `undefined`, or empty\n * `items` argument is treated as a no-op to allow safe pass-through of\n * optional data.\n *\n * @param items - Items to add to the end of the array.\n *\n * @example\n * ```ts\n * // Add a new zebra to the end of the list without touching the rest of state.\n * ctx.setState(\n * patch<AnimalsStateModel>({\n * zebras: append<string>([action.payload])\n * })\n * );\n * ```\n */\nexport function append<T>(items: NoInfer<T[]>): StateOperator<T[]> {\n return function appendOperator(existing: ExistingState<T[]>): T[] {\n // Nothing meaningful to append, so preserve the existing reference\n // to avoid invalidating memoized selectors unnecessarily.\n const itemsNotProvidedButExistingIs = (!items || !items.length) && existing;\n if (itemsNotProvidedButExistingIs) {\n return existing as unknown as T[];\n }\n\n if (isArray(existing)) {\n return existing.concat(items as unknown as ExistingState<T[]>);\n }\n\n // The array property was never initialised, so `items` becomes the\n // initial state rather than being appended to a non-existent array.\n return items as unknown as T[];\n };\n}\n","import { ExistingState, StateOperator } from './types';\n\n/**\n * Chains multiple state operators so they execute left-to-right, each\n * receiving the output of the previous one. Useful when several independent\n * transformations must be applied to the same state slice in a single atomic\n * update, avoiding multiple `setState` calls.\n *\n * @example\n * ```ts\n * // Apply two independent array mutations in one atomic setState call.\n * ctx.setState(\n * compose<AnimalsStateModel>(\n * patch({ zebras: append<string>([action.zebraName]) }),\n * patch({ pandas: removeItem<string>(name => name === action.pandaToRemove) })\n * )\n * );\n * ```\n */\nexport function compose<T>(...operators: NoInfer<StateOperator<T>[]>): StateOperator<T> {\n return function composeOperator(existing: ExistingState<T>): T {\n return operators.reduce(\n (accumulator, operator) => operator(accumulator as ExistingState<T>),\n existing as T\n );\n };\n}\n","import { ExistingState, StateOperator } from './types';\n\nimport { isStateOperator, isPredicate, Predicate } from './utils';\n\nfunction retrieveValue<T>(\n operatorOrValue: StateOperator<T> | T,\n existing: ExistingState<T>\n): T {\n // Delegate to the operator so a derived transformation can be applied\n // rather than substituting a static value.\n if (isStateOperator(operatorOrValue)) {\n const value = operatorOrValue(existing);\n return value as T;\n }\n\n // No else branch was provided, so leave the state unchanged.\n if (operatorOrValue === undefined) {\n return existing as T;\n }\n\n return operatorOrValue as T;\n}\n\n/**\n * Applies one of two operators (or values) based on a condition, keeping\n * conditional logic out of action handlers and inside the state mutation\n * pipeline where it belongs.\n *\n * @param condition - A boolean or a predicate receiving the current state value.\n * Use a predicate when the decision depends on the existing state rather than\n * external data available at dispatch time.\n * @param trueOperatorOrValue - Applied when `condition` is truthy.\n * @param elseOperatorOrValue - Applied when `condition` is falsy. Omit to\n * leave the state unchanged in the false branch.\n *\n * @example\n * ```ts\n * // Only add a panda when the list has fewer than 5 — the cap is enforced\n * // inside the operator so the action handler stays free of branching logic.\n * ctx.setState(\n * patch<AnimalsStateModel>({\n * pandas: iif(\n * pandas => pandas.length < 5,\n * append<string>([action.payload])\n * )\n * })\n * );\n * ```\n */\nexport function iif<T>(\n condition: NoInfer<Predicate<T>> | boolean,\n trueOperatorOrValue: NoInfer<StateOperator<T> | T>,\n elseOperatorOrValue?: NoInfer<StateOperator<T> | T>\n): StateOperator<T> {\n return function iifOperator(existing: ExistingState<T>): T {\n // Normalise to a boolean so both plain booleans and predicates\n // share the same resolution path below.\n let result = !!condition;\n // Predicates receive the current state value so the decision can be\n // based on live state rather than values captured at dispatch time.\n if (isPredicate(condition)) {\n result = condition(existing as T);\n }\n\n if (result) {\n return retrieveValue<T>(trueOperatorOrValue as StateOperator<T> | T, existing);\n }\n\n return retrieveValue<T>(elseOperatorOrValue! as StateOperator<T> | T, existing);\n };\n}\n","import { ExistingState, StateOperator } from './types';\nimport { isArray } from './utils';\n\n/**\n * Inserts an item into an array without mutating the original, satisfying\n * NGXS's immutability requirement. Handles the case where the array property\n * does not exist yet, so callers do not need to initialise it first.\n *\n * @param value - The item to insert. A `null` or `undefined` value is a no-op\n * so that callers can pass through optional data safely.\n * @param beforePosition - Index before which to insert. Omit (or pass a\n * non-positive number) to prepend to the beginning of the array.\n *\n * @example\n * ```ts\n * // Prepend a new zebra (no position = insert at index 0).\n * ctx.setState(\n * patch<AnimalsStateModel>({\n * zebras: insertItem<string>(action.payload)\n * })\n * );\n * ```\n *\n * @example\n * ```ts\n * // Insert before index 2, shifting subsequent items right.\n * ctx.setState(\n * patch<AnimalsStateModel>({\n * zebras: insertItem<string>(action.payload, 2)\n * })\n * );\n * ```\n */\nexport function insertItem<T>(value: NoInfer<T>, beforePosition?: number): StateOperator<T[]> {\n return function insertItemOperator(existing: ExistingState<T[]>): T[] {\n // `== null` covers both `null` and `undefined` while letting falsy\n // values like `0` or `false` through, where `!value` would not.\n if (value == null && existing) {\n return existing as T[];\n }\n\n // The array property may not have been initialised yet; treat it as\n // empty so callers don't have to guard against that case themselves.\n if (!isArray(existing)) {\n return [value as unknown as T];\n }\n\n const clone = existing.slice();\n\n let index = 0;\n\n // `> 0` rather than `>= 0` intentionally: non-numeric values coerce\n // to NaN and fail this check, so no explicit `isNumber` call is needed.\n if (beforePosition! > 0) {\n index = beforePosition!;\n }\n\n clone.splice(index, 0, value as unknown as T);\n return clone;\n };\n}\n","import { ExistingState, StateOperator } from './types';\nimport { isStateOperator } from './utils';\n\ntype NotUndefined<T> = T extends undefined ? never : T;\n\nexport type ɵPatchSpec<T> = { [P in keyof T]?: T[P] | StateOperator<NotUndefined<T[P]>> };\n\n/**\n * Applies a partial update to a state object, only cloning it when at least\n * one property actually changes. This preserves referential equality for\n * unchanged states, preventing unnecessary re-renders in `OnPush` components\n * and keeping memoized selectors from recalculating.\n *\n * Each property in `patchObject` can itself be a state operator, enabling\n * nested immutable updates without manually spreading every level of the tree.\n *\n * @example\n * ```ts\n * // Add an optional property to a state slice without touching existing ones.\n * ctx.setState(\n * patch<AnimalsStateModel>({ monkeys: [] })\n * );\n * ```\n *\n * @example\n * ```ts\n * // Deep update — specify explicit types at each level so TypeScript can\n * // catch property name mistakes in nested patches.\n * ctx.setState(\n * patch<AddressStateModel>({\n * country: patch<AddressStateModel['country']>({\n * city: patch<AddressStateModel['country']['city']>({\n * address: patch<AddressStateModel['country']['city']['address']>({\n * line1: action.line1\n * })\n * })\n * })\n * })\n * );\n * ```\n */\nexport function patch<T extends Record<string, any>>(\n patchObject: NoInfer<ɵPatchSpec<T>>\n): StateOperator<T> {\n return function patchStateOperator(existing: ExistingState<T>): T {\n let clone = null;\n for (const k in patchObject) {\n const newValue = patchObject[k];\n const existingPropValue = existing?.[k];\n const newPropValue = isStateOperator(newValue)\n ? newValue(<any>existingPropValue)\n : newValue;\n if (newPropValue !== existingPropValue) {\n if (!clone) {\n clone = { ...(<any>existing) };\n }\n clone[k] = newPropValue;\n }\n }\n return clone || existing;\n };\n}\n","import { patch, type ɵPatchSpec } from './patch';\nimport type { ExistingState, StateOperator } from './types';\n\n/**\n * Like `patch`, but safe to call when the state slice is `null` or\n * `undefined`. Treats a missing slice as an empty object so the patch is\n * applied against a clean baseline rather than throwing. Useful for lazily\n * initialised state properties or optional sub-states that may not have been\n * set yet.\n *\n * @example\n * ```ts\n * // Update a nested preferences slice that starts as null — no prior\n * // null-check needed; safePatch treats null as an empty object.\n * ctx.setState(\n * patch<UserStateModel>({\n * preferences: safePatch<UserPreferences>({ theme: action.theme })\n * })\n * );\n * ```\n */\nexport function safePatch<T extends object>(\n patchSpec: NoInfer<ɵPatchSpec<T>>\n): StateOperator<T> {\n const patcher = patch(patchSpec as ɵPatchSpec<T>) as unknown as StateOperator<\n Readonly<NonNullable<T>>\n >;\n return function patchSafely(existing: ExistingState<T>): T {\n return patcher(existing ?? ({} as ExistingState<Readonly<NonNullable<T>>>));\n };\n}\n","import { ExistingState, StateOperator } from './types';\n\nimport { isStateOperator, isPredicate, isNumber, invalidIndex, Predicate } from './utils';\n\n/**\n * Replaces or transforms a single array element without cloning elements that\n * did not change, preserving referential equality for the rest of the array.\n * Returns the original array reference when nothing changed, keeping\n * memoized selectors and `OnPush` components from re-rendering unnecessarily.\n *\n * @param selector - The index to update, or a predicate used to locate the\n * item. Prefer a predicate when the item's position may have shifted since the\n * index was last known.\n * @param operatorOrValue - The replacement value, or a state operator applied\n * to the existing element when a derived update is needed.\n *\n * @example\n * ```ts\n * // Rename a panda — locate it by current name so the index doesn't need\n * // to be known ahead of time.\n * ctx.setState(\n * patch<AnimalsStateModel>({\n * pandas: updateItem<string>(\n * name => name === action.payload.name,\n * action.payload.newName\n * )\n * })\n * );\n * ```\n */\nexport function updateItem<T>(\n selector: number | NoInfer<Predicate<T>>,\n operatorOrValue: NoInfer<T> | NoInfer<StateOperator<T>>\n): StateOperator<T[]> {\n return function updateItemOperator(existing: ExistingState<T[]>): T[] {\n let index = -1;\n\n if (isPredicate(selector)) {\n index = existing.findIndex(selector as Predicate<T>);\n } else if (isNumber(selector)) {\n index = selector;\n }\n\n if (invalidIndex(index)) {\n return existing as T[];\n }\n\n let value: T = null!;\n // Resolve the new value before touching the array so we can bail out\n // early and skip the clone when nothing actually changed.\n const theOperatorOrValue = operatorOrValue as T | StateOperator<T>;\n if (isStateOperator(theOperatorOrValue)) {\n value = theOperatorOrValue(existing[index] as ExistingState<T>);\n } else {\n value = theOperatorOrValue;\n }\n\n // Return the original reference to prevent memoized selectors and\n // OnPush components from reacting to a no-op update.\n if (value === existing[index]) {\n return existing as T[];\n }\n\n const clone = existing.slice();\n clone[index] = value as T;\n return clone;\n };\n}\n","import { type StateOperator, type ExistingState } from './types';\nimport { isStateOperator, type Predicate } from './utils';\n\n/**\n * Replaces or transforms every array element that matches the predicate.\n * Unlike `updateItem`, which stops at the first match, this operator walks\n * the entire array so all qualifying elements are updated in one pass.\n *\n * Always returns a new array reference, even when no elements matched or the\n * values produced by the operator are identical to the originals. Use\n * `updateItem` instead when only a single element needs updating and\n * referential equality on no-op updates matters.\n *\n * @param selector - Predicate used to decide which elements to update.\n * @param operatorOrValue - Replacement value, or a state operator applied\n * to each matching element when a derived update is needed.\n *\n * @example\n * ```ts\n * // Mark every inactive animal as active in one setState call.\n * ctx.setState(\n * patch<AnimalsStateModel>({\n * animals: updateItems<Animal>(\n * animal => !animal.active,\n * patch({ active: true })\n * )\n * })\n * );\n * ```\n */\nexport function updateItems<T>(\n selector: NoInfer<Predicate<T>>,\n operatorOrValue: NoInfer<T> | NoInfer<StateOperator<T>>\n) {\n return function updateItemsOperator(existing: ExistingState<T[]>): T[] {\n if (!Array.isArray(existing)) {\n return [] as T[];\n } else if (existing.length === 0) {\n return existing as T[];\n }\n\n const clone = existing.slice();\n for (let index = 0; index < clone.length; index++) {\n let value = clone[index];\n if (selector(value)) {\n const theOperatorOrValue = operatorOrValue as T | StateOperator<T>;\n if (isStateOperator(theOperatorOrValue)) {\n value = theOperatorOrValue(value as ExistingState<T>);\n } else {\n value = theOperatorOrValue;\n }\n clone[index] = value;\n }\n }\n return clone;\n };\n}\n","import { ExistingState, StateOperator } from './types';\nimport { isPredicate, isNumber, invalidIndex, Predicate } from './utils';\n\n/**\n * Removes a single element from an array without mutating the original.\n * Returns the original array reference when no matching item is found, so\n * memoized selectors are not invalidated by a no-op removal.\n *\n * @param selector - The index to remove, or a predicate used to locate the\n * item. Prefer a predicate when the item's position is not guaranteed to be\n * stable across concurrent state updates.\n *\n * @example\n * ```ts\n * // Remove a panda by name — a predicate is safer than a hard-coded index\n * // because the array order may change between dispatch and execution.\n * ctx.setState(\n * patch<AnimalsStateModel>({\n * pandas: removeItem<string>(name => name === action.payload)\n * })\n * );\n * ```\n */\nexport function removeItem<T>(selector: number | NoInfer<Predicate<T>>): StateOperator<T[]> {\n return function removeItemOperator(existing: ExistingState<T[]>): T[] {\n let index = -1;\n\n if (isPredicate(selector)) {\n index = existing.findIndex(selector);\n } else if (isNumber(selector)) {\n index = selector;\n }\n\n if (invalidIndex(index)) {\n return existing as T[];\n }\n\n const clone = existing.slice();\n clone.splice(index, 1);\n return clone;\n };\n}\n","import { type ExistingState } from './types';\nimport type { Predicate } from './utils';\n\n/**\n * Removes every array element that matches the predicate. Unlike `removeItem`,\n * which stops at the first match, this operator walks the entire array so all\n * qualifying elements are eliminated in one pass.\n *\n * Returns the original array reference when no elements matched, so memoized\n * selectors are not invalidated by a no-op removal.\n *\n * @param selector - Predicate used to decide which elements to remove.\n * Elements for which the predicate returns `true` are dropped; the rest are kept.\n *\n * @example\n * ```ts\n * // Remove all inactive animals in one setState call.\n * ctx.setState(\n * patch<AnimalsStateModel>({\n * animals: removeItems<Animal>(animal => !animal.active)\n * })\n * );\n * ```\n */\nexport function removeItems<T>(selector: NoInfer<Predicate<T>>) {\n return function removeItemsOperator(existing: ExistingState<T[]>): T[] {\n if (!Array.isArray(existing)) {\n return [] as T[];\n } else if (existing.length === 0) {\n return existing as T[];\n }\n\n const newValues: T[] = [];\n for (let index = 0; index < existing.length; index++) {\n const value = existing[index];\n // Keep elements that do NOT match — the predicate describes what to remove.\n if (selector(value) === false) {\n newValues.push(value);\n }\n }\n\n // Return the original reference when nothing was removed to avoid\n // invalidating memoized selectors on a no-op call.\n // Note: checking length equality (not `newValues.length > 0`) is\n // intentional — the latter would incorrectly return `existing` when\n // all elements were removed and `newValues` is empty.\n return newValues.length === existing.length ? (existing as T[]) : newValues;\n };\n}\n","/**\n * @module\n * @description\n * Entry point for all public APIs of this package.\n */\nexport { append } from './append';\nexport { compose } from './compose';\nexport { iif } from './iif';\nexport { insertItem } from './insert-item';\nexport { patch, type ɵPatchSpec } from './patch';\nexport { safePatch } from './safe-patch';\nexport { isStateOperator, isPredicate, type Predicate } from './utils';\nexport { updateItem } from './update-item';\nexport { updateItems } from './update-items';\nexport { removeItem } from './remove-item';\nexport { removeItems } from './remove-items';\nexport type { ExistingState, NoInfer, StateOperator } from './types';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":"AAEO,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO;AAIpC,MAAM,UAAU,GAAG,CAAC,KAAc,KAAK,OAAO,KAAK,IAAI,UAAU;AAE1D,MAAM,eAAe,GAAG;AAIxB,MAAM,WAAW,GAAG;AAIpB,MAAM,QAAQ,GAAG,CAAC,KAAc,KAAsB,OAAO,KAAK,KAAK,QAAQ;AAE/E,MAAM,YAAY,GAAG,CAAC,KAAa,KAAK,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC;;ACflF;;;;;;;;;;;;;;;;;;AAkBG;AACG,SAAU,MAAM,CAAI,KAAmB,EAAA;IAC3C,OAAO,SAAS,cAAc,CAAC,QAA4B,EAAA;;;AAGzD,QAAA,MAAM,6BAA6B,GAAG,CAAC,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,QAAQ;QAC3E,IAAI,6BAA6B,EAAE;AACjC,YAAA,OAAO,QAA0B;;AAGnC,QAAA,IAAI,OAAO,CAAC,QAAQ,CAAC,EAAE;AACrB,YAAA,OAAO,QAAQ,CAAC,MAAM,CAAC,KAAsC,CAAC;;;;AAKhE,QAAA,OAAO,KAAuB;AAChC,KAAC;AACH;;ACrCA;;;;;;;;;;;;;;;;AAgBG;AACa,SAAA,OAAO,CAAI,GAAG,SAAsC,EAAA;IAClE,OAAO,SAAS,eAAe,CAAC,QAA0B,EAAA;AACxD,QAAA,OAAO,SAAS,CAAC,MAAM,CACrB,CAAC,WAAW,EAAE,QAAQ,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QAAe;;QAGxB,MAAM,SAAS,GAAQ,EAAE;AACzB,QAAA,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;AACpD,YAAA,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;;AAE7B,YAAA,IAAI,QAAQ,CAAC,KAAK,CAAC,KAAK,KAAK,EAAE;AAC7B,gBAAA,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC;;;;;;;;AASzB,QAAA,OAAO,SAAS,CAAC,MAAM,KAAK,QAAQ,CAAC,MAAM,GAAI,QAAgB,GAAG,SAAS;AAC7E,KAAC;AACH;;AChDA;;;;AAIG;;ACJH;;AAEG;;;;"}
@@ -1,15 +1,11 @@
1
- type _NoInfer<T> = T extends infer S ? S : never;
2
1
  /**
3
- * Blocks the ability of the typescript inferrence engine to be able to use the provided type as part of
4
- * inferring any type parameters from this usage.
2
+ * Re-exported alias for the TypeScript built-in `NoInfer<T>` (available since
3
+ * TypeScript 5.4). Blocks the TypeScript inference engine from using this
4
+ * parameter position to infer type parameters, so that `StateOperator<T>`
5
+ * type parameters are resolved from context (the return type) rather than
6
+ * from the arguments passed to the operator.
7
+ *
5
8
  * @example
6
- * Primarily used to wrap parameters of functions in order to prevent the TypeScript inferrence engine
7
- * from inferring a type parameter of the function from the value provided to this parameter.
8
- * This essentially blocks the Contravariance of the function (through its parameters) so that the
9
- * function type parameter is purely determined by the Covariant requirements of the function's return type.
10
- * This is key to creating `StateOperator`s that are typed based on their contextual usage and not on the arguments
11
- * provided to them. This is critical for type safety and intellisense for State Operators.
12
- * Here is an example of how this benefits a state operator:
13
9
  * ```ts
14
10
  * declare function append<T>(items: NoInfer<T[]>): StateOperator<T[]>;
15
11
  * declare function appendBad<T>(items: T[]): StateOperator<T[]>;
@@ -19,17 +15,16 @@ type _NoInfer<T> = T extends infer S ? S : never;
19
15
  * bar?: boolean;
20
16
  * }
21
17
  *
22
- * // Works
23
- * // (T in append is correctly inferred as AAA)
18
+ * // Works — T is correctly inferred as AAA from the surrounding patch<...> context.
24
19
  * patch<{ test: AAA[] }>({ test: append([{ foo: true }]) });
25
20
  *
26
21
  * // Incorrectly throws: Type 'AAA' is not assignable to type '{ foo: true; }'.ts(2322)
27
- * // (T in appendBad is incorrectly inferred as { foo: true; })
22
+ * // T in appendBad is incorrectly inferred as { foo: true } from the argument.
28
23
  * patch<{ test: AAA[] }>({ test: appendBad([{ foo: true }]) });
29
24
  * ```
30
- *
31
25
  */
32
- type NoInfer<T> = T extends (infer O)[] ? _NoInfer<O>[] : _NoInfer<T>;
26
+ type ɵNoInfer<T> = NoInfer<T>;
27
+
33
28
  /**
34
29
  * IMPORTANT NOTE: This should not be used externally to the library, rather
35
30
  * the exported type `ExistingState<T>` should be used instead.
@@ -321,4 +316,4 @@ declare function removeItem<T>(selector: number | NoInfer<Predicate<T>>): StateO
321
316
  declare function removeItems<T>(selector: NoInfer<Predicate<T>>): (existing: ExistingState<T[]>) => T[];
322
317
 
323
318
  export { append, compose, iif, insertItem, isPredicate, isStateOperator, patch, removeItem, removeItems, safePatch, updateItem, updateItems };
324
- export type { ExistingState, NoInfer, Predicate, StateOperator, ɵPatchSpec };
319
+ export type { ExistingState, ɵNoInfer as NoInfer, Predicate, StateOperator, ɵPatchSpec };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ngxs/store",
3
- "version": "21.0.0-dev.master-11f0b49",
3
+ "version": "21.0.0-dev.master-18ee86d",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {