@youtyan/code-viewer 0.5.0 → 0.5.1

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.
@@ -146,14 +146,22 @@ function createJsonFileStore(options) {
146
146
  async function load(root) {
147
147
  const pendingWrite = queues.get(options.filePath(root));
148
148
  if (pendingWrite)
149
- await pendingWrite.catch(() => {});
149
+ await pendingWrite.catch(() => {
150
+ return;
151
+ });
150
152
  return loadUnqueued(root);
151
153
  }
152
154
  async function save(root, state) {
153
155
  const file = options.filePath(root);
154
156
  const previous = queues.get(file) ?? Promise.resolve();
155
- const run = previous.catch(() => {}).then(() => saveUnqueued(root, state));
156
- const queued = run.then(() => {}, () => {});
157
+ const run = previous.catch(() => {
158
+ return;
159
+ }).then(() => saveUnqueued(root, state));
160
+ const queued = run.then(() => {
161
+ return;
162
+ }, () => {
163
+ return;
164
+ });
157
165
  queues.set(file, queued);
158
166
  try {
159
167
  await run;
@@ -165,13 +173,19 @@ function createJsonFileStore(options) {
165
173
  async function update(root, updater) {
166
174
  const file = options.filePath(root);
167
175
  const previous = queues.get(file) ?? Promise.resolve();
168
- const run = previous.catch(() => {}).then(async () => {
176
+ const run = previous.catch(() => {
177
+ return;
178
+ }).then(async () => {
169
179
  const current = await loadUnqueued(root);
170
180
  const updated = await updater(current);
171
181
  await saveUnqueued(root, updated.state);
172
182
  return updated.result;
173
183
  });
174
- const queued = run.then(() => {}, () => {});
184
+ const queued = run.then(() => {
185
+ return;
186
+ }, () => {
187
+ return;
188
+ });
175
189
  queues.set(file, queued);
176
190
  try {
177
191
  return await run;
@@ -7047,7 +7061,9 @@ function createTableMetaCache(now = () => Date.now()) {
7047
7061
  };
7048
7062
  }
7049
7063
  function observeBackgroundRejection(promise) {
7050
- promise.catch(() => {});
7064
+ promise.catch(() => {
7065
+ return;
7066
+ });
7051
7067
  return promise;
7052
7068
  }
7053
7069
  function createDockerAdapter(config) {
@@ -8021,7 +8037,9 @@ async function getConnection(resolvedPath) {
8021
8037
  adapter,
8022
8038
  path: resolvedPath,
8023
8039
  lastUsed: Date.now(),
8024
- timer: setTimeout(() => {}, 0)
8040
+ timer: setTimeout(() => {
8041
+ return;
8042
+ }, 0)
8025
8043
  };
8026
8044
  pool.set(resolvedPath, entry);
8027
8045
  scheduleEviction(resolvedPath, entry);
@@ -8574,13 +8592,60 @@ function createDockerAdapterCache(maxEntries = DEFAULT_MAX_DOCKER_ADAPTER_CACHE,
8574
8592
  }
8575
8593
  };
8576
8594
  }
8595
+ async function extractErrorReason(res) {
8596
+ if (res.status < 400)
8597
+ return "";
8598
+ const ctype = res.headers.get("content-type") ?? "";
8599
+ if (!ctype.startsWith("text/") && !ctype.includes("json"))
8600
+ return "";
8601
+ let cloned;
8602
+ try {
8603
+ cloned = res.clone();
8604
+ } catch {
8605
+ return "";
8606
+ }
8607
+ try {
8608
+ const body = await cloned.text();
8609
+ if (!body)
8610
+ return "";
8611
+ const trimmed = body.replace(/\s+/g, " ").trim();
8612
+ if (!trimmed)
8613
+ return "";
8614
+ return trimmed.length > MAX_LOGGED_ERROR_BODY ? `${trimmed.slice(0, MAX_LOGGED_ERROR_BODY)}...` : trimmed;
8615
+ } catch {
8616
+ return "";
8617
+ }
8618
+ }
8619
+ function enqueueLogLine(work) {
8620
+ logQueue = logQueue.then(work, work);
8621
+ }
8622
+ function logResponseWithReason(prefix, req, url, res, startMs, opts = {}) {
8623
+ const ms = Date.now() - startMs;
8624
+ const qsLen = opts.qsLen ?? 0;
8625
+ const qs = qsLen > 0 && url.search ? url.search.slice(0, qsLen) : "";
8626
+ const head = `${prefix} ${req.method} ${url.pathname}${qs} ${res.status} ${ms}ms`;
8627
+ if (res.status < 400) {
8628
+ enqueueLogLine(async () => {
8629
+ console.log(head);
8630
+ });
8631
+ return;
8632
+ }
8633
+ let cloned = null;
8634
+ try {
8635
+ cloned = res.clone();
8636
+ } catch {}
8637
+ enqueueLogLine(async () => {
8638
+ const reason = cloned ? await extractErrorReason(cloned) : "";
8639
+ if (reason)
8640
+ console.warn(`${head} :: ${reason}`);
8641
+ else
8642
+ console.warn(head);
8643
+ });
8644
+ }
8577
8645
  function createQueryStrippedLogger(prefix, req, url) {
8578
- const path = url.pathname;
8579
8646
  const start = Date.now();
8580
- const method = req.method;
8581
8647
  return (res) => {
8582
- const ms = Date.now() - start;
8583
- console.log(`[code-viewer] ${prefix} ${method} ${path} ${res.status} ${ms}ms`);
8648
+ logResponseWithReason(`[code-viewer] ${prefix}`, req, url, res, start);
8584
8649
  return res;
8585
8650
  };
8586
8651
  }
@@ -8734,11 +8799,12 @@ function handleError(prefix, action, err) {
8734
8799
  }
8735
8800
  return textError(`failed to ${action}: ${message}`, 500);
8736
8801
  }
8737
- var DEFAULT_MAX_DOCKER_ADAPTER_CACHE = 8, DEFAULT_DOCKER_ADAPTER_IDLE_MS;
8802
+ var DEFAULT_MAX_DOCKER_ADAPTER_CACHE = 8, DEFAULT_DOCKER_ADAPTER_IDLE_MS, MAX_LOGGED_ERROR_BODY = 500, logQueue;
8738
8803
  var init_handle_shared = __esm(() => {
8739
8804
  init_docker_utils();
8740
8805
  init_discovery();
8741
8806
  DEFAULT_DOCKER_ADAPTER_IDLE_MS = 5 * 60 * 1000;
8807
+ logQueue = Promise.resolve();
8742
8808
  });
8743
8809
 
8744
8810
  // web-src/server/database/handle-elasticsearch.ts
@@ -9943,7 +10009,9 @@ function guardedS3Transport(signal, operation, deadline) {
9943
10009
  let timedOut = false;
9944
10010
  let settled = false;
9945
10011
  let timer;
9946
- let cleanupParent = () => {};
10012
+ let cleanupParent = () => {
10013
+ return;
10014
+ };
9947
10015
  const abort = (err, reject) => {
9948
10016
  if (settled)
9949
10017
  return;
@@ -9988,7 +10056,9 @@ function guardedS3Transport(signal, operation, deadline) {
9988
10056
  async function readStreamChunkWithTimeout(reader, signal, deadline) {
9989
10057
  return guardedS3Transport(signal, (transportSignal) => {
9990
10058
  const cancelRead = () => {
9991
- reader.cancel(transportSignal.reason).catch(() => {});
10059
+ reader.cancel(transportSignal.reason).catch(() => {
10060
+ return;
10061
+ });
9992
10062
  };
9993
10063
  if (transportSignal.aborted) {
9994
10064
  cancelRead();
@@ -12643,16 +12713,12 @@ async function handleDatabaseRoute(req, url, cwd, omitDirNames, sideEffectAllowe
12643
12713
  const { handleS3Route: handleS3Route2 } = await Promise.resolve().then(() => (init_handle_s3(), exports_handle_s3));
12644
12714
  return handleS3Route2(req, url, cwd, sideEffectAllowed, omitDirNames);
12645
12715
  }
12646
- const path = url.pathname;
12647
12716
  const start = Date.now();
12648
12717
  const method = req.method;
12649
- const qs = url.search ? url.search.slice(0, 120) : "";
12650
- const log = (status) => {
12651
- const ms = Date.now() - start;
12652
- console.log(`[code-viewer] ${method} ${path}${qs} ${status} ${ms}ms`);
12653
- };
12654
12718
  const wrapResponse = (res) => {
12655
- log(res.status);
12719
+ logResponseWithReason("[code-viewer]", req, url, res, start, {
12720
+ qsLen: 120
12721
+ });
12656
12722
  return res;
12657
12723
  };
12658
12724
  return dispatchRoutes(req, url, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@youtyan/code-viewer",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "Local browser-based code and git diff viewer",
5
5
  "type": "module",
6
6
  "bin": {
package/web/app.js CHANGED
@@ -871,7 +871,9 @@
871
871
  emit();
872
872
  const item = deps.items()[clamped];
873
873
  if (item)
874
- deps.jump(item.entryId).catch(() => {});
874
+ deps.jump(item.entryId).catch(() => {
875
+ return;
876
+ });
875
877
  }
876
878
  }
877
879
  function jumpTo(at) {
@@ -10922,7 +10924,9 @@ ${frontmatter.yaml}
10922
10924
  setTimeout(() => {
10923
10925
  copyBtn.textContent = text2().er.copyMermaid;
10924
10926
  }, 1500);
10925
- }, () => {});
10927
+ }, () => {
10928
+ return;
10929
+ });
10926
10930
  }
10927
10931
  });
10928
10932
  let dragState = null;
@@ -11774,7 +11778,9 @@ ${frontmatter.yaml}
11774
11778
  setTimeout(() => {
11775
11779
  copyBtn.textContent = text2().history.copySql;
11776
11780
  }, 1500);
11777
- }, () => {});
11781
+ }, () => {
11782
+ return;
11783
+ });
11778
11784
  });
