@use-tusk/drift-node-sdk 0.1.15 → 0.1.16

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.cjs CHANGED
@@ -11810,6 +11810,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
11810
11810
  const inputValue = {
11811
11811
  text: queryConfig.text,
11812
11812
  values: queryConfig.values || [],
11813
+ rowMode: queryConfig.rowMode,
11813
11814
  clientType
11814
11815
  };
11815
11816
  if (self.mode === TuskDriftMode.REPLAY) {
@@ -11924,6 +11925,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
11924
11925
  if (typeof firstArg === "object" && firstArg.text) return {
11925
11926
  text: firstArg.text,
11926
11927
  values: firstArg.values,
11928
+ rowMode: firstArg.rowMode,
11927
11929
  callback: firstArg.callback || (typeof args[1] === "function" ? args[1] : void 0)
11928
11930
  };
11929
11931
  return null;
@@ -12024,7 +12026,7 @@ var PgInstrumentation = class extends TdInstrumentationBase {
12024
12026
  logger.warn(`[PgInstrumentation] No mock data found for PG query: ${queryText}`);
12025
12027
  throw new Error(`[PgInstrumentation] No mock data found for PG query: ${queryText}`);
12026
12028
  }
12027
- const processedResult = this.convertPostgresTypes(mockData.result);
12029
+ const processedResult = this.convertPostgresTypes(mockData.result, inputValue.rowMode);
12028
12030
  if (queryConfig.callback) {
12029
12031
  process.nextTick(() => {
12030
12032
  queryConfig.callback(null, processedResult);
@@ -12033,35 +12035,56 @@ var PgInstrumentation = class extends TdInstrumentationBase {
12033
12035
  } else return Promise.resolve(processedResult);
12034
12036
  }
12035
12037
  /**
12038
+ * Convert a single value based on its PostgreSQL data type.
12039
+ *
12040
+ * Reference for data type IDs: https://jdbc.postgresql.org/documentation/publicapi/constant-values.html
12041
+ */
12042
+ convertPostgresValue(value, dataTypeID) {
12043
+ if (value === null || value === void 0) return value;
12044
+ switch (dataTypeID) {
12045
+ case 1184:
12046
+ case 1114:
12047
+ case 1082:
12048
+ if (typeof value === "string") return new Date(value);
12049
+ break;
12050
+ case 1083:
12051
+ case 1266: break;
12052
+ default: break;
12053
+ }
12054
+ return value;
12055
+ }
12056
+ /**
12036
12057
  * Convert PostgreSQL string values back to appropriate JavaScript types
12037
12058
  * based on field metadata from the recorded response.
12038
12059
  *
12039
12060
  * Reference for data type IDs: https://jdbc.postgresql.org/documentation/publicapi/constant-values.html
12040
12061
  */
12041
- convertPostgresTypes(result) {
12062
+ convertPostgresTypes(result, rowMode) {
12042
12063
  if (!result || !result.fields || !result.rows) return result;
12064
+ if (rowMode === "array") {
12065
+ const convertedRows$1 = result.rows.map((row) => {
12066
+ if (!Array.isArray(row)) return row;
12067
+ return row.map((value, index) => {
12068
+ const field = result.fields[index];
12069
+ if (!field) return value;
12070
+ return this.convertPostgresValue(value, field.dataTypeID);
12071
+ });
12072
+ });
12073
+ return {
12074
+ ...result,
12075
+ rows: convertedRows$1
12076
+ };
12077
+ }
12043
12078
  const fieldTypeMap = {};
12044
12079
  result.fields.forEach((field) => {
12045
12080
  fieldTypeMap[field.name] = field.dataTypeID;
12046
12081
  });
12047
- const convertedRows = result.rows.map((row, rowIndex) => {
12082
+ const convertedRows = result.rows.map((row) => {
12048
12083
  const convertedRow = { ...row };
12049
12084
  Object.keys(row).forEach((fieldName) => {
12050
12085
  const dataTypeID = fieldTypeMap[fieldName];
12051
12086
  const value = row[fieldName];
12052
- if (value === null || value === void 0) return;
12053
- switch (dataTypeID) {
12054
- case 1184:
12055
- case 1114:
12056
- if (typeof value === "string") convertedRow[fieldName] = new Date(value);
12057
- break;
12058
- case 1082:
12059
- if (typeof value === "string") convertedRow[fieldName] = new Date(value);
12060
- break;
12061
- case 1083:
12062
- case 1266: break;
12063
- default: break;
12064
- }
12087
+ convertedRow[fieldName] = this.convertPostgresValue(value, dataTypeID);
12065
12088
  });
12066
12089
  return convertedRow;
12067
12090
  });
@@ -13289,6 +13312,12 @@ var MysqlInstrumentation = class extends TdInstrumentationBase {
13289
13312
  logger.debug(`[MysqlInstrumentation] Wrapped Connection.prototype.resume`);
13290
13313
  }
13291
13314
  }
13315
+ if (ConnectionClass.prototype && ConnectionClass.prototype.destroy) {
13316
+ if (!isWrapped$1(ConnectionClass.prototype.destroy)) {
13317
+ this._wrap(ConnectionClass.prototype, "destroy", this._getDestroyPatchFn());
13318
+ logger.debug(`[MysqlInstrumentation] Wrapped Connection.prototype.destroy`);
13319
+ }
13320
+ }
13292
13321
  this.markModuleAsPatched(ConnectionClass);
13293
13322
  logger.debug(`[MysqlInstrumentation] Connection class patching complete`);
13294
13323
  return ConnectionClass;
@@ -13703,6 +13732,19 @@ var MysqlInstrumentation = class extends TdInstrumentationBase {
13703
13732
  };
13704
13733
  }
13705
13734
  /**
13735
+ * Get wrapper function for destroy method
13736
+ */
13737
+ _getDestroyPatchFn() {
13738
+ const self = this;
13739
+ return (originalDestroy) => {
13740
+ return function destroy() {
13741
+ if (self.mode === TuskDriftMode.REPLAY) return;
13742
+ else if (self.mode === TuskDriftMode.RECORD) return originalDestroy.apply(this, arguments);
13743
+ else return originalDestroy.apply(this, arguments);
13744
+ };
13745
+ };
13746
+ }
13747
+ /**
13706
13748
  * Get wrapper function for Pool.end method
13707
13749
  */
13708
13750
  _getPoolEndPatchFn() {
@@ -32015,7 +32057,7 @@ var require_src = /* @__PURE__ */ __commonJS({ "node_modules/@opentelemetry/sdk-
32015
32057
  //#endregion
32016
32058
  //#region package.json
32017
32059
  var import_src$1 = /* @__PURE__ */ __toESM(require_src(), 1);
32018
- var version = "0.1.15";
32060
+ var version = "0.1.16";
32019
32061
 
32020
32062
  //#endregion
32021
32063
  //#region src/version.ts