surreal-zod 0.0.0-alpha.1 → 0.0.0-alpha.10

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.
@@ -0,0 +1,314 @@
1
+ /** biome-ignore-all lint/suspicious/noExplicitAny: needed for conversion */
2
+ /** biome-ignore-all lint/style/noNonNullAssertion: needed for conversion */
3
+ import { BoundQuery, RecordId, type RecordIdValue } from "surrealdb";
4
+ import * as core from "zod/v4/core";
5
+ import * as classic from "zod/v4";
6
+ import { type DefineTableOptions, type RemoveTableOptions, type TableInfo, type TableStructure } from "../surql";
7
+ export interface SurrealZodTypeDef extends core.$ZodTypeDef {
8
+ surrealType?: "any" | "unknown" | "never" | "undefined" | "boolean" | "string" | "number" | "object" | "record_id" | "table";
9
+ }
10
+ export interface SurrealZodInternals {
11
+ type: string;
12
+ }
13
+ export interface SurrealZodTypeInternals<out O = unknown, out I = unknown, out SurrealInternals extends SurrealZodInternals = SurrealZodInternals> extends core.$ZodTypeInternals<O, I> {
14
+ def: SurrealZodTypeDef & {
15
+ surreal: SurrealInternals;
16
+ };
17
+ }
18
+ export interface SurrealZodType<out O = unknown, out I = unknown, out Internals extends SurrealZodTypeInternals<O, I, SurrealZodInternals> = SurrealZodTypeInternals<O, I, SurrealZodInternals>> extends core.$ZodType<O, I, Internals> {
19
+ clone(def?: Internals["def"], params?: {
20
+ parent: boolean;
21
+ }): this;
22
+ parse(data: unknown, params?: core.ParseContext<core.$ZodIssue>): core.output<this>;
23
+ safeParse(data: unknown, params?: core.ParseContext<core.$ZodIssue>): classic.ZodSafeParseResult<core.output<this>>;
24
+ optional(): SurrealZodOptional<this>;
25
+ nonoptional(): SurrealZodNonOptional<this>;
26
+ nullable(): SurrealZodNullable<this>;
27
+ nullish(): SurrealZodOptional<SurrealZodNullable<this>>;
28
+ }
29
+ export interface _SurrealZodType<Internals extends SurrealZodTypeInternals = SurrealZodTypeInternals> extends SurrealZodType<any, any, Internals> {
30
+ }
31
+ export declare const SurrealZodType: core.$constructor<SurrealZodType>;
32
+ export interface SurrealZodAnyInternals extends core.$ZodAnyInternals {
33
+ def: core.$ZodAnyInternals["def"] & {
34
+ surreal: {
35
+ type: "any";
36
+ };
37
+ };
38
+ }
39
+ export interface SurrealZodAny extends _SurrealZodType<SurrealZodAnyInternals> {
40
+ }
41
+ export declare const SurrealZodAny: core.$constructor<SurrealZodAny>;
42
+ export declare function any(): SurrealZodAny;
43
+ export interface SurrealZodUnknownInternals extends core.$ZodUnknownInternals {
44
+ def: core.$ZodUnknownInternals["def"] & {
45
+ surreal: {
46
+ type: "unknown";
47
+ };
48
+ };
49
+ }
50
+ export interface SurrealZodUnknown extends _SurrealZodType<SurrealZodUnknownInternals> {
51
+ }
52
+ export declare const SurrealZodUnknown: core.$constructor<SurrealZodUnknown>;
53
+ export declare function unknown(): SurrealZodUnknown;
54
+ export interface SurrealZodNeverInternals extends core.$ZodNeverInternals {
55
+ def: core.$ZodNeverInternals["def"] & {
56
+ surreal: {
57
+ type: "never";
58
+ };
59
+ };
60
+ }
61
+ export interface SurrealZodNever extends _SurrealZodType<SurrealZodNeverInternals> {
62
+ }
63
+ export declare const SurrealZodNever: core.$constructor<SurrealZodNever>;
64
+ export declare function never(params?: string | core.$ZodNeverParams): SurrealZodNever;
65
+ export interface SurrealZodUndefinedInternals extends core.$ZodUndefinedInternals {
66
+ def: core.$ZodUndefinedInternals["def"] & {
67
+ surreal: {
68
+ type: "undefined";
69
+ };
70
+ };
71
+ }
72
+ export interface SurrealZodUndefined extends _SurrealZodType<SurrealZodUndefinedInternals> {
73
+ }
74
+ export declare const SurrealZodUndefined: core.$constructor<SurrealZodUndefined>;
75
+ declare function _undefined(params?: string | core.$ZodUndefinedParams): SurrealZodUndefined;
76
+ export { _undefined as undefined };
77
+ export interface SurrealZodNullInternals extends core.$ZodNullInternals {
78
+ def: core.$ZodNullInternals["def"] & {
79
+ surreal: {
80
+ type: "null";
81
+ };
82
+ };
83
+ }
84
+ export interface SurrealZodNull extends _SurrealZodType<SurrealZodNullInternals> {
85
+ }
86
+ export declare const SurrealZodNull: core.$constructor<SurrealZodNull>;
87
+ declare function _null(params?: string | core.$ZodNullParams): SurrealZodNull;
88
+ export { _null as null };
89
+ export interface SurrealZodBooleanInternals extends core.$ZodBooleanInternals {
90
+ def: core.$ZodBooleanInternals["def"] & {
91
+ surreal: {
92
+ type: "boolean";
93
+ };
94
+ };
95
+ }
96
+ export interface SurrealZodBoolean extends _SurrealZodType<SurrealZodBooleanInternals> {
97
+ }
98
+ export declare const SurrealZodBoolean: core.$constructor<SurrealZodBoolean>;
99
+ export declare function boolean(params?: string | core.$ZodBooleanParams): SurrealZodBoolean;
100
+ export interface SurrealZodStringInternals extends core.$ZodStringInternals<string> {
101
+ def: core.$ZodStringInternals<string>["def"] & {
102
+ surreal: {
103
+ type: "string";
104
+ };
105
+ };
106
+ }
107
+ export interface SurrealZodString extends _SurrealZodType<SurrealZodStringInternals> {
108
+ }
109
+ export declare const SurrealZodString: core.$constructor<SurrealZodString>;
110
+ export declare function string(params?: string | core.$ZodStringParams): SurrealZodString;
111
+ export interface SurrealZodNumberInternals extends core.$ZodNumberInternals {
112
+ def: core.$ZodNumberInternals["def"] & {
113
+ surreal: {
114
+ type: "number";
115
+ };
116
+ };
117
+ }
118
+ export interface SurrealZodNumber extends _SurrealZodType<SurrealZodNumberInternals> {
119
+ }
120
+ export declare const SurrealZodNumber: core.$constructor<SurrealZodNumber>;
121
+ export declare function number(params?: string | core.$ZodNumberParams): SurrealZodNumber;
122
+ export interface SurrealZodBigIntInternals extends core.$ZodBigIntInternals {
123
+ def: core.$ZodBigIntInternals["def"] & {
124
+ surreal: {
125
+ type: "bigint";
126
+ };
127
+ };
128
+ }
129
+ export interface SurrealZodBigInt extends _SurrealZodType<SurrealZodBigIntInternals> {
130
+ }
131
+ export declare const SurrealZodBigInt: core.$constructor<SurrealZodBigInt>;
132
+ export declare function bigint(params?: string | core.$ZodBigIntParams): SurrealZodBigInt;
133
+ export interface SurrealZodObjectInternals<out Shape extends core.$ZodShape = core.$ZodLooseShape, out Config extends core.$ZodObjectConfig = core.$strip> extends core.$ZodObjectInternals<Shape, Config> {
134
+ def: core.$ZodObjectInternals<Shape, Config>["def"] & {
135
+ surreal: {
136
+ type: "object";
137
+ flexible: boolean;
138
+ };
139
+ };
140
+ }
141
+ export interface SurrealZodObject<out Shape extends core.$ZodShape = core.$ZodLooseShape, out Config extends core.$ZodObjectConfig = core.$strip> extends _SurrealZodType<SurrealZodObjectInternals<Shape, Config>> {
142
+ loose(): this;
143
+ /**
144
+ * @alias loose
145
+ */
146
+ flexible(): this;
147
+ strict(): this;
148
+ extend<U extends core.$ZodLooseShape>(shape: U): SurrealZodObject<core.util.Extend<Shape, U>, Config>;
149
+ safeExtend<U extends core.$ZodLooseShape>(shape: classic.SafeExtendShape<Shape, U> & Partial<Record<keyof Shape, core.SomeType>>): SurrealZodObject<core.util.Extend<Shape, U>, Config>;
150
+ }
151
+ export declare const SurrealZodObject: core.$constructor<SurrealZodObject>;
152
+ export declare function object<T extends core.$ZodLooseShape = Partial<Record<never, core.SomeType>>>(shape?: T, params?: string | core.$ZodObjectParams): SurrealZodObject<core.util.Writeable<T>, core.$strip>;
153
+ export type SurrealZodRecordIdValue = SurrealZodAny | SurrealZodUnknown | SurrealZodString | SurrealZodNumber | SurrealZodBigInt | SurrealZodObject;
154
+ export interface SurrealZodRecordIdDef<Table extends string = string, Id extends SurrealZodRecordIdValue = SurrealZodRecordIdValue> extends SurrealZodTypeDef {
155
+ innerType: Id;
156
+ table?: Table[];
157
+ surreal: {
158
+ type: "record_id";
159
+ };
160
+ }
161
+ export type RecordIdValueOutput<Id extends SurrealZodRecordIdValue> = Id extends {
162
+ _zod: {
163
+ output: any;
164
+ };
165
+ } ? Id["_zod"]["output"] : RecordIdValue;
166
+ export interface SurrealZodRecordIdInternals<Table extends string = string, Id extends SurrealZodRecordIdValue = SurrealZodRecordIdValue> extends SurrealZodTypeInternals<RecordId<Table, RecordIdValueOutput<Id>>, RecordIdValue> {
167
+ def: SurrealZodRecordIdDef<Table, Id>;
168
+ }
169
+ export interface SurrealZodRecordId<Table extends string = string, Id extends SurrealZodRecordIdValue = SurrealZodRecordIdValue> extends _SurrealZodType<SurrealZodRecordIdInternals<Table, Id>> {
170
+ anytable(): SurrealZodRecordId<string, Id>;
171
+ table<NewTable extends string | string[]>(table: NewTable): SurrealZodRecordId<NewTable extends string ? NewTable : NewTable[number], Id>;
172
+ type<NewType extends SurrealZodRecordIdValue>(innerType: NewType): SurrealZodRecordId<Table, NewType>;
173
+ }
174
+ export declare const SurrealZodRecordId: core.$constructor<SurrealZodRecordId>;
175
+ export declare function recordId<const W extends string | string[]>(what?: W, innerType?: SurrealZodRecordIdValue): SurrealZodRecordId<W extends string ? W : W[number]>;
176
+ export type inferRecordIdTable<T extends SurrealZodRecordId<string, any>> = T extends SurrealZodRecordId<infer N> ? N : never;
177
+ export type SurrealZodTableFields = {
178
+ [key: string]: SurrealZodType;
179
+ };
180
+ /**
181
+ * Normalizes the fields of a table schema to include the id field if it is not present.
182
+ * If the id field is present, it will be normalized using the table name and the inner type.
183
+ */
184
+ type NormalizedIdField<TableName extends string, Fields extends SurrealZodTableFields, FieldName extends string> = Fields extends {
185
+ [K in FieldName]: SurrealZodType;
186
+ } ? Fields[FieldName] extends SurrealZodRecordId<infer _N, infer T> ? Omit<Fields, FieldName> & {
187
+ [K in FieldName]: SurrealZodRecordId<TableName, T>;
188
+ } : Fields[FieldName] extends SurrealZodRecordIdValue ? Omit<Fields, FieldName> & {
189
+ [K in FieldName]: SurrealZodRecordId<TableName, Fields[FieldName]>;
190
+ } : Omit<Fields, FieldName> & {
191
+ [K in FieldName]: SurrealZodRecordId<TableName>;
192
+ } : Fields & {
193
+ [K in FieldName]: SurrealZodRecordId<TableName>;
194
+ };
195
+ export type NormalizedFields<TableName extends string = string, Fields extends SurrealZodTableFields = {}> = core.util.Prettify<NormalizedIdField<TableName, Fields, "id">>;
196
+ type SetConfig<Key extends string, Value> = {
197
+ [key in Key]: Value;
198
+ };
199
+ type MergeConfig<A extends Partial<SurrealZodTableConfig>, B extends Partial<SurrealZodTableConfig>> = core.util.Prettify<Omit<A, keyof B> & B>;
200
+ type SurrealZodTableConfigSchemafull = SetConfig<"catchall", {}>;
201
+ type SurrealZodTableConfigSchemaless = SetConfig<"catchall", Record<string, SurrealZodType>>;
202
+ type SurrealZodTableConfig = {
203
+ catchall: any;
204
+ dto: boolean;
205
+ };
206
+ export interface SurrealZodTableDef<Name extends string = string, Fields extends SurrealZodTableFields = {}, Config extends SurrealZodTableConfig = SurrealZodTableConfig> extends SurrealZodTypeDef {
207
+ name: Name;
208
+ fields: (Config["dto"] extends true ? Omit<NormalizedFields<Name, Fields>, "id"> & {
209
+ id: SurrealZodOptional<NormalizedFields<Name, Fields>["id"]>;
210
+ } : NormalizedFields<Name, Fields>) & Config["catchall"];
211
+ catchall?: SurrealZodType;
212
+ dto: Config["dto"];
213
+ surreal: {
214
+ type: "table";
215
+ tableType: "any" | "normal" | "relation";
216
+ schemafull: boolean;
217
+ drop: boolean;
218
+ comment?: string;
219
+ };
220
+ }
221
+ export interface SurrealZodTableInternals<Name extends string = string, Fields extends SurrealZodTableFields = {}, Config extends SurrealZodTableConfig = MergeConfig<SurrealZodTableConfig, SurrealZodTableConfigSchemaless>> extends SurrealZodTypeInternals {
222
+ def: SurrealZodTableDef<Name, Fields, Config>;
223
+ }
224
+ export interface SurrealZodTable<Name extends string = string, Fields extends SurrealZodTableFields = {}, Config extends SurrealZodTableConfig = MergeConfig<SurrealZodTableConfig, SurrealZodTableConfigSchemaless>> extends _SurrealZodType<SurrealZodTableInternals<Name, Fields, Config>> {
225
+ name<NewName extends string>(name: NewName): SurrealZodTable<NewName, Fields>;
226
+ fields<NewFields extends SurrealZodTableFields>(fields: NewFields): SurrealZodTable<Name, NewFields, Config>;
227
+ schemafull(): SurrealZodTable<Name, Fields, MergeConfig<Config, SurrealZodTableConfigSchemafull>>;
228
+ schemaless(): SurrealZodTable<Name, Fields, MergeConfig<Config, SurrealZodTableConfigSchemaless>>;
229
+ any(): SurrealZodTable<Name, Fields, Config>;
230
+ normal(): SurrealZodTableNormal<Name, Fields, Config>;
231
+ relation(): SurrealZodTableRelation<Name, SurrealZodRecordId<string, SurrealZodRecordIdValue>, SurrealZodRecordId<string, SurrealZodRecordIdValue>, Fields, Config>;
232
+ drop(): this;
233
+ nodrop(): this;
234
+ comment(comment: string): this;
235
+ record(): this["_zod"]["def"]["fields"]["id"];
236
+ dto(): SurrealZodTable<Name, Fields, MergeConfig<Config, SetConfig<"dto", true>>>;
237
+ entity(): SurrealZodTable<Name, Fields, MergeConfig<Config, SetConfig<"dto", false>>>;
238
+ toSurql(statement?: "define", options?: DefineTableOptions): BoundQuery<[undefined]>;
239
+ toSurql(statement: "remove", options?: RemoveTableOptions): BoundQuery<[undefined]>;
240
+ toSurql(statement: "info"): BoundQuery<[TableInfo]>;
241
+ toSurql(statement: "structure"): BoundQuery<[TableStructure]>;
242
+ }
243
+ export declare const SurrealZodTable: core.$constructor<SurrealZodTable>;
244
+ export declare function table<Name extends string = string>(name: Name): SurrealZodTable<Name>;
245
+ export interface SurrealZodTableNormal<Name extends string = string, Fields extends SurrealZodTableFields = {}, Config extends SurrealZodTableConfig = MergeConfig<SurrealZodTableConfig, SurrealZodTableConfigSchemaless>> extends SurrealZodTable<Name, Fields, Config> {
246
+ name<NewName extends string>(name: NewName): SurrealZodTableNormal<NewName, Fields, Config>;
247
+ fields<NewFields extends SurrealZodTableFields>(fields: NewFields): SurrealZodTableNormal<Name, NewFields, Config>;
248
+ schemafull(): SurrealZodTableNormal<Name, Fields, MergeConfig<Config, SurrealZodTableConfigSchemafull>>;
249
+ schemaless(): SurrealZodTableNormal<Name, Fields, MergeConfig<Config, SurrealZodTableConfigSchemaless>>;
250
+ dto(): SurrealZodTableNormal<Name, Fields, MergeConfig<Config, SetConfig<"dto", true>>>;
251
+ entity(): SurrealZodTableNormal<Name, Fields, MergeConfig<Config, SetConfig<"dto", false>>>;
252
+ }
253
+ export declare const SurrealZodTableNormal: core.$constructor<SurrealZodTableNormal>;
254
+ export declare function normalTable<Name extends string = string>(name: Name): SurrealZodTableNormal<Name>;
255
+ export interface SurrealZodTableRelation<Name extends string = string, From extends SurrealZodRecordId<string, SurrealZodRecordIdValue> = SurrealZodRecordId<string, SurrealZodRecordIdValue>, To extends SurrealZodRecordId<string, SurrealZodRecordIdValue> = SurrealZodRecordId<string, SurrealZodRecordIdValue>, Fields extends SurrealZodTableFields = {}, Config extends SurrealZodTableConfig = MergeConfig<SurrealZodTableConfig, SurrealZodTableConfigSchemaless>> extends SurrealZodTable<Name, NormalizedIdField<inferRecordIdTable<To>, NormalizedIdField<inferRecordIdTable<From>, Fields & {
256
+ in: From;
257
+ out: To;
258
+ }, "in">, "out">, Config> {
259
+ name<NewName extends string>(name: NewName): SurrealZodTableRelation<NewName, From, To, Fields, Config>;
260
+ fields<NewFields extends SurrealZodTableFields>(fields: NewFields): SurrealZodTableRelation<Name, From, To, NewFields, Config>;
261
+ schemafull(): SurrealZodTableRelation<Name, From, To, Fields, MergeConfig<Config, SurrealZodTableConfigSchemafull>>;
262
+ schemaless(): SurrealZodTableRelation<Name, From, To, Fields, MergeConfig<Config, SurrealZodTableConfigSchemaless>>;
263
+ from<NewFrom extends string | string[] | SurrealZodRecordId<string, SurrealZodRecordIdValue>>(from: NewFrom): SurrealZodTableRelation<Name extends string ? Name : Name[number], toRecordId<NewFrom>, To, Fields, MergeConfig<Config, SurrealZodTableConfigSchemafull>>;
264
+ to<NewTo extends string | string[] | SurrealZodRecordId<string, SurrealZodRecordIdValue>>(to: NewTo): SurrealZodTableRelation<Name extends string ? Name : Name[number], From, toRecordId<NewTo>, Fields, MergeConfig<Config, SurrealZodTableConfigSchemafull>>;
265
+ in<NewFrom extends string | string[] | SurrealZodRecordId<string, SurrealZodRecordIdValue>>(from: NewFrom): SurrealZodTableRelation<Name extends string ? Name : Name[number], toRecordId<NewFrom>, To, Fields, MergeConfig<Config, SurrealZodTableConfigSchemafull>>;
266
+ out<NewTo extends string | string[] | SurrealZodRecordId<string, SurrealZodRecordIdValue>>(to: NewTo): SurrealZodTableRelation<Name extends string ? Name : Name[number], From, toRecordId<NewTo>, Fields, MergeConfig<Config, SurrealZodTableConfigSchemafull>>;
267
+ dto(): SurrealZodTableRelation<Name, From, To, Fields, MergeConfig<Config, SetConfig<"dto", true>>>;
268
+ entity(): SurrealZodTableRelation<Name, From, To, Fields, MergeConfig<Config, SetConfig<"dto", false>>>;
269
+ }
270
+ type toRecordId<T extends string | string[] | SurrealZodRecordId<string, SurrealZodRecordIdValue>> = T extends string ? T extends SurrealZodRecordId<infer N, infer I> ? SurrealZodRecordId<N, I> : SurrealZodRecordId<T> : T extends string[] ? SurrealZodRecordId<T[number]> : T extends SurrealZodRecordId<string, SurrealZodRecordIdValue> ? T : never;
271
+ export declare const SurrealZodTableRelation: core.$constructor<SurrealZodTableRelation>;
272
+ export declare function relationTable<Name extends string = string>(name: Name): SurrealZodTableRelation<Name>;
273
+ export interface SurrealZodOptionalDef<T extends SurrealZodType = SurrealZodType> extends core.$ZodOptionalDef<T> {
274
+ innerType: T;
275
+ surreal: {
276
+ type: "optional";
277
+ };
278
+ }
279
+ export interface SurrealZodOptionalInternals<T extends SurrealZodType = SurrealZodType> extends core.$ZodOptionalInternals<T> {
280
+ def: SurrealZodOptionalDef<T>;
281
+ }
282
+ export interface SurrealZodOptional<T extends SurrealZodType = SurrealZodType> extends _SurrealZodType<SurrealZodOptionalInternals<T>> {
283
+ unwrap(): T;
284
+ }
285
+ export declare const SurrealZodOptional: core.$constructor<SurrealZodOptional>;
286
+ export declare function optional<T extends SurrealZodType = SurrealZodType>(innerType: T): SurrealZodOptional<T>;
287
+ export interface SurrealZodNonOptionalDef<T extends SurrealZodType = SurrealZodType> extends core.$ZodNonOptionalDef<T> {
288
+ innerType: T;
289
+ surreal: {
290
+ type: "nonoptional";
291
+ };
292
+ }
293
+ export interface SurrealZodNonOptionalInternals<T extends SurrealZodType = SurrealZodType> extends core.$ZodNonOptionalInternals<T> {
294
+ def: SurrealZodNonOptionalDef<T>;
295
+ }
296
+ export interface SurrealZodNonOptional<T extends SurrealZodType = SurrealZodType> extends _SurrealZodType<SurrealZodNonOptionalInternals<T>> {
297
+ }
298
+ export declare const SurrealZodNonOptional: core.$constructor<SurrealZodNonOptional>;
299
+ export declare function nonoptional<T extends SurrealZodType = SurrealZodType>(innerType: T): SurrealZodNonOptional<T>;
300
+ export interface SurrealZodNullableDef<T extends SurrealZodType = SurrealZodType> extends core.$ZodNullableDef<T> {
301
+ innerType: T;
302
+ surreal: {
303
+ type: "nullable";
304
+ };
305
+ }
306
+ export interface SurrealZodNullableInternals<T extends SurrealZodType = SurrealZodType> extends core.$ZodNullableInternals<T> {
307
+ def: SurrealZodNullableDef<T>;
308
+ }
309
+ export interface SurrealZodNullable<T extends SurrealZodType = SurrealZodType> extends _SurrealZodType<SurrealZodNullableInternals<T>> {
310
+ }
311
+ export declare const SurrealZodNullable: core.$constructor<SurrealZodNullable>;
312
+ export declare function nullable<T extends SurrealZodType = SurrealZodType>(innerType: T): SurrealZodNullable<T>;
313
+ export declare function nullish<T extends SurrealZodType = SurrealZodType>(innerType: T): SurrealZodOptional<SurrealZodNullable<T>>;
314
+ export type SurrealZodTypes = SurrealZodAny | SurrealZodUnknown | SurrealZodNever | SurrealZodUndefined | SurrealZodOptional | SurrealZodNonOptional | SurrealZodNull | SurrealZodNullable | SurrealZodBoolean | SurrealZodString | SurrealZodNumber | SurrealZodBigInt | SurrealZodObject | SurrealZodRecordId | SurrealZodTable;