(schema: Schema.Top)
| 943 | } |
| 944 | |
| 945 | function declaredErrorFields(schema: Schema.Top) { |
| 946 | if (!SchemaAST.isDeclaration(schema.ast) || schema.ast.annotations?.["~effect/Schema/Class"] === undefined) { |
| 947 | return undefined |
| 948 | } |
| 949 | const fields = schema.ast.typeParameters[0] |
| 950 | if (!SchemaAST.isObjects(fields) || fields.indexSignatures.length > 0) return undefined |
| 951 | const key = fields.propertySignatures.find((field) => field.name === "_tag" || field.name === "name")?.name |
| 952 | if (key !== "_tag" && key !== "name") return undefined |
| 953 | const tag = fields.propertySignatures.find((field) => field.name === key)?.type |
| 954 | if (tag === undefined || !SchemaAST.isLiteral(tag) || typeof tag.literal !== "string") return undefined |
| 955 | return { |
| 956 | key, |
| 957 | tag: tag.literal, |
| 958 | identifier: SchemaAST.resolveIdentifier(schema.ast) ?? tag.literal, |
| 959 | fields: fields.propertySignatures.flatMap((field) => |
| 960 | field.name === key || typeof field.name !== "string" |
| 961 | ? [] |
| 962 | : [[field.name, Schema.make(field.type), SchemaAST.isOptional(field.type)] as const], |
| 963 | ), |
| 964 | } |
| 965 | } |
| 966 | |
| 967 | function isDataEnvelope(schema: Schema.Top) { |
| 968 | if (isStreamSchema(schema) || HttpApiSchema.isNoContent(schema.ast)) return false |
no test coverage detected