11779
11785
  const deleteBtn = document.createElement("button");
11780
11786
  deleteBtn.className = "db-btn db-query-history-danger";
@@ -12624,7 +12630,9 @@ ${frontmatter.yaml}
12624
12630
  keyList.innerHTML = "";
12625
12631
  keyRowsByName.clear();
12626
12632
  setPaneEmpty(mainPane, text2().redis.selectKey);
12627
- const valuePromise = initial.key ? selectKey(initial.key).catch(() => {}) : null;
12633
+ const valuePromise = initial.key ? selectKey(initial.key).catch(() => {
12634
+ return;
12635
+ }) : null;
12628
12636
  await loadKeys(false);
12629
12637
  if (currentDbId !== dbId)
12630
12638
  return;
@@ -14430,7 +14438,9 @@ ${entry.message}` : entry.detail ?? entry.message ?? "";
14430
14438
  setTimeout(() => {
14431
14439
  copyBtn.textContent = text2().sessionLog.copy;
14432
14440
  }, 1200);
14433
- }, () => {});
14441
+ }, () => {
14442
+ return;
14443
+ });
14434
14444
  });
14435
14445
  actions.append(useBtn, copyBtn);
14436
14446
  detailCol.appendChild(actions);
@@ -18576,7 +18586,9 @@ ${entry.message}` : entry.detail ?? entry.message ?? "";
18576
18586
  if (!res.ok)
