@lunora/values 1.0.0-alpha.17 → 1.0.0-alpha.18
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
|
@@ -352,13 +352,23 @@ declare const union: <Vs extends ReadonlyArray<Validator>>(...members: Vs) => Co
|
|
|
352
352
|
declare const optional: <V extends Validator>(inner: V) => ColumnValidator<Infer<V> | undefined, Infer<V> | undefined>;
|
|
353
353
|
declare const any: () => ColumnValidator<unknown, unknown>;
|
|
354
354
|
/**
|
|
355
|
-
*
|
|
356
|
-
*
|
|
357
|
-
*
|
|
355
|
+
* The type a Standard Schema v1 object validates TO — what a read gets back.
|
|
356
|
+
*
|
|
357
|
+
* Defer to the spec's own helper rather than matching `~standard.types`: the spec
|
|
358
|
+
* declares that property optional (it is a phantom that never exists at runtime),
|
|
359
|
+
* so every real library types it as a union with `undefined`, and a hand-written
|
|
360
|
+
* `extends { output: infer O }` misses all of them. A schema that declares no
|
|
361
|
+
* `types` still resolves through the constraint to `unknown`.
|
|
358
362
|
*/
|
|
359
|
-
type InferStandardOutput<S extends StandardSchemaV1> = S
|
|
360
|
-
|
|
361
|
-
|
|
363
|
+
type InferStandardOutput<S extends StandardSchemaV1> = StandardSchemaV1.InferOutput<S>;
|
|
364
|
+
/**
|
|
365
|
+
* The type a Standard Schema v1 object validates FROM — what a write supplies.
|
|
366
|
+
*
|
|
367
|
+
* Distinct from {@link InferStandardOutput} only for a transforming schema
|
|
368
|
+
* (`z.string().transform(…)`, `z.coerce.number()`), where the value handed in is
|
|
369
|
+
* not the value stored. Identical for everything else.
|
|
370
|
+
*/
|
|
371
|
+
type InferStandardInput<S extends StandardSchemaV1> = StandardSchemaV1.InferInput<S>;
|
|
362
372
|
/**
|
|
363
373
|
* Wrap any Standard Schema v1 validator (`zod`, `valibot`, `arktype`, …) so it
|
|
364
374
|
* can be used as an args validator in `query`/`mutation`/`action`, or as a table
|
|
@@ -385,8 +395,15 @@ type InferStandardOutput<S extends StandardSchemaV1> = S["~standard"]["types"] e
|
|
|
385
395
|
*
|
|
386
396
|
* **Sync-only.** Standard Schema allows async `validate`; Lunora validation is
|
|
387
397
|
* synchronous and throws when a Promise is returned.
|
|
398
|
+
*
|
|
399
|
+
* **Reads and writes can differ.** A write supplies the schema's INPUT and a read
|
|
400
|
+
* gets its OUTPUT back, because what is stored is `validate()`'s result. The two
|
|
401
|
+
* coincide for every non-transforming schema; they part for `z.coerce.number()`
|
|
402
|
+
* and friends, where typing the insert side as the output would demand the
|
|
403
|
+
* post-transform value from a caller whose value the validator is there to
|
|
404
|
+
* transform.
|
|
388
405
|
*/
|
|
389
|
-
declare const from: <S extends StandardSchemaV1>(schema: S) => ColumnValidator<InferStandardOutput<S>,
|
|
406
|
+
declare const from: <S extends StandardSchemaV1>(schema: S) => ColumnValidator<InferStandardOutput<S>, InferStandardInput<S>>;
|
|
390
407
|
/**
|
|
391
408
|
* True when `validator` is `v.from(...)` or structurally wraps one through
|
|
392
409
|
* `v.optional` / `v.array` / `v.object` / `v.record` / `v.union`. The nested
|
|
@@ -593,4 +610,4 @@ declare const installCompiledValidatorMap: (validators: object, compiled: Compil
|
|
|
593
610
|
* which case the interpreted loop below runs and owns the result (and any error).
|
|
594
611
|
*/
|
|
595
612
|
declare const parseValidatorMap: (validators: ValidatorMap, source: Record<string, unknown>, label: string) => Record<string, unknown>;
|
|
596
|
-
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 InferStandardOutput, type InferValidatorMap, type InsertShape, type JsonSchema, type JsonSchemaFragment, type MetaOptions, type NumberColumnValidator, type SchemaNodeReader, type SelectShape, type ServerDefaultContext, type StringColumnValidator, type TimestampColumnValidator, ValidationError, type ValidationPath, type Validator, type ValidatorKind, type ValidatorMap, argsToJsonSchema, describeValue, formatPath, installCompiledValidatorMap, isOrWrapsFromValidator, jsonSchemaFromNode, objectSchemaFromNodes, optionalInner, parseValidatorMap, toJsonSchema, v };
|
|
613
|
+
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 SchemaNodeReader, type SelectShape, type ServerDefaultContext, type StringColumnValidator, type TimestampColumnValidator, ValidationError, type ValidationPath, type Validator, type ValidatorKind, type ValidatorMap, argsToJsonSchema, describeValue, formatPath, installCompiledValidatorMap, isOrWrapsFromValidator, jsonSchemaFromNode, objectSchemaFromNodes, optionalInner, parseValidatorMap, toJsonSchema, v };
|
package/dist/index.d.ts
CHANGED
|
@@ -352,13 +352,23 @@ declare const union: <Vs extends ReadonlyArray<Validator>>(...members: Vs) => Co
|
|
|
352
352
|
declare const optional: <V extends Validator>(inner: V) => ColumnValidator<Infer<V> | undefined, Infer<V> | undefined>;
|
|
353
353
|
declare const any: () => ColumnValidator<unknown, unknown>;
|
|
354
354
|
/**
|
|
355
|
-
*
|
|
356
|
-
*
|
|
357
|
-
*
|
|
355
|
+
* The type a Standard Schema v1 object validates TO — what a read gets back.
|
|
356
|
+
*
|
|
357
|
+
* Defer to the spec's own helper rather than matching `~standard.types`: the spec
|
|
358
|
+
* declares that property optional (it is a phantom that never exists at runtime),
|
|
359
|
+
* so every real library types it as a union with `undefined`, and a hand-written
|
|
360
|
+
* `extends { output: infer O }` misses all of them. A schema that declares no
|
|
361
|
+
* `types` still resolves through the constraint to `unknown`.
|
|
358
362
|
*/
|
|
359
|
-
type InferStandardOutput<S extends StandardSchemaV1> = S
|
|
360
|
-
|
|
361
|
-
|
|
363
|
+
type InferStandardOutput<S extends StandardSchemaV1> = StandardSchemaV1.InferOutput<S>;
|
|
364
|
+
/**
|
|
365
|
+
* The type a Standard Schema v1 object validates FROM — what a write supplies.
|
|
366
|
+
*
|
|
367
|
+
* Distinct from {@link InferStandardOutput} only for a transforming schema
|
|
368
|
+
* (`z.string().transform(…)`, `z.coerce.number()`), where the value handed in is
|
|
369
|
+
* not the value stored. Identical for everything else.
|
|
370
|
+
*/
|
|
371
|
+
type InferStandardInput<S extends StandardSchemaV1> = StandardSchemaV1.InferInput<S>;
|
|
362
372
|
/**
|
|
363
373
|
* Wrap any Standard Schema v1 validator (`zod`, `valibot`, `arktype`, …) so it
|
|
364
374
|
* can be used as an args validator in `query`/`mutation`/`action`, or as a table
|
|
@@ -385,8 +395,15 @@ type InferStandardOutput<S extends StandardSchemaV1> = S["~standard"]["types"] e
|
|
|
385
395
|
*
|
|
386
396
|
* **Sync-only.** Standard Schema allows async `validate`; Lunora validation is
|
|
387
397
|
* synchronous and throws when a Promise is returned.
|
|
398
|
+
*
|
|
399
|
+
* **Reads and writes can differ.** A write supplies the schema's INPUT and a read
|
|
400
|
+
* gets its OUTPUT back, because what is stored is `validate()`'s result. The two
|
|
401
|
+
* coincide for every non-transforming schema; they part for `z.coerce.number()`
|
|
402
|
+
* and friends, where typing the insert side as the output would demand the
|
|
403
|
+
* post-transform value from a caller whose value the validator is there to
|
|
404
|
+
* transform.
|
|
388
405
|
*/
|
|
389
|
-
declare const from: <S extends StandardSchemaV1>(schema: S) => ColumnValidator<InferStandardOutput<S>,
|
|
406
|
+
declare const from: <S extends StandardSchemaV1>(schema: S) => ColumnValidator<InferStandardOutput<S>, InferStandardInput<S>>;
|
|
390
407
|
/**
|
|
391
408
|
* True when `validator` is `v.from(...)` or structurally wraps one through
|
|
392
409
|
* `v.optional` / `v.array` / `v.object` / `v.record` / `v.union`. The nested
|
|
@@ -593,4 +610,4 @@ declare const installCompiledValidatorMap: (validators: object, compiled: Compil
|
|
|
593
610
|
* which case the interpreted loop below runs and owns the result (and any error).
|
|
594
611
|
*/
|
|
595
612
|
declare const parseValidatorMap: (validators: ValidatorMap, source: Record<string, unknown>, label: string) => Record<string, unknown>;
|
|
596
|
-
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 InferStandardOutput, type InferValidatorMap, type InsertShape, type JsonSchema, type JsonSchemaFragment, type MetaOptions, type NumberColumnValidator, type SchemaNodeReader, type SelectShape, type ServerDefaultContext, type StringColumnValidator, type TimestampColumnValidator, ValidationError, type ValidationPath, type Validator, type ValidatorKind, type ValidatorMap, argsToJsonSchema, describeValue, formatPath, installCompiledValidatorMap, isOrWrapsFromValidator, jsonSchemaFromNode, objectSchemaFromNodes, optionalInner, parseValidatorMap, toJsonSchema, v };
|
|
613
|
+
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 SchemaNodeReader, type SelectShape, type ServerDefaultContext, type StringColumnValidator, type TimestampColumnValidator, ValidationError, type ValidationPath, type Validator, type ValidatorKind, type ValidatorMap, argsToJsonSchema, describeValue, formatPath, installCompiledValidatorMap, isOrWrapsFromValidator, 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-5sbiLWie.mjs";import{jsonSchemaFromNode as p,objectSchemaFromNodes as i}from"./packem_shared/jsonSchemaFromNode-k28QmNzA.mjs";import{argsToJsonSchema as l,toJsonSchema as d}from"./packem_shared/argsToJsonSchema-C4oyUJUg.mjs";import{isOrWrapsFromValidator as c,optionalInner as f,v as V}from"./packem_shared/isOrWrapsFromValidator-
|
|
1
|
+
import{ValidationError as a,describeValue as e,formatPath as t}from"./packem_shared/ValidationError-5sbiLWie.mjs";import{jsonSchemaFromNode as p,objectSchemaFromNodes as i}from"./packem_shared/jsonSchemaFromNode-k28QmNzA.mjs";import{argsToJsonSchema as l,toJsonSchema as d}from"./packem_shared/argsToJsonSchema-C4oyUJUg.mjs";import{isOrWrapsFromValidator as c,optionalInner as f,v as V}from"./packem_shared/isOrWrapsFromValidator-Bzzgk4ZM.mjs";import{DEFER_VALIDATION as x,installCompiledValidatorMap as F,parseValidatorMap as S}from"./packem_shared/DEFER_VALIDATION-CNrZDGXy.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{LunoraError as v}from"@lunora/errors";import{ValidationError as h,formatPath as x,describeValue as
|
|
1
|
+
import{LunoraError as v}from"@lunora/errors";import{ValidationError as h,formatPath as x,describeValue as b}from"./ValidationError-5sbiLWie.mjs";const j=/^[^\s@]+@[^\s@.]+(?:\.[^\s@.]+)+$/u,S=e=>{if(!URL.canParse(e))return!1;const{protocol:r}=new URL(e);return r==="http:"||r==="https:"};function p(e,r,n,o){const s=[...e.path],i=b(n,{literal:!o?.redactValue});throw new h(`Expected ${r} at ${x(s)}, received ${i}`,{expected:r,path:s,received:i})}const k=(e,r)=>{if(r===void 0)return e;const n=e?.constraints;return{...e,constraints:{...n,...r}}},l=(e,r,n)=>{const o=n?.column??{notNull:!0},s={__type:void 0,"~standard":{validate(a){const t=s.safeParse(a);return t.ok?{value:t.value}:{issues:[{message:t.error.message,path:t.error.path}]}},vendor:"lunora",version:1},_meta:{...n,column:o},_parse(a,t){return r(a,t)},kind:e,parse(a){return r(a,{path:[]})},safeParse(a){try{return{ok:!0,value:r(a,{path:[]})}}catch(t){if(t instanceof h)return{error:t,ok:!1};throw t}}},i=a=>l(e,r,{...n,column:{...o,...a}});switch(s.default=a=>i({defaultValue:a}),s.defaultNow=()=>i({defaultFn:()=>Date.now()}),s.unique=()=>i({unique:!0}),s.$defaultFn=a=>i({defaultFn:a}),s.$onUpdateFn=a=>i({onUpdateFn:a}),s.serverDefault=a=>i({serverDefault:a}),s.$type=(()=>i({})),s.nullable=()=>l(e,(a,t)=>a===null?null:r(a,t),{...n,column:{...o,notNull:!1}}),s.check=(a,t)=>{const c=typeof t=="string"?t:t?.message,u=typeof t=="string"?void 0:t?.schema;return l(e,(d,f)=>{const y=r(d,f);return a(y)||p(f,c??"value matching refinement",y,{redactValue:!0}),y},k(n,u))},s.meta=a=>{const t=a.description===void 0?a.schema:{description:a.description,...a.schema};return l(e,r,k(n,t))},e){case"array":{const a=s;a.min=t=>a.check(c=>c.length>=t,{message:`expected array length >= ${String(t)}`,schema:{minItems:t}}),a.max=t=>a.check(c=>c.length<=t,{message:`expected array length <= ${String(t)}`,schema:{maxItems:t}});break}case"number":{const a=s;a.min=t=>a.check(c=>c>=t,{message:`expected number >= ${String(t)}`,schema:{minimum:t}}),a.max=t=>a.check(c=>c<=t,{message:`expected number <= ${String(t)}`,schema:{maximum:t}}),a.int=()=>a.check(t=>Number.isInteger(t),{message:"expected an integer",schema:{type:"integer"}}),a.positive=()=>a.check(t=>t>0,{message:"expected a positive number",schema:{exclusiveMinimum:0}});break}case"string":{const a=s;a.min=t=>a.check(c=>c.length>=t,{message:`expected string length >= ${String(t)}`,schema:{minLength:t}}),a.max=t=>a.check(c=>c.length<=t,{message:`expected string length <= ${String(t)}`,schema:{maxLength:t}}),a.length=t=>a.check(c=>c.length===t,{message:`expected string length === ${String(t)}`,schema:{maxLength:t,minLength:t}}),a.pattern=t=>{const c=t.global||t.sticky?new RegExp(t.source,t.flags.replaceAll(/[gy]/gu,"")):t;return a.check(u=>c.test(u),{message:`expected string matching ${t.toString()}`,schema:{pattern:t.source}})},a.email=()=>a.check(t=>j.test(t),{message:"expected a valid email address",schema:{format:"email"}}),a.url=()=>a.check(t=>S(t),{message:"expected a valid URL",schema:{format:"uri"}});break}}return s},g=e=>e,m=e=>e,$=e=>e,_=e=>e,A=e=>e,N=()=>$(l("string",(e,r)=>(typeof e!="string"&&p(r,"string",e),e))),L=()=>_(l("number",(e,r)=>((typeof e!="number"||!Number.isFinite(e))&&p(r,"number",e),e))),w=(e,r)=>((typeof e!="number"||!Number.isFinite(e))&&p(r,"number",e),e),V=()=>l("timestamp",w),F=()=>l("date",w),O=()=>m(l("boolean",(e,r)=>(typeof e!="boolean"&&p(r,"boolean",e),e))),P=()=>m(l("bigint",(e,r)=>(typeof e!="bigint"&&p(r,"bigint",e),e))),E=()=>m(l("null",(e,r)=>(e!==null&&p(r,"null",e),e))),R=()=>m(l("bytes",(e,r)=>(e instanceof ArrayBuffer||p(r,"ArrayBuffer",e),e))),I=e=>m(l("id",(r,n)=>(typeof r!="string"&&p(n,`Id<"${e}">`,r),r),{tableName:e})),U=e=>m(l("storage",(r,n)=>(typeof r!="string"&&p(n,"storage object key (string)",r),r),e===void 0?void 0:{bucket:e})),q=()=>m(l("geoPoint",(e,r)=>{(typeof e!="object"||e===null||Array.isArray(e))&&p(r,"geoPoint { lat, lng }",e);const n=e,{lat:o,lng:s}=n;return(typeof o!="number"||!Number.isFinite(o)||o<-90||o>90)&&(r.path.push("lat"),p(r,"latitude in [-90, 90]",o)),(typeof s!="number"||!Number.isFinite(s)||s<-180||s>180)&&(r.path.push("lng"),p(r,"longitude in [-180, 180]",s)),{lat:o,lng:s}})),D=e=>m(l("literal",(r,n)=>(r!==e&&p(n,`literal(${String(e)})`,r),r),{value:e})),T=e=>{const r=g(e);return A(l("array",(n,o)=>{Array.isArray(n)||p(o,"array",n);const{length:s}=n,i=[],{path:a}=o;for(let t=0;t<s;t+=1)a.push(t),i.push(r._parse(n[t],o)),a.pop();return i},{inner:e}))},B=e=>{const r=Object.keys(e).map(n=>{const o=g(e[n]);return{child:o,isOptional:o.kind==="optional",key:n}});if(r.some(({key:n})=>n==="__proto__"))throw new v("INTERNAL",'v.object: "__proto__" cannot be a declared field name — it collides with the Object.prototype accessor');return m(l("object",(n,o)=>{(typeof n!="object"||n===null||Array.isArray(n))&&p(o,"object",n);const s=n,i={},{path:a}=o;for(const{child:t,isOptional:c,key:u}of r){const d=Object.hasOwn(s,u)?s[u]:void 0;d===void 0&&c||(a.push(u),i[u]=t._parse(d,o),a.pop())}return i},{shape:e}))},M=(e,r)=>{const n=g(e),o=g(r);return m(l("record",(s,i)=>{(typeof s!="object"||s===null||Array.isArray(s))&&p(i,"record",s);const a=s,t=Object.create(null),{path:c}=i;for(const u of Object.keys(a)){c.push(u);const d=n._parse(u,i),f=o._parse(a[u],i);c.pop(),t[d]=f}return t},{keyValidator:e,valueValidator:r}))},W=(...e)=>{if(e.length===0)throw new v("INTERNAL","v.union requires at least one member");const r=e.map(n=>g(n));return m(l("union",(n,o)=>{let s;const{path:i}=o,a=i.length;for(const c of r)try{return c._parse(n,o)}catch(u){if(!(u instanceof h))throw u;i.length=a,(s===void 0||u.path.length>s.path.length)&&(s=u)}if(r.length===1&&s!==void 0)throw s;const t=s===void 0?"":` (closest: expected ${s.expected} at ${x(s.path)})`;return p(o,`union of ${String(e.length)} member(s)${t}`,n)},{members:e}))},z=e=>{const r=g(e);return m(l("optional",(n,o)=>n===void 0?void 0:r._parse(n,o),{inner:e}))},G=()=>m(l("any",e=>e)),H=e=>{const r=[];if(!e)return r;for(const n of e){const o=typeof n=="object"&&n!==null&&"key"in n?n.key:n;(typeof o=="string"||typeof o=="number")&&r.push(o)}return r},J=e=>{const r=e["~standard"];if(r?.version!==1||typeof r.validate!="function")throw new v("INTERNAL",'@lunora/values: v.from() expects a Standard Schema v1 object (missing or invalid "~standard")');const n=r.validate;return m(l("from",(o,s)=>{const i=n(o);if(i instanceof Promise||typeof i?.then=="function")throw new h("v.from(): async Standard Schema validators are not supported in args",{expected:"sync Standard Schema result",path:[...s.path],received:"Promise"});const a=i;if(a===null||typeof a!="object")throw new h("v.from(): Standard Schema validator returned a non-object result",{expected:"Standard Schema result object",path:[...s.path],received:b(a)});const t=i;if(t.issues!==void 0){const c=t.issues[0],u=c?.message??"Standard Schema validation failed";throw new h(u,{expected:"valid value",path:[...s.path,...H(c?.path)],received:b(o)})}return t.value}))},K=e=>{if(e.kind==="from")return!0;const r=e._meta;if(!r)return!1;const n=[r.inner,r.keyValidator,r.valueValidator];Array.isArray(r.members)&&n.push(...r.members),r.shape!==null&&typeof r.shape=="object"&&n.push(...Object.values(r.shape));for(const o of n)if(o!==null&&typeof o=="object"&&"kind"in o&&K(o))return!0;return!1},C=e=>{if(e.kind==="optional")return e._meta?.inner},Y={any:G,array:T,bigint:P,boolean:O,bytes:R,date:F,from:J,geoPoint:q,id:I,literal:D,null:E,number:L,object:B,optional:z,record:M,storage:U,string:N,timestamp:V,union:W};export{K as isOrWrapsFromValidator,C as optionalInner,Y 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.18",
|
|
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,8 @@
|
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@lunora/errors": "1.0.0-alpha.13"
|
|
49
|
+
"@lunora/errors": "1.0.0-alpha.13",
|
|
50
|
+
"@standard-schema/spec": "1.1.0"
|
|
50
51
|
},
|
|
51
52
|
"engines": {
|
|
52
53
|
"node": "^22.15.0 || >=24.11.0"
|