Skip to content

Commit 7143aee

Browse files
Refactor out import cycles (#2733)
* refactor out PathElement dependency cycle * refactor out type transformed string util cycle * separate index for re-exports * rename to TransformedStringType * move Type files into dir * refactor out TypeBuilderUtils * fix imports * split TypeGraph utils to own file * move provenance type attribute kind to own file * fix getGraph instanceof * recomment cycle * export through index * assign TypeGraph to TypeBuilder after init * update comments
1 parent 088dadc commit 7143aee

File tree

85 files changed

+569
-500
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+569
-500
lines changed

packages/quicktype-core/src/ConvenienceRenderer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ import {
3232
type TypeKind,
3333
UnionType
3434
} from "./Type";
35-
import { TypeAttributeStoreView } from "./TypeGraph";
36-
import { isNamedType, matchTypeExhaustive, nullableFromUnion, separateNamedTypes } from "./TypeUtils";
35+
import { TypeAttributeStoreView } from "./Type/TypeGraph";
36+
import { isNamedType, matchTypeExhaustive, nullableFromUnion, separateNamedTypes } from "./Type/TypeUtils";
3737

3838
const wordWrap: (s: string) => string = _wordwrap(90);
3939

packages/quicktype-core/src/DeclarationIR.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { iterableFirst, setFilter, setIntersect, setSubtract, setUnionInto } fro
33
import { Graph } from "./Graph";
44
import { messageError } from "./Messages";
55
import { assert, defined, panic } from "./support/Support";
6-
import { type Type } from "./Type";
7-
import { type TypeGraph } from "./TypeGraph";
6+
import { type Type } from "./Type/Type";
7+
import { type TypeGraph } from "./Type/TypeGraph";
88

99
export type DeclarationKind = "forward" | "define";
1010

packages/quicktype-core/src/GatherNames.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import * as pluralize from "pluralize";
44
import { TooManyTypeNames, TypeNames, namesTypeAttributeKind, tooManyNamesThreshold } from "./attributes/TypeNames";
55
import { assert, defined, panic } from "./support/Support";
66
import { transformationForType } from "./Transformers";
7-
import { ObjectType, type Type } from "./Type";
8-
import { type TypeGraph } from "./TypeGraph";
9-
import { matchCompoundType, nullableFromUnion } from "./TypeUtils";
7+
import { ObjectType, type Type } from "./Type/Type";
8+
import { type TypeGraph } from "./Type/TypeGraph";
9+
import { matchCompoundType, nullableFromUnion } from "./Type/TypeUtils";
1010

1111
class UniqueQueue<T> {
1212
private readonly _present = new Set<T>();

packages/quicktype-core/src/GraphRewriting.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ import { EqualityMap, mapMap } from "collection-utils";
33
import { type TypeAttributes, combineTypeAttributes, emptyTypeAttributes } from "./attributes/TypeAttributes";
44
import { assert, indentationString, panic } from "./support/Support";
55
import { type ClassProperty, type MaybeTypeIdentity, type PrimitiveTypeKind, type Type } from "./Type";
6-
// eslint-disable-next-line import/no-cycle
7-
import { type StringTypeMapping, TypeBuilder } from "./TypeBuilder";
6+
import { TypeBuilder } from "./Type/TypeBuilder";
7+
import { type StringTypeMapping } from "./Type/TypeBuilderUtils";
8+
import { type TypeGraph } from "./Type/TypeGraph";
89
import {
9-
type TypeGraph,
1010
type TypeRef,
1111
assertTypeRefGraph,
1212
derefTypeRef,
1313
isTypeRef,
1414
typeAndAttributesForTypeRef,
1515
typeRefIndex
16-
} from "./TypeGraph";
17-
import { combineTypeAttributesOfTypes } from "./TypeUtils";
16+
} from "./Type/TypeRef";
17+
import { combineTypeAttributesOfTypes } from "./Type/TypeUtils";
1818

1919
export interface TypeLookerUp {
2020
lookupTypeRefs: (typeRefs: TypeRef[], forwardingRef?: TypeRef) => TypeRef | undefined;
@@ -229,7 +229,6 @@ export abstract class BaseGraphRewriteBuilder extends TypeBuilder implements Typ
229229
protected readonly debugPrint: boolean
230230
) {
231231
super(
232-
originalGraph.serial + 1,
233232
stringTypeMapping,
234233
alphabetizeProperties,
235234
false,

packages/quicktype-core/src/MakeTransformations.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ import {
3434
isPrimitiveStringTypeKind,
3535
targetTypeKindForTransformedStringTypeKind
3636
} from "./Type";
37-
import { type TypeGraph, type TypeRef, typeRefIndex } from "./TypeGraph";
37+
import { type TypeGraph } from "./Type/TypeGraph";
38+
import { type TypeRef, typeRefIndex } from "./Type/TypeRef";
3839

3940
function transformationAttributes(
4041
graph: TypeGraph,

packages/quicktype-core/src/Renderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { type NewlineSource, type Source, type Sourcelike, annotated, newline, s
66
import { type Comment } from "./support/Comments";
77
import { assert, panic } from "./support/Support";
88
import { type TargetLanguage } from "./TargetLanguage";
9-
import { type TypeGraph } from "./TypeGraph";
9+
import { type TypeGraph } from "./Type/TypeGraph";
1010

1111
export interface RenderResult {
1212
names: ReadonlyMap<Name, string>;

packages/quicktype-core/src/Run.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ import { type Comment } from "./support/Comments";
2020
import { assert } from "./support/Support";
2121
import { type MultiFileRenderResult, type TargetLanguage } from "./TargetLanguage";
2222
import { type TransformedStringTypeKind } from "./Type";
23-
import { type StringTypeMapping, TypeBuilder } from "./TypeBuilder";
24-
import { type TypeGraph, noneToAny, optionalToNullable, removeIndirectionIntersections } from "./TypeGraph";
23+
import { TypeBuilder } from "./Type/TypeBuilder";
24+
import { type StringTypeMapping } from "./Type/TypeBuilderUtils";
25+
import { TypeGraph } from "./Type/TypeGraph";
26+
import { noneToAny, optionalToNullable, removeIndirectionIntersections } from "./Type/TypeGraphUtils";
2527
import { type FixMeOptionsType } from "./types";
2628

2729
export function getTargetLanguage(nameOrInstance: LanguageName | TargetLanguage): TargetLanguage {
@@ -289,13 +291,13 @@ class Run implements RunContext {
289291
const stringTypeMapping = this.stringTypeMapping;
290292
const conflateNumbers = !targetLanguage.supportsUnionsWithBothNumberTypes;
291293
const typeBuilder = new TypeBuilder(
292-
0,
293294
stringTypeMapping,
294295
this._options.alphabetizeProperties,
295296
this._options.allPropertiesOptional,
296297
this._options.checkProvenance,
297298
false
298299
);
300+
typeBuilder.typeGraph = new TypeGraph(typeBuilder, 0, this._options.checkProvenance);
299301

300302
return { targetLanguage, stringTypeMapping, conflateNumbers, typeBuilder };
301303
}

packages/quicktype-core/src/TargetLanguage.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import { type Option, type OptionDefinition } from "./RendererOptions";
77
import { type SerializedRenderResult, serializeRenderResult } from "./Source";
88
import { type Comment } from "./support/Comments";
99
import { defined } from "./support/Support";
10-
import { type Type } from "./Type";
11-
import { type StringTypeMapping } from "./TypeBuilder";
12-
import { type TypeGraph } from "./TypeGraph";
10+
import { type Type } from "./Type/Type";
11+
import { type StringTypeMapping } from "./Type/TypeBuilderUtils";
12+
import { type TypeGraph } from "./Type/TypeGraph";
1313
import { type FixMeOptionsType } from "./types";
1414

1515
export type MultiFileRenderResult = ReadonlyMap<string, SerializedRenderResult>;

packages/quicktype-core/src/Transformers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import { TypeAttributeKind } from "./attributes/TypeAttributes";
1313
import { type BaseGraphRewriteBuilder } from "./GraphRewriting";
1414
import { assert, indentationString, panic } from "./support/Support";
1515
import { EnumType, PrimitiveType, type Type, type TypeKind, UnionType } from "./Type";
16-
import { type TypeGraph, type TypeRef, derefTypeRef } from "./TypeGraph";
16+
import { type TypeGraph } from "./Type/TypeGraph";
17+
import { type TypeRef, derefTypeRef } from "./Type/TypeRef";
1718

1819
function debugStringForType(t: Type): string {
1920
const target = followTargetType(t);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { setUnionManyInto } from "collection-utils";
2+
3+
import { TypeAttributeKind } from "../attributes/TypeAttributes";
4+
5+
import { type TypeKind } from "./TransformedStringType";
6+
7+
// FIXME: Don't infer provenance. All original types should be present in
8+
// non-inferred form in the final graph.
9+
class ProvenanceTypeAttributeKind extends TypeAttributeKind<Set<number>> {
10+
public constructor() {
11+
super("provenance");
12+
}
13+
14+
public appliesToTypeKind(_kind: TypeKind): boolean {
15+
return true;
16+
}
17+
18+
public combine(arr: Array<Set<number>>): Set<number> {
19+
return setUnionManyInto(new Set(), arr);
20+
}
21+
22+
public makeInferred(p: Set<number>): Set<number> {
23+
return p;
24+
}
25+
26+
public stringify(p: Set<number>): string {
27+
return Array.from(p)
28+
.sort()
29+
.map(i => i.toString())
30+
.join(",");
31+
}
32+
}
33+
34+
export const provenanceTypeAttributeKind: TypeAttributeKind<Set<number>> = new ProvenanceTypeAttributeKind();

0 commit comments

Comments
 (0)