Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

ChiragAgg5k
Copy link
Member

@ChiragAgg5k ChiragAgg5k commented Sep 5, 2025

What does this PR do?

(Provide a description of what this PR does.)

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?

(Write your answer here.)

Summary by CodeRabbit

  • Bug Fixes
    • Generated TypeScript definitions now correctly quote collection attribute keys that aren’t valid identifiers, preventing syntax errors in appwrite.d.ts.
    • Improves compatibility with keys containing spaces, dashes, or other non-alphanumeric characters without altering the underlying types.
    • Affects only how keys are declared in exported collection types; existing type mappings remain unchanged.

Copy link

coderabbitai bot commented Sep 5, 2025

Walkthrough

The TypeScript type-generation template was updated to conditionally quote property keys for collection attributes when the key is not a valid TypeScript identifier. It introduces helper variables to compute the final property name (respecting strict mode) and to validate identifier syntax, emitting either an unquoted identifier or a quoted string key accordingly. The emitted types for attributes remain unchanged aside from key quoting. This affects the generated exported type blocks for collections in the produced TypeScript declarations.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch pla-3442

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
templates/cli/lib/type-generation/languages/typescript.js.twig (1)

94-94: Broaden identifier check to support Unicode identifiers.

TS allows Unicode ID_Start/ID_Continue. Current ASCII-only regex may over-quote valid keys (e.g., ümlaut). Consider a Unicode-aware pattern.

Suggested change:

-<% const isValidIdentifier = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(propertyName); -%>
+<% const isValidIdentifier = /^[$_\p{ID_Start}][$_\u200C\u200D\p{ID_Continue}]*$/u.test(propertyName); -%>
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between aea747c and e7fea13.

📒 Files selected for processing (1)
  • templates/cli/lib/type-generation/languages/typescript.js.twig (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (19)
  • GitHub Check: build (8.3, Swift56)
  • GitHub Check: build (8.3, DotNet80)
  • GitHub Check: build (8.3, WebNode)
  • GitHub Check: build (8.3, WebChromium)
  • GitHub Check: build (8.3, AppleSwift56)
  • GitHub Check: build (8.3, Node20)
  • GitHub Check: build (8.3, Python313)
  • GitHub Check: build (8.3, Ruby30)
  • GitHub Check: build (8.3, Python39)
  • GitHub Check: build (8.3, Python312)
  • GitHub Check: build (8.3, Node18)
  • GitHub Check: build (8.3, Go118)
  • GitHub Check: build (8.3, KotlinJava8)
  • GitHub Check: build (8.3, Python311)
  • GitHub Check: build (8.3, Node16)
  • GitHub Check: build (8.3, FlutterStable)
  • GitHub Check: build (8.3, FlutterBeta)
  • GitHub Check: build (8.3, Android14Java17)
  • GitHub Check: build (8.3, Android5Java17)
🔇 Additional comments (1)
templates/cli/lib/type-generation/languages/typescript.js.twig (1)

93-95: Confirm strict-mode intent for renamed keys.

Quoting happens after toCamelCase when strict is true, so keys like foo-bar become fooBar (unquoted). If you intended to preserve original text when invalid (even in strict), consider toggling quoting before rename. Otherwise, this behavior is fine.

<%- strict ? toCamelCase(attribute.key) : attribute.key %>: <%- getType(attribute, collections) %>;
<% const propertyName = strict ? toCamelCase(attribute.key) : attribute.key; -%>
<% const isValidIdentifier = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(propertyName); -%>
<% if (isValidIdentifier) { %><%- propertyName %><% } else { %>"<%- propertyName %>"<% } %>: <%- getType(attribute, collections) %>;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Quote keys safely to avoid invalid d.ts (escape quotes/newlines).

If an attribute key contains a " or control chars, "${propertyName}" will break. Use JSON.stringify to output a valid TS string literal.

Apply this diff:

-    <% if (isValidIdentifier) { %><%- propertyName %><% } else { %>"<%- propertyName %>"<% } %>: <%- getType(attribute, collections) %>;
+    <% if (isValidIdentifier) { %><%- propertyName %><% } else { %><%- JSON.stringify(propertyName) %><% } %>: <%- getType(attribute, collections) %>;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<% if (isValidIdentifier) { %><%- propertyName %><% } else { %>"<%- propertyName %>"<% } %>: <%- getType(attribute, collections) %>;
<% if (isValidIdentifier) { %><%- propertyName %><% } else { %><%- JSON.stringify(propertyName) %><% } %>: <%- getType(attribute, collections) %>;
🤖 Prompt for AI Agents
In templates/cli/lib/type-generation/languages/typescript.js.twig around line
95, the template currently emits property keys using raw double quotes which
will break if the attribute name contains quotes or control characters; replace
the naive quoted form with JSON.stringify(propertyName) when the name is not a
valid identifier so the output is a valid, escaped TypeScript string literal
(i.e., use JSON.stringify to produce the quoted/escaped key), keeping the
identifier branch unchanged and passing attribute/collections to getType as
before.

@loks0n loks0n merged commit 9630aae into master Sep 5, 2025
39 checks passed
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