quicktype-core 23.0.63 → 23.0.65

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.
@@ -230,12 +230,14 @@ class DartRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
230
230
  }
231
231
  if (this._options.justTypes)
232
232
  return;
233
- this.emitLine("// To parse this JSON data, do");
234
- this.emitLine("//");
235
- this.forEachTopLevel("none", (_t, name) => {
236
- const { decoder } = (0, Support_1.defined)(this._topLevelDependents.get(name));
237
- this.emitLine("// final ", (0, Source_1.modifySource)(Strings_1.decapitalize, name), " = ", decoder, "(jsonString);");
238
- });
233
+ if (!this._options.codersInClass) {
234
+ this.emitLine("// To parse this JSON data, do");
235
+ this.emitLine("//");
236
+ this.forEachTopLevel("none", (_t, name) => {
237
+ const { decoder } = (0, Support_1.defined)(this._topLevelDependents.get(name));
238
+ this.emitLine("// final ", (0, Source_1.modifySource)(Strings_1.decapitalize, name), " = ", decoder, "(jsonString);");
239
+ });
240
+ }
239
241
  this.ensureBlankLine();
240
242
  if (this._options.requiredProperties) {
241
243
  this.emitLine("import 'package:meta/meta.dart';");
@@ -246,7 +248,8 @@ class DartRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
246
248
  if (this._options.useHive) {
247
249
  this.emitLine("import 'package:hive/hive.dart';");
248
250
  }
249
- if (this._options.useJsonAnnotation) {
251
+ if (this._options.useJsonAnnotation && !this._options.useFreezed) {
252
+ // The freezed annotatation import already provides the import for json_annotation
250
253
  this.emitLine("import 'package:json_annotation/json_annotation.dart';");
251
254
  }
252
255
  this.emitLine("import 'dart:convert';");
@@ -416,7 +419,8 @@ class DartRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
416
419
  this.emitLine(className, "({");
417
420
  this.indent(() => {
418
421
  this.forEachClassProperty(c, "none", (name, _, prop) => {
419
- const required = this._options.requiredProperties || (this._options.nullSafety && !prop.type.isNullable);
422
+ const required = this._options.requiredProperties ||
423
+ (this._options.nullSafety && (!prop.type.isNullable || !prop.isOptional));
420
424
  this.emitLine(required ? "required " : "", "this.", name, ",");
421
425
  });
422
426
  });
@@ -435,7 +439,7 @@ class DartRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
435
439
  }
436
440
  if (this._options.useJsonAnnotation) {
437
441
  this.classPropertyCounter++;
438
- this.emitLine(`@JsonKey(name:"${jsonName}")`);
442
+ this.emitLine(`@JsonKey(name: "${jsonName}")`);
439
443
  }
440
444
  this.emitLine(this._options.finalProperties ? "final " : "", this.dartType(p.type, true), " ", name, ";");
441
445
  });
