diff --git a/errors.d.ts b/errors.d.ts new file mode 100644 index 000000000..acd6ea271 --- /dev/null +++ b/errors.d.ts @@ -0,0 +1,12 @@ +export interface ErrorWithCode extends Error { + code: number; + description?: string; +} + +type Errors = { + [key: number]: ErrorWithCode; +}; + +declare const errors: Errors; + +export default errors; diff --git a/regedit.d.ts b/regedit.d.ts index 98c7a2b97..51a1057e3 100644 --- a/regedit.d.ts +++ b/regedit.d.ts @@ -1,3 +1,6 @@ +import type { Readable } from 'stream'; +import type { ErrorWithCode } from './errors'; + export interface REG_SZ_Value { value: string; type: "REG_SZ"; @@ -25,7 +28,7 @@ export interface REG_MULTI_SZ_Value { export interface REG_BINARY_Value { value: number[]; - type: "REG_SZ"; + type: "REG_BINARY"; } export interface REG_DEFAULT_Value { @@ -40,36 +43,119 @@ export interface RegistryItem { keys: string[]; values: { [name: string]: RegistryItemValue; + ['']: REG_DEFAULT_Value; }; } +export type RegistryStreamItem = { + key: T[number]; + data: RegistryItem; +} + +export type RegistryUnexpandedItem = { + key: T[number]; + exists: boolean; + value: string; +} + export type RegistryItemCollection = U; export interface RegistryPutItem { [name: string]: RegistryItemValue; + ['']?: REG_DEFAULT_Value; } export type RegistryItemPutCollection = { [key: string]: RegistryPutItem; }; -export const OS_ARCH_AGNOSTIC = "A"; -export const OS_ARCH_SPECIFIC = "S"; -export const OS_ARCH_32BIT = "32"; -export const OS_ARCH_64BIT = "64"; - -type Architecture = (typeof OS_ARCH_AGNOSTIC | typeof OS_ARCH_SPECIFIC | typeof OS_ARCH_32BIT | typeof OS_ARCH_64BIT); +type Architecture = "A" | "S" | "32" | "64"; type ErrResCallback = (err: Error | undefined, res: RegistryItemCollection) => void; +type ErrResUnexpandedCallback = (err: Error | undefined, res: RegistryUnexpandedItem[]) => void; + +export interface ReadStream extends Readable { + read(size?: number): T; + unpipe(destination?: T): this; + unshift(chunk: T): void; + push(chunk: T | null, encoding?: string): boolean; + + addListener(event: 'close', listener: () => void): this; + addListener(event: 'data', listener: (chunk: T) => void): this; + addListener(event: 'end', listener: () => void): this; + addListener(event: 'readable', listener: () => void): this; + addListener(event: 'error', listener: (err: Error) => void): this; + addListener(event: string | symbol, listener: (...args: any[]) => void): this; + + emit(event: 'close'): boolean; + emit(event: 'data', chunk: T): boolean; + emit(event: 'end'): boolean; + emit(event: 'readable'): boolean; + emit(event: 'error', err: Error): boolean; + emit(event: string | symbol, ...args: any[]): boolean; + + on(event: 'close', listener: () => void): this; + on(event: 'data', listener: (chunk: T) => void): this; + on(event: 'end', listener: () => void): this; + on(event: 'readable', listener: () => void): this; + on(event: 'error', listener: (err: Error) => void): this; + on(event: string | symbol, listener: (...args: any[]) => void): this; + + once(event: 'close', listener: () => void): this; + once(event: 'data', listener: (chunk: T) => void): this; + once(event: 'end', listener: () => void): this; + once(event: 'readable', listener: () => void): this; + once(event: 'error', listener: (err: Error) => void): this; + once(event: string | symbol, listener: (...args: any[]) => void): this; + + prependListener(event: 'close', listener: () => void): this; + prependListener(event: 'data', listener: (chunk: T) => void): this; + prependListener(event: 'end', listener: () => void): this; + prependListener(event: 'readable', listener: () => void): this; + prependListener(event: 'error', listener: (err: Error) => void): this; + prependListener(event: string | symbol, listener: (...args: any[]) => void): this; + + prependOnceListener(event: 'close', listener: () => void): this; + prependOnceListener(event: 'data', listener: (chunk: T) => void): this; + prependOnceListener(event: 'end', listener: () => void): this; + prependOnceListener(event: 'readable', listener: () => void): this; + prependOnceListener(event: 'error', listener: (err: Error) => void): this; + prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this; + + removeListener(event: 'close', listener: () => void): this; + removeListener(event: 'data', listener: (chunk: T) => void): this; + removeListener(event: 'end', listener: () => void): this; + removeListener(event: 'readable', listener: () => void): this; + removeListener(event: 'error', listener: (err: Error) => void): this; + removeListener(event: string | symbol, listener: (...args: any[]) => void): this; + + [Symbol.asyncIterator](): AsyncIterableIterator; +} +export function list(keys: readonly K[]): ReadStream>; +export function list(keys: readonly K[], architecture: Architecture): ReadStream>; +/** + * @deprecated https://github.com/ironSource/node-regedit#note-about-listing-default-values list with callback api will be deperecated and eventually removed in future versions, take a look at the streaming interface below + */ export function list(keys: readonly K[], callback: ErrResCallback): void; -export function list(keys: readonly K[], architecture: Architecture, callback?: ErrResCallback): void; - -export function setExternalVBSLocation(newLocation: string): string; - -interface ErrorWithCode extends Error { - code: number; - description: string; - } +/** + * @deprecated https://github.com/ironSource/node-regedit#note-about-listing-default-values list with callback api will be deperecated and eventually removed in future versions, take a look at the streaming interface below + */ +export function list(keys: readonly K[], architecture: Architecture, callback: ErrResCallback): void; + +export function listUnexpandedValues(keys: readonly K[]): ReadStream>; +export function listUnexpandedValues(keys: readonly K[], architecture: Architecture): ReadStream>; +/** + * @deprecated https://github.com/ironSource/node-regedit#note-about-listing-default-values list with callback api will be deperecated and eventually removed in future versions, take a look at the streaming interface below + */ +export function listUnexpandedValues(keys: readonly K[], callback: ErrResUnexpandedCallback): void; +/** + * @deprecated https://github.com/ironSource/node-regedit#note-about-listing-default-values list with callback api will be deperecated and eventually removed in future versions, take a look at the streaming interface below + */ +export function listUnexpandedValues(keys: readonly K[], architecture: Architecture, callback: ErrResUnexpandedCallback): void; + +export type FOLDER_FOUND = 'Folder found and set'; +export type FOLDER_NOT_FOUND = 'Folder not found'; +export function setExternalVBSLocation(newLocation: string): FOLDER_FOUND | FOLDER_NOT_FOUND; type ErrCallback = (err: ErrorWithCode | undefined) => void; @@ -79,6 +165,9 @@ export function createKey(keys: readonly K[], architecture: Ar export function deleteKey(keys: readonly string[], callback: ErrCallback): void; export function deleteKey(keys: readonly string[], architecture: Architecture, callback?: ErrCallback): void; +export function deleteValue(keys: readonly string[], callback: ErrCallback): void; +export function deleteValue(keys: readonly string[], architecture: Architecture, callback?: ErrCallback): void; + export function putValue(map: RegistryItemPutCollection, callback: ErrCallback): void; export function putValue(map: RegistryItemPutCollection, architecture: Architecture, callback?: ErrCallback): void; @@ -86,12 +175,18 @@ export namespace arch { export function list(keys: readonly K[], callback: ErrResCallback): void; export function list32(keys: readonly K[], callback: ErrResCallback): void; export function list64(keys: readonly K[], callback: ErrResCallback): void; + export function listUnexpandedValues(keys: readonly K[], callback: ErrResUnexpandedCallback): void; + export function listUnexpandedValues32(keys: readonly K[], callback: ErrResUnexpandedCallback): void; + export function listUnexpandedValues64(keys: readonly K[], callback: ErrResUnexpandedCallback): void; export function createKey(keys: readonly string[], callback: ErrCallback): void; export function createKey32(keys: readonly string[], callback: ErrCallback): void; export function createKey64(keys: readonly string[], callback: ErrCallback): void; export function deleteKey(keys: readonly string[], callback: ErrCallback): void; export function deleteKey32(keys: readonly string[], callback: ErrCallback): void; export function deleteKey64(keys: readonly string[], callback: ErrCallback): void; + export function deleteValue(keys: readonly string[], callback: ErrCallback): void; + export function deleteValue32(keys: readonly string[], callback: ErrCallback): void; + export function deleteValue64(keys: readonly string[], callback: ErrCallback): void; export function putValue(map: RegistryItemPutCollection, callback: ErrCallback): void; export function putValue32(map: RegistryItemPutCollection, callback: ErrCallback): void; export function putValue64(map: RegistryItemPutCollection, callback: ErrCallback): void; @@ -100,10 +195,14 @@ export namespace arch { export namespace promisified { export function list(keys: readonly K[]): Promise>; export function list(keys: readonly K[], architecture: Architecture): Promise>; + export function listUnexpandedValues(keys: readonly K[]): Promise[]>; + export function listUnexpandedValues(keys: readonly K[], architecture: Architecture): Promise[]>; export function createKey(keys: readonly string[]): Promise; export function createKey(keys: readonly string[], architecture: Architecture): Promise; export function deleteKey(keys: readonly string[]): Promise; export function deleteKey(keys: readonly string[], architecture: Architecture): Promise; + export function deleteValue(keys: readonly string[]): Promise; + export function deleteValue(keys: readonly string[], architecture: Architecture): Promise; export function putValue(map: RegistryItemPutCollection): Promise; export function putValue(map: RegistryItemPutCollection, architecture: Architecture): Promise; @@ -111,12 +210,18 @@ export namespace promisified { export function list(keys: readonly K[]): Promise>; export function list32(keys: readonly K[]): Promise>; export function list64(keys: readonly K[]): Promise>; + export function listUnexpandedValues(keys: readonly K[]): Promise[]>; + export function listUnexpandedValues32(keys: readonly K[]): Promise[]>; + export function listUnexpandedValues64(keys: readonly K[]): Promise[]>; export function createKey(keys: readonly string[]): Promise; export function createKey32(keys: readonly string[]): Promise; export function createKey64(keys: readonly string[]): Promise; export function deleteKey(keys: readonly string[]): Promise; export function deleteKey32(keys: readonly string[]): Promise; export function deleteKey64(keys: readonly string[]): Promise; + export function deleteValue(keys: readonly string[]): Promise; + export function deleteValue32(keys: readonly string[]): Promise; + export function deleteValue64(keys: readonly string[]): Promise; export function putValue(map: RegistryItemPutCollection): Promise; export function putValue32(map: RegistryItemPutCollection): Promise; export function putValue64(map: RegistryItemPutCollection): Promise;