quicktype 16.0.43 → 17.0.0
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 +26 -38
- package/dist/cli/GraphQLIntrospection.js +33 -41
- package/dist/cli/TypeSource.d.ts +1 -1
- package/dist/cli/URLGrammar.js +4 -3
- package/dist/cli/index.js +363 -364
- package/dist/quicktype-core/Annotation.js +2 -0
- package/dist/quicktype-core/ConvenienceRenderer.d.ts +17 -17
- package/dist/quicktype-core/ConvenienceRenderer.js +104 -81
- package/dist/quicktype-core/DateTime.js +1 -0
- package/dist/quicktype-core/DeclarationIR.d.ts +1 -1
- package/dist/quicktype-core/DeclarationIR.js +13 -10
- package/dist/quicktype-core/EncodedMarkovChain.js +1 -0
- package/dist/quicktype-core/GatherNames.js +47 -25
- package/dist/quicktype-core/Graph.d.ts +2 -2
- package/dist/quicktype-core/Graph.js +23 -19
- package/dist/quicktype-core/GraphRewriting.d.ts +2 -2
- package/dist/quicktype-core/GraphRewriting.js +65 -54
- package/dist/quicktype-core/MakeTransformations.js +23 -22
- package/dist/quicktype-core/MarkovChain.d.ts +3 -3
- package/dist/quicktype-core/MarkovChain.js +9 -8
- package/dist/quicktype-core/Messages.d.ts +3 -3
- package/dist/quicktype-core/Messages.js +8 -3
- package/dist/quicktype-core/Naming.d.ts +11 -11
- package/dist/quicktype-core/Naming.js +76 -61
- package/dist/quicktype-core/Renderer.d.ts +6 -6
- package/dist/quicktype-core/Renderer.js +34 -17
- package/dist/quicktype-core/RendererOptions.d.ts +5 -5
- package/dist/quicktype-core/RendererOptions.js +6 -3
- package/dist/quicktype-core/Run.d.ts +9 -9
- package/dist/quicktype-core/Run.js +72 -67
- package/dist/quicktype-core/Source.d.ts +3 -3
- package/dist/quicktype-core/Source.js +19 -18
- package/dist/quicktype-core/TargetLanguage.d.ts +10 -10
- package/dist/quicktype-core/TargetLanguage.js +6 -2
- package/dist/quicktype-core/Transformers.d.ts +25 -25
- package/dist/quicktype-core/Transformers.js +94 -66
- package/dist/quicktype-core/Type.d.ts +41 -43
- package/dist/quicktype-core/Type.js +96 -71
- package/dist/quicktype-core/TypeBuilder.d.ts +2 -2
- package/dist/quicktype-core/TypeBuilder.js +53 -47
- package/dist/quicktype-core/TypeGraph.d.ts +4 -4
- package/dist/quicktype-core/TypeGraph.js +49 -40
- package/dist/quicktype-core/TypeUtils.d.ts +2 -2
- package/dist/quicktype-core/TypeUtils.js +23 -22
- package/dist/quicktype-core/UnifyClasses.js +16 -12
- package/dist/quicktype-core/UnionBuilder.d.ts +3 -3
- package/dist/quicktype-core/UnionBuilder.js +33 -30
- package/dist/quicktype-core/attributes/AccessorNames.d.ts +2 -2
- package/dist/quicktype-core/attributes/AccessorNames.js +18 -17
- package/dist/quicktype-core/attributes/Constraints.d.ts +3 -3
- package/dist/quicktype-core/attributes/Constraints.js +8 -4
- package/dist/quicktype-core/attributes/Description.js +6 -5
- package/dist/quicktype-core/attributes/EnumValues.js +4 -3
- package/dist/quicktype-core/attributes/StringTypes.d.ts +1 -1
- package/dist/quicktype-core/attributes/StringTypes.js +24 -21
- package/dist/quicktype-core/attributes/TypeAttributes.d.ts +3 -3
- package/dist/quicktype-core/attributes/TypeAttributes.js +12 -10
- package/dist/quicktype-core/attributes/TypeNames.d.ts +9 -9
- package/dist/quicktype-core/attributes/TypeNames.js +49 -21
- package/dist/quicktype-core/attributes/URIAttributes.d.ts +1 -1
- package/dist/quicktype-core/attributes/URIAttributes.js +10 -6
- package/dist/quicktype-core/index.js +128 -125
- package/dist/quicktype-core/input/CompressedJSON.d.ts +7 -7
- package/dist/quicktype-core/input/CompressedJSON.js +49 -54
- package/dist/quicktype-core/input/FetchingJSONSchemaStore.js +5 -13
- package/dist/quicktype-core/input/Inference.d.ts +2 -2
- package/dist/quicktype-core/input/Inference.js +25 -17
- package/dist/quicktype-core/input/Inputs.d.ts +2 -2
- package/dist/quicktype-core/input/Inputs.js +38 -54
- package/dist/quicktype-core/input/JSONSchemaInput.d.ts +11 -11
- package/dist/quicktype-core/input/JSONSchemaInput.js +503 -523
- package/dist/quicktype-core/input/JSONSchemaStore.d.ts +1 -1
- package/dist/quicktype-core/input/JSONSchemaStore.js +24 -35
- package/dist/quicktype-core/input/PostmanCollection.js +2 -1
- package/dist/quicktype-core/input/io/NodeIO.js +55 -44
- package/dist/quicktype-core/input/io/get-stream/index.js +6 -2
- package/dist/quicktype-core/language/All.js +3 -2
- package/dist/quicktype-core/language/CPlusPlus.d.ts +8 -8
- package/dist/quicktype-core/language/CPlusPlus.js +185 -151
- package/dist/quicktype-core/language/CSharp.d.ts +7 -7
- package/dist/quicktype-core/language/CSharp.js +82 -72
- package/dist/quicktype-core/language/Crystal.d.ts +2 -2
- package/dist/quicktype-core/language/Crystal.js +18 -17
- package/dist/quicktype-core/language/Dart.d.ts +4 -4
- package/dist/quicktype-core/language/Dart.js +36 -34
- package/dist/quicktype-core/language/Elm.d.ts +6 -6
- package/dist/quicktype-core/language/Elm.js +47 -45
- package/dist/quicktype-core/language/Golang.d.ts +4 -4
- package/dist/quicktype-core/language/Golang.js +23 -20
- package/dist/quicktype-core/language/Haskell.d.ts +5 -5
- package/dist/quicktype-core/language/Haskell.js +25 -23
- package/dist/quicktype-core/language/JSONSchema.d.ts +3 -3
- package/dist/quicktype-core/language/JSONSchema.js +17 -16
- 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 +19 -17
- package/dist/quicktype-core/language/JavaScriptPropTypes.js +15 -13
- package/dist/quicktype-core/language/JavaScriptUnicodeMaps.js +12 -11
- package/dist/quicktype-core/language/Kotlin.d.ts +2 -2
- package/dist/quicktype-core/language/Kotlin.js +39 -37
- package/dist/quicktype-core/language/Objective-C.d.ts +3 -3
- package/dist/quicktype-core/language/Objective-C.js +45 -41
- package/dist/quicktype-core/language/Php.d.ts +2 -2
- package/dist/quicktype-core/language/Php.js +66 -41
- package/dist/quicktype-core/language/Pike.d.ts +1 -1
- package/dist/quicktype-core/language/Pike.js +18 -17
- package/dist/quicktype-core/language/Python.d.ts +8 -8
- package/dist/quicktype-core/language/Python.js +63 -64
- package/dist/quicktype-core/language/Rust.d.ts +2 -2
- package/dist/quicktype-core/language/Rust.js +21 -19
- package/dist/quicktype-core/language/Swift.d.ts +7 -7
- package/dist/quicktype-core/language/Swift.js +568 -565
- package/dist/quicktype-core/language/TypeScriptFlow.d.ts +7 -7
- package/dist/quicktype-core/language/TypeScriptFlow.js +28 -26
- package/dist/quicktype-core/language/ruby/index.d.ts +4 -4
- package/dist/quicktype-core/language/ruby/index.js +49 -24
- package/dist/quicktype-core/language/ruby/keywords.js +1 -0
- package/dist/quicktype-core/rewrites/CombineClasses.js +9 -8
- package/dist/quicktype-core/rewrites/ExpandStrings.d.ts +1 -1
- package/dist/quicktype-core/rewrites/ExpandStrings.js +18 -17
- package/dist/quicktype-core/rewrites/FlattenStrings.js +7 -6
- package/dist/quicktype-core/rewrites/FlattenUnions.js +9 -8
- package/dist/quicktype-core/rewrites/InferMaps.js +11 -10
- package/dist/quicktype-core/rewrites/ReplaceObjectType.js +8 -7
- package/dist/quicktype-core/rewrites/ResolveIntersections.js +68 -67
- package/dist/quicktype-core/support/Acronyms.js +3 -1
- package/dist/quicktype-core/support/Chance.js +10 -0
- package/dist/quicktype-core/support/Converters.js +1 -0
- package/dist/quicktype-core/support/Strings.d.ts +4 -4
- package/dist/quicktype-core/support/Strings.js +17 -16
- package/dist/quicktype-core/support/Support.d.ts +1 -1
- package/dist/quicktype-core/support/Support.js +30 -6
- package/dist/quicktype-graphql-input/GraphQLSchema.d.ts +4 -4
- package/dist/quicktype-graphql-input/GraphQLSchema.js +1 -0
- package/dist/quicktype-graphql-input/index.d.ts +1 -1
- package/dist/quicktype-graphql-input/index.js +229 -212
- package/dist/quicktype-typescript-input/index.js +28 -4
- package/package.json +25 -19
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.matchCompoundType = exports.matchType = exports.matchTypeExhaustive = exports.stringTypesForType = exports.directlyReachableSingleNamedType = exports.directlyReachableTypes = exports.separateNamedTypes = exports.isNamedType = exports.getNullAsOptional = exports.nonNullTypeCases = exports.nullableFromUnion = exports.removeNullFromType = exports.removeNullFromUnion = exports.isAnyOrNull = exports.combineTypeAttributesOfTypes = exports.makeGroupsToFlatten = exports.setOperationMembersRecursively = exports.assertIsClass = exports.assertIsObject = void 0;
|
|
3
4
|
const collection_utils_1 = require("collection-utils");
|
|
4
5
|
const Support_1 = require("./support/Support");
|
|
5
6
|
const TypeAttributes_1 = require("./attributes/TypeAttributes");
|
|
@@ -9,12 +10,12 @@ function assertIsObject(t) {
|
|
|
9
10
|
if (t instanceof Type_1.ObjectType) {
|
|
10
11
|
return t;
|
|
11
12
|
}
|
|
12
|
-
return Support_1.panic("Supposed object type is not an object type");
|
|
13
|
+
return (0, Support_1.panic)("Supposed object type is not an object type");
|
|
13
14
|
}
|
|
14
15
|
exports.assertIsObject = assertIsObject;
|
|
15
16
|
function assertIsClass(t) {
|
|
16
17
|
if (!(t instanceof Type_1.ClassType)) {
|
|
17
|
-
return Support_1.panic("Supposed class type is not a class type");
|
|
18
|
+
return (0, Support_1.panic)("Supposed class type is not a class type");
|
|
18
19
|
}
|
|
19
20
|
return t;
|
|
20
21
|
}
|
|
@@ -33,7 +34,7 @@ function setOperationMembersRecursively(oneOrMany, combinationKind) {
|
|
|
33
34
|
return;
|
|
34
35
|
processedSetOperations.add(so);
|
|
35
36
|
if (combinationKind !== undefined) {
|
|
36
|
-
attributes = TypeAttributes_1.combineTypeAttributes(combinationKind, attributes, t.getAttributes());
|
|
37
|
+
attributes = (0, TypeAttributes_1.combineTypeAttributes)(combinationKind, attributes, t.getAttributes());
|
|
37
38
|
}
|
|
38
39
|
for (const m of so.members) {
|
|
39
40
|
process(m);
|
|
@@ -44,7 +45,7 @@ function setOperationMembersRecursively(oneOrMany, combinationKind) {
|
|
|
44
45
|
}
|
|
45
46
|
else {
|
|
46
47
|
if (combinationKind !== undefined) {
|
|
47
|
-
attributes = TypeAttributes_1.combineTypeAttributes(combinationKind, attributes, t.getAttributes());
|
|
48
|
+
attributes = (0, TypeAttributes_1.combineTypeAttributes)(combinationKind, attributes, t.getAttributes());
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
51
|
}
|
|
@@ -68,7 +69,7 @@ function makeGroupsToFlatten(setOperations, include) {
|
|
|
68
69
|
if (maybeSet === undefined) {
|
|
69
70
|
maybeSet = new Set();
|
|
70
71
|
if (members.size === 1) {
|
|
71
|
-
maybeSet.add(Support_1.defined(collection_utils_1.iterableFirst(members)));
|
|
72
|
+
maybeSet.add((0, Support_1.defined)((0, collection_utils_1.iterableFirst)(members)));
|
|
72
73
|
}
|
|
73
74
|
}
|
|
74
75
|
maybeSet.add(u);
|
|
@@ -78,7 +79,7 @@ function makeGroupsToFlatten(setOperations, include) {
|
|
|
78
79
|
}
|
|
79
80
|
exports.makeGroupsToFlatten = makeGroupsToFlatten;
|
|
80
81
|
function combineTypeAttributesOfTypes(combinationKind, types) {
|
|
81
|
-
return TypeAttributes_1.combineTypeAttributes(combinationKind, Array.from(types).map(t => t.getAttributes()));
|
|
82
|
+
return (0, TypeAttributes_1.combineTypeAttributes)(combinationKind, Array.from(types).map(t => t.getAttributes()));
|
|
82
83
|
}
|
|
83
84
|
exports.combineTypeAttributesOfTypes = combineTypeAttributesOfTypes;
|
|
84
85
|
function isAnyOrNull(t) {
|
|
@@ -93,14 +94,14 @@ function removeNullFromUnion(t, sortBy = false) {
|
|
|
93
94
|
if (sortBy === false)
|
|
94
95
|
return s;
|
|
95
96
|
if (sortBy === true)
|
|
96
|
-
return collection_utils_1.setSortBy(s, m => m.kind);
|
|
97
|
-
return collection_utils_1.setSortBy(s, sortBy);
|
|
97
|
+
return (0, collection_utils_1.setSortBy)(s, m => m.kind);
|
|
98
|
+
return (0, collection_utils_1.setSortBy)(s, sortBy);
|
|
98
99
|
}
|
|
99
100
|
const nullType = t.findMember("null");
|
|
100
101
|
if (nullType === undefined) {
|
|
101
102
|
return [null, sort(t.members)];
|
|
102
103
|
}
|
|
103
|
-
return [nullType, sort(collection_utils_1.setFilter(t.members, m => m.kind !== "null"))];
|
|
104
|
+
return [nullType, sort((0, collection_utils_1.setFilter)(t.members, m => m.kind !== "null"))];
|
|
104
105
|
}
|
|
105
106
|
exports.removeNullFromUnion = removeNullFromUnion;
|
|
106
107
|
function removeNullFromType(t) {
|
|
@@ -119,7 +120,7 @@ function nullableFromUnion(t) {
|
|
|
119
120
|
return null;
|
|
120
121
|
if (nonNulls.size !== 1)
|
|
121
122
|
return null;
|
|
122
|
-
return Support_1.defined(collection_utils_1.iterableFirst(nonNulls));
|
|
123
|
+
return (0, Support_1.defined)((0, collection_utils_1.iterableFirst)(nonNulls));
|
|
123
124
|
}
|
|
124
125
|
exports.nullableFromUnion = nullableFromUnion;
|
|
125
126
|
function nonNullTypeCases(t) {
|
|
@@ -141,9 +142,9 @@ function isNamedType(t) {
|
|
|
141
142
|
}
|
|
142
143
|
exports.isNamedType = isNamedType;
|
|
143
144
|
function separateNamedTypes(types) {
|
|
144
|
-
const objects = collection_utils_1.setFilter(types, t => t.kind === "object" || t.kind === "class");
|
|
145
|
-
const enums = collection_utils_1.setFilter(types, t => t instanceof Type_1.EnumType);
|
|
146
|
-
const unions = collection_utils_1.setFilter(types, t => t instanceof Type_1.UnionType);
|
|
145
|
+
const objects = (0, collection_utils_1.setFilter)(types, t => t.kind === "object" || t.kind === "class");
|
|
146
|
+
const enums = (0, collection_utils_1.setFilter)(types, t => t instanceof Type_1.EnumType);
|
|
147
|
+
const unions = (0, collection_utils_1.setFilter)(types, t => t instanceof Type_1.UnionType);
|
|
147
148
|
return { objects, enums, unions };
|
|
148
149
|
}
|
|
149
150
|
exports.separateNamedTypes = separateNamedTypes;
|
|
@@ -151,7 +152,7 @@ function directlyReachableTypes(t, setForType) {
|
|
|
151
152
|
const set = setForType(t);
|
|
152
153
|
if (set !== null)
|
|
153
154
|
return set;
|
|
154
|
-
return collection_utils_1.setUnion(...Array.from(t.getNonAttributeChildren()).map(c => directlyReachableTypes(c, setForType)));
|
|
155
|
+
return (0, collection_utils_1.setUnion)(...Array.from(t.getNonAttributeChildren()).map(c => directlyReachableTypes(c, setForType)));
|
|
155
156
|
}
|
|
156
157
|
exports.directlyReachableTypes = directlyReachableTypes;
|
|
157
158
|
function directlyReachableSingleNamedType(type) {
|
|
@@ -162,22 +163,22 @@ function directlyReachableSingleNamedType(type) {
|
|
|
162
163
|
}
|
|
163
164
|
return null;
|
|
164
165
|
});
|
|
165
|
-
Support_1.assert(definedTypes.size <= 1, "Cannot have more than one defined type per top-level");
|
|
166
|
-
return collection_utils_1.iterableFirst(definedTypes);
|
|
166
|
+
(0, Support_1.assert)(definedTypes.size <= 1, "Cannot have more than one defined type per top-level");
|
|
167
|
+
return (0, collection_utils_1.iterableFirst)(definedTypes);
|
|
167
168
|
}
|
|
168
169
|
exports.directlyReachableSingleNamedType = directlyReachableSingleNamedType;
|
|
169
170
|
function stringTypesForType(t) {
|
|
170
|
-
Support_1.assert(t.kind === "string", "Only strings can have string types");
|
|
171
|
+
(0, Support_1.assert)(t.kind === "string", "Only strings can have string types");
|
|
171
172
|
const stringTypes = StringTypes_1.stringTypesTypeAttributeKind.tryGetInAttributes(t.getAttributes());
|
|
172
173
|
if (stringTypes === undefined) {
|
|
173
|
-
return Support_1.panic("All strings must have a string type attribute");
|
|
174
|
+
return (0, Support_1.panic)("All strings must have a string type attribute");
|
|
174
175
|
}
|
|
175
176
|
return stringTypes;
|
|
176
177
|
}
|
|
177
178
|
exports.stringTypesForType = stringTypesForType;
|
|
178
179
|
function matchTypeExhaustive(t, noneType, anyType, nullType, boolType, integerType, doubleType, stringType, arrayType, classType, mapType, objectType, enumType, unionType, transformedStringType) {
|
|
179
180
|
if (t.isPrimitive()) {
|
|
180
|
-
if (Type_1.isPrimitiveStringTypeKind(t.kind)) {
|
|
181
|
+
if ((0, Type_1.isPrimitiveStringTypeKind)(t.kind)) {
|
|
181
182
|
if (t.kind === "string") {
|
|
182
183
|
return stringType(t);
|
|
183
184
|
}
|
|
@@ -194,7 +195,7 @@ function matchTypeExhaustive(t, noneType, anyType, nullType, boolType, integerTy
|
|
|
194
195
|
}[kind];
|
|
195
196
|
if (f !== undefined)
|
|
196
197
|
return f(t);
|
|
197
|
-
return Support_1.assertNever(f);
|
|
198
|
+
return (0, Support_1.assertNever)(f);
|
|
198
199
|
}
|
|
199
200
|
else if (t instanceof Type_1.ArrayType)
|
|
200
201
|
return arrayType(t);
|
|
@@ -208,12 +209,12 @@ function matchTypeExhaustive(t, noneType, anyType, nullType, boolType, integerTy
|
|
|
208
209
|
return enumType(t);
|
|
209
210
|
else if (t instanceof Type_1.UnionType)
|
|
210
211
|
return unionType(t);
|
|
211
|
-
return Support_1.panic(`Unknown type ${t.kind}`);
|
|
212
|
+
return (0, Support_1.panic)(`Unknown type ${t.kind}`);
|
|
212
213
|
}
|
|
213
214
|
exports.matchTypeExhaustive = matchTypeExhaustive;
|
|
214
215
|
function matchType(type, anyType, nullType, boolType, integerType, doubleType, stringType, arrayType, classType, mapType, enumType, unionType, transformedStringType) {
|
|
215
216
|
function typeNotSupported(t) {
|
|
216
|
-
return Support_1.panic(`Unsupported type ${t.kind} in non-exhaustive match`);
|
|
217
|
+
return (0, Support_1.panic)(`Unsupported type ${t.kind} in non-exhaustive match`);
|
|
217
218
|
}
|
|
218
219
|
/* tslint:disable:strict-boolean-expressions */
|
|
219
220
|
return matchTypeExhaustive(type, typeNotSupported, anyType, nullType, boolType, integerType, doubleType, stringType, arrayType, classType, mapType, typeNotSupported, enumType, unionType, transformedStringType || typeNotSupported);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unifyTypes = exports.unionBuilderForUnification = exports.UnifyUnionBuilder = void 0;
|
|
3
4
|
const collection_utils_1 = require("collection-utils");
|
|
4
5
|
const Type_1 = require("./Type");
|
|
5
6
|
const TypeUtils_1 = require("./TypeUtils");
|
|
@@ -11,7 +12,7 @@ function getCliqueProperties(clique, builder, makePropertyType) {
|
|
|
11
12
|
let lostTypeAttributes = false;
|
|
12
13
|
let propertyNames = new Set();
|
|
13
14
|
for (const o of clique) {
|
|
14
|
-
collection_utils_1.setUnionInto(propertyNames, o.getProperties().keys());
|
|
15
|
+
(0, collection_utils_1.setUnionInto)(propertyNames, o.getProperties().keys());
|
|
15
16
|
}
|
|
16
17
|
let properties = Array.from(propertyNames).map(name => [name, new Set(), false]);
|
|
17
18
|
let additionalProperties = undefined;
|
|
@@ -69,6 +70,9 @@ function countProperties(clique) {
|
|
|
69
70
|
return { hasProperties, hasAdditionalProperties, hasNonAnyAdditionalProperties };
|
|
70
71
|
}
|
|
71
72
|
class UnifyUnionBuilder extends UnionBuilder_1.UnionBuilder {
|
|
73
|
+
_makeObjectTypes;
|
|
74
|
+
_makeClassesFixed;
|
|
75
|
+
_unifyTypes;
|
|
72
76
|
constructor(typeBuilder, _makeObjectTypes, _makeClassesFixed, _unifyTypes) {
|
|
73
77
|
super(typeBuilder);
|
|
74
78
|
this._makeObjectTypes = _makeObjectTypes;
|
|
@@ -78,29 +82,29 @@ class UnifyUnionBuilder extends UnionBuilder_1.UnionBuilder {
|
|
|
78
82
|
makeObject(objectRefs, typeAttributes, forwardingRef) {
|
|
79
83
|
const maybeTypeRef = this.typeBuilder.lookupTypeRefs(objectRefs, forwardingRef);
|
|
80
84
|
if (maybeTypeRef !== undefined) {
|
|
81
|
-
Support_1.assert(forwardingRef === undefined || maybeTypeRef === forwardingRef, "The forwarding ref must be consumed");
|
|
85
|
+
(0, Support_1.assert)(forwardingRef === undefined || maybeTypeRef === forwardingRef, "The forwarding ref must be consumed");
|
|
82
86
|
this.typeBuilder.addAttributes(maybeTypeRef, typeAttributes);
|
|
83
87
|
return maybeTypeRef;
|
|
84
88
|
}
|
|
85
89
|
if (objectRefs.length === 1) {
|
|
86
90
|
return this.typeBuilder.reconstituteTypeRef(objectRefs[0], typeAttributes, forwardingRef);
|
|
87
91
|
}
|
|
88
|
-
const objectTypes = objectRefs.map(r => TypeUtils_1.assertIsObject(TypeGraph_1.derefTypeRef(r, this.typeBuilder)));
|
|
92
|
+
const objectTypes = objectRefs.map(r => (0, TypeUtils_1.assertIsObject)((0, TypeGraph_1.derefTypeRef)(r, this.typeBuilder)));
|
|
89
93
|
const { hasProperties, hasAdditionalProperties, hasNonAnyAdditionalProperties } = countProperties(objectTypes);
|
|
90
94
|
if (!this._makeObjectTypes && (hasNonAnyAdditionalProperties || (!hasProperties && hasAdditionalProperties))) {
|
|
91
95
|
const propertyTypes = new Set();
|
|
92
96
|
for (const o of objectTypes) {
|
|
93
|
-
collection_utils_1.setUnionInto(propertyTypes, Array.from(o.getProperties().values()).map(cp => cp.typeRef));
|
|
97
|
+
(0, collection_utils_1.setUnionInto)(propertyTypes, Array.from(o.getProperties().values()).map(cp => cp.typeRef));
|
|
94
98
|
}
|
|
95
99
|
const additionalPropertyTypes = new Set(objectTypes
|
|
96
100
|
.filter(o => o.getAdditionalProperties() !== undefined)
|
|
97
|
-
.map(o => Support_1.defined(o.getAdditionalProperties()).typeRef));
|
|
98
|
-
collection_utils_1.setUnionInto(propertyTypes, additionalPropertyTypes);
|
|
101
|
+
.map(o => (0, Support_1.defined)(o.getAdditionalProperties()).typeRef));
|
|
102
|
+
(0, collection_utils_1.setUnionInto)(propertyTypes, additionalPropertyTypes);
|
|
99
103
|
return this.typeBuilder.getMapType(typeAttributes, this._unifyTypes(Array.from(propertyTypes)));
|
|
100
104
|
}
|
|
101
105
|
else {
|
|
102
106
|
const [properties, additionalProperties, lostTypeAttributes] = getCliqueProperties(objectTypes, this.typeBuilder, types => {
|
|
103
|
-
Support_1.assert(types.size > 0, "Property has no type");
|
|
107
|
+
(0, Support_1.assert)(types.size > 0, "Property has no type");
|
|
104
108
|
return this._unifyTypes(Array.from(types).map(t => t.typeRef));
|
|
105
109
|
});
|
|
106
110
|
if (lostTypeAttributes) {
|
|
@@ -110,7 +114,7 @@ class UnifyUnionBuilder extends UnionBuilder_1.UnionBuilder {
|
|
|
110
114
|
return this.typeBuilder.getUniqueObjectType(typeAttributes, properties, additionalProperties, forwardingRef);
|
|
111
115
|
}
|
|
112
116
|
else {
|
|
113
|
-
Support_1.assert(additionalProperties === undefined, "We have additional properties but want to make a class");
|
|
117
|
+
(0, Support_1.assert)(additionalProperties === undefined, "We have additional properties but want to make a class");
|
|
114
118
|
return this.typeBuilder.getUniqueClassType(typeAttributes, this._makeClassesFixed, properties, forwardingRef);
|
|
115
119
|
}
|
|
116
120
|
}
|
|
@@ -122,7 +126,7 @@ class UnifyUnionBuilder extends UnionBuilder_1.UnionBuilder {
|
|
|
122
126
|
}
|
|
123
127
|
exports.UnifyUnionBuilder = UnifyUnionBuilder;
|
|
124
128
|
function unionBuilderForUnification(typeBuilder, makeObjectTypes, makeClassesFixed, conflateNumbers) {
|
|
125
|
-
return new UnifyUnionBuilder(typeBuilder, makeObjectTypes, makeClassesFixed, trefs => unifyTypes(new Set(trefs.map(tref => TypeGraph_1.derefTypeRef(tref, typeBuilder))), TypeAttributes_1.emptyTypeAttributes, typeBuilder, unionBuilderForUnification(typeBuilder, makeObjectTypes, makeClassesFixed, conflateNumbers), conflateNumbers));
|
|
129
|
+
return new UnifyUnionBuilder(typeBuilder, makeObjectTypes, makeClassesFixed, trefs => unifyTypes(new Set(trefs.map(tref => (0, TypeGraph_1.derefTypeRef)(tref, typeBuilder))), TypeAttributes_1.emptyTypeAttributes, typeBuilder, unionBuilderForUnification(typeBuilder, makeObjectTypes, makeClassesFixed, conflateNumbers), conflateNumbers));
|
|
126
130
|
}
|
|
127
131
|
exports.unionBuilderForUnification = unionBuilderForUnification;
|
|
128
132
|
// typeAttributes must not be reconstituted yet.
|
|
@@ -130,10 +134,10 @@ exports.unionBuilderForUnification = unionBuilderForUnification;
|
|
|
130
134
|
function unifyTypes(types, typeAttributes, typeBuilder, unionBuilder, conflateNumbers, maybeForwardingRef) {
|
|
131
135
|
typeAttributes = typeBuilder.reconstituteTypeAttributes(typeAttributes);
|
|
132
136
|
if (types.size === 0) {
|
|
133
|
-
return Support_1.panic("Cannot unify empty set of types");
|
|
137
|
+
return (0, Support_1.panic)("Cannot unify empty set of types");
|
|
134
138
|
}
|
|
135
139
|
else if (types.size === 1) {
|
|
136
|
-
const first = Support_1.defined(collection_utils_1.iterableFirst(types));
|
|
140
|
+
const first = (0, Support_1.defined)((0, collection_utils_1.iterableFirst)(types));
|
|
137
141
|
if (!(first instanceof Type_1.UnionType)) {
|
|
138
142
|
return typeBuilder.reconstituteTypeRef(first.typeRef, typeAttributes, maybeForwardingRef);
|
|
139
143
|
}
|
|
@@ -146,7 +150,7 @@ function unifyTypes(types, typeAttributes, typeBuilder, unionBuilder, conflateNu
|
|
|
146
150
|
}
|
|
147
151
|
const accumulator = new UnionBuilder_1.TypeRefUnionAccumulator(conflateNumbers);
|
|
148
152
|
const nestedAttributes = typeBuilder.reconstituteTypeAttributes(accumulator.addTypes(types));
|
|
149
|
-
typeAttributes = TypeAttributes_1.combineTypeAttributes("union", typeAttributes, nestedAttributes);
|
|
153
|
+
typeAttributes = (0, TypeAttributes_1.combineTypeAttributes)("union", typeAttributes, nestedAttributes);
|
|
150
154
|
return typeBuilder.withForwardingRef(maybeForwardingRef, forwardingRef => {
|
|
151
155
|
typeBuilder.registerUnion(typeRefs, forwardingRef);
|
|
152
156
|
return unionBuilder.buildUnion(accumulator, false, typeAttributes, forwardingRef);
|
|
@@ -10,7 +10,7 @@ export interface UnionTypeProvider<TArrayData, TObjectData> {
|
|
|
10
10
|
getMemberKinds(): TypeAttributeMap<TypeKind>;
|
|
11
11
|
readonly lostTypeAttributes: boolean;
|
|
12
12
|
}
|
|
13
|
-
export
|
|
13
|
+
export type TypeAttributeMap<T extends TypeKind> = Map<T, TypeAttributes>;
|
|
14
14
|
export declare class UnionAccumulator<TArray, TObject> implements UnionTypeProvider<TArray[], TObject[]> {
|
|
15
15
|
private readonly _conflateNumbers;
|
|
16
16
|
private readonly _nonStringTypeAttributes;
|
|
@@ -31,9 +31,9 @@ export declare class UnionAccumulator<TArray, TObject> implements UnionTypeProvi
|
|
|
31
31
|
addEnum(cases: ReadonlySet<string>, attributes: TypeAttributes): void;
|
|
32
32
|
addStringCases(cases: string[], attributes: TypeAttributes): void;
|
|
33
33
|
addStringCase(s: string, count: number, attributes: TypeAttributes): void;
|
|
34
|
-
|
|
34
|
+
get enumCases(): ReadonlySet<string>;
|
|
35
35
|
getMemberKinds(): TypeAttributeMap<TypeKind>;
|
|
36
|
-
|
|
36
|
+
get lostTypeAttributes(): boolean;
|
|
37
37
|
}
|
|
38
38
|
export declare class TypeRefUnionAccumulator extends UnionAccumulator<TypeRef, TypeRef> {
|
|
39
39
|
private addType;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UnionBuilder = exports.TypeRefUnionAccumulator = exports.UnionAccumulator = void 0;
|
|
3
4
|
const collection_utils_1 = require("collection-utils");
|
|
4
5
|
const Type_1 = require("./Type");
|
|
5
6
|
const TypeUtils_1 = require("./TypeUtils");
|
|
@@ -9,7 +10,7 @@ const StringTypes_1 = require("./attributes/StringTypes");
|
|
|
9
10
|
function addAttributes(accumulatorAttributes, newAttributes) {
|
|
10
11
|
if (accumulatorAttributes === undefined)
|
|
11
12
|
return newAttributes;
|
|
12
|
-
return TypeAttributes_1.combineTypeAttributes("union", accumulatorAttributes, newAttributes);
|
|
13
|
+
return (0, TypeAttributes_1.combineTypeAttributes)("union", accumulatorAttributes, newAttributes);
|
|
13
14
|
}
|
|
14
15
|
function setAttributes(attributeMap, kind, newAttributes) {
|
|
15
16
|
attributeMap.set(kind, addAttributes(attributeMap.get(kind), newAttributes));
|
|
@@ -23,22 +24,23 @@ function addAttributesToBuilder(builder, kind, newAttributes) {
|
|
|
23
24
|
arr.push(newAttributes);
|
|
24
25
|
}
|
|
25
26
|
function buildTypeAttributeMap(builder) {
|
|
26
|
-
return collection_utils_1.mapMap(builder, arr => TypeAttributes_1.combineTypeAttributes("union", arr));
|
|
27
|
+
return (0, collection_utils_1.mapMap)(builder, arr => (0, TypeAttributes_1.combineTypeAttributes)("union", arr));
|
|
27
28
|
}
|
|
28
29
|
function moveAttributes(map, fromKind, toKind) {
|
|
29
|
-
const fromAttributes = Support_1.defined(map.get(fromKind));
|
|
30
|
+
const fromAttributes = (0, Support_1.defined)(map.get(fromKind));
|
|
30
31
|
map.delete(fromKind);
|
|
31
32
|
setAttributes(map, toKind, fromAttributes);
|
|
32
33
|
}
|
|
33
34
|
class UnionAccumulator {
|
|
35
|
+
_conflateNumbers;
|
|
36
|
+
_nonStringTypeAttributes = new Map();
|
|
37
|
+
_stringTypeAttributes = new Map();
|
|
38
|
+
arrayData = [];
|
|
39
|
+
objectData = [];
|
|
40
|
+
_enumCases = new Set();
|
|
41
|
+
_lostTypeAttributes = false;
|
|
34
42
|
constructor(_conflateNumbers) {
|
|
35
43
|
this._conflateNumbers = _conflateNumbers;
|
|
36
|
-
this._nonStringTypeAttributes = new Map();
|
|
37
|
-
this._stringTypeAttributes = new Map();
|
|
38
|
-
this.arrayData = [];
|
|
39
|
-
this.objectData = [];
|
|
40
|
-
this._enumCases = new Set();
|
|
41
|
-
this._lostTypeAttributes = false;
|
|
42
44
|
}
|
|
43
45
|
have(kind) {
|
|
44
46
|
return (this._nonStringTypeAttributes.has(kind) || this._stringTypeAttributes.has(kind));
|
|
@@ -54,7 +56,7 @@ class UnionAccumulator {
|
|
|
54
56
|
this._lostTypeAttributes = true;
|
|
55
57
|
}
|
|
56
58
|
addPrimitive(kind, attributes) {
|
|
57
|
-
Support_1.assert(kind !== "any", "any must be added with addAny");
|
|
59
|
+
(0, Support_1.assert)(kind !== "any", "any must be added with addAny");
|
|
58
60
|
addAttributesToBuilder(this._nonStringTypeAttributes, kind, attributes);
|
|
59
61
|
}
|
|
60
62
|
addFullStringType(attributes, stringTypes) {
|
|
@@ -71,7 +73,7 @@ class UnionAccumulator {
|
|
|
71
73
|
}
|
|
72
74
|
const maybeEnumAttributes = this._nonStringTypeAttributes.get("enum");
|
|
73
75
|
if (stringTypes.isRestricted) {
|
|
74
|
-
Support_1.assert(maybeEnumAttributes === undefined, "We can't add both an enum as well as a restricted string type to a union builder");
|
|
76
|
+
(0, Support_1.assert)(maybeEnumAttributes === undefined, "We can't add both an enum as well as a restricted string type to a union builder");
|
|
75
77
|
}
|
|
76
78
|
addAttributesToBuilder(this._stringTypeAttributes, "string", attributes);
|
|
77
79
|
if (stringTypesAttributes !== undefined) {
|
|
@@ -103,7 +105,7 @@ class UnionAccumulator {
|
|
|
103
105
|
return;
|
|
104
106
|
}
|
|
105
107
|
addAttributesToBuilder(this._nonStringTypeAttributes, "enum", attributes);
|
|
106
|
-
collection_utils_1.setUnionInto(this._enumCases, cases);
|
|
108
|
+
(0, collection_utils_1.setUnionInto)(this._enumCases, cases);
|
|
107
109
|
}
|
|
108
110
|
addStringCases(cases, attributes) {
|
|
109
111
|
this.addFullStringType(attributes, StringTypes_1.StringTypes.fromCases(cases));
|
|
@@ -115,14 +117,14 @@ class UnionAccumulator {
|
|
|
115
117
|
return this._enumCases;
|
|
116
118
|
}
|
|
117
119
|
getMemberKinds() {
|
|
118
|
-
Support_1.assert(!(this.have("enum") && this.have("string")), "We can't have both strings and enums in the same union");
|
|
119
|
-
let merged = collection_utils_1.mapMerge(buildTypeAttributeMap(this._nonStringTypeAttributes), buildTypeAttributeMap(this._stringTypeAttributes));
|
|
120
|
+
(0, Support_1.assert)(!(this.have("enum") && this.have("string")), "We can't have both strings and enums in the same union");
|
|
121
|
+
let merged = (0, collection_utils_1.mapMerge)(buildTypeAttributeMap(this._nonStringTypeAttributes), buildTypeAttributeMap(this._stringTypeAttributes));
|
|
120
122
|
if (merged.size === 0) {
|
|
121
123
|
return new Map([["none", TypeAttributes_1.emptyTypeAttributes]]);
|
|
122
124
|
}
|
|
123
125
|
if (this._nonStringTypeAttributes.has("any")) {
|
|
124
|
-
Support_1.assert(this._lostTypeAttributes, "This had to be set when we added 'any'");
|
|
125
|
-
const allAttributes = TypeAttributes_1.combineTypeAttributes("union", Array.from(merged.values()));
|
|
126
|
+
(0, Support_1.assert)(this._lostTypeAttributes, "This had to be set when we added 'any'");
|
|
127
|
+
const allAttributes = (0, TypeAttributes_1.combineTypeAttributes)("union", Array.from(merged.values()));
|
|
126
128
|
return new Map([["any", allAttributes]]);
|
|
127
129
|
}
|
|
128
130
|
if (this._conflateNumbers && this.have("integer") && this.have("double")) {
|
|
@@ -168,9 +170,9 @@ function attributesForTypes(types) {
|
|
|
168
170
|
path.pop();
|
|
169
171
|
}
|
|
170
172
|
else {
|
|
171
|
-
collection_utils_1.mapUpdateInto(unionsForType, t, s => (s === undefined ? new Set(path) : collection_utils_1.setUnionInto(s, path)));
|
|
173
|
+
(0, collection_utils_1.mapUpdateInto)(unionsForType, t, s => (s === undefined ? new Set(path) : (0, collection_utils_1.setUnionInto)(s, path)));
|
|
172
174
|
for (const u of path) {
|
|
173
|
-
collection_utils_1.mapUpdateInto(typesForUnion, u, s => (s === undefined ? new Set([t]) : s.add(t)));
|
|
175
|
+
(0, collection_utils_1.mapUpdateInto)(typesForUnion, u, s => (s === undefined ? new Set([t]) : s.add(t)));
|
|
174
176
|
}
|
|
175
177
|
}
|
|
176
178
|
}
|
|
@@ -179,11 +181,11 @@ function attributesForTypes(types) {
|
|
|
179
181
|
for (const t of typesArray) {
|
|
180
182
|
traverse(t, rootPath, typesArray.length === 1);
|
|
181
183
|
}
|
|
182
|
-
const resultAttributes = collection_utils_1.mapMap(unionsForType, (unionForType, t) => {
|
|
183
|
-
const singleAncestors = Array.from(unionForType).filter(u => Support_1.defined(typesForUnion.get(u)).size === 1);
|
|
184
|
-
Support_1.assert(singleAncestors.every(u => Support_1.defined(typesForUnion.get(u)).has(t)), "We messed up bookkeeping");
|
|
184
|
+
const resultAttributes = (0, collection_utils_1.mapMap)(unionsForType, (unionForType, t) => {
|
|
185
|
+
const singleAncestors = Array.from(unionForType).filter(u => (0, Support_1.defined)(typesForUnion.get(u)).size === 1);
|
|
186
|
+
(0, Support_1.assert)(singleAncestors.every(u => (0, Support_1.defined)(typesForUnion.get(u)).has(t)), "We messed up bookkeeping");
|
|
185
187
|
const inheritedAttributes = singleAncestors.map(u => u.getAttributes());
|
|
186
|
-
return TypeAttributes_1.combineTypeAttributes("union", [t.getAttributes()].concat(inheritedAttributes));
|
|
188
|
+
return (0, TypeAttributes_1.combineTypeAttributes)("union", [t.getAttributes()].concat(inheritedAttributes));
|
|
187
189
|
});
|
|
188
190
|
const unionAttributes = Array.from(unions).map(u => {
|
|
189
191
|
const t = typesForUnion.get(u);
|
|
@@ -194,21 +196,21 @@ function attributesForTypes(types) {
|
|
|
194
196
|
if (unionsEquivalentToRoot.has(u)) {
|
|
195
197
|
return attributes;
|
|
196
198
|
}
|
|
197
|
-
return TypeAttributes_1.makeTypeAttributesInferred(attributes);
|
|
199
|
+
return (0, TypeAttributes_1.makeTypeAttributesInferred)(attributes);
|
|
198
200
|
});
|
|
199
|
-
return [resultAttributes, TypeAttributes_1.combineTypeAttributes("union", unionAttributes)];
|
|
201
|
+
return [resultAttributes, (0, TypeAttributes_1.combineTypeAttributes)("union", unionAttributes)];
|
|
200
202
|
}
|
|
201
203
|
// FIXME: Move this to UnifyClasses.ts?
|
|
202
204
|
class TypeRefUnionAccumulator extends UnionAccumulator {
|
|
203
205
|
// There is a method analogous to this in the IntersectionAccumulator. It might
|
|
204
206
|
// make sense to find a common interface.
|
|
205
207
|
addType(t, attributes) {
|
|
206
|
-
TypeUtils_1.matchTypeExhaustive(t, _noneType => this.addNone(attributes), _anyType => this.addAny(attributes), _nullType => this.addPrimitive("null", attributes), _boolType => this.addPrimitive("bool", attributes), _integerType => this.addPrimitive("integer", attributes), _doubleType => this.addPrimitive("double", attributes), _stringType => this.addStringType("string", attributes), arrayType => this.addArray(arrayType.items.typeRef, attributes), classType => this.addObject(classType.typeRef, attributes), mapType => this.addObject(mapType.typeRef, attributes), objectType => this.addObject(objectType.typeRef, attributes),
|
|
208
|
+
(0, TypeUtils_1.matchTypeExhaustive)(t, _noneType => this.addNone(attributes), _anyType => this.addAny(attributes), _nullType => this.addPrimitive("null", attributes), _boolType => this.addPrimitive("bool", attributes), _integerType => this.addPrimitive("integer", attributes), _doubleType => this.addPrimitive("double", attributes), _stringType => this.addStringType("string", attributes), arrayType => this.addArray(arrayType.items.typeRef, attributes), classType => this.addObject(classType.typeRef, attributes), mapType => this.addObject(mapType.typeRef, attributes), objectType => this.addObject(objectType.typeRef, attributes),
|
|
207
209
|
// FIXME: We're not carrying counts, so this is not correct if we do enum
|
|
208
210
|
// inference. JSON Schema input uses this case, however, without enum
|
|
209
211
|
// inference, which is fine, but still a bit ugly.
|
|
210
212
|
enumType => this.addEnum(enumType.cases, attributes), _unionType => {
|
|
211
|
-
return Support_1.panic("The unions should have been eliminated in attributesForTypesInUnion");
|
|
213
|
+
return (0, Support_1.panic)("The unions should have been eliminated in attributesForTypesInUnion");
|
|
212
214
|
}, transformedStringType => this.addStringType(transformedStringType.kind, attributes));
|
|
213
215
|
}
|
|
214
216
|
addTypes(types) {
|
|
@@ -221,6 +223,7 @@ class TypeRefUnionAccumulator extends UnionAccumulator {
|
|
|
221
223
|
}
|
|
222
224
|
exports.TypeRefUnionAccumulator = TypeRefUnionAccumulator;
|
|
223
225
|
class UnionBuilder {
|
|
226
|
+
typeBuilder;
|
|
224
227
|
constructor(typeBuilder) {
|
|
225
228
|
this.typeBuilder = typeBuilder;
|
|
226
229
|
}
|
|
@@ -235,13 +238,13 @@ class UnionBuilder {
|
|
|
235
238
|
case "array":
|
|
236
239
|
return this.makeArray(typeProvider.arrayData, typeAttributes, forwardingRef);
|
|
237
240
|
default:
|
|
238
|
-
if (Type_1.isPrimitiveTypeKind(kind)) {
|
|
241
|
+
if ((0, Type_1.isPrimitiveTypeKind)(kind)) {
|
|
239
242
|
return this.typeBuilder.getPrimitiveType(kind, typeAttributes, forwardingRef);
|
|
240
243
|
}
|
|
241
244
|
if (kind === "union" || kind === "class" || kind === "map" || kind === "intersection") {
|
|
242
|
-
return Support_1.panic(`getMemberKinds() shouldn't return ${kind}`);
|
|
245
|
+
return (0, Support_1.panic)(`getMemberKinds() shouldn't return ${kind}`);
|
|
243
246
|
}
|
|
244
|
-
return Support_1.assertNever(kind);
|
|
247
|
+
return (0, Support_1.assertNever)(kind);
|
|
245
248
|
}
|
|
246
249
|
}
|
|
247
250
|
buildUnion(typeProvider, unique, typeAttributes, forwardingRef) {
|
|
@@ -255,7 +258,7 @@ class UnionBuilder {
|
|
|
255
258
|
// right now, it's just a very bad way of surfacing that error.
|
|
256
259
|
if (kinds.size === 1) {
|
|
257
260
|
const [[kind, memberAttributes]] = Array.from(kinds);
|
|
258
|
-
const allAttributes = TypeAttributes_1.combineTypeAttributes("union", typeAttributes, TypeAttributes_1.increaseTypeAttributesDistance(memberAttributes));
|
|
261
|
+
const allAttributes = (0, TypeAttributes_1.combineTypeAttributes)("union", typeAttributes, (0, TypeAttributes_1.increaseTypeAttributesDistance)(memberAttributes));
|
|
259
262
|
const t = this.makeTypeOfKind(typeProvider, kind, allAttributes, forwardingRef);
|
|
260
263
|
return t;
|
|
261
264
|
}
|
|
@@ -2,8 +2,8 @@ import { TypeAttributeKind, TypeAttributes } from "./TypeAttributes";
|
|
|
2
2
|
import { EnumType, UnionType, Type, ObjectType } from "../Type";
|
|
3
3
|
import { JSONSchema } from "../input/JSONSchemaStore";
|
|
4
4
|
import { Ref, JSONSchemaType, JSONSchemaAttributes } from "../input/JSONSchemaInput";
|
|
5
|
-
export
|
|
6
|
-
export
|
|
5
|
+
export type AccessorEntry = string | Map<string, string>;
|
|
6
|
+
export type AccessorNames = Map<string, AccessorEntry>;
|
|
7
7
|
export declare const accessorNamesTypeAttributeKind: TypeAttributeKind<AccessorNames>;
|
|
8
8
|
export declare function lookupKey(accessors: AccessorNames, key: string, language: string): [string, boolean] | undefined;
|
|
9
9
|
export declare function objectPropertyNames(o: ObjectType, language: string): Map<string, [string, boolean] | undefined>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.accessorNamesAttributeProducer = exports.makeAccessorNames = exports.unionMemberName = exports.makeUnionMemberNamesAttribute = exports.unionMemberNamesTypeAttributeKind = exports.makeUnionIdentifierAttribute = exports.unionIdentifierTypeAttributeKind = exports.getAccessorName = exports.enumCaseNames = exports.objectPropertyNames = exports.lookupKey = exports.accessorNamesTypeAttributeKind = void 0;
|
|
3
4
|
const collection_utils_1 = require("collection-utils");
|
|
4
5
|
const TypeAttributes_1 = require("./TypeAttributes");
|
|
5
6
|
const Support_1 = require("../support/Support");
|
|
@@ -36,15 +37,15 @@ function objectPropertyNames(o, language) {
|
|
|
36
37
|
const accessors = exports.accessorNamesTypeAttributeKind.tryGetInAttributes(o.getAttributes());
|
|
37
38
|
const map = o.getProperties();
|
|
38
39
|
if (accessors === undefined)
|
|
39
|
-
return collection_utils_1.mapMap(map, _ => undefined);
|
|
40
|
-
return collection_utils_1.mapMap(map, (_cp, n) => lookupKey(accessors, n, language));
|
|
40
|
+
return (0, collection_utils_1.mapMap)(map, _ => undefined);
|
|
41
|
+
return (0, collection_utils_1.mapMap)(map, (_cp, n) => lookupKey(accessors, n, language));
|
|
41
42
|
}
|
|
42
43
|
exports.objectPropertyNames = objectPropertyNames;
|
|
43
44
|
function enumCaseNames(e, language) {
|
|
44
45
|
const accessors = exports.accessorNamesTypeAttributeKind.tryGetInAttributes(e.getAttributes());
|
|
45
46
|
if (accessors === undefined)
|
|
46
|
-
return collection_utils_1.mapMap(e.cases.entries(), _ => undefined);
|
|
47
|
-
return collection_utils_1.mapMap(e.cases.entries(), c => lookupKey(accessors, c, language));
|
|
47
|
+
return (0, collection_utils_1.mapMap)(e.cases.entries(), _ => undefined);
|
|
48
|
+
return (0, collection_utils_1.mapMap)(e.cases.entries(), c => lookupKey(accessors, c, language));
|
|
48
49
|
}
|
|
49
50
|
exports.enumCaseNames = enumCaseNames;
|
|
50
51
|
function getAccessorName(names, original) {
|
|
@@ -66,7 +67,7 @@ class UnionIdentifierTypeAttributeKind extends TypeAttributes_1.TypeAttributeKin
|
|
|
66
67
|
super("unionIdentifier");
|
|
67
68
|
}
|
|
68
69
|
combine(arr) {
|
|
69
|
-
return collection_utils_1.setUnionManyInto(new Set(), arr);
|
|
70
|
+
return (0, collection_utils_1.setUnionManyInto)(new Set(), arr);
|
|
70
71
|
}
|
|
71
72
|
makeInferred(_) {
|
|
72
73
|
return new Set();
|
|
@@ -87,15 +88,15 @@ class UnionMemberNamesTypeAttributeKind extends TypeAttributes_1.TypeAttributeKi
|
|
|
87
88
|
combine(arr) {
|
|
88
89
|
const result = new Map();
|
|
89
90
|
for (const m of arr) {
|
|
90
|
-
collection_utils_1.mapMergeInto(result, m);
|
|
91
|
+
(0, collection_utils_1.mapMergeInto)(result, m);
|
|
91
92
|
}
|
|
92
93
|
return result;
|
|
93
94
|
}
|
|
94
95
|
}
|
|
95
96
|
exports.unionMemberNamesTypeAttributeKind = new UnionMemberNamesTypeAttributeKind();
|
|
96
97
|
function makeUnionMemberNamesAttribute(unionAttributes, entry) {
|
|
97
|
-
const identifiers = Support_1.defined(exports.unionIdentifierTypeAttributeKind.tryGetInAttributes(unionAttributes));
|
|
98
|
-
const map = collection_utils_1.mapFromIterable(identifiers, _ => entry);
|
|
98
|
+
const identifiers = (0, Support_1.defined)(exports.unionIdentifierTypeAttributeKind.tryGetInAttributes(unionAttributes));
|
|
99
|
+
const map = (0, collection_utils_1.mapFromIterable)(identifiers, _ => entry);
|
|
99
100
|
return exports.unionMemberNamesTypeAttributeKind.makeAttributes(map);
|
|
100
101
|
}
|
|
101
102
|
exports.makeUnionMemberNamesAttribute = makeUnionMemberNamesAttribute;
|
|
@@ -125,19 +126,19 @@ function unionMemberName(u, member, language) {
|
|
|
125
126
|
}
|
|
126
127
|
let size;
|
|
127
128
|
let isFixed;
|
|
128
|
-
let first = collection_utils_1.iterableFirst(fixedNames);
|
|
129
|
+
let first = (0, collection_utils_1.iterableFirst)(fixedNames);
|
|
129
130
|
if (first !== undefined) {
|
|
130
131
|
size = fixedNames.size;
|
|
131
132
|
isFixed = true;
|
|
132
133
|
}
|
|
133
134
|
else {
|
|
134
|
-
first = collection_utils_1.iterableFirst(names);
|
|
135
|
+
first = (0, collection_utils_1.iterableFirst)(names);
|
|
135
136
|
if (first === undefined)
|
|
136
137
|
return [undefined, false];
|
|
137
138
|
size = names.size;
|
|
138
139
|
isFixed = false;
|
|
139
140
|
}
|
|
140
|
-
Messages_1.messageAssert(size === 1, "SchemaMoreThanOneUnionMemberName", { names: Array.from(names) });
|
|
141
|
+
(0, Messages_1.messageAssert)(size === 1, "SchemaMoreThanOneUnionMemberName", { names: Array.from(names) });
|
|
141
142
|
return [first, isFixed];
|
|
142
143
|
}
|
|
143
144
|
exports.unionMemberName = unionMemberName;
|
|
@@ -145,17 +146,17 @@ function isAccessorEntry(x) {
|
|
|
145
146
|
if (typeof x === "string") {
|
|
146
147
|
return true;
|
|
147
148
|
}
|
|
148
|
-
return Support_1.isStringMap(x, (v) => typeof v === "string");
|
|
149
|
+
return (0, Support_1.isStringMap)(x, (v) => typeof v === "string");
|
|
149
150
|
}
|
|
150
151
|
function makeAccessorEntry(ae) {
|
|
151
152
|
if (typeof ae === "string")
|
|
152
153
|
return ae;
|
|
153
|
-
return collection_utils_1.mapFromObject(ae);
|
|
154
|
+
return (0, collection_utils_1.mapFromObject)(ae);
|
|
154
155
|
}
|
|
155
156
|
function makeAccessorNames(x) {
|
|
156
157
|
// FIXME: Do proper error reporting
|
|
157
|
-
const stringMap = Support_1.checkStringMap(x, isAccessorEntry);
|
|
158
|
-
return collection_utils_1.mapMap(collection_utils_1.mapFromObject(stringMap), makeAccessorEntry);
|
|
158
|
+
const stringMap = (0, Support_1.checkStringMap)(x, isAccessorEntry);
|
|
159
|
+
return (0, collection_utils_1.mapMap)((0, collection_utils_1.mapFromObject)(stringMap), makeAccessorEntry);
|
|
159
160
|
}
|
|
160
161
|
exports.makeAccessorNames = makeAccessorNames;
|
|
161
162
|
function accessorNamesAttributeProducer(schema, canonicalRef, _types, cases) {
|
|
@@ -169,8 +170,8 @@ function accessorNamesAttributeProducer(schema, canonicalRef, _types, cases) {
|
|
|
169
170
|
}
|
|
170
171
|
else {
|
|
171
172
|
const identifierAttribute = makeUnionIdentifierAttribute();
|
|
172
|
-
const accessors = Support_1.checkArray(maybeAccessors, isAccessorEntry);
|
|
173
|
-
Messages_1.messageAssert(cases.length === accessors.length, "SchemaWrongAccessorEntryArrayLength", {
|
|
173
|
+
const accessors = (0, Support_1.checkArray)(maybeAccessors, isAccessorEntry);
|
|
174
|
+
(0, Messages_1.messageAssert)(cases.length === accessors.length, "SchemaWrongAccessorEntryArrayLength", {
|
|
174
175
|
operation: "oneOf",
|
|
175
176
|
ref: canonicalRef.push("oneOf")
|
|
176
177
|
});
|
|
@@ -2,13 +2,13 @@ import { Type, TypeKind } from "../Type";
|
|
|
2
2
|
import { TypeAttributeKind } from "./TypeAttributes";
|
|
3
3
|
import { JSONSchemaType, JSONSchemaAttributes, Ref } from "../input/JSONSchemaInput";
|
|
4
4
|
import { JSONSchema } from "../input/JSONSchemaStore";
|
|
5
|
-
export
|
|
5
|
+
export type MinMaxConstraint = [number | undefined, number | undefined];
|
|
6
6
|
export declare class MinMaxConstraintTypeAttributeKind extends TypeAttributeKind<MinMaxConstraint> {
|
|
7
7
|
private _typeKinds;
|
|
8
8
|
private _minSchemaProperty;
|
|
9
9
|
private _maxSchemaProperty;
|
|
10
10
|
constructor(name: string, _typeKinds: Set<TypeKind>, _minSchemaProperty: string, _maxSchemaProperty: string);
|
|
11
|
-
|
|
11
|
+
get inIdentity(): boolean;
|
|
12
12
|
combine(arr: MinMaxConstraint[]): MinMaxConstraint | undefined;
|
|
13
13
|
intersect(arr: MinMaxConstraint[]): MinMaxConstraint | undefined;
|
|
14
14
|
makeInferred(_: MinMaxConstraint): undefined;
|
|
@@ -25,7 +25,7 @@ export declare function minMaxValueForType(t: Type): MinMaxConstraint | undefine
|
|
|
25
25
|
export declare function minMaxLengthForType(t: Type): MinMaxConstraint | undefined;
|
|
26
26
|
export declare class PatternTypeAttributeKind extends TypeAttributeKind<string> {
|
|
27
27
|
constructor();
|
|
28
|
-
|
|
28
|
+
get inIdentity(): boolean;
|
|
29
29
|
combine(arr: string[]): string;
|
|
30
30
|
intersect(_arr: string[]): string | undefined;
|
|
31
31
|
makeInferred(_: string): undefined;
|