Skip to content

Conversation

@Ram3ez
Copy link

@Ram3ez Ram3ez commented Dec 15, 2025

What does this PR do?

This PR adds TypeScript definitions (types.d.ts) to the Node.js starter template and updates the entry file to enable IntelliSense.

Changes:

  • Added node/starter/src/types.d.ts which defines the Context, Request, and Response interfaces based on the Appwrite documentation.
  • Updated the main function file to include the /// <reference path="./types.d.ts" /> directive.
  • Added JSDoc comments (/** @param {Context} context */) to the exported function to properly type the destructured parameters (req, res, log, error).

Reasoning:
Currently, the Node.js starter lacks IntelliSense support. By adding these definitions, developers get immediate autocomplete and type checking for the function context in VS Code (and other editors) without needing a build step or a tsconfig.json. This significantly improves the Developer Experience (DX).

Test Plan

I verified the changes manually in VS Code:

  1. Open the node/starter directory in VS Code.
  2. Open the main entry file.
  3. Hover over req or res inside the function parameters.
    • Pass: Verified that the tooltip shows the correct type (e.g., Request, Response) instead of any.
  4. Type res. or req. inside the function.
    • Pass: Verified that IntelliSense suggestions appear (e.g., json(), headers, bodyText).
  5. Validated that the runtime behavior remains unchanged (native Node.js execution).

Related PRs and Issues

Closes #344

Have you read the Contributing Guidelines on issues?

Yes

Summary by CodeRabbit

  • Chores
    • Applied code formatting/consistency updates (cosmetic only).
    • Added/augmented TypeScript type definitions for the runtime context, request, and response shapes to improve developer tooling and type safety.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 15, 2025

Walkthrough

This PR makes two changes: cosmetic formatting edits in node/starter/src/main.js (quote style and minor spacing/param spacing) and adds node/starter/src/types.d.ts which introduces TypeScript global augmentations for interfaces Context, AppwriteRequest, and AppwriteResponse and an export {} module marker. No runtime behavior or exported API signatures were changed.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • node/starter/src/main.js: quick scan to confirm only cosmetic changes (quotes/spacing) and no accidental logic edits.
  • node/starter/src/types.d.ts: validate interfaces (Context, AppwriteRequest, AppwriteResponse) match expected runtime properties and method signatures and that export {} is appropriate.

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding TypeScript definitions to the Node.js starter for IntelliSense support, which matches the core objective.
Linked Issues check ✅ Passed The PR fully addresses issue #344's requirements: adds types.d.ts with Context, AppwriteRequest, AppwriteResponse interfaces; includes reference directive and JSDoc comments in main.js; enables zero-config IntelliSense without breaking changes.
Out of Scope Changes check ✅ Passed All changes are directly related to issue #344. The main.js cosmetic formatting changes are minor and incidental to the primary objective of adding TypeScript definitions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • 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

@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: 0

🧹 Nitpick comments (2)
node/starter/src/main.js (1)

3-14: Outdated inline comments conflict with the new type definitions.

The comment block describes properties that don't match the Request and Response interfaces in types.d.ts:

  • Comment mentions payload and variables, but the Request type has bodyText, bodyJson, bodyBinary, etc.
  • Comment mentions send(text, status), but the Response type has text(), json(), empty(), redirect(), and binary().

Consider updating or removing these comments to avoid confusion, since IntelliSense will now provide accurate documentation from the type definitions.

-/*
-  'req' variable has:
-    'headers' - object with request headers
-    'payload' - request body data as a string
-    'variables' - object with function variables
-
-  'res' variable has:
-    'send(text, status)' - function to return text response. Status code defaults to 200
-    'json(obj, status)' - function to return JSON response. Status code defaults to 200
-
-  If an error is thrown, a response with code 500 will be returned.
-*/
+// See types.d.ts for Request and Response type definitions.
+// If an error is thrown, a response with code 500 will be returned.
node/starter/src/types.d.ts (1)

29-89: Interface names Request and Response shadow Fetch API globals.

