@cli-forge/parser 0.10.0 → 0.11.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 (131) hide show
  1. package/LICENSE.md +5 -0
  2. package/dist/index.js.map +1 -0
  3. package/dist/lib/config-files/configuration-loader.js.map +1 -0
  4. package/dist/lib/config-files/index.js.map +1 -0
  5. package/dist/lib/config-files/json-file-loader.js.map +1 -0
  6. package/dist/lib/config-files/package-json-loader.js.map +1 -0
  7. package/dist/lib/config-files/utils.js.map +1 -0
  8. package/dist/lib/helpers.js.map +1 -0
  9. package/dist/lib/option-types/array.js.map +1 -0
  10. package/dist/lib/option-types/boolean.js.map +1 -0
  11. package/{src → dist}/lib/option-types/common.d.ts +1 -1
  12. package/dist/lib/option-types/common.js.map +1 -0
  13. package/dist/lib/option-types/index.d.ts +15 -0
  14. package/{src → dist}/lib/option-types/index.js +1 -0
  15. package/dist/lib/option-types/index.js.map +1 -0
  16. package/dist/lib/option-types/number.js.map +1 -0
  17. package/dist/lib/option-types/object.d.ts +74 -0
  18. package/dist/lib/option-types/object.js.map +1 -0
  19. package/dist/lib/option-types/option-config-to-type.d.ts +9 -0
  20. package/dist/lib/option-types/option-config-to-type.js.map +1 -0
  21. package/dist/lib/option-types/option-config.d.ts +24 -0
  22. package/dist/lib/option-types/option-config.js.map +1 -0
  23. package/dist/lib/option-types/string.js.map +1 -0
  24. package/dist/lib/option-types/type-resolution.d.ts +126 -0
  25. package/dist/lib/option-types/type-resolution.js +7 -0
  26. package/dist/lib/option-types/type-resolution.js.map +1 -0
  27. package/dist/lib/parser.d.ts +218 -0
  28. package/{src → dist}/lib/parser.js +83 -13
  29. package/dist/lib/parser.js.map +1 -0
  30. package/dist/lib/parsers/array.js.map +1 -0
  31. package/dist/lib/parsers/boolean.js.map +1 -0
  32. package/dist/lib/parsers/number.js.map +1 -0
  33. package/{src → dist}/lib/parsers/object.d.ts +1 -1
  34. package/{src → dist}/lib/parsers/object.js +22 -1
  35. package/dist/lib/parsers/object.js.map +1 -0
  36. package/dist/lib/parsers/parser-map.js.map +1 -0
  37. package/dist/lib/parsers/string.js.map +1 -0
  38. package/dist/lib/parsers/typings.d.ts +11 -0
  39. package/dist/lib/parsers/typings.js.map +1 -0
  40. package/dist/lib/utils/case-transformations.js.map +1 -0
  41. package/dist/lib/utils/chain.d.ts +331 -0
  42. package/dist/lib/utils/chain.js.map +1 -0
  43. package/dist/lib/utils/flags.js.map +1 -0
  44. package/dist/lib/utils/get-configured-key.d.ts +3 -0
  45. package/dist/lib/utils/get-configured-key.js.map +1 -0
  46. package/dist/lib/utils/read-default-value.d.ts +2 -0
  47. package/{src → dist}/lib/utils/read-default-value.js +2 -0
  48. package/dist/lib/utils/read-default-value.js.map +1 -0
  49. package/package.json +17 -6
  50. package/src/lib/config-files/README.md +10 -0
  51. package/src/index.js.map +0 -1
  52. package/src/lib/config-files/configuration-loader.js.map +0 -1
  53. package/src/lib/config-files/index.js.map +0 -1
  54. package/src/lib/config-files/json-file-loader.js.map +0 -1
  55. package/src/lib/config-files/package-json-loader.js.map +0 -1
  56. package/src/lib/config-files/utils.js.map +0 -1
  57. package/src/lib/helpers.js.map +0 -1
  58. package/src/lib/option-types/array.js.map +0 -1
  59. package/src/lib/option-types/boolean.js.map +0 -1
  60. package/src/lib/option-types/common.js.map +0 -1
  61. package/src/lib/option-types/index.d.ts +0 -14
  62. package/src/lib/option-types/index.js.map +0 -1
  63. package/src/lib/option-types/number.js.map +0 -1
  64. package/src/lib/option-types/object.d.ts +0 -10
  65. package/src/lib/option-types/object.js.map +0 -1
  66. package/src/lib/option-types/option-config-to-type.d.ts +0 -26
  67. package/src/lib/option-types/option-config-to-type.js.map +0 -1
  68. package/src/lib/option-types/option-config.d.ts +0 -15
  69. package/src/lib/option-types/option-config.js.map +0 -1
  70. package/src/lib/option-types/string.js.map +0 -1
  71. package/src/lib/parser.d.ts +0 -269
  72. package/src/lib/parser.js.map +0 -1
  73. package/src/lib/parsers/array.js.map +0 -1
  74. package/src/lib/parsers/boolean.js.map +0 -1
  75. package/src/lib/parsers/number.js.map +0 -1
  76. package/src/lib/parsers/object.js.map +0 -1
  77. package/src/lib/parsers/parser-map.js.map +0 -1
  78. package/src/lib/parsers/string.js.map +0 -1
  79. package/src/lib/parsers/typings.d.ts +0 -11
  80. package/src/lib/parsers/typings.js.map +0 -1
  81. package/src/lib/utils/case-transformations.js.map +0 -1
  82. package/src/lib/utils/chain.d.ts +0 -397
  83. package/src/lib/utils/chain.js.map +0 -1
  84. package/src/lib/utils/flags.js.map +0 -1
  85. package/src/lib/utils/get-configured-key.d.ts +0 -3
  86. package/src/lib/utils/get-configured-key.js.map +0 -1
  87. package/src/lib/utils/read-default-value.d.ts +0 -2
  88. package/src/lib/utils/read-default-value.js.map +0 -1
  89. /package/{src → dist}/index.d.ts +0 -0
  90. /package/{src → dist}/index.js +0 -0
  91. /package/{src → dist}/lib/config-files/configuration-loader.d.ts +0 -0
  92. /package/{src → dist}/lib/config-files/configuration-loader.js +0 -0
  93. /package/{src → dist}/lib/config-files/index.d.ts +0 -0
  94. /package/{src → dist}/lib/config-files/index.js +0 -0
  95. /package/{src → dist}/lib/config-files/json-file-loader.d.ts +0 -0
  96. /package/{src → dist}/lib/config-files/json-file-loader.js +0 -0
  97. /package/{src → dist}/lib/config-files/package-json-loader.d.ts +0 -0
  98. /package/{src → dist}/lib/config-files/package-json-loader.js +0 -0
  99. /package/{src → dist}/lib/config-files/utils.d.ts +0 -0
  100. /package/{src → dist}/lib/config-files/utils.js +0 -0
  101. /package/{src → dist}/lib/helpers.d.ts +0 -0
  102. /package/{src → dist}/lib/helpers.js +0 -0
  103. /package/{src → dist}/lib/option-types/array.d.ts +0 -0
  104. /package/{src → dist}/lib/option-types/array.js +0 -0
  105. /package/{src → dist}/lib/option-types/boolean.d.ts +0 -0
  106. /package/{src → dist}/lib/option-types/boolean.js +0 -0
  107. /package/{src → dist}/lib/option-types/common.js +0 -0
  108. /package/{src → dist}/lib/option-types/number.d.ts +0 -0
  109. /package/{src → dist}/lib/option-types/number.js +0 -0
  110. /package/{src → dist}/lib/option-types/object.js +0 -0
  111. /package/{src → dist}/lib/option-types/option-config-to-type.js +0 -0
  112. /package/{src → dist}/lib/option-types/option-config.js +0 -0
  113. /package/{src → dist}/lib/option-types/string.d.ts +0 -0
  114. /package/{src → dist}/lib/option-types/string.js +0 -0
  115. /package/{src → dist}/lib/parsers/array.d.ts +0 -0
  116. /package/{src → dist}/lib/parsers/array.js +0 -0
  117. /package/{src → dist}/lib/parsers/boolean.d.ts +0 -0
  118. /package/{src → dist}/lib/parsers/boolean.js +0 -0
  119. /package/{src → dist}/lib/parsers/number.d.ts +0 -0
  120. /package/{src → dist}/lib/parsers/number.js +0 -0
  121. /package/{src → dist}/lib/parsers/parser-map.d.ts +0 -0
  122. /package/{src → dist}/lib/parsers/parser-map.js +0 -0
  123. /package/{src → dist}/lib/parsers/string.d.ts +0 -0
  124. /package/{src → dist}/lib/parsers/string.js +0 -0
  125. /package/{src → dist}/lib/parsers/typings.js +0 -0
  126. /package/{src → dist}/lib/utils/case-transformations.d.ts +0 -0
  127. /package/{src → dist}/lib/utils/case-transformations.js +0 -0
  128. /package/{src → dist}/lib/utils/chain.js +0 -0
  129. /package/{src → dist}/lib/utils/flags.d.ts +0 -0
  130. /package/{src → dist}/lib/utils/flags.js +0 -0
  131. /package/{src → dist}/lib/utils/get-configured-key.js +0 -0
