amplify-prompts
Advanced tools
Comparing version 2.6.2 to 2.6.3-pinpoint-customer-config.0
@@ -66,2 +66,5 @@ ## API Report File for "amplify-prompts" | ||
// @public (undocumented) | ||
export const between: (min: number, max: number, message?: string | undefined) => Validator; | ||
// Warning: (ae-forgotten-export) The symbol "EqualsFunction" needs to be exported by the entry point index.d.ts | ||
@@ -68,0 +71,0 @@ // Warning: (ae-forgotten-export) The symbol "SingleFilterFunction" needs to be exported by the entry point index.d.ts |
@@ -6,2 +6,19 @@ # Change Log | ||
## [2.6.3-pinpoint-customer-config.0](https://github.com/aws-amplify/amplify-cli/compare/amplify-prompts@2.6.2...amplify-prompts@2.6.3-pinpoint-customer-config.0) (2023-01-24) | ||
### Bug Fixes | ||
* automatic lint fixes ([#11636](https://github.com/aws-amplify/amplify-cli/issues/11636)) ([0e7f70b](https://github.com/aws-amplify/amplify-cli/commit/0e7f70befbe72d17dfb11f5fed1c8609a13d4a97)) | ||
* make prompter multi-select indicator more distinct ([#11742](https://github.com/aws-amplify/amplify-cli/issues/11742)) ([4531c38](https://github.com/aws-amplify/amplify-cli/commit/4531c3819fbf9850d603df443380ae310c85b129)) | ||
### Reverts | ||
* Revert "chore: fixing main to dev merge conflicts (#11696)" ([00fec46](https://github.com/aws-amplify/amplify-cli/commit/00fec4608096390b5ae2563b5c69453cd48bfa45)), closes [#11696](https://github.com/aws-amplify/amplify-cli/issues/11696) | ||
## [2.6.2](https://github.com/aws-amplify/amplify-cli/compare/amplify-prompts@2.6.1...amplify-prompts@2.6.2) (2023-01-03) | ||
@@ -8,0 +25,0 @@ |
@@ -47,3 +47,3 @@ "use strict"; | ||
if (this.flowData && input) { | ||
const finalInput = (redact) ? '*'.repeat(input.length) : input; | ||
const finalInput = redact ? '*'.repeat(input.length) : input; | ||
this.flowData.pushInteractiveFlow(promptString, finalInput); | ||
@@ -94,3 +94,7 @@ } | ||
const opts = (_a = options === null || options === void 0 ? void 0 : options[0]) !== null && _a !== void 0 ? _a : {}; | ||
const enquirerPromptType = 'hidden' in opts && opts.hidden ? EnquirerPromptType.INVISIBLE : opts.returnSize === 'many' ? EnquirerPromptType.LIST : EnquirerPromptType.INPUT; | ||
const enquirerPromptType = 'hidden' in opts && opts.hidden | ||
? EnquirerPromptType.INVISIBLE | ||
: opts.returnSize === 'many' | ||
? EnquirerPromptType.LIST | ||
: EnquirerPromptType.INPUT; | ||
if (flags_1.isYes) { | ||
@@ -134,3 +138,4 @@ if (opts.initial !== undefined) { | ||
const genericChoices = typeof choices[0] === 'string' | ||
? choices.map(choice => ({ name: choice, value: choice })) | ||
? | ||
choices.map(choice => ({ name: choice, value: choice })) | ||
: choices; | ||
@@ -181,2 +186,5 @@ const initialIndexes = initialOptsToIndexes(genericChoices.map(choice => choice.value), opts.initial); | ||
}, | ||
indicator(_, choice) { | ||
return choice.enabled ? chalk_1.default.cyan('●') : '○'; | ||
}, | ||
validate() { | ||
@@ -183,0 +191,0 @@ var _a, _b; |
@@ -8,2 +8,3 @@ export declare type Validator = (value: string) => true | string | Promise<true | string>; | ||
export declare const exact: (expected: string, message?: string | undefined) => Validator; | ||
export declare const between: (min: number, max: number, message?: string | undefined) => Validator; | ||
export declare const and: (validators: [Validator, Validator, ...Validator[]], message?: string | undefined) => Validator; | ||
@@ -10,0 +11,0 @@ export declare const or: (validators: [Validator, Validator, ...Validator[]], message?: string | undefined) => Validator; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.not = exports.or = exports.and = exports.exact = exports.minLength = exports.maxLength = exports.integer = exports.matchRegex = exports.alphanumeric = void 0; | ||
exports.not = exports.or = exports.and = exports.between = exports.exact = exports.minLength = exports.maxLength = exports.integer = exports.matchRegex = exports.alphanumeric = void 0; | ||
const alphanumeric = (message = 'Input must be alphanumeric') => (input) => /^[a-zA-Z0-9]+$/.test(input) ? true : message; | ||
@@ -8,3 +8,3 @@ exports.alphanumeric = alphanumeric; | ||
exports.matchRegex = matchRegex; | ||
const integer = (message = 'Input must be a number') => (input) => /^[0-9]+$/.test(input) ? true : message; | ||
const integer = (message = 'Input must be a number') => (input) => (/^[0-9]+$/.test(input) ? true : message); | ||
exports.integer = integer; | ||
@@ -17,2 +17,4 @@ const maxLength = (maxLen, message) => (input) => input.length > maxLen ? message || `Input must be less than ${maxLen} characters long` : true; | ||
exports.exact = exact; | ||
const between = (min, max, message) => (input) => parseInt(input) >= min && parseInt(input) <= max ? true : message || `Input must be between ${min} and ${max}`; | ||
exports.between = between; | ||
const and = (validators, message) => async (input) => { | ||
@@ -19,0 +21,0 @@ for (const validator of validators) { |
{ | ||
"name": "amplify-prompts", | ||
"version": "2.6.2", | ||
"version": "2.6.3-pinpoint-customer-config.0", | ||
"description": "Utility functions for Amplify CLI terminal I/O", | ||
@@ -53,3 +53,3 @@ "main": "lib/index.js", | ||
}, | ||
"gitHead": "dea54cd4bc5745ba7645808964d29f5a395fe6f7" | ||
"gitHead": "391eae3e5f654848c00bd457c798a43ec444bbe6" | ||
} |
@@ -23,3 +23,3 @@ /* eslint-disable @typescript-eslint/ban-types */ | ||
class AmplifyPrompter implements Prompter { | ||
flowData: IFlowData|undefined; // interactive cli flow data journal | ||
flowData: IFlowData | undefined; // interactive cli flow data journal | ||
stopWatch: Stopwatch; | ||
@@ -40,10 +40,10 @@ constructor(private readonly prompter: typeof prompt = prompt, private readonly print: typeof printer = printer) { | ||
private throwLoggedError = (message: string, errorMsg : string) : void => { | ||
private throwLoggedError = (message: string, errorMsg: string): void => { | ||
this.flowData?.pushInteractiveFlow(message, errorMsg); | ||
throw new Error(errorMsg); | ||
} | ||
}; | ||
setFlowData = (flowData: IFlowData): void => { | ||
this.flowData = flowData; | ||
} | ||
}; | ||
@@ -53,7 +53,7 @@ private pushInteractiveFlow = (promptString: string, input: unknown, redact = false) => { | ||
if (this.flowData && input) { | ||
const finalInput = (redact) ? '*'.repeat((input as string).length) : input; | ||
const finalInput = redact ? '*'.repeat((input as string).length) : input; | ||
this.flowData.pushInteractiveFlow(promptString, finalInput); | ||
} | ||
} | ||
} | ||
}; | ||
@@ -122,5 +122,13 @@ /** | ||
*/ | ||
input = async <RS extends ReturnSize = 'one', T = string>(message: string, ...options: MaybeOptionalInputOptions<RS, T>): Promise<PromptReturn<RS, T>> => { | ||
input = async <RS extends ReturnSize = 'one', T = string>( | ||
message: string, | ||
...options: MaybeOptionalInputOptions<RS, T> | ||
): Promise<PromptReturn<RS, T>> => { | ||
const opts = options?.[0] ?? ({} as InputOptions<RS, T>); | ||
const enquirerPromptType : EnquirerPromptType = 'hidden' in opts && opts.hidden ? EnquirerPromptType.INVISIBLE : opts.returnSize === 'many' ? EnquirerPromptType.LIST : EnquirerPromptType.INPUT; | ||
const enquirerPromptType: EnquirerPromptType = | ||
'hidden' in opts && opts.hidden | ||
? EnquirerPromptType.INVISIBLE | ||
: opts.returnSize === 'many' | ||
? EnquirerPromptType.LIST | ||
: EnquirerPromptType.INPUT; | ||
@@ -154,5 +162,7 @@ if (isYes) { | ||
if (Array.isArray(result)) { | ||
functionResult = (await Promise.all(result.map(async part => (opts.transform as Function)(part) as T))) as unknown as PromptReturn<RS, T>; | ||
functionResult = ((await Promise.all( | ||
result.map(async part => (opts.transform as Function)(part) as T), | ||
)) as unknown) as PromptReturn<RS, T>; | ||
} else { | ||
functionResult = opts.transform(result as string) as unknown as PromptReturn<RS, T>; | ||
functionResult = (opts.transform(result as string) as unknown) as PromptReturn<RS, T>; | ||
} | ||
@@ -164,3 +174,3 @@ this.pushInteractiveFlow(message, functionResult, enquirerPromptType == EnquirerPromptType.INVISIBLE); | ||
this.pushInteractiveFlow(message, result, enquirerPromptType == EnquirerPromptType.INVISIBLE); | ||
return result as unknown as PromptReturn<RS, T>; | ||
return (result as unknown) as PromptReturn<RS, T>; | ||
}; | ||
@@ -194,6 +204,7 @@ | ||
// map string[] choices into GenericChoice<T>[] | ||
const genericChoices: GenericChoice<T>[] = typeof choices[0] === 'string' | ||
// this assertion is safe because the choice array can only be a string[] if the generic type is a string | ||
? ((choices as string[]).map(choice => ({ name: choice, value: choice })) as unknown as GenericChoice<T>[]) | ||
: (choices as GenericChoice<T>[]); | ||
const genericChoices: GenericChoice<T>[] = | ||
typeof choices[0] === 'string' | ||
? // this assertion is safe because the choice array can only be a string[] if the generic type is a string | ||
(((choices as string[]).map(choice => ({ name: choice, value: choice })) as unknown) as GenericChoice<T>[]) | ||
: (choices as GenericChoice<T>[]); | ||
@@ -265,2 +276,5 @@ const initialIndexes = initialOptsToIndexes( | ||
}, | ||
indicator(_: unknown, choice: { enabled: boolean }) { | ||
return choice.enabled ? chalk.cyan('●') : '○'; | ||
}, | ||
validate() { | ||
@@ -301,3 +315,3 @@ if (opts && ('pickAtLeast' in opts || 'pickAtMost' in opts)) { | ||
getTotalPromptElapsedTime = () : number => this.stopWatch.getElapsedMilliseconds() | ||
getTotalPromptElapsedTime = (): number => this.stopWatch.getElapsedMilliseconds(); | ||
} | ||
@@ -313,5 +327,4 @@ | ||
*/ | ||
export const byValues = <T>(selection: T[], equals: EqualsFunction<T> = defaultEquals): MultiFilterFunction<T> => ( | ||
choices: T[], | ||
) => selection.map(sel => choices.findIndex(choice => equals(choice, sel))).filter(idx => idx >= 0); | ||
export const byValues = <T>(selection: T[], equals: EqualsFunction<T> = defaultEquals): MultiFilterFunction<T> => (choices: T[]) => | ||
selection.map(sel => choices.findIndex(choice => equals(choice, sel))).filter(idx => idx >= 0); | ||
@@ -379,4 +392,4 @@ /** | ||
: { | ||
hidden?: boolean; | ||
}; | ||
hidden?: boolean; | ||
}; | ||
@@ -400,4 +413,4 @@ // The initial selection for a pick prompt can be specified either by index or a selection function that generates indexes. | ||
: { | ||
pickAtLeast?: number; | ||
}; | ||
pickAtLeast?: number; | ||
}; | ||
@@ -407,4 +420,4 @@ type MultiSelectMaximum<RS extends ReturnSize> = RS extends 'one' | ||
: { | ||
pickAtMost?: number; | ||
}; | ||
pickAtMost?: number; | ||
}; | ||
@@ -425,7 +438,7 @@ type ValidateValueOption = { | ||
? { | ||
returnSize: 'many'; | ||
} | ||
returnSize: 'many'; | ||
} | ||
: { | ||
returnSize?: 'one'; | ||
}; | ||
returnSize?: 'one'; | ||
}; | ||
@@ -467,5 +480,5 @@ type Choices<T> = T extends string ? GenericChoice<T>[] | string[] : GenericChoice<T>[]; | ||
enum EnquirerPromptType { | ||
INVISIBLE = 'invisible', | ||
LIST = 'list', | ||
INPUT = 'input' | ||
INVISIBLE = 'invisible', | ||
LIST = 'list', | ||
INPUT = 'input', | ||
} |
@@ -15,32 +15,22 @@ export type Validator = (value: string) => true | string | Promise<true | string>; | ||
export const alphanumeric = | ||
(message: string = 'Input must be alphanumeric'): Validator => | ||
(input: string) => | ||
/^[a-zA-Z0-9]+$/.test(input) ? true : message; | ||
export const alphanumeric = (message = 'Input must be alphanumeric'): Validator => (input: string) => | ||
/^[a-zA-Z0-9]+$/.test(input) ? true : message; | ||
export const matchRegex = | ||
(validatorRegex : RegExp, message?: string): Validator => | ||
(input: string) => | ||
validatorRegex.test(input) ? true : message || `Input does not match the regular expression ${validatorRegex}`; | ||
export const matchRegex = (validatorRegex: RegExp, message?: string): Validator => (input: string) => | ||
validatorRegex.test(input) ? true : message || `Input does not match the regular expression ${validatorRegex}`; | ||
export const integer = | ||
(message: string = 'Input must be a number'): Validator => | ||
(input: string) => | ||
/^[0-9]+$/.test(input) ? true : message; | ||
export const integer = (message = 'Input must be a number'): Validator => (input: string) => (/^[0-9]+$/.test(input) ? true : message); | ||
export const maxLength = | ||
(maxLen: number, message?: string): Validator => | ||
(input: string) => | ||
input.length > maxLen ? message || `Input must be less than ${maxLen} characters long` : true; | ||
export const maxLength = (maxLen: number, message?: string): Validator => (input: string) => | ||
input.length > maxLen ? message || `Input must be less than ${maxLen} characters long` : true; | ||
export const minLength = | ||
(minLen: number, message?: string): Validator => | ||
(input: string) => | ||
input.length < minLen ? message || `Input must be more than ${minLen} characters long` : true; | ||
export const minLength = (minLen: number, message?: string): Validator => (input: string) => | ||
input.length < minLen ? message || `Input must be more than ${minLen} characters long` : true; | ||
export const exact = | ||
(expected: string, message?: string): Validator => | ||
(input: string) => | ||
input === expected ? true : message ?? 'Input does not match expected value'; | ||
export const exact = (expected: string, message?: string): Validator => (input: string) => | ||
input === expected ? true : message ?? 'Input does not match expected value'; | ||
export const between = (min: number, max: number, message?: string): Validator => (input: string) => | ||
parseInt(input) >= min && parseInt(input) <= max ? true : message || `Input must be between ${min} and ${max}`; | ||
/** | ||
@@ -50,13 +40,11 @@ * Logically "and"s several validators | ||
*/ | ||
export const and = | ||
(validators: [Validator, Validator, ...Validator[]], message?: string): Validator => | ||
async (input: string) => { | ||
for (const validator of validators) { | ||
const result = await validator(input); | ||
if (typeof result === 'string') { | ||
return message ?? result; | ||
} | ||
export const and = (validators: [Validator, Validator, ...Validator[]], message?: string): Validator => async (input: string) => { | ||
for (const validator of validators) { | ||
const result = await validator(input); | ||
if (typeof result === 'string') { | ||
return message ?? result; | ||
} | ||
return true; | ||
}; | ||
} | ||
return true; | ||
}; | ||
@@ -67,14 +55,12 @@ /** | ||
*/ | ||
export const or = | ||
(validators: [Validator, Validator, ...Validator[]], message?: string): Validator => | ||
async (input: string) => { | ||
let result: string | true = true; | ||
for (const validator of validators) { | ||
result = await validator(input); | ||
if (result === true) { | ||
return true; | ||
} | ||
export const or = (validators: [Validator, Validator, ...Validator[]], message?: string): Validator => async (input: string) => { | ||
let result: string | true = true; | ||
for (const validator of validators) { | ||
result = await validator(input); | ||
if (result === true) { | ||
return true; | ||
} | ||
return message ?? result; | ||
}; | ||
} | ||
return message ?? result; | ||
}; | ||
@@ -85,5 +71,3 @@ /** | ||
*/ | ||
export const not = | ||
(validator: Validator, message: string): Validator => | ||
async (input: string) => | ||
typeof (await validator(input)) === 'string' ? true : message; | ||
export const not = (validator: Validator, message: string): Validator => async (input: string) => | ||
typeof (await validator(input)) === 'string' ? true : message; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
260960
3133
1