quicktype-core 7.0.34 → 7.0.36
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/Annotation.js +0 -1
- package/dist/ConvenienceRenderer.d.ts +17 -17
- package/dist/ConvenienceRenderer.js +80 -81
- package/dist/CycleBreaker.js +5 -6
- package/dist/DateTime.js +0 -1
- package/dist/DeclarationIR.d.ts +1 -1
- package/dist/DeclarationIR.js +10 -11
- package/dist/EncodedMarkovChain.js +0 -1
- package/dist/GatherNames.js +19 -20
- package/dist/Graph.d.ts +2 -2
- package/dist/Graph.js +19 -20
- package/dist/GraphRewriting.d.ts +2 -2
- package/dist/GraphRewriting.js +47 -48
- package/dist/MakeTransformations.js +22 -23
- package/dist/MarkovChain.d.ts +3 -3
- package/dist/MarkovChain.js +8 -9
- package/dist/Messages.d.ts +3 -3
- package/dist/Messages.js +3 -5
- package/dist/Naming.d.ts +11 -11
- package/dist/Naming.js +29 -30
- package/dist/Renderer.d.ts +6 -6
- package/dist/Renderer.js +11 -12
- package/dist/RendererOptions.d.ts +5 -5
- package/dist/RendererOptions.js +3 -4
- package/dist/Run.d.ts +5 -5
- package/dist/Run.js +23 -25
- package/dist/Source.d.ts +3 -3
- package/dist/Source.js +18 -19
- package/dist/TargetLanguage.d.ts +10 -10
- package/dist/TargetLanguage.js +2 -3
- package/dist/Transformers.d.ts +25 -25
- package/dist/Transformers.js +66 -67
- package/dist/Type.d.ts +42 -40
- package/dist/Type.js +71 -79
- package/dist/TypeBuilder.d.ts +2 -2
- package/dist/TypeBuilder.js +42 -43
- package/dist/TypeGraph.d.ts +4 -4
- package/dist/TypeGraph.js +33 -34
- package/dist/TypeUtils.d.ts +2 -2
- package/dist/TypeUtils.js +22 -23
- package/dist/UnifyClasses.js +12 -13
- package/dist/UnionBuilder.d.ts +3 -3
- package/dist/UnionBuilder.js +24 -25
- package/dist/attributes/AccessorNames.d.ts +2 -2
- package/dist/attributes/AccessorNames.js +17 -18
- package/dist/attributes/Constraints.d.ts +3 -3
- package/dist/attributes/Constraints.js +4 -5
- package/dist/attributes/Description.js +5 -6
- package/dist/attributes/EnumValues.js +3 -4
- package/dist/attributes/StringTypes.d.ts +1 -1
- package/dist/attributes/StringTypes.js +21 -22
- package/dist/attributes/TypeAttributes.d.ts +3 -3
- package/dist/attributes/TypeAttributes.js +10 -11
- package/dist/attributes/TypeNames.d.ts +9 -9
- package/dist/attributes/TypeNames.js +20 -21
- package/dist/attributes/URIAttributes.d.ts +1 -1
- package/dist/attributes/URIAttributes.js +5 -6
- package/dist/index.js +125 -128
- package/dist/input/CompressedJSON.d.ts +7 -7
- package/dist/input/CompressedJSON.js +27 -29
- package/dist/input/FetchingJSONSchemaStore.js +2 -4
- package/dist/input/Inference.d.ts +2 -2
- package/dist/input/Inference.js +17 -18
- package/dist/input/Inputs.d.ts +2 -2
- package/dist/input/Inputs.js +14 -16
- package/dist/input/JSONSchemaInput.d.ts +11 -11
- package/dist/input/JSONSchemaInput.js +96 -98
- package/dist/input/JSONSchemaStore.d.ts +1 -1
- package/dist/input/JSONSchemaStore.js +2 -4
- package/dist/input/PostmanCollection.js +1 -2
- package/dist/input/io/NodeIO.js +8 -9
- package/dist/input/io/get-stream/index.js +1 -2
- package/dist/language/All.js +2 -3
- package/dist/language/CPlusPlus.d.ts +12 -9
- package/dist/language/CPlusPlus.js +153 -122
- package/dist/language/CSharp.d.ts +7 -7
- package/dist/language/CSharp.js +70 -71
- package/dist/language/Crystal.d.ts +2 -2
- package/dist/language/Crystal.js +17 -18
- package/dist/language/Dart.d.ts +4 -4
- package/dist/language/Dart.js +28 -29
- package/dist/language/Elm.d.ts +6 -6
- package/dist/language/Elm.js +43 -44
- package/dist/language/Golang.d.ts +4 -4
- package/dist/language/Golang.js +19 -20
- package/dist/language/Haskell.d.ts +5 -5
- package/dist/language/Haskell.js +23 -24
- package/dist/language/JSONSchema.d.ts +3 -3
- package/dist/language/JSONSchema.js +16 -17
- package/dist/language/Java.d.ts +2 -2
- package/dist/language/Java.js +31 -32
- package/dist/language/JavaScript.d.ts +7 -7
- package/dist/language/JavaScript.js +17 -18
- package/dist/language/JavaScriptPropTypes.js +13 -14
- package/dist/language/JavaScriptUnicodeMaps.js +11 -12
- package/dist/language/Kotlin.d.ts +2 -2
- package/dist/language/Kotlin.js +37 -38
- package/dist/language/Objective-C.d.ts +3 -3
- package/dist/language/Objective-C.js +41 -42
- package/dist/language/Php.d.ts +2 -2
- package/dist/language/Php.js +36 -37
- package/dist/language/Pike.d.ts +1 -1
- package/dist/language/Pike.js +17 -18
- package/dist/language/Python.d.ts +8 -8
- package/dist/language/Python.js +54 -55
- package/dist/language/Rust.d.ts +2 -2
- package/dist/language/Rust.js +19 -20
- package/dist/language/Swift.d.ts +7 -7
- package/dist/language/Swift.js +26 -27
- package/dist/language/TypeScriptFlow.d.ts +7 -7
- package/dist/language/TypeScriptFlow.js +26 -27
- package/dist/language/ruby/index.d.ts +4 -4
- package/dist/language/ruby/index.js +23 -24
- package/dist/language/ruby/keywords.js +0 -1
- package/dist/rewrites/CombineClasses.js +8 -9
- package/dist/rewrites/ExpandStrings.d.ts +1 -1
- package/dist/rewrites/ExpandStrings.js +17 -18
- package/dist/rewrites/FlattenStrings.js +6 -7
- package/dist/rewrites/FlattenUnions.js +8 -9
- package/dist/rewrites/InferMaps.js +10 -11
- package/dist/rewrites/ReplaceObjectType.js +7 -8
- package/dist/rewrites/ResolveIntersections.js +47 -48
- package/dist/support/Acronyms.js +1 -3
- package/dist/support/Chance.js +0 -1
- package/dist/support/Converters.js +0 -1
- package/dist/support/Strings.d.ts +4 -4
- package/dist/support/Strings.js +16 -17
- package/dist/support/Support.d.ts +1 -1
- package/dist/support/Support.js +4 -5
- package/package.json +7 -7
package/dist/Annotation.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
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,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");
|
|
@@ -85,7 +84,7 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
85
84
|
return undefined;
|
|
86
85
|
}
|
|
87
86
|
namedTypeToNameForTopLevel(type) {
|
|
88
|
-
if (
|
|
87
|
+
if (TypeUtils_1.isNamedType(type)) {
|
|
89
88
|
return type;
|
|
90
89
|
}
|
|
91
90
|
return undefined;
|
|
@@ -100,16 +99,16 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
100
99
|
return false;
|
|
101
100
|
}
|
|
102
101
|
canBeForwardDeclared(_t) {
|
|
103
|
-
return
|
|
102
|
+
return Support_1.panic("If needsTypeDeclarationBeforeUse returns true, canBeForwardDeclared must be implemented");
|
|
104
103
|
}
|
|
105
104
|
unionNeedsName(u) {
|
|
106
|
-
return
|
|
105
|
+
return TypeUtils_1.nullableFromUnion(u) === null;
|
|
107
106
|
}
|
|
108
107
|
get globalNamespace() {
|
|
109
|
-
return
|
|
108
|
+
return Support_1.defined(this._globalNamespace);
|
|
110
109
|
}
|
|
111
110
|
get nameStoreView() {
|
|
112
|
-
return
|
|
111
|
+
return Support_1.defined(this._nameStoreView);
|
|
113
112
|
}
|
|
114
113
|
descriptionForType(t) {
|
|
115
114
|
let description = this.typeGraph.attributeStore.tryGet(Description_1.descriptionTypeAttributeKind, t);
|
|
@@ -130,11 +129,11 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
130
129
|
this._namedTypeNamer = this.makeNamedTypeNamer();
|
|
131
130
|
this._unionMemberNamer = this.makeUnionMemberNamer();
|
|
132
131
|
this._enumCaseNamer = this.makeEnumCaseNamer();
|
|
133
|
-
this._globalForbiddenNamespace =
|
|
132
|
+
this._globalForbiddenNamespace = Naming_1.keywordNamespace("forbidden", this.forbiddenNamesForGlobalNamespace());
|
|
134
133
|
this._otherForbiddenNamespaces = new Map();
|
|
135
134
|
this._globalNamespace = new Naming_1.Namespace("global", undefined, [this._globalForbiddenNamespace], []);
|
|
136
135
|
const { objects, enums, unions } = this.typeGraph.allNamedTypesSeparated();
|
|
137
|
-
const namedUnions =
|
|
136
|
+
const namedUnions = collection_utils_1.setFilter(unions, u => this.unionNeedsName(u));
|
|
138
137
|
for (const [name, t] of this.topLevels) {
|
|
139
138
|
this.nameStoreView.setForTopLevel(name, this.addNameForTopLevel(t, name));
|
|
140
139
|
}
|
|
@@ -153,7 +152,7 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
153
152
|
for (const t of this.typeGraph.allTypesUnordered()) {
|
|
154
153
|
this.addNameForTransformation(t);
|
|
155
154
|
}
|
|
156
|
-
return
|
|
155
|
+
return collection_utils_1.setUnion([this._globalForbiddenNamespace, this._globalNamespace], this._otherForbiddenNamespaces.values());
|
|
157
156
|
}
|
|
158
157
|
addDependenciesForNamedType(type, named) {
|
|
159
158
|
const dependencyNames = this.makeNamedTypeDependencyNames(type, named);
|
|
@@ -162,7 +161,7 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
162
161
|
}
|
|
163
162
|
}
|
|
164
163
|
makeNameForTopLevel(_t, givenName, _maybeNamedType) {
|
|
165
|
-
return new Naming_1.SimpleName([givenName],
|
|
164
|
+
return new Naming_1.SimpleName([givenName], Support_1.defined(this._namedTypeNamer), exports.topLevelNameOrder);
|
|
166
165
|
}
|
|
167
166
|
addNameForTopLevel(type, givenName) {
|
|
168
167
|
const maybeNamedType = this.namedTypeToNameForTopLevel(type);
|
|
@@ -184,7 +183,7 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
184
183
|
return new Naming_1.SimpleName(names.proposedNames, namer, order);
|
|
185
184
|
}
|
|
186
185
|
makeNameForNamedType(t) {
|
|
187
|
-
return this.makeNameForType(t,
|
|
186
|
+
return this.makeNameForType(t, Support_1.defined(this._namedTypeNamer), givenNameOrder, exports.inferredNameOrder);
|
|
188
187
|
}
|
|
189
188
|
addNameForNamedType(type) {
|
|
190
189
|
const existing = this.nameStoreView.tryGet(type);
|
|
@@ -196,28 +195,28 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
196
195
|
return name;
|
|
197
196
|
}
|
|
198
197
|
get typesWithNamedTransformations() {
|
|
199
|
-
return
|
|
198
|
+
return Support_1.defined(this._namesForTransformations);
|
|
200
199
|
}
|
|
201
200
|
nameForTransformation(t) {
|
|
202
|
-
const xf =
|
|
201
|
+
const xf = Transformers_1.transformationForType(t);
|
|
203
202
|
if (xf === undefined)
|
|
204
203
|
return undefined;
|
|
205
|
-
const name =
|
|
204
|
+
const name = Support_1.defined(this._namesForTransformations).get(t);
|
|
206
205
|
if (name === undefined) {
|
|
207
|
-
return
|
|
206
|
+
return Support_1.panic("No name for transformation");
|
|
208
207
|
}
|
|
209
208
|
return name;
|
|
210
209
|
}
|
|
211
210
|
addNameForTransformation(t) {
|
|
212
|
-
const xf =
|
|
211
|
+
const xf = Transformers_1.transformationForType(t);
|
|
213
212
|
if (xf === undefined)
|
|
214
213
|
return;
|
|
215
|
-
|
|
214
|
+
Support_1.assert(Support_1.defined(this._namesForTransformations).get(t) === undefined, "Tried to give two names to the same transformation");
|
|
216
215
|
const name = this.makeNameForTransformation(xf, this.nameStoreView.tryGet(xf.targetType));
|
|
217
216
|
if (name === undefined)
|
|
218
217
|
return;
|
|
219
218
|
this.globalNamespace.add(name);
|
|
220
|
-
|
|
219
|
+
Support_1.defined(this._namesForTransformations).set(t, name);
|
|
221
220
|
}
|
|
222
221
|
processForbiddenWordsInfo(info, namespaceName) {
|
|
223
222
|
const forbiddenNames = [];
|
|
@@ -230,14 +229,14 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
230
229
|
forbiddenNames.push(nameOrString);
|
|
231
230
|
}
|
|
232
231
|
}
|
|
233
|
-
let namespace =
|
|
232
|
+
let namespace = Support_1.defined(this._otherForbiddenNamespaces).get(namespaceName);
|
|
234
233
|
if (forbiddenStrings.length > 0 && namespace === undefined) {
|
|
235
|
-
namespace =
|
|
236
|
-
this._otherForbiddenNamespaces =
|
|
234
|
+
namespace = Naming_1.keywordNamespace(namespaceName, forbiddenStrings);
|
|
235
|
+
this._otherForbiddenNamespaces = Support_1.defined(this._otherForbiddenNamespaces).set(namespaceName, namespace);
|
|
237
236
|
}
|
|
238
237
|
let forbiddenNamespaces = new Set();
|
|
239
238
|
if (info.includeGlobalForbidden) {
|
|
240
|
-
forbiddenNamespaces = forbiddenNamespaces.add(
|
|
239
|
+
forbiddenNamespaces = forbiddenNamespaces.add(Support_1.defined(this._globalForbiddenNamespace));
|
|
241
240
|
}
|
|
242
241
|
if (namespace !== undefined) {
|
|
243
242
|
forbiddenNamespaces = forbiddenNamespaces.add(namespace);
|
|
@@ -268,12 +267,12 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
268
267
|
addPropertyNames(o, className) {
|
|
269
268
|
const { forbiddenNames, forbiddenNamespaces } = this.processForbiddenWordsInfo(this.forbiddenForObjectProperties(o, className), "forbidden-for-properties");
|
|
270
269
|
let ns;
|
|
271
|
-
const accessorNames =
|
|
272
|
-
const names =
|
|
273
|
-
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);
|
|
274
273
|
let name;
|
|
275
274
|
if (isFixed) {
|
|
276
|
-
name = new Naming_1.FixedName(
|
|
275
|
+
name = new Naming_1.FixedName(Support_1.defined(assignedName));
|
|
277
276
|
}
|
|
278
277
|
else {
|
|
279
278
|
name = this.makeNameForProperty(o, className, p, jsonName, assignedName);
|
|
@@ -289,14 +288,14 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
289
288
|
}
|
|
290
289
|
return name;
|
|
291
290
|
});
|
|
292
|
-
|
|
291
|
+
Support_1.defined(this._propertyNamesStoreView).set(o, names);
|
|
293
292
|
}
|
|
294
293
|
makeNameForUnionMember(u, unionName, t) {
|
|
295
|
-
const [assignedName, isFixed] =
|
|
294
|
+
const [assignedName, isFixed] = AccessorNames_1.unionMemberName(u, t, this.targetLanguage.name);
|
|
296
295
|
if (isFixed) {
|
|
297
|
-
return new Naming_1.FixedName(
|
|
296
|
+
return new Naming_1.FixedName(Support_1.defined(assignedName));
|
|
298
297
|
}
|
|
299
|
-
return new Naming_1.DependencyName(
|
|
298
|
+
return new Naming_1.DependencyName(Support_1.nonNull(this._unionMemberNamer), unionMemberNameOrder, lookup => {
|
|
300
299
|
if (assignedName !== undefined)
|
|
301
300
|
return assignedName;
|
|
302
301
|
return this.proposeUnionMemberName(u, unionName, t, lookup);
|
|
@@ -316,10 +315,10 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
316
315
|
}
|
|
317
316
|
let names = new Map();
|
|
318
317
|
for (const t of u.members) {
|
|
319
|
-
const name = this.makeNameForUnionMember(u, unionName,
|
|
318
|
+
const name = this.makeNameForUnionMember(u, unionName, Transformers_1.followTargetType(t));
|
|
320
319
|
names.set(t, ns.add(name));
|
|
321
320
|
}
|
|
322
|
-
|
|
321
|
+
Support_1.defined(this._memberNamesStoreView).set(u, names);
|
|
323
322
|
}
|
|
324
323
|
makeNameForEnumCase(e, _enumName, caseName, assignedName) {
|
|
325
324
|
// FIXME: See the FIXME in `makeNameForProperty`. We do have global
|
|
@@ -327,7 +326,7 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
327
326
|
const alternative = `${e.getCombinedName()}_${caseName}`;
|
|
328
327
|
const order = assignedName === undefined ? enumCaseNameOrder : assignedEnumCaseNameOrder;
|
|
329
328
|
const names = assignedName === undefined ? [caseName, alternative] : [assignedName];
|
|
330
|
-
return new Naming_1.SimpleName(names,
|
|
329
|
+
return new Naming_1.SimpleName(names, Support_1.nonNull(this._enumCaseNamer), order);
|
|
331
330
|
}
|
|
332
331
|
// FIXME: this is very similar to addPropertyNameds and addUnionMemberNames
|
|
333
332
|
addEnumCaseNames(e, enumName) {
|
|
@@ -342,56 +341,56 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
342
341
|
ns = new Naming_1.Namespace(e.getCombinedName(), this.globalNamespace, forbiddenNamespaces, forbiddenNames);
|
|
343
342
|
}
|
|
344
343
|
let names = new Map();
|
|
345
|
-
const accessorNames =
|
|
344
|
+
const accessorNames = AccessorNames_1.enumCaseNames(e, this.targetLanguage.name);
|
|
346
345
|
for (const caseName of e.cases) {
|
|
347
|
-
const [assignedName, isFixed] =
|
|
346
|
+
const [assignedName, isFixed] = AccessorNames_1.getAccessorName(accessorNames, caseName);
|
|
348
347
|
let name;
|
|
349
348
|
if (isFixed) {
|
|
350
|
-
name = new Naming_1.FixedName(
|
|
349
|
+
name = new Naming_1.FixedName(Support_1.defined(assignedName));
|
|
351
350
|
}
|
|
352
351
|
else {
|
|
353
352
|
name = this.makeNameForEnumCase(e, enumName, caseName, assignedName);
|
|
354
353
|
}
|
|
355
354
|
names.set(caseName, ns.add(name));
|
|
356
355
|
}
|
|
357
|
-
|
|
356
|
+
Support_1.defined(this._caseNamesStoreView).set(e, names);
|
|
358
357
|
}
|
|
359
358
|
childrenOfType(t) {
|
|
360
359
|
const names = this.names;
|
|
361
360
|
if (t instanceof Type_1.ClassType) {
|
|
362
|
-
const propertyNameds =
|
|
363
|
-
const filteredMap =
|
|
361
|
+
const propertyNameds = Support_1.defined(this._propertyNamesStoreView).get(t);
|
|
362
|
+
const filteredMap = collection_utils_1.mapFilterMap(t.getProperties(), (p, n) => {
|
|
364
363
|
if (propertyNameds.get(n) === undefined)
|
|
365
364
|
return undefined;
|
|
366
365
|
return p.type;
|
|
367
366
|
});
|
|
368
|
-
const sortedMap =
|
|
367
|
+
const sortedMap = collection_utils_1.mapSortBy(filteredMap, (_, n) => Support_1.defined(names.get(Support_1.defined(propertyNameds.get(n)))));
|
|
369
368
|
return new Set(sortedMap.values());
|
|
370
369
|
}
|
|
371
370
|
return t.getChildren();
|
|
372
371
|
}
|
|
373
372
|
get namedUnions() {
|
|
374
|
-
return
|
|
373
|
+
return Support_1.defined(this._namedUnions);
|
|
375
374
|
}
|
|
376
375
|
get haveNamedUnions() {
|
|
377
376
|
return this.namedUnions.size > 0;
|
|
378
377
|
}
|
|
379
378
|
get haveNamedTypes() {
|
|
380
|
-
return
|
|
379
|
+
return Support_1.defined(this._namedTypes).length > 0;
|
|
381
380
|
}
|
|
382
381
|
get haveUnions() {
|
|
383
|
-
return
|
|
382
|
+
return Support_1.defined(this._haveUnions);
|
|
384
383
|
}
|
|
385
384
|
get haveMaps() {
|
|
386
|
-
return
|
|
385
|
+
return Support_1.defined(this._haveMaps);
|
|
387
386
|
}
|
|
388
387
|
get haveOptionalProperties() {
|
|
389
|
-
return
|
|
388
|
+
return Support_1.defined(this._haveOptionalProperties);
|
|
390
389
|
}
|
|
391
390
|
// FIXME: Inconsistently named, though technically correct. Right now all enums are named,
|
|
392
391
|
// but this should really be called `namedEnums`.
|
|
393
392
|
get enums() {
|
|
394
|
-
return
|
|
393
|
+
return Support_1.defined(this._namedEnums);
|
|
395
394
|
}
|
|
396
395
|
get haveEnums() {
|
|
397
396
|
return this.enums.size > 0;
|
|
@@ -404,10 +403,10 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
404
403
|
if (simpleName !== null) {
|
|
405
404
|
return simpleName;
|
|
406
405
|
}
|
|
407
|
-
const typeNameForUnionMember = (t) =>
|
|
408
|
-
return
|
|
406
|
+
const typeNameForUnionMember = (t) => TypeUtils_1.matchTypeExhaustive(t, _noneType => {
|
|
407
|
+
return Support_1.panic("none type should have been replaced");
|
|
409
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 => {
|
|
410
|
-
|
|
409
|
+
Support_1.assert(this.targetLanguage.supportsFullObjectType, "Object type should have been replaced in `replaceObjectType`");
|
|
411
410
|
return lookup(this.nameForNamedType(objectType));
|
|
412
411
|
}, _enumType => "enum", _unionType => "union", transformedType => transformedType.kind.replace("-", "_"));
|
|
413
412
|
return typeNameForUnionMember(fieldType);
|
|
@@ -416,24 +415,24 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
416
415
|
return this.nameStoreView.get(t);
|
|
417
416
|
}
|
|
418
417
|
isForwardDeclaredType(t) {
|
|
419
|
-
return
|
|
418
|
+
return Support_1.defined(this._declarationIR).forwardedTypes.has(t);
|
|
420
419
|
}
|
|
421
420
|
isImplicitCycleBreaker(_t) {
|
|
422
|
-
return
|
|
421
|
+
return Support_1.panic("A renderer that invokes isCycleBreakerType must implement isImplicitCycleBreaker");
|
|
423
422
|
}
|
|
424
423
|
canBreakCycles(_t) {
|
|
425
424
|
return true;
|
|
426
425
|
}
|
|
427
426
|
isCycleBreakerType(t) {
|
|
428
427
|
if (this._cycleBreakerTypes === undefined) {
|
|
429
|
-
this._cycleBreakerTypes =
|
|
428
|
+
this._cycleBreakerTypes = DeclarationIR_1.cycleBreakerTypesForGraph(this.typeGraph, s => this.isImplicitCycleBreaker(s), s => this.canBreakCycles(s));
|
|
430
429
|
}
|
|
431
430
|
return this._cycleBreakerTypes.has(t);
|
|
432
431
|
}
|
|
433
432
|
forEachTopLevel(blankLocations, f, predicate) {
|
|
434
433
|
let topLevels;
|
|
435
434
|
if (predicate !== undefined) {
|
|
436
|
-
topLevels =
|
|
435
|
+
topLevels = collection_utils_1.mapFilter(this.topLevels, predicate);
|
|
437
436
|
}
|
|
438
437
|
else {
|
|
439
438
|
topLevels = this.topLevels;
|
|
@@ -441,7 +440,7 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
441
440
|
return this.forEachWithBlankLines(topLevels, blankLocations, (t, name, pos) => f(t, this.nameStoreView.getForTopLevel(name), pos));
|
|
442
441
|
}
|
|
443
442
|
forEachDeclaration(blankLocations, f) {
|
|
444
|
-
this.forEachWithBlankLines(
|
|
443
|
+
this.forEachWithBlankLines(collection_utils_1.iterableEnumerate(Support_1.defined(this._declarationIR).declarations), blankLocations, (decl, _, pos) => f(decl, pos));
|
|
445
444
|
}
|
|
446
445
|
setAlphabetizeProperties(value) {
|
|
447
446
|
this._alphabetizeProperties = value;
|
|
@@ -451,14 +450,14 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
451
450
|
}
|
|
452
451
|
// Returns the number of properties defined for the specified object type.
|
|
453
452
|
propertyCount(o) {
|
|
454
|
-
const propertyNames =
|
|
453
|
+
const propertyNames = Support_1.defined(this._propertyNamesStoreView).get(o);
|
|
455
454
|
return propertyNames.size;
|
|
456
455
|
}
|
|
457
456
|
sortClassProperties(properties, propertyNames) {
|
|
458
457
|
if (this._alphabetizeProperties) {
|
|
459
|
-
return
|
|
460
|
-
const name =
|
|
461
|
-
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));
|
|
462
461
|
});
|
|
463
462
|
}
|
|
464
463
|
else {
|
|
@@ -466,43 +465,43 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
466
465
|
}
|
|
467
466
|
}
|
|
468
467
|
forEachClassProperty(o, blankLocations, f) {
|
|
469
|
-
const propertyNames =
|
|
468
|
+
const propertyNames = Support_1.defined(this._propertyNamesStoreView).get(o);
|
|
470
469
|
const sortedProperties = this.sortClassProperties(o.getProperties(), propertyNames);
|
|
471
470
|
this.forEachWithBlankLines(sortedProperties, blankLocations, (p, jsonName, pos) => {
|
|
472
|
-
const name =
|
|
471
|
+
const name = Support_1.defined(propertyNames.get(jsonName));
|
|
473
472
|
f(name, jsonName, p, pos);
|
|
474
473
|
});
|
|
475
474
|
}
|
|
476
475
|
nameForUnionMember(u, t) {
|
|
477
|
-
return
|
|
476
|
+
return Support_1.defined(Support_1.defined(this._memberNamesStoreView).get(u).get(t));
|
|
478
477
|
}
|
|
479
478
|
nameForEnumCase(e, caseName) {
|
|
480
|
-
const caseNames =
|
|
481
|
-
return
|
|
479
|
+
const caseNames = Support_1.defined(this._caseNamesStoreView).get(e);
|
|
480
|
+
return Support_1.defined(caseNames.get(caseName));
|
|
482
481
|
}
|
|
483
482
|
forEachUnionMember(u, members, blankLocations, sortOrder, f) {
|
|
484
483
|
const iterateMembers = members === null ? u.members : members;
|
|
485
484
|
if (sortOrder === null) {
|
|
486
|
-
sortOrder = n =>
|
|
485
|
+
sortOrder = n => Support_1.defined(this.names.get(n));
|
|
487
486
|
}
|
|
488
|
-
const memberNames =
|
|
489
|
-
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);
|
|
490
489
|
this.forEachWithBlankLines(sortedMemberNames, blankLocations, f);
|
|
491
490
|
}
|
|
492
491
|
forEachEnumCase(e, blankLocations, f) {
|
|
493
|
-
const caseNames =
|
|
494
|
-
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)));
|
|
495
494
|
this.forEachWithBlankLines(sortedCaseNames, blankLocations, f);
|
|
496
495
|
}
|
|
497
496
|
forEachTransformation(blankLocations, f) {
|
|
498
|
-
this.forEachWithBlankLines(
|
|
497
|
+
this.forEachWithBlankLines(Support_1.defined(this._namesForTransformations), blankLocations, f);
|
|
499
498
|
}
|
|
500
499
|
forEachSpecificNamedType(blankLocations, types, f) {
|
|
501
500
|
this.forEachWithBlankLines(types, blankLocations, (t, _, pos) => f(t, this.nameForNamedType(t), pos));
|
|
502
501
|
}
|
|
503
502
|
forEachObject(blankLocations, f) {
|
|
504
503
|
// FIXME: This is ugly.
|
|
505
|
-
this.forEachSpecificNamedType(blankLocations,
|
|
504
|
+
this.forEachSpecificNamedType(blankLocations, Support_1.defined(this._namedObjects).entries(), f);
|
|
506
505
|
}
|
|
507
506
|
forEachEnum(blankLocations, f) {
|
|
508
507
|
this.forEachSpecificNamedType(blankLocations, this.enums.entries(), f);
|
|
@@ -521,7 +520,7 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
521
520
|
this.forEachWithBlankLines(firstUnionByValue, blankLocations, f);
|
|
522
521
|
}
|
|
523
522
|
forEachNamedType(blankLocations, objectFunc, enumFunc, unionFunc) {
|
|
524
|
-
this.forEachWithBlankLines(
|
|
523
|
+
this.forEachWithBlankLines(Support_1.defined(this._namedTypes).entries(), blankLocations, (t, _, pos) => {
|
|
525
524
|
const name = this.nameForNamedType(t);
|
|
526
525
|
if (t instanceof Type_1.ObjectType) {
|
|
527
526
|
// FIXME: This is ugly. We can't runtime check that the function
|
|
@@ -535,7 +534,7 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
535
534
|
unionFunc(t, name, pos);
|
|
536
535
|
}
|
|
537
536
|
else {
|
|
538
|
-
return
|
|
537
|
+
return Support_1.panic("Named type that's neither a class nor union");
|
|
539
538
|
}
|
|
540
539
|
});
|
|
541
540
|
}
|
|
@@ -543,7 +542,7 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
543
542
|
// code. If you need to modify a Name, for example to change its casing,
|
|
544
543
|
// use `modifySource`.
|
|
545
544
|
sourcelikeToString(src) {
|
|
546
|
-
return
|
|
545
|
+
return Source_1.serializeRenderResult(Source_1.sourcelikeToSource(src), this.names, "").lines.join("\n");
|
|
547
546
|
}
|
|
548
547
|
get commentLineStart() {
|
|
549
548
|
return "// ";
|
|
@@ -562,7 +561,7 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
562
561
|
for (const line of lines) {
|
|
563
562
|
let start = first ? firstLineStart : lineStart;
|
|
564
563
|
if (this.sourcelikeToString(line) === "") {
|
|
565
|
-
start =
|
|
564
|
+
start = Strings_1.trimEnd(start);
|
|
566
565
|
}
|
|
567
566
|
this.emitLine(start, line);
|
|
568
567
|
first = false;
|
|
@@ -599,19 +598,19 @@ class ConvenienceRenderer extends Renderer_1.Renderer {
|
|
|
599
598
|
emitTable();
|
|
600
599
|
}
|
|
601
600
|
processGraph() {
|
|
602
|
-
this._declarationIR =
|
|
601
|
+
this._declarationIR = DeclarationIR_1.declarationsForGraph(this.typeGraph, this.needsTypeDeclarationBeforeUse ? t => this.canBeForwardDeclared(t) : undefined, t => this.childrenOfType(t), t => {
|
|
603
602
|
if (t instanceof Type_1.UnionType) {
|
|
604
603
|
return this.unionNeedsName(t);
|
|
605
604
|
}
|
|
606
|
-
return
|
|
605
|
+
return TypeUtils_1.isNamedType(t);
|
|
607
606
|
});
|
|
608
607
|
const types = this.typeGraph.allTypesUnordered();
|
|
609
|
-
this._haveUnions =
|
|
610
|
-
this._haveMaps =
|
|
611
|
-
const classTypes =
|
|
612
|
-
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));
|
|
613
612
|
this._namedTypes = this._declarationIR.declarations.filter(d => d.kind === "define").map(d => d.type);
|
|
614
|
-
const { objects, enums, unions } =
|
|
613
|
+
const { objects, enums, unions } = TypeUtils_1.separateNamedTypes(this._namedTypes);
|
|
615
614
|
this._namedObjects = new Set(objects);
|
|
616
615
|
this._namedEnums = new Set(enums);
|
|
617
616
|
this._namedUnions = new Set(unions);
|
package/dist/CycleBreaker.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.breakCycles = void 0;
|
|
4
3
|
const Support_1 = require("./support/Support");
|
|
5
4
|
function breakCycles(outEdges, chooseBreaker) {
|
|
6
5
|
const numNodes = outEdges.length;
|
|
@@ -29,14 +28,14 @@ function breakCycles(outEdges, chooseBreaker) {
|
|
|
29
28
|
}
|
|
30
29
|
function removeNode(node) {
|
|
31
30
|
for (const n of outEdges[node]) {
|
|
32
|
-
|
|
31
|
+
Support_1.assert(inDegree[n] > 0);
|
|
33
32
|
inDegree[n] -= 1;
|
|
34
33
|
if (inDegree[n] === 0) {
|
|
35
34
|
workList.push(n);
|
|
36
35
|
}
|
|
37
36
|
}
|
|
38
37
|
for (const n of inEdges[node]) {
|
|
39
|
-
|
|
38
|
+
Support_1.assert(outDegree[n] > 0);
|
|
40
39
|
outDegree[n] -= 1;
|
|
41
40
|
if (outDegree[n] === 0) {
|
|
42
41
|
workList.push(n);
|
|
@@ -51,7 +50,7 @@ function breakCycles(outEdges, chooseBreaker) {
|
|
|
51
50
|
done[i] = true;
|
|
52
51
|
continue;
|
|
53
52
|
}
|
|
54
|
-
|
|
53
|
+
Support_1.assert(inDegree[i] === 0 || outDegree[i] === 0, "Can't have nodes in the worklist with in and out edges");
|
|
55
54
|
removeNode(i);
|
|
56
55
|
continue;
|
|
57
56
|
}
|
|
@@ -74,7 +73,7 @@ function breakCycles(outEdges, chooseBreaker) {
|
|
|
74
73
|
// the dependee cycle.
|
|
75
74
|
const maybeEdge = outEdges[n].find(x => !done[x]);
|
|
76
75
|
if (maybeEdge === undefined) {
|
|
77
|
-
return
|
|
76
|
+
return Support_1.panic("Presumed cycle is not a cycle");
|
|
78
77
|
}
|
|
79
78
|
const maybeFirst = path.indexOf(maybeEdge);
|
|
80
79
|
if (maybeFirst === undefined) {
|
|
@@ -86,7 +85,7 @@ function breakCycles(outEdges, chooseBreaker) {
|
|
|
86
85
|
// We found a cycle - break it
|
|
87
86
|
const cycle = path.slice(maybeFirst);
|
|
88
87
|
const [breakNode, info] = chooseBreaker(cycle);
|
|
89
|
-
|
|
88
|
+
Support_1.assert(cycle.indexOf(breakNode) >= 0, "Breaker chose an invalid node");
|
|
90
89
|
removeNode(breakNode);
|
|
91
90
|
results.push([breakNode, info]);
|
|
92
91
|
break;
|
package/dist/DateTime.js
CHANGED
package/dist/DeclarationIR.d.ts
CHANGED
|
@@ -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;
|