Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: readOnly, error stringification, json record prop keys #281

Merged
merged 8 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ jobs:
- run: yarn run eslint
- run: yarn run test:ci
- name: Add coverage
if: github.ref == 'refs/heads/main'
uses: coverallsapp/[email protected]
env:
NODE_COVERALLS_DEBUG: 1
Expand Down
23 changes: 22 additions & 1 deletion docs/JsonSchema.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export declare const annotate: (
readonly description?: string | undefined
readonly references?: Readonly<Record<string, JsonSchema>> | undefined
readonly deprecated?: boolean | undefined
readonly readOnly?: boolean | undefined
}
| undefined
) => (schema: JsonSchema) => Const<JsonSchema, never>
Expand Down Expand Up @@ -184,7 +185,27 @@ Added in v1.2.0
**Signature**

```ts
export declare const record: <A>(additionalProperties: Const<JsonSchema, A>) => Const<JsonSchema, Record<string, A>>
export declare const record: <A>(
additionalProperties: Const<JsonSchema, A>,
propertyNames?:
| (I.JsonEmpty & I.Description & I.References & I.Default & { readonly _A: string })
| (I.JsonString & I.Description & I.References & I.Default & { readonly _A: string })
| (I.JsonNumber & I.Description & I.References & I.Default & { readonly _A: string })
| (I.JsonBoolean & I.Description & I.References & I.Default & { readonly _A: string })
| (I.JsonNull & I.Description & I.References & I.Default & { readonly _A: string })
| (I.JsonInteger & I.Description & I.References & I.Default & { readonly _A: string })
| (I.JsonConst & I.Description & I.References & I.Default & { readonly _A: string })
| (I.JsonString & I.JsonConst & I.Description & I.References & I.Default & { readonly _A: string })
| (I.JsonNumber & I.JsonConst & I.Description & I.References & I.Default & { readonly _A: string })
| (I.JsonBoolean & I.JsonConst & I.Description & I.References & I.Default & { readonly _A: string })
| (I.JsonNull & I.JsonConst & I.Description & I.References & I.Default & { readonly _A: string })
| (I.JsonStruct & I.Description & I.References & I.Default & { readonly _A: string })
| (I.JsonArray & I.Description & I.References & I.Default & { readonly _A: string })
| (I.JsonUnion & I.Description & I.References & I.Default & { readonly _A: string })
| (I.JsonIntersection & I.Description & I.References & I.Default & { readonly _A: string })
| (I.JsonRef & I.Description & I.References & I.Default & { readonly _A: string })
| undefined
) => Const<JsonSchema, Record<string, A>>
```

