import { dataTypes } from './constant'; export declare const enum DraftType { Object = 0, Array = 1, Map = 2, Set = 3 } export declare const Operation: { readonly Remove: "remove"; readonly Replace: "replace"; readonly Add: "add"; }; export type DataType = keyof typeof dataTypes; export type PatchesOptions = boolean | { /** * The default value is `true`. If it's `true`, the path will be an array, otherwise it is a string. */ pathAsArray?: boolean; /** * The default value is `true`. If it's `true`, the array length will be included in the patches, otherwise no include array length. */ arrayLengthAssignment?: boolean; }; export interface Finalities { draft: ((patches?: Patches, inversePatches?: Patches) => void)[]; revoke: (() => void)[]; handledSet: WeakSet; draftsCache: WeakSet; } export interface ProxyDraft { type: DraftType; operated?: boolean; finalized: boolean; original: T; copy: T | null; proxy: T | null; finalities: Finalities; options: Options & { updatedValues?: WeakMap; }; parent?: ProxyDraft | null; key?: string | number | symbol; setMap?: Map; assignedMap?: Map; callbacks?: ((patches?: Patches, inversePatches?: Patches) => void)[]; } export interface IPatch { op: (typeof Operation)[keyof typeof Operation]; value?: any; } export type Patch

= P extends { pathAsArray: false; } ? IPatch & { path: string; } : P extends true | object ? IPatch & { path: (string | number)[]; } : IPatch & { path: string | (string | number)[]; }; export type Patches

= Patch

[]; export type Result = O extends true | object ? [F extends true ? Immutable : T, Patches, Patches] : F extends true ? Immutable : T; export type CreateResult | T | Promise> = R extends Promise | Promise ? Promise> : Result; type BaseMark = null | undefined | DataType; type MarkWithCopy = BaseMark | (() => any); export type Mark = (target: any, types: typeof dataTypes) => O extends true | object ? BaseMark : F extends true ? BaseMark : MarkWithCopy; export interface ApplyMutableOptions { /** * If it's `true`, the state will be mutated directly. */ mutable?: boolean; } export interface Options { /** * In strict mode, Forbid accessing non-draftable values and forbid returning a non-draft value. */ strict?: boolean; /** * Enable patch, and return the patches and inversePatches. */ enablePatches?: O; /** * Enable autoFreeze, and return frozen state. */ enableAutoFreeze?: F; /** * Set a mark to determine if the object is mutable or if an instance is an immutable. * And it can also return a shallow copy function(AutoFreeze and Patches should both be disabled). */ mark?: Mark; } export interface ExternalOptions { /** * In strict mode, Forbid accessing non-draftable values and forbid returning a non-draft value. */ strict?: boolean; /** * Enable patch, and return the patches and inversePatches. */ enablePatches?: O; /** * Enable autoFreeze, and return frozen state. */ enableAutoFreeze?: F; /** * Set a mark to determine if the object is mutable or if an instance is an immutable. * And it can also return a shallow copy function(AutoFreeze and Patches should both be disabled). */ mark?: Mark[] | Mark; } type Primitive = string | number | bigint | boolean | null | undefined; type ImmutableMap = ReadonlyMap, Immutable>; type ImmutableSet = ReadonlySet>; type ImmutableObject = { readonly [K in keyof T]: Immutable; }; export type IfAvailable = true | false extends (T extends never ? true : false) ? Fallback : keyof T extends never ? Fallback : T; type WeakReferences = IfAvailable> | IfAvailable>; type AtomicObject = Function | Promise | Date | RegExp; export type Immutable = T extends Primitive | AtomicObject ? T : T extends IfAvailable> ? ImmutableMap : T extends IfAvailable> ? ImmutableSet : T extends WeakReferences ? T : T extends object ? ImmutableObject : T; type DraftedMap = Map>; type DraftedSet = Set>; export type DraftedObject = { -readonly [K in keyof T]: Draft; }; export type Draft = T extends Primitive | AtomicObject ? T : T extends IfAvailable> ? DraftedMap : T extends IfAvailable> ? DraftedSet : T extends WeakReferences ? T : T extends object ? DraftedObject : T; export type ApplyOptions = Pick, Exclude, 'enablePatches'>> | ApplyMutableOptions; export type ApplyResult = ApplyOptions> = A extends { mutable: true; } ? void : T; export {};