@dbt-tools/web 0.5.8 → 0.6.0

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.
@@ -1,11 +1,116 @@
1
1
  #!/usr/bin/env node
2
- import fs from "node:fs";
3
2
  import http from "node:http";
4
3
  import path from "node:path";
5
4
  import { fileURLToPath } from "node:url";
6
- import fs$1 from "node:fs/promises";
7
- import { ARTIFACT_RUN_ID_CURRENT, DBT_CATALOG_JSON, DBT_MANIFEST_JSON, DBT_RUN_RESULTS_JSON, DBT_SOURCES_JSON, discoverArtifactCandidates, discoverLocalArtifactRunPaths, getDbtToolsRemoteSourceConfigFromEnv, getDbtToolsTargetDirFromEnv, isDbtToolsDebugEnabled, joinObjectStorageKey, mergeRemoteSourceConfigWithParsedLocation, normalizeArtifactPrefix, normalizeArtifactPrefix as normalizeArtifactPrefix$1, parseArtifactSourceLocation, remoteKeysToListedArtifacts } from "@dbt-tools/core";
5
+ import { ARTIFACT_RUN_ID_CURRENT, DBT_CATALOG_JSON, DBT_MANIFEST_JSON, DBT_RUN_RESULTS_JSON, DBT_SOURCES_JSON, createReadStreamValidated, discoverArtifactCandidates, discoverLocalArtifactRunPaths, existsValidated, getDbtToolsRemoteSourceConfigFromEnv, getDbtToolsTargetDirFromEnv, getObjectProperty, isDbtToolsDebugEnabled, joinObjectStorageKey, mergeRemoteSourceConfigWithParsedLocation, normalizeArtifactPrefix, normalizeArtifactPrefix as normalizeArtifactPrefix$1, parseArtifactSourceLocation, readValidatedUtf8, realpathValidatedSync, remoteKeysToListedArtifacts, statValidatedSync } from "@dbt-tools/core";
8
6
  import { createRemoteObjectStoreClient } from "@dbt-tools/core/artifact-io";
7
+ //#region src/server/cli-args.ts
8
+ /** Pure CLI argument parsing for `dbt-tools-web` (testable without starting the server). */
9
+ var USAGE = `
10
+ Usage: dbt-tools-web [options]
11
+
12
+ --target <dir> Path to dbt target directory (sets DBT_TOOLS_TARGET_DIR)
13
+ --port <n> Port to listen on (default: 3000)
14
+ --help Show this help message
15
+ `.trimStart();
16
+ function readRequiredValue(argv, i, flagDesc) {
17
+ const next = argv[i + 1];
18
+ if (!next || next.startsWith("-")) return {
19
+ ok: false,
20
+ message: `Missing value for ${flagDesc}`
21
+ };
22
+ return {
23
+ ok: true,
24
+ value: next,
25
+ nextIndex: i + 1
26
+ };
27
+ }
28
+ function parsePortString(s) {
29
+ const parsed = Number.parseInt(s, 10);
30
+ if (Number.isNaN(parsed) || parsed < 1 || parsed > 65535) return null;
31
+ return parsed;
32
+ }
33
+ function consumeOne(argv, i, state) {
34
+ const arg = argv.at(i);
35
+ if (arg === "--help" || arg === "-h") return {
36
+ status: "done",
37
+ result: { kind: "help" }
38
+ };
39
+ if (arg === "--no-open") return {
40
+ status: "advance",
41
+ nextIndex: i + 1
42
+ };
43
+ if (arg === "--target" || arg === "-t") {
44
+ const r = readRequiredValue(argv, i, "--target (or -t)");
45
+ if (!r.ok) return {
46
+ status: "done",
47
+ result: {
48
+ kind: "error",
49
+ message: r.message
50
+ }
51
+ };
52
+ state.targetDir = r.value;
53
+ return {
54
+ status: "advance",
55
+ nextIndex: r.nextIndex + 1
56
+ };
57
+ }
58
+ if (arg === "--port" || arg === "-p") {
59
+ const r = readRequiredValue(argv, i, "--port (or -p)");
60
+ if (!r.ok) return {
61
+ status: "done",
62
+ result: {
63
+ kind: "error",
64
+ message: r.message
65
+ }
66
+ };
67
+ const p = parsePortString(r.value);
68
+ if (p === null) return {
69
+ status: "done",
70
+ result: {
71
+ kind: "error",
72
+ message: `Invalid port: ${r.value}`
73
+ }
74
+ };
75
+ state.port = p;
76
+ return {
77
+ status: "advance",
78
+ nextIndex: r.nextIndex + 1
79
+ };
80
+ }
81
+ if (arg.startsWith("-")) return {
82
+ status: "done",
83
+ result: {
84
+ kind: "error",
85
+ message: `Unknown option: ${arg}`
86
+ }
87
+ };
88
+ return {
89
+ status: "done",
90
+ result: {
91
+ kind: "error",
92
+ message: `Unexpected argument: ${arg}`
93
+ }
94
+ };
95
+ }
96
+ function parseCliArgs(argv) {
97
+ const state = {
98
+ targetDir: void 0,
99
+ port: 3e3
100
+ };
101
+ let i = 0;
102
+ while (i < argv.length) {
103
+ const step = consumeOne(argv, i, state);
104
+ if (step.status === "done") return step.result;
105
+ i = step.nextIndex;
106
+ }
107
+ return {
108
+ kind: "ok",
109
+ targetDir: state.targetDir,
110
+ port: state.port
111
+ };
112
+ }
113
+ //#endregion
9
114
  //#region src/artifact-source/discovery.ts
