quicktype-core 23.0.166 → 23.0.168

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,6 +1,6 @@
1
- import { type StringTypes } from "./attributes/StringTypes";
2
1
  import { type CombinationKind, type TypeAttributes } from "./attributes/TypeAttributes";
3
2
  import { ArrayType, type ClassProperty, ClassType, EnumType, MapType, ObjectType, type PrimitiveType, type SetOperationType, type Type, UnionType } from "./Type";
3
+ import { type StringTypes } from "./attributes/StringTypes";
4
4
  export declare function assertIsObject(t: Type): ObjectType;
5
5
  export declare function assertIsClass(t: Type): ClassType;
6
6
  export declare function setOperationMembersRecursively<T extends SetOperationType>(setOperations: T | T[], combinationKind: CombinationKind | undefined): [ReadonlySet<Type>, TypeAttributes];
package/dist/TypeUtils.js CHANGED
@@ -2,11 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.matchCompoundType = exports.matchType = exports.matchTypeExhaustive = exports.stringTypesForType = exports.directlyReachableSingleNamedType = exports.directlyReachableTypes = exports.separateNamedTypes = exports.isNamedType = exports.getNullAsOptional = exports.nonNullTypeCases = exports.nullableFromUnion = exports.removeNullFromType = exports.removeNullFromUnion = exports.isAnyOrNull = exports.combineTypeAttributesOfTypes = exports.makeGroupsToFlatten = exports.setOperationMembersRecursively = exports.assertIsClass = exports.assertIsObject = void 0;
4
4
  const collection_utils_1 = require("collection-utils");
5
- // eslint-disable-next-line import/no-cycle
6
- const StringTypes_1 = require("./attributes/StringTypes");
7
5
  const TypeAttributes_1 = require("./attributes/TypeAttributes");
8
6
  const Support_1 = require("./support/Support");
7
+ // eslint-disable-next-line import/no-cycle
9
8
  const Type_1 = require("./Type");
