UNPKG

surrealdb-zod

Version:

Re-useable zod schema's for use with SurrealDB sdk

2 lines (1 loc) 3.43 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("surrealdb"),o=require("zod"),h=o.custom(e=>e instanceof n.Decimal,"Value is not a valid Decimal"),S=o.custom(e=>e instanceof n.Duration,"Value is not a valid Duration"),R=o.custom(e=>e instanceof n.Future,"Value is not a valid Future"),y=o.custom(e=>e instanceof n.GeometryPoint,"Value is not a valid GeometryPoint"),g=o.custom(e=>e instanceof n.GeometryLine,"Value is not a valid GeometryLine"),I=o.custom(e=>e instanceof n.GeometryPolygon,"Value is not a valid GeometryPolygon"),G=o.custom(e=>e instanceof n.GeometryMultiPoint,"Value is not a valid GeometryMultiPoint"),v=o.custom(e=>e instanceof n.GeometryMultiLine,"Value is not a valid GeometryMultiLine"),V=o.custom(e=>e instanceof n.GeometryMultiPolygon,"Value is not a valid GeometryPolygon"),P=o.custom(e=>e instanceof n.GeometryCollection,"Value is not a valid GeometryCollection");function p(e,t){const s=(a,c)=>a instanceof n.BoundIncluded?d(c):a instanceof n.BoundExcluded?m(c):o.undefined();return o.custom(a=>a instanceof n.Range,"Value is not a valid Range").superRefine((a,c)=>{const u=s(a.beg,e).safeParse(a.beg);if(!u.success)for(const i of u.error.issues)c.addIssue({...i,path:["value",...i.path]});const r=s(a.end,t).safeParse(a.end);if(!r.success)for(const i of r.error.issues)c.addIssue({...i,path:["value",...i.path]})})}function d(e){return o.custom(t=>t instanceof n.BoundIncluded,"Value is not a valid BoundIncluded").superRefine((t,s)=>{const a=e.safeParse(t.value);if(a.success)return o.NEVER;for(const c of a.error.issues)s.addIssue({...c,path:["value",...c.path]})})}function m(e){return o.custom(t=>t instanceof n.BoundExcluded,"Value is not a valid BoundIncluded").superRefine((t,s)=>{const a=e.safeParse(t.value);if(!a.success)for(const c of a.error.issues)s.addIssue({...c,path:["value",...c.path]})})}const b=o.custom(e=>e instanceof n.RecordIdRange,"Value is not a valid RecordIdRange");function B(e){return o.string().parse(e),o.custom(t=>t instanceof n.RecordIdRange&&t.tb===e,`Value is not a valid RecordIdRange or is not from table: ${e}`)}const l=o.custom(e=>e instanceof n.RecordId,"Value is not a valid RecordId");function f(e){return o.string().parse(e),o.custom(t=>t instanceof n.RecordId&&t.tb===e,`Value is not a valid RecordId or is not from table: ${e}`)}const M=o.custom(e=>e instanceof n.StringRecordId,"Value is not a valid StringRecordId"),O=o.object({id:l});function T(e){return o.object({id:f(e)})}const D=o.custom(e=>e instanceof n.Table,"Value is not a valid Table");function L(e){return o.string().parse(e),o.custom(t=>t instanceof n.Table&&t.tb===e,`Value is not a valid Table or is not from table: ${e}`)}const E=o.custom(e=>e instanceof n.Uuid,"Value is not a valid Uuid");exports.BoundExcludedSchema=m;exports.BoundIncludedSchema=d;exports.DecimalSchema=h;exports.DurationSchema=S;exports.FutureSchema=R;exports.GeometryCollectionSchema=P;exports.GeometryLineSchema=g;exports.GeometryMultiLineSchema=v;exports.GeometryMultiPointSchema=G;exports.GeometryMultiPolygonSchema=V;exports.GeometryPointSchema=y;exports.GeometryPolygonSchema=I;exports.RangeSchema=p;exports.RecordIdRangeSchema=b;exports.RecordIdRangeSchemaOf=B;exports.RecordIdSchema=l;exports.RecordIdSchemaOf=f;exports.RecordSchema=O;exports.RecordSchemaOf=T;exports.StringRecordIdSchema=M;exports.TableSchema=D;exports.TableSchemaOf=L;exports.UuidSchema=E;