quicktype 17.0.6 → 18.0.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.
- package/dist/cli/CompressedJSONFromStream.js +26 -38
- package/dist/cli/GraphQLIntrospection.js +33 -41
- package/dist/cli/TypeSource.d.ts +1 -1
- package/dist/cli/URLGrammar.js +4 -3
- package/dist/cli/index.js +363 -364
- package/dist/quicktype-core/Annotation.js +2 -0
- package/dist/quicktype-core/ConvenienceRenderer.d.ts +17 -17
- package/dist/quicktype-core/ConvenienceRenderer.js +104 -81
- package/dist/quicktype-core/DateTime.js +1 -0
- package/dist/quicktype-core/DeclarationIR.d.ts +1 -1
- package/dist/quicktype-core/DeclarationIR.js +13 -10
- package/dist/quicktype-core/EncodedMarkovChain.js +1 -0
- package/dist/quicktype-core/GatherNames.js +47 -25
- package/dist/quicktype-core/Graph.d.ts +2 -2
- package/dist/quicktype-core/Graph.js +23 -19
- package/dist/quicktype-core/GraphRewriting.d.ts +2 -2
- package/dist/quicktype-core/GraphRewriting.js +65 -54
- package/dist/quicktype-core/MakeTransformations.js +23 -22
- package/dist/quicktype-core/MarkovChain.d.ts +3 -3
- package/dist/quicktype-core/MarkovChain.js +9 -8
- package/dist/quicktype-core/Messages.d.ts +3 -3
- package/dist/quicktype-core/Messages.js +8 -3
- package/dist/quicktype-core/Naming.d.ts +11 -11
- package/dist/quicktype-core/Naming.js +76 -61
- package/dist/quicktype-core/Renderer.d.ts +6 -6
- package/dist/quicktype-core/Renderer.js +34 -17
- package/dist/quicktype-core/RendererOptions.d.ts +5 -5
- package/dist/quicktype-core/RendererOptions.js +6 -3
- package/dist/quicktype-core/Run.d.ts +9 -9
- package/dist/quicktype-core/Run.js +72 -67
- package/dist/quicktype-core/Source.d.ts +3 -3
- package/dist/quicktype-core/Source.js +19 -18
- package/dist/quicktype-core/TargetLanguage.d.ts +10 -10
- package/dist/quicktype-core/TargetLanguage.js +6 -2
- package/dist/quicktype-core/Transformers.d.ts +25 -25
- package/dist/quicktype-core/Transformers.js +94 -66
- package/dist/quicktype-core/Type.d.ts +41 -43
- package/dist/quicktype-core/Type.js +96 -71
- package/dist/quicktype-core/TypeBuilder.d.ts +2 -2
- package/dist/quicktype-core/TypeBuilder.js +53 -47
- package/dist/quicktype-core/TypeGraph.d.ts +4 -4
- package/dist/quicktype-core/TypeGraph.js +49 -40
- package/dist/quicktype-core/TypeUtils.d.ts +2 -2
- package/dist/quicktype-core/TypeUtils.js +23 -22
- package/dist/quicktype-core/UnifyClasses.js +16 -12
- package/dist/quicktype-core/UnionBuilder.d.ts +3 -3
- package/dist/quicktype-core/UnionBuilder.js +33 -30
- package/dist/quicktype-core/attributes/AccessorNames.d.ts +2 -2
- package/dist/quicktype-core/attributes/AccessorNames.js +18 -17
- package/dist/quicktype-core/attributes/Constraints.d.ts +3 -3
- package/dist/quicktype-core/attributes/Constraints.js +8 -4
- package/dist/quicktype-core/attributes/Description.js +6 -5
- package/dist/quicktype-core/attributes/EnumValues.js +4 -3
- package/dist/quicktype-core/attributes/StringTypes.d.ts +1 -1
- package/dist/quicktype-core/attributes/StringTypes.js +24 -21
- package/dist/quicktype-core/attributes/TypeAttributes.d.ts +3 -3
- package/dist/quicktype-core/attributes/TypeAttributes.js +12 -10
- package/dist/quicktype-core/attributes/TypeNames.d.ts +9 -9
- package/dist/quicktype-core/attributes/TypeNames.js +49 -21
- package/dist/quicktype-core/attributes/URIAttributes.d.ts +1 -1
- package/dist/quicktype-core/attributes/URIAttributes.js +10 -6
- package/dist/quicktype-core/index.js +128 -125
- package/dist/quicktype-core/input/CompressedJSON.d.ts +7 -7
- package/dist/quicktype-core/input/CompressedJSON.js +49 -54
- package/dist/quicktype-core/input/FetchingJSONSchemaStore.js +5 -13
- package/dist/quicktype-core/input/Inference.d.ts +2 -2
- package/dist/quicktype-core/input/Inference.js +25 -17
- package/dist/quicktype-core/input/Inputs.d.ts +2 -2
- package/dist/quicktype-core/input/Inputs.js +38 -54
- package/dist/quicktype-core/input/JSONSchemaInput.d.ts +11 -11
- package/dist/quicktype-core/input/JSONSchemaInput.js +503 -523
- package/dist/quicktype-core/input/JSONSchemaStore.d.ts +1 -1
- package/dist/quicktype-core/input/JSONSchemaStore.js +24 -35
- package/dist/quicktype-core/input/PostmanCollection.js +2 -1
- package/dist/quicktype-core/input/io/NodeIO.js +55 -44
- package/dist/quicktype-core/input/io/get-stream/index.js +6 -2
- package/dist/quicktype-core/language/All.js +3 -2
- package/dist/quicktype-core/language/CPlusPlus.d.ts +8 -8
- package/dist/quicktype-core/language/CPlusPlus.js +185 -151
- package/dist/quicktype-core/language/CSharp.d.ts +7 -7
- package/dist/quicktype-core/language/CSharp.js +82 -72
- package/dist/quicktype-core/language/Crystal.d.ts +2 -2
- package/dist/quicktype-core/language/Crystal.js +18 -17
- package/dist/quicktype-core/language/Dart.d.ts +4 -4
- package/dist/quicktype-core/language/Dart.js +36 -34
- package/dist/quicktype-core/language/Elm.d.ts +6 -6
- package/dist/quicktype-core/language/Elm.js +47 -45
- package/dist/quicktype-core/language/Golang.d.ts +4 -4
- package/dist/quicktype-core/language/Golang.js +23 -20
- package/dist/quicktype-core/language/Haskell.d.ts +5 -5
- package/dist/quicktype-core/language/Haskell.js +25 -23
- package/dist/quicktype-core/language/JSONSchema.d.ts +3 -3
- package/dist/quicktype-core/language/JSONSchema.js +17 -16
- package/dist/quicktype-core/language/Java.d.ts +2 -2
- package/dist/quicktype-core/language/Java.js +97 -97
- package/dist/quicktype-core/language/JavaScript.d.ts +7 -7
- package/dist/quicktype-core/language/JavaScript.js +20 -18
- package/dist/quicktype-core/language/JavaScriptPropTypes.js +15 -13
- package/dist/quicktype-core/language/JavaScriptUnicodeMaps.js +12 -11
- package/dist/quicktype-core/language/Kotlin.d.ts +2 -2
- package/dist/quicktype-core/language/Kotlin.js +39 -37
- package/dist/quicktype-core/language/Objective-C.d.ts +3 -3
- package/dist/quicktype-core/language/Objective-C.js +45 -41
- package/dist/quicktype-core/language/Php.d.ts +2 -2
- package/dist/quicktype-core/language/Php.js +66 -41
- package/dist/quicktype-core/language/Pike.d.ts +1 -1
- package/dist/quicktype-core/language/Pike.js +18 -17
- package/dist/quicktype-core/language/Python.d.ts +8 -8
- package/dist/quicktype-core/language/Python.js +63 -64
- package/dist/quicktype-core/language/Rust.d.ts +2 -2
- package/dist/quicktype-core/language/Rust.js +21 -19
- package/dist/quicktype-core/language/Swift.d.ts +7 -7
- package/dist/quicktype-core/language/Swift.js +568 -565
- package/dist/quicktype-core/language/TypeScriptFlow.d.ts +7 -7
- package/dist/quicktype-core/language/TypeScriptFlow.js +28 -26
- package/dist/quicktype-core/language/ruby/index.d.ts +4 -4
- package/dist/quicktype-core/language/ruby/index.js +49 -24
- package/dist/quicktype-core/language/ruby/keywords.js +1 -0
- package/dist/quicktype-core/rewrites/CombineClasses.js +9 -8
- package/dist/quicktype-core/rewrites/ExpandStrings.d.ts +1 -1
- package/dist/quicktype-core/rewrites/ExpandStrings.js +18 -17
- package/dist/quicktype-core/rewrites/FlattenStrings.js +7 -6
- package/dist/quicktype-core/rewrites/FlattenUnions.js +9 -8
- package/dist/quicktype-core/rewrites/InferMaps.js +11 -10
- package/dist/quicktype-core/rewrites/ReplaceObjectType.js +8 -7
- package/dist/quicktype-core/rewrites/ResolveIntersections.js +68 -67
- package/dist/quicktype-core/support/Acronyms.js +3 -1
- package/dist/quicktype-core/support/Chance.js +10 -0
- package/dist/quicktype-core/support/Converters.js +1 -0
- package/dist/quicktype-core/support/Strings.d.ts +4 -4
- package/dist/quicktype-core/support/Strings.js +17 -16
- package/dist/quicktype-core/support/Support.d.ts +1 -1
- package/dist/quicktype-core/support/Support.js +30 -6
- package/dist/quicktype-graphql-input/GraphQLSchema.d.ts +4 -4
- package/dist/quicktype-graphql-input/GraphQLSchema.js +1 -0
- package/dist/quicktype-graphql-input/index.d.ts +1 -1
- package/dist/quicktype-graphql-input/index.js +229 -212
- package/dist/quicktype-typescript-input/index.js +28 -4
- package/package.json +24 -20
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JavaScriptPropTypesRenderer = exports.JavaScriptPropTypesTargetLanguage = exports.javaScriptPropTypesOptions = void 0;
|
|
3
4
|
const TargetLanguage_1 = require("../TargetLanguage");
|
|
4
5
|
const RendererOptions_1 = require("../RendererOptions");
|
|
5
6
|
const ConvenienceRenderer_1 = require("../ConvenienceRenderer");
|
|
@@ -14,8 +15,8 @@ const TypeUtils_1 = require("../TypeUtils");
|
|
|
14
15
|
const collection_utils_1 = require("collection-utils");
|
|
15
16
|
const Type_1 = require("../Type");
|
|
16
17
|
exports.javaScriptPropTypesOptions = {
|
|
17
|
-
acronymStyle: Acronyms_1.acronymOption(Acronyms_1.AcronymStyleOptions.Pascal),
|
|
18
|
-
converters: Converters_1.convertersOption(),
|
|
18
|
+
acronymStyle: (0, Acronyms_1.acronymOption)(Acronyms_1.AcronymStyleOptions.Pascal),
|
|
19
|
+
converters: (0, Converters_1.convertersOption)(),
|
|
19
20
|
moduleSystem: new RendererOptions_1.EnumOption("module-system", "Which module system to use", [
|
|
20
21
|
["common-js", false],
|
|
21
22
|
["es6", true]
|
|
@@ -29,23 +30,24 @@ class JavaScriptPropTypesTargetLanguage extends TargetLanguage_1.TargetLanguage
|
|
|
29
30
|
super(displayName, names, extension);
|
|
30
31
|
}
|
|
31
32
|
makeRenderer(renderContext, untypedOptionValues) {
|
|
32
|
-
return new JavaScriptPropTypesRenderer(this, renderContext, RendererOptions_1.getOptionValues(exports.javaScriptPropTypesOptions, untypedOptionValues));
|
|
33
|
+
return new JavaScriptPropTypesRenderer(this, renderContext, (0, RendererOptions_1.getOptionValues)(exports.javaScriptPropTypesOptions, untypedOptionValues));
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
36
|
exports.JavaScriptPropTypesTargetLanguage = JavaScriptPropTypesTargetLanguage;
|
|
36
|
-
const identityNamingFunction = Naming_1.funPrefixNamer("properties", s => s);
|
|
37
|
+
const identityNamingFunction = (0, Naming_1.funPrefixNamer)("properties", s => s);
|
|
37
38
|
class JavaScriptPropTypesRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
39
|
+
_jsOptions;
|
|
38
40
|
constructor(targetLanguage, renderContext, _jsOptions) {
|
|
39
41
|
super(targetLanguage, renderContext);
|
|
40
42
|
this._jsOptions = _jsOptions;
|
|
41
43
|
}
|
|
42
44
|
nameStyle(original, upper) {
|
|
43
|
-
const acronyms = Acronyms_1.acronymStyle(this._jsOptions.acronymStyle);
|
|
44
|
-
const words = __1.splitIntoWords(original);
|
|
45
|
-
return __1.combineWords(words, JavaScript_1.legalizeName, upper ? __1.firstUpperWordStyle : Strings_1.allLowerWordStyle, __1.firstUpperWordStyle, upper ? s => __1.capitalize(acronyms(s)) : Strings_1.allLowerWordStyle, acronyms, "", JavaScriptUnicodeMaps_1.isES3IdentifierStart);
|
|
45
|
+
const acronyms = (0, Acronyms_1.acronymStyle)(this._jsOptions.acronymStyle);
|
|
46
|
+
const words = (0, __1.splitIntoWords)(original);
|
|
47
|
+
return (0, __1.combineWords)(words, JavaScript_1.legalizeName, upper ? __1.firstUpperWordStyle : Strings_1.allLowerWordStyle, __1.firstUpperWordStyle, upper ? s => (0, __1.capitalize)(acronyms(s)) : Strings_1.allLowerWordStyle, acronyms, "", JavaScriptUnicodeMaps_1.isES3IdentifierStart);
|
|
46
48
|
}
|
|
47
49
|
makeNamedTypeNamer() {
|
|
48
|
-
return Naming_1.funPrefixNamer("types", s => this.nameStyle(s, true));
|
|
50
|
+
return (0, Naming_1.funPrefixNamer)("types", s => this.nameStyle(s, true));
|
|
49
51
|
}
|
|
50
52
|
namerForObjectProperty() {
|
|
51
53
|
return identityNamingFunction;
|
|
@@ -54,10 +56,10 @@ class JavaScriptPropTypesRenderer extends ConvenienceRenderer_1.ConvenienceRende
|
|
|
54
56
|
return null;
|
|
55
57
|
}
|
|
56
58
|
makeEnumCaseNamer() {
|
|
57
|
-
return Naming_1.funPrefixNamer("enum-cases", s => this.nameStyle(s, false));
|
|
59
|
+
return (0, Naming_1.funPrefixNamer)("enum-cases", s => this.nameStyle(s, false));
|
|
58
60
|
}
|
|
59
61
|
namedTypeToNameForTopLevel(type) {
|
|
60
|
-
return TypeUtils_1.directlyReachableSingleNamedType(type);
|
|
62
|
+
return (0, TypeUtils_1.directlyReachableSingleNamedType)(type);
|
|
61
63
|
}
|
|
62
64
|
makeNameForProperty(c, className, p, jsonName, _assignedName) {
|
|
63
65
|
// Ignore the assigned name
|
|
@@ -67,9 +69,9 @@ class JavaScriptPropTypesRenderer extends ConvenienceRenderer_1.ConvenienceRende
|
|
|
67
69
|
if (["class", "object", "enum"].indexOf(t.kind) >= 0) {
|
|
68
70
|
return ["_", this.nameForNamedType(t)];
|
|
69
71
|
}
|
|
70
|
-
const match = __1.matchType(t, _anyType => "PropTypes.any", _nullType => "PropTypes.any", _boolType => "PropTypes.bool", _integerType => "PropTypes.number", _doubleType => "PropTypes.number", _stringType => "PropTypes.string", arrayType => ["PropTypes.arrayOf(", this.typeMapTypeFor(arrayType.items, false), ")"], _classType => __1.panic("Should already be handled."), _mapType => "PropTypes.object", _enumType => __1.panic("Should already be handled."), unionType => {
|
|
72
|
+
const match = (0, __1.matchType)(t, _anyType => "PropTypes.any", _nullType => "PropTypes.any", _boolType => "PropTypes.bool", _integerType => "PropTypes.number", _doubleType => "PropTypes.number", _stringType => "PropTypes.string", arrayType => ["PropTypes.arrayOf(", this.typeMapTypeFor(arrayType.items, false), ")"], _classType => (0, __1.panic)("Should already be handled."), _mapType => "PropTypes.object", _enumType => (0, __1.panic)("Should already be handled."), unionType => {
|
|
71
73
|
const children = Array.from(unionType.getChildren()).map((type) => this.typeMapTypeFor(type, false));
|
|
72
|
-
return ["PropTypes.oneOfType([", ...collection_utils_1.arrayIntercalate(", ", children), "])"];
|
|
74
|
+
return ["PropTypes.oneOfType([", ...(0, collection_utils_1.arrayIntercalate)(", ", children), "])"];
|
|
73
75
|
}, _transformedStringType => {
|
|
74
76
|
return "PropTypes.string";
|
|
75
77
|
});
|
|
@@ -192,7 +194,7 @@ class JavaScriptPropTypesRenderer extends ConvenienceRenderer_1.ConvenienceRende
|
|
|
192
194
|
this.emitLine("_", name, " = PropTypes.shape({");
|
|
193
195
|
this.indent(() => {
|
|
194
196
|
this.forEachClassProperty(t, "none", (_, jsonName, property) => {
|
|
195
|
-
this.emitLine(`"${Strings_1.utf16StringEscape(jsonName)}"`, ": ", this.typeMapTypeForProperty(property), ",");
|
|
197
|
+
this.emitLine(`"${(0, Strings_1.utf16StringEscape)(jsonName)}"`, ": ", this.typeMapTypeForProperty(property), ",");
|
|
196
198
|
});
|
|
197
199
|
});
|
|
198
200
|
this.emitLine("});");
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Taken from https://github.com/Microsoft/TypeScript
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.isES3IdentifierPart = exports.isES3IdentifierStart = void 0;
|
|
4
5
|
function lookupInUnicodeMap(code, map) {
|
|
5
6
|
// Bail out quickly if it couldn't possibly be in the map.
|
|
6
7
|
if (code < map[0]) {
|
|
@@ -27,20 +28,20 @@ function lookupInUnicodeMap(code, map) {
|
|
|
27
28
|
return false;
|
|
28
29
|
}
|
|
29
30
|
function isES3IdentifierStart(ch) {
|
|
30
|
-
return ((ch >= 65 /* A */ && ch <= 90 /* Z */) ||
|
|
31
|
-
(ch >= 97 /* a */ && ch <= 122 /* z */) ||
|
|
32
|
-
ch === 36 /*
|
|
33
|
-
ch === 95 /* _ */ ||
|
|
34
|
-
(ch > 127 /* maxAsciiCharacter */ && lookupInUnicodeMap(ch, unicodeES3IdentifierStart)));
|
|
31
|
+
return ((ch >= 65 /* CharacterCodes.A */ && ch <= 90 /* CharacterCodes.Z */) ||
|
|
32
|
+
(ch >= 97 /* CharacterCodes.a */ && ch <= 122 /* CharacterCodes.z */) ||
|
|
33
|
+
ch === 36 /* CharacterCodes.$ */ ||
|
|
34
|
+
ch === 95 /* CharacterCodes._ */ ||
|
|
35
|
+
(ch > 127 /* CharacterCodes.maxAsciiCharacter */ && lookupInUnicodeMap(ch, unicodeES3IdentifierStart)));
|
|
35
36
|
}
|
|
36
37
|
exports.isES3IdentifierStart = isES3IdentifierStart;
|
|
37
38
|
function isES3IdentifierPart(ch) {
|
|
38
|
-
return ((ch >= 65 /* A */ && ch <= 90 /* Z */) ||
|
|
39
|
-
(ch >= 97 /* a */ && ch <= 122 /* z */) ||
|
|
40
|
-
(ch >= 48 /* _0 */ && ch <= 57 /* _9 */) ||
|
|
41
|
-
ch === 36 /*
|
|
42
|
-
ch === 95 /* _ */ ||
|
|
43
|
-
(ch > 127 /* maxAsciiCharacter */ && lookupInUnicodeMap(ch, unicodeES3IdentifierPart)));
|
|
39
|
+
return ((ch >= 65 /* CharacterCodes.A */ && ch <= 90 /* CharacterCodes.Z */) ||
|
|
40
|
+
(ch >= 97 /* CharacterCodes.a */ && ch <= 122 /* CharacterCodes.z */) ||
|
|
41
|
+
(ch >= 48 /* CharacterCodes._0 */ && ch <= 57 /* CharacterCodes._9 */) ||
|
|
42
|
+
ch === 36 /* CharacterCodes.$ */ ||
|
|
43
|
+
ch === 95 /* CharacterCodes._ */ ||
|
|
44
|
+
(ch > 127 /* CharacterCodes.maxAsciiCharacter */ && lookupInUnicodeMap(ch, unicodeES3IdentifierPart)));
|
|
44
45
|
}
|
|
45
46
|
exports.isES3IdentifierPart = isES3IdentifierPart;
|
|
46
47
|
/*
|
|
@@ -20,8 +20,8 @@ export declare const kotlinOptions: {
|
|
|
20
20
|
export declare class KotlinTargetLanguage extends TargetLanguage {
|
|
21
21
|
constructor();
|
|
22
22
|
protected getOptions(): Option<any>[];
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
get supportsOptionalClassProperties(): boolean;
|
|
24
|
+
get supportsUnionsWithBothNumberTypes(): boolean;
|
|
25
25
|
protected makeRenderer(renderContext: RenderContext, untypedOptionValues: {
|
|
26
26
|
[name: string]: any;
|
|
27
27
|
}): ConvenienceRenderer;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KotlinXRenderer = exports.KotlinJacksonRenderer = exports.KotlinKlaxonRenderer = exports.KotlinRenderer = exports.KotlinTargetLanguage = exports.kotlinOptions = exports.Framework = void 0;
|
|
3
4
|
const collection_utils_1 = require("collection-utils");
|
|
4
5
|
const Annotation_1 = require("../Annotation");
|
|
5
6
|
const ConvenienceRenderer_1 = require("../ConvenienceRenderer");
|
|
@@ -26,7 +27,7 @@ exports.kotlinOptions = {
|
|
|
26
27
|
["klaxon", Framework.Klaxon],
|
|
27
28
|
["kotlinx", Framework.KotlinX]
|
|
28
29
|
], "klaxon"),
|
|
29
|
-
acronymStyle: Acronyms_1.acronymOption(Acronyms_1.AcronymStyleOptions.Pascal),
|
|
30
|
+
acronymStyle: (0, Acronyms_1.acronymOption)(Acronyms_1.AcronymStyleOptions.Pascal),
|
|
30
31
|
packageName: new RendererOptions_1.StringOption("package", "Package", "PACKAGE", "quicktype")
|
|
31
32
|
};
|
|
32
33
|
class KotlinTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
@@ -43,7 +44,7 @@ class KotlinTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
|
43
44
|
return true;
|
|
44
45
|
}
|
|
45
46
|
makeRenderer(renderContext, untypedOptionValues) {
|
|
46
|
-
const options = RendererOptions_1.getOptionValues(exports.kotlinOptions, untypedOptionValues);
|
|
47
|
+
const options = (0, RendererOptions_1.getOptionValues)(exports.kotlinOptions, untypedOptionValues);
|
|
47
48
|
switch (options.framework) {
|
|
48
49
|
case Framework.None:
|
|
49
50
|
return new KotlinRenderer(this, renderContext, options);
|
|
@@ -54,7 +55,7 @@ class KotlinTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
|
54
55
|
case Framework.KotlinX:
|
|
55
56
|
return new KotlinXRenderer(this, renderContext, options);
|
|
56
57
|
default:
|
|
57
|
-
return Support_1.assertNever(options.framework);
|
|
58
|
+
return (0, Support_1.assertNever)(options.framework);
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
61
|
}
|
|
@@ -111,25 +112,26 @@ const keywords = [
|
|
|
111
112
|
"Klaxon"
|
|
112
113
|
];
|
|
113
114
|
function isPartCharacter(codePoint) {
|
|
114
|
-
return Strings_1.isLetterOrUnderscore(codePoint) || Strings_1.isNumeric(codePoint);
|
|
115
|
+
return (0, Strings_1.isLetterOrUnderscore)(codePoint) || (0, Strings_1.isNumeric)(codePoint);
|
|
115
116
|
}
|
|
116
117
|
function isStartCharacter(codePoint) {
|
|
117
|
-
return isPartCharacter(codePoint) && !Strings_1.isDigit(codePoint);
|
|
118
|
+
return isPartCharacter(codePoint) && !(0, Strings_1.isDigit)(codePoint);
|
|
118
119
|
}
|
|
119
|
-
const legalizeName = Strings_1.legalizeCharacters(isPartCharacter);
|
|
120
|
+
const legalizeName = (0, Strings_1.legalizeCharacters)(isPartCharacter);
|
|
120
121
|
function kotlinNameStyle(isUpper, original, acronymsStyle = Strings_1.allUpperWordStyle) {
|
|
121
|
-
const words = Strings_1.splitIntoWords(original);
|
|
122
|
-
return Strings_1.combineWords(words, legalizeName, isUpper ? Strings_1.firstUpperWordStyle : Strings_1.allLowerWordStyle, Strings_1.firstUpperWordStyle, isUpper ? Strings_1.allUpperWordStyle : Strings_1.allLowerWordStyle, acronymsStyle, "", isStartCharacter);
|
|
122
|
+
const words = (0, Strings_1.splitIntoWords)(original);
|
|
123
|
+
return (0, Strings_1.combineWords)(words, legalizeName, isUpper ? Strings_1.firstUpperWordStyle : Strings_1.allLowerWordStyle, Strings_1.firstUpperWordStyle, isUpper ? Strings_1.allUpperWordStyle : Strings_1.allLowerWordStyle, acronymsStyle, "", isStartCharacter);
|
|
123
124
|
}
|
|
124
125
|
function unicodeEscape(codePoint) {
|
|
125
|
-
return "\\u" + Strings_1.intToHex(codePoint, 4);
|
|
126
|
+
return "\\u" + (0, Strings_1.intToHex)(codePoint, 4);
|
|
126
127
|
}
|
|
127
|
-
const _stringEscape = Strings_1.utf32ConcatMap(Strings_1.escapeNonPrintableMapper(Strings_1.isPrintable, unicodeEscape));
|
|
128
|
+
const _stringEscape = (0, Strings_1.utf32ConcatMap)((0, Strings_1.escapeNonPrintableMapper)(Strings_1.isPrintable, unicodeEscape));
|
|
128
129
|
function stringEscape(s) {
|
|
129
130
|
// "$this" is a template string in Kotlin so we have to escape $
|
|
130
131
|
return _stringEscape(s).replace(/\$/g, "\\$");
|
|
131
132
|
}
|
|
132
133
|
class KotlinRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
134
|
+
_kotlinOptions;
|
|
133
135
|
constructor(targetLanguage, renderContext, _kotlinOptions) {
|
|
134
136
|
super(targetLanguage, renderContext);
|
|
135
137
|
this._kotlinOptions = _kotlinOptions;
|
|
@@ -150,16 +152,16 @@ class KotlinRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
150
152
|
return kotlinNameStyle(true, rawName);
|
|
151
153
|
}
|
|
152
154
|
makeNamedTypeNamer() {
|
|
153
|
-
return Naming_1.funPrefixNamer("upper", s => kotlinNameStyle(true, s, Acronyms_1.acronymStyle(this._kotlinOptions.acronymStyle)));
|
|
155
|
+
return (0, Naming_1.funPrefixNamer)("upper", s => kotlinNameStyle(true, s, (0, Acronyms_1.acronymStyle)(this._kotlinOptions.acronymStyle)));
|
|
154
156
|
}
|
|
155
157
|
namerForObjectProperty() {
|
|
156
|
-
return Naming_1.funPrefixNamer("lower", s => kotlinNameStyle(false, s, Acronyms_1.acronymStyle(this._kotlinOptions.acronymStyle)));
|
|
158
|
+
return (0, Naming_1.funPrefixNamer)("lower", s => kotlinNameStyle(false, s, (0, Acronyms_1.acronymStyle)(this._kotlinOptions.acronymStyle)));
|
|
157
159
|
}
|
|
158
160
|
makeUnionMemberNamer() {
|
|
159
|
-
return Naming_1.funPrefixNamer("upper", s => kotlinNameStyle(true, s) + "Value");
|
|
161
|
+
return (0, Naming_1.funPrefixNamer)("upper", s => kotlinNameStyle(true, s) + "Value");
|
|
160
162
|
}
|
|
161
163
|
makeEnumCaseNamer() {
|
|
162
|
-
return Naming_1.funPrefixNamer("upper", s => kotlinNameStyle(true, s, Acronyms_1.acronymStyle(this._kotlinOptions.acronymStyle)));
|
|
164
|
+
return (0, Naming_1.funPrefixNamer)("upper", s => kotlinNameStyle(true, s, (0, Acronyms_1.acronymStyle)(this._kotlinOptions.acronymStyle)));
|
|
163
165
|
}
|
|
164
166
|
emitDescriptionBlock(lines) {
|
|
165
167
|
this.emitCommentLines(lines, " * ", "/**", " */");
|
|
@@ -183,12 +185,12 @@ class KotlinRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
183
185
|
}
|
|
184
186
|
kotlinType(t, withIssues = false, noOptional = false) {
|
|
185
187
|
const optional = noOptional ? "" : "?";
|
|
186
|
-
return TypeUtils_1.matchType(t, _anyType => {
|
|
187
|
-
return Source_1.maybeAnnotated(withIssues, Annotation_1.anyTypeIssueAnnotation, this.anySourceType(optional));
|
|
188
|
+
return (0, TypeUtils_1.matchType)(t, _anyType => {
|
|
189
|
+
return (0, Source_1.maybeAnnotated)(withIssues, Annotation_1.anyTypeIssueAnnotation, this.anySourceType(optional));
|
|
188
190
|
}, _nullType => {
|
|
189
|
-
return Source_1.maybeAnnotated(withIssues, Annotation_1.nullTypeIssueAnnotation, this.anySourceType(optional));
|
|
191
|
+
return (0, Source_1.maybeAnnotated)(withIssues, Annotation_1.nullTypeIssueAnnotation, this.anySourceType(optional));
|
|
190
192
|
}, _boolType => "Boolean", _integerType => "Long", _doubleType => "Double", _stringType => "String", arrayType => this.arrayType(arrayType, withIssues), classType => this.nameForNamedType(classType), mapType => this.mapType(mapType, withIssues), enumType => this.nameForNamedType(enumType), unionType => {
|
|
191
|
-
const nullable = TypeUtils_1.nullableFromUnion(unionType);
|
|
193
|
+
const nullable = (0, TypeUtils_1.nullableFromUnion)(unionType);
|
|
192
194
|
if (nullable !== null)
|
|
193
195
|
return [this.kotlinType(nullable, withIssues), optional];
|
|
194
196
|
return this.nameForNamedType(unionType);
|
|
@@ -241,7 +243,7 @@ class KotlinRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
241
243
|
let count = c.getProperties().size;
|
|
242
244
|
let first = true;
|
|
243
245
|
this.forEachClassProperty(c, "none", (name, jsonName, p) => {
|
|
244
|
-
const nullable = p.type.kind === "union" && TypeUtils_1.nullableFromUnion(p.type) !== null;
|
|
246
|
+
const nullable = p.type.kind === "union" && (0, TypeUtils_1.nullableFromUnion)(p.type) !== null;
|
|
245
247
|
const nullableOrOptional = p.isOptional || p.type.kind === "null" || nullable;
|
|
246
248
|
const last = --count === 0;
|
|
247
249
|
let meta = [];
|
|
@@ -291,7 +293,7 @@ class KotlinRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
291
293
|
return "_" + kind;
|
|
292
294
|
}
|
|
293
295
|
this.emitDescription(this.descriptionForType(u));
|
|
294
|
-
const [maybeNull, nonNulls] = TypeUtils_1.removeNullFromUnion(u, sortBy);
|
|
296
|
+
const [maybeNull, nonNulls] = (0, TypeUtils_1.removeNullFromUnion)(u, sortBy);
|
|
295
297
|
this.emitClassAnnotations(u, unionName);
|
|
296
298
|
this.emitBlock(["sealed class ", unionName], () => {
|
|
297
299
|
{
|
|
@@ -336,29 +338,29 @@ class KotlinKlaxonRenderer extends KotlinRenderer {
|
|
|
336
338
|
super(targetLanguage, renderContext, _kotlinOptions);
|
|
337
339
|
}
|
|
338
340
|
unionMemberFromJsonValue(t, e) {
|
|
339
|
-
return TypeUtils_1.matchType(t, _anyType => [e, ".inside"], _nullType => "null", _boolType => [e, ".boolean"], _integerType => ["(", e, ".int?.toLong() ?: ", e, ".longValue)"], _doubleType => [e, ".double"], _stringType => [e, ".string"], arrayType => [e, ".array?.let { klaxon.parseFromJsonArray<", this.kotlinType(arrayType.items), ">(it) }"], _classType => [e, ".obj?.let { klaxon.parseFromJsonObject<", this.kotlinType(t), ">(it) }"], _mapType => [e, ".obj?.let { klaxon.parseFromJsonObject<", this.kotlinType(t), ">(it) }"], enumType => [e, ".string?.let { ", this.kotlinType(enumType), ".fromValue(it) }"], _unionType => Support_1.mustNotHappen());
|
|
341
|
+
return (0, TypeUtils_1.matchType)(t, _anyType => [e, ".inside"], _nullType => "null", _boolType => [e, ".boolean"], _integerType => ["(", e, ".int?.toLong() ?: ", e, ".longValue)"], _doubleType => [e, ".double"], _stringType => [e, ".string"], arrayType => [e, ".array?.let { klaxon.parseFromJsonArray<", this.kotlinType(arrayType.items), ">(it) }"], _classType => [e, ".obj?.let { klaxon.parseFromJsonObject<", this.kotlinType(t), ">(it) }"], _mapType => [e, ".obj?.let { klaxon.parseFromJsonObject<", this.kotlinType(t), ">(it) }"], enumType => [e, ".string?.let { ", this.kotlinType(enumType), ".fromValue(it) }"], _unionType => (0, Support_1.mustNotHappen)());
|
|
340
342
|
}
|
|
341
343
|
unionMemberJsonValueGuard(t, _e) {
|
|
342
|
-
return TypeUtils_1.matchType(t, _anyType => "is Any", _nullType => "null", _boolType => "is Boolean", _integerType => "is Int, is Long", _doubleType => "is Double", _stringType => "is String", _arrayType => "is JsonArray<*>",
|
|
344
|
+
return (0, TypeUtils_1.matchType)(t, _anyType => "is Any", _nullType => "null", _boolType => "is Boolean", _integerType => "is Int, is Long", _doubleType => "is Double", _stringType => "is String", _arrayType => "is JsonArray<*>",
|
|
343
345
|
// These could be stricter, but for now we don't allow maps
|
|
344
346
|
// and objects in the same union
|
|
345
347
|
_classType => "is JsonObject", _mapType => "is JsonObject",
|
|
346
348
|
// This could be stricter, but for now we don't allow strings
|
|
347
349
|
// and enums in the same union
|
|
348
|
-
_enumType => "is String", _unionType => Support_1.mustNotHappen());
|
|
350
|
+
_enumType => "is String", _unionType => (0, Support_1.mustNotHappen)());
|
|
349
351
|
}
|
|
350
352
|
emitUsageHeader() {
|
|
351
353
|
this.emitLine("// To parse the JSON, install Klaxon and do:");
|
|
352
354
|
this.emitLine("//");
|
|
353
355
|
this.forEachTopLevel("none", (_, name) => {
|
|
354
|
-
this.emitLine("// val ", Source_1.modifySource(Strings_1.camelCase, name), " = ", name, ".fromJson(jsonString)");
|
|
356
|
+
this.emitLine("// val ", (0, Source_1.modifySource)(Strings_1.camelCase, name), " = ", name, ".fromJson(jsonString)");
|
|
355
357
|
});
|
|
356
358
|
}
|
|
357
359
|
emitHeader() {
|
|
358
360
|
super.emitHeader();
|
|
359
361
|
this.emitLine("import com.beust.klaxon.*");
|
|
360
|
-
const hasUnions = collection_utils_1.iterableSome(this.typeGraph.allNamedTypes(), t => t instanceof Type_1.UnionType && TypeUtils_1.nullableFromUnion(t) === null);
|
|
361
|
-
const hasEmptyObjects = collection_utils_1.iterableSome(this.typeGraph.allNamedTypes(), c => c instanceof Type_1.ClassType && c.getProperties().size === 0);
|
|
362
|
+
const hasUnions = (0, collection_utils_1.iterableSome)(this.typeGraph.allNamedTypes(), t => t instanceof Type_1.UnionType && (0, TypeUtils_1.nullableFromUnion)(t) === null);
|
|
363
|
+
const hasEmptyObjects = (0, collection_utils_1.iterableSome)(this.typeGraph.allNamedTypes(), c => c instanceof Type_1.ClassType && c.getProperties().size === 0);
|
|
362
364
|
if (hasUnions || this.haveEnums || hasEmptyObjects) {
|
|
363
365
|
this.emitGenericConverter();
|
|
364
366
|
}
|
|
@@ -426,14 +428,14 @@ class KotlinKlaxonRenderer extends KotlinRenderer {
|
|
|
426
428
|
if (ignore) {
|
|
427
429
|
properties.push("ignored = true");
|
|
428
430
|
}
|
|
429
|
-
return properties.length === 0 ? undefined : ["@Json(", collection_utils_1.arrayIntercalate(", ", properties), ")"];
|
|
431
|
+
return properties.length === 0 ? undefined : ["@Json(", (0, collection_utils_1.arrayIntercalate)(", ", properties), ")"];
|
|
430
432
|
}
|
|
431
433
|
emitEmptyClassDefinition(c, className) {
|
|
432
434
|
this.emitDescription(this.descriptionForType(c));
|
|
433
435
|
this.emitLine("typealias ", className, " = JsonObject");
|
|
434
436
|
}
|
|
435
437
|
emitClassDefinitionMethods(c, className) {
|
|
436
|
-
const isTopLevel = collection_utils_1.iterableSome(this.topLevels, ([_, top]) => top === c);
|
|
438
|
+
const isTopLevel = (0, collection_utils_1.iterableSome)(this.topLevels, ([_, top]) => top === c);
|
|
437
439
|
if (isTopLevel) {
|
|
438
440
|
this.emitBlock(")", () => {
|
|
439
441
|
this.emitLine("public fun toJson() = klaxon.toJsonString(this)");
|
|
@@ -535,19 +537,19 @@ class KotlinJacksonRenderer extends KotlinRenderer {
|
|
|
535
537
|
super(targetLanguage, renderContext, _kotlinOptions);
|
|
536
538
|
}
|
|
537
539
|
unionMemberJsonValueGuard(t, _e) {
|
|
538
|
-
return TypeUtils_1.matchType(t, _anyType => "is Any", _nullType => "null", _boolType => "is BooleanNode", _integerType => "is IntNode, is LongNode", _doubleType => "is DoubleNode", _stringType => "is TextNode", _arrayType => "is ArrayNode",
|
|
540
|
+
return (0, TypeUtils_1.matchType)(t, _anyType => "is Any", _nullType => "null", _boolType => "is BooleanNode", _integerType => "is IntNode, is LongNode", _doubleType => "is DoubleNode", _stringType => "is TextNode", _arrayType => "is ArrayNode",
|
|
539
541
|
// These could be stricter, but for now we don't allow maps
|
|
540
542
|
// and objects in the same union
|
|
541
543
|
_classType => "is ObjectNode", _mapType => "is ObjectNode",
|
|
542
544
|
// This could be stricter, but for now we don't allow strings
|
|
543
545
|
// and enums in the same union
|
|
544
|
-
_enumType => "is TextNode", _unionType => Support_1.mustNotHappen());
|
|
546
|
+
_enumType => "is TextNode", _unionType => (0, Support_1.mustNotHappen)());
|
|
545
547
|
}
|
|
546
548
|
emitUsageHeader() {
|
|
547
549
|
this.emitLine("// To parse the JSON, install jackson-module-kotlin and do:");
|
|
548
550
|
this.emitLine("//");
|
|
549
551
|
this.forEachTopLevel("none", (_, name) => {
|
|
550
|
-
this.emitLine("// val ", Source_1.modifySource(Strings_1.camelCase, name), " = ", name, ".fromJson(jsonString)");
|
|
552
|
+
this.emitLine("// val ", (0, Source_1.modifySource)(Strings_1.camelCase, name), " = ", name, ".fromJson(jsonString)");
|
|
551
553
|
});
|
|
552
554
|
}
|
|
553
555
|
emitHeader() {
|
|
@@ -560,8 +562,8 @@ import com.fasterxml.jackson.databind.module.SimpleModule
|
|
|
560
562
|
import com.fasterxml.jackson.databind.node.*
|
|
561
563
|
import com.fasterxml.jackson.databind.ser.std.StdSerializer
|
|
562
564
|
import com.fasterxml.jackson.module.kotlin.*`);
|
|
563
|
-
const hasUnions = collection_utils_1.iterableSome(this.typeGraph.allNamedTypes(), t => t instanceof Type_1.UnionType && TypeUtils_1.nullableFromUnion(t) === null);
|
|
564
|
-
const hasEmptyObjects = collection_utils_1.iterableSome(this.typeGraph.allNamedTypes(), c => c instanceof Type_1.ClassType && c.getProperties().size === 0);
|
|
565
|
+
const hasUnions = (0, collection_utils_1.iterableSome)(this.typeGraph.allNamedTypes(), t => t instanceof Type_1.UnionType && (0, TypeUtils_1.nullableFromUnion)(t) === null);
|
|
566
|
+
const hasEmptyObjects = (0, collection_utils_1.iterableSome)(this.typeGraph.allNamedTypes(), c => c instanceof Type_1.ClassType && c.getProperties().size === 0);
|
|
565
567
|
if (hasUnions || this.haveEnums || hasEmptyObjects) {
|
|
566
568
|
this.emitGenericConverter();
|
|
567
569
|
}
|
|
@@ -635,8 +637,8 @@ import com.fasterxml.jackson.module.kotlin.*`);
|
|
|
635
637
|
propertyOpts.push("required=true");
|
|
636
638
|
}
|
|
637
639
|
if (propertyOpts.length > 0) {
|
|
638
|
-
properties.push(["@get:JsonProperty(", collection_utils_1.arrayIntercalate(", ", propertyOpts), ")"]);
|
|
639
|
-
properties.push(["@field:JsonProperty(", collection_utils_1.arrayIntercalate(", ", propertyOpts), ")"]);
|
|
640
|
+
properties.push(["@get:JsonProperty(", (0, collection_utils_1.arrayIntercalate)(", ", propertyOpts), ")"]);
|
|
641
|
+
properties.push(["@field:JsonProperty(", (0, collection_utils_1.arrayIntercalate)(", ", propertyOpts), ")"]);
|
|
640
642
|
}
|
|
641
643
|
if (ignore) {
|
|
642
644
|
properties.push("@get:JsonIgnore");
|
|
@@ -649,7 +651,7 @@ import com.fasterxml.jackson.module.kotlin.*`);
|
|
|
649
651
|
this.emitLine("typealias ", className, " = JsonNode");
|
|
650
652
|
}
|
|
651
653
|
emitClassDefinitionMethods(c, className) {
|
|
652
|
-
const isTopLevel = collection_utils_1.iterableSome(this.topLevels, ([_, top]) => top === c);
|
|
654
|
+
const isTopLevel = (0, collection_utils_1.iterableSome)(this.topLevels, ([_, top]) => top === c);
|
|
653
655
|
if (isTopLevel) {
|
|
654
656
|
this.emitBlock(")", () => {
|
|
655
657
|
this.emitLine("fun toJson() = mapper.writeValueAsString(this)");
|
|
@@ -785,7 +787,7 @@ class KotlinXRenderer extends KotlinRenderer {
|
|
|
785
787
|
this.forEachTopLevel("none", (_, name) => {
|
|
786
788
|
table.push([
|
|
787
789
|
"// val ",
|
|
788
|
-
Source_1.modifySource(Strings_1.camelCase, name),
|
|
790
|
+
(0, Source_1.modifySource)(Strings_1.camelCase, name),
|
|
789
791
|
` = json.parse(${this.sourcelikeToString(name)}.serializer(), jsonString)`
|
|
790
792
|
]);
|
|
791
793
|
});
|
|
@@ -5,8 +5,8 @@ import { Sourcelike } from "../Source";
|
|
|
5
5
|
import { ConvenienceRenderer, ForbiddenWordsInfo } from "../ConvenienceRenderer";
|
|
6
6
|
import { StringOption, BooleanOption, EnumOption, Option, OptionValues } from "../RendererOptions";
|
|
7
7
|
import { RenderContext } from "../Renderer";
|
|
8
|
-
export
|
|
9
|
-
export
|
|
8
|
+
export type MemoryAttribute = "assign" | "strong" | "copy";
|
|
9
|
+
export type OutputFeatures = {
|
|
10
10
|
interface: boolean;
|
|
11
11
|
implementation: boolean;
|
|
12
12
|
};
|
|
@@ -74,6 +74,6 @@ export declare class ObjectiveCRenderer extends ConvenienceRenderer {
|
|
|
74
74
|
private emitPseudoEnumInterface;
|
|
75
75
|
private emitPseudoEnumImplementation;
|
|
76
76
|
protected emitSourceStructure(proposedFilename: string): void;
|
|
77
|
-
private
|
|
77
|
+
private get needsMap();
|
|
78
78
|
protected emitMapFunction(): void;
|
|
79
79
|
}
|