@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 +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +55 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +55 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -6,6 +6,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
6
6
|
|
|
7
7
|
// src/index.ts
|
|
8
8
|
import process from "process";
|
|
9
|
+
import { Buffer as Buffer2 } from "buffer";
|
|
9
10
|
import knex from "knex";
|
|
10
11
|
import odbc from "odbc";
|
|
11
12
|
|
|
@@ -804,6 +805,7 @@ var DB2Client = class extends knex.Client {
|
|
|
804
805
|
super(config);
|
|
805
806
|
// Per-connection statement cache (WeakMap so it's GC'd with connections)
|
|
806
807
|
__publicField(this, "statementCaches", /* @__PURE__ */ new WeakMap());
|
|
808
|
+
__publicField(this, "normalizeBigintToString");
|
|
807
809
|
this.driverName = "odbc";
|
|
808
810
|
if (this.dialect && !this.config.client) {
|
|
809
811
|
this.printWarn(
|
|
@@ -829,6 +831,8 @@ var DB2Client = class extends knex.Client {
|
|
|
829
831
|
if (config.useNullAsDefault) {
|
|
830
832
|
this.valueForUndefined = null;
|
|
831
833
|
}
|
|
834
|
+
const ibmiConfig = config?.ibmi;
|
|
835
|
+
this.normalizeBigintToString = ibmiConfig?.normalizeBigintToString !== false;
|
|
832
836
|
}
|
|
833
837
|
// Helper method to safely stringify objects that might have circular references
|
|
834
838
|
safeStringify(obj, indent = 0) {
|
|
@@ -1109,7 +1113,8 @@ var DB2Client = class extends knex.Client {
|
|
|
1109
1113
|
obj.bindings
|
|
1110
1114
|
);
|
|
1111
1115
|
if (rows) {
|
|
1112
|
-
|
|
1116
|
+
const normalizedRows = this.maybeNormalizeBigint(rows);
|
|
1117
|
+
obj.response = { rows: normalizedRows, rowCount: normalizedRows.length };
|
|
1113
1118
|
}
|
|
1114
1119
|
}
|
|
1115
1120
|
async executeStatementQuery(connection, obj) {
|
|
@@ -1180,6 +1185,44 @@ var DB2Client = class extends knex.Client {
|
|
|
1180
1185
|
const msg = String(error?.message || error || "").toLowerCase();
|
|
1181
1186
|
return msg.includes("02000") || msg.includes("no data") || msg.includes("no rows") || msg.includes("0 rows");
|
|
1182
1187
|
}
|
|
1188
|
+
shouldNormalizeBigintValues() {
|
|
1189
|
+
return this.normalizeBigintToString;
|
|
1190
|
+
}
|
|
1191
|
+
maybeNormalizeBigint(value) {
|
|
1192
|
+
if (value === null || value === void 0) {
|
|
1193
|
+
return value;
|
|
1194
|
+
}
|
|
1195
|
+
if (!this.shouldNormalizeBigintValues()) {
|
|
1196
|
+
return value;
|
|
1197
|
+
}
|
|
1198
|
+
return this.normalizeBigintValue(value);
|
|
1199
|
+
}
|
|
1200
|
+
normalizeBigintValue(value, seen = /* @__PURE__ */ new WeakSet()) {
|
|
1201
|
+
if (typeof value === "bigint") {
|
|
1202
|
+
return value.toString();
|
|
1203
|
+
}
|
|
1204
|
+
if (Array.isArray(value)) {
|
|
1205
|
+
for (let i = 0; i < value.length; i++) {
|
|
1206
|
+
value[i] = this.normalizeBigintValue(value[i], seen);
|
|
1207
|
+
}
|
|
1208
|
+
return value;
|
|
1209
|
+
}
|
|
1210
|
+
if (value && typeof value === "object") {
|
|
1211
|
+
if (value instanceof Date || Buffer2.isBuffer(value) || ArrayBuffer.isView(value)) {
|
|
1212
|
+
return value;
|
|
1213
|
+
}
|
|
1214
|
+
const obj = value;
|
|
1215
|
+
if (seen.has(obj)) {
|
|
1216
|
+
return value;
|
|
1217
|
+
}
|
|
1218
|
+
seen.add(obj);
|
|
1219
|
+
for (const key of Object.keys(obj)) {
|
|
1220
|
+
obj[key] = this.normalizeBigintValue(obj[key], seen);
|
|
1221
|
+
}
|
|
1222
|
+
return value;
|
|
1223
|
+
}
|
|
1224
|
+
return value;
|
|
1225
|
+
}
|
|
1183
1226
|
/**
|
|
1184
1227
|
* Format statement response from ODBC driver
|
|
1185
1228
|
* Handles special case for IDENTITY_VAL_LOCAL() function
|
|
@@ -1187,16 +1230,18 @@ var DB2Client = class extends knex.Client {
|
|
|
1187
1230
|
formatStatementResponse(result) {
|
|
1188
1231
|
const isIdentityQuery = result.statement?.includes("IDENTITY_VAL_LOCAL()");
|
|
1189
1232
|
if (isIdentityQuery && result.columns?.length > 0) {
|
|
1233
|
+
const identityRows = result.map(
|
|
1234
|
+
(row) => row[result.columns[0].name]
|
|
1235
|
+
);
|
|
1236
|
+
const normalizedIdentityRows = this.maybeNormalizeBigint(identityRows);
|
|
1190
1237
|
return {
|
|
1191
|
-
rows:
|
|
1192
|
-
(row) => row[result.columns[0].name]
|
|
1193
|
-
),
|
|
1238
|
+
rows: normalizedIdentityRows,
|
|
1194
1239
|
rowCount: result.count
|
|
1195
1240
|
};
|
|
1196
1241
|
}
|
|
1197
1242
|
const rowCount = typeof result?.count === "number" ? result.count : 0;
|
|
1198
1243
|
return {
|
|
1199
|
-
rows: result,
|
|
1244
|
+
rows: this.maybeNormalizeBigint(result),
|
|
1200
1245
|
rowCount
|
|
1201
1246
|
};
|
|
1202
1247
|
}
|
|
@@ -1268,7 +1313,7 @@ var DB2Client = class extends knex.Client {
|
|
|
1268
1313
|
return;
|
|
1269
1314
|
}
|
|
1270
1315
|
if (!cursor.noData) {
|
|
1271
|
-
this.push(result);
|
|
1316
|
+
this.push(parentThis.maybeNormalizeBigint(result));
|
|
1272
1317
|
} else {
|
|
1273
1318
|
isClosed = true;
|
|
1274
1319
|
cursor.close((closeError) => {
|
|
@@ -1276,7 +1321,7 @@ var DB2Client = class extends knex.Client {
|
|
|
1276
1321
|
parentThis.printError(parentThis.safeStringify(closeError, 2));
|
|
1277
1322
|
}
|
|
1278
1323
|
if (result) {
|
|
1279
|
-
this.push(result);
|
|
1324
|
+
this.push(parentThis.maybeNormalizeBigint(result));
|
|
1280
1325
|
}
|
|
1281
1326
|
this.push(null);
|
|
1282
1327
|
});
|
|
@@ -1340,6 +1385,9 @@ var DB2Client = class extends knex.Client {
|
|
|
1340
1385
|
throw wrappedError;
|
|
1341
1386
|
}
|
|
1342
1387
|
}
|
|
1388
|
+
if (response) {
|
|
1389
|
+
this.maybeNormalizeBigint(response.rows);
|
|
1390
|
+
}
|
|
1343
1391
|
const validationResult = this.validateResponse(obj);
|
|
1344
1392
|
if (validationResult !== null) return validationResult;
|
|
1345
1393
|
return this.processSqlMethod(obj);
|