quicktype-core 7.0.21 → 7.0.22

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.
@@ -7,6 +7,7 @@ const ConvenienceRenderer_1 = require("../../ConvenienceRenderer");
7
7
  const TargetLanguage_1 = require("../../TargetLanguage");
8
8
  const RendererOptions_1 = require("../../RendererOptions");
9
9
  const keywords = require("./keywords");
10
+ const forbiddenForObjectProperties = Array.from(new Set([...keywords.keywords, ...keywords.reservedProperties]));
10
11
  const Type_1 = require("../../Type");
11
12
  const TypeUtils_1 = require("../../TypeUtils");
12
13
  const Strings_1 = require("../../support/Strings");
@@ -46,15 +47,16 @@ class RubyTargetLanguage extends TargetLanguage_1.TargetLanguage {
46
47
  }
47
48
  }
48
49
  exports.RubyTargetLanguage = RubyTargetLanguage;
49
- function isStartCharacter(utf16Unit) {
50
- return unicode.isAlphabetic(utf16Unit) || utf16Unit === 0x5f; // underscore
51
- }
50
+ const isStartCharacter = Strings_1.isLetterOrUnderscore;
52
51
  function isPartCharacter(utf16Unit) {
53
52
  const category = unicode.getCategory(utf16Unit);
54
53
  return ["Nd", "Pc", "Mn", "Mc"].indexOf(category) >= 0 || isStartCharacter(utf16Unit);
55
54
  }
56
55
  const legalizeName = Strings_1.legalizeCharacters(isPartCharacter);
57
56
  function simpleNameStyle(original, uppercase) {
57
+ if (/^[0-9]+$/.test(original)) {
58
+ original = original + "N";
59
+ }
58
60
  const words = Strings_1.splitIntoWords(original);
59
61
  return Strings_1.combineWords(words, legalizeName, uppercase ? Strings_1.firstUpperWordStyle : Strings_1.allLowerWordStyle, uppercase ? Strings_1.firstUpperWordStyle : Strings_1.allLowerWordStyle, Strings_1.allUpperWordStyle, Strings_1.allUpperWordStyle, "", isStartCharacter);
60
62
  }
@@ -77,10 +79,10 @@ class RubyRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
77
79
  return "class" === t.kind;
78
80
  }
79
81
  forbiddenNamesForGlobalNamespace() {
80
- return keywords.globals.concat(["Types", "JSON", "Dry", "Constructor"]);
82
+ return keywords.globals.concat(["Types", "JSON", "Dry", "Constructor", "Self"]);
81
83
  }
82
84
  forbiddenForObjectProperties(_c, _classNamed) {
83
- return { names: keywords.reservedProperties, includeGlobalForbidden: true };
85
+ return { names: forbiddenForObjectProperties, includeGlobalForbidden: true };
84
86
  }
85
87
  makeNamedTypeNamer() {
86
88
  return new Naming_1.Namer("types", n => simpleNameStyle(n, true), []);
@@ -96,7 +98,7 @@ class RubyRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
96
98
  }
