sensemaking 0.18.2 → 0.18.4

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 (179) hide show
  1. package/dist/cjs/cli/status.js +32 -31
  2. package/dist/cjs/cli/status.js.map +1 -1
  3. package/dist/cjs/commands/map.js +50 -67
  4. package/dist/cjs/commands/map.js.map +1 -1
  5. package/dist/cjs/config/access.d.cts +2 -2
  6. package/dist/cjs/config/access.d.ts +2 -2
  7. package/dist/cjs/config/access.js.map +1 -1
  8. package/dist/cjs/config/index.d.cts +1 -1
  9. package/dist/cjs/config/index.d.ts +1 -1
  10. package/dist/cjs/config/index.js.map +1 -1
  11. package/dist/cjs/config/load.js +3 -2
  12. package/dist/cjs/config/load.js.map +1 -1
  13. package/dist/cjs/config/types.d.cts +2 -1
  14. package/dist/cjs/config/types.d.ts +2 -1
  15. package/dist/cjs/config/types.js.map +1 -1
  16. package/dist/cjs/config/validate.js +3 -0
  17. package/dist/cjs/config/validate.js.map +1 -1
  18. package/dist/cjs/embed/identity.js +3 -2
  19. package/dist/cjs/embed/identity.js.map +1 -1
  20. package/dist/cjs/embed/store.js +3 -3
  21. package/dist/cjs/embed/store.js.map +1 -1
  22. package/dist/cjs/index.d.cts +2 -2
  23. package/dist/cjs/index.d.ts +2 -2
  24. package/dist/cjs/index.js.map +1 -1
  25. package/dist/cjs/lib/atomic-write.d.cts +1 -0
  26. package/dist/cjs/lib/atomic-write.d.ts +1 -0
  27. package/dist/cjs/lib/atomic-write.js +26 -0
  28. package/dist/cjs/lib/atomic-write.js.map +1 -0
  29. package/dist/cjs/store/duckdb/batch.js +3 -2
  30. package/dist/cjs/store/duckdb/batch.js.map +1 -1
  31. package/dist/cjs/store/duckdb/connection.js +12 -0
  32. package/dist/cjs/store/duckdb/connection.js.map +1 -1
  33. package/dist/cjs/store/duckdb/fieldStats.d.cts +2 -0
  34. package/dist/cjs/store/duckdb/fieldStats.d.ts +2 -0
  35. package/dist/cjs/store/duckdb/fieldStats.js +219 -0
  36. package/dist/cjs/store/duckdb/fieldStats.js.map +1 -0
  37. package/dist/cjs/store/duckdb/lexical.js +16 -9
  38. package/dist/cjs/store/duckdb/lexical.js.map +1 -1
  39. package/dist/cjs/store/duckdb/native.d.cts +0 -1
  40. package/dist/cjs/store/duckdb/native.d.ts +0 -1
  41. package/dist/cjs/store/duckdb/native.js +7 -336
  42. package/dist/cjs/store/duckdb/native.js.map +1 -1
  43. package/dist/cjs/store/duckdb/sql-functions.js +1 -1
  44. package/dist/cjs/store/duckdb/sql-functions.js.map +1 -1
  45. package/dist/cjs/store/duckdb/store.js +16 -1
  46. package/dist/cjs/store/duckdb/store.js.map +1 -1
  47. package/dist/cjs/store/duckdb/vectors.js +5 -17
  48. package/dist/cjs/store/duckdb/vectors.js.map +1 -1
  49. package/dist/cjs/store/index.js +6 -0
  50. package/dist/cjs/store/index.js.map +1 -1
  51. package/dist/cjs/store/native.d.cts +7 -0
  52. package/dist/cjs/store/native.d.ts +7 -0
  53. package/dist/cjs/store/native.js +350 -0
  54. package/dist/cjs/store/native.js.map +1 -0
  55. package/dist/cjs/store/sqlite/fieldStats.d.cts +2 -0
  56. package/dist/cjs/store/sqlite/fieldStats.d.ts +2 -0
  57. package/dist/cjs/store/sqlite/fieldStats.js +201 -0
  58. package/dist/cjs/store/sqlite/fieldStats.js.map +1 -0
  59. package/dist/cjs/store/sqlite/open.js +82 -29
  60. package/dist/cjs/store/sqlite/open.js.map +1 -1
  61. package/dist/cjs/store/sqlite/store.js +32 -4
  62. package/dist/cjs/store/sqlite/store.js.map +1 -1
  63. package/dist/cjs/store/sqlite/vectors.d.cts +0 -5
  64. package/dist/cjs/store/sqlite/vectors.d.ts +0 -5
  65. package/dist/cjs/store/sqlite/vectors.js +5 -71
  66. package/dist/cjs/store/sqlite/vectors.js.map +1 -1
  67. package/dist/cjs/store/turso/connection.d.cts +3 -0
  68. package/dist/cjs/store/turso/connection.d.ts +3 -0
  69. package/dist/cjs/store/turso/connection.js +529 -0
  70. package/dist/cjs/store/turso/connection.js.map +1 -0
  71. package/dist/cjs/store/turso/fieldStats.d.cts +2 -0
  72. package/dist/cjs/store/turso/fieldStats.d.ts +2 -0
  73. package/dist/cjs/store/turso/fieldStats.js +201 -0
  74. package/dist/cjs/store/turso/fieldStats.js.map +1 -0
  75. package/dist/cjs/store/turso/native.d.cts +2 -0
  76. package/dist/cjs/store/turso/native.d.ts +2 -0
  77. package/dist/cjs/store/turso/native.js +31 -0
  78. package/dist/cjs/store/turso/native.js.map +1 -0
  79. package/dist/cjs/store/turso/open.d.cts +12 -0
  80. package/dist/cjs/store/turso/open.d.ts +12 -0
  81. package/dist/cjs/store/turso/open.js +500 -0
  82. package/dist/cjs/store/turso/open.js.map +1 -0
  83. package/dist/cjs/store/turso/reconcile.d.cts +6 -0
  84. package/dist/cjs/store/turso/reconcile.d.ts +6 -0
  85. package/dist/cjs/store/turso/reconcile.js +793 -0
  86. package/dist/cjs/store/turso/reconcile.js.map +1 -0
  87. package/dist/cjs/store/turso/store.d.cts +5 -0
  88. package/dist/cjs/store/turso/store.d.ts +5 -0
  89. package/dist/cjs/store/turso/store.js +609 -0
  90. package/dist/cjs/store/turso/store.js.map +1 -0
  91. package/dist/cjs/store/types.d.cts +9 -1
  92. package/dist/cjs/store/types.d.ts +9 -1
  93. package/dist/cjs/store/types.js +0 -7
  94. package/dist/cjs/store/types.js.map +1 -1
  95. package/dist/cjs/store/vectors.d.cts +9 -0
  96. package/dist/cjs/store/vectors.d.ts +9 -0
  97. package/dist/cjs/store/vectors.js +215 -0
  98. package/dist/cjs/store/vectors.js.map +1 -0
  99. package/dist/esm/cli/status.js +5 -7
  100. package/dist/esm/cli/status.js.map +1 -1
  101. package/dist/esm/commands/map.js +7 -19
  102. package/dist/esm/commands/map.js.map +1 -1
  103. package/dist/esm/config/access.d.ts +2 -2
  104. package/dist/esm/config/access.js.map +1 -1
  105. package/dist/esm/config/index.d.ts +1 -1
  106. package/dist/esm/config/index.js.map +1 -1
  107. package/dist/esm/config/load.js +4 -3
  108. package/dist/esm/config/load.js.map +1 -1
  109. package/dist/esm/config/types.d.ts +2 -1
  110. package/dist/esm/config/types.js.map +1 -1
  111. package/dist/esm/config/validate.js +3 -0
  112. package/dist/esm/config/validate.js.map +1 -1
  113. package/dist/esm/embed/identity.js +4 -3
  114. package/dist/esm/embed/identity.js.map +1 -1
  115. package/dist/esm/embed/store.js +3 -3
  116. package/dist/esm/embed/store.js.map +1 -1
  117. package/dist/esm/index.d.ts +2 -2
  118. package/dist/esm/index.js.map +1 -1
  119. package/dist/esm/lib/atomic-write.d.ts +1 -0
  120. package/dist/esm/lib/atomic-write.js +17 -0
  121. package/dist/esm/lib/atomic-write.js.map +1 -0
  122. package/dist/esm/store/duckdb/batch.js +3 -2
  123. package/dist/esm/store/duckdb/batch.js.map +1 -1
  124. package/dist/esm/store/duckdb/connection.js +12 -0
  125. package/dist/esm/store/duckdb/connection.js.map +1 -1
  126. package/dist/esm/store/duckdb/fieldStats.d.ts +2 -0
  127. package/dist/esm/store/duckdb/fieldStats.js +39 -0
  128. package/dist/esm/store/duckdb/fieldStats.js.map +1 -0
  129. package/dist/esm/store/duckdb/lexical.js +19 -9
  130. package/dist/esm/store/duckdb/lexical.js.map +1 -1
  131. package/dist/esm/store/duckdb/native.d.ts +0 -1
  132. package/dist/esm/store/duckdb/native.js +7 -84
  133. package/dist/esm/store/duckdb/native.js.map +1 -1
  134. package/dist/esm/store/duckdb/sql-functions.js +1 -1
  135. package/dist/esm/store/duckdb/sql-functions.js.map +1 -1
  136. package/dist/esm/store/duckdb/store.js +8 -5
  137. package/dist/esm/store/duckdb/store.js.map +1 -1
  138. package/dist/esm/store/duckdb/vectors.js +2 -12
  139. package/dist/esm/store/duckdb/vectors.js.map +1 -1
  140. package/dist/esm/store/index.js +6 -0
  141. package/dist/esm/store/index.js.map +1 -1
  142. package/dist/esm/store/native.d.ts +7 -0
  143. package/dist/esm/store/native.js +83 -0
  144. package/dist/esm/store/native.js.map +1 -0
  145. package/dist/esm/store/sqlite/fieldStats.d.ts +2 -0
  146. package/dist/esm/store/sqlite/fieldStats.js +25 -0
  147. package/dist/esm/store/sqlite/fieldStats.js.map +1 -0
  148. package/dist/esm/store/sqlite/open.js +21 -8
  149. package/dist/esm/store/sqlite/open.js.map +1 -1
  150. package/dist/esm/store/sqlite/store.js +14 -1
  151. package/dist/esm/store/sqlite/store.js.map +1 -1
  152. package/dist/esm/store/sqlite/vectors.d.ts +0 -5
  153. package/dist/esm/store/sqlite/vectors.js +2 -22
  154. package/dist/esm/store/sqlite/vectors.js.map +1 -1
  155. package/dist/esm/store/turso/connection.d.ts +3 -0
  156. package/dist/esm/store/turso/connection.js +52 -0
  157. package/dist/esm/store/turso/connection.js.map +1 -0
  158. package/dist/esm/store/turso/fieldStats.d.ts +2 -0
  159. package/dist/esm/store/turso/fieldStats.js +24 -0
  160. package/dist/esm/store/turso/fieldStats.js.map +1 -0
  161. package/dist/esm/store/turso/native.d.ts +2 -0
  162. package/dist/esm/store/turso/native.js +19 -0
  163. package/dist/esm/store/turso/native.js.map +1 -0
  164. package/dist/esm/store/turso/open.d.ts +12 -0
  165. package/dist/esm/store/turso/open.js +113 -0
  166. package/dist/esm/store/turso/open.js.map +1 -0
  167. package/dist/esm/store/turso/reconcile.d.ts +6 -0
  168. package/dist/esm/store/turso/reconcile.js +158 -0
  169. package/dist/esm/store/turso/reconcile.js.map +1 -0
  170. package/dist/esm/store/turso/store.d.ts +5 -0
  171. package/dist/esm/store/turso/store.js +93 -0
  172. package/dist/esm/store/turso/store.js.map +1 -0
  173. package/dist/esm/store/types.d.ts +9 -1
  174. package/dist/esm/store/types.js +0 -7
  175. package/dist/esm/store/types.js.map +1 -1
  176. package/dist/esm/store/vectors.d.ts +9 -0
  177. package/dist/esm/store/vectors.js +26 -0
  178. package/dist/esm/store/vectors.js.map +1 -0
  179. package/package.json +2 -1
@@ -14,347 +14,18 @@ _export(exports, {
14
14
  },
15
15
  get duckdbApi () {
16
16
  return duckdbApi;
17
- },
18
- get loadOrInstall () {
19
- return loadOrInstall;
20
17
  }
21
18
  });
22
- var _nodefs = require("node:fs");
23
- var _nodemodule = /*#__PURE__*/ _interop_require_default(require("node:module"));
24
- var _nodepath = require("node:path");
25
- var _nodeurl = require("node:url");
26
- var _errorsts = require("../../errors.js");
27
- function _array_like_to_array(arr, len) {
28
- if (len == null || len > arr.length) len = arr.length;
29
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
30
- return arr2;
31
- }
32
- function _array_without_holes(arr) {
33
- if (Array.isArray(arr)) return _array_like_to_array(arr);
34
- }
35
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
36
- try {
37
- var info = gen[key](arg);
38
- var value = info.value;
39
- } catch (error) {
40
- reject(error);
41
- return;
42
- }
43
- if (info.done) resolve(value);
44
- else Promise.resolve(value).then(_next, _throw);
45
- }
46
- function _async_to_generator(fn) {
47
- return function() {
48
- var self = this, args = arguments;
49
- return new Promise(function(resolve, reject) {
50
- var gen = fn.apply(self, args);
51
- function _next(value) {
52
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
53
- }
54
- function _throw(err) {
55
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
56
- }
57
- _next(undefined);
58
- });
59
- };
60
- }
61
- function _interop_require_default(obj) {
62
- return obj && obj.__esModule ? obj : {
63
- default: obj
64
- };
65
- }
66
- function _getRequireWildcardCache(nodeInterop) {
67
- if (typeof WeakMap !== "function") return null;
68
- var cacheBabelInterop = new WeakMap();
69
- var cacheNodeInterop = new WeakMap();
70
- return (_getRequireWildcardCache = function(nodeInterop) {
71
- return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
72
- })(nodeInterop);
73
- }
74
- function _interop_require_wildcard(obj, nodeInterop) {
75
- if (!nodeInterop && obj && obj.__esModule) return obj;
76
- if (obj === null || typeof obj !== "object" && typeof obj !== "function") return {
77
- default: obj
78
- };
79
- var cache = _getRequireWildcardCache(nodeInterop);
80
- if (cache && cache.has(obj)) return cache.get(obj);
81
- var newObj = {
82
- __proto__: null
83
- };
84
- var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
85
- for(var key in obj){
86
- if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
87
- var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
88
- if (desc && (desc.get || desc.set)) Object.defineProperty(newObj, key, desc);
89
- else newObj[key] = obj[key];
90
- }
91
- }
92
- newObj.default = obj;
93
- if (cache) cache.set(obj, newObj);
94
- return newObj;
95
- }
96
- function _iterable_to_array(iter) {
97
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) {
98
- return Array.from(iter);
99
- }
100
- }
101
- function _non_iterable_spread() {
102
- throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
103
- }
104
- function _to_consumable_array(arr) {
105
- return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
106
- }
107
- function _ts_generator(thisArg, body) {
108
- var f, y, t, _ = {
109
- label: 0,
110
- sent: function() {
111
- if (t[0] & 1) throw t[1];
112
- return t[1];
113
- },
114
- trys: [],
115
- ops: []
116
- }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
117
- return d(g, "next", {
118
- value: verb(0)
119
- }), d(g, "throw", {
120
- value: verb(1)
121
- }), d(g, "return", {
122
- value: verb(2)
123
- }), typeof Symbol === "function" && d(g, Symbol.iterator, {
124
- value: function() {
125
- return this;
126
- }
127
- }), g;
128
- function verb(n) {
129
- return function(v) {
130
- return step([
131
- n,
132
- v
133
- ]);
134
- };
135
- }
136
- function step(op) {
137
- if (f) throw new TypeError("Generator is already executing.");
138
- while(g && (g = 0, op[0] && (_ = 0)), _)try {
139
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
140
- if (y = 0, t) op = [
141
- op[0] & 2,
142
- t.value
143
- ];
144
- switch(op[0]){
145
- case 0:
146
- case 1:
147
- t = op;
148
- break;
149
- case 4:
150
- _.label++;
151
- return {
152
- value: op[1],
153
- done: false
154
- };
155
- case 5:
156
- _.label++;
157
- y = op[1];
158
- op = [
159
- 0
160
- ];
161
- continue;
162
- case 7:
163
- op = _.ops.pop();
164
- _.trys.pop();
165
- continue;
166
- default:
167
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
168
- _ = 0;
169
- continue;
170
- }
171
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
172
- _.label = op[1];
173
- break;
174
- }
175
- if (op[0] === 6 && _.label < t[1]) {
176
- _.label = t[1];
177
- t = op;
178
- break;
179
- }
180
- if (t && _.label < t[2]) {
181
- _.label = t[2];
182
- _.ops.push(op);
183
- break;
184
- }
185
- if (t[2]) _.ops.pop();
186
- _.trys.pop();
187
- continue;
188
- }
189
- op = body.call(thisArg, _);
190
- } catch (e) {
191
- op = [
192
- 6,
193
- e
194
- ];
195
- y = 0;
196
- } finally{
197
- f = t = 0;
198
- }
199
- if (op[0] & 5) throw op[1];
200
- return {
201
- value: op[0] ? op[1] : void 0,
202
- done: true
203
- };
204
- }
205
- }
206
- function _unsupported_iterable_to_array(o, minLen) {
207
- if (!o) return;
208
- if (typeof o === "string") return _array_like_to_array(o, minLen);
209
- var n = Object.prototype.toString.call(o).slice(8, -1);
210
- if (n === "Object" && o.constructor) n = o.constructor.name;
211
- if (n === "Map" || n === "Set") return Array.from(n);
212
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
213
- }
19
+ var _nativets = require("../native.js");
214
20
  var DUCKDB_PACKAGE = '@duckdb/node-api';
