quicktype 18.0.5 → 19.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. package/README.md +1 -1
  2. package/dist/{cli/CompressedJSONFromStream.d.ts → CompressedJSONFromStream.d.ts} +1 -1
  3. package/dist/{cli/CompressedJSONFromStream.js → CompressedJSONFromStream.js} +2 -2
  4. package/dist/{cli/GraphQLIntrospection.d.ts → GraphQLIntrospection.d.ts} +0 -0
  5. package/dist/{cli/GraphQLIntrospection.js → GraphQLIntrospection.js} +1 -1
  6. package/dist/{cli/TypeSource.d.ts → TypeSource.d.ts} +2 -2
  7. package/dist/{cli/TypeSource.js → TypeSource.js} +0 -0
  8. package/dist/{cli/URLGrammar.d.ts → URLGrammar.d.ts} +0 -0
  9. package/dist/{cli/URLGrammar.js → URLGrammar.js} +1 -1
  10. package/dist/{cli/index.d.ts → index.d.ts} +1 -1
  11. package/dist/{cli/index.js → index.js} +4 -5
  12. package/package.json +61 -77
  13. package/dist/quicktype-core/Annotation.d.ts +0 -8
  14. package/dist/quicktype-core/Annotation.js +0 -16
  15. package/dist/quicktype-core/ConvenienceRenderer.d.ts +0 -138
  16. package/dist/quicktype-core/ConvenienceRenderer.js +0 -668
  17. package/dist/quicktype-core/DateTime.d.ts +0 -10
  18. package/dist/quicktype-core/DateTime.js +0 -57
  19. package/dist/quicktype-core/DeclarationIR.d.ts +0 -14
  20. package/dist/quicktype-core/DeclarationIR.js +0 -167
  21. package/dist/quicktype-core/EncodedMarkovChain.d.ts +0 -1
  22. package/dist/quicktype-core/EncodedMarkovChain.js +0 -4
  23. package/dist/quicktype-core/GatherNames.d.ts +0 -2
  24. package/dist/quicktype-core/GatherNames.js +0 -333
  25. package/dist/quicktype-core/Graph.d.ts +0 -12
  26. package/dist/quicktype-core/Graph.js +0 -220
  27. package/dist/quicktype-core/GraphRewriting.d.ts +0 -87
  28. package/dist/quicktype-core/GraphRewriting.js +0 -421
  29. package/dist/quicktype-core/MakeTransformations.d.ts +0 -4
  30. package/dist/quicktype-core/MakeTransformations.js +0 -193
  31. package/dist/quicktype-core/MarkovChain.d.ts +0 -15
  32. package/dist/quicktype-core/MarkovChain.js +0 -154
  33. package/dist/quicktype-core/Messages.d.ts +0 -294
  34. package/dist/quicktype-core/Messages.js +0 -105
  35. package/dist/quicktype-core/Naming.d.ts +0 -64
  36. package/dist/quicktype-core/Naming.js +0 -356
  37. package/dist/quicktype-core/Renderer.d.ts +0 -50
  38. package/dist/quicktype-core/Renderer.js +0 -274
  39. package/dist/quicktype-core/RendererOptions.d.ts +0 -71
  40. package/dist/quicktype-core/RendererOptions.js +0 -141
  41. package/dist/quicktype-core/Run.d.ts +0 -174
  42. package/dist/quicktype-core/Run.js +0 -393
  43. package/dist/quicktype-core/Source.d.ts +0 -65
  44. package/dist/quicktype-core/Source.js +0 -204
  45. package/dist/quicktype-core/TargetLanguage.d.ts +0 -34
  46. package/dist/quicktype-core/TargetLanguage.js +0 -66
  47. package/dist/quicktype-core/Transformers.d.ts +0 -209
  48. package/dist/quicktype-core/Transformers.js +0 -836
  49. package/dist/quicktype-core/Type.d.ts +0 -206
  50. package/dist/quicktype-core/Type.js +0 -716
  51. package/dist/quicktype-core/TypeBuilder.d.ts +0 -61
  52. package/dist/quicktype-core/TypeBuilder.js +0 -324
  53. package/dist/quicktype-core/TypeGraph.d.ts +0 -75
  54. package/dist/quicktype-core/TypeGraph.js +0 -420
  55. package/dist/quicktype-core/TypeUtils.d.ts +0 -33
  56. package/dist/quicktype-core/TypeUtils.js +0 -230
  57. package/dist/quicktype-core/UnifyClasses.d.ts +0 -16
  58. package/dist/quicktype-core/UnifyClasses.js +0 -159
  59. package/dist/quicktype-core/UnionBuilder.d.ts +0 -49
  60. package/dist/quicktype-core/UnionBuilder.js +0 -282
  61. package/dist/quicktype-core/attributes/AccessorNames.d.ts +0 -18
  62. package/dist/quicktype-core/attributes/AccessorNames.js +0 -182
  63. package/dist/quicktype-core/attributes/Constraints.d.ts +0 -38
  64. package/dist/quicktype-core/attributes/Constraints.js +0 -172
  65. package/dist/quicktype-core/attributes/Description.d.ts +0 -9
  66. package/dist/quicktype-core/attributes/Description.js +0 -97
  67. package/dist/quicktype-core/attributes/EnumValues.d.ts +0 -8
  68. package/dist/quicktype-core/attributes/EnumValues.js +0 -31
  69. package/dist/quicktype-core/attributes/StringTypes.d.ts +0 -28
  70. package/dist/quicktype-core/attributes/StringTypes.js +0 -189
  71. package/dist/quicktype-core/attributes/TypeAttributes.d.ts +0 -34
  72. package/dist/quicktype-core/attributes/TypeAttributes.js +0 -119
  73. package/dist/quicktype-core/attributes/TypeNames.d.ts +0 -46
  74. package/dist/quicktype-core/attributes/TypeNames.js +0 -274
  75. package/dist/quicktype-core/attributes/URIAttributes.d.ts +0 -8
  76. package/dist/quicktype-core/attributes/URIAttributes.js +0 -85
  77. package/dist/quicktype-core/index.d.ts +0 -48
  78. package/dist/quicktype-core/index.js +0 -180
  79. package/dist/quicktype-core/input/CompressedJSON.d.ts +0 -69
  80. package/dist/quicktype-core/input/CompressedJSON.js +0 -276
  81. package/dist/quicktype-core/input/FetchingJSONSchemaStore.d.ts +0 -6
  82. package/dist/quicktype-core/input/FetchingJSONSchemaStore.js +0 -18
  83. package/dist/quicktype-core/input/Inference.d.ts +0 -22
  84. package/dist/quicktype-core/input/Inference.js +0 -240
  85. package/dist/quicktype-core/input/Inputs.d.ts +0 -48
  86. package/dist/quicktype-core/input/Inputs.js +0 -145
  87. package/dist/quicktype-core/input/JSONSchemaInput.d.ts +0 -91
  88. package/dist/quicktype-core/input/JSONSchemaInput.js +0 -1041
  89. package/dist/quicktype-core/input/JSONSchemaStore.d.ts +0 -8
  90. package/dist/quicktype-core/input/JSONSchemaStore.js +0 -36
  91. package/dist/quicktype-core/input/PostmanCollection.d.ts +0 -5
  92. package/dist/quicktype-core/input/PostmanCollection.js +0 -60
  93. package/dist/quicktype-core/input/io/NodeIO.d.ts +0 -3
  94. package/dist/quicktype-core/input/io/NodeIO.js +0 -87
  95. package/dist/quicktype-core/input/io/get-stream/buffer-stream.d.ts +0 -2
  96. package/dist/quicktype-core/input/io/get-stream/buffer-stream.js +0 -45
  97. package/dist/quicktype-core/input/io/get-stream/index.d.ts +0 -9
  98. package/dist/quicktype-core/input/io/get-stream/index.js +0 -52
  99. package/dist/quicktype-core/language/All.d.ts +0 -3
  100. package/dist/quicktype-core/language/All.js +0 -57
  101. package/dist/quicktype-core/language/CPlusPlus.d.ts +0 -241
  102. package/dist/quicktype-core/language/CPlusPlus.js +0 -1847
  103. package/dist/quicktype-core/language/CSharp.d.ts +0 -201
  104. package/dist/quicktype-core/language/CSharp.js +0 -1850
  105. package/dist/quicktype-core/language/Crystal.d.ts +0 -37
  106. package/dist/quicktype-core/language/Crystal.js +0 -337
  107. package/dist/quicktype-core/language/Dart.d.ts +0 -66
  108. package/dist/quicktype-core/language/Dart.js +0 -576
  109. package/dist/quicktype-core/language/Elm.d.ts +0 -58
  110. package/dist/quicktype-core/language/Elm.js +0 -522
  111. package/dist/quicktype-core/language/Golang.d.ts +0 -51
  112. package/dist/quicktype-core/language/Golang.js +0 -460
  113. package/dist/quicktype-core/language/Haskell.d.ts +0 -56
  114. package/dist/quicktype-core/language/Haskell.js +0 -411
  115. package/dist/quicktype-core/language/JSONSchema.d.ts +0 -31
  116. package/dist/quicktype-core/language/JSONSchema.js +0 -169
  117. package/dist/quicktype-core/language/Java.d.ts +0 -125
  118. package/dist/quicktype-core/language/Java.js +0 -1081
  119. package/dist/quicktype-core/language/JavaScript.d.ts +0 -68
  120. package/dist/quicktype-core/language/JavaScript.js +0 -435
  121. package/dist/quicktype-core/language/JavaScriptPropTypes.d.ts +0 -40
  122. package/dist/quicktype-core/language/JavaScriptPropTypes.js +0 -213
  123. package/dist/quicktype-core/language/JavaScriptUnicodeMaps.d.ts +0 -2
  124. package/dist/quicktype-core/language/JavaScriptUnicodeMaps.js +0 -134
  125. package/dist/quicktype-core/language/Kotlin.d.ts +0 -109
  126. package/dist/quicktype-core/language/Kotlin.js +0 -832
  127. package/dist/quicktype-core/language/Objective-C.d.ts +0 -79
  128. package/dist/quicktype-core/language/Objective-C.js +0 -777
  129. package/dist/quicktype-core/language/Php.d.ts +0 -80
  130. package/dist/quicktype-core/language/Php.js +0 -702
  131. package/dist/quicktype-core/language/Pike.d.ts +0 -37
  132. package/dist/quicktype-core/language/Pike.js +0 -276
  133. package/dist/quicktype-core/language/Python.d.ts +0 -107
  134. package/dist/quicktype-core/language/Python.js +0 -969
  135. package/dist/quicktype-core/language/Rust.d.ts +0 -56
  136. package/dist/quicktype-core/language/Rust.js +0 -309
  137. package/dist/quicktype-core/language/Swift.d.ts +0 -96
  138. package/dist/quicktype-core/language/Swift.js +0 -1211
  139. package/dist/quicktype-core/language/TypeScriptFlow.d.ts +0 -77
  140. package/dist/quicktype-core/language/TypeScriptFlow.js +0 -286
  141. package/dist/quicktype-core/language/ruby/index.d.ts +0 -52
  142. package/dist/quicktype-core/language/ruby/index.js +0 -557
  143. package/dist/quicktype-core/language/ruby/keywords.d.ts +0 -3
  144. package/dist/quicktype-core/language/ruby/keywords.js +0 -358
  145. package/dist/quicktype-core/rewrites/CombineClasses.d.ts +0 -3
  146. package/dist/quicktype-core/rewrites/CombineClasses.js +0 -125
  147. package/dist/quicktype-core/rewrites/ExpandStrings.d.ts +0 -4
  148. package/dist/quicktype-core/rewrites/ExpandStrings.js +0 -143
  149. package/dist/quicktype-core/rewrites/FlattenStrings.d.ts +0 -3
  150. package/dist/quicktype-core/rewrites/FlattenStrings.js +0 -45
  151. package/dist/quicktype-core/rewrites/FlattenUnions.d.ts +0 -3
  152. package/dist/quicktype-core/rewrites/FlattenUnions.js +0 -47
  153. package/dist/quicktype-core/rewrites/InferMaps.d.ts +0 -3
  154. package/dist/quicktype-core/rewrites/InferMaps.js +0 -117
  155. package/dist/quicktype-core/rewrites/ReplaceObjectType.d.ts +0 -3
  156. package/dist/quicktype-core/rewrites/ReplaceObjectType.js +0 -60
  157. package/dist/quicktype-core/rewrites/ResolveIntersections.d.ts +0 -3
  158. package/dist/quicktype-core/rewrites/ResolveIntersections.js +0 -244
  159. package/dist/quicktype-core/support/Acronyms.d.ts +0 -10
  160. package/dist/quicktype-core/support/Acronyms.js +0 -1128
  161. package/dist/quicktype-core/support/Chance.d.ts +0 -38
  162. package/dist/quicktype-core/support/Chance.js +0 -2146
  163. package/dist/quicktype-core/support/Converters.d.ts +0 -6
  164. package/dist/quicktype-core/support/Converters.js +0 -16
  165. package/dist/quicktype-core/support/Strings.d.ts +0 -44
  166. package/dist/quicktype-core/support/Strings.js +0 -525
  167. package/dist/quicktype-core/support/Support.d.ts +0 -29
  168. package/dist/quicktype-core/support/Support.js +0 -162
  169. package/dist/quicktype-graphql-input/GraphQLSchema.d.ts +0 -645
  170. package/dist/quicktype-graphql-input/GraphQLSchema.js +0 -39
  171. package/dist/quicktype-graphql-input/index.d.ts +0 -17
  172. package/dist/quicktype-graphql-input/index.js +0 -407
  173. package/dist/quicktype-typescript-input/index.d.ts +0 -2
  174. package/dist/quicktype-typescript-input/index.js +0 -98
