feat(planning): grille hebdomadaire complète avec API et filtres
- Connexion API via proxy Angular (résolution CORS, base path /api) - Import CSS ng-zorro global pour les modales et composants - Filtres Camion/Show câblés sur l'affichage de la grille - Camions affichés via TrucksService (linkés au show du même créneau) - Panneau de détails : spectacles + camions du jour sélectionné - Modale de création de spectacle stylisée avec fond et centrage - Positionnement précis des events à la minute dans leur créneau - Auto-scroll vers l'heure courante au chargement - Ligne "maintenant" sur la colonne du jour actuel - Régénération des services OpenAPI (nouveaux noms de types) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+1
-1
@@ -11,6 +11,7 @@ export {
|
||||
$output,
|
||||
$input,
|
||||
$brand,
|
||||
function,
|
||||
clone,
|
||||
regexes,
|
||||
treeifyError,
|
||||
@@ -19,7 +20,6 @@ export {
|
||||
flattenError,
|
||||
toJSONSchema,
|
||||
TimePrecision,
|
||||
util,
|
||||
NEVER,
|
||||
} from "../core/index.js";
|
||||
|
||||
|
||||
+4
-4
@@ -6,7 +6,7 @@ export interface ZodMiniISODateTime extends schemas.ZodMiniStringFormat<"datetim
|
||||
_zod: core.$ZodISODateTimeInternals;
|
||||
}
|
||||
export const ZodMiniISODateTime: core.$constructor<ZodMiniISODateTime> = /*@__PURE__*/ core.$constructor(
|
||||
"ZodMiniISODateTime",
|
||||
"$ZodISODateTime",
|
||||
(inst, def) => {
|
||||
core.$ZodISODateTime.init(inst, def);
|
||||
schemas.ZodMiniStringFormat.init(inst, def);
|
||||
@@ -21,7 +21,7 @@ export interface ZodMiniISODate extends schemas.ZodMiniStringFormat<"date"> {
|
||||
_zod: core.$ZodISODateInternals;
|
||||
}
|
||||
export const ZodMiniISODate: core.$constructor<ZodMiniISODate> = /*@__PURE__*/ core.$constructor(
|
||||
"ZodMiniISODate",
|
||||
"$ZodISODate",
|
||||
(inst, def) => {
|
||||
core.$ZodISODate.init(inst, def);
|
||||
schemas.ZodMiniStringFormat.init(inst, def);
|
||||
@@ -36,7 +36,7 @@ export interface ZodMiniISOTime extends schemas.ZodMiniStringFormat<"time"> {
|
||||
_zod: core.$ZodISOTimeInternals;
|
||||
}
|
||||
export const ZodMiniISOTime: core.$constructor<ZodMiniISOTime> = /*@__PURE__*/ core.$constructor(
|
||||
"ZodMiniISOTime",
|
||||
"$ZodISOTime",
|
||||
(inst, def) => {
|
||||
core.$ZodISOTime.init(inst, def);
|
||||
schemas.ZodMiniStringFormat.init(inst, def);
|
||||
@@ -51,7 +51,7 @@ export interface ZodMiniISODuration extends schemas.ZodMiniStringFormat<"duratio
|
||||
_zod: core.$ZodISODurationInternals;
|
||||
}
|
||||
export const ZodMiniISODuration: core.$constructor<ZodMiniISODuration> = /*@__PURE__*/ core.$constructor(
|
||||
"ZodMiniISODuration",
|
||||
"$ZodISODuration",
|
||||
(inst, def) => {
|
||||
core.$ZodISODuration.init(inst, def);
|
||||
schemas.ZodMiniStringFormat.init(inst, def);
|
||||
|
||||
+1
-14
@@ -1,14 +1 @@
|
||||
export {
|
||||
parse,
|
||||
safeParse,
|
||||
parseAsync,
|
||||
safeParseAsync,
|
||||
encode,
|
||||
decode,
|
||||
encodeAsync,
|
||||
decodeAsync,
|
||||
safeEncode,
|
||||
safeDecode,
|
||||
safeEncodeAsync,
|
||||
safeDecodeAsync,
|
||||
} from "../core/index.js";
|
||||
export { parse, safeParse, parseAsync, safeParseAsync } from "../core/index.js";
|
||||
|
||||
+40
-203
@@ -9,7 +9,6 @@ export interface ZodMiniType<
|
||||
out Input = unknown,
|
||||
out Internals extends core.$ZodTypeInternals<Output, Input> = core.$ZodTypeInternals<Output, Input>,
|
||||
> extends core.$ZodType<Output, Input, Internals> {
|
||||
type: Internals["def"]["type"];
|
||||
check(...checks: (core.CheckFn<core.output<this>> | core.$ZodCheck<core.output<this>>)[]): this;
|
||||
clone(def?: Internals["def"], params?: { parent: boolean }): this;
|
||||
register<R extends core.$ZodRegistry>(
|
||||
@@ -44,9 +43,7 @@ export const ZodMiniType: core.$constructor<ZodMiniType> = /*@__PURE__*/ core.$c
|
||||
if (!inst._zod) throw new Error("Uninitialized schema in ZodMiniType.");
|
||||
|
||||
core.$ZodType.init(inst, def);
|
||||
|
||||
inst.def = def;
|
||||
inst.type = def.type;
|
||||
inst.parse = (data, params) => parse.parse(inst, data, params, { callee: inst.parse });
|
||||
inst.safeParse = (data, params) => parse.safeParse(inst, data, params);
|
||||
inst.parseAsync = async (data, params) => parse.parseAsync(inst, data, params, { callee: inst.parseAsync });
|
||||
@@ -185,14 +182,6 @@ export function url(params?: string | core.$ZodURLParams): ZodMiniURL {
|
||||
return core._url(ZodMiniURL, params);
|
||||
}
|
||||
|
||||
export function httpUrl(params?: string | Omit<core.$ZodURLParams, "protocol" | "hostname">): ZodMiniURL {
|
||||
return core._url(ZodMiniURL, {
|
||||
protocol: /^https?$/,
|
||||
hostname: core.regexes.domain,
|
||||
...util.normalizeParams(params),
|
||||
});
|
||||
}
|
||||
|
||||
// ZodMiniEmoji
|
||||
export interface ZodMiniEmoji extends _ZodMiniString<core.$ZodEmojiInternals> {
|
||||
// _zod: core.$ZodEmojiInternals;
|
||||
@@ -366,19 +355,6 @@ export function cidrv6(params?: string | core.$ZodCIDRv6Params): ZodMiniCIDRv6 {
|
||||
return core._cidrv6(ZodMiniCIDRv6, params);
|
||||
}
|
||||
|
||||
// ZodMiniMAC
|
||||
export interface ZodMiniMAC extends _ZodMiniString<core.$ZodMACInternals> {
|
||||
// _zod: core.$ZodMACInternals;
|
||||
}
|
||||
export const ZodMiniMAC: core.$constructor<ZodMiniMAC> = /*@__PURE__*/ core.$constructor("ZodMiniMAC", (inst, def) => {
|
||||
core.$ZodMAC.init(inst, def);
|
||||
ZodMiniStringFormat.init(inst, def);
|
||||
});
|
||||
|
||||
export function mac(params?: string | core.$ZodMACParams): ZodMiniMAC {
|
||||
return core._mac(ZodMiniMAC, params);
|
||||
}
|
||||
|
||||
// ZodMiniBase64
|
||||
export interface ZodMiniBase64 extends _ZodMiniString<core.$ZodBase64Internals> {
|
||||
// _zod: core.$ZodBase64Internals;
|
||||
@@ -460,28 +436,6 @@ export function stringFormat<Format extends string>(
|
||||
return core._stringFormat(ZodMiniCustomStringFormat, format, fnOrRegex, _params) as any;
|
||||
}
|
||||
|
||||
export function hostname(_params?: string | core.$ZodStringFormatParams): ZodMiniCustomStringFormat<"hostname"> {
|
||||
return core._stringFormat(ZodMiniCustomStringFormat, "hostname", core.regexes.hostname, _params) as any;
|
||||
}
|
||||
|
||||
export function hex(_params?: string | core.$ZodStringFormatParams): ZodMiniCustomStringFormat<"hex"> {
|
||||
return core._stringFormat(ZodMiniCustomStringFormat, "hex", core.regexes.hex, _params) as any;
|
||||
}
|
||||
|
||||
export function hash<Alg extends util.HashAlgorithm, Enc extends util.HashEncoding = "hex">(
|
||||
alg: Alg,
|
||||
params?: {
|
||||
enc?: Enc;
|
||||
} & core.$ZodStringFormatParams
|
||||
): ZodMiniCustomStringFormat<`${Alg}_${Enc}`> {
|
||||
const enc = params?.enc ?? "hex";
|
||||
const format = `${alg}_${enc}` as const;
|
||||
const regex = core.regexes[format as keyof typeof core.regexes] as RegExp;
|
||||
// check for unrecognized format
|
||||
if (!regex) throw new Error(`Unrecognized hash format: ${format}`);
|
||||
return core._stringFormat(ZodMiniCustomStringFormat, format, regex, params) as any;
|
||||
}
|
||||
|
||||
// ZodMiniNumber
|
||||
interface _ZodMiniNumber<T extends core.$ZodNumberInternals<unknown> = core.$ZodNumberInternals<unknown>>
|
||||
extends _ZodMiniType<T>,
|
||||
@@ -754,9 +708,9 @@ export function array<T extends SomeType>(element: SomeType, params?: any): ZodM
|
||||
}
|
||||
|
||||
// .keyof
|
||||
export function keyof<T extends ZodMiniObject>(schema: T): ZodMiniEnum<util.KeysEnum<T["shape"]>> {
|
||||
export function keyof<T extends ZodMiniObject>(schema: T): ZodMiniLiteral<Exclude<keyof T["shape"], symbol>> {
|
||||
const shape = schema._zod.def.shape;
|
||||
return _enum(Object.keys(shape)) as any;
|
||||
return literal(Object.keys(shape)) as any;
|
||||
}
|
||||
|
||||
// ZodMiniObject
|
||||
@@ -782,7 +736,10 @@ export function object<T extends core.$ZodLooseShape = Record<never, SomeType>>(
|
||||
): ZodMiniObject<T, core.$strip> {
|
||||
const def: core.$ZodObjectDef = {
|
||||
type: "object",
|
||||
shape: shape ?? {},
|
||||
get shape() {
|
||||
util.assignProp(this, "shape", { ...shape });
|
||||
return this.shape;
|
||||
},
|
||||
...util.normalizeParams(params),
|
||||
};
|
||||
return new ZodMiniObject(def) as any;
|
||||
@@ -795,7 +752,11 @@ export function strictObject<T extends core.$ZodLooseShape>(
|
||||
): ZodMiniObject<T, core.$strict> {
|
||||
return new ZodMiniObject({
|
||||
type: "object",
|
||||
shape,
|
||||
// shape: shape as core.$ZodLooseShape,
|
||||
get shape() {
|
||||
util.assignProp(this, "shape", { ...shape });
|
||||
return this.shape;
|
||||
},
|
||||
catchall: never(),
|
||||
...util.normalizeParams(params),
|
||||
}) as any;
|
||||
@@ -808,7 +769,14 @@ export function looseObject<T extends core.$ZodLooseShape>(
|
||||
): ZodMiniObject<T, core.$loose> {
|
||||
return new ZodMiniObject({
|
||||
type: "object",
|
||||
shape,
|
||||
// shape: shape as core.$ZodLooseShape,
|
||||
get shape() {
|
||||
util.assignProp(this, "shape", { ...shape });
|
||||
return this.shape;
|
||||
},
|
||||
// get optional() {
|
||||
// return util.optionalKeys(shape);
|
||||
// },
|
||||
catchall: unknown(),
|
||||
...util.normalizeParams(params),
|
||||
}) as any;
|
||||
@@ -822,23 +790,6 @@ export function extend<T extends ZodMiniObject, U extends core.$ZodLooseShape>(
|
||||
return util.extend(schema, shape);
|
||||
}
|
||||
|
||||
export type SafeExtendShape<Base extends core.$ZodShape, Ext extends core.$ZodLooseShape> = {
|
||||
[K in keyof Ext]: K extends keyof Base
|
||||
? core.output<Ext[K]> extends core.output<Base[K]>
|
||||
? core.input<Ext[K]> extends core.input<Base[K]>
|
||||
? Ext[K]
|
||||
: never
|
||||
: never
|
||||
: Ext[K];
|
||||
};
|
||||
|
||||
export function safeExtend<T extends ZodMiniObject, U extends core.$ZodLooseShape>(
|
||||
schema: T,
|
||||
shape: SafeExtendShape<T["shape"], U>
|
||||
): ZodMiniObject<util.Extend<T["shape"], U>, T["_zod"]["config"]> {
|
||||
return util.safeExtend(schema, shape as any);
|
||||
}
|
||||
|
||||
/** @deprecated Identical to `z.extend(A, B)` */
|
||||
export function merge<T extends ZodMiniObject, U extends ZodMiniObject>(
|
||||
a: T,
|
||||
@@ -952,11 +903,9 @@ export function union<const T extends readonly SomeType[]>(
|
||||
}
|
||||
|
||||
// ZodMiniDiscriminatedUnion
|
||||
export interface ZodMiniDiscriminatedUnion<
|
||||
Options extends readonly SomeType[] = readonly core.$ZodType[],
|
||||
Disc extends string = string,
|
||||
> extends ZodMiniUnion<Options> {
|
||||
_zod: core.$ZodDiscriminatedUnionInternals<Options, Disc>;
|
||||
export interface ZodMiniDiscriminatedUnion<Options extends readonly SomeType[] = readonly core.$ZodType[]>
|
||||
extends ZodMiniUnion<Options> {
|
||||
_zod: core.$ZodDiscriminatedUnionInternals<Options>;
|
||||
}
|
||||
export const ZodMiniDiscriminatedUnion: core.$constructor<ZodMiniDiscriminatedUnion> = /*@__PURE__*/ core.$constructor(
|
||||
"ZodMiniDiscriminatedUnion",
|
||||
@@ -968,18 +917,17 @@ export const ZodMiniDiscriminatedUnion: core.$constructor<ZodMiniDiscriminatedUn
|
||||
|
||||
export function discriminatedUnion<
|
||||
Types extends readonly [core.$ZodTypeDiscriminable, ...core.$ZodTypeDiscriminable[]],
|
||||
Disc extends string,
|
||||
>(
|
||||
discriminator: Disc,
|
||||
discriminator: string,
|
||||
options: Types,
|
||||
params?: string | core.$ZodDiscriminatedUnionParams
|
||||
): ZodMiniDiscriminatedUnion<Types, Disc> {
|
||||
): ZodMiniDiscriminatedUnion<Types> {
|
||||
return new ZodMiniDiscriminatedUnion({
|
||||
type: "union",
|
||||
options,
|
||||
discriminator,
|
||||
...util.normalizeParams(params),
|
||||
}) as ZodMiniDiscriminatedUnion<Types, Disc>;
|
||||
}) as ZodMiniDiscriminatedUnion<Types>;
|
||||
}
|
||||
|
||||
// ZodMiniIntersection
|
||||
@@ -1076,11 +1024,9 @@ export function partialRecord<Key extends core.$ZodRecordKey, Value extends Some
|
||||
valueType: Value,
|
||||
params?: string | core.$ZodRecordParams
|
||||
): ZodMiniRecord<Key & core.$partial, Value> {
|
||||
const k = core.clone(keyType);
|
||||
k._zod.values = undefined;
|
||||
return new ZodMiniRecord({
|
||||
type: "record",
|
||||
keyType: k,
|
||||
keyType: union([keyType, never()]),
|
||||
valueType: valueType as any,
|
||||
...util.normalizeParams(params),
|
||||
}) as any;
|
||||
@@ -1129,15 +1075,12 @@ export function set<Value extends SomeType>(valueType: Value, params?: string |
|
||||
// ZodMiniEnum
|
||||
export interface ZodMiniEnum<T extends util.EnumLike = util.EnumLike> extends _ZodMiniType<core.$ZodEnumInternals<T>> {
|
||||
// _zod: core.$ZodEnumInternals<T>;
|
||||
options: Array<T[keyof T]>;
|
||||
}
|
||||
export const ZodMiniEnum: core.$constructor<ZodMiniEnum> = /*@__PURE__*/ core.$constructor(
|
||||
"ZodMiniEnum",
|
||||
(inst, def) => {
|
||||
core.$ZodEnum.init(inst, def);
|
||||
ZodMiniType.init(inst, def);
|
||||
|
||||
inst.options = Object.values(def.entries);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -1304,7 +1247,7 @@ export function _default<T extends SomeType>(
|
||||
type: "default",
|
||||
innerType: innerType as any as core.$ZodType,
|
||||
get defaultValue() {
|
||||
return typeof defaultValue === "function" ? (defaultValue as Function)() : util.shallowClone(defaultValue);
|
||||
return typeof defaultValue === "function" ? (defaultValue as Function)() : defaultValue;
|
||||
},
|
||||
}) as any;
|
||||
}
|
||||
@@ -1329,7 +1272,7 @@ export function prefault<T extends SomeType>(
|
||||
type: "prefault",
|
||||
innerType: innerType as any as core.$ZodType,
|
||||
get defaultValue() {
|
||||
return typeof defaultValue === "function" ? (defaultValue as Function)() : util.shallowClone(defaultValue);
|
||||
return typeof defaultValue === "function" ? (defaultValue as Function)() : defaultValue;
|
||||
},
|
||||
}) as any;
|
||||
}
|
||||
@@ -1440,38 +1383,6 @@ export function pipe<
|
||||
}) as any;
|
||||
}
|
||||
|
||||
// ZodMiniCodec
|
||||
export interface ZodMiniCodec<A extends SomeType = core.$ZodType, B extends SomeType = core.$ZodType>
|
||||
extends ZodMiniPipe<A, B>,
|
||||
core.$ZodCodec<A, B> {
|
||||
_zod: core.$ZodCodecInternals<A, B>;
|
||||
def: core.$ZodCodecDef<A, B>;
|
||||
}
|
||||
export const ZodMiniCodec: core.$constructor<ZodMiniCodec> = /*@__PURE__*/ core.$constructor(
|
||||
"ZodMiniCodec",
|
||||
(inst, def) => {
|
||||
ZodMiniPipe.init(inst, def);
|
||||
core.$ZodCodec.init(inst, def);
|
||||
}
|
||||
);
|
||||
|
||||
export function codec<const A extends SomeType, B extends core.SomeType = core.$ZodType>(
|
||||
in_: A,
|
||||
out: B,
|
||||
params: {
|
||||
decode: (value: core.output<A>, payload: core.ParsePayload<core.output<A>>) => core.util.MaybeAsync<core.input<B>>;
|
||||
encode: (value: core.input<B>, payload: core.ParsePayload<core.input<B>>) => core.util.MaybeAsync<core.output<A>>;
|
||||
}
|
||||
): ZodMiniCodec<A, B> {
|
||||
return new ZodMiniCodec({
|
||||
type: "pipe",
|
||||
in: in_ as any as core.$ZodType,
|
||||
out: out as any as core.$ZodType,
|
||||
transform: params.decode as any,
|
||||
reverseTransform: params.encode as any,
|
||||
}) as any;
|
||||
}
|
||||
|
||||
// /** @deprecated Use `z.pipe()` and `z.transform()` instead. */
|
||||
// export function preprocess<A, U extends core.$ZodType>(
|
||||
// fn: (arg: unknown, ctx: core.ParsePayload) => A,
|
||||
@@ -1607,17 +1518,6 @@ export function refine<T>(
|
||||
return core._refine(ZodMiniCustom, fn, _params);
|
||||
}
|
||||
|
||||
// superRefine
|
||||
export function superRefine<T>(
|
||||
fn: (arg: T, payload: core.$RefinementCtx<T>) => void | Promise<void>
|
||||
): core.$ZodCheck<T> {
|
||||
return core._superRefine(fn);
|
||||
}
|
||||
|
||||
// Re-export describe and meta from core
|
||||
export const describe = core.describe;
|
||||
export const meta = core.meta;
|
||||
|
||||
// instanceof
|
||||
abstract class Class {
|
||||
constructor(..._args: any[]) {}
|
||||
@@ -1635,16 +1535,18 @@ function _instanceof<T extends typeof Class>(
|
||||
export { _instanceof as instanceof };
|
||||
|
||||
// stringbool
|
||||
export const stringbool: (_params?: string | core.$ZodStringBoolParams) => ZodMiniCodec<ZodMiniString, ZodMiniBoolean> =
|
||||
(...args) =>
|
||||
core._stringbool(
|
||||
{
|
||||
Codec: ZodMiniCodec,
|
||||
Boolean: ZodMiniBoolean,
|
||||
String: ZodMiniString,
|
||||
},
|
||||
...args
|
||||
) as any;
|
||||
export const stringbool: (
|
||||
_params?: string | core.$ZodStringBoolParams
|
||||
) => ZodMiniPipe<ZodMiniPipe<ZodMiniString, ZodMiniTransform<boolean, string>>, ZodMiniBoolean> = (...args) =>
|
||||
core._stringbool(
|
||||
{
|
||||
Pipe: ZodMiniPipe,
|
||||
Boolean: ZodMiniBoolean,
|
||||
String: ZodMiniString,
|
||||
Transform: ZodMiniTransform,
|
||||
},
|
||||
...args
|
||||
) as any;
|
||||
|
||||
// json
|
||||
|
||||
@@ -1675,68 +1577,3 @@ export function json(): ZodMiniJSONSchema {
|
||||
});
|
||||
return jsonSchema;
|
||||
}
|
||||
|
||||
// ZodMiniFunction
|
||||
export interface ZodMiniFunction<
|
||||
Args extends core.$ZodFunctionIn = core.$ZodFunctionIn,
|
||||
Returns extends core.$ZodFunctionOut = core.$ZodFunctionOut,
|
||||
> extends _ZodMiniType<core.$ZodFunctionInternals<Args, Returns>>,
|
||||
core.$ZodFunction<Args, Returns> {
|
||||
_def: core.$ZodFunctionDef<Args, Returns>;
|
||||
_input: core.$InferInnerFunctionType<Args, Returns>;
|
||||
_output: core.$InferOuterFunctionType<Args, Returns>;
|
||||
|
||||
input<const Items extends util.TupleItems, const Rest extends core.$ZodFunctionOut = core.$ZodFunctionOut>(
|
||||
args: Items,
|
||||
rest?: Rest
|
||||
): ZodMiniFunction<ZodMiniTuple<Items, Rest>, Returns>;
|
||||
input<NewArgs extends core.$ZodFunctionIn>(args: NewArgs): ZodMiniFunction<NewArgs, Returns>;
|
||||
input(...args: any[]): ZodMiniFunction<any, Returns>;
|
||||
|
||||
output<NewReturns extends core.$ZodFunctionOut>(output: NewReturns): ZodMiniFunction<Args, NewReturns>;
|
||||
}
|
||||
|
||||
export const ZodMiniFunction: core.$constructor<ZodMiniFunction> = /*@__PURE__*/ core.$constructor(
|
||||
"ZodMiniFunction",
|
||||
(inst, def) => {
|
||||
core.$ZodFunction.init(inst, def);
|
||||
ZodMiniType.init(inst, def);
|
||||
}
|
||||
);
|
||||
|
||||
export function _function(): ZodMiniFunction;
|
||||
export function _function<const In extends Array<SomeType> = Array<SomeType>>(params: {
|
||||
input: In;
|
||||
}): ZodMiniFunction<ZodMiniTuple<In, null>, core.$ZodFunctionOut>;
|
||||
export function _function<
|
||||
const In extends Array<SomeType> = Array<SomeType>,
|
||||
const Out extends core.$ZodFunctionOut = core.$ZodFunctionOut,
|
||||
>(params: {
|
||||
input: In;
|
||||
output: Out;
|
||||
}): ZodMiniFunction<ZodMiniTuple<In, null>, Out>;
|
||||
export function _function<const In extends core.$ZodFunctionIn = core.$ZodFunctionIn>(params: {
|
||||
input: In;
|
||||
}): ZodMiniFunction<In, core.$ZodFunctionOut>;
|
||||
export function _function<const Out extends core.$ZodFunctionOut = core.$ZodFunctionOut>(params: {
|
||||
output: Out;
|
||||
}): ZodMiniFunction<core.$ZodFunctionIn, Out>;
|
||||
export function _function<
|
||||
In extends core.$ZodFunctionIn = core.$ZodFunctionIn,
|
||||
Out extends core.$ZodFunctionOut = core.$ZodFunctionOut,
|
||||
>(params?: {
|
||||
input: In;
|
||||
output: Out;
|
||||
}): ZodMiniFunction<In, Out>;
|
||||
export function _function(params?: {
|
||||
output?: core.$ZodFunctionOut;
|
||||
input?: core.$ZodFunctionArgs | Array<SomeType>;
|
||||
}): ZodMiniFunction {
|
||||
return new ZodMiniFunction({
|
||||
type: "function",
|
||||
input: Array.isArray(params?.input) ? tuple(params?.input as any) : (params?.input ?? array(unknown())),
|
||||
output: params?.output ?? unknown(),
|
||||
});
|
||||
}
|
||||
|
||||
export { _function as function };
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
import { test } from "vitest";
|
||||
|
||||
import * as z from "zod/mini";
|
||||
import * as z from "zod/v4-mini";
|
||||
|
||||
test("assignability", () => {
|
||||
// $ZodString
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
import { expect, test } from "vitest";
|
||||
import * as z from "zod/mini";
|
||||
import * as z from "zod/v4-mini";
|
||||
import { util as zc } from "zod/v4/core";
|
||||
|
||||
test("min/max", () => {
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
import { expect, test } from "vitest";
|
||||
import * as z from "zod/mini";
|
||||
import * as z from "zod/v4-mini";
|
||||
|
||||
test("no locale by default", () => {
|
||||
const result = z.safeParse(z.string(), 12);
|
||||
|
||||
+38
@@ -1,5 +1,43 @@
|
||||
import { expect, test } from "vitest";
|
||||
// import * as z from "zod/v4/core";
|
||||
|
||||
test("z.function", () => {
|
||||
expect(true).toEqual(true);
|
||||
});
|
||||
|
||||
// test("z.function", () => {
|
||||
// const a = z.function({
|
||||
// args: z.tuple([z.string()]),
|
||||
// returns: z.string(),
|
||||
// });
|
||||
|
||||
// const myFunc = a.implement((name: string | number) => `Hello, ${name}!`);
|
||||
|
||||
// expect(myFunc("world")).toEqual("Hello, world!");
|
||||
// expect(() => myFunc(123 as any)).toThrow();
|
||||
|
||||
// // this won't run
|
||||
// () => {
|
||||
// // @ts-expect-error
|
||||
// const r = myFunc(123);
|
||||
// expectTypeOf(r).toEqualTypeOf<string>();
|
||||
// };
|
||||
// });
|
||||
|
||||
// test("z.function async", async () => {
|
||||
// const b = z.function({
|
||||
// args: z.tuple([z.string()]).$check(async (_) => {}),
|
||||
// returns: z.string().$check(async (_) => {}),
|
||||
// });
|
||||
// const myFuncAsync = b.implementAsync(async (name) => `Hello, ${name}!`);
|
||||
|
||||
// expect(await myFuncAsync("world")).toEqual("Hello, world!");
|
||||
// expect(myFuncAsync(123 as any)).rejects.toThrow();
|
||||
|
||||
// // this won't run
|
||||
// () => {
|
||||
// // @ts-expect-error
|
||||
// const r = myFuncAsync(123);
|
||||
// expectTypeOf(r).toEqualTypeOf<Promise<string>>();
|
||||
// };
|
||||
// });
|
||||
|
||||
+2
-53
@@ -1,5 +1,5 @@
|
||||
import { expect, expectTypeOf, test } from "vitest";
|
||||
import * as z from "zod/mini";
|
||||
import * as z from "zod/v4-mini";
|
||||
import type { util } from "zod/v4/core";
|
||||
|
||||
test("z.boolean", () => {
|
||||
@@ -296,29 +296,6 @@ test("z.record", () => {
|
||||
expect(() => z.parse(c, { a: "hello", b: "world" })).toThrow();
|
||||
// extra keys
|
||||
expect(() => z.parse(c, { a: "hello", b: "world", c: "world", d: "world" })).toThrow();
|
||||
|
||||
// literal union keys
|
||||
const d = z.record(z.union([z.literal("a"), z.literal(0)]), z.string());
|
||||
type d = z.output<typeof d>;
|
||||
expectTypeOf<d>().toEqualTypeOf<Record<"a" | 0, string>>();
|
||||
expect(z.parse(d, { a: "hello", 0: "world" })).toEqual({
|
||||
a: "hello",
|
||||
0: "world",
|
||||
});
|
||||
|
||||
// TypeScript enum keys
|
||||
enum Enum {
|
||||
A = 0,
|
||||
B = "hi",
|
||||
}
|
||||
|
||||
const e = z.record(z.enum(Enum), z.string());
|
||||
type e = z.output<typeof e>;
|
||||
expectTypeOf<e>().toEqualTypeOf<Record<Enum, string>>();
|
||||
expect(z.parse(e, { [Enum.A]: "hello", [Enum.B]: "world" })).toEqual({
|
||||
[Enum.A]: "hello",
|
||||
[Enum.B]: "world",
|
||||
});
|
||||
});
|
||||
|
||||
test("z.map", () => {
|
||||
@@ -812,7 +789,7 @@ test("z.stringbool", () => {
|
||||
test("z.promise", async () => {
|
||||
const a = z.promise(z.string());
|
||||
type a = z.output<typeof a>;
|
||||
expectTypeOf<a>().toEqualTypeOf<Promise<string>>();
|
||||
expectTypeOf<a>().toEqualTypeOf<string>();
|
||||
|
||||
expect(await z.safeParseAsync(a, Promise.resolve("hello"))).toMatchObject({
|
||||
success: true,
|
||||
@@ -892,31 +869,3 @@ test("def typing", () => {
|
||||
z.catch(z.string(), "fallback").def.type satisfies "catch";
|
||||
z.file().def.type satisfies "file";
|
||||
});
|
||||
|
||||
test("defaulted object schema returns shallow clone", () => {
|
||||
const schema = z._default(
|
||||
z.object({
|
||||
a: z.string(),
|
||||
}),
|
||||
{ a: "x" }
|
||||
);
|
||||
const result1 = schema.parse(undefined);
|
||||
const result2 = schema.parse(undefined);
|
||||
expect(result1).not.toBe(result2);
|
||||
expect(result1).toEqual(result2);
|
||||
});
|
||||
|
||||
test("runtime type property exists and returns correct values", () => {
|
||||
const stringSchema = z.string();
|
||||
expect(stringSchema.type).toBe("string");
|
||||
});
|
||||
|
||||
test("type narrowing works with type property", () => {
|
||||
type ArrayOrRecord = z.ZodMiniArray<z.ZodMiniString> | z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniAny>;
|
||||
const arraySchema = z.array(z.string()) as ArrayOrRecord;
|
||||
|
||||
if (arraySchema.type === "array") {
|
||||
expectTypeOf(arraySchema).toEqualTypeOf<z.ZodMiniArray<z.ZodMiniString<unknown>>>();
|
||||
expect(arraySchema.def.element).toBeDefined();
|
||||
}
|
||||
});
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
import { expect, expectTypeOf, test } from "vitest";
|
||||
import * as z from "zod/mini";
|
||||
import * as z from "zod/v4-mini";
|
||||
|
||||
test("z.number", () => {
|
||||
const a = z.number();
|
||||
|
||||
+1
-16
@@ -1,5 +1,5 @@
|
||||
import { expect, expectTypeOf, test } from "vitest";
|
||||
import * as z from "zod/mini";
|
||||
import * as z from "zod/v4-mini";
|
||||
|
||||
test("z.object", () => {
|
||||
const a = z.object({
|
||||
@@ -89,12 +89,6 @@ test("z.keyof", () => {
|
||||
type UserKeys = z.infer<typeof userKeysSchema>;
|
||||
expectTypeOf<UserKeys>().toEqualTypeOf<"name" | "age" | "email">();
|
||||
expect(userKeysSchema).toBeDefined();
|
||||
expect(userKeysSchema._zod.def.type).toBe("enum");
|
||||
expect(userKeysSchema._zod.def.entries).toEqual({
|
||||
name: "name",
|
||||
age: "age",
|
||||
email: "email",
|
||||
});
|
||||
expect(z.safeParse(userKeysSchema, "name").success).toBe(true);
|
||||
expect(z.safeParse(userKeysSchema, "age").success).toBe(true);
|
||||
expect(z.safeParse(userKeysSchema, "email").success).toBe(true);
|
||||
@@ -116,15 +110,6 @@ test("z.extend", () => {
|
||||
expect(z.safeParse(extendedSchema, { name: "John", age: 30, isAdmin: true }).success).toBe(true);
|
||||
});
|
||||
|
||||
test("z.safeExtend", () => {
|
||||
const extended = z.safeExtend(userSchema, { name: z.string() });
|
||||
expect(z.safeParse(extended, { name: "John", age: 30 }).success).toBe(true);
|
||||
type Extended = z.infer<typeof extended>;
|
||||
expectTypeOf<Extended>().toEqualTypeOf<{ name: string; age: number; email?: string }>();
|
||||
// @ts-expect-error
|
||||
z.safeExtend(userSchema, { name: z.number() });
|
||||
});
|
||||
|
||||
test("z.pick", () => {
|
||||
const pickedSchema = z.pick(userSchema, { name: true, email: true });
|
||||
type PickedUser = z.infer<typeof pickedSchema>;
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
import { expect, test } from "vitest";
|
||||
import * as z from "zod/mini";
|
||||
import * as z from "zod/v4-mini";
|
||||
|
||||
declare module "zod/v4/core" {
|
||||
interface $ZodType {
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
import { expect, expectTypeOf, test } from "vitest";
|
||||
import { z } from "zod/mini";
|
||||
import { z } from "zod/v4-mini";
|
||||
|
||||
test("recursion with z.lazy", () => {
|
||||
const data = {
|
||||
|
||||
+1
-49
@@ -1,5 +1,5 @@
|
||||
import { expect, expectTypeOf, test } from "vitest";
|
||||
import * as z from "zod/mini";
|
||||
import * as z from "zod/v4-mini";
|
||||
|
||||
const FAIL = { success: false };
|
||||
|
||||
@@ -241,38 +241,6 @@ test("z.ipv6", () => {
|
||||
expect(() => z.parse(a, 123)).toThrow();
|
||||
});
|
||||
|
||||
test("z.mac", () => {
|
||||
const a = z.mac();
|
||||
// valid mac
|
||||
expect(z.parse(a, "00:1A:2B:3C:4D:5E")).toEqual("00:1A:2B:3C:4D:5E");
|
||||
// invalid mac (dash delimiter not accepted by default)
|
||||
expect(() => z.parse(a, "01-23-45-67-89-AB")).toThrow();
|
||||
expect(() => z.parse(a, "00:1A:2B::4D:5E")).toThrow();
|
||||
expect(() => z.parse(a, "00:1a-2B:3c-4D:5e")).toThrow();
|
||||
expect(() => z.parse(a, "hello")).toThrow();
|
||||
// wrong type
|
||||
expect(() => z.parse(a, 123)).toThrow();
|
||||
});
|
||||
|
||||
test("z.mac with custom delimiter", () => {
|
||||
const a = z.mac({ delimiter: ":" });
|
||||
// valid mac with colon
|
||||
expect(z.parse(a, "00:1A:2B:3C:4D:5E")).toEqual("00:1A:2B:3C:4D:5E");
|
||||
// invalid mac with dash
|
||||
expect(() => z.parse(a, "00-1A-2B-3C-4D-5E")).toThrow();
|
||||
|
||||
const b = z.mac({ delimiter: "-" });
|
||||
// valid mac with dash
|
||||
expect(z.parse(b, "00-1A-2B-3C-4D-5E")).toEqual("00-1A-2B-3C-4D-5E");
|
||||
// invalid mac with colon
|
||||
expect(() => z.parse(b, "00:1A:2B:3C:4D:5E")).toThrow();
|
||||
|
||||
const c = z.mac({ delimiter: ":" });
|
||||
// colon-only mac
|
||||
expect(z.parse(c, "00:1A:2B:3C:4D:5E")).toEqual("00:1A:2B:3C:4D:5E");
|
||||
expect(() => z.parse(c, "00-1A-2B-3C-4D-5E")).toThrow();
|
||||
});
|
||||
|
||||
test("z.base64", () => {
|
||||
const a = z.base64();
|
||||
// valid base64
|
||||
@@ -329,19 +297,3 @@ test("z.jwt", () => {
|
||||
// wrong type
|
||||
expect(() => z.parse(a, 123)).toThrow();
|
||||
});
|
||||
|
||||
test("z.hash generic format", () => {
|
||||
expect(z.hash("sha256").parse("a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3")).toBe(
|
||||
"a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3"
|
||||
);
|
||||
|
||||
// --- Type-level checks (ensure the literal format string is encoded in the return type)
|
||||
expectTypeOf(z.hash("md5")).toEqualTypeOf<z.ZodMiniCustomStringFormat<"md5_hex">>();
|
||||
expectTypeOf(z.hash("sha1")).toEqualTypeOf<z.ZodMiniCustomStringFormat<"sha1_hex">>();
|
||||
expectTypeOf(z.hash("sha256", { enc: "base64" as const })).toEqualTypeOf<
|
||||
z.ZodMiniCustomStringFormat<"sha256_base64">
|
||||
>();
|
||||
expectTypeOf(z.hash("sha384", { enc: "base64url" as const })).toEqualTypeOf<
|
||||
z.ZodMiniCustomStringFormat<"sha384_base64url">
|
||||
>();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user