{"version":3,"file":"adapter.mjs","names":[],"sources":["../../../../../../../react-form/src/standard-schema/adapter.ts"],"sourcesContent":["import { ReactNode } from \"react\";\nimport { InputRule } from \"../types\";\nimport { StandardSchemaV1 } from \"./types\";\n\n/**\n * Duck-type guard: is `value` a Standard-Schema-compliant validator?\n *\n * We intentionally avoid importing any concrete library — anything exposing a\n * `~standard.validate` function is accepted (seal, zod, valibot, arktype, …).\n */\nexport function isStandardSchema(value: any): value is StandardSchemaV1 {\n  return (\n    !!value &&\n    typeof value === \"object\" &&\n    \"~standard\" in value &&\n    typeof value[\"~standard\"]?.validate === \"function\"\n  );\n}\n\n/**\n * Run a Standard Schema against a value and normalize the result to a plain\n * `{ issues }` shape. Always returns a Promise — the spec allows `validate` to\n * be sync or async, so we await uniformly.\n */\nexport async function runStandardSchema<Output>(\n  schema: StandardSchemaV1<unknown, Output>,\n  value: unknown\n): Promise<StandardSchemaV1.Result<Output>> {\n  return await schema[\"~standard\"].validate(value);\n}\n\n/**\n * Convert a Standard Schema issue path (e.g. `[\"user\", { key: \"addresses\" }, 0,\n * \"city\"]`) into a dot-notation form-control name (`user.addresses.0.city`).\n */\nexport function issuePathToName(\n  path: StandardSchemaV1.Issue[\"path\"]\n): string {\n  if (!path || path.length === 0) return \"\";\n\n  return path\n    .map((segment) =>\n      typeof segment === \"object\" && segment !== null && \"key\" in segment\n        ? (segment as StandardSchemaV1.PathSegment).key\n        : segment\n    )\n    .join(\".\");\n}\n\n/**\n * Wrap a **single-field** Standard Schema as an `InputRule` so it can run inside\n * the per-control rule pipeline. The first issue's message becomes the rendered\n * error.\n *\n * Used by `useFormControl({ schema })`. The rule is async (the spec permits an\n * async `validate`) and participates in the engine's async gating just like any\n * other promise-returning rule.\n */\nexport function standardSchemaToRule(\n  schema: StandardSchemaV1,\n  name = \"schema\"\n): InputRule {\n  return {\n    name,\n    // Empty values are still handed to the schema so `optional`/`required`\n    // semantics defined by the schema itself are honored.\n    requiresValue: false,\n    validate: async ({ value }): Promise<ReactNode | undefined> => {\n      const result = await runStandardSchema(schema, value);\n\n      if (result.issues && result.issues.length > 0) {\n        return result.issues[0].message;\n      }\n\n      return undefined;\n    },\n  };\n}\n"],"mappings":";;;;;;;AAUA,SAAgB,iBAAiB,OAAuC;CACtE,OACE,CAAC,CAAC,SACF,OAAO,UAAU,YACjB,eAAe,SACf,OAAO,MAAM,YAAY,EAAE,aAAa;AAE5C;;;;;;AAOA,eAAsB,kBACpB,QACA,OAC0C;CAC1C,OAAO,MAAM,OAAO,YAAY,CAAC,SAAS,KAAK;AACjD;;;;;AAMA,SAAgB,gBACd,MACQ;CACR,IAAI,CAAC,QAAQ,KAAK,WAAW,GAAG,OAAO;CAEvC,OAAO,KACJ,KAAK,YACJ,OAAO,YAAY,YAAY,YAAY,QAAQ,SAAS,UACvD,QAAyC,MAC1C,OACN,CAAC,CACA,KAAK,GAAG;AACb;;;;;;;;;;AAWA,SAAgB,qBACd,QACA,OAAO,UACI;CACX,OAAO;EACL;EAGA,eAAe;EACf,UAAU,OAAO,EAAE,YAA4C;GAC7D,MAAM,SAAS,MAAM,kBAAkB,QAAQ,KAAK;GAEpD,IAAI,OAAO,UAAU,OAAO,OAAO,SAAS,GAC1C,OAAO,OAAO,OAAO,EAAE,CAAC;EAI5B;CACF;AACF"}