import type { AnyDataModel } from "../dataModel/BaseDataModel" import type { AnyModel } from "../model/BaseModel" import type { modelTypeKey } from "../model/metadata" import type { Flatten, IsNeverType } from "../utils/types" import type { ModelProps, ModelPropsToSnapshotCreationData, ModelPropsToSnapshotData, ModelPropsToTransformedCreationData, ModelPropsToTransformedData, ModelPropsToUntransformedCreationData, } from "./prop" /** * @ignore */ export const propsTypeSymbol = Symbol("propsType") /** * @ignore */ export const fromSnapshotOverrideTypeSymbol = Symbol("fromSnapshotOverrideType") /** * @ignore */ export const toSnapshotOverrideTypeSymbol = Symbol("toSnapshotOverrideType") /** * @internal */ export const modelInitializedSymbol = Symbol("modelInitialized") /** * Extracts the instance type of a model class. */ export interface ModelClass { new (initialData: any): M fromSnapshotProcessor?: (sn: any) => any toSnapshotProcessor?: (sn: any, modelInstance: any) => any } /** * Extracts the instance type of an abstract model class. */ export type AbstractModelClass = abstract new ( initialData: any ) => M /** * @internal */ export interface ModelWithProps { [propsTypeSymbol]: ModelProps } /** * The props of a model. */ export type ModelPropsOf = M[typeof propsTypeSymbol] /** * The data type of a model, without transformations applied. */ export type ModelUntransformedData = Flatten /** * The creation data type of a model, without transformations applied. */ export type ModelUntransformedCreationData = ModelPropsToUntransformedCreationData> /** * The data type of a model, with transformations applied. */ export type ModelData = ModelPropsToTransformedData> /** * The creation data type of a model, with transformations applied. */ export type ModelCreationData = ModelPropsToTransformedCreationData< ModelPropsOf > /** * The from snapshot type of a model. * * @deprecated Use SnapshotInOf instead. */ export type ModelFromSnapshot< M extends ModelWithProps & { [fromSnapshotOverrideTypeSymbol]: any }, > = IsNeverType< M[typeof fromSnapshotOverrideTypeSymbol], ModelPropsToSnapshotCreationData>, M[typeof fromSnapshotOverrideTypeSymbol] > & { [modelTypeKey]?: string } /** * The to snapshot type of a model. * * @deprecated Use SnapshotOutOf instead. */ export type ModelToSnapshot = IsNeverType< M[typeof toSnapshotOverrideTypeSymbol], ModelPropsToSnapshotData>, M[typeof toSnapshotOverrideTypeSymbol] > & { [modelTypeKey]?: string } /** * Tricks TypeScript into accepting a particular kind of generic class as a parameter for `ExtendedModel`. * Does nothing in runtime. * * @template T Generic model class type. * @param type Generic model class. * @returns */ export function modelClass(type: { prototype: T }): ModelClass { return type as any }