Skip to content

Commit 7be3d8b

Browse files
committed
basic implementation of zod schemas from our schemas
1 parent fa8476e commit 7be3d8b

File tree

11 files changed

+2595
-16
lines changed

11 files changed

+2595
-16
lines changed

package/src/common/create-schema-types.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ import {
1414
generateJsonSchemasFromSchemas,
1515
} from "../../../src/core/schema/json-schema-from-schema.ts";
1616

17+
import {
18+
generateZodTypesFromSchemas,
19+
} from "../../../src/core/schema/zod-types-from-schema.ts";
20+
1721
await generateTypesFromSchemas(Deno.args[0]);
1822
await generateSchemaTypes(Deno.args[0]);
19-
await generateJsonSchemasFromSchemas(Deno.args[0]);
23+
await generateJsonSchemasFromSchemas(Deno.args[0]);
24+
await generateZodTypesFromSchemas(Deno.args[0]);

src/core/schema/build-schema-file.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { kLangCommentChars } from "../lib/partition-cell-options.ts";
3737
import { generateTypesFromSchemas } from "./types-from-schema.ts";
3838
import { generateJsonSchemasFromSchemas } from "./json-schema-from-schema.ts";
3939
import { InternalError } from "../lib/error.ts";
40+
import { generateZodTypesFromSchemas } from "./zod-types-from-schema.ts";
4041

4142
////////////////////////////////////////////////////////////////////////////////
4243

@@ -90,6 +91,7 @@ export async function buildIntelligenceResources() {
9091
await Promise.all([
9192
generateTypesFromSchemas(path),
9293
generateJsonSchemasFromSchemas(path),
94+
generateZodTypesFromSchemas(path),
9395
]);
9496
}
9597

src/core/schema/types-from-schema.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ export function typeNameFromSchemaName(schemaName: string) {
2626
return capitalize(toCapitalizationCase(schemaName.replaceAll("/", "-")));
2727
}
2828

29-
function fmtSource(source: string) {
29+
export function fmtSource(source: string) {
3030
return new Deno.Command(Deno.execPath(), {
3131
args: ["fmt", source],
3232
}).output();
3333
}
3434

3535
export const generatedSrcMessage =
36-
`// This file is automatically generated by \`quarto build-js\`! Do not edit.",
36+
`// This file is automatically generated by \`quarto dev-call build-artifacts\`! Do not edit.",
3737
//
38-
// If you find yourself trying to rebuild types and \`quarto build-js\` won't run because
38+
// If you find yourself trying to rebuild types and \`quarto dev-call build-artifacts\` won't run because
3939
// of bad type definitions, run the following:
4040
// $ cd $QUARTO_ROOT
4141
// $ ./package/dist/bin/tools/deno run --importmap=./src/import_map.json --allow-all ./package/src/common/create-schema-types.ts ./src/resources
@@ -104,7 +104,7 @@ export async function generateTypesFromSchemas(resourcePath: string) {
104104
await fmtSource(join(resourcePath, "/types/schema-types.ts"));
105105
}
106106

107-
function yamlToTypeScriptKey(key: string) {
107+
export function yamlToTypeScriptKey(key: string) {
108108
// if the key isn't a valid typescript identifier, quote it
109109
if (!/^[a-zA-Z_$][0-9a-zA-Z_$]*$/.test(key)) {
110110
return JSON.stringify(key);

0 commit comments

Comments
 (0)