@optique/core 1.0.0-dev.1228 → 1.0.0-dev.1239

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/facade.cjs CHANGED
@@ -1104,9 +1104,12 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
1104
1104
  * @param args The command-line arguments to parse.
1105
1105
  * @param options Configuration options for customizing behavior.
1106
1106
  * @returns The parsed result if successful.
1107
+ * @throws {TypeError} If an async parser is passed at runtime. Use
1108
+ * {@link runParser} or {@link runParserAsync} for async parsers.
1107
1109
  * @since 0.9.0
1108
1110
  */
1109
1111
  function runParserSync(parser, programName, args, options) {
1112
+ if (parser.$mode !== "sync") throw new TypeError("Cannot use an async parser with runParserSync(). Use runParser() or runParserAsync() instead.");
1110
1113
  return runParser(parser, programName, args, options);
1111
1114
  }
1112
1115
  /**
@@ -1465,11 +1468,14 @@ async function runWith(parser, programName, contexts, options) {
1465
1468
  * @param contexts Source contexts to use (priority: earlier overrides later).
1466
1469
  * @param options Run options including args, help, version, etc.
1467
1470
  * @returns The parsed result.
1468
- * @throws Error if any context returns a Promise or if a context's
1471
+ * @throws {TypeError} If an async parser is passed at runtime. Use
1472
+ * {@link runWith} or {@link runWithAsync} for async parsers.
1473
+ * @throws {Error} If any context returns a Promise or if a context's
1469
1474
  * `[Symbol.asyncDispose]` returns a Promise.
1470
1475
  * @since 0.10.0
1471
1476
  */
