quicktype 18.0.6 → 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,47 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.flattenUnions = void 0;
4
- const collection_utils_1 = require("collection-utils");
5
- const TypeGraph_1 = require("../TypeGraph");
6
- const Type_1 = require("../Type");
7
- const TypeUtils_1 = require("../TypeUtils");
8
- const Support_1 = require("../support/Support");
9
- const UnifyClasses_1 = require("../UnifyClasses");
10
- const Messages_1 = require("../Messages");
11
- const TypeAttributes_1 = require("../attributes/TypeAttributes");
12
- function flattenUnions(graph, stringTypeMapping, conflateNumbers, makeObjectTypes, debugPrintReconstitution) {
13
- let needsRepeat = false;
14
- function replace(types, builder, forwardingRef) {
15
- const unionBuilder = new UnifyClasses_1.UnifyUnionBuilder(builder, makeObjectTypes, true, trefs => {
16
- (0, Support_1.assert)(trefs.length > 0, "Must have at least one type to build union");
17
- trefs = trefs.map(tref => builder.reconstituteType((0, TypeGraph_1.derefTypeRef)(tref, graph)));
18
- if (trefs.length === 1) {
19
- return trefs[0];
20
- }
21
- needsRepeat = true;
22
- return builder.getUnionType(TypeAttributes_1.emptyTypeAttributes, new Set(trefs));
23
- });
24
- return (0, UnifyClasses_1.unifyTypes)(types, TypeAttributes_1.emptyTypeAttributes, builder, unionBuilder, conflateNumbers, forwardingRef);
25
- }
26
- const allUnions = (0, collection_utils_1.setFilter)(graph.allTypesUnordered(), t => t instanceof Type_1.UnionType);
27
- const nonCanonicalUnions = (0, collection_utils_1.setFilter)(allUnions, u => !u.isCanonical);
28
- let foundIntersection = false;
29
- const groups = (0, TypeUtils_1.makeGroupsToFlatten)(nonCanonicalUnions, members => {
30
- (0, Messages_1.messageAssert)(members.size > 0, "IRNoEmptyUnions", {});
31
- if (!(0, collection_utils_1.iterableSome)(members, m => m instanceof Type_1.IntersectionType))
32
- return true;
33
- // FIXME: This is stupid. `flattenUnions` returns true when no more union
34
- // flattening is necessary, but `resolveIntersections` can introduce new
35
- // unions that might require flattening, so now `flattenUnions` needs to take
36
- // that into account. Either change `resolveIntersections` such that it
37
- // doesn't introduce non-canonical unions (by using `unifyTypes`), or have
38
- // some other way to tell whether more work is needed that doesn't require
39
- // the two passes to know about each other.
40
- foundIntersection = true;
41
- return false;
42
- });
43
- graph = graph.rewrite("flatten unions", stringTypeMapping, false, groups, debugPrintReconstitution, replace);
44
- // console.log(`flattened ${nonCanonicalUnions.size} of ${unions.size} unions`);
45
- return [graph, !needsRepeat && !foundIntersection];
46
- }
47
- exports.flattenUnions = flattenUnions;
@@ -1,3 +0,0 @@
1
- import { TypeGraph } from "../TypeGraph";
2
- import { StringTypeMapping } from "../TypeBuilder";
3
- export declare function inferMaps(graph: TypeGraph, stringTypeMapping: StringTypeMapping, conflateNumbers: boolean, debugPrintReconstitution: boolean): TypeGraph;
@@ -1,117 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.inferMaps = void 0;
4
- const collection_utils_1 = require("collection-utils");
5
- const Type_1 = require("../Type");
6
- const TypeUtils_1 = require("../TypeUtils");
7
- const Support_1 = require("../support/Support");
8
- const UnifyClasses_1 = require("../UnifyClasses");
9
- const MarkovChain_1 = require("../MarkovChain");
10
- const mapSizeThreshold = 20;
11
- const stringMapSizeThreshold = 50;
12
- let markovChain = undefined;
13
- function nameProbability(name) {
14
- if (markovChain === undefined) {
15
- markovChain = (0, MarkovChain_1.load)();
16
- }
17
- return (0, MarkovChain_1.evaluate)(markovChain, name);
18
- }
19
- function shouldBeMap(properties) {
20
- // Only classes with a certain number of properties are inferred
21
- // as maps.
22
- const numProperties = properties.size;
23
- if (numProperties < 2)
24
- return undefined;
25
- // If all property names are digit-only, we always make a map, no
26
- // questions asked.
27
- if ((0, collection_utils_1.iterableEvery)(properties.keys(), n => /^[0-9]+$/.test(n))) {
28
- return (0, collection_utils_1.setMap)(properties.values(), cp => cp.type);
29
- }
30
- // If all properties are strings or null then an object must have at least
31
- // `stringMapSizeThreshold` to qualify as a map.
32
- if (numProperties < stringMapSizeThreshold &&
33
- (0, collection_utils_1.iterableEvery)(properties.values(), cp => (0, Type_1.isPrimitiveStringTypeKind)(cp.type.kind) || cp.type.kind === "null")) {
34
- return undefined;
35
- }
36
- if (numProperties < mapSizeThreshold) {
37
- const names = Array.from(properties.keys());
38
- const probabilities = names.map(nameProbability);
39
- const product = probabilities.reduce((a, b) => a * b, 1);
40
- const probability = Math.pow(product, 1 / numProperties);
41
- // The idea behind this is to have a probability around 0.0025 for
42
- // n=1, up to around 1.0 for n=20. I.e. when we only have a few
43
- // properties, they need to look really weird to infer a map, but
44
- // when we have more we'll accept more ordinary names. The details
45
- // of the formula are immaterial because I pulled it out of my ass.
46
- // FIXME: Use different exponents and start values depending on
47
- // the property type kind. For string properties, for example, we
48
- // should be more conservative, with class properties more
49
- // aggressive. An exponent of 6 is probably good for string
50
- // properties, and maybe a start value of 0.002, whereas for classes
51
- // we want maybe 0.004 and 5, or maybe something even more
52
- // trigger-happy.
53
- const exponent = 5;
54
- const scale = Math.pow(22, exponent);
55
- const limit = Math.pow(numProperties + 2, exponent) / scale + (0.0025 - Math.pow(3, exponent) / scale);
56
- if (probability > limit)
57
- return undefined;
58
- }
59
- // FIXME: simplify this - it's no longer necessary with the new
60
- // class properties.
61
- // We need to handle three cases for maps (and the fourth case
62
- // where we leave the class as is):
63
- //
64
- // 1. All property types are null.
65
- // 2. Some property types are null or nullable.
66
- // 3. No property types are null or nullable.
67
- let firstNonNullCases = undefined;
68
- const allCases = new Set();
69
- let canBeMap = true;
70
- // Check that all the property types are the same, modulo nullability.
71
- for (const [, p] of properties) {
72
- // The set of types first property can be, minus null.
73
- const nn = (0, TypeUtils_1.removeNullFromType)(p.type)[1];
74
- if (nn.size > 0) {
75
- if (firstNonNullCases !== undefined) {
76
- // The set of non-null cases for all other properties must
77
- // be the the same, otherwise we won't infer a map.
78
- if (!(0, Type_1.setOperationCasesEqual)(nn, firstNonNullCases, true, (a, b) => a.structurallyCompatible(b, true))) {
79
- canBeMap = false;
80
- break;
81
- }
82
- }
83
- else {
84
- firstNonNullCases = nn;
85
- }
86
- }
87
- allCases.add(p.type);
88
- }
89
- if (!canBeMap) {
90
- return undefined;
91
- }
92
- return allCases;
93
- }
94
- function inferMaps(graph, stringTypeMapping, conflateNumbers, debugPrintReconstitution) {
95
- function replaceClass(setOfOneClass, builder, forwardingRef) {
96
- const c = (0, Support_1.defined)((0, collection_utils_1.iterableFirst)(setOfOneClass));
97
- const properties = c.getProperties();
98
- const shouldBe = shouldBeMap(properties);
99
- if (shouldBe === undefined) {
100
- return (0, Support_1.panic)(`We shouldn't be replacing class ${c.getCombinedName()} with a map`);
101
- }
102
- // Now reconstitute all the types in the new graph. TypeGraphs are
103
- // immutable, so any change in the graph actually means building a new
104
- // graph, and the types in the new graph are different objects.
105
- // Reconstituting a type means generating the "same" type in the new
106
- // type graph. Except we don't get Type objects but TypeRef objects,
107
- // which is a type-to-be.
108
- return builder.getMapType(c.getAttributes(), (0, UnifyClasses_1.unifyTypes)(shouldBe, c.getAttributes(), builder, (0, UnifyClasses_1.unionBuilderForUnification)(builder, false, false, conflateNumbers), conflateNumbers), forwardingRef);
109
- }
110
- const classesToReplace = Array.from(graph.allNamedTypesSeparated().objects).filter(o => {
111
- if (!(o instanceof Type_1.ClassType))
112
- return false;
113
- return !o.isFixed && shouldBeMap(o.getProperties()) !== undefined;
114
- });
115
- return graph.rewrite("infer maps", stringTypeMapping, false, classesToReplace.map(c => [c]), debugPrintReconstitution, replaceClass);
116
- }
117
- exports.inferMaps = inferMaps;
@@ -1,3 +0,0 @@
1
- import { TypeGraph } from "../TypeGraph";
2
- import { StringTypeMapping } from "../TypeBuilder";
3
- export declare function replaceObjectType(graph: TypeGraph, stringTypeMapping: StringTypeMapping, _conflateNumbers: boolean, leaveFullObjects: boolean, debugPrintReconstitution: boolean): TypeGraph;
@@ -1,60 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.replaceObjectType = void 0;
4
- const collection_utils_1 = require("collection-utils");
5
- const Support_1 = require("../support/Support");
6
- const TypeAttributes_1 = require("../attributes/TypeAttributes");
7
- function replaceObjectType(graph, stringTypeMapping, _conflateNumbers, leaveFullObjects, debugPrintReconstitution) {
8
- function replace(setOfOneType, builder, forwardingRef) {
9
- const o = (0, Support_1.defined)((0, collection_utils_1.iterableFirst)(setOfOneType));
10
- const attributes = o.getAttributes();
11
- const properties = o.getProperties();
12
- const additionalProperties = o.getAdditionalProperties();
13
- function reconstituteProperties() {
14
- return (0, collection_utils_1.mapMap)(properties, cp => builder.makeClassProperty(builder.reconstituteTypeRef(cp.typeRef), cp.isOptional));
15
- }
16
- function makeClass() {
17
- return builder.getUniqueClassType(attributes, true, reconstituteProperties(), forwardingRef);
18
- }
19
- function reconstituteAdditionalProperties() {
20
- return builder.reconstituteType((0, Support_1.defined)(additionalProperties));
21
- }
22
- if (additionalProperties === undefined) {
23
- return makeClass();
24
- }
25
- if (properties.size === 0) {
26
- return builder.getMapType(attributes, reconstituteAdditionalProperties(), forwardingRef);
27
- }
28
- if (additionalProperties.kind === "any") {
29
- // FIXME: Warn that we're losing additional property semantics.
30
- builder.setLostTypeAttributes();
31
- return makeClass();
32
- }
33
- // FIXME: Warn that we're losing class semantics.
34
- const propertyTypes = (0, collection_utils_1.setMap)(properties.values(), cp => cp.type).add(additionalProperties);
35
- let union = builder.lookupTypeRefs(Array.from(propertyTypes).map(t => t.typeRef));
36
- if (union === undefined) {
37
- const reconstitutedTypes = (0, collection_utils_1.setMap)(propertyTypes, t => builder.reconstituteType(t));
38
- union = builder.getUniqueUnionType(TypeAttributes_1.emptyTypeAttributes, new Set(reconstitutedTypes));
39
- // This is the direct unification alternative. Weirdly enough, it is a tiny
40
- // bit slower. It gives the same results.
41
- /*
42
- union = unifyTypes(
43
- propertyTypes,
44
- combineTypeAttributes(propertyTypes.toArray().map(t => t.getAttributes())),
45
- builder,
46
- unionBuilderForUnification(builder, false, false, false, conflateNumbers),
47
- conflateNumbers
48
- );
49
- */
50
- }
51
- return builder.getMapType(attributes, union, forwardingRef);
52
- }
53
- const allObjectTypes = (0, collection_utils_1.setFilter)(graph.allTypesUnordered(), t => t.kind === "object");
54
- const objectTypesToReplace = leaveFullObjects
55
- ? (0, collection_utils_1.setFilter)(allObjectTypes, o => o.getProperties().size === 0 || o.getAdditionalProperties() === undefined)
56
- : allObjectTypes;
57
- const groups = Array.from(objectTypesToReplace).map(t => [t]);
58
- return graph.rewrite("replace object type", stringTypeMapping, false, groups, debugPrintReconstitution, replace);
59
- }
60
- exports.replaceObjectType = replaceObjectType;
@@ -1,3 +0,0 @@
1
- import { TypeGraph } from "../TypeGraph";
2
- import { StringTypeMapping } from "../TypeBuilder";
3
- export declare function resolveIntersections(graph: TypeGraph, stringTypeMapping: StringTypeMapping, debugPrintReconstitution: boolean): [TypeGraph, boolean];
@@ -1,244 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveIntersections = void 0;
4
- const collection_utils_1 = require("collection-utils");
5
- const UnionBuilder_1 = require("../UnionBuilder");
6
- const Type_1 = require("../Type");
7
- const TypeUtils_1 = require("../TypeUtils");
8
- const Support_1 = require("../support/Support");
9
- const TypeAttributes_1 = require("../attributes/TypeAttributes");
10
- function canResolve(t) {
11
- const members = (0, TypeUtils_1.setOperationMembersRecursively)(t, undefined)[0];
12
- if (members.size <= 1)
13
- return true;
14
- return (0, collection_utils_1.iterableEvery)(members, m => !(m instanceof Type_1.UnionType) || m.isCanonical);
15
- }
16
- function attributesForTypes(types) {
17
- return (0, collection_utils_1.mapMapEntries)(types.entries(), t => [t.kind, t.getAttributes()]);
18
- }
19
- class IntersectionAccumulator {
20
- _primitiveTypes;
21
- _primitiveAttributes = new Map();
22
- // * undefined: We haven't seen any types yet.
23
- // * Set: All types we've seen can be arrays.
24
- // * false: At least one of the types seen can't be an array.
25
- _arrayItemTypes;
26
- _arrayAttributes = TypeAttributes_1.emptyTypeAttributes;
27
- // We start out with all object types allowed, which means
28
- // _additionalPropertyTypes is empty - no restrictions - and
29
- // _classProperties is empty - no defined properties so far.
30
- //
31
- // If _additionalPropertyTypes is undefined, no additional
32
- // properties are allowed anymore. If _classProperties is
33
- // undefined, no object types are allowed, in which case
34
- // _additionalPropertyTypes must also be undefined;
35
- _objectProperties = new Map();
36
- _objectAttributes = TypeAttributes_1.emptyTypeAttributes;
37
- _additionalPropertyTypes = new Set();
38
- _lostTypeAttributes = false;
39
- updatePrimitiveTypes(members) {
40
- const types = (0, collection_utils_1.setFilter)(members, t => (0, Type_1.isPrimitiveTypeKind)(t.kind));
41
- const attributes = attributesForTypes(types);
42
- (0, collection_utils_1.mapMergeWithInto)(this._primitiveAttributes, (a, b) => (0, TypeAttributes_1.combineTypeAttributes)("intersect", a, b), attributes);
43
- const kinds = (0, collection_utils_1.setMap)(types, t => t.kind);
44
- if (this._primitiveTypes === undefined) {
45
- this._primitiveTypes = new Set(kinds);
46
- return;
47
- }
48
- const haveNumber = (0, collection_utils_1.iterableFind)(this._primitiveTypes, Type_1.isNumberTypeKind) !== undefined &&
49
- (0, collection_utils_1.iterableFind)(kinds, Type_1.isNumberTypeKind) !== undefined;
50
- this._primitiveTypes = (0, collection_utils_1.setIntersect)(this._primitiveTypes, kinds);
51
- if (haveNumber && (0, collection_utils_1.iterableFind)(this._primitiveTypes, Type_1.isNumberTypeKind) === undefined) {
52
- // One set has integer, the other has double. The intersection
53
- // of that is integer.
54
- this._primitiveTypes = this._primitiveTypes.add("integer");
55
- }
56
- }
57
- updateArrayItemTypes(members) {
58
- const maybeArray = (0, collection_utils_1.iterableFind)(members, t => t instanceof Type_1.ArrayType);
59
- if (maybeArray === undefined) {
60
- this._arrayItemTypes = false;
61
- return;
62
- }
63
- this._arrayAttributes = (0, TypeAttributes_1.combineTypeAttributes)("intersect", this._arrayAttributes, maybeArray.getAttributes());
64
- if (this._arrayItemTypes === undefined) {
65
- this._arrayItemTypes = new Set();
66
- }
67
- else if (this._arrayItemTypes !== false) {
68
- this._arrayItemTypes.add(maybeArray.items);
69
- }
70
- }
71
- updateObjectProperties(members) {
72
- const maybeObject = (0, collection_utils_1.iterableFind)(members, t => t instanceof Type_1.ObjectType);
73
- if (maybeObject === undefined) {
74
- this._objectProperties = undefined;
75
- this._additionalPropertyTypes = undefined;
76
- return;
77
- }
78
- this._objectAttributes = (0, TypeAttributes_1.combineTypeAttributes)("intersect", this._objectAttributes, maybeObject.getAttributes());
79
- const objectAdditionalProperties = maybeObject.getAdditionalProperties();
80
- if (this._objectProperties === undefined) {
81
- (0, Support_1.assert)(this._additionalPropertyTypes === undefined);
82
- return;
83
- }
84
- const allPropertyNames = (0, collection_utils_1.setUnionInto)(new Set(this._objectProperties.keys()), maybeObject.getProperties().keys());
85
- for (const name of allPropertyNames) {
86
- const existing = (0, Support_1.defined)(this._objectProperties).get(name);
87
- const newProperty = maybeObject.getProperties().get(name);
88
- if (existing !== undefined && newProperty !== undefined) {
89
- const cp = new Type_1.GenericClassProperty(existing.typeData.add(newProperty.type), existing.isOptional && newProperty.isOptional);
90
- (0, Support_1.defined)(this._objectProperties).set(name, cp);
91
- }
92
- else if (existing !== undefined && objectAdditionalProperties !== undefined) {
93
- const cp = new Type_1.GenericClassProperty(existing.typeData.add(objectAdditionalProperties), existing.isOptional);
94
- (0, Support_1.defined)(this._objectProperties).set(name, cp);
95
- }
96
- else if (existing !== undefined) {
97
- (0, Support_1.defined)(this._objectProperties).delete(name);
98
- }
99
- else if (newProperty !== undefined && this._additionalPropertyTypes !== undefined) {
100
- // FIXME: This is potentially slow
101
- const types = new Set(this._additionalPropertyTypes).add(newProperty.type);
102
- (0, Support_1.defined)(this._objectProperties).set(name, new Type_1.GenericClassProperty(types, newProperty.isOptional));
103
- }
104
- else if (newProperty !== undefined) {
105
- (0, Support_1.defined)(this._objectProperties).delete(name);
106
- }
107
- else {
108
- return (0, Support_1.mustNotHappen)();
109
- }
110
- }
111
- if (this._additionalPropertyTypes !== undefined && objectAdditionalProperties !== undefined) {
112
- this._additionalPropertyTypes.add(objectAdditionalProperties);
113
- }
114
- else if (this._additionalPropertyTypes !== undefined || objectAdditionalProperties !== undefined) {
115
- this._additionalPropertyTypes = undefined;
116
- this._lostTypeAttributes = true;
117
- }
118
- }
119
- addUnionSet(members) {
120
- this.updatePrimitiveTypes(members);
121
- this.updateArrayItemTypes(members);
122
- this.updateObjectProperties(members);
123
- }
124
- addType(t) {
125
- let attributes = t.getAttributes();
126
- (0, TypeUtils_1.matchTypeExhaustive)(t, _noneType => {
127
- return (0, Support_1.panic)("There shouldn't be a none type");
128
- }, _anyType => {
129
- return (0, Support_1.panic)("The any type should have been filtered out in setOperationMembersRecursively");
130
- }, nullType => this.addUnionSet([nullType]), boolType => this.addUnionSet([boolType]), integerType => this.addUnionSet([integerType]), doubleType => this.addUnionSet([doubleType]), stringType => this.addUnionSet([stringType]), arrayType => this.addUnionSet([arrayType]), _classType => (0, Support_1.panic)("We should never see class types in intersections"), _mapType => (0, Support_1.panic)("We should never see map types in intersections"), objectType => this.addUnionSet([objectType]), _enumType => (0, Support_1.panic)("We should never see enum types in intersections"), unionType => {
131
- attributes = (0, TypeAttributes_1.combineTypeAttributes)("intersect", [attributes].concat(Array.from(unionType.members).map(m => m.getAttributes())));
132
- this.addUnionSet(unionType.members);
133
- }, transformedStringType => this.addUnionSet([transformedStringType]));
134
- return (0, TypeAttributes_1.makeTypeAttributesInferred)(attributes);
135
- }
136
- get arrayData() {
137
- if (this._arrayItemTypes === undefined || this._arrayItemTypes === false) {
138
- return (0, Support_1.panic)("This should not be called if the type can't be an array");
139
- }
140
- return this._arrayItemTypes;
141
- }
142
- get objectData() {
143
- if (this._objectProperties === undefined) {
144
- (0, Support_1.assert)(this._additionalPropertyTypes === undefined);
145
- return undefined;
146
- }
147
- return [this._objectProperties, this._additionalPropertyTypes];
148
- }
149
- get enumCases() {
150
- return (0, Support_1.panic)("We don't support enums in intersections");
151
- }
152
- getMemberKinds() {
153
- const kinds = (0, collection_utils_1.mapMap)((0, Support_1.defined)(this._primitiveTypes).entries(), k => (0, Support_1.defined)(this._primitiveAttributes.get(k)));
154
- const maybeDoubleAttributes = this._primitiveAttributes.get("double");
155
- // If double was eliminated, add its attributes to integer
156
- if (maybeDoubleAttributes !== undefined && !kinds.has("double") && kinds.has("integer")) {
157
- // FIXME: How can this ever happen??? Where do we "eliminate" double?
158
- (0, collection_utils_1.mapUpdateInto)(kinds, "integer", a => {
159
- return (0, TypeAttributes_1.combineTypeAttributes)("intersect", (0, Support_1.defined)(a), maybeDoubleAttributes);
160
- });
161
- }
162
- if (this._arrayItemTypes !== undefined && this._arrayItemTypes !== false) {
163
- kinds.set("array", this._arrayAttributes);
164
- }
165
- else if (this._arrayAttributes.size > 0) {
166
- this._lostTypeAttributes = true;
167
- }
168
- if (this._objectProperties !== undefined) {
169
- kinds.set("object", this._objectAttributes);
170
- }
171
- else if (this._objectAttributes.size > 0) {
172
- this._lostTypeAttributes = true;
173
- }
174
- return kinds;
175
- }
176
- get lostTypeAttributes() {
177
- return this._lostTypeAttributes;
178
- }
179
- }
180
- class IntersectionUnionBuilder extends UnionBuilder_1.UnionBuilder {
181
- _createdNewIntersections = false;
182
- makeIntersection(members, attributes) {
183
- const reconstitutedMembers = (0, collection_utils_1.setMap)(members, t => this.typeBuilder.reconstituteTypeRef(t.typeRef));
184
- const first = (0, Support_1.defined)((0, collection_utils_1.iterableFirst)(reconstitutedMembers));
185
- if (reconstitutedMembers.size === 1) {
186
- this.typeBuilder.addAttributes(first, attributes);
187
- return first;
188
- }
189
- this._createdNewIntersections = true;
190
- return this.typeBuilder.getUniqueIntersectionType(attributes, reconstitutedMembers);
191
- }
192
- get createdNewIntersections() {
193
- return this._createdNewIntersections;
194
- }
195
- makeObject(maybeData, typeAttributes, forwardingRef) {
196
- if (maybeData === undefined) {
197
- return (0, Support_1.panic)("Either properties or additional properties must be given to make an object type");
198
- }
199
- const [propertyTypes, maybeAdditionalProperties] = maybeData;
200
- const properties = (0, collection_utils_1.mapMap)(propertyTypes, cp => this.typeBuilder.makeClassProperty(this.makeIntersection(cp.typeData, TypeAttributes_1.emptyTypeAttributes), cp.isOptional));
201
- const additionalProperties = maybeAdditionalProperties === undefined
202
- ? undefined
203
- : this.makeIntersection(maybeAdditionalProperties, TypeAttributes_1.emptyTypeAttributes);
204
- return this.typeBuilder.getUniqueObjectType(typeAttributes, properties, additionalProperties, forwardingRef);
205
- }
206
- makeArray(arrays, typeAttributes, forwardingRef) {
207
- // FIXME: attributes
208
- const itemsType = this.makeIntersection(arrays, TypeAttributes_1.emptyTypeAttributes);
209
- const tref = this.typeBuilder.getArrayType(typeAttributes, itemsType, forwardingRef);
210
- return tref;
211
- }
212
- }
213
- function resolveIntersections(graph, stringTypeMapping, debugPrintReconstitution) {
214
- let needsRepeat = false;
215
- function replace(types, builder, forwardingRef) {
216
- const intersections = (0, collection_utils_1.setFilter)(types, t => t instanceof Type_1.IntersectionType);
217
- const [members, intersectionAttributes] = (0, TypeUtils_1.setOperationMembersRecursively)(Array.from(intersections), "intersect");
218
- if (members.size === 0) {
219
- const t = builder.getPrimitiveType("any", intersectionAttributes, forwardingRef);
220
- return t;
221
- }
222
- if (members.size === 1) {
223
- return builder.reconstituteType((0, Support_1.defined)((0, collection_utils_1.iterableFirst)(members)), intersectionAttributes, forwardingRef);
224
- }
225
- const accumulator = new IntersectionAccumulator();
226
- const extraAttributes = (0, TypeAttributes_1.makeTypeAttributesInferred)((0, TypeAttributes_1.combineTypeAttributes)("intersect", Array.from(members).map(t => accumulator.addType(t))));
227
- const attributes = (0, TypeAttributes_1.combineTypeAttributes)("intersect", intersectionAttributes, extraAttributes);
228
- const unionBuilder = new IntersectionUnionBuilder(builder);
229
- const tref = unionBuilder.buildUnion(accumulator, true, attributes, forwardingRef);
230
- if (unionBuilder.createdNewIntersections) {
231
- needsRepeat = true;
232
- }
233
- return tref;
234
- }
235
- // FIXME: We need to handle intersections that resolve to the same set of types.
236
- // See for example the intersections-nested.schema example.
237
- const allIntersections = (0, collection_utils_1.setFilter)(graph.allTypesUnordered(), t => t instanceof Type_1.IntersectionType);
238
- const resolvableIntersections = (0, collection_utils_1.setFilter)(allIntersections, canResolve);
239
- const groups = (0, TypeUtils_1.makeGroupsToFlatten)(resolvableIntersections, undefined);
240
- graph = graph.rewrite("resolve intersections", stringTypeMapping, false, groups, debugPrintReconstitution, replace);
241
- // console.log(`resolved ${resolvableIntersections.size} of ${intersections.size} intersections`);
242
- return [graph, !needsRepeat && allIntersections.size === resolvableIntersections.size];
243
- }
244
- exports.resolveIntersections = resolveIntersections;
@@ -1,10 +0,0 @@
1
- import { EnumOption } from "../RendererOptions";
2
- export declare const acronyms: string[];
3
- export declare enum AcronymStyleOptions {
4
- Pascal = "pascal",
5
- Camel = "camel",
6
- Original = "original",
7
- Lower = "lowerCase"
8
- }
9
- export declare const acronymOption: (defaultOption: AcronymStyleOptions) => EnumOption<AcronymStyleOptions>;
10
- export declare function acronymStyle(style: AcronymStyleOptions): (s: string) => string;