New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

@sinclair/typebox-codegen

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sinclair/typebox-codegen - npm Package Compare versions

Comparing version
0.8.13
to
0.9.0
sinclair-typebox-codegen-0.8.13.tgz

Sorry, the diff of this file is not supported yet

+29
-29

@@ -164,3 +164,3 @@ "use strict";

.map(([key, schema]) => {
const optional = Types.TypeGuard.TOptional(schema);
const optional = Types.TypeGuard.IsOptional(schema);
const property1 = index_1.PropertyEncoder.Encode(key);

@@ -220,53 +220,53 @@ const property2 = optional ? `'${property1}?'` : `${property1}`;

return `'${schema.$id}'`;
if (Types.TypeGuard.TAny(schema))
if (Types.TypeGuard.IsAny(schema))
return Any(schema);
if (Types.TypeGuard.TArray(schema))
if (Types.TypeGuard.IsArray(schema))
return Array(schema);
if (Types.TypeGuard.TBigInt(schema))
if (Types.TypeGuard.IsBigInt(schema))
return BigInt(schema);
if (Types.TypeGuard.TBoolean(schema))
if (Types.TypeGuard.IsBoolean(schema))
return Boolean(schema);
if (Types.TypeGuard.TConstructor(schema))
if (Types.TypeGuard.IsConstructor(schema))
return Constructor(schema);
if (Types.TypeGuard.TDate(schema))
if (Types.TypeGuard.IsDate(schema))
return Date(schema);
if (Types.TypeGuard.TFunction(schema))
if (Types.TypeGuard.IsFunction(schema))
return Function(schema);
if (Types.TypeGuard.TInteger(schema))
if (Types.TypeGuard.IsInteger(schema))
return Integer(schema);
if (Types.TypeGuard.TIntersect(schema))
if (Types.TypeGuard.IsIntersect(schema))
return Intersect(schema);
if (Types.TypeGuard.TLiteral(schema))
if (Types.TypeGuard.IsLiteral(schema))
return Literal(schema);
if (Types.TypeGuard.TNever(schema))
if (Types.TypeGuard.IsNever(schema))
return Never(schema);
if (Types.TypeGuard.TNull(schema))
if (Types.TypeGuard.IsNull(schema))
return Null(schema);
if (Types.TypeGuard.TNumber(schema))
if (Types.TypeGuard.IsNumber(schema))
return Number(schema);
if (Types.TypeGuard.TObject(schema))
if (Types.TypeGuard.IsObject(schema))
return Object(schema);
if (Types.TypeGuard.TPromise(schema))
if (Types.TypeGuard.IsPromise(schema))
return Promise(schema);
if (Types.TypeGuard.TRecord(schema))
if (Types.TypeGuard.IsRecord(schema))
return Record(schema);
if (Types.TypeGuard.TRef(schema))
if (Types.TypeGuard.IsRef(schema))
return Ref(schema);
if (Types.TypeGuard.TString(schema))
if (Types.TypeGuard.IsString(schema))
return String(schema);
if (Types.TypeGuard.TTemplateLiteral(schema))
if (Types.TypeGuard.IsTemplateLiteral(schema))
return TemplateLiteral(schema);
if (Types.TypeGuard.TThis(schema))
if (Types.TypeGuard.IsThis(schema))
return This(schema);
if (Types.TypeGuard.TTuple(schema))
if (Types.TypeGuard.IsTuple(schema))
return Tuple(schema);
if (Types.TypeGuard.TUint8Array(schema))
if (Types.TypeGuard.IsUint8Array(schema))
return UInt8Array(schema);
if (Types.TypeGuard.TUndefined(schema))
if (Types.TypeGuard.IsUndefined(schema))
return Undefined(schema);
if (Types.TypeGuard.TUnion(schema))
if (Types.TypeGuard.IsUnion(schema))
return Union(schema);
if (Types.TypeGuard.TUnknown(schema))
if (Types.TypeGuard.IsUnknown(schema))
return Unknown(schema);
if (Types.TypeGuard.TVoid(schema))
if (Types.TypeGuard.IsVoid(schema))
return Void(schema);

@@ -298,3 +298,3 @@ return UnsupportedType(schema);

buffer.push('export const types = scope({');
for (const type of model.types.filter((type) => Types.TypeGuard.TSchema(type))) {
for (const type of model.types.filter((type) => Types.TypeGuard.IsSchema(type))) {
buffer.push(`${GenerateType(type, model.types)},`);

@@ -304,3 +304,3 @@ }

buffer.push('\n');
for (const type of model.types.filter((type) => Types.TypeGuard.TSchema(type))) {
for (const type of model.types.filter((type) => Types.TypeGuard.IsSchema(type))) {
buffer.push(`export type ${type.$id} = typeof ${type.$id}.infer`);

@@ -307,0 +307,0 @@ buffer.push(`export const ${type.$id} = types.${type.$id}`);

@@ -146,4 +146,4 @@ "use strict";

const properties = globalThis.Object.entries(schema.properties).map(([key, value]) => {
const optional = Types.TypeGuard.TOptional(value);
const readonly = Types.TypeGuard.TReadonly(value);
const optional = Types.TypeGuard.IsOptional(value);
const readonly = Types.TypeGuard.IsReadonly(value);
const property = index_1.PropertyEncoder.Encode(key);

@@ -232,53 +232,53 @@ const resolved = optional ? `t.union([t.undefined, ${Visit(value)}])` : Visit(value);

return schema.$id;
if (Types.TypeGuard.TAny(schema))
if (Types.TypeGuard.IsAny(schema))
return Any(schema);
if (Types.TypeGuard.TArray(schema))
if (Types.TypeGuard.IsArray(schema))
return Array(schema);
if (Types.TypeGuard.TBigInt(schema))
if (Types.TypeGuard.IsBigInt(schema))
return BigInt(schema);
if (Types.TypeGuard.TBoolean(schema))
if (Types.TypeGuard.IsBoolean(schema))
return Boolean(schema);
if (Types.TypeGuard.TDate(schema))
if (Types.TypeGuard.IsDate(schema))
return Date(schema);
if (Types.TypeGuard.TConstructor(schema))
if (Types.TypeGuard.IsConstructor(schema))
return Constructor(schema);
if (Types.TypeGuard.TFunction(schema))
if (Types.TypeGuard.IsFunction(schema))
return Function(schema);
if (Types.TypeGuard.TInteger(schema))
if (Types.TypeGuard.IsInteger(schema))
return Integer(schema);
if (Types.TypeGuard.TIntersect(schema))
if (Types.TypeGuard.IsIntersect(schema))
return Intersect(schema);
if (Types.TypeGuard.TLiteral(schema))
if (Types.TypeGuard.IsLiteral(schema))
return Literal(schema);
if (Types.TypeGuard.TNever(schema))
if (Types.TypeGuard.IsNever(schema))
return Never(schema);
if (Types.TypeGuard.TNull(schema))
if (Types.TypeGuard.IsNull(schema))
return Null(schema);
if (Types.TypeGuard.TNumber(schema))
if (Types.TypeGuard.IsNumber(schema))
return Number(schema);
if (Types.TypeGuard.TObject(schema))
if (Types.TypeGuard.IsObject(schema))
return Object(schema);
if (Types.TypeGuard.TPromise(schema))
if (Types.TypeGuard.IsPromise(schema))
return Promise(schema);
if (Types.TypeGuard.TRecord(schema))
if (Types.TypeGuard.IsRecord(schema))
return Record(schema);
if (Types.TypeGuard.TRef(schema))
if (Types.TypeGuard.IsRef(schema))
return Ref(schema);
if (Types.TypeGuard.TString(schema))
if (Types.TypeGuard.IsString(schema))
return String(schema);
if (Types.TypeGuard.TTemplateLiteral(schema))
if (Types.TypeGuard.IsTemplateLiteral(schema))
return TemplateLiteral(schema);
if (Types.TypeGuard.TThis(schema))
if (Types.TypeGuard.IsThis(schema))
return This(schema);
if (Types.TypeGuard.TTuple(schema))
if (Types.TypeGuard.IsTuple(schema))
return Tuple(schema);
if (Types.TypeGuard.TUint8Array(schema))
if (Types.TypeGuard.IsUint8Array(schema))
return UInt8Array(schema);
if (Types.TypeGuard.TUndefined(schema))
if (Types.TypeGuard.IsUndefined(schema))
return Undefined(schema);
if (Types.TypeGuard.TUnion(schema))
if (Types.TypeGuard.IsUnion(schema))
return Union(schema);
if (Types.TypeGuard.TUnknown(schema))
if (Types.TypeGuard.IsUnknown(schema))
return Unknown(schema);
if (Types.TypeGuard.TVoid(schema))
if (Types.TypeGuard.IsVoid(schema))
return Void(schema);

@@ -319,3 +319,3 @@ return UnsupportedType(schema);

const buffer = [`import t from 'io-ts'`, ''];
const types = model.types.filter((type) => Types.TypeGuard.TSchema(type)).map((type) => GenerateType(model, type, model.types));
const types = model.types.filter((type) => Types.TypeGuard.IsSchema(type)).map((type) => GenerateType(model, type, model.types));
buffer.push(...support_types.values());

@@ -322,0 +322,0 @@ buffer.push('\n');

@@ -132,53 +132,53 @@ "use strict";

function Visit(schema) {
if (Types.TypeGuard.TAny(schema))
if (Types.TypeGuard.IsAny(schema))
return Any(schema);
if (Types.TypeGuard.TArray(schema))
if (Types.TypeGuard.IsArray(schema))
return Array(schema);
if (Types.TypeGuard.TBigInt(schema))
if (Types.TypeGuard.IsBigInt(schema))
return BigInt(schema);
if (Types.TypeGuard.TBoolean(schema))
if (Types.TypeGuard.IsBoolean(schema))
return Boolean(schema);
if (Types.TypeGuard.TDate(schema))
if (Types.TypeGuard.IsDate(schema))
return Date(schema);
if (Types.TypeGuard.TConstructor(schema))
if (Types.TypeGuard.IsConstructor(schema))
return Constructor(schema);
if (Types.TypeGuard.TFunction(schema))
if (Types.TypeGuard.IsFunction(schema))
return Function(schema);
if (Types.TypeGuard.TInteger(schema))
if (Types.TypeGuard.IsInteger(schema))
return Integer(schema);
if (Types.TypeGuard.TIntersect(schema))
if (Types.TypeGuard.IsIntersect(schema))
return Intersect(schema);
if (Types.TypeGuard.TLiteral(schema))
if (Types.TypeGuard.IsLiteral(schema))
return Literal(schema);
if (Types.TypeGuard.TNever(schema))
if (Types.TypeGuard.IsNever(schema))
return Never(schema);
if (Types.TypeGuard.TNull(schema))
if (Types.TypeGuard.IsNull(schema))
return Null(schema);
if (Types.TypeGuard.TNumber(schema))
if (Types.TypeGuard.IsNumber(schema))
return Number(schema);
if (Types.TypeGuard.TObject(schema))
if (Types.TypeGuard.IsObject(schema))
return Object(schema);
if (Types.TypeGuard.TPromise(schema))
if (Types.TypeGuard.IsPromise(schema))
return Promise(schema);
if (Types.TypeGuard.TRecord(schema))
if (Types.TypeGuard.IsRecord(schema))
return Record(schema);
if (Types.TypeGuard.TRef(schema))
if (Types.TypeGuard.IsRef(schema))
return Ref(schema);
if (Types.TypeGuard.TString(schema))
if (Types.TypeGuard.IsString(schema))
return String(schema);
if (Types.TypeGuard.TTemplateLiteral(schema))
if (Types.TypeGuard.IsTemplateLiteral(schema))
return TemplateLiteral(schema);
if (Types.TypeGuard.TThis(schema))
if (Types.TypeGuard.IsThis(schema))
return This(schema);
if (Types.TypeGuard.TTuple(schema))
if (Types.TypeGuard.IsTuple(schema))
return Tuple(schema);
if (Types.TypeGuard.TUint8Array(schema))
if (Types.TypeGuard.IsUint8Array(schema))
return UInt8Array(schema);
if (Types.TypeGuard.TUndefined(schema))
if (Types.TypeGuard.IsUndefined(schema))
return Undefined(schema);
if (Types.TypeGuard.TUnion(schema))
if (Types.TypeGuard.IsUnion(schema))
return Union(schema);
if (Types.TypeGuard.TUnknown(schema))
if (Types.TypeGuard.IsUnknown(schema))
return Unknown(schema);
if (Types.TypeGuard.TVoid(schema))
if (Types.TypeGuard.IsVoid(schema))
return Void(schema);

@@ -189,3 +189,3 @@ return UnsupportedType(schema);

const buffer = [];
for (const type of model.types.filter((type) => Types.TypeGuard.TSchema(type))) {
for (const type of model.types.filter((type) => Types.TypeGuard.IsSchema(type))) {
const schema = Visit(type);

@@ -192,0 +192,0 @@ const encode = JSON.stringify(schema, null, 2);

@@ -142,51 +142,51 @@ "use strict";

reference_map.set(schema.$id, schema);
if (Types.TypeGuard.TAny(schema))
if (Types.TypeGuard.IsAny(schema))
return Any(schema);
if (Types.TypeGuard.TArray(schema))
if (Types.TypeGuard.IsArray(schema))
return Array(schema);
if (Types.TypeGuard.TBoolean(schema))
if (Types.TypeGuard.IsBoolean(schema))
return Boolean(schema);
if (Types.TypeGuard.TBigInt(schema))
if (Types.TypeGuard.IsBigInt(schema))
return BigInt(schema);
if (Types.TypeGuard.TConstructor(schema))
if (Types.TypeGuard.IsConstructor(schema))
return Constructor(schema);
if (Types.TypeGuard.TDate(schema))
if (Types.TypeGuard.IsDate(schema))
return Date(schema);
if (Types.TypeGuard.TFunction(schema))
if (Types.TypeGuard.IsFunction(schema))
return Function(schema);
if (Types.TypeGuard.TInteger(schema))
if (Types.TypeGuard.IsInteger(schema))
return Integer(schema);
if (Types.TypeGuard.TIntersect(schema))
if (Types.TypeGuard.IsIntersect(schema))
return Intersect(schema);
if (Types.TypeGuard.TLiteral(schema))
if (Types.TypeGuard.IsLiteral(schema))
return Literal(schema);
if (Types.TypeGuard.TNever(schema))
if (Types.TypeGuard.IsNever(schema))
return Never(schema);
if (Types.TypeGuard.TNull(schema))
if (Types.TypeGuard.IsNull(schema))
return Null(schema);
if (Types.TypeGuard.TNumber(schema))
if (Types.TypeGuard.IsNumber(schema))
return Number(schema);
if (Types.TypeGuard.TObject(schema))
if (Types.TypeGuard.IsObject(schema))
return Object(schema);
if (Types.TypeGuard.TPromise(schema))
if (Types.TypeGuard.IsPromise(schema))
return Promise(schema);
if (Types.TypeGuard.TRecord(schema))
if (Types.TypeGuard.IsRecord(schema))
return Record(schema);
if (Types.TypeGuard.TRef(schema))
if (Types.TypeGuard.IsRef(schema))
return Ref(schema);
if (Types.TypeGuard.TThis(schema))
if (Types.TypeGuard.IsThis(schema))
return This(schema);
if (Types.TypeGuard.TString(schema))
if (Types.TypeGuard.IsString(schema))
return String(schema);
if (Types.TypeGuard.TTuple(schema))
if (Types.TypeGuard.IsTuple(schema))
return Tuple(schema);
if (Types.TypeGuard.TUint8Array(schema))
if (Types.TypeGuard.IsUint8Array(schema))
return UInt8Array(schema);
if (Types.TypeGuard.TUndefined(schema))
if (Types.TypeGuard.IsUndefined(schema))
return Undefined(schema);
if (Types.TypeGuard.TUnion(schema))
if (Types.TypeGuard.IsUnion(schema))
return Union(schema);
if (Types.TypeGuard.TUnknown(schema))
if (Types.TypeGuard.IsUnknown(schema))
return Unknown(schema);
if (Types.TypeGuard.TVoid(schema))
if (Types.TypeGuard.IsVoid(schema))
return Void(schema);

@@ -193,0 +193,0 @@ return 'unknown';

@@ -127,3 +127,3 @@ "use strict";

const properties = globalThis.Object.entries(schema.properties).map(([key, value]) => {
const optional = Types.TypeGuard.TOptional(value);
const optional = Types.TypeGuard.IsOptional(value);
const property = index_1.PropertyEncoder.Encode(key);

@@ -192,53 +192,53 @@ return optional ? `${property}: v.optional(${Visit(value)})` : `${property}: ${Visit(value)}`;

return schema.$id;
if (Types.TypeGuard.TAny(schema))
if (Types.TypeGuard.IsAny(schema))
return Any(schema);
if (Types.TypeGuard.TArray(schema))
if (Types.TypeGuard.IsArray(schema))
return Array(schema);
if (Types.TypeGuard.TBigInt(schema))
if (Types.TypeGuard.IsBigInt(schema))
return BigInt(schema);
if (Types.TypeGuard.TBoolean(schema))
if (Types.TypeGuard.IsBoolean(schema))
return Boolean(schema);
if (Types.TypeGuard.TDate(schema))
if (Types.TypeGuard.IsDate(schema))
return Date(schema);
if (Types.TypeGuard.TConstructor(schema))
if (Types.TypeGuard.IsConstructor(schema))
return Constructor(schema);
if (Types.TypeGuard.TFunction(schema))
if (Types.TypeGuard.IsFunction(schema))
return Function(schema);
if (Types.TypeGuard.TInteger(schema))
if (Types.TypeGuard.IsInteger(schema))
return Integer(schema);
if (Types.TypeGuard.TIntersect(schema))
if (Types.TypeGuard.IsIntersect(schema))
return Intersect(schema);
if (Types.TypeGuard.TLiteral(schema))
if (Types.TypeGuard.IsLiteral(schema))
return Literal(schema);
if (Types.TypeGuard.TNever(schema))
if (Types.TypeGuard.IsNever(schema))
return Never(schema);
if (Types.TypeGuard.TNull(schema))
if (Types.TypeGuard.IsNull(schema))
return Null(schema);
if (Types.TypeGuard.TNumber(schema))
if (Types.TypeGuard.IsNumber(schema))
return Number(schema);
if (Types.TypeGuard.TObject(schema))
if (Types.TypeGuard.IsObject(schema))
return Object(schema);
if (Types.TypeGuard.TPromise(schema))
if (Types.TypeGuard.IsPromise(schema))
return Promise(schema);
if (Types.TypeGuard.TRecord(schema))
if (Types.TypeGuard.IsRecord(schema))
return Record(schema);
if (Types.TypeGuard.TRef(schema))
if (Types.TypeGuard.IsRef(schema))
return Ref(schema);
if (Types.TypeGuard.TString(schema))
if (Types.TypeGuard.IsString(schema))
return String(schema);
if (Types.TypeGuard.TTemplateLiteral(schema))
if (Types.TypeGuard.IsTemplateLiteral(schema))
return TemplateLiteral(schema);
if (Types.TypeGuard.TThis(schema))
if (Types.TypeGuard.IsThis(schema))
return This(schema);
if (Types.TypeGuard.TTuple(schema))
if (Types.TypeGuard.IsTuple(schema))
return Tuple(schema);
if (Types.TypeGuard.TUint8Array(schema))
if (Types.TypeGuard.IsUint8Array(schema))
return UInt8Array(schema);
if (Types.TypeGuard.TUndefined(schema))
if (Types.TypeGuard.IsUndefined(schema))
return Undefined(schema);
if (Types.TypeGuard.TUnion(schema))
if (Types.TypeGuard.IsUnion(schema))
return Union(schema);
if (Types.TypeGuard.TUnknown(schema))
if (Types.TypeGuard.IsUnknown(schema))
return Unknown(schema);
if (Types.TypeGuard.TVoid(schema))
if (Types.TypeGuard.IsVoid(schema))
return Void(schema);

@@ -278,3 +278,3 @@ return UnsupportedType(schema);

const buffer = [`import * as v from 'valibot'`, ''];
for (const type of model.types.filter((type) => Types.TypeGuard.TSchema(type))) {
for (const type of model.types.filter((type) => Types.TypeGuard.IsSchema(type))) {
buffer.push(GenerateType(model, type, model.types));

@@ -281,0 +281,0 @@ }

@@ -85,3 +85,3 @@ "use strict";

function Intersect(schema) {
const mergable = schema.allOf.every((schema) => Types.TypeGuard.TObject(schema));
const mergable = schema.allOf.every((schema) => Types.TypeGuard.IsObject(schema));
if (!mergable)

@@ -130,3 +130,3 @@ return UnsupportedType(schema);

const properties = globalThis.Object.entries(schema.properties).map(([key, value]) => {
const optional = Types.TypeGuard.TOptional(value);
const optional = Types.TypeGuard.IsOptional(value);
const property = index_1.PropertyEncoder.Encode(key);

@@ -185,53 +185,53 @@ return optional ? `${property}: ${Visit(value)}.optional()` : `${property}: ${Visit(value)}`;

return schema.$id;
if (Types.TypeGuard.TAny(schema))
if (Types.TypeGuard.IsAny(schema))
return Any(schema);
if (Types.TypeGuard.TArray(schema))
if (Types.TypeGuard.IsArray(schema))
return Array(schema);
if (Types.TypeGuard.TBigInt(schema))
if (Types.TypeGuard.IsBigInt(schema))
return BigInt(schema);
if (Types.TypeGuard.TBoolean(schema))
if (Types.TypeGuard.IsBoolean(schema))
return Boolean(schema);
if (Types.TypeGuard.TDate(schema))
if (Types.TypeGuard.IsDate(schema))
return Date(schema);
if (Types.TypeGuard.TConstructor(schema))
if (Types.TypeGuard.IsConstructor(schema))
return Constructor(schema);
if (Types.TypeGuard.TFunction(schema))
if (Types.TypeGuard.IsFunction(schema))
return Function(schema);
if (Types.TypeGuard.TInteger(schema))
if (Types.TypeGuard.IsInteger(schema))
return Integer(schema);
if (Types.TypeGuard.TIntersect(schema))
if (Types.TypeGuard.IsIntersect(schema))
return Intersect(schema);
if (Types.TypeGuard.TLiteral(schema))
if (Types.TypeGuard.IsLiteral(schema))
return Literal(schema);
if (Types.TypeGuard.TNever(schema))
if (Types.TypeGuard.IsNever(schema))
return Never(schema);
if (Types.TypeGuard.TNull(schema))
if (Types.TypeGuard.IsNull(schema))
return Null(schema);
if (Types.TypeGuard.TNumber(schema))
if (Types.TypeGuard.IsNumber(schema))
return Number(schema);
if (Types.TypeGuard.TObject(schema))
if (Types.TypeGuard.IsObject(schema))
return Object(schema);
if (Types.TypeGuard.TPromise(schema))
if (Types.TypeGuard.IsPromise(schema))
return Promise(schema);
if (Types.TypeGuard.TRecord(schema))
if (Types.TypeGuard.IsRecord(schema))
return Record(schema);
if (Types.TypeGuard.TRef(schema))
if (Types.TypeGuard.IsRef(schema))
return Ref(schema);
if (Types.TypeGuard.TString(schema))
if (Types.TypeGuard.IsString(schema))
return String(schema);
if (Types.TypeGuard.TTemplateLiteral(schema))
if (Types.TypeGuard.IsTemplateLiteral(schema))
return TemplateLiteral(schema);
if (Types.TypeGuard.TThis(schema))
if (Types.TypeGuard.IsThis(schema))
return This(schema);
if (Types.TypeGuard.TTuple(schema))
if (Types.TypeGuard.IsTuple(schema))
return Tuple(schema);
if (Types.TypeGuard.TUint8Array(schema))
if (Types.TypeGuard.IsUint8Array(schema))
return UInt8Array(schema);
if (Types.TypeGuard.TUndefined(schema))
if (Types.TypeGuard.IsUndefined(schema))
return Undefined(schema);
if (Types.TypeGuard.TUnion(schema))
if (Types.TypeGuard.IsUnion(schema))
return Union(schema);
if (Types.TypeGuard.TUnknown(schema))
if (Types.TypeGuard.IsUnknown(schema))
return Unknown(schema);
if (Types.TypeGuard.TVoid(schema))
if (Types.TypeGuard.IsVoid(schema))
return Void(schema);

@@ -271,3 +271,3 @@ return UnsupportedType(schema);

const buffer = [`import y from 'yup'`, ''];
for (const type of model.types.filter((type) => Types.TypeGuard.TSchema(type))) {
for (const type of model.types.filter((type) => Types.TypeGuard.IsSchema(type))) {
buffer.push(GenerateType(model, type, model.types));

@@ -274,0 +274,0 @@ }

@@ -135,4 +135,4 @@ "use strict";

const properties = globalThis.Object.entries(schema.properties).map(([key, value]) => {
const optional = Types.TypeGuard.TOptional(value);
const readonly = Types.TypeGuard.TReadonly(value);
const optional = Types.TypeGuard.IsOptional(value);
const readonly = Types.TypeGuard.IsReadonly(value);
const property = index_1.PropertyEncoder.Encode(key);

@@ -210,53 +210,53 @@ // prettier-ignore

return schema.$id;
if (Types.TypeGuard.TAny(schema))
if (Types.TypeGuard.IsAny(schema))
return Any(schema);
if (Types.TypeGuard.TArray(schema))
if (Types.TypeGuard.IsArray(schema))
return Array(schema);
if (Types.TypeGuard.TBigInt(schema))
if (Types.TypeGuard.IsBigInt(schema))
return BigInt(schema);
if (Types.TypeGuard.TBoolean(schema))
if (Types.TypeGuard.IsBoolean(schema))
return Boolean(schema);
if (Types.TypeGuard.TDate(schema))
if (Types.TypeGuard.IsDate(schema))
return Date(schema);
if (Types.TypeGuard.TConstructor(schema))
if (Types.TypeGuard.IsConstructor(schema))
return Constructor(schema);
if (Types.TypeGuard.TFunction(schema))
if (Types.TypeGuard.IsFunction(schema))
return Function(schema);
if (Types.TypeGuard.TInteger(schema))
if (Types.TypeGuard.IsInteger(schema))
return Integer(schema);
if (Types.TypeGuard.TIntersect(schema))
if (Types.TypeGuard.IsIntersect(schema))
return Intersect(schema);
if (Types.TypeGuard.TLiteral(schema))
if (Types.TypeGuard.IsLiteral(schema))
return Literal(schema);
if (Types.TypeGuard.TNever(schema))
if (Types.TypeGuard.IsNever(schema))
return Never(schema);
if (Types.TypeGuard.TNull(schema))
if (Types.TypeGuard.IsNull(schema))
return Null(schema);
if (Types.TypeGuard.TNumber(schema))
if (Types.TypeGuard.IsNumber(schema))
return Number(schema);
if (Types.TypeGuard.TObject(schema))
if (Types.TypeGuard.IsObject(schema))
return Object(schema);
if (Types.TypeGuard.TPromise(schema))
if (Types.TypeGuard.IsPromise(schema))
return Promise(schema);
if (Types.TypeGuard.TRecord(schema))
if (Types.TypeGuard.IsRecord(schema))
return Record(schema);
if (Types.TypeGuard.TRef(schema))
if (Types.TypeGuard.IsRef(schema))
return Ref(schema);
if (Types.TypeGuard.TString(schema))
if (Types.TypeGuard.IsString(schema))
return String(schema);
if (Types.TypeGuard.TTemplateLiteral(schema))
if (Types.TypeGuard.IsTemplateLiteral(schema))
return TemplateLiteral(schema);
if (Types.TypeGuard.TThis(schema))
if (Types.TypeGuard.IsThis(schema))
return This(schema);
if (Types.TypeGuard.TTuple(schema))
if (Types.TypeGuard.IsTuple(schema))
return Tuple(schema);
if (Types.TypeGuard.TUint8Array(schema))
if (Types.TypeGuard.IsUint8Array(schema))
return UInt8Array(schema);
if (Types.TypeGuard.TUndefined(schema))
if (Types.TypeGuard.IsUndefined(schema))
return Undefined(schema);
if (Types.TypeGuard.TUnion(schema))
if (Types.TypeGuard.IsUnion(schema))
return Union(schema);
if (Types.TypeGuard.TUnknown(schema))
if (Types.TypeGuard.IsUnknown(schema))
return Unknown(schema);
if (Types.TypeGuard.TVoid(schema))
if (Types.TypeGuard.IsVoid(schema))
return Void(schema);

@@ -296,3 +296,3 @@ return UnsupportedType(schema);

const buffer = [`import z from 'zod'`, ''];
for (const type of model.types.filter((type) => Types.TypeGuard.TSchema(type))) {
for (const type of model.types.filter((type) => Types.TypeGuard.IsSchema(type))) {
buffer.push(GenerateType(model, type, model.types));

@@ -299,0 +299,0 @@ }

{
"name": "@sinclair/typebox-codegen",
"version": "0.8.13",
"version": "0.9.0",
"description": "Code Generation Tools for TypeBox",

@@ -32,3 +32,3 @@ "main": "index.js",

"dependencies": {
"@sinclair/typebox": "^0.31.28",
"@sinclair/typebox": "^0.32.0",
"prettier": "^2.8.7",

@@ -35,0 +35,0 @@ "typescript": "^5.1.6"

@@ -40,4 +40,4 @@ "use strict";

const exports = {};
const evaluate = new Function('exports', 'Type', 'Kind', 'TypeGuard', 'TypeClone', 'TemplateLiteralParser', 'TemplateLiteralFinite', 'TemplateLiteralGenerator', code);
evaluate(exports, typebox_1.Type, typebox_1.Kind, typebox_1.TypeGuard, typebox_1.TypeClone, typebox_1.TemplateLiteralParser, typebox_1.TemplateLiteralFinite, typebox_1.TemplateLiteralGenerator);
const evaluate = new Function('exports', 'Type', 'Kind', code);
evaluate(exports, typebox_1.Type, typebox_1.Kind);
return new Map(globalThis.Object.entries(exports));

@@ -44,0 +44,0 @@ }

@@ -66,4 +66,2 @@ "use strict";

let useGenerics = false;
// (auto) tracked for mapped types
let useMapped = false;
// (auto) tracked for cases where composition requires deep clone

@@ -230,7 +228,18 @@ let useTypeClone = false;

function* MappedTypeNode(node) {
useMapped = true;
const K = Collect(node.typeParameter);
const T = Collect(node.type);
const C = Collect(node.typeParameter.constraint);
yield `Mapped(${C}, ${K} => ${T})`;
const readonly = node.readonlyToken !== undefined;
const optional = node.questionToken !== undefined;
const readonly_subtractive = readonly && ts.isMinusToken(node.readonlyToken);
const optional_subtractive = optional && ts.isMinusToken(node.questionToken);
// prettier-ignore
return yield ((readonly && optional) ? ((readonly_subtractive && optional_subtractive) ? `Type.Mapped(${C}, ${K} => Type.Readonly(Type.Optional(${T}, false), false))` :
(readonly_subtractive) ? `Type.Mapped(${C}, ${K} => Type.Readonly(Type.Optional(${T}), false))` :
(optional_subtractive) ? `Type.Mapped(${C}, ${K} => Type.Readonly(Type.Optional(${T}, false)))` :
`Type.Mapped(${C}, ${K} => Type.Readonly(Type.Optional(${T})))`) : (readonly) ? (readonly_subtractive
? `Type.Mapped(${C}, ${K} => Type.Readonly(${T}, false))`
: `Type.Mapped(${C}, ${K} => Type.Readonly(${T}))`) : (optional) ? (optional_subtractive
? `Type.Mapped(${C}, ${K} => Type.Optional(${T}, false))`
: `Type.Mapped(${C}, ${K} => Type.Optional(${T}))`) : `Type.Mapped(${C}, ${K} => ${T})`);
}

@@ -654,41 +663,5 @@ function* MethodSignature(node) {

}
if (useMapped) {
set.add('TemplateLiteralFinite');
set.add('TemplateLiteralParser');
set.add('TemplateLiteralGenerator');
set.add('TTemplateLiteral');
set.add('TPropertyKey');
set.add('TypeGuard');
set.add('TSchema');
set.add('TString');
set.add('TNumber');
set.add('TUnion');
set.add('TLiteral');
}
const imports = [...set].join(', ');
return `import { ${imports} } from '@sinclair/typebox'`;
}
function MappedSupport() {
return useMapped
? [
'type MappedContraintKey = TNumber | TString | TLiteral<TPropertyKey>',
'type MappedConstraint = TTemplateLiteral | TUnion<MappedContraintKey[]> | MappedContraintKey',
'type MappedFunction<C extends MappedConstraint, S extends TSchema = TSchema> = (C: C) => S',
'// prettier-ignore',
'function Mapped<C extends MappedConstraint, F extends MappedFunction<C>>(C: C, F: F) {',
' return (',
' TypeGuard.TTemplateLiteral(C) ? (() => {',
' const E = TemplateLiteralParser.ParseExact(C.pattern)',
' const K = TemplateLiteralFinite.Check(E) ? [...TemplateLiteralGenerator.Generate(E)] : []',
' return Type.Object(K.reduce((A, K) => ({ ...A, [K]: F(Type.Literal(K) as any)}), {}))',
' })() :',
' TypeGuard.TUnion(C) ? Type.Object(C.anyOf.reduce((A, K) => ({ ...A, [K.const]: F(K as any)}), {})) : ',
' TypeGuard.TString(C) ? Type.Record(C, F(C)) : ',
' TypeGuard.TNumber(C) ? Type.Record(C, F(C)) : ',
' Type.Object({ [C.const]: F(C) })',
' )',
'}',
].join('\n')
: '';
}
/** Generates TypeBox types from TypeScript interface and type definitions */

@@ -700,3 +673,2 @@ function Generate(typescriptCode, options) {

typenames.clear();
useMapped = false;
useImports = false;

@@ -710,4 +682,3 @@ useOptions = false;

const imports = ImportStatement();
const mapped = MappedSupport();
const typescript = [imports, '', mapped, '', declarations].join('\n');
const typescript = [imports, '', '', declarations].join('\n');
const assertion = ts.transpileModule(typescript, transpilerOptions);

@@ -714,0 +685,0 @@ if (assertion.diagnostics && assertion.diagnostics.length > 0) {