@mason-data/cli 0.9.0 → 0.10.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 +6 -4
- package/dist/src/api/error.js +4 -0
- package/dist/src/api/postgres/proxy.js +6 -160
- package/dist/src/api/postgres/server.js +22 -4
- package/dist/src/cli/command.js +169 -5
- package/dist/src/cli/commands.js +290 -157
- package/dist/src/cli/deploy.js +134 -28
- package/dist/src/cli/doctor.js +14 -11
- package/dist/src/cli/guides.js +20 -11
- package/dist/src/cli/hosted.js +1 -1
- package/dist/src/cli/init.js +110 -25
- package/dist/src/cli/login.js +20 -17
- package/dist/src/cli/machine.js +125 -40
- package/dist/src/cli/main.js +51 -8
- package/dist/src/cli/mcp.js +15 -12
- package/dist/src/cli/project.js +1 -1
- package/dist/src/cli/registry.js +80 -35
- package/dist/src/cli/replica-hosted.js +761 -102
- package/dist/src/cli/replica.js +43 -5
- package/dist/src/cli/replication-mode.js +5 -0
- package/dist/src/cli/request-filter.js +16 -6
- package/dist/src/cli/run-server.js +25 -2
- package/dist/src/cli/secret-input.js +193 -0
- package/dist/src/cli/serve.js +2 -2
- package/dist/src/cli/share.js +20 -15
- package/dist/src/cli/source-role.js +14 -15
- package/dist/src/cli/sources.js +20 -3
- package/dist/src/cli/style.js +14 -0
- package/dist/src/cli/sync.js +17 -8
- package/dist/src/cli/token-hosted.js +30 -24
- package/dist/src/cli/tunnel.js +1 -1
- package/dist/src/cli/ui-hosted.js +163 -0
- package/dist/src/cli/ui-ssh.js +3 -3
- package/dist/src/cli/ui.js +67 -26
- package/dist/src/cli/usage.js +19 -15
- package/dist/src/cli/user-hosted.js +78 -13
- package/dist/src/cli/user.js +168 -50
- package/dist/src/duck/users.js +105 -9
- package/dist/src/lib/cidr.js +177 -0
- package/dist/src/lib/table-sync.js +69 -19
- package/package.json +6 -6
package/dist/src/cli/registry.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* command's summary, in this order — so a command cannot exist without being listed, and tests/cli-help.test.ts holds
|
|
4
4
|
* each one to src/cli/command.ts's rules (its own --help, an example, every option documented).
|
|
5
5
|
*/
|
|
6
|
-
import { failed, parseCommand, reportText, wantsJson } from "./command.js";
|
|
6
|
+
import { FAILURE_CODES, SPEC_NEXT, failed, jsonText, parseCommand, reportText, specAnswer, specJson, wantsJson } from "./command.js";
|
|
7
7
|
import { removedStartFlags } from "../lib/table-sync.js";
|
|
8
8
|
import { sourcesTop } from "./sources.js";
|
|
9
9
|
import { dev } from "./dev.js";
|
|
@@ -37,7 +37,7 @@ export const DEV = {
|
|
|
37
37
|
needs: "project",
|
|
38
38
|
name: "start",
|
|
39
39
|
summary: "start Mason for this folder's project, in the background (mason init makes the project)",
|
|
40
|
-
usage: `usage: mason start [--attach] [--self-signed-tls] [--port <n>] [--json]
|
|
40
|
+
usage: `usage: mason start [--attach] [--self-signed-tls] [--ui-port <n>] [--json]
|
|
41
41
|
|
|
42
42
|
Starts Mason for the project of this folder (mason init made it): one process, which syncs the tables you add
|
|
43
43
|
(mason add) from the project's database into its own file, keeps them current as the sources file says, and answers
|
|
@@ -45,6 +45,17 @@ export const DEV = {
|
|
|
45
45
|
its sync: says replication). It returns once Mason is up; run it again any time (it says so when Mason is
|
|
46
46
|
already running). The synced data and Mason's state stay between runs: the next start resumes.
|
|
47
47
|
|
|
48
|
+
mason start
|
|
49
|
+
mason start --attach in the foreground: Ctrl-C stops it
|
|
50
|
+
MASON_PG_HOST=0.0.0.0 mason start --self-signed-tls the Postgres API for other machines, over TLS
|
|
51
|
+
|
|
52
|
+
--attach stay in the foreground (Ctrl-C stops Mason)
|
|
53
|
+
--self-signed-tls the Postgres API requires TLS, from a certificate made for this project in .mason/ (kept and
|
|
54
|
+
served again by every later start with the flag); not with MASON_PG_TLS_CERT / _KEY
|
|
55
|
+
--ui-port <n> the port of its web page and of the mason commands, on 127.0.0.1 (default ${DEFAULT_UI_PORT}, or the
|
|
56
|
+
next free one); MASON_UI_PORT on a server, never the Postgres API's (MASON_PG_PORT)
|
|
57
|
+
--json as data, once it is up: { running, pid, postgres: { url, host, port, database, sslmode }, next }
|
|
58
|
+
|
|
48
59
|
After its first sync, each table is kept current as the sources file's sync: says — at the top for every table, or
|
|
49
60
|
on a table's entry: off (the default, which mason init writes) reads it again only when you run mason sync <table>;
|
|
50
61
|
poll <interval> (poll 5s, poll 5m, poll 1h) polls it with SELECTs at that interval; replication reads its changes
|
|
@@ -61,7 +72,8 @@ export const DEV = {
|
|
|
61
72
|
created, altered or dropped — Mason makes only its slot. A read replica needs one (it takes no CREATE PUBLICATION).
|
|
62
73
|
|
|
63
74
|
--replication, --poll and --publication are gone: each answers with the line to write at the top of the sources
|
|
64
|
-
file (sync: replication, sync: poll 5m, publication: <name>) and exit 2, and starts nothing.
|
|
75
|
+
file (sync: replication, sync: poll 5m, publication: <name>) and exit 2, and starts nothing. --port is now
|
|
76
|
+
--ui-port: it answers with the line to run and exit 2.
|
|
65
77
|
|
|
66
78
|
The Postgres API's port is the project's: the first start takes 5433, or the next port free on every address when a
|
|
67
79
|
second Postgres holds it, and records it; every later start listens on the same port, so a BI tool's saved connection
|
|
@@ -78,42 +90,36 @@ export const DEV = {
|
|
|
78
90
|
any other address is refused.
|
|
79
91
|
|
|
80
92
|
${PROJECT_LINE}
|
|
81
|
-
|
|
82
|
-
mason start
|
|
83
|
-
mason start --attach in the foreground: Ctrl-C stops it
|
|
84
|
-
MASON_PG_HOST=0.0.0.0 mason start --self-signed-tls the Postgres API for other machines, over TLS
|
|
85
|
-
|
|
86
|
-
--attach stay in the foreground (Ctrl-C stops Mason)
|
|
87
|
-
--self-signed-tls the Postgres API requires TLS, from a certificate made for this project in .mason/ (kept and
|
|
88
|
-
served again by every later start with the flag); not with MASON_PG_TLS_CERT / _KEY
|
|
89
|
-
--port <n> the port the mason commands reach it on (default ${DEFAULT_UI_PORT}, or the next free one)
|
|
90
|
-
--json as data, once it is up: { running, pid, postgres: { url, host, port, database, sslmode }, next }
|
|
91
93
|
`,
|
|
92
94
|
options: {
|
|
93
|
-
port: { type: "string" }, attach: { type: "boolean", default: false }, json: { type: "boolean", default: false },
|
|
95
|
+
"ui-port": { type: "string" }, attach: { type: "boolean", default: false }, json: { type: "boolean", default: false },
|
|
94
96
|
"self-signed-tls": { type: "boolean", default: false },
|
|
95
97
|
},
|
|
96
98
|
json: ["running", "pid", "postgres", "next"],
|
|
97
99
|
};
|
|
98
100
|
async function runDev(argv) {
|
|
99
|
-
// --replication, --poll and --publication are gone (issue 33): each answered with the edit to make in the sources
|
|
101
|
+
// --replication, --poll and --publication are gone (issue 33), and --port is --ui-port: each answered with the edit to make in the sources
|
|
100
102
|
// file, exit 2, before the options are parsed (it would be an unknown option there) and before anything starts. The
|
|
101
103
|
// file is read only when one is given. A decision: `mason start --replication --help` answers the refusal, not the
|
|
102
104
|
// usage — the flag is wrong whatever else the line asks
|
|
103
105
|
const removed = removedStartFlags(argv, () => startSourcesTop(process.cwd()));
|
|
104
|
-
if (removed !== null)
|
|
105
|
-
|
|
106
|
+
if (removed !== null) {
|
|
107
|
+
const { start, sync, ...said } = removed;
|
|
108
|
+
const next = sync ? [[start, "each table kept current as its sync: says"], ["mason help production", "sync: and publication:, and what each needs"]]
|
|
109
|
+
: [[start, "Mason, its web page and the commands on that port"]];
|
|
110
|
+
return failed("start", { code: "usage", ...said, next }, { json: wantsJson(argv, DEV) });
|
|
111
|
+
}
|
|
106
112
|
const f = parseCommand(DEV, argv);
|
|
107
113
|
if (typeof f === "number")
|
|
108
114
|
return f;
|
|
109
115
|
const v = f.values;
|
|
110
116
|
if (f.positionals.length) {
|
|
111
117
|
// the database is the project's now: a URL here is the old habit, answered with the new way
|
|
112
|
-
return failed("start", { message: "it takes no database URL: the project has one", code: "usage", why: "mason init <url> made it; .mason/config.json holds it", usage: DEV.usage }, { json: v.json });
|
|
118
|
+
return failed("start", { message: "it takes no database URL: the project has one", code: "usage", why: "mason init <url> made it; .mason/config.json holds it", fix: "run mason start alone", usage: DEV.usage }, { json: v.json });
|
|
113
119
|
}
|
|
114
|
-
const port = v
|
|
120
|
+
const port = v["ui-port"] === undefined ? DEFAULT_UI_PORT : Number(v["ui-port"]);
|
|
115
121
|
if (!Number.isInteger(port) || port < 1 || port > 65_535)
|
|
116
|
-
return failed("start", { message: `--port must be a port number (1-65535), not ${JSON.stringify(v
|
|
122
|
+
return failed("start", { message: `--ui-port must be a port number (1-65535), not ${JSON.stringify(v["ui-port"])}`, code: "usage" }, { json: v.json });
|
|
117
123
|
if (!v.attach)
|
|
118
124
|
return devInBackground(argv, { json: v.json, selfSignedTls: v["self-signed-tls"] });
|
|
119
125
|
return dev({ port, version: version(), selfSignedTls: v["self-signed-tls"] });
|
|
@@ -127,7 +133,7 @@ function startSourcesTop(cwd) {
|
|
|
127
133
|
export const HELP = {
|
|
128
134
|
name: "help",
|
|
129
135
|
summary: "the commands by step, or one command's usage: mason help add",
|
|
130
|
-
usage: `usage: mason help [<command> | <guide>]
|
|
136
|
+
usage: `usage: mason help [<command> | <guide>] [--json]
|
|
131
137
|
|
|
132
138
|
The commands by step (mason help), how to use one (mason help add — the same as mason add --help), or a guide,
|
|
133
139
|
offline, short enough to read whole and listing exactly what Mason accepts:
|
|
@@ -135,35 +141,74 @@ export const HELP = {
|
|
|
135
141
|
mason help
|
|
136
142
|
mason help add
|
|
137
143
|
${Object.entries(GUIDES).map(([k, v]) => ` mason help ${k.padEnd(14)} ${v}`).join("\n")}
|
|
144
|
+
mason help --json every command's spec as data (mason help agent says its shape)
|
|
145
|
+
|
|
146
|
+
--json as data: mason help, { version, commands: [<spec>…], guides: [{ name, summary }], failureCodes:
|
|
147
|
+
[{ code, meaning }], next }; mason help <command> (the same as mason <command> --help --json), { command:
|
|
148
|
+
<spec>, next }; mason help <guide>, { guide: { name, summary, text }, next }
|
|
138
149
|
`,
|
|
139
|
-
options: {},
|
|
150
|
+
options: { json: { type: "boolean", default: false } },
|
|
151
|
+
json: ["version", "commands", "guides", "failureCodes", "command", "guide", "next"],
|
|
140
152
|
};
|
|
153
|
+
/** `mason version` (also `--version`, `-v`): the CLI's version, as text or with --json as data. Answered by main.ts
|
|
154
|
+
* before the registry, so not one of COMMANDS; described here so `mason help version` and its --json read one spec. */
|
|
155
|
+
export const VERSION = {
|
|
156
|
+
name: "version",
|
|
157
|
+
summary: "the CLI's version",
|
|
158
|
+
usage: `usage: mason version [--json]
|
|
159
|
+
|
|
160
|
+
The CLI's version (mason --version and mason -v are the same):
|
|
161
|
+
|
|
162
|
+
mason version
|
|
163
|
+
|
|
164
|
+
--json as data: { version, next }
|
|
165
|
+
`,
|
|
166
|
+
options: { json: { type: "boolean", default: false } },
|
|
167
|
+
json: ["version", "next"],
|
|
168
|
+
};
|
|
169
|
+
/** `mason version` (and `--version`, `-v`): its line read by VERSION, as every command's is by its spec, so what it
|
|
170
|
+
* accepts is what its spec as data says — `--help`, `--help --json`, a wrong option or an argument refused (exit 2). */
|
|
171
|
+
export function runVersion(argv) {
|
|
172
|
+
const f = parseCommand(VERSION, argv);
|
|
173
|
+
if (typeof f === "number")
|
|
174
|
+
return f;
|
|
175
|
+
const json = f.values.json === true;
|
|
176
|
+
if (f.positionals.length)
|
|
177
|
+
return failed("version", { message: `it takes no argument: ${f.positionals.join(" ")}`, code: "usage", usage: VERSION.usage }, { json });
|
|
178
|
+
process.stdout.write(`${json ? jsonText(VERSION, { version: version() }) : version()}\n`);
|
|
179
|
+
return 0;
|
|
180
|
+
}
|
|
141
181
|
async function runHelp(argv) {
|
|
142
182
|
const f = parseCommand(HELP, argv);
|
|
143
183
|
if (typeof f === "number")
|
|
144
184
|
return f;
|
|
185
|
+
const json = f.values.json === true;
|
|
145
186
|
const [asked, ...rest] = f.positionals;
|
|
146
187
|
if (rest.length)
|
|
147
|
-
return failed("help", { message: "one command or guide at a time", code: "usage", usage: HELP.usage }, { json
|
|
188
|
+
return failed("help", { message: "one command or guide at a time", code: "usage", usage: HELP.usage }, { json });
|
|
148
189
|
if (asked === undefined) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
process.stdout.write(
|
|
190
|
+
if (!json) {
|
|
191
|
+
process.stdout.write(topUsage());
|
|
192
|
+
return 0;
|
|
193
|
+
}
|
|
194
|
+
process.stdout.write(`${jsonText(HELP, {
|
|
195
|
+
version: version(), commands: [...COMMANDS, VERSION].map(specJson), guides: Object.entries(GUIDES).map(([name, summary]) => ({ name, summary })),
|
|
196
|
+
failureCodes: Object.entries(FAILURE_CODES).map(([code, meaning]) => ({ code, meaning })),
|
|
197
|
+
}, [["mason help agent", "driving Mason from a coding agent: these shapes, the failures and the exit codes"]])}\n`);
|
|
154
198
|
return 0;
|
|
155
199
|
}
|
|
156
200
|
if (Object.hasOwn(GUIDES, asked)) {
|
|
157
|
-
|
|
201
|
+
const text = await guideText(asked);
|
|
202
|
+
process.stdout.write(json ? `${jsonText(HELP, { guide: { name: asked, summary: GUIDES[asked], text } }, SPEC_NEXT)}\n` : text);
|
|
158
203
|
return 0;
|
|
159
204
|
}
|
|
160
|
-
const cmd = COMMANDS.find((c) => c.name === asked);
|
|
205
|
+
const cmd = asked === "version" ? VERSION : COMMANDS.find((c) => c.name === asked);
|
|
161
206
|
if (cmd) {
|
|
162
|
-
process.stdout.write(cmd.usage);
|
|
207
|
+
process.stdout.write(json ? `${specAnswer(cmd)}\n` : cmd.usage);
|
|
163
208
|
return 0;
|
|
164
209
|
}
|
|
165
210
|
return failed("help", { message: `there is no command or guide ${JSON.stringify(asked)}${didYouMean(asked, [...COMMANDS.map((c) => c.name), ...Object.keys(GUIDES)])}`, code: "usage",
|
|
166
|
-
why: `the guides: ${Object.keys(GUIDES).join(", ")}`, next: [["mason help", "every command"]] }, { json
|
|
211
|
+
why: `the guides: ${Object.keys(GUIDES).join(", ")}`, fix: "name a command or a guide mason help lists", next: [["mason help", "every command"]] }, { json });
|
|
167
212
|
}
|
|
168
213
|
/**
|
|
169
214
|
* EVERY COMMAND, IN THE ORDER A FIRST SESSION NEEDS THEM (listed in the order a developer will likely need them, the
|
|
@@ -198,7 +243,7 @@ export async function orientation(cwd, s = styleOut()) {
|
|
|
198
243
|
? [["Project", `${project.config.name}, files in ${project.folder}`], ["Mason", run ? `running (pid ${run.pid})` : "not running"]]
|
|
199
244
|
: [["Project", "none here: mason init makes this folder one"]];
|
|
200
245
|
const next = !project
|
|
201
|
-
? [["mason init", "make this folder a project (MASON_DATABASE_URL or DATABASE_URL from .env, or mason init
|
|
246
|
+
? [["mason init", "make this folder a project (MASON_DATABASE_URL or DATABASE_URL from .env, or its URL on stdin: mason init -)"],
|
|
202
247
|
["mason init demo", "or try it on a demo database Mason makes itself: nothing to install"],
|
|
203
248
|
["mason doctor", "what this machine needs for Mason, and whether it has it"]]
|
|
204
249
|
: !run ? [["mason start", "start Mason for this project, in the background"], ["mason status", "the project and its tables"]]
|
|
@@ -238,10 +283,10 @@ export function topUsage(s = styleOut()) {
|
|
|
238
283
|
listed.map(([step, es]) => ` ${s.bold(step)}\n${block(es)}`).join("\n\n"),
|
|
239
284
|
"",
|
|
240
285
|
para("mason <command> --help (or mason help <command>) says how to use one, with examples; the guides are offline and short enough to read whole."),
|
|
241
|
-
para("A command means the project of the folder it runs in (or above it)."),
|
|
286
|
+
para("A command means the project of the folder it runs in (or above it); mason -C <folder> <command> runs it as if started in that folder."),
|
|
242
287
|
para("Every command but help and mcp (whose stdout is the MCP protocol's) takes --json: one JSON object for a program, always with next (what to run " +
|
|
243
288
|
"next); a failure is { error: { code, message, why, fix }, next }. The exit code says how it went: 0 done, 1 failed " +
|
|
244
|
-
"with the reason, 2 a wrong command line, 124 a wait timed out (mason wait, mason deploy, mason replica create). Driving Mason from a coding agent: mason help agent."),
|
|
289
|
+
"with the reason, 2 a wrong command line, 124 a wait timed out (mason wait, mason deploy, mason replica create, mason replica delete). Driving Mason from a coding agent: mason help agent."),
|
|
245
290
|
"",
|
|
246
291
|
].join("\n");
|
|
247
292
|
}
|