@styx-api/core 0.6.1 → 0.7.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.
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { ArgdumpParser } from "./frontend/argdump/index.js";
2
+ import { ArgtypeParser } from "./frontend/argtype/index.js";
2
3
  import { BoutiquesParser } from "./frontend/boutiques/index.js";
3
4
  import { MrtrixParser } from "./frontend/mrtrix/index.js";
4
5
  import { WorkbenchParser } from "./frontend/workbench/index.js";
@@ -22,7 +23,10 @@ export function compile(
22
23
  ? { filename: filenameOrOptions }
23
24
  : (filenameOrOptions ?? {});
24
25
 
25
- const format = options.format ?? detectFormat(source);
26
+ // An explicit `.argtype` filename selects the DSL frontend even though the
27
+ // source is not JSON (detection by content is a fallback).
28
+ const byExtension = options.filename?.endsWith(".argtype") ? "argtype" : undefined;
29
+ const format = options.format ?? byExtension ?? detectFormat(source);
26
30
 
27
31
  if (!format) {
28
32
  return {
@@ -32,13 +36,23 @@ export function compile(
32
36
  };
33
37
  }
34
38
 
35
- const parser =
36
- format === "argdump"
37
- ? new ArgdumpParser()
38
- : format === "workbench"
39
- ? new WorkbenchParser()
40
- : format === "mrtrix"
41
- ? new MrtrixParser()
42
- : new BoutiquesParser();
39
+ const parser = ((): { parse: (s: string, f?: string) => ParseResult } => {
40
+ switch (format) {
41
+ case "argdump":
42
+ return new ArgdumpParser();
43
+ case "argtype":
44
+ return new ArgtypeParser();
45
+ case "workbench":
46
+ return new WorkbenchParser();
47
+ case "mrtrix":
48
+ return new MrtrixParser();
49
+ case "boutiques":
50
+ return new BoutiquesParser();
51
+ default: {
52
+ const _exhaustive: never = format;
53
+ return new BoutiquesParser();
54
+ }
55
+ }
56
+ })();
43
57
  return parser.parse(source, options.filename);
44
58
  }