@parall/cli 1.74.0 → 1.76.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.
Files changed (78) hide show
  1. package/dist/commands/approvals.d.ts.map +1 -1
  2. package/dist/commands/approvals.js +40 -13
  3. package/dist/commands/apps-action-local.d.ts +6 -1
  4. package/dist/commands/apps-action-local.d.ts.map +1 -1
  5. package/dist/commands/apps-action-local.js +11 -2
  6. package/dist/commands/apps-actions-sdk.generated.d.ts +1 -1
  7. package/dist/commands/apps-actions-sdk.generated.d.ts.map +1 -1
  8. package/dist/commands/apps-actions-sdk.generated.js +1 -1
  9. package/dist/commands/apps-actions.d.ts.map +1 -1
  10. package/dist/commands/apps-actions.js +13 -15
  11. package/dist/commands/apps-add.d.ts +6 -0
  12. package/dist/commands/apps-add.d.ts.map +1 -0
  13. package/dist/commands/apps-add.js +93 -0
  14. package/dist/commands/apps-args.d.ts +22 -0
  15. package/dist/commands/apps-args.d.ts.map +1 -0
  16. package/dist/commands/apps-args.js +62 -0
  17. package/dist/commands/apps-blocks.d.ts +96 -0
  18. package/dist/commands/apps-blocks.d.ts.map +1 -0
  19. package/dist/commands/apps-blocks.js +196 -0
  20. package/dist/commands/apps-check.d.ts.map +1 -1
  21. package/dist/commands/apps-check.js +8 -3
  22. package/dist/commands/apps-db.d.ts +3 -1
  23. package/dist/commands/apps-db.d.ts.map +1 -1
  24. package/dist/commands/apps-db.js +4 -7
  25. package/dist/commands/apps-dev-server.d.ts +3 -0
  26. package/dist/commands/apps-dev-server.d.ts.map +1 -1
  27. package/dist/commands/apps-dev-server.js +4 -0
  28. package/dist/commands/apps-dev-vars.d.ts +38 -0
  29. package/dist/commands/apps-dev-vars.d.ts.map +1 -0
  30. package/dist/commands/apps-dev-vars.js +107 -0
  31. package/dist/commands/apps-dev.d.ts.map +1 -1
  32. package/dist/commands/apps-dev.js +2 -1
  33. package/dist/commands/apps-local-runner.generated.d.ts +2 -1
  34. package/dist/commands/apps-local-runner.generated.d.ts.map +1 -1
  35. package/dist/commands/apps-local-runner.generated.js +2 -1
  36. package/dist/commands/apps-publish.d.ts +3 -1
  37. package/dist/commands/apps-publish.d.ts.map +1 -1
  38. package/dist/commands/apps-publish.js +27 -23
  39. package/dist/commands/apps-scaffold-actions.d.ts +4 -9
  40. package/dist/commands/apps-scaffold-actions.d.ts.map +1 -1
  41. package/dist/commands/apps-scaffold-actions.js +4 -163
  42. package/dist/commands/apps-scaffold.d.ts +5 -4
  43. package/dist/commands/apps-scaffold.d.ts.map +1 -1
  44. package/dist/commands/apps-scaffold.js +24 -144
  45. package/dist/commands/apps-template.d.ts +15 -0
  46. package/dist/commands/apps-template.d.ts.map +1 -0
  47. package/dist/commands/apps-template.js +105 -0
  48. package/dist/commands/apps-templates.gen.d.ts +5 -0
  49. package/dist/commands/apps-templates.gen.d.ts.map +1 -0
  50. package/dist/commands/apps-templates.gen.js +540 -0
  51. package/dist/commands/apps.d.ts +5 -4
  52. package/dist/commands/apps.d.ts.map +1 -1
  53. package/dist/commands/apps.js +42 -44
  54. package/dist/commands/comments.d.ts.map +1 -1
  55. package/dist/commands/comments.js +3 -2
  56. package/dist/commands/db-plane.d.ts +5 -14
  57. package/dist/commands/db-plane.d.ts.map +1 -1
  58. package/dist/commands/db-plane.js +63 -32
  59. package/dist/commands/db-target.d.ts +22 -0
  60. package/dist/commands/db-target.d.ts.map +1 -0
  61. package/dist/commands/db-target.js +43 -0
  62. package/dist/commands/dbs.d.ts +3 -6
  63. package/dist/commands/dbs.d.ts.map +1 -1
  64. package/dist/commands/dbs.js +28 -34
  65. package/dist/commands/secrets.d.ts +3 -0
  66. package/dist/commands/secrets.d.ts.map +1 -0
  67. package/dist/commands/secrets.js +66 -0
  68. package/dist/index.js +18 -2
  69. package/dist/lib/approvers.d.ts +12 -0
  70. package/dist/lib/approvers.d.ts.map +1 -0
  71. package/dist/lib/approvers.js +48 -0
  72. package/dist/lib/output.d.ts +30 -0
  73. package/dist/lib/output.d.ts.map +1 -1
  74. package/dist/lib/output.js +99 -6
  75. package/dist/lib/update-check.d.ts +4 -0
  76. package/dist/lib/update-check.d.ts.map +1 -1
  77. package/dist/lib/update-check.js +3 -1
  78. package/package.json +25 -5
