Skip to content

Conversation

apperside
Copy link

@apperside apperside commented Sep 6, 2025

What does this PR do?

This PR improves the typescript types generator by adding optional fields when a field is not required.

So now for an optional field called "myField", it will generate the following typescript code:

myField string

instead of

myField: string | null

This gives a better DevEX because if you want to use this types, you know which fields you really need to fill and which not.
There also seem to exist a bug when handling two way relations and I fixed it.

Test Plan

(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work.)

Related PRs and Issues

(If this PR is related to any other PR or resolves any issue or related to any issue link all related PR and issues here.)

Have you read the Contributing Guidelines on issues?

yes

Summary by CodeRabbit

  • New Features
    • Generated TypeScript now marks non-required attributes as optional (prop?: Type), removing previous “| null” unions.
  • Bug Fixes
    • Improved relationship resolution: if a relationship lacks a related collection but has a two-way key, it’s auto-inferred during normalization.
    • Type generation is more resilient to malformed relationships: emits a warning and uses any for unresolved relationship types instead of failing.

Copy link

coderabbitai bot commented Sep 6, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

  • In lib/commands/types.js, adds a fallback to infer relationship.relatedCollection using twoWayKey by scanning tables for a matching column key; applies only when relatedCollection is absent and twoWayKey exists.
  • In lib/type-generation/languages/typescript.js, adds a guard: when relatedCollection is missing for a relationship, logs a warning and emits type any.
  • Removes adding " | null" for non-required attributes with null defaults.
  • Updates the TypeScript template to mark non-required attributes as optional (property?: Type) in generated interfaces.
  • Other control flow and outputs remain unchanged; exported/public signatures unchanged in source.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 71e8c88 and 9834394.

📒 Files selected for processing (2)
  • lib/commands/types.js (1 hunks)
  • lib/type-generation/languages/typescript.js (2 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

github-actions bot commented Sep 6, 2025

This library is auto-generated by the Appwrite SDK Generator, and does not accept pull requests directly. To learn more about how you can help us improve this SDK, please check the contributing guide.

@github-actions github-actions bot closed this Sep 6, 2025
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.

1 participant