@loculus/infer 0.0.0 → 0.1.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/CHANGELOG.md ADDED
@@ -0,0 +1,17 @@
1
+ # @loculus/infer
2
+
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 82a7ce5: Use the TypeScript 7.1 beta Corsa API for type extraction and replace tinyglobby with glob and minimatch, removing ts-morph and picomatch from the package's runtime dependency graph. Preserve type equivalence, description comments, imports, exclusions, and symlink traversal. Generated union members and compiler-derived object properties may appear in a different order. Extractor instances support `using` and `dispose()` to release their native compiler session; `generate()` manages this automatically.
8
+
9
+ The extractor now requires TypeScript’s optional platform-specific native compiler package. Install optional dependencies and dispose extractor instances when finished.
10
+
11
+ ## 0.0.1
12
+
13
+ ### Patch Changes
14
+
15
+ - f42f278: Add `@loculus/infer`, a CLI and library that extracts `Input` and `Output` types of Loculus schemas as TypeScript source.
16
+ - Updated dependencies [f42f278]
17
+ - loculus@0.4.1
package/README.md CHANGED
@@ -8,6 +8,8 @@ Use it to publish readable types for an API, to check generated types into a rep
8
8
  npm install --save-dev @loculus/infer
9
9
  ```
10
10
 
11
+ Requires Node.js 22.18 or later. Type extraction uses the TypeScript 7.1 beta compiler API and its platform-specific native binary, installed with the package. Optional dependencies must be enabled; installs with `--omit=optional` cannot run the extractor. Reinstall with `npm install --include=optional` if the native compiler is missing.
12
+
11
13
  ## CLI
12
14
 
13
15
  ```ts
@@ -34,7 +36,7 @@ export type QueryInput = {
34
36
  /** Words to search for */
35
37
  search: string;
36
38
  page?: string | number | undefined;
37
- tag?: 'docs' | 'code' | readonly ('docs' | 'code')[] | undefined;
39
+ tag?: 'code' | 'docs' | readonly ('code' | 'docs')[] | undefined;
38
40
  };
39
41
 
40
42
  /** Search query parameters */
@@ -42,10 +44,12 @@ export type QueryOutput = {
42
44
  /** Words to search for */
43
45
  search: string;
44
46
  page: number;
45
- tag?: ('docs' | 'code')[] | undefined;
47
+ tag?: ('code' | 'docs')[] | undefined;
46
48
  };
47
49
  ```
48
50
 
51
+ Glob patterns use `/` separators on every platform; Windows backslash separators in file patterns are normalized.
52
+
49
53
  Every exported Loculus schema in the matching files is extracted. Fields keep the order of the `object()` shape.
50
54
 
51
55
  ```
@@ -79,7 +83,7 @@ Without `--outDir` or `--outFile`, types are printed to standard output. Use `--
79
83
  ```ts
80
84
  import { LoculusTypeExtractor, generate, renderModule } from '@loculus/infer';
81
85
 
82
- const extractor = new LoculusTypeExtractor({ project: './tsconfig.json' });
86
+ using extractor = new LoculusTypeExtractor({ project: './tsconfig.json' });
83
87
  const { input, output } = extractor.extract('src/query.ts', 'QuerySchema');
84
88
 
85
89
  const schemas = extractor.extractAll('src/query.ts', { withDescriptions: true });
@@ -88,6 +92,8 @@ const source = renderModule(schemas, { suffix: 'Schema', mergeSame: true });
88
92
  const { files } = await generate({ include: ['src/**/*.ts'], outDir: 'types' });
89
93
  ```
90
94
 
95
+ The extractor owns a native compiler session. Use `using` as above, or call `extractor.dispose()` when finished. `generate()` releases its session automatically.
96
+
91
97
  ## How types are printed
92
98
 
93
99
  - Types come from the TypeScript compiler, so they match `l.Input<typeof schema>` and `l.Output<typeof schema>`. The tests check this with type-level equality.
@@ -95,6 +101,8 @@ const { files } = await generate({ include: ['src/**/*.ts'], outDir: 'types' });
95
101
  - Named interfaces and classes stay as references, such as `Date`, `URL` or an interface returned by `transform()`. The generated module imports exported types from their own modules. A type that is not exported produces a warning.
96
102
  - `--with-descriptions` reads `description` options written as string literals, including fields of nested `object()` shapes and array rows. Descriptions computed at runtime are not read. After `unflatten()`, only the input type gets field comments, because the output keys are restructured.
97
103
 
104
+ Union members and properties of compiler-generated types may be printed in a different order than earlier releases; the types remain equivalent.
105
+
98
106
  The extractor uses the tsconfig.json given by `--project`, or the nearest one above the working directory. Without one, it uses strict NodeNext settings.
99
107
 
100
108
  ## License
package/dist/cli.d.ts CHANGED
@@ -1,3 +1 @@
1
- //#region src/cli.d.ts
2
- export declare function main(argv?: readonly string[]): Promise<number>;
3
- //#endregion
1
+ export declare function main(argv?: readonly string[]): Promise<number>;
package/dist/cli.js CHANGED
@@ -1,8 +1,8 @@
1
- import { n as findOutdated, r as generate } from "./generate-ncDNvye5.js";
1
+ import { n as findOutdated, r as generate } from "./generate-B66c6Tig.js";
2
2
  import { dirname, relative } from "node:path";
3
3
  import { mkdir, rm, writeFile } from "node:fs/promises";
4
4
  import { parseArgs } from "node:util";
5
- //#region src/cli.ts
5
+ // src/cli.ts
6
6
  const help = `Usage: loculus-infer [options] <files...>
7
7
 
8
8
  Extract Input/Output types from exported Loculus schemas.
@@ -129,5 +129,4 @@ function parseMap(value) {
129
129
  }
130
130
  return map;
131
131
  }
132
- //#endregion
133
132
  export { main };