@saptools/cf-hana 0.1.5 → 0.1.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.
package/dist/index.js CHANGED
@@ -510,7 +510,7 @@ async function listColumns(connection, schema, table) {
510
510
  }
511
511
 
512
512
  // src/config.ts
513
- var CLI_VERSION = "0.1.5";
513
+ var CLI_VERSION = "0.1.6";
514
514
  var ENV_PREFIX = "CF_HANA";
515
515
  var DEFAULT_QUERY_TIMEOUT_MS = 3e4;
516
516
  var DEFAULT_CONNECT_TIMEOUT_MS = 3e4;
@@ -629,7 +629,13 @@ function toConnectionTarget(binding, role) {
629
629
  }
630
630
 
631
631
  // src/driver/fake.ts
632
+ import { appendFile } from "fs/promises";
632
633
  function fakeExec(sql) {
634
+ const kind = classifyStatement(sql);
635
+ const forcedFailure = readEnv(envName("FAKE_FAIL_STATEMENT"))?.toLowerCase();
636
+ if (forcedFailure === kind) {
637
+ throw new Error(`fake driver forced ${kind.toUpperCase()} failure`);
638
+ }
633
639
  if (sql.toUpperCase().includes("DUMMY")) {
634
640
  return {
635
641
  rows: [{ "1": 1 }],
@@ -637,7 +643,6 @@ function fakeExec(sql) {
637
643
  affectedRows: 0
638
644
  };
639
645
  }
640
- const kind = classifyStatement(sql);
641
646
  if (kind === "select") {
642
647
  return {
643
648
  rows: [
@@ -656,10 +661,23 @@ function fakeExec(sql) {
656
661
  }
657
662
  return { rows: [], columns: [], affectedRows: 0 };
658
663
  }
664
+ async function traceFakeExec(sql, params) {
665
+ const tracePath = readEnv(envName("FAKE_TRACE_FILE"));
666
+ if (tracePath === void 0) {
667
+ return;
668
+ }
669
+ const entry = { sql, paramCount: params.length };
670
+ await appendFile(tracePath, `${JSON.stringify(entry)}
671
+ `, {
672
+ encoding: "utf8",
673
+ mode: 384
674
+ });
675
+ }
659
676
  var FakeConnection = class {
660
677
  closed = false;
661
- exec(sql, _params) {
662
- return Promise.resolve(fakeExec(sql));
678
+ async exec(sql, params) {
679
+ await traceFakeExec(sql, params);
680
+ return fakeExec(sql);
663
681
  }
664
682
  setAutoCommit(_enabled) {
665
683
  return Promise.resolve();
@@ -933,7 +951,7 @@ function createDriver(name) {
933
951
  }
934
952
 
935
953
  // src/history.ts
936
- import { appendFile, mkdir as mkdir2, readdir, rm } from "fs/promises";
954
+ import { appendFile as appendFile2, mkdir as mkdir2, readdir, rm } from "fs/promises";
937
955
  import { homedir as homedir2 } from "os";
938
956
  import { join as join2 } from "path";
939
957
  var SAPTOOLS_DIR_NAME2 = ".saptools";
@@ -995,7 +1013,7 @@ async function appendSqlHistory(input, options = {}) {
995
1013
  ...input
996
1014
  };
997
1015
  await mkdir2(historyDir, { recursive: true, mode: 448 });
998
- await appendFile(sqlHistoryFilePath(now, options.saptoolsRoot), `${JSON.stringify(entry)}
1016
+ await appendFile2(sqlHistoryFilePath(now, options.saptoolsRoot), `${JSON.stringify(entry)}
999
1017
  `, {
1000
1018
  encoding: "utf8",
1001
1019
  mode: 384