@contractkit/plugin-typescript 0.28.1 → 0.29.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/.turbo/turbo-build$colon$ci.log +5 -5
- package/.turbo/turbo-test$colon$ci.log +21 -19
- package/CHANGELOG.md +16 -0
- package/README.md +4 -0
- package/dist/codegen-contract.d.ts +7 -0
- package/dist/codegen-contract.d.ts.map +1 -1
- package/dist/codegen-mcp.d.ts +38 -0
- package/dist/codegen-mcp.d.ts.map +1 -0
- package/dist/codegen-operation.d.ts +42 -1
- package/dist/codegen-operation.d.ts.map +1 -1
- package/dist/codegen-plain-types.d.ts +3 -0
- package/dist/codegen-plain-types.d.ts.map +1 -1
- package/dist/index.d.ts +39 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +686 -96
- package/dist/index.js.map +1 -1
- package/dist/ts-render.d.ts +21 -3
- package/dist/ts-render.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/codegen-contract.ts +7 -0
- package/src/codegen-mcp.ts +501 -0
- package/src/codegen-operation.ts +104 -10
- package/src/codegen-plain-types.ts +47 -22
- package/src/index.ts +175 -1
- package/src/ts-render.ts +52 -32
- package/tests/codegen-mcp.test.ts +246 -0
- package/tests/codegen-operation.test.ts +89 -0
- package/tests/codegen-plain-types.test.ts +48 -0
- package/tests/codegen-server.test.ts +37 -0
- package/tests/pipeline.test.ts +59 -0
|
@@ -5,9 +5,9 @@ $ tsup src/index.ts --format esm --sourcemap --dts && tsc --emitDeclarationOnly
|
|
|
5
5
|
[34mCLI[39m tsup v8.5.1
|
|
6
6
|
[34mCLI[39m Target: esnext
|
|
7
7
|
[34mESM[39m Build start
|
|
8
|
-
[32mESM[39m [1mdist/index.js [22m[
|
|
9
|
-
[32mESM[39m [1mdist/index.js.map [22m[
|
|
10
|
-
[32mESM[39m ⚡️ Build success in
|
|
8
|
+
[32mESM[39m [1mdist/index.js [22m[32m178.19 KB[39m
|
|
9
|
+
[32mESM[39m [1mdist/index.js.map [22m[32m395.78 KB[39m
|
|
10
|
+
[32mESM[39m ⚡️ Build success in 396ms
|
|
11
11
|
[34mDTS[39m Build start
|
|
12
|
-
[32mDTS[39m ⚡️ Build success in
|
|
13
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
12
|
+
[32mDTS[39m ⚡️ Build success in 6065ms
|
|
13
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m4.55 KB[39m
|
|
@@ -3,32 +3,34 @@ $ 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[2m128 tests[22m[2m)[22m[32m
|
|
7
|
-
[32m✓[39m tests/codegen-
|
|
8
|
-
[32m✓[39m tests/codegen-
|
|
9
|
-
[32m✓[39m tests/codegen-
|
|
10
|
-
[32m✓[39m tests/
|
|
11
|
-
[32m✓[39m tests/
|
|
12
|
-
[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[2m128 tests[22m[2m)[22m[32m 221[2mms[22m[39m
|
|
7
|
+
[32m✓[39m tests/codegen-sdk.test.ts [2m([22m[2m140 tests[22m[2m)[22m[32m 252[2mms[22m[39m
|
|
8
|
+
[32m✓[39m tests/codegen-operation.test.ts [2m([22m[2m113 tests[22m[2m)[22m[32m 255[2mms[22m[39m
|
|
9
|
+
[32m✓[39m tests/codegen-server.test.ts [2m([22m[2m25 tests[22m[2m)[22m[32m 110[2mms[22m[39m
|
|
10
|
+
[32m✓[39m tests/codegen-plain-types.test.ts [2m([22m[2m66 tests[22m[2m)[22m[32m 35[2mms[22m[39m
|
|
11
|
+
[32m✓[39m tests/pipeline.test.ts [2m([22m[2m28 tests[22m[2m)[22m[32m 217[2mms[22m[39m
|
|
12
|
+
[32m✓[39m tests/escaping-security.test.ts [2m([22m[2m18 tests[22m[2m)[22m[32m 27[2mms[22m[39m
|
|
13
|
+
[32m✓[39m tests/codegen-mcp.test.ts [2m([22m[2m24 tests[22m[2m)[22m[32m 67[2mms[22m[39m
|
|
13
14
|
|
|
14
|
-
[2m Test Files [22m [1m[
|
|
15
|
-
[2m Tests [22m [1m[
|
|
16
|
-
[2m Start at [22m
|
|
17
|
-
[2m Duration [22m 9.
|
|
15
|
+
[2m Test Files [22m [1m[32m8 passed[39m[22m[90m (8)[39m
|
|
16
|
+
[2m Tests [22m [1m[32m542 passed[39m[22m[90m (542)[39m
|
|
17
|
+
[2m Start at [22m 12:07:42
|
|
18
|
+
[2m Duration [22m 9.60s[2m (transform 5.83s, setup 0ms, import 18.92s, tests 1.18s, environment 1ms)[22m
|
|
18
19
|
|
|
19
20
|
[34m % [39m[2mCoverage report from [22m[33mv8[39m
|
|
20
21
|
-------------------|---------|----------|---------|---------|-------------------
|
|
21
22
|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
|
|
22
23
|
-------------------|---------|----------|---------|---------|-------------------
|
|
23
|
-
All files |
|
|
24
|
-
src |
|
|
25
|
-
...n-contract.ts | 88.1 | 82.91 | 90.08 | 89.26 | ...
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
All files | 82.66 | 77.13 | 85.59 | 85.15 |
|
|
25
|
+
src | 82.52 | 76.89 | 85.35 | 85 |
|
|
26
|
+
...n-contract.ts | 88.1 | 82.91 | 90.08 | 89.26 | ...1095,1100-1101
|
|
27
|
+
codegen-mcp.ts | 82.67 | 75.47 | 84.61 | 85.9 | ...85,290-291,374
|
|
28
|
+
...-operation.ts | 80.12 | 77.35 | 79.22 | 81.36 | ...59-770,775-776
|
|
29
|
+
...lain-types.ts | 91.57 | 81.98 | 96.87 | 94.44 | ...31,157,269,275
|
|
28
30
|
codegen-sdk.ts | 88.37 | 83.2 | 87.83 | 91.48 | ...1187-1188,1191
|
|
29
|
-
index.ts |
|
|
30
|
-
path-utils.ts |
|
|
31
|
-
ts-render.ts |
|
|
31
|
+
index.ts | 66.25 | 53.64 | 72.72 | 70.29 | ...1022,1038-1057
|
|
32
|
+
path-utils.ts | 70.28 | 51.13 | 100 | 73.5 | ...65-168,216-231
|
|
33
|
+
ts-render.ts | 85 | 87.36 | 79.16 | 89.23 | 83,159,192-200
|
|
32
34
|
tests | 90.38 | 90.9 | 89.28 | 93.47 |
|
|
33
35
|
helpers.ts | 90.38 | 90.9 | 89.28 | 93.47 | 110-118
|
|
34
36
|
-------------------|---------|----------|---------|---------|-------------------
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @contractkit/contractkit-plugin-typescript
|
|
2
2
|
|
|
3
|
+
## 0.29.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 79e3049: Fix scalar response bodies in generated Koa routers, which emitted the `.ck` scalar name verbatim as a TypeScript type (`const result: binary`). Only `string`, `number`, `boolean`, `bigint`, `null` and `unknown` compiled by coincidence; `binary`, `int`, `uuid`, `datetime` and friends produced invalid code. Scalars now render as the type the handler actually receives: `binary` → `Buffer`, `int` → `number`, `datetime` → luxon `DateTime`, `interval` → `string`, `json` → `_JsonValue`.
|
|
8
|
+
|
|
9
|
+
Generated routers now also import `Duration` and `Interval` from luxon and emit the `_ZodInterval` helper when an operation uses those scalars, instead of referencing undefined names.
|
|
10
|
+
|
|
11
|
+
Plain type files emitted for the server render `binary` as `Buffer` rather than `Blob`. SDK output is unchanged. The standalone `types` sub-generator gained a `target` option (`"client" | "server"`, default `"client"`) to select between the two.
|
|
12
|
+
|
|
13
|
+
## 0.28.2
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- ca9309a: Generated Koa route handlers now use `async ctx => {` instead of `async (ctx, next) => {`. The `next` argument was never referenced in the emitted body and tripped no-unused-vars lint rules in consuming projects.
|
|
18
|
+
|
|
3
19
|
## 0.28.1
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -94,6 +94,10 @@ Generates plain TypeScript interface/type files from `contract` declarations. No
|
|
|
94
94
|
|---|---|---|---|
|
|
95
95
|
| `baseDir` | `string` | `rootDir` | Base directory for output files |
|
|
96
96
|
| `output` | `string` | `"{filename}.types.ts"` | Path template for type files |
|
|
97
|
+
| `target` | `"client" \| "server"` | `"client"` | Runtime the types describe. Affects scalars whose TypeScript type is runtime-specific: `binary` renders as `Buffer` for `server` and `Blob` for `client` |
|
|
98
|
+
|
|
99
|
+
The `server` and `sdk` sub-generators set `target` themselves (`server` and `client` respectively), so
|
|
100
|
+
their plain-type output already matches the runtime that consumes it.
|
|
97
101
|
|
|
98
102
|
## Path templates
|
|
99
103
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ContractRootNode, ModelNode, ContractTypeNode, ObjectMode } from '@contractkit/core';
|
|
2
|
+
import type { TsRenderTarget } from './ts-render.js';
|
|
2
3
|
/**
|
|
3
4
|
* Maps a ContractKit object mode to its Zod constructor name.
|
|
4
5
|
*
|
|
@@ -17,6 +18,12 @@ export interface ContractCodegenContext {
|
|
|
17
18
|
modelsWithOutput?: Set<string>;
|
|
18
19
|
/** If set, import JsonValue from this path instead of re-declaring it (avoids barrel re-export conflicts) */
|
|
19
20
|
jsonValueImportPath?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Runtime the emitted plain types describe. Only affects scalars whose TypeScript type differs
|
|
23
|
+
* per runtime (`binary` → `Buffer` on the server, `Blob` in the client). Ignored by
|
|
24
|
+
* `generateContract`, whose Zod schemas are server-shaped by construction. Default `'client'`.
|
|
25
|
+
*/
|
|
26
|
+
target?: TsRenderTarget;
|
|
20
27
|
}
|
|
21
28
|
/**
|
|
22
29
|
* Compute which models need Input variants, including transitive dependencies.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codegen-contract.d.ts","sourceRoot":"","sources":["../src/codegen-contract.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACR,gBAAgB,EAChB,SAAS,EAET,gBAAgB,EAWhB,UAAU,EACb,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"codegen-contract.d.ts","sourceRoot":"","sources":["../src/codegen-contract.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACR,gBAAgB,EAChB,SAAS,EAET,gBAAgB,EAWhB,UAAU,EACb,MAAM,mBAAmB,CAAC;AAO3B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAErD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAStD;AAID,4GAA4G;AAC5G,MAAM,WAAW,sBAAsB;IACnC,sDAAsD;IACtD,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,8DAA8D;IAC9D,cAAc,EAAE,MAAM,CAAC;IACvB,qFAAqF;IACrF,eAAe,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC9B,oFAAoF;IACpF,gBAAgB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC/B,6GAA6G;IAC7G,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B;;;;OAIG;IACH,MAAM,CAAC,EAAE,cAAc,CAAC;CAC3B;AAID;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,uBAAuB,GAAE,GAAG,CAAC,MAAM,CAAa,GAAG,GAAG,CAAC,MAAM,CAAC,CAsCzH;AAkBD;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,gBAAgB,EAAE,OAAO,CAAC,EAAE,sBAAsB,GAAG,MAAM,CAkEjG;AAgVD;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,gB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@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { OpRootNode } from '@contractkit/core';
|
|
2
|
+
export interface McpCodegenOptions {
|
|
3
|
+
/** Absolute path of the file being generated. Used to compute relative imports. */
|
|
4
|
+
outPath?: string;
|
|
5
|
+
/** Map from schema identifier (model name / `${name}Input`) → absolute output file. */
|
|
6
|
+
modelOutPaths?: Map<string, string>;
|
|
7
|
+
/** Model names that have an Input variant schema. */
|
|
8
|
+
modelsWithInput?: Set<string>;
|
|
9
|
+
/** Model names that have an Output variant schema. */
|
|
10
|
+
modelsWithOutput?: Set<string>;
|
|
11
|
+
/** Import-path template for service implementations (same semantics as ServerConfig). */
|
|
12
|
+
servicePathTemplate?: string;
|
|
13
|
+
/** Emit tools for `internal` operations. Default false. */
|
|
14
|
+
includeInternal?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* True if the root has at least one MCP-exposed operation. With `includeInternal: false`
|
|
18
|
+
* (default) `internal` operations don't count. Mirrors `hasPublicOperations`.
|
|
19
|
+
*/
|
|
20
|
+
export declare function hasMcpOperations(root: OpRootNode, includeInternal?: boolean): boolean;
|
|
21
|
+
/** The exported register-fn name for an op-root file, e.g. `payments.op` → `registerPaymentsMcpTools`. */
|
|
22
|
+
export declare function deriveMcpRegisterFnName(file: string): string;
|
|
23
|
+
/** Generate one `<filename>.mcp.ts` for an op-root: tool handler classes + a per-file register fn. */
|
|
24
|
+
export declare function generateMcpFile(root: OpRootNode, options?: McpCodegenOptions): string;
|
|
25
|
+
/** One entry per emitted `<filename>.mcp.ts` for the aggregator to import. */
|
|
26
|
+
export interface McpAggregatorEntry {
|
|
27
|
+
/** The file's exported register fn name, e.g. `registerPaymentsMcpTools`. */
|
|
28
|
+
registerFn: string;
|
|
29
|
+
/** Module specifier for the file, relative to the aggregator and `.js`-suffixed. */
|
|
30
|
+
importPath: string;
|
|
31
|
+
}
|
|
32
|
+
/** Generate the aggregator `mcp.tools.ts` that assembles the single McpToolHandlerMap. */
|
|
33
|
+
export declare function generateMcpAggregator(entries: McpAggregatorEntry[]): string;
|
|
34
|
+
/** Generate the optional `mcp.router.ts` — the standard ServerKit route wiring for the dispatcher. */
|
|
35
|
+
export declare function generateMcpRouter(options?: {
|
|
36
|
+
path?: string;
|
|
37
|
+
}): string;
|
|
38
|
+
//# sourceMappingURL=codegen-mcp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codegen-mcp.d.ts","sourceRoot":"","sources":["../src/codegen-mcp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAA8E,MAAM,mBAAmB,CAAC;AAShI,MAAM,WAAW,iBAAiB;IAC9B,mFAAmF;IACnF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uFAAuF;IACvF,aAAa,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,qDAAqD;IACrD,eAAe,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC9B,sDAAsD;IACtD,gBAAgB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC/B,yFAAyF;IACzF,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,2DAA2D;IAC3D,eAAe,CAAC,EAAE,OAAO,CAAC;CAC7B;AASD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,UAAU,EAAE,eAAe,UAAQ,GAAG,OAAO,CASnF;AAoVD,0GAA0G;AAC1G,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED,sGAAsG;AACtG,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,GAAE,iBAAsB,GAAG,MAAM,CA0DzF;AAED,8EAA8E;AAC9E,MAAM,WAAW,kBAAkB;IAC/B,6EAA6E;IAC7E,UAAU,EAAE,MAAM,CAAC;IACnB,oFAAoF;IACpF,UAAU,EAAE,MAAM,CAAC;CACtB;AAED,0FAA0F;AAC1F,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,kBAAkB,EAAE,GAAG,MAAM,CAe3E;AAED,sGAAsG;AACtG,wBAAgB,iBAAiB,CAAC,OAAO,GAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,MAAM,CAuBzE"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type { OpRootNode, ContractTypeNode } from '@contractkit/core';
|
|
1
|
+
import type { OpRootNode, OpRouteNode, OpOperationNode, ContractTypeNode } from '@contractkit/core';
|
|
2
2
|
/**
|
|
3
3
|
* Deep structural equality on ContractTypeNode, ignoring source locations on inline fields.
|
|
4
4
|
* Used to decide whether multiple declared request MIMEs can share a single validate path.
|
|
5
5
|
*/
|
|
6
6
|
export declare function bodyTypesStructurallyEqual(a: ContractTypeNode, b: ContractTypeNode): boolean;
|
|
7
|
+
/** Options controlling how {@link generateOp} renders a Koa router module. */
|
|
7
8
|
export interface OpCodegenOptions {
|
|
8
9
|
servicePathTemplate?: string;
|
|
9
10
|
typeImportPathTemplate?: string;
|
|
@@ -23,4 +24,44 @@ export interface OpCodegenOptions {
|
|
|
23
24
|
}
|
|
24
25
|
/** Generate a Koa router module for every operation in `root`, including the imports, type aliases, and handler list. */
|
|
25
26
|
export declare function generateOp(root: OpRootNode, options?: OpCodegenOptions): string;
|
|
27
|
+
/**
|
|
28
|
+
* Resolve the service class and method a handler should delegate to.
|
|
29
|
+
*
|
|
30
|
+
* Uses the operation's explicit `service: Class.method` declaration when present; otherwise derives
|
|
31
|
+
* the class from the contract file name (`ledger.categories.ck` → `LedgerCategoriesService`) and the
|
|
32
|
+
* method from the HTTP verb and whether the path carries a parameter (`get` → `list` / `getById`).
|
|
33
|
+
*
|
|
34
|
+
* @param file Path of the `.ck` file the operation came from.
|
|
35
|
+
*/
|
|
36
|
+
export declare function inferService(op: OpOperationNode, route: OpRouteNode, file: string): {
|
|
37
|
+
className: string;
|
|
38
|
+
methodName: string;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Build the comma-separated argument list passed to the service method in a generated handler.
|
|
42
|
+
*
|
|
43
|
+
* Order is params, body, query, headers. Inline path params are spread as individual identifiers;
|
|
44
|
+
* a referenced/compound params type is passed as a single `params` object. A lone
|
|
45
|
+
* `multipart/form-data` request body is passed as `multipartBody` rather than `body`.
|
|
46
|
+
*
|
|
47
|
+
* @returns The rendered argument list, or an empty string when the method takes no arguments.
|
|
48
|
+
*/
|
|
49
|
+
export declare function buildArgs(route: OpRouteNode, op: OpOperationNode): string;
|
|
50
|
+
/**
|
|
51
|
+
* Derive the PascalCase base name used for router, service, and type names from a contract file path.
|
|
52
|
+
*
|
|
53
|
+
* Strips directories and the `.op`/`.ck` extension, then PascalCases each dot-separated segment
|
|
54
|
+
* (`contracts/ledger.categories.ck` → `LedgerCategories`). Falls back to `Resource` for an empty path.
|
|
55
|
+
*/
|
|
56
|
+
export declare function deriveBaseName(file: string): string;
|
|
57
|
+
/**
|
|
58
|
+
* Resolve the import specifier for a service class.
|
|
59
|
+
*
|
|
60
|
+
* Drops the trailing `Service` suffix and kebab-cases the remainder, then applies `template` if given
|
|
61
|
+
* (`{name}` → `Ledger`, `{kebab}` → `ledger`). Without a template, defaults to
|
|
62
|
+
* `#modules/<kebab>/<kebab>.service.js`.
|
|
63
|
+
*
|
|
64
|
+
* @param template Optional `servicePathTemplate` from the plugin config.
|
|
65
|
+
*/
|
|
66
|
+
export declare function deriveModulePath(serviceName: string, template?: string): string;
|
|
26
67
|
//# sourceMappingURL=codegen-operation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codegen-operation.d.ts","sourceRoot":"","sources":["../src/codegen-operation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"codegen-operation.d.ts","sourceRoot":"","sources":["../src/codegen-operation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAA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 +5,9 @@ import type { ContractCodegenContext } from './codegen-contract.js';
|
|
|
5
5
|
* Unlike `generateContract()` which produces Zod schemas, this emits
|
|
6
6
|
* vanilla TypeScript `interface` and `type` declarations suitable
|
|
7
7
|
* for SDK consumers that don't need runtime validation.
|
|
8
|
+
*
|
|
9
|
+
* @param context Import resolution and Input/Output variant sets. `context.target` selects the
|
|
10
|
+
* runtime the types describe (`'server'` renders `binary` as `Buffer`, `'client'` as `Blob`).
|
|
8
11
|
*/
|
|
9
12
|
export declare function generatePlainTypes(root: ContractRootNode, context?: ContractCodegenContext): string;
|
|
10
13
|
//# sourceMappingURL=codegen-plain-types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codegen-plain-types.d.ts","sourceRoot":"","sources":["../src/codegen-plain-types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAwB,MAAM,mBAAmB,CAAC;AAEhF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"codegen-plain-types.d.ts","sourceRoot":"","sources":["../src/codegen-plain-types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAwB,MAAM,mBAAmB,CAAC;AAEhF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAcpE;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,gBAAgB,EAAE,OAAO,CAAC,EAAE,sBAAsB,GAAG,MAAM,CA4CnG"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ContractKitPlugin } from '@contractkit/core';
|
|
2
|
+
/** Koa server output: routers, and the type or Zod schema files they import. */
|
|
2
3
|
export interface ServerConfig {
|
|
3
4
|
/** Directory (relative to rootDir) where server files are written. Default: rootDir. */
|
|
4
5
|
baseDir?: string;
|
|
@@ -15,6 +16,7 @@ export interface ServerConfig {
|
|
|
15
16
|
/** Whether to emit handlers for `internal` operations. Default true. */
|
|
16
17
|
includeInternal?: boolean;
|
|
17
18
|
}
|
|
19
|
+
/** TypeScript SDK client output: the client class, per-area operation clients, and their types. */
|
|
18
20
|
export interface SdkConfig {
|
|
19
21
|
baseDir?: string;
|
|
20
22
|
name?: string;
|
|
@@ -35,19 +37,56 @@ export interface SdkConfig {
|
|
|
35
37
|
*/
|
|
36
38
|
scaffold?: boolean;
|
|
37
39
|
}
|
|
40
|
+
/** Standalone Zod schema output, independent of the server and SDK sub-generators. */
|
|
38
41
|
export interface ZodConfig {
|
|
39
42
|
baseDir?: string;
|
|
40
43
|
output?: string;
|
|
41
44
|
}
|
|
45
|
+
/** Standalone plain TypeScript type output, independent of the server and SDK sub-generators. */
|
|
42
46
|
export interface TypesConfig {
|
|
43
47
|
baseDir?: string;
|
|
44
48
|
output?: string;
|
|
49
|
+
/**
|
|
50
|
+
* Runtime the emitted types describe. Affects scalars whose TypeScript type is runtime-specific:
|
|
51
|
+
* `binary` renders as `Buffer` for `'server'` and `Blob` for `'client'`. Default `'client'`.
|
|
52
|
+
* The `server` and `sdk` sub-generators set this themselves.
|
|
53
|
+
*/
|
|
54
|
+
target?: 'client' | 'server';
|
|
55
|
+
}
|
|
56
|
+
/** MCP tool output: per-op-file handlers, the aggregator, and the optional POST route. */
|
|
57
|
+
export interface McpConfig {
|
|
58
|
+
/** Directory (relative to rootDir) where MCP files are written. Default: rootDir. */
|
|
59
|
+
baseDir?: string;
|
|
60
|
+
output?: {
|
|
61
|
+
/** Path template for per-op-file tool handlers. Supports {filename}, {dir}, {area}. Default `{filename}.mcp.ts`. */
|
|
62
|
+
tools?: string;
|
|
63
|
+
/** Path (or template) for the aggregator that assembles the McpToolHandlerMap. Default `mcp.tools.ts`. */
|
|
64
|
+
index?: string;
|
|
65
|
+
/** Path (or template) for the optional POST /mcp route file. Default `mcp.router.ts`. */
|
|
66
|
+
router?: string;
|
|
67
|
+
/**
|
|
68
|
+
* Path template for the model **Zod schema** files the tools import (for arg validation and
|
|
69
|
+
* `z.toJSONSchema`). When omitted, falls back to the `server` sub-config's `output.types`
|
|
70
|
+
* (if `server.zod`) or the `zod` sub-config's output. Tools require Zod schemas, not plain types.
|
|
71
|
+
*/
|
|
72
|
+
types?: string;
|
|
73
|
+
};
|
|
74
|
+
/** Emit the `mcp.router.ts` route boilerplate. Default true. */
|
|
75
|
+
emitRouter?: boolean;
|
|
76
|
+
/** Mount path used in the emitted router. Default `/mcp`. */
|
|
77
|
+
path?: string;
|
|
78
|
+
/** Import path template for service implementations (same semantics as ServerConfig). */
|
|
79
|
+
servicePathTemplate?: string;
|
|
80
|
+
/** Whether to expose operations marked `internal` as MCP tools. Default false. */
|
|
81
|
+
includeInternal?: boolean;
|
|
45
82
|
}
|
|
83
|
+
/** Top-level plugin config. Each sub-config that is present enables its sub-generator. */
|
|
46
84
|
export interface TypescriptPluginConfig {
|
|
47
85
|
server?: ServerConfig;
|
|
48
86
|
sdk?: SdkConfig;
|
|
49
87
|
zod?: ZodConfig;
|
|
50
88
|
types?: TypesConfig;
|
|
89
|
+
mcp?: McpConfig;
|
|
51
90
|
}
|
|
52
91
|
/** Bumped when the codegen output shape changes in a way that should bust every per-file fingerprint. */
|
|
53
92
|
export declare const TYPESCRIPT_CODEGEN_VERSION = "1";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACR,iBAAiB,EAQpB,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACR,iBAAiB,EAQpB,MAAM,mBAAmB,CAAC;AA8C3B,gFAAgF;AAChF,MAAM,WAAW,YAAY;IACzB,wFAAwF;IACxF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,6HA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