@@ -5,9 +5,10 @@ import type { Command } from 'commander';
5
5
  * its author roster; `app db …` (apps-db.ts) is the app alias of the data
6
6
  * plane, `parall db …` (dbs.ts) the Database itself; publish / versions /
7
7
  * rollback / pull live in apps-publish.ts, the scaffold + local dev host
8
- * in apps-scaffold.ts, and the app's actions in apps-actions.ts (run, list,
9
- * log) and apps-check.ts (the pre-publish module check). Every command answers 404 while the deployment has
10
- * cap:mini-apps off and 403 MINI_APPS_UNAVAILABLE for an org without the
11
- * mini-apps flag. */
8
+ * in apps-scaffold.ts, the @parall blocks in apps-add.ts, and the app's
9
+ * actions in apps-actions.ts (run, list, log) and apps-check.ts (the
10
+ * pre-publish module check). Every command that calls the server answers
11
+ * 404 while the deployment has cap:mini-apps off and 403
12
+ * MINI_APPS_UNAVAILABLE for an org without the mini-apps flag. */
12
13
  export declare function registerAppCommands(program: Command): void;
13
14
  //# sourceMappingURL=apps.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"apps.d.ts","sourceRoot":"","sources":["../../src/commands/apps.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAUzC;;;;;;;;;qBASqB;AACrB,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,QA8LnD"}
1
+ {"version":3,"file":"apps.d.ts","sourceRoot":"","sources":["../../src/commands/apps.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAYzC;;;;;;;;;;kEAUkE;AAClE,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,QA+LnD"}
@@ -1,6 +1,8 @@
1
1
  import { resolveCredentials } from '../lib/client.js';
2
2
  import { printError, printJson, printRefHint, stripPrllScheme } from '../lib/output.js';
3
3
  import { registerAppActionCommands } from './apps-actions.js';
4
+ import { registerAppAddCommand } from './apps-add.js';
5
+ import { appAndArg, appIdFrom, withApp } from './apps-args.js';
4
6
  import { registerAppCheckCommand } from './apps-check.js';
5
7
  import { registerAppDBCommands } from './apps-db.js';
6
8
  import { registerAppDevCommand } from './apps-dev.js';
@@ -12,10 +14,11 @@ import { registerAppScaffoldCommands } from './apps-scaffold.js';
12
14
  * its author roster; `app db …` (apps-db.ts) is the app alias of the data
13
15
  * plane, `parall db …` (dbs.ts) the Database itself; publish / versions /
14
16
  * rollback / pull live in apps-publish.ts, the scaffold + local dev host
15
- * in apps-scaffold.ts, and the app's actions in apps-actions.ts (run, list,
16
- * log) and apps-check.ts (the pre-publish module check). Every command answers 404 while the deployment has
17
- * cap:mini-apps off and 403 MINI_APPS_UNAVAILABLE for an org without the
18
- * mini-apps flag. */
17
+ * in apps-scaffold.ts, the @parall blocks in apps-add.ts, and the app's
18
+ * actions in apps-actions.ts (run, list, log) and apps-check.ts (the
19
+ * pre-publish module check). Every command that calls the server answers
20
+ * 404 while the deployment has cap:mini-apps off and 403
21
+ * MINI_APPS_UNAVAILABLE for an org without the mini-apps flag. */
19
22
  export function registerAppCommands(program) {
20
23
  const app = program
21
24
  .command('app')
@@ -23,6 +26,7 @@ export function registerAppCommands(program) {
23
26
  registerAppDBCommands(app);
24
27
  registerAppPublishCommands(app);
25
28
  registerAppScaffoldCommands(app);
29
+ registerAppAddCommand(app);
26
30
  registerAppDevCommand(app);
27
31
  registerAppCheckCommand(app);
28
32
  registerAppActionCommands(app);
@@ -43,14 +47,11 @@ export function registerAppCommands(program) {
43
47
  printError(err);
44
48
  }
45
49
  });
