appium-lg-webos-driver
Version:
LG WebOS support for Appium
199 lines • 5.8 kB
TypeScript
/// <reference types="node" />
export type ValueEncoding = BufferEncoding | null;
export type Value = string | Buffer;
/**
* Represents a "value", which is just a file on disk containing something.
*
* A {@linkcode ValueWrapper} does not know anything about where it is stored, or how it is stored.
*/
export interface ValueWrapper<V extends Value> {
/**
* Slugified name
*/
id: string;
/**
* Name of value
*/
name: string;
/**
* Encoding of value
*/
encoding: ValueEncoding;
/**
* Read value from disk
*/
look(): Promise<V>;
/**
* Write to value
* @param value New value to write to value
*/
put(value: V): Promise<void>;
/**
* Current value, if any
*/
get value(): V | undefined;
}
/**
* A function which reads from a value
*/
export interface ValueLooker<V extends Value> {
(value: ValueWrapper<V>): Promise<V>;
}
/**
* A function which writes to a value
*/
export interface ValuePutter<V extends Value> {
(value: ValueWrapper<V>, data: V): Promise<void>;
}
/**
* A value which stores its value in a file on disk
*
* This class is not intended to be instantiated directly
*
*/
export declare class BaseValueWrapper<V extends Value> implements ValueWrapper<V> {
#private;
readonly name: string;
readonly encoding: ValueEncoding;
/**
* Slugified name
*/
readonly id: string;
/**
* Function which reads a value
*/
private readonly looker;
/**
* Function which writes a value
*/
private readonly putter;
/**
* Underlying value
*/
readonly value: V;
/**
* Slugifies the name
* @param name Name of value
* @param looker Reader fn
* @param putter Writer fn
* @param encoding Defaults to `utf8`
*/
constructor(name: string, looker: ValueLooker<V>, putter: ValuePutter<V>, encoding?: ValueEncoding);
/**
* {@inheritdoc IValueWrapper.read}
*/
look(): Promise<V>;
/**
* {@inheritdoc IValueWrapper.write}
*/
put(value: V): Promise<void>;
}
/**
* @see {@linkcode ValueBoxOpts}
*/
export declare const DEFAULT_SUFFIX = "valuebox";
/**
* A class which instantiates a {@linkcode ValueWrapper}.
*/
export interface ValueConstructor<V extends Value> {
new (name: string, reader: ValueLooker<V>, writer: ValuePutter<V>, encoding?: ValueEncoding): ValueWrapper<V>;
}
/**
* Main entry point for use of this module
*
* Manages multiple values.
*/
export declare class ValueBox {
readonly name: string;
/**
* Slugified name of this container; corresponds to the directory name.
*
* If `dir` is provided, this value is unused.
* If `suffix` is provided, then this will be the parent directory of `suffix`.
*/
readonly containerId: string;
/**
* Override the directory of this container.
*
* If this is present, both `suffix` and `containerId` are unused.
*/
readonly dir: string;
protected ctor?: ValueConstructor<any>;
/**
* Factory function for creating new {@linkcode ValueWrapper}s}
*/
protected wrapperIds: Set<string>;
protected constructor(name: string, { dir, suffix, defaultCtor: ctor }?: ValueBoxOpts);
/**
* "mkdirp"'s the value directory and writes it to disk
* @param value ValueWrapper to write
* @param value Value to write to the value
*/
private put;
/**
* "mkdirp"'s the value directory
*/
private init;
/**
* Removes _all_ values from disk by truncating the value directory.
*
* Convniently removes everything else in the value directory, even if it isn't a value!
*/
recycleAll(): Promise<void>;
/**
* Reads a value in a value from disk
* @param value ValueWrapper to read
*/
protected look<V extends Value>(wrapper: ValueWrapper<V>): Promise<V | undefined>;
/**
* Removes a value from disk.
*
* This does _not_ destroy the `ValueWrapper` instance in memory, nor does it allow the `id` to be reused.
* @param wrapper ValueWrapper to drop
*/
recycle(wrapper: ValueWrapper<Value>): Promise<void>;
/**
* Create a new {@linkcode ValueWrapper}. Reads the value from disk, if present.
* @param name Name of value
* @param encoding Encoding of value; defaults to `utf8`
* @returns New value
*/
createWrapper<V extends Value>(name: string, encoding?: ValueEncoding): Promise<ValueWrapper<V>>;
/**
* Creates a {@linkcode ValueWrapper} then immediately writes a value to it.
* If there was anything on disk, it is overwritten.
* @param name Name of value
* @param value Value to write
* @returns New `ValueWrapper` w/ value of `value`
*/
createWrapperWithValue<V extends Value>(name: string, value: V, encoding?: ValueEncoding): Promise<ValueWrapper<V>>;
/**
* Creates a new {@linkcode ValueBox}
* @param name Name of value container
* @param opts Options
* @returns New value
*/
static create(name: string, opts?: ValueBoxOpts): ValueBox;
}
export interface ValueBox {
/**
* Creates a new {@linkcode ValueBox}
* @param name Name of value container
* @param opts Options
* @returns New value
*/
create(name: string, opts?: ValueBoxOpts): ValueBox;
}
export interface ValueBoxOpts {
/**
* Override default value directory, which is chosen according to environment
*/
dir?: string;
/**
* Extra subdir to append to the auto-generated value directory. Ignored if `dir` is a `string`.
* @defaultValue 'valuebox'
*/
suffix?: string;
defaultCtor?: ValueConstructor<any>;
}
//# sourceMappingURL=valuebox.d.ts.map