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