Skip to content
Open
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
7 changes: 7 additions & 0 deletions src/model/model-to-arktype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,14 @@ export namespace ModelToArkType {
}
function GenerateType(schema: Types.TSchema, references: Types.TSchema[]) {
const buffer: string[] = []
/*
// removed for being n^m [see: Issue #56]
for (const reference of references) {
if (reference.$id === undefined) return UnsupportedType(schema)
reference_map.set(reference.$id, reference)
}
*/
if (!schema.$id || !reference_map.has(schema.$id)) return UnsupportedType(schema);
const type = Collect(schema)
buffer.push(`${schema.$id || `T`}: ${type}`)
if (schema.$id) emitted_types.add(schema.$id)
Expand All @@ -275,6 +279,9 @@ export namespace ModelToArkType {
emitted_types.clear()
const buffer: string[] = []
buffer.push('export const types = scope({')
for (const reference of model.types) {
if (reference.$id) reference_map.set(reference.$id, reference);
}
for (const type of model.types.filter((type) => Types.TypeGuard.IsSchema(type))) {
buffer.push(`${GenerateType(type, model.types)},`)
}
Expand Down
7 changes: 7 additions & 0 deletions src/model/model-to-effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,14 @@ export namespace ModelToEffect {
}
function GenerateType(model: TypeBoxModel, schema: Types.TSchema, references: Types.TSchema[]) {
const output: string[] = []
/*
// removed for being n^m [see: Issue #56]
for (const reference of references) {
if (reference.$id === undefined) return UnsupportedType(schema)
reference_map.set(reference.$id, reference)
}
*/
if (!schema.$id || !reference_map.has(schema.$id)) return UnsupportedType(schema);
const type = Collect(schema)
output.push(`export type ${schema.$id} = ET.Type<typeof ${schema.$id}>`)
output.push(`export const ${schema.$id || `T`} = ${Formatter.Format(type)}`)
Expand All @@ -220,6 +224,9 @@ export namespace ModelToEffect {
buffer.push(`import { Schema as ET } from '@effect/schema/Schema'`)
buffer.push(`import { Schema as ES } from '@effect/schema'`)
buffer.push(``)
for (const reference of model.types) {
if (reference.$id) reference_map.set(reference.$id, reference);
}
for (const type of model.types.filter((type) => Types.TypeGuard.IsSchema(type))) {
buffer.push(GenerateType(model, type, model.types))
}
Expand Down
7 changes: 7 additions & 0 deletions src/model/model-to-io-ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,14 @@ export namespace ModelToIoTs {
}
function GenerateType(model: TypeBoxModel, schema: Types.TSchema, references: Types.TSchema[]) {
const output: string[] = []
/*
// removed for being n^m [see: Issue #56]
for (const reference of references) {
if (reference.$id === undefined) return UnsupportedType(schema)
reference_map.set(reference.$id, reference)
}
*/
if (!schema.$id || !reference_map.has(schema.$id)) return UnsupportedType(schema);
const type = Collect(schema)
if (recursive_set.has(schema.$id!)) {
output.push(`export ${ModelToTypeScript.GenerateType(model, schema.$id!)}`)
Expand All @@ -278,6 +282,9 @@ export namespace ModelToIoTs {
recursive_set.clear()
emitted_set.clear()
const buffer: string[] = [`import t from 'io-ts'`, '']
for (const reference of model.types) {
if (reference.$id) reference_map.set(reference.$id, reference);
}
const types = model.types.filter((type) => Types.TypeGuard.IsSchema(type)).map((type) => GenerateType(model, type, model.types))
buffer.push(...support_types.values())
buffer.push('\n')
Expand Down
7 changes: 7 additions & 0 deletions src/model/model-to-valibot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,14 @@ export namespace ModelToValibot {
}
function GenerateType(model: TypeBoxModel, schema: Types.TSchema, references: Types.TSchema[]) {
const output: string[] = []
/*
// removed for being n^m [see: Issue #56]
for (const reference of references) {
if (reference.$id === undefined) return UnsupportedType(schema)
reference_map.set(reference.$id, reference)
}
*/
if (!schema.$id || !reference_map.has(schema.$id)) return UnsupportedType(schema);
const type = Collect(schema)
if (recursive_set.has(schema.$id!)) {
output.push(`export ${ModelToTypeScript.GenerateType(model, schema.$id!)}`)
Expand All @@ -242,6 +246,9 @@ export namespace ModelToValibot {
recursive_set.clear()
emitted_set.clear()
const buffer: string[] = [`import * as v from 'valibot'`, '']
for (const reference of model.types) {
if (reference.$id) reference_map.set(reference.$id, reference);
}
for (const type of model.types.filter((type) => Types.TypeGuard.IsSchema(type))) {
buffer.push(GenerateType(model, type, model.types))
}
Expand Down
7 changes: 7 additions & 0 deletions src/model/model-to-yup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,14 @@ export namespace ModelToYup {
}
function GenerateType(model: TypeBoxModel, schema: Types.TSchema, references: Types.TSchema[]) {
const output: string[] = []
/*
// removed for being n^m [see: Issue #56]
for (const reference of references) {
if (reference.$id === undefined) return UnsupportedType(schema)
reference_map.set(reference.$id, reference)
}
*/
if (!schema.$id || !reference_map.has(schema.$id)) return UnsupportedType(schema);
const type = Collect(schema)
if (recursive_set.has(schema.$id!)) {
output.push(`export ${ModelToTypeScript.GenerateType(model, schema.$id!)}`)
Expand All @@ -220,6 +224,9 @@ export namespace ModelToYup {
recursive_set.clear()
emitted_set.clear()
const buffer: string[] = [`import y from 'yup'`, '']
for (const reference of model.types) {
if (reference.$id) reference_map.set(reference.$id, reference);
}
for (const type of model.types.filter((type) => Types.TypeGuard.IsSchema(type))) {
buffer.push(GenerateType(model, type, model.types))
}
Expand Down
7 changes: 7 additions & 0 deletions src/model/model-to-zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,14 @@ export namespace ModelToZod {
}
function GenerateType(model: TypeBoxModel, schema: Types.TSchema, references: Types.TSchema[]) {
const output: string[] = []
/*
// removed for being n^m [see: Issue #56]
for (const reference of references) {
if (reference.$id === undefined) return UnsupportedType(schema)
reference_map.set(reference.$id, reference)
}
*/
if (!schema.$id || !reference_map.has(schema.$id)) return UnsupportedType(schema);
const type = Collect(schema)
if (recursive_set.has(schema.$id!)) {
output.push(`export ${ModelToTypeScript.GenerateType(model, schema.$id!)}`)
Expand All @@ -240,6 +244,9 @@ export namespace ModelToZod {
recursive_set.clear()
emitted_set.clear()
const buffer: string[] = [`import { z } from 'zod'`, '']
for (const reference of model.types) {
if (reference.$id) reference_map.set(reference.$id, reference);
}
for (const type of model.types.filter((type) => Types.TypeGuard.IsSchema(type))) {
buffer.push(GenerateType(model, type, model.types))
}
Expand Down