feat: replace deprecated methods with object-based syntax and add missing API methods#31
feat: replace deprecated methods with object-based syntax and add missing API methods#31Divyansha23 wants to merge 2 commits intomasterfrom
Conversation
…sing API methods
- Update all SDK method calls to use new object-based parameter syntax
- Fix parameter names: default -> xdefault, path -> xpath
- Use proper enums: Runtime.Node180, ExecutionMethod.GET, IndexType.Key
- Add IndexType to imports
- Add missing methods:
- Databases: listIndexes
- Storage: getFileDownload, getFilePreview (with graceful fallback)
- Users: getUserPrefs, updateUserPrefs
- Functions: updateFunction, listExecutions, createVariable,
listVariables, getVariable, updateVariable, deleteVariable
WalkthroughThe PR migrates Appwrite SDK calls in src/app.js from positional arguments to options-object signatures across Databases, Storage, Users, and Functions APIs, adds the IndexType import, and introduces new API uses (e.g., listIndexes, getFileDownload, getFilePreview, variable/execution/deployment endpoints). Deployment readiness polling and error messages were extended and multiple flows updated to use explicit named fields (functionId, deploymentId, bucketId, fileId, etc.). resources/index.js was converted to an ES module default export, its handler signature now accepts { req, res, log, error }, adds a log call, and updates the response message. Changes total +334/-112 lines. Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 🧹 Recent nitpick comments
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Fix all issues with AI agents
In `@src/app.js`:
- Around line 379-405: getFileDownload currently calls storage.getFileDownload
without error handling which can throw and abort the run; wrap the body of
getFileDownload in a try/catch like getFilePreview does, calling
storage.getFileDownload inside the try and logging success as before, and in the
catch log a warning (e.g., console.log(chalk.yellow(`Skipped: ${err.message}`)))
so failures are handled consistently between getFileDownload and getFilePreview.
- Around line 695-702: The call to functions.createExecution uses the deprecated
parameter name `xpath`; update the argument object to use `path` instead (keep
the same value "/" and other fields unchanged). Locate the createExecution
invocation (the object with functionId, body, async, xpath, method:
ExecutionMethod.GET, headers) and rename the `xpath` property to `path` so it
matches the node-appwrite v21 signature expected by createExecution.
- Around line 523-532: The code is using the deprecated Runtime.Node180 in the
functions.create call (functionId/ name "Node Hello World"); update the runtime
to a supported newer Node version by replacing Runtime.Node180 with
Runtime.Node200 (Node 20 LTS) or Runtime.Node210 (Node 21) depending on your
environment, and ensure your deployment supports that runtime variant before
changing it.
🧹 Nitpick comments (2)
src/app.js (2)
692-709: Unnecessary sleep after synchronous execution.The
async: falseflag meanscreateExecutionshould block until execution completes and return the full result. The 3-second sleep on line 706 is likely redundant. While this appears to be pre-existing behavior, it adds unnecessary latency to the playground run.Suggested cleanup
let response = await functions.createExecution({ functionId, body: "", async: false, xpath: "/", method: ExecutionMethod.GET, headers: {} }); - // sleep for 3 seconds - console.log("Waiting a little to ensure execution is finished ..."); - await new Promise((resolve) => setTimeout(resolve, 3000)); - console.log(response); }
791-804: Variable CRUD runs before function execution — intentional?Variables are created and then fully deleted (lines 797–801) before
executeSync/executeAsync(lines 802–803). If the function code ever readsMY_VAR, it won't be available at execution time. For a pure API demonstration this is fine, but reordering to delete the variable after executions would be a more realistic workflow.Suggested reorder
await createVariable(); await listVariables(); await getVariable(); await updateVariable(); - await deleteVariable(); await executeSync(); await executeAsync(); await listExecutions(); + await deleteVariable(); await deleteFunction();
…ch, update resources/index.js
There was a problem hiding this comment.
Pull request overview
This PR modernizes the Appwrite Node.js Playground by upgrading from SDK version 14.0.0 to 21.1.0, replacing the deprecated positional parameter syntax with the new object-based syntax across all API calls, and adding demonstrations of previously missing API methods.
Changes:
- Upgraded node-appwrite from 14.0.0 to 21.1.0 in package.json and package-lock.json
- Migrated all SDK method calls from positional parameters to object-based syntax throughout src/app.js
- Added demonstrations for 12 new API methods: listIndexes, getFileDownload, getFilePreview, getUserPrefs, updateUserPrefs, updateFunction, listExecutions, createVariable, listVariables, getVariable, updateVariable, and deleteVariable
- Updated function runtime to use ES module syntax (export default) and newer runtime features (log, error parameters) in resources/index.js
- Fixed parameter names to avoid JavaScript reserved keywords (default → xdefault, path → xpath)
- Replaced string literals with proper enum constants (IndexType.Key, ExecutionMethod.GET, Runtime.Node200)
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/app.js | Migrated all Appwrite SDK calls to object-based syntax, added IndexType import, and added 12 new API method demonstrations including database indexes, file download/preview, user preferences, function updates, executions listing, and complete variable CRUD operations |
| resources/index.js | Updated function runtime code to use ES module export syntax and added log/error parameters for compatibility with newer Node runtimes |
| package.json | Updated node-appwrite dependency from 14.0.0 to ^21.1.0 |
| package-lock.json | Updated lock file to reflect node-appwrite 21.1.0 with updated integrity hash and added license field |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const response = await functions.create({ | ||
| functionId: ID.unique(), | ||
| name: "Node Hello World", | ||
| runtime: Runtime.Node200, |
There was a problem hiding this comment.
The PR description mentions using "Runtime.Node180" but the code uses "Runtime.Node200" on lines 530 and 567. This discrepancy should be clarified - either update the PR description to reflect the actual runtime being used (Node200), or if Node180 was intended, update the code to use the correct runtime constant.
Changes
Replace deprecated methods with new methods
Add missing methods
Summary
Total SDK methods demonstrated: 44 to 56
Summary by CodeRabbit
Refactor
New Features
Bug Fixes