{"version":3,"file":"index.mjs","names":[],"sources":["../src/error.ts","../src/module.ts"],"sourcesContent":["/*\n * Copyright (c) 2026.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport { defineIssueItem } from '@ebec/core';\nimport { isObject } from 'validup';\nimport type { Issue } from '@ebec/core';\n\n/**\n * Convert a Standard Schema path (`(PropertyKey | { key })[]`) into a validup\n * `PropertyKey[]`. PathSegments are unwrapped to their `.key`.\n */\nfunction normalizePath(\n    path: ReadonlyArray<PropertyKey | StandardSchemaV1.PathSegment> | undefined,\n): PropertyKey[] {\n    if (!path || path.length === 0) {\n        return [];\n    }\n\n    const output: PropertyKey[] = [];\n    for (const segment of path) {\n        if (isObject(segment) && 'key' in segment) {\n            output.push(segment.key as PropertyKey);\n        } else {\n            output.push(segment as PropertyKey);\n        }\n    }\n    return output;\n}\n\n/**\n * Translate Standard Schema issues into validup `IssueItem`s. Standard Schema\n * intentionally only exposes `message` + `path`; vendor-specific fields like\n * `expected`/`received`/`code` are not part of the spec, so the resulting\n * issues carry only the portable subset (`code` defaults to\n * `IssueCode.VALUE_INVALID`).\n */\nexport function buildIssuesForStandardSchemaIssues(\n    issues: ReadonlyArray<StandardSchemaV1.Issue>,\n): Issue[] {\n    const output: Issue[] = [];\n    for (const issue of issues) {\n        output.push(defineIssueItem({\n            path: normalizePath(issue.path),\n            message: issue.message,\n        }));\n    }\n    return output;\n}\n","/*\n * Copyright (c) 2026.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { ValidatorContext, ValidatorDescriptor } from 'validup';\nimport { ValidupError, defineValidator } from 'validup';\nimport { buildIssuesForStandardSchemaIssues } from './error';\n\ntype StandardSchemaCreateFn<C, S extends StandardSchemaV1> = (\n    ctx: ValidatorContext<C>,\n) => S;\n\n/**\n * Options accepted by {@link createValidator}.\n */\nexport type StandardSchemaCreateValidatorOptions = {\n    /**\n     * Mark the resulting validator as having side effects (network\n     * calls, sibling-field reads, observable state) so the framework\n     * never caches its outcome. Default `false` — most Standard\n     * Schema validators (regex / length / enum / type checks) are\n     * deterministic and safe to cache by `(ctx.value, ctx.context,\n     * ctx.group)`. Set to `true` for schemas that resolve against\n     * external state.\n     */\n    sideEffect?: boolean,\n};\n\n/**\n * Wrap any Standard Schema validator (zod 3.24+, valibot, arktype,\n * effect-schema, …) as a validup `ValidatorDescriptor`. The schema's\n * `~standard.validate` method is invoked with the mounted value; on\n * failure, its issues are translated into validup `IssueItem`s.\n *\n * Pass a function instead of a schema to build per-context schemas\n * (e.g. depending on the active group, sibling values, or\n * `ctx.context`).\n *\n * The returned descriptor infers its `Out` type from the schema's\n * `StandardSchemaV1.InferOutput<S>`, so the builder API\n * (`defineSchema`) picks up real per-field types from any\n * Standard-Schema-compatible library. Returned as a\n * {@link ValidatorDescriptor} so it carries the `sideEffect` flag the\n * validup runtime consults for its result cache.\n */\nexport function createValidator<\n    C = unknown,\n    S extends StandardSchemaV1 = StandardSchemaV1,\n>(\n    input: S | StandardSchemaCreateFn<C, S>,\n    options: StandardSchemaCreateValidatorOptions = {},\n): ValidatorDescriptor<C, StandardSchemaV1.InferOutput<S>> {\n    return defineValidator<C, StandardSchemaV1.InferOutput<S>>({\n        sideEffect: options.sideEffect,\n        run: async (ctx) => {\n            const schema = typeof input === 'function' ? input(ctx) : input;\n            const result = await schema['~standard'].validate(ctx.value);\n\n            if (!result.issues) {\n                return result.value as StandardSchemaV1.InferOutput<S>;\n            }\n\n            throw new ValidupError(buildIssuesForStandardSchemaIssues(result.issues));\n        },\n    });\n}\n"],"mappings":";;;;;;;AAgBA,SAAS,cACL,MACa;CACb,IAAI,CAAC,QAAQ,KAAK,WAAW,GACzB,OAAO,CAAC;CAGZ,MAAM,SAAwB,CAAC;CAC/B,KAAK,MAAM,WAAW,MAClB,IAAI,SAAS,OAAO,KAAK,SAAS,SAC9B,OAAO,KAAK,QAAQ,GAAkB;MAEtC,OAAO,KAAK,OAAsB;CAG1C,OAAO;AACX;;;;;;;;AASA,SAAgB,mCACZ,QACO;CACP,MAAM,SAAkB,CAAC;CACzB,KAAK,MAAM,SAAS,QAChB,OAAO,KAAK,gBAAgB;EACxB,MAAM,cAAc,MAAM,IAAI;EAC9B,SAAS,MAAM;CACnB,CAAC,CAAC;CAEN,OAAO;AACX;;;;;;;;;;;;;;;;;;;;ACHA,SAAgB,gBAIZ,OACA,UAAgD,CAAC,GACM;CACvD,OAAO,gBAAoD;EACvD,YAAY,QAAQ;EACpB,KAAK,OAAO,QAAQ;GAEhB,MAAM,SAAS,OADA,OAAO,UAAU,aAAa,MAAM,GAAG,IAAI,MAAA,CAC9B,YAAY,CAAC,SAAS,IAAI,KAAK;GAE3D,IAAI,CAAC,OAAO,QACR,OAAO,OAAO;GAGlB,MAAM,IAAI,aAAa,mCAAmC,OAAO,MAAM,CAAC;EAC5E;CACJ,CAAC;AACL"}