Added in v1.2.0
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: `AJ`, `G|75|V`, `t9JHK;`)
* 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: `JUh/++++4/iP8//7/d//02oAw1U/6/+bz71=`, `+/Cq3/+/Y1/YR62c/ga///+K`, `B/d+10qClc2/`)
* 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: `__Aza-0a`, `99D-gv_m-`, `-1-MVOt_lE`)
* 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: `bc13scphtda1e7bi165ynb6etr670258`, `bc1d9e9ej3ae112wd8298ged7esdh`, `bc1vr53z75i8x7isc83jis13vq3573w6o05`)
* 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: `|yo`, `u3X=w`, `i,$eIc`)
* 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: `c2+cd+0/8++B+YPe/30F/w8o//tI`, `/+P8/+/+/v++//+XUq/++/8+C/++ON==`, `13D7/++IP2+V+I/2fdKZ+Z8///A87+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: `qUZV_6__uz`, `3d--d--Q`, `-_YI7gt-pY`)
* 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: `1s4G2PUKXQPCocpE7fBy1BbM1KC3W`, `bc1ya7utgd320628hw5w23e4uz00`, `3h3qPY3BnzU6d8KbBt1dkA4Rh9`)
* 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: `6229187398230646`, `50801424388400218`, `340932010329103`)
* 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: `"ᡍ"@8.MU`, `26'.$~?8_&@[458.86.45.0]`, `__~!_%!+?_.~@4-y6y3odB.77NBHAwIq.-RS4oe6.a0E.70.1.B--KL.-.ijQu--m-.VVEmH8nbRc.-sz-8..bcbBP`)
* 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: `0xeACc4EF0bCB12AeB1Ad7AdAAAB82aA3AB7f9C13c`, `0x7c12D631FF58E0Bb2bEE64AC8bFa2eaB8fe8F78b`, `0xD1AAcDFEa4fb2ADA3d3c3fC271f812f1A9Bd8BdB`)
* 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: `#Ec0faCe0`, `D3b001`, `ba8FB0`)
* 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: `Eebbf9BE28`, `BaF2CAab`, `b3DCadb7ADC3`)
* 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(.39145043,0.086%,+093.324270905%)`, `hsl(.7662e+57937700000000100.0e90632%000000000.030%)`, `hsl(+.28000000100e+4231%00000000100e0010%/233008896.70881)`)
* 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: `--.w__aEA`, `T-_-r.p8_5-_p_._9-`, `__.-e-_._Y8S_O-`)
* 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: `(-84.716304053,174)`, `(69,-8)`, `(90,180)`)
* 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: `kyB8/l==`, `__defineSet`, `cdb0f0a654f`)
* 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(207,189,252)`, `rgba(201,242,132,.3)`, `rgba(93%,98%,99%,.3713)`)
* 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: `342103980623911`, `6240979181061252`, `628835139877156146`)
* 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: `%##$+^+}.=^!}~/{.^/Z|.~#}4=/'U|&~@-36--c15A.X.F5.-yD0nzy.-359d--.-3toV--.sJ06.X0fxC3-.rY.7b.5-g--P.pc`, `"ᥣ枹⾌嗾෵城蘭鋚ퟨ徎"@[030.1.3.3]`, `"�￶"@[742.4.45.93]`)
* 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: `0xcfB0cFdCC5ee9FbE3F9A0aE6d52Df014ccfBaAE0`, `0xcb1C41Bc2Ba20b1FdeE00BfEfaFc0Fb7DecC95A1`, `0x627CFBCdFbccDcb8bF6eE9B2acFA01CAB3066ECB`)
* 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: `#2FFdc2Cf`, `D1B12Db2`, `#19D51A`)
* 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: `0hBd6eAfb`, `0H622dca6`, `0HaEcfD98C`)
* 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(0e028+098%100%)`, `hsl(.8turn+000100e-73%0000000000.10620672419%/600%)`, `hsla(.43159390,100%,+000000000.6%)`)
* 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: `5a_j_Ix._7-`, `_x_Z_.Odd.Z_0-`, `nLMq422L._----_E-.GQ1_`)
* 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.0000,180)`, `-90.0000,+151`, `51,-180`)
* 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: `hFU4NGlTSn34Gvtz`, `{<R]`, `@s>u&Z]ZYnBk`)
* 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(100%,92%,69%,.609)`, `rgb(13%,100%,23%)`, `rgb(78%,9%,8%)`)
* 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: `aCfEFf4e-7BC1-DDbF-0Dc1-92c8EAeD3B6c`, `7c01D28b-2fD9-cCFa-DaC2-CDb2C16fD3CB`, `C2a29E0E-9Ac2-B7bd-a7Bb-1F3FC86120Cb`)
* 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: `BC6d2d12-cbbe-6Fea-1D13-Dc30fE2A3acA`, `1C8C4ceC-0Ca1-A1be-b7CF-eaEbBaFF8dCa`, `9ebCBB0b-EFAa-2ca0-BDd6-A7FBAaCda7eF`)

### Unknown (3)

Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"release": "yarn ts-node scripts/config.ts && cd dist && npm publish",
"docs": "yarn run docs-ts",
"docs:pack": "yarn ts-node -r tsconfig-paths/register scripts/docs.ts",
"docs:gen": "yarn prerelease && yarn docs:pack",
"docs:examples:check": "yarn ts-node -r tsconfig-paths/register ./examples/simple-example.ts",
"docs:examples:gen": "yarn markdown --path ./docs/simple-example.md",
"docs:examples": "yarn docs:examples:check && yarn docs:examples:gen",
Expand All @@ -73,6 +74,7 @@
"eslint --fix-type layout --fix --cache",
"prettier --write",
"jest --findRelatedTests --silent",
"yarn prerelease",
"yarn docs:pack",
"git add \"./docs/*.md\""
]
Expand Down
9 changes: 7 additions & 2 deletions src/JsonSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,11 @@ export const struct = <A>(
*/
export const record = <A>(
additionalProperties: Const<JsonSchema, A>,
propertyNames?: Const<JsonSchema, string>,
): Const<JsonSchema, Record<string, A>> =>
make(new I.JsonStruct(new I.JsonEmpty() as any, [], additionalProperties))
make(
new I.JsonStruct(new I.JsonEmpty() as any, [], additionalProperties, propertyNames),
)

/**
* @since 1.2.0
Expand Down Expand Up @@ -276,8 +279,9 @@ export const annotate: (params?: {
readonly description?: string
readonly references?: RR.ReadonlyRecord<string, JsonSchema>
readonly deprecated?: boolean
readonly readOnly?: boolean
}) => (schema: JsonSchema) => Const<JsonSchema, never> =
({ title, description, references, deprecated } = {}) =>
({ title, description, references, deprecated, readOnly } = {}) =>
schema =>
title === undefined && description === undefined && references === undefined
? make(schema)
Expand All @@ -287,6 +291,7 @@ export const annotate: (params?: {
...(description === undefined ? {} : { description }),
...(references === undefined ? {} : { $defs: references }),
...(deprecated === undefined ? {} : { deprecated }),
...(readOnly === undefined ? {} : { readOnly }),
})

// -------------------------------------------------------------------------------------
Expand Down
40 changes: 33 additions & 7 deletions src/TranscodeError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
import { constant, pipe } from 'fp-ts/function'
import * as N from 'fp-ts/number'
import * as O from 'fp-ts/Option'
import * as RA from 'fp-ts/ReadonlyArray'
import * as RNEA from 'fp-ts/ReadonlyNonEmptyArray'
import type * as Sg from 'fp-ts/Semigroup'
Expand Down Expand Up @@ -253,12 +254,12 @@ export const prefixedLines = (
): ((err: TranscodeErrors) => RNEA.ReadonlyNonEmptyArray<string>) => {
const {
TypeMismatch = (expected, actual) =>
`Expected ${expected} but got \`${String(actual)}\``,
UnexpectedValue = actual => `Unexpected value: \`${String(actual)}\``,
`Expected ${expected} but got ${safeShow(actual)}`,
UnexpectedValue = actual => `Unexpected value: ${safeShow(actual)}`,
SerializationError = (expected, error, actual) =>
`Expected ${expected}, but ran into serialization error: \`${String(
`Expected ${expected}, but ran into serialization error: ${safeShow(
error,
)}\`; got ${actual}`,
)}; got ${safeShow(actual)}`,
ErrorAtIndex = index => `at index ${index}:`,
ErrorAtKey = key => `at key ${key}:`,
ErrorAtUnionMember = member => `at union member \`${member}\`:`,
Expand Down Expand Up @@ -364,9 +365,7 @@ export const drawTree: (
_ =>
`${
showHeading
? `Encountered ${totalErrors(errors)} transcode error${
errorCount === 1 ? '' : 's'
}:\n`
? `Encountered ${errorCount} transcode error${errorCount === 1 ? '' : 's'}:\n`
: ''
}${_}`,
)
Expand All @@ -379,3 +378,30 @@ export const drawTree: (
* @category Destructors
*/
export const draw: (errors: TranscodeErrors) => string = drawTree

/** @internal */
const typeOf = (a: unknown): string => {
if (Array.isArray(a)) return 'Array'
return typeof a
}

/** @internal */
const safeShow = (a: unknown): string => {
if (
a instanceof Error ||
typeof a === 'symbol' ||
(typeof a === 'number' && (Number.isNaN(a) || !Number.isFinite(a)))
)
return String(a)
if (typeof a === 'string') return `"${a}"`
if (typeof a === 'bigint') return `${a}n`
if (a instanceof Map) return `Map(${a.size})`
if (a instanceof Set) return `Set(${a.size})`
if (typeof a === 'function')
return `[Function ${a.name === '' ? '(anonymous)' : a.name}]`
const tA = typeOf(a)
return pipe(
O.tryCatch(() => JSON.stringify(a, null, 1)),
O.getOrElse(() => `[Circular ${tA}]`),
)
}
1 change: 1 addition & 0 deletions src/internal/json-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export class JsonStruct {
readonly properties: Readonly<Record<string, JsonSchema>>,
readonly required: ReadonlyArray<string>,
readonly additionalProperties?: JsonSchema | false,
readonly propertyNames?: JsonSchema,
) {}
}

