@bdkinc/knex-ibmi 0.5.3 → 0.5.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.
package/dist/index.d.mts CHANGED
@@ -44,6 +44,7 @@ declare enum SqlMethod {
44
44
  }
45
45
  declare class DB2Client extends knex.Client {
46
46
  private statementCaches;
47
+ private normalizeBigintToString;
47
48
  constructor(config: Knex.Config<DB2Config>);
48
49
  private safeStringify;
49
50
  _driver(): typeof odbc;
@@ -70,6 +71,9 @@ declare class DB2Client extends knex.Client {
70
71
  private executeSelectQuery;
71
72
  private executeStatementQuery;
72
73
  private isNoDataError;
74
+ private shouldNormalizeBigintValues;
75
+ private maybeNormalizeBigint;
76
+ private normalizeBigintValue;
73
77
  /**
74
78
  * Format statement response from ODBC driver
75
79
  * Handles special case for IDENTITY_VAL_LOCAL() function
@@ -201,6 +205,7 @@ interface DB2Config extends Knex.Config {
201
205
  preparedStatementCache?: boolean;
202
206
  preparedStatementCacheSize?: number;
203
207
  readUncommitted?: boolean;
208
+ normalizeBigintToString?: boolean;
204
209
  };
205
210
  }
206
211
  declare const DB2Dialect: typeof DB2Client;
package/dist/index.d.ts CHANGED
@@ -44,6 +44,7 @@ declare enum SqlMethod {
44
44
  }
45
45
  declare class DB2Client extends knex.Client {
46
46
  private statementCaches;
47
+ private normalizeBigintToString;
47
48
  constructor(config: Knex.Config<DB2Config>);
48
49
  private safeStringify;
49
50
  _driver(): typeof odbc;
@@ -70,6 +71,9 @@ declare class DB2Client extends knex.Client {
70
71
  private executeSelectQuery;
71
72
  private executeStatementQuery;
72
73
  private isNoDataError;
74
+ private shouldNormalizeBigintValues;
75
+ private maybeNormalizeBigint;
76
+ private normalizeBigintValue;
73
77
  /**
74
78
  * Format statement response from ODBC driver
75
79
  * Handles special case for IDENTITY_VAL_LOCAL() function
@@ -201,6 +205,7 @@ interface DB2Config extends Knex.Config {
201
205
  preparedStatementCache?: boolean;
202
206
  preparedStatementCacheSize?: number;
203
207
  readUncommitted?: boolean;
208
+ normalizeBigintToString?: boolean;
204
209
  };
205
210
  }
206
211
  declare const DB2Dialect: typeof DB2Client;
package/dist/index.js CHANGED
@@ -40,6 +40,7 @@ __export(index_exports, {
40
40
  });
41
41
  module.exports = __toCommonJS(index_exports);
42
42
  var import_node_process = __toESM(require("process"));
43
+ var import_node_buffer = require("buffer");
43
44
  var import_knex = __toESM(require("knex"));
44
45
  var import_odbc = __toESM(require("odbc"));
45
46
 
@@ -838,6 +839,7 @@ var DB2Client = class extends import_knex.default.Client {
838
839
  super(config);
839
840
  // Per-connection statement cache (WeakMap so it's GC'd with connections)
840
841
  __publicField(this, "statementCaches", /* @__PURE__ */ new WeakMap());
842
+ __publicField(this, "normalizeBigintToString");
841
843
  this.driverName = "odbc";
842
844
  if (this.dialect && !this.config.client) {
843
845
  this.printWarn(
@@ -863,6 +865,8 @@ var DB2Client = class extends import_knex.default.Client {
863
865
  if (config.useNullAsDefault) {
864
866
  this.valueForUndefined = null;
865
867
  }
868
+ const ibmiConfig = config?.ibmi;
869
+ this.normalizeBigintToString = ibmiConfig?.normalizeBigintToString !== false;
866
870
  }
867
871
  // Helper method to safely stringify objects that might have circular references
868
872
  safeStringify(obj, indent = 0) {
@@ -1143,7 +1147,8 @@ var DB2Client = class extends import_knex.default.Client {
1143
1147
  obj.bindings
1144
1148
  );
1145
1149
  if (rows) {
1146
- obj.response = { rows, rowCount: rows.length };
1150
+ const normalizedRows = this.maybeNormalizeBigint(rows);
1151
+ obj.response = { rows: normalizedRows, rowCount: normalizedRows.length };
1147
1152
  }
1148
1153
  }
1149
1154
  async executeStatementQuery(connection, obj) {
@@ -1214,6 +1219,44 @@ var DB2Client = class extends import_knex.default.Client {
1214
1219
  const msg = String(error?.message || error || "").toLowerCase();
1215
1220
  return msg.includes("02000") || msg.includes("no data") || msg.includes("no rows") || msg.includes("0 rows");
1216
1221
  }
1222
+ shouldNormalizeBigintValues() {
1223
+ return this.normalizeBigintToString;
1224
+ }
1225
+ maybeNormalizeBigint(value) {
1226
+ if (value === null || value === void 0) {
1227
+ return value;
1228
+ }
1229
+ if (!this.shouldNormalizeBigintValues()) {
1230
+ return value;
1231
+ }
1232
+ return this.normalizeBigintValue(value);
1233
+ }
1234
+ normalizeBigintValue(value, seen = /* @__PURE__ */ new WeakSet()) {
1235
+ if (typeof value === "bigint") {
1236
+ return value.toString();
1237
+ }
1238
+ if (Array.isArray(value)) {
1239
+ for (let i = 0; i < value.length; i++) {
1240
+ value[i] = this.normalizeBigintValue(value[i], seen);
1241
+ }
1242
+ return value;
1243
+ }
1244
+ if (value && typeof value === "object") {
1245
+ if (value instanceof Date || import_node_buffer.Buffer.isBuffer(value) || ArrayBuffer.isView(value)) {
1246
+ return value;
1247
+ }
1248
+ const obj = value;
1249
+ if (seen.has(obj)) {
1250
+ return value;
1251
+ }
1252
+ seen.add(obj);
1253
+ for (const key of Object.keys(obj)) {
1254
+ obj[key] = this.normalizeBigintValue(obj[key], seen);
1255
+ }
1256
+ return value;
1257
+ }
1258
+ return value;
1259
+ }
1217
1260
  /**
1218
1261
  * Format statement response from ODBC driver
1219
1262
  * Handles special case for IDENTITY_VAL_LOCAL() function
@@ -1221,16 +1264,18 @@ var DB2Client = class extends import_knex.default.Client {
1221
1264
  formatStatementResponse(result) {
1222
1265
  const isIdentityQuery = result.statement?.includes("IDENTITY_VAL_LOCAL()");
1223
1266
  if (isIdentityQuery && result.columns?.length > 0) {
1267
+ const identityRows = result.map(
1268
+ (row) => row[result.columns[0].name]
1269
+ );
1270
+ const normalizedIdentityRows = this.maybeNormalizeBigint(identityRows);
1224
1271
  return {
1225
- rows: result.map(
1226
- (row) => row[result.columns[0].name]
1227
- ),
1272
+ rows: normalizedIdentityRows,
1228
1273
  rowCount: result.count
1229
1274
  };
1230
1275
  }
1231
1276
  const rowCount = typeof result?.count === "number" ? result.count : 0;
1232
1277
  return {
1233
- rows: result,
1278
+ rows: this.maybeNormalizeBigint(result),
1234
1279
  rowCount
1235
1280
  };
1236
1281
  }
@@ -1302,7 +1347,7 @@ var DB2Client = class extends import_knex.default.Client {
1302
1347
  return;
1303
1348
  }
1304
1349
  if (!cursor.noData) {
1305
- this.push(result);
1350
+ this.push(parentThis.maybeNormalizeBigint(result));
1306
1351
  } else {
1307
1352
  isClosed = true;
1308
1353
  cursor.close((closeError) => {
@@ -1310,7 +1355,7 @@ var DB2Client = class extends import_knex.default.Client {
1310
1355
  parentThis.printError(parentThis.safeStringify(closeError, 2));
1311
1356
  }
1312
1357
  if (result) {
1313
- this.push(result);
1358
+ this.push(parentThis.maybeNormalizeBigint(result));
1314
1359
  }
1315
1360
  this.push(null);
1316
1361
  });
@@ -1374,6 +1419,9 @@ var DB2Client = class extends import_knex.default.Client {
1374
1419
  throw wrappedError;
1375
1420
  }
1376
1421
  }
1422
+ if (response) {
1423
+ this.maybeNormalizeBigint(response.rows);
1424
+ }
1377
1425
  const validationResult = this.validateResponse(obj);
1378
1426
  if (validationResult !== null) return validationResult;
1379
1427
  return this.processSqlMethod(obj);