Repository navigation
[BUG] Fix search response types that do not match the API - Refs zerodb-typescript-sdk#3 - #8
Conversation
Two type-level defects. The request paths are correct, so these failed
silently at the field level rather than with an HTTP error.
1. SearchVectorResponse declared totalCount / searchTimeMs, but the API
sends total_count / search_time_ms. There is no case-conversion layer
anywhere in src/ — searched for camel, snake, humps, decamelize and
transformResponse — so the body is passed through untouched and both
fields read undefined at runtime while the compiler guaranteed
number. Any pagination or timing logic built on them breaks with no
error. `vectors` itself was correct, so results came through and only
the metadata was lost, which is what let this survive review.
2. memory.search was typed Promise<ApiResponse<Memory[]>>, but the
endpoint returns an object rather than a bare array.
The real shapes, from the published OpenAPI schema:
.../database/vectors/search -> VectorSearchResult
{vectors, total_count, search_time_ms}
.../database/memory/search -> MemorySearchResult
{memories, total_count, search_time_ms}
The collection keys DIFFER — vectors vs memories — so no shared
interface or single normalising constant is correct for both. Adds
SearchMemoryResponse rather than reusing the vector one.
Corrects the types rather than adding a runtime transform: introducing
snake-to-camel conversion in the client would silently change the shape
of every response across the whole SDK, including endpoints nobody has
audited. Aligning the declared types with the wire format is the
surgical change, and it makes the compiler tell the truth about what
actually arrives.
Confirmed present in the published artifact: @ainative/[email protected] ships
dist/types/zerodb.d.ts:51-52 and dist/index.d.ts:203-204 with the
camelCase fields and no transform, so installed users are affected.
Tests: 211 -> 216 passing, 7 -> 8 suites, all green.
Verified non-vacuous, each defect independently:
- restoring camelCase fields fails 2 of the 5 new tests
- restoring the Memory[] return type fails 1
- restoring both leaves 5 passing
tsc --noEmit reports 7 pre-existing errors in src/react/ and src/vue/
from missing optional peer deps (react, vue). Identical count and
locations on pristine main; zero in the two files changed here.
Refs #3
The one failing check is a pre-existing lint-config gap, not this PR
There is no ESLint config anywhere in the repo — not at root, not under The other 8 checks are CANCELLED, not failed — the matrix aborts once one Verified locally insteadChecked out this branch, clean 216 passing across 8 suites, matching the PR's claim. Worth fixing separatelyEither add an Merging on the strength of the local run. |
Why this PR is here and not on
zerodb-typescript-sdkThe issue (
zerodb-typescript-sdk#3) was filed against a dead mirror. Thatrepo's own README says:
Confirmed from the registry — the published package points here:
zerodb-typescript-sdk(mirror)TypeScript-SDK(canonical, this one)Both defects are present here too, so fixing the mirror would have shipped
nothing to users. Please close
zerodb-typescript-sdk#3pointing at this PR.The defects
Both are type-level. The request paths are correct, so these fail silently at
the field level rather than with an HTTP error.
1.
totalCount/searchTimeMsare alwaysundefinedsrc/types/zerodb.ts:There is no case-conversion layer anywhere in
src/— searched forcamel,snake,humps,decamelize,transformResponse. The body is passed throughuntouched, so both fields read
undefinedat runtime while the compilerguarantees
number. Any pagination or timing logic built on them breaks with noerror.
vectorsitself was correct, so results came through and only the metadata waslost — which is what let this survive review.
2.
memory.searchtyped as an array, returns an objectsrc/zerodb/index.ts:169:The real shapes
From the published OpenAPI schema:
.../database/vectors/searchVectorSearchResultvectors,total_count,search_time_ms.../database/memory/searchMemorySearchResultmemories,total_count,search_time_msThe collection keys differ —
vectorsvsmemories— so no sharedinterface or single normalising constant is correct for both. This PR adds a
separate
SearchMemoryResponserather than reusing the vector one, and a testguards them against being consolidated later.
Why types, not a runtime transform
Adding snake-to-camel conversion in the client would silently change the shape
of every response across the whole SDK, including endpoints nobody has
audited. Aligning the declared types with the wire format is the surgical
change, and it makes the compiler tell the truth about what actually arrives.
If a camelCase public API is wanted later, that is a deliberate breaking change
with a major version bump — not a quiet fix.
Confirmed in the published artifact
Unpacked
@ainative/[email protected]from npm:No transform present in
disteither, so installed users are affected — notjust this repo.
Test Plan
All green, no regressions.
Non-vacuous proof, each defect independently:
Memory[]return typeThe tests assert against the schema's field names rather than against
whatever the types happen to say, and strip comment lines first so the
explanatory comments naming the wrong fields cannot satisfy or trip them.
Noted, not fixed
tsc --noEmitreports 7 pre-existing errors insrc/react/andsrc/vue/from missing optional peer deps (
react,vue). Identical count and locationson pristine
main; zero in the two files changed here. Worth a separate fix— likely adding them as optional
devDependenciesso the typecheck is usable.Refs AINative-Studio/zerodb-typescript-sdk#3