1 | import { checkbox, confirm, editor, expand, input, number, password, rawlist, search, select } from '@inquirer/prompts';
|
2 | import type { Context, DistributiveMerge, Prettify } from '@inquirer/type';
|
3 | import { Observable } from 'rxjs';
|
4 | export type Answers<Key extends string = string> = Record<Key, any>;
|
5 | type AsyncCallbackFunction<R> = (...args: [error: null | undefined, value: R] | [error: Error, value: undefined]) => void;
|
6 | export type AsyncGetterFunction<R, A extends Answers> = (this: {
|
7 | async: () => AsyncCallbackFunction<R>;
|
8 | }, answers: Prettify<Partial<A>>) => void | R | Promise<R>;
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | export interface QuestionMap {
|
24 | __dummy: {
|
25 | message: string;
|
26 | };
|
27 | }
|
28 | type KeyValueOrAsyncGetterFunction<T, k extends string, A extends Answers> = T extends Record<string, any> ? T[k] | AsyncGetterFunction<T[k], A> : never;
|
29 | export type Question<A extends Answers = Answers, Type extends string = string> = {
|
30 | type: Type;
|
31 | name: string;
|
32 | message: string | AsyncGetterFunction<string, A>;
|
33 | default?: any;
|
34 | choices?: any;
|
35 | filter?: (answer: any, answers: Partial<A>) => any;
|
36 | askAnswered?: boolean;
|
37 | when?: boolean | AsyncGetterFunction<boolean, A>;
|
38 | };
|
39 | type QuestionWithGetters<Type extends string, Q extends Record<string, any>, A extends Answers> = DistributiveMerge<Q, {
|
40 | type: Type;
|
41 | askAnswered?: boolean;
|
42 | when?: boolean | AsyncGetterFunction<boolean, A>;
|
43 | filter?(input: any, answers: A): any;
|
44 | message: KeyValueOrAsyncGetterFunction<Q, 'message', A>;
|
45 | default?: KeyValueOrAsyncGetterFunction<Q, 'default', A>;
|
46 | choices?: KeyValueOrAsyncGetterFunction<Q, 'choices', A>;
|
47 | }>;
|
48 | export type UnnamedDistinctQuestion<A extends Answers = object> = QuestionWithGetters<'checkbox', Parameters<typeof checkbox>[0], A> | QuestionWithGetters<'confirm', Parameters<typeof confirm>[0], A> | QuestionWithGetters<'editor', Parameters<typeof editor>[0], A> | QuestionWithGetters<'expand', Parameters<typeof expand>[0], A> | QuestionWithGetters<'input', Parameters<typeof input>[0], A> | QuestionWithGetters<'number', Parameters<typeof number>[0], A> | QuestionWithGetters<'password', Parameters<typeof password>[0], A> | QuestionWithGetters<'rawlist', Parameters<typeof rawlist>[0], A> | QuestionWithGetters<'search', Parameters<typeof search>[0], A> | QuestionWithGetters<'list', Parameters<typeof select>[0], A> | QuestionWithGetters<'select', Parameters<typeof select>[0], A>;
|
49 | export type DistinctQuestion<A extends Answers = Answers> = Prettify<UnnamedDistinctQuestion<A> & {
|
50 | name: Extract<keyof A, string>;
|
51 | }>;
|
52 | export type CustomQuestion<A extends Answers, Q extends Record<string, Record<string, any>>> = {
|
53 | [key in Extract<keyof Q, string>]: Readonly<QuestionWithGetters<key, Q[key], A>>;
|
54 | }[Extract<keyof Q, string>];
|
55 | export type PromptSession<A extends Answers = Answers, Q extends Question<A> = Question<A>> = Q[] | Record<string, Omit<Q, 'name'>> | Observable<Q> | Q;
|
56 | export type StreamOptions = Prettify<Context & {
|
57 | skipTTYChecks?: boolean;
|
58 | }>;
|
59 | export {};
|