@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.
Files changed (153) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.turbo/turbo-check-types.log +36 -0
  3. package/CHANGELOG.md +32 -0
  4. package/README.md +124 -0
  5. package/dist/__tests__/integration.test.js +2 -2
  6. package/dist/__tests__/memory-integration.test.d.ts +2 -0
  7. package/dist/__tests__/memory-integration.test.d.ts.map +1 -0
  8. package/dist/__tests__/memory-integration.test.js +287 -0
  9. package/dist/__tests__/memory.test.d.ts +2 -0
  10. package/dist/__tests__/memory.test.d.ts.map +1 -0
  11. package/dist/__tests__/memory.test.js +357 -0
  12. package/dist/index.d.ts +5 -3
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +5 -3
  15. package/dist/memory/sql.d.ts +30 -0
  16. package/dist/memory/sql.d.ts.map +1 -0
  17. package/dist/memory/sql.js +100 -0
  18. package/dist/memory/store.d.ts +41 -0
  19. package/dist/memory/store.d.ts.map +1 -0
  20. package/dist/memory/store.js +114 -0
  21. package/dist/migrations.d.ts +1 -1
  22. package/dist/migrations.d.ts.map +1 -1
  23. package/dist/migrations.js +9 -3
  24. package/dist/pgvector/__tests__/handle.test.d.ts +2 -0
  25. package/dist/pgvector/__tests__/handle.test.d.ts.map +1 -0
  26. package/dist/pgvector/__tests__/handle.test.js +277 -0
  27. package/dist/pgvector/__tests__/hit.test.d.ts +2 -0
  28. package/dist/pgvector/__tests__/hit.test.d.ts.map +1 -0
  29. package/dist/pgvector/__tests__/hit.test.js +134 -0
  30. package/dist/pgvector/__tests__/integration/document.integration.test.d.ts +7 -0
  31. package/dist/pgvector/__tests__/integration/document.integration.test.d.ts.map +1 -0
  32. package/dist/pgvector/__tests__/integration/document.integration.test.js +587 -0
  33. package/dist/pgvector/__tests__/integration/edge.integration.test.d.ts +8 -0
  34. package/dist/pgvector/__tests__/integration/edge.integration.test.d.ts.map +1 -0
  35. package/dist/pgvector/__tests__/integration/edge.integration.test.js +663 -0
  36. package/dist/pgvector/__tests__/integration/filters.integration.test.d.ts +8 -0
  37. package/dist/pgvector/__tests__/integration/filters.integration.test.d.ts.map +1 -0
  38. package/dist/pgvector/__tests__/integration/filters.integration.test.js +609 -0
  39. package/dist/pgvector/__tests__/integration/lifecycle.integration.test.d.ts +8 -0
  40. package/dist/pgvector/__tests__/integration/lifecycle.integration.test.d.ts.map +1 -0
  41. package/dist/pgvector/__tests__/integration/lifecycle.integration.test.js +449 -0
  42. package/dist/pgvector/__tests__/integration/query.integration.test.d.ts +8 -0
  43. package/dist/pgvector/__tests__/integration/query.integration.test.d.ts.map +1 -0
  44. package/dist/pgvector/__tests__/integration/query.integration.test.js +544 -0
  45. package/dist/pgvector/__tests__/search.test.d.ts +2 -0
  46. package/dist/pgvector/__tests__/search.test.d.ts.map +1 -0
  47. package/dist/pgvector/__tests__/search.test.js +279 -0
  48. package/dist/pgvector/handle.d.ts +60 -0
  49. package/dist/pgvector/handle.d.ts.map +1 -0
  50. package/dist/pgvector/handle.js +213 -0
  51. package/dist/pgvector/hit.d.ts +10 -0
  52. package/dist/pgvector/hit.d.ts.map +1 -0
  53. package/dist/pgvector/hit.js +44 -0
  54. package/dist/pgvector/index.d.ts +7 -0
  55. package/dist/pgvector/index.d.ts.map +1 -0
  56. package/dist/pgvector/index.js +5 -0
  57. package/dist/pgvector/search.d.ts +60 -0
  58. package/dist/pgvector/search.d.ts.map +1 -0
  59. package/dist/pgvector/search.js +227 -0
  60. package/dist/pgvector/sql/__tests__/limit.test.d.ts +2 -0
  61. package/dist/pgvector/sql/__tests__/limit.test.d.ts.map +1 -0
  62. package/dist/pgvector/sql/__tests__/limit.test.js +161 -0
  63. package/dist/pgvector/sql/__tests__/order.test.d.ts +2 -0
  64. package/dist/pgvector/sql/__tests__/order.test.d.ts.map +1 -0
  65. package/dist/pgvector/sql/__tests__/order.test.js +218 -0
  66. package/dist/pgvector/sql/__tests__/query.test.d.ts +2 -0
  67. package/dist/pgvector/sql/__tests__/query.test.d.ts.map +1 -0
  68. package/dist/pgvector/sql/__tests__/query.test.js +392 -0
  69. package/dist/pgvector/sql/__tests__/select.test.d.ts +2 -0
  70. package/dist/pgvector/sql/__tests__/select.test.d.ts.map +1 -0
  71. package/dist/pgvector/sql/__tests__/select.test.js +293 -0
  72. package/dist/pgvector/sql/__tests__/where.test.d.ts +2 -0
  73. package/dist/pgvector/sql/__tests__/where.test.d.ts.map +1 -0
  74. package/dist/pgvector/sql/__tests__/where.test.js +488 -0
  75. package/dist/pgvector/sql/index.d.ts +7 -0
  76. package/dist/pgvector/sql/index.d.ts.map +1 -0
  77. package/dist/pgvector/sql/index.js +6 -0
  78. package/dist/pgvector/sql/limit.d.ts +8 -0
  79. package/dist/pgvector/sql/limit.d.ts.map +1 -0
  80. package/dist/pgvector/sql/limit.js +20 -0
  81. package/dist/pgvector/sql/order.d.ts +9 -0
  82. package/dist/pgvector/sql/order.d.ts.map +1 -0
  83. package/dist/pgvector/sql/order.js +47 -0
  84. package/dist/pgvector/sql/query.d.ts +46 -0
  85. package/dist/pgvector/sql/query.d.ts.map +1 -0
  86. package/dist/pgvector/sql/query.js +54 -0
  87. package/dist/pgvector/sql/schema.d.ts +16 -0
  88. package/dist/pgvector/sql/schema.d.ts.map +1 -0
  89. package/dist/pgvector/sql/schema.js +47 -0
  90. package/dist/pgvector/sql/select.d.ts +11 -0
  91. package/dist/pgvector/sql/select.d.ts.map +1 -0
  92. package/dist/pgvector/sql/select.js +87 -0
  93. package/dist/pgvector/sql/where.d.ts +8 -0
  94. package/dist/pgvector/sql/where.d.ts.map +1 -0
  95. package/dist/pgvector/sql/where.js +137 -0
  96. package/dist/pgvector/types.d.ts +20 -0
  97. package/dist/pgvector/types.d.ts.map +1 -0
  98. package/dist/pgvector/types.js +1 -0
  99. package/dist/pgvector/utils.d.ts +18 -0
  100. package/dist/pgvector/utils.d.ts.map +1 -0
  101. package/dist/pgvector/utils.js +22 -0
  102. package/dist/postgres.d.ts +19 -26
  103. package/dist/postgres.d.ts.map +1 -1
  104. package/dist/postgres.js +15 -27
  105. package/dist/storage.d.ts +48 -0
  106. package/dist/storage.d.ts.map +1 -1
  107. package/dist/storage.js +32 -9
  108. package/dist/thread/sql.d.ts +38 -0
  109. package/dist/thread/sql.d.ts.map +1 -0
  110. package/dist/thread/sql.js +112 -0
  111. package/dist/thread/store.d.ts +2 -2
  112. package/dist/thread/store.d.ts.map +1 -1
  113. package/dist/thread/store.js +32 -102
  114. package/package.json +7 -4
  115. package/src/__tests__/integration.test.ts +15 -17
  116. package/src/__tests__/memory-integration.test.ts +355 -0
  117. package/src/__tests__/memory.test.ts +428 -0
  118. package/src/index.ts +19 -3
  119. package/src/memory/sql.ts +141 -0
  120. package/src/memory/store.ts +166 -0
  121. package/src/migrations.ts +13 -3
  122. package/src/pgvector/README.md +50 -0
  123. package/src/pgvector/__tests__/handle.test.ts +335 -0
  124. package/src/pgvector/__tests__/hit.test.ts +165 -0
  125. package/src/pgvector/__tests__/integration/document.integration.test.ts +717 -0
  126. package/src/pgvector/__tests__/integration/edge.integration.test.ts +835 -0
  127. package/src/pgvector/__tests__/integration/filters.integration.test.ts +721 -0
  128. package/src/pgvector/__tests__/integration/lifecycle.integration.test.ts +570 -0
  129. package/src/pgvector/__tests__/integration/query.integration.test.ts +667 -0
  130. package/src/pgvector/__tests__/search.test.ts +366 -0
  131. package/src/pgvector/handle.ts +285 -0
  132. package/src/pgvector/hit.ts +56 -0
  133. package/src/pgvector/index.ts +7 -0
  134. package/src/pgvector/search.ts +330 -0
  135. package/src/pgvector/sql/__tests__/limit.test.ts +180 -0
  136. package/src/pgvector/sql/__tests__/order.test.ts +248 -0
  137. package/src/pgvector/sql/__tests__/query.test.ts +548 -0
  138. package/src/pgvector/sql/__tests__/select.test.ts +367 -0
  139. package/src/pgvector/sql/__tests__/where.test.ts +554 -0
  140. package/src/pgvector/sql/index.ts +14 -0
  141. package/src/pgvector/sql/limit.ts +29 -0
  142. package/src/pgvector/sql/order.ts +55 -0
  143. package/src/pgvector/sql/query.ts +112 -0
  144. package/src/pgvector/sql/schema.ts +61 -0
  145. package/src/pgvector/sql/select.ts +100 -0
  146. package/src/pgvector/sql/where.ts +152 -0
  147. package/src/pgvector/types.ts +21 -0
  148. package/src/pgvector/utils.ts +24 -0
  149. package/src/postgres.ts +31 -33
  150. package/src/storage.ts +77 -9
  151. package/src/thread/sql.ts +159 -0
  152. package/src/thread/store.ts +40 -127
  153. 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
+ });