@malloydata/db-duckdb 0.0.326 → 0.0.327

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.
@@ -179,7 +179,7 @@ class DuckDBConnection extends duckdb_common_1.DuckDBCommon {
179
179
  reject(err);
180
180
  }
181
181
  else {
182
- rows = processBigInts(rows);
182
+ // rows = processBigInts(rows);
183
183
  resolve({
184
184
  rows,
185
185
  totalRows: rows.length,
@@ -211,7 +211,7 @@ class DuckDBConnection extends duckdb_common_1.DuckDBCommon {
211
211
  break;
212
212
  }
213
213
  index++;
214
- yield processBigInts(row);
214
+ yield row;
215
215
  }
216
216
  }
217
217
  async createHash(sqlCommand) {
@@ -230,12 +230,4 @@ class DuckDBConnection extends duckdb_common_1.DuckDBCommon {
230
230
  }
231
231
  exports.DuckDBConnection = DuckDBConnection;
232
232
  DuckDBConnection.activeDBs = {};
233
- function processBigInts(data) {
234
- return JSON.parse(JSON.stringify(data, (_key, value) => {
235
- if (typeof value === 'bigint') {
236
- return Number(value);
237
- }
238
- return value;
239
- }));
240
- }
241
233
  //# sourceMappingURL=duckdb_connection.js.map
@@ -83,7 +83,13 @@ const unwrapArrow = (value) => {
83
83
  return value;
84
84
  }
85
85
  else if (typeof value === 'bigint') {
86
- return Number(value);
86
+ // Safe bigints can be represented as numbers without precision loss
87
+ if (value >= BigInt(Number.MIN_SAFE_INTEGER) &&
88
+ value <= BigInt(Number.MAX_SAFE_INTEGER)) {
89
+ return Number(value);
90
+ }
91
+ // Large bigints stay as strings to preserve precision
92
+ return value.toString();
87
93
  }
88
94
  else if (typeof value === 'object') {
89
95
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -91,9 +97,27 @@ const unwrapArrow = (value) => {
91
97
  // DecimalBigNums appear as Uint32Arrays, but can be identified
92
98
  // because they have a Symbol.toPrimitive method
93
99
  if (obj[Symbol.toPrimitive]) {
94
- // There seems to be a bug in [Symbol.toPrimitive]("number") so
95
- // convert to string first and then to number.
96
- return Number(obj[Symbol.toPrimitive]());
100
+ const primitiveValue = obj[Symbol.toPrimitive]();
101
+ if (typeof primitiveValue === 'string') {
102
+ const num = Number(primitiveValue);
103
+ // Safe integers can be represented as numbers without precision loss
104
+ if (Number.isSafeInteger(num)) {
105
+ return num;
106
+ }
107
+ // Large numbers stay as strings to preserve precision (HUGEINT)
108
+ return primitiveValue;
109
+ }
110
+ if (typeof primitiveValue === 'number') {
111
+ return primitiveValue;
112
+ }
113
+ if (typeof primitiveValue === 'bigint') {
114
+ if (primitiveValue >= BigInt(Number.MIN_SAFE_INTEGER) &&
115
+ primitiveValue <= BigInt(Number.MAX_SAFE_INTEGER)) {
116
+ return Number(primitiveValue);
117
+ }
118
+ return primitiveValue.toString();
119
+ }
120
+ return primitiveValue.toString();
97
121
  }
98
122
  else if (Array.isArray(value)) {
99
123
  return value.map(exports.unwrapArrow);
@@ -98,7 +98,8 @@ function unwrapMotherDuck(value) {
98
98
  }
99
99
  }
100
100
  else if (typeof value === 'bigint') {
101
- result = Number(value);
101
+ // Preserve precision by converting to string
102
+ result = value.toString();
102
103
  }
103
104
  else {
104
105
  result = value;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/db-duckdb",
3
- "version": "0.0.326",
3
+ "version": "0.0.327",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -39,13 +39,13 @@
39
39
  "lint-fix": "eslint '**/*.ts{,x}' --fix",
40
40
  "test": "jest --config=../../jest.config.js",
41
41
  "build": "tsc --build",
42
- "clean": "tsc --build --clean",
42
+ "clean": "tsc --build --clean && rm -f tsconfig.tsbuildinfo",
43
43
  "malloyc": "ts-node ../../scripts/malloy-to-json",
44
44
  "prepublishOnly": "npm run build"
45
45
  },
46
46
  "dependencies": {
47
47
  "@duckdb/duckdb-wasm": "1.29.1-dev132.0",
48
- "@malloydata/malloy": "0.0.326",
48
+ "@malloydata/malloy": "0.0.327",
49
49
  "@motherduck/wasm-client": "^0.6.6",
50
50
  "apache-arrow": "^17.0.0",
51
51
  "duckdb": "1.3.4",