(def: object, ctx: BaseParseContext)
| 118 | } |
| 119 | |
| 120 | export const parseObject = (def: object, ctx: BaseParseContext): BaseRoot => { |
| 121 | const objectKind = objectKindOf(def) |
| 122 | switch (objectKind) { |
| 123 | case undefined: |
| 124 | if (hasArkKind(def, "root")) { |
| 125 | return isInstanceOf(def, BaseRoot) ? |
| 126 | def.internal |
| 127 | : parseForeignRoot(def, ctx) |
| 128 | } |
| 129 | if (isStandardSchema(def)) return parseStandardSchema(def as never, ctx) |
| 130 | return parseObjectLiteral(def as Dict, ctx) |
| 131 | case "Array": |
| 132 | return parseTuple(def as array, ctx) |
| 133 | case "RegExp": |
| 134 | return ctx.$.node( |
| 135 | "intersection", |
| 136 | { |
| 137 | domain: ctx.$.node("domain", { domain: "string" }), |
| 138 | pattern: [ |
| 139 | ctx.$.node("pattern", constraintInputOf("pattern", def as RegExp)) |
| 140 | ] |
| 141 | }, |
| 142 | { reduced: true } |
| 143 | ) |
| 144 | case "Function": { |
| 145 | if (hasArkKind(def, "root")) { |
| 146 | return isInstanceOf(def, BaseRoot) ? |
| 147 | def.internal |
| 148 | : parseForeignRoot(def, ctx) |
| 149 | } |
| 150 | // e.g. Effect's standardSchemaV1, a class that can't be called as a thunk |
| 151 | if (isStandardSchema(def)) return parseStandardSchema(def as never, ctx) |
| 152 | const resolvedDef = isThunk(def) ? resolveThunk(def) : def |
| 153 | if (hasArkKind(resolvedDef, "root")) return parseObject(resolvedDef, ctx) |
| 154 | return throwParseError(writeBadDefinitionTypeMessage("Function")) |
| 155 | } |
| 156 | default: |
| 157 | return throwParseError( |
| 158 | writeBadDefinitionTypeMessage(objectKind ?? printable(def)) |
| 159 | ) |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | // a class whose constructor takes nothing reads as a thunk, and calling it |
| 164 | // would throw a TypeError in place of the message a class gets. One written |
no test coverage detected