UNPKG

surrealdb-zod

Version:

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

122 lines (121 loc) 4.21 kB
import { Decimal as h, Duration as y, Future as R, GeometryPoint as S, GeometryLine as p, GeometryPolygon as g, GeometryMultiPoint as V, GeometryMultiLine as v, GeometryMultiPolygon as G, GeometryCollection as I, RecordIdRange as r, RecordId as d, StringRecordId as P, Table as l, Uuid as b, Range as B, BoundIncluded as m, BoundExcluded as f } from "surrealdb"; import { z as o } from "zod"; const C = o.custom((e) => e instanceof h, "Value is not a valid Decimal", !0), F = o.custom((e) => e instanceof y, "Value is not a valid Duration", !0), U = o.custom((e) => e instanceof R, "Value is not a valid Future", !0), $ = o.custom((e) => e instanceof S, "Value is not a valid GeometryPoint", !0), j = o.custom((e) => e instanceof p, "Value is not a valid GeometryLine", !0), z = o.custom((e) => e instanceof g, "Value is not a valid GeometryPolygon", !0), N = o.custom((e) => e instanceof V, "Value is not a valid GeometryMultiPoint", !0), k = o.custom((e) => e instanceof v, "Value is not a valid GeometryMultiLine", !0), q = o.custom((e) => e instanceof G, "Value is not a valid GeometryPolygon", !0), w = o.custom((e) => e instanceof I, "Value is not a valid GeometryCollection", !0); function A(e, t) { const s = (n, a) => n instanceof m ? M(a) : n instanceof f ? D(a) : o.undefined(); return o.custom( (n) => n instanceof B, "Value is not a valid Range", !0 ).superRefine( (n, a) => { const i = s(n.beg, e).safeParse(n.beg); if (!i.success) for (const u of i.error.issues) a.addIssue({ ...u, path: [...a.path, "value", ...u.path] }); const c = s(n.end, t).safeParse(n.end); if (!c.success) for (const u of c.error.issues) a.addIssue({ ...u, path: [...a.path, "value", ...u.path] }); } ); } function M(e) { return o.custom( (t) => t instanceof m, "Value is not a valid BoundIncluded", !0 ).superRefine( (t, s) => { const n = e.safeParse(t.value); if (n.success) return o.NEVER; for (const a of n.error.issues) s.addIssue({ ...a, path: [...s.path, "value", ...a.path] }); } ); } function D(e) { return o.custom( (t) => t instanceof f, "Value is not a valid BoundIncluded", !0 ).superRefine( (t, s) => { const n = e.safeParse(t.value); if (!n.success) for (const a of n.error.issues) s.addIssue({ ...a, path: [...s.path, "value", ...a.path] }); } ); } const H = o.custom((e) => e instanceof r, "Value is not a valid RecordIdRange", !0); function J(e) { return o.string().parse(e), o.custom( (t) => t instanceof r && t.tb === e, `Value is not a valid RecordIdRange or is not from table: ${e}`, !0 ); } const L = o.custom((e) => e instanceof d, "Value is not a valid RecordId", !0); function E(e) { return o.string().parse(e), o.custom( (t) => t instanceof d && t.tb === e, `Value is not a valid RecordId or is not from table: ${e}`, !0 ); } const K = o.custom((e) => e instanceof P, "Value is not a valid StringRecordId", !0), Q = o.object({ id: L }); function W(e) { return o.object({ id: E(e) }); } const X = o.custom((e) => e instanceof l, "Value is not a valid Table", !0); function Y(e) { return o.string().parse(e), o.custom( (t) => t instanceof l && t.tb === e, `Value is not a valid Table or is not from table: ${e}`, !0 ); } const Z = o.custom((e) => e instanceof b, "Value is not a valid Uuid", !0); export { D as BoundExcludedSchema, M as BoundIncludedSchema, C as DecimalSchema, F as DurationSchema, U as FutureSchema, w as GeometryCollectionSchema, j as GeometryLineSchema, k as GeometryMultiLineSchema, N as GeometryMultiPointSchema, q as GeometryMultiPolygonSchema, $ as GeometryPointSchema, z as GeometryPolygonSchema, A as RangeSchema, H as RecordIdRangeSchema, J as RecordIdRangeSchemaOf, L as RecordIdSchema, E as RecordIdSchemaOf, Q as RecordSchema, W as RecordSchemaOf, K as StringRecordIdSchema, X as TableSchema, Y as TableSchemaOf, Z as UuidSchema };