@lunora/values 1.0.0-alpha.36 → 1.0.0-alpha.38
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.
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/{DEFER_VALIDATION-9tLHpbIF.mjs → DEFER_VALIDATION-C0nIiPG-.mjs} +1 -1
- package/dist/packem_shared/ValidationError-BdVoGndu.mjs +1 -0
- package/dist/packem_shared/isOrWrapsFromValidator-Drhf5Ake.mjs +1 -0
- package/package.json +2 -2
- package/dist/packem_shared/ValidationError-BLw-y3Pk.mjs +0 -1
- package/dist/packem_shared/isOrWrapsFromValidator-BdXulHj0.mjs +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ValidationError as a,describeValue as e,formatPath as t}from"./packem_shared/ValidationError-
|
|
1
|
+
import{ValidationError as a,describeValue as e,formatPath as t}from"./packem_shared/ValidationError-BdVoGndu.mjs";import{jsonSchemaFromNode as p,objectSchemaFromNodes as i}from"./packem_shared/jsonSchemaFromNode-DtU81nPr.mjs";import{argsToJsonSchema as l,toJsonSchema as d}from"./packem_shared/argsToJsonSchema-ujumcrdC.mjs";import{isOrWrapsFromValidator as c,optionalInner as f,v as V}from"./packem_shared/isOrWrapsFromValidator-Drhf5Ake.mjs";import{DEFER_VALIDATION as x,installCompiledValidatorMap as F,parseValidatorMap as S}from"./packem_shared/DEFER_VALIDATION-C0nIiPG-.mjs";export{x as DEFER_VALIDATION,a as ValidationError,l as argsToJsonSchema,e as describeValue,t as formatPath,F as installCompiledValidatorMap,c as isOrWrapsFromValidator,p as jsonSchemaFromNode,i as objectSchemaFromNodes,f as optionalInner,S as parseValidatorMap,d as toJsonSchema,V as v};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ValidationError as d}from"./ValidationError-
|
|
1
|
+
import{ValidationError as d}from"./ValidationError-BdVoGndu.mjs";const f=Symbol("lunora.deferValidation"),s=new WeakMap,h=(o,n)=>{s.set(o,n)},m=(o,n,p)=>{const a=s.get(o);if(a!==void 0){const t=a(n);if(t!==f)return t}const r={};for(const t of Object.keys(o)){const i=o[t];if(!i)continue;const c=Object.hasOwn(n,t)?n[t]:void 0;if(!(c===void 0&&i.kind==="optional"))try{r[t]=i.parse(c)}catch(e){throw e instanceof d?new d(`${p}.${t}: ${e.message}`,{expected:e.expected,path:[t,...e.path],received:e.received}):e}}return r};export{f as DEFER_VALIDATION,h as installCompiledValidatorMap,m as parseValidatorMap};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as o}from"@lunora/errors";const n=80,i=r=>r.length>n?`${r.slice(0,n)}…`:r,c=r=>{try{const{constructor:e}=r,t=e?.name;if(t!==void 0&&t!=="Object")return i(`object ${t}`)}catch{return"object"}return"object"};class s extends o{path;expected;received;constructor(e,t){super("VALIDATION_ERROR",e,{name:"ValidationError"}),this.path=t.path,this.expected=t.expected,this.received=t.received}}const p=(r,e)=>{const t=e?.literal??!0;return r===null?"null":Array.isArray(r)?"array":r instanceof ArrayBuffer?"ArrayBuffer":typeof r=="string"?t?`string ${i(JSON.stringify(r))}`:"string":typeof r=="number"||typeof r=="boolean"?t?`${typeof r} ${String(r)}`:typeof r:typeof r=="bigint"?t?`bigint ${r.toString()}n`:"bigint":typeof r=="object"?c(r):typeof r},y=r=>r.length===0?"<root>":r.map((e,t)=>typeof e=="number"?`[${String(e)}]`:t===0?e:`.${e}`).join("");export{s as ValidationError,p as describeValue,y as formatPath};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as k}from"@lunora/errors";import{ValidationError as m,describeValue as y,formatPath as $}from"./ValidationError-BdVoGndu.mjs";const P=/^[^\s@]+@[^\s@.]+(?:\.[^\s@.]+)+$/u,I=e=>{if(!URL.canParse(e))return!1;const{protocol:r}=new URL(e);return r==="http:"||r==="https:"},_=new m("union branch probe miss (internal)",{expected:"",path:[],received:""});function u(e,r,s,a){if(e.probe===!0)throw _;const o=[...e.path],i=y(s,{literal:!a?.redactValue});throw new m(`Expected ${r} at ${$(o)}, received ${i}`,{expected:r,path:o,received:i})}const S=(e,r)=>{if(r===void 0)return e;const s=e?.constraints;return{...e,constraints:{...s,...r}}},l=(e,r,s)=>{const a=s?.column??{notNull:!0},o={__type:void 0,"~standard":{validate(n){const t=o.safeParse(n);return t.ok?{value:t.value}:{issues:[{message:t.error.message,path:t.error.path}]}},vendor:"lunora",version:1},_meta:{...s,column:a},_parse(n,t){return r(n,t)},kind:e,parse(n,t){return r(n,{path:[],...t})},safeParse(n,t){try{return{ok:!0,value:r(n,{path:[],...t})}}catch(c){if(c instanceof m)return{error:c,ok:!1};throw c}}},i=n=>l(e,r,{...s,column:{...a,...n}});switch(o.default=n=>i({defaultValue:n}),o.defaultNow=()=>i({defaultFn:()=>Date.now()}),o.unique=()=>i({unique:!0}),o.$defaultFn=n=>i({defaultFn:n}),o.$onUpdateFn=n=>i({onUpdateFn:n}),o.serverDefault=n=>i({serverDefault:n}),o.$type=(()=>i({})),o.nullable=()=>l(e,(t,c)=>t===null?null:r(t,c),{...s,column:{...a,notNull:!1}}),o.check=(n,t)=>{const c=typeof t=="string"?t:t?.message,d=typeof t=="string"?void 0:t?.schema;return l(e,(f,b)=>{const w=r(f,b);return n(w)||u(b,c??"value matching refinement",w,{redactValue:!0}),w},S(s,d))},o.meta=n=>{const t=n.description===void 0?n.schema:{description:n.description,...n.schema};return l(e,r,S(s,t))},e){case"array":{const n=o;n.min=t=>n.check(c=>c.length>=t,{message:`expected array length >= ${String(t)}`,schema:{minItems:t}}),n.max=t=>n.check(c=>c.length<=t,{message:`expected array length <= ${String(t)}`,schema:{maxItems:t}});break}case"number":{const n=o;n.min=t=>n.check(c=>c>=t,{message:`expected number >= ${String(t)}`,schema:{minimum:t}}),n.max=t=>n.check(c=>c<=t,{message:`expected number <= ${String(t)}`,schema:{maximum:t}}),n.int=()=>n.check(t=>Number.isInteger(t),{message:"expected an integer",schema:{type:"integer"}}),n.positive=()=>n.check(t=>t>0,{message:"expected a positive number",schema:{exclusiveMinimum:0}});break}case"string":{const n=o;n.min=t=>n.check(c=>c.length>=t,{message:`expected string length >= ${String(t)}`,schema:{minLength:t}}),n.max=t=>n.check(c=>c.length<=t,{message:`expected string length <= ${String(t)}`,schema:{maxLength:t}}),n.length=t=>n.check(c=>c.length===t,{message:`expected string length === ${String(t)}`,schema:{maxLength:t,minLength:t}}),n.pattern=t=>{const c=t.global||t.sticky?new RegExp(t.source,t.flags.replaceAll(/[gy]/gu,"")):t;return n.check(d=>c.test(d),{message:`expected string matching ${t.toString()}`,schema:{pattern:t.source}})},n.email=()=>n.check(t=>P.test(t),{message:"expected a valid email address",schema:{format:"email"}}),n.url=()=>n.check(t=>I(t),{message:"expected a valid URL",schema:{format:"uri"}});break}}return o},g=e=>e,h=e=>e,N=e=>e,O=e=>e,E=e=>e,L=()=>N(l("string",(e,r)=>(typeof e!="string"&&u(r,"string",e),e))),j=(e,r)=>((typeof e!="number"||!Number.isFinite(e))&&u(r,"number",e),e),V=()=>O(l("number",j)),R=()=>l("timestamp",j),F=()=>l("date",j),U=()=>h(l("boolean",(e,r)=>(typeof e!="boolean"&&u(r,"boolean",e),e))),T=()=>h(l("bigint",(e,r)=>(typeof e!="bigint"&&u(r,"bigint",e),e))),C=()=>h(l("null",(e,r)=>(e!==null&&u(r,"null",e),e))),D=()=>h(l("bytes",(e,r)=>(e instanceof ArrayBuffer||u(r,"ArrayBuffer",e),e))),q=e=>h(l("id",(r,s)=>(typeof r!="string"&&u(s,`Id<"${e}">`,r),r),{tableName:e})),B=e=>h(l("storage",(r,s)=>(typeof r!="string"&&u(s,"storage object key (string)",r),r),e===void 0?void 0:{bucket:e})),M=()=>h(l("geoPoint",(e,r)=>{(typeof e!="object"||e===null||Array.isArray(e))&&u(r,"geoPoint { lat, lng }",e);const s=e,{lat:a,lng:o}=s;return(typeof a!="number"||!Number.isFinite(a)||a<-90||a>90)&&(r.path.push("lat"),u(r,"latitude in [-90, 90]",a)),(typeof o!="number"||!Number.isFinite(o)||o<-180||o>180)&&(r.path.push("lng"),u(r,"longitude in [-180, 180]",o)),{lat:a,lng:o}})),x=e=>h(l("literal",(r,s)=>(r!==e&&u(s,`literal(${String(e)})`,r),r),{value:e})),K=e=>{const r=g(e);return E(l("array",(s,a)=>{Array.isArray(s)||u(a,"array",s);const{length:o}=s,i=[],{path:n}=a;for(let t=0;t<o;t+=1)n.push(t),i.push(r._parse(s[t],a)),n.pop();return i},{inner:e}))},v=(e,r)=>{const s=Object.keys(e).map(o=>{const i=g(e[o]);return{child:i,isOptional:i.kind==="optional",key:o}});if(s.some(({key:o})=>o==="__proto__"))throw new k("INTERNAL",'v.object: "__proto__" cannot be a declared field name — it collides with the Object.prototype accessor');const a=h(l("object",(o,i)=>{(typeof o!="object"||o===null||Array.isArray(o))&&u(i,"object",o);const n=o,t={},{path:c}=i;if(i.rejectUnknownKeys===!0&&r!==!0){const d=new Set(s.map(({key:f})=>f)),p=Object.keys(n).filter(f=>!d.has(f));if(p.length>0)throw new m(`object has ${String(p.length)} undeclared key(s): ${p.join(", ")}. Add them to the validator, or call .strip() on it to drop them on purpose.`,{expected:`only the declared keys (${s.map(({key:f})=>f).join(", ")})`,path:[...c],received:p.join(", ")})}for(const{child:d,isOptional:p,key:f}of s){const b=Object.hasOwn(n,f)?n[f]:void 0;b===void 0&&p||(c.push(f),t[f]=d._parse(b,i),c.pop())}return t},{shape:e}));return a.strip=()=>v(e,!0),a},W=(e,r)=>{const s=g(e),a=g(r);return h(l("record",(o,i)=>{(typeof o!="object"||o===null||Array.isArray(o))&&u(i,"record",o);const n=o,t=Object.create(null),{path:c}=i;for(const d of Object.keys(n)){c.push(d);const p=s._parse(d,i),f=a._parse(n[d],i);c.pop(),t[p]=f}return t},{keyValidator:e,valueValidator:r}))},z=(e,r,s,a)=>{const{path:o}=s;let i;const n=y(r,{literal:!1});let t=!1;for(const d of e)try{d._parse(r,s)}catch(p){if(!(p instanceof m))throw p;o.length=a,t||=p.received===n,(i===void 0||p.path.length>i.path.length)&&(i=p)}if(e.length===1&&i!==void 0)throw i;const c=i===void 0?"":` (closest: expected ${i.expected} at ${$(i.path)})`;return u(s,`union of ${String(e.length)} member(s)${c}`,r,{redactValue:t})},G=(...e)=>{if(e.length===0)throw new k("INTERNAL","v.union requires at least one member");const r=e.map(s=>g(s));return h(l("union",(s,a)=>{const{path:o}=a,i=o.length,n=a.probe===!0;a.probe=!0;try{for(const t of r)try{return t._parse(s,a)}catch(c){if(!(c instanceof m))throw c;o.length=i}}finally{a.probe=n}if(n)throw _;return z(r,s,a,i)},{members:e}))},A=e=>{const r=g(e);return h(l("optional",(s,a)=>s===void 0?void 0:r._parse(s,a),{inner:e}))},H=e=>Object.fromEntries(Object.entries(e).map(([r,s])=>[r,g(s).kind==="optional"?s:A(s)])),J=()=>h(l("any",e=>e)),Q=e=>{const r=[];if(!e)return r;for(const s of e){const a=typeof s=="object"&&s!==null&&"key"in s?s.key:s;(typeof a=="string"||typeof a=="number")&&r.push(a)}return r},X=e=>{const r=e["~standard"];if(r?.version!==1||typeof r.validate!="function")throw new k("INTERNAL",'@lunora/values: v.from() expects a Standard Schema v1 object (missing or invalid "~standard")');const s=r.validate;return h(l("from",(a,o)=>{const i=s(a);if(i instanceof Promise||typeof i?.then=="function")throw new m("v.from(): async Standard Schema validators are not supported in args",{expected:"sync Standard Schema result",path:[...o.path],received:"Promise"});const n=i;if(n===null||typeof n!="object")throw new m("v.from(): Standard Schema validator returned a non-object result",{expected:"Standard Schema result object",path:[...o.path],received:y(n)});const t=i;if(t.issues!==void 0){const c=t.issues[0],d=c?.message??"Standard Schema validation failed";throw new m(d,{expected:"valid value",path:[...o.path,...Q(c?.path)],received:y(a)})}return t.value}))},Y=e=>{if(e.kind==="from")return!0;const r=e._meta;if(!r)return!1;const s=[r.inner,r.keyValidator,r.valueValidator];Array.isArray(r.members)&&s.push(...r.members),r.shape!==null&&typeof r.shape=="object"&&s.push(...Object.values(r.shape));for(const a of s)if(a!==null&&typeof a=="object"&&"kind"in a&&Y(a))return!0;return!1},te=e=>{if(e.kind==="optional")return e._meta?.inner},re={any:J,array:K,bigint:T,boolean:U,bytes:D,date:F,from:X,geoPoint:M,id:q,literal:x,null:C,number:V,object:v,optional:A,partial:H,record:W,storage:B,string:L,timestamp:R,union:G};export{Y as isOrWrapsFromValidator,te as optionalInner,re as v};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/values",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.38",
|
|
4
4
|
"description": "Validators for Lunora: the v.* validator suite with end-to-end return-type inference",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@lunora/errors": "1.0.0-alpha.
|
|
49
|
+
"@lunora/errors": "1.0.0-alpha.30",
|
|
50
50
|
"@standard-schema/spec": "1.1.0"
|
|
51
51
|
},
|
|
52
52
|
"engines": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as i}from"@lunora/errors";const n=80,o=r=>r.length>n?`${r.slice(0,n)}…`:r,c=r=>{try{const{constructor:e}=r,t=e?.name;if(t!==void 0&&t!=="Object")return`object ${t}`}catch{return"object"}return"object"};class s extends i{path;expected;received;constructor(e,t){super("VALIDATION_ERROR",e,{name:"ValidationError"}),this.path=t.path,this.expected=t.expected,this.received=t.received}}const p=(r,e)=>{const t=e?.literal??!0;return r===null?"null":Array.isArray(r)?"array":r instanceof ArrayBuffer?"ArrayBuffer":typeof r=="string"?t?`string ${o(JSON.stringify(r))}`:"string":typeof r=="number"||typeof r=="boolean"?t?`${typeof r} ${String(r)}`:typeof r:typeof r=="bigint"?t?`bigint ${r.toString()}n`:"bigint":typeof r=="object"?c(r):typeof r},y=r=>r.length===0?"<root>":r.map((e,t)=>typeof e=="number"?`[${String(e)}]`:t===0?e:`.${e}`).join("");export{s as ValidationError,p as describeValue,y as formatPath};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as k}from"@lunora/errors";import{ValidationError as m,describeValue as w,formatPath as $}from"./ValidationError-BLw-y3Pk.mjs";const P=/^[^\s@]+@[^\s@.]+(?:\.[^\s@.]+)+$/u,I=e=>{if(!URL.canParse(e))return!1;const{protocol:r}=new URL(e);return r==="http:"||r==="https:"},_=new m("union branch probe miss (internal)",{expected:"",path:[],received:""});function u(e,r,s,i){if(e.probe===!0)throw _;const o=[...e.path],a=w(s,{literal:!i?.redactValue});throw new m(`Expected ${r} at ${$(o)}, received ${a}`,{expected:r,path:o,received:a})}const S=(e,r)=>{if(r===void 0)return e;const s=e?.constraints;return{...e,constraints:{...s,...r}}},l=(e,r,s)=>{const i=s?.column??{notNull:!0},o={__type:void 0,"~standard":{validate(n){const t=o.safeParse(n);return t.ok?{value:t.value}:{issues:[{message:t.error.message,path:t.error.path}]}},vendor:"lunora",version:1},_meta:{...s,column:i},_parse(n,t){return r(n,t)},kind:e,parse(n,t){return r(n,{path:[],...t})},safeParse(n,t){try{return{ok:!0,value:r(n,{path:[],...t})}}catch(c){if(c instanceof m)return{error:c,ok:!1};throw c}}},a=n=>l(e,r,{...s,column:{...i,...n}});switch(o.default=n=>a({defaultValue:n}),o.defaultNow=()=>a({defaultFn:()=>Date.now()}),o.unique=()=>a({unique:!0}),o.$defaultFn=n=>a({defaultFn:n}),o.$onUpdateFn=n=>a({onUpdateFn:n}),o.serverDefault=n=>a({serverDefault:n}),o.$type=(()=>a({})),o.nullable=()=>l(e,(t,c)=>t===null?null:r(t,c),{...s,column:{...i,notNull:!1}}),o.check=(n,t)=>{const c=typeof t=="string"?t:t?.message,f=typeof t=="string"?void 0:t?.schema;return l(e,(d,b)=>{const y=r(d,b);return n(y)||u(b,c??"value matching refinement",y,{redactValue:!0}),y},S(s,f))},o.meta=n=>{const t=n.description===void 0?n.schema:{description:n.description,...n.schema};return l(e,r,S(s,t))},e){case"array":{const n=o;n.min=t=>n.check(c=>c.length>=t,{message:`expected array length >= ${String(t)}`,schema:{minItems:t}}),n.max=t=>n.check(c=>c.length<=t,{message:`expected array length <= ${String(t)}`,schema:{maxItems:t}});break}case"number":{const n=o;n.min=t=>n.check(c=>c>=t,{message:`expected number >= ${String(t)}`,schema:{minimum:t}}),n.max=t=>n.check(c=>c<=t,{message:`expected number <= ${String(t)}`,schema:{maximum:t}}),n.int=()=>n.check(t=>Number.isInteger(t),{message:"expected an integer",schema:{type:"integer"}}),n.positive=()=>n.check(t=>t>0,{message:"expected a positive number",schema:{exclusiveMinimum:0}});break}case"string":{const n=o;n.min=t=>n.check(c=>c.length>=t,{message:`expected string length >= ${String(t)}`,schema:{minLength:t}}),n.max=t=>n.check(c=>c.length<=t,{message:`expected string length <= ${String(t)}`,schema:{maxLength:t}}),n.length=t=>n.check(c=>c.length===t,{message:`expected string length === ${String(t)}`,schema:{maxLength:t,minLength:t}}),n.pattern=t=>{const c=t.global||t.sticky?new RegExp(t.source,t.flags.replaceAll(/[gy]/gu,"")):t;return n.check(f=>c.test(f),{message:`expected string matching ${t.toString()}`,schema:{pattern:t.source}})},n.email=()=>n.check(t=>P.test(t),{message:"expected a valid email address",schema:{format:"email"}}),n.url=()=>n.check(t=>I(t),{message:"expected a valid URL",schema:{format:"uri"}});break}}return o},g=e=>e,p=e=>e,N=e=>e,O=e=>e,E=e=>e,L=()=>N(l("string",(e,r)=>(typeof e!="string"&&u(r,"string",e),e))),j=(e,r)=>((typeof e!="number"||!Number.isFinite(e))&&u(r,"number",e),e),R=()=>O(l("number",j)),V=()=>l("timestamp",j),F=()=>l("date",j),U=()=>p(l("boolean",(e,r)=>(typeof e!="boolean"&&u(r,"boolean",e),e))),C=()=>p(l("bigint",(e,r)=>(typeof e!="bigint"&&u(r,"bigint",e),e))),D=()=>p(l("null",(e,r)=>(e!==null&&u(r,"null",e),e))),T=()=>p(l("bytes",(e,r)=>(e instanceof ArrayBuffer||u(r,"ArrayBuffer",e),e))),q=e=>p(l("id",(r,s)=>(typeof r!="string"&&u(s,`Id<"${e}">`,r),r),{tableName:e})),B=e=>p(l("storage",(r,s)=>(typeof r!="string"&&u(s,"storage object key (string)",r),r),e===void 0?void 0:{bucket:e})),M=()=>p(l("geoPoint",(e,r)=>{(typeof e!="object"||e===null||Array.isArray(e))&&u(r,"geoPoint { lat, lng }",e);const s=e,{lat:i,lng:o}=s;return(typeof i!="number"||!Number.isFinite(i)||i<-90||i>90)&&(r.path.push("lat"),u(r,"latitude in [-90, 90]",i)),(typeof o!="number"||!Number.isFinite(o)||o<-180||o>180)&&(r.path.push("lng"),u(r,"longitude in [-180, 180]",o)),{lat:i,lng:o}})),x=e=>p(l("literal",(r,s)=>(r!==e&&u(s,`literal(${String(e)})`,r),r),{value:e})),K=e=>{const r=g(e);return E(l("array",(s,i)=>{Array.isArray(s)||u(i,"array",s);const{length:o}=s,a=[],{path:n}=i;for(let t=0;t<o;t+=1)n.push(t),a.push(r._parse(s[t],i)),n.pop();return a},{inner:e}))},v=(e,r)=>{const s=Object.keys(e).map(o=>{const a=g(e[o]);return{child:a,isOptional:a.kind==="optional",key:o}});if(s.some(({key:o})=>o==="__proto__"))throw new k("INTERNAL",'v.object: "__proto__" cannot be a declared field name — it collides with the Object.prototype accessor');const i=p(l("object",(o,a)=>{(typeof o!="object"||o===null||Array.isArray(o))&&u(a,"object",o);const n=o,t={},{path:c}=a;if(a.rejectUnknownKeys===!0&&r!==!0){const f=new Set(s.map(({key:d})=>d)),h=Object.keys(n).filter(d=>!f.has(d));if(h.length>0)throw new m(`object has ${String(h.length)} undeclared key(s): ${h.join(", ")}. Add them to the validator, or call .strip() on it to drop them on purpose.`,{expected:`only the declared keys (${s.map(({key:d})=>d).join(", ")})`,path:[...c],received:h.join(", ")})}for(const{child:f,isOptional:h,key:d}of s){const b=Object.hasOwn(n,d)?n[d]:void 0;b===void 0&&h||(c.push(d),t[d]=f._parse(b,a),c.pop())}return t},{shape:e}));return i.strip=()=>v(e,!0),i},W=(e,r)=>{const s=g(e),i=g(r);return p(l("record",(o,a)=>{(typeof o!="object"||o===null||Array.isArray(o))&&u(a,"record",o);const n=o,t=Object.create(null),{path:c}=a;for(const f of Object.keys(n)){c.push(f);const h=s._parse(f,a),d=i._parse(n[f],a);c.pop(),t[h]=d}return t},{keyValidator:e,valueValidator:r}))},z=(e,r,s,i)=>{const{path:o}=s;let a;for(const t of e)try{t._parse(r,s)}catch(c){if(!(c instanceof m))throw c;o.length=i,(a===void 0||c.path.length>a.path.length)&&(a=c)}if(e.length===1&&a!==void 0)throw a;const n=a===void 0?"":` (closest: expected ${a.expected} at ${$(a.path)})`;return u(s,`union of ${String(e.length)} member(s)${n}`,r)},G=(...e)=>{if(e.length===0)throw new k("INTERNAL","v.union requires at least one member");const r=e.map(s=>g(s));return p(l("union",(s,i)=>{const{path:o}=i,a=o.length,n=i.probe===!0;i.probe=!0;try{for(const t of r)try{return t._parse(s,i)}catch(c){if(!(c instanceof m))throw c;o.length=a}}finally{i.probe=n}if(n)throw _;return z(r,s,i,a)},{members:e}))},A=e=>{const r=g(e);return p(l("optional",(s,i)=>s===void 0?void 0:r._parse(s,i),{inner:e}))},H=e=>Object.fromEntries(Object.entries(e).map(([r,s])=>[r,g(s).kind==="optional"?s:A(s)])),J=()=>p(l("any",e=>e)),Q=e=>{const r=[];if(!e)return r;for(const s of e){const i=typeof s=="object"&&s!==null&&"key"in s?s.key:s;(typeof i=="string"||typeof i=="number")&&r.push(i)}return r},X=e=>{const r=e["~standard"];if(r?.version!==1||typeof r.validate!="function")throw new k("INTERNAL",'@lunora/values: v.from() expects a Standard Schema v1 object (missing or invalid "~standard")');const s=r.validate;return p(l("from",(i,o)=>{const a=s(i);if(a instanceof Promise||typeof a?.then=="function")throw new m("v.from(): async Standard Schema validators are not supported in args",{expected:"sync Standard Schema result",path:[...o.path],received:"Promise"});const n=a;if(n===null||typeof n!="object")throw new m("v.from(): Standard Schema validator returned a non-object result",{expected:"Standard Schema result object",path:[...o.path],received:w(n)});const t=a;if(t.issues!==void 0){const c=t.issues[0],f=c?.message??"Standard Schema validation failed";throw new m(f,{expected:"valid value",path:[...o.path,...Q(c?.path)],received:w(i)})}return t.value}))},Y=e=>{if(e.kind==="from")return!0;const r=e._meta;if(!r)return!1;const s=[r.inner,r.keyValidator,r.valueValidator];Array.isArray(r.members)&&s.push(...r.members),r.shape!==null&&typeof r.shape=="object"&&s.push(...Object.values(r.shape));for(const i of s)if(i!==null&&typeof i=="object"&&"kind"in i&&Y(i))return!0;return!1},te=e=>{if(e.kind==="optional")return e._meta?.inner},re={any:J,array:K,bigint:C,boolean:U,bytes:T,date:F,from:X,geoPoint:M,id:q,literal:x,null:D,number:R,object:v,optional:A,partial:H,record:W,storage:B,string:L,timestamp:V,union:G};export{Y as isOrWrapsFromValidator,te as optionalInner,re as v};
|