@travetto/cli 7.0.0-rc.0 → 7.0.0-rc.1

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 (2) hide show
  1. package/package.json +3 -3
  2. package/src/schema.ts +14 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/cli",
3
- "version": "7.0.0-rc.0",
3
+ "version": "7.0.0-rc.1",
4
4
  "description": "CLI infrastructure for Travetto framework",
5
5
  "keywords": [
6
6
  "cli",
@@ -28,8 +28,8 @@
28
28
  "directory": "module/cli"
29
29
  },
30
30
  "dependencies": {
31
- "@travetto/schema": "^7.0.0-rc.0",
32
- "@travetto/terminal": "^7.0.0-rc.0"
31
+ "@travetto/schema": "^7.0.0-rc.1",
32
+ "@travetto/terminal": "^7.0.0-rc.1"
33
33
  },
34
34
  "travetto": {
35
35
  "displayName": "Command Line Interface",
package/src/schema.ts CHANGED
@@ -1,9 +1,19 @@
1
1
  import { castKey, castTo, getClass } from '@travetto/runtime';
2
2
  import { BindUtil, SchemaRegistryIndex, SchemaValidator, ValidationResultError } from '@travetto/schema';
3
3
 
4
- import { ParsedState, CliCommandShape } from './types.ts';
4
+ import { ParsedState, CliCommandShape, CliValidationError } from './types.ts';
5
5
  import { CliValidationResultError } from './error.ts';
6
6
 
7
+ const getSource = (source: string | undefined, def: CliValidationError['source']): CliValidationError['source'] => {
8
+ switch (source) {
9
+ case 'custom':
10
+ case 'arg':
11
+ case 'flag': return source;
12
+ case undefined: return def;
13
+ default: return 'custom';
14
+ }
15
+ };
16
+
7
17
  /**
8
18
  * Allows binding describing/binding inputs for commands
9
19
  */
@@ -47,7 +57,7 @@ export class CliCommandSchemaUtil {
47
57
  */
48
58
  static async validate(cmd: CliCommandShape, args: unknown[]): Promise<typeof cmd> {
49
59
  const cls = getClass(cmd);
50
- const paramNames = SchemaRegistryIndex.getMethodConfig(cls, 'main').parameters.map(x => x.name!);
60
+ const paramNames = SchemaRegistryIndex.get(cls).getMethod('main').parameters.map(x => x.name!);
51
61
 
52
62
  const validators = [
53
63
  (): Promise<void> => SchemaValidator.validate(cls, cmd).then(() => { }),
@@ -60,13 +70,13 @@ export class CliCommandSchemaUtil {
60
70
  },
61
71
  ];
62
72
 
63
- const SOURCES = ['flag', 'arg', 'custom'];
73
+ const SOURCES = ['flag', 'arg', 'custom'] as const;
64
74
 
65
75
  const results = validators.map((x, i) => x().catch(err => {
66
76
  if (!(err instanceof CliValidationResultError) && !(err instanceof ValidationResultError)) {
67
77
  throw err;
68
78
  }
69
- return err.details.errors.map(v => ({ source: SOURCES[i], ...v }));
79
+ return err.details.errors.map(v => ({ ...v, source: getSource(v.source, SOURCES[i]) }));
70
80
  }));
71
81
 
72
82
  const errors = (await Promise.all(results)).flatMap(x => (x ?? []));