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
@@ -0,0 +1,793 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "reconcile", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return reconcile;
9
+ }
10
+ });
11
+ var _errorsts = require("../../errors.js");
12
+ var _indexts = require("../../features/index.js");
13
+ var _progressts = require("../../output/progress.js");
14
+ var _indexts1 = require("../../scan/index.js");
15
+ var _reparsets = require("../../scan/reparse.js");
16
+ var _sharedts = require("../shared.js");
17
+ var _transactionts = require("../transaction.js");
18
+ function _array_like_to_array(arr, len) {
19
+ if (len == null || len > arr.length) len = arr.length;
20
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
21
+ return arr2;
22
+ }
23
+ function _array_without_holes(arr) {
24
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
25
+ }
26
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
27
+ try {
28
+ var info = gen[key](arg);
29
+ var value = info.value;
30
+ } catch (error) {
31
+ reject(error);
32
+ return;
33
+ }
34
+ if (info.done) resolve(value);
35
+ else Promise.resolve(value).then(_next, _throw);
36
+ }
37
+ function _async_to_generator(fn) {
38
+ return function() {
39
+ var self = this, args = arguments;
40
+ return new Promise(function(resolve, reject) {
41
+ var gen = fn.apply(self, args);
42
+ function _next(value) {
43
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
44
+ }
45
+ function _throw(err) {
46
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
47
+ }
48
+ _next(undefined);
49
+ });
50
+ };
51
+ }
52
+ function _iterable_to_array(iter) {
53
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) {
54
+ return Array.from(iter);
55
+ }
56
+ }
57
+ function _non_iterable_spread() {
58
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
59
+ }
60
+ function _to_consumable_array(arr) {
61
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
62
+ }
63
+ function _ts_generator(thisArg, body) {
64
+ var f, y, t, _ = {
65
+ label: 0,
66
+ sent: function() {
67
+ if (t[0] & 1) throw t[1];
68
+ return t[1];
69
+ },
70
+ trys: [],
71
+ ops: []
72
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
73
+ return d(g, "next", {
74
+ value: verb(0)
75
+ }), d(g, "throw", {
76
+ value: verb(1)
77
+ }), d(g, "return", {
78
+ value: verb(2)
79
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
80
+ value: function() {
81
+ return this;
82
+ }
83
+ }), g;
84
+ function verb(n) {
85
+ return function(v) {
86
+ return step([
87
+ n,
88
+ v
89
+ ]);
90
+ };
91
+ }
92
+ function step(op) {
93
+ if (f) throw new TypeError("Generator is already executing.");
94
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
95
+ 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;
96
+ if (y = 0, t) op = [
97
+ op[0] & 2,
98
+ t.value
99
+ ];
100
+ switch(op[0]){
101
+ case 0:
102
+ case 1:
103
+ t = op;
104
+ break;
105
+ case 4:
106
+ _.label++;
107
+ return {
108
+ value: op[1],
109
+ done: false
110
+ };
111
+ case 5:
112
+ _.label++;
113
+ y = op[1];
114
+ op = [
115
+ 0
116
+ ];
117
+ continue;
118
+ case 7:
119
+ op = _.ops.pop();
120
+ _.trys.pop();
121
+ continue;
122
+ default:
123
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
124
+ _ = 0;
125
+ continue;
126
+ }
127
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
128
+ _.label = op[1];
129
+ break;
130
+ }
131
+ if (op[0] === 6 && _.label < t[1]) {
132
+ _.label = t[1];
133
+ t = op;
134
+ break;
135
+ }
136
+ if (t && _.label < t[2]) {
137
+ _.label = t[2];
138
+ _.ops.push(op);
139
+ break;
140
+ }
141
+ if (t[2]) _.ops.pop();
142
+ _.trys.pop();
143
+ continue;
144
+ }
145
+ op = body.call(thisArg, _);
146
+ } catch (e) {
147
+ op = [
148
+ 6,
149
+ e
150
+ ];
151
+ y = 0;
152
+ } finally{
153
+ f = t = 0;
154
+ }
155
+ if (op[0] & 5) throw op[1];
156
+ return {
157
+ value: op[0] ? op[1] : void 0,
158
+ done: true
159
+ };
160
+ }
161
+ }
162
+ function _ts_values(o) {
163
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
164
+ if (m) {
165
+ return m.call(o);
166
+ }
167
+ if (o && typeof o.length === "number") {
168
+ return {
169
+ next: function() {
170
+ if (o && i >= o.length) {
171
+ o = void 0;
172
+ }
173
+ return {
174
+ value: o && o[i++],
175
+ done: !o
176
+ };
177
+ }
178
+ };
179
+ }
180
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
181
+ }
182
+ function _unsupported_iterable_to_array(o, minLen) {
183
+ if (!o) return;
184
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
185
+ var n = Object.prototype.toString.call(o).slice(8, -1);
186
+ if (n === "Object" && o.constructor) n = o.constructor.name;
187
+ if (n === "Map" || n === "Set") return Array.from(n);
188
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
189
+ }
190
+ // Fork of sqlite/reconcile.ts (house precedent: each store owns its engine-specific SQL), not
191
+ // duckdb's, even though duckdb's content handling is the structurally closer of the two. duckdb
192
+ // dropped sqlite's reconcile_max_ms bookkeeping entirely, and this store's busy timeout (open.ts)
193
+ // is derived from exactly that recorded value -- forking duckdb's file would lose it silently.
194
+ // content itself follows duckdb's shape instead: a plain table, no rowid coupling, no FTS index
195
+ // (phase 2's job, not reconcile's), and no `_seg` sidecars (turso's unspaced-script path is not
196
+ // FTS5-shaped).
197
+ var CORE_FRONTMATTER_COLUMNS = new Set([
198
+ 'path',
199
+ '_mtime',
200
+ '_ctime',
201
+ '_size',
202
+ '_parse_error'
203
+ ]);
204
+ // Not a compile-time cap on ALTER TABLE ADD COLUMN (spike-measured: turso accepts 10,000 with no
205
+ // error). The real fence is a SELECT projecting more than this many result columns, which fails
206
+ // to prepare (spike-measured, both `SELECT *` and an explicit list), so a wide frontmatter table
207
+ // would pass every write silently and only break the first time something selects across it.
208
+ // Enforced here, before ALTER, the same shape as sqlite's compile-time fence.
209
+ var MAX_FRONTMATTER_COLUMNS = 2000;
210
+ // No rowid coupling (unlike sqlite's FTS5 content): `path` is content's own primary key.
211
+ var INSERT_CONTENT_SQL = 'INSERT INTO content ("path", title, summary, text) VALUES (?, ?, ?, ?)';
212
+ function contentRow(doc) {
213
+ return [
214
+ doc.relPath,
215
+ doc.search.title,
216
+ doc.search.summary,
217
+ doc.search.text
218
+ ];
219
+ }
220
+ function reconcile(conn, cfg, baseDir) {
221
+ return _async_to_generator(function() {
222
+ var files, currentSet, existingStmt, existingRows, existing, vanished, toReparse, features, seenColumns, report, _ref, parsedDocs, warnings, newColumns, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, col, allColumns, writableColumns, insertSql, added, delta, addedSet, reparsedExisting, txStart, durationMs, prevRaw, prevMax;
223
+ return _ts_generator(this, function(_state) {
224
+ switch(_state.label){
225
+ case 0:
226
+ files = (0, _indexts1.listFiles)(cfg, baseDir);
227
+ currentSet = new Set(files.map(function(f) {
228
+ return f.relPath;
229
+ }));
230
+ return [
231
+ 4,
232
+ conn.prepare('SELECT "path", "_mtime", "_size" FROM frontmatter')
233
+ ];
234
+ case 1:
235
+ existingStmt = _state.sent();
236
+ return [
237
+ 4,
238
+ existingStmt.all()
239
+ ];
240
+ case 2:
241
+ existingRows = _state.sent();
242
+ existing = new Map(existingRows.map(function(r) {
243
+ return [
244
+ r.path,
245
+ r
246
+ ];
247
+ }));
248
+ vanished = existingRows.filter(function(r) {
249
+ return !currentSet.has(r.path);
250
+ }).map(function(r) {
251
+ return r.path;
252
+ });
253
+ toReparse = files.filter(function(f) {
254
+ var row = existing.get(f.relPath);
255
+ return !row || row._mtime !== f.mtimeMs || row._size !== f.size;
256
+ });
257
+ if (vanished.length === 0 && toReparse.length === 0) return [
258
+ 2,
259
+ {
260
+ parsed: 0,
261
+ warnings: []
262
+ }
263
+ ];
264
+ features = (0, _indexts.activeFeatures)(cfg);
265
+ return [
266
+ 4,
267
+ (0, _sharedts.getColumns)(conn)
268
+ ];
269
+ case 3:
270
+ seenColumns = _state.sent();
271
+ // Bulk reparses (a sync, a cold build) are the long silences a query can hit; short
272
+ // reconciles stay silent (progress() has a threshold).
273
+ report = (0, _progressts.progress)('reparsing files', toReparse.length);
274
+ return [
275
+ 4,
276
+ (0, _reparsets.reparseFiles)(toReparse, features, cfg, seenColumns, report.tick)
277
+ ];
278
+ case 4:
279
+ _ref = _state.sent(), parsedDocs = _ref.docs, warnings = _ref.warnings, newColumns = _ref.newColumns;
280
+ report.finish();
281
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
282
+ try {
283
+ for(_iterator = newColumns[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
284
+ col = _step.value;
285
+ seenColumns.add(col);
286
+ }
287
+ } catch (err) {
288
+ _didIteratorError = true;
289
+ _iteratorError = err;
290
+ } finally{
291
+ try {
292
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
293
+ _iterator.return();
294
+ }
295
+ } finally{
296
+ if (_didIteratorError) {
297
+ throw _iteratorError;
298
+ }
299
+ }
300
+ }
301
+ allColumns = _to_consumable_array(seenColumns);
302
+ if (allColumns.length > MAX_FRONTMATTER_COLUMNS) {
303
+ throw new _errorsts.SenseError('COLUMN_LIMIT', "frontmatter would need ".concat(allColumns.length, " columns, crossing turso's SELECT result-set column limit (").concat(MAX_FRONTMATTER_COLUMNS, "; ALTER TABLE ADD COLUMN itself accepts far more, but a query projecting past this many columns fails to prepare). Narrow the presets' include globs so fewer/other files are indexed, or fix whatever is generating unbounded frontmatter keys."));
304
+ }
305
+ // Columns the frontmatter upsert actually writes: core + parsed frontmatter keys, never a
306
+ // feature-owned reserved column (see CORE_FRONTMATTER_COLUMNS above).
307
+ writableColumns = allColumns.filter(function(c) {
308
+ return CORE_FRONTMATTER_COLUMNS.has(c) || !_indexts1.RESERVED_COLUMNS.has(c);
309
+ });
310
+ // ON CONFLICT UPDATE (not OR REPLACE) keeps the row's identity stable across reparses.
311
+ insertSql = "INSERT INTO frontmatter (".concat(writableColumns.map(_sharedts.quoteIdent).join(', '), ") VALUES (").concat(writableColumns.map(function() {
312
+ return '?';
313
+ }).join(', '), ') ON CONFLICT("path") DO UPDATE SET ').concat(writableColumns.filter(function(c) {
314
+ return c !== 'path';
315
+ }).map(function(c) {
316
+ return "".concat((0, _sharedts.quoteIdent)(c), " = excluded.").concat((0, _sharedts.quoteIdent)(c));
317
+ }).join(', '));
318
+ added = toReparse.filter(function(f) {
319
+ return !existing.has(f.relPath);
320
+ }).map(function(f) {
321
+ return f.relPath;
322
+ });
323
+ delta = {
324
+ files: files,
325
+ reparsed: parsedDocs.map(function(d) {
326
+ return d.relPath;
327
+ }),
328
+ added: added,
329
+ vanished: vanished
330
+ };
331
+ addedSet = new Set(added);
332
+ reparsedExisting = parsedDocs.map(function(d) {
333
+ return d.relPath;
334
+ }).filter(function(p) {
335
+ return !addedSet.has(p);
336
+ });
337
+ txStart = Date.now();
338
+ return [
339
+ 4,
340
+ (0, _transactionts.withTransaction)(conn, function() {
341
+ return _async_to_generator(function() {
342
+ var _feature_remove, _feature_afterReconcile, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, col, err, rows, contentTouched, presetTouched, presetRows, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator1, _step1, doc, _iterator2, _step2, presetName, removedPaths, _iteratorNormalCompletion3, _didIteratorError3, _iteratorError3, _iterator3, _step3, feature, err, _iteratorNormalCompletion4, _didIteratorError4, _iteratorError4, _loop, _iterator4, _step4, err, _iteratorNormalCompletion5, _didIteratorError5, _iteratorError5, _iterator5, _step5, feature1, err;
343
+ return _ts_generator(this, function(_state) {
344
+ switch(_state.label){
345
+ case 0:
346
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
347
+ _state.label = 1;
348
+ case 1:
349
+ _state.trys.push([
350
+ 1,
351
+ 6,
352
+ 7,
353
+ 8
354
+ ]);
355
+ _iterator = newColumns[Symbol.iterator]();
356
+ _state.label = 2;
357
+ case 2:
358
+ if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
359
+ 3,
360
+ 5
361
+ ];
362
+ col = _step.value;
363
+ return [
364
+ 4,
365
+ conn.exec("ALTER TABLE frontmatter ADD COLUMN ".concat((0, _sharedts.quoteIdent)(col)))
366
+ ];
367
+ case 3:
368
+ _state.sent();
369
+ _state.label = 4;
370
+ case 4:
371
+ _iteratorNormalCompletion = true;
372
+ return [
373
+ 3,
374
+ 2
375
+ ];
376
+ case 5:
377
+ return [
378
+ 3,
379
+ 8
380
+ ];
381
+ case 6:
382
+ err = _state.sent();
383
+ _didIteratorError = true;
384
+ _iteratorError = err;
385
+ return [
386
+ 3,
387
+ 8
388
+ ];
389
+ case 7:
390
+ try {
391
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
392
+ _iterator.return();
393
+ }
394
+ } finally{
395
+ if (_didIteratorError) {
396
+ throw _iteratorError;
397
+ }
398
+ }
399
+ return [
400
+ 7
401
+ ];
402
+ case 8:
403
+ if (!(parsedDocs.length > 0)) return [
404
+ 3,
405
+ 10
406
+ ];
407
+ rows = parsedDocs.map(function(doc) {
408
+ return writableColumns.map(function(col) {
409
+ var _doc_data_col;
410
+ if (col === 'path') return doc.relPath;
411
+ if (col === '_mtime') return doc.mtimeMs;
412
+ if (col === '_ctime') return doc.ctimeMs;
413
+ if (col === '_size') return doc.size;
414
+ // Written per parse, unlike _rank, which a feature pass owns and the upsert skips.
415
+ if (col === '_parse_error') return doc.parseError;
416
+ return (_doc_data_col = doc.data[col]) !== null && _doc_data_col !== void 0 ? _doc_data_col : null;
417
+ });
418
+ });
419
+ return [
420
+ 4,
421
+ conn.runBatch(insertSql, rows)
422
+ ];
423
+ case 9:
424
+ _state.sent();
425
+ _state.label = 10;
426
+ case 10:
427
+ // content is a plain table keyed by its own path (no rowid subquery, unlike sqlite's FTS5
428
+ // content), so vanished and reparsed docs delete in one pass.
429
+ contentTouched = _to_consumable_array(vanished).concat(_to_consumable_array(reparsedExisting));
430
+ if (!(contentTouched.length > 0)) return [
431
+ 3,
432
+ 12
433
+ ];
434
+ return [
435
+ 4,
436
+ conn.runBatch('DELETE FROM content WHERE "path" = ?', contentTouched.map(function(p) {
437
+ return [
438
+ p
439
+ ];
440
+ }))
441
+ ];
442
+ case 11:
443
+ _state.sent();
444
+ _state.label = 12;
445
+ case 12:
446
+ if (!(parsedDocs.length > 0)) return [
447
+ 3,
448
+ 14
449
+ ];
450
+ return [
451
+ 4,
452
+ conn.runBatch(INSERT_CONTENT_SQL, parsedDocs.map(contentRow))
453
+ ];
454
+ case 13:
455
+ _state.sent();
456
+ _state.label = 14;
457
+ case 14:
458
+ if (!(vanished.length > 0)) return [
459
+ 3,
460
+ 16
461
+ ];
462
+ return [
463
+ 4,
464
+ conn.runBatch('DELETE FROM frontmatter WHERE "path" = ?', vanished.map(function(p) {
465
+ return [
466
+ p
467
+ ];
468
+ }))
469
+ ];
470
+ case 15:
471
+ _state.sent();
472
+ _state.label = 16;
473
+ case 16:
474
+ // A preset edit forces a full rebuild, so an unchanged doc's coverage is already correct;
475
+ // new docs have nothing to clear, which keeps cold builds linear.
476
+ presetTouched = _to_consumable_array(vanished).concat(_to_consumable_array(reparsedExisting));
477
+ if (!(presetTouched.length > 0)) return [
478
+ 3,
479
+ 18
480
+ ];
481
+ return [
482
+ 4,
483
+ conn.runBatch('DELETE FROM preset_files WHERE "path" = ?', presetTouched.map(function(p) {
484
+ return [
485
+ p
486
+ ];
487
+ }))
488
+ ];
489
+ case 17:
490
+ _state.sent();
491
+ _state.label = 18;
492
+ case 18:
493
+ presetRows = [];
494
+ _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined, _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = undefined;
495
+ try {
496
+ for(_iterator1 = parsedDocs[Symbol.iterator](); !(_iteratorNormalCompletion2 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion2 = true){
497
+ doc = _step1.value;
498
+ try {
499
+ for(_iterator2 = doc.presets[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion1 = true){
500
+ presetName = _step2.value;
501
+ presetRows.push([
502
+ doc.relPath,
503
+ presetName
504
+ ]);
505
+ }
506
+ } catch (err) {
507
+ _didIteratorError1 = true;
508
+ _iteratorError1 = err;
509
+ } finally{
510
+ try {
511
+ if (!_iteratorNormalCompletion1 && _iterator2.return != null) {
512
+ _iterator2.return();
513
+ }
514
+ } finally{
515
+ if (_didIteratorError1) {
516
+ throw _iteratorError1;
517
+ }
518
+ }
519
+ }
520
+ }
521
+ } catch (err) {
522
+ _didIteratorError2 = true;
523
+ _iteratorError2 = err;
524
+ } finally{
525
+ try {
526
+ if (!_iteratorNormalCompletion2 && _iterator1.return != null) {
527
+ _iterator1.return();
528
+ }
529
+ } finally{
530
+ if (_didIteratorError2) {
531
+ throw _iteratorError2;
532
+ }
533
+ }
534
+ }
535
+ if (!(presetRows.length > 0)) return [
536
+ 3,
537
+ 20
538
+ ];
539
+ return [
540
+ 4,
541
+ conn.runBatch('INSERT INTO preset_files ("path", preset) VALUES (?, ?)', presetRows)
542
+ ];
543
+ case 19:
544
+ _state.sent();
545
+ _state.label = 20;
546
+ case 20:
547
+ removedPaths = _to_consumable_array(vanished).concat(_to_consumable_array(reparsedExisting));
548
+ _iteratorNormalCompletion3 = true, _didIteratorError3 = false, _iteratorError3 = undefined;
549
+ if (!(removedPaths.length > 0)) return [
550
+ 3,
551
+ 28
552
+ ];
553
+ _state.label = 21;
554
+ case 21:
555
+ _state.trys.push([
556
+ 21,
557
+ 26,
558
+ 27,
559
+ 28
560
+ ]);
561
+ _iterator3 = features[Symbol.iterator]();
562
+ _state.label = 22;
563
+ case 22:
564
+ if (!!(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done)) return [
565
+ 3,
566
+ 25
567
+ ];
568
+ feature = _step3.value;
569
+ return [
570
+ 4,
571
+ (_feature_remove = feature.remove) === null || _feature_remove === void 0 ? void 0 : _feature_remove.call(feature, conn, removedPaths, delta)
572
+ ];
573
+ case 23:
574
+ _state.sent();
575
+ _state.label = 24;
576
+ case 24:
577
+ _iteratorNormalCompletion3 = true;
578
+ return [
579
+ 3,
580
+ 22
581
+ ];
582
+ case 25:
583
+ return [
584
+ 3,
585
+ 28
586
+ ];
587
+ case 26:
588
+ err = _state.sent();
589
+ _didIteratorError3 = true;
590
+ _iteratorError3 = err;
591
+ return [
592
+ 3,
593
+ 28
594
+ ];
595
+ case 27:
596
+ try {
597
+ if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
598
+ _iterator3.return();
599
+ }
600
+ } finally{
601
+ if (_didIteratorError3) {
602
+ throw _iteratorError3;
603
+ }
604
+ }
605
+ return [
606
+ 7
607
+ ];
608
+ case 28:
609
+ _iteratorNormalCompletion4 = true, _didIteratorError4 = false, _iteratorError4 = undefined;
610
+ _state.label = 29;
611
+ case 29:
612
+ _state.trys.push([
613
+ 29,
614
+ 34,
615
+ 35,
616
+ 36
617
+ ]);
618
+ _loop = function() {
619
+ var feature, _feature_store, docsForFeature;
620
+ return _ts_generator(this, function(_state) {
621
+ switch(_state.label){
622
+ case 0:
623
+ feature = _step4.value;
624
+ docsForFeature = parsedDocs.map(function(doc) {
625
+ return {
626
+ path: doc.relPath,
627
+ extracted: doc.extracted[feature.name]
628
+ };
629
+ });
630
+ return [
631
+ 4,
632
+ (_feature_store = feature.store) === null || _feature_store === void 0 ? void 0 : _feature_store.call(feature, conn, docsForFeature, delta)
633
+ ];
634
+ case 1:
635
+ _state.sent();
636
+ return [
637
+ 2
638
+ ];
639
+ }
640
+ });
641
+ };
642
+ _iterator4 = features[Symbol.iterator]();
643
+ _state.label = 30;
644
+ case 30:
645
+ if (!!(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done)) return [
646
+ 3,
647
+ 33
648
+ ];
649
+ return [
650
+ 5,
651
+ _ts_values(_loop())
652
+ ];
653
+ case 31:
654
+ _state.sent();
655
+ _state.label = 32;
656
+ case 32:
657
+ _iteratorNormalCompletion4 = true;
658
+ return [
659
+ 3,
660
+ 30
661
+ ];
662
+ case 33:
663
+ return [
664
+ 3,
665
+ 36
666
+ ];
667
+ case 34:
668
+ err = _state.sent();
669
+ _didIteratorError4 = true;
670
+ _iteratorError4 = err;
671
+ return [
672
+ 3,
673
+ 36
674
+ ];
675
+ case 35:
676
+ try {
677
+ if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
678
+ _iterator4.return();
679
+ }
680
+ } finally{
681
+ if (_didIteratorError4) {
682
+ throw _iteratorError4;
683
+ }
684
+ }
685
+ return [
686
+ 7
687
+ ];
688
+ case 36:
689
+ _iteratorNormalCompletion5 = true, _didIteratorError5 = false, _iteratorError5 = undefined;
690
+ _state.label = 37;
691
+ case 37:
692
+ _state.trys.push([
693
+ 37,
694
+ 42,
695
+ 43,
696
+ 44
697
+ ]);
698
+ _iterator5 = features[Symbol.iterator]();
699
+ _state.label = 38;
700
+ case 38:
701
+ if (!!(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done)) return [
702
+ 3,
703
+ 41
704
+ ];
705
+ feature1 = _step5.value;
706
+ return [
707
+ 4,
708
+ (_feature_afterReconcile = feature1.afterReconcile) === null || _feature_afterReconcile === void 0 ? void 0 : _feature_afterReconcile.call(feature1, conn, delta)
709
+ ];
710
+ case 39:
711
+ _state.sent();
712
+ _state.label = 40;
713
+ case 40:
714
+ _iteratorNormalCompletion5 = true;
715
+ return [
716
+ 3,
717
+ 38
718
+ ];
719
+ case 41:
720
+ return [
721
+ 3,
722
+ 44
723
+ ];
724
+ case 42:
725
+ err = _state.sent();
726
+ _didIteratorError5 = true;
727
+ _iteratorError5 = err;
728
+ return [
729
+ 3,
730
+ 44
731
+ ];
732
+ case 43:
733
+ try {
734
+ if (!_iteratorNormalCompletion5 && _iterator5.return != null) {
735
+ _iterator5.return();
736
+ }
737
+ } finally{
738
+ if (_didIteratorError5) {
739
+ throw _iteratorError5;
740
+ }
741
+ }
742
+ return [
743
+ 7
744
+ ];
745
+ case 44:
746
+ return [
747
+ 2
748
+ ];
749
+ }
750
+ });
751
+ })();
752
+ })
753
+ ];
754
+ case 5:
755
+ _state.sent();
756
+ // Reconcile's own write-transaction duration, for open()'s derived busy_timeout: keep the
757
+ // observed max so a big watcher reconcile's lock hold is what the next open bounds its wait
758
+ // against (the same mechanism sqlite's reconcile records, and the one this store's busy
759
+ // timeout is derived from).
760
+ durationMs = Date.now() - txStart;
761
+ return [
762
+ 4,
763
+ (0, _sharedts.getMeta)(conn, 'reconcile_max_ms')
764
+ ];
765
+ case 6:
766
+ prevRaw = _state.sent();
767
+ // -1, not 0, so a genuinely 0ms first reconcile (sub-millisecond, common on a tiny tree)
768
+ // still gets recorded instead of losing to the "nothing recorded yet" default.
769
+ prevMax = prevRaw === null ? -1 : Number(prevRaw);
770
+ if (!(durationMs > prevMax)) return [
771
+ 3,
772
+ 8
773
+ ];
774
+ return [
775
+ 4,
776
+ (0, _sharedts.setMeta)(conn, 'reconcile_max_ms', String(durationMs))
777
+ ];
778
+ case 7:
779
+ _state.sent();
780
+ _state.label = 8;
781
+ case 8:
782
+ return [
783
+ 2,
784
+ {
785
+ parsed: parsedDocs.length,
786
+ warnings: warnings
787
+ }
788
+ ];
789
+ }
790
+ });
791
+ })();
792
+ }
793
+ /* 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; }