typespec-http-zod 0.25.0 → 0.26.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/dist/src/api.d.ts +150 -116
- package/dist/src/api.js +353 -332
- package/dist/src/lib.d.ts +0 -19
- package/dist/src/lib.js +0 -2
- package/dist/src/registry.js +26 -3
- package/dist/src/runtime.d.ts +20 -34
- package/dist/src/types.d.ts +7 -0
- package/dist/src/types.js +13 -4
- package/dist/src/uri-template.d.ts +106 -0
- package/dist/src/uri-template.js +254 -0
- package/dist/src/zod.d.ts +1 -0
- package/dist/src/zod.js +37 -1
- package/package.json +18 -18
package/dist/src/zod.js
CHANGED
|
@@ -12,6 +12,25 @@ import { reportDiagnostic } from "./lib.js";
|
|
|
12
12
|
* failed the compile that would have written it.
|
|
13
13
|
*/
|
|
14
14
|
const UNREPRESENTABLE = "z.never()";
|
|
15
|
+
/**
|
|
16
|
+
* **Installed by the registry, which is the only place that knows what a declared type is CALLED.**
|
|
17
|
+
*
|
|
18
|
+
* A property emitted as a getter needs its Zod type written out - see the getter docblock in
|
|
19
|
+
* `modelToZod`. Naming the type is the registry's job (it resolves a named type to its declaration,
|
|
20
|
+
* versioned name included), and `types.ts` already imports this module, so the annotation is handed
|
|
21
|
+
* in rather than computed here.
|
|
22
|
+
*/
|
|
23
|
+
let annotateDeferred = () => undefined;
|
|
24
|
+
export function withDeferredAnnotator(annotator, run) {
|
|
25
|
+
const previous = annotateDeferred;
|
|
26
|
+
annotateDeferred = annotator;
|
|
27
|
+
try {
|
|
28
|
+
return run();
|
|
29
|
+
}
|
|
30
|
+
finally {
|
|
31
|
+
annotateDeferred = previous;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
15
34
|
/**
|
|
16
35
|
* TypeSpec type -> Zod source text.
|
|
17
36
|
*
|
|
@@ -762,9 +781,26 @@ function modelToZod(program, model) {
|
|
|
762
781
|
.map((property) => {
|
|
763
782
|
const key = propertyKey(program, property);
|
|
764
783
|
const { value, deferred } = captureBackEdges(() => withDeclarationSite(property, () => propertyToZod(program, property)));
|
|
784
|
+
/**
|
|
785
|
+
* **A getter without a return type infers `unknown`, and the collapse is SILENT.**
|
|
786
|
+
*
|
|
787
|
+
* The docblock above claims the getter keeps `z.infer` inferring the recursive type. It does
|
|
788
|
+
* for the declaration itself, and not for a schema that WRAPS it: measured on the conformance
|
|
789
|
+
* corpus, `z.record(z.string(), innerModelSchema)` - what `@body body: Record<InnerModel>`
|
|
790
|
+
* emits - infers `children?: unknown`, and `.parse()` on it returns `unknown` outright. The
|
|
791
|
+
* generated server then failed to compile with `TS2322`, in `type/dictionary`, which is how
|
|
792
|
+
* this was found; nothing said the emitted TYPE was weaker than the document.
|
|
793
|
+
*
|
|
794
|
+
* Annotating the GETTER rather than the declaration is what keeps `.shape` and `.extend`,
|
|
795
|
+
* which inheritance and every group spread depend on. `: z.ZodType<T, T>` names both of Zod's
|
|
796
|
+
* parameters for the reason `renderSchemas` names both: one leaves the input side `unknown`.
|
|
797
|
+
*/
|
|
798
|
+
const annotation = deferred ? (annotateDeferred(property) ?? "") : "";
|
|
765
799
|
return {
|
|
766
800
|
deferred,
|
|
767
|
-
text: deferred
|
|
801
|
+
text: deferred
|
|
802
|
+
? `\tget ${key}()${annotation} {\n\t\treturn ${value};\n\t},`
|
|
803
|
+
: `\t${key}: ${value},`,
|
|
768
804
|
};
|
|
769
805
|
});
|
|
770
806
|
const entries = members.map((member) => member.text);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typespec-http-zod",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0",
|
|
4
4
|
"description": "TypeSpec emitter and library: turn an HTTP service definition into Zod validators and framework-free contract types that agree, keyword for keyword, with the OpenAPI document @typespec/openapi3 publishes from the same source.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"codegen",
|
|
@@ -43,33 +43,33 @@
|
|
|
43
43
|
"provenance": true
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@types/node": "^26.
|
|
47
|
-
"@typespec/compiler": "1.
|
|
48
|
-
"@typespec/events": "0.
|
|
49
|
-
"@typespec/http": "1.
|
|
46
|
+
"@types/node": "^26.5.1",
|
|
47
|
+
"@typespec/compiler": "1.16.0",
|
|
48
|
+
"@typespec/events": "0.86.0",
|
|
49
|
+
"@typespec/http": "1.16.0",
|
|
50
50
|
"@typespec/http-specs": "0.1.0-alpha.41",
|
|
51
|
-
"@typespec/openapi": "1.
|
|
52
|
-
"@typespec/openapi3": "1.
|
|
53
|
-
"@typespec/rest": "0.
|
|
54
|
-
"@typespec/sse": "0.
|
|
55
|
-
"@typespec/streams": "0.
|
|
56
|
-
"@typespec/versioning": "0.
|
|
57
|
-
"@typespec/xml": "0.
|
|
51
|
+
"@typespec/openapi": "1.16.0",
|
|
52
|
+
"@typespec/openapi3": "1.16.0",
|
|
53
|
+
"@typespec/rest": "0.86.0",
|
|
54
|
+
"@typespec/sse": "0.86.0",
|
|
55
|
+
"@typespec/streams": "0.86.0",
|
|
56
|
+
"@typespec/versioning": "0.86.0",
|
|
57
|
+
"@typespec/xml": "0.86.0",
|
|
58
58
|
"ajv": "^8.20.0",
|
|
59
|
-
"oxfmt": "^0.
|
|
60
|
-
"oxlint": "^1.
|
|
59
|
+
"oxfmt": "^0.67.0",
|
|
60
|
+
"oxlint": "^1.82.0",
|
|
61
61
|
"typescript": "~7.0.2",
|
|
62
62
|
"typespec-http-zod": "link:.",
|
|
63
|
-
"vitest": "^
|
|
64
|
-
"yaml": "^2.9.
|
|
63
|
+
"vitest": "^5.0.0",
|
|
64
|
+
"yaml": "^2.9.1",
|
|
65
65
|
"zod": "^4.5.2"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
68
68
|
"@typespec/compiler": "^1.15.0",
|
|
69
69
|
"@typespec/http": "^1.15.0",
|
|
70
70
|
"@typespec/openapi": "^1.15.0",
|
|
71
|
-
"@typespec/streams": "^0.85.0",
|
|
72
|
-
"@typespec/versioning": "^0.85.0",
|
|
71
|
+
"@typespec/streams": "^0.85.0 || ^0.86.0",
|
|
72
|
+
"@typespec/versioning": "^0.85.0 || ^0.86.0",
|
|
73
73
|
"zod": "^4.5.0"
|
|
74
74
|
},
|
|
75
75
|
"peerDependenciesMeta": {
|