@gunshi/combinators 0.37.1 → 0.37.3

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/lib/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- //#region ../../node_modules/.pnpm/args-tokens@0.28.1/node_modules/args-tokens/lib/resolver.d.ts
2
-
1
+ //#region ../../node_modules/.pnpm/args-tokens@0.29.0/node_modules/args-tokens/lib/resolver.d.ts
3
2
  //#region src/resolver.d.ts
4
3
  /**
5
4
  * An argument schema definition for command-line argument parsing.
@@ -452,13 +451,6 @@ interface ArgSchema {
452
451
  */
453
452
  parse?: (value: string) => any;
454
453
  }
455
- /**
456
- * Machine-readable error codes for {@link ArgsValidationError}.
457
- *
458
- * Each code identifies a validation failure category and is also suitable as an
459
- * i18n resource key for localized rendering.
460
- */
461
-
462
454
  /**
463
455
  * An object that contains {@link ArgSchema | argument schema}.
464
456
  *
@@ -467,13 +459,8 @@ interface ArgSchema {
467
459
  interface Args {
468
460
  [option: string]: ArgSchema;
469
461
  }
470
- /**
471
- * An object that contains the values of the arguments.
472
- *
473
- * @typeParam T - {@link Args | Arguments} which is an object that defines the command line arguments.
474
- */
475
462
  //#endregion
476
- //#region ../../node_modules/.pnpm/args-tokens@0.28.1/node_modules/args-tokens/lib/combinators.d.ts
463
+ //#region ../../node_modules/.pnpm/args-tokens@0.29.0/node_modules/args-tokens/lib/combinators.d.ts
477
464
  //#region src/combinators.d.ts
478
465
  /**
479
466
  * A combinator produced by combinator factory functions.
@@ -863,6 +850,13 @@ type CombinatorWithDefault<T> = {
863
850
  * @experimental
864
851
  */
865
852
  declare function withDefault<T extends string | boolean | number>(schema: CombinatorSchema<T>, defaultValue: T): CombinatorSchema<T> & CombinatorWithDefault<T>;
853
+ /**
854
+ * Overlay a flag onto a combinator schema without dropping other modifiers.
855
+ *
856
+ * Omits the flag keys from `S` first so optional `ArgSchema` fields
857
+ * (`multiple?: true`, `required?: boolean`) cannot stay as unions.
858
+ */
859
+ type WithFlag<S, F> = Omit<S, keyof F> & F;
866
860
  /**
867
861
  * Options for the {@link multiple} combinator.
868
862
  */
