@nshiab/simple-data-analysis-core 2.0.5 → 2.0.6

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 (238) hide show
  1. package/README.md +118 -12
  2. package/esm/class/Simple.d.ts +8 -2
  3. package/esm/class/Simple.d.ts.map +1 -1
  4. package/esm/class/Simple.js +9 -3
  5. package/esm/class/SimpleDB.d.ts +72 -1
  6. package/esm/class/SimpleDB.d.ts.map +1 -1
  7. package/esm/class/SimpleDB.js +81 -1
  8. package/esm/class/SimpleTable.d.ts +251 -274
  9. package/esm/class/SimpleTable.d.ts.map +1 -1
  10. package/esm/class/SimpleTable.js +248 -325
  11. package/esm/helpers/LogValue.d.ts +8 -0
  12. package/esm/helpers/LogValue.d.ts.map +1 -0
  13. package/esm/helpers/LogValue.js +23 -0
  14. package/esm/helpers/cacheTableDependencies.d.ts +9 -0
  15. package/esm/helpers/cacheTableDependencies.d.ts.map +1 -1
  16. package/esm/helpers/cacheTableDependencies.js +131 -21
  17. package/esm/helpers/cleanSQL.d.ts +1 -1
  18. package/esm/helpers/cleanSQL.d.ts.map +1 -1
  19. package/esm/helpers/cleanSQL.js +268 -23
  20. package/esm/helpers/flushAllTables.d.ts.map +1 -1
  21. package/esm/helpers/flushAllTables.js +23 -28
  22. package/esm/helpers/foldIdentifier.d.ts +3 -0
  23. package/esm/helpers/foldIdentifier.d.ts.map +1 -0
  24. package/esm/helpers/foldIdentifier.js +4 -0
  25. package/esm/helpers/geometryFromJSON.d.ts +3 -0
  26. package/esm/helpers/geometryFromJSON.d.ts.map +1 -0
  27. package/esm/helpers/geometryFromJSON.js +4 -0
  28. package/esm/helpers/index.d.ts +1 -0
  29. package/esm/helpers/index.d.ts.map +1 -1
  30. package/esm/helpers/index.js +1 -0
  31. package/esm/helpers/logData.d.ts.map +1 -1
  32. package/esm/helpers/logData.js +45 -44
  33. package/esm/helpers/makeLogConverter.d.ts +5 -0
  34. package/esm/helpers/makeLogConverter.d.ts.map +1 -0
  35. package/esm/helpers/makeLogConverter.js +64 -0
  36. package/esm/helpers/osmFiles.d.ts.map +1 -1
  37. package/esm/helpers/parseTypes.d.ts +1 -1
  38. package/esm/helpers/parseTypes.d.ts.map +1 -1
  39. package/esm/helpers/parseTypes.js +4 -0
  40. package/esm/helpers/pendingOps.d.ts +4 -2
  41. package/esm/helpers/pendingOps.d.ts.map +1 -1
  42. package/esm/helpers/prepareGeometry.d.ts +3 -0
  43. package/esm/helpers/prepareGeometry.d.ts.map +1 -0
  44. package/esm/helpers/prepareGeometry.js +99 -0
  45. package/esm/helpers/prepareJSON.d.ts +3 -0
  46. package/esm/helpers/prepareJSON.d.ts.map +1 -0
  47. package/esm/helpers/prepareJSON.js +50 -0
  48. package/esm/helpers/printTable.d.ts +5 -4
  49. package/esm/helpers/printTable.d.ts.map +1 -1
  50. package/esm/helpers/printTable.js +32 -36
  51. package/esm/helpers/queryDB.js +1 -1
  52. package/esm/helpers/queueAsyncBarrier.d.ts +4 -0
  53. package/esm/helpers/queueAsyncBarrier.d.ts.map +1 -1
  54. package/esm/helpers/queueAsyncBarrier.js +4 -0
  55. package/esm/helpers/queueOp.d.ts.map +1 -1
  56. package/esm/helpers/queueOp.js +5 -3
  57. package/esm/helpers/readMutationRows.d.ts +9 -0
  58. package/esm/helpers/readMutationRows.d.ts.map +1 -0
  59. package/esm/helpers/readMutationRows.js +94 -0
  60. package/esm/helpers/referencedTables.d.ts +9 -0
  61. package/esm/helpers/referencedTables.d.ts.map +1 -0
  62. package/esm/helpers/referencedTables.js +22 -0
  63. package/esm/helpers/runQuery.d.ts.map +1 -1
  64. package/esm/helpers/runQuery.js +11 -13
  65. package/esm/helpers/scanSQL.d.ts +7 -0
  66. package/esm/helpers/scanSQL.d.ts.map +1 -0
  67. package/esm/helpers/scanSQL.js +71 -0
  68. package/esm/helpers/tableRegistry.d.ts +2 -0
  69. package/esm/helpers/tableRegistry.d.ts.map +1 -1
  70. package/esm/helpers/tableRegistry.js +12 -4
  71. package/esm/helpers/updateColumnsWithJS.d.ts +52 -0
  72. package/esm/helpers/updateColumnsWithJS.d.ts.map +1 -0
  73. package/esm/helpers/updateColumnsWithJS.js +139 -0
  74. package/esm/methods/addColumn.d.ts +1 -1
  75. package/esm/methods/addColumn.d.ts.map +1 -1
  76. package/esm/methods/bm25.d.ts.map +1 -1
  77. package/esm/methods/bm25.js +1 -2
  78. package/esm/methods/cache.d.ts.map +1 -1
  79. package/esm/methods/cache.js +4 -6
  80. package/esm/methods/convert.d.ts +2 -2
  81. package/esm/methods/convert.d.ts.map +1 -1
  82. package/esm/methods/convert.js +5 -0
  83. package/esm/methods/getBottom.d.ts +1 -1
  84. package/esm/methods/getBottom.d.ts.map +1 -1
  85. package/esm/methods/getBottom.js +2 -2
  86. package/esm/methods/getData.d.ts +1 -1
  87. package/esm/methods/getData.d.ts.map +1 -1
  88. package/esm/methods/getData.js +2 -2
  89. package/esm/methods/join.d.ts.map +1 -1
  90. package/esm/methods/join.js +8 -16
  91. package/esm/methods/joinGeo.d.ts.map +1 -1
  92. package/esm/methods/joinGeo.js +10 -19
  93. package/esm/methods/loadArray.d.ts +1 -1
  94. package/esm/methods/loadArray.d.ts.map +1 -1
  95. package/esm/methods/loadArray.js +74 -19
  96. package/esm/methods/loadData.js +3 -0
  97. package/esm/methods/log.d.ts +7 -0
  98. package/esm/methods/log.d.ts.map +1 -0
  99. package/esm/methods/log.js +58 -0
  100. package/esm/methods/logBottom.d.ts +5 -0
  101. package/esm/methods/logBottom.d.ts.map +1 -0
  102. package/esm/methods/logBottom.js +9 -0
  103. package/esm/methods/removeTable.d.ts.map +1 -1
  104. package/esm/methods/removeTable.js +2 -0
  105. package/esm/methods/removeTables.d.ts.map +1 -1
  106. package/esm/methods/removeTables.js +7 -0
  107. package/esm/methods/renameTable.d.ts.map +1 -1
  108. package/esm/methods/renameTable.js +4 -0
  109. package/esm/methods/rowToText.js +2 -2
  110. package/esm/methods/selectTables.d.ts.map +1 -1
  111. package/esm/methods/selectTables.js +6 -0
  112. package/esm/methods/setTypes.d.ts +1 -1
  113. package/esm/methods/setTypes.d.ts.map +1 -1
  114. package/esm/methods/stream.d.ts.map +1 -1
  115. package/esm/methods/stream.js +2 -1
  116. package/esm/methods/updateWithJS.d.ts +1 -3
  117. package/esm/methods/updateWithJS.d.ts.map +1 -1
  118. package/esm/methods/updateWithJS.js +123 -37
  119. package/llm.md +337 -444
  120. package/llms.txt +1 -1
  121. package/package.json +1 -1
  122. package/script/class/Simple.d.ts +8 -2
  123. package/script/class/Simple.d.ts.map +1 -1
  124. package/script/class/Simple.js +9 -3
  125. package/script/class/SimpleDB.d.ts +72 -1
  126. package/script/class/SimpleDB.d.ts.map +1 -1
  127. package/script/class/SimpleDB.js +81 -1
  128. package/script/class/SimpleTable.d.ts +251 -274
  129. package/script/class/SimpleTable.d.ts.map +1 -1
  130. package/script/class/SimpleTable.js +248 -325
  131. package/script/helpers/LogValue.d.ts +8 -0
  132. package/script/helpers/LogValue.d.ts.map +1 -0
  133. package/script/helpers/LogValue.js +26 -0
  134. package/script/helpers/cacheTableDependencies.d.ts +9 -0
  135. package/script/helpers/cacheTableDependencies.d.ts.map +1 -1
  136. package/script/helpers/cacheTableDependencies.js +170 -20
  137. package/script/helpers/cleanSQL.d.ts +1 -1
  138. package/script/helpers/cleanSQL.d.ts.map +1 -1
  139. package/script/helpers/cleanSQL.js +271 -23
  140. package/script/helpers/flushAllTables.d.ts.map +1 -1
  141. package/script/helpers/flushAllTables.js +24 -29
  142. package/script/helpers/foldIdentifier.d.ts +3 -0
  143. package/script/helpers/foldIdentifier.d.ts.map +1 -0
  144. package/script/helpers/foldIdentifier.js +7 -0
  145. package/script/helpers/geometryFromJSON.d.ts +3 -0
  146. package/script/helpers/geometryFromJSON.d.ts.map +1 -0
  147. package/script/helpers/geometryFromJSON.js +7 -0
  148. package/script/helpers/index.d.ts +1 -0
  149. package/script/helpers/index.d.ts.map +1 -1
  150. package/script/helpers/index.js +3 -1
  151. package/script/helpers/logData.d.ts.map +1 -1
  152. package/script/helpers/logData.js +45 -44
  153. package/script/helpers/makeLogConverter.d.ts +5 -0
  154. package/script/helpers/makeLogConverter.d.ts.map +1 -0
  155. package/script/helpers/makeLogConverter.js +70 -0
  156. package/script/helpers/osmFiles.d.ts.map +1 -1
  157. package/script/helpers/parseTypes.d.ts +1 -1
  158. package/script/helpers/parseTypes.d.ts.map +1 -1
  159. package/script/helpers/parseTypes.js +4 -0
  160. package/script/helpers/pendingOps.d.ts +4 -2
  161. package/script/helpers/pendingOps.d.ts.map +1 -1
  162. package/script/helpers/prepareGeometry.d.ts +3 -0
  163. package/script/helpers/prepareGeometry.d.ts.map +1 -0
  164. package/script/helpers/prepareGeometry.js +102 -0
  165. package/script/helpers/prepareJSON.d.ts +3 -0
  166. package/script/helpers/prepareJSON.d.ts.map +1 -0
  167. package/script/helpers/prepareJSON.js +53 -0
  168. package/script/helpers/printTable.d.ts +5 -4
  169. package/script/helpers/printTable.d.ts.map +1 -1
  170. package/script/helpers/printTable.js +32 -36
  171. package/script/helpers/queryDB.js +1 -1
  172. package/script/helpers/queueAsyncBarrier.d.ts +4 -0
  173. package/script/helpers/queueAsyncBarrier.d.ts.map +1 -1
  174. package/script/helpers/queueAsyncBarrier.js +4 -0
  175. package/script/helpers/queueOp.d.ts.map +1 -1
  176. package/script/helpers/queueOp.js +4 -2
  177. package/script/helpers/readMutationRows.d.ts +9 -0
  178. package/script/helpers/readMutationRows.d.ts.map +1 -0
  179. package/script/helpers/readMutationRows.js +97 -0
  180. package/script/helpers/referencedTables.d.ts +9 -0
  181. package/script/helpers/referencedTables.d.ts.map +1 -0
  182. package/script/helpers/referencedTables.js +28 -0
  183. package/script/helpers/runQuery.d.ts.map +1 -1
  184. package/script/helpers/runQuery.js +11 -13
  185. package/script/helpers/scanSQL.d.ts +7 -0
  186. package/script/helpers/scanSQL.d.ts.map +1 -0
  187. package/script/helpers/scanSQL.js +74 -0
  188. package/script/helpers/tableRegistry.d.ts +2 -0
  189. package/script/helpers/tableRegistry.d.ts.map +1 -1
  190. package/script/helpers/tableRegistry.js +16 -4
  191. package/script/helpers/updateColumnsWithJS.d.ts +52 -0
  192. package/script/helpers/updateColumnsWithJS.d.ts.map +1 -0
  193. package/script/helpers/updateColumnsWithJS.js +145 -0
  194. package/script/methods/addColumn.d.ts +1 -1
  195. package/script/methods/addColumn.d.ts.map +1 -1
  196. package/script/methods/bm25.d.ts.map +1 -1
  197. package/script/methods/bm25.js +1 -2
  198. package/script/methods/cache.d.ts.map +1 -1
  199. package/script/methods/cache.js +3 -5
  200. package/script/methods/convert.d.ts +2 -2
  201. package/script/methods/convert.d.ts.map +1 -1
  202. package/script/methods/convert.js +5 -0
  203. package/script/methods/getBottom.d.ts +1 -1
  204. package/script/methods/getBottom.d.ts.map +1 -1
  205. package/script/methods/getBottom.js +2 -2
  206. package/script/methods/getData.d.ts +1 -1
  207. package/script/methods/getData.d.ts.map +1 -1
  208. package/script/methods/getData.js +2 -2
  209. package/script/methods/join.d.ts.map +1 -1
  210. package/script/methods/join.js +8 -16
  211. package/script/methods/joinGeo.d.ts.map +1 -1
  212. package/script/methods/joinGeo.js +10 -19
  213. package/script/methods/loadArray.d.ts +1 -1
  214. package/script/methods/loadArray.d.ts.map +1 -1
  215. package/script/methods/loadArray.js +74 -19
  216. package/script/methods/loadData.js +3 -0
  217. package/script/methods/log.d.ts +7 -0
  218. package/script/methods/log.d.ts.map +1 -0
  219. package/script/methods/log.js +64 -0
  220. package/script/methods/logBottom.d.ts +5 -0
  221. package/script/methods/logBottom.d.ts.map +1 -0
  222. package/script/methods/logBottom.js +15 -0
  223. package/script/methods/removeTable.d.ts.map +1 -1
  224. package/script/methods/removeTable.js +2 -0
  225. package/script/methods/removeTables.d.ts.map +1 -1
  226. package/script/methods/removeTables.js +7 -0
  227. package/script/methods/renameTable.d.ts.map +1 -1
  228. package/script/methods/renameTable.js +4 -0
  229. package/script/methods/rowToText.js +2 -2
  230. package/script/methods/selectTables.d.ts.map +1 -1
  231. package/script/methods/selectTables.js +6 -0
  232. package/script/methods/setTypes.d.ts +1 -1
  233. package/script/methods/setTypes.d.ts.map +1 -1
  234. package/script/methods/stream.d.ts.map +1 -1
  235. package/script/methods/stream.js +2 -1
  236. package/script/methods/updateWithJS.d.ts +1 -3
  237. package/script/methods/updateWithJS.d.ts.map +1 -1
  238. package/script/methods/updateWithJS.js +122 -36
