import { CoDiscriminatedUnionSchema, CoValueClass, CoreCoFeedSchema, CoreCoListSchema, CoreCoMapSchema, CoreCoRecordSchema, CoreCoVectorSchema, CorePlainTextSchema, Simplify, CoreSnapshotRefSchema, SnapshotRef, InstanceOfSchemaCoValuesMaybeLoaded, } from "../../../internal.js"; import { CoreCoOptionalSchema } from "../schemaTypes/CoOptionalSchema.js"; import { CoreCoValueSchema } from "../schemaTypes/CoValueSchema.js"; import { CoreRichTextSchema } from "../schemaTypes/RichTextSchema.js"; import { z } from "../zodReExport.js"; import { AnyZodOrCoValueSchema, Loaded } from "../zodSchema.js"; import { TypeOfZodSchema } from "./TypeOfZodSchema.js"; /** * The type of value that can be used to initialize a CoField of the given schema. * * For CoValue fields, this can be either a shallowly-loaded CoValue instance * or a JSON object that will be used to create the CoValue. */ export type CoFieldSchemaInit = S extends CoreCoValueSchema ? S extends CoreSnapshotRefSchema ? SnapshotRef> : | Loaded | (S extends CoreCoRecordSchema ? CoMapSchemaInit<{ [key in z.output & string]: V }> : S extends CoreCoMapSchema ? CoMapSchemaInit : S extends CoreCoListSchema ? CoListSchemaInit : S extends CoreCoFeedSchema ? CoFeedSchemaInit : S extends CoreCoVectorSchema ? CoVectorSchemaInit : S extends CorePlainTextSchema | CoreRichTextSchema ? string : S extends CoreCoOptionalSchema ? CoFieldSchemaInit | undefined : S extends CoDiscriminatedUnionSchema ? CoFieldSchemaInit : never) : S extends z.core.$ZodType ? TypeOfZodSchema : S extends CoValueClass ? InstanceType : never; // Due to a TS limitation with types that contain known properties and // an index signature, we cannot accept catchall properties on creation export type CoMapSchemaInit = Simplify< { /** * Cannot use {@link PartialOnUndefined} because evaluating CoFieldInit * to know if the value can be undefined does not work with recursive types. */ [Key in keyof Shape as Shape[Key] extends | CoreCoOptionalSchema | z.core.$ZodOptional ? never : Key]: CoFieldSchemaInit; } & { [Key in keyof Shape as Shape[Key] extends | CoreCoOptionalSchema | z.core.$ZodOptional ? Key : never]?: CoFieldSchemaInit; } >; export type CoListSchemaInit = Simplify< ReadonlyArray> >; export type CoFeedSchemaInit = Simplify< ReadonlyArray> >; export type CoVectorSchemaInit = ReadonlyArray | Float32Array; /** * The convenience type for extracting the init type of a CoValue schema. */ export type CoInput = S extends CoreCoValueSchema ? Exclude, Loaded> : CoFieldSchemaInit;