46
- app
47
- .command('get')
48
- .description('Get a Mini App by ID')
49
- .argument('<appId>', 'App ID (app_… or prll://app_…)')
50
- .action(async (appId) => {
50
+ withApp(app.command('get').description('Get a Mini App by ID')).action(async (appId, opts) => {
51
51
  try {
52
+ const id = appIdFrom(appId, opts.app);
52
53
  const { client, orgId } = resolveCredentials();
53
- printJson(await client.getMiniApp(orgId, stripPrllScheme(appId)));
54
+ printJson(await client.getMiniApp(orgId, id));
54
55
  }
55
56
  catch (err) {
56
57
  printError(err);
@@ -82,14 +83,14 @@ export function registerAppCommands(program) {
82
83
  printError(err);
83
84
  }
84
85
  });
85
- app
86
+ withApp(app
86
87
  .command('update')
87
- .description("Rename a Mini App or change its description (the app's author or an org owner/admin)")
88
- .argument('<appId>', 'App ID')
88
+ .description("Rename a Mini App or change its description (the app's author or an org owner/admin)"))
89
89
  .option('--name <name>', 'New name')
90
90
  .option('--description <text>', 'New description (empty string clears)')
91
91
  .action(async (appId, opts) => {
92
92
  try {
93
+ const id = appIdFrom(appId, opts.app);
93
94
  const { client, orgId } = resolveCredentials();
94
95
  const data = {};
95
96
  if (opts.name !== undefined)
@@ -99,33 +100,30 @@ export function registerAppCommands(program) {
99
100
  if (Object.keys(data).length === 0) {
100
101
  throw new Error('Nothing to update: pass at least one of --name, --description (data settings live on the Database: `parall db update`)');
101
102
  }
102
- printJson(await client.updateMiniApp(orgId, stripPrllScheme(appId), data));
103
+ printJson(await client.updateMiniApp(orgId, id, data));
103
104
  }
104
105
  catch (err) {
105
106
  printError(err);
106
107
  }
107
108
  });
108
- app
109
+ withApp(app
109
110
  .command('archive')
110
- .description("Archive a Mini App (the app's author or an org owner/admin); data and versions are kept")
111
- .argument('<appId>', 'App ID')
112
- .action(async (appId) => {
111
+ .description("Archive a Mini App (the app's author or an org owner/admin); data and versions are kept")).action(async (appId, opts) => {
113
112
  try {
113
+ const id = appIdFrom(appId, opts.app);
114
114
  const { client, orgId } = resolveCredentials();
115
- printJson(await client.archiveMiniApp(orgId, stripPrllScheme(appId)));
115
+ printJson(await client.archiveMiniApp(orgId, id));
116
116
  }
117
117
  catch (err) {
118
118
  printError(err);
119
119
  }
120
120
  });
121
- app
121
+ withApp(app
122
122
  .command('delete')
123
- .description('Delete a Mini App (org owner/admin only, not its authors). It is gone at once — no one can open it or call its actions — its Database stays, and its versions and files are removed after 30 days')
124
- .argument('<appId>', 'App ID')
125
- .action(async (appId) => {
123
+ .description('Delete a Mini App (org owner/admin only, not its authors). It is gone at once — no one can open it or call its actions — its Database stays, and its versions and files are removed after 30 days')).action(async (appId, opts) => {
126
124
  try {
125
+ const id = appIdFrom(appId, opts.app);
127
126
  const { client, orgId } = resolveCredentials();
128
- const id = stripPrllScheme(appId);
129
127
  await client.deleteMiniApp(orgId, id);
130
128
  console.error(`Deleted ${id}`);
131
129
  }
@@ -133,14 +131,13 @@ export function registerAppCommands(program) {
133
131
  printError(err);
134
132
  }
135
133
  });
136
- app
134
+ withApp(app
137
135
  .command('restore')
138
- .description("Restore an archived Mini App (the app's author or an org owner/admin)")
139
- .argument('<appId>', 'App ID')
140
- .action(async (appId) => {
136
+ .description("Restore an archived Mini App (the app's author or an org owner/admin)")).action(async (appId, opts) => {
141
137
  try {
138
+ const id = appIdFrom(appId, opts.app);
142
139
  const { client, orgId } = resolveCredentials();
143
- printJson(await client.restoreMiniApp(orgId, stripPrllScheme(appId)));
140
+ printJson(await client.restoreMiniApp(orgId, id));
144
141
  }
145
142
  catch (err) {
146
143
  printError(err);
@@ -149,14 +146,11 @@ export function registerAppCommands(program) {
149
146
  const authors = app
150
147
  .command('authors')
151
148
  .description('Manage who manages the app: publish, roll back, rename, archive, authors');
152
- authors
153
- .command('list')
154
- .description('List the authors of a Mini App')
155
- .argument('<appId>', 'App ID')
156
- .action(async (appId) => {
149
+ withApp(authors.command('list').description('List the authors of a Mini App')).action(async (appId, opts) => {
157
150
  try {
151
+ const id = appIdFrom(appId, opts.app);
158
152
  const { client, orgId } = resolveCredentials();
159
- printJson(await client.getMiniAppAuthors(orgId, stripPrllScheme(appId)));
153
+ printJson(await client.getMiniAppAuthors(orgId, id));
160
154
  }
161
155
  catch (err) {
162
156
  printError(err);
@@ -165,12 +159,14 @@ export function registerAppCommands(program) {
165
159
  authors
166
160
  .command('add')
167
161
  .description("Add an author (the app's author or an org owner/admin); the user must be a member of the organization")
168
- .argument('<appId>', 'App ID')
169
- .argument('<userId>', 'User or agent ID (usr_…)')
170
- .action(async (appId, userId) => {
162
+ .argument('[appId]', 'App ID (app_… or prll://app_…); or pass --app')
163
+ .argument('[userId]', 'User or agent ID (usr_…)')
164
+ .option('--app <appId>', 'App ID, in place of the first argument')
165
+ .action(async (first, second, opts) => {
171
166
  try {
167
+ const [id, userId] = appAndArg(first, second, opts.app, 'user ID (usr_…)');
172
168
  const { client, orgId } = resolveCredentials();
173
- printJson(await client.addMiniAppAuthor(orgId, stripPrllScheme(appId), stripPrllScheme(userId)));
169
+ printJson(await client.addMiniAppAuthor(orgId, id, stripPrllScheme(userId)));
174
170
  }
175
171
  catch (err) {
176
172
  printError(err);
@@ -179,13 +175,15 @@ export function registerAppCommands(program) {
179
175
  authors
180
176
  .command('remove')
181
177
  .description("Remove an author (the app's author or an org owner/admin); the creator cannot be removed")
182
- .argument('<appId>', 'App ID')
183
- .argument('<userId>', 'User or agent ID (usr_…)')
184
- .action(async (appId, userId) => {
178
+ .argument('[appId]', 'App ID (app_… or prll://app_…); or pass --app')
179
+ .argument('[userId]', 'User or agent ID (usr_…)')
180
+ .option('--app <appId>', 'App ID, in place of the first argument')
181
+ .action(async (first, second, opts) => {
185
182
  try {
183
+ const [id, userId] = appAndArg(first, second, opts.app, 'user ID (usr_…)');
186
184
  const { client, orgId } = resolveCredentials();
187
- await client.removeMiniAppAuthor(orgId, stripPrllScheme(appId), stripPrllScheme(userId));
188
- console.error(`Removed ${stripPrllScheme(userId)} from the authors of ${stripPrllScheme(appId)}`);
185
+ await client.removeMiniAppAuthor(orgId, id, stripPrllScheme(userId));
186
+ console.error(`Removed ${stripPrllScheme(userId)} from the authors of ${id}`);
189
187
  }
190
188
  catch (err) {
191
189
  printError(err);
@@ -1 +1 @@
1
- {"version":3,"file":"comments.d.ts","sourceRoot":"","sources":["../../src/commands/comments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA4BpC;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,GACzB;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,aAAa,EAAE,MAAM,CAAA;CAAE,CAMpD;AAED;+CAC+C;AAC/C,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,MAAM,GAAG,SAAS,GACxB,QAAQ,GAAG,UAAU,GAAG,KAAK,GAAG,SAAS,CAM3C;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,OAAO,QA4KvD"}
1
+ {"version":3,"file":"comments.d.ts","sourceRoot":"","sources":["../../src/commands/comments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA4BpC;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,GACzB;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,aAAa,EAAE,MAAM,CAAA;CAAE,CAMpD;AAED;+CAC+C;AAC/C,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,MAAM,GAAG,SAAS,GACxB,QAAQ,GAAG,UAAU,GAAG,KAAK,GAAG,SAAS,CAM3C;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,OAAO,QA6KvD"}
@@ -63,12 +63,13 @@ export function registerCommentCommands(program) {
63
63
  comments
64
64
  .command('add')
65
65
  .description('Add a comment to a prll:// target. Inline wiki anchors must pin a revision: ' +
66
- 'prll://wik_x/path.md?rev=<full_commit_sha>#h=<anchor>')
66
+ 'prll://wik_x/path.md?rev=<full_commit_sha>#h=<anchor> (also #l= lines, #t= text bytes, ' +
67
+ 'and #e=<start>-<end> for an element of a .html file, its source byte range)')
67
68
  .requiredOption('--target <uri>', 'Target prll:// URI (task / wiki page / changeset / inline anchor)')
68
69
  .option('--body <text>', BODY_OPTION_DESC)
69
70
  .option('--body-file <path>', BODY_FILE_OPTION_DESC)
70
71
  .option('--parent <id>', 'Root comment ID — post as a threaded reply under it (works on any target type)')
71
- .option('--quote <text>', 'Exact target text the comment anchors to (required for inline text-anchor targets)')
72
+ .option('--quote <text>', 'Text the comment anchors to (required for #t= text and #e= element targets)')
72
73
  .action(async (opts) => {
73
74
  try {
74
75
  // Grammar first: a body-flag error is a parameter error even when
@@ -1,25 +1,17 @@
1
1
  import type { MiniAppSQLParam } from '@parall/sdk';
2
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`. */
3
+ /** A command group of the data plane. Both groups take the target the same
4
+ * ways — as the first argument, with --app or with --db — so the forms an
5
+ * agent reaches for all work; the group only decides which flag its help
6
+ * lists first (`parall db` --db, `parall app db` --app). */
13
7
  export interface DataPlaneBinding {
14
- flag: string;
15
- flagHelp: string;
8
+ primary: 'app' | 'db';
16
9
  /** Extra options every command of the group accepts (e.g. the deprecated
17
10
  * --project). */
18
11
  extraOptions?: Array<{
19
12
  flag: string;
20
13
  help: string;
21
14
  }>;
22
- resolve(ctx: Ctx, opts: Record<string, string | undefined>): Promise<DataPlaneTarget>;
23
15
  }
24
16
  /** The raw-SQL data plane (design §5, §7.2, §8) — a construction surface
25
17
  * for the authors of the apps attached to the Database and for org
@@ -36,5 +28,4 @@ export declare function registerDataPlaneCommands(group: Command, binding: DataP
36
28
  * the parameter's real type, so `--param 42` and `--param '"42"'` both work
37
29
  * for an integer column. */
38
30
  export declare function parseParams(raw: string[] | undefined): MiniAppSQLParam[] | undefined;
39
- export {};
40
31
  //# sourceMappingURL=db-plane.d.ts.map
@@ -1 +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;;;;;;;;mDAQmD;AACnD,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,gBAAgB,QA2JlF;AAgED;;;4BAG4B;AAC5B,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,SAAS,GAAG,eAAe,EAAE,GAAG,SAAS,CASpF"}
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;AASzC;;;4DAG4D;AAC5D,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,KAAK,GAAG,IAAI,CAAC;IACtB;qBACiB;IACjB,YAAY,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACtD;AAgBD;;;;;;;;mDAQmD;AACnD,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,gBAAgB,QAiMlF;AAgED;;;4BAG4B;AAC5B,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,SAAS,GAAG,eAAe,EAAE,GAAG,SAAS,CASpF"}
@@ -2,6 +2,18 @@ import { promises as fs } from 'node:fs';
2
2
  import { resolveCredentials } from '../lib/client.js';
3
3
  import { printError, printJson } from '../lib/output.js';
4
4
  import { resolveApiToken } from '../lib/wiki-shared.js';
5
+ import { outputPath } from './apps-args.js';
6
+ import { resolveDataPlaneTarget } from './db-target.js';
7
+ /** The result of these commands is JSON on stdout, always: --output json
8
+ * (a form scripts reach for) is accepted, any other format refused. */
9
+ function jsonOutput(cmd) {
10
+ return cmd.option('--output <format>', 'Output format: json, the only one (the default)');
11
+ }
12
+ function checkJsonOutput(format) {
13
+ if (format !== undefined && format.trim().toLowerCase() !== 'json') {
14
+ throw new Error(`--output ${format}: the result is always JSON on stdout; to keep it in a file, redirect stdout (> result.json)`);
15
+ }
16
+ }
5
17
  /** The raw-SQL data plane (design §5, §7.2, §8) — a construction surface
6
18
  * for the authors of the apps attached to the Database and for org
7
19
  * owners/admins, not the member product surface (that will be app-defined
@@ -13,22 +25,31 @@ import { resolveApiToken } from '../lib/wiki-shared.js';
13
25
  * always refused with DB_DDL_APPROVAL_REQUIRED. */
14
26
  export function registerDataPlaneCommands(group, binding) {
15
27
  const withTarget = (cmd) => {
16
- cmd.requiredOption(binding.flag, binding.flagHelp);
28
+ cmd.argument('[target]', 'The app (app_…) or Database (adb_… or its name); or pass --app / --db');
29
+ const app = {
30
+ flag: '--app <appId>',
31
+ help: 'App ID (app_… or prll://app_…): its Database, with the app recorded on the SQL log',
32
+ };
33
+ const db = { flag: '--db <idOrName>', help: 'Database ID (adb_… or prll://adb_…) or its name' };
34
+ for (const target of binding.primary === 'app' ? [app, db] : [db, app]) {
35
+ cmd.option(target.flag, target.help);
36
+ }
17
37
  for (const extra of binding.extraOptions ?? []) {
18
38
  cmd.option(extra.flag, extra.help);
19
39
  }
20
40
  return cmd;
21
41
  };
22
- withTarget(group
42
+ jsonOutput(withTarget(group
23
43
  .command('query')
24
- .description('Run one read-only statement (attached-app author or org owner/admin)'))
44
+ .description('Run one read-only statement (attached-app author or org owner/admin)')))
25
45
  .option('--sql <sql>', 'SQL text')
26
46
  .option('--file <path>', 'Read the SQL from a file (- for stdin)')
27
47
  .option('--param <value...>', 'Positional parameters $1..$n; JSON values (42, "text", true, null) or bare text')
28
- .action(async (opts) => {
48
+ .action(async (name, opts) => {
29
49
  try {
50
+ checkJsonOutput(opts.output);
30
51
  const ctx = resolveCredentials();
31
- const target = await binding.resolve(ctx, opts);
52
+ const target = await resolveDataPlaneTarget(ctx, name, opts);
32
53
  const sql = await readSql(opts);
33
54
  printJson(await query(ctx, target, { sql, params: parseParams(opts.param) }));
34
55
  }
@@ -36,17 +57,18 @@ export function registerDataPlaneCommands(group, binding) {
36
57
  printError(err);
37
58
  }
38
59
  });
39
- withTarget(group
60
+ jsonOutput(withTarget(group
40
61
  .command('exec')
41
- .description('Run statements in one transaction: data writes or schema changes (snapshot first); attached-app author or org owner/admin'))
62
+ .description('Run statements in one transaction: data writes or schema changes (snapshot first); attached-app author or org owner/admin')))
42
63
  .option('--sql <sql>', 'SQL text (several statements separated by ;)')
43
64
  .option('--file <path>', 'Read the SQL from a file (- for stdin)')
44
65
  .option('--param <value...>', 'Positional parameters $1..$n (single statement only)')
45
66
  .option('--dry-run', 'Execute inside the transaction and roll back')
46
- .action(async (opts) => {
67
+ .action(async (name, opts) => {
47
68
  try {
69
+ checkJsonOutput(opts.output);
48
70
  const ctx = resolveCredentials();
49
- const target = await binding.resolve(ctx, opts);
71
+ const target = await resolveDataPlaneTarget(ctx, name, opts);
50
72
  const sql = await readSql(opts);
51
73
  printJson(await exec(ctx, target, {
52
74
  sql,
@@ -58,12 +80,14 @@ export function registerDataPlaneCommands(group, binding) {
58
80
  printError(err);
59
81
  }
60
82
  });
61
- withTarget(group
83
+ jsonOutput(withTarget(group
62
84
  .command('schema')
63
- .description('Describe the schema: tables, columns, primary keys, enums')).action(async (opts) => {
85
+ .alias('tables')
86
+ .description('Describe the schema: tables, columns, primary keys, enums'))).action(async (name, opts) => {
64
87
  try {
88
+ checkJsonOutput(opts.output);
65
89
  const ctx = resolveCredentials();
66
- printJson(await schema(ctx, await binding.resolve(ctx, opts)));
90
+ printJson(await schema(ctx, await resolveDataPlaneTarget(ctx, name, opts)));
67
91
  }
68
92
  catch (err) {
69
93
  printError(err);
@@ -71,13 +95,15 @@ export function registerDataPlaneCommands(group, binding) {
71
95
  });
72
96
  withTarget(group.command('types').description('Generate TypeScript types for the schema'))
73
97
  .option('--out <file>', 'Write the declarations to a file instead of stdout')
74
- .action(async (opts) => {
98
+ .option('--output <file>', 'Same as --out')
99
+ .action(async (name, opts) => {
75
100
  try {
101
+ const out = outputPath(opts);
76
102
  const ctx = resolveCredentials();
77
- const result = await types(ctx, await binding.resolve(ctx, opts));
78
- if (opts.out) {
79
- await fs.writeFile(opts.out, result.source, 'utf8');
80
- console.error(`Wrote ${opts.out}`);
103
+ const result = await types(ctx, await resolveDataPlaneTarget(ctx, name, opts));
104
+ if (out) {
105
+ await fs.writeFile(out, result.source, 'utf8');
106
+ console.error(`Wrote ${out}`);
81
107
  }
82
108
  else {
83
109
  process.stdout.write(result.source);
@@ -90,13 +116,15 @@ export function registerDataPlaneCommands(group, binding) {
90
116
  withTarget(group.command('dump').description('Plain-SQL pg_dump of the schema (or one table)'))
91
117
  .option('--table <name>', 'Only this table')
92
118
  .option('--out <file>', 'Write the dump to a file instead of stdout')
93
- .action(async (opts) => {
119
+ .option('--output <file>', 'Same as --out')
120
+ .action(async (name, opts) => {
94
121
  try {
122
+ const out = outputPath(opts);
95
123
  const ctx = resolveCredentials();
96
- const sql = await downloadDump(ctx, await binding.resolve(ctx, opts), opts.table);
97
- if (opts.out) {
98
- await fs.writeFile(opts.out, sql, 'utf8');
99
- console.error(`Wrote ${opts.out} (${sql.length} bytes)`);
124
+ const sql = await downloadDump(ctx, await resolveDataPlaneTarget(ctx, name, opts), opts.table);
125
+ if (out) {
126
+ await fs.writeFile(out, sql, 'utf8');
127
+ console.error(`Wrote ${out} (${sql.length} bytes)`);
100
128
  }
101
129
  else {
102
130
  process.stdout.write(sql);
@@ -106,16 +134,17 @@ export function registerDataPlaneCommands(group, binding) {
106
134
  printError(err);
107
135
  }
108
136
  });
109
- withTarget(group
137
+ jsonOutput(withTarget(group
110
138
  .command('log')
111
- .description('SQL log: execs with actor, app, role, rows, data_seq and errors'))
139
+ .description('SQL log: execs with actor, app, role, rows, data_seq and errors')))
112
140
  .option('--limit <n>', 'Entries to return (default 50, max 200)')
113
141
  .option('--before <rfc3339>', 'Entries created before this instant')
114
142
  .option('--invocation <aci_id>', "Only one action invocation's statements")
115
- .action(async (opts) => {
143
+ .action(async (name, opts) => {
116
144
  try {
145
+ checkJsonOutput(opts.output);
117
146
  const ctx = resolveCredentials();
118
- printJson(await log(ctx, await binding.resolve(ctx, opts), {
147
+ printJson(await log(ctx, await resolveDataPlaneTarget(ctx, name, opts), {
119
148
  limit: opts.limit ? Number(opts.limit) : undefined,
120
149
  before: opts.before,
121
150
  invocation_id: opts.invocation,
@@ -125,23 +154,25 @@ export function registerDataPlaneCommands(group, binding) {
125
154
  printError(err);
126
155
  }
127
156
  });
128
- withTarget(group.command('snapshots').description('Restore points taken before schema changes')).action(async (opts) => {
157
+ jsonOutput(withTarget(group.command('snapshots').description('Restore points taken before schema changes'))).action(async (name, opts) => {
129
158
  try {
159
+ checkJsonOutput(opts.output);
130
160
  const ctx = resolveCredentials();
131
- printJson(await snapshots(ctx, await binding.resolve(ctx, opts)));
161
+ printJson(await snapshots(ctx, await resolveDataPlaneTarget(ctx, name, opts)));
132
162
  }
133
163
  catch (err) {
134
164
  printError(err);
135
165
  }
136
166
  });
137
- withTarget(group
167
+ jsonOutput(withTarget(group
138
168
  .command('restore')
139
- .description('Replace the schema with a snapshot; the current state is snapshotted first'))
169
+ .description('Replace the schema with a snapshot; the current state is snapshotted first')))
140
170
  .requiredOption('--to <logId>', 'log_id of the snapshot (see `snapshots`)')
141
- .action(async (opts) => {
171
+ .action(async (name, opts) => {
142
172
  try {
173
+ checkJsonOutput(opts.output);
143
174
  const ctx = resolveCredentials();
144
- printJson(await restore(ctx, await binding.resolve(ctx, opts), opts.to));
175
+ printJson(await restore(ctx, await resolveDataPlaneTarget(ctx, name, opts), opts.to));
145
176
  }
146
177
  catch (err) {
147
178
  printError(err);
@@ -0,0 +1,22 @@
1
+ import type { resolveCredentials } from '../lib/client.js';
2
+ type Ctx = ReturnType<typeof resolveCredentials>;
3
+ /** What a data-plane command runs against: a Database directly, or an app
4
+ * (the alias: the app's Database, with the app recorded on the log row). */
5
+ export interface DataPlaneTarget {
6
+ kind: 'app' | 'db';
7
+ id: string;
8
+ }
9
+ type TargetOptions = {
10
+ app?: string;
11
+ db?: string;
12
+ };
13
+ /** The target a command names, by what it is: an app ID runs through the
14
+ * app, a Database ID or name on the Database. Given more than once, every
15
+ * form must name the same thing; --app takes IDs only (apps have no name
16
+ * lookup here). */
17
+ export declare function resolveDataPlaneTarget(ctx: Ctx, positional: string | undefined, opts: TargetOptions): Promise<DataPlaneTarget>;
18
+ /** A Database is addressed by id, or by its name — unique in the org,
19
+ * case-insensitively. */
20
+ export declare function resolveDatabaseId(ctx: Ctx, idOrName: string): Promise<string>;
21
+ export {};
22
+ //# sourceMappingURL=db-target.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db-target.d.ts","sourceRoot":"","sources":["../../src/commands/db-target.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAG3D,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,KAAK,aAAa,GAAG;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,EAAE,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAOnD;;;mBAGmB;AACnB,wBAAsB,sBAAsB,CAC1C,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,IAAI,EAAE,aAAa,GAClB,OAAO,CAAC,eAAe,CAAC,CAmB1B;AAED;yBACyB;AACzB,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAYnF"}
@@ -0,0 +1,43 @@
1
+ import { stripPrllScheme } from '../lib/output.js';
2
+ function clean(value) {
3
+ const v = value === undefined ? '' : stripPrllScheme(value.trim());
4
+ return v === '' ? undefined : v;
5
+ }
6
+ /** The target a command names, by what it is: an app ID runs through the
7
+ * app, a Database ID or name on the Database. Given more than once, every
8
+ * form must name the same thing; --app takes IDs only (apps have no name
9
+ * lookup here). */
10
+ export async function resolveDataPlaneTarget(ctx, positional, opts) {
11
+ const app = clean(opts.app);
12
+ if (app && !app.startsWith('app_') && !app.startsWith('adb_')) {
13
+ throw new Error(`--app takes an app ID (app_…); name a Database by its name with --db ${app}`);
14
+ }
15
+ const named = [
16
+ ...new Set([clean(positional), app, clean(opts.db)].filter((v) => v !== undefined)),
17
+ ];
18
+ if (named.length === 0) {
19
+ throw new Error('Name the target: an app (--app app_…) or a Database (--db adb_… or its name), or pass it as the first argument');
20
+ }
21
+ if (named.length > 1) {
22
+ throw new Error(`Name the target once: got ${named.join(' and ')}`);
23
+ }
24
+ const value = named[0];
25
+ if (value.startsWith('app_'))
26
+ return { kind: 'app', id: value };
27
+ return { kind: 'db', id: await resolveDatabaseId(ctx, value) };
28
+ }
29
+ /** A Database is addressed by id, or by its name — unique in the org,
30
+ * case-insensitively. */
31
+ export async function resolveDatabaseId(ctx, idOrName) {
32
+ const value = stripPrllScheme(idOrName.trim());
33
+ if (value === '')
34
+ throw new Error('Pass a Database ID or name');
35
+ if (value.startsWith('adb_'))
36
+ return value;
37
+ const all = await ctx.client.getMiniAppDatabases(ctx.orgId);
38
+ const match = all.find((d) => d.name.toLowerCase() === value.toLowerCase());
39
+ if (!match) {
40
+ throw new Error(`No database named ${JSON.stringify(value)}; pass its adb_ id or check \`parall db list\``);
41
+ }
42
+ return match.id;
43
+ }
@@ -1,16 +1,13 @@
1
1
  import type { Command } from 'commander';
2
- import { resolveCredentials } from '../lib/client.js';
3
2
  /** Database entity: a PostgreSQL schema of its own inside the org's
4
3
  * database on the apps instance (docs/engineering-design/mini-app-design.md
5
4
  * §4, §5). Databases belong to the organization; apps of the org attach to
6
5
  * one, and it may also stand alone. This file manages the entity (visible
7
6
  * to every org member); the raw-SQL data plane (query / exec / schema / …)
8
7
  * 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
8
+ * owners/admins — mounted here and under `parall app db`, both taking the
9
+ * target as an argument, --db or --app (db-target.ts). Every command
10
+ * answers 404 while the deployment has cap:mini-apps
11
11
  * off and 403 MINI_APPS_UNAVAILABLE for an org without the mini-apps flag. */
12
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
13
  //# sourceMappingURL=dbs.d.ts.map
@@ -1 +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,QAgGlD;AASD;yBACyB;AACzB,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,UAAU,CAAC,OAAO,kBAAkB,CAAC,EAC1C,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,CAAC,CAYjB"}
1
+ {"version":3,"file":"dbs.d.ts","sourceRoot":"","sources":["../../src/commands/dbs.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AASzC;;;;;;;;;8EAS8E;AAC9E,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,QA0FlD"}