@internal
(
compile: SchemaParser.Compiler,
compileConstructorDefault: SchemaParser.Compiler = compile
)
| 2116 | } |
| 2117 | /** @internal */ |
| 2118 | getParser( |
| 2119 | compile: SchemaParser.Compiler, |
| 2120 | compileConstructorDefault: SchemaParser.Compiler = compile |
| 2121 | ): SchemaParser.Parser { |
| 2122 | // oxlint-disable-next-line @typescript-eslint/no-this-alias |
| 2123 | const ast = this |
| 2124 | const expectedKeys: Array<PropertyKey> = [] |
| 2125 | for (const ps of ast.propertySignatures) { |
| 2126 | expectedKeys.push(ps.name) |
| 2127 | } |
| 2128 | const hasProperties = expectedKeys.length |
| 2129 | const indexCount = ast.indexSignatures.length |
| 2130 | let expectedKeysSet = hasProperties && indexCount ? new Set(expectedKeys) : undefined |
| 2131 | // --------------------------------------------- |
| 2132 | // handle empty struct |
| 2133 | // --------------------------------------------- |
| 2134 | if (!hasProperties && !indexCount) { |
| 2135 | return fromRefinement(ast, Predicate.isNotNullish) |
| 2136 | } |
| 2137 | |
| 2138 | let properties: Array<ParsedProperty> | undefined |
| 2139 | let indexes: |
| 2140 | | Array<{ |
| 2141 | readonly is: IndexSignature |
| 2142 | readonly parserKey: SchemaParser.Parser |
| 2143 | readonly parserValue: SchemaParser.Parser |
| 2144 | }> |
| 2145 | | undefined |
| 2146 | type Index = NonNullable<typeof indexes>[number] |
| 2147 | const finishIndex = ( |
| 2148 | s: ObjectParserState, |
| 2149 | key: PropertyKey, |
| 2150 | k2: PropertyKey | typeof InternalParser.missing, |
| 2151 | inputValue: unknown, |
| 2152 | exitValue: Exit.Exit<unknown, SchemaIssue.Issue> |
| 2153 | ): Effect.Effect<void, SchemaIssue.Issue, any> => { |
| 2154 | if (exitValue._tag === "Failure") { |
| 2155 | return wrapPropertyKeyIssue(s, ast, key, exitValue) ?? Exit.void |
| 2156 | } |
| 2157 | const value = exitValue === InternalParser.sameExit |
| 2158 | ? inputValue |
| 2159 | : (exitValue as InternalParser.Success<unknown, SchemaIssue.Issue>)[InternalParser.args] |
| 2160 | if (k2 !== InternalParser.missing && value !== InternalParser.missing) { |
| 2161 | if (hasProperties && (expectedKeysSet!.has(key) || expectedKeysSet!.has(k2))) return Exit.void |
| 2162 | InternalRecord.assignProperty(s.out, k2, value) |
| 2163 | } |
| 2164 | return Exit.void |
| 2165 | } |
| 2166 | const parseIndex = ( |
| 2167 | s: ObjectParserState, |
| 2168 | key: PropertyKey, |
| 2169 | index: Index, |
| 2170 | exitKey?: Exit.Exit<unknown, SchemaIssue.Issue> |
| 2171 | ): Effect.Effect<void, SchemaIssue.Issue, any> => { |
| 2172 | if (!exitKey) { |
| 2173 | const eff = index.parserKey(key, s.options) |
| 2174 | if (!effectIsExit(eff)) { |
| 2175 | return Effect.flatMap(Effect.exit(eff), (exit) => parseIndex(s, key, index, exit)) |
nothing calls this directly
no test coverage detected