@@ -873,10 +867,11 @@ type CombinatorMultiple = {
873
867
  * Mark a combinator schema as accepting multiple values.
874
868
  *
875
869
  * The resolved value becomes an array. The original schema is not modified.
870
+ * Other modifiers on `schema` (for example {@link required}) are kept.
876
871
  *
877
- * @typeParam T - The schema's parsed type.
872
+ * @typeParam S - The input combinator schema.
878
873
  * @param schema - The base combinator schema.
879
- * @returns A new schema with `multiple: true`.
874
+ * @returns A copy of `schema` with `multiple: true`.
880
875
  *
881
876
  * @example
882
877
  * ```ts
@@ -888,7 +883,7 @@ type CombinatorMultiple = {
888
883
  *
889
884
  * @experimental
890
885
  */
891
- declare function multiple<T>(schema: CombinatorSchema<T>): CombinatorSchema<T> & CombinatorMultiple;
886
+ declare function multiple<S extends CombinatorSchema<unknown>>(schema: S): WithFlag<S, CombinatorMultiple>;
892
887
  /**
893
888
  * Options for the {@link required} combinator.
894
889
  */
@@ -899,11 +894,12 @@ type CombinatorRequired = {
899
894
  * Mark a combinator schema as required.
900
895
  *
901
896
  * The original schema is not modified.
897
+ * Other modifiers on `schema` (for example {@link multiple}) are kept.
902
898
  *
903
- * @typeParam T - The schema's parsed type.
899
+ * @typeParam S - The input combinator schema.
904
900
  *
905
901
  * @param schema - The base combinator schema.
906
- * @returns A new schema with `required: true`.
902
+ * @returns A copy of `schema` with `required: true`.
907
903
  *
908
904
  * @example
909
905
  * ```ts
@@ -914,7 +910,7 @@ type CombinatorRequired = {
914
910
  *
915
911
  * @experimental
916
912
  */
917
- declare function required<T>(schema: CombinatorSchema<T>): CombinatorSchema<T> & CombinatorRequired;
913
+ declare function required<S extends CombinatorSchema<unknown>>(schema: S): WithFlag<S, CombinatorRequired>;
918
914
  /**
919
915
  * Options for the {@link short} combinator.
920
916
  */
@@ -1134,7 +1130,6 @@ declare function merge<T extends Args[]>(...schemas: T): MergeArgs<T>;
1134
1130
  */
1135
1131
  declare function extend<T extends Args, U extends Args>(base: T, overrides: U): Omit<T, keyof U> & U;
1136
1132
  //#endregion
1137
- //#endregion
1138
1133
  //#region src/index.d.ts
1139
1134
  /**
1140
1135
  * @author kazuya kawaguchi (a.k.a. kazupon)
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- //#region ../../node_modules/.pnpm/args-tokens@0.28.1/node_modules/args-tokens/lib/utils.js
1
+ //#region ../../node_modules/.pnpm/args-tokens@0.29.0/node_modules/args-tokens/lib/utils.js
2
2
  /**
3
3
  * @author kazuya kawaguchi (a.k.a. kazupon)
4
4
  * @license MIT
@@ -23,7 +23,7 @@ function formatChoices(choices) {
23
23
  "-".codePointAt(0);
24
24
  "=".codePointAt(0);
25
25
  //#endregion
26
- //#region ../../node_modules/.pnpm/args-tokens@0.28.1/node_modules/args-tokens/lib/resolver.js
26
+ //#region ../../node_modules/.pnpm/args-tokens@0.29.0/node_modules/args-tokens/lib/resolver.js
27
27
  /**
28
28
  * Entry point of argument options resolver.
29
29
  *
@@ -48,11 +48,24 @@ const ArgsValidationErrorKeys = {
48
48
  unknownOption: "err:arg:unknown-option"
49
49
  };
50
50
  /**
51
+ * Brand that marks {@link ArgsValidationError} instances.
52
+ *
53
+ * The brand is looked up in the global symbol registry with `Symbol.for`, so it stays
54
+ * identical across bundled copies of this module and across realms. It lets
55
+ * {@link isArgsValidationError} recognize errors created by another copy of `args-tokens`,
56
+ * where `instanceof` cannot match.
57
+ */
58
+ const ARGS_VALIDATION_ERROR_BRAND = Symbol.for("args-tokens.ArgsValidationError");
59
+ /**
51
60
  * An error that contains structured metadata for argument validation failures.
52
61
  *
53
62
  * The `message` remains the English fallback message. Renderers can use `code`
54
63
  * and `values` to localize the error, falling back to `message` when localization
55
64
  * is unavailable.
65
+ *
66
+ * Each instance carries a non-enumerable brand keyed by
67
+ * `Symbol.for('args-tokens.ArgsValidationError')`, which {@link isArgsValidationError}
68
+ * uses to recognize instances created by another bundled copy of `args-tokens`.
56
69
  */
57
70
  var ArgsValidationError = class extends Error {
58
71
  /**
@@ -76,10 +89,16 @@ var ArgsValidationError = class extends Error {
76
89
  this.name = "ArgsValidationError";
77
90
  this.code = options.code;
78
91
  this.values = options.values ?? {};
92
+ Object.defineProperty(this, ARGS_VALIDATION_ERROR_BRAND, {
93
+ value: true,
94
+ enumerable: false,
95
+ writable: false,
96
+ configurable: false
97
+ });
79
98
  }
80
99
  };
81
100
  //#endregion
82
- //#region ../../node_modules/.pnpm/args-tokens@0.28.1/node_modules/args-tokens/lib/combinators.js
101
+ //#region ../../node_modules/.pnpm/args-tokens@0.29.0/node_modules/args-tokens/lib/combinators.js
83
102
  /**
84
103
  * Parser combinator factory functions for composable argument schema construction.
85
104
  *
@@ -491,10 +510,11 @@ function withDefault(schema, defaultValue) {
491
510
  * Mark a combinator schema as accepting multiple values.
492
511
  *
493
512
  * The resolved value becomes an array. The original schema is not modified.
513
+ * Other modifiers on `schema` (for example {@link required}) are kept.
494
514
  *
495
- * @typeParam T - The schema's parsed type.
515
+ * @typeParam S - The input combinator schema.
496
516
  * @param schema - The base combinator schema.
497
- * @returns A new schema with `multiple: true`.
517
+ * @returns A copy of `schema` with `multiple: true`.
498
518
  *
499
519
  * @example
500
520
  * ```ts
@@ -517,11 +537,12 @@ function multiple(schema) {
517
537
  * Mark a combinator schema as required.
518
538
  *
519
539
  * The original schema is not modified.
540
+ * Other modifiers on `schema` (for example {@link multiple}) are kept.
520
541
  *
521
- * @typeParam T - The schema's parsed type.
542
+ * @typeParam S - The input combinator schema.
522
543
  *
523
544
  * @param schema - The base combinator schema.
524
- * @returns A new schema with `required: true`.
545
+ * @returns A copy of `schema` with `required: true`.
525
546
  *
526
547
  * @example
527
548
  * ```ts
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gunshi/combinators",
3
3
  "description": "parser combinators for gunshi argument schema",
4
- "version": "0.37.1",
4
+ "version": "0.37.3",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
7
7
  "email": "kawakazu80@gmail.com"
@@ -57,7 +57,7 @@
57
57
  "jsr-exports-lint": "^0.4.2",
58
58
  "publint": "^0.3.20",
59
59
  "tsdown": "0.21.0",
60
- "gunshi": "0.37.1"
60
+ "gunshi": "0.37.3"
61
61
  },
62
62
  "scripts": {
63
63
  "build": "tsdown",