quicktype 17.0.4 → 17.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/CompressedJSONFromStream.js +38 -26
- package/dist/cli/GraphQLIntrospection.js +41 -33
- package/dist/cli/TypeSource.d.ts +1 -1
- package/dist/cli/URLGrammar.js +3 -4
- package/dist/cli/index.js +364 -363
- package/dist/quicktype-core/Annotation.js +0 -2
- package/dist/quicktype-core/ConvenienceRenderer.d.ts +17 -17
- package/dist/quicktype-core/ConvenienceRenderer.js +81 -104
- package/dist/quicktype-core/DateTime.js +0 -1
- package/dist/quicktype-core/DeclarationIR.d.ts +1 -1
- package/dist/quicktype-core/DeclarationIR.js +10 -13
- package/dist/quicktype-core/EncodedMarkovChain.js +0 -1
- package/dist/quicktype-core/GatherNames.js +25 -47
- package/dist/quicktype-core/Graph.d.ts +2 -2
- package/dist/quicktype-core/Graph.js +19 -23
- package/dist/quicktype-core/GraphRewriting.d.ts +2 -2
- package/dist/quicktype-core/GraphRewriting.js +54 -65
- package/dist/quicktype-core/MakeTransformations.js +22 -23
- package/dist/quicktype-core/MarkovChain.d.ts +3 -3
- package/dist/quicktype-core/MarkovChain.js +8 -9
- package/dist/quicktype-core/Messages.d.ts +3 -3
- package/dist/quicktype-core/Messages.js +3 -8
- package/dist/quicktype-core/Naming.d.ts +11 -11
- package/dist/quicktype-core/Naming.js +61 -76
- package/dist/quicktype-core/Renderer.d.ts +6 -6
- package/dist/quicktype-core/Renderer.js +17 -34
- package/dist/quicktype-core/RendererOptions.d.ts +5 -5
- package/dist/quicktype-core/RendererOptions.js +3 -6
- package/dist/quicktype-core/Run.d.ts +9 -9
- package/dist/quicktype-core/Run.js +67 -72
- package/dist/quicktype-core/Source.d.ts +3 -3
- package/dist/quicktype-core/Source.js +18 -19
- package/dist/quicktype-core/TargetLanguage.d.ts +10 -10
- package/dist/quicktype-core/TargetLanguage.js +2 -6
- package/dist/quicktype-core/Transformers.d.ts +25 -25
- package/dist/quicktype-core/Transformers.js +66 -94
- package/dist/quicktype-core/Type.d.ts +43 -41
- package/dist/quicktype-core/Type.js +71 -96
- package/dist/quicktype-core/TypeBuilder.d.ts +2 -2
- package/dist/quicktype-core/TypeBuilder.js +47 -53
- package/dist/quicktype-core/TypeGraph.d.ts +4 -4
- package/dist/quicktype-core/TypeGraph.js +40 -49
- package/dist/quicktype-core/TypeUtils.d.ts +2 -2
- package/dist/quicktype-core/TypeUtils.js +22 -23
- package/dist/quicktype-core/UnifyClasses.js +12 -16
- package/dist/quicktype-core/UnionBuilder.d.ts +3 -3
- package/dist/quicktype-core/UnionBuilder.js +30 -33
- package/dist/quicktype-core/attributes/AccessorNames.d.ts +2 -2
- package/dist/quicktype-core/attributes/AccessorNames.js +17 -18
- package/dist/quicktype-core/attributes/Constraints.d.ts +3 -3
- package/dist/quicktype-core/attributes/Constraints.js +4 -8
- package/dist/quicktype-core/attributes/Description.js +5 -6
- package/dist/quicktype-core/attributes/EnumValues.js +3 -4
- package/dist/quicktype-core/attributes/StringTypes.d.ts +1 -1
- package/dist/quicktype-core/attributes/StringTypes.js +21 -24
- package/dist/quicktype-core/attributes/TypeAttributes.d.ts +3 -3
- package/dist/quicktype-core/attributes/TypeAttributes.js +10 -12
- package/dist/quicktype-core/attributes/TypeNames.d.ts +9 -9
- package/dist/quicktype-core/attributes/TypeNames.js +21 -49
- package/dist/quicktype-core/attributes/URIAttributes.d.ts +1 -1
- package/dist/quicktype-core/attributes/URIAttributes.js +6 -10
- package/dist/quicktype-core/index.js +125 -128
- package/dist/quicktype-core/input/CompressedJSON.d.ts +7 -7
- package/dist/quicktype-core/input/CompressedJSON.js +54 -49
- package/dist/quicktype-core/input/FetchingJSONSchemaStore.js +13 -5
- package/dist/quicktype-core/input/Inference.d.ts +2 -2
- package/dist/quicktype-core/input/Inference.js +17 -25
- package/dist/quicktype-core/input/Inputs.d.ts +2 -2
- package/dist/quicktype-core/input/Inputs.js +54 -38
- package/dist/quicktype-core/input/JSONSchemaInput.d.ts +11 -11
- package/dist/quicktype-core/input/JSONSchemaInput.js +523 -503
- package/dist/quicktype-core/input/JSONSchemaStore.d.ts +1 -1
- package/dist/quicktype-core/input/JSONSchemaStore.js +35 -24
- package/dist/quicktype-core/input/PostmanCollection.js +1 -2
- package/dist/quicktype-core/input/io/NodeIO.js +44 -55
- package/dist/quicktype-core/input/io/get-stream/index.js +2 -6
- package/dist/quicktype-core/language/All.js +2 -3
- package/dist/quicktype-core/language/CPlusPlus.d.ts +12 -9
- package/dist/quicktype-core/language/CPlusPlus.js +249 -251
- package/dist/quicktype-core/language/CSharp.d.ts +7 -7
- package/dist/quicktype-core/language/CSharp.js +72 -82
- package/dist/quicktype-core/language/Crystal.d.ts +2 -2
- package/dist/quicktype-core/language/Crystal.js +17 -18
- package/dist/quicktype-core/language/Dart.d.ts +4 -4
- package/dist/quicktype-core/language/Dart.js +34 -36
- package/dist/quicktype-core/language/Elm.d.ts +6 -6
- package/dist/quicktype-core/language/Elm.js +45 -47
- package/dist/quicktype-core/language/Golang.d.ts +4 -4
- package/dist/quicktype-core/language/Golang.js +20 -23
- package/dist/quicktype-core/language/Haskell.d.ts +5 -5
- package/dist/quicktype-core/language/Haskell.js +23 -25
- package/dist/quicktype-core/language/JSONSchema.d.ts +3 -3
- package/dist/quicktype-core/language/JSONSchema.js +16 -17
- package/dist/quicktype-core/language/Java.d.ts +2 -2
- package/dist/quicktype-core/language/Java.js +97 -97
- package/dist/quicktype-core/language/JavaScript.d.ts +7 -7
- package/dist/quicktype-core/language/JavaScript.js +17 -19
- package/dist/quicktype-core/language/JavaScriptPropTypes.js +13 -15
- package/dist/quicktype-core/language/JavaScriptUnicodeMaps.js +11 -12
- package/dist/quicktype-core/language/Kotlin.d.ts +2 -2
- package/dist/quicktype-core/language/Kotlin.js +37 -39
- package/dist/quicktype-core/language/Objective-C.d.ts +3 -3
- package/dist/quicktype-core/language/Objective-C.js +41 -45
- package/dist/quicktype-core/language/Php.d.ts +2 -2
- package/dist/quicktype-core/language/Php.js +41 -66
- package/dist/quicktype-core/language/Pike.d.ts +1 -1
- package/dist/quicktype-core/language/Pike.js +17 -18
- package/dist/quicktype-core/language/Python.d.ts +8 -8
- package/dist/quicktype-core/language/Python.js +64 -63
- package/dist/quicktype-core/language/Rust.d.ts +2 -2
- package/dist/quicktype-core/language/Rust.js +19 -21
- package/dist/quicktype-core/language/Swift.d.ts +7 -7
- package/dist/quicktype-core/language/Swift.js +804 -807
- package/dist/quicktype-core/language/TypeScriptFlow.d.ts +7 -7
- package/dist/quicktype-core/language/TypeScriptFlow.js +26 -28
- package/dist/quicktype-core/language/ruby/index.d.ts +4 -4
- package/dist/quicktype-core/language/ruby/index.js +24 -49
- package/dist/quicktype-core/language/ruby/keywords.js +0 -1
- package/dist/quicktype-core/rewrites/CombineClasses.js +8 -9
- package/dist/quicktype-core/rewrites/ExpandStrings.d.ts +1 -1
- package/dist/quicktype-core/rewrites/ExpandStrings.js +17 -18
- package/dist/quicktype-core/rewrites/FlattenStrings.js +6 -7
- package/dist/quicktype-core/rewrites/FlattenUnions.js +8 -9
- package/dist/quicktype-core/rewrites/InferMaps.js +10 -11
- package/dist/quicktype-core/rewrites/ReplaceObjectType.js +7 -8
- package/dist/quicktype-core/rewrites/ResolveIntersections.js +67 -68
- package/dist/quicktype-core/support/Acronyms.js +1 -3
- package/dist/quicktype-core/support/Chance.js +0 -10
- package/dist/quicktype-core/support/Converters.js +0 -1
- package/dist/quicktype-core/support/Strings.d.ts +4 -4
- package/dist/quicktype-core/support/Strings.js +16 -17
- package/dist/quicktype-core/support/Support.d.ts +1 -1
- package/dist/quicktype-core/support/Support.js +6 -30
- package/dist/quicktype-graphql-input/GraphQLSchema.d.ts +4 -4
- package/dist/quicktype-graphql-input/GraphQLSchema.js +0 -1
- package/dist/quicktype-graphql-input/index.d.ts +1 -1
- package/dist/quicktype-graphql-input/index.js +212 -229
- package/dist/quicktype-typescript-input/index.js +4 -28
- package/package.json +19 -25
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.flattenStrings = void 0;
|
|
4
3
|
const collection_utils_1 = require("collection-utils");
|
|
5
4
|
const TypeUtils_1 = require("../TypeUtils");
|
|
6
5
|
const Support_1 = require("../support/Support");
|
|
@@ -14,15 +13,15 @@ function unionNeedsReplacing(u) {
|
|
|
14
13
|
const stringType = u.findMember("string");
|
|
15
14
|
if (stringType === undefined)
|
|
16
15
|
return undefined;
|
|
17
|
-
|
|
16
|
+
Support_1.assert(!TypeUtils_1.stringTypesForType(stringType).isRestricted, "We must only flatten strings if we have no restriced strings");
|
|
18
17
|
return stringMembers;
|
|
19
18
|
}
|
|
20
19
|
// Replaces all string types in an enum with the basic string type.
|
|
21
20
|
function replaceUnion(group, builder, forwardingRef) {
|
|
22
|
-
|
|
23
|
-
const u =
|
|
24
|
-
const stringMembers =
|
|
25
|
-
const stringAttributes =
|
|
21
|
+
Support_1.assert(group.size === 1);
|
|
22
|
+
const u = Support_1.defined(collection_utils_1.iterableFirst(group));
|
|
23
|
+
const stringMembers = Support_1.defined(unionNeedsReplacing(u));
|
|
24
|
+
const stringAttributes = TypeUtils_1.combineTypeAttributesOfTypes("union", stringMembers);
|
|
26
25
|
const types = [];
|
|
27
26
|
for (const t of u.members) {
|
|
28
27
|
if (stringMembers.has(t))
|
|
@@ -30,7 +29,7 @@ function replaceUnion(group, builder, forwardingRef) {
|
|
|
30
29
|
types.push(builder.reconstituteType(t));
|
|
31
30
|
}
|
|
32
31
|
if (types.length === 0) {
|
|
33
|
-
return builder.getStringType(
|
|
32
|
+
return builder.getStringType(TypeAttributes_1.combineTypeAttributes("union", stringAttributes, u.getAttributes()), undefined, forwardingRef);
|
|
34
33
|
}
|
|
35
34
|
types.push(builder.getStringType(stringAttributes, undefined));
|
|
36
35
|
return builder.getUnionType(u.getAttributes(), new Set(types), forwardingRef);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.flattenUnions = void 0;
|
|
4
3
|
const collection_utils_1 = require("collection-utils");
|
|
5
4
|
const TypeGraph_1 = require("../TypeGraph");
|
|
6
5
|
const Type_1 = require("../Type");
|
|
@@ -13,22 +12,22 @@ function flattenUnions(graph, stringTypeMapping, conflateNumbers, makeObjectType
|
|
|
13
12
|
let needsRepeat = false;
|
|
14
13
|
function replace(types, builder, forwardingRef) {
|
|
15
14
|
const unionBuilder = new UnifyClasses_1.UnifyUnionBuilder(builder, makeObjectTypes, true, trefs => {
|
|
16
|
-
|
|
17
|
-
trefs = trefs.map(tref => builder.reconstituteType(
|
|
15
|
+
Support_1.assert(trefs.length > 0, "Must have at least one type to build union");
|
|
16
|
+
trefs = trefs.map(tref => builder.reconstituteType(TypeGraph_1.derefTypeRef(tref, graph)));
|
|
18
17
|
if (trefs.length === 1) {
|
|
19
18
|
return trefs[0];
|
|
20
19
|
}
|
|
21
20
|
needsRepeat = true;
|
|
22
21
|
return builder.getUnionType(TypeAttributes_1.emptyTypeAttributes, new Set(trefs));
|
|
23
22
|
});
|
|
24
|
-
return
|
|
23
|
+
return UnifyClasses_1.unifyTypes(types, TypeAttributes_1.emptyTypeAttributes, builder, unionBuilder, conflateNumbers, forwardingRef);
|
|
25
24
|
}
|
|
26
|
-
const allUnions =
|
|
27
|
-
const nonCanonicalUnions =
|
|
25
|
+
const allUnions = collection_utils_1.setFilter(graph.allTypesUnordered(), t => t instanceof Type_1.UnionType);
|
|
26
|
+
const nonCanonicalUnions = collection_utils_1.setFilter(allUnions, u => !u.isCanonical);
|
|
28
27
|
let foundIntersection = false;
|
|
29
|
-
const groups =
|
|
30
|
-
|
|
31
|
-
if (!
|
|
28
|
+
const groups = TypeUtils_1.makeGroupsToFlatten(nonCanonicalUnions, members => {
|
|
29
|
+
Messages_1.messageAssert(members.size > 0, "IRNoEmptyUnions", {});
|
|
30
|
+
if (!collection_utils_1.iterableSome(members, m => m instanceof Type_1.IntersectionType))
|
|
32
31
|
return true;
|
|
33
32
|
// FIXME: This is stupid. `flattenUnions` returns true when no more union
|
|
34
33
|
// flattening is necessary, but `resolveIntersections` can introduce new
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.inferMaps = void 0;
|
|
4
3
|
const collection_utils_1 = require("collection-utils");
|
|
5
4
|
const Type_1 = require("../Type");
|
|
6
5
|
const TypeUtils_1 = require("../TypeUtils");
|
|
@@ -12,9 +11,9 @@ const stringMapSizeThreshold = 50;
|
|
|
12
11
|
let markovChain = undefined;
|
|
13
12
|
function nameProbability(name) {
|
|
14
13
|
if (markovChain === undefined) {
|
|
15
|
-
markovChain =
|
|
14
|
+
markovChain = MarkovChain_1.load();
|
|
16
15
|
}
|
|
17
|
-
return
|
|
16
|
+
return MarkovChain_1.evaluate(markovChain, name);
|
|
18
17
|
}
|
|
19
18
|
function shouldBeMap(properties) {
|
|
20
19
|
// Only classes with a certain number of properties are inferred
|
|
@@ -24,13 +23,13 @@ function shouldBeMap(properties) {
|
|
|
24
23
|
return undefined;
|
|
25
24
|
// If all property names are digit-only, we always make a map, no
|
|
26
25
|
// questions asked.
|
|
27
|
-
if (
|
|
28
|
-
return
|
|
26
|
+
if (collection_utils_1.iterableEvery(properties.keys(), n => /^[0-9]+$/.test(n))) {
|
|
27
|
+
return collection_utils_1.setMap(properties.values(), cp => cp.type);
|
|
29
28
|
}
|
|
30
29
|
// If all properties are strings or null then an object must have at least
|
|
31
30
|
// `stringMapSizeThreshold` to qualify as a map.
|
|
32
31
|
if (numProperties < stringMapSizeThreshold &&
|
|
33
|
-
|
|
32
|
+
collection_utils_1.iterableEvery(properties.values(), cp => Type_1.isPrimitiveStringTypeKind(cp.type.kind) || cp.type.kind === "null")) {
|
|
34
33
|
return undefined;
|
|
35
34
|
}
|
|
36
35
|
if (numProperties < mapSizeThreshold) {
|
|
@@ -70,12 +69,12 @@ function shouldBeMap(properties) {
|
|
|
70
69
|
// Check that all the property types are the same, modulo nullability.
|
|
71
70
|
for (const [, p] of properties) {
|
|
72
71
|
// The set of types first property can be, minus null.
|
|
73
|
-
const nn =
|
|
72
|
+
const nn = TypeUtils_1.removeNullFromType(p.type)[1];
|
|
74
73
|
if (nn.size > 0) {
|
|
75
74
|
if (firstNonNullCases !== undefined) {
|
|
76
75
|
// The set of non-null cases for all other properties must
|
|
77
76
|
// be the the same, otherwise we won't infer a map.
|
|
78
|
-
if (!
|
|
77
|
+
if (!Type_1.setOperationCasesEqual(nn, firstNonNullCases, true, (a, b) => a.structurallyCompatible(b, true))) {
|
|
79
78
|
canBeMap = false;
|
|
80
79
|
break;
|
|
81
80
|
}
|
|
@@ -93,11 +92,11 @@ function shouldBeMap(properties) {
|
|
|
93
92
|
}
|
|
94
93
|
function inferMaps(graph, stringTypeMapping, conflateNumbers, debugPrintReconstitution) {
|
|
95
94
|
function replaceClass(setOfOneClass, builder, forwardingRef) {
|
|
96
|
-
const c =
|
|
95
|
+
const c = Support_1.defined(collection_utils_1.iterableFirst(setOfOneClass));
|
|
97
96
|
const properties = c.getProperties();
|
|
98
97
|
const shouldBe = shouldBeMap(properties);
|
|
99
98
|
if (shouldBe === undefined) {
|
|
100
|
-
return
|
|
99
|
+
return Support_1.panic(`We shouldn't be replacing class ${c.getCombinedName()} with a map`);
|
|
101
100
|
}
|
|
102
101
|
// Now reconstitute all the types in the new graph. TypeGraphs are
|
|
103
102
|
// immutable, so any change in the graph actually means building a new
|
|
@@ -105,7 +104,7 @@ function inferMaps(graph, stringTypeMapping, conflateNumbers, debugPrintReconsti
|
|
|
105
104
|
// Reconstituting a type means generating the "same" type in the new
|
|
106
105
|
// type graph. Except we don't get Type objects but TypeRef objects,
|
|
107
106
|
// which is a type-to-be.
|
|
108
|
-
return builder.getMapType(c.getAttributes(),
|
|
107
|
+
return builder.getMapType(c.getAttributes(), UnifyClasses_1.unifyTypes(shouldBe, c.getAttributes(), builder, UnifyClasses_1.unionBuilderForUnification(builder, false, false, conflateNumbers), conflateNumbers), forwardingRef);
|
|
109
108
|
}
|
|
110
109
|
const classesToReplace = Array.from(graph.allNamedTypesSeparated().objects).filter(o => {
|
|
111
110
|
if (!(o instanceof Type_1.ClassType))
|
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.replaceObjectType = void 0;
|
|
4
3
|
const collection_utils_1 = require("collection-utils");
|
|
5
4
|
const Support_1 = require("../support/Support");
|
|
6
5
|
const TypeAttributes_1 = require("../attributes/TypeAttributes");
|
|
7
6
|
function replaceObjectType(graph, stringTypeMapping, _conflateNumbers, leaveFullObjects, debugPrintReconstitution) {
|
|
8
7
|
function replace(setOfOneType, builder, forwardingRef) {
|
|
9
|
-
const o =
|
|
8
|
+
const o = Support_1.defined(collection_utils_1.iterableFirst(setOfOneType));
|
|
10
9
|
const attributes = o.getAttributes();
|
|
11
10
|
const properties = o.getProperties();
|
|
12
11
|
const additionalProperties = o.getAdditionalProperties();
|
|
13
12
|
function reconstituteProperties() {
|
|
14
|
-
return
|
|
13
|
+
return collection_utils_1.mapMap(properties, cp => builder.makeClassProperty(builder.reconstituteTypeRef(cp.typeRef), cp.isOptional));
|
|
15
14
|
}
|
|
16
15
|
function makeClass() {
|
|
17
16
|
return builder.getUniqueClassType(attributes, true, reconstituteProperties(), forwardingRef);
|
|
18
17
|
}
|
|
19
18
|
function reconstituteAdditionalProperties() {
|
|
20
|
-
return builder.reconstituteType(
|
|
19
|
+
return builder.reconstituteType(Support_1.defined(additionalProperties));
|
|
21
20
|
}
|
|
22
21
|
if (additionalProperties === undefined) {
|
|
23
22
|
return makeClass();
|
|
@@ -31,10 +30,10 @@ function replaceObjectType(graph, stringTypeMapping, _conflateNumbers, leaveFull
|
|
|
31
30
|
return makeClass();
|
|
32
31
|
}
|
|
33
32
|
// FIXME: Warn that we're losing class semantics.
|
|
34
|
-
const propertyTypes =
|
|
33
|
+
const propertyTypes = collection_utils_1.setMap(properties.values(), cp => cp.type).add(additionalProperties);
|
|
35
34
|
let union = builder.lookupTypeRefs(Array.from(propertyTypes).map(t => t.typeRef));
|
|
36
35
|
if (union === undefined) {
|
|
37
|
-
const reconstitutedTypes =
|
|
36
|
+
const reconstitutedTypes = collection_utils_1.setMap(propertyTypes, t => builder.reconstituteType(t));
|
|
38
37
|
union = builder.getUniqueUnionType(TypeAttributes_1.emptyTypeAttributes, new Set(reconstitutedTypes));
|
|
39
38
|
// This is the direct unification alternative. Weirdly enough, it is a tiny
|
|
40
39
|
// bit slower. It gives the same results.
|
|
@@ -50,9 +49,9 @@ function replaceObjectType(graph, stringTypeMapping, _conflateNumbers, leaveFull
|
|
|
50
49
|
}
|
|
51
50
|
return builder.getMapType(attributes, union, forwardingRef);
|
|
52
51
|
}
|
|
53
|
-
const allObjectTypes =
|
|
52
|
+
const allObjectTypes = collection_utils_1.setFilter(graph.allTypesUnordered(), t => t.kind === "object");
|
|
54
53
|
const objectTypesToReplace = leaveFullObjects
|
|
55
|
-
?
|
|
54
|
+
? collection_utils_1.setFilter(allObjectTypes, o => o.getProperties().size === 0 || o.getAdditionalProperties() === undefined)
|
|
56
55
|
: allObjectTypes;
|
|
57
56
|
const groups = Array.from(objectTypesToReplace).map(t => [t]);
|
|
58
57
|
return graph.rewrite("replace object type", stringTypeMapping, false, groups, debugPrintReconstitution, replace);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolveIntersections = void 0;
|
|
4
3
|
const collection_utils_1 = require("collection-utils");
|
|
5
4
|
const UnionBuilder_1 = require("../UnionBuilder");
|
|
6
5
|
const Type_1 = require("../Type");
|
|
@@ -8,59 +7,56 @@ const TypeUtils_1 = require("../TypeUtils");
|
|
|
8
7
|
const Support_1 = require("../support/Support");
|
|
9
8
|
const TypeAttributes_1 = require("../attributes/TypeAttributes");
|
|
10
9
|
function canResolve(t) {
|
|
11
|
-
const members =
|
|
10
|
+
const members = TypeUtils_1.setOperationMembersRecursively(t, undefined)[0];
|
|
12
11
|
if (members.size <= 1)
|
|
13
12
|
return true;
|
|
14
|
-
return
|
|
13
|
+
return collection_utils_1.iterableEvery(members, m => !(m instanceof Type_1.UnionType) || m.isCanonical);
|
|
15
14
|
}
|
|
16
15
|
function attributesForTypes(types) {
|
|
17
|
-
return
|
|
16
|
+
return collection_utils_1.mapMapEntries(types.entries(), t => [t.kind, t.getAttributes()]);
|
|
18
17
|
}
|
|
19
18
|
class IntersectionAccumulator {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
_objectAttributes = TypeAttributes_1.emptyTypeAttributes;
|
|
37
|
-
_additionalPropertyTypes = new Set();
|
|
38
|
-
_lostTypeAttributes = false;
|
|
19
|
+
constructor() {
|
|
20
|
+
this._primitiveAttributes = new Map();
|
|
21
|
+
this._arrayAttributes = TypeAttributes_1.emptyTypeAttributes;
|
|
22
|
+
// We start out with all object types allowed, which means
|
|
23
|
+
// _additionalPropertyTypes is empty - no restrictions - and
|
|
24
|
+
// _classProperties is empty - no defined properties so far.
|
|
25
|
+
//
|
|
26
|
+
// If _additionalPropertyTypes is undefined, no additional
|
|
27
|
+
// properties are allowed anymore. If _classProperties is
|
|
28
|
+
// undefined, no object types are allowed, in which case
|
|
29
|
+
// _additionalPropertyTypes must also be undefined;
|
|
30
|
+
this._objectProperties = new Map();
|
|
31
|
+
this._objectAttributes = TypeAttributes_1.emptyTypeAttributes;
|
|
32
|
+
this._additionalPropertyTypes = new Set();
|
|
33
|
+
this._lostTypeAttributes = false;
|
|
34
|
+
}
|
|
39
35
|
updatePrimitiveTypes(members) {
|
|
40
|
-
const types =
|
|
36
|
+
const types = collection_utils_1.setFilter(members, t => Type_1.isPrimitiveTypeKind(t.kind));
|
|
41
37
|
const attributes = attributesForTypes(types);
|
|
42
|
-
|
|
43
|
-
const kinds =
|
|
38
|
+
collection_utils_1.mapMergeWithInto(this._primitiveAttributes, (a, b) => TypeAttributes_1.combineTypeAttributes("intersect", a, b), attributes);
|
|
39
|
+
const kinds = collection_utils_1.setMap(types, t => t.kind);
|
|
44
40
|
if (this._primitiveTypes === undefined) {
|
|
45
41
|
this._primitiveTypes = new Set(kinds);
|
|
46
42
|
return;
|
|
47
43
|
}
|
|
48
|
-
const haveNumber =
|
|
49
|
-
|
|
50
|
-
this._primitiveTypes =
|
|
51
|
-
if (haveNumber &&
|
|
44
|
+
const haveNumber = collection_utils_1.iterableFind(this._primitiveTypes, Type_1.isNumberTypeKind) !== undefined &&
|
|
45
|
+
collection_utils_1.iterableFind(kinds, Type_1.isNumberTypeKind) !== undefined;
|
|
46
|
+
this._primitiveTypes = collection_utils_1.setIntersect(this._primitiveTypes, kinds);
|
|
47
|
+
if (haveNumber && collection_utils_1.iterableFind(this._primitiveTypes, Type_1.isNumberTypeKind) === undefined) {
|
|
52
48
|
// One set has integer, the other has double. The intersection
|
|
53
49
|
// of that is integer.
|
|
54
50
|
this._primitiveTypes = this._primitiveTypes.add("integer");
|
|
55
51
|
}
|
|
56
52
|
}
|
|
57
53
|
updateArrayItemTypes(members) {
|
|
58
|
-
const maybeArray =
|
|
54
|
+
const maybeArray = collection_utils_1.iterableFind(members, t => t instanceof Type_1.ArrayType);
|
|
59
55
|
if (maybeArray === undefined) {
|
|
60
56
|
this._arrayItemTypes = false;
|
|
61
57
|
return;
|
|
62
58
|
}
|
|
63
|
-
this._arrayAttributes =
|
|
59
|
+
this._arrayAttributes = TypeAttributes_1.combineTypeAttributes("intersect", this._arrayAttributes, maybeArray.getAttributes());
|
|
64
60
|
if (this._arrayItemTypes === undefined) {
|
|
65
61
|
this._arrayItemTypes = new Set();
|
|
66
62
|
}
|
|
@@ -69,43 +65,43 @@ class IntersectionAccumulator {
|
|
|
69
65
|
}
|
|
70
66
|
}
|
|
71
67
|
updateObjectProperties(members) {
|
|
72
|
-
const maybeObject =
|
|
68
|
+
const maybeObject = collection_utils_1.iterableFind(members, t => t instanceof Type_1.ObjectType);
|
|
73
69
|
if (maybeObject === undefined) {
|
|
74
70
|
this._objectProperties = undefined;
|
|
75
71
|
this._additionalPropertyTypes = undefined;
|
|
76
72
|
return;
|
|
77
73
|
}
|
|
78
|
-
this._objectAttributes =
|
|
74
|
+
this._objectAttributes = TypeAttributes_1.combineTypeAttributes("intersect", this._objectAttributes, maybeObject.getAttributes());
|
|
79
75
|
const objectAdditionalProperties = maybeObject.getAdditionalProperties();
|
|
80
76
|
if (this._objectProperties === undefined) {
|
|
81
|
-
|
|
77
|
+
Support_1.assert(this._additionalPropertyTypes === undefined);
|
|
82
78
|
return;
|
|
83
79
|
}
|
|
84
|
-
const allPropertyNames =
|
|
80
|
+
const allPropertyNames = collection_utils_1.setUnionInto(new Set(this._objectProperties.keys()), maybeObject.getProperties().keys());
|
|
85
81
|
for (const name of allPropertyNames) {
|
|
86
|
-
const existing =
|
|
82
|
+
const existing = Support_1.defined(this._objectProperties).get(name);
|
|
87
83
|
const newProperty = maybeObject.getProperties().get(name);
|
|
88
84
|
if (existing !== undefined && newProperty !== undefined) {
|
|
89
85
|
const cp = new Type_1.GenericClassProperty(existing.typeData.add(newProperty.type), existing.isOptional && newProperty.isOptional);
|
|
90
|
-
|
|
86
|
+
Support_1.defined(this._objectProperties).set(name, cp);
|
|
91
87
|
}
|
|
92
88
|
else if (existing !== undefined && objectAdditionalProperties !== undefined) {
|
|
93
89
|
const cp = new Type_1.GenericClassProperty(existing.typeData.add(objectAdditionalProperties), existing.isOptional);
|
|
94
|
-
|
|
90
|
+
Support_1.defined(this._objectProperties).set(name, cp);
|
|
95
91
|
}
|
|
96
92
|
else if (existing !== undefined) {
|
|
97
|
-
|
|
93
|
+
Support_1.defined(this._objectProperties).delete(name);
|
|
98
94
|
}
|
|
99
95
|
else if (newProperty !== undefined && this._additionalPropertyTypes !== undefined) {
|
|
100
96
|
// FIXME: This is potentially slow
|
|
101
97
|
const types = new Set(this._additionalPropertyTypes).add(newProperty.type);
|
|
102
|
-
|
|
98
|
+
Support_1.defined(this._objectProperties).set(name, new Type_1.GenericClassProperty(types, newProperty.isOptional));
|
|
103
99
|
}
|
|
104
100
|
else if (newProperty !== undefined) {
|
|
105
|
-
|
|
101
|
+
Support_1.defined(this._objectProperties).delete(name);
|
|
106
102
|
}
|
|
107
103
|
else {
|
|
108
|
-
return
|
|
104
|
+
return Support_1.mustNotHappen();
|
|
109
105
|
}
|
|
110
106
|
}
|
|
111
107
|
if (this._additionalPropertyTypes !== undefined && objectAdditionalProperties !== undefined) {
|
|
@@ -123,40 +119,40 @@ class IntersectionAccumulator {
|
|
|
123
119
|
}
|
|
124
120
|
addType(t) {
|
|
125
121
|
let attributes = t.getAttributes();
|
|
126
|
-
|
|
127
|
-
return
|
|
122
|
+
TypeUtils_1.matchTypeExhaustive(t, _noneType => {
|
|
123
|
+
return Support_1.panic("There shouldn't be a none type");
|
|
128
124
|
}, _anyType => {
|
|
129
|
-
return
|
|
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 =>
|
|
131
|
-
attributes =
|
|
125
|
+
return Support_1.panic("The any type should have been filtered out in setOperationMembersRecursively");
|
|
126
|
+
}, 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 => Support_1.panic("We should never see class types in intersections"), _mapType => Support_1.panic("We should never see map types in intersections"), objectType => this.addUnionSet([objectType]), _enumType => Support_1.panic("We should never see enum types in intersections"), unionType => {
|
|
127
|
+
attributes = TypeAttributes_1.combineTypeAttributes("intersect", [attributes].concat(Array.from(unionType.members).map(m => m.getAttributes())));
|
|
132
128
|
this.addUnionSet(unionType.members);
|
|
133
129
|
}, transformedStringType => this.addUnionSet([transformedStringType]));
|
|
134
|
-
return
|
|
130
|
+
return TypeAttributes_1.makeTypeAttributesInferred(attributes);
|
|
135
131
|
}
|
|
136
132
|
get arrayData() {
|
|
137
133
|
if (this._arrayItemTypes === undefined || this._arrayItemTypes === false) {
|
|
138
|
-
return
|
|
134
|
+
return Support_1.panic("This should not be called if the type can't be an array");
|
|
139
135
|
}
|
|
140
136
|
return this._arrayItemTypes;
|
|
141
137
|
}
|
|
142
138
|
get objectData() {
|
|
143
139
|
if (this._objectProperties === undefined) {
|
|
144
|
-
|
|
140
|
+
Support_1.assert(this._additionalPropertyTypes === undefined);
|
|
145
141
|
return undefined;
|
|
146
142
|
}
|
|
147
143
|
return [this._objectProperties, this._additionalPropertyTypes];
|
|
148
144
|
}
|
|
149
145
|
get enumCases() {
|
|
150
|
-
return
|
|
146
|
+
return Support_1.panic("We don't support enums in intersections");
|
|
151
147
|
}
|
|
152
148
|
getMemberKinds() {
|
|
153
|
-
const kinds =
|
|
149
|
+
const kinds = collection_utils_1.mapMap(Support_1.defined(this._primitiveTypes).entries(), k => Support_1.defined(this._primitiveAttributes.get(k)));
|
|
154
150
|
const maybeDoubleAttributes = this._primitiveAttributes.get("double");
|
|
155
151
|
// If double was eliminated, add its attributes to integer
|
|
156
152
|
if (maybeDoubleAttributes !== undefined && !kinds.has("double") && kinds.has("integer")) {
|
|
157
153
|
// FIXME: How can this ever happen??? Where do we "eliminate" double?
|
|
158
|
-
|
|
159
|
-
return
|
|
154
|
+
collection_utils_1.mapUpdateInto(kinds, "integer", a => {
|
|
155
|
+
return TypeAttributes_1.combineTypeAttributes("intersect", Support_1.defined(a), maybeDoubleAttributes);
|
|
160
156
|
});
|
|
161
157
|
}
|
|
162
158
|
if (this._arrayItemTypes !== undefined && this._arrayItemTypes !== false) {
|
|
@@ -178,10 +174,13 @@ class IntersectionAccumulator {
|
|
|
178
174
|
}
|
|
179
175
|
}
|
|
180
176
|
class IntersectionUnionBuilder extends UnionBuilder_1.UnionBuilder {
|
|
181
|
-
|
|
177
|
+
constructor() {
|
|
178
|
+
super(...arguments);
|
|
179
|
+
this._createdNewIntersections = false;
|
|
180
|
+
}
|
|
182
181
|
makeIntersection(members, attributes) {
|
|
183
|
-
const reconstitutedMembers =
|
|
184
|
-
const first =
|
|
182
|
+
const reconstitutedMembers = collection_utils_1.setMap(members, t => this.typeBuilder.reconstituteTypeRef(t.typeRef));
|
|
183
|
+
const first = Support_1.defined(collection_utils_1.iterableFirst(reconstitutedMembers));
|
|
185
184
|
if (reconstitutedMembers.size === 1) {
|
|
186
185
|
this.typeBuilder.addAttributes(first, attributes);
|
|
187
186
|
return first;
|
|
@@ -194,10 +193,10 @@ class IntersectionUnionBuilder extends UnionBuilder_1.UnionBuilder {
|
|
|
194
193
|
}
|
|
195
194
|
makeObject(maybeData, typeAttributes, forwardingRef) {
|
|
196
195
|
if (maybeData === undefined) {
|
|
197
|
-
return
|
|
196
|
+
return Support_1.panic("Either properties or additional properties must be given to make an object type");
|
|
198
197
|
}
|
|
199
198
|
const [propertyTypes, maybeAdditionalProperties] = maybeData;
|
|
200
|
-
const properties =
|
|
199
|
+
const properties = collection_utils_1.mapMap(propertyTypes, cp => this.typeBuilder.makeClassProperty(this.makeIntersection(cp.typeData, TypeAttributes_1.emptyTypeAttributes), cp.isOptional));
|
|
201
200
|
const additionalProperties = maybeAdditionalProperties === undefined
|
|
202
201
|
? undefined
|
|
203
202
|
: this.makeIntersection(maybeAdditionalProperties, TypeAttributes_1.emptyTypeAttributes);
|
|
@@ -213,18 +212,18 @@ class IntersectionUnionBuilder extends UnionBuilder_1.UnionBuilder {
|
|
|
213
212
|
function resolveIntersections(graph, stringTypeMapping, debugPrintReconstitution) {
|
|
214
213
|
let needsRepeat = false;
|
|
215
214
|
function replace(types, builder, forwardingRef) {
|
|
216
|
-
const intersections =
|
|
217
|
-
const [members, intersectionAttributes] =
|
|
215
|
+
const intersections = collection_utils_1.setFilter(types, t => t instanceof Type_1.IntersectionType);
|
|
216
|
+
const [members, intersectionAttributes] = TypeUtils_1.setOperationMembersRecursively(Array.from(intersections), "intersect");
|
|
218
217
|
if (members.size === 0) {
|
|
219
218
|
const t = builder.getPrimitiveType("any", intersectionAttributes, forwardingRef);
|
|
220
219
|
return t;
|
|
221
220
|
}
|
|
222
221
|
if (members.size === 1) {
|
|
223
|
-
return builder.reconstituteType(
|
|
222
|
+
return builder.reconstituteType(Support_1.defined(collection_utils_1.iterableFirst(members)), intersectionAttributes, forwardingRef);
|
|
224
223
|
}
|
|
225
224
|
const accumulator = new IntersectionAccumulator();
|
|
226
|
-
const extraAttributes =
|
|
227
|
-
const attributes =
|
|
225
|
+
const extraAttributes = TypeAttributes_1.makeTypeAttributesInferred(TypeAttributes_1.combineTypeAttributes("intersect", Array.from(members).map(t => accumulator.addType(t))));
|
|
226
|
+
const attributes = TypeAttributes_1.combineTypeAttributes("intersect", intersectionAttributes, extraAttributes);
|
|
228
227
|
const unionBuilder = new IntersectionUnionBuilder(builder);
|
|
229
228
|
const tref = unionBuilder.buildUnion(accumulator, true, attributes, forwardingRef);
|
|
230
229
|
if (unionBuilder.createdNewIntersections) {
|
|
@@ -234,9 +233,9 @@ function resolveIntersections(graph, stringTypeMapping, debugPrintReconstitution
|
|
|
234
233
|
}
|
|
235
234
|
// FIXME: We need to handle intersections that resolve to the same set of types.
|
|
236
235
|
// See for example the intersections-nested.schema example.
|
|
237
|
-
const allIntersections =
|
|
238
|
-
const resolvableIntersections =
|
|
239
|
-
const groups =
|
|
236
|
+
const allIntersections = collection_utils_1.setFilter(graph.allTypesUnordered(), t => t instanceof Type_1.IntersectionType);
|
|
237
|
+
const resolvableIntersections = collection_utils_1.setFilter(allIntersections, canResolve);
|
|
238
|
+
const groups = TypeUtils_1.makeGroupsToFlatten(resolvableIntersections, undefined);
|
|
240
239
|
graph = graph.rewrite("resolve intersections", stringTypeMapping, false, groups, debugPrintReconstitution, replace);
|
|
241
240
|
// console.log(`resolved ${resolvableIntersections.size} of ${intersections.size} intersections`);
|
|
242
241
|
return [graph, !needsRepeat && allIntersections.size === resolvableIntersections.size];
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.acronymStyle = exports.acronymOption = exports.AcronymStyleOptions = exports.acronyms = void 0;
|
|
4
3
|
const RendererOptions_1 = require("../RendererOptions");
|
|
5
4
|
const Strings_1 = require("./Strings");
|
|
6
5
|
exports.acronyms = [
|
|
@@ -1107,7 +1106,7 @@ var AcronymStyleOptions;
|
|
|
1107
1106
|
AcronymStyleOptions["Original"] = "original";
|
|
1108
1107
|
AcronymStyleOptions["Lower"] = "lowerCase";
|
|
1109
1108
|
})(AcronymStyleOptions = exports.AcronymStyleOptions || (exports.AcronymStyleOptions = {}));
|
|
1110
|
-
|
|
1109
|
+
exports.acronymOption = function (defaultOption) {
|
|
1111
1110
|
return new RendererOptions_1.EnumOption("acronym-style", "Acronym naming style", [
|
|
1112
1111
|
[AcronymStyleOptions.Original, AcronymStyleOptions.Original],
|
|
1113
1112
|
[AcronymStyleOptions.Pascal, AcronymStyleOptions.Pascal],
|
|
@@ -1115,7 +1114,6 @@ const acronymOption = function (defaultOption) {
|
|
|
1115
1114
|
[AcronymStyleOptions.Lower, AcronymStyleOptions.Lower]
|
|
1116
1115
|
], defaultOption, "secondary");
|
|
1117
1116
|
};
|
|
1118
|
-
exports.acronymOption = acronymOption;
|
|
1119
1117
|
function acronymStyle(style) {
|
|
1120
1118
|
const options = {
|
|
1121
1119
|
[AcronymStyleOptions.Pascal]: Strings_1.allUpperWordStyle,
|
|
@@ -34,15 +34,7 @@ http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
|
|
|
34
34
|
email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)
|
|
35
35
|
*/
|
|
36
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
-
exports.Chance = void 0;
|
|
38
37
|
class MersenneTwister {
|
|
39
|
-
N;
|
|
40
|
-
M;
|
|
41
|
-
MATRIX_A;
|
|
42
|
-
UPPER_MASK;
|
|
43
|
-
LOWER_MASK;
|
|
44
|
-
mt;
|
|
45
|
-
mti;
|
|
46
38
|
constructor(seed) {
|
|
47
39
|
if (seed === undefined) {
|
|
48
40
|
// kept random number same size as time used previously to ensure no unexpected results downstream
|
|
@@ -113,8 +105,6 @@ class MersenneTwister {
|
|
|
113
105
|
}
|
|
114
106
|
// https://github.com/chancejs/chancejs
|
|
115
107
|
class Chance {
|
|
116
|
-
seed;
|
|
117
|
-
mt;
|
|
118
108
|
constructor(seed) {
|
|
119
109
|
this.seed = seed;
|
|
120
110
|
// If no generator function was provided, use our MT
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export type NamingStyle = "pascal" | "camel" | "underscore" | "upper-underscore" | "pascal-upper-acronyms" | "camel-upper-acronyms";
|
|
2
|
-
type CodePointPredicate = (codePoint: number) => boolean;
|
|
1
|
+
export declare type NamingStyle = "pascal" | "camel" | "underscore" | "upper-underscore" | "pascal-upper-acronyms" | "camel-upper-acronyms";
|
|
2
|
+
declare type CodePointPredicate = (codePoint: number) => boolean;
|
|
3
3
|
export declare function utf16ConcatMap(mapper: (utf16Unit: number) => string): (s: string) => string;
|
|
4
4
|
export declare function utf32ConcatMap(mapper: (codePoint: number) => string): (s: string) => string;
|
|
5
5
|
export declare function utf16LegalizeCharacters(isLegal: (utf16Unit: number) => boolean): (s: string) => string;
|
|
@@ -27,13 +27,13 @@ export declare function camelCase(str: string): string;
|
|
|
27
27
|
export declare function snakeCase(str: string): string;
|
|
28
28
|
export declare function startWithLetter(isAllowedStart: (codePoint: number) => boolean, // FIXME: technically, this operates on UTF16 units
|
|
29
29
|
upper: boolean, str: string): string;
|
|
30
|
-
export type WordInName = {
|
|
30
|
+
export declare type WordInName = {
|
|
31
31
|
word: string;
|
|
32
32
|
isAcronym: boolean;
|
|
33
33
|
};
|
|
34
34
|
export declare const fastIsUpperCase: CodePointPredicate;
|
|
35
35
|
export declare function splitIntoWords(s: string): WordInName[];
|
|
36
|
-
export type WordStyle = (word: string) => string;
|
|
36
|
+
export declare type WordStyle = (word: string) => string;
|
|
37
37
|
export declare function firstUpperWordStyle(s: string): string;
|
|
38
38
|
export declare function allUpperWordStyle(s: string): string;
|
|
39
39
|
export declare function originalWord(s: string): string;
|