quicktype 17.0.3 → 17.0.5
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,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.messageAssert = exports.messageError = exports.QuickTypeError = void 0;
|
|
4
3
|
const errorMessages = {
|
|
5
4
|
InternalError: "Internal error: ${message}",
|
|
6
5
|
// Misc
|
|
@@ -66,9 +65,6 @@ const errorMessages = {
|
|
|
66
65
|
TypeScriptCompilerError: "TypeScript error: ${message}"
|
|
67
66
|
};
|
|
68
67
|
class QuickTypeError extends Error {
|
|
69
|
-
errorMessage;
|
|
70
|
-
messageName;
|
|
71
|
-
properties;
|
|
72
68
|
constructor(errorMessage, messageName, userMessage, properties) {
|
|
73
69
|
super(userMessage);
|
|
74
70
|
this.errorMessage = errorMessage;
|
|
@@ -80,9 +76,8 @@ exports.QuickTypeError = QuickTypeError;
|
|
|
80
76
|
function messageError(kind, properties) {
|
|
81
77
|
const message = errorMessages[kind];
|
|
82
78
|
let userMessage = message;
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
let value = propertiesMap[name];
|
|
79
|
+
for (const name of Object.getOwnPropertyNames(properties)) {
|
|
80
|
+
let value = properties[name];
|
|
86
81
|
if (typeof value === "object" && typeof value.toString === "function") {
|
|
87
82
|
value = value.toString();
|
|
88
83
|
}
|
|
@@ -94,7 +89,7 @@ function messageError(kind, properties) {
|
|
|
94
89
|
}
|
|
95
90
|
userMessage = userMessage.replace("${" + name + "}", value);
|
|
96
91
|
}
|
|
97
|
-
throw new QuickTypeError(message, kind, userMessage,
|
|
92
|
+
throw new QuickTypeError(message, kind, userMessage, properties);
|
|
98
93
|
}
|
|
99
94
|
exports.messageError = messageError;
|
|
100
95
|
function messageAssert(assertion, kind, properties) {
|
|
@@ -5,12 +5,12 @@ export declare class Namespace {
|
|
|
5
5
|
private readonly _members;
|
|
6
6
|
constructor(_name: string, parent: Namespace | undefined, forbiddenNamespaces: Iterable<Namespace>, additionalForbidden: Iterable<Name>);
|
|
7
7
|
private addChild;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
readonly children: ReadonlySet<Namespace>;
|
|
9
|
+
readonly members: ReadonlySet<Name>;
|
|
10
|
+
readonly forbiddenNameds: ReadonlySet<Name>;
|
|
11
11
|
add<TName extends Name>(named: TName): TName;
|
|
12
12
|
}
|
|
13
|
-
export type NameStyle = (rawName: string) => string;
|
|
13
|
+
export declare type NameStyle = (rawName: string) => string;
|
|
14
14
|
export declare class Namer {
|
|
15
15
|
readonly name: string;
|
|
16
16
|
readonly nameStyle: NameStyle;
|
|
@@ -25,9 +25,9 @@ export declare abstract class Name {
|
|
|
25
25
|
private readonly _associates;
|
|
26
26
|
constructor(_namingFunction: Namer | undefined, order: number);
|
|
27
27
|
addAssociate(associate: AssociatedName): void;
|
|
28
|
-
abstract
|
|
28
|
+
abstract readonly dependencies: ReadonlyArray<Name>;
|
|
29
29
|
isFixed(): this is FixedName;
|
|
30
|
-
|
|
30
|
+
readonly namingFunction: Namer;
|
|
31
31
|
abstract proposeUnstyledNames(names: ReadonlyMap<Name, string>): ReadonlySet<string>;
|
|
32
32
|
firstProposedName(names: ReadonlyMap<Name, string>): string;
|
|
33
33
|
nameAssignments(forbiddenNames: ReadonlySet<string>, assignedName: string): ReadonlyMap<Name, string> | null;
|
|
@@ -35,29 +35,29 @@ export declare abstract class Name {
|
|
|
35
35
|
export declare class FixedName extends Name {
|
|
36
36
|
private readonly _fixedName;
|
|
37
37
|
constructor(_fixedName: string);
|
|
38
|
-
|
|
38
|
+
readonly dependencies: ReadonlyArray<Name>;
|
|
39
39
|
addAssociate(_: AssociatedName): never;
|
|
40
|
-
|
|
40
|
+
readonly fixedName: string;
|
|
41
41
|
proposeUnstyledNames(_?: ReadonlyMap<Name, string>): ReadonlySet<string>;
|
|
42
42
|
}
|
|
43
43
|
export declare class SimpleName extends Name {
|
|
44
44
|
private readonly _unstyledNames;
|
|
45
45
|
constructor(unstyledNames: Iterable<string>, namingFunction: Namer, order: number);
|
|
46
|
-
|
|
46
|
+
readonly dependencies: ReadonlyArray<Name>;
|
|
47
47
|
proposeUnstyledNames(_?: ReadonlyMap<Name, string>): ReadonlySet<string>;
|
|
48
48
|
}
|
|
49
49
|
export declare class AssociatedName extends Name {
|
|
50
50
|
private readonly _sponsor;
|
|
51
51
|
readonly getName: (sponsorName: string) => string;
|
|
52
52
|
constructor(_sponsor: Name, order: number, getName: (sponsorName: string) => string);
|
|
53
|
-
|
|
53
|
+
readonly dependencies: ReadonlyArray<Name>;
|
|
54
54
|
proposeUnstyledNames(_?: ReadonlyMap<Name, string>): never;
|
|
55
55
|
}
|
|
56
56
|
export declare class DependencyName extends Name {
|
|
57
57
|
private readonly _proposeUnstyledName;
|
|
58
58
|
private readonly _dependencies;
|
|
59
59
|
constructor(namingFunction: Namer | undefined, order: number, _proposeUnstyledName: (lookup: (n: Name) => string) => string);
|
|
60
|
-
|
|
60
|
+
readonly dependencies: ReadonlyArray<Name>;
|
|
61
61
|
proposeUnstyledNames(names: ReadonlyMap<Name, string>): ReadonlySet<string>;
|
|
62
62
|
}
|
|
63
63
|
export declare function keywordNamespace(name: string, keywords: string[]): Namespace;
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.assignNames = exports.keywordNamespace = exports.DependencyName = exports.AssociatedName = exports.SimpleName = exports.FixedName = exports.Name = exports.funPrefixNamer = exports.Namer = exports.Namespace = void 0;
|
|
4
3
|
const collection_utils_1 = require("collection-utils");
|
|
5
4
|
const Support_1 = require("./support/Support");
|
|
6
5
|
class Namespace {
|
|
7
|
-
forbiddenNamespaces;
|
|
8
|
-
additionalForbidden;
|
|
9
|
-
_children = new Set();
|
|
10
|
-
_members = new Set();
|
|
11
6
|
constructor(_name, parent, forbiddenNamespaces, additionalForbidden) {
|
|
7
|
+
this._children = new Set();
|
|
8
|
+
this._members = new Set();
|
|
12
9
|
this.forbiddenNamespaces = new Set(forbiddenNamespaces);
|
|
13
10
|
this.additionalForbidden = new Set(additionalForbidden);
|
|
14
11
|
if (parent !== undefined) {
|
|
@@ -26,7 +23,7 @@ class Namespace {
|
|
|
26
23
|
}
|
|
27
24
|
get forbiddenNameds() {
|
|
28
25
|
// FIXME: cache
|
|
29
|
-
return
|
|
26
|
+
return collection_utils_1.setUnion(this.additionalForbidden, ...Array.from(this.forbiddenNamespaces).map(ns => ns.members));
|
|
30
27
|
}
|
|
31
28
|
add(named) {
|
|
32
29
|
this._members.add(named);
|
|
@@ -49,9 +46,6 @@ exports.Namespace = Namespace;
|
|
|
49
46
|
// `Namer` is a class so that we can compare namers and put them into immutable
|
|
50
47
|
// collections.
|
|
51
48
|
class Namer {
|
|
52
|
-
name;
|
|
53
|
-
nameStyle;
|
|
54
|
-
_prefixes;
|
|
55
49
|
constructor(name, nameStyle, prefixes) {
|
|
56
50
|
this.name = name;
|
|
57
51
|
this.nameStyle = nameStyle;
|
|
@@ -62,7 +56,7 @@ class Namer {
|
|
|
62
56
|
assignNames(names, forbiddenNamesIterable, namesToAssignIterable) {
|
|
63
57
|
const forbiddenNames = new Set(forbiddenNamesIterable);
|
|
64
58
|
const namesToAssign = Array.from(namesToAssignIterable);
|
|
65
|
-
|
|
59
|
+
Support_1.assert(namesToAssign.length > 0, "Number of names can't be less than 1");
|
|
66
60
|
const allAssignedNames = new Map();
|
|
67
61
|
let namesToPrefix = [];
|
|
68
62
|
for (const name of namesToAssign) {
|
|
@@ -70,14 +64,14 @@ class Namer {
|
|
|
70
64
|
const namingFunction = name.namingFunction;
|
|
71
65
|
// Find the first proposed name that isn't proposed by
|
|
72
66
|
// any of the other names and that isn't already forbidden.
|
|
73
|
-
const maybeUniqueName =
|
|
67
|
+
const maybeUniqueName = collection_utils_1.iterableFind(proposedNames, proposed => !forbiddenNames.has(namingFunction.nameStyle(proposed)) &&
|
|
74
68
|
namesToAssign.every(n => n === name || !n.proposeUnstyledNames(names).has(proposed)));
|
|
75
69
|
if (maybeUniqueName !== undefined) {
|
|
76
70
|
const styledName = namingFunction.nameStyle(maybeUniqueName);
|
|
77
71
|
const assigned = name.nameAssignments(forbiddenNames, styledName);
|
|
78
72
|
if (assigned !== null) {
|
|
79
|
-
|
|
80
|
-
|
|
73
|
+
collection_utils_1.mapMergeInto(allAssignedNames, assigned);
|
|
74
|
+
collection_utils_1.setUnionInto(forbiddenNames, assigned.values());
|
|
81
75
|
continue;
|
|
82
76
|
}
|
|
83
77
|
}
|
|
@@ -88,7 +82,7 @@ class Namer {
|
|
|
88
82
|
let prefixes = this._prefixes.values();
|
|
89
83
|
let suffixNumber = 1;
|
|
90
84
|
for (const name of namesToPrefix) {
|
|
91
|
-
const originalName =
|
|
85
|
+
const originalName = Support_1.defined(collection_utils_1.iterableFirst(name.proposeUnstyledNames(names)));
|
|
92
86
|
for (;;) {
|
|
93
87
|
let nameToTry;
|
|
94
88
|
const { done, value: prefix } = prefixes.next();
|
|
@@ -103,8 +97,8 @@ class Namer {
|
|
|
103
97
|
const assigned = name.nameAssignments(forbiddenNames, styledName);
|
|
104
98
|
if (assigned === null)
|
|
105
99
|
continue;
|
|
106
|
-
|
|
107
|
-
|
|
100
|
+
collection_utils_1.mapMergeInto(allAssignedNames, assigned);
|
|
101
|
+
collection_utils_1.setUnionInto(forbiddenNames, assigned.values());
|
|
108
102
|
break;
|
|
109
103
|
}
|
|
110
104
|
}
|
|
@@ -136,13 +130,11 @@ exports.funPrefixNamer = funPrefixNamer;
|
|
|
136
130
|
// own common superclass. Most methods of `Name` make sense only either
|
|
137
131
|
// for `FixedName` or the non-fixed names.
|
|
138
132
|
class Name {
|
|
139
|
-
_namingFunction;
|
|
140
|
-
order;
|
|
141
|
-
_associates = new Set();
|
|
142
133
|
// If a Named is fixed, the namingFunction is undefined.
|
|
143
134
|
constructor(_namingFunction, order) {
|
|
144
135
|
this._namingFunction = _namingFunction;
|
|
145
136
|
this.order = order;
|
|
137
|
+
this._associates = new Set();
|
|
146
138
|
}
|
|
147
139
|
addAssociate(associate) {
|
|
148
140
|
this._associates.add(associate);
|
|
@@ -151,10 +143,10 @@ class Name {
|
|
|
151
143
|
return this instanceof FixedName;
|
|
152
144
|
}
|
|
153
145
|
get namingFunction() {
|
|
154
|
-
return
|
|
146
|
+
return Support_1.defined(this._namingFunction);
|
|
155
147
|
}
|
|
156
148
|
firstProposedName(names) {
|
|
157
|
-
return
|
|
149
|
+
return Support_1.defined(collection_utils_1.iterableFirst(this.proposeUnstyledNames(names)));
|
|
158
150
|
}
|
|
159
151
|
nameAssignments(forbiddenNames, assignedName) {
|
|
160
152
|
if (forbiddenNames.has(assignedName))
|
|
@@ -173,7 +165,6 @@ class Name {
|
|
|
173
165
|
exports.Name = Name;
|
|
174
166
|
// FIXME: FixedNameds should optionally be user-configurable
|
|
175
167
|
class FixedName extends Name {
|
|
176
|
-
_fixedName;
|
|
177
168
|
constructor(_fixedName) {
|
|
178
169
|
super(undefined, 0);
|
|
179
170
|
this._fixedName = _fixedName;
|
|
@@ -182,18 +173,17 @@ class FixedName extends Name {
|
|
|
182
173
|
return [];
|
|
183
174
|
}
|
|
184
175
|
addAssociate(_) {
|
|
185
|
-
return
|
|
176
|
+
return Support_1.panic("Cannot add associates to fixed names");
|
|
186
177
|
}
|
|
187
178
|
get fixedName() {
|
|
188
179
|
return this._fixedName;
|
|
189
180
|
}
|
|
190
181
|
proposeUnstyledNames(_) {
|
|
191
|
-
return
|
|
182
|
+
return Support_1.panic("Only fixedName should be called on FixedName.");
|
|
192
183
|
}
|
|
193
184
|
}
|
|
194
185
|
exports.FixedName = FixedName;
|
|
195
186
|
class SimpleName extends Name {
|
|
196
|
-
_unstyledNames;
|
|
197
187
|
constructor(unstyledNames, namingFunction, order) {
|
|
198
188
|
super(namingFunction, order);
|
|
199
189
|
this._unstyledNames = new Set(unstyledNames);
|
|
@@ -207,8 +197,6 @@ class SimpleName extends Name {
|
|
|
207
197
|
}
|
|
208
198
|
exports.SimpleName = SimpleName;
|
|
209
199
|
class AssociatedName extends Name {
|
|
210
|
-
_sponsor;
|
|
211
|
-
getName;
|
|
212
200
|
constructor(_sponsor, order, getName) {
|
|
213
201
|
super(undefined, order);
|
|
214
202
|
this._sponsor = _sponsor;
|
|
@@ -218,13 +206,11 @@ class AssociatedName extends Name {
|
|
|
218
206
|
return [this._sponsor];
|
|
219
207
|
}
|
|
220
208
|
proposeUnstyledNames(_) {
|
|
221
|
-
return
|
|
209
|
+
return Support_1.panic("AssociatedName must be assigned via its sponsor");
|
|
222
210
|
}
|
|
223
211
|
}
|
|
224
212
|
exports.AssociatedName = AssociatedName;
|
|
225
213
|
class DependencyName extends Name {
|
|
226
|
-
_proposeUnstyledName;
|
|
227
|
-
_dependencies;
|
|
228
214
|
constructor(namingFunction, order, _proposeUnstyledName) {
|
|
229
215
|
super(namingFunction, order);
|
|
230
216
|
this._proposeUnstyledName = _proposeUnstyledName;
|
|
@@ -241,8 +227,8 @@ class DependencyName extends Name {
|
|
|
241
227
|
proposeUnstyledNames(names) {
|
|
242
228
|
return new Set([
|
|
243
229
|
this._proposeUnstyledName(n => {
|
|
244
|
-
|
|
245
|
-
return
|
|
230
|
+
Support_1.assert(this._dependencies.has(n), "DependencyName proposer is not pure");
|
|
231
|
+
return Support_1.defined(names.get(n));
|
|
246
232
|
})
|
|
247
233
|
]);
|
|
248
234
|
}
|
|
@@ -257,50 +243,49 @@ function keywordNamespace(name, keywords) {
|
|
|
257
243
|
}
|
|
258
244
|
exports.keywordNamespace = keywordNamespace;
|
|
259
245
|
function allNamespacesRecursively(namespaces) {
|
|
260
|
-
return
|
|
246
|
+
return collection_utils_1.setUnion(namespaces, ...Array.from(collection_utils_1.setMap(namespaces, ns => allNamespacesRecursively(ns.children))));
|
|
261
247
|
}
|
|
262
248
|
class NamingContext {
|
|
263
|
-
_names = new Map();
|
|
264
|
-
_namedsForName = new Map();
|
|
265
|
-
namespaces;
|
|
266
249
|
constructor(rootNamespaces) {
|
|
250
|
+
this._names = new Map();
|
|
251
|
+
this._namedsForName = new Map();
|
|
252
|
+
this.isReadyToBeNamed = (named) => {
|
|
253
|
+
if (this._names.has(named))
|
|
254
|
+
return false;
|
|
255
|
+
return named.dependencies.every((n) => this._names.has(n));
|
|
256
|
+
};
|
|
257
|
+
this.isConflicting = (namedNamespace, proposed) => {
|
|
258
|
+
const namedsForProposed = this._namedsForName.get(proposed);
|
|
259
|
+
// If the name is not assigned at all, there is no conflict.
|
|
260
|
+
if (namedsForProposed === undefined)
|
|
261
|
+
return false;
|
|
262
|
+
// The name is assigned, but it might still not be forbidden.
|
|
263
|
+
for (const n of namedsForProposed) {
|
|
264
|
+
if (namedNamespace.members.has(n) || namedNamespace.forbiddenNameds.has(n)) {
|
|
265
|
+
return true;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return false;
|
|
269
|
+
};
|
|
270
|
+
this.assign = (named, namedNamespace, name) => {
|
|
271
|
+
Support_1.assert(!this.names.has(named), `Name "${name}" assigned twice`);
|
|
272
|
+
Support_1.assert(!this.isConflicting(namedNamespace, name), `Assigned name "${name}" conflicts`);
|
|
273
|
+
this._names.set(named, name);
|
|
274
|
+
let namedsForName = this._namedsForName.get(name);
|
|
275
|
+
if (namedsForName === undefined) {
|
|
276
|
+
namedsForName = new Set();
|
|
277
|
+
this._namedsForName.set(name, namedsForName);
|
|
278
|
+
}
|
|
279
|
+
namedsForName.add(named);
|
|
280
|
+
};
|
|
267
281
|
this.namespaces = allNamespacesRecursively(rootNamespaces);
|
|
268
282
|
}
|
|
269
283
|
get names() {
|
|
270
284
|
return this._names;
|
|
271
285
|
}
|
|
272
|
-
isReadyToBeNamed = (named) => {
|
|
273
|
-
if (this._names.has(named))
|
|
274
|
-
return false;
|
|
275
|
-
return named.dependencies.every((n) => this._names.has(n));
|
|
276
|
-
};
|
|
277
286
|
areForbiddensFullyNamed(namespace) {
|
|
278
|
-
return
|
|
287
|
+
return collection_utils_1.iterableEvery(namespace.forbiddenNameds, n => this._names.has(n));
|
|
279
288
|
}
|
|
280
|
-
isConflicting = (namedNamespace, proposed) => {
|
|
281
|
-
const namedsForProposed = this._namedsForName.get(proposed);
|
|
282
|
-
// If the name is not assigned at all, there is no conflict.
|
|
283
|
-
if (namedsForProposed === undefined)
|
|
284
|
-
return false;
|
|
285
|
-
// The name is assigned, but it might still not be forbidden.
|
|
286
|
-
for (const n of namedsForProposed) {
|
|
287
|
-
if (namedNamespace.members.has(n) || namedNamespace.forbiddenNameds.has(n)) {
|
|
288
|
-
return true;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
return false;
|
|
292
|
-
};
|
|
293
|
-
assign = (named, namedNamespace, name) => {
|
|
294
|
-
(0, Support_1.assert)(!this.names.has(named), `Name "${name}" assigned twice`);
|
|
295
|
-
(0, Support_1.assert)(!this.isConflicting(namedNamespace, name), `Assigned name "${name}" conflicts`);
|
|
296
|
-
this._names.set(named, name);
|
|
297
|
-
let namedsForName = this._namedsForName.get(name);
|
|
298
|
-
if (namedsForName === undefined) {
|
|
299
|
-
namedsForName = new Set();
|
|
300
|
-
this._namedsForName.set(name, namedsForName);
|
|
301
|
-
}
|
|
302
|
-
namedsForName.add(named);
|
|
303
|
-
};
|
|
304
289
|
}
|
|
305
290
|
// Naming algorithm
|
|
306
291
|
function assignNames(rootNamespaces) {
|
|
@@ -318,36 +303,36 @@ function assignNames(rootNamespaces) {
|
|
|
318
303
|
// at least one unnamed Named that has all its dependencies satisfied.
|
|
319
304
|
// If no such namespace exists we're either done, or there's an unallowed
|
|
320
305
|
// cycle.
|
|
321
|
-
const unfinishedNamespaces =
|
|
322
|
-
const readyNamespace =
|
|
306
|
+
const unfinishedNamespaces = collection_utils_1.setFilter(ctx.namespaces, ns => ctx.areForbiddensFullyNamed(ns));
|
|
307
|
+
const readyNamespace = collection_utils_1.iterableFind(unfinishedNamespaces, ns => collection_utils_1.iterableSome(ns.members, ctx.isReadyToBeNamed));
|
|
323
308
|
if (readyNamespace === undefined) {
|
|
324
309
|
// FIXME: Check for cycles?
|
|
325
310
|
return ctx.names;
|
|
326
311
|
}
|
|
327
|
-
const allForbiddenNames =
|
|
328
|
-
let forbiddenNames =
|
|
312
|
+
const allForbiddenNames = collection_utils_1.setUnion(readyNamespace.members, readyNamespace.forbiddenNameds);
|
|
313
|
+
let forbiddenNames = collection_utils_1.setFilterMap(allForbiddenNames, n => ctx.names.get(n));
|
|
329
314
|
// 2. From low order to high order, sort those names into sets where all
|
|
330
315
|
// members of a set propose the same name and have the same naming
|
|
331
316
|
// function.
|
|
332
317
|
for (;;) {
|
|
333
|
-
const allReadyNames =
|
|
334
|
-
const minOrderName =
|
|
318
|
+
const allReadyNames = collection_utils_1.setFilter(readyNamespace.members, ctx.isReadyToBeNamed);
|
|
319
|
+
const minOrderName = collection_utils_1.iterableMinBy(allReadyNames, n => n.order);
|
|
335
320
|
if (minOrderName === undefined)
|
|
336
321
|
break;
|
|
337
322
|
const minOrder = minOrderName.order;
|
|
338
|
-
const readyNames =
|
|
323
|
+
const readyNames = collection_utils_1.setFilter(allReadyNames, n => n.order === minOrder);
|
|
339
324
|
// It would be nice if we had tuples, then we wouldn't have to do this in
|
|
340
325
|
// two steps.
|
|
341
|
-
const byNamingFunction =
|
|
326
|
+
const byNamingFunction = collection_utils_1.setGroupBy(readyNames, n => n.namingFunction);
|
|
342
327
|
for (const [namer, namedsForNamingFunction] of byNamingFunction) {
|
|
343
|
-
const byProposed =
|
|
328
|
+
const byProposed = collection_utils_1.setGroupBy(namedsForNamingFunction, n => n.namingFunction.nameStyle(n.firstProposedName(ctx.names)));
|
|
344
329
|
for (const [, nameds] of byProposed) {
|
|
345
330
|
// 3. Use each set's naming function to name its members.
|
|
346
331
|
const names = namer.assignNames(ctx.names, forbiddenNames, nameds);
|
|
347
332
|
for (const [name, assigned] of names) {
|
|
348
333
|
ctx.assign(name, readyNamespace, assigned);
|
|
349
334
|
}
|
|
350
|
-
|
|
335
|
+
collection_utils_1.setUnionInto(forbiddenNames, names.values());
|
|
351
336
|
}
|
|
352
337
|
}
|
|
353
338
|
}
|
|
@@ -3,17 +3,17 @@ import { Name, Namespace } from "./Naming";
|
|
|
3
3
|
import { Source, Sourcelike } from "./Source";
|
|
4
4
|
import { AnnotationData } from "./Annotation";
|
|
5
5
|
import { TargetLanguage } from "./TargetLanguage";
|
|
6
|
-
export type RenderResult = {
|
|
6
|
+
export declare type RenderResult = {
|
|
7
7
|
sources: ReadonlyMap<string, Source>;
|
|
8
8
|
names: ReadonlyMap<Name, string>;
|
|
9
9
|
};
|
|
10
|
-
export type BlankLinePosition = "none" | "interposing" | "leading" | "leading-and-interposing";
|
|
11
|
-
export type BlankLineConfig = BlankLinePosition | [BlankLinePosition, number];
|
|
12
|
-
export type RenderContext = {
|
|
10
|
+
export declare type BlankLinePosition = "none" | "interposing" | "leading" | "leading-and-interposing";
|
|
11
|
+
export declare type BlankLineConfig = BlankLinePosition | [BlankLinePosition, number];
|
|
12
|
+
export declare type RenderContext = {
|
|
13
13
|
typeGraph: TypeGraph;
|
|
14
14
|
leadingComments: string[] | undefined;
|
|
15
15
|
};
|
|
16
|
-
export type ForEachPosition = "first" | "last" | "middle" | "only";
|
|
16
|
+
export declare type ForEachPosition = "first" | "last" | "middle" | "only";
|
|
17
17
|
export declare abstract class Renderer {
|
|
18
18
|
protected readonly targetLanguage: TargetLanguage;
|
|
19
19
|
protected readonly typeGraph: TypeGraph;
|
|
@@ -46,5 +46,5 @@ export declare abstract class Renderer {
|
|
|
46
46
|
protected initializeEmitContextForFilename(filename: string): void;
|
|
47
47
|
protected finishFile(filename: string): void;
|
|
48
48
|
render(givenOutputFilename: string): RenderResult;
|
|
49
|
-
|
|
49
|
+
readonly names: ReadonlyMap<Name, string>;
|
|
50
50
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Renderer = void 0;
|
|
4
3
|
const collection_utils_1 = require("collection-utils");
|
|
5
4
|
const Naming_1 = require("./Naming");
|
|
6
5
|
const Source_1 = require("./Source");
|
|
@@ -30,15 +29,6 @@ function lineIndentation(line) {
|
|
|
30
29
|
return { indent: 0, text: null };
|
|
31
30
|
}
|
|
32
31
|
class EmitContext {
|
|
33
|
-
_lastNewline;
|
|
34
|
-
// @ts-ignore: Initialized in startEmit, which is called from the constructor
|
|
35
|
-
_emitted;
|
|
36
|
-
// @ts-ignore: Initialized in startEmit, which is called from the constructor
|
|
37
|
-
_currentEmitTarget;
|
|
38
|
-
// @ts-ignore: Initialized in startEmit, which is called from the constructor
|
|
39
|
-
_numBlankLinesNeeded;
|
|
40
|
-
// @ts-ignore: Initialized in startEmit, which is called from the constructor
|
|
41
|
-
_preventBlankLine;
|
|
42
32
|
constructor() {
|
|
43
33
|
this._currentEmitTarget = this._emitted = [];
|
|
44
34
|
this._numBlankLinesNeeded = 0;
|
|
@@ -58,7 +48,7 @@ class EmitContext {
|
|
|
58
48
|
this._preventBlankLine = false;
|
|
59
49
|
}
|
|
60
50
|
emitNewline() {
|
|
61
|
-
const nl =
|
|
51
|
+
const nl = Source_1.newline();
|
|
62
52
|
this.pushItem(nl);
|
|
63
53
|
this._lastNewline = nl;
|
|
64
54
|
}
|
|
@@ -86,21 +76,21 @@ class EmitContext {
|
|
|
86
76
|
}
|
|
87
77
|
changeIndent(offset) {
|
|
88
78
|
if (this._lastNewline === undefined) {
|
|
89
|
-
return
|
|
79
|
+
return Support_1.panic("Cannot change indent for the first line");
|
|
90
80
|
}
|
|
91
81
|
this._lastNewline.indentationChange += offset;
|
|
92
82
|
}
|
|
93
83
|
}
|
|
94
84
|
class Renderer {
|
|
95
|
-
targetLanguage;
|
|
96
|
-
typeGraph;
|
|
97
|
-
leadingComments;
|
|
98
|
-
_names;
|
|
99
|
-
_finishedFiles;
|
|
100
|
-
_finishedEmitContexts;
|
|
101
|
-
_emitContext;
|
|
102
85
|
constructor(targetLanguage, renderContext) {
|
|
103
86
|
this.targetLanguage = targetLanguage;
|
|
87
|
+
this.emitTable = (tableArray) => {
|
|
88
|
+
if (tableArray.length === 0)
|
|
89
|
+
return;
|
|
90
|
+
const table = tableArray.map(r => r.map(sl => Source_1.sourcelikeToSource(sl)));
|
|
91
|
+
this._emitContext.emitItem({ kind: "table", table });
|
|
92
|
+
this._emitContext.emitNewline();
|
|
93
|
+
};
|
|
104
94
|
this.typeGraph = renderContext.typeGraph;
|
|
105
95
|
this.leadingComments = renderContext.leadingComments;
|
|
106
96
|
this._finishedFiles = new Map();
|
|
@@ -154,7 +144,7 @@ class Renderer {
|
|
|
154
144
|
for (let i = 1; i < numLines; i++) {
|
|
155
145
|
const line = lines[i];
|
|
156
146
|
const { indent, text } = lineIndentation(line);
|
|
157
|
-
|
|
147
|
+
Support_1.assert(indent % 4 === 0, "Indentation is not a multiple of 4.");
|
|
158
148
|
if (text !== null) {
|
|
159
149
|
const newIndent = indent / 4;
|
|
160
150
|
this.changeIndent(newIndent - currentIndent);
|
|
@@ -173,7 +163,7 @@ class Renderer {
|
|
|
173
163
|
const oldEmitContext = this._emitContext;
|
|
174
164
|
this._emitContext = new EmitContext();
|
|
175
165
|
emitter();
|
|
176
|
-
|
|
166
|
+
Support_1.assert(!this._emitContext.isNested, "emit context not restored correctly");
|
|
177
167
|
const source = this._emitContext.source;
|
|
178
168
|
this._emitContext = oldEmitContext;
|
|
179
169
|
return source;
|
|
@@ -185,26 +175,19 @@ class Renderer {
|
|
|
185
175
|
}
|
|
186
176
|
emitAnnotated(annotation, emitter) {
|
|
187
177
|
const lines = this.gatherSource(emitter);
|
|
188
|
-
const source =
|
|
189
|
-
this._emitContext.emitItem(
|
|
178
|
+
const source = Source_1.sourcelikeToSource(lines);
|
|
179
|
+
this._emitContext.emitItem(Source_1.annotated(annotation, source));
|
|
190
180
|
}
|
|
191
181
|
emitIssue(message, emitter) {
|
|
192
182
|
this.emitAnnotated(new Annotation_1.IssueAnnotationData(message), emitter);
|
|
193
183
|
}
|
|
194
|
-
emitTable = (tableArray) => {
|
|
195
|
-
if (tableArray.length === 0)
|
|
196
|
-
return;
|
|
197
|
-
const table = tableArray.map(r => r.map(sl => (0, Source_1.sourcelikeToSource)(sl)));
|
|
198
|
-
this._emitContext.emitItem({ kind: "table", table });
|
|
199
|
-
this._emitContext.emitNewline();
|
|
200
|
-
};
|
|
201
184
|
changeIndent(offset) {
|
|
202
185
|
this._emitContext.changeIndent(offset);
|
|
203
186
|
}
|
|
204
187
|
iterableForEach(iterable, emitter) {
|
|
205
188
|
const items = Array.from(iterable);
|
|
206
189
|
let onFirst = true;
|
|
207
|
-
for (const [i, v] of
|
|
190
|
+
for (const [i, v] of collection_utils_1.iterableEnumerate(items)) {
|
|
208
191
|
const position = items.length === 1 ? "only" : onFirst ? "first" : i === items.length - 1 ? "last" : "middle";
|
|
209
192
|
emitter(v, position);
|
|
210
193
|
onFirst = false;
|
|
@@ -236,7 +219,7 @@ class Renderer {
|
|
|
236
219
|
this.changeIndent(-1);
|
|
237
220
|
}
|
|
238
221
|
assignNames() {
|
|
239
|
-
return
|
|
222
|
+
return Naming_1.assignNames(this.setUpNaming());
|
|
240
223
|
}
|
|
241
224
|
initializeEmitContextForFilename(filename) {
|
|
242
225
|
if (this._finishedEmitContexts.has(filename.toLowerCase())) {
|
|
@@ -250,7 +233,7 @@ class Renderer {
|
|
|
250
233
|
if (this._finishedFiles.has(filename)) {
|
|
251
234
|
console.log(`[WARNING] Tried to emit file ${filename} more than once. If performing multi-file output this warning can be safely ignored.`);
|
|
252
235
|
}
|
|
253
|
-
const source =
|
|
236
|
+
const source = Source_1.sourcelikeToSource(this._emitContext.source);
|
|
254
237
|
this._finishedFiles.set(filename, source);
|
|
255
238
|
// [Michael Fey (@MrRooni), 2019-5-9] We save the current EmitContext for possible reuse later. We put it into the map with a lowercased version of the key so we can do a case-insensitive lookup later. The reason we lowercase it is because some schema (looking at you keyword-unions.schema) define objects of the same name with different casing. BOOL vs. bool, for example.
|
|
256
239
|
this._finishedEmitContexts.set(filename.toLowerCase(), this._emitContext);
|
|
@@ -266,7 +249,7 @@ class Renderer {
|
|
|
266
249
|
}
|
|
267
250
|
get names() {
|
|
268
251
|
if (this._names === undefined) {
|
|
269
|
-
return
|
|
252
|
+
return Support_1.panic("Names accessed before they were assigned");
|
|
270
253
|
}
|
|
271
254
|
return this._names;
|
|
272
255
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Primary options show up in the web UI in the "Language" settings tab,
|
|
3
3
|
* secondary options in "Other".
|
|
4
4
|
*/
|
|
5
|
-
export type OptionKind = "primary" | "secondary";
|
|
5
|
+
export declare type OptionKind = "primary" | "secondary";
|
|
6
6
|
export interface OptionDefinition {
|
|
7
7
|
name: string;
|
|
8
8
|
type: StringConstructor | BooleanConstructor;
|
|
@@ -26,13 +26,13 @@ export declare abstract class Option<T> {
|
|
|
26
26
|
getValue(values: {
|
|
27
27
|
[name: string]: any;
|
|
28
28
|
}): T;
|
|
29
|
-
|
|
29
|
+
readonly cliDefinitions: {
|
|
30
30
|
display: OptionDefinition[];
|
|
31
31
|
actual: OptionDefinition[];
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
|
-
export type OptionValueType<O> = O extends Option<infer T> ? T : never;
|
|
35
|
-
export type OptionValues<T> = {
|
|
34
|
+
export declare type OptionValueType<O> = O extends Option<infer T> ? T : never;
|
|
35
|
+
export declare type OptionValues<T> = {
|
|
36
36
|
[P in keyof T]: OptionValueType<T[P]>;
|
|
37
37
|
};
|
|
38
38
|
export declare function getOptionValues<T extends {
|
|
@@ -51,7 +51,7 @@ export declare class BooleanOption extends Option<boolean> {
|
|
|
51
51
|
* @param kind Whether it's a primary or secondary option.
|
|
52
52
|
*/
|
|
53
53
|
constructor(name: string, description: string, defaultValue: boolean, kind?: OptionKind);
|
|
54
|
-
|
|
54
|
+
readonly cliDefinitions: {
|
|
55
55
|
display: OptionDefinition[];
|
|
56
56
|
actual: OptionDefinition[];
|
|
57
57
|
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EnumOption = exports.StringOption = exports.BooleanOption = exports.getOptionValues = exports.Option = void 0;
|
|
4
3
|
const Support_1 = require("./support/Support");
|
|
5
4
|
const Messages_1 = require("./Messages");
|
|
6
5
|
const collection_utils_1 = require("collection-utils");
|
|
@@ -9,11 +8,10 @@ const collection_utils_1 = require("collection-utils");
|
|
|
9
8
|
* subclasses, `BooleanOption`, `EnumOption`, or `StringOption`.
|
|
10
9
|
*/
|
|
11
10
|
class Option {
|
|
12
|
-
definition;
|
|
13
11
|
constructor(definition) {
|
|
14
12
|
definition.renderer = true;
|
|
15
13
|
this.definition = definition;
|
|
16
|
-
|
|
14
|
+
Support_1.assert(definition.kind !== undefined, "Renderer option kind must be defined");
|
|
17
15
|
}
|
|
18
16
|
getValue(values) {
|
|
19
17
|
const value = values[this.definition.name];
|
|
@@ -107,7 +105,6 @@ class StringOption extends Option {
|
|
|
107
105
|
}
|
|
108
106
|
exports.StringOption = StringOption;
|
|
109
107
|
class EnumOption extends Option {
|
|
110
|
-
_values;
|
|
111
108
|
constructor(name, description, values, defaultValue = undefined, kind = "primary") {
|
|
112
109
|
if (defaultValue === undefined) {
|
|
113
110
|
defaultValue = values[0][0];
|
|
@@ -132,8 +129,8 @@ class EnumOption extends Option {
|
|
|
132
129
|
if (name === undefined) {
|
|
133
130
|
name = this.definition.defaultValue;
|
|
134
131
|
}
|
|
135
|
-
if (!
|
|
136
|
-
return
|
|
132
|
+
if (!collection_utils_1.hasOwnProperty(this._values, name)) {
|
|
133
|
+
return Messages_1.messageError("RendererUnknownOptionValue", { value: name, name: this.definition.name });
|
|
137
134
|
}
|
|
138
135
|
return this._values[name];
|
|
139
136
|
}
|