@w6w/cli 0.1.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 (71) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +110 -0
  3. package/dist/bin/w6w.d.ts +22 -0
  4. package/dist/bin/w6w.d.ts.map +1 -0
  5. package/dist/bin/w6w.js +58 -0
  6. package/dist/bin/w6w.js.map +1 -0
  7. package/dist/mod.d.ts +131 -0
  8. package/dist/mod.d.ts.map +1 -0
  9. package/dist/mod.js +257 -0
  10. package/dist/mod.js.map +1 -0
  11. package/dist/src/args.d.ts +79 -0
  12. package/dist/src/args.d.ts.map +1 -0
  13. package/dist/src/args.js +130 -0
  14. package/dist/src/args.js.map +1 -0
  15. package/dist/src/client.d.ts +90 -0
  16. package/dist/src/client.d.ts.map +1 -0
  17. package/dist/src/client.js +172 -0
  18. package/dist/src/client.js.map +1 -0
  19. package/dist/src/commands/connections.d.ts +13 -0
  20. package/dist/src/commands/connections.d.ts.map +1 -0
  21. package/dist/src/commands/connections.js +30 -0
  22. package/dist/src/commands/connections.js.map +1 -0
  23. package/dist/src/commands/documents.d.ts +34 -0
  24. package/dist/src/commands/documents.d.ts.map +1 -0
  25. package/dist/src/commands/documents.js +179 -0
  26. package/dist/src/commands/documents.js.map +1 -0
  27. package/dist/src/commands/index.d.ts +27 -0
  28. package/dist/src/commands/index.d.ts.map +1 -0
  29. package/dist/src/commands/index.js +39 -0
  30. package/dist/src/commands/index.js.map +1 -0
  31. package/dist/src/commands/me.d.ts +29 -0
  32. package/dist/src/commands/me.d.ts.map +1 -0
  33. package/dist/src/commands/me.js +52 -0
  34. package/dist/src/commands/me.js.map +1 -0
  35. package/dist/src/commands/run.d.ts +24 -0
  36. package/dist/src/commands/run.d.ts.map +1 -0
  37. package/dist/src/commands/run.js +78 -0
  38. package/dist/src/commands/run.js.map +1 -0
  39. package/dist/src/commands/shared.d.ts +117 -0
  40. package/dist/src/commands/shared.d.ts.map +1 -0
  41. package/dist/src/commands/shared.js +152 -0
  42. package/dist/src/commands/shared.js.map +1 -0
  43. package/dist/src/commands/vars.d.ts +59 -0
  44. package/dist/src/commands/vars.d.ts.map +1 -0
  45. package/dist/src/commands/vars.js +216 -0
  46. package/dist/src/commands/vars.js.map +1 -0
  47. package/dist/src/commands/workflows.d.ts +13 -0
  48. package/dist/src/commands/workflows.d.ts.map +1 -0
  49. package/dist/src/commands/workflows.js +75 -0
  50. package/dist/src/commands/workflows.js.map +1 -0
  51. package/dist/src/exit.d.ts +51 -0
  52. package/dist/src/exit.d.ts.map +1 -0
  53. package/dist/src/exit.js +94 -0
  54. package/dist/src/exit.js.map +1 -0
  55. package/dist/src/help.d.ts +48 -0
  56. package/dist/src/help.d.ts.map +1 -0
  57. package/dist/src/help.generated.d.ts +88 -0
  58. package/dist/src/help.generated.d.ts.map +1 -0
  59. package/dist/src/help.generated.js +988 -0
  60. package/dist/src/help.generated.js.map +1 -0
  61. package/dist/src/help.js +128 -0
  62. package/dist/src/help.js.map +1 -0
  63. package/dist/src/output.d.ts +84 -0
  64. package/dist/src/output.d.ts.map +1 -0
  65. package/dist/src/output.js +94 -0
  66. package/dist/src/output.js.map +1 -0
  67. package/dist/src/runtime.d.ts +37 -0
  68. package/dist/src/runtime.d.ts.map +1 -0
  69. package/dist/src/runtime.js +57 -0
  70. package/dist/src/runtime.js.map +1 -0
  71. package/package.json +42 -0
