import { CamelCase } from "type-fest"; import { ZodRawShape } from "zod/lib/types"; import { ZodDiscriminatedUnion, ZodLiteral, ZodObject } from "zod"; import { EntityCore, EntityCoreShape, EntityCoreShapeType, Extender, UnsafeZentity, Zentity, ZodShapeType } from "./zentity"; import { Clean, ValueUnion } from "./utils"; type ExtractType = T extends { [K in D]: infer V; } ? { [K in keyof T]: K extends D ? V : T[K]; } : never; export type VariantsShape = Record; export type KeyedExtender, R extends object> = { [K in keyof KS]?: Extender; }; type Flatten, D extends string> = ValueUnion<{ [K in keyof O]: ZodShapeType & { [Q in D]: K; }; }>; type CamelCaseOf

= CamelCase<`${P}-${K}`>; type VariantShape, VARIANT_KEY extends keyof VARIANTS_SHAPE> = VARIANTS_SHAPE[VARIANT_KEY] & Clean; type VariantType, VARIANT_KEY extends keyof VARIANTS_SHAPE> = ZodShapeType>; type ReturnType = E extends (arg: any) => infer R ? R : {}; type ToZodD, D extends string> = ZodObject; }; }> & BS & EntityCoreShapeType>; type PolymorphicNewFn, D extends string, KSE extends KeyedExtender> = { [key in (keyof KS & string) as CamelCaseOf<`new`, key>]: (params: VariantType & { id: string; }) => PolymorphicEntityType; }; type PolymorphicCreateFn, D extends string, KSE extends KeyedExtender> = { [key in (keyof KS & string) as CamelCaseOf<`create`, key>]: (params: VariantType & EntityCore) => PolymorphicEntityType; }; type PolymorphicUnsafeFn, D extends string, KSE extends KeyedExtender> = { [key in (keyof KS & string) as CamelCaseOf<`unsafe`, key>]: (params: VariantType & EntityCore) => UnsafePolymorphicEntityType; }; type PolymorphicGuardFn, D extends string, KSE extends KeyedExtender> = { [key in (keyof KS & string) as CamelCaseOf<'is', key>]: (data: any) => data is PolymorphicEntityType; }; type PolymorphicShape, D extends string> = { [key in (keyof KS & string) as CamelCaseOf]: VariantShape & { [K in D]: ZodLiteral; } & typeof EntityCoreShape; }; type PolymorphicSchema, D extends string> = { [key in (keyof KS & string) as CamelCaseOf]: ZodObject & { [K in D]: ZodLiteral; } & typeof EntityCoreShape>; }; type PolymorphicEntityType, D extends string, KE extends KeyedExtender, key extends keyof KS> = Zentity<{ [Q in D]: key; } & VariantType, ReturnType>; type UnsafePolymorphicEntityType, D extends string, KE extends KeyedExtender, key extends keyof KS> = UnsafeZentity<{ [Q in D]: key; } & VariantType, ReturnType>; export type PolymorphicEntityClass, D extends string, KE extends KeyedExtender> = { name: string; create: >(params: T & EntityCore & ZodShapeType) => Zentity & ExtractType, ReturnType>; new: >(params: T & ZodShapeType & { id: string; }) => Zentity, ReturnType>; unsafe: >(params: T & ZodShapeType) => UnsafeZentity, ReturnType>; baseShape: BS & typeof EntityCoreShape; schema: ZodDiscriminatedUnion, ...ToZodD[]]>; variants: (keyof KS)[]; } & PolymorphicNewFn & PolymorphicCreateFn & PolymorphicUnsafeFn & PolymorphicGuardFn & PolymorphicSchema & PolymorphicShape; export declare function polymorphicEntity, D extends string, KSE extends KeyedExtender>(options: { name: string; discriminator: D; base: BS; variants: KS; extend: KSE; }): PolymorphicEntityClass; type UnionOfStateShapeTypesWithDiscriminator, D extends string> = ValueUnion<{ [key in keyof KS]: ZodShapeType & { [Q in D]: key; }; }>; export type inferPolymorphicEntityTypeFromClass = T extends PolymorphicEntityClass ? Zentity & ZodShapeType>, ReturnType> : never; export type inferSpecificPolymorphicEntityTypeFromClass = T extends PolymorphicEntityClass ? K extends keyof KS ? Zentity & ZodShapeType, ReturnType> : never : never; export {}; //# sourceMappingURL=polymorphic-entity.d.ts.map