18577
18587
  return;
18578
18588
  applyDbUiState(await res.json());
18579
- }).catch(() => {});
18589
+ }).catch(() => {
18590
+ return;
18591
+ });
18580
18592
  return dbUiLoadPromise;
18581
18593
  }
18582
18594
  function getColumnWidths(dbId, table2) {
@@ -18594,7 +18606,9 @@ ${entry.message}` : entry.detail ?? entry.message ?? "";
18594
18606
  method: "PATCH",
18595
18607
  headers: actionHeaders(),
18596
18608
  body: JSON.stringify({ columnWidths: { [dbId]: { [table2]: widths } } })
18597
- }).catch(() => {});
18609
+ }).catch(() => {
18610
+ return;
18611
+ });
18598
18612
  }
18599
18613
  function getExpandedTables(scopeKey) {
18600
18614
  return [...dbUiState.expandedTables?.[scopeKey] || []];
@@ -18626,7 +18640,9 @@ ${entry.message}` : entry.detail ?? entry.message ?? "";
18626
18640
  [scopeKey]: nextTables.length > 0 ? nextTables : null
18627
18641
  }
18628
18642
  })
18629
- }).catch(() => {});
18643
+ }).catch(() => {
18644
+ return;
18645
+ });
18630
18646
  }
18631
18647
  const dbUiPrefListeners = new Set;
