@contractkit/plugin-typescript 0.23.1 → 0.25.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 +6 -6
- package/.turbo/turbo-test$colon$ci.log +14 -14
- package/CHANGELOG.md +48 -0
- package/coverage/clover.xml +784 -779
- package/coverage/coverage-final.json +3 -3
- package/coverage/index.html +15 -15
- package/coverage/src/codegen-contract.ts.html +252 -207
- package/coverage/src/codegen-operation.ts.html +29 -11
- package/coverage/src/codegen-plain-types.ts.html +1 -1
- package/coverage/src/codegen-sdk.ts.html +1 -1
- package/coverage/src/index.html +19 -19
- package/coverage/src/index.ts.html +1 -1
- package/coverage/src/path-utils.ts.html +1 -1
- package/coverage/src/ts-render.ts.html +1 -1
- package/coverage/tests/helpers.ts.html +7 -7
- package/coverage/tests/index.html +1 -1
- package/dist/codegen-contract.d.ts.map +1 -1
- package/dist/index.js +21 -12
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/codegen-contract.ts +22 -7
- package/src/codegen-operation.ts +11 -5
- package/tests/codegen-contract.test.ts +39 -3
- package/tests/codegen-operation.test.ts +36 -36
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
<div class='clearfix'>
|
|
24
24
|
|
|
25
25
|
<div class='fl pad1y space-right2'>
|
|
26
|
-
<span class="strong">78.
|
|
26
|
+
<span class="strong">78.18% </span>
|
|
27
27
|
<span class="quiet">Statements</span>
|
|
28
|
-
<span class='fraction'>
|
|
28
|
+
<span class='fraction'>362/463</span>
|
|
29
29
|
</div>
|
|
30
30
|
|
|
31
31
|
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
|
|
45
45
|
|
|
46
46
|
<div class='fl pad1y space-right2'>
|
|
47
|
-
<span class="strong">79.
|
|
47
|
+
<span class="strong">79.75% </span>
|
|
48
48
|
<span class="quiet">Lines</span>
|
|
49
|
-
<span class='fraction'>
|
|
49
|
+
<span class='fraction'>319/400</span>
|
|
50
50
|
</div>
|
|
51
51
|
|
|
52
52
|
|
|
@@ -879,7 +879,13 @@
|
|
|
879
879
|
<a name='L814'></a><a href='#L814'>814</a>
|
|
880
880
|
<a name='L815'></a><a href='#L815'>815</a>
|
|
881
881
|
<a name='L816'></a><a href='#L816'>816</a>
|
|
882
|
-
<a name='L817'></a><a href='#L817'>817</a
|
|
882
|
+
<a name='L817'></a><a href='#L817'>817</a>
|
|
883
|
+
<a name='L818'></a><a href='#L818'>818</a>
|
|
884
|
+
<a name='L819'></a><a href='#L819'>819</a>
|
|
885
|
+
<a name='L820'></a><a href='#L820'>820</a>
|
|
886
|
+
<a name='L821'></a><a href='#L821'>821</a>
|
|
887
|
+
<a name='L822'></a><a href='#L822'>822</a>
|
|
888
|
+
<a name='L823'></a><a href='#L823'>823</a></td><td class="line-coverage quiet"><span class="cline-any cline-neutral"> </span>
|
|
883
889
|
<span class="cline-any cline-neutral"> </span>
|
|
884
890
|
<span class="cline-any cline-neutral"> </span>
|
|
885
891
|
<span class="cline-any cline-neutral"> </span>
|
|
@@ -1123,6 +1129,12 @@
|
|
|
1123
1129
|
<span class="cline-any cline-yes">111x</span>
|
|
1124
1130
|
<span class="cline-any cline-yes">111x</span>
|
|
1125
1131
|
<span class="cline-any cline-yes">108x</span>
|
|
1132
|
+
<span class="cline-any cline-neutral"> </span>
|
|
1133
|
+
<span class="cline-any cline-yes">108x</span>
|
|
1134
|
+
<span class="cline-any cline-neutral"> </span>
|
|
1135
|
+
<span class="cline-any cline-neutral"> </span>
|
|
1136
|
+
<span class="cline-any cline-neutral"> </span>
|
|
1137
|
+
<span class="cline-any cline-neutral"> </span>
|
|
1126
1138
|
<span class="cline-any cline-yes">108x</span>
|
|
1127
1139
|
<span class="cline-any cline-neutral"> </span>
|
|
1128
1140
|
<span class="cline-any cline-yes">111x</span>
|
|
@@ -1834,9 +1846,9 @@ export function generateOp(root: OpRootNode, options: OpCodegenOptions = {}): st
|
|
|
1834
1846
|
// before deciding whether to emit the zod import.
|
|
1835
1847
|
const body: string[] = [];
|
|
1836
1848
|
const needsSignature = fileNeedsSignature(root);
|
|
1837
|
-
const
|
|
1849
|
+
const needsPolicy = fileNeedsPolicy(root);
|
|
1838
1850
|
const koaImports = ['ServerKitRouter', 'bodyParserMiddleware'];
|
|
1839
|
-
if (
|
|
1851
|
+
if (needsPolicy) koaImports.push('requirePolicy');
|
|
1840
1852
|
if (needsSignature) koaImports.push('requireSignature');
|
|
1841
1853
|
body.push(`import { ${koaImports.join(', ')} } from '@maroonedsoftware/koa';`);
|
|
1842
1854
|
|
|
@@ -1938,8 +1950,14 @@ function generateHandler(route: OpRouteNode, op: OpOperationNode, root: OpRootNo
|
|
|
1938
1950
|
// Middleware list
|
|
1939
1951
|
const middlewares: string[] = [];
|
|
1940
1952
|
if (effectiveSecurity !== SECURITY_NONE) {
|
|
1941
|
-
const
|
|
1942
|
-
|
|
1953
|
+
const policy = effectiveSecurity?.policy;
|
|
1954
|
+
const args =
|
|
1955
|
+
policy === undefined
|
|
1956
|
+
? ''
|
|
1957
|
+
: policy === false
|
|
1958
|
+
? '{ policy: false }'
|
|
1959
|
+
: `{ policy: '${policy}' }`;
|
|
1960
|
+
middlewares.push(`requirePolicy(${args})`);
|
|
1943
1961
|
}
|
|
1944
1962
|
if (hasBody) {
|
|
1945
1963
|
const parserTokens = Array.from(new Set(bodies.map(b => bodyParserToken(b.contentType))));
|
|
@@ -2458,7 +2476,7 @@ function routeNeedsValidation(root: OpRootNode): boolean {
|
|
|
2458
2476
|
);
|
|
2459
2477
|
}
|
|
2460
2478
|
|
|
2461
|
-
function
|
|
2479
|
+
function fileNeedsPolicy(root: OpRootNode): boolean {
|
|
2462
2480
|
return root.routes.some(route => route.operations.some(op => resolveSecurity(route, op, root) !== SECURITY_NONE));
|
|
2463
2481
|
}
|
|
2464
2482
|
|
|
@@ -2518,7 +2536,7 @@ function deriveTypeImportPath(file: string, template?: string): string {
|
|
|
2518
2536
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
2519
2537
|
Code coverage generated by
|
|
2520
2538
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
2521
|
-
at 2026-05-
|
|
2539
|
+
at 2026-05-13T17:08:53.091Z
|
|
2522
2540
|
</div>
|
|
2523
2541
|
<script src="../prettify.js"></script>
|
|
2524
2542
|
<script>
|
|
@@ -982,7 +982,7 @@ function renderOutputField(field: FieldNode, outputCase: 'camel' | 'snake' | 'pa
|
|
|
982
982
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
983
983
|
Code coverage generated by
|
|
984
984
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
985
|
-
at 2026-05-
|
|
985
|
+
at 2026-05-13T17:08:53.091Z
|
|
986
986
|
</div>
|
|
987
987
|
<script src="../prettify.js"></script>
|
|
988
988
|
<script>
|
|
@@ -3652,7 +3652,7 @@ export function generateSdkAggregator(input: SdkAggregatorInput): string {
|
|
|
3652
3652
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
3653
3653
|
Code coverage generated by
|
|
3654
3654
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
3655
|
-
at 2026-05-
|
|
3655
|
+
at 2026-05-13T17:08:53.091Z
|
|
3656
3656
|
</div>
|
|
3657
3657
|
<script src="../prettify.js"></script>
|
|
3658
3658
|
<script>
|
package/coverage/src/index.html
CHANGED
|
@@ -23,16 +23,16 @@
|
|
|
23
23
|
<div class='clearfix'>
|
|
24
24
|
|
|
25
25
|
<div class='fl pad1y space-right2'>
|
|
26
|
-
<span class="strong">79.
|
|
26
|
+
<span class="strong">79.79% </span>
|
|
27
27
|
<span class="quiet">Statements</span>
|
|
28
|
-
<span class='fraction'>
|
|
28
|
+
<span class='fraction'>1987/2490</span>
|
|
29
29
|
</div>
|
|
30
30
|
|
|
31
31
|
|
|
32
32
|
<div class='fl pad1y space-right2'>
|
|
33
|
-
<span class="strong">74.
|
|
33
|
+
<span class="strong">74.96% </span>
|
|
34
34
|
<span class="quiet">Branches</span>
|
|
35
|
-
<span class='fraction'>
|
|
35
|
+
<span class='fraction'>1204/1606</span>
|
|
36
36
|
</div>
|
|
37
37
|
|
|
38
38
|
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
|
|
45
45
|
|
|
46
46
|
<div class='fl pad1y space-right2'>
|
|
47
|
-
<span class="strong">82.
|
|
47
|
+
<span class="strong">82.38% </span>
|
|
48
48
|
<span class="quiet">Lines</span>
|
|
49
|
-
<span class='fraction'>
|
|
49
|
+
<span class='fraction'>1740/2112</span>
|
|
50
50
|
</div>
|
|
51
51
|
|
|
52
52
|
|
|
@@ -80,32 +80,32 @@
|
|
|
80
80
|
</thead>
|
|
81
81
|
<tbody><tr>
|
|
82
82
|
<td class="file high" data-value="codegen-contract.ts"><a href="codegen-contract.ts.html">codegen-contract.ts</a></td>
|
|
83
|
-
<td data-value="87.
|
|
83
|
+
<td data-value="87.92" class="pic high">
|
|
84
84
|
<div class="chart"><div class="cover-fill" style="width: 87%"></div><div class="cover-empty" style="width: 13%"></div></div>
|
|
85
85
|
</td>
|
|
86
|
-
<td data-value="87.
|
|
87
|
-
<td data-value="
|
|
88
|
-
<td data-value="82.
|
|
89
|
-
<td data-value="
|
|
86
|
+
<td data-value="87.92" class="pct high">87.92%</td>
|
|
87
|
+
<td data-value="679" class="abs high">597/679</td>
|
|
88
|
+
<td data-value="82.7" class="pct high">82.7%</td>
|
|
89
|
+
<td data-value="474" class="abs high">392/474</td>
|
|
90
90
|
<td data-value="90.08" class="pct high">90.08%</td>
|
|
91
91
|
<td data-value="121" class="abs high">109/121</td>
|
|
92
|
-
<td data-value="
|
|
93
|
-
<td data-value="
|
|
92
|
+
<td data-value="89.06" class="pct high">89.06%</td>
|
|
93
|
+
<td data-value="558" class="abs high">497/558</td>
|
|
94
94
|
</tr>
|
|
95
95
|
|
|
96
96
|
<tr>
|
|
97
97
|
<td class="file medium" data-value="codegen-operation.ts"><a href="codegen-operation.ts.html">codegen-operation.ts</a></td>
|
|
98
|
-
<td data-value="78.
|
|
98
|
+
<td data-value="78.18" class="pic medium">
|
|
99
99
|
<div class="chart"><div class="cover-fill" style="width: 78%"></div><div class="cover-empty" style="width: 22%"></div></div>
|
|
100
100
|
</td>
|
|
101
|
-
<td data-value="78.
|
|
102
|
-
<td data-value="
|
|
101
|
+
<td data-value="78.18" class="pct medium">78.18%</td>
|
|
102
|
+
<td data-value="463" class="abs medium">362/463</td>
|
|
103
103
|
<td data-value="74.26" class="pct medium">74.26%</td>
|
|
104
104
|
<td data-value="338" class="abs medium">251/338</td>
|
|
105
105
|
<td data-value="77.77" class="pct medium">77.77%</td>
|
|
106
106
|
<td data-value="72" class="abs medium">56/72</td>
|
|
107
|
-
<td data-value="79.
|
|
108
|
-
<td data-value="
|
|
107
|
+
<td data-value="79.75" class="pct medium">79.75%</td>
|
|
108
|
+
<td data-value="400" class="abs medium">319/400</td>
|
|
109
109
|
</tr>
|
|
110
110
|
|
|
111
111
|
<tr>
|
|
@@ -191,7 +191,7 @@
|
|
|
191
191
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
192
192
|
Code coverage generated by
|
|
193
193
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
194
|
-
at 2026-05-
|
|
194
|
+
at 2026-05-13T17:08:53.091Z
|
|
195
195
|
</div>
|
|
196
196
|
<script src="../prettify.js"></script>
|
|
197
197
|
<script>
|
|
@@ -2635,7 +2635,7 @@ function stableSubConfig(config: unknown): string {
|
|
|
2635
2635
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
2636
2636
|
Code coverage generated by
|
|
2637
2637
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
2638
|
-
at 2026-05-
|
|
2638
|
+
at 2026-05-13T17:08:53.091Z
|
|
2639
2639
|
</div>
|
|
2640
2640
|
<script src="../prettify.js"></script>
|
|
2641
2641
|
<script>
|
|
@@ -730,7 +730,7 @@ export function <span class="fstat-no" title="function not covered" >computePubl
|
|
|
730
730
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
731
731
|
Code coverage generated by
|
|
732
732
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
733
|
-
at 2026-05-
|
|
733
|
+
at 2026-05-13T17:08:53.091Z
|
|
734
734
|
</div>
|
|
735
735
|
<script src="../prettify.js"></script>
|
|
736
736
|
<script>
|
|
@@ -577,7 +577,7 @@ export function renderOutputTsType(type: ContractTypeNode, modelsWithOutput?: Se
|
|
|
577
577
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
578
578
|
Code coverage generated by
|
|
579
579
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
580
|
-
at 2026-05-
|
|
580
|
+
at 2026-05-13T17:08:53.091Z
|
|
581
581
|
</div>
|
|
582
582
|
<script src="../prettify.js"></script>
|
|
583
583
|
<script>
|
|
@@ -341,11 +341,11 @@
|
|
|
341
341
|
<span class="cline-any cline-neutral"> </span>
|
|
342
342
|
<span class="cline-any cline-neutral"> </span>
|
|
343
343
|
<span class="cline-any cline-neutral"> </span>
|
|
344
|
-
<span class="cline-any cline-yes">
|
|
344
|
+
<span class="cline-any cline-yes">903x</span>
|
|
345
345
|
<span class="cline-any cline-neutral"> </span>
|
|
346
346
|
<span class="cline-any cline-neutral"> </span>
|
|
347
347
|
<span class="cline-any cline-neutral"> </span>
|
|
348
|
-
<span class="cline-any cline-yes">
|
|
348
|
+
<span class="cline-any cline-yes">325x</span>
|
|
349
349
|
<span class="cline-any cline-neutral"> </span>
|
|
350
350
|
<span class="cline-any cline-neutral"> </span>
|
|
351
351
|
<span class="cline-any cline-neutral"> </span>
|
|
@@ -381,7 +381,7 @@
|
|
|
381
381
|
<span class="cline-any cline-neutral"> </span>
|
|
382
382
|
<span class="cline-any cline-neutral"> </span>
|
|
383
383
|
<span class="cline-any cline-neutral"> </span>
|
|
384
|
-
<span class="cline-any cline-yes">
|
|
384
|
+
<span class="cline-any cline-yes">11x</span>
|
|
385
385
|
<span class="cline-any cline-neutral"> </span>
|
|
386
386
|
<span class="cline-any cline-neutral"> </span>
|
|
387
387
|
<span class="cline-any cline-neutral"> </span>
|
|
@@ -389,7 +389,7 @@
|
|
|
389
389
|
<span class="cline-any cline-neutral"> </span>
|
|
390
390
|
<span class="cline-any cline-neutral"> </span>
|
|
391
391
|
<span class="cline-any cline-neutral"> </span>
|
|
392
|
-
<span class="cline-any cline-yes">
|
|
392
|
+
<span class="cline-any cline-yes">265x</span>
|
|
393
393
|
<span class="cline-any cline-neutral"> </span>
|
|
394
394
|
<span class="cline-any cline-neutral"> </span>
|
|
395
395
|
<span class="cline-any cline-neutral"> </span>
|
|
@@ -401,7 +401,7 @@
|
|
|
401
401
|
<span class="cline-any cline-neutral"> </span>
|
|
402
402
|
<span class="cline-any cline-neutral"> </span>
|
|
403
403
|
<span class="cline-any cline-neutral"> </span>
|
|
404
|
-
<span class="cline-any cline-yes">
|
|
404
|
+
<span class="cline-any cline-yes">181x</span>
|
|
405
405
|
<span class="cline-any cline-neutral"> </span>
|
|
406
406
|
<span class="cline-any cline-neutral"> </span>
|
|
407
407
|
<span class="cline-any cline-neutral"> </span>
|
|
@@ -411,7 +411,7 @@
|
|
|
411
411
|
<span class="cline-any cline-neutral"> </span>
|
|
412
412
|
<span class="cline-any cline-neutral"> </span>
|
|
413
413
|
<span class="cline-any cline-neutral"> </span>
|
|
414
|
-
<span class="cline-any cline-yes">
|
|
414
|
+
<span class="cline-any cline-yes">140x</span>
|
|
415
415
|
<span class="cline-any cline-neutral"> </span>
|
|
416
416
|
<span class="cline-any cline-neutral"> </span>
|
|
417
417
|
<span class="cline-any cline-neutral"> </span>
|
|
@@ -811,7 +811,7 @@ operation /users/{id}: {
|
|
|
811
811
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
812
812
|
Code coverage generated by
|
|
813
813
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
814
|
-
at 2026-05-
|
|
814
|
+
at 2026-05-13T17:08:53.091Z
|
|
815
815
|
</div>
|
|
816
816
|
<script src="../prettify.js"></script>
|
|
817
817
|
<script>
|
|
@@ -101,7 +101,7 @@
|
|
|
101
101
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
102
102
|
Code coverage generated by
|
|
103
103
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
104
|
-
at 2026-05-
|
|
104
|
+
at 2026-05-13T17:08:53.091Z
|
|
105
105
|
</div>
|
|
106
106
|
<script src="../prettify.js"></script>
|
|
107
107
|
<script>
|
|
@@ -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;AAO3B;;;;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;CAChC;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;
|
|
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;;;;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;CAChC;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,gBAAgB,EAAE,kBAAkB,CAAC,EAAE,OAAO,GAAG,QAAQ,EAAE,WAAW,CAAC,EAAE,UAAU,GAAG,MAAM,CA6B5H;AAgOD;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,gBAAgB,EAAE,eAAe,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC,EAAE,UAAU,GAAG,MAAM,CAuDvH;AA2BD;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,gBAAgB,EAAE,eAAe,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC,EAAE,UAAU,GAAG,MAAM,CAsCvH;AA0CD,oFAAoF;AACpF,wBAAgB,eAAe,CAAC,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAuB7E;AAED,+EAA+E;AAC/E,wBAAgB,eAAe,CAAC,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAE7E;AAED,4FAA4F;AAC5F,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAiBjE;AAED,mGAAmG;AACnG,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,gBAAgB,GAAG,MAAM,EAAE,CAcpE;AAED,0EAA0E;AAC1E,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,gBAAgB,EAAE,eAAe,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,MAAM,EAAE,CA4BvG;AAmCD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,SAAS,EAAE,CA6D/D;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,sBAAsB,GAAG,MAAM,CAgB3F;AAED,gGAAgG;AAChG,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEpD"}
|
package/dist/index.js
CHANGED
|
@@ -197,8 +197,12 @@ function generateSimpleModel(model, outPath) {
|
|
|
197
197
|
for (const field of model.fields) {
|
|
198
198
|
const inputKey = applyCase(field.name, inputCase);
|
|
199
199
|
const outputKey = applyCase(field.name, outputCase);
|
|
200
|
-
|
|
201
|
-
|
|
200
|
+
if (field.optional) {
|
|
201
|
+
const guard = hasInputTransform ? `data.${inputKey} != null` : `data.${inputKey} !== undefined`;
|
|
202
|
+
lines.push(` ...(${guard} ? { ${quoteKey(outputKey)}: data.${inputKey} } : {}),`);
|
|
203
|
+
} else {
|
|
204
|
+
lines.push(` ${quoteKey(outputKey)}: data.${inputKey},`);
|
|
205
|
+
}
|
|
202
206
|
}
|
|
203
207
|
lines.push(`}));`);
|
|
204
208
|
const typeSource = hasOutputTransform && !hasInputTransform ? "input" : "output";
|
|
@@ -567,8 +571,10 @@ function renderInlineObject(o, parseCaseTransform, defaultMode) {
|
|
|
567
571
|
const joined = snakeLines.map((l) => ` ${l}`).join("\n");
|
|
568
572
|
const transformEntries = o.fields.map((f) => {
|
|
569
573
|
const snakeKey = camelToSnake(f.name);
|
|
570
|
-
|
|
571
|
-
|
|
574
|
+
if (f.optional) {
|
|
575
|
+
return ` ...(data.${snakeKey} != null ? { ${quoteKey(f.name)}: data.${snakeKey} } : {}),`;
|
|
576
|
+
}
|
|
577
|
+
return ` ${quoteKey(f.name)}: data.${snakeKey},`;
|
|
572
578
|
}).join("\n");
|
|
573
579
|
return `${wrapper}({
|
|
574
580
|
${joined}
|
|
@@ -581,8 +587,10 @@ ${transformEntries}
|
|
|
581
587
|
const joined = pascalLines.map((l) => ` ${l}`).join("\n");
|
|
582
588
|
const transformEntries = o.fields.map((f) => {
|
|
583
589
|
const pascalKey = camelToPascal(f.name);
|
|
584
|
-
|
|
585
|
-
|
|
590
|
+
if (f.optional) {
|
|
591
|
+
return ` ...(data.${pascalKey} != null ? { ${quoteKey(f.name)}: data.${pascalKey} } : {}),`;
|
|
592
|
+
}
|
|
593
|
+
return ` ${quoteKey(f.name)}: data.${pascalKey},`;
|
|
586
594
|
}).join("\n");
|
|
587
595
|
return `${wrapper}({
|
|
588
596
|
${joined}
|
|
@@ -1164,12 +1172,12 @@ function generateOp(root, options = {}) {
|
|
|
1164
1172
|
const needsParseAndValidate = routeNeedsValidation(root);
|
|
1165
1173
|
const body = [];
|
|
1166
1174
|
const needsSignature = fileNeedsSignature(root);
|
|
1167
|
-
const
|
|
1175
|
+
const needsPolicy = fileNeedsPolicy(root);
|
|
1168
1176
|
const koaImports = [
|
|
1169
1177
|
"ServerKitRouter",
|
|
1170
1178
|
"bodyParserMiddleware"
|
|
1171
1179
|
];
|
|
1172
|
-
if (
|
|
1180
|
+
if (needsPolicy) koaImports.push("requirePolicy");
|
|
1173
1181
|
if (needsSignature) koaImports.push("requireSignature");
|
|
1174
1182
|
body.push(`import { ${koaImports.join(", ")} } from '@maroonedsoftware/koa';`);
|
|
1175
1183
|
for (const svc of services) {
|
|
@@ -1252,8 +1260,9 @@ function generateHandler(route, op, root, options) {
|
|
|
1252
1260
|
const isSingleMultipart = bodies.length === 1 && bodies[0].contentType === "multipart/form-data";
|
|
1253
1261
|
const middlewares = [];
|
|
1254
1262
|
if (effectiveSecurity !== SECURITY_NONE) {
|
|
1255
|
-
const
|
|
1256
|
-
|
|
1263
|
+
const policy = effectiveSecurity?.policy;
|
|
1264
|
+
const args = policy === void 0 ? "" : policy === false ? "{ policy: false }" : `{ policy: '${policy}' }`;
|
|
1265
|
+
middlewares.push(`requirePolicy(${args})`);
|
|
1257
1266
|
}
|
|
1258
1267
|
if (hasBody) {
|
|
1259
1268
|
const parserTokens = Array.from(new Set(bodies.map((b) => bodyParserToken(b.contentType))));
|
|
@@ -1696,10 +1705,10 @@ function routeNeedsValidation(root) {
|
|
|
1696
1705
|
return root.routes.some((r) => hasParamSource(r.params) || r.operations.some((op) => !!op.request || hasParamSource(op.query) || hasParamSource(op.headers)));
|
|
1697
1706
|
}
|
|
1698
1707
|
__name(routeNeedsValidation, "routeNeedsValidation");
|
|
1699
|
-
function
|
|
1708
|
+
function fileNeedsPolicy(root) {
|
|
1700
1709
|
return root.routes.some((route) => route.operations.some((op) => resolveSecurity(route, op, root) !== SECURITY_NONE));
|
|
1701
1710
|
}
|
|
1702
|
-
__name(
|
|
1711
|
+
__name(fileNeedsPolicy, "fileNeedsPolicy");
|
|
1703
1712
|
function fileNeedsSignature(root) {
|
|
1704
1713
|
return root.routes.some((route) => route.operations.some((op) => !!op.signature));
|
|
1705
1714
|
}
|