| 1 | import { assert, describe, it } from "@effect/vitest" |
| 2 | import { Schema, SchemaRepresentation } from "effect" |
| 3 | |
| 4 | describe("SchemaRepresentation.toJsonMultiDocument", () => { |
| 5 | it("encodes every root in order", () => { |
| 6 | const document = SchemaRepresentation.toRepresentations([ |
| 7 | Schema.String.ast, |
| 8 | Schema.Number.ast, |
| 9 | Schema.Literal(1n).ast |
| 10 | ]) |
| 11 | |
| 12 | assert.deepStrictEqual(SchemaRepresentation.toJsonMultiDocument(document), { |
| 13 | representations: [ |
| 14 | { _tag: "String", checks: [] }, |
| 15 | { _tag: "Number", checks: [] }, |
| 16 | { _tag: "Literal", literal: { type: "bigint", value: "1" }, checks: [] } |
| 17 | ], |
| 18 | references: {} |
| 19 | }) |
| 20 | }) |
| 21 | |
| 22 | it("encodes shared references once", () => { |
| 23 | const shared = Schema.String.annotate({ identifier: "Shared", callback: () => "live" }) |
| 24 | const document = SchemaRepresentation.toRepresentations([shared.ast, shared.ast]) |
| 25 | |
| 26 | assert.deepStrictEqual(SchemaRepresentation.toJsonMultiDocument(document), { |
| 27 | representations: [ |
| 28 | { _tag: "Reference", $ref: "Shared" }, |
| 29 | { _tag: "Reference", $ref: "Shared" } |
| 30 | ], |
| 31 | references: { |
| 32 | Shared: { |
| 33 | _tag: "String", |
| 34 | annotations: { identifier: "Shared" }, |
| 35 | checks: [] |
| 36 | } |
| 37 | } |
| 38 | }) |
| 39 | }) |
| 40 | }) |