@malloydata/malloyyo 0.2.57 → 0.2.58
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +206 -79
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2,11 +2,137 @@
|
|
|
2
2
|
|
|
3
3
|
// src/index.ts
|
|
4
4
|
import { Command } from "commander";
|
|
5
|
+
|
|
6
|
+
// src/update-check.ts
|
|
7
|
+
import { spawn } from "node:child_process";
|
|
8
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
9
|
+
import { homedir, tmpdir } from "node:os";
|
|
10
|
+
import { dirname, join } from "node:path";
|
|
11
|
+
import { fileURLToPath } from "node:url";
|
|
12
|
+
|
|
13
|
+
// package.json
|
|
14
|
+
var version = "0.2.58";
|
|
15
|
+
|
|
16
|
+
// src/update-check.ts
|
|
17
|
+
var UPDATE_CHECK_ARGV = "__update-check";
|
|
18
|
+
var PKG = "@malloydata/malloyyo";
|
|
19
|
+
var CHECK_INTERVAL_MS = 1e3 * 60 * 60 * 24;
|
|
20
|
+
var NOTIFY_INTERVAL_MS = 1e3 * 60 * 60 * 24 * 3;
|
|
21
|
+
var FETCH_TIMEOUT_MS = 3e3;
|
|
22
|
+
var QUIET_COMMANDS = /* @__PURE__ */ new Set(["mcp", "sql", UPDATE_CHECK_ARGV]);
|
|
23
|
+
function cacheDir() {
|
|
24
|
+
const home = homedir();
|
|
25
|
+
if (process.env.MALLOYYO_CACHE_DIR) return process.env.MALLOYYO_CACHE_DIR;
|
|
26
|
+
if (process.platform === "darwin") return join(home, "Library", "Caches", "malloyyo");
|
|
27
|
+
if (process.platform === "win32") {
|
|
28
|
+
return join(process.env.LOCALAPPDATA || join(home, "AppData", "Local"), "malloyyo", "Cache");
|
|
29
|
+
}
|
|
30
|
+
return join(process.env.XDG_CACHE_HOME || join(home, ".cache"), "malloyyo");
|
|
31
|
+
}
|
|
32
|
+
function cacheFile() {
|
|
33
|
+
try {
|
|
34
|
+
const dir = cacheDir();
|
|
35
|
+
mkdirSync(dir, { recursive: true });
|
|
36
|
+
return join(dir, "update-check.json");
|
|
37
|
+
} catch {
|
|
38
|
+
return join(tmpdir(), "malloyyo-update-check.json");
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function readCache(file) {
|
|
42
|
+
try {
|
|
43
|
+
const raw = readFileSync(file, "utf8");
|
|
44
|
+
const parsed = JSON.parse(raw);
|
|
45
|
+
return parsed && typeof parsed === "object" ? parsed : {};
|
|
46
|
+
} catch {
|
|
47
|
+
return {};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function writeCache(file, cache) {
|
|
51
|
+
try {
|
|
52
|
+
writeFileSync(file, JSON.stringify(cache));
|
|
53
|
+
} catch {
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function isNewer(latest, current) {
|
|
57
|
+
const seg2 = (v) => (v.split(/[-+]/)[0] ?? "").split(".").map((p) => Number.parseInt(p, 10) || 0);
|
|
58
|
+
const a = seg2(latest);
|
|
59
|
+
const b = seg2(current);
|
|
60
|
+
for (let i = 0; i < Math.max(a.length, b.length); i++) {
|
|
61
|
+
const l = a[i] ?? 0;
|
|
62
|
+
const r = b[i] ?? 0;
|
|
63
|
+
if (l !== r) return l > r;
|
|
64
|
+
}
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
function selfPath() {
|
|
68
|
+
try {
|
|
69
|
+
return fileURLToPath(import.meta.url);
|
|
70
|
+
} catch {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function spawnCheck() {
|
|
75
|
+
try {
|
|
76
|
+
const self = selfPath();
|
|
77
|
+
if (!self || !existsSync(self)) return;
|
|
78
|
+
const child = spawn(process.execPath, [self, UPDATE_CHECK_ARGV], {
|
|
79
|
+
detached: true,
|
|
80
|
+
stdio: "ignore",
|
|
81
|
+
cwd: dirname(self),
|
|
82
|
+
env: { ...process.env, MALLOYYO_NO_UPDATE_CHECK: "1" }
|
|
83
|
+
});
|
|
84
|
+
child.unref();
|
|
85
|
+
} catch {
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
async function runUpdateCheck() {
|
|
89
|
+
const file = cacheFile();
|
|
90
|
+
const cache = readCache(file);
|
|
91
|
+
try {
|
|
92
|
+
const res = await fetch(`https://registry.npmjs.org/-/package/${PKG}/dist-tags`, {
|
|
93
|
+
signal: AbortSignal.timeout(FETCH_TIMEOUT_MS),
|
|
94
|
+
headers: { accept: "application/json" }
|
|
95
|
+
});
|
|
96
|
+
if (!res.ok) return;
|
|
97
|
+
const tags = await res.json();
|
|
98
|
+
const latest = tags?.latest;
|
|
99
|
+
if (typeof latest !== "string" || latest === "") return;
|
|
100
|
+
writeCache(file, { ...cache, latest, checkedAt: Date.now() });
|
|
101
|
+
} catch {
|
|
102
|
+
writeCache(file, { ...cache, checkedAt: Date.now() });
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function noticeOnExit(argv) {
|
|
106
|
+
if (process.env.MALLOYYO_NO_UPDATE_CHECK) return;
|
|
107
|
+
if (process.env.CI) return;
|
|
108
|
+
const command = argv[2];
|
|
109
|
+
if (command && QUIET_COMMANDS.has(command)) return;
|
|
110
|
+
const file = cacheFile();
|
|
111
|
+
const cache = readCache(file);
|
|
112
|
+
if (!cache.checkedAt || Date.now() - cache.checkedAt > CHECK_INTERVAL_MS) spawnCheck();
|
|
113
|
+
if (!cache.latest || !isNewer(cache.latest, version)) return;
|
|
114
|
+
if (cache.notifiedAt && Date.now() - cache.notifiedAt < NOTIFY_INTERVAL_MS) return;
|
|
115
|
+
process.on("exit", () => {
|
|
116
|
+
try {
|
|
117
|
+
writeCache(file, { ...cache, notifiedAt: Date.now() });
|
|
118
|
+
process.stderr.write(
|
|
119
|
+
`
|
|
120
|
+
malloyyo ${version} \u2014 ${cache.latest} is available.
|
|
121
|
+
npm i -g ${PKG}@latest
|
|
122
|
+
(in a dev container this needs no sudo; set MALLOYYO_NO_UPDATE_CHECK=1 to silence)
|
|
123
|
+
`
|
|
124
|
+
);
|
|
125
|
+
} catch {
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// src/index.ts
|
|
5
131
|
import { resolve as resolve4, relative as relative2, sep as sep2 } from "node:path";
|
|
6
132
|
|
|
7
133
|
// src/config.ts
|
|
8
|
-
import { readFileSync, existsSync } from "node:fs";
|
|
9
|
-
import { join } from "node:path";
|
|
134
|
+
import { readFileSync as readFileSync2, existsSync as existsSync2 } from "node:fs";
|
|
135
|
+
import { join as join2 } from "node:path";
|
|
10
136
|
var KNOWN_KEYS = /* @__PURE__ */ new Set(["analytics", "targets", "image_hosts"]);
|
|
11
137
|
function isTarget(v) {
|
|
12
138
|
return typeof v === "object" && v !== null && typeof v.url === "string";
|
|
@@ -62,18 +188,18 @@ ${TARGETS_BLOCK_EXAMPLE}`
|
|
|
62
188
|
);
|
|
63
189
|
}
|
|
64
190
|
function readMalloyyoBlock(dir) {
|
|
65
|
-
const malloyConfig =
|
|
66
|
-
if (
|
|
191
|
+
const malloyConfig = join2(dir, "malloy-config.json");
|
|
192
|
+
if (existsSync2(malloyConfig)) {
|
|
67
193
|
try {
|
|
68
|
-
const json = JSON.parse(
|
|
194
|
+
const json = JSON.parse(readFileSync2(malloyConfig, "utf8"));
|
|
69
195
|
if (json.malloyyo && typeof json.malloyyo === "object") return json.malloyyo;
|
|
70
196
|
} catch {
|
|
71
197
|
}
|
|
72
198
|
}
|
|
73
|
-
const standalone =
|
|
74
|
-
if (
|
|
199
|
+
const standalone = join2(dir, "malloyyo.json");
|
|
200
|
+
if (existsSync2(standalone)) {
|
|
75
201
|
try {
|
|
76
|
-
return JSON.parse(
|
|
202
|
+
return JSON.parse(readFileSync2(standalone, "utf8"));
|
|
77
203
|
} catch {
|
|
78
204
|
}
|
|
79
205
|
}
|
|
@@ -172,9 +298,9 @@ function resolvePublishTarget(dir, name, overrides = {}) {
|
|
|
172
298
|
}
|
|
173
299
|
|
|
174
300
|
// src/gather.ts
|
|
175
|
-
import { readFileSync as
|
|
176
|
-
import { join as
|
|
177
|
-
import { tmpdir } from "node:os";
|
|
301
|
+
import { readFileSync as readFileSync3, existsSync as existsSync3, readdirSync, statSync, mkdtempSync, rmSync } from "node:fs";
|
|
302
|
+
import { join as join3, relative, sep, dirname as dirname2 } from "node:path";
|
|
303
|
+
import { tmpdir as tmpdir2 } from "node:os";
|
|
178
304
|
import { execFileSync } from "node:child_process";
|
|
179
305
|
|
|
180
306
|
// src/repo.ts
|
|
@@ -629,31 +755,31 @@ function walkFields(fields, structDefFields, depth, ctx, anon) {
|
|
|
629
755
|
const ef = f;
|
|
630
756
|
const cls = classifyJoinTarget(ef, ctx.knownSources);
|
|
631
757
|
const inlineMode = ctx.opts.expand === "inline";
|
|
632
|
-
const
|
|
633
|
-
applyDocs(
|
|
634
|
-
if (cls.kind === "ref")
|
|
758
|
+
const join7 = { name: f.name, relationship: joinRel(ef) };
|
|
759
|
+
applyDocs(join7, f.annotations);
|
|
760
|
+
if (cls.kind === "ref") join7.source_ref = cls.name;
|
|
635
761
|
else if (cls.kind === "anon" && !inlineMode) {
|
|
636
|
-
|
|
762
|
+
join7.anon_src_index = allocAnon(ef, cls.refId, depth + 1, ctx, anon);
|
|
637
763
|
}
|
|
638
|
-
if (needsQuote(f.name))
|
|
639
|
-
if (annotations.length > 0)
|
|
640
|
-
if (loc)
|
|
641
|
-
if (access)
|
|
764
|
+
if (needsQuote(f.name)) join7.must_quote = true;
|
|
765
|
+
if (annotations.length > 0) join7.annotations = annotations;
|
|
766
|
+
if (loc) join7.location = loc;
|
|
767
|
+
if (access) join7.access = access;
|
|
642
768
|
const synthetic = isScalarArray(ef) || isRepeatedRecord(ef) || isAnonymousRecord(ef);
|
|
643
|
-
if (isScalarArray(ef))
|
|
644
|
-
else if (isRepeatedRecord(ef))
|
|
645
|
-
else if (isAnonymousRecord(ef))
|
|
769
|
+
if (isScalarArray(ef)) join7.column_shape = "scalar_array";
|
|
770
|
+
else if (isRepeatedRecord(ef)) join7.column_shape = "record_array";
|
|
771
|
+
else if (isAnonymousRecord(ef)) join7.column_shape = "record";
|
|
646
772
|
if (!synthetic && mLoc) {
|
|
647
773
|
const body = sliceSource(ctx.readSource(mLoc.url), mLoc);
|
|
648
|
-
if (body)
|
|
774
|
+
if (body) join7.body = body;
|
|
649
775
|
}
|
|
650
776
|
const shouldInline = inlineMode || cls.kind === "own";
|
|
651
777
|
if (shouldInline && depth < MAX_JOIN_DEPTH) {
|
|
652
778
|
const childStructFields = ef.structDef.fields ?? [];
|
|
653
779
|
const sub = walkFields(ef.allFields, childStructFields, depth + 1, ctx, anon);
|
|
654
|
-
|
|
780
|
+
join7.fields = stripScalarArrayValue(ef, sub);
|
|
655
781
|
}
|
|
656
|
-
groups.joins.push(
|
|
782
|
+
groups.joins.push(join7);
|
|
657
783
|
continue;
|
|
658
784
|
}
|
|
659
785
|
if (f.isQueryField()) {
|
|
@@ -2226,7 +2352,7 @@ function developSurface(host, opts = {}) {
|
|
|
2226
2352
|
// src/discover.ts
|
|
2227
2353
|
import fs from "node:fs";
|
|
2228
2354
|
import path2 from "node:path";
|
|
2229
|
-
import { fileURLToPath } from "node:url";
|
|
2355
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
2230
2356
|
import { createRequire } from "node:module";
|
|
2231
2357
|
var require2 = createRequire(import.meta.url);
|
|
2232
2358
|
var HOST_LIBS = [
|
|
@@ -2251,7 +2377,7 @@ function resolveRuntimeDir() {
|
|
|
2251
2377
|
// src/dashboard.ts (tsx) OR dist/index.js (published)
|
|
2252
2378
|
new URL("../src/frame-runtime/", import.meta.url)
|
|
2253
2379
|
// built dist/ next to sibling src/ (checkout)
|
|
2254
|
-
].map((u) =>
|
|
2380
|
+
].map((u) => fileURLToPath2(u));
|
|
2255
2381
|
const found = candidates.find((c) => fs.existsSync(c));
|
|
2256
2382
|
if (!found) {
|
|
2257
2383
|
throw new Error(
|
|
@@ -2893,29 +3019,29 @@ function gatherDirectory(dir) {
|
|
|
2893
3019
|
const walk = (cur) => {
|
|
2894
3020
|
for (const entry of readdirSync(cur)) {
|
|
2895
3021
|
if (entry.startsWith(".") || SKIP_DIRS.has(entry)) continue;
|
|
2896
|
-
const full =
|
|
3022
|
+
const full = join3(cur, entry);
|
|
2897
3023
|
if (statSync(full).isDirectory()) {
|
|
2898
3024
|
walk(full);
|
|
2899
3025
|
} else if (entry.endsWith(".malloy")) {
|
|
2900
3026
|
files.push({
|
|
2901
3027
|
path: relative(dir, full).split(sep).join("/"),
|
|
2902
|
-
content:
|
|
3028
|
+
content: readFileSync3(full, "utf8")
|
|
2903
3029
|
});
|
|
2904
3030
|
}
|
|
2905
3031
|
}
|
|
2906
3032
|
};
|
|
2907
3033
|
walk(dir);
|
|
2908
|
-
const devcontainer =
|
|
2909
|
-
if (
|
|
2910
|
-
files.push({ path: DEVCONTAINER_PATH, content:
|
|
3034
|
+
const devcontainer = join3(dir, ...DEVCONTAINER_PATH.split("/"));
|
|
3035
|
+
if (existsSync3(devcontainer)) {
|
|
3036
|
+
files.push({ path: DEVCONTAINER_PATH, content: readFileSync3(devcontainer, "utf8") });
|
|
2911
3037
|
}
|
|
2912
|
-
const configPath =
|
|
2913
|
-
const config =
|
|
3038
|
+
const configPath = join3(dir, "malloy-config.json");
|
|
3039
|
+
const config = existsSync3(configPath) ? readFileSync3(configPath, "utf8") : void 0;
|
|
2914
3040
|
return { files, config };
|
|
2915
3041
|
}
|
|
2916
3042
|
async function gatherDashboards(dir) {
|
|
2917
|
-
const dashDir =
|
|
2918
|
-
if (!
|
|
3043
|
+
const dashDir = join3(dir, "dashboards");
|
|
3044
|
+
if (!existsSync3(dashDir)) return [];
|
|
2919
3045
|
const runner = await makeRunner(dir);
|
|
2920
3046
|
try {
|
|
2921
3047
|
const files = readdirSync(dashDir).filter((f) => f.endsWith(".malloy")).sort();
|
|
@@ -2934,11 +3060,11 @@ async function gatherDashboards(dir) {
|
|
|
2934
3060
|
if (a.description) manifest.description = a.description;
|
|
2935
3061
|
if (a.givens) manifest.givens = a.givens;
|
|
2936
3062
|
if (a.autorun === false) manifest.autorun = false;
|
|
2937
|
-
const component = ["jsx", "tsx"].map((ext) =>
|
|
3063
|
+
const component = ["jsx", "tsx"].map((ext) => join3(dashDir, `${base}.${ext}`)).find((p) => existsSync3(p));
|
|
2938
3064
|
payloads.push({
|
|
2939
3065
|
name: a.name || base,
|
|
2940
3066
|
manifest,
|
|
2941
|
-
source: component ?
|
|
3067
|
+
source: component ? readFileSync3(component, "utf8") : ""
|
|
2942
3068
|
});
|
|
2943
3069
|
}
|
|
2944
3070
|
const about = aboutPage(dir);
|
|
@@ -2946,7 +3072,7 @@ async function gatherDashboards(dir) {
|
|
|
2946
3072
|
payloads.unshift({
|
|
2947
3073
|
name: about.name,
|
|
2948
3074
|
manifest: { title: about.title },
|
|
2949
|
-
source:
|
|
3075
|
+
source: readFileSync3(about.tsxPath, "utf8")
|
|
2950
3076
|
});
|
|
2951
3077
|
}
|
|
2952
3078
|
return payloads;
|
|
@@ -2981,8 +3107,8 @@ function gitInfo(dir) {
|
|
|
2981
3107
|
}
|
|
2982
3108
|
}
|
|
2983
3109
|
function gitArchiveZip(dir) {
|
|
2984
|
-
const tmpIndex =
|
|
2985
|
-
mkdtempSync(
|
|
3110
|
+
const tmpIndex = join3(
|
|
3111
|
+
mkdtempSync(join3(tmpdir2(), "malloyyo-index-")),
|
|
2986
3112
|
"index"
|
|
2987
3113
|
);
|
|
2988
3114
|
const git = (args, encoding = "utf8") => execFileSync("git", args, {
|
|
@@ -3011,13 +3137,13 @@ A repo publishes what git tracks, so there has to be a git repo to ask. Run \`gi
|
|
|
3011
3137
|
const zip = git(["archive", "--format=zip", tree], "buffer");
|
|
3012
3138
|
return { zip, fileCount };
|
|
3013
3139
|
} finally {
|
|
3014
|
-
rmSync(
|
|
3140
|
+
rmSync(dirname2(tmpIndex), { recursive: true, force: true });
|
|
3015
3141
|
}
|
|
3016
3142
|
}
|
|
3017
3143
|
|
|
3018
3144
|
// src/lint.ts
|
|
3019
|
-
import { existsSync as
|
|
3020
|
-
import { join as
|
|
3145
|
+
import { existsSync as existsSync4, readdirSync as readdirSync2, readFileSync as readFileSync4 } from "node:fs";
|
|
3146
|
+
import { join as join4, resolve } from "node:path";
|
|
3021
3147
|
import * as esbuild from "esbuild";
|
|
3022
3148
|
var quoteField = (f) => /^[A-Za-z_]\w*$/.test(f) ? f : `\`${f}\``;
|
|
3023
3149
|
function componentQueryLiterals(source) {
|
|
@@ -3030,7 +3156,7 @@ function componentQueryLiterals(source) {
|
|
|
3030
3156
|
function landingPageErrors(dir, file) {
|
|
3031
3157
|
const ext = file.endsWith(".tsx") ? "tsx" : "jsx";
|
|
3032
3158
|
try {
|
|
3033
|
-
esbuild.transformSync(
|
|
3159
|
+
esbuild.transformSync(readFileSync4(join4(dir, file), "utf8"), { loader: ext, jsx: "automatic" });
|
|
3034
3160
|
return [];
|
|
3035
3161
|
} catch (e) {
|
|
3036
3162
|
const msg = e.errors?.map((x) => x.text).join("; ") ?? String(e);
|
|
@@ -3059,8 +3185,8 @@ async function runLint(abs, runner) {
|
|
|
3059
3185
|
const arts = await runner.artifacts();
|
|
3060
3186
|
if (!arts.ok) dashboards.push({ name: "index.malloy", errors: [arts.error], warnings: [] });
|
|
3061
3187
|
}
|
|
3062
|
-
const dir =
|
|
3063
|
-
if (!
|
|
3188
|
+
const dir = join4(abs, "dashboards");
|
|
3189
|
+
if (!existsSync4(dir)) return { ok: dashboards.every((d) => d.errors.length === 0), dashboards };
|
|
3064
3190
|
const entries = readdirSync2(dir);
|
|
3065
3191
|
const malloyFiles = entries.filter((f) => f.endsWith(".malloy")).sort();
|
|
3066
3192
|
const malloyBases = new Set(malloyFiles.map((f) => f.slice(0, -".malloy".length)));
|
|
@@ -3080,7 +3206,7 @@ async function runLint(abs, runner) {
|
|
|
3080
3206
|
const seenNames = /* @__PURE__ */ new Map();
|
|
3081
3207
|
for (const file of malloyFiles) {
|
|
3082
3208
|
const base = file.slice(0, -".malloy".length);
|
|
3083
|
-
const entryFile =
|
|
3209
|
+
const entryFile = join4("dashboards", file);
|
|
3084
3210
|
const errors = [];
|
|
3085
3211
|
const warnings = [];
|
|
3086
3212
|
const res = await runner.artifactForFile(entryFile, base);
|
|
@@ -3122,9 +3248,9 @@ async function runLint(abs, runner) {
|
|
|
3122
3248
|
}
|
|
3123
3249
|
}
|
|
3124
3250
|
for (const ext of ["jsx", "tsx"]) {
|
|
3125
|
-
const cp =
|
|
3126
|
-
if (!
|
|
3127
|
-
const source =
|
|
3251
|
+
const cp = join4(dir, `${base}.${ext}`);
|
|
3252
|
+
if (!existsSync4(cp)) continue;
|
|
3253
|
+
const source = readFileSync4(cp, "utf8");
|
|
3128
3254
|
try {
|
|
3129
3255
|
await esbuild.transform(source, { loader: ext, jsx: "automatic" });
|
|
3130
3256
|
} catch (e) {
|
|
@@ -3186,7 +3312,7 @@ async function lintRepo(root) {
|
|
|
3186
3312
|
const oldLayout = layout.kind === "single" && repoRoot === abs;
|
|
3187
3313
|
const datasets = [];
|
|
3188
3314
|
for (const t of targets) {
|
|
3189
|
-
const root2 = t.dir ?
|
|
3315
|
+
const root2 = t.dir ? join4(abs, t.dir) : abs;
|
|
3190
3316
|
const report = await lintDashboards(root2, {
|
|
3191
3317
|
repoRoot,
|
|
3192
3318
|
...t.name ? { datasetName: t.name } : {}
|
|
@@ -3244,21 +3370,21 @@ function missingEnvHint(missing, where) {
|
|
|
3244
3370
|
// src/oauth.ts
|
|
3245
3371
|
import http from "node:http";
|
|
3246
3372
|
import crypto from "node:crypto";
|
|
3247
|
-
import { spawn } from "node:child_process";
|
|
3373
|
+
import { spawn as spawn2 } from "node:child_process";
|
|
3248
3374
|
|
|
3249
3375
|
// src/store.ts
|
|
3250
|
-
import { homedir } from "node:os";
|
|
3251
|
-
import { dirname as
|
|
3252
|
-
import { mkdirSync, readFileSync as
|
|
3376
|
+
import { homedir as homedir2 } from "node:os";
|
|
3377
|
+
import { dirname as dirname3, join as join5 } from "node:path";
|
|
3378
|
+
import { mkdirSync as mkdirSync2, readFileSync as readFileSync5, writeFileSync as writeFileSync2, existsSync as existsSync5, chmodSync } from "node:fs";
|
|
3253
3379
|
function credsPath() {
|
|
3254
|
-
const base = process.env.XDG_CONFIG_HOME ||
|
|
3255
|
-
return
|
|
3380
|
+
const base = process.env.XDG_CONFIG_HOME || join5(homedir2(), ".config");
|
|
3381
|
+
return join5(base, "malloyyo", "credentials.json");
|
|
3256
3382
|
}
|
|
3257
3383
|
function readAll() {
|
|
3258
3384
|
const p = credsPath();
|
|
3259
|
-
if (!
|
|
3385
|
+
if (!existsSync5(p)) return {};
|
|
3260
3386
|
try {
|
|
3261
|
-
return JSON.parse(
|
|
3387
|
+
return JSON.parse(readFileSync5(p, "utf8"));
|
|
3262
3388
|
} catch {
|
|
3263
3389
|
return {};
|
|
3264
3390
|
}
|
|
@@ -3268,10 +3394,10 @@ function loadCreds(url6) {
|
|
|
3268
3394
|
}
|
|
3269
3395
|
function saveCreds(url6, creds) {
|
|
3270
3396
|
const p = credsPath();
|
|
3271
|
-
|
|
3397
|
+
mkdirSync2(dirname3(p), { recursive: true });
|
|
3272
3398
|
const all = readAll();
|
|
3273
3399
|
all[url6] = creds;
|
|
3274
|
-
|
|
3400
|
+
writeFileSync2(p, JSON.stringify(all, null, 2) + "\n", { mode: 384 });
|
|
3275
3401
|
try {
|
|
3276
3402
|
chmodSync(p, 384);
|
|
3277
3403
|
} catch {
|
|
@@ -3281,13 +3407,10 @@ function clearCreds(url6) {
|
|
|
3281
3407
|
const all = readAll();
|
|
3282
3408
|
if (!(url6 in all)) return false;
|
|
3283
3409
|
delete all[url6];
|
|
3284
|
-
|
|
3410
|
+
writeFileSync2(credsPath(), JSON.stringify(all, null, 2) + "\n", { mode: 384 });
|
|
3285
3411
|
return true;
|
|
3286
3412
|
}
|
|
3287
3413
|
|
|
3288
|
-
// package.json
|
|
3289
|
-
var version = "0.2.57";
|
|
3290
|
-
|
|
3291
3414
|
// src/http.ts
|
|
3292
3415
|
var USER_AGENT = `malloyyo/${version}`;
|
|
3293
3416
|
var UPGRADE_REQUIRED = 426;
|
|
@@ -3341,7 +3464,7 @@ function browserless(platform = process.platform, env = process.env) {
|
|
|
3341
3464
|
function openBrowser(url6) {
|
|
3342
3465
|
const [cmd, args] = process.platform === "darwin" ? ["open", [url6]] : process.platform === "win32" ? ["cmd", ["/c", "start", "", url6]] : ["xdg-open", [url6]];
|
|
3343
3466
|
try {
|
|
3344
|
-
const child =
|
|
3467
|
+
const child = spawn2(cmd, args, { stdio: "ignore", detached: true });
|
|
3345
3468
|
child.on("error", () => {
|
|
3346
3469
|
});
|
|
3347
3470
|
child.unref();
|
|
@@ -4742,7 +4865,7 @@ Publish: deploy ${path9.basename(outDir)}/ to Vercel (vercel.json written: clean
|
|
|
4742
4865
|
import fs9 from "node:fs";
|
|
4743
4866
|
import { execFileSync as execFileSync2 } from "node:child_process";
|
|
4744
4867
|
import path10 from "node:path";
|
|
4745
|
-
import { fileURLToPath as
|
|
4868
|
+
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
4746
4869
|
var AUTHOR_SERVER = "malloyyo_author";
|
|
4747
4870
|
var AUTHOR_MCP = {
|
|
4748
4871
|
mcpServers: {
|
|
@@ -4826,7 +4949,7 @@ function scaffoldRepo(root) {
|
|
|
4826
4949
|
return { notes };
|
|
4827
4950
|
}
|
|
4828
4951
|
function templatePath(...parts) {
|
|
4829
|
-
const distDir = path10.dirname(
|
|
4952
|
+
const distDir = path10.dirname(fileURLToPath3(import.meta.url));
|
|
4830
4953
|
return [
|
|
4831
4954
|
path10.join(distDir, "templates", ...parts),
|
|
4832
4955
|
path10.join(distDir, "..", "src", "templates", ...parts)
|
|
@@ -5012,7 +5135,7 @@ async function sqlCmd(connection, opts) {
|
|
|
5012
5135
|
}
|
|
5013
5136
|
|
|
5014
5137
|
// src/launch.ts
|
|
5015
|
-
import { spawn as
|
|
5138
|
+
import { spawn as spawn3 } from "node:child_process";
|
|
5016
5139
|
import fs11 from "node:fs";
|
|
5017
5140
|
import os from "node:os";
|
|
5018
5141
|
import path12 from "node:path";
|
|
@@ -5032,7 +5155,7 @@ async function launchCmd(mode, opts) {
|
|
|
5032
5155
|
const label = mode === "author" ? "AUTHOR (compile/edit)" : "TEST (claude.ai web preview)";
|
|
5033
5156
|
process.stderr.write(`\u25B6 launching Claude in ${label} mode over ${root}
|
|
5034
5157
|
`);
|
|
5035
|
-
const child =
|
|
5158
|
+
const child = spawn3("claude", ["--strict-mcp-config", "--mcp-config", cfgPath], {
|
|
5036
5159
|
stdio: "inherit",
|
|
5037
5160
|
cwd: root
|
|
5038
5161
|
});
|
|
@@ -5052,8 +5175,8 @@ async function launchCmd(mode, opts) {
|
|
|
5052
5175
|
|
|
5053
5176
|
// src/draft.ts
|
|
5054
5177
|
import { createHash } from "node:crypto";
|
|
5055
|
-
import { existsSync as
|
|
5056
|
-
import { join as
|
|
5178
|
+
import { existsSync as existsSync6, mkdirSync as mkdirSync3, writeFileSync as writeFileSync3 } from "node:fs";
|
|
5179
|
+
import { join as join6, resolve as resolve2 } from "node:path";
|
|
5057
5180
|
async function readStdin2() {
|
|
5058
5181
|
if (process.stdin.isTTY) {
|
|
5059
5182
|
throw new Error(`--token-stdin reads the token from stdin \u2014 pipe it in: printf '%s' "$TOKEN" | malloyyo login <url> --token-stdin`);
|
|
@@ -5135,12 +5258,12 @@ async function draftPromote(slug, dir, opts) {
|
|
|
5135
5258
|
if (!/^[a-z0-9][a-z0-9_-]{0,63}$/i.test(name)) {
|
|
5136
5259
|
throw new Error(`--name must be letters, digits, '-' or '_' (a dashboard's file basename), not "${name}"`);
|
|
5137
5260
|
}
|
|
5138
|
-
const dashboards =
|
|
5139
|
-
|
|
5261
|
+
const dashboards = join6(root, "dashboards");
|
|
5262
|
+
mkdirSync3(dashboards, { recursive: true });
|
|
5140
5263
|
const written = [];
|
|
5141
|
-
const malloyPath =
|
|
5142
|
-
const componentPath =
|
|
5143
|
-
const existing = [malloyPath, componentPath].filter((p) =>
|
|
5264
|
+
const malloyPath = join6(dashboards, `${name}.malloy`);
|
|
5265
|
+
const componentPath = join6(dashboards, `${name}.${opts.tsx ? "tsx" : "jsx"}`);
|
|
5266
|
+
const existing = [malloyPath, componentPath].filter((p) => existsSync6(p));
|
|
5144
5267
|
if (existing.length > 0 && !opts.force) {
|
|
5145
5268
|
throw new Error(
|
|
5146
5269
|
`${existing.map((p) => p.replace(`${root}/`, "")).join(", ")} already exist(s) \u2014 pass --name to promote under another name, or --force to overwrite`
|
|
@@ -5162,7 +5285,7 @@ async function draftPromote(slug, dir, opts) {
|
|
|
5162
5285
|
if (e instanceof DraftRequestError && e.status === 403) unrecorded = e.message;
|
|
5163
5286
|
else throw e;
|
|
5164
5287
|
}
|
|
5165
|
-
for (const f of written)
|
|
5288
|
+
for (const f of written) writeFileSync3(f.path, f.content.endsWith("\n") ? f.content : `${f.content}
|
|
5166
5289
|
`);
|
|
5167
5290
|
console.log(`\u2713 promoted '${draft2.title}' into ${root.replace(process.env.HOME ?? "", "~")}`);
|
|
5168
5291
|
for (const f of written) console.log(` ${f.path.replace(`${root}/`, "")}`);
|
|
@@ -6427,6 +6550,10 @@ program.command("dashboard").argument("<action>", "action to run (dev | bundle)"
|
|
|
6427
6550
|
}
|
|
6428
6551
|
);
|
|
6429
6552
|
registerCloudCommands(program);
|
|
6553
|
+
program.command(UPDATE_CHECK_ARGV, { hidden: true }).description("internal: refresh the cached latest-version check").action(async () => {
|
|
6554
|
+
await runUpdateCheck();
|
|
6555
|
+
});
|
|
6556
|
+
noticeOnExit(process.argv);
|
|
6430
6557
|
program.parseAsync().catch((err) => {
|
|
6431
6558
|
console.error(err instanceof Error ? err.message : String(err));
|
|
6432
6559
|
process.exit(1);
|