18632
18648
  function applyDbUiState(next) {
@@ -18645,7 +18661,9 @@ ${entry.message}` : entry.detail ?? entry.message ?? "";
18645
18661
  method: "PATCH",
18646
18662
  headers: actionHeaders(),
18647
18663
  body: JSON.stringify({ prefs: { [key]: value } })
18648
- }).catch(() => {});
18664
+ }).catch(() => {
18665
+ return;
18666
+ });
18649
18667
  }
18650
18668
  function onDbUiPrefChange(listener) {
18651
18669
  dbUiPrefListeners.add(listener);
@@ -18758,7 +18776,9 @@ ${entry.message}` : entry.detail ?? entry.message ?? "";
18758
18776
  }
18759
18777
  return;
18760
18778
  }
18761
- saveChain = saveChain.catch(() => {}).then(async () => {
18779
+ saveChain = saveChain.catch(() => {
18780
+ return;
18781
+ }).then(async () => {
18762
18782
  const controller = new AbortController;
18763
18783
  saveController = controller;
18764
18784
  try {
@@ -18833,7 +18853,9 @@ ${entry.message}` : entry.detail ?? entry.message ?? "";
18833
18853
  syncActiveRoute();
18834
18854
  scheduleSave();
18835
18855
  if (mounted && !isRestoring()) {
18836
- ensureInitialEnter(id)?.catch(() => {});
18856
+ ensureInitialEnter(id)?.catch(() => {
18857
+ return;
18858
+ });
18837
18859
  }
18838
18860
  }
18839
18861
  function syncActiveRoute() {
@@ -18896,7 +18918,9 @@ ${entry.message}` : entry.detail ?? entry.message ?? "";
18896
18918
  "Content-Type": "application/json",
18897
18919
  "X-Code-Viewer-Action": "1"
18898
18920
  };
18899
- fetch("/_db/close", { method: "POST", headers, body }).catch(() => {});
18921
+ fetch("/_db/close", { method: "POST", headers, body }).catch(() => {
18922
+ return;
18923
+ });
18900
18924
  }
18901
18925
  function clearDropTarget() {
18902
18926
  if (!dropTargetId)
@@ -19406,7 +19430,9 @@ ${entry.message}` : entry.detail ?? entry.message ?? "";
19406
19430
  }
19407
19431
  async function enter(db, schema, table2, view, options = {}) {
19408
19432
  const seq = lifecycleSeq;
19409
- enterQueue = enterQueue.catch(() => {}).then(() => doEnter(seq, db, schema, table2, view, options));
19433
+ enterQueue = enterQueue.catch(() => {
19434
+ return;
19435
+ }).then(() => doEnter(seq, db, schema, table2, view, options));
19410
19436
  await enterQueue;
19411
19437
  }
19412
19438
  function leave() {
@@ -21716,7 +21742,9 @@ ${entry.message}` : entry.detail ?? entry.message ?? "";
21716
21742
  const force = options.force === true;
21717
21743
  const mount = options.mount || (force ? activeMount : defaultMount);
21718
21744
  activateMount(mount);
21719
- entering = entering.then(() => doEnterHistory(force)).catch(() => {});
21745
+ entering = entering.then(() => doEnterHistory(force)).catch(() => {
21746
+ return;
21747
+ });
21720
21748
  return entering;
21721
21749
  }
21722
21750
  async function doEnterHistory(force = false) {
@@ -23627,7 +23655,9 @@ code-viewer query diff rows --id diff-xyz789 --table users --type inserted --lim
23627
23655
  if (!GdpExpandLogic.shouldAttachTrailingExpand(data?.lines?.length || 0))
23628
23656
  return;
23629
23657
  attachTrailingExpandControls(item, file, ref, refPath);
23630
- }).catch(() => {});
23658
+ }).catch(() => {
23659
+ return;
23660
+ });
23631
23661
  }
