/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/@gcornut/valibot-json-schema@0.42.0/dist/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
"use strict";var __defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__hasOwnProp=Object.prototype.hasOwnProperty,__export=(e,t)=>{for(var n in t)__defProp(e,n,{get:t[n],enumerable:!0})},__copyProps=(e,t,n,r)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let a of __getOwnPropNames(t))__hasOwnProp.call(e,a)||a===n||__defProp(e,a,{get:()=>t[a],enumerable:!(r=__getOwnPropDesc(t,a))||r.enumerable});return e},__toCommonJS=e=>__copyProps(__defProp({},"__esModule",{value:!0}),e),src_exports={};__export(src_exports,{jsonSchemaMetadata:()=>jsonSchemaMetadata,toJSONSchema:()=>toJSONSchema,withJSONSchemaFeatures:()=>withJSONSchemaFeatures}),module.exports=__toCommonJS(src_exports);var JSON_SCHEMA_FEATURES_KEY="__json_schema_features";function withJSONSchemaFeatures(e,t){return Object.assign(e,{[JSON_SCHEMA_FEATURES_KEY]:t})}function getJSONSchemaFeatures(e){return e[JSON_SCHEMA_FEATURES_KEY]}function assignExtraJSONSchemaFeatures(e,t){const n=getJSONSchemaFeatures(e);n&&Object.assign(t,n)}function assert(e,t,n){if(!t(e))throw new Error(n.replace("%",String(e)));return e}var $schema="http://json-schema.org/draft-07/schema#";function isJSONLiteral(e){return"number"==typeof e&&!Number.isNaN(e)||"string"==typeof e||"boolean"==typeof e||null===e}var assertJSONLiteral=e=>assert(e,isJSONLiteral,"Unsupported literal value type: %"),import_valibot=require("valibot");function isEqual(e,t){if(e===t)return!0;if("object"==typeof e&&"object"==typeof t){const n=Object.keys(e),r=Object.keys(t);return n.length===r.length&&n.every((n=>isEqual(e[n],t[n])))}return!1}function isSchemaType(e){return t=>!!t&&t.type===e}var isNullishSchema=isSchemaType("nullish"),isOptionalSchema=isSchemaType("optional"),isStringSchema=isSchemaType("string"),isNeverSchema=isSchemaType("never"),toDefinitionURI=e=>`#/definitions/${e}`,SCHEMA_CONVERTERS={any:()=>({}),null:()=>({const:null}),literal:({literal:e})=>({const:assertJSONLiteral(e)}),number:()=>({type:"number"}),string:()=>({type:"string"}),boolean:()=>({type:"boolean"}),optional:(e,t)=>{const n=t(e.wrapped),r=(0,import_valibot.getDefault)(e);return void 0!==r&&(n.default=r),n},nullish:(e,t)=>{const n={anyOf:[{const:null},t(e.wrapped)]},r=(0,import_valibot.getDefault)(e);return void 0!==r&&(n.default=r),n},nullable:(e,t)=>{const n={anyOf:[{const:null},t(e.wrapped)]},r=(0,import_valibot.getDefault)(e);return void 0!==r&&(n.default=r),n},picklist:({options:e})=>({enum:e.map(assertJSONLiteral)}),enum:e=>({enum:Object.values(e.enum).map(assertJSONLiteral)}),union:({options:e},t)=>({anyOf:e.map(t)}),intersect:({options:e},t)=>({allOf:e.map(t)}),array:({item:e},t)=>({type:"array",items:t(e)}),tuple_with_rest({items:e,rest:t},n){const r=e.length;let a,i,o=e.map(n);if(isNeverSchema(t))a=r;else if(t){const e=n(t);1===o.length&&isEqual(o[0],e)?o=o[0]:i=e}return{type:"array",items:o,...i&&{additionalItems:i},...r&&{minItems:r},...a&&{maxItems:a}}},strict_tuple({items:e},t){const n=e.map(t);return{type:"array",items:n,minItems:n.length,maxItems:n.length}},tuple({items:e},t,n){const r=e.map(t);return{type:"array",items:r,minItems:r.length}},object_with_rest({entries:e,rest:t},n,r){const a={},i=[];for(const[t,r]of Object.entries(e)){const e=r;isOptionalSchema(e)||isNullishSchema(e)||i.push(t),a[t]=n(e),assignExtraJSONSchemaFeatures(r,a[t])}let o;t?o=!isNeverSchema(t)&&n(t):r.strictObjectTypes&&(o=!1);const s={type:"object",properties:a};return void 0!==o&&(s.additionalProperties=o),i.length&&(s.required=i),s},object:(e,t,n)=>SCHEMA_CONVERTERS.object_with_rest(e,t,n),strict_object:(e,t,n)=>({...SCHEMA_CONVERTERS.object_with_rest(e,t,n),additionalProperties:!1}),record:({key:e,value:t},n)=>(assert(e,isStringSchema,"Unsupported record key type: %"),{type:"object",additionalProperties:n(t)}),lazy(e,t,n){const r=e.getter({}),a=n.defNameMap.get(r);if(!a)throw new Error("Type inside lazy schema must be provided in the definitions");return{$ref:toDefinitionURI(a)}},date(e,t,n){if(!n.dateStrategy)throw new Error('The "dateStrategy" option must be set to handle date validators');switch(n.dateStrategy){case"integer":return{type:"integer",format:"unix-time"};case"string":return{type:"string",format:"date-time"}}},undefined(e,t,n){if(!n.undefinedStrategy)throw new Error('The "undefinedStrategy" option must be set to handle the `undefined` schema');switch(n.undefinedStrategy){case"any":return{};case"null":return{type:"null"}}},bigint(e,t,n){if(!n.bigintStrategy)throw new Error('The "bigintStrategy" option must be set to handle `bigint` validators');switch(n.bigintStrategy){case"integer":return{type:"integer",format:"int64"};case"string":return{type:"string"}}},variant:({options:e},...t)=>SCHEMA_CONVERTERS.union({options:e},...t)},METADATA_BY_TYPE={description:({description:e})=>({description:e}),"@gcornut/to-json-schema/json_schema_metadata":({metadata:e})=>e};function asDateRequirement(e,t,n){return assert(t,(()=>"integer"===n.dateStrategy),`${e} validation is only available with 'integer' date strategy`),assert(t,(e=>e instanceof Date),`Non-date value used for ${e} validation`),t.getTime()}var VALIDATION_BY_SCHEMA={array:{length:({requirement:e})=>({minItems:e,maxItems:e}),min_length:({requirement:e})=>({minItems:e}),max_length:({requirement:e})=>({maxItems:e})},string:{value:({requirement:e})=>({const:e}),length:({requirement:e})=>({minLength:e,maxLength:e}),min_length:({requirement:e})=>({minLength:e}),max_length:({requirement:e})=>({maxLength:e}),regex:({requirement:e})=>({pattern:e.source}),email:()=>({format:"email"}),iso_date:()=>({format:"date"}),iso_timestamp:()=>({format:"date-time"}),ipv4:()=>({format:"ipv4"}),ipv6:()=>({format:"ipv6"}),uuid:()=>({format:"uuid"})},number:{value:({requirement:e})=>({const:e}),min_value:({requirement:e})=>({minimum:e}),max_value:({requirement:e})=>({maximum:e}),multiple_of:({requirement:e})=>({multipleOf:e}),integer:()=>({type:"integer"})},boolean:{value:({requirement:e})=>({const:e})},date:{value:({requirement:e},t)=>({const:asDateRequirement("value",e,t)}),min_value:({requirement:e},t)=>({minimum:asDateRequirement("minValue",e,t)}),max_value:({requirement:e},t)=>({maximum:asDateRequirement("maxValue",e,t)})}};function convertPipe(e,t,n){const[r,...a]=t||[];if(!r)return{};const i=convertPipe(e,null==r?void 0:r.pipe,n);return a.reduce((function(t,r){var a,i,o;const s=r.type,m=(null==(i=null==(a=n.customValidationConversion)?void 0:a[e])?void 0:i[s])||(null==(o=VALIDATION_BY_SCHEMA[e])?void 0:o[s])||METADATA_BY_TYPE[s];if(!m&&n.ignoreUnknownValidation)return{};assert(m,Boolean,`Unsupported valibot validation \`${s}\` for schema \`${e}\``);const u=m(r,n);return Object.assign(t,u)}),i)}function getDefNameMap(e={}){const t=new Map;for(const[n,r]of Object.entries(e))t.set(r,n);return t}function createConverter(e){const t={};return{definitions:t,converter:function n(r){var a;const i=e.defNameMap.get(r),o=i&&toDefinitionURI(i);if(o&&o in t)return{$ref:o};const s=(null==(a=e.customSchemaConversion)?void 0:a[r.type])||SCHEMA_CONVERTERS[r.type];assert(s,Boolean,`Unsupported valibot schema: ${(null==r?void 0:r.type)||r}`);let m=s(r,n,e)||{};const u=convertPipe(r.type,r.pipe,e);return m={...m,...u},assignExtraJSONSchemaFeatures(r,m),o?(t[i]=m,{$ref:o}):m}}}function toJSONSchema(e){const{schema:t,definitions:n,...r}=e,a=getDefNameMap(n),{definitions:i,converter:o}=createConverter({defNameMap:a,...r});if(!t&&!n)throw new Error("No main schema or definitions provided.");n&&Object.values(n).forEach(o);const s=t&&o(t),m=t&&a.get(t),u={$schema:$schema};return m?u.$ref=toDefinitionURI(m):Object.assign(u,s),Object.keys(i).length&&(u.definitions=i),u}function jsonSchemaMetadata(e){return{kind:"metadata",type:"@gcornut/to-json-schema/json_schema_metadata",reference:jsonSchemaMetadata,metadata:e}}
//# sourceMappingURL=/sm/55ac5fa1b486ea8c04d8f825622cb195bacc0de7df1e709db0026e0f544b4f90.map