// Type definitions for data-context v2.0 // Project: https://www.npmjs.com/package/data-context // Definitions by: Manuel Lõhmus and contributors /* eslint-disable @typescript-eslint/ban-types */ declare namespace DC { type Primitive = string | number | boolean | null | undefined; interface ChangeEvent { eventName: 'new' | 'set' | 'reposition' | 'delete' | '-change' | string; target: DataContext; propertyPath: string[]; oldValue: any; newValue: any; } interface StringifyOptions { modifiedData?: boolean; setUnmodified?: boolean; includeBOM?: boolean; } type JSONReplacer = (this: any, key: string, value: any) => any; interface WatchJsonFileOptions { filePath?: string; data?: any; removeUnusedKeys?: boolean; allowFileReadWrite?: boolean; onDataChange?: (event: { strChanges: string | undefined; strJson: string | undefined; datacontext: DataContext; }) => void; onFileChange?: (event: { strChanges: string | undefined; strJson: string | undefined; datacontext: DataContext; }) => void; } interface DataContextBase { readonly _isDataContext: true; _isModified: boolean; readonly _modified: string[]; _propertyName: string | null; _parent: DataContext | null; toString(createModifiedData?: boolean): string; overwritingData(text: string | number | null | undefined, reviver?: any): void; stringifyChanges( replacer?: JSONReplacer | string[] | null, space?: number | string, modifiedData?: boolean, setUnmodified?: boolean ): string | undefined; readonly isChanged: boolean; resetChanges(): void; once(eventName: string, listener: (event: ChangeEvent) => boolean | void): this; on( eventName: string, listener: (event: ChangeEvent) => boolean | void, isActive?: boolean | (() => boolean) | { isConnected?: boolean } | any ): this; emitToParent(eventName: string, ...params: any[]): boolean; emit(eventName: string, ...params: any[]): boolean; } type DataContextArray = DataContextBase & Array>; type DataContextObject = DataContextBase & { [K in keyof T]: DataContext; }; type DataContext = T extends Function ? T : T extends Array ? DataContextArray : T extends object ? DataContextObject : T; interface CreateDataContext { (value: T, propertyName?: string | null, parent?: any): DataContext; /** Create a new proxy object with the same structure as the original object. */ createDataContext: CreateDataContext; /** Merge/sync source into target (recursively). */ syncData(target: T, source: any, removeUnusedKeys?: boolean): T; /** Parse text into value (optionally reviving into DataContext). */ parse(text: string | number | null | undefined): T | undefined; parse(text: string | number | null | undefined, reviver: JSONReplacer): any; parse(text: string | number | null | undefined, reviver: CreateDataContext): DataContext; parse(text: string | number | null | undefined, reviver: DataContext): DataContext; /** Stringify value with support for metadata and modified-data modes. */ stringify( value: any, replacer?: JSONReplacer | string[] | null, space?: number | string, options?: StringifyOptions ): string | undefined; /** * Node.js only: watch and persist a JSON file to a DataContext. * Returns an implementation-specific watcher/handle (or undefined in non-Node environments). */ watchJsonFile(options?: WatchJsonFileOptions): unknown; /** When true, reading/writing files via watchJsonFile is enabled. */ enableFileReadWrite: boolean; /** When true, metadata comments are ignored during parse/stringify. */ ignoreMetadata: boolean; } } declare const createDataContext: DC.CreateDataContext; export = createDataContext;