23632
23662
  function insertContextRows(targetTr, lines, newStart, oldStart, dir, sideIndex) {
23633
23663
  const tbody = targetTr.parentElement;
@@ -23766,7 +23796,9 @@ code-viewer query diff rows --id diff-xyz789 --table users --type inserted --lim
23766
23796
  function fetchRefs() {
23767
23797
  return fetch("/_refs").then((r2) => r2.json()).then((refs) => {
23768
23798
  Object.assign(REFS, refs);
23769
- }).catch(() => {});
23799
+ }).catch(() => {
23800
+ return;
23801
+ });
23770
23802
  }
23771
23803
  fetchRefs();
23772
23804
  let popTab = "commits";
@@ -28822,7 +28854,9 @@ code-viewer query diff rows --id diff-xyz789 --table users --type inserted --lim
28822
28854
  headers: actionHeaders(),
28823
28855
  body,
28824
28856
  keepalive: options.keepalive
28825
- }).catch(() => {});
28857
+ }).catch(() => {
28858
+ return;
28859
+ });
28826
28860
  }
28827
28861
  let pendingViewPatch = null;
28828
28862
  let pendingViewTimer = null;
@@ -28895,7 +28929,9 @@ code-viewer query diff rows --id diff-xyz789 --table users --type inserted --lim
28895
28929
  headers: actionHeaders(),
28896
28930
  body,
28897
28931
  keepalive
28898
- }).catch(() => {});
28932
+ }).catch(() => {
28933
+ return;
28934
+ });
28899
28935
  };
28900
28936
  if (options.keepalive) {
28901
28937
  if (pendingViewTimer !== null)
@@ -28931,7 +28967,9 @@ code-viewer query diff rows --id diff-xyz789 --table users --type inserted --lim
28931
28967
  headers: actionHeaders(),
28932
28968
  body,
28933
28969
  keepalive
28934
- }).catch(() => {});
28970
+ }).catch(() => {
28971
+ return;
28972
+ });
28935
28973
  }
28936
28974
  function savedScopeOmitDirs() {
28937
28975
  return APP_SETTINGS.scopeOmitDirs ? normalizeScopeOmitDirs(APP_SETTINGS.scopeOmitDirs) : null;
@@ -30997,7 +31035,9 @@ code-viewer query diff rows --id diff-xyz789 --table users --type inserted --lim
30997
31035
  STATE.to = range.to;
30998
31036
  activeHistoryPathFilter = pathFilter || null;
30999
31037
  syncRefInputs();
31000
- return load().then(() => {});
31038
+ return load().then(() => {
31039
+ return;
31040
+ });
31001
31041
  },
31002
31042
  showEmptyDiffPane: () => {
31003
31043
  if (activeFileHistoryDiffHost || activeFileHistoryEmptyHost) {