qa-prompt 1.0.16

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.
@@ -0,0 +1 @@
1
+ {"jsSources":[],"tsSources":["Prompt.ts","Stepper.ts","index.ts","suggestChoices.ts","types.ts","validatePrompt.ts","prompts/autocomplete.ts","prompts/confirm.ts","prompts/index.ts","prompts/text.ts"],"nonJsSources":[],"entrySources":["Prompt.ts","Stepper.ts","index.ts","suggestChoices.ts","types.ts","validatePrompt.ts","prompts/autocomplete.ts","prompts/confirm.ts","prompts/index.ts","prompts/text.ts"]}
package/Prompt.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ import { PromptType, PromptTypeMap, PromptConfig } from './types.js';
2
+ type WithPrompts = {
3
+ [TType in PromptType]: PromptTypeMap[TType];
4
+ };
5
+ interface Prompt<TState extends object = {}> extends WithPrompts {
6
+ }
7
+ declare class Prompt<TState extends object = {}> implements PromiseLike<TState> {
8
+ private initialState?;
9
+ static definePrompt<TType extends PromptType>(type: TType, callback: PromptConfig<TType>): void;
10
+ private callbacks;
11
+ private addCallback;
12
+ constructor(initialState?: TState | undefined);
13
+ then<TResult1 = TState, TResult2 = never>(onfulfilled?: ((value: TState) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): PromiseLike<TResult1 | TResult2>;
14
+ }
15
+ export default Prompt;
16
+ //# sourceMappingURL=Prompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Prompt.d.ts","sourceRoot":"","sources":["../Prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,UAAU,EAAE,aAAa,EAAe,YAAY,EAAwC,MAAM,YAAY,CAAC;AAErJ,KAAK,WAAW,GAAG;KAAG,KAAK,IAAI,UAAU,GAAG,aAAa,CAAC,KAAK,CAAC;CAAE,CAAC;AAEnE,UAAU,MAAM,CAAC,MAAM,SAAS,MAAM,GAAG,EAAE,CAAE,SAAQ,WAAW;CAAG;AAEnE,cAAM,MAAM,CAAC,MAAM,SAAS,MAAM,GAAG,EAAE,CAAE,YAAW,WAAW,CAAC,MAAM,CAAC;IAoCvD,OAAO,CAAC,YAAY,CAAC;IAlCjC,MAAM,CAAC,YAAY,CAAC,KAAK,SAAS,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,YAAY,CAAC,KAAK,CAAC;IAyBxF,OAAO,CAAC,SAAS,CAAgC;IAEjD,OAAO,CAAC,WAAW;gBAOC,YAAY,CAAC,EAAE,MAAM,YAAA;IAKzC,IAAI,CAAC,QAAQ,GAAG,MAAM,EAAE,QAAQ,GAAG,KAAK,EAAE,WAAW,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC,GAAG,SAAS,GAAG,IAAI,EAAE,UAAU,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,GAAG,KAAK,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC,GAAG,SAAS,GAAG,IAAI,GAAG,WAAW,CAAC,QAAQ,GAAG,QAAQ,CAAC;CAS3P;AAED,eAAe,MAAM,CAAC"}
package/Prompt.js ADDED
@@ -0,0 +1,85 @@
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));
20
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
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 {
35
+ constructor(initialState) {
36
+ this.initialState = initialState;
37
+ __publicField(this, "callbacks");
38
+ const callbacks = [];
39
+ this.callbacks = callbacks;
40
+ }
41
+ static definePrompt(type, callback) {
42
+ Object.defineProperty(_Prompt.prototype, type, {
43
+ enumerable: true,
44
+ value: /* @__PURE__ */ __name(function(name, prompt) {
45
+ return this.addCallback(async (state) => {
46
+ var _b, _c;
47
+ const _a = prompt, { message, required, skip, initial: initialRaw } = _a, rest = __objRest(_a, ["message", "required", "skip", "initial"]);
48
+ const initialValue = state[name];
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;
51
+ if (skipped) {
52
+ return { [name]: (_c = state[name]) != null ? _c : initial };
53
+ }
54
+ const resolved = __spreadProps(__spreadValues({}, rest), {
55
+ message: typeof message === "function" ? await message(state) : message,
56
+ required: typeof required === "function" ? await required(state) : required != null ? required : false,
57
+ initial,
58
+ skip: skipped
59
+ });
60
+ return await callback(name, resolved, state);
61
+ });
62
+ }, "value")
63
+ });
64
+ }
65
+ addCallback(callback) {
66
+ this.callbacks.push(callback);
67
+ return this;
68
+ }
69
+ then(onfulfilled, onrejected) {
70
+ var _a;
71
+ return this.callbacks.reduce(
72
+ (next, callback) => next.then(
73
+ async (state) => __spreadValues(__spreadValues({}, state), await callback(state))
74
+ ),
75
+ Promise.resolve((_a = this.initialState) != null ? _a : {})
76
+ ).then(onfulfilled, onrejected);
77
+ }
78
+ };
79
+ __name(_Prompt, "Prompt");
80
+ let Prompt = _Prompt;
81
+ var Prompt_default = Prompt;
82
+ export {
83
+ Prompt_default as default
84
+ };
85
+ //# sourceMappingURL=Prompt.js.map
package/Prompt.js.map ADDED
@@ -0,0 +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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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.d.ts ADDED
@@ -0,0 +1,27 @@
1
+ export type Step<TInput = unknown, TOutput = unknown> = {
2
+ (state: TInput, goTo: GoTo<{}>): Promise<TOutput>;
3
+ };
4
+ export type GoTo<TSteps extends Record<string, Step> = {}> = <TName extends StringKey<TSteps>>(name: TName, state: StepInput<TSteps[TName]>) => GoToException<TName, StepInput<TSteps[TName]>>;
5
+ export type StringKey<T> = Exclude<keyof T, symbol | number>;
6
+ export type StepFn<TInput, TOutput, TSteps extends Record<string, Step> = {}> = {
7
+ (state: TInput, goTo: GoTo<TSteps>): TOutput | Promise<TOutput>;
8
+ };
9
+ export type StepInput<TStep extends Step<any, any>> = TStep extends Step<infer TInput, any> ? TInput : never;
10
+ export type StepOutput<TStep extends Step<any, any>> = TStep extends Step<any, infer TOutput> ? TOutput : never;
11
+ declare class GoToException<TName extends string, TValue> extends Error {
12
+ readonly name: TName;
13
+ readonly value: TValue;
14
+ constructor(name: TName, value: TValue);
15
+ }
16
+ declare class Stepper<TValue = never, TSteps extends Record<string, Step> = {}> {
17
+ private data?;
18
+ private steps;
19
+ private stepNames;
20
+ constructor(data?: TValue | undefined);
21
+ step<TName extends string, TOutput>(name: TName, step: StepFn<TValue, TOutput, TSteps>): Stepper<TOutput, TSteps & {
22
+ [K in TName]: Step<TValue, TOutput>;
23
+ }>;
24
+ then<TResult1 = TValue, TResult2 = never>(onfulfilled?: ((value: TValue) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): PromiseLike<TResult1 | TResult2>;
25
+ }
26
+ export default Stepper;
27
+ //# sourceMappingURL=Stepper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Stepper.d.ts","sourceRoot":"","sources":["../Stepper.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,IAAI,CAAC,MAAM,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO,IAAI;IACpD,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACrD,CAAA;AAED,MAAM,MAAM,IAAI,CAAC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,SAAS,SAAS,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,aAAa,CAAC,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,K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AAE,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG;SAAG,CAAC,IAAI,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC;KAAE,CAAC;IAM3J,IAAI,CAAC,QAAQ,GAAG,MAAM,EAAE,QAAQ,GAAG,KAAK,EACpC,WAAW,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC,GAAG,SAAS,GAAG,IAAI,EACtF,UAAU,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,GAAG,KAAK,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC,GAAG,SAAS,GAAG,IAAI,GACpF,WAAW,CAAC,QAAQ,GAAG,QAAQ,CAAC;CAqBtC;AAED,eAAe,OAAO,CAAC"}
package/Stepper.js ADDED
@@ -0,0 +1,54 @@
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;
3
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ const _GoToException = class _GoToException extends Error {
6
+ constructor(name, value) {
7
+ super();
8
+ this.name = name;
9
+ this.value = value;
10
+ }
11
+ };
12
+ __name(_GoToException, "GoToException");
13
+ let GoToException = _GoToException;
14
+ const _Stepper = class _Stepper {
15
+ constructor(data) {
16
+ this.data = data;
17
+ __publicField(this, "steps");
18
+ __publicField(this, "stepNames");
19
+ this.steps = {};
20
+ this.stepNames = [];
21
+ }
22
+ step(name, step) {
23
+ this.steps[name] = step;
24
+ this.stepNames.push(name);
25
+ return this;
26
+ }
27
+ then(onfulfilled, onrejected) {
28
+ return Promise.resolve(this.data).then(async (value) => {
29
+ const goTo = /* @__PURE__ */ __name((name, value2) => new GoToException(name, value2), "goTo");
30
+ let current = value;
31
+ for (let i = 0; i < this.stepNames.length; i++) {
32
+ const name = this.stepNames[i];
33
+ const step = this.steps[name];
34
+ try {
35
+ current = await step(current, goTo);
36
+ } catch (error) {
37
+ if (!(error instanceof GoToException)) {
38
+ throw error;
39
+ }
40
+ i = this.stepNames.indexOf(error.name) - 1;
41
+ current = error.value;
42
+ }
43
+ }
44
+ return current;
45
+ }).then(onfulfilled, onrejected);
46
+ }
47
+ };
48
+ __name(_Stepper, "Stepper");
49
+ let Stepper = _Stepper;
50
+ var Stepper_default = Stepper;
51
+ export {
52
+ Stepper_default as default
53
+ };
54
+ //# sourceMappingURL=Stepper.js.map
package/Stepper.js.map ADDED
@@ -0,0 +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":";;;;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/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import './prompts/index.js';
2
+ import Prompt from './Prompt.js';
3
+ import Stepper from './Stepper.js';
4
+ export { Stepper };
5
+ export default Prompt;
6
+ //# sourceMappingURL=index.d.ts.map
package/index.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,oBAAoB,CAAC;AAC5B,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,CAAA;AAClB,eAAe,MAAM,CAAC"}
package/index.js ADDED
@@ -0,0 +1,9 @@
1
+ import "./prompts/index.js";
2
+ import Prompt from "./Prompt.js";
3
+ import Stepper from "./Stepper.js";
4
+ var qa_prompt_default = Prompt;
5
+ export {
6
+ Stepper,
7
+ qa_prompt_default as default
8
+ };
9
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../index.ts"],"sourcesContent":["import './prompts/index.js';\nimport Prompt from './Prompt.js';\nimport Stepper from './Stepper.js';\nexport { Stepper }\nexport default Prompt;"],"mappings":"AAAA,OAAO;AACP,OAAO,YAAY;AACnB,OAAO,aAAa;AAEpB,IAAO,oBAAQ;","names":[]}
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "qa-prompt",
3
+ "version": "1.0.16",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": {
7
+ "default": "./index.js"
8
+ }
9
+ },
10
+ "files": [
11
+ "./**"
12
+ ],
13
+ "peerDependencies": {
14
+ "react": "18.2.0",
15
+ "react-dom": "18.2.0"
16
+ },
17
+ "dependencies": {
18
+ "fuse.js": "7.0.0",
19
+ "enquirer": "2.4.1",
20
+ "prompts": "2.4.2",
21
+ "kleur": "4.1.5"
22
+ }
23
+ }
@@ -0,0 +1,24 @@
1
+ import Prompt from '../Prompt.js';
2
+ import { BasePrompt, PromptResult, Promiseable } from '../types.js';
3
+ export type AutocompleteType<TValue = any, TMultiple extends boolean = false> = true extends TMultiple ? TValue[] : TValue;
4
+ export type AutocompleteChoice<TValue = any> = {
5
+ name: string;
6
+ value: TValue;
7
+ };
8
+ export type AutocompletePrompt<TName extends string, TState extends {
9
+ [K in TName]?: any;
10
+ }, 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> & {
11
+ choices: AutocompleteChoice<TValue>[] | ((state: TState) => Promiseable<AutocompleteChoice<TValue>[]>);
12
+ multiple?: TMultiple;
13
+ };
14
+ export type AutocompletePromptCallback = {
15
+ <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>(this: Prompt<TState & {
16
+ [K in TName]?: AutocompleteType<TValue, TMultiple>;
17
+ }>, name: TName, prompt: AutocompletePrompt<TName, TState, TValue, TMultiple, TInitial, TRequired, TSkip>): PromptResult<TName, AutocompleteType<TValue, TMultiple>, TState, TInitial, TRequired, TSkip>;
18
+ };
19
+ declare module '../types.js' {
20
+ interface PromptTypeMap {
21
+ autocomplete: AutocompletePromptCallback;
22
+ }
23
+ }
24
+ //# sourceMappingURL=autocomplete.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autocomplete.d.ts","sourceRoot":"","sources":["../../prompts/autocomplete.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,cAAc,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAqB,WAAW,EAAE,MAAM,aAAa,CAAC;AAIvF,MAAM,MAAM,gBAAgB,CAAC,MAAM,GAAG,GAAG,EAAE,SAAS,SAAS,OAAO,GAAG,KAAK,IAAI,IAAI,SAAS,SAAS,GAAG,MAAM,EAAE,GAAG,MAAM,CAAC;AAE3H,MAAM,MAAM,kBAAkB,CAAC,MAAM,GAAG,GAAG,IAAI;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAE/E,MAAM,MAAM,kBAAkB,CAAC,KAAK,SAAS,MAAM,EAAE,MAAM,SAAS;KAAG,CAAC,IAAI,KAAK,CAAC,CAAC,EAAE,GAAG;CAAE,EAAE,MAAM,GAAG,GAAG,EAAE,SAAS,SAAS,OAAO,GAAG,KAAK,EAAE,QAAQ,SAAS,gBAAgB,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,SAAS,GAAG,gBAAgB,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,SAAS,EAAE,SAAS,SAAS,OAAO,GAAG,KAAK,EAAE,KAAK,SAAS,OAAO,GAAG,KAAK,IAAI,UAAU,CAAC,KAAK,EAAE,gBAAgB,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,CAAC,GAAG;IAC9Z,OAAO,EAAE,kBAAkB,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,WAAW,CAAC,kBAAkB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;IACvG,QAAQ,CAAC,EAAE,SAAS,CAAA;CACvB,CAAA;AAED,MAAM,MAAM,0BAA0B,GAAG;IACrC,CAAC,KAAK,SAAS,MAAM,EAAE,MAAM,SAAS,MAAM,GAAG,EAAE,EAAE,MAAM,GAAG,GAAG,EAAE,SAAS,SAAS,OAAO,GAAG,KAAK,EAAE,QAAQ,SAAS,gBAAgB,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,SAAS,GAAG,gBAAgB,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,SAAS,EAAE,SAAS,SAAS,OAAO,GAAG,KAAK,EAAE,KAAK,SAAS,OAAO,GAAG,KAAK,EACpR,IAAI,EAAE,MAAM,CAAC,MAAM,GAAG;SAAG,CAAC,IAAI,KAAK,CAAC,CAAC,EAAE,gBAAgB,CAAC,MAAM,EAAE,SAAS,CAAC;KAAE,CAAC,EAC7E,IAAI,EAAE,KAAK,EACX,MAAM,EAAE,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,CAAC,GACzF,YAAY,CAAC,KAAK,EAAE,gBAAgB,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,CAAC,CAAA;CAClG,CAAA;AAED,OAAO,QAAQ,aAAa,CAAC;IACzB,UAAiB,aAAa;QAC1B,YAAY,EAAE,0BAA0B,CAAC;KAC5C;CACJ"}
@@ -0,0 +1,53 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import prompts from "prompts";
4
+ import Prompt from "../Prompt.js";
5
+ import validatePrompt from "../validatePrompt.js";
6
+ import suggestChoices from "../suggestChoices.js";
7
+ Prompt.definePrompt("autocomplete", async (name, { message, choices: rawChoices, initial: rawInitial, validate, required, skip, multiple = false }, state) => {
8
+ const resolvedChoices = typeof rawChoices === "function" ? await rawChoices(state) : rawChoices;
9
+ const choices = resolvedChoices.map(({ name: name2 }) => ({ title: name2, value: name2 }));
10
+ let selectedValue;
11
+ let initial;
12
+ if (rawInitial) {
13
+ if (multiple) {
14
+ initial = rawInitial == null ? void 0 : rawInitial.map((value) => {
15
+ const index = resolvedChoices.findIndex((choice) => choice.value === value);
16
+ return index >= 0 ? choices[index].value : null;
17
+ }).filter((value) => value != null);
18
+ } else {
19
+ const index = resolvedChoices.findIndex((choice) => choice.value === rawInitial);
20
+ initial = index >= 0 ? choices[index].value : void 0;
21
+ }
22
+ }
23
+ const handle = /* @__PURE__ */ __name(async () => {
24
+ let suggestContext = { reset: false };
25
+ const suggest = suggestChoices(choices, "title", () => suggestContext.reset = true);
26
+ const result = await prompts({
27
+ type: "autocomplete",
28
+ name,
29
+ initial,
30
+ message,
31
+ choices,
32
+ multiple,
33
+ validate: validatePrompt(required, state, validate),
34
+ suggest,
35
+ format: /* @__PURE__ */ __name((value) => {
36
+ const index = choices.findIndex((choice) => choice.value === value);
37
+ selectedValue = index >= 0 ? resolvedChoices[index].value : value;
38
+ return value;
39
+ }, "format"),
40
+ onRender() {
41
+ if (suggestContext.reset) {
42
+ this.moveSelect(0);
43
+ suggestContext.reset = false;
44
+ }
45
+ },
46
+ skip
47
+ }, { onCancel: /* @__PURE__ */ __name(() => process.exit(), "onCancel") });
48
+ Object.assign(result, { [name]: selectedValue });
49
+ return result;
50
+ }, "handle");
51
+ return handle();
52
+ });
53
+ //# sourceMappingURL=autocomplete.js.map
@@ -0,0 +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,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"]}
@@ -0,0 +1,17 @@
1
+ import Prompt from '../Prompt.js';
2
+ import { BasePrompt, PromptResult } from '../types.js';
3
+ export type ConfirmType = boolean;
4
+ export type ConfirmPrompt<TName extends string, TState extends {
5
+ [K in TName]?: any;
6
+ }, TInitial extends boolean | undefined = boolean | undefined, TRequired extends boolean = false, TSkip extends boolean = false> = BasePrompt<TName, ConfirmType, TState, TInitial, TRequired, TSkip> & {};
7
+ export type ConfirmPromptCallback = {
8
+ <TName extends string, TState extends object = {}, TInitial extends boolean | undefined = boolean | undefined, TRequired extends boolean = false, TSkip extends boolean = false>(this: Prompt<TState & {
9
+ [K in TName]?: ConfirmType;
10
+ }>, name: TName, prompt: ConfirmPrompt<TName, TState, TInitial, TRequired, TSkip>): PromptResult<TName, ConfirmType, TState, TInitial, TRequired, TSkip>;
11
+ };
12
+ declare module '../types.js' {
13
+ interface PromptTypeMap {
14
+ confirm: ConfirmPromptCallback;
15
+ }
16
+ }
17
+ //# sourceMappingURL=confirm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"confirm.d.ts","sourceRoot":"","sources":["../../prompts/confirm.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,cAAc,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAqB,MAAM,aAAa,CAAC;AAG1E,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC;AAElC,MAAM,MAAM,aAAa,CAAC,KAAK,SAAS,MAAM,EAAE,MAAM,SAAS;KAAG,CAAC,IAAI,KAAK,CAAC,CAAC,EAAE,GAAG;CAAE,EAAE,QAAQ,SAAS,OAAO,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,EAAE,SAAS,SAAS,OAAO,GAAG,KAAK,EAAE,KAAK,SAAS,OAAO,GAAG,KAAK,IAAI,UAAU,CAAC,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,CAAC,GAAG,EAAE,CAAA;AAE9R,MAAM,MAAM,qBAAqB,GAAG;IAChC,CAAC,KAAK,SAAS,MAAM,EAAE,MAAM,SAAS,MAAM,GAAG,EAAE,EAAE,QAAQ,SAAS,OAAO,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,EAAE,SAAS,SAAS,OAAO,GAAG,KAAK,EAAE,KAAK,SAAS,OAAO,GAAG,KAAK,EAC3K,IAAI,EAAE,MAAM,CAAC,MAAM,GAAG;SAAG,CAAC,IAAI,KAAK,CAAC,CAAC,EAAE,WAAW;KAAE,CAAC,EACrD,IAAI,EAAE,KAAK,EACX,MAAM,EAAE,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,CAAC,GACjE,YAAY,CAAC,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,CAAC,CAAA;CAC1E,CAAA;AAED,OAAO,QAAQ,aAAa,CAAC;IACzB,UAAiB,aAAa;QAC1B,OAAO,EAAE,qBAAqB,CAAC;KAClC;CACJ"}
@@ -0,0 +1,18 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import prompts from "prompts";
4
+ import Prompt from "../Prompt.js";
5
+ import validatePrompt from "../validatePrompt.js";
6
+ Prompt.definePrompt("confirm", async (name, { message, validate, initial, required }, state) => {
7
+ const handle = /* @__PURE__ */ __name(async () => await prompts({
8
+ type: "confirm",
9
+ name,
10
+ initial,
11
+ message,
12
+ validate: validatePrompt(required, state, validate)
13
+ }, {
14
+ onCancel: /* @__PURE__ */ __name(() => process.exit(), "onCancel")
15
+ }), "handle");
16
+ return handle();
17
+ });
18
+ //# sourceMappingURL=confirm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../prompts/confirm.ts"],"sourcesContent":["import prompts from 'prompts';\nimport Prompt from '../Prompt.js';\nimport { BasePrompt, PromptResult, PromptResultValue } from '../types.js';\nimport validatePrompt from '../validatePrompt.js';\n\nexport type ConfirmType = boolean;\n\nexport type ConfirmPrompt<TName extends string, TState extends { [K in TName]?: any }, TInitial extends boolean | undefined = boolean | undefined, TRequired extends boolean = false, TSkip extends boolean = false> = BasePrompt<TName, ConfirmType, TState, TInitial, TRequired, TSkip> & {}\n\nexport type ConfirmPromptCallback = {\n <TName extends string, TState extends object = {}, TInitial extends boolean | undefined = boolean | undefined, TRequired extends boolean = false, TSkip extends boolean = false>(\n this: Prompt<TState & { [K in TName]?: ConfirmType }>,\n name: TName,\n prompt: ConfirmPrompt<TName, TState, TInitial, TRequired, TSkip>\n ): PromptResult<TName, ConfirmType, TState, TInitial, TRequired, TSkip>\n}\n\ndeclare module '../types.js' {\n export interface PromptTypeMap {\n confirm: ConfirmPromptCallback;\n }\n}\n\nPrompt.definePrompt('confirm', async (name, { message, validate, initial, required }, state) => {\n const handle = async () => await prompts({\n type: 'confirm',\n name,\n initial,\n message,\n validate: validatePrompt(required, state, validate) as never,\n } as never, {\n onCancel: () => process.exit(),\n }) as PromptResultValue<typeof name, ConfirmType, ConfirmType, typeof required>;\n return handle();\n});"],"mappings":";;AAAA,OAAO,aAAa;AACpB,OAAO,YAAY;AAEnB,OAAO,oBAAoB;AAoB3B,OAAO,aAAa,WAAW,OAAO,MAAM,EAAE,SAAS,UAAU,SAAS,SAAS,GAAG,UAAU;AAC5F,QAAM,SAAS,mCAAY,MAAM,QAAQ;AAAA,IACrC,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU,eAAe,UAAU,OAAO,QAAQ;AAAA,EACpD,GAAY;AAAA,IACV,UAAU,6BAAM,QAAQ,KAAK,GAAnB;AAAA,EACZ,CAAC,GARY;AASf,SAAO,OAAO;AAClB,CAAC;","names":[]}
@@ -0,0 +1,4 @@
1
+ export * from './text.js';
2
+ export * from './confirm.js';
3
+ export * from './autocomplete.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../prompts/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from "./text.js";
2
+ export * from "./confirm.js";
3
+ export * from "./autocomplete.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../prompts/index.ts"],"sourcesContent":["export * from './text.js';\nexport * from './confirm.js';\nexport * from './autocomplete.js';"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
@@ -0,0 +1,17 @@
1
+ import Prompt from '../Prompt.js';
2
+ import { BasePrompt, PromptResult } from '../types.js';
3
+ export type TextType = string;
4
+ export type TextPrompt<TName extends string, TState extends {
5
+ [K in TName]?: any;
6
+ }, TInitial extends string | undefined = string | undefined, TRequired extends boolean = false, TSkip extends boolean = false> = BasePrompt<TName, InputType, TState, TInitial, TRequired, TSkip> & {};
7
+ export type TextPromptCallback = {
8
+ <TName extends string, TState extends object = {}, TInitial extends string | undefined = string | undefined, TRequired extends boolean = false, TSkip extends boolean = false>(this: Prompt<TState & {
9
+ [K in TName]?: TextType;
10
+ }>, name: TName, prompt: TextPrompt<TName, TState, TInitial, TRequired, TSkip>): PromptResult<TName, TextType, TState, TInitial, TRequired, TSkip>;
11
+ };
12
+ declare module '../types.js' {
13
+ interface PromptTypeMap {
14
+ text: TextPromptCallback;
15
+ }
16
+ }
17
+ //# sourceMappingURL=text.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../prompts/text.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,cAAc,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAqB,MAAM,aAAa,CAAC;AAG1E,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC;AAE9B,MAAM,MAAM,UAAU,CAAC,KAAK,SAAS,MAAM,EAAE,MAAM,SAAS;KAAG,CAAC,IAAI,KAAK,CAAC,CAAC,EAAE,GAAG;CAAE,EAAE,QAAQ,SAAS,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,EAAE,SAAS,SAAS,OAAO,GAAG,KAAK,EAAE,KAAK,SAAS,OAAO,GAAG,KAAK,IAAI,UAAU,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,CAAC,GAAG,EAAE,CAAA;AAEvR,MAAM,MAAM,kBAAkB,GAAG;IAC7B,CAAC,KAAK,SAAS,MAAM,EAAE,MAAM,SAAS,MAAM,GAAG,EAAE,EAAE,QAAQ,SAAS,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,EAAE,SAAS,SAAS,OAAO,GAAG,KAAK,EAAE,KAAK,SAAS,OAAO,GAAG,KAAK,EACzK,IAAI,EAAE,MAAM,CAAC,MAAM,GAAG;SAAG,CAAC,IAAI,KAAK,CAAC,CAAC,EAAE,QAAQ;KAAE,CAAC,EAClD,IAAI,EAAE,KAAK,EACX,MAAM,EAAE,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,CAAC,GAC9D,YAAY,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,CAAC,CAAA;CACvE,CAAA;AAED,OAAO,QAAQ,aAAa,CAAC;IACzB,UAAiB,aAAa;QAC1B,IAAI,EAAE,kBAAkB,CAAC;KAC5B;CACJ"}
@@ -0,0 +1,18 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import prompts from "prompts";
4
+ import Prompt from "../Prompt.js";
5
+ import validatePrompt from "../validatePrompt.js";
6
+ Prompt.definePrompt("text", async (name, { message, validate, initial, required }, state) => {
7
+ const handle = /* @__PURE__ */ __name(async () => await prompts([{
8
+ type: "text",
9
+ name,
10
+ initial,
11
+ message,
12
+ validate: validatePrompt(required, state, validate)
13
+ }], {
14
+ onCancel: /* @__PURE__ */ __name(() => process.exit(), "onCancel")
15
+ }), "handle");
16
+ return handle();
17
+ });
18
+ //# sourceMappingURL=text.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../prompts/text.ts"],"sourcesContent":["import prompts from 'prompts';\nimport Prompt from '../Prompt.js';\nimport { BasePrompt, PromptResult, PromptResultValue } from '../types.js';\nimport validatePrompt from '../validatePrompt.js';\n\nexport type TextType = string;\n\nexport type TextPrompt<TName extends string, TState extends { [K in TName]?: any }, TInitial extends string | undefined = string | undefined, TRequired extends boolean = false, TSkip extends boolean = false> = BasePrompt<TName, InputType, TState, TInitial, TRequired, TSkip> & {}\n\nexport type TextPromptCallback = {\n <TName extends string, TState extends object = {}, TInitial extends string | undefined = string | undefined, TRequired extends boolean = false, TSkip extends boolean = false>(\n this: Prompt<TState & { [K in TName]?: TextType }>,\n name: TName,\n prompt: TextPrompt<TName, TState, TInitial, TRequired, TSkip>\n ): PromptResult<TName, TextType, TState, TInitial, TRequired, TSkip>\n}\n\ndeclare module '../types.js' {\n export interface PromptTypeMap {\n text: TextPromptCallback;\n }\n}\n\nPrompt.definePrompt('text', async (name, { message, validate, initial, required }, state) => {\n const handle = async () => await prompts([{\n type: 'text',\n name,\n initial,\n message,\n validate: validatePrompt(required, state, validate) as never,\n }] as never, {\n onCancel: () => process.exit(),\n }) as PromptResultValue<typeof name, TextType, TextType, typeof required>;\n return handle();\n});"],"mappings":";;AAAA,OAAO,aAAa;AACpB,OAAO,YAAY;AAEnB,OAAO,oBAAoB;AAoB3B,OAAO,aAAa,QAAQ,OAAO,MAAM,EAAE,SAAS,UAAU,SAAS,SAAS,GAAG,UAAU;AACzF,QAAM,SAAS,mCAAY,MAAM,QAAQ,CAAC;AAAA,IACtC,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU,eAAe,UAAU,OAAO,QAAQ;AAAA,EACpD,CAAC,GAAY;AAAA,IACX,UAAU,6BAAM,QAAQ,KAAK,GAAnB;AAAA,EACZ,CAAC,GARY;AASf,SAAO,OAAO;AAClB,CAAC;","names":[]}
@@ -0,0 +1,7 @@
1
+ declare function suggestChoices<TName extends string = 'name', TChoice extends {
2
+ [K in TName]: string;
3
+ } = {
4
+ [K in TName]: string;
5
+ }>(choices: TChoice[], key?: TName, onSearch?: (input: string) => void): (input: string) => Promise<TChoice[]>;
6
+ export default suggestChoices;
7
+ //# sourceMappingURL=suggestChoices.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"suggestChoices.d.ts","sourceRoot":"","sources":["../suggestChoices.ts"],"names":[],"mappings":"AAEA,iBAAS,cAAc,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM,EAAE,OAAO,SAAS;KAAG,CAAC,IAAI,KAAK,GAAG,MAAM;CAAE,GAAG;KAAG,CAAC,IAAI,KAAK,GAAG,MAAM;CAAE,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,GAAG,GAAE,KAAuB,EAAE,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,WAIvL,MAAM,wBAO9B;AAED,eAAe,cAAc,CAAC"}
@@ -0,0 +1,21 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import Fuse from "fuse.js";
4
+ function suggestChoices(choices, key = "name", onSearch) {
5
+ const fuse = new Fuse(choices, {
6
+ keys: [key]
7
+ });
8
+ return async (input) => {
9
+ if (!input.trim()) {
10
+ return choices;
11
+ }
12
+ onSearch == null ? void 0 : onSearch(input);
13
+ return fuse.search(input).map((result) => result.item);
14
+ };
15
+ }
16
+ __name(suggestChoices, "suggestChoices");
17
+ var suggestChoices_default = suggestChoices;
18
+ export {
19
+ suggestChoices_default as default
20
+ };
21
+ //# sourceMappingURL=suggestChoices.js.map
@@ -0,0 +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,yCAAW;AACX,WAAO,KAAK,OAAO,KAAK,EAAE,IAAI,YAAU,OAAO,IAAI;AAAA,EACvD;AACJ;AAXS;AAaT,IAAO,yBAAQ;","names":[]}
package/types.d.ts ADDED
@@ -0,0 +1,45 @@
1
+ import Prompt from './Prompt.js';
2
+ export * from './prompts/index.js';
3
+ export type Promiseable<T> = Promise<T> | T;
4
+ export type Thunk<T> = T | (() => T);
5
+ export type ThunkPromiseable<T> = T | (() => T | Promiseable<T>);
6
+ export type ResolvePromise<T> = T extends PromiseLike<infer U> ? U : T;
7
+ export type StringKey<T> = Exclude<keyof T, symbol | number>;
8
+ export type BasePrompt<TName extends string, TValue, TState extends {
9
+ [K in TName]?: any;
10
+ }, TInitial extends TValue | undefined = TValue | undefined, TRequired extends boolean = false, TSkip extends boolean = false> = {
11
+ message: string | ((state: TState) => Promiseable<string>);
12
+ validate?: ValidateCallback<TValue, TState>;
13
+ initial?: ((value: TValue | undefined, state: TState) => Promiseable<TInitial>) | (() => Promiseable<TInitial>) | TInitial;
14
+ required?: TRequired | ((state: TState) => Promiseable<TRequired>);
15
+ skip?: TSkip | ((state: TState) => Promiseable<TSkip>);
16
+ };
17
+ export type PromptCallback<TState extends object, TOutputState extends object> = (state: TState) => Promiseable<TOutputState>;
18
+ export type PromptResultValue<TName extends string, TValue, TInitial extends TValue | undefined, TRequired extends boolean, TSkip extends boolean = false> = {
19
+ [K in TName]: TSkip extends false ? TRequired extends true ? TValue : TValue | TInitial : TValue | TInitial;
20
+ };
21
+ export type PromptResult<TName extends string, TValue, TState extends object, TInitial extends TValue | undefined, TRequired extends boolean, TSkip extends boolean> = PromptResultValue<TName, TValue, TInitial, TRequired, TSkip> extends infer TResult ? Prompt<{
22
+ [K in keyof (Omit<TState, keyof TResult> & TResult)]: (Omit<TState, keyof TResult> & TResult)[K];
23
+ }> : never;
24
+ export interface PromptTypeMap {
25
+ }
26
+ export type PromptType = keyof PromptTypeMap;
27
+ export type PromptConfigInput<TType extends PromptType> = PromptTypeMap[TType] extends {
28
+ (this: Prompt<any>, name: string, prompt: infer TInput): PromptResult<string, any, any, any, boolean, boolean>;
29
+ } ? TInput : BasePrompt<string, any, any, boolean, boolean>;
30
+ export type ResolvePrompt<TType extends PromptType, TName extends string, TState extends {
31
+ [K in TName]?: any;
32
+ }, TInitial extends PromptValue<TType> | undefined, TRequired extends boolean, TSkip extends boolean> = Omit<PromptConfigInput<TType>, 'message' | 'initial' | 'required' | 'skip'> & {
33
+ message: string;
34
+ initial: TInitial;
35
+ required: TRequired;
36
+ skip: TSkip;
37
+ };
38
+ export type PromptValue<TType extends PromptType> = ReturnType<PromptTypeMap[TType]> extends PromptResult<string, infer TValue, any, any, boolean, boolean> ? TValue : any;
39
+ export type PromptConfig<TType extends PromptType> = {
40
+ <TName extends string, TState extends {
41
+ [K in TName]?: PromptValue<TType>;
42
+ }, TInitial extends PromptValue<TType> | undefined, TRequired extends boolean, TSkip extends boolean>(name: TName, promptResult: ResolvePrompt<TType, TName, TState, TInitial, TRequired, TSkip>, state: TState): Promiseable<PromptResultValue<TName, PromptValue<TType>, TInitial, TRequired, TSkip>>;
43
+ };
44
+ export type ValidateCallback<T = any, TState extends object = any> = (value: T, state: TState) => Promiseable<true | string | false>;
45
+ //# sourceMappingURL=types.d.ts.map
package/types.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../types.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AAEjC,cAAc,oBAAoB,CAAC;AAEnC,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAC5C,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;AACrC,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,WA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,WAAW,CAAC,iBAAiB,CAAC,KAAK,EAAE,WAAW,CAAC,KAAK,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC,CAAA;CACpX,CAAA;AAED,MAAM,MAAM,gBAAgB,CAAC,CAAC,GAAG,GAAG,EAAE,MAAM,SAAS,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,WAAW,CAAC,IAAI,GAAG,MAAM,GAAG,KAAK,CAAC,CAAC"}
package/types.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from "./prompts/index.js";
2
+ ;
3
+ //# sourceMappingURL=types.js.map
package/types.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../types.ts"],"sourcesContent":["import Prompt from './Prompt.js';\n\nexport * from './prompts/index.js';\n\nexport type Promiseable<T> = Promise<T> | T;\nexport type Thunk<T> = T | (() => T);\nexport type ThunkPromiseable<T> = T | (() => T | Promiseable<T>);\nexport type ResolvePromise<T> = T extends PromiseLike<infer U> ? U : T;\nexport type StringKey<T> = Exclude<keyof T, symbol | number>;\nexport type BasePrompt<TName extends string, TValue, TState extends { [K in TName]?: any }, TInitial extends TValue | undefined = TValue | undefined, TRequired extends boolean = false, TSkip extends boolean = false> = {\n message: string |((state: TState) => Promiseable<string>);\n validate?: ValidateCallback<TValue, TState>; \n initial?: ((value: TValue | undefined, state: TState) => Promiseable<TInitial>) | (() => Promiseable<TInitial>) | TInitial,\n required?: TRequired | ((state: TState) => Promiseable<TRequired>),\n skip?: TSkip | ((state: TState) => Promiseable<TSkip>),\n}\n\nexport type PromptCallback<TState extends object, TOutputState extends object> = (state: TState) => Promiseable<TOutputState>;\n\nexport type PromptResultValue<TName extends string, TValue, TInitial extends TValue | undefined, TRequired extends boolean, TSkip extends boolean = false> = { [K in TName]: TSkip extends false ? TRequired extends true ? TValue : TValue | TInitial : TValue | TInitial };\n\nexport type PromptResult<TName extends string, TValue, TState extends object, TInitial extends TValue | undefined, TRequired extends boolean, TSkip extends boolean> = PromptResultValue<TName, TValue, TInitial, TRequired, TSkip> extends infer TResult\n ? Prompt<{ [K in keyof (Omit<TState, keyof TResult> & TResult)]: (Omit<TState, keyof TResult> & TResult)[K] }>\n : never;\n\nexport interface PromptTypeMap {};\n\nexport type PromptType = keyof PromptTypeMap;\n\nexport type PromptConfigInput<TType extends PromptType> = PromptTypeMap[TType] extends {\n (\n this: Prompt<any>,\n name: string,\n prompt: infer TInput\n ): PromptResult<string, any, any, any, boolean, boolean>\n} ? TInput : BasePrompt<string, any, any, boolean, boolean>;\n\nexport type ResolvePrompt<TType extends PromptType, TName extends string, TState extends { [K in TName]?: any }, TInitial extends PromptValue<TType> | undefined, TRequired extends boolean, TSkip extends boolean> = Omit<PromptConfigInput<TType>, 'message' | 'initial' | 'required' | 'skip'> & { message: string, initial: TInitial, required: TRequired, skip: TSkip };\n\nexport type PromptValue<TType extends PromptType> = ReturnType<PromptTypeMap[TType]> extends PromptResult<string, infer TValue, any, any, boolean, boolean> ? TValue : any;\n\nexport type PromptConfig<TType extends PromptType> = {\n <TName extends string, TState extends { [K in TName]?: PromptValue<TType> }, TInitial extends PromptValue<TType> | undefined, TRequired extends boolean, TSkip extends boolean>(name: TName, promptResult: ResolvePrompt<TType, TName, TState, TInitial, TRequired, TSkip>, state: TState): Promiseable<PromptResultValue<TName, PromptValue<TType>, TInitial, TRequired, TSkip>>\n}\n\nexport type ValidateCallback<T = any, TState extends object = any> = (value: T, state: TState) => Promiseable<true | string | false>;"],"mappings":"AAEA,cAAc;AAuBmB;","names":[]}
@@ -0,0 +1,4 @@
1
+ import { ValidateCallback } from './types.js';
2
+ declare function validatePrompt<T = any>(required: boolean, state: any, validate?: ValidateCallback<T>): (value: any) => Promise<string | true>;
3
+ export default validatePrompt;
4
+ //# sourceMappingURL=validatePrompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validatePrompt.d.ts","sourceRoot":"","sources":["../validatePrompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C,iBAAS,cAAc,CAAC,CAAC,GAAG,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,WACrE,GAAG,4BAa3B;AAED,eAAe,cAAc,CAAC"}
@@ -0,0 +1,20 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ function validatePrompt(required, state, validate) {
4
+ return async (value) => {
5
+ if (required && !(typeof value === "string" ? value.trim() : value)) {
6
+ return "Invalid";
7
+ }
8
+ const result = await (validate == null ? void 0 : validate(value, state));
9
+ if (result === false) {
10
+ return "Invalid input";
11
+ }
12
+ return result != null ? result : true;
13
+ };
14
+ }
15
+ __name(validatePrompt, "validatePrompt");
16
+ var validatePrompt_default = validatePrompt;
17
+ export {
18
+ validatePrompt_default as default
19
+ };
20
+ //# sourceMappingURL=validatePrompt.js.map
@@ -0,0 +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,OAAM,qCAAW,OAAO;AAEvC,QAAI,WAAW,OAAO;AAClB,aAAO;AAAA,IACX;AAEA,WAAO,0BAAU;AAAA,EACrB;AACJ;AAdS;AAgBT,IAAO,yBAAQ;","names":[]}