nginx-testing
Version:
Support for integration/acceptance testing of nginx configuration.
72 lines • 2.41 kB
TypeScript
/**
* Nginx configuration editor returned by {@link parseConf}.
*/
export interface NginxConfEditor {
/**
* Returns a value of a directive at the path specified by a JSON Pointer
* (e.g. `/http/servers/0/listen`).
*
* - If the directive is not declared, returns `undefined`.
* - If the path points to an unnamed block (e.g. `server`), returns an empty string.
* - If an intermediate directive is declared multiple times and no index is
* specified in the path (e.g. `/http/servers/listen`), the first one is
* selected (`/http/servers/0/listen`).
* - If the path points to a directive that is declared multiple times (in the
* same context), returns an array of each declaration's value.
*/
get(path: string): string | string[] | undefined;
/**
* Applies the specified patch operations on the config.
*
* @throws {RangeError} if some intermediate directive on the path does not exist.
* @see PatchOperation
*/
applyPatch(patch: PatchOperation[]): this;
/**
* Dumps the config back to string.
*/
toString(): string;
}
/**
* A patch operation to be performed on nginx config.
*
* It's an object with the following properties:
*
* - `op` -- The operation name; one of:
* - `'add'` -- Adds a directive.
* - `'default'` -- Sets a directive if it's not declared yet.
* - `'remove'` -- Removes a directive.
* - `'set'` -- Sets a directive and removes its existing declarations in the
* same context.
*
* - `path` -- A JSON Pointer of the directive to be added, set or removed.
* For example, `/http/server/1/listen` points to a directive `listen` in
* the second `server` context inside `http` context. See documentation of
* `get` function in {@link NginxConfEditor} for more information.
*
* - `value` -- A value of the directive (not defined for op `'remove'`).
*
* This is based on [JSON Patch](http://jsonpatch.com/), but with a different
* operations.
*/
export type PatchOperation = {
op: 'add';
path: string;
value: string;
} | {
op: 'default';
path: string;
value: string;
} | {
op: 'remove';
path: string;
} | {
op: 'set';
path: string;
value: string;
};
/**
* Parses the given nginx config.
*/
export declare function parseConf(source: string): NginxConfEditor;
//# sourceMappingURL=nginxConf.d.ts.map