quicktype 18.0.6 → 19.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.
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} +2 -1
  11. package/dist/{cli/index.js → index.js} +4 -4
  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,358 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.reservedProperties = exports.globals = exports.keywords = void 0;
4
- exports.keywords = [
5
- "__ENCODING__",
6
- "__FILE__",
7
- "__LINE__",
8
- "alias",
9
- "and",
10
- "begin",
11
- "BEGIN",
12
- "break",
13
- "case",
14
- "class",
15
- "def",
16
- "defined?",
17
- "do",
18
- "else",
19
- "elsif",
20
- "end",
21
- "END",
22
- "ensure",
23
- "false",
24
- "for",
25
- "if",
26
- "in",
27
- "module",
28
- "next",
29
- "nil",
30
- "not",
31
- "or",
32
- "redo",
33
- "rescue",
34
- "retry",
35
- "return",
36
- "self",
37
- "super",
38
- "then",
39
- "true",
40
- "undef",
41
- "unless",
42
- "until",
43
- "when",
44
- "while",
45
- "yield"
46
- ];
47
- const globalClasses = [
48
- "ArgumentError",
49
- "Array",
50
- "BasicObject",
51
- "Class",
52
- "ClosedQueueError",
53
- "Comparable",
54
- "Complex",
55
- "ConditionVariable",
56
- "Continuation",
57
- "Data",
58
- "Date",
59
- "Dir",
60
- "ENV",
61
- "EOFError",
62
- "Encoding",
63
- "EncodingError",
64
- "Enumerable",
65
- "Enumerator",
66
- "Errno",
67
- "Exception",
68
- "FalseClass",
69
- "Fiber",
70
- "FiberError",
71
- "File",
72
- "FileTest",
73
- "Float",
74
- "FloatDomainError",
75
- "FrozenError",
76
- "GC",
77
- "Hash",
78
- "IO",
79
- "IOError",
80
- "IndexError",
81
- "Integer",
82
- "Interrupt",
83
- "KeyError",
84
- "LoadError",
85
- "LocalJumpError",
86
- "Marshal",
87
- "MatchData",
88
- "Math",
89
- "Method",
90
- "Module",
91
- "Mutex",
92
- "NameError",
93
- "NilClass",
94
- "NoMemoryError",
95
- "NoMethodError",
96
- "NotImplementedError",
97
- "Numeric",
98
- "Object",
99
- "ObjectSpace",
100
- "Proc",
101
- "Process",
102
- "Queue",
103
- "Random",
104
- "Range",
105
- "RangeError",
106
- "Rational",
107
- "Regexp",
108
- "RegexpError",
109
- "RubyVM",
110
- "RuntimeError",
111
- "ScriptError",
112
- "SecurityError",
113
- "Set",
114
- "Signal",
115
- "SignalException",
116
- "SizedQueue",
117
- "StandardError",
118
- "StopIteration",
119
- "String",
120
- "Struct",
121
- "Symbol",
122
- "SyntaxError",
123
- "SystemCallError",
124
- "SystemExit",
125
- "SystemStackError",
126
- "Thread",
127
- "ThreadError",
128
- "ThreadGroup",
129
- "Time",
130
- "TracePoint",
131
- "TrueClass",
132
- "TypeError",
133
- "UnboundMethod",
134
- "UncaughtThrowError",
135
- "Undefined",
136
- "UnicodeNormalize",
137
- "Warning",
138
- "ZeroDivisionError"
139
- ];
140
- const kernel = [
141
- "__callee__",
142
- "__dir__",
143
- "__id__",
144
- "__method__",
145
- "__send__",
146
- "!",
147
- "!=",
148
- "!~",
149
- "<",
150
- "<=",
151
- "<=>",
152
- "==",
153
- "===",
154
- "=~",
155
- ">",
156
- ">=",
157
- "abort",
158
- "ancestors",
159
- "at_exit",
160
- "autoload",
161
- "autoload?",
162
- "binding",
163
- "block_given?",
164
- "caller",
165
- "caller_locations",
166
- "catch",
167
- "class",
168
- "class_eval",
169
- "class_exec",
170
- "class_variable_defined?",
171
- "class_variable_get",
172
- "class_variable_set",
173
- "class_variables",
174
- "clone",
175
- "const_defined?",
176
- "const_get",
177
- "const_missing",
178
- "const_set",
179
- "constants",
180
- "define_singleton_method",
181
- "deprecate_constant",
182
- "display",
183
- "dup",
184
- "enum_for",
185
- "eql?",
186
- "equal?",
187
- "eval",
188
- "exec",
189
- "exit",
190
- "exit!",
191
- "extend",
192
- "fail",
193
- "fork",
194
- "format",
195
- "freeze",
196
- "frozen?",
197
- "gets",
198
- "global_variables",
199
- "hash",
200
- "include",
201
- "include?",
202
- "included_modules",
203
- "inspect",
204
- "instance_eval",
205
- "instance_exec",
206
- "instance_method",
207
- "instance_methods",
208
- "instance_of?",
209
- "instance_variable_defined?",
210
- "instance_variable_get",
211
- "instance_variable_set",
212
- "instance_variables",
213
- "is_a?",
214
- "iterator?",
215
- "itself",
216
- "kind_of?",
217
- "lambda",
218
- "load",
219
- "local_variables",
220
- "loop",
221
- "method",
222
- "method_defined?",
223
- "methods",
224
- "module_eval",
225
- "module_exec",
226
- "name",
227
- "new",
228
- "nil?",
229
- "object_id",
230
- "open",
231
- "p",
232
- "prepend",
233
- "print",
234
- "printf",
235
- "private_class_method",
236
- "private_constant",
237
- "private_instance_methods",
238
- "private_method_defined?",
239
- "private_methods",
240
- "proc",
241
- "protected_instance_methods",
242
- "protected_method_defined?",
243
- "protected_methods",
244
- "public_class_method",
245
- "public_constant",
246
- "public_instance_method",
247
- "public_instance_methods",
248
- "public_method",
249
- "public_method_defined?",
250
- "public_methods",
251
- "public_send",
252
- "putc",
253
- "puts",
254
- "raise",
255
- "rand",
256
- "readline",
257
- "readlines",
258
- "remove_class_variable",
259
- "remove_instance_variable",
260
- "require",
261
- "require_relative",
262
- "respond_to?",
263
- "select",
264
- "send",
265
- "set_trace_func",
266
- "singleton_class",
267
- "singleton_class?",
268
- "singleton_method",
269
- "singleton_methods",
270
- "sleep",
271
- "spawn",
272
- "sprintf",
273
- "srand",
274
- "syscall",
275
- "system",
276
- "taint",
277
- "tainted?",
278
- "tap",
279
- "test",
280
- "throw",
281
- "to_enum",
282
- "to_s",
283
- "trace_var",
284
- "trap",
285
- "trust",
286
- "untaint",
287
- "untrace_var",
288
- "untrust",
289
- "untrusted?",
290
- "warn"
291
- ];
292
- exports.globals = kernel.concat(globalClasses);
293
- exports.reservedProperties = [
294
- "__id__",
295
- "__send__",
296
- "break",
297
- "call",
298
- "case",
299
- "class",
300
- "clone",
301
- "constrained_type",
302
- "constrained?",
303
- "constrained",
304
- "constructor",
305
- "default",
306
- "define_singleton_method",
307
- "display",
308
- "dup",
309
- "enum_for",
310
- "enum",
311
- "extend",
312
- "freeze",
313
- "gem",
314
- "hash",
315
- "inspect",
316
- "instance_eval",
317
- "instance_exec",
318
- "instance_variable_defined?",
319
- "instance_variable_get",
320
- "instance_variable_set",
321
- "instance_variables",
322
- "itself",
323
- "meta",
324
- "method",
325
- "methods",
326
- "next",
327
- "object_id",
328
- "optional",
329
- "options",
330
- "pristine",
331
- "private_methods",
332
- "protected_methods",
333
- "public_method",
334
- "public_methods",
335
- "public_send",
336
- "remove_instance_variable",
337
- "rule",
338
- "safe",
339
- "self",
340
- "send",
341
- "singleton_class",
342
- "singleton_method",
343
- "singleton_methods",
344
- "taint",
345
- "tap",
346
- "to_ast",
347
- "to_enum",
348
- "to_json",
349
- "to_s",
350
- "trust",
351
- "try",
352
- "type",
353
- "untaint",
354
- "undef",
355
- "untrust",
356
- "while",
357
- "with"
358
- ];
@@ -1,3 +0,0 @@
1
- import { TypeGraph } from "../TypeGraph";
2
- import { RunContext } from "../Run";
3
- export declare function combineClasses(ctx: RunContext, graph: TypeGraph, alphabetizeProperties: boolean, conflateNumbers: boolean, onlyWithSameProperties: boolean, debugPrintReconstitution: boolean): TypeGraph;
@@ -1,125 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.combineClasses = void 0;
4
- const Type_1 = require("../Type");
5
- const TypeUtils_1 = require("../TypeUtils");
6
- const Support_1 = require("../support/Support");
7
- const UnifyClasses_1 = require("../UnifyClasses");
8
- const REQUIRED_OVERLAP = 3 / 4;
9
- // FIXME: Allow some type combinations to unify, like different enums,
10
- // enums with strings, integers with doubles, maps with objects of
11
- // the correct type.
12
- function typeSetsCanBeCombined(s1, s2) {
13
- return (0, Type_1.setOperationCasesEqual)(s1, s2, true, (a, b) => a.structurallyCompatible(b, true));
14
- }
15
- function canBeCombined(c1, c2, onlyWithSameProperties) {
16
- const p1 = c1.getProperties();
17
- const p2 = c2.getProperties();
18
- if (onlyWithSameProperties) {
19
- if (p1.size !== p2.size) {
20
- return false;
21
- }
22
- }
23
- else {
24
- if (p1.size < p2.size * REQUIRED_OVERLAP || p2.size < p1.size * REQUIRED_OVERLAP) {
25
- return false;
26
- }
27
- }
28
- let larger;
29
- let smaller;
30
- if (p1.size > p2.size) {
31
- larger = p1;
32
- smaller = p2;
33
- }
34
- else {
35
- larger = p2;
36
- smaller = p1;
37
- }
38
- let maxFaults;
39
- if (onlyWithSameProperties) {
40
- maxFaults = 0;
41
- }
42
- else {
43
- const minOverlap = Math.ceil(larger.size * REQUIRED_OVERLAP);
44
- maxFaults = smaller.size - minOverlap;
45
- }
46
- (0, Support_1.assert)(maxFaults >= 0, "Max faults negative");
47
- const commonProperties = [];
48
- let faults = 0;
49
- for (const [name] of smaller) {
50
- if (larger.has(name)) {
51
- commonProperties.push(name);
52
- }
53
- else {
54
- faults += 1;
55
- if (faults > maxFaults)
56
- break;
57
- }
58
- }
59
- if (faults > maxFaults)
60
- return false;
61
- for (const name of commonProperties) {
62
- let ts = smaller.get(name);
63
- let tl = larger.get(name);
64
- if (ts === undefined || tl === undefined) {
65
- return (0, Support_1.panic)(`Both classes should have property ${name}`);
66
- }
67
- const tsCases = (0, TypeUtils_1.nonNullTypeCases)(ts.type);
68
- const tlCases = (0, TypeUtils_1.nonNullTypeCases)(tl.type);
69
- if (tsCases.size > 0 && tlCases.size > 0 && !typeSetsCanBeCombined(tsCases, tlCases)) {
70
- return false;
71
- }
72
- }
73
- return true;
74
- }
75
- function tryAddToClique(c, clique, onlyWithSameProperties) {
76
- for (const prototype of clique.prototypes) {
77
- if (prototype.structurallyCompatible(c)) {
78
- clique.members.push(c);
79
- return true;
80
- }
81
- }
82
- for (const prototype of clique.prototypes) {
83
- if (canBeCombined(prototype, c, onlyWithSameProperties)) {
84
- clique.prototypes.push(c);
85
- clique.members.push(c);
86
- return true;
87
- }
88
- }
89
- return false;
90
- }
91
- function findSimilarityCliques(graph, onlyWithSameProperties, includeFixedClasses) {
92
- const classCandidates = Array.from(graph.allNamedTypesSeparated().objects).filter(o => o instanceof Type_1.ClassType && (includeFixedClasses || !o.isFixed));
93
- const cliques = [];
94
- for (const c of classCandidates) {
95
- let cliqueIndex = undefined;
96
- for (let i = 0; i < cliques.length; i++) {
97
- if (tryAddToClique(c, cliques[i], onlyWithSameProperties)) {
98
- cliqueIndex = i;
99
- break;
100
- }
101
- }
102
- if (cliqueIndex === undefined) {
103
- // New clique
104
- cliqueIndex = cliques.length;
105
- cliques.push({ members: [c], prototypes: [c] });
106
- }
107
- // Move the clique we just added to to the front, in the hope that
108
- // some cliques are more often added to than others, and they'll
109
- // move to the front.
110
- const tmp = cliques[0];
111
- cliques[0] = cliques[cliqueIndex];
112
- cliques[cliqueIndex] = tmp;
113
- }
114
- return cliques.map(clique => clique.members).filter(cl => cl.length > 1);
115
- }
116
- function combineClasses(ctx, graph, alphabetizeProperties, conflateNumbers, onlyWithSameProperties, debugPrintReconstitution) {
117
- const cliques = ctx.time(" find similarity cliques", () => findSimilarityCliques(graph, onlyWithSameProperties, false));
118
- function makeCliqueClass(clique, builder, forwardingRef) {
119
- (0, Support_1.assert)(clique.size > 0, "Clique can't be empty");
120
- const attributes = (0, TypeUtils_1.combineTypeAttributesOfTypes)("union", clique);
121
- return (0, UnifyClasses_1.unifyTypes)(clique, attributes, builder, (0, UnifyClasses_1.unionBuilderForUnification)(builder, false, false, conflateNumbers), conflateNumbers, forwardingRef);
122
- }
123
- return graph.rewrite("combine classes", ctx.stringTypeMapping, alphabetizeProperties, cliques, debugPrintReconstitution, makeCliqueClass);
124
- }
125
- exports.combineClasses = combineClasses;
@@ -1,4 +0,0 @@
1
- import { TypeGraph } from "../TypeGraph";
2
- import { RunContext } from "../Run";
3
- export type EnumInference = "none" | "all" | "infer";
4
- export declare function expandStrings(ctx: RunContext, graph: TypeGraph, inference: EnumInference): TypeGraph;
@@ -1,143 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.expandStrings = void 0;
4
- const collection_utils_1 = require("collection-utils");
5
- const TypeUtils_1 = require("../TypeUtils");
6
- const Support_1 = require("../support/Support");
7
- const TypeAttributes_1 = require("../attributes/TypeAttributes");
8
- const StringTypes_1 = require("../attributes/StringTypes");
9
- const MIN_LENGTH_FOR_ENUM = 10;
10
- const MIN_LENGTH_FOR_OVERLAP = 5;
11
- const REQUIRED_OVERLAP = 3 / 4;
12
- function isOwnEnum({ numValues, cases }) {
13
- return numValues >= MIN_LENGTH_FOR_ENUM && cases.size < Math.sqrt(numValues);
14
- }
15
- function enumCasesOverlap(newCases, existingCases, newAreSubordinate) {
16
- const smaller = newAreSubordinate ? newCases.size : Math.min(newCases.size, existingCases.size);
17
- const overlap = (0, collection_utils_1.setIntersect)(newCases, existingCases).size;
18
- return overlap >= smaller * REQUIRED_OVERLAP;
19
- }
20
- function isAlwaysEmptyString(cases) {
21
- return cases.length === 1 && cases[0] === "";
22
- }
23
- function expandStrings(ctx, graph, inference) {
24
- const stringTypeMapping = ctx.stringTypeMapping;
25
- const allStrings = Array.from(graph.allTypesUnordered()).filter(t => t.kind === "string" && (0, TypeUtils_1.stringTypesForType)(t).isRestricted);
26
- function makeEnumInfo(t) {
27
- const stringTypes = (0, TypeUtils_1.stringTypesForType)(t);
28
- const mappedStringTypes = stringTypes.applyStringTypeMapping(stringTypeMapping);
29
- if (!mappedStringTypes.isRestricted)
30
- return undefined;
31
- const cases = (0, Support_1.defined)(mappedStringTypes.cases);
32
- if (cases.size === 0)
33
- return undefined;
34
- const numValues = (0, collection_utils_1.iterableReduce)(cases.values(), 0, (a, b) => a + b);
35
- if (inference !== "all") {
36
- const keys = Array.from(cases.keys());
37
- if (isAlwaysEmptyString(keys))
38
- return undefined;
39
- const someCaseIsNotNumber = (0, collection_utils_1.iterableSome)(keys, key => /^(\-|\+)?[0-9]+(\.[0-9]+)?$/.test(key) === false);
40
- if (!someCaseIsNotNumber)
41
- return undefined;
42
- }
43
- return { cases: new Set(cases.keys()), numValues };
44
- }
45
- const enumInfos = new Map();
46
- const enumSets = [];
47
- if (inference !== "none") {
48
- for (const t of allStrings) {
49
- const enumInfo = makeEnumInfo(t);
50
- if (enumInfo === undefined)
51
- continue;
52
- enumInfos.set(t, enumInfo);
53
- }
54
- function findOverlap(newCases, newAreSubordinate) {
55
- return enumSets.findIndex(s => enumCasesOverlap(newCases, s, newAreSubordinate));
56
- }
57
- // First, make case sets for all the enums that stand on their own. If
58
- // we find some overlap (searching eagerly), make unions.
59
- for (const t of Array.from(enumInfos.keys())) {
60
- const enumInfo = (0, Support_1.defined)(enumInfos.get(t));
61
- const cases = enumInfo.cases;
62
- if (inference === "all") {
63
- enumSets.push(cases);
64
- }
65
- else {
66
- if (!isOwnEnum(enumInfo))
67
- continue;
68
- const index = findOverlap(cases, false);
69
- if (index >= 0) {
70
- // console.log(
71
- // `unifying ${JSON.stringify(Array.from(cases))} with ${JSON.stringify(
72
- // Array.from(enumSets[index])
73
- // )}`
74
- // );
75
- enumSets[index] = (0, collection_utils_1.setUnion)(enumSets[index], cases);
76
- }
77
- else {
78
- // console.log(`adding new ${JSON.stringify(Array.from(cases))}`);
79
- enumSets.push(cases);
80
- }
81
- }
82
- // Remove the ones we're done with.
83
- enumInfos.delete(t);
84
- }
85
- if (inference === "all") {
86
- (0, Support_1.assert)(enumInfos.size === 0);
87
- }
88
- // Now see if we can unify the rest with some a set we found in the
89
- // previous step.
90
- for (const [, enumInfo] of enumInfos.entries()) {
91
- if (enumInfo.numValues < MIN_LENGTH_FOR_OVERLAP)
92
- continue;
93
- const index = findOverlap(enumInfo.cases, true);
94
- if (index >= 0) {
95
- // console.log(
96
- // `late unifying ${JSON.stringify(Array.from(enumInfo.cases))} with ${JSON.stringify(
97
- // Array.from(enumSets[index])
98
- // )}`
99
- // );
100
- enumSets[index] = (0, collection_utils_1.setUnion)(enumSets[index], enumInfo.cases);
101
- }
102
- }
103
- }
104
- function replaceString(group, builder, forwardingRef) {
105
- (0, Support_1.assert)(group.size === 1);
106
- const t = (0, Support_1.defined)((0, collection_utils_1.iterableFirst)(group));
107
- const stringTypes = (0, TypeUtils_1.stringTypesForType)(t);
108
- const attributes = (0, collection_utils_1.mapFilter)(t.getAttributes(), a => a !== stringTypes);
109
- const mappedStringTypes = stringTypes.applyStringTypeMapping(stringTypeMapping);
110
- if (!mappedStringTypes.isRestricted) {
111
- return builder.getStringType(attributes, StringTypes_1.StringTypes.unrestricted, forwardingRef);
112
- }
113
- const setMatches = inference === "all" ? collection_utils_1.areEqual : collection_utils_1.setIsSuperset;
114
- const types = [];
115
- const cases = (0, Support_1.defined)(mappedStringTypes.cases);
116
- if (cases.size > 0) {
117
- const keys = new Set(cases.keys());
118
- const fullCases = enumSets.find(s => setMatches(s, keys));
119
- if (inference !== "none" && !isAlwaysEmptyString(Array.from(keys)) && fullCases !== undefined) {
120
- types.push(builder.getEnumType(TypeAttributes_1.emptyTypeAttributes, fullCases));
121
- }
122
- else {
123
- return builder.getStringType(attributes, StringTypes_1.StringTypes.unrestricted, forwardingRef);
124
- }
125
- }
126
- const transformations = mappedStringTypes.transformations;
127
- // FIXME: This is probably wrong, or at least overly conservative. This is for the case
128
- // where some attributes are identity ones, i.e. where we can't merge the primitive types,
129
- // like it happens in the line after the `if`. The case where this occured was with URI
130
- // attributes: we had two separate string types with different URI attributes, but because
131
- // both are rewritten via `getPrimitiveType` below without any attributes, they end up
132
- // being the same string type.
133
- if (types.length === 0 && transformations.size === 1) {
134
- const kind = (0, Support_1.defined)((0, collection_utils_1.iterableFirst)(transformations));
135
- return builder.getPrimitiveType(kind, attributes, forwardingRef);
136
- }
137
- types.push(...Array.from(transformations).map(k => builder.getPrimitiveType(k)));
138
- (0, Support_1.assert)(types.length > 0, "We got an empty string type");
139
- return builder.getUnionType(attributes, new Set(types), forwardingRef);
140
- }
141
- return graph.rewrite("expand strings", stringTypeMapping, false, allStrings.map(t => [t]), ctx.debugPrintReconstitution, replaceString);
142
- }
143
- exports.expandStrings = expandStrings;
@@ -1,3 +0,0 @@
1
- import { TypeGraph } from "../TypeGraph";
2
- import { StringTypeMapping } from "../TypeBuilder";
3
- export declare function flattenStrings(graph: TypeGraph, stringTypeMapping: StringTypeMapping, debugPrintReconstitution: boolean): TypeGraph;
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.flattenStrings = void 0;
4
- const collection_utils_1 = require("collection-utils");
5
- const TypeUtils_1 = require("../TypeUtils");
6
- const Support_1 = require("../support/Support");
7
- const TypeAttributes_1 = require("../attributes/TypeAttributes");
8
- // A union needs replacing if it contains more than one string type, one of them being
9
- // a basic string type.
10
- function unionNeedsReplacing(u) {
11
- const stringMembers = u.stringTypeMembers;
12
- if (stringMembers.size <= 1)
13
- return undefined;
14
- const stringType = u.findMember("string");
15
- if (stringType === undefined)
16
- return undefined;
17
- (0, Support_1.assert)(!(0, TypeUtils_1.stringTypesForType)(stringType).isRestricted, "We must only flatten strings if we have no restriced strings");
18
- return stringMembers;
19
- }
20
- // Replaces all string types in an enum with the basic string type.
21
- function replaceUnion(group, builder, forwardingRef) {
22
- (0, Support_1.assert)(group.size === 1);
23
- const u = (0, Support_1.defined)((0, collection_utils_1.iterableFirst)(group));
24
- const stringMembers = (0, Support_1.defined)(unionNeedsReplacing(u));
25
- const stringAttributes = (0, TypeUtils_1.combineTypeAttributesOfTypes)("union", stringMembers);
26
- const types = [];
27
- for (const t of u.members) {
28
- if (stringMembers.has(t))
29
- continue;
30
- types.push(builder.reconstituteType(t));
31
- }
32
- if (types.length === 0) {
33
- return builder.getStringType((0, TypeAttributes_1.combineTypeAttributes)("union", stringAttributes, u.getAttributes()), undefined, forwardingRef);
34
- }
35
- types.push(builder.getStringType(stringAttributes, undefined));
36
- return builder.getUnionType(u.getAttributes(), new Set(types), forwardingRef);
37
- }
38
- function flattenStrings(graph, stringTypeMapping, debugPrintReconstitution) {
39
- const allUnions = graph.allNamedTypesSeparated().unions;
40
- const unionsToReplace = Array.from(allUnions)
41
- .filter(unionNeedsReplacing)
42
- .map(t => [t]);
43
- return graph.rewrite("flatten strings", stringTypeMapping, false, unionsToReplace, debugPrintReconstitution, replaceUnion);
44
- }
45
- exports.flattenStrings = flattenStrings;
@@ -1,3 +0,0 @@
1
- import { TypeGraph } from "../TypeGraph";
2
- import { StringTypeMapping } from "../TypeBuilder";
3
- export declare function flattenUnions(graph: TypeGraph, stringTypeMapping: StringTypeMapping, conflateNumbers: boolean, makeObjectTypes: boolean, debugPrintReconstitution: boolean): [TypeGraph, boolean];