@meltemi/diagrams-cli 0.0.0-stage → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +58 -2
- package/dist/assets-command.d.ts +16 -0
- package/dist/assets-command.d.ts.map +1 -0
- package/dist/assets-command.js +145 -0
- package/dist/assets-command.js.map +1 -0
- package/dist/assist-command.d.ts +19 -0
- package/dist/assist-command.d.ts.map +1 -0
- package/dist/assist-command.js +268 -0
- package/dist/assist-command.js.map +1 -0
- package/dist/auth-command.d.ts +14 -0
- package/dist/auth-command.d.ts.map +1 -0
- package/dist/auth-command.js +233 -0
- package/dist/auth-command.js.map +1 -0
- package/dist/bin.d.ts +3 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +60 -0
- package/dist/bin.js.map +1 -0
- package/dist/build-command.d.ts +23 -0
- package/dist/build-command.d.ts.map +1 -0
- package/dist/build-command.js +123 -0
- package/dist/build-command.js.map +1 -0
- package/dist/cli.d.ts +46 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +823 -0
- package/dist/cli.js.map +1 -0
- package/dist/cloud-client.d.ts +246 -0
- package/dist/cloud-client.d.ts.map +1 -0
- package/dist/cloud-client.js +591 -0
- package/dist/cloud-client.js.map +1 -0
- package/dist/cloud-command.d.ts +56 -0
- package/dist/cloud-command.d.ts.map +1 -0
- package/dist/cloud-command.js +81 -0
- package/dist/cloud-command.js.map +1 -0
- package/dist/cloud-context.d.ts +106 -0
- package/dist/cloud-context.d.ts.map +1 -0
- package/dist/cloud-context.js +185 -0
- package/dist/cloud-context.js.map +1 -0
- package/dist/cloud-errors.d.ts +37 -0
- package/dist/cloud-errors.d.ts.map +1 -0
- package/dist/cloud-errors.js +46 -0
- package/dist/cloud-errors.js.map +1 -0
- package/dist/cloud-host.d.ts +72 -0
- package/dist/cloud-host.d.ts.map +1 -0
- package/dist/cloud-host.js +129 -0
- package/dist/cloud-host.js.map +1 -0
- package/dist/cloud-manifest.d.ts +12 -0
- package/dist/cloud-manifest.d.ts.map +1 -0
- package/dist/cloud-manifest.js +21 -0
- package/dist/cloud-manifest.js.map +1 -0
- package/dist/cloud-paths.d.ts +48 -0
- package/dist/cloud-paths.d.ts.map +1 -0
- package/dist/cloud-paths.js +104 -0
- package/dist/cloud-paths.js.map +1 -0
- package/dist/credentials.d.ts +107 -0
- package/dist/credentials.d.ts.map +1 -0
- package/dist/credentials.js +243 -0
- package/dist/credentials.js.map +1 -0
- package/dist/export-command.d.ts +35 -0
- package/dist/export-command.d.ts.map +1 -0
- package/dist/export-command.js +524 -0
- package/dist/export-command.js.map +1 -0
- package/dist/import-command.d.ts +20 -0
- package/dist/import-command.d.ts.map +1 -0
- package/dist/import-command.js +254 -0
- package/dist/import-command.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/init-command.d.ts +28 -0
- package/dist/init-command.d.ts.map +1 -0
- package/dist/init-command.js +199 -0
- package/dist/init-command.js.map +1 -0
- package/dist/login-listener.d.ts +58 -0
- package/dist/login-listener.d.ts.map +1 -0
- package/dist/login-listener.js +173 -0
- package/dist/login-listener.js.map +1 -0
- package/dist/messages/en.d.ts +533 -0
- package/dist/messages/en.d.ts.map +1 -0
- package/dist/messages/en.js +803 -0
- package/dist/messages/en.js.map +1 -0
- package/dist/messages/es.d.ts +3 -0
- package/dist/messages/es.d.ts.map +1 -0
- package/dist/messages/es.js +764 -0
- package/dist/messages/es.js.map +1 -0
- package/dist/messages/index.d.ts +442 -0
- package/dist/messages/index.d.ts.map +1 -0
- package/dist/messages/index.js +42 -0
- package/dist/messages/index.js.map +1 -0
- package/dist/messages/push-pull-en.d.ts +84 -0
- package/dist/messages/push-pull-en.d.ts.map +1 -0
- package/dist/messages/push-pull-en.js +146 -0
- package/dist/messages/push-pull-en.js.map +1 -0
- package/dist/messages/push-pull-es.d.ts +7 -0
- package/dist/messages/push-pull-es.d.ts.map +1 -0
- package/dist/messages/push-pull-es.js +144 -0
- package/dist/messages/push-pull-es.js.map +1 -0
- package/dist/open-url.d.ts +11 -0
- package/dist/open-url.d.ts.map +1 -0
- package/dist/open-url.js +36 -0
- package/dist/open-url.js.map +1 -0
- package/dist/plugins-command.d.ts +15 -0
- package/dist/plugins-command.d.ts.map +1 -0
- package/dist/plugins-command.js +106 -0
- package/dist/plugins-command.js.map +1 -0
- package/dist/preview.d.ts +54 -0
- package/dist/preview.d.ts.map +1 -0
- package/dist/preview.js +249 -0
- package/dist/preview.js.map +1 -0
- package/dist/project-errors.d.ts +17 -0
- package/dist/project-errors.d.ts.map +1 -0
- package/dist/project-errors.js +85 -0
- package/dist/project-errors.js.map +1 -0
- package/dist/projects-command.d.ts +13 -0
- package/dist/projects-command.d.ts.map +1 -0
- package/dist/projects-command.js +85 -0
- package/dist/projects-command.js.map +1 -0
- package/dist/publish-command.d.ts +41 -0
- package/dist/publish-command.d.ts.map +1 -0
- package/dist/publish-command.js +311 -0
- package/dist/publish-command.js.map +1 -0
- package/dist/pull-command.d.ts +21 -0
- package/dist/pull-command.d.ts.map +1 -0
- package/dist/pull-command.js +300 -0
- package/dist/pull-command.js.map +1 -0
- package/dist/push-command.d.ts +31 -0
- package/dist/push-command.d.ts.map +1 -0
- package/dist/push-command.js +391 -0
- package/dist/push-command.js.map +1 -0
- package/dist/push-review.d.ts +16 -0
- package/dist/push-review.d.ts.map +1 -0
- package/dist/push-review.js +72 -0
- package/dist/push-review.js.map +1 -0
- package/dist/push-set.d.ts +126 -0
- package/dist/push-set.d.ts.map +1 -0
- package/dist/push-set.js +289 -0
- package/dist/push-set.js.map +1 -0
- package/dist/push-validation.d.ts +20 -0
- package/dist/push-validation.d.ts.map +1 -0
- package/dist/push-validation.js +70 -0
- package/dist/push-validation.js.map +1 -0
- package/dist/redact.d.ts +9 -0
- package/dist/redact.d.ts.map +1 -0
- package/dist/redact.js +22 -0
- package/dist/redact.js.map +1 -0
- package/dist/review-command.d.ts +44 -0
- package/dist/review-command.d.ts.map +1 -0
- package/dist/review-command.js +348 -0
- package/dist/review-command.js.map +1 -0
- package/package.json +56 -3
- package/templates/c4/diagrams/views.meltemi +16 -0
- package/templates/c4/models/system.meltemi +23 -0
- package/templates/ci/github.yml +96 -0
- package/templates/ci/gitlab.yml +53 -0
- package/templates/flow/diagrams/overview.meltemi +15 -0
- package/templates/free/diagrams/slide.meltemi +39 -0
- package/templates/purchase/diagrams/architecture.meltemi +36 -0
- package/templates/purchase/diagrams/executive.meltemi +52 -0
- package/templates/purchase/diagrams/payment.meltemi +42 -0
- package/templates/purchase/models/commerce.meltemi +30 -0
- package/templates/purchase/stories/purchase.meltemi +38 -0
- package/templates/sequence/diagrams/sign-in.meltemi +36 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The cloud commands (`cli-cloud`): one table of names to commands, and the dispatcher that gives
|
|
3
|
+
* each the same context, keeps tokens out of everything it prints and turns a `CloudError` into a
|
|
4
|
+
* line on standard error and an exit code (1, or 3 when the person has to run `login`).
|
|
5
|
+
*
|
|
6
|
+
* Adding a command is a file with a `CloudCommand` (`cloud-context.ts` has the helpers: `openCloud`
|
|
7
|
+
* for the host, the token and the client, `usageError`) and one line in `CLOUD_COMMANDS`; `cli.ts`
|
|
8
|
+
* and the help need nothing else but the words in `messages/`.
|
|
9
|
+
*/
|
|
10
|
+
import type { Locale } from "@meltemi/diagrams-i18n";
|
|
11
|
+
import { type CloudCommand, type CloudContext, type CloudHooks } from "./cloud-context.js";
|
|
12
|
+
/** The cloud commands by name. */
|
|
13
|
+
declare const CLOUD_COMMANDS: {
|
|
14
|
+
readonly login: CloudCommand;
|
|
15
|
+
readonly push: CloudCommand;
|
|
16
|
+
readonly pull: CloudCommand;
|
|
17
|
+
readonly logout: CloudCommand;
|
|
18
|
+
readonly whoami: CloudCommand;
|
|
19
|
+
readonly projects: CloudCommand;
|
|
20
|
+
readonly publish: CloudCommand;
|
|
21
|
+
};
|
|
22
|
+
export type CloudCommandName = keyof typeof CLOUD_COMMANDS;
|
|
23
|
+
/** The names of the cloud commands. */
|
|
24
|
+
export declare const CLOUD_COMMAND_NAMES: CloudCommandName[];
|
|
25
|
+
/** Whether a command name is one of the cloud commands. */
|
|
26
|
+
export declare function isCloudCommand(name: string): name is CloudCommandName;
|
|
27
|
+
/** What the dispatcher needs from the command line: its streams, its environment and its hooks. */
|
|
28
|
+
export interface CloudCommandIo {
|
|
29
|
+
/** The command line's name, `meltemi-diagrams`. */
|
|
30
|
+
readonly name: string;
|
|
31
|
+
readonly stdout: (text: string) => void;
|
|
32
|
+
readonly stderr: (text: string) => void;
|
|
33
|
+
readonly cwd: string;
|
|
34
|
+
readonly display: (path: string) => string;
|
|
35
|
+
readonly toolVersion: string;
|
|
36
|
+
readonly env?: Readonly<Record<string, string | undefined>> | undefined;
|
|
37
|
+
readonly ask?: ((question: string) => Promise<string>) | undefined;
|
|
38
|
+
readonly stdin?: (() => Promise<string>) | undefined;
|
|
39
|
+
readonly cloud?: CloudHooks | undefined;
|
|
40
|
+
/** The language of the files a command writes: `--lang`, when given (never the machine's). */
|
|
41
|
+
readonly locale?: Locale | undefined;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The context of a command, from the command line's streams and environment: its output goes
|
|
45
|
+
* through `redactSecrets`, so a token that an answer, a file or an error carried is shown as
|
|
46
|
+
* `mdg_…`. `cloudCommand` makes one for each cloud command; a command that is not one of them but
|
|
47
|
+
* talks to the service (`review --base cloud`) makes its own with `command` set to its name.
|
|
48
|
+
*/
|
|
49
|
+
export declare function cloudContext(command: string, io: CloudCommandIo): CloudContext;
|
|
50
|
+
/**
|
|
51
|
+
* Runs a cloud command. A `CloudError` it throws is printed as `<name> <command>: <code>: <sentence>`
|
|
52
|
+
* on standard error (`reportCloudError`) and its exit code is returned.
|
|
53
|
+
*/
|
|
54
|
+
export declare function cloudCommand(command: CloudCommandName, args: readonly string[], io: CloudCommandIo): Promise<number>;
|
|
55
|
+
export {};
|
|
56
|
+
//# sourceMappingURL=cloud-command.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloud-command.d.ts","sourceRoot":"","sources":["../src/cloud-command.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAErD,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,UAAU,EAChB,MAAM,oBAAoB,CAAC;AAS5B,kCAAkC;AAClC,QAAA,MAAM,cAAc;;;;;;;;CAQuC,CAAC;AAE5D,MAAM,MAAM,gBAAgB,GAAG,MAAM,OAAO,cAAc,CAAC;AAE3D,uCAAuC;AACvC,eAAO,MAAM,mBAAmB,EAAkC,gBAAgB,EAAE,CAAC;AAErF,2DAA2D;AAC3D,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,gBAAgB,CAErE;AAED,mGAAmG;AACnG,MAAM,WAAW,cAAc;IAC7B,mDAAmD;IACnD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,QAAQ,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IAC3C,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,GAAG,SAAS,CAAC;IACxE,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,SAAS,CAAC;IACnE,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,SAAS,CAAC;IACrD,QAAQ,CAAC,KAAK,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;IACxC,8FAA8F;IAC9F,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACtC;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,cAAc,GAAG,YAAY,CAyB9E;AAED;;;GAGG;AACH,wBAAsB,YAAY,CAChC,OAAO,EAAE,gBAAgB,EACzB,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,EAAE,EAAE,cAAc,GACjB,OAAO,CAAC,MAAM,CAAC,CAQjB"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The cloud commands (`cli-cloud`): one table of names to commands, and the dispatcher that gives
|
|
3
|
+
* each the same context, keeps tokens out of everything it prints and turns a `CloudError` into a
|
|
4
|
+
* line on standard error and an exit code (1, or 3 when the person has to run `login`).
|
|
5
|
+
*
|
|
6
|
+
* Adding a command is a file with a `CloudCommand` (`cloud-context.ts` has the helpers: `openCloud`
|
|
7
|
+
* for the host, the token and the client, `usageError`) and one line in `CLOUD_COMMANDS`; `cli.ts`
|
|
8
|
+
* and the help need nothing else but the words in `messages/`.
|
|
9
|
+
*/
|
|
10
|
+
import { loginCommand, logoutCommand, whoamiCommand } from "./auth-command.js";
|
|
11
|
+
import { reportCloudError, } from "./cloud-context.js";
|
|
12
|
+
import { CloudError } from "./cloud-errors.js";
|
|
13
|
+
import { CredentialsStore } from "./credentials.js";
|
|
14
|
+
import { projectsCommand } from "./projects-command.js";
|
|
15
|
+
import { publishCommand } from "./publish-command.js";
|
|
16
|
+
import { pullCommand } from "./pull-command.js";
|
|
17
|
+
import { pushCommand } from "./push-command.js";
|
|
18
|
+
import { redactSecrets } from "./redact.js";
|
|
19
|
+
/** The cloud commands by name. */
|
|
20
|
+
const CLOUD_COMMANDS = {
|
|
21
|
+
login: loginCommand,
|
|
22
|
+
push: pushCommand,
|
|
23
|
+
pull: pullCommand,
|
|
24
|
+
logout: logoutCommand,
|
|
25
|
+
whoami: whoamiCommand,
|
|
26
|
+
projects: projectsCommand,
|
|
27
|
+
publish: publishCommand,
|
|
28
|
+
};
|
|
29
|
+
/** The names of the cloud commands. */
|
|
30
|
+
export const CLOUD_COMMAND_NAMES = Object.keys(CLOUD_COMMANDS);
|
|
31
|
+
/** Whether a command name is one of the cloud commands. */
|
|
32
|
+
export function isCloudCommand(name) {
|
|
33
|
+
return Object.hasOwn(CLOUD_COMMANDS, name);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The context of a command, from the command line's streams and environment: its output goes
|
|
37
|
+
* through `redactSecrets`, so a token that an answer, a file or an error carried is shown as
|
|
38
|
+
* `mdg_…`. `cloudCommand` makes one for each cloud command; a command that is not one of them but
|
|
39
|
+
* talks to the service (`review --base cloud`) makes its own with `command` set to its name.
|
|
40
|
+
*/
|
|
41
|
+
export function cloudContext(command, io) {
|
|
42
|
+
const env = io.env ?? process.env;
|
|
43
|
+
const hooks = io.cloud ?? {};
|
|
44
|
+
const clean = (write) => (text) => write(redactSecrets(text, env));
|
|
45
|
+
return {
|
|
46
|
+
name: io.name,
|
|
47
|
+
command,
|
|
48
|
+
stdout: clean(io.stdout),
|
|
49
|
+
stderr: clean(io.stderr),
|
|
50
|
+
cwd: io.cwd,
|
|
51
|
+
display: io.display,
|
|
52
|
+
env,
|
|
53
|
+
toolVersion: io.toolVersion,
|
|
54
|
+
...(io.ask ? { ask: io.ask } : {}),
|
|
55
|
+
...(io.stdin ? { stdin: io.stdin } : {}),
|
|
56
|
+
...(io.locale ? { locale: io.locale } : {}),
|
|
57
|
+
hooks,
|
|
58
|
+
credentials: new CredentialsStore({
|
|
59
|
+
env,
|
|
60
|
+
...(hooks.platform ? { platform: hooks.platform } : {}),
|
|
61
|
+
...(hooks.home ? { home: hooks.home } : {}),
|
|
62
|
+
}),
|
|
63
|
+
used: {},
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Runs a cloud command. A `CloudError` it throws is printed as `<name> <command>: <code>: <sentence>`
|
|
68
|
+
* on standard error (`reportCloudError`) and its exit code is returned.
|
|
69
|
+
*/
|
|
70
|
+
export async function cloudCommand(command, args, io) {
|
|
71
|
+
const context = cloudContext(command, io);
|
|
72
|
+
try {
|
|
73
|
+
return await CLOUD_COMMANDS[command](args, context);
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
if (error instanceof CloudError)
|
|
77
|
+
return reportCloudError(error, context);
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=cloud-command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloud-command.js","sourceRoot":"","sources":["../src/cloud-command.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,EACL,gBAAgB,GAIjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,kCAAkC;AAClC,MAAM,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,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACxC,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3C,KAAK;QACL,WAAW,EAAE,IAAI,gBAAgB,CAAC;YAChC,GAAG;YACH,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACvD,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC5C,CAAC;QACF,IAAI,EAAE,EAAE;KACT,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,OAAyB,EACzB,IAAuB,EACvB,EAAkB;IAElB,MAAM,OAAO,GAAG,YAAY,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAC1C,IAAI,CAAC;QACH,OAAO,MAAM,cAAc,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACtD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,UAAU;YAAE,OAAO,gBAAgB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACzE,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What every cloud command shares (`cli-cloud`): the context the dispatcher gives it, the way it
|
|
3
|
+
* finds its host and its token, how it reports a usage error, and how a failure reads in the
|
|
4
|
+
* interface language. A command is `(args, context) => Promise<number>` in a file of its own,
|
|
5
|
+
* registered in `cloud-command.ts`.
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* export const pushCommand: CloudCommand = async (args, context) => {
|
|
9
|
+
* const { values, positionals } = parseArgs(...); // usageError(context, error, help) on a throw
|
|
10
|
+
* const { host, client } = openCloud(context, { host: values.host, manifestHost: manifest.cloud?.host });
|
|
11
|
+
* const files = await client.files(projectId);
|
|
12
|
+
* ...
|
|
13
|
+
* return EXIT_OK;
|
|
14
|
+
* };
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* A command reports a failure by throwing a `CloudError` (`cloud-errors.ts`); the dispatcher prints
|
|
18
|
+
* it as `<name> <command>: <code>: <sentence>` on standard error and exits with the error's code.
|
|
19
|
+
*/
|
|
20
|
+
import type { Locale } from "@meltemi/diagrams-i18n";
|
|
21
|
+
import { CloudClient, type Fetch } from "./cloud-client.js";
|
|
22
|
+
import { CloudError } from "./cloud-errors.js";
|
|
23
|
+
import { CredentialsStore, type ResolvedToken } from "./credentials.js";
|
|
24
|
+
/** What a test replaces: the network, the browser, the clock of the wait, the configuration folder. */
|
|
25
|
+
export interface CloudHooks {
|
|
26
|
+
/** Replaces `fetch`. */
|
|
27
|
+
readonly fetch?: Fetch;
|
|
28
|
+
/** Opens an address in the browser; rejects when it cannot. */
|
|
29
|
+
readonly openBrowser?: (url: string) => Promise<void> | void;
|
|
30
|
+
/** Milliseconds `login` waits for the approval; five minutes by default. */
|
|
31
|
+
readonly loginTimeoutMs?: number;
|
|
32
|
+
/** The platform and home folder the credentials folder is derived from. */
|
|
33
|
+
readonly platform?: NodeJS.Platform;
|
|
34
|
+
readonly home?: string;
|
|
35
|
+
}
|
|
36
|
+
export interface CloudContext {
|
|
37
|
+
/** The command line's name, `meltemi-diagrams`, for messages that name a command to run. */
|
|
38
|
+
readonly name: string;
|
|
39
|
+
/** The cloud command being run: `login`, `push`, … */
|
|
40
|
+
readonly command: string;
|
|
41
|
+
/** Output, with API tokens already replaced by `mdg_…`. */
|
|
42
|
+
readonly stdout: (text: string) => void;
|
|
43
|
+
readonly stderr: (text: string) => void;
|
|
44
|
+
readonly cwd: string;
|
|
45
|
+
/** A path as printed: relative to the working folder. */
|
|
46
|
+
readonly display: (path: string) => string;
|
|
47
|
+
readonly env: Readonly<Record<string, string | undefined>>;
|
|
48
|
+
readonly toolVersion: string;
|
|
49
|
+
/** Asks a question in a terminal; absent when nobody can answer (then refuse unless `--force`). */
|
|
50
|
+
readonly ask?: (question: string) => Promise<string>;
|
|
51
|
+
/** Reads standard input (for `login --token`); absent when the host gave none. */
|
|
52
|
+
readonly stdin?: () => Promise<string>;
|
|
53
|
+
/** The language of the files the command writes: `--lang`, when given (never the machine's). */
|
|
54
|
+
readonly locale?: Locale;
|
|
55
|
+
readonly hooks: CloudHooks;
|
|
56
|
+
readonly credentials: CredentialsStore;
|
|
57
|
+
/** What the command has settled on so far, so that a failure can name it. */
|
|
58
|
+
readonly used: {
|
|
59
|
+
host?: string;
|
|
60
|
+
project?: string;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/** A cloud command: its arguments after its name, and the exit code. */
|
|
64
|
+
export type CloudCommand = (args: readonly string[], context: CloudContext) => Promise<number>;
|
|
65
|
+
/** A client for a host, with the token given (none for the calls that need none). */
|
|
66
|
+
export declare function newClient(context: CloudContext, host: string, token?: string): CloudClient;
|
|
67
|
+
/**
|
|
68
|
+
* The host of a command: `--host`, else `MELTEMI_HOST`, else the default (never a manifest's). When
|
|
69
|
+
* `manifestHost` is given (`project.json`'s `cloud.host`) and is another host, it fails with
|
|
70
|
+
* `cloud.host-mismatch` before anything is sent.
|
|
71
|
+
*/
|
|
72
|
+
export declare function cloudHost(context: CloudContext, options?: {
|
|
73
|
+
readonly host?: string | undefined;
|
|
74
|
+
readonly manifestHost?: string | null | undefined;
|
|
75
|
+
}): string;
|
|
76
|
+
/** A command's connection to the service. */
|
|
77
|
+
export interface CloudSession {
|
|
78
|
+
readonly host: string;
|
|
79
|
+
readonly client: CloudClient;
|
|
80
|
+
/** Where the token came from (`MELTEMI_TOKEN`, or the credentials file). */
|
|
81
|
+
readonly token: ResolvedToken;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The host and a client with its token, for a command that needs to be signed in: resolves the host
|
|
85
|
+
* (`cloudHost`), then the token (`MELTEMI_TOKEN`, else the stored entry for that host); with none,
|
|
86
|
+
* `cloud.not-signed-in` (exit code 3, "run login"). Nothing has been sent when it returns or throws.
|
|
87
|
+
*/
|
|
88
|
+
export declare function openCloud(context: CloudContext, options?: {
|
|
89
|
+
readonly host?: string | undefined;
|
|
90
|
+
readonly manifestHost?: string | null | undefined;
|
|
91
|
+
}): CloudSession;
|
|
92
|
+
/** Prints a usage error with the command's usage, and the exit code 2 (`parseArgs` threw). */
|
|
93
|
+
export declare function usageError(context: CloudContext, error: unknown, help: string): number;
|
|
94
|
+
/** Prints a usage message with the command's usage, and the exit code 2. */
|
|
95
|
+
export declare function usage(context: CloudContext, message: string, help: string): number;
|
|
96
|
+
/**
|
|
97
|
+
* Prints a failure on standard error as `<name> <command>: <code>: <sentence>` and answers the exit
|
|
98
|
+
* code it carries (3 when the person has to run `login`, else 1).
|
|
99
|
+
*/
|
|
100
|
+
export declare function reportCloudError(error: CloudError, context: CloudContext): number;
|
|
101
|
+
/**
|
|
102
|
+
* A failure as a person reads it: the stable code, then a sentence in the interface language when
|
|
103
|
+
* the code is one the command line knows, else the service's own English message.
|
|
104
|
+
*/
|
|
105
|
+
export declare function describeCloudError(error: CloudError, context: CloudContext): string;
|
|
106
|
+
//# sourceMappingURL=cloud-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloud-context.d.ts","sourceRoot":"","sources":["../src/cloud-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAGrD,OAAO,EAAE,WAAW,EAAE,KAAK,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC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IACnC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;CAC9C,GACL,YAAY,CASd;AAED,8FAA8F;AAC9F,wBAAgB,UAAU,CAAC,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAEtF;AAED,4EAA4E;AAC5E,wBAAgB,KAAK,CAAC,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAGlF;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,GAAG,MAAM,CAGjF;AAMD;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,GAAG,MAAM,CAwGnF"}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What every cloud command shares (`cli-cloud`): the context the dispatcher gives it, the way it
|
|
3
|
+
* finds its host and its token, how it reports a usage error, and how a failure reads in the
|
|
4
|
+
* interface language. A command is `(args, context) => Promise<number>` in a file of its own,
|
|
5
|
+
* registered in `cloud-command.ts`.
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* export const pushCommand: CloudCommand = async (args, context) => {
|
|
9
|
+
* const { values, positionals } = parseArgs(...); // usageError(context, error, help) on a throw
|
|
10
|
+
* const { host, client } = openCloud(context, { host: values.host, manifestHost: manifest.cloud?.host });
|
|
11
|
+
* const files = await client.files(projectId);
|
|
12
|
+
* ...
|
|
13
|
+
* return EXIT_OK;
|
|
14
|
+
* };
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* A command reports a failure by throwing a `CloudError` (`cloud-errors.ts`); the dispatcher prints
|
|
18
|
+
* it as `<name> <command>: <code>: <sentence>` on standard error and exits with the error's code.
|
|
19
|
+
*/
|
|
20
|
+
import { formatSize } from "./build-command.js";
|
|
21
|
+
import { argumentsError, messages } from "./messages/index.js";
|
|
22
|
+
import { CloudClient } from "./cloud-client.js";
|
|
23
|
+
import { CloudError, EXIT_USAGE } from "./cloud-errors.js";
|
|
24
|
+
import { describeProjectError } from "./project-errors.js";
|
|
25
|
+
import { CredentialsStore, checkManifestHost, resolveHost, } from "./credentials.js";
|
|
26
|
+
/** A client for a host, with the token given (none for the calls that need none). */
|
|
27
|
+
export function newClient(context, host, token) {
|
|
28
|
+
return new CloudClient({
|
|
29
|
+
host,
|
|
30
|
+
token,
|
|
31
|
+
userAgent: `${context.name}/${context.toolVersion}`,
|
|
32
|
+
...(context.hooks.fetch ? { fetch: context.hooks.fetch } : {}),
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The host of a command: `--host`, else `MELTEMI_HOST`, else the default (never a manifest's). When
|
|
37
|
+
* `manifestHost` is given (`project.json`'s `cloud.host`) and is another host, it fails with
|
|
38
|
+
* `cloud.host-mismatch` before anything is sent.
|
|
39
|
+
*/
|
|
40
|
+
export function cloudHost(context, options = {}) {
|
|
41
|
+
const host = resolveHost({ flag: options.host, env: context.env });
|
|
42
|
+
context.used.host = host;
|
|
43
|
+
checkManifestHost(host, options.manifestHost);
|
|
44
|
+
return host;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The host and a client with its token, for a command that needs to be signed in: resolves the host
|
|
48
|
+
* (`cloudHost`), then the token (`MELTEMI_TOKEN`, else the stored entry for that host); with none,
|
|
49
|
+
* `cloud.not-signed-in` (exit code 3, "run login"). Nothing has been sent when it returns or throws.
|
|
50
|
+
*/
|
|
51
|
+
export function openCloud(context, options = {}) {
|
|
52
|
+
const host = cloudHost(context, options);
|
|
53
|
+
const token = context.credentials.resolveToken(host, context.env);
|
|
54
|
+
if (token === undefined) {
|
|
55
|
+
throw new CloudError("cloud.not-signed-in", `There is no token for ${host}.`, {
|
|
56
|
+
details: { host },
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return { host, client: newClient(context, host, token.token), token };
|
|
60
|
+
}
|
|
61
|
+
/** Prints a usage error with the command's usage, and the exit code 2 (`parseArgs` threw). */
|
|
62
|
+
export function usageError(context, error, help) {
|
|
63
|
+
return usage(context, argumentsError(error), help);
|
|
64
|
+
}
|
|
65
|
+
/** Prints a usage message with the command's usage, and the exit code 2. */
|
|
66
|
+
export function usage(context, message, help) {
|
|
67
|
+
context.stderr(`${context.name} ${context.command}: ${message}\n\n${help}`);
|
|
68
|
+
return EXIT_USAGE;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Prints a failure on standard error as `<name> <command>: <code>: <sentence>` and answers the exit
|
|
72
|
+
* code it carries (3 when the person has to run `login`, else 1).
|
|
73
|
+
*/
|
|
74
|
+
export function reportCloudError(error, context) {
|
|
75
|
+
context.stderr(`${context.name} ${context.command}: ${describeCloudError(error, context)}\n`);
|
|
76
|
+
return error.exitCode;
|
|
77
|
+
}
|
|
78
|
+
/** What a `details` entry is, as text. */
|
|
79
|
+
const text = (value, fallback) => typeof value === "string" && value !== "" ? value : fallback;
|
|
80
|
+
/**
|
|
81
|
+
* A failure as a person reads it: the stable code, then a sentence in the interface language when
|
|
82
|
+
* the code is one the command line knows, else the service's own English message.
|
|
83
|
+
*/
|
|
84
|
+
export function describeCloudError(error, context) {
|
|
85
|
+
const t = messages().cloud.errors;
|
|
86
|
+
const host = text(error.details["host"], context.used.host ?? "the service");
|
|
87
|
+
const path = text(error.details["path"], "");
|
|
88
|
+
const reason = text(error.details["reason"], error.message);
|
|
89
|
+
const sentence = (() => {
|
|
90
|
+
switch (error.code) {
|
|
91
|
+
case "cloud.host-mismatch":
|
|
92
|
+
return t.hostMismatch(text(error.details["manifestHost"], "?"), host);
|
|
93
|
+
case "cloud.insecure-host":
|
|
94
|
+
return t.insecureHost(host);
|
|
95
|
+
case "cloud.host-invalid":
|
|
96
|
+
return t.hostInvalid(host);
|
|
97
|
+
case "cloud.unreachable":
|
|
98
|
+
return t.unreachable(host, reason);
|
|
99
|
+
case "cloud.timeout":
|
|
100
|
+
return t.timeout(host);
|
|
101
|
+
case "cloud.response-too-large":
|
|
102
|
+
return t.tooLarge(host);
|
|
103
|
+
case "cloud.redirect":
|
|
104
|
+
return t.redirect(host, error.status);
|
|
105
|
+
case "cloud.bad-response":
|
|
106
|
+
return t.badResponse(host, error.status);
|
|
107
|
+
case "cloud.not-signed-in":
|
|
108
|
+
return t.notSignedIn(context.name, host);
|
|
109
|
+
case "token.invalid":
|
|
110
|
+
case "auth.required":
|
|
111
|
+
return t.tokenRefused(context.name, host);
|
|
112
|
+
case "credentials.corrupt":
|
|
113
|
+
return t.credentialsCorrupt(path, reason);
|
|
114
|
+
case "credentials.unreadable":
|
|
115
|
+
return t.credentialsUnreadable(path, reason);
|
|
116
|
+
case "credentials.unwritable":
|
|
117
|
+
return t.credentialsUnwritable(path, reason);
|
|
118
|
+
case "cli.invalid":
|
|
119
|
+
return t.cliInvalid;
|
|
120
|
+
case "cli.rate":
|
|
121
|
+
return t.cliRate(error.retryAfter ?? 60);
|
|
122
|
+
case "quota.tokens":
|
|
123
|
+
return t.quotaTokens;
|
|
124
|
+
case "login.timeout":
|
|
125
|
+
return t.loginTimeout;
|
|
126
|
+
case "login.state-mismatch":
|
|
127
|
+
return t.stateMismatch;
|
|
128
|
+
case "login.environment-token":
|
|
129
|
+
return t.environmentToken;
|
|
130
|
+
case "login.token-input":
|
|
131
|
+
return t.tokenInput;
|
|
132
|
+
case "login.no-token":
|
|
133
|
+
return t.noToken;
|
|
134
|
+
case "login.not-a-token":
|
|
135
|
+
return t.notAToken;
|
|
136
|
+
case "login.not-stored":
|
|
137
|
+
return t.notStored(reason);
|
|
138
|
+
case "login.not-stored-not-revoked":
|
|
139
|
+
return t.notStoredNotRevoked(reason);
|
|
140
|
+
case "login.listener":
|
|
141
|
+
return t.listener(reason);
|
|
142
|
+
case "logout.not-revoked":
|
|
143
|
+
return t.notRevoked(host, reason, path);
|
|
144
|
+
case "cloud.no-project":
|
|
145
|
+
return t.noProject(context.name);
|
|
146
|
+
case "pull.unsafe-path":
|
|
147
|
+
return t.unsafePath(path);
|
|
148
|
+
case "version.not-found":
|
|
149
|
+
return t.versionNotFound(text(String(error.details["version"] ?? ""), "that was asked for"));
|
|
150
|
+
case "project.not-found":
|
|
151
|
+
return t.projectNotFound(text(error.details["project"], context.used.project ?? "?"));
|
|
152
|
+
case "access.denied":
|
|
153
|
+
return t.accessDenied;
|
|
154
|
+
case "handle.taken":
|
|
155
|
+
return t.handleTaken(text(error.details["handle"], "chosen"));
|
|
156
|
+
case "handle.locked":
|
|
157
|
+
// The handle the account has, which cannot change; else the one asked for.
|
|
158
|
+
return t.handleLocked(text(error.details["current"], text(error.details["handle"], "?")));
|
|
159
|
+
case "handle.invalid":
|
|
160
|
+
return t.handleInvalid(text(error.details["handle"], "that"));
|
|
161
|
+
case "handle.required":
|
|
162
|
+
return t.handleRequired(context.name);
|
|
163
|
+
case "publish.handle-in-page":
|
|
164
|
+
return t.handleInPage(text(error.details["handle"], "you want"));
|
|
165
|
+
case "publish.too-large":
|
|
166
|
+
return t.publishTooLarge(typeof error.details["bytes"] === "number"
|
|
167
|
+
? formatSize(error.details["bytes"])
|
|
168
|
+
: undefined);
|
|
169
|
+
case "publish.rate":
|
|
170
|
+
return t.publishRate(error.retryAfter ?? 3600);
|
|
171
|
+
case "publish.taken":
|
|
172
|
+
return t.publishTaken(text(error.details["slug"], "that name"));
|
|
173
|
+
case "publish.not-published":
|
|
174
|
+
return t.notPublished(text(error.details["slug"], "that name"));
|
|
175
|
+
case "publish.empty":
|
|
176
|
+
return t.publishEmpty;
|
|
177
|
+
case "publish.errors":
|
|
178
|
+
return t.publishErrors;
|
|
179
|
+
default:
|
|
180
|
+
return describeProjectError(error) ?? error.message;
|
|
181
|
+
}
|
|
182
|
+
})();
|
|
183
|
+
return `${error.code}: ${sentence}`;
|
|
184
|
+
}
|
|
185
|
+
//# sourceMapp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C,OAAO,CAAC;QACxD,CAAC;IACH,CAAC,CAAC,EAAE,CAAC;IACL,OAAO,GAAG,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The failures of the cloud commands (`cli-cloud`): one typed error for the service's answers, for
|
|
3
|
+
* what the command line refuses before it asks, and for the credentials file. The `code` is the
|
|
4
|
+
* stable name (the service's own for an answer, `cloud.*`, `credentials.*` and `login.*` for the
|
|
5
|
+
* command line's); the `message` is English, never holds a token, and is what an unknown code is
|
|
6
|
+
* printed with. `describeCloudError` (`cloud-command.ts`) turns the known codes into the
|
|
7
|
+
* interface language.
|
|
8
|
+
*/
|
|
9
|
+
/** Exit codes of the cloud commands: 0 done, 1 failed, 2 usage error, 3 sign in. */
|
|
10
|
+
export declare const EXIT_OK = 0;
|
|
11
|
+
export declare const EXIT_FAILED = 1;
|
|
12
|
+
export declare const EXIT_USAGE = 2;
|
|
13
|
+
/** Not signed in, or the service refused the token: run `mdg login`. */
|
|
14
|
+
export declare const EXIT_AUTH = 3;
|
|
15
|
+
export interface CloudErrorOptions {
|
|
16
|
+
/** The HTTP status of the service's answer; 0 when there was none or the refusal is local. */
|
|
17
|
+
readonly status?: number;
|
|
18
|
+
/** What the code carries: the room's `revision` of a `revision.mismatch`, a host, a path. */
|
|
19
|
+
readonly details?: Readonly<Record<string, unknown>>;
|
|
20
|
+
/** Seconds the service asked to wait (`Retry-After`). */
|
|
21
|
+
readonly retryAfter?: number;
|
|
22
|
+
/** Overrides the exit code the code implies (3 for the sign-in codes, else 1). */
|
|
23
|
+
readonly exitCode?: number;
|
|
24
|
+
}
|
|
25
|
+
export declare class CloudError extends Error {
|
|
26
|
+
readonly code: string;
|
|
27
|
+
readonly status: number;
|
|
28
|
+
readonly details: Readonly<Record<string, unknown>>;
|
|
29
|
+
readonly retryAfter: number | undefined;
|
|
30
|
+
readonly exitCode: number;
|
|
31
|
+
constructor(code: string, message: string, options?: CloudErrorOptions);
|
|
32
|
+
/** The room's revision a `revision.mismatch` carries, when it is a number. */
|
|
33
|
+
get revision(): number | undefined;
|
|
34
|
+
}
|
|
35
|
+
/** Whether an error is a `CloudError`, with the code given when there is one. */
|
|
36
|
+
export declare function isCloudError(error: unknown, code?: string): error is CloudError;
|
|
37
|
+
//# sourceMappingURL=cloud-errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloud-errors.d.ts","sourceRoot":"","sources":["../src/cloud-errors.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,oFAAoF;AACpF,eAAO,MAAM,OAAO,IAAI,CAAC;AACzB,eAAO,MAAM,WAAW,IAAI,CAAC;AAC7B,eAAO,MAAM,UAAU,IAAI,CAAC;AAC5B,wEAAwE;AACxE,eAAO,MAAM,SAAS,IAAI,CAAC;AAS3B,MAAM,WAAW,iBAAiB;IAChC,8FAA8F;IAC9F,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,6FAA6F;IAC7F,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACrD,yDAAyD;IACzD,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,kFAAkF;IAClF,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,qBAAa,UAAW,SAAQ,KAAK;IAOjC,QAAQ,CAAC,IAAI,EAAE,MAAM;IANvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACpD,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IACxC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;gBAGf,IAAI,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,iBAAsB;IAUjC,8EAA8E;IAC9E,IAAI,QAAQ,IAAI,MAAM,GAAG,SAAS,CAGjC;CACF;AAED,iFAAiF;AACjF,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,KAAK,IAAI,UAAU,CAE/E"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The failures of the cloud commands (`cli-cloud`): one typed error for the service's answers, for
|
|
3
|
+
* what the command line refuses before it asks, and for the credentials file. The `code` is the
|
|
4
|
+
* stable name (the service's own for an answer, `cloud.*`, `credentials.*` and `login.*` for the
|
|
5
|
+
* command line's); the `message` is English, never holds a token, and is what an unknown code is
|
|
6
|
+
* printed with. `describeCloudError` (`cloud-command.ts`) turns the known codes into the
|
|
7
|
+
* interface language.
|
|
8
|
+
*/
|
|
9
|
+
/** Exit codes of the cloud commands: 0 done, 1 failed, 2 usage error, 3 sign in. */
|
|
10
|
+
export const EXIT_OK = 0;
|
|
11
|
+
export const EXIT_FAILED = 1;
|
|
12
|
+
export const EXIT_USAGE = 2;
|
|
13
|
+
/** Not signed in, or the service refused the token: run `mdg login`. */
|
|
14
|
+
export const EXIT_AUTH = 3;
|
|
15
|
+
/** Codes that mean the person has to sign in: the service's two and the command line's own. */
|
|
16
|
+
const AUTH_CODES = new Set([
|
|
17
|
+
"token.invalid",
|
|
18
|
+
"auth.required",
|
|
19
|
+
"cloud.not-signed-in",
|
|
20
|
+
]);
|
|
21
|
+
export class CloudError extends Error {
|
|
22
|
+
code;
|
|
23
|
+
status;
|
|
24
|
+
details;
|
|
25
|
+
retryAfter;
|
|
26
|
+
exitCode;
|
|
27
|
+
constructor(code, message, options = {}) {
|
|
28
|
+
super(message);
|
|
29
|
+
this.code = code;
|
|
30
|
+
this.name = "CloudError";
|
|
31
|
+
this.status = options.status ?? 0;
|
|
32
|
+
this.details = options.details ?? {};
|
|
33
|
+
this.retryAfter = options.retryAfter;
|
|
34
|
+
this.exitCode = options.exitCode ?? (AUTH_CODES.has(code) ? EXIT_AUTH : EXIT_FAILED);
|
|
35
|
+
}
|
|
36
|
+
/** The room's revision a `revision.mismatch` carries, when it is a number. */
|
|
37
|
+
get revision() {
|
|
38
|
+
const revision = this.details["revision"];
|
|
39
|
+
return typeof revision === "number" ? revision : undefined;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** Whether an error is a `CloudError`, with the code given when there is one. */
|
|
43
|
+
export function isCloudError(error, code) {
|
|
44
|
+
return error instanceof CloudError && (code === undefined || error.code === code);
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=cloud-errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloud-errors.js","sourceRoot":"","sources":["../src/cloud-errors.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,oFAAoF;AACpF,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,CAAC;AACzB,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC;AAC7B,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC;AAC5B,wEAAwE;AACxE,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC;AAE3B,+FAA+F;AAC/F,MAAM,UAAU,GAAwB,IAAI,GAAG,CAAC;IAC9C,eAAe;IACf,eAAe;IACf,qBAAqB;CACtB,CAAC,CAAC;AAaH,MAAM,OAAO,UAAW,SAAQ,KAAK;IAOxB;IANF,MAAM,CAAS;IACf,OAAO,CAAoC;IAC3C,UAAU,CAAqB;IAC/B,QAAQ,CAAS;IAE1B,YACW,IAAY,EACrB,OAAe,EACf,UAA6B,EAAE;QAE/B,KAAK,CAAC,OAAO,CAAC,CAAC;QAJN,SAAI,GAAJ,IAAI,CAAQ;QAKrB,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC,CAAC;QAClC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC;QACrC,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QACrC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;IACvF,CAAC;IAED,8EAA8E;IAC9E,IAAI,QAAQ;QACV,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAC1C,OAAO,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;IAC7D,CAAC;CACF;AAED,iFAAiF;AACjF,MAAM,UAAU,YAAY,CAAC,KAAc,EAAE,IAAa;IACxD,OAAO,KAAK,YAAY,UAAU,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;AACpF,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A cloud project as a `ProjectHost` (`cli-cloud`, "Projects and review against the cloud"): what
|
|
3
|
+
* `review --base cloud[:<n>]` compares the folder with, as `gitRevisionHost` is what `review
|
|
4
|
+
* --base <revision>` compares it with.
|
|
5
|
+
*
|
|
6
|
+
* A `ProjectHost` is synchronous, so the cloud is read once, up front: the project's files (or a
|
|
7
|
+
* version's) and the images and fonts they reference, each blob once. Every path the service
|
|
8
|
+
* answers then goes through the path rule of the cloud (`isCleanPath`) and must resolve inside the
|
|
9
|
+
* project's root; one that does not is `pull.unsafe-path` and nothing is compared. The only paths
|
|
10
|
+
* left out without a word are the losers of a name collision (`<path>~<id>`, listed in the
|
|
11
|
+
* answer's `collisions`): the service keeps them out of copies and restores for the same reason.
|
|
12
|
+
*
|
|
13
|
+
* The host is rooted at the local project root, like the git host is rooted at the repository:
|
|
14
|
+
* `<root>/<path>` answers the fetched text or bytes and `readDirectory` is made from the path set.
|
|
15
|
+
*/
|
|
16
|
+
import { type ProjectHost } from "@meltemi/diagrams-project";
|
|
17
|
+
import type { CloudClient } from "./cloud-client.js";
|
|
18
|
+
/** The files of a cloud project as the service answered them, before any host is made of them. */
|
|
19
|
+
export interface CloudSnapshot {
|
|
20
|
+
/** The room's revision of a snapshot of the current files; undefined for a version. */
|
|
21
|
+
readonly revision: number | undefined;
|
|
22
|
+
/** The version the snapshot is of; undefined for the current files. */
|
|
23
|
+
readonly version: number | undefined;
|
|
24
|
+
/** Path to text. */
|
|
25
|
+
readonly files: ReadonlyMap<string, string>;
|
|
26
|
+
/** Path to the hash and the bytes of an image or a font. */
|
|
27
|
+
readonly binaries: ReadonlyMap<string, {
|
|
28
|
+
readonly hash: string;
|
|
29
|
+
readonly bytes: Uint8Array;
|
|
30
|
+
}>;
|
|
31
|
+
/** Collision losers (`<path>~<id>`) that were left out. */
|
|
32
|
+
readonly skipped: readonly string[];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Whether a path the cloud answered is NOT safe to put under `root` by itself, with the checks
|
|
36
|
+
* `pull` makes (`cloud-paths.ts`): it breaks the cloud's path rule, a name of it could not be kept
|
|
37
|
+
* on Windows (a device name such as `con` or `com1.txt`, a name that ends with a dot or a space), or
|
|
38
|
+
* joined to the root it leaves it (or is the root itself). What only a set of paths can show
|
|
39
|
+
* (`setProblems`) is checked by `checkCloudPaths`.
|
|
40
|
+
*/
|
|
41
|
+
export declare function unsafeCloudPath(root: string, path: string): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Fails with `pull.unsafe-path` naming the first of `paths` that is not safe under `root`: one that
|
|
44
|
+
* `unsafeCloudPath` refuses, or that cannot be written beside the others, because it differs from
|
|
45
|
+
* another only in letter case (one overwrites the other on Windows and macOS) or is a file where
|
|
46
|
+
* another path needs a folder. The path is named as `pull` names it, escaped (`printablePath`), as it
|
|
47
|
+
* is the cloud's to choose and the terminal is the person's.
|
|
48
|
+
*/
|
|
49
|
+
export declare function checkCloudPaths(root: string, paths: Iterable<string>): void;
|
|
50
|
+
/**
|
|
51
|
+
* Reads a cloud project once: its current files, or version `version`'s, and the blobs they
|
|
52
|
+
* reference. `root` is the folder the paths are checked against (`pull.unsafe-path`, before any
|
|
53
|
+
* blob is fetched). An unknown version is `version.not-found` naming it; an unknown project,
|
|
54
|
+
* `project.not-found`.
|
|
55
|
+
*/
|
|
56
|
+
export declare function fetchCloudSnapshot(client: CloudClient, options: {
|
|
57
|
+
readonly project: string;
|
|
58
|
+
readonly root: string;
|
|
59
|
+
readonly version?: number;
|
|
60
|
+
}): Promise<CloudSnapshot>;
|
|
61
|
+
/** The host of a snapshot, rooted at `root`: `<root>/<path>` is the file the cloud holds there. */
|
|
62
|
+
export declare function cloudSnapshotHost(root: string, snapshot: CloudSnapshot): ProjectHost;
|
|
63
|
+
/**
|
|
64
|
+
* The host of a cloud project (`project`, its current files or those of `version`) rooted at the
|
|
65
|
+
* local project root `root`, filled by one prefetch (`fetchCloudSnapshot`).
|
|
66
|
+
*/
|
|
67
|
+
export declare function cloudHost(client: CloudClient, options: {
|
|
68
|
+
readonly project: string;
|
|
69
|
+
readonly root: string;
|
|
70
|
+
readonly version?: number;
|
|
71
|
+
}): Promise<ProjectHost>;
|
|
72
|
+
//# sourceMappingURL=cloud-host.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloud-host.d.ts","sourceRoot":"","sources":["../src/cloud-host.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAA8B,KAAK,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACzF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAarD,kGAAkG;AAClG,MAAM,WAAW,aAAa;IAC5B,uFAAuF;IACvF,QAAQ,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