MCPcopy Create free account
hub / github.com/Effect-TS/effect / nodeAtEnv

Function nodeAtEnv

packages/effect/src/ConfigProvider.ts:998–1021  ·  view source on GitHub ↗
(
  trie: EnvTrieNode,
  env: Record<string, string | undefined>,
  path: Path,
  preserveEmptyStrings: boolean
)

Source from the content-addressed store, hash-verified

996}
997
998function nodeAtEnv(
999 trie: EnvTrieNode,
1000 env: Record<string, string | undefined>,
1001 path: Path,
1002 preserveEmptyStrings: boolean
1003): Node | undefined {
1004 const key = path.map(String).join("_")
1005 const leafValue = emptyStringAsMissing(Object.hasOwn(env, key) ? env[key] : undefined, preserveEmptyStrings)
1006
1007 const trieNode = trieNodeAt(trie, path)
1008 const children = trieNode?.children ? Object.keys(trieNode.children) : []
1009
1010 if (children.length === 0) {
1011 return leafValue === undefined ? undefined : makeValue(leafValue)
1012 }
1013
1014 const allNumeric = children.every(Arr.isCanonicalArrayIndex)
1015 if (allNumeric) {
1016 const length = Math.max(...children.map((k) => parseInt(k, 10))) + 1
1017 return makeArray(length, leafValue)
1018 }
1019
1020 return makeRecord(new Set(children), leafValue)
1021}
1022
1023function trieNodeAt(root: EnvTrieNode, path: Path): EnvTrieNode | undefined {
1024 if (path.length === 0) return root

Callers 1

fromEnvRecordFunction · 0.85

Calls 8

emptyStringAsMissingFunction · 0.85
trieNodeAtFunction · 0.85
makeValueFunction · 0.85
keysMethod · 0.80
makeArrayFunction · 0.70
makeRecordFunction · 0.70
joinMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected