Skip to content

fix: keep top-level arrays as arrays in fromSnakeToCamel - #70

Merged
omgate234 merged 3 commits into
mainfrom
release
Sep 3, 2026
Merged

omgate234 merged 3 commits into
mainfrom
release

Conversation

@omgate234

Copy link
Copy Markdown
Collaborator

Pull Request

Description:
Patch release 0.3.2. Fixes snake_case to camelCase conversion of API responses
whose payload is a top-level array, then bumps the version and writes the
changelog entry.

fromSnakeToCamel() ran its input through lodash mapKeys, which turns an
array into a plain object keyed "0", "1", and so on. Any response whose
data was an array therefore reached callers as an index-keyed object rather
than an array. Three methods were broken by this:

  • Collection.searchTitle() threw (res.data || []).map is not a function
  • Video.getThumbnails() threw the same
  • Connection.getInvoices() resolved to an object instead of the unknown[]
    its signature declares

Arrays are now mapped element-wise before falling through to the object chain,
which is the guard fromCamelToSnake() already had. Object conversion is
untouched, so nothing else in the response path changes behaviour.

Changes:

  • Bugfix: fromSnakeToCamel() keeps a top-level array an array (src/utils/index.ts)
  • Regression tests for both converters, top-level arrays, nested arrays,
    empty arrays, arrays of primitives, and the unchanged object path
    (test/regressions.spec.ts)
  • Version bump to 0.3.2 in package.json and package-lock.json.
    binaryConfig.version stays at 0.3.1 on purpose, since it pins the
    capture binary artifact and its checksums, not the package
  • CHANGELOG.md entry for 0.3.2

Related Issues:
None filed. Found while calling searchTitle() against a live collection.

Testing:

  • npm test passes, 23 tests across 2 suites, including the 9 new cases in
    test/regressions.spec.ts
  • npm run build runs clean through tsc and tsc-alias
  • Re-test any caller that consumes a list-shaped response, since those
    previously received an index-keyed object and downstream code may have been
    written around that shape: Collection.searchTitle(),
    Video.getThumbnails(), Connection.getInvoices()

Checklist:

  • Code follows project coding standards
  • Tests have been added or updated
  • Code Review
  • Manual test after merge
  • All checks passed

lodash `mapKeys` on an array returns a plain object keyed "0","1",…, so
any response whose `data` is a top-level array was silently converted to
an object by HttpClient's snake->camel pass. Collection.searchTitle() and
Video.getThumbnails() threw `(res.data || []).map is not a function`, and
Connection.getInvoices() returned an index-keyed object instead of the
declared array.

Map arrays element-wise before falling through to the object chain,
matching the guard fromCamelToSnake already has. Object behaviour is
unchanged.
fix: keep top-level arrays as arrays in fromSnakeToCamel
@omgate234
omgate234 merged commit 2f73b5e into main Sep 3, 2026
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