UNPKG

5.09 kBTypeScriptView Raw
1import { Construct } from './construct-compat';
2export declare type Mapper = (x: any) => any;
3export declare const stringToCloudFormation: Mapper;
4export declare const booleanToCloudFormation: Mapper;
5export declare const objectToCloudFormation: Mapper;
6export declare const numberToCloudFormation: Mapper;
7/**
8 * The date needs to be formatted as an ISO date in UTC
9 *
10 * Some usage sites require a date, some require a timestamp. We'll
11 * always output a timestamp and hope the parser on the other end
12 * is smart enough to ignore the time part... (?)
13 */
14export declare function dateToCloudFormation(x?: Date): any;
15/**
16 * Turn a tag object into the proper CloudFormation representation
17 */
18export declare function cfnTagToCloudFormation(x: any): any;
19export declare function listMapper(elementMapper: Mapper): Mapper;
20export declare function hashMapper(elementMapper: Mapper): Mapper;
21/**
22 * Return a union mapper
23 *
24 * Takes a list of validators and a list of mappers, which should correspond pairwise.
25 *
26 * The mapper of the first successful validator will be called.
27 */
28export declare function unionMapper(validators: Validator[], mappers: Mapper[]): Mapper;
29/**
30 * Representation of validation results
31 *
32 * Models a tree of validation errors so that we have as much information as possible
33 * about the failure that occurred.
34 */
35export declare class ValidationResult {
36 readonly errorMessage: string;
37 readonly results: ValidationResults;
38 constructor(errorMessage?: string, results?: ValidationResults);
39 get isSuccess(): boolean;
40 /**
41 * Turn a failed validation into an exception
42 */
43 assertSuccess(): void;
44 /**
45 * Return a string rendering of the tree of validation failures
46 */
47 errorTree(): string;
48 /**
49 * Wrap this result with an error message, if it concerns an error
50 */
51 prefix(message: string): ValidationResult;
52}
53/**
54 * A collection of validation results
55 */
56export declare class ValidationResults {
57 results: ValidationResult[];
58 constructor(results?: ValidationResult[]);
59 collect(result: ValidationResult): void;
60 get isSuccess(): boolean;
61 errorTreeList(): string;
62 /**
63 * Wrap up all validation results into a single tree node
64 *
65 * If there are failures in the collection, add a message, otherwise
66 * return a success.
67 */
68 wrap(message: string): ValidationResult;
69}
70export declare const VALIDATION_SUCCESS: ValidationResult;
71export declare type Validator = (x: any) => ValidationResult;
72/**
73 * Return whether this object can be validated at all
74 *
75 * True unless it's undefined or a CloudFormation intrinsic
76 */
77export declare function canInspect(x: any): boolean;
78export declare function validateString(x: any): ValidationResult;
79export declare function validateNumber(x: any): ValidationResult;
80export declare function validateBoolean(x: any): ValidationResult;
81export declare function validateDate(x: any): ValidationResult;
82export declare function validateObject(x: any): ValidationResult;
83export declare function validateCfnTag(x: any): ValidationResult;
84/**
85 * Return a list validator based on the given element validator
86 */
87export declare function listValidator(elementValidator: Validator): Validator;
88/**
89 * Return a hash validator based on the given element validator
90 */
91export declare function hashValidator(elementValidator: Validator): Validator;
92/**
93 * Decorate a validator with a message clarifying the property the failure is for.
94 */
95export declare function propertyValidator(propName: string, validator: Validator): Validator;
96/**
97 * Return a validator that will fail if the passed property is not present
98 *
99 * Does not distinguish between the property actually not being present, vs being present but 'null'
100 * or 'undefined' (courtesy of JavaScript), which is generally the behavior that we want.
101 *
102 * Empty strings are considered "present"--don't know if this agrees with how CloudFormation looks
103 * at the world.
104 */
105export declare function requiredValidator(x: any): ValidationResult;
106/**
107 * Require a property from a property bag.
108 *
109 * @param props the property bag from which a property is required.
110 * @param name the name of the required property.
111 * @param typeName the name of the construct type that requires the property
112 *
113 * @returns the value of ``props[name]``
114 *
115 * @throws if the property ``name`` is not present in ``props``.
116 */
117export declare function requireProperty(props: {
118 [name: string]: any;
119}, name: string, context: Construct): any;
120/**
121 * Validates if any of the given validators matches
122 *
123 * We add either/or words to the front of the error mesages so that they read
124 * more nicely. Example:
125 *
126 * Properties not correct for 'FunctionProps'
127 * codeUri: not one of the possible types
128 * either: properties not correct for 'S3LocationProperty'
129 * bucket: required but missing
130 * key: required but missing
131 * version: required but missing
132 * or: '3' should be a 'string'
133 *
134 */
135export declare function unionValidator(...validators: Validator[]): Validator;