Skip to content

Commit

Permalink
Format typescript (glideapps#2082)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdsgl authored Jan 8, 2023
1 parent 7599c47 commit c1f6db7
Show file tree
Hide file tree
Showing 47 changed files with 4,456 additions and 7,281 deletions.
3,313 changes: 676 additions & 2,637 deletions data/lib.d.ts

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"test": "script/test",
"start": "script/watch",
"pkg": "script/make-pkgs.sh",
"format": "prettier --write **/*.ts",
"tslint": "tslint --project src/cli --exclude 'src/__tests__/**' --exclude 'src/quicktype-core/input/io/get-stream/**'",
"clean": "rm -rf dist node_modules *~",
"publish": "script/publish.sh"
Expand Down
34 changes: 17 additions & 17 deletions script/patch-npm-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@ import * as shell from "shelljs";
import * as semver from "semver";

function exec(command: string) {
const result = shell.exec(command, { silent: true });
return (result.stdout as string).trim();
const result = shell.exec(command, { silent: true });
return (result.stdout as string).trim();
}

const PUBLISHED = (() => {
// Get the highest published version of any tag
const all = JSON.parse(exec(`npm show quicktype versions --json`));
return all[all.length - 1];
// Get the highest published version of any tag
const all = JSON.parse(exec(`npm show quicktype versions --json`));
return all[all.length - 1];
})();

const CURRENT = exec(`npm version`).match(/quicktype: '(.+)'/)![1];

switch (semver.compare(CURRENT, PUBLISHED)) {
case -1:
console.error(`* package.json version is ${CURRENT} but ${PUBLISHED} is published. Patching...`);
exec(`npm version ${PUBLISHED} --force --no-git-tag-version`);
shell.exec(`npm version patch --no-git-tag-version`);
break;
case 0:
console.error(`* package.json version is ${CURRENT} but ${PUBLISHED} is published. Patching...`);
shell.exec(`npm version patch --no-git-tag-version`);
break;
default:
// Greater than published, nothing to do
break;
case -1:
console.error(`* package.json version is ${CURRENT} but ${PUBLISHED} is published. Patching...`);
exec(`npm version ${PUBLISHED} --force --no-git-tag-version`);
shell.exec(`npm version patch --no-git-tag-version`);
break;
case 0:
console.error(`* package.json version is ${CURRENT} but ${PUBLISHED} is published. Patching...`);
shell.exec(`npm version patch --no-git-tag-version`);
break;
default:
// Greater than published, nothing to do
break;
}
32 changes: 13 additions & 19 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,14 +341,14 @@ function makeOptionDefinitions(targetLanguages: TargetLanguage[]): OptionDefinit
targetLanguages.length < 2
? []
: [
{
name: "lang",
alias: "l",
type: String,
typeLabel: makeLangTypeLabel(targetLanguages),
description: "The target language."
}
];
{
name: "lang",
alias: "l",
type: String,
typeLabel: makeLangTypeLabel(targetLanguages),
description: "The target language."
}
];
const afterLang: OptionDefinition[] = [
{
name: "src-lang",
Expand Down Expand Up @@ -595,18 +595,13 @@ function parseOptions(definitions: OptionDefinition[], argv: string[], partial:
}
}

const options: { rendererOptions: RendererOptions;[key: string]: any } = { rendererOptions: {} };
const options: { rendererOptions: RendererOptions; [key: string]: any } = { rendererOptions: {} };
for (const o of definitions) {
if (!hasOwnProperty(opts, o.name)) continue;
const v = opts[o.name] as string;
if (o.renderer !== undefined) options.rendererOptions[o.name] = v;
else {
const k = _.lowerFirst(
o.name
.split("-")
.map(_.upperFirst)
.join("")
);
const k = _.lowerFirst(o.name.split("-").map(_.upperFirst).join(""));
options[k] = v;
}
}
Expand Down Expand Up @@ -820,10 +815,9 @@ export async function makeQuicktypeOptions(
collectionFile
);
for (const src of postmanSources) {
sources.push(Object.assign(
{ kind: "json" },
stringSourceDataToStreamSourceData(src)
) as JSONTypeSource);
sources.push(
Object.assign({ kind: "json" }, stringSourceDataToStreamSourceData(src)) as JSONTypeSource
);
}
if (postmanSources.length > 1) {
fixedTopLevels = true;
Expand Down
3 changes: 2 additions & 1 deletion src/quicktype-core/EncodedMarkovChain.ts

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/quicktype-core/GatherNames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,10 @@ export function gatherNames(graph: TypeGraph, destructive: boolean, debugPrint:
alternatives = new Set();
}

alternatives = setUnion(alternatives, setMap(names, name => `${name}_${t.kind}`));
alternatives = setUnion(
alternatives,
setMap(names, name => `${name}_${t.kind}`)
);
directAlternativesForType.set(t, alternatives);
}

Expand Down
6 changes: 5 additions & 1 deletion src/quicktype-core/Graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,11 @@ export class Graph<T> {
stronglyConnectedComponents(): Graph<ReadonlySet<T>> {
const components = stronglyConnectedComponents(this._successors);
const componentSuccessors = buildMetaSuccessors(this._successors, components);
return new Graph(components.map(ns => setMap(ns, n => this._nodes[n])), false, componentSuccessors);
return new Graph(
components.map(ns => setMap(ns, n => this._nodes[n])),
false,
componentSuccessors
);
}

makeDot(includeNode: (n: T) => boolean, nodeLabel: (n: T) => string): string {
Expand Down
6 changes: 5 additions & 1 deletion src/quicktype-core/MakeTransformations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,11 @@ function replaceUnion(
transformerForString = new DecodingTransformer(
graph,
getStringType(),
new ChoiceTransformer(graph, getStringType(), stringTypes.map(t => defined(transformerForStringType(t))))
new ChoiceTransformer(
graph,
getStringType(),
stringTypes.map(t => defined(transformerForStringType(t)))
)
);
}

Expand Down
5 changes: 4 additions & 1 deletion src/quicktype-core/Source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ export function sourcelikeToSource(sl: Sourcelike): Source {
}
return {
kind: "sequence",
sequence: arrayIntercalate(newline(), lines.map((l: string) => ({ kind: "text", text: l } as Source)))
sequence: arrayIntercalate(
newline(),
lines.map((l: string) => ({ kind: "text", text: l } as Source))
)
};
}
if (sl instanceof Name) {
Expand Down
4 changes: 1 addition & 3 deletions src/quicktype-core/Transformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -974,9 +974,7 @@ export class MinMaxValueTransformer extends ProducerTransformer {
equals(other: any): boolean {
if (!super.equals(other)) return false;
return (
other instanceof MinMaxValueTransformer &&
this.minimum === other.minimum &&
this.maximum === other.maximum
other instanceof MinMaxValueTransformer && this.minimum === other.minimum && this.maximum === other.maximum
);
}
}
Expand Down
17 changes: 13 additions & 4 deletions src/quicktype-core/Type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ const transformedStringTypeTargetTypeKinds = {
"bool-string": { jsonSchema: "boolean", primitive: "bool" } as TransformedStringTypeTargets
};

export const transformedStringTypeTargetTypeKindsMap = mapFromObject(transformedStringTypeTargetTypeKinds as {
[kind: string]: TransformedStringTypeTargets;
});
export const transformedStringTypeTargetTypeKindsMap = mapFromObject(
transformedStringTypeTargetTypeKinds as {
[kind: string]: TransformedStringTypeTargets;
}
);

export type TransformedStringTypeKind = keyof typeof transformedStringTypeTargetTypeKinds;
export type PrimitiveStringTypeKind = "string" | TransformedStringTypeKind;
Expand Down Expand Up @@ -642,7 +644,14 @@ export class MapType extends ObjectType {
readonly kind: "map";

constructor(typeRef: TypeRef, graph: TypeGraph, valuesRef: TypeRef | undefined) {
super(typeRef, graph, "map", false, definedMap(valuesRef, () => new Map()), valuesRef);
super(
typeRef,
graph,
"map",
false,
definedMap(valuesRef, () => new Map()),
valuesRef
);
}

// FIXME: Remove and use `getAdditionalProperties()` instead.
Expand Down
12 changes: 10 additions & 2 deletions src/quicktype-core/TypeBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ import {
TypeKind
} from "./Type";
import { TypeGraph, TypeRef, makeTypeRef, derefTypeRef, typeRefIndex, assertTypeRefGraph } from "./TypeGraph";
import { TypeAttributes, combineTypeAttributes, TypeAttributeKind, emptyTypeAttributes } from "./attributes/TypeAttributes";
import {
TypeAttributes,
combineTypeAttributes,
TypeAttributeKind,
emptyTypeAttributes
} from "./attributes/TypeAttributes";
import { defined, assert, panic } from "./support/Support";
import { stringTypesTypeAttributeKind, StringTypes } from "./attributes/StringTypes";

Expand Down Expand Up @@ -276,7 +281,10 @@ export class TypeBuilder {
// we found the type based on its identity, i.e. all the identity
// attributes must be in there already, and we have a check that
// asserts that no identity attributes are added later.
this.addAttributes(result, mapFilter(attributes, (_, k) => !k.inIdentity));
this.addAttributes(
result,
mapFilter(attributes, (_, k) => !k.inIdentity)
);
}
return result;
}
Expand Down
23 changes: 16 additions & 7 deletions src/quicktype-core/TypeUtils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { setFilter, setSortBy, iterableFirst, setUnion, EqualityMap } from "collection-utils";

import { defined, panic, assert, assertNever } from "./support/Support";
import { TypeAttributes, combineTypeAttributes, emptyTypeAttributes, CombinationKind } from "./attributes/TypeAttributes";
import {
TypeAttributes,
combineTypeAttributes,
emptyTypeAttributes,
CombinationKind
} from "./attributes/TypeAttributes";
import {
Type,
PrimitiveType,
Expand Down Expand Up @@ -105,7 +110,10 @@ export function makeGroupsToFlatten<T extends SetOperationType>(
}

export function combineTypeAttributesOfTypes(combinationKind: CombinationKind, types: Iterable<Type>): TypeAttributes {
return combineTypeAttributes(combinationKind, Array.from(types).map(t => t.getAttributes()));
return combineTypeAttributes(
combinationKind,
Array.from(types).map(t => t.getAttributes())
);
}

export function isAnyOrNull(t: Type): boolean {
Expand Down Expand Up @@ -174,11 +182,12 @@ export type SeparatedNamedTypes = {
};

export function separateNamedTypes(types: Iterable<Type>): SeparatedNamedTypes {
const objects = (setFilter(types, t => t.kind === "object" || t.kind === "class") as Set<
ObjectType
>) as ReadonlySet<ObjectType>;
const enums = (setFilter(types, t => t instanceof EnumType) as Set<EnumType>) as ReadonlySet<EnumType>;
const unions = (setFilter(types, t => t instanceof UnionType) as Set<UnionType>) as ReadonlySet<UnionType>;
const objects = setFilter(
types,
t => t.kind === "object" || t.kind === "class"
) as Set<ObjectType> as ReadonlySet<ObjectType>;
const enums = setFilter(types, t => t instanceof EnumType) as Set<EnumType> as ReadonlySet<EnumType>;
const unions = setFilter(types, t => t instanceof UnionType) as Set<UnionType> as ReadonlySet<UnionType>;

return { objects, enums, unions };
}
Expand Down
13 changes: 9 additions & 4 deletions src/quicktype-core/UnifyClasses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ function getCliqueProperties(
return [unifiedProperties, unifiedAdditionalProperties, lostTypeAttributes];
}

function countProperties(
clique: ObjectType[]
): { hasProperties: boolean; hasAdditionalProperties: boolean; hasNonAnyAdditionalProperties: boolean } {
function countProperties(clique: ObjectType[]): {
hasProperties: boolean;
hasAdditionalProperties: boolean;
hasNonAnyAdditionalProperties: boolean;
} {
let hasProperties = false;
let hasAdditionalProperties = false;
let hasNonAnyAdditionalProperties = false;
Expand Down Expand Up @@ -119,7 +121,10 @@ export class UnifyUnionBuilder extends UnionBuilder<BaseGraphRewriteBuilder, Typ
if (!this._makeObjectTypes && (hasNonAnyAdditionalProperties || (!hasProperties && hasAdditionalProperties))) {
const propertyTypes = new Set<TypeRef>();
for (const o of objectTypes) {
setUnionInto(propertyTypes, Array.from(o.getProperties().values()).map(cp => cp.typeRef));
setUnionInto(
propertyTypes,
Array.from(o.getProperties().values()).map(cp => cp.typeRef)
);
}
const additionalPropertyTypes = new Set(
objectTypes
Expand Down
5 changes: 4 additions & 1 deletion src/quicktype-core/UnionBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,10 @@ function attributesForTypes(types: Iterable<Type>): [ReadonlyMap<Type, TypeAttri

const resultAttributes = mapMap(unionsForType, (unionForType, t) => {
const singleAncestors = Array.from(unionForType).filter(u => defined(typesForUnion.get(u)).size === 1);
assert(singleAncestors.every(u => defined(typesForUnion.get(u)).has(t)), "We messed up bookkeeping");
assert(
singleAncestors.every(u => defined(typesForUnion.get(u)).has(t)),
"We messed up bookkeeping"
);
const inheritedAttributes = singleAncestors.map(u => u.getAttributes());
return combineTypeAttributes("union", [t.getAttributes()].concat(inheritedAttributes));
});
Expand Down
10 changes: 4 additions & 6 deletions src/quicktype-core/attributes/AccessorNames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@ class UnionIdentifierTypeAttributeKind extends TypeAttributeKind<ReadonlySet<num
}
}

export const unionIdentifierTypeAttributeKind: TypeAttributeKind<
ReadonlySet<number>
> = new UnionIdentifierTypeAttributeKind();
export const unionIdentifierTypeAttributeKind: TypeAttributeKind<ReadonlySet<number>> =
new UnionIdentifierTypeAttributeKind();

let nextUnionIdentifier: number = 0;

Expand All @@ -118,9 +117,8 @@ class UnionMemberNamesTypeAttributeKind extends TypeAttributeKind<Map<number, Ac
}
}

export const unionMemberNamesTypeAttributeKind: TypeAttributeKind<
Map<number, AccessorEntry>
> = new UnionMemberNamesTypeAttributeKind();
export const unionMemberNamesTypeAttributeKind: TypeAttributeKind<Map<number, AccessorEntry>> =
new UnionMemberNamesTypeAttributeKind();

export function makeUnionMemberNamesAttribute(unionAttributes: TypeAttributes, entry: AccessorEntry): TypeAttributes {
const identifiers = defined(unionIdentifierTypeAttributeKind.tryGetInAttributes(unionAttributes));
Expand Down
5 changes: 2 additions & 3 deletions src/quicktype-core/attributes/Description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ class PropertyDescriptionsTypeAttributeKind extends TypeAttributeKind<Map<string
}
}

export const propertyDescriptionsTypeAttributeKind: TypeAttributeKind<
Map<string, ReadonlySet<string>>
> = new PropertyDescriptionsTypeAttributeKind();
export const propertyDescriptionsTypeAttributeKind: TypeAttributeKind<Map<string, ReadonlySet<string>>> =
new PropertyDescriptionsTypeAttributeKind();

function isPropertiesKey(el: PathElement): boolean {
return el.kind === PathElementKind.KeyOrIndex && el.key === "properties";
Expand Down
5 changes: 1 addition & 4 deletions src/quicktype-core/attributes/EnumValues.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import {
mapMap,
} from "collection-utils";
import { mapMap } from "collection-utils";

import { lookupKey, AccessorNames, makeAccessorNames } from "./AccessorNames";
import { EnumType } from "../Type";
Expand Down Expand Up @@ -30,7 +28,6 @@ export function enumValuesAttributeProducer(
_canonicalRef: Ref | undefined,
_types: Set<JSONSchemaType>
): JSONSchemaAttributes | undefined {

if (typeof schema !== "object") return undefined;

const maybeEnumValues = schema["qt-enum-values"];
Expand Down
Loading

0 comments on commit c1f6db7

Please sign in to comment.