surreal-zod 0.0.0-alpha.11 → 0.0.0-alpha.12
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.
- package/lib/index.d.ts +4 -3
- package/lib/index.js +4 -3
- package/lib/registries.d.ts +7 -0
- package/lib/registries.js +5 -0
- package/lib/surql.d.ts +34 -17
- package/lib/surql.js +661 -265
- package/lib/zod/core.d.ts +262 -0
- package/lib/zod/core.js +10 -0
- package/lib/zod/index.d.ts +2 -0
- package/lib/zod/index.js +2 -0
- package/lib/zod/json-schema.d.ts +89 -0
- package/lib/zod/json-schema.js +629 -0
- package/lib/zod/original.d.ts +2 -0
- package/lib/zod/original.js +177 -0
- package/lib/zod/parse.d.ts +71 -0
- package/lib/zod/parse.js +17 -0
- package/lib/zod/schema.d.ts +1798 -233
- package/lib/zod/schema.js +2255 -278
- package/lib/zod/utils.d.ts +3 -2
- package/lib/zod/utils.js +0 -2
- package/package.json +6 -8
- package/src/index.ts +4 -3
- package/src/registries.ts +9 -0
- package/src/surql.ts +768 -324
- package/src/zod/core.ts +605 -0
- package/src/zod/index.ts +2 -0
- package/src/zod/json-schema.ts +892 -0
- package/src/zod/original.ts +369 -0
- package/src/zod/parse.ts +138 -0
- package/src/zod/schema.ts +7099 -984
- package/src/zod/utils.ts +15 -5
package/src/zod/core.ts
ADDED
|
@@ -0,0 +1,605 @@
|
|
|
1
|
+
import * as core from "zod/v4/core";
|
|
2
|
+
import type { ZodSurrealType } from "./schema";
|
|
3
|
+
|
|
4
|
+
//////////////////////////////// API //////////////////////////////////////////
|
|
5
|
+
|
|
6
|
+
export type Params<
|
|
7
|
+
T extends $ZodSurrealType | core.$ZodCheck,
|
|
8
|
+
IssueTypes extends core.$ZodIssueBase,
|
|
9
|
+
OmitKeys extends keyof T["_zod"]["def"] = never,
|
|
10
|
+
> = core.util.Flatten<
|
|
11
|
+
Partial<
|
|
12
|
+
core.util.EmptyToNever<
|
|
13
|
+
Omit<T["_zod"]["def"], OmitKeys> &
|
|
14
|
+
([IssueTypes] extends [never]
|
|
15
|
+
? {}
|
|
16
|
+
: {
|
|
17
|
+
error?: string | core.$ZodErrorMap<IssueTypes> | undefined;
|
|
18
|
+
/** @deprecated This parameter is deprecated. Use `error` instead. */
|
|
19
|
+
message?: string | undefined;
|
|
20
|
+
})
|
|
21
|
+
>
|
|
22
|
+
>
|
|
23
|
+
>;
|
|
24
|
+
|
|
25
|
+
export type TypeParams<
|
|
26
|
+
T extends $ZodSurrealType = ZodSurrealType & {
|
|
27
|
+
_isst: never;
|
|
28
|
+
},
|
|
29
|
+
AlsoOmit extends Exclude<
|
|
30
|
+
keyof T["_zod"]["def"],
|
|
31
|
+
"type" | "checks" | "error"
|
|
32
|
+
> = never,
|
|
33
|
+
> = Params<
|
|
34
|
+
T,
|
|
35
|
+
NonNullable<T["_zod"]["isst"]>,
|
|
36
|
+
"type" | "checks" | "error" | AlsoOmit
|
|
37
|
+
>;
|
|
38
|
+
|
|
39
|
+
//////////////////////////////// CORE /////////////////////////////////////////
|
|
40
|
+
|
|
41
|
+
export interface $ZodSurrealTypeDef {
|
|
42
|
+
type:
|
|
43
|
+
| "string"
|
|
44
|
+
| "number"
|
|
45
|
+
| "boolean"
|
|
46
|
+
| "bigint"
|
|
47
|
+
| "symbol"
|
|
48
|
+
| "undefined"
|
|
49
|
+
| "null"
|
|
50
|
+
| "any"
|
|
51
|
+
| "unknown"
|
|
52
|
+
| "never"
|
|
53
|
+
| "void"
|
|
54
|
+
| "date"
|
|
55
|
+
| "array"
|
|
56
|
+
| "object"
|
|
57
|
+
| "union"
|
|
58
|
+
| "intersection"
|
|
59
|
+
| "tuple"
|
|
60
|
+
| "record"
|
|
61
|
+
| "map"
|
|
62
|
+
| "set"
|
|
63
|
+
| "enum"
|
|
64
|
+
| "file"
|
|
65
|
+
| "transform"
|
|
66
|
+
| "literal"
|
|
67
|
+
| "optional"
|
|
68
|
+
| "nullable"
|
|
69
|
+
| "default"
|
|
70
|
+
| "prefault"
|
|
71
|
+
| "nonoptional"
|
|
72
|
+
| "success"
|
|
73
|
+
| "catch"
|
|
74
|
+
| "nan"
|
|
75
|
+
| "pipe"
|
|
76
|
+
| "readonly"
|
|
77
|
+
| "template_literal"
|
|
78
|
+
| "lazy"
|
|
79
|
+
| "promise"
|
|
80
|
+
| "function"
|
|
81
|
+
| "custom"
|
|
82
|
+
| "record_id"
|
|
83
|
+
// DB specific (We want a different one for each schema type, this helps on
|
|
84
|
+
// inferring final data type to use on the database queries and DDLs)
|
|
85
|
+
| "table"
|
|
86
|
+
| "field"
|
|
87
|
+
| "duration";
|
|
88
|
+
error?: core.$ZodErrorMap<never> | undefined;
|
|
89
|
+
checks?: core.$ZodCheck<never>[];
|
|
90
|
+
surreal?: $ZodSurrealTypeDefInternals;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export interface $ZodSurrealTypeDefInternals {
|
|
94
|
+
type?:
|
|
95
|
+
| "string"
|
|
96
|
+
| "number"
|
|
97
|
+
| "int"
|
|
98
|
+
| "float"
|
|
99
|
+
| "bool"
|
|
100
|
+
| "int"
|
|
101
|
+
| "none"
|
|
102
|
+
| "null"
|
|
103
|
+
| "any"
|
|
104
|
+
| "datetime"
|
|
105
|
+
| "uuid"
|
|
106
|
+
| "duration";
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export interface _$ZodSurrealTypeInternals {
|
|
110
|
+
/** The `@zod/core` version of this schema */
|
|
111
|
+
version: typeof core.version;
|
|
112
|
+
/** Schema definition. */
|
|
113
|
+
def: $ZodSurrealTypeDef;
|
|
114
|
+
/** @internal Randomly generated ID for this schema. */
|
|
115
|
+
/** @internal List of deferred initializers. */
|
|
116
|
+
deferred: core.util.AnyFunc[] | undefined;
|
|
117
|
+
/** @internal Parses input and runs all checks (refinements). */
|
|
118
|
+
run(
|
|
119
|
+
payload: core.ParsePayload<any>,
|
|
120
|
+
ctx: core.ParseContextInternal,
|
|
121
|
+
): core.util.MaybeAsync<core.ParsePayload>;
|
|
122
|
+
/** @internal Parses input, doesn't run checks. */
|
|
123
|
+
parse(
|
|
124
|
+
payload: core.ParsePayload<any>,
|
|
125
|
+
ctx: core.ParseContextInternal,
|
|
126
|
+
): core.util.MaybeAsync<core.ParsePayload>;
|
|
127
|
+
/** @internal Stores identifiers for the set of traits implemented by this schema. */
|
|
128
|
+
traits: Set<string>;
|
|
129
|
+
/** @internal Indicates that a schema output type should be considered optional inside objects.
|
|
130
|
+
* @default Required
|
|
131
|
+
*/
|
|
132
|
+
/** @internal */
|
|
133
|
+
optin?: "optional" | undefined;
|
|
134
|
+
/** @internal */
|
|
135
|
+
optout?: "optional" | undefined;
|
|
136
|
+
/** @internal */
|
|
137
|
+
dboptin?: "optional" | undefined;
|
|
138
|
+
/** @internal */
|
|
139
|
+
dboptout?: "optional" | undefined;
|
|
140
|
+
/** @internal The set of literal values that will pass validation. Must be an exhaustive set. Used to determine optionality in z.record().
|
|
141
|
+
*
|
|
142
|
+
* Defined on: enum, const, literal, null, undefined
|
|
143
|
+
* Passthrough: optional, nullable, branded, default, catch, pipe
|
|
144
|
+
* Todo: unions?
|
|
145
|
+
*/
|
|
146
|
+
values?: core.util.PrimitiveSet | undefined;
|
|
147
|
+
/** Default value bubbled up from */
|
|
148
|
+
/** @internal A set of literal discriminators used for the fast path in discriminated unions. */
|
|
149
|
+
propValues?: core.util.PropValues | undefined;
|
|
150
|
+
/** @internal This flag indicates that a schema validation can be represented with a regular expression. Used to determine allowable schemas in z.templateLiteral(). */
|
|
151
|
+
pattern: RegExp | undefined;
|
|
152
|
+
/** @internal The constructor function of this schema. */
|
|
153
|
+
constr: new (
|
|
154
|
+
def: any,
|
|
155
|
+
) => $ZodSurrealType;
|
|
156
|
+
/** @internal A catchall object for bag metadata related to this schema. Commonly modified by checks using `onattach`. */
|
|
157
|
+
bag: Record<string, unknown>;
|
|
158
|
+
/** @internal The set of issues this schema might throw during type checking. */
|
|
159
|
+
isst: core.$ZodIssueBase;
|
|
160
|
+
/** @internal Subject to change, not a public API. */
|
|
161
|
+
processJSONSchema?:
|
|
162
|
+
| ((
|
|
163
|
+
ctx: core.ToJSONSchemaContext,
|
|
164
|
+
json: core.JSONSchema.BaseSchema,
|
|
165
|
+
params: core.ProcessParams,
|
|
166
|
+
) => void)
|
|
167
|
+
| undefined;
|
|
168
|
+
/** An optional method used to override `toJSONSchema` logic. */
|
|
169
|
+
toJSONSchema?: () => unknown;
|
|
170
|
+
/** @internal The parent of this schema. Only set during certain clone operations. */
|
|
171
|
+
parent?: $ZodSurrealType | undefined;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export interface $ZodSurrealTypeInternals<
|
|
175
|
+
out O = unknown,
|
|
176
|
+
out I = unknown,
|
|
177
|
+
out DBO = O,
|
|
178
|
+
out DBI = I,
|
|
179
|
+
> extends _$ZodSurrealTypeInternals {
|
|
180
|
+
/** @internal The inferred output type */
|
|
181
|
+
output: O;
|
|
182
|
+
/** @internal The inferred input type */
|
|
183
|
+
input: I;
|
|
184
|
+
|
|
185
|
+
/** @internal The inferred output type when using database context */
|
|
186
|
+
dboutput: DBO;
|
|
187
|
+
/** @internal The inferred input type when using database context */
|
|
188
|
+
dbinput: DBI;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export type $SomeSurrealType = { _zod: _$ZodSurrealTypeInternals };
|
|
192
|
+
|
|
193
|
+
export type $ZodBranded<
|
|
194
|
+
T extends $SomeSurrealType,
|
|
195
|
+
Brand extends string | number | symbol,
|
|
196
|
+
Dir extends "in" | "out" | "inout" = "out",
|
|
197
|
+
> = T &
|
|
198
|
+
(Dir extends "inout"
|
|
199
|
+
? {
|
|
200
|
+
_zod: {
|
|
201
|
+
input: core.input<T> & core.$brand<Brand>;
|
|
202
|
+
output: core.output<T> & core.$brand<Brand>;
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
: Dir extends "in"
|
|
206
|
+
? {
|
|
207
|
+
_zod: {
|
|
208
|
+
input: core.input<T> & core.$brand<Brand>;
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
: {
|
|
212
|
+
_zod: {
|
|
213
|
+
output: core.output<T> & core.$brand<Brand>;
|
|
214
|
+
};
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
export interface $ZodSurrealType<
|
|
218
|
+
out O = unknown,
|
|
219
|
+
out I = unknown,
|
|
220
|
+
out DBO = O,
|
|
221
|
+
out DBI = I,
|
|
222
|
+
out Internals extends $ZodSurrealTypeInternals<
|
|
223
|
+
O,
|
|
224
|
+
I,
|
|
225
|
+
DBO,
|
|
226
|
+
DBI
|
|
227
|
+
> = $ZodSurrealTypeInternals<O, I, DBO, DBI>,
|
|
228
|
+
> {
|
|
229
|
+
_zod: Internals;
|
|
230
|
+
"~standard": core.$ZodStandardSchema<this>;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
//////////////////////////// TYPE HELPERS ///////////////////////////////////
|
|
234
|
+
|
|
235
|
+
export type $catchall<T extends $SomeSurrealType> = {
|
|
236
|
+
out: {
|
|
237
|
+
[k: string]: core.output<T>;
|
|
238
|
+
};
|
|
239
|
+
in: {
|
|
240
|
+
[k: string]: core.input<T>;
|
|
241
|
+
};
|
|
242
|
+
};
|
|
243
|
+
export type $ZodSurrealShape = Readonly<{
|
|
244
|
+
[k: string]: $ZodSurrealType;
|
|
245
|
+
}>;
|
|
246
|
+
|
|
247
|
+
export type OptionalOutSchema = { _zod: { optout: "optional" } };
|
|
248
|
+
export type OptionalDbOutSchema = { _zod: { dboptout: "optional" } };
|
|
249
|
+
export type OptionalInSchema = { _zod: { optin: "optional" } };
|
|
250
|
+
export type OptionalDbInSchema = { _zod: { dboptin: "optional" } };
|
|
251
|
+
|
|
252
|
+
export type IsOptionalIn<T extends $SomeSurrealType> =
|
|
253
|
+
T extends OptionalInSchema ? true : false;
|
|
254
|
+
export type IsOptionalOut<T extends $SomeSurrealType> =
|
|
255
|
+
T extends OptionalOutSchema ? true : false;
|
|
256
|
+
export type IsOptionalDbIn<T extends $SomeSurrealType> =
|
|
257
|
+
T extends OptionalDbInSchema ? true : false;
|
|
258
|
+
export type IsOptionalDbOut<T extends $SomeSurrealType> =
|
|
259
|
+
T extends OptionalDbOutSchema ? true : false;
|
|
260
|
+
|
|
261
|
+
export type $InferObjectDbOutput<
|
|
262
|
+
T extends core.$ZodLooseShape,
|
|
263
|
+
Extra extends Record<string, unknown>,
|
|
264
|
+
> = string extends keyof T
|
|
265
|
+
? core.util.IsAny<T[keyof T]> extends true
|
|
266
|
+
? Record<string, unknown>
|
|
267
|
+
: Record<string, dboutput<T[keyof T]>>
|
|
268
|
+
: keyof (T & Extra) extends never
|
|
269
|
+
? Record<string, never>
|
|
270
|
+
: core.util.Prettify<
|
|
271
|
+
{
|
|
272
|
+
-readonly [k in keyof T as T[k] extends OptionalDbOutSchema
|
|
273
|
+
? never
|
|
274
|
+
: k]: T[k]["_zod"]["dboutput"];
|
|
275
|
+
} & {
|
|
276
|
+
-readonly [k in keyof T as T[k] extends OptionalDbOutSchema
|
|
277
|
+
? k
|
|
278
|
+
: never]?: T[k]["_zod"]["dboutput"];
|
|
279
|
+
} & Extra
|
|
280
|
+
>;
|
|
281
|
+
|
|
282
|
+
export type $InferObjectDbInput<
|
|
283
|
+
T extends core.$ZodLooseShape,
|
|
284
|
+
Extra extends Record<string, unknown>,
|
|
285
|
+
> = string extends keyof T
|
|
286
|
+
? core.util.IsAny<T[keyof T]> extends true
|
|
287
|
+
? Record<string, unknown>
|
|
288
|
+
: Record<string, dbinput<T[keyof T]>>
|
|
289
|
+
: keyof (T & Extra) extends never
|
|
290
|
+
? Record<string, never>
|
|
291
|
+
: core.util.Prettify<
|
|
292
|
+
{
|
|
293
|
+
-readonly [k in keyof T as T[k] extends OptionalDbInSchema
|
|
294
|
+
? never
|
|
295
|
+
: k]: T[k]["_zod"]["dbinput"];
|
|
296
|
+
} & {
|
|
297
|
+
-readonly [k in keyof T as T[k] extends OptionalDbInSchema
|
|
298
|
+
? k
|
|
299
|
+
: never]?: T[k]["_zod"]["dbinput"];
|
|
300
|
+
} & Extra
|
|
301
|
+
>;
|
|
302
|
+
|
|
303
|
+
export type dbinput<T> = T extends { _zod: { dbinput: any } }
|
|
304
|
+
? T["_zod"]["dbinput"]
|
|
305
|
+
: T extends { _zod: { input: any } }
|
|
306
|
+
? T["_zod"]["input"]
|
|
307
|
+
: unknown;
|
|
308
|
+
|
|
309
|
+
export type dboutput<T> = T extends { _zod: { dboutput: any } }
|
|
310
|
+
? T["_zod"]["dboutput"]
|
|
311
|
+
: T extends { _zod: { output: any } }
|
|
312
|
+
? T["_zod"]["output"]
|
|
313
|
+
: unknown;
|
|
314
|
+
|
|
315
|
+
// Unions
|
|
316
|
+
|
|
317
|
+
export type $InferUnionOutput<T extends $SomeSurrealType> = T extends any
|
|
318
|
+
? core.output<T>
|
|
319
|
+
: never;
|
|
320
|
+
export type $InferUnionInput<T extends $SomeSurrealType> = T extends any
|
|
321
|
+
? core.input<T>
|
|
322
|
+
: never;
|
|
323
|
+
export type $InferUnionDbOutput<T extends $SomeSurrealType> = T extends any
|
|
324
|
+
? dboutput<T>
|
|
325
|
+
: never;
|
|
326
|
+
export type $InferUnionDbInput<T extends $SomeSurrealType> = T extends any
|
|
327
|
+
? dbinput<T>
|
|
328
|
+
: never;
|
|
329
|
+
|
|
330
|
+
export interface $ZodSurrealTypeDiscriminableInternals
|
|
331
|
+
extends $ZodSurrealTypeInternals {
|
|
332
|
+
propValues: core.util.PropValues;
|
|
333
|
+
}
|
|
334
|
+
export interface $ZodSurrealTypeDiscriminable extends $ZodSurrealType {
|
|
335
|
+
_zod: $ZodSurrealTypeDiscriminableInternals;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// Tuples
|
|
339
|
+
|
|
340
|
+
export type TupleItems = ReadonlyArray<$SomeSurrealType>;
|
|
341
|
+
|
|
342
|
+
export type $InferTupleInputType<
|
|
343
|
+
T extends TupleItems,
|
|
344
|
+
Rest extends $SomeSurrealType | null,
|
|
345
|
+
> = [
|
|
346
|
+
...TupleInputTypeWithOptionals<T>,
|
|
347
|
+
...(Rest extends $SomeSurrealType ? core.input<Rest>[] : []),
|
|
348
|
+
];
|
|
349
|
+
type TupleInputTypeNoOptionals<T extends TupleItems> = {
|
|
350
|
+
[k in keyof T]: core.input<T[k]>;
|
|
351
|
+
};
|
|
352
|
+
type TupleInputTypeWithOptionals<T extends TupleItems> = T extends readonly [
|
|
353
|
+
...infer Prefix extends $SomeSurrealType[],
|
|
354
|
+
infer Tail extends $SomeSurrealType,
|
|
355
|
+
]
|
|
356
|
+
? Tail["_zod"]["optin"] extends "optional"
|
|
357
|
+
? [...TupleInputTypeWithOptionals<Prefix>, core.input<Tail>?]
|
|
358
|
+
: TupleInputTypeNoOptionals<T>
|
|
359
|
+
: [];
|
|
360
|
+
|
|
361
|
+
export type $InferTupleDbInputType<
|
|
362
|
+
T extends TupleItems,
|
|
363
|
+
Rest extends $SomeSurrealType | null,
|
|
364
|
+
> = [
|
|
365
|
+
...TupleDbInputTypeWithOptionals<T>,
|
|
366
|
+
...(Rest extends $SomeSurrealType ? dbinput<Rest>[] : []),
|
|
367
|
+
];
|
|
368
|
+
type TupleDbInputTypeNoOptionals<T extends TupleItems> = {
|
|
369
|
+
[k in keyof T]: dbinput<T[k]>;
|
|
370
|
+
};
|
|
371
|
+
type TupleDbInputTypeWithOptionals<T extends TupleItems> = T extends readonly [
|
|
372
|
+
...infer Prefix extends $SomeSurrealType[],
|
|
373
|
+
infer Tail extends $SomeSurrealType,
|
|
374
|
+
]
|
|
375
|
+
? Tail["_zod"]["dboptin"] extends "optional"
|
|
376
|
+
? [...TupleDbInputTypeWithOptionals<Prefix>, dbinput<Tail>?]
|
|
377
|
+
: TupleDbInputTypeNoOptionals<T>
|
|
378
|
+
: [];
|
|
379
|
+
|
|
380
|
+
export type $InferTupleOutputType<
|
|
381
|
+
T extends TupleItems,
|
|
382
|
+
Rest extends $SomeSurrealType | null,
|
|
383
|
+
> = [
|
|
384
|
+
...TupleOutputTypeWithOptionals<T>,
|
|
385
|
+
...(Rest extends $SomeSurrealType ? core.output<Rest>[] : []),
|
|
386
|
+
];
|
|
387
|
+
type TupleOutputTypeNoOptionals<T extends TupleItems> = {
|
|
388
|
+
[k in keyof T]: core.output<T[k]>;
|
|
389
|
+
};
|
|
390
|
+
type TupleOutputTypeWithOptionals<T extends TupleItems> = T extends readonly [
|
|
391
|
+
...infer Prefix extends $SomeSurrealType[],
|
|
392
|
+
infer Tail extends $SomeSurrealType,
|
|
393
|
+
]
|
|
394
|
+
? Tail["_zod"]["optout"] extends "optional"
|
|
395
|
+
? [...TupleOutputTypeWithOptionals<Prefix>, core.output<Tail>?]
|
|
396
|
+
: TupleOutputTypeNoOptionals<T>
|
|
397
|
+
: [];
|
|
398
|
+
|
|
399
|
+
export type $InferTupleDbOutputType<
|
|
400
|
+
T extends TupleItems,
|
|
401
|
+
Rest extends $SomeSurrealType | null,
|
|
402
|
+
> = [
|
|
403
|
+
...TupleDbOutputTypeWithOptionals<T>,
|
|
404
|
+
...(Rest extends $SomeSurrealType ? dboutput<Rest>[] : []),
|
|
405
|
+
];
|
|
406
|
+
type TupleDbOutputTypeNoOptionals<T extends TupleItems> = {
|
|
407
|
+
[k in keyof T]: dboutput<T[k]>;
|
|
408
|
+
};
|
|
409
|
+
type TupleDbOutputTypeWithOptionals<T extends TupleItems> = T extends readonly [
|
|
410
|
+
...infer Prefix extends $SomeSurrealType[],
|
|
411
|
+
infer Tail extends $SomeSurrealType,
|
|
412
|
+
]
|
|
413
|
+
? Tail["_zod"]["dboptout"] extends "optional"
|
|
414
|
+
? [...TupleDbOutputTypeWithOptionals<Prefix>, dboutput<Tail>?]
|
|
415
|
+
: TupleDbOutputTypeNoOptionals<T>
|
|
416
|
+
: [];
|
|
417
|
+
|
|
418
|
+
// Record
|
|
419
|
+
|
|
420
|
+
export type $ZodRecordKey = $ZodSurrealType<string | number | symbol, unknown>;
|
|
421
|
+
|
|
422
|
+
export type $InferZodRecordOutput<
|
|
423
|
+
Key extends $ZodRecordKey = $ZodRecordKey,
|
|
424
|
+
Value extends $SomeSurrealType = $ZodSurrealType,
|
|
425
|
+
> = Key extends core.$partial
|
|
426
|
+
? Partial<Record<core.output<Key>, core.output<Value>>>
|
|
427
|
+
: Record<core.output<Key>, core.output<Value>>;
|
|
428
|
+
|
|
429
|
+
export type $InferZodRecordInput<
|
|
430
|
+
Key extends $ZodRecordKey = $ZodRecordKey,
|
|
431
|
+
Value extends $SomeSurrealType = $ZodSurrealType,
|
|
432
|
+
> = Key extends core.$partial
|
|
433
|
+
? Partial<Record<core.input<Key> & PropertyKey, core.input<Value>>>
|
|
434
|
+
: Record<core.input<Key> & PropertyKey, core.input<Value>>;
|
|
435
|
+
|
|
436
|
+
// export type $InferZodRecordOutput<
|
|
437
|
+
// Key extends $ZodRecordKey = $ZodRecordKey,
|
|
438
|
+
// Value extends SomeType = $ZodType,
|
|
439
|
+
// > = undefined extends Key["_zod"]["values"]
|
|
440
|
+
// ? string extends core.output<Key>
|
|
441
|
+
// ? Record<core.output<Key>, core.output<Value>>
|
|
442
|
+
// : number extends core.output<Key>
|
|
443
|
+
// ? Record<core.output<Key>, core.output<Value>>
|
|
444
|
+
// : symbol extends core.output<Key>
|
|
445
|
+
// ? Record<core.output<Key>, core.output<Value>>
|
|
446
|
+
// : Record<core.output<Key>, core.output<Value>>
|
|
447
|
+
// : Record<core.output<Key>, core.output<Value>>;
|
|
448
|
+
export type $InferZodRecordDbOutput<
|
|
449
|
+
Key extends $ZodRecordKey = $ZodRecordKey,
|
|
450
|
+
Value extends $SomeSurrealType = ZodSurrealType,
|
|
451
|
+
> = Key extends core.$partial
|
|
452
|
+
? Partial<Record<dboutput<Key>, dboutput<Value>>>
|
|
453
|
+
: Record<dboutput<Key>, dboutput<Value>>;
|
|
454
|
+
|
|
455
|
+
// export type $InferZodRecordInput<
|
|
456
|
+
// Key extends $ZodRecordKey = $ZodRecordKey,
|
|
457
|
+
// Value extends SomeType = $ZodType,
|
|
458
|
+
// > = undefined extends Key["_zod"]["values"]
|
|
459
|
+
// ? string extends core.input<Key>
|
|
460
|
+
// ? Record<core.input<Key>, core.input<Value>>
|
|
461
|
+
// : number extends core.input<Key>
|
|
462
|
+
// ? Record<core.input<Key>, core.input<Value>>
|
|
463
|
+
// : symbol extends core.input<Key>
|
|
464
|
+
// ? Record<core.input<Key>, core.input<Value>>
|
|
465
|
+
// : Record<core.input<Key>, core.input<Value>>
|
|
466
|
+
// : Record<core.input<Key>, core.input<Value>>;
|
|
467
|
+
|
|
468
|
+
export type $InferZodRecordDbInput<
|
|
469
|
+
Key extends $ZodRecordKey = $ZodRecordKey,
|
|
470
|
+
Value extends $SomeSurrealType = ZodSurrealType,
|
|
471
|
+
> = Key extends core.$partial
|
|
472
|
+
? Partial<Record<dbinput<Key> & PropertyKey, dbinput<Value>>>
|
|
473
|
+
: Record<dbinput<Key> & PropertyKey, dbinput<Value>>;
|
|
474
|
+
|
|
475
|
+
// Enum
|
|
476
|
+
|
|
477
|
+
export type $InferEnumDbOutput<T extends core.util.EnumLike> = T[keyof T] & {};
|
|
478
|
+
export type $InferEnumDbInput<T extends core.util.EnumLike> = T[keyof T] & {};
|
|
479
|
+
|
|
480
|
+
// Function
|
|
481
|
+
|
|
482
|
+
export type ZodSurrealFunctionArgs = ZodSurrealType<unknown[], unknown[]>;
|
|
483
|
+
export type ZodSurrealFunctionIn = ZodSurrealFunctionArgs;
|
|
484
|
+
export type ZodSurrealFunctionOut = ZodSurrealType;
|
|
485
|
+
|
|
486
|
+
export type $InferInnerFunctionType<
|
|
487
|
+
Args extends ZodSurrealFunctionIn,
|
|
488
|
+
Returns extends ZodSurrealFunctionOut,
|
|
489
|
+
> = (
|
|
490
|
+
...args: ZodSurrealFunctionIn extends Args ? never[] : core.output<Args>
|
|
491
|
+
) => core.input<Returns>;
|
|
492
|
+
|
|
493
|
+
export type $InferInnerFunctionDbType<
|
|
494
|
+
Args extends ZodSurrealFunctionIn,
|
|
495
|
+
Returns extends ZodSurrealFunctionOut,
|
|
496
|
+
> = (
|
|
497
|
+
...args: ZodSurrealFunctionIn extends Args ? never[] : dboutput<Args>
|
|
498
|
+
) => dbinput<Returns>;
|
|
499
|
+
|
|
500
|
+
export type $InferInnerFunctionTypeAsync<
|
|
501
|
+
Args extends ZodSurrealFunctionIn,
|
|
502
|
+
Returns extends ZodSurrealFunctionOut,
|
|
503
|
+
> = (
|
|
504
|
+
...args: ZodSurrealFunctionIn extends Args ? never[] : core.output<Args>
|
|
505
|
+
) => core.util.MaybeAsync<core.input<Returns>>;
|
|
506
|
+
|
|
507
|
+
export type $InferInnerFunctionDbTypeAsync<
|
|
508
|
+
Args extends ZodSurrealFunctionIn,
|
|
509
|
+
Returns extends ZodSurrealFunctionOut,
|
|
510
|
+
> = (
|
|
511
|
+
...args: ZodSurrealFunctionIn extends Args ? never[] : dboutput<Args>
|
|
512
|
+
) => core.util.MaybeAsync<dbinput<Returns>>;
|
|
513
|
+
|
|
514
|
+
export type $InferOuterFunctionType<
|
|
515
|
+
Args extends ZodSurrealFunctionIn,
|
|
516
|
+
Returns extends ZodSurrealFunctionOut,
|
|
517
|
+
> = (
|
|
518
|
+
...args: ZodSurrealFunctionIn extends Args ? never[] : core.input<Args>
|
|
519
|
+
) => core.output<Returns>;
|
|
520
|
+
|
|
521
|
+
export type $InferOuterFunctionDbType<
|
|
522
|
+
Args extends ZodSurrealFunctionIn,
|
|
523
|
+
Returns extends ZodSurrealFunctionOut,
|
|
524
|
+
> = (
|
|
525
|
+
...args: ZodSurrealFunctionIn extends Args ? never[] : dbinput<Args>
|
|
526
|
+
) => dboutput<Returns>;
|
|
527
|
+
|
|
528
|
+
export type $InferOuterFunctionTypeAsync<
|
|
529
|
+
Args extends ZodSurrealFunctionIn,
|
|
530
|
+
Returns extends ZodSurrealFunctionOut,
|
|
531
|
+
> = (
|
|
532
|
+
...args: ZodSurrealFunctionIn extends Args ? never[] : core.input<Args>
|
|
533
|
+
) => Promise<core.output<Returns>>;
|
|
534
|
+
|
|
535
|
+
export type $InferOuterFunctionDbTypeAsync<
|
|
536
|
+
Args extends ZodSurrealFunctionIn,
|
|
537
|
+
Returns extends ZodSurrealFunctionOut,
|
|
538
|
+
> = (
|
|
539
|
+
...args: ZodSurrealFunctionIn extends Args ? never[] : dbinput<Args>
|
|
540
|
+
) => Promise<dboutput<Returns>>;
|
|
541
|
+
|
|
542
|
+
export interface ZodSurrealFunctionDef<
|
|
543
|
+
In extends ZodSurrealFunctionIn = ZodSurrealFunctionIn,
|
|
544
|
+
Out extends ZodSurrealFunctionOut = ZodSurrealFunctionOut,
|
|
545
|
+
> extends $ZodSurrealTypeDef {
|
|
546
|
+
type: "function";
|
|
547
|
+
input: In;
|
|
548
|
+
output: Out;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
// Literal
|
|
552
|
+
|
|
553
|
+
type LiteralPart = Exclude<core.util.Literal, symbol>;
|
|
554
|
+
interface SchemaPartInternals
|
|
555
|
+
extends $ZodSurrealTypeInternals<LiteralPart, LiteralPart> {
|
|
556
|
+
pattern: RegExp;
|
|
557
|
+
}
|
|
558
|
+
interface SchemaPart extends $ZodSurrealType {
|
|
559
|
+
_zod: SchemaPartInternals;
|
|
560
|
+
}
|
|
561
|
+
export type $ZodSurrealTemplateLiteralPart = LiteralPart | SchemaPart;
|
|
562
|
+
type UndefinedToEmptyString<T> = T extends undefined ? "" : T;
|
|
563
|
+
type AppendToTemplateLiteral<
|
|
564
|
+
Template extends string,
|
|
565
|
+
Suffix extends LiteralPart | $ZodSurrealType,
|
|
566
|
+
> = Suffix extends LiteralPart
|
|
567
|
+
? `${Template}${UndefinedToEmptyString<Suffix>}`
|
|
568
|
+
: Suffix extends $ZodSurrealType
|
|
569
|
+
? `${Template}${core.output<Suffix> extends infer T extends LiteralPart ? UndefinedToEmptyString<T> : never}`
|
|
570
|
+
: never;
|
|
571
|
+
export type $PartsToTemplateLiteral<
|
|
572
|
+
Parts extends $ZodSurrealTemplateLiteralPart[],
|
|
573
|
+
> = [] extends Parts
|
|
574
|
+
? ``
|
|
575
|
+
: Parts extends [
|
|
576
|
+
...infer Rest,
|
|
577
|
+
infer Last extends $ZodSurrealTemplateLiteralPart,
|
|
578
|
+
]
|
|
579
|
+
? Rest extends $ZodSurrealTemplateLiteralPart[]
|
|
580
|
+
? AppendToTemplateLiteral<$PartsToTemplateLiteral<Rest>, Last>
|
|
581
|
+
: never
|
|
582
|
+
: never;
|
|
583
|
+
|
|
584
|
+
///////////////////////////// Type Overriden Functions /////////////////////////
|
|
585
|
+
|
|
586
|
+
export function normalizeParams<T, S extends $ZodSurrealTypeDefInternals>(
|
|
587
|
+
_params: T,
|
|
588
|
+
surreal?: S,
|
|
589
|
+
): core.util.Normalize<T> & {
|
|
590
|
+
surreal: Exclude<S, undefined>;
|
|
591
|
+
} {
|
|
592
|
+
const params = core.util.normalizeParams(_params);
|
|
593
|
+
if (params && typeof params === "object") {
|
|
594
|
+
return { ...params, surreal: surreal ?? {} } as any;
|
|
595
|
+
}
|
|
596
|
+
return params ?? { surreal: surreal ?? {} };
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
export const clone: <T extends $ZodSurrealType>(
|
|
600
|
+
inst: T,
|
|
601
|
+
def?: T["_zod"]["def"],
|
|
602
|
+
params?: {
|
|
603
|
+
parent: boolean;
|
|
604
|
+
},
|
|
605
|
+
) => T = core.clone as any;
|
package/src/zod/index.ts
ADDED