Skip to content

feat: Strongly type Language Options #2611

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 115 commits into
base: release/v23.1.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
6e557fe
standardise json formatting
inferrinizzard Mar 19, 2024
2648d2d
fix @types in deps
inferrinizzard Mar 30, 2024
a7cec76
add file association for schema files
inferrinizzard Mar 19, 2024
03e2f12
uses const type for All array
inferrinizzard Mar 30, 2024
dcf6d31
move python args to own constructor
inferrinizzard Mar 30, 2024
a834d2c
make constructor first in misc languages
inferrinizzard Mar 30, 2024
7101e24
add generics to TargetLanguage for names and extension
inferrinizzard Mar 30, 2024
b17d3f2
fix generics for JavaScript + subclassing
inferrinizzard Mar 30, 2024
c529c53
add strict types for language names and display names
inferrinizzard Mar 30, 2024
5ca879c
move language displayName, names, extension to class static members
inferrinizzard Apr 6, 2024
0822bab
add strict typing for language name
inferrinizzard Apr 6, 2024
1072369
Merge branch 'master' into feat/core/language-types
inferrinizzard Apr 6, 2024
36e8514
:recycle:
inferrinizzard Apr 6, 2024
3e5f345
Revert "move language displayName, names, extension to class static m…
inferrinizzard Apr 6, 2024
8d7c622
add generics to TargetLanguage for names and extension
inferrinizzard Mar 30, 2024
4acad79
fix generics for JavaScript + subclassing
inferrinizzard Mar 30, 2024
c4ce60f
:recycle:
inferrinizzard Apr 6, 2024
95beb5f
Merge branch 'feat/core/language-names' into feat/core/language-types
inferrinizzard Apr 6, 2024
6140704
Merge branch 'master' into chore/repo/eslint
inferrinizzard Apr 7, 2024
b2a7904
install eslint packages
inferrinizzard Apr 7, 2024
b97c2b2
add eslint config
inferrinizzard Apr 7, 2024
e504a8a
remove tslint
inferrinizzard Apr 7, 2024
92bd563
eslint autofix
inferrinizzard Apr 7, 2024
392838a
update eslint rules, eslintignore
inferrinizzard Apr 8, 2024
d9baf6e
add lint:fix script
inferrinizzard Apr 8, 2024
8bbabf1
update eslint rules, eslintignore
inferrinizzard Apr 8, 2024
f1d19aa
add lint:fix script
inferrinizzard Apr 8, 2024
994567e
add import rules
inferrinizzard Apr 8, 2024
d259874
add import rules
inferrinizzard Apr 8, 2024
291f5c9
update import rules
inferrinizzard Apr 12, 2024
03d8001
reduce excess style rules
inferrinizzard Apr 12, 2024
99dd240
downgrade remaining to warnings
inferrinizzard Apr 13, 2024
7f22254
fix enum values
inferrinizzard Apr 8, 2024
885b35a
add all missing accessibility modifiers
inferrinizzard Apr 11, 2024
f791721
fix nullish errors
inferrinizzard Apr 12, 2024
db9a9cf
update import rules
inferrinizzard Apr 12, 2024
3088be7
fix all require imports
inferrinizzard Apr 12, 2024
c492962
fix all imports
inferrinizzard Apr 12, 2024
a47609a
reduce excess style rules
inferrinizzard Apr 12, 2024
b536136
fix any types
inferrinizzard Apr 13, 2024
f0e7615
fix misc errors
inferrinizzard Apr 13, 2024
c0232f3
downgrade remaining to warnings
inferrinizzard Apr 13, 2024
59e877f
return types
inferrinizzard Apr 13, 2024
e5edac4
fix types errors
inferrinizzard Apr 13, 2024
0267ad0
Merge branch 'chore/repo/eslint' into chore/repo/eslint-fix
inferrinizzard Apr 13, 2024
130fe31
fix json import for test tsconfig
inferrinizzard Apr 13, 2024
37812f3
Merge branch 'master' into chore/repo/eslint
inferrinizzard Apr 14, 2024
e89f453
Merge branch 'chore/repo/eslint' into chore/repo/eslint-fix
inferrinizzard Apr 14, 2024
06002f9
auto lint fix
inferrinizzard Apr 14, 2024
93ab86e
fix lint errors in extension
inferrinizzard Apr 14, 2024
6a81618
Merge branch 'master' into chore/repo/eslint
inferrinizzard Apr 14, 2024
6ca4eaa
Merge branch 'chore/repo/eslint' into chore/repo/eslint-fix
inferrinizzard Apr 14, 2024
1ec5933
fix lint errors in Elixir
inferrinizzard Apr 14, 2024
4620ba5
make ref.pushElement public
inferrinizzard Apr 14, 2024
4fe1649
fix misc
inferrinizzard Apr 14, 2024
eed53c6
fix accidental public in CSharp raw text get
inferrinizzard Apr 14, 2024
10675c9
Merge branch 'master' into feat/core/language-types
inferrinizzard Apr 16, 2024
15fd452
use full generics for all languages to all extensibility
inferrinizzard Apr 16, 2024
6fd903c
add generics for elixir
inferrinizzard Apr 16, 2024
719a028
typescript 4.9 doesn't support const generics yet
inferrinizzard Apr 16, 2024
a0e399a
export LanguageName type and predicates
inferrinizzard Apr 16, 2024
45c06ce
fix type safety for extension
inferrinizzard Apr 16, 2024
beddba2
fix type safety for cli
inferrinizzard Apr 16, 2024
fb25f79
reduce target language generic to singular config object
inferrinizzard Apr 19, 2024
050d6d0
strongly type Renderer Options with map for enums
inferrinizzard Apr 20, 2024
afdb99a
support existing tuple params
inferrinizzard Apr 20, 2024
d0b8c15
update all non-inherited target languages to have external language c…
inferrinizzard Apr 20, 2024
410ed42
flatten all languages to extend from TargetLanguage
inferrinizzard Apr 20, 2024
1053a44
Merge branch 'refactor/core/no-language-inheritance' into feat/core/l…
inferrinizzard Apr 20, 2024
e542e87
Merge branch 'master' into feat/core/language-types
inferrinizzard Apr 20, 2024
a4989bf
Merge branch 'master' into chore/repo/eslint-fix
inferrinizzard Apr 30, 2024
8e6fc4f
fix new lint errors
inferrinizzard Apr 30, 2024
58cfc88
Merge branch 'chore/repo/eslint-fix' into base
inferrinizzard May 5, 2024
f16e6ad
Merge branch 'refactor/imports/languages'
inferrinizzard May 5, 2024
cacc55d
Merge branch 'base' into feat/core/language-types
inferrinizzard May 10, 2024
23e74d3
fix package-lock
inferrinizzard May 10, 2024
811ac4a
lint fixed
inferrinizzard May 10, 2024
b61fbe2
Merge branch 'master' into feat/core/language-types
inferrinizzard May 18, 2024
e0f9089
Merge branch 'master' into feat/core/language-types
inferrinizzard May 18, 2024
9b8908a
use LanguageName in cli index
inferrinizzard May 19, 2024
8555b84
fix type errors in test
inferrinizzard May 19, 2024
1e9126e
Merge commit 'e0f9089c2809b70a1e51a7d7ea80f62410cf33f1' into feat/cor…
inferrinizzard May 19, 2024
29bb816
refactor: Fixes some easier dependency cycles (#2605)
inferrinizzard May 31, 2024
23c2c5f
add docs for creating custom languages and renderers
inferrinizzard May 31, 2024
aef27c2
update README
inferrinizzard May 31, 2024
6a5763b
Merge branch 'feat/core/language-types' into feat/core/typed-options
inferrinizzard Jun 1, 2024
9956c47
Merge branch 'release/v23.1.0' of https://github.com/glideapps/quickt…
inferrinizzard Jun 1, 2024
898d5f2
working tuple type generics
inferrinizzard Jun 1, 2024
da86caf
re-export All through index
inferrinizzard Jun 2, 2024
31b343d
move language specific types into own file
inferrinizzard Jun 2, 2024
6d488d3
use map arg for EnumOption instead of tuple
inferrinizzard Jun 2, 2024
258bd00
remove custom NoInfer
inferrinizzard Jun 2, 2024
a68107a
split OptionMap and OptionValues types
inferrinizzard Jun 4, 2024
7ca8ffc
update EnumOptions to use map
inferrinizzard Jun 4, 2024
0f203f7
update getOptions to return options object instead of array
inferrinizzard Jun 4, 2024
9e0f8aa
aggregate language options types
inferrinizzard Jun 4, 2024
2608f68
fix naming style options for C langs
inferrinizzard Jun 4, 2024
288feb4
use LanguageOptions in Run
inferrinizzard Jun 4, 2024
96c411f
readd NoInfer util type
inferrinizzard Jun 4, 2024
37320e7
feat(python): add --pydantic-base-model option (#2604)
alpoi Jan 20, 2025
e96ff17
add LanguageOptions type
inferrinizzard Apr 20, 2025
89946ac
move RendererOptions to own dir
inferrinizzard Apr 20, 2025
6ab469e
move options types to own file
inferrinizzard Apr 20, 2025
19ba522
update type of LanguageOptions to reflect input
inferrinizzard Apr 20, 2025
94cfe7d
fix types errors in cli script
inferrinizzard Apr 20, 2025
d7098e7
rename back to RendererOptions
inferrinizzard Apr 20, 2025
c7837e6
fix: punycode error for non CI (#2587)
avallete Apr 23, 2025
63db12c
fix: Revert GH Actions to use Ubuntu 22.04 (#2701)
inferrinizzard Apr 24, 2025
31965e0
Merge remote-tracking branch 'quicktype/master' into feat/core/typed-…
inferrinizzard Apr 24, 2025
a84cba7
fix type error for fixtures.ts
inferrinizzard Apr 24, 2025
169c982
update messageError
inferrinizzard Apr 25, 2025
0ca2e3c
add temp log
inferrinizzard Apr 25, 2025
d9961e9
add temp log 2
inferrinizzard Apr 25, 2025
9570fde
update getOptionValues to use name instead of key
inferrinizzard Apr 25, 2025
e527f1d
optional swift
inferrinizzard Apr 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

jobs:
publish:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: ./.github/workflows/setup
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/setup/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ runs:
echo "source_key=$SOURCE_KEY" >> $GITHUB_ENV

- name: Setup node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ env.node_version }}
cache: npm
Expand Down
25 changes: 13 additions & 12 deletions .github/workflows/test-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ on:
pull_request:
branches:
- master
- 'release/**'
- "release/**"
jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: ./.github/workflows/setup
Expand Down Expand Up @@ -45,7 +45,7 @@ jobs:
# Implementation is too outdated to test in GitHub Actions
# - elm,schema-elm

# Language is too niche / obscure to test easily on ubuntu-latest
# Language is too niche / obscure to test easily on ubuntu-22.04
# - pike,schema-pike

# Not yet started
Expand All @@ -56,18 +56,18 @@ jobs:
# Never tested?
# - crystal

runs-on: [ubuntu-latest]
runs-on: [ubuntu-22.04]

include:
# Rust is very slow, so we use a larger runner
- fixture: rust,schema-rust
runs-on: ubuntu-latest-8-cores
runs-on: ubuntu-latest-16-cores
# Kotlin is also slow
- fixture: kotlin,schema-kotlin,kotlin-jackson,schema-kotlin-jackson
runs-on: ubuntu-latest-8-cores
runs-on: ubuntu-latest-16-cores

- fixture: objective-c
runs-on: macos-11
# - fixture: objective-c # FIXME: temp disable obj-c in ci
# runs-on: macos-latest

name: ${{ matrix.fixture }}
steps:
Expand All @@ -89,6 +89,7 @@ jobs:
- name: Setup Swift
if: ${{ contains(matrix.fixture, 'swift') }}
uses: swift-actions/setup-swift@v1
continue-on-error: true
with:
swift-version: "5.7.2"

Expand Down Expand Up @@ -190,8 +191,8 @@ jobs:
test-complete:
if: ${{ cancelled() || contains(needs.*.result, 'cancelled') || contains(needs.*.result, 'failure') }}
needs: test
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- run: |
echo "Some workflows have failed!"
exit 1
- run: |
echo "Some workflows have failed!"
exit 1
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v18.18.0
v22.14.0
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "tabWidth": 4, "printWidth": 120, "trailingComma": "none", "arrowParens": "avoid" }
{ "tabWidth": 4, "printWidth": 120, "trailingComma": "none", "arrowParens": "avoid", "quoteProps": "consistent" }
6 changes: 2 additions & 4 deletions doc/CustomRenderer.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,8 @@ class BrandNewLanguage extends TargetLanguage<typeof brandNewLanguageConfig> {
super(brandNewLanguageConfig);
}

protected getOptions(): Array<Option<any>> {
return [
brandNewLanguageOptions.allowFoo // list all options from the options config
];
public getOptions(): typeof brandNewLanguageOptions {
return brandNewLanguageOptions;
}

protected makeRenderer(
Expand Down
33 changes: 16 additions & 17 deletions packages/quicktype-core/src/Messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export type ErrorProperties =
// TypeScript input
| { kind: "TypeScriptCompilerError"; properties: { message: string } };

export type ErrorKinds = ErrorProperties extends { kind: infer K } ? K : never;
export type ErrorKinds = ErrorProperties["kind"];

type ErrorMessages = { readonly [K in ErrorKinds]: string };

Expand Down Expand Up @@ -165,7 +165,7 @@ const errorMessages: ErrorMessages = {
TypeScriptCompilerError: "TypeScript error: ${message}"
};

export type ErrorPropertiesForName<K> =
export type ErrorPropertiesForKind<K extends ErrorKinds = ErrorKinds> =
Extract<ErrorProperties, { kind: K }> extends { properties: infer P } ? P : never;

export class QuickTypeError extends Error {
Expand All @@ -179,31 +179,30 @@ export class QuickTypeError extends Error {
}
}

export function messageError<N extends ErrorKinds>(kind: N, properties: ErrorPropertiesForName<N>): never {
export function messageError<Kind extends ErrorKinds>(kind: Kind, properties: ErrorPropertiesForKind<Kind>): never {
const message = errorMessages[kind];
let userMessage: string = message;
const propertiesMap = properties as StringMap;

for (const name of Object.getOwnPropertyNames(propertiesMap)) {
let value = propertiesMap[name];
if (typeof value === "object" && typeof value.toString === "function") {
value = value.toString();
} else if (typeof value.message === "string") {
value = value.message;

for (const [name, value] of Object.entries(properties as StringMap)) {
let valueString = "";
if (typeof value === "object" && typeof value?.toString === "function") {
valueString = value.toString();
} else if (typeof value?.message === "string") {
valueString = value.message;
} else if (typeof value !== "string") {
value = JSON.stringify(value);
valueString = JSON.stringify(value);
}

userMessage = userMessage.replace("${" + name + "}", value);
userMessage = userMessage.replace("${" + name + "}", valueString);
}

throw new QuickTypeError(message, kind, userMessage, propertiesMap);
throw new QuickTypeError(message, kind, userMessage, properties as StringMap);
}

export function messageAssert<N extends ErrorKinds>(
export function messageAssert<Kind extends ErrorKinds>(
assertion: boolean,
kind: N,
properties: ErrorPropertiesForName<N>
kind: Kind,
properties: ErrorPropertiesForKind<Kind>
): void {
if (assertion) return;
return messageError(kind, properties);
Expand Down
193 changes: 0 additions & 193 deletions packages/quicktype-core/src/RendererOptions.ts

This file was deleted.

Loading
Loading