Skip to content

feat: add TypeScript source#60

Open
SimoneMariaRomeo wants to merge 6 commits into
parse-community:mainfrom
SimoneMariaRomeo:bounty/typescript-migration
Open

feat: add TypeScript source#60
SimoneMariaRomeo wants to merge 6 commits into
parse-community:mainfrom
SimoneMariaRomeo:bounty/typescript-migration

Conversation

@SimoneMariaRomeo
Copy link
Copy Markdown

@SimoneMariaRomeo SimoneMariaRomeo commented May 11, 2026

Closes #49.

Summary

  • Add index.ts as the typed adapter source and emit index.js / index.d.ts with tsc.
  • Preserve CommonJS usage and the existing module.exports.default export.
  • Build before tests, coverage, and package creation so generated output stays in sync.
  • Parse GCS_DIRECT_ACCESS as a boolean and cover it with a regression test.

Validation

  • npm test
  • npm run coverage

Summary by CodeRabbit

  • New Features

    • Added a Google Cloud Storage adapter with upload, download, delete, and configurable direct-access URLs; safe object path handling and content-type handling.
  • Tests

    • Added tests covering adapter export shape, environment options, path validation, content-type rules, and missing-file behavior.
  • Chores

    • Added TypeScript support, declaration files, build/config scripts, updated dev dependencies, and updated .gitignore to exclude coverage output.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 11, 2026

Warning

Rate limit exceeded

@SimoneMariaRomeo has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 35 minutes and 40 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f212d3ab-ca1a-4fad-968f-4e1642ba24df

📥 Commits

Reviewing files that changed from the base of the PR and between 9125d66 and 49c0227.

📒 Files selected for processing (3)
  • index.js
  • index.ts
  • spec/test.spec.js
📝 Walkthrough

Walkthrough

This PR migrates the GCS adapter from JavaScript to TypeScript by adding index.ts, index.d.ts, tsconfig.json, build scripts, and a class-based implementation while updating tests and package metadata.

Changes

TypeScript Migration for GCS Adapter

Layer / File(s) Summary
Type Definitions & Build Configuration
tsconfig.json, index.d.ts, package.json, package-lock.json, .gitignore
Adds strict TypeScript config and declaration file; points package.json types to index.d.ts; adds typescript and @types/node to devDependencies; updates scripts to run tsc before tests; adds .nyc_output to .gitignore and updates lockfile.
Options & Validation Helpers
index.js (lines 1–62), index.ts (lines 1–76, 61–76, 77–100)
Introduces helpers for merging constructor args with environment variables, stringFromEnvironmentOrDefault/booleanFromEnvironmentOrDefault, contentTypeOrDefault, filename/object-name validation, and encoding of GCS object names.
TypeScript Class & File Operations
index.ts (lines 111–234)
Implements GCSAdapter class initializing Storage client; createFile streams uploads with contentType metadata and optional makePublic; deleteFile wraps file.delete(); getFileData checks file.exists() then downloads; getFileLocation returns direct GCS URL or proxied mount URL; adds private filePath helper and dual export wiring.
JavaScript Transpiled Implementation
index.js (lines 72–181)
Refactors prototype-based implementation into an ES6 class GCSAdapter, updates methods to use validation/encoding helpers, and sets exports to exports.default with __esModule.
Test Coverage
spec/test.spec.js (lines 11–153)
Updates constructor error assertions, verifies GCSAdapter.default equality, tests GCS_DIRECT_ACCESS boolean parsing and getFileLocation outputs, and adds input validation tests for unsafe filenames, content types, and missing files.

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 3

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Security Check ⚠️ Warning stringFromEnvironmentOrDefault treats empty string as falsy, allowing env vars to silently override explicit bucketPrefix: '' configuration Use explicit undefined checks instead of || operator to preserve empty string configuration values
Engage In Review Feedback ⚠️ Warning Review feedback on stringFromEnvironmentOrDefault was not engaged. The function still uses || operator which treats empty strings as falsy, causing misconfiguration. The issue remains unfixed. Author must implement the suggested fix using !== undefined, or engage in discussion. No commit or acknowledgment of the issue was found.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'feat: add TypeScript source' uses the required 'feat:' prefix and clearly describes the main change: adding TypeScript implementation and build setup for the GCS adapter.
Linked Issues check ✅ Passed The PR comprehensively addresses all coding requirements from issue #49: implements a TypeScript GCSAdapter class with typed options, parses GCS_DIRECT_ACCESS as boolean, provides all required methods (createFile, deleteFile, getFileData, getFileLocation), and compiles to JavaScript and type declarations.
Out of Scope Changes check ✅ Passed All changes are directly aligned with the TypeScript migration objective. Package configuration updates (tsconfig.json, package.json), build tooling, test enhancements, and the .gitignore update are all necessary supporting changes for the TypeScript implementation and build process.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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
Copy Markdown

