Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update TS types with listUnexpandedValues #101

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 56 additions & 7 deletions regedit.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,30 @@ 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 ErrResCallback<T extends readonly string[]> = (err: Error | undefined, res: RegistryItemCollection<T>) => void;
type ErrResCallback<T> = (err: Error | undefined, res: T) => void;

export function list<K extends string>(keys: readonly K[], callback: ErrResCallback<typeof keys>): void;
export function list<K extends string>(keys: readonly K[], architecture: Architecture, callback?: ErrResCallback<typeof keys>): void;
export function list<K extends string>(keys: readonly K[], callback: ErrResCallback<RegistryItemCollection<typeof keys>>): void;
export function list<K extends string>(keys: readonly K[], architecture: Architecture, callback?: ErrResCallback<RegistryItemCollection<typeof keys>>): void;

interface Stream<T> {
on(event: "data", callback: (entry: T) => void): Stream<T>;
on(event: "finish", callback: () => void): Stream<T>;
}

interface RegistryEntry<T> {
key: T;
data: RegistryItem;
}

export function list<K extends string>(keys: readonly K[]): Stream<RegistryEntry<typeof keys[number]>>;
export function list<K extends string>(keys: readonly K[], architecture: Architecture): Stream<RegistryEntry<typeof keys[number]>>;

export function setExternalVBSLocation(newLocation: string): string;

interface ErrorWithCode extends Error {
code: number;
description: string;
}
}

type ErrCallback = (err: ErrorWithCode | undefined) => void;

Expand All @@ -82,10 +95,27 @@ export function deleteKey(keys: readonly string[], architecture: Architecture, c
export function putValue(map: RegistryItemPutCollection, callback: ErrCallback): void;
export function putValue(map: RegistryItemPutCollection, architecture: Architecture, callback?: ErrCallback): void;

interface UnexpandedValue<T> {
path: T;
exists: boolean;
value: string;
}

export function listUnexpandedValues<K extends string>(key: K, callback: ErrResCallback<UnexpandedValue<typeof key>[]>): void;
export function listUnexpandedValues<K extends string>(key: K): Stream<UnexpandedValue<typeof key>>;
export function listUnexpandedValues<K extends string>(keys: K[], callback: ErrResCallback<UnexpandedValue<typeof keys[number]>[]>): void;
export function listUnexpandedValues<K extends string>(keys: K[]): Stream<UnexpandedValue<typeof keys[number]>>;
export function listUnexpandedValues<K extends string>(key: K, architecture: Architecture, callback: ErrResCallback<UnexpandedValue<typeof key>[]>): void;
export function listUnexpandedValues<K extends string>(key: K, architecture: Architecture): Stream<UnexpandedValue<typeof key>>;
export function listUnexpandedValues<K extends string>(keys: K[], architecture: Architecture, callback: ErrResCallback<UnexpandedValue<typeof keys[number]>[]>): void;
export function listUnexpandedValues<K extends string>(keys: K[], architecture: Architecture): Stream<UnexpandedValue<typeof keys[number]>>;

export namespace arch {
export function list<K extends string>(keys: readonly K[], callback: ErrResCallback<typeof keys>): void;
export function list32<K extends string>(keys: readonly K[], callback: ErrResCallback<typeof keys>): void;
export function list64<K extends string>(keys: readonly K[], callback: ErrResCallback<typeof keys>): void;
export function list<K extends string>(keys: readonly K[], callback: ErrResCallback<RegistryItemCollection<typeof keys>>): void;
export function list32<K extends string>(keys: readonly K[], callback: ErrResCallback<RegistryItemCollection<typeof keys>>): void;
export function list64<K extends string>(keys: readonly K[], callback: ErrResCallback<RegistryItemCollection<typeof keys>>): void;
export function list32<K extends string>(keys: readonly K[]): Stream<RegistryEntry<typeof keys[number]>>;
export function list64<K extends string>(keys: readonly K[]): Stream<RegistryEntry<typeof keys[number]>>;
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;
Expand All @@ -95,6 +125,15 @@ export namespace arch {
export function putValue(map: RegistryItemPutCollection, callback: ErrCallback): void;
export function putValue32(map: RegistryItemPutCollection, callback: ErrCallback): void;
export function putValue64(map: RegistryItemPutCollection, callback: ErrCallback): void;

export function listUnexpandedValues32<K extends string>(key: K, callback: ErrResCallback<UnexpandedValue<typeof key>[]>): void;
export function listUnexpandedValues64<K extends string>(key: K, callback: ErrResCallback<UnexpandedValue<typeof key>[]>): void;
export function listUnexpandedValues32<K extends string>(key: K): Stream<UnexpandedValue<typeof key>>;
export function listUnexpandedValues64<K extends string>(key: K): Stream<UnexpandedValue<typeof key>>;
export function listUnexpandedValues32<K extends string>(keys: K[], callback: ErrResCallback<UnexpandedValue<typeof keys[number]>[]>): void;
export function listUnexpandedValues64<K extends string>(keys: K[], callback: ErrResCallback<UnexpandedValue<typeof keys[number]>[]>): void;
export function listUnexpandedValues32<K extends string>(keys: K[]): Stream<UnexpandedValue<typeof keys[number]>>;
export function listUnexpandedValues64<K extends string>(keys: K[]): Stream<UnexpandedValue<typeof keys[number]>>;
}

export namespace promisified {
Expand All @@ -107,6 +146,11 @@ export namespace promisified {
export function putValue(map: RegistryItemPutCollection): Promise<void>;
export function putValue(map: RegistryItemPutCollection, architecture: Architecture): Promise<void>;

export function listUnexpandedValues<K extends string>(key: K): Promise<UnexpandedValue<typeof key>[]>;
export function listUnexpandedValues<K extends string>(keys: K[]): Promise<UnexpandedValue<typeof keys[number]>[]>;
export function listUnexpandedValues<K extends string>(key: K, architecture: Architecture): Promise<UnexpandedValue<typeof key>[]>;
export function listUnexpandedValues<K extends string>(keys: K[], architecture: Architecture): Promise<UnexpandedValue<typeof keys[number]>[]>;

export namespace arch {
export function list<K extends string>(keys: readonly K[]): Promise<RegistryItemCollection<typeof keys>>;
export function list32<K extends string>(keys: readonly K[]): Promise<RegistryItemCollection<typeof keys>>;
Expand All @@ -120,5 +164,10 @@ export namespace promisified {
export function putValue(map: RegistryItemPutCollection): Promise<void>;
export function putValue32(map: RegistryItemPutCollection): Promise<void>;
export function putValue64(map: RegistryItemPutCollection): Promise<void>;

export function listUnexpandedValues32<K extends string>(key: K): Promise<UnexpandedValue<typeof key>[]>;
export function listUnexpandedValues64<K extends string>(key: K): Promise<UnexpandedValue<typeof key>[]>;
export function listUnexpandedValues32<K extends string>(keys: K[]): Promise<UnexpandedValue<typeof keys>[]>;
export function listUnexpandedValues64<K extends string>(keys: K[]): Promise<UnexpandedValue<typeof keys>[]>;
}
}
3 changes: 2 additions & 1 deletion test/regedit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,8 @@ describe('regedit', function() {

describe('listUnexpandedValues', function () {
it('reads values without expanding environment variables embedded in them', function(done) {
index.listUnexpandedValues('HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\\AppData', function(err, result) {
const key = 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\\AppData'
index.listUnexpandedValues(key, function(err, result) {
if (err) {
return done(err)
}
Expand Down