@parall/cli 1.67.0 → 1.68.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/dist/commands/agents.d.ts +2 -0
- package/dist/commands/agents.d.ts.map +1 -1
- package/dist/commands/apps-db.d.ts +8 -0
- package/dist/commands/apps-db.d.ts.map +1 -0
- package/dist/commands/apps-db.js +17 -0
- package/dist/commands/apps-publish.d.ts +23 -0
- package/dist/commands/apps-publish.d.ts.map +1 -0
- package/dist/commands/apps-publish.js +288 -0
- package/dist/commands/apps-scaffold.d.ts +9 -0
- package/dist/commands/apps-scaffold.d.ts.map +1 -0
- package/dist/commands/apps-scaffold.js +379 -0
- package/dist/commands/apps.d.ts +9 -5
- package/dist/commands/apps.d.ts.map +1 -1
- package/dist/commands/apps.js +31 -32
- package/dist/commands/clip.d.ts.map +1 -1
- package/dist/commands/clip.js +55 -10
- package/dist/commands/db-plane.d.ts +41 -0
- package/dist/commands/db-plane.d.ts.map +1 -0
- package/dist/commands/db-plane.js +237 -0
- package/dist/commands/dbs.d.ts +16 -0
- package/dist/commands/dbs.d.ts.map +1 -0
- package/dist/commands/dbs.js +147 -0
- package/dist/commands/triggers.d.ts +14 -1
- package/dist/commands/triggers.d.ts.map +1 -1
- package/dist/commands/triggers.js +64 -0
- package/dist/commands/watch.d.ts +1 -1
- package/dist/commands/watch.d.ts.map +1 -1
- package/dist/commands/watch.js +21 -11
- package/dist/commands/wiki-changesets.d.ts +3 -0
- package/dist/commands/wiki-changesets.d.ts.map +1 -0
- package/dist/commands/wiki-changesets.js +176 -0
- package/dist/commands/wiki.d.ts.map +1 -1
- package/dist/commands/wiki.js +4 -173
- package/dist/index.js +2 -0
- package/dist/lib/wiki-tool-definition.d.ts +23 -0
- package/dist/lib/wiki-tool-definition.d.ts.map +1 -0
- package/dist/lib/wiki-tool-definition.js +17 -0
- package/dist/lib/wiki-tools.d.ts +2 -24
- package/dist/lib/wiki-tools.d.ts.map +1 -1
- package/dist/lib/wiki-tools.js +11 -16
- package/package.json +6 -4
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { MiniAppSQLParam } from '@parall/sdk';
|
|
2
|
+
import type { Command } from 'commander';
|
|
3
|
+
import { resolveCredentials } from '../lib/client.js';
|
|
4
|
+
type Ctx = ReturnType<typeof resolveCredentials>;
|
|
5
|
+
/** What a data-plane command runs against: a Database directly, or an app
|
|
6
|
+
* (the alias: the app's Database, with the app recorded on the log row). */
|
|
7
|
+
export interface DataPlaneTarget {
|
|
8
|
+
kind: 'app' | 'db';
|
|
9
|
+
id: string;
|
|
10
|
+
}
|
|
11
|
+
/** How a command group names its target. `parall db …` takes `--db` (id or
|
|
12
|
+
* name, unique in the org), `parall app db …` takes `--app`. */
|
|
13
|
+
export interface DataPlaneBinding {
|
|
14
|
+
flag: string;
|
|
15
|
+
flagHelp: string;
|
|
16
|
+
/** Extra options every command of the group accepts (e.g. the deprecated
|
|
17
|
+
* --project). */
|
|
18
|
+
extraOptions?: Array<{
|
|
19
|
+
flag: string;
|
|
20
|
+
help: string;
|
|
21
|
+
}>;
|
|
22
|
+
resolve(ctx: Ctx, opts: Record<string, string | undefined>): Promise<DataPlaneTarget>;
|
|
23
|
+
}
|
|
24
|
+
/** The raw-SQL data plane (design §5, §7.2, §8) — a construction surface
|
|
25
|
+
* for the authors of the apps attached to the Database and for org
|
|
26
|
+
* owners/admins, not the member product surface (that will be app-defined
|
|
27
|
+
* actions, designed separately). A standalone Database (no apps) is
|
|
28
|
+
* owners/admins-only. query runs one read-only statement as the Database's
|
|
29
|
+
* read role; exec runs one or more statements in a single transaction as
|
|
30
|
+
* the write role, or as the owner role with a snapshot first when the SQL
|
|
31
|
+
* is a schema change. Destructive DDL and restores issued by an agent are
|
|
32
|
+
* refused with DB_DDL_APPROVAL_REQUIRED while the Database requires
|
|
33
|
+
* org owner/admin approval. */
|
|
34
|
+
export declare function registerDataPlaneCommands(group: Command, binding: DataPlaneBinding): void;
|
|
35
|
+
/** Each --param is a JSON value when it parses as one, else the bare text.
|
|
36
|
+
* The server binds every value as text and lets PostgreSQL parse it against
|
|
37
|
+
* the parameter's real type, so `--param 42` and `--param '"42"'` both work
|
|
38
|
+
* for an integer column. */
|
|
39
|
+
export declare function parseParams(raw: string[] | undefined): MiniAppSQLParam[] | undefined;
|
|
40
|
+
export {};
|
|
41
|
+
//# sourceMappingURL=db-plane.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db-plane.d.ts","sourceRoot":"","sources":["../../src/commands/db-plane.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAUV,eAAe,EAEhB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAItD,KAAK,GAAG,GAAG,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAEjD;4EAC4E;AAC5E,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,KAAK,GAAG,IAAI,CAAC;IACnB,EAAE,EAAE,MAAM,CAAC;CACZ;AAED;gEACgE;AAChE,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB;qBACiB;IACjB,YAAY,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACrD,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;CACvF;AAED;;;;;;;;;+BAS+B;AAC/B,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,gBAAgB,QAyJlF;AAgED;;;4BAG4B;AAC5B,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,SAAS,GAAG,eAAe,EAAE,GAAG,SAAS,CASpF"}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { promises as fs } from 'node:fs';
|
|
2
|
+
import { resolveCredentials } from '../lib/client.js';
|
|
3
|
+
import { printError, printJson } from '../lib/output.js';
|
|
4
|
+
import { resolveApiToken } from '../lib/wiki-shared.js';
|
|
5
|
+
/** The raw-SQL data plane (design §5, §7.2, §8) — a construction surface
|
|
6
|
+
* for the authors of the apps attached to the Database and for org
|
|
7
|
+
* owners/admins, not the member product surface (that will be app-defined
|
|
8
|
+
* actions, designed separately). A standalone Database (no apps) is
|
|
9
|
+
* owners/admins-only. query runs one read-only statement as the Database's
|
|
10
|
+
* read role; exec runs one or more statements in a single transaction as
|
|
11
|
+
* the write role, or as the owner role with a snapshot first when the SQL
|
|
12
|
+
* is a schema change. Destructive DDL and restores issued by an agent are
|
|
13
|
+
* refused with DB_DDL_APPROVAL_REQUIRED while the Database requires
|
|
14
|
+
* org owner/admin approval. */
|
|
15
|
+
export function registerDataPlaneCommands(group, binding) {
|
|
16
|
+
const withTarget = (cmd) => {
|
|
17
|
+
cmd.requiredOption(binding.flag, binding.flagHelp);
|
|
18
|
+
for (const extra of binding.extraOptions ?? []) {
|
|
19
|
+
cmd.option(extra.flag, extra.help);
|
|
20
|
+
}
|
|
21
|
+
return cmd;
|
|
22
|
+
};
|
|
23
|
+
withTarget(group
|
|
24
|
+
.command('query')
|
|
25
|
+
.description('Run one read-only statement (attached-app author or org owner/admin)'))
|
|
26
|
+
.option('--sql <sql>', 'SQL text')
|
|
27
|
+
.option('--file <path>', 'Read the SQL from a file (- for stdin)')
|
|
28
|
+
.option('--param <value...>', 'Positional parameters $1..$n; JSON values (42, "text", true, null) or bare text')
|
|
29
|
+
.action(async (opts) => {
|
|
30
|
+
try {
|
|
31
|
+
const ctx = resolveCredentials();
|
|
32
|
+
const target = await binding.resolve(ctx, opts);
|
|
33
|
+
const sql = await readSql(opts);
|
|
34
|
+
printJson(await query(ctx, target, { sql, params: parseParams(opts.param) }));
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
printError(err);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
withTarget(group
|
|
41
|
+
.command('exec')
|
|
42
|
+
.description('Run statements in one transaction: data writes or schema changes (snapshot first); attached-app author or org owner/admin'))
|
|
43
|
+
.option('--sql <sql>', 'SQL text (several statements separated by ;)')
|
|
44
|
+
.option('--file <path>', 'Read the SQL from a file (- for stdin)')
|
|
45
|
+
.option('--param <value...>', 'Positional parameters $1..$n (single statement only)')
|
|
46
|
+
.option('--dry-run', 'Execute inside the transaction and roll back')
|
|
47
|
+
.action(async (opts) => {
|
|
48
|
+
try {
|
|
49
|
+
const ctx = resolveCredentials();
|
|
50
|
+
const target = await binding.resolve(ctx, opts);
|
|
51
|
+
const sql = await readSql(opts);
|
|
52
|
+
printJson(await exec(ctx, target, {
|
|
53
|
+
sql,
|
|
54
|
+
params: parseParams(opts.param),
|
|
55
|
+
dry_run: Boolean(opts.dryRun),
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
printError(err);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
withTarget(group
|
|
63
|
+
.command('schema')
|
|
64
|
+
.description('Describe the schema: tables, columns, primary keys, enums')).action(async (opts) => {
|
|
65
|
+
try {
|
|
66
|
+
const ctx = resolveCredentials();
|
|
67
|
+
printJson(await schema(ctx, await binding.resolve(ctx, opts)));
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
printError(err);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
withTarget(group.command('types').description('Generate TypeScript types for the schema'))
|
|
74
|
+
.option('--out <file>', 'Write the declarations to a file instead of stdout')
|
|
75
|
+
.action(async (opts) => {
|
|
76
|
+
try {
|
|
77
|
+
const ctx = resolveCredentials();
|
|
78
|
+
const result = await types(ctx, await binding.resolve(ctx, opts));
|
|
79
|
+
if (opts.out) {
|
|
80
|
+
await fs.writeFile(opts.out, result.source, 'utf8');
|
|
81
|
+
console.error(`Wrote ${opts.out}`);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
process.stdout.write(result.source);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
printError(err);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
withTarget(group.command('dump').description('Plain-SQL pg_dump of the schema (or one table)'))
|
|
92
|
+
.option('--table <name>', 'Only this table')
|
|
93
|
+
.option('--out <file>', 'Write the dump to a file instead of stdout')
|
|
94
|
+
.action(async (opts) => {
|
|
95
|
+
try {
|
|
96
|
+
const ctx = resolveCredentials();
|
|
97
|
+
const sql = await downloadDump(ctx, await binding.resolve(ctx, opts), opts.table);
|
|
98
|
+
if (opts.out) {
|
|
99
|
+
await fs.writeFile(opts.out, sql, 'utf8');
|
|
100
|
+
console.error(`Wrote ${opts.out} (${sql.length} bytes)`);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
process.stdout.write(sql);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
printError(err);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
withTarget(group
|
|
111
|
+
.command('log')
|
|
112
|
+
.description('SQL log: execs with actor, app, role, rows, data_seq and errors'))
|
|
113
|
+
.option('--limit <n>', 'Entries to return (default 50, max 200)')
|
|
114
|
+
.option('--before <rfc3339>', 'Entries created before this instant')
|
|
115
|
+
.action(async (opts) => {
|
|
116
|
+
try {
|
|
117
|
+
const ctx = resolveCredentials();
|
|
118
|
+
printJson(await log(ctx, await binding.resolve(ctx, opts), {
|
|
119
|
+
limit: opts.limit ? Number(opts.limit) : undefined,
|
|
120
|
+
before: opts.before,
|
|
121
|
+
}));
|
|
122
|
+
}
|
|
123
|
+
catch (err) {
|
|
124
|
+
printError(err);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
withTarget(group.command('snapshots').description('Restore points taken before schema changes')).action(async (opts) => {
|
|
128
|
+
try {
|
|
129
|
+
const ctx = resolveCredentials();
|
|
130
|
+
printJson(await snapshots(ctx, await binding.resolve(ctx, opts)));
|
|
131
|
+
}
|
|
132
|
+
catch (err) {
|
|
133
|
+
printError(err);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
withTarget(group
|
|
137
|
+
.command('restore')
|
|
138
|
+
.description('Replace the schema with a snapshot; the current state is snapshotted first'))
|
|
139
|
+
.requiredOption('--to <logId>', 'log_id of the snapshot (see `snapshots`)')
|
|
140
|
+
.action(async (opts) => {
|
|
141
|
+
try {
|
|
142
|
+
const ctx = resolveCredentials();
|
|
143
|
+
printJson(await restore(ctx, await binding.resolve(ctx, opts), opts.to));
|
|
144
|
+
}
|
|
145
|
+
catch (err) {
|
|
146
|
+
printError(err);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
function query(ctx, t, req) {
|
|
151
|
+
return t.kind === 'app'
|
|
152
|
+
? ctx.client.queryMiniAppDB(ctx.orgId, t.id, req)
|
|
153
|
+
: ctx.client.queryMiniAppDatabase(ctx.orgId, t.id, req);
|
|
154
|
+
}
|
|
155
|
+
function exec(ctx, t, req) {
|
|
156
|
+
return t.kind === 'app'
|
|
157
|
+
? ctx.client.execMiniAppDB(ctx.orgId, t.id, req)
|
|
158
|
+
: ctx.client.execMiniAppDatabase(ctx.orgId, t.id, req);
|
|
159
|
+
}
|
|
160
|
+
function schema(ctx, t) {
|
|
161
|
+
return t.kind === 'app'
|
|
162
|
+
? ctx.client.getMiniAppDBSchema(ctx.orgId, t.id)
|
|
163
|
+
: ctx.client.getMiniAppDatabaseSchema(ctx.orgId, t.id);
|
|
164
|
+
}
|
|
165
|
+
function types(ctx, t) {
|
|
166
|
+
return t.kind === 'app'
|
|
167
|
+
? ctx.client.getMiniAppDBTypes(ctx.orgId, t.id)
|
|
168
|
+
: ctx.client.getMiniAppDatabaseTypes(ctx.orgId, t.id);
|
|
169
|
+
}
|
|
170
|
+
function log(ctx, t, q) {
|
|
171
|
+
return t.kind === 'app'
|
|
172
|
+
? ctx.client.getMiniAppDBLog(ctx.orgId, t.id, q)
|
|
173
|
+
: ctx.client.getMiniAppDatabaseLog(ctx.orgId, t.id, q);
|
|
174
|
+
}
|
|
175
|
+
function snapshots(ctx, t) {
|
|
176
|
+
return t.kind === 'app'
|
|
177
|
+
? ctx.client.getMiniAppDBSnapshots(ctx.orgId, t.id)
|
|
178
|
+
: ctx.client.getMiniAppDatabaseSnapshots(ctx.orgId, t.id);
|
|
179
|
+
}
|
|
180
|
+
function restore(ctx, t, logId) {
|
|
181
|
+
return t.kind === 'app'
|
|
182
|
+
? ctx.client.restoreMiniAppDB(ctx.orgId, t.id, logId)
|
|
183
|
+
: ctx.client.restoreMiniAppDatabase(ctx.orgId, t.id, logId);
|
|
184
|
+
}
|
|
185
|
+
async function readSql(opts) {
|
|
186
|
+
if (opts.sql && opts.file)
|
|
187
|
+
throw new Error('Pass either --sql or --file, not both');
|
|
188
|
+
if (opts.sql !== undefined)
|
|
189
|
+
return opts.sql;
|
|
190
|
+
if (opts.file === '-')
|
|
191
|
+
return readStdin();
|
|
192
|
+
if (opts.file)
|
|
193
|
+
return fs.readFile(opts.file, 'utf8');
|
|
194
|
+
throw new Error('Pass --sql <sql> or --file <path> (- for stdin)');
|
|
195
|
+
}
|
|
196
|
+
async function readStdin() {
|
|
197
|
+
const chunks = [];
|
|
198
|
+
for await (const chunk of process.stdin) {
|
|
199
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
200
|
+
}
|
|
201
|
+
return Buffer.concat(chunks).toString('utf8');
|
|
202
|
+
}
|
|
203
|
+
/** Each --param is a JSON value when it parses as one, else the bare text.
|
|
204
|
+
* The server binds every value as text and lets PostgreSQL parse it against
|
|
205
|
+
* the parameter's real type, so `--param 42` and `--param '"42"'` both work
|
|
206
|
+
* for an integer column. */
|
|
207
|
+
export function parseParams(raw) {
|
|
208
|
+
if (!raw || raw.length === 0)
|
|
209
|
+
return undefined;
|
|
210
|
+
return raw.map((value) => {
|
|
211
|
+
try {
|
|
212
|
+
return JSON.parse(value);
|
|
213
|
+
}
|
|
214
|
+
catch {
|
|
215
|
+
return value;
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
/** The dump is `application/sql` text, not a JSON envelope, so it is fetched
|
|
220
|
+
* directly rather than through the SDK. */
|
|
221
|
+
async function downloadDump(ctx, t, table) {
|
|
222
|
+
const base = (process.env.PRLL_API_URL ?? '').replace(/\/+$/, '');
|
|
223
|
+
const path = t.kind === 'app' ? `apps/${t.id}/db/dump` : `dbs/${t.id}/dump`;
|
|
224
|
+
let url = `${base}/api/v1/orgs/${ctx.orgId}/${path}`;
|
|
225
|
+
if (table)
|
|
226
|
+
url += `?table=${encodeURIComponent(table)}`;
|
|
227
|
+
const headers = { Authorization: `Bearer ${resolveApiToken(ctx)}` };
|
|
228
|
+
if (process.env.PRLL_SWIMLANE_NAME) {
|
|
229
|
+
headers['X-Prll-Swimlane'] = process.env.PRLL_SWIMLANE_NAME;
|
|
230
|
+
}
|
|
231
|
+
const response = await fetch(url, { headers });
|
|
232
|
+
if (!response.ok) {
|
|
233
|
+
const text = await response.text().catch(() => '');
|
|
234
|
+
throw new Error(`GET ${url}: ${response.status} ${response.statusText}${text ? ` — ${text}` : ''}`);
|
|
235
|
+
}
|
|
236
|
+
return response.text();
|
|
237
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Command } from 'commander';
|
|
2
|
+
import { resolveCredentials } from '../lib/client.js';
|
|
3
|
+
/** Database entity: a PostgreSQL schema of its own inside the org's
|
|
4
|
+
* database on the apps instance (docs/engineering-design/mini-app-design.md
|
|
5
|
+
* §4, §5). Databases belong to the organization; apps of the org attach to
|
|
6
|
+
* one, and it may also stand alone. This file manages the entity (visible
|
|
7
|
+
* to every org member); the raw-SQL data plane (query / exec / schema / …)
|
|
8
|
+
* is db-plane.ts — a construction surface for attached-app authors and org
|
|
9
|
+
* owners/admins — mounted here with `--db` and under `parall app db` with
|
|
10
|
+
* `--app`. Every command answers 404 while the deployment has cap:mini-apps
|
|
11
|
+
* off and 403 MINI_APPS_UNAVAILABLE for an org without the mini-apps flag. */
|
|
12
|
+
export declare function registerDbCommands(program: Command): void;
|
|
13
|
+
/** A Database is addressed by id, or by its name — unique in the org,
|
|
14
|
+
* case-insensitively. */
|
|
15
|
+
export declare function resolveDatabaseId(ctx: ReturnType<typeof resolveCredentials>, idOrName: string): Promise<string>;
|
|
16
|
+
//# sourceMappingURL=dbs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dbs.d.ts","sourceRoot":"","sources":["../../src/commands/dbs.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAOtD;;;;;;;;8EAQ8E;AAC9E,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,QAkIlD;AASD;yBACyB;AACzB,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,UAAU,CAAC,OAAO,kBAAkB,CAAC,EAC1C,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,CAAC,CAYjB"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { resolveCredentials } from '../lib/client.js';
|
|
2
|
+
import { printError, printJson, printRefHint, stripPrllScheme } from '../lib/output.js';
|
|
3
|
+
import { registerDataPlaneCommands } from './db-plane.js';
|
|
4
|
+
const DEPRECATED_PROJECT = 'Deprecated and ignored: Databases belong to the organization and names are unique in it';
|
|
5
|
+
/** Database entity: a PostgreSQL schema of its own inside the org's
|
|
6
|
+
* database on the apps instance (docs/engineering-design/mini-app-design.md
|
|
7
|
+
* §4, §5). Databases belong to the organization; apps of the org attach to
|
|
8
|
+
* one, and it may also stand alone. This file manages the entity (visible
|
|
9
|
+
* to every org member); the raw-SQL data plane (query / exec / schema / …)
|
|
10
|
+
* is db-plane.ts — a construction surface for attached-app authors and org
|
|
11
|
+
* owners/admins — mounted here with `--db` and under `parall app db` with
|
|
12
|
+
* `--app`. Every command answers 404 while the deployment has cap:mini-apps
|
|
13
|
+
* off and 403 MINI_APPS_UNAVAILABLE for an org without the mini-apps flag. */
|
|
14
|
+
export function registerDbCommands(program) {
|
|
15
|
+
const db = program
|
|
16
|
+
.command('db')
|
|
17
|
+
.description('Manage Databases (Mini App data); the SQL commands are the construction surface of app authors and org owners/admins');
|
|
18
|
+
registerDataPlaneCommands(db, {
|
|
19
|
+
flag: '--db <idOrName>',
|
|
20
|
+
flagHelp: 'Database ID (adb_… or prll://adb_…) or its name',
|
|
21
|
+
extraOptions: [{ flag: '--project <projectId>', help: DEPRECATED_PROJECT }],
|
|
22
|
+
resolve: resolveDatabaseTarget,
|
|
23
|
+
});
|
|
24
|
+
db.command('list')
|
|
25
|
+
.description("List the organization's Databases")
|
|
26
|
+
.option('--project <projectId>', DEPRECATED_PROJECT)
|
|
27
|
+
.action(async () => {
|
|
28
|
+
try {
|
|
29
|
+
const { client, orgId } = resolveCredentials();
|
|
30
|
+
printJson(await client.getMiniAppDatabases(orgId));
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
printError(err);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
db.command('get')
|
|
37
|
+
.description('Get a Database and the apps attached to it')
|
|
38
|
+
.argument('<idOrName>', 'Database ID or its name')
|
|
39
|
+
.option('--project <projectId>', DEPRECATED_PROJECT)
|
|
40
|
+
.action(async (idOrName) => {
|
|
41
|
+
try {
|
|
42
|
+
const ctx = resolveCredentials();
|
|
43
|
+
const id = await resolveDatabaseId(ctx, idOrName);
|
|
44
|
+
printJson(await ctx.client.getMiniAppDatabase(ctx.orgId, id));
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
printError(err);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
db.command('create')
|
|
51
|
+
.description('Create a standalone Database (its SQL stays org owners/admins-only until an app attaches)')
|
|
52
|
+
.option('--project <projectId>', DEPRECATED_PROJECT)
|
|
53
|
+
.requiredOption('--name <name>', 'Database name (unique in the organization)')
|
|
54
|
+
.option('--description <text>', 'Description')
|
|
55
|
+
.option('--members-read-only', 'Reserved for the future action layer; no effect on the raw-SQL surface')
|
|
56
|
+
.option('--agent-destructive-requires-approval <bool>', 'true (default) = destructive DDL and restores by an agent need org owner/admin approval')
|
|
57
|
+
.action(async (opts) => {
|
|
58
|
+
try {
|
|
59
|
+
const { client, orgId } = resolveCredentials();
|
|
60
|
+
const data = { name: opts.name };
|
|
61
|
+
if (opts.description)
|
|
62
|
+
data.description = opts.description;
|
|
63
|
+
if (opts.membersReadOnly)
|
|
64
|
+
data.members_read_only = true;
|
|
65
|
+
if (opts.agentDestructiveRequiresApproval !== undefined) {
|
|
66
|
+
data.agent_destructive_requires_approval = parseBoolFlag('--agent-destructive-requires-approval', opts.agentDestructiveRequiresApproval);
|
|
67
|
+
}
|
|
68
|
+
const result = await client.createMiniAppDatabase(orgId, data);
|
|
69
|
+
printJson(result);
|
|
70
|
+
printRefHint(result.id);
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
printError(err);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
db.command('update')
|
|
77
|
+
.description('Update a Database (org owner/admin)')
|
|
78
|
+
.argument('<idOrName>', 'Database ID or its name')
|
|
79
|
+
.option('--project <projectId>', DEPRECATED_PROJECT)
|
|
80
|
+
.option('--name <name>', 'New name')
|
|
81
|
+
.option('--description <text>', 'New description (empty string clears)')
|
|
82
|
+
.option('--members-read-only <bool>', 'Reserved for the future action layer; no effect on the raw-SQL surface')
|
|
83
|
+
.option('--agent-destructive-requires-approval <bool>', 'true (default) = destructive DDL and restores by an agent need org owner/admin approval')
|
|
84
|
+
.action(async (idOrName, opts) => {
|
|
85
|
+
try {
|
|
86
|
+
const ctx = resolveCredentials();
|
|
87
|
+
const data = {};
|
|
88
|
+
if (opts.name !== undefined)
|
|
89
|
+
data.name = opts.name;
|
|
90
|
+
if (opts.description !== undefined)
|
|
91
|
+
data.description = opts.description;
|
|
92
|
+
if (opts.membersReadOnly !== undefined) {
|
|
93
|
+
data.members_read_only = parseBoolFlag('--members-read-only', opts.membersReadOnly);
|
|
94
|
+
}
|
|
95
|
+
if (opts.agentDestructiveRequiresApproval !== undefined) {
|
|
96
|
+
data.agent_destructive_requires_approval = parseBoolFlag('--agent-destructive-requires-approval', opts.agentDestructiveRequiresApproval);
|
|
97
|
+
}
|
|
98
|
+
if (Object.keys(data).length === 0) {
|
|
99
|
+
throw new Error('Nothing to update: pass at least one of --name, --description, --members-read-only, --agent-destructive-requires-approval');
|
|
100
|
+
}
|
|
101
|
+
const id = await resolveDatabaseId(ctx, idOrName);
|
|
102
|
+
printJson(await ctx.client.updateMiniAppDatabase(ctx.orgId, id, data));
|
|
103
|
+
}
|
|
104
|
+
catch (err) {
|
|
105
|
+
printError(err);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
db.command('delete')
|
|
109
|
+
.description('Delete a Database nothing is attached to (org owner/admin)')
|
|
110
|
+
.argument('<idOrName>', 'Database ID or its name')
|
|
111
|
+
.option('--project <projectId>', DEPRECATED_PROJECT)
|
|
112
|
+
.action(async (idOrName) => {
|
|
113
|
+
try {
|
|
114
|
+
const ctx = resolveCredentials();
|
|
115
|
+
const id = await resolveDatabaseId(ctx, idOrName);
|
|
116
|
+
await ctx.client.deleteMiniAppDatabase(ctx.orgId, id);
|
|
117
|
+
console.error(`Deleted ${id}`);
|
|
118
|
+
}
|
|
119
|
+
catch (err) {
|
|
120
|
+
printError(err);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
async function resolveDatabaseTarget(ctx, opts) {
|
|
125
|
+
return { kind: 'db', id: await resolveDatabaseId(ctx, opts.db ?? '') };
|
|
126
|
+
}
|
|
127
|
+
/** A Database is addressed by id, or by its name — unique in the org,
|
|
128
|
+
* case-insensitively. */
|
|
129
|
+
export async function resolveDatabaseId(ctx, idOrName) {
|
|
130
|
+
const value = stripPrllScheme(idOrName.trim());
|
|
131
|
+
if (value === '')
|
|
132
|
+
throw new Error('Pass a Database ID or name');
|
|
133
|
+
if (value.startsWith('adb_'))
|
|
134
|
+
return value;
|
|
135
|
+
const all = await ctx.client.getMiniAppDatabases(ctx.orgId);
|
|
136
|
+
const match = all.find((d) => d.name.toLowerCase() === value.toLowerCase());
|
|
137
|
+
if (!match) {
|
|
138
|
+
throw new Error(`No database named ${JSON.stringify(value)}; pass its adb_ id or check \`parall db list\``);
|
|
139
|
+
}
|
|
140
|
+
return match.id;
|
|
141
|
+
}
|
|
142
|
+
function parseBoolFlag(flag, value) {
|
|
143
|
+
if (value !== 'true' && value !== 'false') {
|
|
144
|
+
throw new Error(`${flag} must be true or false`);
|
|
145
|
+
}
|
|
146
|
+
return value === 'true';
|
|
147
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { TriggerConnection } from '@parall/sdk';
|
|
1
|
+
import type { TestTriggerFilterInput, Trigger, TriggerConnection } from '@parall/sdk';
|
|
2
2
|
import type { Command } from 'commander';
|
|
3
3
|
export declare const TRIGGERS_FLAG = "external-triggers";
|
|
4
4
|
type TriggerFeatureFlagClient = {
|
|
@@ -10,6 +10,19 @@ type IngressTokenOutputOptions = {
|
|
|
10
10
|
tokenFile?: string;
|
|
11
11
|
showToken?: boolean;
|
|
12
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Builds `parall triggers test` input: the filter and source kind default to
|
|
15
|
+
* the given trigger's; the event is exactly one of a sample file's JSON
|
|
16
|
+
* object, a stored ingress event, or a real task/project (platform events).
|
|
17
|
+
*/
|
|
18
|
+
export declare function triggerFilterTestInput(opts: {
|
|
19
|
+
filter?: string;
|
|
20
|
+
sourceKind?: string;
|
|
21
|
+
sample?: string;
|
|
22
|
+
event?: string;
|
|
23
|
+
entity?: string;
|
|
24
|
+
eventType?: string;
|
|
25
|
+
}, trigger: Pick<Trigger, 'filter_expr' | 'source_kind'> | undefined, sampleText: string | undefined): TestTriggerFilterInput;
|
|
13
26
|
export declare function isFeatureFlagEnabled(value: boolean | string | number | undefined): boolean;
|
|
14
27
|
export declare function requireTriggersEnabled(client: TriggerFeatureFlagClient, orgId: string): Promise<void>;
|
|
15
28
|
export declare function validateIngressTokenOutputOptions(opts: IngressTokenOutputOptions): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"triggers.d.ts","sourceRoot":"","sources":["../../src/commands/triggers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"triggers.d.ts","sourceRoot":"","sources":["../../src/commands/triggers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,sBAAsB,EACtB,OAAO,EACP,iBAAiB,EAKlB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAOzC,eAAO,MAAM,aAAa,sBAAsB,CAAC;AAEjD,KAAK,wBAAwB,GAAG;IAC9B,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC,CAAA;KAAE,CAAC,CAAC;CAC/F,CAAC;AAEF,KAAK,yBAAyB,GAAG;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAsDF;;;;GAIG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE;IACJ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,EACD,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,aAAa,GAAG,aAAa,CAAC,GAAG,SAAS,EACjE,UAAU,EAAE,MAAM,GAAG,SAAS,GAC7B,sBAAsB,CAqCxB;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,CAM1F;AAED,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,wBAAwB,EAChC,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,IAAI,CAAC,CAKf;AAQD,wBAAgB,iCAAiC,CAAC,IAAI,EAAE,yBAAyB,GAAG,IAAI,CAKvF;AAED,wBAAsB,qBAAqB,CACzC,UAAU,EAAE,iBAAiB,EAC7B,IAAI,EAAE,yBAAyB,GAC9B,OAAO,CAAC,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAqBtD;AAkBD,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,OAAO,QA0fvD"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { chmod, readFile, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { readTextFileArg } from '../lib/text-input.js';
|
|
2
3
|
import { resolveCredentials } from '../lib/client.js';
|
|
3
4
|
import { printError, printJson, printRefHint, stripPrllScheme } from '../lib/output.js';
|
|
4
5
|
const connectionStatuses = ['active', 'disabled'];
|
|
@@ -50,6 +51,46 @@ function parseJsonObject(value, flag) {
|
|
|
50
51
|
}
|
|
51
52
|
return parsed;
|
|
52
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Builds `parall triggers test` input: the filter and source kind default to
|
|
56
|
+
* the given trigger's; the event is exactly one of a sample file's JSON
|
|
57
|
+
* object, a stored ingress event, or a real task/project (platform events).
|
|
58
|
+
*/
|
|
59
|
+
export function triggerFilterTestInput(opts, trigger, sampleText) {
|
|
60
|
+
if ([opts.sample, opts.event, opts.entity].filter(Boolean).length !== 1) {
|
|
61
|
+
throw new Error('Pass exactly one of --sample <path>, --event <ingressEventId> or --entity <prll://tsk_…|prll://prj_…>.');
|
|
62
|
+
}
|
|
63
|
+
if (opts.eventType && !opts.entity) {
|
|
64
|
+
throw new Error('--event-type only applies with --entity.');
|
|
65
|
+
}
|
|
66
|
+
const filter = opts.filter ?? trigger?.filter_expr;
|
|
67
|
+
if (!filter) {
|
|
68
|
+
throw new Error('Pass --filter <expr>, or a trigger ID to test its filter.');
|
|
69
|
+
}
|
|
70
|
+
const sourceKind = parseEnum(opts.sourceKind, triggerSourceKinds, '--source-kind') ??
|
|
71
|
+
trigger?.source_kind ??
|
|
72
|
+
(opts.entity ? 'platform_event' : 'webhook');
|
|
73
|
+
if (opts.sample) {
|
|
74
|
+
return {
|
|
75
|
+
filter_expr: filter,
|
|
76
|
+
source_kind: sourceKind,
|
|
77
|
+
envelope: parseJsonObject(sampleText, '--sample'),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
if (opts.event) {
|
|
81
|
+
return {
|
|
82
|
+
filter_expr: filter,
|
|
83
|
+
source_kind: sourceKind,
|
|
84
|
+
ingress_event_id: stripPrllScheme(opts.event),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
filter_expr: filter,
|
|
89
|
+
source_kind: sourceKind,
|
|
90
|
+
entity_uri: opts.entity,
|
|
91
|
+
...stripUndefined({ event_type: opts.eventType }),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
53
94
|
export function isFeatureFlagEnabled(value) {
|
|
54
95
|
return (value === true ||
|
|
55
96
|
(typeof value === 'string' && value !== '') ||
|
|
@@ -249,6 +290,29 @@ export function registerTriggerCommands(program) {
|
|
|
249
290
|
printError(err);
|
|
250
291
|
}
|
|
251
292
|
});
|
|
293
|
+
triggers
|
|
294
|
+
.command('test')
|
|
295
|
+
.description('Evaluate a filter against one event without creating a run; shows each judge.* answer')
|
|
296
|
+
.argument('[triggerId]', 'Trigger whose filter and source kind to test (optional)')
|
|
297
|
+
.option('--filter <expr>', "CEL filter to test (default: the trigger's filter)")
|
|
298
|
+
.option('--source-kind <kind>', "webhook | platform_event (default: the trigger's, else webhook)")
|
|
299
|
+
.option('--sample <path>', 'JSON file holding a sample event envelope (- reads stdin)')
|
|
300
|
+
.option('--event <ingressEventId>', 'A stored ingress event you can read')
|
|
301
|
+
.option('--entity <uri>', 'A task or project you can read (platform_event): prll://tsk_… or prll://prj_…')
|
|
302
|
+
.option('--event-type <type>', 'With --entity: the platform event to simulate (default: its *.created)')
|
|
303
|
+
.action(async (triggerId, opts) => {
|
|
304
|
+
try {
|
|
305
|
+
const { client, orgId } = await resolveTriggerCommandContext();
|
|
306
|
+
const trigger = triggerId
|
|
307
|
+
? await client.getTrigger(orgId, stripPrllScheme(triggerId))
|
|
308
|
+
: undefined;
|
|
309
|
+
const sampleText = opts.sample ? readTextFileArg('--sample', opts.sample) : undefined;
|
|
310
|
+
printJson(await client.testTriggerFilter(orgId, triggerFilterTestInput(opts, trigger, sampleText)));
|
|
311
|
+
}
|
|
312
|
+
catch (err) {
|
|
313
|
+
printError(err);
|
|
314
|
+
}
|
|
315
|
+
});
|
|
252
316
|
triggers
|
|
253
317
|
.command('list')
|
|
254
318
|
.description('List Triggers in the organization')
|
package/dist/commands/watch.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { SetWatchLevelRequest } from '@parall/sdk';
|
|
|
2
2
|
import type { Command } from 'commander';
|
|
3
3
|
export declare function normalizeTargetUri(input: string): string;
|
|
4
4
|
/**
|
|
5
|
-
* Parse `all | mentions [until <when>]` into a request body. `until`
|
|
5
|
+
* Parse `all | mentions [until <when>] | smart` into a request body. `until`
|
|
6
6
|
* accepts an RFC 3339 time, `tomorrow` (09:00 local next day), or a relative
|
|
7
7
|
* duration such as `2h`, `90m`, `1d`. Throws on anything else.
|
|
8
8
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watch.d.ts","sourceRoot":"","sources":["../../src/commands/watch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"watch.d.ts","sourceRoot":"","sources":["../../src/commands/watch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA2BzC,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAGxD;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,GAAG,GAAE,IAAiB,GACrB,IAAI,CAAC,oBAAoB,EAAE,OAAO,GAAG,OAAO,CAAC,CAoB/C;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,GAAG,IAAI,CAiBzD;AAKD,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAiH5D"}
|