Skip to content

Commit

Permalink
Merge pull request #286 from jacob-alford/ja/fix-fp-dts
Browse files Browse the repository at this point in the history
fix: downstream dts for fp-ts types
  • Loading branch information
jacob-alford committed Aug 16, 2023
2 parents 90f84b0 + 54b976b commit c88e46b
Show file tree
Hide file tree
Showing 25 changed files with 128 additions and 66 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ const personTranscoderPar: TranscoderPar<PersonInput, Person> =

## Type Guards

Type guards are used by TypeScript to narrow the type of a value to something concrete. Guards can be derived from schemas using `deriveTypeGuard`:
Type guards are used by TypeScript to narrow the type of a value to something concrete. Guards can be derived from schemas using `deriveGuard`:

```ts
import { deriveGuard, type Guard } from 'schemata-ts/Guard'
Expand Down
8 changes: 4 additions & 4 deletions docs/Transcoder.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Added in v2.0.0
**Signature**

```ts
export declare const failure: <A>(e: TE.TranscodeErrors) => E.Either<TE.TranscodeErrors, A>
export declare const failure: <A>(e: TE.TranscodeErrors) => Either<TE.TranscodeErrors, A>
```

Added in v2.0.0
Expand All @@ -119,7 +119,7 @@ Added in v2.0.0
**Signature**

```ts
export declare const success: <A>(a: A) => E.Either<TE.TranscodeErrors, A>
export declare const success: <A>(a: A) => Either<TE.TranscodeErrors, A>
```

Added in v2.0.0
Expand Down Expand Up @@ -221,8 +221,8 @@ Added in v2.0.0

```ts
export interface Transcoder<I, O> {
readonly decode: (u: unknown) => E.Either<Const<TE.TranscodeErrors, I>, O>
readonly encode: (o: O) => E.Either<Const<TE.TranscodeErrors, O>, I>
readonly decode: (u: unknown) => Either<Const<TE.TranscodeErrors, I>, O>
readonly encode: (o: O) => Either<Const<TE.TranscodeErrors, O>, I>
}
```

Expand Down
8 changes: 4 additions & 4 deletions docs/TranscoderPar.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Added in v2.0.0
**Signature**

```ts
export declare const failure: <A>(e: TCE.TranscodeErrors) => TE.TaskEither<TCE.TranscodeErrors, A>
export declare const failure: <A>(e: TCE.TranscodeErrors) => TaskEither<TCE.TranscodeErrors, A>
```

Added in v2.0.0
Expand All @@ -52,7 +52,7 @@ Added in v2.0.0
**Signature**

```ts
export declare const success: <A>(a: A) => TE.TaskEither<TCE.TranscodeErrors, A>
export declare const success: <A>(a: A) => TaskEither<TCE.TranscodeErrors, A>
```

Added in v2.0.0
Expand Down Expand Up @@ -103,8 +103,8 @@ Added in v2.0.0

```ts
export interface TranscoderPar<I, O> {
readonly decode: (u: unknown) => TE.TaskEither<Const<TCE.TranscodeErrors, I>, O>
readonly encode: (o: O) => TE.TaskEither<Const<TCE.TranscodeErrors, O>, I>
readonly decode: (u: unknown) => TaskEither<Const<TCE.TranscodeErrors, I>, O>
readonly encode: (o: O) => TaskEither<Const<TCE.TranscodeErrors, O>, I>
}
```

Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ const personTranscoderPar: TranscoderPar<PersonInput, Person> =

## Type Guards

Type guards are used by TypeScript to narrow the type of a value to something concrete. Guards can be derived from schemas using `deriveTypeGuard`:
Type guards are used by TypeScript to narrow the type of a value to something concrete. Guards can be derived from schemas using `deriveGuard`:

```ts
import { deriveGuard, type Guard } from 'schemata-ts/Guard'
Expand Down
4 changes: 2 additions & 2 deletions docs/schemata/Parse.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ A schema for pre-parsing/printing a string
```ts
export declare const Parse: <I>(
name: string,
parse: (raw: string) => E.Either<unknown, unknown>,
print: (a: I) => E.Either<unknown, string>,
parse: (raw: string) => Either<unknown, unknown>,
print: (a: I) => Either<unknown, string>,
options?: ParserOptions | undefined
) => <O>(inner: Schema<I, O>) => Schema<string, O>
```
Expand Down
4 changes: 2 additions & 2 deletions docs/schemata/ParseEncodedJson.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ Useful for things like conversion between character encodings.

