qa-prompt 1.0.33-rc.7 → 1.0.33
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.
- package/Prompt.js +48 -17
- package/Prompt.js.map +1 -1
- package/Stepper.js +12 -12
- package/Stepper.js.map +1 -1
- package/package.json +1 -1
- package/prompts/autocomplete.js +1 -1
- package/prompts/autocomplete.js.map +1 -1
- package/suggestChoices.js +1 -1
- package/suggestChoices.js.map +1 -1
- package/validatePrompt.js +2 -2
- package/validatePrompt.js.map +1 -1
package/Prompt.js
CHANGED
|
@@ -1,52 +1,83 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
2
20
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
|
|
21
|
+
var __objRest = (source, exclude) => {
|
|
22
|
+
var target = {};
|
|
23
|
+
for (var prop in source)
|
|
24
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
25
|
+
target[prop] = source[prop];
|
|
26
|
+
if (source != null && __getOwnPropSymbols)
|
|
27
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
28
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
29
|
+
target[prop] = source[prop];
|
|
30
|
+
}
|
|
31
|
+
return target;
|
|
32
|
+
};
|
|
33
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
34
|
+
const _Prompt = class _Prompt {
|
|
4
35
|
constructor(initialState) {
|
|
5
36
|
this.initialState = initialState;
|
|
37
|
+
__publicField(this, "callbacks");
|
|
6
38
|
const callbacks = [];
|
|
7
39
|
this.callbacks = callbacks;
|
|
8
40
|
}
|
|
9
|
-
static {
|
|
10
|
-
__name(this, "Prompt");
|
|
11
|
-
}
|
|
12
41
|
static definePrompt(type, callback) {
|
|
13
|
-
Object.defineProperty(
|
|
42
|
+
Object.defineProperty(_Prompt.prototype, type, {
|
|
14
43
|
enumerable: true,
|
|
15
44
|
value: /* @__PURE__ */ __name(function(name, prompt) {
|
|
16
45
|
return this.addCallback(async (state) => {
|
|
17
|
-
|
|
46
|
+
var _b, _c;
|
|
47
|
+
const _a = prompt, { message, required, skip, initial: initialRaw } = _a, rest = __objRest(_a, ["message", "required", "skip", "initial"]);
|
|
18
48
|
const initialValue = state[name];
|
|
19
|
-
const initial = (typeof initialRaw === "function" ? await initialRaw(initialValue, state) : initialRaw)
|
|
20
|
-
const skipped = typeof skip === "function" ? await skip(state) : skip
|
|
49
|
+
const initial = (_b = typeof initialRaw === "function" ? await initialRaw(initialValue, state) : initialRaw) != null ? _b : initialValue;
|
|
50
|
+
const skipped = typeof skip === "function" ? await skip(state) : skip != null ? skip : false;
|
|
21
51
|
if (skipped) {
|
|
22
|
-
return { [name]: state[name]
|
|
52
|
+
return { [name]: (_c = state[name]) != null ? _c : initial };
|
|
23
53
|
}
|
|
24
|
-
const resolved = {
|
|
25
|
-
...rest,
|
|
54
|
+
const resolved = __spreadProps(__spreadValues({}, rest), {
|
|
26
55
|
message: typeof message === "function" ? await message(state) : message,
|
|
27
|
-
required: typeof required === "function" ? await required(state) : required
|
|
56
|
+
required: typeof required === "function" ? await required(state) : required != null ? required : false,
|
|
28
57
|
initial,
|
|
29
58
|
skip: skipped
|
|
30
|
-
};
|
|
59
|
+
});
|
|
31
60
|
return await callback(name, resolved, state);
|
|
32
61
|
});
|
|
33
62
|
}, "value")
|
|
34
63
|
});
|
|
35
64
|
}
|
|
36
|
-
callbacks;
|
|
37
65
|
addCallback(callback) {
|
|
38
66
|
this.callbacks.push(callback);
|
|
39
67
|
return this;
|
|
40
68
|
}
|
|
41
69
|
then(onfulfilled, onrejected) {
|
|
70
|
+
var _a;
|
|
42
71
|
return this.callbacks.reduce(
|
|
43
72
|
(next, callback) => next.then(
|
|
44
|
-
async (state) => ({
|
|
73
|
+
async (state) => __spreadValues(__spreadValues({}, state), await callback(state))
|
|
45
74
|
),
|
|
46
|
-
Promise.resolve(this.initialState
|
|
75
|
+
Promise.resolve((_a = this.initialState) != null ? _a : {})
|
|
47
76
|
).then(onfulfilled, onrejected);
|
|
48
77
|
}
|
|
49
|
-
}
|
|
78
|
+
};
|
|
79
|
+
__name(_Prompt, "Prompt");
|
|
80
|
+
let Prompt = _Prompt;
|
|
50
81
|
var Prompt_default = Prompt;
|
|
51
82
|
export {
|
|
52
83
|
Prompt_default as default
|
package/Prompt.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../Prompt.ts"],"sourcesContent":["import { PromptCallback, Promiseable, PromptType, PromptTypeMap, PromptValue, PromptConfig, PromptConfigInput, PromptResultValue } from './types.js';\n\ntype WithPrompts = { [TType in PromptType]: PromptTypeMap[TType] };\n\ninterface Prompt<TState extends object = {}> extends WithPrompts {}\n\nclass Prompt<TState extends object = {}> implements PromiseLike<TState> {\n\n static definePrompt<TType extends PromptType>(type: TType, callback: PromptConfig<TType>) {\n Object.defineProperty(Prompt.prototype, type, {\n enumerable: true,\n value: function <TName extends string, TState extends object = {}, TInitial extends PromptValue<TType> | undefined = undefined, TRequired extends boolean = false, TSkip extends boolean = false>(this: Prompt<TState & { [K in TName]?: PromptValue<TType> }>, name: TName, prompt: PromptConfigInput<TType>) {\n return this.addCallback(async (state: TState) => {\n const { message, required, skip, initial: initialRaw, ...rest } = prompt as any;\n const initialValue = (state as any)[name];\n const initial = (typeof initialRaw === 'function' ? await initialRaw(initialValue, state) : initialRaw) ?? initialValue;\n const skipped = typeof skip === 'function' ? await skip(state) : skip ?? false;\n if (skipped) {\n return { [name]: (state as any)[name] ?? initial };\n }\n const resolved = {\n ...rest,\n message: typeof message === 'function'? await message(state) : message,\n required: typeof required === 'function' ? await required(state) : required ?? false,\n initial,\n skip: skipped,\n };\n return await callback(name, resolved, state) as PromptResultValue<TName, PromptValue<TType>, TInitial, TRequired, TSkip>;\n });\n }\n })\n }\n\n private callbacks: PromptCallback<TState, any>[];\n\n private addCallback<TOutputState extends object>(\n callback: PromptCallback<TState, TOutputState>\n ): Prompt<{ [K in keyof (Omit<TState, keyof TOutputState> & TOutputState)]: (Omit<TState, keyof TOutputState> & TOutputState)[K] }> {\n this.callbacks.push(callback);\n return this as never;\n }\n\n constructor(private initialState?: TState) {\n const callbacks: PromptCallback<TState, any>[] = [];\n this.callbacks = callbacks;\n }\n\n then<TResult1 = TState, TResult2 = never>(onfulfilled?: ((value: TState) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): PromiseLike<TResult1 | TResult2> {\n return this.callbacks.reduce(\n (next, callback) => next.then(\n async state => ({ ...state, ...await (callback(state))})\n ),\n Promise.resolve(this.initialState ?? {} as TState),\n )\n .then(onfulfilled, onrejected);\n }\n}\n\nexport default Prompt;"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../Prompt.ts"],"sourcesContent":["import { PromptCallback, Promiseable, PromptType, PromptTypeMap, PromptValue, PromptConfig, PromptConfigInput, PromptResultValue } from './types.js';\n\ntype WithPrompts = { [TType in PromptType]: PromptTypeMap[TType] };\n\ninterface Prompt<TState extends object = {}> extends WithPrompts {}\n\nclass Prompt<TState extends object = {}> implements PromiseLike<TState> {\n\n static definePrompt<TType extends PromptType>(type: TType, callback: PromptConfig<TType>) {\n Object.defineProperty(Prompt.prototype, type, {\n enumerable: true,\n value: function <TName extends string, TState extends object = {}, TInitial extends PromptValue<TType> | undefined = undefined, TRequired extends boolean = false, TSkip extends boolean = false>(this: Prompt<TState & { [K in TName]?: PromptValue<TType> }>, name: TName, prompt: PromptConfigInput<TType>) {\n return this.addCallback(async (state: TState) => {\n const { message, required, skip, initial: initialRaw, ...rest } = prompt as any;\n const initialValue = (state as any)[name];\n const initial = (typeof initialRaw === 'function' ? await initialRaw(initialValue, state) : initialRaw) ?? initialValue;\n const skipped = typeof skip === 'function' ? await skip(state) : skip ?? false;\n if (skipped) {\n return { [name]: (state as any)[name] ?? initial };\n }\n const resolved = {\n ...rest,\n message: typeof message === 'function'? await message(state) : message,\n required: typeof required === 'function' ? await required(state) : required ?? false,\n initial,\n skip: skipped,\n };\n return await callback(name, resolved, state) as PromptResultValue<TName, PromptValue<TType>, TInitial, TRequired, TSkip>;\n });\n }\n })\n }\n\n private callbacks: PromptCallback<TState, any>[];\n\n private addCallback<TOutputState extends object>(\n callback: PromptCallback<TState, TOutputState>\n ): Prompt<{ [K in keyof (Omit<TState, keyof TOutputState> & TOutputState)]: (Omit<TState, keyof TOutputState> & TOutputState)[K] }> {\n this.callbacks.push(callback);\n return this as never;\n }\n\n constructor(private initialState?: TState) {\n const callbacks: PromptCallback<TState, any>[] = [];\n this.callbacks = callbacks;\n }\n\n then<TResult1 = TState, TResult2 = never>(onfulfilled?: ((value: TState) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): PromiseLike<TResult1 | TResult2> {\n return this.callbacks.reduce(\n (next, callback) => next.then(\n async state => ({ ...state, ...await (callback(state))})\n ),\n Promise.resolve(this.initialState ?? {} as TState),\n )\n .then(onfulfilled, onrejected);\n }\n}\n\nexport default Prompt;"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,MAAM,UAAN,MAAM,QAAkE;AAAA,EAoCpE,YAAoB,cAAuB;AAAvB;AATpB,wBAAQ;AAUJ,UAAM,YAA2C,CAAC;AAClD,SAAK,YAAY;AAAA,EACrB;AAAA,EArCA,OAAO,aAAuC,MAAa,UAA+B;AACtF,WAAO,eAAe,QAAO,WAAW,MAAM;AAAA,MAC1C,YAAY;AAAA,MACZ,OAAO,gCAAyP,MAAa,QAAkC;AAC3S,eAAO,KAAK,YAAY,OAAO,UAAkB;AAZjE;AAaoB,gBAAkE,aAA1D,WAAS,UAAU,MAAM,SAAS,WAb9D,IAasF,IAAT,iBAAS,IAAT,CAAjD,WAAS,YAAU,QAAM;AACjC,gBAAM,eAAgB,MAAc,IAAI;AACxC,gBAAM,WAAW,YAAO,eAAe,aAAa,MAAM,WAAW,cAAc,KAAK,IAAI,eAA3E,YAA0F;AAC3G,gBAAM,UAAU,OAAO,SAAS,aAAa,MAAM,KAAK,KAAK,IAAI,sBAAQ;AACzE,cAAI,SAAS;AACT,mBAAO,EAAE,CAAC,IAAI,IAAI,WAAc,IAAI,MAAlB,YAAuB,QAAQ;AAAA,UACrD;AACA,gBAAM,WAAW,iCACV,OADU;AAAA,YAEb,SAAS,OAAO,YAAY,aAAY,MAAM,QAAQ,KAAK,IAAI;AAAA,YAC/D,UAAU,OAAO,aAAa,aAAa,MAAM,SAAS,KAAK,IAAI,8BAAY;AAAA,YAC/E;AAAA,YACA,MAAM;AAAA,UACV;AACA,iBAAO,MAAM,SAAS,MAAM,UAAU,KAAK;AAAA,QAC/C,CAAC;AAAA,MACL,GAlBO;AAAA,IAmBX,CAAC;AAAA,EACL;AAAA,EAIQ,YACJ,UACgI;AAChI,SAAK,UAAU,KAAK,QAAQ;AAC5B,WAAO;AAAA,EACX;AAAA,EAOA,KAA0C,aAAwF,YAAuH;AA/C7P;AAgDQ,WAAO,KAAK,UAAU;AAAA,MAClB,CAAC,MAAM,aAAa,KAAK;AAAA,QACrB,OAAM,UAAU,kCAAK,QAAU,MAAO,SAAS,KAAK;AAAA,MACxD;AAAA,MACA,QAAQ,SAAQ,UAAK,iBAAL,YAAqB,CAAC,CAAW;AAAA,IACrD,EACK,KAAK,aAAa,UAAU;AAAA,EACrC;AACJ;AAlDwE;AAAxE,IAAM,SAAN;AAoDA,IAAO,iBAAQ;","names":[]}
|
package/Stepper.js
CHANGED
|
@@ -1,26 +1,24 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
2
3
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
|
|
4
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
const _GoToException = class _GoToException extends Error {
|
|
4
6
|
constructor(name, value) {
|
|
5
7
|
super();
|
|
6
8
|
this.name = name;
|
|
7
9
|
this.value = value;
|
|
8
10
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class Stepper {
|
|
11
|
+
};
|
|
12
|
+
__name(_GoToException, "GoToException");
|
|
13
|
+
let GoToException = _GoToException;
|
|
14
|
+
const _Stepper = class _Stepper {
|
|
14
15
|
constructor(data) {
|
|
15
16
|
this.data = data;
|
|
17
|
+
__publicField(this, "steps");
|
|
18
|
+
__publicField(this, "stepNames");
|
|
16
19
|
this.steps = {};
|
|
17
20
|
this.stepNames = [];
|
|
18
21
|
}
|
|
19
|
-
static {
|
|
20
|
-
__name(this, "Stepper");
|
|
21
|
-
}
|
|
22
|
-
steps;
|
|
23
|
-
stepNames;
|
|
24
22
|
step(name, step) {
|
|
25
23
|
this.steps[name] = step;
|
|
26
24
|
this.stepNames.push(name);
|
|
@@ -46,7 +44,9 @@ class Stepper {
|
|
|
46
44
|
return current;
|
|
47
45
|
}).then(onfulfilled, onrejected);
|
|
48
46
|
}
|
|
49
|
-
}
|
|
47
|
+
};
|
|
48
|
+
__name(_Stepper, "Stepper");
|
|
49
|
+
let Stepper = _Stepper;
|
|
50
50
|
var Stepper_default = Stepper;
|
|
51
51
|
export {
|
|
52
52
|
Stepper_default as default
|
package/Stepper.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../Stepper.ts"],"sourcesContent":["export type Step<TInput = unknown, TOutput = unknown> = {\n (state: TInput, goTo: GoTo<{}>): Promise<TOutput>;\n}\n\nexport type GoTo<TSteps extends Record<string, Step> = {}> = <TName extends StringKey<TSteps>>(name: TName, state: StepInput<TSteps[TName]>) => GoToException<TName, StepInput<TSteps[TName]>>;\nexport type StringKey<T> = Exclude<keyof T, symbol | number>;\nexport type StepFn<TInput, TOutput, TSteps extends Record<string, Step> = {}> = {\n (state: TInput, goTo: GoTo<TSteps>): TOutput | Promise<TOutput>;\n}\n\nexport type StepInput<TStep extends Step<any, any>> = TStep extends Step<infer TInput, any> ? TInput : never;\nexport type StepOutput<TStep extends Step<any, any>> = TStep extends Step<any, infer TOutput> ? TOutput : never;\n\nclass GoToException<TName extends string, TValue> extends Error {\n constructor(readonly name: TName, readonly value: TValue) {\n super();\n }\n}\n\nclass Stepper<TValue = never, TSteps extends Record<string, Step> = {}> {\n\n private steps: TSteps;\n\n private stepNames: string[];\n\n constructor(private data?: TValue) {\n this.steps = {} as never;\n this.stepNames = [];\n }\n\n step<TName extends string, TOutput>(name: TName, step: StepFn<TValue, TOutput, TSteps>): Stepper<TOutput, TSteps & { [K in TName]: Step<TValue, TOutput> }> {\n (this.steps as any)[name] = step;\n this.stepNames.push(name);\n return this as never; \n }\n\n then<TResult1 = TValue, TResult2 = never>(\n onfulfilled?: ((value: TValue) => TResult1 | PromiseLike<TResult1>) | undefined | null,\n onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null\n ): PromiseLike<TResult1 | TResult2> {\n return Promise.resolve(this.data).then(async (value) => {\n const goTo: GoTo<TSteps> = (name, value) => new GoToException(name, value); \n let current = value as any;\n for (let i = 0; i < this.stepNames.length; i++) {\n const name = this.stepNames[i];\n const step = this.steps[name];\n try {\n current = await step(current, goTo);\n } catch (error) {\n if (!(error instanceof GoToException)) {\n throw error;\n } \n i = this.stepNames.indexOf(error.name) - 1;\n current = error.value;\n }\n }\n return current;\n }).then(onfulfilled, onrejected)\n }\n\n}\n\nexport default Stepper;"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../Stepper.ts"],"sourcesContent":["export type Step<TInput = unknown, TOutput = unknown> = {\n (state: TInput, goTo: GoTo<{}>): Promise<TOutput>;\n}\n\nexport type GoTo<TSteps extends Record<string, Step> = {}> = <TName extends StringKey<TSteps>>(name: TName, state: StepInput<TSteps[TName]>) => GoToException<TName, StepInput<TSteps[TName]>>;\nexport type StringKey<T> = Exclude<keyof T, symbol | number>;\nexport type StepFn<TInput, TOutput, TSteps extends Record<string, Step> = {}> = {\n (state: TInput, goTo: GoTo<TSteps>): TOutput | Promise<TOutput>;\n}\n\nexport type StepInput<TStep extends Step<any, any>> = TStep extends Step<infer TInput, any> ? TInput : never;\nexport type StepOutput<TStep extends Step<any, any>> = TStep extends Step<any, infer TOutput> ? TOutput : never;\n\nclass GoToException<TName extends string, TValue> extends Error {\n constructor(readonly name: TName, readonly value: TValue) {\n super();\n }\n}\n\nclass Stepper<TValue = never, TSteps extends Record<string, Step> = {}> {\n\n private steps: TSteps;\n\n private stepNames: string[];\n\n constructor(private data?: TValue) {\n this.steps = {} as never;\n this.stepNames = [];\n }\n\n step<TName extends string, TOutput>(name: TName, step: StepFn<TValue, TOutput, TSteps>): Stepper<TOutput, TSteps & { [K in TName]: Step<TValue, TOutput> }> {\n (this.steps as any)[name] = step;\n this.stepNames.push(name);\n return this as never; \n }\n\n then<TResult1 = TValue, TResult2 = never>(\n onfulfilled?: ((value: TValue) => TResult1 | PromiseLike<TResult1>) | undefined | null,\n onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null\n ): PromiseLike<TResult1 | TResult2> {\n return Promise.resolve(this.data).then(async (value) => {\n const goTo: GoTo<TSteps> = (name, value) => new GoToException(name, value); \n let current = value as any;\n for (let i = 0; i < this.stepNames.length; i++) {\n const name = this.stepNames[i];\n const step = this.steps[name];\n try {\n current = await step(current, goTo);\n } catch (error) {\n if (!(error instanceof GoToException)) {\n throw error;\n } \n i = this.stepNames.indexOf(error.name) - 1;\n current = error.value;\n }\n }\n return current;\n }).then(onfulfilled, onrejected)\n }\n\n}\n\nexport default Stepper;"],"mappings":";;;;AAaA,MAAM,iBAAN,MAAM,uBAAoD,MAAM;AAAA,EAC5D,YAAqB,MAAsB,OAAe;AACtD,UAAM;AADW;AAAsB;AAAA,EAE3C;AACJ;AAJgE;AAAhE,IAAM,gBAAN;AAMA,MAAM,WAAN,MAAM,SAAkE;AAAA,EAMpE,YAAoB,MAAe;AAAf;AAJpB,wBAAQ;AAER,wBAAQ;AAGJ,SAAK,QAAQ,CAAC;AACd,SAAK,YAAY,CAAC;AAAA,EACtB;AAAA,EAEA,KAAoC,MAAa,MAA2G;AACxJ,IAAC,KAAK,MAAc,IAAI,IAAI;AAC5B,SAAK,UAAU,KAAK,IAAI;AACxB,WAAO;AAAA,EACX;AAAA,EAEA,KACI,aACA,YACgC;AAChC,WAAO,QAAQ,QAAQ,KAAK,IAAI,EAAE,KAAK,OAAO,UAAU;AACpD,YAAM,OAAqB,wBAAC,MAAMA,WAAU,IAAI,cAAc,MAAMA,MAAK,GAA9C;AAC3B,UAAI,UAAU;AACd,eAAS,IAAI,GAAG,IAAI,KAAK,UAAU,QAAQ,KAAK;AAC5C,cAAM,OAAO,KAAK,UAAU,CAAC;AAC7B,cAAM,OAAO,KAAK,MAAM,IAAI;AAC5B,YAAI;AACA,oBAAU,MAAM,KAAK,SAAS,IAAI;AAAA,QACtC,SAAS,OAAO;AACZ,cAAI,EAAE,iBAAiB,gBAAgB;AACnC,kBAAM;AAAA,UACV;AACA,cAAI,KAAK,UAAU,QAAQ,MAAM,IAAI,IAAI;AACzC,oBAAU,MAAM;AAAA,QACpB;AAAA,MACJ;AACA,aAAO;AAAA,IACZ,CAAC,EAAE,KAAK,aAAa,UAAU;AAAA,EAClC;AAEJ;AAzCwE;AAAxE,IAAM,UAAN;AA2CA,IAAO,kBAAQ;","names":["value"]}
|
package/package.json
CHANGED
package/prompts/autocomplete.js
CHANGED
|
@@ -11,7 +11,7 @@ Prompt.definePrompt("autocomplete", async (name, { message, choices: rawChoices,
|
|
|
11
11
|
let initial;
|
|
12
12
|
if (rawInitial) {
|
|
13
13
|
if (multiple) {
|
|
14
|
-
initial = rawInitial
|
|
14
|
+
initial = rawInitial == null ? void 0 : rawInitial.map((value) => {
|
|
15
15
|
const index = resolvedChoices.findIndex((choice) => choice.value === value);
|
|
16
16
|
return index >= 0 ? choices[index].value : null;
|
|
17
17
|
}).filter((value) => value != null);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../prompts/autocomplete.ts"],"sourcesContent":["import prompts from 'prompts';\nimport Prompt from '../Prompt.js';\nimport { BasePrompt, PromptResult, PromptResultValue, Promiseable } from '../types.js';\nimport validatePrompt from '../validatePrompt.js';\nimport suggestChoices from '../suggestChoices.js';\n\nexport type AutocompleteType<TValue = any, TMultiple extends boolean = false> = true extends TMultiple ? TValue[] : TValue;\n\nexport type AutocompleteChoice<TValue = any> = { name: string, value: TValue };\n\nexport type AutocompletePrompt<TName extends string, TState extends { [K in TName]?: any }, TValue = any, TMultiple extends boolean = false, TInitial extends AutocompleteType<TValue, TMultiple> | undefined = AutocompleteType<TValue, TMultiple> | undefined, TRequired extends boolean = false, TSkip extends boolean = false> = BasePrompt<TName, AutocompleteType<TValue, TMultiple>, TState, TInitial, TRequired, TSkip> & {\n choices: AutocompleteChoice<TValue>[] | ((state: TState) => Promiseable<AutocompleteChoice<TValue>[]>),\n multiple?: TMultiple\n}\n\nexport type AutocompletePromptCallback = {\n <TName extends string, TState extends object = {}, TValue = any, TMultiple extends boolean = false, TInitial extends AutocompleteType<TValue, TMultiple> | undefined = AutocompleteType<TValue, TMultiple> | undefined, TRequired extends boolean = false, TSkip extends boolean = false>(\n this: Prompt<TState & { [K in TName]?: AutocompleteType<TValue, TMultiple> }>,\n name: TName,\n prompt: AutocompletePrompt<TName, TState, TValue, TMultiple, TInitial, TRequired, TSkip>\n ): PromptResult<TName, AutocompleteType<TValue, TMultiple>, TState, TInitial, TRequired, TSkip>\n}\n\ndeclare module '../types.js' {\n export interface PromptTypeMap {\n autocomplete: AutocompletePromptCallback;\n }\n}\n\nPrompt.definePrompt('autocomplete', async (name, { message, choices: rawChoices, initial: rawInitial, validate, required, skip, multiple = false }, state) => {\n const resolvedChoices = (typeof rawChoices === 'function' ? await rawChoices(state) : rawChoices);\n const choices = resolvedChoices.map(({ name }) => ({ title: name, value: name, }));\n let selectedValue: any;\n let initial: any; \n\n if (rawInitial) {\n if (multiple) {\n initial = (rawInitial as any[])?.map(value => {\n const index = resolvedChoices.findIndex(choice => choice.value === value);\n return index >= 0 ? choices[index].value : null;\n }).filter(value => value != null)\n } else {\n const index = resolvedChoices.findIndex(choice => choice.value === rawInitial);\n initial = index >= 0 ? choices[index].value : undefined;\n }\n }\n\n const handle = async () => {\n let suggestContext = { reset: false }\n const suggest = suggestChoices(choices, 'title', () => suggestContext.reset = true);\n const result = await prompts({\n type: 'autocomplete',\n name,\n initial,\n message,\n choices: choices,\n multiple,\n validate: validatePrompt(required, state, validate) as never,\n suggest,\n format: (value: any) => {\n const index = choices.findIndex(choice => choice.value === value);\n selectedValue = index >= 0 ? resolvedChoices[index].value : value;\n return value;\n },\n onRender() {\n if (suggestContext.reset) {\n (this as any).moveSelect(0);\n suggestContext.reset = false;\n }\n },\n skip,\n } as never, { onCancel: () => process.exit() });\n\n Object.assign(result, { [name]: selectedValue });\n\n return result as PromptResultValue<typeof name, AutocompleteType, typeof initial, typeof required, typeof skip>;\n };\n\n return handle();\n});"],"mappings":";;AAAA,OAAO,aAAa;AACpB,OAAO,YAAY;AAEnB,OAAO,oBAAoB;AAC3B,OAAO,oBAAoB;AAyB3B,OAAO,aAAa,gBAAgB,OAAO,MAAM,EAAE,SAAS,SAAS,YAAY,SAAS,YAAY,UAAU,UAAU,MAAM,WAAW,MAAM,GAAG,UAAU;AAC1J,QAAM,kBAAmB,OAAO,eAAe,aAAa,MAAM,WAAW,KAAK,IAAI;AACtF,QAAM,UAAU,gBAAgB,IAAI,CAAC,EAAE,MAAAA,MAAK,OAAO,EAAE,OAAOA,OAAM,OAAOA,MAAM,EAAE;AACjF,MAAI;AACJ,MAAI;AAEJ,MAAI,YAAY;AACZ,QAAI,UAAU;AACV,gBAAW,
|
|
1
|
+
{"version":3,"sources":["../../prompts/autocomplete.ts"],"sourcesContent":["import prompts from 'prompts';\nimport Prompt from '../Prompt.js';\nimport { BasePrompt, PromptResult, PromptResultValue, Promiseable } from '../types.js';\nimport validatePrompt from '../validatePrompt.js';\nimport suggestChoices from '../suggestChoices.js';\n\nexport type AutocompleteType<TValue = any, TMultiple extends boolean = false> = true extends TMultiple ? TValue[] : TValue;\n\nexport type AutocompleteChoice<TValue = any> = { name: string, value: TValue };\n\nexport type AutocompletePrompt<TName extends string, TState extends { [K in TName]?: any }, TValue = any, TMultiple extends boolean = false, TInitial extends AutocompleteType<TValue, TMultiple> | undefined = AutocompleteType<TValue, TMultiple> | undefined, TRequired extends boolean = false, TSkip extends boolean = false> = BasePrompt<TName, AutocompleteType<TValue, TMultiple>, TState, TInitial, TRequired, TSkip> & {\n choices: AutocompleteChoice<TValue>[] | ((state: TState) => Promiseable<AutocompleteChoice<TValue>[]>),\n multiple?: TMultiple\n}\n\nexport type AutocompletePromptCallback = {\n <TName extends string, TState extends object = {}, TValue = any, TMultiple extends boolean = false, TInitial extends AutocompleteType<TValue, TMultiple> | undefined = AutocompleteType<TValue, TMultiple> | undefined, TRequired extends boolean = false, TSkip extends boolean = false>(\n this: Prompt<TState & { [K in TName]?: AutocompleteType<TValue, TMultiple> }>,\n name: TName,\n prompt: AutocompletePrompt<TName, TState, TValue, TMultiple, TInitial, TRequired, TSkip>\n ): PromptResult<TName, AutocompleteType<TValue, TMultiple>, TState, TInitial, TRequired, TSkip>\n}\n\ndeclare module '../types.js' {\n export interface PromptTypeMap {\n autocomplete: AutocompletePromptCallback;\n }\n}\n\nPrompt.definePrompt('autocomplete', async (name, { message, choices: rawChoices, initial: rawInitial, validate, required, skip, multiple = false }, state) => {\n const resolvedChoices = (typeof rawChoices === 'function' ? await rawChoices(state) : rawChoices);\n const choices = resolvedChoices.map(({ name }) => ({ title: name, value: name, }));\n let selectedValue: any;\n let initial: any; \n\n if (rawInitial) {\n if (multiple) {\n initial = (rawInitial as any[])?.map(value => {\n const index = resolvedChoices.findIndex(choice => choice.value === value);\n return index >= 0 ? choices[index].value : null;\n }).filter(value => value != null)\n } else {\n const index = resolvedChoices.findIndex(choice => choice.value === rawInitial);\n initial = index >= 0 ? choices[index].value : undefined;\n }\n }\n\n const handle = async () => {\n let suggestContext = { reset: false }\n const suggest = suggestChoices(choices, 'title', () => suggestContext.reset = true);\n const result = await prompts({\n type: 'autocomplete',\n name,\n initial,\n message,\n choices: choices,\n multiple,\n validate: validatePrompt(required, state, validate) as never,\n suggest,\n format: (value: any) => {\n const index = choices.findIndex(choice => choice.value === value);\n selectedValue = index >= 0 ? resolvedChoices[index].value : value;\n return value;\n },\n onRender() {\n if (suggestContext.reset) {\n (this as any).moveSelect(0);\n suggestContext.reset = false;\n }\n },\n skip,\n } as never, { onCancel: () => process.exit() });\n\n Object.assign(result, { [name]: selectedValue });\n\n return result as PromptResultValue<typeof name, AutocompleteType, typeof initial, typeof required, typeof skip>;\n };\n\n return handle();\n});"],"mappings":";;AAAA,OAAO,aAAa;AACpB,OAAO,YAAY;AAEnB,OAAO,oBAAoB;AAC3B,OAAO,oBAAoB;AAyB3B,OAAO,aAAa,gBAAgB,OAAO,MAAM,EAAE,SAAS,SAAS,YAAY,SAAS,YAAY,UAAU,UAAU,MAAM,WAAW,MAAM,GAAG,UAAU;AAC1J,QAAM,kBAAmB,OAAO,eAAe,aAAa,MAAM,WAAW,KAAK,IAAI;AACtF,QAAM,UAAU,gBAAgB,IAAI,CAAC,EAAE,MAAAA,MAAK,OAAO,EAAE,OAAOA,OAAM,OAAOA,MAAM,EAAE;AACjF,MAAI;AACJ,MAAI;AAEJ,MAAI,YAAY;AACZ,QAAI,UAAU;AACV,gBAAW,yCAAsB,IAAI,WAAS;AAC1C,cAAM,QAAQ,gBAAgB,UAAU,YAAU,OAAO,UAAU,KAAK;AACxE,eAAO,SAAS,IAAI,QAAQ,KAAK,EAAE,QAAQ;AAAA,MAC/C,GAAG,OAAO,WAAS,SAAS;AAAA,IAChC,OAAO;AACH,YAAM,QAAQ,gBAAgB,UAAU,YAAU,OAAO,UAAU,UAAU;AAC7E,gBAAU,SAAS,IAAI,QAAQ,KAAK,EAAE,QAAQ;AAAA,IAClD;AAAA,EACJ;AAEA,QAAM,SAAS,mCAAY;AACvB,QAAI,iBAAiB,EAAE,OAAO,MAAM;AACpC,UAAM,UAAU,eAAe,SAAS,SAAS,MAAM,eAAe,QAAQ,IAAI;AAClF,UAAM,SAAS,MAAM,QAAQ;AAAA,MACzB,MAAM;AAAA,MACN;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,UAAU,eAAe,UAAU,OAAO,QAAQ;AAAA,MAClD;AAAA,MACA,QAAQ,wBAAC,UAAe;AACpB,cAAM,QAAQ,QAAQ,UAAU,YAAU,OAAO,UAAU,KAAK;AAChE,wBAAgB,SAAS,IAAI,gBAAgB,KAAK,EAAE,QAAQ;AAC5D,eAAO;AAAA,MACX,GAJQ;AAAA,MAKR,WAAW;AACP,YAAI,eAAe,OAAO;AACtB,UAAC,KAAa,WAAW,CAAC;AAC1B,yBAAe,QAAQ;AAAA,QAC3B;AAAA,MACJ;AAAA,MACA;AAAA,IACJ,GAAY,EAAE,UAAU,6BAAM,QAAQ,KAAK,GAAnB,YAAqB,CAAC;AAE9C,WAAO,OAAO,QAAQ,EAAE,CAAC,IAAI,GAAG,cAAc,CAAC;AAE/C,WAAO;AAAA,EACX,GA7Be;AA+Bf,SAAO,OAAO;AAClB,CAAC;","names":["name"]}
|
package/suggestChoices.js
CHANGED
package/suggestChoices.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../suggestChoices.ts"],"sourcesContent":["import Fuse from 'fuse.js';\n\nfunction suggestChoices<TName extends string = 'name', TChoice extends { [K in TName]: string } = { [K in TName]: string }>(choices: TChoice[], key: TName = 'name' as never, onSearch?: (input: string) => void) {\n const fuse = new Fuse(choices, {\n keys: [key],\n });\n return async (input: string) => {\n if (!input.trim()) {\n return choices;\n }\n onSearch?.(input);\n return fuse.search(input).map(result => result.item);\n };\n}\n\nexport default suggestChoices;"],"mappings":";;AAAA,OAAO,UAAU;AAEjB,SAAS,eAAmH,SAAoB,MAAa,QAAiB,UAAoC;AAC9M,QAAM,OAAO,IAAI,KAAK,SAAS;AAAA,IAC3B,MAAM,CAAC,GAAG;AAAA,EACd,CAAC;AACD,SAAO,OAAO,UAAkB;AAC5B,QAAI,CAAC,MAAM,KAAK,GAAG;AACf,aAAO;AAAA,IACX;AACA,
|
|
1
|
+
{"version":3,"sources":["../suggestChoices.ts"],"sourcesContent":["import Fuse from 'fuse.js';\n\nfunction suggestChoices<TName extends string = 'name', TChoice extends { [K in TName]: string } = { [K in TName]: string }>(choices: TChoice[], key: TName = 'name' as never, onSearch?: (input: string) => void) {\n const fuse = new Fuse(choices, {\n keys: [key],\n });\n return async (input: string) => {\n if (!input.trim()) {\n return choices;\n }\n onSearch?.(input);\n return fuse.search(input).map(result => result.item);\n };\n}\n\nexport default suggestChoices;"],"mappings":";;AAAA,OAAO,UAAU;AAEjB,SAAS,eAAmH,SAAoB,MAAa,QAAiB,UAAoC;AAC9M,QAAM,OAAO,IAAI,KAAK,SAAS;AAAA,IAC3B,MAAM,CAAC,GAAG;AAAA,EACd,CAAC;AACD,SAAO,OAAO,UAAkB;AAC5B,QAAI,CAAC,MAAM,KAAK,GAAG;AACf,aAAO;AAAA,IACX;AACA,yCAAW;AACX,WAAO,KAAK,OAAO,KAAK,EAAE,IAAI,YAAU,OAAO,IAAI;AAAA,EACvD;AACJ;AAXS;AAaT,IAAO,yBAAQ;","names":[]}
|
package/validatePrompt.js
CHANGED
|
@@ -5,11 +5,11 @@ function validatePrompt(required, state, validate) {
|
|
|
5
5
|
if (required && !(typeof value === "string" ? value.trim() : value)) {
|
|
6
6
|
return "Invalid";
|
|
7
7
|
}
|
|
8
|
-
const result = await validate
|
|
8
|
+
const result = await (validate == null ? void 0 : validate(value, state));
|
|
9
9
|
if (result === false) {
|
|
10
10
|
return "Invalid input";
|
|
11
11
|
}
|
|
12
|
-
return result
|
|
12
|
+
return result != null ? result : true;
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
15
|
__name(validatePrompt, "validatePrompt");
|
package/validatePrompt.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../validatePrompt.ts"],"sourcesContent":["import { ValidateCallback } from './types.js';\n\nfunction validatePrompt<T = any>(required: boolean, state: any, validate?: ValidateCallback<T>) {\n return async (value: any) => {\n if (required && !(typeof value === 'string' ? value.trim() : value)) {\n return 'Invalid';\n }\n\n const result = await validate?.(value, state);\n\n if (result === false) {\n return 'Invalid input';\n }\n\n return result ?? true;\n };\n}\n\nexport default validatePrompt;"],"mappings":";;AAEA,SAAS,eAAwB,UAAmB,OAAY,UAAgC;AAC5F,SAAO,OAAO,UAAe;AACzB,QAAI,YAAY,EAAE,OAAO,UAAU,WAAW,MAAM,KAAK,IAAI,QAAQ;AACjE,aAAO;AAAA,IACX;AAEA,UAAM,SAAS,
|
|
1
|
+
{"version":3,"sources":["../validatePrompt.ts"],"sourcesContent":["import { ValidateCallback } from './types.js';\n\nfunction validatePrompt<T = any>(required: boolean, state: any, validate?: ValidateCallback<T>) {\n return async (value: any) => {\n if (required && !(typeof value === 'string' ? value.trim() : value)) {\n return 'Invalid';\n }\n\n const result = await validate?.(value, state);\n\n if (result === false) {\n return 'Invalid input';\n }\n\n return result ?? true;\n };\n}\n\nexport default validatePrompt;"],"mappings":";;AAEA,SAAS,eAAwB,UAAmB,OAAY,UAAgC;AAC5F,SAAO,OAAO,UAAe;AACzB,QAAI,YAAY,EAAE,OAAO,UAAU,WAAW,MAAM,KAAK,IAAI,QAAQ;AACjE,aAAO;AAAA,IACX;AAEA,UAAM,SAAS,OAAM,qCAAW,OAAO;AAEvC,QAAI,WAAW,OAAO;AAClB,aAAO;AAAA,IACX;AAEA,WAAO,0BAAU;AAAA,EACrB;AACJ;AAdS;AAgBT,IAAO,yBAAQ;","names":[]}
|