quicktype 17.0.5 → 18.0.0
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 +12 -9
- package/dist/quicktype-core/language/CPlusPlus.js +283 -217
- 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 +19 -17
- 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.JacksonRenderer = exports.JavaRenderer = exports.javaNameStyle = exports.stringEscape = exports.JavaTargetLanguage = exports.javaOptions = void 0;
|
|
3
4
|
const Annotation_1 = require("../Annotation");
|
|
4
5
|
const ConvenienceRenderer_1 = require("../ConvenienceRenderer");
|
|
5
6
|
const Naming_1 = require("../Naming");
|
|
@@ -21,7 +22,7 @@ exports.javaOptions = {
|
|
|
21
22
|
["java8", "java8"],
|
|
22
23
|
["legacy", "legacy"]
|
|
23
24
|
], "java8"),
|
|
24
|
-
acronymStyle: Acronyms_1.acronymOption(Acronyms_1.AcronymStyleOptions.Pascal),
|
|
25
|
+
acronymStyle: (0, Acronyms_1.acronymOption)(Acronyms_1.AcronymStyleOptions.Pascal),
|
|
25
26
|
// FIXME: Do this via a configurable named eventually.
|
|
26
27
|
packageName: new RendererOptions_1.StringOption("package", "Generated package name", "NAME", "io.quicktype"),
|
|
27
28
|
lombok: new RendererOptions_1.BooleanOption("lombok", "Use lombok", false, "primary"),
|
|
@@ -46,7 +47,7 @@ class JavaTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
|
46
47
|
return true;
|
|
47
48
|
}
|
|
48
49
|
makeRenderer(renderContext, untypedOptionValues) {
|
|
49
|
-
const options = RendererOptions_1.getOptionValues(exports.javaOptions, untypedOptionValues);
|
|
50
|
+
const options = (0, RendererOptions_1.getOptionValues)(exports.javaOptions, untypedOptionValues);
|
|
50
51
|
if (options.justTypes) {
|
|
51
52
|
return new JavaRenderer(this, renderContext, options);
|
|
52
53
|
}
|
|
@@ -130,63 +131,62 @@ const javaKeywords = [
|
|
|
130
131
|
"false",
|
|
131
132
|
"true"
|
|
132
133
|
];
|
|
133
|
-
exports.stringEscape = Strings_1.utf16ConcatMap(Strings_1.escapeNonPrintableMapper(Strings_1.isAscii, Strings_1.standardUnicodeHexEscape));
|
|
134
|
+
exports.stringEscape = (0, Strings_1.utf16ConcatMap)((0, Strings_1.escapeNonPrintableMapper)(Strings_1.isAscii, Strings_1.standardUnicodeHexEscape));
|
|
134
135
|
function isStartCharacter(codePoint) {
|
|
135
136
|
if (codePoint === 0x5f)
|
|
136
137
|
return true; // underscore
|
|
137
|
-
return Strings_1.isAscii(codePoint) && Strings_1.isLetter(codePoint);
|
|
138
|
+
return (0, Strings_1.isAscii)(codePoint) && (0, Strings_1.isLetter)(codePoint);
|
|
138
139
|
}
|
|
139
140
|
function isPartCharacter(codePoint) {
|
|
140
|
-
return isStartCharacter(codePoint) || (Strings_1.isAscii(codePoint) && Strings_1.isDigit(codePoint));
|
|
141
|
+
return isStartCharacter(codePoint) || ((0, Strings_1.isAscii)(codePoint) && (0, Strings_1.isDigit)(codePoint));
|
|
141
142
|
}
|
|
142
|
-
const legalizeName = Strings_1.utf16LegalizeCharacters(isPartCharacter);
|
|
143
|
+
const legalizeName = (0, Strings_1.utf16LegalizeCharacters)(isPartCharacter);
|
|
143
144
|
function javaNameStyle(startWithUpper, upperUnderscore, original, acronymsStyle = Strings_1.allUpperWordStyle) {
|
|
144
|
-
const words = Strings_1.splitIntoWords(original);
|
|
145
|
-
return Strings_1.combineWords(words, legalizeName, upperUnderscore ? Strings_1.allUpperWordStyle : startWithUpper ? Strings_1.firstUpperWordStyle : Strings_1.allLowerWordStyle, upperUnderscore ? Strings_1.allUpperWordStyle : Strings_1.firstUpperWordStyle, upperUnderscore || startWithUpper ? Strings_1.allUpperWordStyle : Strings_1.allLowerWordStyle, acronymsStyle, upperUnderscore ? "_" : "", isStartCharacter);
|
|
145
|
+
const words = (0, Strings_1.splitIntoWords)(original);
|
|
146
|
+
return (0, Strings_1.combineWords)(words, legalizeName, upperUnderscore ? Strings_1.allUpperWordStyle : startWithUpper ? Strings_1.firstUpperWordStyle : Strings_1.allLowerWordStyle, upperUnderscore ? Strings_1.allUpperWordStyle : Strings_1.firstUpperWordStyle, upperUnderscore || startWithUpper ? Strings_1.allUpperWordStyle : Strings_1.allLowerWordStyle, acronymsStyle, upperUnderscore ? "_" : "", isStartCharacter);
|
|
146
147
|
}
|
|
147
148
|
exports.javaNameStyle = javaNameStyle;
|
|
148
149
|
class JavaDateTimeProvider {
|
|
150
|
+
_renderer;
|
|
151
|
+
_className;
|
|
149
152
|
constructor(_renderer, _className) {
|
|
150
153
|
this._renderer = _renderer;
|
|
151
154
|
this._className = _className;
|
|
152
|
-
this.shouldEmitDateTimeConverter = true;
|
|
153
|
-
this.shouldEmitTimeConverter = true;
|
|
154
|
-
this.shouldEmitDateConverter = true;
|
|
155
155
|
}
|
|
156
|
+
shouldEmitDateTimeConverter = true;
|
|
157
|
+
shouldEmitTimeConverter = true;
|
|
158
|
+
shouldEmitDateConverter = true;
|
|
156
159
|
}
|
|
157
160
|
class Java8DateTimeProvider extends JavaDateTimeProvider {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
this.dateJacksonAnnotations = [];
|
|
188
|
-
this.timeJacksonAnnotations = [];
|
|
189
|
-
}
|
|
161
|
+
keywords = [
|
|
162
|
+
"LocalDate",
|
|
163
|
+
"OffsetDateTime",
|
|
164
|
+
"OffsetTime",
|
|
165
|
+
"ZoneOffset",
|
|
166
|
+
"ZonedDateTime",
|
|
167
|
+
"DateTimeFormatter",
|
|
168
|
+
"DateTimeFormatterBuilder",
|
|
169
|
+
"ChronoField"
|
|
170
|
+
];
|
|
171
|
+
dateTimeImports = ["java.time.OffsetDateTime"];
|
|
172
|
+
dateImports = ["java.time.LocalDate"];
|
|
173
|
+
timeImports = ["java.time.OffsetTime"];
|
|
174
|
+
converterImports = [
|
|
175
|
+
"java.time.LocalDate",
|
|
176
|
+
"java.time.OffsetDateTime",
|
|
177
|
+
"java.time.OffsetTime",
|
|
178
|
+
"java.time.ZoneOffset",
|
|
179
|
+
"java.time.ZonedDateTime",
|
|
180
|
+
"java.time.format.DateTimeFormatter",
|
|
181
|
+
"java.time.format.DateTimeFormatterBuilder",
|
|
182
|
+
"java.time.temporal.ChronoField"
|
|
183
|
+
];
|
|
184
|
+
dateTimeType = "OffsetDateTime";
|
|
185
|
+
dateType = "LocalDate";
|
|
186
|
+
timeType = "OffsetTime";
|
|
187
|
+
dateTimeJacksonAnnotations = [];
|
|
188
|
+
dateJacksonAnnotations = [];
|
|
189
|
+
timeJacksonAnnotations = [];
|
|
190
190
|
emitDateTimeConverters() {
|
|
191
191
|
this._renderer.ensureBlankLine();
|
|
192
192
|
this._renderer.emitLine("private static final DateTimeFormatter DATE_TIME_FORMATTER = new DateTimeFormatterBuilder()");
|
|
@@ -240,22 +240,17 @@ class Java8DateTimeProvider extends JavaDateTimeProvider {
|
|
|
240
240
|
}
|
|
241
241
|
}
|
|
242
242
|
class JavaLegacyDateTimeProvider extends JavaDateTimeProvider {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
this.dateJacksonAnnotations = ['@JsonFormat(pattern = "yyyy-MM-dd")'];
|
|
255
|
-
this.timeJacksonAnnotations = ['@JsonFormat(pattern = "HH:mm:ssX", timezone = "UTC")'];
|
|
256
|
-
this.shouldEmitTimeConverter = false;
|
|
257
|
-
this.shouldEmitDateConverter = false;
|
|
258
|
-
}
|
|
243
|
+
keywords = ["SimpleDateFormat", "Date"];
|
|
244
|
+
dateTimeImports = ["java.util.Date"];
|
|
245
|
+
dateImports = ["java.util.Date"];
|
|
246
|
+
timeImports = ["java.util.Date"];
|
|
247
|
+
converterImports = ["java.util.Date", "java.text.SimpleDateFormat"];
|
|
248
|
+
dateTimeType = "Date";
|
|
249
|
+
dateType = "Date";
|
|
250
|
+
timeType = "Date";
|
|
251
|
+
dateTimeJacksonAnnotations = ['@JsonFormat(pattern = "yyyy-MM-dd\'T\'HH:mm:ssX", timezone = "UTC")'];
|
|
252
|
+
dateJacksonAnnotations = ['@JsonFormat(pattern = "yyyy-MM-dd")'];
|
|
253
|
+
timeJacksonAnnotations = ['@JsonFormat(pattern = "HH:mm:ssX", timezone = "UTC")'];
|
|
259
254
|
emitDateTimeConverters() {
|
|
260
255
|
this._renderer.ensureBlankLine();
|
|
261
256
|
this._renderer.emitLine("private static final String[] DATE_TIME_FORMATS = {");
|
|
@@ -297,6 +292,8 @@ class JavaLegacyDateTimeProvider extends JavaDateTimeProvider {
|
|
|
297
292
|
this._renderer.emitLine('return new SimpleDateFormat("hh:mm:ssZ").format(datetime);');
|
|
298
293
|
});
|
|
299
294
|
}
|
|
295
|
+
shouldEmitTimeConverter = false;
|
|
296
|
+
shouldEmitDateConverter = false;
|
|
300
297
|
convertStringToDateTime(variable) {
|
|
301
298
|
return [this._className, ".parseAllDateTimeString(", variable, ")"];
|
|
302
299
|
}
|
|
@@ -317,13 +314,16 @@ class JavaLegacyDateTimeProvider extends JavaDateTimeProvider {
|
|
|
317
314
|
}
|
|
318
315
|
}
|
|
319
316
|
class JavaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
317
|
+
_options;
|
|
318
|
+
_currentFilename;
|
|
319
|
+
_gettersAndSettersForPropertyName = new Map();
|
|
320
|
+
_haveEmittedLeadingComments = false;
|
|
321
|
+
_dateTimeProvider;
|
|
322
|
+
_converterClassname = "Converter";
|
|
323
|
+
_converterKeywords = [];
|
|
320
324
|
constructor(targetLanguage, renderContext, _options) {
|
|
321
325
|
super(targetLanguage, renderContext);
|
|
322
326
|
this._options = _options;
|
|
323
|
-
this._gettersAndSettersForPropertyName = new Map();
|
|
324
|
-
this._haveEmittedLeadingComments = false;
|
|
325
|
-
this._converterClassname = "Converter";
|
|
326
|
-
this._converterKeywords = [];
|
|
327
327
|
switch (_options.dateTimeProvider) {
|
|
328
328
|
default:
|
|
329
329
|
case "java8":
|
|
@@ -359,13 +359,13 @@ class JavaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
359
359
|
return this.getNameStyling("enumCaseNamingFunction");
|
|
360
360
|
}
|
|
361
361
|
unionNeedsName(u) {
|
|
362
|
-
return TypeUtils_1.nullableFromUnion(u) === null;
|
|
362
|
+
return (0, TypeUtils_1.nullableFromUnion)(u) === null;
|
|
363
363
|
}
|
|
364
364
|
namedTypeToNameForTopLevel(type) {
|
|
365
365
|
// If the top-level type doesn't contain any classes or unions
|
|
366
366
|
// we have to define a class just for the `FromJson` method, in
|
|
367
367
|
// emitFromJsonForTopLevel.
|
|
368
|
-
return TypeUtils_1.directlyReachableSingleNamedType(type);
|
|
368
|
+
return (0, TypeUtils_1.directlyReachableSingleNamedType)(type);
|
|
369
369
|
}
|
|
370
370
|
makeNamesForPropertyGetterAndSetter(_c, _className, _p, _jsonName, name) {
|
|
371
371
|
const getterName = new Naming_1.DependencyName(this.getNameStyling("propertyNamingFunction"), name.order, lookup => `get_${lookup(name)}`);
|
|
@@ -379,9 +379,9 @@ class JavaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
379
379
|
}
|
|
380
380
|
getNameStyling(convention) {
|
|
381
381
|
const styling = {
|
|
382
|
-
typeNamingFunction: Naming_1.funPrefixNamer("types", n => javaNameStyle(true, false, n, Acronyms_1.acronymStyle(this._options.acronymStyle))),
|
|
383
|
-
propertyNamingFunction: Naming_1.funPrefixNamer("properties", n => javaNameStyle(false, false, n, Acronyms_1.acronymStyle(this._options.acronymStyle))),
|
|
384
|
-
enumCaseNamingFunction: Naming_1.funPrefixNamer("enum-cases", n => javaNameStyle(true, true, n, Acronyms_1.acronymStyle(this._options.acronymStyle)))
|
|
382
|
+
typeNamingFunction: (0, Naming_1.funPrefixNamer)("types", n => javaNameStyle(true, false, n, (0, Acronyms_1.acronymStyle)(this._options.acronymStyle))),
|
|
383
|
+
propertyNamingFunction: (0, Naming_1.funPrefixNamer)("properties", n => javaNameStyle(false, false, n, (0, Acronyms_1.acronymStyle)(this._options.acronymStyle))),
|
|
384
|
+
enumCaseNamingFunction: (0, Naming_1.funPrefixNamer)("enum-cases", n => javaNameStyle(true, true, n, (0, Acronyms_1.acronymStyle)(this._options.acronymStyle)))
|
|
385
385
|
};
|
|
386
386
|
return styling[convention];
|
|
387
387
|
}
|
|
@@ -389,7 +389,7 @@ class JavaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
389
389
|
if (this.topLevels.size === 1) {
|
|
390
390
|
return methodName;
|
|
391
391
|
}
|
|
392
|
-
return [topLevelName, Strings_1.capitalize(methodName)];
|
|
392
|
+
return [topLevelName, (0, Strings_1.capitalize)(methodName)];
|
|
393
393
|
}
|
|
394
394
|
methodName(prefix, suffix, topLevelName) {
|
|
395
395
|
if (this.topLevels.size === 1) {
|
|
@@ -410,7 +410,7 @@ class JavaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
410
410
|
return this.methodName("get", "ObjectWriter", topLevelName);
|
|
411
411
|
}
|
|
412
412
|
startFile(basename) {
|
|
413
|
-
Support_1.assert(this._currentFilename === undefined, "Previous file wasn't finished");
|
|
413
|
+
(0, Support_1.assert)(this._currentFilename === undefined, "Previous file wasn't finished");
|
|
414
414
|
// FIXME: The filenames should actually be Sourcelikes, too
|
|
415
415
|
this._currentFilename = `${this.sourcelikeToString(basename)}.java`;
|
|
416
416
|
// FIXME: Why is this necessary?
|
|
@@ -422,7 +422,7 @@ class JavaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
422
422
|
}
|
|
423
423
|
}
|
|
424
424
|
finishFile() {
|
|
425
|
-
super.finishFile(Support_1.defined(this._currentFilename));
|
|
425
|
+
super.finishFile((0, Support_1.defined)(this._currentFilename));
|
|
426
426
|
this._currentFilename = undefined;
|
|
427
427
|
}
|
|
428
428
|
emitPackageAndImports(imports) {
|
|
@@ -456,7 +456,7 @@ class JavaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
456
456
|
this.emitTryCatch(f, () => this.emitLine("// Ignored"));
|
|
457
457
|
}
|
|
458
458
|
javaType(reference, t, withIssues = false) {
|
|
459
|
-
return TypeUtils_1.matchType(t, _anyType => Source_1.maybeAnnotated(withIssues, Annotation_1.anyTypeIssueAnnotation, "Object"), _nullType => Source_1.maybeAnnotated(withIssues, Annotation_1.nullTypeIssueAnnotation, "Object"), _boolType => (reference ? "Boolean" : "boolean"), _integerType => (reference ? "Long" : "long"), _doubleType => (reference ? "Double" : "double"), _stringType => "String", arrayType => {
|
|
459
|
+
return (0, TypeUtils_1.matchType)(t, _anyType => (0, Source_1.maybeAnnotated)(withIssues, Annotation_1.anyTypeIssueAnnotation, "Object"), _nullType => (0, Source_1.maybeAnnotated)(withIssues, Annotation_1.nullTypeIssueAnnotation, "Object"), _boolType => (reference ? "Boolean" : "boolean"), _integerType => (reference ? "Long" : "long"), _doubleType => (reference ? "Double" : "double"), _stringType => "String", arrayType => {
|
|
460
460
|
if (this._options.useList) {
|
|
461
461
|
return ["List<", this.javaType(true, arrayType.items, withIssues), ">"];
|
|
462
462
|
}
|
|
@@ -464,7 +464,7 @@ class JavaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
464
464
|
return [this.javaType(false, arrayType.items, withIssues), "[]"];
|
|
465
465
|
}
|
|
466
466
|
}, classType => this.nameForNamedType(classType), mapType => ["Map<String, ", this.javaType(true, mapType.values, withIssues), ">"], enumType => this.nameForNamedType(enumType), unionType => {
|
|
467
|
-
const nullable = TypeUtils_1.nullableFromUnion(unionType);
|
|
467
|
+
const nullable = (0, TypeUtils_1.nullableFromUnion)(unionType);
|
|
468
468
|
if (nullable !== null)
|
|
469
469
|
return this.javaType(true, nullable, withIssues);
|
|
470
470
|
return this.nameForNamedType(unionType);
|
|
@@ -485,7 +485,7 @@ class JavaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
485
485
|
});
|
|
486
486
|
}
|
|
487
487
|
javaImport(t) {
|
|
488
|
-
return TypeUtils_1.matchType(t, _anyType => [], _nullType => [], _boolType => [], _integerType => [], _doubleType => [], _stringType => [], arrayType => {
|
|
488
|
+
return (0, TypeUtils_1.matchType)(t, _anyType => [], _nullType => [], _boolType => [], _integerType => [], _doubleType => [], _stringType => [], arrayType => {
|
|
489
489
|
if (this._options.useList) {
|
|
490
490
|
return [...this.javaImport(arrayType.items), "java.util.List"];
|
|
491
491
|
}
|
|
@@ -525,7 +525,7 @@ class JavaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
525
525
|
return "Map";
|
|
526
526
|
}
|
|
527
527
|
else if (t instanceof Type_1.UnionType) {
|
|
528
|
-
const nullable = TypeUtils_1.nullableFromUnion(t);
|
|
528
|
+
const nullable = (0, TypeUtils_1.nullableFromUnion)(t);
|
|
529
529
|
if (nullable !== null)
|
|
530
530
|
return this.javaTypeWithoutGenerics(true, nullable);
|
|
531
531
|
return this.nameForNamedType(t);
|
|
@@ -552,7 +552,7 @@ class JavaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
552
552
|
if (t instanceof Type_1.EnumType) {
|
|
553
553
|
return ["java.io.IOException"];
|
|
554
554
|
}
|
|
555
|
-
return Support_1.assertNever(t);
|
|
555
|
+
return (0, Support_1.assertNever)(t);
|
|
556
556
|
}
|
|
557
557
|
importsForClass(c) {
|
|
558
558
|
const imports = [];
|
|
@@ -564,7 +564,7 @@ class JavaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
564
564
|
}
|
|
565
565
|
importsForUnionMembers(u) {
|
|
566
566
|
const imports = [];
|
|
567
|
-
const [, nonNulls] = TypeUtils_1.removeNullFromUnion(u);
|
|
567
|
+
const [, nonNulls] = (0, TypeUtils_1.removeNullFromUnion)(u);
|
|
568
568
|
this.forEachUnionMember(u, nonNulls, "none", null, (_fieldName, t) => {
|
|
569
569
|
this.javaImport(t).forEach(imp => imports.push(imp));
|
|
570
570
|
});
|
|
@@ -593,7 +593,7 @@ class JavaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
593
593
|
if (!this._options.lombok) {
|
|
594
594
|
this.forEachClassProperty(c, "leading-and-interposing", (name, jsonName, p) => {
|
|
595
595
|
this.emitDescription(this.descriptionForClassProperty(c, jsonName));
|
|
596
|
-
const [getterName, setterName] = Support_1.defined(this._gettersAndSettersForPropertyName.get(name));
|
|
596
|
+
const [getterName, setterName] = (0, Support_1.defined)(this._gettersAndSettersForPropertyName.get(name));
|
|
597
597
|
const rendered = this.javaType(false, p.type);
|
|
598
598
|
this.annotationsForAccessor(c, className, name, jsonName, p, false).forEach(annotation => this.emitLine(annotation));
|
|
599
599
|
this.emitLine("public ", rendered, " ", getterName, "() { return ", name, "; }");
|
|
@@ -620,7 +620,7 @@ class JavaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
620
620
|
const imports = [...this.importsForType(u), ...this.importsForUnionMembers(u)];
|
|
621
621
|
this.emitFileHeader(unionName, imports);
|
|
622
622
|
this.emitDescription(this.descriptionForType(u));
|
|
623
|
-
const [, nonNulls] = TypeUtils_1.removeNullFromUnion(u);
|
|
623
|
+
const [, nonNulls] = (0, TypeUtils_1.removeNullFromUnion)(u);
|
|
624
624
|
this.emitUnionAttributes(u, unionName);
|
|
625
625
|
this.emitBlock(["public class ", unionName], () => {
|
|
626
626
|
for (const t of nonNulls) {
|
|
@@ -655,7 +655,7 @@ class JavaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
655
655
|
this.emitLine("switch (this) {");
|
|
656
656
|
this.indent(() => {
|
|
657
657
|
this.forEachEnumCase(e, "none", (name, jsonName) => {
|
|
658
|
-
this.emitLine("case ", name, ': return "', exports.stringEscape(jsonName), '";');
|
|
658
|
+
this.emitLine("case ", name, ': return "', (0, exports.stringEscape)(jsonName), '";');
|
|
659
659
|
});
|
|
660
660
|
});
|
|
661
661
|
this.emitLine("}");
|
|
@@ -665,7 +665,7 @@ class JavaRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
665
665
|
this.emitEnumDeserializationAttributes(e);
|
|
666
666
|
this.emitBlock(["public static ", enumName, " forValue(String value) throws IOException"], () => {
|
|
667
667
|
this.forEachEnumCase(e, "none", (name, jsonName) => {
|
|
668
|
-
this.emitLine('if (value.equals("', exports.stringEscape(jsonName), '")) return ', name, ";");
|
|
668
|
+
this.emitLine('if (value.equals("', (0, exports.stringEscape)(jsonName), '")) return ', name, ";");
|
|
669
669
|
});
|
|
670
670
|
this.emitLine('throw new IOException("Cannot deserialize ', enumName, '");');
|
|
671
671
|
});
|
|
@@ -680,18 +680,18 @@ exports.JavaRenderer = JavaRenderer;
|
|
|
680
680
|
class JacksonRenderer extends JavaRenderer {
|
|
681
681
|
constructor(targetLanguage, renderContext, options) {
|
|
682
682
|
super(targetLanguage, renderContext, options);
|
|
683
|
-
this._converterKeywords = [
|
|
684
|
-
"JsonProperty",
|
|
685
|
-
"JsonDeserialize",
|
|
686
|
-
"JsonDeserializer",
|
|
687
|
-
"JsonSerialize",
|
|
688
|
-
"JsonSerializer",
|
|
689
|
-
"JsonParser",
|
|
690
|
-
"JsonProcessingException",
|
|
691
|
-
"DeserializationContext",
|
|
692
|
-
"SerializerProvider"
|
|
693
|
-
];
|
|
694
683
|
}
|
|
684
|
+
_converterKeywords = [
|
|
685
|
+
"JsonProperty",
|
|
686
|
+
"JsonDeserialize",
|
|
687
|
+
"JsonDeserializer",
|
|
688
|
+
"JsonSerialize",
|
|
689
|
+
"JsonSerializer",
|
|
690
|
+
"JsonParser",
|
|
691
|
+
"JsonProcessingException",
|
|
692
|
+
"DeserializationContext",
|
|
693
|
+
"SerializerProvider"
|
|
694
|
+
];
|
|
695
695
|
emitClassAttributes(c, _className) {
|
|
696
696
|
if (c.getProperties().size === 0)
|
|
697
697
|
this.emitLine("@JsonAutoDetect(fieldVisibility=JsonAutoDetect.Visibility.NONE)");
|
|
@@ -699,7 +699,7 @@ class JacksonRenderer extends JavaRenderer {
|
|
|
699
699
|
}
|
|
700
700
|
annotationsForAccessor(_c, _className, _propertyName, jsonName, p, _isSetter) {
|
|
701
701
|
const superAnnotations = super.annotationsForAccessor(_c, _className, _propertyName, jsonName, p, _isSetter);
|
|
702
|
-
const annotations = ['@JsonProperty("' + exports.stringEscape(jsonName) + '")'];
|
|
702
|
+
const annotations = ['@JsonProperty("' + (0, exports.stringEscape)(jsonName) + '")'];
|
|
703
703
|
switch (p.type.kind) {
|
|
704
704
|
case "date-time":
|
|
705
705
|
this._dateTimeProvider.dateTimeJacksonAnnotations.forEach(annotation => annotations.push(annotation));
|
|
@@ -734,7 +734,7 @@ class JacksonRenderer extends JavaRenderer {
|
|
|
734
734
|
imports.push("com.fasterxml.jackson.annotation.*");
|
|
735
735
|
return imports;
|
|
736
736
|
}
|
|
737
|
-
return Support_1.assertNever(t);
|
|
737
|
+
return (0, Support_1.assertNever)(t);
|
|
738
738
|
}
|
|
739
739
|
emitUnionAttributes(_u, unionName) {
|
|
740
740
|
this.emitLine("@JsonDeserialize(using = ", unionName, ".Deserializer.class)");
|
|
@@ -766,7 +766,7 @@ class JacksonRenderer extends JavaRenderer {
|
|
|
766
766
|
this.emitLine("value.", fieldName, " = UUID.fromString(", parseFrom, ");");
|
|
767
767
|
break;
|
|
768
768
|
default:
|
|
769
|
-
return Support_1.panic("Requested type isnt an object!");
|
|
769
|
+
return (0, Support_1.panic)("Requested type isnt an object!");
|
|
770
770
|
}
|
|
771
771
|
};
|
|
772
772
|
const emitDeserializeType = (t, variableFieldName = "") => {
|
|
@@ -868,7 +868,7 @@ class JacksonRenderer extends JavaRenderer {
|
|
|
868
868
|
case "date-time":
|
|
869
869
|
return this._dateTimeProvider.convertDateTimeToString(fieldName);
|
|
870
870
|
default:
|
|
871
|
-
return Support_1.panic("Requested type doesn't have custom serializer code!");
|
|
871
|
+
return (0, Support_1.panic)("Requested type doesn't have custom serializer code!");
|
|
872
872
|
}
|
|
873
873
|
};
|
|
874
874
|
const emitSerializeType = (t) => {
|
|
@@ -883,7 +883,7 @@ class JacksonRenderer extends JavaRenderer {
|
|
|
883
883
|
this.emitLine("return;");
|
|
884
884
|
});
|
|
885
885
|
};
|
|
886
|
-
const [maybeNull, nonNulls] = TypeUtils_1.removeNullFromUnion(u);
|
|
886
|
+
const [maybeNull, nonNulls] = (0, TypeUtils_1.removeNullFromUnion)(u);
|
|
887
887
|
this.ensureBlankLine();
|
|
888
888
|
this.emitBlock(["static class Deserializer extends JsonDeserializer<", unionName, ">"], () => {
|
|
889
889
|
this.emitLine("@Override");
|
|
@@ -15,7 +15,7 @@ export declare const javaScriptOptions: {
|
|
|
15
15
|
converters: EnumOption<ConvertersOptions>;
|
|
16
16
|
rawType: EnumOption<"any" | "json">;
|
|
17
17
|
};
|
|
18
|
-
export
|
|
18
|
+
export type JavaScriptTypeAnnotations = {
|
|
19
19
|
any: string;
|
|
20
20
|
anyArray: string;
|
|
21
21
|
anyMap: string;
|
|
@@ -27,9 +27,9 @@ export declare type JavaScriptTypeAnnotations = {
|
|
|
27
27
|
export declare class JavaScriptTargetLanguage extends TargetLanguage {
|
|
28
28
|
constructor(displayName?: string, names?: string[], extension?: string);
|
|
29
29
|
protected getOptions(): Option<any>[];
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
get stringTypeMapping(): StringTypeMapping;
|
|
31
|
+
get supportsOptionalClassProperties(): boolean;
|
|
32
|
+
get supportsFullObjectType(): boolean;
|
|
33
33
|
protected makeRenderer(renderContext: RenderContext, untypedOptionValues: {
|
|
34
34
|
[name: string]: any;
|
|
35
35
|
}): JavaScriptRenderer;
|
|
@@ -54,9 +54,9 @@ export declare class JavaScriptRenderer extends ConvenienceRenderer {
|
|
|
54
54
|
protected deserializerFunctionLine(_t: Type, name: Name): Sourcelike;
|
|
55
55
|
protected serializerFunctionName(name: Name): Sourcelike;
|
|
56
56
|
protected serializerFunctionLine(_t: Type, name: Name): Sourcelike;
|
|
57
|
-
protected
|
|
58
|
-
protected
|
|
59
|
-
protected
|
|
57
|
+
protected get moduleLine(): string | undefined;
|
|
58
|
+
protected get castFunctionLines(): [string, string];
|
|
59
|
+
protected get typeAnnotations(): JavaScriptTypeAnnotations;
|
|
60
60
|
protected emitConvertModuleBody(): void;
|
|
61
61
|
protected emitConvertModuleHelpers(): void;
|
|
62
62
|
protected emitConvertModule(): void;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JavaScriptRenderer = exports.legalizeName = exports.JavaScriptTargetLanguage = exports.javaScriptOptions = void 0;
|
|
3
4
|
const collection_utils_1 = require("collection-utils");
|
|
4
5
|
const TypeUtils_1 = require("../TypeUtils");
|
|
5
6
|
const Acronyms_1 = require("../support/Acronyms");
|
|
@@ -13,10 +14,10 @@ const TargetLanguage_1 = require("../TargetLanguage");
|
|
|
13
14
|
const RendererOptions_1 = require("../RendererOptions");
|
|
14
15
|
const JavaScriptUnicodeMaps_1 = require("./JavaScriptUnicodeMaps");
|
|
15
16
|
exports.javaScriptOptions = {
|
|
16
|
-
acronymStyle: Acronyms_1.acronymOption(Acronyms_1.AcronymStyleOptions.Pascal),
|
|
17
|
+
acronymStyle: (0, Acronyms_1.acronymOption)(Acronyms_1.AcronymStyleOptions.Pascal),
|
|
17
18
|
runtimeTypecheck: new RendererOptions_1.BooleanOption("runtime-typecheck", "Verify JSON.parse results at runtime", true),
|
|
18
19
|
runtimeTypecheckIgnoreUnknownProperties: new RendererOptions_1.BooleanOption("runtime-typecheck-ignore-unknown-properties", "Ignore unknown properties when verifying at runtime", false, "secondary"),
|
|
19
|
-
converters: Converters_1.convertersOption(),
|
|
20
|
+
converters: (0, Converters_1.convertersOption)(),
|
|
20
21
|
rawType: new RendererOptions_1.EnumOption("raw-type", "Type of raw input (json by default)", [
|
|
21
22
|
["json", "json"],
|
|
22
23
|
["any", "any"]
|
|
@@ -49,24 +50,25 @@ class JavaScriptTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
|
49
50
|
return true;
|
|
50
51
|
}
|
|
51
52
|
makeRenderer(renderContext, untypedOptionValues) {
|
|
52
|
-
return new JavaScriptRenderer(this, renderContext, RendererOptions_1.getOptionValues(exports.javaScriptOptions, untypedOptionValues));
|
|
53
|
+
return new JavaScriptRenderer(this, renderContext, (0, RendererOptions_1.getOptionValues)(exports.javaScriptOptions, untypedOptionValues));
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
56
|
exports.JavaScriptTargetLanguage = JavaScriptTargetLanguage;
|
|
56
|
-
exports.legalizeName = Strings_1.utf16LegalizeCharacters(JavaScriptUnicodeMaps_1.isES3IdentifierPart);
|
|
57
|
-
const identityNamingFunction = Naming_1.funPrefixNamer("properties", s => s);
|
|
57
|
+
exports.legalizeName = (0, Strings_1.utf16LegalizeCharacters)(JavaScriptUnicodeMaps_1.isES3IdentifierPart);
|
|
58
|
+
const identityNamingFunction = (0, Naming_1.funPrefixNamer)("properties", s => s);
|
|
58
59
|
class JavaScriptRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
60
|
+
_jsOptions;
|
|
59
61
|
constructor(targetLanguage, renderContext, _jsOptions) {
|
|
60
62
|
super(targetLanguage, renderContext);
|
|
61
63
|
this._jsOptions = _jsOptions;
|
|
62
64
|
}
|
|
63
65
|
nameStyle(original, upper) {
|
|
64
|
-
const acronyms = Acronyms_1.acronymStyle(this._jsOptions.acronymStyle);
|
|
65
|
-
const words = Strings_1.splitIntoWords(original);
|
|
66
|
-
return Strings_1.combineWords(words, exports.legalizeName, upper ? Strings_1.firstUpperWordStyle : Strings_1.allLowerWordStyle, Strings_1.firstUpperWordStyle, upper ? s => Strings_1.capitalize(acronyms(s)) : Strings_1.allLowerWordStyle, acronyms, "", JavaScriptUnicodeMaps_1.isES3IdentifierStart);
|
|
66
|
+
const acronyms = (0, Acronyms_1.acronymStyle)(this._jsOptions.acronymStyle);
|
|
67
|
+
const words = (0, Strings_1.splitIntoWords)(original);
|
|
68
|
+
return (0, Strings_1.combineWords)(words, exports.legalizeName, upper ? Strings_1.firstUpperWordStyle : Strings_1.allLowerWordStyle, Strings_1.firstUpperWordStyle, upper ? s => (0, Strings_1.capitalize)(acronyms(s)) : Strings_1.allLowerWordStyle, acronyms, "", JavaScriptUnicodeMaps_1.isES3IdentifierStart);
|
|
67
69
|
}
|
|
68
70
|
makeNamedTypeNamer() {
|
|
69
|
-
return Naming_1.funPrefixNamer("types", s => this.nameStyle(s, true));
|
|
71
|
+
return (0, Naming_1.funPrefixNamer)("types", s => this.nameStyle(s, true));
|
|
70
72
|
}
|
|
71
73
|
namerForObjectProperty() {
|
|
72
74
|
return identityNamingFunction;
|
|
@@ -75,10 +77,10 @@ class JavaScriptRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
75
77
|
return null;
|
|
76
78
|
}
|
|
77
79
|
makeEnumCaseNamer() {
|
|
78
|
-
return Naming_1.funPrefixNamer("enum-cases", s => this.nameStyle(s, true));
|
|
80
|
+
return (0, Naming_1.funPrefixNamer)("enum-cases", s => this.nameStyle(s, true));
|
|
79
81
|
}
|
|
80
82
|
namedTypeToNameForTopLevel(type) {
|
|
81
|
-
return TypeUtils_1.directlyReachableSingleNamedType(type);
|
|
83
|
+
return (0, TypeUtils_1.directlyReachableSingleNamedType)(type);
|
|
82
84
|
}
|
|
83
85
|
makeNameForProperty(c, className, p, jsonName, _assignedName) {
|
|
84
86
|
// Ignore the assigned name
|
|
@@ -91,9 +93,9 @@ class JavaScriptRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
91
93
|
if (["class", "object", "enum"].indexOf(t.kind) >= 0) {
|
|
92
94
|
return ['r("', this.nameForNamedType(t), '")'];
|
|
93
95
|
}
|
|
94
|
-
return TypeUtils_1.matchType(t, _anyType => '"any"', _nullType => `null`, _boolType => `true`, _integerType => `0`, _doubleType => `3.14`, _stringType => `""`, arrayType => ["a(", this.typeMapTypeFor(arrayType.items), ")"], _classType => Support_1.panic("We handled this above"), mapType => ["m(", this.typeMapTypeFor(mapType.values), ")"], _enumType => Support_1.panic("We handled this above"), unionType => {
|
|
96
|
+
return (0, TypeUtils_1.matchType)(t, _anyType => '"any"', _nullType => `null`, _boolType => `true`, _integerType => `0`, _doubleType => `3.14`, _stringType => `""`, arrayType => ["a(", this.typeMapTypeFor(arrayType.items), ")"], _classType => (0, Support_1.panic)("We handled this above"), mapType => ["m(", this.typeMapTypeFor(mapType.values), ")"], _enumType => (0, Support_1.panic)("We handled this above"), unionType => {
|
|
95
97
|
const children = Array.from(unionType.getChildren()).map((type) => this.typeMapTypeFor(type));
|
|
96
|
-
return ["u(", ...collection_utils_1.arrayIntercalate(", ", children), ")"];
|
|
98
|
+
return ["u(", ...(0, collection_utils_1.arrayIntercalate)(", ", children), ")"];
|
|
97
99
|
}, transformedStringType => {
|
|
98
100
|
if (transformedStringType.kind === "date-time") {
|
|
99
101
|
return "Date";
|
|
@@ -122,7 +124,7 @@ class JavaScriptRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
122
124
|
this.emitLine('"', name, '": o([');
|
|
123
125
|
this.indent(() => {
|
|
124
126
|
this.forEachClassProperty(t, "none", (propName, jsonName, property) => {
|
|
125
|
-
this.emitLine('{ json: "', Strings_1.utf16StringEscape(jsonName), '", js: "', Source_1.modifySource(Strings_1.utf16StringEscape, propName), '", typ: ', this.typeMapTypeForProperty(property), " },");
|
|
127
|
+
this.emitLine('{ json: "', (0, Strings_1.utf16StringEscape)(jsonName), '", js: "', (0, Source_1.modifySource)(Strings_1.utf16StringEscape, propName), '", typ: ', this.typeMapTypeForProperty(property), " },");
|
|
126
128
|
});
|
|
127
129
|
});
|
|
128
130
|
this.emitLine("], ", additional, "),");
|
|
@@ -131,7 +133,7 @@ class JavaScriptRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
131
133
|
this.emitLine('"', name, '": [');
|
|
132
134
|
this.indent(() => {
|
|
133
135
|
this.forEachEnumCase(e, "none", (_caseName, jsonName) => {
|
|
134
|
-
this.emitLine(`"${Strings_1.utf16StringEscape(jsonName)}",`);
|
|
136
|
+
this.emitLine(`"${(0, Strings_1.utf16StringEscape)(jsonName)}",`);
|
|
135
137
|
});
|
|
136
138
|
});
|
|
137
139
|
this.emitLine("],");
|
|
@@ -145,7 +147,7 @@ class JavaScriptRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
145
147
|
return ["function ", this.deserializerFunctionName(name), "(json)"];
|
|
146
148
|
}
|
|
147
149
|
serializerFunctionName(name) {
|
|
148
|
-
const camelCaseName = Source_1.modifySource(Strings_1.camelCase, name);
|
|
150
|
+
const camelCaseName = (0, Source_1.modifySource)(Strings_1.camelCase, name);
|
|
149
151
|
return [camelCaseName, "ToJson"];
|
|
150
152
|
}
|
|
151
153
|
serializerFunctionLine(_t, name) {
|
|
@@ -397,7 +399,7 @@ function r(name${stringAnnotation}) {
|
|
|
397
399
|
this.emitUsageImportComment();
|
|
398
400
|
this.emitLine("//");
|
|
399
401
|
this.forEachTopLevel("none", (_t, name) => {
|
|
400
|
-
const camelCaseName = Source_1.modifySource(Strings_1.camelCase, name);
|
|
402
|
+
const camelCaseName = (0, Source_1.modifySource)(Strings_1.camelCase, name);
|
|
401
403
|
this.emitLine("// const ", camelCaseName, " = Convert.to", name, "(json);");
|
|
402
404
|
});
|
|
403
405
|
if (this._jsOptions.runtimeTypecheck) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JavaScriptPropTypesRenderer = exports.JavaScriptPropTypesTargetLanguage = exports.javaScriptPropTypesOptions = void 0;
|
|
3
4
|
const TargetLanguage_1 = require("../TargetLanguage");
|
|
4
5
|
const RendererOptions_1 = require("../RendererOptions");
|
|
5
6
|
const ConvenienceRenderer_1 = require("../ConvenienceRenderer");
|
|
@@ -14,8 +15,8 @@ const TypeUtils_1 = require("../TypeUtils");
|
|
|
14
15
|
const collection_utils_1 = require("collection-utils");
|
|
15
16
|
const Type_1 = require("../Type");
|
|
16
17
|
exports.javaScriptPropTypesOptions = {
|
|
17
|
-
acronymStyle: Acronyms_1.acronymOption(Acronyms_1.AcronymStyleOptions.Pascal),
|
|
18
|
-
converters: Converters_1.convertersOption(),
|
|
18
|
+
acronymStyle: (0, Acronyms_1.acronymOption)(Acronyms_1.AcronymStyleOptions.Pascal),
|
|
19
|
+
converters: (0, Converters_1.convertersOption)(),
|
|
19
20
|
moduleSystem: new RendererOptions_1.EnumOption("module-system", "Which module system to use", [
|
|
20
21
|
["common-js", false],
|
|
21
22
|
["es6", true]
|
|
@@ -29,23 +30,24 @@ class JavaScriptPropTypesTargetLanguage extends TargetLanguage_1.TargetLanguage
|
|
|
29
30
|
super(displayName, names, extension);
|
|
30
31
|
}
|
|
31
32
|
makeRenderer(renderContext, untypedOptionValues) {
|
|
32
|
-
return new JavaScriptPropTypesRenderer(this, renderContext, RendererOptions_1.getOptionValues(exports.javaScriptPropTypesOptions, untypedOptionValues));
|
|
33
|
+
return new JavaScriptPropTypesRenderer(this, renderContext, (0, RendererOptions_1.getOptionValues)(exports.javaScriptPropTypesOptions, untypedOptionValues));
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
36
|
exports.JavaScriptPropTypesTargetLanguage = JavaScriptPropTypesTargetLanguage;
|
|
36
|
-
const identityNamingFunction = Naming_1.funPrefixNamer("properties", s => s);
|
|
37
|
+
const identityNamingFunction = (0, Naming_1.funPrefixNamer)("properties", s => s);
|
|
37
38
|
class JavaScriptPropTypesRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
39
|
+
_jsOptions;
|
|
38
40
|
constructor(targetLanguage, renderContext, _jsOptions) {
|
|
39
41
|
super(targetLanguage, renderContext);
|
|
40
42
|
this._jsOptions = _jsOptions;
|
|
41
43
|
}
|
|
42
44
|
nameStyle(original, upper) {
|
|
43
|
-
const acronyms = Acronyms_1.acronymStyle(this._jsOptions.acronymStyle);
|
|
44
|
-
const words = __1.splitIntoWords(original);
|
|
45
|
-
return __1.combineWords(words, JavaScript_1.legalizeName, upper ? __1.firstUpperWordStyle : Strings_1.allLowerWordStyle, __1.firstUpperWordStyle, upper ? s => __1.capitalize(acronyms(s)) : Strings_1.allLowerWordStyle, acronyms, "", JavaScriptUnicodeMaps_1.isES3IdentifierStart);
|
|
45
|
+
const acronyms = (0, Acronyms_1.acronymStyle)(this._jsOptions.acronymStyle);
|
|
46
|
+
const words = (0, __1.splitIntoWords)(original);
|
|
47
|
+
return (0, __1.combineWords)(words, JavaScript_1.legalizeName, upper ? __1.firstUpperWordStyle : Strings_1.allLowerWordStyle, __1.firstUpperWordStyle, upper ? s => (0, __1.capitalize)(acronyms(s)) : Strings_1.allLowerWordStyle, acronyms, "", JavaScriptUnicodeMaps_1.isES3IdentifierStart);
|
|
46
48
|
}
|
|
47
49
|
makeNamedTypeNamer() {
|
|
48
|
-
return Naming_1.funPrefixNamer("types", s => this.nameStyle(s, true));
|
|
50
|
+
return (0, Naming_1.funPrefixNamer)("types", s => this.nameStyle(s, true));
|
|
49
51
|
}
|
|
50
52
|
namerForObjectProperty() {
|
|
51
53
|
return identityNamingFunction;
|
|
@@ -54,10 +56,10 @@ class JavaScriptPropTypesRenderer extends ConvenienceRenderer_1.ConvenienceRende
|
|
|
54
56
|
return null;
|
|
55
57
|
}
|
|
56
58
|
makeEnumCaseNamer() {
|
|
57
|
-
return Naming_1.funPrefixNamer("enum-cases", s => this.nameStyle(s, false));
|
|
59
|
+
return (0, Naming_1.funPrefixNamer)("enum-cases", s => this.nameStyle(s, false));
|
|
58
60
|
}
|
|
59
61
|
namedTypeToNameForTopLevel(type) {
|
|
60
|
-
return TypeUtils_1.directlyReachableSingleNamedType(type);
|
|
62
|
+
return (0, TypeUtils_1.directlyReachableSingleNamedType)(type);
|
|
61
63
|
}
|
|
62
64
|
makeNameForProperty(c, className, p, jsonName, _assignedName) {
|
|
63
65
|
// Ignore the assigned name
|
|
@@ -67,9 +69,9 @@ class JavaScriptPropTypesRenderer extends ConvenienceRenderer_1.ConvenienceRende
|
|
|
67
69
|
if (["class", "object", "enum"].indexOf(t.kind) >= 0) {
|
|
68
70
|
return ["_", this.nameForNamedType(t)];
|
|
69
71
|
}
|
|
70
|
-
const match = __1.matchType(t, _anyType => "PropTypes.any", _nullType => "PropTypes.any", _boolType => "PropTypes.bool", _integerType => "PropTypes.number", _doubleType => "PropTypes.number", _stringType => "PropTypes.string", arrayType => ["PropTypes.arrayOf(", this.typeMapTypeFor(arrayType.items, false), ")"], _classType => __1.panic("Should already be handled."), _mapType => "PropTypes.object", _enumType => __1.panic("Should already be handled."), unionType => {
|
|
72
|
+
const match = (0, __1.matchType)(t, _anyType => "PropTypes.any", _nullType => "PropTypes.any", _boolType => "PropTypes.bool", _integerType => "PropTypes.number", _doubleType => "PropTypes.number", _stringType => "PropTypes.string", arrayType => ["PropTypes.arrayOf(", this.typeMapTypeFor(arrayType.items, false), ")"], _classType => (0, __1.panic)("Should already be handled."), _mapType => "PropTypes.object", _enumType => (0, __1.panic)("Should already be handled."), unionType => {
|
|
71
73
|
const children = Array.from(unionType.getChildren()).map((type) => this.typeMapTypeFor(type, false));
|
|
72
|
-
return ["PropTypes.oneOfType([", ...collection_utils_1.arrayIntercalate(", ", children), "])"];
|
|
74
|
+
return ["PropTypes.oneOfType([", ...(0, collection_utils_1.arrayIntercalate)(", ", children), "])"];
|
|
73
75
|
}, _transformedStringType => {
|
|
74
76
|
return "PropTypes.string";
|
|
75
77
|
});
|
|
@@ -192,7 +194,7 @@ class JavaScriptPropTypesRenderer extends ConvenienceRenderer_1.ConvenienceRende
|
|
|
192
194
|
this.emitLine("_", name, " = PropTypes.shape({");
|
|
193
195
|
this.indent(() => {
|
|
194
196
|
this.forEachClassProperty(t, "none", (_, jsonName, property) => {
|
|
195
|
-
this.emitLine(`"${Strings_1.utf16StringEscape(jsonName)}"`, ": ", this.typeMapTypeForProperty(property), ",");
|
|
197
|
+
this.emitLine(`"${(0, Strings_1.utf16StringEscape)(jsonName)}"`, ": ", this.typeMapTypeForProperty(property), ",");
|
|
196
198
|
});
|
|
197
199
|
});
|
|
198
200
|
this.emitLine("});");
|