1 | import { input, select, number, confirm, rawlist, expand, checkbox, password, editor } from '@inquirer/prompts';
|
2 | import type { Prettify, KeyUnion, DistributiveMerge, Pick } from '@inquirer/type';
|
3 | import { Observable } from 'rxjs';
|
4 | export type Answers<Key extends string = string> = {
|
5 | [key in Key]: any;
|
6 | };
|
7 | type AsyncCallbackFunction<R> = (...args: [error: null | undefined, value: R] | [error: Error, value: undefined]) => void;
|
8 | type AsyncGetterFunction<R, A extends Answers> = (this: {
|
9 | async: () => AsyncCallbackFunction<R>;
|
10 | }, answers: Partial<A>) => void | R | Promise<R>;
|
11 | export interface QuestionMap {
|
12 | input: Parameters<typeof input>[0];
|
13 | select: Parameters<typeof select>[0];
|
14 |
|
15 | list: Parameters<typeof select>[0];
|
16 | number: Parameters<typeof number>[0];
|
17 | confirm: Parameters<typeof confirm>[0];
|
18 | rawlist: Parameters<typeof rawlist>[0];
|
19 | expand: Parameters<typeof expand>[0];
|
20 | checkbox: Parameters<typeof checkbox>[0];
|
21 | password: Parameters<typeof password>[0];
|
22 | editor: Parameters<typeof editor>[0];
|
23 | }
|
24 | type PromptConfigMap<A extends Answers> = {
|
25 | [key in keyof QuestionMap]: Readonly<DistributiveMerge<QuestionMap[keyof QuestionMap], {
|
26 | type: keyof QuestionMap;
|
27 | name: KeyUnion<A>;
|
28 | when?: AsyncGetterFunction<boolean, Prettify<A>> | boolean;
|
29 | askAnswered?: boolean;
|
30 | message: Pick<QuestionMap[keyof QuestionMap], 'message'> | AsyncGetterFunction<Pick<QuestionMap[keyof QuestionMap], 'message'>, Prettify<A>>;
|
31 | choices?: Pick<QuestionMap[keyof QuestionMap], 'choices'> | string[] | AsyncGetterFunction<Pick<QuestionMap[keyof QuestionMap], 'choices'> | string[], Prettify<A>>;
|
32 | default?: Pick<QuestionMap[keyof QuestionMap], 'default'> | AsyncGetterFunction<Pick<QuestionMap[keyof QuestionMap], 'default'> | string[], Prettify<A>>;
|
33 | }>>;
|
34 | };
|
35 | export type Question<A extends Answers> = PromptConfigMap<A>[keyof PromptConfigMap<A>];
|
36 | export type QuestionAnswerMap<A extends Answers> = Readonly<{
|
37 | [name in KeyUnion<A>]: Omit<Question<A>, 'name'>;
|
38 | }> | never;
|
39 | export type QuestionArray<A extends Answers> = readonly Question<A>[] | never;
|
40 | export type QuestionObservable<A extends Answers> = Observable<Question<A>> | never;
|
41 | export type StreamOptions = Prettify<Parameters<typeof input>[1] & {
|
42 | skipTTYChecks?: boolean;
|
43 | }>;
|
44 | export {};
|