@lunora/values 1.0.0-alpha.71 → 1.0.0-alpha.73
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.d.mts
CHANGED
|
@@ -501,6 +501,15 @@ declare const isOrWrapsFromValidator: (validator: Validator) => boolean;
|
|
|
501
501
|
* @returns The inner validator if `v.optional(...)`, otherwise `undefined`.
|
|
502
502
|
*/
|
|
503
503
|
declare const optionalInner: (validator: Validator) => Validator | undefined;
|
|
504
|
+
/**
|
|
505
|
+
* True when every value `validator` accepts is a string: `v.string()`, `v.id()`,
|
|
506
|
+
* `v.storage()`, a `v.literal("…")`, or a `v.union(...)` of those. For tooling
|
|
507
|
+
* that carries a value as a string on a wire (a URL segment, a topic key) and
|
|
508
|
+
* must refuse, up front, a validator that could never match it. The members of a
|
|
509
|
+
* union and the value of a literal live on `_meta`; this accessor keeps that
|
|
510
|
+
* knowledge in the package that owns validator internals.
|
|
511
|
+
*/
|
|
512
|
+
declare const isStringValidator: (validator: Validator) => boolean;
|
|
504
513
|
/**
|
|
505
514
|
* Validator/codec namespace. Each factory returns a {@link Validator} with a
|
|
506
515
|
* runtime `parse`/`safeParse` plus a phantom `__type` field for inference.
|
|
@@ -719,4 +728,4 @@ declare const installCompiledValidatorMap: (validators: object, compiled: Compil
|
|
|
719
728
|
* which case the interpreted loop below runs and owns the result (and any error).
|
|
720
729
|
*/
|
|
721
730
|
declare const parseValidatorMap: (validators: ValidatorMap, source: Record<string, unknown>, label: string) => Record<string, unknown>;
|
|
722
|
-
export { type ArrayColumnValidator, type CheckOptions, type Column, type ColumnMeta, type ColumnValidator, type CompiledValidatorMap, DEFER_VALIDATION, type GeoPoint, type Id, type Infer, type InferInsert, type InferSelect, type InferStandardInput, type InferStandardOutput, type InferValidatorMap, type InsertShape, type JsonSchema, type JsonSchemaFragment, type MetaOptions, type NumberColumnValidator, type ObjectColumnValidator, type ParseOptions, type SchemaNodeReader, type SelectShape, type ServerDefaultContext, type StringColumnValidator, type TimestampColumnValidator, ValidationError, type ValidationPath, type Validator, type ValidatorKind, type ValidatorMap, acceptsAbsent, argsToJsonSchema, cyrb53, describeValue, formatPath, installCompiledValidatorMap, isOrWrapsFromValidator, jsonSchemaFromNode, objectSchemaFromNodes, optionalInner, parseValidatorMap, toJsonSchema, v };
|
|
731
|
+
export { type ArrayColumnValidator, type CheckOptions, type Column, type ColumnMeta, type ColumnValidator, type CompiledValidatorMap, DEFER_VALIDATION, type GeoPoint, type Id, type Infer, type InferInsert, type InferSelect, type InferStandardInput, type InferStandardOutput, type InferValidatorMap, type InsertShape, type JsonSchema, type JsonSchemaFragment, type MetaOptions, type NumberColumnValidator, type ObjectColumnValidator, type ParseOptions, type SchemaNodeReader, type SelectShape, type ServerDefaultContext, type StringColumnValidator, type TimestampColumnValidator, ValidationError, type ValidationPath, type Validator, type ValidatorKind, type ValidatorMap, acceptsAbsent, argsToJsonSchema, cyrb53, describeValue, formatPath, installCompiledValidatorMap, isOrWrapsFromValidator, isStringValidator, jsonSchemaFromNode, objectSchemaFromNodes, optionalInner, parseValidatorMap, toJsonSchema, v };
|
package/dist/index.d.ts
CHANGED
|
@@ -501,6 +501,15 @@ declare const isOrWrapsFromValidator: (validator: Validator) => boolean;
|
|
|
501
501
|
* @returns The inner validator if `v.optional(...)`, otherwise `undefined`.
|
|
502
502
|
*/
|
|
503
503
|
declare const optionalInner: (validator: Validator) => Validator | undefined;
|
|
504
|
+
/**
|
|
505
|
+
* True when every value `validator` accepts is a string: `v.string()`, `v.id()`,
|
|
506
|
+
* `v.storage()`, a `v.literal("…")`, or a `v.union(...)` of those. For tooling
|
|
507
|
+
* that carries a value as a string on a wire (a URL segment, a topic key) and
|
|
508
|
+
* must refuse, up front, a validator that could never match it. The members of a
|
|
509
|
+
* union and the value of a literal live on `_meta`; this accessor keeps that
|
|
510
|
+
* knowledge in the package that owns validator internals.
|
|
511
|
+
*/
|
|
512
|
+
declare const isStringValidator: (validator: Validator) => boolean;
|
|
504
513
|
/**
|
|
505
514
|
* Validator/codec namespace. Each factory returns a {@link Validator} with a
|
|
506
515
|
* runtime `parse`/`safeParse` plus a phantom `__type` field for inference.
|
|
@@ -719,4 +728,4 @@ declare const installCompiledValidatorMap: (validators: object, compiled: Compil
|
|
|
719
728
|
* which case the interpreted loop below runs and owns the result (and any error).
|
|
720
729
|
*/
|
|
721
730
|
declare const parseValidatorMap: (validators: ValidatorMap, source: Record<string, unknown>, label: string) => Record<string, unknown>;
|
|
722
|
-
export { type ArrayColumnValidator, type CheckOptions, type Column, type ColumnMeta, type ColumnValidator, type CompiledValidatorMap, DEFER_VALIDATION, type GeoPoint, type Id, type Infer, type InferInsert, type InferSelect, type InferStandardInput, type InferStandardOutput, type InferValidatorMap, type InsertShape, type JsonSchema, type JsonSchemaFragment, type MetaOptions, type NumberColumnValidator, type ObjectColumnValidator, type ParseOptions, type SchemaNodeReader, type SelectShape, type ServerDefaultContext, type StringColumnValidator, type TimestampColumnValidator, ValidationError, type ValidationPath, type Validator, type ValidatorKind, type ValidatorMap, acceptsAbsent, argsToJsonSchema, cyrb53, describeValue, formatPath, installCompiledValidatorMap, isOrWrapsFromValidator, jsonSchemaFromNode, objectSchemaFromNodes, optionalInner, parseValidatorMap, toJsonSchema, v };
|
|
731
|
+
export { type ArrayColumnValidator, type CheckOptions, type Column, type ColumnMeta, type ColumnValidator, type CompiledValidatorMap, DEFER_VALIDATION, type GeoPoint, type Id, type Infer, type InferInsert, type InferSelect, type InferStandardInput, type InferStandardOutput, type InferValidatorMap, type InsertShape, type JsonSchema, type JsonSchemaFragment, type MetaOptions, type NumberColumnValidator, type ObjectColumnValidator, type ParseOptions, type SchemaNodeReader, type SelectShape, type ServerDefaultContext, type StringColumnValidator, type TimestampColumnValidator, ValidationError, type ValidationPath, type Validator, type ValidatorKind, type ValidatorMap, acceptsAbsent, argsToJsonSchema, cyrb53, describeValue, formatPath, installCompiledValidatorMap, isOrWrapsFromValidator, isStringValidator, jsonSchemaFromNode, objectSchemaFromNodes, optionalInner, parseValidatorMap, toJsonSchema, v };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ValidationError as a,describeValue as e,formatPath as t}from"./packem_shared/ValidationError-BdVoGndu.mjs";import{cyrb53 as
|
|
1
|
+
import{ValidationError as a,describeValue as e,formatPath as t}from"./packem_shared/ValidationError-BdVoGndu.mjs";import{cyrb53 as i}from"./packem_shared/cyrb53-CFiior4X.mjs";import{acceptsAbsent as s,jsonSchemaFromNode as l,objectSchemaFromNodes as n}from"./packem_shared/acceptsAbsent-Biqy6mRN.mjs";import{argsToJsonSchema as d,toJsonSchema as f}from"./packem_shared/argsToJsonSchema-ATrQFtr_.mjs";import{isOrWrapsFromValidator as x,isStringValidator as h,optionalInner as S,v as b}from"./packem_shared/isOrWrapsFromValidator-CpKb4P21.mjs";import{DEFER_VALIDATION as A,installCompiledValidatorMap as E,parseValidatorMap as I}from"./packem_shared/DEFER_VALIDATION-C0nIiPG-.mjs";export{A as DEFER_VALIDATION,a as ValidationError,s as acceptsAbsent,d as argsToJsonSchema,i as cyrb53,e as describeValue,t as formatPath,E as installCompiledValidatorMap,x as isOrWrapsFromValidator,h as isStringValidator,l as jsonSchemaFromNode,n as objectSchemaFromNodes,S as optionalInner,I as parseValidatorMap,f as toJsonSchema,b as v};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{LunoraError as k}from"@lunora/errors";import{ValidationError as m,describeValue as y,formatPath as
|
|
1
|
+
import{LunoraError as k}from"@lunora/errors";import{ValidationError as m,describeValue as y,formatPath as _}from"./ValidationError-BdVoGndu.mjs";const v=/^[^\s@]+@[^\s@.]+(?:\.[^\s@.]+)+$/u,O=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=y(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,(p,b)=>{const w=r(p,b);return n(w)||u(b,c??"value matching refinement",w,{redactValue:!0}),w},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=>v.test(t),{message:"expected a valid email address",schema:{format:"email"}}),n.url=()=>n.check(t=>O(t),{message:"expected a valid URL",schema:{format:"uri"}});break}}return o},g=e=>e,h=e=>e,I=e=>e,N=e=>e,V=e=>e,L=()=>I(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),E=()=>N(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)=>ArrayBuffer.isView(e)?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):(e instanceof ArrayBuffer||u(r,"ArrayBuffer",e),e))),B=e=>h(l("id",(r,s)=>(typeof r!="string"&&u(s,`Id<"${e}">`,r),r),{tableName:e})),q=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: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=>h(l("literal",(r,s)=>(r!==e&&u(s,`literal(${String(e)})`,r),r),{value:e})),K=e=>{const r=g(e);return V(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}))},A=(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=h(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:p})=>p)),d=Object.keys(n).filter(p=>!f.has(p));if(d.length>0)throw new m(`object has ${String(d.length)} undeclared key(s): ${d.join(", ")}. Add them to the validator, or call .strip() on it to drop them on purpose.`,{expected:`only the declared keys (${s.map(({key:p})=>p).join(", ")})`,path:[...c],received:d.join(", ")})}for(const{child:f,isOptional:d,key:p}of s){const b=Object.hasOwn(n,p)?n[p]:void 0;b===void 0&&d||(c.push(p),t[p]=f._parse(b,a),c.pop())}return t},{shape:e}));return i.strip=()=>A(e,!0),i},W=(e,r)=>{const s=g(e),i=g(r);return h(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 d=s._parse(f,a),p=i._parse(n[f],a);c.pop(),t[d]=p}return t},{keyValidator:e,valueValidator:r}))},z=(e,r,s,i)=>{const{path:o}=s;let a;const n=y(r,{literal:!1});let t=!1;for(const f of e)try{f._parse(r,s)}catch(d){if(!(d instanceof m))throw d;o.length=i,t||=d.received===n,(a===void 0||d.path.length>a.path.length)&&(a=d)}if(e.length===1&&a!==void 0)throw a;const c=a===void 0?"":` (closest: expected ${a.expected} at ${_(a.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,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}))},P=e=>{const r=g(e);return h(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:P(s)])),J=()=>h(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 h(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:y(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:y(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},re=e=>{if(e.kind==="optional")return e._meta?.inner},Z=e=>{switch(e.kind){case"id":case"storage":case"string":return!0;case"literal":return typeof e._meta?.value=="string";case"union":return e._meta?.members?.every(s=>Z(s))??!1;default:return!1}},ne={any:J,array:K,bigint:T,boolean:U,bytes:D,date:F,from:X,geoPoint:M,id:B,literal:x,null:C,number:E,object:A,optional:P,partial:H,record:W,storage:q,string:L,timestamp:R,union:G};export{Y as isOrWrapsFromValidator,Z as isStringValidator,re as optionalInner,ne as v};
|