mirror of
https://github.com/lancedb/lancedb.git
synced 2026-12-03 07:45:17 +00:00
Fixes #4849. **Problem** - TypeScript SDK: `Branches.list()` returned napi class instances whose fields live on the prototype, so `console.log`, spread and `JSON.stringify` showed `{}` (the exact symptom in the docs example). `create_at` and `metadata`, which Lance already stores for every branch, were not exposed at all. - Python SDK: the `Branches.list()` dicts also dropped `create_at` and `metadata`. **Change** - `nodejs/src/table.rs`: `BranchContents` stays a runtime napi class export and gains `create_at` (Unix seconds) and `metadata`, populated from the stored Lance branch contents. The `metadata` getter defines every key as an own enumerable data property (`napi_define_properties`), so keys like `__proto__` that ordinary map conversion would route to the prototype setter are preserved. - `nodejs/lancedb/table.ts`: the `Branches.list()` wrapper promotes all fields (`parentBranch`, `parentVersion`, `createAt`, `manifestSize`, `metadata`) to own enumerable properties on each returned instance by reusing the class getters and setters, so spread and `JSON.stringify` see them while `instanceof` keeps working. Its return type is `ListedBranchContents`, which guarantees `createAt` and `metadata`. - Public typing: the exported `BranchContents` type keeps its released shape (`parentBranch`/`parentVersion`/`manifestSize` only), so values and interfaces written against it stay assignable and extendable, including a view whose `createAt` is a `Date` and an interface that extends `BranchContents` with its own `metadata`. `ListedBranchContents extends BranchContents` adds `createAt` and `metadata` as required fields, and the exported `BranchContents` constructor value has its `prototype` typed as `BranchContents`, so the class value and `instanceof` checks are unchanged. - `python/src/table.rs`: `Branches.list()` dicts now include `create_at` and `metadata`. - Docs: regenerated TypeScript API reference for the new shape, and the branching guide now documents `createAt`/`create_at` (Unix seconds) and `metadata`. **Tests** - `nodejs/__test__/table.test.ts`: a branch whose stored ref file carries non-empty metadata (including a `__proto__` key) and a known creation time in Unix seconds is listed with both, as a `BranchContents` instance with own enumerable fields, surviving spread and a JSON round-trip with every metadata key intact. A second test covers the consumer type contracts with `tsc`: a released-shape value with an extra `createAt: Date` stays assignable to `BranchContents`, an interface extending `BranchContents` can declare its own `metadata` shape, the exported constructor's `prototype` is typed as `BranchContents`, and `branches.list()` results guarantee `createAt` and `metadata`. - `python/python/tests/test_table.py::test_branches`: same non-empty-metadata (with `__proto__`) and known-`create_at` coverage. - Verified locally on Linux x86_64: `tsc -b`, Biome checks, regenerated docs diff limited to the `BranchContents` pages, node branches suite (34 passed), python `test_branches` (4 passed, 1 skipped). --------- Co-authored-by: tomwangcn <tomwangcn@users.noreply.github.com>
423 B
423 B
@lancedb/lancedb • Docs
@lancedb/lancedb / BranchContents
Variable: BranchContents
BranchContents: () => BranchContents & object;
Runtime class of the branch contents returned by Branches.list.
Returned instances pass instanceof BranchContents checks.
Type declaration
prototype
prototype: BranchContents;