@parall/cli 1.83.0 → 1.85.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/apps-scaffold.d.ts +4 -4
- package/dist/commands/apps-scaffold.d.ts.map +1 -1
- package/dist/commands/apps-scaffold.js +24 -16
- package/dist/commands/apps-template-catalog.d.ts +46 -72
- package/dist/commands/apps-template-catalog.d.ts.map +1 -1
- package/dist/commands/apps-template-catalog.js +107 -22
- package/dist/commands/apps-template-download.d.ts +7 -0
- package/dist/commands/apps-template-download.d.ts.map +1 -0
- package/dist/commands/apps-template-download.js +116 -0
- package/dist/commands/apps-template-init.d.ts +22 -25
- package/dist/commands/apps-template-init.d.ts.map +1 -1
- package/dist/commands/apps-template-init.js +16 -60
- package/dist/commands/apps-template.d.ts +3 -2
- package/dist/commands/apps-template.d.ts.map +1 -1
- package/dist/commands/apps-template.js +4 -1
- package/dist/commands/browser.js +1 -1
- package/dist/commands/triggers.d.ts.map +1 -1
- package/dist/commands/triggers.js +11 -45
- package/dist/commands/wiki-changesets.d.ts.map +1 -1
- package/dist/commands/wiki-changesets.js +10 -2
- package/dist/commands/wiki-edit.d.ts +7 -0
- package/dist/commands/wiki-edit.d.ts.map +1 -0
- package/dist/commands/wiki-edit.js +50 -0
- package/dist/commands/wiki.d.ts.map +1 -1
- package/dist/commands/wiki.js +2 -0
- package/dist/lib/output.d.ts +7 -0
- package/dist/lib/output.d.ts.map +1 -1
- package/dist/lib/output.js +14 -0
- package/dist/lib/trigger-arguments.d.ts +47 -0
- package/dist/lib/trigger-arguments.d.ts.map +1 -0
- package/dist/lib/trigger-arguments.js +126 -0
- package/dist/lib/wiki-copies.d.ts +18 -0
- package/dist/lib/wiki-copies.d.ts.map +1 -0
- package/dist/lib/wiki-copies.js +88 -0
- package/dist/lib/wiki-edit.d.ts +22 -0
- package/dist/lib/wiki-edit.d.ts.map +1 -0
- package/dist/lib/wiki-edit.js +74 -0
- package/dist/lib/wiki-service-error.d.ts +10 -0
- package/dist/lib/wiki-service-error.d.ts.map +1 -0
- package/dist/lib/wiki-service-error.js +23 -0
- package/dist/lib/wiki-shared.d.ts.map +1 -1
- package/dist/lib/wiki-shared.js +2 -1
- package/dist/lib/wiki-stale-mounts.d.ts +2 -0
- package/dist/lib/wiki-stale-mounts.d.ts.map +1 -0
- package/dist/lib/wiki-stale-mounts.js +59 -0
- package/dist/lib/wiki-sync.d.ts.map +1 -1
- package/dist/lib/wiki-sync.js +4 -59
- package/package.json +5 -5
- package/dist/commands/apps-template-catalog.gen.d.ts +0 -3
- package/dist/commands/apps-template-catalog.gen.d.ts.map +0 -1
- package/dist/commands/apps-template-catalog.gen.js +0 -242
|
@@ -6,9 +6,9 @@ import type { Command } from 'commander';
|
|
|
6
6
|
* for: the scaffold's SQL is written in the dialect of that app's Database
|
|
7
7
|
* (MySQL on TiDB, PostgreSQL otherwise; mini-app-tidb-placement-design.md
|
|
8
8
|
* §6.7) and the next steps name the app. Without it the SQL is PostgreSQL,
|
|
9
|
-
* as before. `--template` starts from an app template
|
|
10
|
-
* example (apps-template-init.ts), listed by
|
|
11
|
-
* (apps-template-catalog.ts). Blocks go on top with
|
|
12
|
-
* (apps-add.ts). */
|
|
9
|
+
* as before. `--template` starts from an app template in the server's
|
|
10
|
+
* library instead of the example (apps-template-init.ts), listed by
|
|
11
|
+
* `parall app templates` (apps-template-catalog.ts). Blocks go on top with
|
|
12
|
+
* `parall app add` (apps-add.ts). */
|
|
13
13
|
export declare function registerAppScaffoldCommands(app: Command): void;
|
|
14
14
|
//# sourceMappingURL=apps-scaffold.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apps-scaffold.d.ts","sourceRoot":"","sources":["../../src/commands/apps-scaffold.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"apps-scaffold.d.ts","sourceRoot":"","sources":["../../src/commands/apps-scaffold.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAsBzC;;;;;;;;;;qCAUqC;AACrC,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,OAAO,QA0DvD"}
|
|
@@ -2,9 +2,10 @@ import { promises as fs } from 'node:fs';
|
|
|
2
2
|
import { join, resolve, sep } from 'node:path';
|
|
3
3
|
import { printError } from '../lib/output.js';
|
|
4
4
|
import { dialectOf } from './apps-placement.js';
|
|
5
|
-
import { scaffoldProject } from './apps-template.js';
|
|
6
|
-
import { cliVersion,
|
|
7
|
-
import {
|
|
5
|
+
import { nameProject, scaffoldProject } from './apps-template.js';
|
|
6
|
+
import { cliVersion, needsNewerCli, readTemplate, registerAppTemplatesCommand, shortVersion, UPDATE_CLI, } from './apps-template-catalog.js';
|
|
7
|
+
import { downloadTemplateProject } from './apps-template-download.js';
|
|
8
|
+
import { resolveInitTarget, templateNextSteps, templateRefusal, withTemplateSkill, writeTemplateProject, } from './apps-template-init.js';
|
|
8
9
|
/** `parall app init`: the scaffold of design §7.4 — Vite + React + TS +
|
|
9
10
|
* Tailwind + shadcn/ui with the host bridge wired (apps-template.ts);
|
|
10
11
|
* `--actions` adds the server-side actions, the schema and an example list
|
|
@@ -12,10 +13,10 @@ import { resolveInitTarget, templateBlocks, templateNextSteps, templateProject,
|
|
|
12
13
|
* for: the scaffold's SQL is written in the dialect of that app's Database
|
|
13
14
|
* (MySQL on TiDB, PostgreSQL otherwise; mini-app-tidb-placement-design.md
|
|
14
15
|
* §6.7) and the next steps name the app. Without it the SQL is PostgreSQL,
|
|
15
|
-
* as before. `--template` starts from an app template
|
|
16
|
-
* example (apps-template-init.ts), listed by
|
|
17
|
-
* (apps-template-catalog.ts). Blocks go on top with
|
|
18
|
-
* (apps-add.ts). */
|
|
16
|
+
* as before. `--template` starts from an app template in the server's
|
|
17
|
+
* library instead of the example (apps-template-init.ts), listed by
|
|
18
|
+
* `parall app templates` (apps-template-catalog.ts). Blocks go on top with
|
|
19
|
+
* `parall app add` (apps-add.ts). */
|
|
19
20
|
export function registerAppScaffoldCommands(app) {
|
|
20
21
|
registerAppTemplatesCommand(app);
|
|
21
22
|
app
|
|
@@ -23,7 +24,7 @@ export function registerAppScaffoldCommands(app) {
|
|
|
23
24
|
.description('Scaffold a new Mini App project (Vite + React + TS + Tailwind + shadcn/ui, bridge wired)')
|
|
24
25
|
.argument('<dir>', 'Directory to create (must be empty or absent)')
|
|
25
26
|
.option('--actions', 'Also scaffold server-side actions, the schema and an example list wired to them (actions/ → dist/_actions/index.js)')
|
|
26
|
-
.option('--template <id>', 'Start from an app template (parall app templates) instead of the example: its pages, actions and schema over the --actions scaffold, and its skill as SKILL.md. Needs --app; read the skill first (parall app templates show <id>)')
|
|
27
|
+
.option('--template <id>', 'Start from an app template in the library (parall app templates) instead of the example: its pages, actions and schema over the --actions scaffold, and its skill as SKILL.md. Needs --app; read the skill first (parall app templates show <id>)')
|
|
27
28
|
.option('--app <appId>', "The app the project is for (app_… or prll://app_…; create it first with parall app create): the SQL is written for its Database — MySQL when the Database's placement is tidb, PostgreSQL otherwise — the next steps name the app, and --template checks its Database")
|
|
28
29
|
.action(async (dir, opts, command) => {
|
|
29
30
|
try {
|
|
@@ -65,20 +66,27 @@ export function registerAppScaffoldCommands(app) {
|
|
|
65
66
|
}
|
|
66
67
|
});
|
|
67
68
|
}
|
|
68
|
-
/** init --template
|
|
69
|
-
*
|
|
69
|
+
/** init --template, in the order of mini-app-template-registry-design.md
|
|
70
|
+
* §8.2: the app and its Database first, then the template from the library
|
|
71
|
+
* and its project, checked file by file, and only then anything written —
|
|
72
|
+
* refused, with nothing written, when --app is missing, the app's Database
|
|
73
|
+
* cannot take the template, the library has no such template, its version
|
|
74
|
+
* needs a newer CLI, or the library or the download fails. */
|
|
70
75
|
async function initFromTemplate(p) {
|
|
71
|
-
const template = findAppTemplate(p.id);
|
|
72
|
-
if (!template)
|
|
73
|
-
throw unknownTemplateError(p.id, cliVersion(p.command));
|
|
74
76
|
if (p.app === undefined) {
|
|
75
|
-
throw new Error(`--template needs --app: create the app first (parall app create --name "<name>"), then parall app init ${p.dir} --template ${
|
|
77
|
+
throw new Error(`--template needs --app: create the app first (parall app create --name "<name>"), then parall app init ${p.dir} --template ${p.id} --app <app_…>`);
|
|
76
78
|
}
|
|
77
79
|
const target = await resolveInitTarget(p.app);
|
|
78
|
-
const refusal = templateRefusal(
|
|
80
|
+
const refusal = templateRefusal(p.id, target);
|
|
79
81
|
if (refusal)
|
|
80
82
|
throw new Error(refusal);
|
|
81
|
-
await
|
|
83
|
+
const template = await readTemplate(p.id, { writes: true });
|
|
84
|
+
const version = cliVersion(p.command);
|
|
85
|
+
if (needsNewerCli(template, version)) {
|
|
86
|
+
throw new Error(`The ${template.id} template (version ${shortVersion(template.version)}) needs parall ${template.cli} or newer, and this is parall ${version}. Nothing was written. Update the CLI once — ${UPDATE_CLI} — then run this command again.`);
|
|
87
|
+
}
|
|
88
|
+
const project = await downloadTemplateProject(template);
|
|
89
|
+
await writeTemplateProject(p.out, withTemplateSkill(nameProject(project, p.name), template));
|
|
82
90
|
console.error(templateNextSteps({ ...p, template, target }));
|
|
83
91
|
}
|
|
84
92
|
function nextSteps(p) {
|
|
@@ -1,81 +1,55 @@
|
|
|
1
|
+
import { type AppTemplateDetail, type AppTemplateSummary } from '@parall/sdk';
|
|
1
2
|
import type { Command } from 'commander';
|
|
2
3
|
/**
|
|
3
|
-
* The app templates
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
4
|
+
* The app templates (docs/engineering-design/mini-app-templates-design.md
|
|
5
|
+
* §3–§5): ready-made apps a person picks and an agent builds with the
|
|
6
|
+
* organization's own data. The CLI reads them from the server's template
|
|
7
|
+
* library (mini-app-template-registry-design.md §7, §8.2), the one the Web
|
|
8
|
+
* shows: each template at the version the server uses — the deployment's,
|
|
9
|
+
* or the one an admin pinned — and none that was taken down. The CLI
|
|
10
|
+
* carries no template of its own and never falls back to one: when the
|
|
11
|
+
* library cannot be read, the commands say so. `parall app templates` lists
|
|
12
|
+
* them, `templates show <id>` prints a skill, and `parall app init
|
|
13
|
+
* --template` (apps-template-init.ts) writes a project from one.
|
|
12
14
|
*/
|
|
13
|
-
/**
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
/** How to update the CLI, as the Mini App instructions put it. */
|
|
16
|
+
export declare const UPDATE_CLI = "npm install -g @parall/cli@latest, or where that is not allowed npm install --prefix ~/.parall-cli @parall/cli@latest and run ~/.parall-cli/node_modules/.bin/parall";
|
|
17
|
+
/** A version as people and agents see it: the first 8 characters of its
|
|
18
|
+
* hash, as the AGENTS.md line init writes names it. */
|
|
19
|
+
export declare function shortVersion(version: string): string;
|
|
20
|
+
/** The version of the CLI that runs (the root command's). */
|
|
21
|
+
export declare function cliVersion(command: Command): string;
|
|
22
|
+
/** Whether the template's version asks for a newer CLI than this one. A
|
|
23
|
+
* CLI that is not a release — a staging build, 0.0.0-staging.<sha>, built
|
|
24
|
+
* from main like the server it talks to — is taken to have what it needs. */
|
|
25
|
+
export declare function needsNewerCli(template: {
|
|
18
26
|
cli: string;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
/** Under the data: what it agrees with the person first. */
|
|
42
|
-
data_note: string;
|
|
43
|
-
/** Who sees what goes into the app. */
|
|
44
|
-
visibility: string;
|
|
45
|
-
/** What the agent does once the app runs. */
|
|
46
|
-
routine: string[];
|
|
47
|
-
/** What wakes it: data_changed, daily. */
|
|
48
|
-
wake: Array<{
|
|
49
|
-
kind: string;
|
|
50
|
-
name: string;
|
|
51
|
-
text: string;
|
|
52
|
-
}>;
|
|
53
|
-
/** What the app cannot do. */
|
|
54
|
-
limits: Array<{
|
|
55
|
-
kind: string;
|
|
56
|
-
text: string;
|
|
57
|
-
}>;
|
|
58
|
-
}
|
|
59
|
-
export interface AppTemplate {
|
|
60
|
-
id: string;
|
|
61
|
-
intro: AppTemplateIntro;
|
|
62
|
-
/** skill.md: SKILL.md in the project. */
|
|
63
|
-
skill: string;
|
|
64
|
-
/** overlay/, path → content: laid over the --actions scaffold the way
|
|
65
|
-
* with-actions is laid over base (_overlay.json: `remove`, `blocks`). */
|
|
66
|
-
overlay: Readonly<Record<string, string>>;
|
|
67
|
-
}
|
|
68
|
-
export declare function findAppTemplate(id: string): AppTemplate | undefined;
|
|
69
|
-
/** What `parall app templates` prints. */
|
|
70
|
-
export declare function listAppTemplates(): {
|
|
27
|
+
}, version: string): boolean;
|
|
28
|
+
/** The error for a template the library does not have: there is none with
|
|
29
|
+
* this id, or it was taken down — the library answers both alike. */
|
|
30
|
+
export declare function unavailableTemplateError(id: string, opts: {
|
|
31
|
+
writes: boolean;
|
|
32
|
+
}): Error;
|
|
33
|
+
/** The error for a library that did not answer: the CLI has no copy of its
|
|
34
|
+
* own to use instead. */
|
|
35
|
+
export declare function libraryUnavailableError(err: unknown, opts: {
|
|
36
|
+
writes: boolean;
|
|
37
|
+
}): Error;
|
|
38
|
+
/** The library: every template it has now. */
|
|
39
|
+
export declare function readLibrary(): Promise<AppTemplateSummary[]>;
|
|
40
|
+
/** One template of the library, with its skill and project. */
|
|
41
|
+
export declare function readTemplate(id: string, opts: {
|
|
42
|
+
writes: boolean;
|
|
43
|
+
}): Promise<AppTemplateDetail>;
|
|
44
|
+
/** One template as `parall app templates` lists it, with the command that
|
|
45
|
+
* reads it; `requires_cli` when its version asks for a newer CLI. */
|
|
46
|
+
export declare function listedTemplate(template: AppTemplateSummary, version: string): {
|
|
47
|
+
next: string;
|
|
48
|
+
requires_cli?: string | undefined;
|
|
71
49
|
id: string;
|
|
72
50
|
name: string;
|
|
73
51
|
summary: string;
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
export declare function cliVersion(command: Command): string;
|
|
77
|
-
/** The error for an id this CLI does not carry: what it has, and that the
|
|
78
|
-
* template may be newer than this CLI. */
|
|
79
|
-
export declare function unknownTemplateError(id: string, version: string): Error;
|
|
52
|
+
version: string;
|
|
53
|
+
};
|
|
80
54
|
export declare function registerAppTemplatesCommand(app: Command): void;
|
|
81
55
|
//# sourceMappingURL=apps-template-catalog.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apps-template-catalog.d.ts","sourceRoot":"","sources":["../../src/commands/apps-template-catalog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"apps-template-catalog.d.ts","sourceRoot":"","sources":["../../src/commands/apps-template-catalog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,iBAAiB,EAAE,KAAK,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACxF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKzC;;;;;;;;;;;GAWG;AAEH,kEAAkE;AAClE,eAAO,MAAM,UAAU,yKACiJ,CAAC;AAEzK;uDACuD;AACvD,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED,6DAA6D;AAC7D,wBAAgB,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAInD;AAED;;6EAE6E;AAC7E,wBAAgB,aAAa,CAAC,QAAQ,EAAE;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAEjF;AAED;qEACqE;AACrE,wBAAgB,wBAAwB,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;IAAE,MAAM,EAAE,OAAO,CAAA;CAAE,GAAG,KAAK,CAMrF;AAED;yBACyB;AACzB,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE;IAAE,MAAM,EAAE,OAAO,CAAA;CAAE,GAAG,KAAK,CAWtF;AAED,8CAA8C;AAC9C,wBAAsB,WAAW,IAAI,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAOjE;AAED,+DAA+D;AAC/D,wBAAsB,YAAY,CAChC,EAAE,EAAE,MAAM,EACV,IAAI,EAAE;IAAE,MAAM,EAAE,OAAO,CAAA;CAAE,GACxB,OAAO,CAAC,iBAAiB,CAAC,CAU5B;AAED;qEACqE;AACrE,wBAAgB,cAAc,CAAC,QAAQ,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM;;;;;;;EAS3E;AAUD,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,OAAO,QA6CvD"}
|
|
@@ -1,11 +1,25 @@
|
|
|
1
|
+
import { ApiError } from '@parall/sdk';
|
|
2
|
+
import { resolveCredentials } from '../lib/client.js';
|
|
1
3
|
import { printError, printJson, printProgress } from '../lib/output.js';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
import { isNewerRelease } from '../lib/update-check.js';
|
|
5
|
+
/**
|
|
6
|
+
* The app templates (docs/engineering-design/mini-app-templates-design.md
|
|
7
|
+
* §3–§5): ready-made apps a person picks and an agent builds with the
|
|
8
|
+
* organization's own data. The CLI reads them from the server's template
|
|
9
|
+
* library (mini-app-template-registry-design.md §7, §8.2), the one the Web
|
|
10
|
+
* shows: each template at the version the server uses — the deployment's,
|
|
11
|
+
* or the one an admin pinned — and none that was taken down. The CLI
|
|
12
|
+
* carries no template of its own and never falls back to one: when the
|
|
13
|
+
* library cannot be read, the commands say so. `parall app templates` lists
|
|
14
|
+
* them, `templates show <id>` prints a skill, and `parall app init
|
|
15
|
+
* --template` (apps-template-init.ts) writes a project from one.
|
|
16
|
+
*/
|
|
17
|
+
/** How to update the CLI, as the Mini App instructions put it. */
|
|
18
|
+
export const UPDATE_CLI = 'npm install -g @parall/cli@latest, or where that is not allowed npm install --prefix ~/.parall-cli @parall/cli@latest and run ~/.parall-cli/node_modules/.bin/parall';
|
|
19
|
+
/** A version as people and agents see it: the first 8 characters of its
|
|
20
|
+
* hash, as the AGENTS.md line init writes names it. */
|
|
21
|
+
export function shortVersion(version) {
|
|
22
|
+
return version.slice(0, 8);
|
|
9
23
|
}
|
|
10
24
|
/** The version of the CLI that runs (the root command's). */
|
|
11
25
|
export function cliVersion(command) {
|
|
@@ -14,33 +28,104 @@ export function cliVersion(command) {
|
|
|
14
28
|
root = root.parent;
|
|
15
29
|
return root.version() ?? 'unknown';
|
|
16
30
|
}
|
|
17
|
-
/**
|
|
18
|
-
*
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
31
|
+
/** Whether the template's version asks for a newer CLI than this one. A
|
|
32
|
+
* CLI that is not a release — a staging build, 0.0.0-staging.<sha>, built
|
|
33
|
+
* from main like the server it talks to — is taken to have what it needs. */
|
|
34
|
+
export function needsNewerCli(template, version) {
|
|
35
|
+
return isNewerRelease(version, template.cli);
|
|
36
|
+
}
|
|
37
|
+
/** The error for a template the library does not have: there is none with
|
|
38
|
+
* this id, or it was taken down — the library answers both alike. */
|
|
39
|
+
export function unavailableTemplateError(id, opts) {
|
|
40
|
+
return new Error(`No app template ${JSON.stringify(id)} is available: there is none with this id, or it has been taken down.` +
|
|
41
|
+
(opts.writes ? ' Nothing was written.' : '') +
|
|
42
|
+
' parall app templates lists the templates there are; if none fits, tell the person this template cannot be used, and ask before building the app another way.');
|
|
43
|
+
}
|
|
44
|
+
/** The error for a library that did not answer: the CLI has no copy of its
|
|
45
|
+
* own to use instead. */
|
|
46
|
+
export function libraryUnavailableError(err, opts) {
|
|
47
|
+
const message = (err instanceof Error ? err.message : String(err)).replace(/\.$/, '');
|
|
48
|
+
const reason = err instanceof ApiError
|
|
49
|
+
? `${message} (${err.code ?? (err.status ? `HTTP ${err.status}` : 'no answer')})`
|
|
50
|
+
: message;
|
|
51
|
+
return new Error(`The app template library could not be read from Parall: ${reason}.` +
|
|
52
|
+
(opts.writes ? ' Nothing was written.' : '') +
|
|
53
|
+
' Try again in a minute; if it keeps failing, tell the person the templates cannot be reached right now.');
|
|
54
|
+
}
|
|
55
|
+
/** The library: every template it has now. */
|
|
56
|
+
export async function readLibrary() {
|
|
57
|
+
const { client } = resolveCredentials();
|
|
58
|
+
try {
|
|
59
|
+
return await client.listAppTemplates();
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
throw libraryUnavailableError(err, { writes: false });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/** One template of the library, with its skill and project. */
|
|
66
|
+
export async function readTemplate(id, opts) {
|
|
67
|
+
const { client } = resolveCredentials();
|
|
68
|
+
try {
|
|
69
|
+
return await client.getAppTemplate(id);
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
if (err instanceof ApiError && err.status === 404 && err.code === 'APP_TEMPLATE_NOT_FOUND') {
|
|
73
|
+
throw unavailableTemplateError(id, opts);
|
|
74
|
+
}
|
|
75
|
+
throw libraryUnavailableError(err, opts);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/** One template as `parall app templates` lists it, with the command that
|
|
79
|
+
* reads it; `requires_cli` when its version asks for a newer CLI. */
|
|
80
|
+
export function listedTemplate(template, version) {
|
|
81
|
+
return {
|
|
82
|
+
id: template.id,
|
|
83
|
+
name: template.intro.name,
|
|
84
|
+
summary: template.intro.summary,
|
|
85
|
+
version: shortVersion(template.version),
|
|
86
|
+
...(needsNewerCli(template, version) ? { requires_cli: template.cli } : {}),
|
|
87
|
+
next: `parall app templates show ${template.id}`,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/** The line `templates show` adds under the skill: the version, and what
|
|
91
|
+
* to do first when it asks for a newer CLI. */
|
|
92
|
+
function versionLine(template, version) {
|
|
93
|
+
const line = `Version ${shortVersion(template.version)} of the ${template.id} template.`;
|
|
94
|
+
if (!needsNewerCli(template, version))
|
|
95
|
+
return line;
|
|
96
|
+
return `${line} Building from it needs parall ${template.cli} or newer, and this is parall ${version}: update the CLI first — ${UPDATE_CLI}.`;
|
|
25
97
|
}
|
|
26
98
|
export function registerAppTemplatesCommand(app) {
|
|
27
99
|
const templates = app
|
|
28
100
|
.command('templates')
|
|
29
101
|
.description('List ready-made app templates (a customer / partner pipeline, …) to build an app from; parall app templates show <id> prints how')
|
|
30
|
-
.action(() => {
|
|
31
|
-
|
|
32
|
-
|
|
102
|
+
.action(async (_opts, command) => {
|
|
103
|
+
try {
|
|
104
|
+
const version = cliVersion(command);
|
|
105
|
+
const listed = (await readLibrary()).map((template) => listedTemplate(template, version));
|
|
106
|
+
printJson(listed);
|
|
107
|
+
if (listed.length === 0) {
|
|
108
|
+
printProgress('There are no app templates in the library right now.');
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
printProgress('Read one before building: parall app templates show <id> prints its skill — what to agree with the person first, then parall app init <dir> --template <id> --app <app_…>');
|
|
112
|
+
if (listed.some((template) => 'requires_cli' in template)) {
|
|
113
|
+
printProgress(`Templates with requires_cli need a newer parall than this one (${version}) to build from: update it once — ${UPDATE_CLI}.`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
catch (err) {
|
|
117
|
+
printError(err);
|
|
118
|
+
}
|
|
33
119
|
});
|
|
34
120
|
templates
|
|
35
121
|
.command('show')
|
|
36
122
|
.description("Print a template's skill (Markdown): what to agree with the person and the data to read, how to build the app, and what to do once it runs")
|
|
37
123
|
.argument('<id>', 'Template id (parall app templates)')
|
|
38
|
-
.action((id, _opts, command) => {
|
|
124
|
+
.action(async (id, _opts, command) => {
|
|
39
125
|
try {
|
|
40
|
-
const template =
|
|
41
|
-
if (!template)
|
|
42
|
-
throw unknownTemplateError(id, cliVersion(command));
|
|
126
|
+
const template = await readTemplate(id, { writes: false });
|
|
43
127
|
process.stdout.write(template.skill.endsWith('\n') ? template.skill : `${template.skill}\n`);
|
|
128
|
+
printProgress(versionLine(template, cliVersion(command)));
|
|
44
129
|
}
|
|
45
130
|
catch (err) {
|
|
46
131
|
printError(err);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AppTemplateDetail } from '@parall/sdk';
|
|
2
|
+
export declare function plainPath(path: string): boolean;
|
|
3
|
+
/** The version's project, path → content, sorted by path, its app name
|
|
4
|
+
* still {{APP_NAME}}. Throws, having written nothing, when the download
|
|
5
|
+
* fails or is not the version's files. */
|
|
6
|
+
export declare function downloadTemplateProject(template: AppTemplateDetail): Promise<Array<[string, string | Buffer]>>;
|
|
7
|
+
//# sourceMappingURL=apps-template-download.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apps-template-download.d.ts","sourceRoot":"","sources":["../../src/commands/apps-template-download.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAmB,MAAM,aAAa,CAAC;AAmBtE,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAM/C;AAgED;;0CAE0C;AAC1C,wBAAsB,uBAAuB,CAC3C,QAAQ,EAAE,iBAAiB,GAC1B,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,CA+B3C"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { gunzipSync } from 'node:zlib';
|
|
3
|
+
import * as tar from 'tar-stream';
|
|
4
|
+
import { resolveCredentials } from '../lib/client.js';
|
|
5
|
+
import { libraryUnavailableError, shortVersion } from './apps-template-catalog.js';
|
|
6
|
+
/**
|
|
7
|
+
* The project of a template version, as `parall app init --template`
|
|
8
|
+
* writes it (mini-app-template-registry-design.md §4, §8.2): the archive
|
|
9
|
+
* the library names, opened in memory and checked entry by entry against
|
|
10
|
+
* the project files the library lists — the same paths, each once, each
|
|
11
|
+
* with its sha256 and size — before anything is written. The archive is
|
|
12
|
+
* only a way to download those files; its own bytes are not checked.
|
|
13
|
+
*/
|
|
14
|
+
// A path a version may hold: plain relative segments, no `.` or `..`, as the
|
|
15
|
+
// server accepts them (apptemplate.ValidPath) — so no entry lands outside
|
|
16
|
+
// the project.
|
|
17
|
+
const SEGMENT = /^[A-Za-z0-9._@+-]+$/;
|
|
18
|
+
export function plainPath(path) {
|
|
19
|
+
return (path.length > 0 &&
|
|
20
|
+
path.length <= 512 &&
|
|
21
|
+
path.split('/').every((s) => SEGMENT.test(s) && s !== '.' && s !== '..'));
|
|
22
|
+
}
|
|
23
|
+
function sha256(bytes) {
|
|
24
|
+
return createHash('sha256').update(bytes).digest('hex');
|
|
25
|
+
}
|
|
26
|
+
/** The archive's entries but directories, in archive order (a repeated path
|
|
27
|
+
* kept). Throws when it is not a tar.gz, or is larger than maxBytes. */
|
|
28
|
+
async function readArchive(gz, maxBytes) {
|
|
29
|
+
const tarBytes = gunzipSync(gz, { maxOutputLength: maxBytes });
|
|
30
|
+
const entries = [];
|
|
31
|
+
const extract = tar.extract();
|
|
32
|
+
const done = new Promise((resolveDone, rejectDone) => {
|
|
33
|
+
extract.on('entry', (header, stream, next) => {
|
|
34
|
+
const chunks = [];
|
|
35
|
+
stream.on('data', (chunk) => chunks.push(chunk));
|
|
36
|
+
stream.on('end', () => {
|
|
37
|
+
const type = header.type ?? 'file';
|
|
38
|
+
if (type !== 'directory') {
|
|
39
|
+
entries.push({ path: header.name, type, body: Buffer.concat(chunks) });
|
|
40
|
+
}
|
|
41
|
+
next();
|
|
42
|
+
});
|
|
43
|
+
stream.on('error', rejectDone);
|
|
44
|
+
});
|
|
45
|
+
extract.on('finish', () => resolveDone());
|
|
46
|
+
extract.on('error', rejectDone);
|
|
47
|
+
});
|
|
48
|
+
extract.end(tarBytes);
|
|
49
|
+
await done;
|
|
50
|
+
return entries;
|
|
51
|
+
}
|
|
52
|
+
/** Why the entries are not the files listed, or undefined when they are. */
|
|
53
|
+
function mismatch(entries, files) {
|
|
54
|
+
const listed = new Map();
|
|
55
|
+
for (const file of files) {
|
|
56
|
+
if (!plainPath(file.path))
|
|
57
|
+
return `its file list names ${JSON.stringify(file.path)}`;
|
|
58
|
+
listed.set(file.path, file);
|
|
59
|
+
}
|
|
60
|
+
const seen = new Set();
|
|
61
|
+
for (const { path, type, body } of entries) {
|
|
62
|
+
if (type !== 'file')
|
|
63
|
+
return `it has ${path}, which is not a plain file`;
|
|
64
|
+
const file = listed.get(path);
|
|
65
|
+
if (!file)
|
|
66
|
+
return `it has ${path}, which the template's file list does not`;
|
|
67
|
+
if (seen.has(path))
|
|
68
|
+
return `it has ${path} twice`;
|
|
69
|
+
seen.add(path);
|
|
70
|
+
if (body.length !== file.size || sha256(body) !== file.sha256) {
|
|
71
|
+
return `${path} is not the file the template's file list names`;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const missing = [...listed.keys()].filter((path) => !seen.has(path));
|
|
75
|
+
return missing.length > 0 ? `it lacks ${missing.join(', ')}` : undefined;
|
|
76
|
+
}
|
|
77
|
+
/** A file's content: text as a string when it is UTF-8, else its bytes. */
|
|
78
|
+
function content(body) {
|
|
79
|
+
const text = body.toString('utf8');
|
|
80
|
+
return Buffer.from(text, 'utf8').equals(body) ? text : body;
|
|
81
|
+
}
|
|
82
|
+
/** The version's project, path → content, sorted by path, its app name
|
|
83
|
+
* still {{APP_NAME}}. Throws, having written nothing, when the download
|
|
84
|
+
* fails or is not the version's files. */
|
|
85
|
+
export async function downloadTemplateProject(template) {
|
|
86
|
+
const { client } = resolveCredentials();
|
|
87
|
+
let archive;
|
|
88
|
+
try {
|
|
89
|
+
archive = await client.getAppTemplateFile(template.project.archive);
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
throw libraryUnavailableError(err, { writes: true });
|
|
93
|
+
}
|
|
94
|
+
const files = template.project.files;
|
|
95
|
+
// Room for each entry's header and padding; anything bigger is not the
|
|
96
|
+
// project listed.
|
|
97
|
+
const maxBytes = files.reduce((sum, file) => sum + file.size, 0) + 4096 * (files.length + 4);
|
|
98
|
+
let problem;
|
|
99
|
+
let entries = [];
|
|
100
|
+
try {
|
|
101
|
+
entries = await readArchive(archive, maxBytes);
|
|
102
|
+
problem = mismatch(entries, files);
|
|
103
|
+
}
|
|
104
|
+
catch (err) {
|
|
105
|
+
problem =
|
|
106
|
+
err instanceof RangeError
|
|
107
|
+
? 'it is larger than its files'
|
|
108
|
+
: `its archive could not be read (${err.message})`;
|
|
109
|
+
}
|
|
110
|
+
if (problem) {
|
|
111
|
+
throw new Error(`The project of the ${template.id} template (version ${shortVersion(template.version)}) did not download intact: ${problem}. Nothing was written. Run the command again; if it keeps failing, tell the person the template cannot be used right now.`);
|
|
112
|
+
}
|
|
113
|
+
return entries
|
|
114
|
+
.map(({ path, body }) => [path, content(body)])
|
|
115
|
+
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
|
|
116
|
+
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import type { MiniAppPlacement } from '@parall/sdk';
|
|
2
|
-
import type { AppTemplate } from './apps-template-catalog.js';
|
|
1
|
+
import type { AppTemplateDetail, MiniAppPlacement } from '@parall/sdk';
|
|
3
2
|
/**
|
|
4
|
-
* `parall app init <dir> --template <id> --app <app_…>` (design §5.2
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
3
|
+
* `parall app init <dir> --template <id> --app <app_…>` (design §5.2,
|
|
4
|
+
* mini-app-template-registry-design.md §8.2): the project of the template's
|
|
5
|
+
* version in the library — the `--actions` scaffold with the template's
|
|
6
|
+
* reference source and blocks already laid together when it was packed —
|
|
7
|
+
* named after the directory, its skill as SKILL.md and a line in AGENTS.md
|
|
8
|
+
* pointing to it that names the version. The app is created first; its
|
|
8
9
|
* Database decides whether the template fits: the templates are written for
|
|
9
|
-
* PostgreSQL, so one on TiDB is refused before anything is written.
|
|
10
|
+
* PostgreSQL, so one on TiDB is refused before anything is read or written.
|
|
10
11
|
*/
|
|
11
12
|
/** The app a project is for (`init --app`) and where its Database keeps
|
|
12
13
|
* its data. */
|
|
@@ -17,32 +18,28 @@ export interface InitTarget {
|
|
|
17
18
|
}
|
|
18
19
|
export declare function resolveInitTarget(raw: string): Promise<InitTarget>;
|
|
19
20
|
/** Why the template cannot be used for this app, or undefined when it can. */
|
|
20
|
-
export declare function templateRefusal(
|
|
21
|
-
/**
|
|
22
|
-
export
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
export declare function templateProjectFiles(name: string, template: AppTemplate): Array<[string, string]>;
|
|
21
|
+
export declare function templateRefusal(id: string, target: InitTarget): string | undefined;
|
|
22
|
+
/** What init needs of a template: what the library answers for it. */
|
|
23
|
+
export type InitTemplate = Pick<AppTemplateDetail, 'id' | 'version' | 'skill'> & {
|
|
24
|
+
intro: {
|
|
25
|
+
name: string;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
28
|
/** The project with the template's skill as SKILL.md and, under the title
|
|
29
|
-
* of AGENTS.md, the line that points to it: what init writes
|
|
30
|
-
*
|
|
31
|
-
export declare function withTemplateSkill(project: ReadonlyArray<readonly [string,
|
|
32
|
-
/** The blocks the template names (_overlay.json `blocks`). */
|
|
33
|
-
export declare function templateBlocks(template: AppTemplate): string[];
|
|
29
|
+
* of AGENTS.md, the line that points to it: what init writes, sorted by
|
|
30
|
+
* path. */
|
|
31
|
+
export declare function withTemplateSkill<C extends string | Uint8Array>(project: ReadonlyArray<readonly [string, C]>, template: InitTemplate): Array<[string, C | string]>;
|
|
34
32
|
/**
|
|
35
|
-
* Writes the project to out (absent or empty): built beside it,
|
|
36
|
-
*
|
|
37
|
-
* nothing behind.
|
|
33
|
+
* Writes the project to out (absent or empty): built beside it, then moved
|
|
34
|
+
* into place — a write that fails partway leaves nothing behind.
|
|
38
35
|
*/
|
|
39
|
-
export declare function writeTemplateProject(out: string, files:
|
|
36
|
+
export declare function writeTemplateProject(out: string, files: ReadonlyArray<readonly [string, string | Uint8Array]>): Promise<void>;
|
|
40
37
|
/** What init prints when it is done. */
|
|
41
38
|
export declare function templateNextSteps(p: {
|
|
42
39
|
name: string;
|
|
43
40
|
dir: string;
|
|
44
41
|
out: string;
|
|
45
|
-
template:
|
|
42
|
+
template: InitTemplate;
|
|
46
43
|
target: InitTarget;
|
|
47
44
|
}): string;
|
|
48
45
|
//# sourceMappingURL=apps-template-init.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apps-template-init.d.ts","sourceRoot":"","sources":["../../src/commands/apps-template-init.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"apps-template-init.d.ts","sourceRoot":"","sources":["../../src/commands/apps-template-init.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAKvE;;;;;;;;;GASG;AAEH;eACe;AACf,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,gBAAgB,CAAC;CAC7B;AAED,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAYxE;AAED,8EAA8E;AAC9E,wBAAgB,eAAe,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,CAQlF;AAED,sEAAsE;AACtE,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,iBAAiB,EAAE,IAAI,GAAG,SAAS,GAAG,OAAO,CAAC,GAAG;IAC/E,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;CACzB,CAAC;AAaF;;WAEW;AACX,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,MAAM,GAAG,UAAU,EAC7D,OAAO,EAAE,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAC5C,QAAQ,EAAE,YAAY,GACrB,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAS7B;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAAC,CAAC,GAC3D,OAAO,CAAC,IAAI,CAAC,CAsBf;AAED,wCAAwC;AACxC,wBAAgB,iBAAiB,CAAC,CAAC,EAAE;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,YAAY,CAAC;IACvB,MAAM,EAAE,UAAU,CAAC;CACpB,GAAG,MAAM,CAcT"}
|