quicktype-core 23.0.76 → 23.0.78
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -56,21 +56,21 @@ class TypeScriptEffectSchemaRenderer extends ConvenienceRenderer_1.ConvenienceRe
|
|
|
56
56
|
}
|
|
57
57
|
emitImports() {
|
|
58
58
|
this.ensureBlankLine();
|
|
59
|
-
this.emitLine(this.importStatement("* as
|
|
59
|
+
this.emitLine(this.importStatement("* as S", '"@effect/schema/Schema"'));
|
|
60
60
|
}
|
|
61
61
|
typeMapTypeForProperty(p) {
|
|
62
62
|
const typeMap = this.typeMapTypeFor(p.type);
|
|
63
|
-
return p.isOptional ? ["
|
|
63
|
+
return p.isOptional ? ["S.optional(", typeMap, ")"] : typeMap;
|
|
64
64
|
}
|
|
65
65
|
typeMapTypeFor(t, required = true) {
|
|
66
66
|
if (["class", "object", "enum"].indexOf(t.kind) >= 0) {
|
|
67
|
-
return ["
|
|
67
|
+
return ["S.lazy(() => ", this.nameForNamedType(t), ")"];
|
|
68
68
|
}
|
|
69
|
-
const match = (0, TypeUtils_1.matchType)(t, _anyType => "
|
|
69
|
+
const match = (0, TypeUtils_1.matchType)(t, _anyType => "S.any", _nullType => "S.null", _boolType => "S.boolean", _integerType => "S.number", _doubleType => "S.number", _stringType => "S.string", arrayType => ["S.array(", this.typeMapTypeFor(arrayType.items, false), ")"], _classType => (0, Support_1.panic)("Should already be handled."), _mapType => ["S.record(S.string, ", this.typeMapTypeFor(_mapType.values, false), ")"], _enumType => (0, Support_1.panic)("Should already be handled."), unionType => {
|
|
70
70
|
const children = Array.from(unionType.getChildren()).map((type) => this.typeMapTypeFor(type, false));
|
|
71
|
-
return ["
|
|
71
|
+
return ["S.union(", ...(0, collection_utils_1.arrayIntercalate)(", ", children), ")"];
|
|
72
72
|
}, _transformedStringType => {
|
|
73
|
-
return "
|
|
73
|
+
return "S.string";
|
|
74
74
|
});
|
|
75
75
|
if (required) {
|
|
76
76
|
return [match];
|
|
@@ -79,7 +79,12 @@ class TypeScriptEffectSchemaRenderer extends ConvenienceRenderer_1.ConvenienceRe
|
|
|
79
79
|
}
|
|
80
80
|
emitObject(name, t) {
|
|
81
81
|
this.ensureBlankLine();
|
|
82
|
-
this.
|
|
82
|
+
if (this._options.justSchema) {
|
|
83
|
+
this.emitLine("\nexport const ", name, " = S.struct({");
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
this.emitLine("\nconst ", name, "_ = S.struct({");
|
|
87
|
+
}
|
|
83
88
|
this.indent(() => {
|
|
84
89
|
this.forEachClassProperty(t, "none", (_, jsonName, property) => {
|
|
85
90
|
this.emitLine(`"${(0, Strings_1.utf16StringEscape)(jsonName)}"`, ": ", this.typeMapTypeForProperty(property), ",");
|
|
@@ -87,20 +92,21 @@ class TypeScriptEffectSchemaRenderer extends ConvenienceRenderer_1.ConvenienceRe
|
|
|
87
92
|
});
|
|
88
93
|
this.emitLine("});");
|
|
89
94
|
if (!this._options.justSchema) {
|
|
90
|
-
this.emitLine("export
|
|
95
|
+
this.emitLine("export interface ", name, " extends S.Schema.To<typeof ", name, "_> {}");
|
|
96
|
+
this.emitLine("export const ", name, ": S.Schema<S.Schema.From<typeof ", name, "_>, ", name, "> = ", name, "_;");
|
|
91
97
|
}
|
|
92
98
|
}
|
|
93
99
|
emitEnum(e, enumName) {
|
|
94
100
|
this.ensureBlankLine();
|
|
95
101
|
this.emitDescription(this.descriptionForType(e));
|
|
96
|
-
this.emitLine("\nexport const ", enumName, "
|
|
102
|
+
this.emitLine("\nexport const ", enumName, " = ", "S.enums({");
|
|
97
103
|
this.indent(() => this.forEachEnumCase(e, "none", (_, jsonName) => {
|
|
98
104
|
const name = (0, Strings_1.stringEscape)(jsonName);
|
|
99
105
|
this.emitLine('"', name, '": "', name, '",');
|
|
100
106
|
}));
|
|
101
107
|
this.emitLine("});");
|
|
102
108
|
if (!this._options.justSchema) {
|
|
103
|
-
this.emitLine("export type ", enumName, " = Schema.
|
|
109
|
+
this.emitLine("export type ", enumName, " = S.Schema.To<typeof ", enumName, ">;");
|
|
104
110
|
}
|
|
105
111
|
}
|
|
106
112
|
emitSchemas() {
|
|
@@ -38,7 +38,8 @@ class TypeScriptFlowBaseTargetLanguage extends JavaScript_1.JavaScriptTargetLang
|
|
|
38
38
|
exports.tsFlowOptions.converters,
|
|
39
39
|
exports.tsFlowOptions.rawType,
|
|
40
40
|
exports.tsFlowOptions.preferUnions,
|
|
41
|
-
exports.tsFlowOptions.preferTypes
|
|
41
|
+
exports.tsFlowOptions.preferTypes,
|
|
42
|
+
exports.tsFlowOptions.preferConstValues
|
|
42
43
|
];
|
|
43
44
|
}
|
|
44
45
|
get supportsOptionalClassProperties() {
|