9
+ // String types should be imported last to avoid circular dependency issues.
10
+ // eslint-disable-next-line import/order
11
+ const StringTypes_1 = require("./attributes/StringTypes");
10
12
  function assertIsObject(t) {
11
13
  if (t instanceof Type_1.ObjectType) {
12
14
  return t;
@@ -24,7 +24,7 @@ import { type RenderContext } from "../../Renderer";
24
24
  import { EnumOption, type Option, StringOption } from "../../RendererOptions";
25
25
  import { type NamingStyle } from "../../support/Strings";
26
26
  import { TargetLanguage } from "../../TargetLanguage";
27
- import { type FixMeOptionsType, type FixMeOptionsAnyType } from "../../types";
27
+ import { type FixMeOptionsAnyType, type FixMeOptionsType } from "../../types";
28
28
  import { CJSONRenderer } from "./CJSONRenderer";
29
29
  export declare const cJSONOptions: {
30
30
  typeSourceStyle: EnumOption<boolean>;
@@ -71,7 +71,7 @@ class RustRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
71
71
  emitRenameAttribute(propName, jsonName, defaultNamingStyle, preferedNamingStyle) {
72
72
  const escapedName = (0, utils_1.rustStringEscape)(jsonName);
73
73
  const name = utils_1.namingStyles[defaultNamingStyle].fromParts(this.sourcelikeToString(propName).split(" "));
74
- const styledName = (0, utils_1.nameToNamingStyle)(name, preferedNamingStyle);
74
+ const styledName = (0, utils_1.nameWithNamingStyle)(name, preferedNamingStyle);
75
75
  const namesDiffer = escapedName !== styledName;
76
76
  if (namesDiffer) {
77
77
  this.emitLine('#[serde(rename = "', escapedName, '")]');
@@ -103,7 +103,7 @@ class RustRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
103
103
  });
104
104
  // Set the default naming style on the struct
105
105
  const defaultStyle = "snake_case";
106
- const preferedNamingStyle = (0, utils_1.getPreferedNamingStyle)(Object.values(propertiesNamingStyles).flat(), defaultStyle);
106
+ const preferedNamingStyle = (0, utils_1.getPreferredNamingStyle)(Object.values(propertiesNamingStyles).flat(), defaultStyle);
107
107
  if (preferedNamingStyle !== defaultStyle) {
108
108
  this.emitLine(`#[serde(rename_all = "${preferedNamingStyle}")]`);
109
109
  }
@@ -148,7 +148,7 @@ class RustRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
148
148
  });
149
149
  // Set the default naming style on the enum
150
150
  const defaultStyle = "PascalCase";
151
- const preferedNamingStyle = (0, utils_1.getPreferedNamingStyle)(Object.values(enumCasesNamingStyles).flat(), defaultStyle);
151
+ const preferedNamingStyle = (0, utils_1.getPreferredNamingStyle)(Object.values(enumCasesNamingStyles).flat(), defaultStyle);
152
152
  if (preferedNamingStyle !== defaultStyle) {
153
153
  this.emitLine(`#[serde(rename_all = "${preferedNamingStyle}")]`);
154
154
  }
@@ -7,18 +7,52 @@ export declare enum Visibility {
7
7
  Crate = "Crate",
8
8
  Public = "Public"
9
9
  }
10
- type NameToParts = (name: string) => string[];
11
- type PartsToName = (parts: string[]) => string;
12
- interface NamingStyle {
13
- fromParts: PartsToName;
14
- regex: RegExp;
15
- toParts: NameToParts;
16
- }
17
- export declare const namingStyles: Record<string, NamingStyle>;
10
+ export declare const namingStyles: {
11
+ readonly snake_case: {
12
+ readonly regex: RegExp;
13
+ readonly toParts: (name: string) => string[];
14
+ readonly fromParts: (parts: string[]) => string;
15
+ };
16
+ readonly SCREAMING_SNAKE_CASE: {
17
+ readonly regex: RegExp;
18
+ readonly toParts: (name: string) => string[];
19
+ readonly fromParts: (parts: string[]) => string;
20
+ };
21
+ readonly camelCase: {
22
+ readonly regex: RegExp;
23
+ readonly toParts: (name: string) => string[];
24
+ readonly fromParts: (parts: string[]) => string;
25
+ };
26
+ readonly PascalCase: {
27
+ readonly regex: RegExp;
28
+ readonly toParts: (name: string) => string[];
29
+ readonly fromParts: (parts: string[]) => string;
30
+ };
31
+ readonly "kebab-case": {
32
+ readonly regex: RegExp;
33
+ readonly toParts: (name: string) => string[];
34
+ readonly fromParts: (parts: string[]) => string;
35
+ };
36
+ readonly "SCREAMING-KEBAB-CASE": {
37
+ readonly regex: RegExp;
38
+ readonly toParts: (name: string) => string[];
39
+ readonly fromParts: (parts: string[]) => string;
40
+ };
41
+ readonly lowercase: {
42
+ readonly regex: RegExp;
43
+ readonly toParts: (name: string) => string[];
44
+ readonly fromParts: (parts: string[]) => string;
45
+ };
46
+ readonly UPPERCASE: {
47
+ readonly regex: RegExp;
48
+ readonly toParts: (name: string) => string[];
49
+ readonly fromParts: (parts: string[]) => string;
50
+ };
51
+ };
52
+ export type NamingStyleKey = keyof typeof namingStyles;
18
53
  export declare const snakeNamingFunction: import("../../Naming").Namer;
19
54
  export declare const camelNamingFunction: import("../../Naming").Namer;
20
55
  export declare const rustStringEscape: (s: string) => string;
21
- export declare function getPreferedNamingStyle(namingStyleOccurences: string[], defaultStyle: string): string;
22
- export declare function listMatchingNamingStyles(name: string): string[];
23
- export declare function nameToNamingStyle(name: string, style: string): string;
24
- export {};
56
+ export declare function getPreferredNamingStyle(namingStyleOccurences: string[], defaultStyle: NamingStyleKey): NamingStyleKey;
57
+ export declare function listMatchingNamingStyles(name: string): NamingStyleKey[];
58
+ export declare function nameWithNamingStyle(name: string, style: NamingStyleKey): string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.nameToNamingStyle = exports.listMatchingNamingStyles = exports.getPreferedNamingStyle = exports.rustStringEscape = exports.camelNamingFunction = exports.snakeNamingFunction = exports.namingStyles = exports.Visibility = exports.Density = void 0;
3
+ exports.nameWithNamingStyle = exports.listMatchingNamingStyles = exports.getPreferredNamingStyle = exports.rustStringEscape = exports.camelNamingFunction = exports.snakeNamingFunction = exports.namingStyles = exports.Visibility = exports.Density = void 0;
4
4
  const Naming_1 = require("../../Naming");
5
5
  const Strings_1 = require("../../support/Strings");
6
6
  var Density;
@@ -58,6 +58,7 @@ exports.namingStyles = {
58
58
  fromParts: (parts) => parts.map(p => p.toUpperCase()).join("")
59
59
  }
60
60
  };
