Skip to content

Commit 5dffa5f

Browse files
committed
improve export naming, add hello world test
1 parent 590d500 commit 5dffa5f

File tree

3 files changed

+119
-1
lines changed

3 files changed

+119
-1
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,19 @@ class ZodDeclarationFileBuilder {
6060
fileSource(): string {
6161
const zodDeclarations = this.declarations.join("\n");
6262
const zodInferredTypes = this.inferredTypes.join("\n");
63+
const zodObject = (() => {
64+
const lines = [
65+
"export const Zod = {",
66+
];
67+
Object.keys(this.schemas).forEach((name) => {
68+
const typeName = typeNameFromSchemaName(name);
69+
lines.push(
70+
` ${typeName}: Zod${typeName},`,
71+
);
72+
});
73+
lines.push("};");
74+
return lines.join("\n");
75+
})();
6376
return `import { z } from "zod";
6477
6578
import { ZodSidebarContents, ZodNavigationItem, ZodNavigationItemObject } from "./handwritten-schema-types.ts";
@@ -68,7 +81,10 @@ export { ZodSidebarContents, ZodNavigationItem, ZodNavigationItemObject } from "
6881
${generatedSrcMessage}
6982
7083
${zodDeclarations}
71-
${zodInferredTypes}`;
84+
${zodInferredTypes}
85+
86+
${zodObject}
87+
`;
7288
}
7389

7490
// deno-lint-ignore no-explicit-any

src/resources/types/zod/schema-types.ts

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1972,3 +1972,90 @@ export type BrandDefaultsBootstrap = z.infer<typeof ZodBrandDefaultsBootstrap>;
19721972
export type ProjectConfig = z.infer<typeof ZodProjectConfig>;
19731973

19741974
export type BookProject = z.infer<typeof ZodBookProject>;
1975+
1976+
export const Zod = {
1977+
Date: ZodDate,
1978+
MathMethods: ZodMathMethods,
1979+
PandocFormatRequestHeaders: ZodPandocFormatRequestHeaders,
1980+
PandocFormatOutputFile: ZodPandocFormatOutputFile,
1981+
PandocFormatFilters: ZodPandocFormatFilters,
1982+
PandocShortcodes: ZodPandocShortcodes,
1983+
PageColumn: ZodPageColumn,
1984+
ContentsAuto: ZodContentsAuto,
1985+
NavigationItem: ZodNavigationItem,
1986+
NavigationItemObject: ZodNavigationItemObject,
1987+
GiscusThemes: ZodGiscusThemes,
1988+
GiscusConfiguration: ZodGiscusConfiguration,
1989+
DocumentCommentsConfiguration: ZodDocumentCommentsConfiguration,
1990+
SocialMetadata: ZodSocialMetadata,
1991+
PageFooterRegion: ZodPageFooterRegion,
1992+
SidebarContents: ZodSidebarContents,
1993+
ProjectPreview: ZodProjectPreview,
1994+
ProjectServe: ZodProjectServe,
1995+
Publish: ZodPublish,
1996+
PublishRecord: ZodPublishRecord,
1997+
TwitterCardConfig: ZodTwitterCardConfig,
1998+
OpenGraphConfig: ZodOpenGraphConfig,
1999+
PageFooter: ZodPageFooter,
2000+
BaseWebsite: ZodBaseWebsite,
2001+
BookSchema: ZodBookSchema,
2002+
ChapterItem: ZodChapterItem,
2003+
ChapterList: ZodChapterList,
2004+
OtherLinks: ZodOtherLinks,
2005+
CrossrefLabelsSchema: ZodCrossrefLabelsSchema,
2006+
EpubContributor: ZodEpubContributor,
2007+
FormatLanguage: ZodFormatLanguage,
2008+
WebsiteAbout: ZodWebsiteAbout,
2009+
WebsiteListing: ZodWebsiteListing,
2010+
WebsiteListingContentsObject: ZodWebsiteListingContentsObject,
2011+
CslDate: ZodCslDate,
2012+
CslPerson: ZodCslPerson,
2013+
CslNumber: ZodCslNumber,
2014+
CslItemShared: ZodCslItemShared,
2015+
CslItem: ZodCslItem,
2016+
CitationItem: ZodCitationItem,
2017+
SmartInclude: ZodSmartInclude,
2018+
Semver: ZodSemver,
2019+
QuartoDate: ZodQuartoDate,
2020+
ProjectProfile: ZodProjectProfile,
2021+
BadParseSchema: ZodBadParseSchema,
2022+
QuartoDevSchema: ZodQuartoDevSchema,
2023+
NotebookViewSchema: ZodNotebookViewSchema,
2024+
CodeLinksSchema: ZodCodeLinksSchema,
2025+
ManuscriptSchema: ZodManuscriptSchema,
2026+
BrandMeta: ZodBrandMeta,
2027+
BrandStringLightDark: ZodBrandStringLightDark,
2028+
BrandLogoExplicitResource: ZodBrandLogoExplicitResource,
2029+
BrandLogoResource: ZodBrandLogoResource,
2030+
BrandLogo: ZodBrandLogo,
2031+
BrandNamedLogo: ZodBrandNamedLogo,
2032+
BrandColorValue: ZodBrandColorValue,
2033+
BrandColor: ZodBrandColor,
2034+
BrandMaybeNamedColor: ZodBrandMaybeNamedColor,
2035+
BrandNamedThemeColor: ZodBrandNamedThemeColor,
2036+
BrandTypography: ZodBrandTypography,
2037+
BrandTypographyOptionsBase: ZodBrandTypographyOptionsBase,
2038+
BrandTypographyOptionsHeadings: ZodBrandTypographyOptionsHeadings,
2039+
BrandTypographyOptionsMonospace: ZodBrandTypographyOptionsMonospace,
2040+
BrandTypographyOptionsMonospaceInline:
2041+
ZodBrandTypographyOptionsMonospaceInline,
2042+
LineHeightNumberString: ZodLineHeightNumberString,
2043+
BrandTypographyOptionsMonospaceBlock: ZodBrandTypographyOptionsMonospaceBlock,
2044+
BrandTypographyOptionsLink: ZodBrandTypographyOptionsLink,
2045+
BrandNamedFont: ZodBrandNamedFont,
2046+
BrandFont: ZodBrandFont,
2047+
BrandFontWeight: ZodBrandFontWeight,
2048+
BrandFontStyle: ZodBrandFontStyle,
2049+
BrandFontCommon: ZodBrandFontCommon,
2050+
BrandFontSystem: ZodBrandFontSystem,
2051+
BrandFontGoogle: ZodBrandFontGoogle,
2052+
BrandFontBunny: ZodBrandFontBunny,
2053+
BrandFontFile: ZodBrandFontFile,
2054+
BrandFontFamily: ZodBrandFontFamily,
2055+
Brand: ZodBrand,
2056+
BrandPathBoolLightDark: ZodBrandPathBoolLightDark,
2057+
BrandDefaults: ZodBrandDefaults,
2058+
BrandDefaultsBootstrap: ZodBrandDefaultsBootstrap,
2059+
ProjectConfig: ZodProjectConfig,
2060+
BookProject: ZodBookProject,
2061+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* simple.test.ts
3+
*
4+
* Copyright (C) 2025 Posit Software, PBC
5+
*
6+
*/
7+
8+
import { unitTest } from "../../../test.ts";
9+
import { assertThrows } from "testing/asserts";
10+
import { Zod } from "../../../../src/resources/types/zod/schema-types.ts";
11+
12+
unitTest("zod-schema-basic", async () => {
13+
assertThrows(() => Zod.MathMethods.parse("latex"));
14+
const result = Zod.MathMethods.parse("katex");
15+
});

0 commit comments

Comments
 (0)