@amritk/mjst 0.12.2 → 0.13.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/README.md CHANGED
@@ -21,7 +21,7 @@
21
21
 
22
22
  Options can be supplied via CLI flags or a JSON config file. **CLI flags always take precedence over config file values.**
23
23
 
24
- It also carries a `lint` subcommand — `mjst lint <files>` — a format-agnostic JSON/YAML style-guide linter powered by [`@amritk/lint`](../lint). See [Linting](#linting).
24
+ It also carries a `lint` subcommand — `mjst lint <files>` — a format-agnostic JSON/YAML style-guide linter powered by [`@amritk/lint`](../lint) (see [Linting](#linting)), and a `compile-api` subcommand — `mjst compile-api <routes-module> --out <file>` — that compiles [`@amritk/api`](../api) route contracts into a production fetch-handler module (see [Compiling an API](#compiling-an-api)).
25
25
 
26
26
  ---
27
27
 
@@ -219,6 +219,33 @@ The exit code is `0` when no finding reaches `--fail-severity`, `1` when one doe
219
219
 
220
220
  ---
221
221
 
222
+ ## Compiling an API
223
+
224
+ `mjst compile-api` compiles [`@amritk/api`](../api) route contracts into a fused fetch-handler module — the production counterpart to `createApi`, with inlined guards, schema-derived serializers, and a precomputed OpenAPI document. It wraps the library's `compileToModule` so you do not have to hand-write a build script. Like `lint`, it has its own flags (and its own `--help`), independent of the generation flags above.
225
+
226
+ ```bash
227
+ # Compile every route contract exported by the routes module
228
+ npx mjst compile-api src/routes.ts --out dist/handler.js
229
+
230
+ # Wire in the exports-by-name options (context factory, mounts, OpenAPI info, ...)
231
+ npx mjst compile-api src/routes.ts --out dist/handler.js --options compile-options.json
232
+ ```
233
+
234
+ Every export of the routes module that looks like a route contract (`method`, `path`, `responses`) is compiled; the generated module imports those contracts back through `--routes-import` (default: the relative path from the out file to the routes module). The routes module is imported at build time, so it must be loadable by the runtime running mjst — run via `bunx` for TypeScript sources, or under Node install a loader such as `tsx` (`node --import tsx`).
235
+
236
+ | Flag | Description |
237
+ | --- | --- |
238
+ | `<routes-module>` | Module exporting the route contracts (positional). |
239
+ | `--out` | Output file for the generated module (required; parent directories are created). |
240
+ | `--routes-import` | Import specifier the generated module uses for the routes module. Defaults to the relative path from the out file. |
241
+ | `--options` | JSON file spread into the `compileToModule` options — `contextExport`, `mounts`, `info`, `servers`, `security`, `securitySchemes`, and friends. Flags take precedence. |
242
+ | `--open-api-path` | Serve the precomputed OpenAPI JSON at this path (default `/openapi.json`). |
243
+ | `--max-body-bytes` | Reject request bodies larger than this many bytes with a 413 (default `1048576`; `Infinity` disables the cap). |
244
+
245
+ The exit code is `0` on success, `1` when compilation fails (unloadable module, no contracts found, invalid options JSON), and `2` on a usage error. Run `mjst compile-api --help` for details.
246
+
247
+ ---
248
+
222
249
  ## Configuration reference
223
250
 
224
251
  <!-- config-table-start -->