///
import * as net from 'net';
import type { BrightScriptDebugSession } from './debugSession/BrightScriptDebugSession';
import type { Position, Range } from 'brighterscript';
import type { AdapterOptions, DisposableLike } from './interfaces';
import type { Logger } from '@rokucommunity/logger';
import type { DeviceConfig, RokuDeploySocket } from 'roku-deploy';
declare class Util {
/**
* Resolve a project's staging folder the same way roku-deploy's `stage()` does: the default
* staging folder name inside `outDir`. roku-deploy does not expose this resolution, so it is
* rolled here and must stay in step with roku-deploy's own defaults.
*/
getStagingDir(options: {
outDir?: string;
cwd?: string;
}): string;
/**
* Resolve a project's output zip path the same way roku-deploy's `zip()` does: `outFile`
* inside `outDir`, with a `.zip` extension enforced. roku-deploy does not expose this
* resolution, so it is rolled here and must stay in step with roku-deploy's own defaults.
*/
getOutputZipPath(options: {
outDir?: string;
outFile?: string;
cwd?: string;
}): string;
/**
* If the path does not have a trailing slash, one is appended to it
* @param dirPath
*/
ensureTrailingSlash(dirPath: string): string;
/**
* Determine if a file exists
* @param filePath
*/
fileExists(filePath: string): Promise;
/**
* Determine if a file exists, comparing its name case insensitively against the entries of its
* parent directory. The parent directory path itself must exist as given (on a case-sensitive
* filesystem that means with matching case); returns false when it does not.
* @param filePath
*/
fileExistsCaseInsensitive(filePath: string): Promise;
/**
* Determines if the given path is a file
* @param filePathAbsolute
*/
isFile(filePathAbsolute: string): Promise;
/**
* Removes any leading scheme in the file path
* @param filePath
*/
removeFileScheme(filePath: string): string;
/**
* Gets any leading scheme in the file path
* @param filePath
*/
getFileScheme(filePath: string): string | null;
/**
* Remove a single trailing newline from a string (\n or \r\n)
*/
removeTrailingNewline(value: string): string;
/**
* Reads the the manifest file and converts to a javascript object skipping empty lines and comments
* @param path location of the manifest file
*/
convertManifestToObject(path: string): Promise | undefined>;
/**
* Split a comma-delimited string into trimmed, non-empty entries. Returns an empty array when the
* value is missing or blank.
* @param value the raw string to split (may be undefined)
*/
splitAndTrim(value: string | undefined): string[];
/**
* Replace the first case-insensitive occurrence of `search` in `subject` with `replace`.
* Returns `subject` unchanged when `search` is not found.
* @param subject the string that will have its contents replaced
* @param search the search text to find in `subject`
* @param replace the text to replace `search` with in `subject`
*/
stringReplaceInsensitive(subject: string, search: string, replace: string): string;
/**
* Checks to see if the port is already in use
* @param port target port to check
*/
isPortInUse(port: number): Promise;
/**
* A reference to the current debug session. Used for logging, and set in the debug session constructor
*/
_debugSession: BrightScriptDebugSession;
/**
* Write to the standard brightscript output log so users can see it. (This also writes to the debug server output channel, and the console)
* @param message
*/
log(message: string): void;
/**
* The vscode hover will occasionally forget to include the closing quotemark for quoted strings,
* so this attempts to auto-insert a closing quotemark if an opening one was found but is missing the closing one
* @param text
*/
ensureClosingQuote(text: string): string;
/**
* Test if `position` is in `range`. If the position is at the edges, will return true.
* Adapted from core vscode
* @param range
* @param position
*/
rangeContains(range: Range, position: Position): boolean;
/**
* Ensures that all roku-emitted beacons are entirely on their own lines
*/
ensureDebugPromptOnOwnLine(text: string): string;
/**
* Does the string end with the "Brightscript Debugger>" prompt?
* @param responseText
*/
endsWithDebuggerPrompt(text: string): boolean;
/**
* Does the string end with the "thread attached......" text, ignoring trailing whitespace.
* explanation: https://regex101.com/r/pN6grB/1
*/
endsWithThreadAttachedText(text: string): boolean;
/**
* Remove those pesky "Thread attached" messages and the debugger prompt following them.
* explanation: https://regex101.com/r/OwAWdw/4
*/
removeThreadAttachedText(text: string): string;
/**
* Removes the trailing `Brightscript Debugger>` prompt if present. If not present, returns original value
* @param value
*/
trimDebugPrompt(value: string): string;
/**
* Check if the parameter is an expression
* The HACK portion is copied from the getVariablePath function
* @param expression
*/
isAssignableExpression(expression: string): boolean;
/**
* Get the keys for a given variable expression, or undefined if the expression doesn't make sense.
*/
getVariablePath(expression: string): string[];
/**
* Given a full URL, convert any dns name into its IP address and then return the full URL with the name replaced
*/
resolveUrl(url: string, skipCache?: boolean): Promise;
dnsLookup(host: string, skipCache?: boolean): Promise;
private dnsCache;
/**
* Is this expression the `print` keyword followed by a variable expression (like `a.b` or `a['b'].c`)
* @param expression
*/
isPrintVarExpression(expression: string): boolean;
sleep(milliseconds: number): Promise;
fence(data: string): string;
formatTime(ms: number): string;
normalizeAdapterOptions(options: AdapterOptions): void;
/**
* Set an interval that can be cleared by calling the callback
* @param intervalMs the number of milliseconds to wait for the next interval
*/
setInterval(callback: (cancel: () => void) => any, intervalMs: number): () => void;
isNullish(item: any): boolean;
/**
* Translate our request options into the needle options we want for talking to a Roku.
*/
private buildNeedleOptions;
/**
* Build our own `HttpResponse` from needle's response.
*/
private buildHttpResponse;
/**
* Do an http GET request
*/
httpGet(url: string, options?: HttpRequestOptions): Promise;
/**
* Do an http POST request
*/
httpPost(url: string, options?: HttpRequestOptions): Promise;
/**
* Does the supplied value have at least one defined property with a non-nullish value?
*/
hasNonNullishProperty(value: Record): boolean;
private minPort;
getPort(): Promise;
isTransientVariable(variableName: string): boolean;
handleLogFragments(currentFragment: string, newFragment: string): {
completed: string;
remaining: string;
};
/**
* Execute dispose for a series of disposable items, and empties the array in-place
* @param disposables a list of functions or disposables
*/
applyDispose(disposables: DisposableLike[]): void;
/**
* Hydrate the Cloud Emulator api token onto an RCE device option from the `ROKU_RCE_TOKEN`
* environment variable when the option does not already carry one. The VS Code extension
* injects that variable into the debug adapter process so the token does not have to travel
* through the launch config (where it would end up in DAP traffic and logs); a token supplied
* directly on the device option always wins. Anything that is not a tokenless RCE device
* config is returned unchanged.
*/
hydrateRceTokenFromEnv(device: T): T;
/**
* A short human-readable identifier for a device, safe for log and error messages (never
* includes credentials like the rceToken). A local device is identified by its host and an RCE
* device by its instanceUrl, id, or esn.
*/
getDeviceLabel(device: DeviceConfig): string;
/**
* Register the socket events for logging
* @param socket - the socket to listen to for events. Accepts a real `net.Socket` as well as
* roku-deploy's `RokuDeploySocket` (an RCE device's telnet socket is not a real tcp socket, so its
* address-related fields are always undefined; the events below that never fire for it are
* harmless no-ops)
* @param logger - the logger to use for logging
* @param socketType - the type of socket (e.g. "client", "server")
*/
registerSocketLogging(socket: net.Socket | RokuDeploySocket, logger: Logger, socketType: string): void;
private getSocketAddressForLogs;
truncate(value: string, maxLength: number): string;
/**
* Coerce any value into an Error object. If it's already an Error, return it as-is. If it's not, create a new Error with the stringified value as the message
* @param error
* @returns
*/
toError(error: any): Error;
}
export declare function defer(): {
promise: Promise;
tryResolve: (value?: PromiseLike | T) => void;
resolve: (value?: PromiseLike | T) => void;
tryReject: (reason?: any) => void;
reject: (reason?: any) => void;
isResolved: boolean;
isRejected: boolean;
readonly isCompleted: boolean;
};
export declare const util: Util;
export interface Deferred {
promise: Promise;
resolve(value?: T): any;
reject(error?: any): any;
}
/**
* The subset of request options this library actually supports. Previously this was
* `CoreOptions` from `@types/request`; it was narrowed to drop the `postman-request`
* dependency, which carried vulnerable transitive deps.
*/
export interface HttpRequestOptions {
/**
* Milliseconds to wait for the connection to open and for the first response byte.
*/
timeout?: number;
headers?: Record;
body?: string;
}
/**
* The response shape returned by `util.httpPost()`. Deliberately our own type rather than needle's,
* so `@types/needle` stays a devDependency and needle is not part of this package's public surface.
*/
export interface HttpResponse {
statusCode: number;
statusMessage?: string;
/** Response headers, lower-cased names. */
headers: Record;
/** The response body, decoded as a utf8 string (empty string for bodyless responses). */
body: string;
}
export {};