In Node.js 18+ (and modern browsers), Request and Response are built-in global types from the Fetch API. Declaring them in declare global will shadow those types, which could cause type errors if developers use the Fetch API in their functions.

Consider prefixing these interfaces to avoid conflicts:

-  interface Request {
+  interface AppwriteRequest {
-  interface Response {
+  interface AppwriteResponse {

Then update Context accordingly:

-    req: Request;
-    res: Response;
+    req: AppwriteRequest;
+    res: AppwriteResponse;

Also applies to: 91-144

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 512c5db and b31a6a2.

📒 Files selected for processing (2)
  • node/starter/src/main.js (2 hunks)
  • node/starter/src/types.d.ts (1 hunks)
🔇 Additional comments (4)
node/starter/src/main.js (2)

1-2: Type reference and JSDoc annotation look good.

The /// <reference path="./types.d.ts" /> directive and @param {Context} context JSDoc correctly enable IntelliSense for the destructured req, res, log, and error parameters without requiring a build step.

Also applies to: 18-20


36-51: Formatting changes are consistent.

The single-quote standardization aligns with common JavaScript style conventions.

node/starter/src/types.d.ts (2)

1-27: Global augmentation structure and Context interface look good.

The declare global with export {} pattern correctly augments the global scope. The Context interface with req, res, log, and error members matches the Appwrite function signature and has helpful JSDoc documentation.

Also applies to: 145-147


98-102: The response methods are correctly typed to return void. The return res.text(...) and return res.json(...) patterns in the code use the return statement for control flow (to stop execution within the handler), not to capture a return value. Appwrite's response methods "immediately produce the HTTP execution response" without returning a meaningful value; the void return type accurately reflects this behavior. This pattern is consistent across all Node.js templates in the codebase.

Likely an incorrect or invalid review comment.

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: 0

🧹 Nitpick comments (2)
node/starter/src/main.js (2)

8-12: JSDoc Context typing for the destructured parameter looks good; consider a small tweak if IntelliSense is spotty

Annotating the function with @param {Context} context should allow TS/VS Code to infer types for { req, res, log, error } from your Context interface. If you notice any gaps in autocomplete, an alternative is to accept a named context parameter and destructure inside the function, which some tooling handles more consistently:

-/**
- * @param {Context} context
- */
-// This Appwrite function will be executed every time your function is triggered
-export default async ({ req, res, log, error }) => {
+/**
+ * @param {Context} context
+ */
+// This Appwrite function will be executed every time your function is triggered
+export default async (context) => {
+  const { req, res, log, error } = context;

26-28: Error logging is fine; optionally harden it for non-Error throws

error('Could not list users: ' + err.message); is acceptable assuming users.list() throws Error instances, but you could make this a bit more robust against unexpected values:

-  } catch (err) {
-    error('Could not list users: ' + err.message);
+  } catch (err) {
+    const message = err?.message ?? String(err);
+    error('Could not list users: ' + message);

Not mandatory, but slightly safer for odd error shapes.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b31a6a2 and 12cbfc6.

📒 Files selected for processing (2)
  • node/starter/src/main.js (2 hunks)
  • node/starter/src/types.d.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • node/starter/src/types.d.ts
🔇 Additional comments (3)
node/starter/src/main.js (3)

1-5: Triple-slash reference is appropriate for wiring in the d.ts types

Using /// <reference path="./types.d.ts" /> is a good way to pull the ambient Context/request/response types into this JS file without changing runtime behavior. Please just double-check in VS Code that the file picks up those types as expected for hover/IntelliSense, per your test plan.


31-35: Ping route handler remains clear and idiomatic

The req.path === '/ping' check with return res.text('Pong'); keeps the behavior simple and explicit, and the added comments make the intent clear. No issues here.


38-41: JSON response content changes are non-breaking

Updating the motto, learn, connect, and getInspired strings/URLs is purely content-level; the response shape is unchanged, so existing consumers should keep working while benefiting from the new links/text.

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.

Enhancement: Add TypeScript definitions (IntelliSense) to Node.js starter

1 participant