Skip to content

Latest commit

 

History

History
117 lines (89 loc) · 1.95 KB

File metadata and controls

117 lines (89 loc) · 1.95 KB

Core API

The @object-ui/core package (also published as @object-ui/protocol) provides the foundational type definitions and schemas for Object UI.

Installation

npm install @object-ui/protocol

Type Definitions

Schema Types

import type {
  BaseSchema,
  PageSchema,
  FormSchema,
  ViewSchema,
  ComponentSchema
} from '@object-ui/protocol'

BaseSchema

All schemas extend from BaseSchema:

interface BaseSchema {
  type: string
  id?: string
  name?: string
  className?: string
  style?: React.CSSProperties
  visible?: boolean
  visibleOn?: string
}

Component Types

Page

interface PageSchema extends BaseSchema {
  type: 'page'
  title: string
  description?: string
  body: ComponentSchema | ComponentSchema[]
}

Form

interface FormSchema extends BaseSchema {
  type: 'form'
  title?: string
  body: FieldSchema[]
  actions?: ActionSchema[]
  onSubmit?: string
}

Input

interface InputSchema extends BaseSchema {
  type: 'input'
  name: string
  label: string
  placeholder?: string
  required?: boolean
  disabled?: boolean
  inputType?: 'text' | 'email' | 'password' | 'number'
}

Validation

Using Zod

import { PageSchema } from '@object-ui/protocol'
import { z } from 'zod'

const pageValidator = z.object({
  type: z.literal('page'),
  title: z.string(),
  body: z.any()
})

// Validate
const result = pageValidator.safeParse(mySchema)

Utilities

Type Guards

import { isPageSchema, isFormSchema } from '@object-ui/protocol'

if (isPageSchema(schema)) {
  // TypeScript knows schema is PageSchema
  console.log(schema.title)
}

API Reference

Full API documentation coming soon.

For now, see: