@stripe/formspec
v0.1.0-alpha.72
Published
Type-safe form specifications that compile to JSON Schema and JSON Forms UI Schema
Maintainers
Readme
formspec
Umbrella package for the common FormSpec authoring and runtime APIs.
It re-exports the most commonly used pieces from:
@stripe/formspec-core@stripe/formspec-dsl@stripe/formspec-build@stripe/formspec-runtime
It does not include the CLI, ESLint plugin, or language server.
Install
pnpm add @stripe/formspecQuick start
import {
buildFormSchemas,
defineResolvers,
field,
formspec,
group,
is,
type InferFormSchema,
when,
} from "@stripe/formspec";
const OrderForm = formspec(
group(
"Order",
field.text("customerName", { required: true }),
field.enum("status", ["draft", "submitted"] as const, { required: true })
),
when(is("status", "submitted"), field.text("submittedBy"))
);
type OrderData = InferFormSchema<typeof OrderForm>;
const { jsonSchema, uiSchema } = buildFormSchemas(OrderForm);
const resolvers = defineResolvers(OrderForm, {});What you get
DSL
formspecfieldgroupwhenisformspecWithValidationvalidateForm
Build
buildFormSchemasgenerateJsonSchemagenerateUiSchemawriteSchemas
Runtime
defineResolvers
Types
InferSchemaInferFormSchema- core field, layout, and state types
- resolver and validation helper types
Utilities
createInitialFieldStatevalidateFormlogValidationIssues
When to use individual packages
- Use
@stripe/formspec-builddirectly forgenerateSchemas(),generateSchemasFromClass(),generateSchemasFromProgram(),buildMixedAuthoringSchemas(), and static TypeScript analysis. - Use
@stripe/formspec-eslint-pluginfor lint rules. - Use
@stripe/formspec-clifor build-time artifact generation from files. - Use
@stripe/formspec-validatorfor runtime JSON Schema validation.
License
This package is part of the FormSpec monorepo and is released under the MIT License. See LICENSE for details.
