Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

json-schema-to-ts

Package Overview
Dependencies
Maintainers
1
Versions
81
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-schema-to-ts - npm Package Compare versions

Comparing version 2.2.0 to 2.3.0-beta.0

lib/definitions/deserializationPattern.d.ts

3

lib/definitions/fromSchemaOptions.d.ts

@@ -0,1 +1,2 @@

import { DeserializationPattern } from "./deserializationPattern";
export declare type FromSchemaOptions = {

@@ -5,2 +6,3 @@ parseNotKeyword?: boolean;

definitionsPath?: string;
deserialize?: DeserializationPattern[] | false;
};

@@ -11,2 +13,3 @@ export declare type FromSchemaDefaultOptions = {

definitionsPath: "$defs";
deserialize: false;
};

1

lib/definitions/fromSchemaOptions.js
export {};
//# sourceMappingURL=fromSchemaOptions.js.map

@@ -0,2 +1,3 @@

export { DeserializationPattern } from "./deserializationPattern";
export { JSONSchema7 } from "./jsonSchema7";
export { FromSchemaOptions, FromSchemaDefaultOptions, } from "./fromSchemaOptions";
export {};
//# sourceMappingURL=index.js.map
export {};
//# sourceMappingURL=jsonSchema7.js.map

@@ -7,5 +7,5 @@ import { M } from "ts-algebra";

import type { Readonly, Writable } from "./utils";
export { FromSchemaOptions, FromSchemaDefaultOptions } from "./definitions";
export { DeserializationPattern, FromSchemaOptions, FromSchemaDefaultOptions, } from "./definitions";
export declare type JSONSchema7 = $JSONSchema7 | Readonly<$JSONSchema7>;
export declare type JSONSchema = JSONSchema7;
export declare type FromSchema<S extends JSONSchema, O extends FromSchemaOptions = FromSchemaDefaultOptions, W extends $JSONSchema7 = S extends O.Object ? Writable<S> : S> = M.$Resolve<ParseSchema<W, ParseOptions<W, O>>>;
export {};
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

import { JSONSchema7, FromSchemaOptions, FromSchemaDefaultOptions } from "./definitions";
import { JSONSchema7, FromSchemaOptions, FromSchemaDefaultOptions, DeserializationPattern } from "./definitions";
import { ParseSchemaOptions } from "./parse-schema";

@@ -7,4 +7,5 @@ export declare type ParseOptions<S extends JSONSchema7, O extends FromSchemaOptions, N extends Omit<ParseSchemaOptions, "definitions"> = {

definitionsPath: O["definitionsPath"] extends string ? O["definitionsPath"] : FromSchemaDefaultOptions["definitionsPath"];
deserialize: O["deserialize"] extends DeserializationPattern[] | false ? O["deserialize"] : FromSchemaDefaultOptions["deserialize"];
}> = N & {
definitions: S extends Record<N["definitionsPath"], Record<string, JSONSchema7>> ? S[N["definitionsPath"]] : {};
};
export {};
//# sourceMappingURL=parse-options.js.map

@@ -11,3 +11,3 @@ import { M } from "ts-algebra";

export declare type ParseAllOfSchema<P extends AllOfSchema, O extends ParseSchemaOptions> = RecurseOnAllOfSchema<P["allOf"], P, O, HasKeyIn<P, "enum" | "const" | "type" | "anyOf" | "oneOf"> extends true ? ParseSchema<Omit<P, "allOf">, O> : M.Any>;
declare type RecurseOnAllOfSchema<S extends JSONSchema7[], P extends AllOfSchema, O extends ParseSchemaOptions, R extends any> = {
declare type RecurseOnAllOfSchema<S extends JSONSchema7[], P extends AllOfSchema, O extends ParseSchemaOptions, R> = {
stop: R;

@@ -14,0 +14,0 @@ continue: RecurseOnAllOfSchema<L.Tail<S>, P, O, M.$Intersect<ParseSchema<MergeSubSchema<Omit<P, "allOf">, L.Head<S>>, O>, R>>;

export {};
//# sourceMappingURL=allOf.js.map

@@ -11,3 +11,3 @@ import { M } from "ts-algebra";

export declare type ParseAnyOfSchema<S extends AnyOfSchema, O extends ParseSchemaOptions> = M.$Union<RecurseOnAnyOfSchema<S["anyOf"], S, O>>;
declare type RecurseOnAnyOfSchema<S extends JSONSchema7[], P extends AnyOfSchema, O extends ParseSchemaOptions, R extends any = never> = {
declare type RecurseOnAnyOfSchema<S extends JSONSchema7[], P extends AnyOfSchema, O extends ParseSchemaOptions, R = never> = {
stop: R;

@@ -14,0 +14,0 @@ continue: RecurseOnAnyOfSchema<L.Tail<S>, P, O, R | (HasKeyIn<P, "enum" | "const" | "type"> extends true ? M.$Intersect<ParseSchema<Omit<P, "anyOf">, O>, ParseSchema<MergeSubSchema<Omit<P, "anyOf">, L.Head<S>>, O>> : ParseSchema<Merge<Omit<P, "anyOf">, RemoveInvalidAdditionalItems<L.Head<S>>>, O>)>;

export {};
//# sourceMappingURL=anyOf.js.map

@@ -29,3 +29,3 @@ import { M } from "ts-algebra";

} ? S["additionalItems"] : true, O>;
declare type ApplyBoundaries<T extends any[], Min extends number, Max extends number | undefined, R extends any = never, HasMin extends boolean = false, HasMax extends boolean = false, C extends any[] = T> = {
declare type ApplyBoundaries<T extends any[], Min extends number, Max extends number | undefined, R = never, HasMin extends boolean = false, HasMax extends boolean = false, C extends any[] = T> = {
stop: {

@@ -32,0 +32,0 @@ result: Max extends undefined ? R | M.$Tuple<L.Reverse<T>> : HasMax extends true ? R | M.$Tuple<L.Reverse<T>> : Max extends T["length"] ? M.$Tuple<L.Reverse<T>> : IsLongerThan<L.Tail<T>, Max> extends true ? never : R | M.$Tuple<L.Reverse<T>>;

export {};
//# sourceMappingURL=array.js.map
export {};
//# sourceMappingURL=const.js.map
export {};
//# sourceMappingURL=definition.js.map
export {};
//# sourceMappingURL=enum.js.map

@@ -11,3 +11,3 @@ import { M } from "ts-algebra";

};
export declare type ParseIfThenElseSchema<S extends IfThenElseSchema, O extends ParseSchemaOptions, R extends JSONSchema7 = Omit<S, "if" | "then" | "else">, I extends JSONSchema7 = MergeSubSchema<R, S["if"]>, T extends any = S extends {
export declare type ParseIfThenElseSchema<S extends IfThenElseSchema, O extends ParseSchemaOptions, R extends JSONSchema7 = Omit<S, "if" | "then" | "else">, I extends JSONSchema7 = MergeSubSchema<R, S["if"]>, T = S extends {
then: JSONSchema7;

@@ -14,0 +14,0 @@ } ? M.$Intersect<ParseSchema<I, O>, ParseSchema<MergeSubSchema<R, S["then"]>, O>> : ParseSchema<I, O>, E = S extends {

export {};
//# sourceMappingURL=ifThenElse.js.map
import { M } from "ts-algebra";
import { JSONSchema7 } from "../definitions";
import { DeserializationPattern, JSONSchema7 } from "../definitions";
import { And, DoesExtend } from "../utils";
import { DeserializeSchema } from "./deserialize";
import { ConstSchema, ParseConstSchema } from "./const";

@@ -20,3 +21,6 @@ import { EnumSchema, ParseEnumSchema } from "./enum";

definitions: Record<string, JSONSchema7>;
deserialize: DeserializationPattern[] | false;
};
export declare type ParseSchema<S extends JSONSchema7, O extends ParseSchemaOptions> = JSONSchema7 extends S ? M.Any : S extends true | string ? M.Any : S extends false ? M.Never : S extends NullableSchema ? ParseNullableSchema<S, O> : S extends DefinitionSchema<O> ? ParseDefinitionSchema<S, O> : And<DoesExtend<O["parseIfThenElseKeywords"], true>, DoesExtend<S, IfThenElseSchema>> extends true ? S extends IfThenElseSchema ? ParseIfThenElseSchema<S, O> : never : And<DoesExtend<O["parseNotKeyword"], true>, DoesExtend<S, NotSchema>> extends true ? S extends NotSchema ? ParseNotSchema<S, O> : never : S extends AllOfSchema ? ParseAllOfSchema<S, O> : S extends OneOfSchema ? ParseOneOfSchema<S, O> : S extends AnyOfSchema ? ParseAnyOfSchema<S, O> : S extends EnumSchema ? ParseEnumSchema<S, O> : S extends ConstSchema ? ParseConstSchema<S, O> : S extends MultipleTypesSchema ? ParseMultipleTypesSchema<S, O> : S extends SingleTypeSchema ? ParseSingleTypeSchema<S, O> : M.Any;
export declare type ParseSchema<S extends JSONSchema7, O extends ParseSchemaOptions, P = JSONSchema7 extends S ? M.Any : S extends true | string ? M.Any : S extends false ? M.Never : S extends NullableSchema ? ParseNullableSchema<S, O> : S extends DefinitionSchema<O> ? ParseDefinitionSchema<S, O> : And<DoesExtend<O["parseIfThenElseKeywords"], true>, DoesExtend<S, IfThenElseSchema>> extends true ? S extends IfThenElseSchema ? ParseIfThenElseSchema<S, O> : never : And<DoesExtend<O["parseNotKeyword"], true>, DoesExtend<S, NotSchema>> extends true ? S extends NotSchema ? ParseNotSchema<S, O> : never : S extends AllOfSchema ? ParseAllOfSchema<S, O> : S extends OneOfSchema ? ParseOneOfSchema<S, O> : S extends AnyOfSchema ? ParseAnyOfSchema<S, O> : S extends EnumSchema ? ParseEnumSchema<S, O> : S extends ConstSchema ? ParseConstSchema<S, O> : S extends MultipleTypesSchema ? ParseMultipleTypesSchema<S, O> : S extends SingleTypeSchema ? ParseSingleTypeSchema<S, O> : M.Any> = O extends {
deserialize: DeserializationPattern[];
} ? M.$Intersect<DeserializeSchema<S, O>, P> : P;
export {};
//# sourceMappingURL=index.js.map

@@ -10,3 +10,3 @@ import { JSONSchema7TypeName } from "json-schema";

export declare type ParseMultipleTypesSchema<P extends MultipleTypesSchema, O extends ParseSchemaOptions> = M.$Union<RecurseOnMixedSchema<P["type"], P, O>>;
declare type RecurseOnMixedSchema<S extends JSONSchema7TypeName[], P extends MultipleTypesSchema, O extends ParseSchemaOptions, R extends any = never> = {
declare type RecurseOnMixedSchema<S extends JSONSchema7TypeName[], P extends MultipleTypesSchema, O extends ParseSchemaOptions, R = never> = {
stop: R;

@@ -13,0 +13,0 @@ continue: RecurseOnMixedSchema<L.Tail<S>, P, O, R | ParseSchema<Omit<P, "type"> & {

export {};
//# sourceMappingURL=multipleTypes.js.map

@@ -10,3 +10,3 @@ import { M } from "ts-algebra";

declare type AllTypes = M.Union<M.Primitive<null> | M.Primitive<boolean> | M.Primitive<number> | M.Primitive<string> | M.Array<M.Any> | M.Object<{}, never, M.Any>>;
export declare type ParseNotSchema<S extends NotSchema, O extends ParseSchemaOptions, P extends any = ParseSchema<Omit<S, "not">, O>, E = M.$Exclude<HasKeyIn<S, "enum" | "const" | "type" | "anyOf" | "oneOf" | "allOf"> extends true ? P : AllTypes, ParseSchema<MergeSubSchema<Omit<S, "not">, S["not"]>, O>>> = E extends M.Never ? P : E;
export declare type ParseNotSchema<S extends NotSchema, O extends ParseSchemaOptions, P = ParseSchema<Omit<S, "not">, O>, E = M.$Exclude<HasKeyIn<S, "enum" | "const" | "type" | "anyOf" | "oneOf" | "allOf"> extends true ? P : AllTypes, ParseSchema<MergeSubSchema<Omit<S, "not">, S["not"]>, O>>> = E extends M.Never ? P : E;
export {};
export {};
//# sourceMappingURL=not.js.map

@@ -8,4 +8,4 @@ import { M } from "ts-algebra";

import { ParseSchema, ParseSchemaOptions } from "./index";
export declare type ParseNullableSchema<S extends NullableSchema, O extends ParseSchemaOptions, R extends any = HasKeyIn<S, "enum" | "const" | "type" | "anyOf" | "oneOf" | "allOf" | "not" | "if"> extends true ? ParseSchema<Omit<S, "nullable">, O> : M.Any> = S extends {
export declare type ParseNullableSchema<S extends NullableSchema, O extends ParseSchemaOptions, R = HasKeyIn<S, "enum" | "const" | "type" | "anyOf" | "oneOf" | "allOf" | "not" | "if"> extends true ? ParseSchema<Omit<S, "nullable">, O> : M.Any> = S extends {
nullable: true;
} ? M.$Union<M.Primitive<null> | R> : R;
export {};
//# sourceMappingURL=nullable.js.map
export {};
//# sourceMappingURL=object.js.map

@@ -11,3 +11,3 @@ import { M } from "ts-algebra";

export declare type ParseOneOfSchema<P extends OneOfSchema, O extends ParseSchemaOptions> = M.$Union<RecurseOnOneOfSchema<P["oneOf"], P, O>>;
declare type RecurseOnOneOfSchema<S extends JSONSchema7[], P extends OneOfSchema, O extends ParseSchemaOptions, R extends any = never> = {
declare type RecurseOnOneOfSchema<S extends JSONSchema7[], P extends OneOfSchema, O extends ParseSchemaOptions, R = never> = {
stop: R;

@@ -14,0 +14,0 @@ continue: RecurseOnOneOfSchema<L.Tail<S>, P, O, R | (HasKeyIn<P, "enum" | "const" | "type" | "anyOf"> extends true ? M.$Intersect<ParseSchema<Omit<P, "oneOf">, O>, ParseSchema<MergeSubSchema<Omit<P, "oneOf">, L.Head<S>>, O>> : ParseSchema<Merge<Omit<P, "oneOf">, RemoveInvalidAdditionalItems<L.Head<S>>>, O>)>;

export {};
//# sourceMappingURL=oneOf.js.map
export {};
//# sourceMappingURL=singleType.js.map
export {};
//# sourceMappingURL=utils.js.map
export {};
//# sourceMappingURL=and.js.map
export {};
//# sourceMappingURL=extends.js.map
export {};
//# sourceMappingURL=hasKeyIn.js.map
export {};
//# sourceMappingURL=index.js.map
export {};
//# sourceMappingURL=merge.js.map
export {};
//# sourceMappingURL=readonly.js.map
export {};
//# sourceMappingURL=writable.js.map
{
"name": "json-schema-to-ts",
"version": "2.2.0",
"version": "2.3.0-beta.0",
"description": "Infer typescript types from your JSON schemas!",

@@ -18,3 +18,3 @@ "main": "lib/index.js",

"ts-toolbelt": "^9.6.0",
"ts-algebra": "^1.0.1"
"ts-algebra": "^1.1.1"
},

@@ -21,0 +21,0 @@ "devDependencies": {

@@ -138,2 +138,3 @@ <img src="assets/header-round-medium.png" width="100%" align="center" />

- [Definitions](#definitions)
- [Deserialization](#deserialization)
- [FAQ](#frequently-asked-questions)

@@ -661,2 +662,54 @@

## Deserialization
You can specify deserialization patterns with the `deserialize` option:
```typescript
const userSchema = {
type: "object",
properties: {
name: { type: "string" },
email: {
type: "string",
format: "email",
},
birthDate: {
type: "string",
format: "date-time",
},
},
required: ["name", "email", "birthDate"],
additionalProperties: false,
} as const;
type Email = string & { brand: "email" };
type ReceivedUser = FromSchema<
typeof userSchema,
{
deserialize: [
{
pattern: {
type: "string";
format: "email";
};
output: Email;
},
{
pattern: {
type: "string";
format: "date-time";
};
output: Date;
}
];
}
>;
// => {
// name: string;
// email: Email;
// birthDate: Date;
// }
```
## Frequently Asked Questions

@@ -663,0 +716,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc