diff --git a/README.md b/README.md index a3653e3..2b335be 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ A commandline utility for converting CDDL to various formats. ## Usage 1. Clone this repo and `cd` into it. -2. `cargo run -- path/to/file.cddl` +2. `cargo run -- [--format ] path/to/file.cddl` ## Tips @@ -26,4 +26,4 @@ cargo run -- path/to/file.cddl | prettier --stdin-filepath=$outfile > $outfile ## Limitations -1. Only [`TypeScript`](https://www.typescriptlang.org/) and [`Zod v4`](https://zod.dev/) is supported at the moment. +1. Only [`TypeScript`](https://www.typescriptlang.org/) (`--format type-script`) and [`Zod v4`](https://zod.dev/) (`--format zod`) are supported at the moment. diff --git a/src/engines/zod.rs b/src/engines/zod.rs index d1c3d19..a9c2102 100644 --- a/src/engines/zod.rs +++ b/src/engines/zod.rs @@ -113,13 +113,13 @@ impl<'a, 'b: 'a, 'c, Stdout: Write, Stderr: Write> Engine { .all(|type2| matches!(type2, cddl::ast::Type2::TextValue { .. })) { if self.is_type_mode { - write!(self.stdout, "z.ZodEnum<["); + write!(self.stdout, "z.ZodEnum<{{"); for type2 in t.type_choices.iter().map(|choice| &choice.type1.type2) { if let cddl::ast::Type2::TextValue { value, .. } = type2 { - write!(self.stdout, "\"{}\",", value); + write!(self.stdout, "\"{}\":\"{}\",", value, value); } } - write!(self.stdout, "]>"); + write!(self.stdout, "}}>"); } else { write!(self.stdout, "z.enum(["); for type2 in t.type_choices.iter().map(|choice| &choice.type1.type2) { @@ -137,7 +137,7 @@ impl<'a, 'b: 'a, 'c, Stdout: Write, Stderr: Write> Engine { fn visit_array(&mut self, g: &'b cddl::ast::Group<'a>) -> cddl::visitor::Result { if g.group_choices.len() != 1 { if self.is_type_mode { - write!(self.stdout, "z.ZodUnion<["); + write!(self.stdout, "z.ZodUnion Engine { } if upper < MAX_ARRAYS { if self.is_type_mode { - write!(self.stdout, "z.ZodUnion<["); + write!(self.stdout, "z.ZodUnion Engine { } else if self.is_type_mode { write!(self.stdout, "z.ZodArray<"); self.visit_type(&entry.entry_type)?; - if lower == 1 { - write!(self.stdout, ", \"atleastone\""); - } write!(self.stdout, ">"); } else { write!(self.stdout, "z.array("); @@ -597,7 +594,7 @@ impl<'a, 'b: 'a, Stdout: Write, Stderr: Write> Visitor<'a, 'b, Error> for Engine } if t.type_choices.len() != 1 { if self.is_type_mode { - write!(self.stdout, "z.ZodUnion<["); + write!(self.stdout, "z.ZodUnion Visitor<'a, 'b, Error> for Engine self.print_group_joiner(); if matches!(calculate_occurrence(&ge.occur), (0, max) if max > 0) { if self.is_type_mode { - write!(self.stdout, "z.ZodUnion<["); + write!(self.stdout, "z.ZodUnion]>"); } else { @@ -704,7 +701,7 @@ impl<'a, 'b: 'a, Stdout: Write, Stderr: Write> Visitor<'a, 'b, Error> for Engine self.print_group_joiner(); if matches!(calculate_occurrence(&occur), (0, max) if max > 0) { if self.is_type_mode { - write!(self.stdout, "z.ZodUnion<["); + write!(self.stdout, "z.ZodUnion]>"); } else { @@ -755,7 +752,7 @@ impl<'a, 'b: 'a, Stdout: Write, Stderr: Write> Visitor<'a, 'b, Error> for Engine fn visit_group(&mut self, g: &'b cddl::ast::Group<'a>) -> cddl::visitor::Result { if g.group_choices.len() != 1 { if self.is_type_mode { - write!(self.stdout, "z.ZodUnion<["); + write!(self.stdout, "z.ZodUnion> = z.lazy(() => z.union([BrowserCommandSchema,BrowsingContextCommandSchema,InputCommandSchema,NetworkCommandSchema,ScriptCommandSchema,SessionCommandSchema])); +CommandDataSchema: z.ZodLazy> = z.lazy(() => z.union([BrowserCommandSchema,BrowsingContextCommandSchema,InputCommandSchema,NetworkCommandSchema,ScriptCommandSchema,SessionCommandSchema])); export const EmptyParamsSchema: z.ZodLazy = z.lazy(() => ExtensibleSchema); -export const MessageSchema: z.ZodLazy> = z.lazy(() => z.union([CommandResponseSchema,ErrorResponseSchema,EventSchema])); +export const MessageSchema: z.ZodLazy> = z.lazy(() => z.union([CommandResponseSchema,ErrorResponseSchema,EventSchema])); export const CommandResponseSchema: z.ZodLazy,"id":typeof JsUintSchema,"result":typeof ResultDataSchema}>,typeof ExtensibleSchema>> = z.lazy(() => z.object({ "type":z.literal("success"),"id":JsUintSchema,"result":ResultDataSchema}).and( ExtensibleSchema) ); export const ErrorResponseSchema: z.ZodLazy,"id":z.ZodUnion<[typeof JsUintSchema,z.ZodNull]>,"error":typeof ErrorCodeSchema,"message":z.ZodString,"stacktrace":z.ZodOptional}>,typeof ExtensibleSchema>> = z.lazy(() => z.object({ +"type":z.ZodLiteral<"error">,"id":z.ZodUnion,"error":typeof ErrorCodeSchema,"message":z.ZodString,"stacktrace":z.ZodOptional}>,typeof ExtensibleSchema>> = z.lazy(() => z.object({ "type":z.literal("error"),"id":z.union([JsUintSchema,z.null()]),"error":ErrorCodeSchema,"message":z.string(),"stacktrace":z.string().optional()}).and( ExtensibleSchema) ); -export const ResultDataSchema: z.ZodLazy> = z.lazy(() => z.union([BrowsingContextResultSchema,EmptyResultSchema,NetworkResultSchema,ScriptResultSchema,SessionResultSchema])); +export const ResultDataSchema: z.ZodLazy> = z.lazy(() => z.union([BrowsingContextResultSchema,EmptyResultSchema,NetworkResultSchema,ScriptResultSchema,SessionResultSchema])); export const EmptyResultSchema: z.ZodLazy = z.lazy(() => ExtensibleSchema); export const EventSchema: z.ZodLazy}>,typeof EventDataSchema>,typeof ExtensibleSchema>> = z.lazy(() => z.object({ @@ -33,17 +33,17 @@ EventDataSchema) ExtensibleSchema) ); export const -EventDataSchema: z.ZodLazy> = z.lazy(() => z.union([BrowsingContextEventSchema,LogEventSchema,NetworkEventSchema,ScriptEventSchema])); +EventDataSchema: z.ZodLazy> = z.lazy(() => z.union([BrowsingContextEventSchema,LogEventSchema,NetworkEventSchema,ScriptEventSchema])); export const ExtensibleSchema: z.ZodLazy> = z.lazy(() => z.record( z.string(),z.any())); export const JsIntSchema: z.ZodNumber = z.number().int().gte(-9007199254740991).lte(9007199254740991); export const JsUintSchema: z.ZodNumber = z.number().int().nonnegative().gte(0).lte(9007199254740991); -export const ErrorCodeSchema: z.ZodLazy> = z.lazy(() => z.enum(["invalid argument","invalid session id","move target out of bounds","no such alert","no such element","no such frame","no such handle","no such history entry","no such intercept","no such node","no such request","no such script","session not created","unable to capture screen","unable to close browser","unknown command","unknown error","unsupported operation",])); +export const ErrorCodeSchema: z.ZodLazy> = z.lazy(() => z.enum(["invalid argument","invalid session id","move target out of bounds","no such alert","no such element","no such frame","no such handle","no such history entry","no such intercept","no such node","no such request","no such script","session not created","unable to capture screen","unable to close browser","unknown command","unknown error","unsupported operation",])); export const -SessionCommandSchema: z.ZodLazy> = z.lazy(() => z.union([Session.EndSchema,Session.NewSchema,Session.StatusSchema,Session.SubscribeSchema,Session.UnsubscribeSchema])); -export const SessionResultSchema: z.ZodLazy> = z.lazy(() => z.union([Session.NewResultSchema,Session.StatusResultSchema])); +SessionCommandSchema: z.ZodLazy> = z.lazy(() => z.union([Session.EndSchema,Session.NewSchema,Session.StatusSchema,Session.SubscribeSchema,Session.UnsubscribeSchema])); +export const SessionResultSchema: z.ZodLazy> = z.lazy(() => z.union([Session.NewResultSchema,Session.StatusResultSchema])); export namespace Session { export const CapabilitiesRequestSchema: z.ZodLazy,"firstMatch":z.ZodOptional>}>> = z.lazy(() => z.object({ @@ -57,7 +57,7 @@ ExtensibleSchema) ); } export namespace Session { -export const ProxyConfigurationSchema: z.ZodLazy]>> = z.lazy(() => z.union([Session.AutodetectProxyConfigurationSchema,Session.DirectProxyConfigurationSchema,Session.ManualProxyConfigurationSchema,Session.PacProxyConfigurationSchema,Session.SystemProxyConfigurationSchema,z.object({ })])); } @@ -80,7 +80,7 @@ ExtensibleSchema) export namespace Session { export const ManualProxyConfigurationSchema: z.ZodLazy,"ftpProxy":z.ZodOptional,"httpProxy":z.ZodOptional,"sslProxy":z.ZodOptional}>,z.ZodUnion<[typeof Session.SocksProxyConfigurationSchema,z.ZodObject<{}>]>>,z.ZodObject<{ +"proxyType":z.ZodLiteral<"manual">,"ftpProxy":z.ZodOptional,"httpProxy":z.ZodOptional,"sslProxy":z.ZodOptional}>,z.ZodUnion]>>,z.ZodObject<{ "noProxy":z.ZodOptional>}>>,typeof ExtensibleSchema>> = z.lazy(() => z.object({ "proxyType":z.literal("manual"),"ftpProxy":z.string().optional(),"httpProxy":z.string().optional(),"sslProxy":z.string().optional()}).and( Session.SocksProxyConfigurationSchema.or(z.object({}))) @@ -176,10 +176,10 @@ CloseSchema: z.ZodLazy> = z.lazy(() => z.union([BrowsingContext.ActivateSchema,BrowsingContext.CaptureScreenshotSchema,BrowsingContext.CloseSchema,BrowsingContext.CreateSchema,BrowsingContext.GetTreeSchema,BrowsingContext.HandleUserPromptSchema,BrowsingContext.LocateNodesSchema,BrowsingContext.NavigateSchema,BrowsingContext.PrintSchema,BrowsingContext.ReloadSchema,BrowsingContext.SetViewportSchema,BrowsingContext.TraverseHistorySchema])); -export const BrowsingContextResultSchema: z.ZodLazy> = z.lazy(() => z.union([BrowsingContext.CaptureScreenshotResultSchema,BrowsingContext.CreateResultSchema,BrowsingContext.GetTreeResultSchema,BrowsingContext.LocateNodesResultSchema,BrowsingContext.NavigateResultSchema,BrowsingContext.PrintResultSchema,BrowsingContext.TraverseHistoryResultSchema])); +BrowsingContextCommandSchema: z.ZodLazy> = z.lazy(() => z.union([BrowsingContext.ActivateSchema,BrowsingContext.CaptureScreenshotSchema,BrowsingContext.CloseSchema,BrowsingContext.CreateSchema,BrowsingContext.GetTreeSchema,BrowsingContext.HandleUserPromptSchema,BrowsingContext.LocateNodesSchema,BrowsingContext.NavigateSchema,BrowsingContext.PrintSchema,BrowsingContext.ReloadSchema,BrowsingContext.SetViewportSchema,BrowsingContext.TraverseHistorySchema])); +export const BrowsingContextResultSchema: z.ZodLazy> = z.lazy(() => z.union([BrowsingContext.CaptureScreenshotResultSchema,BrowsingContext.CreateResultSchema,BrowsingContext.GetTreeResultSchema,BrowsingContext.LocateNodesResultSchema,BrowsingContext.NavigateResultSchema,BrowsingContext.PrintResultSchema,BrowsingContext.TraverseHistoryResultSchema])); export const -BrowsingContextEventSchema: z.ZodLazy> = z.lazy(() => z.union([BrowsingContext.ContextCreatedSchema,BrowsingContext.ContextDestroyedSchema,BrowsingContext.DomContentLoadedSchema,BrowsingContext.DownloadWillBeginSchema,BrowsingContext.FragmentNavigatedSchema,BrowsingContext.LoadSchema,BrowsingContext.NavigationAbortedSchema,BrowsingContext.NavigationFailedSchema,BrowsingContext.NavigationStartedSchema,BrowsingContext.UserPromptClosedSchema,BrowsingContext.UserPromptOpenedSchema])); +BrowsingContextEventSchema: z.ZodLazy> = z.lazy(() => z.union([BrowsingContext.ContextCreatedSchema,BrowsingContext.ContextDestroyedSchema,BrowsingContext.DomContentLoadedSchema,BrowsingContext.DownloadWillBeginSchema,BrowsingContext.FragmentNavigatedSchema,BrowsingContext.LoadSchema,BrowsingContext.NavigationAbortedSchema,BrowsingContext.NavigationFailedSchema,BrowsingContext.NavigationStartedSchema,BrowsingContext.UserPromptClosedSchema,BrowsingContext.UserPromptOpenedSchema])); export namespace BrowsingContext { export const BrowsingContextSchema: z.ZodLazy = z.lazy(() => z.string()); } @@ -188,11 +188,11 @@ export const InfoListSchema: z.ZodType = z.lazy(() => z.array(BrowsingContext.In } export namespace BrowsingContext { export const InfoSchema: z.ZodLazy,"parent":z.ZodOptional>}>> = z.lazy(() => z.object({ +"context":typeof BrowsingContext.BrowsingContextSchema,"url":z.ZodString,"children":z.ZodUnion,"parent":z.ZodOptional>}>> = z.lazy(() => z.object({ "context":BrowsingContext.BrowsingContextSchema,"url":z.string(),"children":z.union([BrowsingContext.InfoListSchema,z.null()]),"parent":z.union([BrowsingContext.BrowsingContextSchema,z.null()]).optional()})); } export namespace BrowsingContext { -export const LocatorSchema: z.ZodLazy> = z.lazy(() => z.union([BrowsingContext.CssLocatorSchema,BrowsingContext.InnerTextLocatorSchema,BrowsingContext.XPathLocatorSchema])); +export const LocatorSchema: z.ZodLazy> = z.lazy(() => z.union([BrowsingContext.CssLocatorSchema,BrowsingContext.InnerTextLocatorSchema,BrowsingContext.XPathLocatorSchema])); } export namespace BrowsingContext { export const CssLocatorSchema: z.ZodLazy,"value":z.ZodString,"ignoreCase":z.ZodOptional,"matchType":z.ZodOptional>,"maxDepth":z.ZodOptional}>> = z.lazy(() => z.object({ +"type":z.ZodLiteral<"innerText">,"value":z.ZodString,"ignoreCase":z.ZodOptional,"matchType":z.ZodOptional>,"maxDepth":z.ZodOptional}>> = z.lazy(() => z.object({ "type":z.literal("innerText"),"value":z.string(),"ignoreCase":z.boolean().optional(),"matchType":z.enum(["full","partial",]).optional(),"maxDepth":JsUintSchema.optional()})); } export namespace BrowsingContext { @@ -214,11 +214,11 @@ export const NavigationSchema: z.ZodLazy = z.lazy(() => z.string()) } export namespace BrowsingContext { export const NavigationInfoSchema: z.ZodLazy,"timestamp":typeof JsUintSchema,"url":z.ZodString}>> = z.lazy(() => z.object({ +"context":typeof BrowsingContext.BrowsingContextSchema,"navigation":z.ZodUnion,"timestamp":typeof JsUintSchema,"url":z.ZodString}>> = z.lazy(() => z.object({ "context":BrowsingContext.BrowsingContextSchema,"navigation":z.union([BrowsingContext.NavigationSchema,z.null()]),"timestamp":JsUintSchema,"url":z.string()})); } export namespace BrowsingContext { -export const ReadinessStateSchema: z.ZodLazy> = z.lazy(() => z.enum(["none","interactive","complete",])); +export const ReadinessStateSchema: z.ZodLazy> = z.lazy(() => z.enum(["none","interactive","complete",])); } export namespace BrowsingContext { export const @@ -239,7 +239,7 @@ CaptureScreenshotSchema: z.ZodLazy>>,"format":z.ZodOptional,"clip":z.ZodOptional}>> = z.lazy(() => z.object({ +"context":typeof BrowsingContext.BrowsingContextSchema,"origin":z.ZodOptional>>,"format":z.ZodOptional,"clip":z.ZodOptional}>> = z.lazy(() => z.object({ "context":BrowsingContext.BrowsingContextSchema,"origin":z.enum(["viewport","document",]).default("viewport").optional(),"format":BrowsingContext.ImageFormatSchema.optional(),"clip":BrowsingContext.ClipRectangleSchema.optional()})); } export namespace BrowsingContext { @@ -248,7 +248,7 @@ export const ImageFormatSchema: z.ZodLazy> = z.lazy(() => z.union([BrowsingContext.BoxClipRectangleSchema,BrowsingContext.ElementClipRectangleSchema])); +export const ClipRectangleSchema: z.ZodLazy> = z.lazy(() => z.union([BrowsingContext.BoxClipRectangleSchema,BrowsingContext.ElementClipRectangleSchema])); } export namespace BrowsingContext { export const ElementClipRectangleSchema: z.ZodLazy> = z.lazy(() => z.enum(["tab","window",])); +export const CreateTypeSchema: z.ZodLazy> = z.lazy(() => z.enum(["tab","window",])); } export namespace BrowsingContext { export const CreateParametersSchema: z.ZodLazy,"ownership":z.ZodOptional,"sandbox":z.ZodOptional,"serializationOptions":z.ZodOptional,"startNodes":z.ZodOptional>}>> = z.lazy(() => z.object({ +"context":typeof BrowsingContext.BrowsingContextSchema,"locator":typeof BrowsingContext.LocatorSchema,"maxNodeCount":z.ZodOptional,"ownership":z.ZodOptional,"sandbox":z.ZodOptional,"serializationOptions":z.ZodOptional,"startNodes":z.ZodOptional>}>> = z.lazy(() => z.object({ "context":BrowsingContext.BrowsingContextSchema,"locator":BrowsingContext.LocatorSchema,"maxNodeCount":JsUintSchema.gte(1).optional(),"ownership":Script.ResultOwnershipSchema.optional(),"sandbox":z.string().optional(),"serializationOptions":Script.SerializationOptionsSchema.optional(),"startNodes":z.array(Script.SharedReferenceSchema).nonempty().optional()})); } export namespace BrowsingContext { @@ -351,7 +351,7 @@ export const NavigateParametersSchema: z.ZodLazy,"url":z.ZodString}>> = z.lazy(() => z.object({ +"navigation":z.ZodUnion,"url":z.ZodString}>> = z.lazy(() => z.object({ "navigation":z.union([BrowsingContext.NavigationSchema,z.null()]),"url":z.string()})); } export namespace BrowsingContext { @@ -362,7 +362,7 @@ PrintSchema: z.ZodLazy>,"margin":z.ZodOptional,"orientation":z.ZodOptional>>,"page":z.ZodOptional,"pageRanges":z.ZodOptional>>,"scale":z.ZodOptional>,"shrinkToFit":z.ZodOptional>}>> = z.lazy(() => z.object({ +"context":typeof BrowsingContext.BrowsingContextSchema,"background":z.ZodOptional>,"margin":z.ZodOptional,"orientation":z.ZodOptional>>,"page":z.ZodOptional,"pageRanges":z.ZodOptional>>,"scale":z.ZodOptional>,"shrinkToFit":z.ZodOptional>}>> = z.lazy(() => z.object({ "context":BrowsingContext.BrowsingContextSchema,"background":z.boolean().default(false).optional(),"margin":BrowsingContext.PrintMarginParametersSchema.optional(),"orientation":z.enum(["portrait","landscape",]).default("portrait").optional(),"page":BrowsingContext.PrintPageParametersSchema.optional(),"pageRanges":z.array(z.union([JsUintSchema,z.string()])).optional(),"scale":z.number().gte(0.1).lte(2).default(1).optional(),"shrinkToFit":z.boolean().default(true).optional()})); } export namespace BrowsingContext { @@ -399,7 +399,7 @@ SetViewportSchema: z.ZodLazy>,"devicePixelRatio":z.ZodOptional>}>> = z.lazy(() => z.object({ +"context":typeof BrowsingContext.BrowsingContextSchema,"viewport":z.ZodOptional>,"devicePixelRatio":z.ZodOptional>}>> = z.lazy(() => z.object({ "context":BrowsingContext.BrowsingContextSchema,"viewport":z.union([BrowsingContext.ViewportSchema,z.null()]).optional(),"devicePixelRatio":z.union([z.number().gt(0),z.null()]).optional()})); } export namespace BrowsingContext { @@ -496,15 +496,15 @@ UserPromptOpenedSchema: z.ZodLazy,"message":z.ZodString,"defaultValue":z.ZodOptional}>> = z.lazy(() => z.object({ +"context":typeof BrowsingContext.BrowsingContextSchema,"type":z.ZodEnum<{"alert":"alert","confirm":"confirm","prompt":"prompt","beforeunload":"beforeunload",}>,"message":z.ZodString,"defaultValue":z.ZodOptional}>> = z.lazy(() => z.object({ "context":BrowsingContext.BrowsingContextSchema,"type":z.enum(["alert","confirm","prompt","beforeunload",]),"message":z.string(),"defaultValue":z.string().optional()})); } export const -NetworkCommandSchema: z.ZodLazy> = z.lazy(() => z.union([Network.AddInterceptSchema,Network.ContinueRequestSchema,Network.ContinueResponseSchema,Network.ContinueWithAuthSchema,Network.FailRequestSchema,Network.ProvideResponseSchema,Network.RemoveInterceptSchema])); +NetworkCommandSchema: z.ZodLazy> = z.lazy(() => z.union([Network.AddInterceptSchema,Network.ContinueRequestSchema,Network.ContinueResponseSchema,Network.ContinueWithAuthSchema,Network.FailRequestSchema,Network.ProvideResponseSchema,Network.RemoveInterceptSchema])); export const NetworkResultSchema: z.ZodLazy = z.lazy(() => Network.AddInterceptResultSchema); export const -NetworkEventSchema: z.ZodLazy> = z.lazy(() => z.union([Network.AuthRequiredSchema,Network.BeforeRequestSentSchema,Network.FetchErrorSchema,Network.ResponseCompletedSchema,Network.ResponseStartedSchema])); +NetworkEventSchema: z.ZodLazy> = z.lazy(() => z.union([Network.AuthRequiredSchema,Network.BeforeRequestSentSchema,Network.FetchErrorSchema,Network.ResponseCompletedSchema,Network.ResponseStartedSchema])); export namespace Network { export const AuthChallengeSchema: z.ZodLazy> = z.lazy(() => z.object({ @@ -518,11 +518,11 @@ export const AuthCredentialsSchema: z.ZodLazy,"isBlocked":z.ZodBoolean,"navigation":z.ZodUnion<[typeof BrowsingContext.NavigationSchema,z.ZodNull]>,"redirectCount":typeof JsUintSchema,"request":typeof Network.RequestDataSchema,"timestamp":typeof JsUintSchema,"intercepts":z.ZodOptional>}>> = z.lazy(() => z.object({ +"context":z.ZodUnion,"isBlocked":z.ZodBoolean,"navigation":z.ZodUnion,"redirectCount":typeof JsUintSchema,"request":typeof Network.RequestDataSchema,"timestamp":typeof JsUintSchema,"intercepts":z.ZodOptional>}>> = z.lazy(() => z.object({ "context":z.union([BrowsingContext.BrowsingContextSchema,z.null()]),"isBlocked":z.boolean(),"navigation":z.union([BrowsingContext.NavigationSchema,z.null()]),"redirectCount":JsUintSchema,"request":Network.RequestDataSchema,"timestamp":JsUintSchema,"intercepts":z.array(Network.InterceptSchema).nonempty().optional()})); } export namespace Network { -export const BytesValueSchema: z.ZodLazy> = z.lazy(() => z.union([Network.StringValueSchema,Network.Base64ValueSchema])); +export const BytesValueSchema: z.ZodLazy> = z.lazy(() => z.union([Network.StringValueSchema,Network.Base64ValueSchema])); } export namespace Network { export const StringValueSchema: z.ZodLazy,"expires":z.ZodOptional}>> = z.lazy(() => z.object({ +"name":z.ZodString,"value":typeof Network.BytesValueSchema,"domain":z.ZodString,"path":z.ZodString,"size":typeof JsUintSchema,"httpOnly":z.ZodBoolean,"secure":z.ZodBoolean,"sameSite":z.ZodEnum<{"strict":"strict","lax":"lax","none":"none",}>,"expires":z.ZodOptional}>> = z.lazy(() => z.object({ "name":z.string(),"value":Network.BytesValueSchema,"domain":z.string(),"path":z.string(),"size":JsUintSchema,"httpOnly":z.boolean(),"secure":z.boolean(),"sameSite":z.enum(["strict","lax","none",]),"expires":JsUintSchema.optional()})); } export namespace Network { @@ -556,7 +556,7 @@ export const HeaderSchema: z.ZodLazy,"columnNumber":z.ZodOptional,"lineNumber":z.ZodOptional,"stackTrace":z.ZodOptional,"request":z.ZodOptional}>> = z.lazy(() => z.object({ +"type":z.ZodEnum<{"parser":"parser","script":"script","preflight":"preflight","other":"other",}>,"columnNumber":z.ZodOptional,"lineNumber":z.ZodOptional,"stackTrace":z.ZodOptional,"request":z.ZodOptional}>> = z.lazy(() => z.object({ "type":z.enum(["parser","script","preflight","other",]),"columnNumber":JsUintSchema.optional(),"lineNumber":JsUintSchema.optional(),"stackTrace":Script.StackTraceSchema.optional(),"request":Network.RequestSchema.optional()})); } export namespace Network { @@ -567,7 +567,7 @@ export const RequestSchema: z.ZodLazy = z.lazy(() => z.string()); } export namespace Network { export const RequestDataSchema: z.ZodLazy,"cookies":z.ZodArray,"headersSize":typeof JsUintSchema,"bodySize":z.ZodUnion<[typeof JsUintSchema,z.ZodNull]>,"timings":typeof Network.FetchTimingInfoSchema}>> = z.lazy(() => z.object({ +"request":typeof Network.RequestSchema,"url":z.ZodString,"method":z.ZodString,"headers":z.ZodArray,"cookies":z.ZodArray,"headersSize":typeof JsUintSchema,"bodySize":z.ZodUnion,"timings":typeof Network.FetchTimingInfoSchema}>> = z.lazy(() => z.object({ "request":Network.RequestSchema,"url":z.string(),"method":z.string(),"headers":z.array(Network.HeaderSchema),"cookies":z.array(Network.CookieSchema),"headersSize":JsUintSchema,"bodySize":z.union([JsUintSchema,z.null()]),"timings":Network.FetchTimingInfoSchema})); } export namespace Network { @@ -577,16 +577,16 @@ export const ResponseContentSchema: z.ZodLazy,"mimeType":z.ZodString,"bytesReceived":typeof JsUintSchema,"headersSize":z.ZodUnion<[typeof JsUintSchema,z.ZodNull]>,"bodySize":z.ZodUnion<[typeof JsUintSchema,z.ZodNull]>,"content":typeof Network.ResponseContentSchema,"authChallenge":z.ZodOptional}>> = z.lazy(() => z.object({ +"url":z.ZodString,"protocol":z.ZodString,"status":typeof JsUintSchema,"statusText":z.ZodString,"fromCache":z.ZodBoolean,"headers":z.ZodArray,"mimeType":z.ZodString,"bytesReceived":typeof JsUintSchema,"headersSize":z.ZodUnion,"bodySize":z.ZodUnion,"content":typeof Network.ResponseContentSchema,"authChallenge":z.ZodOptional}>> = z.lazy(() => z.object({ "url":z.string(),"protocol":z.string(),"status":JsUintSchema,"statusText":z.string(),"fromCache":z.boolean(),"headers":z.array(Network.HeaderSchema),"mimeType":z.string(),"bytesReceived":JsUintSchema,"headersSize":z.union([JsUintSchema,z.null()]),"bodySize":z.union([JsUintSchema,z.null()]),"content":Network.ResponseContentSchema,"authChallenge":Network.AuthChallengeSchema.optional()})); } export namespace Network { export const SetCookieHeaderSchema: z.ZodLazy,"httpOnly":z.ZodOptional,"expires":z.ZodOptional,"maxAge":z.ZodOptional,"path":z.ZodOptional,"sameSite":z.ZodOptional>,"secure":z.ZodOptional}>> = z.lazy(() => z.object({ +"name":z.ZodString,"value":typeof Network.BytesValueSchema,"domain":z.ZodOptional,"httpOnly":z.ZodOptional,"expires":z.ZodOptional,"maxAge":z.ZodOptional,"path":z.ZodOptional,"sameSite":z.ZodOptional>,"secure":z.ZodOptional}>> = z.lazy(() => z.object({ "name":z.string(),"value":Network.BytesValueSchema,"domain":z.string().optional(),"httpOnly":z.boolean().optional(),"expires":z.string().optional(),"maxAge":JsIntSchema.optional(),"path":z.string().optional(),"sameSite":z.enum(["strict","lax","none",]).optional(),"secure":z.boolean().optional()})); } export namespace Network { -export const UrlPatternSchema: z.ZodLazy> = z.lazy(() => z.union([Network.UrlPatternPatternSchema,Network.UrlPatternStringSchema])); +export const UrlPatternSchema: z.ZodLazy> = z.lazy(() => z.union([Network.UrlPatternPatternSchema,Network.UrlPatternStringSchema])); } export namespace Network { export const UrlPatternPatternSchema: z.ZodLazy,"urlPatterns":z.ZodOptional>}>> = z.lazy(() => z.object({ +"phases":z.ZodArray,"urlPatterns":z.ZodOptional>}>> = z.lazy(() => z.object({ "phases":z.array(Network.InterceptPhaseSchema).nonempty(),"urlPatterns":z.array(Network.UrlPatternSchema).optional()})); } export namespace Network { -export const InterceptPhaseSchema: z.ZodLazy> = z.lazy(() => z.enum(["beforeRequestSent","responseStarted","authRequired",])); +export const InterceptPhaseSchema: z.ZodLazy> = z.lazy(() => z.enum(["beforeRequestSent","responseStarted","authRequired",])); } export namespace Network { export const AddInterceptResultSchema: z.ZodLazy,z.ZodUnion<[typeof Network.ContinueWithAuthCredentialsSchema,typeof Network.ContinueWithAuthNoCredentialsSchema]>>> = z.lazy(() => z.object({ +"request":typeof Network.RequestSchema}>,z.ZodUnion>> = z.lazy(() => z.object({ "request":Network.RequestSchema}).and( z.union([Network.ContinueWithAuthCredentialsSchema,Network.ContinueWithAuthNoCredentialsSchema])) ); @@ -661,7 +661,7 @@ ContinueWithAuthCredentialsSchema: z.ZodLazy}>> = z.lazy(() => z.object({ +"action":z.ZodEnum<{"default":"default","cancel":"cancel",}>}>> = z.lazy(() => z.object({ "action":z.enum(["default","cancel",])})); } export namespace Network { @@ -763,10 +763,10 @@ z.object({ ); } export const -ScriptCommandSchema: z.ZodLazy> = z.lazy(() => z.union([Script.AddPreloadScriptSchema,Script.CallFunctionSchema,Script.DisownSchema,Script.EvaluateSchema,Script.GetRealmsSchema,Script.RemovePreloadScriptSchema])); -export const ScriptResultSchema: z.ZodLazy> = z.lazy(() => z.union([Script.AddPreloadScriptResultSchema,Script.EvaluateResultSchema,Script.GetRealmsResultSchema])); +ScriptCommandSchema: z.ZodLazy> = z.lazy(() => z.union([Script.AddPreloadScriptSchema,Script.CallFunctionSchema,Script.DisownSchema,Script.EvaluateSchema,Script.GetRealmsSchema,Script.RemovePreloadScriptSchema])); +export const ScriptResultSchema: z.ZodLazy> = z.lazy(() => z.union([Script.AddPreloadScriptResultSchema,Script.EvaluateResultSchema,Script.GetRealmsResultSchema])); export const -ScriptEventSchema: z.ZodLazy> = z.lazy(() => z.union([Script.MessageSchema,Script.RealmCreatedSchema,Script.RealmDestroyedSchema])); +ScriptEventSchema: z.ZodLazy> = z.lazy(() => z.union([Script.MessageSchema,Script.RealmCreatedSchema,Script.RealmDestroyedSchema])); export namespace Script { export const ChannelSchema: z.ZodLazy = z.lazy(() => z.string()); } @@ -781,7 +781,7 @@ export const ChannelPropertiesSchema: z.ZodLazy> = z.lazy(() => z.union([Script.EvaluateResultSuccessSchema,Script.EvaluateResultExceptionSchema])); +export const EvaluateResultSchema: z.ZodLazy> = z.lazy(() => z.union([Script.EvaluateResultSuccessSchema,Script.EvaluateResultExceptionSchema])); } export namespace Script { export const EvaluateResultSuccessSchema: z.ZodLazy,typeof Script.LocalValueSchema], null>>> = z.lazy(() => z.array(z.tuple([ +z.ZodUnion,typeof Script.LocalValueSchema], null>>> = z.lazy(() => z.array(z.tuple([ z.union([Script.LocalValueSchema,z.string()]),Script.LocalValueSchema]))); } export namespace Script { @@ -857,7 +857,7 @@ export namespace Script { export const RealmSchema: z.ZodLazy = z.lazy(() => z.string()); } export namespace Script { -export const PrimitiveProtocolValueSchema: z.ZodLazy> = z.lazy(() => z.union([Script.UndefinedValueSchema,Script.NullValueSchema,Script.StringValueSchema,Script.NumberValueSchema,Script.BooleanValueSchema,Script.BigIntValueSchema])); +export const PrimitiveProtocolValueSchema: z.ZodLazy> = z.lazy(() => z.union([Script.UndefinedValueSchema,Script.NullValueSchema,Script.StringValueSchema,Script.NumberValueSchema,Script.BooleanValueSchema,Script.BigIntValueSchema])); } export namespace Script { export const UndefinedValueSchema: z.ZodLazy> = z.lazy(() => z.enum(["NaN","-0","Infinity","-Infinity",])); +export const SpecialNumberSchema: z.ZodLazy> = z.lazy(() => z.enum(["NaN","-0","Infinity","-Infinity",])); } export namespace Script { export const NumberValueSchema: z.ZodLazy,"value":z.ZodUnion<[z.ZodNumber,typeof Script.SpecialNumberSchema]>}>> = z.lazy(() => z.object({ +"type":z.ZodLiteral<"number">,"value":z.ZodUnion}>> = z.lazy(() => z.object({ "type":z.literal("number"),"value":z.union([z.number(),Script.SpecialNumberSchema])})); } export namespace Script { @@ -893,7 +893,7 @@ export const BigIntValueSchema: z.ZodLazy> = z.lazy(() => z.union([Script.WindowRealmInfoSchema,Script.DedicatedWorkerRealmInfoSchema,Script.SharedWorkerRealmInfoSchema,Script.ServiceWorkerRealmInfoSchema,Script.WorkerRealmInfoSchema,Script.PaintWorkletRealmInfoSchema,Script.AudioWorkletRealmInfoSchema,Script.WorkletRealmInfoSchema])); +export const RealmInfoSchema: z.ZodLazy> = z.lazy(() => z.union([Script.WindowRealmInfoSchema,Script.DedicatedWorkerRealmInfoSchema,Script.SharedWorkerRealmInfoSchema,Script.ServiceWorkerRealmInfoSchema,Script.WorkerRealmInfoSchema,Script.PaintWorkletRealmInfoSchema,Script.AudioWorkletRealmInfoSchema,Script.WorkletRealmInfoSchema])); } export namespace Script { export const @@ -958,10 +958,10 @@ z.object({ ); } export namespace Script { -export const RealmTypeSchema: z.ZodLazy> = z.lazy(() => z.enum(["window","dedicated-worker","shared-worker","service-worker","worker","paint-worklet","audio-worklet","worklet",])); +export const RealmTypeSchema: z.ZodLazy> = z.lazy(() => z.enum(["window","dedicated-worker","shared-worker","service-worker","worker","paint-worklet","audio-worklet","worklet",])); } export namespace Script { -export const RemoteReferenceSchema: z.ZodLazy> = z.lazy(() => z.union([Script.SharedReferenceSchema,Script.RemoteObjectReferenceSchema])); +export const RemoteReferenceSchema: z.ZodLazy> = z.lazy(() => z.union([Script.SharedReferenceSchema,Script.RemoteObjectReferenceSchema])); } export namespace Script { export const SharedReferenceSchema: z.ZodLazy,typeof Script.RemoteValueSchema], null>>> = z.lazy(() => z.array(z.tuple([ +z.ZodUnion,typeof Script.RemoteValueSchema], null>>> = z.lazy(() => z.array(z.tuple([ z.union([Script.RemoteValueSchema,z.string()]),Script.RemoteValueSchema]))); } export namespace Script { @@ -1090,7 +1090,7 @@ export const NodeRemoteValueSchema: z.ZodType = z.lazy(() => z.object({ export namespace Script { export const NodePropertiesSchema: z.ZodLazy>,"children":z.ZodOptional>,"localName":z.ZodOptional,"mode":z.ZodOptional>,"namespaceURI":z.ZodOptional,"nodeValue":z.ZodOptional,"shadowRoot":z.ZodOptional>}>> = z.lazy(() => z.object({ +z.ZodString,z.ZodString>>,"children":z.ZodOptional>,"localName":z.ZodOptional,"mode":z.ZodOptional>,"namespaceURI":z.ZodOptional,"nodeValue":z.ZodOptional,"shadowRoot":z.ZodOptional>}>> = z.lazy(() => z.object({ "nodeType":JsUintSchema,"childNodeCount":JsUintSchema,"attributes":z.record( z.string(),z.string()).optional(),"children":z.array(Script.NodeRemoteValueSchema).optional(),"localName":z.string().optional(),"mode":z.enum(["open","closed",]).optional(),"namespaceURI":z.string().optional(),"nodeValue":z.string().optional(),"shadowRoot":z.union([Script.NodeRemoteValueSchema,z.null()]).optional()})); } @@ -1105,11 +1105,11 @@ export const WindowProxyPropertiesSchema: z.ZodLazy> = z.lazy(() => z.enum(["root","none",])); +export const ResultOwnershipSchema: z.ZodLazy> = z.lazy(() => z.enum(["root","none",])); } export namespace Script { export const SerializationOptionsSchema: z.ZodLazy>>,"maxObjectDepth":z.ZodOptional>>,"includeShadowTree":z.ZodOptional>>}>> = z.lazy(() => z.object({ +"maxDomDepth":z.ZodOptional>>,"maxObjectDepth":z.ZodOptional>>,"includeShadowTree":z.ZodOptional>>}>> = z.lazy(() => z.object({ "maxDomDepth":z.union([JsUintSchema,z.null()]).default(0).optional(),"maxObjectDepth":z.union([JsUintSchema,z.null()]).default(null).optional(),"includeShadowTree":z.enum(["none","open","all",]).default("none").optional()})); } export namespace Script { @@ -1141,7 +1141,7 @@ export const ContextTargetSchema: z.ZodLazy> = z.lazy(() => z.union([Script.RealmTargetSchema,Script.ContextTargetSchema])); +export const TargetSchema: z.ZodLazy> = z.lazy(() => z.union([Script.RealmTargetSchema,Script.ContextTargetSchema])); } export namespace Script { export const @@ -1151,7 +1151,7 @@ AddPreloadScriptSchema: z.ZodLazy>,"contexts":z.ZodOptional>,"sandbox":z.ZodOptional}>> = z.lazy(() => z.object({ +"functionDeclaration":z.ZodString,"arguments":z.ZodOptional>,"contexts":z.ZodOptional>,"sandbox":z.ZodOptional}>> = z.lazy(() => z.object({ "functionDeclaration":z.string(),"arguments":z.array(Script.ChannelValueSchema).optional(),"contexts":z.array(BrowsingContext.BrowsingContextSchema).nonempty().optional(),"sandbox":z.string().optional()})); } export namespace Script { @@ -1250,15 +1250,15 @@ export const RealmDestroyedParametersSchema: z.ZodLazy = z.lazy(() => Log.EntryAddedSchema); export namespace Log { -export const LevelSchema: z.ZodLazy> = z.lazy(() => z.enum(["debug","info","warn","error",])); +export const LevelSchema: z.ZodLazy> = z.lazy(() => z.enum(["debug","info","warn","error",])); } export namespace Log { -export const EntrySchema: z.ZodLazy> = z.lazy(() => z.union([Log.GenericLogEntrySchema,Log.ConsoleLogEntrySchema,Log.JavascriptLogEntrySchema])); +export const EntrySchema: z.ZodLazy> = z.lazy(() => z.union([Log.GenericLogEntrySchema,Log.ConsoleLogEntrySchema,Log.JavascriptLogEntrySchema])); } export namespace Log { export const BaseLogEntrySchema: z.ZodLazy,"timestamp":typeof JsUintSchema,"stackTrace":z.ZodOptional}>> = z.lazy(() => z.object({ +"level":typeof Log.LevelSchema,"source":typeof Script.SourceSchema,"text":z.ZodUnion,"timestamp":typeof JsUintSchema,"stackTrace":z.ZodOptional}>> = z.lazy(() => z.object({ "level":Log.LevelSchema,"source":Script.SourceSchema,"text":z.union([z.string(),z.null()]),"timestamp":JsUintSchema,"stackTrace":Script.StackTraceSchema.optional()})); } export namespace Log { @@ -1289,7 +1289,7 @@ EntryAddedSchema: z.ZodLazy> = z.lazy(() => z.union([Input.PerformActionsSchema,Input.ReleaseActionsSchema])); +InputCommandSchema: z.ZodLazy> = z.lazy(() => z.union([Input.PerformActionsSchema,Input.ReleaseActionsSchema])); export namespace Input { export const ElementOriginSchema: z.ZodLazy,"element":typeof Script.SharedReferenceSchema}>> = z.lazy(() => z.object({ @@ -1307,7 +1307,7 @@ export const PerformActionsParametersSchema: z.ZodLazy> = z.lazy(() => z.union([Input.NoneSourceActionsSchema,Input.KeySourceActionsSchema,Input.PointerSourceActionsSchema,Input.WheelSourceActionsSchema])); +export const SourceActionsSchema: z.ZodLazy> = z.lazy(() => z.union([Input.NoneSourceActionsSchema,Input.KeySourceActionsSchema,Input.PointerSourceActionsSchema,Input.WheelSourceActionsSchema])); } export namespace Input { export const NoneSourceActionsSchema: z.ZodLazy> = z.lazy(() => z.union([Input.PauseActionSchema,Input.KeyDownActionSchema,Input.KeyUpActionSchema])); +export const KeySourceActionSchema: z.ZodLazy> = z.lazy(() => z.union([Input.PauseActionSchema,Input.KeyDownActionSchema,Input.KeyUpActionSchema])); } export namespace Input { export const PointerSourceActionsSchema: z.ZodLazy> = z.lazy(() => z.enum(["mouse","pen","touch",])); +export const PointerTypeSchema: z.ZodLazy> = z.lazy(() => z.enum(["mouse","pen","touch",])); } export namespace Input { export const PointerParametersSchema: z.ZodLazy> = z.lazy(() => z.union([Input.PauseActionSchema,Input.PointerDownActionSchema,Input.PointerUpActionSchema,Input.PointerMoveActionSchema])); +export const PointerSourceActionSchema: z.ZodLazy> = z.lazy(() => z.union([Input.PauseActionSchema,Input.PointerDownActionSchema,Input.PointerUpActionSchema,Input.PointerMoveActionSchema])); } export namespace Input { export const WheelSourceActionsSchema: z.ZodLazy> = z.lazy(() => z.union([Input.PauseActionSchema,Input.WheelScrollActionSchema])); +export const WheelSourceActionSchema: z.ZodLazy> = z.lazy(() => z.union([Input.PauseActionSchema,Input.WheelScrollActionSchema])); } export namespace Input { export const PauseActionSchema: z.ZodLazy,z.ZodLiteral<"pointer">,typeof Input.ElementOriginSchema]>> = z.lazy(() => z.union([z.literal("viewport"),z.literal("pointer"),Input.ElementOriginSchema])); +export const OriginSchema: z.ZodLazy,z.ZodLiteral<"pointer">,typeof Input.ElementOriginSchema]>> = z.lazy(() => z.union([z.literal("viewport"),z.literal("pointer"),Input.ElementOriginSchema])); } export namespace Input { export const diff --git a/tests/snapshots/zod__it_works_with_enums-2.snap b/tests/snapshots/zod__it_works_with_enums-2.snap index c06a570..431a6a0 100644 --- a/tests/snapshots/zod__it_works_with_enums-2.snap +++ b/tests/snapshots/zod__it_works_with_enums-2.snap @@ -2,9 +2,9 @@ source: tests/zod.rs expression: "String :: from_utf8(stdout.into_inner().unwrap()).unwrap()" --- -export const QEnumSchema: z.ZodLazy> = z.lazy(() => z.enum(["qValue","qValue2",])); +export const QEnumSchema: z.ZodLazy> = z.lazy(() => z.enum(["qValue","qValue2",])); export namespace Network { -export const SameSiteSchema: z.ZodLazy> = z.lazy(() => z.enum(["strict","lax","none",])); +export const SameSiteSchema: z.ZodLazy> = z.lazy(() => z.enum(["strict","lax","none",])); } export namespace Network { export const CookieSchema: z.ZodLazy,z.ZodUnion<[z.ZodObject<{ +"foo":z.ZodString}>,z.ZodUnion,z.ZodObject<{}>]>>> = z.lazy(() => z.object({ "foo":z.string()}).and( z.object({ "bar":z.string()}).or(z.object({}))) ); export const BSchema: z.ZodLazy,z.ZodUnion<[typeof BarSchema,z.ZodObject<{}>]>>> = z.lazy(() => z.object({ +"foo":z.ZodString}>,z.ZodUnion]>>> = z.lazy(() => z.object({ "foo":z.string()}).and( BarSchema.or(z.object({}))) ); diff --git a/tests/snapshots/zod__it_works_with_simple_optional_groups-2.snap b/tests/snapshots/zod__it_works_with_simple_optional_groups-2.snap index da15190..135ef5a 100644 --- a/tests/snapshots/zod__it_works_with_simple_optional_groups-2.snap +++ b/tests/snapshots/zod__it_works_with_simple_optional_groups-2.snap @@ -4,7 +4,7 @@ expression: "String :: from_utf8(stdout.into_inner().unwrap()).unwrap()" --- export namespace Bluetooth { export const HandleRequestDevicePromptParametersSchema: z.ZodLazy,z.ZodUnion<[typeof Bluetooth.HandleRequestDevicePromptAcceptParametersSchema,typeof Bluetooth.HandleRequestDevicePromptCancelParametersSchema]>>> = z.lazy(() => z.object({ +"context":z.ZodString,"prompt":z.ZodString}>,z.ZodUnion>> = z.lazy(() => z.object({ "context":z.string(),"prompt":z.string()}).and( z.union([Bluetooth.HandleRequestDevicePromptAcceptParametersSchema,Bluetooth.HandleRequestDevicePromptCancelParametersSchema])) );