"use strict";
/* Socket Lib - Built with rolldown */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_primordials_error = require('../primordials/error.js');
const require_schema_validate = require('./validate.js');

//#region src/schema/parse.ts
/**
* @file Throwing twin of `validateSchema`. Use `parseSchema(schema, data)` for
*   fail-fast trust boundaries (app startup, config files, internal
*   assertions). Use the non-throwing `validateSchema` for recoverable input
*   (form fields, API request bodies, anywhere errors need to surface to a
*   user).
*
* @example
*   ;```ts
*   import { z } from 'zod'
*   import { parseSchema } from '@socketsecurity/lib/schema/parse'
*
*   const Config = z.object({ host: z.string(), port: z.number() })
*   const config = parseSchema(Config, json) // throws on invalid
*   ```
*/
/**
* Parse `data` against `schema` and return the validated value.
*
* @throws {Error} When validation fails. The message lists all issues as `path:
*   message, path: message, ...`. Use `validateSchema` if you need structured
*   access to the error list.
*/
function parseSchema(schema, data) {
	const result = require_schema_validate.validateSchema(schema, data);
	if (result.ok) return result.value;
	throw new require_primordials_error.ErrorCtor(`Validation failed: ${result.errors.map((e) => `${e.path.join(".") || "(root)"}: ${e.message}`).join(", ")}`);
}

//#endregion
exports.parseSchema = parseSchema;