@optique/testing 1.3.0-dev.2488 → 1.3.0-dev.2491

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/README.md CHANGED
@@ -18,6 +18,23 @@ visible from its import:
18
18
  The package root holds only the contracts that mean the same thing at more than
19
19
  one boundary. It depends on no test framework and no assertion library.
20
20
 
21
+ The parser layer is available through `parseArgs()` and `parseArgsSync()`:
22
+
23
+ ~~~~ typescript
24
+ import { option } from "@optique/core/primitives";
25
+ import { parseArgsSync } from "@optique/testing/parser";
26
+
27
+ const result = parseArgsSync(option("--verbose"), ["--verbose"]);
28
+ if (result.success) {
29
+ console.log(result.value);
30
+ } else {
31
+ console.error(result.error, result.remainingArgs, result.commandPath);
32
+ }
33
+ ~~~~
34
+
35
+ The runner, discovery, and child-process entry points remain reserved while
36
+ their helpers are developed.
37
+
21
38
  [Optique]: https://optique.dev/
22
39
 
23
40
 
package/dist/parser.cjs CHANGED
@@ -0,0 +1,66 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+
23
+ //#endregion
24
+ const __optique_core_parser = __toESM(require("@optique/core/parser"));
25
+
26
+ //#region src/parser.ts
27
+ /**
28
+ * Parses a complete argument list and always returns a promise.
29
+ *
30
+ * Parser failures are returned as structured values. Exceptions thrown by a
31
+ * parser, or rejections from an asynchronous parser, reject the returned
32
+ * promise.
33
+ *
34
+ * @template TParser The parser type, including its inferred result value.
35
+ * @param parser The parser to exercise.
36
+ * @param args The complete argument list to parse.
37
+ * @param options Optional parser annotations.
38
+ * @returns A promise resolving to the parsed value or structured failure.
39
+ * @since 1.3.0
40
+ */
41
+ async function parseArgs(parser, args, options) {
42
+ return await (0, __optique_core_parser.parseDetailed)(parser, args, options);
43
+ }
44
+ /**
45
+ * Parses a complete argument list with a synchronous parser.
46
+ *
47
+ * Parser failures are returned as structured values. Exceptions thrown by a
48
+ * parser propagate to the caller.
49
+ *
50
+ * @template TParser The synchronous parser type, including its inferred result
51
+ * value.
52
+ * @param parser The synchronous parser to exercise.
53
+ * @param args The complete argument list to parse.
54
+ * @param options Optional parser annotations.
55
+ * @returns The parsed value or structured failure.
56
+ * @throws {TypeError} When called with an asynchronous parser at runtime.
57
+ * @since 1.3.0
58
+ */
59
+ function parseArgsSync(parser, args, options) {
60
+ if (parser.mode !== "sync") throw new TypeError("Cannot use an async parser with parseArgsSync(). Use parseArgs() instead.");
61
+ return (0, __optique_core_parser.parseDetailed)(parser, args, options);
62
+ }
63
+
64
+ //#endregion
65
+ exports.parseArgs = parseArgs;
66
+ exports.parseArgsSync = parseArgsSync;
package/dist/parser.d.cts CHANGED
@@ -1 +1,44 @@
1
- export { };
1
+ import { DetailedParseResult, InferValue, Mode, ParseOptions, Parser } from "@optique/core/parser";
2
+
3
+ //#region src/parser.d.ts
4
+
5
+ /**
6
+ * The result of parsing a complete argument list in a parser-layer test.
7
+ *
8
+ * @template T The inferred parser value type.
9
+ * @since 1.3.0
10
+ */
11
+ type ParseArgsResult<T> = DetailedParseResult<T>;
12
+ /**
13
+ * Parses a complete argument list and always returns a promise.
14
+ *
15
+ * Parser failures are returned as structured values. Exceptions thrown by a
16
+ * parser, or rejections from an asynchronous parser, reject the returned
17
+ * promise.
18
+ *
19
+ * @template TParser The parser type, including its inferred result value.
20
+ * @param parser The parser to exercise.
21
+ * @param args The complete argument list to parse.
22
+ * @param options Optional parser annotations.
23
+ * @returns A promise resolving to the parsed value or structured failure.
24
+ * @since 1.3.0
25
+ */
26
+ declare function parseArgs<TParser extends Parser<Mode, unknown, unknown>>(parser: TParser, args: readonly string[], options?: ParseOptions): Promise<ParseArgsResult<InferValue<TParser>>>;
27
+ /**
28
+ * Parses a complete argument list with a synchronous parser.
29
+ *
30
+ * Parser failures are returned as structured values. Exceptions thrown by a
31
+ * parser propagate to the caller.
32
+ *
33
+ * @template TParser The synchronous parser type, including its inferred result
34
+ * value.
35
+ * @param parser The synchronous parser to exercise.
36
+ * @param args The complete argument list to parse.
37
+ * @param options Optional parser annotations.
38
+ * @returns The parsed value or structured failure.
39
+ * @throws {TypeError} When called with an asynchronous parser at runtime.
40
+ * @since 1.3.0
41
+ */
42
+ declare function parseArgsSync<TParser extends Parser<"sync", unknown, unknown>>(parser: TParser, args: readonly string[], options?: ParseOptions): ParseArgsResult<InferValue<TParser>>;
43
+ //#endregion
44
+ export { ParseArgsResult, parseArgs, parseArgsSync };
package/dist/parser.d.ts CHANGED
@@ -1 +1,44 @@
1
- export { };
1
+ import { DetailedParseResult, InferValue, Mode, ParseOptions, Parser } from "@optique/core/parser";
2
+
3
+ //#region src/parser.d.ts
4
+
5
+ /**
6
+ * The result of parsing a complete argument list in a parser-layer test.
7
+ *
8
+ * @template T The inferred parser value type.
9
+ * @since 1.3.0
10
+ */
11
+ type ParseArgsResult<T> = DetailedParseResult<T>;
12
+ /**
13
+ * Parses a complete argument list and always returns a promise.
14
+ *
15
+ * Parser failures are returned as structured values. Exceptions thrown by a
16
+ * parser, or rejections from an asynchronous parser, reject the returned
17
+ * promise.
18
+ *
19
+ * @template TParser The parser type, including its inferred result value.
20
+ * @param parser The parser to exercise.
21
+ * @param args The complete argument list to parse.
22
+ * @param options Optional parser annotations.
23
+ * @returns A promise resolving to the parsed value or structured failure.
24
+ * @since 1.3.0
25
+ */
26
+ declare function parseArgs<TParser extends Parser<Mode, unknown, unknown>>(parser: TParser, args: readonly string[], options?: ParseOptions): Promise<ParseArgsResult<InferValue<TParser>>>;
27
+ /**
28
+ * Parses a complete argument list with a synchronous parser.
29
+ *
30
+ * Parser failures are returned as structured values. Exceptions thrown by a
31
+ * parser propagate to the caller.
32
+ *
33
+ * @template TParser The synchronous parser type, including its inferred result
34
+ * value.
35
+ * @param parser The synchronous parser to exercise.
36
+ * @param args The complete argument list to parse.
37
+ * @param options Optional parser annotations.
38
+ * @returns The parsed value or structured failure.
39
+ * @throws {TypeError} When called with an asynchronous parser at runtime.
40
+ * @since 1.3.0
41
+ */
42
+ declare function parseArgsSync<TParser extends Parser<"sync", unknown, unknown>>(parser: TParser, args: readonly string[], options?: ParseOptions): ParseArgsResult<InferValue<TParser>>;
43
+ //#endregion
44
+ export { ParseArgsResult, parseArgs, parseArgsSync };
package/dist/parser.js CHANGED
@@ -0,0 +1,42 @@
1
+ import { parseDetailed } from "@optique/core/parser";
2
+
3
+ //#region src/parser.ts
4
+ /**
5
+ * Parses a complete argument list and always returns a promise.
6
+ *
7
+ * Parser failures are returned as structured values. Exceptions thrown by a
8
+ * parser, or rejections from an asynchronous parser, reject the returned
9
+ * promise.
10
+ *
11
+ * @template TParser The parser type, including its inferred result value.
12
+ * @param parser The parser to exercise.
13
+ * @param args The complete argument list to parse.
14
+ * @param options Optional parser annotations.
15
+ * @returns A promise resolving to the parsed value or structured failure.
16
+ * @since 1.3.0
17
+ */
18
+ async function parseArgs(parser, args, options) {
19
+ return await parseDetailed(parser, args, options);
20
+ }
21
+ /**
22
+ * Parses a complete argument list with a synchronous parser.
23
+ *
24
+ * Parser failures are returned as structured values. Exceptions thrown by a
25
+ * parser propagate to the caller.
26
+ *
27
+ * @template TParser The synchronous parser type, including its inferred result
28
+ * value.
29
+ * @param parser The synchronous parser to exercise.
30
+ * @param args The complete argument list to parse.
31
+ * @param options Optional parser annotations.
32
+ * @returns The parsed value or structured failure.
33
+ * @throws {TypeError} When called with an asynchronous parser at runtime.
34
+ * @since 1.3.0
35
+ */
36
+ function parseArgsSync(parser, args, options) {
37
+ if (parser.mode !== "sync") throw new TypeError("Cannot use an async parser with parseArgsSync(). Use parseArgs() instead.");
38
+ return parseDetailed(parser, args, options);
39
+ }
40
+
41
+ //#endregion
42
+ export { parseArgs, parseArgsSync };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/testing",
3
- "version": "1.3.0-dev.2488",
3
+ "version": "1.3.0-dev.2491",
4
4
  "description": "Testing support for Optique command-line interfaces",
5
5
  "keywords": [
6
6
  "CLI",
@@ -85,6 +85,9 @@
85
85
  }
86
86
  },
87
87
  "sideEffects": false,
88
+ "dependencies": {
89
+ "@optique/core": "1.3.0-dev.2491+0b23bdcf"
90
+ },
88
91
  "devDependencies": {
89
92
  "@types/node": "^24.0.0",
90
93
  "tsdown": "^0.13.0",