@pact-foundation/pact
Version:
Pact for all things Javascript
173 lines (172 loc) • 8.81 kB
TypeScript
import { ArrayContainsMatcher, DateTimeMatcher, Matcher, MaxLikeMatcher, MinLikeMatcher, ProviderStateInjectedValue, RulesMatcher, V3RegexMatcher } from './types';
import { AnyJson } from '../common/jsonTypes';
export * from './types';
export declare function isMatcher(x: unknown): x is Matcher<unknown>;
/**
* Value must match the given template
* @param template Template to base the comparison on
*/
export declare const like: <T>(template: T) => Matcher<T>;
/**
* Object where the key itself is ignored, but the value template must match.
*
* @deprecated use eachKeyMatches or eachValueMatches
* @param keyTemplate Example key to use
* @param template Example value template to base the comparison on
*/
export declare const eachKeyLike: <T>(keyTemplate: string, template: T) => Matcher<T>;
/**
* Object where the _keys_ must match the supplied matchers.
* The values for each key are ignored. That is, there can be 0 or more keys
* with any valid JSON identifier, so long as the names of the keys match the constraints.
*
* @param example Example object with key/values e.g. `{ foo: 'bar', baz: 'qux'}`
* @param matchers Matchers to apply to each key
*/
export declare const eachKeyMatches: (example: Record<string, unknown>, matchers?: Matcher<string> | Matcher<string>[]) => RulesMatcher<unknown>;
/**
* Object where the _values_ must match the supplied matchers.
* The names of the keys are ignored. That is, there can be 0 or more keys
* with any valid JSON identifier, so long as the values match the constraints.
*
* @param example Example object with key/values e.g. `{ foo: 'bar', baz: 'qux'}`
* @param matchers Matchers to apply to each value
*/
export declare const eachValueMatches: <T>(example: Record<string, T>, matchers: Matcher<T> | Matcher<T>[]) => RulesMatcher<T>;
/**
* Array where each element must match the given template
* @param template Template to base the comparison on
* @param min Minimum number of elements required in the array
*/
export declare const eachLike: <T>(template: T, min?: number) => MinLikeMatcher<T[]>;
/**
* An array that has to have at least one element and each element must match the given template
* @param template Template to base the comparison on
* @param count Number of examples to generate, defaults to one
*/
export declare const atLeastOneLike: <T>(template: T, count?: number) => MinLikeMatcher<T[]>;
/**
* An array that has to have at least the required number of elements and each element must match the given template
* @param template Template to base the comparison on
* @param min Minimum number of elements required in the array
* @param count Number of examples to generate, defaults to min
*/
export declare const atLeastLike: <T>(template: T, min: number, count?: number) => MinLikeMatcher<T[]>;
/**
* An array that has to have at most the required number of elements and each element must match the given template
* @param template Template to base the comparison on
* @param max Maximum number of elements required in the array
* @param count Number of examples to generate, defaults to one
*/
export declare const atMostLike: <T>(template: T, max: number, count?: number) => MaxLikeMatcher<T[]>;
/**
* An array whose size is constrained to the minimum and maximum number of elements and each element must match the given template
* @param template Template to base the comparison on
* @param min Minimum number of elements required in the array
* @param max Maximum number of elements required in the array
* @param count Number of examples to generate, defaults to one
*/
export declare const constrainedArrayLike: <T>(template: T, min: number, max: number, count?: number) => MinLikeMatcher<T[]> & MaxLikeMatcher<T[]>;
/**
* Value must be a boolean
* @param b Boolean example value. Defaults to true if unsupplied
*/
export declare const boolean: (b?: boolean) => Matcher<boolean>;
/**
* Value must be an integer (must be a number and have no decimal places)
* @param int Example value. If omitted a random value will be generated.
*/
export declare const integer: (int?: number) => Matcher<number>;
/**
* Value must be a decimal number (must be a number and have decimal places)
* @param num Example value. If omitted a random value will be generated.
*/
export declare const decimal: (num?: number) => Matcher<number>;
/**
* Value must be a number
* @param num Example value. If omitted a random integer value will be generated.
*/
export declare function number(num?: number): Matcher<number>;
/**
* Value must be a string
* @param str Example value
*/
export declare function string(str?: string): Matcher<string>;
/**
* Value that must match the given regular expression
* @param pattern Regular Expression to match
* @param str Example value
*/
export declare function regex(pattern: RegExp | string, str: string): V3RegexMatcher;
/**
* Value that must be equal to the example. This is mainly used to reset the matching rules which cascade.
* @param value Example value
*/
export declare const equal: <T>(value: T) => Matcher<T>;
/**
* String value that must match the provided datetime format string.
* @param format Datetime format string. See [Java SimpleDateFormat](https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html)
* @param example Example value to use. If omitted a value using the current system date and time will be generated.
*/
export declare function datetime(format: string, example: string): DateTimeMatcher;
/**
* String value that must match the provided datetime format string.
* @param format Datetime format string. See [Java SimpleDateFormat](https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html)
* @param example Example value to use. If omitted a value using the current system date and time will be generated.
*/
export declare function timestamp(format: string, example: string): DateTimeMatcher;
/**
* String value that must match the provided time format string.
* @param format Time format string. See [Java SimpleDateFormat](https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html)
* @param example Example value to use. If omitted a value using the current system time will be generated.
*/
export declare function time(format: string, example: string): DateTimeMatcher;
/**
* String value that must match the provided date format string.
* @param format Date format string. See [Java SimpleDateFormat](https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html)
* @param example Example value to use. If omitted a value using the current system date will be generated.
*/
export declare function date(format: string, example: string): DateTimeMatcher;
/**
* Value that must include the example value as a substring.
* @param value String value to include
*/
export declare function includes(value: string): Matcher<string>;
/**
* Value that must be null. This will only match the JSON Null value. For other content types, it will
* match if the attribute is missing.
*/
export declare function nullValue(): Matcher<null>;
/**
* Matches a URL composed of a base path and a list of path fragments
* @param basePath Base path of the URL. If null, will use the base URL from the mock server.
* @param pathFragments list of path fragments, can be regular expressions
*/
export declare function url2(basePath: string | null, pathFragments: Array<string | V3RegexMatcher | RegExp>): V3RegexMatcher;
/**
* Matches a URL composed of a list of path fragments. The base URL from the mock server will be used.
* @param pathFragments list of path fragments, can be regular expressions
*/
export declare function url(pathFragments: Array<string | V3RegexMatcher | RegExp>): V3RegexMatcher;
/**
* Matches the items in an array against a number of variants. Matching is successful if each variant
* occurs once in the array. Variants may be objects containing matching rules.
*/
export declare function arrayContaining(...variants: unknown[]): ArrayContainsMatcher;
/**
* Marks an item to be injected from the provider state
* @param expression Expression to lookup in the provider state context
* @param exampleValue Example value to use in the consumer test
*/
export declare function fromProviderState<V>(expression: string, exampleValue: V): ProviderStateInjectedValue<V>;
/**
* Match a universally unique identifier (UUID). Random values will be used for examples if no example is given.
*/
export declare function uuid(example?: string): V3RegexMatcher;
export declare const matcherValueOrString: (obj: unknown) => string;
/**
* Recurse the object removing any underlying matching guff, returning the raw
* example content.
*/
export declare function reify(input: unknown): AnyJson;
export { reify as extractPayload };