Test case
1 generated file · +19 −1test/inputs/json/misc/00ec5.json
Mtypescript-effect-schemadefault / TopLevel.ts+19 −1
| @@ -1,5 +1,23 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export const Type = S.Literal( |
| 5 | 23 | "string", |
| @@ -56,7 +74,7 @@ export class Property extends S.Class<Property>("Property")({ | ||
| 56 | 74 | }) {} |
| 57 | 75 | |
| 58 | 76 | export class Provider extends S.Class<Provider>("Provider")({ |
| 59 | - "properties": S.Record({ key: S.String, value: Property}), | |
| 77 | + "properties": mapSchema(Property), | |
| 60 | 78 | }) {} |
| 61 | 79 | |
| 62 | 80 | export class Definitions extends S.Class<Definitions>("Definitions")({ |
Test case
1 generated file · +19 −1test/inputs/json/misc/033b1.json
Mtypescript-effect-schemadefault / TopLevel.ts+19 −1
| @@ -1,8 +1,26 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export class TopLevel extends S.Class<TopLevel>("TopLevel")({ |
| 5 | 23 | "base": S.String, |
| 6 | 24 | "date": S.String.pipe(S.pattern(/^\d{4}-\d{2}-\d{2}$/)), |
| 7 | - "rates": S.Record({ key: S.String, value: S.Number}), | |
| 25 | + "rates": mapSchema(S.Number), | |
| 8 | 26 | }) {} |
Test case
1 generated file · +19 −1test/inputs/json/misc/09f54.json
Mtypescript-effect-schemadefault / TopLevel.ts+19 −1
| @@ -1,5 +1,23 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export class Description extends S.Class<Description>("Description")({ |
| 5 | 23 | "base_period": S.String, |
| @@ -14,6 +32,6 @@ export class Datum extends S.Class<Datum>("Datum")({ | ||
| 14 | 32 | }) {} |
| 15 | 33 | |
| 16 | 34 | export class TopLevel extends S.Class<TopLevel>("TopLevel")({ |
| 17 | - "data": S.Record({ key: S.String, value: Datum}), | |
| 35 | + "data": mapSchema(Datum), | |
| 18 | 36 | "description": Description, |
| 19 | 37 | }) {} |
Test case
1 generated file · +19 −1test/inputs/json/misc/167d6.json
Mtypescript-effect-schemadefault / TopLevel.ts+19 −1
| @@ -1,8 +1,26 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export class TopLevel extends S.Class<TopLevel>("TopLevel")({ |
| 5 | 23 | "base": S.String, |
| 6 | 24 | "date": S.String.pipe(S.pattern(/^\d{4}-\d{2}-\d{2}$/)), |
| 7 | - "rates": S.Record({ key: S.String, value: S.Number}), | |
| 25 | + "rates": mapSchema(S.Number), | |
| 8 | 26 | }) {} |
Test case
1 generated file · +19 −1test/inputs/json/misc/43eaf.json
Mtypescript-effect-schemadefault / TopLevel.ts+19 −1
| @@ -1,8 +1,26 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export class TopLevel extends S.Class<TopLevel>("TopLevel")({ |
| 5 | 23 | "base": S.String, |
| 6 | 24 | "date": S.String.pipe(S.pattern(/^\d{4}-\d{2}-\d{2}$/)), |
| 7 | - "rates": S.Record({ key: S.String, value: S.Number}), | |
| 25 | + "rates": mapSchema(S.Number), | |
| 8 | 26 | }) {} |
Test case
1 generated file · +19 −1test/inputs/json/misc/5f3a1.json
Mtypescript-effect-schemadefault / TopLevel.ts+19 −1
| @@ -1,8 +1,26 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export class TopLevel extends S.Class<TopLevel>("TopLevel")({ |
| 5 | 23 | "base": S.String, |
| 6 | 24 | "date": S.String.pipe(S.pattern(/^\d{4}-\d{2}-\d{2}$/)), |
| 7 | - "rates": S.Record({ key: S.String, value: S.Number}), | |
| 25 | + "rates": mapSchema(S.Number), | |
| 8 | 26 | }) {} |
Test case
1 generated file · +19 −1test/inputs/json/misc/6260a.json
Mtypescript-effect-schemadefault / TopLevel.ts+19 −1
| @@ -1,8 +1,26 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export class TopLevel extends S.Class<TopLevel>("TopLevel")({ |
| 5 | 23 | "base": S.String, |
| 6 | 24 | "date": S.String.pipe(S.pattern(/^\d{4}-\d{2}-\d{2}$/)), |
| 7 | - "rates": S.Record({ key: S.String, value: S.Number}), | |
| 25 | + "rates": mapSchema(S.Number), | |
| 8 | 26 | }) {} |
Test case
1 generated file · +19 −1test/inputs/json/misc/70c77.json
Mtypescript-effect-schemadefault / TopLevel.ts+19 −1
| @@ -1,8 +1,26 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export class TopLevel extends S.Class<TopLevel>("TopLevel")({ |
| 5 | 23 | "base": S.String, |
| 6 | 24 | "date": S.String.pipe(S.pattern(/^\d{4}-\d{2}-\d{2}$/)), |
| 7 | - "rates": S.Record({ key: S.String, value: S.Number}), | |
| 25 | + "rates": mapSchema(S.Number), | |
| 8 | 26 | }) {} |
Test case
1 generated file · +19 −1test/inputs/json/misc/75912.json
Mtypescript-effect-schemadefault / TopLevel.ts+19 −1
| @@ -1,8 +1,26 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export class TopLevel extends S.Class<TopLevel>("TopLevel")({ |
| 5 | 23 | "base": S.String, |
| 6 | 24 | "date": S.String.pipe(S.pattern(/^\d{4}-\d{2}-\d{2}$/)), |
| 7 | - "rates": S.Record({ key: S.String, value: S.Number}), | |
| 25 | + "rates": mapSchema(S.Number), | |
| 8 | 26 | }) {} |
Test case
1 generated file · +19 −1test/inputs/json/misc/76ae1.json
Mtypescript-effect-schemadefault / TopLevel.ts+19 −1
| @@ -1,5 +1,23 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export const FormatEnum = S.Literal( |
| 5 | 23 | "string", |
| @@ -80,7 +98,7 @@ export class Property extends S.Class<Property>("Property")({ | ||
| 80 | 98 | }) {} |
| 81 | 99 | |
| 82 | 100 | export class Article extends S.Class<Article>("Article")({ |
| 83 | - "properties": S.Record({ key: S.String, value: Property}), | |
| 101 | + "properties": mapSchema(Property), | |
| 84 | 102 | }) {} |
| 85 | 103 | |
| 86 | 104 | export class Definitions extends S.Class<Definitions>("Definitions")({ |
Test case
1 generated file · +19 −1test/inputs/json/misc/7d397.json
Mtypescript-effect-schemadefault / TopLevel.ts+19 −1
| @@ -1,5 +1,23 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export const Type = S.Literal( |
| 5 | 23 | "string", |
| @@ -67,7 +85,7 @@ export class Property extends S.Class<Property>("Property")({ | ||
| 67 | 85 | }) {} |
| 68 | 86 | |
| 69 | 87 | export class List extends S.Class<List>("List")({ |
| 70 | - "properties": S.Record({ key: S.String, value: Property}), | |
| 88 | + "properties": mapSchema(Property), | |
| 71 | 89 | }) {} |
| 72 | 90 | |
| 73 | 91 | export class Definitions extends S.Class<Definitions>("Definitions")({ |
Test case
1 generated file · +19 −1test/inputs/json/misc/7f568.json
Mtypescript-effect-schemadefault / TopLevel.ts+19 −1
| @@ -1,5 +1,23 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export const Language = S.Literal( |
| 5 | 23 | "Markdown", |
| @@ -26,7 +44,7 @@ export class TopLevelElement extends S.Class<TopLevelElement>("TopLevelElement") | ||
| 26 | 44 | "commits_url": S.String, |
| 27 | 45 | "created_at": S.String.pipe(S.pattern(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/)), |
| 28 | 46 | "description": S.NullOr(S.String), |
| 29 | - "files": S.Record({ key: S.String, value: File}), | |
| 47 | + "files": mapSchema(File), | |
| 30 | 48 | "forks_url": S.String, |
| 31 | 49 | "git_pull_url": S.String, |
| 32 | 50 | "git_push_url": S.String, |
Test case
1 generated file · +19 −1test/inputs/json/misc/9617f.json
Mtypescript-effect-schemadefault / TopLevel.ts+19 −1
| @@ -1,8 +1,26 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export class TopLevel extends S.Class<TopLevel>("TopLevel")({ |
| 5 | 23 | "base": S.String, |
| 6 | 24 | "date": S.String.pipe(S.pattern(/^\d{4}-\d{2}-\d{2}$/)), |
| 7 | - "rates": S.Record({ key: S.String, value: S.Number}), | |
| 25 | + "rates": mapSchema(S.Number), | |
| 8 | 26 | }) {} |
Test case
1 generated file · +19 −1test/inputs/json/misc/a9691.json
Mtypescript-effect-schemadefault / TopLevel.ts+19 −1
| @@ -1,8 +1,26 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export class TopLevel extends S.Class<TopLevel>("TopLevel")({ |
| 5 | 23 | "base": S.String, |
| 6 | 24 | "date": S.String.pipe(S.pattern(/^\d{4}-\d{2}-\d{2}$/)), |
| 7 | - "rates": S.Record({ key: S.String, value: S.Number}), | |
| 25 | + "rates": mapSchema(S.Number), | |
| 8 | 26 | }) {} |
Test case
1 generated file · +19 −1test/inputs/json/misc/ac944.json
Mtypescript-effect-schemadefault / TopLevel.ts+19 −1
| @@ -1,8 +1,26 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export class TopLevel extends S.Class<TopLevel>("TopLevel")({ |
| 5 | 23 | "base": S.String, |
| 6 | 24 | "date": S.String.pipe(S.pattern(/^\d{4}-\d{2}-\d{2}$/)), |
| 7 | - "rates": S.Record({ key: S.String, value: S.Number}), | |
| 25 | + "rates": mapSchema(S.Number), | |
| 8 | 26 | }) {} |
Test case
1 generated file · +19 −1test/inputs/json/misc/c0356.json
Mtypescript-effect-schemadefault / TopLevel.ts+19 −1
| @@ -1,5 +1,23 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export class Description extends S.Class<Description>("Description")({ |
| 5 | 23 | "base_period": S.String, |
| @@ -13,6 +31,6 @@ export class Datum extends S.Class<Datum>("Datum")({ | ||
| 13 | 31 | }) {} |
| 14 | 32 | |
| 15 | 33 | export class TopLevel extends S.Class<TopLevel>("TopLevel")({ |
| 16 | - "data": S.Record({ key: S.String, value: Datum}), | |
| 34 | + "data": mapSchema(Datum), | |
| 17 | 35 | "description": Description, |
| 18 | 36 | }) {} |
Test case
1 generated file · +19 −1test/inputs/json/misc/cb81e.json
Mtypescript-effect-schemadefault / TopLevel.ts+19 −1
| @@ -1,5 +1,23 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export class Description extends S.Class<Description>("Description")({ |
| 5 | 23 | "base_period": S.String, |
| @@ -9,6 +27,6 @@ export class Description extends S.Class<Description>("Description")({ | ||
| 9 | 27 | }) {} |
| 10 | 28 | |
| 11 | 29 | export class TopLevel extends S.Class<TopLevel>("TopLevel")({ |
| 12 | - "data": S.Record({ key: S.String, value: S.String}), | |
| 30 | + "data": mapSchema(S.String), | |
| 13 | 31 | "description": Description, |
| 14 | 32 | }) {} |
Test case
1 generated file · +19 −1test/inputs/json/misc/cd463.json
Mtypescript-effect-schemadefault / TopLevel.ts+19 −1
| @@ -1,8 +1,26 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export class TopLevel extends S.Class<TopLevel>("TopLevel")({ |
| 5 | 23 | "base": S.String, |
| 6 | 24 | "date": S.String.pipe(S.pattern(/^\d{4}-\d{2}-\d{2}$/)), |
| 7 | - "rates": S.Record({ key: S.String, value: S.Number}), | |
| 25 | + "rates": mapSchema(S.Number), | |
| 8 | 26 | }) {} |
Test case
1 generated file · +19 −1test/inputs/json/misc/cfbce.json
Mtypescript-effect-schemadefault / TopLevel.ts+19 −1
| @@ -1,8 +1,26 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export class TopLevel extends S.Class<TopLevel>("TopLevel")({ |
| 5 | 23 | "base": S.String, |
| 6 | 24 | "date": S.String.pipe(S.pattern(/^\d{4}-\d{2}-\d{2}$/)), |
| 7 | - "rates": S.Record({ key: S.String, value: S.Number}), | |
| 25 | + "rates": mapSchema(S.Number), | |
| 8 | 26 | }) {} |
Test case
1 generated file · +19 −1test/inputs/json/misc/e324e.json
Mtypescript-effect-schemadefault / TopLevel.ts+19 −1
| @@ -1,5 +1,23 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export const Type = S.Literal( |
| 5 | 23 | "string", |
| @@ -61,7 +79,7 @@ export class Property extends S.Class<Property>("Property")({ | ||
| 61 | 79 | }) {} |
| 62 | 80 | |
| 63 | 81 | export class Rate extends S.Class<Rate>("Rate")({ |
| 64 | - "properties": S.Record({ key: S.String, value: Property}), | |
| 82 | + "properties": mapSchema(Property), | |
| 65 | 83 | }) {} |
| 66 | 84 | |
| 67 | 85 | export class Definitions extends S.Class<Definitions>("Definitions")({ |
Test case
1 generated file · +19 −1test/inputs/json/misc/ed095.json
Mtypescript-effect-schemadefault / TopLevel.ts+19 −1
| @@ -1,4 +1,22 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | -export const TopLevel = S.Record({ key: S.String, value: S.String}); | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 21 | +export const TopLevel = mapSchema(S.String); | |
| 4 | 22 | export type TopLevel = S.Schema.Type<typeof TopLevel>; |
Test case
1 generated file · +19 −1test/inputs/json/misc/fd329.json
Mtypescript-effect-schemadefault / TopLevel.ts+19 −1
| @@ -1,5 +1,23 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export class Description extends S.Class<Description>("Description")({ |
| 5 | 23 | "base_period": S.String, |
| @@ -14,6 +32,6 @@ export class Datum extends S.Class<Datum>("Datum")({ | ||
| 14 | 32 | }) {} |
| 15 | 33 | |
| 16 | 34 | export class TopLevel extends S.Class<TopLevel>("TopLevel")({ |
| 17 | - "data": S.Record({ key: S.String, value: Datum}), | |
| 35 | + "data": mapSchema(Datum), | |
| 18 | 36 | "description": Description, |
| 19 | 37 | }) {} |
Test case
1 generated file · +21 −3test/inputs/json/priority/bug2037.json
Mtypescript-effect-schemadefault / TopLevel.ts+21 −3
| @@ -1,17 +1,35 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export class Reward extends S.Class<Reward>("Reward")(S.Struct({}).pipe(S.filter(value => typeof value === "object" && value !== null && !Array.isArray(value))) |
| 5 | 23 | ) {} |
| 6 | 24 | |
| 7 | 25 | export class Objective extends S.Class<Objective>("Objective")({ |
| 8 | - "rewards": S.Record({ key: S.String, value: Reward}), | |
| 26 | + "rewards": mapSchema(Reward), | |
| 9 | 27 | }) {} |
| 10 | 28 | |
| 11 | 29 | export class MissionSpec extends S.Class<MissionSpec>("MissionSpec")({ |
| 12 | - "objectives": S.Record({ key: S.String, value: Objective}), | |
| 30 | + "objectives": mapSchema(Objective), | |
| 13 | 31 | }) {} |
| 14 | 32 | |
| 15 | 33 | export class TopLevel extends S.Class<TopLevel>("TopLevel")({ |
| 16 | - "mission_specs": S.Record({ key: S.String, value: MissionSpec}), | |
| 34 | + "mission_specs": mapSchema(MissionSpec), | |
| 17 | 35 | }) {} |
Test case
1 generated file · +19 −1test/inputs/json/priority/bug855-short.json
Mtypescript-effect-schemadefault / TopLevel.ts+19 −1
| @@ -1,5 +1,23 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export class TopLevelValue extends S.Class<TopLevelValue>("TopLevelValue")({ |
| 5 | 23 | "channel_id": S.String.pipe(S.pattern(/^-?\d+$/)), |
| @@ -9,5 +27,5 @@ export class TopLevelValue extends S.Class<TopLevelValue>("TopLevelValue")({ | ||
| 9 | 27 | "id": S.Int, |
| 10 | 28 | }) {} |
| 11 | 29 | |
| 12 | -export const TopLevel = S.Record({ key: S.String, value: TopLevelValue}); | |
| 30 | +export const TopLevel = mapSchema(TopLevelValue); | |
| 13 | 31 | export type TopLevel = S.Schema.Type<typeof TopLevel>; |
Test case
1 generated file · +19 −1test/inputs/json/priority/coin-pairs.json
Mtypescript-effect-schemadefault / TopLevel.ts+19 −1
| @@ -1,5 +1,23 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export class Pair extends S.Class<Pair>("Pair")({ |
| 5 | 23 | "decimal_places": S.Int, |
| @@ -13,6 +31,6 @@ export class Pair extends S.Class<Pair>("Pair")({ | ||
| 13 | 31 | }) {} |
| 14 | 32 | |
| 15 | 33 | export class TopLevel extends S.Class<TopLevel>("TopLevel")({ |
| 16 | - "pairs": S.Record({ key: S.String, value: Pair}), | |
| 34 | + "pairs": mapSchema(Pair), | |
| 17 | 35 | "server_time": S.Int, |
| 18 | 36 | }) {} |
Test case
2 generated files · +54 −18test/inputs/json/priority/combinations1.json
Mtypescript-effect-schemadefault / TopLevel.ts+27 −9
| @@ -1,5 +1,23 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export class Interacinar extends S.Class<Interacinar>("Interacinar")({ |
| 5 | 23 | "assapan": S.Number, |
| @@ -293,18 +311,18 @@ export class TopLevel extends S.Class<TopLevel>("TopLevel")({ | ||
| 293 | 311 | "citrated": S.Int, |
| 294 | 312 | "clinodome": S.Array(S.Union(S.Number, S.String)), |
| 295 | 313 | "coadjust": S.Array(S.Union(S.Number, CoadjustClass)), |
| 296 | - "consilience": S.Array(S.Union(S.Number, S.Record({ key: S.String, value: S.Int}))), | |
| 297 | - "constructor": S.Array(S.Union(S.Boolean, S.Record({ key: S.String, value: S.NullOr(S.Int)}))), | |
| 298 | - "continuative": S.Array(S.Union(S.Record({ key: S.String, value: S.Int}), S.String)), | |
| 314 | + "consilience": S.Array(S.Union(S.Number, mapSchema(S.Int))), | |
| 315 | + "constructor": S.Array(S.Union(S.Boolean, mapSchema(S.NullOr(S.Int)))), | |
| 316 | + "continuative": S.Array(S.Union(mapSchema(S.Int), S.String)), | |
| 299 | 317 | "credulity": S.Array(S.Union(S.Int, S.String, CredulityClass)), |
| 300 | - "creviced": S.Array(S.Union(S.Boolean, S.Record({ key: S.String, value: S.Int}), S.String)), | |
| 318 | + "creviced": S.Array(S.Union(S.Boolean, mapSchema(S.Int), S.String)), | |
| 301 | 319 | "cubiculum": S.Array(S.Array(S.NullOr(S.Int))), |
| 302 | 320 | "deruralize": S.Array(S.Union(S.Array(S.Null), S.Boolean, DeruralizeClass)), |
| 303 | 321 | "diaereses": S.Array(S.Union(S.Array(S.Int), S.Boolean, DiaereseClass)), |
| 304 | 322 | "dissolution": S.Array(S.NullOr(S.Array(S.Null))), |
| 305 | 323 | "downstroke": S.Array(S.Union(S.Array(S.Null), S.Boolean, S.String)), |
| 306 | 324 | "electrotautomerism": S.Array(S.NullOr(S.Number)), |
| 307 | - "eleutheromania": S.Array(S.Union(S.Number, S.Record({ key: S.String, value: S.Int}), S.String)), | |
| 325 | + "eleutheromania": S.Array(S.Union(S.Number, mapSchema(S.Int), S.String)), | |
| 308 | 326 | "encrust": Encrust, |
| 309 | 327 | "entomoid": S.Array(S.Union(S.Int, CimeliaClass)), |
| 310 | 328 | "epipaleolithic": S.Array(S.Union(S.Array(S.Int), S.Number)), |
| @@ -314,10 +332,10 @@ export class TopLevel extends S.Class<TopLevel>("TopLevel")({ | ||
| 314 | 332 | "flagmaking": S.Array(S.Union(S.Boolean, S.Number, FlagmakingClass)), |
| 315 | 333 | "fluorometer": S.Array(S.Union(S.Int, S.String, S.Null)), |
| 316 | 334 | "fulsome": S.Array(S.NullOr(S.Int)), |
| 317 | - "fuzzy": S.Array(S.Union(S.Int, S.Record({ key: S.String, value: S.NullOr(S.Int)}))), | |
| 335 | + "fuzzy": S.Array(S.Union(S.Int, mapSchema(S.NullOr(S.Int)))), | |
| 318 | 336 | "gardenwards": S.Array(S.Union(S.Array(S.Int), S.Boolean, S.String)), |
| 319 | - "generalissimo": S.Array(S.Union(S.Boolean, S.Record({ key: S.String, value: S.Int}), S.Null)), | |
| 320 | - "habeas": S.Array(S.NullOr(S.Record({ key: S.String, value: S.Int}))), | |
| 337 | + "generalissimo": S.Array(S.Union(S.Boolean, mapSchema(S.Int), S.Null)), | |
| 338 | + "habeas": S.Array(S.NullOr(mapSchema(S.Int))), | |
| 321 | 339 | "hemicrystalline": S.Array(S.Union(S.String, CimeliaClass)), |
| 322 | 340 | "hemocoele": S.Array(S.Union(S.Array(S.Int), HemocoeleClass)), |
| 323 | 341 | "hoister": S.Array(S.Union(S.String, CimeliaClass, S.Null)), |
| @@ -328,5 +346,5 @@ export class TopLevel extends S.Class<TopLevel>("TopLevel")({ | ||
| 328 | 346 | "intentiveness": S.Array(S.Union(S.Number, S.String, CimeliaClass)), |
| 329 | 347 | "interacinar": Interacinar, |
| 330 | 348 | "intercorrelation": S.Array(S.NullOr(S.Array(S.Int))), |
| 331 | - "jacutinga": S.Array(S.Union(S.Array(S.Int), S.Record({ key: S.String, value: S.NullOr(S.Int)}))), | |
| 349 | + "jacutinga": S.Array(S.Union(S.Array(S.Int), mapSchema(S.NullOr(S.Int)))), | |
| 332 | 350 | }) {} |
Mtypescript-effect-schemajust-schema-true--8c4ca457bcba / TopLevel.ts+27 −9
| @@ -1,5 +1,23 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export class Interacinar extends S.Class<Interacinar>("Interacinar")({ |
| 5 | 23 | "assapan": S.Number, |
| @@ -293,18 +311,18 @@ export class TopLevel extends S.Class<TopLevel>("TopLevel")({ | ||
| 293 | 311 | "citrated": S.Int, |
| 294 | 312 | "clinodome": S.Array(S.Union(S.Number, S.String)), |
| 295 | 313 | "coadjust": S.Array(S.Union(S.Number, CoadjustClass)), |
| 296 | - "consilience": S.Array(S.Union(S.Number, S.Record({ key: S.String, value: S.Int}))), | |
| 297 | - "constructor": S.Array(S.Union(S.Boolean, S.Record({ key: S.String, value: S.NullOr(S.Int)}))), | |
| 298 | - "continuative": S.Array(S.Union(S.Record({ key: S.String, value: S.Int}), S.String)), | |
| 314 | + "consilience": S.Array(S.Union(S.Number, mapSchema(S.Int))), | |
| 315 | + "constructor": S.Array(S.Union(S.Boolean, mapSchema(S.NullOr(S.Int)))), | |
| 316 | + "continuative": S.Array(S.Union(mapSchema(S.Int), S.String)), | |
| 299 | 317 | "credulity": S.Array(S.Union(S.Int, S.String, CredulityClass)), |
| 300 | - "creviced": S.Array(S.Union(S.Boolean, S.Record({ key: S.String, value: S.Int}), S.String)), | |
| 318 | + "creviced": S.Array(S.Union(S.Boolean, mapSchema(S.Int), S.String)), | |
| 301 | 319 | "cubiculum": S.Array(S.Array(S.NullOr(S.Int))), |
| 302 | 320 | "deruralize": S.Array(S.Union(S.Array(S.Null), S.Boolean, DeruralizeClass)), |
| 303 | 321 | "diaereses": S.Array(S.Union(S.Array(S.Int), S.Boolean, DiaereseClass)), |
| 304 | 322 | "dissolution": S.Array(S.NullOr(S.Array(S.Null))), |
| 305 | 323 | "downstroke": S.Array(S.Union(S.Array(S.Null), S.Boolean, S.String)), |
| 306 | 324 | "electrotautomerism": S.Array(S.NullOr(S.Number)), |
| 307 | - "eleutheromania": S.Array(S.Union(S.Number, S.Record({ key: S.String, value: S.Int}), S.String)), | |
| 325 | + "eleutheromania": S.Array(S.Union(S.Number, mapSchema(S.Int), S.String)), | |
| 308 | 326 | "encrust": Encrust, |
| 309 | 327 | "entomoid": S.Array(S.Union(S.Int, CimeliaClass)), |
| 310 | 328 | "epipaleolithic": S.Array(S.Union(S.Array(S.Int), S.Number)), |
| @@ -314,10 +332,10 @@ export class TopLevel extends S.Class<TopLevel>("TopLevel")({ | ||
| 314 | 332 | "flagmaking": S.Array(S.Union(S.Boolean, S.Number, FlagmakingClass)), |
| 315 | 333 | "fluorometer": S.Array(S.Union(S.Int, S.String, S.Null)), |
| 316 | 334 | "fulsome": S.Array(S.NullOr(S.Int)), |
| 317 | - "fuzzy": S.Array(S.Union(S.Int, S.Record({ key: S.String, value: S.NullOr(S.Int)}))), | |
| 335 | + "fuzzy": S.Array(S.Union(S.Int, mapSchema(S.NullOr(S.Int)))), | |
| 318 | 336 | "gardenwards": S.Array(S.Union(S.Array(S.Int), S.Boolean, S.String)), |
| 319 | - "generalissimo": S.Array(S.Union(S.Boolean, S.Record({ key: S.String, value: S.Int}), S.Null)), | |
| 320 | - "habeas": S.Array(S.NullOr(S.Record({ key: S.String, value: S.Int}))), | |
| 337 | + "generalissimo": S.Array(S.Union(S.Boolean, mapSchema(S.Int), S.Null)), | |
| 338 | + "habeas": S.Array(S.NullOr(mapSchema(S.Int))), | |
| 321 | 339 | "hemicrystalline": S.Array(S.Union(S.String, CimeliaClass)), |
| 322 | 340 | "hemocoele": S.Array(S.Union(S.Array(S.Int), HemocoeleClass)), |
| 323 | 341 | "hoister": S.Array(S.Union(S.String, CimeliaClass, S.Null)), |
| @@ -328,5 +346,5 @@ export class TopLevel extends S.Class<TopLevel>("TopLevel")({ | ||
| 328 | 346 | "intentiveness": S.Array(S.Union(S.Number, S.String, CimeliaClass)), |
| 329 | 347 | "interacinar": Interacinar, |
| 330 | 348 | "intercorrelation": S.Array(S.NullOr(S.Array(S.Int))), |
| 331 | - "jacutinga": S.Array(S.Union(S.Array(S.Int), S.Record({ key: S.String, value: S.NullOr(S.Int)}))), | |
| 349 | + "jacutinga": S.Array(S.Union(S.Array(S.Int), mapSchema(S.NullOr(S.Int)))), | |
| 332 | 350 | }) {} |
Test case
2 generated files · +60 −24test/inputs/json/priority/combinations2.json
Mtypescript-effect-schemadefault / TopLevel.ts+30 −12
| @@ -1,5 +1,23 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export class OskarClass extends S.Class<OskarClass>("OskarClass")({ |
| 5 | 23 | "Acrobates": S.Null, |
| @@ -233,8 +251,8 @@ export class AlleviateClass extends S.Class<AlleviateClass>("AlleviateClass")({ | ||
| 233 | 251 | |
| 234 | 252 | export class TopLevel extends S.Class<TopLevel>("TopLevel")({ |
| 235 | 253 | "Abranchiata": S.Array(S.Union(S.Array(S.Int), S.Int, S.Null)), |
| 236 | - "academe": S.Array(S.Union(S.Array(S.Int), S.Int, S.Record({ key: S.String, value: S.Int}))), | |
| 237 | - "acquirable": S.Array(S.Union(S.Array(S.NullOr(S.Int)), S.Record({ key: S.String, value: S.Int}))), | |
| 254 | + "academe": S.Array(S.Union(S.Array(S.Int), S.Int, mapSchema(S.Int))), | |
| 255 | + "acquirable": S.Array(S.Union(S.Array(S.NullOr(S.Int)), mapSchema(S.Int))), | |
| 238 | 256 | "aerometry": S.Array(S.Union(S.Boolean, S.Number)), |
| 239 | 257 | "alexin": S.Array(S.Union(S.Array(S.Int), S.Boolean)), |
| 240 | 258 | "alleviate": S.Array(S.Union(S.Array(S.NullOr(S.Int)), AlleviateClass)), |
| @@ -243,38 +261,38 @@ export class TopLevel extends S.Class<TopLevel>("TopLevel")({ | ||
| 243 | 261 | "amphithyron": S.Array(S.NullOr(Amphithyron)), |
| 244 | 262 | "Andriana": S.Array(S.NullOr(S.String)), |
| 245 | 263 | "ankee": S.Array(S.Union(S.Array(S.Int), S.Int, AnkeeClass)), |
| 246 | - "annihilator": S.Array(S.NullOr(S.Record({ key: S.String, value: S.NullOr(S.Int)}))), | |
| 264 | + "annihilator": S.Array(S.NullOr(mapSchema(S.NullOr(S.Int)))), | |
| 247 | 265 | "annulose": S.Null, |
| 248 | 266 | "Ansarie": S.Array(S.Union(S.Array(S.Int), AnsarieClass, S.Null)), |
| 249 | 267 | "aphasia": S.Array(S.Union(S.Array(S.Int), S.Int)), |
| 250 | 268 | "asprawl": S.Array(S.Union(S.Number, S.String)), |
| 251 | 269 | "attractive": S.Array(S.NullOr(S.Boolean)), |
| 252 | - "barksome": S.Record({ key: S.String, value: S.Int}), | |
| 270 | + "barksome": mapSchema(S.Int), | |
| 253 | 271 | "bedesman": S.Array(S.Union(S.Boolean, S.Number, S.String)), |
| 254 | 272 | "belard": S.Array(S.Union(S.Array(S.Int), S.Number, Rebecca)), |
| 255 | - "bocking": S.Array(S.Union(S.Array(S.Int), S.Boolean, S.Record({ key: S.String, value: S.Int}))), | |
| 256 | - "brawlingly": S.Array(S.Union(S.Array(S.Null), S.Record({ key: S.String, value: S.NullOr(S.Int)}))), | |
| 273 | + "bocking": S.Array(S.Union(S.Array(S.Int), S.Boolean, mapSchema(S.Int))), | |
| 274 | + "brawlingly": S.Array(S.Union(S.Array(S.Null), mapSchema(S.NullOr(S.Int)))), | |
| 257 | 275 | "brookie": S.Array(S.Union(S.Array(S.Int), Rebecca)), |
| 258 | 276 | "bumboatman": S.Array(S.Union(S.Array(S.Null), S.String, S.Null)), |
| 259 | 277 | "bystreet": S.Array(S.Null), |
| 260 | 278 | "calaverite": S.Array(S.Union(S.Array(S.Int), S.String)), |
| 261 | - "catallactic": S.Array(S.Union(S.Array(S.Null), S.Boolean, S.Record({ key: S.String, value: S.Int}))), | |
| 262 | - "cemental": S.Array(S.Union(S.Array(S.Int), S.Number, S.Record({ key: S.String, value: S.Int}))), | |
| 279 | + "catallactic": S.Array(S.Union(S.Array(S.Null), S.Boolean, mapSchema(S.Int))), | |
| 280 | + "cemental": S.Array(S.Union(S.Array(S.Int), S.Number, mapSchema(S.Int))), | |
| 263 | 281 | "Chytridiaceae": S.Array(S.Union(S.Boolean, ChytridiaceaeClass, S.Null)), |
| 264 | 282 | "Discordia": S.Array(S.Union(S.Array(S.Int), DiscordiaClass)), |
| 265 | 283 | "Endomyces": S.Array(S.Union(S.Int, S.String)), |
| 266 | 284 | "Epinephelidae": S.Array(S.Union(S.Boolean, S.Int, S.String)), |
| 267 | - "Eupatorium": S.Array(S.Union(S.Array(S.Null), S.Record({ key: S.String, value: S.Int}))), | |
| 285 | + "Eupatorium": S.Array(S.Union(S.Array(S.Null), mapSchema(S.Int))), | |
| 268 | 286 | "Gryphosaurus": S.Array(S.Union(S.Array(S.Int), S.String, GryphosaurusClass)), |
| 269 | - "Koryak": S.Array(S.Union(S.Record({ key: S.String, value: S.NullOr(S.Int)}), S.String)), | |
| 287 | + "Koryak": S.Array(S.Union(mapSchema(S.NullOr(S.Int)), S.String)), | |
| 270 | 288 | "Lavinia": S.Array(S.Union(S.String, LaviniaClass)), |
| 271 | 289 | "Oskar": S.Array(S.Union(S.Array(S.Int), OskarClass)), |
| 272 | 290 | "Rebecca": S.Array(S.Union(S.Int, S.String, Rebecca)), |
| 273 | 291 | "Rhomboganoidei": S.Array(S.Union(S.Array(S.Int), S.String, Rebecca)), |
| 274 | 292 | "Rigsmal": S.Boolean, |
| 275 | 293 | "Ruellia": S.Array(S.Union(S.Boolean, S.String, Rebecca)), |
| 276 | - "School": S.Array(S.Union(S.Int, S.Record({ key: S.String, value: S.Int}), S.Null)), | |
| 294 | + "School": S.Array(S.Union(S.Int, mapSchema(S.Int), S.Null)), | |
| 277 | 295 | "Shakespearolater": S.Array(S.Union(S.Array(S.Int), S.Number, S.String)), |
| 278 | 296 | "Svan": S.Array(S.Number), |
| 279 | - "Wayao": S.Record({ key: S.String, value: S.Number}), | |
| 297 | + "Wayao": mapSchema(S.Number), | |
| 280 | 298 | }) {} |
Mtypescript-effect-schemajust-schema-true--8c4ca457bcba / TopLevel.ts+30 −12
| @@ -1,5 +1,23 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export class OskarClass extends S.Class<OskarClass>("OskarClass")({ |
| 5 | 23 | "Acrobates": S.Null, |
| @@ -233,8 +251,8 @@ export class AlleviateClass extends S.Class<AlleviateClass>("AlleviateClass")({ | ||
| 233 | 251 | |
| 234 | 252 | export class TopLevel extends S.Class<TopLevel>("TopLevel")({ |
| 235 | 253 | "Abranchiata": S.Array(S.Union(S.Array(S.Int), S.Int, S.Null)), |
| 236 | - "academe": S.Array(S.Union(S.Array(S.Int), S.Int, S.Record({ key: S.String, value: S.Int}))), | |
| 237 | - "acquirable": S.Array(S.Union(S.Array(S.NullOr(S.Int)), S.Record({ key: S.String, value: S.Int}))), | |
| 254 | + "academe": S.Array(S.Union(S.Array(S.Int), S.Int, mapSchema(S.Int))), | |
| 255 | + "acquirable": S.Array(S.Union(S.Array(S.NullOr(S.Int)), mapSchema(S.Int))), | |
| 238 | 256 | "aerometry": S.Array(S.Union(S.Boolean, S.Number)), |
| 239 | 257 | "alexin": S.Array(S.Union(S.Array(S.Int), S.Boolean)), |
| 240 | 258 | "alleviate": S.Array(S.Union(S.Array(S.NullOr(S.Int)), AlleviateClass)), |
| @@ -243,38 +261,38 @@ export class TopLevel extends S.Class<TopLevel>("TopLevel")({ | ||
| 243 | 261 | "amphithyron": S.Array(S.NullOr(Amphithyron)), |
| 244 | 262 | "Andriana": S.Array(S.NullOr(S.String)), |
| 245 | 263 | "ankee": S.Array(S.Union(S.Array(S.Int), S.Int, AnkeeClass)), |
| 246 | - "annihilator": S.Array(S.NullOr(S.Record({ key: S.String, value: S.NullOr(S.Int)}))), | |
| 264 | + "annihilator": S.Array(S.NullOr(mapSchema(S.NullOr(S.Int)))), | |
| 247 | 265 | "annulose": S.Null, |
| 248 | 266 | "Ansarie": S.Array(S.Union(S.Array(S.Int), AnsarieClass, S.Null)), |
| 249 | 267 | "aphasia": S.Array(S.Union(S.Array(S.Int), S.Int)), |
| 250 | 268 | "asprawl": S.Array(S.Union(S.Number, S.String)), |
| 251 | 269 | "attractive": S.Array(S.NullOr(S.Boolean)), |
| 252 | - "barksome": S.Record({ key: S.String, value: S.Int}), | |
| 270 | + "barksome": mapSchema(S.Int), | |
| 253 | 271 | "bedesman": S.Array(S.Union(S.Boolean, S.Number, S.String)), |
| 254 | 272 | "belard": S.Array(S.Union(S.Array(S.Int), S.Number, Rebecca)), |
| 255 | - "bocking": S.Array(S.Union(S.Array(S.Int), S.Boolean, S.Record({ key: S.String, value: S.Int}))), | |
| 256 | - "brawlingly": S.Array(S.Union(S.Array(S.Null), S.Record({ key: S.String, value: S.NullOr(S.Int)}))), | |
| 273 | + "bocking": S.Array(S.Union(S.Array(S.Int), S.Boolean, mapSchema(S.Int))), | |
| 274 | + "brawlingly": S.Array(S.Union(S.Array(S.Null), mapSchema(S.NullOr(S.Int)))), | |
| 257 | 275 | "brookie": S.Array(S.Union(S.Array(S.Int), Rebecca)), |
| 258 | 276 | "bumboatman": S.Array(S.Union(S.Array(S.Null), S.String, S.Null)), |
| 259 | 277 | "bystreet": S.Array(S.Null), |
| 260 | 278 | "calaverite": S.Array(S.Union(S.Array(S.Int), S.String)), |
| 261 | - "catallactic": S.Array(S.Union(S.Array(S.Null), S.Boolean, S.Record({ key: S.String, value: S.Int}))), | |
| 262 | - "cemental": S.Array(S.Union(S.Array(S.Int), S.Number, S.Record({ key: S.String, value: S.Int}))), | |
| 279 | + "catallactic": S.Array(S.Union(S.Array(S.Null), S.Boolean, mapSchema(S.Int))), | |
| 280 | + "cemental": S.Array(S.Union(S.Array(S.Int), S.Number, mapSchema(S.Int))), | |
| 263 | 281 | "Chytridiaceae": S.Array(S.Union(S.Boolean, ChytridiaceaeClass, S.Null)), |
| 264 | 282 | "Discordia": S.Array(S.Union(S.Array(S.Int), DiscordiaClass)), |
| 265 | 283 | "Endomyces": S.Array(S.Union(S.Int, S.String)), |
| 266 | 284 | "Epinephelidae": S.Array(S.Union(S.Boolean, S.Int, S.String)), |
| 267 | - "Eupatorium": S.Array(S.Union(S.Array(S.Null), S.Record({ key: S.String, value: S.Int}))), | |
| 285 | + "Eupatorium": S.Array(S.Union(S.Array(S.Null), mapSchema(S.Int))), | |
| 268 | 286 | "Gryphosaurus": S.Array(S.Union(S.Array(S.Int), S.String, GryphosaurusClass)), |
| 269 | - "Koryak": S.Array(S.Union(S.Record({ key: S.String, value: S.NullOr(S.Int)}), S.String)), | |
| 287 | + "Koryak": S.Array(S.Union(mapSchema(S.NullOr(S.Int)), S.String)), | |
| 270 | 288 | "Lavinia": S.Array(S.Union(S.String, LaviniaClass)), |
| 271 | 289 | "Oskar": S.Array(S.Union(S.Array(S.Int), OskarClass)), |
| 272 | 290 | "Rebecca": S.Array(S.Union(S.Int, S.String, Rebecca)), |
| 273 | 291 | "Rhomboganoidei": S.Array(S.Union(S.Array(S.Int), S.String, Rebecca)), |
| 274 | 292 | "Rigsmal": S.Boolean, |
| 275 | 293 | "Ruellia": S.Array(S.Union(S.Boolean, S.String, Rebecca)), |
| 276 | - "School": S.Array(S.Union(S.Int, S.Record({ key: S.String, value: S.Int}), S.Null)), | |
| 294 | + "School": S.Array(S.Union(S.Int, mapSchema(S.Int), S.Null)), | |
| 277 | 295 | "Shakespearolater": S.Array(S.Union(S.Array(S.Int), S.Number, S.String)), |
| 278 | 296 | "Svan": S.Array(S.Number), |
| 279 | - "Wayao": S.Record({ key: S.String, value: S.Number}), | |
| 297 | + "Wayao": mapSchema(S.Number), | |
| 280 | 298 | }) {} |
Test case
2 generated files · +50 −14test/inputs/json/priority/combinations3.json
Mtypescript-effect-schemadefault / TopLevel.ts+25 −7
| @@ -1,5 +1,23 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export class PrefreshmanClass extends S.Class<PrefreshmanClass>("PrefreshmanClass")({ |
| 5 | 23 | "azorubine": S.Null, |
| @@ -340,7 +358,7 @@ export class JurorClass extends S.Class<JurorClass>("JurorClass")({ | ||
| 340 | 358 | |
| 341 | 359 | export class TopLevel extends S.Class<TopLevel>("TopLevel")({ |
| 342 | 360 | "juror": S.Array(S.Union(S.Boolean, JurorClass)), |
| 343 | - "kongoni": S.Array(S.Union(S.Array(S.Int), S.Record({ key: S.String, value: S.Int}))), | |
| 361 | + "kongoni": S.Array(S.Union(S.Array(S.Int), mapSchema(S.Int))), | |
| 344 | 362 | "ladronism": S.Array(S.Union(S.Number, S.String, LadronismClass)), |
| 345 | 363 | "landlubberly": S.Array(S.Union(S.Boolean, S.Int, LandlubberlyClass)), |
| 346 | 364 | "listener": S.Array(S.Union(S.Array(S.Null), S.Int)), |
| @@ -361,24 +379,24 @@ export class TopLevel extends S.Class<TopLevel>("TopLevel")({ | ||
| 361 | 379 | "nonvaluation": S.Array(S.Union(S.Array(S.Null), S.Boolean, S.Number)), |
| 362 | 380 | "occupationalist": S.Array(S.Union(S.Array(S.Null), OccupationalistClass, S.Null)), |
| 363 | 381 | "outrival": S.Array(S.Union(S.Number, OutrivalClass, S.Null)), |
| 364 | - "paleographically": S.Array(S.Union(S.Number, S.Record({ key: S.String, value: S.NullOr(S.Int)}))), | |
| 365 | - "pamphletwise": S.Array(S.Union(S.Int, S.Record({ key: S.String, value: S.Int}), S.String)), | |
| 382 | + "paleographically": S.Array(S.Union(S.Number, mapSchema(S.NullOr(S.Int)))), | |
| 383 | + "pamphletwise": S.Array(S.Union(S.Int, mapSchema(S.Int), S.String)), | |
| 366 | 384 | "pediatrics": S.Array(S.Union(S.Boolean, S.Number, S.Null)), |
| 367 | 385 | "perceptive": S.Array(S.Boolean), |
| 368 | 386 | "piaculum": S.Array(S.Union(S.Number, PiaculumClass)), |
| 369 | 387 | "piccadilly": S.Array(S.Union(S.Number, S.String, S.Null)), |
| 370 | 388 | "piffler": S.Array(S.Union(S.Array(S.Null), MonaziteClass)), |
| 371 | 389 | "pithful": S.Array(S.Union(S.Boolean, S.Int, S.Null)), |
| 372 | - "placuntitis": S.Array(S.Union(S.Int, S.Record({ key: S.String, value: S.Int}))), | |
| 373 | - "plectopterous": S.Array(S.Union(S.Number, S.Record({ key: S.String, value: S.Int}))), | |
| 390 | + "placuntitis": S.Array(S.Union(S.Int, mapSchema(S.Int))), | |
| 391 | + "plectopterous": S.Array(S.Union(S.Number, mapSchema(S.Int))), | |
| 374 | 392 | "pneumocele": S.Array(S.NullOr(Pneumocele)), |
| 375 | 393 | "poliorcetic": S.Array(S.Union(S.Boolean, MonaziteClass)), |
| 376 | - "poormaster": S.Array(S.Union(S.Array(S.Int), S.Record({ key: S.String, value: S.Int}), S.Null)), | |
| 394 | + "poormaster": S.Array(S.Union(S.Array(S.Int), mapSchema(S.Int), S.Null)), | |
| 377 | 395 | "potwhisky": S.Array(S.Union(S.Int, PotwhiskyClass, S.Null)), |
| 378 | 396 | "practicalizer": S.Array(S.Union(S.Array(S.Null), S.String, MonaziteClass)), |
| 379 | 397 | "prefreshman": S.Array(S.Union(S.Array(S.Null), S.String, PrefreshmanClass)), |
| 380 | 398 | "prehensility": S.Array(S.Union(S.Array(S.Null), S.Boolean, MonaziteClass)), |
| 381 | 399 | "prevoidance": S.Array(S.Union(S.Array(S.Int), S.Int, MonaziteClass)), |
| 382 | - "probant": S.Array(S.Record({ key: S.String, value: S.NullOr(S.Int)})), | |
| 400 | + "probant": S.Array(mapSchema(S.NullOr(S.Int))), | |
| 383 | 401 | "protext": S.Array(S.Union(S.Array(S.Int), S.Boolean, MonaziteClass)), |
| 384 | 402 | }) {} |
Mtypescript-effect-schemajust-schema-true--8c4ca457bcba / TopLevel.ts+25 −7
| @@ -1,5 +1,23 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export class PrefreshmanClass extends S.Class<PrefreshmanClass>("PrefreshmanClass")({ |
| 5 | 23 | "azorubine": S.Null, |
| @@ -340,7 +358,7 @@ export class JurorClass extends S.Class<JurorClass>("JurorClass")({ | ||
| 340 | 358 | |
| 341 | 359 | export class TopLevel extends S.Class<TopLevel>("TopLevel")({ |
| 342 | 360 | "juror": S.Array(S.Union(S.Boolean, JurorClass)), |
| 343 | - "kongoni": S.Array(S.Union(S.Array(S.Int), S.Record({ key: S.String, value: S.Int}))), | |
| 361 | + "kongoni": S.Array(S.Union(S.Array(S.Int), mapSchema(S.Int))), | |
| 344 | 362 | "ladronism": S.Array(S.Union(S.Number, S.String, LadronismClass)), |
| 345 | 363 | "landlubberly": S.Array(S.Union(S.Boolean, S.Int, LandlubberlyClass)), |
| 346 | 364 | "listener": S.Array(S.Union(S.Array(S.Null), S.Int)), |
| @@ -361,24 +379,24 @@ export class TopLevel extends S.Class<TopLevel>("TopLevel")({ | ||
| 361 | 379 | "nonvaluation": S.Array(S.Union(S.Array(S.Null), S.Boolean, S.Number)), |
| 362 | 380 | "occupationalist": S.Array(S.Union(S.Array(S.Null), OccupationalistClass, S.Null)), |
| 363 | 381 | "outrival": S.Array(S.Union(S.Number, OutrivalClass, S.Null)), |
| 364 | - "paleographically": S.Array(S.Union(S.Number, S.Record({ key: S.String, value: S.NullOr(S.Int)}))), | |
| 365 | - "pamphletwise": S.Array(S.Union(S.Int, S.Record({ key: S.String, value: S.Int}), S.String)), | |
| 382 | + "paleographically": S.Array(S.Union(S.Number, mapSchema(S.NullOr(S.Int)))), | |
| 383 | + "pamphletwise": S.Array(S.Union(S.Int, mapSchema(S.Int), S.String)), | |
| 366 | 384 | "pediatrics": S.Array(S.Union(S.Boolean, S.Number, S.Null)), |
| 367 | 385 | "perceptive": S.Array(S.Boolean), |
| 368 | 386 | "piaculum": S.Array(S.Union(S.Number, PiaculumClass)), |
| 369 | 387 | "piccadilly": S.Array(S.Union(S.Number, S.String, S.Null)), |
| 370 | 388 | "piffler": S.Array(S.Union(S.Array(S.Null), MonaziteClass)), |
| 371 | 389 | "pithful": S.Array(S.Union(S.Boolean, S.Int, S.Null)), |
| 372 | - "placuntitis": S.Array(S.Union(S.Int, S.Record({ key: S.String, value: S.Int}))), | |
| 373 | - "plectopterous": S.Array(S.Union(S.Number, S.Record({ key: S.String, value: S.Int}))), | |
| 390 | + "placuntitis": S.Array(S.Union(S.Int, mapSchema(S.Int))), | |
| 391 | + "plectopterous": S.Array(S.Union(S.Number, mapSchema(S.Int))), | |
| 374 | 392 | "pneumocele": S.Array(S.NullOr(Pneumocele)), |
| 375 | 393 | "poliorcetic": S.Array(S.Union(S.Boolean, MonaziteClass)), |
| 376 | - "poormaster": S.Array(S.Union(S.Array(S.Int), S.Record({ key: S.String, value: S.Int}), S.Null)), | |
| 394 | + "poormaster": S.Array(S.Union(S.Array(S.Int), mapSchema(S.Int), S.Null)), | |
| 377 | 395 | "potwhisky": S.Array(S.Union(S.Int, PotwhiskyClass, S.Null)), |
| 378 | 396 | "practicalizer": S.Array(S.Union(S.Array(S.Null), S.String, MonaziteClass)), |
| 379 | 397 | "prefreshman": S.Array(S.Union(S.Array(S.Null), S.String, PrefreshmanClass)), |
| 380 | 398 | "prehensility": S.Array(S.Union(S.Array(S.Null), S.Boolean, MonaziteClass)), |
| 381 | 399 | "prevoidance": S.Array(S.Union(S.Array(S.Int), S.Int, MonaziteClass)), |
| 382 | - "probant": S.Array(S.Record({ key: S.String, value: S.NullOr(S.Int)})), | |
| 400 | + "probant": S.Array(mapSchema(S.NullOr(S.Int))), | |
| 383 | 401 | "protext": S.Array(S.Union(S.Array(S.Int), S.Boolean, MonaziteClass)), |
| 384 | 402 | }) {} |
Test case
2 generated files · +58 −22test/inputs/json/priority/combinations4.json
Mtypescript-effect-schemadefault / TopLevel.ts+29 −11
| @@ -1,5 +1,23 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export class WrothyClass extends S.Class<WrothyClass>("WrothyClass")({ |
| 5 | 23 | "Aeschynanthus": S.Null, |
| @@ -389,7 +407,7 @@ export class TopLevel extends S.Class<TopLevel>("TopLevel")({ | ||
| 389 | 407 | "pulpitism": S.Array(S.Union(S.Array(S.Int), S.Number, PulpitismClass)), |
| 390 | 408 | "pyodermia": S.Array(S.Union(S.Int, PyodermiaClass)), |
| 391 | 409 | "quebrachine": S.Array(S.Union(S.Boolean, QuebrachineClass, S.Null)), |
| 392 | - "querier": S.Array(S.Union(S.Boolean, S.Record({ key: S.String, value: S.Int}))), | |
| 410 | + "querier": S.Array(S.Union(S.Boolean, mapSchema(S.Int))), | |
| 393 | 411 | "rebarbative": S.Array(S.Union(S.Array(S.Int), S.Boolean, S.Number)), |
| 394 | 412 | "reimagine": S.Array(Reimagine), |
| 395 | 413 | "ressaut": Ressaut, |
| @@ -398,10 +416,10 @@ export class TopLevel extends S.Class<TopLevel>("TopLevel")({ | ||
| 398 | 416 | "rewrite": S.Array(S.Union(S.Array(S.Null), S.Number, RewriteClass)), |
| 399 | 417 | "saccoderm": S.Array(S.Union(S.Array(S.Int), S.String, S.Null)), |
| 400 | 418 | "santir": S.Array(S.Union(S.Number, SantirClass)), |
| 401 | - "saprophilous": S.Array(S.Union(S.Record({ key: S.String, value: S.Int}), S.String, S.Null)), | |
| 419 | + "saprophilous": S.Array(S.Union(mapSchema(S.Int), S.String, S.Null)), | |
| 402 | 420 | "saxten": S.Array(S.Union(S.String, SaxtenClass)), |
| 403 | 421 | "scatty": S.Array(S.NullOr(Scatty)), |
| 404 | - "scoffer": S.Array(S.Union(S.Array(S.Null), S.Record({ key: S.String, value: S.Int}), S.Null)), | |
| 422 | + "scoffer": S.Array(S.Union(S.Array(S.Null), mapSchema(S.Int), S.Null)), | |
| 405 | 423 | "scrampum": S.Array(S.Union(S.Array(S.Int), S.Boolean, S.Null)), |
| 406 | 424 | "semantic": S.Number, |
| 407 | 425 | "serpentinic": S.Array(S.Union(S.Array(S.Int), S.Number)), |
| @@ -409,7 +427,7 @@ export class TopLevel extends S.Class<TopLevel>("TopLevel")({ | ||
| 409 | 427 | "sistering": S.Array(S.Union(S.Array(S.Null), S.Int, SisteringClass)), |
| 410 | 428 | "staghunting": S.Array(Staghunting), |
| 411 | 429 | "stagmometer": S.Array(S.Union(S.Array(S.NullOr(S.Int)), S.String)), |
| 412 | - "stimulability": S.Array(S.Union(S.Boolean, S.Int, S.Record({ key: S.String, value: S.Int}))), | |
| 430 | + "stimulability": S.Array(S.Union(S.Boolean, S.Int, mapSchema(S.Int))), | |
| 413 | 431 | "strangleable": S.Array(S.Union(S.Array(S.Null), S.Number)), |
| 414 | 432 | "strenuosity": S.Array(S.Union(S.Array(S.Null), StrenuosityClass)), |
| 415 | 433 | "tabaxir": S.Array(S.Union(S.Boolean, S.Number)), |
| @@ -419,22 +437,22 @@ export class TopLevel extends S.Class<TopLevel>("TopLevel")({ | ||
| 419 | 437 | "tortricine": S.Array(S.Union(S.Array(S.NullOr(S.Int)), QuebrachineClass)), |
| 420 | 438 | "truantcy": S.Array(S.Union(S.Boolean, TruantcyClass)), |
| 421 | 439 | "turgesce": S.Array(S.String), |
| 422 | - "unbeginning": S.Array(S.Union(S.Array(S.Null), S.Record({ key: S.String, value: S.Int}), S.String)), | |
| 440 | + "unbeginning": S.Array(S.Union(S.Array(S.Null), mapSchema(S.Int), S.String)), | |
| 423 | 441 | "underdunged": S.Array(S.Number), |
| 424 | - "undesirability": S.Array(S.Union(S.Array(S.Int), S.Record({ key: S.String, value: S.Int}), S.String)), | |
| 425 | - "unerasing": S.Array(S.Union(S.Array(S.Null), S.Int, S.Record({ key: S.String, value: S.Int}))), | |
| 442 | + "undesirability": S.Array(S.Union(S.Array(S.Int), mapSchema(S.Int), S.String)), | |
| 443 | + "unerasing": S.Array(S.Union(S.Array(S.Null), S.Int, mapSchema(S.Int))), | |
| 426 | 444 | "unguentarium": S.Array(S.Union(S.Array(S.Null), S.Int, S.Null)), |
| 427 | 445 | "unimpeachably": S.Array(S.Union(S.Boolean, UnimpeachablyClass)), |
| 428 | - "unmortgaged": S.Array(S.Union(S.Number, S.Record({ key: S.String, value: S.Int}), S.Null)), | |
| 446 | + "unmortgaged": S.Array(S.Union(S.Number, mapSchema(S.Int), S.Null)), | |
| 429 | 447 | "unobstructed": S.Array(S.Union(S.Int, QuebrachineClass, S.Null)), |
| 430 | 448 | "unreceptivity": S.Array(S.Union(S.Array(S.Null), S.Int, S.String)), |
| 431 | 449 | "unsatisfactoriness": S.Array(S.Union(S.Array(S.Int), S.Boolean, S.Int)), |
| 432 | 450 | "unsecurity": S.Array(S.Int), |
| 433 | 451 | "unstressed": S.Array(S.Union(S.Boolean, S.String, UnstressedClass)), |
| 434 | - "untasked": S.Array(S.Union(S.Array(S.Null), S.Number, S.Record({ key: S.String, value: S.Int}))), | |
| 435 | - "unvarying": S.Array(S.Union(S.Boolean, S.Number, S.Record({ key: S.String, value: S.Int}))), | |
| 452 | + "untasked": S.Array(S.Union(S.Array(S.Null), S.Number, mapSchema(S.Int))), | |
| 453 | + "unvarying": S.Array(S.Union(S.Boolean, S.Number, mapSchema(S.Int))), | |
| 436 | 454 | "vehemently": S.Array(S.Union(S.Array(S.Null), S.Boolean, S.Null)), |
| 437 | - "warriorship": S.Record({ key: S.String, value: S.Boolean}), | |
| 455 | + "warriorship": mapSchema(S.Boolean), | |
| 438 | 456 | "whitepot": S.Array(S.Union(S.Number, QuebrachineClass)), |
| 439 | 457 | "wrothy": S.Array(S.Union(S.Array(S.Null), WrothyClass)), |
| 440 | 458 | }) {} |
Mtypescript-effect-schemajust-schema-true--8c4ca457bcba / TopLevel.ts+29 −11
| @@ -1,5 +1,23 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export class WrothyClass extends S.Class<WrothyClass>("WrothyClass")({ |
| 5 | 23 | "Aeschynanthus": S.Null, |
| @@ -389,7 +407,7 @@ export class TopLevel extends S.Class<TopLevel>("TopLevel")({ | ||
| 389 | 407 | "pulpitism": S.Array(S.Union(S.Array(S.Int), S.Number, PulpitismClass)), |
| 390 | 408 | "pyodermia": S.Array(S.Union(S.Int, PyodermiaClass)), |
| 391 | 409 | "quebrachine": S.Array(S.Union(S.Boolean, QuebrachineClass, S.Null)), |
| 392 | - "querier": S.Array(S.Union(S.Boolean, S.Record({ key: S.String, value: S.Int}))), | |
| 410 | + "querier": S.Array(S.Union(S.Boolean, mapSchema(S.Int))), | |
| 393 | 411 | "rebarbative": S.Array(S.Union(S.Array(S.Int), S.Boolean, S.Number)), |
| 394 | 412 | "reimagine": S.Array(Reimagine), |
| 395 | 413 | "ressaut": Ressaut, |
| @@ -398,10 +416,10 @@ export class TopLevel extends S.Class<TopLevel>("TopLevel")({ | ||
| 398 | 416 | "rewrite": S.Array(S.Union(S.Array(S.Null), S.Number, RewriteClass)), |
| 399 | 417 | "saccoderm": S.Array(S.Union(S.Array(S.Int), S.String, S.Null)), |
| 400 | 418 | "santir": S.Array(S.Union(S.Number, SantirClass)), |
| 401 | - "saprophilous": S.Array(S.Union(S.Record({ key: S.String, value: S.Int}), S.String, S.Null)), | |
| 419 | + "saprophilous": S.Array(S.Union(mapSchema(S.Int), S.String, S.Null)), | |
| 402 | 420 | "saxten": S.Array(S.Union(S.String, SaxtenClass)), |
| 403 | 421 | "scatty": S.Array(S.NullOr(Scatty)), |
| 404 | - "scoffer": S.Array(S.Union(S.Array(S.Null), S.Record({ key: S.String, value: S.Int}), S.Null)), | |
| 422 | + "scoffer": S.Array(S.Union(S.Array(S.Null), mapSchema(S.Int), S.Null)), | |
| 405 | 423 | "scrampum": S.Array(S.Union(S.Array(S.Int), S.Boolean, S.Null)), |
| 406 | 424 | "semantic": S.Number, |
| 407 | 425 | "serpentinic": S.Array(S.Union(S.Array(S.Int), S.Number)), |
| @@ -409,7 +427,7 @@ export class TopLevel extends S.Class<TopLevel>("TopLevel")({ | ||
| 409 | 427 | "sistering": S.Array(S.Union(S.Array(S.Null), S.Int, SisteringClass)), |
| 410 | 428 | "staghunting": S.Array(Staghunting), |
| 411 | 429 | "stagmometer": S.Array(S.Union(S.Array(S.NullOr(S.Int)), S.String)), |
| 412 | - "stimulability": S.Array(S.Union(S.Boolean, S.Int, S.Record({ key: S.String, value: S.Int}))), | |
| 430 | + "stimulability": S.Array(S.Union(S.Boolean, S.Int, mapSchema(S.Int))), | |
| 413 | 431 | "strangleable": S.Array(S.Union(S.Array(S.Null), S.Number)), |
| 414 | 432 | "strenuosity": S.Array(S.Union(S.Array(S.Null), StrenuosityClass)), |
| 415 | 433 | "tabaxir": S.Array(S.Union(S.Boolean, S.Number)), |
| @@ -419,22 +437,22 @@ export class TopLevel extends S.Class<TopLevel>("TopLevel")({ | ||
| 419 | 437 | "tortricine": S.Array(S.Union(S.Array(S.NullOr(S.Int)), QuebrachineClass)), |
| 420 | 438 | "truantcy": S.Array(S.Union(S.Boolean, TruantcyClass)), |
| 421 | 439 | "turgesce": S.Array(S.String), |
| 422 | - "unbeginning": S.Array(S.Union(S.Array(S.Null), S.Record({ key: S.String, value: S.Int}), S.String)), | |
| 440 | + "unbeginning": S.Array(S.Union(S.Array(S.Null), mapSchema(S.Int), S.String)), | |
| 423 | 441 | "underdunged": S.Array(S.Number), |
| 424 | - "undesirability": S.Array(S.Union(S.Array(S.Int), S.Record({ key: S.String, value: S.Int}), S.String)), | |
| 425 | - "unerasing": S.Array(S.Union(S.Array(S.Null), S.Int, S.Record({ key: S.String, value: S.Int}))), | |
| 442 | + "undesirability": S.Array(S.Union(S.Array(S.Int), mapSchema(S.Int), S.String)), | |
| 443 | + "unerasing": S.Array(S.Union(S.Array(S.Null), S.Int, mapSchema(S.Int))), | |
| 426 | 444 | "unguentarium": S.Array(S.Union(S.Array(S.Null), S.Int, S.Null)), |
| 427 | 445 | "unimpeachably": S.Array(S.Union(S.Boolean, UnimpeachablyClass)), |
| 428 | - "unmortgaged": S.Array(S.Union(S.Number, S.Record({ key: S.String, value: S.Int}), S.Null)), | |
| 446 | + "unmortgaged": S.Array(S.Union(S.Number, mapSchema(S.Int), S.Null)), | |
| 429 | 447 | "unobstructed": S.Array(S.Union(S.Int, QuebrachineClass, S.Null)), |
| 430 | 448 | "unreceptivity": S.Array(S.Union(S.Array(S.Null), S.Int, S.String)), |
| 431 | 449 | "unsatisfactoriness": S.Array(S.Union(S.Array(S.Int), S.Boolean, S.Int)), |
| 432 | 450 | "unsecurity": S.Array(S.Int), |
| 433 | 451 | "unstressed": S.Array(S.Union(S.Boolean, S.String, UnstressedClass)), |
| 434 | - "untasked": S.Array(S.Union(S.Array(S.Null), S.Number, S.Record({ key: S.String, value: S.Int}))), | |
| 435 | - "unvarying": S.Array(S.Union(S.Boolean, S.Number, S.Record({ key: S.String, value: S.Int}))), | |
| 452 | + "untasked": S.Array(S.Union(S.Array(S.Null), S.Number, mapSchema(S.Int))), | |
| 453 | + "unvarying": S.Array(S.Union(S.Boolean, S.Number, mapSchema(S.Int))), | |
| 436 | 454 | "vehemently": S.Array(S.Union(S.Array(S.Null), S.Boolean, S.Null)), |
| 437 | - "warriorship": S.Record({ key: S.String, value: S.Boolean}), | |
| 455 | + "warriorship": mapSchema(S.Boolean), | |
| 438 | 456 | "whitepot": S.Array(S.Union(S.Number, QuebrachineClass)), |
| 439 | 457 | "wrothy": S.Array(S.Union(S.Array(S.Null), WrothyClass)), |
| 440 | 458 | }) {} |
Test case
1 generated file · +30 −12test/inputs/json/priority/nbl-stats.json
Mtypescript-effect-schemadefault / TopLevel.ts+30 −12
| @@ -1,5 +1,23 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export const LeaddatumEnum = S.Literal( |
| 5 | 23 | "", |
| @@ -222,11 +240,11 @@ export class Pbp extends S.Class<Pbp>("Pbp")({ | ||
| 222 | 240 | }) {} |
| 223 | 241 | |
| 224 | 242 | export class Totallds extends S.Class<Totallds>("Totallds")({ |
| 225 | - "sAssists": S.Record({ key: S.String, value: Scorer}), | |
| 226 | - "sBlocks": S.Record({ key: S.String, value: Scorer}), | |
| 227 | - "sPoints": S.Record({ key: S.String, value: Scorer}), | |
| 228 | - "sReboundsTotal": S.Record({ key: S.String, value: Scorer}), | |
| 229 | - "sSteals": S.Record({ key: S.String, value: Scorer}), | |
| 243 | + "sAssists": mapSchema(Scorer), | |
| 244 | + "sBlocks": mapSchema(Scorer), | |
| 245 | + "sPoints": mapSchema(Scorer), | |
| 246 | + "sReboundsTotal": mapSchema(Scorer), | |
| 247 | + "sSteals": mapSchema(Scorer), | |
| 230 | 248 | }) {} |
| 231 | 249 | |
| 232 | 250 | export class Team extends S.Class<Team>("Team")({ |
| @@ -266,9 +284,9 @@ export class TopLevel extends S.Class<TopLevel>("TopLevel")({ | ||
| 266 | 284 | "periodLengthREGULAR": S.Int, |
| 267 | 285 | "periodType": PerType, |
| 268 | 286 | "periodsMax": S.Int, |
| 269 | - "scorers": S.Record({ key: S.String, value: S.Array(Scorer)}), | |
| 287 | + "scorers": mapSchema(S.Array(Scorer)), | |
| 270 | 288 | "timeline": S.Array(S.Any), |
| 271 | - "tm": S.Record({ key: S.String, value: S.suspend(() => Tm)}), | |
| 289 | + "tm": mapSchema(S.suspend(() => Tm)), | |
| 272 | 290 | "totalTimeAdded": S.Int, |
| 273 | 291 | "totallds": Totallds, |
| 274 | 292 | }) {} |
| @@ -278,11 +296,11 @@ export class SBlocks extends S.Class<SBlocks>("SBlocks")({ | ||
| 278 | 296 | }) {} |
| 279 | 297 | |
| 280 | 298 | export class Lds extends S.Class<Lds>("Lds")({ |
| 281 | - "sAssists": S.Record({ key: S.String, value: Scorer}), | |
| 299 | + "sAssists": mapSchema(Scorer), | |
| 282 | 300 | "sBlocks": SBlocks, |
| 283 | - "sPoints": S.Record({ key: S.String, value: Scorer}), | |
| 284 | - "sReboundsTotal": S.Record({ key: S.String, value: Scorer}), | |
| 285 | - "sSteals": S.Record({ key: S.String, value: Scorer}), | |
| 301 | + "sPoints": mapSchema(Scorer), | |
| 302 | + "sReboundsTotal": mapSchema(Scorer), | |
| 303 | + "sSteals": mapSchema(Scorer), | |
| 286 | 304 | }) {} |
| 287 | 305 | |
| 288 | 306 | export class Tm extends S.Class<Tm>("Tm")({ |
| @@ -298,7 +316,7 @@ export class Tm extends S.Class<Tm>("Tm")({ | ||
| 298 | 316 | "p2_score": S.Int, |
| 299 | 317 | "p3_score": S.Int, |
| 300 | 318 | "p4_score": S.Int, |
| 301 | - "pl": S.Record({ key: S.String, value: Pl}), | |
| 319 | + "pl": mapSchema(Pl), | |
| 302 | 320 | "score": S.Int, |
| 303 | 321 | "scoring": S.Array(Scorer), |
| 304 | 322 | "shortName": S.String, |
Test case
1 generated file · +20 −2test/inputs/json/priority/nested-objects.json
Mtypescript-effect-schemadefault / TopLevel.ts+20 −2
| @@ -1,7 +1,25 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export class TopLevel extends S.Class<TopLevel>("TopLevel")({ |
| 5 | - "a": S.Record({ key: S.String, value: S.Int}), | |
| 6 | - "b": S.Record({ key: S.String, value: S.Int}), | |
| 23 | + "a": mapSchema(S.Int), | |
| 24 | + "b": mapSchema(S.Int), | |
| 7 | 25 | }) {} |
Test case
1 generated file · +19 −1test/inputs/json/priority/number-map.json
Mtypescript-effect-schemadefault / TopLevel.ts+19 −1
| @@ -1,6 +1,24 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export class TopLevel extends S.Class<TopLevel>("TopLevel")({ |
| 5 | - "foo": S.Record({ key: S.String, value: S.Number}), | |
| 23 | + "foo": mapSchema(S.Number), | |
| 6 | 24 | }) {} |
Test case
1 generated file · +20 −2test/inputs/json/samples/kitchen-sink.json
Mtypescript-effect-schemadefault / TopLevel.ts+20 −2
| @@ -1,5 +1,23 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export class PurplePerson extends S.Class<PurplePerson>("PurplePerson")({ |
| 5 | 23 | "intOrString": S.Int, |
| @@ -22,10 +40,10 @@ export class TopLevel extends S.Class<TopLevel>("TopLevel")({ | ||
| 22 | 40 | "differentThings": S.Array(S.Union(S.Int, S.NumberFromString.pipe(S.int()), DifferentThingClass)), |
| 23 | 41 | "doubleValue": S.Number, |
| 24 | 42 | "intValue": S.Int, |
| 25 | - "mapValue": S.Record({ key: S.String, value: S.NullOr(S.Int)}), | |
| 43 | + "mapValue": mapSchema(S.NullOr(S.Int)), | |
| 26 | 44 | "name with spaces": S.Null, |
| 27 | 45 | "nullValue": S.Null, |
| 28 | - "nullableMapValue": S.Record({ key: S.String, value: S.NullOr(S.Int)}), | |
| 46 | + "nullableMapValue": mapSchema(S.NullOr(S.Int)), | |
| 29 | 47 | "people": S.Array(PersonElement), |
| 30 | 48 | "person": PurplePerson, |
| 31 | 49 | "stringValue": S.String, |
Test case
1 generated file · +19 −1test/inputs/json/samples/us-avg-temperatures.json
Mtypescript-effect-schemadefault / TopLevel.ts+19 −1
| @@ -1,5 +1,23 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export class Description extends S.Class<Description>("Description")({ |
| 5 | 23 | "base_period": S.String, |
| @@ -14,6 +32,6 @@ export class Datum extends S.Class<Datum>("Datum")({ | ||
| 14 | 32 | }) {} |
| 15 | 33 | |
| 16 | 34 | export class TopLevel extends S.Class<TopLevel>("TopLevel")({ |
| 17 | - "data": S.Record({ key: S.String, value: Datum}), | |
| 35 | + "data": mapSchema(Datum), | |
| 18 | 36 | "description": Description, |
| 19 | 37 | }) {} |
Test case
1 generated file · +19 −1test/inputs/schema/any.schema
Mschema-typescript-effect-schemadefault / TopLevel.ts+19 −1
| @@ -1,7 +1,25 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export class TopLevel extends S.Class<TopLevel>("TopLevel")({ |
| 5 | 23 | "foo": S.Any, |
| 6 | - "values": S.Record({ key: S.String, value: S.Any}), | |
| 24 | + "values": mapSchema(S.Any), | |
| 7 | 25 | }) {} |
Test case
1 generated file · +19 −1test/inputs/schema/class-map-union.schema
Mschema-typescript-effect-schemadefault / TopLevel.ts+19 −1
| @@ -1,10 +1,28 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export class UnionClass extends S.Class<UnionClass>("UnionClass")({ |
| 5 | 23 | "quux": S.optional(S.Int), |
| 6 | 24 | }) {} |
| 7 | 25 | |
| 8 | 26 | export class TopLevel extends S.Class<TopLevel>("TopLevel")({ |
| 9 | - "union": S.optional(S.Record({ key: S.String, value: S.Union(S.Boolean, S.Number, S.String, UnionClass)})), | |
| 27 | + "union": S.optional(mapSchema(S.Union(S.Boolean, S.Number, S.String, UnionClass))), | |
| 10 | 28 | }) {} |
Test case
1 generated file · +19 −1test/inputs/schema/class-with-additional.schema
Mschema-typescript-effect-schemadefault / TopLevel.ts+19 −1
| @@ -1,6 +1,24 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export class TopLevel extends S.Class<TopLevel>("TopLevel")({ |
| 5 | - "map": S.optional(S.Record({ key: S.String, value: S.Union(S.Boolean, S.Number)})), | |
| 23 | + "map": S.optional(mapSchema(S.Union(S.Boolean, S.Number))), | |
| 6 | 24 | }) {} |
Test case
1 generated file · +21 −3test/inputs/schema/direct-union.schema
Mschema-typescript-effect-schemadefault / TopLevel.ts+21 −3
| @@ -1,11 +1,29 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export class Thing extends S.Class<Thing>("Thing")({ |
| 5 | - "optional": S.optional(S.Union(S.Array(S.Any), S.Boolean, S.Number, S.Int, S.Record({ key: S.String, value: S.Any}), S.String, S.Null)), | |
| 6 | - "required": S.Union(S.Array(S.Any), S.Boolean, S.Number, S.Int, S.Record({ key: S.String, value: S.Any}), S.String, S.Null), | |
| 23 | + "optional": S.optional(S.Union(S.Array(S.Any), S.Boolean, S.Number, S.Int, mapSchema(S.Any), S.String, S.Null)), | |
| 24 | + "required": S.Union(S.Array(S.Any), S.Boolean, S.Number, S.Int, mapSchema(S.Any), S.String, S.Null), | |
| 7 | 25 | }) {} |
| 8 | 26 | |
| 9 | 27 | export class TopLevel extends S.Class<TopLevel>("TopLevel")({ |
| 10 | - "stuff": S.Record({ key: S.String, value: Thing}), | |
| 28 | + "stuff": mapSchema(Thing), | |
| 11 | 29 | }) {} |
Test case
1 generated file · +19 −1test/inputs/schema/empty-object.schema
Mschema-typescript-effect-schemadefault / TopLevel.ts+19 −1
| @@ -1,4 +1,22 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | -export const TopLevel = S.Record({ key: S.String, value: S.Any}); | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 21 | +export const TopLevel = mapSchema(S.Any); | |
| 4 | 22 | export type TopLevel = S.Schema.Type<typeof TopLevel>; |
Test case
1 generated file · +19 −1test/inputs/schema/go-schema-pattern-properties.schema
Mschema-typescript-effect-schemadefault / TopLevel.ts+19 −1
| @@ -1,6 +1,24 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export class TopLevel extends S.Class<TopLevel>("TopLevel")({ |
| 5 | - "map": S.Record({ key: S.String, value: S.Int}), | |
| 23 | + "map": mapSchema(S.Int), | |
| 6 | 24 | }) {} |
Test case
1 generated file · +21 −3test/inputs/schema/recursive-union-flattening.schema
Mschema-typescript-effect-schemadefault / TopLevel.ts+21 −3
| @@ -1,13 +1,31 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export class XClass extends S.Class<XClass>("XClass")({ |
| 5 | - "x": S.optional(S.Union(S.Array(S.Union(S.Array(S.Any), S.Boolean, S.Number, S.String, S.suspend(() => XClass), S.Null)), S.Boolean, S.Number, S.Record({ key: S.String, value: S.Any}), S.String, S.Null)), | |
| 23 | + "x": S.optional(S.Union(S.Array(S.Union(S.Array(S.Any), S.Boolean, S.Number, S.String, S.suspend(() => XClass), S.Null)), S.Boolean, S.Number, mapSchema(S.Any), S.String, S.Null)), | |
| 6 | 24 | }) {} |
| 7 | 25 | |
| 8 | 26 | export class TopLevelClass extends S.Class<TopLevelClass>("TopLevelClass")({ |
| 9 | - "x": S.optional(S.Union(S.Array(S.Union(S.Array(S.Any), S.Boolean, S.Number, S.String, XClass, S.Null)), S.Boolean, S.Number, S.Record({ key: S.String, value: S.Any}), S.String, S.Null)), | |
| 27 | + "x": S.optional(S.Union(S.Array(S.Union(S.Array(S.Any), S.Boolean, S.Number, S.String, XClass, S.Null)), S.Boolean, S.Number, mapSchema(S.Any), S.String, S.Null)), | |
| 10 | 28 | }) {} |
| 11 | 29 | |
| 12 | -export const TopLevel = S.Union(S.Array(S.Union(S.Array(S.Any), S.Boolean, S.Number, S.String, TopLevelClass, S.Null)), S.Boolean, S.Number, S.Int, S.Record({ key: S.String, value: S.Any}), S.String, S.Null); | |
| 30 | +export const TopLevel = S.Union(S.Array(S.Union(S.Array(S.Any), S.Boolean, S.Number, S.String, TopLevelClass, S.Null)), S.Boolean, S.Number, S.Int, mapSchema(S.Any), S.String, S.Null); | |
| 13 | 31 | export type TopLevel = S.Schema.Type<typeof TopLevel>; |
Test case
1 generated file · +19 −1test/inputs/schema/unevaluated-properties.schema
Mschema-typescript-effect-schemadefault / TopLevel.ts+19 −1
| @@ -1,5 +1,23 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | |
| 4 | 22 | export class Item extends S.Class<Item>("Item")({ |
| 5 | 23 | "key": S.String, |
| @@ -12,7 +30,7 @@ export class ClosedClass extends S.Class<ClosedClass>("ClosedClass")(S.Struct({} | ||
| 12 | 30 | export class Config extends S.Class<Config>("Config")({ |
| 13 | 31 | "closed": S.optional(S.Union(S.Array(S.Any), S.Boolean, S.Number, S.Int, S.String, ClosedClass, S.Null)), |
| 14 | 32 | "name": S.optional(S.String), |
| 15 | - "settings": S.optional(S.Record({ key: S.String, value: S.Array(Item)})), | |
| 33 | + "settings": S.optional(mapSchema(S.Array(Item))), | |
| 16 | 34 | }) {} |
| 17 | 35 | |
| 18 | 36 | export class TopLevel extends S.Class<TopLevel>("TopLevel")({ |
Test case
1 generated file · +29 −11test/inputs/schema/vega-lite.schema
Mschema-typescript-effect-schemadefault / TopLevel.ts+29 −11
| @@ -1,5 +1,23 @@ | ||
| 1 | 1 | import * as S from "effect/Schema"; |
| 2 | 2 | |
| 3 | +const objectSchema = <A>() => | |
| 4 | + S.declare( | |
| 5 | + (input): input is Record<string, A> => | |
| 6 | + typeof input === "object" && input !== null && !Array.isArray(input) | |
| 7 | + ); | |
| 8 | +const mapSchema = <A, I, R>(value: S.Schema<A, I, R>) => { | |
| 9 | + const entries = S.transform(objectSchema<unknown>(), S.Array(S.Tuple(S.String, value)), { | |
| 10 | + strict: false, | |
| 11 | + decode: Object.entries, | |
| 12 | + encode: Object.fromEntries | |
| 13 | + }); | |
| 14 | + return S.transform(entries, objectSchema<A>(), { | |
| 15 | + strict: false, | |
| 16 | + decode: Object.fromEntries, | |
| 17 | + encode: Object.entries | |
| 18 | + }); | |
| 19 | +}; | |
| 20 | + | |
| 3 | 21 | // Determines how size calculation should be performed, one of `"content"` or `"padding"`. |
| 4 | 22 | // The default setting (`"content"`) interprets the width and height settings as the data |
| 5 | 23 | // rectangle (plotting) dimensions, to which padding is then added. In contrast, the |
| @@ -642,7 +660,7 @@ export class Projection extends S.Class<Projection>("Projection")({ | ||
| 642 | 660 | "fraction": S.optional(S.Number), |
| 643 | 661 | "lobes": S.optional(S.Number), |
| 644 | 662 | "parallel": S.optional(S.Number), |
| 645 | - "precision": S.optional(S.Record({ key: S.String, value: S.Union(S.Number, S.String)})), | |
| 663 | + "precision": S.optional(mapSchema(S.Union(S.Number, S.String))), | |
| 646 | 664 | "radius": S.optional(S.Number), |
| 647 | 665 | "ratio": S.optional(S.Number), |
| 648 | 666 | "rotate": S.optional(S.Array(S.Number)), |
| @@ -789,7 +807,7 @@ export class Header extends S.Class<Header>("Header")({ | ||
| 789 | 807 | }) {} |
| 790 | 808 | |
| 791 | 809 | export class SelectionDef extends S.Class<SelectionDef>("SelectionDef")({ |
| 792 | - "bind": S.optional(S.Union(BindEnum, S.Record({ key: S.String, value: S.suspend(() => VgBinding)}))), | |
| 810 | + "bind": S.optional(S.Union(BindEnum, mapSchema(S.suspend(() => VgBinding)))), | |
| 793 | 811 | "empty": S.optional(Empty), |
| 794 | 812 | "encodings": S.optional(S.Array(SingleDefChannel)), |
| 795 | 813 | "fields": S.optional(S.Array(S.String)), |
| @@ -989,7 +1007,7 @@ export class EncodingWithFacet extends S.Class<EncodingWithFacet>("EncodingWithF | ||
| 989 | 1007 | }) {} |
| 990 | 1008 | |
| 991 | 1009 | export class DataFormat extends S.Class<DataFormat>("DataFormat")({ |
| 992 | - "parse": S.optional(S.Union(ParseEnum, S.Record({ key: S.String, value: S.Any}))), | |
| 1010 | + "parse": S.optional(S.Union(ParseEnum, mapSchema(S.Any))), | |
| 993 | 1011 | "type": S.optional(DataFormatType), |
| 994 | 1012 | "property": S.optional(S.String), |
| 995 | 1013 | "feature": S.optional(S.String), |
| @@ -999,7 +1017,7 @@ export class DataFormat extends S.Class<DataFormat>("DataFormat")({ | ||
| 999 | 1017 | export class Data extends S.Class<Data>("Data")({ |
| 1000 | 1018 | "format": S.optional(DataFormat), |
| 1001 | 1019 | "url": S.optional(S.String), |
| 1002 | - "values": S.optional(S.Union(S.Array(S.Union(S.Boolean, S.Number, S.Record({ key: S.String, value: S.Any}), S.String)), S.Record({ key: S.String, value: S.Any}), S.String)), | |
| 1020 | + "values": S.optional(S.Union(S.Array(S.Union(S.Boolean, S.Number, mapSchema(S.Any), S.String)), mapSchema(S.Any), S.String)), | |
| 1003 | 1021 | "name": S.optional(S.String), |
| 1004 | 1022 | }) {} |
| 1005 | 1023 | |
| @@ -1139,7 +1157,7 @@ export class VgBinding extends S.Class<VgBinding>("VgBinding")({ | ||
| 1139 | 1157 | }) {} |
| 1140 | 1158 | |
| 1141 | 1159 | export class SingleSelectionConfig extends S.Class<SingleSelectionConfig>("SingleSelectionConfig")({ |
| 1142 | - "bind": S.optional(S.Record({ key: S.String, value: VgBinding})), | |
| 1160 | + "bind": S.optional(mapSchema(VgBinding)), | |
| 1143 | 1161 | "empty": S.optional(Empty), |
| 1144 | 1162 | "encodings": S.optional(S.Array(SingleDefChannel)), |
| 1145 | 1163 | "fields": S.optional(S.Array(S.String)), |
| @@ -1237,7 +1255,7 @@ export class ProjectionConfig extends S.Class<ProjectionConfig>("ProjectionConfi | ||
| 1237 | 1255 | "fraction": S.optional(S.Number), |
| 1238 | 1256 | "lobes": S.optional(S.Number), |
| 1239 | 1257 | "parallel": S.optional(S.Number), |
| 1240 | - "precision": S.optional(S.Record({ key: S.String, value: S.Union(S.Number, S.String)})), | |
| 1258 | + "precision": S.optional(mapSchema(S.Union(S.Number, S.String))), | |
| 1241 | 1259 | "radius": S.optional(S.Number), |
| 1242 | 1260 | "ratio": S.optional(S.Number), |
| 1243 | 1261 | "rotate": S.optional(S.Array(S.Number)), |
| @@ -1474,14 +1492,14 @@ export class Config extends S.Class<Config>("Config")({ | ||
| 1474 | 1492 | "padding": S.optional(S.Union(S.Number, PaddingClass)), |
| 1475 | 1493 | "point": S.optional(MarkConfig), |
| 1476 | 1494 | "projection": S.optional(ProjectionConfig), |
| 1477 | - "range": S.optional(S.Record({ key: S.String, value: S.Union(S.Array(S.Union(S.Number, S.String)), VgScheme)})), | |
| 1495 | + "range": S.optional(mapSchema(S.Union(S.Array(S.Union(S.Number, S.String)), VgScheme))), | |
| 1478 | 1496 | "rect": S.optional(MarkConfig), |
| 1479 | 1497 | "rule": S.optional(MarkConfig), |
| 1480 | 1498 | "scale": S.optional(ScaleConfig), |
| 1481 | 1499 | "selection": S.optional(SelectionConfig), |
| 1482 | 1500 | "square": S.optional(MarkConfig), |
| 1483 | 1501 | "stack": S.optional(StackOffset), |
| 1484 | - "style": S.optional(S.Record({ key: S.String, value: VgMarkConfig})), | |
| 1502 | + "style": S.optional(mapSchema(VgMarkConfig)), | |
| 1485 | 1503 | "text": S.optional(TextConfig), |
| 1486 | 1504 | "tick": S.optional(TickConfig), |
| 1487 | 1505 | "timeFormat": S.optional(S.String), |
| @@ -1524,7 +1542,7 @@ export class TopLevel extends S.Class<TopLevel>("TopLevel")({ | ||
| 1524 | 1542 | "name": S.optional(S.String), |
| 1525 | 1543 | "padding": S.optional(S.Union(S.Number, PaddingClass)), |
| 1526 | 1544 | "projection": S.optional(Projection), |
| 1527 | - "selection": S.optional(S.Record({ key: S.String, value: SelectionDef})), | |
| 1545 | + "selection": S.optional(mapSchema(SelectionDef)), | |
| 1528 | 1546 | "title": S.optional(S.Union(S.String, TitleParams)), |
| 1529 | 1547 | "transform": S.optional(S.Array(Transform)), |
| 1530 | 1548 | "width": S.optional(S.Number), |
| @@ -1550,7 +1568,7 @@ export class Spec extends S.Class<Spec>("Spec")({ | ||
| 1550 | 1568 | "encoding": S.optional(Encoding), |
| 1551 | 1569 | "mark": S.optional(S.Union(Mark, MarkDef)), |
| 1552 | 1570 | "projection": S.optional(Projection), |
| 1553 | - "selection": S.optional(S.Record({ key: S.String, value: SelectionDef})), | |
| 1571 | + "selection": S.optional(mapSchema(SelectionDef)), | |
| 1554 | 1572 | "facet": S.optional(FacetMapping), |
| 1555 | 1573 | "spec": S.optional(S.suspend(() => Spec)), |
| 1556 | 1574 | "repeat": S.optional(Repeat), |
| @@ -1571,5 +1589,5 @@ export class LayerSpec extends S.Class<LayerSpec>("LayerSpec")({ | ||
| 1571 | 1589 | "encoding": S.optional(Encoding), |
| 1572 | 1590 | "mark": S.optional(S.Union(Mark, MarkDef)), |
| 1573 | 1591 | "projection": S.optional(Projection), |
| 1574 | - "selection": S.optional(S.Record({ key: S.String, value: SelectionDef})), | |
| 1592 | + "selection": S.optional(mapSchema(SelectionDef)), | |
| 1575 | 1593 | }) {} |
No generated files match these filters.