@formspec/runtime
v0.1.0-alpha.63
Published
Runtime helpers for FormSpec - resolvers and data fetching
Readme
@formspec/runtime
Runtime helpers for dynamic FormSpec data sources.
Install
pnpm add @formspec/runtimeOr use:
pnpm add formspecMain API
defineResolvers(form, resolvers) creates a typed resolver registry for the dynamic enum and dynamic schema sources used by a form.
import { field, formspec } from "@formspec/dsl";
import { defineResolvers } from "@formspec/runtime";
const Form = formspec(
field.dynamicEnum("country", "countries"),
field.dynamicEnum("state", "states")
);
const resolvers = defineResolvers(Form, {
countries: async () => ({
options: [
{ value: "us", label: "United States" },
{ value: "ca", label: "Canada" },
],
validity: "valid",
}),
states: async () => ({
options: [],
validity: "unknown",
}),
});
const countries = await resolvers.get("countries")();Main Exports
defineResolvers(form, resolvers)ResolverResolverMapResolverRegistryResolverSourcesForForm
License
This package is part of the FormSpec monorepo and is released under the MIT License. See LICENSE for details.
