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.CrystalRenderer = exports.CrystalTargetLanguage = void 0;
|
|
3
4
|
const TargetLanguage_1 = require("../TargetLanguage");
|
|
4
5
|
const ConvenienceRenderer_1 = require("../ConvenienceRenderer");
|
|
5
6
|
const Strings_1 = require("../support/Strings");
|
|
@@ -161,35 +162,35 @@ const keywords = [
|
|
|
161
162
|
"yield"
|
|
162
163
|
];
|
|
163
164
|
function isAsciiLetterOrUnderscoreOrDigit(codePoint) {
|
|
164
|
-
if (!Strings_1.isAscii(codePoint)) {
|
|
165
|
+
if (!(0, Strings_1.isAscii)(codePoint)) {
|
|
165
166
|
return false;
|
|
166
167
|
}
|
|
167
|
-
return Strings_1.isLetterOrUnderscoreOrDigit(codePoint);
|
|
168
|
+
return (0, Strings_1.isLetterOrUnderscoreOrDigit)(codePoint);
|
|
168
169
|
}
|
|
169
170
|
function isAsciiLetterOrUnderscore(codePoint) {
|
|
170
|
-
if (!Strings_1.isAscii(codePoint)) {
|
|
171
|
+
if (!(0, Strings_1.isAscii)(codePoint)) {
|
|
171
172
|
return false;
|
|
172
173
|
}
|
|
173
|
-
return Strings_1.isLetterOrUnderscore(codePoint);
|
|
174
|
+
return (0, Strings_1.isLetterOrUnderscore)(codePoint);
|
|
174
175
|
}
|
|
175
|
-
const legalizeName = Strings_1.legalizeCharacters(isAsciiLetterOrUnderscoreOrDigit);
|
|
176
|
+
const legalizeName = (0, Strings_1.legalizeCharacters)(isAsciiLetterOrUnderscoreOrDigit);
|
|
176
177
|
function crystalStyle(original, isSnakeCase) {
|
|
177
|
-
const words = Strings_1.splitIntoWords(original);
|
|
178
|
+
const words = (0, Strings_1.splitIntoWords)(original);
|
|
178
179
|
const wordStyle = isSnakeCase ? Strings_1.allLowerWordStyle : Strings_1.firstUpperWordStyle;
|
|
179
|
-
const combined = Strings_1.combineWords(words, legalizeName, wordStyle, wordStyle, wordStyle, wordStyle, isSnakeCase ? "_" : "", isAsciiLetterOrUnderscore);
|
|
180
|
+
const combined = (0, Strings_1.combineWords)(words, legalizeName, wordStyle, wordStyle, wordStyle, wordStyle, isSnakeCase ? "_" : "", isAsciiLetterOrUnderscore);
|
|
180
181
|
return combined === "_" ? "_underscore" : combined;
|
|
181
182
|
}
|
|
182
|
-
const snakeNamingFunction = Naming_1.funPrefixNamer("default", (original) => crystalStyle(original, true));
|
|
183
|
-
const camelNamingFunction = Naming_1.funPrefixNamer("camel", (original) => crystalStyle(original, false));
|
|
183
|
+
const snakeNamingFunction = (0, Naming_1.funPrefixNamer)("default", (original) => crystalStyle(original, true));
|
|
184
|
+
const camelNamingFunction = (0, Naming_1.funPrefixNamer)("camel", (original) => crystalStyle(original, false));
|
|
184
185
|
function standardUnicodeCrystalEscape(codePoint) {
|
|
185
186
|
if (codePoint <= 0xffff) {
|
|
186
|
-
return "\\u{" + Strings_1.intToHex(codePoint, 4) + "}";
|
|
187
|
+
return "\\u{" + (0, Strings_1.intToHex)(codePoint, 4) + "}";
|
|
187
188
|
}
|
|
188
189
|
else {
|
|
189
|
-
return "\\u{" + Strings_1.intToHex(codePoint, 6) + "}";
|
|
190
|
+
return "\\u{" + (0, Strings_1.intToHex)(codePoint, 6) + "}";
|
|
190
191
|
}
|
|
191
192
|
}
|
|
192
|
-
const crystalStringEscape = Strings_1.utf32ConcatMap(Strings_1.escapeNonPrintableMapper(Strings_1.isPrintable, standardUnicodeCrystalEscape));
|
|
193
|
+
const crystalStringEscape = (0, Strings_1.utf32ConcatMap)((0, Strings_1.escapeNonPrintableMapper)(Strings_1.isPrintable, standardUnicodeCrystalEscape));
|
|
193
194
|
class CrystalRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
194
195
|
constructor(targetLanguage, renderContext) {
|
|
195
196
|
super(targetLanguage, renderContext);
|
|
@@ -229,11 +230,11 @@ class CrystalRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
229
230
|
return kind === "array" || kind === "map";
|
|
230
231
|
}
|
|
231
232
|
crystalType(t, withIssues = false) {
|
|
232
|
-
return TypeUtils_1.matchType(t, _anyType => Source_1.maybeAnnotated(withIssues, Annotation_1.anyTypeIssueAnnotation, "JSON::Any?"), _nullType => Source_1.maybeAnnotated(withIssues, Annotation_1.nullTypeIssueAnnotation, "Nil"), _boolType => "Bool", _integerType => "Int32", _doubleType => "Float64", _stringType => "String", arrayType => ["Array(", this.crystalType(arrayType.items, withIssues), ")"], classType => this.nameForNamedType(classType), mapType => ["Hash(String, ", this.crystalType(mapType.values, withIssues), ")"], _enumType => "String", unionType => {
|
|
233
|
-
const nullable = TypeUtils_1.nullableFromUnion(unionType);
|
|
233
|
+
return (0, TypeUtils_1.matchType)(t, _anyType => (0, Source_1.maybeAnnotated)(withIssues, Annotation_1.anyTypeIssueAnnotation, "JSON::Any?"), _nullType => (0, Source_1.maybeAnnotated)(withIssues, Annotation_1.nullTypeIssueAnnotation, "Nil"), _boolType => "Bool", _integerType => "Int32", _doubleType => "Float64", _stringType => "String", arrayType => ["Array(", this.crystalType(arrayType.items, withIssues), ")"], classType => this.nameForNamedType(classType), mapType => ["Hash(String, ", this.crystalType(mapType.values, withIssues), ")"], _enumType => "String", unionType => {
|
|
234
|
+
const nullable = (0, TypeUtils_1.nullableFromUnion)(unionType);
|
|
234
235
|
if (nullable !== null)
|
|
235
236
|
return this.nullableCrystalType(nullable, withIssues);
|
|
236
|
-
const [hasNull] = TypeUtils_1.removeNullFromUnion(unionType);
|
|
237
|
+
const [hasNull] = (0, TypeUtils_1.removeNullFromUnion)(unionType);
|
|
237
238
|
const name = this.nameForNamedType(unionType);
|
|
238
239
|
return hasNull !== null ? [name, "?"] : name;
|
|
239
240
|
});
|
|
@@ -273,12 +274,12 @@ class CrystalRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
273
274
|
this.emitLine("end");
|
|
274
275
|
}
|
|
275
276
|
emitUnion(u, unionName) {
|
|
276
|
-
const isMaybeWithSingleType = TypeUtils_1.nullableFromUnion(u);
|
|
277
|
+
const isMaybeWithSingleType = (0, TypeUtils_1.nullableFromUnion)(u);
|
|
277
278
|
if (isMaybeWithSingleType !== null) {
|
|
278
279
|
return;
|
|
279
280
|
}
|
|
280
281
|
this.emitDescription(this.descriptionForType(u));
|
|
281
|
-
const [, nonNulls] = TypeUtils_1.removeNullFromUnion(u);
|
|
282
|
+
const [, nonNulls] = (0, TypeUtils_1.removeNullFromUnion)(u);
|
|
282
283
|
let types = [];
|
|
283
284
|
this.forEachUnionMember(u, nonNulls, "none", null, (_name, t) => {
|
|
284
285
|
const crystalType = this.breakCycle(t, true);
|
|
@@ -21,8 +21,8 @@ export declare const dartOptions: {
|
|
|
21
21
|
export declare class DartTargetLanguage extends TargetLanguage {
|
|
22
22
|
constructor();
|
|
23
23
|
protected getOptions(): Option<any>[];
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
get supportsUnionsWithBothNumberTypes(): boolean;
|
|
25
|
+
get stringTypeMapping(): StringTypeMapping;
|
|
26
26
|
protected makeRenderer(renderContext: RenderContext, untypedOptionValues: {
|
|
27
27
|
[name: string]: any;
|
|
28
28
|
}): DartRenderer;
|
|
@@ -44,8 +44,8 @@ export declare class DartRenderer extends ConvenienceRenderer {
|
|
|
44
44
|
protected makeEnumCaseNamer(): Namer;
|
|
45
45
|
protected unionNeedsName(u: UnionType): boolean;
|
|
46
46
|
protected namedTypeToNameForTopLevel(type: Type): Type | undefined;
|
|
47
|
-
protected
|
|
48
|
-
protected
|
|
47
|
+
protected get toJson(): string;
|
|
48
|
+
protected get fromJson(): string;
|
|
49
49
|
protected makeTopLevelDependencyNames(_t: Type, name: Name): DependencyName[];
|
|
50
50
|
protected makeNamesForPropertyGetterAndSetter(_c: ClassType, _className: Name, _p: ClassProperty, _jsonName: string, name: Name): [Name, Name];
|
|
51
51
|
protected makePropertyDependencyNames(c: ClassType, className: Name, p: ClassProperty, jsonName: string, name: Name): Name[];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DartRenderer = exports.DartTargetLanguage = exports.dartOptions = void 0;
|
|
3
4
|
const Type_1 = require("../Type");
|
|
4
5
|
const TypeUtils_1 = require("../TypeUtils");
|
|
5
6
|
const Source_1 = require("../Source");
|
|
@@ -52,7 +53,7 @@ class DartTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
|
52
53
|
return mapping;
|
|
53
54
|
}
|
|
54
55
|
makeRenderer(renderContext, untypedOptionValues) {
|
|
55
|
-
const options = RendererOptions_1.getOptionValues(exports.dartOptions, untypedOptionValues);
|
|
56
|
+
const options = (0, RendererOptions_1.getOptionValues)(exports.dartOptions, untypedOptionValues);
|
|
56
57
|
return new DartRenderer(this, renderContext, options);
|
|
57
58
|
}
|
|
58
59
|
}
|
|
@@ -128,44 +129,45 @@ const keywords = [
|
|
|
128
129
|
"fromMap",
|
|
129
130
|
"toMap"
|
|
130
131
|
];
|
|
131
|
-
const typeNamingFunction = Naming_1.funPrefixNamer("types", n => dartNameStyle(true, false, n));
|
|
132
|
-
const propertyNamingFunction = Naming_1.funPrefixNamer("properties", n => dartNameStyle(false, false, n));
|
|
133
|
-
const enumCaseNamingFunction = Naming_1.funPrefixNamer("enum-cases", n => dartNameStyle(true, true, n));
|
|
132
|
+
const typeNamingFunction = (0, Naming_1.funPrefixNamer)("types", n => dartNameStyle(true, false, n));
|
|
133
|
+
const propertyNamingFunction = (0, Naming_1.funPrefixNamer)("properties", n => dartNameStyle(false, false, n));
|
|
134
|
+
const enumCaseNamingFunction = (0, Naming_1.funPrefixNamer)("enum-cases", n => dartNameStyle(true, true, n));
|
|
134
135
|
// Escape the dollar sign, which is used in string interpolation
|
|
135
|
-
const stringEscape = Strings_1.utf16ConcatMap(Strings_1.escapeNonPrintableMapper(cp => Strings_1.isPrintable(cp) && cp !== 0x24, Strings_1.standardUnicodeHexEscape));
|
|
136
|
+
const stringEscape = (0, Strings_1.utf16ConcatMap)((0, Strings_1.escapeNonPrintableMapper)(cp => (0, Strings_1.isPrintable)(cp) && cp !== 0x24, Strings_1.standardUnicodeHexEscape));
|
|
136
137
|
function isStartCharacter(codePoint) {
|
|
137
138
|
if (codePoint === 0x5f)
|
|
138
139
|
return false; // underscore
|
|
139
|
-
return Strings_1.isAscii(codePoint) && Strings_1.isLetter(codePoint);
|
|
140
|
+
return (0, Strings_1.isAscii)(codePoint) && (0, Strings_1.isLetter)(codePoint);
|
|
140
141
|
}
|
|
141
142
|
function isPartCharacter(codePoint) {
|
|
142
|
-
return isStartCharacter(codePoint) || (Strings_1.isAscii(codePoint) && Strings_1.isDigit(codePoint));
|
|
143
|
+
return isStartCharacter(codePoint) || ((0, Strings_1.isAscii)(codePoint) && (0, Strings_1.isDigit)(codePoint));
|
|
143
144
|
}
|
|
144
|
-
const legalizeName = Strings_1.utf16LegalizeCharacters(isPartCharacter);
|
|
145
|
+
const legalizeName = (0, Strings_1.utf16LegalizeCharacters)(isPartCharacter);
|
|
145
146
|
// FIXME: Handle acronyms consistently. In particular, that means that
|
|
146
147
|
// we have to use namers to produce the getter and setter names - we can't
|
|
147
148
|
// just capitalize and concatenate.
|
|
148
149
|
// https://stackoverflow.com/questions/8277355/naming-convention-for-upper-case-abbreviations
|
|
149
150
|
function dartNameStyle(startWithUpper, upperUnderscore, original) {
|
|
150
|
-
const words = Strings_1.splitIntoWords(original);
|
|
151
|
+
const words = (0, Strings_1.splitIntoWords)(original);
|
|
151
152
|
const firstWordStyle = upperUnderscore
|
|
152
153
|
? Strings_1.allUpperWordStyle
|
|
153
154
|
: startWithUpper
|
|
154
155
|
? Strings_1.firstUpperWordStyle
|
|
155
156
|
: Strings_1.allLowerWordStyle;
|
|
156
157
|
const restWordStyle = upperUnderscore ? Strings_1.allUpperWordStyle : Strings_1.firstUpperWordStyle;
|
|
157
|
-
return Strings_1.combineWords(words, legalizeName, firstWordStyle, restWordStyle, firstWordStyle, restWordStyle, upperUnderscore ? "_" : "", isStartCharacter);
|
|
158
|
+
return (0, Strings_1.combineWords)(words, legalizeName, firstWordStyle, restWordStyle, firstWordStyle, restWordStyle, upperUnderscore ? "_" : "", isStartCharacter);
|
|
158
159
|
}
|
|
159
160
|
class DartRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
161
|
+
_options;
|
|
162
|
+
_gettersAndSettersForPropertyName = new Map();
|
|
163
|
+
_needEnumValues = false;
|
|
164
|
+
classCounter = 0;
|
|
165
|
+
classPropertyCounter = 0;
|
|
166
|
+
_topLevelDependents = new Map();
|
|
167
|
+
_enumValues = new Map();
|
|
160
168
|
constructor(targetLanguage, renderContext, _options) {
|
|
161
169
|
super(targetLanguage, renderContext);
|
|
162
170
|
this._options = _options;
|
|
163
|
-
this._gettersAndSettersForPropertyName = new Map();
|
|
164
|
-
this._needEnumValues = false;
|
|
165
|
-
this.classCounter = 0;
|
|
166
|
-
this.classPropertyCounter = 0;
|
|
167
|
-
this._topLevelDependents = new Map();
|
|
168
|
-
this._enumValues = new Map();
|
|
169
171
|
}
|
|
170
172
|
forbiddenNamesForGlobalNamespace() {
|
|
171
173
|
return keywords;
|
|
@@ -186,13 +188,13 @@ class DartRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
186
188
|
return enumCaseNamingFunction;
|
|
187
189
|
}
|
|
188
190
|
unionNeedsName(u) {
|
|
189
|
-
return TypeUtils_1.nullableFromUnion(u) === null;
|
|
191
|
+
return (0, TypeUtils_1.nullableFromUnion)(u) === null;
|
|
190
192
|
}
|
|
191
193
|
namedTypeToNameForTopLevel(type) {
|
|
192
194
|
// If the top-level type doesn't contain any classes or unions
|
|
193
195
|
// we have to define a class just for the `FromJson` method, in
|
|
194
196
|
// emitFromJsonForTopLevel.
|
|
195
|
-
return TypeUtils_1.directlyReachableSingleNamedType(type);
|
|
197
|
+
return (0, TypeUtils_1.directlyReachableSingleNamedType)(type);
|
|
196
198
|
}
|
|
197
199
|
get toJson() {
|
|
198
200
|
return `to${this._options.methodNamesWithMap ? "Map" : "Json"}`;
|
|
@@ -232,8 +234,8 @@ class DartRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
232
234
|
this.emitLine("// To parse this JSON data, do");
|
|
233
235
|
this.emitLine("//");
|
|
234
236
|
this.forEachTopLevel("none", (_t, name) => {
|
|
235
|
-
const { decoder } = Support_1.defined(this._topLevelDependents.get(name));
|
|
236
|
-
this.emitLine("// final ", Source_1.modifySource(Strings_1.decapitalize, name), " = ", decoder, "(jsonString);");
|
|
237
|
+
const { decoder } = (0, Support_1.defined)(this._topLevelDependents.get(name));
|
|
238
|
+
this.emitLine("// final ", (0, Source_1.modifySource)(Strings_1.decapitalize, name), " = ", decoder, "(jsonString);");
|
|
237
239
|
});
|
|
238
240
|
this.ensureBlankLine();
|
|
239
241
|
if (this._options.requiredProperties) {
|
|
@@ -250,7 +252,7 @@ class DartRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
250
252
|
this.ensureBlankLine();
|
|
251
253
|
const optionNameIsEmpty = this._options.partName.length === 0;
|
|
252
254
|
// FIXME: This should use a `Name`, not `modifySource`
|
|
253
|
-
const name = Source_1.modifySource(Strings_1.snakeCase, optionNameIsEmpty ? [...this.topLevels.keys()][0] : this._options.partName);
|
|
255
|
+
const name = (0, Source_1.modifySource)(Strings_1.snakeCase, optionNameIsEmpty ? [...this.topLevels.keys()][0] : this._options.partName);
|
|
254
256
|
if (this._options.useFreezed) {
|
|
255
257
|
this.emitLine("part '", name, ".freezed.dart';");
|
|
256
258
|
}
|
|
@@ -268,7 +270,7 @@ class DartRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
268
270
|
this.emitLine("}");
|
|
269
271
|
}
|
|
270
272
|
dartType(t, withIssues = false) {
|
|
271
|
-
return TypeUtils_1.matchType(t, _anyType => Source_1.maybeAnnotated(withIssues, Annotation_1.anyTypeIssueAnnotation, "dynamic"), _nullType => Source_1.maybeAnnotated(withIssues, Annotation_1.nullTypeIssueAnnotation, "dynamic"), _boolType => {
|
|
273
|
+
return (0, TypeUtils_1.matchType)(t, _anyType => (0, Source_1.maybeAnnotated)(withIssues, Annotation_1.anyTypeIssueAnnotation, "dynamic"), _nullType => (0, Source_1.maybeAnnotated)(withIssues, Annotation_1.nullTypeIssueAnnotation, "dynamic"), _boolType => {
|
|
272
274
|
if (this._options.nullSafety) {
|
|
273
275
|
return ["bool", "?"];
|
|
274
276
|
}
|
|
@@ -309,7 +311,7 @@ class DartRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
309
311
|
}
|
|
310
312
|
return this.nameForNamedType(enumType);
|
|
311
313
|
}, unionType => {
|
|
312
|
-
const maybeNullable = TypeUtils_1.nullableFromUnion(unionType);
|
|
314
|
+
const maybeNullable = (0, TypeUtils_1.nullableFromUnion)(unionType);
|
|
313
315
|
if (maybeNullable === null) {
|
|
314
316
|
return "dynamic";
|
|
315
317
|
}
|
|
@@ -337,15 +339,15 @@ class DartRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
337
339
|
return ["Map.from(", map, ").map((k, v) => MapEntry<String, ", valueType, ">(k, ", valueMapper, "))"];
|
|
338
340
|
}
|
|
339
341
|
fromDynamicExpression(t, ...dynamic) {
|
|
340
|
-
return TypeUtils_1.matchType(t, _anyType => dynamic, _nullType => dynamic, // FIXME: check null
|
|
342
|
+
return (0, TypeUtils_1.matchType)(t, _anyType => dynamic, _nullType => dynamic, // FIXME: check null
|
|
341
343
|
// FIXME: check null
|
|
342
344
|
_boolType => dynamic, _integerType => dynamic, _doubleType => [dynamic, ".toDouble()"], _stringType => dynamic, arrayType => this.mapList(this.dartType(arrayType.items), dynamic, this.fromDynamicExpression(arrayType.items, "x")), classType => [this.nameForNamedType(classType), ".", this.fromJson, "(", dynamic, ")"], mapType => this.mapMap(this.dartType(mapType.values), dynamic, this.fromDynamicExpression(mapType.values, "v")), enumType => {
|
|
343
345
|
if (this._options.nullSafety) {
|
|
344
|
-
return [Support_1.defined(this._enumValues.get(enumType)), "!.map[", dynamic, "]"];
|
|
346
|
+
return [(0, Support_1.defined)(this._enumValues.get(enumType)), "!.map[", dynamic, "]"];
|
|
345
347
|
}
|
|
346
|
-
return [Support_1.defined(this._enumValues.get(enumType)), ".map[", dynamic, "]"];
|
|
348
|
+
return [(0, Support_1.defined)(this._enumValues.get(enumType)), ".map[", dynamic, "]"];
|
|
347
349
|
}, unionType => {
|
|
348
|
-
const maybeNullable = TypeUtils_1.nullableFromUnion(unionType);
|
|
350
|
+
const maybeNullable = (0, TypeUtils_1.nullableFromUnion)(unionType);
|
|
349
351
|
if (maybeNullable === null) {
|
|
350
352
|
return dynamic;
|
|
351
353
|
}
|
|
@@ -364,18 +366,18 @@ class DartRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
364
366
|
});
|
|
365
367
|
}
|
|
366
368
|
toDynamicExpression(t, ...dynamic) {
|
|
367
|
-
return TypeUtils_1.matchType(t, _anyType => dynamic, _nullType => dynamic, _boolType => dynamic, _integerType => dynamic, _doubleType => dynamic, _stringType => dynamic, arrayType => this.mapList("dynamic", dynamic, this.toDynamicExpression(arrayType.items, "x")), _classType => {
|
|
369
|
+
return (0, TypeUtils_1.matchType)(t, _anyType => dynamic, _nullType => dynamic, _boolType => dynamic, _integerType => dynamic, _doubleType => dynamic, _stringType => dynamic, arrayType => this.mapList("dynamic", dynamic, this.toDynamicExpression(arrayType.items, "x")), _classType => {
|
|
368
370
|
if (this._options.nullSafety) {
|
|
369
371
|
return [dynamic, "!.", this.toJson, "()"];
|
|
370
372
|
}
|
|
371
373
|
return [dynamic, ".", this.toJson, "()"];
|
|
372
374
|
}, mapType => this.mapMap("dynamic", dynamic, this.toDynamicExpression(mapType.values, "v")), enumType => {
|
|
373
375
|
if (this._options.nullSafety) {
|
|
374
|
-
return [Support_1.defined(this._enumValues.get(enumType)), ".reverse![", dynamic, "]"];
|
|
376
|
+
return [(0, Support_1.defined)(this._enumValues.get(enumType)), ".reverse![", dynamic, "]"];
|
|
375
377
|
}
|
|
376
|
-
return [Support_1.defined(this._enumValues.get(enumType)), ".reverse[", dynamic, "]"];
|
|
378
|
+
return [(0, Support_1.defined)(this._enumValues.get(enumType)), ".reverse[", dynamic, "]"];
|
|
377
379
|
}, unionType => {
|
|
378
|
-
const maybeNullable = TypeUtils_1.nullableFromUnion(unionType);
|
|
380
|
+
const maybeNullable = (0, TypeUtils_1.nullableFromUnion)(unionType);
|
|
379
381
|
if (maybeNullable === null) {
|
|
380
382
|
return dynamic;
|
|
381
383
|
}
|
|
@@ -522,11 +524,11 @@ class DartRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
522
524
|
emitEnumDefinition(e, enumName) {
|
|
523
525
|
const caseNames = Array.from(e.cases).map(c => this.nameForEnumCase(e, c));
|
|
524
526
|
this.emitDescription(this.descriptionForType(e));
|
|
525
|
-
this.emitLine("enum ", enumName, " { ", collection_utils_1.arrayIntercalate(", ", caseNames), " }");
|
|
527
|
+
this.emitLine("enum ", enumName, " { ", (0, collection_utils_1.arrayIntercalate)(", ", caseNames), " }");
|
|
526
528
|
if (this._options.justTypes)
|
|
527
529
|
return;
|
|
528
530
|
this.ensureBlankLine();
|
|
529
|
-
this.emitLine("final ", Support_1.defined(this._enumValues.get(e)), " = EnumValues({");
|
|
531
|
+
this.emitLine("final ", (0, Support_1.defined)(this._enumValues.get(e)), " = EnumValues({");
|
|
530
532
|
this.indent(() => {
|
|
531
533
|
this.forEachEnumCase(e, "none", (name, jsonName, pos) => {
|
|
532
534
|
const comma = pos === "first" || pos === "middle" ? "," : [];
|
|
@@ -554,7 +556,7 @@ class DartRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
554
556
|
this.emitFileHeader();
|
|
555
557
|
if (!this._options.justTypes && !this._options.codersInClass) {
|
|
556
558
|
this.forEachTopLevel("leading-and-interposing", (t, name) => {
|
|
557
|
-
const { encoder, decoder } = Support_1.defined(this._topLevelDependents.get(name));
|
|
559
|
+
const { encoder, decoder } = (0, Support_1.defined)(this._topLevelDependents.get(name));
|
|
558
560
|
this.emitLine(this.dartType(t), " ", decoder, "(String str) => ", this.fromDynamicExpression(t, "json.decode(str)"), ";");
|
|
559
561
|
this.ensureBlankLine();
|
|
560
562
|
this.emitLine("String ", encoder, "(", this.dartType(t), " data) => json.encode(", this.toDynamicExpression(t, "data"), ");");
|
|
@@ -13,8 +13,8 @@ export declare const elmOptions: {
|
|
|
13
13
|
export declare class ElmTargetLanguage extends TargetLanguage {
|
|
14
14
|
constructor();
|
|
15
15
|
protected getOptions(): Option<any>[];
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
get supportsOptionalClassProperties(): boolean;
|
|
17
|
+
get supportsUnionsWithBothNumberTypes(): boolean;
|
|
18
18
|
protected makeRenderer(renderContext: RenderContext, untypedOptionValues: {
|
|
19
19
|
[name: string]: any;
|
|
20
20
|
}): ElmRenderer;
|
|
@@ -31,13 +31,13 @@ export declare class ElmRenderer extends ConvenienceRenderer {
|
|
|
31
31
|
protected namerForObjectProperty(): Namer;
|
|
32
32
|
protected forbiddenForObjectProperties(_c: ClassType, _className: Name): ForbiddenWordsInfo;
|
|
33
33
|
protected makeUnionMemberNamer(): Namer;
|
|
34
|
-
protected
|
|
34
|
+
protected get unionMembersInGlobalNamespace(): boolean;
|
|
35
35
|
protected makeEnumCaseNamer(): Namer;
|
|
36
|
-
protected
|
|
36
|
+
protected get enumCasesInGlobalNamespace(): boolean;
|
|
37
37
|
protected proposeUnionMemberName(u: UnionType, unionName: Name, fieldType: Type, lookup: (n: Name) => string): string;
|
|
38
|
-
protected
|
|
38
|
+
protected get commentLineStart(): string;
|
|
39
39
|
protected emitDescriptionBlock(lines: Sourcelike[]): void;
|
|
40
|
-
private
|
|
40
|
+
private get arrayType();
|
|
41
41
|
private elmType;
|
|
42
42
|
private elmProperty;
|
|
43
43
|
private decoderNameForNamedType;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ElmRenderer = exports.ElmTargetLanguage = exports.elmOptions = void 0;
|
|
3
4
|
const collection_utils_1 = require("collection-utils");
|
|
4
5
|
const TargetLanguage_1 = require("../TargetLanguage");
|
|
5
6
|
const RendererOptions_1 = require("../RendererOptions");
|
|
@@ -34,7 +35,7 @@ class ElmTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
|
34
35
|
return true;
|
|
35
36
|
}
|
|
36
37
|
makeRenderer(renderContext, untypedOptionValues) {
|
|
37
|
-
return new ElmRenderer(this, renderContext, RendererOptions_1.getOptionValues(exports.elmOptions, untypedOptionValues));
|
|
38
|
+
return new ElmRenderer(this, renderContext, (0, RendererOptions_1.getOptionValues)(exports.elmOptions, untypedOptionValues));
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
41
|
exports.ElmTargetLanguage = ElmTargetLanguage;
|
|
@@ -78,19 +79,19 @@ const forbiddenNames = [
|
|
|
78
79
|
"String",
|
|
79
80
|
"Float"
|
|
80
81
|
];
|
|
81
|
-
const legalizeName = Strings_1.legalizeCharacters(cp => Strings_1.isAscii(cp) && Strings_1.isLetterOrUnderscoreOrDigit(cp));
|
|
82
|
+
const legalizeName = (0, Strings_1.legalizeCharacters)(cp => (0, Strings_1.isAscii)(cp) && (0, Strings_1.isLetterOrUnderscoreOrDigit)(cp));
|
|
82
83
|
function elmNameStyle(original, upper) {
|
|
83
|
-
const words = Strings_1.splitIntoWords(original);
|
|
84
|
-
return Strings_1.combineWords(words, legalizeName, upper ? Strings_1.firstUpperWordStyle : Strings_1.allLowerWordStyle, Strings_1.firstUpperWordStyle, upper ? Strings_1.allUpperWordStyle : Strings_1.allLowerWordStyle, Strings_1.allUpperWordStyle, "", Strings_1.isLetterOrUnderscore);
|
|
84
|
+
const words = (0, Strings_1.splitIntoWords)(original);
|
|
85
|
+
return (0, Strings_1.combineWords)(words, legalizeName, upper ? Strings_1.firstUpperWordStyle : Strings_1.allLowerWordStyle, Strings_1.firstUpperWordStyle, upper ? Strings_1.allUpperWordStyle : Strings_1.allLowerWordStyle, Strings_1.allUpperWordStyle, "", Strings_1.isLetterOrUnderscore);
|
|
85
86
|
}
|
|
86
|
-
const upperNamingFunction = Naming_1.funPrefixNamer("upper", n => elmNameStyle(n, true));
|
|
87
|
-
const lowerNamingFunction = Naming_1.funPrefixNamer("lower", n => elmNameStyle(n, false));
|
|
87
|
+
const upperNamingFunction = (0, Naming_1.funPrefixNamer)("upper", n => elmNameStyle(n, true));
|
|
88
|
+
const lowerNamingFunction = (0, Naming_1.funPrefixNamer)("lower", n => elmNameStyle(n, false));
|
|
88
89
|
function requiredOrOptional(p) {
|
|
89
90
|
function optional(fallback) {
|
|
90
91
|
return { reqOrOpt: "Jpipe.optional", fallback };
|
|
91
92
|
}
|
|
92
93
|
const t = p.type;
|
|
93
|
-
if (p.isOptional || (t instanceof Type_1.UnionType && TypeUtils_1.nullableFromUnion(t) !== null)) {
|
|
94
|
+
if (p.isOptional || (t instanceof Type_1.UnionType && (0, TypeUtils_1.nullableFromUnion)(t) !== null)) {
|
|
94
95
|
return optional(" Nothing");
|
|
95
96
|
}
|
|
96
97
|
if (t.kind === "null") {
|
|
@@ -99,11 +100,12 @@ function requiredOrOptional(p) {
|
|
|
99
100
|
return { reqOrOpt: "Jpipe.required", fallback: "" };
|
|
100
101
|
}
|
|
101
102
|
class ElmRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
103
|
+
_options;
|
|
104
|
+
_topLevelDependents = new Map();
|
|
105
|
+
_namedTypeDependents = new Map();
|
|
102
106
|
constructor(targetLanguage, renderContext, _options) {
|
|
103
107
|
super(targetLanguage, renderContext);
|
|
104
108
|
this._options = _options;
|
|
105
|
-
this._topLevelDependents = new Map();
|
|
106
|
-
this._namedTypeDependents = new Map();
|
|
107
109
|
}
|
|
108
110
|
forbiddenNamesForGlobalNamespace() {
|
|
109
111
|
return forbiddenNames;
|
|
@@ -166,20 +168,20 @@ class ElmRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
166
168
|
return this._options.useList ? "List" : "Array";
|
|
167
169
|
}
|
|
168
170
|
elmType(t, noOptional = false) {
|
|
169
|
-
return TypeUtils_1.matchType(t, _anyType => Source_1.singleWord(Source_1.annotated(Annotation_1.anyTypeIssueAnnotation, "Jdec.Value")), _nullType => Source_1.singleWord(Source_1.annotated(Annotation_1.nullTypeIssueAnnotation, "()")), _boolType => Source_1.singleWord("Bool"), _integerType => Source_1.singleWord("Int"), _doubleType => Source_1.singleWord("Float"), _stringType => Source_1.singleWord("String"), arrayType => Source_1.multiWord(" ", this.arrayType, Source_1.parenIfNeeded(this.elmType(arrayType.items))), classType => Source_1.singleWord(this.nameForNamedType(classType)), mapType => Source_1.multiWord(" ", "Dict String", Source_1.parenIfNeeded(this.elmType(mapType.values))), enumType => Source_1.singleWord(this.nameForNamedType(enumType)), unionType => {
|
|
170
|
-
const nullable = TypeUtils_1.nullableFromUnion(unionType);
|
|
171
|
+
return (0, TypeUtils_1.matchType)(t, _anyType => (0, Source_1.singleWord)((0, Source_1.annotated)(Annotation_1.anyTypeIssueAnnotation, "Jdec.Value")), _nullType => (0, Source_1.singleWord)((0, Source_1.annotated)(Annotation_1.nullTypeIssueAnnotation, "()")), _boolType => (0, Source_1.singleWord)("Bool"), _integerType => (0, Source_1.singleWord)("Int"), _doubleType => (0, Source_1.singleWord)("Float"), _stringType => (0, Source_1.singleWord)("String"), arrayType => (0, Source_1.multiWord)(" ", this.arrayType, (0, Source_1.parenIfNeeded)(this.elmType(arrayType.items))), classType => (0, Source_1.singleWord)(this.nameForNamedType(classType)), mapType => (0, Source_1.multiWord)(" ", "Dict String", (0, Source_1.parenIfNeeded)(this.elmType(mapType.values))), enumType => (0, Source_1.singleWord)(this.nameForNamedType(enumType)), unionType => {
|
|
172
|
+
const nullable = (0, TypeUtils_1.nullableFromUnion)(unionType);
|
|
171
173
|
if (nullable !== null) {
|
|
172
174
|
const nullableType = this.elmType(nullable);
|
|
173
175
|
if (noOptional)
|
|
174
176
|
return nullableType;
|
|
175
|
-
return Source_1.multiWord(" ", "Maybe", Source_1.parenIfNeeded(nullableType));
|
|
177
|
+
return (0, Source_1.multiWord)(" ", "Maybe", (0, Source_1.parenIfNeeded)(nullableType));
|
|
176
178
|
}
|
|
177
|
-
return Source_1.singleWord(this.nameForNamedType(unionType));
|
|
179
|
+
return (0, Source_1.singleWord)(this.nameForNamedType(unionType));
|
|
178
180
|
});
|
|
179
181
|
}
|
|
180
182
|
elmProperty(p) {
|
|
181
183
|
if (p.isOptional) {
|
|
182
|
-
return Source_1.multiWord(" ", "Maybe", Source_1.parenIfNeeded(this.elmType(p.type, true))).source;
|
|
184
|
+
return (0, Source_1.multiWord)(" ", "Maybe", (0, Source_1.parenIfNeeded)(this.elmType(p.type, true))).source;
|
|
183
185
|
}
|
|
184
186
|
else {
|
|
185
187
|
return this.elmType(p.type).source;
|
|
@@ -187,23 +189,23 @@ class ElmRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
187
189
|
}
|
|
188
190
|
decoderNameForNamedType(t) {
|
|
189
191
|
const name = this.nameForNamedType(t);
|
|
190
|
-
return Support_1.defined(this._namedTypeDependents.get(name)).decoder;
|
|
192
|
+
return (0, Support_1.defined)(this._namedTypeDependents.get(name)).decoder;
|
|
191
193
|
}
|
|
192
194
|
decoderNameForType(t, noOptional = false) {
|
|
193
|
-
return TypeUtils_1.matchType(t, _anyType => Source_1.singleWord("Jdec.value"), _nullType => Source_1.multiWord(" ", "Jdec.null", "()"), _boolType => Source_1.singleWord("Jdec.bool"), _integerType => Source_1.singleWord("Jdec.int"), _doubleType => Source_1.singleWord("Jdec.float"), _stringType => Source_1.singleWord("Jdec.string"), arrayType => Source_1.multiWord(" ", ["Jdec.", Strings_1.decapitalize(this.arrayType)], Source_1.parenIfNeeded(this.decoderNameForType(arrayType.items))), classType => Source_1.singleWord(this.decoderNameForNamedType(classType)), mapType => Source_1.multiWord(" ", "Jdec.dict", Source_1.parenIfNeeded(this.decoderNameForType(mapType.values))), enumType => Source_1.singleWord(this.decoderNameForNamedType(enumType)), unionType => {
|
|
194
|
-
const nullable = TypeUtils_1.nullableFromUnion(unionType);
|
|
195
|
+
return (0, TypeUtils_1.matchType)(t, _anyType => (0, Source_1.singleWord)("Jdec.value"), _nullType => (0, Source_1.multiWord)(" ", "Jdec.null", "()"), _boolType => (0, Source_1.singleWord)("Jdec.bool"), _integerType => (0, Source_1.singleWord)("Jdec.int"), _doubleType => (0, Source_1.singleWord)("Jdec.float"), _stringType => (0, Source_1.singleWord)("Jdec.string"), arrayType => (0, Source_1.multiWord)(" ", ["Jdec.", (0, Strings_1.decapitalize)(this.arrayType)], (0, Source_1.parenIfNeeded)(this.decoderNameForType(arrayType.items))), classType => (0, Source_1.singleWord)(this.decoderNameForNamedType(classType)), mapType => (0, Source_1.multiWord)(" ", "Jdec.dict", (0, Source_1.parenIfNeeded)(this.decoderNameForType(mapType.values))), enumType => (0, Source_1.singleWord)(this.decoderNameForNamedType(enumType)), unionType => {
|
|
196
|
+
const nullable = (0, TypeUtils_1.nullableFromUnion)(unionType);
|
|
195
197
|
if (nullable !== null) {
|
|
196
198
|
const nullableDecoder = this.decoderNameForType(nullable);
|
|
197
199
|
if (noOptional)
|
|
198
200
|
return nullableDecoder;
|
|
199
|
-
return Source_1.multiWord(" ", "Jdec.nullable", Source_1.parenIfNeeded(nullableDecoder));
|
|
201
|
+
return (0, Source_1.multiWord)(" ", "Jdec.nullable", (0, Source_1.parenIfNeeded)(nullableDecoder));
|
|
200
202
|
}
|
|
201
|
-
return Source_1.singleWord(this.decoderNameForNamedType(unionType));
|
|
203
|
+
return (0, Source_1.singleWord)(this.decoderNameForNamedType(unionType));
|
|
202
204
|
});
|
|
203
205
|
}
|
|
204
206
|
decoderNameForProperty(p) {
|
|
205
207
|
if (p.isOptional) {
|
|
206
|
-
return Source_1.multiWord(" ", "Jdec.nullable", Source_1.parenIfNeeded(this.decoderNameForType(p.type, true)));
|
|
208
|
+
return (0, Source_1.multiWord)(" ", "Jdec.nullable", (0, Source_1.parenIfNeeded)(this.decoderNameForType(p.type, true)));
|
|
207
209
|
}
|
|
208
210
|
else {
|
|
209
211
|
return this.decoderNameForType(p.type);
|
|
@@ -211,23 +213,23 @@ class ElmRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
211
213
|
}
|
|
212
214
|
encoderNameForNamedType(t) {
|
|
213
215
|
const name = this.nameForNamedType(t);
|
|
214
|
-
return Support_1.defined(this._namedTypeDependents.get(name)).encoder;
|
|
216
|
+
return (0, Support_1.defined)(this._namedTypeDependents.get(name)).encoder;
|
|
215
217
|
}
|
|
216
218
|
encoderNameForType(t, noOptional = false) {
|
|
217
|
-
return TypeUtils_1.matchType(t, _anyType => Source_1.singleWord("identity"), _nullType => Source_1.multiWord(" ", "always", "Jenc.null"), _boolType => Source_1.singleWord("Jenc.bool"), _integerType => Source_1.singleWord("Jenc.int"), _doubleType => Source_1.singleWord("Jenc.float"), _stringType => Source_1.singleWord("Jenc.string"), arrayType => Source_1.multiWord(" ", ["make", this.arrayType, "Encoder"], Source_1.parenIfNeeded(this.encoderNameForType(arrayType.items))), classType => Source_1.singleWord(this.encoderNameForNamedType(classType)), mapType => Source_1.multiWord(" ", "makeDictEncoder", Source_1.parenIfNeeded(this.encoderNameForType(mapType.values))), enumType => Source_1.singleWord(this.encoderNameForNamedType(enumType)), unionType => {
|
|
218
|
-
const nullable = TypeUtils_1.nullableFromUnion(unionType);
|
|
219
|
+
return (0, TypeUtils_1.matchType)(t, _anyType => (0, Source_1.singleWord)("identity"), _nullType => (0, Source_1.multiWord)(" ", "always", "Jenc.null"), _boolType => (0, Source_1.singleWord)("Jenc.bool"), _integerType => (0, Source_1.singleWord)("Jenc.int"), _doubleType => (0, Source_1.singleWord)("Jenc.float"), _stringType => (0, Source_1.singleWord)("Jenc.string"), arrayType => (0, Source_1.multiWord)(" ", ["make", this.arrayType, "Encoder"], (0, Source_1.parenIfNeeded)(this.encoderNameForType(arrayType.items))), classType => (0, Source_1.singleWord)(this.encoderNameForNamedType(classType)), mapType => (0, Source_1.multiWord)(" ", "makeDictEncoder", (0, Source_1.parenIfNeeded)(this.encoderNameForType(mapType.values))), enumType => (0, Source_1.singleWord)(this.encoderNameForNamedType(enumType)), unionType => {
|
|
220
|
+
const nullable = (0, TypeUtils_1.nullableFromUnion)(unionType);
|
|
219
221
|
if (nullable !== null) {
|
|
220
222
|
const nullableEncoder = this.encoderNameForType(nullable);
|
|
221
223
|
if (noOptional)
|
|
222
224
|
return nullableEncoder;
|
|
223
|
-
return Source_1.multiWord(" ", "makeNullableEncoder", Source_1.parenIfNeeded(nullableEncoder));
|
|
225
|
+
return (0, Source_1.multiWord)(" ", "makeNullableEncoder", (0, Source_1.parenIfNeeded)(nullableEncoder));
|
|
224
226
|
}
|
|
225
|
-
return Source_1.singleWord(this.encoderNameForNamedType(unionType));
|
|
227
|
+
return (0, Source_1.singleWord)(this.encoderNameForNamedType(unionType));
|
|
226
228
|
});
|
|
227
229
|
}
|
|
228
230
|
encoderNameForProperty(p) {
|
|
229
231
|
if (p.isOptional) {
|
|
230
|
-
return Source_1.multiWord(" ", "makeNullableEncoder", Source_1.parenIfNeeded(this.encoderNameForType(p.type, true)));
|
|
232
|
+
return (0, Source_1.multiWord)(" ", "makeNullableEncoder", (0, Source_1.parenIfNeeded)(this.encoderNameForType(p.type, true)));
|
|
231
233
|
}
|
|
232
234
|
else {
|
|
233
235
|
return this.encoderNameForType(p.type);
|
|
@@ -288,17 +290,17 @@ class ElmRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
288
290
|
this.emitLine(equalsOrPipe, " ", constructor);
|
|
289
291
|
}
|
|
290
292
|
else {
|
|
291
|
-
this.emitLine(equalsOrPipe, " ", constructor, " ", Source_1.parenIfNeeded(this.elmType(t)));
|
|
293
|
+
this.emitLine(equalsOrPipe, " ", constructor, " ", (0, Source_1.parenIfNeeded)(this.elmType(t)));
|
|
292
294
|
}
|
|
293
295
|
onFirst = false;
|
|
294
296
|
});
|
|
295
297
|
});
|
|
296
298
|
}
|
|
297
299
|
emitTopLevelFunctions(t, topLevelName) {
|
|
298
|
-
const { encoder, decoder } = Support_1.defined(this._topLevelDependents.get(topLevelName));
|
|
300
|
+
const { encoder, decoder } = (0, Support_1.defined)(this._topLevelDependents.get(topLevelName));
|
|
299
301
|
if (this.namedTypeToNameForTopLevel(t) === undefined) {
|
|
300
|
-
this.emitLine(Support_1.defined(decoder), " : Jdec.Decoder ", topLevelName);
|
|
301
|
-
this.emitLine(Support_1.defined(decoder), " = ", this.decoderNameForType(t).source);
|
|
302
|
+
this.emitLine((0, Support_1.defined)(decoder), " : Jdec.Decoder ", topLevelName);
|
|
303
|
+
this.emitLine((0, Support_1.defined)(decoder), " = ", this.decoderNameForType(t).source);
|
|
302
304
|
this.ensureBlankLine();
|
|
303
305
|
}
|
|
304
306
|
this.emitLine(encoder, " : ", topLevelName, " -> String");
|
|
@@ -312,9 +314,9 @@ class ElmRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
312
314
|
this.emitLine("Jpipe.decode ", className);
|
|
313
315
|
this.indent(() => {
|
|
314
316
|
this.forEachClassProperty(c, "none", (_, jsonName, p) => {
|
|
315
|
-
const propDecoder = Source_1.parenIfNeeded(this.decoderNameForProperty(p));
|
|
317
|
+
const propDecoder = (0, Source_1.parenIfNeeded)(this.decoderNameForProperty(p));
|
|
316
318
|
const { reqOrOpt, fallback } = requiredOrOptional(p);
|
|
317
|
-
this.emitLine("|> ", reqOrOpt, ' "', Strings_1.stringEscape(jsonName), '" ', propDecoder, fallback);
|
|
319
|
+
this.emitLine("|> ", reqOrOpt, ' "', (0, Strings_1.stringEscape)(jsonName), '" ', propDecoder, fallback);
|
|
318
320
|
});
|
|
319
321
|
});
|
|
320
322
|
});
|
|
@@ -329,7 +331,7 @@ class ElmRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
329
331
|
this.forEachClassProperty(c, "none", (name, jsonName, p) => {
|
|
330
332
|
const bracketOrComma = onFirst ? "[" : ",";
|
|
331
333
|
const propEncoder = this.encoderNameForProperty(p).source;
|
|
332
|
-
this.emitLine(bracketOrComma, ' ("', Strings_1.stringEscape(jsonName), '", ', propEncoder, " x.", name, ")");
|
|
334
|
+
this.emitLine(bracketOrComma, ' ("', (0, Strings_1.stringEscape)(jsonName), '", ', propEncoder, " x.", name, ")");
|
|
333
335
|
onFirst = false;
|
|
334
336
|
});
|
|
335
337
|
if (onFirst) {
|
|
@@ -351,7 +353,7 @@ class ElmRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
351
353
|
this.emitLine("case str of");
|
|
352
354
|
this.indent(() => {
|
|
353
355
|
this.forEachEnumCase(e, "none", (name, jsonName) => {
|
|
354
|
-
this.emitLine('"', Strings_1.stringEscape(jsonName), '" -> Jdec.succeed ', name);
|
|
356
|
+
this.emitLine('"', (0, Strings_1.stringEscape)(jsonName), '" -> Jdec.succeed ', name);
|
|
355
357
|
});
|
|
356
358
|
this.emitLine('somethingElse -> Jdec.fail <| "Invalid ', enumName, ': " ++ somethingElse');
|
|
357
359
|
});
|
|
@@ -365,7 +367,7 @@ class ElmRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
365
367
|
this.emitLine(encoderName, " x = case x of");
|
|
366
368
|
this.indent(() => {
|
|
367
369
|
this.forEachEnumCase(e, "none", (name, jsonName) => {
|
|
368
|
-
this.emitLine(name, ' -> Jenc.string "', Strings_1.stringEscape(jsonName), '"');
|
|
370
|
+
this.emitLine(name, ' -> Jenc.string "', (0, Strings_1.stringEscape)(jsonName), '"');
|
|
369
371
|
});
|
|
370
372
|
});
|
|
371
373
|
}
|
|
@@ -396,7 +398,7 @@ class ElmRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
396
398
|
this.emitLine(bracketOrComma, " Jdec.null ", constructor);
|
|
397
399
|
}
|
|
398
400
|
else {
|
|
399
|
-
const decoder = Source_1.parenIfNeeded(this.decoderNameForType(t));
|
|
401
|
+
const decoder = (0, Source_1.parenIfNeeded)(this.decoderNameForType(t));
|
|
400
402
|
this.emitLine(bracketOrComma, " Jdec.map ", constructor, " ", decoder);
|
|
401
403
|
}
|
|
402
404
|
onFirst = false;
|
|
@@ -424,23 +426,23 @@ class ElmRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
424
426
|
const exports = [];
|
|
425
427
|
const topLevelDecoders = [];
|
|
426
428
|
this.forEachTopLevel("none", (_, name) => {
|
|
427
|
-
let { encoder, decoder } = Support_1.defined(this._topLevelDependents.get(name));
|
|
429
|
+
let { encoder, decoder } = (0, Support_1.defined)(this._topLevelDependents.get(name));
|
|
428
430
|
if (decoder === undefined) {
|
|
429
|
-
decoder = Support_1.defined(this._namedTypeDependents.get(name)).decoder;
|
|
431
|
+
decoder = (0, Support_1.defined)(this._namedTypeDependents.get(name)).decoder;
|
|
430
432
|
}
|
|
431
433
|
topLevelDecoders.push(decoder);
|
|
432
434
|
exports.push(name, encoder, decoder);
|
|
433
435
|
});
|
|
434
436
|
this.forEachObject("none", (t, name) => {
|
|
435
|
-
if (!collection_utils_1.mapContains(this.topLevels, t))
|
|
437
|
+
if (!(0, collection_utils_1.mapContains)(this.topLevels, t))
|
|
436
438
|
exports.push(name);
|
|
437
439
|
});
|
|
438
440
|
this.forEachEnum("none", (t, name) => {
|
|
439
|
-
if (!collection_utils_1.mapContains(this.topLevels, t))
|
|
441
|
+
if (!(0, collection_utils_1.mapContains)(this.topLevels, t))
|
|
440
442
|
exports.push([name, "(..)"]);
|
|
441
443
|
});
|
|
442
444
|
this.forEachUnion("none", (t, name) => {
|
|
443
|
-
if (!collection_utils_1.mapContains(this.topLevels, t))
|
|
445
|
+
if (!(0, collection_utils_1.mapContains)(this.topLevels, t))
|
|
444
446
|
exports.push([name, "(..)"]);
|
|
445
447
|
});
|
|
446
448
|
if (this.leadingComments !== undefined) {
|
|
@@ -456,14 +458,14 @@ class ElmRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
456
458
|
"",
|
|
457
459
|
" import Json.Decode exposing (decodeString)`);"
|
|
458
460
|
]);
|
|
459
|
-
this.emitLine("-- import ", this._options.moduleName, " exposing (", collection_utils_1.arrayIntercalate(", ", topLevelDecoders), ")");
|
|
461
|
+
this.emitLine("-- import ", this._options.moduleName, " exposing (", (0, collection_utils_1.arrayIntercalate)(", ", topLevelDecoders), ")");
|
|
460
462
|
this.emitMultiline(`--
|
|
461
463
|
-- and you're off to the races with
|
|
462
464
|
--`);
|
|
463
465
|
this.forEachTopLevel("none", (_, name) => {
|
|
464
|
-
let { decoder } = Support_1.defined(this._topLevelDependents.get(name));
|
|
466
|
+
let { decoder } = (0, Support_1.defined)(this._topLevelDependents.get(name));
|
|
465
467
|
if (decoder === undefined) {
|
|
466
|
-
decoder = Support_1.defined(this._namedTypeDependents.get(name)).decoder;
|
|
468
|
+
decoder = (0, Support_1.defined)(this._namedTypeDependents.get(name)).decoder;
|
|
467
469
|
}
|
|
468
470
|
this.emitLine("-- decodeString ", decoder, " myJsonString");
|
|
469
471
|
});
|
|
@@ -503,7 +505,7 @@ import Dict exposing (Dict, map, toList)`);
|
|
|
503
505
|
this.emitLine("make", this.arrayType, "Encoder : (a -> Jenc.Value) -> ", this.arrayType, " a -> Jenc.Value");
|
|
504
506
|
this.emitLine("make", this.arrayType, "Encoder f arr =");
|
|
505
507
|
this.indent(() => {
|
|
506
|
-
this.emitLine("Jenc.", Strings_1.decapitalize(this.arrayType), " (", this.arrayType, ".map f arr)");
|
|
508
|
+
this.emitLine("Jenc.", (0, Strings_1.decapitalize)(this.arrayType), " (", this.arrayType, ".map f arr)");
|
|
507
509
|
});
|
|
508
510
|
this.ensureBlankLine();
|
|
509
511
|
this.emitMultiline(`makeDictEncoder : (a -> Jenc.Value) -> Dict String a -> Jenc.Value
|