Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(zui): export schemas of JSONSchema #535

Merged
merged 2 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions zui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bpinternal/zui",
"version": "0.13.5",
"version": "0.13.6",
"description": "A fork of Zod with additional features",
"type": "module",
"source": "./src/index.ts",
Expand Down Expand Up @@ -72,4 +72,4 @@
"pnpm": "8.6.2"
},
"packageManager": "pnpm@8.6.2"
}
}
4 changes: 4 additions & 0 deletions zui/src/ui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ export { ZuiForm, type ZuiFormProps } from './Form'
export * from './component-definitions'
export * from './ErrorBoundary'

export { isObjectSchema, isArraySchema } from './utils'

export type {
BaseType,
UIComponentDefinitions,
Expand All @@ -11,6 +13,8 @@ export type {
ZuiReactComponent,
ZuiReactComponentProps,
JSONSchema,
ObjectSchema,
ArraySchema,
JSONSchemaOfType,
MergeUIComponentDefinitions,
FormValidation,
Expand Down
10 changes: 9 additions & 1 deletion zui/src/ui/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { zuiKey } from './constants'
import { resolveDiscriminator } from './hooks/useDiscriminator'
import { BaseType, JSONSchema, Path, ZuiComponentMap, ZuiReactComponent } from './types'
import { ArraySchema, BaseType, JSONSchema, ObjectSchema, Path, ZuiComponentMap, ZuiReactComponent } from './types'

type ComponentMeta<Type extends BaseType = BaseType> = {
type: Type
Expand Down Expand Up @@ -545,3 +545,11 @@ const specialCase = [
'XSS',
'YouTube',
]

export function isObjectSchema(schema: JSONSchema): schema is ObjectSchema {
return schema.type === 'object' && typeof schema.properties === 'object' && schema.properties !== null
}

export function isArraySchema(schema: JSONSchema): schema is ArraySchema {
return schema.type === 'array' && typeof schema.items === 'object' && schema.items !== null
}
Loading