@contractkit/plugin-python 0.11.6 → 0.11.8
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 +4 -4
- package/.turbo/turbo-test$colon$ci.log +9 -9
- package/CHANGELOG.md +15 -0
- package/dist/codegen-client.d.ts.map +1 -1
- package/dist/codegen-models.d.ts +9 -0
- package/dist/codegen-models.d.ts.map +1 -1
- package/dist/index.js +24 -8
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/codegen-client.ts +17 -2
- package/src/codegen-models.ts +34 -8
- package/tests/codegen-client.test.ts +64 -0
- package/tests/codegen-models.test.ts +49 -0
- package/coverage/base.css +0 -224
- package/coverage/block-navigation.js +0 -87
- package/coverage/clover.xml +0 -559
- package/coverage/coverage-final.json +0 -4
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +0 -131
- package/coverage/prettify.css +0 -1
- package/coverage/prettify.js +0 -2
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +0 -210
- package/coverage/src/codegen-client.ts.html +0 -2071
- package/coverage/src/codegen-models.ts.html +0 -1360
- package/coverage/src/index.html +0 -131
- package/coverage/tests/helpers.ts.html +0 -667
- package/coverage/tests/index.html +0 -116
|
@@ -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[32m43.30 KB[39m
|
|
9
|
+
[32mESM[39m [1mdist/index.js.map [22m[32m92.85 KB[39m
|
|
10
|
+
[32mESM[39m ⚡️ Build success in 209ms
|
|
11
11
|
[34mDTS[39m Build start
|
|
12
|
-
[32mDTS[39m ⚡️ Build success in
|
|
12
|
+
[32mDTS[39m ⚡️ Build success in 5126ms
|
|
13
13
|
[32mDTS[39m [1mdist/index.d.ts [22m[32m1.10 KB[39m
|
|
@@ -3,22 +3,22 @@ $ vitest run --coverage
|
|
|
3
3
|
[1m[30m[46m RUN [49m[39m[22m [36mv4.1.5 [39m[90m/home/runner/work/ContractKit/ContractKit/packages/plugin-python[39m
|
|
4
4
|
[2mCoverage enabled with [22m[33mv8[39m
|
|
5
5
|
|
|
6
|
-
[32m✓[39m tests/codegen-models.test.ts [2m([22m[
|
|
7
|
-
[32m✓[39m tests/codegen-client.test.ts [2m([22m[
|
|
6
|
+
[32m✓[39m tests/codegen-models.test.ts [2m([22m[2m36 tests[22m[2m)[22m[32m 110[2mms[22m[39m
|
|
7
|
+
[32m✓[39m tests/codegen-client.test.ts [2m([22m[2m30 tests[22m[2m)[22m[32m 96[2mms[22m[39m
|
|
8
8
|
|
|
9
9
|
[2m Test Files [22m [1m[32m2 passed[39m[22m[90m (2)[39m
|
|
10
|
-
[2m Tests [22m [1m[
|
|
11
|
-
[2m Start at [22m 15:
|
|
12
|
-
[2m Duration [22m
|
|
10
|
+
[2m Tests [22m [1m[32m66 passed[39m[22m[90m (66)[39m
|
|
11
|
+
[2m Start at [22m 15:07:02
|
|
12
|
+
[2m Duration [22m 5.06s[2m (transform 1.91s, setup 0ms, import 6.42s, tests 206ms, environment 0ms)[22m
|
|
13
13
|
|
|
14
14
|
[34m % [39m[2mCoverage report from [22m[33mv8[39m
|
|
15
15
|
-------------------|---------|----------|---------|---------|-------------------
|
|
16
16
|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
|
|
17
17
|
-------------------|---------|----------|---------|---------|-------------------
|
|
18
|
-
All files |
|
|
19
|
-
src |
|
|
20
|
-
...gen-client.ts |
|
|
21
|
-
...gen-models.ts |
|
|
18
|
+
All files | 83.57 | 78.28 | 86.31 | 85.13 |
|
|
19
|
+
src | 83.33 | 78.6 | 84.28 | 84.61 |
|
|
20
|
+
...gen-client.ts | 83.18 | 78.96 | 87.17 | 83.56 | ...02-522,555-556
|
|
21
|
+
...gen-models.ts | 83.53 | 78.06 | 80.64 | 85.97 | ...59,373-375,379
|
|
22
22
|
tests | 86.66 | 74.19 | 92 | 92.1 |
|
|
23
23
|
helpers.ts | 86.66 | 74.19 | 92 | 92.1 | 137-141,167
|
|
24
24
|
-------------------|---------|----------|---------|---------|-------------------
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @contractkit/contractkit-plugin-python
|
|
2
2
|
|
|
3
|
+
## 0.11.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [23e4beb]
|
|
8
|
+
- @contractkit/core@0.24.0
|
|
9
|
+
|
|
10
|
+
## 0.11.7
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 2bf01f1: Split multi-line descriptions across `#` comment lines and escape `"""` in generated method docstrings so ordinary multi-line doc comments can no longer produce invalid Python. Render the `interval` scalar as `str` and throw on an unmapped scalar type instead of falling back to `Any`.
|
|
15
|
+
- Updated dependencies [2bf01f1]
|
|
16
|
+
- @contractkit/core@0.23.0
|
|
17
|
+
|
|
3
18
|
## 0.11.6
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codegen-client.d.ts","sourceRoot":"","sources":["../src/codegen-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAqF,MAAM,mBAAmB,CAAC;AAMvI,MAAM,WAAW,oBAAoB;IACjC,0EAA0E;IAC1E,gBAAgB,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC,0FAA0F;IAC1F,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,kDAAkD;IAClD,eAAe,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 export interface ModelCodegenOptions {
|
|
|
11
11
|
* Generate Pydantic v2 model classes from a ContractRootNode.
|
|
12
12
|
*/
|
|
13
13
|
export declare function generatePydanticModels(root: ContractRootNode, opts?: ModelCodegenOptions): string;
|
|
14
|
+
/**
|
|
15
|
+
* Render a ContractKit type node as its Python type annotation (Pydantic v2 conventions).
|
|
16
|
+
*
|
|
17
|
+
* @param modelsWithInput - Model names that have a distinct `Input` variant; a `ref` to one of
|
|
18
|
+
* these renders as `<Name>Input` when `forInput` is set.
|
|
19
|
+
* @param forInput - When true, request-side refs use their `Input` variant.
|
|
20
|
+
* @throws {Error} Via the scalar renderer, if a scalar name has no Python mapping (guards against
|
|
21
|
+
* a scalar being added to core without updating this plugin).
|
|
22
|
+
*/
|
|
14
23
|
export declare function renderPyType(type: ContractTypeNode, modelsWithInput?: Set<string>, forInput?: boolean): string;
|
|
15
24
|
/** Convert a field name to a valid Python identifier in snake_case. */
|
|
16
25
|
export declare function toPythonFieldName(name: string): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codegen-models.d.ts","sourceRoot":"","sources":["../src/codegen-models.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAwB,gBAAgB,
|
|
1
|
+
{"version":3,"file":"codegen-models.d.ts","sourceRoot":"","sources":["../src/codegen-models.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAwB,gBAAgB,EAAkB,MAAM,mBAAmB,CAAC;AAKlH,MAAM,WAAW,mBAAmB;IAChC,wEAAwE;IACxE,gBAAgB,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC,6DAA6D;IAC7D,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,+DAA+D;IAC/D,eAAe,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CACjC;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,gBAAgB,EAAE,IAAI,GAAE,mBAAwB,GAAG,MAAM,CAwDrG;AAsGD;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,gBAAgB,EAAE,eAAe,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,QAAQ,UAAQ,GAAG,MAAM,CAkC5G;AA6CD,uEAAuE;AACvE,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAUtD;AAuKD,kHAAkH;AAClH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQ3D"}
|
package/dist/index.js
CHANGED
|
@@ -221,6 +221,8 @@ function renderScalar(name) {
|
|
|
221
221
|
return "datetime";
|
|
222
222
|
case "duration":
|
|
223
223
|
return "timedelta";
|
|
224
|
+
case "interval":
|
|
225
|
+
return "str";
|
|
224
226
|
case "uuid":
|
|
225
227
|
return "UUID";
|
|
226
228
|
case "null":
|
|
@@ -231,8 +233,10 @@ function renderScalar(name) {
|
|
|
231
233
|
case "json":
|
|
232
234
|
case "object":
|
|
233
235
|
return "Any";
|
|
234
|
-
default:
|
|
235
|
-
|
|
236
|
+
default: {
|
|
237
|
+
const _exhaustive = name;
|
|
238
|
+
throw new Error(`plugin-python: unmapped scalar '${String(_exhaustive)}' \u2014 add a case`);
|
|
239
|
+
}
|
|
236
240
|
}
|
|
237
241
|
}
|
|
238
242
|
__name(renderScalar, "renderScalar");
|
|
@@ -244,6 +248,10 @@ function toPythonFieldName(name) {
|
|
|
244
248
|
return result;
|
|
245
249
|
}
|
|
246
250
|
__name(toPythonFieldName, "toPythonFieldName");
|
|
251
|
+
function commentLines(text, indent) {
|
|
252
|
+
return text.split("\n").map((line) => `${indent}# ${line}`);
|
|
253
|
+
}
|
|
254
|
+
__name(commentLines, "commentLines");
|
|
247
255
|
function generateModel(model, allModelsWithInput, imports) {
|
|
248
256
|
if (model.type) {
|
|
249
257
|
return generateTypeAlias(model, allModelsWithInput, imports);
|
|
@@ -257,7 +265,7 @@ function generateModel(model, allModelsWithInput, imports) {
|
|
|
257
265
|
__name(generateModel, "generateModel");
|
|
258
266
|
function generateTypeAlias(model, allModelsWithInput, _) {
|
|
259
267
|
const lines = [];
|
|
260
|
-
if (model.description) lines.push(
|
|
268
|
+
if (model.description) lines.push(...commentLines(model.description, ""));
|
|
261
269
|
if (model.deprecated) lines.push("# @deprecated");
|
|
262
270
|
lines.push(`${model.name} = ${renderPyType(model.type, allModelsWithInput)}`);
|
|
263
271
|
if (allModelsWithInput.has(model.name)) {
|
|
@@ -268,7 +276,7 @@ function generateTypeAlias(model, allModelsWithInput, _) {
|
|
|
268
276
|
__name(generateTypeAlias, "generateTypeAlias");
|
|
269
277
|
function generateSimpleModel(model, allModelsWithInput, imports) {
|
|
270
278
|
const lines = [];
|
|
271
|
-
if (model.description) lines.push(
|
|
279
|
+
if (model.description) lines.push(...commentLines(model.description, ""));
|
|
272
280
|
if (model.deprecated) lines.push("# @deprecated");
|
|
273
281
|
const baseList = model.bases && model.bases.length > 0 ? model.bases.join(", ") : "BaseModel";
|
|
274
282
|
lines.push(`class ${model.name}(${baseList}):`);
|
|
@@ -290,7 +298,7 @@ __name(generateSimpleModel, "generateSimpleModel");
|
|
|
290
298
|
function generateSplitModel(model, allModelsWithInput, imports) {
|
|
291
299
|
const lines = [];
|
|
292
300
|
const readFields = model.fields.filter((f) => f.visibility !== "writeonly");
|
|
293
|
-
if (model.description) lines.push(
|
|
301
|
+
if (model.description) lines.push(...commentLines(model.description, ""));
|
|
294
302
|
if (model.deprecated) lines.push("# @deprecated");
|
|
295
303
|
const readBaseList = model.bases && model.bases.length > 0 ? model.bases.join(", ") : "BaseModel";
|
|
296
304
|
lines.push(`class ${model.name}(${readBaseList}):`);
|
|
@@ -350,7 +358,7 @@ function renderField(field, allModelsWithInput, imports, forInput) {
|
|
|
350
358
|
fieldAnnotations.push(`default=${def}`);
|
|
351
359
|
}
|
|
352
360
|
if (field.deprecated) lines.push(` # @deprecated`);
|
|
353
|
-
if (field.description) lines.push(
|
|
361
|
+
if (field.description) lines.push(...commentLines(field.description, " "));
|
|
354
362
|
let rhs;
|
|
355
363
|
if (fieldAnnotations.length > 0) {
|
|
356
364
|
imports.add("pydantic", "Field");
|
|
@@ -511,8 +519,8 @@ function generateMethod(route, op, opts) {
|
|
|
511
519
|
if (op.name || desc) {
|
|
512
520
|
lines.push(` async def ${methodName}(${selfParam}${paramStr}) -> ${returnType}:`);
|
|
513
521
|
lines.push(` """`);
|
|
514
|
-
if (op.name) lines.push(
|
|
515
|
-
if (desc) lines.push(
|
|
522
|
+
if (op.name) lines.push(...docstringLines(op.name, " "));
|
|
523
|
+
if (desc) lines.push(...docstringLines(desc, " "));
|
|
516
524
|
lines.push(` """`);
|
|
517
525
|
} else {
|
|
518
526
|
lines.push(` async def ${methodName}(${selfParam}${paramStr}) -> ${returnType}:`);
|
|
@@ -596,6 +604,14 @@ function buildHeadersDictLines(headers, typeName) {
|
|
|
596
604
|
return lines;
|
|
597
605
|
}
|
|
598
606
|
__name(buildHeadersDictLines, "buildHeadersDictLines");
|
|
607
|
+
function docstringLines(text, indent) {
|
|
608
|
+
return text.split("\n").map((line) => {
|
|
609
|
+
let safe = line.replace(/"/g, '\\"');
|
|
610
|
+
if (/\\$/.test(safe)) safe += " ";
|
|
611
|
+
return `${indent}${safe}`;
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
__name(docstringLines, "docstringLines");
|
|
599
615
|
function snakeToPascal(s) {
|
|
600
616
|
return s.split("_").filter(Boolean).map((p) => p.charAt(0).toUpperCase() + p.slice(1)).join("");
|
|
601
617
|
}
|