(
representation: Exclude<SchemaRepresentation.Representation, SchemaRepresentation.Reference>,
path: Path,
includeTypeBrands: boolean
)
| 396 | } |
| 397 | |
| 398 | function on( |
| 399 | representation: Exclude<SchemaRepresentation.Representation, SchemaRepresentation.Reference>, |
| 400 | path: Path, |
| 401 | includeTypeBrands: boolean |
| 402 | ): SchemaRepresentation.Code { |
| 403 | switch (representation._tag) { |
| 404 | case "Declaration": { |
| 405 | const callback = representation.annotations?.toCode |
| 406 | if (callback === undefined) { |
| 407 | throw errorWithPath("Missing toCode callback", [...path, "annotations", "toCode"]) |
| 408 | } |
| 409 | const typeParameters = representation.typeParameters.map((typeParameter, index) => |
| 410 | recur(typeParameter, [...path, "typeParameters", index]) |
| 411 | ) |
| 412 | const output = (callback as SchemaRepresentation.Generation.Declaration)({ typeParameters }) |
| 413 | for (const importDeclaration of output.importDeclarations ?? []) addImport(importDeclaration) |
| 414 | return makeCode(output.runtime, output.Type) |
| 415 | } |
| 416 | case "Suspend": { |
| 417 | explicitSuspendDepth++ |
| 418 | const thunk = recur(representation.thunk, [...path, "thunk"]) |
| 419 | explicitSuspendDepth-- |
| 420 | return makeCode(`Schema.suspend((): Schema.Codec<${thunk.Type}> => ${thunk.runtime})`, thunk.Type) |
| 421 | } |
| 422 | case "Null": |
| 423 | return makeCode("Schema.Null", "null") |
| 424 | case "Undefined": |
| 425 | return makeCode("Schema.Undefined", "undefined") |
| 426 | case "Void": |
| 427 | return makeCode("Schema.Void", "void") |
| 428 | case "Never": |
| 429 | return makeCode("Schema.Never", "never") |
| 430 | case "Unknown": |
| 431 | return makeCode("Schema.Unknown", "unknown") |
| 432 | case "Any": |
| 433 | return makeCode("Schema.Any", "any") |
| 434 | case "String": |
| 435 | return makeCode("Schema.String", "string") |
| 436 | case "Number": |
| 437 | return makeCode("Schema.Number", "number") |
| 438 | case "Boolean": |
| 439 | return makeCode("Schema.Boolean", "boolean") |
| 440 | case "BigInt": |
| 441 | return makeCode("Schema.BigInt", "bigint") |
| 442 | case "Symbol": |
| 443 | return makeCode("Schema.Symbol", "symbol") |
| 444 | case "Literal": { |
| 445 | const literal = format(representation.literal) |
| 446 | return makeCode(`Schema.Literal(${literal})`, literal) |
| 447 | } |
| 448 | case "UniqueSymbol": { |
| 449 | const identifier = addSymbol(representation.symbol) |
| 450 | return makeCode(`Schema.UniqueSymbol(${identifier})`, `typeof ${identifier}`) |
| 451 | } |
| 452 | case "ObjectKeyword": |
| 453 | return makeCode("Schema.ObjectKeyword", "object") |
| 454 | case "Enum": { |
| 455 | const identifier = freshIdentifier("_Enum") |
no test coverage detected