@kernl-sdk/pg 0.1.11 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/.turbo/turbo-check-types.log +36 -0
- package/CHANGELOG.md +32 -0
- package/README.md +124 -0
- package/dist/__tests__/integration.test.js +2 -2
- package/dist/__tests__/memory-integration.test.d.ts +2 -0
- package/dist/__tests__/memory-integration.test.d.ts.map +1 -0
- package/dist/__tests__/memory-integration.test.js +287 -0
- package/dist/__tests__/memory.test.d.ts +2 -0
- package/dist/__tests__/memory.test.d.ts.map +1 -0
- package/dist/__tests__/memory.test.js +357 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -3
- package/dist/memory/sql.d.ts +30 -0
- package/dist/memory/sql.d.ts.map +1 -0
- package/dist/memory/sql.js +100 -0
- package/dist/memory/store.d.ts +41 -0
- package/dist/memory/store.d.ts.map +1 -0
- package/dist/memory/store.js +114 -0
- package/dist/migrations.d.ts +1 -1
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js +9 -3
- package/dist/pgvector/__tests__/handle.test.d.ts +2 -0
- package/dist/pgvector/__tests__/handle.test.d.ts.map +1 -0
- package/dist/pgvector/__tests__/handle.test.js +277 -0
- package/dist/pgvector/__tests__/hit.test.d.ts +2 -0
- package/dist/pgvector/__tests__/hit.test.d.ts.map +1 -0
- package/dist/pgvector/__tests__/hit.test.js +134 -0
- package/dist/pgvector/__tests__/integration/document.integration.test.d.ts +7 -0
- package/dist/pgvector/__tests__/integration/document.integration.test.d.ts.map +1 -0
- package/dist/pgvector/__tests__/integration/document.integration.test.js +587 -0
- package/dist/pgvector/__tests__/integration/edge.integration.test.d.ts +8 -0
- package/dist/pgvector/__tests__/integration/edge.integration.test.d.ts.map +1 -0
- package/dist/pgvector/__tests__/integration/edge.integration.test.js +663 -0
- package/dist/pgvector/__tests__/integration/filters.integration.test.d.ts +8 -0
- package/dist/pgvector/__tests__/integration/filters.integration.test.d.ts.map +1 -0
- package/dist/pgvector/__tests__/integration/filters.integration.test.js +609 -0
- package/dist/pgvector/__tests__/integration/lifecycle.integration.test.d.ts +8 -0
- package/dist/pgvector/__tests__/integration/lifecycle.integration.test.d.ts.map +1 -0
- package/dist/pgvector/__tests__/integration/lifecycle.integration.test.js +449 -0
- package/dist/pgvector/__tests__/integration/query.integration.test.d.ts +8 -0
- package/dist/pgvector/__tests__/integration/query.integration.test.d.ts.map +1 -0
- package/dist/pgvector/__tests__/integration/query.integration.test.js +544 -0
- package/dist/pgvector/__tests__/search.test.d.ts +2 -0
- package/dist/pgvector/__tests__/search.test.d.ts.map +1 -0
- package/dist/pgvector/__tests__/search.test.js +279 -0
- package/dist/pgvector/handle.d.ts +60 -0
- package/dist/pgvector/handle.d.ts.map +1 -0
- package/dist/pgvector/handle.js +213 -0
- package/dist/pgvector/hit.d.ts +10 -0
- package/dist/pgvector/hit.d.ts.map +1 -0
- package/dist/pgvector/hit.js +44 -0
- package/dist/pgvector/index.d.ts +7 -0
- package/dist/pgvector/index.d.ts.map +1 -0
- package/dist/pgvector/index.js +5 -0
- package/dist/pgvector/search.d.ts +60 -0
- package/dist/pgvector/search.d.ts.map +1 -0
- package/dist/pgvector/search.js +227 -0
- package/dist/pgvector/sql/__tests__/limit.test.d.ts +2 -0
- package/dist/pgvector/sql/__tests__/limit.test.d.ts.map +1 -0
- package/dist/pgvector/sql/__tests__/limit.test.js +161 -0
- package/dist/pgvector/sql/__tests__/order.test.d.ts +2 -0
- package/dist/pgvector/sql/__tests__/order.test.d.ts.map +1 -0
- package/dist/pgvector/sql/__tests__/order.test.js +218 -0
- package/dist/pgvector/sql/__tests__/query.test.d.ts +2 -0
- package/dist/pgvector/sql/__tests__/query.test.d.ts.map +1 -0
- package/dist/pgvector/sql/__tests__/query.test.js +392 -0
- package/dist/pgvector/sql/__tests__/select.test.d.ts +2 -0
- package/dist/pgvector/sql/__tests__/select.test.d.ts.map +1 -0
- package/dist/pgvector/sql/__tests__/select.test.js +293 -0
- package/dist/pgvector/sql/__tests__/where.test.d.ts +2 -0
- package/dist/pgvector/sql/__tests__/where.test.d.ts.map +1 -0
- package/dist/pgvector/sql/__tests__/where.test.js +488 -0
- package/dist/pgvector/sql/index.d.ts +7 -0
- package/dist/pgvector/sql/index.d.ts.map +1 -0
- package/dist/pgvector/sql/index.js +6 -0
- package/dist/pgvector/sql/limit.d.ts +8 -0
- package/dist/pgvector/sql/limit.d.ts.map +1 -0
- package/dist/pgvector/sql/limit.js +20 -0
- package/dist/pgvector/sql/order.d.ts +9 -0
- package/dist/pgvector/sql/order.d.ts.map +1 -0
- package/dist/pgvector/sql/order.js +47 -0
- package/dist/pgvector/sql/query.d.ts +46 -0
- package/dist/pgvector/sql/query.d.ts.map +1 -0
- package/dist/pgvector/sql/query.js +54 -0
- package/dist/pgvector/sql/schema.d.ts +16 -0
- package/dist/pgvector/sql/schema.d.ts.map +1 -0
- package/dist/pgvector/sql/schema.js +47 -0
- package/dist/pgvector/sql/select.d.ts +11 -0
- package/dist/pgvector/sql/select.d.ts.map +1 -0
- package/dist/pgvector/sql/select.js +87 -0
- package/dist/pgvector/sql/where.d.ts +8 -0
- package/dist/pgvector/sql/where.d.ts.map +1 -0
- package/dist/pgvector/sql/where.js +137 -0
- package/dist/pgvector/types.d.ts +20 -0
- package/dist/pgvector/types.d.ts.map +1 -0
- package/dist/pgvector/types.js +1 -0
- package/dist/pgvector/utils.d.ts +18 -0
- package/dist/pgvector/utils.d.ts.map +1 -0
- package/dist/pgvector/utils.js +22 -0
- package/dist/postgres.d.ts +19 -26
- package/dist/postgres.d.ts.map +1 -1
- package/dist/postgres.js +15 -27
- package/dist/storage.d.ts +48 -0
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +32 -9
- package/dist/thread/sql.d.ts +38 -0
- package/dist/thread/sql.d.ts.map +1 -0
- package/dist/thread/sql.js +112 -0
- package/dist/thread/store.d.ts +2 -2
- package/dist/thread/store.d.ts.map +1 -1
- package/dist/thread/store.js +32 -102
- package/package.json +7 -4
- package/src/__tests__/integration.test.ts +15 -17
- package/src/__tests__/memory-integration.test.ts +355 -0
- package/src/__tests__/memory.test.ts +428 -0
- package/src/index.ts +19 -3
- package/src/memory/sql.ts +141 -0
- package/src/memory/store.ts +166 -0
- package/src/migrations.ts +13 -3
- package/src/pgvector/README.md +50 -0
- package/src/pgvector/__tests__/handle.test.ts +335 -0
- package/src/pgvector/__tests__/hit.test.ts +165 -0
- package/src/pgvector/__tests__/integration/document.integration.test.ts +717 -0
- package/src/pgvector/__tests__/integration/edge.integration.test.ts +835 -0
- package/src/pgvector/__tests__/integration/filters.integration.test.ts +721 -0
- package/src/pgvector/__tests__/integration/lifecycle.integration.test.ts +570 -0
- package/src/pgvector/__tests__/integration/query.integration.test.ts +667 -0
- package/src/pgvector/__tests__/search.test.ts +366 -0
- package/src/pgvector/handle.ts +285 -0
- package/src/pgvector/hit.ts +56 -0
- package/src/pgvector/index.ts +7 -0
- package/src/pgvector/search.ts +330 -0
- package/src/pgvector/sql/__tests__/limit.test.ts +180 -0
- package/src/pgvector/sql/__tests__/order.test.ts +248 -0
- package/src/pgvector/sql/__tests__/query.test.ts +548 -0
- package/src/pgvector/sql/__tests__/select.test.ts +367 -0
- package/src/pgvector/sql/__tests__/where.test.ts +554 -0
- package/src/pgvector/sql/index.ts +14 -0
- package/src/pgvector/sql/limit.ts +29 -0
- package/src/pgvector/sql/order.ts +55 -0
- package/src/pgvector/sql/query.ts +112 -0
- package/src/pgvector/sql/schema.ts +61 -0
- package/src/pgvector/sql/select.ts +100 -0
- package/src/pgvector/sql/where.ts +152 -0
- package/src/pgvector/types.ts +21 -0
- package/src/pgvector/utils.ts +24 -0
- package/src/postgres.ts +31 -33
- package/src/storage.ts +77 -9
- package/src/thread/sql.ts +159 -0
- package/src/thread/store.ts +40 -127
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { SEARCH_HIT } from "../hit";
|
|
3
|
+
|
|
4
|
+
describe("SEARCH_HIT", () => {
|
|
5
|
+
describe("decode", () => {
|
|
6
|
+
it("converts basic row to SearchHit", () => {
|
|
7
|
+
const row = {
|
|
8
|
+
id: "doc-123",
|
|
9
|
+
score: 0.95,
|
|
10
|
+
title: "Hello World",
|
|
11
|
+
content: "Some content",
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const result = SEARCH_HIT.decode(row, "docs");
|
|
15
|
+
|
|
16
|
+
expect(result).toEqual({
|
|
17
|
+
id: "doc-123",
|
|
18
|
+
index: "docs",
|
|
19
|
+
score: 0.95,
|
|
20
|
+
document: {
|
|
21
|
+
id: "doc-123",
|
|
22
|
+
title: "Hello World",
|
|
23
|
+
content: "Some content",
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("converts id to string", () => {
|
|
29
|
+
const row = { id: 123, score: 0.5 };
|
|
30
|
+
const result = SEARCH_HIT.decode(row, "docs");
|
|
31
|
+
expect(result.id).toBe("123");
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("defaults score to 0 when not a number", () => {
|
|
35
|
+
const row = { id: "1", score: null };
|
|
36
|
+
const result = SEARCH_HIT.decode(row, "docs");
|
|
37
|
+
expect(result.score).toBe(0);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("defaults score to 0 when undefined", () => {
|
|
41
|
+
const row = { id: "1" };
|
|
42
|
+
const result = SEARCH_HIT.decode(row, "docs");
|
|
43
|
+
expect(result.score).toBe(0);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("returns document with only id when no other fields", () => {
|
|
47
|
+
const row = { id: "1", score: 0.5 };
|
|
48
|
+
const result = SEARCH_HIT.decode(row, "docs");
|
|
49
|
+
expect(result.document).toEqual({ id: "1" });
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe("with binding", () => {
|
|
53
|
+
const binding = {
|
|
54
|
+
schema: "public",
|
|
55
|
+
table: "documents",
|
|
56
|
+
pkey: "id",
|
|
57
|
+
fields: {
|
|
58
|
+
title: { column: "doc_title", type: "string" as const },
|
|
59
|
+
content: { column: "doc_content", type: "string" as const },
|
|
60
|
+
embedding: {
|
|
61
|
+
column: "vec",
|
|
62
|
+
type: "vector" as const,
|
|
63
|
+
dimensions: 3,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
it("maps columns to logical field names", () => {
|
|
69
|
+
const row = {
|
|
70
|
+
id: "1",
|
|
71
|
+
score: 0.9,
|
|
72
|
+
doc_title: "Hello",
|
|
73
|
+
doc_content: "World",
|
|
74
|
+
vec: [0.1, 0.2, 0.3],
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const result = SEARCH_HIT.decode(row, "docs", binding);
|
|
78
|
+
|
|
79
|
+
expect(result.document).toEqual({
|
|
80
|
+
id: "1",
|
|
81
|
+
title: "Hello",
|
|
82
|
+
content: "World",
|
|
83
|
+
embedding: [0.1, 0.2, 0.3],
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("only includes fields defined in binding", () => {
|
|
88
|
+
const row = {
|
|
89
|
+
id: "1",
|
|
90
|
+
score: 0.9,
|
|
91
|
+
doc_title: "Hello",
|
|
92
|
+
extra_col: "should be ignored",
|
|
93
|
+
internal_field: "also ignored",
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const result = SEARCH_HIT.decode(row, "docs", binding);
|
|
97
|
+
|
|
98
|
+
expect(result.document).toEqual({
|
|
99
|
+
id: "1",
|
|
100
|
+
title: "Hello",
|
|
101
|
+
});
|
|
102
|
+
expect((result.document as any)?.extra_col).toBeUndefined();
|
|
103
|
+
expect((result.document as any)?.internal_field).toBeUndefined();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("handles missing columns gracefully", () => {
|
|
107
|
+
const row = {
|
|
108
|
+
id: "1",
|
|
109
|
+
score: 0.9,
|
|
110
|
+
doc_title: "Hello",
|
|
111
|
+
// doc_content and vec are missing
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const result = SEARCH_HIT.decode(row, "docs", binding);
|
|
115
|
+
|
|
116
|
+
expect(result.document).toEqual({
|
|
117
|
+
id: "1",
|
|
118
|
+
title: "Hello",
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("returns document with only id when no bound fields present", () => {
|
|
123
|
+
const row = {
|
|
124
|
+
id: "1",
|
|
125
|
+
score: 0.9,
|
|
126
|
+
unrelated_column: "value",
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const result = SEARCH_HIT.decode(row, "docs", binding);
|
|
130
|
+
|
|
131
|
+
expect(result.document).toEqual({ id: "1" });
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
describe("with TDocument generic", () => {
|
|
136
|
+
interface Document {
|
|
137
|
+
title: string;
|
|
138
|
+
views: number;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
it("types document correctly", () => {
|
|
142
|
+
const row = {
|
|
143
|
+
id: "1",
|
|
144
|
+
score: 0.9,
|
|
145
|
+
title: "Hello",
|
|
146
|
+
views: 100,
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
const result = SEARCH_HIT.decode<Document>(row, "docs");
|
|
150
|
+
|
|
151
|
+
// TypeScript should allow accessing these fields
|
|
152
|
+
expect(result.document?.title).toBe("Hello");
|
|
153
|
+
expect(result.document?.views).toBe(100);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
describe("encode", () => {
|
|
159
|
+
it("throws not implemented", () => {
|
|
160
|
+
expect(() => SEARCH_HIT.encode({} as any)).toThrow(
|
|
161
|
+
"SEARCH_HIT.encode: not implemented",
|
|
162
|
+
);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
});
|