import { GraphQLSchema } from 'graphql'; import { GraphQLHandler, HttpHandler } from 'msw'; import { Database } from './db/Database'; import { NullableObject, NullableProperty } from './nullable'; import { PrimaryKey } from './primaryKey'; import { BulkQueryOptions, QueryOptions, QuerySelector, WeakQuerySelector } from './query/queryTypes'; import { OneOf, ManyOf } from './relations/Relation'; export declare const PRIMARY_KEY: unique symbol; export declare const ENTITY_TYPE: unique symbol; export declare const DATABASE_INSTANCE: unique symbol; export declare type KeyType = string | number | symbol; export declare type AnyObject = Record; export declare type PrimaryKeyType = string | number; export declare type PrimitiveValueType = string | number | boolean | Date; export declare type ModelValueType = PrimitiveValueType | PrimitiveValueType[]; export declare type ModelValueTypeGetter = () => ModelValueType; export declare type ModelDefinition = Record; export declare type ModelDefinitionValue = PrimaryKey | ModelValueTypeGetter | NullableProperty | NullableObject | OneOf | ManyOf | NestedModelDefinition; export declare type NestedModelDefinition = { [propertyName: string]: ModelValueTypeGetter | NullableProperty | NullableObject | OneOf | ManyOf | NestedModelDefinition; }; export declare type FactoryAPI> = { [ModelName in keyof Dictionary]: ModelAPI; } & { [DATABASE_INSTANCE]: Database; }; export declare type ModelDictionary = Record>; export declare type Limit = { [Key in keyof Definition]: Definition[Key] extends ModelDefinitionValue ? Definition[Key] : { error: 'expected primary key, initial value, or relation'; }; }; export interface InternalEntityProperties { readonly [ENTITY_TYPE]: ModelName; readonly [PRIMARY_KEY]: PrimaryKeyType; } export declare type Entity = PublicEntity & InternalEntityProperties; export declare type PublicEntity = Value; export declare type RequiredExactlyOne = { [Key in KeysType]: Required> & Partial, never>>; }[KeysType] & Pick>; export declare type DeepRequiredExactlyOne = RequiredExactlyOne<{ [Key in keyof Target]: Target[Key] extends AnyObject ? DeepRequiredExactlyOne : Target[Key]; }>; export declare type InitialValues = Partial>; export declare type StrictQueryReturnType = Options['strict'] extends true ? ValueType : ValueType | null; export interface ModelAPI { /** * Create a single entity for the model. */ create(initialValues?: InitialValues): Entity; /** * Return the total number of entities. */ count(query?: QueryOptions & QuerySelector>): number; /** * Find a first entity matching the query. */ findFirst(query: Options & QuerySelector>): StrictQueryReturnType>; /** * Find multiple entities. */ findMany(query: QueryOptions & WeakQuerySelector> & BulkQueryOptions>): Entity[]; /** * Return all entities of the current model. */ getAll(): Entity[]; /** * Update a single entity with the next data. */ update(query: Options & QuerySelector> & { data: Partial>; }): StrictQueryReturnType>; /** * Update many entities with the next data. */ updateMany(query: Options & QuerySelector> & { data: Partial>; }): StrictQueryReturnType[]>; /** * Delete a single entity. */ delete(query: Options & QuerySelector>): StrictQueryReturnType>; /** * Delete multiple entities. */ deleteMany(query: Options & QuerySelector>): StrictQueryReturnType[]>; /** * Generate request handlers of the given type based on the model definition. */ toHandlers(type: 'rest', baseUrl?: string): HttpHandler[]; /** * Generate request handlers of the given type based on the model definition. */ toHandlers(type: 'graphql', baseUrl?: string): GraphQLHandler[]; /** * Generate a graphql schema based on the model definition. */ toGraphQLSchema(): GraphQLSchema; } export declare type UpdateManyValue = Value | { [Key in keyof Target]?: Target[Key] extends PrimaryKey ? (prevValue: ReturnType, entity: Value) => ReturnType : Target[Key] extends ModelValueTypeGetter ? (prevValue: ReturnType, entity: Value) => ReturnType : Target[Key] extends OneOf ? (prevValue: PublicEntity, entity: Value) => PublicEntity : Target[Key] extends ManyOf ? (prevValue: PublicEntity[], entity: Value) => PublicEntity[] : Target[Key] extends AnyObject ? Partial> : (prevValue: ReturnType, entity: Value) => ReturnType; }; export declare type Value = { [Key in keyof Target]: Target[Key] extends PrimaryKey ? ReturnType : Target[Key] extends NullableProperty ? ReturnType : Target[Key] extends NullableObject ? Partial> | null : Target[Key] extends OneOf ? Nullable extends true ? PublicEntity | null : PublicEntity | undefined : Target[Key] extends ManyOf ? Nullable extends true ? PublicEntity[] | null : PublicEntity[] : Target[Key] extends ModelValueTypeGetter ? ReturnType : Target[Key] extends AnyObject ? Partial> : ReturnType; };