Expand Down
3 changes: 2 additions & 1 deletion src/schemables/annotate/instances/json-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const AnnotateJsonSchema: WithAnnotate<JS.SchemableLambda> = {
annotate:
params =>
<O>(inner: Const<JS.JsonSchema, O>): Const<JS.JsonSchema, O> => {
const { title, description, references, deprecated } = params
const { title, description, references, deprecated, readOnly } = params
if (title === undefined && description === undefined && references === undefined)
return inner
return pipe(
Expand All @@ -17,6 +17,7 @@ export const AnnotateJsonSchema: WithAnnotate<JS.SchemableLambda> = {
...(title === undefined ? {} : { title }),
...(description === undefined ? {} : { description }),
...(deprecated === undefined ? {} : { deprecated }),
...(readOnly === undefined ? {} : { readOnly }),
})
: identity,
references !== undefined ? JS.addReferences({ $defs: references }) : identity,
Expand Down
20 changes: 13 additions & 7 deletions src/schemables/date/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,21 @@ export const earliestSafeDate = new Date(smallestSafeMs)
/** @internal */
export const latestSafeDate = new Date(largestSafeMs)

// istanbul ignore next
export const getDateBoundsStr: (
params?: DateParams,
lchar?: string,
rchar?: string,
) => string = (params = {}, lchar = '<', rchar = '>') => {
export const getDateBoundsStr: (params?: DateParams) => string = (
// istanbul ignore next
params = {},
) => {
const { afterDate, beforeDate } = params
if (afterDate === undefined && beforeDate === undefined) return ''
// istanbul ignore next
const beforeDateStr = beforeDate?.toISOString()
// istanbul ignore next
const afterDateStr = afterDate?.toISOString()
return `${lchar}${afterDateStr ?? ''},${beforeDateStr ?? ''}${rchar}`
return `<${
// istanbul ignore next
afterDateStr ?? ''
},${
// istanbul ignore next
beforeDateStr ?? ''
}>`
}
3 changes: 2 additions & 1 deletion src/schemables/primitives/instances/eq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const PrimitivesEq: WithPrimitives<Eq.SchemableLambda> = {
return Eq.fromEquals((x, y) => Math.abs(x - y) <= (epsilon ?? 2000 * Number.EPSILON))
},
boolean: B.Eq,
unknown: Eq.eqStrict,
// note: `fromEquals` first applies the equality check, which fails for NaN
unknown: Eq.fromEquals((x, y) => Number.isNaN(x) && Number.isNaN(y)),
literal: constant(Eq.eqStrict),
}
4 changes: 2 additions & 2 deletions src/schemables/primitives/instances/type-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {
export const PrimitivesTypeString: WithPrimitives<SchemableLambda> = {
string: (params = {}) =>
makeTypeString(`string${getLengthBoundsString(params, '<', '>')}`),
int: (params = {}) => makeTypeString(`Integer${getNumberBoundsInt(params, '<', '>')}`),
float: (params = {}) => makeTypeString(`Float${getNumberBoundsInt(params, '<', '>')}`),
int: (params = {}) => makeTypeString(`Integer${getNumberBoundsInt(params)}`),
float: (params = {}) => makeTypeString(`Float${getNumberBoundsInt(params)}`),
boolean: makeTypeString('boolean'),
unknown: makeTypeString('unknown'),
literal: (...items) =>
Expand Down
12 changes: 5 additions & 7 deletions src/schemables/primitives/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,11 @@ export const getLengthBoundsString: (
return `${lchar}${minLength ?? ''},${maxLength ?? ''}${rchar}`
}

// istanbul ignore next
export const getNumberBoundsInt: (
params?: NumberParams<any, any>,
lchar?: string,
rchar?: string,
) => string = (params = {}, lchar = '<', rchar = '>') => {
export const getNumberBoundsInt: (params?: NumberParams<any, any>) => string = (
// istanbul ignore next
params = {},
) => {
const { min, max } = params
if (min === undefined && max === undefined) return ''
return `${lchar}${min ?? ''},${max ?? ''}${rchar}`
return `<${min ?? ''},${max ?? ''}>`
}
2 changes: 1 addition & 1 deletion src/schemables/struct/instances/json-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ export const StructJsonSchema: WithStruct<JS.SchemableLambda> = {
extraProps === 'error' ? false : extraProps === 'strip' ? undefined : extraProps,
) as any
},
record: (_, so) => JS.make(new JS.JsonStruct({}, [], so)),
record: (keys, so) => JS.make(new JS.JsonStruct({}, [], so, keys)),
intersection: (x, y) => JS.make(new JS.JsonIntersection([x, y])),
}
1 change: 0 additions & 1 deletion src/schemables/struct/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ export const getValidateObject: <M extends URIS2>(
) => Kind2<M, TranscodeErrors, Record<string | number | symbol, unknown>> =
M => name => u => {
if (u === null || typeof u !== 'object' || Array.isArray(u)) {
// istanbul ignore next
return M.throwError(TC.transcodeErrors(TC.typeMismatch(name, u)))
}
return M.of(u as Record<string | number | symbol, unknown>)
Expand Down
Loading
Loading