```ts
export declare const ParseEncodedJsonString: (
decode: (encoded: string) => E.Either<unknown, string>,
encode: (jsonString: string) => E.Either<unknown, string>,
decode: (encoded: string) => Either<unknown, string>,
encode: (jsonString: string) => Either<unknown, string>,
options?: (ParserOptions & { readonly nameOverride?: string | undefined }) | undefined
) => <I, O>(inner: Schema<I, O>) => Schema<Const<Opaque<string, { JsonString: unique symbol }>, I>, O>
```
Expand Down
30 changes: 15 additions & 15 deletions docs/schemata/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,23 @@ has_children: true

### String (17)

* Ascii ([docs](https://jacob-alford.github.io/schemata-ts/schemata/Ascii.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/Ascii.ts)) (e.g: `Ly<<\"uw)^`, `Ye0_3`, `zLWIn_`)
* Base64 ([docs](https://jacob-alford.github.io/schemata-ts/schemata/Base64.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/Base64.ts)) (e.g: `X5++1/06/qUT/+6+++/SY62/d++2xr/c+96j+i/+`, `gS+/q+5/Q5NT6y5jxqE//++0/r/1R+/7`, `++2D/y0W8+cX`)
* Base64Url ([docs](https://jacob-alford.github.io/schemata-ts/schemata/Base64Url.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/Base64Url.ts)) (e.g: `_f__0C1P`, `_-xC--W`, `--hgy4-6`)
* BitcoinAddress ([docs](https://jacob-alford.github.io/schemata-ts/schemata/BitcoinAddress.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/BitcoinAddress.ts)) (e.g: `2PZMzG4Lj3thyJFiC2SXHj6Ki9Bec2x5`, `bc16i1qtok0p2c4175i5uwlhyhm54bdoprt`, `2Zv7S96f4FRJApCmF4FZKmKn3t`)
* Ascii ([docs](https://jacob-alford.github.io/schemata-ts/schemata/Ascii.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/Ascii.ts)) (e.g: `N>]G3"_eRiH`, `}L FB4`, `-NK<LUFY`)
* Base64 ([docs](https://jacob-alford.github.io/schemata-ts/schemata/Base64.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/Base64.ts)) (e.g: `8+///K04++cb+F+++8/5SA95fUVzzIE/W+l+`, `b/+I//T=`, `+3w2/zZ++R/TL/VjSH/T+++bPeI+MSM+Z//=`)
* Base64Url ([docs](https://jacob-alford.github.io/schemata-ts/schemata/Base64Url.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/Base64Url.ts)) (e.g: `X03--Y-J4-`, `Q_cA2cdC`, `b9-6R-`)
* BitcoinAddress ([docs](https://jacob-alford.github.io/schemata-ts/schemata/BitcoinAddress.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/BitcoinAddress.ts)) (e.g: `2umr1KNDmbpfk3eyvT1Zq3D8g1pSuGcf`, `19JZCQ4RN7BcP9BXyLyjQmnW1pK`, `bc1193117461v687z71ec97gx260`)
* CamelCaseString ([docs](https://jacob-alford.github.io/schemata-ts/schemata/CamelCaseString.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/CamelCaseString.ts)) (e.g: `Camel_case-string``camelCaseString`)
* CreditCard ([docs](https://jacob-alford.github.io/schemata-ts/schemata/CreditCard.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/CreditCard.ts)) (e.g: `3879120218342341`, `35847025514861707`, `65481870723977630`)
* EmailAddress ([docs](https://jacob-alford.github.io/schemata-ts/schemata/EmailAddress.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/EmailAddress.ts)) (e.g: `"漲ሀ洄酭ᐆ鞱"@9..a0d71.Vb-r--.HtUjHelKOuir`, `"�陶"@4e77EGNKJ.-.-7-Xr.U-sZ-a35.ab-1B-d.d.-3.qk181-.-92pl-.-X95ur--.1-rOql-.eDE`, `"㍃ꠌ鎉￶頚￰昐￷⅍㵴픺"@[66.45.253.60]`)
* EthereumAddress ([docs](https://jacob-alford.github.io/schemata-ts/schemata/EthereumAddress.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/EthereumAddress.ts)) (e.g: `0xbcc0eDCF1cDCbbacd7b8dCa969Ac30a83bE0A133`, `0x0bAd6FafFECCb357B92DaACBbfc9aCf2b631CFE5`, `0x7A69C2DebaBFD2BfbAcFAeA0fcEc0cADeDDA450F`)
* HexColor ([docs](https://jacob-alford.github.io/schemata-ts/schemata/HexColor.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/HexColor.ts)) (e.g: `#f7CD6FcA`, `#B3EbA4Ba`, `b0C5c0B9`)
* Hexadecimal ([docs](https://jacob-alford.github.io/schemata-ts/schemata/Hexadecimal.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/Hexadecimal.ts)) (e.g: `0xDc1ad`, `9584eAf1f`, `0haE943E4`)
* HslColor ([docs](https://jacob-alford.github.io/schemata-ts/schemata/HslColor.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/HslColor.ts)) (e.g: `hsl(.90,0.08157545814%,+000.698088872e-000%,512.67899580e-032%)`, `hsla(92.343e4000.358195e73213027%00090e190%/1016995836e+8517%)`, `hsla(+117,000.80e+54%,000.895%,76)`)
* Jwt ([docs](https://jacob-alford.github.io/schemata-ts/schemata/Jwt.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/Jwt.ts)) (e.g: `c9_S8d4_-D.G._`, `0c.-6-9Y-AV3b.uD-4Y`, `-C_.dY-`)
* LatLong ([docs](https://jacob-alford.github.io/schemata-ts/schemata/LatLong.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/LatLong.ts)) (e.g: `(90,23)`, `90,180.0000000`, `90,180.00`)
* NonEmptyString ([docs](https://jacob-alford.github.io/schemata-ts/schemata/NonEmptyString.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/NonEmptyString.ts)) (e.g: `l6/FQ4saJNfEkt==`, `194d8fbe93c2`, `DFkgzVTV`)
* RGB ([docs](https://jacob-alford.github.io/schemata-ts/schemata/RGB.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/RGB.ts)) (e.g: `rgba(254,252,228,1.0)`, `rgba(11,233,180,1.0)`, `rgba(100%,100%,100%,1.0)`)
* CreditCard ([docs](https://jacob-alford.github.io/schemata-ts/schemata/CreditCard.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/CreditCard.ts)) (e.g: `8292259233347204`, `6286183693101011807`, `8118910162983532`)
* EmailAddress ([docs](https://jacob-alford.github.io/schemata-ts/schemata/EmailAddress.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/EmailAddress.ts)) (e.g: `!+$!-'~3^&!.|&{/G~!_|8'!.6s+/+%*+@[13.003.34.23]`, `#$&^{=~-.$&%5D8?i~#|.|?*%.'$t_+.#|/^.=+'._%@[16.718.718.253]`, `#.6}6/|r~$.-|.+}==&|x*.?#&&/$%.$_^u%==}?./?-~.-}~*/$.!^}'n^/&{@6.1BlH.6-7LC9--2G.3-3v876o-1.wzJMpRy.7-z7F6H.8zE0g.8D-.l7-k.cat`)
* EthereumAddress ([docs](https://jacob-alford.github.io/schemata-ts/schemata/EthereumAddress.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/EthereumAddress.ts)) (e.g: `0xdEB8aEff639b061DcB78AFbECf47ebE58BC81d9D`, `0xEaeFfBABEdDB3Fc3AADCebAbAbAc4cEd5d1BbAbC`, `0x1fBD7bACC17962c7C592F5EAFc999beFa212dfB9`)
* HexColor ([docs](https://jacob-alford.github.io/schemata-ts/schemata/HexColor.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/HexColor.ts)) (e.g: `CE0Eddbb`, `#d17aC2F6`, `#39b7faBc`)
* Hexadecimal ([docs](https://jacob-alford.github.io/schemata-ts/schemata/Hexadecimal.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/Hexadecimal.ts)) (e.g: `0xB12FFEdF21e`, `0Hec1bCccf6`, `0h418bbB51bc`)
* HslColor ([docs](https://jacob-alford.github.io/schemata-ts/schemata/HslColor.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/HslColor.ts)) (e.g: `hsl(227733893639e-532deg+000000000.33938060647%00100.000000%)`, `hsla(+18,+00.238%,000.05e+45283535%)`, `hsl(4.6261e-13deg,+000100.00000%,00100.0%)`)
* Jwt ([docs](https://jacob-alford.github.io/schemata-ts/schemata/Jwt.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/Jwt.ts)) (e.g: `--_.-pA5-_`, `3j_---.aK_5c`, `HE1.__761I_`)
* LatLong ([docs](https://jacob-alford.github.io/schemata-ts/schemata/LatLong.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/LatLong.ts)) (e.g: `(88,-180.00)`, `(88,180)`, `+87.7388905040,180.0000000`)
* NonEmptyString ([docs](https://jacob-alford.github.io/schemata-ts/schemata/NonEmptyString.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/NonEmptyString.ts)) (e.g: `DW=3*lf6{`, `applyProp`, `M99CvFD=`)
* RGB ([docs](https://jacob-alford.github.io/schemata-ts/schemata/RGB.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/RGB.ts)) (e.g: `rgb(92%,100%,93%)`, `rgb(90%,90%,1%)`, `rgba(38%,100%,41%,1.0)`)
* String ([docs](https://jacob-alford.github.io/schemata-ts/schemata/String.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/String.ts))
* UUID ([docs](https://jacob-alford.github.io/schemata-ts/schemata/UUID.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/UUID.ts)) (e.g: `3DFead8c-ca28-CAFC-811D-bEeFa5CBcffE`, `7dEBCb7C-9cbF-E0b9-AeaE-cAAEdAaA98ED`, `fbbad0Cf-bb97-6D3e-6aaa-9FcaDB393bAc`)
* UUID ([docs](https://jacob-alford.github.io/schemata-ts/schemata/UUID.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/UUID.ts)) (e.g: `71f2f45B-15Dc-f6AC-fA2b-4Be8bCFF60bC`, `BBBd701e-BDF8-9b98-Ec38-e27C0C3bDc17`, `cd82fa6A-9DAd-EDfD-ADfA-DeFCf887bbff`)

### Unknown (3)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "schemata-ts",
"version": "2.0.4",
"version": "2.0.5",
"description": "An all-inclusive schema engine featuring schemata inspired by io-ts and validators.js. Written for TypeScript with fp-ts",
"homepage": "https://jacob-alford.github.io/schemata-ts/",
"repository": {
Expand Down
10 changes: 5 additions & 5 deletions src/Transcoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
* @since 2.0.0
*/
import { type Const } from 'fp-ts/Const'
import type * as E from 'fp-ts/Either'
import { pipe, unsafeCoerce } from 'fp-ts/function'
import { type Invariant2 } from 'fp-ts/Invariant'
import type * as RNEA from 'fp-ts/ReadonlyNonEmptyArray'
import { deriveTranscoder as deriveTranscoder_ } from 'schemata-ts/derivations/transcoder-schemable'
import { type Either } from 'schemata-ts/internal/either'
import * as I from 'schemata-ts/internal/transcoder'
import { type Schema } from 'schemata-ts/Schema'
import * as TE from 'schemata-ts/TranscodeError'
Expand All @@ -27,8 +27,8 @@ import * as TE from 'schemata-ts/TranscodeError'
* @category Model
*/
export interface Transcoder<I, O> {
readonly decode: (u: unknown) => E.Either<Const<TE.TranscodeErrors, I>, O>
readonly encode: (o: O) => E.Either<Const<TE.TranscodeErrors, O>, I>
readonly decode: (u: unknown) => Either<Const<TE.TranscodeErrors, I>, O>
readonly encode: (o: O) => Either<Const<TE.TranscodeErrors, O>, I>
}

// -------------------------------------------------------------------------------------
Expand All @@ -39,13 +39,13 @@ export interface Transcoder<I, O> {
* @since 2.0.0
* @category Constructors
*/
export const success: <A>(a: A) => E.Either<TE.TranscodeErrors, A> = I.success
export const success: <A>(a: A) => Either<TE.TranscodeErrors, A> = I.success

/**
* @since 2.0.0
* @category Constructors
*/
export const failure: <A>(e: TE.TranscodeErrors) => E.Either<TE.TranscodeErrors, A> =
export const failure: <A>(e: TE.TranscodeErrors) => Either<TE.TranscodeErrors, A> =
I.failure

/**
Expand Down
13 changes: 6 additions & 7 deletions src/TranscoderPar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import { type Const } from 'fp-ts/Const'
import { pipe, unsafeCoerce } from 'fp-ts/function'
import { type Invariant2 } from 'fp-ts/Invariant'
import type * as TE from 'fp-ts/TaskEither'
import { deriveTranscoderPar as deriveTranscoderPar_ } from 'schemata-ts/derivations/transcoder-par-schemable'
import { type TaskEither } from 'schemata-ts/internal/task-either'
import * as I from 'schemata-ts/internal/transcoder-par'
import { type Schema } from 'schemata-ts/Schema'
import type * as TCE from 'schemata-ts/TranscodeError'
Expand All @@ -25,8 +25,8 @@ import type * as TCE from 'schemata-ts/TranscodeError'
* @category Model
*/
export interface TranscoderPar<I, O> {
readonly decode: (u: unknown) => TE.TaskEither<Const<TCE.TranscodeErrors, I>, O>
readonly encode: (o: O) => TE.TaskEither<Const<TCE.TranscodeErrors, O>, I>
readonly decode: (u: unknown) => TaskEither<Const<TCE.TranscodeErrors, I>, O>
readonly encode: (o: O) => TaskEither<Const<TCE.TranscodeErrors, O>, I>
}

// -------------------------------------------------------------------------------------
Expand All @@ -37,15 +37,14 @@ export interface TranscoderPar<I, O> {
* @since 2.0.0
* @category Constructors
*/
export const success: <A>(a: A) => TE.TaskEither<TCE.TranscodeErrors, A> = I.success
export const success: <A>(a: A) => TaskEither<TCE.TranscodeErrors, A> = I.success

/**
* @since 2.0.0
* @category Constructors
*/
export const failure: <A>(
e: TCE.TranscodeErrors,
) => TE.TaskEither<TCE.TranscodeErrors, A> = I.failure
export const failure: <A>(e: TCE.TranscodeErrors) => TaskEither<TCE.TranscodeErrors, A> =
I.failure

// -------------------------------------------------------------------------------------
// combinators
Expand Down
1 change: 1 addition & 0 deletions src/internal/either.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type * from 'fp-ts/Either'
1 change: 1 addition & 0 deletions src/internal/option.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type * from 'fp-ts/Option'
1 change: 1 addition & 0 deletions src/internal/task-either.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type * from 'fp-ts/TaskEither'
12 changes: 6 additions & 6 deletions src/internal/transcoder-par.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ import { flow } from 'fp-ts/function'
import * as T from 'fp-ts/Task'
import * as TE from 'fp-ts/TaskEither'
import type * as hkt from 'schemata-ts/internal/schemable'
import { type TaskEither } from 'schemata-ts/internal/task-either'
import { type Transcoder } from 'schemata-ts/internal/transcoder'
import * as TCE from 'schemata-ts/TranscodeError'

export interface TranscoderPar<I, O> {
readonly decode: (u: unknown) => TE.TaskEither<TCE.TranscodeErrors, O>
readonly encode: (out: O) => TE.TaskEither<TCE.TranscodeErrors, I>
readonly decode: (u: unknown) => TaskEither<TCE.TranscodeErrors, O>
readonly encode: (out: O) => TaskEither<TCE.TranscodeErrors, I>
}

/** @internal */
export const success: <A>(a: A) => TE.TaskEither<TCE.TranscodeErrors, A> = TE.right
export const success: <A>(a: A) => TaskEither<TCE.TranscodeErrors, A> = TE.right

/** @internal */
export const failure: <A>(
e: TCE.TranscodeErrors,
) => TE.TaskEither<TCE.TranscodeErrors, A> = TE.throwError
export const failure: <A>(e: TCE.TranscodeErrors) => TaskEither<TCE.TranscodeErrors, A> =
TE.throwError

/** @internal */
export const applicativeValidationPar = TE.getApplicativeTaskValidation(
Expand Down
9 changes: 5 additions & 4 deletions src/internal/transcoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@ import * as E from 'fp-ts/Either'
import { flow } from 'fp-ts/function'
import type * as RNEA from 'fp-ts/ReadonlyNonEmptyArray'
import type * as G from 'schemata-ts/Guard'
import { type Either } from 'schemata-ts/internal/either'
import type * as hkt from 'schemata-ts/internal/schemable'
import * as TE from 'schemata-ts/TranscodeError'

export interface Transcoder<I, O> {
readonly decode: (u: unknown) => E.Either<TE.TranscodeErrors, O>
readonly encode: (out: O) => E.Either<TE.TranscodeErrors, I>
readonly decode: (u: unknown) => Either<TE.TranscodeErrors, O>
readonly encode: (out: O) => Either<TE.TranscodeErrors, I>
}

/** @internal */
export const success: <A>(a: A) => E.Either<TE.TranscodeErrors, A> = E.right
export const success: <A>(a: A) => Either<TE.TranscodeErrors, A> = E.right

/** @internal */
export const failure: <A>(e: TE.TranscodeErrors) => E.Either<TE.TranscodeErrors, A> =
export const failure: <A>(e: TE.TranscodeErrors) => Either<TE.TranscodeErrors, A> =
E.throwError

/** @internal */
Expand Down
9 changes: 7 additions & 2 deletions src/schemables/parser/instances/transcoder-par.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as TC from 'schemata-ts/internal/transcoder'
import type * as TCP from 'schemata-ts/internal/transcoder-par'
import { type WithParser } from 'schemata-ts/schemables/parser/definition'
import { PrimitivesTranscoderPar } from 'schemata-ts/schemables/primitives/instances/transcoder-par'
import { TranscodeErrors } from 'schemata-ts/TranscodeError'

export const ParserTranscoderPar: WithParser<TCP.SchemableLambda> = {
parse: (name, parse, print) => inner => ({
Expand All @@ -14,7 +15,9 @@ export const ParserTranscoderPar: WithParser<TCP.SchemableLambda> = {
print(encoded),
TE.fromEither,
TE.mapLeft(err =>
TC.transcodeErrors(TC.serializationError(name, err, encoded)),
err instanceof TranscodeErrors
? err
: TC.transcodeErrors(TC.serializationError(name, err, encoded)),
),
),
),
Expand All @@ -26,7 +29,9 @@ export const ParserTranscoderPar: WithParser<TCP.SchemableLambda> = {
parse(preparsed),
TE.fromEither,
TE.mapLeft(err =>
TC.transcodeErrors(TC.serializationError(name, err, preparsed)),
err instanceof TranscodeErrors
? err
: TC.transcodeErrors(TC.serializationError(name, err, preparsed)),
),
),
),
Expand Down

0 comments on commit c88e46b

Please sign in to comment.