10
115
  function mapCoreCandidatesToResolvedRuns(disc, resolveKey) {
11
116
  return disc.candidates.map((c) => ({
@@ -57,13 +162,13 @@ function toRemoteArtifactRun(provider, run) {
57
162
  function toLocalManagedArtifactRun(run) {
58
163
  return {
59
164
  runId: run.runId,
60
- label: run.runId === ARTIFACT_RUN_ID_CURRENT ? "Local (root)" : `Local (${run.runId})`,
165
+ label: "Local",
61
166
  updatedAtMs: run.updatedAtMs,
62
167
  versionToken: run.versionToken
63
168
  };
64
169
  }
65
170
  //#endregion
66
- //#region src/artifact-source/resolveLocalTargetDir.ts
171
+ //#region src/artifact-source/resolve-local-target-dir.ts
67
172
  function expandDbtTargetDirFromEnvValue(targetDir) {
68
173
  return targetDir.replace(/^~($|\/)/, `${process.env.HOME ?? ""}$1`).trim();
69
174
  }
@@ -71,7 +176,7 @@ function resolveLocalArtifactTargetDirFromEnv(cwd, rawTargetDir) {
71
176
  return path.resolve(cwd, expandDbtTargetDirFromEnvValue(rawTargetDir));
72
177
  }
73
178
  //#endregion
74
- //#region src/artifact-source/sourceService.ts
179
+ //#region src/artifact-source/source-service.ts
75
180
  /** Node (Vite dev) service: configurable local path or remote S3/GCS; drives middleware routes. */
76
181
  function debugLog(...args) {
77
182
  if (isDbtToolsDebugEnabled()) console.log("[artifact-source]", ...args);
@@ -129,7 +234,7 @@ var ArtifactSourceService = class {
129
234
  }
130
235
  async bootstrapFromExplicitOptions(options) {
131
236
  if (options.remoteConfig != null) {
132
- await this.applyRemoteConfiguration(options.remoteConfig, options.remoteClient ?? createRemoteObjectStoreClient(options.remoteConfig), true);
237
+ await this.applyRemoteConfiguration(options.remoteConfig, options.remoteClient ?? await createRemoteObjectStoreClient(options.remoteConfig), true);
133
238
  return;
134
239
  }
135
240
  if (options.targetDir != null) {
@@ -140,7 +245,7 @@ var ArtifactSourceService = class {
140
245
  async seedFromEnvironment() {
141
246
  const remoteEnv = getDbtToolsRemoteSourceConfigFromEnv();
142
247
  if (remoteEnv != null) {
143
- await this.applyRemoteConfiguration(remoteEnv, createRemoteObjectStoreClient(remoteEnv), true);
248
+ await this.applyRemoteConfiguration(remoteEnv, await createRemoteObjectStoreClient(remoteEnv), true);
144
249
  return;
145
250
  }
146
251
  const rawTarget = getDbtToolsTargetDirFromEnv();
@@ -148,10 +253,8 @@ var ArtifactSourceService = class {
148
253
  const resolved = resolveLocalArtifactTargetDirFromEnv(this.cwd, rawTarget);
149
254
  await this.applyLocalDirectory(resolved, true);
150
255
  }
151
- pickBootstrapRunId(mode, runs) {
152
- if (mode === "remote") return runs[0]?.runId ?? null;
153
- if (runs.length === 1) return runs[0].runId;
154
- return null;
256
+ pickBootstrapRunId(runs) {
257
+ return runs.length === 1 ? runs[0].runId : null;
155
258
  }
156
259
  discoveryErrorMessage() {
157
260
  return this.discoveryResult != null && !this.discoveryResult.ok ? this.discoveryResult.failure.message : null;
@@ -171,24 +274,16 @@ var ArtifactSourceService = class {
171
274
  currentRun: null,
172
275
  pendingRun: null,
173
276
  supportsSwitch: false,
174
- needsSelection: false,
175
- candidates: void 0,
176
277
  discoveryError: null,
177
278
  sourceKind: null,
178
279
  locationDisplay: null,
179
280
  missingOptionalArtifacts: void 0
180
281
  });
181
282
  }
182
- mapRunsToUiRows() {
183
- return this.runs.map((run) => runToUiRow(this.mode, this.remoteProvider, run));
184
- }
185
283
  runToUiOrNull(run) {
186
284
  if (run == null) return null;
187
285
  return runToUiRow(this.mode, this.remoteProvider, run);
188
286
  }
189
- needsExplicitRunSelection(discoveryError) {
190
- return this.runs.length > 0 && this.selectedRunId == null && discoveryError == null;
191
- }
192
287
  optionalArtifactsForResolved(currentResolved) {
193
288
  return currentResolved == null ? void 0 : missingOptionalFromRun(currentResolved);
194
289
  }
@@ -196,26 +291,23 @@ var ArtifactSourceService = class {
196
291
  if (this.mode !== "remote") return null;
197
292
  return this.remoteConfig?.pollIntervalMs ?? null;
198
293
  }
199
- remoteSupportsPendingSwitch(pendingRun, needsSelection) {
200
- return this.mode === "remote" && pendingRun != null && !needsSelection;
294
+ remoteSupportsPendingSwitch(pendingRun) {
295
+ return this.mode === "remote" && pendingRun != null;
201
296
  }
202
297
  currentManagedSourceOrNull(params) {
203
- if (params.needsSelection || params.discoveryError != null || params.currentResolved == null) return null;
298
+ if (params.discoveryError != null || params.currentResolved == null) return null;
204
299
  if (this.mode === "none") return null;
205
300
  return this.mode;
206
301
  }
207
302
  buildActiveArtifactStatus() {
208
303
  const discoveryError = this.discoveryErrorMessage();
209
- const candidatesUi = this.mapRunsToUiRows();
210
304
  const currentResolved = this.resolveSelectedRun();
211
305
  const currentRunUi = this.runToUiOrNull(currentResolved);
212
306
  const pendingRun = this.pendingRunAfterLatest(currentResolved);
213
- const needsSelection = this.needsExplicitRunSelection(discoveryError);
214
307
  const missingOptionalArtifacts = this.optionalArtifactsForResolved(currentResolved);
215
- const supportsSwitch = this.remoteSupportsPendingSwitch(pendingRun, needsSelection);
308
+ const supportsSwitch = this.remoteSupportsPendingSwitch(pendingRun);
216
309
  const pollIntervalMs = this.remotePollIntervalOrNull();
217
310
  const currentSource = this.currentManagedSourceOrNull({
218
- needsSelection,
219
311
  discoveryError,
220
312
  currentResolved
221
313
  });
@@ -229,8 +321,6 @@ var ArtifactSourceService = class {
229
321
  currentRun: currentRunUi,
230
322
  pendingRun,
231
323
  supportsSwitch,
232
- needsSelection,
233
- candidates: candidatesUi.length > 0 ? candidatesUi : void 0,
234
324
  discoveryError,
235
325
  sourceKind: this.sourceKind ?? void 0,
236
326
  locationDisplay: this.locationDisplay,
@@ -243,12 +333,17 @@ var ArtifactSourceService = class {
243
333
  return runToUiRow("remote", this.remoteProvider, latestRun);
244
334
  }
245
335
  async readPreloadArtifacts(run) {
246
- const [manifestBytes, runResultsBytes, catalogBytes, sourcesBytes] = await Promise.all([
247
- fs$1.readFile(run.manifestKey),
248
- fs$1.readFile(run.runResultsKey),
249
- run.catalogKey != null ? fs$1.readFile(run.catalogKey).catch(() => null) : Promise.resolve(null),
250
- run.sourcesKey != null ? fs$1.readFile(run.sourcesKey).catch(() => null) : Promise.resolve(null)
336
+ const encoder = new TextEncoder();
337
+ const [manifestText, runResultsText, catalogText, sourcesText] = await Promise.all([
338
+ readValidatedUtf8(run.manifestKey),
339
+ readValidatedUtf8(run.runResultsKey),
340
+ run.catalogKey != null ? readValidatedUtf8(run.catalogKey).catch(() => null) : Promise.resolve(null),
341
+ run.sourcesKey != null ? readValidatedUtf8(run.sourcesKey).catch(() => null) : Promise.resolve(null)
251
342
  ]);
343
+ const manifestBytes = encoder.encode(manifestText);
344
+ const runResultsBytes = encoder.encode(runResultsText);
345
+ const catalogBytes = catalogText != null ? encoder.encode(catalogText) : null;
346
+ const sourcesBytes = sourcesText != null ? encoder.encode(sourcesText) : null;
252
347
  return {
253
348
  source: "preload",
254
349
  manifestBytes,
@@ -280,23 +375,13 @@ var ArtifactSourceService = class {
280
375
  ...sourcesBytes != null ? { sourcesBytes } : {}
281
376
  };
282
377
  }
283
- previewToUiRows(discovery) {
284
- return discovery.runs.map((run) => runToUiRow(discovery.mode, discovery.remoteProvider, run));
285
- }
286
- discoveryNeedsSelection(discovery, selectedRunId) {
287
- const discoveryError = discovery.discoveryResult.ok === true ? null : discovery.discoveryResult.failure.message;
288
- return discovery.runs.length > 0 && selectedRunId == null && discoveryError == null;
289
- }
290
378
  resolveConfiguredRunId(discovery, runId) {
291
379
  if (!discovery.discoveryResult.ok) throw new Error(discovery.discoveryResult.failure.message);
292
- const trimmedRunId = runId?.trim();
293
- if (trimmedRunId != null && trimmedRunId !== "") {
294
- if (!discovery.runs.some((run) => run.runId === trimmedRunId)) throw new Error(`Unknown run id "${trimmedRunId}". Candidates: ${discovery.runs.map((run) => run.runId).join(", ")}`);
295
- return trimmedRunId;
296
- }
297
- if (discovery.runs.length === 1) return discovery.runs[0].runId;
298
380
  if (discovery.runs.length === 0) throw new Error("No complete dbt artifact pair found at this location.");
299
- throw new Error(`Multiple artifact sets found (${discovery.runs.length}). Select a candidate run before loading.`);
381
+ const sole = discovery.runs[0];
382
+ const trimmedRunId = runId?.trim();
383
+ if (trimmedRunId != null && trimmedRunId !== "" && trimmedRunId !== sole.runId) throw new Error(`Unknown run id "${trimmedRunId}".`);
384
+ return sole.runId;
300
385
  }
301
386
  applyDiscoveredArtifactSource(discovery, selectedRunId) {
302
387
  this.mode = discovery.mode;
@@ -343,33 +428,29 @@ var ArtifactSourceService = class {
343
428
  discoveryResult: discovery
344
429
  };
345
430
  }
346
- async discoverArtifactSourceInternal(kind, location) {
431
+ async discoverArtifactSourceInternal(kind, location, providerOptions) {
347
432
  const parsed = parseArtifactSourceLocation(kind, location, this.cwd);
348
433
  if (parsed.kind === "local") return this.discoverLocalDirectory(parsed.resolvedPath);
349
- const merged = mergeRemoteSourceConfigWithParsedLocation(getDbtToolsRemoteSourceConfigFromEnv(), parsed);
350
- const client = createRemoteObjectStoreClient(merged);
434
+ const merged = mergeRemoteSourceConfigWithParsedLocation(getDbtToolsRemoteSourceConfigFromEnv(), parsed, kind === "gcs" ? providerOptions : void 0);
435
+ const client = await createRemoteObjectStoreClient(merged);
351
436
  return this.discoverRemoteConfiguration(merged, client);
352
437
  }
353
438
  async applyLocalDirectory(resolvedDir, fromEnvBootstrap) {
354
439
  const discovery = await this.discoverLocalDirectory(resolvedDir);
355
- const selectedRunId = discovery.discoveryResult.ok && fromEnvBootstrap ? this.pickBootstrapRunId("preload", discovery.runs) : null;
440
+ const selectedRunId = discovery.discoveryResult.ok && fromEnvBootstrap ? this.pickBootstrapRunId(discovery.runs) : null;
356
441
  this.applyDiscoveredArtifactSource(discovery, selectedRunId);
357
442
  }
358
443
  async applyRemoteConfiguration(config, client, fromEnvBootstrap) {
359
444
  const discovery = await this.discoverRemoteConfiguration(config, client);
360
- const selectedRunId = discovery.discoveryResult.ok && fromEnvBootstrap ? this.pickBootstrapRunId("remote", discovery.runs) : null;
445
+ const selectedRunId = discovery.discoveryResult.ok && fromEnvBootstrap ? this.pickBootstrapRunId(discovery.runs) : null;
361
446
  this.applyDiscoveredArtifactSource(discovery, selectedRunId);
362
447
  }
363
- async discoverArtifactSource(kind, location) {
448
+ async discoverArtifactSource(kind, location, providerOptions) {
364
449
  await this.ensureReady();
365
- const discovery = await this.discoverArtifactSourceInternal(kind, location);
366
- const candidates = this.previewToUiRows(discovery);
367
- const needsSelection = this.discoveryNeedsSelection(discovery, null);
450
+ const discovery = await this.discoverArtifactSourceInternal(kind, location, providerOptions);
368
451
  return {
369
452
  sourceKind: discovery.sourceKind,
370
453
  locationDisplay: discovery.locationDisplay,
371
- candidates: candidates.length > 0 ? candidates : void 0,
372
- needsSelection,
373
454
  discoveryError: discovery.discoveryResult.ok === true ? null : discovery.discoveryResult.failure.message
374
455
  };
375
456
  }
@@ -377,9 +458,9 @@ var ArtifactSourceService = class {
377
458
  * User-driven configuration (UI or API). Commits the location only when the
378
459
  * selected run is explicit or uniquely determined.
379
460
  */
380
- async configureArtifactSource(kind, location, runId) {
461
+ async configureArtifactSource(kind, location, runId, providerOptions) {
381
462
  await this.ensureReady();
382
- const discovery = await this.discoverArtifactSourceInternal(kind, location);
463
+ const discovery = await this.discoverArtifactSourceInternal(kind, location, providerOptions);
383
464
  const selectedRunId = this.resolveConfiguredRunId(discovery, runId);
384
465
  this.applyDiscoveredArtifactSource(discovery, selectedRunId);
385
466
  return this.getStatus();
@@ -413,7 +494,33 @@ var ArtifactSourceService = class {
413
494
  }
414
495
  };
415
496
  //#endregion
416
- //#region src/artifact-source/viteArtifactRoutes.ts
497
+ //#region src/artifact-source/vite-artifact-routes.ts
498
+ var ARTIFACT_SOURCE_UNSUPPORTED_OPTIONS_ERROR = "Service account impersonation is only supported for Google Cloud Storage. Options are not supported for local or S3 artifact sources.";
499
+ function parseArtifactSourceRequestOptions(kind, body) {
500
+ if (!Object.prototype.hasOwnProperty.call(body, "options")) return {
501
+ ok: true,
502
+ gcsOptions: void 0
503
+ };
504
+ const raw = body.options;
505
+ if (kind !== "gcs") return {
506
+ ok: false,
507
+ error: ARTIFACT_SOURCE_UNSUPPORTED_OPTIONS_ERROR
508
+ };
509
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return {
510
+ ok: false,
511
+ error: "Invalid options payload for Google Cloud Storage artifact source."
512
+ };
513
+ const isa = raw.impersonatedServiceAccount;
514
+ if (isa !== void 0 && isa !== null && typeof isa !== "string") return {
515
+ ok: false,
516
+ error: "Invalid options.impersonatedServiceAccount for Google Cloud Storage artifact source."
517
+ };
518
+ const trimmed = typeof isa === "string" ? isa.trim() : "";
519
+ return {
520
+ ok: true,
521
+ gcsOptions: trimmed === "" ? void 0 : { impersonatedServiceAccount: trimmed }
522
+ };
523
+ }
417
524
  async function readJsonBody(request) {
418
525
  const chunks = [];
419
526
  for await (const chunk of request) chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
@@ -484,8 +591,14 @@ async function respondArtifactConfigure(req, res, service) {
484
591
  sendJson(res, 400, { error: "Invalid or missing type (expected local, s3, or gcs)." });
485
592
  return;
486
593
  }
594
+ const kind = typeRaw;
595
+ const parsedOptions = parseArtifactSourceRequestOptions(kind, body);
596
+ if (!parsedOptions.ok) {
597
+ sendJson(res, 400, { error: parsedOptions.error });
598
+ return;
599
+ }
487
600
  try {
488
- sendJson(res, 200, await service.configureArtifactSource(typeRaw, location, runId));
601
+ sendJson(res, 200, await service.configureArtifactSource(kind, location, runId, parsedOptions.gcsOptions));
489
602
  } catch (error) {
490
603
  sendJson(res, 400, { error: error instanceof Error ? error.message : "Invalid configuration." });
491
604
  }
@@ -499,8 +612,14 @@ async function respondArtifactDiscover(req, res, service) {
499
612
  sendJson(res, 400, { error: "Invalid or missing type (expected local, s3, or gcs)." });
500
613
  return;
501
614
  }
615
+ const kind = typeRaw;
616
+ const parsedOptions = parseArtifactSourceRequestOptions(kind, body);
617
+ if (!parsedOptions.ok) {
618
+ sendJson(res, 400, { error: parsedOptions.error });
619
+ return;
620
+ }
502
621
  try {
503
- sendJson(res, 200, await service.discoverArtifactSource(typeRaw, location));
622
+ sendJson(res, 200, await service.discoverArtifactSource(kind, location, parsedOptions.gcsOptions));
504
623
  } catch (error) {
505
624
  sendJson(res, 400, { error: error instanceof Error ? error.message : "Invalid configuration." });
506
625
  }
@@ -551,7 +670,7 @@ var __dirname = path.dirname(fileURLToPath(import.meta.url));
551
670
  var DIST_DIR = path.resolve(__dirname, "../../dist");
552
671
  var DIST_ROOT_REAL;
553
672
  try {
554
- DIST_ROOT_REAL = fs.realpathSync(DIST_DIR);
673
+ DIST_ROOT_REAL = realpathValidatedSync(DIST_DIR);
555
674
  } catch {
556
675
  DIST_ROOT_REAL = path.resolve(DIST_DIR);
557
676
  }
@@ -586,7 +705,7 @@ function toSafeAbsoluteUnderDist(candidatePath) {
586
705
  if (rel.startsWith("..") || path.isAbsolute(rel)) return INDEX_HTML;
587
706
  const underReal = path.join(DIST_ROOT_REAL, rel);
588
707
  try {
589
- const canonical = fs.realpathSync(underReal);
708
+ const canonical = realpathValidatedSync(underReal);
590
709
  return isContainedUnderRoot(DIST_ROOT_REAL, canonical) ? canonical : INDEX_HTML;
591
710
  } catch {
592
711
  return underReal;
@@ -607,7 +726,7 @@ function resolveStaticPath(urlPath) {
607
726
  const resolved = path.resolve(DIST_DIR, relativeSegment);
608
727
  if (!isContainedUnderRoot(DIST_DIR, resolved)) return INDEX_HTML;
609
728
  try {
610
- const canonical = fs.realpathSync(resolved);
729
+ const canonical = realpathValidatedSync(resolved);
611
730
  if (!isContainedUnderRoot(DIST_ROOT_REAL, canonical)) return INDEX_HTML;
612
731
  return canonical;
613
732
  } catch {
@@ -626,7 +745,7 @@ function sendInternalError(res, destroyIfPartial) {
626
745
  }
627
746
  function sendFileWithOptionalSpaFallback(primaryPath, res, allowSpaFallback) {
628
747
  const safePath = toSafeAbsoluteUnderDist(primaryPath);
629
- const stream = fs.createReadStream(safePath);
748
+ const stream = createReadStreamValidated(safePath);
630
749
  stream.on("error", () => {
631
750
  stream.destroy();
632
751
  if (allowSpaFallback && !res.headersSent) {
@@ -635,8 +754,8 @@ function sendFileWithOptionalSpaFallback(primaryPath, res, allowSpaFallback) {
635
754
  }
636
755
  sendInternalError(res, true);
637
756
  });
638
- const ext = path.extname(safePath).toLowerCase();
639
- res.setHeader("Content-Type", MIME[ext] ?? "application/octet-stream");
757
+ const mime = getObjectProperty(MIME, path.extname(safePath).toLowerCase()) ?? "application/octet-stream";
758
+ res.setHeader("Content-Type", mime);
640
759
  res.statusCode = 200;
641
760
  stream.pipe(res);
642
761
  }
@@ -644,7 +763,7 @@ function serveStaticFile(filePath, res) {
644
763
  const safeResolved = toSafeAbsoluteUnderDist(filePath);
645
764
  const safeIndex = toSafeAbsoluteUnderDist(INDEX_HTML);
646
765
  let target = safeResolved;
647
- if (!fs.existsSync(target) || fs.statSync(target).isDirectory()) target = safeIndex;
766
+ if (!existsValidated(target) || statValidatedSync(target).isDirectory()) target = safeIndex;
648
767
  sendFileWithOptionalSpaFallback(target, res, safeResolved !== safeIndex);
649
768
  }
650
769
  function sendApiNotFound(res) {
@@ -678,113 +797,6 @@ function startServer(port) {
678
797
  });
679
798
  }
680
799
  //#endregion
681
- //#region src/server/cli-args.ts
682
- /** Pure CLI argument parsing for `dbt-tools-web` (testable without starting the server). */
683
- var USAGE = `
684
- Usage: dbt-tools-web [options]
685
-
686
- --target <dir> Path to dbt target directory (sets DBT_TOOLS_TARGET_DIR)
687
- --port <n> Port to listen on (default: 3000)
688
- --help Show this help message
689
- `.trimStart();
690
- function readRequiredValue(argv, i, flagDesc) {
691
- const next = argv[i + 1];
692
- if (!next || next.startsWith("-")) return {
693
- ok: false,
694
- message: `Missing value for ${flagDesc}`
695
- };
696
- return {
697
- ok: true,
698
- value: next,
699
- nextIndex: i + 1
700
- };
701
- }
702
- function parsePortString(s) {
703
- const parsed = Number.parseInt(s, 10);
704
- if (Number.isNaN(parsed) || parsed < 1 || parsed > 65535) return null;
705
- return parsed;
706
- }
707
- function consumeOne(argv, i, state) {
708
- const arg = argv[i];
709
- if (arg === "--help" || arg === "-h") return {
710
- status: "done",
711
- result: { kind: "help" }
712
- };
713
- if (arg === "--no-open") return {
714
- status: "advance",
715
- nextIndex: i + 1
716
- };
717
- if (arg === "--target" || arg === "-t") {
718
- const r = readRequiredValue(argv, i, "--target (or -t)");
719
- if (!r.ok) return {
720
- status: "done",
721
- result: {
722
- kind: "error",
723
- message: r.message
724
- }
725
- };
726
- state.targetDir = r.value;
727
- return {
728
- status: "advance",
729
- nextIndex: r.nextIndex + 1
730
- };
731
- }
732
- if (arg === "--port" || arg === "-p") {
733
- const r = readRequiredValue(argv, i, "--port (or -p)");
734
- if (!r.ok) return {
735
- status: "done",
736
- result: {
737
- kind: "error",
738
- message: r.message
739
- }
740
- };
741
- const p = parsePortString(r.value);
742
- if (p === null) return {
743
- status: "done",
744
- result: {
745
- kind: "error",
746
- message: `Invalid port: ${r.value}`
747
- }
748
- };
749
- state.port = p;
750
- return {
751
- status: "advance",
752
- nextIndex: r.nextIndex + 1
753
- };
754
- }
755
- if (arg.startsWith("-")) return {
756
- status: "done",
757
- result: {
758
- kind: "error",
759
- message: `Unknown option: ${arg}`
760
- }
761
- };
762
- return {
763
- status: "done",
764
- result: {
765
- kind: "error",
766
- message: `Unexpected argument: ${arg}`
767
- }
768
- };
769
- }
770
- function parseCliArgs(argv) {
771
- const state = {
772
- targetDir: void 0,
773
- port: 3e3
774
- };
775
- let i = 0;
776
- while (i < argv.length) {
777
- const step = consumeOne(argv, i, state);
778
- if (step.status === "done") return step.result;
779
- i = step.nextIndex;
780
- }
781
- return {
782
- kind: "ok",
783
- targetDir: state.targetDir,
784
- port: state.port
785
- };
786
- }
787
- //#endregion
788
800
  //#region src/server/cli.ts
789
801
  var parsed = parseCliArgs(process.argv.slice(2));
790
802
  if (parsed.kind === "help") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dbt-tools/web",
3
- "version": "0.5.8",
3
+ "version": "0.6.0",
4
4
  "description": "Browser UI for deterministic dbt artifact investigation — dependencies, execution timelines, inventory (no LLM required)",
5
5
  "keywords": [
6
6
  "dbt",
@@ -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.5.8"
41
+ "@dbt-tools/core": "0.6.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@playwright/test": "^1.59.1",
@@ -53,13 +53,16 @@
53
53
  "access": "public"
54
54
  },
55
55
  "scripts": {
56
- "build": "pnpm --filter @dbt-tools/core build && tsc && vite build && pnpm run build:serve",
56
+ "build": "pnpm --filter @dbt-tools/core build && tsc -p tsconfig.build.json && vite build && pnpm run build:serve",
57
57
  "build:serve": "vite build --config vite.server.config.ts",
58
58
  "dev": "vite",
59
59
  "dev:debug": "DBT_TOOLS_DEBUG=1 vite",
60
60
  "dev:target": "DBT_TOOLS_TARGET_DIR=./target vite",
61
61
  "preview": "vite preview",
62
+ "test": "vitest run --project @dbt-tools/web",
63
+ "test:watch": "vitest --project @dbt-tools/web",
62
64
  "test:e2e": "pnpm build && playwright test",
65
+ "demo:reel": "pnpm build && playwright test --config=playwright.demo.config.ts",
63
66
  "lint": "pnpm lint:eslint && pnpm lint:stylelint",
64
67
  "lint:eslint": "eslint ../../eslint.config.mjs",
65
68
  "lint:stylelint": "stylelint -c ../../stylelint.config.mjs **/*.css",