Skip to content

[BUG] Fix search response types that do not match the API - Refs zerodb-typescript-sdk#3 - #8

Merged
urbantech merged 1 commit into
mainfrom
bug/3-search-response-shape
Dec 3, 2026
Merged

urbantech merged 1 commit into
mainfrom
bug/3-search-response-shape

Conversation

@urbantech

Copy link
Copy Markdown
Contributor

Why this PR is here and not on zerodb-typescript-sdk

The issue (zerodb-typescript-sdk#3) was filed against a dead mirror. That
repo's own README says:

⚠️ This repo has moved — This was a duplicate mirror of the AINative
TypeScript SDK. The canonical, actively-maintained repo is
AINative-Studio/TypeScript-SDK.

Confirmed from the registry — the published package points here:

@ainative/sdk  latest: 3.2.1
repository: git+https://github.com/AINative-Studio/TypeScript-SDK.git
Repo Version
zerodb-typescript-sdk (mirror) 1.1.0
TypeScript-SDK (canonical, this one) 3.2.1

Both defects are present here too, so fixing the mirror would have shipped
nothing to users. Please close zerodb-typescript-sdk#3 pointing 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 / searchTimeMs are always undefined

src/types/zerodb.ts:

export interface SearchVectorResponse {
  vectors: Vector[];
  totalCount: number;      // API sends total_count
  searchTimeMs: number;    // API sends search_time_ms
}

There is no case-conversion layer anywhere in src/ — searched for camel,
snake, humps, decamelize, transformResponse. The body is passed through
untouched, so both fields read undefined at runtime while the compiler
guarantees 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 typed as an array, returns an object

src/zerodb/index.ts:169:

search: async (...): Promise<ApiResponse<Memory[]>> => {
  return this.client.post<Memory[]>(`/projects/${projectId}/database/memory/search`, data);
}

The real shapes

From the published OpenAPI schema:

Endpoint Schema Properties
.../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. This PR adds a
separate SearchMemoryResponse rather than reusing the vector one, and a test
guards 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:

x/package/dist/types/zerodb.d.ts:51:    totalCount: number;
x/package/dist/types/zerodb.d.ts:52:    searchTimeMs: number;
x/package/dist/index.d.ts:203:    totalCount: number;
x/package/dist/index.d.ts:204:    searchTimeMs: number;

No transform present in dist either, so installed users are affected — not
just this repo.

Test Plan

npx jest
Suites Tests
Before 7 211 passing
After 8 216 passing

All green, no regressions.

Non-vacuous proof, each defect independently:

Reintroduced Result
camelCase fields 2 of 5 new tests fail
Memory[] return type 1 of 5 fails
Neither 5 passing

The 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 --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. Worth a separate fix
— likely adding them as optional devDependencies so the typecheck is usable.

Refs AINative-Studio/zerodb-typescript-sdk#3

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
@urbantech

Copy link
Copy Markdown
Contributor Author

The one failing check is a pre-existing lint-config gap, not this PR

test (ubuntu-latest, 20) fails in npm run lint:

ESLint couldn't find a configuration file.
ESLint looked for configuration files in .../TypeScript-SDK/examples and its ancestors.
Process completed with exit code 2

There is no ESLint config anywhere in the repo — not at root, not under
examples/. So npm run lint cannot pass on any commit, and Test is red on
the last 4 main runs (6f46cfe7, a2dd75f1, 3d8ca5fa, 24368340).

The other 8 checks are CANCELLED, not failed — the matrix aborts once one
leg exits non-zero. Worth noting because a cancelled check reads as benign next
to a failure, and here it conceals that the real test legs never reported.

Verified locally instead

Checked out this branch, clean npm ci, full suite:

Test Suites: 8 passed, 8 total
Tests:       216 passed, 216 total

216 passing across 8 suites, matching the PR's claim.

Worth fixing separately

Either add an .eslintrc/eslint.config.js, or drop lint from the test
script. As it stands the matrix can never go green, so no check in this repo
produces signal — the same trap as merging through a wall of red.

Merging on the strength of the local run.

@urbantech
urbantech merged commit 6b7eaf7 into main Dec 3, 2026
0 of 9 checks passed
@urbantech
urbantech deleted the bug/3-search-response-shape branch December 3, 2026 03:44
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