MCPcopy Create free account
hub / github.com/TanStack/db / replaceIncludesInConditionalSelect

Function replaceIncludesInConditionalSelect

packages/db/src/query/compiler/index.ts:1992–2034  ·  view source on GitHub ↗
(
  conditional: ConditionalSelect,
  path: Array<string>,
  replacement: ValClass,
)

Source from the content-addressed store, hash-verified

1990}
1991
1992function replaceIncludesInConditionalSelect(
1993 conditional: ConditionalSelect,
1994 path: Array<string>,
1995 replacement: ValClass,
1996): { value: ConditionalSelect; replaced: boolean } {
1997 let replaced = false
1998 const branches = conditional.branches.map((branch) => {
1999 const result =
2000 path.length === 0
2001 ? replaceIncludesValue(branch.value, replacement)
2002 : replaceIncludesInSelectValue(branch.value, path, replacement)
2003 if (!result.replaced) {
2004 return branch
2005 }
2006 replaced = true
2007 return { ...branch, value: result.value }
2008 })
2009
2010 let defaultValue = conditional.defaultValue
2011 if (conditional.defaultValue !== undefined) {
2012 const result =
2013 path.length === 0
2014 ? replaceIncludesValue(conditional.defaultValue, replacement)
2015 : replaceIncludesInSelectValue(
2016 conditional.defaultValue,
2017 path,
2018 replacement,
2019 )
2020 if (result.replaced) {
2021 replaced = true
2022 defaultValue = result.value
2023 }
2024 }
2025
2026 if (!replaced) {
2027 return { value: conditional, replaced: false }
2028 }
2029
2030 return {
2031 value: new ConditionalSelect(branches, defaultValue),
2032 replaced: true,
2033 }
2034}
2035
2036/**
2037 * Gets a nested value from an object by path segments.

Callers 2

replaceIncludesValueFunction · 0.85

Calls 3

replaceIncludesValueFunction · 0.85
mapMethod · 0.45

Tested by

no test coverage detected