quicktype 18.0.6 → 19.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. package/README.md +1 -1
  2. package/dist/{cli/CompressedJSONFromStream.d.ts → CompressedJSONFromStream.d.ts} +1 -1
  3. package/dist/{cli/CompressedJSONFromStream.js → CompressedJSONFromStream.js} +2 -2
  4. package/dist/{cli/GraphQLIntrospection.d.ts → GraphQLIntrospection.d.ts} +0 -0
  5. package/dist/{cli/GraphQLIntrospection.js → GraphQLIntrospection.js} +1 -1
  6. package/dist/{cli/TypeSource.d.ts → TypeSource.d.ts} +2 -2
  7. package/dist/{cli/TypeSource.js → TypeSource.js} +0 -0
  8. package/dist/{cli/URLGrammar.d.ts → URLGrammar.d.ts} +0 -0
  9. package/dist/{cli/URLGrammar.js → URLGrammar.js} +1 -1
  10. package/dist/{cli/index.d.ts → index.d.ts} +1 -1
  11. package/dist/{cli/index.js → index.js} +4 -5
  12. package/package.json +61 -77
  13. package/dist/quicktype-core/Annotation.d.ts +0 -8
  14. package/dist/quicktype-core/Annotation.js +0 -16
  15. package/dist/quicktype-core/ConvenienceRenderer.d.ts +0 -138
  16. package/dist/quicktype-core/ConvenienceRenderer.js +0 -668
  17. package/dist/quicktype-core/DateTime.d.ts +0 -10
  18. package/dist/quicktype-core/DateTime.js +0 -57
  19. package/dist/quicktype-core/DeclarationIR.d.ts +0 -14
  20. package/dist/quicktype-core/DeclarationIR.js +0 -167
  21. package/dist/quicktype-core/EncodedMarkovChain.d.ts +0 -1
  22. package/dist/quicktype-core/EncodedMarkovChain.js +0 -4
  23. package/dist/quicktype-core/GatherNames.d.ts +0 -2
  24. package/dist/quicktype-core/GatherNames.js +0 -333
  25. package/dist/quicktype-core/Graph.d.ts +0 -12
  26. package/dist/quicktype-core/Graph.js +0 -220
  27. package/dist/quicktype-core/GraphRewriting.d.ts +0 -87
  28. package/dist/quicktype-core/GraphRewriting.js +0 -421
  29. package/dist/quicktype-core/MakeTransformations.d.ts +0 -4
  30. package/dist/quicktype-core/MakeTransformations.js +0 -193
  31. package/dist/quicktype-core/MarkovChain.d.ts +0 -15
  32. package/dist/quicktype-core/MarkovChain.js +0 -154
  33. package/dist/quicktype-core/Messages.d.ts +0 -294
  34. package/dist/quicktype-core/Messages.js +0 -105
  35. package/dist/quicktype-core/Naming.d.ts +0 -64
  36. package/dist/quicktype-core/Naming.js +0 -356
  37. package/dist/quicktype-core/Renderer.d.ts +0 -50
  38. package/dist/quicktype-core/Renderer.js +0 -274
  39. package/dist/quicktype-core/RendererOptions.d.ts +0 -71
  40. package/dist/quicktype-core/RendererOptions.js +0 -141
  41. package/dist/quicktype-core/Run.d.ts +0 -174
  42. package/dist/quicktype-core/Run.js +0 -393
  43. package/dist/quicktype-core/Source.d.ts +0 -65
  44. package/dist/quicktype-core/Source.js +0 -204
  45. package/dist/quicktype-core/TargetLanguage.d.ts +0 -34
  46. package/dist/quicktype-core/TargetLanguage.js +0 -66
  47. package/dist/quicktype-core/Transformers.d.ts +0 -209
  48. package/dist/quicktype-core/Transformers.js +0 -836
  49. package/dist/quicktype-core/Type.d.ts +0 -206
  50. package/dist/quicktype-core/Type.js +0 -716
  51. package/dist/quicktype-core/TypeBuilder.d.ts +0 -61
  52. package/dist/quicktype-core/TypeBuilder.js +0 -324
  53. package/dist/quicktype-core/TypeGraph.d.ts +0 -75
  54. package/dist/quicktype-core/TypeGraph.js +0 -420
  55. package/dist/quicktype-core/TypeUtils.d.ts +0 -33
  56. package/dist/quicktype-core/TypeUtils.js +0 -230
  57. package/dist/quicktype-core/UnifyClasses.d.ts +0 -16
  58. package/dist/quicktype-core/UnifyClasses.js +0 -159
  59. package/dist/quicktype-core/UnionBuilder.d.ts +0 -49
  60. package/dist/quicktype-core/UnionBuilder.js +0 -282
  61. package/dist/quicktype-core/attributes/AccessorNames.d.ts +0 -18
  62. package/dist/quicktype-core/attributes/AccessorNames.js +0 -182
  63. package/dist/quicktype-core/attributes/Constraints.d.ts +0 -38
  64. package/dist/quicktype-core/attributes/Constraints.js +0 -172
  65. package/dist/quicktype-core/attributes/Description.d.ts +0 -9
  66. package/dist/quicktype-core/attributes/Description.js +0 -97
  67. package/dist/quicktype-core/attributes/EnumValues.d.ts +0 -8
  68. package/dist/quicktype-core/attributes/EnumValues.js +0 -31
  69. package/dist/quicktype-core/attributes/StringTypes.d.ts +0 -28
  70. package/dist/quicktype-core/attributes/StringTypes.js +0 -189
  71. package/dist/quicktype-core/attributes/TypeAttributes.d.ts +0 -34
  72. package/dist/quicktype-core/attributes/TypeAttributes.js +0 -119
  73. package/dist/quicktype-core/attributes/TypeNames.d.ts +0 -46
  74. package/dist/quicktype-core/attributes/TypeNames.js +0 -274
  75. package/dist/quicktype-core/attributes/URIAttributes.d.ts +0 -8
  76. package/dist/quicktype-core/attributes/URIAttributes.js +0 -85
  77. package/dist/quicktype-core/index.d.ts +0 -48
  78. package/dist/quicktype-core/index.js +0 -180
  79. package/dist/quicktype-core/input/CompressedJSON.d.ts +0 -69
  80. package/dist/quicktype-core/input/CompressedJSON.js +0 -276
  81. package/dist/quicktype-core/input/FetchingJSONSchemaStore.d.ts +0 -6
  82. package/dist/quicktype-core/input/FetchingJSONSchemaStore.js +0 -18
  83. package/dist/quicktype-core/input/Inference.d.ts +0 -22
  84. package/dist/quicktype-core/input/Inference.js +0 -240
  85. package/dist/quicktype-core/input/Inputs.d.ts +0 -48
  86. package/dist/quicktype-core/input/Inputs.js +0 -145
  87. package/dist/quicktype-core/input/JSONSchemaInput.d.ts +0 -91
  88. package/dist/quicktype-core/input/JSONSchemaInput.js +0 -1041
  89. package/dist/quicktype-core/input/JSONSchemaStore.d.ts +0 -8
  90. package/dist/quicktype-core/input/JSONSchemaStore.js +0 -36
  91. package/dist/quicktype-core/input/PostmanCollection.d.ts +0 -5
  92. package/dist/quicktype-core/input/PostmanCollection.js +0 -60
  93. package/dist/quicktype-core/input/io/NodeIO.d.ts +0 -3
  94. package/dist/quicktype-core/input/io/NodeIO.js +0 -87
  95. package/dist/quicktype-core/input/io/get-stream/buffer-stream.d.ts +0 -2
  96. package/dist/quicktype-core/input/io/get-stream/buffer-stream.js +0 -45
  97. package/dist/quicktype-core/input/io/get-stream/index.d.ts +0 -9
  98. package/dist/quicktype-core/input/io/get-stream/index.js +0 -52
  99. package/dist/quicktype-core/language/All.d.ts +0 -3
  100. package/dist/quicktype-core/language/All.js +0 -57
  101. package/dist/quicktype-core/language/CPlusPlus.d.ts +0 -241
  102. package/dist/quicktype-core/language/CPlusPlus.js +0 -1847
  103. package/dist/quicktype-core/language/CSharp.d.ts +0 -201
  104. package/dist/quicktype-core/language/CSharp.js +0 -1850
  105. package/dist/quicktype-core/language/Crystal.d.ts +0 -37
  106. package/dist/quicktype-core/language/Crystal.js +0 -337
  107. package/dist/quicktype-core/language/Dart.d.ts +0 -66
  108. package/dist/quicktype-core/language/Dart.js +0 -576
  109. package/dist/quicktype-core/language/Elm.d.ts +0 -58
  110. package/dist/quicktype-core/language/Elm.js +0 -522
  111. package/dist/quicktype-core/language/Golang.d.ts +0 -51
  112. package/dist/quicktype-core/language/Golang.js +0 -460
  113. package/dist/quicktype-core/language/Haskell.d.ts +0 -56
  114. package/dist/quicktype-core/language/Haskell.js +0 -411
  115. package/dist/quicktype-core/language/JSONSchema.d.ts +0 -31
  116. package/dist/quicktype-core/language/JSONSchema.js +0 -169
  117. package/dist/quicktype-core/language/Java.d.ts +0 -125
  118. package/dist/quicktype-core/language/Java.js +0 -1081
  119. package/dist/quicktype-core/language/JavaScript.d.ts +0 -68
  120. package/dist/quicktype-core/language/JavaScript.js +0 -435
  121. package/dist/quicktype-core/language/JavaScriptPropTypes.d.ts +0 -40
  122. package/dist/quicktype-core/language/JavaScriptPropTypes.js +0 -213
  123. package/dist/quicktype-core/language/JavaScriptUnicodeMaps.d.ts +0 -2
  124. package/dist/quicktype-core/language/JavaScriptUnicodeMaps.js +0 -134
  125. package/dist/quicktype-core/language/Kotlin.d.ts +0 -109
  126. package/dist/quicktype-core/language/Kotlin.js +0 -832
  127. package/dist/quicktype-core/language/Objective-C.d.ts +0 -79
  128. package/dist/quicktype-core/language/Objective-C.js +0 -777
  129. package/dist/quicktype-core/language/Php.d.ts +0 -80
  130. package/dist/quicktype-core/language/Php.js +0 -702
  131. package/dist/quicktype-core/language/Pike.d.ts +0 -37
  132. package/dist/quicktype-core/language/Pike.js +0 -276
  133. package/dist/quicktype-core/language/Python.d.ts +0 -107
  134. package/dist/quicktype-core/language/Python.js +0 -969
  135. package/dist/quicktype-core/language/Rust.d.ts +0 -56
  136. package/dist/quicktype-core/language/Rust.js +0 -309
  137. package/dist/quicktype-core/language/Swift.d.ts +0 -96
  138. package/dist/quicktype-core/language/Swift.js +0 -1211
  139. package/dist/quicktype-core/language/TypeScriptFlow.d.ts +0 -77
  140. package/dist/quicktype-core/language/TypeScriptFlow.js +0 -286
  141. package/dist/quicktype-core/language/ruby/index.d.ts +0 -52
  142. package/dist/quicktype-core/language/ruby/index.js +0 -557
  143. package/dist/quicktype-core/language/ruby/keywords.d.ts +0 -3
  144. package/dist/quicktype-core/language/ruby/keywords.js +0 -358
  145. package/dist/quicktype-core/rewrites/CombineClasses.d.ts +0 -3
  146. package/dist/quicktype-core/rewrites/CombineClasses.js +0 -125
  147. package/dist/quicktype-core/rewrites/ExpandStrings.d.ts +0 -4
  148. package/dist/quicktype-core/rewrites/ExpandStrings.js +0 -143
  149. package/dist/quicktype-core/rewrites/FlattenStrings.d.ts +0 -3
  150. package/dist/quicktype-core/rewrites/FlattenStrings.js +0 -45
  151. package/dist/quicktype-core/rewrites/FlattenUnions.d.ts +0 -3
  152. package/dist/quicktype-core/rewrites/FlattenUnions.js +0 -47
  153. package/dist/quicktype-core/rewrites/InferMaps.d.ts +0 -3
  154. package/dist/quicktype-core/rewrites/InferMaps.js +0 -117
  155. package/dist/quicktype-core/rewrites/ReplaceObjectType.d.ts +0 -3
  156. package/dist/quicktype-core/rewrites/ReplaceObjectType.js +0 -60
  157. package/dist/quicktype-core/rewrites/ResolveIntersections.d.ts +0 -3
  158. package/dist/quicktype-core/rewrites/ResolveIntersections.js +0 -244
  159. package/dist/quicktype-core/support/Acronyms.d.ts +0 -10
  160. package/dist/quicktype-core/support/Acronyms.js +0 -1128
  161. package/dist/quicktype-core/support/Chance.d.ts +0 -38
  162. package/dist/quicktype-core/support/Chance.js +0 -2146
  163. package/dist/quicktype-core/support/Converters.d.ts +0 -6
  164. package/dist/quicktype-core/support/Converters.js +0 -16
  165. package/dist/quicktype-core/support/Strings.d.ts +0 -44
  166. package/dist/quicktype-core/support/Strings.js +0 -525
  167. package/dist/quicktype-core/support/Support.d.ts +0 -29
  168. package/dist/quicktype-core/support/Support.js +0 -162
  169. package/dist/quicktype-graphql-input/GraphQLSchema.d.ts +0 -645
  170. package/dist/quicktype-graphql-input/GraphQLSchema.js +0 -39
  171. package/dist/quicktype-graphql-input/index.d.ts +0 -17
  172. package/dist/quicktype-graphql-input/index.js +0 -407
  173. package/dist/quicktype-typescript-input/index.d.ts +0 -2
  174. package/dist/quicktype-typescript-input/index.js +0 -98