@@ -0,0 +1,94 @@
1
+ /**
2
+ * The exit-code mapping — the CLI's machine-readable half of every answer.
3
+ *
4
+ * A command's stdout is for a human or for `jq`; its exit code is for the shell
5
+ * that called it, and it is the only part of the answer a CI job reads. So the
6
+ * four codes are a contract, generated into `src/help.generated.ts` from the
7
+ * shared wrapper surface contract rather than restated here:
8
+ *
9
+ * | code | meaning |
10
+ * |---|---|
11
+ * | 0 | success — including help, and including a queued or running workflow |
12
+ * | 1 | usage error — a bad invocation, or a client that was never configured |
13
+ * | 2 | API error — the server was reached and answered with a failure |
14
+ * | 3 | run failure — `--wait` came back with a run whose status is `failed` |
15
+ *
16
+ * Two of those are traps, and {@linkcode exitCodeFor} exists so that every
17
+ * command falls into them the same way instead of each deciding for itself:
18
+ *
19
+ * - **A queued run is success.** Enqueuing a workflow answers before the run
20
+ * finishes; the caller asked for it to start, and it started.
21
+ * - **A failed run is data, not an error.** The server reports a run-level
22
+ * failure inside the response envelope, with an ordinary success status — so
23
+ * the SDK returns it rather than raising, and only the CLI turns it into a
24
+ * distinct code. Keeping it apart from an API error is the whole point: a
25
+ * failed workflow and an unreachable server demand opposite responses, and a
26
+ * script that cannot tell them apart will retry the wrong one.
27
+ *
28
+ * @module
29
+ */
30
+ import { ApiError } from "@w6w/sdk";
31
+ import { EXIT_API_ERROR, EXIT_RUN_FAILURE, EXIT_SUCCESS, EXIT_USAGE } from "./help.generated.js";
32
+ export { EXIT_API_ERROR, EXIT_RUN_FAILURE, EXIT_SUCCESS, EXIT_USAGE };
33
+ /** The run status that means the workflow itself failed. */
34
+ const FAILED = "failed";
35
+ /**
36
+ * Whether an outcome is a terminal run that failed.
37
+ *
38
+ * Structural on purpose: the run envelope arrives from the SDK as data, and the
39
+ * only field this mapping is entitled to read is the one the exit-code contract
40
+ * names.
41
+ */
42
+ function isFailedRun(outcome) {
43
+ if (typeof outcome !== "object" || outcome === null)
44
+ return false;
45
+ return outcome.status === FAILED;
46
+ }
47
+ /**
48
+ * Whether a thrown value is an error raised by the server having answered.
49
+ *
50
+ * `instanceof` is the primary test. The name check behind it is not ceremony:
51
+ * an installed CLI resolves `@w6w/sdk` through the package manager, and a host
52
+ * that ends up with two copies of the SDK on disk produces an `ApiError` that
53
+ * fails `instanceof` against *this* copy's class. Falling back to the name keeps
54
+ * a genuine server failure out of the usage bucket in that case.
55
+ */
56
+ function isApiError(outcome) {
57
+ return outcome instanceof ApiError ||
58
+ (outcome instanceof Error && outcome.name === "ApiError");
59
+ }
60
+ /**
61
+ * Map a command's outcome — its return value, or the error it threw — to an
62
+ * exit code.
63
+ *
64
+ * This is the only place any command decides what to exit with; there are no
65
+ * other codes anywhere in the CLI.
66
+ *
67
+ * ```ts
68
+ * try {
69
+ * return exitCodeFor(await client.workflows.run(id, { wait: true }));
70
+ * } catch (err) {
71
+ * return exitCodeFor(err);
72
+ * }
73
+ * ```
74
+ *
75
+ * @param outcome - A returned payload, or a caught error.
76
+ * @returns One of the four codes above.
77
+ */
78
+ export function exitCodeFor(outcome) {
79
+ // The server answered, and what it answered was a failure.
80
+ if (isApiError(outcome))
81
+ return EXIT_API_ERROR;
82
+ // Anything else that was thrown never reached the server: a configuration
83
+ // error (no base URL, no token, a token that cannot be sent) or a local bug.
84
+ // The split matters — an API error means the request was made and refused,
85
+ // and a caller that retries on it would be retrying nothing here.
86
+ if (outcome instanceof Error)
87
+ return EXIT_USAGE;
88
+ // Returned data. A run that came back failed is the one payload that is not
89
+ // success; every other payload is.
90
+ if (isFailedRun(outcome))
91
+ return EXIT_RUN_FAILURE;
92
+ return EXIT_SUCCESS;
93
+ }
94
+ //# sourceMappingURL=exit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exit.js","sourceRoot":"","sources":["../../src/exit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjG,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,YAAY,EAAE,UAAU,EAAE,CAAC;AAEtE,4DAA4D;AAC5D,MAAM,MAAM,GAAG,QAAQ,CAAC;AAExB;;;;;;GAMG;AACH,SAAS,WAAW,CAAC,OAAgB;IACnC,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAClE,OAAQ,OAAgC,CAAC,MAAM,KAAK,MAAM,CAAC;AAC7D,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,UAAU,CAAC,OAAgB;IAClC,OAAO,OAAO,YAAY,QAAQ;QAChC,CAAC,OAAO,YAAY,KAAK,IAAI,OAAO,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC;AAC9D,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,WAAW,CAAC,OAAgB;IAC1C,2DAA2D;IAC3D,IAAI,UAAU,CAAC,OAAO,CAAC;QAAE,OAAO,cAAc,CAAC;IAC/C,0EAA0E;IAC1E,6EAA6E;IAC7E,2EAA2E;IAC3E,kEAAkE;IAClE,IAAI,OAAO,YAAY,KAAK;QAAE,OAAO,UAAU,CAAC;IAChD,4EAA4E;IAC5E,mCAAmC;IACnC,IAAI,WAAW,CAAC,OAAO,CAAC;QAAE,OAAO,gBAAgB,CAAC;IAClD,OAAO,YAAY,CAAC;AACtB,CAAC"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * The help renderer.
3
+ *
4
+ * `--help` is the CLI's documentation — not a pointer to documentation, the thing
5
+ * itself. So it resolves at all three levels (root, group, command), it never
6
+ * authenticates, it never reads configuration, it never makes a network call, and
7
+ * nothing in this file does any I/O at all: every function here takes a tree and
8
+ * returns a string. The caller decides whether that string goes to stdout with
9
+ * exit 0 (help was asked for) or to stderr with exit 1 (the invocation was
10
+ * unknown or incomplete).
11
+ *
12
+ * The tree itself is generated from the shared wrapper surface contract — see
13
+ * `scripts/gen-help.ts`. This file only lays it out.
14
+ *
15
+ * @module
16
+ */
17
+ import type { HelpCommand, HelpGroup, HelpTree } from "./help.generated.ts";
18
+ /** Where a command path landed in the tree. */
19
+ export type Resolution = {
20
+ kind: "root";
21
+ } | {
22
+ kind: "group";
23
+ group: HelpGroup;
24
+ } | {
25
+ kind: "command";
26
+ command: HelpCommand;
27
+ group: HelpGroup | null;
28
+ } | {
29
+ kind: "unknown";
30
+ token: string;
31
+ group: HelpGroup | null;
32
+ };
33
+ /**
34
+ * Resolves a command path against the tree.
35
+ *
36
+ * Handles the `w6w info` style aliases declared by the contract, so an alias
37
+ * prints the help of the command it stands for rather than a second copy.
38
+ */
39
+ export declare function resolve(path: string[], tree?: HelpTree): Resolution;
40
+ /** Root help: what w6w is, its command groups, and the global flags. */
41
+ export declare function renderRootHelp(tree?: HelpTree): string;
42
+ /** Group help: the commands in that group, and nothing else. */
43
+ export declare function renderGroupHelp(group: HelpGroup, tree?: HelpTree): string;
44
+ /** Command help: summary, usage, arguments, flags, and a runnable example. */
45
+ export declare function renderCommandHelp(command: HelpCommand, tree?: HelpTree): string;
46
+ /** Renders whichever level a resolution landed on. */
47
+ export declare function renderHelp(resolution: Resolution, tree?: HelpTree): string;
48
+ //# sourceMappingURL=help.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"help.d.ts","sourceRoot":"","sources":["../../src/help.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAa,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEvF,+CAA+C;AAC/C,MAAM,MAAM,UAAU,GAClB;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAChB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,SAAS,CAAA;CAAE,GACnC;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,WAAW,CAAC;IAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAAA;CAAE,GAClE;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAAA;CAAE,CAAC;AAiChE;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,IAAI,GAAE,QAAoB,GAAG,UAAU,CAuB9E;AAED,wEAAwE;AACxE,wBAAgB,cAAc,CAAC,IAAI,GAAE,QAAoB,GAAG,MAAM,CAejE;AAED,gEAAgE;AAChE,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,GAAE,QAAoB,GAAG,MAAM,CAWpF;AAED,8EAA8E;AAC9E,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,GAAE,QAAoB,GAAG,MAAM,CAsB1F;AAED,sDAAsD;AACtD,wBAAgB,UAAU,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI,GAAE,QAAoB,GAAG,MAAM,CAWrF"}
@@ -0,0 +1,88 @@
1
+ /** One argument or flag of a command, ready to render. */
2
+ export interface HelpParam {
3
+ /** The contract's parameter name. */
4
+ name: string;
5
+ /** `argument` renders under ARGUMENTS, `flag` under OPTIONS. */
6
+ kind: "argument" | "flag";
7
+ /** What the help line shows, e.g. `<id>` or `--format <f>`. */
8
+ display: string;
9
+ description: string;
10
+ required: boolean;
11
+ }
12
+ /** One of the CLI's global flags. */
13
+ export interface HelpGlobalFlag {
14
+ name: string;
15
+ alias: string | null;
16
+ type: string;
17
+ env: string | null;
18
+ /** What the help line shows, e.g. `-v, --version`. */
19
+ display: string;
20
+ description: string;
21
+ }
22
+ /** One runnable command — a leaf of the tree. */
23
+ export interface HelpCommand {
24
+ /** The contract operation this command implements, e.g. `documents.create`. */
25
+ operation: string;
26
+ /** The command path below the binary, e.g. `["documents", "create"]`. */
27
+ path: string[];
28
+ name: string;
29
+ /** Alternative paths that resolve to this same command. */
30
+ aliases: string[][];
31
+ /** The contract's summary, verbatim. */
32
+ summary: string;
33
+ /** The summary as it appears in a one-line COMMANDS listing. */
34
+ short: string;
35
+ /** The summary as it appears after the em dash in the command's own help. */
36
+ headline: string;
37
+ usage: string;
38
+ /** The contract's `naming.cli` spelling, verbatim. */
39
+ naming: string;
40
+ /** The contract's `status` — server readiness, not wrapper completeness. */
41
+ status: string;
42
+ params: HelpParam[];
43
+ examples: string[];
44
+ notes: string[];
45
+ }
46
+ /** A group of commands, e.g. `w6w documents`. Groups are never runnable. */
47
+ export interface HelpGroup {
48
+ name: string;
49
+ summary: string;
50
+ headline: string;
51
+ usage: string;
52
+ commands: HelpCommand[];
53
+ /** Flags every command in the group accepts. */
54
+ options: HelpParam[];
55
+ examples: string[];
56
+ }
57
+ /** The whole command tree. */
58
+ export interface HelpTree {
59
+ binary: string;
60
+ contractVersion: string;
61
+ tagline: string;
62
+ usage: string;
63
+ docsUrl: string;
64
+ /** Commands that sit at the root because they have no siblings. */
65
+ commands: HelpCommand[];
66
+ groups: HelpGroup[];
67
+ globalFlags: HelpGlobalFlag[];
68
+ examples: string[];
69
+ }
70
+ /** One entry of the exit-code contract. */
71
+ export interface HelpExitCode {
72
+ code: number;
73
+ name: string;
74
+ meaning: string;
75
+ }
76
+ /** The command tree, generated from the shared wrapper surface contract. */
77
+ export declare const HELP_TREE: HelpTree;
78
+ /** Every command path the parser may match, aliases included. */
79
+ export declare const COMMAND_PATHS: string[][];
80
+ /** The exit-code contract, verbatim from the shared contract's `cli.exitCodes`. */
81
+ export declare const EXIT_CODES: HelpExitCode[];
82
+ export declare const EXIT_SUCCESS: number;
83
+ export declare const EXIT_USAGE: number;
84
+ export declare const EXIT_API_ERROR: number;
85
+ export declare const EXIT_RUN_FAILURE: number;
86
+ /** The global flags, lifted out of the tree for the argument parser. */
87
+ export declare const GLOBAL_FLAGS: HelpGlobalFlag[];
88
+ //# sourceMappingURL=help.generated.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"help.generated.d.ts","sourceRoot":"","sources":["../../src/help.generated.ts"],"names":[],"mappings":"AAiBA,0DAA0D;AAC1D,MAAM,WAAW,SAAS;IACxB,qCAAqC;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,gEAAgE;IAChE,IAAI,EAAE,UAAU,GAAG,MAAM,CAAC;IAC1B,+DAA+D;IAC/D,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,qCAAqC;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