-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.d.ts
130 lines (117 loc) · 3.5 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import { Extension, ExtensionClass } from "./ext/index.js";
import { ErrorRecord } from "./lib/errors.js";
import { Result } from "./lib/result.js";
/**
* Represents options for configuring the PowerJS instance.
*/
interface PowerJSOptions {
/**
* Additional interpreters for PowerShell.
*
* Always the PowerJS class will add "pwsh" and "powershell" to the end of the list.
*/
additionalShellNames?: string[];
runas?: boolean | RunAsOptions;
/**
* Disable this if you want to do some stuff before start.
*
* Note: Shell is always spawned even if `autoStart` is set to false!
*/
autoStart?: boolean;
/**
* Extensions to import.
*/
extensions: ExtensionClass[];
/**
* DLLs to import.
*/
dlls: Record<string, Record<string, string[]>>;
}
/**
* Represents options for running PowerShell with elevated permissions.
*/
interface RunAsOptions {
user?: string;
password?: string;
}
/**
* Represents the configuration for executing a PowerShell command or script.
*/
interface PowerJSExecConfig {
/**
* Your awesome command.
*
* Notes:
*
* 1- All variables is private for each run of a command. If you want to make them global, use `$global:your_variable_here`.
*
* 2- When you except an array as a return, wrap your output statement in a
*
* `,(your_statement)`
*/
command: string;
/**
* Timeout is milliseconds.
*
* Set to `0` to disable timeout. ( NOT RECOMMENDED )
*/
timeout?: number;
}
/**
* Represents the PowerJS class to interact with PowerShell shell.
*/
declare class PowerJS {
/**
* Creates a new instance of the PowerJS class.
* @param options An optional configuration object.
*/
constructor(options?: PowerJSOptions);
/**
* Starts the PowerJS shell and initializes the instance.
* @param extensions Optional extensions to load on startup.
* @throws If the shell cannot be initiated.
* @returns A promise that resolves when PowerJS is started.
*/
start(...extensions: Extension[]): Promise<void>;
/**
* Executes a PowerShell command or script.
* @param config The configuration for the execution. Can be a string as a command.
* @returns A promise that resolves with the execution result.
* @throws If the shell isn't initiated yet.
*/
exec(config: PowerJSExecConfig | string): Promise<Result>;
/**
* Imports a DLL and its definitions for use in PowerShell commands.
* @param dllpath The path to the DLL file.
* @param defenition The DLL definitions.
* @throws If DLLs cannot be imported after starting.
*/
importDll(dllpath: string, defenition: Record<string, unknown>): void;
/**
* Get an extension by class or name.
*
* @param extClassOrName - The extension class or name to retrieve.
* @returns The extension instance or undefined if not found.
*/
getExtension(extClassOrName: string | ExtensionClass): Extension | undefined;
/**
* Extend PowerJS with custom extensions.
*
* @param extclasses - The extension classes to add to PowerJS.
*/
extend(...extclasses: ExtensionClass[]): void;
/**
* Gets the DLL-related properties and methods.
*/
readonly dll: {
/**
* Returns a copy of the imported DLLs and their definitions.
*/
readonly [name: string]: Record<
string,
// eslint-disable-next-line @typescript-eslint/ban-types
Record<string, Function | string | number | boolean>
>;
};
}
export { PowerJS, ErrorRecord, Extension, Result, PowerJSOptions, RunAsOptions, PowerJSExecConfig };