@contractkit/plugin-typescript 0.33.0 → 0.33.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.
@@ -7,7 +7,7 @@ $ tsup src/index.ts --format esm --sourcemap --dts && tsc --emitDeclarationOnly
7
7
  ESM Build start
8
8
  ESM dist/index.js 210.74 KB
9
9
  ESM dist/index.js.map 480.07 KB
10
- ESM ⚡️ Build success in 478ms
10
+ ESM ⚡️ Build success in 359ms
11
11
  DTS Build start
12
- DTS ⚡️ Build success in 3983ms
12
+ DTS ⚡️ Build success in 6133ms
13
13
  DTS dist/index.d.ts 5.14 KB
@@ -3,19 +3,19 @@ $ vitest run --coverage
3
3
   RUN  v4.1.5 /home/runner/work/ContractKit/ContractKit/packages/plugin-typescript
4
4
  Coverage enabled with v8
5
5
 
6
- ✓ tests/codegen-contract.test.ts (140 tests) 214ms
7
- ✓ tests/codegen-operation.test.ts (155 tests) 270ms
8
- ✓ tests/codegen-sdk.test.ts (159 tests) 239ms
9
- ✓ tests/codegen-server.test.ts (30 tests) 84ms
10
- ✓ tests/codegen-plain-types.test.ts (66 tests) 82ms
11
- ✓ tests/pipeline.test.ts (30 tests) 279ms
12
- ✓ tests/codegen-mcp.test.ts (24 tests) 31ms
13
- ✓ tests/escaping-security.test.ts (18 tests) 21ms
6
+ ✓ tests/codegen-contract.test.ts (140 tests) 154ms
7
+ ✓ tests/codegen-operation.test.ts (155 tests) 220ms
8
+ ✓ tests/codegen-sdk.test.ts (159 tests) 227ms
9
+ ✓ tests/codegen-plain-types.test.ts (66 tests) 61ms
10
+ ✓ tests/codegen-server.test.ts (30 tests) 143ms
11
+ ✓ tests/pipeline.test.ts (30 tests) 269ms
12
+ ✓ tests/codegen-mcp.test.ts (24 tests) 57ms
13
+ ✓ tests/escaping-security.test.ts (18 tests) 24ms
14
14
 
15
15
   Test Files  8 passed (8)
16
16
   Tests  622 passed (622)
17
-  Start at  17:30:03
18
-  Duration  8.38s (transform 4.61s, setup 0ms, import 16.31s, tests 1.22s, environment 1ms)
17
+  Start at  18:42:58
18
+  Duration  10.53s (transform 7.47s, setup 0ms, import 19.72s, tests 1.15s, environment 1ms)
19
19
 
20
20
   % Coverage report from v8
21
21
  -------------------|---------|----------|---------|---------|-------------------
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @contractkit/contractkit-plugin-typescript
2
2
 
3
+ ## 0.33.1
4
+
5
+ ### Patch Changes
6
+
7
+ - ffb2ec6: Ship an `llms.txt` in every package, so an AI assistant reading the package out of `node_modules` gets its exact name, a config block with real key names, the full option table, the programmatic API, and the mistakes specific to it — without needing the repo checked out.
8
+
9
+ Correct several documented snippets that could not work as written. The five plugin READMEs named packages that do not exist (`@contractkit/contractkit-plugin-*`, and `-python-sdk` for the Python plugin) in both their install commands and their `contractkit.config.json` keys. `@contractkit/core`'s README exported `Diagnostics` and `validateOperation`, which are really `DiagnosticCollector` and `validateOp`, and gave the wrong signatures for three validation passes. `@contractkit/cli`'s README documented the OpenAPI importer as `contractkit openapi-to-ck --input <spec>`; it is `contractkit import-openapi <spec>`, with the path positional. `@contractkit/plugin-openapi` described its output as OpenAPI 3.0, but it emits 3.1.
10
+
11
+ - Updated dependencies [ffb2ec6]
12
+ - @contractkit/core@0.28.1
13
+
3
14
  ## 0.33.0
4
15
 
5
16
  ### Minor Changes
package/README.md CHANGED
@@ -1,11 +1,11 @@
1
- # @contractkit/contractkit-plugin-typescript
1
+ # @contractkit/plugin-typescript
2
2
 
3
3
  ContractKit plugin that generates TypeScript output from `.ck` contract files. Covers all server-side and client-side TypeScript needs: Koa routers, SDK clients, Zod schemas, and plain TypeScript interfaces.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- pnpm add @contractkit/contractkit-plugin-typescript
8
+ pnpm add @contractkit/plugin-typescript
9
9
  ```
10
10
 
11
11
  ## Configuration
@@ -15,7 +15,7 @@ Add the plugin to `contractkit.config.json`. Each sub-config is independent —
15
15
  ```json
16
16
  {
17
17
  "plugins": {
18
- "@contractkit/contractkit-plugin-typescript": {
18
+ "@contractkit/plugin-typescript": {
19
19
  "server": {
20
20
  "baseDir": "apps/api/",
21
21
  "zod": true,
@@ -170,7 +170,7 @@ statuses fall into which set.
170
170
  ## Programmatic use
171
171
 
172
172
  ```typescript
173
- import { createTypescriptPlugin } from '@contractkit/contractkit-plugin-typescript';
173
+ import { createTypescriptPlugin } from '@contractkit/plugin-typescript';
174
174
 
175
175
  const plugin = createTypescriptPlugin({
176
176
  server: {
package/llms.txt ADDED
@@ -0,0 +1,111 @@
1
+ # @contractkit/plugin-typescript
2
+
3
+ > ContractKit's TypeScript code generator. From the same `.ck` files it emits Koa routers, a
4
+ > TypeScript SDK client, Zod schemas, plain TypeScript types, and MCP tool handlers. Five
5
+ > independent sub-generators, each enabled by the presence of its config key.
6
+
7
+ Loaded by `@contractkit/cli` through `contractkit.config.json`. It consumes the AST produced by
8
+ `@contractkit/core`; you do not call it directly in a normal build.
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ pnpm add -D @contractkit/cli @contractkit/plugin-typescript
14
+ ```
15
+
16
+ ## Configure
17
+
18
+ `plugins` is an **object** keyed by package name, not an array. Each sub-config is independent —
19
+ include only the ones you want; omitting a key disables that sub-generator entirely.
20
+
21
+ ```json
22
+ {
23
+ "rootDir": ".",
24
+ "patterns": ["contracts/**/*.ck"],
25
+ "plugins": {
26
+ "@contractkit/plugin-typescript": {
27
+ "server": {
28
+ "baseDir": "apps/api/",
29
+ "zod": true,
30
+ "output": {
31
+ "routes": "src/routes/{filename}.router.ts",
32
+ "types": "src/modules/{area}/types/{filename}.ts"
33
+ },
34
+ "servicePathTemplate": "#modules/{module}/{module}.service.js"
35
+ },
36
+ "sdk": {
37
+ "baseDir": "packages/sdk/",
38
+ "name": "acme",
39
+ "zod": true,
40
+ "output": {
41
+ "sdk": "src/{name}.sdk.ts",
42
+ "types": "src/{area}/types/{filename}.ts",
43
+ "clients": "src/{area}/{filename}.client.ts"
44
+ }
45
+ },
46
+ "zod": { "baseDir": "packages/schemas/", "output": "{filename}.schema.ts" },
47
+ "types": { "baseDir": "packages/types/", "output": "{filename}.types.ts" }
48
+ }
49
+ }
50
+ }
51
+ ```
52
+
53
+ Path templates accept `{filename}`, `{dir}`, `{area}`, and — in `sdk.output.sdk` — `{name}`.
54
+
55
+ ## Sub-configs
56
+
57
+ | Key | Emits |
58
+ | --- | --- |
59
+ | `server` | Koa routers from `operation` declarations, plus the type or Zod files they import |
60
+ | `sdk` | The SDK class, per-area operation clients, and their types |
61
+ | `zod` | Standalone Zod schemas, independent of `server` and `sdk` |
62
+ | `types` | Standalone plain TypeScript types, independent of `server` and `sdk` |
63
+ | `mcp` | Per-file MCP tool handlers, an aggregator, and an optional `POST /mcp` route |
64
+
65
+ Options worth knowing:
66
+
67
+ - `server.zod` / `sdk.zod` — when true, `output.types` emits Zod schema files instead of plain
68
+ interfaces. Off by default.
69
+ - `server.validateResponses` — each handler re-parses the service result through its declared
70
+ response schema before writing `ctx.body`. **Requires `zod: true`**; without it `output.types`
71
+ emits plain interfaces, which are types with no runtime value to parse through. A body that
72
+ transitively references a model with `format(input=…)`/`format(output=…)`, and a status whose
73
+ several mimes carry different body types, are left unvalidated.
74
+ - `sdk.scaffold` — write-once starter `package.json` and `tsconfig.json` at the SDK `baseDir`, so
75
+ the generated output is a publishable package on its own. Never overwritten once created, so your
76
+ edits survive. Dependency ranges are derived from the contracts.
77
+ - `includeInternal` on `server`/`sdk` — whether operations marked `internal` get handlers or client
78
+ methods. Defaults to `true` for `server`, `false` for `sdk`.
79
+ - `types.target` — `'client'` (default) or `'server'`; decides whether `binary` renders as `Blob`
80
+ or `Buffer`. The `server` and `sdk` sub-generators set it themselves.
81
+ - `mcp.output.types` must point at **Zod schema** files, not plain types — tools need a runtime
82
+ schema for argument validation and `z.toJSONSchema`. It falls back to `server.output.types` (when
83
+ `server.zod`) or the `zod` sub-config's output.
84
+
85
+ ## Programmatic use
86
+
87
+ ```typescript
88
+ import { createTypescriptPlugin } from '@contractkit/plugin-typescript';
89
+
90
+ const plugin = createTypescriptPlugin({ types: { output: '{filename}.types.ts' } }, process.cwd());
91
+ ```
92
+
93
+ Prefer the default export when loading through `contractkit.config.json`; the factory is for
94
+ building the plugin in code (tests, custom build scripts).
95
+
96
+ ## Gotchas
97
+
98
+ - The four output sub-configs are independent. `zod: true` **inside** `server` is not the same thing
99
+ as the top-level `zod` sub-config: the first changes what `server.output.types` emits, the second
100
+ adds a separate standalone schema output.
101
+ - `validateResponses` silently does nothing useful without `zod: true`.
102
+ - Which statuses a router writes and which the SDK throws is decided by the contract, not by this
103
+ plugin — a `404(documented)` is the client's error contract, a bare `404:` is a status the service
104
+ produces. See the response-set helpers in `@contractkit/core`.
105
+
106
+ ## More
107
+
108
+ - README: https://github.com/MaroonedSoftware/contractkit/blob/main/packages/plugin-typescript/README.md
109
+ - Configuration: https://github.com/MaroonedSoftware/contractkit/blob/main/docs/config.md
110
+ - SDK generation and subclient grouping: https://github.com/MaroonedSoftware/contractkit/blob/main/docs/tooling.md
111
+ - Full usage guide: https://github.com/MaroonedSoftware/contractkit/blob/main/llms-full.txt
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contractkit/plugin-typescript",
3
- "version": "0.33.0",
3
+ "version": "0.33.1",
4
4
  "description": "ContractKit built-in plugin: TypeScript codegen (SDK clients, Koa routers, Zod schemas, plain types)",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -27,11 +27,11 @@
27
27
  ".": "./dist/index.js"
28
28
  },
29
29
  "dependencies": {
30
- "@contractkit/core": "0.28.0"
30
+ "@contractkit/core": "0.28.1"
31
31
  },
32
32
  "devDependencies": {
33
- "@repo/config-typescript": "0.1.0",
34
- "@repo/config-eslint": "0.3.1"
33
+ "@repo/config-eslint": "0.3.1",
34
+ "@repo/config-typescript": "0.1.0"
35
35
  },
36
36
  "scripts": {
37
37
  "build": "tsup src/index.ts --format esm --sourcemap --dts && tsc --emitDeclarationOnly --declaration",