@@ -1,668 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ConvenienceRenderer = exports.inferredNameOrder = exports.topLevelNameOrder = void 0;
4
- const collection_utils_1 = require("collection-utils");
5
- const Type_1 = require("./Type");
6
- const TypeUtils_1 = require("./TypeUtils");
7
- const Naming_1 = require("./Naming");
8
- const Renderer_1 = require("./Renderer");
9
- const Support_1 = require("./support/Support");
10
- const Strings_1 = require("./support/Strings");
11
- const Source_1 = require("./Source");
12
- const DeclarationIR_1 = require("./DeclarationIR");
13
- const TypeGraph_1 = require("./TypeGraph");
14
- const TypeAttributes_1 = require("./attributes/TypeAttributes");
15
- const Description_1 = require("./attributes/Description");
16
- const AccessorNames_1 = require("./attributes/AccessorNames");
17
- const Transformers_1 = require("./Transformers");
18
- const wordWrap = require("wordwrap")(90);
19
- exports.topLevelNameOrder = 1;
20
- const givenNameOrder = 10;
21
- exports.inferredNameOrder = 30;
22
- const classPropertyNameOrder = 20;
23
- const assignedClassPropertyNameOrder = 10;
24
- const enumCaseNameOrder = 20;
25
- const assignedEnumCaseNameOrder = 10;
26
- const unionMemberNameOrder = 40;
27
- function splitDescription(descriptions) {
28
- if (descriptions === undefined)
29
- return undefined;
30
- const description = Array.from(descriptions).join("\n\n").trim();
31
- if (description === "")
32
- return undefined;
33
- return wordWrap(description)
34
- .split("\n")
35
- .map(l => l.trim());
36
- }
37
- const assignedNameAttributeKind = new TypeAttributes_1.TypeAttributeKind("assignedName");
38
- const assignedPropertyNamesAttributeKind = new TypeAttributes_1.TypeAttributeKind("assignedPropertyNames");
39
- const assignedMemberNamesAttributeKind = new TypeAttributes_1.TypeAttributeKind("assignedMemberNames");
40
- const assignedCaseNamesAttributeKind = new TypeAttributes_1.TypeAttributeKind("assignedCaseNames");
41
- 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
- constructor(targetLanguage, renderContext) {
66
- super(targetLanguage, renderContext);
67
- }
68
- get topLevels() {
69
- return this.typeGraph.topLevels;
70
- }
71
- /**
72
- * Return an array of strings which are not allowed as names in the global
73
- * namespace. Since names of generated types are in the global namespace,
74
- * this will include anything built into the language or default libraries
75
- * that can conflict with that, such as reserved keywords or common type
76
- * names.
77
- */
78
- forbiddenNamesForGlobalNamespace() {
79
- return [];
80
- }
81
- /**
82
- * Returns which names are forbidden for the property names of an object
83
- * type. `names` can contain strings as well as `Name`s. In some
84
- * languages, the class name can't be used as the name for a property, for
85
- * example, in which case `_className` would have to be return in `names`.
86
- * If `includeGlobalForbidden` is set, then all names that are forbidden
87
- * in the global namespace will also be forbidden for the properties.
88
- * Note: That doesn't mean that the names in the global namespace will be
89
- * forbidden, too!
90
- */
91
- forbiddenForObjectProperties(_o, _className) {
92
- return { names: [], includeGlobalForbidden: false };
93
- }
94
- forbiddenForUnionMembers(_u, _unionName) {
95
- return { names: [], includeGlobalForbidden: false };
96
- }
97
- forbiddenForEnumCases(_e, _enumName) {
98
- return { names: [], includeGlobalForbidden: false };
99
- }
100
- makeTopLevelDependencyNames(_t, _topLevelName) {
101
- return [];
102
- }
103
- makeNamedTypeDependencyNames(_t, _name) {
104
- return [];
105
- }
106
- makeNameForTransformation(_xf, _typeName) {
107
- return undefined;
108
- }
109
- namedTypeToNameForTopLevel(type) {
110
- if ((0, TypeUtils_1.isNamedType)(type)) {
111
- return type;
112
- }
113
- return undefined;
114
- }
115
- get unionMembersInGlobalNamespace() {
116
- return false;
117
- }
118
- get enumCasesInGlobalNamespace() {
119
- return false;
120
- }
121
- get needsTypeDeclarationBeforeUse() {
122
- return false;
123
- }
124
- canBeForwardDeclared(_t) {
125
- return (0, Support_1.panic)("If needsTypeDeclarationBeforeUse returns true, canBeForwardDeclared must be implemented");
126
- }
127
- unionNeedsName(u) {
128
- return (0, TypeUtils_1.nullableFromUnion)(u) === null;
129
- }
130
- get globalNamespace() {
131
- return (0, Support_1.defined)(this._globalNamespace);
132
- }
133
- get nameStoreView() {
134
- return (0, Support_1.defined)(this._nameStoreView);
135
- }
136
- descriptionForType(t) {
137
- let description = this.typeGraph.attributeStore.tryGet(Description_1.descriptionTypeAttributeKind, t);
138
- return splitDescription(description);
139
- }
140
- descriptionForClassProperty(o, name) {
141
- const descriptions = this.typeGraph.attributeStore.tryGet(Description_1.propertyDescriptionsTypeAttributeKind, o);
142
- if (descriptions === undefined)
143
- return undefined;
144
- return splitDescription(descriptions.get(name));
145
- }
146
- setUpNaming() {
147
- this._nameStoreView = new TypeGraph_1.TypeAttributeStoreView(this.typeGraph.attributeStore, assignedNameAttributeKind);
148
- this._propertyNamesStoreView = new TypeGraph_1.TypeAttributeStoreView(this.typeGraph.attributeStore, assignedPropertyNamesAttributeKind);
149
- this._memberNamesStoreView = new TypeGraph_1.TypeAttributeStoreView(this.typeGraph.attributeStore, assignedMemberNamesAttributeKind);
150
- this._caseNamesStoreView = new TypeGraph_1.TypeAttributeStoreView(this.typeGraph.attributeStore, assignedCaseNamesAttributeKind);
151
- this._namesForTransformations = new Map();
152
- this._namedTypeNamer = this.makeNamedTypeNamer();
153
- this._unionMemberNamer = this.makeUnionMemberNamer();
154
- this._enumCaseNamer = this.makeEnumCaseNamer();
155
- this._globalForbiddenNamespace = (0, Naming_1.keywordNamespace)("forbidden", this.forbiddenNamesForGlobalNamespace());
156
- this._otherForbiddenNamespaces = new Map();
157
- this._globalNamespace = new Naming_1.Namespace("global", undefined, [this._globalForbiddenNamespace], []);
158
- const { objects, enums, unions } = this.typeGraph.allNamedTypesSeparated();
159
- const namedUnions = (0, collection_utils_1.setFilter)(unions, u => this.unionNeedsName(u));
160
- for (const [name, t] of this.topLevels) {
161
- this.nameStoreView.setForTopLevel(name, this.addNameForTopLevel(t, name));
162
- }
163
- for (const o of objects) {
164
- const name = this.addNameForNamedType(o);
165
- this.addPropertyNames(o, name);
166
- }
167
- for (const e of enums) {
168
- const name = this.addNameForNamedType(e);
169
- this.addEnumCaseNames(e, name);
170
- }
171
- for (const u of namedUnions) {
172
- const name = this.addNameForNamedType(u);
173
- this.addUnionMemberNames(u, name);
174
- }
175
- for (const t of this.typeGraph.allTypesUnordered()) {
176
- this.addNameForTransformation(t);
177
- }
178
- return (0, collection_utils_1.setUnion)([this._globalForbiddenNamespace, this._globalNamespace], this._otherForbiddenNamespaces.values());
179
- }
180
- addDependenciesForNamedType(type, named) {
181
- const dependencyNames = this.makeNamedTypeDependencyNames(type, named);
182
- for (const dn of dependencyNames) {
183
- this.globalNamespace.add(dn);
184
- }
185
- }
186
- makeNameForTopLevel(_t, givenName, _maybeNamedType) {
187
- return new Naming_1.SimpleName([givenName], (0, Support_1.defined)(this._namedTypeNamer), exports.topLevelNameOrder);
188
- }
189
- addNameForTopLevel(type, givenName) {
190
- const maybeNamedType = this.namedTypeToNameForTopLevel(type);
191
- const name = this.makeNameForTopLevel(type, givenName, maybeNamedType);
192
- this.globalNamespace.add(name);
193
- const dependencyNames = this.makeTopLevelDependencyNames(type, name);
194
- for (const dn of dependencyNames) {
195
- this.globalNamespace.add(dn);
196
- }
197
- if (maybeNamedType !== undefined) {
198
- this.addDependenciesForNamedType(maybeNamedType, name);
199
- this.nameStoreView.set(maybeNamedType, name);
200
- }
201
- return name;
202
- }
203
- makeNameForType(t, namer, givenOrder, inferredOrder) {
204
- const names = t.getNames();
205
- const order = names.areInferred ? inferredOrder : givenOrder;
206
- return new Naming_1.SimpleName(names.proposedNames, namer, order);
207
- }
208
- makeNameForNamedType(t) {
209
- return this.makeNameForType(t, (0, Support_1.defined)(this._namedTypeNamer), givenNameOrder, exports.inferredNameOrder);
210
- }
211
- addNameForNamedType(type) {
212
- const existing = this.nameStoreView.tryGet(type);
213
- if (existing !== undefined)
214
- return existing;
215
- const name = this.globalNamespace.add(this.makeNameForNamedType(type));
216
- this.addDependenciesForNamedType(type, name);
217
- this.nameStoreView.set(type, name);
218
- return name;
219
- }
220
- get typesWithNamedTransformations() {
221
- return (0, Support_1.defined)(this._namesForTransformations);
222
- }
223
- nameForTransformation(t) {
224
- const xf = (0, Transformers_1.transformationForType)(t);
225
- if (xf === undefined)
226
- return undefined;
227
- const name = (0, Support_1.defined)(this._namesForTransformations).get(t);
228
- if (name === undefined) {
229
- return (0, Support_1.panic)("No name for transformation");
230
- }
231
- return name;
232
- }
233
- addNameForTransformation(t) {
234
- const xf = (0, Transformers_1.transformationForType)(t);
235
- if (xf === undefined)
236
- return;
237
- (0, Support_1.assert)((0, Support_1.defined)(this._namesForTransformations).get(t) === undefined, "Tried to give two names to the same transformation");
238
- const name = this.makeNameForTransformation(xf, this.nameStoreView.tryGet(xf.targetType));
239
- if (name === undefined)
240
- return;
241
- this.globalNamespace.add(name);
242
- (0, Support_1.defined)(this._namesForTransformations).set(t, name);
243
- }
244
- processForbiddenWordsInfo(info, namespaceName) {
245
- const forbiddenNames = [];
246
- const forbiddenStrings = [];
247
- for (const nameOrString of info.names) {
248
- if (typeof nameOrString === "string") {
249
- forbiddenStrings.push(nameOrString);
250
- }
251
- else {
252
- forbiddenNames.push(nameOrString);
253
- }
254
- }
255
- let namespace = (0, Support_1.defined)(this._otherForbiddenNamespaces).get(namespaceName);
256
- if (forbiddenStrings.length > 0 && namespace === undefined) {
257
- namespace = (0, Naming_1.keywordNamespace)(namespaceName, forbiddenStrings);
258
- this._otherForbiddenNamespaces = (0, Support_1.defined)(this._otherForbiddenNamespaces).set(namespaceName, namespace);
259
- }
260
- let forbiddenNamespaces = new Set();
261
- if (info.includeGlobalForbidden) {
262
- forbiddenNamespaces = forbiddenNamespaces.add((0, Support_1.defined)(this._globalForbiddenNamespace));
263
- }
264
- if (namespace !== undefined) {
265
- forbiddenNamespaces = forbiddenNamespaces.add(namespace);
266
- }
267
- return { forbiddenNames: new Set(forbiddenNames), forbiddenNamespaces };
268
- }
269
- makeNameForProperty(o, _className, p, jsonName, assignedName) {
270
- const namer = this.namerForObjectProperty(o, p);
271
- if (namer === null)
272
- return undefined;
273
- // FIXME: This alternative should really depend on what the
274
- // actual name of the class ends up being. We can do this
275
- // with a DependencyName.
276
- // Also, we currently don't have any languages where properties
277
- // are global, so collisions here could only occur where two
278
- // properties of the same class have the same name, in which case
279
- // the alternative would also be the same, i.e. useless. But
280
- // maybe we'll need global properties for some weird language at
281
- // some point.
282
- const alternative = `${o.getCombinedName()}_${jsonName}`;
283
- const order = assignedName === undefined ? classPropertyNameOrder : assignedClassPropertyNameOrder;
284
- const names = assignedName === undefined ? [jsonName, alternative] : [assignedName];
285
- return new Naming_1.SimpleName(names, namer, order);
286
- }
287
- makePropertyDependencyNames(_o, _className, _p, _jsonName, _name) {
288
- return [];
289
- }
290
- addPropertyNames(o, className) {
291
- const { forbiddenNames, forbiddenNamespaces } = this.processForbiddenWordsInfo(this.forbiddenForObjectProperties(o, className), "forbidden-for-properties");
292
- let ns;
293
- const accessorNames = (0, AccessorNames_1.objectPropertyNames)(o, this.targetLanguage.name);
294
- const names = (0, collection_utils_1.mapFilterMap)(o.getSortedProperties(), (p, jsonName) => {
295
- const [assignedName, isFixed] = (0, AccessorNames_1.getAccessorName)(accessorNames, jsonName);
296
- let name;
297
- if (isFixed) {
298
- name = new Naming_1.FixedName((0, Support_1.defined)(assignedName));
299
- }
300
- else {
301
- name = this.makeNameForProperty(o, className, p, jsonName, assignedName);
302
- }
303
- if (name === undefined)
304
- return undefined;
305
- if (ns === undefined) {
306
- ns = new Naming_1.Namespace(o.getCombinedName(), this.globalNamespace, forbiddenNamespaces, forbiddenNames);
307
- }
308
- ns.add(name);
309
- for (const depName of this.makePropertyDependencyNames(o, className, p, jsonName, name)) {
310
- ns.add(depName);
311
- }
312
- return name;
313
- });
314
- (0, Support_1.defined)(this._propertyNamesStoreView).set(o, names);
315
- }
316
- makeNameForUnionMember(u, unionName, t) {
317
- const [assignedName, isFixed] = (0, AccessorNames_1.unionMemberName)(u, t, this.targetLanguage.name);
318
- if (isFixed) {
319
- return new Naming_1.FixedName((0, Support_1.defined)(assignedName));
320
- }
321
- return new Naming_1.DependencyName((0, Support_1.nonNull)(this._unionMemberNamer), unionMemberNameOrder, lookup => {
322
- if (assignedName !== undefined)
323
- return assignedName;
324
- return this.proposeUnionMemberName(u, unionName, t, lookup);
325
- });
326
- }
327
- addUnionMemberNames(u, unionName) {
328
- const memberNamer = this._unionMemberNamer;
329
- if (memberNamer === null)
330
- return;
331
- const { forbiddenNames, forbiddenNamespaces } = this.processForbiddenWordsInfo(this.forbiddenForUnionMembers(u, unionName), "forbidden-for-union-members");
332
- let ns;
333
- if (this.unionMembersInGlobalNamespace) {
334
- ns = this.globalNamespace;
335
- }
336
- else {
337
- ns = new Naming_1.Namespace(u.getCombinedName(), this.globalNamespace, forbiddenNamespaces, forbiddenNames);
338
- }
339
- let names = new Map();
340
- for (const t of u.members) {
341
- const name = this.makeNameForUnionMember(u, unionName, (0, Transformers_1.followTargetType)(t));
342
- names.set(t, ns.add(name));
343
- }
344
- (0, Support_1.defined)(this._memberNamesStoreView).set(u, names);
345
- }
346
- makeNameForEnumCase(e, _enumName, caseName, assignedName) {
347
- // FIXME: See the FIXME in `makeNameForProperty`. We do have global
348
- // enum cases, though (in Go), so this is actually useful already.
349
- const alternative = `${e.getCombinedName()}_${caseName}`;
350
- const order = assignedName === undefined ? enumCaseNameOrder : assignedEnumCaseNameOrder;
351
- const names = assignedName === undefined ? [caseName, alternative] : [assignedName];
352
- return new Naming_1.SimpleName(names, (0, Support_1.nonNull)(this._enumCaseNamer), order);
353
- }
354
- // FIXME: this is very similar to addPropertyNameds and addUnionMemberNames
355
- addEnumCaseNames(e, enumName) {
356
- if (this._enumCaseNamer === null)
357
- return;
358
- const { forbiddenNames, forbiddenNamespaces } = this.processForbiddenWordsInfo(this.forbiddenForEnumCases(e, enumName), "forbidden-for-enum-cases");
359
- let ns;
360
- if (this.enumCasesInGlobalNamespace) {
361
- ns = this.globalNamespace;
362
- }
363
- else {
364
- ns = new Naming_1.Namespace(e.getCombinedName(), this.globalNamespace, forbiddenNamespaces, forbiddenNames);
365
- }
366
- let names = new Map();
367
- const accessorNames = (0, AccessorNames_1.enumCaseNames)(e, this.targetLanguage.name);
368
- for (const caseName of e.cases) {
369
- const [assignedName, isFixed] = (0, AccessorNames_1.getAccessorName)(accessorNames, caseName);
370
- let name;
371
- if (isFixed) {
372
- name = new Naming_1.FixedName((0, Support_1.defined)(assignedName));
373
- }
374
- else {
375
- name = this.makeNameForEnumCase(e, enumName, caseName, assignedName);
376
- }
377
- names.set(caseName, ns.add(name));
378
- }
379
- (0, Support_1.defined)(this._caseNamesStoreView).set(e, names);
380
- }
381
- childrenOfType(t) {
382
- const names = this.names;
383
- if (t instanceof Type_1.ClassType) {
384
- const propertyNameds = (0, Support_1.defined)(this._propertyNamesStoreView).get(t);
385
- const filteredMap = (0, collection_utils_1.mapFilterMap)(t.getProperties(), (p, n) => {
386
- if (propertyNameds.get(n) === undefined)
387
- return undefined;
388
- return p.type;
389
- });
390
- const sortedMap = (0, collection_utils_1.mapSortBy)(filteredMap, (_, n) => (0, Support_1.defined)(names.get((0, Support_1.defined)(propertyNameds.get(n)))));
391
- return new Set(sortedMap.values());
392
- }
393
- return t.getChildren();
394
- }
395
- get namedUnions() {
396
- return (0, Support_1.defined)(this._namedUnions);
397
- }
398
- get haveNamedUnions() {
399
- return this.namedUnions.size > 0;
400
- }
401
- get haveNamedTypes() {
402
- return (0, Support_1.defined)(this._namedTypes).length > 0;
403
- }
404
- get haveUnions() {
405
- return (0, Support_1.defined)(this._haveUnions);
406
- }
407
- get haveMaps() {
408
- return (0, Support_1.defined)(this._haveMaps);
409
- }
410
- get haveOptionalProperties() {
411
- return (0, Support_1.defined)(this._haveOptionalProperties);
412
- }
413
- // FIXME: Inconsistently named, though technically correct. Right now all enums are named,
414
- // but this should really be called `namedEnums`.
415
- get enums() {
416
- return (0, Support_1.defined)(this._namedEnums);
417
- }
418
- get haveEnums() {
419
- return this.enums.size > 0;
420
- }
421
- proposedUnionMemberNameForTypeKind(_kind) {
422
- return null;
423
- }
424
- proposeUnionMemberName(_u, _unionName, fieldType, lookup) {
425
- const simpleName = this.proposedUnionMemberNameForTypeKind(fieldType.kind);
426
- if (simpleName !== null) {
427
- return simpleName;
428
- }
429
- const typeNameForUnionMember = (t) => (0, TypeUtils_1.matchTypeExhaustive)(t, _noneType => {
430
- return (0, Support_1.panic)("none type should have been replaced");
431
- }, _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
- (0, Support_1.assert)(this.targetLanguage.supportsFullObjectType, "Object type should have been replaced in `replaceObjectType`");
433
- return lookup(this.nameForNamedType(objectType));
434
- }, _enumType => "enum", _unionType => "union", transformedType => transformedType.kind.replace("-", "_"));
435
- return typeNameForUnionMember(fieldType);
436
- }
437
- nameForNamedType(t) {
438
- return this.nameStoreView.get(t);
439
- }
440
- isForwardDeclaredType(t) {
441
- return (0, Support_1.defined)(this._declarationIR).forwardedTypes.has(t);
442
- }
443
- isImplicitCycleBreaker(_t) {
444
- return (0, Support_1.panic)("A renderer that invokes isCycleBreakerType must implement isImplicitCycleBreaker");
445
- }
446
- canBreakCycles(_t) {
447
- return true;
448
- }
449
- isCycleBreakerType(t) {
450
- if (this._cycleBreakerTypes === undefined) {
451
- this._cycleBreakerTypes = (0, DeclarationIR_1.cycleBreakerTypesForGraph)(this.typeGraph, s => this.isImplicitCycleBreaker(s), s => this.canBreakCycles(s));
452
- }
453
- return this._cycleBreakerTypes.has(t);
454
- }
455
- forEachTopLevel(blankLocations, f, predicate) {
456
- let topLevels;
457
- if (predicate !== undefined) {
458
- topLevels = (0, collection_utils_1.mapFilter)(this.topLevels, predicate);
459
- }
460
- else {
461
- topLevels = this.topLevels;
462
- }
463
- return this.forEachWithBlankLines(topLevels, blankLocations, (t, name, pos) => f(t, this.nameStoreView.getForTopLevel(name), pos));
464
- }
465
- forEachDeclaration(blankLocations, f) {
466
- this.forEachWithBlankLines((0, collection_utils_1.iterableEnumerate)((0, Support_1.defined)(this._declarationIR).declarations), blankLocations, (decl, _, pos) => f(decl, pos));
467
- }
468
- setAlphabetizeProperties(value) {
469
- this._alphabetizeProperties = value;
470
- }
471
- getAlphabetizeProperties() {
472
- return this._alphabetizeProperties;
473
- }
474
- // Returns the number of properties defined for the specified object type.
475
- propertyCount(o) {
476
- const propertyNames = (0, Support_1.defined)(this._propertyNamesStoreView).get(o);
477
- return propertyNames.size;
478
- }
479
- sortClassProperties(properties, propertyNames) {
480
- if (this._alphabetizeProperties) {
481
- return (0, collection_utils_1.mapSortBy)(properties, (_p, jsonName) => {
482
- const name = (0, Support_1.defined)(propertyNames.get(jsonName));
483
- return (0, Support_1.defined)(this.names.get(name));
484
- });
485
- }
486
- else {
487
- return properties;
488
- }
489
- }
490
- forEachClassProperty(o, blankLocations, f) {
491
- const propertyNames = (0, Support_1.defined)(this._propertyNamesStoreView).get(o);
492
- const sortedProperties = this.sortClassProperties(o.getProperties(), propertyNames);
493
- this.forEachWithBlankLines(sortedProperties, blankLocations, (p, jsonName, pos) => {
494
- const name = (0, Support_1.defined)(propertyNames.get(jsonName));
495
- f(name, jsonName, p, pos);
496
- });
497
- }
498
- nameForUnionMember(u, t) {
499
- return (0, Support_1.defined)((0, Support_1.defined)(this._memberNamesStoreView).get(u).get(t));
500
- }
501
- nameForEnumCase(e, caseName) {
502
- const caseNames = (0, Support_1.defined)(this._caseNamesStoreView).get(e);
503
- return (0, Support_1.defined)(caseNames.get(caseName));
504
- }
505
- forEachUnionMember(u, members, blankLocations, sortOrder, f) {
506
- const iterateMembers = members === null ? u.members : members;
507
- if (sortOrder === null) {
508
- sortOrder = n => (0, Support_1.defined)(this.names.get(n));
509
- }
510
- const memberNames = (0, collection_utils_1.mapFilter)((0, Support_1.defined)(this._memberNamesStoreView).get(u), (_, t) => iterateMembers.has(t));
511
- const sortedMemberNames = (0, collection_utils_1.mapSortBy)(memberNames, sortOrder);
512
- this.forEachWithBlankLines(sortedMemberNames, blankLocations, f);
513
- }
514
- forEachEnumCase(e, blankLocations, f) {
515
- const caseNames = (0, Support_1.defined)(this._caseNamesStoreView).get(e);
516
- const sortedCaseNames = (0, collection_utils_1.mapSortBy)(caseNames, n => (0, Support_1.defined)(this.names.get(n)));
517
- this.forEachWithBlankLines(sortedCaseNames, blankLocations, f);
518
- }
519
- forEachTransformation(blankLocations, f) {
520
- this.forEachWithBlankLines((0, Support_1.defined)(this._namesForTransformations), blankLocations, f);
521
- }
522
- forEachSpecificNamedType(blankLocations, types, f) {
523
- this.forEachWithBlankLines(types, blankLocations, (t, _, pos) => f(t, this.nameForNamedType(t), pos));
524
- }
525
- forEachObject(blankLocations, f) {
526
- // FIXME: This is ugly.
527
- this.forEachSpecificNamedType(blankLocations, (0, Support_1.defined)(this._namedObjects).entries(), f);
528
- }
529
- forEachEnum(blankLocations, f) {
530
- this.forEachSpecificNamedType(blankLocations, this.enums.entries(), f);
531
- }
532
- forEachUnion(blankLocations, f) {
533
- this.forEachSpecificNamedType(blankLocations, this.namedUnions.entries(), f);
534
- }
535
- forEachUniqueUnion(blankLocations, uniqueValue, f) {
536
- const firstUnionByValue = new Map();
537
- for (const u of this.namedUnions) {
538
- const v = uniqueValue(u);
539
- if (!firstUnionByValue.has(v)) {
540
- firstUnionByValue.set(v, u);
541
- }
542
- }
543
- this.forEachWithBlankLines(firstUnionByValue, blankLocations, f);
544
- }
545
- forEachNamedType(blankLocations, objectFunc, enumFunc, unionFunc) {
546
- this.forEachWithBlankLines((0, Support_1.defined)(this._namedTypes).entries(), blankLocations, (t, _, pos) => {
547
- const name = this.nameForNamedType(t);
548
- if (t instanceof Type_1.ObjectType) {
549
- // FIXME: This is ugly. We can't runtime check that the function
550
- // takes full object types if we have them.
551
- objectFunc(t, name, pos);
552
- }
553
- else if (t instanceof Type_1.EnumType) {
554
- enumFunc(t, name, pos);
555
- }
556
- else if (t instanceof Type_1.UnionType) {
557
- unionFunc(t, name, pos);
558
- }
559
- else {
560
- return (0, Support_1.panic)("Named type that's neither a class nor union");
561
- }
562
- });
563
- }
564
- // You should never have to use this to produce parts of your generated
565
- // code. If you need to modify a Name, for example to change its casing,
566
- // use `modifySource`.
567
- sourcelikeToString(src) {
568
- return (0, Source_1.serializeRenderResult)((0, Source_1.sourcelikeToSource)(src), this.names, "").lines.join("\n");
569
- }
570
- get commentLineStart() {
571
- return "// ";
572
- }
573
- emitCommentLines(lines, lineStart, beforeLine, afterLine, firstLineStart) {
574
- if (lineStart === undefined) {
575
- lineStart = this.commentLineStart;
576
- }
577
- if (firstLineStart === undefined) {
578
- firstLineStart = lineStart;
579
- }
580
- if (beforeLine !== undefined) {
581
- this.emitLine(beforeLine);
582
- }
583
- let first = true;
584
- for (const line of lines) {
585
- let start = first ? firstLineStart : lineStart;
586
- if (this.sourcelikeToString(line) === "") {
587
- start = (0, Strings_1.trimEnd)(start);
588
- }
589
- this.emitLine(start, line);
590
- first = false;
591
- }
592
- if (afterLine !== undefined) {
593
- this.emitLine(afterLine);
594
- }
595
- }
596
- emitDescription(description) {
597
- if (description === undefined)
598
- return;
599
- // FIXME: word-wrap
600
- this.emitDescriptionBlock(description);
601
- }
602
- emitDescriptionBlock(lines) {
603
- this.emitCommentLines(lines);
604
- }
605
- emitPropertyTable(c, makePropertyRow) {
606
- let table = [];
607
- const emitTable = () => {
608
- if (table.length === 0)
609
- return;
610
- this.emitTable(table);
611
- table = [];
612
- };
613
- this.forEachClassProperty(c, "none", (name, jsonName, p) => {
614
- const description = this.descriptionForClassProperty(c, jsonName);
615
- if (description !== undefined) {
616
- emitTable();
617
- this.emitDescription(description);
618
- }
619
- table.push(makePropertyRow(name, jsonName, p));
620
- });
621
- emitTable();
622
- }
623
- processGraph() {
624
- this._declarationIR = (0, DeclarationIR_1.declarationsForGraph)(this.typeGraph, this.needsTypeDeclarationBeforeUse ? t => this.canBeForwardDeclared(t) : undefined, t => this.childrenOfType(t), t => {
625
- if (t instanceof Type_1.UnionType) {
626
- return this.unionNeedsName(t);
627
- }
628
- return (0, TypeUtils_1.isNamedType)(t);
629
- });
630
- const types = this.typeGraph.allTypesUnordered();
631
- this._haveUnions = (0, collection_utils_1.iterableSome)(types, t => t instanceof Type_1.UnionType);
632
- this._haveMaps = (0, collection_utils_1.iterableSome)(types, t => t instanceof Type_1.MapType);
633
- const classTypes = (0, collection_utils_1.setFilter)(types, t => t instanceof Type_1.ClassType);
634
- this._haveOptionalProperties = (0, collection_utils_1.iterableSome)(classTypes, c => (0, collection_utils_1.mapSome)(c.getProperties(), p => p.isOptional));
635
- this._namedTypes = this._declarationIR.declarations.filter(d => d.kind === "define").map(d => d.type);
636
- const { objects, enums, unions } = (0, TypeUtils_1.separateNamedTypes)(this._namedTypes);
637
- this._namedObjects = new Set(objects);
638
- this._namedEnums = new Set(enums);
639
- this._namedUnions = new Set(unions);
640
- }
641
- emitSource(givenOutputFilename) {
642
- this.processGraph();
643
- this.emitSourceStructure(givenOutputFilename);
644
- }
645
- forEachType(process) {
646
- const visitedTypes = new Set();
647
- const processed = new Set();
648
- const queue = Array.from(this.typeGraph.topLevels.values());
649
- function visit(t) {
650
- if (visitedTypes.has(t))
651
- return;
652
- for (const c of t.getChildren()) {
653
- queue.push(c);
654
- }
655
- visitedTypes.add(t);
656
- processed.add(process(t));
657
- }
658
- for (;;) {
659
- const maybeType = queue.pop();
660
- if (maybeType === undefined) {
661
- break;
662
- }
663
- visit(maybeType);
664
- }
665
- return processed;
666
- }
667
- }
668
- exports.ConvenienceRenderer = ConvenienceRenderer;
@@ -1,10 +0,0 @@
1
- export interface DateTimeRecognizer {
2
- isDate(s: string): boolean;
3
- isTime(s: string): boolean;
4
- isDateTime(s: string): boolean;
5
- }
6
- export declare class DefaultDateTimeRecognizer implements DateTimeRecognizer {
7
- isDate(str: string): boolean;
8
- isTime(str: string): boolean;
9
- isDateTime(str: string): boolean;
10
- }