phibac 0.0.1 → 0.1.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/LICENSE +202 -0
- package/README.md +47 -5
- package/dist/api.d.ts +96 -0
- package/dist/api.js +174 -0
- package/dist/api.js.map +1 -0
- package/dist/brand.d.ts +19 -0
- package/dist/brand.js +20 -0
- package/dist/brand.js.map +1 -0
- package/dist/cli.d.ts +4 -0
- package/dist/cli.js +66 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/deploy.d.ts +3 -0
- package/dist/commands/deploy.js +83 -0
- package/dist/commands/deploy.js.map +1 -0
- package/dist/commands/dev.d.ts +3 -0
- package/dist/commands/dev.js +132 -0
- package/dist/commands/dev.js.map +1 -0
- package/dist/commands/generate.d.ts +4 -0
- package/dist/commands/generate.js +33 -0
- package/dist/commands/generate.js.map +1 -0
- package/dist/commands/init.d.ts +3 -0
- package/dist/commands/init.js +62 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/mcp.d.ts +3 -0
- package/dist/commands/mcp.js +151 -0
- package/dist/commands/mcp.js.map +1 -0
- package/dist/commands/native.d.ts +3 -0
- package/dist/commands/native.js +114 -0
- package/dist/commands/native.js.map +1 -0
- package/dist/compile.d.ts +37 -0
- package/dist/compile.js +187 -0
- package/dist/compile.js.map +1 -0
- package/dist/config.d.ts +58 -0
- package/dist/config.js +24 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/package.json +39 -7
- package/src/api.ts +216 -0
- package/src/brand.ts +23 -0
- package/src/cli.ts +66 -0
- package/src/commands/deploy.ts +88 -0
- package/src/commands/dev.ts +127 -0
- package/src/commands/generate.ts +35 -0
- package/src/commands/init.ts +67 -0
- package/src/commands/mcp.ts +145 -0
- package/src/commands/native.ts +125 -0
- package/src/compile.ts +217 -0
- package/src/config.ts +73 -0
- package/src/index.ts +26 -0
- package/bin/phibac.js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AI,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QACnD,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACvB,OAAO,CAAC,CAAC;IACX,CAAC;IACD,OAAO,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,GAAG,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AAC9E,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type Context } from "../api.js";
|
|
2
|
+
export declare const USAGE = "Usage: phibac deploy\n\nCompiles pb.config.ts and publishes its collections. Every collection is\npreviewed first (a dry run). If any change is breaking, or any preview fails,\nnothing is published and the exit code is 1. Collections that are unchanged\nare skipped.\nNeeds PB_TOKEN (a developer token); PB_BASE_URL defaults to the local server.";
|
|
3
|
+
export declare function deploy(ctx: Context): Promise<number>;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { ApiError, CliError, Client, guard, parseFlags } from "../api.js";
|
|
3
|
+
import { CLI_NAME, CONFIG_FILE } from "../brand.js";
|
|
4
|
+
import { compileConfig } from "../compile.js";
|
|
5
|
+
export const USAGE = `Usage: ${CLI_NAME} deploy
|
|
6
|
+
|
|
7
|
+
Compiles ${CONFIG_FILE} and publishes its collections. Every collection is
|
|
8
|
+
previewed first (a dry run). If any change is breaking, or any preview fails,
|
|
9
|
+
nothing is published and the exit code is 1. Collections that are unchanged
|
|
10
|
+
are skipped.
|
|
11
|
+
Needs PB_TOKEN (a developer token); PB_BASE_URL defaults to the local server.`;
|
|
12
|
+
const path = (app, name) => `/v1/apps/${encodeURIComponent(app)}/collections/${encodeURIComponent(name)}`;
|
|
13
|
+
const plural = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`;
|
|
14
|
+
export function deploy(ctx) {
|
|
15
|
+
return guard(ctx, USAGE, async () => {
|
|
16
|
+
parseFlags(ctx.args, {});
|
|
17
|
+
const config = await compileConfig(join(ctx.cwd, CONFIG_FILE));
|
|
18
|
+
if (config.collections.length === 0) {
|
|
19
|
+
ctx.out(`${CONFIG_FILE} defines no collections, so there is nothing to publish. Add a collection (see the commented example), then run ${CLI_NAME} deploy again.`);
|
|
20
|
+
return 0;
|
|
21
|
+
}
|
|
22
|
+
const client = new Client(ctx, true);
|
|
23
|
+
const width = Math.max(...config.collections.map((c) => c.name.length));
|
|
24
|
+
const line = (name, text) => ctx.out(`${name.padEnd(width)} ${text}`);
|
|
25
|
+
ctx.out(`Previewing ${plural(config.collections.length, "collection")} for app ${config.app} on ${client.baseUrl}`);
|
|
26
|
+
const toPublish = [];
|
|
27
|
+
const blocked = [];
|
|
28
|
+
for (const c of config.collections) {
|
|
29
|
+
try {
|
|
30
|
+
const r = await client.request("PUT", path(config.app, c.name), { body: c, query: { dryRun: "true" } });
|
|
31
|
+
if (r.kind === "same") {
|
|
32
|
+
line(c.name, `same (version ${r.major}.${r.minor}, nothing to publish)`);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
line(c.name, `additive (will become version ${r.major}.${r.minor})`);
|
|
36
|
+
toPublish.push(c);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
catch (e) {
|
|
40
|
+
if (!(e instanceof ApiError))
|
|
41
|
+
throw e;
|
|
42
|
+
blocked.push(c.name);
|
|
43
|
+
if (e.code === "schema_incompatible") {
|
|
44
|
+
line(c.name, "breaking");
|
|
45
|
+
for (const reason of e.reasons)
|
|
46
|
+
ctx.out(` - ${reason}`);
|
|
47
|
+
ctx.out(` Publish it as the next major version: set "version": ${c.version + 1} on this collection in ${CONFIG_FILE}, or remove the changes listed above.`);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
line(c.name, `failed (${e.code})`);
|
|
51
|
+
ctx.err(`${c.name}: ${e.code}: ${e.message}`);
|
|
52
|
+
if (e.hint)
|
|
53
|
+
ctx.err(` hint: ${e.hint}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (blocked.length > 0) {
|
|
58
|
+
throw new CliError(`nothing was published: ${blocked.join(", ")} cannot be published (see above). Fix ${plural(blocked.length, "collection")} and run ${CLI_NAME} deploy again.`);
|
|
59
|
+
}
|
|
60
|
+
if (toPublish.length === 0) {
|
|
61
|
+
ctx.out("Nothing to publish: every collection is already up to date.");
|
|
62
|
+
return 0;
|
|
63
|
+
}
|
|
64
|
+
const done = [];
|
|
65
|
+
for (const c of toPublish) {
|
|
66
|
+
try {
|
|
67
|
+
const r = await client.request("PUT", path(config.app, c.name), { body: c });
|
|
68
|
+
done.push(c.name);
|
|
69
|
+
ctx.out(`published ${c.name} version ${r.major}.${r.minor}`);
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
const left = toPublish.slice(done.length).map((x) => x.name);
|
|
73
|
+
ctx.err(`published: ${done.length ? done.join(", ") : "none"}`);
|
|
74
|
+
ctx.err(`not published: ${left.join(", ")}`);
|
|
75
|
+
ctx.err(`Fix the error below, then run ${CLI_NAME} deploy again; collections already published are skipped as unchanged.`);
|
|
76
|
+
throw e;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
ctx.out(`Published ${plural(done.length, "collection")}.`);
|
|
80
|
+
return 0;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=deploy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deploy.js","sourceRoot":"","sources":["../../src/commands/deploy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAgB,MAAM,WAAW,CAAC;AACxF,OAAO,EAAE,QAAQ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,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC;gBAC5F,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;gBAClB,GAAG,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,IAAI,YAAY,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;YAC/D,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,MAAM,IAAI,GAAG,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;gBAC7D,GAAG,CAAC,GAAG,CAAC,cAAc,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;gBAChE,GAAG,CAAC,GAAG,CAAC,kBAAkB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBAC7C,GAAG,CAAC,GAAG,CAAC,iCAAiC,QAAQ,wEAAwE,CAAC,CAAC;gBAC3H,MAAM,CAAC,CAAC;YACV,CAAC;QACH,CAAC;QACD,GAAG,CAAC,GAAG,CAAC,aAAa,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC;QAC3D,OAAO,CAAC,CAAC;IACX,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type Context } from "../api.js";
|
|
2
|
+
export declare const USAGE = "Usage: phibac dev\n\nRuns a pb server for local development (billing off, data in ./.pb, port 8787)\nwith PB_MODE=dev PB_DATA_DIR=./.pb PB_PORT=8787 PB_BASE_URL=http://localhost:8787.\nYour other environment variables are passed to the server (a PB_BASE_URL you set\nfor phibac deploy is not: the local server always gets its own address). Press Ctrl-C to stop it; phibac exits with the server's exit code.\n\nWhich server binary runs:\n PB_SERVER_BIN=<path> run this binary\n PB_RELEASES_URL=<url> otherwise download pb-server_<os>_<arch> for this CLI's\n version from <url>/v<version>/ once, check it against the\n SHA-256 in <that file>.sha256, cache it in ~/.cache/pb/ and run it\n (https only; http://localhost is allowed for tests)\nIf neither is set, phibac dev cannot start a server.";
|
|
3
|
+
export declare function dev(ctx: Context): Promise<number>;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { chmod, mkdir, rename, rm, writeFile } from "node:fs/promises";
|
|
4
|
+
import { constants as osConstants } from "node:os";
|
|
5
|
+
import { dirname, join } from "node:path";
|
|
6
|
+
import { CliError, guard, parseFlags } from "../api.js";
|
|
7
|
+
import { BRAND, CLI_NAME, SERVER_BIN } from "../brand.js";
|
|
8
|
+
export const USAGE = `Usage: ${CLI_NAME} dev
|
|
9
|
+
|
|
10
|
+
Runs a ${BRAND} server for local development (billing off, data in ./.pb, port 8787)
|
|
11
|
+
with PB_MODE=dev PB_DATA_DIR=./.pb PB_PORT=8787 PB_BASE_URL=http://localhost:8787.
|
|
12
|
+
Your other environment variables are passed to the server (a PB_BASE_URL you set
|
|
13
|
+
for ${CLI_NAME} deploy is not: the local server always gets its own address). Press Ctrl-C to stop it; ${CLI_NAME} exits with the server's exit code.
|
|
14
|
+
|
|
15
|
+
Which server binary runs:
|
|
16
|
+
PB_SERVER_BIN=<path> run this binary
|
|
17
|
+
PB_RELEASES_URL=<url> otherwise download ${SERVER_BIN}_<os>_<arch> for this CLI's
|
|
18
|
+
version from <url>/v<version>/ once, check it against the
|
|
19
|
+
SHA-256 in <that file>.sha256, cache it in ~/.cache/${BRAND}/ and run it
|
|
20
|
+
(https only; http://localhost is allowed for tests)
|
|
21
|
+
If neither is set, ${CLI_NAME} dev cannot start a server.`;
|
|
22
|
+
// The local development server's port and address.
|
|
23
|
+
const DEV_PORT = 8787;
|
|
24
|
+
const DEV_BASE_URL = `http://localhost:${DEV_PORT}`;
|
|
25
|
+
const OS_NAMES = { darwin: "darwin", linux: "linux", win32: "windows" };
|
|
26
|
+
const ARCH_NAMES = { x64: "amd64", arm64: "arm64" };
|
|
27
|
+
function checkUrl(raw) {
|
|
28
|
+
let u;
|
|
29
|
+
try {
|
|
30
|
+
u = new URL(raw);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
throw new CliError(`PB_RELEASES_URL ${JSON.stringify(raw)} is not a URL. Use an https:// address.`);
|
|
34
|
+
}
|
|
35
|
+
if (u.protocol !== "https:" && !(u.protocol === "http:" && u.hostname === "localhost")) {
|
|
36
|
+
throw new CliError(`PB_RELEASES_URL must start with https:// (http:// is only allowed for localhost); refusing to download a server binary over ${u.protocol.replace(":", "")}.`);
|
|
37
|
+
}
|
|
38
|
+
return u;
|
|
39
|
+
}
|
|
40
|
+
/** serverBinary returns the path of the binary to run, downloading it if needed. */
|
|
41
|
+
async function serverBinary(ctx) {
|
|
42
|
+
const given = ctx.env.PB_SERVER_BIN?.trim();
|
|
43
|
+
if (given)
|
|
44
|
+
return given;
|
|
45
|
+
const releases = ctx.env.PB_RELEASES_URL?.trim();
|
|
46
|
+
if (!releases) {
|
|
47
|
+
throw new CliError(`there is no server to run. Set PB_SERVER_BIN to the path of a ${SERVER_BIN} binary (build one with "make build" in the server repository), ` +
|
|
48
|
+
`or set PB_RELEASES_URL to the https address that hosts the ${BRAND} server releases so ${CLI_NAME} dev can download one.`);
|
|
49
|
+
}
|
|
50
|
+
checkUrl(releases);
|
|
51
|
+
const os = OS_NAMES[ctx.platform];
|
|
52
|
+
const arch = ARCH_NAMES[ctx.arch];
|
|
53
|
+
if (!os || !arch)
|
|
54
|
+
throw new CliError(`there is no ${SERVER_BIN} release for ${ctx.platform}/${ctx.arch}; set PB_SERVER_BIN to a binary you built.`);
|
|
55
|
+
const asset = `${SERVER_BIN}_${os}_${arch}${os === "windows" ? ".exe" : ""}`;
|
|
56
|
+
const dest = join(ctx.homedir, ".cache", BRAND, `v${ctx.version}`, asset);
|
|
57
|
+
if (existsSync(dest))
|
|
58
|
+
return dest;
|
|
59
|
+
const url = `${releases.replace(/\/+$/, "")}/v${ctx.version}/${asset}`;
|
|
60
|
+
const get = async (u, what) => {
|
|
61
|
+
let res;
|
|
62
|
+
try {
|
|
63
|
+
res = await ctx.fetch(u);
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
throw new CliError(`could not download the ${what} from ${u}: ${e instanceof Error ? e.message : String(e)}`);
|
|
67
|
+
}
|
|
68
|
+
if (!res.ok)
|
|
69
|
+
throw new CliError(`could not download the ${what} from ${u}: HTTP ${res.status}`);
|
|
70
|
+
return res;
|
|
71
|
+
};
|
|
72
|
+
const bin = Buffer.from(await (await get(url, "server binary")).arrayBuffer());
|
|
73
|
+
const sumRes = await get(`${url}.sha256`, "checksum file").catch((e) => {
|
|
74
|
+
throw new CliError(`${e.message}. Refusing to run a server binary without its checksum.`);
|
|
75
|
+
});
|
|
76
|
+
const expected = (await sumRes.text()).trim().split(/\s+/)[0]?.toLowerCase() ?? "";
|
|
77
|
+
if (!/^[0-9a-f]{64}$/.test(expected))
|
|
78
|
+
throw new CliError(`the checksum file ${url}.sha256 does not hold a SHA-256 checksum; refusing to run the downloaded binary.`);
|
|
79
|
+
const actual = createHash("sha256").update(bin).digest("hex");
|
|
80
|
+
if (actual !== expected) {
|
|
81
|
+
throw new CliError(`checksum mismatch for ${url}: expected ${expected}, got ${actual}. The download is not what was released; refusing to run it.`);
|
|
82
|
+
}
|
|
83
|
+
await mkdir(dirname(dest), { recursive: true });
|
|
84
|
+
const part = `${dest}.part-${process.pid}`;
|
|
85
|
+
try {
|
|
86
|
+
await writeFile(part, bin);
|
|
87
|
+
await chmod(part, 0o755);
|
|
88
|
+
await rename(part, dest);
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
await rm(part, { force: true });
|
|
92
|
+
throw new CliError(`could not save the server binary to ${dest}: ${e instanceof Error ? e.message : String(e)}`);
|
|
93
|
+
}
|
|
94
|
+
ctx.out(`Downloaded ${asset} v${ctx.version} to ${dest} (checksum verified).`);
|
|
95
|
+
return dest;
|
|
96
|
+
}
|
|
97
|
+
export function dev(ctx) {
|
|
98
|
+
return guard(ctx, USAGE, async () => {
|
|
99
|
+
parseFlags(ctx.args, {});
|
|
100
|
+
const bin = await serverBinary(ctx);
|
|
101
|
+
const env = { ...ctx.env, PB_MODE: "dev", PB_DATA_DIR: "./.pb", PB_PORT: String(DEV_PORT), PB_BASE_URL: DEV_BASE_URL };
|
|
102
|
+
const given = ctx.env.PB_BASE_URL?.trim();
|
|
103
|
+
if (given && given.replace(/\/+$/, "") !== DEV_BASE_URL) {
|
|
104
|
+
ctx.out(`PB_BASE_URL (${given}) is for ${CLI_NAME} deploy; the local server uses ${DEV_BASE_URL}.`);
|
|
105
|
+
}
|
|
106
|
+
ctx.out(`Starting ${bin} (PB_MODE=dev, data in ./.pb, ${DEV_BASE_URL}). Press Ctrl-C to stop.`);
|
|
107
|
+
const child = ctx.spawn(bin, [], { env, cwd: ctx.cwd, stdio: "inherit" });
|
|
108
|
+
// Ctrl-C reaches the server through the terminal; a signal sent to this
|
|
109
|
+
// process alone is passed on.
|
|
110
|
+
const signals = ["SIGINT", "SIGTERM"];
|
|
111
|
+
const forward = (sig) => () => child.kill?.(sig);
|
|
112
|
+
const handlers = signals.map((s) => [s, forward(s)]);
|
|
113
|
+
for (const [s, h] of handlers)
|
|
114
|
+
process.on(s, h);
|
|
115
|
+
try {
|
|
116
|
+
return await new Promise((resolve, reject) => {
|
|
117
|
+
child.once("error", (e) => reject(new CliError(`could not start ${bin}: ${e.message}`)));
|
|
118
|
+
child.once("exit", (code, signal) => {
|
|
119
|
+
if (code !== null)
|
|
120
|
+
resolve(code);
|
|
121
|
+
else
|
|
122
|
+
resolve(128 + (signal ? (osConstants.signals[signal] ?? 0) : 1));
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
finally {
|
|
127
|
+
for (const [s, h] of handlers)
|
|
128
|
+
process.off(s, h);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=dev.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev.js","sourceRoot":"","sources":["../../src/commands/dev.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAE,SAAS,IAAI,WAAW,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAgB,MAAM,WAAW,CAAC;AACtE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE1D,MAAM,CAAC,MAAM,KAAK,GAAG,UAAU,QAAQ;;SAE9B,KAAK;;;MAGR,QAAQ,2FAA2F,QAAQ;;;;iDAIhE,UAAU;;kFAEuB,KAAK;;qBAElE,QAAQ,6BAA6B,CAAC;AAE3D,mDAAmD;AACnD,MAAM,QAAQ,GAAG,IAAI,CAAC;AACtB,MAAM,YAAY,GAAG,oBAAoB,QAAQ,EAAE,CAAC;AAEpD,MAAM,QAAQ,GAA6C,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;AAClH,MAAM,UAAU,GAA2B,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CA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,EAAE,CAAC,CAAC,IAAI,QAAQ;gBAAE,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACnD,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type Context } from "../api.js";
|
|
2
|
+
export declare const DEFAULT_OUT = "src/pb-types.ts";
|
|
3
|
+
export declare const USAGE = "Usage: phibac generate [--out <file>]\n\nWrites TypeScript types for the collections in pb.config.ts, at the major\nversions it names, from the published schemas. Publish first with phibac deploy.\n --out <file> where to write them (default src/pb-types.ts); directories are created\n and an existing file is overwritten\nNeeds no token; PB_BASE_URL defaults to the local server.";
|
|
4
|
+
export declare function generate(ctx: Context): Promise<number>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
2
|
+
import { dirname, join, resolve } from "node:path";
|
|
3
|
+
import { CliError, Client, guard, parseFlags } from "../api.js";
|
|
4
|
+
import { CLI_NAME, CONFIG_FILE } from "../brand.js";
|
|
5
|
+
import { compileConfig } from "../compile.js";
|
|
6
|
+
export const DEFAULT_OUT = "src/pb-types.ts";
|
|
7
|
+
export const USAGE = `Usage: ${CLI_NAME} generate [--out <file>]
|
|
8
|
+
|
|
9
|
+
Writes TypeScript types for the collections in ${CONFIG_FILE}, at the major
|
|
10
|
+
versions it names, from the published schemas. Publish first with ${CLI_NAME} deploy.
|
|
11
|
+
--out <file> where to write them (default ${DEFAULT_OUT}); directories are created
|
|
12
|
+
and an existing file is overwritten
|
|
13
|
+
Needs no token; PB_BASE_URL defaults to the local server.`;
|
|
14
|
+
export function generate(ctx) {
|
|
15
|
+
return guard(ctx, USAGE, async () => {
|
|
16
|
+
const { values } = parseFlags(ctx.args, { out: { type: "string" } });
|
|
17
|
+
const out = values.out ?? DEFAULT_OUT;
|
|
18
|
+
const config = await compileConfig(join(ctx.cwd, CONFIG_FILE));
|
|
19
|
+
if (config.collections.length === 0) {
|
|
20
|
+
throw new CliError(`${CONFIG_FILE} defines no collections, so there are no types to generate. Add a collection and run ${CLI_NAME} deploy first.`);
|
|
21
|
+
}
|
|
22
|
+
const items = config.collections.map((c) => `${c.name}@${c.version}`);
|
|
23
|
+
const client = new Client(ctx, false);
|
|
24
|
+
const res = await client.send("GET", "/v1/types", { query: { collections: items.join(",") } });
|
|
25
|
+
const ts = await res.text();
|
|
26
|
+
const file = resolve(ctx.cwd, out);
|
|
27
|
+
await mkdir(dirname(file), { recursive: true });
|
|
28
|
+
await writeFile(file, ts);
|
|
29
|
+
ctx.out(`Wrote ${out} (${items.length} ${items.length === 1 ? "collection" : "collections"}: ${items.join(", ")}).`);
|
|
30
|
+
return 0;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=generate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../src/commands/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAgB,MAAM,WAAW,CAAC;AAC9E,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,MAAM,CAAC,MAAM,WAAW,GAAG,iBAAiB,CAAC;AAE7C,MAAM,CAAC,MAAM,KAAK,GAAG,UAAU,QAAQ;;iDAEU,WAAW;oEACQ,QAAQ;gDAC5B,WAAW;;0DAED,CAAC;AAE3D,MAAM,UAAU,QAAQ,CAAC,GAAY;IACnC,OAAO,KAAK,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,IAAI,EAAE;QAClC,MAAM,EAAE,MAAM,E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,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,aAAa,KAAK,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACrH,OAAO,CAAC,CAAC;IACX,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type Context } from "../api.js";
|
|
2
|
+
export declare const USAGE = "Usage: phibac init --name <name> [--origin <url>]\n\nCreates an app on the server and writes pb.config.ts with its app ID.\n --name <name> the name users see on the consent page\n --origin <url> an origin the app is served from, e.g. https://journal.example.com\n (http://localhost:<port> may be used for development). Leave it\n out for an app that is only a mobile app; register that with\n phibac native set.\nNeeds PB_TOKEN (a developer token); PB_BASE_URL defaults to the local server.";
|
|
3
|
+
export declare function init(ctx: Context): Promise<number>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { writeFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { Client, UsageError, CliError, guard, parseFlags } from "../api.js";
|
|
5
|
+
import { BRAND, CLI_NAME, CONFIG_FILE } from "../brand.js";
|
|
6
|
+
export const USAGE = `Usage: ${CLI_NAME} init --name <name> [--origin <url>]
|
|
7
|
+
|
|
8
|
+
Creates an app on the server and writes ${CONFIG_FILE} with its app ID.
|
|
9
|
+
--name <name> the name users see on the consent page
|
|
10
|
+
--origin <url> an origin the app is served from, e.g. https://journal.example.com
|
|
11
|
+
(http://localhost:<port> may be used for development). Leave it
|
|
12
|
+
out for an app that is only a mobile app; register that with
|
|
13
|
+
${CLI_NAME} native set.
|
|
14
|
+
Needs PB_TOKEN (a developer token); PB_BASE_URL defaults to the local server.`;
|
|
15
|
+
/** The scaffold: valid as written, and the commented example works once uncommented. */
|
|
16
|
+
function scaffold(appId) {
|
|
17
|
+
return `// App config for ${BRAND}. Describe your collections inside collections, then run: ${CLI_NAME} deploy
|
|
18
|
+
// To try the example, remove the leading "// " from the lines inside collections
|
|
19
|
+
// and change the collection name to one you own: a reverse-domain name of at
|
|
20
|
+
// least three lowercase parts, e.g. com.yourname.notes.note
|
|
21
|
+
import { defineApp, collection, string, boolean } from "${CLI_NAME}";
|
|
22
|
+
|
|
23
|
+
export default defineApp({
|
|
24
|
+
app: ${JSON.stringify(appId)},
|
|
25
|
+
collections: {
|
|
26
|
+
// "com.example.notes.note": collection({
|
|
27
|
+
// version: 1,
|
|
28
|
+
// description: "A note written by the user",
|
|
29
|
+
// fields: {
|
|
30
|
+
// text: string({ description: "Note text", maxLength: 20000, required: true }),
|
|
31
|
+
// pinned: boolean({ description: "Whether the note is pinned" }),
|
|
32
|
+
// },
|
|
33
|
+
// }),
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
`;
|
|
37
|
+
}
|
|
38
|
+
export function init(ctx) {
|
|
39
|
+
return guard(ctx, USAGE, async () => {
|
|
40
|
+
const { values } = parseFlags(ctx.args, { name: { type: "string" }, origin: { type: "string" } });
|
|
41
|
+
const name = values.name?.trim();
|
|
42
|
+
const origin = values.origin?.trim();
|
|
43
|
+
if (!name)
|
|
44
|
+
throw new UsageError("--name is required");
|
|
45
|
+
const file = join(ctx.cwd, CONFIG_FILE);
|
|
46
|
+
if (existsSync(file)) {
|
|
47
|
+
throw new CliError(`${CONFIG_FILE} already exists in ${ctx.cwd}; not overwriting it. Delete or rename it to start over, or keep using it (its \`app\` value is the app ID).`);
|
|
48
|
+
}
|
|
49
|
+
const app = await new Client(ctx, true).request("POST", "/v1/apps", { body: { name, origins: origin ? [origin] : [] } });
|
|
50
|
+
try {
|
|
51
|
+
await writeFile(file, scaffold(app.id), { flag: "wx" });
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
throw new CliError(`created app ${app.id} but could not write ${file}: ${e instanceof Error ? e.message : String(e)}. Create the file yourself with app: "${app.id}".`);
|
|
55
|
+
}
|
|
56
|
+
ctx.out(`Created app ${app.id} (${name}, ${origin ? `origin ${origin}` : "no web address"}).`);
|
|
57
|
+
ctx.out(`Wrote ${CONFIG_FILE}.`);
|
|
58
|
+
ctx.out(`Next: define your collections in ${CONFIG_FILE} (see the commented example), then run: ${CLI_NAME} deploy`);
|
|
59
|
+
return 0;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=init.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAgB,MAAM,WAAW,CAAC;AAC1F,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE3D,MAAM,CAAC,MAAM,KAAK,GAAG,UAAU,QAAQ;;0CAEG,WAAW;;;;;qBAKhC,QAAQ;8EACiD,CAAC;AAM/E,wFAAwF;AACxF,SAAS,QAAQ,CAAC,KAAa;IAC7B,OAAO,qBAAqB,KAAK,6DAA6D,QAAQ;;;;0DAI9C,QAAQ;;;SAGzD,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;;;;;;;;;;;;CAY7B,CAAC;AACF,CAAC;AAED,MAAM,UAAU,IAAI,CAAC,GAAY;IAC/B,OAAO,KAAK,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,IAAI,EAAE;QAClC,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC;QAClG,MAAM,IAAI,G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AAC;QAC/F,GAAG,CAAC,GAAG,CAAC,SAAS,WAAW,GAAG,CAAC,CAAC;QACjC,GAAG,CAAC,GAAG,CAAC,oCAAoC,WAAW,2CAA2C,QAAQ,SAAS,CAAC,CAAC;QACrH,OAAO,CAAC,CAAC;IACX,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type Context } from "../api.js";
|
|
2
|
+
export declare const USAGE = "Usage: phibac mcp\n\nA bridge for agents that speak MCP over stdio. Each newline-delimited JSON-RPC\nmessage read from stdin is POSTed to PB_BASE_URL/mcp with your developer token,\nand each response message is written to stdout as one line. Diagnostics go to\nstderr. It exits when stdin closes.\nNeeds PB_TOKEN (a developer token); PB_BASE_URL defaults to the local server.";
|
|
3
|
+
export declare function mcp(ctx: Context): Promise<number>;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { ApiError, Client, formatApiError, guard, parseFlags, redact, requireToken } from "../api.js";
|
|
2
|
+
import { CLI_NAME } from "../brand.js";
|
|
3
|
+
export const USAGE = `Usage: ${CLI_NAME} mcp
|
|
4
|
+
|
|
5
|
+
A bridge for agents that speak MCP over stdio. Each newline-delimited JSON-RPC
|
|
6
|
+
message read from stdin is POSTed to PB_BASE_URL/mcp with your developer token,
|
|
7
|
+
and each response message is written to stdout as one line. Diagnostics go to
|
|
8
|
+
stderr. It exits when stdin closes.
|
|
9
|
+
Needs PB_TOKEN (a developer token); PB_BASE_URL defaults to the local server.`;
|
|
10
|
+
/** The JSON-RPC server-error code used for transport failures. */
|
|
11
|
+
const TRANSPORT_ERROR = -32000;
|
|
12
|
+
const PARSE_ERROR = -32700;
|
|
13
|
+
function isRpc(text) {
|
|
14
|
+
try {
|
|
15
|
+
return JSON.parse(text)?.jsonrpc === "2.0";
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** Reads the data fields of server-sent events from a stream, calling onData for each event. */
|
|
22
|
+
async function readEvents(body, onData) {
|
|
23
|
+
const decoder = new TextDecoder();
|
|
24
|
+
const reader = body.getReader();
|
|
25
|
+
let buf = "";
|
|
26
|
+
const flush = (block) => {
|
|
27
|
+
const data = block
|
|
28
|
+
.split("\n")
|
|
29
|
+
.filter((l) => l.startsWith("data:"))
|
|
30
|
+
.map((l) => l.slice(5).replace(/^ /, ""))
|
|
31
|
+
.join("\n");
|
|
32
|
+
if (data !== "")
|
|
33
|
+
onData(data);
|
|
34
|
+
};
|
|
35
|
+
for (;;) {
|
|
36
|
+
const { done, value } = await reader.read();
|
|
37
|
+
buf += decoder.decode(value, { stream: !done }).replace(/\r\n?/g, "\n");
|
|
38
|
+
let i;
|
|
39
|
+
while ((i = buf.indexOf("\n\n")) >= 0) {
|
|
40
|
+
flush(buf.slice(0, i));
|
|
41
|
+
buf = buf.slice(i + 2);
|
|
42
|
+
}
|
|
43
|
+
if (done)
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
if (buf.trim() !== "")
|
|
47
|
+
flush(buf);
|
|
48
|
+
}
|
|
49
|
+
export function mcp(ctx) {
|
|
50
|
+
return guard(ctx, USAGE, async () => {
|
|
51
|
+
parseFlags(ctx.args, {});
|
|
52
|
+
const token = requireToken(ctx.env);
|
|
53
|
+
const client = new Client(ctx, true);
|
|
54
|
+
const url = `${client.baseUrl}/mcp`;
|
|
55
|
+
const emit = (msg) => ctx.out(JSON.stringify(msg));
|
|
56
|
+
const rpcError = (id, code, message) => emit({ jsonrpc: "2.0", id, error: { code, message } });
|
|
57
|
+
/** fail reports a failed request: to the caller when it has an id, else on stderr. */
|
|
58
|
+
const fail = (id, message) => {
|
|
59
|
+
const text = redact(message, token);
|
|
60
|
+
if (id !== undefined)
|
|
61
|
+
rpcError(id, TRANSPORT_ERROR, text);
|
|
62
|
+
else
|
|
63
|
+
ctx.err(`${CLI_NAME} mcp: ${text}`);
|
|
64
|
+
};
|
|
65
|
+
const emitMessage = (text) => {
|
|
66
|
+
let parsed;
|
|
67
|
+
try {
|
|
68
|
+
parsed = JSON.parse(text);
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
ctx.err(`${CLI_NAME} mcp: the server sent a message that is not JSON; dropped it`);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
for (const m of Array.isArray(parsed) ? parsed : [parsed])
|
|
75
|
+
emit(m);
|
|
76
|
+
};
|
|
77
|
+
const handle = async (line) => {
|
|
78
|
+
let msg;
|
|
79
|
+
try {
|
|
80
|
+
msg = JSON.parse(line);
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
rpcError(null, PARSE_ERROR, "the message is not valid JSON");
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const id = typeof msg === "object" && msg !== null && "id" in msg ? msg.id : undefined;
|
|
87
|
+
let res;
|
|
88
|
+
try {
|
|
89
|
+
res = await ctx.fetch(url, {
|
|
90
|
+
method: "POST",
|
|
91
|
+
headers: {
|
|
92
|
+
Authorization: `Bearer ${token}`,
|
|
93
|
+
"Content-Type": "application/json",
|
|
94
|
+
Accept: "application/json, text/event-stream",
|
|
95
|
+
},
|
|
96
|
+
body: line,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
catch (e) {
|
|
100
|
+
fail(id, client.networkError(e).message);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
try {
|
|
104
|
+
if (!res.ok) {
|
|
105
|
+
const text = await res.text().catch(() => "");
|
|
106
|
+
// A JSON-RPC error body (for example for a malformed request) is passed on as it is.
|
|
107
|
+
if (isRpc(text)) {
|
|
108
|
+
emitMessage(text);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const err = client.errorFromText(res.status, text, url);
|
|
112
|
+
fail(id, err instanceof ApiError ? formatApiError(err).join(" ").replace(/^error: /, "") : err.message);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (res.status === 202 || res.status === 204 || !res.body)
|
|
116
|
+
return;
|
|
117
|
+
if ((res.headers.get("content-type") ?? "").includes("text/event-stream")) {
|
|
118
|
+
await readEvents(res.body, emitMessage);
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
const text = await res.text();
|
|
122
|
+
if (text.trim() !== "")
|
|
123
|
+
emitMessage(text);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
catch (e) {
|
|
127
|
+
fail(id, `the response could not be read: ${e instanceof Error ? e.message : String(e)}`);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
const pending = [];
|
|
131
|
+
const decoder = new TextDecoder();
|
|
132
|
+
let buf = "";
|
|
133
|
+
const take = (line) => {
|
|
134
|
+
if (line.trim() !== "")
|
|
135
|
+
pending.push(handle(line.trim()));
|
|
136
|
+
};
|
|
137
|
+
for await (const chunk of ctx.stdin) {
|
|
138
|
+
buf += typeof chunk === "string" ? chunk : decoder.decode(chunk, { stream: true });
|
|
139
|
+
let i;
|
|
140
|
+
while ((i = buf.indexOf("\n")) >= 0) {
|
|
141
|
+
take(buf.slice(0, i));
|
|
142
|
+
buf = buf.slice(i + 1);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
buf += decoder.decode();
|
|
146
|
+
take(buf);
|
|
147
|
+
await Promise.all(pending);
|
|
148
|
+
return 0;
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=mcp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.js","sourceRoot":"","sources":["../../src/commands/mcp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,cAAc,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,EAAgB,MAAM,WAAW,CAAC;AACpH,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,MAAM,CAAC,MAAM,KAAK,GAAG,UAAU,QAAQ;;;;;;8EAMuC,CAAC;AAE/E,kEA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YACzB,CAAC;QACH,CAAC;QACD,GAAG,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;QACxB,IAAI,CAAC,GAAG,CAAC,CAAC;QACV,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC3B,OAAO,CAAC,CAAC;IACX,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type Context } from "../api.js";
|
|
2
|
+
export declare const USAGE = "Usage: phibac native set [--ios <team>.<bundle>]... [--android <package>=<fingerprint>[,<fingerprint>]...]...\n phibac native show\n\nRegisters the iOS and Android apps that are the app in pb.config.ts, so that\na phone hands a sign-in back to those apps and no other.\n set replaces the list of each platform that is given; a platform that is\n not given is left as it is. \"--ios none\" or \"--android none\" clears it.\n --ios A1B2C3D4E5.com.example.notes\n the Apple team ID, a dot, the bundle ID\n --android com.example.notes=14:6D:...,AA:BB:...\n the package name, \"=\", the SHA-256 fingerprints of the\n certificates the app is signed with (a debug build, an upload\n key and the store's signing key each have their own)\n show prints what is registered and the address a sign-in returns to.\nNeeds PB_TOKEN (a developer token); PB_BASE_URL defaults to the local server.";
|
|
3
|
+
export declare function native(ctx: Context): Promise<number>;
|