-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: pass predefined zod object to ADT Builder
We previously shipped support for Record Builder accepting Zod object schemas. This brings that support to the ADT builder. The following patterns are now psosible: ```ts const Circle = z.object({ radius: z.number() }) const Square = z.object({ size: z.number() }) const Shape1 = Alge.data('Shape', { Circle, Square }) const Shape2 = Alge.data('shape') .record('Circle') .schema(CircleSchema) .record('Square') .schema(SquareSchema) .done() ```
- Loading branch information
1 parent
14784f6
commit 91809c7
Showing
6 changed files
with
99 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Alge } from '../../../src/index.js' | ||
import { $AB } from '../../__helpers__.js' | ||
import { expectType } from 'tsd' | ||
import { z } from 'zod' | ||
|
||
it(`zod object schemas can be passed into shorthand builder`, () => { | ||
const A = z.object({ m: z.string() }) | ||
const B = z.object({ n: z.number() }) | ||
const AB = Alge.data($AB, { A, B }) | ||
|
||
const AB2 = Alge.data($AB) | ||
.record(`B`) | ||
.schema({ n: z.number() }) | ||
.record(`A`) | ||
.schema({ m: z.string() }) | ||
.done() | ||
|
||
expectType<typeof AB2>(AB) | ||
expect(AB.A.create({ m: `` })).toMatchObject({ _tag: `A`, m: `` }) | ||
}) | ||
|
||
it(`zod object schemas can be passed into chain builder`, () => { | ||
const A = z.object({ m: z.string() }) | ||
const B = z.object({ n: z.number() }) | ||
const AB = Alge.data($AB).record(`B`).schema(B).record(`A`).schema(A).done() | ||
|
||
const AB2 = Alge.data($AB) | ||
.record(`B`) | ||
.schema({ n: z.number() }) | ||
.record(`A`) | ||
.schema({ m: z.string() }) | ||
.done() | ||
|
||
expectType<typeof AB2>(AB) | ||
expect(AB.A.create({ m: `` })).toMatchObject({ _tag: `A`, m: `` }) | ||
}) |