UNPKG

9.11 kBPlain TextView Raw
1import { Monitor } from '@neo-one/monitor';
2import { Paths } from 'env-paths';
3import { Observable, Subject } from 'rxjs';
4import Vorpal, { Args, Command } from 'vorpal';
5import { ResourceDependency } from './MasterResourceAdapter';
6import { ResourceAdapter } from './ResourceAdapter';
7import { ResourceType } from './ResourceType';
8import { Task, TaskList } from './TaskList';
9
10export type ListTable = ReadonlyArray<ReadonlyArray<string>>;
11export interface SubDescribeTable {
12 readonly type: 'describe';
13 readonly table: DescribeTable;
14}
15export type DescribeTable = ReadonlyArray<
16 [string, string | { readonly type: 'list'; readonly table: ListTable } | SubDescribeTable]
17>;
18
19export type ResourceState = 'started' | 'stopped';
20export interface BaseResource {
21 readonly plugin: string;
22 readonly resourceType: string;
23 readonly name: string;
24 readonly baseName: string;
25 readonly state: ResourceState;
26}
27
28export type BaseResourceOptions = object;
29export interface GetResourceResponse {
30 readonly resources: ReadonlyArray<BaseResource>;
31}
32export interface DescribeResourceResponse {
33 readonly resource: BaseResource;
34}
35export interface TaskStatus {
36 readonly id: string;
37 readonly title: string;
38 readonly message?: string;
39 readonly subtasks?: ReadonlyArray<TaskStatus>;
40 readonly pending?: boolean;
41 readonly skipped?: string | boolean;
42 readonly complete?: boolean;
43 readonly error?: string;
44 readonly collapse: boolean;
45}
46
47export interface ExecuteTaskListResponse {
48 readonly tasks: ReadonlyArray<TaskStatus>;
49}
50
51export interface ReadRequest {
52 readonly type: 'start' | 'abort';
53}
54export type ReadResponse =
55 | {
56 readonly type: 'response';
57 // tslint:disable-next-line no-any
58 readonly response: any;
59 }
60 | {
61 readonly type: 'error';
62 readonly code: string;
63 readonly message: string;
64 }
65 | {
66 readonly type: 'aborted';
67 };
68
69export interface ExecuteTaskListRequestStart {
70 readonly type: 'start';
71 readonly plugin: string;
72 readonly options: string;
73}
74
75export interface ExecuteTaskListRequestAbort {
76 readonly type: 'abort';
77}
78
79export type ExecuteTaskListRequest = ExecuteTaskListRequestStart | ExecuteTaskListRequestAbort;
80
81export interface CRUDRequestStart extends ExecuteTaskListRequestStart {
82 readonly resourceType: string;
83 readonly name: string;
84}
85
86export interface CRUDRequestAbort extends ExecuteTaskListRequestAbort {}
87export type CRUDRequest = CRUDRequestStart | CRUDRequestAbort;
88export interface AllResources {
89 readonly [pluginResourceType: string]: ReadonlyArray<BaseResource>;
90}
91
92export interface Client {
93 readonly getVersion: () => Promise<string>;
94 readonly getDebug: () => Promise<DescribeTable>;
95 readonly getAllPlugins: () => Promise<ReadonlyArray<string>>;
96 readonly getPlugins$: () => Observable<string>;
97 readonly getAllResources$: () => Observable<AllResources>;
98 readonly getResources$: (
99 options: {
100 readonly plugin: string;
101 readonly resourceType: string;
102 readonly options: BaseResourceOptions;
103 },
104 ) => Observable<ReadonlyArray<BaseResource>>;
105 readonly getResource$: (
106 options: {
107 readonly plugin: string;
108 readonly resourceType: string;
109 readonly name: string;
110 readonly options: BaseResourceOptions;
111 },
112 ) => Observable<BaseResource | undefined>;
113 readonly getResource: (
114 options: {
115 readonly plugin: string;
116 readonly resourceType: string;
117 readonly name: string;
118 readonly options: BaseResourceOptions;
119 },
120 ) => Promise<BaseResource | undefined>;
121 readonly createResource$: (
122 options: {
123 readonly plugin: string;
124 readonly resourceType: string;
125 readonly name: string;
126 readonly options: BaseResourceOptions;
127 readonly cancel$: Observable<void>;
128 },
129 ) => Observable<ExecuteTaskListResponse>;
130 readonly createResource: (
131 options: {
132 readonly plugin: string;
133 readonly resourceType: string;
134 readonly name: string;
135 readonly options: BaseResourceOptions;
136 readonly cancel$: Observable<void>;
137 },
138 ) => Promise<BaseResource>;
139 readonly deleteResource$: (
140 options: {
141 readonly plugin: string;
142 readonly resourceType: string;
143 readonly name: string;
144 readonly options: BaseResourceOptions;
145 readonly cancel$: Observable<void>;
146 },
147 ) => Observable<ExecuteTaskListResponse>;
148 readonly startResource$: (
149 options: {
150 readonly plugin: string;
151 readonly resourceType: string;
152 readonly name: string;
153 readonly options: BaseResourceOptions;
154 readonly cancel$: Observable<void>;
155 },
156 ) => Observable<ExecuteTaskListResponse>;
157 readonly stopResource$: (
158 options: {
159 readonly plugin: string;
160 readonly resourceType: string;
161 readonly name: string;
162 readonly options: BaseResourceOptions;
163 readonly cancel$: Observable<void>;
164 },
165 ) => Observable<ExecuteTaskListResponse>;
166 readonly executeTaskList$: (
167 options: {
168 readonly plugin: string;
169 readonly options: object;
170 readonly cancel$: Observable<void>;
171 },
172 ) => Observable<ExecuteTaskListResponse>;
173}
174
175export interface Binary {
176 readonly cmd: string;
177 readonly firstArgs: ReadonlyArray<string>;
178}
179
180export interface LogConfig {
181 readonly name: string;
182 readonly path: string;
183 readonly level: string;
184 readonly maxSize: number;
185 readonly maxFiles: number;
186}
187
188export interface CLIArgs {
189 readonly monitor: Monitor;
190 readonly shutdown: (
191 options: {
192 readonly exitCode: number;
193 readonly error?: Error;
194 },
195 ) => void;
196 mutableShutdownFuncs: Array<() => void>;
197 readonly logConfig$: Subject<LogConfig>;
198 readonly vorpal: Vorpal;
199 readonly debug: boolean;
200 readonly binary: Binary;
201 readonly serverArgs: {
202 readonly dir?: string;
203 readonly serverPort?: number;
204 readonly minPort?: number;
205 };
206 readonly paths: Paths;
207}
208// tslint:disable-next-line no-any
209export type Session = any;
210
211export interface InteractiveCLI {
212 readonly vorpal: Vorpal;
213 readonly client: Client;
214 readonly debug: boolean;
215 readonly updateSession: (plugin: string, session: Session) => void;
216 readonly mergeSession: (plugin: string, session: Session) => void;
217 readonly getSession: (plugin: string) => Promise<Session>;
218 readonly getSession$: (plugin: string) => Observable<Session>;
219 readonly addDelimiter: (key: string, name: string) => void;
220 readonly removeDelimiter: (key: string) => void;
221 readonly resetDelimiter: () => void;
222 // tslint:disable-next-line no-any
223 readonly prompt: (questions: ReadonlyArray<object>) => Promise<any>;
224 readonly monitor: Monitor | undefined;
225 readonly exec: (command: string) => Promise<void>;
226 readonly printDescribe: (describeTable: DescribeTable, log?: (value: string) => void) => void;
227 readonly printList: (listTable: ListTable, log?: (value: string) => void) => void;
228 readonly print: (value: string) => void;
229 readonly getResourceType: (
230 options: {
231 readonly plugin: string;
232 readonly resourceType: string;
233 },
234 ) => ResourceType;
235}
236
237export interface InteractiveCLIArgs {
238 readonly cli: InteractiveCLI;
239}
240
241export type InteractiveCommand = (cliArgs: InteractiveCLIArgs) => Command;
242
243export type CLIHook = (
244 options: {
245 readonly cli: InteractiveCLI;
246 readonly args: Args;
247 },
248) => Promise<void>;
249
250export interface PortAllocator {
251 readonly allocatePort: (
252 options: {
253 readonly plugin: string;
254 readonly resourceType: string;
255 readonly resource: string;
256 readonly name: string;
257 },
258 ) => number;
259 readonly releasePort: (
260 options: {
261 readonly plugin: string;
262 readonly resourceType: string;
263 readonly resource: string;
264 readonly name?: string;
265 },
266 ) => void;
267}
268
269export interface ResourcesManager<
270 Resource extends BaseResource = BaseResource,
271 ResourceOptions extends BaseResourceOptions = BaseResourceOptions
272> {
273 readonly getResource: (options: { readonly name: string; readonly options: ResourceOptions }) => Promise<Resource>;
274 readonly getResources$: (options: ResourceOptions) => Observable<ReadonlyArray<Resource>>;
275 readonly getResource$: (
276 options: { readonly name: string; readonly options: ResourceOptions },
277 ) => Observable<Resource | undefined>;
278 readonly getResourceAdapter: (name: string) => ResourceAdapter<Resource, ResourceOptions>;
279 // tslint:disable-next-line no-any
280 readonly masterResourceAdapter: any;
281 readonly addDependent: (name: string, dependent: ResourceDependency) => void;
282 readonly create: (name: string, options: ResourceOptions) => TaskList;
283 readonly delete: (name: string, options: ResourceOptions) => TaskList;
284 readonly start: (name: string, options: ResourceOptions) => TaskList;
285}
286
287export interface PluginManager {
288 readonly httpServerPort: number;
289 readonly getResourcesManager: (
290 options: { readonly plugin: string; readonly resourceType: string },
291 ) => ResourcesManager;
292}
293
294export type CreateHook = (
295 options: {
296 readonly name: string;
297 readonly options: BaseResourceOptions;
298 readonly pluginManager: PluginManager;
299 },
300) => Task;