@qodalis/cli-core 0.0.10 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,130 +1,7 @@
1
- import { Terminal } from '@xterm/xterm';
2
- import { Observable, Subject } from 'rxjs';
3
- import { CliBackgroundColor, CliForegroundColor, CliLogLevel, CliOptions, CliProcessCommand, CliProcessorMetadata, ICliUser, ICliUserSession } from '../models';
4
- export interface ICliCommandAuthor {
5
- /**
6
- * The name of the author
7
- */
8
- name: string;
9
- /**
10
- * The email of the author
11
- */
12
- email: string;
13
- }
14
- /**
15
- * Represents a command processor
16
- */
17
- export interface ICliCommandProcessor {
18
- /**
19
- * The command that this processor handles
20
- */
21
- command: string;
22
- /**
23
- * A description of the command
24
- */
25
- description?: string;
26
- /**
27
- * The author of the command
28
- */
29
- author?: ICliCommandAuthor;
30
- /**
31
- * If true, the processor can handle unlisted commands
32
- * @default false
33
- * @remarks If true, the processor can handle unlisted commands. If false, the processor will only handle commands that are explicitly listed in the processors property
34
- * @remarks Optional if valueRequired is true
35
- */
36
- allowUnlistedCommands?: boolean;
37
- /**
38
- * If true, the value is required
39
- */
40
- valueRequired?: boolean;
41
- /**
42
- * The version of the command processor
43
- * @default '1.0.0'
44
- */
45
- version?: string;
46
- /**
47
- * The metadata for the command processor
48
- */
49
- metadata?: CliProcessorMetadata;
50
- /**
51
- * Processors that are nested under this processor
52
- */
53
- processors?: ICliCommandProcessor[];
54
- /**
55
- * Parameters that the command accepts
56
- */
57
- parameters?: ICliCommandParameterDescriptor[];
58
- /**
59
- * Process the command
60
- * @param command The command to process
61
- * @param context The context in which the command is executed
62
- */
63
- processCommand(command: CliProcessCommand, context: ICliExecutionContext): Promise<void>;
64
- /**
65
- * Write the description of the command
66
- * @param context The context in which the command is executed
67
- */
68
- writeDescription?(context: ICliExecutionContext): void;
69
- /**
70
- * A function that validates the command before execution
71
- * @param value The value to validate
72
- * @returns An object with a valid property that indicates if the value is valid and an optional message property that contains a message to display if the value is not valid
73
- */
74
- validateBeforeExecution?: (command: CliProcessCommand, context: ICliExecutionContext) => {
75
- valid: boolean;
76
- message?: string;
77
- };
78
- /**
79
- * Initialize the command processor
80
- * @param context The context in which the command is executed
81
- */
82
- initialize?(context: ICliExecutionContext): Promise<void>;
83
- }
84
- /**
85
- * Represents a command parameter
86
- */
87
- export interface ICliCommandParameterDescriptor {
88
- /**
89
- * The name of the parameter
90
- */
91
- name: string;
92
- /**
93
- * Aliases for the parameter
94
- */
95
- aliases?: string[];
96
- /**
97
- * A description of the parameter
98
- */
99
- description: string;
100
- /**
101
- * If true, the parameter is required
102
- */
103
- required: boolean;
104
- /**
105
- * The type of the parameter
106
- */
107
- type: string;
108
- /**
109
- * The default value of the parameter
110
- */
111
- defaultValue?: any;
112
- /**
113
- * A validator function that validates the value of the parameter
114
- * @param value The value to validate
115
- * @returns An object with a valid property that indicates if the value is valid and an optional message property that contains a message to display if the value is not valid
116
- */
117
- validator?: (value: any) => {
118
- /**
119
- * Indicates if the value is valid
120
- */
121
- valid: boolean;
122
- /**
123
- * An optional message to display if the value is not valid
124
- */
125
- message?: string;
126
- };
127
- }
1
+ import { Observable, Subscription } from 'rxjs';
2
+ import { CliBackgroundColor, CliForegroundColor, CliLogLevel, CliProcessCommand, CliProvider, CliState } from '../models';
3
+ import { ICliExecutionContext } from './execution-context';
4
+ import { ICliCommandChildProcessor, ICliCommandProcessor } from './command-processor';
128
5
  export interface ICliTerminalWriter {
129
6
  /**
130
7
  * Write text to the terminal
@@ -211,58 +88,6 @@ export interface ICliTerminalWriter {
211
88
  char?: string;
212
89
  }): void;
213
90
  }
214
- export interface ICliProgressBar {
215
- /**
216
- * Indicates if the progress bar is running
217
- */
218
- isRunning: boolean;
219
- /**
220
- * Show the progress bar
221
- */
222
- show: () => void;
223
- /**
224
- * Hide the progress bar
225
- */
226
- hide: () => void;
227
- }
228
- /**
229
- * Represents a spinner for the CLI
230
- */
231
- export interface ICliSpinner extends ICliProgressBar {
232
- /**
233
- * Set the text of the spinner
234
- * @param text The text to set
235
- */
236
- setText: (text: string) => void;
237
- }
238
- export type CliPercentageProgressBarUpdateValueOptions = {
239
- /**
240
- * The type of update to perform
241
- * @default 'replace'
242
- */
243
- type?: 'replace' | 'increment';
244
- };
245
- /**
246
- * Represents a progress bar for the CLI
247
- */
248
- export interface ICliPercentageProgressBar extends ICliProgressBar {
249
- /**
250
- * Update the progress of the progress bar
251
- * @param progress The progress to update to
252
- * @returns void
253
- */
254
- update: (progress: number, options?: CliPercentageProgressBarUpdateValueOptions) => void;
255
- /**
256
- * Complete the progress bar
257
- * @returns void
258
- */
259
- complete: () => void;
260
- /**
261
- * Set the text of the spinner
262
- * @param text The text to set
263
- */
264
- setText: (text: string) => void;
265
- }
266
91
  /**
267
92
  * Represents a clipboard for the CLI
268
93
  */