@@ -1,61 +0,0 @@
1
- import { PrimitiveTypeKind, Type, PrimitiveStringTypeKind, ClassProperty, MaybeTypeIdentity, TransformedStringTypeKind } from "./Type";
2
- import { TypeGraph, TypeRef } from "./TypeGraph";
3
- import { TypeAttributes, TypeAttributeKind } from "./attributes/TypeAttributes";
4
- import { StringTypes } from "./attributes/StringTypes";
5
- export declare const provenanceTypeAttributeKind: TypeAttributeKind<Set<number>>;
6
- export type StringTypeMapping = ReadonlyMap<TransformedStringTypeKind, PrimitiveStringTypeKind>;
7
- export declare function stringTypeMappingGet(stm: StringTypeMapping, kind: TransformedStringTypeKind): PrimitiveStringTypeKind;
8
- export declare function getNoStringTypeMapping(): StringTypeMapping;
9
- export declare class TypeBuilder {
10
- private readonly _stringTypeMapping;
11
- readonly canonicalOrder: boolean;
12
- private readonly _allPropertiesOptional;
13
- private readonly _addProvenanceAttributes;
14
- readonly typeGraph: TypeGraph;
15
- protected readonly topLevels: Map<string, TypeRef>;
16
- protected readonly types: (Type | undefined)[];
17
- private readonly typeAttributes;
18
- private _addedForwardingIntersection;
19
- constructor(typeGraphSerial: number, _stringTypeMapping: StringTypeMapping, canonicalOrder: boolean, _allPropertiesOptional: boolean, _addProvenanceAttributes: boolean, inheritsProvenanceAttributes: boolean);
20
- addTopLevel(name: string, tref: TypeRef): void;
21
- reserveTypeRef(): TypeRef;
22
- private assertTypeRefGraph;
23
- private assertTypeRefSetGraph;
24
- private filterTypeAttributes;
25
- private commitType;
26
- protected addType<T extends Type>(forwardingRef: TypeRef | undefined, creator: (tref: TypeRef) => T, attributes: TypeAttributes | undefined): TypeRef;
27
- typeAtIndex(index: number): Type;
28
- atIndex(index: number): [Type, TypeAttributes];
29
- addAttributes(tref: TypeRef, attributes: TypeAttributes): void;
30
- finish(): TypeGraph;
31
- protected addForwardingIntersection(forwardingRef: TypeRef, tref: TypeRef): TypeRef;
32
- protected forwardIfNecessary(forwardingRef: TypeRef | undefined, tref: undefined): undefined;
33
- protected forwardIfNecessary(forwardingRef: TypeRef | undefined, tref: TypeRef): TypeRef;
34
- protected forwardIfNecessary(forwardingRef: TypeRef | undefined, tref: TypeRef | undefined): TypeRef | undefined;
35
- get didAddForwardingIntersection(): boolean;
36
- private readonly _typeForIdentity;
37
- private registerTypeForIdentity;
38
- protected makeIdentity(maker: () => MaybeTypeIdentity): MaybeTypeIdentity;
39
- private getOrAddType;
40
- private registerType;
41
- getPrimitiveType(kind: PrimitiveTypeKind, maybeAttributes?: TypeAttributes, forwardingRef?: TypeRef): TypeRef;
42
- getStringType(attributes: TypeAttributes, stringTypes: StringTypes | undefined, forwardingRef?: TypeRef): TypeRef;
43
- getEnumType(attributes: TypeAttributes, cases: ReadonlySet<string>, forwardingRef?: TypeRef): TypeRef;
44
- makeClassProperty(tref: TypeRef, isOptional: boolean): ClassProperty;
45
- getUniqueObjectType(attributes: TypeAttributes, properties: ReadonlyMap<string, ClassProperty> | undefined, additionalProperties: TypeRef | undefined, forwardingRef?: TypeRef): TypeRef;
46
- getUniqueMapType(forwardingRef?: TypeRef): TypeRef;
47
- getMapType(attributes: TypeAttributes, values: TypeRef, forwardingRef?: TypeRef): TypeRef;
48
- setObjectProperties(ref: TypeRef, properties: ReadonlyMap<string, ClassProperty>, additionalProperties: TypeRef | undefined): void;
49
- getUniqueArrayType(forwardingRef?: TypeRef): TypeRef;
50
- getArrayType(attributes: TypeAttributes, items: TypeRef, forwardingRef?: TypeRef): TypeRef;
51
- setArrayItems(ref: TypeRef, items: TypeRef): void;
52
- modifyPropertiesIfNecessary(properties: ReadonlyMap<string, ClassProperty>): ReadonlyMap<string, ClassProperty>;
53
- getClassType(attributes: TypeAttributes, properties: ReadonlyMap<string, ClassProperty>, forwardingRef?: TypeRef): TypeRef;
54
- getUniqueClassType(attributes: TypeAttributes, isFixed: boolean, properties: ReadonlyMap<string, ClassProperty> | undefined, forwardingRef?: TypeRef): TypeRef;
55
- getUnionType(attributes: TypeAttributes, members: ReadonlySet<TypeRef>, forwardingRef?: TypeRef): TypeRef;
56
- getUniqueUnionType(attributes: TypeAttributes, members: ReadonlySet<TypeRef> | undefined, forwardingRef?: TypeRef): TypeRef;
57
- getIntersectionType(attributes: TypeAttributes, members: ReadonlySet<TypeRef>, forwardingRef?: TypeRef): TypeRef;
58
- getUniqueIntersectionType(attributes: TypeAttributes, members: ReadonlySet<TypeRef> | undefined, forwardingRef?: TypeRef): TypeRef;
59
- setSetOperationMembers(ref: TypeRef, members: ReadonlySet<TypeRef>): void;
60
- setLostTypeAttributes(): void;
61
- }
@@ -1,324 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TypeBuilder = exports.getNoStringTypeMapping = exports.stringTypeMappingGet = exports.provenanceTypeAttributeKind = void 0;
4
- const collection_utils_1 = require("collection-utils");
5
- const Type_1 = require("./Type");
6
- const TypeGraph_1 = require("./TypeGraph");
7
- const TypeAttributes_1 = require("./attributes/TypeAttributes");
8
- const Support_1 = require("./support/Support");
9
- const StringTypes_1 = require("./attributes/StringTypes");
10
- // FIXME: Don't infer provenance. All original types should be present in
11
- // non-inferred form in the final graph.
12
- class ProvenanceTypeAttributeKind extends TypeAttributes_1.TypeAttributeKind {
13
- constructor() {
14
- super("provenance");
15
- }
16
- appliesToTypeKind(_kind) {
17
- return true;
18
- }
19
- combine(arr) {
20
- return (0, collection_utils_1.setUnionManyInto)(new Set(), arr);
21
- }
22
- makeInferred(p) {
23
- return p;
24
- }
25
- stringify(p) {
26
- return Array.from(p)
27
- .sort()
28
- .map(i => i.toString())
29
- .join(",");
30
- }
31
- }
32
- exports.provenanceTypeAttributeKind = new ProvenanceTypeAttributeKind();
33
- function stringTypeMappingGet(stm, kind) {
34
- const mapped = stm.get(kind);
35
- if (mapped === undefined)
36
- return "string";
37
- return mapped;
38
- }
39
- exports.stringTypeMappingGet = stringTypeMappingGet;
40
- let noStringTypeMapping;
41
- function getNoStringTypeMapping() {
42
- if (noStringTypeMapping === undefined) {
43
- noStringTypeMapping = new Map(Array.from(Type_1.transformedStringTypeKinds).map(k => [k, k]));
44
- }
45
- return noStringTypeMapping;
46
- }
47
- exports.getNoStringTypeMapping = getNoStringTypeMapping;
48
- class TypeBuilder {
49
- _stringTypeMapping;
50
- canonicalOrder;
51
- _allPropertiesOptional;
52
- _addProvenanceAttributes;
53
- typeGraph;
54
- topLevels = new Map();
55
- types = [];
56
- typeAttributes = [];
57
- _addedForwardingIntersection = false;
58
- constructor(typeGraphSerial, _stringTypeMapping, canonicalOrder, _allPropertiesOptional, _addProvenanceAttributes, inheritsProvenanceAttributes) {
59
- this._stringTypeMapping = _stringTypeMapping;
60
- this.canonicalOrder = canonicalOrder;
61
- this._allPropertiesOptional = _allPropertiesOptional;
62
- this._addProvenanceAttributes = _addProvenanceAttributes;
63
- (0, Support_1.assert)(!_addProvenanceAttributes || !inheritsProvenanceAttributes, "We can't both inherit as well as add provenance");
64
- this.typeGraph = new TypeGraph_1.TypeGraph(this, typeGraphSerial, _addProvenanceAttributes || inheritsProvenanceAttributes);
65
- }
66
- addTopLevel(name, tref) {
67
- // assert(t.typeGraph === this.typeGraph, "Adding top-level to wrong type graph");
68
- (0, Support_1.assert)(!this.topLevels.has(name), "Trying to add top-level with existing name");
69
- (0, Support_1.assert)(this.types[(0, TypeGraph_1.typeRefIndex)(tref)] !== undefined, "Trying to add a top-level type that doesn't exist (yet?)");
70
- this.topLevels.set(name, tref);
71
- }
72
- reserveTypeRef() {
73
- const index = this.types.length;
74
- // console.log(`reserving ${index}`);
75
- this.types.push(undefined);
76
- const tref = (0, TypeGraph_1.makeTypeRef)(this.typeGraph, index);
77
- const attributes = this._addProvenanceAttributes
78
- ? exports.provenanceTypeAttributeKind.makeAttributes(new Set([index]))
79
- : TypeAttributes_1.emptyTypeAttributes;
80
- this.typeAttributes.push(attributes);
81
- return tref;
82
- }
83
- assertTypeRefGraph(tref) {
84
- if (tref === undefined)
85
- return;
86
- (0, TypeGraph_1.assertTypeRefGraph)(tref, this.typeGraph);
87
- }
88
- assertTypeRefSetGraph(trefs) {
89
- if (trefs === undefined)
90
- return;
91
- trefs.forEach(tref => this.assertTypeRefGraph(tref));
92
- }
93
- filterTypeAttributes(t, attributes) {
94
- const filtered = (0, collection_utils_1.mapFilter)(attributes, (_, k) => k.appliesToTypeKind(t.kind));
95
- if (attributes.size !== filtered.size) {
96
- this.setLostTypeAttributes();
97
- }
98
- return filtered;
99
- }
100
- commitType(tref, t) {
101
- this.assertTypeRefGraph(tref);
102
- const index = (0, TypeGraph_1.typeRefIndex)(tref);
103
- // const name = names !== undefined ? ` ${names.combinedName}` : "";
104
- // console.log(`committing ${t.kind}${name} to ${index}`);
105
- (0, Support_1.assert)(this.types[index] === undefined, "A type index was committed twice");
106
- this.types[index] = t;
107
- this.typeAttributes[index] = this.filterTypeAttributes(t, this.typeAttributes[index]);
108
- }
109
- addType(forwardingRef, creator, attributes) {
110
- if (forwardingRef !== undefined) {
111
- this.assertTypeRefGraph(forwardingRef);
112
- (0, Support_1.assert)(this.types[(0, TypeGraph_1.typeRefIndex)(forwardingRef)] === undefined);
113
- }
114
- const tref = forwardingRef !== undefined ? forwardingRef : this.reserveTypeRef();
115
- if (attributes !== undefined) {
116
- const index = (0, TypeGraph_1.typeRefIndex)(tref);
117
- this.typeAttributes[index] = (0, TypeAttributes_1.combineTypeAttributes)("union", this.typeAttributes[index], attributes);
118
- }
119
- const t = creator(tref);
120
- this.commitType(tref, t);
121
- return tref;
122
- }
123
- typeAtIndex(index) {
124
- const maybeType = this.types[index];
125
- if (maybeType === undefined) {
126
- return (0, Support_1.panic)("Trying to deref an undefined type in a type builder");
127
- }
128
- return maybeType;
129
- }
130
- atIndex(index) {
131
- const t = this.typeAtIndex(index);
132
- const attribtues = this.typeAttributes[index];
133
- return [t, attribtues];
134
- }
135
- addAttributes(tref, attributes) {
136
- this.assertTypeRefGraph(tref);
137
- const index = (0, TypeGraph_1.typeRefIndex)(tref);
138
- const existingAttributes = this.typeAttributes[index];
139
- (0, Support_1.assert)((0, collection_utils_1.iterableEvery)(attributes, ([k, v]) => {
140
- if (!k.inIdentity)
141
- return true;
142
- const existing = existingAttributes.get(k);
143
- if (existing === undefined)
144
- return false;
145
- return (0, collection_utils_1.areEqual)(existing, v);
146
- }), "Can't add different identity type attributes to an existing type");
147
- const maybeType = this.types[index];
148
- if (maybeType !== undefined) {
149
- attributes = this.filterTypeAttributes(maybeType, attributes);
150
- }
151
- const nonIdentityAttributes = (0, collection_utils_1.mapFilter)(attributes, (_, k) => !k.inIdentity);
152
- this.typeAttributes[index] = (0, TypeAttributes_1.combineTypeAttributes)("union", existingAttributes, nonIdentityAttributes);
153
- }
154
- finish() {
155
- this.typeGraph.freeze(this.topLevels, this.types.map(Support_1.defined), this.typeAttributes);
156
- return this.typeGraph;
157
- }
158
- addForwardingIntersection(forwardingRef, tref) {
159
- this.assertTypeRefGraph(tref);
160
- this._addedForwardingIntersection = true;
161
- return this.addType(forwardingRef, tr => new Type_1.IntersectionType(tr, this.typeGraph, new Set([tref])), undefined);
162
- }
163
- forwardIfNecessary(forwardingRef, tref) {
164
- if (tref === undefined)
165
- return undefined;
166
- if (forwardingRef === undefined)
167
- return tref;
168
- return this.addForwardingIntersection(forwardingRef, tref);
169
- }
170
- get didAddForwardingIntersection() {
171
- return this._addedForwardingIntersection;
172
- }
173
- _typeForIdentity = new collection_utils_1.EqualityMap();
174
- registerTypeForIdentity(identity, tref) {
175
- if (identity === undefined)
176
- return;
177
- this._typeForIdentity.set(identity, tref);
178
- }
179
- makeIdentity(maker) {
180
- return maker();
181
- }
182
- getOrAddType(identityMaker, creator, attributes, forwardingRef) {
183
- const identity = this.makeIdentity(identityMaker);
184
- let maybeTypeRef;
185
- if (identity === undefined) {
186
- maybeTypeRef = undefined;
187
- }
188
- else {
189
- maybeTypeRef = this._typeForIdentity.get(identity);
190
- }
191
- if (maybeTypeRef !== undefined) {
192
- const result = this.forwardIfNecessary(forwardingRef, maybeTypeRef);
193
- if (attributes !== undefined) {
194
- // We only add the attributes that are not in the identity, since
195
- // we found the type based on its identity, i.e. all the identity
196
- // attributes must be in there already, and we have a check that
197
- // asserts that no identity attributes are added later.
198
- this.addAttributes(result, (0, collection_utils_1.mapFilter)(attributes, (_, k) => !k.inIdentity));
199
- }
200
- return result;
201
- }
202
- const tref = this.addType(forwardingRef, creator, attributes);
203
- this.registerTypeForIdentity(identity, tref);
204
- return tref;
205
- }
206
- registerType(t) {
207
- this.registerTypeForIdentity(t.identity, t.typeRef);
208
- }
209
- getPrimitiveType(kind, maybeAttributes, forwardingRef) {
210
- const attributes = (0, collection_utils_1.withDefault)(maybeAttributes, TypeAttributes_1.emptyTypeAttributes);
211
- // FIXME: Why do date/time types need a StringTypes attribute?
212
- // FIXME: Remove this from here and put it into flattenStrings
213
- let stringTypes = kind === "string" ? undefined : StringTypes_1.StringTypes.unrestricted;
214
- if ((0, Type_1.isPrimitiveStringTypeKind)(kind) && kind !== "string") {
215
- kind = stringTypeMappingGet(this._stringTypeMapping, kind);
216
- }
217
- if (kind === "string") {
218
- return this.getStringType(attributes, stringTypes, forwardingRef);
219
- }
220
- return this.getOrAddType(() => (0, Type_1.primitiveTypeIdentity)(kind, attributes), tr => new Type_1.PrimitiveType(tr, this.typeGraph, kind), attributes, forwardingRef);
221
- }
222
- getStringType(attributes, stringTypes, forwardingRef) {
223
- const existingStringTypes = (0, collection_utils_1.mapFind)(attributes, (_, k) => k === StringTypes_1.stringTypesTypeAttributeKind);
224
- (0, Support_1.assert)((stringTypes === undefined) !== (existingStringTypes === undefined), "Must instantiate string type with one enum case attribute");
225
- if (existingStringTypes === undefined) {
226
- attributes = (0, TypeAttributes_1.combineTypeAttributes)("union", attributes, StringTypes_1.stringTypesTypeAttributeKind.makeAttributes((0, Support_1.defined)(stringTypes)));
227
- }
228
- return this.getOrAddType(() => (0, Type_1.primitiveTypeIdentity)("string", attributes), tr => new Type_1.PrimitiveType(tr, this.typeGraph, "string"), attributes, forwardingRef);
229
- }
230
- getEnumType(attributes, cases, forwardingRef) {
231
- return this.getOrAddType(() => (0, Type_1.enumTypeIdentity)(attributes, cases), tr => new Type_1.EnumType(tr, this.typeGraph, cases), attributes, forwardingRef);
232
- }
233
- makeClassProperty(tref, isOptional) {
234
- return new Type_1.ClassProperty(tref, this.typeGraph, isOptional);
235
- }
236
- getUniqueObjectType(attributes, properties, additionalProperties, forwardingRef) {
237
- this.assertTypeRefGraph(additionalProperties);
238
- properties = (0, collection_utils_1.definedMap)(properties, p => this.modifyPropertiesIfNecessary(p));
239
- return this.addType(forwardingRef, tref => new Type_1.ObjectType(tref, this.typeGraph, "object", true, properties, additionalProperties), attributes);
240
- }
241
- getUniqueMapType(forwardingRef) {
242
- return this.addType(forwardingRef, tr => new Type_1.MapType(tr, this.typeGraph, undefined), undefined);
243
- }
244
- getMapType(attributes, values, forwardingRef) {
245
- this.assertTypeRefGraph(values);
246
- return this.getOrAddType(() => (0, Type_1.mapTypeIdentify)(attributes, values), tr => new Type_1.MapType(tr, this.typeGraph, values), attributes, forwardingRef);
247
- }
248
- setObjectProperties(ref, properties, additionalProperties) {
249
- this.assertTypeRefGraph(additionalProperties);
250
- const type = (0, TypeGraph_1.derefTypeRef)(ref, this.typeGraph);
251
- if (!(type instanceof Type_1.ObjectType)) {
252
- return (0, Support_1.panic)("Tried to set properties of non-object type");
253
- }
254
- type.setProperties(this.modifyPropertiesIfNecessary(properties), additionalProperties);
255
- this.registerType(type);
256
- }
257
- getUniqueArrayType(forwardingRef) {
258
- return this.addType(forwardingRef, tr => new Type_1.ArrayType(tr, this.typeGraph, undefined), undefined);
259
- }
260
- getArrayType(attributes, items, forwardingRef) {
261
- this.assertTypeRefGraph(items);
262
- return this.getOrAddType(() => (0, Type_1.arrayTypeIdentity)(attributes, items), tr => new Type_1.ArrayType(tr, this.typeGraph, items), attributes, forwardingRef);
263
- }
264
- setArrayItems(ref, items) {
265
- this.assertTypeRefGraph(items);
266
- const type = (0, TypeGraph_1.derefTypeRef)(ref, this.typeGraph);
267
- if (!(type instanceof Type_1.ArrayType)) {
268
- return (0, Support_1.panic)("Tried to set items of non-array type");
269
- }
270
- type.setItems(items);
271
- this.registerType(type);
272
- }
273
- modifyPropertiesIfNecessary(properties) {
274
- properties.forEach(p => this.assertTypeRefGraph(p.typeRef));
275
- if (this.canonicalOrder) {
276
- properties = (0, collection_utils_1.mapSortByKey)(properties);
277
- }
278
- if (this._allPropertiesOptional) {
279
- properties = (0, collection_utils_1.mapMap)(properties, cp => this.makeClassProperty(cp.typeRef, true));
280
- }
281
- return properties;
282
- }
283
- getClassType(attributes, properties, forwardingRef) {
284
- properties = this.modifyPropertiesIfNecessary(properties);
285
- return this.getOrAddType(() => (0, Type_1.classTypeIdentity)(attributes, properties), tr => new Type_1.ClassType(tr, this.typeGraph, false, properties), attributes, forwardingRef);
286
- }
287
- // FIXME: Maybe just distinguish between this and `getClassType`
288
- // via a flag? That would make `ClassType.map` simpler.
289
- getUniqueClassType(attributes, isFixed, properties, forwardingRef) {
290
- properties = (0, collection_utils_1.definedMap)(properties, p => this.modifyPropertiesIfNecessary(p));
291
- return this.addType(forwardingRef, tref => new Type_1.ClassType(tref, this.typeGraph, isFixed, properties), attributes);
292
- }
293
- getUnionType(attributes, members, forwardingRef) {
294
- this.assertTypeRefSetGraph(members);
295
- return this.getOrAddType(() => (0, Type_1.unionTypeIdentity)(attributes, members), tr => new Type_1.UnionType(tr, this.typeGraph, members), attributes, forwardingRef);
296
- }
297
- // FIXME: why do we sometimes call this with defined members???
298
- getUniqueUnionType(attributes, members, forwardingRef) {
299
- this.assertTypeRefSetGraph(members);
300
- return this.addType(forwardingRef, tref => new Type_1.UnionType(tref, this.typeGraph, members), attributes);
301
- }
302
- getIntersectionType(attributes, members, forwardingRef) {
303
- this.assertTypeRefSetGraph(members);
304
- return this.getOrAddType(() => (0, Type_1.intersectionTypeIdentity)(attributes, members), tr => new Type_1.IntersectionType(tr, this.typeGraph, members), attributes, forwardingRef);
305
- }
306
- // FIXME: why do we sometimes call this with defined members???
307
- getUniqueIntersectionType(attributes, members, forwardingRef) {
308
- this.assertTypeRefSetGraph(members);
309
- return this.addType(forwardingRef, tref => new Type_1.IntersectionType(tref, this.typeGraph, members), attributes);
310
- }
311
- setSetOperationMembers(ref, members) {
312
- this.assertTypeRefSetGraph(members);
313
- const type = (0, TypeGraph_1.derefTypeRef)(ref, this.typeGraph);
314
- if (!(type instanceof Type_1.UnionType || type instanceof Type_1.IntersectionType)) {
315
- return (0, Support_1.panic)("Tried to set members of non-set-operation type");
316
- }
317
- type.setMembers(members);
318
- this.registerType(type);
319
- }
320
- setLostTypeAttributes() {
321
- return;
322
- }
323
- }
324
- exports.TypeBuilder = TypeBuilder;
@@ -1,75 +0,0 @@
1
- import { Type } from "./Type";
2
- import { SeparatedNamedTypes } from "./TypeUtils";
3
- import { TypeBuilder, StringTypeMapping } from "./TypeBuilder";
4
- import { GraphRewriteBuilder, BaseGraphRewriteBuilder } from "./GraphRewriting";
5
- import { Graph } from "./Graph";
6
- import { TypeAttributeKind, TypeAttributes } from "./attributes/TypeAttributes";
7
- export type TypeRef = number;
8
- export declare function isTypeRef(x: any): x is TypeRef;
9
- export declare function makeTypeRef(graph: TypeGraph, index: number): TypeRef;
10
- export declare function typeRefIndex(tref: TypeRef): number;
11
- export declare function assertTypeRefGraph(tref: TypeRef, graph: TypeGraph): void;
12
- export declare function derefTypeRef(tref: TypeRef, graphOrBuilder: TypeGraph | BaseGraphRewriteBuilder): Type;
13
- export declare function attributesForTypeRef(tref: TypeRef, graphOrBuilder: TypeGraph | BaseGraphRewriteBuilder): TypeAttributes;
14
- export declare function typeAndAttributesForTypeRef(tref: TypeRef, graphOrBuilder: TypeGraph | BaseGraphRewriteBuilder): [Type, TypeAttributes];
15
- export declare class TypeAttributeStore {
16
- private readonly _typeGraph;
17
- private _values;
18
- private readonly _topLevelValues;
19
- constructor(_typeGraph: TypeGraph, _values: (TypeAttributes | undefined)[]);
20
- private getTypeIndex;
21
- attributesForType(t: Type): TypeAttributes;
22
- attributesForTopLevel(name: string): TypeAttributes;
23
- private setInMap;
24
- set<T>(kind: TypeAttributeKind<T>, t: Type, value: T): void;
25
- setForTopLevel<T>(kind: TypeAttributeKind<T>, topLevelName: string, value: T): void;
26
- private tryGetInMap;
27
- tryGet<T>(kind: TypeAttributeKind<T>, t: Type): T | undefined;
28
- tryGetForTopLevel<T>(kind: TypeAttributeKind<T>, topLevelName: string): T | undefined;
29
- }
30
- export declare class TypeAttributeStoreView<T> {
31
- private readonly _attributeStore;
32
- private readonly _definition;
33
- constructor(_attributeStore: TypeAttributeStore, _definition: TypeAttributeKind<T>);
34
- set(t: Type, value: T): void;
35
- setForTopLevel(name: string, value: T): void;
36
- tryGet(t: Type): T | undefined;
37
- get(t: Type): T;
38
- tryGetForTopLevel(name: string): T | undefined;
39
- getForTopLevel(name: string): T;
40
- }
41
- export declare class TypeGraph {
42
- readonly serial: number;
43
- private readonly _haveProvenanceAttributes;
44
- private _typeBuilder?;
45
- private _attributeStore;
46
- private _topLevels;
47
- private _types?;
48
- private _parents;
49
- private _printOnRewrite;
50
- constructor(typeBuilder: TypeBuilder, serial: number, _haveProvenanceAttributes: boolean);
51
- private get isFrozen();
52
- get attributeStore(): TypeAttributeStore;
53
- freeze(topLevels: ReadonlyMap<string, TypeRef>, types: Type[], typeAttributes: (TypeAttributes | undefined)[]): void;
54
- get topLevels(): ReadonlyMap<string, Type>;
55
- typeAtIndex(index: number): Type;
56
- atIndex(index: number): [Type, TypeAttributes];
57
- private filterTypes;
58
- allNamedTypes(): ReadonlySet<Type>;
59
- allNamedTypesSeparated(): SeparatedNamedTypes;
60
- private allProvenance;
61
- setPrintOnRewrite(): void;
62
- private checkLostTypeAttributes;
63
- private printRewrite;
64
- rewrite<T extends Type>(title: string, stringTypeMapping: StringTypeMapping, alphabetizeProperties: boolean, replacementGroups: T[][], debugPrintReconstitution: boolean, replacer: (typesToReplace: ReadonlySet<T>, builder: GraphRewriteBuilder<T>, forwardingRef: TypeRef) => TypeRef, force?: boolean): TypeGraph;
65
- remap(title: string, stringTypeMapping: StringTypeMapping, alphabetizeProperties: boolean, map: ReadonlyMap<Type, Type>, debugPrintRemapping: boolean, force?: boolean): TypeGraph;
66
- garbageCollect(alphabetizeProperties: boolean, debugPrintReconstitution: boolean): TypeGraph;
67
- rewriteFixedPoint(alphabetizeProperties: boolean, debugPrintReconstitution: boolean): TypeGraph;
68
- allTypesUnordered(): ReadonlySet<Type>;
69
- makeGraph(invertDirection: boolean, childrenOfType: (t: Type) => ReadonlySet<Type>): Graph<Type>;
70
- getParentsOfType(t: Type): Set<Type>;
71
- printGraph(): void;
72
- }
73
- export declare function noneToAny(graph: TypeGraph, stringTypeMapping: StringTypeMapping, debugPrintReconstitution: boolean): TypeGraph;
74
- export declare function optionalToNullable(graph: TypeGraph, stringTypeMapping: StringTypeMapping, debugPrintReconstitution: boolean): TypeGraph;
75
- export declare function removeIndirectionIntersections(graph: TypeGraph, stringTypeMapping: StringTypeMapping, debugPrintRemapping: boolean): TypeGraph;