quicktype 18.0.5 → 19.0.4
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/README.md +1 -1
- package/dist/{cli/CompressedJSONFromStream.d.ts → CompressedJSONFromStream.d.ts} +1 -1
- package/dist/{cli/CompressedJSONFromStream.js → CompressedJSONFromStream.js} +2 -2
- package/dist/{cli/GraphQLIntrospection.d.ts → GraphQLIntrospection.d.ts} +0 -0
- package/dist/{cli/GraphQLIntrospection.js → GraphQLIntrospection.js} +1 -1
- package/dist/{cli/TypeSource.d.ts → TypeSource.d.ts} +2 -2
- package/dist/{cli/TypeSource.js → TypeSource.js} +0 -0
- package/dist/{cli/URLGrammar.d.ts → URLGrammar.d.ts} +0 -0
- package/dist/{cli/URLGrammar.js → URLGrammar.js} +1 -1
- package/dist/{cli/index.d.ts → index.d.ts} +1 -1
- package/dist/{cli/index.js → index.js} +4 -5
- package/package.json +61 -77
- package/dist/quicktype-core/Annotation.d.ts +0 -8
- package/dist/quicktype-core/Annotation.js +0 -16
- package/dist/quicktype-core/ConvenienceRenderer.d.ts +0 -138
- package/dist/quicktype-core/ConvenienceRenderer.js +0 -668
- package/dist/quicktype-core/DateTime.d.ts +0 -10
- package/dist/quicktype-core/DateTime.js +0 -57
- package/dist/quicktype-core/DeclarationIR.d.ts +0 -14
- package/dist/quicktype-core/DeclarationIR.js +0 -167
- package/dist/quicktype-core/EncodedMarkovChain.d.ts +0 -1
- package/dist/quicktype-core/EncodedMarkovChain.js +0 -4
- package/dist/quicktype-core/GatherNames.d.ts +0 -2
- package/dist/quicktype-core/GatherNames.js +0 -333
- package/dist/quicktype-core/Graph.d.ts +0 -12
- package/dist/quicktype-core/Graph.js +0 -220
- package/dist/quicktype-core/GraphRewriting.d.ts +0 -87
- package/dist/quicktype-core/GraphRewriting.js +0 -421
- package/dist/quicktype-core/MakeTransformations.d.ts +0 -4
- package/dist/quicktype-core/MakeTransformations.js +0 -193
- package/dist/quicktype-core/MarkovChain.d.ts +0 -15
- package/dist/quicktype-core/MarkovChain.js +0 -154
- package/dist/quicktype-core/Messages.d.ts +0 -294
- package/dist/quicktype-core/Messages.js +0 -105
- package/dist/quicktype-core/Naming.d.ts +0 -64
- package/dist/quicktype-core/Naming.js +0 -356
- package/dist/quicktype-core/Renderer.d.ts +0 -50
- package/dist/quicktype-core/Renderer.js +0 -274
- package/dist/quicktype-core/RendererOptions.d.ts +0 -71
- package/dist/quicktype-core/RendererOptions.js +0 -141
- package/dist/quicktype-core/Run.d.ts +0 -174
- package/dist/quicktype-core/Run.js +0 -393
- package/dist/quicktype-core/Source.d.ts +0 -65
- package/dist/quicktype-core/Source.js +0 -204
- package/dist/quicktype-core/TargetLanguage.d.ts +0 -34
- package/dist/quicktype-core/TargetLanguage.js +0 -66
- package/dist/quicktype-core/Transformers.d.ts +0 -209
- package/dist/quicktype-core/Transformers.js +0 -836
- package/dist/quicktype-core/Type.d.ts +0 -206
- package/dist/quicktype-core/Type.js +0 -716
- package/dist/quicktype-core/TypeBuilder.d.ts +0 -61
- package/dist/quicktype-core/TypeBuilder.js +0 -324
- package/dist/quicktype-core/TypeGraph.d.ts +0 -75
- package/dist/quicktype-core/TypeGraph.js +0 -420
- package/dist/quicktype-core/TypeUtils.d.ts +0 -33
- package/dist/quicktype-core/TypeUtils.js +0 -230
- package/dist/quicktype-core/UnifyClasses.d.ts +0 -16
- package/dist/quicktype-core/UnifyClasses.js +0 -159
- package/dist/quicktype-core/UnionBuilder.d.ts +0 -49
- package/dist/quicktype-core/UnionBuilder.js +0 -282
- package/dist/quicktype-core/attributes/AccessorNames.d.ts +0 -18
- package/dist/quicktype-core/attributes/AccessorNames.js +0 -182
- package/dist/quicktype-core/attributes/Constraints.d.ts +0 -38
- package/dist/quicktype-core/attributes/Constraints.js +0 -172
- package/dist/quicktype-core/attributes/Description.d.ts +0 -9
- package/dist/quicktype-core/attributes/Description.js +0 -97
- package/dist/quicktype-core/attributes/EnumValues.d.ts +0 -8
- package/dist/quicktype-core/attributes/EnumValues.js +0 -31
- package/dist/quicktype-core/attributes/StringTypes.d.ts +0 -28
- package/dist/quicktype-core/attributes/StringTypes.js +0 -189
- package/dist/quicktype-core/attributes/TypeAttributes.d.ts +0 -34
- package/dist/quicktype-core/attributes/TypeAttributes.js +0 -119
- package/dist/quicktype-core/attributes/TypeNames.d.ts +0 -46
- package/dist/quicktype-core/attributes/TypeNames.js +0 -274
- package/dist/quicktype-core/attributes/URIAttributes.d.ts +0 -8
- package/dist/quicktype-core/attributes/URIAttributes.js +0 -85
- package/dist/quicktype-core/index.d.ts +0 -48
- package/dist/quicktype-core/index.js +0 -180
- package/dist/quicktype-core/input/CompressedJSON.d.ts +0 -69
- package/dist/quicktype-core/input/CompressedJSON.js +0 -276
- package/dist/quicktype-core/input/FetchingJSONSchemaStore.d.ts +0 -6
- package/dist/quicktype-core/input/FetchingJSONSchemaStore.js +0 -18
- package/dist/quicktype-core/input/Inference.d.ts +0 -22
- package/dist/quicktype-core/input/Inference.js +0 -240
- package/dist/quicktype-core/input/Inputs.d.ts +0 -48
- package/dist/quicktype-core/input/Inputs.js +0 -145
- package/dist/quicktype-core/input/JSONSchemaInput.d.ts +0 -91
- package/dist/quicktype-core/input/JSONSchemaInput.js +0 -1041
- package/dist/quicktype-core/input/JSONSchemaStore.d.ts +0 -8
- package/dist/quicktype-core/input/JSONSchemaStore.js +0 -36
- package/dist/quicktype-core/input/PostmanCollection.d.ts +0 -5
- package/dist/quicktype-core/input/PostmanCollection.js +0 -60
- package/dist/quicktype-core/input/io/NodeIO.d.ts +0 -3
- package/dist/quicktype-core/input/io/NodeIO.js +0 -87
- package/dist/quicktype-core/input/io/get-stream/buffer-stream.d.ts +0 -2
- package/dist/quicktype-core/input/io/get-stream/buffer-stream.js +0 -45
- package/dist/quicktype-core/input/io/get-stream/index.d.ts +0 -9
- package/dist/quicktype-core/input/io/get-stream/index.js +0 -52
- package/dist/quicktype-core/language/All.d.ts +0 -3
- package/dist/quicktype-core/language/All.js +0 -57
- package/dist/quicktype-core/language/CPlusPlus.d.ts +0 -241
- package/dist/quicktype-core/language/CPlusPlus.js +0 -1847
- package/dist/quicktype-core/language/CSharp.d.ts +0 -201
- package/dist/quicktype-core/language/CSharp.js +0 -1850
- package/dist/quicktype-core/language/Crystal.d.ts +0 -37
- package/dist/quicktype-core/language/Crystal.js +0 -337
- package/dist/quicktype-core/language/Dart.d.ts +0 -66
- package/dist/quicktype-core/language/Dart.js +0 -576
- package/dist/quicktype-core/language/Elm.d.ts +0 -58
- package/dist/quicktype-core/language/Elm.js +0 -522
- package/dist/quicktype-core/language/Golang.d.ts +0 -51
- package/dist/quicktype-core/language/Golang.js +0 -460
- package/dist/quicktype-core/language/Haskell.d.ts +0 -56
- package/dist/quicktype-core/language/Haskell.js +0 -411
- package/dist/quicktype-core/language/JSONSchema.d.ts +0 -31
- package/dist/quicktype-core/language/JSONSchema.js +0 -169
- package/dist/quicktype-core/language/Java.d.ts +0 -125
- package/dist/quicktype-core/language/Java.js +0 -1081
- package/dist/quicktype-core/language/JavaScript.d.ts +0 -68
- package/dist/quicktype-core/language/JavaScript.js +0 -435
- package/dist/quicktype-core/language/JavaScriptPropTypes.d.ts +0 -40
- package/dist/quicktype-core/language/JavaScriptPropTypes.js +0 -213
- package/dist/quicktype-core/language/JavaScriptUnicodeMaps.d.ts +0 -2
- package/dist/quicktype-core/language/JavaScriptUnicodeMaps.js +0 -134
- package/dist/quicktype-core/language/Kotlin.d.ts +0 -109
- package/dist/quicktype-core/language/Kotlin.js +0 -832
- package/dist/quicktype-core/language/Objective-C.d.ts +0 -79
- package/dist/quicktype-core/language/Objective-C.js +0 -777
- package/dist/quicktype-core/language/Php.d.ts +0 -80
- package/dist/quicktype-core/language/Php.js +0 -702
- package/dist/quicktype-core/language/Pike.d.ts +0 -37
- package/dist/quicktype-core/language/Pike.js +0 -276
- package/dist/quicktype-core/language/Python.d.ts +0 -107
- package/dist/quicktype-core/language/Python.js +0 -969
- package/dist/quicktype-core/language/Rust.d.ts +0 -56
- package/dist/quicktype-core/language/Rust.js +0 -309
- package/dist/quicktype-core/language/Swift.d.ts +0 -96
- package/dist/quicktype-core/language/Swift.js +0 -1211
- package/dist/quicktype-core/language/TypeScriptFlow.d.ts +0 -77
- package/dist/quicktype-core/language/TypeScriptFlow.js +0 -286
- package/dist/quicktype-core/language/ruby/index.d.ts +0 -52
- package/dist/quicktype-core/language/ruby/index.js +0 -557
- package/dist/quicktype-core/language/ruby/keywords.d.ts +0 -3
- package/dist/quicktype-core/language/ruby/keywords.js +0 -358
- package/dist/quicktype-core/rewrites/CombineClasses.d.ts +0 -3
- package/dist/quicktype-core/rewrites/CombineClasses.js +0 -125
- package/dist/quicktype-core/rewrites/ExpandStrings.d.ts +0 -4
- package/dist/quicktype-core/rewrites/ExpandStrings.js +0 -143
- package/dist/quicktype-core/rewrites/FlattenStrings.d.ts +0 -3
- package/dist/quicktype-core/rewrites/FlattenStrings.js +0 -45
- package/dist/quicktype-core/rewrites/FlattenUnions.d.ts +0 -3
- package/dist/quicktype-core/rewrites/FlattenUnions.js +0 -47
- package/dist/quicktype-core/rewrites/InferMaps.d.ts +0 -3
- package/dist/quicktype-core/rewrites/InferMaps.js +0 -117
- package/dist/quicktype-core/rewrites/ReplaceObjectType.d.ts +0 -3
- package/dist/quicktype-core/rewrites/ReplaceObjectType.js +0 -60
- package/dist/quicktype-core/rewrites/ResolveIntersections.d.ts +0 -3
- package/dist/quicktype-core/rewrites/ResolveIntersections.js +0 -244
- package/dist/quicktype-core/support/Acronyms.d.ts +0 -10
- package/dist/quicktype-core/support/Acronyms.js +0 -1128
- package/dist/quicktype-core/support/Chance.d.ts +0 -38
- package/dist/quicktype-core/support/Chance.js +0 -2146
- package/dist/quicktype-core/support/Converters.d.ts +0 -6
- package/dist/quicktype-core/support/Converters.js +0 -16
- package/dist/quicktype-core/support/Strings.d.ts +0 -44
- package/dist/quicktype-core/support/Strings.js +0 -525
- package/dist/quicktype-core/support/Support.d.ts +0 -29
- package/dist/quicktype-core/support/Support.js +0 -162
- package/dist/quicktype-graphql-input/GraphQLSchema.d.ts +0 -645
- package/dist/quicktype-graphql-input/GraphQLSchema.js +0 -39
- package/dist/quicktype-graphql-input/index.d.ts +0 -17
- package/dist/quicktype-graphql-input/index.js +0 -407
- package/dist/quicktype-typescript-input/index.d.ts +0 -2
- package/dist/quicktype-typescript-input/index.js +0 -98
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { TargetLanguage } from "../TargetLanguage";
|
|
2
|
-
import { ConvenienceRenderer, ForbiddenWordsInfo } from "../ConvenienceRenderer";
|
|
3
|
-
import { Name, Namer } from "../Naming";
|
|
4
|
-
import { UnionType, Type, ClassType, EnumType } from "../Type";
|
|
5
|
-
import { Sourcelike } from "../Source";
|
|
6
|
-
import { BooleanOption, EnumOption, Option, OptionValues } from "../RendererOptions";
|
|
7
|
-
import { RenderContext } from "../Renderer";
|
|
8
|
-
export declare enum Density {
|
|
9
|
-
Normal = 0,
|
|
10
|
-
Dense = 1
|
|
11
|
-
}
|
|
12
|
-
export declare enum Visibility {
|
|
13
|
-
Private = 0,
|
|
14
|
-
Crate = 1,
|
|
15
|
-
Public = 2
|
|
16
|
-
}
|
|
17
|
-
export declare const rustOptions: {
|
|
18
|
-
density: EnumOption<Density>;
|
|
19
|
-
visibility: EnumOption<Visibility>;
|
|
20
|
-
deriveDebug: BooleanOption;
|
|
21
|
-
edition2018: BooleanOption;
|
|
22
|
-
leadingComments: BooleanOption;
|
|
23
|
-
};
|
|
24
|
-
export declare class RustTargetLanguage extends TargetLanguage {
|
|
25
|
-
protected makeRenderer(renderContext: RenderContext, untypedOptionValues: {
|
|
26
|
-
[name: string]: any;
|
|
27
|
-
}): RustRenderer;
|
|
28
|
-
constructor();
|
|
29
|
-
protected getOptions(): Option<any>[];
|
|
30
|
-
}
|
|
31
|
-
export declare class RustRenderer extends ConvenienceRenderer {
|
|
32
|
-
private readonly _options;
|
|
33
|
-
constructor(targetLanguage: TargetLanguage, renderContext: RenderContext, _options: OptionValues<typeof rustOptions>);
|
|
34
|
-
protected makeNamedTypeNamer(): Namer;
|
|
35
|
-
protected namerForObjectProperty(): Namer | null;
|
|
36
|
-
protected makeUnionMemberNamer(): Namer | null;
|
|
37
|
-
protected makeEnumCaseNamer(): Namer | null;
|
|
38
|
-
protected forbiddenNamesForGlobalNamespace(): string[];
|
|
39
|
-
protected forbiddenForObjectProperties(_c: ClassType, _className: Name): ForbiddenWordsInfo;
|
|
40
|
-
protected forbiddenForUnionMembers(_u: UnionType, _unionName: Name): ForbiddenWordsInfo;
|
|
41
|
-
protected forbiddenForEnumCases(_e: EnumType, _enumName: Name): ForbiddenWordsInfo;
|
|
42
|
-
protected get commentLineStart(): string;
|
|
43
|
-
private nullableRustType;
|
|
44
|
-
protected isImplicitCycleBreaker(t: Type): boolean;
|
|
45
|
-
private rustType;
|
|
46
|
-
private breakCycle;
|
|
47
|
-
private emitRenameAttribute;
|
|
48
|
-
private get visibility();
|
|
49
|
-
protected emitStructDefinition(c: ClassType, className: Name): void;
|
|
50
|
-
protected emitBlock(line: Sourcelike, f: () => void): void;
|
|
51
|
-
protected emitUnion(u: UnionType, unionName: Name): void;
|
|
52
|
-
protected emitEnumDefinition(e: EnumType, enumName: Name): void;
|
|
53
|
-
protected emitTopLevelAlias(t: Type, name: Name): void;
|
|
54
|
-
protected emitLeadingComments(): void;
|
|
55
|
-
protected emitSourceStructure(): void;
|
|
56
|
-
}
|
|
@@ -1,309 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RustRenderer = exports.RustTargetLanguage = exports.rustOptions = exports.Visibility = exports.Density = void 0;
|
|
4
|
-
const collection_utils_1 = require("collection-utils");
|
|
5
|
-
const TargetLanguage_1 = require("../TargetLanguage");
|
|
6
|
-
const ConvenienceRenderer_1 = require("../ConvenienceRenderer");
|
|
7
|
-
const Strings_1 = require("../support/Strings");
|
|
8
|
-
const Naming_1 = require("../Naming");
|
|
9
|
-
const TypeUtils_1 = require("../TypeUtils");
|
|
10
|
-
const Source_1 = require("../Source");
|
|
11
|
-
const Annotation_1 = require("../Annotation");
|
|
12
|
-
const RendererOptions_1 = require("../RendererOptions");
|
|
13
|
-
const Support_1 = require("../support/Support");
|
|
14
|
-
var Density;
|
|
15
|
-
(function (Density) {
|
|
16
|
-
Density[Density["Normal"] = 0] = "Normal";
|
|
17
|
-
Density[Density["Dense"] = 1] = "Dense";
|
|
18
|
-
})(Density = exports.Density || (exports.Density = {}));
|
|
19
|
-
var Visibility;
|
|
20
|
-
(function (Visibility) {
|
|
21
|
-
Visibility[Visibility["Private"] = 0] = "Private";
|
|
22
|
-
Visibility[Visibility["Crate"] = 1] = "Crate";
|
|
23
|
-
Visibility[Visibility["Public"] = 2] = "Public";
|
|
24
|
-
})(Visibility = exports.Visibility || (exports.Visibility = {}));
|
|
25
|
-
exports.rustOptions = {
|
|
26
|
-
density: new RendererOptions_1.EnumOption("density", "Density", [
|
|
27
|
-
["normal", Density.Normal],
|
|
28
|
-
["dense", Density.Dense]
|
|
29
|
-
]),
|
|
30
|
-
visibility: new RendererOptions_1.EnumOption("visibility", "Field visibility", [
|
|
31
|
-
["private", Visibility.Private],
|
|
32
|
-
["crate", Visibility.Crate],
|
|
33
|
-
["public", Visibility.Public]
|
|
34
|
-
]),
|
|
35
|
-
deriveDebug: new RendererOptions_1.BooleanOption("derive-debug", "Derive Debug impl", false),
|
|
36
|
-
edition2018: new RendererOptions_1.BooleanOption("edition-2018", "Edition 2018", false),
|
|
37
|
-
leadingComments: new RendererOptions_1.BooleanOption("leading-comments", "Leading Comments", true)
|
|
38
|
-
};
|
|
39
|
-
class RustTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
40
|
-
makeRenderer(renderContext, untypedOptionValues) {
|
|
41
|
-
return new RustRenderer(this, renderContext, (0, RendererOptions_1.getOptionValues)(exports.rustOptions, untypedOptionValues));
|
|
42
|
-
}
|
|
43
|
-
constructor() {
|
|
44
|
-
super("Rust", ["rust", "rs", "rustlang"], "rs");
|
|
45
|
-
}
|
|
46
|
-
getOptions() {
|
|
47
|
-
return [
|
|
48
|
-
exports.rustOptions.density,
|
|
49
|
-
exports.rustOptions.visibility,
|
|
50
|
-
exports.rustOptions.deriveDebug,
|
|
51
|
-
exports.rustOptions.edition2018,
|
|
52
|
-
exports.rustOptions.leadingComments
|
|
53
|
-
];
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
exports.RustTargetLanguage = RustTargetLanguage;
|
|
57
|
-
const keywords = [
|
|
58
|
-
// Special reserved identifiers used internally for elided lifetimes,
|
|
59
|
-
// unnamed method parameters, crate root module, error recovery etc.
|
|
60
|
-
"{{root}}",
|
|
61
|
-
"$crate",
|
|
62
|
-
// Keywords used in the language.
|
|
63
|
-
"as",
|
|
64
|
-
"box",
|
|
65
|
-
"break",
|
|
66
|
-
"const",
|
|
67
|
-
"continue",
|
|
68
|
-
"crate",
|
|
69
|
-
"else",
|
|
70
|
-
"enum",
|
|
71
|
-
"extern",
|
|
72
|
-
"false",
|
|
73
|
-
"fn",
|
|
74
|
-
"for",
|
|
75
|
-
"if",
|
|
76
|
-
"impl",
|
|
77
|
-
"in",
|
|
78
|
-
"let",
|
|
79
|
-
"loop",
|
|
80
|
-
"match",
|
|
81
|
-
"mod",
|
|
82
|
-
"move",
|
|
83
|
-
"mut",
|
|
84
|
-
"pub",
|
|
85
|
-
"ref",
|
|
86
|
-
"return",
|
|
87
|
-
"self",
|
|
88
|
-
"Self",
|
|
89
|
-
"static",
|
|
90
|
-
"struct",
|
|
91
|
-
"super",
|
|
92
|
-
"trait",
|
|
93
|
-
"true",
|
|
94
|
-
"type",
|
|
95
|
-
"unsafe",
|
|
96
|
-
"use",
|
|
97
|
-
"where",
|
|
98
|
-
"while",
|
|
99
|
-
// Keywords reserved for future use.
|
|
100
|
-
"abstract",
|
|
101
|
-
"alignof",
|
|
102
|
-
"become",
|
|
103
|
-
"do",
|
|
104
|
-
"final",
|
|
105
|
-
"macro",
|
|
106
|
-
"offsetof",
|
|
107
|
-
"override",
|
|
108
|
-
"priv",
|
|
109
|
-
"proc",
|
|
110
|
-
"pure",
|
|
111
|
-
"sizeof",
|
|
112
|
-
"typeof",
|
|
113
|
-
"unsized",
|
|
114
|
-
"virtual",
|
|
115
|
-
"yield",
|
|
116
|
-
// Weak keywords, have special meaning only in specific contexts.
|
|
117
|
-
"catch",
|
|
118
|
-
"default",
|
|
119
|
-
"dyn",
|
|
120
|
-
"'static",
|
|
121
|
-
"union"
|
|
122
|
-
];
|
|
123
|
-
const isAsciiLetterOrUnderscoreOrDigit = (codePoint) => {
|
|
124
|
-
if (!(0, Strings_1.isAscii)(codePoint)) {
|
|
125
|
-
return false;
|
|
126
|
-
}
|
|
127
|
-
return (0, Strings_1.isLetterOrUnderscoreOrDigit)(codePoint);
|
|
128
|
-
};
|
|
129
|
-
const isAsciiLetterOrUnderscore = (codePoint) => {
|
|
130
|
-
if (!(0, Strings_1.isAscii)(codePoint)) {
|
|
131
|
-
return false;
|
|
132
|
-
}
|
|
133
|
-
return (0, Strings_1.isLetterOrUnderscore)(codePoint);
|
|
134
|
-
};
|
|
135
|
-
const legalizeName = (0, Strings_1.legalizeCharacters)(isAsciiLetterOrUnderscoreOrDigit);
|
|
136
|
-
function rustStyle(original, isSnakeCase) {
|
|
137
|
-
const words = (0, Strings_1.splitIntoWords)(original);
|
|
138
|
-
const wordStyle = isSnakeCase ? Strings_1.allLowerWordStyle : Strings_1.firstUpperWordStyle;
|
|
139
|
-
const combined = (0, Strings_1.combineWords)(words, legalizeName, wordStyle, wordStyle, wordStyle, wordStyle, isSnakeCase ? "_" : "", isAsciiLetterOrUnderscore);
|
|
140
|
-
return combined === "_" ? "_underscore" : combined;
|
|
141
|
-
}
|
|
142
|
-
const snakeNamingFunction = (0, Naming_1.funPrefixNamer)("default", (original) => rustStyle(original, true));
|
|
143
|
-
const camelNamingFunction = (0, Naming_1.funPrefixNamer)("camel", (original) => rustStyle(original, false));
|
|
144
|
-
const standardUnicodeRustEscape = (codePoint) => {
|
|
145
|
-
if (codePoint <= 0xffff) {
|
|
146
|
-
return "\\u{" + (0, Strings_1.intToHex)(codePoint, 4) + "}";
|
|
147
|
-
}
|
|
148
|
-
else {
|
|
149
|
-
return "\\u{" + (0, Strings_1.intToHex)(codePoint, 6) + "}";
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
const rustStringEscape = (0, Strings_1.utf32ConcatMap)((0, Strings_1.escapeNonPrintableMapper)(Strings_1.isPrintable, standardUnicodeRustEscape));
|
|
153
|
-
class RustRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
154
|
-
_options;
|
|
155
|
-
constructor(targetLanguage, renderContext, _options) {
|
|
156
|
-
super(targetLanguage, renderContext);
|
|
157
|
-
this._options = _options;
|
|
158
|
-
}
|
|
159
|
-
makeNamedTypeNamer() {
|
|
160
|
-
return camelNamingFunction;
|
|
161
|
-
}
|
|
162
|
-
namerForObjectProperty() {
|
|
163
|
-
return snakeNamingFunction;
|
|
164
|
-
}
|
|
165
|
-
makeUnionMemberNamer() {
|
|
166
|
-
return camelNamingFunction;
|
|
167
|
-
}
|
|
168
|
-
makeEnumCaseNamer() {
|
|
169
|
-
return camelNamingFunction;
|
|
170
|
-
}
|
|
171
|
-
forbiddenNamesForGlobalNamespace() {
|
|
172
|
-
return keywords;
|
|
173
|
-
}
|
|
174
|
-
forbiddenForObjectProperties(_c, _className) {
|
|
175
|
-
return { names: [], includeGlobalForbidden: true };
|
|
176
|
-
}
|
|
177
|
-
forbiddenForUnionMembers(_u, _unionName) {
|
|
178
|
-
return { names: [], includeGlobalForbidden: true };
|
|
179
|
-
}
|
|
180
|
-
forbiddenForEnumCases(_e, _enumName) {
|
|
181
|
-
return { names: [], includeGlobalForbidden: true };
|
|
182
|
-
}
|
|
183
|
-
get commentLineStart() {
|
|
184
|
-
return "/// ";
|
|
185
|
-
}
|
|
186
|
-
nullableRustType(t, withIssues) {
|
|
187
|
-
return ["Option<", this.breakCycle(t, withIssues), ">"];
|
|
188
|
-
}
|
|
189
|
-
isImplicitCycleBreaker(t) {
|
|
190
|
-
const kind = t.kind;
|
|
191
|
-
return kind === "array" || kind === "map";
|
|
192
|
-
}
|
|
193
|
-
rustType(t, withIssues = false) {
|
|
194
|
-
return (0, TypeUtils_1.matchType)(t, _anyType => (0, Source_1.maybeAnnotated)(withIssues, Annotation_1.anyTypeIssueAnnotation, "Option<serde_json::Value>"), _nullType => (0, Source_1.maybeAnnotated)(withIssues, Annotation_1.nullTypeIssueAnnotation, "Option<serde_json::Value>"), _boolType => "bool", _integerType => "i64", _doubleType => "f64", _stringType => "String", arrayType => ["Vec<", this.rustType(arrayType.items, withIssues), ">"], classType => this.nameForNamedType(classType), mapType => ["HashMap<String, ", this.rustType(mapType.values, withIssues), ">"], enumType => this.nameForNamedType(enumType), unionType => {
|
|
195
|
-
const nullable = (0, TypeUtils_1.nullableFromUnion)(unionType);
|
|
196
|
-
if (nullable !== null)
|
|
197
|
-
return this.nullableRustType(nullable, withIssues);
|
|
198
|
-
const [hasNull] = (0, TypeUtils_1.removeNullFromUnion)(unionType);
|
|
199
|
-
const isCycleBreaker = this.isCycleBreakerType(unionType);
|
|
200
|
-
const name = isCycleBreaker
|
|
201
|
-
? ["Box<", this.nameForNamedType(unionType), ">"]
|
|
202
|
-
: this.nameForNamedType(unionType);
|
|
203
|
-
return hasNull !== null ? ["Option<", name, ">"] : name;
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
breakCycle(t, withIssues) {
|
|
207
|
-
const rustType = this.rustType(t, withIssues);
|
|
208
|
-
const isCycleBreaker = this.isCycleBreakerType(t);
|
|
209
|
-
return isCycleBreaker ? ["Box<", rustType, ">"] : rustType;
|
|
210
|
-
}
|
|
211
|
-
emitRenameAttribute(propName, jsonName) {
|
|
212
|
-
const escapedName = rustStringEscape(jsonName);
|
|
213
|
-
const namesDiffer = this.sourcelikeToString(propName) !== escapedName;
|
|
214
|
-
if (namesDiffer || this._options.density === Density.Normal) {
|
|
215
|
-
this.emitLine('#[serde(rename = "', escapedName, '")]');
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
get visibility() {
|
|
219
|
-
if (this._options.visibility === Visibility.Crate) {
|
|
220
|
-
return "pub(crate) ";
|
|
221
|
-
}
|
|
222
|
-
else if (this._options.visibility === Visibility.Public) {
|
|
223
|
-
return "pub ";
|
|
224
|
-
}
|
|
225
|
-
return "";
|
|
226
|
-
}
|
|
227
|
-
emitStructDefinition(c, className) {
|
|
228
|
-
this.emitDescription(this.descriptionForType(c));
|
|
229
|
-
this.emitLine("#[derive(", this._options.deriveDebug ? "Debug, " : "", "Serialize, Deserialize)]");
|
|
230
|
-
const blankLines = this._options.density === Density.Dense ? "none" : "interposing";
|
|
231
|
-
const structBody = () => this.forEachClassProperty(c, blankLines, (name, jsonName, prop) => {
|
|
232
|
-
this.emitDescription(this.descriptionForClassProperty(c, jsonName));
|
|
233
|
-
this.emitRenameAttribute(name, jsonName);
|
|
234
|
-
this.emitLine(this.visibility, name, ": ", this.breakCycle(prop.type, true), ",");
|
|
235
|
-
});
|
|
236
|
-
this.emitBlock(["pub struct ", className], structBody);
|
|
237
|
-
}
|
|
238
|
-
emitBlock(line, f) {
|
|
239
|
-
this.emitLine(line, " {");
|
|
240
|
-
this.indent(f);
|
|
241
|
-
this.emitLine("}");
|
|
242
|
-
}
|
|
243
|
-
emitUnion(u, unionName) {
|
|
244
|
-
const isMaybeWithSingleType = (0, TypeUtils_1.nullableFromUnion)(u);
|
|
245
|
-
if (isMaybeWithSingleType !== null) {
|
|
246
|
-
return;
|
|
247
|
-
}
|
|
248
|
-
this.emitDescription(this.descriptionForType(u));
|
|
249
|
-
this.emitLine("#[derive(", this._options.deriveDebug ? "Debug, " : "", "Serialize, Deserialize)]");
|
|
250
|
-
this.emitLine("#[serde(untagged)]");
|
|
251
|
-
const [, nonNulls] = (0, TypeUtils_1.removeNullFromUnion)(u);
|
|
252
|
-
const blankLines = this._options.density === Density.Dense ? "none" : "interposing";
|
|
253
|
-
this.emitBlock(["pub enum ", unionName], () => this.forEachUnionMember(u, nonNulls, blankLines, null, (fieldName, t) => {
|
|
254
|
-
const rustType = this.breakCycle(t, true);
|
|
255
|
-
this.emitLine([fieldName, "(", rustType, "),"]);
|
|
256
|
-
}));
|
|
257
|
-
}
|
|
258
|
-
emitEnumDefinition(e, enumName) {
|
|
259
|
-
this.emitDescription(this.descriptionForType(e));
|
|
260
|
-
this.emitLine("#[derive(", this._options.deriveDebug ? "Debug, " : "", "Serialize, Deserialize)]");
|
|
261
|
-
const blankLines = this._options.density === Density.Dense ? "none" : "interposing";
|
|
262
|
-
this.emitBlock(["pub enum ", enumName], () => this.forEachEnumCase(e, blankLines, (name, jsonName) => {
|
|
263
|
-
this.emitRenameAttribute(name, jsonName);
|
|
264
|
-
this.emitLine([name, ","]);
|
|
265
|
-
}));
|
|
266
|
-
}
|
|
267
|
-
emitTopLevelAlias(t, name) {
|
|
268
|
-
this.emitLine("pub type ", name, " = ", this.rustType(t), ";");
|
|
269
|
-
}
|
|
270
|
-
emitLeadingComments() {
|
|
271
|
-
if (this.leadingComments !== undefined) {
|
|
272
|
-
this.emitCommentLines(this.leadingComments);
|
|
273
|
-
return;
|
|
274
|
-
}
|
|
275
|
-
const topLevelName = (0, Support_1.defined)((0, collection_utils_1.mapFirst)(this.topLevels)).getCombinedName();
|
|
276
|
-
this.emitMultiline(`// Example code that deserializes and serializes the model.
|
|
277
|
-
// extern crate serde;
|
|
278
|
-
// #[macro_use]
|
|
279
|
-
// extern crate serde_derive;
|
|
280
|
-
// extern crate serde_json;
|
|
281
|
-
//
|
|
282
|
-
// use generated_module::${topLevelName};
|
|
283
|
-
//
|
|
284
|
-
// fn main() {
|
|
285
|
-
// let json = r#"{"answer": 42}"#;
|
|
286
|
-
// let model: ${topLevelName} = serde_json::from_str(&json).unwrap();
|
|
287
|
-
// }`);
|
|
288
|
-
}
|
|
289
|
-
emitSourceStructure() {
|
|
290
|
-
if (this._options.leadingComments) {
|
|
291
|
-
this.emitLeadingComments();
|
|
292
|
-
}
|
|
293
|
-
this.ensureBlankLine();
|
|
294
|
-
if (this._options.edition2018) {
|
|
295
|
-
this.emitLine("use serde::{Serialize, Deserialize};");
|
|
296
|
-
}
|
|
297
|
-
else {
|
|
298
|
-
this.emitLine("extern crate serde_derive;");
|
|
299
|
-
}
|
|
300
|
-
if (this.haveMaps) {
|
|
301
|
-
this.emitLine("use std::collections::HashMap;");
|
|
302
|
-
}
|
|
303
|
-
this.forEachTopLevel("leading", (t, name) => this.emitTopLevelAlias(t, name), t => this.namedTypeToNameForTopLevel(t) === undefined);
|
|
304
|
-
this.forEachObject("leading-and-interposing", (c, name) => this.emitStructDefinition(c, name));
|
|
305
|
-
this.forEachUnion("leading-and-interposing", (u, name) => this.emitUnion(u, name));
|
|
306
|
-
this.forEachEnum("leading-and-interposing", (e, name) => this.emitEnumDefinition(e, name));
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
exports.RustRenderer = RustRenderer;
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { TargetLanguage } from "../TargetLanguage";
|
|
2
|
-
import { Type, ClassType, EnumType, UnionType, TypeKind, ClassProperty } from "../Type";
|
|
3
|
-
import { Name, Namer } from "../Naming";
|
|
4
|
-
import { BooleanOption, EnumOption, Option, StringOption, OptionValues } from "../RendererOptions";
|
|
5
|
-
import { Sourcelike } from "../Source";
|
|
6
|
-
import { ConvenienceRenderer, ForbiddenWordsInfo } from "../ConvenienceRenderer";
|
|
7
|
-
import { RenderContext, ForEachPosition } from "../Renderer";
|
|
8
|
-
import { StringTypeMapping } from "../TypeBuilder";
|
|
9
|
-
import { DateTimeRecognizer } from "../DateTime";
|
|
10
|
-
import { AcronymStyleOptions } from "../support/Acronyms";
|
|
11
|
-
export declare const swiftOptions: {
|
|
12
|
-
justTypes: BooleanOption;
|
|
13
|
-
convenienceInitializers: BooleanOption;
|
|
14
|
-
explicitCodingKeys: BooleanOption;
|
|
15
|
-
alamofire: BooleanOption;
|
|
16
|
-
namedTypePrefix: StringOption;
|
|
17
|
-
useClasses: EnumOption<boolean>;
|
|
18
|
-
mutableProperties: BooleanOption;
|
|
19
|
-
acronymStyle: EnumOption<AcronymStyleOptions>;
|
|
20
|
-
dense: EnumOption<boolean>;
|
|
21
|
-
linux: BooleanOption;
|
|
22
|
-
objcSupport: BooleanOption;
|
|
23
|
-
optionalEnums: BooleanOption;
|
|
24
|
-
swift5Support: BooleanOption;
|
|
25
|
-
multiFileOutput: BooleanOption;
|
|
26
|
-
accessLevel: EnumOption<string>;
|
|
27
|
-
protocol: EnumOption<{
|
|
28
|
-
equatable: boolean;
|
|
29
|
-
hashable: boolean;
|
|
30
|
-
}>;
|
|
31
|
-
};
|
|
32
|
-
export interface SwiftProperty {
|
|
33
|
-
name: Name;
|
|
34
|
-
jsonName: string;
|
|
35
|
-
parameter: ClassProperty;
|
|
36
|
-
position: ForEachPosition;
|
|
37
|
-
}
|
|
38
|
-
export declare class SwiftTargetLanguage extends TargetLanguage {
|
|
39
|
-
constructor();
|
|
40
|
-
protected getOptions(): Option<any>[];
|
|
41
|
-
get stringTypeMapping(): StringTypeMapping;
|
|
42
|
-
get supportsOptionalClassProperties(): boolean;
|
|
43
|
-
get supportsUnionsWithBothNumberTypes(): boolean;
|
|
44
|
-
protected makeRenderer(renderContext: RenderContext, untypedOptionValues: {
|
|
45
|
-
[name: string]: any;
|
|
46
|
-
}): SwiftRenderer;
|
|
47
|
-
get dateTimeRecognizer(): DateTimeRecognizer;
|
|
48
|
-
}
|
|
49
|
-
export declare class SwiftRenderer extends ConvenienceRenderer {
|
|
50
|
-
private readonly _options;
|
|
51
|
-
private _currentFilename;
|
|
52
|
-
private _needAny;
|
|
53
|
-
private _needNull;
|
|
54
|
-
constructor(targetLanguage: TargetLanguage, renderContext: RenderContext, _options: OptionValues<typeof swiftOptions>);
|
|
55
|
-
protected forbiddenNamesForGlobalNamespace(): string[];
|
|
56
|
-
protected forbiddenForObjectProperties(_c: ClassType, _classNamed: Name): ForbiddenWordsInfo;
|
|
57
|
-
protected forbiddenForEnumCases(_e: EnumType, _enumName: Name): ForbiddenWordsInfo;
|
|
58
|
-
protected forbiddenForUnionMembers(_u: UnionType, _unionName: Name): ForbiddenWordsInfo;
|
|
59
|
-
protected makeNamedTypeNamer(): Namer;
|
|
60
|
-
protected namerForObjectProperty(): Namer;
|
|
61
|
-
protected makeUnionMemberNamer(): Namer;
|
|
62
|
-
protected makeEnumCaseNamer(): Namer;
|
|
63
|
-
protected isImplicitCycleBreaker(t: Type): boolean;
|
|
64
|
-
protected emitDescriptionBlock(lines: Sourcelike[]): void;
|
|
65
|
-
private emitBlock;
|
|
66
|
-
private emitBlockWithAccess;
|
|
67
|
-
private justTypesCase;
|
|
68
|
-
private get lowerNamingFunction();
|
|
69
|
-
protected swiftPropertyType(p: ClassProperty): Sourcelike;
|
|
70
|
-
protected swiftType(t: Type, withIssues?: boolean, noOptional?: boolean): Sourcelike;
|
|
71
|
-
protected proposedUnionMemberNameForTypeKind(kind: TypeKind): string | null;
|
|
72
|
-
private renderSingleFileHeaderComments;
|
|
73
|
-
private renderHeader;
|
|
74
|
-
private renderTopLevelAlias;
|
|
75
|
-
protected getProtocolsArray(_t: Type, isClass: boolean): string[];
|
|
76
|
-
private getProtocolString;
|
|
77
|
-
private getEnumPropertyGroups;
|
|
78
|
-
private get accessLevel();
|
|
79
|
-
private get objcMembersDeclaration();
|
|
80
|
-
protected startFile(basename: Sourcelike): void;
|
|
81
|
-
protected endFile(): void;
|
|
82
|
-
protected propertyLinesDefinition(name: Name, parameter: ClassProperty): Sourcelike;
|
|
83
|
-
private renderClassDefinition;
|
|
84
|
-
protected initializableProperties(c: ClassType): SwiftProperty[];
|
|
85
|
-
private emitNewEncoderDecoder;
|
|
86
|
-
private emitConvenienceInitializersExtension;
|
|
87
|
-
private renderEnumDefinition;
|
|
88
|
-
private renderUnionDefinition;
|
|
89
|
-
private emitTopLevelMapAndArrayConvenienceInitializerExtensions;
|
|
90
|
-
private emitDecodingError;
|
|
91
|
-
private emitSupportFunctions4;
|
|
92
|
-
private emitConvenienceMutator;
|
|
93
|
-
protected emitMark(line: Sourcelike, horizontalLine?: boolean): void;
|
|
94
|
-
protected emitSourceStructure(): void;
|
|
95
|
-
private emitAlamofireExtension;
|
|
96
|
-
}
|