@@ -535,8 +539,14 @@ class DartRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
535
539
  else {
536
540
  this.emitLine("const factory ", className, "({");
537
541
  this.indent(() => {
538
- this.forEachClassProperty(c, "none", (name, _, _p) => {
539
- this.emitLine(this._options.requiredProperties ? "required " : "", this.dartType(_p.type, true), this._options.requiredProperties ? "" : "?", " ", name, ",");
542
+ this.forEachClassProperty(c, "none", (name, jsonName, prop) => {
543
+ const required = this._options.requiredProperties ||
544
+ (this._options.nullSafety && (!prop.type.isNullable || !prop.isOptional));
545
+ if (this._options.useJsonAnnotation) {
546
+ this.classPropertyCounter++;
547
+ this.emitLine(`@JsonKey(name: "${jsonName}")`);
548
+ }
549
+ this.emitLine(required ? "required " : "", this.dartType(prop.type, true), " ", name, ",");
540
550
  });
541
551
  });
542
552
  this.emitLine("}) = _", className, ";");
@@ -1,16 +1,18 @@
1
- import { ClassProperty, Type } from "../Type";
1
+ import { StringTypeMapping } from "TypeBuilder";
2
+ import { ConvenienceRenderer } from "../ConvenienceRenderer";
2
3
  import { Namer } from "../Naming";
3
4
  import { RenderContext } from "../Renderer";
4
5
  import { BooleanOption, Option, OptionValues } from "../RendererOptions";
5
- import { TargetLanguage } from "../TargetLanguage";
6
6
  import { Sourcelike } from "../Source";
7
- import { ConvenienceRenderer } from "../ConvenienceRenderer";
7
+ import { TargetLanguage } from "../TargetLanguage";
8
+ import { ClassProperty, Type } from "../Type";
8
9
  export declare const typeScriptZodOptions: {
9
10
  justSchema: BooleanOption;
10
11
  };
11
12
  export declare class TypeScriptZodTargetLanguage extends TargetLanguage {
12
13
  protected getOptions(): Option<any>[];
13
14
  constructor(displayName?: string, names?: string[], extension?: string);
15
+ get stringTypeMapping(): StringTypeMapping;
14
16
  protected makeRenderer(renderContext: RenderContext, untypedOptionValues: {
15
17
  [name: string]: any;
16
18
  }): TypeScriptZodRenderer;
@@ -2,15 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TypeScriptZodRenderer = exports.TypeScriptZodTargetLanguage = exports.typeScriptZodOptions = void 0;
4
4
  const collection_utils_1 = require("collection-utils");
5
- const TypeUtils_1 = require("../TypeUtils");
5
+ const ConvenienceRenderer_1 = require("../ConvenienceRenderer");
6
6
  const Naming_1 = require("../Naming");
7
7
  const RendererOptions_1 = require("../RendererOptions");
8
+ const TargetLanguage_1 = require("../TargetLanguage");
9
+ const TypeUtils_1 = require("../TypeUtils");
8
10
  const Acronyms_1 = require("../support/Acronyms");
9
11
  const Strings_1 = require("../support/Strings");
10
- const TargetLanguage_1 = require("../TargetLanguage");
11
- const JavaScript_1 = require("./JavaScript");
12
12
  const Support_1 = require("../support/Support");
13
- const ConvenienceRenderer_1 = require("../ConvenienceRenderer");
13
+ const JavaScript_1 = require("./JavaScript");
14
14
  exports.typeScriptZodOptions = {
15
15
  justSchema: new RendererOptions_1.BooleanOption("just-schema", "Schema only", false)
16
16
  };
@@ -21,6 +21,12 @@ class TypeScriptZodTargetLanguage extends TargetLanguage_1.TargetLanguage {
21
21
  constructor(displayName = "TypeScript Zod", names = ["typescript-zod"], extension = "ts") {
22
22
  super(displayName, names, extension);
23
23
  }
24
+ get stringTypeMapping() {
25
+ const mapping = new Map();
26
+ const dateTimeType = "date-time";
27
+ mapping.set("date-time", dateTimeType);
28
+ return mapping;
29
+ }
24
30
  makeRenderer(renderContext, untypedOptionValues) {
25
31
  return new TypeScriptZodRenderer(this, renderContext, (0, RendererOptions_1.getOptionValues)(exports.typeScriptZodOptions, untypedOptionValues));
26
32
  }
@@ -70,6 +76,9 @@ class TypeScriptZodRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
70
76
  const children = Array.from(unionType.getChildren()).map((type) => this.typeMapTypeFor(type, false));
71
77
  return ["z.union([", ...(0, collection_utils_1.arrayIntercalate)(", ", children), "])"];
72
78
  }, _transformedStringType => {
79
+ if (_transformedStringType.kind === "date-time") {
80
+ return "z.coerce.date()";
81
+ }
73
82
  return "z.string()";
74
83
  });
75
84
  if (required) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quicktype-core",
3
- "version": "23.0.63",
3
+ "version": "23.0.65",
4
4
  "description": "The quicktype engine as a library",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",