UNPKG

surrealdb-zod

Version:

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

45 lines (44 loc) 4.32 kB
import { BoundExcluded, BoundIncluded, DateTime, Decimal, Duration, FileRef, Future, Geometry, GeometryCollection, GeometryLine, GeometryMultiLine, GeometryMultiPoint, GeometryMultiPolygon, GeometryPoint, GeometryPolygon, Range, RecordId, RecordIdRange, RecordIdValue, StringRecordId, Table, Uuid } from 'surrealdb'; import { output, ZodArray, ZodBigInt, ZodCustom, ZodEnum, ZodLiteral, ZodNumber, ZodObject, ZodString, ZodType } from 'zod'; /** * @private */ type RecordIdValueSchema = ZodString | ZodNumber | ZodCustom<Uuid> | ZodBigInt | ZodObject | ZodArray | ZodLiteral<string | number | bigint> | ZodEnum | ZodType<RecordIdValue>; export declare const DateTimeSchema: ZodCustom<DateTime, DateTime>; export declare const DecimalSchema: ZodCustom<Decimal, Decimal>; export declare const DurationSchema: ZodCustom<Duration, Duration>; export declare const FileRefSchema: ZodCustom<FileRef, FileRef>; /** * @deprecated Futures were removed in SurrealDB 3.0 */ export declare const FutureSchema: ZodCustom<Future, Future>; export declare const GeometrySchema: ZodCustom<Geometry, Geometry>; export declare const GeometryPointSchema: ZodCustom<GeometryPoint, GeometryPoint>; export declare const GeometryLineSchema: ZodCustom<GeometryLine, GeometryLine>; export declare const GeometryPolygonSchema: ZodCustom<GeometryPolygon, GeometryPolygon>; export declare const GeometryMultiPointSchema: ZodCustom<GeometryMultiPoint, GeometryMultiPoint>; export declare const GeometryMultiLineSchema: ZodCustom<GeometryMultiLine, GeometryMultiLine>; export declare const GeometryMultiPolygonSchema: ZodCustom<GeometryMultiPolygon, GeometryMultiPolygon>; export declare const GeometryCollectionSchema: ZodCustom<GeometryCollection, GeometryCollection>; export declare function RangeSchema<Beg extends ZodType, End extends ZodType>(begValueSchema: Beg, endValueSchema: End): ZodCustom<Range<output<Beg>, output<End>>, Range<output<Beg>, output<End>>>; export declare function BoundIncludedSchema<T extends ZodType>(valueSchema: T): ZodCustom<BoundIncluded<T>, BoundIncluded<T>>; export declare function BoundExcludedSchema<T extends ZodType>(valueSchema: T): ZodCustom<BoundExcluded<T>, BoundExcluded<T>>; export declare const RecordIdRangeSchema: ZodCustom<RecordIdRange, RecordIdRange>; export declare function RecordIdRangeSchemaOf<Tb extends string, Id extends RecordIdValueSchema | undefined = undefined>(table: Tb, id?: Id): ZodCustom<RecordIdRange<Tb, Id extends ZodType<unknown, unknown, import('zod/v4/core').$ZodTypeInternals<unknown, unknown>> ? output<Id> : RecordIdValue>, RecordIdRange<Tb, Id extends ZodType<unknown, unknown, import('zod/v4/core').$ZodTypeInternals<unknown, unknown>> ? output<Id> : RecordIdValue>>; export declare const RecordIdSchema: ZodCustom<RecordId, RecordId>; export declare function RecordIdSchemaOf<Tb extends string, Id extends RecordIdValueSchema | undefined = undefined>(table: Tb, id?: Id): ZodCustom<RecordId<Tb, Id extends ZodType<unknown, unknown, import('zod/v4/core').$ZodTypeInternals<unknown, unknown>> ? output<Id> : RecordIdValue>, RecordId<Tb, Id extends ZodType<unknown, unknown, import('zod/v4/core').$ZodTypeInternals<unknown, unknown>> ? output<Id> : RecordIdValue>>; export declare const StringRecordIdSchema: ZodCustom<StringRecordId, StringRecordId>; export declare const RecordSchema: ZodObject<{ id: ZodCustom<RecordId, RecordId>; }, import('zod/v4/core').$strip>; export declare function RecordSchemaOf<Tb extends string, Id extends RecordIdValueSchema | undefined = undefined>(table: Tb, id?: Id): ZodObject<{ id: ZodCustom<RecordId<Tb, Id extends ZodType<unknown, unknown, import('zod/v4/core').$ZodTypeInternals<unknown, unknown>> ? output<Id> : RecordIdValue>, RecordId<Tb, Id extends ZodType<unknown, unknown, import('zod/v4/core').$ZodTypeInternals<unknown, unknown>> ? output<Id> : RecordIdValue>>; }, import('zod/v4/core').$strip>; export declare const TableSchema: ZodCustom<Table<string>, Table<string>>; export declare function TableSchemaOf<Tb extends string>(table: Tb): ZodCustom<Table<Tb>, Table<Tb>>; export declare const UuidSchema: ZodCustom<Uuid, Uuid>; export type Record = output<typeof RecordSchema>; export type RecordOf<Tb extends string = string, Id extends RecordIdValue = RecordIdValue> = { id: RecordId<Tb, Id>; }; export {};