(ctx: NodeParseContext)
| 149 | } |
| 150 | |
| 151 | export const parseNode = (ctx: NodeParseContext): BaseNode => { |
| 152 | const impl = nodeImplementationsByKind[ctx.kind] |
| 153 | const configuredSchema = |
| 154 | impl.applyConfig?.(ctx.def, ctx.$.resolvedConfig) ?? ctx.def |
| 155 | const inner: dict = {} |
| 156 | const { meta: metaSchema, ...innerSchema } = configuredSchema as dict & { |
| 157 | meta?: TypeMeta.Collapsible |
| 158 | } |
| 159 | |
| 160 | const meta: ArkEnv.meta & dict = |
| 161 | metaSchema === undefined ? {} |
| 162 | : typeof metaSchema === "string" ? { description: metaSchema } |
| 163 | : (metaSchema as never) |
| 164 | |
| 165 | // ensure node entries are parsed in order of precedence, with non-children |
| 166 | // parsed first |
| 167 | const innerSchemaEntries = entriesOf(innerSchema) |
| 168 | .sort(([lKey], [rKey]) => |
| 169 | isNodeKind(lKey) ? |
| 170 | isNodeKind(rKey) ? precedenceOfKind(lKey) - precedenceOfKind(rKey) |
| 171 | : 1 |
| 172 | : isNodeKind(rKey) ? -1 |
| 173 | : lKey < rKey ? -1 |
| 174 | : 1 |
| 175 | ) |
| 176 | .filter(([k, v]) => { |
| 177 | // move meta. prefixed props to meta, overwriting existing nested |
| 178 | // props of the same name if they exist |
| 179 | if (k.startsWith("meta.")) { |
| 180 | const metaKey = k.slice(5) |
| 181 | meta[metaKey] = v |
| 182 | return false |
| 183 | } |
| 184 | return true |
| 185 | }) |
| 186 | |
| 187 | for (const entry of innerSchemaEntries) { |
| 188 | const k = entry[0] |
| 189 | const keyImpl = impl.keys[k] |
| 190 | if (!keyImpl) |
| 191 | return throwParseError(`Key ${k} is not valid on ${ctx.kind} schema`) |
| 192 | |
| 193 | const v = keyImpl.parse ? keyImpl.parse(entry[1], ctx) : entry[1] |
| 194 | if (v !== unset && (v !== undefined || keyImpl.preserveUndefined)) |
| 195 | inner[k] = v |
| 196 | } |
| 197 | |
| 198 | if (impl.reduce && !ctx.prereduced) { |
| 199 | const reduced = impl.reduce(inner, ctx.$) |
| 200 | if (reduced) { |
| 201 | if (reduced instanceof Disjoint) return reduced.throw() |
| 202 | |
| 203 | // we can't cache this reduction for now in case the reduction involved |
| 204 | // impliedSiblings |
| 205 | return withMeta(reduced, meta) |
| 206 | } |
| 207 | } |
| 208 |
no test coverage detected
searching dependent graphs…