61
+ exports.namingStyles;
61
62
  const isAsciiLetterOrUnderscoreOrDigit = (codePoint) => {
62
63
  if (!(0, Strings_1.isAscii)(codePoint)) {
63
64
  return false;
@@ -88,26 +89,22 @@ const standardUnicodeRustEscape = (codePoint) => {
88
89
  }
89
90
  };
90
91
  exports.rustStringEscape = (0, Strings_1.utf32ConcatMap)((0, Strings_1.escapeNonPrintableMapper)(Strings_1.isPrintable, standardUnicodeRustEscape));
91
- function getPreferedNamingStyle(namingStyleOccurences, defaultStyle) {
92
+ function getPreferredNamingStyle(namingStyleOccurences, defaultStyle) {
92
93
  const occurrences = Object.fromEntries(Object.keys(exports.namingStyles).map(key => [key, 0]));
93
94
  namingStyleOccurences.forEach(style => ++occurrences[style]);
94
95
  const max = Math.max(...Object.values(occurrences));
95
- const preferedStyles = Object.entries(occurrences)
96
- .filter(([_style, num]) => num === max)
97
- .map(([style, _num]) => style);
96
+ const preferedStyles = Object.entries(occurrences).flatMap(([style, num]) => num === max ? [style] : []);
98
97
  if (preferedStyles.includes(defaultStyle)) {
99
98
  return defaultStyle;
100
99
  }
101
100
  return preferedStyles[0];
102
101
  }
103
- exports.getPreferedNamingStyle = getPreferedNamingStyle;
102
+ exports.getPreferredNamingStyle = getPreferredNamingStyle;
104
103
  function listMatchingNamingStyles(name) {
105
- return Object.entries(exports.namingStyles)
106
- .filter(([_, { regex }]) => regex.test(name))
107
- .map(([namingStyle, _]) => namingStyle);
104
+ return Object.entries(exports.namingStyles).flatMap(([namingStyleKey, { regex }]) => regex.test(name) ? [namingStyleKey] : []);
108
105
  }
109
106
  exports.listMatchingNamingStyles = listMatchingNamingStyles;
110
- function nameToNamingStyle(name, style) {
107
+ function nameWithNamingStyle(name, style) {
111
108
  if (exports.namingStyles[style].regex.test(name)) {
112
109
  return name;
113
110
  }
@@ -117,4 +114,4 @@ function nameToNamingStyle(name, style) {
117
114
  }
118
115
  return exports.namingStyles[style].fromParts(exports.namingStyles[fromStyle].toParts(name));
119
116
  }
120
- exports.nameToNamingStyle = nameToNamingStyle;
117
+ exports.nameWithNamingStyle = nameWithNamingStyle;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quicktype-core",
3
- "version": "23.0.166",
3
+ "version": "23.0.168",
4
4
  "description": "The quicktype engine as a library",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",