package/LICENSE.md ADDED
@@ -0,0 +1,5 @@
1
+ Copyright 2024 Craigory Coppola
2
+
3
+ Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
4
+
5
+ THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,uDAA6B;AAC7B,2EAAiD;AACjD,wDAA8B;AAC9B,6DAAmC;AACnC,yEAA+C;AAC/C,4DAAkC;AAElC;;GAEG;AACH,iFAAyD"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configuration-loader.js","sourceRoot":"","sources":["../../../src/lib/config-files/configuration-loader.ts"],"names":[],"mappings":";;AAwBA,oDAgCC;AAxDD,+BAA4B;AAsB5B,iFAAiF;AACjF,yEAAyE;AACzE,SAAgB,oBAAoB,CAClC,iBAAyB,EACzB,OAAmC;IAEnC,SAAS,iBAAiB,CACxB,QAAgB,EAChB,QAAkC;QAElC,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACvC,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACnB,MAAM,QAAQ,GAAG,oBAAoB,CACnC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC;gBAC5B,CAAC,CAAC,IAAA,WAAI,EAAC,iBAAiB,EAAE,MAAM,CAAC,OAAO,CAAC;gBACzC,CAAC,CAAC,MAAM,CAAC,OAAO,EAClB,OAAO,CACR,CAAC;YACF,OAAO,EAAE,GAAG,QAAQ,EAAE,GAAG,MAAM,EAAE,CAAC;QACpC,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,IAAI,QAAQ,GAAM,EAAO,CAAC;IAC1B,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;QACnD,IAAI,QAAQ,EAAE,CAAC;YACb,QAAQ,GAAG;gBACT,GAAG,iBAAiB,CAAC,QAAQ,EAAE,MAAM,CAAC;gBACtC,GAAG,QAAQ;aACZ,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/config-files/index.ts"],"names":[],"mappings":";;;AAAA,iEAAuC;AACvC,6DAAmC;AACnC,gEAAsC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-file-loader.js","sourceRoot":"","sources":["../../../src/lib/config-files/json-file-loader.ts"],"names":[],"mappings":";;AAYA,0DAuCC;AAnDD,2BAAkC;AAClC,+BAA+B;AAG/B,mCAA0C;AAE1C;;;;;GAKG;AACH,SAAgB,uBAAuB,CACrC,QAAgB,EAChB,SAA4B;IAE5B,SAAS,YAAY,CAAC,QAAgB;QACpC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAA,iBAAY,EAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;IACrD,CAAC;IAED,MAAM,oBAAoB;QAChB,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;QAEjC,OAAO,CAAC,iBAAyB;YAC/B,MAAM,WAAW,GAAG,IAAA,uBAAe,EAAC,QAAQ,EAAE,iBAAiB,CAAC,CAAC;YACjE,IAAI,CAAC,WAAW,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;gBACnD,OAAO,SAAS,CAAC;YACnB,CAAC;YACD,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;gBAC/B,MAAM,IAAI,KAAK,CACb,sDAAsD,WAAW,sHAAsH,CACxL,CAAC;YACJ,CAAC;YACD,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;YAC3B,OAAO,WAAW,CAAC;QACrB,CAAC;QAED,IAAI,CAAC,QAAgB;YACnB,MAAM,IAAI,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC;YACpC,IAAI,SAAS,EAAE,CAAC;gBACd,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC;YACzB,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;QAED,CAAC,cAAO,CAAC,MAAM,CAAC;YACd,OAAO,wBAAwB,GAAG,QAAQ,CAAC;QAC7C,CAAC;KACF;IAED,OAAO,IAAI,oBAAoB,EAAE,CAAC;AACpC,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package-json-loader.js","sourceRoot":"","sources":["../../../src/lib/config-files/package-json-loader.ts"],"names":[],"mappings":";;AAUA,8EAUC;AApBD,yCAAoC;AAGpC,yDAA6D;AAE7D;;;;GAIG;AACH,SAAgB,iCAAiC,CAC/C,GAAW;IAEX,MAAM,MAAM,GAAG,IAAA,0CAAuB,EACpC,cAAc,EACd,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CACpB,CAAC;IACD,MAAc,CAAC,mBAAO,CAAC,MAAM,CAAC,GAAG,GAAG,EAAE,CACrC,kCAAkC,GAAG,GAAG,CAAC;IAC3C,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/lib/config-files/utils.ts"],"names":[],"mappings":";;AAGA,0CAiBC;AApBD,qCAAqC;AACrC,yCAA0C;AAE1C,SAAgB,eAAe,CAC7B,cAAsB,EACtB,SAAS,GAAG,OAAO,CAAC,GAAG,EAAE;IAEzB,4CAA4C;IAC5C,IAAI,IAAwB,CAAC;IAC7B,IAAI,OAAO,GAAG,SAAS,CAAC;IACxB,OAAO,IAAI,KAAK,OAAO,EAAE,CAAC;QACxB,IAAI,GAAG,OAAO,CAAC;QACf,MAAM,QAAQ,GAAG,IAAA,gBAAI,EAAC,OAAO,EAAE,cAAc,CAAC,CAAC;QAC/C,IAAI,IAAA,oBAAU,EAAC,QAAQ,CAAC,EAAE,CAAC;YACzB,OAAO,QAAQ,CAAC;QAClB,CAAC;aAAM,CAAC;YACN,OAAO,GAAG,IAAA,mBAAO,EAAC,OAAO,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/lib/helpers.ts"],"names":[],"mappings":";AAAA,iFAAiF;;AAwBjF,0BAEC;AAED,wBAEC;AA5BD,SAAS,sBAAsB;IAC7B,0DAA0D;IAC1D,qDAAqD;IACrD,IAAI,oBAAoB,EAAE;QAAE,OAAO,CAAC,CAAC;IACrC,mCAAmC;IACnC,0DAA0D;IAC1D,kEAAkE;IAClE,OAAO,CAAC,CAAC;AACX,CAAC;AAED,SAAS,oBAAoB;IAC3B,0FAA0F;IAC1F,oGAAoG;IACpG,OAAO,aAAa,EAAE,IAAI,CAAE,OAA2B,CAAC,UAAU,CAAC;AACrE,CAAC;AAED,SAAS,aAAa;IACpB,oEAAoE;IACpE,0GAA0G;IAC1G,OAAO,CAAC,CAAE,OAA2B,CAAC,QAAQ,CAAC,QAAQ,CAAC;AAC1D,CAAC;AAED,SAAgB,OAAO,CAAC,IAAc;IACpC,OAAO,IAAI,CAAC,KAAK,CAAC,sBAAsB,EAAE,GAAG,CAAC,CAAC,CAAC;AAClD,CAAC;AAED,SAAgB,MAAM,CAAC,IAAc;IACnC,OAAO,IAAI,CAAC,sBAAsB,EAAE,CAAC,CAAC;AACxC,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array.js","sourceRoot":"","sources":["../../../src/lib/option-types/array.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"boolean.js","sourceRoot":"","sources":["../../../src/lib/option-types/boolean.ts"],"names":[],"mappings":""}
@@ -26,7 +26,7 @@ export type CommonOptionConfig<T, TCoerce = T, TChoices = T[]> = {
26
26
  *
27
27
  * If the default value is a tuple, the first value will be used as the default value, and the second value will be used as the description.
28
28
  */
29
- default?: Default<T>;
29
+ default?: Default<NoInfer<T>>;
30
30
  /**
31
31
  * Provide a description for the option.
32
32
  */
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/lib/option-types/common.ts"],"names":[],"mappings":""}
@@ -0,0 +1,15 @@
1
+ import { OptionConfig, UnknownOptionConfig } from './option-config';
2
+ export * from './option-config-to-type';
3
+ export * from './type-resolution';
4
+ export * from './common';
5
+ export * from './array';
6
+ export * from './boolean';
7
+ export * from './number';
8
+ export * from './object';
9
+ export * from './string';
10
+ export type { OptionConfig, UnknownOptionConfig };
11
+ export type Internal<T extends UnknownOptionConfig> = T & InternalOptionConfig;
12
+ export type InternalOptionConfig = UnknownOptionConfig & {
13
+ key: string;
14
+ position?: number;
15
+ };
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./option-config-to-type"), exports);
5
+ tslib_1.__exportStar(require("./type-resolution"), exports);
5
6
  tslib_1.__exportStar(require("./common"), exports);
6
7
  tslib_1.__exportStar(require("./array"), exports);
7
8
  tslib_1.__exportStar(require("./boolean"), exports);
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/option-types/index.ts"],"names":[],"mappings":";;;AAEA,kEAAwC;AACxC,4DAAkC;AAClC,mDAAyB;AACzB,kDAAwB;AACxB,oDAA0B;AAC1B,mDAAyB;AACzB,mDAAyB;AACzB,mDAAyB"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"number.js","sourceRoot":"","sources":["../../../src/lib/option-types/number.ts"],"names":[],"mappings":""}
@@ -0,0 +1,74 @@
1
+ import { CommonOptionConfig, Default } from './common';
2
+ import { ResolveProperties, AdditionalPropertiesType } from './type-resolution';
3
+ /**
4
+ * Compute the full value type for an object option.
5
+ * Resolves each property to its final type (respecting optional/required)
6
+ * and adds an index signature if additionalProperties is set.
7
+ *
8
+ * Uses a structural constraint for TProperties to avoid circular imports
9
+ * with option-config.ts.
10
+ */
11
+ type ObjectValue<TProperties extends Record<string, {
12
+ type: string;
13
+ }>, TAdditionalProperties extends false | 'string' | 'number' | 'boolean'> = ResolveProperties<TProperties> & AdditionalPropertiesType<TAdditionalProperties>;
14
+ /**
15
+ * Configuration for object options. Objects are parsed from dot notation
16
+ * or JSON strings.
17
+ *
18
+ * e.g. `--config.host localhost --config.port 3000` or `--config '{"host":"localhost"}'`
19
+ *
20
+ * Note: This type explicitly lists all fields from CommonOptionConfig instead of using
21
+ * Omit<CommonOptionConfig<TValue>, ...> to avoid circular type inference issues.
22
+ * When Omit is used, TypeScript must fully evaluate CommonOptionConfig<TValue> first,
23
+ * which requires computing TValue from TProperties, creating a circular dependency
24
+ * when callbacks reference nested properties.
25
+ */
26
+ /**
27
+ * Configuration for object options. Objects are parsed from dot notation
28
+ * or JSON strings.
29
+ *
30
+ * e.g. `--config.host localhost --config.port 3000` or `--config '{"host":"localhost"}'`
31
+ *
32
+ * Note: This type explicitly lists all fields from CommonOptionConfig instead of using
33
+ * Omit<CommonOptionConfig<TValue>, ...> to avoid circular type inference issues.
34
+ * When Omit is used, TypeScript must fully evaluate CommonOptionConfig<TValue> first,
35
+ * which requires computing TValue from TProperties, creating a circular dependency
36
+ * when callbacks reference nested properties.
37
+ */
38
+ /**
39
+ * Compute the validate parameter type for object options.
40
+ * When coerce is provided, validate receives the coerced type (TCoerce).
41
+ * When coerce is not provided, validate receives the computed ObjectValue type.
42
+ *
43
+ * Uses `unknown extends TCoerce` to detect if TCoerce was not explicitly provided,
44
+ * since it defaults to `unknown` when no coerce function is given.
45
+ */
46
+ type ObjectValidateType<TCoerce, TProperties extends Record<string, {
47
+ type: string;
48
+ }>, TAdditionalProperties extends false | 'string' | 'number' | 'boolean'> = unknown extends TCoerce ? ObjectValue<TProperties, TAdditionalProperties> : TCoerce;
49
+ export type ObjectOptionConfig<TCoerce, TProperties extends Record<string, {
50
+ type: string;
51
+ }>, TAdditionalProperties extends false | 'string' | 'number' | 'boolean' = false> = {
52
+ [key in keyof Omit<CommonOptionConfig<ObjectValue<NoInfer<TProperties>, NoInfer<TAdditionalProperties>>, NoInfer<TCoerce>>, 'choices' | 'coerce' | 'validate' | 'default'>]: CommonOptionConfig<ObjectValue<NoInfer<TProperties>, NoInfer<TAdditionalProperties>>, NoInfer<TCoerce>>[key];
53
+ } & {
54
+ type: 'object';
55
+ properties: TProperties;
56
+ additionalProperties?: TAdditionalProperties;
57
+ /**
58
+ * Provide a default value for the entire object.
59
+ * Uses a permissive type (object) to avoid interfering with TProperties inference.
60
+ * The actual type checking happens at runtime.
61
+ */
62
+ default?: Default<object>;
63
+ /**
64
+ * Coerce transforms the parsed object value.
65
+ * The return type becomes the final type for this option.
66
+ */
67
+ coerce?: (value: ObjectValue<TProperties, NoInfer<TAdditionalProperties>>) => TCoerce;
68
+ /**
69
+ * Validate the object value after coercion (or the raw value if no coerce).
70
+ * Receives the coerced type if coerce is provided, otherwise the computed ObjectValue type.
71
+ */
72
+ validate?: (value: ObjectValidateType<TCoerce, TProperties, TAdditionalProperties>) => boolean | string;
73
+ };
74
+ export {};
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object.js","sourceRoot":"","sources":["../../../src/lib/option-types/object.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ import { ResolveOptionType, WithOptional, ResolveProperties, AdditionalPropertiesType } from './type-resolution';
2
+ /**
3
+ * Converts an OptionConfig to the TypeScript type for the parsed value.
4
+ * Uses shared type resolution logic from type-resolution.ts.
5
+ */
6
+ export type OptionConfigToType<TOptionConfig extends {
7
+ type: string;
8
+ }> = WithOptional<ResolveOptionType<TOptionConfig>, TOptionConfig>;
9
+ export type { ResolveProperties, AdditionalPropertiesType };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"option-config-to-type.js","sourceRoot":"","sources":["../../../src/lib/option-types/option-config-to-type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,24 @@
1
+ import { ArrayOptionConfig } from './array';
2
+ import { BooleanOptionConfig } from './boolean';
3
+ import { NumberOptionConfig } from './number';
4
+ import { ObjectOptionConfig } from './object';
5
+ import { StringOptionConfig } from './string';
6
+ /**
7
+ * Configures an option for the parser. See subtypes for more information.
8
+ * - {@link StringOptionConfig}
9
+ * - {@link NumberOptionConfig}
10
+ * - {@link ArrayOptionConfig}
11
+ * - {@link BooleanOptionConfig}
12
+ *
13
+ * @typeParam TCoerce The return type of the `coerce` function if provided.
14
+ */
15
+ export type OptionConfig<TCoerce = any, TChoices = any[], TObjectProps extends Record<string, {
16
+ type: string;
17
+ }> = Record<string, any>, TAdditionalProps extends false | 'string' | 'number' | 'boolean' = false> = StringOptionConfig<TCoerce, TChoices> | NumberOptionConfig<TCoerce, TChoices> | ArrayOptionConfig<TCoerce, TChoices> | BooleanOptionConfig<TCoerce, TChoices> | ObjectOptionConfig<TCoerce, TObjectProps, TAdditionalProps>;
18
+ /**
19
+ * An OptionConfig with generic parameters set for maximum compatibility.
20
+ * Uses `any` for all type parameters to allow maximum assignability.
21
+ * The IsAny check in AdditionalPropertiesType handles the case where
22
+ * TAdditionalProps is `any` by returning `unknown` instead of an index signature.
23
+ */
24
+ export type UnknownOptionConfig = OptionConfig<any, any, any, any>;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"option-config.js","sourceRoot":"","sources":["../../../src/lib/option-types/option-config.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.js","sourceRoot":"","sources":["../../../src/lib/option-types/string.ts"],"names":[],"mappings":""}
@@ -0,0 +1,126 @@
1
+ /**
2
+ * Core type resolution utilities for option configs.
3
+ * Uses structural typing to avoid circular imports.
4
+ */
5
+ /**
6
+ * Check if a type is `any`.
7
+ * Uses the property that `1 & any` is `any`, and `0 extends any` is true.
8
+ */
9
+ type IsAny<T> = 0 extends 1 & T ? true : false;
10
+ /**
11
+ * Force TypeScript to fully expand a type.
12
+ * This helps with deferred type evaluation in recursive types.
13
+ */
14
+ export type Expand<T> = T extends infer O ? {
15
+ [K in keyof O]: O[K];
16
+ } : never;
17
+ /**
18
+ * Deeply expand a type, including nested objects.
19
+ */
20
+ export type ExpandDeep<T> = T extends object ? T extends infer O ? {
21
+ [K in keyof O]: ExpandDeep<O[K]>;
22
+ } : never : T;
23
+ /**
24
+ * Infer the choice type from an option config.
25
+ * Choices can be an array (including readonly) or a function returning an array.
26
+ */
27
+ export type InferChoice<T> = T extends {
28
+ choices: readonly (infer C)[];
29
+ } ? C : T extends {
30
+ choices: () => readonly (infer C)[];
31
+ } ? C : never;
32
+ /**
33
+ * Infer the coerced type. If coerce function exists, use its return type.
34
+ * Otherwise fall back to the provided fallback type.
35
+ *
36
+ * Uses optional property matching `coerce?:` to handle configs where coerce
37
+ * is defined as optional (like ObjectOptionConfig).
38
+ *
39
+ * Special handling:
40
+ * - [R] extends [never]: When coerce is missing/undefined, R infers as never
41
+ * - R extends undefined: When coerce explicitly returns undefined
42
+ */
43
+ export type InferCoerce<T, TFallback> = T extends {
44
+ coerce?: (v: any) => infer R;
45
+ } ? [R] extends [never] ? TFallback : R extends undefined ? TFallback : R : TFallback;
46
+ /**
47
+ * Map an option config to its base TypeScript type.
48
+ * Uses structural typing to avoid circular imports.
49
+ */
50
+ export type BaseType<T> = T extends {
51
+ type: 'string';
52
+ } ? string : T extends {
53
+ type: 'number';
54
+ } ? number : T extends {
55
+ type: 'boolean';
56
+ } ? boolean : T extends {
57
+ type: 'array';
58
+ items: 'string';
59
+ } ? string[] : T extends {
60
+ type: 'array';
61
+ items: 'number';
62
+ } ? number[] : T extends {
63
+ type: 'object';
64
+ properties: infer P;
65
+ additionalProperties: infer A;
66
+ } ? P extends Record<string, unknown> ? ResolveProperties<P> & AdditionalPropertiesType<A> : never : T extends {
67
+ type: 'object';
68
+ properties: infer P;
69
+ } ? P extends Record<string, unknown> ? ResolveProperties<P> : never : never;
70
+ /**
71
+ * Resolve a single option config to its final type.
72
+ * Priority: choices > coerce > base type
73
+ */
74
+ export type ResolveOptionType<T> = InferChoice<T> extends never ? InferCoerce<T, BaseType<T>> : InferChoice<T>;
75
+ /**
76
+ * Wrap a resolved type with undefined if the option is optional.
77
+ * Required options or options with defaults are never undefined.
78
+ *
79
+ * Uses `'key' extends keyof TConfig` instead of `TConfig extends { key: unknown }`
80
+ * to properly detect OPTIONAL properties. The latter check fails for optional
81
+ * properties because `{ default?: X }` doesn't guarantee `default` exists.
82
+ */
83
+ export type WithOptional<TResolved, TConfig> = TConfig extends {
84
+ required: true;
85
+ } ? TResolved : 'default' extends keyof TConfig ? TResolved : TResolved | undefined;
86
+ /**
87
+ * Resolve all properties of an object option to their types.
88
+ * Each property becomes its resolved type, wrapped with optional handling.
89
+ *
90
+ * Special case: when TProperties is `any` (from `OptionConfig<any, any, any, any>`),
91
+ * we return `unknown` to avoid creating an index signature that would hide
92
+ * the actual properties inferred from the value.
93
+ */
94
+ export type ResolveProperties<TProperties> = IsAny<TProperties> extends true ? unknown : {
95
+ [K in keyof TProperties]: WithOptional<ResolveOptionType<TProperties[K]>, TProperties[K]>;
96
+ };
97
+ /**
98
+ * Map the additionalProperties field to an index signature type.
99
+ * If false, undefined, or any, contributes nothing to the type.
100
+ *
101
+ * IMPORTANT: We use `unknown` in the index signature instead of the strict
102
+ * primitive type (e.g., `Record<string, string>`) to avoid conflicts with
103
+ * explicit nested properties. TypeScript's index signatures require ALL values
104
+ * (including explicit properties) to be assignable to the index type. Using
105
+ * `Record<string, string>` would make `{ server: {...} } & Record<string, string>`
106
+ * impossible since the nested object isn't a string.
107
+ *
108
+ * By using `{ [K: string]: unknown }`, the type is "open" - explicit properties
109
+ * retain their types while additional dynamic keys are allowed. Type safety
110
+ * for additional properties is enforced at runtime during parsing.
111
+ *
112
+ * Uses tuple wrapping to prevent distribution over unions.
113
+ */
114
+ export type AdditionalPropertiesType<T> = IsAny<T> extends true ? unknown : [T] extends [false] ? unknown : [T] extends ['string'] ? {
115
+ [K: string]: string;
116
+ } : [T] extends ['number'] ? {
117
+ [K: string]: number;
118
+ } : [T] extends ['boolean'] ? {
119
+ [K: string]: boolean;
120
+ } : unknown;
121
+ /**
122
+ * Compute the full value type for an object option.
123
+ * Combines resolved properties with additional properties index signature.
124
+ */
125
+ export type ObjectValueType<TProperties, TAdditionalProperties> = ResolveProperties<TProperties> & AdditionalPropertiesType<TAdditionalProperties>;
126
+ export {};
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * Core type resolution utilities for option configs.
4
+ * Uses structural typing to avoid circular imports.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ //# sourceMappingURL=type-resolution.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-resolution.js","sourceRoot":"","sources":["../../../src/lib/option-types/type-resolution.ts"],"names":[],"mappings":";AAAA;;;GAGG"}
@@ -0,0 +1,218 @@
1
+ import { OptionConfigToType, ResolveProperties, AdditionalPropertiesType } from './option-types/option-config-to-type';
2
+ import { WithOptional } from './option-types/type-resolution';
3
+ import { InternalOptionConfig, ObjectOptionConfig, StringOptionConfig, NumberOptionConfig, BooleanOptionConfig, ArrayOptionConfig, OptionConfig } from './option-types';
4
+ import { Parser, ParserContext } from './parsers/typings';
5
+ import { ConfigurationProvider } from './config-files/configuration-loader';
6
+ /**
7
+ * Defines the option configuration passed to {@link ArgvParser.env}.
8
+ */
9
+ export type EnvOptionConfig = {
10
+ prefix?: string;
11
+ reflect?: boolean;
12
+ populate?: boolean;
13
+ };
14
+ /**
15
+ * Base type for parsed arguments.
16
+ */
17
+ export type ParsedArgs<T = never> = [T] extends [never] ? {
18
+ /**
19
+ * Contains any unmatched arguments as originally passed to the parser.
20
+ */
21
+ unmatched: string[];
22
+ /**
23
+ * Contains any arguments passed after `--`, which halts parsing of flags.
24
+ */
25
+ '--'?: string[];
26
+ } : {
27
+ /**
28
+ * Contains any unmatched arguments as originally passed to the parser.
29
+ */
30
+ unmatched: string[];
31
+ /**
32
+ * Contains any arguments passed after `--`, which halts parsing of flags.
33
+ */
34
+ '--'?: string[];
35
+ } & T;
36
+ /**
37
+ * Extra options for the parser
38
+ */
39
+ export type ParserOptions<T extends ParsedArgs = ParsedArgs> = {
40
+ /**
41
+ * Can be used to implement custom parser types.
42
+ */
43
+ extraParsers?: Record<string, Parser<any>>;
44
+ /**
45
+ * Can be used to implement custom handling for unmatched arguments.
46
+ * @returns true if the argument was handled, false if it was not
47
+ */
48
+ unmatchedParser?: (arg: string, tokens: string[], parser: ArgvParser<T>) => boolean;
49
+ };
50
+ export interface ReadonlyArgvParser<TArgs extends ParsedArgs> {
51
+ configuredOptions: Readonly<{
52
+ [key in keyof TArgs]: InternalOptionConfig;
53
+ }>;
54
+ configuredPositionals: readonly Readonly<InternalOptionConfig>[];
55
+ options: Readonly<Required<ParserOptions<TArgs>>>;
56
+ }
57
+ /**
58
+ * The main parser class. This class is used to configure and parse arguments.
59
+ *
60
+ * {@link parser} is a small helper function to create a new parser instance.
61
+ */
62
+ export declare class ArgvParser<TArgs extends ParsedArgs = {
63
+ unmatched: string[];
64
+ }> implements ReadonlyArgvParser<TArgs> {
65
+ /**
66
+ * The configured options for the parser.
67
+ */
68
+ configuredOptions: {
69
+ [key in keyof TArgs]: InternalOptionConfig;
70
+ };
71
+ /**
72
+ * The configured positional arguments for the parser
73
+ */
74
+ configuredPositionals: InternalOptionConfig[];
75
+ /**
76
+ * The configured conflicts for the parser. If an option is set, and a conflicting option is also set, an error will be thrown.
77
+ */
78
+ configuredConflicts: Record<string, Set<string>>;
79
+ /**
80
+ * The configured implies for the parser. If an option is set, the implied option must also be set.
81
+ */
82
+ configuredImplies: Record<string, Set<string>>;
83
+ /**
84
+ * The configuration for the parser itself
85
+ */
86
+ options: Required<ParserOptions<TArgs>>;
87
+ /**
88
+ * The parsers used to parse individual option types.
89
+ */
90
+ parserMap: Record<string, Parser<any>>;
91
+ private configuredConfigurationProviders;
92
+ /**
93
+ * If set, options can be populated from environment variables of the form `${envPrefix}_${optionName}`.
94
+ */
95
+ private envPrefix?;
96
+ private shouldReadFromEnv?;
97
+ private shouldReflectEnv?;
98
+ /**
99
+ * Creates a new parser. Normally using {@link parser} is preferred.
100
+ * @param options
101
+ */
102
+ constructor(options?: ParserOptions<TArgs>);
103
+ /**
104
+ * Registers a new option with the parser.
105
+ * @param name The name of the option
106
+ * @param config The configuration for the option. See {@link UnknownOptionConfig}
107
+ * @returns Updated parser instance with the new option registered.
108
+ */
109
+ option<TOption extends string, TCoerce, const TProps extends Record<string, {
110
+ type: string;
111
+ }>, TAdditionalProps extends false | 'string' | 'number' | 'boolean' = false>(name: TOption, config: ObjectOptionConfig<TCoerce, TProps, TAdditionalProps>): ArgvParser<TArgs & {
112
+ [key in TOption]: WithOptional<unknown extends TCoerce ? ResolveProperties<TProps> & AdditionalPropertiesType<TAdditionalProps> : TCoerce, ObjectOptionConfig<TCoerce, TProps, TAdditionalProps>>;
113
+ }>;
114
+ option<TOption extends string, const TConfig extends StringOptionConfig<any, any>>(name: TOption, config: TConfig): ArgvParser<TArgs & {
115
+ [key in TOption]: OptionConfigToType<TConfig>;
116
+ }>;
117
+ option<TOption extends string, const TConfig extends NumberOptionConfig<any, any>>(name: TOption, config: TConfig): ArgvParser<TArgs & {
118
+ [key in TOption]: OptionConfigToType<TConfig>;
119
+ }>;
120
+ option<TOption extends string, const TConfig extends BooleanOptionConfig<any, any>>(name: TOption, config: TConfig): ArgvParser<TArgs & {
121
+ [key in TOption]: OptionConfigToType<TConfig>;
122
+ }>;
123
+ option<TOption extends string, const TConfig extends ArrayOptionConfig<any, any>>(name: TOption, config: TConfig): ArgvParser<TArgs & {
124
+ [key in TOption]: OptionConfigToType<TConfig>;
125
+ }>;
126
+ option<TOption extends string, const TOptionConfig extends OptionConfig<any, any, any, any>>(name: TOption, config: TOptionConfig): ArgvParser<TArgs & {
127
+ [key in TOption]: OptionConfigToType<TOptionConfig>;
128
+ }>;
129
+ /**
130
+ * Registers a new positional argument with the parser.
131
+ * @param name The name of the positional argument
132
+ * @param config The configuration for the positional argument. See {@link UnknownOptionConfig}
133
+ * @returns Updated parser instance with the new positional argument registered.
134
+ */
135
+ positional<TOption extends string, TCoerce, const TProps extends Record<string, {
136
+ type: string;
137
+ }>, TAdditionalProps extends false | 'string' | 'number' | 'boolean' = false>(name: TOption, config: ObjectOptionConfig<TCoerce, TProps, TAdditionalProps>): ArgvParser<TArgs & {
138
+ [key in TOption]: WithOptional<unknown extends TCoerce ? ResolveProperties<TProps> & AdditionalPropertiesType<TAdditionalProps> : TCoerce, ObjectOptionConfig<TCoerce, TProps, TAdditionalProps>>;
139
+ }>;
140
+ positional<TOption extends string, const TConfig extends StringOptionConfig<any, any>>(name: TOption, config: TConfig): ArgvParser<TArgs & {
141
+ [key in TOption]: OptionConfigToType<TConfig>;
142
+ }>;
143
+ positional<TOption extends string, const TConfig extends NumberOptionConfig<any, any>>(name: TOption, config: TConfig): ArgvParser<TArgs & {
144
+ [key in TOption]: OptionConfigToType<TConfig>;
145
+ }>;
146
+ positional<TOption extends string, const TConfig extends BooleanOptionConfig<any, any>>(name: TOption, config: TConfig): ArgvParser<TArgs & {
147
+ [key in TOption]: OptionConfigToType<TConfig>;
148
+ }>;
149
+ positional<TOption extends string, const TConfig extends ArrayOptionConfig<any, any>>(name: TOption, config: TConfig): ArgvParser<TArgs & {
150
+ [key in TOption]: OptionConfigToType<TConfig>;
151
+ }>;
152
+ positional<TOption extends string, const TOptionConfig extends OptionConfig<any, any, any, any>>(name: TOption, config: TOptionConfig): ArgvParser<TArgs & {
153
+ [key in TOption]: OptionConfigToType<TOptionConfig>;
154
+ }>;
155
+ /**
156
+ * Enables environment variable population for options.
157
+ * @param envPrefix Prefix for environment variables. The full environment variable name will be `${envPrefix}_${optionName}`.
158
+ */
159
+ env(envPrefix?: string): typeof this;
160
+ env(options: EnvOptionConfig): typeof this;
161
+ /**
162
+ * Registers a configuration provider to read configuration from.
163
+ * @param provider The configuration provider to register.
164
+ */
165
+ config(provider: ConfigurationProvider<TArgs>): this;
166
+ /**
167
+ * Parses an array of arguments into a structured object.
168
+ * @param argv The array of arguments to parse
169
+ * @returns The parsed arguments
170
+ */
171
+ parse(argv?: string[]): TArgs;
172
+ private normalizeOptions;
173
+ private validateAndNormalizeResults;
174
+ private readFromEnv;
175
+ private reflectEnv;
176
+ private cachedConfigKey;
177
+ private cachedConfig;
178
+ private getEnvKey;
179
+ private readFromConfig;
180
+ /**
181
+ * Registers that a set of options cannot be provided at the same time.
182
+ * @param options The options that cannot be provided together.
183
+ */
184
+ conflicts(...options: [string, string, ...string[]]): this;
185
+ /**
186
+ * Registers that the presence of one option implies the presence of one or more other options.
187
+ * @param options The options that imply the other option.
188
+ */
189
+ implies(option: string, ...options: string[]): this;
190
+ /**
191
+ * Used to combine two parsers into a single parser. Mutates `this`, but returns with updated typings
192
+ * @param parser The parser to augment the current parser with.
193
+ * @returns The updated parser instance.
194
+ */
195
+ augment<TAugment extends ParsedArgs>(parser: ArgvParser<TAugment>): ArgvParser<TArgs & TAugment>;
196
+ clone(parserOptions?: ParserOptions<TArgs>): ArgvParser<TArgs>;
197
+ asReadonly(): ReadonlyArgvParser<TArgs>;
198
+ }
199
+ /**
200
+ * Small helper function to create a new parser instance.
201
+ * @param opts see {@link ParserOptions}
202
+ * @returns new parser, see {@link ArgvParser}
203
+ */
204
+ export declare function parser(opts?: ParserOptions): ArgvParser<{
205
+ /**
206
+ * Contains any unmatched arguments as originally passed to the parser.
207
+ */
208
+ unmatched: string[];
209
+ /**
210
+ * Contains any arguments passed after `--`, which halts parsing of flags.
211
+ */
212
+ '--'?: string[];
213
+ }>;
214
+ export declare function tryParseValue(parser: Parser<InternalOptionConfig>, input: ParserContext<InternalOptionConfig>): any;
215
+ export declare class ValidationFailedError<T> extends AggregateError {
216
+ partialArgV: Partial<T>;
217
+ constructor(errors: Error[], message: string, partialArgV: Partial<T>);
218
+ }