json-schema-to-ts
Advanced tools
Comparing version 1.4.2 to 1.4.3
@@ -5,4 +5,8 @@ import { JSONSchema6Definition } from "json-schema"; | ||
import { ParseSchema } from "./parse-schema"; | ||
import { WriteableRec, ReadonlyRec } from "./utils"; | ||
import { DeepWriteable, DeepReadonly } from "./utils"; | ||
/** | ||
* Unwided JSON schema (e.g. defined with the `as const` statement) | ||
*/ | ||
export declare type JSONSchema = JSONSchema6Definition | DeepReadonly<JSONSchema6DefinitionWithoutInterface>; | ||
/** | ||
* Given a JSON schema defined with the `as const` statement, infers the type of valid instances | ||
@@ -12,2 +16,2 @@ * | ||
*/ | ||
export declare type FromSchema<S extends JSONSchema6Definition | ReadonlyRec<JSONSchema6DefinitionWithoutInterface>> = Resolve<ParseSchema<WriteableRec<S>>>; | ||
export declare type FromSchema<S extends JSONSchema> = Resolve<ParseSchema<DeepWriteable<S>>>; |
@@ -1,2 +0,2 @@ | ||
import { DoesExtend, Get, UnsafeMergeRec } from "../utils"; | ||
import { DoesExtend, Get, DeepMergeUnsafe } from "../utils"; | ||
import { Resolve, Any } from "."; | ||
@@ -18,7 +18,7 @@ export declare type ObjectType = "object"; | ||
declare type IsObjectValid<O> = IsOpen<O> extends false ? Required<O> extends keyof Values<O> ? true : false : true; | ||
declare type ResolveValidObject<O> = UnsafeMergeRec<IsOpen<O> extends true ? IsEmpty<O> extends true ? { | ||
declare type ResolveValidObject<O> = DeepMergeUnsafe<IsOpen<O> extends true ? IsEmpty<O> extends true ? { | ||
[key: string]: Resolve<Get<O, "openProps">>; | ||
} : { | ||
[key: string]: Resolve<Any>; | ||
} : {}, UnsafeMergeRec<{ | ||
} : {}, DeepMergeUnsafe<{ | ||
[key in Exclude<keyof Values<O>, Required<O>>]?: Resolve<Values<O>[key]>; | ||
@@ -25,0 +25,0 @@ }, { |
import { Enum, Intersection } from "../meta-types"; | ||
import { GetRec, HasKeyIn } from "../utils"; | ||
import { DeepGet, HasKeyIn } from "../utils"; | ||
import { ParseSchema } from "."; | ||
export declare type ParseEnumSchema<S> = HasKeyIn<S, "const" | "type"> extends true ? Intersection<Enum<GetRec<S, ["enum", number]>>, ParseSchema<Omit<S, "enum">>> : Enum<GetRec<S, ["enum", number]>>; | ||
export declare type ParseEnumSchema<S> = HasKeyIn<S, "const" | "type"> extends true ? Intersection<Enum<DeepGet<S, ["enum", number]>>, ParseSchema<Omit<S, "enum">>> : Enum<DeepGet<S, ["enum", number]>>; |
import { Union } from "../meta-types"; | ||
import { Get, Head, Tail, UnsafeMergeRec } from "../utils"; | ||
import { Get, Head, Tail, DeepMergeUnsafe } from "../utils"; | ||
import { ParseSchema } from "."; | ||
@@ -7,3 +7,3 @@ export declare type ParseMixedSchema<S> = Union<RecurseOnMixedSchema<Get<S, "type">, S>>; | ||
stop: R; | ||
continue: T extends any[] ? RecurseOnMixedSchema<Tail<T>, S, R | ParseSchema<UnsafeMergeRec<S, { | ||
continue: T extends any[] ? RecurseOnMixedSchema<Tail<T>, S, R | ParseSchema<DeepMergeUnsafe<S, { | ||
type: Head<T>; | ||
@@ -10,0 +10,0 @@ }>>> : never; |
@@ -20,5 +20,5 @@ import { Head } from "./head"; | ||
*/ | ||
export declare type GetRec<O, P, F = never> = { | ||
continue: Head<P> extends keyof O ? GetRec<O[Head<P>], Tail<P>, F> : F; | ||
export declare type DeepGet<O, P, F = never> = { | ||
continue: Head<P> extends keyof O ? DeepGet<O[Head<P>], Tail<P>, F> : F; | ||
stop: O; | ||
}[P extends [any, ...any[]] ? "continue" : "stop"]; |
@@ -5,10 +5,10 @@ export { And } from "./and"; | ||
export { FilterExtending } from "./filter"; | ||
export { Get, GetRec } from "./get"; | ||
export { Get, DeepGet } from "./get"; | ||
export { HasKeyIn } from "./hasKeyIn"; | ||
export { Head } from "./head"; | ||
export { SafeMergeRec, UnsafeMergeRec, Merge } from "./merge"; | ||
export { DeepMergeSafe, DeepMergeUnsafe, Merge } from "./merge"; | ||
export { OptionalProps } from "./optionalProps"; | ||
export { Prepend } from "./prepend"; | ||
export { Prettify } from "./prettify"; | ||
export { ReadonlyRec } from "./readonly"; | ||
export { DeepReadonly } from "./readonly"; | ||
export { Replace } from "./replace"; | ||
@@ -18,2 +18,2 @@ export { RequiredProps } from "./requiredProps"; | ||
export { Tail } from "./tail"; | ||
export { WriteableRec } from "./writeable"; | ||
export { DeepWriteable } from "./writeable"; |
@@ -9,3 +9,3 @@ import { Concat } from "./concat"; | ||
* | ||
* `UnsafeMergeRec` preserves non-required properties, but can return `never` if TS infers that `A & B = never` (which can happen if some properties are incompatible) | ||
* `DeepMergeUnsafe` preserves non-required properties, but can return `never` if TS infers that `A & B = never` (which can happen if some properties are incompatible) | ||
* | ||
@@ -16,4 +16,4 @@ * @param A Type | ||
*/ | ||
export declare type UnsafeMergeRec<A, B> = IsObject<A> extends true ? IsObject<B> extends true ? { | ||
[K in keyof (A & B)]: K extends keyof B ? K extends keyof A ? UnsafeMergeRec<A[K], B[K]> : B[K] : K extends keyof A ? A[K] : never; | ||
export declare type DeepMergeUnsafe<A, B> = IsObject<A> extends true ? IsObject<B> extends true ? { | ||
[K in keyof (A & B)]: K extends keyof B ? K extends keyof A ? DeepMergeUnsafe<A[K], B[K]> : B[K] : K extends keyof A ? A[K] : never; | ||
} : B : IsArray<A> extends true ? IsArray<B> extends true ? B extends any[] ? Concat<A, B> : never : B : B; | ||
@@ -26,3 +26,3 @@ /** | ||
* | ||
* Contrary to `UnsafeMergeRec`, `SafeMergeRec` never returns `never`, but doesn't preserve non-required properties | ||
* Contrary to `DeepMergeUnsafe`, `DeepMergeSafe` never returns `never`, but doesn't preserve non-required properties | ||
* | ||
@@ -33,4 +33,4 @@ * @param A Type | ||
*/ | ||
export declare type SafeMergeRec<A, B> = IsObject<A> extends true ? IsObject<B> extends true ? { | ||
[K in keyof A | keyof B]: K extends keyof B ? K extends keyof A ? SafeMergeRec<A[K], B[K]> : B[K] : K extends keyof A ? A[K] : never; | ||
export declare type DeepMergeSafe<A, B> = IsObject<A> extends true ? IsObject<B> extends true ? { | ||
[K in keyof A | keyof B]: K extends keyof B ? K extends keyof A ? DeepMergeSafe<A[K], B[K]> : B[K] : K extends keyof A ? A[K] : never; | ||
} : B : IsArray<A> extends true ? IsArray<B> extends true ? B extends any[] ? Concat<A, B> : never : B : B; | ||
@@ -37,0 +37,0 @@ /** |
@@ -7,4 +7,4 @@ /** | ||
*/ | ||
export declare type ReadonlyRec<O> = O extends object ? { | ||
readonly [K in keyof O]: ReadonlyRec<O[K]>; | ||
export declare type DeepReadonly<O> = O extends object ? { | ||
readonly [K in keyof O]: DeepReadonly<O[K]>; | ||
} : O; |
@@ -1,2 +0,2 @@ | ||
import { UnsafeMergeRec } from "./merge"; | ||
import { DeepMergeUnsafe } from "./merge"; | ||
import { OptionalProps } from "./optionalProps"; | ||
@@ -12,3 +12,3 @@ import { RequiredProps } from "./requiredProps"; | ||
*/ | ||
export declare type Replace<O extends Record<string | number | symbol, any>, P extends keyof O, V, Req extends keyof O = RequiredProps<O>, Opt extends keyof O = OptionalProps<O>> = UnsafeMergeRec<UnsafeMergeRec<Omit<O, P>, { | ||
export declare type Replace<O extends Record<string | number | symbol, any>, P extends keyof O, V, Req extends keyof O = RequiredProps<O>, Opt extends keyof O = OptionalProps<O>> = DeepMergeUnsafe<DeepMergeUnsafe<Omit<O, P>, { | ||
[key in P & Req]: V; | ||
@@ -15,0 +15,0 @@ }>, { |
@@ -7,4 +7,4 @@ /** | ||
*/ | ||
export declare type WriteableRec<O> = O extends object ? { | ||
-readonly [K in keyof O]: WriteableRec<O[K]>; | ||
export declare type DeepWriteable<O> = O extends object ? { | ||
-readonly [K in keyof O]: DeepWriteable<O[K]>; | ||
} : O; |
{ | ||
"name": "json-schema-to-ts", | ||
"version": "1.4.2", | ||
"version": "1.4.3", | ||
"description": "Infer typescript types from your JSON schemas!", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.d.ts", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
50568
803