scribase 0.1.0 → 0.3.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/CHANGELOG.md +56 -0
- package/LICENSE +202 -0
- package/README.md +59 -20
- package/dist/cli/add.d.ts +98 -0
- package/dist/cli/add.d.ts.map +1 -0
- package/dist/cli/add.js +348 -0
- package/dist/cli/add.js.map +1 -0
- package/dist/cli/aliases.d.ts +9 -0
- package/dist/cli/aliases.d.ts.map +1 -0
- package/dist/cli/aliases.js +14 -0
- package/dist/cli/aliases.js.map +1 -0
- package/dist/cli/branch.d.ts +73 -0
- package/dist/cli/branch.d.ts.map +1 -0
- package/dist/cli/branch.js +351 -0
- package/dist/cli/branch.js.map +1 -0
- package/dist/cli/capabilities/ota.d.ts +80 -0
- package/dist/cli/capabilities/ota.d.ts.map +1 -0
- package/dist/cli/capabilities/ota.js +299 -0
- package/dist/cli/capabilities/ota.js.map +1 -0
- package/dist/cli/capabilities/railyard/ai.d.ts +14 -0
- package/dist/cli/capabilities/railyard/ai.d.ts.map +1 -0
- package/dist/cli/capabilities/railyard/ai.js +33 -0
- package/dist/cli/capabilities/railyard/ai.js.map +1 -0
- package/dist/cli/capabilities/railyard/analytics.d.ts +27 -0
- package/dist/cli/capabilities/railyard/analytics.d.ts.map +1 -0
- package/dist/cli/capabilities/railyard/analytics.js +72 -0
- package/dist/cli/capabilities/railyard/analytics.js.map +1 -0
- package/dist/cli/capabilities/railyard/billing.d.ts +14 -0
- package/dist/cli/capabilities/railyard/billing.d.ts.map +1 -0
- package/dist/cli/capabilities/railyard/billing.js +39 -0
- package/dist/cli/capabilities/railyard/billing.js.map +1 -0
- package/dist/cli/capabilities/railyard/consent-files.d.ts +16 -0
- package/dist/cli/capabilities/railyard/consent-files.d.ts.map +1 -0
- package/dist/cli/capabilities/railyard/consent-files.js +24 -0
- package/dist/cli/capabilities/railyard/consent-files.js.map +1 -0
- package/dist/cli/capabilities/railyard/consent.d.ts +12 -0
- package/dist/cli/capabilities/railyard/consent.d.ts.map +1 -0
- package/dist/cli/capabilities/railyard/consent.js +38 -0
- package/dist/cli/capabilities/railyard/consent.js.map +1 -0
- package/dist/cli/capabilities/railyard/deploy.d.ts +16 -0
- package/dist/cli/capabilities/railyard/deploy.d.ts.map +1 -0
- package/dist/cli/capabilities/railyard/deploy.js +68 -0
- package/dist/cli/capabilities/railyard/deploy.js.map +1 -0
- package/dist/cli/capabilities/railyard/flags.d.ts +18 -0
- package/dist/cli/capabilities/railyard/flags.d.ts.map +1 -0
- package/dist/cli/capabilities/railyard/flags.js +45 -0
- package/dist/cli/capabilities/railyard/flags.js.map +1 -0
- package/dist/cli/capabilities/railyard/index.d.ts +55 -0
- package/dist/cli/capabilities/railyard/index.d.ts.map +1 -0
- package/dist/cli/capabilities/railyard/index.js +209 -0
- package/dist/cli/capabilities/railyard/index.js.map +1 -0
- package/dist/cli/capabilities/railyard/uptime.d.ts +18 -0
- package/dist/cli/capabilities/railyard/uptime.d.ts.map +1 -0
- package/dist/cli/capabilities/railyard/uptime.js +47 -0
- package/dist/cli/capabilities/railyard/uptime.js.map +1 -0
- package/dist/cli/connect.d.ts +100 -0
- package/dist/cli/connect.d.ts.map +1 -0
- package/dist/cli/connect.js +338 -0
- package/dist/cli/connect.js.map +1 -0
- package/dist/cli/credentials.d.ts +8 -0
- package/dist/cli/credentials.d.ts.map +1 -1
- package/dist/cli/credentials.js +27 -0
- package/dist/cli/credentials.js.map +1 -1
- package/dist/cli/doctor.d.ts +51 -0
- package/dist/cli/doctor.d.ts.map +1 -0
- package/dist/cli/doctor.js +265 -0
- package/dist/cli/doctor.js.map +1 -0
- package/dist/cli/envfile.d.ts +18 -2
- package/dist/cli/envfile.d.ts.map +1 -1
- package/dist/cli/envfile.js +80 -6
- package/dist/cli/envfile.js.map +1 -1
- package/dist/cli/environments.d.ts +46 -0
- package/dist/cli/environments.d.ts.map +1 -0
- package/dist/cli/environments.js +128 -0
- package/dist/cli/environments.js.map +1 -0
- package/dist/cli/framework.d.ts +16 -1
- package/dist/cli/framework.d.ts.map +1 -1
- package/dist/cli/framework.js +95 -2
- package/dist/cli/framework.js.map +1 -1
- package/dist/cli/index.d.ts +4 -3
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +278 -21
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/init.d.ts +80 -7
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +250 -27
- package/dist/cli/init.js.map +1 -1
- package/dist/cli/mcp.d.ts +18 -0
- package/dist/cli/mcp.d.ts.map +1 -0
- package/dist/cli/mcp.js +107 -0
- package/dist/cli/mcp.js.map +1 -0
- package/dist/cli/migrate.d.ts +70 -0
- package/dist/cli/migrate.d.ts.map +1 -0
- package/dist/cli/migrate.js +254 -0
- package/dist/cli/migrate.js.map +1 -0
- package/dist/cli/project.d.ts +25 -0
- package/dist/cli/project.d.ts.map +1 -0
- package/dist/cli/project.js +44 -0
- package/dist/cli/project.js.map +1 -0
- package/dist/cli/sql.d.ts +59 -0
- package/dist/cli/sql.d.ts.map +1 -0
- package/dist/cli/sql.js +164 -0
- package/dist/cli/sql.js.map +1 -0
- package/dist/cli/token.d.ts +44 -0
- package/dist/cli/token.d.ts.map +1 -0
- package/dist/cli/token.js +96 -0
- package/dist/cli/token.js.map +1 -0
- package/dist/types.gen.d.ts +11 -1
- package/dist/types.gen.d.ts.map +1 -1
- package/package.json +16 -4
package/dist/cli/mcp.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One tool call on the hosted MCP server (`<api>/mcp`, streamable HTTP with
|
|
3
|
+
* JSON answers): open a session, call the tool, close the session. The same
|
|
4
|
+
* tools a coding agent uses, so the terminal follows the same rules.
|
|
5
|
+
*/
|
|
6
|
+
import { InitError } from './init.js';
|
|
7
|
+
const PROTOCOL_VERSION = '2025-06-18';
|
|
8
|
+
const CLIENT_VERSION = '0.3.0';
|
|
9
|
+
/** The MCP endpoint of an API origin (`SCRIBASE_MCP_URL` overrides it). */
|
|
10
|
+
export function mcpEndpoint(apiUrl, env) {
|
|
11
|
+
const explicit = env.SCRIBASE_MCP_URL?.trim();
|
|
12
|
+
return explicit ? explicit.replace(/\/+$/, '') : `${apiUrl.replace(/\/+$/, '')}/mcp`;
|
|
13
|
+
}
|
|
14
|
+
async function send(target, method, session, body) {
|
|
15
|
+
const headers = {
|
|
16
|
+
accept: 'application/json',
|
|
17
|
+
authorization: `Bearer ${target.token}`,
|
|
18
|
+
'mcp-protocol-version': PROTOCOL_VERSION,
|
|
19
|
+
'user-agent': 'scribase-cli',
|
|
20
|
+
};
|
|
21
|
+
if (session)
|
|
22
|
+
headers['mcp-session-id'] = session;
|
|
23
|
+
if (body !== undefined)
|
|
24
|
+
headers['content-type'] = 'application/json';
|
|
25
|
+
try {
|
|
26
|
+
return await target.fetch(target.endpoint, {
|
|
27
|
+
method,
|
|
28
|
+
headers,
|
|
29
|
+
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
|
30
|
+
signal: AbortSignal.timeout(target.timeoutMs),
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
throw new InitError('network_error', `could not reach ${target.endpoint}: ${error.message}`, 'check your connection or SCRIBASE_API_URL');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async function rpcResult(response) {
|
|
38
|
+
const text = await response.text();
|
|
39
|
+
let reply = null;
|
|
40
|
+
try {
|
|
41
|
+
reply = text ? JSON.parse(text) : null;
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
reply = null;
|
|
45
|
+
}
|
|
46
|
+
if (!reply)
|
|
47
|
+
throw new InitError('request_failed', `the hosted MCP server answered HTTP ${response.status} without a JSON-RPC body`);
|
|
48
|
+
if (reply.error)
|
|
49
|
+
throw new InitError('request_failed', reply.error.message ?? 'the MCP server refused the request');
|
|
50
|
+
if (!reply.result)
|
|
51
|
+
throw new InitError('request_failed', `the hosted MCP server answered HTTP ${response.status} without a result`);
|
|
52
|
+
return reply.result;
|
|
53
|
+
}
|
|
54
|
+
function toolPayload(result) {
|
|
55
|
+
const content = Array.isArray(result.content) ? result.content : [];
|
|
56
|
+
const text = typeof content[0]?.text === 'string' ? content[0].text : '';
|
|
57
|
+
if (result.isError === true) {
|
|
58
|
+
const next = text.includes('`destructive` scope')
|
|
59
|
+
? 'run `npx scribase login --scope branches:write --scope keys:read --scope destructive` (approve in the browser), then run this again'
|
|
60
|
+
: undefined;
|
|
61
|
+
throw new InitError('tool_error', text || 'the tool failed without a message', next);
|
|
62
|
+
}
|
|
63
|
+
if (result.structuredContent && typeof result.structuredContent === 'object') {
|
|
64
|
+
return result.structuredContent;
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
return JSON.parse(text);
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
throw new InitError('request_failed', 'the tool answered without a result');
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/** Calls `tool` with `args` and returns its structured payload. */
|
|
74
|
+
export async function callTool(target, tool, args, refusedHint = '') {
|
|
75
|
+
const opened = await send(target, 'POST', null, {
|
|
76
|
+
jsonrpc: '2.0',
|
|
77
|
+
id: 1,
|
|
78
|
+
method: 'initialize',
|
|
79
|
+
params: { protocolVersion: PROTOCOL_VERSION, capabilities: {}, clientInfo: { name: 'scribase-cli', version: CLIENT_VERSION } },
|
|
80
|
+
});
|
|
81
|
+
if (opened.status === 401 || opened.status === 403) {
|
|
82
|
+
throw new InitError('unauthorized', `the hosted MCP server refused this token (HTTP ${opened.status})`, `run \`npx scribase login\`, or \`npx scribase init\` again if the temporary project expired.${refusedHint}`);
|
|
83
|
+
}
|
|
84
|
+
await rpcResult(opened);
|
|
85
|
+
const session = opened.headers.get('mcp-session-id');
|
|
86
|
+
if (!session)
|
|
87
|
+
throw new InitError('request_failed', 'the MCP server opened no session');
|
|
88
|
+
try {
|
|
89
|
+
const notified = await send(target, 'POST', session, { jsonrpc: '2.0', method: 'notifications/initialized' });
|
|
90
|
+
await notified.arrayBuffer();
|
|
91
|
+
if (notified.status < 200 || notified.status >= 300) {
|
|
92
|
+
throw new InitError('request_failed', `the MCP server answered HTTP ${notified.status}`);
|
|
93
|
+
}
|
|
94
|
+
const called = await send(target, 'POST', session, { jsonrpc: '2.0', id: 2, method: 'tools/call', params: { name: tool, arguments: args } });
|
|
95
|
+
return toolPayload(await rpcResult(called));
|
|
96
|
+
}
|
|
97
|
+
finally {
|
|
98
|
+
try {
|
|
99
|
+
const closed = await send(target, 'DELETE', session);
|
|
100
|
+
await closed.arrayBuffer();
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
// The session expires on its own.
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=mcp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.js","sourceRoot":"","sources":["../../src/cli/mcp.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,gBAAgB,GAAG,YAAY,CAAC;AACtC,MAAM,cAAc,GAAG,OAAO,CAAC;AAgB/B,2EAA2E;AAC3E,MAAM,UAAU,WAAW,CAAC,MAAc,EAAE,GAAuC;IACjF,MAAM,QAAQ,GAAG,GAAG,CAAC,gBAAgB,EAAE,IAAI,EAAE,CAAC;IAC9C,OAAO,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC;AACvF,CAAC;AAED,KAAK,UAAU,IAAI,CAAC,MAAiB,EAAE,MAAyB,EAAE,OAAsB,EAAE,IAAc;IACtG,MAAM,OAAO,GAA2B;QACtC,MAAM,EAAE,kBAAkB;QAC1B,aAAa,EAAE,UAAU,MAAM,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AC;QAC3F,CAAC;QACD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;QAC7I,OAAO,WAAW,CAAC,MAAM,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9C,CAAC;YAAS,CAAC;QACT,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;YACrD,MAAM,MAAM,CAAC,WAAW,EAAE,CAAC;QAC7B,CAAC;QAAC,MAAM,CAAC;YACP,kCAAkC;QACpC,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `npx scribase migrate`: real SQL migration files for the project this
|
|
3
|
+
* folder is connected to (after `init`), tracked on disk in `supabase/
|
|
4
|
+
* migrations/*.sql` and run through the control plane's own plan/lint/apply
|
|
5
|
+
* route — the same route the generated SDK's `client.migrations` resource
|
|
6
|
+
* wraps (`POST .../migrations`), finally wired to this binary.
|
|
7
|
+
*
|
|
8
|
+
* npx scribase migrate new <name> scaffold a timestamped migration file
|
|
9
|
+
* npx scribase migrate plan, lint and apply every migration
|
|
10
|
+
* not yet in this environment's ledger
|
|
11
|
+
* npx scribase migrate --dry-run plan and lint only; nothing runs
|
|
12
|
+
*
|
|
13
|
+
* This replaces the old next-step dead end ("SQL migrations ... with
|
|
14
|
+
* `scribase db push` from the full CLI") with something that works from this
|
|
15
|
+
* same npm package: every local `.sql` file under `supabase/migrations/` is
|
|
16
|
+
* sent, oldest first, every time; the server skips versions already applied
|
|
17
|
+
* (and refuses if an applied file's SQL changed underneath it — checksum
|
|
18
|
+
* drift), so this is always safe to re-run. A table in the `public` schema
|
|
19
|
+
* with no RLS policy is blocked before anything executes (`missing_rls`),
|
|
20
|
+
* same as it would be for a hand-written `scribase sql` script.
|
|
21
|
+
*/
|
|
22
|
+
import type { MigrationLintFinding, RunMigrationsResult } from '../types.gen.js';
|
|
23
|
+
/** Where migration files live, relative to the project root. */
|
|
24
|
+
export declare const MIGRATIONS_DIR = "supabase/migrations";
|
|
25
|
+
export interface MigrateOptions {
|
|
26
|
+
action: 'new' | 'run';
|
|
27
|
+
/** `new` only: the name given on the command line. */
|
|
28
|
+
name?: string;
|
|
29
|
+
dryRun: boolean;
|
|
30
|
+
json: boolean;
|
|
31
|
+
}
|
|
32
|
+
export interface MigrateIo {
|
|
33
|
+
cwd: string;
|
|
34
|
+
env: Record<string, string | undefined>;
|
|
35
|
+
fetch: typeof fetch;
|
|
36
|
+
readFile: (path: string) => string | null;
|
|
37
|
+
writeFile: (path: string, contents: string) => void;
|
|
38
|
+
/** Filenames directly inside {@link MIGRATIONS_DIR}; empty if it does not exist. */
|
|
39
|
+
listMigrationFiles: () => string[];
|
|
40
|
+
credentials: () => {
|
|
41
|
+
apiUrl?: string;
|
|
42
|
+
token?: string;
|
|
43
|
+
};
|
|
44
|
+
now: () => Date;
|
|
45
|
+
}
|
|
46
|
+
export type MigrateResult = {
|
|
47
|
+
ok: true;
|
|
48
|
+
action: 'new';
|
|
49
|
+
version: string;
|
|
50
|
+
name: string;
|
|
51
|
+
path: string;
|
|
52
|
+
} | {
|
|
53
|
+
ok: true;
|
|
54
|
+
action: 'run';
|
|
55
|
+
dryRun: boolean;
|
|
56
|
+
/** How many local `.sql` files were sent (0 when the folder has none yet). */
|
|
57
|
+
files: number;
|
|
58
|
+
plan: RunMigrationsResult['plan'];
|
|
59
|
+
lintFindings: MigrationLintFinding[];
|
|
60
|
+
applied: number[];
|
|
61
|
+
/** True when a `BLOCK` finding stopped every pending migration from applying. */
|
|
62
|
+
blocked: boolean;
|
|
63
|
+
};
|
|
64
|
+
/** Parses `migrate` arguments: `new <name>`, or the default run, plus `--dry-run`/`--json`. */
|
|
65
|
+
export declare function parseMigrateArgs(argv: string[]): MigrateOptions;
|
|
66
|
+
/** Runs `new` (pure filesystem) or `run` (plan/lint/apply against the control plane). */
|
|
67
|
+
export declare function runMigrate(options: MigrateOptions, io: MigrateIo): Promise<MigrateResult>;
|
|
68
|
+
/** The human-readable output of {@link runMigrate}. */
|
|
69
|
+
export declare function formatMigrate(result: MigrateResult): string;
|
|
70
|
+
//# sourceMappingURL=migrate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../../src/cli/migrate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAMH,OAAO,KAAK,EAAkB,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAKjG,gEAAgE;AAChE,eAAO,MAAM,cAAc,wBAAwB,CAAC;AAMpD,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,KAAK,GAAG,KAAK,CAAC;IACtB,sDAAsD;IACtD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,OAAO,CAAC;IAChB,IAAI,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IACxC,KAAK,EAAE,OAAO,KAAK,CAAC;IACpB,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;IAC1C,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IACpD,oFAAoF;IACpF,kBAAkB,EAAE,MAAM,MAAM,EAAE,CAAC;IACnC,WAAW,EAAE,MAAM;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACvD,GAAG,EAAE,MAAM,IAAI,CAAC;CACjB;AAED,MAAM,MAAM,aAAa,GACrB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACxE;IACE,EAAE,EAAE,IAAI,CAAC;IACT,MAAM,EAAE,KAAK,CAAC;IACd,MAAM,EAAE,OAAO,CAAC;IAChB,8EAA8E;IAC9E,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,mBAAmB,CAAC,MAAM,CAAC,CAAC;IAClC,YAAY,EAAE,oBAAoB,EAAE,CAAC;IACrC,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,iFAAiF;IACjF,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AASN,+FAA+F;AAC/F,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,cAAc,CAgB/D;AAwKD,yFAAyF;AACzF,wBAAsB,UAAU,CAAC,OAAO,EAAE,cAAc,EAAE,EAAE,EAAE,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,CAG/F;AAED,uDAAuD;AACvD,wBAAgB,aAAa,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,CA+B3D"}
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `npx scribase migrate`: real SQL migration files for the project this
|
|
3
|
+
* folder is connected to (after `init`), tracked on disk in `supabase/
|
|
4
|
+
* migrations/*.sql` and run through the control plane's own plan/lint/apply
|
|
5
|
+
* route — the same route the generated SDK's `client.migrations` resource
|
|
6
|
+
* wraps (`POST .../migrations`), finally wired to this binary.
|
|
7
|
+
*
|
|
8
|
+
* npx scribase migrate new <name> scaffold a timestamped migration file
|
|
9
|
+
* npx scribase migrate plan, lint and apply every migration
|
|
10
|
+
* not yet in this environment's ledger
|
|
11
|
+
* npx scribase migrate --dry-run plan and lint only; nothing runs
|
|
12
|
+
*
|
|
13
|
+
* This replaces the old next-step dead end ("SQL migrations ... with
|
|
14
|
+
* `scribase db push` from the full CLI") with something that works from this
|
|
15
|
+
* same npm package: every local `.sql` file under `supabase/migrations/` is
|
|
16
|
+
* sent, oldest first, every time; the server skips versions already applied
|
|
17
|
+
* (and refuses if an applied file's SQL changed underneath it — checksum
|
|
18
|
+
* drift), so this is always safe to re-run. A table in the `public` schema
|
|
19
|
+
* with no RLS policy is blocked before anything executes (`missing_rls`),
|
|
20
|
+
* same as it would be for a hand-written `scribase sql` script.
|
|
21
|
+
*/
|
|
22
|
+
import { refusedHint, resolveToken } from './token.js';
|
|
23
|
+
import { readEnvValue } from './envfile.js';
|
|
24
|
+
import { InitError, STATE_FILE } from './init.js';
|
|
25
|
+
const DEFAULT_API_URL = 'https://api.scribase.com';
|
|
26
|
+
/** Env files init may have written, most specific first. */
|
|
27
|
+
const ENV_FILES = ['.env.local', '.env'];
|
|
28
|
+
/** Where migration files live, relative to the project root. */
|
|
29
|
+
export const MIGRATIONS_DIR = 'supabase/migrations';
|
|
30
|
+
/** `<version>_<name>.sql`: version sorts and parses as the server's i64. */
|
|
31
|
+
const FILE_PATTERN = /^(\d+)_(.+)\.sql$/;
|
|
32
|
+
/** Splits a file into its up and (optional) down SQL. */
|
|
33
|
+
const DOWN_MARKER = /^[ \t]*--[ \t]*down[ \t]*$/im;
|
|
34
|
+
/** Parses `migrate` arguments: `new <name>`, or the default run, plus `--dry-run`/`--json`. */
|
|
35
|
+
export function parseMigrateArgs(argv) {
|
|
36
|
+
const flags = new Set(argv.filter((arg) => arg.startsWith('--')));
|
|
37
|
+
const positional = argv.filter((arg) => !arg.startsWith('--'));
|
|
38
|
+
const unknown = [...flags].find((flag) => flag !== '--dry-run' && flag !== '--json');
|
|
39
|
+
if (unknown)
|
|
40
|
+
throw new InitError('invalid_argument', `unknown option ${unknown}`, 'run `npx scribase migrate --help`');
|
|
41
|
+
const json = flags.has('--json');
|
|
42
|
+
const dryRun = flags.has('--dry-run');
|
|
43
|
+
if (positional[0] === 'new') {
|
|
44
|
+
const name = positional[1];
|
|
45
|
+
if (!name)
|
|
46
|
+
throw new InitError('invalid_argument', 'no migration name given', 'run `npx scribase migrate new <name>`, e.g. `npx scribase migrate new add_notes`');
|
|
47
|
+
return { action: 'new', name, dryRun: false, json };
|
|
48
|
+
}
|
|
49
|
+
if (positional.length > 0 && positional[0] !== 'up') {
|
|
50
|
+
throw new InitError('invalid_argument', `unknown argument ${positional[0]}`, 'run `npx scribase migrate --help`');
|
|
51
|
+
}
|
|
52
|
+
return { action: 'run', dryRun, json };
|
|
53
|
+
}
|
|
54
|
+
/** A filename-safe, lowercase slug; never empty. */
|
|
55
|
+
function slugify(name) {
|
|
56
|
+
const slug = name
|
|
57
|
+
.trim()
|
|
58
|
+
.toLowerCase()
|
|
59
|
+
.replace(/[^a-z0-9]+/g, '_')
|
|
60
|
+
.replace(/^_+|_+$/g, '');
|
|
61
|
+
return slug || 'migration';
|
|
62
|
+
}
|
|
63
|
+
/** `YYYYMMDDHHMMSS` in UTC: sorts lexically, parses as the server's i64 version. */
|
|
64
|
+
function versionFor(now) {
|
|
65
|
+
const pad = (value, length = 2) => String(value).padStart(length, '0');
|
|
66
|
+
return (`${now.getUTCFullYear()}${pad(now.getUTCMonth() + 1)}${pad(now.getUTCDate())}` +
|
|
67
|
+
`${pad(now.getUTCHours())}${pad(now.getUTCMinutes())}${pad(now.getUTCSeconds())}`);
|
|
68
|
+
}
|
|
69
|
+
function join(root, relative) {
|
|
70
|
+
return `${root.replace(/\/+$/, '')}/${relative}`;
|
|
71
|
+
}
|
|
72
|
+
/** The scaffold `npx scribase migrate new <name>` writes. Both the up and down
|
|
73
|
+
* examples are commented out, so an unedited file applies as a real, valid,
|
|
74
|
+
* no-op migration (it reserves the version; it changes nothing) rather than
|
|
75
|
+
* creating a table the caller never asked for. */
|
|
76
|
+
function scaffold(name, slug) {
|
|
77
|
+
return [
|
|
78
|
+
`-- ${name}`,
|
|
79
|
+
'--',
|
|
80
|
+
'-- Edit the SQL below, then run `npx scribase migrate` (or `--dry-run` to',
|
|
81
|
+
'-- preview first). Every local file in this folder is sent in version',
|
|
82
|
+
'-- order every time; already-applied ones are skipped, so re-running is',
|
|
83
|
+
'-- always safe.',
|
|
84
|
+
'--',
|
|
85
|
+
'-- Scribase blocks a migration before anything runs if it leaves a',
|
|
86
|
+
'-- `public`-schema table with no RLS policy (rule `missing_rls`) -- an',
|
|
87
|
+
'-- exposed table with RLS off is readable and writable by anyone through',
|
|
88
|
+
'-- the REST API. Uncomment and adapt this example, or write your own:',
|
|
89
|
+
'--',
|
|
90
|
+
`-- create table public.${slug} (`,
|
|
91
|
+
'-- id uuid primary key default gen_random_uuid(),',
|
|
92
|
+
'-- created_at timestamptz not null default now()',
|
|
93
|
+
'-- );',
|
|
94
|
+
'--',
|
|
95
|
+
`-- alter table public.${slug} enable row level security;`,
|
|
96
|
+
'--',
|
|
97
|
+
`-- create policy "${slug}_select_own" on public.${slug}`,
|
|
98
|
+
'-- for select',
|
|
99
|
+
'-- using (auth.uid() is not null);',
|
|
100
|
+
'',
|
|
101
|
+
'-- down',
|
|
102
|
+
'-- SQL here undoes the migration above. Optional: only a future rollback',
|
|
103
|
+
'-- command reads it; `npx scribase migrate` never runs it. Example for the',
|
|
104
|
+
'-- table above:',
|
|
105
|
+
'--',
|
|
106
|
+
`-- drop table if exists public.${slug};`,
|
|
107
|
+
'',
|
|
108
|
+
].join('\n');
|
|
109
|
+
}
|
|
110
|
+
/** `new`: writes the scaffold and returns where it went. Pure filesystem, no network. */
|
|
111
|
+
function runNew(name, io) {
|
|
112
|
+
const slug = slugify(name);
|
|
113
|
+
const version = versionFor(io.now());
|
|
114
|
+
const filename = `${version}_${slug}.sql`;
|
|
115
|
+
const path = join(join(io.cwd, MIGRATIONS_DIR), filename);
|
|
116
|
+
io.writeFile(path, scaffold(name, slug));
|
|
117
|
+
return { ok: true, action: 'new', version, name: slug, path };
|
|
118
|
+
}
|
|
119
|
+
function readProject(io) {
|
|
120
|
+
const text = io.readFile(join(io.cwd, STATE_FILE));
|
|
121
|
+
let state = null;
|
|
122
|
+
try {
|
|
123
|
+
state = text ? JSON.parse(text) : null;
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
state = null;
|
|
127
|
+
}
|
|
128
|
+
if (!state?.organization_id || !state.project_id || !state.environment_id) {
|
|
129
|
+
throw new InitError('not_initialized', 'this folder is not connected to a Scribase project', 'run `npx scribase init` here first');
|
|
130
|
+
}
|
|
131
|
+
return state;
|
|
132
|
+
}
|
|
133
|
+
function failure(status, body, hint = '') {
|
|
134
|
+
const value = (body ?? {});
|
|
135
|
+
const code = typeof value.code === 'string' ? value.code : 'request_failed';
|
|
136
|
+
const detail = typeof value.detail === 'string' ? value.detail : 'the request failed';
|
|
137
|
+
const next = status === 401 || status === 403
|
|
138
|
+
? 'run `npx scribase login`, or `npx scribase init` again if the temporary project expired'
|
|
139
|
+
: undefined;
|
|
140
|
+
return new InitError(code, `${detail} (HTTP ${status})`, next && hint ? `${next}.${hint}` : next);
|
|
141
|
+
}
|
|
142
|
+
/** Reads every `<version>_<name>.sql` file, oldest version first, splitting each on the `-- down` marker. */
|
|
143
|
+
function readLocalMigrations(io) {
|
|
144
|
+
const files = io.listMigrationFiles().filter((name) => FILE_PATTERN.test(name));
|
|
145
|
+
const parsed = files
|
|
146
|
+
.map((filename) => {
|
|
147
|
+
const match = FILE_PATTERN.exec(filename);
|
|
148
|
+
const version = match?.[1];
|
|
149
|
+
const name = match?.[2];
|
|
150
|
+
if (version === undefined || name === undefined)
|
|
151
|
+
return null;
|
|
152
|
+
const contents = io.readFile(join(join(io.cwd, MIGRATIONS_DIR), filename)) ?? '';
|
|
153
|
+
const splitAt = contents.search(DOWN_MARKER);
|
|
154
|
+
const up = (splitAt === -1 ? contents : contents.slice(0, splitAt)).trim();
|
|
155
|
+
const downText = splitAt === -1 ? '' : contents.slice(splitAt).replace(DOWN_MARKER, '').trim();
|
|
156
|
+
// exactOptionalPropertyTypes: omit `down` entirely rather than setting it to undefined.
|
|
157
|
+
return { version, name, up, ...(downText.length > 0 ? { down: downText } : {}) };
|
|
158
|
+
})
|
|
159
|
+
.filter((migration) => migration !== null);
|
|
160
|
+
return parsed.sort((left, right) => (BigInt(left.version) < BigInt(right.version) ? -1 : BigInt(left.version) > BigInt(right.version) ? 1 : 0));
|
|
161
|
+
}
|
|
162
|
+
/** `run`: sends every local migration file to this folder's project; the server plans, lints and (unless `--dry-run`) applies. */
|
|
163
|
+
async function runRun(options, io) {
|
|
164
|
+
const migrations = readLocalMigrations(io);
|
|
165
|
+
if (migrations.length === 0) {
|
|
166
|
+
return { ok: true, action: 'run', dryRun: options.dryRun, files: 0, plan: { steps: [] }, lintFindings: [], applied: [], blocked: false };
|
|
167
|
+
}
|
|
168
|
+
const project = readProject(io);
|
|
169
|
+
const resolved = resolveToken(io);
|
|
170
|
+
const token = resolved?.token;
|
|
171
|
+
if (!token) {
|
|
172
|
+
throw new InitError('not_signed_in', 'no Scribase token for this folder', 'run `npx scribase login`, or `npx scribase init` here');
|
|
173
|
+
}
|
|
174
|
+
const apiUrl = (io.env.SCRIBASE_API_URL ?? project.api_url ?? io.credentials().apiUrl ?? DEFAULT_API_URL).replace(/\/+$/, '');
|
|
175
|
+
const path = `/v1/organizations/${encodeURIComponent(project.organization_id)}` +
|
|
176
|
+
`/projects/${encodeURIComponent(project.project_id)}` +
|
|
177
|
+
`/environments/${encodeURIComponent(project.environment_id)}/migrations`;
|
|
178
|
+
let response;
|
|
179
|
+
try {
|
|
180
|
+
response = await io.fetch(`${apiUrl}${path}`, {
|
|
181
|
+
method: 'POST',
|
|
182
|
+
headers: {
|
|
183
|
+
accept: 'application/json',
|
|
184
|
+
'content-type': 'application/json',
|
|
185
|
+
'user-agent': 'scribase-migrate',
|
|
186
|
+
authorization: `Bearer ${token}`,
|
|
187
|
+
},
|
|
188
|
+
body: JSON.stringify({ migrations, apply: !options.dryRun }),
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
throw new InitError('network_error', `could not reach ${apiUrl}: ${error.message}`, 'check your connection or SCRIBASE_API_URL');
|
|
193
|
+
}
|
|
194
|
+
const text = await response.text();
|
|
195
|
+
let body = null;
|
|
196
|
+
try {
|
|
197
|
+
body = text ? JSON.parse(text) : null;
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
body = { detail: text.slice(0, 200) };
|
|
201
|
+
}
|
|
202
|
+
if (response.status !== 200)
|
|
203
|
+
throw failure(response.status, body, refusedHint(resolved, io.env));
|
|
204
|
+
const value = (body ?? {});
|
|
205
|
+
const plan = value.plan && Array.isArray(value.plan.steps) ? value.plan : { steps: [] };
|
|
206
|
+
const lintFindings = Array.isArray(value.lintFindings) ? value.lintFindings : [];
|
|
207
|
+
const applied = Array.isArray(value.applied) ? value.applied : [];
|
|
208
|
+
const blocking = lintFindings.some((finding) => finding.severity === 'BLOCK');
|
|
209
|
+
const blocked = !options.dryRun && plan.steps.length > 0 && applied.length === 0 && blocking;
|
|
210
|
+
return { ok: true, action: 'run', dryRun: options.dryRun, files: migrations.length, plan, lintFindings, applied, blocked };
|
|
211
|
+
}
|
|
212
|
+
/** Runs `new` (pure filesystem) or `run` (plan/lint/apply against the control plane). */
|
|
213
|
+
export async function runMigrate(options, io) {
|
|
214
|
+
if (options.action === 'new')
|
|
215
|
+
return runNew(options.name, io);
|
|
216
|
+
return runRun(options, io);
|
|
217
|
+
}
|
|
218
|
+
/** The human-readable output of {@link runMigrate}. */
|
|
219
|
+
export function formatMigrate(result) {
|
|
220
|
+
if (result.action === 'new') {
|
|
221
|
+
return [`Created ${MIGRATIONS_DIR}/${result.version}_${result.name}.sql`, 'Edit it, then run `npx scribase migrate` (or `--dry-run` to preview first).', ''].join('\n');
|
|
222
|
+
}
|
|
223
|
+
if (result.files === 0) {
|
|
224
|
+
return [`No migration files in ${MIGRATIONS_DIR}/. Run \`npx scribase migrate new <name>\` to create one.`, ''].join('\n');
|
|
225
|
+
}
|
|
226
|
+
const lines = [];
|
|
227
|
+
const direction = result.dryRun ? 'would run' : 'ran';
|
|
228
|
+
const pending = result.plan.steps.filter((step) => step.direction === 'up');
|
|
229
|
+
if (pending.length === 0) {
|
|
230
|
+
lines.push(`Up to date: all ${result.files} local migration(s) are already applied.`);
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
lines.push(`${pending.length} migration(s) ${result.dryRun ? 'pending' : result.blocked ? 'blocked' : direction}:`);
|
|
234
|
+
for (const step of pending) {
|
|
235
|
+
const state = result.dryRun ? 'planned' : result.applied.includes(step.version) ? 'applied' : 'not applied';
|
|
236
|
+
lines.push(` ${step.version}_${step.name} (${state})`);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
for (const finding of result.lintFindings) {
|
|
240
|
+
lines.push(` [${finding.severity}] ${finding.rule}: ${finding.message} (${finding.subject}:${finding.line})`);
|
|
241
|
+
}
|
|
242
|
+
if (result.blocked) {
|
|
243
|
+
lines.push('Nothing applied: a BLOCK finding above stops every pending migration until it is fixed.');
|
|
244
|
+
}
|
|
245
|
+
else if (result.dryRun && pending.length > 0) {
|
|
246
|
+
lines.push('Dry run: nothing applied. Run the same command without --dry-run to apply it.');
|
|
247
|
+
}
|
|
248
|
+
else if (pending.length > 0 && !result.blocked) {
|
|
249
|
+
lines.push('The REST API reloads its schema right after; if a query still says the table is not found, retry in a few seconds.');
|
|
250
|
+
}
|
|
251
|
+
lines.push('');
|
|
252
|
+
return lines.join('\n');
|
|
253
|
+
}
|
|
254
|
+
//# sourceMappingURL=migrate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate.js","sourceRoot":"","sources":["../../src/cli/migrate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE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FAAyF,CAAC,CAAC;IACxG,CAAC;SAAM,IAAI,MAAM,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC/C,KAAK,CAAC,IAAI,CAAC,+EAA+E,CAAC,CAAC;IAC9F,CAAC;SAAM,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACjD,KAAK,CAAC,IAAI,CAAC,oHAAoH,CAAC,CAAC;IACnI,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACf,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The project this folder is connected to (`.scribase/project.json`, written
|
|
3
|
+
* by `npx scribase init`), the API origin and the token for it. Shared by the
|
|
4
|
+
* folder-scoped commands `env` and `branch`.
|
|
5
|
+
*/
|
|
6
|
+
import type { ResolvedToken, TokenIo } from './token.js';
|
|
7
|
+
export declare const DEFAULT_API_URL = "https://api.scribase.com";
|
|
8
|
+
export interface ProjectState {
|
|
9
|
+
organization_id: string;
|
|
10
|
+
project_id: string;
|
|
11
|
+
environment_id: string;
|
|
12
|
+
api_url?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface ProjectIo extends TokenIo {
|
|
15
|
+
fetch: typeof fetch;
|
|
16
|
+
}
|
|
17
|
+
export declare function joinPath(root: string, relative: string): string;
|
|
18
|
+
/** The folder's project, or `null` when `init` has not run here. */
|
|
19
|
+
export declare function readProjectState(io: Pick<ProjectIo, 'cwd' | 'readFile'>): ProjectState | null;
|
|
20
|
+
export declare function requireProjectState(io: Pick<ProjectIo, 'cwd' | 'readFile'>): ProjectState;
|
|
21
|
+
export declare function apiUrlFor(io: ProjectIo, project?: ProjectState | null): string;
|
|
22
|
+
export declare function requireToken(io: ProjectIo): ResolvedToken;
|
|
23
|
+
/** Ids are lowercase letters, digits, dashes and underscores. */
|
|
24
|
+
export declare function isId(value: string): boolean;
|
|
25
|
+
//# sourceMappingURL=project.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../src/cli/project.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAEzD,eAAO,MAAM,eAAe,6BAA6B,CAAC;AAE1D,MAAM,WAAW,YAAY;IAC3B,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,SAAU,SAAQ,OAAO;IACxC,KAAK,EAAE,OAAO,KAAK,CAAC;CACrB;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE/D;AAED,oEAAoE;AACpE,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,IAAI,CAAC,SAAS,EAAE,KAAK,GAAG,UAAU,CAAC,GAAG,YAAY,GAAG,IAAI,CAQ7F;AAED,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,IAAI,CAAC,SAAS,EAAE,KAAK,GAAG,UAAU,CAAC,GAAG,YAAY,CAMzF;AAED,wBAAgB,SAAS,CAAC,EAAE,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,IAAI,GAAG,MAAM,CAE9E;AAED,wBAAgB,YAAY,CAAC,EAAE,EAAE,SAAS,GAAG,aAAa,CAMzD;AAED,iEAAiE;AACjE,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE3C"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The project this folder is connected to (`.scribase/project.json`, written
|
|
3
|
+
* by `npx scribase init`), the API origin and the token for it. Shared by the
|
|
4
|
+
* folder-scoped commands `env` and `branch`.
|
|
5
|
+
*/
|
|
6
|
+
import { InitError, STATE_FILE } from './init.js';
|
|
7
|
+
import { resolveToken } from './token.js';
|
|
8
|
+
export const DEFAULT_API_URL = 'https://api.scribase.com';
|
|
9
|
+
export function joinPath(root, relative) {
|
|
10
|
+
return `${root.replace(/\/+$/, '')}/${relative}`;
|
|
11
|
+
}
|
|
12
|
+
/** The folder's project, or `null` when `init` has not run here. */
|
|
13
|
+
export function readProjectState(io) {
|
|
14
|
+
const text = io.readFile(joinPath(io.cwd, STATE_FILE));
|
|
15
|
+
try {
|
|
16
|
+
const state = text ? JSON.parse(text) : null;
|
|
17
|
+
return state?.organization_id && state.project_id && state.environment_id ? state : null;
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export function requireProjectState(io) {
|
|
24
|
+
const state = readProjectState(io);
|
|
25
|
+
if (!state) {
|
|
26
|
+
throw new InitError('not_initialized', 'this folder is not connected to a Scribase project', 'run `npx scribase init` here first');
|
|
27
|
+
}
|
|
28
|
+
return state;
|
|
29
|
+
}
|
|
30
|
+
export function apiUrlFor(io, project) {
|
|
31
|
+
return (io.env.SCRIBASE_API_URL ?? project?.api_url ?? io.credentials().apiUrl ?? DEFAULT_API_URL).replace(/\/+$/, '');
|
|
32
|
+
}
|
|
33
|
+
export function requireToken(io) {
|
|
34
|
+
const resolved = resolveToken(io);
|
|
35
|
+
if (!resolved) {
|
|
36
|
+
throw new InitError('not_signed_in', 'no Scribase token for this folder', 'run `npx scribase login`, or `npx scribase init` here');
|
|
37
|
+
}
|
|
38
|
+
return resolved;
|
|
39
|
+
}
|
|
40
|
+
/** Ids are lowercase letters, digits, dashes and underscores. */
|
|
41
|
+
export function isId(value) {
|
|
42
|
+
return /^[a-z0-9_][a-z0-9_-]{0,62}$/.test(value);
|
|
43
|
+
}
|
|
44
|
+
//#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AC,EAAa,EAAE,OAA6B;IACpE,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,gBAAgB,IAAI,OAAO,EAAE,OAAO,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,MAAM,IAAI,eAAe,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AACzH,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,EAAa;IACxC,MAAM,QAAQ,GAAG,YAAY,CAAC,EAAE,CAAC,CAAC;IAClC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,SAAS,CAAC,eAAe,EAAE,mCAAmC,EAAE,uDAAuD,CAAC,CAAC;IACrI,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,iEAAiE;AACjE,MAAM,UAAU,IAAI,CAAC,KAAa;IAChC,OAAO,6BAA6B,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACnD,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `npx scribase sql "<script>"`: runs SQL against the project this folder is
|
|
3
|
+
* connected to (the one `npx scribase init` wrote to `.scribase/project.json`).
|
|
4
|
+
*
|
|
5
|
+
* It exists so the first thing a new user tries after init works on an empty
|
|
6
|
+
* database: create a table here, then query it from the app. The script runs
|
|
7
|
+
* in one transaction on the control plane (`POST .../database/execute`), which
|
|
8
|
+
* also makes the REST API see new tables at once. Destructive statements
|
|
9
|
+
* (DROP, TRUNCATE, DELETE without WHERE, ...) only run with `--confirm`.
|
|
10
|
+
*
|
|
11
|
+
* The token comes from SCRIBASE_ACCESS_TOKEN, else the env file init wrote (a
|
|
12
|
+
* temporary project's own agent token), else `scribase login`. It is never
|
|
13
|
+
* printed.
|
|
14
|
+
*/
|
|
15
|
+
export interface SqlOptions {
|
|
16
|
+
query: string;
|
|
17
|
+
json: boolean;
|
|
18
|
+
confirm: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface SqlIo {
|
|
21
|
+
cwd: string;
|
|
22
|
+
env: Record<string, string | undefined>;
|
|
23
|
+
fetch: typeof fetch;
|
|
24
|
+
readFile: (path: string) => string | null;
|
|
25
|
+
credentials: () => {
|
|
26
|
+
apiUrl?: string;
|
|
27
|
+
token?: string;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export interface SqlStatementResult {
|
|
31
|
+
index: number;
|
|
32
|
+
command: string;
|
|
33
|
+
statement: string;
|
|
34
|
+
kind: string;
|
|
35
|
+
affected_rows?: number | null;
|
|
36
|
+
row_count?: number;
|
|
37
|
+
rows?: Record<string, unknown>[];
|
|
38
|
+
}
|
|
39
|
+
export type SqlResult = {
|
|
40
|
+
ok: true;
|
|
41
|
+
status: 'committed';
|
|
42
|
+
statements: SqlStatementResult[];
|
|
43
|
+
duration_ms: number;
|
|
44
|
+
} | {
|
|
45
|
+
ok: true;
|
|
46
|
+
status: 'confirmation_required';
|
|
47
|
+
destructive: {
|
|
48
|
+
command: string;
|
|
49
|
+
statement: string;
|
|
50
|
+
reason: string;
|
|
51
|
+
}[];
|
|
52
|
+
};
|
|
53
|
+
/** Parses `sql` arguments: one SQL script (or `--file <path>`), `--json`, `--confirm`. */
|
|
54
|
+
export declare function parseSqlArgs(argv: string[], readFile: (path: string) => string | null): SqlOptions;
|
|
55
|
+
/** Runs the script against this folder's project and returns what happened. */
|
|
56
|
+
export declare function runSql(options: SqlOptions, io: SqlIo): Promise<SqlResult>;
|
|
57
|
+
/** The human-readable output of {@link runSql}. */
|
|
58
|
+
export declare function formatSql(result: SqlResult): string;
|
|
59
|
+
//# sourceMappingURL=sql.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sql.d.ts","sourceRoot":"","sources":["../../src/cli/sql.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAeH,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE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