quicktype-core 23.1.0 → 23.1.1

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.
@@ -41,11 +41,13 @@ class TypeScriptEffectSchemaRenderer extends ConvenienceRenderer_1.ConvenienceRe
41
41
  }
42
42
  emitImports() {
43
43
  this.ensureBlankLine();
44
- this.emitLine(this.importStatement("* as S", '"@effect/schema/Schema"'));
44
+ this.emitLine(this.importStatement("* as S", '"effect/Schema"'));
45
45
  }
46
46
  typeMapTypeForProperty(p) {
47
- const typeMap = this.typeMapTypeFor(p.type);
48
- return p.isOptional ? ["S.optional(", typeMap, ")"] : typeMap;
47
+ if (!p.isOptional) {
48
+ return this.typeMapTypeFor(p.type);
49
+ }
50
+ return ["S.optional(", this.typeMapTypeFor(p.type), ")"];
49
51
  }
50
52
  typeMapTypeFor(t, required = true) {
51
53
  if (t.kind === "class" || t.kind === "object" || t.kind === "enum") {
@@ -55,9 +57,22 @@ class TypeScriptEffectSchemaRenderer extends ConvenienceRenderer_1.ConvenienceRe
55
57
  }
56
58
  return ["S.suspend(() => ", name, ")"];
57
59
  }
58
- 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 => {
59
- const children = Array.from(unionType.getChildren()).map((type) => this.typeMapTypeFor(type, false));
60
- return ["S.Union(", ...(0, collection_utils_1.arrayIntercalate)(", ", children), ")"];
60
+ 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({ key: S.String, value: ", this.typeMapTypeFor(_mapType.values, false), "})"], _enumType => (0, Support_1.panic)("Should already be handled."), unionType => {
61
+ const types = Array.from(unionType.getChildren());
62
+ let children = [];
63
+ let nullable = false;
64
+ for (const type of types) {
65
+ if (type.kind === "null") {
66
+ nullable = true;
67
+ }
68
+ else {
69
+ children.push(this.typeMapTypeFor(type, false));
70
+ }
71
+ }
72
+ if (nullable && children.length === 1) {
73
+ return ["S.NullOr(", children[0], ")"];
74
+ }
75
+ return ["S.Union(", ...(0, collection_utils_1.arrayIntercalate)(", ", children), nullable ? ", S.Null)" : ")"];
61
76
  }, _transformedStringType => {
62
77
  return "S.String";
63
78
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quicktype-core",
3
- "version": "23.1.0",
3
+ "version": "23.1.1",
4
4
  "description": "The quicktype engine as a library",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",