mirror of
https://github.com/lancedb/lancedb.git
synced 2026-12-03 07:45:17 +00:00
fix(node): make tags.list() values plain serializable objects (#4915)
Related: #4849 (same defect class on `branches.list()`, fixed in #4914). **Problem** `Tags.list()` returns napi class instances whose fields live on the prototype, so `console.log`, spread and `JSON.stringify` show `{}` — the documented example (`{ "v1": { version: 1, manifestSize: ... } }`) doesn't match what users actually see. Property access (`tags["v1"].version`) works, which is why the existing tests didn't catch it. **Change** - `TagContents` stays a runtime napi class export: existing ESM named imports of `TagContents` and `instanceof` checks keep working, and existing TypeScript values remain assignable to it. - `nodejs/lancedb/table.ts` post-processes `Tags.prototype.list()` results, promoting `version` and `manifestSize` to own enumerable properties on each returned instance by reusing the class getters and setters. Values are now enumerable, spreadable and JSON-serializable with no fields added, removed or renamed. - TS-only: the Python SDK already returns proper dicts with both fields. **Tests** - New regression test in `nodejs/__test__/table.test.ts` covers the named import and `instanceof` alongside own-enumerable keys, spread and a JSON round-trip through `tags.list()`. - The tag tests from #5145 are kept and pass against this change. - Verified locally on Linux x86_64: `tsc -b`, Biome checks, and the focused tags suite (4 passed), including `tags.create(name)` / `tags.create(name, null)` behavior.
This commit is contained in:
@@ -19,6 +19,7 @@ import {
|
||||
Table,
|
||||
TableDelta,
|
||||
TableDeltaReader,
|
||||
TagContents,
|
||||
VectorQuery,
|
||||
blob,
|
||||
connect,
|
||||
@@ -4144,6 +4145,34 @@ describe("when dealing with tags", () => {
|
||||
await tags.create("tag-checkout");
|
||||
expect(await tags.getVersion("tag-checkout")).toBe(2);
|
||||
});
|
||||
|
||||
it("returns serializable TagContents instances from list()", async () => {
|
||||
const conn = await connect(tmpDir.name, {
|
||||
readConsistencyInterval: 0,
|
||||
});
|
||||
const table = await conn.createTable("my_table", [
|
||||
{ id: 1n, vector: [0.1, 0.2] },
|
||||
]);
|
||||
const tagsManager = await table.tags();
|
||||
await tagsManager.create("tag1", 1);
|
||||
|
||||
const list = await tagsManager.list();
|
||||
const tag1 = list["tag1"];
|
||||
|
||||
// The runtime class export and instance identity are preserved.
|
||||
expect(tag1).toBeInstanceOf(TagContents);
|
||||
|
||||
// version and manifestSize are own enumerable properties, so spread
|
||||
// and JSON serialization see them.
|
||||
expect(Object.keys(tag1)).toEqual(
|
||||
expect.arrayContaining(["version", "manifestSize"]),
|
||||
);
|
||||
expect({ ...tag1 }.version).toBe(1);
|
||||
|
||||
const serialized = JSON.parse(JSON.stringify(list));
|
||||
expect(serialized["tag1"].version).toBe(1);
|
||||
expect(serialized["tag1"].manifestSize).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("when dealing with branches", () => {
|
||||
|
||||
Reference in New Issue
Block a user