From ad5a992741c28e007a9071743c24ab2471667604 Mon Sep 17 00:00:00 2001 From: allardy Date: Fri, 24 Jan 2025 12:14:04 -0500 Subject: [PATCH 1/2] fix(zui): export schemas of JSONSchema --- zui/package.json | 4 ++-- zui/src/ui/index.ts | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/zui/package.json b/zui/package.json index fae5e143..487cb223 100644 --- a/zui/package.json +++ b/zui/package.json @@ -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", @@ -72,4 +72,4 @@ "pnpm": "8.6.2" }, "packageManager": "pnpm@8.6.2" -} +} \ No newline at end of file diff --git a/zui/src/ui/index.ts b/zui/src/ui/index.ts index 005b8ea8..12d9fb15 100644 --- a/zui/src/ui/index.ts +++ b/zui/src/ui/index.ts @@ -11,6 +11,8 @@ export type { ZuiReactComponent, ZuiReactComponentProps, JSONSchema, + ObjectSchema, + ArraySchema, JSONSchemaOfType, MergeUIComponentDefinitions, FormValidation, From edb2109999cf2bd396fdc770c936156369c0a0dc Mon Sep 17 00:00:00 2001 From: allardy Date: Fri, 24 Jan 2025 12:18:47 -0500 Subject: [PATCH 2/2] guards --- zui/src/ui/index.ts | 2 ++ zui/src/ui/utils.ts | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/zui/src/ui/index.ts b/zui/src/ui/index.ts index 12d9fb15..53f1c099 100644 --- a/zui/src/ui/index.ts +++ b/zui/src/ui/index.ts @@ -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, diff --git a/zui/src/ui/utils.ts b/zui/src/ui/utils.ts index d7d9065d..b2d87c62 100644 --- a/zui/src/ui/utils.ts +++ b/zui/src/ui/utils.ts @@ -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: Type @@ -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 +}