@dbt-tools/web 0.6.2 → 0.6.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.html CHANGED
@@ -11,7 +11,7 @@
11
11
  href="https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500&family=Space+Grotesk:wght@500;600;700&display=swap"
12
12
  rel="stylesheet"
13
13
  />
14
- <script type="module" crossorigin src="/assets/index-DRBtWycK.js"></script>
14
+ <script type="module" crossorigin src="/assets/index-CQwlMVeT.js"></script>
15
15
  <link rel="modulepreload" crossorigin href="/assets/rolldown-runtime-Dw2cE7zH.js">
16
16
  <link rel="modulepreload" crossorigin href="/assets/react-vendor-DBiqvVPF.js">
17
17
  <link rel="modulepreload" crossorigin href="/assets/tanstack-virtual-vendor-BfMyFx37.js">
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { ARTIFACT_RUN_ID_CURRENT, DBT_CATALOG_JSON, DBT_MANIFEST_JSON, DBT_RUN_RESULTS_JSON, DBT_SOURCES_JSON, applyEntrypointRemoteOptionsToEnv, argvElementAt, createReadStreamValidated, discoverArtifactCandidates, discoverLocalArtifactRunPaths, entrypointRemoteHelpLines, existsValidated, getDbtToolsDbtTargetFromEnv, getDbtToolsRemoteClientEnvFromEnv, getDbtToolsTargetDirFromEnv, getObjectProperty, isDbtToolsDebugEnabled, joinObjectStorageKey, mergeRemoteSourceConfigWithParsedLocation, normalizeArtifactPrefix, normalizeArtifactPrefix as normalizeArtifactPrefix$1, parseArtifactSourceLocation, parseDbtToolsArtifactTarget, parseEntrypointRemoteArgv, readValidatedUtf8, readValidatedUtf8Sync, realpathValidatedSync, remoteKeysToListedArtifacts, resolveEntrypointRemoteOptions, statValidatedSync } from "@dbt-tools/core";
2
+ import { ARTIFACT_RUN_ID_CURRENT, DBT_CATALOG_JSON, DBT_MANIFEST_JSON, DBT_RUN_RESULTS_JSON, DBT_SOURCES_JSON, applyEntrypointRemoteOptionsToEnv, argvElementAt, captureSessionBinding, createReadStreamValidated, discoverArtifactCandidates, discoverLocalArtifactRunPaths, entrypointRemoteHelpLines, existsValidated, getDbtToolsDbtTargetFromEnv, getDbtToolsRemoteClientEnvFromEnv, getDbtToolsTargetDirFromEnv, getObjectProperty, isDbtToolsDebugEnabled, isSessionBindingCurrent, joinObjectStorageKey, mergeRemoteSourceConfigWithParsedLocation, normalizeArtifactPrefix, normalizeArtifactPrefix as normalizeArtifactPrefix$1, parseArtifactSourceLocation, parseDbtToolsArtifactTarget, parseEntrypointRemoteArgv, readValidatedUtf8, readValidatedUtf8Sync, realpathValidatedSync, remoteKeysToListedArtifacts, resolveEntrypointRemoteOptions, statValidatedSync } from "@dbt-tools/core";
3
3
  import { fileURLToPath } from "node:url";
4
4
  import http from "node:http";
5
5
  import path from "node:path";
