@contractkit/plugin-typescript 0.33.0 → 0.33.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/.turbo/turbo-build$colon$ci.log +2 -2
- package/.turbo/turbo-test$colon$ci.log +10 -10
- package/CHANGELOG.md +18 -0
- package/README.md +4 -4
- package/llms.txt +111 -0
- package/package.json +4 -4
|
@@ -7,7 +7,7 @@ $ tsup src/index.ts --format esm --sourcemap --dts && tsc --emitDeclarationOnly
|
|
|
7
7
|
[34mESM[39m Build start
|
|
8
8
|
[32mESM[39m [1mdist/index.js [22m[32m210.74 KB[39m
|
|
9
9
|
[32mESM[39m [1mdist/index.js.map [22m[32m480.07 KB[39m
|
|
10
|
-
[32mESM[39m ⚡️ Build success in
|
|
10
|
+
[32mESM[39m ⚡️ Build success in 537ms
|
|
11
11
|
[34mDTS[39m Build start
|
|
12
|
-
[32mDTS[39m ⚡️ Build success in
|
|
12
|
+
[32mDTS[39m ⚡️ Build success in 4711ms
|
|
13
13
|
[32mDTS[39m [1mdist/index.d.ts [22m[32m5.14 KB[39m
|
|
@@ -3,19 +3,19 @@ $ vitest run --coverage
|
|
|
3
3
|
[1m[30m[46m RUN [49m[39m[22m [36mv4.1.5 [39m[90m/home/runner/work/ContractKit/ContractKit/packages/plugin-typescript[39m
|
|
4
4
|
[2mCoverage enabled with [22m[33mv8[39m
|
|
5
5
|
|
|
6
|
-
[32m✓[39m tests/codegen-contract.test.ts [2m([22m[2m140 tests[22m[2m)[22m[32m
|
|
7
|
-
[32m✓[39m tests/codegen-operation.test.ts [2m([22m[2m155 tests[22m[2m)[22m[
|
|
8
|
-
[32m✓[39m tests/codegen-sdk.test.ts [2m([22m[2m159 tests[22m[2m)[22m[
|
|
9
|
-
[32m✓[39m tests/codegen-server.test.ts [2m([22m[2m30 tests[22m[2m)[22m[32m
|
|
10
|
-
[32m✓[39m tests/codegen-plain-types.test.ts [2m([22m[2m66 tests[22m[2m)[22m[32m
|
|
11
|
-
[32m✓[39m tests/pipeline.test.ts [2m([22m[2m30 tests[22m[2m)[22m[
|
|
12
|
-
[32m✓[39m tests/codegen-mcp.test.ts [2m([22m[2m24 tests[22m[2m)[22m[32m
|
|
13
|
-
[32m✓[39m tests/escaping-security.test.ts [2m([22m[2m18 tests[22m[2m)[22m[32m
|
|
6
|
+
[32m✓[39m tests/codegen-contract.test.ts [2m([22m[2m140 tests[22m[2m)[22m[32m 291[2mms[22m[39m
|
|
7
|
+
[32m✓[39m tests/codegen-operation.test.ts [2m([22m[2m155 tests[22m[2m)[22m[33m 339[2mms[22m[39m
|
|
8
|
+
[32m✓[39m tests/codegen-sdk.test.ts [2m([22m[2m159 tests[22m[2m)[22m[33m 336[2mms[22m[39m
|
|
9
|
+
[32m✓[39m tests/codegen-server.test.ts [2m([22m[2m30 tests[22m[2m)[22m[32m 106[2mms[22m[39m
|
|
10
|
+
[32m✓[39m tests/codegen-plain-types.test.ts [2m([22m[2m66 tests[22m[2m)[22m[32m 90[2mms[22m[39m
|
|
11
|
+
[32m✓[39m tests/pipeline.test.ts [2m([22m[2m30 tests[22m[2m)[22m[33m 458[2mms[22m[39m
|
|
12
|
+
[32m✓[39m tests/codegen-mcp.test.ts [2m([22m[2m24 tests[22m[2m)[22m[32m 81[2mms[22m[39m
|
|
13
|
+
[32m✓[39m tests/escaping-security.test.ts [2m([22m[2m18 tests[22m[2m)[22m[32m 35[2mms[22m[39m
|
|
14
14
|
|
|
15
15
|
[2m Test Files [22m [1m[32m8 passed[39m[22m[90m (8)[39m
|
|
16
16
|
[2m Tests [22m [1m[32m622 passed[39m[22m[90m (622)[39m
|
|
17
|
-
[2m Start at [22m
|
|
18
|
-
[2m Duration [22m
|
|
17
|
+
[2m Start at [22m 19:19:25
|
|
18
|
+
[2m Duration [22m 10.45s[2m (transform 4.58s, setup 0ms, import 19.71s, tests 1.74s, environment 1ms)[22m
|
|
19
19
|
|
|
20
20
|
[34m % [39m[2mCoverage report from [22m[33mv8[39m
|
|
21
21
|
-------------------|---------|----------|---------|---------|-------------------
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @contractkit/contractkit-plugin-typescript
|
|
2
2
|
|
|
3
|
+
## 0.33.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [74b8a28]
|
|
8
|
+
- @contractkit/core@0.28.2
|
|
9
|
+
|
|
10
|
+
## 0.33.1
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 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.
|
|
15
|
+
|
|
16
|
+
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.
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [ffb2ec6]
|
|
19
|
+
- @contractkit/core@0.28.1
|
|
20
|
+
|
|
3
21
|
## 0.33.0
|
|
4
22
|
|
|
5
23
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
# @contractkit/
|
|
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/
|
|
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/
|
|
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/
|
|
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.
|
|
3
|
+
"version": "0.33.2",
|
|
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.
|
|
30
|
+
"@contractkit/core": "0.28.2"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@repo/config-
|
|
34
|
-
"@repo/config-
|
|
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",
|