UNPKG

surrealdb-zod

Version:

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

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