fix: expose branch create_at and metadata in branches.list() for node and python (#4914)

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>
This commit is contained in:
Tomwang.eth
2026-12-01 17:29:44 +08:00
committed by GitHub
co-authored by tomwangcn
parent a85cb92ffd
commit 76c8bf335a
13 changed files with 424 additions and 52 deletions
-43
View File
@@ -1,43 +0,0 @@
[**@lancedb/lancedb**](../README.md) • **Docs**
***
[@lancedb/lancedb](../globals.md) / BranchContents
# Class: BranchContents
## Constructors
### new BranchContents()
```ts
new BranchContents(): BranchContents
```
#### Returns
[`BranchContents`](BranchContents.md)
## Properties
### manifestSize
```ts
manifestSize: number;
```
***
### parentBranch?
```ts
optional parentBranch: string;
```
***
### parentVersion
```ts
parentVersion: number;
```
+5 -2
View File
@@ -158,11 +158,14 @@ Compare a branch against main without modifying either branch.
### list()
```ts
list(): Promise<Record<string, BranchContents>>
list(): Promise<Record<string, ListedBranchContents>>
```
List all branches, mapping name to branch metadata.
Every entry always carries `createAt` (the branch creation time in Unix
seconds) and `metadata` (a string map), in addition to the fork source.
#### Returns
`Promise`&lt;`Record`&lt;`string`, [`BranchContents`](BranchContents.md)&gt;&gt;
`Promise`&lt;`Record`&lt;`string`, [`ListedBranchContents`](../interfaces/ListedBranchContents.md)&gt;&gt;
+6 -1
View File
@@ -23,7 +23,6 @@
- [BlobFile](classes/BlobFile.md)
- [BooleanQuery](classes/BooleanQuery.md)
- [BoostQuery](classes/BoostQuery.md)
- [BranchContents](classes/BranchContents.md)
- [Branches](classes/Branches.md)
- [Catalog](classes/Catalog.md)
- [ColumnAlreadyExistsError](classes/ColumnAlreadyExistsError.md)
@@ -100,6 +99,7 @@
- [BloomFilterOptions](interfaces/BloomFilterOptions.md)
- [BranchColumnChange](interfaces/BranchColumnChange.md)
- [BranchColumnSummary](interfaces/BranchColumnSummary.md)
- [BranchContents](interfaces/BranchContents.md)
- [BranchDiff](interfaces/BranchDiff.md)
- [BranchIndexSummary](interfaces/BranchIndexSummary.md)
- [BranchRowCountSummary](interfaces/BranchRowCountSummary.md)
@@ -171,6 +171,7 @@
- [JobProgress](interfaces/JobProgress.md)
- [JobWaitOptions](interfaces/JobWaitOptions.md)
- [LanceErrorOptions](interfaces/LanceErrorOptions.md)
- [ListedBranchContents](interfaces/ListedBranchContents.md)
- [ListingOptions](interfaces/ListingOptions.md)
- [MaterializedViewDefinition](interfaces/MaterializedViewDefinition.md)
- [MemtableStats](interfaces/MemtableStats.md)
@@ -259,6 +260,10 @@
- [TableLike](type-aliases/TableLike.md)
- [TokenizeTableOptions](type-aliases/TokenizeTableOptions.md)
## Variables
- [BranchContents](variables/BranchContents.md)
## Functions
- [RecordBatchIterator](functions/RecordBatchIterator.md)
+47
View File
@@ -0,0 +1,47 @@
[**@lancedb/lancedb**](../README.md) • **Docs**
***
[@lancedb/lancedb](../globals.md) / BranchContents
# Interface: BranchContents
Contents of a table branch.
This is the shape released in 0.41.0. Newer fields exposed by
[Branches.list](../classes/Branches.md#list) are declared on [ListedBranchContents](ListedBranchContents.md) so that
values and interfaces written against the released shape remain assignable.
## Extended by
- [`ListedBranchContents`](ListedBranchContents.md)
## Properties
### manifestSize
```ts
manifestSize: number;
```
Size in bytes of the branch's manifest file.
***
### parentBranch?
```ts
optional parentBranch: string;
```
Branch this branch was forked from. Absent for direct forks of `main`.
***
### parentVersion
```ts
parentVersion: number;
```
Version on the parent branch this branch was forked from.
@@ -0,0 +1,76 @@
[**@lancedb/lancedb**](../README.md) • **Docs**
***
[@lancedb/lancedb](../globals.md) / ListedBranchContents
# Interface: ListedBranchContents
Branch contents as returned by [Branches.list](../classes/Branches.md#list), with the newer
`createAt` and `metadata` fields guaranteed to be present.
## Extends
- [`BranchContents`](BranchContents.md)
## Properties
### createAt
```ts
createAt: number;
```
Branch creation time in Unix seconds.
***
### manifestSize
```ts
manifestSize: number;
```
Size in bytes of the branch's manifest file.
#### Inherited from
[`BranchContents`](BranchContents.md).[`manifestSize`](BranchContents.md#manifestsize)
***
### metadata
```ts
metadata: Record<string, string>;
```
Application-defined string metadata.
***
### parentBranch?
```ts
optional parentBranch: string;
```
Branch this branch was forked from. Absent for direct forks of `main`.
#### Inherited from
[`BranchContents`](BranchContents.md).[`parentBranch`](BranchContents.md#parentbranch)
***
### parentVersion
```ts
parentVersion: number;
```
Version on the parent branch this branch was forked from.
#### Inherited from
[`BranchContents`](BranchContents.md).[`parentVersion`](BranchContents.md#parentversion)
+22
View File
@@ -0,0 +1,22 @@
[**@lancedb/lancedb**](../README.md) • **Docs**
***
[@lancedb/lancedb](../globals.md) / BranchContents
# Variable: BranchContents
```ts
BranchContents: () => BranchContents & object;
```
Runtime class of the branch contents returned by [Branches.list](../classes/Branches.md#list).
Returned instances pass `instanceof BranchContents` checks.
## Type declaration
### prototype
```ts
prototype: BranchContents;
```