unmock-core
Version:
[][npmjs] [](https://circleci.com/gh/unmock/unmock-js) [](h
92 lines • 4.3 kB
TypeScript
import { OpenAPIObject, Operation, PathItem, Schema } from "loas3/dist/generated/full";
import { HTTPMethod, ISerializedRequest } from "../interfaces";
import { IDSL, ITopLevelDSL } from "./dsl/interfaces";
import { IRequestResponsePair, ServiceSpy } from "./spy";
export { Header, isOperation, isReference, isSchema, MediaType, OpenAPIObject, Paths, Schema, Operation, Parameter, PathItem, Reference, Response, Responses, } from "loas3/dist/generated/full";
declare const DEF_REST_METHOD: readonly ["any"];
declare type DEFAULT_HTTP_METHOD_AS_TYPE = typeof DEF_REST_METHOD[number];
export declare type ExtendedHTTPMethod = HTTPMethod | DEFAULT_HTTP_METHOD_AS_TYPE;
export declare type OASMethodKey = keyof PathItem & HTTPMethod;
export interface IStateInputGenerator {
isEmpty: boolean;
gen: (schema: Schema) => {
spreadState: Record<string, Schema> | Schema;
error?: string;
};
top: ITopLevelDSL;
readonly state: any;
}
export declare const isStateInputGenerator: (u: any) => u is IStateInputGenerator;
export declare type Dereferencer = <T>(obj: any) => T;
export interface IStateInput {
method: ExtendedHTTPMethod;
endpoint: string;
newState: IStateInputGenerator;
}
export declare type mediaTypeToSchema = Record<string, Schema>;
export declare type codeToMedia = Record<string, mediaTypeToSchema>;
export declare type MatcherResponse = {
operation: Operation;
state: codeToMedia | undefined;
service: IServiceCore;
} | undefined;
export interface IService {
readonly state: StateType;
readonly spy: ServiceSpy;
reset(): void;
}
export declare type ServiceStoreType = Record<string, IService>;
export interface IObjectToService {
baseUrl: string;
method: HTTPMethod;
endpoint: string;
statusCode: number;
response: string | Schema;
name?: string;
}
export interface IServiceCore {
readonly name: string;
readonly schema: OpenAPIObject;
readonly absPath: string;
readonly dereferencer: Dereferencer;
readonly spy: ServiceSpy;
hasDefinedPaths: boolean;
track(requestResponsePair: IRequestResponsePair): void;
updateState(input: IStateInput): void;
resetState(): void;
getState(method: HTTPMethod, endpoint: string): codeToMedia | undefined;
match(sreq: ISerializedRequest): MatcherResponse;
}
interface INestedState<T> {
[key: string]: INestedState<T> | T;
}
export interface IUnmockServiceState extends INestedState<IDSL | string | number | (() => string | number) | undefined | boolean> {
}
export declare type UnmockServiceState = IUnmockServiceState & ITopLevelDSL | IDSL;
declare type FunctionInput = (req: ISerializedRequest) => any;
export declare type StateInput = IStateInputGenerator | UnmockServiceState | string | FunctionInput;
interface IResetState {
reset(): void;
}
declare type SetStateForSpecificMethod = {
get(state: StateInput): SetStateForSpecificMethod;
get(endpoint: string, state: StateInput): SetStateForSpecificMethod;
head(state: StateInput): SetStateForSpecificMethod;
head(endpoint: string, state: StateInput): SetStateForSpecificMethod;
post(state: StateInput): SetStateForSpecificMethod;
post(endpoint: string, state: StateInput): SetStateForSpecificMethod;
put(state: StateInput): SetStateForSpecificMethod;
put(endpoint: string, state: StateInput): SetStateForSpecificMethod;
patch(state: StateInput): SetStateForSpecificMethod;
patch(endpoint: string, state: StateInput): SetStateForSpecificMethod;
delete(state: StateInput): SetStateForSpecificMethod;
delete(endpoint: string, state: StateInput): SetStateForSpecificMethod;
options(state: StateInput): SetStateForSpecificMethod;
options(endpoint: string, state: StateInput): SetStateForSpecificMethod;
trace(state: StateInput): SetStateForSpecificMethod;
trace(endpoint: string, state: StateInput): SetStateForSpecificMethod;
} & IResetState;
declare type SetStateForAllPaths = (state: StateInput) => SetStateForSpecificMethod;
declare type SetStateForMatchingEndpoint = (endpoint: string, state: StateInput) => SetStateForSpecificMethod;
export declare type StateType = SetStateForAllPaths & SetStateForMatchingEndpoint & SetStateForSpecificMethod & IResetState;
//# sourceMappingURL=interfaces.d.ts.map