@kvbox/cli 0.5.48 → 0.5.49
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/kvbox.js +100 -55
- package/dist/kvbox.js.map +1 -1
- package/package.json +1 -1
package/dist/kvbox.js
CHANGED
|
@@ -164,7 +164,7 @@ function versionOf(srcFileUrl, injected) {
|
|
|
164
164
|
}
|
|
165
165
|
|
|
166
166
|
// src/version.ts
|
|
167
|
-
var VERSION = versionOf(import.meta.url, true ? "0.5.
|
|
167
|
+
var VERSION = versionOf(import.meta.url, true ? "0.5.49" : void 0);
|
|
168
168
|
|
|
169
169
|
// src/commands/vm/index.ts
|
|
170
170
|
import { Command as Command37 } from "commander";
|
|
@@ -802,6 +802,15 @@ var CapacitySchema = z2.object({
|
|
|
802
802
|
version: z2.string().optional()
|
|
803
803
|
});
|
|
804
804
|
var ImageSchema = z2.object({ name: z2.string(), version: z2.string().nullable() });
|
|
805
|
+
var ImageIndexSchema = z2.object({
|
|
806
|
+
updatedAt: z2.string(),
|
|
807
|
+
images: z2.record(z2.string(), z2.object({ version: z2.string().min(1), minServer: z2.string().min(1).optional() }))
|
|
808
|
+
});
|
|
809
|
+
var LatestImagesSchema = z2.object({
|
|
810
|
+
updatedAt: z2.string().nullable(),
|
|
811
|
+
images: ImageIndexSchema.shape.images,
|
|
812
|
+
checkedAt: z2.string().nullable()
|
|
813
|
+
});
|
|
805
814
|
var RecoveryReportSchema = z2.object({
|
|
806
815
|
at: z2.string(),
|
|
807
816
|
booted: z2.array(z2.string()),
|
|
@@ -1261,11 +1270,18 @@ var ManagedCatalogEntrySchema = z4.object({
|
|
|
1261
1270
|
description: z4.string(),
|
|
1262
1271
|
/** The version a new one runs, as shown: `18`. */
|
|
1263
1272
|
version: z4.string(),
|
|
1264
|
-
/** The port
|
|
1273
|
+
/** The port a linked box reaches it on. */
|
|
1265
1274
|
port: z4.number().int(),
|
|
1275
|
+
/** The port `public on` opens behind a host port: `port` again unless the kind serves TLS on another. */
|
|
1276
|
+
publicPort: z4.number().int(),
|
|
1277
|
+
/** Its guide, as a URL. */
|
|
1278
|
+
docs: z4.string().optional(),
|
|
1266
1279
|
storage: z4.object({ defaultGib: z4.number().int(), minGib: z4.number().int(), maxGib: z4.number().int() }),
|
|
1267
|
-
/**
|
|
1268
|
-
|
|
1280
|
+
/**
|
|
1281
|
+
* What create takes of this kind alone, beside what every kind takes (name, password, storage, near): a
|
|
1282
|
+
* flag and a form field each, all optional, `default` in words.
|
|
1283
|
+
*/
|
|
1284
|
+
options: z4.array(z4.object({ name: z4.string(), title: z4.string(), description: z4.string(), default: z4.string() })),
|
|
1269
1285
|
/** A month of it running with the default storage, and each further GB of storage. */
|
|
1270
1286
|
price: PriceSchema.extend({ storageGibPerMonth: z4.number() }),
|
|
1271
1287
|
/** Whether a host answering now can run it. */
|
|
@@ -1273,25 +1289,24 @@ var ManagedCatalogEntrySchema = z4.object({
|
|
|
1273
1289
|
});
|
|
1274
1290
|
var CreateManagedRequest = z4.object({
|
|
1275
1291
|
name: z4.string(),
|
|
1276
|
-
|
|
1277
|
-
|
|
1292
|
+
/** The kind's own options by name (its catalog entry lists them); the kind checks them. */
|
|
1293
|
+
options: z4.record(z4.string(), z4.string()).optional(),
|
|
1278
1294
|
password: z4.string().optional(),
|
|
1279
1295
|
storageGib: z4.number().int().optional(),
|
|
1280
1296
|
/** Place it on the host of this box, so the box can be linked to it. */
|
|
1281
1297
|
near: z4.string().optional()
|
|
1282
1298
|
});
|
|
1283
1299
|
var ManagedHealthSchema = z4.object({
|
|
1284
|
-
/** Its first start has finished:
|
|
1300
|
+
/** Its first start has finished: it has set itself up on its storage. */
|
|
1285
1301
|
ready: z4.boolean(),
|
|
1286
1302
|
/** It accepts connections. */
|
|
1287
1303
|
accepting: z4.boolean(),
|
|
1288
1304
|
version: z4.string(),
|
|
1289
|
-
connections: z4.number().int(),
|
|
1290
|
-
/** The size of the data itself. */
|
|
1291
|
-
dataBytes: z4.number().optional(),
|
|
1292
1305
|
/** The storage volume: what is used of it and its size. */
|
|
1293
1306
|
storageUsedBytes: z4.number().optional(),
|
|
1294
|
-
storageTotalBytes: z4.number().optional()
|
|
1307
|
+
storageTotalBytes: z4.number().optional(),
|
|
1308
|
+
/** What else the kind reports, ready to show: `{title: "Connections", value: "3"}`. */
|
|
1309
|
+
facts: z4.array(z4.object({ title: z4.string(), value: z4.string() }))
|
|
1295
1310
|
});
|
|
1296
1311
|
var UrlsSchema = z4.object({ private: z4.string(), public: z4.string().optional() });
|
|
1297
1312
|
var ManagedSchema = z4.object({
|
|
@@ -1304,8 +1319,8 @@ var ManagedSchema = z4.object({
|
|
|
1304
1319
|
status: BoxStatusSchema,
|
|
1305
1320
|
/** The catalog version: `18`. */
|
|
1306
1321
|
version: z4.string(),
|
|
1307
|
-
|
|
1308
|
-
|
|
1322
|
+
/** What the kind keeps of its create options, defaults filled in: `{database, user}` for Postgres, `{}` for a kind with none. */
|
|
1323
|
+
settings: z4.record(z4.string(), z4.string()),
|
|
1309
1324
|
storageGib: z4.number().int(),
|
|
1310
1325
|
/** Where a linked box reaches it: `<name>.<slug>.kvbox` (resolves from a box of any slug it is linked to) and the port. */
|
|
1311
1326
|
private: z4.object({ host: z4.string(), port: z4.number().int() }),
|
|
@@ -1324,7 +1339,7 @@ var ManagedSchema = z4.object({
|
|
|
1324
1339
|
/** Only in `GET /managed/<kind>/<name>` (asked live): null when it is not running or did not answer. */
|
|
1325
1340
|
health: ManagedHealthSchema.nullable().optional()
|
|
1326
1341
|
});
|
|
1327
|
-
var ManagedSecretSchema = z4.object({
|
|
1342
|
+
var ManagedSecretSchema = z4.object({ password: z4.string(), urls: UrlsSchema });
|
|
1328
1343
|
var CreatedManagedSchema = ManagedSchema.extend({ secret: ManagedSecretSchema });
|
|
1329
1344
|
var ResetPasswordRequest = z4.object({ password: z4.string().optional() });
|
|
1330
1345
|
var SetPublicRequest = z4.object({ on: z4.boolean() });
|
|
@@ -5729,8 +5744,26 @@ import { setTimeout as sleep3 } from "timers/promises";
|
|
|
5729
5744
|
|
|
5730
5745
|
// src/commands/managed/shared.ts
|
|
5731
5746
|
import "commander";
|
|
5732
|
-
var POSTGRES2 = {
|
|
5733
|
-
|
|
5747
|
+
var POSTGRES2 = {
|
|
5748
|
+
kind: "postgres",
|
|
5749
|
+
command: "pg",
|
|
5750
|
+
aliases: ["postgres"],
|
|
5751
|
+
title: "PostgreSQL",
|
|
5752
|
+
storageGib: 10,
|
|
5753
|
+
options: [
|
|
5754
|
+
{ name: "database", arg: "name", help: "the database created in it (default: the name)" },
|
|
5755
|
+
{ name: "user", arg: "name", help: "the user that owns it (default: the name)" }
|
|
5756
|
+
]
|
|
5757
|
+
};
|
|
5758
|
+
var REDIS = {
|
|
5759
|
+
kind: "redis",
|
|
5760
|
+
command: "redis",
|
|
5761
|
+
aliases: [],
|
|
5762
|
+
title: "Redis (Valkey)",
|
|
5763
|
+
storageGib: 5,
|
|
5764
|
+
options: []
|
|
5765
|
+
};
|
|
5766
|
+
var KINDS = [POSTGRES2, REDIS];
|
|
5734
5767
|
async function managedClient(cmd) {
|
|
5735
5768
|
const client = await clientFor(cmd.optsWithGlobals());
|
|
5736
5769
|
if (client.target.kind !== "cloud") {
|
|
@@ -5757,9 +5790,9 @@ function infoRows(spec, m, user) {
|
|
|
5757
5790
|
["version", `${spec.title} ${m.health?.version ?? m.version}`]
|
|
5758
5791
|
];
|
|
5759
5792
|
if (user !== void 0 && m.owner !== user) rows2.push(["owner", m.owner]);
|
|
5760
|
-
|
|
5793
|
+
for (const fact of m.health?.facts ?? []) rows2.push([fact.title.toLowerCase(), fact.value]);
|
|
5761
5794
|
rows2.push(["storage", `${storageText(m)}${nearlyFull(m) ? color.yellow(` almost full: kvbox ${spec.command} grow ${name} <GB>`) : ""}`]);
|
|
5762
|
-
rows2.push(
|
|
5795
|
+
rows2.push(...settingRows(spec, m.settings), ["password", color.dim(`kvbox ${spec.command} password ${name}`)]);
|
|
5763
5796
|
rows2.push(["private", `${m.urls.private} ${color.dim(m.links.length > 0 ? `(from ${m.links.join(", ")})` : `(no box is linked: kvbox ${spec.command} link ${name} <box>)`)}`]);
|
|
5764
5797
|
rows2.push(["public", m.urls.public ?? color.dim(`off (kvbox ${spec.command} public ${name} on)`)]);
|
|
5765
5798
|
rows2.push(["cost", `${money(m.price.perMonth, m.price.currency)} a month while it runs, ${money(m.price.storagePerMonth, m.price.currency)} stopped ${color.dim("(estimated)")}`]);
|
|
@@ -5771,9 +5804,13 @@ function printRows(rows2) {
|
|
|
5771
5804
|
for (const [label, value] of rows2) process.stdout.write(`${color.dim(label.padEnd(width2))} ${value}
|
|
5772
5805
|
`);
|
|
5773
5806
|
}
|
|
5807
|
+
function settingRows(spec, settings) {
|
|
5808
|
+
const order = spec.options.map((o) => o.name);
|
|
5809
|
+
const names2 = [...order.filter((name) => settings[name] !== void 0), ...Object.keys(settings).filter((name) => !order.includes(name))];
|
|
5810
|
+
return names2.map((name) => [name, settings[name]]);
|
|
5811
|
+
}
|
|
5774
5812
|
function secretRows(secret) {
|
|
5775
5813
|
return [
|
|
5776
|
-
["user", secret.user],
|
|
5777
5814
|
["password", secret.password],
|
|
5778
5815
|
["private", secret.urls.private],
|
|
5779
5816
|
...secret.urls.public ? [["public", secret.urls.public]] : []
|
|
@@ -5788,43 +5825,46 @@ function parseStorage(text2, flag) {
|
|
|
5788
5825
|
// src/commands/managed/create.ts
|
|
5789
5826
|
var READY_WAIT_MS = 9e4;
|
|
5790
5827
|
var READY_STEP_MS = 2e3;
|
|
5791
|
-
var createCommand4 = (spec) =>
|
|
5792
|
-
const
|
|
5793
|
-
|
|
5794
|
-
|
|
5795
|
-
|
|
5796
|
-
|
|
5797
|
-
|
|
5798
|
-
|
|
5799
|
-
|
|
5800
|
-
|
|
5801
|
-
|
|
5802
|
-
|
|
5803
|
-
const
|
|
5804
|
-
|
|
5805
|
-
|
|
5806
|
-
|
|
5807
|
-
|
|
5828
|
+
var createCommand4 = (spec) => {
|
|
5829
|
+
const command = new Command63("create").alias("new").description(`create a ${spec.title} database: a name is all it needs`).argument("<name>", "its name (1-12 chars, lowercase letters, digits and '-'); a linked box reaches it at <name>.<account>.kvbox");
|
|
5830
|
+
for (const o of spec.options) command.option(`--${o.name} <${o.arg}>`, o.help);
|
|
5831
|
+
return command.option("--password <password>", "its password (default: generated)").option("--storage <gb>", `storage for the data in GB (default: ${spec.storageGib}; it can grow later)`).option("--near <box>", "run it on the host of this box, so the box can be linked to it").option("--json", "print it as JSON, password included").action(async (name, opts, cmd) => {
|
|
5832
|
+
const options = Object.fromEntries(spec.options.flatMap((o) => typeof opts[o.name] === "string" ? [[o.name, opts[o.name]]] : []));
|
|
5833
|
+
const req = {
|
|
5834
|
+
name,
|
|
5835
|
+
...Object.keys(options).length > 0 ? { options } : {},
|
|
5836
|
+
...opts.password !== void 0 ? { password: opts.password } : {},
|
|
5837
|
+
...opts.storage !== void 0 ? { storageGib: parseStorage(opts.storage, "--storage") } : {},
|
|
5838
|
+
...opts.near !== void 0 ? { near: opts.near } : {}
|
|
5839
|
+
};
|
|
5840
|
+
const client = await managedClient(cmd);
|
|
5841
|
+
try {
|
|
5842
|
+
const made = await spin(`creating ${spec.title} database ${name}\u2026`, client.createManaged(spec.kind, req));
|
|
5843
|
+
const shown = shownName(made, me(client));
|
|
5844
|
+
const ready = await spin(`starting ${spec.title}\u2026`, async () => {
|
|
5845
|
+
for (const until = Date.now() + READY_WAIT_MS; Date.now() < until; await sleep3(READY_STEP_MS)) {
|
|
5846
|
+
const now = await client.getManaged(spec.kind, shown).catch(() => void 0);
|
|
5847
|
+
if (now?.health?.ready && now.health.accepting) return true;
|
|
5848
|
+
}
|
|
5849
|
+
return false;
|
|
5850
|
+
});
|
|
5851
|
+
if (opts.json) {
|
|
5852
|
+
json({ ...made, ready });
|
|
5853
|
+
return;
|
|
5808
5854
|
}
|
|
5809
|
-
|
|
5810
|
-
|
|
5811
|
-
|
|
5812
|
-
|
|
5813
|
-
|
|
5855
|
+
info(`${color.green("\u2713")} database ${color.bold(shown)} ${ready ? "is ready" : "is created and still starting"} ${color.dim(`(${spec.title} ${made.version}, ${made.storageGib} GB of storage)`)}`);
|
|
5856
|
+
printRows([...settingRows(spec, made.settings), ...secretRows(made.secret)].map(([label, value]) => [` ${label}`, value]));
|
|
5857
|
+
info("");
|
|
5858
|
+
info("Nobody can reach it yet. To let something in:");
|
|
5859
|
+
info(` a box on the same host kvbox ${spec.command} link ${shown} <box> ${color.dim(`(a new one: kvbox new <box> --near ${shown})`)}`);
|
|
5860
|
+
info(` the internet kvbox ${spec.command} public ${shown} on`);
|
|
5861
|
+
info(color.dim(`It costs about ${money(made.price.perMonth, made.price.currency)} a month while it runs, ${money(made.price.storagePerMonth, made.price.currency)} stopped. The password again: kvbox ${spec.command} password ${shown}`));
|
|
5862
|
+
if (!ready) info(color.dim(`It was not answering after ${READY_WAIT_MS / 1e3} s; see how it is with: kvbox ${spec.command} info ${shown}`));
|
|
5863
|
+
} finally {
|
|
5864
|
+
await client.close();
|
|
5814
5865
|
}
|
|
5815
|
-
|
|
5816
|
-
|
|
5817
|
-
printRows(rows2.map(([label, value]) => [` ${label}`, value]));
|
|
5818
|
-
info("");
|
|
5819
|
-
info("Nobody can reach it yet. To let something in:");
|
|
5820
|
-
info(` a box on the same host kvbox ${spec.command} link ${shown} <box> ${color.dim(`(a new one: kvbox new <box> --near ${shown})`)}`);
|
|
5821
|
-
info(` the internet kvbox ${spec.command} public ${shown} on`);
|
|
5822
|
-
info(color.dim(`It costs about ${money(made.price.perMonth, made.price.currency)} a month while it runs, ${money(made.price.storagePerMonth, made.price.currency)} stopped. The password again: kvbox ${spec.command} password ${shown}`));
|
|
5823
|
-
if (!ready) info(color.dim(`It was not answering after ${READY_WAIT_MS / 1e3} s; see how it is with: kvbox ${spec.command} info ${shown}`));
|
|
5824
|
-
} finally {
|
|
5825
|
-
await client.close();
|
|
5826
|
-
}
|
|
5827
|
-
});
|
|
5866
|
+
});
|
|
5867
|
+
};
|
|
5828
5868
|
|
|
5829
5869
|
// src/commands/managed/grow.ts
|
|
5830
5870
|
import { Command as Command64 } from "commander";
|
|
@@ -6011,9 +6051,12 @@ function kindCommand(spec, description) {
|
|
|
6011
6051
|
// src/commands/pg/index.ts
|
|
6012
6052
|
var pgCommand = kindCommand(POSTGRES2, "managed PostgreSQL: a database kvbox runs for you, private until you link a box or make it public");
|
|
6013
6053
|
|
|
6054
|
+
// src/commands/redis/index.ts
|
|
6055
|
+
var redisCommand = kindCommand(REDIS, "managed Redis (Valkey): a Redis kvbox runs for you, private until you link a box or make it public");
|
|
6056
|
+
|
|
6014
6057
|
// src/commands/managed/index.ts
|
|
6015
6058
|
import { Command as Command75 } from "commander";
|
|
6016
|
-
var managedCommand = new Command75("managed").description(
|
|
6059
|
+
var managedCommand = new Command75("managed").description(`databases kvbox runs for you, every kind together (${KINDS.map((k) => `${k.title}: kvbox ${k.command}`).join(", ")})`).addCommand(lsCommand9().option("--org <slug>", "act in this org (- for your personal databases)"));
|
|
6017
6060
|
|
|
6018
6061
|
// src/commands/env/index.ts
|
|
6019
6062
|
import { Command as Command79 } from "commander";
|
|
@@ -6468,6 +6511,7 @@ var HELP_GROUPS = [
|
|
|
6468
6511
|
["snapshots", "freeze a running box into a snapshot, start new boxes from it"],
|
|
6469
6512
|
["volume", "disks of their own that move between boxes"],
|
|
6470
6513
|
["pg", "managed PostgreSQL: a database kvbox runs for you"],
|
|
6514
|
+
["redis", "managed Redis (Valkey): a Redis kvbox runs for you"],
|
|
6471
6515
|
["managed", "every managed database, whatever its kind"],
|
|
6472
6516
|
["env", "environment variables and secrets every box of yours gets"],
|
|
6473
6517
|
["domain", "serve a box at a domain of your own"]
|
|
@@ -6531,6 +6575,7 @@ function buildProgram() {
|
|
|
6531
6575
|
program.addCommand(snapshotsCommand);
|
|
6532
6576
|
program.addCommand(volumeCommand);
|
|
6533
6577
|
program.addCommand(pgCommand);
|
|
6578
|
+
program.addCommand(redisCommand);
|
|
6534
6579
|
program.addCommand(managedCommand);
|
|
6535
6580
|
program.addCommand(envCommand);
|
|
6536
6581
|
program.addCommand(domainCommand);
|