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