Skip to content

refactor(api): migrate Folder from Flow to TypeScript - #4990

Open
bonchevskyi wants to merge 1 commit into
box:masterfrom
bonchevskyi:refactor/flow-to-ts-api-folder
Open

bonchevskyi wants to merge 1 commit into
box:masterfrom
bonchevskyi:refactor/flow-to-ts-api-folder

Conversation

@bonchevskyi

@bonchevskyi bonchevskyi commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Convert Folder API to TypeScript

This PR converts src/api/Folder from JavaScript with Flow to TypeScript.

Changes

  • Converted src/api/Folder.js to src/api/Folder.ts
  • Converted src/api/__tests__/Folder.test.js to Folder.test.ts
  • Created src/api/Folder.js.flow (original Flow source) for backward compatibility with remaining Flow importers (APIFactory, Recents, uploads/FolderUploadNode)
  • Updated src/utils/__tests__/flatten.test.ts to cast its constructor options to APIOptions, now that Folder is typed
  • In Folder.test.ts, replaced toThrow(Error, /Bad box item/) with toThrow(Error); Jest ignores the second argument, so the assertions are unchanged

Contract

  • Declared Flow contract preserved (public methods, parameter requiredness, defaults, default export, runtime behavior)
  • folderRequest return type narrowed from Promise<any> to Promise<void> to match its actual return paths; no runtime change

Summary by CodeRabbit

  • New Features
    • Added support for retrieving folder details and paginated contents, using cached data when available.
    • Added the ability to create folders and update cached parent folder contents.
  • Bug Fixes
    • Invalid folder responses are rejected with an error.

@bonchevskyi
bonchevskyi requested a review from a team as a code owner November 30, 2026 14:09
@mergify

mergify Bot commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request once it meets the queue conditions

@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

This change adds a Folder API class for fetching folder details and items, serving cached collections, and creating folders. It also updates tests to use APIOptions types and to assert errors without requiring a specific message.

Changes

Folder API

Layer / File(s) Summary
Folder fetch and cache lookup
src/api/Folder.ts, src/api/__tests__/Folder.test.ts
The new Folder class stores request parameters and callbacks, builds detail and item requests, and returns cached collections unless forceFetch is set.
Folder responses and collections
src/api/Folder.ts, src/api/__tests__/Folder.test.ts, src/utils/__tests__/flatten.test.ts
The class validates folder and collection data, flattens item entries into the cache, and builds collections with pagination and sorting metadata. Tests use APIOptions and check for errors without matching a message.
Folder creation
src/api/Folder.ts, src/api/__tests__/Folder.test.ts
The class posts a folder name and parent ID. If the parent collection is cached, it adds the child and increments total_count; otherwise, it returns the created folder.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Refactor

Possibly related PRs

Suggested reviewers: vitali-usik, tjiang-box, jpan-box

Merge Risk: Minimal · up to a2e8f

This migrates the Folder API and its tests to TypeScript, with a Flow declaration kept for existing importers. No runtime behavior change or merge-blocking issue was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "refactor(api): migrate Folder from Flow to TypeScript" names the main change: the Folder API and its tests move from Flow-typed JavaScript to TypeScript. The raw summary and the PR objectiv…
Description check Passed The description states the purpose (converting src/api/Folder from Flow to TypeScript) and lists the changes: file conversions, the new Folder.js.flow for backward compatibility with remaining Flow im…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "refactor(api): migrate Folder from Flow to TypeScript" names the main change: the Folder API and its tests move from Flow-typed JavaScript to TypeScript. The raw summary and the PR objectives both confirm this as the primary change. The title is specific and follows a conventional commit style.

Full details: Description check

Explanation

The description states the purpose (converting src/api/Folder from Flow to TypeScript) and lists the changes: file conversions, the new Folder.js.flow for backward compatibility with remaining Flow importers, the flatten test cast, and the toThrow assertion change. It also covers the contract preservation and the folderRequest return type narrowing. It does not follow the repository template, which is a merge-queue checklist with no fields to fill in, so the author's content is complete for the change itself.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

A rabbit checks the folder’s trail,
Then gathers cached items without fail.
New entries hop into the view,
A child folder joins the queue.
The API’s paths are clear and bright,
As carrots rest beneath moonlight.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2e6c43b7-bc51-4a61-b21d-7e1fa7b4141f
Commits

Reviewing files that changed from the base of the PR and between fcd5d5b and a2e8fe6.

Files selected for processing: 4

  • src/api/Folder.js.flow
  • src/api/Folder.ts
  • src/api/__tests__/Folder.test.ts
  • src/utils/__tests__/flatten.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.

This branch has not been deployed

No deployments
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