(value: unknown, path: string, mode: KeyMode)
| 179 | } |
| 180 | const at = (path: string) => (path ? ` at \`${path}\`` : "") |
| 181 | const write = (value: unknown, path: string, mode: KeyMode): void => { |
| 182 | if (hasDomain(value, "object")) { |
| 183 | const index = seen.get(value) |
| 184 | if (index !== undefined) return void values.push(`seen ${index}`) |
| 185 | seen.set(value, seen.size) |
| 186 | } |
| 187 | const defaulted = defaultsByMorph?.get(value) |
| 188 | const runtimeKey = hasDomain(value, "object") && runtimeKeyOf(value) |
| 189 | if (defaulted) { |
| 190 | values.push("default") |
| 191 | write(defaulted[2], path, "value") |
| 192 | } else if (runtimeKey) values.push(`runtime ${runtimeKey}`) |
| 193 | else if (isNode(value)) { |
| 194 | if (defaultsByMorph || !value.isRoot()) values.push("node") |
| 195 | else writeKeyOf("Type", value, path) |
| 196 | } else if (hasArkKind(value, "module")) { |
| 197 | const entries = Object.entries(value) |
| 198 | values.push(`Module ${entries.length}`) |
| 199 | for (const [k, entry] of entries) { |
| 200 | values.push(JSON.stringify(k)) |
| 201 | write(entry, appendStringifiedKey(path, k), "definition") |
| 202 | } |
| 203 | } else if (hasArkKind(value, "scope")) { |
| 204 | // a builtin scope holds only arktype's own functions, named stably |
| 205 | if (value.isBuiltin) values.push(`Scope ${value.name}`) |
| 206 | // e.g. a Type's, which each Type of the Scope shares |
| 207 | else if (value !== start) writeKeyOf("Scope", value, path) |
| 208 | else { |
| 209 | const aliases = Object.entries(value.aliases) |
| 210 | values.push( |
| 211 | `Scope ${JSON.stringify(value.exportedNames)} ${aliases.length}` |
| 212 | ) |
| 213 | write(value.scopeConfig, "", "config") |
| 214 | // the definition, as resolving it would run default checks early |
| 215 | for (const [k, def] of aliases) { |
| 216 | values.push(JSON.stringify(k)) |
| 217 | if (isThunkAlias(def)) { |
| 218 | values.push("thunk") |
| 219 | thunks.push([value, k, ""]) |
| 220 | } else write(def, appendStringifiedKey(path, k), "definition") |
| 221 | } |
| 222 | } |
| 223 | } else if (hasArkKind(value, "generic")) { |
| 224 | values.push("Generic") |
| 225 | write(value.paramDefs, path, "definition") |
| 226 | // an hkt body is a function only identity tells apart |
| 227 | if (value.hkt) { |
| 228 | refuse( |
| 229 | `has an hkt body${at(path)}, whose results decide what it creates` |
| 230 | ) |
| 231 | } else write(value.bodyDef, path, "definition") |
| 232 | write(value.$, appendStringifiedKey(path, "$"), "definition") |
| 233 | // a Generic bound into another Scope parses its arguments there |
| 234 | write(value.arg$, appendStringifiedKey(path, "arg$"), "definition") |
| 235 | } else if (isTypedFn(value)) { |
| 236 | values.push("TypedFn") |
| 237 | write(value.params, path, "value") |
| 238 | write(value.returns, path, "value") |
no test coverage detected