@@ -249,6 +249,15 @@ var ArtifactSourceService = class {
249
249
  runs = [];
250
250
  discoveryResult = null;
251
251
  selectedRunId = null;
252
+ /** Version token of artifacts the active investigation is using (ADR-0004 detect-notify-confirm). */
253
+ loadedVersionToken = null;
254
+ remoteDiscoveryRefreshPromise = null;
255
+ /** Bytes last committed for investigation; pins remote reads while a newer prefix version is pending. */
256
+ loadedArtifactCache = null;
257
+ /** Incremented on user configure so in-flight remote poll refresh cannot revert the session. */
258
+ sessionGeneration = 0;
259
+ /** Set when background remote list/refresh fails; surfaced via discoveryError when discovery is otherwise ok. */
260
+ remoteRefreshError = null;
252
261
  constructor(options = {}) {
253
262
  this.cwd = options.cwd ?? process.cwd();
254
263
  this.seedFromEnv = options.seedFromEnv !== false;
@@ -284,6 +293,7 @@ var ArtifactSourceService = class {
284
293
  const discovery = await this.discoverArtifactSourceInternal(parsed.provider, rawDbtTarget);
285
294
  const selectedRunId = discovery.discoveryResult.ok && discovery.mode === "remote" ? this.pickBootstrapRunId(discovery.runs) : null;
286
295
  this.applyDiscoveredArtifactSource(discovery, selectedRunId);
296
+ if (selectedRunId != null) await this.refreshLoadedArtifactCache();
287
297
  return;
288
298
  }
289
299
  await this.applyLocalDirectory(parsed.resolvedPath, true);
@@ -341,7 +351,7 @@ var ArtifactSourceService = class {
341
351
  return this.mode;
342
352
  }
343
353
  buildActiveArtifactStatus() {
344
- const discoveryError = this.discoveryErrorMessage();
354
+ const discoveryError = this.discoveryErrorMessage() ?? this.remoteRefreshError;
345
355
  const currentResolved = this.resolveSelectedRun();
346
356
  const currentRunUi = this.runToUiOrNull(currentResolved);
347
357
  const pendingRun = this.pendingRunAfterLatest(currentResolved);
@@ -368,11 +378,60 @@ var ArtifactSourceService = class {
368
378
  missingOptionalArtifacts
369
379
  };
370
380
  }
371
- pendingRunAfterLatest(currentResolved) {
381
+ syncLoadedVersionToken(selectedRunId, runs) {
382
+ if (selectedRunId == null) {
383
+ this.loadedVersionToken = null;
384
+ return;
385
+ }
386
+ this.loadedVersionToken = runs.find((candidate) => candidate.runId === selectedRunId)?.versionToken ?? null;
387
+ }
388
+ pendingRunAfterLatest(_currentResolved) {
372
389
  const latestRun = this.runs[0] ?? null;
373
- if (this.mode !== "remote" || this.remoteProvider == null || latestRun == null || currentResolved == null || latestRun.runId === currentResolved.runId) return null;
390
+ if (this.mode !== "remote" || this.remoteProvider == null || latestRun == null) return null;
391
+ if (this.loadedVersionToken == null || latestRun.versionToken === this.loadedVersionToken) return null;
374
392
  return runToUiRow("remote", this.remoteProvider, latestRun);
375
393
  }
394
+ /** Re-list the remote prefix so polling can detect newer artifact pairs (ADR-0004). */
395
+ async refreshRemoteDiscovery() {
396
+ if (this.mode !== "remote" || this.remoteConfig == null || this.remoteClient == null) return;
397
+ if (this.remoteDiscoveryRefreshPromise != null) return this.remoteDiscoveryRefreshPromise;
398
+ this.remoteDiscoveryRefreshPromise = this.refreshRemoteDiscoveryInternal().finally(() => {
399
+ this.remoteDiscoveryRefreshPromise = null;
400
+ });
401
+ return this.remoteDiscoveryRefreshPromise;
402
+ }
403
+ async refreshRemoteDiscoveryInternal() {
404
+ if (this.mode !== "remote" || this.remoteConfig == null || this.remoteClient == null) return;
405
+ const binding = captureSessionBinding(this.sessionGeneration, null);
406
+ try {
407
+ const discovery = await this.discoverRemoteConfiguration(this.remoteConfig, this.remoteClient);
408
+ if (!discovery.discoveryResult.ok) {
409
+ if (isSessionBindingCurrent(binding, this.sessionGeneration, null)) this.remoteRefreshError = discovery.discoveryResult.failure.message ?? "Remote artifact discovery failed.";
410
+ return;
411
+ }
412
+ if (!isSessionBindingCurrent(binding, this.sessionGeneration, null)) return;
413
+ this.remoteRefreshError = null;
414
+ this.applyDiscoveredArtifactSource(discovery, this.selectedRunId, { commitLoadedVersion: false });
415
+ } catch (error) {
416
+ if (isSessionBindingCurrent(binding, this.sessionGeneration, null)) this.remoteRefreshError = error instanceof Error ? error.message : "Remote artifact discovery refresh failed.";
417
+ debugLog("Remote discovery refresh failed", error);
418
+ }
419
+ }
420
+ async readCurrentArtifactPayload(run) {
421
+ if (this.mode === "preload" && this.localDir != null) return this.readPreloadArtifacts(run);
422
+ if (this.mode === "remote" && this.remoteClient != null && this.remoteConfig != null) return this.readRemoteArtifacts(run, this.remoteConfig.bucket, this.remoteClient);
423
+ return null;
424
+ }
425
+ async refreshLoadedArtifactCache() {
426
+ const binding = captureSessionBinding(this.sessionGeneration, this.selectedRunId);
427
+ const run = this.resolveSelectedRun();
428
+ if (run == null || this.discoveryResult?.ok !== true) {
429
+ if (isSessionBindingCurrent(binding, this.sessionGeneration, this.selectedRunId)) this.loadedArtifactCache = null;
430
+ return;
431
+ }
432
+ const payload = await this.readCurrentArtifactPayload(run);
433
+ if (isSessionBindingCurrent(binding, this.sessionGeneration, this.selectedRunId)) this.loadedArtifactCache = payload;
434
+ }
376
435
  async readPreloadArtifacts(run) {
377
436
  const encoder = new TextEncoder();
378
437
  const [manifestText, runResultsText, catalogText, sourcesText] = await Promise.all([
@@ -424,7 +483,7 @@ var ArtifactSourceService = class {
424
483
  if (trimmedRunId != null && trimmedRunId !== "" && trimmedRunId !== sole.runId) throw new Error(`Unknown run id "${trimmedRunId}".`);
425
484
  return sole.runId;
426
485
  }
427
- applyDiscoveredArtifactSource(discovery, selectedRunId) {
486
+ applyDiscoveredArtifactSource(discovery, selectedRunId, options) {
428
487
  this.mode = discovery.mode;
429
488
  this.localDir = discovery.localDir;
430
489
  this.locationDisplay = discovery.locationDisplay;
@@ -435,6 +494,10 @@ var ArtifactSourceService = class {
435
494
  this.discoveryResult = discovery.discoveryResult;
436
495
  this.runs = discovery.runs;
437
496
  this.selectedRunId = selectedRunId;
497
+ if (options?.commitLoadedVersion !== false) {
498
+ this.syncLoadedVersionToken(selectedRunId, discovery.runs);
499
+ this.loadedArtifactCache = null;
500
+ }
438
501
  }
439
502
  async discoverLocalDirectory(resolvedDir) {
440
503
  const { runs, discovery } = await discoverLocalResolvedArtifactRuns(resolvedDir);
@@ -484,11 +547,13 @@ var ArtifactSourceService = class {
484
547
  const discovery = await this.discoverLocalDirectory(resolvedDir);
485
548
  const selectedRunId = discovery.discoveryResult.ok && fromEnvBootstrap ? this.pickBootstrapRunId(discovery.runs) : null;
486
549
  this.applyDiscoveredArtifactSource(discovery, selectedRunId);
550
+ if (selectedRunId != null) await this.refreshLoadedArtifactCache();
487
551
  }
488
552
  async applyRemoteConfiguration(config, client, fromEnvBootstrap) {
489
553
  const discovery = await this.discoverRemoteConfiguration(config, client);
490
554
  const selectedRunId = discovery.discoveryResult.ok && fromEnvBootstrap ? this.pickBootstrapRunId(discovery.runs) : null;
491
555
  this.applyDiscoveredArtifactSource(discovery, selectedRunId);
556
+ if (selectedRunId != null) await this.refreshLoadedArtifactCache();
492
557
  }
493
558
  async discoverArtifactSource(kind, location, providerOptions) {
494
559
  await this.ensureReady();
@@ -505,9 +570,13 @@ var ArtifactSourceService = class {
505
570
  */
506
571
  async configureArtifactSource(kind, location, runId, providerOptions) {
507
572
  await this.ensureReady();
573
+ this.sessionGeneration += 1;
574
+ const binding = captureSessionBinding(this.sessionGeneration, null);
508
575
  const discovery = await this.discoverArtifactSourceInternal(kind, location, providerOptions);
576
+ if (!isSessionBindingCurrent(binding, this.sessionGeneration, null)) return this.getStatus();
509
577
  const selectedRunId = this.resolveConfiguredRunId(discovery, runId);
510
578
  this.applyDiscoveredArtifactSource(discovery, selectedRunId);
579
+ await this.refreshLoadedArtifactCache();
511
580
  return this.getStatus();
512
581
  }
513
582
  async getStatus() {
@@ -516,24 +585,52 @@ var ArtifactSourceService = class {
516
585
  if (this.mode === "none") return this.statusWhenNone();
517
586
  return toArtifactSourceStatus(this.buildActiveArtifactStatus());
518
587
  }
588
+ /** Re-list remote prefix and merge discovery (poll / explicit refresh). */
589
+ async refreshRemoteArtifactDiscovery() {
590
+ await this.ensureReady();
591
+ if (this.delegatedAdapter != null) return this.delegatedAdapter.getStatus();
592
+ if (this.mode === "remote") await this.refreshRemoteDiscovery();
593
+ return this.getStatus();
594
+ }
595
+ /**
596
+ * Switch to a pending remote run and return status plus current artifact bytes.
597
+ * Server commits run selection and artifact cache before the client loads analysis.
598
+ */
599
+ async acceptPendingRemoteRun(runId) {
600
+ await this.ensureReady();
601
+ if (this.delegatedAdapter != null) throw new Error("acceptPendingRemoteRun is not supported with a delegated adapter.");
602
+ if (this.mode !== "remote") throw new Error("acceptPendingRemoteRun requires a remote artifact source.");
603
+ const trimmed = runId.trim();
604
+ if (trimmed === "") throw new Error("runId is required.");
605
+ if (!this.runs.some((run) => run.runId === trimmed)) throw new Error(`Unknown artifact run id: ${trimmed}`);
606
+ this.selectedRunId = trimmed;
607
+ this.syncLoadedVersionToken(this.selectedRunId, this.runs);
608
+ this.loadedArtifactCache = null;
609
+ await this.refreshLoadedArtifactCache();
610
+ return this.getStatus();
611
+ }
519
612
  async getCurrentArtifacts() {
520
613
  await this.ensureReady();
521
614
  if (this.delegatedAdapter != null) return this.delegatedAdapter.getCurrentArtifacts();
522
615
  if (this.selectedRunId == null || this.discoveryResult?.ok !== true) return null;
523
616
  const run = this.runs.find((r) => r.runId === this.selectedRunId);
524
617
  if (run == null) return null;
525
- if (this.mode === "preload" && this.localDir != null) return this.readPreloadArtifacts(run);
526
- if (this.mode === "remote" && this.remoteClient != null && this.remoteConfig != null) return this.readRemoteArtifacts(run, this.remoteConfig.bucket, this.remoteClient);
527
- return null;
618
+ if (this.mode === "remote" && this.loadedArtifactCache != null && this.loadedVersionToken != null) return this.loadedArtifactCache;
619
+ const payload = await this.readCurrentArtifactPayload(run);
620
+ if (payload != null && this.mode === "remote" && this.loadedVersionToken != null && run.versionToken === this.loadedVersionToken) this.loadedArtifactCache = payload;
621
+ return payload;
528
622
  }
529
623
  async switchToRun(runId) {
530
624
  await this.ensureReady();
531
625
  if (this.delegatedAdapter != null) return this.delegatedAdapter.switchToRun(runId);
532
626
  if (runId != null && runId.trim() !== "") {
533
- if (this.runs.some((r) => r.runId === runId)) {
534
- this.selectedRunId = runId;
535
- debugLog("Selected artifact run", this.selectedRunId);
536
- }
627
+ const trimmed = runId.trim();
628
+ if (!this.runs.some((r) => r.runId === trimmed)) throw new Error(`Unknown artifact run id: ${trimmed}`);
629
+ this.selectedRunId = trimmed;
630
+ this.syncLoadedVersionToken(this.selectedRunId, this.runs);
631
+ this.loadedArtifactCache = null;
632
+ await this.refreshLoadedArtifactCache();
633
+ debugLog("Selected artifact run", this.selectedRunId);
537
634
  }
538
635
  return this.getStatus();
539
636
  }
@@ -608,6 +705,12 @@ function isArtifactStatusRequest(req, pathname) {
608
705
  function isArtifactSwitchRequest(req, pathname) {
609
706
  return req.method === "POST" && pathname === "/api/artifact-source/switch";
610
707
  }
708
+ function isArtifactRefreshRequest(req, pathname) {
709
+ return req.method === "POST" && pathname === "/api/artifact-source/refresh";
710
+ }
711
+ function isArtifactAcceptPendingRequest(req, pathname) {
712
+ return req.method === "POST" && pathname === "/api/artifact-source/accept-pending-run";
713
+ }
611
714
  function isArtifactConfigureRequest(req, pathname) {
612
715
  return req.method === "POST" && pathname === "/api/artifact-source/configure";
613
716
  }
@@ -623,7 +726,27 @@ async function respondArtifactStatus(res, service) {
623
726
  async function respondArtifactSwitch(req, res, service) {
624
727
  const body = await readJsonBody(req);
625
728
  const runId = typeof body.runId === "string" && body.runId.trim() !== "" ? body.runId : void 0;
626
- sendJson(res, 200, await service.switchToRun(runId));
729
+ try {
730
+ sendJson(res, 200, await service.switchToRun(runId));
731
+ } catch (error) {
732
+ sendJson(res, 400, { error: error instanceof Error ? error.message : "Failed to switch artifact run." });
733
+ }
734
+ }
735
+ async function respondArtifactRefresh(res, service) {
736
+ try {
737
+ sendJson(res, 200, await service.refreshRemoteArtifactDiscovery());
738
+ } catch (error) {
739
+ sendJson(res, 500, { error: error instanceof Error ? error.message : "Remote artifact discovery refresh failed." });
740
+ }
741
+ }
742
+ async function respondArtifactAcceptPending(req, res, service) {
743
+ const body = await readJsonBody(req);
744
+ const runId = typeof body.runId === "string" ? body.runId : "";
745
+ try {
746
+ sendJson(res, 200, await service.acceptPendingRemoteRun(runId));
747
+ } catch (error) {
748
+ sendJson(res, 400, { error: error instanceof Error ? error.message : "Failed to accept pending remote run." });
749
+ }
627
750
  }
628
751
  async function respondArtifactConfigure(req, res, service) {
629
752
  const body = await readJsonBody(req);
@@ -695,6 +818,14 @@ async function tryHandleArtifactSourceViteRequest(req, res, service) {
695
818
  await respondArtifactSwitch(req, res, service);
696
819
  return true;
697
820
  }
821
+ if (isArtifactRefreshRequest(req, pathname)) {
822
+ await respondArtifactRefresh(res, service);
823
+ return true;
824
+ }
825
+ if (isArtifactAcceptPendingRequest(req, pathname)) {
826
+ await respondArtifactAcceptPending(req, res, service);
827
+ return true;
828
+ }
698
829
  if (isArtifactConfigureRequest(req, pathname)) {
699
830
  await respondArtifactConfigure(req, res, service);
700
831
  return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dbt-tools/web",
3
- "version": "0.6.2",
3
+ "version": "0.6.4",
4
4
  "description": "Browser UI for deterministic dbt artifact investigation — dependencies, execution timelines, inventory (no LLM required)",
5
5
  "keywords": [
6
6
  "dbt",
@@ -17,7 +17,7 @@
17
17
  "bugs": {
18
18
  "url": "https://github.com/yu-iskw/dbt-tools-ts/issues"
19
19
  },
20
- "homepage": "https://github.com/yu-iskw/dbt-tools-ts#readme",
20
+ "homepage": "https://yu-iskw.github.io/dbt-tools-ts/",
21
21
  "engines": {
22
22
  "node": ">=20"
23
23
  },
@@ -38,7 +38,7 @@
38
38
  "react-dom": "^19.2.4",
39
39
  "react-markdown": "^10.1.0",
40
40
  "remark-gfm": "^4.0.1",
41
- "@dbt-tools/core": "0.6.2"
41
+ "@dbt-tools/core": "0.6.4"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@playwright/test": "^1.59.1",