@amritk/mjst 0.13.0 → 0.13.2
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/AI.md +56 -0
- package/dist/lint/resolver.js +2 -1
- package/dist/lint/ruleset-loader.d.ts +1 -1
- package/dist/lint/run.js +2 -1
- package/package.json +13 -12
package/AI.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# @amritk/mjst (the `mjst` CLI) — notes for AI coding agents
|
|
2
|
+
|
|
3
|
+
The command-line entry point to mjst: generate TypeScript parsers, validators,
|
|
4
|
+
and types from JSON Schema, plus `lint` and `compile-api` subcommands. Full
|
|
5
|
+
reference is [README.md](./README.md); config options are in
|
|
6
|
+
[config.schema.json](./config.schema.json).
|
|
7
|
+
|
|
8
|
+
> Pre-alpha: generated output and flags change without notice pre-1.0. This
|
|
9
|
+
> package ships **only a `mjst` binary** — there are no JS exports. For the
|
|
10
|
+
> programmatic API import `@amritk/generate-parsers` etc. instead.
|
|
11
|
+
|
|
12
|
+
## The three commands
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
# 1. Codegen (default command)
|
|
16
|
+
mjst --schema ./schema.json --out-dir ./generated
|
|
17
|
+
|
|
18
|
+
# 2. Lint JSON/YAML against JSON Schema + style rules
|
|
19
|
+
mjst lint "**/*.{yaml,json}" -r .lint.yaml
|
|
20
|
+
|
|
21
|
+
# 3. Compile an @amritk/api routes module to a fused, eval-free handler
|
|
22
|
+
mjst compile-api ./routes.ts --out ./dist/handler.ts
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Codegen gotchas
|
|
26
|
+
|
|
27
|
+
1. **You must pass an output.** `--out-dir <dir>` **or** `--out-file <file>` —
|
|
28
|
+
omitting both errors. `--out-file` only works with `--types-only`.
|
|
29
|
+
2. **`--import-ext` defaults to `ts`, not `js`.** Generated imports carry literal
|
|
30
|
+
`.ts` extensions, so plain `tsc` needs `allowImportingTsExtensions`. Use
|
|
31
|
+
`--import-ext js` or `--build` for directly-compilable output.
|
|
32
|
+
`--import-ext ts` + `--build` is a hard error.
|
|
33
|
+
3. **Flags accept kebab or camel** (`--out-dir` ≡ `--outDir`). **Config-file
|
|
34
|
+
keys are camelCase** (`outDir`, `schemaDir`, `typesOnly`, …), validated
|
|
35
|
+
against `config.schema.json`. CLI flags always override the config file.
|
|
36
|
+
4. **The root type name comes from the schema `title`/filename**, not
|
|
37
|
+
`Document`. Override with `--root-type <name>` (single-schema only; rejected
|
|
38
|
+
with `--schema-dir`).
|
|
39
|
+
5. **Non-JSON input** (`--input typebox|zod|valibot|effect`) works for a single
|
|
40
|
+
`--schema`; `--schema-dir` only accepts `json`.
|
|
41
|
+
|
|
42
|
+
## Common flags
|
|
43
|
+
|
|
44
|
+
`--schema` / `--schema-dir`, `--out-dir` / `--out-file`, `--input`,
|
|
45
|
+
`--validators`, `--examples`, `--types-only`, `--build`, `--strict`,
|
|
46
|
+
`--strip-unknown`, `--readonly`, `--import-ext ts|js`, `--config <path>`,
|
|
47
|
+
`--resolve-remote` / `--allowed-hosts` (SSRF-guarded remote `$ref`s).
|
|
48
|
+
|
|
49
|
+
## Lint gotchas
|
|
50
|
+
|
|
51
|
+
- `-F`/`--fail-severity` (default `error`) sets the exit-code threshold
|
|
52
|
+
(`0` clean, `1` findings at/above threshold, `2` usage error).
|
|
53
|
+
- With no `-r`, a `.lint.{yaml,yml,json,js,mjs}` ruleset is auto-discovered by
|
|
54
|
+
walking up from each file.
|
|
55
|
+
|
|
56
|
+
Install: `bun add -d @amritk/mjst` (or `npx mjst …`).
|
package/dist/lint/resolver.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
import { resolve as resolvePath } from "node:path";
|
|
3
|
-
import { createDocument,
|
|
3
|
+
import { createDocument, resolveSourceOriginFromMap } from "@amritk/lint";
|
|
4
|
+
import { DiagnosticSeverity } from "@amritk/lint/types";
|
|
4
5
|
import { resolveRefs, resolveRefsFromFile } from "@amritk/resolve-refs";
|
|
5
6
|
import { parse as parseYaml } from "@amritk/yaml";
|
|
6
7
|
import { hasExternalRefs } from "../has-external-refs.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { RulesetDefinition } from '@amritk/lint/types';
|
|
2
2
|
/** Loads a ruleset definition from a YAML, JSON, or JS/MJS file. */
|
|
3
3
|
export declare const loadRuleset: (path: string) => Promise<RulesetDefinition>;
|
|
4
4
|
/** Walks up from a directory looking for a `.lint.*` ruleset file. */
|
package/dist/lint/run.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
2
|
import { dirname, isAbsolute, resolve } from "node:path";
|
|
3
|
-
import {
|
|
3
|
+
import { lintDocument, validateRuleset } from "@amritk/lint";
|
|
4
|
+
import { DiagnosticSeverity } from "@amritk/lint/types";
|
|
4
5
|
import fg from "fast-glob";
|
|
5
6
|
import yargs from "yargs";
|
|
6
7
|
import { createLintResolver } from "./resolver.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amritk/mjst",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.2",
|
|
4
4
|
"description": "Generate TypeScript parsers and type definitions from JSON Schemas.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
"mjst": "./dist/cli.js"
|
|
28
28
|
},
|
|
29
29
|
"files": [
|
|
30
|
-
"dist"
|
|
30
|
+
"dist",
|
|
31
|
+
"AI.md"
|
|
31
32
|
],
|
|
32
33
|
"publishConfig": {
|
|
33
34
|
"access": "public"
|
|
@@ -41,16 +42,16 @@
|
|
|
41
42
|
"generate-readme": "bun run ./scripts/generate-readme.ts"
|
|
42
43
|
},
|
|
43
44
|
"dependencies": {
|
|
44
|
-
"@amritk/adapters": "0.3.
|
|
45
|
-
"@amritk/api": "0.
|
|
46
|
-
"@amritk/generate-examples": "0.5.
|
|
47
|
-
"@amritk/generate-parsers": "0.17.
|
|
48
|
-
"@amritk/generate-validators": "0.11.
|
|
49
|
-
"@amritk/generate-markdown": "0.4.
|
|
50
|
-
"@amritk/helpers": "0.13.
|
|
51
|
-
"@amritk/lint": "0.
|
|
52
|
-
"@amritk/resolve-refs": "0.4.
|
|
53
|
-
"@amritk/yaml": "0.3.
|
|
45
|
+
"@amritk/adapters": "0.3.4",
|
|
46
|
+
"@amritk/api": "0.6.1",
|
|
47
|
+
"@amritk/generate-examples": "0.5.4",
|
|
48
|
+
"@amritk/generate-parsers": "0.17.1",
|
|
49
|
+
"@amritk/generate-validators": "0.11.10",
|
|
50
|
+
"@amritk/generate-markdown": "0.4.4",
|
|
51
|
+
"@amritk/helpers": "0.13.4",
|
|
52
|
+
"@amritk/lint": "0.4.0",
|
|
53
|
+
"@amritk/resolve-refs": "0.4.4",
|
|
54
|
+
"@amritk/yaml": "0.3.4",
|
|
54
55
|
"fast-glob": "^3.3.2",
|
|
55
56
|
"yargs": "^17.7.2"
|
|
56
57
|
},
|