@@ -7,6 +7,7 @@ exports.runExemptFromFlush = runExemptFromFlush;
7
7
  exports.default = flushAllTables;
8
8
  const node_async_hooks_1 = require("node:async_hooks");
9
9
  const cleanSQL_js_1 = __importDefault(require("./cleanSQL.js"));
10
+ const referencedTables_js_1 = __importDefault(require("./referencedTables.js"));
10
11
  const ensureSpatial_js_1 = __importDefault(require("./ensureSpatial.js"));
11
12
  const extractTypes_js_1 = __importDefault(require("./extractTypes.js"));
12
13
  const mergeOptions_js_1 = __importDefault(require("./mergeOptions.js"));
@@ -147,8 +148,8 @@ async function replayEntries(sdb, pendingEntries) {
147
148
  }
148
149
  const reads = op.rawSQL === undefined
149
150
  ? []
150
- : referencedTables(op.rawSQL, sdb);
151
- if (reads.includes(table)) {
151
+ : (0, referencedTables_js_1.default)(op.rawSQL, sdb);
152
+ if (op.kind === "fusable" && reads.includes(table)) {
152
153
  // User-supplied SQL referencing the operation's own table must read
153
154
  // the state produced by the previous steps, which a fused chain
154
155
  // can't provide (the name would resolve to the pre-chain table). So
@@ -184,7 +185,8 @@ async function replayEntries(sdb, pendingEntries) {
184
185
  if (op.kind === "source") {
185
186
  // A source replaces the target table from an external relation. It
186
187
  // starts a new segment rather than consuming any segment already open
187
- // on the same table.
188
+ // on the same table. A source may read that materialized table itself
189
+ // (for example, an in-place join) and still fuse with downstream steps.
188
190
  await runOpenSegment();
189
191
  open = { table, ops: [op] };
190
192
  current = null;
@@ -263,23 +265,6 @@ async function drainAsyncOperationFrame(frame) {
263
265
  }
264
266
  }
265
267
  }
266
- /**
267
- * Returns the tables of the database whose names appear in the given SQL
268
- * fragments. Matching is conservative (a column sharing a table's name
269
- * counts as a reference): a false positive only costs fusion, never
270
- * correctness.
271
- */
272
- function referencedTables(rawSQL, sdb) {
273
- const referenced = [];
274
- for (const table of (0, tableRegistry_js_1.getRegisteredTables)(sdb)) {
275
- const escaped = table.name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
276
- const pattern = new RegExp(`(?<![\\w"])"?${escaped}"?(?![\\w"])`, "i");
277
- if (rawSQL.some((sql) => pattern.test(sql))) {
278
- referenced.push(table);
279
- }
280
- }
281
- return referenced;
282
- }
283
268
  async function runSegment(table, ops) {
284
269
  if (ops.length === 1) {
285
270
  await runStepwise(table, ops[0]);
@@ -288,8 +273,7 @@ async function runSegment(table, ops) {
288
273
  if (ops.some(needsSpatial)) {
289
274
  await (0, ensureSpatial_js_1.default)(table);
290
275
  }
291
- // Each fragment is cleaned individually: cleanSQL's WHERE handling must not
292
- // cross fragment boundaries once they are composed into one statement.
276
+ // Normalize each fragment once using the database syntax before composition.
293
277
  const ctes = [];
294
278
  // The schema of the next fragment's input, reused while operations declare
295
279
  // they preserve it, so a run of same-shape steps costs at most one
@@ -316,11 +300,21 @@ async function runSegment(table, ops) {
316
300
  await executeFused(table, ops, ctes);
317
301
  }
318
302
  async function compileOp(table, op, ctes, schema) {
303
+ // Source relations can read tables named s1, s2, etc. A generated CTE must
304
+ // not shadow those physical inputs, including in later chain fragments.
305
+ const usedNames = new Set([
306
+ ...(0, tableRegistry_js_1.getRegisteredTables)(table.sdb).map((input) => input.name.toLowerCase()),
307
+ ...ctes.map((cte) => cte.alias),
308
+ ]);
309
+ let aliasIndex = ctes.length + 1;
310
+ while (usedNames.has(`s${aliasIndex}`))
311
+ aliasIndex++;
312
+ const alias = `s${aliasIndex}`;
319
313
  if (op.kind === "source") {
320
314
  return {
321
315
  cte: {
322
- alias: `s${ctes.length + 1}`,
323
- select: (0, cleanSQL_js_1.default)(op.buildSelect()),
316
+ alias,
317
+ select: (0, cleanSQL_js_1.default)(await op.buildSelect(), table.sdb.expressionSyntax),
324
318
  values: [],
325
319
  },
326
320
  schema: op.schema ?? null,
@@ -342,15 +336,16 @@ async function compileOp(table, op, ctes, schema) {
342
336
  : null;
343
337
  return {
344
338
  cte: {
345
- alias: `s${ctes.length + 1}`,
346
- select: (0, cleanSQL_js_1.default)(op.buildSelect(input, buildSchema)),
339
+ alias,
340
+ select: (0, cleanSQL_js_1.default)(op.buildSelect(input, buildSchema), table.sdb.expressionSyntax),
347
341
  values: resolveValues(op, buildSchema),
348
342
  },
349
343
  schema: outputSchema,
350
344
  };
351
345
  }
352
346
  async function executeFused(table, ops, ctes) {
353
- const query = `CREATE OR REPLACE TABLE ${(0, quoteIdentifier_js_1.default)(table.name)} AS WITH ${ctes.map((c) => `${(0, quoteIdentifier_js_1.default)(c.alias)} AS (${c.select})`).join(", ")} SELECT * FROM ${(0, quoteIdentifier_js_1.default)(ctes[ctes.length - 1].alias)}`;
347
+ // A trailing line comment must end before the generated CTE delimiter.
348
+ const query = `CREATE OR REPLACE TABLE ${(0, quoteIdentifier_js_1.default)(table.name)} AS WITH ${ctes.map((c) => `${(0, quoteIdentifier_js_1.default)(c.alias)} AS (${c.select}\n)`).join(", ")} SELECT * FROM ${(0, quoteIdentifier_js_1.default)(ctes[ctes.length - 1].alias)}`;
354
349
  try {
355
350
  await (0, queryDB_js_1.default)(table, query, (0, mergeOptions_js_1.default)(table, {
356
351
  table: table.name,
@@ -388,7 +383,7 @@ async function runStepwise(table, op) {
388
383
  }));
389
384
  }
390
385
  function needsSpatial(op) {
391
- return op.kind === "fusable" && op.needsSpatial === true;
386
+ return op.needsSpatial === true;
392
387
  }
393
388
  function resolveValues(op, schema) {
394
389
  return typeof op.values === "function" ? op.values(schema) : op.values ?? [];
@@ -401,7 +396,7 @@ function resolveValues(op, schema) {
401
396
  async function describeChain(table, ctes) {
402
397
  const select = ctes.length === 0
403
398
  ? `SELECT * FROM ${(0, quoteIdentifier_js_1.default)(table.name)}`
404
- : `WITH ${ctes.map((c) => `${(0, quoteIdentifier_js_1.default)(c.alias)} AS (${c.select})`).join(", ")} SELECT * FROM ${(0, quoteIdentifier_js_1.default)(ctes[ctes.length - 1].alias)}`;
399
+ : `WITH ${ctes.map((c) => `${(0, quoteIdentifier_js_1.default)(c.alias)} AS (${c.select}\n)`).join(", ")} SELECT * FROM ${(0, quoteIdentifier_js_1.default)(ctes[ctes.length - 1].alias)}`;
405
400
  const query = ctes.length === 0
406
401
  ? `DESCRIBE ${(0, quoteIdentifier_js_1.default)(table.name)}`
407
402
  : `DESCRIBE ${select}`;
@@ -0,0 +1,3 @@
1
+ /** Matches DuckDB's ASCII case folding for quoted and unquoted identifiers. */
2
+ export default function foldIdentifier(identifier: string): string;
3
+ //# sourceMappingURL=foldIdentifier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"foldIdentifier.d.ts","sourceRoot":"","sources":["../../src/helpers/foldIdentifier.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAEjE"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = foldIdentifier;
4
+ /** Matches DuckDB's ASCII case folding for quoted and unquoted identifiers. */
5
+ function foldIdentifier(identifier) {
6
+ return identifier.replace(/[A-Z]/g, (letter) => letter.toLowerCase());
7
+ }
@@ -0,0 +1,3 @@
1
+ /** Converts validated GeoJSON SQL text to an explicitly typed WGS84 geometry. */
2
+ export default function geometryFromJSON(expression: string): string;
3
+ //# sourceMappingURL=geometryFromJSON.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geometryFromJSON.d.ts","sourceRoot":"","sources":["../../src/helpers/geometryFromJSON.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAEnE"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = geometryFromJSON;
4
+ /** Converts validated GeoJSON SQL text to an explicitly typed WGS84 geometry. */
5
+ function geometryFromJSON(expression) {
6
+ return `ST_GeomFromGeoJSON(${expression})::GEOMETRY('EPSG:4326')`;
7
+ }
@@ -20,4 +20,5 @@ export { default as queryDB } from "./queryDB.js";
20
20
  export { default as queueAsyncBarrier } from "./queueAsyncBarrier.js";
21
21
  export { default as quoteIdentifier } from "./quoteIdentifier.js";
22
22
  export { default as stringToArray } from "./stringToArray.js";
23
+ export { default as updateColumnsWithJS } from "./updateColumnsWithJS.js";
23
24
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,sBAAsB,CAAC;AAG9B,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,sBAAsB,CAAC;AAG9B,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,0BAA0B,CAAC"}
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.stringToArray = exports.quoteIdentifier = exports.queueAsyncBarrier = exports.queryDB = exports.parseValue = exports.mergeOptions = exports.createDirectory = void 0;
6
+ exports.updateColumnsWithJS = exports.stringToArray = exports.quoteIdentifier = exports.queueAsyncBarrier = exports.queryDB = exports.parseValue = exports.mergeOptions = exports.createDirectory = void 0;
7
7
  /**
8
8
  * Helper utilities for Simple Data Analysis Core.
9
9
  *
@@ -33,3 +33,5 @@ var quoteIdentifier_js_1 = require("./quoteIdentifier.js");
33
33
  Object.defineProperty(exports, "quoteIdentifier", { enumerable: true, get: function () { return __importDefault(quoteIdentifier_js_1).default; } });
34
34
  var stringToArray_js_1 = require("./stringToArray.js");
35
35
  Object.defineProperty(exports, "stringToArray", { enumerable: true, get: function () { return __importDefault(stringToArray_js_1).default; } });
36
+ var updateColumnsWithJS_js_1 = require("./updateColumnsWithJS.js");
37
+ Object.defineProperty(exports, "updateColumnsWithJS", { enumerable: true, get: function () { return __importDefault(updateColumnsWithJS_js_1).default; } });
@@ -1 +1 @@
1
- {"version":3,"file":"logData.d.ts","sourceRoot":"","sources":["../../src/helpers/logData.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,UAAU,OAAO,CAC7B,KAAK,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,GAAG,IAAI,EACvC,IAAI,EACA;IACA,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,EAAE,GACD,IAAI,EACR,UAAU,CAAC,EAAE,MAAM,QA4DpB"}
1
+ {"version":3,"file":"logData.d.ts","sourceRoot":"","sources":["../../src/helpers/logData.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,OAAO,UAAU,OAAO,CAC7B,KAAK,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,GAAG,IAAI,EACvC,IAAI,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,EAAE,GAAG,IAAI,EACzC,UAAU,CAAC,EAAE,MAAM,QAkEpB"}
@@ -4,56 +4,57 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.default = logData;
7
+ const LogValue_js_1 = __importDefault(require("./LogValue.js"));
7
8
  const printTable_js_1 = __importDefault(require("./printTable.js"));
8
9
  function logData(types, data, charsToLog) {
9
10
  if (data === null) {
10
11
  console.log("Data is null");
12
+ return;
11
13
  }
12
- else {
13
- if (data.length === 0) {
14
- console.log(data);
14
+ if (data.length === 0) {
15
+ console.log(data);
16
+ return;
17
+ }
18
+ const formatted = data.map((row) => Object.fromEntries(Object.entries(row).map(([key, value]) => {
19
+ const nested = value !== null && typeof value === "object" &&
20
+ !(value instanceof Date) && !(value instanceof LogValue_js_1.default);
21
+ let text = value instanceof LogValue_js_1.default
22
+ ? value.text
23
+ : nested
24
+ ? JSON.stringify(value)
25
+ : value;
26
+ const truncatable = !(value instanceof LogValue_js_1.default) ||
27
+ value.category === "string";
28
+ if (truncatable && typeof text === "string" &&
29
+ typeof charsToLog === "number" && text.length > charsToLog) {
30
+ const limit = Math.max(0, Math.floor(charsToLog));
31
+ text = text.slice(0, Math.max(0, limit - 3)) + "...".slice(0, limit);
15
32
  }
16
- else {
17
- const dataToBeLogged = [];
18
- const keys = Object.keys(data[0]);
19
- for (let i = 0; i < data.length; i++) {
20
- const newItem = {};
21
- for (const key of keys) {
22
- if (typeof charsToLog === "number" &&
23
- typeof data[i][key] === "string" &&
24
- data[i][key].length > charsToLog) {
25
- newItem[key] = data[i][key].slice(0, charsToLog) + "...";
26
- }
27
- else {
28
- newItem[key] = data[i][key];
29
- }
30
- }
31
- dataToBeLogged.push(newItem);
32
- }
33
- let hasTypesRow = false;
34
- if (types !== null) {
35
- const columns = Object.keys(types);
36
- if (columns.length > 0) {
37
- for (const col of columns) {
38
- if (data[0][col] === "<Geometry>") {
39
- continue;
40
- }
41
- else {
42
- types[col] = types[col] + "/" +
43
- (data[0][col] === null ? null : typeof data[0][col]);
44
- }
45
- }
46
- // Add types as the first row
47
- dataToBeLogged.unshift(types);
48
- hasTypesRow = true;
33
+ return [
34
+ key,
35
+ value instanceof LogValue_js_1.default
36
+ ? new LogValue_js_1.default(String(text), value.jsType, value.category)
37
+ : text,
38
+ ];
39
+ })));
40
+ const hasTypes = types !== null && Object.keys(types).length > 0;
41
+ if (hasTypes) {
42
+ formatted.unshift(Object.fromEntries(Object.entries(types).map(([key, sqlType]) => {
43
+ const representations = new Set(data.flatMap((row) => {
44
+ const value = row[key];
45
+ if (value instanceof LogValue_js_1.default) {
46
+ return value.category === "null" ? [] : [value.jsType];
49
47
  }
50
- }
51
- (0, printTable_js_1.default)(dataToBeLogged, {
52
- ...(typeof charsToLog === "number"
53
- ? { maxColumnWidth: charsToLog }
54
- : {}),
55
- ...(hasTypesRow ? { typesRowIndex: 0 } : {}),
56
- });
57
- }
48
+ return value === null || value === undefined ? [] : [typeof value];
49
+ }));
50
+ const first = data[0][key];
51
+ const representation = representations.size > 0
52
+ ? [...representations].join("|")
53
+ : first instanceof LogValue_js_1.default
54
+ ? first.jsType
55
+ : "null";
56
+ return [key, `${sqlType}/${representation}`];
57
+ })));
58
58
  }
59
+ (0, printTable_js_1.default)(formatted, hasTypes ? { typesRowIndex: 0 } : undefined);
59
60
  }
@@ -0,0 +1,5 @@
1
+ import { type DuckDBType, type DuckDBValue } from "@duckdb/node-api";
2
+ import LogValue from "./LogValue.js";
3
+ /** Formats native temporal values before extraction can discard precision. */
4
+ export default function makeLogConverter(type: DuckDBType, convert: (value: DuckDBValue) => unknown): (value: DuckDBValue) => LogValue;
5
+ //# sourceMappingURL=makeLogConverter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"makeLogConverter.d.ts","sourceRoot":"","sources":["../../src/helpers/makeLogConverter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EAEf,KAAK,WAAW,EACjB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,QAAQ,MAAM,eAAe,CAAC;AAErC,8EAA8E;AAC9E,MAAM,CAAC,OAAO,UAAU,gBAAgB,CACtC,IAAI,EAAE,UAAU,EAChB,OAAO,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,GACvC,CAAC,KAAK,EAAE,WAAW,KAAK,QAAQ,CA8DlC"}
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = makeLogConverter;
7
+ const node_api_1 = require("@duckdb/node-api");
8
+ const LogValue_js_1 = __importDefault(require("./LogValue.js"));
9
+ /** Formats native temporal values before extraction can discard precision. */
10
+ function makeLogConverter(type, convert) {
11
+ const sqlType = type.toString();
12
+ const floatArray = sqlType.includes("FLOAT[");
13
+ const placeholder = sqlType.toLowerCase().includes("geometry") ||
14
+ floatArray;
15
+ const temporal = [
16
+ node_api_1.DuckDBTypeId.DATE,
17
+ node_api_1.DuckDBTypeId.TIME,
18
+ node_api_1.DuckDBTypeId.TIME_TZ,
19
+ node_api_1.DuckDBTypeId.TIME_NS,
20
+ node_api_1.DuckDBTypeId.TIMESTAMP,
21
+ node_api_1.DuckDBTypeId.TIMESTAMP_TZ,
22
+ node_api_1.DuckDBTypeId.TIMESTAMP_S,
23
+ node_api_1.DuckDBTypeId.TIMESTAMP_MS,
24
+ node_api_1.DuckDBTypeId.TIMESTAMP_NS,
25
+ ].includes(type.typeId);
26
+ const numeric = !placeholder &&
27
+ /^(TINYINT|SMALLINT|INTEGER|BIGINT|HUGEINT|UTINYINT|USMALLINT|UINTEGER|UBIGINT|UHUGEINT|FLOAT|DOUBLE|DECIMAL|BIGNUM)(\(|$)/
28
+ .test(sqlType);
29
+ const jsType = placeholder ? "string" : type.typeId === node_api_1.DuckDBTypeId.DATE ||
30
+ type.typeId === node_api_1.DuckDBTypeId.TIMESTAMP
31
+ ? "object"
32
+ : temporal
33
+ ? "string"
34
+ : type.typeId === node_api_1.DuckDBTypeId.BOOLEAN
35
+ ? "boolean"
36
+ : numeric
37
+ ? (/^(DECIMAL|BIGNUM)/.test(sqlType) ? "string" : "number")
38
+ : [
39
+ node_api_1.DuckDBTypeId.LIST,
40
+ node_api_1.DuckDBTypeId.ARRAY,
41
+ node_api_1.DuckDBTypeId.STRUCT,
42
+ node_api_1.DuckDBTypeId.MAP,
43
+ node_api_1.DuckDBTypeId.UNION,
44
+ node_api_1.DuckDBTypeId.INTERVAL,
45
+ ].includes(type.typeId)
46
+ ? "object"
47
+ : "string";
48
+ return (value) => {
49
+ if (value === null)
50
+ return new LogValue_js_1.default("null", jsType, "null");
51
+ // TIMESTAMPTZ uses the existing UTC converter, independent of process timezone.
52
+ const converted = floatArray
53
+ ? `<${sqlType}>`
54
+ : temporal && type.typeId !== node_api_1.DuckDBTypeId.TIMESTAMP_TZ
55
+ ? String(value)
56
+ : convert(value);
57
+ const text = typeof converted === "object" && converted !== null
58
+ ? JSON.stringify(converted)
59
+ : String(converted);
60
+ return new LogValue_js_1.default(text,
61
+ // NaN and infinities are strings in the public JSON conversion.
62
+ temporal ? jsType : typeof converted, temporal
63
+ ? "date"
64
+ : numeric
65
+ ? "number"
66
+ : jsType === "boolean"
67
+ ? "boolean"
68
+ : "string");
69
+ };
70
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"osmFiles.d.ts","sourceRoot":"","sources":["../../src/helpers/osmFiles.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,UAAU,CAAC;AAShD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI,CAMnE;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAOpD;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAe1D;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAmBrD;AAED,wBAAsB,0BAA0B,CAC9C,GAAG,EAAE,MAAM,EACX,OAAO,EAAE;IACP,MAAM,EAAE,aAAa,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAChD,GACA,OAAO,CAAC,MAAM,CAAC,CAmHjB;AAgMD,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAWjD"}
1
+ {"version":3,"file":"osmFiles.d.ts","sourceRoot":"","sources":["../../src/helpers/osmFiles.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,UAAU,CAAC;AAShD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI,CAMnE;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAOpD;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAe1D;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAmBrD;AAED,wBAAsB,0BAA0B,CAC9C,GAAG,EAAE,MAAM,EACX,OAAO,EAAE;IACP,MAAM,EAAE,aAAa,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAChD,GACA,OAAO,CAAC,MAAM,CAAC,CAqHjB;AAgMD,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAWjD"}
@@ -1,2 +1,2 @@
1
- export default function parseType(type: "integer" | "float" | "number" | "string" | "date" | "time" | "datetime" | "datetimeTz" | "bigint" | "double" | "varchar" | "timestamp" | "timestamp with time zone" | "boolean" | `geometry('${string}')` | `GEOMETRY('${string}')`): string;
1
+ export default function parseType(type: "integer" | "float" | "number" | "string" | "date" | "time" | "datetime" | "datetimeTz" | "bigint" | "double" | "varchar" | "timestamp" | "timestamp with time zone" | "boolean" | "json" | "JSON" | `float[${number}]` | `FLOAT[${number}]` | `geometry('${string}')` | `GEOMETRY('${string}')`): string;
2
2
  //# sourceMappingURL=parseTypes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parseTypes.d.ts","sourceRoot":"","sources":["../../src/helpers/parseTypes.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,UAAU,SAAS,CAC/B,IAAI,EACA,SAAS,GACT,OAAO,GACP,QAAQ,GACR,QAAQ,GACR,MAAM,GACN,MAAM,GACN,UAAU,GACV,YAAY,GACZ,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,WAAW,GACX,0BAA0B,GAC1B,SAAS,GACT,aAAa,MAAM,IAAI,GACvB,aAAa,MAAM,IAAI,UAgC5B"}
1
+ {"version":3,"file":"parseTypes.d.ts","sourceRoot":"","sources":["../../src/helpers/parseTypes.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,UAAU,SAAS,CAC/B,IAAI,EACA,SAAS,GACT,OAAO,GACP,QAAQ,GACR,QAAQ,GACR,MAAM,GACN,MAAM,GACN,UAAU,GACV,YAAY,GACZ,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,WAAW,GACX,0BAA0B,GAC1B,SAAS,GACT,MAAM,GACN,MAAM,GACN,SAAS,MAAM,GAAG,GAClB,SAAS,MAAM,GAAG,GAClB,aAAa,MAAM,IAAI,GACvB,aAAa,MAAM,IAAI,UAmC5B"}
@@ -28,9 +28,13 @@ function parseType(type) {
28
28
  "timestamp",
29
29
  "timestamp with time zone",
30
30
  "boolean",
31
+ "json",
31
32
  ].includes(typeLowerCase)) {
32
33
  return type.toUpperCase();
33
34
  }
35
+ else if (/^float\[[1-9]\d*\]$/.test(typeLowerCase)) {
36
+ return type.toUpperCase();
37
+ }
34
38
  else if (typeLowerCase.includes("geometry")) {
35
39
  return type.toUpperCase();
36
40
  }
@@ -94,8 +94,10 @@ export type SourceOp = {
94
94
  rawSQL?: string[];
95
95
  /** A schema known from explicit source options, when inference is unnecessary. */
96
96
  schema?: TableSchema;
97
- /** Returns the source as a single composable SELECT statement. */
98
- buildSelect: () => string;
97
+ /** Whether the source uses spatial functions. */
98
+ needsSpatial?: boolean;
99
+ /** Returns a composable SELECT, optionally inspecting materialized inputs. */
100
+ buildSelect: () => string | Promise<string>;
99
101
  };
100
102
  /** A relational operation that can participate in a fused segment. */
101
103
  export type RelationalOp = SourceOp | FusableOp;
@@ -1 +1 @@
1
- {"version":3,"file":"pendingOps.d.ts","sourceRoot":"","sources":["../../src/helpers/pendingOps.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG;IAAE,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAAC;AAEvD;;;;GAIG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,EAAE,SAAS,CAAC;IAChB,mEAAmE;IACnE,MAAM,EAAE,MAAM,CAAC;IACf,gEAAgE;IAChE,UAAU,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;IAC9C;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,WAAW,EAAE,OAAO,CAAC;IACrB;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;;;;;;OAQG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB;;;;;OAKG;IACH,yBAAyB,CAAC,EAAE,OAAO,CAAC;IACpC,oEAAoE;IACpE,MAAM,CAAC,EAAE,WAAW,EAAE,GAAG,CAAC,CAAC,MAAM,EAAE,WAAW,KAAK,WAAW,EAAE,CAAC,CAAC;IAClE;;;;;OAKG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;OAIG;IACH,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,WAAW,CAAC;IACnD;;;OAGG;IACH,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,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AM,CAAC;IACf,0EAA0E;IAC1E,UAAU,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;IAC9C,+DAA+D;IAC/D,QAAQ,EAAE,MAAM,CAAC;IACjB,qDAAqD;IACrD,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG,YAAY,GAAG,SAAS,GAAG,cAAc,CAAC;AAElE;;;GAGG;AACH,MAAM,MAAM,cAAc,GACtB,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC,GAC3B,IAAI,CAAC,QAAQ,EAAE,UAAU,CAAC,GAC1B,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC,GAC3B,IAAI,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ /** Validates and snapshots a two-dimensional WGS84 GeoJSON geometry cell. */
2
+ export default function prepareGeometry(value: unknown, column: string, row: number): string | null;
3
+ //# sourceMappingURL=prepareGeometry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prepareGeometry.d.ts","sourceRoot":"","sources":["../../src/helpers/prepareGeometry.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,MAAM,CAAC,OAAO,UAAU,eAAe,CACrC,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,GACV,MAAM,GAAG,IAAI,CA+Gf"}
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = prepareGeometry;
4
+ /** Validates and snapshots a two-dimensional WGS84 GeoJSON geometry cell. */
5
+ function prepareGeometry(value, column, row) {
6
+ if (value === null)
7
+ return null;
8
+ const fail = (message) => {
9
+ throw new Error(`Column ${JSON.stringify(column)}, row ${row}: ${message}`);
10
+ };
11
+ const active = new Set();
12
+ let hasSignedZero = false;
13
+ function position(value) {
14
+ if (!Array.isArray(value) || value.length !== 2 ||
15
+ !Array.from(value).every((n) => typeof n === "number" && Number.isFinite(n))) {
16
+ fail("Expected a finite two-dimensional [longitude, latitude] position; Z/M coordinates are unsupported.");
17
+ }
18
+ const point = value;
19
+ if (Math.abs(point[0]) > 180 || Math.abs(point[1]) > 90) {
20
+ fail("Expected WGS84 longitude [-180, 180] and latitude [-90, 90]; reproject the input first.");
21
+ }
22
+ hasSignedZero ||= Object.is(point[0], -0) || Object.is(point[1], -0);
23
+ return [...point];
24
+ }
25
+ function list(value, convert) {
26
+ if (!Array.isArray(value))
27
+ fail("Expected a coordinate array.");
28
+ return Array.from(value, convert);
29
+ }
30
+ function line(value) {
31
+ const points = list(value, position);
32
+ if (points.length < 2) {
33
+ fail("A LineString must contain at least two positions.");
34
+ }
35
+ return points;
36
+ }
37
+ function ring(value) {
38
+ const points = list(value, position);
39
+ if (points.length < 4 || points[0][0] !== points.at(-1)[0] ||
40
+ points[0][1] !== points.at(-1)[1]) {
41
+ fail("A polygon ring must contain at least four positions and be closed.");
42
+ }
43
+ return points;
44
+ }
45
+ function geometry(value) {
46
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
47
+ fail("Expected a GeoJSON geometry object or null.");
48
+ }
49
+ const object = value;
50
+ if (active.has(object))
51
+ fail("Cyclic GeometryCollections are unsupported.");
52
+ if (active.size >= 100) {
53
+ fail("GeometryCollections may nest at most 100 levels.");
54
+ }
55
+ active.add(object);
56
+ try {
57
+ const type = object.type;
58
+ if (type === "Feature" || type === "FeatureCollection") {
59
+ fail("Expected a GeoJSON geometry object, not a Feature or FeatureCollection; extract each feature's geometry first.");
60
+ }
61
+ if ("crs" in object) {
62
+ fail("Geometry crs members are unsupported; supply WGS84 coordinates and declare GEOMETRY('EPSG:4326').");
63
+ }
64
+ let coordinates;
65
+ switch (type) {
66
+ case "Point":
67
+ coordinates = position(object.coordinates);
68
+ break;
69
+ case "MultiPoint":
70
+ coordinates = list(object.coordinates, position);
71
+ break;
72
+ case "LineString":
73
+ coordinates = line(object.coordinates);
74
+ break;
75
+ case "MultiLineString":
76
+ coordinates = list(object.coordinates, line);
77
+ break;
78
+ case "Polygon":
79
+ coordinates = list(object.coordinates, ring);
80
+ break;
81
+ case "MultiPolygon":
82
+ coordinates = list(object.coordinates, (v) => list(v, ring));
83
+ break;
84
+ case "GeometryCollection":
85
+ return { type, geometries: list(object.geometries, geometry) };
86
+ default:
87
+ fail("Expected a supported GeoJSON geometry type.");
88
+ }
89
+ return { type, coordinates };
90
+ }
91
+ finally {
92
+ active.delete(object);
93
+ }
94
+ }
95
+ const prepared = geometry(value);
96
+ if (!hasSignedZero)
97
+ return JSON.stringify(prepared);
98
+ // JSON.stringify normalizes -0. Only supported geometry type names survive
99
+ // validation as strings, so the "-0" marker cannot collide with input text.
100
+ // Emit a decimal literal so DuckDB also preserves its sign when parsing JSON.
101
+ return JSON.stringify(prepared, (_key, cell) => Object.is(cell, -0) ? "-0" : cell).replaceAll('"-0"', "-0.0");
102
+ }
@@ -0,0 +1,3 @@
1
+ /** Validates and snapshots a JavaScript JSON value without dropping information. */
2
+ export default function prepareJSON(value: unknown, column: string, row: number): string | null;
3
+ //# sourceMappingURL=prepareJSON.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prepareJSON.d.ts","sourceRoot":"","sources":["../../src/helpers/prepareJSON.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,MAAM,CAAC,OAAO,UAAU,WAAW,CACjC,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,GACV,MAAM,GAAG,IAAI,CAmEf"}
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = prepareJSON;
4
+ /** Validates and snapshots a JavaScript JSON value without dropping information. */
5
+ function prepareJSON(value, column, row) {
6
+ if (value === null || value === undefined)
7
+ return null;
8
+ const active = new Set();
9
+ const fail = (path, message) => {
10
+ throw new Error(`Column ${JSON.stringify(column)}, row ${row}, ${path}: ${message}`);
11
+ };
12
+ function serialize(value, path) {
13
+ if (value === null)
14
+ return "null";
15
+ if (typeof value === "string" || typeof value === "boolean") {
16
+ return JSON.stringify(value);
17
+ }
18
+ if (typeof value === "number" && Number.isFinite(value)) {
19
+ return Object.is(value, -0) ? "-0.0" : JSON.stringify(value);
20
+ }
21
+ if (typeof value !== "object") {
22
+ return fail(path, "Expected a JSON value: finite numbers, strings, booleans, null, arrays, or plain objects.");
23
+ }
24
+ if (active.has(value)) {
25
+ return fail(path, "Cyclic JSON values are unsupported.");
26
+ }
27
+ if (active.size >= 100) {
28
+ return fail(path, "JSON values may nest at most 100 levels.");
29
+ }
30
+ const array = Array.isArray(value);
31
+ if (!array && Object.getPrototypeOf(value) !== Object.prototype &&
32
+ Object.getPrototypeOf(value) !== null) {
33
+ return fail(path, "Expected a plain JSON object; convert class instances to JSON values first.");
34
+ }
35
+ if (Object.getOwnPropertySymbols(value).length) {
36
+ return fail(path, "JSON cannot represent symbol keys.");
37
+ }
38
+ active.add(value);
39
+ try {
40
+ if (array) {
41
+ if (Object.keys(value).length !== value.length) {
42
+ return fail(path, "JSON arrays must be dense and have no extra properties.");
43
+ }
44
+ return `[${Array.from(value, (item, i) => serialize(item, `${path}[${i}]`)).join(",")}]`;
45
+ }
46
+ return `{${Object.entries(value).map(([key, item]) => `${JSON.stringify(key)}:${serialize(item, `${path}[${JSON.stringify(key)}]`)}`).join(",")}}`;
47
+ }
48
+ finally {
49
+ active.delete(value);
50
+ }
51
+ }
52
+ return serialize(value, "$");
53
+ }
@@ -1,14 +1,15 @@
1
1
  /**
2
2
  * Prints a formatted table to the console with support for word wrapping
3
- * within cells. Unlike `console.table()`, this function properly handles
4
- * multi-line content within cells, making it ideal for displaying data with
5
- * long text values.
3
+ * within headers and cells. Unlike `console.table()`, this function properly
4
+ * handles multi-line content, making it ideal for displaying data with long
5
+ * column names and text values.
6
6
  *
7
7
  * @param data - An array of objects representing the rows of the table. Each
8
8
  * object should have string keys.
9
9
  * @param options - Optional configuration for table rendering.
10
10
  * @param options.maxColumnWidth - The maximum width for any column (default:
11
- * `75`). Values exceeding this width will be wrapped at word boundaries.
11
+ * `75`). Headers and values exceeding this width will be wrapped at word
12
+ * boundaries.
12
13
  * @param options.minColumnWidth - The minimum width for any column (default:
13
14
  * `3`).
14
15
  * @param options.typesRowIndex - The index of a row that contains type