Skip to content
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

feat: add programmatic API for types #6861

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

andyjessop
Copy link
Contributor

What this PR solves / how to test

Fixes #000.

Adds a programmatic API for type generation.

Author has addressed the following

  • Tests
    • TODO (before merge)
    • Tests included
    • Tests not necessary because:
  • E2E Tests CI Job required? (Use "e2e" label or ask maintainer to run separately)
    • I don't know
    • Required
    • Not required because:
  • Changeset (Changeset guidelines)
    • TODO (before merge)
    • Changeset included
    • Changeset not necessary because:
  • Public documentation
    • TODO (before merge)
    • Cloudflare docs PR(s):
    • Documentation not necessary because:

Copy link

changeset-bot bot commented Sep 30, 2024

⚠️ No Changeset found

Latest commit: 2dc76b6

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

outFile?: string;
persistToFilesystem?: boolean;
}): Promise<string> {
return generateTypes(getProjectTypes, options);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does getProjectTypes come from?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not yet implemented. It would be an abstraction that isolates some of the logic already existing inside the type generation code. Basically just gets a string of the Env types.

(I don't know if "Project" is the right word here. Could also go with "Env" or something else).

getRuntimeTypes({
compatibilityDate: config.compatibility_date,
compatibilityFlags: config.compatibility_flags.filter(
(flag) => !flag.includes("nodejs_compat")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to be explicit here, checking against nodejs_compat and nodejs_compat_v2

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call.

Comment on lines +47 to +57
if (!config && !configFile) {
throw new Error("Either config or configFile must be provided");
}
if (config && configFile) {
throw new Error("Only one of config or configFile should be provided");
}
if (outFile && persistToFilesystem === undefined) {
throw new Error(
"persistToFilesystem must be specified when outFile is provided"
);
}
Copy link
Contributor

@RamIdeas RamIdeas Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This combo have validation can be accomplished with union types

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or overloads perhaps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants