@formadapter/core 0.0.0

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["isRecord","isRecord"],"sources":["../src/path-segment.ts","../src/record.ts","../src/compile.ts","../src/defaults.ts","../src/path.ts","../src/rules.ts","../src/prepare.ts","../src/options.ts","../src/submission.ts","../src/validation.ts"],"sourcesContent":["const STANDARD_OBJECT_PROTOTYPE_SEGMENTS = [\n \"__defineGetter__\",\n \"__defineSetter__\",\n \"__lookupGetter__\",\n \"__lookupSetter__\",\n \"__proto__\",\n \"constructor\",\n \"hasOwnProperty\",\n \"isPrototypeOf\",\n \"propertyIsEnumerable\",\n \"toLocaleString\",\n \"toString\",\n \"valueOf\",\n] as const;\n\nexport type ReservedFormPathSegment =\n | (typeof STANDARD_OBJECT_PROTOTYPE_SEGMENTS)[number]\n | \"prototype\"\n | \"root\";\n\n/** Names that collide with JavaScript object lookup or form-runtime state. */\nexport const RESERVED_FORM_PATH_SEGMENTS: ReadonlySet<string> = new Set([\n ...Object.getOwnPropertyNames(Object.prototype),\n \"prototype\",\n \"root\",\n]);\n\nexport function formPathSegmentError(segment: string): string | undefined {\n if (segment.length === 0) {\n return \"Empty property names cannot be represented in a form path\";\n }\n if (RESERVED_FORM_PATH_SEGMENTS.has(segment)) {\n return `Property name “${segment}” is reserved and cannot be represented safely in a form path`;\n }\n if (segment.startsWith(\"__formadapter_\")) {\n return `Property name “${segment}” uses FormAdapter's reserved internal namespace`;\n }\n if (segment.startsWith(\"$ACTION_\")) {\n return `Property name “${segment}” uses a reserved server-action prefix and cannot be represented safely`;\n }\n if (\n segment.includes(\".\") ||\n segment.includes(\"[\") ||\n segment.includes(\"]\") ||\n segment.includes(\"'\") ||\n segment.includes('\"')\n ) {\n return `Property name “${segment}” contains form-path syntax and cannot be represented safely`;\n }\n if (!Number.isNaN(Number(segment))) {\n return `Numeric-like property name “${segment}” cannot be distinguished safely from an array index`;\n }\n return undefined;\n}\n\n/** True when a schema property cannot be represented losslessly as one path segment. */\nexport function isReservedFormPathSegment(segment: string): boolean {\n return formPathSegmentError(segment) !== undefined;\n}\n","/** Own-property checks that are safe for null-prototype and hostile-key records. */\nexport function hasOwn(\n value: object,\n key: PropertyKey,\n): boolean {\n return Object.prototype.hasOwnProperty.call(value, key);\n}\n\n/**\n * Creates a dictionary without inherited names such as `constructor` or\n * `toString`. Use this for path-indexed internal/public maps.\n */\nexport function createNullRecord<Value>(): Record<string, Value> {\n return Object.create(null) as Record<string, Value>;\n}\n\n/** Defines a normal enumerable data property without invoking `__proto__`. */\nexport function defineOwn<Value>(\n target: Record<string, Value>,\n key: string,\n value: Value,\n): void {\n Object.defineProperty(target, key, {\n configurable: true,\n enumerable: true,\n value,\n writable: true,\n });\n}\n\nexport function ownValue(\n value: Readonly<Record<string, unknown>>,\n key: string,\n): unknown {\n return hasOwn(value, key) ? value[key] : undefined;\n}\n","import type {\n BuiltInControl,\n FieldConfig,\n FieldDataType,\n FieldState,\n FormConfig,\n FormModel,\n FormNode,\n FormOption,\n JsonPrimitive,\n JsonSchema,\n JsonSchemaObject,\n NativeInputType,\n ResolvedFieldConfig,\n ScalarConstraints,\n} from \"./types\";\nimport type { FormSchema, InferInput } from \"./standard\";\nimport { formPathSegmentError } from \"./path-segment\";\nimport {\n createNullRecord,\n defineOwn,\n hasOwn,\n ownValue,\n} from \"./record\";\n\nexport class SchemaConversionError extends Error {\n public override readonly name = \"SchemaConversionError\";\n\n public constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n }\n}\n\ninterface CompileContext<Input, Control extends string> {\n readonly config: FormConfig<Input, Control>;\n readonly rootSchema: JsonSchemaObject;\n readonly resolvingRefs: ReadonlySet<string>;\n}\n\ninterface NodeInput<Input, Control extends string> {\n readonly context: CompileContext<Input, Control>;\n readonly key: string;\n readonly labelFallback: string;\n readonly nullable?: boolean;\n readonly path: string;\n readonly required: boolean;\n readonly schema: JsonSchema;\n}\n\nfunction isRecord(value: unknown): value is Readonly<Record<string, unknown>> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction isSchemaObject(schema: unknown): schema is JsonSchemaObject {\n return typeof schema === \"object\" && schema !== null && !Array.isArray(schema);\n}\n\nfunction humanize(value: string): string {\n const words = value\n .replaceAll(\"[]\", \"\")\n .replace(/([a-z0-9])([A-Z])/g, \"$1 $2\")\n .replace(/[_-]+/g, \" \")\n .trim();\n return words ? words.charAt(0).toLocaleUpperCase() + words.slice(1) : \"Field\";\n}\n\nfunction pointerValue(root: JsonSchemaObject, reference: string): JsonSchema | undefined {\n if (!reference.startsWith(\"#/\")) return undefined;\n let current: unknown = root;\n for (const encoded of reference.slice(2).split(\"/\")) {\n const segment = encoded.replaceAll(\"~1\", \"/\").replaceAll(\"~0\", \"~\");\n if (!isRecord(current) || !hasOwn(current, segment)) return undefined;\n current = current[segment];\n }\n return typeof current === \"boolean\" || isRecord(current)\n ? (current as JsonSchema)\n : undefined;\n}\n\nfunction sameValue(left: unknown, right: unknown): boolean {\n if (Object.is(left, right)) return true;\n if (Array.isArray(left) || Array.isArray(right)) {\n return Array.isArray(left) &&\n Array.isArray(right) &&\n left.length === right.length &&\n left.every((value, index) => sameValue(value, right[index]));\n }\n if (!isRecord(left) || !isRecord(right)) return false;\n const leftKeys = Object.keys(left).sort();\n const rightKeys = Object.keys(right).sort();\n return leftKeys.length === rightKeys.length &&\n leftKeys.every((key, index) =>\n key === rightKeys[index] && sameValue(left[key], right[key])\n );\n}\n\ninterface SchemaIntersection {\n readonly schema?: JsonSchemaObject;\n readonly error?: string;\n}\n\nconst COMPOSED_KEYWORDS = new Set([\n \"$defs\",\n \"additionalProperties\",\n \"allOf\",\n \"const\",\n \"default\",\n \"definitions\",\n \"deprecated\",\n \"description\",\n \"enum\",\n \"examples\",\n \"exclusiveMaximum\",\n \"exclusiveMinimum\",\n \"format\",\n \"items\",\n \"maxItems\",\n \"maxLength\",\n \"maximum\",\n \"minItems\",\n \"minLength\",\n \"minimum\",\n \"multipleOf\",\n \"pattern\",\n \"patternProperties\",\n \"properties\",\n \"propertyNames\",\n \"readOnly\",\n \"required\",\n \"title\",\n \"type\",\n \"uniqueItems\",\n \"writeOnly\",\n]);\n\nfunction intersectSchemaValue(left: JsonSchema, right: JsonSchema): JsonSchema {\n if (left === false || right === false) return false;\n if (left === true) return right;\n if (right === true) return left;\n return { allOf: [left, right] };\n}\n\nfunction mergeSchemaMap(\n left: Readonly<Record<string, JsonSchema>> | undefined,\n right: Readonly<Record<string, JsonSchema>> | undefined,\n): Readonly<Record<string, JsonSchema>> | undefined {\n if (!left && !right) return undefined;\n const merged = createNullRecord<JsonSchema>();\n for (const [key, value] of Object.entries(left ?? {})) {\n defineOwn(merged, key, value);\n }\n for (const [key, value] of Object.entries(right ?? {})) {\n defineOwn(\n merged,\n key,\n hasOwn(merged, key) ? intersectSchemaValue(merged[key]!, value) : value,\n );\n }\n return merged;\n}\n\nfunction mergeDefinitions(\n left: Readonly<Record<string, JsonSchema>> | undefined,\n right: Readonly<Record<string, JsonSchema>> | undefined,\n keyword: \"$defs\" | \"definitions\",\n): { readonly definitions?: Readonly<Record<string, JsonSchema>>; readonly error?: string } {\n if (!left && !right) return {};\n const merged = createNullRecord<JsonSchema>();\n for (const [key, value] of Object.entries(left ?? {})) defineOwn(merged, key, value);\n for (const [key, value] of Object.entries(right ?? {})) {\n if (hasOwn(merged, key) && !sameValue(merged[key], value)) {\n return { error: `Cannot safely combine conflicting ${keyword} definition “${key}”` };\n }\n defineOwn(merged, key, value);\n }\n return { definitions: merged };\n}\n\nfunction explicitTypes(schema: JsonSchemaObject): readonly string[] | undefined {\n if (typeof schema.type === \"string\") return [schema.type];\n return Array.isArray(schema.type) ? schema.type : undefined;\n}\n\nfunction intersectTypes(\n left: readonly string[] | undefined,\n right: readonly string[] | undefined,\n): readonly string[] | undefined {\n if (!left) return right;\n if (!right) return left;\n const result: string[] = [];\n for (const leftType of left) {\n for (const rightType of right) {\n const intersection = leftType === rightType\n ? leftType\n : (leftType === \"number\" && rightType === \"integer\") ||\n (leftType === \"integer\" && rightType === \"number\")\n ? \"integer\"\n : undefined;\n if (intersection && !result.includes(intersection)) result.push(intersection);\n }\n }\n return result;\n}\n\nfunction constrainedValues(schema: JsonSchemaObject): readonly unknown[] | undefined {\n const hasConst = hasOwn(schema, \"const\");\n const enumValues = schema.enum;\n if (!hasConst) return enumValues;\n if (!enumValues) return [schema.const];\n return enumValues.some((value) => sameValue(value, schema.const))\n ? [schema.const]\n : [];\n}\n\nfunction intersectValues(\n left: readonly unknown[] | undefined,\n right: readonly unknown[] | undefined,\n): readonly unknown[] | undefined {\n if (!left) return right;\n if (!right) return left;\n return left.filter((leftValue) =>\n right.some((rightValue) => sameValue(leftValue, rightValue))\n );\n}\n\nfunction valueMatchesType(value: unknown, type: string): boolean {\n switch (type) {\n case \"array\": return Array.isArray(value);\n case \"boolean\": return typeof value === \"boolean\";\n case \"integer\": return typeof value === \"number\" && Number.isInteger(value);\n case \"null\": return value === null;\n case \"number\": return typeof value === \"number\" && Number.isFinite(value);\n case \"object\": return isRecord(value);\n case \"string\": return typeof value === \"string\";\n default: return false;\n }\n}\n\ninterface NumericBoundary {\n readonly exclusive: boolean;\n readonly value: number;\n}\n\nfunction lowerBoundary(schema: JsonSchemaObject): NumericBoundary | undefined {\n const candidates: NumericBoundary[] = [];\n if (schema.minimum !== undefined) {\n candidates.push({ exclusive: false, value: schema.minimum });\n }\n if (schema.exclusiveMinimum !== undefined) {\n candidates.push({ exclusive: true, value: schema.exclusiveMinimum });\n }\n return candidates.sort((left, right) =>\n right.value - left.value || Number(right.exclusive) - Number(left.exclusive)\n )[0];\n}\n\nfunction upperBoundary(schema: JsonSchemaObject): NumericBoundary | undefined {\n const candidates: NumericBoundary[] = [];\n if (schema.maximum !== undefined) {\n candidates.push({ exclusive: false, value: schema.maximum });\n }\n if (schema.exclusiveMaximum !== undefined) {\n candidates.push({ exclusive: true, value: schema.exclusiveMaximum });\n }\n return candidates.sort((left, right) =>\n left.value - right.value || Number(right.exclusive) - Number(left.exclusive)\n )[0];\n}\n\nfunction stricterLower(\n left: NumericBoundary | undefined,\n right: NumericBoundary | undefined,\n): NumericBoundary | undefined {\n if (!left) return right;\n if (!right) return left;\n if (left.value !== right.value) return left.value > right.value ? left : right;\n return left.exclusive ? left : right;\n}\n\nfunction stricterUpper(\n left: NumericBoundary | undefined,\n right: NumericBoundary | undefined,\n): NumericBoundary | undefined {\n if (!left) return right;\n if (!right) return left;\n if (left.value !== right.value) return left.value < right.value ? left : right;\n return left.exclusive ? left : right;\n}\n\nfunction stricterMultipleOf(\n left: number | undefined,\n right: number | undefined,\n): number | undefined {\n if (left === undefined) return right;\n if (right === undefined || Object.is(left, right)) return left;\n if (left > 0 && right > 0) {\n const leftRatio = left / right;\n if (Number.isInteger(leftRatio)) return left;\n const rightRatio = right / left;\n if (Number.isInteger(rightRatio)) return right;\n }\n return undefined;\n}\n\nfunction mergeSchema(left: JsonSchemaObject, right: JsonSchemaObject): SchemaIntersection {\n for (const key of Object.keys(left)) {\n if (\n hasOwn(right, key) &&\n !COMPOSED_KEYWORDS.has(key) &&\n !key.startsWith(\"x-formadapter\") &&\n !sameValue(left[key], right[key])\n ) {\n return { error: `Cannot safely combine conflicting allOf keyword “${key}”` };\n }\n }\n\n const types = intersectTypes(explicitTypes(left), explicitTypes(right));\n if (types?.length === 0) {\n return { error: \"The allOf branches require incompatible JSON Schema types\" };\n }\n\n let values = intersectValues(constrainedValues(left), constrainedValues(right));\n if (values && types) {\n values = values.filter((value) => types.some((type) => valueMatchesType(value, type)));\n }\n if (values?.length === 0) {\n return { error: \"The allOf branches have no allowed values in common\" };\n }\n\n if (\n left.pattern !== undefined &&\n right.pattern !== undefined &&\n left.pattern !== right.pattern\n ) {\n return { error: \"Multiple different patterns in allOf cannot be represented by one form control\" };\n }\n if (\n left.format !== undefined &&\n right.format !== undefined &&\n left.format !== right.format\n ) {\n return { error: \"Conflicting formats in allOf cannot be represented by one form control\" };\n }\n\n const multipleOf = stricterMultipleOf(left.multipleOf, right.multipleOf);\n if (\n left.multipleOf !== undefined &&\n right.multipleOf !== undefined &&\n multipleOf === undefined\n ) {\n return { error: \"Different multipleOf constraints in allOf cannot be represented safely\" };\n }\n\n const minimum = stricterLower(lowerBoundary(left), lowerBoundary(right));\n const maximum = stricterUpper(upperBoundary(left), upperBoundary(right));\n if (\n minimum &&\n maximum &&\n (minimum.value > maximum.value ||\n (minimum.value === maximum.value && (minimum.exclusive || maximum.exclusive)))\n ) {\n return { error: \"The allOf numeric constraints cannot be satisfied\" };\n }\n\n const minLength = Math.max(left.minLength ?? 0, right.minLength ?? 0);\n const maxLength = Math.min(left.maxLength ?? Number.POSITIVE_INFINITY, right.maxLength ?? Number.POSITIVE_INFINITY);\n if (minLength > maxLength) {\n return { error: \"The allOf string-length constraints cannot be satisfied\" };\n }\n const minItems = Math.max(left.minItems ?? 0, right.minItems ?? 0);\n const maxItems = Math.min(left.maxItems ?? Number.POSITIVE_INFINITY, right.maxItems ?? Number.POSITIVE_INFINITY);\n if (minItems > maxItems) {\n return { error: \"The allOf array-length constraints cannot be satisfied\" };\n }\n\n const definitions = mergeDefinitions(left.definitions, right.definitions, \"definitions\");\n if (definitions.error) return { error: definitions.error };\n const defs = mergeDefinitions(left.$defs, right.$defs, \"$defs\");\n if (defs.error) return { error: defs.error };\n\n const leftProperties = new Set(Object.keys(left.properties ?? {}));\n const rightProperties = new Set(Object.keys(right.properties ?? {}));\n if (\n (left.additionalProperties === false &&\n [...rightProperties].some((key) => !leftProperties.has(key))) ||\n (right.additionalProperties === false &&\n [...leftProperties].some((key) => !rightProperties.has(key)))\n ) {\n return {\n error: \"Closed object branches in allOf declare incompatible property sets\",\n };\n }\n\n const merged = { ...left, ...right } as Record<string, unknown>;\n delete merged.type;\n if (types) merged.type = types.length === 1 ? types[0] : types;\n\n delete merged.const;\n delete merged.enum;\n if (values) {\n const usesConst = hasOwn(left, \"const\") || hasOwn(right, \"const\");\n if (usesConst && values.length === 1) merged.const = values[0];\n else merged.enum = values;\n }\n\n const properties = mergeSchemaMap(left.properties, right.properties);\n if (properties) merged.properties = properties;\n const patternProperties = mergeSchemaMap(left.patternProperties, right.patternProperties);\n if (patternProperties) merged.patternProperties = patternProperties;\n if (left.required || right.required) {\n merged.required = [...new Set([...(left.required ?? []), ...(right.required ?? [])])];\n }\n\n if (hasOwn(left, \"additionalProperties\") && hasOwn(right, \"additionalProperties\")) {\n merged.additionalProperties = intersectSchemaValue(\n left.additionalProperties!,\n right.additionalProperties!,\n );\n }\n if (hasOwn(left, \"propertyNames\") && hasOwn(right, \"propertyNames\")) {\n merged.propertyNames = intersectSchemaValue(left.propertyNames!, right.propertyNames!);\n }\n if (hasOwn(left, \"items\") && hasOwn(right, \"items\")) {\n if (Array.isArray(left.items) || Array.isArray(right.items)) {\n if (!sameValue(left.items, right.items)) {\n return { error: \"Different tuple item schemas in allOf cannot be represented safely\" };\n }\n } else {\n merged.items = intersectSchemaValue(\n left.items as JsonSchema,\n right.items as JsonSchema,\n );\n }\n }\n\n const allOf = [...(left.allOf ?? []), ...(right.allOf ?? [])];\n if (allOf.length > 0) merged.allOf = allOf;\n else delete merged.allOf;\n\n delete merged.minimum;\n delete merged.exclusiveMinimum;\n if (minimum) merged[minimum.exclusive ? \"exclusiveMinimum\" : \"minimum\"] = minimum.value;\n delete merged.maximum;\n delete merged.exclusiveMaximum;\n if (maximum) merged[maximum.exclusive ? \"exclusiveMaximum\" : \"maximum\"] = maximum.value;\n\n delete merged.minLength;\n delete merged.maxLength;\n if (left.minLength !== undefined || right.minLength !== undefined) merged.minLength = minLength;\n if (maxLength !== Number.POSITIVE_INFINITY) merged.maxLength = maxLength;\n delete merged.minItems;\n delete merged.maxItems;\n if (left.minItems !== undefined || right.minItems !== undefined) merged.minItems = minItems;\n if (maxItems !== Number.POSITIVE_INFINITY) merged.maxItems = maxItems;\n if (multipleOf !== undefined) merged.multipleOf = multipleOf;\n\n if (left.uniqueItems !== undefined || right.uniqueItems !== undefined) {\n merged.uniqueItems = left.uniqueItems === true || right.uniqueItems === true;\n }\n if (left.readOnly !== undefined || right.readOnly !== undefined) {\n merged.readOnly = left.readOnly === true || right.readOnly === true;\n }\n if (hasOwn(left, \"writeOnly\") || hasOwn(right, \"writeOnly\")) {\n merged.writeOnly = left.writeOnly === true || right.writeOnly === true;\n }\n if (definitions.definitions) merged.definitions = definitions.definitions;\n if (defs.definitions) merged.$defs = defs.definitions;\n\n return { schema: merged as JsonSchemaObject };\n}\n\nfunction schemaChildren(schema: JsonSchemaObject): readonly JsonSchema[] {\n const children: JsonSchema[] = [];\n children.push(...Object.values(schema.properties ?? {}));\n children.push(...Object.values(schema.patternProperties ?? {}));\n for (const keyword of [\"additionalProperties\", \"propertyNames\"] as const) {\n const child = schema[keyword];\n if (typeof child === \"boolean\" || isSchemaObject(child)) children.push(child);\n }\n if (Array.isArray(schema.items)) children.push(...schema.items);\n else if (typeof schema.items === \"boolean\" || isSchemaObject(schema.items)) children.push(schema.items);\n children.push(...(schema.prefixItems ?? []));\n children.push(...(schema.allOf ?? []), ...(schema.anyOf ?? []), ...(schema.oneOf ?? []));\n return children;\n}\n\nfunction referenceIsRecursive(\n root: JsonSchemaObject,\n reference: string,\n): boolean {\n const target = pointerValue(root, reference);\n if (target === undefined) return false;\n const visitedObjects = new Set<JsonSchemaObject>();\n const visitedReferences = new Set<string>();\n const visit = (schema: JsonSchema): boolean => {\n if (!isSchemaObject(schema)) return false;\n if (schema.$ref) {\n if (schema.$ref === reference) return true;\n if (visitedReferences.has(schema.$ref)) return false;\n visitedReferences.add(schema.$ref);\n const nested = pointerValue(root, schema.$ref);\n if (nested !== undefined && visit(nested)) return true;\n }\n if (visitedObjects.has(schema)) return false;\n visitedObjects.add(schema);\n return schemaChildren(schema).some(visit);\n };\n return visit(target);\n}\n\nfunction resolveSchema<Input, Control extends string>(\n schema: JsonSchema,\n context: CompileContext<Input, Control>,\n): { schema: JsonSchema; context: CompileContext<Input, Control>; error?: string } {\n if (!isSchemaObject(schema) || !schema.$ref) return { schema, context };\n const reference = schema.$ref;\n if (context.resolvingRefs.has(reference) && referenceIsRecursive(context.rootSchema, reference)) {\n return { schema, context, error: `Circular JSON Schema reference “${reference}”` };\n }\n const target = pointerValue(context.rootSchema, reference);\n if (target === undefined) {\n return { schema, context, error: `Unresolved JSON Schema reference “${reference}”` };\n }\n const nextContext: CompileContext<Input, Control> = {\n ...context,\n resolvingRefs: new Set([...context.resolvingRefs, reference]),\n };\n const { $ref: _ignored, ...siblings } = schema;\n if (target === false) return { schema: false, context: nextContext };\n if (target === true) {\n return Object.keys(siblings).length === 0\n ? { schema: true, context: nextContext }\n : { schema: siblings, context: nextContext };\n }\n const resolvedTarget = target.$ref\n ? resolveSchema(target, nextContext)\n : { schema: target as JsonSchema, context: nextContext };\n if (resolvedTarget.error || resolvedTarget.schema === false) return resolvedTarget;\n if (resolvedTarget.schema === true) {\n return Object.keys(siblings).length === 0\n ? resolvedTarget\n : { schema: siblings, context: resolvedTarget.context };\n }\n if (Object.keys(siblings).length === 0) return resolvedTarget;\n const merged = mergeSchema(resolvedTarget.schema, siblings);\n return merged.error\n ? { schema, context, error: merged.error }\n : { schema: merged.schema!, context: resolvedTarget.context };\n}\n\nfunction collapseAllOf<Input, Control extends string>(\n schema: JsonSchemaObject,\n context: CompileContext<Input, Control>,\n): {\n schema: JsonSchemaObject;\n context: CompileContext<Input, Control>;\n error?: string;\n} {\n if (!schema.allOf || schema.allOf.length === 0) return { schema, context };\n const { allOf, ...base } = schema;\n let merged = base;\n const resolvingRefs = new Set(context.resolvingRefs);\n\n for (const branch of allOf) {\n const resolved = resolveSchema(branch, context);\n if (resolved.error) return { schema: merged, context, error: resolved.error };\n if (resolved.schema === false) {\n return {\n schema: merged,\n context,\n error: \"An allOf branch can never be valid\",\n };\n }\n if (resolved.schema === true) continue;\n\n const collapsed = collapseAllOf(resolved.schema, resolved.context);\n if (collapsed.error) return collapsed;\n const intersection = mergeSchema(merged, collapsed.schema);\n if (intersection.error) {\n return { schema: merged, context, error: intersection.error };\n }\n merged = intersection.schema!;\n for (const reference of collapsed.context.resolvingRefs) {\n resolvingRefs.add(reference);\n }\n }\n\n return {\n schema: merged,\n context: { ...context, resolvingRefs },\n };\n}\n\nfunction primitive(value: unknown): value is JsonPrimitive {\n return value === null || [\"string\", \"number\", \"boolean\"].includes(typeof value);\n}\n\nfunction optionsFromSchema(schema: JsonSchemaObject): readonly FormOption[] | undefined {\n const raw = schema.enum ?? (schema.const !== undefined ? [schema.const] : undefined);\n if (!raw || !raw.every(primitive)) return undefined;\n return raw.map((value) => ({ label: humanize(String(value)), value }));\n}\n\nfunction optionsFromUnion<Input, Control extends string>(\n branches: readonly JsonSchema[],\n context: CompileContext<Input, Control>,\n exclusive: boolean,\n): readonly FormOption[] | undefined {\n const options: FormOption[] = [];\n for (const branch of branches) {\n const resolved = resolveSchema(branch, context);\n if (resolved.error || resolved.schema === true) return undefined;\n if (resolved.schema === false) continue;\n const collapsed = collapseAllOf(resolved.schema, resolved.context);\n if (collapsed.error) return undefined;\n const branchOptions = optionsFromSchema(collapsed.schema);\n if (!branchOptions) return undefined;\n for (const option of branchOptions) {\n const duplicate = options.some((existing) => Object.is(existing.value, option.value));\n if (duplicate) {\n if (exclusive) return undefined;\n continue;\n }\n options.push({\n label: collapsed.schema.title ?? option.label,\n value: option.value,\n });\n }\n }\n return options;\n}\n\nfunction mediaTypesFromUnion<Input, Control extends string>(\n branches: readonly JsonSchema[],\n context: CompileContext<Input, Control>,\n): readonly string[] | undefined {\n const mediaTypes: string[] = [];\n for (const branch of branches) {\n const resolved = resolveSchema(branch, context);\n if (resolved.error || !isSchemaObject(resolved.schema)) return undefined;\n const collapsed = collapseAllOf(resolved.schema, resolved.context);\n if (collapsed.error || typeof collapsed.schema.contentMediaType !== \"string\") {\n return undefined;\n }\n const unsupportedKeyword = Object.keys(collapsed.schema).find((key) =>\n ![\n \"$comment\",\n \"contentMediaType\",\n \"deprecated\",\n \"description\",\n \"readOnly\",\n \"title\",\n \"writeOnly\",\n ].includes(key)\n );\n if (unsupportedKeyword) return undefined;\n if (!mediaTypes.includes(collapsed.schema.contentMediaType)) {\n mediaTypes.push(collapsed.schema.contentMediaType);\n }\n }\n return mediaTypes.length > 0 ? mediaTypes : undefined;\n}\n\ninterface ObjectUnionRule {\n readonly visibleFor: readonly JsonPrimitive[];\n readonly requiredFor: readonly JsonPrimitive[];\n}\n\ninterface NormalizedObjectUnion {\n readonly discriminator: string;\n readonly rules: Readonly<Record<string, ObjectUnionRule>>;\n readonly schema: JsonSchemaObject;\n}\n\nfunction sameSchema(left: JsonSchema, right: JsonSchema): boolean {\n return sameValue(left, right);\n}\n\nfunction normalizedObjectUnion<Input, Control extends string>(\n branches: readonly JsonSchema[],\n context: CompileContext<Input, Control>,\n): NormalizedObjectUnion | undefined {\n const objects: JsonSchemaObject[] = [];\n for (const branch of branches) {\n const resolved = resolveSchema(branch, context);\n if (resolved.error || !isSchemaObject(resolved.schema)) return undefined;\n const collapsed = collapseAllOf(resolved.schema, resolved.context);\n if (collapsed.error || !schemaTypes(collapsed.schema).includes(\"object\")) {\n return undefined;\n }\n objects.push(collapsed.schema);\n }\n if (objects.length < 2) return undefined;\n\n const commonKeys = Object.keys(objects[0]?.properties ?? {}).filter((key) =>\n objects.every((branch) => hasOwn(branch.properties ?? {}, key))\n );\n const discriminator = commonKeys.find((key) => {\n const values = objects.map((branch) => {\n const property = branch.properties?.[key];\n if (property === undefined || !isSchemaObject(property)) return undefined;\n const options = optionsFromSchema(property);\n return options?.length === 1 ? options[0]?.value : undefined;\n });\n return values.every((value) => value !== undefined) &&\n new Set(values.map((value) => JSON.stringify(value))).size === values.length;\n });\n if (!discriminator) return undefined;\n\n const discriminatorValues = objects.map((branch) => {\n const property = branch.properties?.[discriminator];\n return optionsFromSchema(property as JsonSchemaObject)?.[0]?.value;\n }) as JsonPrimitive[];\n const propertyNames = [...new Set(\n objects.flatMap((branch) => Object.keys(branch.properties ?? {})),\n )];\n const properties = createNullRecord<JsonSchema>();\n const rules = createNullRecord<ObjectUnionRule>();\n\n for (const propertyName of propertyNames) {\n const schemas = objects.flatMap((branch) => {\n const property = branch.properties?.[propertyName];\n return property === undefined ? [] : [property];\n });\n if (propertyName === discriminator) {\n const initial = schemas[0];\n const first: JsonSchemaObject = initial !== undefined && isSchemaObject(initial)\n ? initial\n : {};\n const { const: _const, ...withoutConst } = first;\n defineOwn(properties, propertyName, {\n ...withoutConst,\n enum: discriminatorValues,\n });\n } else {\n const first = schemas[0]!;\n defineOwn(\n properties,\n propertyName,\n schemas.every((candidate) => sameSchema(first, candidate))\n ? first\n : { anyOf: schemas },\n );\n }\n\n const visibleFor: JsonPrimitive[] = [];\n const requiredFor: JsonPrimitive[] = [];\n for (const [index, branch] of objects.entries()) {\n if (branch.properties?.[propertyName] !== undefined) {\n visibleFor.push(discriminatorValues[index]!);\n }\n if (branch.required?.includes(propertyName)) {\n requiredFor.push(discriminatorValues[index]!);\n }\n }\n defineOwn(rules, propertyName, { requiredFor, visibleFor });\n }\n\n const required = propertyNames.filter((propertyName) =>\n objects.every((branch) => branch.required?.includes(propertyName))\n );\n return {\n discriminator,\n rules,\n schema: {\n properties,\n required,\n type: \"object\",\n },\n };\n}\n\nfunction runtimePathValue(values: unknown, path: string): unknown {\n return path.split(\".\").reduce<unknown>((current, segment) => {\n return isRecord(current) ? ownValue(current, segment) : undefined;\n }, values);\n}\n\nfunction stateValue<Values>(state: FieldState<Values>, values: Values): boolean {\n return typeof state === \"function\"\n ? state(values as Readonly<import(\"./path\").DeepPartial<Values>>)\n : state;\n}\n\nfunction extensionConfig(schema: JsonSchemaObject): Readonly<Record<string, unknown>> {\n const nested = isRecord(schema[\"x-formadapter\"])\n ? schema[\"x-formadapter\"]\n : {};\n const flat = createNullRecord<unknown>();\n const prefix = \"x-formadapter-\";\n for (const [key, value] of Object.entries(schema)) {\n if (key.startsWith(prefix)) defineOwn(flat, key.slice(prefix.length), value);\n }\n return { ...nested, ...flat };\n}\n\nfunction fieldOverride<Input, Control extends string>(\n path: string,\n config: FormConfig<Input, Control>,\n): FieldConfig<Control, Input> | undefined {\n const fields = config.fields as\n | Readonly<Record<string, FieldConfig<Control, Input> | undefined>>\n | undefined;\n return fields && hasOwn(fields, path) ? fields[path] : undefined;\n}\n\nfunction stringValue(value: unknown): string | undefined {\n return typeof value === \"string\" ? value : undefined;\n}\n\nfunction numberValue(value: unknown): number | undefined {\n return typeof value === \"number\" && Number.isFinite(value) ? value : undefined;\n}\n\nfunction booleanValue(value: unknown): boolean | undefined {\n return typeof value === \"boolean\" ? value : undefined;\n}\n\nfunction resolvedConfig<Input, Control extends string>(\n schema: JsonSchemaObject,\n override: FieldConfig<Control, Input> | undefined,\n): ResolvedFieldConfig<Control, Input> {\n const extensions = extensionConfig(schema);\n const control = override?.control ?? stringValue(extensions.control);\n const placeholder = override?.placeholder ?? stringValue(extensions.placeholder);\n const order = override?.order ?? numberValue(extensions.order);\n const className =\n override?.className ??\n stringValue(extensions.className ?? extensions[\"class-name\"]);\n return {\n ...(control !== undefined\n ? { control: control as BuiltInControl | Control }\n : {}),\n ...(placeholder !== undefined ? { placeholder } : {}),\n hidden: override?.hidden ?? booleanValue(extensions.hidden) ?? false,\n disabled: override?.disabled ?? booleanValue(extensions.disabled) ?? false,\n readOnly:\n override?.readOnly ??\n booleanValue(extensions.readonly ?? extensions.readOnly) ??\n schema.readOnly ??\n false,\n ...(order !== undefined ? { order } : {}),\n ...(className !== undefined ? { className } : {}),\n ...(override?.controlProps ? { controlProps: override.controlProps } : {}),\n multiple: override?.multiple ?? booleanValue(extensions.multiple) ?? false,\n ...(override?.options ? { options: override.options } : {}),\n requiredWhenVisible:\n override?.requiredWhenVisible ??\n booleanValue(extensions.requiredWhenVisible ?? extensions[\"required-when-visible\"]) ??\n false,\n ...(override?.requiredMessage ? { requiredMessage: override.requiredMessage } : {}),\n ...(override?.asyncValidate !== undefined\n ? { asyncValidate: override.asyncValidate as NonNullable<ResolvedFieldConfig<Control, Input>[\"asyncValidate\"]> }\n : {}),\n asyncValidationDebounceMs: Math.max(\n 0,\n override?.asyncValidationDebounceMs ?? 250,\n ),\n ...(override?.array ? { array: override.array } : {}),\n extensions,\n };\n}\n\nfunction schemaTypes(schema: JsonSchemaObject): readonly string[] {\n if (typeof schema.type === \"string\") return [schema.type];\n if (Array.isArray(schema.type)) {\n const types = [...new Set(schema.type)];\n return types.includes(\"number\")\n ? types.filter((type) => type !== \"integer\")\n : types;\n }\n if (schema.properties) return [\"object\"];\n if (schema.items) return [\"array\"];\n if (schema.const !== undefined) {\n if (schema.const === null) return [\"null\"];\n return [typeof schema.const];\n }\n if (schema.enum?.length) {\n return [...new Set(schema.enum.map((value) => (value === null ? \"null\" : typeof value)))];\n }\n return [];\n}\n\nfunction inferControl(\n dataType: FieldDataType,\n schema: JsonSchemaObject,\n options: readonly FormOption[] | undefined,\n): BuiltInControl {\n if (dataType === \"boolean\") return \"checkbox\";\n if (options !== undefined) return \"select\";\n if (dataType === \"number\" || dataType === \"integer\") return \"number\";\n if (dataType === \"file\") return \"file\";\n switch (schema.format) {\n case \"date\": return \"date\";\n // RFC 3339 date-times include offset semantics that datetime-local drops.\n // Consumers can explicitly opt into datetime-local when they own conversion.\n case \"date-time\": return \"text\";\n case \"email\": return \"email\";\n case \"password\": return \"password\";\n case \"tel\": return \"tel\";\n case \"time\": return \"time\";\n case \"uri\":\n case \"url\": return \"url\";\n default: return \"text\";\n }\n}\n\nconst NATIVE_INPUT_TYPES = new Set<NativeInputType>([\n \"checkbox\",\n \"date\",\n \"datetime-local\",\n \"email\",\n \"file\",\n \"hidden\",\n \"number\",\n \"password\",\n \"range\",\n \"search\",\n \"tel\",\n \"text\",\n \"time\",\n \"url\",\n]);\n\nfunction inputType(control: string): NativeInputType | undefined {\n return NATIVE_INPUT_TYPES.has(control as NativeInputType)\n ? control as NativeInputType\n : undefined;\n}\n\nfunction constraints(\n schema: JsonSchemaObject,\n config: ResolvedFieldConfig<string, unknown>,\n acceptedMediaTypes?: readonly string[],\n): ScalarConstraints {\n return {\n ...(schema.format ? { format: schema.format } : {}),\n ...(schema.minLength !== undefined ? { minLength: schema.minLength } : {}),\n ...(schema.maxLength !== undefined ? { maxLength: schema.maxLength } : {}),\n ...(schema.pattern ? { pattern: schema.pattern } : {}),\n ...(schema.minimum !== undefined ? { minimum: schema.minimum } : {}),\n ...(schema.maximum !== undefined ? { maximum: schema.maximum } : {}),\n ...(schema.exclusiveMinimum !== undefined\n ? { exclusiveMinimum: schema.exclusiveMinimum }\n : {}),\n ...(schema.exclusiveMaximum !== undefined\n ? { exclusiveMaximum: schema.exclusiveMaximum }\n : {}),\n ...(schema.multipleOf !== undefined ? { multipleOf: schema.multipleOf } : {}),\n ...(acceptedMediaTypes?.length\n ? { accept: acceptedMediaTypes.join(\",\") }\n : schema.contentMediaType\n ? { accept: schema.contentMediaType }\n : {}),\n multiple: config.multiple,\n ...(schema.contentEncoding ? { contentEncoding: schema.contentEncoding } : {}),\n ...(schema.contentMediaType ? { contentMediaType: schema.contentMediaType } : {}),\n };\n}\n\nfunction isFileSchema(schema: JsonSchemaObject): boolean {\n return schema.format === \"binary\" ||\n schema.contentEncoding === \"binary\" ||\n schema.contentMediaType !== undefined;\n}\n\nfunction nonNullUnionBranch<Input, Control extends string>(\n branch: JsonSchema,\n context: CompileContext<Input, Control>,\n): { readonly branch?: JsonSchema; readonly nullable: boolean } {\n const resolved = resolveSchema(branch, context);\n if (resolved.error) return { branch, nullable: false };\n if (resolved.schema === false) return { nullable: false };\n if (resolved.schema === true) return { branch: true, nullable: false };\n const collapsed = collapseAllOf(resolved.schema, resolved.context);\n if (collapsed.error) return { branch, nullable: false };\n const schema = collapsed.schema;\n const types = schemaTypes(schema);\n if (!types.includes(\"null\")) return { branch, nullable: false };\n\n const nonNullTypes = types.filter((type) => type !== \"null\");\n if (nonNullTypes.length === 0) return { nullable: true };\n if (Array.isArray(schema.type)) {\n return {\n branch: {\n ...schema,\n type: schema.type.filter((type) => type !== \"null\"),\n },\n nullable: true,\n };\n }\n if (schema.enum) {\n return {\n branch: {\n ...schema,\n enum: schema.enum.filter((value) => value !== null),\n },\n nullable: true,\n };\n }\n return { branch, nullable: true };\n}\n\nfunction unsupported<Input, Control extends string>(\n input: NodeInput<Input, Control>,\n schema: JsonSchema,\n reason: string,\n): FormNode<Control, Input> {\n const objectSchema = isSchemaObject(schema) ? schema : {};\n const override = fieldOverride(input.path, input.context.config);\n return {\n kind: \"unsupported\",\n key: input.key,\n path: input.path,\n label: override?.label ?? objectSchema.title ?? input.labelFallback,\n ...(override?.description ?? objectSchema.description\n ? { description: override?.description ?? objectSchema.description }\n : {}),\n required: input.required,\n nullable: input.nullable ?? false,\n ...(override?.defaultValue ?? objectSchema.default !== undefined\n ? { defaultValue: override?.defaultValue ?? objectSchema.default }\n : {}),\n config: resolvedConfig(objectSchema, override),\n source: schema,\n reason,\n };\n}\n\nfunction compileNode<Input, Control extends string>(\n input: NodeInput<Input, Control>,\n): FormNode<Control, Input> {\n const resolved = resolveSchema(input.schema, input.context);\n if (resolved.error) return unsupported(input, input.schema, resolved.error);\n if (resolved.schema === false) return unsupported(input, false, \"This field can never be valid\");\n if (resolved.schema === true) return unsupported(input, true, \"The schema does not describe a renderable field\");\n\n const collapsed = collapseAllOf(resolved.schema, resolved.context);\n if (collapsed.error) {\n return unsupported(input, resolved.schema, collapsed.error);\n }\n let schema = collapsed.schema;\n const nodeContext = collapsed.context;\n if (schema.enum?.length === 0) {\n return unsupported(input, schema, \"An empty enum can never be valid\");\n }\n if (Array.isArray(schema.type) && schema.type.length === 0) {\n return unsupported(input, schema, \"An empty type union can never be valid\");\n }\n const union = schema.oneOf ?? schema.anyOf;\n let nullable = input.nullable ?? false;\n let unionOptions: readonly FormOption[] | undefined;\n let objectUnion: NormalizedObjectUnion | undefined;\n let acceptedMediaTypes: readonly string[] | undefined;\n if (union) {\n if (union.length === 0) {\n return unsupported(input, schema, \"An empty union can never be valid\");\n }\n const classified = union.map((branch) => nonNullUnionBranch(branch, nodeContext));\n const nonNull = classified.flatMap((entry) =>\n entry.branch === undefined ? [] : [entry.branch]\n );\n nullable ||= classified.some((entry) => entry.nullable);\n acceptedMediaTypes = isFileSchema(schema) && schema.anyOf !== undefined\n ? mediaTypesFromUnion(nonNull, nodeContext)\n : undefined;\n objectUnion = acceptedMediaTypes\n ? undefined\n : normalizedObjectUnion(nonNull, nodeContext);\n if (acceptedMediaTypes) {\n const { oneOf: _one, anyOf: _any, ...withoutUnion } = schema;\n schema = withoutUnion;\n } else if (objectUnion) {\n if (input.path.includes(\"[]\")) {\n return unsupported(\n input,\n schema,\n \"Discriminated object unions inside arrays are not supported yet\",\n );\n }\n const { oneOf: _one, anyOf: _any, ...withoutUnion } = schema;\n const intersection = mergeSchema(withoutUnion, objectUnion.schema);\n if (intersection.error) return unsupported(input, schema, intersection.error);\n schema = intersection.schema!;\n } else if (nonNull.length === 1 && isSchemaObject(nonNull[0]!)) {\n const { oneOf: _one, anyOf: _any, ...withoutUnion } = schema;\n const resolvedBranch = resolveSchema(nonNull[0]!, nodeContext);\n if (resolvedBranch.error) return unsupported(input, schema, resolvedBranch.error);\n if (resolvedBranch.schema === false) {\n return unsupported(input, schema, \"This union cannot be valid\");\n }\n if (resolvedBranch.schema === true) {\n return unsupported(input, schema, \"An unconstrained union cannot be represented as one form control\");\n }\n const collapsedBranch = collapseAllOf(resolvedBranch.schema, resolvedBranch.context);\n if (collapsedBranch.error) return unsupported(input, schema, collapsedBranch.error);\n const intersection = mergeSchema(withoutUnion, collapsedBranch.schema);\n if (intersection.error) return unsupported(input, schema, intersection.error);\n schema = intersection.schema!;\n } else {\n unionOptions = optionsFromUnion(nonNull, nodeContext, schema.oneOf !== undefined);\n if (!unionOptions || unionOptions.length === 0) {\n return unsupported(input, schema, \"This union cannot be represented as one form control\");\n }\n const { oneOf: _one, anyOf: _any, ...withoutUnion } = schema;\n schema = {\n ...withoutUnion,\n enum: unionOptions.map((option) => option.value),\n };\n }\n }\n\n const types = schemaTypes(schema).filter((type) => type !== \"null\");\n nullable ||= schemaTypes(schema).includes(\"null\");\n const type = types.length === 1 ? types[0] : undefined;\n const override = fieldOverride(input.path, input.context.config);\n const extensions = extensionConfig(schema);\n const label =\n override?.label ??\n schema.title ??\n stringValue(extensions.label) ??\n input.labelFallback;\n const description = override?.description ?? schema.description ?? stringValue(extensions.description);\n const defaultValue = override?.defaultValue ?? schema.default;\n const config = resolvedConfig(schema, override);\n const common = {\n key: input.key,\n path: input.path,\n label,\n ...(description ? { description } : {}),\n required: input.required,\n nullable,\n ...(defaultValue !== undefined ? { defaultValue } : {}),\n config,\n source: schema,\n };\n\n if (type === \"object\") {\n const hasProperties = Object.keys(schema.properties ?? {}).length > 0;\n const hasDynamicProperties =\n schema.additionalProperties === true ||\n isSchemaObject(schema.additionalProperties ?? false) ||\n Object.keys(schema.patternProperties ?? {}).length > 0 ||\n (!hasProperties && schema.propertyNames !== undefined);\n if (hasDynamicProperties) {\n return unsupported(\n input,\n schema,\n \"Dynamic record keys are not supported yet\",\n );\n }\n const required = new Set(schema.required ?? []);\n const children = Object.entries(schema.properties ?? {}).map(([key, child]) => {\n const path = input.path ? `${input.path}.${key}` : key;\n const childInput = {\n context: nodeContext,\n key,\n labelFallback: humanize(key),\n path,\n required: required.has(key),\n schema: child,\n } satisfies NodeInput<Input, Control>;\n const invalidPath = formPathSegmentError(key);\n const compiled = invalidPath\n ? unsupported(childInput, child, invalidPath)\n : compileNode(childInput);\n const unionInfo = objectUnion;\n const rule = unionInfo?.rules[key];\n if (!unionInfo || !rule || path.includes(\"[]\")) return compiled;\n const discriminatorPath = input.path\n ? `${input.path}.${unionInfo.discriminator}`\n : unionInfo.discriminator;\n const existingHidden = compiled.config.hidden;\n const existingRequired = compiled.config.requiredWhenVisible;\n return {\n ...compiled,\n config: {\n ...compiled.config,\n hidden: (values: Readonly<import(\"./path\").DeepPartial<Input>>) => {\n const selected = runtimePathValue(values, discriminatorPath);\n const branchCount = unionInfo.rules[unionInfo.discriminator]?.visibleFor.length ?? 0;\n const branchHidden = rule.visibleFor.length < branchCount &&\n !rule.visibleFor.some((value) => Object.is(value, selected));\n return stateValue(existingHidden, values as Input) || branchHidden;\n },\n requiredWhenVisible: (\n values: Readonly<import(\"./path\").DeepPartial<Input>>,\n ) => {\n const selected = runtimePathValue(values, discriminatorPath);\n const branchRequired = rule.requiredFor.some((value) => Object.is(value, selected));\n return stateValue(existingRequired, values as Input) || branchRequired;\n },\n },\n };\n }).sort((left, right) => {\n return (left.config.order ?? Number.MAX_SAFE_INTEGER) -\n (right.config.order ?? Number.MAX_SAFE_INTEGER);\n });\n return { kind: \"object\", ...common, children };\n }\n\n if (type === \"array\") {\n const itemSchema = schema.items;\n if (Array.isArray(itemSchema) || schema.prefixItems) {\n return unsupported(input, schema, \"Tuple schemas are not supported yet\");\n }\n if (!itemSchema) return unsupported(input, schema, \"Array schema is missing its item schema\");\n const itemPath = `${input.path}[]`;\n const item = compileNode({\n context: nodeContext,\n key: input.key,\n labelFallback: `${label} item`,\n path: itemPath,\n required: true,\n schema: itemSchema as JsonSchema,\n });\n return {\n kind: \"array\",\n ...common,\n item,\n ...(schema.minItems !== undefined ? { minItems: schema.minItems } : {}),\n ...(schema.maxItems !== undefined ? { maxItems: schema.maxItems } : {}),\n uniqueItems: schema.uniqueItems ?? false,\n };\n }\n\n const configuredOptions = Array.isArray(override?.options)\n ? override.options as readonly FormOption[]\n : undefined;\n const hasDynamicOptions = typeof override?.options === \"function\";\n let options = configuredOptions ?? unionOptions ?? optionsFromSchema(schema);\n const isFile = isFileSchema(schema) || acceptedMediaTypes !== undefined;\n if (isFile && config.multiple) {\n return unsupported(\n input,\n schema,\n \"Multiple file selection requires an array-of-files schema\",\n );\n }\n const dataType: FieldDataType = isFile\n ? \"file\"\n : type === \"string\" || type === \"number\" || type === \"integer\" || type === \"boolean\"\n ? type\n : \"unknown\";\n if (nullable && options && !options.some((option) => option.value === null)) {\n options = [...options, { label: \"None\", value: null }];\n }\n if (nullable && dataType === \"boolean\" && !options) {\n options = [\n { label: \"Yes\", value: true },\n { label: \"No\", value: false },\n { label: \"None\", value: null },\n ];\n }\n if (dataType === \"unknown\" && !options) {\n return unsupported(input, schema, `Unsupported JSON Schema type “${type ?? \"unknown\"}”`);\n }\n const control =\n config.control ??\n (hasDynamicOptions\n ? \"select\"\n : nullable && dataType === \"boolean\"\n ? \"select\"\n : inferControl(dataType, schema, options));\n const nativeType = inputType(control);\n return {\n kind: \"scalar\",\n ...common,\n dataType,\n control,\n ...(nativeType ? { inputType: nativeType } : {}),\n constraints: constraints(\n schema,\n config as ResolvedFieldConfig<string, unknown>,\n acceptedMediaTypes,\n ),\n ...(options ? { options } : {}),\n };\n}\n\nfunction collectFields<Control extends string, Input>(\n node: FormNode<Control, Input>,\n target: Record<string, FormNode<Control, Input>>,\n): void {\n if (node.path) defineOwn(target, node.path, node);\n if (node.kind === \"object\") {\n for (const child of node.children) collectFields(child, target);\n } else if (node.kind === \"array\") {\n collectFields(node.item, target);\n }\n}\n\nfunction arkTypeLibraryOptions(\n schema: FormSchema,\n config: FormConfig<unknown, string>,\n): Readonly<Record<string, unknown>> | undefined {\n const configured = config.jsonSchema?.libraryOptions;\n if (schema[\"~standard\"].vendor !== \"arktype\" || config.jsonSchema?.opaqueRefinements === \"error\") {\n return configured;\n }\n const existingFallback = isRecord(configured?.fallback) ? configured.fallback : {};\n return {\n ...configured,\n fallback: {\n ...existingFallback,\n predicate: (context: { readonly base: Record<string, unknown> }) => context.base,\n },\n };\n}\n\nexport function toInputJsonSchema<Schema extends FormSchema>(\n schema: Schema,\n config: FormConfig<InferInput<Schema>, string> = {},\n): JsonSchemaObject {\n try {\n const jsonSchema = schema[\"~standard\"].jsonSchema.input({\n target: \"draft-2020-12\",\n ...(arkTypeLibraryOptions(\n schema,\n config as FormConfig<unknown, string>,\n )\n ? { libraryOptions: arkTypeLibraryOptions(schema, config as FormConfig<unknown, string>) }\n : {}),\n });\n return jsonSchema as JsonSchemaObject;\n } catch (error) {\n throw new SchemaConversionError(\n `Unable to convert the ${schema[\"~standard\"].vendor} schema to JSON Schema for form inference.`,\n { cause: error },\n );\n }\n}\n\nexport function compileForm<\n Schema extends FormSchema,\n Control extends string = never,\n>(\n schema: Schema,\n config: FormConfig<InferInput<Schema>, Control> = {},\n): FormModel<InferInput<Schema>, Control> {\n const rootSchema = toInputJsonSchema(\n schema,\n config as FormConfig<InferInput<Schema>, string>,\n );\n const context: CompileContext<InferInput<Schema>, Control> = {\n config,\n rootSchema,\n resolvingRefs: new Set(),\n };\n const root = compileNode({\n context,\n key: \"root\",\n labelFallback: rootSchema.title ?? \"Form\",\n path: \"\",\n required: true,\n schema: rootSchema,\n });\n const fieldMap = createNullRecord<FormNode<Control, InferInput<Schema>>>();\n collectFields(root, fieldMap);\n return {\n root,\n fields: root.kind === \"object\" ? root.children : [root],\n fieldMap,\n };\n}\n","import type { DeepPartial } from \"./path\";\nimport { defineOwn } from \"./record\";\nimport type { FormModel, FormNode } from \"./types\";\n\nfunction cloneDefault(value: unknown): unknown {\n if (Array.isArray(value)) return value.map(cloneDefault);\n if (typeof value !== \"object\" || value === null) return value;\n if (value instanceof Date) return new Date(value.getTime());\n const prototype = Object.getPrototypeOf(value) as object | null;\n if (prototype !== Object.prototype && prototype !== null) return value;\n return Object.fromEntries(\n Object.entries(value).map(([key, child]) => [key, cloneDefault(child)]),\n );\n}\n\nexport function defaultValueForNode(\n node: FormNode<string, unknown>,\n): unknown {\n if (node.defaultValue !== undefined) return cloneDefault(node.defaultValue);\n if (!node.required) return undefined;\n\n switch (node.kind) {\n case \"array\": {\n const count = node.minItems ?? 0;\n return Array.from(\n { length: count },\n () => cloneDefault(defaultValueForNode(node.item)),\n );\n }\n case \"object\": {\n const value: Record<string, unknown> = {};\n for (const child of node.children) {\n const childDefault = defaultValueForNode(\n child as FormNode<string, unknown>,\n );\n if (childDefault !== undefined) defineOwn(value, child.key, childDefault);\n }\n return value;\n }\n case \"scalar\":\n if (node.dataType === \"boolean\") return false;\n if (node.dataType === \"string\" && node.required && !node.options) return \"\";\n return undefined;\n case \"unsupported\":\n return undefined;\n }\n}\n\nexport function getDefaultValues<Input, Control extends string>(\n model: FormModel<Input, Control>,\n): DeepPartial<Input> {\n const value = defaultValueForNode(\n model.root as FormNode<string, unknown>,\n );\n return (value ?? {}) as DeepPartial<Input>;\n}\n","import type { ReservedFormPathSegment } from \"./path-segment\";\n\ntype Primitive = string | number | boolean | bigint | symbol | null | undefined;\ntype FileLike = {\n readonly name: string;\n readonly size: number;\n readonly type: string;\n readonly lastModified: number;\n};\ntype Atomic =\n | Primitive\n | Date\n | RegExp\n | Error\n | Function\n | Promise<unknown>\n | Map<unknown, unknown>\n | Set<unknown>\n | ArrayBuffer\n | DataView\n | FileLike;\n\ntype IsAny<T> = 0 extends 1 & T ? true : false;\ntype IsTraversable<T> = IsAny<T> extends true\n ? false\n : NonNullable<T> extends Atomic\n ? false\n : NonNullable<T> extends object\n ? true\n : false;\ntype NextDepth<Depth extends readonly unknown[]> = [...Depth, 0];\ntype AtMaxDepth<Depth extends readonly unknown[]> = Depth[\"length\"] extends 8 ? true : false;\ntype Join<Prefix extends string, Key extends string> = Prefix extends \"\"\n ? Key\n : `${Prefix}.${Key}`;\ntype PathWhitespace = \" \" | \"\\f\" | \"\\n\" | \"\\r\" | \"\\t\" | \"\\v\";\ntype TrimPathWhitespace<Key extends string> =\n Key extends `${PathWhitespace}${infer Rest}`\n ? TrimPathWhitespace<Rest>\n : Key extends `${infer Rest}${PathWhitespace}`\n ? TrimPathWhitespace<Rest>\n : Key;\ntype NumericLikePathKey<Key extends string> = TrimPathWhitespace<Key> extends \"\"\n ? true\n : TrimPathWhitespace<Key> extends\n | `${number}`\n | \"+Infinity\"\n | \"-Infinity\"\n | \"Infinity\"\n ? true\n : false;\ntype SafePathKey<Key extends string> = Key extends \"\" | ReservedFormPathSegment\n ? never\n : NumericLikePathKey<Key> extends true\n ? never\n : Key extends\n | `$ACTION_${string}`\n | `__formadapter_${string}`\n | `${string}.${string}`\n | `${string}[${string}`\n | `${string}]${string}`\n | `${string}'${string}`\n | `${string}\"${string}`\n ? never\n : Key;\n\ntype PathsForValue<\n Value,\n Prefix extends string,\n Depth extends readonly unknown[],\n> =\n | Prefix\n | (AtMaxDepth<Depth> extends true\n ? never\n : NonNullable<Value> extends readonly (infer Item)[]\n ? | `${Prefix}[]`\n | (IsTraversable<Item> extends true\n ? PathsForValue<NonNullable<Item>, `${Prefix}[]`, NextDepth<Depth>>\n : never)\n : IsTraversable<Value> extends true\n ? ObjectPaths<NonNullable<Value>, Prefix, NextDepth<Depth>>\n : never);\n\ntype ObjectPaths<\n Value,\n Prefix extends string,\n Depth extends readonly unknown[],\n> = Value extends unknown\n ? Value extends object\n ? {\n [Key in Extract<keyof Value, string>]-?: PathsForValue<\n Value[Key],\n Join<Prefix, SafePathKey<Key>>,\n Depth\n >;\n }[Extract<keyof Value, string>]\n : never\n : never;\n\n/** Canonical schema field paths. Array items use `[]`, for example `users[].email`. */\nexport type FieldPath<Value> = IsTraversable<Value> extends true\n ? Extract<ObjectPaths<NonNullable<Value>, \"\", []>, string>\n : never;\n\ntype SegmentValue<Value, Segment extends string> = Value extends unknown\n ? Segment extends `${infer Prefix}[]`\n ? SegmentValue<Value, Prefix> extends readonly (infer Item)[]\n ? Item\n : never\n : Segment extends keyof NonNullable<Value>\n ? NonNullable<Value>[Segment]\n : never\n : never;\n\ntype PathValueInternal<Value, Path extends string> = Path extends `${infer Head}.${infer Tail}`\n ? PathValueInternal<SegmentValue<Value, Head>, Tail>\n : SegmentValue<Value, Path>;\n\nexport type PathValue<Value, Path extends FieldPath<Value>> = PathValueInternal<Value, Path>;\n\nexport type DeepPartial<Value> = IsAny<Value> extends true\n ? Value\n : Value extends Atomic\n ? Value\n : Value extends readonly (infer Item)[]\n ? Array<DeepPartial<Item>>\n : Value extends object\n ? { [Key in keyof Value]?: DeepPartial<Value[Key]> }\n : Value;\n\nexport function pathToName(path: ReadonlyArray<string | number>): string {\n return path.map(String).join(\".\");\n}\n\nexport function pathToConfigPath(path: ReadonlyArray<string | number>): string {\n let result = \"\";\n for (const segment of path) {\n if (typeof segment === \"number\") {\n result += \"[]\";\n } else {\n result += result === \"\" ? segment : `.${segment}`;\n }\n }\n return result;\n}\n","import type { DeepPartial } from \"./path\";\nimport { ownValue } from \"./record\";\nimport type { StandardIssue } from \"./standard\";\nimport type {\n FieldState,\n FormModel,\n FormNode,\n} from \"./types\";\n\nfunction isRecord(value: unknown): value is Readonly<Record<string, unknown>> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nexport function resolveFieldState<Values>(\n state: FieldState<Values> | undefined,\n values: Readonly<DeepPartial<Values>>,\n fallback = false,\n): boolean {\n if (typeof state === \"function\") return Boolean(state(values));\n return typeof state === \"boolean\" ? state : fallback;\n}\n\nexport function isEmptyFieldValue(value: unknown): boolean {\n if (value === undefined || value === null || value === \"\") return true;\n if (Array.isArray(value)) return value.length === 0;\n if (isRecord(value)) return Object.values(value).every(isEmptyFieldValue);\n return false;\n}\n\nfunction visitRequiredRules(\n node: FormNode<string, unknown>,\n value: unknown,\n values: Readonly<Record<string, unknown>>,\n path: readonly (number | string)[],\n inheritedHidden: boolean,\n issues: StandardIssue[],\n): void {\n const hidden =\n inheritedHidden || resolveFieldState(node.config.hidden, values, false);\n const required = resolveFieldState(\n node.config.requiredWhenVisible,\n values,\n false,\n );\n\n if (!hidden && required && isEmptyFieldValue(value)) {\n issues.push({\n message: node.config.requiredMessage ?? `${node.label} is required`,\n path,\n });\n }\n\n if (node.kind === \"object\") {\n const record = isRecord(value) ? value : {};\n for (const child of node.children) {\n visitRequiredRules(\n child as FormNode<string, unknown>,\n ownValue(record, child.key),\n values,\n [...path, child.key],\n hidden,\n issues,\n );\n }\n } else if (node.kind === \"array\" && Array.isArray(value)) {\n for (const [index, item] of value.entries()) {\n visitRequiredRules(\n node.item as FormNode<string, unknown>,\n item,\n values,\n [...path, index],\n hidden,\n issues,\n );\n }\n }\n}\n\n/** Validates portable presentation rules that are intentionally outside the schema. */\nexport function validatePresentationRules<Input, Control extends string>(\n model: FormModel<Input, Control>,\n values: Readonly<DeepPartial<Input>>,\n): readonly StandardIssue[] {\n const issues: StandardIssue[] = [];\n const record = isRecord(values) ? values : {};\n visitRequiredRules(\n model.root as FormNode<string, unknown>,\n values,\n record,\n [],\n false,\n issues,\n );\n return issues;\n}\n","import { resolveFieldState } from \"./rules\";\nimport { defineOwn, ownValue } from \"./record\";\nimport type {\n FormModel,\n FormNode,\n} from \"./types\";\n\nfunction isRecord(value: unknown): value is Readonly<Record<string, unknown>> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction prepareNodeValue(\n field: FormNode<string, unknown>,\n value: unknown,\n rootValues: Readonly<Record<string, unknown>>,\n): unknown {\n const hidden = field.path !== \"\" &&\n resolveFieldState(field.config.hidden, rootValues, false);\n if (hidden) return undefined;\n\n if (field.kind === \"scalar\") {\n if (value !== \"\") return value;\n if (field.nullable) return null;\n if (!field.required) return undefined;\n if (field.dataType === \"number\" || field.dataType === \"integer\") {\n return undefined;\n }\n return \"\";\n }\n\n if (field.kind === \"array\") {\n return Array.isArray(value)\n ? value.map((item) =>\n prepareNodeValue(field.item, item, rootValues)\n )\n : value;\n }\n\n if (field.kind === \"object\") {\n const source = isRecord(value) ? value : {};\n const prepared: Record<string, unknown> = {};\n for (const child of field.children) {\n const next = prepareNodeValue(\n child as FormNode<string, unknown>,\n ownValue(source, child.key),\n rootValues,\n );\n if (next !== undefined) defineOwn(prepared, child.key, next);\n }\n if (!field.required && Object.keys(prepared).length === 0) return undefined;\n return prepared;\n }\n\n return value;\n}\n\n/**\n * Converts browser form values to schema input: optional blanks become absent,\n * nullable blanks become null, and presentation-hidden branches are pruned.\n */\nexport function prepareFormValues<Input, Control extends string>(\n model: FormModel<Input, Control>,\n values: unknown,\n): unknown {\n const rootValues = isRecord(values) ? values : {};\n return prepareNodeValue(\n model.root as FormNode<string, unknown>,\n values,\n rootValues,\n );\n}\n","import type { FormOption, JsonPrimitive } from \"./types\";\n\n/** Stable DOM serialization for non-string option values. */\nexport function serializeOptionValue(value: JsonPrimitive): string {\n if (value === null) return \"null:\";\n return `${typeof value}:${String(value)}`;\n}\n\nexport function optionForSerializedValue(\n options: readonly FormOption[],\n serialized: string,\n): FormOption | undefined {\n return options.find(\n (option) => serializeOptionValue(option.value) === serialized,\n );\n}\n","import { createNullRecord, defineOwn, hasOwn } from \"./record\";\n\nexport type SubmissionErrorKind = \"business\" | \"transport\" | \"validation\";\n\nexport interface IdleSubmission {\n readonly status: \"idle\";\n}\n\nexport interface SuccessfulSubmission<Data = unknown> {\n readonly status: \"success\";\n readonly data?: Data;\n readonly message?: string;\n}\n\nexport interface FailedSubmission {\n readonly status: \"error\";\n readonly errorKind: SubmissionErrorKind;\n readonly fieldErrors: Readonly<Record<string, readonly string[]>>;\n readonly formErrors: readonly string[];\n}\n\nexport type SubmissionState<Data = unknown> =\n | FailedSubmission\n | IdleSubmission\n | SuccessfulSubmission<Data>;\n\nexport type SubmissionAction<Payload, Data = unknown> = (\n previousState: SubmissionState<Data>,\n payload: Payload,\n) => Promise<SubmissionState<Data>>;\n\nexport const initialSubmissionState: IdleSubmission = { status: \"idle\" };\n\nconst SUCCESS_KEYS = new Set([\"data\", \"message\", \"status\"]);\nconst ERROR_KEYS = new Set([\"errorKind\", \"fieldErrors\", \"formErrors\", \"status\"]);\n\nexport function submissionFailure(\n options: {\n readonly errorKind?: SubmissionErrorKind;\n readonly fieldErrors?: Readonly<Record<string, readonly string[]>>;\n readonly formErrors?: readonly string[];\n } = {},\n): FailedSubmission {\n const fieldErrors = createNullRecord<readonly string[]>();\n for (const [path, messages] of Object.entries(options.fieldErrors ?? {})) {\n defineOwn(fieldErrors, path, messages);\n }\n return {\n errorKind: options.errorKind ?? \"business\",\n fieldErrors,\n formErrors: options.formErrors ?? [],\n status: \"error\",\n };\n}\n\nexport function submissionSuccess<Data = undefined>(\n data?: Data,\n message?: string,\n): SuccessfulSubmission<Data> {\n return {\n ...(data !== undefined ? { data } : {}),\n ...(message ? { message } : {}),\n status: \"success\",\n };\n}\n\nexport function isSubmissionState(value: unknown): value is SubmissionState {\n try {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n return false;\n }\n const state = value as Readonly<Record<string, unknown>>;\n if (!hasOwn(state, \"status\") || Object.getOwnPropertySymbols(state).length > 0) {\n return false;\n }\n const keys = Object.keys(state);\n const hasOnly = (allowed: ReadonlySet<string>): boolean =>\n keys.every((key) => allowed.has(key));\n\n if (state.status === \"idle\") {\n return keys.length === 1 && keys[0] === \"status\";\n }\n if (state.status === \"success\") {\n return hasOnly(SUCCESS_KEYS) &&\n (!hasOwn(state, \"message\") || typeof state.message === \"string\");\n }\n if (state.status !== \"error\") return false;\n if (!hasOnly(ERROR_KEYS)) {\n return false;\n }\n if (\n !hasOwn(state, \"errorKind\") ||\n !hasOwn(state, \"fieldErrors\") ||\n !hasOwn(state, \"formErrors\")\n ) {\n return false;\n }\n if (\n state.errorKind !== \"business\" &&\n state.errorKind !== \"transport\" &&\n state.errorKind !== \"validation\"\n ) {\n return false;\n }\n if (\n !Array.isArray(state.formErrors) ||\n !state.formErrors.every((message) => typeof message === \"string\")\n ) {\n return false;\n }\n if (\n typeof state.fieldErrors !== \"object\" ||\n state.fieldErrors === null ||\n Array.isArray(state.fieldErrors)\n ) {\n return false;\n }\n return Object.values(state.fieldErrors).every(\n (messages) =>\n Array.isArray(messages) &&\n messages.every((message) => typeof message === \"string\"),\n );\n } catch {\n return false;\n }\n}\n","import { pathToName } from \"./path\";\nimport { createNullRecord, defineOwn, hasOwn } from \"./record\";\nimport type {\n FormSchema,\n InferOutput,\n StandardIssue,\n} from \"./standard\";\n\nexport type ValidationResult<Output> =\n | { readonly success: true; readonly data: Output }\n | { readonly success: false; readonly issues: readonly StandardIssue[] };\n\nexport function issuePath(issue: StandardIssue): readonly PropertyKey[] {\n return (issue.path ?? []).map((segment) => {\n if (typeof segment !== \"object\" || segment === null) return segment;\n return hasOwn(segment, \"key\")\n ? (segment as { readonly key: PropertyKey }).key\n : String(segment);\n });\n}\n\nexport function issuesToFieldErrors(\n issues: readonly StandardIssue[],\n): Readonly<Record<string, readonly string[]>> {\n const errors = createNullRecord<string[]>();\n for (const issue of issues) {\n const path = pathToName(\n issuePath(issue).map((segment) =>\n typeof segment === \"number\" || typeof segment === \"string\"\n ? segment\n : String(segment),\n ),\n );\n let messages = errors[path];\n if (!messages) {\n messages = [];\n defineOwn(errors, path, messages);\n }\n messages.push(issue.message);\n }\n return errors;\n}\n\nexport async function validate<Schema extends FormSchema>(\n schema: Schema,\n value: unknown,\n): Promise<ValidationResult<InferOutput<Schema>>> {\n const result = await schema[\"~standard\"].validate(value);\n if (result.issues === undefined) {\n return { success: true, data: result.value };\n }\n return {\n success: false,\n issues: result.issues.length > 0\n ? result.issues\n : [{ message: \"Schema validation failed\" }],\n };\n}\n"],"mappings":";;AAqBA,MAAa,8BAAmD,IAAI,IAAI;CACtE,GAAG,OAAO,oBAAoB,OAAO,UAAU;CAC/C;CACA;CACD,CAAC;AAEF,SAAgB,qBAAqB,SAAqC;AACxE,KAAI,QAAQ,WAAW,EACrB,QAAO;AAET,KAAI,4BAA4B,IAAI,QAAQ,CAC1C,QAAO,kBAAkB,QAAQ;AAEnC,KAAI,QAAQ,WAAW,iBAAiB,CACtC,QAAO,kBAAkB,QAAQ;AAEnC,KAAI,QAAQ,WAAW,WAAW,CAChC,QAAO,kBAAkB,QAAQ;AAEnC,KACE,QAAQ,SAAS,IAAI,IACrB,QAAQ,SAAS,IAAI,IACrB,QAAQ,SAAS,IAAI,IACrB,QAAQ,SAAS,IAAI,IACrB,QAAQ,SAAS,KAAI,CAErB,QAAO,kBAAkB,QAAQ;AAEnC,KAAI,CAAC,OAAO,MAAM,OAAO,QAAQ,CAAC,CAChC,QAAO,+BAA+B,QAAQ;;;AAMlD,SAAgB,0BAA0B,SA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C,EAAE,SAAS,4BAA4B,CAAC;EAC9C"}
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@formadapter/core",
3
+ "version": "0.0.0",
4
+ "description": "Framework-free schema compilation and validation primitives for FormAdapter.",
5
+ "keywords": [
6
+ "forms",
7
+ "schema",
8
+ "standard-schema",
9
+ "json-schema",
10
+ "typescript"
11
+ ],
12
+ "homepage": "https://formadapter.com",
13
+ "bugs": {
14
+ "url": "https://github.com/ludicroushq/formadapter/issues"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/ludicroushq/formadapter.git",
19
+ "directory": "packages/core"
20
+ },
21
+ "license": "MIT",
22
+ "author": "ludicrous",
23
+ "type": "module",
24
+ "sideEffects": false,
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "files": [
29
+ "dist",
30
+ "README.md",
31
+ "LICENSE"
32
+ ],
33
+ "main": "./dist/index.js",
34
+ "module": "./dist/index.js",
35
+ "types": "./dist/index.d.ts",
36
+ "exports": {
37
+ ".": {
38
+ "types": "./dist/index.d.ts",
39
+ "import": "./dist/index.js",
40
+ "default": "./dist/index.js"
41
+ },
42
+ "./package.json": "./package.json"
43
+ },
44
+ "devDependencies": {
45
+ "arktype": "^2.2.3",
46
+ "zod": "^4.4.3"
47
+ },
48
+ "scripts": {
49
+ "build": "tsdown",
50
+ "clean": "rm -rf dist tsconfig.tsbuildinfo .turbo",
51
+ "dev": "tsdown --watch",
52
+ "test": "vitest run --config vitest.config.ts",
53
+ "test:coverage": "vitest run --config vitest.config.ts --coverage",
54
+ "typecheck": "tsc --project tsconfig.json --noEmit"
55
+ }
56
+ }