@formspec/build 0.1.0-alpha.10 → 0.1.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.cjs +549 -0
- package/dist/browser.cjs.map +1 -0
- package/dist/browser.d.ts +4 -2
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +498 -45
- package/dist/browser.js.map +1 -1
- package/dist/build.d.ts +343 -33
- package/dist/cli.cjs +2267 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.js +2204 -101
- package/dist/cli.js.map +1 -1
- package/dist/generators/class-schema.d.ts +5 -9
- package/dist/generators/class-schema.d.ts.map +1 -1
- package/dist/index.cjs +2093 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2024 -114
- package/dist/index.js.map +1 -1
- package/dist/internals.cjs +1345 -0
- package/dist/internals.cjs.map +1 -0
- package/dist/internals.d.ts +1 -0
- package/dist/internals.d.ts.map +1 -1
- package/dist/internals.js +1297 -21
- package/dist/internals.js.map +1 -1
- package/dist/json-schema/generator.d.ts.map +1 -1
- package/dist/json-schema/schema.d.ts +16 -0
- package/dist/json-schema/schema.d.ts.map +1 -0
- package/dist/ui-schema/generator.d.ts +15 -0
- package/dist/ui-schema/generator.d.ts.map +1 -1
- package/dist/ui-schema/schema.d.ts +357 -0
- package/dist/ui-schema/schema.d.ts.map +1 -0
- package/dist/ui-schema/types.d.ts +8 -73
- package/dist/ui-schema/types.d.ts.map +1 -1
- package/package.json +14 -9
- package/dist/__tests__/analyzer-edge-cases.test.js +0 -376
- package/dist/__tests__/analyzer-edge-cases.test.js.map +0 -1
- package/dist/__tests__/analyzer.test.js +0 -190
- package/dist/__tests__/analyzer.test.js.map +0 -1
- package/dist/__tests__/cli.test.js +0 -178
- package/dist/__tests__/cli.test.js.map +0 -1
- package/dist/__tests__/codegen.test.js +0 -506
- package/dist/__tests__/codegen.test.js.map +0 -1
- package/dist/__tests__/decorator-pipeline.test.js +0 -460
- package/dist/__tests__/decorator-pipeline.test.js.map +0 -1
- package/dist/__tests__/edge-cases.test.js +0 -215
- package/dist/__tests__/edge-cases.test.js.map +0 -1
- package/dist/__tests__/fixtures/edge-cases.js +0 -137
- package/dist/__tests__/fixtures/edge-cases.js.map +0 -1
- package/dist/__tests__/fixtures/example-a-builtins.js +0 -100
- package/dist/__tests__/fixtures/example-a-builtins.js.map +0 -1
- package/dist/__tests__/fixtures/example-b-decorators.js +0 -5
- package/dist/__tests__/fixtures/example-b-decorators.js.map +0 -1
- package/dist/__tests__/fixtures/example-b-extended.js +0 -60
- package/dist/__tests__/fixtures/example-b-extended.js.map +0 -1
- package/dist/__tests__/fixtures/example-c-custom.js +0 -61
- package/dist/__tests__/fixtures/example-c-custom.js.map +0 -1
- package/dist/__tests__/fixtures/example-c-decorators.js +0 -4
- package/dist/__tests__/fixtures/example-c-decorators.js.map +0 -1
- package/dist/__tests__/fixtures/example-d-mixed-decorators.js +0 -75
- package/dist/__tests__/fixtures/example-d-mixed-decorators.js.map +0 -1
- package/dist/__tests__/fixtures/example-e-decorators.js +0 -10
- package/dist/__tests__/fixtures/example-e-decorators.js.map +0 -1
- package/dist/__tests__/fixtures/example-e-no-namespace.js +0 -61
- package/dist/__tests__/fixtures/example-e-no-namespace.js.map +0 -1
- package/dist/__tests__/fixtures/example-interface-types.js +0 -8
- package/dist/__tests__/fixtures/example-interface-types.js.map +0 -1
- package/dist/__tests__/fixtures/example-jsdoc-constraints.js +0 -98
- package/dist/__tests__/fixtures/example-jsdoc-constraints.js.map +0 -1
- package/dist/__tests__/fixtures/example-nested-class.js +0 -248
- package/dist/__tests__/fixtures/example-nested-class.js.map +0 -1
- package/dist/__tests__/fixtures/sample-forms.js +0 -78
- package/dist/__tests__/fixtures/sample-forms.js.map +0 -1
- package/dist/__tests__/generator.test.js +0 -234
- package/dist/__tests__/generator.test.js.map +0 -1
- package/dist/__tests__/integration.test.js +0 -161
- package/dist/__tests__/integration.test.js.map +0 -1
- package/dist/__tests__/interface-types.test.js +0 -404
- package/dist/__tests__/interface-types.test.js.map +0 -1
- package/dist/__tests__/jsdoc-constraints.test.js +0 -465
- package/dist/__tests__/jsdoc-constraints.test.js.map +0 -1
- package/dist/__tests__/write-schemas.test.js +0 -198
- package/dist/__tests__/write-schemas.test.js.map +0 -1
- package/dist/analyzer/class-analyzer.js +0 -377
- package/dist/analyzer/class-analyzer.js.map +0 -1
- package/dist/analyzer/decorator-extractor.js +0 -336
- package/dist/analyzer/decorator-extractor.js.map +0 -1
- package/dist/analyzer/jsdoc-constraints.js +0 -153
- package/dist/analyzer/jsdoc-constraints.js.map +0 -1
- package/dist/analyzer/program.js +0 -114
- package/dist/analyzer/program.js.map +0 -1
- package/dist/analyzer/type-converter.js +0 -474
- package/dist/analyzer/type-converter.js.map +0 -1
- package/dist/codegen/index.js +0 -597
- package/dist/codegen/index.js.map +0 -1
- package/dist/generators/class-schema.js +0 -140
- package/dist/generators/class-schema.js.map +0 -1
- package/dist/generators/method-schema.js +0 -108
- package/dist/generators/method-schema.js.map +0 -1
- package/dist/json-schema/generator.js +0 -166
- package/dist/json-schema/generator.js.map +0 -1
- package/dist/json-schema/types.js +0 -33
- package/dist/json-schema/types.js.map +0 -1
- package/dist/ui-schema/generator.js +0 -148
- package/dist/ui-schema/generator.js.map +0 -1
- package/dist/ui-schema/types.js +0 -8
- package/dist/ui-schema/types.js.map +0 -1
package/dist/browser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAU5D,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAiBhF,kCAAkC;AAClC,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAY5D;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,gBAAgB,CAAmC,IAAiB;IAClF,OAAO;QACL,UAAU,EAAE,kBAAkB,CAAC,IAAI,CAAC;QACpC,QAAQ,EAAE,gBAAgB,CAAC,IAAI,CAAC;KACjC,CAAC;AACJ,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../src/json-schema/schema.ts","../src/json-schema/generator.ts","../src/ui-schema/schema.ts","../src/ui-schema/generator.ts","../src/json-schema/types.ts","../src/browser.ts"],"sourcesContent":["/**\n * Zod schemas for JSON Schema draft-07 output validation.\n *\n * These schemas cover the subset of JSON Schema draft-07 that FormSpec generates,\n * plus the FormSpec-specific `x-formspec-*` extension properties.\n *\n * @see https://json-schema.org/draft-07/schema\n */\n\nimport { z } from \"zod\";\nimport type { JSONSchema7 } from \"./types.js\";\n\n// =============================================================================\n// JSON Schema type enum\n// =============================================================================\n\n/**\n * Zod schema for JSON Schema primitive type strings.\n */\nexport const jsonSchemaTypeSchema = z.enum([\n \"string\",\n \"number\",\n \"integer\",\n \"boolean\",\n \"object\",\n \"array\",\n \"null\",\n]);\n\n// =============================================================================\n// JSON Schema draft-07 schema (recursive)\n// =============================================================================\n\n// We annotate with z.ZodType<JSONSchema7> for the recursive self-reference.\n// The @ts-expect-error is required because exactOptionalPropertyTypes:true causes\n// Zod's inferred output type for optional fields (`T | undefined`) to be\n// incompatible with the JSONSchema7 interface's exact optional fields (`T?`).\n// The runtime behavior is correct: z.optional() will strip `undefined` values\n// during parsing and correctly handle absent keys.\n//\n// @ts-expect-error -- exactOptionalPropertyTypes: Zod optional infers `T | undefined`\n// but JSONSchema7 uses exact optional `?:` which disallows explicit undefined.\nexport const jsonSchema7Schema: z.ZodType<JSONSchema7> = z.lazy(() =>\n z\n .object({\n $schema: z.string().optional(),\n $id: z.string().optional(),\n $ref: z.string().optional(),\n\n // Metadata\n title: z.string().optional(),\n description: z.string().optional(),\n deprecated: z.boolean().optional(),\n\n // Type\n type: z.union([jsonSchemaTypeSchema, z.array(jsonSchemaTypeSchema)]).optional(),\n\n // String validation\n minLength: z.number().optional(),\n maxLength: z.number().optional(),\n pattern: z.string().optional(),\n\n // Number validation\n minimum: z.number().optional(),\n maximum: z.number().optional(),\n exclusiveMinimum: z.number().optional(),\n exclusiveMaximum: z.number().optional(),\n\n // Enum\n enum: z\n .array(z.union([z.string(), z.number(), z.boolean(), z.null()]))\n .readonly()\n .optional(),\n const: z.union([z.string(), z.number(), z.boolean(), z.null()]).optional(),\n\n // Object\n properties: z.record(z.string(), jsonSchema7Schema).optional(),\n required: z.array(z.string()).optional(),\n additionalProperties: z.union([z.boolean(), jsonSchema7Schema]).optional(),\n\n // Array\n items: z.union([jsonSchema7Schema, z.array(jsonSchema7Schema)]).optional(),\n minItems: z.number().optional(),\n maxItems: z.number().optional(),\n\n // Composition\n allOf: z.array(jsonSchema7Schema).optional(),\n anyOf: z.array(jsonSchema7Schema).optional(),\n oneOf: z.array(jsonSchema7Schema).optional(),\n not: jsonSchema7Schema.optional(),\n\n // Conditional\n if: jsonSchema7Schema.optional(),\n then: jsonSchema7Schema.optional(),\n else: jsonSchema7Schema.optional(),\n\n // Format\n format: z.string().optional(),\n\n // Default\n default: z.unknown().optional(),\n\n // FormSpec extensions\n \"x-formspec-source\": z.string().optional(),\n \"x-formspec-params\": z.array(z.string()).readonly().optional(),\n \"x-formspec-schemaSource\": z.string().optional(),\n })\n // passthrough preserves arbitrary x-formspec-* extension properties\n // added by custom decorators without causing validation failures\n .passthrough()\n);\n","/**\n * JSON Schema generator for FormSpec forms.\n */\n\nimport type {\n FormElement,\n FormSpec,\n AnyField,\n Group,\n Conditional,\n ArrayField,\n ObjectField,\n} from \"@formspec/core\";\nimport type { JSONSchema7 } from \"./types.js\";\nimport { jsonSchema7Schema } from \"./schema.js\";\nimport { z } from \"zod\";\n\n/**\n * Parses a value through a Zod schema, converting validation errors to a descriptive Error.\n */\nfunction parseOrThrow<T>(schema: z.ZodType<T>, value: unknown, label: string): T {\n try {\n return schema.parse(value);\n } catch (error) {\n if (error instanceof z.ZodError) {\n throw new Error(\n `Generated ${label} failed validation:\\n${error.issues.map((i) => ` ${i.path.join(\".\")}: ${i.message}`).join(\"\\n\")}`\n );\n }\n throw error;\n }\n}\n\n/**\n * Generates JSON Schema for nested elements (used for array items and object properties).\n */\nfunction generateNestedSchema(elements: readonly FormElement[]): JSONSchema7 {\n const properties: Record<string, JSONSchema7> = {};\n const required: string[] = [];\n\n collectFields(elements, properties, required);\n\n // Deduplicate required array (can have duplicates when the same field is defined\n // in multiple branches/containers, e.g., repeated in different conditional branches)\n const uniqueRequired = [...new Set(required)];\n\n return {\n type: \"object\",\n properties,\n ...(uniqueRequired.length > 0 && { required: uniqueRequired }),\n };\n}\n\n/**\n * Converts a single field to its JSON Schema representation.\n */\nfunction fieldToJsonSchema(field: AnyField): JSONSchema7 {\n const base: JSONSchema7 = {};\n\n if (field.label !== undefined) {\n base.title = field.label;\n }\n\n switch (field._field) {\n case \"text\":\n return { ...base, type: \"string\" };\n\n case \"number\":\n return {\n ...base,\n type: \"number\",\n ...(field.min !== undefined && { minimum: field.min }),\n ...(field.max !== undefined && { maximum: field.max }),\n };\n\n case \"boolean\":\n return { ...base, type: \"boolean\" };\n\n case \"enum\": {\n const opts = field.options;\n const isObjectOptions =\n opts.length > 0 &&\n opts.every(\n (opt): opt is { id: string; label: string } =>\n typeof opt === \"object\" && \"id\" in opt && \"label\" in opt\n );\n if (isObjectOptions) {\n // Object options with id/label: use oneOf with const/title\n return {\n ...base,\n type: \"string\",\n oneOf: opts.map((o) => ({\n const: o.id,\n title: o.label,\n })),\n };\n }\n return { ...base, type: \"string\", enum: opts as readonly string[] };\n }\n\n case \"dynamic_enum\":\n // Dynamic enums are strings at the schema level\n // The actual options are resolved at runtime\n // x-formspec-source indicates the data source key\n // x-formspec-params indicates dependent field names for fetching options\n return {\n ...base,\n type: \"string\",\n \"x-formspec-source\": field.source,\n ...(field.params !== undefined &&\n field.params.length > 0 && { \"x-formspec-params\": field.params }),\n };\n\n case \"dynamic_schema\":\n // Dynamic schemas are objects with unknown properties\n // x-formspec-schemaSource indicates where to load the schema from\n return {\n ...base,\n type: \"object\",\n additionalProperties: true,\n \"x-formspec-schemaSource\": field.schemaSource,\n };\n\n case \"array\": {\n const arrayField = field as ArrayField<string, readonly FormElement[]>;\n return {\n ...base,\n type: \"array\",\n items: generateNestedSchema(arrayField.items),\n ...(arrayField.minItems !== undefined && { minItems: arrayField.minItems }),\n ...(arrayField.maxItems !== undefined && { maxItems: arrayField.maxItems }),\n };\n }\n\n case \"object\": {\n const objectField = field as ObjectField<string, readonly FormElement[]>;\n const nestedSchema = generateNestedSchema(objectField.properties);\n return {\n ...base,\n ...nestedSchema,\n };\n }\n\n default: {\n // Exhaustiveness check\n const _exhaustive: never = field;\n return _exhaustive;\n }\n }\n}\n\n/**\n * Visits all elements in a form tree, collecting fields and required fields.\n */\nfunction collectFields(\n elements: readonly FormElement[],\n properties: Record<string, JSONSchema7>,\n required: string[]\n): void {\n for (const element of elements) {\n switch (element._type) {\n case \"field\":\n properties[element.name] = fieldToJsonSchema(element);\n if (element.required === true) {\n required.push(element.name);\n }\n break;\n\n case \"group\":\n // Groups don't affect schema structure, just collect their children\n collectFields((element as Group<readonly FormElement[]>).elements, properties, required);\n break;\n\n case \"conditional\":\n // Conditional fields are still part of the schema\n // They're just hidden/shown in the UI\n collectFields(\n (element as Conditional<string, unknown, readonly FormElement[]>).elements,\n properties,\n required\n );\n break;\n }\n }\n}\n\n/**\n * Generates a JSON Schema from a FormSpec.\n *\n * @example\n * ```typescript\n * const form = formspec(\n * field.text(\"name\", { label: \"Name\", required: true }),\n * field.number(\"age\", { min: 0 }),\n * );\n *\n * const schema = generateJsonSchema(form);\n * // {\n * // $schema: \"https://json-schema.org/draft-07/schema#\",\n * // type: \"object\",\n * // properties: {\n * // name: { type: \"string\", title: \"Name\" },\n * // age: { type: \"number\", minimum: 0 }\n * // },\n * // required: [\"name\"]\n * // }\n * ```\n *\n * @param form - The FormSpec to convert\n * @returns A JSON Schema object\n */\nexport function generateJsonSchema<E extends readonly FormElement[]>(\n form: FormSpec<E>\n): JSONSchema7 {\n const properties: Record<string, JSONSchema7> = {};\n const required: string[] = [];\n\n collectFields(form.elements, properties, required);\n\n // Deduplicate required array (can have duplicates when the same field is defined\n // in multiple branches/containers, e.g., repeated in different conditional branches)\n const uniqueRequired = [...new Set(required)];\n\n const result: JSONSchema7 = {\n $schema: \"https://json-schema.org/draft-07/schema#\",\n type: \"object\",\n properties,\n ...(uniqueRequired.length > 0 && { required: uniqueRequired }),\n };\n\n return parseOrThrow(jsonSchema7Schema, result, \"JSON Schema\");\n}\n","/**\n * Zod schemas for JSON Forms UI Schema.\n *\n * These schemas are the source of truth for UI Schema validation.\n * TypeScript types are derived from these schemas via `z.infer<>`.\n *\n * @see https://jsonforms.io/docs/uischema/\n */\n\nimport { z } from \"zod\";\n\n// =============================================================================\n// Primitive helpers\n// =============================================================================\n\n/** JSON Pointer string (e.g., \"#/properties/fieldName\") */\nconst jsonPointerSchema = z.string();\n\n// =============================================================================\n// Rule Effect and Element Type enums\n// =============================================================================\n\n/**\n * Zod schema for rule effect values.\n */\nexport const ruleEffectSchema = z.enum([\"SHOW\", \"HIDE\", \"ENABLE\", \"DISABLE\"]);\n\n/**\n * Rule effect types for conditional visibility.\n */\nexport type RuleEffect = z.infer<typeof ruleEffectSchema>;\n\n/**\n * Zod schema for UI Schema element type strings.\n */\nexport const uiSchemaElementTypeSchema = z.enum([\n \"Control\",\n \"VerticalLayout\",\n \"HorizontalLayout\",\n \"Group\",\n \"Categorization\",\n \"Category\",\n \"Label\",\n]);\n\n/**\n * UI Schema element types.\n */\nexport type UISchemaElementType = z.infer<typeof uiSchemaElementTypeSchema>;\n\n// =============================================================================\n// Rule Condition Schema (recursive)\n// =============================================================================\n\n// Forward-declare the recursive TypeScript type.\n// We use an interface here (rather than z.infer<>) because the recursive\n// z.lazy() type annotation requires us to pre-declare the shape.\n/**\n * JSON Schema subset used in rule conditions.\n */\nexport interface RuleConditionSchema {\n const?: unknown;\n enum?: readonly unknown[];\n type?: string;\n not?: RuleConditionSchema;\n minimum?: number;\n maximum?: number;\n exclusiveMinimum?: number;\n exclusiveMaximum?: number;\n minLength?: number;\n properties?: Record<string, RuleConditionSchema>;\n required?: string[];\n allOf?: RuleConditionSchema[];\n}\n\n// Build the Zod schema referencing the pre-declared interface.\n// We use z.ZodType<RuleConditionSchema> so the recursive reference works.\n// The interface uses `?` (exact optional), and z.ZodType checks output only,\n// so the optional fields (which Zod infers as `T | undefined`) are compatible\n// because `T | undefined` is assignable to the optional field slot.\n//\n// @ts-expect-error -- exactOptionalPropertyTypes: the Zod output type for optional\n// fields is `T | undefined`, but our interface uses `?` (exact optional, key may\n// be absent). This is a known mismatch when using z.ZodType<T> with\n// exactOptionalPropertyTypes:true; the runtime behavior is correct.\nexport const ruleConditionSchema: z.ZodType<RuleConditionSchema> = z.lazy(() =>\n z\n .object({\n const: z.unknown().optional(),\n enum: z.array(z.unknown()).readonly().optional(),\n type: z.string().optional(),\n not: ruleConditionSchema.optional(),\n minimum: z.number().optional(),\n maximum: z.number().optional(),\n exclusiveMinimum: z.number().optional(),\n exclusiveMaximum: z.number().optional(),\n minLength: z.number().optional(),\n properties: z.record(z.string(), ruleConditionSchema).optional(),\n required: z.array(z.string()).optional(),\n allOf: z.array(ruleConditionSchema).optional(),\n })\n .strict()\n);\n\n// =============================================================================\n// Schema-Based Condition and Rule\n// =============================================================================\n\n/**\n * Zod schema for a schema-based rule condition.\n */\nexport const schemaBasedConditionSchema = z\n .object({\n scope: jsonPointerSchema,\n schema: ruleConditionSchema,\n })\n .strict();\n\n/**\n * Condition for a rule.\n */\nexport type SchemaBasedCondition = z.infer<typeof schemaBasedConditionSchema>;\n\n/**\n * Zod schema for a UI Schema rule.\n */\nexport const ruleSchema = z\n .object({\n effect: ruleEffectSchema,\n condition: schemaBasedConditionSchema,\n })\n .strict();\n\n/**\n * Rule for conditional element visibility/enablement.\n */\nexport type Rule = z.infer<typeof ruleSchema>;\n\n// =============================================================================\n// UI Schema Element Schemas (recursive via z.lazy)\n// =============================================================================\n\n// Forward-declare UISchemaElement so layout schemas can reference it.\n// We declare the type up-front and wire the Zod schema below.\n/**\n * Union of all UI Schema element types.\n */\nexport type UISchemaElement =\n | ControlElement\n | VerticalLayout\n | HorizontalLayout\n | GroupLayout\n | Categorization\n | Category\n | LabelElement;\n\n// The Zod schema for UISchemaElement is defined as a const using z.lazy(),\n// which defers evaluation until first use. This allows all element schemas\n// below to be referenced even though they are declared after this line.\nexport const uiSchemaElementSchema: z.ZodType<UISchemaElement> = z.lazy(() =>\n z.union([\n controlSchema,\n verticalLayoutSchema,\n horizontalLayoutSchema,\n groupLayoutSchema,\n categorizationSchema,\n categorySchema,\n labelElementSchema,\n ])\n) as z.ZodType<UISchemaElement>;\n\n// -----------------------------------------------------------------------------\n// Control\n// -----------------------------------------------------------------------------\n\n/**\n * Zod schema for a Control element.\n */\nexport const controlSchema = z\n .object({\n type: z.literal(\"Control\"),\n scope: jsonPointerSchema,\n label: z.union([z.string(), z.literal(false)]).optional(),\n rule: ruleSchema.optional(),\n options: z.record(z.string(), z.unknown()).optional(),\n })\n .passthrough();\n\n/**\n * A Control element that binds to a JSON Schema property.\n */\nexport type ControlElement = z.infer<typeof controlSchema>;\n\n// -----------------------------------------------------------------------------\n// VerticalLayout\n// -----------------------------------------------------------------------------\n\n// Pre-declare the interface so the Zod schema can reference UISchemaElement.\n/**\n * A vertical layout element.\n */\nexport interface VerticalLayout {\n type: \"VerticalLayout\";\n elements: UISchemaElement[];\n rule?: Rule | undefined;\n options?: Record<string, unknown> | undefined;\n [k: string]: unknown;\n}\n\nexport const verticalLayoutSchema: z.ZodType<VerticalLayout> = z.lazy(() =>\n z\n .object({\n type: z.literal(\"VerticalLayout\"),\n elements: z.array(uiSchemaElementSchema),\n rule: ruleSchema.optional(),\n options: z.record(z.string(), z.unknown()).optional(),\n })\n .passthrough()\n);\n\n// -----------------------------------------------------------------------------\n// HorizontalLayout\n// -----------------------------------------------------------------------------\n\n/**\n * A horizontal layout element.\n */\nexport interface HorizontalLayout {\n type: \"HorizontalLayout\";\n elements: UISchemaElement[];\n rule?: Rule | undefined;\n options?: Record<string, unknown> | undefined;\n [k: string]: unknown;\n}\n\nexport const horizontalLayoutSchema: z.ZodType<HorizontalLayout> = z.lazy(() =>\n z\n .object({\n type: z.literal(\"HorizontalLayout\"),\n elements: z.array(uiSchemaElementSchema),\n rule: ruleSchema.optional(),\n options: z.record(z.string(), z.unknown()).optional(),\n })\n .passthrough()\n);\n\n// -----------------------------------------------------------------------------\n// GroupLayout\n// -----------------------------------------------------------------------------\n\n/**\n * A group element with a label.\n */\nexport interface GroupLayout {\n type: \"Group\";\n label: string;\n elements: UISchemaElement[];\n rule?: Rule | undefined;\n options?: Record<string, unknown> | undefined;\n [k: string]: unknown;\n}\n\nexport const groupLayoutSchema: z.ZodType<GroupLayout> = z.lazy(() =>\n z\n .object({\n type: z.literal(\"Group\"),\n label: z.string(),\n elements: z.array(uiSchemaElementSchema),\n rule: ruleSchema.optional(),\n options: z.record(z.string(), z.unknown()).optional(),\n })\n .passthrough()\n);\n\n// -----------------------------------------------------------------------------\n// Category\n// -----------------------------------------------------------------------------\n\n/**\n * A Category element, used inside a Categorization layout.\n */\nexport interface Category {\n type: \"Category\";\n label: string;\n elements: UISchemaElement[];\n rule?: Rule | undefined;\n options?: Record<string, unknown> | undefined;\n [k: string]: unknown;\n}\n\nexport const categorySchema: z.ZodType<Category> = z.lazy(() =>\n z\n .object({\n type: z.literal(\"Category\"),\n label: z.string(),\n elements: z.array(uiSchemaElementSchema),\n rule: ruleSchema.optional(),\n options: z.record(z.string(), z.unknown()).optional(),\n })\n .passthrough()\n);\n\n// -----------------------------------------------------------------------------\n// Categorization\n// -----------------------------------------------------------------------------\n\n/**\n * A Categorization element (tab-based layout).\n */\nexport interface Categorization {\n type: \"Categorization\";\n elements: Category[];\n label?: string | undefined;\n rule?: Rule | undefined;\n options?: Record<string, unknown> | undefined;\n [k: string]: unknown;\n}\n\nexport const categorizationSchema: z.ZodType<Categorization> = z.lazy(() =>\n z\n .object({\n type: z.literal(\"Categorization\"),\n elements: z.array(categorySchema),\n label: z.string().optional(),\n rule: ruleSchema.optional(),\n options: z.record(z.string(), z.unknown()).optional(),\n })\n .passthrough()\n);\n\n// -----------------------------------------------------------------------------\n// LabelElement\n// -----------------------------------------------------------------------------\n\n/**\n * Zod schema for a Label element.\n */\nexport const labelElementSchema = z\n .object({\n type: z.literal(\"Label\"),\n text: z.string(),\n rule: ruleSchema.optional(),\n options: z.record(z.string(), z.unknown()).optional(),\n })\n .passthrough();\n\n/**\n * A Label element for displaying static text.\n */\nexport type LabelElement = z.infer<typeof labelElementSchema>;\n\n// =============================================================================\n// Root UISchema\n// =============================================================================\n\n/**\n * Root UI Schema (always a layout — not a Control, Category, or Label).\n */\nexport type UISchema = VerticalLayout | HorizontalLayout | GroupLayout | Categorization;\n\n/**\n * Zod schema for the root UI Schema (layout types only).\n */\nexport const uiSchema: z.ZodType<UISchema> = z.lazy(() =>\n z.union([verticalLayoutSchema, horizontalLayoutSchema, groupLayoutSchema, categorizationSchema])\n) as z.ZodType<UISchema>;\n","/**\n * JSON Forms UI Schema generator for FormSpec forms.\n */\n\nimport type { FormElement, FormSpec, Group, Conditional } from \"@formspec/core\";\nimport type { UISchemaElement, UISchema, ControlElement, GroupLayout, Rule } from \"./types.js\";\nimport { uiSchema as uiSchemaValidator } from \"./schema.js\";\nimport type { FormSpecField } from \"../analyzer/type-converter.js\";\nimport { z } from \"zod\";\n\n/**\n * Parses a value through a Zod schema, converting validation errors to a descriptive Error.\n */\nfunction parseOrThrow<T>(schema: z.ZodType<T>, value: unknown, label: string): T {\n try {\n return schema.parse(value);\n } catch (error) {\n if (error instanceof z.ZodError) {\n throw new Error(\n `Generated ${label} failed validation:\\n${error.issues.map((i) => ` ${i.path.join(\".\")}: ${i.message}`).join(\"\\n\")}`\n );\n }\n throw error;\n }\n}\n\n/**\n * Converts a field name to a JSON Pointer scope.\n */\nfunction fieldToScope(fieldName: string): string {\n return `#/properties/${fieldName}`;\n}\n\n/**\n * Creates a rule for conditional visibility.\n */\nfunction createShowRule(fieldName: string, value: unknown): Rule {\n return {\n effect: \"SHOW\",\n condition: {\n scope: fieldToScope(fieldName),\n schema: { const: value },\n },\n };\n}\n\n/**\n * Combines two rules into one using allOf.\n *\n * When elements are nested inside multiple conditionals, all conditions\n * must be met for the element to be visible.\n */\nfunction combineRules(parentRule: Rule, childRule: Rule): Rule {\n // Both rules should have the same effect (SHOW)\n // Combine conditions using allOf\n const parentCondition = parentRule.condition;\n const childCondition = childRule.condition;\n\n return {\n effect: \"SHOW\",\n condition: {\n scope: \"#\",\n schema: {\n allOf: [\n {\n properties: {\n [parentCondition.scope.replace(\"#/properties/\", \"\")]: parentCondition.schema,\n },\n },\n {\n properties: {\n [childCondition.scope.replace(\"#/properties/\", \"\")]: childCondition.schema,\n },\n },\n ],\n },\n },\n };\n}\n\n/**\n * Converts form elements to UI Schema elements.\n *\n * @param elements - The form elements to convert\n * @param parentRule - Optional rule inherited from parent conditional\n * @returns Array of UI Schema elements\n */\nfunction elementsToUiSchema(\n elements: readonly FormElement[],\n parentRule?: Rule\n): UISchemaElement[] {\n const result: UISchemaElement[] = [];\n\n for (const element of elements) {\n switch (element._type) {\n case \"field\": {\n const control: ControlElement = {\n type: \"Control\",\n scope: fieldToScope(element.name),\n ...(element.label !== undefined && { label: element.label }),\n ...(parentRule !== undefined && { rule: parentRule }),\n };\n result.push(control);\n break;\n }\n\n case \"group\": {\n const groupElement = element as Group<readonly FormElement[]>;\n const group: GroupLayout = {\n type: \"Group\",\n label: groupElement.label,\n elements: elementsToUiSchema(groupElement.elements, parentRule),\n ...(parentRule !== undefined && { rule: parentRule }),\n };\n result.push(group);\n break;\n }\n\n case \"conditional\": {\n const conditionalElement = element as Conditional<string, unknown, readonly FormElement[]>;\n // Create a rule for this conditional\n const newRule = createShowRule(conditionalElement.field, conditionalElement.value);\n // Combine with parent rule if present (for nested conditionals)\n const combinedRule = parentRule !== undefined ? combineRules(parentRule, newRule) : newRule;\n // Apply the combined rule to all children\n const childElements = elementsToUiSchema(conditionalElement.elements, combinedRule);\n result.push(...childElements);\n break;\n }\n }\n }\n\n return result;\n}\n\n/**\n * Converts a single FormSpecField to a ControlElement, resolving showWhen into a rule.\n *\n * @param field - The FormSpecField to convert\n * @param scopePrefix - The JSON Pointer prefix for the field's scope\n * @returns A ControlElement\n */\nfunction formSpecFieldToElement(\n field: FormSpecField,\n scopePrefix = \"#/properties\"\n): ControlElement {\n const control: ControlElement = {\n type: \"Control\",\n scope: `${scopePrefix}/${field.id}`,\n };\n\n if (field.label !== undefined) {\n control.label = field.label;\n }\n\n if (\n field.showWhen !== undefined &&\n typeof field.showWhen === \"object\" &&\n \"field\" in field.showWhen &&\n \"value\" in field.showWhen\n ) {\n const sw = field.showWhen as { field: string; value: unknown };\n control.rule = {\n effect: \"SHOW\",\n condition: {\n scope: `#/properties/${sw.field}`,\n schema: { const: sw.value },\n },\n };\n }\n\n return control;\n}\n\n/**\n * Converts FormSpecField[] (from decorator/interface/type analysis) to a JSON Forms UISchema.\n *\n * Mapping:\n * - Each field → `{ type: \"Control\", scope: \"#/properties/{id}\", label? }`\n * - `showWhen: { field, value }` → rule with SHOW effect\n * - `group` property → Groups fields by group name, preserving insertion order\n * - `fields` (nested object) → single Control pointing to the object property\n * - Root wrapper → `{ type: \"VerticalLayout\", elements }`\n *\n * @param fields - The FormSpecField array to convert\n * @returns A JSON Forms UISchema\n */\nexport function generateUiSchemaFromFields(fields: FormSpecField[]): UISchema {\n // Collect elements, grouping by the `group` property.\n // Map preserves insertion order — first occurrence of a group name determines its position.\n const groupMap = new Map<string, ControlElement[]>();\n const orderedKeys: (string | null)[] = []; // null = ungrouped slot\n const ungrouped: ControlElement[] = [];\n\n for (const field of fields) {\n const element = formSpecFieldToElement(field);\n\n if (field.group !== undefined) {\n if (!groupMap.has(field.group)) {\n groupMap.set(field.group, []);\n orderedKeys.push(field.group);\n }\n // We know the key exists since we just set it above.\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n groupMap.get(field.group)!.push(element);\n } else {\n // Track position for ungrouped fields relative to grouped fields.\n // Use a sentinel to mark the slot for ungrouped elements inline.\n orderedKeys.push(null);\n ungrouped.push(element);\n }\n }\n\n // Build the flat elements list respecting insertion order.\n const elements: UISchemaElement[] = [];\n let ungroupedIndex = 0;\n\n for (const key of orderedKeys) {\n if (key === null) {\n // Ungrouped field — emit directly.\n const el = ungrouped[ungroupedIndex++];\n if (el !== undefined) {\n elements.push(el);\n }\n } else {\n // Each group key appears in orderedKeys exactly once (guarded by\n // `!groupMap.has()` above), so we emit the Group element directly.\n const groupElements = groupMap.get(key) ?? [];\n const groupLayout: GroupLayout = {\n type: \"Group\",\n label: key,\n elements: groupElements,\n };\n elements.push(groupLayout);\n }\n }\n\n const result: UISchema = {\n type: \"VerticalLayout\",\n elements,\n };\n\n return parseOrThrow(uiSchemaValidator, result, \"UI Schema\");\n}\n\n/**\n * Generates a JSON Forms UI Schema from a FormSpec.\n *\n * @example\n * ```typescript\n * const form = formspec(\n * group(\"Customer\",\n * field.text(\"name\", { label: \"Name\" }),\n * ),\n * when(\"status\", \"draft\",\n * field.text(\"notes\", { label: \"Notes\" }),\n * ),\n * );\n *\n * const uiSchema = generateUiSchema(form);\n * // {\n * // type: \"VerticalLayout\",\n * // elements: [\n * // {\n * // type: \"Group\",\n * // label: \"Customer\",\n * // elements: [\n * // { type: \"Control\", scope: \"#/properties/name\", label: \"Name\" }\n * // ]\n * // },\n * // {\n * // type: \"Control\",\n * // scope: \"#/properties/notes\",\n * // label: \"Notes\",\n * // rule: {\n * // effect: \"SHOW\",\n * // condition: { scope: \"#/properties/status\", schema: { const: \"draft\" } }\n * // }\n * // }\n * // ]\n * // }\n * ```\n *\n * @param form - The FormSpec to convert\n * @returns A JSON Forms UI Schema\n */\nexport function generateUiSchema<E extends readonly FormElement[]>(form: FormSpec<E>): UISchema {\n const result: UISchema = {\n type: \"VerticalLayout\",\n elements: elementsToUiSchema(form.elements),\n };\n\n return parseOrThrow(uiSchemaValidator, result, \"UI Schema\");\n}\n","/**\n * JSON Schema Draft-07 type definitions.\n *\n * These types are a subset of JSON Schema sufficient for form generation.\n */\n\n/**\n * JSON Schema primitive types.\n */\nexport type JSONSchemaType =\n | \"string\"\n | \"number\"\n | \"integer\"\n | \"boolean\"\n | \"object\"\n | \"array\"\n | \"null\";\n\n/**\n * A JSON Schema definition (draft-07 subset).\n */\nexport interface JSONSchema7 {\n $schema?: string;\n $id?: string;\n $ref?: string;\n\n // Metadata\n title?: string;\n description?: string;\n deprecated?: boolean;\n\n // Type\n type?: JSONSchemaType | JSONSchemaType[];\n\n // String validation\n minLength?: number;\n maxLength?: number;\n pattern?: string;\n\n // Number validation\n minimum?: number;\n maximum?: number;\n exclusiveMinimum?: number;\n exclusiveMaximum?: number;\n\n // Enum\n enum?: readonly (string | number | boolean | null)[];\n const?: string | number | boolean | null;\n\n // Object\n properties?: Record<string, JSONSchema7>;\n required?: string[];\n additionalProperties?: boolean | JSONSchema7;\n\n // Array\n items?: JSONSchema7 | JSONSchema7[];\n minItems?: number;\n maxItems?: number;\n\n // Composition\n allOf?: JSONSchema7[];\n anyOf?: JSONSchema7[];\n oneOf?: JSONSchema7[];\n not?: JSONSchema7;\n\n // Conditional\n if?: JSONSchema7;\n then?: JSONSchema7;\n else?: JSONSchema7;\n\n // Format\n format?: string;\n\n // Default\n default?: unknown;\n\n // =============================================================================\n // FormSpec Extensions (x- prefixed)\n // =============================================================================\n\n /**\n * Data source key for dynamic enum fields.\n * Indicates that options should be fetched from a registered resolver.\n */\n \"x-formspec-source\"?: string;\n\n /**\n * Field names whose values are needed to fetch dynamic enum options.\n * Used for dependent/cascading dropdowns.\n */\n \"x-formspec-params\"?: readonly string[];\n\n /**\n * Schema source identifier for dynamic schema fields.\n * Indicates that the schema should be loaded dynamically at runtime.\n */\n \"x-formspec-schemaSource\"?: string;\n}\n\n/** Extension properties for custom FormSpec decorators. */\nexport type FormSpecSchemaExtensions = Record<`x-formspec-${string}`, unknown>;\n\n/** JSON Schema with FormSpec extension properties for arbitrary x-formspec-* keys. */\nexport type ExtendedJSONSchema7 = JSONSchema7 & FormSpecSchemaExtensions;\n\n/**\n * Sets a FormSpec extension property on a JSON Schema node.\n *\n * Use this to safely add `x-formspec-*` properties to any schema,\n * including nested schemas typed as `JSONSchema7` (which don't carry\n * the extension index signature).\n *\n * @param schema - Any JSON Schema node\n * @param key - Extension key (must start with `x-formspec-`)\n * @param value - Extension value\n */\nexport function setSchemaExtension(\n schema: JSONSchema7,\n key: `x-formspec-${string}`,\n value: unknown\n): void {\n (schema as ExtendedJSONSchema7)[key] = value;\n}\n\n/**\n * Reads a FormSpec extension property from a JSON Schema node.\n *\n * Use this to safely read `x-formspec-*` properties from any schema,\n * including nested schemas typed as `JSONSchema7`.\n *\n * @param schema - Any JSON Schema node\n * @param key - Extension key (must start with `x-formspec-`)\n * @returns The extension value, or `undefined` if not present\n */\nexport function getSchemaExtension(schema: JSONSchema7, key: `x-formspec-${string}`): unknown {\n return (schema as ExtendedJSONSchema7)[key];\n}\n","/**\n * Browser-safe exports for `@formspec/build`.\n *\n * This entry point excludes Node.js-specific functions like `writeSchemas`\n * that use `node:fs` and `node:path`, making it suitable for browser environments.\n *\n * @example\n * ```typescript\n * // In browser code (e.g., playground)\n * import { buildFormSchemas, generateJsonSchema, generateUiSchema } from \"@formspec/build/browser\";\n *\n * const form = formspec(field.text(\"name\"));\n * const { jsonSchema, uiSchema } = buildFormSchemas(form);\n * ```\n *\n * @packageDocumentation\n */\n\nimport type { FormElement, FormSpec } from \"@formspec/core\";\nimport { generateJsonSchema } from \"./json-schema/generator.js\";\nimport { generateUiSchema } from \"./ui-schema/generator.js\";\n\n// Re-export types\nexport type {\n JSONSchema7,\n JSONSchemaType,\n ExtendedJSONSchema7,\n FormSpecSchemaExtensions,\n} from \"./json-schema/types.js\";\n\nexport { setSchemaExtension, getSchemaExtension } from \"./json-schema/types.js\";\n\nexport type {\n UISchema,\n UISchemaElement,\n UISchemaElementBase,\n UISchemaElementType,\n ControlElement,\n VerticalLayout,\n HorizontalLayout,\n GroupLayout,\n Categorization,\n Category,\n LabelElement,\n Rule,\n RuleEffect,\n RuleConditionSchema,\n SchemaBasedCondition,\n} from \"./ui-schema/types.js\";\n\n// Zod validation schemas\nexport {\n ruleEffectSchema,\n uiSchemaElementTypeSchema,\n ruleConditionSchema,\n schemaBasedConditionSchema,\n ruleSchema,\n controlSchema,\n verticalLayoutSchema,\n horizontalLayoutSchema,\n groupLayoutSchema,\n categorizationSchema,\n categorySchema,\n labelElementSchema,\n uiSchemaElementSchema,\n uiSchema as uiSchemaSchema,\n} from \"./ui-schema/schema.js\";\n\nexport { jsonSchemaTypeSchema, jsonSchema7Schema } from \"./json-schema/schema.js\";\n\n// Re-export individual generators\nexport { generateJsonSchema } from \"./json-schema/generator.js\";\nexport { generateUiSchema, generateUiSchemaFromFields } from \"./ui-schema/generator.js\";\n\n/**\n * Result of building form schemas.\n */\nexport interface BuildResult {\n /** JSON Schema for validation */\n readonly jsonSchema: ReturnType<typeof generateJsonSchema>;\n /** JSON Forms UI Schema for rendering */\n readonly uiSchema: ReturnType<typeof generateUiSchema>;\n}\n\n/**\n * Builds both JSON Schema and UI Schema from a FormSpec.\n *\n * This is a browser-safe version that does not include file system operations.\n *\n * @example\n * ```typescript\n * const form = formspec(\n * field.text(\"name\", { required: true }),\n * field.number(\"age\", { min: 0 }),\n * );\n *\n * const { jsonSchema, uiSchema } = buildFormSchemas(form);\n * ```\n *\n * @param form - The FormSpec to build schemas from\n * @returns Object containing both jsonSchema and uiSchema\n */\nexport function buildFormSchemas<E extends readonly FormElement[]>(form: FormSpec<E>): BuildResult {\n return {\n jsonSchema: generateJsonSchema(form),\n uiSchema: generateUiSchema(form),\n };\n}\n"],"mappings":";AASA,SAAS,SAAS;AAUX,IAAM,uBAAuB,EAAE,KAAK;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAeM,IAAM,oBAA4C,EAAE;AAAA,EAAK,MAC9D,EACG,OAAO;AAAA,IACN,SAAS,EAAE,OAAO,EAAE,SAAS;AAAA,IAC7B,KAAK,EAAE,OAAO,EAAE,SAAS;AAAA,IACzB,MAAM,EAAE,OAAO,EAAE,SAAS;AAAA;AAAA,IAG1B,OAAO,EAAE,OAAO,EAAE,SAAS;AAAA,IAC3B,aAAa,EAAE,OAAO,EAAE,SAAS;AAAA,IACjC,YAAY,EAAE,QAAQ,EAAE,SAAS;AAAA;AAAA,IAGjC,MAAM,EAAE,MAAM,CAAC,sBAAsB,EAAE,MAAM,oBAAoB,CAAC,CAAC,EAAE,SAAS;AAAA;AAAA,IAG9E,WAAW,EAAE,OAAO,EAAE,SAAS;AAAA,IAC/B,WAAW,EAAE,OAAO,EAAE,SAAS;AAAA,IAC/B,SAAS,EAAE,OAAO,EAAE,SAAS;AAAA;AAAA,IAG7B,SAAS,EAAE,OAAO,EAAE,SAAS;AAAA,IAC7B,SAAS,EAAE,OAAO,EAAE,SAAS;AAAA,IAC7B,kBAAkB,EAAE,OAAO,EAAE,SAAS;AAAA,IACtC,kBAAkB,EAAE,OAAO,EAAE,SAAS;AAAA;AAAA,IAGtC,MAAM,EACH,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,EAAE,OAAO,GAAG,EAAE,QAAQ,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,EAC9D,SAAS,EACT,SAAS;AAAA,IACZ,OAAO,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,EAAE,OAAO,GAAG,EAAE,QAAQ,GAAG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MAAM;AAAA,IACN;AAAA,EACF;AAEA,SAAOC,cAAa,UAAmB,QAAQ,WAAW;AAC5D;AA2CO,SAAS,iBAAmD,MAA6B;AAC9F,QAAM,SAAmB;AAAA,IACvB,MAAM;AAAA,IACN,UAAU,mBAAmB,KAAK,QAAQ;AAAA,EAC5C;AAEA,SAAOA,cAAa,UAAmB,QAAQ,WAAW;AAC5D;;;ACjLO,SAAS,mBACd,QACA,KACA,OACM;AACN,EAAC,OAA+B,GAAG,IAAI;AACzC;AAYO,SAAS,mBAAmB,QAAqB,KAAsC;AAC5F,SAAQ,OAA+B,GAAG;AAC5C;;;AClCO,SAAS,iBAAmD,MAAgC;AACjG,SAAO;AAAA,IACL,YAAY,mBAAmB,IAAI;AAAA,IACnC,UAAU,iBAAiB,IAAI;AAAA,EACjC;AACF;","names":["z","z","z","parseOrThrow"]}
|
package/dist/build.d.ts
CHANGED
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
|
|
26
26
|
import type { FormElement } from '@formspec/core';
|
|
27
27
|
import type { FormSpec } from '@formspec/core';
|
|
28
|
+
import { z } from 'zod';
|
|
28
29
|
|
|
29
30
|
/**
|
|
30
31
|
* Builds both JSON Schema and UI Schema from a FormSpec.
|
|
@@ -65,16 +66,42 @@ export declare interface BuildResult {
|
|
|
65
66
|
readonly uiSchema: UISchema;
|
|
66
67
|
}
|
|
67
68
|
|
|
69
|
+
/**
|
|
70
|
+
* A Categorization element (tab-based layout).
|
|
71
|
+
*/
|
|
72
|
+
export declare interface Categorization {
|
|
73
|
+
type: "Categorization";
|
|
74
|
+
elements: Category[];
|
|
75
|
+
label?: string | undefined;
|
|
76
|
+
rule?: Rule | undefined;
|
|
77
|
+
options?: Record<string, unknown> | undefined;
|
|
78
|
+
[k: string]: unknown;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export declare const categorizationSchema: z.ZodType<Categorization>;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* A Category element, used inside a Categorization layout.
|
|
85
|
+
*/
|
|
86
|
+
export declare interface Category {
|
|
87
|
+
type: "Category";
|
|
88
|
+
label: string;
|
|
89
|
+
elements: UISchemaElement[];
|
|
90
|
+
rule?: Rule | undefined;
|
|
91
|
+
options?: Record<string, unknown> | undefined;
|
|
92
|
+
[k: string]: unknown;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export declare const categorySchema: z.ZodType<Category>;
|
|
96
|
+
|
|
68
97
|
/**
|
|
69
98
|
* Generated schemas for a class.
|
|
70
99
|
*/
|
|
71
100
|
export declare interface ClassSchemas {
|
|
72
101
|
/** JSON Schema for validation */
|
|
73
102
|
jsonSchema: ExtendedJSONSchema7;
|
|
74
|
-
/**
|
|
75
|
-
uiSchema:
|
|
76
|
-
elements: FormSpecField[];
|
|
77
|
-
};
|
|
103
|
+
/** JSON Forms UI Schema for rendering */
|
|
104
|
+
uiSchema: UISchema;
|
|
78
105
|
}
|
|
79
106
|
|
|
80
107
|
/**
|
|
@@ -92,11 +119,102 @@ export declare interface CodegenOptions {
|
|
|
92
119
|
/**
|
|
93
120
|
* A Control element that binds to a JSON Schema property.
|
|
94
121
|
*/
|
|
95
|
-
export declare
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
122
|
+
export declare type ControlElement = z.infer<typeof controlSchema>;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Zod schema for a Control element.
|
|
126
|
+
*/
|
|
127
|
+
export declare const controlSchema: z.ZodObject<{
|
|
128
|
+
type: z.ZodLiteral<"Control">;
|
|
129
|
+
scope: z.ZodString;
|
|
130
|
+
label: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodLiteral<false>]>>;
|
|
131
|
+
rule: z.ZodOptional<z.ZodObject<{
|
|
132
|
+
effect: z.ZodEnum<["SHOW", "HIDE", "ENABLE", "DISABLE"]>;
|
|
133
|
+
condition: z.ZodObject<{
|
|
134
|
+
scope: z.ZodString;
|
|
135
|
+
schema: z.ZodType<RuleConditionSchema, z.ZodTypeDef, RuleConditionSchema>;
|
|
136
|
+
}, "strict", z.ZodTypeAny, {
|
|
137
|
+
schema: RuleConditionSchema;
|
|
138
|
+
scope: string;
|
|
139
|
+
}, {
|
|
140
|
+
schema: RuleConditionSchema;
|
|
141
|
+
scope: string;
|
|
142
|
+
}>;
|
|
143
|
+
}, "strict", z.ZodTypeAny, {
|
|
144
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
145
|
+
condition: {
|
|
146
|
+
schema: RuleConditionSchema;
|
|
147
|
+
scope: string;
|
|
148
|
+
};
|
|
149
|
+
}, {
|
|
150
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
151
|
+
condition: {
|
|
152
|
+
schema: RuleConditionSchema;
|
|
153
|
+
scope: string;
|
|
154
|
+
};
|
|
155
|
+
}>>;
|
|
156
|
+
options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
157
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
158
|
+
type: z.ZodLiteral<"Control">;
|
|
159
|
+
scope: z.ZodString;
|
|
160
|
+
label: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodLiteral<false>]>>;
|
|
161
|
+
rule: z.ZodOptional<z.ZodObject<{
|
|
162
|
+
effect: z.ZodEnum<["SHOW", "HIDE", "ENABLE", "DISABLE"]>;
|
|
163
|
+
condition: z.ZodObject<{
|
|
164
|
+
scope: z.ZodString;
|
|
165
|
+
schema: z.ZodType<RuleConditionSchema, z.ZodTypeDef, RuleConditionSchema>;
|
|
166
|
+
}, "strict", z.ZodTypeAny, {
|
|
167
|
+
schema: RuleConditionSchema;
|
|
168
|
+
scope: string;
|
|
169
|
+
}, {
|
|
170
|
+
schema: RuleConditionSchema;
|
|
171
|
+
scope: string;
|
|
172
|
+
}>;
|
|
173
|
+
}, "strict", z.ZodTypeAny, {
|
|
174
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
175
|
+
condition: {
|
|
176
|
+
schema: RuleConditionSchema;
|
|
177
|
+
scope: string;
|
|
178
|
+
};
|
|
179
|
+
}, {
|
|
180
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
181
|
+
condition: {
|
|
182
|
+
schema: RuleConditionSchema;
|
|
183
|
+
scope: string;
|
|
184
|
+
};
|
|
185
|
+
}>>;
|
|
186
|
+
options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
187
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
188
|
+
type: z.ZodLiteral<"Control">;
|
|
189
|
+
scope: z.ZodString;
|
|
190
|
+
label: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodLiteral<false>]>>;
|
|
191
|
+
rule: z.ZodOptional<z.ZodObject<{
|
|
192
|
+
effect: z.ZodEnum<["SHOW", "HIDE", "ENABLE", "DISABLE"]>;
|
|
193
|
+
condition: z.ZodObject<{
|
|
194
|
+
scope: z.ZodString;
|
|
195
|
+
schema: z.ZodType<RuleConditionSchema, z.ZodTypeDef, RuleConditionSchema>;
|
|
196
|
+
}, "strict", z.ZodTypeAny, {
|
|
197
|
+
schema: RuleConditionSchema;
|
|
198
|
+
scope: string;
|
|
199
|
+
}, {
|
|
200
|
+
schema: RuleConditionSchema;
|
|
201
|
+
scope: string;
|
|
202
|
+
}>;
|
|
203
|
+
}, "strict", z.ZodTypeAny, {
|
|
204
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
205
|
+
condition: {
|
|
206
|
+
schema: RuleConditionSchema;
|
|
207
|
+
scope: string;
|
|
208
|
+
};
|
|
209
|
+
}, {
|
|
210
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
211
|
+
condition: {
|
|
212
|
+
schema: RuleConditionSchema;
|
|
213
|
+
scope: string;
|
|
214
|
+
};
|
|
215
|
+
}>>;
|
|
216
|
+
options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
217
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
100
218
|
|
|
101
219
|
/**
|
|
102
220
|
* Information about a decorated class found during codegen analysis.
|
|
@@ -174,10 +292,8 @@ export declare interface GenerateFromClassOptions {
|
|
|
174
292
|
export declare interface GenerateFromClassResult {
|
|
175
293
|
/** JSON Schema for validation */
|
|
176
294
|
jsonSchema: ExtendedJSONSchema7;
|
|
177
|
-
/**
|
|
178
|
-
uiSchema:
|
|
179
|
-
elements: FormSpecField[];
|
|
180
|
-
};
|
|
295
|
+
/** JSON Forms UI Schema for rendering */
|
|
296
|
+
uiSchema: UISchema;
|
|
181
297
|
}
|
|
182
298
|
|
|
183
299
|
/**
|
|
@@ -307,6 +423,21 @@ export declare interface GenerateSchemasOptions {
|
|
|
307
423
|
*/
|
|
308
424
|
export declare function generateUiSchema<E extends readonly FormElement[]>(form: FormSpec<E>): UISchema;
|
|
309
425
|
|
|
426
|
+
/**
|
|
427
|
+
* Converts FormSpecField[] (from decorator/interface/type analysis) to a JSON Forms UISchema.
|
|
428
|
+
*
|
|
429
|
+
* Mapping:
|
|
430
|
+
* - Each field → `{ type: "Control", scope: "#/properties/{id}", label? }`
|
|
431
|
+
* - `showWhen: { field, value }` → rule with SHOW effect
|
|
432
|
+
* - `group` property → Groups fields by group name, preserving insertion order
|
|
433
|
+
* - `fields` (nested object) → single Control pointing to the object property
|
|
434
|
+
* - Root wrapper → `{ type: "VerticalLayout", elements }`
|
|
435
|
+
*
|
|
436
|
+
* @param fields - The FormSpecField array to convert
|
|
437
|
+
* @returns A JSON Forms UISchema
|
|
438
|
+
*/
|
|
439
|
+
export declare function generateUiSchemaFromFields(fields: FormSpecField[]): UISchema;
|
|
440
|
+
|
|
310
441
|
/**
|
|
311
442
|
* Reads a FormSpec extension property from a JSON Schema node.
|
|
312
443
|
*
|
|
@@ -322,20 +453,30 @@ export declare function getSchemaExtension(schema: JSONSchema7, key: `x-formspec
|
|
|
322
453
|
/**
|
|
323
454
|
* A group element with a label.
|
|
324
455
|
*/
|
|
325
|
-
export declare interface GroupLayout
|
|
456
|
+
export declare interface GroupLayout {
|
|
326
457
|
type: "Group";
|
|
327
458
|
label: string;
|
|
328
459
|
elements: UISchemaElement[];
|
|
460
|
+
rule?: Rule | undefined;
|
|
461
|
+
options?: Record<string, unknown> | undefined;
|
|
462
|
+
[k: string]: unknown;
|
|
329
463
|
}
|
|
330
464
|
|
|
465
|
+
export declare const groupLayoutSchema: z.ZodType<GroupLayout>;
|
|
466
|
+
|
|
331
467
|
/**
|
|
332
468
|
* A horizontal layout element.
|
|
333
469
|
*/
|
|
334
|
-
export declare interface HorizontalLayout
|
|
470
|
+
export declare interface HorizontalLayout {
|
|
335
471
|
type: "HorizontalLayout";
|
|
336
472
|
elements: UISchemaElement[];
|
|
473
|
+
rule?: Rule | undefined;
|
|
474
|
+
options?: Record<string, unknown> | undefined;
|
|
475
|
+
[k: string]: unknown;
|
|
337
476
|
}
|
|
338
477
|
|
|
478
|
+
export declare const horizontalLayoutSchema: z.ZodType<HorizontalLayout>;
|
|
479
|
+
|
|
339
480
|
/**
|
|
340
481
|
* A JSON Schema definition (draft-07 subset).
|
|
341
482
|
*/
|
|
@@ -388,6 +529,8 @@ export declare interface JSONSchema7 {
|
|
|
388
529
|
"x-formspec-schemaSource"?: string;
|
|
389
530
|
}
|
|
390
531
|
|
|
532
|
+
export declare const jsonSchema7Schema: z.ZodType<JSONSchema7>;
|
|
533
|
+
|
|
391
534
|
/**
|
|
392
535
|
* JSON Schema Draft-07 type definitions.
|
|
393
536
|
*
|
|
@@ -398,31 +541,171 @@ export declare interface JSONSchema7 {
|
|
|
398
541
|
*/
|
|
399
542
|
export declare type JSONSchemaType = "string" | "number" | "integer" | "boolean" | "object" | "array" | "null";
|
|
400
543
|
|
|
544
|
+
/**
|
|
545
|
+
* Zod schema for JSON Schema primitive type strings.
|
|
546
|
+
*/
|
|
547
|
+
export declare const jsonSchemaTypeSchema: z.ZodEnum<["string", "number", "integer", "boolean", "object", "array", "null"]>;
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* A Label element for displaying static text.
|
|
551
|
+
*/
|
|
552
|
+
export declare type LabelElement = z.infer<typeof labelElementSchema>;
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* Zod schema for a Label element.
|
|
556
|
+
*/
|
|
557
|
+
export declare const labelElementSchema: z.ZodObject<{
|
|
558
|
+
type: z.ZodLiteral<"Label">;
|
|
559
|
+
text: z.ZodString;
|
|
560
|
+
rule: z.ZodOptional<z.ZodObject<{
|
|
561
|
+
effect: z.ZodEnum<["SHOW", "HIDE", "ENABLE", "DISABLE"]>;
|
|
562
|
+
condition: z.ZodObject<{
|
|
563
|
+
scope: z.ZodString;
|
|
564
|
+
schema: z.ZodType<RuleConditionSchema, z.ZodTypeDef, RuleConditionSchema>;
|
|
565
|
+
}, "strict", z.ZodTypeAny, {
|
|
566
|
+
schema: RuleConditionSchema;
|
|
567
|
+
scope: string;
|
|
568
|
+
}, {
|
|
569
|
+
schema: RuleConditionSchema;
|
|
570
|
+
scope: string;
|
|
571
|
+
}>;
|
|
572
|
+
}, "strict", z.ZodTypeAny, {
|
|
573
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
574
|
+
condition: {
|
|
575
|
+
schema: RuleConditionSchema;
|
|
576
|
+
scope: string;
|
|
577
|
+
};
|
|
578
|
+
}, {
|
|
579
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
580
|
+
condition: {
|
|
581
|
+
schema: RuleConditionSchema;
|
|
582
|
+
scope: string;
|
|
583
|
+
};
|
|
584
|
+
}>>;
|
|
585
|
+
options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
586
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
587
|
+
type: z.ZodLiteral<"Label">;
|
|
588
|
+
text: z.ZodString;
|
|
589
|
+
rule: z.ZodOptional<z.ZodObject<{
|
|
590
|
+
effect: z.ZodEnum<["SHOW", "HIDE", "ENABLE", "DISABLE"]>;
|
|
591
|
+
condition: z.ZodObject<{
|
|
592
|
+
scope: z.ZodString;
|
|
593
|
+
schema: z.ZodType<RuleConditionSchema, z.ZodTypeDef, RuleConditionSchema>;
|
|
594
|
+
}, "strict", z.ZodTypeAny, {
|
|
595
|
+
schema: RuleConditionSchema;
|
|
596
|
+
scope: string;
|
|
597
|
+
}, {
|
|
598
|
+
schema: RuleConditionSchema;
|
|
599
|
+
scope: string;
|
|
600
|
+
}>;
|
|
601
|
+
}, "strict", z.ZodTypeAny, {
|
|
602
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
603
|
+
condition: {
|
|
604
|
+
schema: RuleConditionSchema;
|
|
605
|
+
scope: string;
|
|
606
|
+
};
|
|
607
|
+
}, {
|
|
608
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
609
|
+
condition: {
|
|
610
|
+
schema: RuleConditionSchema;
|
|
611
|
+
scope: string;
|
|
612
|
+
};
|
|
613
|
+
}>>;
|
|
614
|
+
options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
615
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
616
|
+
type: z.ZodLiteral<"Label">;
|
|
617
|
+
text: z.ZodString;
|
|
618
|
+
rule: z.ZodOptional<z.ZodObject<{
|
|
619
|
+
effect: z.ZodEnum<["SHOW", "HIDE", "ENABLE", "DISABLE"]>;
|
|
620
|
+
condition: z.ZodObject<{
|
|
621
|
+
scope: z.ZodString;
|
|
622
|
+
schema: z.ZodType<RuleConditionSchema, z.ZodTypeDef, RuleConditionSchema>;
|
|
623
|
+
}, "strict", z.ZodTypeAny, {
|
|
624
|
+
schema: RuleConditionSchema;
|
|
625
|
+
scope: string;
|
|
626
|
+
}, {
|
|
627
|
+
schema: RuleConditionSchema;
|
|
628
|
+
scope: string;
|
|
629
|
+
}>;
|
|
630
|
+
}, "strict", z.ZodTypeAny, {
|
|
631
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
632
|
+
condition: {
|
|
633
|
+
schema: RuleConditionSchema;
|
|
634
|
+
scope: string;
|
|
635
|
+
};
|
|
636
|
+
}, {
|
|
637
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
638
|
+
condition: {
|
|
639
|
+
schema: RuleConditionSchema;
|
|
640
|
+
scope: string;
|
|
641
|
+
};
|
|
642
|
+
}>>;
|
|
643
|
+
options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
644
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
645
|
+
|
|
401
646
|
/**
|
|
402
647
|
* Rule for conditional element visibility/enablement.
|
|
403
648
|
*/
|
|
404
|
-
export declare
|
|
405
|
-
effect: RuleEffect;
|
|
406
|
-
condition: SchemaBasedCondition;
|
|
407
|
-
}
|
|
649
|
+
export declare type Rule = z.infer<typeof ruleSchema>;
|
|
408
650
|
|
|
409
651
|
/**
|
|
410
|
-
* JSON Schema subset
|
|
652
|
+
* JSON Schema subset used in rule conditions.
|
|
411
653
|
*/
|
|
412
654
|
export declare interface RuleConditionSchema {
|
|
413
655
|
const?: unknown;
|
|
414
656
|
enum?: readonly unknown[];
|
|
415
657
|
type?: string;
|
|
658
|
+
not?: RuleConditionSchema;
|
|
416
659
|
minimum?: number;
|
|
417
660
|
maximum?: number;
|
|
661
|
+
exclusiveMinimum?: number;
|
|
662
|
+
exclusiveMaximum?: number;
|
|
663
|
+
minLength?: number;
|
|
418
664
|
properties?: Record<string, RuleConditionSchema>;
|
|
665
|
+
required?: string[];
|
|
419
666
|
allOf?: RuleConditionSchema[];
|
|
420
667
|
}
|
|
421
668
|
|
|
669
|
+
export declare const ruleConditionSchema: z.ZodType<RuleConditionSchema>;
|
|
670
|
+
|
|
422
671
|
/**
|
|
423
672
|
* Rule effect types for conditional visibility.
|
|
424
673
|
*/
|
|
425
|
-
export declare type RuleEffect =
|
|
674
|
+
export declare type RuleEffect = z.infer<typeof ruleEffectSchema>;
|
|
675
|
+
|
|
676
|
+
/**
|
|
677
|
+
* Zod schema for rule effect values.
|
|
678
|
+
*/
|
|
679
|
+
export declare const ruleEffectSchema: z.ZodEnum<["SHOW", "HIDE", "ENABLE", "DISABLE"]>;
|
|
680
|
+
|
|
681
|
+
/**
|
|
682
|
+
* Zod schema for a UI Schema rule.
|
|
683
|
+
*/
|
|
684
|
+
export declare const ruleSchema: z.ZodObject<{
|
|
685
|
+
effect: z.ZodEnum<["SHOW", "HIDE", "ENABLE", "DISABLE"]>;
|
|
686
|
+
condition: z.ZodObject<{
|
|
687
|
+
scope: z.ZodString;
|
|
688
|
+
schema: z.ZodType<RuleConditionSchema, z.ZodTypeDef, RuleConditionSchema>;
|
|
689
|
+
}, "strict", z.ZodTypeAny, {
|
|
690
|
+
schema: RuleConditionSchema;
|
|
691
|
+
scope: string;
|
|
692
|
+
}, {
|
|
693
|
+
schema: RuleConditionSchema;
|
|
694
|
+
scope: string;
|
|
695
|
+
}>;
|
|
696
|
+
}, "strict", z.ZodTypeAny, {
|
|
697
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
698
|
+
condition: {
|
|
699
|
+
schema: RuleConditionSchema;
|
|
700
|
+
scope: string;
|
|
701
|
+
};
|
|
702
|
+
}, {
|
|
703
|
+
effect: "SHOW" | "HIDE" | "ENABLE" | "DISABLE";
|
|
704
|
+
condition: {
|
|
705
|
+
schema: RuleConditionSchema;
|
|
706
|
+
scope: string;
|
|
707
|
+
};
|
|
708
|
+
}>;
|
|
426
709
|
|
|
427
710
|
/**
|
|
428
711
|
* Runs the code generation.
|
|
@@ -432,10 +715,21 @@ export declare function runCodegen(options: CodegenOptions): void;
|
|
|
432
715
|
/**
|
|
433
716
|
* Condition for a rule.
|
|
434
717
|
*/
|
|
435
|
-
export declare
|
|
718
|
+
export declare type SchemaBasedCondition = z.infer<typeof schemaBasedConditionSchema>;
|
|
719
|
+
|
|
720
|
+
/**
|
|
721
|
+
* Zod schema for a schema-based rule condition.
|
|
722
|
+
*/
|
|
723
|
+
export declare const schemaBasedConditionSchema: z.ZodObject<{
|
|
724
|
+
scope: z.ZodString;
|
|
725
|
+
schema: z.ZodType<RuleConditionSchema, z.ZodTypeDef, RuleConditionSchema>;
|
|
726
|
+
}, "strict", z.ZodTypeAny, {
|
|
727
|
+
schema: RuleConditionSchema;
|
|
436
728
|
scope: string;
|
|
729
|
+
}, {
|
|
437
730
|
schema: RuleConditionSchema;
|
|
438
|
-
|
|
731
|
+
scope: string;
|
|
732
|
+
}>;
|
|
439
733
|
|
|
440
734
|
/**
|
|
441
735
|
* Sets a FormSpec extension property on a JSON Schema node.
|
|
@@ -487,17 +781,22 @@ export declare interface TypeMetadata {
|
|
|
487
781
|
}
|
|
488
782
|
|
|
489
783
|
/**
|
|
490
|
-
* Root UI Schema (always a layout).
|
|
784
|
+
* Root UI Schema (always a layout — not a Control, Category, or Label).
|
|
491
785
|
*/
|
|
492
|
-
export declare type UISchema = VerticalLayout | HorizontalLayout | GroupLayout;
|
|
786
|
+
export declare type UISchema = VerticalLayout | HorizontalLayout | GroupLayout | Categorization;
|
|
493
787
|
|
|
494
788
|
/**
|
|
495
789
|
* Union of all UI Schema element types.
|
|
496
790
|
*/
|
|
497
|
-
export declare type UISchemaElement = ControlElement | VerticalLayout | HorizontalLayout | GroupLayout;
|
|
791
|
+
export declare type UISchemaElement = ControlElement | VerticalLayout | HorizontalLayout | GroupLayout | Categorization | Category | LabelElement;
|
|
498
792
|
|
|
499
793
|
/**
|
|
500
794
|
* Base interface for all UI Schema elements.
|
|
795
|
+
*
|
|
796
|
+
* This is a manually maintained interface representing the common shape
|
|
797
|
+
* shared by all element types. It is kept as an interface (rather than
|
|
798
|
+
* derived from Zod) because it is the base of a discriminated union, not
|
|
799
|
+
* a union member itself.
|
|
501
800
|
*/
|
|
502
801
|
export declare interface UISchemaElementBase {
|
|
503
802
|
type: UISchemaElementType;
|
|
@@ -505,25 +804,36 @@ export declare interface UISchemaElementBase {
|
|
|
505
804
|
options?: Record<string, unknown>;
|
|
506
805
|
}
|
|
507
806
|
|
|
807
|
+
export declare const uiSchemaElementSchema: z.ZodType<UISchemaElement>;
|
|
808
|
+
|
|
508
809
|
/**
|
|
509
|
-
*
|
|
510
|
-
*
|
|
511
|
-
* These types define the UI layout structure for JSON Forms.
|
|
512
|
-
* See: https://jsonforms.io/docs/uischema/
|
|
810
|
+
* UI Schema element types.
|
|
513
811
|
*/
|
|
812
|
+
export declare type UISchemaElementType = z.infer<typeof uiSchemaElementTypeSchema>;
|
|
813
|
+
|
|
514
814
|
/**
|
|
515
|
-
* UI Schema element
|
|
815
|
+
* Zod schema for UI Schema element type strings.
|
|
516
816
|
*/
|
|
517
|
-
export declare
|
|
817
|
+
export declare const uiSchemaElementTypeSchema: z.ZodEnum<["Control", "VerticalLayout", "HorizontalLayout", "Group", "Categorization", "Category", "Label"]>;
|
|
818
|
+
|
|
819
|
+
/**
|
|
820
|
+
* Zod schema for the root UI Schema (layout types only).
|
|
821
|
+
*/
|
|
822
|
+
export declare const uiSchemaSchema: z.ZodType<UISchema>;
|
|
518
823
|
|
|
519
824
|
/**
|
|
520
825
|
* A vertical layout element.
|
|
521
826
|
*/
|
|
522
|
-
export declare interface VerticalLayout
|
|
827
|
+
export declare interface VerticalLayout {
|
|
523
828
|
type: "VerticalLayout";
|
|
524
829
|
elements: UISchemaElement[];
|
|
830
|
+
rule?: Rule | undefined;
|
|
831
|
+
options?: Record<string, unknown> | undefined;
|
|
832
|
+
[k: string]: unknown;
|
|
525
833
|
}
|
|
526
834
|
|
|
835
|
+
export declare const verticalLayoutSchema: z.ZodType<VerticalLayout>;
|
|
836
|
+
|
|
527
837
|
/**
|
|
528
838
|
* Builds and writes both JSON Schema and UI Schema files to disk.
|
|
529
839
|
*
|