@@ -300,12 +125,29 @@ export interface ICliCommandExecutorService {
300
125
  * Represents a registry for command processors
301
126
  */
302
127
  export interface ICliCommandProcessorRegistry {
128
+ /**
129
+ * The processors registered with the registry
130
+ */
131
+ readonly processors: ICliCommandProcessor[];
303
132
  /**
304
133
  * Find a processor for a command
305
134
  * @param mainCommand
306
135
  * @param chainCommands
307
136
  */
308
137
  findProcessor(mainCommand: string, chainCommands: string[]): ICliCommandProcessor | undefined;
138
+ /**
139
+ * Recursively searches for a processor matching the given command.
140
+ * @param mainCommand The main command name.
141
+ * @param chainCommands The remaining chain commands (if any).
142
+ * @param processors The list of available processors.
143
+ * @returns The matching processor or undefined if not found.
144
+ */
145
+ findProcessorInCollection(mainCommand: string, chainCommands: string[], processors: ICliCommandProcessor[]): ICliCommandProcessor | undefined;
146
+ /**
147
+ * Get the root processor for a child processor
148
+ * @param child The child processor
149
+ */
150
+ getRootProcessor(child: ICliCommandChildProcessor): ICliCommandProcessor;
309
151
  /**
310
152
  * Register a processor
311
153
  * @param processor
@@ -360,128 +202,71 @@ export interface ICliExecutionProcess {
360
202
  output(data: any): void;
361
203
  }
362
204
  /**
363
- * Represents the context in which a command is executed
205
+ * Represents a key-value store for the CLI
364
206
  */
365
- export interface ICliExecutionContext {
366
- /**
367
- * The current user session
368
- */
369
- userSession?: ICliUserSession;
370
- /**
371
- * The spinner to use for showing/hiding the loader
372
- */
373
- spinner?: ICliSpinner;
374
- /**
375
- * The progress bar to use for showing progress
376
- */
377
- progressBar: ICliPercentageProgressBar;
378
- /**
379
- * A subject that emits when the command is aborted
380
- */
381
- onAbort: Subject<void>;
382
- /**
383
- * The terminal to use for writing
384
- */
385
- terminal: Terminal;
386
- /**
387
- * The writer to use for writing to the terminal
388
- */
389
- writer: ICliTerminalWriter;
390
- /**
391
- * The command executor to use for executing commands
392
- */
393
- executor: ICliCommandExecutorService;
394
- /**
395
- * The clipboard to use for copying/pasting
396
- */
397
- clipboard: ICliClipboard;
398
- /**
399
- * The data store to use for storing data
400
- */
401
- dataStore: ICliCommandDataStore;
402
- /**
403
- * The options for the CLI
404
- */
405
- options?: CliOptions;
207
+ export interface ICliKeyValueStore {
406
208
  /**
407
- * The prompt to use for prompting the user for input
209
+ * Retrieves a value by key.
210
+ * @param key - The key to retrieve the value for.
211
+ * @returns A promise resolving to the value or undefined if not found.
408
212
  */
409
- showPrompt: () => void;
213
+ get<T = any>(key: string): Promise<T | undefined>;
410
214
  /**
411
- * Set the current main processor
412
- * @param processor The processor to set
215
+ * Sets a key-value pair in the store.
216
+ * @param key - The key to set.
217
+ * @param value - The value to store.
218
+ * @returns A promise resolving when the value is stored.
413
219
  */
414
- setMainProcessor(processor: ICliCommandProcessor): void;
220
+ set(key: string, value: any): Promise<void>;
415
221
  /**
416
- * The process to use for exiting the CLI
222
+ * Removes a key-value pair by key.
223
+ * @param key - The key to remove.
224
+ * @returns A promise resolving when the key is removed.
417
225
  */
418
- process: ICliExecutionProcess;
226
+ remove(key: string): Promise<void>;
419
227
  /**
420
- * The logger to use for logging
228
+ * Clears all key-value pairs from the store.
229
+ * @returns A promise resolving when the store is cleared.
421
230
  */
422
- logger: ICliLogger;
231
+ clear(): Promise<void>;
423
232
  }
424
233
  /**
425
- * Represents a data store for storing data associated with commands
234
+ * Represents a store for storing data associated with commands
426
235
  */
427
- export interface ICliCommandDataStore {
428
- /**
429
- * The data store
430
- */
431
- data: Record<string, Record<string, any>>;
236
+ export interface ICliStateStore {
432
237
  /**
433
- * Append data to the data store
434
- * @param command
435
- * @param key
436
- * @param data
238
+ * Get the current state as an object.
437
239
  */
438
- appendData(command: string, key: string, data: any): void;
240
+ getState(): CliState;
439
241
  /**
440
- * Get data from the data store
441
- * @param command
442
- * @param key
242
+ * Update the state with new values. Supports partial updates.
243
+ * @param newState Partial state to merge with the current state.
443
244
  */
444
- getData<T = any>(command: string, key: string): T;
445
- }
446
- /**
447
- * Represents a service that manages user sessions in the CLI
448
- */
449
- export interface ICliUserSessionService {
245
+ updateState(newState: Partial<CliState>): void;
450
246
  /**
451
- * Gets the current user session
452
- * @returns An observable that emits the current user session
247
+ * Select a specific property or computed value from the state.
248
+ * @param selector A function to project a slice of the state.
249
+ * @returns Observable of the selected value.
453
250
  */
454
- getUserSession(): Observable<ICliUserSession | undefined>;
251
+ select<K>(selector: (state: CliState) => K): Observable<K>;
455
252
  /**
456
- * Sets the current user session
457
- * @param session The session to set
253
+ * Subscribe to state changes.
254
+ * @param callback Callback function to handle state changes.
255
+ * @returns Subscription object to manage the subscription.
458
256
  */
459
- setUserSession(session: ICliUserSession): Promise<void>;
460
- }
461
- /**
462
- * Represents a service that manages users in the CLI
463
- */
464
- export interface ICliUsersStoreService {
257
+ subscribe(callback: (state: CliState) => void): Subscription;
465
258
  /**
466
- * Gets the current users
467
- * @returns An observable that emits the current users
259
+ * Reset the state to its initial value.
468
260
  */
469
- getUsers(options?: {
470
- query?: string;
471
- skip?: number;
472
- take?: number;
473
- }): Observable<ICliUser[]>;
261
+ reset(): void;
474
262
  /**
475
- * Creates a user
476
- * @param user The user to create
263
+ * Persist the state to storage.
477
264
  */
478
- createUser(user: Omit<ICliUser, 'id'>): Promise<ICliUser>;
265
+ persist(): Promise<void>;
479
266
  /**
480
- * Gets a user by id
481
- * @param id The id of the user to get
482
- * @returns An observable that emits the user with the specified id
267
+ * Initialize the state from storage.
483
268
  */
484
- getUser(id: string): Observable<ICliUser | undefined>;
269
+ initialize(): Promise<void>;
485
270
  }
486
271
  /**
487
272
  * Represents a service that pings the server
@@ -542,3 +327,23 @@ export interface ICliLogger {
542
327
  */
543
328
  debug(...args: any[]): void;
544
329
  }
330
+ /**
331
+ * Represents a service provider for the CLI
332
+ */
333
+ export interface ICliServiceProvider {
334
+ /**
335
+ * Get a service
336
+ * @param service The service to get
337
+ */
338
+ get<T>(service: any): T;
339
+ /**
340
+ * Set a service
341
+ * @param definition The definition of the service
342
+ */
343
+ set(definition: CliProvider | CliProvider[]): void;
344
+ }
345
+ export * from './execution-context';
346
+ export * from './command-processor';
347
+ export * from './progress-bars';
348
+ export * from './command-hooks';
349
+ export * from './users';
@@ -0,0 +1,72 @@
1
+ export interface ICliProgressBar {
2
+ /**
3
+ * Indicates if the progress bar is running
4
+ */
5
+ isRunning: boolean;
6
+ /**
7
+ * Show the progress bar
8
+ */
9
+ show: (text?: string) => void;
10
+ /**
11
+ * Hide the progress bar
12
+ */
13
+ hide: () => void;
14
+ }
15
+ /**
16
+ * Represents a spinner for the CLI
17
+ */
18
+ export interface ICliSpinner extends ICliProgressBar {
19
+ /**
20
+ * Set the text of the spinner
21
+ * @param text The text to set
22
+ */
23
+ setText: (text: string) => void;
24
+ }
25
+ export type CliPercentageProgressBarUpdateValueOptions = {
26
+ /**
27
+ * The type of update to perform
28
+ * @default 'replace'
29
+ */
30
+ type?: 'replace' | 'increment';
31
+ };
32
+ /**
33
+ * Represents a progress bar for the CLI
34
+ */
35
+ export interface ICliPercentageProgressBar extends ICliProgressBar {
36
+ /**
37
+ * Update the progress of the progress bar
38
+ * @param progress The progress to update to
39
+ * @returns void
40
+ */
41
+ update: (progress: number, options?: CliPercentageProgressBarUpdateValueOptions) => void;
42
+ /**
43
+ * Complete the progress bar
44
+ * @returns void
45
+ */
46
+ complete: () => void;
47
+ /**
48
+ * Set the text of the spinner
49
+ * @param text The text to set
50
+ */
51
+ setText: (text: string) => void;
52
+ }
53
+ export type CliTextAnimatorOptions = {
54
+ /**
55
+ * The speed of the animation
56
+ * @default 100
57
+ */
58
+ speed?: number;
59
+ /**
60
+ * The text will be removed after typing
61
+ */
62
+ removeAfterTyping?: boolean;
63
+ };
64
+ export interface ICliTextAnimator extends ICliProgressBar {
65
+ /**
66
+ * Show animated text in a typing and erasing effect.
67
+ * @param text
68
+ * @param options
69
+ * @returns
70
+ */
71
+ showText: (text: string, options?: CliTextAnimatorOptions) => void;
72
+ }
@@ -0,0 +1,42 @@
1
+ import { ICliUserSession, ICliUser, CliAddUser } from '../models';
2
+ import { Observable } from 'rxjs';
3
+ /**
4
+ * Represents a service that manages user sessions in the CLI
5
+ */
6
+ export interface ICliUserSessionService {
7
+ /**
8
+ * Gets the current user session
9
+ * @returns An observable that emits the current user session
10
+ */
11
+ getUserSession(): Observable<ICliUserSession | undefined>;
12
+ /**
13
+ * Sets the current user session
14
+ * @param session The session to set
15
+ */
16
+ setUserSession(session: ICliUserSession): Promise<void>;
17
+ }
18
+ /**
19
+ * Represents a service that manages users in the CLI
20
+ */
21
+ export interface ICliUsersStoreService {
22
+ /**
23
+ * Gets the current users
24
+ * @returns An observable that emits the current users
25
+ */
26
+ getUsers(options?: {
27
+ query?: string;
28
+ skip?: number;
29
+ take?: number;
30
+ }): Observable<ICliUser[]>;
31
+ /**
32
+ * Creates a user
33
+ * @param user The user to create
34
+ */
35
+ createUser(user: CliAddUser): Promise<ICliUser>;
36
+ /**
37
+ * Gets a user by id
38
+ * @param id The id of the user to get
39
+ * @returns An observable that emits the user with the specified id
40
+ */
41
+ getUser(id: string): Observable<ICliUser | undefined>;
42
+ }
@@ -7,7 +7,7 @@ export type CliProcessCommand = {
7
7
  /**
8
8
  * The data that was entered
9
9
  */
10
- data?: string;
10
+ data?: any;
11
11
  /**
12
12
  * The chain of commands that were entered
13
13
  */
@@ -162,35 +162,6 @@ export declare enum CliIcon {
162
162
  Balloon = "\uD83C\uDF88",
163
163
  Gift = "\uD83C\uDF81"
164
164
  }
165
- export type ICliUser = {
166
- /**
167
- * The id of the user
168
- */
169
- id: string;
170
- /**
171
- * The name of the user
172
- */
173
- name: string;
174
- /**
175
- * The email of the user
176
- */
177
- email: string;
178
- /**
179
- * The groups the user belongs to
180
- * @default []
181
- */
182
- groups?: string[];
183
- };
184
- export interface ICliUserSession {
185
- /**
186
- * The user associated with the session
187
- */
188
- user: ICliUser;
189
- /**
190
- * The data associated with the user session
191
- */
192
- data?: Record<string, any>;
193
- }
194
165
  /**
195
166
  * Options for the CLI
196
167
  */
@@ -286,6 +257,20 @@ export type CliProcessorMetadata = Record<string, any> & {
286
257
  */
287
258
  icon?: CliIcon | string;
288
259
  };
260
+ /**
261
+ * Represents a state configuration for the CLI processor
262
+ */
263
+ export type CliStateConfiguration = {
264
+ /**
265
+ * The initial state for the processor
266
+ */
267
+ initialState: Record<string, any>;
268
+ /**
269
+ * The store identifier for the processor, if any
270
+ * @remarks If the store identifier is not set, the processor command name is used
271
+ */
272
+ storeName?: string;
273
+ };
289
274
  /**
290
275
  * Represents a log level for the CLI
291
276
  */
@@ -297,9 +282,12 @@ export declare enum CliLogLevel {
297
282
  WARN = 4,
298
283
  ERROR = 5
299
284
  }
285
+ export type CliState = Record<string, any>;
300
286
  export declare const enums: {
301
287
  CliForegroundColor: typeof CliForegroundColor;
302
288
  CliBackgroundColor: typeof CliBackgroundColor;
303
289
  CliIcon: typeof CliIcon;
304
290
  CliLogLevel: typeof CliLogLevel;
305
291
  };
292
+ export * from './services';
293
+ export * from './users';
@@ -0,0 +1,20 @@
1
+ type MultiServices = {
2
+ /**
3
+ * When true, injector returns an array of instances. This is useful to allow multiple
4
+ * providers spread across many files to provide configuration information to a common token.
5
+ */
6
+ multi?: boolean;
7
+ };
8
+ export type CliValueProvider = MultiServices & {
9
+ useValue: any;
10
+ };
11
+ export type CliTypeProvider = MultiServices & {
12
+ useClass: any;
13
+ };
14
+ export type CliFactoryProvider = MultiServices & {
15
+ useFactory: Function;
16
+ };
17
+ export type CliProvider = {
18
+ provide: any;
19
+ } & (CliValueProvider | CliTypeProvider | CliFactoryProvider) & Record<string, any>;
20
+ export {};
@@ -0,0 +1,30 @@
1
+ export type ICliUser = {
2
+ /**
3
+ * The id of the user
4
+ */
5
+ id: string;
6
+ /**
7
+ * The name of the user
8
+ */
9
+ name: string;
10
+ /**
11
+ * The email of the user
12
+ */
13
+ email: string;
14
+ /**
15
+ * The groups the user belongs to
16
+ * @default []
17
+ */
18
+ groups?: string[];
19
+ };
20
+ export interface ICliUserSession {
21
+ /**
22
+ * The user associated with the session
23
+ */
24
+ user: ICliUser;
25
+ /**
26
+ * The data associated with the user session
27
+ */
28
+ data?: Record<string, any>;
29
+ }
30
+ export type CliAddUser = Omit<ICliUser, 'id'>;
@@ -3,6 +3,6 @@ export declare class CancellablePromise<T> {
3
3
  private hasCancelled;
4
4
  private abortController;
5
5
  constructor(executor: (resolve: (value: T) => void, reject: (reason?: any) => void) => void);
6
- promise: Promise<T>;
6
+ execute(): Promise<T>;
7
7
  cancel(): void;
8
8
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qodalis/cli-core",
3
- "version": "0.0.10",
3
+ "version": "0.0.12",
4
4
  "description": "Core Angular CLI for @qodalis extensions.",
5
5
  "author": "Nicolae Lupei, Qodalis Solutions",
6
6
  "license": "MIT",