@dbt-tools/web 0.3.7 → 0.4.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.
- package/README.md +116 -141
- package/dist/assets/analysis.worker-DCy3HfXU.js +1 -0
- package/dist/assets/index-ChMNDJZo.css +1 -0
- package/dist/assets/index-siMZqYEh.js +31 -0
- package/dist/assets/resultsQuery.worker-DeSSHvCv.js +1 -0
- package/dist/index.html +2 -3
- package/dist-serve/server/cli.js +528 -0
- package/package.json +14 -5
- package/dist/assets/analysis.worker-uCmLG0eu.js +0 -1
- package/dist/assets/index-Bd6Bx1iO.css +0 -1
- package/dist/assets/index-BhxYA8Y1.js +0 -2
- package/dist/assets/recharts-vendor-Ds9sjKZG.js +0 -33
- package/dist/assets/resultsQuery.worker-BAssRVck.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(){let e={accent:`#635BFF`,text:`#171C28`,textSoft:`#6B7385`,bg:`#F6F7FB`,bgSoft:`#FFFFFF`,borderDefault:`#D7DCE7`,borderSubtle:`#E6E9F0`,slate:`#64748B`,rose:`#C0352B`,mint:`#0F8A4B`,amber:`#A56315`},t={accent:`#8A7CFF`,text:`#F3F6FC`,textSoft:`#98A3BC`,bg:`#0D1120`,bgSoft:`#151A2E`,borderDefault:`#313A58`,borderSubtle:`#262E47`,slate:`#8690AA`,rose:`#FF8D86`,mint:`#59D38C`,amber:`#F5B95C`};e.mint,e.rose,e.slate,e.rose,e.mint,e.rose,e.amber,e.slate,t.mint,t.rose,t.slate,t.rose,t.mint,t.rose,t.amber,t.slate,e.text,e.textSoft,e.slate,e.accent,t.text,t.textSoft,t.slate,t.accent;let n=new Set([`model`,`seed`,`snapshot`,`source`,`source_freshness`,`test`,`unit_test`,`metric`,`semantic_model`]),r=new Set([`test`,`unit_test`]);[...n].filter(e=>!r.has(e)).sort((e,t)=>e.localeCompare(t));function i(e,t){return t===`all`?!0:t===`issues`?e.statusTone===`danger`||e.statusTone===`warning`:e.statusTone===t}function a(e){return e.slice(8)}function o(e){return e.startsWith(`adapter:`)}function s(e,t){return e.adapterResponseFields?.find(e=>e.key===t)}function c(){return{all:0,positive:0,warning:0,danger:0}}function l(){return{all:0,models:0,tests:0,seeds:0,snapshots:0,operations:0,healthy:0,warnings:0,errors:0,issues:0}}function u(e){let t=[...(e.adapterResponseFields??[]).flatMap(e=>[e.key,e.displayValue]),...e.adapterMetrics?[e.adapterMetrics.adapterMessage??``,e.adapterMetrics.rawKeys.join(` `)]:[]];return[e.name,e.resourceType,e.packageName,e.path??``,e.uniqueId,e.status,e.threadId??``,...t].join(` `).toLowerCase()}function d(e){return e.trim().toLowerCase()}function f(e,t){return i(e,t)}function p(e){return r.has(e.resourceType)?`tests`:e.resourceType===`seed`?`seeds`:e.resourceType===`snapshot`?`snapshots`:e.resourceType===`operation`||e.resourceType===`sql_operation`||e.resourceType===`macro`?`operations`:`models`}function m(e,t){return t===`all`||p(e)===t}function h(e,t){return t===`all`?!0:t===`fast`?e.executionTime<1:t===`medium`?e.executionTime>=1&&e.executionTime<5:e.executionTime>=5}function g(e,t){let n=e===void 0,r=t===void 0;return n&&r?0:n?1:r?-1:typeof e==`number`&&typeof t==`number`?t-e:String(e).localeCompare(String(t),void 0,{numeric:!0,sensitivity:`base`})}function _(e,t,n){switch(n){case`duration`:return t.executionTime-e.executionTime;case`name`:return e.name.localeCompare(t.name);case`status`:return e.status.localeCompare(t.status);case`start`:return(t.start??0)-(e.start??0);default:if(o(n)){let r=a(n),i=s(e,r),o=s(t,r);return!i?.isScalar&&!o?.isScalar?0:i?.isScalar?o?.isScalar?g(i.sortValue,o.sortValue):-1:1}{let n={danger:0,warning:1,positive:2,skipped:3,neutral:4},r=n[e.statusTone]-n[t.statusTone];return r===0?t.executionTime-e.executionTime:r}case`attention`:{let n={danger:0,warning:1,positive:2,skipped:3,neutral:4},r=n[e.statusTone]-n[t.statusTone];return r===0?t.executionTime-e.executionTime:r}}}function v(e){let t=c(),n=l(),r={},i={};t.all=e.length,n.all=e.length;for(let a of e){let{row:e}=a;e.statusTone===`positive`?(t.positive+=1,n.healthy+=1):e.statusTone===`warning`?(t.warning+=1,n.warnings+=1,n.issues+=1):e.statusTone===`danger`&&(t.danger+=1,n.errors+=1,n.issues+=1),n[p(e)]+=1,r[e.resourceType]=(r[e.resourceType]??0)+1,e.threadId&&(i[e.threadId]=(i[e.threadId]??0)+1)}return{status:t,facets:n,resourceTypes:r,threadIds:i}}function y(e){let t=e.map(e=>({row:e,searchText:u(e)}));return{entries:t,summary:v(t)}}function b(e,t){let n=d(t.query),r=new Set(t.resourceTypes),i=new Set(t.threadIds),a=e.entries.filter(e=>{let{row:a}=e;return!(!m(a,t.kind)||!f(a,t.status)||n!==``&&!e.searchText.includes(n)||r.size>0&&!r.has(a.resourceType)||i.size>0&&!i.has(a.threadId??``)||!h(a,t.durationBand))}),o=t.sortBy??`attention`;return[...a].sort((e,t)=>_(e.row,t.row,o))}let x=null,S=null,C=[];function w(e){self.postMessage({type:`error`,message:e})}self.onmessage=e=>{let t=e.data;if(t.type===`init`){x=y(t.rows),S=null,C=[],self.postMessage({type:`ready`,summary:x.summary});return}if(x==null){w(`Results worker queried before initialization.`);return}let n=[t.kind,t.status,t.query.trim().toLowerCase(),t.resourceTypes.sort().join(`,`),t.threadIds.sort().join(`,`),t.durationBand,t.sortBy].join(`::`);n!==S&&(C=b(x,{kind:t.kind,status:t.status,query:t.query,resourceTypes:t.resourceTypes,threadIds:t.threadIds,durationBand:t.durationBand,sortBy:t.sortBy}),S=n);let r=C.slice(0,t.limit);self.postMessage({type:`query-result`,requestId:t.requestId,rows:r.map(e=>e.row),totalMatches:C.length,summary:{status:{all:C.length,positive:C.filter(e=>e.row.statusTone===`positive`).length,warning:C.filter(e=>e.row.statusTone===`warning`).length,danger:C.filter(e=>e.row.statusTone===`danger`).length},facets:{all:C.length,models:C.filter(e=>{let t=e.row.resourceType;return t!==`test`&&t!==`unit_test`&&t!==`seed`&&t!==`snapshot`&&t!==`operation`&&t!==`sql_operation`&&t!==`macro`}).length,tests:C.filter(e=>e.row.resourceType===`test`||e.row.resourceType===`unit_test`).length,seeds:C.filter(e=>e.row.resourceType===`seed`).length,snapshots:C.filter(e=>e.row.resourceType===`snapshot`).length,operations:C.filter(e=>[`operation`,`sql_operation`,`macro`].includes(e.row.resourceType)).length,healthy:C.filter(e=>e.row.statusTone===`positive`).length,warnings:C.filter(e=>e.row.statusTone===`warning`).length,errors:C.filter(e=>e.row.statusTone===`danger`).length,issues:C.filter(e=>e.row.statusTone===`danger`||e.row.statusTone===`warning`).length},resourceTypes:Object.fromEntries(Object.entries(r.reduce((e,t)=>(e[t.row.resourceType]=(e[t.row.resourceType]??0)+1,e),{}))),threadIds:Object.fromEntries(Object.entries(r.reduce((e,t)=>(t.row.threadId&&(e[t.row.threadId]=(e[t.row.threadId]??0)+1),e),{})))}})}})();
|
package/dist/index.html
CHANGED
|
@@ -11,12 +11,11 @@
|
|
|
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-
|
|
14
|
+
<script type="module" crossorigin src="/assets/index-siMZqYEh.js"></script>
|
|
15
15
|
<link rel="modulepreload" crossorigin href="/assets/rolldown-runtime-Dw2cE7zH.js">
|
|
16
16
|
<link rel="modulepreload" crossorigin href="/assets/react-vendor-DL38pS2M.js">
|
|
17
|
-
<link rel="modulepreload" crossorigin href="/assets/recharts-vendor-Ds9sjKZG.js">
|
|
18
17
|
<link rel="modulepreload" crossorigin href="/assets/tanstack-virtual-vendor-DdCr1qam.js">
|
|
19
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
18
|
+
<link rel="stylesheet" crossorigin href="/assets/index-ChMNDJZo.css">
|
|
20
19
|
</head>
|
|
21
20
|
<body>
|
|
22
21
|
<div id="root"></div>
|
|
@@ -0,0 +1,528 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { exec } from "node:child_process";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import http from "node:http";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
import fs$1 from "node:fs/promises";
|
|
8
|
+
import { DBT_MANIFEST_JSON, DBT_RUN_RESULTS_JSON, getDbtToolsRemoteSourceConfigFromEnv, getDbtToolsTargetDirFromEnv, isDbtToolsDebugEnabled } from "@dbt-tools/core";
|
|
9
|
+
import { GetObjectCommand, ListObjectsV2Command, S3Client } from "@aws-sdk/client-s3";
|
|
10
|
+
import { Storage } from "@google-cloud/storage";
|
|
11
|
+
//#region src/artifact-source/prefix.ts
|
|
12
|
+
/** Trim leading/trailing slashes for object-store key prefix handling. */
|
|
13
|
+
function normalizeArtifactPrefix(prefix) {
|
|
14
|
+
return prefix.replace(/^\/+|\/+$/g, "");
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/artifact-source/discovery.ts
|
|
18
|
+
function toRelativeKey(key, prefix) {
|
|
19
|
+
const normalizedKey = key.replace(/^\/+/, "");
|
|
20
|
+
const normalizedPrefix = normalizeArtifactPrefix(prefix);
|
|
21
|
+
if (normalizedPrefix === "") return normalizedKey;
|
|
22
|
+
if (normalizedKey === normalizedPrefix) return "";
|
|
23
|
+
if (normalizedKey.startsWith(`${normalizedPrefix}/`)) return normalizedKey.slice(normalizedPrefix.length + 1);
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
function runIdForKey(relativeKey) {
|
|
27
|
+
const dir = path.posix.dirname(relativeKey);
|
|
28
|
+
return dir === "." ? "current" : dir;
|
|
29
|
+
}
|
|
30
|
+
function versionTokenForKeys(parts) {
|
|
31
|
+
return parts.map((part) => [
|
|
32
|
+
part.key,
|
|
33
|
+
part.updatedAtMs,
|
|
34
|
+
part.etag ?? "",
|
|
35
|
+
part.generation ?? ""
|
|
36
|
+
].join(":")).join("|");
|
|
37
|
+
}
|
|
38
|
+
function discoverLatestArtifactRuns(objects, prefix) {
|
|
39
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
40
|
+
for (const object of objects) {
|
|
41
|
+
const relativeKey = toRelativeKey(object.key, prefix);
|
|
42
|
+
if (relativeKey == null) continue;
|
|
43
|
+
const fileName = path.posix.basename(relativeKey);
|
|
44
|
+
if (fileName !== DBT_MANIFEST_JSON && fileName !== DBT_RUN_RESULTS_JSON) continue;
|
|
45
|
+
const runId = runIdForKey(relativeKey);
|
|
46
|
+
const current = grouped.get(runId) ?? {};
|
|
47
|
+
if (fileName === DBT_MANIFEST_JSON) current.manifest = object;
|
|
48
|
+
if (fileName === DBT_RUN_RESULTS_JSON) current.runResults = object;
|
|
49
|
+
grouped.set(runId, current);
|
|
50
|
+
}
|
|
51
|
+
return [...grouped.entries()].flatMap(([runId, parts]) => {
|
|
52
|
+
if (parts.manifest == null || parts.runResults == null) return [];
|
|
53
|
+
return [{
|
|
54
|
+
runId,
|
|
55
|
+
manifestKey: parts.manifest.key,
|
|
56
|
+
runResultsKey: parts.runResults.key,
|
|
57
|
+
updatedAtMs: Math.max(parts.manifest.updatedAtMs, parts.runResults.updatedAtMs),
|
|
58
|
+
versionToken: versionTokenForKeys([parts.manifest, parts.runResults])
|
|
59
|
+
}];
|
|
60
|
+
}).sort((left, right) => {
|
|
61
|
+
if (right.updatedAtMs !== left.updatedAtMs) return right.updatedAtMs - left.updatedAtMs;
|
|
62
|
+
return right.runId.localeCompare(left.runId);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
function toRemoteArtifactRun(provider, run) {
|
|
66
|
+
return {
|
|
67
|
+
runId: run.runId,
|
|
68
|
+
label: run.runId === "current" ? `${provider.toUpperCase()} current` : `${provider.toUpperCase()} ${run.runId}`,
|
|
69
|
+
updatedAtMs: run.updatedAtMs,
|
|
70
|
+
versionToken: run.versionToken
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region src/artifact-source/remoteObjectStore.ts
|
|
75
|
+
var S3RemoteObjectStoreClient = class {
|
|
76
|
+
client;
|
|
77
|
+
constructor(config) {
|
|
78
|
+
this.client = new S3Client({
|
|
79
|
+
region: config.region,
|
|
80
|
+
endpoint: config.endpoint,
|
|
81
|
+
forcePathStyle: config.forcePathStyle
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
async listObjects(bucket, prefix) {
|
|
85
|
+
const results = [];
|
|
86
|
+
let continuationToken;
|
|
87
|
+
do {
|
|
88
|
+
const response = await this.client.send(new ListObjectsV2Command({
|
|
89
|
+
Bucket: bucket,
|
|
90
|
+
Prefix: prefix === "" ? void 0 : `${prefix}/`,
|
|
91
|
+
ContinuationToken: continuationToken
|
|
92
|
+
}));
|
|
93
|
+
for (const object of response.Contents ?? []) {
|
|
94
|
+
if (!object.Key || !object.LastModified) continue;
|
|
95
|
+
results.push({
|
|
96
|
+
key: object.Key,
|
|
97
|
+
updatedAtMs: object.LastModified.getTime(),
|
|
98
|
+
etag: object.ETag ?? void 0
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
continuationToken = response.IsTruncated ? response.NextContinuationToken : void 0;
|
|
102
|
+
} while (continuationToken);
|
|
103
|
+
return results;
|
|
104
|
+
}
|
|
105
|
+
async readObjectBytes(bucket, key) {
|
|
106
|
+
const bytes = await (await this.client.send(new GetObjectCommand({
|
|
107
|
+
Bucket: bucket,
|
|
108
|
+
Key: key
|
|
109
|
+
}))).Body?.transformToByteArray();
|
|
110
|
+
if (bytes == null) throw new Error(`Missing S3 object body for ${key}`);
|
|
111
|
+
return bytes;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
var GcsRemoteObjectStoreClient = class {
|
|
115
|
+
storage;
|
|
116
|
+
constructor(config) {
|
|
117
|
+
this.storage = new Storage({ projectId: config.projectId });
|
|
118
|
+
}
|
|
119
|
+
async listObjects(bucket, prefix) {
|
|
120
|
+
const [files] = await this.storage.bucket(bucket).getFiles({
|
|
121
|
+
prefix: prefix === "" ? void 0 : `${prefix}/`,
|
|
122
|
+
autoPaginate: true
|
|
123
|
+
});
|
|
124
|
+
return files.flatMap((file) => {
|
|
125
|
+
const updated = file.metadata.updated;
|
|
126
|
+
if (!updated) return [];
|
|
127
|
+
return [{
|
|
128
|
+
key: file.name,
|
|
129
|
+
updatedAtMs: new Date(updated).getTime(),
|
|
130
|
+
etag: file.metadata.etag,
|
|
131
|
+
generation: file.metadata.generation == null ? void 0 : String(file.metadata.generation)
|
|
132
|
+
}];
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
async readObjectBytes(bucket, key) {
|
|
136
|
+
const [bytes] = await this.storage.bucket(bucket).file(key).download();
|
|
137
|
+
return bytes;
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
function createRemoteObjectStoreClient(config) {
|
|
141
|
+
return config.provider === "s3" ? new S3RemoteObjectStoreClient(config) : new GcsRemoteObjectStoreClient(config);
|
|
142
|
+
}
|
|
143
|
+
//#endregion
|
|
144
|
+
//#region src/artifact-source/resolveLocalTargetDir.ts
|
|
145
|
+
function expandDbtTargetDirFromEnvValue(targetDir) {
|
|
146
|
+
return targetDir.replace(/^~($|\/)/, `${process.env.HOME ?? ""}$1`).trim();
|
|
147
|
+
}
|
|
148
|
+
function resolveLocalArtifactTargetDirFromEnv(cwd, rawTargetDir) {
|
|
149
|
+
return path.resolve(cwd, expandDbtTargetDirFromEnvValue(rawTargetDir));
|
|
150
|
+
}
|
|
151
|
+
//#endregion
|
|
152
|
+
//#region src/artifact-source/sourceService.ts
|
|
153
|
+
/** Node (Vite dev) service: local target dir vs remote S3/GCS; drives middleware routes. */
|
|
154
|
+
function debugLog(...args) {
|
|
155
|
+
if (isDbtToolsDebugEnabled()) console.log("[artifact-source]", ...args);
|
|
156
|
+
}
|
|
157
|
+
function toLocationLabel(provider, bucket, prefix) {
|
|
158
|
+
return `${provider.toUpperCase()} ${bucket}/${prefix}`;
|
|
159
|
+
}
|
|
160
|
+
function toArtifactSourceStatus(status) {
|
|
161
|
+
return {
|
|
162
|
+
...status,
|
|
163
|
+
checkedAtMs: Date.now()
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
var LocalArtifactSourceAdapter = class {
|
|
167
|
+
constructor(targetDir) {
|
|
168
|
+
this.targetDir = targetDir;
|
|
169
|
+
}
|
|
170
|
+
async getStatus() {
|
|
171
|
+
return toArtifactSourceStatus({
|
|
172
|
+
mode: "preload",
|
|
173
|
+
currentSource: "preload",
|
|
174
|
+
label: "Live target",
|
|
175
|
+
remoteProvider: null,
|
|
176
|
+
remoteLocation: null,
|
|
177
|
+
pollIntervalMs: null,
|
|
178
|
+
currentRun: null,
|
|
179
|
+
pendingRun: null,
|
|
180
|
+
supportsSwitch: false
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
async getCurrentArtifacts() {
|
|
184
|
+
try {
|
|
185
|
+
const [manifestBytes, runResultsBytes] = await Promise.all([fs$1.readFile(path.join(this.targetDir, DBT_MANIFEST_JSON)), fs$1.readFile(path.join(this.targetDir, DBT_RUN_RESULTS_JSON))]);
|
|
186
|
+
return {
|
|
187
|
+
source: "preload",
|
|
188
|
+
manifestBytes,
|
|
189
|
+
runResultsBytes
|
|
190
|
+
};
|
|
191
|
+
} catch {
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
async switchToRun() {
|
|
196
|
+
return this.getStatus();
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
var RemoteArtifactSourceAdapter = class {
|
|
200
|
+
currentRunId = null;
|
|
201
|
+
constructor(config, client) {
|
|
202
|
+
this.config = config;
|
|
203
|
+
this.client = client;
|
|
204
|
+
}
|
|
205
|
+
async resolveRuns() {
|
|
206
|
+
return discoverLatestArtifactRuns(await this.client.listObjects(this.config.bucket, normalizeArtifactPrefix(this.config.prefix)), this.config.prefix);
|
|
207
|
+
}
|
|
208
|
+
chooseCurrentRun(runs) {
|
|
209
|
+
if (runs.length === 0) return null;
|
|
210
|
+
if (this.currentRunId == null) {
|
|
211
|
+
this.currentRunId = runs[0].runId;
|
|
212
|
+
return runs[0];
|
|
213
|
+
}
|
|
214
|
+
const current = runs.find((run) => run.runId === this.currentRunId);
|
|
215
|
+
if (current) return current;
|
|
216
|
+
this.currentRunId = runs[0].runId;
|
|
217
|
+
return runs[0];
|
|
218
|
+
}
|
|
219
|
+
async getStatus() {
|
|
220
|
+
const runs = await this.resolveRuns();
|
|
221
|
+
const currentRun = this.chooseCurrentRun(runs);
|
|
222
|
+
const latestRun = runs[0] ?? null;
|
|
223
|
+
const pendingRun = latestRun != null && currentRun != null && latestRun.runId !== currentRun.runId ? latestRun : null;
|
|
224
|
+
return toArtifactSourceStatus({
|
|
225
|
+
mode: "remote",
|
|
226
|
+
currentSource: currentRun == null ? null : "remote",
|
|
227
|
+
label: "Remote source",
|
|
228
|
+
remoteProvider: this.config.provider,
|
|
229
|
+
remoteLocation: toLocationLabel(this.config.provider, this.config.bucket, normalizeArtifactPrefix(this.config.prefix)),
|
|
230
|
+
pollIntervalMs: this.config.pollIntervalMs,
|
|
231
|
+
currentRun: currentRun == null ? null : toRemoteArtifactRun(this.config.provider, currentRun),
|
|
232
|
+
pendingRun: pendingRun == null ? null : toRemoteArtifactRun(this.config.provider, pendingRun),
|
|
233
|
+
supportsSwitch: pendingRun != null
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
async getCurrentArtifacts() {
|
|
237
|
+
const runs = await this.resolveRuns();
|
|
238
|
+
const currentRun = this.chooseCurrentRun(runs);
|
|
239
|
+
if (currentRun == null) return null;
|
|
240
|
+
const [manifestBytes, runResultsBytes] = await Promise.all([this.client.readObjectBytes(this.config.bucket, currentRun.manifestKey), this.client.readObjectBytes(this.config.bucket, currentRun.runResultsKey)]);
|
|
241
|
+
return {
|
|
242
|
+
source: "remote",
|
|
243
|
+
manifestBytes,
|
|
244
|
+
runResultsBytes
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
async switchToRun(runId) {
|
|
248
|
+
const runs = await this.resolveRuns();
|
|
249
|
+
const target = runId == null ? runs[0] : runs.find((candidate) => candidate.runId === runId);
|
|
250
|
+
if (target != null) {
|
|
251
|
+
this.currentRunId = target.runId;
|
|
252
|
+
debugLog("Switched remote artifact run", this.currentRunId);
|
|
253
|
+
}
|
|
254
|
+
return this.getStatus();
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
var ArtifactSourceService = class {
|
|
258
|
+
adapter;
|
|
259
|
+
constructor(options = {}) {
|
|
260
|
+
if (options.adapter !== void 0) {
|
|
261
|
+
this.adapter = options.adapter;
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
const remoteConfig = options.remoteConfig === void 0 ? getDbtToolsRemoteSourceConfigFromEnv() : options.remoteConfig;
|
|
265
|
+
if (remoteConfig != null) {
|
|
266
|
+
debugLog("Configured remote artifact source", remoteConfig.provider, remoteConfig.bucket, remoteConfig.prefix);
|
|
267
|
+
this.adapter = new RemoteArtifactSourceAdapter(remoteConfig, options.remoteClient ?? createRemoteObjectStoreClient(remoteConfig));
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
const targetDir = options.targetDir === void 0 ? getDbtToolsTargetDirFromEnv() : options.targetDir;
|
|
271
|
+
if (targetDir == null) {
|
|
272
|
+
this.adapter = null;
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
this.adapter = new LocalArtifactSourceAdapter(resolveLocalArtifactTargetDirFromEnv(process.cwd(), targetDir));
|
|
276
|
+
}
|
|
277
|
+
async getStatus() {
|
|
278
|
+
if (this.adapter == null) return toArtifactSourceStatus({
|
|
279
|
+
mode: "none",
|
|
280
|
+
currentSource: null,
|
|
281
|
+
label: "Waiting for artifacts",
|
|
282
|
+
remoteProvider: null,
|
|
283
|
+
remoteLocation: null,
|
|
284
|
+
pollIntervalMs: null,
|
|
285
|
+
currentRun: null,
|
|
286
|
+
pendingRun: null,
|
|
287
|
+
supportsSwitch: false
|
|
288
|
+
});
|
|
289
|
+
return this.adapter.getStatus();
|
|
290
|
+
}
|
|
291
|
+
async getCurrentArtifacts() {
|
|
292
|
+
return this.adapter?.getCurrentArtifacts() ?? null;
|
|
293
|
+
}
|
|
294
|
+
async switchToRun(runId) {
|
|
295
|
+
if (this.adapter == null) return this.getStatus();
|
|
296
|
+
return this.adapter.switchToRun(runId);
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
//#endregion
|
|
300
|
+
//#region src/artifact-source/viteArtifactRoutes.ts
|
|
301
|
+
async function readJsonBody(request) {
|
|
302
|
+
const chunks = [];
|
|
303
|
+
for await (const chunk of request) chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
304
|
+
if (chunks.length === 0) return {};
|
|
305
|
+
try {
|
|
306
|
+
return JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
307
|
+
} catch {
|
|
308
|
+
return {};
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
function sendJson(res, statusCode, payload) {
|
|
312
|
+
res.setHeader("Content-Type", "application/json");
|
|
313
|
+
res.statusCode = statusCode;
|
|
314
|
+
res.end(JSON.stringify(payload));
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Vite middleware handler for artifact-source HTTP routes. Returns `true` when
|
|
318
|
+
* the request was fully handled (response ended).
|
|
319
|
+
*/
|
|
320
|
+
async function tryHandleArtifactSourceViteRequest(req, res, service) {
|
|
321
|
+
const pathname = req.url?.split("?")[0];
|
|
322
|
+
if (!pathname) return false;
|
|
323
|
+
if (req.method === "GET" && pathname === "/api/artifact-source") {
|
|
324
|
+
sendJson(res, 200, await service.getStatus());
|
|
325
|
+
return true;
|
|
326
|
+
}
|
|
327
|
+
if (req.method === "POST" && pathname === "/api/artifact-source/switch") {
|
|
328
|
+
const body = await readJsonBody(req);
|
|
329
|
+
const runId = typeof body.runId === "string" && body.runId.trim() !== "" ? body.runId : void 0;
|
|
330
|
+
sendJson(res, 200, await service.switchToRun(runId));
|
|
331
|
+
return true;
|
|
332
|
+
}
|
|
333
|
+
if (req.method === "GET" && (pathname === `/api/${DBT_MANIFEST_JSON}` || pathname === `/api/artifacts/current/${DBT_MANIFEST_JSON}` || pathname === `/api/${DBT_RUN_RESULTS_JSON}` || pathname === `/api/artifacts/current/${DBT_RUN_RESULTS_JSON}`)) {
|
|
334
|
+
const current = await service.getCurrentArtifacts();
|
|
335
|
+
if (current == null) {
|
|
336
|
+
res.statusCode = 404;
|
|
337
|
+
res.end();
|
|
338
|
+
return true;
|
|
339
|
+
}
|
|
340
|
+
const bytes = pathname.endsWith(DBT_MANIFEST_JSON) ? current.manifestBytes : current.runResultsBytes;
|
|
341
|
+
res.setHeader("Content-Type", "application/json");
|
|
342
|
+
res.statusCode = 200;
|
|
343
|
+
res.end(Buffer.from(bytes));
|
|
344
|
+
return true;
|
|
345
|
+
}
|
|
346
|
+
return false;
|
|
347
|
+
}
|
|
348
|
+
//#endregion
|
|
349
|
+
//#region src/server/serve.ts
|
|
350
|
+
var __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
351
|
+
var DIST_DIR = path.resolve(__dirname, "../../dist");
|
|
352
|
+
var DIST_ROOT_REAL;
|
|
353
|
+
try {
|
|
354
|
+
DIST_ROOT_REAL = fs.realpathSync(DIST_DIR);
|
|
355
|
+
} catch {
|
|
356
|
+
DIST_ROOT_REAL = path.resolve(DIST_DIR);
|
|
357
|
+
}
|
|
358
|
+
var INDEX_HTML = path.join(DIST_DIR, "index.html");
|
|
359
|
+
/** Loopback host used for listen and advertised URLs (IPv4; avoids localhost → ::1 mismatch). */
|
|
360
|
+
var LISTEN_HOST = "127.0.0.1";
|
|
361
|
+
var MIME = {
|
|
362
|
+
".html": "text/html; charset=utf-8",
|
|
363
|
+
".js": "application/javascript",
|
|
364
|
+
".mjs": "application/javascript",
|
|
365
|
+
".css": "text/css",
|
|
366
|
+
".json": "application/json",
|
|
367
|
+
".svg": "image/svg+xml",
|
|
368
|
+
".png": "image/png",
|
|
369
|
+
".ico": "image/x-icon",
|
|
370
|
+
".woff": "font/woff",
|
|
371
|
+
".woff2": "font/woff2",
|
|
372
|
+
".ttf": "font/ttf",
|
|
373
|
+
".txt": "text/plain"
|
|
374
|
+
};
|
|
375
|
+
function isContainedUnderRoot(root, candidateResolved) {
|
|
376
|
+
const rel = path.relative(root, candidateResolved);
|
|
377
|
+
return rel === "" || !rel.startsWith("..") && !path.isAbsolute(rel);
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Path safe for `fs.*`: validate relative to logical `DIST_DIR`, then rebuild with
|
|
381
|
+
* `path.join(DIST_ROOT_REAL, rel)` + `realpathSync` so CodeQL `js/path-injection` sees a guarded join.
|
|
382
|
+
*/
|
|
383
|
+
function toSafeAbsoluteUnderDist(candidatePath) {
|
|
384
|
+
const resolvedInput = path.resolve(candidatePath);
|
|
385
|
+
const rel = path.relative(DIST_DIR, resolvedInput);
|
|
386
|
+
if (rel.startsWith("..") || path.isAbsolute(rel)) return INDEX_HTML;
|
|
387
|
+
const underReal = path.join(DIST_ROOT_REAL, rel);
|
|
388
|
+
try {
|
|
389
|
+
const canonical = fs.realpathSync(underReal);
|
|
390
|
+
return isContainedUnderRoot(DIST_ROOT_REAL, canonical) ? canonical : INDEX_HTML;
|
|
391
|
+
} catch {
|
|
392
|
+
return underReal;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* URL path → filesystem path under dist (traversal + symlink escape). Symlinked `DIST_DIR` uses logical containment first.
|
|
397
|
+
*/
|
|
398
|
+
function resolveStaticPath(urlPath) {
|
|
399
|
+
const pathOnly = (urlPath.startsWith("/") ? urlPath : `/${urlPath}`).split("?")[0] ?? "/";
|
|
400
|
+
let decoded;
|
|
401
|
+
try {
|
|
402
|
+
decoded = decodeURIComponent(pathOnly);
|
|
403
|
+
} catch {
|
|
404
|
+
return INDEX_HTML;
|
|
405
|
+
}
|
|
406
|
+
const relativeSegment = decoded.replace(/^\/+/, "") || ".";
|
|
407
|
+
const resolved = path.resolve(DIST_DIR, relativeSegment);
|
|
408
|
+
if (!isContainedUnderRoot(DIST_DIR, resolved)) return INDEX_HTML;
|
|
409
|
+
try {
|
|
410
|
+
const canonical = fs.realpathSync(resolved);
|
|
411
|
+
if (!isContainedUnderRoot(DIST_ROOT_REAL, canonical)) return INDEX_HTML;
|
|
412
|
+
return canonical;
|
|
413
|
+
} catch {
|
|
414
|
+
return resolved;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
function requestPathname(req) {
|
|
418
|
+
return (req.url ?? "/").split("?")[0] ?? "/";
|
|
419
|
+
}
|
|
420
|
+
/** 500 body, or destroy if a response was already started (e.g. mid-stream read failure). */
|
|
421
|
+
function sendInternalError(res, destroyIfPartial) {
|
|
422
|
+
if (!res.headersSent) {
|
|
423
|
+
res.statusCode = 500;
|
|
424
|
+
res.end("Internal server error");
|
|
425
|
+
} else if (destroyIfPartial) res.destroy();
|
|
426
|
+
}
|
|
427
|
+
function sendFileWithOptionalSpaFallback(primaryPath, res, allowSpaFallback) {
|
|
428
|
+
const safePath = toSafeAbsoluteUnderDist(primaryPath);
|
|
429
|
+
const stream = fs.createReadStream(safePath);
|
|
430
|
+
stream.on("error", () => {
|
|
431
|
+
stream.destroy();
|
|
432
|
+
if (allowSpaFallback && !res.headersSent) {
|
|
433
|
+
sendFileWithOptionalSpaFallback(INDEX_HTML, res, false);
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
sendInternalError(res, true);
|
|
437
|
+
});
|
|
438
|
+
const ext = path.extname(safePath).toLowerCase();
|
|
439
|
+
res.setHeader("Content-Type", MIME[ext] ?? "application/octet-stream");
|
|
440
|
+
res.statusCode = 200;
|
|
441
|
+
stream.pipe(res);
|
|
442
|
+
}
|
|
443
|
+
function serveStaticFile(filePath, res) {
|
|
444
|
+
const safeResolved = toSafeAbsoluteUnderDist(filePath);
|
|
445
|
+
const safeIndex = toSafeAbsoluteUnderDist(INDEX_HTML);
|
|
446
|
+
let target = safeResolved;
|
|
447
|
+
if (!fs.existsSync(target) || fs.statSync(target).isDirectory()) target = safeIndex;
|
|
448
|
+
sendFileWithOptionalSpaFallback(target, res, safeResolved !== safeIndex);
|
|
449
|
+
}
|
|
450
|
+
function sendApiNotFound(res) {
|
|
451
|
+
res.statusCode = 404;
|
|
452
|
+
res.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
453
|
+
res.end(JSON.stringify({ error: "not_found" }));
|
|
454
|
+
}
|
|
455
|
+
function startServer(port) {
|
|
456
|
+
const service = new ArtifactSourceService();
|
|
457
|
+
const server = http.createServer((req, res) => {
|
|
458
|
+
(async () => {
|
|
459
|
+
try {
|
|
460
|
+
if (await tryHandleArtifactSourceViteRequest(req, res, service)) return;
|
|
461
|
+
const pathname = requestPathname(req);
|
|
462
|
+
if (pathname === "/api" || pathname.startsWith("/api/")) {
|
|
463
|
+
sendApiNotFound(res);
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
serveStaticFile(resolveStaticPath(req.url ?? "/"), res);
|
|
467
|
+
} catch (err) {
|
|
468
|
+
sendInternalError(res, false);
|
|
469
|
+
console.error("[dbt-tools-web]", err);
|
|
470
|
+
}
|
|
471
|
+
})();
|
|
472
|
+
});
|
|
473
|
+
return new Promise((resolve, reject) => {
|
|
474
|
+
server.once("error", reject);
|
|
475
|
+
server.listen(port, LISTEN_HOST, () => {
|
|
476
|
+
resolve();
|
|
477
|
+
});
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
//#endregion
|
|
481
|
+
//#region src/server/cli.ts
|
|
482
|
+
var USAGE = `
|
|
483
|
+
Usage: dbt-tools-web [options]
|
|
484
|
+
|
|
485
|
+
--target <dir> Path to dbt target directory (sets DBT_TOOLS_TARGET_DIR)
|
|
486
|
+
--port <n> Port to listen on (default: 3000)
|
|
487
|
+
--no-open Do not open the browser automatically
|
|
488
|
+
--help Show this help message
|
|
489
|
+
`.trimStart();
|
|
490
|
+
function parseArgs(argv) {
|
|
491
|
+
let targetDir;
|
|
492
|
+
let port = 3e3;
|
|
493
|
+
let open = true;
|
|
494
|
+
for (let i = 0; i < argv.length; i++) {
|
|
495
|
+
const arg = argv[i];
|
|
496
|
+
if (arg === "--help" || arg === "-h") {
|
|
497
|
+
process.stdout.write(USAGE);
|
|
498
|
+
process.exit(0);
|
|
499
|
+
} else if (arg === "--no-open") open = false;
|
|
500
|
+
else if ((arg === "--target" || arg === "-t") && argv[i + 1]) targetDir = argv[++i];
|
|
501
|
+
else if ((arg === "--port" || arg === "-p") && argv[i + 1]) {
|
|
502
|
+
const parsed = parseInt(argv[++i], 10);
|
|
503
|
+
if (isNaN(parsed) || parsed < 1 || parsed > 65535) {
|
|
504
|
+
process.stderr.write(`Invalid port: ${argv[i]}\n`);
|
|
505
|
+
process.exit(1);
|
|
506
|
+
}
|
|
507
|
+
port = parsed;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
return {
|
|
511
|
+
targetDir,
|
|
512
|
+
port,
|
|
513
|
+
open
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
function openBrowser(url) {
|
|
517
|
+
exec(process.platform === "darwin" ? `open ${url}` : process.platform === "win32" ? `start "" "${url}"` : `xdg-open ${url}`, (err) => {
|
|
518
|
+
if (err) {}
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
var { targetDir, port, open } = parseArgs(process.argv.slice(2));
|
|
522
|
+
if (targetDir !== void 0) process.env.DBT_TOOLS_TARGET_DIR = targetDir;
|
|
523
|
+
await startServer(port);
|
|
524
|
+
var url = `http://${LISTEN_HOST}:${port}`;
|
|
525
|
+
process.stdout.write(`dbt-tools-web ${url}\n`);
|
|
526
|
+
if (open) openBrowser(url);
|
|
527
|
+
//#endregion
|
|
528
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dbt-tools/web",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Web application for visual dbt artifact analysis",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dbt",
|
|
@@ -9,9 +9,16 @@
|
|
|
9
9
|
],
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
11
|
"author": "yu-iskw",
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": ">=20"
|
|
14
|
+
},
|
|
12
15
|
"type": "module",
|
|
16
|
+
"bin": {
|
|
17
|
+
"dbt-tools-web": "./dist-serve/server/cli.js"
|
|
18
|
+
},
|
|
13
19
|
"files": [
|
|
14
20
|
"dist",
|
|
21
|
+
"dist-serve",
|
|
15
22
|
"README.md"
|
|
16
23
|
],
|
|
17
24
|
"dependencies": {
|
|
@@ -20,9 +27,10 @@
|
|
|
20
27
|
"@tanstack/react-virtual": "^3.13.23",
|
|
21
28
|
"react": "^19.2.4",
|
|
22
29
|
"react-dom": "^19.2.4",
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"@dbt-tools/core": "0.
|
|
30
|
+
"react-markdown": "^10.1.0",
|
|
31
|
+
"remark-gfm": "^4.0.1",
|
|
32
|
+
"@dbt-tools/core": "0.4.0",
|
|
33
|
+
"dbt-artifacts-parser": "0.4.0"
|
|
26
34
|
},
|
|
27
35
|
"devDependencies": {
|
|
28
36
|
"@playwright/test": "^1.58.2",
|
|
@@ -37,7 +45,8 @@
|
|
|
37
45
|
"access": "public"
|
|
38
46
|
},
|
|
39
47
|
"scripts": {
|
|
40
|
-
"build": "pnpm --filter @dbt-tools/core build && tsc && vite build",
|
|
48
|
+
"build": "pnpm --filter @dbt-tools/core build && tsc && vite build && pnpm run build:serve",
|
|
49
|
+
"build:serve": "vite build --config vite.server.config.ts",
|
|
41
50
|
"dev": "vite",
|
|
42
51
|
"dev:debug": "DBT_TOOLS_DEBUG=1 vite",
|
|
43
52
|
"dev:target": "DBT_TOOLS_TARGET_DIR=./target vite",
|