import { fromSnapshotOverrideTypeSymbol, ModelClass, propsTypeSymbol, toSnapshotOverrideTypeSymbol } from '../modelShared/BaseModelShared'; import { ModelProps, ModelPropsToTransformedCreationData, ModelPropsToUntransformedData } from '../modelShared/prop'; import { SnapshotInOfModel, SnapshotOutOfModel } from '../snapshot/SnapshotOf'; import { TypeCheckError } from '../types/TypeCheckError'; import { modelIdKey, modelTypeKey } from './metadata'; /** * @ignore */ export declare const modelIdPropertyNameSymbol: unique symbol; /** * @ignore */ export type ModelIdPropertyType = [ ModelIdPropertyName ] extends [never] ? never : ModelPropsToUntransformedData>[ModelIdPropertyName]; /** * Base abstract class for models. Use `Model` instead when extending. * * Never override the constructor, use `onInit` or `onAttachedToRootStore` instead. * * @template Data Data type. * @template CreationData Creation data type. * @template ModelIdPropertyName Model id property name. */ export declare abstract class BaseModel, ToSnapshotOverride extends Record, ModelIdPropertyName extends string = never> { [propsTypeSymbol]: TProps; [fromSnapshotOverrideTypeSymbol]: FromSnapshotOverride; [toSnapshotOverrideTypeSymbol]: ToSnapshotOverride; [modelIdPropertyNameSymbol]: ModelIdPropertyName; /** * Model type name. */ readonly [modelTypeKey]: string; /** * Model internal id. Can be modified inside a model action. * It will return `undefined` if there's no id prop set. */ get [modelIdKey](): ModelIdPropertyType; set [modelIdKey](newId: ModelIdPropertyType); /** * Can be overridden to offer a reference id to be used in reference resolution. * By default it will use the `idProp` if available or return `undefined` otherwise. */ getRefId(): string | undefined; /** * Called after the model has been created. */ protected onInit?(): void; /** * Data part of the model, which is observable and will be serialized in snapshots. * Use it if one of the data properties matches one of the model properties/functions. */ readonly $: ModelPropsToUntransformedData; /** * Optional hook that will run once this model instance is attached to the tree of a model marked as * root store via `registerRootStore`. * Basically this is the place where you know the full root store is complete and where things such as * middlewares, effects (reactions, etc), and other side effects should be registered, since it means * that the model is now part of the active application state. * * It can return a disposer that will be run once this model instance is detached from such root store tree. * * @param rootStore * @returns */ protected onAttachedToRootStore?(rootStore: object): (() => void) | void; /** * Performs a type check over the model instance. * For this to work a data type has to be declared as part of the model properties. * * @returns A `TypeCheckError` or `null` if there is no error. */ typeCheck(): TypeCheckError | null; /** * Creates an instance of a model. */ constructor(data: ModelPropsToTransformedCreationData); toString(options?: { withData?: boolean; }): string; } /** * @ignore */ export type BaseModelKeys = keyof AnyModel | "onInit" | "onAttachedToRootStore"; /** * Any kind of model instance. */ export interface AnyModel extends BaseModel { } /** * @deprecated Should not be needed anymore. * * Tricks TypeScript into accepting abstract classes as a parameter for `ExtendedModel`. * Does nothing in runtime. * * @template T Abstract model class type. * @param type Abstract model class. * @returns */ export declare function abstractModelClass(type: T): T & Object; /** * The model id property name. */ export type ModelIdPropertyName = M[typeof modelIdPropertyNameSymbol]; /** * Add missing model metadata to a model creation snapshot to generate a proper model snapshot. * Usually used alongside `fromSnapshot`. * * @template M Model type. * @param modelClass Model class. * @param snapshot Model creation snapshot without metadata. * @returns The model snapshot (including metadata). */ export declare function modelSnapshotInWithMetadata(modelClass: ModelClass, snapshot: Omit, typeof modelTypeKey>): SnapshotInOfModel; /** * Add missing model metadata to a model output snapshot to generate a proper model snapshot. * Usually used alongside `applySnapshot`. * * @template M Model type. * @param modelClass Model class. * @param snapshot Model output snapshot without metadata. * @returns The model snapshot (including metadata). */ export declare function modelSnapshotOutWithMetadata(modelClass: ModelClass, snapshot: Omit, typeof modelTypeKey>): SnapshotOutOfModel; /** * A model class declaration, made of a base model and the model interface. */ export type ModelClassDeclaration = BaseModelClass & { new (...args: any[]): ModelInterface; };