97
99
  dryType(t, isOptional = false) {
98
100
  const optional = isOptional ? ".optional" : "";
99
- return TypeUtils_1.matchType(t, _anyType => ["Types::Any", optional], _nullType => ["Types::Nil", optional], _boolType => ["Types::Bool", optional], _integerType => ["Types::Int", optional], _doubleType => ["Types::Double", optional], _stringType => ["Types::String", optional], arrayType => ["Types.Array(", this.dryType(arrayType.items), ")", optional], classType => [this.nameForNamedType(classType), optional], mapType => ["Types::Hash.meta(of: ", this.dryType(mapType.values), ")", optional], enumType => ["Types::", this.nameForNamedType(enumType), optional], unionType => {
101
+ return TypeUtils_1.matchType(t, _anyType => ["Types::Any", optional], _nullType => ["Types::Nil", optional], _boolType => ["Types::Bool", optional], _integerType => ["Types::Integer", optional], _doubleType => ["Types::Double", optional], _stringType => ["Types::String", optional], arrayType => ["Types.Array(", this.dryType(arrayType.items), ")", optional], classType => [this.nameForNamedType(classType), optional], mapType => ["Types::Hash.meta(of: ", this.dryType(mapType.values), ")", optional], enumType => ["Types::", this.nameForNamedType(enumType), optional], unionType => {
100
102
  const nullable = TypeUtils_1.nullableFromUnion(unionType);
101
103
  if (nullable !== null) {
102
104
  return [this.dryType(nullable), ".optional"];
@@ -307,7 +309,7 @@ class RubyRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
307
309
  this.indent(() => {
308
310
  const inits = [];
309
311
  this.forEachClassProperty(c, "none", (name, jsonName, p) => {
310
- const expression = this.toDynamic(p.type, ["@", name], p.isOptional);
312
+ const expression = this.toDynamic(p.type, name, p.isOptional);
311
313
  inits.push([[`"${stringEscape(jsonName)}"`], [" => ", expression, ","]]);
312
314
  });
313
315
  this.emitTable(inits);
@@ -376,9 +378,9 @@ class RubyRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
376
378
  this.emitBlock("def to_dynamic", () => {
377
379
  let first = true;
378
380
  this.forEachUnionMember(u, nonNulls, "none", null, (name, t) => {
379
- this.emitLine(first ? "if" : "elsif", " @", name, " != nil");
381
+ this.emitLine(first ? "if" : "elsif", " ", name, " != nil");
380
382
  this.indent(() => {
381
- this.emitLine(this.toDynamic(t, ["@", name]));
383
+ this.emitLine(this.toDynamic(t, name));
382
384
  });
383
385
  first = false;
384
386
  });
@@ -398,7 +400,7 @@ class RubyRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
398
400
  }
399
401
  emitTypesModule() {
400
402
  this.emitBlock(["module Types"], () => {
401
- this.emitLine("include Dry::Types.module");
403
+ this.emitLine("include Dry.Types(default: :nominal)");
402
404
  const declarations = [];
403
405
  if (this._options.strictness !== Strictness.None) {
404
406
  let has = { int: false, nil: false, bool: false, hash: false, string: false, double: false };
@@ -413,7 +415,7 @@ class RubyRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
413
415
  };
414
416
  });
415
417
  if (has.int)
416
- declarations.push([["Int"], [` = ${this._options.strictness}Int`]]);
418
+ declarations.push([["Integer"], [` = ${this._options.strictness}Integer`]]);
417
419
  if (this._options.strictness === Strictness.Strict) {
418
420
  if (has.nil)
419
421
  declarations.push([["Nil"], [` = ${this._options.strictness}Nil`]]);
@@ -427,7 +429,7 @@ class RubyRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
427
429
  if (has.double)
428
430
  declarations.push([
429
431
  ["Double"],
430
- [` = ${this._options.strictness}Float | ${this._options.strictness}Int`]
432
+ [` = ${this._options.strictness}Float | ${this._options.strictness}Integer`]
431
433
  ]);
432
434
  }
433
435
  this.forEachEnum("none", (enumType, enumName) => {
@@ -223,6 +223,7 @@ const kernel = [
223
223
  "module_eval",
224
224
  "module_exec",
225
225
  "name",
226
+ "new",
226
227
  "nil?",
227
228
  "object_id",
228
229
  "open",
@@ -291,7 +292,9 @@ exports.globals = kernel.concat(globalClasses);
291
292
  exports.reservedProperties = [
292
293
  "__id__",
293
294
  "__send__",
295
+ "break",
294
296
  "call",
297
+ "case",
295
298
  "class",
296
299
  "clone",
297
300
  "constrained_type",
@@ -319,6 +322,7 @@ exports.reservedProperties = [
319
322
  "meta",
320
323
  "method",
321
324
  "methods",
325
+ "next",
322
326
  "object_id",
323
327
  "optional",
324
328
  "options",
@@ -331,6 +335,7 @@ exports.reservedProperties = [
331
335
  "remove_instance_variable",
332
336
  "rule",
333
337
  "safe",
338
+ "self",
334
339
  "send",
335
340
  "singleton_class",
336
341
  "singleton_method",
@@ -345,6 +350,8 @@ exports.reservedProperties = [
345
350
  "try",
346
351
  "type",
347
352
  "untaint",
353
+ "undef",
348
354
  "untrust",
355
+ "while",
349
356
  "with"
350
357
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quicktype-core",
3
- "version": "7.0.21",
3
+ "version": "7.0.22",
4
4
  "description": "The quicktype engine as a library",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",
@@ -45,6 +45,6 @@
45
45
  "fs": false
46
46
  },
47
47
  "config": {
48
- "commit": "f27d5e096ad0c592d6b7aa50c4c56b310356754e"
48
+ "commit": "e6d9552bcb36d29258d8750515d2a0af310aefcd"
49
49
  }
50
50
  }