quicktype-core 23.0.7 → 23.0.9
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/index.d.ts +2 -0
- package/dist/index.js +9 -1
- package/dist/language/All.js +4 -0
- package/dist/language/CPlusPlus.js +1 -1
- package/dist/language/Scala3.d.ts +77 -0
- package/dist/language/Scala3.js +586 -0
- package/dist/language/Smithy4s.d.ts +53 -0
- package/dist/language/Smithy4s.js +390 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -39,6 +39,8 @@ export { JavaScriptPropTypesTargetLanguage, JavaScriptPropTypesRenderer, javaScr
|
|
|
39
39
|
export { TypeScriptTargetLanguage, TypeScriptRenderer, FlowTargetLanguage, FlowRenderer, tsFlowOptions } from "./language/TypeScriptFlow";
|
|
40
40
|
export { SwiftTargetLanguage, SwiftRenderer, swiftOptions } from "./language/Swift";
|
|
41
41
|
export { KotlinTargetLanguage, KotlinRenderer, kotlinOptions } from "./language/Kotlin";
|
|
42
|
+
export { Scala3TargetLanguage, Scala3Renderer, scala3Options } from "./language/Scala3";
|
|
43
|
+
export { SmithyTargetLanguage, Smithy4sRenderer, SmithyOptions } from "./language/Smithy4s";
|
|
42
44
|
export { ElmTargetLanguage, ElmRenderer, elmOptions } from "./language/Elm";
|
|
43
45
|
export { JSONSchemaTargetLanguage, JSONSchemaRenderer } from "./language/JSONSchema";
|
|
44
46
|
export { RustTargetLanguage, RustRenderer, rustOptions } from "./language/Rust";
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ClassType = exports.ArrayType = exports.PrimitiveType = exports.Type = exports.messageAssert = exports.messageError = exports.QuickTypeError = exports.trainMarkovChain = exports.isLetterOrDigit = exports.legalizeCharacters = exports.allUpperWordStyle = exports.firstUpperWordStyle = exports.combineWords = exports.capitalize = exports.splitIntoWords = exports.inflateBase64 = exports.checkArray = exports.checkStringMap = exports.parseJSON = exports.assertNever = exports.defined = exports.assert = exports.panic = exports.IssueAnnotationData = exports.Namer = exports.funPrefixNamer = exports.Name = exports.parenIfNeeded = exports.singleWord = exports.modifySource = exports.languageNamed = exports.defaultTargetLanguages = exports.TargetLanguage = exports.getOptionValues = exports.Option = exports.Ref = exports.JSONSchemaInput = exports.jsonInputForTargetLanguage = exports.JSONInput = exports.InputData = exports.CompressedJSON = exports.inferenceFlagsObject = exports.defaultInferenceFlags = exports.inferenceFlagNames = exports.inferenceFlags = exports.combineRenderResults = exports.quicktype = exports.quicktypeMultiFileSync = exports.quicktypeMultiFile = exports.getTargetLanguage = void 0;
|
|
4
4
|
exports.TypeScriptRenderer = exports.TypeScriptTargetLanguage = exports.javaScriptPropTypesOptions = exports.JavaScriptPropTypesRenderer = exports.JavaScriptPropTypesTargetLanguage = exports.javaScriptOptions = exports.JavaScriptRenderer = exports.JavaScriptTargetLanguage = exports.javaOptions = exports.JavaRenderer = exports.JavaTargetLanguage = exports.objcOptions = exports.ObjectiveCRenderer = exports.ObjectiveCTargetLanguage = exports.goOptions = exports.GoRenderer = exports.GoTargetLanguage = exports.pythonOptions = exports.PythonRenderer = exports.PythonTargetLanguage = exports.CSharpRenderer = exports.cSharpOptions = exports.CSharpTargetLanguage = exports.cPlusPlusOptions = exports.CPlusPlusRenderer = exports.CPlusPlusTargetLanguage = exports.uriTypeAttributeKind = exports.ConvenienceRenderer = exports.nullableFromUnion = exports.matchType = exports.removeNullFromUnion = exports.StringTypes = exports.namesTypeAttributeKind = exports.makeNamesTypeAttributes = exports.TypeNames = exports.emptyTypeAttributes = exports.TypeAttributeKind = exports.derefTypeRef = exports.TypeBuilder = exports.sourcesFromPostmanCollection = exports.JSONSchemaStore = exports.FetchingJSONSchemaStore = exports.readFromFileOrURL = exports.readableFromFileOrURL = exports.getStream = exports.ObjectType = exports.UnionType = exports.MapType = exports.EnumType = exports.ClassProperty = void 0;
|
|
5
|
-
exports.dartOptions = exports.DartRenderer = exports.DartTargetLanguage = exports.haskellOptions = exports.HaskellRenderer = exports.HaskellTargetLanguage = exports.CrystalRenderer = exports.CrystalTargetLanguage = exports.rubyOptions = exports.RubyRenderer = exports.RubyTargetLanguage = exports.rustOptions = exports.RustRenderer = exports.RustTargetLanguage = exports.JSONSchemaRenderer = exports.JSONSchemaTargetLanguage = exports.elmOptions = exports.ElmRenderer = exports.ElmTargetLanguage = exports.kotlinOptions = exports.KotlinRenderer = exports.KotlinTargetLanguage = exports.swiftOptions = exports.SwiftRenderer = exports.SwiftTargetLanguage = exports.tsFlowOptions = exports.FlowRenderer = exports.FlowTargetLanguage = void 0;
|
|
5
|
+
exports.dartOptions = exports.DartRenderer = exports.DartTargetLanguage = exports.haskellOptions = exports.HaskellRenderer = exports.HaskellTargetLanguage = exports.CrystalRenderer = exports.CrystalTargetLanguage = exports.rubyOptions = exports.RubyRenderer = exports.RubyTargetLanguage = exports.rustOptions = exports.RustRenderer = exports.RustTargetLanguage = exports.JSONSchemaRenderer = exports.JSONSchemaTargetLanguage = exports.elmOptions = exports.ElmRenderer = exports.ElmTargetLanguage = exports.SmithyOptions = exports.Smithy4sRenderer = exports.SmithyTargetLanguage = exports.scala3Options = exports.Scala3Renderer = exports.Scala3TargetLanguage = exports.kotlinOptions = exports.KotlinRenderer = exports.KotlinTargetLanguage = exports.swiftOptions = exports.SwiftRenderer = exports.SwiftTargetLanguage = exports.tsFlowOptions = exports.FlowRenderer = exports.FlowTargetLanguage = void 0;
|
|
6
6
|
var Run_1 = require("./Run");
|
|
7
7
|
Object.defineProperty(exports, "getTargetLanguage", { enumerable: true, get: function () { return Run_1.getTargetLanguage; } });
|
|
8
8
|
Object.defineProperty(exports, "quicktypeMultiFile", { enumerable: true, get: function () { return Run_1.quicktypeMultiFile; } });
|
|
@@ -152,6 +152,14 @@ var Kotlin_1 = require("./language/Kotlin");
|
|
|
152
152
|
Object.defineProperty(exports, "KotlinTargetLanguage", { enumerable: true, get: function () { return Kotlin_1.KotlinTargetLanguage; } });
|
|
153
153
|
Object.defineProperty(exports, "KotlinRenderer", { enumerable: true, get: function () { return Kotlin_1.KotlinRenderer; } });
|
|
154
154
|
Object.defineProperty(exports, "kotlinOptions", { enumerable: true, get: function () { return Kotlin_1.kotlinOptions; } });
|
|
155
|
+
var Scala3_1 = require("./language/Scala3");
|
|
156
|
+
Object.defineProperty(exports, "Scala3TargetLanguage", { enumerable: true, get: function () { return Scala3_1.Scala3TargetLanguage; } });
|
|
157
|
+
Object.defineProperty(exports, "Scala3Renderer", { enumerable: true, get: function () { return Scala3_1.Scala3Renderer; } });
|
|
158
|
+
Object.defineProperty(exports, "scala3Options", { enumerable: true, get: function () { return Scala3_1.scala3Options; } });
|
|
159
|
+
var Smithy4s_1 = require("./language/Smithy4s");
|
|
160
|
+
Object.defineProperty(exports, "SmithyTargetLanguage", { enumerable: true, get: function () { return Smithy4s_1.SmithyTargetLanguage; } });
|
|
161
|
+
Object.defineProperty(exports, "Smithy4sRenderer", { enumerable: true, get: function () { return Smithy4s_1.Smithy4sRenderer; } });
|
|
162
|
+
Object.defineProperty(exports, "SmithyOptions", { enumerable: true, get: function () { return Smithy4s_1.SmithyOptions; } });
|
|
155
163
|
var Elm_1 = require("./language/Elm");
|
|
156
164
|
Object.defineProperty(exports, "ElmTargetLanguage", { enumerable: true, get: function () { return Elm_1.ElmTargetLanguage; } });
|
|
157
165
|
Object.defineProperty(exports, "ElmRenderer", { enumerable: true, get: function () { return Elm_1.ElmRenderer; } });
|
package/dist/language/All.js
CHANGED
|
@@ -12,6 +12,8 @@ const JavaScriptPropTypes_1 = require("./JavaScriptPropTypes");
|
|
|
12
12
|
const TypeScriptFlow_1 = require("./TypeScriptFlow");
|
|
13
13
|
const Swift_1 = require("./Swift");
|
|
14
14
|
const Kotlin_1 = require("./Kotlin");
|
|
15
|
+
const Scala3_1 = require("./Scala3");
|
|
16
|
+
const Smithy4s_1 = require("./Smithy4s");
|
|
15
17
|
const Elm_1 = require("./Elm");
|
|
16
18
|
const JSONSchema_1 = require("./JSONSchema");
|
|
17
19
|
const Rust_1 = require("./Rust");
|
|
@@ -35,6 +37,8 @@ exports.all = [
|
|
|
35
37
|
new JavaScriptPropTypes_1.JavaScriptPropTypesTargetLanguage(),
|
|
36
38
|
new TypeScriptFlow_1.FlowTargetLanguage(),
|
|
37
39
|
new Swift_1.SwiftTargetLanguage(),
|
|
40
|
+
new Scala3_1.Scala3TargetLanguage(),
|
|
41
|
+
new Smithy4s_1.SmithyTargetLanguage(),
|
|
38
42
|
new Kotlin_1.KotlinTargetLanguage(),
|
|
39
43
|
new Elm_1.ElmTargetLanguage(),
|
|
40
44
|
new JSONSchema_1.JSONSchemaTargetLanguage(),
|
|
@@ -1654,7 +1654,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1654
1654
|
optionalMacroName += "_";
|
|
1655
1655
|
});
|
|
1656
1656
|
untypedMacroName += "HELPER";
|
|
1657
|
-
|
|
1657
|
+
optionalMacroName += "HELPER";
|
|
1658
1658
|
this.emitLine("#ifndef " + untypedMacroName);
|
|
1659
1659
|
this.emitLine("#define " + untypedMacroName);
|
|
1660
1660
|
this.emitBlock(["inline json get_untyped(", this.withConst("json"), " & j, ", this.withConst("char"), " * property)"], false, () => {
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { ConvenienceRenderer, ForbiddenWordsInfo } from "../ConvenienceRenderer";
|
|
2
|
+
import { Name, Namer } from "../Naming";
|
|
3
|
+
import { EnumOption, Option, StringOption, OptionValues } from "../RendererOptions";
|
|
4
|
+
import { Sourcelike } from "../Source";
|
|
5
|
+
import { TargetLanguage } from "../TargetLanguage";
|
|
6
|
+
import { ArrayType, ClassType, EnumType, MapType, ObjectType, Type, UnionType } from "../Type";
|
|
7
|
+
import { RenderContext } from "../Renderer";
|
|
8
|
+
export declare enum Framework {
|
|
9
|
+
None = 0,
|
|
10
|
+
Upickle = 1,
|
|
11
|
+
Circe = 2
|
|
12
|
+
}
|
|
13
|
+
export declare const scala3Options: {
|
|
14
|
+
framework: EnumOption<Framework>;
|
|
15
|
+
packageName: StringOption;
|
|
16
|
+
};
|
|
17
|
+
export declare class Scala3Renderer extends ConvenienceRenderer {
|
|
18
|
+
protected readonly _scalaOptions: OptionValues<typeof scala3Options>;
|
|
19
|
+
constructor(targetLanguage: TargetLanguage, renderContext: RenderContext, _scalaOptions: OptionValues<typeof scala3Options>);
|
|
20
|
+
protected forbiddenNamesForGlobalNamespace(): string[];
|
|
21
|
+
protected forbiddenForObjectProperties(_: ObjectType, _classNamed: Name): ForbiddenWordsInfo;
|
|
22
|
+
protected forbiddenForEnumCases(_: EnumType, _enumName: Name): ForbiddenWordsInfo;
|
|
23
|
+
protected forbiddenForUnionMembers(_u: UnionType, _unionName: Name): ForbiddenWordsInfo;
|
|
24
|
+
protected topLevelNameStyle(rawName: string): string;
|
|
25
|
+
protected makeNamedTypeNamer(): Namer;
|
|
26
|
+
protected namerForObjectProperty(): Namer;
|
|
27
|
+
protected makeUnionMemberNamer(): Namer;
|
|
28
|
+
protected makeEnumCaseNamer(): Namer;
|
|
29
|
+
protected emitDescriptionBlock(lines: Sourcelike[]): void;
|
|
30
|
+
protected emitBlock(line: Sourcelike, f: () => void, delimiter?: "curly" | "paren" | "lambda" | "none"): void;
|
|
31
|
+
protected anySourceType(optional: boolean): Sourcelike;
|
|
32
|
+
protected arrayType(arrayType: ArrayType, withIssues?: boolean): Sourcelike;
|
|
33
|
+
protected mapType(mapType: MapType, withIssues?: boolean): Sourcelike;
|
|
34
|
+
protected scalaType(t: Type, withIssues?: boolean, noOptional?: boolean): Sourcelike;
|
|
35
|
+
protected emitUsageHeader(): void;
|
|
36
|
+
protected emitHeader(): void;
|
|
37
|
+
protected emitTopLevelArray(t: ArrayType, name: Name): void;
|
|
38
|
+
protected emitTopLevelMap(t: MapType, name: Name): void;
|
|
39
|
+
protected emitEmptyClassDefinition(c: ClassType, className: Name): void;
|
|
40
|
+
protected emitClassDefinition(c: ClassType, className: Name): void;
|
|
41
|
+
protected emitClassDefinitionMethods(): void;
|
|
42
|
+
protected emitEnumDefinition(e: EnumType, enumName: Name): void;
|
|
43
|
+
protected emitUnionDefinition(u: UnionType, unionName: Name): void;
|
|
44
|
+
protected emitSourceStructure(): void;
|
|
45
|
+
}
|
|
46
|
+
export declare class UpickleRenderer extends Scala3Renderer {
|
|
47
|
+
protected emitClassDefinitionMethods(): void;
|
|
48
|
+
protected emitHeader(): void;
|
|
49
|
+
}
|
|
50
|
+
export declare class Smithy4sRenderer extends Scala3Renderer {
|
|
51
|
+
protected emitHeader(): void;
|
|
52
|
+
protected emitTopLevelArray(t: ArrayType, name: Name): void;
|
|
53
|
+
protected emitTopLevelMap(t: MapType, name: Name): void;
|
|
54
|
+
protected emitEmptyClassDefinition(c: ClassType, className: Name): void;
|
|
55
|
+
protected emitEnumDefinition(e: EnumType, enumName: Name): void;
|
|
56
|
+
}
|
|
57
|
+
export declare class CirceRenderer extends Scala3Renderer {
|
|
58
|
+
seenUnionTypes: Array<string>;
|
|
59
|
+
protected circeEncoderForType(t: Type, _?: boolean, noOptional?: boolean, paramName?: string): Sourcelike;
|
|
60
|
+
protected emitEmptyClassDefinition(c: ClassType, className: Name): void;
|
|
61
|
+
protected anySourceType(optional: boolean): Sourcelike;
|
|
62
|
+
protected emitClassDefinitionMethods(): void;
|
|
63
|
+
protected emitEnumDefinition(e: EnumType, enumName: Name): void;
|
|
64
|
+
protected emitHeader(): void;
|
|
65
|
+
protected emitTopLevelArray(t: ArrayType, name: Name): void;
|
|
66
|
+
protected emitTopLevelMap(t: MapType, name: Name): void;
|
|
67
|
+
protected emitUnionDefinition(u: UnionType, unionName: Name): void;
|
|
68
|
+
}
|
|
69
|
+
export declare class Scala3TargetLanguage extends TargetLanguage {
|
|
70
|
+
constructor();
|
|
71
|
+
protected getOptions(): Option<any>[];
|
|
72
|
+
get supportsOptionalClassProperties(): boolean;
|
|
73
|
+
get supportsUnionsWithBothNumberTypes(): boolean;
|
|
74
|
+
protected makeRenderer(renderContext: RenderContext, untypedOptionValues: {
|
|
75
|
+
[name: string]: any;
|
|
76
|
+
}): ConvenienceRenderer;
|
|
77
|
+
}
|
|
@@ -0,0 +1,586 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Scala3TargetLanguage = exports.CirceRenderer = exports.Smithy4sRenderer = exports.UpickleRenderer = exports.Scala3Renderer = exports.scala3Options = exports.Framework = void 0;
|
|
4
|
+
const Annotation_1 = require("../Annotation");
|
|
5
|
+
const ConvenienceRenderer_1 = require("../ConvenienceRenderer");
|
|
6
|
+
const Naming_1 = require("../Naming");
|
|
7
|
+
const RendererOptions_1 = require("../RendererOptions");
|
|
8
|
+
const Source_1 = require("../Source");
|
|
9
|
+
const Strings_1 = require("../support/Strings");
|
|
10
|
+
const Support_1 = require("../support/Support");
|
|
11
|
+
const TargetLanguage_1 = require("../TargetLanguage");
|
|
12
|
+
const Type_1 = require("../Type");
|
|
13
|
+
const TypeUtils_1 = require("../TypeUtils");
|
|
14
|
+
var Framework;
|
|
15
|
+
(function (Framework) {
|
|
16
|
+
Framework[Framework["None"] = 0] = "None";
|
|
17
|
+
Framework[Framework["Upickle"] = 1] = "Upickle";
|
|
18
|
+
Framework[Framework["Circe"] = 2] = "Circe";
|
|
19
|
+
})(Framework = exports.Framework || (exports.Framework = {}));
|
|
20
|
+
exports.scala3Options = {
|
|
21
|
+
framework: new RendererOptions_1.EnumOption("framework", "Serialization framework", [
|
|
22
|
+
["just-types", Framework.None],
|
|
23
|
+
["circe", Framework.Circe],
|
|
24
|
+
["upickle", Framework.Upickle],
|
|
25
|
+
], undefined),
|
|
26
|
+
packageName: new RendererOptions_1.StringOption("package", "Package", "PACKAGE", "quicktype")
|
|
27
|
+
};
|
|
28
|
+
// Use backticks for param names with symbols
|
|
29
|
+
const invalidSymbols = [
|
|
30
|
+
":",
|
|
31
|
+
"-",
|
|
32
|
+
"+",
|
|
33
|
+
"!",
|
|
34
|
+
"@",
|
|
35
|
+
"#",
|
|
36
|
+
"$",
|
|
37
|
+
"%",
|
|
38
|
+
"^",
|
|
39
|
+
"&",
|
|
40
|
+
"*",
|
|
41
|
+
"(",
|
|
42
|
+
")",
|
|
43
|
+
">",
|
|
44
|
+
"<",
|
|
45
|
+
"/",
|
|
46
|
+
";",
|
|
47
|
+
"'",
|
|
48
|
+
'"',
|
|
49
|
+
"{",
|
|
50
|
+
"}",
|
|
51
|
+
":",
|
|
52
|
+
"~",
|
|
53
|
+
"`",
|
|
54
|
+
"."
|
|
55
|
+
];
|
|
56
|
+
const keywords = [
|
|
57
|
+
"abstract",
|
|
58
|
+
"case",
|
|
59
|
+
"catch",
|
|
60
|
+
"class",
|
|
61
|
+
"def",
|
|
62
|
+
"do",
|
|
63
|
+
"else",
|
|
64
|
+
"enum",
|
|
65
|
+
"extends",
|
|
66
|
+
"export",
|
|
67
|
+
"false",
|
|
68
|
+
"final",
|
|
69
|
+
"finally",
|
|
70
|
+
"for",
|
|
71
|
+
"forSome",
|
|
72
|
+
"if",
|
|
73
|
+
"implicit",
|
|
74
|
+
"import",
|
|
75
|
+
"lazy",
|
|
76
|
+
"match",
|
|
77
|
+
"new",
|
|
78
|
+
"null",
|
|
79
|
+
"object",
|
|
80
|
+
"override",
|
|
81
|
+
"package",
|
|
82
|
+
"private",
|
|
83
|
+
"protected",
|
|
84
|
+
"return",
|
|
85
|
+
"sealed",
|
|
86
|
+
"super",
|
|
87
|
+
"this",
|
|
88
|
+
"then",
|
|
89
|
+
"throw",
|
|
90
|
+
"trait",
|
|
91
|
+
"try",
|
|
92
|
+
"true",
|
|
93
|
+
"type",
|
|
94
|
+
"val",
|
|
95
|
+
"var",
|
|
96
|
+
"while",
|
|
97
|
+
"with",
|
|
98
|
+
"yield",
|
|
99
|
+
"Any",
|
|
100
|
+
"Boolean",
|
|
101
|
+
"Double",
|
|
102
|
+
"Float",
|
|
103
|
+
"Long",
|
|
104
|
+
"Int",
|
|
105
|
+
"Short",
|
|
106
|
+
"System",
|
|
107
|
+
"Byte",
|
|
108
|
+
"String",
|
|
109
|
+
"Array",
|
|
110
|
+
"List",
|
|
111
|
+
"Map",
|
|
112
|
+
"Enum"
|
|
113
|
+
];
|
|
114
|
+
/**
|
|
115
|
+
* Check if given parameter name should be wrapped in a backtick
|
|
116
|
+
* @param paramName
|
|
117
|
+
*/
|
|
118
|
+
const shouldAddBacktick = (paramName) => {
|
|
119
|
+
return keywords.some(s => paramName === s) || invalidSymbols.some(s => paramName.includes(s)) || !isNaN(+parseFloat(paramName)) || !isNaN(parseInt(paramName.charAt(0)));
|
|
120
|
+
};
|
|
121
|
+
const wrapOption = (s, optional) => {
|
|
122
|
+
if (optional) {
|
|
123
|
+
return "Option[" + s + "]";
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
return s;
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
function isPartCharacter(codePoint) {
|
|
130
|
+
return (0, Strings_1.isLetterOrUnderscore)(codePoint) || (0, Strings_1.isNumeric)(codePoint);
|
|
131
|
+
}
|
|
132
|
+
function isStartCharacter(codePoint) {
|
|
133
|
+
return isPartCharacter(codePoint) && !(0, Strings_1.isDigit)(codePoint);
|
|
134
|
+
}
|
|
135
|
+
const legalizeName = (0, Strings_1.legalizeCharacters)(isPartCharacter);
|
|
136
|
+
function scalaNameStyle(isUpper, original) {
|
|
137
|
+
const words = (0, Strings_1.splitIntoWords)(original);
|
|
138
|
+
return (0, Strings_1.combineWords)(words, legalizeName, isUpper ? Strings_1.firstUpperWordStyle : Strings_1.allLowerWordStyle, Strings_1.firstUpperWordStyle, isUpper ? Strings_1.allUpperWordStyle : Strings_1.allLowerWordStyle, Strings_1.allUpperWordStyle, "", isStartCharacter);
|
|
139
|
+
}
|
|
140
|
+
/* function unicodeEscape(codePoint: number): string {
|
|
141
|
+
return "\\u" + intToHex(codePoint, 4);
|
|
142
|
+
} */
|
|
143
|
+
//const _stringEscape = utf32ConcatMap(escapeNonPrintableMapper(isPrintable, unicodeEscape));
|
|
144
|
+
/* function stringEscape(s: string): string {
|
|
145
|
+
// "$this" is a template string in Kotlin so we have to escape $
|
|
146
|
+
return _stringEscape(s).replace(/\$/g, "\\$");
|
|
147
|
+
} */
|
|
148
|
+
const upperNamingFunction = (0, Naming_1.funPrefixNamer)("upper", s => scalaNameStyle(true, s));
|
|
149
|
+
const lowerNamingFunction = (0, Naming_1.funPrefixNamer)("lower", s => scalaNameStyle(false, s));
|
|
150
|
+
class Scala3Renderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
151
|
+
constructor(targetLanguage, renderContext, _scalaOptions) {
|
|
152
|
+
super(targetLanguage, renderContext);
|
|
153
|
+
this._scalaOptions = _scalaOptions;
|
|
154
|
+
}
|
|
155
|
+
forbiddenNamesForGlobalNamespace() {
|
|
156
|
+
return keywords;
|
|
157
|
+
}
|
|
158
|
+
forbiddenForObjectProperties(_, _classNamed) {
|
|
159
|
+
return { names: [], includeGlobalForbidden: true };
|
|
160
|
+
}
|
|
161
|
+
forbiddenForEnumCases(_, _enumName) {
|
|
162
|
+
return { names: [], includeGlobalForbidden: true };
|
|
163
|
+
}
|
|
164
|
+
forbiddenForUnionMembers(_u, _unionName) {
|
|
165
|
+
return { names: [], includeGlobalForbidden: false };
|
|
166
|
+
}
|
|
167
|
+
topLevelNameStyle(rawName) {
|
|
168
|
+
return scalaNameStyle(true, rawName);
|
|
169
|
+
}
|
|
170
|
+
makeNamedTypeNamer() {
|
|
171
|
+
return upperNamingFunction;
|
|
172
|
+
}
|
|
173
|
+
namerForObjectProperty() {
|
|
174
|
+
return lowerNamingFunction;
|
|
175
|
+
}
|
|
176
|
+
makeUnionMemberNamer() {
|
|
177
|
+
return (0, Naming_1.funPrefixNamer)("upper", s => scalaNameStyle(true, s) + "Value");
|
|
178
|
+
}
|
|
179
|
+
makeEnumCaseNamer() {
|
|
180
|
+
return (0, Naming_1.funPrefixNamer)("upper", s => s.replace(" ", "")); // TODO - add backticks where appropriate
|
|
181
|
+
}
|
|
182
|
+
emitDescriptionBlock(lines) {
|
|
183
|
+
this.emitCommentLines(lines, " * ", "/**", " */");
|
|
184
|
+
}
|
|
185
|
+
emitBlock(line, f, delimiter = "curly") {
|
|
186
|
+
const [open, close] = delimiter === "curly"
|
|
187
|
+
? ["{", "}"]
|
|
188
|
+
: delimiter === "paren"
|
|
189
|
+
? ["(", ")"]
|
|
190
|
+
: delimiter === "none"
|
|
191
|
+
? ["", ""]
|
|
192
|
+
: ["{", "})"];
|
|
193
|
+
this.emitLine(line, " ", open);
|
|
194
|
+
this.indent(f);
|
|
195
|
+
this.emitLine(close);
|
|
196
|
+
}
|
|
197
|
+
anySourceType(optional) {
|
|
198
|
+
return [wrapOption("Any", optional)];
|
|
199
|
+
}
|
|
200
|
+
// (asarazan): I've broken out the following two functions
|
|
201
|
+
// because some renderers, such as kotlinx, can cope with `any`, while some get mad.
|
|
202
|
+
arrayType(arrayType, withIssues = false) {
|
|
203
|
+
return ["Seq[", this.scalaType(arrayType.items, withIssues), "]"];
|
|
204
|
+
}
|
|
205
|
+
mapType(mapType, withIssues = false) {
|
|
206
|
+
return ["Map[String, ", this.scalaType(mapType.values, withIssues), "]"];
|
|
207
|
+
}
|
|
208
|
+
scalaType(t, withIssues = false, noOptional = false) {
|
|
209
|
+
return (0, TypeUtils_1.matchType)(t, _anyType => {
|
|
210
|
+
return (0, Source_1.maybeAnnotated)(withIssues, Annotation_1.anyTypeIssueAnnotation, this.anySourceType(!noOptional));
|
|
211
|
+
}, _nullType => {
|
|
212
|
+
//return "None.type"
|
|
213
|
+
return (0, Source_1.maybeAnnotated)(withIssues, Annotation_1.nullTypeIssueAnnotation, this.anySourceType(!noOptional));
|
|
214
|
+
}, _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 => {
|
|
215
|
+
const nullable = (0, TypeUtils_1.nullableFromUnion)(unionType);
|
|
216
|
+
if (nullable !== null) {
|
|
217
|
+
if (noOptional) {
|
|
218
|
+
return [this.scalaType(nullable, withIssues)];
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
return ["Option[", this.scalaType(nullable, withIssues), "]"];
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return this.nameForNamedType(unionType);
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
emitUsageHeader() {
|
|
228
|
+
// To be overridden
|
|
229
|
+
}
|
|
230
|
+
emitHeader() {
|
|
231
|
+
if (this.leadingComments !== undefined) {
|
|
232
|
+
this.emitCommentLines(this.leadingComments);
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
this.emitUsageHeader();
|
|
236
|
+
}
|
|
237
|
+
this.ensureBlankLine();
|
|
238
|
+
this.emitLine("package ", this._scalaOptions.packageName);
|
|
239
|
+
this.ensureBlankLine();
|
|
240
|
+
}
|
|
241
|
+
emitTopLevelArray(t, name) {
|
|
242
|
+
const elementType = this.scalaType(t.items);
|
|
243
|
+
this.emitLine(["type ", name, " = List[", elementType, "]"]);
|
|
244
|
+
}
|
|
245
|
+
emitTopLevelMap(t, name) {
|
|
246
|
+
const elementType = this.scalaType(t.values);
|
|
247
|
+
this.emitLine(["type ", name, " = Map[String, ", elementType, "]"]);
|
|
248
|
+
}
|
|
249
|
+
emitEmptyClassDefinition(c, className) {
|
|
250
|
+
this.emitDescription(this.descriptionForType(c));
|
|
251
|
+
this.emitLine("case class ", className, "()");
|
|
252
|
+
}
|
|
253
|
+
emitClassDefinition(c, className) {
|
|
254
|
+
if (c.getProperties().size === 0) {
|
|
255
|
+
this.emitEmptyClassDefinition(c, className);
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
const scalaType = (p) => {
|
|
259
|
+
if (p.isOptional) {
|
|
260
|
+
return ["Option[", this.scalaType(p.type, true, true), "]"];
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
return this.scalaType(p.type, true);
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
this.emitDescription(this.descriptionForType(c));
|
|
267
|
+
this.emitLine("case class ", className, " (");
|
|
268
|
+
this.indent(() => {
|
|
269
|
+
let count = c.getProperties().size;
|
|
270
|
+
let first = true;
|
|
271
|
+
this.forEachClassProperty(c, "none", (_, jsonName, p) => {
|
|
272
|
+
const nullable = p.type.kind === "union" && (0, TypeUtils_1.nullableFromUnion)(p.type) !== null;
|
|
273
|
+
const nullableOrOptional = p.isOptional || p.type.kind === "null" || nullable;
|
|
274
|
+
const last = --count === 0;
|
|
275
|
+
const meta = [];
|
|
276
|
+
const description = this.descriptionForClassProperty(c, jsonName);
|
|
277
|
+
if (description !== undefined) {
|
|
278
|
+
meta.push(() => this.emitDescription(description));
|
|
279
|
+
}
|
|
280
|
+
if (meta.length > 0 && !first) {
|
|
281
|
+
this.ensureBlankLine();
|
|
282
|
+
}
|
|
283
|
+
for (const emit of meta) {
|
|
284
|
+
emit();
|
|
285
|
+
}
|
|
286
|
+
const nameNeedsBackticks = jsonName.endsWith("_") || shouldAddBacktick(jsonName);
|
|
287
|
+
const nameWithBackticks = nameNeedsBackticks ? "`" + jsonName + "`" : jsonName;
|
|
288
|
+
this.emitLine("val ", nameWithBackticks, " : ", scalaType(p), p.isOptional ? " = None" : nullableOrOptional ? " = None" : "", last ? "" : ",");
|
|
289
|
+
if (meta.length > 0 && !last) {
|
|
290
|
+
this.ensureBlankLine();
|
|
291
|
+
}
|
|
292
|
+
first = false;
|
|
293
|
+
});
|
|
294
|
+
});
|
|
295
|
+
this.emitClassDefinitionMethods();
|
|
296
|
+
}
|
|
297
|
+
emitClassDefinitionMethods() {
|
|
298
|
+
this.emitLine(")");
|
|
299
|
+
}
|
|
300
|
+
emitEnumDefinition(e, enumName) {
|
|
301
|
+
this.emitDescription(this.descriptionForType(e));
|
|
302
|
+
this.emitBlock(["enum ", enumName, " : "], () => {
|
|
303
|
+
let count = e.cases.size;
|
|
304
|
+
if (count > 0) {
|
|
305
|
+
this.emitItem("\t case ");
|
|
306
|
+
}
|
|
307
|
+
;
|
|
308
|
+
this.forEachEnumCase(e, "none", (name, jsonName) => {
|
|
309
|
+
if (!(jsonName == "")) {
|
|
310
|
+
const backticks = shouldAddBacktick(jsonName) ||
|
|
311
|
+
jsonName.includes(" ") ||
|
|
312
|
+
!isNaN(parseInt(jsonName.charAt(0)));
|
|
313
|
+
if (backticks) {
|
|
314
|
+
this.emitItem("`");
|
|
315
|
+
}
|
|
316
|
+
this.emitItemOnce([name]);
|
|
317
|
+
if (backticks) {
|
|
318
|
+
this.emitItem("`");
|
|
319
|
+
}
|
|
320
|
+
if (--count > 0)
|
|
321
|
+
this.emitItem([","]);
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
--count;
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
}, "none");
|
|
328
|
+
}
|
|
329
|
+
emitUnionDefinition(u, unionName) {
|
|
330
|
+
function sortBy(t) {
|
|
331
|
+
const kind = t.kind;
|
|
332
|
+
if (kind === "class")
|
|
333
|
+
return kind;
|
|
334
|
+
return "_" + kind;
|
|
335
|
+
}
|
|
336
|
+
this.emitDescription(this.descriptionForType(u));
|
|
337
|
+
const [maybeNull, nonNulls] = (0, TypeUtils_1.removeNullFromUnion)(u, sortBy);
|
|
338
|
+
const theTypes = [];
|
|
339
|
+
this.forEachUnionMember(u, nonNulls, "none", null, (_, t) => {
|
|
340
|
+
theTypes.push(this.scalaType(t));
|
|
341
|
+
});
|
|
342
|
+
if (maybeNull !== null) {
|
|
343
|
+
theTypes.push(this.nameForUnionMember(u, maybeNull));
|
|
344
|
+
}
|
|
345
|
+
this.emitItem(["type ", unionName, " = "]);
|
|
346
|
+
theTypes.forEach((t, i) => {
|
|
347
|
+
this.emitItem(i === 0 ? t : [" | ", t]);
|
|
348
|
+
});
|
|
349
|
+
this.ensureBlankLine();
|
|
350
|
+
}
|
|
351
|
+
emitSourceStructure() {
|
|
352
|
+
this.emitHeader();
|
|
353
|
+
// Top-level arrays, maps
|
|
354
|
+
this.forEachTopLevel("leading", (t, name) => {
|
|
355
|
+
if (t instanceof Type_1.ArrayType) {
|
|
356
|
+
this.emitTopLevelArray(t, name);
|
|
357
|
+
}
|
|
358
|
+
else if (t instanceof Type_1.MapType) {
|
|
359
|
+
this.emitTopLevelMap(t, name);
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
this.forEachNamedType("leading-and-interposing", (c, n) => this.emitClassDefinition(c, n), (e, n) => this.emitEnumDefinition(e, n), (u, n) => this.emitUnionDefinition(u, n));
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
exports.Scala3Renderer = Scala3Renderer;
|
|
366
|
+
class UpickleRenderer extends Scala3Renderer {
|
|
367
|
+
emitClassDefinitionMethods() {
|
|
368
|
+
this.emitLine(") derives ReadWriter ");
|
|
369
|
+
}
|
|
370
|
+
emitHeader() {
|
|
371
|
+
super.emitHeader();
|
|
372
|
+
this.emitLine("import upickle.default.*");
|
|
373
|
+
this.ensureBlankLine();
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
exports.UpickleRenderer = UpickleRenderer;
|
|
377
|
+
class Smithy4sRenderer extends Scala3Renderer {
|
|
378
|
+
emitHeader() {
|
|
379
|
+
if (this.leadingComments !== undefined) {
|
|
380
|
+
this.emitCommentLines(this.leadingComments);
|
|
381
|
+
}
|
|
382
|
+
else {
|
|
383
|
+
this.emitUsageHeader();
|
|
384
|
+
}
|
|
385
|
+
this.ensureBlankLine();
|
|
386
|
+
this.emitLine("namespace ", this._scalaOptions.packageName);
|
|
387
|
+
this.ensureBlankLine();
|
|
388
|
+
}
|
|
389
|
+
emitTopLevelArray(t, name) {
|
|
390
|
+
const elementType = this.scalaType(t.items);
|
|
391
|
+
this.emitLine(["list ", name, " { member : ", elementType, "}"]);
|
|
392
|
+
}
|
|
393
|
+
emitTopLevelMap(t, name) {
|
|
394
|
+
const elementType = this.scalaType(t.values);
|
|
395
|
+
this.emitLine(["map ", name, " { map[ key : String , value : ", elementType, "}"]);
|
|
396
|
+
}
|
|
397
|
+
emitEmptyClassDefinition(c, className) {
|
|
398
|
+
this.emitDescription(this.descriptionForType(c));
|
|
399
|
+
this.emitLine("structure ", className, "{}");
|
|
400
|
+
}
|
|
401
|
+
emitEnumDefinition(e, enumName) {
|
|
402
|
+
this.emitDescription(this.descriptionForType(e));
|
|
403
|
+
this.ensureBlankLine();
|
|
404
|
+
this.emitItem(["enum ", enumName, " { "]);
|
|
405
|
+
let count = e.cases.size;
|
|
406
|
+
this.forEachEnumCase(e, "none", (name, jsonName) => {
|
|
407
|
+
// if (!(jsonName == "")) {
|
|
408
|
+
/* const backticks =
|
|
409
|
+
shouldAddBacktick(jsonName) ||
|
|
410
|
+
jsonName.includes(" ") ||
|
|
411
|
+
!isNaN(parseInt(jsonName.charAt(0)))
|
|
412
|
+
if (backticks) {this.emitItem("`")} else */
|
|
413
|
+
this.emitLine();
|
|
414
|
+
this.emitItem([name, " = \"", jsonName, "\""]);
|
|
415
|
+
// if (backticks) {this.emitItem("`")}
|
|
416
|
+
if (--count > 0)
|
|
417
|
+
this.emitItem([","]);
|
|
418
|
+
//} else {
|
|
419
|
+
//--count
|
|
420
|
+
//}
|
|
421
|
+
});
|
|
422
|
+
this.ensureBlankLine();
|
|
423
|
+
this.emitItem(["}"]);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
exports.Smithy4sRenderer = Smithy4sRenderer;
|
|
427
|
+
class CirceRenderer extends Scala3Renderer {
|
|
428
|
+
constructor() {
|
|
429
|
+
super(...arguments);
|
|
430
|
+
this.seenUnionTypes = [];
|
|
431
|
+
}
|
|
432
|
+
circeEncoderForType(t, _ = false, noOptional = false, paramName = "") {
|
|
433
|
+
return (0, TypeUtils_1.matchType)(t, _anyType => ["Encoder.encodeJson(", paramName, ")"], _nullType => ["Encoder.encodeNone(", paramName, ")"], _boolType => ["Encoder.encodeBoolean(", paramName, ")"], _integerType => ["Encoder.encodeLong(", paramName, ")"], _doubleType => ["Encoder.encodeDouble(", paramName, ")"], _stringType => ["Encoder.encodeString(", paramName, ")"], arrayType => ["Encoder.encodeSeq[", this.scalaType(arrayType.items), "].apply(", paramName, ")"], classType => ["Encoder.AsObject[", this.scalaType(classType), "].apply(", paramName, ")"], mapType => ["Encoder.encodeMap[String,", this.scalaType(mapType.values), "].apply(", paramName, ")"], _ => ["Encoder.encodeString(", paramName, ")"], unionType => {
|
|
434
|
+
const nullable = (0, TypeUtils_1.nullableFromUnion)(unionType);
|
|
435
|
+
if (nullable !== null) {
|
|
436
|
+
if (noOptional) {
|
|
437
|
+
return ["Encoder.AsObject[", this.nameForNamedType(nullable), "]"];
|
|
438
|
+
}
|
|
439
|
+
else {
|
|
440
|
+
return ["Encoder.AsObject[Option[", this.nameForNamedType(nullable), "]]"];
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
return ["Encoder.AsObject[", this.nameForNamedType(unionType), "]"];
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
emitEmptyClassDefinition(c, className) {
|
|
447
|
+
this.emitDescription(this.descriptionForType(c));
|
|
448
|
+
this.ensureBlankLine();
|
|
449
|
+
this.emitLine("case class ", className, "() derives Encoder.AsObject, Decoder");
|
|
450
|
+
}
|
|
451
|
+
anySourceType(optional) {
|
|
452
|
+
return [wrapOption("Json", optional)];
|
|
453
|
+
}
|
|
454
|
+
emitClassDefinitionMethods() {
|
|
455
|
+
this.emitLine(") derives Encoder.AsObject, Decoder");
|
|
456
|
+
}
|
|
457
|
+
emitEnumDefinition(e, enumName) {
|
|
458
|
+
this.emitDescription(this.descriptionForType(e));
|
|
459
|
+
this.ensureBlankLine();
|
|
460
|
+
this.emitItem(["type ", enumName, " = "]);
|
|
461
|
+
let count = e.cases.size;
|
|
462
|
+
this.forEachEnumCase(e, "none", (_, jsonName) => {
|
|
463
|
+
// if (!(jsonName == "")) {
|
|
464
|
+
/* const backticks =
|
|
465
|
+
shouldAddBacktick(jsonName) ||
|
|
466
|
+
jsonName.includes(" ") ||
|
|
467
|
+
!isNaN(parseInt(jsonName.charAt(0)))
|
|
468
|
+
if (backticks) {this.emitItem("`")} else */
|
|
469
|
+
this.emitItem(["\"", jsonName, "\""]);
|
|
470
|
+
// if (backticks) {this.emitItem("`")}
|
|
471
|
+
if (--count > 0)
|
|
472
|
+
this.emitItem([" | "]);
|
|
473
|
+
//} else {
|
|
474
|
+
//--count
|
|
475
|
+
//}
|
|
476
|
+
});
|
|
477
|
+
this.ensureBlankLine();
|
|
478
|
+
}
|
|
479
|
+
emitHeader() {
|
|
480
|
+
super.emitHeader();
|
|
481
|
+
this.emitLine("import scala.util.Try");
|
|
482
|
+
this.emitLine("import io.circe.syntax._");
|
|
483
|
+
this.emitLine("import io.circe._");
|
|
484
|
+
this.emitLine("import cats.syntax.functor._");
|
|
485
|
+
this.ensureBlankLine();
|
|
486
|
+
this.emitLine("// For serialising string unions");
|
|
487
|
+
this.emitLine("given [A <: Singleton](using A <:< String): Decoder[A] = Decoder.decodeString.emapTry(x => Try(x.asInstanceOf[A])) ");
|
|
488
|
+
this.emitLine("given [A <: Singleton](using ev: A <:< String): Encoder[A] = Encoder.encodeString.contramap(ev) ");
|
|
489
|
+
this.ensureBlankLine();
|
|
490
|
+
this.emitLine("// If a union has a null in, then we'll need this too... ");
|
|
491
|
+
this.emitLine("type NullValue = None.type");
|
|
492
|
+
}
|
|
493
|
+
emitTopLevelArray(t, name) {
|
|
494
|
+
super.emitTopLevelArray(t, name);
|
|
495
|
+
const elementType = this.scalaType(t.items);
|
|
496
|
+
this.emitLine(["given (using ev : ", elementType, "): Encoder[Map[String,", elementType, "]] = Encoder.encodeMap[String, ", elementType, "]"]);
|
|
497
|
+
}
|
|
498
|
+
emitTopLevelMap(t, name) {
|
|
499
|
+
super.emitTopLevelMap(t, name);
|
|
500
|
+
const elementType = this.scalaType(t.values);
|
|
501
|
+
this.ensureBlankLine();
|
|
502
|
+
this.emitLine(["given (using ev : ", elementType, "): Encoder[Map[String, ", elementType, "]] = Encoder.encodeMap[String, ", elementType, "]"]);
|
|
503
|
+
}
|
|
504
|
+
emitUnionDefinition(u, unionName) {
|
|
505
|
+
function sortBy(t) {
|
|
506
|
+
const kind = t.kind;
|
|
507
|
+
if (kind === "class")
|
|
508
|
+
return kind;
|
|
509
|
+
return "_" + kind;
|
|
510
|
+
}
|
|
511
|
+
this.emitDescription(this.descriptionForType(u));
|
|
512
|
+
const [maybeNull, nonNulls] = (0, TypeUtils_1.removeNullFromUnion)(u, sortBy);
|
|
513
|
+
const theTypes = [];
|
|
514
|
+
this.forEachUnionMember(u, nonNulls, "none", null, (_, t) => {
|
|
515
|
+
theTypes.push(this.scalaType(t));
|
|
516
|
+
});
|
|
517
|
+
if (maybeNull !== null) {
|
|
518
|
+
theTypes.push(this.nameForUnionMember(u, maybeNull));
|
|
519
|
+
}
|
|
520
|
+
this.emitItem(["type ", unionName, " = "]);
|
|
521
|
+
theTypes.forEach((t, i) => {
|
|
522
|
+
this.emitItem(i === 0 ? t : [" | ", t]);
|
|
523
|
+
});
|
|
524
|
+
const thisUnionType = theTypes.map(x => this.sourcelikeToString(x)).join(" | ");
|
|
525
|
+
this.ensureBlankLine();
|
|
526
|
+
if (!this.seenUnionTypes.some(y => y === thisUnionType)) {
|
|
527
|
+
this.seenUnionTypes.push(thisUnionType);
|
|
528
|
+
const sourceLikeTypes = [];
|
|
529
|
+
this.forEachUnionMember(u, nonNulls, "none", null, (_, t) => {
|
|
530
|
+
sourceLikeTypes.push([this.scalaType(t), t]);
|
|
531
|
+
});
|
|
532
|
+
if (maybeNull !== null) {
|
|
533
|
+
sourceLikeTypes.push([this.nameForUnionMember(u, maybeNull), maybeNull]);
|
|
534
|
+
}
|
|
535
|
+
this.emitLine(["given Decoder[", unionName, "] = {"]);
|
|
536
|
+
this.indent(() => {
|
|
537
|
+
this.emitLine(["List[Decoder[", unionName, "]]("]);
|
|
538
|
+
this.indent(() => {
|
|
539
|
+
sourceLikeTypes.forEach((t) => {
|
|
540
|
+
this.emitLine(["Decoder[", t[0], "].widen,"]);
|
|
541
|
+
});
|
|
542
|
+
});
|
|
543
|
+
this.emitLine(").reduceLeft(_ or _)");
|
|
544
|
+
});
|
|
545
|
+
this.emitLine(["}"]);
|
|
546
|
+
this.ensureBlankLine();
|
|
547
|
+
this.emitLine(["given Encoder[", unionName, "] = Encoder.instance {"]);
|
|
548
|
+
this.indent(() => {
|
|
549
|
+
sourceLikeTypes.forEach((t, i) => {
|
|
550
|
+
const paramTemp = `enc${i.toString()}`;
|
|
551
|
+
this.emitLine(["case ", paramTemp, " : ", t[0], " => ", this.circeEncoderForType(t[1], false, false, paramTemp)]);
|
|
552
|
+
});
|
|
553
|
+
});
|
|
554
|
+
this.emitLine("}");
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
exports.CirceRenderer = CirceRenderer;
|
|
559
|
+
class Scala3TargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
560
|
+
constructor() {
|
|
561
|
+
super("Scala3", ["scala3"], "scala");
|
|
562
|
+
}
|
|
563
|
+
getOptions() {
|
|
564
|
+
return [exports.scala3Options.framework, exports.scala3Options.packageName];
|
|
565
|
+
}
|
|
566
|
+
get supportsOptionalClassProperties() {
|
|
567
|
+
return true;
|
|
568
|
+
}
|
|
569
|
+
get supportsUnionsWithBothNumberTypes() {
|
|
570
|
+
return true;
|
|
571
|
+
}
|
|
572
|
+
makeRenderer(renderContext, untypedOptionValues) {
|
|
573
|
+
const options = (0, RendererOptions_1.getOptionValues)(exports.scala3Options, untypedOptionValues);
|
|
574
|
+
switch (options.framework) {
|
|
575
|
+
case Framework.None:
|
|
576
|
+
return new Scala3Renderer(this, renderContext, options);
|
|
577
|
+
case Framework.Upickle:
|
|
578
|
+
return new UpickleRenderer(this, renderContext, options);
|
|
579
|
+
case Framework.Circe:
|
|
580
|
+
return new CirceRenderer(this, renderContext, options);
|
|
581
|
+
default:
|
|
582
|
+
return (0, Support_1.assertNever)(options.framework);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
exports.Scala3TargetLanguage = Scala3TargetLanguage;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { ConvenienceRenderer, ForbiddenWordsInfo } from "../ConvenienceRenderer";
|
|
2
|
+
import { Name, Namer } from "../Naming";
|
|
3
|
+
import { EnumOption, Option, StringOption, OptionValues } from "../RendererOptions";
|
|
4
|
+
import { Sourcelike } from "../Source";
|
|
5
|
+
import { TargetLanguage } from "../TargetLanguage";
|
|
6
|
+
import { ArrayType, ClassProperty, ClassType, EnumType, MapType, ObjectType, Type, UnionType } from "../Type";
|
|
7
|
+
import { RenderContext } from "../Renderer";
|
|
8
|
+
export declare enum Framework {
|
|
9
|
+
None = 0
|
|
10
|
+
}
|
|
11
|
+
export declare const SmithyOptions: {
|
|
12
|
+
framework: EnumOption<Framework>;
|
|
13
|
+
packageName: StringOption;
|
|
14
|
+
};
|
|
15
|
+
export declare class Smithy4sRenderer extends ConvenienceRenderer {
|
|
16
|
+
protected readonly _scalaOptions: OptionValues<typeof SmithyOptions>;
|
|
17
|
+
constructor(targetLanguage: TargetLanguage, renderContext: RenderContext, _scalaOptions: OptionValues<typeof SmithyOptions>);
|
|
18
|
+
protected forbiddenNamesForGlobalNamespace(): string[];
|
|
19
|
+
protected forbiddenForObjectProperties(_: ObjectType, _classNamed: Name): ForbiddenWordsInfo;
|
|
20
|
+
protected forbiddenForEnumCases(_: EnumType, _enumName: Name): ForbiddenWordsInfo;
|
|
21
|
+
protected forbiddenForUnionMembers(_u: UnionType, _unionName: Name): ForbiddenWordsInfo;
|
|
22
|
+
protected topLevelNameStyle(rawName: string): string;
|
|
23
|
+
protected makeNamedTypeNamer(): Namer;
|
|
24
|
+
protected namerForObjectProperty(): Namer;
|
|
25
|
+
protected makeUnionMemberNamer(): Namer;
|
|
26
|
+
protected makeEnumCaseNamer(): Namer;
|
|
27
|
+
protected emitDescriptionBlock(lines: Sourcelike[]): void;
|
|
28
|
+
protected emitBlock(line: Sourcelike, f: () => void, delimiter?: "curly" | "paren" | "lambda" | "none"): void;
|
|
29
|
+
protected anySourceType(_: boolean): Sourcelike;
|
|
30
|
+
protected arrayType(arrayType: ArrayType, _?: boolean): Sourcelike;
|
|
31
|
+
protected emitArrayType(_: ArrayType, smithyType: Sourcelike): void;
|
|
32
|
+
protected mapType(mapType: MapType, _?: boolean): Sourcelike;
|
|
33
|
+
protected scalaType(t: Type, withIssues?: boolean, noOptional?: boolean): Sourcelike;
|
|
34
|
+
protected emitUsageHeader(): void;
|
|
35
|
+
protected emitHeader(): void;
|
|
36
|
+
protected emitTopLevelArray(t: ArrayType, name: Name): void;
|
|
37
|
+
protected emitTopLevelMap(t: MapType, name: Name): void;
|
|
38
|
+
protected emitEmptyClassDefinition(c: ClassType, className: Name): void;
|
|
39
|
+
protected emitClassDefinition(c: ClassType, className: Name): void;
|
|
40
|
+
protected emitClassDefinitionMethods(arrayTypes: ClassProperty[]): void;
|
|
41
|
+
protected emitEnumDefinition(e: EnumType, enumName: Name): void;
|
|
42
|
+
protected emitUnionDefinition(u: UnionType, unionName: Name): void;
|
|
43
|
+
protected emitSourceStructure(): void;
|
|
44
|
+
}
|
|
45
|
+
export declare class SmithyTargetLanguage extends TargetLanguage {
|
|
46
|
+
constructor();
|
|
47
|
+
protected getOptions(): Option<any>[];
|
|
48
|
+
get supportsOptionalClassProperties(): boolean;
|
|
49
|
+
get supportsUnionsWithBothNumberTypes(): boolean;
|
|
50
|
+
protected makeRenderer(renderContext: RenderContext, untypedOptionValues: {
|
|
51
|
+
[name: string]: any;
|
|
52
|
+
}): ConvenienceRenderer;
|
|
53
|
+
}
|
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SmithyTargetLanguage = exports.Smithy4sRenderer = exports.SmithyOptions = exports.Framework = void 0;
|
|
4
|
+
const Annotation_1 = require("../Annotation");
|
|
5
|
+
const ConvenienceRenderer_1 = require("../ConvenienceRenderer");
|
|
6
|
+
const Naming_1 = require("../Naming");
|
|
7
|
+
const RendererOptions_1 = require("../RendererOptions");
|
|
8
|
+
const Source_1 = require("../Source");
|
|
9
|
+
const Strings_1 = require("../support/Strings");
|
|
10
|
+
const Support_1 = require("../support/Support");
|
|
11
|
+
const TargetLanguage_1 = require("../TargetLanguage");
|
|
12
|
+
const Type_1 = require("../Type");
|
|
13
|
+
const TypeUtils_1 = require("../TypeUtils");
|
|
14
|
+
var Framework;
|
|
15
|
+
(function (Framework) {
|
|
16
|
+
Framework[Framework["None"] = 0] = "None";
|
|
17
|
+
})(Framework = exports.Framework || (exports.Framework = {}));
|
|
18
|
+
exports.SmithyOptions = {
|
|
19
|
+
framework: new RendererOptions_1.EnumOption("framework", "Serialization framework", [
|
|
20
|
+
["just-types", Framework.None]
|
|
21
|
+
], undefined),
|
|
22
|
+
packageName: new RendererOptions_1.StringOption("package", "Package", "PACKAGE", "quicktype")
|
|
23
|
+
};
|
|
24
|
+
// Use backticks for param names with symbols
|
|
25
|
+
const invalidSymbols = [
|
|
26
|
+
":",
|
|
27
|
+
"-",
|
|
28
|
+
"+",
|
|
29
|
+
"!",
|
|
30
|
+
"@",
|
|
31
|
+
"#",
|
|
32
|
+
"%",
|
|
33
|
+
"^",
|
|
34
|
+
"&",
|
|
35
|
+
"*",
|
|
36
|
+
"(",
|
|
37
|
+
")",
|
|
38
|
+
">",
|
|
39
|
+
"<",
|
|
40
|
+
"/",
|
|
41
|
+
";",
|
|
42
|
+
"'",
|
|
43
|
+
'"',
|
|
44
|
+
"{",
|
|
45
|
+
"}",
|
|
46
|
+
":",
|
|
47
|
+
"~",
|
|
48
|
+
"`",
|
|
49
|
+
"."
|
|
50
|
+
];
|
|
51
|
+
const keywords = [
|
|
52
|
+
"abstract",
|
|
53
|
+
"case",
|
|
54
|
+
"catch",
|
|
55
|
+
"do",
|
|
56
|
+
"else",
|
|
57
|
+
"export",
|
|
58
|
+
"false",
|
|
59
|
+
"final",
|
|
60
|
+
"finally",
|
|
61
|
+
"for",
|
|
62
|
+
"forSome",
|
|
63
|
+
"if",
|
|
64
|
+
"implicit",
|
|
65
|
+
"import",
|
|
66
|
+
"new",
|
|
67
|
+
"override",
|
|
68
|
+
"package",
|
|
69
|
+
"private",
|
|
70
|
+
"protected",
|
|
71
|
+
"return",
|
|
72
|
+
"sealed",
|
|
73
|
+
"super",
|
|
74
|
+
"this",
|
|
75
|
+
"then",
|
|
76
|
+
"throw",
|
|
77
|
+
"trait",
|
|
78
|
+
"try",
|
|
79
|
+
"true",
|
|
80
|
+
"val",
|
|
81
|
+
"var",
|
|
82
|
+
"while",
|
|
83
|
+
"with",
|
|
84
|
+
"yield",
|
|
85
|
+
"Any",
|
|
86
|
+
"Boolean",
|
|
87
|
+
"Double",
|
|
88
|
+
"Float",
|
|
89
|
+
"Long",
|
|
90
|
+
"Int",
|
|
91
|
+
"Short",
|
|
92
|
+
"System",
|
|
93
|
+
"Byte",
|
|
94
|
+
"String",
|
|
95
|
+
"Array",
|
|
96
|
+
"List",
|
|
97
|
+
"Map",
|
|
98
|
+
"Enum"
|
|
99
|
+
];
|
|
100
|
+
/**
|
|
101
|
+
* Check if given parameter name should be wrapped in a backtick
|
|
102
|
+
* @param paramName
|
|
103
|
+
*/
|
|
104
|
+
const shouldAddBacktick = (paramName) => {
|
|
105
|
+
return keywords.some(s => paramName === s) || invalidSymbols.some(s => paramName.includes(s)) || !isNaN(parseFloat(paramName)) || !isNaN(parseInt(paramName.charAt(0)));
|
|
106
|
+
};
|
|
107
|
+
function isPartCharacter(codePoint) {
|
|
108
|
+
return (0, Strings_1.isLetterOrUnderscore)(codePoint) || (0, Strings_1.isNumeric)(codePoint);
|
|
109
|
+
}
|
|
110
|
+
function isStartCharacter(codePoint) {
|
|
111
|
+
return isPartCharacter(codePoint) && !(0, Strings_1.isDigit)(codePoint);
|
|
112
|
+
}
|
|
113
|
+
const legalizeName = (0, Strings_1.legalizeCharacters)(isPartCharacter);
|
|
114
|
+
function scalaNameStyle(isUpper, original) {
|
|
115
|
+
const words = (0, Strings_1.splitIntoWords)(original);
|
|
116
|
+
return (0, Strings_1.combineWords)(words, legalizeName, isUpper ? Strings_1.firstUpperWordStyle : Strings_1.allLowerWordStyle, Strings_1.firstUpperWordStyle, isUpper ? Strings_1.allUpperWordStyle : Strings_1.allLowerWordStyle, Strings_1.allUpperWordStyle, "", isStartCharacter);
|
|
117
|
+
}
|
|
118
|
+
const upperNamingFunction = (0, Naming_1.funPrefixNamer)("upper", s => scalaNameStyle(true, s));
|
|
119
|
+
const lowerNamingFunction = (0, Naming_1.funPrefixNamer)("lower", s => scalaNameStyle(false, s));
|
|
120
|
+
class Smithy4sRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
121
|
+
constructor(targetLanguage, renderContext, _scalaOptions) {
|
|
122
|
+
super(targetLanguage, renderContext);
|
|
123
|
+
this._scalaOptions = _scalaOptions;
|
|
124
|
+
}
|
|
125
|
+
forbiddenNamesForGlobalNamespace() {
|
|
126
|
+
return keywords;
|
|
127
|
+
}
|
|
128
|
+
forbiddenForObjectProperties(_, _classNamed) {
|
|
129
|
+
return { names: [], includeGlobalForbidden: true };
|
|
130
|
+
}
|
|
131
|
+
forbiddenForEnumCases(_, _enumName) {
|
|
132
|
+
return { names: [], includeGlobalForbidden: true };
|
|
133
|
+
}
|
|
134
|
+
forbiddenForUnionMembers(_u, _unionName) {
|
|
135
|
+
return { names: [], includeGlobalForbidden: false };
|
|
136
|
+
}
|
|
137
|
+
topLevelNameStyle(rawName) {
|
|
138
|
+
return scalaNameStyle(true, rawName);
|
|
139
|
+
}
|
|
140
|
+
makeNamedTypeNamer() {
|
|
141
|
+
return upperNamingFunction;
|
|
142
|
+
}
|
|
143
|
+
namerForObjectProperty() {
|
|
144
|
+
return lowerNamingFunction;
|
|
145
|
+
}
|
|
146
|
+
makeUnionMemberNamer() {
|
|
147
|
+
return (0, Naming_1.funPrefixNamer)("upper", s => scalaNameStyle(true, s) + "Value");
|
|
148
|
+
}
|
|
149
|
+
makeEnumCaseNamer() {
|
|
150
|
+
return (0, Naming_1.funPrefixNamer)("upper", s => s.replace(" ", "")); // TODO - add backticks where appropriate
|
|
151
|
+
}
|
|
152
|
+
emitDescriptionBlock(lines) {
|
|
153
|
+
this.emitCommentLines(lines, " * ", "/**", " */");
|
|
154
|
+
}
|
|
155
|
+
emitBlock(line, f, delimiter = "curly") {
|
|
156
|
+
const [open, close] = delimiter === "curly"
|
|
157
|
+
? ["{", "}"]
|
|
158
|
+
: delimiter === "paren"
|
|
159
|
+
? ["(", ")"]
|
|
160
|
+
: delimiter === "none"
|
|
161
|
+
? ["", ""]
|
|
162
|
+
: ["{", "})"];
|
|
163
|
+
this.emitLine(line, " ", open);
|
|
164
|
+
this.indent(f);
|
|
165
|
+
this.emitLine(close);
|
|
166
|
+
}
|
|
167
|
+
anySourceType(_) {
|
|
168
|
+
return ["Document"];
|
|
169
|
+
}
|
|
170
|
+
// (asarazan): I've broken out the following two functions
|
|
171
|
+
// because some renderers, such as kotlinx, can cope with `any`, while some get mad.
|
|
172
|
+
arrayType(arrayType, _ = false) {
|
|
173
|
+
//this.emitTopLevelArray(arrayType, new Name(arrayType.getCombinedName().toString() + "List"))
|
|
174
|
+
return arrayType.getCombinedName().toString() + "List";
|
|
175
|
+
}
|
|
176
|
+
emitArrayType(_, smithyType) {
|
|
177
|
+
this.emitLine(["list ", smithyType, " { member : ", "}"]);
|
|
178
|
+
}
|
|
179
|
+
mapType(mapType, _ = false) {
|
|
180
|
+
return mapType.getCombinedName().toString() + "Map";
|
|
181
|
+
//return [this.scalaType(mapType.values, withIssues), "Map"];
|
|
182
|
+
}
|
|
183
|
+
scalaType(t, withIssues = false, noOptional = false) {
|
|
184
|
+
return (0, TypeUtils_1.matchType)(t, _anyType => {
|
|
185
|
+
return (0, Source_1.maybeAnnotated)(withIssues, Annotation_1.anyTypeIssueAnnotation, this.anySourceType(!noOptional));
|
|
186
|
+
}, _nullType => {
|
|
187
|
+
//return "None.type"
|
|
188
|
+
return (0, Source_1.maybeAnnotated)(withIssues, Annotation_1.nullTypeIssueAnnotation, this.anySourceType(!noOptional));
|
|
189
|
+
}, _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 => {
|
|
190
|
+
const nullable = (0, TypeUtils_1.nullableFromUnion)(unionType);
|
|
191
|
+
if (nullable !== null) {
|
|
192
|
+
return [this.scalaType(nullable, withIssues)];
|
|
193
|
+
}
|
|
194
|
+
return this.nameForNamedType(unionType);
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
emitUsageHeader() {
|
|
198
|
+
// To be overridden
|
|
199
|
+
}
|
|
200
|
+
emitHeader() {
|
|
201
|
+
if (this.leadingComments !== undefined) {
|
|
202
|
+
this.emitCommentLines(this.leadingComments);
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
this.emitUsageHeader();
|
|
206
|
+
}
|
|
207
|
+
this.ensureBlankLine();
|
|
208
|
+
this.emitLine("$version: \"2\"");
|
|
209
|
+
this.emitLine("namespace ", this._scalaOptions.packageName);
|
|
210
|
+
this.ensureBlankLine();
|
|
211
|
+
this.emitLine("document NullValue");
|
|
212
|
+
this.ensureBlankLine();
|
|
213
|
+
}
|
|
214
|
+
emitTopLevelArray(t, name) {
|
|
215
|
+
const elementType = this.scalaType(t.items);
|
|
216
|
+
this.emitLine(["list ", name, " { member : ", elementType, "}"]);
|
|
217
|
+
}
|
|
218
|
+
emitTopLevelMap(t, name) {
|
|
219
|
+
const elementType = this.scalaType(t.values);
|
|
220
|
+
this.emitLine(["map ", name, " { map[ key : String , value : ", elementType, "}"]);
|
|
221
|
+
}
|
|
222
|
+
emitEmptyClassDefinition(c, className) {
|
|
223
|
+
this.emitDescription(this.descriptionForType(c));
|
|
224
|
+
this.emitLine("structure ", className, "{}");
|
|
225
|
+
}
|
|
226
|
+
emitClassDefinition(c, className) {
|
|
227
|
+
if (c.getProperties().size === 0) {
|
|
228
|
+
this.emitEmptyClassDefinition(c, className);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
const scalaType = (p) => {
|
|
232
|
+
if (p.isOptional) {
|
|
233
|
+
return [this.scalaType(p.type, true, true)];
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
return [this.scalaType(p.type, true)];
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
const emitLater = [];
|
|
240
|
+
this.emitDescription(this.descriptionForType(c));
|
|
241
|
+
this.emitLine("structure ", className, " {");
|
|
242
|
+
this.indent(() => {
|
|
243
|
+
let count = c.getProperties().size;
|
|
244
|
+
let first = true;
|
|
245
|
+
this.forEachClassProperty(c, "none", (_, jsonName, p) => {
|
|
246
|
+
const nullable = p.type.kind === "union" && (0, TypeUtils_1.nullableFromUnion)(p.type) !== null;
|
|
247
|
+
const nullableOrOptional = p.isOptional || p.type.kind === "null" || nullable;
|
|
248
|
+
const last = --count === 0;
|
|
249
|
+
const meta = [];
|
|
250
|
+
const laterType = p.type.kind === "array" || p.type.kind === "map";
|
|
251
|
+
if (laterType) {
|
|
252
|
+
emitLater.push(p);
|
|
253
|
+
}
|
|
254
|
+
const description = this.descriptionForClassProperty(c, jsonName);
|
|
255
|
+
if (description !== undefined) {
|
|
256
|
+
meta.push(() => this.emitDescription(description));
|
|
257
|
+
}
|
|
258
|
+
if (meta.length > 0 && !first) {
|
|
259
|
+
this.ensureBlankLine();
|
|
260
|
+
}
|
|
261
|
+
for (const emit of meta) {
|
|
262
|
+
emit();
|
|
263
|
+
}
|
|
264
|
+
const nameNeedsBackticks = jsonName.endsWith("_") || shouldAddBacktick(jsonName);
|
|
265
|
+
const nameWithBackticks = nameNeedsBackticks ? "`" + jsonName + "`" : jsonName;
|
|
266
|
+
this.emitLine(p.isOptional ? "" : nullableOrOptional ? "" : "@required ", nameWithBackticks, " : ", scalaType(p), last ? "" : ",");
|
|
267
|
+
if (meta.length > 0 && !last) {
|
|
268
|
+
this.ensureBlankLine();
|
|
269
|
+
}
|
|
270
|
+
first = false;
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
this.emitClassDefinitionMethods(emitLater);
|
|
274
|
+
}
|
|
275
|
+
emitClassDefinitionMethods(arrayTypes) {
|
|
276
|
+
this.emitLine("}");
|
|
277
|
+
arrayTypes.forEach(p => {
|
|
278
|
+
function ignore(_) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
(0, TypeUtils_1.matchCompoundType)(p.type, at => {
|
|
282
|
+
this.emitLine(["list ", this.scalaType(at, true), "{ member: ", this.scalaType(at.items, true), "}"]);
|
|
283
|
+
}, ignore, mt => {
|
|
284
|
+
this.emitLine(["map ", this.scalaType(mt, true), "{ key: String , value: ", this.scalaType(mt.values, true), "}"]);
|
|
285
|
+
}, ignore, ignore);
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
emitEnumDefinition(e, enumName) {
|
|
289
|
+
this.emitDescription(this.descriptionForType(e));
|
|
290
|
+
this.ensureBlankLine();
|
|
291
|
+
this.emitItem(["enum ", enumName, " { "]);
|
|
292
|
+
let count = e.cases.size;
|
|
293
|
+
this.forEachEnumCase(e, "none", (name, jsonName) => {
|
|
294
|
+
// if (!(jsonName == "")) {
|
|
295
|
+
/* const backticks =
|
|
296
|
+
shouldAddBacktick(jsonName) ||
|
|
297
|
+
jsonName.includes(" ") ||
|
|
298
|
+
!isNaN(parseInt(jsonName.charAt(0)))
|
|
299
|
+
if (backticks) {this.emitItem("`")} else */
|
|
300
|
+
this.emitLine();
|
|
301
|
+
this.emitItem([name, " = \"", jsonName, "\""]);
|
|
302
|
+
// if (backticks) {this.emitItem("`")}
|
|
303
|
+
if (--count > 0)
|
|
304
|
+
this.emitItem([","]);
|
|
305
|
+
//} else {
|
|
306
|
+
//--count
|
|
307
|
+
//}
|
|
308
|
+
});
|
|
309
|
+
this.ensureBlankLine();
|
|
310
|
+
this.emitItem(["}"]);
|
|
311
|
+
}
|
|
312
|
+
emitUnionDefinition(u, unionName) {
|
|
313
|
+
function sortBy(t) {
|
|
314
|
+
const kind = t.kind;
|
|
315
|
+
if (kind === "class")
|
|
316
|
+
return kind;
|
|
317
|
+
return "_" + kind;
|
|
318
|
+
}
|
|
319
|
+
const emitLater = [];
|
|
320
|
+
this.emitDescription(this.descriptionForType(u));
|
|
321
|
+
const [maybeNull, nonNulls] = (0, TypeUtils_1.removeNullFromUnion)(u, sortBy);
|
|
322
|
+
const theTypes = [];
|
|
323
|
+
this.forEachUnionMember(u, nonNulls, "none", null, (_, t) => {
|
|
324
|
+
const laterType = t.kind === "array" || t.kind === "map";
|
|
325
|
+
if (laterType) {
|
|
326
|
+
emitLater.push(t);
|
|
327
|
+
}
|
|
328
|
+
theTypes.push(this.scalaType(t));
|
|
329
|
+
});
|
|
330
|
+
if (maybeNull !== null) {
|
|
331
|
+
theTypes.push(this.nameForUnionMember(u, maybeNull));
|
|
332
|
+
}
|
|
333
|
+
this.emitLine(["@untagged union ", unionName, " { "]);
|
|
334
|
+
this.indent(() => {
|
|
335
|
+
theTypes.forEach((t, i) => {
|
|
336
|
+
this.emitLine([String.fromCharCode(i + 65), " : ", t]);
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
this.emitLine("}");
|
|
340
|
+
this.ensureBlankLine();
|
|
341
|
+
emitLater.forEach(p => {
|
|
342
|
+
function ignore(_) {
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
(0, TypeUtils_1.matchCompoundType)(p, at => {
|
|
346
|
+
this.emitLine(["list ", this.scalaType(at, true), "{ member: ", this.scalaType(at.items, true), "}"]);
|
|
347
|
+
}, ignore, mt => {
|
|
348
|
+
this.emitLine(["map ", this.scalaType(mt, true), "{ key: String , value: ", this.scalaType(mt.values, true), "}"]);
|
|
349
|
+
}, ignore, ignore);
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
emitSourceStructure() {
|
|
353
|
+
this.emitHeader();
|
|
354
|
+
// Top-level arrays, maps
|
|
355
|
+
this.forEachTopLevel("leading", (t, name) => {
|
|
356
|
+
if (t instanceof Type_1.ArrayType) {
|
|
357
|
+
this.emitTopLevelArray(t, name);
|
|
358
|
+
}
|
|
359
|
+
else if (t instanceof Type_1.MapType) {
|
|
360
|
+
this.emitTopLevelMap(t, name);
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
this.forEachNamedType("leading-and-interposing", (c, n) => this.emitClassDefinition(c, n), (e, n) => this.emitEnumDefinition(e, n), (u, n) => this.emitUnionDefinition(u, n));
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
exports.Smithy4sRenderer = Smithy4sRenderer;
|
|
367
|
+
class SmithyTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
368
|
+
constructor() {
|
|
369
|
+
super("Smithy", ["Smithy"], "smithy");
|
|
370
|
+
}
|
|
371
|
+
getOptions() {
|
|
372
|
+
return [exports.SmithyOptions.framework, exports.SmithyOptions.packageName];
|
|
373
|
+
}
|
|
374
|
+
get supportsOptionalClassProperties() {
|
|
375
|
+
return true;
|
|
376
|
+
}
|
|
377
|
+
get supportsUnionsWithBothNumberTypes() {
|
|
378
|
+
return true;
|
|
379
|
+
}
|
|
380
|
+
makeRenderer(renderContext, untypedOptionValues) {
|
|
381
|
+
const options = (0, RendererOptions_1.getOptionValues)(exports.SmithyOptions, untypedOptionValues);
|
|
382
|
+
switch (options.framework) {
|
|
383
|
+
case Framework.None:
|
|
384
|
+
return new Smithy4sRenderer(this, renderContext, options);
|
|
385
|
+
default:
|
|
386
|
+
return (0, Support_1.assertNever)(options.framework);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
exports.SmithyTargetLanguage = SmithyTargetLanguage;
|