quicktype 17.0.0 → 17.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/CompressedJSONFromStream.js +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 +8 -8
- package/dist/quicktype-core/language/CPlusPlus.js +151 -185
- 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,11 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.nullTypeIssueAnnotation = exports.anyTypeIssueAnnotation = exports.IssueAnnotationData = exports.AnnotationData = void 0;
|
|
4
3
|
class AnnotationData {
|
|
5
4
|
}
|
|
6
5
|
exports.AnnotationData = AnnotationData;
|
|
7
6
|
class IssueAnnotationData extends AnnotationData {
|
|
8
|
-
message;
|
|
9
7
|
constructor(message) {
|
|
10
8
|
super();
|
|
11
9
|
this.message = message;
|
|
@@ -7,7 +7,7 @@ import { Transformation } from "./Transformers";
|
|
|
7
7
|
import { TargetLanguage } from "./TargetLanguage";
|
|
8
8
|
export declare const topLevelNameOrder = 1;
|
|
9
9
|
export declare const inferredNameOrder = 30;
|
|
10
|
-
export type ForbiddenWordsInfo = {
|
|
10
|
+
export declare type ForbiddenWordsInfo = {
|
|
11
11
|
names: (Name | string)[];
|
|
12
12
|
includeGlobalForbidden: boolean;
|
|
13
13
|
};
|
|
@@ -34,7 +34,7 @@ export declare abstract class ConvenienceRenderer extends Renderer {
|
|
|
34
34
|
private _cycleBreakerTypes?;
|
|
35
35
|
private _alphabetizeProperties;
|
|
36
36
|
constructor(targetLanguage: TargetLanguage, renderContext: RenderContext);
|
|
37
|
-
|
|
37
|
+
readonly topLevels: ReadonlyMap<string, Type>;
|
|
38
38
|
/**
|
|
39
39
|
* Return an array of strings which are not allowed as names in the global
|
|
40
40
|
* namespace. Since names of generated types are in the global namespace,
|
|
@@ -65,13 +65,13 @@ export declare abstract class ConvenienceRenderer extends Renderer {
|
|
|
65
65
|
protected abstract emitSourceStructure(givenOutputFilename: string): void;
|
|
66
66
|
protected makeNameForTransformation(_xf: Transformation, _typeName: Name | undefined): Name | undefined;
|
|
67
67
|
protected namedTypeToNameForTopLevel(type: Type): Type | undefined;
|
|
68
|
-
protected
|
|
69
|
-
protected
|
|
70
|
-
protected
|
|
68
|
+
protected readonly unionMembersInGlobalNamespace: boolean;
|
|
69
|
+
protected readonly enumCasesInGlobalNamespace: boolean;
|
|
70
|
+
protected readonly needsTypeDeclarationBeforeUse: boolean;
|
|
71
71
|
protected canBeForwardDeclared(_t: Type): boolean;
|
|
72
72
|
protected unionNeedsName(u: UnionType): boolean;
|
|
73
|
-
private
|
|
74
|
-
private
|
|
73
|
+
private readonly globalNamespace;
|
|
74
|
+
private readonly nameStoreView;
|
|
75
75
|
protected descriptionForType(t: Type): string[] | undefined;
|
|
76
76
|
protected descriptionForClassProperty(o: ObjectType, name: string): string[] | undefined;
|
|
77
77
|
protected setUpNaming(): ReadonlySet<Namespace>;
|
|
@@ -81,7 +81,7 @@ export declare abstract class ConvenienceRenderer extends Renderer {
|
|
|
81
81
|
private makeNameForType;
|
|
82
82
|
protected makeNameForNamedType(t: Type): Name;
|
|
83
83
|
private addNameForNamedType;
|
|
84
|
-
protected
|
|
84
|
+
protected readonly typesWithNamedTransformations: ReadonlyMap<Type, Name>;
|
|
85
85
|
protected nameForTransformation(t: Type): Name | undefined;
|
|
86
86
|
private addNameForTransformation;
|
|
87
87
|
private processForbiddenWordsInfo;
|
|
@@ -93,14 +93,14 @@ export declare abstract class ConvenienceRenderer extends Renderer {
|
|
|
93
93
|
protected makeNameForEnumCase(e: EnumType, _enumName: Name, caseName: string, assignedName: string | undefined): Name;
|
|
94
94
|
private addEnumCaseNames;
|
|
95
95
|
private childrenOfType;
|
|
96
|
-
protected
|
|
97
|
-
protected
|
|
98
|
-
protected
|
|
99
|
-
protected
|
|
100
|
-
protected
|
|
101
|
-
protected
|
|
102
|
-
protected
|
|
103
|
-
protected
|
|
96
|
+
protected readonly namedUnions: ReadonlySet<UnionType>;
|
|
97
|
+
protected readonly haveNamedUnions: boolean;
|
|
98
|
+
protected readonly haveNamedTypes: boolean;
|
|
99
|
+
protected readonly haveUnions: boolean;
|
|
100
|
+
protected readonly haveMaps: boolean;
|
|
101
|
+
protected readonly haveOptionalProperties: boolean;
|
|
102
|
+
protected readonly enums: ReadonlySet<EnumType>;
|
|
103
|
+
protected readonly haveEnums: boolean;
|
|
104
104
|
protected proposedUnionMemberNameForTypeKind(_kind: TypeKind): string | null;
|
|
105
105
|
protected proposeUnionMemberName(_u: UnionType, _unionName: Name, fieldType: Type, lookup: (n: Name) => string): string;
|
|
106
106
|
protected nameForNamedType(t: Type): Name;
|
|
@@ -127,7 +127,7 @@ export declare abstract class ConvenienceRenderer extends Renderer {
|
|
|
127
127
|
protected forEachUniqueUnion<T>(blankLocations: BlankLineConfig, uniqueValue: (u: UnionType) => T, f: (firstUnion: UnionType, value: T, position: ForEachPosition) => void): void;
|
|
128
128
|
protected forEachNamedType(blankLocations: BlankLineConfig, objectFunc: ((c: ClassType, className: Name, position: ForEachPosition) => void) | ((o: ObjectType, objectName: Name, position: ForEachPosition) => void), enumFunc: (e: EnumType, enumName: Name, position: ForEachPosition) => void, unionFunc: (u: UnionType, unionName: Name, position: ForEachPosition) => void): void;
|
|
129
129
|
protected sourcelikeToString(src: Sourcelike): string;
|
|
130
|
-
protected
|
|
130
|
+
protected readonly commentLineStart: string;
|
|
131
131
|
protected emitCommentLines(lines: Sourcelike[], lineStart?: string, beforeLine?: string, afterLine?: string, firstLineStart?: string): void;
|
|
132
132
|
protected emitDescription(description: Sourcelike[] | undefined): void;
|
|
133
133
|
protected emitDescriptionBlock(lines: Sourcelike[]): void;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConvenienceRenderer = exports.inferredNameOrder = exports.topLevelNameOrder = void 0;
|
|
4
3
|
const collection_utils_1 = require("collection-utils");
|
|
5
4
|
const Type_1 = require("./Type");
|
|
6
5
|
const TypeUtils_1 = require("./TypeUtils");
|
|
@@ -39,31 +38,9 @@ const assignedPropertyNamesAttributeKind = new TypeAttributes_1.TypeAttributeKin
|
|
|
39
38
|
const assignedMemberNamesAttributeKind = new TypeAttributes_1.TypeAttributeKind("assignedMemberNames");
|
|
40
39
|
const assignedCaseNamesAttributeKind = new TypeAttributes_1.TypeAttributeKind("assignedCaseNames");
|
|
41
40
|
class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
42
|
-
_globalForbiddenNamespace;
|
|
43
|
-
_otherForbiddenNamespaces;
|
|
44
|
-
_globalNamespace;
|
|
45
|
-
_nameStoreView;
|
|
46
|
-
_propertyNamesStoreView;
|
|
47
|
-
_memberNamesStoreView;
|
|
48
|
-
_caseNamesStoreView;
|
|
49
|
-
_namesForTransformations;
|
|
50
|
-
_namedTypeNamer;
|
|
51
|
-
// @ts-ignore: FIXME: Make this `Namer | undefined`
|
|
52
|
-
_unionMemberNamer;
|
|
53
|
-
// @ts-ignore: FIXME: Make this `Namer | undefined`
|
|
54
|
-
_enumCaseNamer;
|
|
55
|
-
_declarationIR;
|
|
56
|
-
_namedTypes;
|
|
57
|
-
_namedObjects;
|
|
58
|
-
_namedEnums;
|
|
59
|
-
_namedUnions;
|
|
60
|
-
_haveUnions;
|
|
61
|
-
_haveMaps;
|
|
62
|
-
_haveOptionalProperties;
|
|
63
|
-
_cycleBreakerTypes;
|
|
64
|
-
_alphabetizeProperties = false;
|
|
65
41
|
constructor(targetLanguage, renderContext) {
|
|
66
42
|
super(targetLanguage, renderContext);
|
|
43
|
+
this._alphabetizeProperties = false;
|
|
67
44
|
}
|
|
68
45
|
get topLevels() {
|
|
69
46
|
return this.typeGraph.topLevels;
|
|
@@ -107,7 +84,7 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
107
84
|
return undefined;
|
|
108
85
|
}
|
|
109
86
|
namedTypeToNameForTopLevel(type) {
|
|
110
|
-
if (
|
|
87
|
+
if (TypeUtils_1.isNamedType(type)) {
|
|
111
88
|
return type;
|
|
112
89
|
}
|
|
113
90
|
return undefined;
|
|
@@ -122,16 +99,16 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
122
99
|
return false;
|
|
123
100
|
}
|
|
124
101
|
canBeForwardDeclared(_t) {
|
|
125
|
-
return
|
|
102
|
+
return Support_1.panic("If needsTypeDeclarationBeforeUse returns true, canBeForwardDeclared must be implemented");
|
|
126
103
|
}
|
|
127
104
|
unionNeedsName(u) {
|
|
128
|
-
return
|
|
105
|
+
return TypeUtils_1.nullableFromUnion(u) === null;
|
|
129
106
|
}
|
|
130
107
|
get globalNamespace() {
|
|
131
|
-
return
|
|
108
|
+
return Support_1.defined(this._globalNamespace);
|
|
132
109
|
}
|
|
133
110
|
get nameStoreView() {
|
|
134
|
-
return
|
|
111
|
+
return Support_1.defined(this._nameStoreView);
|
|
135
112
|
}
|
|
136
113
|
descriptionForType(t) {
|
|
137
114
|
let description = this.typeGraph.attributeStore.tryGet(Description_1.descriptionTypeAttributeKind, t);
|
|
@@ -152,11 +129,11 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
152
129
|
this._namedTypeNamer = this.makeNamedTypeNamer();
|
|
153
130
|
this._unionMemberNamer = this.makeUnionMemberNamer();
|
|
154
131
|
this._enumCaseNamer = this.makeEnumCaseNamer();
|
|
155
|
-
this._globalForbiddenNamespace =
|
|
132
|
+
this._globalForbiddenNamespace = Naming_1.keywordNamespace("forbidden", this.forbiddenNamesForGlobalNamespace());
|
|
156
133
|
this._otherForbiddenNamespaces = new Map();
|
|
157
134
|
this._globalNamespace = new Naming_1.Namespace("global", undefined, [this._globalForbiddenNamespace], []);
|
|
158
135
|
const { objects, enums, unions } = this.typeGraph.allNamedTypesSeparated();
|
|
159
|
-
const namedUnions =
|
|
136
|
+
const namedUnions = collection_utils_1.setFilter(unions, u => this.unionNeedsName(u));
|
|
160
137
|
for (const [name, t] of this.topLevels) {
|
|
161
138
|
this.nameStoreView.setForTopLevel(name, this.addNameForTopLevel(t, name));
|
|
162
139
|
}
|
|
@@ -175,7 +152,7 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
175
152
|
for (const t of this.typeGraph.allTypesUnordered()) {
|
|
176
153
|
this.addNameForTransformation(t);
|
|
177
154
|
}
|
|
178
|
-
return
|
|
155
|
+
return collection_utils_1.setUnion([this._globalForbiddenNamespace, this._globalNamespace], this._otherForbiddenNamespaces.values());
|
|
179
156
|
}
|
|
180
157
|
addDependenciesForNamedType(type, named) {
|
|
181
158
|
const dependencyNames = this.makeNamedTypeDependencyNames(type, named);
|
|
@@ -184,7 +161,7 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
184
161
|
}
|
|
185
162
|
}
|
|
186
163
|
makeNameForTopLevel(_t, givenName, _maybeNamedType) {
|
|
187
|
-
return new Naming_1.SimpleName([givenName],
|
|
164
|
+
return new Naming_1.SimpleName([givenName], Support_1.defined(this._namedTypeNamer), exports.topLevelNameOrder);
|
|
188
165
|
}
|
|
189
166
|
addNameForTopLevel(type, givenName) {
|
|
190
167
|
const maybeNamedType = this.namedTypeToNameForTopLevel(type);
|
|
@@ -206,7 +183,7 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
206
183
|
return new Naming_1.SimpleName(names.proposedNames, namer, order);
|
|
207
184
|
}
|
|
208
185
|
makeNameForNamedType(t) {
|
|
209
|
-
return this.makeNameForType(t,
|
|
186
|
+
return this.makeNameForType(t, Support_1.defined(this._namedTypeNamer), givenNameOrder, exports.inferredNameOrder);
|
|
210
187
|
}
|
|
211
188
|
addNameForNamedType(type) {
|
|
212
189
|
const existing = this.nameStoreView.tryGet(type);
|
|
@@ -218,28 +195,28 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
218
195
|
return name;
|
|
219
196
|
}
|
|
220
197
|
get typesWithNamedTransformations() {
|
|
221
|
-
return
|
|
198
|
+
return Support_1.defined(this._namesForTransformations);
|
|
222
199
|
}
|
|
223
200
|
nameForTransformation(t) {
|
|
224
|
-
const xf =
|
|
201
|
+
const xf = Transformers_1.transformationForType(t);
|
|
225
202
|
if (xf === undefined)
|
|
226
203
|
return undefined;
|
|
227
|
-
const name =
|
|
204
|
+
const name = Support_1.defined(this._namesForTransformations).get(t);
|
|
228
205
|
if (name === undefined) {
|
|
229
|
-
return
|
|
206
|
+
return Support_1.panic("No name for transformation");
|
|
230
207
|
}
|
|
231
208
|
return name;
|
|
232
209
|
}
|
|
233
210
|
addNameForTransformation(t) {
|
|
234
|
-
const xf =
|
|
211
|
+
const xf = Transformers_1.transformationForType(t);
|
|
235
212
|
if (xf === undefined)
|
|
236
213
|
return;
|
|
237
|
-
|
|
214
|
+
Support_1.assert(Support_1.defined(this._namesForTransformations).get(t) === undefined, "Tried to give two names to the same transformation");
|
|
238
215
|
const name = this.makeNameForTransformation(xf, this.nameStoreView.tryGet(xf.targetType));
|
|
239
216
|
if (name === undefined)
|
|
240
217
|
return;
|
|
241
218
|
this.globalNamespace.add(name);
|
|
242
|
-
|
|
219
|
+
Support_1.defined(this._namesForTransformations).set(t, name);
|
|
243
220
|
}
|
|
244
221
|
processForbiddenWordsInfo(info, namespaceName) {
|
|
245
222
|
const forbiddenNames = [];
|
|
@@ -252,14 +229,14 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
252
229
|
forbiddenNames.push(nameOrString);
|
|
253
230
|
}
|
|
254
231
|
}
|
|
255
|
-
let namespace =
|
|
232
|
+
let namespace = Support_1.defined(this._otherForbiddenNamespaces).get(namespaceName);
|
|
256
233
|
if (forbiddenStrings.length > 0 && namespace === undefined) {
|
|
257
|
-
namespace =
|
|
258
|
-
this._otherForbiddenNamespaces =
|
|
234
|
+
namespace = Naming_1.keywordNamespace(namespaceName, forbiddenStrings);
|
|
235
|
+
this._otherForbiddenNamespaces = Support_1.defined(this._otherForbiddenNamespaces).set(namespaceName, namespace);
|
|
259
236
|
}
|
|
260
237
|
let forbiddenNamespaces = new Set();
|
|
261
238
|
if (info.includeGlobalForbidden) {
|
|
262
|
-
forbiddenNamespaces = forbiddenNamespaces.add(
|
|
239
|
+
forbiddenNamespaces = forbiddenNamespaces.add(Support_1.defined(this._globalForbiddenNamespace));
|
|
263
240
|
}
|
|
264
241
|
if (namespace !== undefined) {
|
|
265
242
|
forbiddenNamespaces = forbiddenNamespaces.add(namespace);
|
|
@@ -290,12 +267,12 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
290
267
|
addPropertyNames(o, className) {
|
|
291
268
|
const { forbiddenNames, forbiddenNamespaces } = this.processForbiddenWordsInfo(this.forbiddenForObjectProperties(o, className), "forbidden-for-properties");
|
|
292
269
|
let ns;
|
|
293
|
-
const accessorNames =
|
|
294
|
-
const names =
|
|
295
|
-
const [assignedName, isFixed] =
|
|
270
|
+
const accessorNames = AccessorNames_1.objectPropertyNames(o, this.targetLanguage.name);
|
|
271
|
+
const names = collection_utils_1.mapFilterMap(o.getSortedProperties(), (p, jsonName) => {
|
|
272
|
+
const [assignedName, isFixed] = AccessorNames_1.getAccessorName(accessorNames, jsonName);
|
|
296
273
|
let name;
|
|
297
274
|
if (isFixed) {
|
|
298
|
-
name = new Naming_1.FixedName(
|
|
275
|
+
name = new Naming_1.FixedName(Support_1.defined(assignedName));
|
|
299
276
|
}
|
|
300
277
|
else {
|
|
301
278
|
name = this.makeNameForProperty(o, className, p, jsonName, assignedName);
|
|
@@ -311,14 +288,14 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
311
288
|
}
|
|
312
289
|
return name;
|
|
313
290
|
});
|
|
314
|
-
|
|
291
|
+
Support_1.defined(this._propertyNamesStoreView).set(o, names);
|
|
315
292
|
}
|
|
316
293
|
makeNameForUnionMember(u, unionName, t) {
|
|
317
|
-
const [assignedName, isFixed] =
|
|
294
|
+
const [assignedName, isFixed] = AccessorNames_1.unionMemberName(u, t, this.targetLanguage.name);
|
|
318
295
|
if (isFixed) {
|
|
319
|
-
return new Naming_1.FixedName(
|
|
296
|
+
return new Naming_1.FixedName(Support_1.defined(assignedName));
|
|
320
297
|
}
|
|
321
|
-
return new Naming_1.DependencyName(
|
|
298
|
+
return new Naming_1.DependencyName(Support_1.nonNull(this._unionMemberNamer), unionMemberNameOrder, lookup => {
|
|
322
299
|
if (assignedName !== undefined)
|
|
323
300
|
return assignedName;
|
|
324
301
|
return this.proposeUnionMemberName(u, unionName, t, lookup);
|
|
@@ -338,10 +315,10 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
338
315
|
}
|
|
339
316
|
let names = new Map();
|
|
340
317
|
for (const t of u.members) {
|
|
341
|
-
const name = this.makeNameForUnionMember(u, unionName,
|
|
318
|
+
const name = this.makeNameForUnionMember(u, unionName, Transformers_1.followTargetType(t));
|
|
342
319
|
names.set(t, ns.add(name));
|
|
343
320
|
}
|
|
344
|
-
|
|
321
|
+
Support_1.defined(this._memberNamesStoreView).set(u, names);
|
|
345
322
|
}
|
|
346
323
|
makeNameForEnumCase(e, _enumName, caseName, assignedName) {
|
|
347
324
|
// FIXME: See the FIXME in `makeNameForProperty`. We do have global
|
|
@@ -349,7 +326,7 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
349
326
|
const alternative = `${e.getCombinedName()}_${caseName}`;
|
|
350
327
|
const order = assignedName === undefined ? enumCaseNameOrder : assignedEnumCaseNameOrder;
|
|
351
328
|
const names = assignedName === undefined ? [caseName, alternative] : [assignedName];
|
|
352
|
-
return new Naming_1.SimpleName(names,
|
|
329
|
+
return new Naming_1.SimpleName(names, Support_1.nonNull(this._enumCaseNamer), order);
|
|
353
330
|
}
|
|
354
331
|
// FIXME: this is very similar to addPropertyNameds and addUnionMemberNames
|
|
355
332
|
addEnumCaseNames(e, enumName) {
|
|
@@ -364,56 +341,56 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
364
341
|
ns = new Naming_1.Namespace(e.getCombinedName(), this.globalNamespace, forbiddenNamespaces, forbiddenNames);
|
|
365
342
|
}
|
|
366
343
|
let names = new Map();
|
|
367
|
-
const accessorNames =
|
|
344
|
+
const accessorNames = AccessorNames_1.enumCaseNames(e, this.targetLanguage.name);
|
|
368
345
|
for (const caseName of e.cases) {
|
|
369
|
-
const [assignedName, isFixed] =
|
|
346
|
+
const [assignedName, isFixed] = AccessorNames_1.getAccessorName(accessorNames, caseName);
|
|
370
347
|
let name;
|
|
371
348
|
if (isFixed) {
|
|
372
|
-
name = new Naming_1.FixedName(
|
|
349
|
+
name = new Naming_1.FixedName(Support_1.defined(assignedName));
|
|
373
350
|
}
|
|
374
351
|
else {
|
|
375
352
|
name = this.makeNameForEnumCase(e, enumName, caseName, assignedName);
|
|
376
353
|
}
|
|
377
354
|
names.set(caseName, ns.add(name));
|
|
378
355
|
}
|
|
379
|
-
|
|
356
|
+
Support_1.defined(this._caseNamesStoreView).set(e, names);
|
|
380
357
|
}
|
|
381
358
|
childrenOfType(t) {
|
|
382
359
|
const names = this.names;
|
|
383
360
|
if (t instanceof Type_1.ClassType) {
|
|
384
|
-
const propertyNameds =
|
|
385
|
-
const filteredMap =
|
|
361
|
+
const propertyNameds = Support_1.defined(this._propertyNamesStoreView).get(t);
|
|
362
|
+
const filteredMap = collection_utils_1.mapFilterMap(t.getProperties(), (p, n) => {
|
|
386
363
|
if (propertyNameds.get(n) === undefined)
|
|
387
364
|
return undefined;
|
|
388
365
|
return p.type;
|
|
389
366
|
});
|
|
390
|
-
const sortedMap =
|
|
367
|
+
const sortedMap = collection_utils_1.mapSortBy(filteredMap, (_, n) => Support_1.defined(names.get(Support_1.defined(propertyNameds.get(n)))));
|
|
391
368
|
return new Set(sortedMap.values());
|
|
392
369
|
}
|
|
393
370
|
return t.getChildren();
|
|
394
371
|
}
|
|
395
372
|
get namedUnions() {
|
|
396
|
-
return
|
|
373
|
+
return Support_1.defined(this._namedUnions);
|
|
397
374
|
}
|
|
398
375
|
get haveNamedUnions() {
|
|
399
376
|
return this.namedUnions.size > 0;
|
|
400
377
|
}
|
|
401
378
|
get haveNamedTypes() {
|
|
402
|
-
return
|
|
379
|
+
return Support_1.defined(this._namedTypes).length > 0;
|
|
403
380
|
}
|
|
404
381
|
get haveUnions() {
|
|
405
|
-
return
|
|
382
|
+
return Support_1.defined(this._haveUnions);
|
|
406
383
|
}
|
|
407
384
|
get haveMaps() {
|
|
408
|
-
return
|
|
385
|
+
return Support_1.defined(this._haveMaps);
|
|
409
386
|
}
|
|
410
387
|
get haveOptionalProperties() {
|
|
411
|
-
return
|
|
388
|
+
return Support_1.defined(this._haveOptionalProperties);
|
|
412
389
|
}
|
|
413
390
|
// FIXME: Inconsistently named, though technically correct. Right now all enums are named,
|
|
414
391
|
// but this should really be called `namedEnums`.
|
|
415
392
|
get enums() {
|
|
416
|
-
return
|
|
393
|
+
return Support_1.defined(this._namedEnums);
|
|
417
394
|
}
|
|
418
395
|
get haveEnums() {
|
|
419
396
|
return this.enums.size > 0;
|
|
@@ -426,10 +403,10 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
426
403
|
if (simpleName !== null) {
|
|
427
404
|
return simpleName;
|
|
428
405
|
}
|
|
429
|
-
const typeNameForUnionMember = (t) =>
|
|
430
|
-
return
|
|
406
|
+
const typeNameForUnionMember = (t) => TypeUtils_1.matchTypeExhaustive(t, _noneType => {
|
|
407
|
+
return Support_1.panic("none type should have been replaced");
|
|
431
408
|
}, _anyType => "anything", _nullType => "null", _boolType => "bool", _integerType => "integer", _doubleType => "double", _stringType => "string", arrayType => typeNameForUnionMember(arrayType.items) + "_array", classType => lookup(this.nameForNamedType(classType)), mapType => typeNameForUnionMember(mapType.values) + "_map", objectType => {
|
|
432
|
-
|
|
409
|
+
Support_1.assert(this.targetLanguage.supportsFullObjectType, "Object type should have been replaced in `replaceObjectType`");
|
|
433
410
|
return lookup(this.nameForNamedType(objectType));
|
|
434
411
|
}, _enumType => "enum", _unionType => "union", transformedType => transformedType.kind.replace("-", "_"));
|
|
435
412
|
return typeNameForUnionMember(fieldType);
|
|
@@ -438,24 +415,24 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
438
415
|
return this.nameStoreView.get(t);
|
|
439
416
|
}
|
|
440
417
|
isForwardDeclaredType(t) {
|
|
441
|
-
return
|
|
418
|
+
return Support_1.defined(this._declarationIR).forwardedTypes.has(t);
|
|
442
419
|
}
|
|
443
420
|
isImplicitCycleBreaker(_t) {
|
|
444
|
-
return
|
|
421
|
+
return Support_1.panic("A renderer that invokes isCycleBreakerType must implement isImplicitCycleBreaker");
|
|
445
422
|
}
|
|
446
423
|
canBreakCycles(_t) {
|
|
447
424
|
return true;
|
|
448
425
|
}
|
|
449
426
|
isCycleBreakerType(t) {
|
|
450
427
|
if (this._cycleBreakerTypes === undefined) {
|
|
451
|
-
this._cycleBreakerTypes =
|
|
428
|
+
this._cycleBreakerTypes = DeclarationIR_1.cycleBreakerTypesForGraph(this.typeGraph, s => this.isImplicitCycleBreaker(s), s => this.canBreakCycles(s));
|
|
452
429
|
}
|
|
453
430
|
return this._cycleBreakerTypes.has(t);
|
|
454
431
|
}
|
|
455
432
|
forEachTopLevel(blankLocations, f, predicate) {
|
|
456
433
|
let topLevels;
|
|
457
434
|
if (predicate !== undefined) {
|
|
458
|
-
topLevels =
|
|
435
|
+
topLevels = collection_utils_1.mapFilter(this.topLevels, predicate);
|
|
459
436
|
}
|
|
460
437
|
else {
|
|
461
438
|
topLevels = this.topLevels;
|
|
@@ -463,7 +440,7 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
463
440
|
return this.forEachWithBlankLines(topLevels, blankLocations, (t, name, pos) => f(t, this.nameStoreView.getForTopLevel(name), pos));
|
|
464
441
|
}
|
|
465
442
|
forEachDeclaration(blankLocations, f) {
|
|
466
|
-
this.forEachWithBlankLines(
|
|
443
|
+
this.forEachWithBlankLines(collection_utils_1.iterableEnumerate(Support_1.defined(this._declarationIR).declarations), blankLocations, (decl, _, pos) => f(decl, pos));
|
|
467
444
|
}
|
|
468
445
|
setAlphabetizeProperties(value) {
|
|
469
446
|
this._alphabetizeProperties = value;
|
|
@@ -473,14 +450,14 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
473
450
|
}
|
|
474
451
|
// Returns the number of properties defined for the specified object type.
|
|
475
452
|
propertyCount(o) {
|
|
476
|
-
const propertyNames =
|
|
453
|
+
const propertyNames = Support_1.defined(this._propertyNamesStoreView).get(o);
|
|
477
454
|
return propertyNames.size;
|
|
478
455
|
}
|
|
479
456
|
sortClassProperties(properties, propertyNames) {
|
|
480
457
|
if (this._alphabetizeProperties) {
|
|
481
|
-
return
|
|
482
|
-
const name =
|
|
483
|
-
return
|
|
458
|
+
return collection_utils_1.mapSortBy(properties, (_p, jsonName) => {
|
|
459
|
+
const name = Support_1.defined(propertyNames.get(jsonName));
|
|
460
|
+
return Support_1.defined(this.names.get(name));
|
|
484
461
|
});
|
|
485
462
|
}
|
|
486
463
|
else {
|
|
@@ -488,43 +465,43 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
488
465
|
}
|
|
489
466
|
}
|
|
490
467
|
forEachClassProperty(o, blankLocations, f) {
|
|
491
|
-
const propertyNames =
|
|
468
|
+
const propertyNames = Support_1.defined(this._propertyNamesStoreView).get(o);
|
|
492
469
|
const sortedProperties = this.sortClassProperties(o.getProperties(), propertyNames);
|
|
493
470
|
this.forEachWithBlankLines(sortedProperties, blankLocations, (p, jsonName, pos) => {
|
|
494
|
-
const name =
|
|
471
|
+
const name = Support_1.defined(propertyNames.get(jsonName));
|
|
495
472
|
f(name, jsonName, p, pos);
|
|
496
473
|
});
|
|
497
474
|
}
|
|
498
475
|
nameForUnionMember(u, t) {
|
|
499
|
-
return
|
|
476
|
+
return Support_1.defined(Support_1.defined(this._memberNamesStoreView).get(u).get(t));
|
|
500
477
|
}
|
|
501
478
|
nameForEnumCase(e, caseName) {
|
|
502
|
-
const caseNames =
|
|
503
|
-
return
|
|
479
|
+
const caseNames = Support_1.defined(this._caseNamesStoreView).get(e);
|
|
480
|
+
return Support_1.defined(caseNames.get(caseName));
|
|
504
481
|
}
|
|
505
482
|
forEachUnionMember(u, members, blankLocations, sortOrder, f) {
|
|
506
483
|
const iterateMembers = members === null ? u.members : members;
|
|
507
484
|
if (sortOrder === null) {
|
|
508
|
-
sortOrder = n =>
|
|
485
|
+
sortOrder = n => Support_1.defined(this.names.get(n));
|
|
509
486
|
}
|
|
510
|
-
const memberNames =
|
|
511
|
-
const sortedMemberNames =
|
|
487
|
+
const memberNames = collection_utils_1.mapFilter(Support_1.defined(this._memberNamesStoreView).get(u), (_, t) => iterateMembers.has(t));
|
|
488
|
+
const sortedMemberNames = collection_utils_1.mapSortBy(memberNames, sortOrder);
|
|
512
489
|
this.forEachWithBlankLines(sortedMemberNames, blankLocations, f);
|
|
513
490
|
}
|
|
514
491
|
forEachEnumCase(e, blankLocations, f) {
|
|
515
|
-
const caseNames =
|
|
516
|
-
const sortedCaseNames =
|
|
492
|
+
const caseNames = Support_1.defined(this._caseNamesStoreView).get(e);
|
|
493
|
+
const sortedCaseNames = collection_utils_1.mapSortBy(caseNames, n => Support_1.defined(this.names.get(n)));
|
|
517
494
|
this.forEachWithBlankLines(sortedCaseNames, blankLocations, f);
|
|
518
495
|
}
|
|
519
496
|
forEachTransformation(blankLocations, f) {
|
|
520
|
-
this.forEachWithBlankLines(
|
|
497
|
+
this.forEachWithBlankLines(Support_1.defined(this._namesForTransformations), blankLocations, f);
|
|
521
498
|
}
|
|
522
499
|
forEachSpecificNamedType(blankLocations, types, f) {
|
|
523
500
|
this.forEachWithBlankLines(types, blankLocations, (t, _, pos) => f(t, this.nameForNamedType(t), pos));
|
|
524
501
|
}
|
|
525
502
|
forEachObject(blankLocations, f) {
|
|
526
503
|
// FIXME: This is ugly.
|
|
527
|
-
this.forEachSpecificNamedType(blankLocations,
|
|
504
|
+
this.forEachSpecificNamedType(blankLocations, Support_1.defined(this._namedObjects).entries(), f);
|
|
528
505
|
}
|
|
529
506
|
forEachEnum(blankLocations, f) {
|
|
530
507
|
this.forEachSpecificNamedType(blankLocations, this.enums.entries(), f);
|
|
@@ -543,7 +520,7 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
543
520
|
this.forEachWithBlankLines(firstUnionByValue, blankLocations, f);
|
|
544
521
|
}
|
|
545
522
|
forEachNamedType(blankLocations, objectFunc, enumFunc, unionFunc) {
|
|
546
|
-
this.forEachWithBlankLines(
|
|
523
|
+
this.forEachWithBlankLines(Support_1.defined(this._namedTypes).entries(), blankLocations, (t, _, pos) => {
|
|
547
524
|
const name = this.nameForNamedType(t);
|
|
548
525
|
if (t instanceof Type_1.ObjectType) {
|
|
549
526
|
// FIXME: This is ugly. We can't runtime check that the function
|
|
@@ -557,7 +534,7 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
557
534
|
unionFunc(t, name, pos);
|
|
558
535
|
}
|
|
559
536
|
else {
|
|
560
|
-
return
|
|
537
|
+
return Support_1.panic("Named type that's neither a class nor union");
|
|
561
538
|
}
|
|
562
539
|
});
|
|
563
540
|
}
|
|
@@ -565,7 +542,7 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
565
542
|
// code. If you need to modify a Name, for example to change its casing,
|
|
566
543
|
// use `modifySource`.
|
|
567
544
|
sourcelikeToString(src) {
|
|
568
|
-
return
|
|
545
|
+
return Source_1.serializeRenderResult(Source_1.sourcelikeToSource(src), this.names, "").lines.join("\n");
|
|
569
546
|
}
|
|
570
547
|
get commentLineStart() {
|
|
571
548
|
return "// ";
|
|
@@ -584,7 +561,7 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
584
561
|
for (const line of lines) {
|
|
585
562
|
let start = first ? firstLineStart : lineStart;
|
|
586
563
|
if (this.sourcelikeToString(line) === "") {
|
|
587
|
-
start =
|
|
564
|
+
start = Strings_1.trimEnd(start);
|
|
588
565
|
}
|
|
589
566
|
this.emitLine(start, line);
|
|
590
567
|
first = false;
|
|
@@ -621,19 +598,19 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
621
598
|
emitTable();
|
|
622
599
|
}
|
|
623
600
|
processGraph() {
|
|
624
|
-
this._declarationIR =
|
|
601
|
+
this._declarationIR = DeclarationIR_1.declarationsForGraph(this.typeGraph, this.needsTypeDeclarationBeforeUse ? t => this.canBeForwardDeclared(t) : undefined, t => this.childrenOfType(t), t => {
|
|
625
602
|
if (t instanceof Type_1.UnionType) {
|
|
626
603
|
return this.unionNeedsName(t);
|
|
627
604
|
}
|
|
628
|
-
return
|
|
605
|
+
return TypeUtils_1.isNamedType(t);
|
|
629
606
|
});
|
|
630
607
|
const types = this.typeGraph.allTypesUnordered();
|
|
631
|
-
this._haveUnions =
|
|
632
|
-
this._haveMaps =
|
|
633
|
-
const classTypes =
|
|
634
|
-
this._haveOptionalProperties =
|
|
608
|
+
this._haveUnions = collection_utils_1.iterableSome(types, t => t instanceof Type_1.UnionType);
|
|
609
|
+
this._haveMaps = collection_utils_1.iterableSome(types, t => t instanceof Type_1.MapType);
|
|
610
|
+
const classTypes = collection_utils_1.setFilter(types, t => t instanceof Type_1.ClassType);
|
|
611
|
+
this._haveOptionalProperties = collection_utils_1.iterableSome(classTypes, c => collection_utils_1.mapSome(c.getProperties(), p => p.isOptional));
|
|
635
612
|
this._namedTypes = this._declarationIR.declarations.filter(d => d.kind === "define").map(d => d.type);
|
|
636
|
-
const { objects, enums, unions } =
|
|
613
|
+
const { objects, enums, unions } = TypeUtils_1.separateNamedTypes(this._namedTypes);
|
|
637
614
|
this._namedObjects = new Set(objects);
|
|
638
615
|
this._namedEnums = new Set(enums);
|
|
639
616
|
this._namedUnions = new Set(unions);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TypeGraph } from "./TypeGraph";
|
|
2
2
|
import { Type } from "./Type";
|
|
3
|
-
export type DeclarationKind = "forward" | "define";
|
|
3
|
+
export declare type DeclarationKind = "forward" | "define";
|
|
4
4
|
export interface Declaration {
|
|
5
5
|
readonly kind: DeclarationKind;
|
|
6
6
|
readonly type: Type;
|