@qodalis/cli-core 0.0.11 → 0.0.13

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,7 +1,7 @@
1
- import { Observable } from 'rxjs';
2
- import { CliBackgroundColor, CliForegroundColor, CliLogLevel, CliProcessCommand, CliProvider, ICliUser, ICliUserSession } from '../models';
1
+ import { Observable, Subscription } from 'rxjs';
2
+ import { CliBackgroundColor, CliForegroundColor, CliLogLevel, CliProcessCommand, CliProvider, CliState } from '../models';
3
3
  import { ICliExecutionContext } from './execution-context';
4
- import { ICliCommandProcessor } from './command-processor';
4
+ import { ICliCommandChildProcessor, ICliCommandProcessor } from './command-processor';
5
5
  export interface ICliTerminalWriter {
6
6
  /**
7
7
  * Write text to the terminal
@@ -125,12 +125,29 @@ export interface ICliCommandExecutorService {
125
125
  * Represents a registry for command processors
126
126
  */
127
127
  export interface ICliCommandProcessorRegistry {
128
+ /**
129
+ * The processors registered with the registry
130
+ */
131
+ readonly processors: ICliCommandProcessor[];
128
132
  /**
129
133
  * Find a processor for a command
130
134
  * @param mainCommand
131
135
  * @param chainCommands
132
136
  */
133
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;
134
151
  /**
135
152
  * Register a processor
136
153
  * @param processor
@@ -185,66 +202,71 @@ export interface ICliExecutionProcess {
185
202
  output(data: any): void;
186
203
  }
187
204
  /**
188
- * Represents a data store for storing data associated with commands
205
+ * Represents a key-value store for the CLI
189
206
  */
190
- export interface ICliCommandDataStore {
207
+ export interface ICliKeyValueStore {
191
208
  /**
192
- * The data store
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.
193
212
  */
194
- data: Record<string, Record<string, any>>;
213
+ get<T = any>(key: string): Promise<T | undefined>;
195
214
  /**
196
- * Append data to the data store
197
- * @param command
198
- * @param key
199
- * @param data
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.
200
219
  */
201
- appendData(command: string, key: string, data: any): void;
220
+ set(key: string, value: any): Promise<void>;
202
221
  /**
203
- * Get data from the data store
204
- * @param command
205
- * @param key
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.
206
225
  */
207
- getData<T = any>(command: string, key: string): T;
226
+ remove(key: string): Promise<void>;
227
+ /**
228
+ * Clears all key-value pairs from the store.
229
+ * @returns A promise resolving when the store is cleared.
230
+ */
231
+ clear(): Promise<void>;
208
232
  }
209
233
  /**
210
- * Represents a service that manages user sessions in the CLI
234
+ * Represents a store for storing data associated with commands
211
235
  */
212
- export interface ICliUserSessionService {
236
+ export interface ICliStateStore {
213
237
  /**
214
- * Gets the current user session
215
- * @returns An observable that emits the current user session
238
+ * Get the current state as an object.
216
239
  */
217
- getUserSession(): Observable<ICliUserSession | undefined>;
240
+ getState<T extends CliState = CliState>(): T;
218
241
  /**
219
- * Sets the current user session
220
- * @param session The session to set
242
+ * Update the state with new values. Supports partial updates.
243
+ * @param newState Partial state to merge with the current state.
221
244
  */
222
- setUserSession(session: ICliUserSession): Promise<void>;
223
- }
224
- /**
225
- * Represents a service that manages users in the CLI
226
- */
227
- export interface ICliUsersStoreService {
245
+ updateState(newState: Partial<CliState>): void;
246
+ /**
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.
250
+ */
251
+ select<K>(selector: (state: CliState) => K): Observable<K>;
252
+ /**
253
+ * Subscribe to state changes.
254
+ * @param callback Callback function to handle state changes.
255
+ * @returns Subscription object to manage the subscription.
256
+ */
257
+ subscribe(callback: (state: CliState) => void): Subscription;
228
258
  /**
229
- * Gets the current users
230
- * @returns An observable that emits the current users
259
+ * Reset the state to its initial value.
231
260
  */
232
- getUsers(options?: {
233
- query?: string;
234
- skip?: number;
235
- take?: number;
236
- }): Observable<ICliUser[]>;
261
+ reset(): void;
237
262
  /**
238
- * Creates a user
239
- * @param user The user to create
263
+ * Persist the state to storage.
240
264
  */
241
- createUser(user: Omit<ICliUser, 'id'>): Promise<ICliUser>;
265
+ persist(): Promise<void>;
242
266
  /**
243
- * Gets a user by id
244
- * @param id The id of the user to get
245
- * @returns An observable that emits the user with the specified id
267
+ * Initialize the state from storage.
246
268
  */
247
- getUser(id: string): Observable<ICliUser | undefined>;
269
+ initialize(): Promise<void>;
248
270
  }
249
271
  /**
250
272
  * Represents a service that pings the server
@@ -306,9 +328,9 @@ export interface ICliLogger {
306
328
  debug(...args: any[]): void;
307
329
  }
308
330
  /**
309
- * Represents a services for the CLI context
331
+ * Represents a service provider for the CLI
310
332
  */
311
- export interface ICliContextServices {
333
+ export interface ICliServiceProvider {
312
334
  /**
313
335
  * Get a service
314
336
  * @param service The service to get
@@ -323,3 +345,5 @@ export interface ICliContextServices {
323
345
  export * from './execution-context';
324
346
  export * from './command-processor';
325
347
  export * from './progress-bars';
348
+ export * from './command-hooks';
349
+ export * from './users';
@@ -6,7 +6,7 @@ export interface ICliProgressBar {
6
6
  /**
7
7
  * Show the progress bar
8
8
  */
9
- show: () => void;
9
+ show: (text?: string) => void;
10
10
  /**
11
11
  * Hide the progress bar
12
12
  */
@@ -50,3 +50,23 @@ export interface ICliPercentageProgressBar extends ICliProgressBar {
50
50
  */
51
51
  setText: (text: string) => void;
52
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
+ }
@@ -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,6 +282,7 @@ 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;
@@ -304,3 +290,4 @@ export declare const enums: {
304
290
  CliLogLevel: typeof CliLogLevel;
305
291
  };
306
292
  export * from './services';
293
+ export * from './users';
@@ -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'>;
@@ -0,0 +1,16 @@
1
+ import { ITheme } from '@xterm/xterm';
2
+ export type CliTheme = ITheme;
3
+ export declare const DefaultThemes: {
4
+ default: CliTheme;
5
+ dracula: CliTheme;
6
+ monokai: CliTheme;
7
+ solarizedDark: CliTheme;
8
+ solarizedLight: CliTheme;
9
+ gruvboxDark: CliTheme;
10
+ gruvboxLight: CliTheme;
11
+ nord: CliTheme;
12
+ oneDark: CliTheme;
13
+ material: CliTheme;
14
+ yellow: CliTheme;
15
+ [key: string]: CliTheme;
16
+ };
@@ -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
  }
@@ -0,0 +1 @@
1
+ export declare const LIBRARY_VERSION = "0.0.13";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qodalis/cli-core",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
4
4
  "description": "Core Angular CLI for @qodalis extensions.",
5
5
  "author": "Nicolae Lupei, Qodalis Solutions",
6
6
  "license": "MIT",
package/public-api.d.ts CHANGED
@@ -4,3 +4,5 @@ export * from './lib/modules';
4
4
  export * from './lib/utils';
5
5
  export * from './lib/constants';
6
6
  export * from './lib/types';
7
+ export * from './lib/themes';
8
+ export * from './lib/version';