@qodalis/cli-server-abstractions 1.0.0-beta.6 → 1.0.0-beta.8

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.
@@ -14,6 +14,11 @@ export interface ICliCommandProcessor {
14
14
  allowUnlistedCommands?: boolean;
15
15
  /** When true, the command requires a positional value argument. */
16
16
  valueRequired?: boolean;
17
+ /**
18
+ * When true, the command reads an optional positional value (`command.value`).
19
+ * Implied by {@link valueRequired}. MCP exposes it as an optional `value` argument.
20
+ */
21
+ acceptsValue?: boolean;
17
22
  /** Semantic version of this processor. */
18
23
  version: string;
19
24
  /** Nested sub-command processors. */
@@ -51,6 +56,7 @@ export declare abstract class CliCommandProcessor implements ICliCommandProcesso
51
56
  author: ICliCommandAuthor;
52
57
  allowUnlistedCommands?: boolean;
53
58
  valueRequired?: boolean;
59
+ acceptsValue?: boolean;
54
60
  version: string;
55
61
  processors?: ICliCommandProcessor[];
56
62
  parameters?: ICliCommandParameterDescriptor[];
@@ -1 +1 @@
1
- {"version":3,"file":"cli-command-processor.d.ts","sourceRoot":"","sources":["../src/cli-command-processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAwB,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EAAE,8BAA8B,EAAE,MAAM,oCAAoC,CAAC;AACpF,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAElE,mGAAmG;AACnG,MAAM,WAAW,oBAAoB;IACjC,qDAAqD;IACrD,OAAO,EAAE,MAAM,CAAC;IAChB,sDAAsD;IACtD,WAAW,EAAE,MAAM,CAAC;IACpB,0CAA0C;IAC1C,MAAM,EAAE,iBAAiB,CAAC;IAC1B,gGAAgG;IAChG,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,mEAAmE;IACnE,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,0CAA0C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AAO,CAAC;IACxB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,OAAO,EAAE,MAAM,CAAW;IAC1B,UAAU,CAAC,EAAE,oBAAoB,EAAE,CAAC;IACpC,UAAU,CAAC,EAAE,8BAA8B,EAAE,CAAC;IAC9C,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;IAE/B,QAAQ,CAAC,WAAW,CAAC,OAAO,EAAE,iBAAiB,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;IACvF,qBAAqB,CAAC,CAAC,OAAO,EAAE,iBAAiB,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,qBAAqB,CAAC;CAC3G"}
@@ -10,6 +10,7 @@ class CliCommandProcessor {
10
10
  author = cli_command_author_1.DefaultLibraryAuthor;
11
11
  allowUnlistedCommands;
12
12
  valueRequired;
13
+ acceptsValue;
13
14
  version = '1.0.0';
14
15
  processors;
15
16
  parameters;
@@ -1 +1 @@
1
- {"version":3,"file":"cli-command-processor.js","sourceRoot":"","sources":["../src/cli-command-processor.ts"],"names":[],"mappings":";;;AAAA,6DAA+E;AA6C/E;;;GAGG;AACH,MAAsB,mBAAmB;IAGrC,MAAM,GAAsB,yCAAoB,CAAC;IACjD,qBAAqB,CAAW;IAChC,aAAa,CAAW;IACxB,OAAO,GAAW,OAAO,CAAC;IAC1B,UAAU,CAA0B;IACpC,UAAU,CAAoC;IAC9C,mBAAmB,CAAY;CAIlC;AAbD,kDAaC"}
1
+ {"version":3,"file":"cli-command-processor.js","sourceRoot":"","sources":["../src/cli-command-processor.ts"],"names":[],"mappings":";;;AAAA,6DAA+E;AAkD/E;;;GAGG;AACH,MAAsB,mBAAmB;IAGrC,MAAM,GAAsB,yCAAoB,CAAC;IACjD,qBAAqB,CAAW;IAChC,aAAa,CAAW;IACxB,YAAY,CAAW;IACvB,OAAO,GAAW,OAAO,CAAC;IAC1B,UAAU,CAA0B;IACpC,UAAU,CAAoC;IAC9C,mBAAmB,CAAY;CAIlC;AAdD,kDAcC"}
@@ -10,6 +10,13 @@ export interface CliProcessCommand {
10
10
  rawCommand: string;
11
11
  /** Positional value argument (the first non-flag token after the command). */
12
12
  value?: string;
13
+ /**
14
+ * The positional arguments after the command and sub-command words, split
15
+ * like a shell: quotes removed, backslash escapes applied, flags excluded.
16
+ * Sent by newer browsers; `value` stays as typed. Read it with `getPositionals`,
17
+ * which falls back to splitting `value` when it is missing.
18
+ */
19
+ positionals?: string[];
13
20
  /** Named arguments parsed from flags (e.g. { algorithm: "sha256" }). */
14
21
  args: Record<string, any>;
15
22
  }
@@ -1 +1 @@
1
- {"version":3,"file":"cli-process-command.d.ts","sourceRoot":"","sources":["../src/cli-process-command.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,MAAM,WAAW,iBAAiB;IAC9B,qDAAqD;IACrD,OAAO,EAAE,MAAM,CAAC;IAChB,qDAAqD;IACrD,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,6FAA6F;IAC7F,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,+DAA+D;IAC/D,UAAU,EAAE,MAAM,CAAC;IACnB,8EAA8E;IAC9E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wEAAwE;IACxE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC7B"}
1
+ {"version":3,"file":"cli-process-command.d.ts","sourceRoot":"","sources":["../src/cli-process-command.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,MAAM,WAAW,iBAAiB;IAC9B,qDAAqD;IACrD,OAAO,EAAE,MAAM,CAAC;IAChB,qDAAqD;IACrD,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,6FAA6F;IAC7F,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,+DAA+D;IAC/D,UAAU,EAAE,MAAM,CAAC;IACnB,8EAA8E;IAC9E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,wEAAwE;IACxE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC7B"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { ICliCommandAuthor, CliCommandAuthor, DefaultLibraryAuthor } from './cli-command-author';
2
2
  export { CliProcessCommand } from './cli-process-command';
3
+ export { splitShellWords, joinShellWords, getPositionals, getPositionalText, quoteShellWord } from './shell-words';
3
4
  export { ICliCommandParameterDescriptor, CliCommandParameterDescriptor } from './cli-command-parameter-descriptor';
4
5
  export { ICliCommandProcessor, CliCommandProcessor } from './cli-command-processor';
5
6
  export { ICliModule, CliModule } from './cli-module';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACjG,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,8BAA8B,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AACnH,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACpF,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AACvF,OAAO,EACH,OAAO,EACP,uBAAuB,EACvB,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,sBAAsB,EACtB,YAAY,EACZ,kBAAkB,EAClB,QAAQ,EACR,SAAS,EACT,WAAW,EACX,WAAW,GACd,MAAM,QAAQ,CAAC;AAChB,OAAO,EACH,oBAAoB,EACpB,wBAAwB,EACxB,oBAAoB,EACpB,+BAA+B,EAC/B,2BAA2B,EAC3B,4BAA4B,EAC5B,kBAAkB,EAClB,0BAA0B,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AAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,0BAA0B,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC"}
package/dist/index.js CHANGED
@@ -1,9 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isStreamCapable = exports.DataExplorerOutputFormat = exports.DataExplorerLanguage = exports.CliModule = exports.CliCommandProcessor = exports.CliCommandParameterDescriptor = exports.DefaultLibraryAuthor = exports.CliCommandAuthor = void 0;
3
+ exports.isStreamCapable = exports.DataExplorerOutputFormat = exports.DataExplorerLanguage = exports.CliModule = exports.CliCommandProcessor = exports.CliCommandParameterDescriptor = exports.quoteShellWord = exports.getPositionalText = exports.getPositionals = exports.joinShellWords = exports.splitShellWords = exports.DefaultLibraryAuthor = exports.CliCommandAuthor = void 0;
4
4
  var cli_command_author_1 = require("./cli-command-author");
5
5
  Object.defineProperty(exports, "CliCommandAuthor", { enumerable: true, get: function () { return cli_command_author_1.CliCommandAuthor; } });
6
6
  Object.defineProperty(exports, "DefaultLibraryAuthor", { enumerable: true, get: function () { return cli_command_author_1.DefaultLibraryAuthor; } });
7
+ var shell_words_1 = require("./shell-words");
8
+ Object.defineProperty(exports, "splitShellWords", { enumerable: true, get: function () { return shell_words_1.splitShellWords; } });
9
+ Object.defineProperty(exports, "joinShellWords", { enumerable: true, get: function () { return shell_words_1.joinShellWords; } });
10
+ Object.defineProperty(exports, "getPositionals", { enumerable: true, get: function () { return shell_words_1.getPositionals; } });
11
+ Object.defineProperty(exports, "getPositionalText", { enumerable: true, get: function () { return shell_words_1.getPositionalText; } });
12
+ Object.defineProperty(exports, "quoteShellWord", { enumerable: true, get: function () { return shell_words_1.quoteShellWord; } });
7
13
  var cli_command_parameter_descriptor_1 = require("./cli-command-parameter-descriptor");
8
14
  Object.defineProperty(exports, "CliCommandParameterDescriptor", { enumerable: true, get: function () { return cli_command_parameter_descriptor_1.CliCommandParameterDescriptor; } });
9
15
  var cli_command_processor_1 = require("./cli-command-processor");
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,2DAAiG;AAArE,sHAAA,gBAAgB,OAAA;AAAE,0HAAA,oBAAoB,OAAA;AAElE,uFAAmH;AAA1E,iJAAA,6BAA6B,OAAA;AACtE,iEAAoF;AAArD,4HAAA,mBAAmB,OAAA;AAClD,2CAAqD;AAAhC,uGAAA,SAAS,OAAA;AAgB9B,6DAa+B;AAZ3B,2HAAA,oBAAoB,OAAA;AACpB,+HAAA,wBAAwB,OAAA;AAc5B,+EAA6F;AAAxD,+HAAA,eAAe,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,2DAAiG;AAArE,sHAAA,gBAAgB,OAAA;AAAE,0HAAA,oBAAoB,OAAA;AAElE,6CAAmH;AAA1G,8GAAA,eAAe,OAAA;AAAE,6GAAA,cAAc,OAAA;AAAE,6GAAA,cAAc,OAAA;AAAE,gHAAA,iBAAiB,OAAA;AAAE,6GAAA,cAAc,OAAA;AAC3F,uFAAmH;AAA1E,iJAAA,6BAA6B,OAAA;AACtE,iEAAoF;AAArD,4HAAA,mBAAmB,OAAA;AAClD,2CAAqD;AAAhC,uGAAA,SAAS,OAAA;AAgB9B,6DAa+B;AAZ3B,2HAAA,oBAAoB,OAAA;AACpB,+HAAA,wBAAwB,OAAA;AAc5B,+EAA6F;AAAxD,+HAAA,eAAe,OAAA"}
@@ -0,0 +1,31 @@
1
+ import { CliProcessCommand } from './cli-process-command';
2
+ /**
3
+ * Splits text into words like a shell, as the browser CLI does: whitespace
4
+ * separates words, quotes are removed (`"a b"` is one word `a b`), a backslash
5
+ * outside quotes escapes the next character (`my\ file` -> `my file`), and
6
+ * inside double quotes `\"` and `\\` are escapes. Single quotes keep their
7
+ * content as is. A quote without a closing one is text.
8
+ */
9
+ export declare function splitShellWords(text: string): string[];
10
+ /**
11
+ * The arguments as a shell's echo prints them, as the browser CLI's own
12
+ * `echo` does: quotes removed, the words joined by one space, spacing inside
13
+ * quotes kept (`"a" "b"` -> `a b`). A quote without a closing one is text.
14
+ */
15
+ export declare function joinShellWords(text: string): string;
16
+ /**
17
+ * The positional arguments of a command, unquoted: `command.positionals` as the
18
+ * browser sends it, or, from clients that do not send it, `command.value`
19
+ * split with the same shell rules.
20
+ */
21
+ export declare function getPositionals(command: Pick<CliProcessCommand, 'positionals' | 'value'>): string[];
22
+ /** The positional arguments joined by one space (`base64 encode "a b"` -> `a b`); empty when there are none. */
23
+ export declare function getPositionalText(command: Pick<CliProcessCommand, 'positionals' | 'value'>): string;
24
+ /**
25
+ * Quotes a word for a command line so `splitShellWords` (and the browser CLI's
26
+ * parser) reads it back unchanged: as is when it has no spaces, quotes or
27
+ * special characters; in double quotes when it has no `"`; in single quotes
28
+ * when it has no `'`; otherwise in double quotes with `\"` and `\\` escapes.
29
+ */
30
+ export declare function quoteShellWord(value: string): string;
31
+ //# sourceMappingURL=shell-words.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shell-words.d.ts","sourceRoot":"","sources":["../src/shell-words.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAe1D;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CA4BtD;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,IAAI,CAAC,iBAAiB,EAAE,aAAa,GAAG,OAAO,CAAC,GAAG,MAAM,EAAE,CAGlG;AAED,gHAAgH;AAChH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,IAAI,CAAC,iBAAiB,EAAE,aAAa,GAAG,OAAO,CAAC,GAAG,MAAM,CAEnG;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAKpD"}
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.splitShellWords = splitShellWords;
4
+ exports.joinShellWords = joinShellWords;
5
+ exports.getPositionals = getPositionals;
6
+ exports.getPositionalText = getPositionalText;
7
+ exports.quoteShellWord = quoteShellWord;
8
+ /** Index of the quote closing the one at `start`, or -1. In double quotes `\"` and `\\` are escapes. */
9
+ function closingQuote(text, start) {
10
+ const quote = text[start];
11
+ for (let i = start + 1; i < text.length; i++) {
12
+ if (quote === '"' && text[i] === '\\' && (text[i + 1] === '"' || text[i + 1] === '\\')) {
13
+ i++;
14
+ }
15
+ else if (text[i] === quote) {
16
+ return i;
17
+ }
18
+ }
19
+ return -1;
20
+ }
21
+ /**
22
+ * Splits text into words like a shell, as the browser CLI does: whitespace
23
+ * separates words, quotes are removed (`"a b"` is one word `a b`), a backslash
24
+ * outside quotes escapes the next character (`my\ file` -> `my file`), and
25
+ * inside double quotes `\"` and `\\` are escapes. Single quotes keep their
26
+ * content as is. A quote without a closing one is text.
27
+ */
28
+ function splitShellWords(text) {
29
+ const words = [];
30
+ let current = '';
31
+ let inWord = false;
32
+ for (let i = 0; i < text.length; i++) {
33
+ const ch = text[i];
34
+ if (ch === '\\' && i + 1 < text.length) {
35
+ current += text[++i];
36
+ inWord = true;
37
+ continue;
38
+ }
39
+ const end = ch === '"' || ch === "'" ? closingQuote(text, i) : -1;
40
+ if (end !== -1) {
41
+ const inner = text.slice(i + 1, end);
42
+ current += ch === '"' ? inner.replace(/\\(["\\])/g, '$1') : inner;
43
+ inWord = true;
44
+ i = end;
45
+ }
46
+ else if (/\s/.test(ch)) {
47
+ if (inWord)
48
+ words.push(current);
49
+ current = '';
50
+ inWord = false;
51
+ }
52
+ else {
53
+ current += ch;
54
+ inWord = true;
55
+ }
56
+ }
57
+ if (inWord)
58
+ words.push(current);
59
+ return words;
60
+ }
61
+ /**
62
+ * The arguments as a shell's echo prints them, as the browser CLI's own
63
+ * `echo` does: quotes removed, the words joined by one space, spacing inside
64
+ * quotes kept (`"a" "b"` -> `a b`). A quote without a closing one is text.
65
+ */
66
+ function joinShellWords(text) {
67
+ return splitShellWords(text).join(' ');
68
+ }
69
+ /**
70
+ * The positional arguments of a command, unquoted: `command.positionals` as the
71
+ * browser sends it, or, from clients that do not send it, `command.value`
72
+ * split with the same shell rules.
73
+ */
74
+ function getPositionals(command) {
75
+ if (Array.isArray(command.positionals))
76
+ return command.positionals.map((p) => String(p));
77
+ return splitShellWords(command.value ?? '');
78
+ }
79
+ /** The positional arguments joined by one space (`base64 encode "a b"` -> `a b`); empty when there are none. */
80
+ function getPositionalText(command) {
81
+ return getPositionals(command).join(' ');
82
+ }
83
+ /**
84
+ * Quotes a word for a command line so `splitShellWords` (and the browser CLI's
85
+ * parser) reads it back unchanged: as is when it has no spaces, quotes or
86
+ * special characters; in double quotes when it has no `"`; in single quotes
87
+ * when it has no `'`; otherwise in double quotes with `\"` and `\\` escapes.
88
+ */
89
+ function quoteShellWord(value) {
90
+ if (/^[^\s"'\\=|&;<>()$`*?#~-][^\s"'\\=|&;<>()$`*?#~]*$/.test(value))
91
+ return value;
92
+ if (!value.includes('"'))
93
+ return `"${value.replace(/\\/g, '\\\\')}"`;
94
+ if (!value.includes("'"))
95
+ return `'${value}'`;
96
+ return `"${value.replace(/[\\"]/g, '\\$&')}"`;
97
+ }
98
+ //# sourceMappingURL=shell-words.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shell-words.js","sourceRoot":"","sources":["../src/shell-words.ts"],"names":[],"mappings":";;AAsBA,0CA4BC;AAOD,wCAEC;AAOD,wCAGC;AAGD,8CAEC;AAQD,wCAKC;AArFD,wGAAwG;AACxG,SAAS,YAAY,CAAC,IAAY,EAAE,KAAa;I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AC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC7C,CAAC;AAED;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,KAAa;IACxC,IAAI,oDAAoD,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACnF,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC;IACrE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,KAAK,GAAG,CAAC;IAC9C,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC;AAClD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qodalis/cli-server-abstractions",
3
- "version": "1.0.0-beta.6",
3
+ "version": "1.0.0-beta.8",
4
4
  "description": "Shared interfaces and base classes for Qodalis CLI command processors — zero framework dependencies",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",