MCPcopy Create free account
hub / github.com/Effect-TS/effect / compileDeclaration

Function compileDeclaration

packages/effect/src/encoding/SchemaBinary.ts:2602–2668  ·  view source on GitHub ↗
(ast: SchemaAST.Declaration)

Source from the content-addressed store, hash-verified

2600 }
2601
2602 function compileDeclaration(ast: SchemaAST.Declaration): Layout {
2603 const id = representationId(ast)
2604 switch (id) {
2605 case "effect/schema/Date":
2606 return { _: "int64", flavor: "date" }
2607 case "effect/schema/DateTimeUtc":
2608 return { _: "int64", flavor: "utc" }
2609 case "effect/schema/DateTimeZoned":
2610 return leaf("dateTimeZoned")
2611 case "effect/schema/Duration":
2612 return leaf("duration")
2613 case "effect/schema/BigDecimal":
2614 return leaf("bigDecimal")
2615 case "effect/schema/Uint8Array":
2616 return leaf("bytes")
2617 }
2618 const tps = ast.typeParameters
2619 switch (id) {
2620 case "effect/schema/Option": {
2621 const layout = { _: "option" as const, value: undefined as unknown as Layout }
2622 memo.set(ast, layout)
2623 layout.value = compile(tps[0])
2624 return layout
2625 }
2626 case "effect/schema/Result": {
2627 const layout = {
2628 _: "result" as const,
2629 success: undefined as unknown as Layout,
2630 failure: undefined as unknown as Layout
2631 }
2632 memo.set(ast, layout)
2633 layout.success = compile(tps[0])
2634 layout.failure = compile(tps[1])
2635 return layout
2636 }
2637 case "effect/schema/Exit": {
2638 const cause: ReasonLayout = {
2639 _: "cause",
2640 error: undefined as unknown as Layout,
2641 defect: undefined as unknown as Layout
2642 }
2643 const layout = { _: "exit" as const, value: undefined as unknown as Layout, cause }
2644 memo.set(ast, layout)
2645 layout.value = compile(tps[0])
2646 cause.error = compile(tps[1])
2647 cause.defect = compile(tps[2])
2648 return layout
2649 }
2650 case "effect/schema/Cause":
2651 case "effect/schema/CauseReason": {
2652 const layout: ReasonLayout = {
2653 _: id === "effect/schema/Cause" ? "cause" : "causeReason",
2654 error: undefined as unknown as Layout,
2655 defect: undefined as unknown as Layout
2656 }
2657 memo.set(ast, layout)
2658 layout.error = compile(tps[0])
2659 layout.defect = compile(tps[1])

Callers 1

goFunction · 0.70

Calls 5

representationIdFunction · 0.85
isJsonDeclarationFunction · 0.85
leafFunction · 0.70
compileFunction · 0.70
setMethod · 0.65

Tested by

no test coverage detected