mirror of
https://github.com/45Drives/cockpit-navigator.git
synced 2025-07-29 16:45:13 +02:00
start cockpit typings
This commit is contained in:
parent
8cad2177cc
commit
192ff817f9
16
navigator/types/cockpit/Problem.d.ts
vendored
Normal file
16
navigator/types/cockpit/Problem.d.ts
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
export type ProblemCode =
|
||||
'access-denied' |
|
||||
'authentication-failed' |
|
||||
'internal-error' |
|
||||
'no-cockpit' |
|
||||
'no-session' |
|
||||
'not-found' |
|
||||
'terminated' |
|
||||
'timeout' |
|
||||
'unknown-hostkey' |
|
||||
'no-forwarding';
|
||||
|
||||
export interface Problem {
|
||||
message: string;
|
||||
problem: ProblemCode | null;
|
||||
}
|
55
navigator/types/cockpit/Spawn.d.ts
vendored
Normal file
55
navigator/types/cockpit/Spawn.d.ts
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
import { Problem } from "./Problem";
|
||||
|
||||
export interface SpawnProblem extends Problem {
|
||||
exit_status: number | null;
|
||||
exit_signal: string | null;
|
||||
}
|
||||
|
||||
export type SpawnOptionsErr = "out" | "ignore" | "message"
|
||||
|
||||
export interface SpawnOptions {
|
||||
/**
|
||||
* If set to `true` then handle the input and output of the process as
|
||||
* arrays of binary bytes.
|
||||
*/
|
||||
binary?: boolean;
|
||||
/**
|
||||
* The directory to spawn the process in.
|
||||
*/
|
||||
directory?: string;
|
||||
/**
|
||||
* Controls where the standard error is sent. By default it is logged to the
|
||||
* journal.
|
||||
* If set to `"out"` it is included in with the output data.
|
||||
* If set to `"ignore"` then the error output is discarded.
|
||||
* If set to `"message"`, then it will be returned as the error message.
|
||||
* When the {@link SpawnOptions.pty} `"pty"` field is set, this field has no effect.
|
||||
*/
|
||||
err?: "out" | "ignore" | "message";
|
||||
/**
|
||||
* The remote host to spawn the process on. If an alternate user or port is
|
||||
* required it can be specified as `"user@myhost:port"`. If no host is
|
||||
* specified then the correct one will be automatically selected based on
|
||||
* the page calling this function.
|
||||
*/
|
||||
host?: string;
|
||||
/**
|
||||
* An optional array that contains strings to be used as additional
|
||||
* environment variables for the new process. These are "NAME=VALUE"
|
||||
* strings.
|
||||
*/
|
||||
environ?: string[];
|
||||
/**
|
||||
* Launch the process in its own PTY terminal, and send/receive terminal
|
||||
* input and output.
|
||||
*/
|
||||
pty?: boolean;
|
||||
/**
|
||||
* Batch data coming from the process in blocks of at least this size. This
|
||||
* is not a guarantee. After a short timeout the data will be sent even if
|
||||
* the data doesn't match the batch size. Defaults to zero.
|
||||
*/
|
||||
batch?: number;
|
||||
}
|
||||
|
||||
export type Spawn = () => void;
|
167
navigator/types/cockpit/index.d.ts
vendored
Normal file
167
navigator/types/cockpit/index.d.ts
vendored
Normal file
@ -0,0 +1,167 @@
|
||||
export import { Problem, ProblemCode } from './Problem';
|
||||
export import { Spawn, SpawnOptions, SpawnOptionsErr, SpawnProblem } from './Spawn';
|
||||
|
||||
export interface Cockpit {
|
||||
spawn: Spawn;
|
||||
}
|
||||
|
||||
declare global {
|
||||
declare var cockpit: Cockpit;
|
||||
}
|
||||
// interface Func1<T, R = void> {
|
||||
// (arg: T): R;
|
||||
// }
|
||||
|
||||
// interface Func2<T, K, R = void> {
|
||||
// (arg1: T, arg2: K): R;
|
||||
// }
|
||||
|
||||
// interface Func3<T, K, V, R = void> {
|
||||
// (arg1: T, arg2: K, arg3: V): R;
|
||||
// }
|
||||
|
||||
// type GUID = string;
|
||||
|
||||
// type Fail = {
|
||||
// message: string;
|
||||
// problem?: string;
|
||||
// };
|
||||
|
||||
// type SpawnFail = Fail & {
|
||||
// exit_status?: number;
|
||||
// exit_signal?: number;
|
||||
// };
|
||||
|
||||
// type ErrorConfig = 'message' | 'out' | 'ignore' | 'pty';
|
||||
// type Superuser = 'require' | 'try';
|
||||
// type ProblemCodes = 'access-denied' | 'authentication-failed' | 'internal-error' | 'no-cockpit' | 'no-session' | 'not-found' | 'terminated' | 'timeout' | 'unknown-hostkey' | 'no-forwarding';
|
||||
|
||||
// type SpawnConfig = {
|
||||
// err?: ErrorConfig;
|
||||
// binary?: boolean;
|
||||
// directory?: string;
|
||||
// host?: string;
|
||||
// environ?: string[];
|
||||
// pty?: boolean;
|
||||
// batch?: boolean;
|
||||
// latency?: number;
|
||||
// superuser?: Superuser;
|
||||
// };
|
||||
|
||||
// interface SyntaxParser<K> {
|
||||
// parse: Func1<string, K>;
|
||||
// stringify: Func1<K, string>;
|
||||
// }
|
||||
|
||||
// type FileConfig<K extends object = {}> = {
|
||||
// syntax?: SyntaxParser<K>;
|
||||
// binary?: boolean;
|
||||
// max_read_size?: number;
|
||||
// superuser?: Superuser;
|
||||
// host?: string;
|
||||
// };
|
||||
|
||||
// interface FileOperationsPromise extends JQuery.Promise<string> {}
|
||||
|
||||
// interface ClosableWithProblem { close(problem?: ProblemCodes): void; }
|
||||
|
||||
// interface FileOperations extends Closable {
|
||||
// read(): FileOperationsPromise;
|
||||
// replace(content: string | null, tag?: string): FileOperationsPromise;
|
||||
// modify(): FileOperationsPromise;
|
||||
// watch(callback: Func3<string, string, string> | Func2<string, string>): void;
|
||||
// /**
|
||||
// * A string containing the path that was passed to the `cockpit.file()` method.
|
||||
// */
|
||||
// path: string;
|
||||
// }
|
||||
|
||||
// interface SpawnPromise extends JQuery.Promise<string>, ClosableWithProblem {
|
||||
// stream(callback: Func1<string>): SpawnPromise;
|
||||
// input(data?: string | Uint8Array, stream?: boolean): SpawnPromise;
|
||||
// }
|
||||
|
||||
// interface Closable { close(): void; }
|
||||
|
||||
// function CacheProvider(provide: Func1<any>, key: any): Closable | null;
|
||||
|
||||
// interface UserInfo {
|
||||
// id: number;
|
||||
// name: string;
|
||||
// full_name: string;
|
||||
// groups: string[];
|
||||
// home: string;
|
||||
// shell: string;
|
||||
// }
|
||||
|
||||
// interface EventHandler<V, T = string> {
|
||||
// addEventListener(type: T, handler: Func1<CustomEvent<V>>);
|
||||
// removeEventListener(type: T, handler: Func1<CustomEvent<V>>);
|
||||
// dispatchEvent(event: Event);
|
||||
// }
|
||||
|
||||
// interface UserInfoPromise extends JQuery.Promise<UserInfo> {}
|
||||
|
||||
// type PermissionOptions = { group: string };
|
||||
|
||||
// type PermissionEvents = 'changed';
|
||||
|
||||
// interface PermissionInfo extends EventHandler<PermissionInfoPromise, PermissionEvents>, Closable {
|
||||
// allowed: boolean;
|
||||
// user: UserInfo;
|
||||
// };
|
||||
|
||||
// interface PermissionInfoPromise extends JQuery.Promise<PermissionInfo> {};
|
||||
|
||||
// type HttpHeaders = any;
|
||||
|
||||
// interface HttpOptions {
|
||||
// address: string;
|
||||
// connection: string;
|
||||
// superuser: Superuser;
|
||||
// }
|
||||
|
||||
// type HttpData = string | Uint8Array;
|
||||
|
||||
// declare const enum HttpMethod {
|
||||
// Get = 'GET',
|
||||
// Post = 'POST',
|
||||
// Head = 'HEAD'
|
||||
// }
|
||||
|
||||
// interface HttpRequestOptions {
|
||||
// body?: HttpData;
|
||||
// headers?: HttpHeaders;
|
||||
// method?: HttpMethod;
|
||||
// params?: any;
|
||||
// path?: string;
|
||||
// }
|
||||
|
||||
// interface HttpOperations extends ClosableWithProblem {
|
||||
// get(path: string, params: any, headers: HttpHeaders): HttpOperationsPromise;
|
||||
// post(path: string, body: string | any, headers: HttpHeaders): HttpOperationsPromise;
|
||||
// request(options: HttpRequestOptions): HttpOperationsPromise;
|
||||
// }
|
||||
|
||||
// interface HttpOperationsPromise extends JQuery.Promise<HttpData>, ClosableWithProblem {
|
||||
// response(handler: Func2<number, HttpHeaders>): HttpOperationsPromise;
|
||||
// stream(handler: Func1<HttpData>): HttpOperationsPromise;
|
||||
// input(handler: HttpData, stream?: boolean): HttpOperationsPromise;
|
||||
// }
|
||||
|
||||
// interface CockpitAPI {
|
||||
// spawn(path: string[], config?: SpawnConfig): SpawnPromise;
|
||||
// script(path: string, args?: string[], config?: SpawnConfig): SpawnPromise;
|
||||
// file(path: string): FileOperations;
|
||||
// cache(key: GUID, provider: CacheProvider, consumer: Func2<any, any>): Closable;
|
||||
// logout(reload: boolean): void;
|
||||
// user(): UserInfoPromise;
|
||||
// permission(options?: PermissionOptions): PermissionInfoPromise;
|
||||
// http(endpoint: string | number, options: HttpOptions): HttpOperations;
|
||||
// }
|
||||
|
||||
// declare var cockpit : CockpitAPI;
|
||||
// declare module 'cockpit' {
|
||||
// export default cockpit;
|
||||
// export { Superuser, ErrorConfig, ProblemCodes };
|
||||
// }
|
Loading…
x
Reference in New Issue
Block a user