@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)
index.ts (1)

19-29: ⚡ Quick win

Prefer throwing Error objects over strings.

Line 26 throws a template string. Best practice is to throw Error objects to ensure proper stack traces and error handling.

♻️ Proposed fix
 function requiredOrFromEnvironment(
   options: GCSAdapterOptions,
   key: 'bucket',
   env: string
 ): GCSAdapterOptions {
   options[key] = options[key] || process.env[env];
   if (!options[key]) {
-    throw `GCSAdapter requires an ${key}`;
+    throw new Error(`GCSAdapter requires an ${key}`);
   }
   return options;
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@index.ts` around lines 19 - 29, The function requiredOrFromEnvironment should
throw an Error object instead of a string; update the throw in
requiredOrFromEnvironment (which sets options[key] from process.env[env]) to
throw new Error(`GCSAdapter requires an ${key}`) so callers get proper stack
traces and standard error handling.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@index.ts`:
- Around line 148-168: getFileData currently rejects with the raw err from
file.exists which can be null when the file simply doesn't exist; update the
file.exists callback in getFileData to reject with a meaningful Error object
instead (e.g. new Error(`File not found: ${filename}`)) when exists is false,
and include the original err details when present (e.g. reject(err || new
Error(...))) so callers never receive null as the rejection value.

---

Nitpick comments:
In `@index.ts`:
- Around line 19-29: The function requiredOrFromEnvironment should throw an
Error object instead of a string; update the throw in requiredOrFromEnvironment
(which sets options[key] from process.env[env]) to throw new Error(`GCSAdapter
requires an ${key}`) so callers get proper stack traces and standard error
handling.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 54db176d-efc9-441f-93aa-e6bb86f11828

📥 Commits

Reviewing files that changed from the base of the PR and between f2eae90 and 8d595d6.

📒 Files selected for processing (8)
  • .gitignore
  • index.d.ts
  • index.js
  • index.ts
  • package-lock.json
  • package.json
  • spec/test.spec.js
  • tsconfig.json

Comment thread index.ts
@SimoneMariaRomeo
Copy link
Copy Markdown
Author

SimoneMariaRomeo commented May 11, 2026

Follow-up fixes are now pushed in 5dc9575 and 9125d66.

  • Missing-file getFileData now rejects with an Error instead of null.
  • Missing bucket config now throws an Error object.
  • Filename traversal, direct URL encoding, and contentType CR/LF handling are hardened.
  • Local validation: npm run coverage passes with 10 specs.

CodeRabbit and Snyk checks are green. The GitHub Actions CI run is still waiting for maintainer approval because this is a fork PR.

@SimoneMariaRomeo
Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 12, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@index.js`:
- Around line 11-13: The helper stringFromEnvironmentOrDefault currently uses
the || operator which treats empty strings as missing; change it to only fall
back when options[key] is strictly undefined (and use process.env[env] only when
it is defined), so explicit empty-string values (e.g., bucketPrefix: '') are
preserved; update the implementation of stringFromEnvironmentOrDefault (and
therefore its call sites that set projectId, keyFilename, bucketPrefix) to check
for undefined rather than falsy values when deciding to override.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 393a944e-8c4b-47f5-9651-15c2707b5853

📥 Commits

Reviewing files that changed from the base of the PR and between 8d595d6 and 9125d66.

📒 Files selected for processing (4)
  • index.d.ts
  • index.js
  • index.ts
  • spec/test.spec.js
🚧 Files skipped from review as they are similar to previous changes (2)
  • index.d.ts
  • index.ts

Comment thread index.js
@SimoneMariaRomeo
Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 12, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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.

Upgrade to typescript

1 participant