quicktype-core 23.3.17 → 23.3.19

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.
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fetch = void 0;
4
- console.info("=== RUNNING IN CI, USE FETCH.CI ===");
4
+ // No logging here: this module runs at import time, and anything written to
5
+ // stdout corrupts redirected CLI output (issue #2874).
5
6
  exports.fetch = require("cross-fetch").default;
@@ -55,7 +55,7 @@ const is_url_1 = __importDefault(require("is-url"));
55
55
  const Messages_1 = require("../../Messages");
56
56
  const Support_1 = require("../../support/Support");
57
57
  const get_stream_1 = require("./get-stream");
58
- const _fetch_ci_1 = require("./$fetch.ci");
58
+ const _fetch_1 = require("./$fetch");
59
59
  function parseHeaders(httpHeaders) {
60
60
  if (!Array.isArray(httpHeaders)) {
61
61
  return {};
@@ -87,7 +87,7 @@ function readableFromFileOrURL(fileOrURL, httpHeaders) {
87
87
  return __awaiter(this, void 0, void 0, function* () {
88
88
  try {
89
89
  if ((0, is_url_1.default)(fileOrURL)) {
90
- const response = yield (0, _fetch_ci_1.fetch)(fileOrURL, {
90
+ const response = yield (0, _fetch_1.fetch)(fileOrURL, {
91
91
  headers: parseHeaders(httpHeaders),
92
92
  });
93
93
  return (0, ts_necessities_1.defined)(response.body);
@@ -350,7 +350,13 @@ class SystemTextJsonCSharpRenderer extends CSharpRenderer_1.CSharpRenderer {
350
350
  if (converter !== undefined) {
351
351
  const typeSource = this.csType(targetType);
352
352
  this.emitLine("var converter = ", this.converterObject(converter), ";");
353
- this.emitLine("var ", variableName, " = (", typeSource, ")converter.ReadJson(reader, typeof(", typeSource, "), null, serializer);");
353
+ // The converter is for the non-null type, so if the target
354
+ // type is nullable we have to handle null ourselves.
355
+ const isNullable = targetType instanceof Type_1.UnionType &&
356
+ (0, TypeUtils_1.nullableFromUnion)(targetType) !== null;
357
+ this.emitLine("var ", variableName, " = ", isNullable
358
+ ? "reader.TokenType == JsonTokenType.Null ? null : "
359
+ : "", "(", typeSource, ")converter.Read(ref reader, typeof(", typeSource, "), options);");
354
360
  }
355
361
  else if (source.kind !== "null") {
356
362
  const output = targetType.kind === "double" ? targetType : source;
@@ -366,7 +372,7 @@ class SystemTextJsonCSharpRenderer extends CSharpRenderer_1.CSharpRenderer {
366
372
  // FIXME: handle EOF
367
373
  this.emitLine("reader.Read();");
368
374
  this.emitLine("var ", variableName, " = new List<", this.csType(targetType.items), ">();");
369
- this.emitLine("while (reader.TokenType != JsonToken.EndArray)");
375
+ this.emitLine("while (reader.TokenType != JsonTokenType.EndArray)");
370
376
  this.emitBlock(() => {
371
377
  this.emitDecodeTransformer(xfer.itemTransformer, xfer.itemTargetType, (v) => this.emitLine(variableName, ".Add(", v, ");"), "arrayItem", varGen);
372
378
  // FIXME: handle EOF
@@ -525,7 +531,24 @@ class SystemTextJsonCSharpRenderer extends CSharpRenderer_1.CSharpRenderer {
525
531
  const converter = this.converterForType(xfer.sourceType);
526
532
  if (converter !== undefined) {
527
533
  this.emitLine("var converter = ", this.converterObject(converter), ";");
528
- this.emitLine("converter.WriteJson(writer, ", variable, ", serializer);");
534
+ // The converter is for the non-null type, so if the source
535
+ // type is nullable we have to handle null ourselves.
536
+ const maybeNullable = xfer.sourceType instanceof Type_1.UnionType
537
+ ? (0, TypeUtils_1.nullableFromUnion)(xfer.sourceType)
538
+ : null;
539
+ if (maybeNullable !== null) {
540
+ let member = variable;
541
+ if ((0, utils_1.isValueType)((0, Transformers_1.followTargetType)(maybeNullable))) {
542
+ member = [member, ".Value"];
543
+ }
544
+ this.emitLine("if (", variable, " == null)");
545
+ this.emitBlock(() => this.emitLine("writer.WriteNullValue();"));
546
+ this.emitLine("else");
547
+ this.emitBlock(() => this.emitLine("converter.Write(writer, ", member, ", options);"));
548
+ }
549
+ else {
550
+ this.emitLine("converter.Write(writer, ", variable, ", options);");
551
+ }
529
552
  }
530
553
  else {
531
554
  this.emitLine(this.serializeValueCode(variable), ";");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quicktype-core",
3
- "version": "23.3.17",
3
+ "version": "23.3.19",
4
4
  "description": "The quicktype engine as a library",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",