215
- // install-module-linked itself is small, but its target (@duckdb/node-api) is not: deferred the
216
- // same way embed/static.ts defers @huggingface/tokenizers, so requiring it stays inside the
217
- // already-gated branch below rather than running for every store/index.ts load.
218
- var _require = typeof require === 'undefined' ? _nodemodule.default.createRequire(require("url").pathToFileURL(__filename).toString()) : require;
219
- var _dirname = (0, _nodepath.dirname)(typeof __filename !== 'undefined' ? __filename : (0, _nodeurl.fileURLToPath)(require("url").pathToFileURL(__filename).toString()));
220
- // Walks up from this file's own directory to find the real package.json, rather than a fixed
221
- // dot-count from __dirname (xz-compat's `../../node_modules`): `tsds test:node` runs straight
222
- // off src/, one directory shallower than dist/{cjs,esm}/store/duckdb sits under the built
223
- // package, so a hardcoded depth is right for one and wrong for the other. Works the same way
224
- // for a globally-installed `sense`, whose node_modules this resolves to -- never the caller's
225
- // cwd.
226
- function packageNodeModules() {
227
- var dir = _dirname;
228
- for(;;){
229
- var candidate = (0, _nodepath.join)(dir, 'package.json');
230
- if ((0, _nodefs.existsSync)(candidate)) {
231
- var pkg = JSON.parse((0, _nodefs.readFileSync)(candidate, 'utf8'));
232
- if (pkg.name === 'sensemaking') return (0, _nodepath.join)(dir, 'node_modules');
233
- }
234
- var parent = (0, _nodepath.dirname)(dir);
235
- if (parent === dir) throw new Error('could not locate the sensemaking package root to install @duckdb/node-api into');
236
- dir = parent;
237
- }
238
- }
239
- var installing = new Map();
240
- // De-dupes concurrent installs within this process (see spawn-term's loadInk for the shape).
241
- // The install here is async -- the load site already awaits a dynamic import -- so a bare
242
- // attempted flag (xz-compat's `installationAttempted`, enough for its synchronous single-target
243
- // install) isn't enough on its own; concurrent callers instead await the same in-flight promise,
244
- // keyed by specifier and target so tests exercising several installs in one process don't share
245
- // one slot. A failed install is not cached, so a later call retries.
246
- function installOnce(specifier, nodeModulesPath) {
247
- var key = "".concat(specifier, "\n").concat(nodeModulesPath);
248
- var promise = installing.get(key);
249
- if (!promise) {
250
- var installModuleLinked = _require('install-module-linked').default;
251
- promise = installModuleLinked(specifier, nodeModulesPath).then(function() {}, function(err) {
252
- installing.delete(key);
253
- throw err;
254
- });
255
- installing.set(key, promise);
256
- }
257
- return promise;
258
- }
259
- // Node caches a bare specifier's package resolution -- including a "not found" miss -- for the
260
- // life of the process, so retrying `import(importName)` right after installing sees the same
261
- // stale miss and falls through to a bogus index.js guess instead of the package's real entry
262
- // (verified against a real global install: the plain-specifier retry failed there, this did
263
- // not). Reading the freshly-installed package's own package.json and importing its entry file
264
- // by an absolute file: URL sidesteps that stale cache instead of re-resolving the bare name.
265
- function resolveEntryUrl(importName, nodeModulesPath) {
266
- var _pkg_main;
267
- var pkgDir = _nodepath.join.apply(void 0, [
268
- nodeModulesPath
269
- ].concat(_to_consumable_array(importName.split('/'))));
270
- var pkg = JSON.parse((0, _nodefs.readFileSync)((0, _nodepath.join)(pkgDir, 'package.json'), 'utf8'));
271
- var entry = typeof pkg.exports === 'string' ? pkg.exports : (_pkg_main = pkg.main) !== null && _pkg_main !== void 0 ? _pkg_main : 'index.js';
272
- return (0, _nodeurl.pathToFileURL)((0, _nodepath.join)(pkgDir, entry)).href;
273
- }
274
- function loadOrInstall(importName, nodeModulesPath) {
275
- return _async_to_generator(function() {
276
- var unused, installErr, loadErr;
277
- return _ts_generator(this, function(_state) {
278
- switch(_state.label){
279
- case 0:
280
- _state.trys.push([
281
- 0,
282
- 2,
283
- ,
284
- 10
285
- ]);
286
- return [
287
- 4,
288
- Promise.resolve(importName).then(function(p) {
289
- return /*#__PURE__*/ _interop_require_wildcard(require(p));
290
- })
291
- ];
292
- case 1:
293
- return [
294
- 2,
295
- _state.sent()
296
- ];
297
- case 2:
298
- unused = _state.sent();
299
- console.error('sense: store "duckdb" needs '.concat(DUCKDB_PACKAGE, "; installing it now (one-time download, ~110MB)..."));
300
- _state.label = 3;
301
- case 3:
302
- _state.trys.push([
303
- 3,
304
- 5,
305
- ,
306
- 6
307
- ]);
308
- return [
309
- 4,
310
- installOnce(importName, nodeModulesPath)
311
- ];
312
- case 4:
313
- _state.sent();
314
- return [
315
- 3,
316
- 6
317
- ];
318
- case 5:
319
- installErr = _state.sent();
320
- throw new _errorsts.SenseError('STORE_DEPENDENCY_MISSING', 'store "duckdb" needs '.concat(DUCKDB_PACKAGE, ", and installing it automatically failed (").concat(installErr.message, "); this can happen offline, in a sandboxed environment, or when node_modules is read-only or owned by another user (e.g. under a global install) -- run `npm install ").concat(DUCKDB_PACKAGE, "` yourself and try again"));
321
- case 6:
322
- _state.trys.push([
323
- 6,
324
- 8,
325
- ,
326
- 9
327
- ]);
328
- return [
329
- 4,
330
- Promise.resolve(resolveEntryUrl(importName, nodeModulesPath)).then(function(p) {
331
- return /*#__PURE__*/ _interop_require_wildcard(require(p));
332
- })
333
- ];
334
- case 7:
335
- return [
336
- 2,
337
- _state.sent()
338
- ];
339
- case 8:
340
- loadErr = _state.sent();
341
- throw new _errorsts.SenseError('STORE_DEPENDENCY_MISSING', 'store "duckdb" installed '.concat(DUCKDB_PACKAGE, " but it could not be loaded (").concat(loadErr.message, "); it may not be available for this platform (").concat(process.platform, "-").concat(process.arch, ") -- run `npm install ").concat(DUCKDB_PACKAGE, "` to see the underlying error"));
342
- case 9:
343
- return [
344
- 3,
345
- 10
346
- ];
347
- case 10:
348
- return [
349
- 2
350
- ];
351
- }
352
- });
353
- })();
354
- }
21
+ var DUCKDB = {
22
+ store: 'duckdb',
23
+ pkg: DUCKDB_PACKAGE,
24
+ sizeHint: '~110MB'
25
+ };
355
26
  var duckdbApiPromise;
356
27
  function duckdbApi() {
357
- if (!duckdbApiPromise) duckdbApiPromise = loadOrInstall(DUCKDB_PACKAGE, packageNodeModules());
28
+ if (!duckdbApiPromise) duckdbApiPromise = (0, _nativets.loadOrInstall)(DUCKDB, (0, _nativets.packageNodeModules)());
358
29
  return duckdbApiPromise;
359
30
  }
