import type { __modelMeta__ } from '../runtime/client'; import type { BaseSchema, ConversationType, CustomOperation, CustomType, EnumType, GenericModelSchema, ModelSchemaContents, ModelType, } from '../ModelSchema'; import type { ClientCustomOperation, ClientCustomType, ClientEnum, ClientModel, } from './Core'; import type { CombinedModelSchema, CombinedSchemaIndexesUnion, } from '../CombineSchema'; import type { SchemaMetadata } from './utilities/SchemaMetadata'; import type { Brand, Select, SpreadTuple } from '../util'; import { ClientConversation } from './ai/ClientConversation'; export type ClientSchema< Schema extends GenericModelSchema | CombinedModelSchema, > = Schema extends GenericModelSchema ? InternalClientSchema : Schema extends CombinedModelSchema ? InternalCombinedSchema : never; type InternalClientSchema< CustomerSchema extends ModelSchemaContents | BaseSchema, Metadata extends SchemaMetadata = never, IsRDS extends boolean = never, > = CustomerSchema extends ModelSchemaContents ? { [K in keyof CustomerSchema as K extends string ? K : never]: K extends string ? ClientSchemaProperty : never; } : CustomerSchema extends BaseSchema ? InternalClientSchema< CustomerSchema['data']['types'], SchemaMetadata, CustomerSchema extends Brand<'RDSSchema'> ? true : false > : never; type ClientSchemaProperty< T extends ModelSchemaContents, Metadata extends SchemaMetadata, IsRDS extends boolean, K extends keyof T & string, > = T[K] extends Brand<'enum'> ? RemapEnum : T[K] extends Brand<'customType'> ? RemapCustomType : T[K] extends Brand< | 'queryCustomOperation' | 'mutationCustomOperation' | 'subscriptionCustomOperation' | 'generationCustomOperation' > ? RemapCustomOperation : T[K] extends Brand<'modelType'> ? RemapModel : T[K] extends Brand<'conversationCustomOperation'> ? RemapAIRoute : never; type RemapEnum<_T extends ModelSchemaContents, E> = E extends EnumType ? ClientEnum : never; type RemapCustomType< T extends ModelSchemaContents, Metadata extends SchemaMetadata, IsRDS extends boolean, E, > = E extends CustomType ? ClientCustomType, CT> : never; type RemapCustomOperation< T extends ModelSchemaContents, Metadata extends SchemaMetadata, IsRDS extends boolean, E, > = E extends CustomOperation ? ClientCustomOperation, CO> : never; type RemapModel< T extends ModelSchemaContents, Metadata extends SchemaMetadata, IsRDS extends boolean, E, K extends keyof T & string, > = E extends ModelType ? ClientModel< InternalClientSchema, Metadata, IsRDS, MT, K > : never; type RemapAIRoute< _T extends ModelSchemaContents, E, > = E extends ConversationType ? ClientConversation : never; type GetInternalClientSchema = Schema extends GenericModelSchema ? InternalClientSchema : never; type CombinedClientSchemas< Schemas extends CombinedModelSchema['schemas'], > = { [Index in keyof Schemas]: Index extends CombinedSchemaIndexesUnion ? GetInternalClientSchema : never; }; /** * Types for unwrapping and combining generic type args into client-consumable types * for multiple schemas * * @typeParam Combined - A container of multiple schemas * * @internal @typeParam ClientSchemas - The tuple of client schemas to combine */ type InternalCombinedSchema< Combined extends CombinedModelSchema, ClientSchemas extends [...any] = CombinedClientSchemas, > = SpreadTuple<{ [I in keyof ClientSchemas]: I extends CombinedSchemaIndexesUnion ? Omit : never; }>; export type ClientSchemaByEntityTypeBaseShape = { enums: Record>; customTypes: Record>; models: Record>; queries: Record>; mutations: Record>; subscriptions: Record>; conversations: Record; generations: Record>; }; export type ClientSchemaByEntityType = { enums: Select; customTypes: Select; models: Select; queries: Select; mutations: Select; subscriptions: Select; conversations: Select; generations: Select; };