1472
1477
  function runWithSync(parser, programName, contexts, options) {
1478
+ if (parser.$mode !== "sync") throw new TypeError("Cannot use an async parser with runWithSync(). Use runWith() or runWithAsync() instead.");
1473
1479
  const args = options?.args ?? [];
1474
1480
  if (needsEarlyExit(args, options)) return runParser(parser, programName, args, options);
1475
1481
  if (contexts.length === 0) return runParser(parser, programName, args, options);
package/dist/facade.d.cts CHANGED
@@ -301,6 +301,8 @@ declare function runParser<TParser extends Parser<Mode, unknown, unknown>, THelp
301
301
  * @param args The command-line arguments to parse.
302
302
  * @param options Configuration options for customizing behavior.
303
303
  * @returns The parsed result if successful.
304
+ * @throws {TypeError} If an async parser is passed at runtime. Use
305
+ * {@link runParser} or {@link runParserAsync} for async parsers.
304
306
  * @since 0.9.0
305
307
  */
306
308
  declare function runParserSync<TParser extends Parser<"sync", unknown, unknown>, THelp = void, TError = never>(parser: TParser, programName: string, args: readonly string[], options?: RunOptions<THelp, TError>): InferValue<TParser>;
@@ -461,7 +463,9 @@ declare function runWith<TParser extends Parser<Mode, unknown, unknown>, TContex
461
463
  * @param contexts Source contexts to use (priority: earlier overrides later).
462
464
  * @param options Run options including args, help, version, etc.
463
465
  * @returns The parsed result.
464
- * @throws Error if any context returns a Promise or if a context's
466
+ * @throws {TypeError} If an async parser is passed at runtime. Use
467
+ * {@link runWith} or {@link runWithAsync} for async parsers.
468
+ * @throws {Error} If any context returns a Promise or if a context's
465
469
  * `[Symbol.asyncDispose]` returns a Promise.
466
470
  * @since 0.10.0
467
471
  */
package/dist/facade.d.ts CHANGED
@@ -301,6 +301,8 @@ declare function runParser<TParser extends Parser<Mode, unknown, unknown>, THelp
301
301
  * @param args The command-line arguments to parse.
302
302
  * @param options Configuration options for customizing behavior.
303
303
  * @returns The parsed result if successful.
304
+ * @throws {TypeError} If an async parser is passed at runtime. Use
305
+ * {@link runParser} or {@link runParserAsync} for async parsers.
304
306
  * @since 0.9.0
305
307
  */
306
308
  declare function runParserSync<TParser extends Parser<"sync", unknown, unknown>, THelp = void, TError = never>(parser: TParser, programName: string, args: readonly string[], options?: RunOptions<THelp, TError>): InferValue<TParser>;
@@ -461,7 +463,9 @@ declare function runWith<TParser extends Parser<Mode, unknown, unknown>, TContex
461
463
  * @param contexts Source contexts to use (priority: earlier overrides later).
462
464
  * @param options Run options including args, help, version, etc.
463
465
  * @returns The parsed result.
464
- * @throws Error if any context returns a Promise or if a context's
466
+ * @throws {TypeError} If an async parser is passed at runtime. Use
467
+ * {@link runWith} or {@link runWithAsync} for async parsers.
468
+ * @throws {Error} If any context returns a Promise or if a context's
465
469
  * `[Symbol.asyncDispose]` returns a Promise.
466
470
  * @since 0.10.0
467
471
  */
package/dist/facade.js CHANGED
@@ -1104,9 +1104,12 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
1104
1104
  * @param args The command-line arguments to parse.
1105
1105
  * @param options Configuration options for customizing behavior.
1106
1106
  * @returns The parsed result if successful.
1107
+ * @throws {TypeError} If an async parser is passed at runtime. Use
1108
+ * {@link runParser} or {@link runParserAsync} for async parsers.
1107
1109
  * @since 0.9.0
1108
1110
  */
1109
1111
  function runParserSync(parser, programName, args, options) {
1112
+ if (parser.$mode !== "sync") throw new TypeError("Cannot use an async parser with runParserSync(). Use runParser() or runParserAsync() instead.");
1110
1113
  return runParser(parser, programName, args, options);
1111
1114
  }
1112
1115
  /**
@@ -1465,11 +1468,14 @@ async function runWith(parser, programName, contexts, options) {
1465
1468
  * @param contexts Source contexts to use (priority: earlier overrides later).
1466
1469
  * @param options Run options including args, help, version, etc.
1467
1470
  * @returns The parsed result.
1468
- * @throws Error if any context returns a Promise or if a context's
1471
+ * @throws {TypeError} If an async parser is passed at runtime. Use
1472
+ * {@link runWith} or {@link runWithAsync} for async parsers.
1473
+ * @throws {Error} If any context returns a Promise or if a context's
1469
1474
  * `[Symbol.asyncDispose]` returns a Promise.
1470
1475
  * @since 0.10.0
1471
1476
  */
1472
1477
  function runWithSync(parser, programName, contexts, options) {
1478
+ if (parser.$mode !== "sync") throw new TypeError("Cannot use an async parser with runWithSync(). Use runWith() or runWithAsync() instead.");
1473
1479
  const args = options?.args ?? [];
1474
1480
  if (needsEarlyExit(args, options)) return runParser(parser, programName, args, options);
1475
1481
  if (contexts.length === 0) return runParser(parser, programName, args, options);
@@ -810,6 +810,10 @@ function locale(options = {}) {
810
810
  * @param options Configuration options for the UUID parser.
811
811
  * @returns A {@link ValueParser} that converts string input to {@link Uuid}
812
812
  * strings.
813
+ * @throws {TypeError} If any element of
814
+ * {@link UuidOptions.allowedVersions} is not an integer.
815
+ * @throws {RangeError} If any element of
816
+ * {@link UuidOptions.allowedVersions} is outside the range 1 to 8.
813
817
  */
814
818
  function uuid(options = {}) {
815
819
  const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
@@ -817,7 +821,15 @@ function uuid(options = {}) {
817
821
  require_nonempty.ensureNonEmptyString(metavar);
818
822
  checkBooleanOption(options, "strict");
819
823
  const strict = options.strict !== false;
820
- const allowedVersions = options.allowedVersions != null ? Object.freeze([...options.allowedVersions]) : null;
824
+ const allowedVersions = options.allowedVersions != null ? (() => {
825
+ const unique = /* @__PURE__ */ new Set();
826
+ for (const v of options.allowedVersions) {
827
+ if (!Number.isInteger(v)) throw new TypeError(`Expected every element of allowedVersions to be an integer, but got value "${typeof v === "symbol" ? v.toString() : String(v)}" of type "${Array.isArray(v) ? "array" : v === null ? "null" : typeof v}".`);
828
+ if (v < 1 || v > 8) throw new RangeError(`Expected every element of allowedVersions to be between 1 and 8, but got: ${v}.`);
829
+ unique.add(v);
830
+ }
831
+ return Object.freeze([...unique]);
832
+ })() : null;
821
833
  const invalidUuid = options.errors?.invalidUuid;
822
834
  const disallowedVersion = options.errors?.disallowedVersion;
823
835
  const invalidVariant = options.errors?.invalidVariant;
@@ -562,9 +562,13 @@ interface UuidOptions {
562
562
  readonly metavar?: NonEmptyString;
563
563
  /**
564
564
  * List of allowed UUID versions (e.g., `[4, 5]` for UUIDs version 4 and 5).
565
+ * Each version must be an integer between 1 and 8 (the standardized
566
+ * [RFC 9562] versions). Duplicate entries are automatically removed.
565
567
  * If specified, the parser will validate that the UUID matches one of the
566
568
  * allowed versions. If not specified, the accepted versions depend on
567
569
  * the {@link strict} option.
570
+ *
571
+ * [RFC 9562]: https://www.rfc-editor.org/rfc/rfc9562
568
572
  */
569
573
  readonly allowedVersions?: readonly number[];
570
574
  /**
@@ -633,6 +637,10 @@ interface UuidOptions {
633
637
  * @param options Configuration options for the UUID parser.
634
638
  * @returns A {@link ValueParser} that converts string input to {@link Uuid}
635
639
  * strings.
640
+ * @throws {TypeError} If any element of
641
+ * {@link UuidOptions.allowedVersions} is not an integer.
642
+ * @throws {RangeError} If any element of
643
+ * {@link UuidOptions.allowedVersions} is outside the range 1 to 8.
636
644
  */
637
645
  declare function uuid(options?: UuidOptions): ValueParser<"sync", Uuid>;
638
646
  /**
@@ -562,9 +562,13 @@ interface UuidOptions {
562
562
  readonly metavar?: NonEmptyString;
563
563
  /**
564
564
  * List of allowed UUID versions (e.g., `[4, 5]` for UUIDs version 4 and 5).
565
+ * Each version must be an integer between 1 and 8 (the standardized
566
+ * [RFC 9562] versions). Duplicate entries are automatically removed.
565
567
  * If specified, the parser will validate that the UUID matches one of the
566
568
  * allowed versions. If not specified, the accepted versions depend on
567
569
  * the {@link strict} option.
570
+ *
571
+ * [RFC 9562]: https://www.rfc-editor.org/rfc/rfc9562
568
572
  */
569
573
  readonly allowedVersions?: readonly number[];
570
574
  /**
@@ -633,6 +637,10 @@ interface UuidOptions {
633
637
  * @param options Configuration options for the UUID parser.
634
638
  * @returns A {@link ValueParser} that converts string input to {@link Uuid}
635
639
  * strings.
640
+ * @throws {TypeError} If any element of
641
+ * {@link UuidOptions.allowedVersions} is not an integer.
642
+ * @throws {RangeError} If any element of
643
+ * {@link UuidOptions.allowedVersions} is outside the range 1 to 8.
636
644
  */
637
645
  declare function uuid(options?: UuidOptions): ValueParser<"sync", Uuid>;
638
646
  /**
@@ -810,6 +810,10 @@ function locale(options = {}) {
810
810
  * @param options Configuration options for the UUID parser.
811
811
  * @returns A {@link ValueParser} that converts string input to {@link Uuid}
812
812
  * strings.
813
+ * @throws {TypeError} If any element of
814
+ * {@link UuidOptions.allowedVersions} is not an integer.
815
+ * @throws {RangeError} If any element of
816
+ * {@link UuidOptions.allowedVersions} is outside the range 1 to 8.
813
817
  */
814
818
  function uuid(options = {}) {
815
819
  const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
@@ -817,7 +821,15 @@ function uuid(options = {}) {
817
821
  ensureNonEmptyString(metavar);
818
822
  checkBooleanOption(options, "strict");
819
823
  const strict = options.strict !== false;
820
- const allowedVersions = options.allowedVersions != null ? Object.freeze([...options.allowedVersions]) : null;
824
+ const allowedVersions = options.allowedVersions != null ? (() => {
825
+ const unique = /* @__PURE__ */ new Set();
826
+ for (const v of options.allowedVersions) {
827
+ if (!Number.isInteger(v)) throw new TypeError(`Expected every element of allowedVersions to be an integer, but got value "${typeof v === "symbol" ? v.toString() : String(v)}" of type "${Array.isArray(v) ? "array" : v === null ? "null" : typeof v}".`);
828
+ if (v < 1 || v > 8) throw new RangeError(`Expected every element of allowedVersions to be between 1 and 8, but got: ${v}.`);
829
+ unique.add(v);
830
+ }
831
+ return Object.freeze([...unique]);
832
+ })() : null;
821
833
  const invalidUuid = options.errors?.invalidUuid;
822
834
  const disallowedVersion = options.errors?.disallowedVersion;
823
835
  const invalidVariant = options.errors?.invalidVariant;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.0.0-dev.1228+2971180c",
3
+ "version": "1.0.0-dev.1239+e5c4f6ba",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",