360
31
  /* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/store/duckdb/native.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\nimport Module from 'node:module';\nimport { dirname, join } from 'node:path';\nimport { fileURLToPath, pathToFileURL } from 'node:url';\nimport { SenseError } from '../../errors.ts';\n\nexport const DUCKDB_PACKAGE = '@duckdb/node-api';\n\n// install-module-linked itself is small, but its target (@duckdb/node-api) is not: deferred the\n// same way embed/static.ts defers @huggingface/tokenizers, so requiring it stays inside the\n// already-gated branch below rather than running for every store/index.ts load.\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst _dirname = dirname(typeof __filename !== 'undefined' ? __filename : fileURLToPath(import.meta.url));\n\n// Walks up from this file's own directory to find the real package.json, rather than a fixed\n// dot-count from __dirname (xz-compat's `../../node_modules`): `tsds test:node` runs straight\n// off src/, one directory shallower than dist/{cjs,esm}/store/duckdb sits under the built\n// package, so a hardcoded depth is right for one and wrong for the other. Works the same way\n// for a globally-installed `sense`, whose node_modules this resolves to -- never the caller's\n// cwd.\nfunction packageNodeModules(): string {\n let dir = _dirname;\n for (;;) {\n const candidate = join(dir, 'package.json');\n if (existsSync(candidate)) {\n const pkg = JSON.parse(readFileSync(candidate, 'utf8')) as { name?: string };\n if (pkg.name === 'sensemaking') return join(dir, 'node_modules');\n }\n const parent = dirname(dir);\n if (parent === dir) throw new Error('could not locate the sensemaking package root to install @duckdb/node-api into');\n dir = parent;\n }\n}\n\nconst installing = new Map<string, Promise<void>>();\n\n// De-dupes concurrent installs within this process (see spawn-term's loadInk for the shape).\n// The install here is async -- the load site already awaits a dynamic import -- so a bare\n// attempted flag (xz-compat's `installationAttempted`, enough for its synchronous single-target\n// install) isn't enough on its own; concurrent callers instead await the same in-flight promise,\n// keyed by specifier and target so tests exercising several installs in one process don't share\n// one slot. A failed install is not cached, so a later call retries.\nfunction installOnce(specifier: string, nodeModulesPath: string): Promise<void> {\n const key = `${specifier}\\n${nodeModulesPath}`;\n let promise = installing.get(key);\n if (!promise) {\n const installModuleLinked = (_require('install-module-linked') as { default: (specifier: string, nodeModulesPath: string) => Promise<string> }).default;\n promise = installModuleLinked(specifier, nodeModulesPath).then(\n () => {},\n (err) => {\n installing.delete(key);\n throw err;\n }\n );\n installing.set(key, promise);\n }\n return promise;\n}\n\n// Node caches a bare specifier's package resolution -- including a \"not found\" miss -- for the\n// life of the process, so retrying `import(importName)` right after installing sees the same\n// stale miss and falls through to a bogus index.js guess instead of the package's real entry\n// (verified against a real global install: the plain-specifier retry failed there, this did\n// not). Reading the freshly-installed package's own package.json and importing its entry file\n// by an absolute file: URL sidesteps that stale cache instead of re-resolving the bare name.\nfunction resolveEntryUrl(importName: string, nodeModulesPath: string): string {\n const pkgDir = join(nodeModulesPath, ...importName.split('/'));\n const pkg = JSON.parse(readFileSync(join(pkgDir, 'package.json'), 'utf8')) as { main?: string; exports?: string };\n const entry = typeof pkg.exports === 'string' ? pkg.exports : (pkg.main ?? 'index.js');\n return pathToFileURL(join(pkgDir, entry)).href;\n}\n\n// Import-then-install-then-retry, over an injectable target so the failure path (import AND\n// install both fail) can be exercised for real in tests without downloading @duckdb/node-api's\n// real ~110MB native binding. Production always passes @duckdb/node-api's own name; the thrown\n// error names @duckdb/node-api regardless, since that is what a real user needs to install.\nexport async function loadOrInstall<T>(importName: string, nodeModulesPath: string): Promise<T> {\n try {\n return (await import(importName)) as T;\n } catch {\n console.error(`sense: store \"duckdb\" needs ${DUCKDB_PACKAGE}; installing it now (one-time download, ~110MB)...`);\n try {\n await installOnce(importName, nodeModulesPath);\n } catch (installErr) {\n throw new SenseError(\n 'STORE_DEPENDENCY_MISSING',\n `store \"duckdb\" needs ${DUCKDB_PACKAGE}, and installing it automatically failed (${(installErr as Error).message}); this can happen offline, in a sandboxed environment, or when node_modules is read-only or owned by another user (e.g. under a global install) -- run \\`npm install ${DUCKDB_PACKAGE}\\` yourself and try again`\n );\n }\n try {\n return (await import(resolveEntryUrl(importName, nodeModulesPath))) as T;\n } catch (loadErr) {\n throw new SenseError('STORE_DEPENDENCY_MISSING', `store \"duckdb\" installed ${DUCKDB_PACKAGE} but it could not be loaded (${(loadErr as Error).message}); it may not be available for this platform (${process.platform}-${process.arch}) -- run \\`npm install ${DUCKDB_PACKAGE}\\` to see the underlying error`);\n }\n }\n}\n\nlet duckdbApiPromise: Promise<typeof import('@duckdb/node-api')> | undefined;\n\n// The one accessor every consumer of @duckdb/node-api (open.ts, sql-functions.ts, vectors.ts)\n// must go through, rather than each doing its own `import('@duckdb/node-api')`: once a fresh\n// install has happened in this process, Node keeps returning that pre-install \"not found\" miss\n// to any NEW bare-specifier lookup of the same path, so a second independent import elsewhere\n// in the process fails even though the package is now genuinely on disk (the same stale-cache\n// problem loadOrInstall works around for its own retry). Caching the resolved module here means\n// only the first caller ever resolves the bare specifier at all.\nexport function duckdbApi(): Promise<typeof import('@duckdb/node-api')> {\n if (!duckdbApiPromise) duckdbApiPromise = loadOrInstall<typeof import('@duckdb/node-api')>(DUCKDB_PACKAGE, packageNodeModules());\n return duckdbApiPromise;\n}\n"],"names":["DUCKDB_PACKAGE","duckdbApi","loadOrInstall","_require","require","Module","createRequire","_dirname","dirname","__filename","fileURLToPath","packageNodeModules","dir","candidate","join","existsSync","pkg","JSON","parse","readFileSync","name","parent","Error","installing","Map","installOnce","specifier","nodeModulesPath","key","promise","get","installModuleLinked","default","then","err","delete","set","resolveEntryUrl","importName","pkgDir","split","entry","exports","main","pathToFileURL","href","installErr","loadErr","console","error","SenseError","message","process","platform","arch","duckdbApiPromise"],"mappings":";;;;;;;;;;;QAMaA;eAAAA;;QAoGGC;eAAAA;;QA9BMC;eAAAA;;;sBA5EmB;iEACtB;wBACW;uBACe;wBAClB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AoEC,OAApBA,QAAQC,QAAQ,EAAC,KAAyCrD,OAAtCoD,QAAQE,IAAI,EAAC,0BAAwC,OAAftD,gBAAe;;;;;;;;;;;;IAGrR;;AAEA,IAAIuD;AASG,SAAStD;IACd,IAAI,CAACsD,kBAAkBA,mBAAmBrD,cAAiDF,gBAAgBW;IAC3G,OAAO4C;AACT"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/store/duckdb/native.ts"],"sourcesContent":["import { loadOrInstall, type NativeDescriptor, packageNodeModules } from '../native.ts';\n\nexport const DUCKDB_PACKAGE = '@duckdb/node-api';\n\nconst DUCKDB: NativeDescriptor = { store: 'duckdb', pkg: DUCKDB_PACKAGE, sizeHint: '~110MB' };\n\nlet duckdbApiPromise: Promise<typeof import('@duckdb/node-api')> | undefined;\n\n// The one accessor every consumer of @duckdb/node-api (open.ts, sql-functions.ts, vectors.ts)\n// must go through, rather than each doing its own `import('@duckdb/node-api')`: once a fresh\n// install has happened in this process, Node keeps returning that pre-install \"not found\" miss\n// to any NEW bare-specifier lookup of the same path, so a second independent import elsewhere\n// in the process fails even though the package is now genuinely on disk (the same stale-cache\n// problem loadOrInstall works around for its own retry). Caching the resolved module here means\n// only the first caller ever resolves the bare specifier at all.\nexport function duckdbApi(): Promise<typeof import('@duckdb/node-api')> {\n if (!duckdbApiPromise) duckdbApiPromise = loadOrInstall<typeof import('@duckdb/node-api')>(DUCKDB, packageNodeModules());\n return duckdbApiPromise;\n}\n"],"names":["DUCKDB_PACKAGE","duckdbApi","DUCKDB","store","pkg","sizeHint","duckdbApiPromise","loadOrInstall","packageNodeModules"],"mappings":";;;;;;;;;;;QAEaA;eAAAA;;QAaGC;eAAAA;;;wBAfyD;AAElE,IAAMD,iBAAiB;AAE9B,IAAME,SAA2B;IAAEC,OAAO;IAAUC,KAAKJ;IAAgBK,UAAU;AAAS;AAE5F,IAAIC;AASG,SAASL;IACd,IAAI,CAACK,kBAAkBA,mBAAmBC,IAAAA,uBAAa,EAAoCL,QAAQM,IAAAA,4BAAkB;IACrH,OAAOF;AACT"}
@@ -179,7 +179,7 @@ function registerFunctions(conn) {
179
179
  // segment() rewrites unspaced-script runs into the grapheme phrase FTS5's `_seg` sidecars
180
180
  // need (see src/text/segment.ts); this store's own lexical index uses contains() instead (D1)
181
181
  // and never calls this, but hand-written raw SQL naming it still gets the real implementation
182
- // rather than a silent passthrough (principle 6).
182
+ // rather than a silent passthrough (PRINCIPLES: no-silent-modes).
183
183
  conn.registerScalarFunction(DuckDBScalarFunction.create({
184
184
  name: 'segment',
185
185
  parameterTypes: [
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/store/duckdb/sql-functions.ts"],"sourcesContent":["import type { DuckDBConnection } from '@duckdb/node-api';\nimport { segmentMatch } from '../../text/segment.ts';\nimport { basenameImpl, hasImpl } from '../sql-functions.ts';\nimport { duckdbApi } from './native.ts';\n\n// Dynamic, not a top-level import: sqlite trees must never even attempt to resolve this optional\n// peer dependency (see open.ts's connect()). Goes through native.ts's shared duckdbApi(), not a\n// bare `import('@duckdb/node-api')` of its own -- by the time this runs, open.ts has already\n// resolved the package, possibly via an on-demand install, and a second independent bare-specifier\n// lookup in the same process would hit Node's stale pre-install resolution miss (see native.ts).\nexport async function registerFunctions(conn: DuckDBConnection): Promise<void> {\n const { DuckDBIntegerType, DuckDBScalarFunction, DuckDBVarCharType } = await duckdbApi();\n conn.registerScalarFunction(\n DuckDBScalarFunction.create({\n name: 'has',\n parameterTypes: [DuckDBVarCharType.instance, DuckDBVarCharType.instance],\n returnType: DuckDBIntegerType.instance,\n mainFunction(_info, inputChunk, outputVector) {\n const fieldVec = inputChunk.getColumnVector(0);\n const valueVec = inputChunk.getColumnVector(1);\n for (let i = 0; i < inputChunk.rowCount; i++) outputVector.setItem(i, hasImpl(fieldVec.getItem(i), valueVec.getItem(i)));\n outputVector.flush();\n },\n })\n );\n conn.registerScalarFunction(\n DuckDBScalarFunction.create({\n name: 'basename',\n parameterTypes: [DuckDBVarCharType.instance],\n varArgsType: DuckDBVarCharType.instance,\n returnType: DuckDBVarCharType.instance,\n mainFunction(_info, inputChunk, outputVector) {\n const pathVec = inputChunk.getColumnVector(0);\n const suffixVec = inputChunk.columnCount > 1 ? inputChunk.getColumnVector(1) : null;\n for (let i = 0; i < inputChunk.rowCount; i++) outputVector.setItem(i, basenameImpl(pathVec.getItem(i), suffixVec ? suffixVec.getItem(i) : undefined));\n outputVector.flush();\n },\n })\n );\n // segment() rewrites unspaced-script runs into the grapheme phrase FTS5's `_seg` sidecars\n // need (see src/text/segment.ts); this store's own lexical index uses contains() instead (D1)\n // and never calls this, but hand-written raw SQL naming it still gets the real implementation\n // rather than a silent passthrough (principle 6).\n conn.registerScalarFunction(\n DuckDBScalarFunction.create({\n name: 'segment',\n parameterTypes: [DuckDBVarCharType.instance],\n returnType: DuckDBVarCharType.instance,\n mainFunction(_info, inputChunk, outputVector) {\n const textVec = inputChunk.getColumnVector(0);\n for (let i = 0; i < inputChunk.rowCount; i++) outputVector.setItem(i, segmentMatch(String(textVec.getItem(i) ?? '')));\n outputVector.flush();\n },\n })\n );\n}\n"],"names":["registerFunctions","conn","DuckDBIntegerType","DuckDBScalarFunction","DuckDBVarCharType","duckdbApi","registerScalarFunction","create","name","parameterTypes","instance","returnType","mainFunction","_info","inputChunk","outputVector","fieldVec","getColumnVector","valueVec","i","rowCount","setItem","hasImpl","getItem","flush","varArgsType","pathVec","suffixVec","columnCount","basenameImpl","undefined","textVec","segmentMatch","String"],"mappings":";;;;+BAUsBA;;;eAAAA;;;yBATO;8BACS;wBACZ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOnB,SAAeA,kBAAkBC,IAAsB;;YACW,MAA/DC,mBAAmBC,sBAAsBC;;;;oBA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F,8FAA8F;oBAC9F,8FAA8F;oBAC9F,kDAAkD;oBAClDvB,KAAKK,sBAAsB,CACzBH,qBAAqBI,MAAM,CAAC;wBAC1BC,MAAM;wBACNC,cAAc;4BAAGL,kBAAkBM,QAAQ;;wBAC3CC,YAAYP,kBAAkBM,QAAQ;wBACtCE,cAAAA,SAAAA,aAAaC,KAAK,EAAEC,UAAU,EAAEC,YAAY;gCAEgDgB;4BAD1F,IAAMA,UAAUjB,WAAWG,eAAe,CAAC;4BAC3C,IAAK,IAAIE,IAAI,GAAGA,IAAIL,WAAWM,QAAQ,EAAED,IAAKJ,aAAaM,OAAO,CAACF,GAAGa,IAAAA,uBAAY,EAACC,QAAOF,mBAAAA,QAAQR,OAAO,CAACJ,gBAAhBY,8BAAAA,mBAAsB;4BAChHhB,aAAaS,KAAK;wBACpB;oBACF;;;;;;IAEJ"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/store/duckdb/sql-functions.ts"],"sourcesContent":["import type { DuckDBConnection } from '@duckdb/node-api';\nimport { segmentMatch } from '../../text/segment.ts';\nimport { basenameImpl, hasImpl } from '../sql-functions.ts';\nimport { duckdbApi } from './native.ts';\n\n// Dynamic, not a top-level import: sqlite trees must never even attempt to resolve this optional\n// peer dependency (see open.ts's connect()). Goes through native.ts's shared duckdbApi(), not a\n// bare `import('@duckdb/node-api')` of its own -- by the time this runs, open.ts has already\n// resolved the package, possibly via an on-demand install, and a second independent bare-specifier\n// lookup in the same process would hit Node's stale pre-install resolution miss (see native.ts).\nexport async function registerFunctions(conn: DuckDBConnection): Promise<void> {\n const { DuckDBIntegerType, DuckDBScalarFunction, DuckDBVarCharType } = await duckdbApi();\n conn.registerScalarFunction(\n DuckDBScalarFunction.create({\n name: 'has',\n parameterTypes: [DuckDBVarCharType.instance, DuckDBVarCharType.instance],\n returnType: DuckDBIntegerType.instance,\n mainFunction(_info, inputChunk, outputVector) {\n const fieldVec = inputChunk.getColumnVector(0);\n const valueVec = inputChunk.getColumnVector(1);\n for (let i = 0; i < inputChunk.rowCount; i++) outputVector.setItem(i, hasImpl(fieldVec.getItem(i), valueVec.getItem(i)));\n outputVector.flush();\n },\n })\n );\n conn.registerScalarFunction(\n DuckDBScalarFunction.create({\n name: 'basename',\n parameterTypes: [DuckDBVarCharType.instance],\n varArgsType: DuckDBVarCharType.instance,\n returnType: DuckDBVarCharType.instance,\n mainFunction(_info, inputChunk, outputVector) {\n const pathVec = inputChunk.getColumnVector(0);\n const suffixVec = inputChunk.columnCount > 1 ? inputChunk.getColumnVector(1) : null;\n for (let i = 0; i < inputChunk.rowCount; i++) outputVector.setItem(i, basenameImpl(pathVec.getItem(i), suffixVec ? suffixVec.getItem(i) : undefined));\n outputVector.flush();\n },\n })\n );\n // segment() rewrites unspaced-script runs into the grapheme phrase FTS5's `_seg` sidecars\n // need (see src/text/segment.ts); this store's own lexical index uses contains() instead (D1)\n // and never calls this, but hand-written raw SQL naming it still gets the real implementation\n // rather than a silent passthrough (PRINCIPLES: no-silent-modes).\n conn.registerScalarFunction(\n DuckDBScalarFunction.create({\n name: 'segment',\n parameterTypes: [DuckDBVarCharType.instance],\n returnType: DuckDBVarCharType.instance,\n mainFunction(_info, inputChunk, outputVector) {\n const textVec = inputChunk.getColumnVector(0);\n for (let i = 0; i < inputChunk.rowCount; i++) outputVector.setItem(i, segmentMatch(String(textVec.getItem(i) ?? '')));\n outputVector.flush();\n },\n })\n );\n}\n"],"names":["registerFunctions","conn","DuckDBIntegerType","DuckDBScalarFunction","DuckDBVarCharType","duckdbApi","registerScalarFunction","create","name","parameterTypes","instance","returnType","mainFunction","_info","inputChunk","outputVector","fieldVec","getColumnVector","valueVec","i","rowCount","setItem","hasImpl","getItem","flush","varArgsType","pathVec","suffixVec","columnCount","basenameImpl","undefined","textVec","segmentMatch","String"],"mappings":";;;;+BAUsBA;;;eAAAA;;;yBATO;8BACS;wBACZ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAaM,OAAO,CAACF,GAAGU,IAAAA,4BAAY,EAACH,QAAQH,OAAO,CAACJ,IAAIQ,YAAYA,UAAUJ,OAAO,CAACJ,KAAKW;4BAC1If,aAAaS,KAAK;wBACpB;oBACF;oBAEF,0FAA0F;oBAC1F,8FAA8F;oBAC9F,8FAA8F;oBAC9F,kEAAkE;oBAClEvB,KAAKK,sBAAsB,CACzBH,qBAAqBI,MAAM,CAAC;wBAC1BC,MAAM;wBACNC,cAAc;4BAAGL,kBAAkBM,QAAQ;;wBAC3CC,YAAYP,kBAAkBM,QAAQ;wBACtCE,cAAAA,SAAAA,aAAaC,KAAK,EAAEC,UAAU,EAAEC,YAAY;gCAEgDgB;4BAD1F,IAAMA,UAAUjB,WAAWG,eAAe,CAAC;4BAC3C,IAAK,IAAIE,IAAI,GAAGA,IAAIL,WAAWM,QAAQ,EAAED,IAAKJ,aAAaM,OAAO,CAACF,GAAGa,IAAAA,uBAAY,EAACC,QAAOF,mBAAAA,QAAQR,OAAO,CAACJ,gBAAhBY,8BAAAA,mBAAsB;4BAChHhB,aAAaS,KAAK;wBACpB;oBACF;;;;;;IAEJ"}
@@ -18,9 +18,10 @@ _export(exports, {
18
18
  });
19
19
  var _typests = require("../../embed/types.js");
20
20
  var _sharedts = require("../shared.js");
21
- var _vectorsts = require("../sqlite/vectors.js");
22
21
  var _transactionts = require("../transaction.js");
22
+ var _vectorsts = require("../vectors.js");
23
23
  var _connectionts = require("./connection.js");
24
+ var _fieldStatsts = require("./fieldStats.js");
24
25
  var _lexicalts = require("./lexical.js");
25
26
  var _reconcilets = require("./reconcile.js");
26
27
  var _vectorsts1 = require("./vectors.js");
@@ -371,6 +372,9 @@ function createStore(instance, duckdb, conn, cfg, baseDir) {
371
372
  }
372
373
  });
373
374
  })();
375
+ },
376
+ fieldStats: function fieldStats(columns, scopeWhere) {
377
+ return (0, _fieldStatsts.fieldStats)(conn, columns, scopeWhere);
374
378
  }
375
379
  },
376
380
  lexical: {
@@ -396,6 +400,17 @@ function createStore(instance, duckdb, conn, cfg, baseDir) {
396
400
  return (0, _vectorsts.hasVectorRow)(conn, path);
397
401
  }
398
402
  },
403
+ engineStatus: // No comparable setting to report yet.
404
+ function engineStatus() {
405
+ return _async_to_generator(function() {
406
+ return _ts_generator(this, function(_state) {
407
+ return [
408
+ 2,
409
+ {}
410
+ ];
411
+ });
412
+ })();
413
+ },
399
414
  raw: {
400
415
  prepare: function prepare(sql) {
401
416
  return _async_to_generator(function() {
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/store/duckdb/store.ts"],"sourcesContent":["import type { DuckDBConnection, DuckDBInstance } from '@duckdb/node-api';\nimport type { Config } from '../../config/index.ts';\nimport { STORE_DIMS } from '../../embed/types.ts';\nimport { getColumns } from '../shared.ts';\n// pending()/hasVector() are IS NULL/IS NOT NULL checks the portable Connection already\n// answers identically regardless of the vector column's type, so this store reuses sqlite's\n// (engine-neutral despite the module name) instead of duplicating them.\nimport { hasVectorRow, pendingRows } from '../sqlite/vectors.ts';\nimport { withTransaction } from '../transaction.ts';\nimport type { Capability, Connection, Statement, Store } from '../types.ts';\nimport { storeRowToJs } from './connection.ts';\nimport { createLexicalIndex } from './lexical.ts';\nimport { reconcile } from './reconcile.ts';\nimport { scanCandidates, scanSimilar, writeVectorBatch } from './vectors.ts';\n\n// Portable surface, links/sections/tags/rank, raw sql passthrough, lexical (D1: fts BM25 +\n// contains(), see lexical.ts), and vectors (D2: native FLOAT[N] + array_cosine_similarity, see\n// vectors.ts) are implemented. 'snippets' is declined: no snippet()-equivalent exists, so every\n// lexical hit relies on the caller's JS excerpt fallback (commands/search.ts) rather than a\n// bounded engine-native one. 'phrases' means quoted-phrase matching only (types.ts):\n// prefix/boolean/NEAR/column-filter FTS5 syntax is not claimed here -- lexical.ts rejects it\n// rather than answer it differently.\nexport const CAPABILITIES: ReadonlySet<Capability> = new Set(['lexical', 'phrases', 'vectors']);\n\n// Shares one Connection instance (conn) with open()'s own reconcile call so transaction depth\n// (see transaction.ts) is tracked against the same object everywhere. The instance is the\n// native database handle that owns the WAL: close() must close it, not just disconnect the\n// connection, or DuckDB never checkpoints and the next open reads a mismatched WAL.\nexport function createStore(instance: DuckDBInstance, duckdb: DuckDBConnection, conn: Connection, cfg: Config, baseDir: string): Store {\n const lex = createLexicalIndex(conn);\n return {\n name: 'duckdb',\n capabilities: CAPABILITIES,\n async exec(sql: string): Promise<void> {\n await conn.exec(sql);\n },\n async prepare(sql: string): Promise<Statement> {\n return conn.prepare(sql);\n },\n async runBatch(sql: string, paramRows: unknown[][]): Promise<void> {\n await conn.runBatch(sql, paramRows);\n },\n async transaction<T>(fn: () => Promise<T>): Promise<T> {\n return withTransaction(conn, fn);\n },\n async reconcile() {\n const result = await reconcile(conn, cfg, baseDir);\n // content may have changed; the fts index is rebuilt lazily, on the next lexical query\n // that needs it, not here (see lexical.ts's FtsIndexState).\n lex.markStale();\n return result;\n },\n docs: {\n async columns() {\n return [...(await getColumns(conn))];\n },\n },\n lexical: {\n query: lex.query,\n },\n // The column's fixed DDL width (STORE_DIMS) is what every scan binds against, not the\n // interface's per-call storeDims -- see vectors.ts's padded() for why a shorter vector is\n // still correct against a wider column.\n vectors: {\n pending: () => pendingRows(conn),\n writeVectors: (rows) => writeVectorBatch(duckdb, conn, STORE_DIMS, rows),\n candidates: (qv, _storeDims, fetch, allowed) => scanCandidates(duckdb, qv, STORE_DIMS, fetch, allowed),\n similar: (path, opts) => scanSimilar(duckdb, conn, STORE_DIMS, path, opts),\n hasVector: (path) => hasVectorRow(conn, path),\n },\n raw: {\n async prepare(sql: string) {\n const prepared = await duckdb.prepare(sql);\n return {\n columns: () => {\n const out: Array<{ name: string }> = [];\n for (let i = 0; i < prepared.columnCount; i++) out.push({ name: prepared.columnName(i) });\n return out;\n },\n // Real incremental streaming: DuckDB reads its own result in row-group chunks, so\n // each readUntil only fetches what isn't already in hand.\n iterate: async function* (...params: unknown[]) {\n if (params.length > 0) prepared.bind(params as Parameters<typeof prepared.bind>[0]);\n const reader = await prepared.streamAndRead();\n let yielded = 0;\n do {\n await reader.readUntil(reader.currentRowCount + 2048);\n const rows = reader.getRowObjectsJS() as Array<Record<string, unknown>>;\n for (; yielded < rows.length; yielded++) yield storeRowToJs(rows[yielded]);\n } while (!reader.done);\n },\n };\n },\n },\n async close() {\n // Order matters: the connection must be gone before the instance closes the WAL.\n duckdb.disconnectSync();\n instance.closeSync();\n },\n };\n}\n"],"names":["CAPABILITIES","createStore","Set","instance","duckdb","conn","cfg","baseDir","lex","createLexicalIndex","name","capabilities","exec","sql","prepare","runBatch","paramRows","transaction","fn","withTransaction","reconcile","result","markStale","docs","columns","getColumns","lexical","query","vectors","pending","pendingRows","writeVectors","rows","writeVectorBatch","STORE_DIMS","candidates","qv","_storeDims","fetch","allowed","scanCandidates","similar","path","opts","scanSimilar","hasVector","hasVectorRow","raw","prepared","out","i","columnCount","push","columnName","iterate","params","reader","yielded","length","bind","streamAndRead","readUntil","currentRowCount","getRowObjectsJS","storeRowToJs","done","close","disconnectSync","closeSync"],"mappings":";;;;;;;;;;;QAsBaA;eAAAA;;QAMGC;eAAAA;;;uBA1BW;wBACA;yBAIe;6BACV;4BAEH;yBACM;2BACT;0BACoC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASvD,IAAMD,eAAwC,IAAIE,IAAI;IAAC;IAAW;IAAW;CAAU;AAMvF,SAASD,YAAYE,QAAwB,EAAEC,MAAwB,EAAEC,IAAgB,EAAEC,GAAW,EAAEC,OAAe;IAC5H,IAAMC,MAAMC,IAAAA,6BAAkB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AAA,uBAAY,EAACzC,MAAMqC;;QAC1C;QACAK,KAAK;YACGjC,SAAN,SAAMA,QAAQD,GAAW;;wBACjBmC;;;;gCAAW;;oCAAM5C,OAAOU,OAAO,CAACD;;;gCAAhCmC,WAAW;gCACjB;;oCAAO;wCACLxB,SAAS,SAATA;4CACE,IAAMyB,MAA+B,EAAE;4CACvC,IAAK,IAAIC,IAAI,GAAGA,IAAIF,SAASG,WAAW,EAAED,IAAKD,IAAIG,IAAI,CAAC;gDAAE1C,MAAMsC,SAASK,UAAU,CAACH;4CAAG;4CACvF,OAAOD;wCACT;wCACA,kFAAkF;wCAClF,0DAA0D;wCAC1DK,SAAS,SAATA;4CAA0B,IAAA,IAAA,OAAA,UAAA,QAAA,AAAGC,SAAH,UAAA,OAAA,OAAA,GAAA,OAAA,MAAA;gDAAGA,OAAH,QAAA,SAAA,CAAA,KAAoB;;;oDAEtCC,QACFC,SAGIzB;;;;4DALR,IAAIuB,OAAOG,MAAM,GAAG,GAAGV,SAASW,IAAI,CAACJ;4DACtB;;gEAAA,uBAAMP,SAASY,aAAa;;;4DAArCJ,SAAS;4DACXC,UAAU;;;4DAEZ;;gEAAA,uBAAMD,OAAOK,SAAS,CAACL,OAAOM,eAAe,GAAG;;;4DAAhD;4DACM9B,OAAOwB,OAAOO,eAAe;;;iEAC5BN,CAAAA,UAAUzB,KAAK0B,MAAM,AAAD;;;;4DAAc;;gEAAMM,IAAAA,0BAAY,EAAChC,IAAI,CAACyB,QAAQ;;;4DAAhC;;;4DAAXA;;;;;;gEACvB,CAACD,OAAOS,IAAI,EAAZ;;;;;;;;;;;4CACX;;oCACF;;;;gBACF;;QACF;QACMC,OAAN,SAAMA;;;oBACJ,iFAAiF;oBACjF9D,OAAO+D,cAAc;oBACrBhE,SAASiE,SAAS;;;;;YACpB;;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/store/duckdb/store.ts"],"sourcesContent":["import type { DuckDBConnection, DuckDBInstance } from '@duckdb/node-api';\nimport type { Config } from '../../config/index.ts';\nimport { STORE_DIMS } from '../../embed/types.ts';\nimport { getColumns } from '../shared.ts';\nimport { withTransaction } from '../transaction.ts';\nimport type { Capability, Connection, Statement, Store } from '../types.ts';\nimport { hasVectorRow, pendingRows } from '../vectors.ts';\nimport { storeRowToJs } from './connection.ts';\nimport { fieldStats } from './fieldStats.ts';\nimport { createLexicalIndex } from './lexical.ts';\nimport { reconcile } from './reconcile.ts';\nimport { scanCandidates, scanSimilar, writeVectorBatch } from './vectors.ts';\n\n// Portable surface, links/sections/tags/rank, raw sql passthrough, lexical (D1: fts BM25 +\n// contains(), see lexical.ts), and vectors (D2: native FLOAT[N] + array_cosine_similarity, see\n// vectors.ts) are implemented. 'snippets' is declined: no snippet()-equivalent exists, so every\n// lexical hit relies on the caller's JS excerpt fallback (commands/search.ts) rather than a\n// bounded engine-native one. 'phrases' means quoted-phrase matching only (types.ts):\n// prefix/boolean/NEAR/column-filter FTS5 syntax is not claimed here -- lexical.ts rejects it\n// rather than answer it differently.\nexport const CAPABILITIES: ReadonlySet<Capability> = new Set(['lexical', 'phrases', 'vectors']);\n\n// Shares one Connection instance (conn) with open()'s own reconcile call so transaction depth\n// (see transaction.ts) is tracked against the same object everywhere. The instance is the\n// native database handle that owns the WAL: close() must close it, not just disconnect the\n// connection, or DuckDB never checkpoints and the next open reads a mismatched WAL.\nexport function createStore(instance: DuckDBInstance, duckdb: DuckDBConnection, conn: Connection, cfg: Config, baseDir: string): Store {\n const lex = createLexicalIndex(conn);\n return {\n name: 'duckdb',\n capabilities: CAPABILITIES,\n async exec(sql: string): Promise<void> {\n await conn.exec(sql);\n },\n async prepare(sql: string): Promise<Statement> {\n return conn.prepare(sql);\n },\n async runBatch(sql: string, paramRows: unknown[][]): Promise<void> {\n await conn.runBatch(sql, paramRows);\n },\n async transaction<T>(fn: () => Promise<T>): Promise<T> {\n return withTransaction(conn, fn);\n },\n async reconcile() {\n const result = await reconcile(conn, cfg, baseDir);\n // content may have changed; the fts index is rebuilt lazily, on the next lexical query\n // that needs it, not here (see lexical.ts's FtsIndexState).\n lex.markStale();\n return result;\n },\n docs: {\n async columns() {\n return [...(await getColumns(conn))];\n },\n fieldStats: (columns, scopeWhere) => fieldStats(conn, columns, scopeWhere),\n },\n lexical: {\n query: lex.query,\n },\n // The column's fixed DDL width (STORE_DIMS) is what every scan binds against, not the\n // interface's per-call storeDims -- see vectors.ts's padded() for why a shorter vector is\n // still correct against a wider column.\n vectors: {\n pending: () => pendingRows(conn),\n writeVectors: (rows) => writeVectorBatch(duckdb, conn, STORE_DIMS, rows),\n candidates: (qv, _storeDims, fetch, allowed) => scanCandidates(duckdb, qv, STORE_DIMS, fetch, allowed),\n similar: (path, opts) => scanSimilar(duckdb, conn, STORE_DIMS, path, opts),\n hasVector: (path) => hasVectorRow(conn, path),\n },\n // No comparable setting to report yet.\n async engineStatus() {\n return {};\n },\n raw: {\n async prepare(sql: string) {\n const prepared = await duckdb.prepare(sql);\n return {\n columns: () => {\n const out: Array<{ name: string }> = [];\n for (let i = 0; i < prepared.columnCount; i++) out.push({ name: prepared.columnName(i) });\n return out;\n },\n // Real incremental streaming: DuckDB reads its own result in row-group chunks, so\n // each readUntil only fetches what isn't already in hand.\n iterate: async function* (...params: unknown[]) {\n if (params.length > 0) prepared.bind(params as Parameters<typeof prepared.bind>[0]);\n const reader = await prepared.streamAndRead();\n let yielded = 0;\n do {\n await reader.readUntil(reader.currentRowCount + 2048);\n const rows = reader.getRowObjectsJS() as Array<Record<string, unknown>>;\n for (; yielded < rows.length; yielded++) yield storeRowToJs(rows[yielded]);\n } while (!reader.done);\n },\n };\n },\n },\n async close() {\n // Order matters: the connection must be gone before the instance closes the WAL.\n duckdb.disconnectSync();\n instance.closeSync();\n },\n };\n}\n"],"names":["CAPABILITIES","createStore","Set","instance","duckdb","conn","cfg","baseDir","lex","createLexicalIndex","name","capabilities","exec","sql","prepare","runBatch","paramRows","transaction","fn","withTransaction","reconcile","result","markStale","docs","columns","getColumns","fieldStats","scopeWhere","lexical","query","vectors","pending","pendingRows","writeVectors","rows","writeVectorBatch","STORE_DIMS","candidates","qv","_storeDims","fetch","allowed","scanCandidates","similar","path","opts","scanSimilar","hasVector","hasVectorRow","engineStatus","raw","prepared","out","i","columnCount","push","columnName","iterate","params","reader","yielded","length","bind","streamAndRead","readUntil","currentRowCount","getRowObjectsJS","storeRowToJs","done","close","disconnectSync","closeSync"],"mappings":";;;;;;;;;;;QAoBaA;eAAAA;;QAMGC;eAAAA;;;uBAxBW;wBACA;6BACK;yBAEU;4BACb;4BACF;yBACQ;2BACT;0BACoC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASvD,IAAMD,eAAwC,IAAIE,IAAI;IAAC;IAAW;IAAW;CAAU;AAMvF,SAASD,YAAYE,QAAwB,EAAEC,MAAwB,EAAEC,IAAgB,EAAEC,GAAW,EAAEC,OAAe;IAC5H,IAAMC,MAAMC,IAAAA,6BAAkB,EAACJ;IAC/B,OAAO;QACLK,MAAM;QACNC,cAAcX;QACRY,MAAN,SAAMA,KAAKC,GAAW;;;;;4BACpB;;gCAAMR,KAAKO,IAAI,CAACC;;;4BAAhB;;;;;;YACF;;QACMC,SAAN,SAAMA,QAAQD,GAAW;;;oBACvB;;wBAAOR,KAAKS,OAAO,CAACD;;;YACtB;;QACME,UAAN,SAAMA,SAASF,GAAW,EAAEG,SAAsB;;;;;4BAChD;;gCAAMX,KAAKU,QAAQ,CAACF,KAAKG;;;4BAAzB;;;;;;YACF;;QACMC,aAAN,SAAMA,YAAeC,EAAoB;;;oBACv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AAIC,IAAI,GAAGA,IAAIF,SAASG,WAAW,EAAED,IAAKD,IAAIG,IAAI,CAAC;gDAAE7C,MAAMyC,SAASK,UAAU,CAACH;4CAAG;4CACvF,OAAOD;wCACT;wCACA,kFAAkF;wCAClF,0DAA0D;wCAC1DK,SAAS,SAATA;4CAA0B,IAAA,IAAA,OAAA,UAAA,QAAA,AAAGC,SAAH,UAAA,OAAA,OAAA,GAAA,OAAA,MAAA;gDAAGA,OAAH,QAAA,SAAA,CAAA,KAAoB;;;oDAEtCC,QACFC,SAGI1B;;;;4DALR,IAAIwB,OAAOG,MAAM,GAAG,GAAGV,SAASW,IAAI,CAACJ;4DACtB;;gEAAA,uBAAMP,SAASY,aAAa;;;4DAArCJ,SAAS;4DACXC,UAAU;;;4DAEZ;;gEAAA,uBAAMD,OAAOK,SAAS,CAACL,OAAOM,eAAe,GAAG;;;4DAAhD;4DACM/B,OAAOyB,OAAOO,eAAe;;;iEAC5BN,CAAAA,UAAU1B,KAAK2B,MAAM,AAAD;;;;4DAAc;;gEAAMM,IAAAA,0BAAY,EAACjC,IAAI,CAAC0B,QAAQ;;;4DAAhC;;;4DAAXA;;;;;;gEACvB,CAACD,OAAOS,IAAI,EAAZ;;;;;;;;;;;4CACX;;oCACF;;;;gBACF;;QACF;QACMC,OAAN,SAAMA;;;oBACJ,iFAAiF;oBACjFjE,OAAOkE,cAAc;oBACrBnE,SAASoE,SAAS;;;;;YACpB;;IACF;AACF"}
@@ -20,6 +20,7 @@ _export(exports, {
20
20
  }
21
21
  });
22
22
  var _transactionts = require("../transaction.js");
23
+ var _vectorsts = require("../vectors.js");
23
24
  var _batchts = require("./batch.js");
24
25
  var _nativets = require("./native.js");
25
26
  function _array_like_to_array(arr, len) {
@@ -189,16 +190,6 @@ function _unsupported_iterable_to_array(o, minLen) {
189
190
  // A bind position whose type is left to auto-inference (safe for plain strings/numbers; only
190
191
  // the vector ARRAY positions below need an explicit type -- see writeVectorBatch's comment).
191
192
  var untyped = undefined;
192
- // Seed chunks that participate in a `related` scan; must match sqlite/vectors.ts's
193
- // TARGET_CHUNK_CAP for identical sampling behavior (see that file for the measurement it's
194
- // based on -- 12.7s at 201 chunks/note without sampling).
195
- var TARGET_CHUNK_CAP = 16;
196
- // array_cosine_similarity is already a true cosine (no int8 accumulation to push slightly
197
- // outside [-1, 1]), but rounded the same way sqlite's scores are so both stores print the
198
- // same bounded number rather than one having more decimal noise than the other.
199
- function asCosine(score) {
200
- return Math.round(Math.min(1, Math.max(-1, score)) * 1000) / 1000;
201
- }
202
193
  // The DDL-fixed array width can exceed a vector's actual length (a hypothetical model sliced
203
194
  // under the column's width); zero-padding leaves cosine scores unchanged since the added
204
195
  // dimensions contribute nothing to either vector's dot product or norm.
@@ -377,7 +368,7 @@ function scanCandidates(duckdb, qv, dims, fetch, allowed) {
377
368
  return {
378
369
  path: r.path,
379
370
  lines: "L".concat(r.start_line, "-").concat(r.end_line),
380
- similarity: asCosine(r.score)
371
+ similarity: (0, _vectorsts.asCosine)(r.score)
381
372
  };
382
373
  })
383
374
  ];
@@ -396,7 +387,7 @@ function scanCandidates(duckdb, qv, dims, fetch, allowed) {
396
387
  }
397
388
  function scanSimilar(duckdb, conn, dims, path, opts) {
398
389
  return _async_to_generator(function() {
399
- var targetStmt, targetRows, step, targets, _ref, arrayValue, ARRAY, DOUBLE, excludeList, allowedList, sql, stmt, values, types, reader, rows;
390
+ var targetStmt, targetRows, targets, _ref, arrayValue, ARRAY, DOUBLE, excludeList, allowedList, sql, stmt, values, types, reader, rows;
400
391
  return _ts_generator(this, function(_state) {
401
392
  switch(_state.label){
402
393
  case 0:
@@ -420,10 +411,7 @@ function scanSimilar(duckdb, conn, dims, path, opts) {
420
411
  2,
421
412
  []
422
413
  ];
423
- step = Math.max(1, Math.ceil(targetRows.length / TARGET_CHUNK_CAP));
424
- targets = targetRows.filter(function(_, i) {
425
- return i % step === 0;
426
- }).map(function(row) {
414
+ targets = (0, _vectorsts.sampleEvenly)(targetRows).map(function(row) {
427
415
  return row.vector;
428
416
  });
429
417
  return [
@@ -482,7 +470,7 @@ function scanSimilar(duckdb, conn, dims, path, opts) {
482
470
  rows.map(function(r) {
483
471
  return {
484
472
  path: r.path,
485
- similarity: asCosine(r.score)
473
+ similarity: (0, _vectorsts.asCosine)(r.score)
486
474
  };
487
475
  })
488
476
  ];